From patchwork Wed May 24 06:38:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13253304 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BA1EC77B7C for ; Wed, 24 May 2023 06:38:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD2CB900003; Wed, 24 May 2023 02:38:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8299280001; Wed, 24 May 2023 02:38:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 924EE900004; Wed, 24 May 2023 02:38:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 832E6900003 for ; Wed, 24 May 2023 02:38:37 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5774A1208BD for ; Wed, 24 May 2023 06:38:37 +0000 (UTC) X-FDA: 80824195074.25.75458F5 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf01.hostedemail.com (Postfix) with ESMTP id 9330F40010 for ; Wed, 24 May 2023 06:38:35 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=tY0urzL7; dmarc=none; spf=none (imf01.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684910315; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3ZBFgl7r+XFxtKE+zV/zBQvmUj5fJULrZ1iHCvCgOQw=; b=e7iwwXHw+B9CSouJlSgFWjezdNyYMTuojjy5GaJMxkcEV3a9W6SFgr9CwxNdidN382P1Dn Elhs5VHwclTXJgk2gGwlILAaK+OAZfoE/kRi7F+iO7j96xlZJr42XrctSoAjqOhNmqR78R 0cIuU0D4a87VnyxRepcYMtjS0PjU4HI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=tY0urzL7; dmarc=none; spf=none (imf01.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684910315; a=rsa-sha256; cv=none; b=U/smUxFcmYAMXVTKTyrrxhcCWQRtuOHul9rUkJI9bXx/j6nRgMX2A34BHrHm9tY+mj5UtP Jv2SlpSLpjX1bclV9Wg3KHcIRzJFbsCdGtfw2pX1JEGowEzTJz6KQCPWybfTrDw5ULV84O kcD9n4Ij0K+kb0g5ZT4PnzgqPxYS4wc= 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=3ZBFgl7r+XFxtKE+zV/zBQvmUj5fJULrZ1iHCvCgOQw=; b=tY0urzL7m/HaNOr8G/zUxyGp6S FoIjFAcvbfI8RdwE9ZHdSIYwIRQyGst2BgdCR0tD2X6tKPmuCSp0vBcKBcdPFZuE4GHVVoD9zLDr0 b+Yh7HhLY2ZVQm7bq03t8ljOce4Vrq0LuSG5ojDtyi+R37g358hJD9UQGsuI81vZLgpsyzd+szQHt pdXXj3y5w+W5irwoxqxjY/b0xjxll0KN9YQ9zY6ubXAMLGTfDy5pieRjAIOb2YGFpXe86r0Tgm2FI Cq+X1Exb264UkIRUBUZY5Z8AANOVfor9+6VCoY5hlbVi75rryBPnYgBjKHjo2s6K7l09DQi8/Kj4B W+d85bUg==; Received: from [2001:4bb8:188:23b2:cbb8:fcea:a637:5089] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1i8W-00CVeW-2b; Wed, 24 May 2023 06:38:17 +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, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 01/11] backing_dev: remove current->backing_dev_info Date: Wed, 24 May 2023 08:38:00 +0200 Message-Id: <20230524063810.1595778-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524063810.1595778-1-hch@lst.de> References: <20230524063810.1595778-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 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9330F40010 X-Stat-Signature: cjazo6muzm1ok99hbpz489zh8nn9zfqm X-HE-Tag: 1684910315-639572 X-HE-Meta: U2FsdGVkX1/PeY/sw2H0XfGQXF4HMy/MHK9MdH1UVG/yPvmFlyoBjYmIb4q5OK2yqTcxzBOMFyCPY6rlCoTrv22f16S9EeaWdZ8UY8Yr0YBTJnhbUTISpLt2d5oKitPAUrGfY8mz2g6INO8rN27dZUYewkFmqJVgBEee0GOoBCX4957+z+PJ7p43617VRNFv1p2dc1jSzeP7bYVHpkO9sEpQjOMelsmLC6DFF7KyeNpOVd3wE1jRBqPacrK1W/PtiYsr1hWy9yrQnBm1yqG6OzhA4el4Mza1F4PGOjSXPHZ55Gcs0cMDfAFEpk5YTGWIV3bV3QuQieSdsC0zrT7rjDl5k4pIpybV9n2Ve8+wl213+igT13C0rxHIeXQ+fzRTAdNytBVYiI6hT79cdfqg1nr0ZOrT865uGfF70XUs+WvzERcT1HSHYSVgkBX+ZQjtPqyHu4ROhG8viVSwVIi6DVyPu96/nmmQbTsCNq7NaWNAkIlA9sbhBOvcqPCvf6J25eIE3PmCQdOO95pfscyoadYyGOmqABliTMuGlabRIlP6s3jJmFQKf5/1Nqgt4xDl5sWybYMkIoKLtCL4K/iyKRrbjhP8GrRpJtLgjvUYxLP+BkuNEsItNlgqewUWtPhNbnsGiR5hcmyxAt3VysPx+Tg0ARcVKT8AYYJrdhTJfzQYqOmzWdeXl1qx4oQcSvf52Fa0i3dchBV3CR78hiM38rXlnkLEGYQ8KnQlX1bvLG4YwE8uOx3TtnuO0eo8YPWIMHC1mOAk1c0hj+Yukvv9KOxILosKpbO2RH/N3YLfWIMmrrsrsJdzSv+F9+4JOpKVIX6ESMRmvbBcliQ8tVX7m1gPRyHrYMpoZ6FLRxpZDgS3s4y9nKfgb0vLZfW/OaaBN+/tL7HTmqtYvVoCuRuqmgudkEmpZecelk9HHnRtz2wRVqKSs1f58fQZxeAG2WHJG9wvThmtIDcc2TUX6n0 Z7utQgaa QoPTXEwFBSDov4VoMVOebzvBFfYcarcmXNh6CzZt4DNmw+O9GiGxScCiYEBUxDga/nIMocbfDCPDaCaaJzr/QFFzfVMyqUbHSTPjm0neLicRO9JGUQlmtszOVqcjY01IUj1WIzXFLMLAmQKQUFG4Ud12AQSKkooQwgDnY8RKCa+pc8ZktJSMwP/M7meu5varFCllFJ10dyCJSJM3wTDQvPA4vg1tN/h638yLraQ/hPz3Y4WgS40FlUV0k4l0U64c11ONJKo9ifuShRKzGEEd9+yHNeSncfJlMbnxKtsE/inVCLGVFbe0wq4NfIl65VDuASORpCSbVfhJUoTyHjUIw8XC7uIe3OZAhwFVE71ghZpjjtpjUClj/43yioOTUbkpEg2ibZWPJGrbH12FxMp6wUjKI01A0iQmyxJggoVrZg8o6SYPcmqfTbnQ0KJQJBZ70aJqoaJOeov+WD2I/cmai6e5Pvg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The last user of current->backing_dev_info disappeared in commit b9b1335e6403 ("remove bdi_congested() and wb_congested() and related functions"). Remove the field and all assignments to it. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Reviewed-by: Hannes Reinecke --- fs/btrfs/file.c | 6 +----- fs/ceph/file.c | 4 ---- fs/ext4/file.c | 2 -- fs/f2fs/file.c | 2 -- fs/fuse/file.c | 4 ---- fs/gfs2/file.c | 2 -- fs/nfs/file.c | 5 +---- fs/ntfs/file.c | 2 -- fs/ntfs3/file.c | 3 --- fs/xfs/xfs_file.c | 4 ---- include/linux/sched.h | 3 --- mm/filemap.c | 3 --- 12 files changed, 2 insertions(+), 38 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index f649647392e0e4..ecd43ab66fa6c7 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1145,7 +1145,6 @@ static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from, !(BTRFS_I(inode)->flags & (BTRFS_INODE_NODATACOW | BTRFS_INODE_PREALLOC))) return -EAGAIN; - current->backing_dev_info = inode_to_bdi(inode); ret = file_remove_privs(file); if (ret) return ret; @@ -1165,10 +1164,8 @@ static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from, loff_t end_pos = round_up(pos + count, fs_info->sectorsize); ret = btrfs_cont_expand(BTRFS_I(inode), oldsize, end_pos); - if (ret) { - current->backing_dev_info = NULL; + if (ret) return ret; - } } return 0; @@ -1689,7 +1686,6 @@ ssize_t btrfs_do_write_iter(struct kiocb *iocb, struct iov_iter *from, if (sync) atomic_dec(&inode->sync_writers); - current->backing_dev_info = NULL; return num_written; } diff --git a/fs/ceph/file.c b/fs/ceph/file.c index f4d8bf7dec88a8..c8ef72f723badd 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) @@ -1940,7 +1937,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 d101b3b0c7dad8..bc430270c23c19 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -285,9 +285,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 5ac53d2627d20d..4f423d367a44b9 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) { iocb->ki_pos += ret; diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 89d97f6188e05e..97d435874b14aa 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1362,9 +1362,6 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) writethrough: inode_lock(inode); - /* We can write back this queue in page reclaim */ - current->backing_dev_info = inode_to_bdi(inode); - err = generic_write_checks(iocb, from); if (err <= 0) goto out; @@ -1409,7 +1406,6 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) iocb->ki_pos += written; } out: - current->backing_dev_info = NULL; inode_unlock(inode); if (written > 0) written = generic_write_sync(iocb, written); diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 300844f50dcd28..904a0d6ac1a1a9 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -1041,11 +1041,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) { iocb->ki_pos += ret; written += ret; diff --git a/fs/nfs/file.c b/fs/nfs/file.c index f0edf5a36237d1..665ce3fc62eaf4 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/fs/ntfs/file.c b/fs/ntfs/file.c index c481b14e4fd989..e296f804a9c442 100644 --- a/fs/ntfs/file.c +++ b/fs/ntfs/file.c @@ -1911,11 +1911,9 @@ static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) inode_lock(vi); /* We can write back this queue in page reclaim. */ - current->backing_dev_info = inode_to_bdi(vi); err = ntfs_prepare_file_for_write(iocb, from); if (iov_iter_count(from) && !err) written = ntfs_perform_write(file, from, iocb->ki_pos); - current->backing_dev_info = NULL; inode_unlock(vi); iocb->ki_pos += written; if (likely(written > 0)) diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 9a3d55c367d920..86d16a2c8339ca 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -820,7 +820,6 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from) if (!pages) return -ENOMEM; - current->backing_dev_info = inode_to_bdi(inode); err = file_remove_privs(file); if (err) goto out; @@ -993,8 +992,6 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from) out: kfree(pages); - current->backing_dev_info = NULL; - if (err < 0) return err; diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index aede746541f8ae..431c3fd0e2b598 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -717,9 +717,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); @@ -753,7 +750,6 @@ xfs_file_buffered_write( goto write_retry; } - current->backing_dev_info = NULL; out: if (iolock) xfs_iunlock(ip, iolock); diff --git a/include/linux/sched.h b/include/linux/sched.h index eed5d65b8d1f4d..54780571fe9a07 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -41,7 +41,6 @@ /* task_struct member predeclarations (sorted alphabetically): */ struct audit_context; -struct backing_dev_info; struct bio_list; struct blk_plug; struct bpf_local_storage; @@ -1186,8 +1185,6 @@ struct task_struct { /* VM state: */ struct reclaim_state *reclaim_state; - struct backing_dev_info *backing_dev_info; - struct io_context *io_context; #ifdef CONFIG_COMPACTION diff --git a/mm/filemap.c b/mm/filemap.c index b4c9bd368b7e58..33b54660ad2b39 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3991,8 +3991,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) ssize_t err; ssize_t status; - /* We can write back this queue in page reclaim */ - current->backing_dev_info = inode_to_bdi(inode); err = file_remove_privs(file); if (err) goto out; @@ -4053,7 +4051,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) iocb->ki_pos += written; } out: - current->backing_dev_info = NULL; return written ? written : err; } EXPORT_SYMBOL(__generic_file_write_iter); From patchwork Wed May 24 06:38:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13253303 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C495C77B7A for ; Wed, 24 May 2023 06:38:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0CCB6B0072; Wed, 24 May 2023 02:38:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B4669900003; Wed, 24 May 2023 02:38:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0DD46B0075; Wed, 24 May 2023 02:38:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 920066B0072 for ; Wed, 24 May 2023 02:38:33 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6124B4089D for ; Wed, 24 May 2023 06:38:33 +0000 (UTC) X-FDA: 80824194906.12.E649CD6 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id B0344C0003 for ; Wed, 24 May 2023 06:38:31 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ke0+rXm1; spf=none (imf28.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684910311; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=i1RqdoBmGpSI4AoluhMWSmKwEQoLh7rSlvwZtq3xMpc=; b=kEGJPq0pw8CFW5Bqkb5XtA7GgJGB3UF9MzMx9v3uxjK9CTA9ZALNZSbQj/UrXqSIU4zmna W/FypHRw+AuV7/YKfTt2hkrUc1a5d0LccuAup8DabxGEqN8LlgJQwFqVmvNMbZkeVJwDW/ haPme8KnEm0x1v3z1DZlGqYUz4onqhs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684910311; a=rsa-sha256; cv=none; b=QcKcBl3ev/T6oKNZm10QWetJ9SlLqhPXySiJYqFA+OfeJs//NhYryXLkgGmvjhs6PZLQEd nyv1lFqhguMKFCcenTuoE+UvWcEcKWIKBe+goXx5xflEMPOUERfqRFisiiaGuuD2K/iqAY yqZ/AkxHwYM+6gx7JyB2PAN0Ye2dQxc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ke0+rXm1; spf=none (imf28.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none 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=i1RqdoBmGpSI4AoluhMWSmKwEQoLh7rSlvwZtq3xMpc=; b=ke0+rXm1I+H4jWkGSmB5Pvjfls Ax469rTeh6NFooGWSj+OyR/gQOOCNXmTcHB//65B4AAeTWh+8v+kOnTf83phdlbLYQANm/xrelpKO RPEcRgSn5ZizNYXFRdqRNbcCBJoc/CloJeJBhecvABTLDE00F5dvyIHhM6+UnqHl3jIAza8/mg3No RtjM/skaLWEkdssyDF1XBD8OVIZXSCWSZQwuR7WUjIhOHEVNyPqGJR5SC/DSSjJfkwfGUPruKxAzS 4ZZSQ6AZRI0e9yGK0i67PwJ4CoUjusCveYX70o0pH4iDQMSa7dPAZ0aeXl7tzo1DZvnjxd5jcRdXu z+zNBwCg==; Received: from [2001:4bb8:188:23b2:cbb8:fcea:a637:5089] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1i8a-00CVes-0r; Wed, 24 May 2023 06:38:20 +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, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 02/11] iomap: update ki_pos a little later in iomap_dio_complete Date: Wed, 24 May 2023 08:38:01 +0200 Message-Id: <20230524063810.1595778-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524063810.1595778-1-hch@lst.de> References: <20230524063810.1595778-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 X-Stat-Signature: y3xqs1w7ar1e51rqgd8w8s7fw36wmf5y X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B0344C0003 X-Rspam-User: X-HE-Tag: 1684910311-861594 X-HE-Meta: U2FsdGVkX19l4JRul6gimpEvm7SRckM/Clhlz4aoDKX3cYrms1Fe3H518NjrC/IemAs0K2/qdd/SvBqk096FV5OGTP7aCjkZkgXx3ETH6/xvpoQ6aR85EtpmIQirF/GmHE0ys0JmSolWu1rIDr+lHY1ui4JgBqqdVZr6vpyJwQjJP8FPAMB1X9rD6YVBeLm/Ljr6tH9ECISu3QqtMITYYlfNCGzIiXAWMQGUunhHQoWyOol3Nb0t5MfKc9fx2VwLAZho7Vl5rE0aF3moCemRnr98RmWycL4mOSUKo8UB5XYQL4kkF0hm1nXnELYnk+wnd5zBpBX/VR4izzUKRsDW5sH0b5YxshHoSwFX+BsGmoEsHSRqCbp+xmlIxckp4TwdcGJpscm0mbO4f+cun0AP7cLjbW9zzZesJ2lhA+DoO8xP/D4vBemkPHOw43/acEWOcPHmk560OZTIdfN6UfME++1+vnpXYI3wgtPJtuMmO7mgmpUTnBRh7zQ6FndIKHQhhZ+LvwDlyylz661YYKEAHdLLzQ1ZnADGKHEiPvDUG/RgVa51QGB2IaqxXBz67xmoEG34S9JHMClAKjgrlWt0mGNj0z0LLqnL5RDcMId8pLnhJEjhsDPcEVsslJ5S74DRWPaznIe1wvjWJkc1sux0EtY36C0VRAqydbQgwKOzLYEpItHbt+Knx+SHx0QfjYKYok3OFUlDd/0ZuSr3atKjN/07Aq9/kKKsvvtaY9dSr8zhcMrUKYZBSjMYW+DVmriE0M8vd9T+VBFiPAD3lOPRggDNJB6arl7xa/db/Pehnvq/GqjjYkDp/hgMBOA3qeI1R3jWsq1EHpafO1Nu/39xohfTWjKzkem2qFqX87xw/PUVE1SJRVaNjTYTe8gj4IREEtaY+nTbpBjgcEZV5jiOiz5wjSL4QO4lybDUEk2zb0Rw6hbOV2QZVr/QxkUWSzimIhMkYaYpuXnG5/8D80T 35bNfQo/ J8gFh1Uz51TD4XDrnRv+iJ2Twwv5hqsX00P3pS2rFoHzZPDPHHlBibqwwA1Bg41+5Rlgqjp1LyRo4gZ3XCZA1XwzV+v7PDgEERjo19QzVPbv4xMdioPVQouQzN0lx12bFQCQnXPTzqP/fY98bN7ge0q/A8q8dGP3wXN/3jp8tCOYSowbHWwd9Lyp2kEwPpVyh6sPl0xzZTa7ZqlfBVG/Ql0Yfqg3jhKpfOC+0PYN38mvqW5CfzcCh+6RCozIuZp/UU1MnHwTE31ou+mFxih9J5SKKtsJtpcuWXnBgoMqjujik3kpWrACLHulWSMr0oEsmA7UdM0vyxhnNKBkVhfv4KJgp5BwYgoPlnqttJEUlF2z1rQeQX9M+++KhUJHlmpPrH8k4tsi2g3qL8fevXdujKVzelhjCXAyWRDNqBjMqAaekuihCrn2596dOeB1YUM5cqYGNpILixHAJ6rZu2YndHQKm4C3pfIIC8DGPGUmaJqTfXORk85MblN7ilLx7A83YagNsiBVLJR0xk3A= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Darrick J. Wong Reviewed-by: Hannes Reinecke --- 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 Wed May 24 06:38:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13253306 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DE9CC77B7C for ; Wed, 24 May 2023 06:38:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7777D280003; Wed, 24 May 2023 02:38:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 72AAD280001; Wed, 24 May 2023 02:38:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C8CC280003; Wed, 24 May 2023 02:38:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4D559280001 for ; Wed, 24 May 2023 02:38:39 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 22AC3140867 for ; Wed, 24 May 2023 06:38:39 +0000 (UTC) X-FDA: 80824195158.16.94299EC Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP id 655E940012 for ; Wed, 24 May 2023 06:38:37 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=U875Nf6B; spf=none (imf07.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684910317; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eC4fKlJuAZk6Bs9zfH3GxbdW7XFrPuxkzUVDWdmQe5g=; b=L4+04BabAa2Tw4EAxkAJNu34+soE6OY22LJmVbO1RvteyTUXYysrrkSwqAEREEAgOL1cJl 860tbw1PksuhJCQpZ28rB9c+t+aqSzisL/vj152prP21hnlG5EdcxTyoGhEHywZyGkpb36 GyaGjX8kt44MxLHU6WUtqob9fFn+Ql4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684910317; a=rsa-sha256; cv=none; b=OWhIiWXTk2nAKTHXdcrjHdbiTzD3WsXvARLqS8tRgfO74AysQlueskYqxkfc+hJYsdn3Kw rN2/IB4Rv+BOMTNfia8FvOi3406BoPCoSSQYBqRQEI2AqxJBVj6+dbqW1duEkxw7PJKpzx iCphrEgL5WQ/crF9EdEA+p9HzDV4pKM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=U875Nf6B; spf=none (imf07.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none 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=eC4fKlJuAZk6Bs9zfH3GxbdW7XFrPuxkzUVDWdmQe5g=; b=U875Nf6B+VixmZn3RCK57UbTUU IFC0MeeaeIlbgfB/LVshuRLIofQrNBg07H6ArsN/S4kztKs2Gdx3sBck98mxzZ6RTXhCQBVXC7/u7 i9xBhUMRbD7a1jKdA/JPzbaHfjiavwo4CIWKOoe1Yj8Z05UGrZF2AThxvYxwSQAyFfc87tXPIZ4vh V39JXltuaCnrdgxByGkJWT2mJPgbOnQgbZY/NGQM3agFFFH5l75VSVn8S/KTo2KbrkM03l+cEvvBf e/uITYC+j0JHWGaMUQ5DoVgNuR0TXMLu4m5OFU/iCDA+DzlVkPoKbiFDcpNMAlA0wT7qfVqH4Z4nE WHCJyCJw==; Received: from [2001:4bb8:188:23b2:cbb8:fcea:a637:5089] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1i8c-00CVf8-2h; Wed, 24 May 2023 06:38:23 +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, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 03/11] filemap: update ki_pos in generic_perform_write Date: Wed, 24 May 2023 08:38:02 +0200 Message-Id: <20230524063810.1595778-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524063810.1595778-1-hch@lst.de> References: <20230524063810.1595778-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 X-Rspamd-Queue-Id: 655E940012 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ysg1xf4nh1rmp6gze7eifujbq5yc8d16 X-HE-Tag: 1684910317-344319 X-HE-Meta: U2FsdGVkX1+FTREMm2nP74FQlVYi7gW4BUZUcsVxRIVPPSBz7rTYzERiY2/dp5jrLtGZakACHeYRswcO/7arOE68qwudiV+Kx4d8luGmJF5ryAkkuuzxJ2OOP+po0Lu5syXAgujler8dnk58b1DMZa/hF7Kmp9QwVS1J1nvWE+v622qDMtVHJ8buXczV99RgxeTnE/lBnEv9yvWUU7bGMDkbbR3GQwRAq1dGm+DHZ3QDncQOjGMBbLs2kQPMIYraWdPDvQKoXz8Ovn2oeLnwGgX/SNOeWHRgew2+T/G4rFj6DKg/gahCzoKh1GYOD7tRYJyWhDnOI7fvLJ5qeays6Hw/YXJdYfWQ6zHZbM+guntYJM83yyDKO2h9W9jtTyti67yfFEM/G/lGvo7hkjdRswJWQCJILD6bfQC9naR/69Ngb9If0haIMOB9tgcpgG31COnDL62qexHG34jUow/w5+lnB0P8qgTBW6a2+rdI3EIPnyW7O/hkY9tIc1duicD/l9aeY/xwgetur8M21llLRuZT9mML9uGhVUdE5cvQTsV5QhU65nUeo/F4aRxU0wsjLwcsMppGb5y8wseTrYn6ZjTWbeAUv0y8Bt7pHP6lwzGRLd50pVWGQOGk0xkEGtEJEMmWX7R005h/Ej8CbVV8m1A5phXkdvuwh6duUKHgA7JIKm4a4A+apGMx256ZcmdjdDso7MULITbNPkwduIYpz1YG5c1dB0HNy2/Ttznss4YMnBQlDxkX/I0slIj5mPq1F55TTGSSEZbYOoEwekzAbhdJBon/DJvtM3oGsGFFogBa+aQehR47Qq7/MCh2GejhkDZJyFuvzx46bhcVwlIhuJgX4W0d3V44Ijq2khI9atoy0qrmEKcSH7t5ZolwsjoFMpVxENtJ7OyZQMxfxHHznxGs7/D+Tcf1D0TF8ADM28ELxS6oQ/RIshaDqAqQYy64/6zL01iR/ClMCk25X3D h9NH7Mdf QmYzTcQ7jWZvDxN5iTIcMUqlIrEVDm6QnWWKn0rfbBwqsWEvXPgTyHLNikZvJ877VkGE3SLAGs2YTndQ845Q0hef9Llj4Fz/boTZz3ut5g5R+Cx7c8XX53hN65H0hfGUXS2ApNsNonl0zWw1Lg8gdJhORjt9ybqM1JD/pYim9M6ZTaxMfH+VpoH7tzHFWrmidDuV4ALaorUi+sv+SxP/F+lv3o/BuULWSXzujk/1GU1xcEUTckDuG6DCskw/aaPSE2K/6FKxPYytDiYTxoOqauW2sqApI08KbmOEDL2ZLI0qy69ihDunn8K4xh+DNJhybRyFEweDxOBbIpzzm4s/grWb09Xxj4qsZp658owmDRx9AYIPLzSdCwr4X4rOjhRc3Jrl/2nTcXBgJX1cHRtQeicV89dbPgzwo+f6JJkOEl3hbBbgbHLETxzajuqAZsvbCfS2B3qHIPv1epBFj+b/NOkW+ZQJQaBZMzr7LlFOrzeumuGj0LQldxZzQEn6fWAwvzi0URJ9ppYz8/pe0MZHNae+teBalu0MgHKGf X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: All callers of generic_perform_write need to updated ki_pos, move it into common code. Signed-off-by: Christoph Hellwig Reviewed-by: Xiubo Li Reviewed-by: Damien Le Moal Acked-by: Darrick J. Wong Reviewed-by: Hannes Reinecke --- 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 c8ef72f723badd..767f4dfe7def64 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1891,8 +1891,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 bc430270c23c19..ea0ada3985cba2 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -289,12 +289,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 4f423d367a44b9..7134fe8bd008cb 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4520,7 +4520,6 @@ static ssize_t f2fs_buffered_write_iter(struct kiocb *iocb, ret = generic_perform_write(iocb, from); 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 665ce3fc62eaf4..e8bb4c48a3210a 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -655,7 +655,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 33b54660ad2b39..15907af4a57ff5 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); @@ -4034,7 +4037,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, @@ -4047,8 +4049,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: return written ? written : err; From patchwork Wed May 24 06:38:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13253305 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8613EC7EE2F for ; Wed, 24 May 2023 06:38:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1AA7C280002; Wed, 24 May 2023 02:38:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 15D91280001; Wed, 24 May 2023 02:38:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F1715280002; Wed, 24 May 2023 02:38:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D503A280001 for ; Wed, 24 May 2023 02:38:38 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9B5CC140867 for ; Wed, 24 May 2023 06:38:38 +0000 (UTC) X-FDA: 80824195116.19.BB520CF Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf29.hostedemail.com (Postfix) with ESMTP id 01A6212000E for ; Wed, 24 May 2023 06:38:36 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=KluVLKd9; spf=none (imf29.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684910317; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JJwCNovA8Hvn4E2j3I1EFqtVuzu7mduVb6MIKUgJaYA=; b=YnTDFLYRFXQHd4OufXWYqVpMbzEuklMPcwHdM1Kz/P0YCcxLyT1xJDhbRdcM+JughL5j81 aqKT33oOJIed3P6i1QbUS7IOymfe9YzCVvCipPdzgksPMMUyMVDYlFcd0l4PuyXss7uLpw U6xzWTvExAo7O0Av6ucbT8e4tJZ8YFM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=KluVLKd9; spf=none (imf29.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684910317; a=rsa-sha256; cv=none; b=tIHjH7RYZf1YKEDY3i6w41iL/rz2YPQn2ZNRHRee6OY/CIJWviKW6aV37D3E/qtBwXKgdz B8ct6aCYk9hd6MYVfCeY/biu605UrZtanxcXTD7X/t4BLMfJa92T2udYBdH9p6XAV9y+/b J/nTU0HGlPp7RiAqrgBFQaFfh+/YS1w= 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=JJwCNovA8Hvn4E2j3I1EFqtVuzu7mduVb6MIKUgJaYA=; b=KluVLKd9ujTBULz/Oac6KpUAEF sPSrWCifr7i0eK+kRjnOHUKMBeVjKARBkPf9xwEJp8kT01+lLQv6MRd/hqkSNoQUcLqKZ7/BGrDcN dA3NJJNXp/9uMXRhkFjxdjy5Cix+8ukkPMb/2IOstgyXPxekPMR5F0U56sNBp9qT4v2u57Ha/q7kF ydIlmlrEAUFmlDYIA9/lAt6aihuql08dwpcpP9IBMk2Pqg/kgz/RSPJciiTw5Eona1z8aYRGjnxl5 dgFQlf2gaeA/3y76BPGTs55ud6OcsdO38YfGliCEJWIcQ5j89VqlB+U7Y62S6aiqSM7c2KLIuczIz /3UPYgzg==; Received: from [2001:4bb8:188:23b2:cbb8:fcea:a637:5089] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1i8f-00CVfQ-1M; Wed, 24 May 2023 06:38:26 +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, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 04/11] filemap: add a kiocb_write_and_wait helper Date: Wed, 24 May 2023 08:38:03 +0200 Message-Id: <20230524063810.1595778-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524063810.1595778-1-hch@lst.de> References: <20230524063810.1595778-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 X-Rspamd-Queue-Id: 01A6212000E X-Rspam-User: X-Stat-Signature: b3p7goc3xou4n66pzzn87sxqbp9up78q X-Rspamd-Server: rspam01 X-HE-Tag: 1684910316-412545 X-HE-Meta: U2FsdGVkX19ifz1nsoPuu0XHg675ETpeLeUVXqd79If83xNkOchrVzlkyAy4fiDKmQJWwHQrz0VCZ+4Ii0EOC52AOZ2FzN0awyO73WX2gAv1mfcMiE/GQR647Z3uj7QnU7ChxE9fKQ4o4eHKgeEeDNawHLhAzx62BymHwUaProoqpAw4hIjst9patXXYuoAHwbMtV3Nc4JUlSvWKdbZkSe+ynwQ3tHKoCcIudrKN0I3Rh2C1xpXFfpCn3GLEpIO9jxeD5guKUAR5EXnrJ6SjzVO9FpxMkyXDrbK8VwaI0+L8WR59P6ojCJl1UyuzKQuTH2ITHhHzWNlQY002NUiZlkBlF7u70vFsm3h7PEu7SU/Up4fktuxOisfZh3Znfnry3TB+4ENgIS4yTCr2X62QioUU53ND0EBIPuZpZ1joYn8eIhmYho603nJIIG2QvF2jRrxszjWt+gCgHPFSl2Z2o6F/7CRiNPDuGP6aPGPFyZ+/5WwsHDrn26YWOi+UNePlgBFQ/QxdxM6CsIQ0h8kpbAoIgF6FhWAnLYpkpEhbv9lnFwzBWzBEdXtrPGG/8nIrPNi+rYwwMir+B+UrqBciyhYSfylPVhzPdAPKSd5SjKMpc31+X7lyT44lwvxgrdaM1121gH3w5JH5qjW8M+2tBYNz2gS1cN4ylxcLR/NLEdFkrP4bf2pDRrci1iuYolpyQiBlkoUHtRnA8pK4Qe3kPQRzOKw2l251PcA4/CgIr8WEDwtVT/+wlVYNk6b9eeDhrIcTLvxDK/EnkqXJtCl0Qc/ZZ37sh++2xkBAHwxQJLemaYeQclEN2cHa2GyKzJoR+ocV9Hg2ywW5N+N31xJYRjcucPUgmLFdZeEsRkHdkal/eo1V71kFrppzXIhmwS1HrM3YFtwMqoU4cCIoE/ArqT4EDISOAJR2b95HLZsC9r6T3Fg5CXetWf1dymijXgjL/6xVdUBlryjlYtKzGHP h2Y1SeUy 4xLmvxMY9yZ07uDWxIiA8pEqGMNJMjvTwU+EjHlvFmW8Y74d+SrSbsDL12TG4iuHEg3x/GTBjJAjccXqliya86JsTRE4QkQV8HvLKrbnYHKRhvs3wT42NFL07YY5+k29m8XJ412pZgqd16taghVOkqSHUkktLZDhJzI0HflEv5rTTmWkW8jD4e0e1Fc1zCKSSxAaDqWD9uDspSfULrc3K/SXdMm2Tbn4mD32la2l6xQB36Ydl5LV+SOD+72S3VPAA+H7DMHNq19nOd2qXvE0mznVeSu9DIiSNsTMA26jqWPVdarFFSqsJmFGvz7i3KiUw+BiFGlLAz9Dl8CwF3EGvMH8KGFUl3IxaTraq5wG/+wZ7h0zZTft08brosWESNYTlqoudeDK2U9nNk19M2nn2B8xvQhWeQrFpOG+mmpgcqHoM/TKqLHKBYwfjTyhgYO12Eg+bNzdBLXFOeE65prIv3qKg1aNudw6w31tN2WPZ6Ux9yU221zgU12S0BrYjC90P3KDcHhmaMemCBAuD8z9F4108IGsoLdV6XxGpmaaSpRcTWyo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Factor out a helper that does filemap_write_and_wait_range for 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 Acked-by: Darrick J. Wong Reviewed-by: Hannes Reinecke --- 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 58d0aebc7313a8..575171049c5d83 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 15907af4a57ff5..5fcd5227f9cae2 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 Wed May 24 06:38:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13253308 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C60AC7EE2F for ; Wed, 24 May 2023 06:38:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90123280005; Wed, 24 May 2023 02:38:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8124D280001; Wed, 24 May 2023 02:38:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B33F280005; Wed, 24 May 2023 02:38:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 57858280001 for ; Wed, 24 May 2023 02:38:45 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1DDDE4089C for ; Wed, 24 May 2023 06:38:45 +0000 (UTC) X-FDA: 80824195410.21.CA1DB02 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id 860CD40012 for ; Wed, 24 May 2023 06:38:43 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=q6Wu9SA2; dmarc=none; spf=none (imf17.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684910323; a=rsa-sha256; cv=none; b=IgohJiAMzUELdKpuAeaa+U8fbK0wQHmaplX4f2f3OVZo2ptqtGGF9fVMBWO4D3j38mZo2W WmBRMfPrYEn2fIeITQHjAisqaxE4PmMfAoaqgw+4TFrkTBhVudus1P8JHYsLvSZb3US4or 3d6clX8sGZsLRzbvb52VLYV58DHuvCg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=q6Wu9SA2; dmarc=none; spf=none (imf17.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684910323; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zJveT6acb7t2j3iomHi3xo9Jbx75D5jbjB5CrMVejjo=; b=hmFMsO8dx+lRcwIrArgwGgS+tfgf9ee/90qqsWbEMN1F7Kl8TeMA3eyUArMy4UtwynRcD9 qTwO5OoGWoLDJ3Eb3xtG44z1e8yCq8Pmz+TH9i6JbInX42QK3ILjY3/OP2zLhVHsGo4G7K cxTCHBqw9x1G1Jxrp3Vy/kDrxDAip7Y= 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=zJveT6acb7t2j3iomHi3xo9Jbx75D5jbjB5CrMVejjo=; b=q6Wu9SA2gFSAIh9AiPOt14soTX 8DdCnoqFBQBu9bVMEqanr24O7/zWkWVuK1A3e4GSuOZym5FMwUCETTPqH/YxzZmXnJ60fvuu4y4Cw zSelNT1zRkORnz6HOunLGdkPo9/2iwMfyLLsa6YucU7Ax7LkK+Bxf18JLpANp7XwpxLxolfGBpyzd pEl9ELdZf8XF8Zy0Fe5jt5VYKTQvXvte0rXpg7K5/ebo7gGyug/xu0fIimIGoBr+PsNE9xIJ6abMo cu2VIUtOdIWHXchhn2Fc52BZisN7YgWLK7XyMLHJzwyCVRxere7W7z82n7/oeqEU/DTy9CVwNsr/t oK1WlLZg==; Received: from [2001:4bb8:188:23b2:cbb8:fcea:a637:5089] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1i8i-00CVfn-1t; Wed, 24 May 2023 06:38:28 +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, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 05/11] filemap: add a kiocb_invalidate_pages helper Date: Wed, 24 May 2023 08:38:04 +0200 Message-Id: <20230524063810.1595778-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524063810.1595778-1-hch@lst.de> References: <20230524063810.1595778-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 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 860CD40012 X-Stat-Signature: 6c5qjmj6gjm49iob3jc5c5eeryg4rder X-HE-Tag: 1684910323-376326 X-HE-Meta: U2FsdGVkX1+Owf9/H6/4E0IXzDWtNCUe/f+1Z5ojhyh1Il5rxZmTIr1RPOnzivIC0s2pN5TzfIHrHL9F+tHmqCN0yZ827ZQGkvgCPKnac+1WcIMt2e4szxDuNfL/rJUxXrS/8OBJITPZaB3NwTHSmw7nZ7xj/7/CyI8l9r4Jit78fzdrkq1NiDmwGFT6j8G4S/TODWMifSXQvM5nIQhRATjBMUFLaY/nLBNt62fX4X81y6f5mOgZndQZ8CQbra6XYz1kr5R8G9TVg9qMcB8V7AOgFImYK8Yo2d7dkhJ4MmziEU1ZbQS7Ju3Lle8KDhabWqUbIlRHmdX19Td1jT4KrekEzUDjC0c9aO259mFIcQGlUoErSfjQ3FYBJaRXSUDKGnqj5FfMM0j8yAiIPGJjxbKzdTuk4LyMidecgIPzhrI4gLYxPJoBaaOSEsSdYqYzRHZ8DtrKzVtV+UEvsUU8hWr5mUthXoGtlzDOLiwoLdV/KAowui/+8U0o0Y8lnWN1nbxN73371pstMIkTXxsQgN9kIitH5cw8lZQcx6EC09dSxyPvYfAvg4LZm97JP0MjGNFQumbdljYM9Mwoz4FK2N7BfFYi0eiDZEKzGvSBvsajpXtCnjOK9LnE/eQy+7Tn6pSF6QKi5DhHSgIXtYXKlpGgw5eJL4pMJCwZe3TBT4JBxl3gDlWeZ1QqGrsDjYwKGwc/BurDjoigqAMcEnviB1q6yH48UDibOqLqGaVEFD5HxifSj4e5aPw2BmR+3SeJlw9S2uhtZpnvg7S2MIPy8l0JLe6BvexXbq98qTNH0NLxMA+QFzxOLggDk9YKMn9lu7ZIKFQemhMttZq6YSHImUJ1NGTTk8b1hk4Y0o2Gs7aJHo5C5SEpkIOOJp7VNIBNxJFGNeJQRaRoJp/vzAneQBYl3f4wVQgNTH8s7ZY9CDapAyKk5ehzjdLOQL99dFCxIB8utDeM5ImCsZu+Ute AZUVmHg8 rDlP+lqYMYMx0kqlUUJcjfq4yKDAZeXVBgDNz7UbuiYto7CcC9xmWP47fnBccXKFw/u3IuDi3ZzCy9U/yq8bKQfa4zBr6NszrhoKTVzewp7wbpwI/gASvKrlNegygBGXTWtpK3d225ZgWSeTxzRYNQLzoO5zB3yw5/Nflek7tja/PeBst6nBh7/7NaGjoU6q2TKByNJYdtJzMMNiF8dS/mZhLeCzrep5hmdM7qt4oi8xYr0R5W0NKX1JB92Cd5R0BIqARKCGsUIjVJwmfVNHOhqHrKpyPivzyWEPE1lgc9fV3fT/cijYRHFJWjRxc7umYDIm9eawM46jTG35sB6Rw13Czz1tDQjxaKR3YKnqE0doawsTxdLS6FKWJi+o190+pjxaOcEYZCcoe0BOzeYdI7CHvZUZgAEIbUqL+MqX8vs4zE+9xDht+geedFV0dLnBafhtVgG49v9pZTdQaQ7kzFA8ePJp3Gk7iN+TCDW3vwzKhIG6JfmbX52jQ8fo4GmqSpiVWzNAZEz/WqxWmYvAv6UOh7T+aUGtvrl4ZQm5y8UqlgRo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Factor out a helper that calls filemap_write_and_wait_range and invalidate_inode_pages2_range for 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 Acked-by: Darrick J. Wong Reviewed-by: Hannes Reinecke --- 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 5fcd5227f9cae2..a1cb01a4b8046a 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 Wed May 24 06:38:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13253307 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47C26C7EE31 for ; Wed, 24 May 2023 06:38:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B71A4280004; Wed, 24 May 2023 02:38:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B1E4F280001; Wed, 24 May 2023 02:38:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BFB8280004; Wed, 24 May 2023 02:38:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8BA2C280001 for ; Wed, 24 May 2023 02:38:44 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3A05B1408C2 for ; Wed, 24 May 2023 06:38:44 +0000 (UTC) X-FDA: 80824195368.25.0C3D337 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf01.hostedemail.com (Postfix) with ESMTP id 8F4DD40014 for ; Wed, 24 May 2023 06:38:42 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=aIT9RxPA; spf=none (imf01.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684910322; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HdqYutACGg449lbpC5g+tM8dj77PJUcg5E3vRPFmYq0=; b=4Gf1r3ls7o3vXqB23UsZ5ARBh8mDhs5oF4dGcBpzdYbfipYUSfvw6J6QAvd1XhvByhCFsL KKC0REmGliinUHcNBnsmQuoxkSvQnydIqO8Umoia23UQy5Vn4oAIwiT0m3DgpSPtJ9V6nk Yz+l9rtclRGE5NUksVc7dvmI1l0ja8A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684910322; a=rsa-sha256; cv=none; b=SVuJR2BmN+OxJ9iGkJRITkmsDlEULTGjOrF7LVivCrLfihC1zhoLHQUrtN+Q8MtE2TwiLD Rm/cxL39VjAJCqP7uUXbuWVV8cV9D0WJFvpd+yS1PNVkn3DZS9ZyGjnHf95/FouTaTA6/R GpZNpawB1+NrT9iPxty9RXBZOGm/TQA= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=aIT9RxPA; spf=none (imf01.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none 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=HdqYutACGg449lbpC5g+tM8dj77PJUcg5E3vRPFmYq0=; b=aIT9RxPAfhHOwqFZulkLmucxGV rLmMDARC7Dok2azH//gTb4c6Pv6q2CYBKqB8tbL2AuYl8Tfm9vOJ5XyRfvYGxjYgaZYnnX2Hx6xah vrC1KPdTBTHrMFDf6/pdyS2fU62TnVe2a/zKaA4Er+WhodXEB55zZVt7ffWjrFYZ8qwq2O1XSL6jZ Jf55EKX6Pdh43s8/PobRAATn/qfOc8Kte4qHFp4RoHJZ42gh+MbsmJr0BE8l4SxPAs7j+iwO11vfy 2Y+30GGr5oR4tTZ1yrEZRl9Jb/f+do7t9ATt+B+FC6zzk83WgR+wA/beHBKCN+AZh236kLMfXWU/D OHHhHfaQ==; Received: from [2001:4bb8:188:23b2:cbb8:fcea:a637:5089] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1i8l-00CVg9-0q; Wed, 24 May 2023 06:38:31 +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, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 06/11] filemap: add a kiocb_invalidate_post_direct_write helper Date: Wed, 24 May 2023 08:38:05 +0200 Message-Id: <20230524063810.1595778-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524063810.1595778-1-hch@lst.de> References: <20230524063810.1595778-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 X-Rspamd-Queue-Id: 8F4DD40014 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: xuisbhicprausdzuz6xdqmtsybji54wi X-HE-Tag: 1684910322-645483 X-HE-Meta: U2FsdGVkX182VQ9lYf6pHiSIgp3YStf+fIuO2qZTwciZLke3diD5HA/0yx98QJVc1q3aFTzPMLJH977cuJD5v+l8YeNDnhqazleUkOSfaKqKoarVlIt/u03gdx87fN2bjWwiw17JbICUaD6SJc/J41Zod0TmijVwbGISuM/cr8W4RBb6EA9G5fUxxrEXRsEuHNgtmpgljYz6nzWjmr3ToYOl0A1/KsxndxDG76qfyk9p5gc2HWhFcoKr2yPrMw17NAxV3svWtjxdPiMOn+PJ5cycQyyIQjz3DUi25mBrucV1ASlZBfbtDa5MKRMOgR+EbmeF+oaPnsy/BzTIzo0dIolA5EhzmKV87h+UfFcJetO2Nn+R7c3k+e9VWzWJcoA50InXtFC150GhJxF0DGA+mWnMGMipdo6Wc+SLletibAhm0gpiMAgeTUAvHWOcCx6q6tI8RiKaRKJkto1buRK0NfVOyZkfJwjIw83+YOBaWIb2n62Xh3OY4oBbtCOR4CZxGQQ7xteO/YwTQmQyIiDPMFSmxiSYAbXmMeNs536sFG22f28yO1fRv3+cGQaGWYtbuIlM5ro4Ab5TvVEVq0An6kNHrI3CMPjOk8Q9ZR6DbFcHfQKk0J2skIm8Ei3qcowC/zAjU2pP8XwURi+On6ArG9+7VgnssDGUYnIy35VImXt9NVUITBcDZN90dKGZvbwZ5MbY0ADIaDRNFqls5A56nGtx+l0qyZO1KA8Ia3kgqSbVb4dxTKGNXTTVP83/maKb43NkfyqwW+0D/EyIbRpdCihZxCS48jnoaxs8Hww631yGWWx72TkTaTUUfuV1lny36BUBqDkD94kyHAWxqD5I+pTX2dRzGXUGKq30CEVf+hc2NH7zJa1BioUGa4SiRGZvPCxDQSkSRghqDqGRQcghL7McFJbGi20eOm8omExYsPdJ5ShnCBhQ1nxbs0LEqRf69dA6K8s7iWF0tISMQLK JsO93E3C dC3lWot6HExDoNxLUMwH8aXWTMR6b8N4ccehFjOogcGEKdgifVReFTjLYe/a6TydxlGfnikRwz9ZENeyUUaB1loVSICvqIuwYLdHReasgB2n5TCb4TuGn2aMsxKHoD2swPYLHWek5R/c6z9KZhFupue12hzo9hXBagEmhcqPBVfMLdoHJ/7EfoYFgp8OPutFaXacv7vTz0WLCzIdA+8TCytfwxf7tAEScUk0fcg064c5iVXFe8o34OWa+x2VtSbM3FgM+RAnHx2P5TSfAEsJCh3YHcsel8aYjK2rBRUM3Pez7nwY9lfT/mHyJxGWVO7sijmnDlYG+hXNtnQM3NpjfMvWUuZPKyARtJz+DwShdfkjUCZEvgFrek/xIEuiaUmRCa7hXe3o0MaRRaNvoZ0MRNL/e/9u7Davy5qJv+/uMoAZj07h2hNFibWi1JMGtpGfP15sSTKzmdrZlF0jqR23VS4nqlEuqJbnNY06wLKfONW0uQGCQ6997NEjlM6y9VsbKOn3RUn+rQpv9YfDrm7PLHmcbqNBoDewLGV9ZT+x+CGoE2Bw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add a helper to invalidate page cache after a dio write. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Acked-by: Darrick J. Wong Reviewed-by: Hannes Reinecke --- 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..4f9069aee0fe19 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_direct_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..0795c54a745bca 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_direct_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..6ecc4aaf5e3d51 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_direct_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 a1cb01a4b8046a..ddb6f8aa86d6ca 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_direct_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_direct_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 Wed May 24 06:38:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13253309 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81E6DC7EE43 for ; Wed, 24 May 2023 06:38:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 18446280006; Wed, 24 May 2023 02:38:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 133E9280001; Wed, 24 May 2023 02:38:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3DB6280006; Wed, 24 May 2023 02:38:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DF6FB280001 for ; Wed, 24 May 2023 02:38:48 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BB723808DD for ; Wed, 24 May 2023 06:38:48 +0000 (UTC) X-FDA: 80824195536.05.A2DD126 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP id 247FC1C0014 for ; Wed, 24 May 2023 06:38:46 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=dZJR1oP4; dmarc=none; spf=none (imf20.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684910327; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5bzp/0by06gXMZwpvo50hn7+jgjD2rUy1lubnHgSTkM=; b=Qvp/EHNEBXVIaiwvxWPQaUHdAHmmP0QzbipW7pJTbeOr5TAzsSm+63JeoD1atQRrJuqaJG +v7td6Q1p3+PnCRaPBz+ftrFdzPrpmzH3/0pxMJ5SH1ekj5QtTiNLAVcMgXGN62xo8JBlr tkLi6DSZFE/w59HDdcasJj3i2qc8K2w= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=dZJR1oP4; dmarc=none; spf=none (imf20.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684910327; a=rsa-sha256; cv=none; b=AIEP926v6tCpIRnG8ZcvonpCz8kQ6mu/nyzU9pwCUX7YB5eUAoTF6aJGajzGWuNwrSZFJc /DZEVOfKdMelwH5x0mXrx4ygG8OshKoP8HWm8Z7MTEy7I744NzrN2xokkZ50/BC5K2o17P hC793g6EQGYBmHiqg8g6H4X2xv8KIkQ= 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=5bzp/0by06gXMZwpvo50hn7+jgjD2rUy1lubnHgSTkM=; b=dZJR1oP4oAplc7LAjvEqiOhesB j7mrqWb9DWAuwPSwrRP2EQ4KmmmV/xPU693vKh+gRgrPd4FlnzipdL0Tf3RnH8pWT04fo2OrOt/MX N1AnYXpvNNNDzD80MVj5+yqF0hc7fZtkFgL7ZOqnTIPICju9QtDmjIBAK2jbAVsb+3FH+XPugCtsf x8MO+Ly2fr6FyFgNfot7iOnrIBg3YP7NDK2ldi9YCmXeaf0hzldjZA0PlqFpHHlViiNiMN3NJ3PDd FeEiw0uOKKPmsMpwvOBJX0eYgoM6ge9MKvyHE60E5CTNznh6tpfnhAAxqy0uCep+knDMbYOYuRMev QNE8HMIw==; Received: from [2001:4bb8:188:23b2:cbb8:fcea:a637:5089] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1i8n-00CVgm-2V; Wed, 24 May 2023 06:38: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, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 07/11] iomap: update ki_pos in iomap_file_buffered_write Date: Wed, 24 May 2023 08:38:06 +0200 Message-Id: <20230524063810.1595778-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524063810.1595778-1-hch@lst.de> References: <20230524063810.1595778-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 X-Rspam-User: X-Stat-Signature: 7tj13yb837qqca1oj9pn9p9uufke9cib X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 247FC1C0014 X-HE-Tag: 1684910326-960967 X-HE-Meta: U2FsdGVkX1+gi/r+t4OvuBAt5hetv7y1DXWfC5UiBbg2lHTIjvd8/kwbl392E19kiABsHARFblRdkE0VhqvrZ9ggNvaqui3Z5skKb7Uw+nRZJxkc8MW7oz+at6/Kq/c8voDCCU5KPICJgqYZ5JF/jFE99kl6h/E8LOlenwOloavmvYdz6BOSFJTtf/0H4z6/InYKZ872od+7Bq3oxvfeWrGzOTbcFIQiq5yz+XWt/1Iu+3rnXjillBO6NW1C/eAWQ7hCB28nqnzK7EE606St7vAA8K2Pj8qN0J+bcsm3pEthXTs8pOG7feT1V6bi6FPQ7bglSj4KnXI2ca/XDkKbJUwctd++4O0tOdKV2vGmiC9hLoixIAF6d017yO5JGocrL0iXIW59Kw1VwVR7pv6BjzxZtVosMr96CQj3TYmHrgWzSbIleL8Mb1g0K5ZZAU8m5H2Mb5tnKULG0ynHWZF38VBZeui6J3AlnI0Y7XXcNTqu/Ka6s0Qmwclum1bDLk49QwL1Bw+LXisrO0if+hMwLrkZ1FEeKD6iK7lkmI1iwqbAmoczc3pVNuOslSZ0OPC7v0OQ3u8jQBGlYaLzrKosRc3YlRAZTKAtTfbrbk9KZn8Mgsjn7X+88H84GEvJYFUCWAtPa5QBTLqAglzyohctLW9RyQnUEgNJA1UumTiBbrTvnAASsX7VK3D1bVA1u5G4HRy0VnopfVguenHdPA1GKXXsQNaWT57JPlyTjPmi3/pIfWH4um/Lci/6FsJtUycWCmJIUTAiJe3xLSEuSVyDKj1yKObefGQEYlZ/jwCiS86k/5OVnNllKssaR44MTrLRzH2BUYz6ZZaTDxyNHNXm1+wI8XL5pA8NSAdsgvJbzRib9W6cQPsYfWdUsbE1EkGuubSoGSWd8TXAFaBqnd00O6qAXlICHzA0+k6VAA3RvNG/WPC620ofpG5V5Aw5OM3NCB/hMlYW5nm6Zw4gRYb 2X6RIL5L s2AarjAY+HIfZbJbowyFpySjA1ql4BFA7CinO4i8dhjSr+irSzzGmTLR2lvE4RwJq24+TK8C2xL3Xo/VD11ksI3DwIvO0ZFe2xzxK3tI2xjDPkf4xS7aIfFApKTQxXG4VXspkVZwUowLTgTlo5BWGVOVvetftY8Nho3cdqDphHxDcZQDyQQ1CYcHlB8arEROE32E23+7umGuUX4b15JbJj7flvfKm9RVQR3oUa4sIzYOLxluMRh8VQHNkxHeZyuhKYw5719OsFGeMqk0/WqlmryQeq0Cw9HbCI+EDD7OQdYtu/ytZYrDpbioMj+s9HNwDlJDOSO6x1WjUp2943LFM/GVjNhX2FjjU/B9vQkl8eWzxh89QYjD7YdraPept3p+UHr0pW6qOXfsiZLr55DYfaFne1qs7Loa1WvzUbnvNjPeZwluAa/qOYjkf+Zcq/OKbyt/P7N4oFO5016sJd8PGKqcx5SJm9sc3BjuZ3MH+4CN0mOgvLrbLUwbRrhP9cRZ/0yBecITh1WU22bC1GJ8SSDapkZxBe2ZXeQUJqBk7Fjc5Rjggje44MENQJw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Darrick J. Wong Reviewed-by: Andreas Gruenbacher Reviewed-by: Hannes Reinecke --- 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 904a0d6ac1a1a9..c6a7555d5ad8bb 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -1044,10 +1044,8 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, pagefault_disable(); ret = iomap_file_buffered_write(iocb, from, &gfs2_iomap_ops); pagefault_enable(); - 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 431c3fd0e2b598..d57443db633637 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -720,8 +720,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 Wed May 24 06:38:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13253310 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 032A1C7EE31 for ; Wed, 24 May 2023 06:38:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AF3E280007; Wed, 24 May 2023 02:38:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 86103280001; Wed, 24 May 2023 02:38:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DB20280007; Wed, 24 May 2023 02:38:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5B26E280001 for ; Wed, 24 May 2023 02:38:52 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 099811208CD for ; Wed, 24 May 2023 06:38:52 +0000 (UTC) X-FDA: 80824195704.23.CAF977B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id 3D53CC0003 for ; Wed, 24 May 2023 06:38:49 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qGygllY5; dmarc=none; spf=none (imf28.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684910330; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UGcays7SHtJ30c2YB72Xoeq2mxU68x0UDEkjnGlewMo=; b=ZleCo/lFUoLlJdlYL9LzZJ616p2I7EaNoZ9XJb3Ym6Iqrg09dw08X40GiX4P6eMryPYU6N 800GNXePkxkQF3efGDgNzX3OcdaBTpUf041ZzUPCa/himSa8hfmQtX+mLKR+Rka125XJrx TEsqJ9uRYVt3hy2lHEtiNBqslBywpd0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qGygllY5; dmarc=none; spf=none (imf28.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684910330; a=rsa-sha256; cv=none; b=Tz7j62P1P6gOCCP7BSiSNQAtFJTc9SkFm+kOtv++zgG55onX7hHVjra5VGFJOj3S0UkIyX /Bgi1fDmy7zZZHK+XPX2jO4AOpMZSmCNqnu0WtTnMGcOSyG+TWW+c4JGKkeiedaGyR0zWp mcgeL8RrTf+z4aPTmhKVsq/PXA1msc4= 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=UGcays7SHtJ30c2YB72Xoeq2mxU68x0UDEkjnGlewMo=; b=qGygllY5nnLJOFYyd0IBWQFSLQ EZRHhM8vXPJRpF7uMOuG8ZcWfWL49uI8P24Xjrd3+TBG2ba06CYT1Tki5Tc+pxSgIqvYZ8NcjEohR 57ll/L5ERXco+rn8oNDpkolxK8nebCYh8CBEV843AEYixyxCv7TYDxS1qGAORZVqrKw8bWV1FbS0y NsHl2Ecyndoz0kXEJACW+wX5KzE5uQuK6zIUFsTmXcDQu0yTIm5olLObpfTWlPt1gD8tBwmwFxHzS rkzCUHnWktCU/Iqvy5KBUEACLMonmTd3FskyrdBZZ+17oEQwG/YhB1b4cZb5+fKS94wcg1c2w18RG cdczDtgQ==; Received: from [2001:4bb8:188:23b2:cbb8:fcea:a637:5089] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1i8q-00CVhQ-1A; Wed, 24 May 2023 06:38: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, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 08/11] iomap: use kiocb_write_and_wait and kiocb_invalidate_pages Date: Wed, 24 May 2023 08:38:07 +0200 Message-Id: <20230524063810.1595778-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524063810.1595778-1-hch@lst.de> References: <20230524063810.1595778-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 X-Rspamd-Queue-Id: 3D53CC0003 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: b7iyf3jtj19dz8bxg9e91dn7f4y841oi X-HE-Tag: 1684910329-625596 X-HE-Meta: U2FsdGVkX1/r0tK3HXH94DT2tO5BW4TEWsCsUxPLeRWdL2zb7PjMbIOXvfC+VH2OcBb4i6UELGCu45yiTkgMInyiPlkax3Oe8sYqYZMIBi5h0qaH/Z7tzWjfWS5V8FcESsqdEu74TMxIrB8w8RcyMOz/WdjaYQuwlaCwp7UyNNcAvfYQYubI//u29xYazzrtyh6bHiCZ65kqCGD475G1p7W678D6R+mtnc+qePpczZHSmHCNbqh02h246yhIiiMh2p4Zmy5ARu//iSoRUQ168jjestlBQtiIeBIHkubdN7vsVHPJPu9O0WUbbsLfvxrG95NeGPX6RoFBB12BQTjQfW5WCzKNpvnijJ7C5YUCuGuD5VKMu3FGONtH2JJkS9NjHDRdi9tJMN8frXIo5W4ega2eNiCUDtwdD1/KA/hTuONxPJQ4PdUw/RG771GPrel9gIalwwslw/uk/IS7VHfF9xk8ozTTpErYs0B4faM5iu9t++E0ir6N92pmJjXv6w7cms0qdgL2Cp/LONwAGE5mDiMAAAd98PafGqLV/lyZhbuYx4Q17OWzm56wftqS9K5FHzWI9oD4u4rdqEwCdqCu4NMHV4lEOTh4GUj+vU/9SRaJDxPeIkggBpgZwsmyj0NxCy2oytzKMWy1crwKsFySYkShjaJEwic++yvYJzaSdAySB/HKp2UgcmpybLoRMXS6Ywe2te4vvaJmvFGUtPT+5rmqpbLaUUBp60kzOBgpv/ByVf/XI/CR0s3gENypCzeQDJD8rZ1LnefbOSXPsYosYPoQ6k32S/gAOc9uRNh2Q/1hsSvVyXgNEMXEaJiMy/dLDcbM/3tgAdz1jQC94lzUYBunpOEfYi8Tapaj/IB1spWL915jlaD48ISmkhSxQHETYQOX8tXr4NdYsskKMbLQ8wa5Op+NRz11ZI3bILQODBTPs5IzcRInYzQXJHfCCIIaxJtYwmssnTrc6ZcwyWD QfyoxYUP ggWMkbxXc5FL4B4Nm3fncDPVbLtpnPZUdIrTnO/VBLNZWNCsBB7JH9PjpkwSXu7x1uvSppOQK+4sRn2X2GKQ++d3m7rtEtoSSHn25/eQfg/OkDSAtagSKJMV0V+lnvmjZU54+v6j/fsiHKuQ87g7d2OWHn4aRj0m9uIEilwqpC62HI5cE2rA6T3iR91r2oavJiW2ZgvlR6ELV9i/2p4s7H2AAft4p9gdB/qc4OkNYKxhcbka6DbylcZFAAFYER2cg04qDBQ4ite99b17/qa2yirf7RbcwnfkOv75MA9/Jx94NSklgVrztqJviDHARUVZmI4YaiQbHY1ifR/8LM1tZ1EqxeyeyywItcA8XVBqJVsfblv071gpcv51vg67SFDEza1leBL0Hmpm3OKkSODonKd0LZ+yUOlblvNiwbdI5OUAREGkT3Y2DimW1RwJZVq5qj9fFxQbne0c0c33sCIqH88oxZbDsaXjrsAsY5FNUe5rd5cRpaShUBXvTW7hjSMGDPXvzQh3ILkKCYrE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Darrick J. Wong Reviewed-by: Hannes Reinecke --- 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 0795c54a745bca..6bd14691f96e07 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 Wed May 24 06:38:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13253311 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD86AC87FDE for ; Wed, 24 May 2023 06:38:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 701C6280002; Wed, 24 May 2023 02:38:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B1D8280001; Wed, 24 May 2023 02:38:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A0E6280002; Wed, 24 May 2023 02:38:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4B09D280001 for ; Wed, 24 May 2023 02:38:57 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 21F4BA0893 for ; Wed, 24 May 2023 06:38:57 +0000 (UTC) X-FDA: 80824195914.21.313EDEA Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id 76AB64000A for ; Wed, 24 May 2023 06:38:55 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=0Qg7PBPM; spf=none (imf17.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684910335; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DuSI6OMC8P69e9w39tXFOndbEiGmzCe8R8L+odlgjgw=; b=3tOO6tvjjNbh2vPj6KEgjY5gKwwd+n7kZvecehoYdC6PhZisICj1tahqTPojnXUoWB0Hnu fa+StRwTO5B590YbmvzIjmYRqKhCphIfAtVe1TQxNWjYhSJBOX6fhjK05yKnRJF9jvKFH6 QhQPl206dsz6rEr0MMIQ2BuNe70wgd4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=0Qg7PBPM; spf=none (imf17.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684910335; a=rsa-sha256; cv=none; b=xmUqglJ0581CcB1Potjh9xK49rsB60W68Yo+t1fPTQe19wH0c8hh3txaWHhHBT131ofFME DGFUB1s/8/IfJk0P5Em4HUKKB+19TxtLh3aWWkZC9ygRy7BLdKslsQI+ccY9SYxEaQsGPZ 5TGhVEQJYIOQ7iyHaXyuvlHXt66k7sM= 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=DuSI6OMC8P69e9w39tXFOndbEiGmzCe8R8L+odlgjgw=; b=0Qg7PBPMhzJDDeLv8Rqy6M7JAb 8k8XDfr7gosbki8YW1OPh/Xlmot6rYDT/mDCbXqA3BPW+zZcIe3FXGThCbPkhur2e+HMw+d4wYowy 0CJfJz5vrLO/S4zcFsHJLU99CEw0c2tfwCem9AUTZ0e9Pxa99F5SPl1ChWbKYU+/5C3w2ObMvuTAy 1NXVnYWz+JNuUJ4bHEl40eKIcuM8QL/G0nVxdhkgT1tagjWs1rSoDMrM6MnqYT2ZCc25yRHhNWXyM IZSDR0+FWgC4BldGhUdfB8nRnQAAY0i5yf4TkdO51rKiexpi09016vufJ9PPlGS6Tmjsn3wZP20mW BaPqCKkQ==; Received: from [2001:4bb8:188:23b2:cbb8:fcea:a637:5089] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1i8t-00CVho-07; Wed, 24 May 2023 06:38: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, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 09/11] fs: factor out a direct_write_fallback helper Date: Wed, 24 May 2023 08:38:08 +0200 Message-Id: <20230524063810.1595778-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524063810.1595778-1-hch@lst.de> References: <20230524063810.1595778-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 X-Rspamd-Queue-Id: 76AB64000A X-Rspam-User: X-Stat-Signature: ruk3b6yt3hnrrtd6ewhsq16a5onr7jsz X-Rspamd-Server: rspam01 X-HE-Tag: 1684910335-963117 X-HE-Meta: U2FsdGVkX187/PL0wWm+7YRbzgDGjD6b6SlA8bOPgmYU6oz59wIvsZFVDYqXsx7TLnyFbs3ITKjWZbR208kdF+fW2ZePj+VHlnU/V2hrSxkeWWLCi3tbWT7a3WUIIK4PTXX3KFAdHFUdPUY9qHKcs8xdrMgVBGsViiTc+laWSLI3VL37CxwBNVyDQHjE7wyi/XvPS872KtiNXHUx9jG0qZttZEJ/C6ofC4dzccY0ebNObnkGMRoKFQygdMOc0DpgNFL4feIxMHuCbGkloU1LgL5e5EtDyDdAb+3EM3xu997GYhN4Y0dkDoj+bk2TKiykAMfY/rCFcSEal2NhEmCYeB1d/YUWWX/kEqk55t16jd8HgN/AhxjQq8eSZS73OJGKZr9kxNkRkAnzkfU5OojVeBW0yBtDNtrSQY9vh2bsQQcH0fFq8jmD/A/Zbg1j5T0+sJ2ukRP9Ul756qKYxeYgtKxAu7sBDGxLoQZ2Qodh+giJ6PStuYVWEIk2NwdqGKLt/4wlyUQi2BObeFDJwW3VeWjtMInPmCOXW8Y5svPJ7tsfzyvKEWTznx3lM4JzI/oZMk+ARHk8av6C3b9gbzNpjsIJHK5m7cCmCNJy3A+Qio0XJRxQBBwGakZcXDUI3RTbHm0EVcSUvreqaBK/tjUaOKW1CMosJqQpqMAKzJsVScAiLzWmn8fJP9zLhYe1yQkxLmvWpbZo2Xva2bGj0FMF286TK7hpXCqPKtRNUeGj4XZqY6Tf5nQKLQdDwyKRqCVqdCNqFiCuqlLXdh+ySeT6uqKrepQgwizKj5XvEGM0n3rt36dnjv4i1xsAUB/PCg9OI6AvNG5RrrB+UiOA34Y4Pbj4/+hbywSLzlINSWMJRe02AhGCJ5KKZC/zkJWLHxn+LN/Rs3d1m9dbj4gNpyKwjpk+YWoNu50Y1wojtbb+fLC/p9dHzryvAgSLmpyxSma6pvFq5umgQkxKQRZCva/ UchM0A2S XRt+w7jaT1pZK/b11Hws1jnrurYHqQkS3xOMXj74jJwnJzVh3+bvsLjAe5pzm4KTOlG0nMzdQSn+QFHGXGvXjcbL84r0Ah6bwV/9kFHZ2+i7fgC0rRHFYSc3cu/sQsVkpC+BNrYMVLw6ho5AhbHxrt5TmFu1GrvzS7nQ59ZwJo3X8kmKZFxA71/uOiWRHprGmcBjdANyKi+2B+JG5BnDJRomVMrLLKg6AzMqqKklr1wpTwA7iWdRD7VAEqnlwGeg7GTEz5VLHM50On8gX/o3VlEgAI0dkl983cOXlYDkbij/Bx20UGWhCfwqMnL1zMf0BrFE2RTsK2DKogvUJABwxQ2q4GJ4xJDKIpdJ3psPp4Eolkb3AvN7FsUJHB6Wt6pbNuHXtEV289oWtYgTJtz74qdqvxm8VbdHYG52XEZK79kvGP7asgs8HT/nYTQNTrZR2NcLzKp6XaRYYroKlraliuz4pjw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add a helper dealing with handling the syncing of a buffered write fallback for direct I/O. Signed-off-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- fs/libfs.c | 36 +++++++++++++++++++++++++ include/linux/fs.h | 2 ++ mm/filemap.c | 66 +++++++++++----------------------------------- 3 files changed, 53 insertions(+), 51 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 89cf614a327158..ad37a49e2ecfb7 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 - buffered_written; + loff_t end = iocb->ki_pos - 1; + 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. + */ + 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 ddb6f8aa86d6ca..137508da5525b6 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -4006,23 +4006,19 @@ 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; - err = file_remove_privs(file); - if (err) - goto out; + ret = file_remove_privs(file); + if (ret) + return ret; - err = file_update_time(file); - if (err) - goto out; + ret = file_update_time(file); + if (ret) + return ret; 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 @@ -4030,45 +4026,13 @@ 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 - */ - } - } else { - written = generic_perform_write(iocb, from); + if (ret < 0 || !iov_iter_count(from) || IS_DAX(inode)) + return ret; + return direct_write_fallback(iocb, from, ret, + generic_perform_write(iocb, from)); } -out: - return written ? written : err; + + return generic_perform_write(iocb, from); } EXPORT_SYMBOL(__generic_file_write_iter); From patchwork Wed May 24 06:38: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: 13253312 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C127AC77B7A for ; Wed, 24 May 2023 06:39:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A246280008; Wed, 24 May 2023 02:39:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 55223280001; Wed, 24 May 2023 02:39:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F3CE280008; Wed, 24 May 2023 02:39:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2DF28280001 for ; Wed, 24 May 2023 02:39:07 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0F6A4A08AD for ; Wed, 24 May 2023 06:39:07 +0000 (UTC) X-FDA: 80824196334.30.FC8AAC4 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf26.hostedemail.com (Postfix) with ESMTP id 5C46A140017 for ; Wed, 24 May 2023 06:39:05 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="2ZfYf4T/"; spf=none (imf26.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684910345; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eobR5ofZ8yxLf84yh50zZqRr7gdMKJnXJJVUfhV2d0w=; b=oqQe+s0YyBMVnp83FKMBhb+1pseR4nFzHIEZIzeYrRDoQqTMnctY/ENMmMP9J4oAa1Kq1H mpZmRU/cN+Z1GgKSPIuIvVkTxLAchp5G/o24QEouuJckfBk6hZl2pEtNUcLvFp1WCrkJ6i /Anp9X4lyUnTGFT6L1L9KIXawRB6nFw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684910345; a=rsa-sha256; cv=none; b=67qWYHYIZ2ce6yrfA0fam+8iY4Olt91eW9+xq4UZ6aXGpY3CYx//Pqo3WodFUsWo29gTBm bFbUAHb4l9v79stdLxa0dh2talZ6VIg+nkHys13l8N3aayv9fuMwCtquzxDuPy/sDijvsS Y7F4jVOmMaIPdqfwNs0Kd7QMeJWWau8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="2ZfYf4T/"; spf=none (imf26.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none 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=eobR5ofZ8yxLf84yh50zZqRr7gdMKJnXJJVUfhV2d0w=; b=2ZfYf4T/+f++kX0X6NMRNZXwFn 6aJYCflJ4wEp0XLVUCdXCN0nfsQ5luRD33XEc2EqYblO0dhiYNMTUNSmJchUW/7enLAPlmHRPVTRN HrjFHfPzJiM/nyFHTY8ScCLT7mFVz+NtIFvc/acgUikn31hWmFmFJ4FMTJq/43ss5+MCXBqLVImmE A9pdpS5w9NbP2G9XPCMhi0fFgf0vvzeY/WWuMXCznPPcLFetHBcLbiKST4MtObidiE+5CIpuLwNdm pCu2aMfTqEU6JWZiCVS25Y7Gz/zN3AFzBMMo8MRaMCSzXHj+V3ehXBI9NdPv8q47zr966sS5g1e0P EcTndYAw==; Received: from [2001:4bb8:188:23b2:cbb8:fcea:a637:5089] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1i8v-00CVjC-1x; Wed, 24 May 2023 06:38: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, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 10/11] fuse: update ki_pos in fuse_perform_write Date: Wed, 24 May 2023 08:38:09 +0200 Message-Id: <20230524063810.1595778-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524063810.1595778-1-hch@lst.de> References: <20230524063810.1595778-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 X-Rspamd-Queue-Id: 5C46A140017 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: jppukfs1y8b8y1sr5rgnoe34u4xirtmq X-HE-Tag: 1684910345-398803 X-HE-Meta: U2FsdGVkX18Hfbk6zDt5NaVycoVMZ4pD4S54GG95smuJFRWqRzztE8+WbxGB53iTj+XVKZkAAWFcI6Pty+UtzREXt2DNieIEUFpmu3QJ6zhgK08nv58ZfabpkPwMvP7tgO79ZypJyEVh4RXjTKdRVqlGXzsfWzWIsVh94ueIMWFmbLjeruvywRGJkZDhjD01VKCg7Oc6b64Iw45AVT4wXH6VWY8kL6YMnnnfUhrYFyfKIaOOyIPS8hPovLiFTmmp4puYkhmP+0jgPM1fhldDgZ6pydqTfCm78D/szmV7yWv/yx3RWxqkDs8kKS67qjp51lLUWfT46aFzwgY+HEIbUm9TIuQvVlEJra8hPXo1w/O7jrpXVHVGBatSS3PissLtYEglvpFsD2ICr6vIw4it+Ag05Iw2j1fkvYdzujYSuV5SOla/fxn4su3w1i4ZfBBCA6BWbYUWaG/u4u4NAodJYKADm/Slh0IBPMUUsQvZr5T0anWU2k4MiJ35HrPbZUkJkxJeNNRVvv2cJ+gIOtAZFVS6sJLHgi+AOU30O/WRa14t2k5U/bBinuprbjkey9W7kBq6cKu8s50mFDPejAKjSPSc0INnP3yC1AOFcmYDgjBT4UWfduO1twS/f4RYYRp9xBTtjMzPsDHLBOo7tyovyi8+MaPtPubQPMWaF4dQ/J0TB/EJNWdVP3vQNwJBX6pQElDFcbhG5NMfZPG5alKqtecCCRUbjDFA+jciwVbBPs69EPJPQttUlybc8JZaVFmrIXOAxFQsxnowgn9Dhbwr6AcWsB0/nK09etKxAjAWVIhaKCF8wb1FSDtD765T+Kohj0aneKDP1TdFAKzgzcdMD6mreyUqq6ZHNfHdjTDndxChcyVybcghNPp6ha0U7+DnyFnoHx4Q2lmHSNWZafflYs0TOfisLBf9y37xZrpUh1qi75/F7fYrswG9z9c5uPJZH+TLXjvV92cDixqkl67 ALxcdHAH 217JI6F6yGEPVVXPAJThBeZd9h9awXAAtpnyezZcJl/h4R5eTnDh4861WGh82rr3PsF3yp3xlQXJJIQpqQhVb0RzRDz6j7MKEPb/An1eSz3ogkUs5UKvOdvPvlbdKO/w/IKdL56/GVVJsTLygC1Bsj6Uam74yUPPypaSV2gwD0E5gCcOSnUE/76X4NYurH0Vre0OLut4Rub1AuZQlnldrc5xuLjsJ8ZgIEdAXCWQnj7GNMKAOh0fLt21AOIDVUuH6wGvcg8do9aRhmPwAgqCN92slGB1guiKhxnQe+LmK88Iw05sbYUZA9GKxK/8XT2il2NqLHecFfVQwEst7grLsBoGczOl9mCxCDOxHgI0CiHX2smSEKTr7U+DmocHfHbXtodK++olx+xmFgpfp8bkolZxzDWFIxOW9T8lWmopqoRUfC+avCtzqnmh36kv/qbkgy/GHZqr+pGfa7YhGgScNU6Jpf/VW8NyvlmVcpHtR3GLFmOhsMEiZZXYNU8JwXfdzOohv2sh5JUgPz8w= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Hannes Reinecke --- 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 97d435874b14aa..90d587a7bdf813 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) @@ -1375,41 +1378,35 @@ 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: inode_unlock(inode); - if (written > 0) - written = generic_write_sync(iocb, written); - return written ? written : err; } From patchwork Wed May 24 06:38: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: 13253313 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E8C0C7EE33 for ; Wed, 24 May 2023 06:39:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 99B89280009; Wed, 24 May 2023 02:39:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94956280001; Wed, 24 May 2023 02:39:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 811D1280009; Wed, 24 May 2023 02:39:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6E74F280001 for ; Wed, 24 May 2023 02:39:13 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 429AAC087D for ; Wed, 24 May 2023 06:39:13 +0000 (UTC) X-FDA: 80824196586.02.120DA59 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP id 8714418000D for ; Wed, 24 May 2023 06:39:11 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=loGcfNQq; dmarc=none; spf=none (imf16.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684910351; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=I7nRLrC53ZpahuFKynf6W2iN4n5J8f6yAz18mg2al/A=; b=yYNi8p8FS0l3TkkjAtPtWiNl+FCyRyZpa9yoo6SNmnTemBcOoSlYFmhUu4NP1a5idr4GOI Sg6XGGLn6HWbcWr5WRCxDAjtaWorNGWJRY3lYj2KjrSNarsRZEPCsDKUbw3m/E7VrYnv2G COJI5gt1pI1wfxNMdIBaZokSo/u/dLY= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=loGcfNQq; dmarc=none; spf=none (imf16.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684910351; a=rsa-sha256; cv=none; b=CuoCya+U4v4zI49DyAw3H6x7J+5Z/gfsh7+zzVYBAF6cFB8hsXodiXcEUH5mrZfIa7KLCR UzclK7efvZ4ymmScG3a8unA/dQzSX9PPc+8an749JsnFnPZ4GZpQsnOxsWmrG3M+LoGdA7 HkaBE2Hg7umbrc7MQFTRQpoY9GWQVOc= 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=I7nRLrC53ZpahuFKynf6W2iN4n5J8f6yAz18mg2al/A=; b=loGcfNQqoDcdpH3rz6JPxASSDR s0fquDmmeLd7u6HychBoJwA1I1ehMTaxvhR/hGW1eOWoplEmBpgawme3dl/bkliWeD81N5gRQagz2 75qmOSQmgExHJPNJTU+rjkO+l0lbgtXMcL8u7p4ZgdUF2l2Y0hzxdH1lzlTbL0Y5w4ExDTy4vlzgD J0IgvzxF1QbdE/vnF/UZY4vxDgPzRezXMnqD7bbE1yilua/MaPprSSMxo7eCBWXprIYSQCK0MrICO J/7RLbRylWjr2yXwriuVGNUk9p8tErXqthikzs4ueQbj9vMzKxNthea3PnELRedBPiZHrAIcamUza 8s/a+Ehw==; Received: from [2001:4bb8:188:23b2:cbb8:fcea:a637:5089] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1i8y-00CVkq-1K; Wed, 24 May 2023 06:38:44 +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, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 11/11] fuse: drop redundant arguments to fuse_perform_write Date: Wed, 24 May 2023 08:38:10 +0200 Message-Id: <20230524063810.1595778-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524063810.1595778-1-hch@lst.de> References: <20230524063810.1595778-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 X-Rspamd-Queue-Id: 8714418000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: gs3me6etrsg1przuecajax58ax4x4n6h X-HE-Tag: 1684910351-500631 X-HE-Meta: U2FsdGVkX19GVR88a2ZH4G+zIK9YsYVopRSqQCKPIPITF1K02G0QozmzThkMPjCOmzY0yGbRtRcCH6lWd06kiPUGQFXROE+vUi5ApREe7JhiHSrXSpq+lcvzw2OJbzX71iNUn5eH8Nyo5jFG7wlP/2M2sr9L25815riDdOkUlmhVRAGkxD2tAfANxOti3ah5/j+Nh2P4AM91u77XWKy54FCLRGfZIttZTLYnei9bdmyPPqJmvj78kN5HgDsh8HTi4rKsw6DP9FUypWZv833uyA+0IbOq1yDGJRTwSV2I2rhpNzJ1DDKLrcRFX8WEvtM41o7tXf+QI9FzkDnXETlWoDUYdYrNXKw+Lt+DyFqlEr0BefC4+UpYShIZA/xO7ry43KgZTwbYiTJCBEbMhLWMu7ky+yk9KdU+CoT/T24Fvy9GySJ3xPvLFPvTi5nN2tQBa8nCAz3u3SQrfaY56w9CX9/8m3lK1C69RS2HAlIK3OmtfdJ83otJSHQ6jhBr2rSRWBwDrEnCSucbxJI6RMD+czyNdXzFFQYAkbDD5c+PqttxqGtFU/SzJgZH8Dn47gZq9m5bugLfxIETmPfd+btf+ipAp7xHbttw8873bqcPftBe9uZQpKesj+dnVh7GEavoIu46B4iE6KhCzOAeWOONiLE5TivogvgsptytmNcLC0RXPXDxhIaqt1bwvXpHHU+9GIrDi7QxTTr/HX8mKGxwD5a2BCpM2NWb4t9XUr7jWzOvF4A4zw2+a8QPftb97uhVcNNyq7OJe55CR6MzeWhz5ZiGJcLaSyO5lP4KjV+/F6He1zOxAnoOSR4owsAgHcFXXuI669ndAPMaCzhBZdsORizqpZhB/zfAqW6KXNTJyxzsNLqe81VXa69Ht9zNRa0Kt6/ep2NwPaPoIWFuV3FHZwkdHbzoM1vFBQ1e/E96yTSrD2ewcuNfvUlVLPA17Y4CyoUSgXe1ldcw+C8wV2w dY5xfZ37 FnkOdyrjNK/9/YQi2QxT3PodmEjHD1J0GzNUoHGKyZh6b850YLDQFfxb1+vk31/ZpgcWsI9uFsd5haYZTvYRaTvaKOVzDzNPOXuALHNAH0jgfo0YQZxQEA6ZntFEpcsXdfmtzkVQqqqhVpd5Wh0cwfxGnlxqPmIVV9PC913EUkYrAWBBxiI7ihZetKUmY2aK5XVQK0b1v2HrvyJWc687p4y+TYrBFno8xO80zSTxEC8Akncvx6Gq0i69iTT2CuwxQEe/R1Jv31LUaPCliM+8SbXB5UqAmOvg/31xZxRXiagzq98eAy3jDYOL/izXLc71v9CSGNDGjSdpN4YuYPrJJKXZoxtJs4yIfkoPWG03SWKycxiKEHMXLco3mqCXyXCA0W+/RCDq126BH8dhdcgURwOOSlf40zKH8ppOPQBmtRb4WW43JGhWcn6AMwiqAyTSD+lhZQi4GzH1YDd0c0w7rX8jw9jpUO/eb+WrkqLXVihnJjgIAeRNzt2SD8l3G6bpuUbeAXnEUZfZAaeI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Miklos Szeredi Reviewed-by: Hannes Reinecke --- 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 90d587a7bdf813..bf48aae49daf56 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; @@ -1382,8 +1382,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; @@ -1403,7 +1402,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: inode_unlock(inode);