mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 15:57:09 +00:00
vc: Detach device when unable to store sandbox device
In Container#mountSharedDirMounts, if sandbox.storeSandboxDevices() returns error, we should detach the device. Fixes #2301 Signed-off-by: Ted Yu yuzhihong@gmail.com
This commit is contained in:
parent
d11696de9a
commit
1f957e1b87
@ -495,9 +495,17 @@ func (c *Container) shareFiles(m Mount, idx int, hostSharedDir, guestSharedDir s
|
|||||||
// It also updates the container mount list with the HostPath info, and store
|
// It also updates the container mount list with the HostPath info, and store
|
||||||
// container mounts to the storage. This way, we will have the HostPath info
|
// container mounts to the storage. This way, we will have the HostPath info
|
||||||
// available when we will need to unmount those mounts.
|
// available when we will need to unmount those mounts.
|
||||||
func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) (map[string]Mount, map[string]Mount, error) {
|
func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) (sharedDirMounts map[string]Mount, ignoredMounts map[string]Mount, err error) {
|
||||||
sharedDirMounts := make(map[string]Mount)
|
sharedDirMounts = make(map[string]Mount)
|
||||||
ignoredMounts := make(map[string]Mount)
|
ignoredMounts = make(map[string]Mount)
|
||||||
|
var devicesToDetach []string
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
for _, id := range devicesToDetach {
|
||||||
|
c.sandbox.devManager.DetachDevice(id, c.sandbox)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
for idx, m := range c.mounts {
|
for idx, m := range c.mounts {
|
||||||
// Skip mounting certain system paths from the source on the host side
|
// Skip mounting certain system paths from the source on the host side
|
||||||
// into the container as it does not make sense to do so.
|
// into the container as it does not make sense to do so.
|
||||||
@ -521,9 +529,10 @@ func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) (
|
|||||||
// instead of passing this as a shared mount.
|
// instead of passing this as a shared mount.
|
||||||
if len(m.BlockDeviceID) > 0 {
|
if len(m.BlockDeviceID) > 0 {
|
||||||
// Attach this block device, all other devices passed in the config have been attached at this point
|
// Attach this block device, all other devices passed in the config have been attached at this point
|
||||||
if err := c.sandbox.devManager.AttachDevice(m.BlockDeviceID, c.sandbox); err != nil {
|
if err = c.sandbox.devManager.AttachDevice(m.BlockDeviceID, c.sandbox); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
devicesToDetach = append(devicesToDetach, m.BlockDeviceID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,7 +543,9 @@ func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) (
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
guestDest, ignore, err := c.shareFiles(m, idx, hostSharedDir, guestSharedDir)
|
var ignore bool
|
||||||
|
var guestDest string
|
||||||
|
guestDest, ignore, err = c.shareFiles(m, idx, hostSharedDir, guestSharedDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user