linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: use directio end_io error status to finish unwritten aio dio correctly
@ 2016-02-18  5:45 Darrick J. Wong
  2016-02-18  6:01 ` Christoph Hellwig
  0 siblings, 1 reply; 11+ messages in thread
From: Darrick J. Wong @ 2016-02-18  5:45 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: linux-ext4

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;
 

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

end of thread, other threads:[~2016-02-29  7:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-18  5:45 [PATCH] ext4: use directio end_io error status to finish unwritten aio dio correctly Darrick J. Wong
2016-02-18  6:01 ` 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

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).