block: move the NEED_PART_SCAN flag to struct gendisk

We can only scan for partitions on the whole disk, so move the flag
from struct block_device to struct gendisk.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Christoph Hellwig 2020-09-21 09:19:45 +02:00 коммит произвёл Jens Axboe
Родитель 07d098e6bb
Коммит 38430f0876
6 изменённых файлов: 13 добавлений и 14 удалений

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

@ -731,7 +731,7 @@ static void register_disk(struct device *parent, struct gendisk *disk,
if (!bdev) if (!bdev)
goto exit; goto exit;
set_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags); set_bit(GD_NEED_PART_SCAN, &disk->state);
err = blkdev_get(bdev, FMODE_READ, NULL); err = blkdev_get(bdev, FMODE_READ, NULL);
if (err < 0) if (err < 0)
goto exit; goto exit;
@ -2112,7 +2112,7 @@ bool bdev_check_media_change(struct block_device *bdev)
if (__invalidate_device(bdev, true)) if (__invalidate_device(bdev, true))
pr_warn("VFS: busy inodes on changed media %s\n", pr_warn("VFS: busy inodes on changed media %s\n",
bdev->bd_disk->disk_name); bdev->bd_disk->disk_name);
set_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags); set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
return true; return true;
} }
EXPORT_SYMBOL(bdev_check_media_change); EXPORT_SYMBOL(bdev_check_media_change);

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

@ -315,7 +315,7 @@ static void nbd_size_update(struct nbd_device *nbd)
bd_set_nr_sectors(bdev, nr_sectors); bd_set_nr_sectors(bdev, nr_sectors);
set_blocksize(bdev, config->blksize); set_blocksize(bdev, config->blksize);
} else } else
set_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags); set_bit(GD_NEED_PART_SCAN, &nbd->disk->state);
bdput(bdev); bdput(bdev);
} }
kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE); kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE);
@ -1322,7 +1322,7 @@ static int nbd_start_device_ioctl(struct nbd_device *nbd, struct block_device *b
return ret; return ret;
if (max_part) if (max_part)
set_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags); set_bit(GD_NEED_PART_SCAN, &nbd->disk->state);
mutex_unlock(&nbd->config_lock); mutex_unlock(&nbd->config_lock);
ret = wait_event_interruptible(config->recv_wq, ret = wait_event_interruptible(config->recv_wq,
atomic_read(&config->recv_threads) == 0); atomic_read(&config->recv_threads) == 0);
@ -1500,9 +1500,9 @@ static int nbd_open(struct block_device *bdev, fmode_t mode)
refcount_set(&nbd->config_refs, 1); refcount_set(&nbd->config_refs, 1);
refcount_inc(&nbd->refs); refcount_inc(&nbd->refs);
mutex_unlock(&nbd->config_lock); mutex_unlock(&nbd->config_lock);
set_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags); set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
} else if (nbd_disconnected(nbd->config)) { } else if (nbd_disconnected(nbd->config)) {
set_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags); set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
} }
out: out:
mutex_unlock(&nbd_index_mutex); mutex_unlock(&nbd_index_mutex);

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

@ -230,7 +230,7 @@ static int ide_gd_open(struct block_device *bdev, fmode_t mode)
bdev->bd_disk->disk_name); bdev->bd_disk->disk_name);
drive->disk_ops->get_capacity(drive); drive->disk_ops->get_capacity(drive);
set_capacity(disk, ide_gd_capacity(drive)); set_capacity(disk, ide_gd_capacity(drive));
set_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags); set_bit(GD_NEED_PART_SCAN, &disk->state);
} else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) { } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) {
ret = -EBUSY; ret = -EBUSY;
goto out_put_idkp; goto out_put_idkp;

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

@ -910,7 +910,6 @@ struct block_device *bdget(dev_t dev)
bdev->bd_super = NULL; bdev->bd_super = NULL;
bdev->bd_inode = inode; bdev->bd_inode = inode;
bdev->bd_part_count = 0; bdev->bd_part_count = 0;
bdev->bd_flags = 0;
inode->i_mode = S_IFBLK; inode->i_mode = S_IFBLK;
inode->i_rdev = dev; inode->i_rdev = dev;
inode->i_bdev = bdev; inode->i_bdev = bdev;
@ -1385,7 +1384,7 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate)
lockdep_assert_held(&bdev->bd_mutex); lockdep_assert_held(&bdev->bd_mutex);
clear_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags); clear_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
rescan: rescan:
ret = blk_drop_partitions(bdev); ret = blk_drop_partitions(bdev);
@ -1509,7 +1508,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, void *holder,
* The latter is necessary to prevent ghost * The latter is necessary to prevent ghost
* partitions on a removed medium. * partitions on a removed medium.
*/ */
if (test_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags) && if (test_bit(GD_NEED_PART_SCAN, &disk->state) &&
(!ret || ret == -ENOMEDIUM)) (!ret || ret == -ENOMEDIUM))
bdev_disk_changed(bdev, ret == -ENOMEDIUM); bdev_disk_changed(bdev, ret == -ENOMEDIUM);
@ -1539,7 +1538,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, void *holder,
if (bdev->bd_disk->fops->open) if (bdev->bd_disk->fops->open)
ret = bdev->bd_disk->fops->open(bdev, mode); ret = bdev->bd_disk->fops->open(bdev, mode);
/* the same as first opener case, read comment there */ /* the same as first opener case, read comment there */
if (test_bit(BDEV_NEED_PART_SCAN, &bdev->bd_flags) && if (test_bit(GD_NEED_PART_SCAN, &disk->state) &&
(!ret || ret == -ENOMEDIUM)) (!ret || ret == -ENOMEDIUM))
bdev_disk_changed(bdev, ret == -ENOMEDIUM); bdev_disk_changed(bdev, ret == -ENOMEDIUM);
if (ret) if (ret)

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

@ -19,8 +19,6 @@ struct cgroup_subsys_state;
typedef void (bio_end_io_t) (struct bio *); typedef void (bio_end_io_t) (struct bio *);
struct bio_crypt_ctx; struct bio_crypt_ctx;
#define BDEV_NEED_PART_SCAN 0
struct block_device { struct block_device {
dev_t bd_dev; dev_t bd_dev;
int bd_openers; int bd_openers;
@ -39,7 +37,7 @@ struct block_device {
struct hd_struct * bd_part; struct hd_struct * bd_part;
/* number of times partitions within this device have been opened. */ /* number of times partitions within this device have been opened. */
unsigned bd_part_count; unsigned bd_part_count;
unsigned long bd_flags;
spinlock_t bd_size_lock; /* for bd_inode->i_size updates */ spinlock_t bd_size_lock; /* for bd_inode->i_size updates */
struct gendisk * bd_disk; struct gendisk * bd_disk;
struct backing_dev_info *bd_bdi; struct backing_dev_info *bd_bdi;

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

@ -191,6 +191,8 @@ struct gendisk {
void *private_data; void *private_data;
int flags; int flags;
unsigned long state;
#define GD_NEED_PART_SCAN 0
struct rw_semaphore lookup_sem; struct rw_semaphore lookup_sem;
struct kobject *slave_dir; struct kobject *slave_dir;