Skip to content

Commit

Permalink
runtime: delete Stateful from SandboxConfig
Browse files Browse the repository at this point in the history
Since all containers are started from shim v2, `Stateful` is not needed.

Fixes: kata-containers#332

Signed-off-by: bin liu <bin@hyper.sh>
  • Loading branch information
liubin committed Jul 8, 2020
1 parent 069505e commit 3cf8b47
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 70 deletions.
2 changes: 0 additions & 2 deletions src/runtime/pkg/katautils/create.go
Expand Up @@ -113,8 +113,6 @@ func CreateSandbox(ctx context.Context, vci vc.VC, ociSpec specs.Spec, runtimeCo
return nil, vc.Process{}, err
}

sandboxConfig.Stateful = true

if err := checkForFIPS(&sandboxConfig); err != nil {
return nil, vc.Process{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/virtcontainers/acrn.go
Expand Up @@ -349,7 +349,7 @@ func (a *Acrn) createDummyVirtioBlkDev(devices []Device) ([]Device, error) {
}

// createSandbox is the Hypervisor sandbox creation.
func (a *Acrn) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, stateful bool) error {
func (a *Acrn) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error {
// Save the tracing context
a.ctx = ctx

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/virtcontainers/acrn_test.go
Expand Up @@ -237,7 +237,7 @@ func TestAcrnCreateSandbox(t *testing.T) {
//set PID to 1 to ignore hypercall to get UUID and set a random UUID
a.state.PID = 1
a.state.UUID = "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"
err = a.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, false)
err = a.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig)
assert.NoError(err)
assert.Exactly(acrnConfig, a.config)
}
Expand Down
25 changes: 0 additions & 25 deletions src/runtime/virtcontainers/api.go
Expand Up @@ -62,9 +62,6 @@ func CreateSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Fac
defer span.Finish()

s, err := createSandboxFromConfig(ctx, sandboxConfig, factory)
if err == nil {
s.releaseStatelessSandbox()
}

return s, err
}
Expand Down Expand Up @@ -157,7 +154,6 @@ func DeleteSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
if err != nil {
return nil, err
}
defer s.releaseStatelessSandbox()

// Delete it.
if err := s.Delete(); err != nil {
Expand Down Expand Up @@ -227,7 +223,6 @@ func StartSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
if err != nil {
return nil, err
}
defer s.releaseStatelessSandbox()

// Start it
err = s.Start()
Expand Down Expand Up @@ -263,7 +258,6 @@ func StopSandbox(ctx context.Context, sandboxID string, force bool) (VCSandbox,
if err != nil {
return nil, err
}
defer s.releaseStatelessSandbox()

// Stop it.
err = s.Stop(force)
Expand All @@ -289,7 +283,6 @@ func RunSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
if err != nil {
return nil, err
}
defer s.releaseStatelessSandbox()

unlock, err := rwLockSandbox(s.id)
if err != nil {
Expand Down Expand Up @@ -365,7 +358,6 @@ func StatusSandbox(ctx context.Context, sandboxID string) (SandboxStatus, error)
if err != nil {
return SandboxStatus{}, err
}
defer s.releaseStatelessSandbox()

var contStatusList []ContainerStatus
for _, container := range s.containers {
Expand Down Expand Up @@ -409,7 +401,6 @@ func CreateContainer(ctx context.Context, sandboxID string, containerConfig Cont
if err != nil {
return nil, nil, err
}
defer s.releaseStatelessSandbox()

c, err := s.CreateContainer(containerConfig)
if err != nil {
Expand Down Expand Up @@ -448,7 +439,6 @@ func DeleteContainer(ctx context.Context, sandboxID, containerID string) (VCCont
if err != nil {
return nil, err
}
defer s.releaseStatelessSandbox()

return s.DeleteContainer(containerID)
}
Expand Down Expand Up @@ -477,7 +467,6 @@ func StartContainer(ctx context.Context, sandboxID, containerID string) (VCConta
if err != nil {
return nil, err
}
defer s.releaseStatelessSandbox()

return s.StartContainer(containerID)
}
Expand Down Expand Up @@ -506,7 +495,6 @@ func StopContainer(ctx context.Context, sandboxID, containerID string) (VCContai
if err != nil {
return nil, err
}
defer s.releaseStatelessSandbox()

return s.StopContainer(containerID, false)
}
Expand Down Expand Up @@ -535,7 +523,6 @@ func EnterContainer(ctx context.Context, sandboxID, containerID string, cmd type
if err != nil {
return nil, nil, nil, err
}
defer s.releaseStatelessSandbox()

c, process, err := s.EnterContainer(containerID, cmd)
if err != nil {
Expand Down Expand Up @@ -569,7 +556,6 @@ func StatusContainer(ctx context.Context, sandboxID, containerID string) (Contai
if err != nil {
return ContainerStatus{}, err
}
defer s.releaseStatelessSandbox()

return statusContainer(s, containerID)
}
Expand Down Expand Up @@ -616,7 +602,6 @@ func KillContainer(ctx context.Context, sandboxID, containerID string, signal sy
if err != nil {
return err
}
defer s.releaseStatelessSandbox()

return s.KillContainer(containerID, signal, all)
}
Expand Down Expand Up @@ -645,7 +630,6 @@ func ProcessListContainer(ctx context.Context, sandboxID, containerID string, op
if err != nil {
return nil, err
}
defer s.releaseStatelessSandbox()

return s.ProcessListContainer(containerID, options)
}
Expand Down Expand Up @@ -674,7 +658,6 @@ func UpdateContainer(ctx context.Context, sandboxID, containerID string, resourc
if err != nil {
return err
}
defer s.releaseStatelessSandbox()

return s.UpdateContainer(containerID, resources)
}
Expand Down Expand Up @@ -703,7 +686,6 @@ func StatsContainer(ctx context.Context, sandboxID, containerID string) (Contain
if err != nil {
return ContainerStats{}, err
}
defer s.releaseStatelessSandbox()

return s.StatsContainer(containerID)
}
Expand All @@ -728,7 +710,6 @@ func StatsSandbox(ctx context.Context, sandboxID string) (SandboxStats, []Contai
if err != nil {
return SandboxStats{}, []ContainerStats{}, err
}
defer s.releaseStatelessSandbox()

sandboxStats, err := s.Stats()
if err != nil {
Expand Down Expand Up @@ -766,7 +747,6 @@ func togglePauseContainer(ctx context.Context, sandboxID, containerID string, pa
if err != nil {
return err
}
defer s.releaseStatelessSandbox()

if pause {
return s.PauseContainer(containerID)
Expand Down Expand Up @@ -810,7 +790,6 @@ func AddDevice(ctx context.Context, sandboxID string, info deviceConfig.DeviceIn
if err != nil {
return nil, err
}
defer s.releaseStatelessSandbox()

return s.AddDevice(info)
}
Expand All @@ -830,7 +809,6 @@ func toggleInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interfa
if err != nil {
return nil, err
}
defer s.releaseStatelessSandbox()

if add {
return s.AddInterface(inf)
Expand Down Expand Up @@ -874,7 +852,6 @@ func ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface
if err != nil {
return nil, err
}
defer s.releaseStatelessSandbox()

return s.ListInterfaces()
}
Expand All @@ -898,7 +875,6 @@ func UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route
if err != nil {
return nil, err
}
defer s.releaseStatelessSandbox()

return s.UpdateRoutes(routes)
}
Expand All @@ -922,7 +898,6 @@ func ListRoutes(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error)
if err != nil {
return nil, err
}
defer s.releaseStatelessSandbox()

return s.ListRoutes()
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/virtcontainers/clh.go
Expand Up @@ -161,7 +161,7 @@ func (clh *cloudHypervisor) checkVersion() 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, stateful bool) error {
func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error {
clh.ctx = ctx

span, _ := clh.trace("createSandbox")
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/virtcontainers/clh_test.go
Expand Up @@ -241,7 +241,7 @@ func TestClhCreateSandbox(t *testing.T) {
},
}

err = clh.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, false)
err = clh.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig)
assert.NoError(err)
assert.Exactly(clhConfig, clh.config)
}
Expand Down
14 changes: 6 additions & 8 deletions src/runtime/virtcontainers/fc.go
Expand Up @@ -149,9 +149,8 @@ type firecracker struct {
config HypervisorConfig
pendingDevices []firecrackerDevice // Devices to be added before the FC VM ready

state firecrackerState
jailed bool //Set to true if jailer is enabled
stateful bool //Set to true if running with shimv2
state firecrackerState
jailed bool //Set to true if jailer is enabled

fcConfigPath string
fcConfig *types.FcConfig // Parameters configured before VM starts
Expand Down Expand Up @@ -196,7 +195,7 @@ func (fc *firecracker) truncateID(id string) string {

// 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, stateful bool) error {
func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error {
fc.ctx = ctx

span, _ := fc.trace("createSandbox")
Expand All @@ -207,7 +206,6 @@ func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS N
fc.id = fc.truncateID(id)
fc.state.set(notReady)
fc.config = *hypervisorConfig
fc.stateful = stateful

// When running with jailer all resources need to be under
// a specific location and that location needs to have
Expand Down Expand Up @@ -367,7 +365,7 @@ func (fc *firecracker) fcInit(timeout int) error {
return err
}

if !fc.config.Debug && fc.stateful {
if !fc.config.Debug {
args = append(args, "--daemonize")
}

Expand Down Expand Up @@ -399,7 +397,7 @@ func (fc *firecracker) fcInit(timeout int) error {
cmd = exec.Command(fc.config.HypervisorPath, args...)
}

if fc.config.Debug && fc.stateful {
if fc.config.Debug {
stdin, err := fc.watchConsole()
if err != nil {
return err
Expand Down Expand Up @@ -697,7 +695,7 @@ func (fc *firecracker) fcInitConfiguration() error {
return err
}

if fc.config.Debug && fc.stateful {
if fc.config.Debug {
fcKernelParams = append(fcKernelParams, Param{"console", "ttyS0"})
} else {
fcKernelParams = append(fcKernelParams, []Param{
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/virtcontainers/hypervisor.go
Expand Up @@ -776,7 +776,7 @@ func generateVMSocket(id string, useVsock bool, vmStogarePath string) (interface
// hypervisor is the virtcontainers hypervisor interface.
// The default hypervisor implementation is Qemu.
type hypervisor interface {
createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, stateful bool) error
createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error
startSandbox(timeout int) error
stopSandbox() error
pauseSandbox() error
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/virtcontainers/mock_hypervisor.go
Expand Up @@ -26,7 +26,7 @@ func (m *mockHypervisor) hypervisorConfig() HypervisorConfig {
return HypervisorConfig{}
}

func (m *mockHypervisor) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, stateful bool) error {
func (m *mockHypervisor) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error {
err := hypervisorConfig.valid()
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/virtcontainers/mock_hypervisor_test.go
Expand Up @@ -31,7 +31,7 @@ func TestMockHypervisorCreateSandbox(t *testing.T) {
ctx := context.Background()

// wrong config
err := m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig, false)
err := m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig)
assert.Error(err)

sandbox.config.HypervisorConfig = HypervisorConfig{
Expand All @@ -40,7 +40,7 @@ func TestMockHypervisorCreateSandbox(t *testing.T) {
HypervisorPath: fmt.Sprintf("%s/%s", testDir, testHypervisor),
}

err = m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig, false)
err = m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig)
assert.NoError(err)
}

Expand Down
2 changes: 0 additions & 2 deletions src/runtime/virtcontainers/persist.go
Expand Up @@ -190,7 +190,6 @@ func (s *Sandbox) dumpConfig(ss *persistapi.SandboxState) {

ShmSize: sconfig.ShmSize,
SharePidNs: sconfig.SharePidNs,
Stateful: sconfig.Stateful,
SystemdCgroup: sconfig.SystemdCgroup,
SandboxCgroupOnly: sconfig.SandboxCgroupOnly,
DisableGuestSeccomp: sconfig.DisableGuestSeccomp,
Expand Down Expand Up @@ -458,7 +457,6 @@ func loadSandboxConfig(id string) (*SandboxConfig, error) {

ShmSize: savedConf.ShmSize,
SharePidNs: savedConf.SharePidNs,
Stateful: savedConf.Stateful,
SystemdCgroup: savedConf.SystemdCgroup,
SandboxCgroupOnly: savedConf.SandboxCgroupOnly,
DisableGuestSeccomp: savedConf.DisableGuestSeccomp,
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/virtcontainers/qemu.go
Expand Up @@ -459,7 +459,7 @@ func (q *qemu) setupFileBackedMem(knobs *govmmQemu.Knobs, memory *govmmQemu.Memo
}

// createSandbox is the Hypervisor sandbox creation implementation for govmmQemu.
func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, stateful bool) error {
func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error {
// Save the tracing context
q.ctx = ctx

Expand Down

0 comments on commit 3cf8b47

Please sign in to comment.