mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
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:
parent
76f1ce9e30
commit
f434bcbf6c
@ -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 {
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user