diff options
author | Alex Elder <elder@inktank.com> | 2012-07-09 21:04:23 -0500 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2012-07-30 09:29:58 -0700 |
commit | ea3352f4aa4fc32397d9a535780315e0f2bfee15 (patch) | |
tree | 9ed74bb7b8a0edf06885507086cd22bf24b84feb | |
parent | f8c36c58accd5c53a472b5c289910565b3df9f9d (diff) | |
download | linux-ea3352f4aa4fc32397d9a535780315e0f2bfee15.tar.bz2 |
rbd: define dup_token()
Define a new function dup_token(), to be used during argument
parsing for making dynamically-allocated copies of tokens being
parsed.
Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Yehuda Sadeh <yehuda@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
-rw-r--r-- | drivers/block/rbd.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 2ae3bb0c0a34..384694f40b44 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -2281,6 +2281,42 @@ static inline size_t copy_token(const char **buf, } /* + * Finds the next token in *buf, dynamically allocates a buffer big + * enough to hold a copy of it, and copies the token into the new + * buffer. The copy is guaranteed to be terminated with '\0'. Note + * that a duplicate buffer is created even for a zero-length token. + * + * Returns a pointer to the newly-allocated duplicate, or a null + * pointer if memory for the duplicate was not available. If + * the lenp argument is a non-null pointer, the length of the token + * (not including the '\0') is returned in *lenp. + * + * If successful, the *buf pointer will be updated to point beyond + * the end of the found token. + * + * Note: uses GFP_KERNEL for allocation. + */ +static inline char *dup_token(const char **buf, size_t *lenp) +{ + char *dup; + size_t len; + + len = next_token(buf); + dup = kmalloc(len + 1, GFP_KERNEL); + if (!dup) + return NULL; + + memcpy(dup, *buf, len); + *(dup + len) = '\0'; + *buf += len; + + if (lenp) + *lenp = len; + + return dup; +} + +/* * This fills in the pool_name, obj, obj_len, snap_name, obj_len, * rbd_dev, rbd_md_name, and name fields of the given rbd_dev, based * on the list of monitor addresses and other options provided via |