From patchwork Wed May 31 07:50:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261638 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 231E3C7EE43 for ; Wed, 31 May 2023 07:50:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EBDE6B0074; Wed, 31 May 2023 03:50:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89C5C6B0075; Wed, 31 May 2023 03:50:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73D5B900002; Wed, 31 May 2023 03:50:49 -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 593A46B0074 for ; Wed, 31 May 2023 03:50:49 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D4074A025D for ; Wed, 31 May 2023 07:50:48 +0000 (UTC) X-FDA: 80849778576.08.1796634 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf18.hostedemail.com (Postfix) with ESMTP id 106431C0013 for ; Wed, 31 May 2023 07:50:46 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=d6s3dTvX; dmarc=none; spf=none (imf18.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=1685519447; 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=Gb/32YToAmTzBasa+tomVYVBZeEz1hHVFybe5E93oTVi/D96xuwCeQXBJU4wK9zn24Aq7b z3JIp/DvxJHx7xZqVgHN7matYQAGSWN1eO+JbabtqO9q3TmbOy4T7hQ2riadtc9yNFX6ub O1P/f/9SM9tI/5FJMmOl4n+2wuVjdgw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=d6s3dTvX; dmarc=none; spf=none (imf18.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=1685519447; a=rsa-sha256; cv=none; b=bjRyBrBQwZsFtV6f0oh8oVcofyCKrjaYHnJsSvyGKRG9upfriobl2Tcb5zCFS9vVxmLiad 5IMmoeeoMbrGDHb5P2d2NZ3EpczqGW3A6Itg0sm6WXJQeaK8gnYqQVlIwISwk5I/RaO35I j8LsdxQE3DnRClseVcsSN8BHuy3tEbo= 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=d6s3dTvXVTM2e4BtO+Kt3za1v2 lm+WZ2EMJDEpFCJMVeDdn7/7iSfS/gDqydHCpwAlxW2I+LnIOr6qLV0OOF+LKBeaaec1LMlY5ngrw two9EzTnRAEgjhST0bZj4SsL3hZk4cWd3TlxmK9mL/DlRgrclnhadM4hdX1/jz8Oq/BhEKhpmRCJv WhXjUd9eEakyhTEOMLDwmVqqjZJqKnOx63kPNHc1JVPMjuO/02pJyhrlO85R567DR9SVEwJcVuHgW pdm9CTjQvFpL02rQSnPyF98Ow3ALjPB31hEiLAIN9TLFTX9NPf9kRzdlwCQuhe5HZTU1WRTXWcM4J H8mIs9mQ==; 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 1q4GbH-00GVn3-2h; Wed, 31 May 2023 07:50:32 +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 01/12] backing_dev: remove current->backing_dev_info Date: Wed, 31 May 2023 09:50:15 +0200 Message-Id: <20230531075026.480237-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531075026.480237-1-hch@lst.de> References: <20230531075026.480237-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-Server: rspam09 X-Rspamd-Queue-Id: 106431C0013 X-Stat-Signature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+t2fknwjZnnmRck8Frvdi6Vi7TE2KB8G8EyiXMgIs69YIFCrHm9nEgR45dpm7PPT+zNuobZqqt5Q9ZfCmCgXuFFJ+k0R63/BAhP8M7QllbRthd94oi/vxJgXtMEtHpdMfqatVFt1c8bhYwxJofdCl0TeRC+HqtQl262rZ2x/D+4iPO1BrESTkVu5QPap9vZ4Ogkp8w35SqoqOMKsBpxEWG60tJqE7mhPXZfFoLKkZJMtVSy4Nlygicn6ryw5hmG/X7oWHBkIm84UZxyYDSkA/7BcFGNZm+iNT7uQ08CirpDdT6IfsOzPh4RSs4jx4eyLutB267llgrLmCOBrtroC8fLpqYHQNODbpsAhVbqSFWugXxbRWPoeMl261JAhXOXfTgHLw/g++op2hZt+hHxuIb2Rxq8H2kV6SoefZoD4it46cdIib59p3X7jklrPd0m2EA3a5PitZCJBDetNXHn4cWCrHk+CNdbXFZFo0j6upQbNy6wp3bZufRYnWjkZTlmX0Y= 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 Reviewed-by: Damien Le Moal Reviewed-by: Johannes Thumshirn Reviewed-by: Christian Brauner --- 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:50:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261639 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 BAD40C83005 for ; Wed, 31 May 2023 07:50:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DB666B0075; Wed, 31 May 2023 03:50:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76358900002; Wed, 31 May 2023 03:50:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62AA16B007B; Wed, 31 May 2023 03:50:50 -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 4CECB6B0075 for ; Wed, 31 May 2023 03:50:50 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1017C80290 for ; Wed, 31 May 2023 07:50:50 +0000 (UTC) X-FDA: 80849778660.01.03F2686 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf19.hostedemail.com (Postfix) with ESMTP id EB3CE1A001F for ; Wed, 31 May 2023 07:50:47 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=uBZ06PKZ; spf=none (imf19.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=1685519448; 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=chpTIhAIF6N7Dr6b1nzszF+TXvxv6hW4PAIQbx8EQsaundTxl3aJgqiXGsOK4NTQ7J5p4b Axol5a20uJmDWtitQzgBS+Mjv2yNqBKsZZlEoRQiDRut3+BIhU+M23T+tL1nYyJj6UnzT3 C4RCebAPg5Tlc5D55QvDqMuV6tCa8IU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685519448; a=rsa-sha256; cv=none; b=pjsFgMS0RceOZBnKOabmPKbqjZRc7vcK9ejXh6svb6UB+j9ndLcNaYFB+SX18hZOf+8saa 8002erAMGadR88f6PFa+5zq0Qu7bv0HHxnCkPcCoh0jxhHGUQY8A204hG7XFtWddjq/Vhb WIc9YnEnWimS2yh+69aQQnm+ZWdV4YM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=uBZ06PKZ; spf=none (imf19.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=1AhsMC0b8Le+Qj8+/F9cJR6e5GLVWYekas+17NCVqqI=; b=uBZ06PKZz56TQZNDL5Rj3l6Ywk 8hDrBqiUGVvcnLZ96e4rBnJsLigvjBlDrb+OYi7cBk6/wm2sE/xqKs9swjM2jJO8KETrxs76khtQn d4fOq3XMAndT05YkXMtMyms1Rsmq2g6bjt9chnJpDEJD189AC84uz33pb6ILpz/E0Uu5VJpMDXTn8 011Ez/C8z4tcneQxI80elWP3wXIRS7ELykiDvQUu4E0BsYMRyDtEDdmmAoHwPe65nRDwYtKcQRJ5P /46jPJjoSfx7uXd345WSwgi6WauS6l+vXHFNg0/2Uh4xvlWFw/Q0ltbf1G6Q7gUX0QwJ4yFOYjWg8 hmquvfyA==; 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 1q4GbK-00GVnQ-2g; Wed, 31 May 2023 07:50:35 +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 02/12] iomap: update ki_pos a little later in iomap_dio_complete Date: Wed, 31 May 2023 09:50:16 +0200 Message-Id: <20230531075026.480237-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531075026.480237-1-hch@lst.de> References: <20230531075026.480237-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: EB3CE1A001F X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: zawdi3g1g9cg99xetsd8fb6hmkqznkcq X-HE-Tag: 1685519447-336138 X-HE-Meta: U2FsdGVkX1/Ni3PjOvGT1Ojg9f83hBW5ZViLe2xRXU+XrL0AcGV3lv+If9VkbQTyUEBZjHpAWILmSTe10R6Vc2GUMHrphCwj2JMApxOXN0ftEogJG3tNjBSEtLCLF74+A9fLxlLDGF21caDQdJpm/IfwR0g0sINnlCuilJ2aLNI1gOolzzErDj+f8BVJUitcQgE/8PRuIH9xtKnMkHv/M6rBtcoKamuozP8qxLQn/jDk6r/f/o8Y0V/OymMb8G9vkdfEhFYOidscx9eY4SY2uP7+QtJM693Sw/e5SiH0NKkt/ok8VH3nrtRg/e2CAuDocB2CBaKt1JeTdh20TGTUCEgu4oinHbyS/HXLaeJcjdIUnWKyphQc2HNR8068h8eq+07E96rnFzBNx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kRfOFCjSlNsKtSz6lyb5LKdXjOykCu5NrNQaGIZ1osZ4OfwQEyBDf8EWvc4WtEnHo0pedF37z6sAA0c4ReHo7AjU+rawoboa8rxBW7a4JHKMcwehH20LkwfhILswKxFRtpsRCb 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:50:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261641 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 343A0C7EE32 for ; Wed, 31 May 2023 07:50:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D5746B0078; Wed, 31 May 2023 03:50:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 086DE6B007B; Wed, 31 May 2023 03:50:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF37E6B007D; Wed, 31 May 2023 03:50:51 -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 CC08F6B0078 for ; Wed, 31 May 2023 03:50:51 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9F90F4027C for ; Wed, 31 May 2023 07:50:51 +0000 (UTC) X-FDA: 80849778702.20.9CC1F01 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf01.hostedemail.com (Postfix) with ESMTP id E1E1A40018 for ; Wed, 31 May 2023 07:50:49 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=rp8mwzag; dmarc=none; spf=none (imf01.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=1685519449; 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=EgmrdCBK6pB9bPiajYFkmOVCamW8V+u/H1/m4ApLqyyDInx1mpCCGgGKYRdSH0sgedvEDj xMQL/RjwScQQUVGq9LDObJ7c49FYju+3TqflPaTA83kibFRlokDtgvrGAbZOGhPW9tr3Z0 xgu0KvFcQGQ7p2F3baV9y5KD8dpTxso= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=rp8mwzag; dmarc=none; spf=none (imf01.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=1685519449; a=rsa-sha256; cv=none; b=TjxsxnIw6up08Dr9x/ZZM/5XIJUc4IWKkpxa85RO6DYV3feHLdFddJchBtm2Pg/W5C7AwE Qk196BzVXVllholtRzu8WuCukwKwUr6CrME8Gmg4Z2/734CQre/Ihv4n8MBNJTL9GOEtuC NYVO5hSOXU0DWjXO/NSByY+B83Y9/5k= 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=rp8mwzagdteTZ0EXk9oVQdo1Qd tc5MZw6BKx0YGXCFQAmrduC/QSle4P0r46LzB8VqcNfa6VIs95D5MS/JwOJshsPGwbrKtTmvKuewN zvjk+SM00mwYSG7acM0n2iiX4E/D2ZFT/bMioR7WIoszzM9PJMnXK5H5hx2nqeiXPoFn8dJMv9Cg9 FpAH1BOcgSrYBAzQRKv5yjQdA+A+l0eFMLu2cO0WcozGKfjeszHvvqaI2/Omfv44j/S3xyvFjN3fs +W9WAdIpr3pT/xdVp7xohI2bPhFHcjVQn6z85d85ZvwqdNARep4OIN1/9fs0xf1FwfLnmpl30rSKV F4ujuWRA==; 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 1q4GbN-00GVny-1J; Wed, 31 May 2023 07:50:37 +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 03/12] filemap: update ki_pos in generic_perform_write Date: Wed, 31 May 2023 09:50:17 +0200 Message-Id: <20230531075026.480237-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531075026.480237-1-hch@lst.de> References: <20230531075026.480237-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: E1E1A40018 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 375tbjpx8mjwqbbipmy7iqtpspqksrtf X-HE-Tag: 1685519449-147894 X-HE-Meta: U2FsdGVkX1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kaUDt8Q04ywPqoUwq+LdeSdyKMktWLPrrpgwU5eeLE6VHSAuCZ4zJIg51C1YMIUzgt0/vBfnNCu9+kirn/8+sLN/vx36QRxkfLKPtYJ3Fl/yMuCaUYXpiwj607do1Nie1ubmSWrraw89WJQNVNGUZ0+Lbn58PFyiKM6vRlFtmTK67K8eiCXc6ajGd2uQp8u4xYohzhGhiM8DBKqC3eYyLFRpre9wOZoaCUP8gL7r9R3I4UaXna5c7DiQMT3+i6VSnP4QX3xb5nn5D0w2YhUFt27qGxQvNsxBGC8GK8+1jzWO34OwAaJMbW1hdcZIQ0JofCH43GWcUaqruS1oeX+Ru82E0FFvjhl19RTKcApT2Fpkp7LG95pgCT4wQslc24m175/2Gvtybrqm1POJb1xPSun8iSUz2Y/q0xgtDSTk8I5lB0P7cPvBtlX/rOCJy1W/EehpaP1Fd6jR7bOH870ME 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:50:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261640 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 8F7B8C87FE2 for ; Wed, 31 May 2023 07:50:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 011B46B007B; Wed, 31 May 2023 03:50:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F05C66B007D; Wed, 31 May 2023 03:50:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C44D86B007E; Wed, 31 May 2023 03:50:52 -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 B6AC26B007B for ; Wed, 31 May 2023 03:50:52 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8639580249 for ; Wed, 31 May 2023 07:50:52 +0000 (UTC) X-FDA: 80849778744.13.F6854A0 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id D3CE5C0011 for ; Wed, 31 May 2023 07:50:50 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=mX63p2gq; 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; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685519450; a=rsa-sha256; cv=none; b=RxjdwddaZ7/inawnZY8wCwKjg5/eWQR6HsXdj9cgsZHtddzFcPAsa+rQ6C3/XxUdHxN8kq cYRL1dKOj0WkFdhp/8aMDpq96tKgo/YKuyxicJgR33uFeBQVlos1ivxXCRzoN7ioQ+kTgi f8ND6JeBpceRVZyByP9yXzhPzIGms0Q= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=mX63p2gq; 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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685519450; 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=dJ4WobheDnn2z9HKC6Bjs5uvTFB03Q0lzIDzakdZpl2jHIsEF2tru+0UKFnID01G3sK0fC IuPw9i14BoovCuT0hupjA3jzzhB8vb4iIOzygruKfWr6ZZlrglZRFUgNrwOqKLGN13QUOZ lS0KDTigFZucPQIL7gq8HHaigH7K9AM= 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=mX63p2gq79YVonFeh66UH/Gf07 oDQXwuuVG/0zTbaChYcaSZnA6FeYN2+9PpMTDarXzQiay1+KiGGQH1JIFRsfB64CVQWWnTGpLxwVO VcpKJWbzddayA6uVwiaBzXTcqQxwjJk1jmmNn1tjvtVvwMsaEd4AEVEQhGQXPPFQ1E/Kq493soZrW 9Z2XZuavCo3rcl9FCHi+6jxhHCR6klyJnP2Kasjtdf8Fe8M/81uTlaDUsNSJfVZXOwAhdv3404pY6 rQfVgPAz0cL/WvQa9HtgtvqrCTXdWaIaGGb7pgiRTbLTatjklSX4muexsK6BIbV6QgrMZDrXKNRk6 VVYhOjBw==; 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 1q4GbQ-00GVp2-07; Wed, 31 May 2023 07:50:40 +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 04/12] filemap: add a kiocb_write_and_wait helper Date: Wed, 31 May 2023 09:50:18 +0200 Message-Id: <20230531075026.480237-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531075026.480237-1-hch@lst.de> References: <20230531075026.480237-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-Server: rspam08 X-Rspamd-Queue-Id: D3CE5C0011 X-Stat-Signature: njd94na6c3jccod3zzx3u4njpy79u6en X-Rspam-User: X-HE-Tag: 1685519450-746564 X-HE-Meta: U2FsdGVkX1/EsQr+M0jb8jCZrvOT7UGvy0b0h/zrojQFj9aDGAqqURCoK0x20p8TVsXHWMikMjoO8WLVPdw+rlaeso35F2oafkxQ2ZhFFL8RZjAU+pjI3oCKfHAn89KlCEALGZeaJhoqeof5DFsf95gxhznDW8XyV8HIND3DogAPeVrAqmNsMdHHUoCdGEbUUWXFpRrFpIJoSJt/LUO0+YOP4IHwDLgiUfVrGPpcS1kNyfo0TSXQ14A3/jNjYmJST/DCH+/3NkVNnxm5uQ/1+ATTkKL38adOm07IK4bEIe6F5CzRtJUAhXZPBWztnHU6rKGZeWDJtumpbmlH7v3ZpnGU83cgVPCdWlZA/HNkdo+kgK5610CNh9+Nk4RGMGNcrdAF54wTGdnYYrrdvyc53unsk9qP0MrIRnFkMieeW/9x2WR3JYDXktvlYFRw4YzINy0lpdm5+uwuAvvMCG8GxYIjESTOrwZfrLYUAgDCulmvslSTVj8sL//LqiGGwpCJIDIbdFIE4wogjXqShfQuSbwdMFgvIVpYPQW5IXaLYwJEPADnJCvoygCa/6xEt0DCajKviNmH4F6QryczQFH6/18O3Iq3XxXIlMEMm+EKau4hWU5Nb2HySomgqQSsDpSZnupodd5RQfl0CjRZKX9d/zsznd2OgcgMLjnYjjbpJWHOCXQs6jTAYXSe8/ww9knLV8S0s5DZU1IBFU1iwlfKUs+GV1rp6NEELTPNTZhDqEIVVj2f/WynlwfzbKnLMrw/lAfULtlwAdOGeWTrR5rQpnK/mCCRJjmo6wOyD5Ui14Mz3snPDEsLQIcoNQOIaBctIyVtqH6c8dy37bw9mAYsaVvB3Gkm6sk4licpzitMGMSlHV2evtwb+wIz71zSh22caXjW8OZWtHs90kIvTNF0Bdi42UApbLS95TkPv1FRyEA7PUGhISfdkVuQ4u0/gQx1f8zd2zfUCTesFrVzyyv wXiC+f2q KX75tNqLIXnwOu0j+BhmYuIVSAMVyZl2Pa4vVEVmsWUGIgc5Ro1LaToQw1BofnGtF1AghbXshFAy/I09RcsavrPzIAIpV6FqyRxiYyto50IAmzrJPrzaOG0SLhunn6ebF9/cCQB1zZzqppP0c8V3OpZuQQr+g+yhrxHzBmE9m/j5kKpxBsQhAQl5GgP4Zqob+1RXe7GEpu8uZnD7n+aON7yqc0ZM9DQqcWu9y/FFrVrQMDK4mrv7PkjwEWY3mjUVVkCb7fBIcHc50PCz7CYMucS8m8Ev22txFUYAmxJ7dPTBygG72dRaffiN16+ZyJjwqjE1KScEGmtKPGRjpeRFLl1nvEvRExS6g77HmSQgdpi2T8aeZdXFJXipfxuKNa9KI2qpH5Kte5z9kuCvs4dHlafiRZzW9bS3pykPm8Y+MqDXcJb3NplhFtJX5IDpXp4LGQLqQSQ7wgdo+7LbCM9wbte1csmN+GIX8IBNmfe8LzRhrZ1zq3mvvGX4ozTlub5nYf93P6wL3uaprrNTdW+2SDWgyqeI/hbHhZ2lTp4BtrQKBRCK7fsawgMD20Wx+sJakIxp7ivJ+ftlBjmpDZlnidEWRLUtatsJex18YawLUF1uROz2sgpTZCBqaoQ== 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:50:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261642 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 DFEB7C88C83 for ; Wed, 31 May 2023 07:50:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCD4C6B007D; Wed, 31 May 2023 03:50:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D800A6B007E; Wed, 31 May 2023 03:50:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA9B9900002; Wed, 31 May 2023 03:50:53 -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 A6CE66B007D for ; Wed, 31 May 2023 03:50:53 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 80CE7160236 for ; Wed, 31 May 2023 07:50:53 +0000 (UTC) X-FDA: 80849778786.05.5FF00E8 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id B3CBD4001A for ; Wed, 31 May 2023 07:50:51 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UwK1FHTH; spf=none (imf17.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=1685519451; 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=KPir+te76Ty253BzOTE2TD9ZZnI+r4n7mOuFhqbHRs7nqjN6+zMoj4tmQnUFKX59nW0gpO NAwlzYzPJIhvZYoNffSDBxYPEEKwDe8vjY3GO+T3smwndcO8KgQZd0YQJAe79qe/XFk2vA m2Qp0B7BhapA5hyJP3JMWN8yWOtHcNk= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UwK1FHTH; spf=none (imf17.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685519451; a=rsa-sha256; cv=none; b=Inj9c/vycmRwJOzUgzwtJey7MUPiX3ZtHWUYpSedhanLzA27aThOkGA2oggvdVAGYd2fT7 QyAi7uQyvRDJM4+5Er89zIfZb29OZiJaGw0RJw/rqhyLNAeHJD68b7manKxzhavTmiMvfb xXfF8kNWww7dFadx+Cb8YXaVssPq2uw= 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=UwK1FHTHtOyBkGhF5SwrqCYJaI V5Un7eCVkDVa2V6bOZ5kcaWv3HZlwGRURrEg1/HxkiYB6u5glE/X4tofTPC+PKyi2g6J3lruXgfP3 UHhLKQUSgT8GtfPqc0agUDElsY8y9lGiTs5xfOfH746K52QwP2aT6XR7+J+Qy5DxdIoQ0710G/Cm+ xsB/kIaUPj2s++pH24XeVlWjAza25Q0tRJOfURvfha9P6ipbqROKE1VC+9VUe9b5gp2jGi0+kt9r/ +G7NSTe6LjzFZbPWe2mPeEvoiWJYNa+d00SyQ9qv1QS47XF0PEnXMrGpmL4zg4e3WT1Ul4gE8Z8jH fBjN8G+w==; 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 1q4GbS-00GVpj-1y; Wed, 31 May 2023 07:50:43 +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 05/12] filemap: add a kiocb_invalidate_pages helper Date: Wed, 31 May 2023 09:50:19 +0200 Message-Id: <20230531075026.480237-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531075026.480237-1-hch@lst.de> References: <20230531075026.480237-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: B3CBD4001A X-Rspam-User: X-Stat-Signature: w974q8woptzoppuk5ggjg4odrdrdphyi X-Rspamd-Server: rspam01 X-HE-Tag: 1685519451-995918 X-HE-Meta: U2FsdGVkX1+/x4YMy0WrEA/GweCirloNCq8muO8i423mUqmm7S7Lk6WlxRSzajuhYZ6+SRWMRIg9tYH9pbyEkygSX/sQZCIrJB1DcrKgNl+C0+tZYWVuj5DrZuqQB+UEUWKTRiNJ5PqM3MsFndPjseuybfG2xKdq6PR8/iryGRqX1pU8o/IQP/2w6oOUO27ita3VKYeJ+vyySkD1kA5Tx26ZSis4//HLO7kt8NnNGt8C9Z9XyPcyBG8kwu3mGM56u9TN/TEc5dWD9hsjQHjSWt3yL5qhIHHUlOY1dA6BqomvBzaeQVOjLD1vTUZL3Epj1+GGGpx+RJpy1ZqDPZq/hUXHCBYmlhUMZ3ctGEzDApWBhnYqYd8omH2tppN1+B5dxRwAnk9lK+beNYfJPc2MtOuXUDYTVWwY6DXpWTKRDCBMCyBEOjYDC7UMRSMjTDwhXb6OL6oyNzlxu758k10GspvUv9IiXoMcEFYwDGw4xWiwqJPQjUn4QvphGkLQHwaXCsgU+Y6Ddv6P1vAh4ik96p4TXXzEb8LljMPxoqT2lt7ghZ9c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: 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:50:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261643 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 AF1E9C7EE3A for ; Wed, 31 May 2023 07:50:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CD9F6B007E; Wed, 31 May 2023 03:50:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47C546B0080; Wed, 31 May 2023 03:50:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 344C8900002; Wed, 31 May 2023 03:50:58 -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 26D516B007E for ; Wed, 31 May 2023 03:50:58 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F1EA640274 for ; Wed, 31 May 2023 07:50:57 +0000 (UTC) X-FDA: 80849778954.01.C158AD2 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf29.hostedemail.com (Postfix) with ESMTP id 4CC7112000E for ; Wed, 31 May 2023 07:50:56 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=VcmrNqxv; dmarc=none; spf=none (imf29.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=1685519456; 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=5TSOYWRDz2jC8XfYbFDYYy2tUqSzxOeb0P1XVM32wjB4dWtJWNT/kwW0ogHljlHnhpmBA1 j9kL/YBSPtbR0PmjY1CSxiP1IAff9Pzl1BFkUL/UjKw+0Qe4iVtlNi8krcAtya514Zt/wM I5YLnKsSv30YnUHqHwThP4/8DInz92o= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=VcmrNqxv; dmarc=none; spf=none (imf29.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=1685519456; a=rsa-sha256; cv=none; b=bzve0QSEFdKof8ZjoTjc8nKegT8aBtcrDFWuCkJoXu7QRd8bexbVU32KCnGjc4oIrTbFy8 feM5AZfNYPjQiyKEUq/4gZUANuO2XdqnOJcDM4AddFb5ZMyD9rQzLq3Icins+OW6NDy4Lt NI5GOd0NJNianiHrzShpbO0Q7BEtOIo= 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=VcmrNqxv6S1vmZIVE8SqEniQ4K Ht4eRjWh//ZZRedyE2Z6jK13px/jDCNCkcSP7a6uSXXa/UA8qcUY6tmc2HdJotSsc/YgRZZqPIAqy 1zZHXQunc/rbJwCSAN2NabXi0UCMx+vnSvyncvJR51m42KTjvtsrPadacaIND/KLcewXau9x3INds 6SG2baH6RhFWFFLB+EuHNHEqUCaFLhpF0L+GuFU5Fpyh4cWfa+zXkNkvDEV25oAFzTIydQGskBztG BLqbxh8Dndj/ZmVPDzAQUEokLF4cjS/5E+W8Pk/u8s9wXTwjrWBkSS8p6uMbCdhMqUKMNgnES7SrK RE6cKBbA==; 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 1q4GbV-00GVql-0P; Wed, 31 May 2023 07:50:45 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Hannes Reinecke Subject: [PATCH 06/12] filemap: add a kiocb_invalidate_post_direct_write helper Date: Wed, 31 May 2023 09:50:20 +0200 Message-Id: <20230531075026.480237-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531075026.480237-1-hch@lst.de> References: <20230531075026.480237-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: 4CC7112000E X-Stat-Signature: hwe5ogz9fz3oq6siqp91fa1igtmtss58 X-HE-Tag: 1685519456-157670 X-HE-Meta: U2FsdGVkX1/+X6WrCBSdusH/V136MgsmpJjjjmxGZTUQUhzE+wLg8P+1Od1wX5z14hikH3AjNANitOWFBE3OUlJ7zRydsAon5/RAi+NfaKo3XawO+CTltgdsedgLXD0Msm3/uiEiuyofq94OticFPQ68Bg0GybJr+T4Po4Y2m4c/qZ+PJl2cdNQoI/anYjWHu9fMu/LH582pVGGnraR9b0iNTXl26PcnHGnT/JBCu8UyAlhUKgY14/B6HxZmFFeHsJD1QSuWLLBJ3h9X9IR4VtViHZyXOdvOdehWPlYibxop+2dR+dGlv3YlMu9OmeKB/bLOemRyjtzPgSyUd12qEknv93kMErNaOBmkncHBaH+xATMIS6QSsSKayLfQTLCSyoRWUfeHBNV7+6NqhOR4mIXMsO8QPObCN8AWZ7OAh+kMj8e5zBncx+jr8C2aNnjgRj0AxRsAs5ta1iI4ooA9cefZoP7BAiSLKBYO2osct/S/Vi8xwZbEsww9ewH4rwAIUGcUitSPND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l4Z+qekWxKLbb4Bqnz5kA== 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:50:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261644 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 BEC00C77B7A for ; Wed, 31 May 2023 07:51:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B78E6B0080; Wed, 31 May 2023 03:51:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 58FF56B0081; Wed, 31 May 2023 03:51:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45577900002; Wed, 31 May 2023 03:51:01 -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 35AFD6B0080 for ; Wed, 31 May 2023 03:51:01 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 051F140263 for ; Wed, 31 May 2023 07:51:00 +0000 (UTC) X-FDA: 80849779122.11.0689742 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf06.hostedemail.com (Postfix) with ESMTP id 530C3180012 for ; Wed, 31 May 2023 07:50:59 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=dtzDh96n; dmarc=none; spf=none (imf06.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=1685519459; 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=cE2PB1QZ+5LdTtFt0I/IZjtSSVEKr4z4G5hbDK48SsXIC5BmfTPmPuXuA/zUX0Z1C1FKCb CK/w8nNqKnXsxJrcSz00+ohKh0y9TE7RM7s/6WMj1/bD5K4hglQrnzKKicJZ9d5HFHAwGc kTwU8O/Mrjcd28URH1Nt0LtEwzWVqE4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=dtzDh96n; dmarc=none; spf=none (imf06.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=1685519459; a=rsa-sha256; cv=none; b=BaurnE4/9HR0yTdduj6Gp1eWjnNp49o6NwzstuRX6fpLMVbwEAwIB2yjrmAotGzcey02DA 0XiZEUdtgwhy1XUGtTEqza7Ypco5cqezn8oWTZSeZnuv7VrAkx45biMNqznnPn3jkTGXMs Wt+P8MKBUwqklZ1S35d3xTi9G1TZzR8= 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=dtzDh96nnXtXyfwl4BSC7ayjQE qh58dEtcSivNAYmh7iKknqZcpZJBK3+VDCEhLSEqAyjvf5uEOpUBBDBNO1k8OfFRVDZwQUidhp5Fi htnHhQOD2HjbNoLI3Bwf0DFq9gfTLu5OqINK1Var/z/5Ne5P14U+UDPJMpXNS2G7Xy08+i9OJ0Nsr c3nqm3UjKGw0V4AJYwEPhJjo/dE+uP+Rpl8EhugrdpQqxLRO7hQYKYxH1h7dYoLBZIrjFB/MMKECA UuMW7v6bMKsd3oSI64dTyA3e0ZEMIV8p7moXb/sPDTbln+xmyY0r0ktJMrFiI1YrJCcCf2PQJDZkU Py5GgmrA==; 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 1q4GbX-00GVrP-2h; Wed, 31 May 2023 07:50:48 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Hannes Reinecke Subject: [PATCH 07/12] iomap: update ki_pos in iomap_file_buffered_write Date: Wed, 31 May 2023 09:50:21 +0200 Message-Id: <20230531075026.480237-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531075026.480237-1-hch@lst.de> References: <20230531075026.480237-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-Server: rspam09 X-Rspamd-Queue-Id: 530C3180012 X-Stat-Signature: x8cd7piybrc3nkn3u79ftqghtckzrxgp X-Rspam-User: X-HE-Tag: 1685519459-653403 X-HE-Meta: U2Fsd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YIAU6DJu/Qytfes1bKI5JEgMEsrneXS0AQVWrmea7K7cXanvDT0QZTviETZPpM5IfxViwznhYYF0hrYOw8vzJrteoeVBxUH0or+eKygVDb6C41aDm88B340fmVRMlDMYPLeJ/LBpJ7mVjK5Im/fpTgYsu0RKlwKB4G9Vh56Tt/3w4UV/mCsVVrTCIhCCYOK80W2gTAvGOf18vZMqNfhxtN/BjSHIGdEqXo2pNN5IhZTmdrq/XOpfTJWUZvha8mVWk0QqkFwcyzFAh08O03mWpsWimLyEB1xBA0aKzz3kfmNBWpcjhl9JxTM7FA1tZg/c+cNXOG4hh1tudhnMn7MUeidHjjlGBfh6lUSaTjUW0tEfAQ3CgJ0jaefGDuzcvm4QjklQzB7pqC3ukuQt7F9zgxlTDju/3u2iqy9YmHrhZ4x4AQCm/QeWPKc6b66+2Uf/TkNb4jJuXCCivmK 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:50:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261645 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 F2273C7EE24 for ; Wed, 31 May 2023 07:51:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EB476B0074; Wed, 31 May 2023 03:51:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89BBC6B0081; Wed, 31 May 2023 03:51:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EDE4900002; Wed, 31 May 2023 03:51:03 -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 60B3D6B0074 for ; Wed, 31 May 2023 03:51:03 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2FFFBC0273 for ; Wed, 31 May 2023 07:51:03 +0000 (UTC) X-FDA: 80849779206.29.D32FADF Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf04.hostedemail.com (Postfix) with ESMTP id 7ADF740012 for ; Wed, 31 May 2023 07:51:01 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=DjkGSNhf; dmarc=none; spf=none (imf04.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=1685519461; a=rsa-sha256; cv=none; b=QP/VkcuwDi2Khqzg79j5EpPYR9T0+NKbAeM4UBGuKZwRyTBcsT7ohOCwlun5wDf+tbwEcm 4do5nk1qKCfg95cPrkqtlIQyW6LgKEFY50S3a8DJ33H2fsyrhgpiYqhGinIHXnofznEBc5 BwDnVB3mHzm6l2CNXq4kpFN7LAyYuG0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=DjkGSNhf; dmarc=none; spf=none (imf04.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=1685519461; 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=IMlAWTlSsR9JSuXl16n/bX4DVX+YSmOzqfrf2H4oFbG0IX5sQPUFL6iQEPNt8aY7NldB2m Zs4lV/xkTgHRzGBVNgEzxx1PxUGD5pSC0/iuolSaXaN7U4QdJCzSy2vFoCGccMnxIdlxM5 qBxy4DXK5Py1sdVDdi62ur+PvbJk6TQ= 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=DjkGSNhfxlyHdHmZ+aBPLm0AmK 3nSTrCN5Pwh8HDmmbRXnhMRvz+JIT6h6F6yA35TYrD1FIj5qGsM8GHWl+ZAvE08Pvcxni0zcnTB7E 9jeKuRIiiVPJSBVoabk1ohE4Idh4SVB4aeVHVnQFVpZfMWvueT+wTI8vn65XazJ8ocFrbD5Hky125 TK6Bcl1zzEUcXiyd6sCm1IdkM43w3fN8zhNYZ117MvX5gdTQcqIBpA+WBivtnVlskMyMktya6Icr6 /4xWKrsWFA3/X27UuR2AvcifM2q4neWhR4fdC9tT555gl4NlHZ9UXxvTDSisBM+I0AyMC17ZdOsGI Cs7By28Q==; 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 1q4Gba-00GVsM-19; Wed, 31 May 2023 07:50:50 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Hannes Reinecke Subject: [PATCH 08/12] iomap: use kiocb_write_and_wait and kiocb_invalidate_pages Date: Wed, 31 May 2023 09:50:22 +0200 Message-Id: <20230531075026.480237-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531075026.480237-1-hch@lst.de> References: <20230531075026.480237-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: 7ADF740012 X-Stat-Signature: 3bkij6pna7pqu81w43kyzgtoqcq5679w X-HE-Tag: 1685519461-94308 X-HE-Meta: U2FsdGVkX1+COPpj/Mt8ajJ+B1FRW0ZC88I8NlaETN8yok6wSgN+kP5Zji/B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qwTia4XqQZeKCaKOxrSp/4O+c6PL9jgTEl9fCjRppBF21AlCy8t9A3SAPD31rV9nbiEd2UTQHcSpcN1CLpNnRPqWdPFzylghZ/awWYJnLY4IjQxhT2VMtIHc/AJND+dGT/MLkmq+Nh9OuLmrdABpBqjVavzGLwHYB8wrfO6vjT8VeSSZVMrJeVjgTDc/hSR61b0Xm7Q01NQ5ZvAOOYEk255gpdk2GmcV6hMkFGRZjwzTJcA/1LqkFuEvee/DyDZNKrW/EJVKi0In6cjAatDcupAtbXP0FTujJzzqQmpUiwCZstGPLoh3nlUISCfytqz74XK8lau+QCNUsg7VeQHd7L4zP+ltSAiTUhcqVoXy5eq4RpH4XK34+103dKfa2xPneV4e2Oa1w9CWv+/ZxDr10xjBpeWbXm8Qxa+Rf6c/GcSH2a20TvwNXoVYPkLbAy99DSlwsdug 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; } From patchwork Wed May 31 07:50:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261646 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 50545C7EE24 for ; Wed, 31 May 2023 07:51:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1AEF6B0075; Wed, 31 May 2023 03:51:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DCB1C900002; Wed, 31 May 2023 03:51:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6C6F6B0081; Wed, 31 May 2023 03:51:08 -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 B66306B0075 for ; Wed, 31 May 2023 03:51:08 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 88E3BA025D for ; Wed, 31 May 2023 07:51:08 +0000 (UTC) X-FDA: 80849779416.20.B99C029 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf06.hostedemail.com (Postfix) with ESMTP id F1831180012 for ; Wed, 31 May 2023 07:51:06 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="N1IkSc/F"; spf=none (imf06.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=1685519467; 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=11fdSgTG4jIa+lyPH9HFZjOssjJQOFkzGuhPffE88Ak=; b=tzboRNDWBg1wWzBVmErCHlt8UMGxN54jEuJH4/NFWMLTh8ULT8NumyR9/fzRoLtjGY020b IH2J7ghIwx0vqh1nhekgMWGagpJXALijRaB6RxOV6bc9Fdf6I/l0HXxhbYOdRb0sK/T8NP aNLvPyL0y8xxHrUTrmSipbzBvwPycKY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685519467; a=rsa-sha256; cv=none; b=2Nx/8ef+wSg3mn2PPUvFQhrjosqz7r1pkPaLmX1t1nyH2Vc61UtHXyVvfITMdc0QWsELy0 PbFwjv9xa0mNAacFGYAHqgSSXr8OUWBB5KIdchGbR9XXas0I1PEUEllyAqociQGYwJTS69 4YSOvrF1MerYBNYXZx5GrgMHrDEntWs= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="N1IkSc/F"; spf=none (imf06.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=11fdSgTG4jIa+lyPH9HFZjOssjJQOFkzGuhPffE88Ak=; b=N1IkSc/F+8A4KQZ69jwKm+YdVJ ttzm96cZrwRIglbmBQ7IM5r/NkpF04kG82W7HAoa2XeT3JqbLH9NHTWBanjy9ttbehUxPmZv1ziAa ZPjwzx263cmBsH2k08HRlZqhWrrJEQTRDLSj81pBtTdaeRZiQwJuIF1V7Pjb70zz1bLEwjIef8fS0 ejj0atwMoeXbA3dxf6snc8QgefUF7DakmT61oqvfsJn+DYJ3h5KFnE4H7KYgfmLDNYjp6DkzRQY0J 4VgxKppjSfcbo3TDcefjJe52TouvoD56hyuShTmjKbP30TJToxprGqjLVwDlsUJmVLEsYAiJvNStV 1fwL7WUA==; 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 1q4Gbc-00GVv5-2z; Wed, 31 May 2023 07:50:53 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 09/12] fs: factor out a direct_write_fallback helper Date: Wed, 31 May 2023 09:50:23 +0200 Message-Id: <20230531075026.480237-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531075026.480237-1-hch@lst.de> References: <20230531075026.480237-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: co3zp1d64t8gwkipxu7fyz69hjjimexj X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: F1831180012 X-Rspam-User: X-HE-Tag: 1685519466-208519 X-HE-Meta: U2FsdGVkX1/Nrb1q4NDdQZAorIUMXMdAR8n9x0Gd9VLlmEylpfabSrjpYSPAlHhHD/orb4Tf9BOhk3EruSxrL7rcwHL0f1LedgRKB5j9U9Pdk34dnU2ignFhIDcXkKL4ECZZcSWKvDc/clM2ATfCP+dR7e7+7YnA2ssgW+vPjapNQlv8alclgAgKkK+Baus7nh7onJJVZiDYINcbBXljCDCEnWwpjKsMDZZ8atNeSabQR6/lLdjdgWGPm+aC+UwbdoUQdlBCFyfqY4wcxt/bRLwkWfMwa6jvy6uFZiPDNIIU8OggD3nMBil6c/6VugyHJJiBND/X5dHL4bzV/JcxZ5Nf+jT4H+i8eCZ+3+3y//dADdEpLQaoQsV15woclbUU0ru0uwgs7Ofoc2tekuT2QdLDhqjkKmFtu14OLoZfLx2+d7ybOVS2MYE9guiYHdpOdQrDIhVjwizJ9QopkvAfje6HE2tX/1Xx46hdz6kWgQIWM7Wm9ny+0iaFrizBPlr47bx0PslkEn+F/L0kI7f35cCuHrxH9aTnxsf7Oyscbq87mWOWWEJybeT8/KQa17Q7ZhBCNtK+Nt3xu8pwC16kWMXBmxGcOazhLGiNlbpRxLkqV8gKZGHhDKZzTjVOtfS7/eGkDhn4V6nD+Fhv2OLDQeeiAZYDnEOApVAU9vemytnLGoQMKRH+3ukLeh9MU+Q/qW0jMQLbIRuKMzSiGUuosxc6loevITZyfScm/Rc6fN2g6ui6M/nwYhBkP07ECOga6+tRZqgo79DfWfRk8ONYeV7eYvnlQwtw+ahtmcr9r0L612AU1wchaKqu+9CZAUYtDwkJrf/jmhdHgFKEuoptyRgxVLSOjbNWGbBxpgMtWAede2HzXu2UCfcUA0jlZFpC0/+MAyyXZBQ9UcOLIro8aQ71SlbaS40GC7sADZvGO7DZg50yxa3PUyG8BKu/fQsG5HJf2CTx0aGOsBYPSTL 9VFwI0vx QypBWSJciSZk8OtStJv82/Getwt4zSiZl6XMStPxwHv72UiuJPp190UoKKAOroppjwWE3JYTdBJ7e13k/DX/tSC7vUbBD5TGVLzff6SrpZWZ42fRJo9I93P+gOLeCgtKcE04RXvFzChJ3v+9ecjn6jDmRdqNkDepMgbZQdPV3Z7kAt2f5pLI+4isQoKPs86WI3rSOLJ9Hx/eg18Khsz7ivq1AFTCKq/tUm7mI2+i8w5Dk92/rlIN+vuB1JOSnr5x1jO+1u2H5Tnedn/ZPrk66BHmd3PgRs6yAsIDgKsueVz4zCVKBrr46dqRFk7DOg5Hb+dLX2Apxb2VdKHqs0SfURWKVz7iT+CUWuDvSxNwATvfK9UyelFfTLUoU1n4TUY69oVyWHgg4/cm2E5m3yuP4ZtIuUYsMw5XIG7Cb7e0x7Ve3V9s6gSc29wMJUiR5E24ooyMJuZyWkVKWzDQq/NC0vEC2aw== 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: Damien Le Moal Reviewed-by: Miklos Szeredi --- fs/libfs.c | 41 ++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ mm/filemap.c | 66 +++++++++++----------------------------------- 3 files changed, 58 insertions(+), 51 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 89cf614a327158..5b851315eeed03 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1613,3 +1613,44 @@ 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)) { + if (direct_written) + return direct_written; + 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 + */ + if (direct_written) + return 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 91021b4e1f6f48..6af25137543824 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 31 07:50:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261647 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 1EBFCC77B7A for ; Wed, 31 May 2023 07:51:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B82D96B007B; Wed, 31 May 2023 03:51:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B33006B0081; Wed, 31 May 2023 03:51:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FB4D6B0082; Wed, 31 May 2023 03:51:12 -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 91C106B007B for ; Wed, 31 May 2023 03:51:12 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6947B120258 for ; Wed, 31 May 2023 07:51:12 +0000 (UTC) X-FDA: 80849779584.29.C825109 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf01.hostedemail.com (Postfix) with ESMTP id B917840014 for ; Wed, 31 May 2023 07:51:10 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=lXdWtXE9; dmarc=none; spf=none (imf01.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=1685519470; 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=2D8XoARsLusIaNOTQgxJjzpyZIj7rnVFP+jfuTSd/MY=; b=zbaYjjR1lCqvsZmxCvaNlon8rn/dSVVj+obuAapnjhqO+aLhTD3zUW1HkNgIONLjQNaoZV Z0AHTJicUlZwoEcRLqjT08fws7WwaAzc1aYbaAr1VHAPXw/O/iDFChsPoKe4zxD99XdW3B nI0cJVd/DQ0x2iOw3jyT7ihdNvpdaeQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=lXdWtXE9; dmarc=none; spf=none (imf01.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=1685519470; a=rsa-sha256; cv=none; b=dZ69+MP2yxEIljK5WbwekANctmBRhl89HQnUb0LGsAzQsvYvOlZtn3rvDGuOiJuGW6P7Gp 6TbY80mV6WrZ2hdyAbuZ9DEypoOSY654NKAenErtMov/HqDCMZN77v4ckNV9bbEt1FOFRG il+LpGpaJ/P3pXDBD+KdxZG6ILd/hxY= 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=2D8XoARsLusIaNOTQgxJjzpyZIj7rnVFP+jfuTSd/MY=; b=lXdWtXE9H+JciBmtuVsLbtCKPT GX5uIP0+yZkYtTfcDXxQOuFNApqhc8M9a/zDOXzkMRYwgr7TzOkpfLGgPe06Jxxcgo77pUOh6aL/V cWdk3/2TwD9HylHUqpmuONFzpVY5cXRQ56KFBc6U5yo91xVSGeiPuYQclHPRi06FBVrLcF1/VREE1 EEHcUGOTEFBntJf9n7KAFBDECmypX7Jo8o0eYSy00fkUm999rHZKipMlAd/fVmEto4kUOgxK097xh PN+BNthoICWgs8N/EnwICdmd1e51zusTZ/kvayY6r1y7C0Mo62C1gt4VCrQhJMWoYVJfZgfWJiumA Wr6wcc2w==; 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 1q4Gbf-00GVxd-1r; Wed, 31 May 2023 07:50:55 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 10/12] fuse: update ki_pos in fuse_perform_write Date: Wed, 31 May 2023 09:50:24 +0200 Message-Id: <20230531075026.480237-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531075026.480237-1-hch@lst.de> References: <20230531075026.480237-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: rztpxfusbpukn1mi5153ma7n5cxdexju X-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pArIou4CYhV5pDg1ZDY02RPmW5gtWw1l9krj7tn1c/Jv6egBgc5B1xWEz32kHl07xWe+VwIIuZ2SiWNx8iz3jsMq2VEb4biXx7bKkat2jBn2wWp2c2Okq27VNiumdeFf6j4hkVd0sATuIX/WMS1Sl5XobZex3wxHaKWXW9LsI15U+ruUpS+IVVXvR/uMrOSZuRcle5/eOOBs8XQY5ZSznzV7C/A+FrWxhE+1ltGL02m814yuXVkyn9kTcNPgoJfSmwe41CdDfQbWUqXptUmhYQP0/Im5/dhdq9nPMqMIxDaFC/+UzuZhKdevROX63GCL5nPuTYuQRDz1IftxwHW3H1n/6GbVEe794SUmz0Lgn9qIQvr6+ipBIouhiRsg215r3LtTfZEe5rNUKiXHdfCaXP2NSZeuYfgef+B5IZS5J+Yv9tkk6aS6uJ8G6GWh9QbFpIOIpCco3dqgP7JiqQ2lj7NXcUg2kTRLDwliW0ijb1KuMvzoTBpyOqwHrANAPYg= 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 --- fs/fuse/file.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 97d435874b14aa..e60e48bf392d49 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) @@ -1341,7 +1344,6 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) struct inode *inode = mapping->host; ssize_t err; struct fuse_conn *fc = get_fuse_conn(inode); - loff_t endbyte = 0; if (fc->writeback_cache) { /* Update size (EOF optimization) and mode (SUID clearing) */ @@ -1375,19 +1377,20 @@ 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; + loff_t pos, endbyte; + 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; + pos = iocb->ki_pos - written_buffered; + endbyte = iocb->ki_pos - 1; err = filemap_write_and_wait_range(file->f_mapping, pos, endbyte); @@ -1399,17 +1402,11 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) endbyte >> PAGE_SHIFT); written += written_buffered; - iocb->ki_pos = 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 31 07:50:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261648 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 BE9A8C7EE24 for ; Wed, 31 May 2023 07:51:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58F726B0078; Wed, 31 May 2023 03:51:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 53FB26B007E; Wed, 31 May 2023 03:51:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 407FE6B0081; Wed, 31 May 2023 03:51:17 -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 3265B6B0078 for ; Wed, 31 May 2023 03:51:17 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1480D1C6F61 for ; Wed, 31 May 2023 07:51:17 +0000 (UTC) X-FDA: 80849779794.25.9A6AE4B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP id 68FC1180007 for ; Wed, 31 May 2023 07:51:15 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=aD7gWyr8; dmarc=none; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685519475; 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=aL4JtBxyhKSUIoIs8zshulNYsaa+7wvzZcQ7A9usZGk=; b=mu6ZSdp+rATynO8gXyBkmQUdOGn+29auUZ5AX97k57UkoQoIZLUhptA2oGchtZe7jU842f NWZIAgMnfIiaai/3o46K0OU9jPjsgIpQl6GxX1H26T6lo812glU5RnfyrbhZD7OB/Iwdzd 01kzO9kUJb0COSnhiIlodvaaxAWu6+w= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=aD7gWyr8; dmarc=none; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685519475; a=rsa-sha256; cv=none; b=Dh1nFv7HjMgbqOabvedOGVAHqWq1OFOaKtCen4FyjE0ctpagI3ebLkqMWqwfeCctupSPMq TZf0wwQ8zDUFYY5uErZzCXK13PClH1jKnZnD6lXmV7kBbRy5nAy0YBwUarlDDLyKOB85gv smCUfjvFD1M+3S/7EBn0v/SejMxAs/g= 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=aL4JtBxyhKSUIoIs8zshulNYsaa+7wvzZcQ7A9usZGk=; b=aD7gWyr8b1clmJUz0ng4wh8iN1 2pIdPjbYXIRRh1Kmmhvr9XUZfJmEzYUSG9MpfRaqOXtpIf81N0C4KW91kRTVNx/1xjofKh6ID5fEZ y0kgxzCPuOAOcRvxjkI+DhSzh8PYwGOXVEdzJScdskD02HMegMKHsJzKs791UpMHizTDm3fmN//tX 6rl5sT9sqqCp86Mfokmpj/WL2CP1OSYP66n1f8RX2gICxutiEFyhwPyN+TIwbF9/1JsQcegS+vv7u 4nIF9K3m4qzWLhU31xzEOyoJGgpwCjxO0CBkTrYH/d1JRTGC4jWZ7AwjftTuF3pr+nYL1/XFGg0kY tKlqRbMg==; 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 1q4Gbi-00GW03-0R; Wed, 31 May 2023 07:50:58 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Hannes Reinecke , Miklos Szeredi Subject: [PATCH 11/12] fuse: drop redundant arguments to fuse_perform_write Date: Wed, 31 May 2023 09:50:25 +0200 Message-Id: <20230531075026.480237-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531075026.480237-1-hch@lst.de> References: <20230531075026.480237-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: 68FC1180007 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: wb1wfh4oirzw9gouyar6oxg4sdbq1nnn X-HE-Tag: 1685519475-892764 X-HE-Meta: U2FsdGVkX1/mChL/ozOOQyVtiRUoLibAfuk1IHC7u618UgRVYdTf36Wgf7PFxFxS7woZaR6nrShJeKKdXQAuNBt4fhXbyKjOML3ohNDqkevNIHd4P7WX5wEL0rd3w37jz6Uk6YMuztpUfBiv0AyUluodS4wvW/RKFyKCjy0UiW8fxHhrLanHzT9bBTgyvJ37jFvnB1610XhkU+WDBw8pa7vY83oGqq+CkI+zJSr3zolYYKjhwQ4D0fHC3atr791ya1HcN/oLYRVwwmu2h2CxK3VkKcQMcnCWyA7uWOhanrRXf3APKJ5+xFYWLb3skgT+DLRjeJUkUwna/TRPkDxhxyCu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0H+kUjj1GieCseA4NDScu6Z2DXRYnTrajNzauIafa+HujRR6ZLiqP7iV/lsdGMXfRiON/5NE8EKwXMo9igJDJPdtVZP6MSSLB+QW/ 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 Reviewed-by: Hannes Reinecke Acked-by: Miklos Szeredi --- 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 e60e48bf392d49..025973ad813e05 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; @@ -1383,8 +1383,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; } else { - written = fuse_perform_write(iocb, mapping, from, iocb->ki_pos); + written = fuse_perform_write(iocb, from); } out: inode_unlock(inode); From patchwork Wed May 31 07:50:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261649 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 766BAC77B7A for ; Wed, 31 May 2023 07:51:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 197716B0074; Wed, 31 May 2023 03:51:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1489D6B007E; Wed, 31 May 2023 03:51:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 010526B0080; Wed, 31 May 2023 03:51:25 -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 E39EE6B0074 for ; Wed, 31 May 2023 03:51:25 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B6748A0276 for ; Wed, 31 May 2023 07:51:25 +0000 (UTC) X-FDA: 80849780130.23.6D53A78 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf18.hostedemail.com (Postfix) with ESMTP id 133581C0014 for ; Wed, 31 May 2023 07:51:23 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qCXO75gZ; dmarc=none; spf=none (imf18.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=1685519484; 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=zxv1M1WmrjWJV8hj/zJXb5/eLkyYVzKVbPyzJ0QvWkE=; b=ERq7HO0dIH6y2zSqO905hg5svApii5PTPwGuGwrVt2/xq8pfVXX0MUT2xZPke0378+R3iy JT3wmQoIuxrblJ2zv74wHfOgJLeEqpekHg9R70iZ86vFZema0maCMlmaK5U0HMoQWVwVmg W4HDO5EYWBiB6ZtShlnetyzb+Sk01zs= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qCXO75gZ; dmarc=none; spf=none (imf18.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=1685519484; a=rsa-sha256; cv=none; b=8U2mhKlNYroCaz5svp+Citxgr/+J5+puDTl2mYr1AYNELQEwO0aUBKSCo2I0/ubpHAvYjT NEurp/rfuF3LoDMLd2ZlLhYWW9cvj+lo7TTmFsl2u+Uyq7Sqyd+v0dQwRgB42S2tdeYKRB mz7hRFmNet/baK53qLsLEipTsfAJfVI= 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=zxv1M1WmrjWJV8hj/zJXb5/eLkyYVzKVbPyzJ0QvWkE=; b=qCXO75gZuJgbpccptPK2DLklM9 7+jixpNM42DMgAIn5IVH47ttmh1LXyMN3Nm3ju6h4FrJ1vmcb8QK8gnjPjADfnAxP9X0MFv/u+Ktk YTIMY24eQRcNpYuawN5uwkai/ooVN5y02Uo9VIZI++fjdqeeFflRYypDJV39i9odIMzqi/nrKdjxR RErlb3jA6ZKsJrPH1N5ozDdN11HA75vxETG5rz6+OLXCcOzkw8VRqrcK8i7uNfXcXFqeTqk58bqq1 x7k/8x4r+F1Vr57n2meaCv9eQYXHVbIpUB3M28qDtFw9afFmrlhPRHbg7pecLYydha8NRG5/4zPi2 e749VASQ==; 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 1q4Gbk-00GW1W-2H; Wed, 31 May 2023 07:51:01 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 12/12] fuse: use direct_write_fallback Date: Wed, 31 May 2023 09:50:26 +0200 Message-Id: <20230531075026.480237-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531075026.480237-1-hch@lst.de> References: <20230531075026.480237-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-Server: rspam09 X-Rspamd-Queue-Id: 133581C0014 X-Stat-Signature: szsi39uid719awpdci45nmc6sgquajry X-Rspam-User: X-HE-Tag: 1685519483-796389 X-HE-Meta: U2FsdGVkX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ETruOY6u9bzjiuOdu5FhlELB5fZCqzf0c0axJ5fiDU21crBlO5SDM1bSU/ChRj09EBD+UQJ610FdSU2IkXKmt+c4xRsx/3BW4D2MVHB9A5knP1QBMTgm+jA2alxOW5LTPYktjQOQMbUL634oVo7DQ7VD4/KYpJ0F/S9/jjWKyUYGBJyiUag8sZ9hFEiiNCe1LMzWoS2uy5KmirWh9HnoYNM39wlojcXqwb/PVN/VazZp1gQiQOQuWx5pY1g40K8K9Hw0ThOv5PrFLOuQ2aorVi66UUmf+3qOKQw0jTuEhnW1lTrOURRcB/Ci6TvEzImgnSiVWpjYVe7geeJ+fuKvTaxLV+5tiSiftpQTdwAq87OIwtt9Hh9YwhCo89IWxWZTe3YqT912xvM2NlqG7d+8U= 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 generic direct_write_fallback helper instead of duplicating the logic. Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal --- fs/fuse/file.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 025973ad813e05..7a72dc0a691201 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1340,7 +1340,6 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) struct file *file = iocb->ki_filp; struct address_space *mapping = file->f_mapping; ssize_t written = 0; - ssize_t written_buffered = 0; struct inode *inode = mapping->host; ssize_t err; struct fuse_conn *fc = get_fuse_conn(inode); @@ -1377,30 +1376,11 @@ 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, endbyte; - written = generic_file_direct_write(iocb, from); if (written < 0 || !iov_iter_count(from)) goto out; - - written_buffered = fuse_perform_write(iocb, from); - if (written_buffered < 0) { - err = written_buffered; - goto out; - } - pos = iocb->ki_pos - written_buffered; - endbyte = iocb->ki_pos - 1; - - err = filemap_write_and_wait_range(file->f_mapping, pos, - endbyte); - if (err) - goto out; - - invalidate_mapping_pages(file->f_mapping, - pos >> PAGE_SHIFT, - endbyte >> PAGE_SHIFT); - - written += written_buffered; + written = direct_write_fallback(iocb, from, written, + generic_perform_write(iocb, from)); } else { written = fuse_perform_write(iocb, from); }