On Thu, Oct 20, 2022 at 12:56:01PM +0200, Christoph Hellwig wrote: > nvme and xen-blkfront are already doing this to stop buffered writes from > creating dirty pages that can't be written out later. Move it to the > common code. Note that this follows the xen-blkfront version that does > not send and uevent as the uevent is a bit confusing when the device is > about to go away a little later, and the the size change is just to stop > buffered writes faster. > > This also removes the comment about the ordering from nvme, as bd_mutex > not only is gone entirely, but also hasn't been used for locking updates > to the disk size long before that, and thus the ordering requirement > documented there doesn't apply any more. > > Signed-off-by: Christoph Hellwig <hch@xxxxxx> > --- > block/genhd.c | 3 +++ > drivers/block/xen-blkfront.c | 1 - > drivers/nvme/host/core.c | 7 +------ > 3 files changed, 4 insertions(+), 7 deletions(-) > > diff --git a/block/genhd.c b/block/genhd.c > index 17b33c62423df..2877b5f905579 100644 > --- a/block/genhd.c > +++ b/block/genhd.c > @@ -555,6 +555,9 @@ void blk_mark_disk_dead(struct gendisk *disk) > { > set_bit(GD_DEAD, &disk->state); > blk_queue_start_drain(disk->queue); > + > + /* stop buffered writers from dirtying pages that can't written out */ > + set_capacity(disk, 0); The idea makes sense: Reviewed-by: Ming Lei <ming.lei@xxxxxxxxxx> Just one small issue on mtip32xx, which may call blk_mark_disk_dead() in irq context, and ->bd_size_lock is actually not irq safe. But mtip32xx is already broken since blk_queue_start_drain() need mutex, maybe mtip32xx isn't actively used at all. Thanks, Ming