Skip to content

Commit 48ef0ba

Browse files
Ming LeiMike Snitzer
authored andcommitted
dm: restore synchronous close of device mapper block device
'dmsetup remove' and 'dmsetup remove_all' require synchronous bdev release. Otherwise dm_lock_for_deletion() may return -EBUSY if the open count is > 0, because the open count is dropped in dm_blk_close() which occurs after fput() completes. So if dm_blk_close() is delayed because of asynchronous fput(), this device mapper device is skipped during remove, which is a regression. Fix the issue by using __fput_sync(). Also, DM device removal has long supported being made asynchronous by setting the DMF_DEFERRED_REMOVE flag on the DM device. So leverage using async fput() in close_table_device() if DMF_DEFERRED_REMOVE flag is set. Reported-by: Zhong Changhui <czhong@redhat.com> Fixes: a28d893 ("md: port block device access to file") Suggested-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Ming Lei <ming.lei@redhat.com> [snitzer: editted commit header, use fput() if DMF_DEFERRED_REMOVE set] Signed-off-by: Mike Snitzer <snitzer@kernel.org>
1 parent f141dde commit 48ef0ba

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/md/dm.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ static struct table_device *open_table_device(struct mapped_device *md,
765765
return td;
766766

767767
out_blkdev_put:
768-
fput(bdev_file);
768+
__fput_sync(bdev_file);
769769
out_free_td:
770770
kfree(td);
771771
return ERR_PTR(r);
@@ -778,7 +778,13 @@ static void close_table_device(struct table_device *td, struct mapped_device *md
778778
{
779779
if (md->disk->slave_dir)
780780
bd_unlink_disk_holder(td->dm_dev.bdev, md->disk);
781-
fput(td->dm_dev.bdev_file);
781+
782+
/* Leverage async fput() if DMF_DEFERRED_REMOVE set */
783+
if (unlikely(test_bit(DMF_DEFERRED_REMOVE, &md->flags)))
784+
fput(td->dm_dev.bdev_file);
785+
else
786+
__fput_sync(td->dm_dev.bdev_file);
787+
782788
put_dax(td->dm_dev.dax_dev);
783789
list_del(&td->list);
784790
kfree(td);

0 commit comments

Comments
 (0)