block: add a new set_read_only method

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>
This commit is contained in:
Christoph Hellwig 2020-11-03 11:00:11 +01:00 коммит произвёл Jens Axboe
Родитель 4a9d6d667f
Коммит e00adcadf3
2 изменённых файлов: 6 добавлений и 0 удалений

Просмотреть файл

@ -389,6 +389,11 @@ static int blkdev_roset(struct block_device *bdev, fmode_t mode,
return ret; return ret;
if (get_user(n, (int __user *)arg)) if (get_user(n, (int __user *)arg))
return -EFAULT; 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); set_device_ro(bdev, n);
return 0; return 0;
} }

Просмотреть файл

@ -1850,6 +1850,7 @@ struct block_device_operations {
void (*unlock_native_capacity) (struct gendisk *); void (*unlock_native_capacity) (struct gendisk *);
int (*revalidate_disk) (struct gendisk *); int (*revalidate_disk) (struct gendisk *);
int (*getgeo)(struct block_device *, struct hd_geometry *); 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 */ /* this callback is with swap_lock and sometimes page table lock held */
void (*swap_slot_free_notify) (struct block_device *, unsigned long); void (*swap_slot_free_notify) (struct block_device *, unsigned long);
int (*report_zones)(struct gendisk *, sector_t sector, int (*report_zones)(struct gendisk *, sector_t sector,