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: consolidate the shutdown logic in blk_mark_disk_dead and del_gendisk

blk_mark_disk_dead does very similar work a a section of del_gendisk:

- set the GD_DEAD flag
- set the capacity to zero
- start a queue drain

but del_gendisk also sets QUEUE_FLAG_DYING on the queue if it is owned by
the disk, sets the capacity to zero before starting the drain, and both
with sending a uevent and kernel message for this fake capacity change.

Move the exact logic from the more heavily used del_gendisk into
blk_mark_disk_dead and then call blk_mark_disk_dead from del_gendisk.

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-5-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
66fddc25 74e6464a

+12 -14
+12 -14
block/genhd.c
··· 572 572 */ 573 573 void blk_mark_disk_dead(struct gendisk *disk) 574 574 { 575 + /* 576 + * Fail any new I/O. 577 + */ 575 578 set_bit(GD_DEAD, &disk->state); 576 - blk_queue_start_drain(disk->queue); 579 + if (test_bit(GD_OWNS_QUEUE, &disk->state)) 580 + blk_queue_flag_set(QUEUE_FLAG_DYING, disk->queue); 577 581 578 582 /* 579 583 * Stop buffered writers from dirtying pages that can't be written out. 580 584 */ 581 - set_capacity_and_notify(disk, 0); 585 + set_capacity(disk, 0); 586 + 587 + /* 588 + * Prevent new I/O from crossing bio_queue_enter(). 589 + */ 590 + blk_queue_start_drain(disk->queue); 582 591 } 583 592 EXPORT_SYMBOL_GPL(blk_mark_disk_dead); 584 593 ··· 629 620 fsync_bdev(disk->part0); 630 621 __invalidate_device(disk->part0, true); 631 622 632 - /* 633 - * Fail any new I/O. 634 - */ 635 - set_bit(GD_DEAD, &disk->state); 636 - if (test_bit(GD_OWNS_QUEUE, &disk->state)) 637 - blk_queue_flag_set(QUEUE_FLAG_DYING, q); 638 - set_capacity(disk, 0); 639 - 640 - /* 641 - * Prevent new I/O from crossing bio_queue_enter(). 642 - */ 643 - blk_queue_start_drain(q); 623 + blk_mark_disk_dead(disk); 644 624 645 625 if (!(disk->flags & GENHD_FL_HIDDEN)) { 646 626 sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi");