]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
block: add a new set_read_only method
authorChristoph Hellwig <hch@lst.de>
Tue, 3 Nov 2020 10:00:11 +0000 (11:00 +0100)
committerSasha Levin <sashal@kernel.org>
Tue, 26 Mar 2024 22:21:48 +0000 (18:21 -0400)
[ Upstream commit e00adcadf3af7a8335026d71ab9f0e0a922191ac ]

Add a new method to allow for driver-specific processing when setting or
clearing the block device read-only state.  This allows to replace the
cumbersome and error-prone override of the whole ioctl implementation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Stable-dep-of: 9674f54e41ff ("md: Don't clear MD_CLOSING when the raid is about to stop")
Signed-off-by: Sasha Levin <sashal@kernel.org>
block/ioctl.c
include/linux/blkdev.h

index e7eed7dadb5cf5867b21efc59a125dc9dc43ca87..24f8042f12b6033ac7edd2366b5a18e08157a656 100644 (file)
@@ -405,6 +405,11 @@ static int blkdev_roset(struct block_device *bdev, fmode_t mode,
                return ret;
        if (get_user(n, (int __user *)arg))
                return -EFAULT;
+       if (bdev->bd_disk->fops->set_read_only) {
+               ret = bdev->bd_disk->fops->set_read_only(bdev, n);
+               if (ret)
+                       return ret;
+       }
        set_device_ro(bdev, n);
        return 0;
 }
index 98fdf5a31fd66c80683cba3a5edf42ddcad6cf4d..583824f1110790057ad313de57500615ce2ed664 100644 (file)
@@ -1883,6 +1883,7 @@ struct block_device_operations {
        void (*unlock_native_capacity) (struct gendisk *);
        int (*revalidate_disk) (struct gendisk *);
        int (*getgeo)(struct block_device *, struct hd_geometry *);
+       int (*set_read_only)(struct block_device *bdev, bool ro);
        /* this callback is with swap_lock and sometimes page table lock held */
        void (*swap_slot_free_notify) (struct block_device *, unsigned long);
        int (*report_zones)(struct gendisk *, sector_t sector,