diff options
author | Alex Elder <elder@inktank.com> | 2013-04-03 02:28:57 -0400 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-05-02 00:18:08 -0400 |
commit | c54d47bfadce7059af0774d80b2b3faaea4afd28 (patch) | |
tree | 3f71a5c736f9b5021ccfc07849dcd95597e83b07 | |
parent | 43bfe5de9fa78e07248b70992ce50321efec622c (diff) |
libceph: define a few more helpers
Define ceph_osd_data_init() and ceph_osd_data_release() to clean up
a little code.
Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
-rw-r--r-- | net/ceph/osd_client.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c index f8f8561b602e..b399e8a18f2b 100644 --- a/net/ceph/osd_client.c +++ b/net/ceph/osd_client.c | |||
@@ -79,6 +79,12 @@ static int calc_layout(struct ceph_file_layout *layout, u64 off, u64 *plen, | |||
79 | return 0; | 79 | return 0; |
80 | } | 80 | } |
81 | 81 | ||
82 | static void ceph_osd_data_init(struct ceph_osd_data *osd_data) | ||
83 | { | ||
84 | memset(osd_data, 0, sizeof (*osd_data)); | ||
85 | osd_data->type = CEPH_OSD_DATA_TYPE_NONE; | ||
86 | } | ||
87 | |||
82 | void ceph_osd_data_pages_init(struct ceph_osd_data *osd_data, | 88 | void ceph_osd_data_pages_init(struct ceph_osd_data *osd_data, |
83 | struct page **pages, u64 length, u32 alignment, | 89 | struct page **pages, u64 length, u32 alignment, |
84 | bool pages_from_pool, bool own_pages) | 90 | bool pages_from_pool, bool own_pages) |
@@ -111,16 +117,28 @@ void ceph_osd_data_bio_init(struct ceph_osd_data *osd_data, | |||
111 | EXPORT_SYMBOL(ceph_osd_data_bio_init); | 117 | EXPORT_SYMBOL(ceph_osd_data_bio_init); |
112 | #endif /* CONFIG_BLOCK */ | 118 | #endif /* CONFIG_BLOCK */ |
113 | 119 | ||
120 | static void ceph_osd_data_release(struct ceph_osd_data *osd_data) | ||
121 | { | ||
122 | if (osd_data->type != CEPH_OSD_DATA_TYPE_PAGES) | ||
123 | return; | ||
124 | |||
125 | if (osd_data->own_pages) { | ||
126 | int num_pages; | ||
127 | |||
128 | num_pages = calc_pages_for((u64)osd_data->alignment, | ||
129 | (u64)osd_data->length); | ||
130 | ceph_release_page_vector(osd_data->pages, num_pages); | ||
131 | } | ||
132 | } | ||
133 | |||
114 | /* | 134 | /* |
115 | * requests | 135 | * requests |
116 | */ | 136 | */ |
117 | void ceph_osdc_release_request(struct kref *kref) | 137 | void ceph_osdc_release_request(struct kref *kref) |
118 | { | 138 | { |
119 | int num_pages; | 139 | struct ceph_osd_request *req; |
120 | struct ceph_osd_request *req = container_of(kref, | ||
121 | struct ceph_osd_request, | ||
122 | r_kref); | ||
123 | 140 | ||
141 | req = container_of(kref, struct ceph_osd_request, r_kref); | ||
124 | if (req->r_request) | 142 | if (req->r_request) |
125 | ceph_msg_put(req->r_request); | 143 | ceph_msg_put(req->r_request); |
126 | if (req->r_reply) { | 144 | if (req->r_reply) { |
@@ -128,18 +146,8 @@ void ceph_osdc_release_request(struct kref *kref) | |||
128 | ceph_msg_put(req->r_reply); | 146 | ceph_msg_put(req->r_reply); |
129 | } | 147 | } |
130 | 148 | ||
131 | if (req->r_data_in.type == CEPH_OSD_DATA_TYPE_PAGES && | 149 | ceph_osd_data_release(&req->r_data_in); |
132 | req->r_data_in.own_pages) { | 150 | ceph_osd_data_release(&req->r_data_out); |
133 | num_pages = calc_pages_for((u64)req->r_data_in.alignment, | ||
134 | (u64)req->r_data_in.length); | ||
135 | ceph_release_page_vector(req->r_data_in.pages, num_pages); | ||
136 | } | ||
137 | if (req->r_data_out.type == CEPH_OSD_DATA_TYPE_PAGES && | ||
138 | req->r_data_out.own_pages) { | ||
139 | num_pages = calc_pages_for((u64)req->r_data_out.alignment, | ||
140 | (u64)req->r_data_out.length); | ||
141 | ceph_release_page_vector(req->r_data_out.pages, num_pages); | ||
142 | } | ||
143 | 151 | ||
144 | ceph_put_snap_context(req->r_snapc); | 152 | ceph_put_snap_context(req->r_snapc); |
145 | if (req->r_mempool) | 153 | if (req->r_mempool) |
@@ -203,8 +211,8 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, | |||
203 | } | 211 | } |
204 | req->r_reply = msg; | 212 | req->r_reply = msg; |
205 | 213 | ||
206 | req->r_data_in.type = CEPH_OSD_DATA_TYPE_NONE; | 214 | ceph_osd_data_init(&req->r_data_in); |
207 | req->r_data_out.type = CEPH_OSD_DATA_TYPE_NONE; | 215 | ceph_osd_data_init(&req->r_data_out); |
208 | 216 | ||
209 | /* create request message; allow space for oid */ | 217 | /* create request message; allow space for oid */ |
210 | if (use_mempool) | 218 | if (use_mempool) |