linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: "Theodore Ts'o" <tytso@mit.edu>
Cc: linux-ext4 <linux-ext4@vger.kernel.org>
Subject: [PATCH] ext4: use directio end_io error status to finish unwritten aio dio correctly
Date: Wed, 17 Feb 2016 21:45:57 -0800	[thread overview]
Message-ID: <20160218054557.GH6338@birch.djwong.org> (raw)

Use the new error code passed to the directio end_io function to
decide if we're going to remap the blocks.  If an IO error happened
during an AIO DIO, we must skip the unwritten extent conversion to
avoid exposing stale blocks.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/ext4/ext4.h    |    2 ++
 fs/ext4/inode.c   |   23 +++++++++++++++--------
 fs/ext4/page-io.c |    2 +-
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 0662b28..363c701 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1523,6 +1523,8 @@ static inline void ext4_inode_aio_set(struct inode *inode, ext4_io_end_t *io)
 	inode->i_private = io;
 }
 
+extern void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end);
+
 /*
  * Inode dynamic state flags
  */
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 9db04dd..a302094 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3166,9 +3166,6 @@ static int ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
 {
         ext4_io_end_t *io_end = iocb->private;
 
-	if (size <= 0)
-		return 0;
-
 	/* if not async direct IO just return */
 	if (!io_end)
 		return 0;
@@ -3179,11 +3176,21 @@ static int ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
 		  size);
 
 	iocb->private = NULL;
-	io_end->offset = offset;
-	io_end->size = size;
-	ext4_put_io_end(io_end);
-
-	return 0;
+	/*
+	 * If an IO error happened, skip the unwritten extent conversion
+	 * to avoid disclosing old disk contents.
+	 */
+	if (size <= 0) {
+		if (io_end->flag & EXT4_IO_END_UNWRITTEN) {
+			ext4_clear_io_unwritten_flag(io_end);
+			if (ext4_handle_valid(io_end->handle))
+				ext4_journal_stop(io_end->handle);
+		}
+	} else {
+		io_end->offset = offset;
+		io_end->size = size;
+	}
+	return ext4_put_io_end(io_end);
 }
 
 /*
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 090b349..a0bc182b 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -139,7 +139,7 @@ static void ext4_release_io_end(ext4_io_end_t *io_end)
 	kmem_cache_free(io_end_cachep, io_end);
 }
 
-static void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end)
+void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end)
 {
 	struct inode *inode = io_end->inode;
 

             reply	other threads:[~2016-02-18  5:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-18  5:45 Darrick J. Wong [this message]
2016-02-18  6:01 ` [PATCH] ext4: use directio end_io error status to finish unwritten aio dio correctly Christoph Hellwig
2016-02-18 21:30   ` Jan Kara
2016-02-18 22:02   ` Dave Chinner
2016-02-19 13:18     ` Jan Kara
2016-02-19 15:15       ` Theodore Ts'o
2016-02-21  6:28       ` Dave Chinner
2016-02-22  8:19         ` Jan Kara
2016-02-22 20:11           ` Darrick J. Wong
2016-02-22  8:56       ` Christoph Hellwig
2016-02-29  7:03       ` Dave Chinner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160218054557.GH6338@birch.djwong.org \
    --to=darrick.wong@oracle.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).