Skip to content

Commit

Permalink
Fix containerdisk unmount logic
Browse files Browse the repository at this point in the history
It is possible that record of mount is already
unmouted and therefore the target path does
not exists.

Signed-off-by: L. Pivarc <lpivarc@redhat.com>
  • Loading branch information
xpivarc authored and kubevirt-bot committed Aug 11, 2022
1 parent 6c0221d commit 37c0e62
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pkg/virt-handler/container-disk/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,19 +351,22 @@ func (m *mounter) Unmount(vmi *v1.VirtualMachineInstance) error {
log.DefaultLogger().Object(vmi).Infof("Found container disk mount entries")
for _, entry := range record.MountTargetEntries {
log.DefaultLogger().Object(vmi).Infof("Looking to see if containerdisk is mounted at path %s", entry.TargetFile)
path, err := safepath.NewFileNoFollow(entry.TargetFile)
file, err := safepath.NewFileNoFollow(entry.TargetFile)
if err != nil {
return fmt.Errorf(failedCheckMountPointFmt, path, err)
if os.IsNotExist(err) {
continue
}
return fmt.Errorf(failedCheckMountPointFmt, entry.TargetFile, err)
}
_ = path.Close()
if mounted, err := isolation.IsMounted(path.Path()); err != nil {
return fmt.Errorf(failedCheckMountPointFmt, path, err)
_ = file.Close()
if mounted, err := isolation.IsMounted(file.Path()); err != nil {
return fmt.Errorf(failedCheckMountPointFmt, file, err)
} else if mounted {
log.DefaultLogger().Object(vmi).Infof("unmounting container disk at path %s", path)
log.DefaultLogger().Object(vmi).Infof("unmounting container disk at path %s", file)
// #nosec No risk for attacket injection. Parameters are predefined strings
out, err := virt_chroot.UmountChroot(path.Path()).CombinedOutput()
out, err := virt_chroot.UmountChroot(file.Path()).CombinedOutput()
if err != nil {
return fmt.Errorf(failedUnmountFmt, path, string(out), err)
return fmt.Errorf(failedUnmountFmt, file, string(out), err)
}
}
}
Expand Down

0 comments on commit 37c0e62

Please sign in to comment.