aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-11-13 22:11:15 -0500
committerAlex Elder <elder@inktank.com>2013-01-17 17:34:57 -0500
commitae7ca4a35b1f5df86e2c32b2cfc01a8d528c7b8c (patch)
treea6dfed1fd8f50cf59cd72be27408f51ee621607c /net
parentd07c09589f533db9ab500ac38151bc9f3a4d0648 (diff)
libceph: pass num_op with ops
Both ceph_osdc_alloc_request() and ceph_osdc_build_request() are provided an array of ceph osd request operations. Rather than just passing the number of operations in the array, the caller is required append an additional zeroed operation structure to signal the end of the array. All callers know the number of operations at the time these functions are called, so drop the silly zero entry and supply that number directly. As a result, get_num_ops() is no longer needed. This also means that ceph_osdc_alloc_request() never uses its ops argument, so that can be dropped. Also rbd_create_rw_ops() no longer needs to add one to reserve room for the additional op. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'net')
-rw-r--r--net/ceph/osd_client.c43
1 files changed, 15 insertions, 28 deletions
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index bdc3bb12bfd5..500ae8b49321 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -160,25 +160,14 @@ void ceph_osdc_release_request(struct kref *kref)
160} 160}
161EXPORT_SYMBOL(ceph_osdc_release_request); 161EXPORT_SYMBOL(ceph_osdc_release_request);
162 162
163static int get_num_ops(struct ceph_osd_req_op *ops)
164{
165 int i = 0;
166
167 while (ops[i].op)
168 i++;
169
170 return i;
171}
172
173struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, 163struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
174 struct ceph_snap_context *snapc, 164 struct ceph_snap_context *snapc,
175 struct ceph_osd_req_op *ops, 165 unsigned int num_op,
176 bool use_mempool, 166 bool use_mempool,
177 gfp_t gfp_flags) 167 gfp_t gfp_flags)
178{ 168{
179 struct ceph_osd_request *req; 169 struct ceph_osd_request *req;
180 struct ceph_msg *msg; 170 struct ceph_msg *msg;
181 int num_op = get_num_ops(ops);
182 size_t msg_size = sizeof(struct ceph_osd_request_head); 171 size_t msg_size = sizeof(struct ceph_osd_request_head);
183 172
184 msg_size += num_op*sizeof(struct ceph_osd_op); 173 msg_size += num_op*sizeof(struct ceph_osd_op);
@@ -317,7 +306,7 @@ static void osd_req_encode_op(struct ceph_osd_request *req,
317 * 306 *
318 */ 307 */
319void ceph_osdc_build_request(struct ceph_osd_request *req, 308void ceph_osdc_build_request(struct ceph_osd_request *req,
320 u64 off, u64 len, 309 u64 off, u64 len, unsigned int num_op,
321 struct ceph_osd_req_op *src_ops, 310 struct ceph_osd_req_op *src_ops,
322 struct ceph_snap_context *snapc, u64 snap_id, 311 struct ceph_snap_context *snapc, u64 snap_id,
323 struct timespec *mtime) 312 struct timespec *mtime)
@@ -327,7 +316,6 @@ void ceph_osdc_build_request(struct ceph_osd_request *req,
327 struct ceph_osd_req_op *src_op; 316 struct ceph_osd_req_op *src_op;
328 struct ceph_osd_op *op; 317 struct ceph_osd_op *op;
329 void *p; 318 void *p;
330 int num_op = get_num_ops(src_ops);
331 size_t msg_size = sizeof(*head) + num_op*sizeof(*op); 319 size_t msg_size = sizeof(*head) + num_op*sizeof(*op);
332 int flags = req->r_flags; 320 int flags = req->r_flags;
333 u64 data_len = 0; 321 u64 data_len = 0;
@@ -346,20 +334,17 @@ void ceph_osdc_build_request(struct ceph_osd_request *req,
346 head->flags = cpu_to_le32(flags); 334 head->flags = cpu_to_le32(flags);
347 if (flags & CEPH_OSD_FLAG_WRITE) 335 if (flags & CEPH_OSD_FLAG_WRITE)
348 ceph_encode_timespec(&head->mtime, mtime); 336 ceph_encode_timespec(&head->mtime, mtime);
337 BUG_ON(num_op > (unsigned int) ((u16) -1));
349 head->num_ops = cpu_to_le16(num_op); 338 head->num_ops = cpu_to_le16(num_op);
350 339
351
352 /* fill in oid */ 340 /* fill in oid */
353 head->object_len = cpu_to_le32(req->r_oid_len); 341 head->object_len = cpu_to_le32(req->r_oid_len);
354 memcpy(p, req->r_oid, req->r_oid_len); 342 memcpy(p, req->r_oid, req->r_oid_len);
355 p += req->r_oid_len; 343 p += req->r_oid_len;
356 344
357 src_op = src_ops; 345 src_op = src_ops;
358 while (src_op->op) { 346 while (num_op--)
359 osd_req_encode_op(req, op, src_op); 347 osd_req_encode_op(req, op++, src_op++);
360 src_op++;
361 op++;
362 }
363 348
364 data_len += req->r_trail.length; 349 data_len += req->r_trail.length;
365 350
@@ -414,23 +399,24 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
414 bool use_mempool, int num_reply, 399 bool use_mempool, int num_reply,
415 int page_align) 400 int page_align)
416{ 401{
417 struct ceph_osd_req_op ops[3]; 402 struct ceph_osd_req_op ops[2];
418 struct ceph_osd_request *req; 403 struct ceph_osd_request *req;
404 unsigned int num_op = 1;
419 int r; 405 int r;
420 406
407 memset(&ops, 0, sizeof ops);
408
421 ops[0].op = opcode; 409 ops[0].op = opcode;
422 ops[0].extent.truncate_seq = truncate_seq; 410 ops[0].extent.truncate_seq = truncate_seq;
423 ops[0].extent.truncate_size = truncate_size; 411 ops[0].extent.truncate_size = truncate_size;
424 ops[0].payload_len = 0;
425 412
426 if (do_sync) { 413 if (do_sync) {
427 ops[1].op = CEPH_OSD_OP_STARTSYNC; 414 ops[1].op = CEPH_OSD_OP_STARTSYNC;
428 ops[1].payload_len = 0; 415 num_op++;
429 ops[2].op = 0; 416 }
430 } else
431 ops[1].op = 0;
432 417
433 req = ceph_osdc_alloc_request(osdc, snapc, ops, use_mempool, GFP_NOFS); 418 req = ceph_osdc_alloc_request(osdc, snapc, num_op, use_mempool,
419 GFP_NOFS);
434 if (!req) 420 if (!req)
435 return ERR_PTR(-ENOMEM); 421 return ERR_PTR(-ENOMEM);
436 req->r_flags = flags; 422 req->r_flags = flags;
@@ -446,7 +432,8 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
446 req->r_num_pages = calc_pages_for(page_align, *plen); 432 req->r_num_pages = calc_pages_for(page_align, *plen);
447 req->r_page_alignment = page_align; 433 req->r_page_alignment = page_align;
448 434
449 ceph_osdc_build_request(req, off, *plen, ops, snapc, vino.snap, mtime); 435 ceph_osdc_build_request(req, off, *plen, num_op, ops,
436 snapc, vino.snap, mtime);
450 437
451 return req; 438 return req;
452} 439}