aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/rbd.c
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-07-09 22:04:24 -0400
committerSage Weil <sage@inktank.com>2012-07-30 12:30:02 -0400
commit849b4260d482f7d4be5565b2044901a25f80e2c6 (patch)
treecea7dc8ccc5b584dce337cdf17d866c5d11bac07 /drivers/block/rbd.c
parentd22f76e703040c2cc4ad13dd7747845b9844d360 (diff)
rbd: dynamically allocate object prefix
There is no need to impose a small limit the length of the object prefix recorded for an rbd image in a struct rbd_image_header. Remove the limitation by allocating space for the object prefix dynamically. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r--drivers/block/rbd.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 61ce29d268a6..92867f3e945c 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -77,7 +77,7 @@
77 */ 77 */
78struct rbd_image_header { 78struct rbd_image_header {
79 u64 image_size; 79 u64 image_size;
80 char object_prefix[32]; 80 char *object_prefix;
81 __u8 obj_order; 81 __u8 obj_order;
82 __u8 crypt_type; 82 __u8 crypt_type;
83 __u8 comp_type; 83 __u8 comp_type;
@@ -517,8 +517,15 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
517 header->snap_names = NULL; 517 header->snap_names = NULL;
518 header->snap_sizes = NULL; 518 header->snap_sizes = NULL;
519 } 519 }
520
521 header->object_prefix = kmalloc(sizeof (ondisk->block_name) + 1,
522 gfp_flags);
523 if (!header->object_prefix)
524 goto err_sizes;
525
520 memcpy(header->object_prefix, ondisk->block_name, 526 memcpy(header->object_prefix, ondisk->block_name,
521 sizeof(ondisk->block_name)); 527 sizeof(ondisk->block_name));
528 header->object_prefix[sizeof (ondisk->block_name)] = '\0';
522 529
523 header->image_size = le64_to_cpu(ondisk->image_size); 530 header->image_size = le64_to_cpu(ondisk->image_size);
524 header->obj_order = ondisk->options.order; 531 header->obj_order = ondisk->options.order;
@@ -545,6 +552,8 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
545 552
546 return 0; 553 return 0;
547 554
555err_sizes:
556 kfree(header->snap_sizes);
548err_names: 557err_names:
549 kfree(header->snap_names); 558 kfree(header->snap_names);
550err_snapc: 559err_snapc:
@@ -610,9 +619,10 @@ done:
610 619
611static void rbd_header_free(struct rbd_image_header *header) 620static void rbd_header_free(struct rbd_image_header *header)
612{ 621{
613 kfree(header->snapc); 622 kfree(header->object_prefix);
614 kfree(header->snap_names);
615 kfree(header->snap_sizes); 623 kfree(header->snap_sizes);
624 kfree(header->snap_names);
625 kfree(header->snapc);
616} 626}
617 627
618/* 628/*
@@ -1710,15 +1720,20 @@ static int __rbd_refresh_header(struct rbd_device *rbd_dev)
1710 if head moves */ 1720 if head moves */
1711 follow_seq = 1; 1721 follow_seq = 1;
1712 1722
1713 kfree(rbd_dev->header.snapc); 1723 /* rbd_dev->header.object_prefix shouldn't change */
1714 kfree(rbd_dev->header.snap_names);
1715 kfree(rbd_dev->header.snap_sizes); 1724 kfree(rbd_dev->header.snap_sizes);
1725 kfree(rbd_dev->header.snap_names);
1726 kfree(rbd_dev->header.snapc);
1716 1727
1717 rbd_dev->header.total_snaps = h.total_snaps; 1728 rbd_dev->header.total_snaps = h.total_snaps;
1718 rbd_dev->header.snapc = h.snapc; 1729 rbd_dev->header.snapc = h.snapc;
1719 rbd_dev->header.snap_names = h.snap_names; 1730 rbd_dev->header.snap_names = h.snap_names;
1720 rbd_dev->header.snap_names_len = h.snap_names_len; 1731 rbd_dev->header.snap_names_len = h.snap_names_len;
1721 rbd_dev->header.snap_sizes = h.snap_sizes; 1732 rbd_dev->header.snap_sizes = h.snap_sizes;
1733 /* Free the extra copy of the object prefix */
1734 WARN_ON(strcmp(rbd_dev->header.object_prefix, h.object_prefix));
1735 kfree(h.object_prefix);
1736
1722 if (follow_seq) 1737 if (follow_seq)
1723 rbd_dev->header.snapc->seq = rbd_dev->header.snapc->snaps[0]; 1738 rbd_dev->header.snapc->seq = rbd_dev->header.snapc->snaps[0];
1724 else 1739 else
@@ -2361,10 +2376,11 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev,
2361 if (!rbd_dev->pool_name) 2376 if (!rbd_dev->pool_name)
2362 return -ENOMEM; 2377 return -ENOMEM;
2363 2378
2364 ret = -EINVAL;
2365 len = copy_token(&buf, rbd_dev->obj, sizeof (rbd_dev->obj)); 2379 len = copy_token(&buf, rbd_dev->obj, sizeof (rbd_dev->obj));
2366 if (!len || len >= sizeof (rbd_dev->obj)) 2380 if (!len || len >= sizeof (rbd_dev->obj)) {
2381 ret = -EINVAL;
2367 goto out_err; 2382 goto out_err;
2383 }
2368 2384
2369 /* We have the object length in hand, save it. */ 2385 /* We have the object length in hand, save it. */
2370 2386
@@ -2382,8 +2398,10 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev,
2382 if (!len) 2398 if (!len)
2383 memcpy(rbd_dev->snap_name, RBD_SNAP_HEAD_NAME, 2399 memcpy(rbd_dev->snap_name, RBD_SNAP_HEAD_NAME,
2384 sizeof (RBD_SNAP_HEAD_NAME)); 2400 sizeof (RBD_SNAP_HEAD_NAME));
2385 else if (len >= sizeof (rbd_dev->snap_name)) 2401 else if (len >= sizeof (rbd_dev->snap_name)) {
2402 ret = -EINVAL;
2386 goto out_err; 2403 goto out_err;
2404 }
2387 2405
2388 return 0; 2406 return 0;
2389 2407