CEPH filesystem development
 help / color / mirror / Atom feed
From: Josh Durgin <josh.durgin@inktank.com>
To: Alex Elder <elder@inktank.com>
Cc: ceph-devel@vger.kernel.org
Subject: Re: [PATCH 6/9] rbd: get snapshot name for a v2 image
Date: Wed, 19 Sep 2012 12:31:18 -0700	[thread overview]
Message-ID: <505A1D86.1060108@inktank.com> (raw)
In-Reply-To: <504A639E.7080503@inktank.com>

A couple small things, otherwise:

Reviewed-by: Josh Durgin <josh.durgin@inktank.com>

On 09/07/2012 02:14 PM, Alex Elder wrote:
> Define rbd_dev_v2_snap_name() to fetch the name for a particular
> snapshot in a format 2 rbd image.
>
> Define rbd_dev_v2_snap_info() to to be a wrapper for getting the
> name, size, and features for a particular snapshot, using an
> interface that matches the equivalent function for version 1 images.
>
> Define rbd_dev_snap_info() wrapper function and use it to call the
> appropriate function for getting the snapshot name, size, and
> features, dependent on the rbd image format.
>
> Signed-off-by: Alex Elder <elder@inktank.com>
> ---
>   drivers/block/rbd.c |   78
> ++++++++++++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 77 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 8ff84fd..c6922a1 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -2313,6 +2313,82 @@ out:
>   	return 0;
>   }
>
> +static char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev, u32 which)
> +{
> +	size_t size;
> +	void *reply_buf;
> +	__le64 snap_id;
> +	int ret;
> +	void *p;
> +	void *end;
> +	size_t snap_name_len;
> +	char *snap_name;
> +
> +	size = sizeof (__le32) + RBD_MAX_SNAP_NAME_LEN;
> +	reply_buf = kmalloc(size, GFP_KERNEL);
> +	if (!reply_buf)
> +		return ERR_PTR(-ENOMEM);
> +
> +	snap_id = cpu_to_le64(rbd_dev->header.snapc->snaps[which]);
> +	ret = rbd_req_sync_exec(rbd_dev, rbd_dev->header_name,
> +				"rbd", "get_snapshot_name",
> +				(char *) &snap_id, sizeof (snap_id),
> +				reply_buf, size,
> +				CEPH_OSD_FLAG_READ, NULL);
> +	dout("%s: rbd_req_sync_exec returned %d\n", __func__, ret);
> +	if (ret < 0)
> +		goto out;
> +
> +	p = reply_buf;
> +	end = (char *) reply_buf + size;
> +	snap_name_len = 0;
> +	snap_name = ceph_extract_encoded_string(&p, end, &snap_name_len,
> +				GFP_KERNEL);
> +	if (IS_ERR(snap_name)) {
> +		ret = PTR_ERR(snap_name);
> +		goto out;
> +	} else
> +		dout("  snap_id 0x%016llx snap_name = %s\n",
> +			(unsigned long long) le64_to_cpu(snap_id), snap_name);

else block should have braces to match the if block.

> +	kfree(reply_buf);
> +
> +	return snap_name;
> +out:
> +	kfree(reply_buf);
> +
> +	return ERR_PTR(ret);
> +}
> +
> +static char *rbd_dev_v2_snap_info(struct rbd_device *rbd_dev, u32 which,
> +		u64 *snap_size, u64 *snap_features)
> +{
> +	__le64 snap_id;
> +	u8 order;
> +	int ret;
> +
> +	snap_id = rbd_dev->header.snapc->snaps[which];
> +	ret = _rbd_dev_v2_snap_size(rbd_dev, snap_id, &order, snap_size);
> +	if (ret)
> +		return ERR_PTR(ret);
> +	ret = _rbd_dev_v2_snap_features(rbd_dev, snap_id, snap_features);
> +	if (ret)
> +		return ERR_PTR(ret);
> +
> +	return rbd_dev_v2_snap_name(rbd_dev, which);
> +}
> +
> +static char *rbd_dev_snap_info(struct rbd_device *rbd_dev, u32 which,
> +		u64 *snap_size, u64 *snap_features)
> +{
> +	if (rbd_dev->image_format == 1)
> +		return rbd_dev_v1_snap_info(rbd_dev, which,
> +					snap_size, snap_features);
> +	if (rbd_dev->image_format == 2)
> +		return rbd_dev_v2_snap_info(rbd_dev, which,
> +					snap_size, snap_features);
> +	return ERR_PTR(-EINVAL);
> +}
> +
>   /*
>    * Scan the rbd device's current snapshot list and compare it to the
>    * newly-received snapshot context.  Remove any existing snapshots
> @@ -2366,7 +2442,7 @@ static int rbd_dev_snaps_update(struct rbd_device
> *rbd_dev)
>   			continue;
>   		}
>
> -		snap_name = rbd_dev_v1_snap_info(rbd_dev, index,
> +		snap_name = rbd_dev_snap_info(rbd_dev, index,
>   						&snap_size, &snap_features);

This line's indentation is offset now.

>   		if (IS_ERR(snap_name))
>   			return PTR_ERR(snap_name);
>


  reply	other threads:[~2012-09-19 19:31 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 ` [PATCH 2/9] rbd: add code to get the size of a v2 rbd image Alex Elder
2012-09-19 18:52   ` 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 [this message]
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=505A1D86.1060108@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