mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 00:07:16 +00:00
virtcontainers: add a stateful to FC struct
Add a 'sateful' variable to FC to indicate when it is called with cli or shimv2. Signed-off-by: lifupan <lifupan@gmail.com>
This commit is contained in:
parent
f2bbcf4eb6
commit
13a00a2cf2
@ -348,7 +348,7 @@ func (a *Acrn) createDummyVirtioBlkDev(devices []Device) ([]Device, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// createSandbox is the Hypervisor sandbox creation.
|
// createSandbox is the Hypervisor sandbox creation.
|
||||||
func (a *Acrn) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, store *store.VCStore) error {
|
func (a *Acrn) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, store *store.VCStore, stateful bool) error {
|
||||||
// Save the tracing context
|
// Save the tracing context
|
||||||
a.ctx = ctx
|
a.ctx = ctx
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ func TestAcrnCreateSandbox(t *testing.T) {
|
|||||||
//set PID to 1 to ignore hypercall to get UUID and set a random UUID
|
//set PID to 1 to ignore hypercall to get UUID and set a random UUID
|
||||||
a.state.PID = 1
|
a.state.PID = 1
|
||||||
a.state.UUID = "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"
|
a.state.UUID = "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"
|
||||||
err = a.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, nil)
|
err = a.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, nil, false)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Exactly(acrnConfig, a.config)
|
assert.Exactly(acrnConfig, a.config)
|
||||||
}
|
}
|
||||||
|
@ -141,8 +141,9 @@ type firecracker struct {
|
|||||||
config HypervisorConfig
|
config HypervisorConfig
|
||||||
pendingDevices []firecrackerDevice // Devices to be added when the FC API is ready
|
pendingDevices []firecrackerDevice // Devices to be added when the FC API is ready
|
||||||
|
|
||||||
state firecrackerState
|
state firecrackerState
|
||||||
jailed bool //Set to true if jailer is enabled
|
jailed bool //Set to true if jailer is enabled
|
||||||
|
stateful bool //Set to true if running with shimv2
|
||||||
}
|
}
|
||||||
|
|
||||||
type firecrackerDevice struct {
|
type firecrackerDevice struct {
|
||||||
@ -211,7 +212,7 @@ func (fc *firecracker) bindMount(ctx context.Context, source, destination string
|
|||||||
|
|
||||||
// For firecracker this call only sets the internal structure up.
|
// 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, vcStore *store.VCStore) error {
|
func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, vcStore *store.VCStore, stateful bool) error {
|
||||||
fc.ctx = ctx
|
fc.ctx = ctx
|
||||||
|
|
||||||
span, _ := fc.trace("createSandbox")
|
span, _ := fc.trace("createSandbox")
|
||||||
@ -223,6 +224,7 @@ func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS N
|
|||||||
fc.store = vcStore
|
fc.store = vcStore
|
||||||
fc.state.set(notReady)
|
fc.state.set(notReady)
|
||||||
fc.config = *hypervisorConfig
|
fc.config = *hypervisorConfig
|
||||||
|
fc.stateful = stateful
|
||||||
|
|
||||||
// When running with jailer all resources need to be under
|
// When running with jailer all resources need to be under
|
||||||
// a specific location and that location needs to have
|
// a specific location and that location needs to have
|
||||||
|
@ -716,7 +716,7 @@ func generateVMSocket(id string, useVsock bool) (interface{}, error) {
|
|||||||
// hypervisor is the virtcontainers hypervisor interface.
|
// hypervisor is the virtcontainers hypervisor interface.
|
||||||
// The default hypervisor implementation is Qemu.
|
// The default hypervisor implementation is Qemu.
|
||||||
type hypervisor interface {
|
type hypervisor interface {
|
||||||
createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, store *store.VCStore) error
|
createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, store *store.VCStore, stateful bool) error
|
||||||
startSandbox(timeout int) error
|
startSandbox(timeout int) error
|
||||||
stopSandbox() error
|
stopSandbox() error
|
||||||
pauseSandbox() error
|
pauseSandbox() error
|
||||||
|
@ -27,7 +27,7 @@ func (m *mockHypervisor) hypervisorConfig() HypervisorConfig {
|
|||||||
return HypervisorConfig{}
|
return HypervisorConfig{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockHypervisor) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, store *store.VCStore) error {
|
func (m *mockHypervisor) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, store *store.VCStore, stateful bool) error {
|
||||||
err := hypervisorConfig.valid()
|
err := hypervisorConfig.valid()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -31,7 +31,7 @@ func TestMockHypervisorCreateSandbox(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// wrong config
|
// wrong config
|
||||||
err := m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig, nil)
|
err := m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig, nil, false)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
sandbox.config.HypervisorConfig = HypervisorConfig{
|
sandbox.config.HypervisorConfig = HypervisorConfig{
|
||||||
@ -40,7 +40,7 @@ func TestMockHypervisorCreateSandbox(t *testing.T) {
|
|||||||
HypervisorPath: fmt.Sprintf("%s/%s", testDir, testHypervisor),
|
HypervisorPath: fmt.Sprintf("%s/%s", testDir, testHypervisor),
|
||||||
}
|
}
|
||||||
|
|
||||||
err = m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig, nil)
|
err = m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig, nil, false)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,7 +463,7 @@ func (q *qemu) setupFileBackedMem(knobs *govmmQemu.Knobs, memory *govmmQemu.Memo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// createSandbox is the Hypervisor sandbox creation implementation for govmmQemu.
|
// createSandbox is the Hypervisor sandbox creation implementation for govmmQemu.
|
||||||
func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, vcStore *store.VCStore) error {
|
func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, vcStore *store.VCStore, stateful bool) error {
|
||||||
// Save the tracing context
|
// Save the tracing context
|
||||||
q.ctx = ctx
|
q.ctx = ctx
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ func TestQemuCreateSandbox(t *testing.T) {
|
|||||||
parentDir := store.SandboxConfigurationRootPath(sandbox.id)
|
parentDir := store.SandboxConfigurationRootPath(sandbox.id)
|
||||||
assert.NoError(os.MkdirAll(parentDir, store.DirMode))
|
assert.NoError(os.MkdirAll(parentDir, store.DirMode))
|
||||||
|
|
||||||
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, sandbox.store)
|
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, sandbox.store, false)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NoError(os.RemoveAll(parentDir))
|
assert.NoError(os.RemoveAll(parentDir))
|
||||||
assert.Exactly(qemuConfig, q.config)
|
assert.Exactly(qemuConfig, q.config)
|
||||||
@ -131,7 +131,7 @@ func TestQemuCreateSandboxMissingParentDirFail(t *testing.T) {
|
|||||||
parentDir := store.SandboxConfigurationRootPath(sandbox.id)
|
parentDir := store.SandboxConfigurationRootPath(sandbox.id)
|
||||||
assert.NoError(os.RemoveAll(parentDir))
|
assert.NoError(os.RemoveAll(parentDir))
|
||||||
|
|
||||||
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, sandbox.store)
|
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, sandbox.store, false)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,7 +429,7 @@ func TestQemuFileBackedMem(t *testing.T) {
|
|||||||
|
|
||||||
q := &qemu{}
|
q := &qemu{}
|
||||||
sandbox.config.HypervisorConfig.SharedFS = config.VirtioFS
|
sandbox.config.HypervisorConfig.SharedFS = config.VirtioFS
|
||||||
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, sandbox.store)
|
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, sandbox.store, false)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
assert.Equal(q.qemuConfig.Knobs.FileBackedMem, true)
|
assert.Equal(q.qemuConfig.Knobs.FileBackedMem, true)
|
||||||
@ -445,7 +445,7 @@ func TestQemuFileBackedMem(t *testing.T) {
|
|||||||
sandbox.config.HypervisorConfig.SharedFS = config.VirtioFS
|
sandbox.config.HypervisorConfig.SharedFS = config.VirtioFS
|
||||||
sandbox.config.HypervisorConfig.MemoryPath = fallbackFileBackedMemDir
|
sandbox.config.HypervisorConfig.MemoryPath = fallbackFileBackedMemDir
|
||||||
|
|
||||||
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, sandbox.store)
|
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, sandbox.store, false)
|
||||||
|
|
||||||
expectErr := errors.New("VM templating has been enabled with either virtio-fs or file backed memory and this configuration will not work")
|
expectErr := errors.New("VM templating has been enabled with either virtio-fs or file backed memory and this configuration will not work")
|
||||||
assert.Equal(expectErr.Error(), err.Error())
|
assert.Equal(expectErr.Error(), err.Error())
|
||||||
@ -456,7 +456,7 @@ func TestQemuFileBackedMem(t *testing.T) {
|
|||||||
|
|
||||||
q = &qemu{}
|
q = &qemu{}
|
||||||
sandbox.config.HypervisorConfig.FileBackedMemRootDir = "/tmp/xyzabc"
|
sandbox.config.HypervisorConfig.FileBackedMemRootDir = "/tmp/xyzabc"
|
||||||
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, sandbox.store)
|
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, sandbox.store, false)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Equal(q.qemuConfig.Knobs.FileBackedMem, false)
|
assert.Equal(q.qemuConfig.Knobs.FileBackedMem, false)
|
||||||
assert.Equal(q.qemuConfig.Knobs.MemShared, false)
|
assert.Equal(q.qemuConfig.Knobs.MemShared, false)
|
||||||
|
@ -569,7 +569,7 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
|
|||||||
s.Restore()
|
s.Restore()
|
||||||
|
|
||||||
// new store doesn't require hypervisor to be stored immediately
|
// new store doesn't require hypervisor to be stored immediately
|
||||||
if err = s.hypervisor.createSandbox(ctx, s.id, s.networkNS, &sandboxConfig.HypervisorConfig, nil); err != nil {
|
if err = s.hypervisor.createSandbox(ctx, s.id, s.networkNS, &sandboxConfig.HypervisorConfig, nil, s.stateful); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -591,7 +591,7 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
|
|||||||
s.state = state
|
s.state = state
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = s.hypervisor.createSandbox(ctx, s.id, s.networkNS, &sandboxConfig.HypervisorConfig, s.store); err != nil {
|
if err = s.hypervisor.createSandbox(ctx, s.id, s.networkNS, &sandboxConfig.HypervisorConfig, s.store, s.stateful); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ func NewVM(ctx context.Context, config VMConfig) (*VM, error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err = hypervisor.createSandbox(ctx, id, NetworkNamespace{}, &config.HypervisorConfig, vcStore); err != nil {
|
if err = hypervisor.createSandbox(ctx, id, NetworkNamespace{}, &config.HypervisorConfig, vcStore, false); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user