Commit 0d8189e1 authored by Alex Elder's avatar Alex Elder Committed by Sage Weil

rbd: don't clean up watch in device release function

Currently, a watch on an rbd device header object gets torn down
when its final Linux device reference gets dropped.  Instead, tear
it down when removing the device.  If an error occurs cleaning up
the watch event when unmapping, abort the unmap request.

All images (including parents) still get watch requests set up, so
tear these down also, in rbd_dev_remove_parent().  For now, ignore
any errors that occur in this case.

Get rid of local variable "rc" in rbd_remove(); use "ret" instead
(they both somehow ended up defined in the function and only one is
needed).
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
parent 332bb12d
...@@ -4729,6 +4729,7 @@ static int rbd_dev_probe_parent(struct rbd_device *rbd_dev) ...@@ -4729,6 +4729,7 @@ static int rbd_dev_probe_parent(struct rbd_device *rbd_dev)
static int rbd_dev_probe_finish(struct rbd_device *rbd_dev) static int rbd_dev_probe_finish(struct rbd_device *rbd_dev)
{ {
int ret; int ret;
int tmp;
ret = rbd_dev_header_watch_sync(rbd_dev, 1); ret = rbd_dev_header_watch_sync(rbd_dev, 1);
if (ret) if (ret)
...@@ -4780,6 +4781,9 @@ static int rbd_dev_probe_finish(struct rbd_device *rbd_dev) ...@@ -4780,6 +4781,9 @@ static int rbd_dev_probe_finish(struct rbd_device *rbd_dev)
unregister_blkdev(rbd_dev->major, rbd_dev->name); unregister_blkdev(rbd_dev->major, rbd_dev->name);
err_out_id: err_out_id:
rbd_dev_id_put(rbd_dev); rbd_dev_id_put(rbd_dev);
tmp = rbd_dev_header_watch_sync(rbd_dev, 0);
if (tmp)
rbd_warn(rbd_dev, "failed to cancel watch event (%d)\n", ret);
rbd_dev_mapping_clear(rbd_dev); rbd_dev_mapping_clear(rbd_dev);
return ret; return ret;
...@@ -4975,9 +4979,6 @@ static void rbd_dev_release(struct device *dev) ...@@ -4975,9 +4979,6 @@ static void rbd_dev_release(struct device *dev)
{ {
struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
if (rbd_dev->watch_event)
rbd_dev_header_watch_sync(rbd_dev, 0);
/* clean up and free blkdev */ /* clean up and free blkdev */
rbd_free_disk(rbd_dev); rbd_free_disk(rbd_dev);
unregister_blkdev(rbd_dev->major, rbd_dev->name); unregister_blkdev(rbd_dev->major, rbd_dev->name);
...@@ -5003,6 +5004,7 @@ static void rbd_dev_remove_parent(struct rbd_device *rbd_dev) ...@@ -5003,6 +5004,7 @@ static void rbd_dev_remove_parent(struct rbd_device *rbd_dev)
struct rbd_device *first = rbd_dev; struct rbd_device *first = rbd_dev;
struct rbd_device *second = first->parent; struct rbd_device *second = first->parent;
struct rbd_device *third; struct rbd_device *third;
int ret;
/* /*
* Follow to the parent with no grandparent and * Follow to the parent with no grandparent and
...@@ -5013,6 +5015,10 @@ static void rbd_dev_remove_parent(struct rbd_device *rbd_dev) ...@@ -5013,6 +5015,10 @@ static void rbd_dev_remove_parent(struct rbd_device *rbd_dev)
second = third; second = third;
} }
rbd_assert(second); rbd_assert(second);
ret = rbd_dev_header_watch_sync(rbd_dev, 0);
if (ret)
rbd_warn(rbd_dev,
"failed to cancel watch event (%d)\n", ret);
rbd_remove_all_snaps(second); rbd_remove_all_snaps(second);
rbd_bus_del_dev(second); rbd_bus_del_dev(second);
first->parent = NULL; first->parent = NULL;
...@@ -5029,13 +5035,13 @@ static ssize_t rbd_remove(struct bus_type *bus, ...@@ -5029,13 +5035,13 @@ static ssize_t rbd_remove(struct bus_type *bus,
size_t count) size_t count)
{ {
struct rbd_device *rbd_dev = NULL; struct rbd_device *rbd_dev = NULL;
int target_id, rc; int target_id;
unsigned long ul; unsigned long ul;
int ret = count; int ret;
rc = strict_strtoul(buf, 10, &ul); ret = strict_strtoul(buf, 10, &ul);
if (rc) if (ret)
return rc; return ret;
/* convert to int; abort if we lost anything in the conversion */ /* convert to int; abort if we lost anything in the conversion */
target_id = (int) ul; target_id = (int) ul;
...@@ -5059,6 +5065,15 @@ static ssize_t rbd_remove(struct bus_type *bus, ...@@ -5059,6 +5065,15 @@ static ssize_t rbd_remove(struct bus_type *bus,
if (ret < 0) if (ret < 0)
goto done; goto done;
ret = rbd_dev_header_watch_sync(rbd_dev, 0);
if (ret) {
rbd_warn(rbd_dev, "failed to cancel watch event (%d)\n", ret);
clear_bit(RBD_DEV_FLAG_REMOVING, &rbd_dev->flags);
smp_mb();
return ret;
}
ret = count;
rbd_dev_remove_parent(rbd_dev); rbd_dev_remove_parent(rbd_dev);
rbd_remove_all_snaps(rbd_dev); rbd_remove_all_snaps(rbd_dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment