diff options
author | Alex Elder <elder@inktank.com> | 2013-03-13 21:50:01 -0400 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-05-02 00:17:48 -0400 |
commit | d18d1e2807f38a94839be1f83682e17011f53322 (patch) | |
tree | 5237d307969cfa0604dbb3c1c93fa08ee78d5ef3 /net/ceph/osd_client.c | |
parent | a19dadfba91c73a12a666e6fdb9e242f325df825 (diff) |
libceph: clean up ceph_osd_new_request()
All callers of ceph_osd_new_request() pass either CEPH_OSD_OP_READ
or CEPH_OSD_OP_WRITE as the opcode value. The function assumes it
by filling in the extent fields in the ops array it builds. So just
assert that is the case, and don't bother calling op_has_extent()
before filling in the first osd operation in the array.
Define some local variables to gather the information to fill into
the first op, and then fill in the op array all in one place.
Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'net/ceph/osd_client.c')
-rw-r--r-- | net/ceph/osd_client.c | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c index 0eb417b44195..7136060a0501 100644 --- a/net/ceph/osd_client.c +++ b/net/ceph/osd_client.c | |||
@@ -32,12 +32,6 @@ static void __unregister_linger_request(struct ceph_osd_client *osdc, | |||
32 | static void __send_request(struct ceph_osd_client *osdc, | 32 | static void __send_request(struct ceph_osd_client *osdc, |
33 | struct ceph_osd_request *req); | 33 | struct ceph_osd_request *req); |
34 | 34 | ||
35 | static int op_has_extent(int op) | ||
36 | { | ||
37 | return (op == CEPH_OSD_OP_READ || | ||
38 | op == CEPH_OSD_OP_WRITE); | ||
39 | } | ||
40 | |||
41 | /* | 35 | /* |
42 | * Implement client access to distributed object storage cluster. | 36 | * Implement client access to distributed object storage cluster. |
43 | * | 37 | * |
@@ -554,22 +548,15 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, | |||
554 | { | 548 | { |
555 | struct ceph_osd_req_op ops[2]; | 549 | struct ceph_osd_req_op ops[2]; |
556 | struct ceph_osd_request *req; | 550 | struct ceph_osd_request *req; |
557 | unsigned int num_op = 1; | 551 | unsigned int num_op = do_sync ? 2 : 1; |
558 | u64 objnum = 0; | 552 | u64 objnum = 0; |
559 | u64 objoff = 0; | 553 | u64 objoff = 0; |
560 | u64 objlen = 0; | 554 | u64 objlen = 0; |
555 | u32 object_size; | ||
556 | u64 object_base; | ||
561 | int r; | 557 | int r; |
562 | 558 | ||
563 | memset(&ops, 0, sizeof ops); | 559 | BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE); |
564 | |||
565 | ops[0].op = opcode; | ||
566 | ops[0].extent.truncate_seq = truncate_seq; | ||
567 | ops[0].extent.truncate_size = truncate_size; | ||
568 | |||
569 | if (do_sync) { | ||
570 | ops[1].op = CEPH_OSD_OP_STARTSYNC; | ||
571 | num_op++; | ||
572 | } | ||
573 | 560 | ||
574 | req = ceph_osdc_alloc_request(osdc, snapc, num_op, use_mempool, | 561 | req = ceph_osdc_alloc_request(osdc, snapc, num_op, use_mempool, |
575 | GFP_NOFS); | 562 | GFP_NOFS); |
@@ -584,21 +571,28 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, | |||
584 | return ERR_PTR(r); | 571 | return ERR_PTR(r); |
585 | } | 572 | } |
586 | 573 | ||
587 | if (op_has_extent(ops[0].op)) { | 574 | object_size = le32_to_cpu(layout->fl_object_size); |
588 | u32 osize = le32_to_cpu(layout->fl_object_size); | 575 | object_base = off - objoff; |
589 | ops[0].extent.offset = objoff; | 576 | if (truncate_size <= object_base) { |
590 | ops[0].extent.length = objlen; | 577 | truncate_size = 0; |
591 | if (ops[0].extent.truncate_size <= off - objoff) { | 578 | } else { |
592 | ops[0].extent.truncate_size = 0; | 579 | truncate_size -= object_base; |
593 | } else { | 580 | if (truncate_size > object_size) |
594 | ops[0].extent.truncate_size -= off - objoff; | 581 | truncate_size = object_size; |
595 | if (ops[0].extent.truncate_size > osize) | ||
596 | ops[0].extent.truncate_size = osize; | ||
597 | } | ||
598 | } | 582 | } |
583 | |||
584 | memset(&ops, 0, sizeof ops); | ||
585 | ops[0].op = opcode; | ||
586 | ops[0].extent.offset = objoff; | ||
587 | ops[0].extent.length = objlen; | ||
588 | ops[0].extent.truncate_size = truncate_size; | ||
589 | ops[0].extent.truncate_seq = truncate_seq; | ||
599 | if (ops[0].op == CEPH_OSD_OP_WRITE) | 590 | if (ops[0].op == CEPH_OSD_OP_WRITE) |
600 | ops[0].payload_len = *plen; | 591 | ops[0].payload_len = *plen; |
601 | 592 | ||
593 | if (do_sync) | ||
594 | ops[1].op = CEPH_OSD_OP_STARTSYNC; | ||
595 | |||
602 | req->r_file_layout = *layout; /* keep a copy */ | 596 | req->r_file_layout = *layout; /* keep a copy */ |
603 | 597 | ||
604 | snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx", | 598 | snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx", |