aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2013-03-13 21:50:00 -0400
committerSage Weil <sage@inktank.com>2013-05-02 00:17:46 -0400
commit75d1c941e57d4247de4c0ed4064a65cf1a4d3ed8 (patch)
tree58a1f59a447cf2afb70e961b05bf065e7f6bbdb3
parent33803f3300265661b5c5d20a9811c6a2a157d545 (diff)
libceph: pass offset and length out of calc_layout()
The purpose of calc_layout() is to determine, given a file offset and length and a layout describing the placement of file data across objects, where in "object space" that data resides. Specifically, it determines which object should hold the first part of the specified range of file data, and the offset and length of data within that object. The length will not exceed the bounds of the object, and the caller is informed of that maximum length. Add two parameters to calc_layout() to allow the object-relative offset and length to be passed back to the caller. This is the first steps toward having ceph_osdc_new_request() build its osd op structure using osd_req_op_extent_init(). Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
-rw-r--r--net/ceph/osd_client.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 02ed72820479..f782aca54daa 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -64,32 +64,31 @@ static int op_has_extent(int op)
64 * fill osd op in request message. 64 * fill osd op in request message.
65 */ 65 */
66static int calc_layout(struct ceph_file_layout *layout, u64 off, u64 *plen, 66static int calc_layout(struct ceph_file_layout *layout, u64 off, u64 *plen,
67 struct ceph_osd_req_op *op, u64 *bno) 67 struct ceph_osd_req_op *op, u64 *objnum,
68 u64 *objoff, u64 *objlen)
68{ 69{
69 u64 orig_len = *plen; 70 u64 orig_len = *plen;
70 u64 objoff = 0;
71 u64 objlen = 0;
72 int r; 71 int r;
73 72
74 /* object extent? */ 73 /* object extent? */
75 r = ceph_calc_file_object_mapping(layout, off, orig_len, bno, 74 r = ceph_calc_file_object_mapping(layout, off, orig_len, objnum,
76 &objoff, &objlen); 75 objoff, objlen);
77 if (r < 0) 76 if (r < 0)
78 return r; 77 return r;
79 if (objlen < orig_len) { 78 if (*objlen < orig_len) {
80 *plen = objlen; 79 *plen = *objlen;
81 dout(" skipping last %llu, final file extent %llu~%llu\n", 80 dout(" skipping last %llu, final file extent %llu~%llu\n",
82 orig_len - *plen, off, *plen); 81 orig_len - *plen, off, *plen);
83 } 82 }
84 83
85 if (op_has_extent(op->op)) { 84 if (op_has_extent(op->op)) {
86 u32 osize = le32_to_cpu(layout->fl_object_size); 85 u32 osize = le32_to_cpu(layout->fl_object_size);
87 op->extent.offset = objoff; 86 op->extent.offset = *objoff;
88 op->extent.length = objlen; 87 op->extent.length = *objlen;
89 if (op->extent.truncate_size <= off - objoff) { 88 if (op->extent.truncate_size <= off - *objoff) {
90 op->extent.truncate_size = 0; 89 op->extent.truncate_size = 0;
91 } else { 90 } else {
92 op->extent.truncate_size -= off - objoff; 91 op->extent.truncate_size -= off - *objoff;
93 if (op->extent.truncate_size > osize) 92 if (op->extent.truncate_size > osize)
94 op->extent.truncate_size = osize; 93 op->extent.truncate_size = osize;
95 } 94 }
@@ -97,7 +96,7 @@ static int calc_layout(struct ceph_file_layout *layout, u64 off, u64 *plen,
97 if (op->op == CEPH_OSD_OP_WRITE) 96 if (op->op == CEPH_OSD_OP_WRITE)
98 op->payload_len = *plen; 97 op->payload_len = *plen;
99 98
100 dout("calc_layout bno=%llx %llu~%llu\n", *bno, objoff, objlen); 99 dout("calc_layout objnum=%llx %llu~%llu\n", *objnum, *objoff, *objlen);
101 100
102 return 0; 101 return 0;
103} 102}
@@ -572,7 +571,9 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
572 struct ceph_osd_req_op ops[2]; 571 struct ceph_osd_req_op ops[2];
573 struct ceph_osd_request *req; 572 struct ceph_osd_request *req;
574 unsigned int num_op = 1; 573 unsigned int num_op = 1;
575 u64 bno = 0; 574 u64 objnum = 0;
575 u64 objoff = 0;
576 u64 objlen = 0;
576 int r; 577 int r;
577 578
578 memset(&ops, 0, sizeof ops); 579 memset(&ops, 0, sizeof ops);
@@ -593,14 +594,15 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
593 req->r_flags = flags; 594 req->r_flags = flags;
594 595
595 /* calculate max write size */ 596 /* calculate max write size */
596 r = calc_layout(layout, off, plen, ops, &bno); 597 r = calc_layout(layout, off, plen, ops, &objnum, &objoff, &objlen);
597 if (r < 0) { 598 if (r < 0) {
598 ceph_osdc_put_request(req); 599 ceph_osdc_put_request(req);
599 return ERR_PTR(r); 600 return ERR_PTR(r);
600 } 601 }
601 req->r_file_layout = *layout; /* keep a copy */ 602 req->r_file_layout = *layout; /* keep a copy */
602 603
603 snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx", vino.ino, bno); 604 snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx",
605 vino.ino, objnum);
604 req->r_oid_len = strlen(req->r_oid); 606 req->r_oid_len = strlen(req->r_oid);
605 607
606 ceph_osdc_build_request(req, off, num_op, ops, 608 ceph_osdc_build_request(req, off, num_op, ops,