From patchwork Wed May 31 07:19:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261549 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 ADE1EC7EE43 for ; Wed, 31 May 2023 07:20:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17CA06B0075; Wed, 31 May 2023 03:20:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12E2B280001; Wed, 31 May 2023 03:20:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC1C06B007B; Wed, 31 May 2023 03:20:27 -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 DCF226B0075 for ; Wed, 31 May 2023 03:20:27 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B099A1C6FDA for ; Wed, 31 May 2023 07:20:27 +0000 (UTC) X-FDA: 80849702094.21.2DE598E Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP id 001781C0005 for ; Wed, 31 May 2023 07:20:25 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=caV75RH9; spf=none (imf20.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+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=1685517626; 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=rJDdDhTRqJ0hb0KJKHGdzKkpTnId05huPY6N7LjcMHE=; b=5n3gwydjR+ufmiJ+TKpMryAonGdWflD0YG0WzVDzKT5oLqU5/6nIgKPQiZqSPHgn3ntw8h 1GtYMhhRquzV6OnsUyYBi4tfO2LKkWfLqWq6vrPdqsEcasxcLwCiH7pfnyMXa/5MyIiDVP GSdU3pbDCSkucI1Zzri+RTxU1C58LYc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685517626; a=rsa-sha256; cv=none; b=aBvuUzxKYsSxefOuZh0J1toKPbjknuIg0zje+ckSnLihikjAtuwv+OsjYGvFSwk9LRcHLD PckKaqHD2DHiv912q5bJswfQt1otZYEMibg+mxyMjz//8NtOuiZK7HYrp0D9vqPvjPfcVk A5m8muK4lU5g1BlLp2d5QPMmHLdenhU= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=caV75RH9; spf=none (imf20.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+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=rJDdDhTRqJ0hb0KJKHGdzKkpTnId05huPY6N7LjcMHE=; b=caV75RH9GjbjbIvfo/jDfAInhX zYGyafMyiy8fIUXngpb4b7orGLjJ/3uUzi842pRK0mb3Ij62dCApYSRvbMvy7XBq6shE0uByzA0Q9 g63D0B1dmceEeU5OqSgve1SvjemzExqcYyaL0HLEbIWLRSdVrii6oDODdkckMbeiQGai2P+iNUlxD SS4dr1cJy4Srcj92O4sdjP1JeF+wxOXxBcusFwd5KqU4OIclGHUTYYTHWhxqRixAA9SBKxzBRMuzq lBELI9gho7DL1fRBStQKyGkMBWG4s68/52SIcwhPTQrWl9kwhUb9PbEngS5hZjg/AA+/fbnqNsTK7 gogLC8TQ==; Received: from [2001:4bb8:182:6d06:f5c3:53d7:b5aa:b6a7] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4G7w-00GPhO-0L; Wed, 31 May 2023 07:20:12 +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, Hannes Reinecke Subject: [PATCH 1/8] backing_dev: remove current->backing_dev_info Date: Wed, 31 May 2023 09:19:59 +0200 Message-Id: <20230531072006.476386-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531072006.476386-1-hch@lst.de> References: <20230531072006.476386-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: kx6rpa9qksoyagpc5cbfxxq3x87neitq X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 001781C0005 X-Rspam-User: X-HE-Tag: 1685517625-331954 X-HE-Meta: U2FsdGVkX18nIgFldO1Lb4YTnyFl7bBny6JE4/cSEKZqqKyHqjmI7nS8Ui15dSsqRH32+7Ft/1jQg6ilHLBL1LTsPb3wM9P5gb7lLWTOtYxV9Ic39jVDCHoJmrVbAlkBMdgNOUy2IoNsUcDHXHUIoby03DPqfsT2tfec5F+hQXBLg4xx39RuOoZTwOrVPaKRbUgwV6SAgEKzYp4riZvZmAbowg6uHO2lqF6e8QlXlD+9aFmNIl1KHf+U/ozHYHzRtOdBV6HyAW57kNtFnINuXBihVE8S7dxkaHcYO3DiJ59dUzqT2IZfXZ+nEzwRuPWk2654Jx2464P/HiG1pSwncpXNE+aQu59dbcOG0Gjtr3PuANBEVoeTHeZEiu1Aap0x6gbyGphlfYF4tna9W4jNXQ9YZV/hkeiHec3JPrObD3pUGcEIBnBS7sJx4/2Fk8fXXHCwIrrqEHaAgTVSa96R7H+dSDpACpLrDWFjomDSoVJsCSNrqxME0UM7TTADCQVP26TL91iAsvQCj098GLaWbkVbLyTVGstCg7o7vNq1DVfA1M+ShIzp/hC8m8UjuwMpelZwC0DbRYsv0OtpvuQYOU7YsiHoNZfYFnGOcnr78gloTXsJ9Ekuj0af43KwJf+DXy6umyqIiEPpFom3NG8Us+cNcFBY2nbD/xFdsLOaEBgCi5XpjMCwbuRn+14P/aKMBFD67JGTuMLzfIBbApGt0FtztNOjP6N3Kzdf+cNQtukvtzrBIo+M/O3rjiP+ryb0hBL16j9m+V9PKIIcOhbwLthPLBrX+iMnOe5/dx7ZLI1uoFtwuU4/yhgGhknOnLFq5wO9BtBFxihl4gclpnb0mQluU/czqZ/1lPo0SjPjRo8NRtx/53tApjseuAfxh1FbO3ul7zlw5ISX/n9QBKgTihGMouSGdv1XRr7/MtR0P/3ceD/w/xCRSKTSGQ/492wzwhoJ1uaqarGI2CuhEbQ KaINnRjk irb4x2iUQ/dkQscYW8WP9+mcGmCpVePyrulmqPXnYKK/RS1TNz/IJ4vtwJkXkYoVaWgc7SMOyB27SrQGjsSTljv32l8uP+k6hLbwMws13oywLpuJWk+amq4O9VDTnY2sQEDUugqafj0bix6LtQlE/QbJ3sc5Xs9L+e9XjdWSlW2zS9IoRjlkKkEAjmAxjxgCxSdQgKowiaeqTDIRh0g1hibheb65SJBVnNOERtGP9aLYlMHEkkIR3qpM5To1gI5RD05wa1C6ahqBvBozNwINZ+PjgKP7cmHCmKHk/LTS1uf7xMRNH2eXB0Cu+xsUsbi6JnPMBNAdZVr67XoFI08Y0GGMrV0q8MeX9vTV0L7nSgl2cFjZDqyy80oiG5kkoeaNjm/7SY4jTiGLg5BP98HiLHrYqhbcelgl/fH9VrzeCo0LA4hw3ld710VH4rcDEo+cUhaXGMvoPI+NxqoJQvTl8zGZrmdu4Oh6ZYmytYuThTZu7DY/qNkzTGs19IRAB5o2vSrCl4NsoVtzgsmw= 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: Hannes Reinecke Reviewed-by: Darrick J. Wong --- 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 31 07:20: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: 13261550 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 94F9AC83003 for ; Wed, 31 May 2023 07:20:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 093676B0078; Wed, 31 May 2023 03:20:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEA7B6B007B; Wed, 31 May 2023 03:20:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D14676B007D; Wed, 31 May 2023 03:20:29 -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 BFEE86B0078 for ; Wed, 31 May 2023 03:20:29 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 90C2880253 for ; Wed, 31 May 2023 07:20:29 +0000 (UTC) X-FDA: 80849702178.08.8C421B2 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP id E925B40014 for ; Wed, 31 May 2023 07:20:27 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ngxKf22N; dmarc=none; spf=none (imf07.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+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=1685517628; 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=1AhsMC0b8Le+Qj8+/F9cJR6e5GLVWYekas+17NCVqqI=; b=nbxfUWeYHogLncD1RA3TrHT7ph24XyFlLyYuMvJKzJM0Dy2KyYYYaS8TfRhwKMGKvG3+ji Oxn5mJDdkH1Gby/iXSG3dLa2hr3r/YUpFINPUSfsnO2yVmMV5Itlrmo7EmVsXk9lir6Iov EGK8HrUhZrywHffeJiTlrTleLNflHuw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ngxKf22N; dmarc=none; spf=none (imf07.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685517628; a=rsa-sha256; cv=none; b=K583mdt+Q9bUUTCZ82VMtPEt4xVcPeiVXcCbshFpjNPNVyLLm7yefJIB3o22Pxyj+GiHR6 LmVXRODQcAnnRRiplddb1BSfQFvG2sAGP6L1TY9iskZ0N7HW1nb1C2HosQ8THvB3htA3aq umY1DKc+A4vHlIoJtpCV3yM+biQApyA= 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=1AhsMC0b8Le+Qj8+/F9cJR6e5GLVWYekas+17NCVqqI=; b=ngxKf22NWcVmXxqJwcEfwC+j8T 3PxkmTMDjWxvvbR0duw8sA22hBD8npF8M7zy6uMP4A5nP81zq24egxiseYxIct9QT3BCtbnaev2MP wbiG/KzTwrwXiTebokTJ7zF2jRnxdAYau+XBec+F7XpGZX21QBO/OVfktTd4rlLpzooJH46MVsmsK +e4Tx0iJl2vZNXf3rTUvEhj2U+bq4yTQ5Rorj9IL8ZzUYJY9U+Zj+4quc3/7Yk+xX4BT5iyozg9is oymt/Or6TlEeT9TsG94njHW/hepEKG1n0Fi1TB0ymGUOgiWMRRS2N8SqiUunjzPtuqt/z9Padv5X7 cRckgdNw==; Received: from [2001:4bb8:182:6d06:f5c3:53d7:b5aa:b6a7] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4G7y-00GPht-1z; Wed, 31 May 2023 07:20:14 +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, Hannes Reinecke Subject: [PATCH 2/8] iomap: update ki_pos a little later in iomap_dio_complete Date: Wed, 31 May 2023 09:20:00 +0200 Message-Id: <20230531072006.476386-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531072006.476386-1-hch@lst.de> References: <20230531072006.476386-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: E925B40014 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: st4h6pkif7xhofokoxn7yeg5t6b8n66a X-HE-Tag: 1685517627-707212 X-HE-Meta: U2FsdGVkX18M8mFYJNKLUNG0OhuohypihxZy+og9mpqpoOAfSRoYW2XmrGji1E4rG08CyTWT244jiUYfNKarDviQNBpjuSF+6vX8iK6af4i/tkYcKsugu0sXCsG9X8jKWSqG09k0m7TeV+638UAPHNls2Bi82MuBxxIyjPES3VEPTAWYPblSxxJyYIk5URC3LRo14hR4hub4wlz1Dv/9tLWQHdg8AhR64K9m3V73RPZcX6gvsTMUmhAAlsW/XHiOMepqpMZlzPGFqPzIJQ/01PbN0AoFgl36RMjt1LCabVIMrZ05FKql3kkfodpl06+s0og6z3FMnSPc+rwECJCJ5wKQMY1kkA3l56DaccELmAVLPZ9jXA9L5MkgkIu/a7YFKOWwcD3Z6NTd0UhSSYP+lbWlHIEcWIDagutTDghpuZUN6oYFxBNpXDUweIvLhvUYYWwe0gqAxj2d4UWFmL0fzK2jB5fW6bz0U9miRLg6KntwSch8kJB9Bz4UqNM3Rk20xU24b0J4dQRWk6+wgSTAJiBGYmrSN8IKouAouX+5EA5cKOX/RGNk1RA0ekdAs51DoB3hwMYgyTG5pX11hYic56ludisTjLLgblvHX8YPU7NXbCih6geAwK6AJBoKmNLrcplhW/E96+zOkGa9AdN1Kbn9HqklT98E9QWV0EIWEkIOouJugK3Ab+8wKka+6yrCaOJdkiw331KBsokgUjD68gKOIVW4lF8HzBP3mk1LUrg9EiPpLiEkSBy9vw9jXMgzmiDvNF5KyOodIjeUqogsXrx4y+k3y8lkpJoPMdbiSnmEgM2xKSHkokItGrYa26fJY+2RpYT/DCnyWUrB1eVuqV+CwwhEwXpJT9a3NtAsHCvVOB7P8CtIVRrdZ3tuMs1vlcM4Yc4eRONZ3ulNbgfZfsN80P1sPMaIztufA1SF7QNN3fvOrl/zCAqwnNmAxjzZYT58Ez5n+/pmFJCFnhy lzAf3vLM hwm3S9o1sh2/snsxXZVMng/xKqBoVl2yoX8EZ8I5HjZ4aP8K+VnPOv8CXwOAxwXNMJd99juouse+h6jektkxk0EHLpBmL+Up89kZ+HPRjdU6kZyCjGwG3iXoYAf91Z5jDt/llO2TSKHzWRhLByR2ByAq5iIaILB76Hjrao4xjehDtlvcv84jnzQzEtNeUp2AJ/5Y6HzImuVhg4RarV8qtmmW0Q+jPkNHb51PPmXuR0b4yxI5TK6f3QAWSlK1xL5rSb41RiJLyjJ/mvH1zzA59jMpbkwhXxqdZMm4xsri8hj1QLgv3JRC51KaB4SJOnen8twXOHqpnZ10mHpish+idOSPIk+AAi4vNOIw8MdxoYrB5ByJjmHLUtliBEZnYDbSRjdxPXkACI69gcoo6NOf5UECh5PzePELq6L0Upy5VrdfQJaRzxLX8AIDnBQCPP8nJ3jx1hyWs5GbMbjaQMY60g82OEbsSZFIP60r3c3XPGdus2m5deJpMAkNy8am9NSU0QwbZ0aOx0pU0jB0= 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: Hannes Reinecke Reviewed-by: Darrick J. Wong --- 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 31 07:20: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: 13261551 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 A6F82C83005 for ; Wed, 31 May 2023 07:20:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B41546B007B; Wed, 31 May 2023 03:20:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF36C6B007D; Wed, 31 May 2023 03:20:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96A5D6B007E; Wed, 31 May 2023 03:20:31 -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 875376B007B for ; Wed, 31 May 2023 03:20:31 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 52F8EC021A for ; Wed, 31 May 2023 07:20:31 +0000 (UTC) X-FDA: 80849702262.19.5A1B556 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf30.hostedemail.com (Postfix) with ESMTP id 9DA288001E for ; Wed, 31 May 2023 07:20:29 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=WIvJCu2W; dmarc=none; spf=none (imf30.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+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=1685517629; 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=zBZfLo79n2onda8TMRoaSImQJ1x4yClUpeA3xrekMTk=; b=eqm6HOHvEgCqCIkOU3hDhkX+KRl4SagM9zPvJwOjd51HZV7AsNDRR5WLKGa9IDCMX4cCqI vbupAi9xoIYdMubD/gdEwvEmlT4C94VWYUOpFQFM88ULsVgJapRLKL5vC2gLN4ElD0lBRF IMelR7BHq9TheA+eBAHiUKLzVdY2KUs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=WIvJCu2W; dmarc=none; spf=none (imf30.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685517629; a=rsa-sha256; cv=none; b=mLKrnxxJIrgqp2cTT3MRZKi7i6T9wP8XgV6oAdOLVm+5BPydgJ0wjRgph0yHkosLcpSNEZ sZfNxNDdVj+6nt69V55zp9u4uRQKH0RlZc+EA4VE+JFjkZFSof409/xGyr/+KNk+YWopQu szto1Nk8uae7adqlrreFyxp1IiTEdAI= 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=zBZfLo79n2onda8TMRoaSImQJ1x4yClUpeA3xrekMTk=; b=WIvJCu2WcZCPxyyElumOzaF+3c /RvEl7Rd3lQdRO0Twp9TVret57OwjxhPz2wC4zzHR9NJ2222yBJnOaOpx+0Kw5lvEwSA8dKaL3vWX mI+t/R/Z5f8hm++0kU6KUHfULeRm8WoThwXgVOgmdYePJYzaXGiGOzdJaJBR5bsYUTmXW990744su +5OM2lso0jyefF2GTzsaJGS5INdouHWmZpaAEh6NceGkwXox+v1NXwvj8UpFQCWcZ4zvAS0tKBu3X pXSuBa7GfyBqpWj1/Wfh248oclvoi6NKSkGEzi4PjB4d0yeGNgQaw31c5eU17cE8JTvWdyvAbZWmW WoLOfN0A==; Received: from [2001:4bb8:182:6d06:f5c3:53d7:b5aa:b6a7] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4G81-00GPiD-0U; Wed, 31 May 2023 07:20: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, Hannes Reinecke Subject: [PATCH 3/8] filemap: update ki_pos in generic_perform_write Date: Wed, 31 May 2023 09:20:01 +0200 Message-Id: <20230531072006.476386-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531072006.476386-1-hch@lst.de> References: <20230531072006.476386-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: 9DA288001E X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: zbp3xth1sma83f7qstrp5ipfa8dmykzm X-HE-Tag: 1685517629-596588 X-HE-Meta: U2FsdGVkX1+7TwMPsp8bdFIvq5oWkELFFbUSY3QwJe3D1AIAcCJapsLOTLEKj1OfQWSHFrQFWBCOvJA5U7w1Y9On9WMwcIMA39XRiSB7rCzMrf3SSlgLgp38W+kyRRKv/Qm/PL0ktSiq88T6InrQNFC3dlSkNkuNKMtUWgRl8C9aFSc7BK936WhG7jcokgLAhKkgc0n3rIib2DtMRvkeR2zNEPdijjUeZUoToM1NyyrkSIHOCeXHSZvKq5CxX0IoF7W7ZqDaVkZVRUVyYTum/b1Xfqr95/PDmUe04WKvYi1MoZR2tKro1C0Qh0ihwx8Q1aoEaDGR5rTinrQ5fTgfaJ+MV6tP3wWfalEIMl4gks1CtM4CgmCqwdohOzZ5hEr2jdzlUanjIgtSK9m5Zv16pRcQblyOJWT9bRbb43Wa58vZXSJI3FkP3df9epklfoB1/6msgMUmZxhahVpqa/eSnXIjcLYWws1G3kfhk2N82IaBMhTVcybtDazYhN1/M0ptSA/JW9+mULn9VF3xGK2WJ210mDFvD07d0KkralKns4PVdPL3t7ABUMPyT2HEc6wgxawYmD8DaeK6pSjh8+5v/RhBOQ0zXi3zy5RyWcwS4DZiHLCQSPNHNibl4G0fnVHSNGdNcGtrC6Em/5k3wWsFoiiYxFEKU/PtMsroa5MDRt6d21l752wWptuV0Rsr5KmLheUo40drPsK6nSKmOmEyCy1Vcl5H3pB/ti1usOAmUr5hsSLyB+JtWhTfZG9gjtOs3QBYludyFngIN0lz+0HPkPjxnTJ1t7lj8KF5t1RZ7W31U3/XPCBdW0UUeN1wDkuqSsSGFg7hK0eo9g4L1uXL6muOJSJbboMS37vEcK+QxGE8xEUtybaBqRbmaIWCFv5G0s98rrtyQ/Vaan2CCUVbjG9Led0k/V6QBfGp0ORbOpe+NOGTPQa0qLpdD2dz8E4dUEzFZeXA4faiOnLVEUk GZwuwrWe r+lLjvoEExb/eFKFlI7QA984iZdguhRAViAtvNTFDrKt8A82iNP+H6WfVWynFo5rmqJd8R60GPDzAnYuGyS60HA3CDsACwv7l8yS73d6eZVDr3vKp+bOkgVFzk0qF1kbEU17MjEHWb08oqOPyNP0zVvlP7729WgZRz13QeAiMWMWaLaC9NoTvrcE7iEomelYrBcy5/LKBSsYnv0G2EIg9H5OgBkd0V5oRLpeCuZTzgJ1zfU9E0rpwPyUEhuVgi8lzyZZ36aDEsLVhoZ4zbEyCnS/LG3VPK2ppt8cg9JQmbvTmlaN5wYZoljbyQ0oF390g4T0SefLVojdUsvikQpwA0KwicUOduoLrOEe+S303ZSUh5SsaOJ2uLiLicAYKbijeo4jwF8L46NNXLCrOHlslddLFuMwbL0fl05dHXqcGAew5YitztXjq5PvWa9notJaiR53dJF+MZfX4YnHJzUC9Uxg19fU6Qs2WoM0TpL+8LtNlsqHx0zBvYPPdsuHzSnJTsaUwpo/yIfk9DJfOD6STMpVR2g6aT6M6lRk2 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 Reviewed-by: Hannes Reinecke Acked-by: Darrick J. Wong --- 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 31 07:20: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: 13261553 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 AF9D6C7EE31 for ; Wed, 31 May 2023 07:20:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AE10280001; Wed, 31 May 2023 03:20:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6839D280003; Wed, 31 May 2023 03:20:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52460280001; Wed, 31 May 2023 03:20:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2CF3E280003 for ; Wed, 31 May 2023 03:20:37 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0369EC023D for ; Wed, 31 May 2023 07:20:36 +0000 (UTC) X-FDA: 80849702514.16.8792C4E Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf09.hostedemail.com (Postfix) with ESMTP id 55329140006 for ; Wed, 31 May 2023 07:20:35 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=P7EMymZb; dmarc=none; spf=none (imf09.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685517635; a=rsa-sha256; cv=none; b=czR33cqUJj61pRat0Y5aNHuX7n3s9TZcalmmFCFUYsudUZ1XUfxHCg0MzW8DBdK6tyMEMx 6grnGzdz5jbY48Uo0pX30JD+ixRoTFx6LWUEw9991WUT3EekParzUJuS8f1CGU29askg23 Q7ujXpQ1UN1mpTg3o94S5/fPnSNjt8Y= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=P7EMymZb; dmarc=none; spf=none (imf09.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+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=1685517635; 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=4ln1KAbDHy9yBOHA1NQmJ3I7VD+LrDF+lbZ0/N7BIOE=; b=uXUK21aVt90qEwawdO2I+JoEgvNMpFgGzfwdGbayVgADZOo8VB7+f0hg3zyByPKlDyOXi3 43kGSzwl85Hu5ck7f5FSJH9W+7x6/GoBaVoEJHgKYAdZjRKqAhspgGJ3c31I4DFYOGiL+j Dm0SUk+l4lyW0z6OT3cmT9SLrAZn5v4= 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=4ln1KAbDHy9yBOHA1NQmJ3I7VD+LrDF+lbZ0/N7BIOE=; b=P7EMymZbaMf4CPWvbtTuLH92VN MqnRNnbAEBNDVD8OMiv8ebWC+it/ueXM36mJCcB7G3ODgHJs3tdP3qoV5g2RvTC7KqCaQWbYiEZb8 vT2SRM3Uanswsa6v+vSdXkQxbf1LYKUZlHul/riM3uXa7KyHf0nfrACMNI4uFMP3GgbI9yJAJh4gv 3oG8UNCAJoPpZgvfaW7sDAYEOuHaeS9BeA4z7na00RFhLzEhWGAn7FfW1Ik1gQ2pdAG9Fx+r8rQor Oz+LpL0MRW7OvyW/1M4ooWk9itJKblI7C0BESzQDG6qAejwfiLJR6xV+9hrwCbJzUVYoUd8Ie3hTk U5PhsZ3Q==; Received: from [2001:4bb8:182:6d06:f5c3:53d7:b5aa:b6a7] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4G83-00GPiT-29; Wed, 31 May 2023 07:20: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, Hannes Reinecke Subject: [PATCH 4/8] filemap: add a kiocb_write_and_wait helper Date: Wed, 31 May 2023 09:20:02 +0200 Message-Id: <20230531072006.476386-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531072006.476386-1-hch@lst.de> References: <20230531072006.476386-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: 55329140006 X-Stat-Signature: 86uib34bjgtgp97q5epbjpxtxbugrqjs X-HE-Tag: 1685517635-853177 X-HE-Meta: U2FsdGVkX1/Jbr9K/w3SleeRBGNU1RmLC8DI9VNldMSwPQ9EE+wai7L1f04Mm+RqkytG8oEututy+tKAxduynTgR4sNnY6J2iUOYXWHH/phqBPyJwbs21Sus7QLmMYRSD7/lM6bITP31jgzQOrDS1fYnm13FhEKSvawTfoWtGcsGKpqMljCWmRqDOqSrQOo/WdU+mfilKYR41OqV6+fBGFgdFd+yTj8ITgbPzrJ4mA/8ft+xavV8obkNyuepzOxXJ/CFh7F4cAn0HHgtmDSrN0xR14SN/pUC93a7/6GnUUPerQZh9PuD9QEhWl75PR73Mxa9J79i76ean7wlq/b8jwXSIhI7ZeFyRstUbzqN2ukX3A9z0Vn3VLXFLG9Vs+ULdPAeVDm/HvN3aNAmCP3RjMAfQIYKxjpYala+sTGeuwFchfJ7hHva/Zc+46VOxQC+OmAcaRMB6cBf/ZFxjCWYY2PQZzZBlcbeAe59cKEo3wrFWB+tcHylE/kyjfgUe4o4TGepBPgI4pv+lD5BUCeTsHMLh3xreMAEEmu8LEjTeWJfHGT4cam1r6s00bCYaJqjLQYzoFY26BcNxurwU0s0GVGF8xvSetOgNicB+jxCzctM8ZXRa7rup1ipTAhChPBsICYX6s6j/Z/ONl4D1/spqc8g3+5tK0CBMw8s3wk2TeNzoCe/pYYSoVgr2Uz449/3kxCGs4WWp/y3G0pe+ZEkWBS29UvFZ248SLFF8qdEXq5pnkAPgFLDoCVrQEUYMoyTV2GXuyaITBOmnD6WUU9hB1i9GNhE28yvSF+YOxm7YmmP4H2a0pKFtEphUevQi+/f0XQh6lJbEl1zA9iAM+CSV2XLBNWYlZNX6LlnzHvwefd51xYUfZ4BBKqokfTFS2VevcZwzrUDzKblwPgcSCwIvmofxZBfHX3Nbp1CszQla3hc1vSbi3c0YKezTRdaWcvgIeQwwfrUeB1DyBTxx2V Tyh8m+vq Na9bUMN0CCdeUsreBN34uBNrf+fjyb6BGWrN0EaGb4wZ6yxYvNp871Pvu6O/b8n0v+ZC7E5uMMrCogMEyizAs3retxa3BElBY4GtVij4EEEF26381r+tgV91i3eQchqVssPvgcOlJyyiLr4POpkP6Y/a2/d46XybTdBmTH71qNRiVvHgFiiBxHg3WQEk3kAX7rsFHRKzesbXlU38pjERcKUvJQXbIx3mF4kLrxO+7RqsLpV9WUMRSO1vvAbtytI46IHf66r4kFq0xIQEvGXJW0qde+2ZpX1FrrCcmMCeeBTiY/wmeak9qZKxjbyBy65QnNqSNVFddRZYJdhicfYFq56JW+qANCTOOqJvZQnqCwEDb5svSsTC7YgcyN6Rz/+MgOUhsdP0xy94qwM3FIczsxwbIlH9qF1d/01wRPOTfII7REOX/u+vrpIwS/gjczU5OiO2dvA8mllc5iMcEfw6VQM/kpvi9TXHkmP4LGb0CUzuWLMuWCNT2F6HvT7jnigQRxKyaE8xjVxeIEy/eyM9O9o0hDnkecgnwKhGPbBAjJ7HiAZo= 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 Reviewed-by: Hannes Reinecke Acked-by: Darrick J. Wong --- 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 31 07:20: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: 13261552 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 85B77C77B73 for ; Wed, 31 May 2023 07:20:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CB3C280002; Wed, 31 May 2023 03:20:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 17BAC280001; Wed, 31 May 2023 03:20:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04261280002; Wed, 31 May 2023 03:20:36 -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 E9434280001 for ; Wed, 31 May 2023 03:20:36 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9965E80227 for ; Wed, 31 May 2023 07:20:36 +0000 (UTC) X-FDA: 80849702472.23.90B1654 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP id E52D418000E for ; Wed, 31 May 2023 07:20:34 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="ncreG/Qh"; spf=none (imf16.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+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=1685517635; 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=oeUDNAIuBGOOZ56XkyqMnjDXKnQawdRHpRl2i305rtg=; b=iq7eZNVqiOW4lj2OatCospJaZL51YVZCoQUa2cR4LvAOw0urv5xkRLe95DpNIW/3FMJCc8 m1lF5FyEhKx/BD+qmEct81YPLvDE0f033vpgdiEFLnkz4ARVNi0KkVGAuvDAUeK1rlPhR1 MedTHhRGqSBvEjRkKKNHtg01d10iW8s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685517635; a=rsa-sha256; cv=none; b=tSBCr7mbEYjv8w3NcIuonxmR+APmJpnEL7iHwirCRHIDypWMx2caqXIH4O8R3Xsne1Vwbk uPbB3rJdJWa46exXFu12YUeDz4KaajN50xEmlQZXQH0eKWH8+U/P8NarSmkLnDSFaSgW9d RVle+x3+aKyDhPeg8cgn/sKyylD7GNk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="ncreG/Qh"; spf=none (imf16.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+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=oeUDNAIuBGOOZ56XkyqMnjDXKnQawdRHpRl2i305rtg=; b=ncreG/QhyaELQ2k8D8sdUXciwt gOfrMClk0xHmq6y5/Blma4l71TEq2fD6Lp+5u5zNS2rJGAbP27wqZyUwUgR6lANp8/zka/so3nRuX /fLhumNBrJ/CcYaaR6iisG+ECwkwOhnKIo0dR71ulzPLy2vURp1/XGDQhY6+mMUo4zS+oqnpfLfAi pwexPwws3xiWx9JiWDwRitL7J4US4DAjIajF/QRqgYJ9Df6Tap6WkV3jyxiTkhoNsltUay9LhYGuy J/V+hmhM4e/nPbg8iDcjx6APJR+mNcUe4ny+f4cwPKEl3SY5D0ymMPR4r/5+Zrqoi9qLmqLIrwtYd pGMn73zg==; Received: from [2001:4bb8:182:6d06:f5c3:53d7:b5aa:b6a7] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4G86-00GPis-28; Wed, 31 May 2023 07:20: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, Hannes Reinecke Subject: [PATCH 5/8] filemap: add a kiocb_invalidate_pages helper Date: Wed, 31 May 2023 09:20:03 +0200 Message-Id: <20230531072006.476386-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531072006.476386-1-hch@lst.de> References: <20230531072006.476386-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: E52D418000E X-Rspam-User: X-Stat-Signature: nj9us17eufug48fzhufpqaqqqz9fg85a X-Rspamd-Server: rspam03 X-HE-Tag: 1685517634-639176 X-HE-Meta: U2FsdGVkX19v2e5JxcaQuRdNNkbfa2Yy4A43R51x7hIaWDuArNLYdOYsSqf5LHQ/v0nIxVDa0lhDe4Ucg6/pO/Y9XJNNU2Sgc0+NFOOTuypCQAlAhccQ1kGCNTDs3k+wfc7UiJEHehKanhlvFgV+O6wc8zOqtsdk/1b6/qs2e65vgkgQpcnua98D23C9cumItDABebHh9IQm0DOvmKNGDMsOC3F4yFkXQ7pvjCobKl2TAq2ZhjLJNIHqnvJ5x5yg3j0QtDfzWBRiK6nFbtyPBYXmvBY8Rplo+YfYY+z7iq8lJUZZ/GL3SlhPExwZ+M0SQGQKjVVR6eoSadeURcaUva0YxLC4EAosKKQSv/p54lWXq23ODaXlZ0OUUiUpQ9d5IqUnumZ2clbay4sizjhcNBx3gqBwRfQ3deEeNntqQRvDjADjjQgBvnW10NPNQi1s8rIdAvZcRlqUWYFpit3Z9s+KYRwyLReieaWc4MYbP1aunpF+W5j3U3cZXdw3hWjzig1KZcspxZzIPa6j/Xb2AjdO0Re4GXZz2xHEpKrjtml4oxOo4FqBRJgEGRVpgFMqZStvzZnMKHW5rK1J05NIUP4K+W9/R346QdpRbVIc0vYfbltVoDa+8Kbn+zP3XMT8MKszhqVIznzO+s1fm5kPkFd59n1Z4TTV2iLvyBlbChGacLG6+YZ0XML6VZvRaYkf6n4xm4jwNAOL4v33L8To11fVcY4YOy88IIp2GBDju5GWLBnNo/W3X5qV2vWb2O+AFhPma0ga4wz80cu/I8u5kA/N2VR7oojsSNCkrD8zXH2zBtOpJkhr2muee6X4lSmyM2buLuB3ickGZvAM0hJ8BfvZZ4WvRPIifPJB0LocFalbJ6QzOusRqSpsGAYYUN1gWPNAncCyu4wk8Ei9h6OsmWepLmeK3794EgV/AOSBurE5JICrYp7niMrQcHkhS/XSEvNC8vFwI/vF2HfXfUr ZOLTzvYA Pvd6cRuZGcuaE4J+QxRpWl158Hmu5bnaPjYvyg5qG/ls6yTyVbcubMKJvIUObQE/7mIPlOOJHxXOEag/hfEu6dw4VibBWj1bgWRwOnauXIWjSHu1agIHABh55h3R55pcGakYGcs193VMa2++Kgv868tUtis55zQJHg9N7hu+LNtfoWHd4OIJu7MXaU4O4CHWOQ7T4irbh9aUDYaVfXTFFoNECmTw+/OY5KqcDo1esq7a9Rj94mENWRTUWJbBFH/+E+mF9GF+lxQhZ71AuFW3yChXDjeidjX/mff4G1h0LNdPULyyLXLMNyB09f8LTGYYtU60FllJLky+93dN9T6suU41sS4fFAoUVq1yKYP0PIeK775FconEce+fghFysN/v+kQzWp034SAZdgEnAm6au1u+iqLXjvtE1qPIdTyZaKcfZMqcn+dwJfVcOPJcWBBgt/siqHfO+Nuq66CYhhwK9kxr74MjmnGBSLdR27T1GLu//dAyOuS9CndtTSLyjBPIMi6nOZoAeKB5Z0/9jMglAtbDWoY++a24Ag4yqBnjwK7KJyEc= 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 Reviewed-by: Hannes Reinecke Acked-by: Darrick J. Wong --- 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 31 07:20: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: 13261554 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 B896BC77B7C for ; Wed, 31 May 2023 07:20:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C5A1280004; Wed, 31 May 2023 03:20:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 57367280003; Wed, 31 May 2023 03:20:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3772F280004; Wed, 31 May 2023 03:20:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 27C2B280003 for ; Wed, 31 May 2023 03:20:40 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id ED93A12022F for ; Wed, 31 May 2023 07:20:39 +0000 (UTC) X-FDA: 80849702598.26.FC0B6B0 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id 22C85C0004 for ; Wed, 31 May 2023 07:20:37 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=J1M7xmS2; dmarc=none; spf=none (imf28.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+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=1685517638; 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=nJKP2lo8qunKNZgc/SdmDxY20EOraczIBDBFCWeBRL0=; b=JHyotPJLUVxL+dA041++97mXWjWSVKWHUEqhc6RwL0QWFO0JVP8CIuVQFgjiLUkX56trE8 UgotN47l8iQ19qHMrwe6187FHlfW3U/zTQw0lHBIo8vIE20Se9B5YFVzBUVPiY4XL++DB0 6tSTY4M2tNt1k17LJtjGExTvh5LPvXg= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=J1M7xmS2; dmarc=none; spf=none (imf28.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685517638; a=rsa-sha256; cv=none; b=MDU212HGSqbnIb099S/ndlh4Qy7hT8p7rTdfRzi+BunkXElpab7PPgFHqaxiqfv+czysWp QWYx+wuX4UB61oWbB8dSGe6VeAgGxiGr2rCRtt8Qix+x9o1rAbIZ5Ap3YHjUiDhed690s5 sEnRHINU2pL9+VMYfEYVCOhcYxf0RFI= 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=nJKP2lo8qunKNZgc/SdmDxY20EOraczIBDBFCWeBRL0=; b=J1M7xmS2smYT0WGZBNMeQ7h67W 05CC3gy3+uiDSRnwU9CvRdOwOXzI4hvby1CGkGqCB328TKi5Q03euobXsrGg8apFwmDbL5lAco0CQ 2zk8Lhn5l16g1f1ztPQGJF1t8Log1MveoJ4bxlU5qDwgCAZv98DsQJfceEvpKKKx59WH33C6Xhr+j jLFOFUvmiqSPPiqw9tAMb/ss52uKMM/5zEKK0XnS2i5LeK+kABfmmwS5v4UnVgIKhrvjMYcXhu9MA D/UTl71t6BFAkGEL9i8SWj1IzbYMcwqk/G9jaoCuVA0Q95Xq1tMEAHhbTU0cnj5wJo/sunF9oga36 5AZj3qDw==; Received: from [2001:4bb8:182:6d06:f5c3:53d7:b5aa:b6a7] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4G89-00GPjL-1N; Wed, 31 May 2023 07:20:25 +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, Hannes Reinecke Subject: [PATCH 6/8] filemap: add a kiocb_invalidate_post_direct_write helper Date: Wed, 31 May 2023 09:20:04 +0200 Message-Id: <20230531072006.476386-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531072006.476386-1-hch@lst.de> References: <20230531072006.476386-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: 22C85C0004 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: f3m9mujgjmd4396bqotu5u5r99mkpgyi X-HE-Tag: 1685517637-769305 X-HE-Meta: U2FsdGVkX18tWWPKdGYwwih/jUA1j7uiYLGnjGUrqQeF4W2I5B3lwS2GFCb2sGUJkaVdFegLGwS0ijtTyTrNRr1CqnKCTK++k2wkv3PLLPpHOu8JeD0jdaJnoTh19Q7ETQoUSjqJ/cmchnMoPAQ7NgfEkObg7Ws8vLXbZDM7MmYAtn8WZPg6bIDme5ihVgB1B/S4wOJtZerie36I85vc+cnbNddOb9mC7jIOqt0nDk4Pi5YcfvFE3nwffRN+5iHWSsu81TFFDpxc3C4uz6+4hErfaSDaY7ivaqZgnOBxz3465Qgc/T4x4rid97JTzk2lR5SayKsugWh/ln7PEytfrpFVqwiCXExM5E0UCCD0Jubd55SqeB9Exj0a3KiNLGL/POqVQadbhZ6GKJIfgu1mD8u0dXrn9vm0RfHNUqrUP4gBRCGKiaqdzl6a5qmrU3Lp6nEiv+dimWPcJhOT0mrQBc0Sa3r77O4Q4iuYvTupcAYa4Q/clBVMnF23M0yiCGnk4oKkJ4ItEYsjUSPXsMfGqDdExuDx1IYVqUAlvmHhyjtMGSUSKg3PuHPsyJL/CuB1QTBJVGWL6l9R6lqb37CX3m/9s3xMWECw5Ft8kJbpoVkU4ElPWR9b9u3Twggqz1drW7s5uIoR4BGZpdvkridJqwZeZ5x5F6P2oFNdepqhGu+7QqVhpmkQp1fFiG/QTDIsEDGYQ1dEjx0z3atW3JgHyo3T7/HUBW5BIhmfFlCSQhbngzi32+74srHLIR2lc2xlbO4V3xIijqXUMpFsdQu7RuKI+pim8qhHlXCEBzu56bSLuYwXBJ/8wRrRJIAyfZOfU3pxCIjwTXB+gtEybVpJGYdh7g1imAiivyckw6Ot72s55VtymplwlIFIa/OSOIwv1D4hO4cBZTqa4RPwQi54nY4tqNQRYsBUrouxcKM5HYqQWOFKUYxWsaXNJiUzIDbjdTiF1R3PgQCLN9XSnFw Gz1gBtFC rziRj8smdrWsTZc1Hq7NeEPvWULdusBF9atWnTyDR+AqI5dm6t5Wz7I2vG0JXJaFGTfzSwBzmvXVDtWVqwaJs6x5XijyzBPAReWxJJzYaRgxNqqByaanPtYsgqoI0FW+fg5i+kjNZXAqdlr97ZpKMl+D/pPZ+09TPX+QDxCJRq3viCVx2kxoC6rPvk4vml70XefsA+3Ts0TFdSUY49gBnWLuR0dUvnRRr3zu4n9ofE+MgxeL6dK2jzqv92prRyGksoHJP0HI3/swyO+BD/JIVyVYFzchvo3VfIX6r7iz+vDWOzgSVZo0SRol0obpGRXdtjgUvudxUvX/noGd2f4Rw0RJDRMU+FqqsW11bgwiqZnooCmHfeP7u4cMGwjx006BecWNK+x/awUpYax4GXl1s7iq/pb8rMS4P85i0z0iY5KPNJcnHKj8ygJEfjk9Ijt2Doo79uoBXJIFTF6EaYiqBpOeBgdk/t6XDKID7Gr4/EPbX2H9t9mKcd3lelsOywyXLMtzagT59KTglPcpzFqdtyGvTi2Wv9sPnrD438PBFzTXOc+Q= 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 Reviewed-by: Hannes Reinecke Acked-by: Darrick J. Wong --- 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 133f0640fb2411..91021b4e1f6f48 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 31 07:20: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: 13261555 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 68375C7EE43 for ; Wed, 31 May 2023 07:20:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E025C280005; Wed, 31 May 2023 03:20:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D89CF280003; Wed, 31 May 2023 03:20:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB55A280005; Wed, 31 May 2023 03:20:40 -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 A03F9280003 for ; Wed, 31 May 2023 03:20:40 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 62514120214 for ; Wed, 31 May 2023 07:20:40 +0000 (UTC) X-FDA: 80849702640.21.0C091BF Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf02.hostedemail.com (Postfix) with ESMTP id B1A0280012 for ; Wed, 31 May 2023 07:20:38 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=juedmjHF; dmarc=none; spf=none (imf02.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+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=1685517638; 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=a5Lvr5nZsxWnI6T+V3CK7XOpJ+ONTwidG7DsWkZk2X0=; b=QPotZX83+KGH5tmJqw2+GqSJeTIHeyDnKGkAPMFZfBMAfjcH69dg7UEEqT1q6LxADSrM8t yv0BMGrc8KJCPlxDtYATiRguyAuiSrxSx+2kcHTaI1hdQWjfD2ogXrB/f89Bi4Qup6vGsQ AQQge/gkuWSQM/7UdJaGDm49Xsc+M+I= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=juedmjHF; dmarc=none; spf=none (imf02.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685517638; a=rsa-sha256; cv=none; b=yZ422JyQ5rEDyuBqHlY5FOMKhGFjTRrPPb2/ktzcE8eftW47yQZnw3CevmEj7eHQU6SajF 7CX+KOLrg/V9ZQzF+WymDoqPQKcpzE6MWPz27Rplaw+f/btO2y/DYqDyOKSJueJ9N0Kkdi WC9qgqCucgAJUMOIUGPc8PytBio7wgU= 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=a5Lvr5nZsxWnI6T+V3CK7XOpJ+ONTwidG7DsWkZk2X0=; b=juedmjHFrERjVgI+I6F168RFU1 8pH8XOy3sucLV1v0mN1uWgXZCJ/dLQBD7d3VBl/n8a2N/x7DxsnF356O5Ue6J+a0dsBF+fjJTzd3l aOGNVfiVsTfKiUKyyIX4T1XXnubzaLIRwJv8n8CPQOCI+Vg53c09fBs8+EIxQr3RJ9F+A3wRPkVWA rtQiT8SCwODXG3Kl5EfHPmokqaMRG+7Ss0IgI2ZnYZV9neu8xowjG+6QkLMMCeSKyxsCLF/tXUCiR qmIjbcbIAfCWj0L6Pccxh5vJeTEW/6QWeuF8ClfTQzy8NiMHp1n9IFioL7Jm14IwGVM3KU2JFJ35V iDgZl8Hg==; Received: from [2001:4bb8:182:6d06:f5c3:53d7:b5aa:b6a7] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4G8C-00GPk2-0F; Wed, 31 May 2023 07:20: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, Hannes Reinecke Subject: [PATCH 7/8] iomap: update ki_pos in iomap_file_buffered_write Date: Wed, 31 May 2023 09:20:05 +0200 Message-Id: <20230531072006.476386-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531072006.476386-1-hch@lst.de> References: <20230531072006.476386-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: B1A0280012 X-Stat-Signature: 7wf4qird44p4a4rgcokpbcijg4kauihq X-HE-Tag: 1685517638-598657 X-HE-Meta: U2FsdGVkX1+xkrMmfqcJqqXJab9gATmbfDPINgEcLFd8Aip45EQAlRcwdP7ZIlcWUihlWcTEILcIIBg6JhsBnI8BdXi0L10EIxzsmdnAZJsFIoFiMez0oZ0N0ZuzrSkhV6CyRGVPWi+y+iJkBIWtU2orwBXNDbCF3KCKT1ONIOsyJoUB81xf5CmgNC4mTeKQbfAFSI56cet93Qv/Jn+dqfsYX52i5Zf6o+H3lggyF+f5eNwU1Se7rBh9X47UWCWHfvtd75VJw4HxaLJm4jMIU/byBAwbnzARBHbARUZCwxkpIEpIQYd36h8DsWJ+bFp3ymEijE0e6DNna9JRaw7Ccy2FhJRiCGUhchGKkZizZAzNzRnFj1YC0/usYmIyyEbPUVx1E12yszGamnehH7zpTt9U0K+UnhdjnRTAqs0aDnr0kj8sQK6rr/C+zAjRxlw4pjds7npvQpCyvRr4XjdLzBFR2KJ/2Czhvejqx7mELfXhFXaOm4uUWpqbRODHsIFS5h3h54tuinFrdCiPsy1ptqwfJ4Rfgd66S6tbFqAEcIxFmkYQXbgoQycfXbIrpZFvcD9yQX1XJDqnZWFlhjq2k1AGhJGvcpl/GDSv2sy487OQh8P8ansFTFsIUMUugf6rQTnjrZIqkMaO6lGaBZ+P91jwvXyWLkbnGo4enQh25Kj4nzKfX9rEweGHLEWF9npAjDHbt3NKaFaIV8f8+ietB9lCNeoJ+P8vZxl3AweaLyHFhuAZg9+QYyDh8SIUEBwCoHu7l2SZp/FwBeLFzNxXEixBzDI1A0EVDCXBW6a5xIyY1DCsegGuB2fxRr2zRzSC8vh6CVZIOwfgR7z0gjmFqDrAAC/5fGzrsL0rb65AAjy9W8tjfry9nQFLG2F4v0QLwmkH3s3PaakL79rYs0GcIatx37BU+Nd6vcniTaAAl58n6HFsu08Q677HRcsZTapYJYZ4bKrqH0hqKp0m67p 86/S1/wh zP+IukZgjvdJMrmwU6ovcHUdOTX3koZ+oSnUpmNRCJWnvTUOhmrq/I3M5qGihEOrnpFGQ0c902+nEDRd2GlVnosjwRu7WL27DsSVXT0c7l3SVffeUHw94Ja4dc6aMzLkErDuWcivrzbBAciM3yv859GjrhZytpROrUo2Ew1XmHsum/6Cb8ZUXeF3BfYvm/Ff0GSJr8sCD7xkjS792i38j4OD8ZEfpSzLXPbQ0OSZxMLooqOI1EII9v4gd5/hwODR0dkFwaYq9Q5L/V3sZvcUy4P5EFSR36Yf9IJgqTJSrtEeXl7HFSw1KLNMf2bRjW/RNlDOGl2jnDTwEVRqWq8ovAbnvhOz4CABqPHL0nyFtHB8+97vG7AyxpBGUg0mP+oitr7bsFUZ4yO82O1krYZI2KpwMeF4ZQWWHXPVS166Gz5z//bchVt2oHCuduEAmPGxpeKJsoq0Ql8EtTB37tstFp2A4tn3Q9TIUSNHTf8Mhtt4Z3rLVTtvnDBjsckg/blB2fQkv5aIVOHKdzXDZC6jzqCdfz620KeTWp8b+ 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 Reviewed-by: Andreas Gruenbacher Reviewed-by: Hannes Reinecke Reviewed-by: Darrick J. Wong Acked-by: Damien Le Moal --- fs/gfs2/file.c | 4 +--- fs/iomap/buffered-io.c | 9 ++++++--- fs/xfs/xfs_file.c | 2 -- fs/zonefs/file.c | 4 +--- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 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 31 07:20: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: 13261556 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 31A04C77B73 for ; Wed, 31 May 2023 07:20:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B8E98280006; Wed, 31 May 2023 03:20:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B4002280003; Wed, 31 May 2023 03:20:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B80B280006; Wed, 31 May 2023 03:20:45 -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 84D02280003 for ; Wed, 31 May 2023 03:20:45 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4F75EAE143 for ; Wed, 31 May 2023 07:20:45 +0000 (UTC) X-FDA: 80849702850.27.2C9F191 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id 98FF4C000A for ; Wed, 31 May 2023 07:20:43 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=GArYrnZp; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+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=1685517643; 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=+TlwHQVmCcfSC9sL9si103D1qv7dfudCnmtDuQc976U=; b=OYShH1Q13AbqhtxArgoMViNVgATc1xyEv4Au79Vfr/DNCIqrZDTWFFdEfTz56KvYjzWCGI kzMgAP/Ke3scE8TlKGF6/yGcF4YJ8AHh33egBaIfd7pwd8br1N6mnF0xFU020/W/Y5UL71 iALMvkpHT3wy+jXJ/xdx/blYUL9oF1c= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=GArYrnZp; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685517643; a=rsa-sha256; cv=none; b=69GpUkqdJtQ0f0b1tZO6R5bJNN9NFt59uwXvFXiS1OHmR6i81sDLde6zR0qWHuraojLWzE mvuqhYnZkTqQFfC2cRH95QlGABqSD5rl+JUoVE/mK+/VCN9l3y9/qdgZynZX78YwyuCfnP 8cG3hV8JTDDorq7KRacVb/V6nc6zl70= 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=+TlwHQVmCcfSC9sL9si103D1qv7dfudCnmtDuQc976U=; b=GArYrnZpd4OZAs3xbif7+d7vqx 1Epxi2mxm3ip8SMuY4TSJYoZrVYNpe2qUyfEyPBIbs7ZP+YugOxkFqIeToOTmGhfq0A6McJ6nGNIL ZvBgXgzRvw4K16aeaqXagkmXbjzhbc3gjcxGYVTl3zCXHVmLMCG4u3ssO6xd/AyVAAc/T/Px6RA5K v9jqxkE2QuGNdw9Xm14krIBUUx6tDjepzsbzBGhTd/VsKffWs+ifjGCyax3OvF+8V3llDWnx2+M/a 3NggQtSHRBgxloKcjNBUvLBOJTXPLVWsAHcgCcYkZTj75LY/GK1DdVBVnTid2lzQJrmUUzl215JmJ DBaU6RCg==; Received: from [2001:4bb8:182:6d06:f5c3:53d7:b5aa:b6a7] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4G8E-00GPmA-2F; Wed, 31 May 2023 07:20: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, Hannes Reinecke Subject: [PATCH 8/8] iomap: use kiocb_write_and_wait and kiocb_invalidate_pages Date: Wed, 31 May 2023 09:20:06 +0200 Message-Id: <20230531072006.476386-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531072006.476386-1-hch@lst.de> References: <20230531072006.476386-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: 98FF4C000A X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 6k19khox7iybgrrincpouotm8eey57im X-HE-Tag: 1685517643-164791 X-HE-Meta: U2FsdGVkX18F2hhoPdVqxgpZ5y3A25YEp/0MfCqZlomZl0OVl06tJ7ykewMCTaNTIXJWNBbA3319oF1f6W3OM2NOaytrWTtPSucusXg9Lk3a4r83/xfbK5Q+PVPyLwyWj7zqF1mTM8s3GF99Sxnas02WP9eJufNHY0S6iUz+yUMDF6QRmzOaWRAFupOwf4kmwaKsxKSWYWPdYp0t4nHEhSYNOUuCwmMy+N+IPD5/ScbZt4FJe7TwbPQaegZ6I6v+0+KogjiI38i5aPkEkSkT142Qfewim5+IxuaHSy14hlrmKVj8iqz4+dXHQlFB8sN8nyVB/Qha9Qz9JnoPoKXbGxF4UYwwCi61535cc0ZJ8rDe0jU0QaeLZqjjKP5EmRE89UhtvWeLclbXgL7D2QeTTwMNq/Qs57GKfAH8+aDbx+wBmtjqcYRskqMZuUHmZtDZyKwHWSqG/YvlnF+j3+PjdQ1wcsuxSjkdOQatbth86xdyIvn2NrndkgnISN0uDt0lWWxBzu1VvoOQEvvPBvntr7dwk700Wcwa7jqdzsby1XRU0z5rL/TJQk/rdUSuTzwOrhcbIVQEf4hDWxtznwpxE1+IYy/QPss740pwV8zIEkYzUDOsJfoUfYRIzpCPyX1naDP8y6B2AgfoFJNtpR9OGVu22e5Ga07WAkFhgUn9lz4sHMchZj8eOp6qez7Prf5nwSU0+5dg2Fp5KrAyeGLegLlOd4Xa/CNOWQqsW/3iu04ceVsAvHiKwLxYgwWEPJGO1IbYS9gcm0wzoTlmKCmeEuK5ab1UlpVzOlFMoirOXAMWbzmxhehek8tIXggU0F0ZkEw3jI2ySSH8ZL+7cL0lZh5XbYHXkofwL9AmVhO4CrBdgj09CIvD7/agFYAqywLOaFwSKV+OJ2dexl1dLG8SBrnsCeAGcFH2pzmgmhf9XulRAJ336POrdf+hjGB123+Unit7NyqklDgroL4hsrA SL+AwjpV NQqdt/W56VuGf3LrHNZ2zEf0RlnzsXwNo+Cw0AG4qpZ/99P4wECruzrPTKzdMacXgsVjpzgyGhUQDp5leVYLO9M6FvtpMed+hZLeDVCEYp/+X6wD0V6wkrOOJmwQJRmdQQbnIcc4feFXKpD7vcWk0MH6aPW1Z3cUIQURM+Mf2STYtPXpOt17HvG07g0GcXxyjfFLLGa77ZZ2ggpIVkD1XMyM2sEpv6ikib910Y2L2vWL32SmNKWi8YgSa+7fCS8LvetOSXaY4coF4fbmkVAiJdOCwDV6vdgmhhL/TkBvOAi7HEzczGcFMwafgkhHRAEo65QFnAnYX2pHLL/tULd2QlOCRSHxNChg4f/wgqRLrWISwHdq48rFJ/waiU2ZyUXJ0H4UksOr/497lc/y4iXCfj+UfAumdhNenDz073ydOfFbbbeFfgfvP9qiiMBjfz5oFxKMBorca53S3AaiUXTdR4eeaql4dMgyj63vXUPTZFC6HvCUcSzhYaNqlLpGEocG7CJWt1e/mi3R5GBc= 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: Hannes Reinecke Reviewed-by: Darrick J. Wong --- 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; }