Skip to content

Commit c99d2d4

Browse files
Alex ElderSage Weil
authored andcommitted
libceph: specify osd op by index in request
An osd request now holds all of its source op structures, and every place that initializes one of these is in fact initializing one of the entries in the the osd request's array. So rather than supplying the address of the op to initialize, have caller specify the osd request and an indication of which op it would like to initialize. This better hides the details the op structure (and faciltates moving the data pointers they use). Since osd_req_op_init() is a common routine, and it's not used outside the osd client code, give it static scope. Also make it return the address of the specified op (so all the other init routines don't have to repeat that code). Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
1 parent 8c042b0 commit c99d2d4

4 files changed

Lines changed: 67 additions & 53 deletions

File tree

‎drivers/block/rbd.c‎

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,16 +1336,17 @@ static void rbd_osd_req_format_op(struct rbd_obj_request *obj_request,
13361336
snap_id = img_request->snap_id;
13371337
}
13381338
if (obj_request->type != OBJ_REQUEST_NODATA) {
1339-
struct ceph_osd_req_op *op = &obj_request->osd_req->r_ops[0];
1340-
13411339
/*
13421340
* If it has data, it's either a object class method
13431341
* call (cls) or it's an extent operation.
13441342
*/
1345-
if (op->op == CEPH_OSD_OP_CALL)
1346-
osd_req_op_cls_response_data(op, osd_data);
1343+
/* XXX This use of the ops array goes away in the next patch */
1344+
if (obj_request->osd_req->r_ops[0].op == CEPH_OSD_OP_CALL)
1345+
osd_req_op_cls_response_data(obj_request->osd_req, 0,
1346+
osd_data);
13471347
else
1348-
osd_req_op_extent_osd_data(op, osd_data);
1348+
osd_req_op_extent_osd_data(obj_request->osd_req, 0,
1349+
osd_data);
13491350
}
13501351
ceph_osdc_build_request(osd_req, obj_request->offset,
13511352
snapc, snap_id, mtime);
@@ -1577,7 +1578,6 @@ static int rbd_img_request_fill_bio(struct rbd_img_request *img_request,
15771578
while (resid) {
15781579
const char *object_name;
15791580
unsigned int clone_size;
1580-
struct ceph_osd_req_op *op;
15811581
u64 offset;
15821582
u64 length;
15831583

@@ -1606,8 +1606,8 @@ static int rbd_img_request_fill_bio(struct rbd_img_request *img_request,
16061606
if (!obj_request->osd_req)
16071607
goto out_partial;
16081608

1609-
op = &obj_request->osd_req->r_ops[0];
1610-
osd_req_op_extent_init(op, opcode, offset, length, 0, 0);
1609+
osd_req_op_extent_init(obj_request->osd_req, 0,
1610+
opcode, offset, length, 0, 0);
16111611
rbd_osd_req_format_op(obj_request, write_request);
16121612

16131613
/* status and version are initially zero-filled */
@@ -1710,7 +1710,6 @@ static int rbd_obj_notify_ack(struct rbd_device *rbd_dev,
17101710
u64 ver, u64 notify_id)
17111711
{
17121712
struct rbd_obj_request *obj_request;
1713-
struct ceph_osd_req_op *op;
17141713
struct ceph_osd_client *osdc;
17151714
int ret;
17161715

@@ -1724,8 +1723,8 @@ static int rbd_obj_notify_ack(struct rbd_device *rbd_dev,
17241723
if (!obj_request->osd_req)
17251724
goto out;
17261725

1727-
op = &obj_request->osd_req->r_ops[0];
1728-
osd_req_op_watch_init(op, CEPH_OSD_OP_NOTIFY_ACK, notify_id, ver, 0);
1726+
osd_req_op_watch_init(obj_request->osd_req, 0, CEPH_OSD_OP_NOTIFY_ACK,
1727+
notify_id, ver, 0);
17291728
rbd_osd_req_format_op(obj_request, false);
17301729

17311730
osdc = &rbd_dev->rbd_client->client->osdc;
@@ -1766,7 +1765,6 @@ static int rbd_dev_header_watch_sync(struct rbd_device *rbd_dev, int start)
17661765
{
17671766
struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc;
17681767
struct rbd_obj_request *obj_request;
1769-
struct ceph_osd_req_op *op;
17701768
int ret;
17711769

17721770
rbd_assert(start ^ !!rbd_dev->watch_event);
@@ -1790,8 +1788,7 @@ static int rbd_dev_header_watch_sync(struct rbd_device *rbd_dev, int start)
17901788
if (!obj_request->osd_req)
17911789
goto out_cancel;
17921790

1793-
op = &obj_request->osd_req->r_ops[0];
1794-
osd_req_op_watch_init(op, CEPH_OSD_OP_WATCH,
1791+
osd_req_op_watch_init(obj_request->osd_req, 0, CEPH_OSD_OP_WATCH,
17951792
rbd_dev->watch_event->cookie,
17961793
rbd_dev->header.obj_version, start);
17971794
rbd_osd_req_format_op(obj_request, true);
@@ -1854,7 +1851,6 @@ static int rbd_obj_method_sync(struct rbd_device *rbd_dev,
18541851
{
18551852
struct rbd_obj_request *obj_request;
18561853
struct ceph_osd_client *osdc;
1857-
struct ceph_osd_req_op *op;
18581854
struct page **pages;
18591855
u32 page_count;
18601856
int ret;
@@ -1884,8 +1880,8 @@ static int rbd_obj_method_sync(struct rbd_device *rbd_dev,
18841880
if (!obj_request->osd_req)
18851881
goto out;
18861882

1887-
op = &obj_request->osd_req->r_ops[0];
1888-
osd_req_op_cls_init(op, CEPH_OSD_OP_CALL, class_name, method_name,
1883+
osd_req_op_cls_init(obj_request->osd_req, 0, CEPH_OSD_OP_CALL,
1884+
class_name, method_name,
18891885
outbound, outbound_size);
18901886
rbd_osd_req_format_op(obj_request, false);
18911887

@@ -2066,7 +2062,6 @@ static int rbd_obj_read_sync(struct rbd_device *rbd_dev,
20662062

20672063
{
20682064
struct rbd_obj_request *obj_request;
2069-
struct ceph_osd_req_op *op;
20702065
struct ceph_osd_client *osdc;
20712066
struct page **pages = NULL;
20722067
u32 page_count;
@@ -2091,8 +2086,8 @@ static int rbd_obj_read_sync(struct rbd_device *rbd_dev,
20912086
if (!obj_request->osd_req)
20922087
goto out;
20932088

2094-
op = &obj_request->osd_req->r_ops[0];
2095-
osd_req_op_extent_init(op, CEPH_OSD_OP_READ, offset, length, 0, 0);
2089+
osd_req_op_extent_init(obj_request->osd_req, 0, CEPH_OSD_OP_READ,
2090+
offset, length, 0, 0);
20962091
rbd_osd_req_format_op(obj_request, false);
20972092

20982093
osdc = &rbd_dev->rbd_client->client->osdc;

‎fs/ceph/addr.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ static int ceph_writepages_start(struct address_space *mapping,
926926

927927
/* Update the write op length in case we changed it */
928928

929-
osd_req_op_extent_update(&req->r_ops[0], len);
929+
osd_req_op_extent_update(req, 0, len);
930930

931931
vino = ceph_vino(inode);
932932
ceph_osdc_build_request(req, offset, snapc, vino.snap,

‎include/linux/ceph/osd_client.h‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,25 @@ extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
233233
extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
234234
struct ceph_msg *msg);
235235

236-
extern void osd_req_op_init(struct ceph_osd_req_op *op, u16 opcode);
237-
extern void osd_req_op_extent_init(struct ceph_osd_req_op *op, u16 opcode,
236+
extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
237+
unsigned int which, u16 opcode,
238238
u64 offset, u64 length,
239239
u64 truncate_size, u32 truncate_seq);
240-
extern void osd_req_op_extent_update(struct ceph_osd_req_op *op, u64 length);
241-
extern void osd_req_op_extent_osd_data(struct ceph_osd_req_op *op,
240+
extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
241+
unsigned int which, u64 length);
242+
extern void osd_req_op_extent_osd_data(struct ceph_osd_request *osd_req,
243+
unsigned int which,
242244
struct ceph_osd_data *osd_data);
243-
extern void osd_req_op_cls_init(struct ceph_osd_req_op *op, u16 opcode,
245+
extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req,
246+
unsigned int which, u16 opcode,
244247
const char *class, const char *method,
245248
const void *request_data,
246249
size_t request_data_size);
247-
extern void osd_req_op_cls_response_data(struct ceph_osd_req_op *op,
250+
extern void osd_req_op_cls_response_data(struct ceph_osd_request *osd_req,
251+
unsigned int which,
248252
struct ceph_osd_data *response_data);
249-
extern void osd_req_op_watch_init(struct ceph_osd_req_op *op, u16 opcode,
253+
extern void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
254+
unsigned int which, u16 opcode,
250255
u64 cookie, u64 version, int flag);
251256

252257
extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,

‎net/ceph/osd_client.c‎

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -329,25 +329,32 @@ static bool osd_req_opcode_valid(u16 opcode)
329329
* other information associated with them. It also serves as a
330330
* common init routine for all the other init functions, below.
331331
*/
332-
void osd_req_op_init(struct ceph_osd_req_op *op, u16 opcode)
332+
static struct ceph_osd_req_op *
333+
osd_req_op_init(struct ceph_osd_request *osd_req, unsigned int which,
334+
u16 opcode)
333335
{
336+
struct ceph_osd_req_op *op;
337+
338+
BUG_ON(which >= osd_req->r_num_ops);
334339
BUG_ON(!osd_req_opcode_valid(opcode));
335340

341+
op = &osd_req->r_ops[which];
336342
memset(op, 0, sizeof (*op));
337-
338343
op->op = opcode;
344+
345+
return op;
339346
}
340347

341-
void osd_req_op_extent_init(struct ceph_osd_req_op *op, u16 opcode,
348+
void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
349+
unsigned int which, u16 opcode,
342350
u64 offset, u64 length,
343351
u64 truncate_size, u32 truncate_seq)
344352
{
353+
struct ceph_osd_req_op *op = osd_req_op_init(osd_req, which, opcode);
345354
size_t payload_len = 0;
346355

347356
BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE);
348357

349-
osd_req_op_init(op, opcode);
350-
351358
op->extent.offset = offset;
352359
op->extent.length = length;
353360
op->extent.truncate_size = truncate_size;
@@ -359,9 +366,15 @@ void osd_req_op_extent_init(struct ceph_osd_req_op *op, u16 opcode,
359366
}
360367
EXPORT_SYMBOL(osd_req_op_extent_init);
361368

362-
void osd_req_op_extent_update(struct ceph_osd_req_op *op, u64 length)
369+
void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
370+
unsigned int which, u64 length)
363371
{
364-
u64 previous = op->extent.length;
372+
struct ceph_osd_req_op *op;
373+
u64 previous;
374+
375+
BUG_ON(which >= osd_req->r_num_ops);
376+
op = &osd_req->r_ops[which];
377+
previous = op->extent.length;
365378

366379
if (length == previous)
367380
return; /* Nothing to do */
@@ -372,24 +385,25 @@ void osd_req_op_extent_update(struct ceph_osd_req_op *op, u64 length)
372385
}
373386
EXPORT_SYMBOL(osd_req_op_extent_update);
374387

375-
void osd_req_op_extent_osd_data(struct ceph_osd_req_op *op,
388+
void osd_req_op_extent_osd_data(struct ceph_osd_request *osd_req,
389+
unsigned int which,
376390
struct ceph_osd_data *osd_data)
377391
{
378-
op->extent.osd_data = osd_data;
392+
BUG_ON(which >= osd_req->r_num_ops);
393+
osd_req->r_ops[which].extent.osd_data = osd_data;
379394
}
380395
EXPORT_SYMBOL(osd_req_op_extent_osd_data);
381396

382-
void osd_req_op_cls_init(struct ceph_osd_req_op *op, u16 opcode,
383-
const char *class, const char *method,
397+
void osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
398+
u16 opcode, const char *class, const char *method,
384399
const void *request_data, size_t request_data_size)
385400
{
401+
struct ceph_osd_req_op *op = osd_req_op_init(osd_req, which, opcode);
386402
size_t payload_len = 0;
387403
size_t size;
388404

389405
BUG_ON(opcode != CEPH_OSD_OP_CALL);
390406

391-
osd_req_op_init(op, opcode);
392-
393407
op->cls.class_name = class;
394408
size = strlen(class);
395409
BUG_ON(size > (size_t) U8_MAX);
@@ -412,26 +426,28 @@ void osd_req_op_cls_init(struct ceph_osd_req_op *op, u16 opcode,
412426
op->payload_len = payload_len;
413427
}
414428
EXPORT_SYMBOL(osd_req_op_cls_init);
415-
416-
void osd_req_op_cls_response_data(struct ceph_osd_req_op *op,
429+
void osd_req_op_cls_response_data(struct ceph_osd_request *osd_req,
430+
unsigned int which,
417431
struct ceph_osd_data *response_data)
418432
{
419-
op->cls.response_data = response_data;
433+
BUG_ON(which >= osd_req->r_num_ops);
434+
osd_req->r_ops[which].cls.response_data = response_data;
420435
}
421436
EXPORT_SYMBOL(osd_req_op_cls_response_data);
422437

423-
void osd_req_op_watch_init(struct ceph_osd_req_op *op, u16 opcode,
438+
void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
439+
unsigned int which, u16 opcode,
424440
u64 cookie, u64 version, int flag)
425441
{
426-
BUG_ON(opcode != CEPH_OSD_OP_NOTIFY_ACK && opcode != CEPH_OSD_OP_WATCH);
442+
struct ceph_osd_req_op *op = osd_req_op_init(osd_req, which, opcode);
427443

428-
osd_req_op_init(op, opcode);
444+
BUG_ON(opcode != CEPH_OSD_OP_NOTIFY_ACK && opcode != CEPH_OSD_OP_WATCH);
429445

430446
op->watch.cookie = cookie;
431447
/* op->watch.ver = version; */ /* XXX 3847 */
432448
op->watch.ver = cpu_to_le64(version);
433449
if (opcode == CEPH_OSD_OP_WATCH && flag)
434-
op->watch.flag = (u8) 1;
450+
op->watch.flag = (u8)1;
435451
}
436452
EXPORT_SYMBOL(osd_req_op_watch_init);
437453

@@ -629,7 +645,6 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
629645
{
630646
struct ceph_osd_request *req;
631647
struct ceph_osd_data *osd_data;
632-
struct ceph_osd_req_op *op;
633648
u64 objnum = 0;
634649
u64 objoff = 0;
635650
u64 objlen = 0;
@@ -665,18 +680,17 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
665680
truncate_size = object_size;
666681
}
667682

668-
op = &req->r_ops[0];
669-
osd_req_op_extent_init(op, opcode, objoff, objlen,
683+
osd_req_op_extent_init(req, 0, opcode, objoff, objlen,
670684
truncate_size, truncate_seq);
671-
osd_req_op_extent_osd_data(op, osd_data);
685+
osd_req_op_extent_osd_data(req, 0, osd_data);
672686

673687
/*
674688
* A second op in the ops array means the caller wants to
675689
* also issue a include a 'startsync' command so that the
676690
* osd will flush data quickly.
677691
*/
678692
if (num_ops > 1)
679-
osd_req_op_init(++op, CEPH_OSD_OP_STARTSYNC);
693+
osd_req_op_init(req, 1, CEPH_OSD_OP_STARTSYNC);
680694

681695
req->r_file_layout = *layout; /* keep a copy */
682696

0 commit comments

Comments
 (0)