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 2/2] rbd: do all argument parsing in one place
Date: Mon, 29 Oct 2012 14:13:05 -0700	[thread overview]
Message-ID: <508EF161.2000808@inktank.com> (raw)
In-Reply-To: <508B14F8.6080905@inktank.com>

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

On 10/26/2012 03:55 PM, Alex Elder wrote:
> This patch makes rbd_add_parse_args() be the single place all
> argument parsing occurs for an image map request:
>      - Move the ceph_parse_options() call into that function
>      - Use local variables rather than parameters to hold the list
>        of monitor addresses supplied
>      - Rather than returning it, pass the snapshot name (and its
>        length) back via parameters
>      - Have the function return a ceph_options structure pointer
>
> Signed-off-by: Alex Elder <elder@inktank.com>
> ---
>   drivers/block/rbd.c |   77
> +++++++++++++++++++++++++--------------------------
>   1 file changed, 37 insertions(+), 40 deletions(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 6e36c63..4fe14ff 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -2845,24 +2845,27 @@ static inline char *dup_token(const char **buf,
> size_t *lenp)
>    *
>    * Note: rbd_dev is assumed to have been initially zero-filled.
>    */
> -static char *rbd_add_parse_args(struct rbd_device *rbd_dev,
> -				const char *buf,
> -				const char **mon_addrs,
> -				size_t *mon_addrs_size,
> -				char *options,
> -				size_t options_size)
> +static struct ceph_options *rbd_add_parse_args(struct rbd_device *rbd_dev,
> +						const char *buf,
> +						char *options,
> +						size_t options_size,
> +						char **snap_name,
> +						size_t *snap_name_len)
>   {
>   	size_t len;
> -	char *err_ptr = ERR_PTR(-EINVAL);
> -	char *snap_name;
> +	const char *mon_addrs;
> +	size_t mon_addrs_size;
> +	struct rbd_options rbd_opts;
> +	struct ceph_options *ceph_opts;
> +	struct ceph_options *err_ptr = ERR_PTR(-EINVAL);
>
>   	/* The first four tokens are required */
>
>   	len = next_token(&buf);
>   	if (!len)
>   		return err_ptr;
> -	*mon_addrs_size = len + 1;
> -	*mon_addrs = buf;
> +	mon_addrs_size = len + 1;
> +	mon_addrs = buf;
>
>   	buf += len;
>
> @@ -2890,14 +2893,27 @@ static char *rbd_add_parse_args(struct
> rbd_device *rbd_dev,
>   		buf = RBD_SNAP_HEAD_NAME; /* No snapshot supplied */
>   		len = sizeof (RBD_SNAP_HEAD_NAME) - 1;
>   	}
> -	snap_name = kmalloc(len + 1, GFP_KERNEL);
> -	if (!snap_name)
> +	*snap_name = kmalloc(len + 1, GFP_KERNEL);
> +	if (!*snap_name)
>   		goto out_err;
> -	memcpy(snap_name, buf, len);
> -	*(snap_name + len) = '\0';
> +	memcpy(*snap_name, buf, len);
> +	*(*snap_name + len) = '\0';
> +	*snap_name_len = len;
> +	/* Initialize all rbd options to the defaults */
>
> -	return snap_name;
> +	rbd_opts.read_only = RBD_READ_ONLY_DEFAULT;
>
> +	ceph_opts = ceph_parse_options(options, mon_addrs,
> +					mon_addrs + mon_addrs_size - 1,
> +					parse_rbd_opts_token, &rbd_opts);
> +
> +	/* Record the parsed rbd options */
> +
> +	if (!IS_ERR(ceph_opts)) {
> +		rbd_dev->mapping.read_only = rbd_opts.read_only;
> +	}
> +
> +	return ceph_opts;
>   out_err:
>   	kfree(rbd_dev->image_name);
>   	rbd_dev->image_name = NULL;
> @@ -3114,10 +3130,8 @@ static ssize_t rbd_add(struct bus_type *bus,
>   {
>   	char *options;
>   	struct rbd_device *rbd_dev = NULL;
> -	const char *mon_addrs = NULL;
> -	size_t mon_addrs_size = 0;
>   	char *snap_name;
> -	struct rbd_options rbd_opts;
> +	size_t snap_name_len = 0;
>   	struct ceph_options *ceph_opts;
>   	struct ceph_osd_client *osdc;
>   	int rc = -ENOMEM;
> @@ -3139,32 +3153,16 @@ static ssize_t rbd_add(struct bus_type *bus,
>   	init_rwsem(&rbd_dev->header_rwsem);
>
>   	/* parse add command */
> -	snap_name = rbd_add_parse_args(rbd_dev, buf,
> -				&mon_addrs, &mon_addrs_size, options, count);
> -	if (IS_ERR(snap_name)) {
> -		rc = PTR_ERR(snap_name);
> -		goto err_out_mem;
> -	}
> -
> -	/* Initialize all rbd options to the defaults */
> -
> -	rbd_opts.read_only = RBD_READ_ONLY_DEFAULT;
> -
> -	ceph_opts = ceph_parse_options(options, mon_addrs,
> -					mon_addrs + mon_addrs_size - 1,
> -					parse_rbd_opts_token, &rbd_opts);
> +	ceph_opts = rbd_add_parse_args(rbd_dev, buf, options, count,
> +				&snap_name, &snap_name_len);
>   	if (IS_ERR(ceph_opts)) {
>   		rc = PTR_ERR(ceph_opts);
> -		goto err_out_args;
> +		goto err_out_mem;
>   	}
>
> -	/* Record the parsed rbd options */
> -
> -	rbd_dev->mapping.read_only = rbd_opts.read_only;
> -
>   	rc = rbd_get_client(rbd_dev, ceph_opts);
>   	if (rc < 0)
> -		goto err_out_opts;
> +		goto err_out_args;
>   	ceph_opts = NULL;	/* ceph_opts now owned by rbd_dev client */
>
>   	/* pick the pool */
> @@ -3257,10 +3255,9 @@ err_out_client:
>   	kfree(rbd_dev->header_name);
>   	rbd_put_client(rbd_dev);
>   	kfree(rbd_dev->image_id);
> -err_out_opts:
> +err_out_args:
>   	if (ceph_opts)
>   		ceph_destroy_options(ceph_opts);
> -err_out_args:
>   	kfree(rbd_dev->snap_name);
>   	kfree(rbd_dev->image_name);
>   	kfree(rbd_dev->pool_name);
>


  reply	other threads:[~2012-10-29 21:13 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-26 22:42 Another pile of patches Alex Elder
2012-10-26 22:44 ` [PATCH, resend] rbd: simplify rbd_rq_fn() Alex Elder
2012-10-29 20:29   ` Josh Durgin
2012-10-30 12:01     ` Alex Elder
2012-10-26 22:45 ` [PATCH] rbd: remove snapshots on error in rbd_add() Alex Elder
2012-10-29 20:36   ` Josh Durgin
2012-10-26 22:45 ` [PATCH] rbd: make pool_id a 64 bit value Alex Elder
2012-10-29 20:40   ` Josh Durgin
2012-10-26 22:48 ` [PATCH 0/2] rbd: mapping structure changes Alex Elder
2012-10-26 22:51   ` [PATCH 1/2] rbd: move snap info out of rbd_mapping struct Alex Elder
2012-10-29 20:43     ` Josh Durgin
2012-10-26 22:51   ` [PATCH 2/2] rbd: rename snap_exists field Alex Elder
2012-10-29 20:46     ` Josh Durgin
2012-10-26 22:52 ` [PATCH 0/2] rbd: consolidate argument parsing Alex Elder
2012-10-26 22:55   ` [PATCH 1/2] rbd: move ceph_parse_options() call up Alex Elder
2012-10-29 21:08     ` Josh Durgin
2012-10-26 22:55   ` [PATCH 2/2] rbd: do all argument parsing in one place Alex Elder
2012-10-29 21:13     ` Josh Durgin [this message]
2012-10-26 22:56 ` [PATCH 0/8] rbd: have rbd_add_parse_args() only parse args Alex Elder
2012-10-26 23:00   ` [PATCH 1/8] rbd: get rid of snap_name_len Alex Elder
2012-10-29 21:14     ` Josh Durgin
2012-10-26 23:00   ` [PATCH 2/8] rbd: remove options args from rbd_add_parse_args() Alex Elder
2012-10-29 21:17     ` Josh Durgin
2012-10-26 23:01   ` [PATCH 3/8] rbd: remove snap_name arg " Alex Elder
2012-10-29 21:26     ` Josh Durgin
2012-10-26 23:02   ` [PATCH 4/8] rbd: pass and populate rbd_options structure Alex Elder
2012-10-29 21:27     ` Josh Durgin
2012-10-26 23:02   ` [PATCH 5/8] rbd: have rbd_add_parse_args() return error Alex Elder
2012-10-29 21:28     ` Josh Durgin
2012-10-26 23:03   ` [PATCH 6/8] rbd: define image specification structure Alex Elder
2012-10-29 22:13     ` Josh Durgin
2012-10-30 12:40       ` Alex Elder
2012-10-30 20:13         ` Josh Durgin
2012-10-26 23:03   ` [PATCH 7/8] rbd: add reference counting to rbd_spec Alex Elder
2012-10-29 22:20     ` Josh Durgin
2012-10-30 12:59       ` Alex Elder
2012-10-30 20:17         ` Josh Durgin
2012-10-26 23:03   ` [PATCH 8/8] rbd: fill rbd_spec in rbd_add_parse_args() Alex Elder
2012-10-29 22:30     ` Josh Durgin
2012-10-30 13:09       ` Alex Elder
2012-10-30 20:18         ` 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=508EF161.2000808@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