All of lore.kernel.org
 help / color / mirror / Atom feed
* resend: zeroout fixes
@ 2016-07-19  9:23 Christoph Hellwig
  2016-07-19  9:23 ` [PATCH 1/2] block: introduce BLKDEV_DISCARD_ZERO to fix zeroout Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Christoph Hellwig @ 2016-07-19  9:23 UTC (permalink / raw)
  To: axboe; +Cc: shli, martin.petersen, snitzer, sitsofe, linux-block

The first one is a repost of my BLKDEV_DISCARD_ZERO with the spelling
fixes suggest from Martin, the second one just drops the -EOPNOTSUPP
special casing in blkdev_issue_write_same.

Note that the patches are against the block for-next tree, and
unfortunately we have diverged significantly from 4.7 in this area:
4.7 has the missing bio_put for the sumbmit_bio_wait callers, and
4.8 has the various req_op changes, including a new calling
convention for __blkdev_issue_zeroout.  I'm not sure how to best
sort this mess out, but I really think we need the bio_put in the
for-4.8 tree as well, and we should probably bring the changed
__blkdev_issue_discard calling convention into 4.7 as well.
Suggestion for how to best handle this?

Compared to the last posting on June 24th this just adds the Reviewed-by:
tags from Martin.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] block: introduce BLKDEV_DISCARD_ZERO to fix zeroout
  2016-07-19  9:23 resend: zeroout fixes Christoph Hellwig
@ 2016-07-19  9:23 ` Christoph Hellwig
  2016-07-19  9:23 ` [PATCH 2/2] block: don't ignore -EOPNOTSUPP blkdev_issue_write_same Christoph Hellwig
  2016-07-20 23:36 ` resend: zeroout fixes Jens Axboe
  2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2016-07-19  9:23 UTC (permalink / raw)
  To: axboe; +Cc: shli, martin.petersen, snitzer, sitsofe, linux-block

Currently blkdev_issue_zeroout cascades down from discards (if the driver
guarantees that discards zero data), to WRITE SAME and then to a loop
writing zeroes.  Unfortunately we ignore run-time EOPNOTSUPP errors in the
block layer blkdev_issue_discard helper to work around DM volumes that
may have mixed discard support underneath.

This patch intoroduces a new BLKDEV_DISCARD_ZERO flag to
blkdev_issue_discard that indicates we are called for zeroing operation.
This allows both to ignore the EOPNOTSUPP hack and actually consolidating
the discard_zeroes_data check into the function.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
---
 block/blk-lib.c        | 17 +++++++++++------
 include/linux/blkdev.h |  4 +++-
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/block/blk-lib.c b/block/blk-lib.c
index 78626c2..45b35b1 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -36,12 +36,17 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 		return -ENXIO;
 
 	if (flags & BLKDEV_DISCARD_SECURE) {
+		if (flags & BLKDEV_DISCARD_ZERO)
+			return -EOPNOTSUPP;
 		if (!blk_queue_secure_erase(q))
 			return -EOPNOTSUPP;
 		op = REQ_OP_SECURE_ERASE;
 	} else {
 		if (!blk_queue_discard(q))
 			return -EOPNOTSUPP;
+		if ((flags & BLKDEV_DISCARD_ZERO) &&
+		    !q->limits.discard_zeroes_data)
+			return -EOPNOTSUPP;
 		op = REQ_OP_DISCARD;
 	}
 
@@ -116,7 +121,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 			&bio);
 	if (!ret && bio) {
 		ret = submit_bio_wait(bio);
-		if (ret == -EOPNOTSUPP)
+		if (ret == -EOPNOTSUPP && !(flags & BLKDEV_DISCARD_ZERO))
 			ret = 0;
 	}
 	blk_finish_plug(&plug);
@@ -241,11 +246,11 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
 int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
 			 sector_t nr_sects, gfp_t gfp_mask, bool discard)
 {
-	struct request_queue *q = bdev_get_queue(bdev);
-
-	if (discard && blk_queue_discard(q) && q->limits.discard_zeroes_data &&
-	    blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, 0) == 0)
-		return 0;
+	if (discard) {
+		if (!blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask,
+				BLKDEV_DISCARD_ZERO))
+			return 0;
+	}
 
 	if (bdev_write_same(bdev) &&
 	    blkdev_issue_write_same(bdev, sector, nr_sects, gfp_mask,
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 9ae49cc..03fa3d1 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1136,7 +1136,9 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt,
 	return bqt->tag_index[tag];
 }
 
-#define BLKDEV_DISCARD_SECURE  0x01    /* secure discard */
+
+#define BLKDEV_DISCARD_SECURE	(1 << 0)	/* issue a secure erase */
+#define BLKDEV_DISCARD_ZERO	(1 << 1)	/* must reliably zero data */
 
 extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *);
 extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] block: don't ignore -EOPNOTSUPP blkdev_issue_write_same
  2016-07-19  9:23 resend: zeroout fixes Christoph Hellwig
  2016-07-19  9:23 ` [PATCH 1/2] block: introduce BLKDEV_DISCARD_ZERO to fix zeroout Christoph Hellwig
@ 2016-07-19  9:23 ` Christoph Hellwig
  2016-07-20 23:36 ` resend: zeroout fixes Jens Axboe
  2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2016-07-19  9:23 UTC (permalink / raw)
  To: axboe; +Cc: shli, martin.petersen, snitzer, sitsofe, linux-block

WRITE SAME is a data integrity operation and we can't simply ignore
errors.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
---
 block/blk-lib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/blk-lib.c b/block/blk-lib.c
index 45b35b1..e371f83 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -178,7 +178,7 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
 
 	if (bio)
 		ret = submit_bio_wait(bio);
-	return ret != -EOPNOTSUPP ? ret : 0;
+	return ret;
 }
 EXPORT_SYMBOL(blkdev_issue_write_same);
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: resend: zeroout fixes
  2016-07-19  9:23 resend: zeroout fixes Christoph Hellwig
  2016-07-19  9:23 ` [PATCH 1/2] block: introduce BLKDEV_DISCARD_ZERO to fix zeroout Christoph Hellwig
  2016-07-19  9:23 ` [PATCH 2/2] block: don't ignore -EOPNOTSUPP blkdev_issue_write_same Christoph Hellwig
@ 2016-07-20 23:36 ` Jens Axboe
  2016-07-21  5:47   ` Christoph Hellwig
  2 siblings, 1 reply; 5+ messages in thread
From: Jens Axboe @ 2016-07-20 23:36 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: shli, martin.petersen, snitzer, sitsofe, linux-block

On 07/19/2016 03:23 AM, Christoph Hellwig wrote:
> The first one is a repost of my BLKDEV_DISCARD_ZERO with the spelling
> fixes suggest from Martin, the second one just drops the -EOPNOTSUPP
> special casing in blkdev_issue_write_same.
>
> Note that the patches are against the block for-next tree, and
> unfortunately we have diverged significantly from 4.7 in this area:
> 4.7 has the missing bio_put for the sumbmit_bio_wait callers, and
> 4.8 has the various req_op changes, including a new calling
> convention for __blkdev_issue_zeroout.  I'm not sure how to best
> sort this mess out, but I really think we need the bio_put in the
> for-4.8 tree as well, and we should probably bring the changed
> __blkdev_issue_discard calling convention into 4.7 as well.
> Suggestion for how to best handle this?

I think we should leave 4.7 as-is. The put issue being fixed is the most 
important one, so just roll a separate 4.8 patch for that.

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: resend: zeroout fixes
  2016-07-20 23:36 ` resend: zeroout fixes Jens Axboe
@ 2016-07-21  5:47   ` Christoph Hellwig
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2016-07-21  5:47 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Christoph Hellwig, shli, martin.petersen, snitzer, sitsofe, linux-block

On Wed, Jul 20, 2016 at 05:36:32PM -0600, Jens Axboe wrote:
> I think we should leave 4.7 as-is. The put issue being fixed is the most 
> important one, so just roll a separate 4.8 patch for that.

Ok, in that case just merge this series as-is for now.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-07-21  5:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-19  9:23 resend: zeroout fixes Christoph Hellwig
2016-07-19  9:23 ` [PATCH 1/2] block: introduce BLKDEV_DISCARD_ZERO to fix zeroout Christoph Hellwig
2016-07-19  9:23 ` [PATCH 2/2] block: don't ignore -EOPNOTSUPP blkdev_issue_write_same Christoph Hellwig
2016-07-20 23:36 ` resend: zeroout fixes Jens Axboe
2016-07-21  5:47   ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.