MCPcopy
hub / github.com/firecracker-microvm/firecracker-containerd / buildVMConfiguration

Method buildVMConfiguration

runtime/service.go:927–1050  ·  view source on GitHub ↗
(req *proto.CreateVMRequest)

Source from the content-addressed store, hash-verified

925}
926
927func (s *service) buildVMConfiguration(req *proto.CreateVMRequest) (*firecracker.Config, error) {
928 for _, driveMount := range req.DriveMounts {
929 // Verify the request specified an absolute path for the source/dest of drives.
930 // Otherwise, users can implicitly rely on the CWD of this shim or agent.
931 if !strings.HasPrefix(driveMount.HostPath, "/") || !strings.HasPrefix(driveMount.VMPath, "/") {
932 return nil, fmt.Errorf("driveMount %s contains relative path", driveMount.String())
933 }
934 }
935
936 relSockPath, err := s.shimDir.FirecrackerSockRelPath()
937 if err != nil {
938 return nil, fmt.Errorf("failed to get relative path to firecracker api socket: %w", err)
939 }
940
941 relVSockPath, err := s.jailer.JailPath().FirecrackerVSockRelPath()
942 if err != nil {
943 return nil, fmt.Errorf("failed to get relative path to firecracker vsock: %w", err)
944 }
945
946 cfg := firecracker.Config{
947 SocketPath: relSockPath,
948 VsockDevices: []firecracker.VsockDevice{{
949 Path: relVSockPath,
950 ID: "agent_api",
951 }},
952 MachineCfg: machineConfigurationFromProto(s.config, req.MachineCfg),
953 LogLevel: s.config.DebugHelper.GetFirecrackerLogLevel(),
954 VMID: s.vmID,
955 }
956
957 flag, err := internal.SupportCPUTemplate()
958 if err != nil {
959 return nil, err
960 }
961 if !flag {
962 cfg.MachineCfg.CPUTemplate = ""
963 }
964
965 logPath := s.shimDir.FirecrackerLogFifoPath()
966 if req.LogFifoPath != "" {
967 logPath = req.LogFifoPath
968 }
969 err = syscall.Mkfifo(logPath, 0700)
970 if err != nil {
971 return nil, err
972 }
973
974 metricsPath := s.shimDir.FirecrackerMetricsFifoPath()
975 if req.MetricsFifoPath != "" {
976 metricsPath = req.MetricsFifoPath
977 }
978 err = syscall.Mkfifo(metricsPath, 0700)
979 if err != nil {
980 return nil, err
981 }
982
983 // The Config struct has LogFifo and MetricsFifo, but they will be deprecated since
984 // Firecracker doesn't have the corresponding fields anymore.

Callers 3

TestBuildVMConfigurationFunction · 0.95
createVMMethod · 0.95
TestDebugConfigFunction · 0.80

Calls 13

buildRootDriveMethod · 0.95
SupportCPUTemplateFunction · 0.92
CreateContainerStubsFunction · 0.85
CreateDriveMountStubsFunction · 0.85
networkConfigFromProtoFunction · 0.85
JailPathMethod · 0.65

Tested by 2

TestBuildVMConfigurationFunction · 0.76
TestDebugConfigFunction · 0.64