From patchwork Fri May 19 09:35:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEC50C7EE31 for ; Fri, 19 May 2023 09:37:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231797AbjESJhP (ORCPT ); Fri, 19 May 2023 05:37:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231704AbjESJg6 (ORCPT ); Fri, 19 May 2023 05:36:58 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AB611991; Fri, 19 May 2023 02:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=C58xAMXMWyHPUrJzlledIWUNnBNJDxIHqrA6uNazQYQ=; b=oyB5ENrtpS3oCMIV1tdQqugXkU sJw9tWTnvGCKGzKa9RpoMfHRvUYSVzT0RXiuWCYAumP4uyadSzytLs+6N80qNj9Wx28cGiAr5gPRY KzRMEKVFBYf9VfLGcLm7M27cD+XoFkxkgCSSKqQHZ2uH/AqoUIgSHz/wG2IogiCKWS/kp20FiYsw9 xyQ9CaQyFtSTLVG/mgOLVL5dwvmUwJri/zQlIjlsjwVm/9D6Z4u0xvXzVPX25fHmcOK0AEKAUd6wR 5Pyq49d9NQSlXRan5UmQ0bHDH+gbH8e7O2mZ27adQFXSM/HW3HE7/4rluA8VRqK7aYy04HDSPH9D2 6F0846Dw==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWF-00Fjaj-1T; Fri, 19 May 2023 09:35:27 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 01/13] iomap: update ki_pos a little later in iomap_dio_complete Date: Fri, 19 May 2023 11:35:09 +0200 Message-Id: <20230519093521.133226-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Move the ki_pos update down a bit to prepare for a better common helper that invalidates pages based of an iocb. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/iomap/direct-io.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 019cc87d0fb339..6207a59d2162e1 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -94,7 +94,6 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) if (offset + ret > dio->i_size && !(dio->flags & IOMAP_DIO_WRITE)) ret = dio->i_size - offset; - iocb->ki_pos += ret; } /* @@ -120,19 +119,21 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) } inode_dio_end(file_inode(iocb->ki_filp)); - /* - * If this is a DSYNC write, make sure we push it to stable storage now - * that we've written data. - */ - if (ret > 0 && (dio->flags & IOMAP_DIO_NEED_SYNC)) - ret = generic_write_sync(iocb, ret); - if (ret > 0) - ret += dio->done_before; + if (ret > 0) { + iocb->ki_pos += ret; + /* + * If this is a DSYNC write, make sure we push it to stable + * storage now that we've written data. + */ + if (dio->flags & IOMAP_DIO_NEED_SYNC) + ret = generic_write_sync(iocb, ret); + if (ret > 0) + ret += dio->done_before; + } trace_iomap_dio_complete(iocb, dio->error, ret); kfree(dio); - return ret; } EXPORT_SYMBOL_GPL(iomap_dio_complete); From patchwork Fri May 19 09:35:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248072 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6499AC7EE2F for ; Fri, 19 May 2023 09:37:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231771AbjESJhO (ORCPT ); Fri, 19 May 2023 05:37:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231706AbjESJg7 (ORCPT ); Fri, 19 May 2023 05:36:59 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A19321995; Fri, 19 May 2023 02:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=l1nHpSO+SfI7dJoy9Bf6sKMQrfHZhTAI7csUoY2gOqg=; b=fNcIJXStbg35Q3/kxwRadlJBkR BDEVYzDTYkGHq1nmqbayvo2Mb8RhUWRs2vpPYsKxu8f33DSVER7T9eunP8b8/p+Cm1VPG75aVtHEh rUAEhk75WkLoyrZwgVxPM/pVzSBCQHe5cSaLK2/BGJnm0EZLku21y03qF/1nrgLfo8Y/CBxH34Xpi mjIWogLEu/YGtIV81gHtLrQwwS6ZOgNx8i2yLDnmdlw9wjPJt68CN5aY4zUsNNalfAYBB5h0jwBe9 IU91VmeeMOfWsiiyMRY6eeqJxbWxpymNlF04FNOu5GcpFrlEbHeZbYXoC9JEhrJNWBeTP/bnm84Qw taYBszPA==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWI-00Fjbs-0u; Fri, 19 May 2023 09:35:30 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 02/13] filemap: update ki_pos in generic_perform_write Date: Fri, 19 May 2023 11:35:10 +0200 Message-Id: <20230519093521.133226-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org All callers of generic_perform_write need to updated ki_pos, move it into common code. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Xiubo Li --- fs/ceph/file.c | 2 -- fs/ext4/file.c | 9 +++------ fs/f2fs/file.c | 1 - fs/nfs/file.c | 1 - mm/filemap.c | 8 ++++---- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index f4d8bf7dec88a8..feeb9882ef635a 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1894,8 +1894,6 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from) * can not run at the same time */ written = generic_perform_write(iocb, from); - if (likely(written >= 0)) - iocb->ki_pos = pos + written; ceph_end_io_write(inode); } diff --git a/fs/ext4/file.c b/fs/ext4/file.c index d101b3b0c7dad8..50824831d31def 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -291,12 +291,9 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb, out: inode_unlock(inode); - if (likely(ret > 0)) { - iocb->ki_pos += ret; - ret = generic_write_sync(iocb, ret); - } - - return ret; + if (unlikely(ret <= 0)) + return ret; + return generic_write_sync(iocb, ret); } static ssize_t ext4_handle_inode_extension(struct inode *inode, loff_t offset, diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 5ac53d2627d20d..9e3855e43a7a63 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4522,7 +4522,6 @@ static ssize_t f2fs_buffered_write_iter(struct kiocb *iocb, current->backing_dev_info = NULL; if (ret > 0) { - iocb->ki_pos += ret; f2fs_update_iostat(F2FS_I_SB(inode), inode, APP_BUFFERED_IO, ret); } diff --git a/fs/nfs/file.c b/fs/nfs/file.c index f0edf5a36237d1..3cc87ae8473356 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -658,7 +658,6 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) goto out; written = result; - iocb->ki_pos += written; nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written); if (mntflags & NFS_MOUNT_WRITE_EAGER) { diff --git a/mm/filemap.c b/mm/filemap.c index b4c9bd368b7e58..4d0ec2fa1c7070 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3957,7 +3957,10 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) balance_dirty_pages_ratelimited(mapping); } while (iov_iter_count(i)); - return written ? written : status; + if (!written) + return status; + iocb->ki_pos += written; + return written; } EXPORT_SYMBOL(generic_perform_write); @@ -4036,7 +4039,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) endbyte = pos + status - 1; err = filemap_write_and_wait_range(mapping, pos, endbyte); if (err == 0) { - iocb->ki_pos = endbyte + 1; written += status; invalidate_mapping_pages(mapping, pos >> PAGE_SHIFT, @@ -4049,8 +4051,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) } } else { written = generic_perform_write(iocb, from); - if (likely(written > 0)) - iocb->ki_pos += written; } out: current->backing_dev_info = NULL; From patchwork Fri May 19 09:35:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248077 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAA13C7EE2D for ; Fri, 19 May 2023 09:37:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231869AbjESJhZ (ORCPT ); Fri, 19 May 2023 05:37:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231720AbjESJg7 (ORCPT ); Fri, 19 May 2023 05:36:59 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BB1D1BF9; Fri, 19 May 2023 02:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=6ol1bWODvCYTDT1JUgKKn9Fh7sNo8e9dyRg15aWfO9s=; b=M6KzmetzkAeuS/VLc0Lh9JjJju Ru7ZWS27kADd2VtwycBozYnipzuMCirIKKvprX9mPjk8FvigFdIjN4M/xtUGuo008+0WHzo3WfJO3 EWdbDmUJHxpyHqFvevzzdoF8sY4ioA/FmCmhyHPkTSVBFbLUMUzg40a4nDIY0CgVciRjpOyZAAYL6 xkhg/yyrk3LagyAARJhct/1trEUwML73oIOqKl2Q1BZS5BLz1DLbgF0IsqLaC9nklXzoY22/+vvE8 6CgJvHjCSdFdTeTp+UnCpdHK3HMDcG/2uwD5g8SjDrtquin8RrPGVFwqC+Dwf8e+kLQB4xAFRANP0 98GWXd4g==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWL-00FjdO-2V; Fri, 19 May 2023 09:35:34 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 03/13] filemap: assign current->backing_dev_info in generic_perform_write Date: Fri, 19 May 2023 11:35:11 +0200 Message-Id: <20230519093521.133226-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Move the assignment to current->backing_dev_info from the callers into generic_perform_write to reduce boiler plate code and reduce the scope to just around the page dirtying loop. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Xiubo Li --- fs/ceph/file.c | 4 ---- fs/ext4/file.c | 3 --- fs/f2fs/file.c | 2 -- fs/nfs/file.c | 5 +---- mm/filemap.c | 2 ++ 5 files changed, 3 insertions(+), 13 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index feeb9882ef635a..767f4dfe7def64 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1791,9 +1791,6 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from) else ceph_start_io_write(inode); - /* We can write back this queue in page reclaim */ - current->backing_dev_info = inode_to_bdi(inode); - if (iocb->ki_flags & IOCB_APPEND) { err = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE, false); if (err < 0) @@ -1938,7 +1935,6 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from) ceph_end_io_write(inode); out_unlocked: ceph_free_cap_flush(prealloc_cf); - current->backing_dev_info = NULL; return written ? written : err; } diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 50824831d31def..3cb83a3e2e4a2a 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -29,7 +29,6 @@ #include #include #include -#include #include "ext4.h" #include "ext4_jbd2.h" #include "xattr.h" @@ -285,9 +284,7 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb, if (ret <= 0) goto out; - current->backing_dev_info = inode_to_bdi(inode); ret = generic_perform_write(iocb, from); - current->backing_dev_info = NULL; out: inode_unlock(inode); diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 9e3855e43a7a63..7134fe8bd008cb 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4517,9 +4517,7 @@ static ssize_t f2fs_buffered_write_iter(struct kiocb *iocb, if (iocb->ki_flags & IOCB_NOWAIT) return -EOPNOTSUPP; - current->backing_dev_info = inode_to_bdi(inode); ret = generic_perform_write(iocb, from); - current->backing_dev_info = NULL; if (ret > 0) { f2fs_update_iostat(F2FS_I_SB(inode), inode, diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 3cc87ae8473356..e8bb4c48a3210a 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -648,11 +648,8 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) since = filemap_sample_wb_err(file->f_mapping); nfs_start_io_write(inode); result = generic_write_checks(iocb, from); - if (result > 0) { - current->backing_dev_info = inode_to_bdi(inode); + if (result > 0) result = generic_perform_write(iocb, from); - current->backing_dev_info = NULL; - } nfs_end_io_write(inode); if (result <= 0) goto out; diff --git a/mm/filemap.c b/mm/filemap.c index 4d0ec2fa1c7070..bf693ad1da1ece 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3892,6 +3892,7 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) long status = 0; ssize_t written = 0; + current->backing_dev_info = inode_to_bdi(mapping->host); do { struct page *page; unsigned long offset; /* Offset into pagecache page */ @@ -3956,6 +3957,7 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) balance_dirty_pages_ratelimited(mapping); } while (iov_iter_count(i)); + current->backing_dev_info = NULL; if (!written) return status; From patchwork Fri May 19 09:35:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248076 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB04EC77B75 for ; Fri, 19 May 2023 09:37:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231856AbjESJhY (ORCPT ); Fri, 19 May 2023 05:37:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231722AbjESJhA (ORCPT ); Fri, 19 May 2023 05:37:00 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FA131FC0; Fri, 19 May 2023 02:36:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=tGCXuJSpKeMdDJfNmlfVF+NepybRn/cvj/Ka18QV4Tk=; b=xArZwU++0j0FGgKFO7gwbG5SAC a1/RPaFHnsRd+UOwpiKD4Hll+FQbOU/DKkcxbAcjid8e3CwS1tnTNCYZM+x+KyqcKxXicxUupis0e ZB3+K10LpIi0KqMuYdfgZL6dZTSTQbvZkH6r8F/El40AXbo89yVa1KaDyWLp3QCGRzcYOWW19+z/N 2m+4ElhodZEmxP0Tr1ON4pIvchIdcns7DtlQG0WP60hmdAH+rnDgdc0p0Ohgew+bUcpPErepKoeep u14tVprafp/sJaOi2+meSJDf/HCFZ/FFjC0EYErlFi9kYKElkKwIgcEtgjqPYwnbsZPkkX1lMh8UH EPHXXp9Q==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWO-00FjeP-1n; Fri, 19 May 2023 09:35:36 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 04/13] filemap: add a kiocb_write_and_wait helper Date: Fri, 19 May 2023 11:35:12 +0200 Message-Id: <20230519093521.133226-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Factor out a helper that does filemap_write_and_wait_range for a the range covered by a read kiocb, or returns -EAGAIN if the kiocb is marked as nowait and there would be pages to write. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- block/fops.c | 18 +++--------------- include/linux/pagemap.h | 2 ++ mm/filemap.c | 30 ++++++++++++++++++------------ 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/block/fops.c b/block/fops.c index d2e6be4e3d1c7d..c194939b851cfb 100644 --- a/block/fops.c +++ b/block/fops.c @@ -576,21 +576,9 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) goto reexpand; /* skip atime */ if (iocb->ki_flags & IOCB_DIRECT) { - struct address_space *mapping = iocb->ki_filp->f_mapping; - - if (iocb->ki_flags & IOCB_NOWAIT) { - if (filemap_range_needs_writeback(mapping, pos, - pos + count - 1)) { - ret = -EAGAIN; - goto reexpand; - } - } else { - ret = filemap_write_and_wait_range(mapping, pos, - pos + count - 1); - if (ret < 0) - goto reexpand; - } - + ret = kiocb_write_and_wait(iocb, count); + if (ret < 0) + goto reexpand; file_accessed(iocb->ki_filp); ret = blkdev_direct_IO(iocb, to); diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a56308a9d1a450..36fc2cea13ce20 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -30,6 +30,7 @@ static inline void invalidate_remote_inode(struct inode *inode) int invalidate_inode_pages2(struct address_space *mapping); int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end); + int write_inode_now(struct inode *, int sync); int filemap_fdatawrite(struct address_space *); int filemap_flush(struct address_space *); @@ -54,6 +55,7 @@ int filemap_check_errors(struct address_space *mapping); void __filemap_set_wb_err(struct address_space *mapping, int err); int filemap_fdatawrite_wbc(struct address_space *mapping, struct writeback_control *wbc); +int kiocb_write_and_wait(struct kiocb *iocb, size_t count); static inline int filemap_write_and_wait(struct address_space *mapping) { diff --git a/mm/filemap.c b/mm/filemap.c index bf693ad1da1ece..2d7712b13b95c9 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2762,6 +2762,21 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter, } EXPORT_SYMBOL_GPL(filemap_read); +int kiocb_write_and_wait(struct kiocb *iocb, size_t count) +{ + struct address_space *mapping = iocb->ki_filp->f_mapping; + loff_t pos = iocb->ki_pos; + loff_t end = pos + count - 1; + + if (iocb->ki_flags & IOCB_NOWAIT) { + if (filemap_range_needs_writeback(mapping, pos, end)) + return -EAGAIN; + return 0; + } + + return filemap_write_and_wait_range(mapping, pos, end); +} + /** * generic_file_read_iter - generic filesystem read routine * @iocb: kernel I/O control block @@ -2797,18 +2812,9 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) struct address_space *mapping = file->f_mapping; struct inode *inode = mapping->host; - if (iocb->ki_flags & IOCB_NOWAIT) { - if (filemap_range_needs_writeback(mapping, iocb->ki_pos, - iocb->ki_pos + count - 1)) - return -EAGAIN; - } else { - retval = filemap_write_and_wait_range(mapping, - iocb->ki_pos, - iocb->ki_pos + count - 1); - if (retval < 0) - return retval; - } - + retval = kiocb_write_and_wait(iocb, count); + if (retval < 0) + return retval; file_accessed(file); retval = mapping->a_ops->direct_IO(iocb, iter); From patchwork Fri May 19 09:35:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248075 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB31BC7EE31 for ; Fri, 19 May 2023 09:37:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230285AbjESJhX (ORCPT ); Fri, 19 May 2023 05:37:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231551AbjESJhA (ORCPT ); Fri, 19 May 2023 05:37:00 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 120B51FC3; Fri, 19 May 2023 02:36:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=2vGhRrsGDQG1XODk9UotEfGLA1kaizvBUpauFyMQx+4=; b=TBnMbLul9soaolAwQt3sWNxAv8 S50hIIY4562VCW+y/Cq8+3LO3VrJg96XVVX2EEiXJHKTs9YdOwSZr3vQ7xKMYQq9loacKBMo2TjQb mt2oOAqhwJYf/vwi9ZwUhGiDHZEP+OGyxljgfJPRxypkUk2aYNRd8cRBNC8WigFq4itE5QkV3u6WE k6G4AwhOJicC5M2bn3hgQkw1CEDeF7NprlLZ1rD8HkyWJakLoX2ZPgXlNNx1J6pEwSt17Z1ByP739 zN5MLhg8XrTTTkFcFtuLeIxZDkVu1Lvi1yv+CkNKAggzxH5e0OR08oQL+h60U4KPl67tkcU+vLZ53 YO6mHBPw==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWR-00Fjew-1b; Fri, 19 May 2023 09:35:39 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 05/13] filemap: add a kiocb_invalidate_pages helper Date: Fri, 19 May 2023 11:35:13 +0200 Message-Id: <20230519093521.133226-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Factor out a helper that calls filemap_write_and_wait_range and invalidate_inode_pages2_rangefor a the range covered by a write kiocb or returns -EAGAIN if the kiocb is marked as nowait and there would be pages to write or invalidate. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- include/linux/pagemap.h | 1 + mm/filemap.c | 48 ++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 36fc2cea13ce20..6e4c9ee40baa99 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -30,6 +30,7 @@ static inline void invalidate_remote_inode(struct inode *inode) int invalidate_inode_pages2(struct address_space *mapping); int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end); +int kiocb_invalidate_pages(struct kiocb *iocb, size_t count); int write_inode_now(struct inode *, int sync); int filemap_fdatawrite(struct address_space *); diff --git a/mm/filemap.c b/mm/filemap.c index 2d7712b13b95c9..8607220e20eae3 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2777,6 +2777,33 @@ int kiocb_write_and_wait(struct kiocb *iocb, size_t count) return filemap_write_and_wait_range(mapping, pos, end); } +int kiocb_invalidate_pages(struct kiocb *iocb, size_t count) +{ + struct address_space *mapping = iocb->ki_filp->f_mapping; + loff_t pos = iocb->ki_pos; + loff_t end = pos + count - 1; + int ret; + + if (iocb->ki_flags & IOCB_NOWAIT) { + /* we could block if there are any pages in the range */ + if (filemap_range_has_page(mapping, pos, end)) + return -EAGAIN; + } else { + ret = filemap_write_and_wait_range(mapping, pos, end); + if (ret) + return ret; + } + + /* + * After a write we want buffered reads to be sure to go to disk to get + * the new data. We invalidate clean cached page from the region we're + * about to write. We do this *before* the write so that we can return + * without clobbering -EIOCBQUEUED from ->direct_IO(). + */ + return invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, + end >> PAGE_SHIFT); +} + /** * generic_file_read_iter - generic filesystem read routine * @iocb: kernel I/O control block @@ -3820,30 +3847,11 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) write_len = iov_iter_count(from); end = (pos + write_len - 1) >> PAGE_SHIFT; - if (iocb->ki_flags & IOCB_NOWAIT) { - /* If there are pages to writeback, return */ - if (filemap_range_has_page(file->f_mapping, pos, - pos + write_len - 1)) - return -EAGAIN; - } else { - written = filemap_write_and_wait_range(mapping, pos, - pos + write_len - 1); - if (written) - goto out; - } - - /* - * After a write we want buffered reads to be sure to go to disk to get - * the new data. We invalidate clean cached page from the region we're - * about to write. We do this *before* the write so that we can return - * without clobbering -EIOCBQUEUED from ->direct_IO(). - */ - written = invalidate_inode_pages2_range(mapping, - pos >> PAGE_SHIFT, end); /* * If a page can not be invalidated, return 0 to fall back * to buffered write. */ + written = kiocb_invalidate_pages(iocb, write_len); if (written) { if (written == -EBUSY) return 0; From patchwork Fri May 19 09:35:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248074 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94836C7EE26 for ; Fri, 19 May 2023 09:37:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230372AbjESJhU (ORCPT ); Fri, 19 May 2023 05:37:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230315AbjESJhE (ORCPT ); Fri, 19 May 2023 05:37:04 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 986281FCC; Fri, 19 May 2023 02:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=GbtEVhZzh4P+WH4HZJFPMpvqDDxXPgcuIWhhv+qk6PM=; b=DqmA7dTVT68FU40NAJdsxdmoON 8s/SjmRcLhGu/lJi1M5fPke/bAE0vf9gejgATRJo1zuxUpJEhdGw3FmwR1P2R72Oe18XJcUzIJOyY 4qaiwrSWHS/9emssqkgRPz8S3h/CI0f2FzdmoTm9HnpQDQ8G4NmMwHdOVS5LmbnUUDQLMjijPyL6k KuL4nVoWfTnMbUen4VrJnRsGiEj3SYnspKxbC0Tzz4Yjb3lktJSQcHtRwxuRTaGXZ8SFw1KA1OxyS pkniwg11DAgjk+g9anhw1Lz6Vuw1/aF7J5KEsLQSp4gnwDqM+hLSnkAz39O+o0uQRe90pl4yU9eBW DZlsgkVA==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWU-00FjfV-06; Fri, 19 May 2023 09:35:42 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 06/13] filemap: add a kiocb_invalidate_post_write helper Date: Fri, 19 May 2023 11:35:14 +0200 Message-Id: <20230519093521.133226-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add a helper to invalidate page cache after a dio write. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/direct-io.c | 10 ++-------- fs/iomap/direct-io.c | 12 ++---------- include/linux/fs.h | 5 ----- include/linux/pagemap.h | 1 + mm/filemap.c | 37 ++++++++++++++++++++----------------- 5 files changed, 25 insertions(+), 40 deletions(-) diff --git a/fs/direct-io.c b/fs/direct-io.c index 0b380bb8a81e11..c25d68eabf4281 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -285,14 +285,8 @@ static ssize_t dio_complete(struct dio *dio, ssize_t ret, unsigned int flags) * zeros from unwritten extents. */ if (flags & DIO_COMPLETE_INVALIDATE && - ret > 0 && dio_op == REQ_OP_WRITE && - dio->inode->i_mapping->nrpages) { - err = invalidate_inode_pages2_range(dio->inode->i_mapping, - offset >> PAGE_SHIFT, - (offset + ret - 1) >> PAGE_SHIFT); - if (err) - dio_warn_stale_pagecache(dio->iocb->ki_filp); - } + ret > 0 && dio_op == REQ_OP_WRITE) + kiocb_invalidate_post_write(dio->iocb, ret); inode_dio_end(dio->inode); diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 6207a59d2162e1..45accd98344e79 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -81,7 +81,6 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) { const struct iomap_dio_ops *dops = dio->dops; struct kiocb *iocb = dio->iocb; - struct inode *inode = file_inode(iocb->ki_filp); loff_t offset = iocb->ki_pos; ssize_t ret = dio->error; @@ -108,15 +107,8 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) * ->end_io() when necessary, otherwise a racing buffer read would cache * zeros from unwritten extents. */ - if (!dio->error && dio->size && - (dio->flags & IOMAP_DIO_WRITE) && inode->i_mapping->nrpages) { - int err; - err = invalidate_inode_pages2_range(inode->i_mapping, - offset >> PAGE_SHIFT, - (offset + dio->size - 1) >> PAGE_SHIFT); - if (err) - dio_warn_stale_pagecache(iocb->ki_filp); - } + if (!dio->error && dio->size && (dio->flags & IOMAP_DIO_WRITE)) + kiocb_invalidate_post_write(iocb, dio->size); inode_dio_end(file_inode(iocb->ki_filp)); diff --git a/include/linux/fs.h b/include/linux/fs.h index 21a98168085641..e4efc1792a877a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2837,11 +2837,6 @@ static inline void inode_dio_end(struct inode *inode) wake_up_bit(&inode->i_state, __I_DIO_WAKEUP); } -/* - * Warn about a page cache invalidation failure diring a direct I/O write. - */ -void dio_warn_stale_pagecache(struct file *filp); - extern void inode_set_flags(struct inode *inode, unsigned int flags, unsigned int mask); diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 6e4c9ee40baa99..9695730ea86a98 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -31,6 +31,7 @@ int invalidate_inode_pages2(struct address_space *mapping); int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end); int kiocb_invalidate_pages(struct kiocb *iocb, size_t count); +void kiocb_invalidate_post_write(struct kiocb *iocb, size_t count); int write_inode_now(struct inode *, int sync); int filemap_fdatawrite(struct address_space *); diff --git a/mm/filemap.c b/mm/filemap.c index 8607220e20eae3..c1b988199aece5 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3816,7 +3816,7 @@ EXPORT_SYMBOL(read_cache_page_gfp); /* * Warn about a page cache invalidation failure during a direct I/O write. */ -void dio_warn_stale_pagecache(struct file *filp) +static void dio_warn_stale_pagecache(struct file *filp) { static DEFINE_RATELIMIT_STATE(_rs, 86400 * HZ, DEFAULT_RATELIMIT_BURST); char pathname[128]; @@ -3833,19 +3833,23 @@ void dio_warn_stale_pagecache(struct file *filp) } } +void kiocb_invalidate_post_write(struct kiocb *iocb, size_t count) +{ + struct address_space *mapping = iocb->ki_filp->f_mapping; + + if (mapping->nrpages && + invalidate_inode_pages2_range(mapping, + iocb->ki_pos >> PAGE_SHIFT, + (iocb->ki_pos + count - 1) >> PAGE_SHIFT)) + dio_warn_stale_pagecache(iocb->ki_filp); +} + ssize_t generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) { - struct file *file = iocb->ki_filp; - struct address_space *mapping = file->f_mapping; - struct inode *inode = mapping->host; - loff_t pos = iocb->ki_pos; - ssize_t written; - size_t write_len; - pgoff_t end; - - write_len = iov_iter_count(from); - end = (pos + write_len - 1) >> PAGE_SHIFT; + struct address_space *mapping = iocb->ki_filp->f_mapping; + size_t write_len = iov_iter_count(from); + ssize_t written; /* * If a page can not be invalidated, return 0 to fall back @@ -3855,7 +3859,7 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) if (written) { if (written == -EBUSY) return 0; - goto out; + return written; } written = mapping->a_ops->direct_IO(iocb, from); @@ -3877,11 +3881,11 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) * * Skip invalidation for async writes or if mapping has no pages. */ - if (written > 0 && mapping->nrpages && - invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, end)) - dio_warn_stale_pagecache(file); - if (written > 0) { + struct inode *inode = mapping->host; + loff_t pos = iocb->ki_pos; + + kiocb_invalidate_post_write(iocb, written); pos += written; write_len -= written; if (pos > i_size_read(inode) && !S_ISBLK(inode->i_mode)) { @@ -3892,7 +3896,6 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) } if (written != -EIOCBQUEUED) iov_iter_revert(from, write_len - iov_iter_count(from)); -out: return written; } EXPORT_SYMBOL(generic_file_direct_write); From patchwork Fri May 19 09:35:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248078 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF979C77B75 for ; Fri, 19 May 2023 09:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231267AbjESJiA (ORCPT ); Fri, 19 May 2023 05:38:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231723AbjESJhI (ORCPT ); Fri, 19 May 2023 05:37:08 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40BF319A2; Fri, 19 May 2023 02:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=jBsLbOyW4gxJfboFsPaM/jr4wcWxBT1Mri8F0Ud0gD8=; b=CJ+A5CucslKF05xEph7ZTKtrZ0 2m1gkbiYfzpbtTt1XTbMs91Z6sBHAPMva3XLcVNtvCKv+5A6Yt3jZeQsnaQfDhtMWLLz7dmaTQVZ7 M09DndXYZgSi3F84aM+aUrXASh0lFIaychMModF2k0xSG4po0YGEvtMoBhLtzic+dHU8AqxyUk7nq rUT1Lz/9lG68YM/Y1UnQTYM8Xu0RsVv+sH1YXWxHCT9P5xvCDmv3wB05YjcuDoGbnPzzlAJaKcdQl rzznR1GintoXSsaocfkeJCe2ZH8w34EK+LZ0LW9n/Nu7pOWNGYOfKPfWYZVwB0Q+0Z040kY30qie4 cyio+LIA==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWW-00Fjfv-2R; Fri, 19 May 2023 09:35:45 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 07/13] iomap: update ki_pos in iomap_file_buffered_write Date: Fri, 19 May 2023 11:35:15 +0200 Message-Id: <20230519093521.133226-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org All callers of iomap_file_buffered_write need to updated ki_pos, move it into common code. Signed-off-by: Christoph Hellwig Acked-by: Damien Le Moal --- fs/gfs2/file.c | 4 +--- fs/iomap/buffered-io.c | 9 ++++++--- fs/xfs/xfs_file.c | 2 -- fs/zonefs/file.c | 4 +--- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 300844f50dcd28..499ef174dec138 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -1046,10 +1046,8 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, ret = iomap_file_buffered_write(iocb, from, &gfs2_iomap_ops); pagefault_enable(); current->backing_dev_info = NULL; - if (ret > 0) { - iocb->ki_pos += ret; + if (ret > 0) written += ret; - } if (inode == sdp->sd_rindex) gfs2_glock_dq_uninit(statfs_gh); diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 063133ec77f49e..550525a525c45c 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -864,16 +864,19 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, .len = iov_iter_count(i), .flags = IOMAP_WRITE, }; - int ret; + ssize_t ret; if (iocb->ki_flags & IOCB_NOWAIT) iter.flags |= IOMAP_NOWAIT; while ((ret = iomap_iter(&iter, ops)) > 0) iter.processed = iomap_write_iter(&iter, i); - if (iter.pos == iocb->ki_pos) + + if (unlikely(ret < 0)) return ret; - return iter.pos - iocb->ki_pos; + ret = iter.pos - iocb->ki_pos; + iocb->ki_pos += ret; + return ret; } EXPORT_SYMBOL_GPL(iomap_file_buffered_write); diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index aede746541f8ae..bfba10e0b0f3c2 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -723,8 +723,6 @@ xfs_file_buffered_write( trace_xfs_file_buffered_write(iocb, from); ret = iomap_file_buffered_write(iocb, from, &xfs_buffered_write_iomap_ops); - if (likely(ret >= 0)) - iocb->ki_pos += ret; /* * If we hit a space limit, try to free up some lingering preallocated diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c index 132f01d3461f14..e212d0636f848e 100644 --- a/fs/zonefs/file.c +++ b/fs/zonefs/file.c @@ -643,9 +643,7 @@ static ssize_t zonefs_file_buffered_write(struct kiocb *iocb, goto inode_unlock; ret = iomap_file_buffered_write(iocb, from, &zonefs_write_iomap_ops); - if (ret > 0) - iocb->ki_pos += ret; - else if (ret == -EIO) + if (ret == -EIO) zonefs_io_error(inode, true); inode_unlock: From patchwork Fri May 19 09:35:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248079 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFF4CC7EE30 for ; Fri, 19 May 2023 09:38:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231709AbjESJiD (ORCPT ); Fri, 19 May 2023 05:38:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231755AbjESJhK (ORCPT ); Fri, 19 May 2023 05:37:10 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFA68101; Fri, 19 May 2023 02:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=DWCBIuCWrEPUSgFUMsFJ6qSq1T5QDjJd5vFpRCChJ1w=; b=GayNG3kzJFJ5dJ+3pyHdgpJaHg Vg+D3WJSisJRAfKh4FdM+kMULiHBkVK2JlSjPpe6AWhhM9TnhNcnVYwVNicVKsW2D6CwQtiNr4GbI ifi8oL59NNJcPyuNM4H5lL3BQg0kUH1IUPhrqcRX4x0gkGHePahAMpgU+OMoye7IWbL1i4P4N0K7d hPveIYGdIaP1exiwrksrwwox3ggk+6PoAmRpABmAJW0vLpX170W8n4+WiyOMWiWdUV0KUHViDPR2V y4iTj0Am5OrXwsAxT9LSL8UdxWNyTm0g69FXTbp/zKBR4iorevNKqz7EDBD0kG/pHeghxQmsCy7c1 7dhC9L+g==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWZ-00FjgM-1F; Fri, 19 May 2023 09:35:48 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 08/13] iomap: assign current->backing_dev_info in iomap_file_buffered_write Date: Fri, 19 May 2023 11:35:16 +0200 Message-Id: <20230519093521.133226-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Move the assignment to current->backing_dev_info from the callers into iomap_file_buffered_write to reduce boiler plate code and reduce the scope to just around the page dirtying loop. Note that zonefs was missing this assignment before. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/gfs2/file.c | 3 --- fs/iomap/buffered-io.c | 3 +++ fs/xfs/xfs_file.c | 5 ----- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 499ef174dec138..261897fcfbc495 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include "gfs2.h" @@ -1041,11 +1040,9 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, goto out_unlock; } - current->backing_dev_info = inode_to_bdi(inode); pagefault_disable(); ret = iomap_file_buffered_write(iocb, from, &gfs2_iomap_ops); pagefault_enable(); - current->backing_dev_info = NULL; if (ret > 0) written += ret; diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 550525a525c45c..b2779bd1f10611 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -3,6 +3,7 @@ * Copyright (C) 2010 Red Hat, Inc. * Copyright (C) 2016-2019 Christoph Hellwig. */ +#include #include #include #include @@ -869,8 +870,10 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i, if (iocb->ki_flags & IOCB_NOWAIT) iter.flags |= IOMAP_NOWAIT; + current->backing_dev_info = inode_to_bdi(iter.inode); while ((ret = iomap_iter(&iter, ops)) > 0) iter.processed = iomap_write_iter(&iter, i); + current->backing_dev_info = NULL; if (unlikely(ret < 0)) return ret; diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index bfba10e0b0f3c2..98d763cc3b114c 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -27,7 +27,6 @@ #include #include -#include #include #include #include @@ -717,9 +716,6 @@ xfs_file_buffered_write( if (ret) goto out; - /* We can write back this queue in page reclaim */ - current->backing_dev_info = inode_to_bdi(inode); - trace_xfs_file_buffered_write(iocb, from); ret = iomap_file_buffered_write(iocb, from, &xfs_buffered_write_iomap_ops); @@ -751,7 +747,6 @@ xfs_file_buffered_write( goto write_retry; } - current->backing_dev_info = NULL; out: if (iolock) xfs_iunlock(ip, iolock); From patchwork Fri May 19 09:35:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248082 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F2EBC7EE2D for ; Fri, 19 May 2023 09:38:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231752AbjESJiM (ORCPT ); Fri, 19 May 2023 05:38:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231699AbjESJhO (ORCPT ); Fri, 19 May 2023 05:37:14 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18A2519BF; Fri, 19 May 2023 02:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=g0XZ1SdajcGpQ1AF9r9lkRdRsXz7pcMVrMTOSW6r8Eo=; b=pQ7KSa/86Q7HW7fROWUx7jCR6O 5XFMJ9iXKvcRSF09WDb7T2Oe4gvkeIhaNzzaxy6czyIFHufAKCGsQQXKPj6V3g2+Yh3xCdmhw8Yem xgj5RovMsJ5sb9CwXmpuBgGG47h6W14hgsw8meXVfD8srvupuYd1wrBTP29pKyg4C/aN3aYMDx30V 3F+s9l05Pu0Nj8l8G8vVeSaGYZTNPRkhzs8LqCoRz22GQLqjxNh8lLcb8lcq9x99NvHbkhc0/jELZ O9XVqtERlrKY6QQYh73k45QPJOqZSIliql+BFfuGqGfwEgWEqLQweYUs7+GB+p22ORdFXz0Af4uz4 UCA5bGHA==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWc-00Fjh6-1P; Fri, 19 May 2023 09:35:50 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 09/13] iomap: use kiocb_write_and_wait and kiocb_invalidate_pages Date: Fri, 19 May 2023 11:35:17 +0200 Message-Id: <20230519093521.133226-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Use the common helpers for direct I/O page invalidation instead of open coding the logic. This leads to a slight reordering of checks in __iomap_dio_rw to keep the logic straight. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/iomap/direct-io.c | 55 ++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 45accd98344e79..ccf51d57619721 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -472,7 +472,6 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, const struct iomap_ops *ops, const struct iomap_dio_ops *dops, unsigned int dio_flags, void *private, size_t done_before) { - struct address_space *mapping = iocb->ki_filp->f_mapping; struct inode *inode = file_inode(iocb->ki_filp); struct iomap_iter iomi = { .inode = inode, @@ -481,11 +480,11 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, .flags = IOMAP_DIRECT, .private = private, }; - loff_t end = iomi.pos + iomi.len - 1, ret = 0; bool wait_for_completion = is_sync_kiocb(iocb) || (dio_flags & IOMAP_DIO_FORCE_WAIT); struct blk_plug plug; struct iomap_dio *dio; + loff_t ret = 0; trace_iomap_dio_rw_begin(iocb, iter, dio_flags, done_before); @@ -509,31 +508,29 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, dio->submit.waiter = current; dio->submit.poll_bio = NULL; + if (iocb->ki_flags & IOCB_NOWAIT) + iomi.flags |= IOMAP_NOWAIT; + if (iov_iter_rw(iter) == READ) { if (iomi.pos >= dio->i_size) goto out_free_dio; - if (iocb->ki_flags & IOCB_NOWAIT) { - if (filemap_range_needs_writeback(mapping, iomi.pos, - end)) { - ret = -EAGAIN; - goto out_free_dio; - } - iomi.flags |= IOMAP_NOWAIT; - } - if (user_backed_iter(iter)) dio->flags |= IOMAP_DIO_DIRTY; + + ret = kiocb_write_and_wait(iocb, iomi.len); + if (ret) + goto out_free_dio; } else { iomi.flags |= IOMAP_WRITE; dio->flags |= IOMAP_DIO_WRITE; - if (iocb->ki_flags & IOCB_NOWAIT) { - if (filemap_range_has_page(mapping, iomi.pos, end)) { - ret = -EAGAIN; + if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) { + ret = -EAGAIN; + if (iomi.pos >= dio->i_size || + iomi.pos + iomi.len > dio->i_size) goto out_free_dio; - } - iomi.flags |= IOMAP_NOWAIT; + iomi.flags |= IOMAP_OVERWRITE_ONLY; } /* for data sync or sync, we need sync completion processing */ @@ -549,31 +546,19 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, if (!(iocb->ki_flags & IOCB_SYNC)) dio->flags |= IOMAP_DIO_WRITE_FUA; } - } - - if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) { - ret = -EAGAIN; - if (iomi.pos >= dio->i_size || - iomi.pos + iomi.len > dio->i_size) - goto out_free_dio; - iomi.flags |= IOMAP_OVERWRITE_ONLY; - } - ret = filemap_write_and_wait_range(mapping, iomi.pos, end); - if (ret) - goto out_free_dio; - - if (iov_iter_rw(iter) == WRITE) { /* * Try to invalidate cache pages for the range we are writing. * If this invalidation fails, let the caller fall back to * buffered I/O. */ - if (invalidate_inode_pages2_range(mapping, - iomi.pos >> PAGE_SHIFT, end >> PAGE_SHIFT)) { - trace_iomap_dio_invalidate_fail(inode, iomi.pos, - iomi.len); - ret = -ENOTBLK; + ret = kiocb_invalidate_pages(iocb, iomi.len); + if (ret) { + if (ret != -EAGAIN) { + trace_iomap_dio_invalidate_fail(inode, iomi.pos, + iomi.len); + ret = -ENOTBLK; + } goto out_free_dio; } From patchwork Fri May 19 09:35:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248081 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 884FDC77B7F for ; Fri, 19 May 2023 09:38:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231795AbjESJiN (ORCPT ); Fri, 19 May 2023 05:38:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231804AbjESJhQ (ORCPT ); Fri, 19 May 2023 05:37:16 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6C241BC1; Fri, 19 May 2023 02:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=bXtYYEEzQwvZPWpQse6yFS2DlWFyrRFvHXQe3dgGWLU=; b=wuR5MfjM+D3bTZWoEm9c9T3FyQ Jue/kbHK6tmzfma8e+SaYSkRo0i0M95KfzwDKIl7yAZarwpeGlFg8SOccbWg+5smRc3AQ4HdXO5Wr nxv736/1Pra0TlJRc6gOvRj0yJnIoeus3Ea9ZcLZX9vsbfDhxOOcJdu2Sh3OLpn1iJaVfJZVoL+PO 6JYYrGM32hNNnf9ay0x08Yy8FXV4AEv6azjWxZA7R3S8/gudYOrARKgoCUAPoEHO6BpLCM3Eu/iHd Ze6v9o/MZ4FMpWwAoU8d5cZ1OtyW+xcKH2yx0ol+dIujh/Uz9vLoSMKaWdOFEP9SsxpBhnAOmgW1i fsiOwFhw==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWe-00FjiA-3B; Fri, 19 May 2023 09:35:53 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 10/13] fs: factor out a direct_write_fallback helper Date: Fri, 19 May 2023 11:35:18 +0200 Message-Id: <20230519093521.133226-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add a helper dealing with handling the syncing of a buffered write fallback for direct I/O. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/libfs.c | 36 ++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ mm/filemap.c | 59 ++++++++++------------------------------------ 3 files changed, 50 insertions(+), 47 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 89cf614a327158..9f3791fc6e0715 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1613,3 +1613,39 @@ u64 inode_query_iversion(struct inode *inode) return cur >> I_VERSION_QUERIED_SHIFT; } EXPORT_SYMBOL(inode_query_iversion); + +ssize_t direct_write_fallback(struct kiocb *iocb, struct iov_iter *iter, + ssize_t direct_written, ssize_t buffered_written) +{ + struct address_space *mapping = iocb->ki_filp->f_mapping; + loff_t pos = iocb->ki_pos, end; + int err; + + /* + * If the buffered write fallback returned an error, we want to return + * the number of bytes which were written by direct I/O, or the error + * code if that was zero. + * + * Note that this differs from normal direct-io semantics, which will + * return -EFOO even if some bytes were written. + */ + if (unlikely(buffered_written < 0)) + return buffered_written; + + /* + * We need to ensure that the page cache pages are written to disk and + * invalidated to preserve the expected O_DIRECT semantics. + */ + end = pos + buffered_written - 1; + err = filemap_write_and_wait_range(mapping, pos, end); + if (err < 0) { + /* + * We don't know how much we wrote, so just return the number of + * bytes which were direct-written + */ + return err; + } + invalidate_mapping_pages(mapping, pos >> PAGE_SHIFT, end >> PAGE_SHIFT); + return direct_written + buffered_written; +} +EXPORT_SYMBOL_GPL(direct_write_fallback); diff --git a/include/linux/fs.h b/include/linux/fs.h index e4efc1792a877a..576a945db178ef 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2738,6 +2738,8 @@ extern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_direct_write(struct kiocb *, struct iov_iter *); ssize_t generic_perform_write(struct kiocb *, struct iov_iter *); +ssize_t direct_write_fallback(struct kiocb *iocb, struct iov_iter *iter, + ssize_t direct_written, ssize_t buffered_written); ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos, rwf_t flags); diff --git a/mm/filemap.c b/mm/filemap.c index c1b988199aece5..875b2108d0a05f 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -4008,25 +4008,21 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; struct address_space *mapping = file->f_mapping; - struct inode *inode = mapping->host; - ssize_t written = 0; - ssize_t err; - ssize_t status; + struct inode *inode = mapping->host; + ssize_t ret; /* We can write back this queue in page reclaim */ current->backing_dev_info = inode_to_bdi(inode); - err = file_remove_privs(file); - if (err) + ret = file_remove_privs(file); + if (ret) goto out; - err = file_update_time(file); - if (err) + ret = file_update_time(file); + if (ret) goto out; if (iocb->ki_flags & IOCB_DIRECT) { - loff_t pos, endbyte; - - written = generic_file_direct_write(iocb, from); + ret = generic_file_direct_write(iocb, from); /* * If the write stopped short of completing, fall back to * buffered writes. Some filesystems do this for writes to @@ -4034,46 +4030,15 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) * not succeed (even if it did, DAX does not handle dirty * page-cache pages correctly). */ - if (written < 0 || !iov_iter_count(from) || IS_DAX(inode)) - goto out; - - pos = iocb->ki_pos; - status = generic_perform_write(iocb, from); - /* - * If generic_perform_write() returned a synchronous error - * then we want to return the number of bytes which were - * direct-written, or the error code if that was zero. Note - * that this differs from normal direct-io semantics, which - * will return -EFOO even if some bytes were written. - */ - if (unlikely(status < 0)) { - err = status; - goto out; - } - /* - * We need to ensure that the page cache pages are written to - * disk and invalidated to preserve the expected O_DIRECT - * semantics. - */ - endbyte = pos + status - 1; - err = filemap_write_and_wait_range(mapping, pos, endbyte); - if (err == 0) { - written += status; - invalidate_mapping_pages(mapping, - pos >> PAGE_SHIFT, - endbyte >> PAGE_SHIFT); - } else { - /* - * We don't know how much we wrote, so just return - * the number of bytes which were direct-written - */ - } + if (ret >= 0 && iov_iter_count(from) && !IS_DAX(inode)) + ret = direct_write_fallback(iocb, from, ret, + generic_perform_write(iocb, from)); } else { - written = generic_perform_write(iocb, from); + ret = generic_perform_write(iocb, from); } out: current->backing_dev_info = NULL; - return written ? written : err; + return ret; } EXPORT_SYMBOL(__generic_file_write_iter); From patchwork Fri May 19 09:35:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248080 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9971BC7EE2D for ; Fri, 19 May 2023 09:38:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231862AbjESJiN (ORCPT ); Fri, 19 May 2023 05:38:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231810AbjESJhQ (ORCPT ); Fri, 19 May 2023 05:37:16 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DF271BC6; Fri, 19 May 2023 02:36:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=TKBAB7v33dbYW3H4NRpBXoH9tha0ccQ02cfBeOuFf/4=; b=jBbC+jMl9D3UjfJN7p2yKZDP/I WbBFLIN3Q/AJih3OxKSHbTD9vT/F1tJobu4KuSjWuiUGnD5rFBmeuEaeD/Iu5pzKBe+WoF0cJV/pR aHdHe3VblJTeUN80/WZVfFkLjN2xPcAqkhJGTHlmMCBAXleLOTmJaaYavT1/S9aM9V0FApxTI8BsN kq2VaEl7CyULWIrWWkY30KLE99zxPFDr6mlVbG53PUvDT0Owj+1Oafd0P6BmL8cNhjdjQCmT8ZUKw mgdHI+yL0Zy6QHpBrK9tCvQI2IS8OZd316ApM4Rm2MZrQDKXQ1/k3sGBk62SyeqnLCKYpmESn7t8M izw91Nrw==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWh-00Fjj0-1m; Fri, 19 May 2023 09:35:55 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 11/13] fuse: update ki_pos in fuse_perform_write Date: Fri, 19 May 2023 11:35:19 +0200 Message-Id: <20230519093521.133226-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Both callers of fuse_perform_write need to updated ki_pos, move it into common code. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/fuse/file.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 89d97f6188e05e..fd2f27f2144750 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1329,7 +1329,10 @@ static ssize_t fuse_perform_write(struct kiocb *iocb, fuse_write_update_attr(inode, pos, res); clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state); - return res > 0 ? res : err; + if (!res) + return err; + iocb->ki_pos += res; + return res; } static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) @@ -1378,42 +1381,36 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) goto out; if (iocb->ki_flags & IOCB_DIRECT) { - loff_t pos = iocb->ki_pos; written = generic_file_direct_write(iocb, from); if (written < 0 || !iov_iter_count(from)) goto out; - pos += written; - - written_buffered = fuse_perform_write(iocb, mapping, from, pos); + written_buffered = fuse_perform_write(iocb, mapping, from, + iocb->ki_pos); if (written_buffered < 0) { err = written_buffered; goto out; } - endbyte = pos + written_buffered - 1; + endbyte = iocb->ki_pos + written_buffered - 1; - err = filemap_write_and_wait_range(file->f_mapping, pos, + err = filemap_write_and_wait_range(file->f_mapping, + iocb->ki_pos, endbyte); if (err) goto out; invalidate_mapping_pages(file->f_mapping, - pos >> PAGE_SHIFT, + iocb->ki_pos >> PAGE_SHIFT, endbyte >> PAGE_SHIFT); written += written_buffered; - iocb->ki_pos = pos + written_buffered; + iocb->ki_pos += written_buffered; } else { written = fuse_perform_write(iocb, mapping, from, iocb->ki_pos); - if (written >= 0) - iocb->ki_pos += written; } out: current->backing_dev_info = NULL; inode_unlock(inode); - if (written > 0) - written = generic_write_sync(iocb, written); - return written ? written : err; } From patchwork Fri May 19 09:35:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248083 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6776AC7EE2F for ; Fri, 19 May 2023 09:38:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231810AbjESJiU (ORCPT ); Fri, 19 May 2023 05:38:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231825AbjESJhT (ORCPT ); Fri, 19 May 2023 05:37:19 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E22B61BD4; Fri, 19 May 2023 02:36:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=STVg9hQSNCoHnaWP+j57/x1LHg0FYksrLdPn28xq/k4=; b=lQYT2kwaUEtArFfEb79xA//fBJ qogp7VjnGEoqLT6bjXgEup01sK0KL/4RiA1Fe8gDUeej2m9QIQCe2S/3Jocd+N+cdKp668C9VvAeW phbQS3w1Z6z10f/6yehWWZEY+S9fYiGxT0TfhkNTWvUDWB9iDdV0uv+kx5oc3HcI/0ayvEc19i8ma zliWUfhpNpatxjBI+G08zM6lhwpCdNsKd9r0pUWyuMh5c22vx8ahQkEsYV+AjmSNW3RXuG4Ue3k+H sTtOSNleeSciqjt1JlkB9rX6zj9iM4pWW19+tNfp7ueTD0W+O2LSYhMGFcK+0P4fgPFc3EgSG2rLh YUxjFJXg==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWk-00Fjjz-1H; Fri, 19 May 2023 09:35:58 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 12/13] fuse: drop redundant arguments to fuse_perform_write Date: Fri, 19 May 2023 11:35:20 +0200 Message-Id: <20230519093521.133226-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org pos is always equal to iocb->ki_pos, and mapping is always equal to iocb->ki_filp->f_mapping. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/fuse/file.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index fd2f27f2144750..5f7b58798f99fc 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1280,13 +1280,13 @@ static inline unsigned int fuse_wr_pages(loff_t pos, size_t len, max_pages); } -static ssize_t fuse_perform_write(struct kiocb *iocb, - struct address_space *mapping, - struct iov_iter *ii, loff_t pos) +static ssize_t fuse_perform_write(struct kiocb *iocb, struct iov_iter *ii) { + struct address_space *mapping = iocb->ki_filp->f_mapping; struct inode *inode = mapping->host; struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_inode *fi = get_fuse_inode(inode); + loff_t pos = iocb->ki_pos; int err = 0; ssize_t res = 0; @@ -1385,8 +1385,7 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) if (written < 0 || !iov_iter_count(from)) goto out; - written_buffered = fuse_perform_write(iocb, mapping, from, - iocb->ki_pos); + written_buffered = fuse_perform_write(iocb, from); if (written_buffered < 0) { err = written_buffered; goto out; @@ -1406,7 +1405,7 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) written += written_buffered; iocb->ki_pos += written_buffered; } else { - written = fuse_perform_write(iocb, mapping, from, iocb->ki_pos); + written = fuse_perform_write(iocb, from); } out: current->backing_dev_info = NULL; From patchwork Fri May 19 09:35:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13248084 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB33CC77B7A for ; Fri, 19 May 2023 09:38:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231833AbjESJil (ORCPT ); Fri, 19 May 2023 05:38:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230358AbjESJhz (ORCPT ); Fri, 19 May 2023 05:37:55 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E98910C9; Fri, 19 May 2023 02:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=lKV8h274a8dJZYXDnZBnFaYep44iQbnn3gg/wqWXLcU=; b=cWIcWF+NCJsR16lt+GN3SyqYi8 20m98Sg1zXHAv7DP2DoTSsINVBJLT/jPU8582VtWjlVAlPAxQNKVTFaC0YOnpEd5FvRMnBLi4ey94 K4WsXk4K1iXMjE0WTmxaYPPuCk8QMzpH/S5exdIPqIWUyCVLjzR3cBZl2UWcus5acmbfLvwlunIjm 4ycE2BJo+CC540gWRfo2M+hpyeOMIoCToQspTNQ3U/ipx7csq77R4XMThx+m4QCcDyjZBfA7VJFoS hKoo+WYpC8HvPYhP5WamSeG2WcUggfS4/afnmf7Abg1NQrcteg0tvokFZlTlL+/0VmwC02dijjfgF XYj4OTgA==; Received: from [2001:4bb8:188:3dd5:e8d0:68bb:e5be:210a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pzwWm-00Fjl7-2x; Fri, 19 May 2023 09:36:01 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE SYSTEM), cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 13/13] fuse: use direct_write_fallback Date: Fri, 19 May 2023 11:35:21 +0200 Message-Id: <20230519093521.133226-14-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519093521.133226-1-hch@lst.de> References: <20230519093521.133226-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Use the generic direct_write_fallback helper instead of duplicating the logic. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/fuse/file.c | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 5f7b58798f99fc..02ab446ab57f1f 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1340,11 +1340,9 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) struct file *file = iocb->ki_filp; struct address_space *mapping = file->f_mapping; ssize_t written = 0; - ssize_t written_buffered = 0; struct inode *inode = mapping->host; ssize_t err; struct fuse_conn *fc = get_fuse_conn(inode); - loff_t endbyte = 0; if (fc->writeback_cache) { /* Update size (EOF optimization) and mode (SUID clearing) */ @@ -1382,28 +1380,9 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) if (iocb->ki_flags & IOCB_DIRECT) { written = generic_file_direct_write(iocb, from); - if (written < 0 || !iov_iter_count(from)) - goto out; - - written_buffered = fuse_perform_write(iocb, from); - if (written_buffered < 0) { - err = written_buffered; - goto out; - } - endbyte = iocb->ki_pos + written_buffered - 1; - - err = filemap_write_and_wait_range(file->f_mapping, - iocb->ki_pos, - endbyte); - if (err) - goto out; - - invalidate_mapping_pages(file->f_mapping, - iocb->ki_pos >> PAGE_SHIFT, - endbyte >> PAGE_SHIFT); - - written += written_buffered; - iocb->ki_pos += written_buffered; + if (written >= 0 && iov_iter_count(from)) + written = direct_write_fallback(iocb, from, written, + fuse_perform_write(iocb, from)); } else { written = fuse_perform_write(iocb, from); }