aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-11-19 23:55:21 -0500
committerAlex Elder <elder@inktank.com>2013-01-17 17:34:59 -0500
commit5efea49a98d1a3b3a7301d3a17f826ad4c31b290 (patch)
tree3c85d7a5e3406b6eb95a7a4c7174acf45a45bf95 /drivers/block
parent2647ba38100765298fc67ce1ec5d32e80d9fe046 (diff)
rbd: move remaining osd op setup into rbd_osd_req_op_create()
The two remaining osd ops used by rbd are CEPH_OSD_OP_WATCH and CEPH_OSD_OP_NOTIFY_ACK. Move the setup of those operations into rbd_osd_req_op_create(), and get rid of rbd_create_rw_op() and rbd_destroy_op(). Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/rbd.c68
1 files changed, 27 insertions, 41 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 760be82548d9..3802a7857280 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1027,24 +1027,6 @@ out_err:
1027 return NULL; 1027 return NULL;
1028} 1028}
1029 1029
1030static struct ceph_osd_req_op *rbd_create_rw_op(int opcode, u64 ofs, u64 len)
1031{
1032 struct ceph_osd_req_op *op;
1033
1034 op = kzalloc(sizeof (*op), GFP_NOIO);
1035 if (!op)
1036 return NULL;
1037
1038 op->op = opcode;
1039
1040 return op;
1041}
1042
1043static void rbd_destroy_op(struct ceph_osd_req_op *op)
1044{
1045 kfree(op);
1046}
1047
1048struct ceph_osd_req_op *rbd_osd_req_op_create(u16 opcode, ...) 1030struct ceph_osd_req_op *rbd_osd_req_op_create(u16 opcode, ...)
1049{ 1031{
1050 struct ceph_osd_req_op *op; 1032 struct ceph_osd_req_op *op;
@@ -1087,6 +1069,16 @@ struct ceph_osd_req_op *rbd_osd_req_op_create(u16 opcode, ...)
1087 op->cls.indata_len = (u32) size; 1069 op->cls.indata_len = (u32) size;
1088 op->payload_len += size; 1070 op->payload_len += size;
1089 break; 1071 break;
1072 case CEPH_OSD_OP_NOTIFY_ACK:
1073 case CEPH_OSD_OP_WATCH:
1074 /* rbd_osd_req_op_create(NOTIFY_ACK, cookie, version) */
1075 /* rbd_osd_req_op_create(WATCH, cookie, version, flag) */
1076 op->watch.cookie = va_arg(args, u64);
1077 op->watch.ver = va_arg(args, u64);
1078 op->watch.ver = cpu_to_le64(op->watch.ver);
1079 if (opcode == CEPH_OSD_OP_WATCH && va_arg(args, int))
1080 op->watch.flag = (u8) 1;
1081 break;
1090 default: 1082 default:
1091 rbd_warn(NULL, "unsupported opcode %hu\n", opcode); 1083 rbd_warn(NULL, "unsupported opcode %hu\n", opcode);
1092 kfree(op); 1084 kfree(op);
@@ -1434,14 +1426,10 @@ static int rbd_req_sync_notify_ack(struct rbd_device *rbd_dev,
1434 struct ceph_osd_req_op *op; 1426 struct ceph_osd_req_op *op;
1435 int ret; 1427 int ret;
1436 1428
1437 op = rbd_create_rw_op(CEPH_OSD_OP_NOTIFY_ACK, 0, 0); 1429 op = rbd_osd_req_op_create(CEPH_OSD_OP_NOTIFY_ACK, notify_id, ver);
1438 if (!op) 1430 if (!op)
1439 return -ENOMEM; 1431 return -ENOMEM;
1440 1432
1441 op->watch.ver = cpu_to_le64(ver);
1442 op->watch.cookie = notify_id;
1443 op->watch.flag = 0;
1444
1445 ret = rbd_do_request(NULL, rbd_dev, NULL, CEPH_NOSNAP, 1433 ret = rbd_do_request(NULL, rbd_dev, NULL, CEPH_NOSNAP,
1446 rbd_dev->header_name, 0, 0, NULL, 1434 rbd_dev->header_name, 0, 0, NULL,
1447 NULL, 0, 1435 NULL, 0,
@@ -1450,7 +1438,8 @@ static int rbd_req_sync_notify_ack(struct rbd_device *rbd_dev,
1450 NULL, 0, 1438 NULL, 0,
1451 rbd_simple_req_cb, 0, NULL); 1439 rbd_simple_req_cb, 0, NULL);
1452 1440
1453 rbd_destroy_op(op); 1441 rbd_osd_req_op_destroy(op);
1442
1454 return ret; 1443 return ret;
1455} 1444}
1456 1445
@@ -1480,14 +1469,9 @@ static void rbd_watch_cb(u64 ver, u64 notify_id, u8 opcode, void *data)
1480 */ 1469 */
1481static int rbd_req_sync_watch(struct rbd_device *rbd_dev, int start) 1470static int rbd_req_sync_watch(struct rbd_device *rbd_dev, int start)
1482{ 1471{
1483 struct ceph_osd_req_op *op;
1484 struct ceph_osd_request **linger_req = NULL; 1472 struct ceph_osd_request **linger_req = NULL;
1485 __le64 version = 0; 1473 struct ceph_osd_req_op *op;
1486 int ret; 1474 int ret = 0;
1487
1488 op = rbd_create_rw_op(CEPH_OSD_OP_WATCH, 0, 0);
1489 if (!op)
1490 return -ENOMEM;
1491 1475
1492 if (start) { 1476 if (start) {
1493 struct ceph_osd_client *osdc; 1477 struct ceph_osd_client *osdc;
@@ -1496,26 +1480,28 @@ static int rbd_req_sync_watch(struct rbd_device *rbd_dev, int start)
1496 ret = ceph_osdc_create_event(osdc, rbd_watch_cb, 0, rbd_dev, 1480 ret = ceph_osdc_create_event(osdc, rbd_watch_cb, 0, rbd_dev,
1497 &rbd_dev->watch_event); 1481 &rbd_dev->watch_event);
1498 if (ret < 0) 1482 if (ret < 0)
1499 goto done; 1483 return ret;
1500 version = cpu_to_le64(rbd_dev->header.obj_version);
1501 linger_req = &rbd_dev->watch_request; 1484 linger_req = &rbd_dev->watch_request;
1485 } else {
1486 rbd_assert(rbd_dev->watch_request != NULL);
1502 } 1487 }
1503 1488
1504 op->watch.ver = version; 1489 op = rbd_osd_req_op_create(CEPH_OSD_OP_WATCH,
1505 op->watch.cookie = cpu_to_le64(rbd_dev->watch_event->cookie); 1490 rbd_dev->watch_event->cookie,
1506 op->watch.flag = (u8) start ? 1 : 0; 1491 rbd_dev->header.obj_version, start);
1507 1492 if (op)
1508 ret = rbd_req_sync_op(rbd_dev, 1493 ret = rbd_req_sync_op(rbd_dev,
1509 CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK, 1494 CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK,
1510 op, rbd_dev->header_name, 1495 op, rbd_dev->header_name,
1511 0, 0, NULL, linger_req, NULL); 1496 0, 0, NULL, linger_req, NULL);
1512 1497
1513 if (!start || ret < 0) { 1498 /* Cancel the event if we're tearing down, or on error */
1499
1500 if (!start || !op || ret < 0) {
1514 ceph_osdc_cancel_event(rbd_dev->watch_event); 1501 ceph_osdc_cancel_event(rbd_dev->watch_event);
1515 rbd_dev->watch_event = NULL; 1502 rbd_dev->watch_event = NULL;
1516 } 1503 }
1517done: 1504 rbd_osd_req_op_destroy(op);
1518 rbd_destroy_op(op);
1519 1505
1520 return ret; 1506 return ret;
1521} 1507}