From: Alex Elder <elder@dreamhost.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 4/5] rbd: have rbd_parse_args() report found mon_addrs size
Date: Tue, 28 Feb 2012 19:59:18 -0800 [thread overview]
Message-ID: <4F4DA296.8010909@dreamhost.com> (raw)
In-Reply-To: <4F4DA1EA.3080705@dreamhost.com>
The argument parsing routine already computes the size of the
mon_addrs buffer it extracts from the "command." Pass it to the
caller so it can use it to provide the length to rbd_get_client().
Signed-off-by: Alex Elder <elder@dreamhost.com>
---
drivers/block/rbd.c | 20 +++++++++++++-------
1 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 0602ed9..1cc7614 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -391,7 +391,9 @@ static int parse_rbd_opts_token(char *c, void *private)
* Get a ceph client with specific addr and configuration, if one does
* not exist create it.
*/
-static struct rbd_client *rbd_get_client(const char *mon_addr, char
*options)
+static struct rbd_client *rbd_get_client(const char *mon_addr,
+ size_t mon_addr_len,
+ char *options)
{
struct rbd_client *rbdc;
struct ceph_options *opt;
@@ -404,7 +406,7 @@ static struct rbd_client *rbd_get_client(const char
*mon_addr, char *options)
rbd_opts->notify_timeout = RBD_NOTIFY_TIMEOUT_DEFAULT;
opt = ceph_parse_options(options, mon_addr,
- mon_addr + strlen(mon_addr),
+ mon_addr + mon_addr_len,
parse_rbd_opts_token, rbd_opts);
if (IS_ERR(opt)) {
kfree(rbd_opts);
@@ -2282,7 +2284,7 @@ static inline size_t copy_token(const char **buf,
static int rbd_add_parse_args(struct rbd_device *rbd_dev,
const char *buf,
char *mon_addrs,
- size_t mon_addrs_size,
+ size_t *mon_addrs_size,
char *options,
size_t options_size)
{
@@ -2290,9 +2292,10 @@ static int rbd_add_parse_args(struct rbd_device
*rbd_dev,
/* The first four tokens are required */
- len = copy_token(&buf, mon_addrs, mon_addrs_size);
- if (!len || len >= mon_addrs_size)
+ len = copy_token(&buf, mon_addrs, *mon_addrs_size);
+ if (!len || len >= *mon_addrs_size)
return -EINVAL;
+ *mon_addrs_size = len + 1;
len = copy_token(&buf, options, options_size);
if (!len || len >= options_size)
@@ -2334,6 +2337,7 @@ static ssize_t rbd_add(struct bus_type *bus,
{
struct rbd_device *rbd_dev;
char *mon_addrs = NULL;
+ size_t mon_addrs_size;
char *options = NULL;
struct ceph_osd_client *osdc;
int rc = -ENOMEM;
@@ -2364,12 +2368,14 @@ static ssize_t rbd_add(struct bus_type *bus,
sprintf(rbd_dev->name, "%s%d", RBD_DRV_NAME, rbd_dev->id);
/* parse add command */
- rc = rbd_add_parse_args(rbd_dev, buf, mon_addrs, count,
+ mon_addrs_size = count;
+ rc = rbd_add_parse_args(rbd_dev, buf, mon_addrs, &mon_addrs_size,
options, count);
if (rc)
goto err_put_id;
- rbd_dev->rbd_client = rbd_get_client(mon_addrs, options);
+ rbd_dev->rbd_client = rbd_get_client(mon_addrs, mon_addrs_size - 1,
+ options);
if (IS_ERR(rbd_dev->rbd_client)) {
rc = PTR_ERR(rbd_dev->rbd_client);
goto err_put_id;
--
1.7.5.4
next prev parent reply other threads:[~2012-02-29 3:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-29 3:56 [PATCH 0/5] rbd: cleanups related to argument parsing Alex Elder
2012-02-29 3:59 ` [PATCH 1/5] rbd: encapsulate argument parsing for rbd_add() Alex Elder
2012-02-29 3:59 ` [PATCH 2/5] rbd: don't use sscanf() in rbd_add_parse_args() Alex Elder
2012-02-29 3:59 ` [PATCH 3/5] rbd: do a few checks at build time Alex Elder
2012-02-29 3:59 ` Alex Elder [this message]
2012-02-29 3:59 ` [PATCH 5/5] rbd: don't allocate mon_addrs buffer in rbd_add() Alex Elder
2012-03-02 21:28 ` [PATCH 0/5] rbd: cleanups related to argument parsing Sage Weil
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=4F4DA296.8010909@dreamhost.com \
--to=elder@dreamhost.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.