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>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
struct list_head *tmp;
int dev_id;
unsigned long ul;
+ bool already = false;
int ret;
ret = strict_strtoul(buf, 10, &ul);
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);