summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-07-03 16:01:19 -0500
committerAlex Elder <elder@inktank.com>2012-10-01 14:30:53 -0500
commit9d475de5d12af8ac4c2101807e0a889ac7389c5a (patch)
treeaa0a4e6246ed6f1d9fbcf4d536f6ff448146c98a /drivers
parenta30b71b999c92071befec73434f4e67fd4b4734b (diff)
downloadlinux-9d475de5d12af8ac4c2101807e0a889ac7389c5a.tar.bz2
rbd: add code to get the size of a v2 rbd image
The size of an rbd format 2 image is fetched from the server using a "get_size" method. The same method is used for getting the size of a snapshot, so structure this addition with a generic helper routine that we can get this information for either. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/block/rbd.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 3b284d53a566..061c62496fea 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -2128,6 +2128,47 @@ static char *rbd_dev_v1_snap_info(struct rbd_device *rbd_dev, u32 which,
}
/*
+ * Get the size and object order for an image snapshot, or if
+ * snap_id is CEPH_NOSNAP, gets this information for the base
+ * image.
+ */
+static int _rbd_dev_v2_snap_size(struct rbd_device *rbd_dev, u64 snap_id,
+ u8 *order, u64 *snap_size)
+{
+ __le64 snapid = cpu_to_le64(snap_id);
+ int ret;
+ struct {
+ u8 order;
+ __le64 size;
+ } __attribute__ ((packed)) size_buf = { 0 };
+
+ ret = rbd_req_sync_exec(rbd_dev, rbd_dev->header_name,
+ "rbd", "get_size",
+ (char *) &snapid, sizeof (snapid),
+ (char *) &size_buf, sizeof (size_buf),
+ CEPH_OSD_FLAG_READ, NULL);
+ dout("%s: rbd_req_sync_exec returned %d\n", __func__, ret);
+ if (ret < 0)
+ return ret;
+
+ *order = size_buf.order;
+ *snap_size = le64_to_cpu(size_buf.size);
+
+ dout(" snap_id 0x%016llx order = %u, snap_size = %llu\n",
+ (unsigned long long) snap_id, (unsigned int) *order,
+ (unsigned long long) *snap_size);
+
+ return 0;
+}
+
+static int rbd_dev_v2_image_size(struct rbd_device *rbd_dev)
+{
+ return _rbd_dev_v2_snap_size(rbd_dev, CEPH_NOSNAP,
+ &rbd_dev->header.obj_order,
+ &rbd_dev->header.image_size);
+}
+
+/*
* Scan the rbd device's current snapshot list and compare it to the
* newly-received snapshot context. Remove any existing snapshots
* not present in the new snapshot context. Add a new snapshot for
@@ -2636,6 +2677,7 @@ out_err:
static int rbd_dev_v2_probe(struct rbd_device *rbd_dev)
{
size_t size;
+ int ret;
/*
* Image id was filled in by the caller. Record the header
@@ -2647,12 +2689,23 @@ static int rbd_dev_v2_probe(struct rbd_device *rbd_dev)
return -ENOMEM;
sprintf(rbd_dev->header_name, "%s%s",
RBD_HEADER_PREFIX, rbd_dev->image_id);
+
+ /* Get the size and object order for the image */
+
+ ret = rbd_dev_v2_image_size(rbd_dev);
+ if (ret < 0)
+ goto out_err;
rbd_dev->image_format = 2;
dout("discovered version 2 image, header name is %s\n",
rbd_dev->header_name);
return -ENOTSUPP;
+out_err:
+ kfree(rbd_dev->header_name);
+ rbd_dev->header_name = NULL;
+
+ return ret;
}
/*