Deactivate and reactivate LVs 0.4.19
authorAlexander Chernyakhovsky <achernya@mit.edu>
Mon, 22 Jul 2013 07:13:43 +0000 (03:13 -0400)
committerAlexander Chernyakhovsky <achernya@mit.edu>
Mon, 22 Jul 2013 07:13:43 +0000 (03:13 -0400)
debian/changelog
host/usr/sbin/invirt-lvm

index 0c4f96a..5408670 100644 (file)
@@ -1,3 +1,9 @@
+invirt-remote (0.4.19) precise; urgency=low
+
+  * New (c)lvm requires that an LV be deactivated before renamed or resized.
+
+ -- Alexander Chernyakhovsky <achernya@mit.edu>  Mon, 22 Jul 2013 03:11:38 -0400
+
 invirt-remote (0.4.18) precise; urgency=low
 
   * Updating for precise migration.
index 6860d9c..58e6c1c 100755 (executable)
@@ -22,6 +22,11 @@ def ensureoff(machine):
     rv = call(["/usr/sbin/xm", "destroy", prefix + machine],
               stderr=PIPE)
 
+def lvm_activation(path, mode):
+    p = Popen(["/sbin/lvchange", "-a%s" % (mode,), path], stdout=PIPE, stderr=PIPE)
+    rv = p.wait()
+    return rv
+
 machine_specific = subcommand not in ['lvcreate-all', 'vgcapacity']
 
 if machine_specific:
@@ -53,6 +58,9 @@ elif subcommand == "lvremove":
     
     # Rename the LV to something else so we can wipe it before reusing
     # the space
+    if lvm_activation(lvpath, 'n') != 0:
+        print >>sys.stderr, "Could not deactivate LV %s", % (lvname,)
+        sys.exit(1)
     while True:
         new_lvname = "old_%s_%s" % (lvname, ''.join(random.choice(string.ascii_letters) for i in xrange(6)))
         new_lvpath = "/dev/%s/%s" % (vg, new_lvname)
@@ -63,6 +71,9 @@ elif subcommand == "lvremove":
         elif rv != 0:
             error()
         else:
+            if lvm_activation(new_lvpath, 'y') != 0:
+                print >> sys.stderr, "Could not reactivate renamed LV %s" % (lvname,)
+                sys.exit(1)
             break
     ensureoff(machine)
     
@@ -72,6 +83,9 @@ elif subcommand == "lvremove":
 elif subcommand == "lvresize":
     size = sys.argv[4]
     ensureoff(machine)
+    if lvm_activation(lvpath, 'n') != 0:
+        print >>sys.stderr, "Could not deactivate LV %s", % (lvname,)
+        sys.exit(1)
     p = Popen(["/sbin/lvresize", "-L", size + "M", lvpath],
               stdin=PIPE, stderr=PIPE)
     print >> p.stdin, 'y'
@@ -80,16 +94,27 @@ elif subcommand == "lvresize":
         print >> sys.stderr, "Error resizing LV %s:\n" %(lvname,)
         print >> sys.stderr, err
         sys.exit(1)
+    if lvm_activation(lvpath, 'y') != 0:
+        print >> sys.stderr, "Could not reactivate resized LV %s" % (lvname,)
+        sys.exit(1)
     print >> sys.stderr, err
 elif subcommand == "lvrename":
     newmachine = sys.argv[4]
     newlvname = prefix + newmachine + "_" + disk
     ensureoff(machine)
-    ensureoff(newmachine)    
+    ensureoff(newmachine)
+    lvpath = "/dev/" + vg + "/" + lvname
+    new_lvpath = "/dev/" + vg + "/" + newlvname
+    if lvm_activation(lvpath, 'n') != 0:
+        print >>sys.stderr, "Could not deactivate LV %s", % (lvname,)
+        sys.exit(1)
     rv = call(["/sbin/lvrename", vg, lvname, newlvname])
     if rv != 0:
         print >>sys.stderr, "Error renaming LV %s\n" %(lvname,)
         sys.exit(1)
+    if lvm_activation(new_lvpath, 'y') != 0:
+        print >> sys.stderr, "Could not reactivate renamed LV %s" % (lvname,)
+        sys.exit(1)
 elif subcommand == "lvcreate":
     size = sys.argv[4]
     rv = call(["/sbin/lvcreate", "-L", size + "M", "-n", lvname, vg])