提交 d22f76e7 编写于 作者: A Alex Elder 提交者: Sage Weil

rbd: dynamically allocate pool name

There is no need to impose a small limit the length of the pool name
recorded for an rbd image in a struct rbd_device.  Remove the
limitation by allocating space for the pool name ynamically.
Signed-off-by: NAlex Elder <elder@inktank.com>
Reviewed-by: NJosh Durgin <josh.durgin@inktank.com>
上级 9bb2f334
......@@ -56,7 +56,6 @@
#define RBD_MINORS_PER_MAJOR 256 /* max minors per blkdev */
#define RBD_MAX_MD_NAME_LEN (RBD_MAX_OBJ_NAME_LEN + sizeof(RBD_SUFFIX))
#define RBD_MAX_POOL_NAME_LEN 64
#define RBD_MAX_SNAP_NAME_LEN 32
#define RBD_MAX_OPT_LEN 1024
......@@ -166,7 +165,7 @@ struct rbd_device {
char obj[RBD_MAX_OBJ_NAME_LEN]; /* rbd image name */
int obj_len;
char obj_md_name[RBD_MAX_MD_NAME_LEN]; /* hdr nm. */
char pool_name[RBD_MAX_POOL_NAME_LEN];
char *pool_name;
int pool_id;
struct ceph_osd_event *watch_event;
......@@ -2331,6 +2330,8 @@ static inline char *dup_token(const char **buf, size_t *lenp)
* 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
* /sys/bus/rbd/add.
*
* Note: rbd_dev is assumed to have been initially zero-filled.
*/
static int rbd_add_parse_args(struct rbd_device *rbd_dev,
const char *buf,
......@@ -2340,6 +2341,7 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev,
size_t options_size)
{
size_t len;
int ret;
/* The first four tokens are required */
......@@ -2355,13 +2357,14 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev,
if (!len || len >= options_size)
return -EINVAL;
len = copy_token(&buf, rbd_dev->pool_name, sizeof (rbd_dev->pool_name));
if (!len || len >= sizeof (rbd_dev->pool_name))
return -EINVAL;
rbd_dev->pool_name = dup_token(&buf, NULL);
if (!rbd_dev->pool_name)
return -ENOMEM;
ret = -EINVAL;
len = copy_token(&buf, rbd_dev->obj, sizeof (rbd_dev->obj));
if (!len || len >= sizeof (rbd_dev->obj))
return -EINVAL;
goto out_err;
/* We have the object length in hand, save it. */
......@@ -2380,9 +2383,15 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev,
memcpy(rbd_dev->snap_name, RBD_SNAP_HEAD_NAME,
sizeof (RBD_SNAP_HEAD_NAME));
else if (len >= sizeof (rbd_dev->snap_name))
return -EINVAL;
goto out_err;
return 0;
out_err:
kfree(rbd_dev->pool_name);
rbd_dev->pool_name = NULL;
return ret;
}
static ssize_t rbd_add(struct bus_type *bus,
......@@ -2480,6 +2489,7 @@ static ssize_t rbd_add(struct bus_type *bus,
err_out_client:
rbd_put_client(rbd_dev);
err_put_id:
kfree(rbd_dev->pool_name);
rbd_id_put(rbd_dev);
err_nomem:
kfree(options);
......@@ -2528,6 +2538,7 @@ static void rbd_dev_release(struct device *dev)
unregister_blkdev(rbd_dev->major, rbd_dev->name);
/* done with the id, and with the rbd_dev */
kfree(rbd_dev->pool_name);
rbd_id_put(rbd_dev);
kfree(rbd_dev);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册