diff mbox series

[2/9] block: avoid repeated work in blk_mark_disk_dead

Message ID 20230505175132.2236632-3-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/9] block: consolidate the shutdown logic in blk_mark_disk_dead and del_gendisk | expand

Commit Message

Christoph Hellwig May 5, 2023, 5:51 p.m. UTC
Check if GD_DEAD is already set in blk_mark_disk_dead, and don't
duplicate the work already done.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/genhd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Jan Kara May 7, 2023, 7:05 p.m. UTC | #1
On Fri 05-05-23 13:51:25, Christoph Hellwig wrote:
> Check if GD_DEAD is already set in blk_mark_disk_dead, and don't
> duplicate the work already done.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good to me. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  block/genhd.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/block/genhd.c b/block/genhd.c
> index 461999e9489937..9a35b8443f0b5f 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -586,7 +586,9 @@ void blk_mark_disk_dead(struct gendisk *disk)
>  	/*
>  	 * Fail any new I/O.
>  	 */
> -	set_bit(GD_DEAD, &disk->state);
> +	if (test_and_set_bit(GD_DEAD, &disk->state))
> +		return;
> +
>  	if (test_bit(GD_OWNS_QUEUE, &disk->state))
>  		blk_queue_flag_set(QUEUE_FLAG_DYING, disk->queue);
>  
> -- 
> 2.39.2
>
Christian Brauner May 16, 2023, 4:29 p.m. UTC | #2
On Fri, May 05, 2023 at 01:51:25PM -0400, Christoph Hellwig wrote:
> Check if GD_DEAD is already set in blk_mark_disk_dead, and don't
> duplicate the work already done.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---

Acked-by: Christian Brauner <brauner@kernel.org>
diff mbox series

Patch

diff --git a/block/genhd.c b/block/genhd.c
index 461999e9489937..9a35b8443f0b5f 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -586,7 +586,9 @@  void blk_mark_disk_dead(struct gendisk *disk)
 	/*
 	 * Fail any new I/O.
 	 */
-	set_bit(GD_DEAD, &disk->state);
+	if (test_and_set_bit(GD_DEAD, &disk->state))
+		return;
+
 	if (test_bit(GD_OWNS_QUEUE, &disk->state))
 		blk_queue_flag_set(QUEUE_FLAG_DYING, disk->queue);