Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp246518ybn; Thu, 3 Oct 2019 04:35:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjZZ1N+JfyvxlP9gSNxlGcTfsHlxttBiztx6yVfMCIXPL74YqZDo7BI9PN4lHrPBQxbRik X-Received: by 2002:a17:906:f846:: with SMTP id ks6mr7340303ejb.192.1570102546034; Thu, 03 Oct 2019 04:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570102546; cv=none; d=google.com; s=arc-20160816; b=LjQn2V4m5gdWXcCwJ6TMGIlORV+juzfu2YMVglJvPioK2aComwVW/LmSyO+HGkUS8n IWq1Sr40/AtDpoo7cTudy3UK8y6lGNnGIP+TzlgEBx3Fs6oXt3v78w4eE4kWMdh9Km6H wWYrDpjwGKM4vIv8cDYNZhQexHTfceDHnk/2749UodQ46CYUjStmyhgBgacjdzEI/eKM IFDJFlNhWtETgUvMP0rJqQoN13LrT1dqybCqPgzmSuFemvbO5TqZA4VwAFPHxKI54fF1 Eyjselw0O8Go88Z7cwz2x4SDOWQlBlzD5uMDWn+QQe4QXU4WJOuLRYGX1UOpku0nEIH6 0ULQ== 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=M87IY+2KVSkzSC9nEbKGMnVlb0Np+3Hd+IxPBaWE+Zg=; b=fIkUdvs2xQe4fSlqdYcip+exrrA4Lul3zFmgpdwKEiiBJroixXvPzhd44E0jD9gD04 wlTVHXwk4iTFcA/qD6kgspMV9TYO/pxwVdv4i9V6xENakAsgcsuEVu/CjAla6NiNM1F/ 0/sS+8E8TgM25k5Xgn0MIBzZdEfZ9R6dV7IrGjN+GnmxiduivKBitVIouCcbMV/AXUXp KDpQqOEklhmvbTxm/ke+h7qGVvcBLdx9fzn88GTqfjufdZbYK+bBvH894O8IYHaPsPsD +Dws7uGWcgXE7uf2nR+pwR0gfKqt4xqluDU5PGXOQJotJNFEm3MDO14R8l1YxImuOY5p wTUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=sUMHGC5A; 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 i33si1278231eda.205.2019.10.03.04.35.20; Thu, 03 Oct 2019 04:35:46 -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=sUMHGC5A; 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 S1730204AbfJCLeI (ORCPT + 99 others); Thu, 3 Oct 2019 07:34:08 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:35716 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730051AbfJCLeI (ORCPT ); Thu, 3 Oct 2019 07:34:08 -0400 Received: by mail-pl1-f193.google.com with SMTP id y10so1396689plp.2 for ; Thu, 03 Oct 2019 04:34:08 -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=M87IY+2KVSkzSC9nEbKGMnVlb0Np+3Hd+IxPBaWE+Zg=; b=sUMHGC5AT9lFKBhMdmRLRp7wEd3e4u+/zZBmXi2lFCshYiT0gisuTE8eqkUy6gcX/I jqA/UNRoqmREpUogZ18WisZ7bFnQGE1qFtxg7rn59xhjqgfb27cZTqDOwPxdRgv0jDqC At0YRNUbyOKuWsQ5/VH0WuHyS56xvqghqBg3WmwaAhOCS7LOuuFU5z94kBgys5BOtpko E51PLVTEe8ZN708Kyn4U3UK6gr9CcmturIr93KgkLIe7SfPLeDRmczYpTCxjjs76uuj6 9yUQ1j5VGEIcQI3XxoWgTYEy6ZKEEJKCWH2+HkAo6HZmGwoyBuRLbPJLM7vNCGyG8bWP KoQg== 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=M87IY+2KVSkzSC9nEbKGMnVlb0Np+3Hd+IxPBaWE+Zg=; b=nQGpLUuOtJR/oE0w6t6OP2oaQ2iMhtHmsKpe61Lp23R5TLnCmU7EDveduU5boD8ZRO GTrMp2X283oi9ZokgR3dgP3bugVNGM6f+cPACvPcq/0AQWnlHos/C+v5WJEmkPqI+yx4 Jguu00B0cZKQr8LlK5tHYrO2XgsvHVhU0umpfIa0N9oNSAqhWc9cFtuFLJRa3cRORQZl N36N0lyUtQ3nHwvt3OtuN39+86AHbQAkwRqGci1pL6G+Wn0o3svI4s5kmS/OIBPsO7N4 vJrrNoigEdIowCC1lNTdB0SyHRDW4hSGmWTf+ukvzZ/jHwWUFU9zB/POb/p9WOc0wzwu PeGg== X-Gm-Message-State: APjAAAW0neGPWLw3wl11jcvRH/zMOV14gVicRgKNt4gs8sGeOjeBvkge vX/GotUZzOa2/fVzk5Hh8B62 X-Received: by 2002:a17:902:ac8a:: with SMTP id h10mr9106187plr.170.1570102447340; Thu, 03 Oct 2019 04:34:07 -0700 (PDT) Received: from poseidon.bobrowski.net ([114.78.226.167]) by smtp.gmail.com with ESMTPSA id q14sm5855223pgf.74.2019.10.03.04.34.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2019 04:34:06 -0700 (PDT) Date: Thu, 3 Oct 2019 21:34:00 +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, hch@infradead.org, david@fromorbit.com, darrick.wong@oracle.com Subject: [PATCH v4 4/8] ext4: introduce direct I/O read path 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 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 read operation being performed on the inode does not pass the preliminary checks performed within ext4_dio_supported(), then we simply fallback to buffered I/O in order to fulfil the request. Existing direct I/O read buffer_head code has been removed as it's now redundant. Signed-off-by: Matthew Bobrowski --- fs/ext4/file.c | 58 +++++++++++++++++++++++++++++++++++++++++++++---- fs/ext4/inode.c | 32 +-------------------------- 2 files changed, 55 insertions(+), 35 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index ab75aee3e687..69ac042fb74b 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_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); + + /* + * 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_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 withiin + * 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); + 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); } diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 1dace576b8bd..159ffb92f82d 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); } @@ -3855,30 +3852,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. - */ - 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; @@ -3905,10 +3878,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