提交 3c49f6f9 编写于 作者: C Christoph Hellwig 提交者: Jialin Zhang

block: merge disk_scan_partitions and blkdev_reread_part

mainline inclusion
from mainline-v5.17-rc1
commit e16e506c
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I6MQLP
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e16e506ccd673a3a888a34f8f694698305840044

--------------------------------

Unify the functionality that implements a partition rescan for a
gendisk.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20211122130625.1136848-6-hch@lst.deSigned-off-by: NJens Axboe <axboe@kernel.dk>

Conflicts:
	block/blk.h
	block/genhd.c
	block/ioctl.c
Signed-off-by: NYu Kuai <yukuai3@huawei.com>
Reviewed-by: NHou Tao <houtao1@huawei.com>
Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
上级 6c98f4cc
...@@ -186,6 +186,7 @@ bool blk_bio_list_merge(struct request_queue *q, struct list_head *list, ...@@ -186,6 +186,7 @@ bool blk_bio_list_merge(struct request_queue *q, struct list_head *list,
void blk_account_io_start(struct request *req); void blk_account_io_start(struct request *req);
void blk_account_io_done(struct request *req, u64 now); void blk_account_io_done(struct request *req, u64 now);
int disk_scan_partitions(struct gendisk *disk, fmode_t mode);
/* /*
* Plug flush limits * Plug flush limits
......
...@@ -736,17 +736,19 @@ static void register_disk(struct device *parent, struct gendisk *disk, ...@@ -736,17 +736,19 @@ static void register_disk(struct device *parent, struct gendisk *disk,
} }
} }
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;
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;
} }
static void disk_init_partition(struct gendisk *disk) static void disk_init_partition(struct gendisk *disk)
...@@ -755,7 +757,8 @@ static void disk_init_partition(struct gendisk *disk) ...@@ -755,7 +757,8 @@ static void disk_init_partition(struct gendisk *disk)
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *part; struct hd_struct *part;
disk_scan_partitions(disk); if (get_capacity(disk))
disk_scan_partitions(disk, FMODE_READ);
/* announce disk after possible partitions are created */ /* announce disk after possible partitions are created */
dev_set_uevent_suppress(ddev, 0); dev_set_uevent_suppress(ddev, 0);
......
...@@ -90,31 +90,6 @@ static int compat_blkpg_ioctl(struct block_device *bdev, ...@@ -90,31 +90,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_part_count)
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)
{ {
...@@ -562,7 +537,13 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode, ...@@ -562,7 +537,13 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode,
bdev->bd_bdi->ra_pages = (arg * 512) / PAGE_SIZE; bdev->bd_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;
if (bdev->bd_part_count)
return -EBUSY;
return disk_scan_partitions(bdev->bd_disk, mode & ~FMODE_EXCL);
case BLKTRACESTART: case BLKTRACESTART:
case BLKTRACESTOP: case BLKTRACESTOP:
case BLKTRACETEARDOWN: case BLKTRACETEARDOWN:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册