github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/persist.go (about) 1 // Copyright (c) 2019 Huawei Corporation 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 6 package virtcontainers 7 8 import ( 9 "context" 10 "errors" 11 12 "github.com/kata-containers/runtime/virtcontainers/device/api" 13 exp "github.com/kata-containers/runtime/virtcontainers/experimental" 14 "github.com/kata-containers/runtime/virtcontainers/persist" 15 persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api" 16 "github.com/kata-containers/runtime/virtcontainers/store" 17 "github.com/kata-containers/runtime/virtcontainers/types" 18 "github.com/mitchellh/mapstructure" 19 ) 20 21 var ( 22 errContainerPersistNotExist = errors.New("container doesn't exist in persist data") 23 ) 24 25 func (s *Sandbox) dumpVersion(ss *persistapi.SandboxState) { 26 // New created sandbox has a uninitialized `PersistVersion` which should be set to current version when do the first saving; 27 // Old restored sandbox should keep its original version and shouldn't be modified any more after it's initialized. 28 ss.PersistVersion = s.state.PersistVersion 29 if ss.PersistVersion == 0 { 30 ss.PersistVersion = persistapi.CurPersistVersion 31 } 32 } 33 34 func (s *Sandbox) dumpState(ss *persistapi.SandboxState, cs map[string]persistapi.ContainerState) { 35 ss.SandboxContainer = s.id 36 ss.GuestMemoryBlockSizeMB = s.state.GuestMemoryBlockSizeMB 37 ss.GuestMemoryHotplugProbe = s.state.GuestMemoryHotplugProbe 38 ss.State = string(s.state.State) 39 ss.CgroupPath = s.state.CgroupPath 40 ss.CgroupPaths = s.state.CgroupPaths 41 42 for id, cont := range s.containers { 43 state := persistapi.ContainerState{} 44 if v, ok := cs[id]; ok { 45 state = v 46 } 47 state.State = string(cont.state.State) 48 state.Rootfs = persistapi.RootfsState{ 49 BlockDeviceID: cont.state.BlockDeviceID, 50 FsType: cont.state.Fstype, 51 } 52 state.CgroupPath = cont.state.CgroupPath 53 cs[id] = state 54 } 55 56 // delete removed containers 57 for id := range cs { 58 if _, ok := s.containers[id]; !ok { 59 delete(cs, id) 60 } 61 } 62 } 63 64 func (s *Sandbox) dumpHypervisor(ss *persistapi.SandboxState) { 65 ss.HypervisorState = s.hypervisor.save() 66 // BlockIndexMap will be moved from sandbox state to hypervisor state later 67 ss.HypervisorState.BlockIndexMap = s.state.BlockIndexMap 68 } 69 70 func deviceToDeviceState(devices []api.Device) (dss []persistapi.DeviceState) { 71 for _, dev := range devices { 72 dss = append(dss, dev.Save()) 73 } 74 return 75 } 76 77 func (s *Sandbox) dumpDevices(ss *persistapi.SandboxState, cs map[string]persistapi.ContainerState) { 78 ss.Devices = deviceToDeviceState(s.devManager.GetAllDevices()) 79 80 for id, cont := range s.containers { 81 state := persistapi.ContainerState{} 82 if v, ok := cs[id]; ok { 83 state = v 84 } 85 86 state.DeviceMaps = nil 87 for _, dev := range cont.devices { 88 state.DeviceMaps = append(state.DeviceMaps, persistapi.DeviceMap{ 89 ID: dev.ID, 90 ContainerPath: dev.ContainerPath, 91 FileMode: dev.FileMode, 92 UID: dev.UID, 93 GID: dev.GID, 94 }) 95 } 96 97 cs[id] = state 98 } 99 100 // delete removed containers 101 for id := range cs { 102 if _, ok := s.containers[id]; !ok { 103 delete(cs, id) 104 } 105 } 106 } 107 108 func (s *Sandbox) dumpProcess(cs map[string]persistapi.ContainerState) { 109 for id, cont := range s.containers { 110 state := persistapi.ContainerState{} 111 if v, ok := cs[id]; ok { 112 state = v 113 } 114 115 state.Process = persistapi.Process{ 116 Token: cont.process.Token, 117 Pid: cont.process.Pid, 118 StartTime: cont.process.StartTime, 119 } 120 121 cs[id] = state 122 } 123 124 // delete removed containers 125 for id := range cs { 126 if _, ok := s.containers[id]; !ok { 127 delete(cs, id) 128 } 129 } 130 } 131 132 func (s *Sandbox) dumpMounts(cs map[string]persistapi.ContainerState) { 133 for id, cont := range s.containers { 134 state := persistapi.ContainerState{} 135 if v, ok := cs[id]; ok { 136 state = v 137 } 138 139 for _, m := range cont.mounts { 140 state.Mounts = append(state.Mounts, persistapi.Mount{ 141 Source: m.Source, 142 Destination: m.Destination, 143 Options: m.Options, 144 HostPath: m.HostPath, 145 ReadOnly: m.ReadOnly, 146 BlockDeviceID: m.BlockDeviceID, 147 }) 148 } 149 150 cs[id] = state 151 } 152 153 // delete removed containers 154 for id := range cs { 155 if _, ok := s.containers[id]; !ok { 156 delete(cs, id) 157 } 158 } 159 } 160 161 func (s *Sandbox) dumpAgent(ss *persistapi.SandboxState) { 162 if s.agent != nil { 163 ss.AgentState = s.agent.save() 164 } 165 } 166 167 func (s *Sandbox) dumpNetwork(ss *persistapi.SandboxState) { 168 ss.Network = persistapi.NetworkInfo{ 169 NetNsPath: s.networkNS.NetNsPath, 170 NetmonPID: s.networkNS.NetmonPID, 171 NetNsCreated: s.networkNS.NetNsCreated, 172 } 173 for _, e := range s.networkNS.Endpoints { 174 ss.Network.Endpoints = append(ss.Network.Endpoints, e.save()) 175 } 176 } 177 178 func (s *Sandbox) dumpConfig(ss *persistapi.SandboxState) { 179 sconfig := s.config 180 ss.Config = persistapi.SandboxConfig{ 181 HypervisorType: string(sconfig.HypervisorType), 182 AgentType: string(sconfig.AgentType), 183 ProxyType: string(sconfig.ProxyType), 184 ProxyConfig: persistapi.ProxyConfig{ 185 Path: sconfig.ProxyConfig.Path, 186 Debug: sconfig.ProxyConfig.Debug, 187 }, 188 ShimType: string(sconfig.ShimType), 189 NetworkConfig: persistapi.NetworkConfig{ 190 NetNSPath: sconfig.NetworkConfig.NetNSPath, 191 NetNsCreated: sconfig.NetworkConfig.NetNsCreated, 192 DisableNewNetNs: sconfig.NetworkConfig.DisableNewNetNs, 193 InterworkingModel: int(sconfig.NetworkConfig.InterworkingModel), 194 }, 195 196 ShmSize: sconfig.ShmSize, 197 SharePidNs: sconfig.SharePidNs, 198 Stateful: sconfig.Stateful, 199 SystemdCgroup: sconfig.SystemdCgroup, 200 SandboxCgroupOnly: sconfig.SandboxCgroupOnly, 201 EnableAgentPidNs: sconfig.EnableAgentPidNs, 202 DisableGuestSeccomp: sconfig.DisableGuestSeccomp, 203 Cgroups: sconfig.Cgroups, 204 } 205 206 for _, e := range sconfig.Experimental { 207 ss.Config.Experimental = append(ss.Config.Experimental, e.Name) 208 } 209 210 ss.Config.HypervisorConfig = persistapi.HypervisorConfig{ 211 NumVCPUs: sconfig.HypervisorConfig.NumVCPUs, 212 DefaultMaxVCPUs: sconfig.HypervisorConfig.DefaultMaxVCPUs, 213 MemorySize: sconfig.HypervisorConfig.MemorySize, 214 DefaultBridges: sconfig.HypervisorConfig.DefaultBridges, 215 Msize9p: sconfig.HypervisorConfig.Msize9p, 216 MemSlots: sconfig.HypervisorConfig.MemSlots, 217 MemOffset: sconfig.HypervisorConfig.MemOffset, 218 VirtioMem: sconfig.HypervisorConfig.VirtioMem, 219 VirtioFSCacheSize: sconfig.HypervisorConfig.VirtioFSCacheSize, 220 KernelPath: sconfig.HypervisorConfig.KernelPath, 221 ImagePath: sconfig.HypervisorConfig.ImagePath, 222 InitrdPath: sconfig.HypervisorConfig.InitrdPath, 223 FirmwarePath: sconfig.HypervisorConfig.FirmwarePath, 224 MachineAccelerators: sconfig.HypervisorConfig.MachineAccelerators, 225 CPUFeatures: sconfig.HypervisorConfig.CPUFeatures, 226 HypervisorPath: sconfig.HypervisorConfig.HypervisorPath, 227 HypervisorPathList: sconfig.HypervisorConfig.HypervisorPathList, 228 HypervisorCtlPath: sconfig.HypervisorConfig.HypervisorCtlPath, 229 HypervisorCtlPathList: sconfig.HypervisorConfig.HypervisorCtlPathList, 230 JailerPath: sconfig.HypervisorConfig.JailerPath, 231 JailerPathList: sconfig.HypervisorConfig.JailerPathList, 232 BlockDeviceDriver: sconfig.HypervisorConfig.BlockDeviceDriver, 233 HypervisorMachineType: sconfig.HypervisorConfig.HypervisorMachineType, 234 MemoryPath: sconfig.HypervisorConfig.MemoryPath, 235 DevicesStatePath: sconfig.HypervisorConfig.DevicesStatePath, 236 EntropySource: sconfig.HypervisorConfig.EntropySource, 237 SharedFS: sconfig.HypervisorConfig.SharedFS, 238 VirtioFSDaemon: sconfig.HypervisorConfig.VirtioFSDaemon, 239 VirtioFSDaemonList: sconfig.HypervisorConfig.VirtioFSDaemonList, 240 VirtioFSCache: sconfig.HypervisorConfig.VirtioFSCache, 241 VirtioFSExtraArgs: sconfig.HypervisorConfig.VirtioFSExtraArgs[:], 242 BlockDeviceCacheSet: sconfig.HypervisorConfig.BlockDeviceCacheSet, 243 BlockDeviceCacheDirect: sconfig.HypervisorConfig.BlockDeviceCacheDirect, 244 BlockDeviceCacheNoflush: sconfig.HypervisorConfig.BlockDeviceCacheNoflush, 245 DisableBlockDeviceUse: sconfig.HypervisorConfig.DisableBlockDeviceUse, 246 EnableIOThreads: sconfig.HypervisorConfig.EnableIOThreads, 247 Debug: sconfig.HypervisorConfig.Debug, 248 MemPrealloc: sconfig.HypervisorConfig.MemPrealloc, 249 HugePages: sconfig.HypervisorConfig.HugePages, 250 FileBackedMemRootDir: sconfig.HypervisorConfig.FileBackedMemRootDir, 251 FileBackedMemRootList: sconfig.HypervisorConfig.FileBackedMemRootList, 252 Realtime: sconfig.HypervisorConfig.Realtime, 253 Mlock: sconfig.HypervisorConfig.Mlock, 254 DisableNestingChecks: sconfig.HypervisorConfig.DisableNestingChecks, 255 UseVSock: sconfig.HypervisorConfig.UseVSock, 256 DisableImageNvdimm: sconfig.HypervisorConfig.DisableImageNvdimm, 257 HotplugVFIOOnRootBus: sconfig.HypervisorConfig.HotplugVFIOOnRootBus, 258 PCIeRootPort: sconfig.HypervisorConfig.PCIeRootPort, 259 BootToBeTemplate: sconfig.HypervisorConfig.BootToBeTemplate, 260 BootFromTemplate: sconfig.HypervisorConfig.BootFromTemplate, 261 DisableVhostNet: sconfig.HypervisorConfig.DisableVhostNet, 262 EnableVhostUserStore: sconfig.HypervisorConfig.EnableVhostUserStore, 263 VhostUserStorePath: sconfig.HypervisorConfig.VhostUserStorePath, 264 VhostUserStorePathList: sconfig.HypervisorConfig.VhostUserStorePathList, 265 GuestHookPath: sconfig.HypervisorConfig.GuestHookPath, 266 VMid: sconfig.HypervisorConfig.VMid, 267 EnableAnnotations: sconfig.HypervisorConfig.EnableAnnotations, 268 } 269 270 if sconfig.AgentType == "kata" { 271 var sagent KataAgentConfig 272 err := mapstructure.Decode(sconfig.AgentConfig, &sagent) 273 if err != nil { 274 s.Logger().WithError(err).Error("internal error: KataAgentConfig failed to decode") 275 } else { 276 ss.Config.KataAgentConfig = &persistapi.KataAgentConfig{ 277 LongLiveConn: sagent.LongLiveConn, 278 UseVSock: sagent.UseVSock, 279 } 280 } 281 } 282 283 if sconfig.ShimType == "kataShim" { 284 var shim ShimConfig 285 err := mapstructure.Decode(sconfig.ShimConfig, &shim) 286 if err != nil { 287 s.Logger().WithError(err).Error("internal error: ShimConfig failed to decode") 288 } else { 289 ss.Config.KataShimConfig = &persistapi.ShimConfig{ 290 Path: shim.Path, 291 Debug: shim.Debug, 292 } 293 } 294 } 295 296 for _, contConf := range sconfig.Containers { 297 ss.Config.ContainerConfigs = append(ss.Config.ContainerConfigs, persistapi.ContainerConfig{ 298 ID: contConf.ID, 299 Annotations: contConf.Annotations, 300 RootFs: contConf.RootFs.Target, 301 Resources: contConf.Resources, 302 }) 303 } 304 } 305 306 func (s *Sandbox) Save() error { 307 var ( 308 ss = persistapi.SandboxState{} 309 cs = make(map[string]persistapi.ContainerState) 310 ) 311 312 s.dumpVersion(&ss) 313 s.dumpState(&ss, cs) 314 s.dumpHypervisor(&ss) 315 s.dumpDevices(&ss, cs) 316 s.dumpProcess(cs) 317 s.dumpMounts(cs) 318 s.dumpAgent(&ss) 319 s.dumpNetwork(&ss) 320 s.dumpConfig(&ss) 321 322 if err := s.newStore.ToDisk(ss, cs); err != nil { 323 return err 324 } 325 326 return nil 327 } 328 329 func (s *Sandbox) loadState(ss persistapi.SandboxState) { 330 s.state.PersistVersion = ss.PersistVersion 331 s.state.GuestMemoryBlockSizeMB = ss.GuestMemoryBlockSizeMB 332 s.state.BlockIndexMap = ss.HypervisorState.BlockIndexMap 333 s.state.State = types.StateString(ss.State) 334 s.state.CgroupPath = ss.CgroupPath 335 s.state.CgroupPaths = ss.CgroupPaths 336 s.state.GuestMemoryHotplugProbe = ss.GuestMemoryHotplugProbe 337 } 338 339 func (c *Container) loadContState(cs persistapi.ContainerState) { 340 c.state = types.ContainerState{ 341 State: types.StateString(cs.State), 342 BlockDeviceID: cs.Rootfs.BlockDeviceID, 343 Fstype: cs.Rootfs.FsType, 344 CgroupPath: cs.CgroupPath, 345 } 346 } 347 348 func (s *Sandbox) loadHypervisor(hs persistapi.HypervisorState) { 349 s.hypervisor.load(hs) 350 } 351 352 func (s *Sandbox) loadAgent(as persistapi.AgentState) { 353 if s.agent != nil { 354 s.agent.load(as) 355 } 356 } 357 358 func (s *Sandbox) loadDevices(devStates []persistapi.DeviceState) { 359 s.devManager.LoadDevices(devStates) 360 } 361 362 func (c *Container) loadContDevices(cs persistapi.ContainerState) { 363 c.devices = nil 364 for _, dev := range cs.DeviceMaps { 365 c.devices = append(c.devices, ContainerDevice{ 366 ID: dev.ID, 367 ContainerPath: dev.ContainerPath, 368 FileMode: dev.FileMode, 369 UID: dev.UID, 370 GID: dev.GID, 371 }) 372 } 373 } 374 375 func (c *Container) loadContMounts(cs persistapi.ContainerState) { 376 c.mounts = nil 377 for _, m := range cs.Mounts { 378 c.mounts = append(c.mounts, Mount{ 379 Source: m.Source, 380 Destination: m.Destination, 381 Options: m.Options, 382 HostPath: m.HostPath, 383 ReadOnly: m.ReadOnly, 384 BlockDeviceID: m.BlockDeviceID, 385 }) 386 } 387 } 388 389 func (c *Container) loadContProcess(cs persistapi.ContainerState) { 390 c.process = Process{ 391 Token: cs.Process.Token, 392 Pid: cs.Process.Pid, 393 StartTime: cs.Process.StartTime, 394 } 395 } 396 397 func (s *Sandbox) loadNetwork(netInfo persistapi.NetworkInfo) { 398 s.networkNS = NetworkNamespace{ 399 NetNsPath: netInfo.NetNsPath, 400 NetmonPID: netInfo.NetmonPID, 401 NetNsCreated: netInfo.NetNsCreated, 402 } 403 404 for _, e := range netInfo.Endpoints { 405 var ep Endpoint 406 switch EndpointType(e.Type) { 407 case PhysicalEndpointType: 408 ep = &PhysicalEndpoint{} 409 case VethEndpointType: 410 ep = &VethEndpoint{} 411 case VhostUserEndpointType: 412 ep = &VhostUserEndpoint{} 413 case BridgedMacvlanEndpointType: 414 ep = &BridgedMacvlanEndpoint{} 415 case MacvtapEndpointType: 416 ep = &MacvtapEndpoint{} 417 case TapEndpointType: 418 ep = &TapEndpoint{} 419 case IPVlanEndpointType: 420 ep = &IPVlanEndpoint{} 421 default: 422 s.Logger().WithField("endpoint-type", e.Type).Error("unknown endpoint type") 423 continue 424 } 425 ep.load(e) 426 s.networkNS.Endpoints = append(s.networkNS.Endpoints, ep) 427 } 428 } 429 430 // Restore will restore sandbox data from persist file on disk 431 func (s *Sandbox) Restore() error { 432 ss, _, err := s.newStore.FromDisk(s.id) 433 if err != nil { 434 return err 435 } 436 437 s.loadState(ss) 438 s.loadHypervisor(ss.HypervisorState) 439 s.loadDevices(ss.Devices) 440 s.loadAgent(ss.AgentState) 441 s.loadNetwork(ss.Network) 442 return nil 443 } 444 445 // Restore will restore container data from persist file on disk 446 func (c *Container) Restore() error { 447 _, css, err := c.sandbox.newStore.FromDisk(c.sandbox.id) 448 if err != nil { 449 return err 450 } 451 452 cs, ok := css[c.id] 453 if !ok { 454 return errContainerPersistNotExist 455 } 456 457 c.loadContState(cs) 458 c.loadContDevices(cs) 459 c.loadContProcess(cs) 460 c.loadContMounts(cs) 461 return nil 462 } 463 464 func loadSandboxConfig(id string) (*SandboxConfig, error) { 465 store, err := persist.GetDriver() 466 if err != nil || store == nil { 467 return nil, errors.New("failed to get fs persist driver") 468 } 469 470 ss, _, err := store.FromDisk(id) 471 if err != nil { 472 return nil, err 473 } 474 475 savedConf := ss.Config 476 sconfig := &SandboxConfig{ 477 ID: id, 478 HypervisorType: HypervisorType(savedConf.HypervisorType), 479 AgentType: AgentType(savedConf.AgentType), 480 ProxyType: ProxyType(savedConf.ProxyType), 481 ProxyConfig: ProxyConfig{ 482 Path: savedConf.ProxyConfig.Path, 483 Debug: savedConf.ProxyConfig.Debug, 484 }, 485 ShimType: ShimType(savedConf.ShimType), 486 NetworkConfig: NetworkConfig{ 487 NetNSPath: savedConf.NetworkConfig.NetNSPath, 488 NetNsCreated: savedConf.NetworkConfig.NetNsCreated, 489 DisableNewNetNs: savedConf.NetworkConfig.DisableNewNetNs, 490 InterworkingModel: NetInterworkingModel(savedConf.NetworkConfig.InterworkingModel), 491 }, 492 493 ShmSize: savedConf.ShmSize, 494 SharePidNs: savedConf.SharePidNs, 495 Stateful: savedConf.Stateful, 496 SystemdCgroup: savedConf.SystemdCgroup, 497 SandboxCgroupOnly: savedConf.SandboxCgroupOnly, 498 EnableAgentPidNs: savedConf.EnableAgentPidNs, 499 DisableGuestSeccomp: savedConf.DisableGuestSeccomp, 500 Cgroups: savedConf.Cgroups, 501 } 502 503 for _, name := range savedConf.Experimental { 504 sconfig.Experimental = append(sconfig.Experimental, *exp.Get(name)) 505 } 506 507 hconf := savedConf.HypervisorConfig 508 sconfig.HypervisorConfig = HypervisorConfig{ 509 NumVCPUs: hconf.NumVCPUs, 510 DefaultMaxVCPUs: hconf.DefaultMaxVCPUs, 511 MemorySize: hconf.MemorySize, 512 DefaultBridges: hconf.DefaultBridges, 513 Msize9p: hconf.Msize9p, 514 MemSlots: hconf.MemSlots, 515 MemOffset: hconf.MemOffset, 516 VirtioMem: hconf.VirtioMem, 517 VirtioFSCacheSize: hconf.VirtioFSCacheSize, 518 KernelPath: hconf.KernelPath, 519 ImagePath: hconf.ImagePath, 520 InitrdPath: hconf.InitrdPath, 521 FirmwarePath: hconf.FirmwarePath, 522 MachineAccelerators: hconf.MachineAccelerators, 523 CPUFeatures: hconf.CPUFeatures, 524 HypervisorPath: hconf.HypervisorPath, 525 HypervisorPathList: hconf.HypervisorPathList, 526 HypervisorCtlPath: hconf.HypervisorCtlPath, 527 HypervisorCtlPathList: hconf.HypervisorCtlPathList, 528 JailerPath: hconf.JailerPath, 529 JailerPathList: hconf.JailerPathList, 530 BlockDeviceDriver: hconf.BlockDeviceDriver, 531 HypervisorMachineType: hconf.HypervisorMachineType, 532 MemoryPath: hconf.MemoryPath, 533 DevicesStatePath: hconf.DevicesStatePath, 534 EntropySource: hconf.EntropySource, 535 SharedFS: hconf.SharedFS, 536 VirtioFSDaemon: hconf.VirtioFSDaemon, 537 VirtioFSDaemonList: hconf.VirtioFSDaemonList, 538 VirtioFSCache: hconf.VirtioFSCache, 539 VirtioFSExtraArgs: hconf.VirtioFSExtraArgs[:], 540 BlockDeviceCacheSet: hconf.BlockDeviceCacheSet, 541 BlockDeviceCacheDirect: hconf.BlockDeviceCacheDirect, 542 BlockDeviceCacheNoflush: hconf.BlockDeviceCacheNoflush, 543 DisableBlockDeviceUse: hconf.DisableBlockDeviceUse, 544 EnableIOThreads: hconf.EnableIOThreads, 545 Debug: hconf.Debug, 546 MemPrealloc: hconf.MemPrealloc, 547 HugePages: hconf.HugePages, 548 FileBackedMemRootDir: hconf.FileBackedMemRootDir, 549 FileBackedMemRootList: hconf.FileBackedMemRootList, 550 Realtime: hconf.Realtime, 551 Mlock: hconf.Mlock, 552 DisableNestingChecks: hconf.DisableNestingChecks, 553 UseVSock: hconf.UseVSock, 554 DisableImageNvdimm: hconf.DisableImageNvdimm, 555 HotplugVFIOOnRootBus: hconf.HotplugVFIOOnRootBus, 556 PCIeRootPort: hconf.PCIeRootPort, 557 BootToBeTemplate: hconf.BootToBeTemplate, 558 BootFromTemplate: hconf.BootFromTemplate, 559 DisableVhostNet: hconf.DisableVhostNet, 560 EnableVhostUserStore: hconf.EnableVhostUserStore, 561 VhostUserStorePath: hconf.VhostUserStorePath, 562 VhostUserStorePathList: hconf.VhostUserStorePathList, 563 GuestHookPath: hconf.GuestHookPath, 564 VMid: hconf.VMid, 565 EnableAnnotations: hconf.EnableAnnotations, 566 } 567 568 if savedConf.AgentType == "kata" { 569 sconfig.AgentConfig = KataAgentConfig{ 570 LongLiveConn: savedConf.KataAgentConfig.LongLiveConn, 571 UseVSock: savedConf.KataAgentConfig.UseVSock, 572 } 573 } 574 575 if savedConf.ShimType == "kataShim" { 576 sconfig.ShimConfig = ShimConfig{ 577 Path: savedConf.KataShimConfig.Path, 578 Debug: savedConf.KataShimConfig.Debug, 579 } 580 } 581 582 for _, contConf := range savedConf.ContainerConfigs { 583 sconfig.Containers = append(sconfig.Containers, ContainerConfig{ 584 ID: contConf.ID, 585 Annotations: contConf.Annotations, 586 Resources: contConf.Resources, 587 RootFs: RootFs{ 588 Target: contConf.RootFs, 589 }, 590 }) 591 } 592 return sconfig, nil 593 } 594 595 var oldstoreKey = struct{}{} 596 597 func loadSandboxConfigFromOldStore(ctx context.Context, sid string) (*SandboxConfig, context.Context, error) { 598 var config SandboxConfig 599 // We're bootstrapping 600 vcStore, err := store.NewVCSandboxStore(ctx, sid) 601 if err != nil { 602 return nil, ctx, err 603 } 604 605 if err := vcStore.Load(store.Configuration, &config); err != nil { 606 return nil, ctx, err 607 } 608 609 return &config, context.WithValue(ctx, oldstoreKey, true), nil 610 } 611 612 func useOldStore(ctx context.Context) bool { 613 v := ctx.Value(oldstoreKey) 614 return v != nil 615 }