loop: remove lo_refcount and avoid lo_mutex in ->open / ->release
authorChristoph Hellwig <hch@lst.de>
Wed, 30 Mar 2022 05:29:16 +0000 (07:29 +0200)
committerJens Axboe <axboe@kernel.dk>
Mon, 18 Apr 2022 12:54:09 +0000 (06:54 -0600)
commita0e286b6a5b61d4da01bdf865071c4da417046d6
tree3bc885d95283578b71c3750935e1d8d3bf3604c2
parent158eaeba4b8edf9940f64daa83cbd1ac7db7593c
loop: remove lo_refcount and avoid lo_mutex in ->open / ->release

lo_refcount counts how many openers a loop device has, but that count
is already provided by the block layer in the bd_openers field of the
whole-disk block_device.  Remove lo_refcount and allow opens to
succeed even on devices beeing deleted - now that ->free_disk is
implemented we can handle that race gracefull and all I/O on it will
just fail. Similarly there is a small race window now where
loop_control_remove does not synchronize the delete vs the remove
due do bd_openers not being under lo_mutex protection, but we can
handle that just as gracefully.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20220330052917.2566582-15-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/loop.c
drivers/block/loop.h