Skip to content

Commit

Permalink
block: remove GENHD_FL_UP
Browse files Browse the repository at this point in the history
Just check inode_unhashed on the whole device bdev inode instead,
and provide a helper to check for that information.

Signed-off-by: Christoph Hellwig <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Aug 12, 2021
1 parent b75f4ae commit 50b4aec
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 15 deletions.
6 changes: 2 additions & 4 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ bool set_capacity_and_notify(struct gendisk *disk, sector_t size)
* initial capacity during probing.
*/
if (size == capacity ||
(disk->flags & (GENHD_FL_UP | GENHD_FL_HIDDEN)) != GENHD_FL_UP)
!disk_live(disk) ||
(disk->flags & GENHD_FL_HIDDEN))
return false;

pr_info("%s: detected capacity change from %lld to %lld\n",
Expand Down Expand Up @@ -527,8 +528,6 @@ void device_add_disk(struct device *parent, struct gendisk *disk,
disk->flags |= GENHD_FL_EXT_DEVT;
}

disk->flags |= GENHD_FL_UP;

disk_alloc_events(disk);

if (disk->flags & GENHD_FL_HIDDEN) {
Expand Down Expand Up @@ -597,7 +596,6 @@ void del_gendisk(struct gendisk *disk)

mutex_lock(&disk->open_mutex);
remove_inode_hash(disk->part0->bd_inode);
disk->flags &= ~GENHD_FL_UP;
blk_drop_partitions(disk);
mutex_unlock(&disk->open_mutex);

Expand Down
4 changes: 2 additions & 2 deletions block/partitions/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ int bdev_add_partition(struct block_device *bdev, int partno,
int ret;

mutex_lock(&disk->open_mutex);
if (!(disk->flags & GENHD_FL_UP)) {
if (!disk_live(disk)) {
ret = -ENXIO;
goto out;
}
Expand Down Expand Up @@ -669,7 +669,7 @@ int bdev_disk_changed(struct gendisk *disk, bool invalidate)

lockdep_assert_held(&disk->open_mutex);

if (!(disk->flags & GENHD_FL_UP))
if (!disk_live(disk))
return -ENXIO;

rescan:
Expand Down
4 changes: 1 addition & 3 deletions drivers/md/md.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,9 +764,7 @@ struct md_rdev *md_find_rdev_rcu(struct mddev *mddev, dev_t dev);

static inline bool is_mddev_broken(struct md_rdev *rdev, const char *md_type)
{
int flags = rdev->bdev->bd_disk->flags;

if (!(flags & GENHD_FL_UP)) {
if (!disk_live(rdev->bdev->bd_disk)) {
if (!test_and_set_bit(MD_BROKEN, &rdev->mddev->flags))
pr_warn("md: %s: %s array has a missing/failed member\n",
mdname(rdev->mddev), md_type);
Expand Down
2 changes: 1 addition & 1 deletion drivers/nvme/host/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,7 @@ static void nvme_update_disk_info(struct gendisk *disk,
static inline bool nvme_first_scan(struct gendisk *disk)
{
/* nvme_alloc_ns() scans the disk prior to adding it */
return !(disk->flags & GENHD_FL_UP);
return !disk_live(disk);
}

static void nvme_set_chunk_sectors(struct nvme_ns *ns, struct nvme_id_ns *id)
Expand Down
2 changes: 1 addition & 1 deletion fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder)

mutex_lock(&disk->open_mutex);
ret = -ENXIO;
if (!(disk->flags & GENHD_FL_UP))
if (!disk_live(disk))
goto abort_claiming;
if (bdev_is_partition(bdev))
ret = blkdev_get_part(bdev, mode);
Expand Down
9 changes: 5 additions & 4 deletions include/linux/genhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ struct partition_meta_info {
* device.
* Affects responses to the ``CDROM_GET_CAPABILITY`` ioctl.
*
* ``GENHD_FL_UP`` (0x0010): indicates that the block device is "up",
* with a similar meaning to network interfaces.
*
* ``GENHD_FL_SUPPRESS_PARTITION_INFO`` (0x0020): don't include
* partition information in ``/proc/partitions`` or in the output of
* printk_all_partitions().
Expand Down Expand Up @@ -97,7 +94,6 @@ struct partition_meta_info {
/* 2 is unused (used to be GENHD_FL_DRIVERFS) */
/* 4 is unused (used to be GENHD_FL_MEDIA_CHANGE_NOTIFY) */
#define GENHD_FL_CD 0x0008
#define GENHD_FL_UP 0x0010
#define GENHD_FL_SUPPRESS_PARTITION_INFO 0x0020
#define GENHD_FL_EXT_DEVT 0x0040
#define GENHD_FL_NATIVE_CAPACITY 0x0080
Expand Down Expand Up @@ -178,6 +174,11 @@ struct gendisk {
u64 diskseq;
};

static inline bool disk_live(struct gendisk *disk)
{
return !inode_unhashed(disk->part0->bd_inode);
}

/*
* The gendisk is refcounted by the part0 block_device, and the bd_device
* therein is also used for device model presentation in sysfs.
Expand Down

0 comments on commit 50b4aec

Please sign in to comment.