From patchwork Thu Feb 18 05:45:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darrick Wong X-Patchwork-Id: 584521 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 839B8140273 for ; Thu, 18 Feb 2016 16:53:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756673AbcBRFxM (ORCPT ); Thu, 18 Feb 2016 00:53:12 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:28325 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1425151AbcBRFqD (ORCPT ); Thu, 18 Feb 2016 00:46:03 -0500 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u1I5jxMW009086 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 18 Feb 2016 05:46:00 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u1I5jxKq007483 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Thu, 18 Feb 2016 05:45:59 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u1I5jwkG003852; Thu, 18 Feb 2016 05:45:59 GMT Received: from localhost (/24.21.154.84) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 17 Feb 2016 21:45:58 -0800 Date: Wed, 17 Feb 2016 21:45:57 -0800 From: "Darrick J. Wong" To: "Theodore Ts'o" Cc: linux-ext4 Subject: [PATCH] ext4: use directio end_io error status to finish unwritten aio dio correctly Message-ID: <20160218054557.GH6338@birch.djwong.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 --- fs/ext4/ext4.h | 2 ++ fs/ext4/inode.c | 23 +++++++++++++++-------- fs/ext4/page-io.c | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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;