]> www.infradead.org Git - users/hch/block.git/commitdiff
block: always call ->open and ->release for partitions
authorChristoph Hellwig <hch@lst.de>
Wed, 19 Jan 2022 07:26:45 +0000 (08:26 +0100)
committerChristoph Hellwig <hch@lst.de>
Wed, 19 Jan 2022 15:19:56 +0000 (16:19 +0100)
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 <hch@lst.de>
block/bdev.c

index f1fda6dd6be5246bded6d542092447fa0fa3173e..f81ef2a101234cbeb9e9f157a0ee8285d0f85e4f 100644 (file)
@@ -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);
 }