diff options
author | Alex Elder <elder@inktank.com> | 2012-08-24 00:22:06 -0400 |
---|---|---|
committer | Alex Elder <elder@inktank.com> | 2012-10-01 15:30:49 -0400 |
commit | f785cc1dbe90b561b8ded92df4fe9732bdc54859 (patch) | |
tree | 455a9d2e5e9eba5fc892d9cf40fca5d046f24ad6 /drivers/block/rbd.c | |
parent | 58c17b0e1b2278824aedc5d1201f6a43a38d6a48 (diff) |
rbd: kill incore snap_names_len
The only thing the on-disk snap_names_len field is needed is to
size the buffer allocated to hold a copy of the snapshot names
for an rbd image.
So don't bother saving it in the in-core rbd_image_header structure.
Just use a local variable to hold the required buffer size while
it's needed.
Move the code that actually copies the snapshot names up closer
to where the required length is saved.
Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Yehuda Sadeh <yehuda@inktank.com>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r-- | drivers/block/rbd.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index a27167942a92..163fd853a15f 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -81,7 +81,6 @@ struct rbd_image_header { | |||
81 | __u8 crypt_type; | 81 | __u8 crypt_type; |
82 | __u8 comp_type; | 82 | __u8 comp_type; |
83 | struct ceph_snap_context *snapc; | 83 | struct ceph_snap_context *snapc; |
84 | u64 snap_names_len; | ||
85 | u32 total_snaps; | 84 | u32 total_snaps; |
86 | 85 | ||
87 | char *snap_names; | 86 | char *snap_names; |
@@ -534,12 +533,21 @@ static int rbd_header_from_disk(struct rbd_image_header *header, | |||
534 | header->object_prefix[len] = '\0'; | 533 | header->object_prefix[len] = '\0'; |
535 | 534 | ||
536 | if (snap_count) { | 535 | if (snap_count) { |
537 | header->snap_names_len = le64_to_cpu(ondisk->snap_names_len); | 536 | u64 snap_names_len = le64_to_cpu(ondisk->snap_names_len); |
538 | BUG_ON(header->snap_names_len > (u64) SIZE_MAX); | 537 | |
539 | header->snap_names = kmalloc(header->snap_names_len, | 538 | if (snap_names_len > (u64) SIZE_MAX) |
540 | GFP_KERNEL); | 539 | return -EIO; |
540 | header->snap_names = kmalloc(snap_names_len, GFP_KERNEL); | ||
541 | if (!header->snap_names) | 541 | if (!header->snap_names) |
542 | goto out_err; | 542 | goto out_err; |
543 | /* | ||
544 | * Note that rbd_dev_v1_header_read() guarantees | ||
545 | * the ondisk buffer we're working with has | ||
546 | * snap_names_len bytes beyond the end of the | ||
547 | * snapshot id array, this memcpy() is safe. | ||
548 | */ | ||
549 | memcpy(header->snap_names, &ondisk->snaps[snap_count], | ||
550 | snap_names_len); | ||
543 | 551 | ||
544 | size = snap_count * sizeof (*header->snap_sizes); | 552 | size = snap_count * sizeof (*header->snap_sizes); |
545 | header->snap_sizes = kmalloc(size, GFP_KERNEL); | 553 | header->snap_sizes = kmalloc(size, GFP_KERNEL); |
@@ -547,7 +555,6 @@ static int rbd_header_from_disk(struct rbd_image_header *header, | |||
547 | goto out_err; | 555 | goto out_err; |
548 | } else { | 556 | } else { |
549 | WARN_ON(ondisk->snap_names_len); | 557 | WARN_ON(ondisk->snap_names_len); |
550 | header->snap_names_len = 0; | ||
551 | header->snap_names = NULL; | 558 | header->snap_names = NULL; |
552 | header->snap_sizes = NULL; | 559 | header->snap_sizes = NULL; |
553 | } | 560 | } |
@@ -579,10 +586,6 @@ static int rbd_header_from_disk(struct rbd_image_header *header, | |||
579 | header->snap_sizes[i] = | 586 | header->snap_sizes[i] = |
580 | le64_to_cpu(ondisk->snaps[i].image_size); | 587 | le64_to_cpu(ondisk->snaps[i].image_size); |
581 | } | 588 | } |
582 | |||
583 | /* copy snapshot names */ | ||
584 | memcpy(header->snap_names, &ondisk->snaps[snap_count], | ||
585 | header->snap_names_len); | ||
586 | } | 589 | } |
587 | 590 | ||
588 | return 0; | 591 | return 0; |
@@ -592,7 +595,6 @@ out_err: | |||
592 | header->snap_sizes = NULL; | 595 | header->snap_sizes = NULL; |
593 | kfree(header->snap_names); | 596 | kfree(header->snap_names); |
594 | header->snap_names = NULL; | 597 | header->snap_names = NULL; |
595 | header->snap_names_len = 0; | ||
596 | kfree(header->object_prefix); | 598 | kfree(header->object_prefix); |
597 | header->object_prefix = NULL; | 599 | header->object_prefix = NULL; |
598 | 600 | ||
@@ -660,7 +662,6 @@ static void rbd_header_free(struct rbd_image_header *header) | |||
660 | header->snap_sizes = NULL; | 662 | header->snap_sizes = NULL; |
661 | kfree(header->snap_names); | 663 | kfree(header->snap_names); |
662 | header->snap_names = NULL; | 664 | header->snap_names = NULL; |
663 | header->snap_names_len = 0; | ||
664 | ceph_put_snap_context(header->snapc); | 665 | ceph_put_snap_context(header->snapc); |
665 | header->snapc = NULL; | 666 | header->snapc = NULL; |
666 | } | 667 | } |
@@ -1800,7 +1801,6 @@ static int __rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver) | |||
1800 | rbd_dev->header.total_snaps = h.total_snaps; | 1801 | rbd_dev->header.total_snaps = h.total_snaps; |
1801 | rbd_dev->header.snapc = h.snapc; | 1802 | rbd_dev->header.snapc = h.snapc; |
1802 | rbd_dev->header.snap_names = h.snap_names; | 1803 | rbd_dev->header.snap_names = h.snap_names; |
1803 | rbd_dev->header.snap_names_len = h.snap_names_len; | ||
1804 | rbd_dev->header.snap_sizes = h.snap_sizes; | 1804 | rbd_dev->header.snap_sizes = h.snap_sizes; |
1805 | /* Free the extra copy of the object prefix */ | 1805 | /* Free the extra copy of the object prefix */ |
1806 | WARN_ON(strcmp(rbd_dev->header.object_prefix, h.object_prefix)); | 1806 | WARN_ON(strcmp(rbd_dev->header.object_prefix, h.object_prefix)); |