From: Josh Durgin <josh.durgin@inktank.com>
To: Alex Elder <elder@inktank.com>
Cc: ceph-devel@vger.kernel.org
Subject: Re: [PATCH 3/3] rbd: encapsulate code that gets snapshot info
Date: Tue, 11 Sep 2012 16:14:25 -0700 [thread overview]
Message-ID: <504FC5D1.3000008@inktank.com> (raw)
In-Reply-To: <504A4A17.8060008@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
On 09/07/2012 12:25 PM, Alex Elder wrote:
> Create a function that encapsulates looking up the name, size and
> features related to a given snapshot, which is indicated by its
> index in an rbd device's snapshot context array of snapshot ids.
>
> This interface will be used to hide differences between the format 1
> and format 2 images.
>
> At the moment this (looking up the name anyway) is slightly less
> efficient than what's done currently, but we may be able to optimize
> this a bit later on by cacheing the last lookup if it proves to be a
> problem.
>
> Signed-off-by: Alex Elder <elder@inktank.com>
> ---
> drivers/block/rbd.c | 36 ++++++++++++++++++++++++++++++------
> 1 file changed, 30 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index c62d3f4..e6b8fa6 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -2097,6 +2097,25 @@ err:
> return ERR_PTR(ret);
> }
>
> +static char *rbd_dev_v1_snap_info(struct rbd_device *rbd_dev, u32 which,
> + u64 *snap_size, u64 *snap_features)
> +{
> + char *snap_name;
> +
> + rbd_assert(which < rbd_dev->header.snapc->num_snaps);
> +
> + *snap_size = rbd_dev->header.snap_sizes[which];
> + *snap_features = 0; /* No features for v1 */
> +
> + /* Skip over names until we find the one we are looking for */
> +
> + snap_name = rbd_dev->header.snap_names;
> + while (which--)
> + snap_name += strlen(snap_name) + 1;
> +
> + return snap_name;
> +}
> +
> /*
> * Scan the rbd device's current snapshot list and compare it to the
> * newly-received snapshot context. Remove any existing snapshots
> @@ -2113,7 +2132,6 @@ static int rbd_dev_snaps_update(struct rbd_device
> *rbd_dev)
> {
> struct ceph_snap_context *snapc = rbd_dev->header.snapc;
> const u32 snap_count = snapc->num_snaps;
> - char *snap_name = rbd_dev->header.snap_names;
> struct list_head *head = &rbd_dev->snaps;
> struct list_head *links = head->next;
> u32 index = 0;
> @@ -2122,6 +2140,9 @@ static int rbd_dev_snaps_update(struct rbd_device
> *rbd_dev)
> while (index < snap_count || links != head) {
> u64 snap_id;
> struct rbd_snap *snap;
> + char *snap_name;
> + u64 snap_size = 0;
> + u64 snap_features = 0;
>
> snap_id = index < snap_count ? snapc->snaps[index]
> : CEPH_NOSNAP;
> @@ -2148,16 +2169,20 @@ static int rbd_dev_snaps_update(struct
> rbd_device *rbd_dev)
> continue;
> }
>
> + snap_name = rbd_dev_v1_snap_info(rbd_dev, index,
> + &snap_size, &snap_features);
> + if (IS_ERR(snap_name))
> + return PTR_ERR(snap_name);
> +
> dout("entry %u: snap_id = %llu\n", (unsigned int) snap_count,
> (unsigned long long) snap_id);
> if (!snap || (snap_id != CEPH_NOSNAP && snap->id < snap_id)) {
> - struct rbd_image_header *header = &rbd_dev->header;
> struct rbd_snap *new_snap;
>
> /* We haven't seen this snapshot before */
>
> new_snap = __rbd_add_snap_dev(rbd_dev, snap_name,
> - snap_id, header->snap_sizes[index], 0);
> + snap_id, snap_size, snap_features);
> if (IS_ERR(new_snap)) {
> int err = PTR_ERR(new_snap);
>
> @@ -2178,9 +2203,9 @@ static int rbd_dev_snaps_update(struct rbd_device
> *rbd_dev)
>
> dout(" already present\n");
>
> - rbd_assert(snap->size ==
> - rbd_dev->header.snap_sizes[index]);
> + rbd_assert(snap->size == snap_size);
> rbd_assert(!strcmp(snap->name, snap_name));
> + rbd_assert(snap->features == snap_features);
>
> /* Done with this list entry; advance */
>
> @@ -2190,7 +2215,6 @@ static int rbd_dev_snaps_update(struct rbd_device
> *rbd_dev)
> /* Advance to the next entry in the snapshot context */
>
> index++;
> - snap_name += strlen(snap_name) + 1;
> }
> dout("%s: done\n", __func__);
>
prev parent reply other threads:[~2012-09-11 23:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-07 19:22 [PATCH 0/3] rbd: hide some snapshot info details Alex Elder
2012-09-07 19:24 ` [PATCH 1/3] rbd: don't use index in __rbd_add_snap_dev() Alex Elder
2012-09-11 22:49 ` Josh Durgin
2012-09-07 19:25 ` [PATCH 2/3] rbd: add an rbd features field Alex Elder
2012-09-11 22:58 ` Josh Durgin
2012-09-07 19:25 ` [PATCH 3/3] rbd: encapsulate code that gets snapshot info Alex Elder
2012-09-11 23:14 ` Josh Durgin [this message]
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=504FC5D1.3000008@inktank.com \
--to=josh.durgin@inktank.com \
--cc=ceph-devel@vger.kernel.org \
--cc=elder@inktank.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox