aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/rbd.c
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-07-09 22:04:23 -0400
committerSage Weil <sage@inktank.com>2012-07-30 12:29:58 -0400
commitea3352f4aa4fc32397d9a535780315e0f2bfee15 (patch)
tree9ed74bb7b8a0edf06885507086cd22bf24b84feb /drivers/block/rbd.c
parentf8c36c58accd5c53a472b5c289910565b3df9f9d (diff)
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>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r--drivers/block/rbd.c36
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,
2281} 2281}
2282 2282
2283/* 2283/*
2284 * Finds the next token in *buf, dynamically allocates a buffer big
2285 * enough to hold a copy of it, and copies the token into the new
2286 * buffer. The copy is guaranteed to be terminated with '\0'. Note
2287 * that a duplicate buffer is created even for a zero-length token.
2288 *
2289 * Returns a pointer to the newly-allocated duplicate, or a null
2290 * pointer if memory for the duplicate was not available. If
2291 * the lenp argument is a non-null pointer, the length of the token
2292 * (not including the '\0') is returned in *lenp.
2293 *
2294 * If successful, the *buf pointer will be updated to point beyond
2295 * the end of the found token.
2296 *
2297 * Note: uses GFP_KERNEL for allocation.
2298 */
2299static inline char *dup_token(const char **buf, size_t *lenp)
2300{
2301 char *dup;
2302 size_t len;
2303
2304 len = next_token(buf);
2305 dup = kmalloc(len + 1, GFP_KERNEL);
2306 if (!dup)
2307 return NULL;
2308
2309 memcpy(dup, *buf, len);
2310 *(dup + len) = '\0';
2311 *buf += len;
2312
2313 if (lenp)
2314 *lenp = len;
2315
2316 return dup;
2317}
2318
2319/*
2284 * This fills in the pool_name, obj, obj_len, snap_name, obj_len, 2320 * This fills in the pool_name, obj, obj_len, snap_name, obj_len,
2285 * rbd_dev, rbd_md_name, and name fields of the given rbd_dev, based 2321 * rbd_dev, rbd_md_name, and name fields of the given rbd_dev, based
2286 * on the list of monitor addresses and other options provided via 2322 * on the list of monitor addresses and other options provided via