Skip to contentSkip to conversation

block: Make blkdev_issue_discard() interruptible

PATCH New Lukas Czerner 2 participants 4 messages Oct 21, 2010 – Oct 22, 2010 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: Make blkdev_issue_discard() interruptible

Since the discard may take quite long time, especially with really big extents (like the whole device for example), it would be nice to give to users the opportunity to abort it. This is especially useful for mkfs, when user can not know in advance how long it will take.

In conjunction with mke2fs patch "Inform user about ongoing discard" it gives the user all the comfort of being informed about discard and being able to abort the operation.

---
 block/blk-lib.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
block/blk-lib.c +5 -0
index c392029..204839b 100644
@@ -101,6 +101,11 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 		else if (!bio_flagged(bio, BIO_UPTODATE))
 			ret = -EIO;
 		bio_put(bio);
+
+		if (fatal_signal_pending(current)) {
+			ret = -ERESTARTSYS;
+			break;
+		}
 	}
 
 	return ret;
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 1/1 block: Make blkdev_issue_discard() interruptible

Since the discard may take quite long time, especially with really big extents (like the whole device for example), it would be nice to give to users the opportunity to abort it. This is especially useful for mkfs, when user can not know in advance how long it will take.

In conjunction with mke2fs patch "Inform user about ongoing discard" it gives the user all the comfort of being informed about discard and being able to abort the operation.

---
 block/blk-lib.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
block/blk-lib.c +3 -0
index 1a320d2..db44671 100644
@@ -91,6 +91,9 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 		bio_get(bio);
 		submit_bio(type, bio);
 
+		if (unlikely(fatal_signal_pending(current)))
+			ret = -ERESTARTSYS;
+
 		wait_for_completion(&wait);
 
 		if (bio_flagged(bio, BIO_EOPNOTSUPP))
Signature · 1 line
1.7.2.3
#2 lore raw
Quoted 8 lines · Lukas Czerner

Since the discard may take quite long time, especially with really big extents (like the whole device for example), it would be nice to give to users the opportunity to abort it. This is especially useful for mkfs, when user can not know in advance how long it will take.

In conjunction with mke2fs patch "Inform user about ongoing discard" it gives the user all the comfort of being informed about discard and being able to abort the operation.

For others reviewing, this is against the block tree's for-next branch.

Quoted 9 lines
---
 block/blk-lib.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
block/blk-lib.c +0 -0
index 1a320d2..db44671 100644

block/blk-lib.c int blkdev_issue_discard(struct block_device *bdev, sector_t sector, · line 99

Quoted 9 lines
block/blk-lib.c +3 -0
@@ -91,6 +91,9 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 		bio_get(bio);
 		submit_bio(type, bio);
 
+		if (unlikely(fatal_signal_pending(current)))
+			ret = -ERESTARTSYS;
+
 		wait_for_completion(&wait);
 
 		if (bio_flagged(bio, BIO_EOPNOTSUPP))

Given that you're still doing the wait_for_completion, wouldn't it be better to check for a pending signal after that?

What testing did you perform?

Cheers,
Jeff

#3 lore raw

PATCH 1/1 block: Make blkdev_issue_discard() interruptible

Since the discard may take quite long time, especially with really big extents (like the whole device for example), it would be nice to give to users the opportunity to abort it. This is especially useful for mkfs, when user can not know in advance how long it will take.

In conjunction with mke2fs patch "Inform user about ongoing discard" it gives the user all the comfort of being informed about discard and being able to abort the operation.

It has been tested on SSD device where mkfs.ext4 without -K takes rally long due to discarding whole device. With this patch I am able to successfully terminate that with ctrl+c. Aside that discard functionality remains unchanged.

---
 block/blk-lib.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
block/blk-lib.c +3 -0
index c392029..54994e7 100644
@@ -101,6 +101,9 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 		else if (!bio_flagged(bio, BIO_UPTODATE))
 			ret = -EIO;
 		bio_put(bio);
+
+		if (unlikely(fatal_signal_pending(current)))
+			ret = -ERESTARTSYS;
 	}
 
 	return ret;
Signature · 1 line
1.7.2.3