提交 d18d1e28 编写于 作者: A Alex Elder 提交者: Sage Weil

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: NAlex Elder <elder@inktank.com>
Reviewed-by: NJosh Durgin <josh.durgin@inktank.com>
上级 a19dadfb
...@@ -32,12 +32,6 @@ static void __unregister_linger_request(struct ceph_osd_client *osdc, ...@@ -32,12 +32,6 @@ static void __unregister_linger_request(struct ceph_osd_client *osdc,
static void __send_request(struct ceph_osd_client *osdc, static void __send_request(struct ceph_osd_client *osdc,
struct ceph_osd_request *req); struct ceph_osd_request *req);
static int op_has_extent(int op)
{
return (op == CEPH_OSD_OP_READ ||
op == CEPH_OSD_OP_WRITE);
}
/* /*
* Implement client access to distributed object storage cluster. * Implement client access to distributed object storage cluster.
* *
...@@ -554,22 +548,15 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, ...@@ -554,22 +548,15 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
{ {
struct ceph_osd_req_op ops[2]; struct ceph_osd_req_op ops[2];
struct ceph_osd_request *req; struct ceph_osd_request *req;
unsigned int num_op = 1; unsigned int num_op = do_sync ? 2 : 1;
u64 objnum = 0; u64 objnum = 0;
u64 objoff = 0; u64 objoff = 0;
u64 objlen = 0; u64 objlen = 0;
u32 object_size;
u64 object_base;
int r; int r;
memset(&ops, 0, sizeof ops); BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE);
ops[0].op = opcode;
ops[0].extent.truncate_seq = truncate_seq;
ops[0].extent.truncate_size = truncate_size;
if (do_sync) {
ops[1].op = CEPH_OSD_OP_STARTSYNC;
num_op++;
}
req = ceph_osdc_alloc_request(osdc, snapc, num_op, use_mempool, req = ceph_osdc_alloc_request(osdc, snapc, num_op, use_mempool,
GFP_NOFS); GFP_NOFS);
...@@ -584,21 +571,28 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, ...@@ -584,21 +571,28 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
return ERR_PTR(r); return ERR_PTR(r);
} }
if (op_has_extent(ops[0].op)) { object_size = le32_to_cpu(layout->fl_object_size);
u32 osize = le32_to_cpu(layout->fl_object_size); object_base = off - objoff;
ops[0].extent.offset = objoff; if (truncate_size <= object_base) {
ops[0].extent.length = objlen; truncate_size = 0;
if (ops[0].extent.truncate_size <= off - objoff) { } else {
ops[0].extent.truncate_size = 0; truncate_size -= object_base;
} else { if (truncate_size > object_size)
ops[0].extent.truncate_size -= off - objoff; truncate_size = object_size;
if (ops[0].extent.truncate_size > osize)
ops[0].extent.truncate_size = osize;
}
} }
memset(&ops, 0, sizeof ops);
ops[0].op = opcode;
ops[0].extent.offset = objoff;
ops[0].extent.length = objlen;
ops[0].extent.truncate_size = truncate_size;
ops[0].extent.truncate_seq = truncate_seq;
if (ops[0].op == CEPH_OSD_OP_WRITE) if (ops[0].op == CEPH_OSD_OP_WRITE)
ops[0].payload_len = *plen; ops[0].payload_len = *plen;
if (do_sync)
ops[1].op = CEPH_OSD_OP_STARTSYNC;
req->r_file_layout = *layout; /* keep a copy */ req->r_file_layout = *layout; /* keep a copy */
snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx", snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册