Add a rpc call for BlockDev.Close()
authorIustin Pop <iustin@google.com>
Fri, 20 Jun 2008 10:59:15 +0000 (10:59 +0000)
committerIustin Pop <iustin@google.com>
Fri, 20 Jun 2008 10:59:15 +0000 (10:59 +0000)
This patch adds rpc layer calls (in rpc.py and the equivalent in
ganeti-noded) to close a list of block devices, and the wrapper in
backend.py that takes a list of Disk objects, identifies them and
returns correctly formatted results.

The reason why this very basic call was missing until now from the rpc
layer is that we usually don't care about device closes (though we
should, and will do so in the future) as only drbd has a meaningful
Close() operation; right now we directly do Shutdown().

The patch is clean enough that it's actually independent of the live
migration implementation.

Reviewed-by: imsnah

daemons/ganeti-noded
lib/backend.py
lib/rpc.py

index ec17a72..3d9e9d5 100755 (executable)
@@ -212,6 +212,14 @@ class ServerObject(pb.Avatar):
     amount = params[1]
     return backend.GrowBlockDevice(cfbd, amount)
 
+  @staticmethod
+  def perspective_blockdev_close(params):
+    """Closes the given block devices.
+
+    """
+    disks = [objects.Disk.FromDict(cf) for cf in params]
+    return backend.CloseBlockDevices(disks)
+
   # export/import  --------------------------
 
   @staticmethod
index f876686..e4aa895 100644 (file)
@@ -1478,6 +1478,31 @@ def RenameBlockDevices(devlist):
   return result
 
 
+def CloseBlockDevices(disks):
+  """Closes the given block devices.
+
+  This means they will be switched to secondary mode (in case of DRBD).
+
+  """
+  bdevs = []
+  for cf in disks:
+    rd = _RecursiveFindBD(cf)
+    if rd is None:
+      return (False, "Can't find device %s" % cf)
+    bdevs.append(rd)
+
+  msg = []
+  for rd in bdevs:
+    try:
+      rd.Close()
+    except errors.BlockDeviceError, err:
+      msg.append(str(err))
+  if msg:
+    return (False, "Can't make devices secondary: %s" % ",".join(msg))
+  else:
+    return (True, "All devices secondary")
+
+
 class HooksRunner(object):
   """Hook runner.
 
index 9a34b0a..eb2013c 100644 (file)
@@ -621,6 +621,19 @@ def call_blockdev_find(node, disk):
   return c.getresult().get(node, False)
 
 
+def call_blockdev_close(node, disks):
+  """Closes the given block devices.
+
+  This is a single-node call.
+
+  """
+  params = [cf.ToDict() for cf in disks]
+  c = Client("blockdev_close", params)
+  c.connect(node)
+  c.run()
+  return c.getresult().get(node, False)
+
+
 def call_upload_file(node_list, file_name):
   """Upload a file.