From 968a762326318f295b9b885e5f02c9dbb9f0d32e Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 4 Aug 2009 12:43:22 +0200
Subject: [PATCH] rpc: add rpc call for getting disk size

Note that this exports the disk size as bdev returns it, in bytes. The
value will be converted to MiB in cmdlib.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 daemons/ganeti-noded |  8 ++++++++
 lib/backend.py       | 26 ++++++++++++++++++++++++++
 lib/rpc.py           |  9 +++++++++
 3 files changed, 43 insertions(+)

diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded
index 1f2862f16..36e8e7053 100755
--- a/daemons/ganeti-noded
+++ b/daemons/ganeti-noded
@@ -232,6 +232,14 @@ class NodeHttpServer(http.server.HttpServer):
     disks = [objects.Disk.FromDict(cf) for cf in params[1]]
     return backend.BlockdevClose(params[0], disks)
 
+  @staticmethod
+  def perspective_blockdev_getsize(params):
+    """Compute the sizes of the given block devices.
+
+    """
+    disks = [objects.Disk.FromDict(cf) for cf in params[0]]
+    return backend.BlockdevGetsize(disks)
+
   # blockdev/drbd specific methods ----------
 
   @staticmethod
diff --git a/lib/backend.py b/lib/backend.py
index afb39213a..c865b0fc1 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -1442,6 +1442,32 @@ def BlockdevFind(disk):
   return (True, (rbd.dev_path, rbd.major, rbd.minor) + rbd.GetSyncStatus())
 
 
+def BlockdevGetsize(disks):
+  """Computes the size of the given disks.
+
+  If a disk is not found, returns None instead.
+
+  @type disks: list of L{objects.Disk}
+  @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
+
+  """
+  result = []
+  for cf in disks:
+    try:
+      rbd = _RecursiveFindBD(cf)
+    except errors.BlockDeviceError, err:
+      result.append(None)
+      continue
+    if rbd is None:
+      result.append(None)
+    else:
+      result.append(rbd.GetActualSize())
+  return result
+
+
 def UploadFile(file_name, data, mode, uid, gid, atime, mtime):
   """Write a file to the filesystem.
 
diff --git a/lib/rpc.py b/lib/rpc.py
index 1ce44acbb..6392f50cb 100644
--- a/lib/rpc.py
+++ b/lib/rpc.py
@@ -807,6 +807,15 @@ class RpcRunner(object):
     params = [instance_name, [cf.ToDict() for cf in disks]]
     return self._SingleNodeCall(node, "blockdev_close", params)
 
+  def call_blockdev_getsizes(self, node, disks):
+    """Returns the size of the given disks.
+
+    This is a single-node call.
+
+    """
+    params = [[cf.ToDict() for cf in disks]]
+    return self._SingleNodeCall(node, "blockdev_getsize", params)
+
   def call_drbd_disconnect_net(self, node_list, nodes_ip, disks):
     """Disconnects the network of the given drbd devices.
 
-- 
GitLab