Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

block: delete partitions later in del_gendisk

Delay dropping the block_devices for partitions in del_gendisk until
after the call to blk_mark_disk_dead, so that we can implementat
notification of removed devices in blk_mark_disk_dead.

This requires splitting a lower-level drop_partition helper out of
delete_partition and using that from del_gendisk, while having a
common loop for the whole device and partitions that calls
remove_inode_hash, fsync_bdev and __invalidate_device before the
call to blk_mark_disk_dead.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Acked-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Link: https://lore.kernel.org/r/20230601094459.1350643-8-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
eec1be4c 69f90b70

+32 -13
+1 -1
block/blk.h
··· 409 409 int bdev_del_partition(struct gendisk *disk, int partno); 410 410 int bdev_resize_partition(struct gendisk *disk, int partno, sector_t start, 411 411 sector_t length); 412 - void blk_drop_partitions(struct gendisk *disk); 412 + void drop_partition(struct block_device *part); 413 413 414 414 void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors); 415 415
+19 -5
block/genhd.c
··· 615 615 void del_gendisk(struct gendisk *disk) 616 616 { 617 617 struct request_queue *q = disk->queue; 618 + struct block_device *part; 619 + unsigned long idx; 618 620 619 621 might_sleep(); 620 622 ··· 625 623 626 624 disk_del_events(disk); 627 625 626 + /* 627 + * Prevent new openers by unlinked the bdev inode, and write out 628 + * dirty data before marking the disk dead and stopping all I/O. 629 + */ 628 630 mutex_lock(&disk->open_mutex); 629 - remove_inode_hash(disk->part0->bd_inode); 630 - blk_drop_partitions(disk); 631 + xa_for_each(&disk->part_tbl, idx, part) { 632 + remove_inode_hash(part->bd_inode); 633 + fsync_bdev(part); 634 + __invalidate_device(part, true); 635 + } 631 636 mutex_unlock(&disk->open_mutex); 632 637 633 - fsync_bdev(disk->part0); 634 - __invalidate_device(disk->part0, true); 635 - 636 638 blk_mark_disk_dead(disk); 639 + 640 + /* 641 + * Drop all partitions now that the disk is marked dead. 642 + */ 643 + mutex_lock(&disk->open_mutex); 644 + xa_for_each_start(&disk->part_tbl, idx, part, 1) 645 + drop_partition(part); 646 + mutex_unlock(&disk->open_mutex); 637 647 638 648 if (!(disk->flags & GENHD_FL_HIDDEN)) { 639 649 sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi");
+12 -7
block/partitions/core.c
··· 263 263 .uevent = part_uevent, 264 264 }; 265 265 266 - static void delete_partition(struct block_device *part) 266 + void drop_partition(struct block_device *part) 267 267 { 268 268 lockdep_assert_held(&part->bd_disk->open_mutex); 269 269 270 + xa_erase(&part->bd_disk->part_tbl, part->bd_partno); 271 + kobject_put(part->bd_holder_dir); 272 + 273 + device_del(&part->bd_device); 274 + put_device(&part->bd_device); 275 + } 276 + 277 + static void delete_partition(struct block_device *part) 278 + { 270 279 /* 271 280 * Remove the block device from the inode hash, so that it cannot be 272 281 * looked up any more even when openers still hold references. ··· 285 276 fsync_bdev(part); 286 277 __invalidate_device(part, true); 287 278 288 - xa_erase(&part->bd_disk->part_tbl, part->bd_partno); 289 - kobject_put(part->bd_holder_dir); 290 - device_del(&part->bd_device); 291 - 292 - put_device(&part->bd_device); 279 + drop_partition(part); 293 280 } 294 281 295 282 static ssize_t whole_disk_show(struct device *dev, ··· 524 519 return true; 525 520 } 526 521 527 - void blk_drop_partitions(struct gendisk *disk) 522 + static void blk_drop_partitions(struct gendisk *disk) 528 523 { 529 524 struct block_device *part; 530 525 unsigned long idx;