Commit d4b125e9 authored by Alex Elder's avatar Alex Elder

rbd: increase maximum snapshot name length

Change RBD_MAX_SNAP_NAME_LEN to be based on NAME_MAX.  That is a
practical limit for the length of a snapshot name (based on the
presence of a directory using the name under /sys/bus/rbd to
represent the snapshot).

The /sys entry is created by prefixing it with "snap_"; define that
prefix symbolically, and take its length into account in defining
the snapshot name length limit.

Enforce the limit in rbd_add_parse_args().  Also delete a dout()
call in that function that was not meant to be committed.
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarDan Mick <dan.mick@inktank.com>
Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
parent db2388b6
...@@ -61,7 +61,10 @@ ...@@ -61,7 +61,10 @@
#define RBD_MINORS_PER_MAJOR 256 /* max minors per blkdev */ #define RBD_MINORS_PER_MAJOR 256 /* max minors per blkdev */
#define RBD_MAX_SNAP_NAME_LEN 32 #define RBD_SNAP_DEV_NAME_PREFIX "snap_"
#define RBD_MAX_SNAP_NAME_LEN \
(NAME_MAX - (sizeof (RBD_SNAP_DEV_NAME_PREFIX) - 1))
#define RBD_MAX_SNAP_COUNT 510 /* allows max snapc to fit in 4KB */ #define RBD_MAX_SNAP_COUNT 510 /* allows max snapc to fit in 4KB */
#define RBD_MAX_OPT_LEN 1024 #define RBD_MAX_OPT_LEN 1024
...@@ -2063,7 +2066,7 @@ static int rbd_register_snap_dev(struct rbd_snap *snap, ...@@ -2063,7 +2066,7 @@ static int rbd_register_snap_dev(struct rbd_snap *snap,
dev->type = &rbd_snap_device_type; dev->type = &rbd_snap_device_type;
dev->parent = parent; dev->parent = parent;
dev->release = rbd_snap_dev_release; dev->release = rbd_snap_dev_release;
dev_set_name(dev, "snap_%s", snap->name); dev_set_name(dev, "%s%s", RBD_SNAP_DEV_NAME_PREFIX, snap->name);
dout("%s: registering device for snapshot %s\n", __func__, snap->name); dout("%s: registering device for snapshot %s\n", __func__, snap->name);
ret = device_register(dev); ret = device_register(dev);
...@@ -2797,8 +2800,13 @@ static char *rbd_add_parse_args(struct rbd_device *rbd_dev, ...@@ -2797,8 +2800,13 @@ static char *rbd_add_parse_args(struct rbd_device *rbd_dev,
if (!rbd_dev->image_name) if (!rbd_dev->image_name)
goto out_err; goto out_err;
/* Snapshot name is optional */ /* Snapshot name is optional; default is to use "head" */
len = next_token(&buf); len = next_token(&buf);
if (len > RBD_MAX_SNAP_NAME_LEN) {
err_ptr = ERR_PTR(-ENAMETOOLONG);
goto out_err;
}
if (!len) { if (!len) {
buf = RBD_SNAP_HEAD_NAME; /* No snapshot supplied */ buf = RBD_SNAP_HEAD_NAME; /* No snapshot supplied */
len = sizeof (RBD_SNAP_HEAD_NAME) - 1; len = sizeof (RBD_SNAP_HEAD_NAME) - 1;
...@@ -2809,8 +2817,6 @@ static char *rbd_add_parse_args(struct rbd_device *rbd_dev, ...@@ -2809,8 +2817,6 @@ static char *rbd_add_parse_args(struct rbd_device *rbd_dev,
memcpy(snap_name, buf, len); memcpy(snap_name, buf, len);
*(snap_name + len) = '\0'; *(snap_name + len) = '\0';
dout(" SNAP_NAME is <%s>, len is %zd\n", snap_name, len);
return snap_name; return snap_name;
out_err: out_err:
......
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