Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3440490ybg; Mon, 28 Oct 2019 12:53:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqwtITnMbYm6lGvKLiEt0iho2/yOtnOL9Uo+ZfbwrPFWNWRpZ5aWDyoHr4Isa0K/U2bcQEh5 X-Received: by 2002:a17:906:76c3:: with SMTP id q3mr8359418ejn.199.1572292382782; Mon, 28 Oct 2019 12:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572292382; cv=none; d=google.com; s=arc-20160816; b=oJzAKbUzUE7OYZC3E1QjRtSXIxDnVH6O1HDud0cbRWsMt7WlIihowZQVHA6+chEoPi lIIWWN7CqaGrjV4DCuh+2dDH7WsrLLk8f7UevXrR7OYfvbyb8YofMvtFibOvVmSlIGax 6F0W/gKgz4Ydrzu9rbZXVwgvNi56ryTBXcP8oaYLZbsPX8bhXJrVGqIP8B9pl7ugaLWz Oe65fR8NQgFd6K3NT+zKnvZ1XMooo4H1WUa1h9tj0tvvJ84TCIydmRhWqXLBePCfCJ1s w7n65OKFbN1N5mYDwciHC0bihAFvjWw/1dDRGSR2qjHs0ZEGqvF86uKuBg6LoFuM5usw jCqw== 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=0i4Q8lN5RfQHFAjF7mAEg7OwHhBhoJgtUkCfBexPhbI=; b=XtpOe70fv4XMMWZVzHM6ofuq3U8NOIN1IDzhKNyrRB9YL3WkWecbyvQT2YAtoeFKjU iJ4RwsMDWSEmcTfshcUvjgeUq8piq81Jhu5ZLFuzmW1xfx+lMAU6uHOIN4LG1y5tiBAk v0IVV0y8aH6MsD7Kvp+zoP+W/qQao00XdVn0XTCeSwQYSh0Kz6NH5S8DtS482FR9V869 lXoop8w4eNNuXtZg3NJB0jbDM47j/bU2/ftmvj82ilW5aoBDPggAvEahl9kFn/Tz0bq9 sr5KWrvg/Rj45BzrhlFeUlhdYUh9my6bmp0Abd6QHtaODdbNlmXTs23EgsYgheMy/cDE IlpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=KGl2mnsq; 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 y40si7787558edd.383.2019.10.28.12.52.38; Mon, 28 Oct 2019 12:53:02 -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=KGl2mnsq; 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 S1730777AbfJ1Kwp (ORCPT + 99 others); Mon, 28 Oct 2019 06:52:45 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43990 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729177AbfJ1Kwo (ORCPT ); Mon, 28 Oct 2019 06:52:44 -0400 Received: by mail-pl1-f194.google.com with SMTP id v5so5400889ply.10 for ; Mon, 28 Oct 2019 03:52:44 -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=0i4Q8lN5RfQHFAjF7mAEg7OwHhBhoJgtUkCfBexPhbI=; b=KGl2mnsqc3Dbgubqw/0YGsRP4gLcH1PBGTTzD1Ep1NHWIsrZR9xDqQIvYnr66fmESG fl8xcT2P2mRn/65SpHD4wCXoX9Zep6zqZwVizVOzsGoT7ViVo8qjvV3b1V619DftOX3v utd97ogd9IWCvcjjDJS2VyY7Ar4DmABnGVCoDIJ4oM+g7sy1GnFylmwpA9EZUToyjEV4 p7Fn0VBsooii8KMOkTrSy32GzMEY9QctwKN+CTKVNM0mXkyWAlyTJIQsOnW3HvThXbck B3Sj/d9W9MlmniWYOeSCcqSJtqKkcGIRrzoaWhVNtUcYVeOIgcCDufGrD+fCunhMfr0x 5DdA== 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=0i4Q8lN5RfQHFAjF7mAEg7OwHhBhoJgtUkCfBexPhbI=; b=TVTw5HY2QCzY3CPUK0vPzvOC2WLeJd9hhxAVB10lGheKuuzVf8w8XdRBkcgfH5ffBQ kAedr0CgpiBRlGBqf4hWMbzCdMvJKTBpQ6NR1swinE1budOOpSni0t1aWQZKiSyDs4p1 ZwDCymjiK1ewnB1o7oe5evf/uBhVzwKcUv8GS6/+7Z/vkPm15Zmv5b2YlqwWnFemjg3/ JOpqm9hcwXEXclPwNpp/573CfHB4vYb9e2+Uhq4LTl1VuQ1GLBFeiS/HvCAheVLkhYD3 2yzIGVh2bfwsswxjww4kRow7saGHxjDjSUzx4491TPayx83cvV8/VdCJx69VUYtzI0hB +yDg== X-Gm-Message-State: APjAAAXwNBKJpy7BezWgs4JBPgLMJRLT7OdjQwCB6odHd1llO4Zq2MCY CibA9wm0ksYm7w3LxLDVDF8t X-Received: by 2002:a17:902:848e:: with SMTP id c14mr17050134plo.77.1572259963862; Mon, 28 Oct 2019 03:52:43 -0700 (PDT) Received: from poseidon.bobrowski.net (d114-78-127-22.bla803.nsw.optusnet.com.au. [114.78.127.22]) by smtp.gmail.com with ESMTPSA id x190sm11771535pfc.89.2019.10.28.03.52.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 03:52:43 -0700 (PDT) Date: Mon, 28 Oct 2019 21:52:37 +1100 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, hch@infradead.org, david@fromorbit.com, darrick.wong@oracle.com Subject: [PATCH v6 07/11] ext4: introduce direct I/O read using iomap infrastructure Message-ID: 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 I/O read path which makes use of the iomap infrastructure. The new function ext4_do_read_iter() is responsible for calling into the iomap infrastructure via iomap_dio_rw(). If the read operation performed on the inode is not supported, which is checked via ext4_dio_supported(), then we simply fallback and complete the I/O using buffered I/O. Existing direct I/O read code path has been removed, as it is now redundant. Signed-off-by: Matthew Bobrowski Reviewed-by: Jan Kara Reviewed-by: Ritesh Harjani --- fs/ext4/file.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++-- fs/ext4/inode.c | 38 +--------------------------------- 2 files changed, 54 insertions(+), 39 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index ab75aee3e687..440f4c6ba4ee 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -34,6 +34,52 @@ #include "xattr.h" #include "acl.h" +static bool ext4_dio_supported(struct inode *inode) +{ + if (IS_ENABLED(CONFIG_FS_ENCRYPTION) && IS_ENCRYPTED(inode)) + return false; + if (fsverity_active(inode)) + return false; + 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); + + if (iocb->ki_flags & IOCB_NOWAIT) { + if (!inode_trylock_shared(inode)) + return -EAGAIN; + } else { + inode_lock_shared(inode); + } + + if (!ext4_dio_supported(inode)) { + inode_unlock_shared(inode); + /* + * Fallback to buffered I/O if the operation being performed on + * the inode is not supported by direct I/O. The IOCB_DIRECT + * flag needs to be cleared here in order to ensure that the + * direct I/O path within generic_file_read_iter() is not + * taken. + */ + iocb->ki_flags &= ~IOCB_DIRECT; + return generic_file_read_iter(iocb, to); + } + + ret = iomap_dio_rw(iocb, to, &ext4_iomap_ops, NULL, + is_sync_kiocb(iocb)); + 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 +110,21 @@ 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); } diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 50b4835cd927..e44b3b1dbbc4 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -863,9 +863,6 @@ int ext4_dio_get_block(struct inode *inode, sector_t iblock, { /* We don't expect handle for direct IO */ WARN_ON_ONCE(ext4_journal_current_handle()); - - if (!create) - return _ext4_get_block(inode, iblock, bh, 0); return ext4_get_block_trans(inode, iblock, bh, EXT4_GET_BLOCKS_CREATE); } @@ -3874,36 +3871,6 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter) return ret; } -static ssize_t ext4_direct_IO_read(struct kiocb *iocb, struct iov_iter *iter) -{ - struct address_space *mapping = iocb->ki_filp->f_mapping; - struct inode *inode = mapping->host; - size_t count = iov_iter_count(iter); - ssize_t ret; - - /* - * Shared inode_lock is enough for us - it protects against concurrent - * writes & truncates and since we take care of writing back page cache, - * we are protected against page writeback as well. - */ - if (iocb->ki_flags & IOCB_NOWAIT) { - if (!inode_trylock_shared(inode)) - return -EAGAIN; - } else { - inode_lock_shared(inode); - } - - ret = filemap_write_and_wait_range(mapping, iocb->ki_pos, - iocb->ki_pos + count - 1); - if (ret) - goto out_unlock; - ret = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, - iter, ext4_dio_get_block, NULL, NULL, 0); -out_unlock: - inode_unlock_shared(inode); - return ret; -} - static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter) { struct file *file = iocb->ki_filp; @@ -3930,10 +3897,7 @@ static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter) return 0; trace_ext4_direct_IO_enter(inode, offset, count, iov_iter_rw(iter)); - if (iov_iter_rw(iter) == READ) - ret = ext4_direct_IO_read(iocb, iter); - else - ret = ext4_direct_IO_write(iocb, iter); + ret = ext4_direct_IO_write(iocb, iter); trace_ext4_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), ret); return ret; } -- 2.20.1