[PATCHv2] blk-lib: check for kill signal

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Keith Busch <kbusch@xxxxxxxxxx>

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@xxxxxxxxxx>
Cc: Nilay Shroff <nilay@xxxxxxxxxxxxx>
Cc: Chaitanya Kulkarni <chaitanyak@xxxxxxxxxx>
Reported-by: Conrad Meyer <conradmeyer@xxxxxxxx>
Signed-off-by: Keith Busch <kbusch@xxxxxxxxxx>
---
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.

 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;
+		}
 	}
 	blk_finish_plug(&plug);
 
-- 
2.34.1






[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux