Improve some corner cases in instance migration
authorIustin Pop <iustin@google.com>
Thu, 26 Jun 2008 10:32:45 +0000 (10:32 +0000)
committerIustin Pop <iustin@google.com>
Thu, 26 Jun 2008 10:32:45 +0000 (10:32 +0000)
Since the backend.DrbdReconfigNet function is called from the rpc layer,
it's better not to raise exception but to return a meaningful error
message.

The patch adds two try.. except blocks around the ReAttachNet() calls
which are the ones which most often return errors (among the few errors
that we have for now).

The patch also adds two SetDiskID calls in cmdlib's LUMigrateInstance
before the change-to-secondary which are needed depending on what is
saved in the config file.

Reviewed-by: ultrotter

lib/backend.py
lib/cmdlib.py

index 33f9bad..d76ea2b 100644 (file)
@@ -1621,7 +1621,10 @@ def DrbdReconfigNet(instance_name, disks, nodes_ip, multimaster):
 
   # switch to new master configuration and if needed primary mode
   for rd in bdevs:
-    rd.ReAttachNet(multimaster)
+    try:
+      rd.ReAttachNet(multimaster)
+    except errors.BlockDeviceError, err:
+      return (False, "Can't change network configuration: %s" % str(err))
   # wait until the disks are connected; we need to retry the re-attach
   # if the device becomes standalone, as this might happen if the one
   # node disconnects and reconnects in a different mode before the
@@ -1638,7 +1641,10 @@ def DrbdReconfigNet(instance_name, disks, nodes_ip, multimaster):
         notyet = True
       if stats.is_standalone:
         # peer had different config info and this node became standalone
-        rd.ReAttachNet(multimaster)
+        try:
+          rd.ReAttachNet(multimaster)
+        except errors.BlockDeviceError, err:
+          return (False, "Can't change network configuration: %s" % str(err))
     if not notyet:
       break
     time.sleep(5)
index d8cb793..546d9c2 100644 (file)
@@ -3004,6 +3004,8 @@ class LUMigrateInstance(LogicalUnit):
                                  " aborting migrate." % dev.iv_name)
 
     feedback_fn("* ensuring the target is in secondary mode")
+    for disk in instance.disks:
+      self.cfg.SetDiskID(disk, target_node)
     result = rpc.call_blockdev_close(target_node, instance.name,
                                      instance.disks)
     if not result or not result[0]:
@@ -3052,6 +3054,8 @@ class LUMigrateInstance(LogicalUnit):
     self.cfg.Update(instance)
 
     feedback_fn("* changing the instance's disks on source node to secondary")
+    for disk in instance.disks:
+      self.cfg.SetDiskID(disk, source_node)
     result = rpc.call_blockdev_close(source_node, instance.name,
                                      instance.disks)
     if not result or not result[0]: