From: Alex Elder <elder@inktank.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 2/9] rbd: add code to get the size of a v2 rbd image
Date: Fri, 07 Sep 2012 16:13:29 -0500 [thread overview]
Message-ID: <504A6379.7010308@inktank.com> (raw)
In-Reply-To: <504A6273.7030807@inktank.com>
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>
---
drivers/block/rbd.c | 53
+++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 019e695..24d12e3 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -2123,6 +2123,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
@@ -2631,6 +2672,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
@@ -2642,12 +2684,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;
}
/*
--
1.7.9.5
next prev parent reply other threads:[~2012-09-07 21:13 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-07 21:09 [PATCH 0/9] rbd: activate v2 image support Alex Elder
2012-09-07 21:13 ` [PATCH 1/9] rbd: lay out header probe infrastructure Alex Elder
2012-09-19 18:35 ` Josh Durgin
2012-09-07 21:13 ` Alex Elder [this message]
2012-09-19 18:52 ` [PATCH 2/9] rbd: add code to get the size of a v2 rbd image Josh Durgin
2012-09-07 21:13 ` [PATCH 3/9] rbd: get the object prefix for " Alex Elder
2012-09-19 18:57 ` Josh Durgin
2012-09-07 21:13 ` [PATCH 4/9] rbd: get image features for a v2 image Alex Elder
2012-09-19 19:02 ` Josh Durgin
2012-09-07 21:13 ` [PATCH 5/9] rbd: get the snapshot context " Alex Elder
2012-09-19 19:17 ` Josh Durgin
2012-09-07 21:14 ` [PATCH 6/9] rbd: get snapshot name " Alex Elder
2012-09-19 19:31 ` Josh Durgin
2012-09-07 21:15 ` [PATCH 7/9] rbd: update remaining header fields for v2 Alex Elder
2012-09-19 19:38 ` Josh Durgin
2012-09-07 21:15 ` [PATCH 8/9] rbd: define rbd_dev_v2_snapc_refresh() Alex Elder
2012-09-19 21:00 ` Josh Durgin
2012-09-07 21:15 ` [PATCH 9/9] rbd: activate v2 image support Alex Elder
2012-09-19 19:56 ` Josh Durgin
2012-09-19 19:57 ` Josh Durgin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=504A6379.7010308@inktank.com \
--to=elder@inktank.com \
--cc=ceph-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.