From 3147681ca8254f9581a01f91d50b20cfcdcbbc8f Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Wed, 19 Jan 2022 08:26:45 +0100 Subject: [PATCH] block: always call ->open and ->release for partitions The current rules for calling ->open and ->release on block devices are a bit strange in that the methods are called for each blkdev_get/put on the whole device, but only once per partition. Change to use the same rules for partitions and whole devices, notwithstanding that for most drivers that really should be once only eventually. Signed-off-by: Christoph Hellwig --- block/bdev.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index f1fda6dd6be5..f81ef2a10123 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -734,9 +734,6 @@ static int blkdev_get_part(struct block_device *part, fmode_t mode) struct gendisk *disk = part->bd_disk; int ret; - if (part->bd_openers) - goto done; - ret = blkdev_get_whole(bdev_whole(part), mode); if (ret) return ret; @@ -745,10 +742,11 @@ static int blkdev_get_part(struct block_device *part, fmode_t mode) if (!bdev_nr_sectors(part)) goto out_blkdev_put; - disk->open_partitions++; - set_init_blocksize(part); -done: - part->bd_openers++; + if (!part->bd_openers++) { + disk->open_partitions++; + set_init_blocksize(part); + } + return 0; out_blkdev_put: @@ -760,10 +758,10 @@ static void blkdev_put_part(struct block_device *part, fmode_t mode) { struct block_device *whole = bdev_whole(part); - if (--part->bd_openers) - return; - blkdev_flush_mapping(part); - whole->bd_disk->open_partitions--; + if (!--part->bd_openers) { + blkdev_flush_mapping(part); + whole->bd_disk->open_partitions--; + } blkdev_put_whole(whole, mode); } -- 2.50.1