Commit bf3e5ae1 authored by Alex Elder's avatar Alex Elder Committed by Sage Weil

rbd: dynamically allocate image name

There is no need to impose a small limit the length of the rbd image
name recorded in a struct rbd_dev.  Remove the limitation by
allocating space for the image name dynamically.
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
parent cb8627c7
...@@ -161,8 +161,8 @@ struct rbd_device { ...@@ -161,8 +161,8 @@ struct rbd_device {
spinlock_t lock; /* queue lock */ spinlock_t lock; /* queue lock */
struct rbd_image_header header; struct rbd_image_header header;
char obj[RBD_MAX_OBJ_NAME_LEN]; /* rbd image name */ char *obj; /* rbd image name */
int obj_len; size_t obj_len;
char *obj_md_name; /* hdr nm. */ char *obj_md_name; /* hdr nm. */
char *pool_name; char *pool_name;
int pool_id; int pool_id;
...@@ -2371,27 +2371,22 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev, ...@@ -2371,27 +2371,22 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev,
if (!len || len >= options_size) if (!len || len >= options_size)
return -EINVAL; return -EINVAL;
ret = -ENOMEM;
rbd_dev->pool_name = dup_token(&buf, NULL); rbd_dev->pool_name = dup_token(&buf, NULL);
if (!rbd_dev->pool_name) if (!rbd_dev->pool_name)
return -ENOMEM;
len = copy_token(&buf, rbd_dev->obj, sizeof (rbd_dev->obj));
if (!len || len >= sizeof (rbd_dev->obj)) {
ret = -EINVAL;
goto out_err; goto out_err;
}
/* We have the object length in hand, save it. */ rbd_dev->obj = dup_token(&buf, &rbd_dev->obj_len);
if (!rbd_dev->obj)
rbd_dev->obj_len = len; goto out_err;
/* Create the name of the header object */ /* Create the name of the header object */
rbd_dev->obj_md_name = kmalloc(len + sizeof (RBD_SUFFIX), GFP_KERNEL); rbd_dev->obj_md_name = kmalloc(rbd_dev->obj_len
if (!rbd_dev->obj_md_name) { + sizeof (RBD_SUFFIX),
ret = -ENOMEM; GFP_KERNEL);
if (!rbd_dev->obj_md_name)
goto out_err; goto out_err;
}
sprintf(rbd_dev->obj_md_name, "%s%s", rbd_dev->obj, RBD_SUFFIX); sprintf(rbd_dev->obj_md_name, "%s%s", rbd_dev->obj, RBD_SUFFIX);
/* /*
...@@ -2411,6 +2406,7 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev, ...@@ -2411,6 +2406,7 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev,
out_err: out_err:
kfree(rbd_dev->obj_md_name); kfree(rbd_dev->obj_md_name);
kfree(rbd_dev->obj);
kfree(rbd_dev->pool_name); kfree(rbd_dev->pool_name);
rbd_dev->pool_name = NULL; rbd_dev->pool_name = NULL;
...@@ -2514,6 +2510,7 @@ static ssize_t rbd_add(struct bus_type *bus, ...@@ -2514,6 +2510,7 @@ static ssize_t rbd_add(struct bus_type *bus,
err_put_id: err_put_id:
if (rbd_dev->pool_name) { if (rbd_dev->pool_name) {
kfree(rbd_dev->obj_md_name); kfree(rbd_dev->obj_md_name);
kfree(rbd_dev->obj);
kfree(rbd_dev->pool_name); kfree(rbd_dev->pool_name);
} }
rbd_id_put(rbd_dev); rbd_id_put(rbd_dev);
...@@ -2566,6 +2563,7 @@ static void rbd_dev_release(struct device *dev) ...@@ -2566,6 +2563,7 @@ static void rbd_dev_release(struct device *dev)
/* done with the id, and with the rbd_dev */ /* done with the id, and with the rbd_dev */
kfree(rbd_dev->obj_md_name); kfree(rbd_dev->obj_md_name);
kfree(rbd_dev->pool_name); kfree(rbd_dev->pool_name);
kfree(rbd_dev->obj);
rbd_id_put(rbd_dev); rbd_id_put(rbd_dev);
kfree(rbd_dev); kfree(rbd_dev);
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#define RBD_MIN_OBJ_ORDER 16 #define RBD_MIN_OBJ_ORDER 16
#define RBD_MAX_OBJ_ORDER 30 #define RBD_MAX_OBJ_ORDER 30
#define RBD_MAX_OBJ_NAME_LEN 96
#define RBD_MAX_SEG_NAME_LEN 128 #define RBD_MAX_SEG_NAME_LEN 128
#define RBD_COMP_NONE 0 #define RBD_COMP_NONE 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment