Skip to content

Commit 630161c

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move bdev_disk_changed
Move bdev_disk_changed to block/partitions/core.c, together with the rest of the partition scanning code. Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 2bc8cda commit 630161c

File tree

3 files changed

+54
-55
lines changed

3 files changed

+54
-55
lines changed

block/partitions/core.c

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev,
596596
return true;
597597
}
598598

599-
int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
599+
static int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
600600
{
601601
struct parsed_partitions *state;
602602
int ret = -EAGAIN, p;
@@ -657,6 +657,59 @@ int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
657657
return ret;
658658
}
659659

660+
int bdev_disk_changed(struct block_device *bdev, bool invalidate)
661+
{
662+
struct gendisk *disk = bdev->bd_disk;
663+
int ret = 0;
664+
665+
lockdep_assert_held(&disk->open_mutex);
666+
667+
if (!(disk->flags & GENHD_FL_UP))
668+
return -ENXIO;
669+
670+
rescan:
671+
if (disk->open_partitions)
672+
return -EBUSY;
673+
sync_blockdev(bdev);
674+
invalidate_bdev(bdev);
675+
blk_drop_partitions(disk);
676+
677+
clear_bit(GD_NEED_PART_SCAN, &disk->state);
678+
679+
/*
680+
* Historically we only set the capacity to zero for devices that
681+
* support partitions (independ of actually having partitions created).
682+
* Doing that is rather inconsistent, but changing it broke legacy
683+
* udisks polling for legacy ide-cdrom devices. Use the crude check
684+
* below to get the sane behavior for most device while not breaking
685+
* userspace for this particular setup.
686+
*/
687+
if (invalidate) {
688+
if (disk_part_scan_enabled(disk) ||
689+
!(disk->flags & GENHD_FL_REMOVABLE))
690+
set_capacity(disk, 0);
691+
}
692+
693+
if (get_capacity(disk)) {
694+
ret = blk_add_partitions(disk, bdev);
695+
if (ret == -EAGAIN)
696+
goto rescan;
697+
} else if (invalidate) {
698+
/*
699+
* Tell userspace that the media / partition table may have
700+
* changed.
701+
*/
702+
kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
703+
}
704+
705+
return ret;
706+
}
707+
/*
708+
* Only exported for loop and dasd for historic reasons. Don't use in new
709+
* code!
710+
*/
711+
EXPORT_SYMBOL_GPL(bdev_disk_changed);
712+
660713
void *read_part_sector(struct parsed_partitions *state, sector_t n, Sector *p)
661714
{
662715
struct address_space *mapping = state->bdev->bd_inode->i_mapping;

fs/block_dev.c

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,59 +1242,6 @@ static void blkdev_flush_mapping(struct block_device *bdev)
12421242
bdev_write_inode(bdev);
12431243
}
12441244

1245-
int bdev_disk_changed(struct block_device *bdev, bool invalidate)
1246-
{
1247-
struct gendisk *disk = bdev->bd_disk;
1248-
int ret = 0;
1249-
1250-
lockdep_assert_held(&disk->open_mutex);
1251-
1252-
if (!(disk->flags & GENHD_FL_UP))
1253-
return -ENXIO;
1254-
1255-
rescan:
1256-
if (disk->open_partitions)
1257-
return -EBUSY;
1258-
sync_blockdev(bdev);
1259-
invalidate_bdev(bdev);
1260-
blk_drop_partitions(disk);
1261-
1262-
clear_bit(GD_NEED_PART_SCAN, &disk->state);
1263-
1264-
/*
1265-
* Historically we only set the capacity to zero for devices that
1266-
* support partitions (independ of actually having partitions created).
1267-
* Doing that is rather inconsistent, but changing it broke legacy
1268-
* udisks polling for legacy ide-cdrom devices. Use the crude check
1269-
* below to get the sane behavior for most device while not breaking
1270-
* userspace for this particular setup.
1271-
*/
1272-
if (invalidate) {
1273-
if (disk_part_scan_enabled(disk) ||
1274-
!(disk->flags & GENHD_FL_REMOVABLE))
1275-
set_capacity(disk, 0);
1276-
}
1277-
1278-
if (get_capacity(disk)) {
1279-
ret = blk_add_partitions(disk, bdev);
1280-
if (ret == -EAGAIN)
1281-
goto rescan;
1282-
} else if (invalidate) {
1283-
/*
1284-
* Tell userspace that the media / partition table may have
1285-
* changed.
1286-
*/
1287-
kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
1288-
}
1289-
1290-
return ret;
1291-
}
1292-
/*
1293-
* Only exported for loop and dasd for historic reasons. Don't use in new
1294-
* code!
1295-
*/
1296-
EXPORT_SYMBOL_GPL(bdev_disk_changed);
1297-
12981245
static int blkdev_get_whole(struct block_device *bdev, fmode_t mode)
12991246
{
13001247
struct gendisk *disk = bdev->bd_disk;

include/linux/genhd.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ static inline sector_t get_capacity(struct gendisk *disk)
257257
}
258258

259259
int bdev_disk_changed(struct block_device *bdev, bool invalidate);
260-
int blk_add_partitions(struct gendisk *disk, struct block_device *bdev);
261260
void blk_drop_partitions(struct gendisk *disk);
262261

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

0 commit comments

Comments
 (0)