aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2013-04-05 02:27:11 -0400
committerSage Weil <sage@inktank.com>2013-05-02 00:18:15 -0400
commitc99d2d4abb6c405ef52e9bc1da87b382b8f41739 (patch)
tree073ad414ec82f706a38300d38fe5c5a710d3098a
parent8c042b0df99cd06ef8473ef6e204b87b3dc80158 (diff)
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>
-rw-r--r--drivers/block/rbd.c35
-rw-r--r--fs/ceph/addr.c2
-rw-r--r--include/linux/ceph/osd_client.h19
-rw-r--r--net/ceph/osd_client.c64
4 files changed, 67 insertions, 53 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index eb64ed0f228f..80ac772587c8 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1336,16 +1336,17 @@ static void rbd_osd_req_format_op(struct rbd_obj_request *obj_request,
1336 snap_id = img_request->snap_id; 1336 snap_id = img_request->snap_id;
1337 } 1337 }
1338 if (obj_request->type != OBJ_REQUEST_NODATA) { 1338 if (obj_request->type != OBJ_REQUEST_NODATA) {
1339 struct ceph_osd_req_op *op = &obj_request->osd_req->r_ops[0];
1340
1341 /* 1339 /*
1342 * If it has data, it's either a object class method 1340 * If it has data, it's either a object class method
1343 * call (cls) or it's an extent operation. 1341 * call (cls) or it's an extent operation.
1344 */ 1342 */
1345 if (op->op == CEPH_OSD_OP_CALL) 1343 /* XXX This use of the ops array goes away in the next patch */
1346 osd_req_op_cls_response_data(op, osd_data); 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);
1347 else 1347 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);
1349 } 1350 }
1350 ceph_osdc_build_request(osd_req, obj_request->offset, 1351 ceph_osdc_build_request(osd_req, obj_request->offset,
1351 snapc, snap_id, mtime); 1352 snapc, snap_id, mtime);
@@ -1577,7 +1578,6 @@ static int rbd_img_request_fill_bio(struct rbd_img_request *img_request,
1577 while (resid) { 1578 while (resid) {
1578 const char *object_name; 1579 const char *object_name;
1579 unsigned int clone_size; 1580 unsigned int clone_size;
1580 struct ceph_osd_req_op *op;
1581 u64 offset; 1581 u64 offset;
1582 u64 length; 1582 u64 length;
1583 1583
@@ -1606,8 +1606,8 @@ static int rbd_img_request_fill_bio(struct rbd_img_request *img_request,
1606 if (!obj_request->osd_req) 1606 if (!obj_request->osd_req)
1607 goto out_partial; 1607 goto out_partial;
1608 1608
1609 op = &obj_request->osd_req->r_ops[0]; 1609 osd_req_op_extent_init(obj_request->osd_req, 0,
1610 osd_req_op_extent_init(op, opcode, offset, length, 0, 0); 1610 opcode, offset, length, 0, 0);
1611 rbd_osd_req_format_op(obj_request, write_request); 1611 rbd_osd_req_format_op(obj_request, write_request);
1612 1612
1613 /* status and version are initially zero-filled */ 1613 /* status and version are initially zero-filled */
@@ -1710,7 +1710,6 @@ static int rbd_obj_notify_ack(struct rbd_device *rbd_dev,
1710 u64 ver, u64 notify_id) 1710 u64 ver, u64 notify_id)
1711{ 1711{
1712 struct rbd_obj_request *obj_request; 1712 struct rbd_obj_request *obj_request;
1713 struct ceph_osd_req_op *op;
1714 struct ceph_osd_client *osdc; 1713 struct ceph_osd_client *osdc;
1715 int ret; 1714 int ret;
1716 1715
@@ -1724,8 +1723,8 @@ static int rbd_obj_notify_ack(struct rbd_device *rbd_dev,
1724 if (!obj_request->osd_req) 1723 if (!obj_request->osd_req)
1725 goto out; 1724 goto out;
1726 1725
1727 op = &obj_request->osd_req->r_ops[0]; 1726 osd_req_op_watch_init(obj_request->osd_req, 0, CEPH_OSD_OP_NOTIFY_ACK,
1728 osd_req_op_watch_init(op, CEPH_OSD_OP_NOTIFY_ACK, notify_id, ver, 0); 1727 notify_id, ver, 0);
1729 rbd_osd_req_format_op(obj_request, false); 1728 rbd_osd_req_format_op(obj_request, false);
1730 1729
1731 osdc = &rbd_dev->rbd_client->client->osdc; 1730 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)
1766{ 1765{
1767 struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc; 1766 struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc;
1768 struct rbd_obj_request *obj_request; 1767 struct rbd_obj_request *obj_request;
1769 struct ceph_osd_req_op *op;
1770 int ret; 1768 int ret;
1771 1769
1772 rbd_assert(start ^ !!rbd_dev->watch_event); 1770 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)
1790 if (!obj_request->osd_req) 1788 if (!obj_request->osd_req)
1791 goto out_cancel; 1789 goto out_cancel;
1792 1790
1793 op = &obj_request->osd_req->r_ops[0]; 1791 osd_req_op_watch_init(obj_request->osd_req, 0, CEPH_OSD_OP_WATCH,
1794 osd_req_op_watch_init(op, CEPH_OSD_OP_WATCH,
1795 rbd_dev->watch_event->cookie, 1792 rbd_dev->watch_event->cookie,
1796 rbd_dev->header.obj_version, start); 1793 rbd_dev->header.obj_version, start);
1797 rbd_osd_req_format_op(obj_request, true); 1794 rbd_osd_req_format_op(obj_request, true);
@@ -1854,7 +1851,6 @@ static int rbd_obj_method_sync(struct rbd_device *rbd_dev,
1854{ 1851{
1855 struct rbd_obj_request *obj_request; 1852 struct rbd_obj_request *obj_request;
1856 struct ceph_osd_client *osdc; 1853 struct ceph_osd_client *osdc;
1857 struct ceph_osd_req_op *op;
1858 struct page **pages; 1854 struct page **pages;
1859 u32 page_count; 1855 u32 page_count;
1860 int ret; 1856 int ret;
@@ -1884,8 +1880,8 @@ static int rbd_obj_method_sync(struct rbd_device *rbd_dev,
1884 if (!obj_request->osd_req) 1880 if (!obj_request->osd_req)
1885 goto out; 1881 goto out;
1886 1882
1887 op = &obj_request->osd_req->r_ops[0]; 1883 osd_req_op_cls_init(obj_request->osd_req, 0, CEPH_OSD_OP_CALL,
1888 osd_req_op_cls_init(op, CEPH_OSD_OP_CALL, class_name, method_name, 1884 class_name, method_name,
1889 outbound, outbound_size); 1885 outbound, outbound_size);
1890 rbd_osd_req_format_op(obj_request, false); 1886 rbd_osd_req_format_op(obj_request, false);
1891 1887
@@ -2066,7 +2062,6 @@ static int rbd_obj_read_sync(struct rbd_device *rbd_dev,
2066 2062
2067{ 2063{
2068 struct rbd_obj_request *obj_request; 2064 struct rbd_obj_request *obj_request;
2069 struct ceph_osd_req_op *op;
2070 struct ceph_osd_client *osdc; 2065 struct ceph_osd_client *osdc;
2071 struct page **pages = NULL; 2066 struct page **pages = NULL;
2072 u32 page_count; 2067 u32 page_count;
@@ -2091,8 +2086,8 @@ static int rbd_obj_read_sync(struct rbd_device *rbd_dev,
2091 if (!obj_request->osd_req) 2086 if (!obj_request->osd_req)
2092 goto out; 2087 goto out;
2093 2088
2094 op = &obj_request->osd_req->r_ops[0]; 2089 osd_req_op_extent_init(obj_request->osd_req, 0, CEPH_OSD_OP_READ,
2095 osd_req_op_extent_init(op, CEPH_OSD_OP_READ, offset, length, 0, 0); 2090 offset, length, 0, 0);
2096 rbd_osd_req_format_op(obj_request, false); 2091 rbd_osd_req_format_op(obj_request, false);
2097 2092
2098 osdc = &rbd_dev->rbd_client->client->osdc; 2093 osdc = &rbd_dev->rbd_client->client->osdc;
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 0ac3a37753cb..cc57104a7266 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -926,7 +926,7 @@ get_more_pages:
926 926
927 /* Update the write op length in case we changed it */ 927 /* Update the write op length in case we changed it */
928 928
929 osd_req_op_extent_update(&req->r_ops[0], len); 929 osd_req_op_extent_update(req, 0, len);
930 930
931 vino = ceph_vino(inode); 931 vino = ceph_vino(inode);
932 ceph_osdc_build_request(req, offset, snapc, vino.snap, 932 ceph_osdc_build_request(req, offset, snapc, vino.snap,
diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
index ae5193550fbf..144d57cbef9e 100644
--- a/include/linux/ceph/osd_client.h
+++ b/include/linux/ceph/osd_client.h
@@ -233,20 +233,25 @@ extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
233extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc, 233extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
234 struct ceph_msg *msg); 234 struct ceph_msg *msg);
235 235
236extern void osd_req_op_init(struct ceph_osd_req_op *op, u16 opcode); 236extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
237extern void osd_req_op_extent_init(struct ceph_osd_req_op *op, u16 opcode, 237 unsigned int which, u16 opcode,
238 u64 offset, u64 length, 238 u64 offset, u64 length,
239 u64 truncate_size, u32 truncate_seq); 239 u64 truncate_size, u32 truncate_seq);
240extern void osd_req_op_extent_update(struct ceph_osd_req_op *op, u64 length); 240extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
241extern void osd_req_op_extent_osd_data(struct ceph_osd_req_op *op, 241 unsigned int which, u64 length);
242extern void osd_req_op_extent_osd_data(struct ceph_osd_request *osd_req,
243 unsigned int which,
242 struct ceph_osd_data *osd_data); 244 struct ceph_osd_data *osd_data);
243extern void osd_req_op_cls_init(struct ceph_osd_req_op *op, u16 opcode, 245extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req,
246 unsigned int which, u16 opcode,
244 const char *class, const char *method, 247 const char *class, const char *method,
245 const void *request_data, 248 const void *request_data,
246 size_t request_data_size); 249 size_t request_data_size);
247extern void osd_req_op_cls_response_data(struct ceph_osd_req_op *op, 250extern void osd_req_op_cls_response_data(struct ceph_osd_request *osd_req,
251 unsigned int which,
248 struct ceph_osd_data *response_data); 252 struct ceph_osd_data *response_data);
249extern void osd_req_op_watch_init(struct ceph_osd_req_op *op, u16 opcode, 253extern void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
254 unsigned int which, u16 opcode,
250 u64 cookie, u64 version, int flag); 255 u64 cookie, u64 version, int flag);
251 256
252extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, 257extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 23491e92b229..ad24f210bf0c 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -329,25 +329,32 @@ static bool osd_req_opcode_valid(u16 opcode)
329 * other information associated with them. It also serves as a 329 * other information associated with them. It also serves as a
330 * common init routine for all the other init functions, below. 330 * common init routine for all the other init functions, below.
331 */ 331 */
332void osd_req_op_init(struct ceph_osd_req_op *op, u16 opcode) 332static struct ceph_osd_req_op *
333osd_req_op_init(struct ceph_osd_request *osd_req, unsigned int which,
334 u16 opcode)
333{ 335{
336 struct ceph_osd_req_op *op;
337
338 BUG_ON(which >= osd_req->r_num_ops);
334 BUG_ON(!osd_req_opcode_valid(opcode)); 339 BUG_ON(!osd_req_opcode_valid(opcode));
335 340
341 op = &osd_req->r_ops[which];
336 memset(op, 0, sizeof (*op)); 342 memset(op, 0, sizeof (*op));
337
338 op->op = opcode; 343 op->op = opcode;
344
345 return op;
339} 346}
340 347
341void osd_req_op_extent_init(struct ceph_osd_req_op *op, u16 opcode, 348void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
349 unsigned int which, u16 opcode,
342 u64 offset, u64 length, 350 u64 offset, u64 length,
343 u64 truncate_size, u32 truncate_seq) 351 u64 truncate_size, u32 truncate_seq)
344{ 352{
353 struct ceph_osd_req_op *op = osd_req_op_init(osd_req, which, opcode);
345 size_t payload_len = 0; 354 size_t payload_len = 0;
346 355
347 BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE); 356 BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE);
348 357
349 osd_req_op_init(op, opcode);
350
351 op->extent.offset = offset; 358 op->extent.offset = offset;
352 op->extent.length = length; 359 op->extent.length = length;
353 op->extent.truncate_size = truncate_size; 360 op->extent.truncate_size = truncate_size;
@@ -359,9 +366,15 @@ void osd_req_op_extent_init(struct ceph_osd_req_op *op, u16 opcode,
359} 366}
360EXPORT_SYMBOL(osd_req_op_extent_init); 367EXPORT_SYMBOL(osd_req_op_extent_init);
361 368
362void osd_req_op_extent_update(struct ceph_osd_req_op *op, u64 length) 369void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
370 unsigned int which, u64 length)
363{ 371{
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;
365 378
366 if (length == previous) 379 if (length == previous)
367 return; /* Nothing to do */ 380 return; /* Nothing to do */
@@ -372,24 +385,25 @@ void osd_req_op_extent_update(struct ceph_osd_req_op *op, u64 length)
372} 385}
373EXPORT_SYMBOL(osd_req_op_extent_update); 386EXPORT_SYMBOL(osd_req_op_extent_update);
374 387
375void osd_req_op_extent_osd_data(struct ceph_osd_req_op *op, 388void osd_req_op_extent_osd_data(struct ceph_osd_request *osd_req,
389 unsigned int which,
376 struct ceph_osd_data *osd_data) 390 struct ceph_osd_data *osd_data)
377{ 391{
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;
379} 394}
380EXPORT_SYMBOL(osd_req_op_extent_osd_data); 395EXPORT_SYMBOL(osd_req_op_extent_osd_data);
381 396
382void osd_req_op_cls_init(struct ceph_osd_req_op *op, u16 opcode, 397void osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
383 const char *class, const char *method, 398 u16 opcode, const char *class, const char *method,
384 const void *request_data, size_t request_data_size) 399 const void *request_data, size_t request_data_size)
385{ 400{
401 struct ceph_osd_req_op *op = osd_req_op_init(osd_req, which, opcode);
386 size_t payload_len = 0; 402 size_t payload_len = 0;
387 size_t size; 403 size_t size;
388 404
389 BUG_ON(opcode != CEPH_OSD_OP_CALL); 405 BUG_ON(opcode != CEPH_OSD_OP_CALL);
390 406
391 osd_req_op_init(op, opcode);
392
393 op->cls.class_name = class; 407 op->cls.class_name = class;
394 size = strlen(class); 408 size = strlen(class);
395 BUG_ON(size > (size_t) U8_MAX); 409 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,
412 op->payload_len = payload_len; 426 op->payload_len = payload_len;
413} 427}
414EXPORT_SYMBOL(osd_req_op_cls_init); 428EXPORT_SYMBOL(osd_req_op_cls_init);
415 429void osd_req_op_cls_response_data(struct ceph_osd_request *osd_req,
416void osd_req_op_cls_response_data(struct ceph_osd_req_op *op, 430 unsigned int which,
417 struct ceph_osd_data *response_data) 431 struct ceph_osd_data *response_data)
418{ 432{
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;
420} 435}
421EXPORT_SYMBOL(osd_req_op_cls_response_data); 436EXPORT_SYMBOL(osd_req_op_cls_response_data);
422 437
423void osd_req_op_watch_init(struct ceph_osd_req_op *op, u16 opcode, 438void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
439 unsigned int which, u16 opcode,
424 u64 cookie, u64 version, int flag) 440 u64 cookie, u64 version, int flag)
425{ 441{
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);
427 443
428 osd_req_op_init(op, opcode); 444 BUG_ON(opcode != CEPH_OSD_OP_NOTIFY_ACK && opcode != CEPH_OSD_OP_WATCH);
429 445
430 op->watch.cookie = cookie; 446 op->watch.cookie = cookie;
431 /* op->watch.ver = version; */ /* XXX 3847 */ 447 /* op->watch.ver = version; */ /* XXX 3847 */
432 op->watch.ver = cpu_to_le64(version); 448 op->watch.ver = cpu_to_le64(version);
433 if (opcode == CEPH_OSD_OP_WATCH && flag) 449 if (opcode == CEPH_OSD_OP_WATCH && flag)
434 op->watch.flag = (u8) 1; 450 op->watch.flag = (u8)1;
435} 451}
436EXPORT_SYMBOL(osd_req_op_watch_init); 452EXPORT_SYMBOL(osd_req_op_watch_init);
437 453
@@ -629,7 +645,6 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
629{ 645{
630 struct ceph_osd_request *req; 646 struct ceph_osd_request *req;
631 struct ceph_osd_data *osd_data; 647 struct ceph_osd_data *osd_data;
632 struct ceph_osd_req_op *op;
633 u64 objnum = 0; 648 u64 objnum = 0;
634 u64 objoff = 0; 649 u64 objoff = 0;
635 u64 objlen = 0; 650 u64 objlen = 0;
@@ -665,10 +680,9 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
665 truncate_size = object_size; 680 truncate_size = object_size;
666 } 681 }
667 682
668 op = &req->r_ops[0]; 683 osd_req_op_extent_init(req, 0, opcode, objoff, objlen,
669 osd_req_op_extent_init(op, opcode, objoff, objlen,
670 truncate_size, truncate_seq); 684 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);
672 686
673 /* 687 /*
674 * A second op in the ops array means the caller wants to 688 * A second op in the ops array means the caller wants to
@@ -676,7 +690,7 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
676 * osd will flush data quickly. 690 * osd will flush data quickly.
677 */ 691 */
678 if (num_ops > 1) 692 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);
680 694
681 req->r_file_layout = *layout; /* keep a copy */ 695 req->r_file_layout = *layout; /* keep a copy */
682 696