aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-11-13 22:11:15 -0500
committerAlex Elder <elder@inktank.com>2013-01-17 17:34:58 -0500
commit907703d050df92979b3848ee42f88d5c9c6c13fe (patch)
treef8afc0441dcbb856b3c9d2df6f0c11e456aecaba /drivers/block
parent0903e875caa93e1fb231dd66c69b118dbdad25cb (diff)
rbd: combine rbd sync watch/unwatch functions
The rbd_req_sync_watch() and rbd_req_sync_unwatch() functions are nearly identical. Combine them into a single function with a flag indicating whether a watch is to be initiated or torn down. 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.c81
1 files changed, 27 insertions, 54 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index d2a6e9589fab..9d21fcd7e188 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1429,74 +1429,48 @@ static void rbd_watch_cb(u64 ver, u64 notify_id, u8 opcode, void *data)
1429} 1429}
1430 1430
1431/* 1431/*
1432 * Request sync osd watch 1432 * Request sync osd watch/unwatch. The value of "start" determines
1433 * whether a watch request is being initiated or torn down.
1433 */ 1434 */
1434static int rbd_req_sync_watch(struct rbd_device *rbd_dev) 1435static int rbd_req_sync_watch(struct rbd_device *rbd_dev, int start)
1435{ 1436{
1436 struct ceph_osd_req_op *op; 1437 struct ceph_osd_req_op *op;
1437 struct ceph_osd_client *osdc = &rbd_dev->rbd_client->client->osdc; 1438 struct ceph_osd_request **linger_req = NULL;
1439 __le64 version = 0;
1438 int ret; 1440 int ret;
1439 1441
1440 op = rbd_create_rw_op(CEPH_OSD_OP_WATCH, 0); 1442 op = rbd_create_rw_op(CEPH_OSD_OP_WATCH, 0);
1441 if (!op) 1443 if (!op)
1442 return -ENOMEM; 1444 return -ENOMEM;
1443 1445
1444 ret = ceph_osdc_create_event(osdc, rbd_watch_cb, 0, 1446 if (start) {
1445 (void *)rbd_dev, &rbd_dev->watch_event); 1447 struct ceph_osd_client *osdc;
1446 if (ret < 0)
1447 goto fail;
1448
1449 op->watch.ver = cpu_to_le64(rbd_dev->header.obj_version);
1450 op->watch.cookie = cpu_to_le64(rbd_dev->watch_event->cookie);
1451 op->watch.flag = 1;
1452
1453 ret = rbd_req_sync_op(rbd_dev,
1454 CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK,
1455 op,
1456 rbd_dev->header_name,
1457 0, 0, NULL,
1458 &rbd_dev->watch_request, NULL);
1459
1460 if (ret < 0)
1461 goto fail_event;
1462
1463 rbd_destroy_op(op);
1464 return 0;
1465
1466fail_event:
1467 ceph_osdc_cancel_event(rbd_dev->watch_event);
1468 rbd_dev->watch_event = NULL;
1469fail:
1470 rbd_destroy_op(op);
1471 return ret;
1472}
1473
1474/*
1475 * Request sync osd unwatch
1476 */
1477static int rbd_req_sync_unwatch(struct rbd_device *rbd_dev)
1478{
1479 struct ceph_osd_req_op *op;
1480 int ret;
1481 1448
1482 op = rbd_create_rw_op(CEPH_OSD_OP_WATCH, 0); 1449 osdc = &rbd_dev->rbd_client->client->osdc;
1483 if (!op) 1450 ret = ceph_osdc_create_event(osdc, rbd_watch_cb, 0, rbd_dev,
1484 return -ENOMEM; 1451 &rbd_dev->watch_event);
1452 if (ret < 0)
1453 goto done;
1454 version = cpu_to_le64(rbd_dev->header.obj_version);
1455 linger_req = &rbd_dev->watch_request;
1456 }
1485 1457
1486 op->watch.ver = 0; 1458 op->watch.ver = version;
1487 op->watch.cookie = cpu_to_le64(rbd_dev->watch_event->cookie); 1459 op->watch.cookie = cpu_to_le64(rbd_dev->watch_event->cookie);
1488 op->watch.flag = 0; 1460 op->watch.flag = (u8) start ? 1 : 0;
1489 1461
1490 ret = rbd_req_sync_op(rbd_dev, 1462 ret = rbd_req_sync_op(rbd_dev,
1491 CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK, 1463 CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK,
1492 op, 1464 op, rbd_dev->header_name,
1493 rbd_dev->header_name, 1465 0, 0, NULL, linger_req, NULL);
1494 0, 0, NULL, NULL, NULL);
1495
1496 1466
1467 if (!start || ret < 0) {
1468 ceph_osdc_cancel_event(rbd_dev->watch_event);
1469 rbd_dev->watch_event = NULL;
1470 }
1471done:
1497 rbd_destroy_op(op); 1472 rbd_destroy_op(op);
1498 ceph_osdc_cancel_event(rbd_dev->watch_event); 1473
1499 rbd_dev->watch_event = NULL;
1500 return ret; 1474 return ret;
1501} 1475}
1502 1476
@@ -3033,7 +3007,7 @@ static int rbd_init_watch_dev(struct rbd_device *rbd_dev)
3033 int ret, rc; 3007 int ret, rc;
3034 3008
3035 do { 3009 do {
3036 ret = rbd_req_sync_watch(rbd_dev); 3010 ret = rbd_req_sync_watch(rbd_dev, 1);
3037 if (ret == -ERANGE) { 3011 if (ret == -ERANGE) {
3038 rc = rbd_dev_refresh(rbd_dev, NULL); 3012 rc = rbd_dev_refresh(rbd_dev, NULL);
3039 if (rc < 0) 3013 if (rc < 0)
@@ -3752,8 +3726,7 @@ static void rbd_dev_release(struct device *dev)
3752 rbd_dev->watch_request); 3726 rbd_dev->watch_request);
3753 } 3727 }
3754 if (rbd_dev->watch_event) 3728 if (rbd_dev->watch_event)
3755 rbd_req_sync_unwatch(rbd_dev); 3729 rbd_req_sync_watch(rbd_dev, 0);
3756
3757 3730
3758 /* clean up and free blkdev */ 3731 /* clean up and free blkdev */
3759 rbd_free_disk(rbd_dev); 3732 rbd_free_disk(rbd_dev);