Skip to content

Commit 8c042b0

Browse files
Alex ElderSage Weil
authored andcommitted
libceph: add data pointers in osd op structures
An extent type osd operation currently implies that there will be corresponding data supplied in the data portion of the request (for write) or response (for read) message. Similarly, an osd class method operation implies a data item will be supplied to receive the response data from the operation. Add a ceph_osd_data pointer to each of those structures, and assign it to point to eithre the incoming or the outgoing data structure in the osd message. The data is not always available when an op is initially set up, so add two new functions to allow setting them after the op has been initialized. Begin to make use of the data item pointer available in the osd operation rather than the request data in or out structure in places where it's convenient. Add some assertions to verify pointers are always set the way they're expected to be. This is a sort of stepping stone toward really moving the data into the osd request ops, to allow for some validation before making that jump. This is the first in a series of patches that resolve: http://tracker.ceph.com/issues/4657 Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
1 parent 54d5064 commit 8c042b0

5 files changed

Lines changed: 59 additions & 10 deletions

File tree

‎drivers/block/rbd.c‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,23 +1315,39 @@ static void rbd_osd_req_format_op(struct rbd_obj_request *obj_request,
13151315
bool write_request)
13161316
{
13171317
struct rbd_img_request *img_request = obj_request->img_request;
1318+
struct ceph_osd_request *osd_req = obj_request->osd_req;
1319+
struct ceph_osd_data *osd_data = NULL;
13181320
struct ceph_snap_context *snapc = NULL;
13191321
u64 snap_id = CEPH_NOSNAP;
13201322
struct timespec *mtime = NULL;
13211323
struct timespec now;
13221324

1323-
rbd_assert(obj_request->osd_req != NULL);
1325+
rbd_assert(osd_req != NULL);
13241326

13251327
if (write_request) {
1328+
osd_data = &osd_req->r_data_out;
13261329
now = CURRENT_TIME;
13271330
mtime = &now;
13281331
if (img_request)
13291332
snapc = img_request->snapc;
1330-
} else if (img_request) {
1331-
snap_id = img_request->snap_id;
1333+
} else {
1334+
osd_data = &osd_req->r_data_in;
1335+
if (img_request)
1336+
snap_id = img_request->snap_id;
13321337
}
1338+
if (obj_request->type != OBJ_REQUEST_NODATA) {
1339+
struct ceph_osd_req_op *op = &obj_request->osd_req->r_ops[0];
13331340

1334-
ceph_osdc_build_request(obj_request->osd_req, obj_request->offset,
1341+
/*
1342+
* If it has data, it's either a object class method
1343+
* call (cls) or it's an extent operation.
1344+
*/
1345+
if (op->op == CEPH_OSD_OP_CALL)
1346+
osd_req_op_cls_response_data(op, osd_data);
1347+
else
1348+
osd_req_op_extent_osd_data(op, osd_data);
1349+
}
1350+
ceph_osdc_build_request(osd_req, obj_request->offset,
13351351
snapc, snap_id, mtime);
13361352
}
13371353

‎fs/ceph/addr.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ static int start_read(struct inode *inode, struct list_head *page_list, int max)
343343
}
344344
pages[i] = page;
345345
}
346-
ceph_osd_data_pages_init(&req->r_data_in, pages, len, 0,
346+
BUG_ON(req->r_ops[0].extent.osd_data != &req->r_data_in);
347+
ceph_osd_data_pages_init(req->r_ops[0].extent.osd_data, pages, len, 0,
347348
false, false);
348349
req->r_callback = finish_read;
349350
req->r_inode = inode;
@@ -916,8 +917,9 @@ static int ceph_writepages_start(struct address_space *mapping,
916917
dout("writepages got %d pages at %llu~%llu\n",
917918
locked_pages, offset, len);
918919

919-
ceph_osd_data_pages_init(&req->r_data_out, pages, len, 0,
920-
!!pool, false);
920+
BUG_ON(req->r_ops[0].extent.osd_data != &req->r_data_out);
921+
ceph_osd_data_pages_init(req->r_ops[0].extent.osd_data, pages,
922+
len, 0, !!pool, false);
921923

922924
pages = NULL; /* request message now owns the pages array */
923925
pool = NULL;

‎fs/ceph/file.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,9 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
574574
own_pages = true;
575575
}
576576
}
577-
ceph_osd_data_pages_init(&req->r_data_out, pages, len, page_align,
578-
false, own_pages);
577+
BUG_ON(req->r_ops[0].extent.osd_data != &req->r_data_out);
578+
ceph_osd_data_pages_init(req->r_ops[0].extent.osd_data, pages, len,
579+
page_align, false, own_pages);
579580

580581
/* BUG_ON(vino.snap != CEPH_NOSNAP); */
581582
ceph_osdc_build_request(req, pos, snapc, vino.snap, &mtime);

‎include/linux/ceph/osd_client.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ struct ceph_osd_req_op {
8787
u64 offset, length;
8888
u64 truncate_size;
8989
u32 truncate_seq;
90+
struct ceph_osd_data *osd_data;
9091
} extent;
9192
struct {
9293
const char *class_name;
9394
const char *method_name;
9495
const void *request_data;
9596
u32 request_data_len;
97+
struct ceph_osd_data *response_data;
9698
__u8 class_len;
9799
__u8 method_len;
98100
__u8 argc;
@@ -236,10 +238,14 @@ extern void osd_req_op_extent_init(struct ceph_osd_req_op *op, u16 opcode,
236238
u64 offset, u64 length,
237239
u64 truncate_size, u32 truncate_seq);
238240
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,
242+
struct ceph_osd_data *osd_data);
239243
extern void osd_req_op_cls_init(struct ceph_osd_req_op *op, u16 opcode,
240244
const char *class, const char *method,
241245
const void *request_data,
242246
size_t request_data_size);
247+
extern void osd_req_op_cls_response_data(struct ceph_osd_req_op *op,
248+
struct ceph_osd_data *response_data);
243249
extern void osd_req_op_watch_init(struct ceph_osd_req_op *op, u16 opcode,
244250
u64 cookie, u64 version, int flag);
245251

‎net/ceph/osd_client.c‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,13 @@ void osd_req_op_extent_update(struct ceph_osd_req_op *op, u64 length)
372372
}
373373
EXPORT_SYMBOL(osd_req_op_extent_update);
374374

375+
void osd_req_op_extent_osd_data(struct ceph_osd_req_op *op,
376+
struct ceph_osd_data *osd_data)
377+
{
378+
op->extent.osd_data = osd_data;
379+
}
380+
EXPORT_SYMBOL(osd_req_op_extent_osd_data);
381+
375382
void osd_req_op_cls_init(struct ceph_osd_req_op *op, u16 opcode,
376383
const char *class, const char *method,
377384
const void *request_data, size_t request_data_size)
@@ -406,6 +413,13 @@ void osd_req_op_cls_init(struct ceph_osd_req_op *op, u16 opcode,
406413
}
407414
EXPORT_SYMBOL(osd_req_op_cls_init);
408415

416+
void osd_req_op_cls_response_data(struct ceph_osd_req_op *op,
417+
struct ceph_osd_data *response_data)
418+
{
419+
op->cls.response_data = response_data;
420+
}
421+
EXPORT_SYMBOL(osd_req_op_cls_response_data);
422+
409423
void osd_req_op_watch_init(struct ceph_osd_req_op *op, u16 opcode,
410424
u64 cookie, u64 version, int flag)
411425
{
@@ -449,6 +463,10 @@ static u64 osd_req_encode_op(struct ceph_osd_request *req,
449463
cpu_to_le64(src->extent.truncate_size);
450464
dst->extent.truncate_seq =
451465
cpu_to_le32(src->extent.truncate_seq);
466+
if (src->op == CEPH_OSD_OP_WRITE)
467+
WARN_ON(src->extent.osd_data != &req->r_data_out);
468+
else
469+
WARN_ON(src->extent.osd_data != &req->r_data_in);
452470
break;
453471
case CEPH_OSD_OP_CALL:
454472
pagelist = kmalloc(sizeof (*pagelist), GFP_NOFS);
@@ -464,8 +482,9 @@ static u64 osd_req_encode_op(struct ceph_osd_request *req,
464482
src->cls.method_len);
465483
ceph_pagelist_append(pagelist, src->cls.request_data,
466484
src->cls.request_data_len);
467-
468485
ceph_osd_data_pagelist_init(&req->r_data_out, pagelist);
486+
487+
WARN_ON(src->cls.response_data != &req->r_data_in);
469488
request_data_len = pagelist->length;
470489
break;
471490
case CEPH_OSD_OP_STARTSYNC:
@@ -609,6 +628,7 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
609628
bool use_mempool)
610629
{
611630
struct ceph_osd_request *req;
631+
struct ceph_osd_data *osd_data;
612632
struct ceph_osd_req_op *op;
613633
u64 objnum = 0;
614634
u64 objoff = 0;
@@ -623,6 +643,8 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
623643
GFP_NOFS);
624644
if (!req)
625645
return ERR_PTR(-ENOMEM);
646+
osd_data = opcode == CEPH_OSD_OP_WRITE ? &req->r_data_out
647+
: &req->r_data_in;
626648

627649
req->r_flags = flags;
628650

@@ -646,6 +668,8 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
646668
op = &req->r_ops[0];
647669
osd_req_op_extent_init(op, opcode, objoff, objlen,
648670
truncate_size, truncate_seq);
671+
osd_req_op_extent_osd_data(op, osd_data);
672+
649673
/*
650674
* A second op in the ops array means the caller wants to
651675
* also issue a include a 'startsync' command so that the

0 commit comments

Comments
 (0)