summaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-07-09 21:04:24 -0500
committerSage Weil <sage@inktank.com>2012-07-30 09:30:04 -0700
commit820a5f3e94b9f8ea8c0c6125ce34b237ed67b1dc (patch)
tree0056a0c95a15a18de05e06846265a2f44c1b98f7 /drivers/block
parentbf3e5ae1129ef18a702c14fbaac27aeb2fe25e62 (diff)
downloadlinux-820a5f3e94b9f8ea8c0c6125ce34b237ed67b1dc.tar.bz2
rbd: dynamically allocate snapshot name
There is no need to impose a small limit the length of the snapshot name recorded for an rbd image in a struct rbd_dev. Remove the limitation by allocating space for the snapshot name dynamically. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/rbd.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 7d4735c9dba5..5c0f0445982c 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -172,7 +172,7 @@ struct rbd_device {
/* protects updating the header */
struct rw_semaphore header_rwsem;
- char snap_name[RBD_MAX_SNAP_NAME_LEN];
+ char *snap_name;
u64 snap_id; /* current snapshot id */
int read_only;
@@ -588,8 +588,6 @@ static int rbd_header_set_snap(struct rbd_device *dev, u64 *size)
struct ceph_snap_context *snapc = header->snapc;
int ret = -ENOENT;
- BUILD_BUG_ON(sizeof (dev->snap_name) < sizeof (RBD_SNAP_HEAD_NAME));
-
down_write(&dev->header_rwsem);
if (!memcmp(dev->snap_name, RBD_SNAP_HEAD_NAME,
@@ -2390,16 +2388,22 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev,
sprintf(rbd_dev->obj_md_name, "%s%s", rbd_dev->obj, RBD_SUFFIX);
/*
- * The snapshot name is optional, but it's an error if it's
- * too long. If no snapshot is supplied, fill in the default.
+ * The snapshot name is optional. If none is is supplied,
+ * we use the default value.
*/
- len = copy_token(&buf, rbd_dev->snap_name, sizeof (rbd_dev->snap_name));
- if (!len)
+ rbd_dev->snap_name = dup_token(&buf, &len);
+ if (!rbd_dev->snap_name)
+ goto out_err;
+ if (!len) {
+ /* Replace the empty name with the default */
+ kfree(rbd_dev->snap_name);
+ rbd_dev->snap_name
+ = kmalloc(sizeof (RBD_SNAP_HEAD_NAME), GFP_KERNEL);
+ if (!rbd_dev->snap_name)
+ goto out_err;
+
memcpy(rbd_dev->snap_name, RBD_SNAP_HEAD_NAME,
sizeof (RBD_SNAP_HEAD_NAME));
- else if (len >= sizeof (rbd_dev->snap_name)) {
- ret = -EINVAL;
- goto out_err;
}
return 0;
@@ -2509,6 +2513,7 @@ err_out_client:
rbd_put_client(rbd_dev);
err_put_id:
if (rbd_dev->pool_name) {
+ kfree(rbd_dev->snap_name);
kfree(rbd_dev->obj_md_name);
kfree(rbd_dev->obj);
kfree(rbd_dev->pool_name);
@@ -2561,6 +2566,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->snap_name);
kfree(rbd_dev->obj_md_name);
kfree(rbd_dev->pool_name);
kfree(rbd_dev->obj);