hypervisor: createSandbox is CreateVM

Last of a series of commits to export the top level
hypervisor generic methods.

s/createSandbox/CreateVM

Fixes #2880

Signed-off-by: Manohar Castelino <mcastelino@apple.com>
Signed-off-by: Eric Ernst <eric_ernst@apple.com>
This commit is contained in:
Manohar Castelino 2021-09-21 16:37:17 -07:00 committed by Eric Ernst
parent 76f1ce9e30
commit f434bcbf6c
8 changed files with 24 additions and 22 deletions

View File

@ -353,12 +353,12 @@ func (a *Acrn) setConfig(config *HypervisorConfig) error {
return nil return nil
} }
// createSandbox is the Hypervisor sandbox creation. // CreateVM is the VM creation
func (a *Acrn) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error { func (a *Acrn) CreateVM(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error {
// Save the tracing context // Save the tracing context
a.ctx = ctx 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() defer span.End()
if err := a.setup(ctx, id, hypervisorConfig); err != nil { if err := a.setup(ctx, id, hypervisorConfig); err != nil {

View File

@ -200,11 +200,11 @@ func (clh *cloudHypervisor) setConfig(config *HypervisorConfig) error {
} }
// For cloudHypervisor this call only sets the internal structure up. // For cloudHypervisor this call only sets the internal structure up.
// The VM will be created and started through startSandbox(). // The VM will be created and started through StartVM().
func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error { func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error {
clh.ctx = ctx 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 clh.ctx = newCtx
defer span.End() defer span.End()
@ -215,7 +215,7 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ
clh.id = id clh.id = id
clh.state.state = clhNotReady 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) virtiofsdSocketPath, err := clh.virtioFsSocketPath(clh.id)
if err != nil { if err != nil {
@ -223,7 +223,7 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ
} }
if clh.state.PID > 0 { 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{ clh.virtiofsd = &virtiofsd{
PID: clh.state.VirtiofsdPID, PID: clh.state.VirtiofsdPID,
sourcePath: filepath.Join(getSharePath(clh.id)), 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 // 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. // 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 // Make sure the kernel path is valid
kernelPath, err := clh.config.KernelAssetPath() kernelPath, err := clh.config.KernelAssetPath()

View File

@ -198,12 +198,12 @@ func (fc *firecracker) setConfig(config *HypervisorConfig) error {
return nil 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(). // 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 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() defer span.End()
//TODO: Check validity of the hypervisor config provided //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) 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 fc.netNSPath = networkNS.NetNsPath
// Till we create lower privileged kata user run as root // Till we create lower privileged kata user run as root

View File

@ -537,6 +537,8 @@ func (conf *HypervisorConfig) CheckTemplateConfig() error {
} }
func (conf *HypervisorConfig) Valid() error { func (conf *HypervisorConfig) Valid() error {
// Kata specific checks. Should be done outside the hypervisor
if conf.KernelPath == "" { if conf.KernelPath == "" {
return fmt.Errorf("Missing kernel path") return fmt.Errorf("Missing kernel path")
} }
@ -897,7 +899,7 @@ func generateVMSocket(id string, vmStogarePath string) (interface{}, error) {
// The default hypervisor implementation is Qemu. // The default hypervisor implementation is Qemu.
type hypervisor interface { type hypervisor interface {
setConfig(config *HypervisorConfig) error 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 StartVM(ctx context.Context, timeout int) error
// If wait is set, don't actively stop the sandbox: // If wait is set, don't actively stop the sandbox:

View File

@ -38,7 +38,7 @@ func (m *mockHypervisor) setConfig(config *HypervisorConfig) error {
return nil 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 { if err := m.setConfig(hypervisorConfig); err != nil {
return err return err
} }

View File

@ -476,15 +476,15 @@ func (q *qemu) setConfig(config *HypervisorConfig) error {
return nil return nil
} }
// createSandbox is the Hypervisor sandbox creation implementation for govmmQemu. // CreateVM is the Hypervisor VM creation implementation for govmmQemu.
func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error { func (q *qemu) CreateVM(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error {
// Save the tracing context // Save the tracing context
q.ctx = ctx 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() 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 { if err := q.setup(ctx, id, hypervisorConfig); err != nil {
return err return err
} }
@ -514,7 +514,6 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa
IOMMUPlatform: q.config.IOMMUPlatform, IOMMUPlatform: q.config.IOMMUPlatform,
} }
// MRC: Kata specific
kernelPath, err := q.config.KernelAssetPath() kernelPath, err := q.config.KernelAssetPath()
if err != nil { if err != nil {
return err return err
@ -525,6 +524,7 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa
return err return err
} }
// Breaks hypervisor abstration Has Kata Specific logic
kernel := govmmQemu.Kernel{ kernel := govmmQemu.Kernel{
Path: kernelPath, Path: kernelPath,
InitrdPath: initrdPath, InitrdPath: initrdPath,

View File

@ -556,7 +556,7 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
} }
// store doesn't require hypervisor to be stored immediately // 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 return nil, err
} }

View File

@ -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 return nil, err
} }