Add post_release() block device operation which provides a hook for performing synchronous cleanup without disk->open_mutex held. This is needed by block drivers (such as the loop device) that must drain in-flight I/O and perform synchronization after disk->open_mutex has been released. Suggested-by: Tetsuo Handa Signed-off-by: Bart Van Assche --- block/bdev.c | 3 +++ include/linux/blkdev.h | 5 +++++ rust/kernel/block/mq/gen_disk.rs | 1 + 3 files changed, 9 insertions(+) diff --git a/block/bdev.c b/block/bdev.c index fac74319e9fb..350f3c29d682 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1189,6 +1189,9 @@ void bdev_release(struct file *bdev_file) blkdev_put_whole(bdev); mutex_unlock(&disk->open_mutex); + if (disk->fops->post_release) + disk->fops->post_release(disk); + module_put(disk->fops->owner); put_no_open: blkdev_put_no_open(bdev); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index d003a9d2d1f6..b35f8af1243e 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1580,6 +1580,11 @@ struct block_device_operations { unsigned int flags); int (*open)(struct gendisk *disk, blk_mode_t mode); void (*release)(struct gendisk *disk); + /* + * Called after disk->open_mutex is released in the bdev_release() path, + * after .release(). Implementations may sleep. + */ + void (*post_release)(struct gendisk *disk); int (*ioctl)(struct block_device *bdev, blk_mode_t mode, unsigned cmd, unsigned long arg); int (*compat_ioctl)(struct block_device *bdev, blk_mode_t mode, diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_disk.rs index fc97dd873974..2ff77ef49781 100644 --- a/rust/kernel/block/mq/gen_disk.rs +++ b/rust/kernel/block/mq/gen_disk.rs @@ -129,6 +129,7 @@ pub fn build( submit_bio: None, open: None, release: None, + post_release: None, ioctl: None, compat_ioctl: None, check_events: None,