Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp2067986ybe; Thu, 12 Sep 2019 04:07:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyGAufZVvw6pQy6wfm/5uiv+KStbQwYM24R72VBVs3s28F+NDOutj8HUH7XO0h7Gs+x67P8 X-Received: by 2002:a50:9e08:: with SMTP id z8mr42197467ede.305.1568286463322; Thu, 12 Sep 2019 04:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568286463; cv=none; d=google.com; s=arc-20160816; b=f6M9G+9ml2i+7MvSXt3DFPYYpNEhwQ4kp9kUMLZiBniSaBdq2L9RNV7XURMDrGI9G/ i8Kr/7JDxZBb8dCgvWVjAgWqcPHY/2PjQ1gr68xq4Jqs+bj75xWAGz2KcZjm84ZP6RyM HUJFREmHanfr0+bWS2SkOb78C2a2kFysVKpUeFABACIgyYH2DUlGJTz8S3RbmdaltTYM g9kL1kj3Ch9GYNL8g8DMV36HubOpJdoJSeByRnkVkUS0nbzuDjUKB9lyeiOb3bFmpLlV VUri8YHty4X9RhMN1C38D7UlLlez7iXHJvo4hihfQpI/B87xw9jAK7l055+QDyhaLqK2 X62Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gWhEv95xTEIL42qPF3+CSeyG/Xs7G/CybwgHcd2mrXY=; b=TVaKGyWXxBUWE5OkY7ibNN36DgAhafCFb662AokY2vU9FZoHqEPbXUmHHHNva7mKET P/rEu/G4zTjW94r3yow4HF4oYtLdpy+r0ur7/kPGrBeuzos94yUCWQXJkE8xaor2j3ED ElrF7vgid0Hr8J2XHqIfctXaDUsFVf2BxDPGcAHCC8AiX/STpR48R9pMgCauczilzm6o xQenKGa/Y2T5SuidPljCVAF8OFOKYFN7KW0Ur8ElFRBmn/Fm2+TzvWjOwM5CTyVy5UW2 NwV3UnJg3WvmUuUX/kR3gp0kbI8/pYrrHF1iKN1hAPi/66ykMwMcewU6QedFfSqX+gdi pZdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=Vsnv9GpP; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay3si12756962ejb.149.2019.09.12.04.07.18; Thu, 12 Sep 2019 04:07:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=Vsnv9GpP; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731320AbfILLDx (ORCPT + 99 others); Thu, 12 Sep 2019 07:03:53 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:37266 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730268AbfILLDw (ORCPT ); Thu, 12 Sep 2019 07:03:52 -0400 Received: by mail-pf1-f196.google.com with SMTP id y5so13031622pfo.4 for ; Thu, 12 Sep 2019 04:03:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mbobrowski-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=gWhEv95xTEIL42qPF3+CSeyG/Xs7G/CybwgHcd2mrXY=; b=Vsnv9GpP/UwFIuF1xKQ1ymfWv4uzJy++3sv+5fdk76QqcRzf9lyyN6naP60MS7Bsuo qANymsS6MIzGRxEsVIzIZYhj9h1hwplWnVrxDyN5m5Zwd+0ksXYwlydloFFbK2Mkm3SZ xwTtkUApbqn/nkubInIphQb1goysnPXrkeWScszARjIf4vUHVIJfMPCfbRnEhvCFP6UM QidOAQJgxDipAwRqwINCbG8y4d34iQ+8wD5hVQaz+IQxpxf6Hx/Oqwg5lWUch1vPX8Fs XuSQ1FZIalNZcE+XjZioGEH+X9ZdHIe6WY/3C3sNk49A2uraGYFOtAm2b7H6Wdlv2ieL hvSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=gWhEv95xTEIL42qPF3+CSeyG/Xs7G/CybwgHcd2mrXY=; b=VWou2dMeKodm3kRMX1SoIgtG/tzxhhVIrtI7mNCcJQjNqPb1rVXqQO62adnJ6NJwZX doDMFkCtDCQUsxEvzfQZewojVP0W3lHYEGdQfMwmLu5e5QEjgYrRl6b+9tIVY+OUv7dF rkiELq0lPJ7uWu3nclvHJ3RpuVbpmj6rXM5RVZj3mKE5aSkljmanMQ103rPHrn4Hw4Wd 7EIBNvEk9LW8drErqx2tVFcGjA4+/CnEayxmn3QKjjiv1yr4+iFQ4iVIzsKFqlCQ/8MZ 7q3xOeZRJYnpWv1KfniKsGU6vEHZXhMyRv9kioVhY37AsMxyYz+3RrTWFrTBTSuhsEWT 2r/g== X-Gm-Message-State: APjAAAXMwE7iFc7WEq2Mk4QTs8Y4HQ6S7WmYTSPtbCXko2hGW+GjbXTI Ph3MpKlB/NpyFT0sVp4XGHoz X-Received: by 2002:a63:d64f:: with SMTP id d15mr38390739pgj.345.1568286230822; Thu, 12 Sep 2019 04:03:50 -0700 (PDT) Received: from poseidon.bobrowski.net ([114.78.226.167]) by smtp.gmail.com with ESMTPSA id c125sm31171591pfa.107.2019.09.12.04.03.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2019 04:03:50 -0700 (PDT) Date: Thu, 12 Sep 2019 21:03:44 +1000 From: Matthew Bobrowski To: tytso@mit.edu, jack@suse.cz, adilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, david@fromorbit.com, hch@infradead.org, darrick.wong@oracle.com Subject: [PATCH v3 1/6] ext4: introduce direct IO read path using iomap infrastructure Message-ID: <532d8deae8e522a27539470457eec6b1a5683127.1568282664.git.mbobrowski@mbobrowski.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org This patch introduces a new direct IO read path that makes use of the iomap infrastructure. The new function ext4_dio_read_iter() is responsible for calling into the iomap infrastructure via iomap_dio_rw(). If the inode in question does not pass preliminary checks in ext4_dio_checks(), then we simply fallback to buffered IO and take that path to fulfil the request. It's imperative that we drop the IOCB_DIRECT flag from iocb->ki_flags in order to prevent generic_file_read_iter() from trying to take the direct IO code path again. Signed-off-by: Matthew Bobrowski Reviewed-by: Ritesh Harjani --- fs/ext4/file.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 70b0438dbc94..e52e3928dc25 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -34,6 +34,53 @@ #include "xattr.h" #include "acl.h" +static bool ext4_dio_checks(struct inode *inode) +{ +#if IS_ENABLED(CONFIG_FS_ENCRYPTION) + if (IS_ENCRYPTED(inode)) + return false; +#endif + if (ext4_should_journal_data(inode)) + return false; + if (ext4_has_inline_data(inode)) + return false; + return true; +} + +static ssize_t ext4_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) +{ + ssize_t ret; + struct inode *inode = file_inode(iocb->ki_filp); + + /* + * Get exclusion from truncate and other inode operations. + */ + if (!inode_trylock_shared(inode)) { + if (iocb->ki_flags & IOCB_NOWAIT) + return -EAGAIN; + inode_lock_shared(inode); + } + + if (!ext4_dio_checks(inode)) { + inode_unlock_shared(inode); + /* + * Fallback to buffered IO if the operation being + * performed on the inode is not supported by direct + * IO. The IOCB_DIRECT flag flags needs to be cleared + * here to ensure that the direct IO code path within + * generic_file_read_iter() is not taken again. + */ + iocb->ki_flags &= ~IOCB_DIRECT; + return generic_file_read_iter(iocb, to); + } + + ret = iomap_dio_rw(iocb, to, &ext4_iomap_ops, NULL); + inode_unlock_shared(inode); + + file_accessed(iocb->ki_filp); + return ret; +} + #ifdef CONFIG_FS_DAX static ssize_t ext4_dax_read_iter(struct kiocb *iocb, struct iov_iter *to) { @@ -64,16 +111,19 @@ static ssize_t ext4_dax_read_iter(struct kiocb *iocb, struct iov_iter *to) static ssize_t ext4_file_read_iter(struct kiocb *iocb, struct iov_iter *to) { - if (unlikely(ext4_forced_shutdown(EXT4_SB(file_inode(iocb->ki_filp)->i_sb)))) + struct inode *inode = file_inode(iocb->ki_filp); + + if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) return -EIO; if (!iov_iter_count(to)) return 0; /* skip atime */ -#ifdef CONFIG_FS_DAX - if (IS_DAX(file_inode(iocb->ki_filp))) + if (IS_DAX(inode)) return ext4_dax_read_iter(iocb, to); -#endif + + if (iocb->ki_flags & IOCB_DIRECT) + return ext4_dio_read_iter(iocb, to); return generic_file_read_iter(iocb, to); } -- 2.20.1