mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 00:37:24 +00:00
Merge pull request #2118 from amshinde/load-state-early
Load state early so that hypervisor can store the correct state
This commit is contained in:
commit
04489fec2d
@ -477,34 +477,13 @@ func createSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Fac
|
|||||||
s.Logger().WithField("features", s.config.Experimental).Infof("Enable experimental features")
|
s.Logger().WithField("features", s.config.Experimental).Infof("Enable experimental features")
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.supportNewStore() {
|
// Sandbox state has been loaded from storage.
|
||||||
// Restored successfully from newstore before.
|
// If the Stae is not empty, this is a re-creation, i.e.
|
||||||
if s.state.State != "" {
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Fetch sandbox network to be able to access it from the sandbox structure.
|
|
||||||
var networkNS NetworkNamespace
|
|
||||||
if err := s.store.Load(store.Network, &networkNS); err == nil {
|
|
||||||
s.networkNS = networkNS
|
|
||||||
}
|
|
||||||
|
|
||||||
devices, err := s.store.LoadDevices()
|
|
||||||
if err != nil {
|
|
||||||
s.Logger().WithError(err).WithField("sandboxid", s.id).Warning("load sandbox devices failed")
|
|
||||||
}
|
|
||||||
s.devManager = deviceManager.NewDeviceManager(sandboxConfig.HypervisorConfig.BlockDeviceDriver, devices)
|
|
||||||
|
|
||||||
// We first try to fetch the sandbox state from storage.
|
|
||||||
// If it exists, this means this is a re-creation, i.e.
|
|
||||||
// we don't need to talk to the guest's agent, but only
|
// we don't need to talk to the guest's agent, but only
|
||||||
// want to create the sandbox and its containers in memory.
|
// want to create the sandbox and its containers in memory.
|
||||||
state, err := s.store.LoadState()
|
if s.state.State != "" {
|
||||||
if err == nil && state.State != "" {
|
|
||||||
s.state = state
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Below code path is called only during create, because of earlier check.
|
// Below code path is called only during create, because of earlier check.
|
||||||
if err := s.agent.createSandbox(s); err != nil {
|
if err := s.agent.createSandbox(s); err != nil {
|
||||||
@ -588,6 +567,24 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Fetch sandbox network to be able to access it from the sandbox structure.
|
||||||
|
var networkNS NetworkNamespace
|
||||||
|
if err = s.store.Load(store.Network, &networkNS); err == nil {
|
||||||
|
s.networkNS = networkNS
|
||||||
|
}
|
||||||
|
|
||||||
|
devices, err := s.store.LoadDevices()
|
||||||
|
if err != nil {
|
||||||
|
s.Logger().WithError(err).WithField("sandboxid", s.id).Warning("load sandbox devices failed")
|
||||||
|
}
|
||||||
|
s.devManager = deviceManager.NewDeviceManager(sandboxConfig.HypervisorConfig.BlockDeviceDriver, devices)
|
||||||
|
|
||||||
|
// Load sandbox state. The hypervisor.createSandbox call, may need to access statei.
|
||||||
|
state, err := s.store.LoadState()
|
||||||
|
if err == nil {
|
||||||
|
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); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user