Commit 8a08c5fd authored by Keith Busch's avatar Keith Busch Committed by Jens Axboe

blk-lib: check for kill signal

Some of these block operations can access a significant capacity and
take longer than the user expected. A user may change their mind about
wanting to run that command and attempt to kill the process and do
something else with their device. But since the task is uninterruptable,
they have to wait for it to finish, which could be many hours.

Check for a fatal signal at each iteration so the user doesn't have to
wait for their regretted operation to complete naturally.
Reported-by: default avatarConrad Meyer <conradmeyer@meta.com>
Tested-by: default avatarNilay Shroff <nilay@linux.ibm.com>
Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
Link: https://lore.kernel.org/r/20240223155910.3622666-5-kbusch@meta.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 0eb4db47
...@@ -35,6 +35,26 @@ static sector_t bio_discard_limit(struct block_device *bdev, sector_t sector) ...@@ -35,6 +35,26 @@ static sector_t bio_discard_limit(struct block_device *bdev, sector_t sector)
return round_down(UINT_MAX, discard_granularity) >> SECTOR_SHIFT; return round_down(UINT_MAX, discard_granularity) >> SECTOR_SHIFT;
} }
static void await_bio_endio(struct bio *bio)
{
complete(bio->bi_private);
bio_put(bio);
}
/*
* await_bio_chain - ends @bio and waits for every chained bio to complete
*/
static void await_bio_chain(struct bio *bio)
{
DECLARE_COMPLETION_ONSTACK_MAP(done,
bio->bi_bdev->bd_disk->lockdep_map);
bio->bi_private = &done;
bio->bi_end_io = await_bio_endio;
bio_endio(bio);
blk_wait_io(&done);
}
int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
sector_t nr_sects, gfp_t gfp_mask, struct bio **biop) sector_t nr_sects, gfp_t gfp_mask, struct bio **biop)
{ {
...@@ -77,6 +97,10 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, ...@@ -77,6 +97,10 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
* is disabled. * is disabled.
*/ */
cond_resched(); cond_resched();
if (fatal_signal_pending(current)) {
await_bio_chain(bio);
return -EINTR;
}
} }
*biop = bio; *biop = bio;
...@@ -143,6 +167,10 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev, ...@@ -143,6 +167,10 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
nr_sects -= len; nr_sects -= len;
sector += len; sector += len;
cond_resched(); cond_resched();
if (fatal_signal_pending(current)) {
await_bio_chain(bio);
return -EINTR;
}
} }
*biop = bio; *biop = bio;
...@@ -187,6 +215,10 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev, ...@@ -187,6 +215,10 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev,
break; break;
} }
cond_resched(); cond_resched();
if (fatal_signal_pending(current)) {
await_bio_chain(bio);
return -EINTR;
}
} }
*biop = bio; *biop = bio;
...@@ -277,7 +309,7 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, ...@@ -277,7 +309,7 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
bio_put(bio); bio_put(bio);
} }
blk_finish_plug(&plug); blk_finish_plug(&plug);
if (ret && try_write_zeroes) { if (ret && ret != -EINTR && try_write_zeroes) {
if (!(flags & BLKDEV_ZERO_NOFALLBACK)) { if (!(flags & BLKDEV_ZERO_NOFALLBACK)) {
try_write_zeroes = false; try_write_zeroes = false;
goto retry; goto retry;
...@@ -329,6 +361,12 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector, ...@@ -329,6 +361,12 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector,
sector += len; sector += len;
nr_sects -= len; nr_sects -= len;
cond_resched(); cond_resched();
if (fatal_signal_pending(current)) {
await_bio_chain(bio);
ret = -EINTR;
bio = NULL;
break;
}
} }
if (bio) { if (bio) {
ret = submit_bio_wait(bio); ret = submit_bio_wait(bio);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment