Commit ae7ca4a3 authored by Alex Elder's avatar Alex Elder

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: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
parent d07c0958
...@@ -1026,12 +1026,12 @@ static struct bio *bio_chain_clone_range(struct bio **bio_src, ...@@ -1026,12 +1026,12 @@ static struct bio *bio_chain_clone_range(struct bio **bio_src,
/* /*
* helpers for osd request op vectors. * helpers for osd request op vectors.
*/ */
static struct ceph_osd_req_op *rbd_create_rw_ops(int num_ops, static struct ceph_osd_req_op *rbd_create_rw_ops(int num_op,
int opcode, u32 payload_len) int opcode, u32 payload_len)
{ {
struct ceph_osd_req_op *ops; struct ceph_osd_req_op *ops;
ops = kzalloc(sizeof (*ops) * (num_ops + 1), GFP_NOIO); ops = kzalloc(num_op * sizeof (*ops), GFP_NOIO);
if (!ops) if (!ops)
return NULL; return NULL;
...@@ -1149,7 +1149,7 @@ static int rbd_do_request(struct request *rq, ...@@ -1149,7 +1149,7 @@ static int rbd_do_request(struct request *rq,
(unsigned long long) len, coll, coll_index); (unsigned long long) len, coll, coll_index);
osdc = &rbd_dev->rbd_client->client->osdc; osdc = &rbd_dev->rbd_client->client->osdc;
osd_req = ceph_osdc_alloc_request(osdc, snapc, ops, false, GFP_NOIO); osd_req = ceph_osdc_alloc_request(osdc, snapc, num_op, false, GFP_NOIO);
if (!osd_req) { if (!osd_req) {
ret = -ENOMEM; ret = -ENOMEM;
goto done_pages; goto done_pages;
...@@ -1178,7 +1178,8 @@ static int rbd_do_request(struct request *rq, ...@@ -1178,7 +1178,8 @@ static int rbd_do_request(struct request *rq,
ofs, &len, &bno, osd_req, ops); ofs, &len, &bno, osd_req, ops);
rbd_assert(ret == 0); rbd_assert(ret == 0);
ceph_osdc_build_request(osd_req, ofs, len, ops, snapc, snapid, &mtime); ceph_osdc_build_request(osd_req, ofs, len, num_op, ops,
snapc, snapid, &mtime);
if (linger_req) { if (linger_req) {
ceph_osdc_set_request_linger(osdc, osd_req); ceph_osdc_set_request_linger(osdc, osd_req);
......
...@@ -214,12 +214,13 @@ extern int ceph_calc_raw_layout(struct ceph_file_layout *layout, ...@@ -214,12 +214,13 @@ extern int ceph_calc_raw_layout(struct ceph_file_layout *layout,
extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
struct ceph_snap_context *snapc, struct ceph_snap_context *snapc,
struct ceph_osd_req_op *ops, unsigned int num_op,
bool use_mempool, bool use_mempool,
gfp_t gfp_flags); gfp_t gfp_flags);
extern void ceph_osdc_build_request(struct ceph_osd_request *req, extern void ceph_osdc_build_request(struct ceph_osd_request *req,
u64 off, u64 len, u64 off, u64 len,
unsigned int num_op,
struct ceph_osd_req_op *src_ops, struct ceph_osd_req_op *src_ops,
struct ceph_snap_context *snapc, struct ceph_snap_context *snapc,
u64 snap_id, u64 snap_id,
......
...@@ -160,25 +160,14 @@ void ceph_osdc_release_request(struct kref *kref) ...@@ -160,25 +160,14 @@ void ceph_osdc_release_request(struct kref *kref)
} }
EXPORT_SYMBOL(ceph_osdc_release_request); EXPORT_SYMBOL(ceph_osdc_release_request);
static int get_num_ops(struct ceph_osd_req_op *ops)
{
int i = 0;
while (ops[i].op)
i++;
return i;
}
struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
struct ceph_snap_context *snapc, struct ceph_snap_context *snapc,
struct ceph_osd_req_op *ops, unsigned int num_op,
bool use_mempool, bool use_mempool,
gfp_t gfp_flags) gfp_t gfp_flags)
{ {
struct ceph_osd_request *req; struct ceph_osd_request *req;
struct ceph_msg *msg; struct ceph_msg *msg;
int num_op = get_num_ops(ops);
size_t msg_size = sizeof(struct ceph_osd_request_head); size_t msg_size = sizeof(struct ceph_osd_request_head);
msg_size += num_op*sizeof(struct ceph_osd_op); 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,7 +306,7 @@ static void osd_req_encode_op(struct ceph_osd_request *req,
* *
*/ */
void ceph_osdc_build_request(struct ceph_osd_request *req, void ceph_osdc_build_request(struct ceph_osd_request *req,
u64 off, u64 len, u64 off, u64 len, unsigned int num_op,
struct ceph_osd_req_op *src_ops, struct ceph_osd_req_op *src_ops,
struct ceph_snap_context *snapc, u64 snap_id, struct ceph_snap_context *snapc, u64 snap_id,
struct timespec *mtime) struct timespec *mtime)
...@@ -327,7 +316,6 @@ void ceph_osdc_build_request(struct ceph_osd_request *req, ...@@ -327,7 +316,6 @@ void ceph_osdc_build_request(struct ceph_osd_request *req,
struct ceph_osd_req_op *src_op; struct ceph_osd_req_op *src_op;
struct ceph_osd_op *op; struct ceph_osd_op *op;
void *p; void *p;
int num_op = get_num_ops(src_ops);
size_t msg_size = sizeof(*head) + num_op*sizeof(*op); size_t msg_size = sizeof(*head) + num_op*sizeof(*op);
int flags = req->r_flags; int flags = req->r_flags;
u64 data_len = 0; u64 data_len = 0;
...@@ -346,20 +334,17 @@ void ceph_osdc_build_request(struct ceph_osd_request *req, ...@@ -346,20 +334,17 @@ void ceph_osdc_build_request(struct ceph_osd_request *req,
head->flags = cpu_to_le32(flags); head->flags = cpu_to_le32(flags);
if (flags & CEPH_OSD_FLAG_WRITE) if (flags & CEPH_OSD_FLAG_WRITE)
ceph_encode_timespec(&head->mtime, mtime); ceph_encode_timespec(&head->mtime, mtime);
BUG_ON(num_op > (unsigned int) ((u16) -1));
head->num_ops = cpu_to_le16(num_op); head->num_ops = cpu_to_le16(num_op);
/* fill in oid */ /* fill in oid */
head->object_len = cpu_to_le32(req->r_oid_len); head->object_len = cpu_to_le32(req->r_oid_len);
memcpy(p, req->r_oid, req->r_oid_len); memcpy(p, req->r_oid, req->r_oid_len);
p += req->r_oid_len; p += req->r_oid_len;
src_op = src_ops; src_op = src_ops;
while (src_op->op) { while (num_op--)
osd_req_encode_op(req, op, src_op); osd_req_encode_op(req, op++, src_op++);
src_op++;
op++;
}
data_len += req->r_trail.length; data_len += req->r_trail.length;
...@@ -414,23 +399,24 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, ...@@ -414,23 +399,24 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
bool use_mempool, int num_reply, bool use_mempool, int num_reply,
int page_align) int page_align)
{ {
struct ceph_osd_req_op ops[3]; struct ceph_osd_req_op ops[2];
struct ceph_osd_request *req; struct ceph_osd_request *req;
unsigned int num_op = 1;
int r; int r;
memset(&ops, 0, sizeof ops);
ops[0].op = opcode; ops[0].op = opcode;
ops[0].extent.truncate_seq = truncate_seq; ops[0].extent.truncate_seq = truncate_seq;
ops[0].extent.truncate_size = truncate_size; ops[0].extent.truncate_size = truncate_size;
ops[0].payload_len = 0;
if (do_sync) { if (do_sync) {
ops[1].op = CEPH_OSD_OP_STARTSYNC; ops[1].op = CEPH_OSD_OP_STARTSYNC;
ops[1].payload_len = 0; num_op++;
ops[2].op = 0; }
} else
ops[1].op = 0;
req = ceph_osdc_alloc_request(osdc, snapc, ops, use_mempool, GFP_NOFS); req = ceph_osdc_alloc_request(osdc, snapc, num_op, use_mempool,
GFP_NOFS);
if (!req) if (!req)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
req->r_flags = flags; req->r_flags = flags;
...@@ -446,7 +432,8 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, ...@@ -446,7 +432,8 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
req->r_num_pages = calc_pages_for(page_align, *plen); req->r_num_pages = calc_pages_for(page_align, *plen);
req->r_page_alignment = page_align; req->r_page_alignment = page_align;
ceph_osdc_build_request(req, off, *plen, ops, snapc, vino.snap, mtime); ceph_osdc_build_request(req, off, *plen, num_op, ops,
snapc, vino.snap, mtime);
return req; return req;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment