File 0007-Fix-containerdisk-unmount-logic.patch of Package kubevirt.26844

From 0238e1e088de1190f242f489810e918a908e37d1 Mon Sep 17 00:00:00 2001
From: "L. Pivarc" <lpivarc@redhat.com>
Date: Tue, 9 Aug 2022 21:41:29 +0200
Subject: [PATCH] Fix containerdisk unmount logic

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>
---
 pkg/virt-handler/container-disk/mount.go | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/pkg/virt-handler/container-disk/mount.go b/pkg/virt-handler/container-disk/mount.go
index d28fe46fd..bc29127b5 100644
--- a/pkg/virt-handler/container-disk/mount.go
+++ b/pkg/virt-handler/container-disk/mount.go
@@ -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)
 			}
 		}
 	}
-- 
2.37.1

openSUSE Build Service is sponsored by