block: merge disk_scan_partitions and blkdev_reread_part
Unify the functionality that implements a partition rescan for a gendisk. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20211122130625.1136848-6-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
e3b3bad3f2
commit
e16e506ccd
|
@ -449,6 +449,7 @@ int bio_add_hw_page(struct request_queue *q, struct bio *bio,
|
||||||
unsigned int max_sectors, bool *same_page);
|
unsigned int max_sectors, bool *same_page);
|
||||||
|
|
||||||
struct request_queue *blk_alloc_queue(int node_id);
|
struct request_queue *blk_alloc_queue(int node_id);
|
||||||
|
int disk_scan_partitions(struct gendisk *disk, fmode_t mode);
|
||||||
|
|
||||||
int disk_alloc_events(struct gendisk *disk);
|
int disk_alloc_events(struct gendisk *disk);
|
||||||
void disk_add_events(struct gendisk *disk);
|
void disk_add_events(struct gendisk *disk);
|
||||||
|
|
|
@ -372,17 +372,21 @@ void disk_uevent(struct gendisk *disk, enum kobject_action action)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(disk_uevent);
|
EXPORT_SYMBOL_GPL(disk_uevent);
|
||||||
|
|
||||||
static void disk_scan_partitions(struct gendisk *disk)
|
int disk_scan_partitions(struct gendisk *disk, fmode_t mode)
|
||||||
{
|
{
|
||||||
struct block_device *bdev;
|
struct block_device *bdev;
|
||||||
|
|
||||||
if (!get_capacity(disk) || !disk_part_scan_enabled(disk))
|
if (!disk_part_scan_enabled(disk))
|
||||||
return;
|
return -EINVAL;
|
||||||
|
if (disk->open_partitions)
|
||||||
|
return -EBUSY;
|
||||||
|
|
||||||
set_bit(GD_NEED_PART_SCAN, &disk->state);
|
set_bit(GD_NEED_PART_SCAN, &disk->state);
|
||||||
bdev = blkdev_get_by_dev(disk_devt(disk), FMODE_READ, NULL);
|
bdev = blkdev_get_by_dev(disk_devt(disk), mode, NULL);
|
||||||
if (!IS_ERR(bdev))
|
if (IS_ERR(bdev))
|
||||||
blkdev_put(bdev, FMODE_READ);
|
return PTR_ERR(bdev);
|
||||||
|
blkdev_put(bdev, mode);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -509,7 +513,8 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
|
||||||
goto out_unregister_bdi;
|
goto out_unregister_bdi;
|
||||||
|
|
||||||
bdev_add(disk->part0, ddev->devt);
|
bdev_add(disk->part0, ddev->devt);
|
||||||
disk_scan_partitions(disk);
|
if (get_capacity(disk))
|
||||||
|
disk_scan_partitions(disk, FMODE_READ);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Announce the disk and partitions after all partitions are
|
* Announce the disk and partitions after all partitions are
|
||||||
|
|
|
@ -82,31 +82,6 @@ static int compat_blkpg_ioctl(struct block_device *bdev,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int blkdev_reread_part(struct block_device *bdev, fmode_t mode)
|
|
||||||
{
|
|
||||||
struct block_device *tmp;
|
|
||||||
|
|
||||||
if (!disk_part_scan_enabled(bdev->bd_disk) || bdev_is_partition(bdev))
|
|
||||||
return -EINVAL;
|
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
|
||||||
return -EACCES;
|
|
||||||
if (bdev->bd_disk->open_partitions)
|
|
||||||
return -EBUSY;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Reopen the device to revalidate the driver state and force a
|
|
||||||
* partition rescan.
|
|
||||||
*/
|
|
||||||
mode &= ~FMODE_EXCL;
|
|
||||||
set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
|
|
||||||
|
|
||||||
tmp = blkdev_get_by_dev(bdev->bd_dev, mode, NULL);
|
|
||||||
if (IS_ERR(tmp))
|
|
||||||
return PTR_ERR(tmp);
|
|
||||||
blkdev_put(tmp, mode);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,
|
static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,
|
||||||
unsigned long arg, unsigned long flags)
|
unsigned long arg, unsigned long flags)
|
||||||
{
|
{
|
||||||
|
@ -522,7 +497,11 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode,
|
||||||
bdev->bd_disk->bdi->ra_pages = (arg * 512) / PAGE_SIZE;
|
bdev->bd_disk->bdi->ra_pages = (arg * 512) / PAGE_SIZE;
|
||||||
return 0;
|
return 0;
|
||||||
case BLKRRPART:
|
case BLKRRPART:
|
||||||
return blkdev_reread_part(bdev, mode);
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
|
return -EACCES;
|
||||||
|
if (bdev_is_partition(bdev))
|
||||||
|
return -EINVAL;
|
||||||
|
return disk_scan_partitions(bdev->bd_disk, mode & ~FMODE_EXCL);
|
||||||
case BLKTRACESTART:
|
case BLKTRACESTART:
|
||||||
case BLKTRACESTOP:
|
case BLKTRACESTOP:
|
||||||
case BLKTRACETEARDOWN:
|
case BLKTRACETEARDOWN:
|
||||||
|
|
Loading…
Reference in New Issue