diff mbox

[2/5] rbd: protect against concurrent unmaps

Message ID 51A94C5A.20807@inktank.com (mailing list archive)
State New, archived
Headers show

Commit Message

Alex Elder June 1, 2013, 1:20 a.m. UTC
Make sure two concurrent unmap operations on the same rbd device
won't collide, by only proceeding with the removal and cleanup of a
device if is not already underway.

Signed-off-by: Alex Elder <elder@inktank.com>
---
 drivers/block/rbd.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Josh Durgin June 7, 2013, 5:42 p.m. UTC | #1
Reviewed-by: Josh Durgin <josh.durgin@inktank.com> 

Alex Elder <elder@inktank.com> wrote:
>Make sure two concurrent unmap operations on the same rbd device
>won't collide, by only proceeding with the removal and cleanup of a
>device if is not already underway.
>
>Signed-off-by: Alex Elder <elder@inktank.com>
>---
> drivers/block/rbd.c |    6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
>index 716ef1f..380940d 100644
>--- a/drivers/block/rbd.c
>+++ b/drivers/block/rbd.c
>@@ -5153,6 +5153,7 @@ static ssize_t rbd_remove(struct bus_type *bus,
> 	struct list_head *tmp;
> 	int dev_id;
> 	unsigned long ul;
>+	bool already = false;
> 	int ret;
>
> 	ret = strict_strtoul(buf, 10, &ul);
>@@ -5180,11 +5181,12 @@ static ssize_t rbd_remove(struct bus_type *bus,
> 		if (rbd_dev->open_count)
> 			ret = -EBUSY;
> 		else
>-			set_bit(RBD_DEV_FLAG_REMOVING, &rbd_dev->flags);
>+			already = test_and_set_bit(RBD_DEV_FLAG_REMOVING,
>+							&rbd_dev->flags);
> 		spin_unlock_irq(&rbd_dev->lock);
> 	}
> 	spin_unlock(&rbd_dev_list_lock);
>-	if (ret < 0)
>+	if (ret < 0 || already)
> 		goto done;
>
> 	rbd_bus_del_dev(rbd_dev);


--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 716ef1f..380940d 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -5153,6 +5153,7 @@  static ssize_t rbd_remove(struct bus_type *bus,
 	struct list_head *tmp;
 	int dev_id;
 	unsigned long ul;
+	bool already = false;
 	int ret;

 	ret = strict_strtoul(buf, 10, &ul);
@@ -5180,11 +5181,12 @@  static ssize_t rbd_remove(struct bus_type *bus,
 		if (rbd_dev->open_count)
 			ret = -EBUSY;
 		else
-			set_bit(RBD_DEV_FLAG_REMOVING, &rbd_dev->flags);
+			already = test_and_set_bit(RBD_DEV_FLAG_REMOVING,
+							&rbd_dev->flags);
 		spin_unlock_irq(&rbd_dev->lock);
 	}
 	spin_unlock(&rbd_dev_list_lock);
-	if (ret < 0)
+	if (ret < 0 || already)
 		goto done;

 	rbd_bus_del_dev(rbd_dev);