Re: [PATCH 10/11] fs, block: propagate REQ_FLUSH/FUA interface to upper layers

Previous thread: [PATCH v2] MD: raid, fix BUG caused by flags handling by Jiri Slaby on Thursday, August 12, 2010 - 5:31 am. (3 messages)

Next thread: [PATCH 11/11] block: use REQ_FLUSH in blkdev_issue_flush() by Tejun Heo on Thursday, August 12, 2010 - 5:41 am. (1 message)
From: Tejun Heo
Date: Thursday, August 12, 2010 - 5:41 am

Propagate deprecation of REQ_HARDBARRIER and new REQ_FLUSH/FUA
interface to upper layers.

* WRITE_BARRIER is marked deprecated and WRITE_FLUSH, WRITE_FUA and
  WRITE_FLUSH_FUA are added.

* REQ_COMMON_MASK now includes REQ_FLUSH | REQ_FUA so that they are
  copied from bio to request.

* BH_Ordered is marked deprecated and BH_Flush and BH_FUA are added.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
---
 fs/buffer.c                 |   27 ++++++++++++++++-----------
 include/linux/blk_types.h   |    2 +-
 include/linux/buffer_head.h |    8 ++++++--
 include/linux/fs.h          |   20 +++++++++++++-------
 4 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index d54812b..ec32fbb 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -3019,18 +3019,23 @@ int submit_bh(int rw, struct buffer_head * bh)
 	BUG_ON(buffer_delay(bh));
 	BUG_ON(buffer_unwritten(bh));
 
-	/*
-	 * Mask in barrier bit for a write (could be either a WRITE or a
-	 * WRITE_SYNC
-	 */
-	if (buffer_ordered(bh) && (rw & WRITE))
-		rw |= WRITE_BARRIER;
+	if (rw & WRITE) {
+		/* ordered is deprecated, will be removed */
+		if (buffer_ordered(bh))
+			rw |= WRITE_BARRIER;
 
-	/*
-	 * Only clear out a write error when rewriting
-	 */
-	if (test_set_buffer_req(bh) && (rw & WRITE))
-		clear_buffer_write_io_error(bh);
+		if (buffer_flush(bh))
+			rw |= WRITE_FLUSH;
+
+		if (buffer_fua(bh))
+			rw |= WRITE_FUA;
+
+		/*
+		 * Only clear out a write error when rewriting
+		 */
+		if (test_set_buffer_req(bh))
+			clear_buffer_write_io_error(bh);
+	}
 
 	/*
 	 * from here on down, it's all bio -- do the initial mapping,
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 8e9887d..6609fc0 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -164,7 +164,7 @@ enum rq_flag_bits {
 	(REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER)
 #define REQ_COMMON_MASK \
 	(REQ_WRITE ...
From: Jan Kara
Date: Thursday, August 12, 2010 - 2:24 pm

Deprecating BH_Ordered is fine but I wouldn't introduce new BH flags for
this. BH flags should be used for buffer state, not for encoding how the
buffer should be written (there were actually bugs in the past because of
this). Being able to set proper flags when calling submit_bh() in the rw
parameter is enough.

-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR
--

From: Tejun Heo
Date: Friday, August 13, 2010 - 12:19 am

Hello, Jan.


Ah, okay, I was just trying to match the BH_Ordered usage but you're
saying just requiring submit_bh() users to specify appropriate REQ_*
(or WRITE_*) in @rw is okay, right?  I'll drop the bh part then.

Thanks.

-- 
tejun
--

From: Christoph Hellwig
Date: Friday, August 13, 2010 - 12:47 am

FYI: I've already sent a patch to kill BH_Ordered, hopefully Al will
still push it in this merge window.

--

From: Tejun Heo
Date: Monday, August 16, 2010 - 9:33 am

Propagate deprecation of REQ_HARDBARRIER and new REQ_FLUSH/FUA
interface to upper layers.

* WRITE_BARRIER is marked deprecated and WRITE_FLUSH, WRITE_FUA and
  WRITE_FLUSH_FUA are added.

* REQ_COMMON_MASK now includes REQ_FLUSH | REQ_FUA so that they are
  copied from bio to request.

* BH_Ordered and BH_Eopnotsupp are marked deprecated.  BH_Flush/FUA
  are _NOT_ added as they can and should be specified when calling
  submit_bh() as @rw parameter as suggested by Jan Kara.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Jan Kara <jack@suse.cz>
---
Dropped BH_Flush/FUA as suggested.

Thanks.

 include/linux/blk_types.h   |    2 +-
 include/linux/buffer_head.h |    4 ++--
 include/linux/fs.h          |   20 +++++++++++++-------
 3 files changed, 16 insertions(+), 10 deletions(-)

Index: block/include/linux/fs.h
===================================================================
--- block.orig/include/linux/fs.h
+++ block/include/linux/fs.h
@@ -138,13 +138,13 @@ struct inodes_stat_t {
  * SWRITE_SYNC
  * SWRITE_SYNC_PLUG	Like WRITE_SYNC/WRITE_SYNC_PLUG, but locks the buffer.
  *			See SWRITE.
- * WRITE_BARRIER	Like WRITE_SYNC, but tells the block layer that all
- *			previously submitted writes must be safely on storage
- *			before this one is started. Also guarantees that when
- *			this write is complete, it itself is also safely on
- *			storage. Prevents reordering of writes on both sides
- *			of this IO.
- *
+ * WRITE_BARRIER	DEPRECATED. Always fails. Use FLUSH/FUA instead.
+ * WRITE_FLUSH		Like WRITE_SYNC but with preceding cache flush.
+ * WRITE_FUA		Like WRITE_SYNC but data is guaranteed to be on
+ *			non-volatile media on completion.
+ * WRITE_FLUSH_FUA	Combination of WRITE_FLUSH and FUA.  The IO is preceded
+ *			by a cache flush and data is guaranteed to be on
+ *			non-volatile media on completion.
  */
 #define RW_MASK			REQ_WRITE
 #define RWA_MASK		REQ_RAHEAD
@@ -162,6 +162,12 @@ struct inodes_stat_t {
 ...
Previous thread: [PATCH v2] MD: raid, fix BUG caused by flags handling by Jiri Slaby on Thursday, August 12, 2010 - 5:31 am. (3 messages)

Next thread: [PATCH 11/11] block: use REQ_FLUSH in blkdev_issue_flush() by Tejun Heo on Thursday, August 12, 2010 - 5:41 am. (1 message)