diff options
author | Alex Elder <elder@inktank.com> | 2013-04-30 01:44:32 -0400 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-05-02 00:20:09 -0400 |
commit | 812164f8c3f6f5348aa69003a2f81775c2872ac0 (patch) | |
tree | 55b322ee4736ea34d6aae6527146aabe872a4cd3 | |
parent | 4f0dcb10cf1454a1c38aeaa04cb2757535e4905e (diff) |
ceph: use ceph_create_snap_context()
Now that we have a library routine to create snap contexts, use it.
This is part of:
http://tracker.ceph.com/issues/4857
Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
-rw-r--r-- | drivers/block/rbd.c | 41 | ||||
-rw-r--r-- | fs/ceph/snap.c | 3 |
2 files changed, 7 insertions, 37 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index d41f97690343..5c1c38dc0b51 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -672,35 +672,6 @@ static void rbd_client_release(struct kref *kref) | |||
672 | kfree(rbdc); | 672 | kfree(rbdc); |
673 | } | 673 | } |
674 | 674 | ||
675 | /* Caller has to fill in snapc->seq and snapc->snaps[0..snap_count-1] */ | ||
676 | |||
677 | static struct ceph_snap_context *rbd_snap_context_create(u32 snap_count) | ||
678 | { | ||
679 | struct ceph_snap_context *snapc; | ||
680 | size_t size; | ||
681 | |||
682 | size = sizeof (struct ceph_snap_context); | ||
683 | size += snap_count * sizeof (snapc->snaps[0]); | ||
684 | snapc = kzalloc(size, GFP_KERNEL); | ||
685 | if (!snapc) | ||
686 | return NULL; | ||
687 | |||
688 | atomic_set(&snapc->nref, 1); | ||
689 | snapc->num_snaps = snap_count; | ||
690 | |||
691 | return snapc; | ||
692 | } | ||
693 | |||
694 | static inline void rbd_snap_context_get(struct ceph_snap_context *snapc) | ||
695 | { | ||
696 | (void)ceph_get_snap_context(snapc); | ||
697 | } | ||
698 | |||
699 | static inline void rbd_snap_context_put(struct ceph_snap_context *snapc) | ||
700 | { | ||
701 | ceph_put_snap_context(snapc); | ||
702 | } | ||
703 | |||
704 | /* | 675 | /* |
705 | * Drop reference to ceph client node. If it's not referenced anymore, release | 676 | * Drop reference to ceph client node. If it's not referenced anymore, release |
706 | * it. | 677 | * it. |
@@ -820,7 +791,7 @@ static int rbd_header_from_disk(struct rbd_image_header *header, | |||
820 | 791 | ||
821 | header->image_size = le64_to_cpu(ondisk->image_size); | 792 | header->image_size = le64_to_cpu(ondisk->image_size); |
822 | 793 | ||
823 | header->snapc = rbd_snap_context_create(snap_count); | 794 | header->snapc = ceph_create_snap_context(snap_count, GFP_KERNEL); |
824 | if (!header->snapc) | 795 | if (!header->snapc) |
825 | goto out_err; | 796 | goto out_err; |
826 | header->snapc->seq = le64_to_cpu(ondisk->snap_seq); | 797 | header->snapc->seq = le64_to_cpu(ondisk->snap_seq); |
@@ -1753,7 +1724,7 @@ static struct rbd_img_request *rbd_img_request_create( | |||
1753 | 1724 | ||
1754 | if (write_request) { | 1725 | if (write_request) { |
1755 | down_read(&rbd_dev->header_rwsem); | 1726 | down_read(&rbd_dev->header_rwsem); |
1756 | rbd_snap_context_get(rbd_dev->header.snapc); | 1727 | ceph_get_snap_context(rbd_dev->header.snapc); |
1757 | up_read(&rbd_dev->header_rwsem); | 1728 | up_read(&rbd_dev->header_rwsem); |
1758 | } | 1729 | } |
1759 | 1730 | ||
@@ -1805,7 +1776,7 @@ static void rbd_img_request_destroy(struct kref *kref) | |||
1805 | rbd_assert(img_request->obj_request_count == 0); | 1776 | rbd_assert(img_request->obj_request_count == 0); |
1806 | 1777 | ||
1807 | if (img_request_write_test(img_request)) | 1778 | if (img_request_write_test(img_request)) |
1808 | rbd_snap_context_put(img_request->snapc); | 1779 | ceph_put_snap_context(img_request->snapc); |
1809 | 1780 | ||
1810 | if (img_request_child_test(img_request)) | 1781 | if (img_request_child_test(img_request)) |
1811 | rbd_obj_request_put(img_request->obj_request); | 1782 | rbd_obj_request_put(img_request->obj_request); |
@@ -3071,7 +3042,7 @@ static int rbd_dev_v1_refresh(struct rbd_device *rbd_dev, u64 *hver) | |||
3071 | kfree(rbd_dev->header.snap_sizes); | 3042 | kfree(rbd_dev->header.snap_sizes); |
3072 | kfree(rbd_dev->header.snap_names); | 3043 | kfree(rbd_dev->header.snap_names); |
3073 | /* osd requests may still refer to snapc */ | 3044 | /* osd requests may still refer to snapc */ |
3074 | rbd_snap_context_put(rbd_dev->header.snapc); | 3045 | ceph_put_snap_context(rbd_dev->header.snapc); |
3075 | 3046 | ||
3076 | if (hver) | 3047 | if (hver) |
3077 | *hver = h.obj_version; | 3048 | *hver = h.obj_version; |
@@ -3914,7 +3885,7 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev, u64 *ver) | |||
3914 | goto out; | 3885 | goto out; |
3915 | ret = 0; | 3886 | ret = 0; |
3916 | 3887 | ||
3917 | snapc = rbd_snap_context_create(snap_count); | 3888 | snapc = ceph_create_snap_context(snap_count, GFP_KERNEL); |
3918 | if (!snapc) { | 3889 | if (!snapc) { |
3919 | ret = -ENOMEM; | 3890 | ret = -ENOMEM; |
3920 | goto out; | 3891 | goto out; |
@@ -4590,7 +4561,7 @@ static void rbd_dev_unprobe(struct rbd_device *rbd_dev) | |||
4590 | /* Free dynamic fields from the header, then zero it out */ | 4561 | /* Free dynamic fields from the header, then zero it out */ |
4591 | 4562 | ||
4592 | header = &rbd_dev->header; | 4563 | header = &rbd_dev->header; |
4593 | rbd_snap_context_put(header->snapc); | 4564 | ceph_put_snap_context(header->snapc); |
4594 | kfree(header->snap_sizes); | 4565 | kfree(header->snap_sizes); |
4595 | kfree(header->snap_names); | 4566 | kfree(header->snap_names); |
4596 | kfree(header->object_prefix); | 4567 | kfree(header->object_prefix); |
diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c index cbb2f54a3019..f01645a27752 100644 --- a/fs/ceph/snap.c +++ b/fs/ceph/snap.c | |||
@@ -332,10 +332,9 @@ static int build_snap_context(struct ceph_snap_realm *realm) | |||
332 | err = -ENOMEM; | 332 | err = -ENOMEM; |
333 | if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64)) | 333 | if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64)) |
334 | goto fail; | 334 | goto fail; |
335 | snapc = kzalloc(sizeof(*snapc) + num*sizeof(u64), GFP_NOFS); | 335 | snapc = ceph_create_snap_context(num, GFP_NOFS); |
336 | if (!snapc) | 336 | if (!snapc) |
337 | goto fail; | 337 | goto fail; |
338 | atomic_set(&snapc->nref, 1); | ||
339 | 338 | ||
340 | /* build (reverse sorted) snap vector */ | 339 | /* build (reverse sorted) snap vector */ |
341 | num = 0; | 340 | num = 0; |