New RPC to get size and spindles of disks
authorBernardo Dal Seno <bdalseno@google.com>
Wed, 22 May 2013 23:21:19 +0000 (01:21 +0200)
committerBernardo Dal Seno <bdalseno@google.com>
Tue, 28 May 2013 09:45:51 +0000 (11:45 +0200)
This RPC replaces the existing one that only returned disk size.

Signed-off-by: Bernardo Dal Seno <bdalseno@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>

lib/backend.py
lib/cmdlib/cluster.py
lib/cmdlib/instance_storage.py
lib/rpc_defs.py
lib/server/noded.py

index d1eae9f..e38ab8a 100644 (file)
@@ -2149,7 +2149,7 @@ def BlockdevFind(disk):
   return rbd.GetSyncStatus()
 
 
-def BlockdevGetsize(disks):
+def BlockdevGetdimensions(disks):
   """Computes the size of the given disks.
 
   If a disk is not found, returns None instead.
@@ -2158,7 +2158,8 @@ def BlockdevGetsize(disks):
   @param disks: the list of disk to compute the size for
   @rtype: list
   @return: list with elements None if the disk cannot be found,
-      otherwise the size
+      otherwise the pair (size, spindles), where spindles is None if the
+      device doesn't support that
 
   """
   result = []
@@ -2171,7 +2172,7 @@ def BlockdevGetsize(disks):
     if rbd is None:
       result.append(None)
     else:
-      result.append(rbd.GetActualSize())
+      result.append(rbd.GetActualDimensions())
   return result
 
 
index 6c1667f..1959963 100644 (file)
@@ -533,9 +533,9 @@ class LUClusterRepairDiskSizes(NoHooksLU):
       newl = [v[2].Copy() for v in dskl]
       for dsk in newl:
         self.cfg.SetDiskID(dsk, node)
-      result = self.rpc.call_blockdev_getsize(node, newl)
+      result = self.rpc.call_blockdev_getdimensions(node, newl)
       if result.fail_msg:
-        self.LogWarning("Failure in blockdev_getsize call to node"
+        self.LogWarning("Failure in blockdev_getdimensions call to node"
                         " %s, ignoring", node)
         continue
       if len(result.payload) != len(dskl):
@@ -544,11 +544,17 @@ class LUClusterRepairDiskSizes(NoHooksLU):
         self.LogWarning("Invalid result from node %s, ignoring node results",
                         node)
         continue
-      for ((instance, idx, disk), size) in zip(dskl, result.payload):
-        if size is None:
+      for ((instance, idx, disk), dimensions) in zip(dskl, result.payload):
+        if dimensions is None:
           self.LogWarning("Disk %d of instance %s did not return size"
                           " information, ignoring", idx, instance.name)
           continue
+        if not isinstance(dimensions, (tuple, list)):
+          self.LogWarning("Disk %d of instance %s did not return valid"
+                          " dimension information, ignoring", idx,
+                          instance.name)
+          continue
+        (size, _) = dimensions
         if not isinstance(size, (int, long)):
           self.LogWarning("Disk %d of instance %s did not return valid"
                           " size information, ignoring", idx, instance.name)
index 1aed5b2..603ee86 100644 (file)
@@ -1440,15 +1440,17 @@ class LUInstanceGrowDisk(LogicalUnit):
 
     if wipe_disks:
       # Get disk size from primary node for wiping
-      result = self.rpc.call_blockdev_getsize(instance.primary_node, [disk])
+      result = self.rpc.call_blockdev_getdimensions(instance.primary_node,
+                                                    [disk])
       result.Raise("Failed to retrieve disk size from node '%s'" %
                    instance.primary_node)
 
-      (disk_size_in_bytes, ) = result.payload
+      (disk_dimensions, ) = result.payload
 
-      if disk_size_in_bytes is None:
+      if disk_dimensions is None:
         raise errors.OpExecError("Failed to retrieve disk size from primary"
                                  " node '%s'" % instance.primary_node)
+      (disk_size_in_bytes, _) = disk_dimensions
 
       old_disk_size = _DiskSizeInBytesToMebibytes(self, disk_size_in_bytes)
 
index 360c19e..1ebf35d 100644 (file)
@@ -384,9 +384,9 @@ _BLOCKDEV_CALLS = [
     ("instance_name", None, None),
     ("disks", ED_OBJECT_DICT_LIST, None),
     ], None, None, "Closes the given block devices"),
-  ("blockdev_getsize", SINGLE, None, constants.RPC_TMO_NORMAL, [
+  ("blockdev_getdimensions", SINGLE, None, constants.RPC_TMO_NORMAL, [
     ("disks", ED_OBJECT_DICT_LIST, None),
-    ], None, None, "Returns the size of the given disks"),
+    ], None, None, "Returns size and spindles of the given disks"),
   ("drbd_disconnect_net", MULTI, None, constants.RPC_TMO_NORMAL, [
     ("nodes_ip", None, None),
     ("disks", ED_OBJECT_DICT_LIST, None),
index 5c21fc0..39b3096 100644 (file)
@@ -379,12 +379,12 @@ class NodeRequestHandler(http.server.HttpServerHandler):
     return backend.BlockdevClose(params[0], disks)
 
   @staticmethod
-  def perspective_blockdev_getsize(params):
+  def perspective_blockdev_getdimensions(params):
     """Compute the sizes of the given block devices.
 
     """
     disks = [objects.Disk.FromDict(cf) for cf in params[0]]
-    return backend.BlockdevGetsize(disks)
+    return backend.BlockdevGetdimensions(disks)
 
   @staticmethod
   def perspective_blockdev_export(params):