public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Keith Busch <kbusch@meta.com>
Cc: linux-block@vger.kernel.org, axboe@kernel.org,
	Keith Busch <kbusch@kernel.org>,
	Nilay Shroff <nilay@linux.ibm.com>,
	Chaitanya Kulkarni <chaitanyak@nvidia.com>,
	Conrad Meyer <conradmeyer@meta.com>
Subject: Re: [PATCHv2] blk-lib: check for kill signal
Date: Thu, 22 Feb 2024 12:02:36 +0800	[thread overview]
Message-ID: <ZdbHXDCquO23rbJk@fedora> (raw)
In-Reply-To: <20240221222013.582613-1-kbusch@meta.com>

On Wed, Feb 21, 2024 at 02:20:13PM -0800, Keith Busch wrote:
> From: Keith Busch <kbusch@kernel.org>
> 
> Some of these block operations can access the entire device capacity,
> and can take a lot longer than the user expected. The user may change
> their mind about wanting to run that command and attempt to kill the
> process, but we're running uninterruptable, so they have to wait for it
> to finish, which could be hours.
> 
> Check for a fatal signal at each iteration so the user doesn't have to
> wait for their regretted operation to complete.
> 
> Cc: Ming Lei <ming.lei@redhat.com>
> Cc: Nilay Shroff <nilay@linux.ibm.com>
> Cc: Chaitanya Kulkarni <chaitanyak@nvidia.com>
> Reported-by: Conrad Meyer <conradmeyer@meta.com>
> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
> Changes from v1:
> 
>   Check the kill signal on all the long operations, not just the
>   zero-out fallback.
> 
>   Be sure to return -EINTR on the condition.
> 
>   After the kill signal is observered, instead of submitting and waiting
>   for the current parent bio in the chain, abort it by ending it
>   immediately and do the final bio_put() after every previously submitted
>   chained bio completes.

I feel this way is fragile:

1) user sends KILL signal

2) discard API returns

3) submitted discard requests are still run in background, and there
can be thousands of such bios

4) what if application or FS code(such as meta) starts to write data to
the discard range?

> 
>  block/blk-lib.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/block/blk-lib.c b/block/blk-lib.c
> index e59c3069e8351..88f6a4aebe75e 100644
> --- a/block/blk-lib.c
> +++ b/block/blk-lib.c
> @@ -35,6 +35,17 @@ static sector_t bio_discard_limit(struct block_device *bdev, sector_t sector)
>  	return round_down(UINT_MAX, discard_granularity) >> SECTOR_SHIFT;
>  }
>  
> +static void abort_bio_endio(struct bio *bio)
> +{
> +	bio_put(bio);
> +}
> +
> +static void abort_bio(struct bio *bio)
> +{
> +	bio->bi_end_io = abort_bio_endio;
> +	bio_endio(bio);
> +}
> +
>  int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
>  		sector_t nr_sects, gfp_t gfp_mask, struct bio **biop)
>  {
> @@ -77,6 +88,10 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
>  		 * is disabled.
>  		 */
>  		cond_resched();
> +		if (fatal_signal_pending(current)) {
> +			abort_bio(bio);
> +			return -EINTR;
> +		}
>  	}
>  
>  	*biop = bio;
> @@ -146,6 +161,10 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
>  			nr_sects = 0;
>  		}
>  		cond_resched();
> +		if (fatal_signal_pending(current)) {
> +			abort_bio(bio);
> +			return -EINTR;
> +		}
>  	}
>  
>  	*biop = bio;
> @@ -190,6 +209,10 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev,
>  				break;
>  		}
>  		cond_resched();
> +		if (fatal_signal_pending(current)) {
> +			abort_bio(bio);
> +			return -EINTR;
> +		}
>  	}
>  
>  	*biop = bio;
> @@ -337,6 +360,11 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector,
>  			break;
>  		}
>  		cond_resched();
> +		if (fatal_signal_pending(current)) {
> +			abort_bio(bio);
> +			ret = -EINTR;
> +			bio = NULL;
> +		}

The handling for blkdev_issue_secure_erase is different with others, and
actually it doesn't return immediately, care to add comment?


Thanks,
Ming


  reply	other threads:[~2024-02-22  4:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-21 22:20 [PATCHv2] blk-lib: check for kill signal Keith Busch
2024-02-22  4:02 ` Ming Lei [this message]
2024-02-22  4:18   ` Keith Busch
2024-02-22 10:22     ` Chaitanya Kulkarni
  -- strict thread matches above, loose matches on Subject: below --
2024-02-22 19:18 Keith Busch
2024-02-22 19:20 ` Keith Busch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZdbHXDCquO23rbJk@fedora \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.org \
    --cc=chaitanyak@nvidia.com \
    --cc=conradmeyer@meta.com \
    --cc=kbusch@kernel.org \
    --cc=kbusch@meta.com \
    --cc=linux-block@vger.kernel.org \
    --cc=nilay@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox