diff --git a/src/runtime/virtcontainers/acrn.go b/src/runtime/virtcontainers/acrn.go index cbd45a49a5..a15e42d337 100644 --- a/src/runtime/virtcontainers/acrn.go +++ b/src/runtime/virtcontainers/acrn.go @@ -353,12 +353,12 @@ func (a *Acrn) setConfig(config *HypervisorConfig) error { return nil } -// createSandbox is the Hypervisor sandbox creation. -func (a *Acrn) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error { +// CreateVM is the VM creation +func (a *Acrn) CreateVM(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error { // Save the tracing context a.ctx = ctx - span, ctx := katatrace.Trace(ctx, a.Logger(), "createSandbox", acrnTracingTags, map[string]string{"sandbox_id": a.id}) + span, ctx := katatrace.Trace(ctx, a.Logger(), "CreateVM", acrnTracingTags, map[string]string{"sandbox_id": a.id}) defer span.End() if err := a.setup(ctx, id, hypervisorConfig); err != nil { diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index 434d9ea87a..591efa5aa0 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -200,11 +200,11 @@ func (clh *cloudHypervisor) setConfig(config *HypervisorConfig) error { } // For cloudHypervisor this call only sets the internal structure up. -// The VM will be created and started through startSandbox(). -func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error { +// The VM will be created and started through StartVM(). +func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error { clh.ctx = ctx - span, newCtx := katatrace.Trace(clh.ctx, clh.Logger(), "createSandbox", clhTracingTags, map[string]string{"sandbox_id": clh.id}) + span, newCtx := katatrace.Trace(clh.ctx, clh.Logger(), "CreateVM", clhTracingTags, map[string]string{"sandbox_id": clh.id}) clh.ctx = newCtx defer span.End() @@ -215,7 +215,7 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ clh.id = id clh.state.state = clhNotReady - clh.Logger().WithField("function", "createSandbox").Info("creating Sandbox") + clh.Logger().WithField("function", "CreateVM").Info("creating Sandbox") virtiofsdSocketPath, err := clh.virtioFsSocketPath(clh.id) if err != nil { @@ -223,7 +223,7 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ } if clh.state.PID > 0 { - clh.Logger().WithField("function", "createSandbox").Info("Sandbox already exist, loading from state") + clh.Logger().WithField("function", "CreateVM").Info("Sandbox already exist, loading from state") clh.virtiofsd = &virtiofsd{ PID: clh.state.VirtiofsdPID, sourcePath: filepath.Join(getSharePath(clh.id)), @@ -235,7 +235,7 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ // No need to return an error from there since there might be nothing // to fetch if this is the first time the hypervisor is created. - clh.Logger().WithField("function", "createSandbox").Info("Sandbox not found creating") + clh.Logger().WithField("function", "CreateVM").Info("Sandbox not found creating") // Make sure the kernel path is valid kernelPath, err := clh.config.KernelAssetPath() diff --git a/src/runtime/virtcontainers/fc.go b/src/runtime/virtcontainers/fc.go index bfb48506e3..1b4c055ccf 100644 --- a/src/runtime/virtcontainers/fc.go +++ b/src/runtime/virtcontainers/fc.go @@ -198,12 +198,12 @@ func (fc *firecracker) setConfig(config *HypervisorConfig) error { return nil } -// For firecracker this call only sets the internal structure up. +// CreateVM For firecracker this call only sets the internal structure up. // The sandbox will be created and started through startSandbox(). -func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error { +func (fc *firecracker) CreateVM(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error { fc.ctx = ctx - span, _ := katatrace.Trace(ctx, fc.Logger(), "createSandbox", fcTracingTags, map[string]string{"sandbox_id": fc.id}) + span, _ := katatrace.Trace(ctx, fc.Logger(), "CreateVM", fcTracingTags, map[string]string{"sandbox_id": fc.id}) defer span.End() //TODO: Check validity of the hypervisor config provided @@ -217,7 +217,7 @@ func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS N fc.setPaths(&fc.config) - // So we need to repopulate this at startSandbox where it is valid + // So we need to repopulate this at StartVM where it is valid fc.netNSPath = networkNS.NetNsPath // Till we create lower privileged kata user run as root diff --git a/src/runtime/virtcontainers/hypervisor.go b/src/runtime/virtcontainers/hypervisor.go index 788338b26b..751d8d9ef3 100644 --- a/src/runtime/virtcontainers/hypervisor.go +++ b/src/runtime/virtcontainers/hypervisor.go @@ -537,6 +537,8 @@ func (conf *HypervisorConfig) CheckTemplateConfig() error { } func (conf *HypervisorConfig) Valid() error { + + // Kata specific checks. Should be done outside the hypervisor if conf.KernelPath == "" { return fmt.Errorf("Missing kernel path") } @@ -897,7 +899,7 @@ func generateVMSocket(id string, vmStogarePath string) (interface{}, error) { // The default hypervisor implementation is Qemu. type hypervisor interface { setConfig(config *HypervisorConfig) error - createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error + CreateVM(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error StartVM(ctx context.Context, timeout int) error // If wait is set, don't actively stop the sandbox: diff --git a/src/runtime/virtcontainers/mock_hypervisor.go b/src/runtime/virtcontainers/mock_hypervisor.go index 3dccdcfcca..2c132f0ba8 100644 --- a/src/runtime/virtcontainers/mock_hypervisor.go +++ b/src/runtime/virtcontainers/mock_hypervisor.go @@ -38,7 +38,7 @@ func (m *mockHypervisor) setConfig(config *HypervisorConfig) error { return nil } -func (m *mockHypervisor) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error { +func (m *mockHypervisor) CreateVM(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error { if err := m.setConfig(hypervisorConfig); err != nil { return err } diff --git a/src/runtime/virtcontainers/qemu.go b/src/runtime/virtcontainers/qemu.go index bb040f568a..25c9b093f2 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -476,15 +476,15 @@ func (q *qemu) setConfig(config *HypervisorConfig) error { return nil } -// createSandbox is the Hypervisor sandbox creation implementation for govmmQemu. -func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error { +// CreateVM is the Hypervisor VM creation implementation for govmmQemu. +func (q *qemu) CreateVM(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error { // Save the tracing context q.ctx = ctx - span, ctx := katatrace.Trace(ctx, q.Logger(), "createSandbox", qemuTracingTags, map[string]string{"sandbox_id": q.id}) + span, ctx := katatrace.Trace(ctx, q.Logger(), "CreateVM", qemuTracingTags, map[string]string{"VM_ID": q.id}) defer span.End() - // Has Kata Specific logic: See within + // Breaks hypervisor abstraction Has Kata Specific logic: See within if err := q.setup(ctx, id, hypervisorConfig); err != nil { return err } @@ -514,7 +514,6 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa IOMMUPlatform: q.config.IOMMUPlatform, } - // MRC: Kata specific kernelPath, err := q.config.KernelAssetPath() if err != nil { return err @@ -525,6 +524,7 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa return err } + // Breaks hypervisor abstration Has Kata Specific logic kernel := govmmQemu.Kernel{ Path: kernelPath, InitrdPath: initrdPath, diff --git a/src/runtime/virtcontainers/sandbox.go b/src/runtime/virtcontainers/sandbox.go index b726a5508f..107474f77d 100644 --- a/src/runtime/virtcontainers/sandbox.go +++ b/src/runtime/virtcontainers/sandbox.go @@ -556,7 +556,7 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor } // store doesn't require hypervisor to be stored immediately - if err = s.hypervisor.createSandbox(ctx, s.id, s.networkNS, &sandboxConfig.HypervisorConfig); err != nil { + if err = s.hypervisor.CreateVM(ctx, s.id, s.networkNS, &sandboxConfig.HypervisorConfig); err != nil { return nil, err } diff --git a/src/runtime/virtcontainers/vm.go b/src/runtime/virtcontainers/vm.go index 3c91d6534b..b77da81c30 100644 --- a/src/runtime/virtcontainers/vm.go +++ b/src/runtime/virtcontainers/vm.go @@ -111,7 +111,7 @@ func NewVM(ctx context.Context, config VMConfig) (*VM, error) { } }() - if err = hypervisor.createSandbox(ctx, id, NetworkNamespace{}, &config.HypervisorConfig); err != nil { + if err = hypervisor.CreateVM(ctx, id, NetworkNamespace{}, &config.HypervisorConfig); err != nil { return nil, err }