Skip to content

Commit

Permalink
block: move bdev_disk_changed
Browse files Browse the repository at this point in the history
Move bdev_disk_changed to block/partitions/core.c, together with the
rest of the partition scanning code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210624123240.441814-2-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Christoph Hellwig authored and Jens Axboe committed Jun 24, 2021
1 parent 2bc8cda commit 630161c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 55 deletions.
55 changes: 54 additions & 1 deletion block/partitions/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev,
return true;
}

int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
static int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
{
struct parsed_partitions *state;
int ret = -EAGAIN, p;
Expand Down Expand Up @@ -657,6 +657,59 @@ int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
return ret;
}

int bdev_disk_changed(struct block_device *bdev, bool invalidate)
{
struct gendisk *disk = bdev->bd_disk;
int ret = 0;

lockdep_assert_held(&disk->open_mutex);

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

rescan:
if (disk->open_partitions)
return -EBUSY;
sync_blockdev(bdev);
invalidate_bdev(bdev);
blk_drop_partitions(disk);

clear_bit(GD_NEED_PART_SCAN, &disk->state);

/*
* Historically we only set the capacity to zero for devices that
* support partitions (independ of actually having partitions created).
* Doing that is rather inconsistent, but changing it broke legacy
* udisks polling for legacy ide-cdrom devices. Use the crude check
* below to get the sane behavior for most device while not breaking
* userspace for this particular setup.
*/
if (invalidate) {
if (disk_part_scan_enabled(disk) ||
!(disk->flags & GENHD_FL_REMOVABLE))
set_capacity(disk, 0);
}

if (get_capacity(disk)) {
ret = blk_add_partitions(disk, bdev);
if (ret == -EAGAIN)
goto rescan;
} else if (invalidate) {
/*
* Tell userspace that the media / partition table may have
* changed.
*/
kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
}

return ret;
}
/*
* Only exported for loop and dasd for historic reasons. Don't use in new
* code!
*/
EXPORT_SYMBOL_GPL(bdev_disk_changed);

void *read_part_sector(struct parsed_partitions *state, sector_t n, Sector *p)
{
struct address_space *mapping = state->bdev->bd_inode->i_mapping;
Expand Down
53 changes: 0 additions & 53 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,59 +1242,6 @@ static void blkdev_flush_mapping(struct block_device *bdev)
bdev_write_inode(bdev);
}

int bdev_disk_changed(struct block_device *bdev, bool invalidate)
{
struct gendisk *disk = bdev->bd_disk;
int ret = 0;

lockdep_assert_held(&disk->open_mutex);

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

rescan:
if (disk->open_partitions)
return -EBUSY;
sync_blockdev(bdev);
invalidate_bdev(bdev);
blk_drop_partitions(disk);

clear_bit(GD_NEED_PART_SCAN, &disk->state);

/*
* Historically we only set the capacity to zero for devices that
* support partitions (independ of actually having partitions created).
* Doing that is rather inconsistent, but changing it broke legacy
* udisks polling for legacy ide-cdrom devices. Use the crude check
* below to get the sane behavior for most device while not breaking
* userspace for this particular setup.
*/
if (invalidate) {
if (disk_part_scan_enabled(disk) ||
!(disk->flags & GENHD_FL_REMOVABLE))
set_capacity(disk, 0);
}

if (get_capacity(disk)) {
ret = blk_add_partitions(disk, bdev);
if (ret == -EAGAIN)
goto rescan;
} else if (invalidate) {
/*
* Tell userspace that the media / partition table may have
* changed.
*/
kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
}

return ret;
}
/*
* Only exported for loop and dasd for historic reasons. Don't use in new
* code!
*/
EXPORT_SYMBOL_GPL(bdev_disk_changed);

static int blkdev_get_whole(struct block_device *bdev, fmode_t mode)
{
struct gendisk *disk = bdev->bd_disk;
Expand Down
1 change: 0 additions & 1 deletion include/linux/genhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ static inline sector_t get_capacity(struct gendisk *disk)
}

int bdev_disk_changed(struct block_device *bdev, bool invalidate);
int blk_add_partitions(struct gendisk *disk, struct block_device *bdev);
void blk_drop_partitions(struct gendisk *disk);

extern struct gendisk *__alloc_disk_node(int minors, int node_id);
Expand Down

0 comments on commit 630161c

Please sign in to comment.