[Openstack] [PATCH] don't disconnect a mounted device

Serge E. Hallyn serge.hallyn at canonical.com
Fri Sep 30 21:42:46 UTC 2011


I'm sure the patch should be tweaked (helpers moved elsewhere, whatever)
but running euca-terminate-instances twice on an lxc container can cause
oopses on the host without this.

Signed-off-by: Serge Hallyn <serge.hallyn at canonical.com>
--

Index: nova-2011.3/nova/virt/disk.py
===================================================================
--- nova-2011.3.orig/nova/virt/disk.py	2011-09-30 16:29:43.806061035 -0500
+++ nova-2011.3/nova/virt/disk.py	2011-09-30 16:29:56.490061147 -0500
@@ -224,9 +224,30 @@
         return out.strip()
 
 
+def is_mounted(device):
+    f=open("/proc/mounts", "r")
+    for l in f.readlines():
+        fields = l.split()
+        if fields[0] == device:
+            f.close()
+            return true
+    f.close()
+    return false
+
+def is_stuck_mounted(device):
+    if is_mounted(device):
+        utils.execute('umount', device, run_as_root=True)
+    if is_mounted(device):
+        return true
+    return false
+
+
 def _unlink_device(device, nbd):
     """Unlink image from device using loopback or nbd"""
     if nbd:
+        if is_stuck_mounted(device):
+            raise exception.Error(_('Could not unmount device %s') % device)
+
         utils.execute('qemu-nbd', '-d', device, run_as_root=True)
         _free_device(device)
     else:




More information about the Openstack mailing list