Przeglądaj źródła

Fix 'target is busy' when dismounting '/dev' from worker instance.

When unmounting /dev, 'target is busy' error mostly appears if whether:
- There are mountpoints inside the target directory;
- Running processes use the target directory, preventing it from unmonting.
This patch makes sure no processes use the chroot directory while dismounting OS,
and that the mountpoints are being unmounted in a proper order.
Daniel Vincze 6 lat temu
rodzic
commit
813b3ac417
1 zmienionych plików z 10 dodań i 1 usunięć
  1. 10 1
      coriolis/osmorphing/osmount/base.py

+ 10 - 1
coriolis/osmorphing/osmount/base.py

@@ -469,16 +469,25 @@ class BaseLinuxOSMountTools(BaseSSHOSMountTools):
         return os_root_dir, os_root_device
 
     def dismount_os(self, root_dir):
+        self._exec_cmd('sudo fuser --kill --mount %s || true' % root_dir)
         mounted_fs = self._get_mount_destinations()
         # Sort all mounted filesystems by length. This will ensure that
         # the first in the list is a subfolder of the next in the list,
         # and we unmount them in the proper order
-        mounted_fs = list(reversed(sorted(mounted_fs)))
+        mounted_fs = list(reversed(sorted(mounted_fs, key=len)))
         for d in mounted_fs:
+            # umount these two at the very end
+            if d.endswith('/dev') or d.rstrip('/') == root_dir.rstrip('/'):
+                continue
             if d.startswith(root_dir):
                 # mounted filesystem is a subfolder of our root_dir
                 self._exec_cmd('sudo umount %s' % d)
 
+        dev_fs = "%s/%s" % (root_dir.rstrip('/'), "dev")
+        self._exec_cmd('mountpoint -q %s && sudo umount %s' % (dev_fs, dev_fs))
+        self._exec_cmd(
+            'mountpoint -q %s && sudo umount %s' % (root_dir, root_dir))
+
     def set_proxy(self, proxy_settings):
         url = proxy_settings.get('url')
         if not url: