In plain to drbd conversion, rename LVs back on failure
authorKlaus Aehlig <aehlig@google.com>
Tue, 23 Apr 2013 09:35:18 +0000 (11:35 +0200)
committerKlaus Aehlig <aehlig@google.com>
Fri, 26 Apr 2013 13:06:02 +0000 (15:06 +0200)
Currently, if converting an instance from plain to drbd fails after
renaming the original LVs, the instance is left in an inconsistent
state. This commit tries to undo the renaming if a failure occurs
on assembling a DRBD device, e.g., when device minor numbers are
exhausted. (Issue 229)

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>

lib/cmdlib.py

index 228abd5..6a091f2 100644 (file)
@@ -14008,11 +14008,22 @@ class LUInstanceSetParams(LogicalUnit):
 
     feedback_fn("Initializing DRBD devices...")
     # all child devices are in place, we can now create the DRBD devices
-    for disk in anno_disks:
-      for (node, excl_stor) in [(pnode, p_excl_stor), (snode, s_excl_stor)]:
-        f_create = node == pnode
-        _CreateSingleBlockDev(self, node, instance, disk, info, f_create,
-                              excl_stor)
+    try:
+      for disk in anno_disks:
+        for (node, excl_stor) in [(pnode, p_excl_stor), (snode, s_excl_stor)]:
+          f_create = node == pnode
+          _CreateSingleBlockDev(self, node, instance, disk, info, f_create,
+                                excl_stor)
+    except errors.GenericError, e:
+      feedback_fn("Initializing of DRBD devices failed;"
+                  " renaming back original volumes...")
+      for disk in new_disks:
+        self.cfg.SetDiskID(disk, pnode)
+      rename_back_list = [(n.children[0], o.logical_id)
+                          for (n, o) in zip(new_disks, instance.disks)]
+      result = self.rpc.call_blockdev_rename(pnode, rename_back_list)
+      result.Raise("Failed to rename LVs back after error %s" % str(e))
+      raise
 
     # at this point, the instance has been modified
     instance.disk_template = constants.DT_DRBD8