From patchwork Wed May 31 07:20:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13261551 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6F82C83005 for ; Wed, 31 May 2023 07:20:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B41546B007B; Wed, 31 May 2023 03:20:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF36C6B007D; Wed, 31 May 2023 03:20:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96A5D6B007E; Wed, 31 May 2023 03:20:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 875376B007B for ; Wed, 31 May 2023 03:20:31 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 52F8EC021A for ; Wed, 31 May 2023 07:20:31 +0000 (UTC) X-FDA: 80849702262.19.5A1B556 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf30.hostedemail.com (Postfix) with ESMTP id 9DA288001E for ; Wed, 31 May 2023 07:20:29 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=WIvJCu2W; dmarc=none; spf=none (imf30.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685517629; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zBZfLo79n2onda8TMRoaSImQJ1x4yClUpeA3xrekMTk=; b=eqm6HOHvEgCqCIkOU3hDhkX+KRl4SagM9zPvJwOjd51HZV7AsNDRR5WLKGa9IDCMX4cCqI vbupAi9xoIYdMubD/gdEwvEmlT4C94VWYUOpFQFM88ULsVgJapRLKL5vC2gLN4ElD0lBRF IMelR7BHq9TheA+eBAHiUKLzVdY2KUs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=WIvJCu2W; dmarc=none; spf=none (imf30.hostedemail.com: domain of BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b81a8c9a6d22e8bb2302+7220+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685517629; a=rsa-sha256; cv=none; b=mLKrnxxJIrgqp2cTT3MRZKi7i6T9wP8XgV6oAdOLVm+5BPydgJ0wjRgph0yHkosLcpSNEZ sZfNxNDdVj+6nt69V55zp9u4uRQKH0RlZc+EA4VE+JFjkZFSof409/xGyr/+KNk+YWopQu szto1Nk8uae7adqlrreFyxp1IiTEdAI= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=zBZfLo79n2onda8TMRoaSImQJ1x4yClUpeA3xrekMTk=; b=WIvJCu2WcZCPxyyElumOzaF+3c /RvEl7Rd3lQdRO0Twp9TVret57OwjxhPz2wC4zzHR9NJ2222yBJnOaOpx+0Kw5lvEwSA8dKaL3vWX mI+t/R/Z5f8hm++0kU6KUHfULeRm8WoThwXgVOgmdYePJYzaXGiGOzdJaJBR5bsYUTmXW990744su +5OM2lso0jyefF2GTzsaJGS5INdouHWmZpaAEh6NceGkwXox+v1NXwvj8UpFQCWcZ4zvAS0tKBu3X pXSuBa7GfyBqpWj1/Wfh248oclvoi6NKSkGEzi4PjB4d0yeGNgQaw31c5eU17cE8JTvWdyvAbZWmW WoLOfN0A==; Received: from [2001:4bb8:182:6d06:f5c3:53d7:b5aa:b6a7] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4G81-00GPiD-0U; Wed, 31 May 2023 07:20:17 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Hannes Reinecke Subject: [PATCH 3/8] filemap: update ki_pos in generic_perform_write Date: Wed, 31 May 2023 09:20:01 +0200 Message-Id: <20230531072006.476386-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230531072006.476386-1-hch@lst.de> References: <20230531072006.476386-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 9DA288001E X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: zbp3xth1sma83f7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82iNP+H6WfVWynFo5rmqJd8R60GPDzAnYuGyS60HA3CDsACwv7l8yS73d6eZVDr3vKp+bOkgVFzk0qF1kbEU17MjEHWb08oqOPyNP0zVvlP7729WgZRz13QeAiMWMWaLaC9NoTvrcE7iEomelYrBcy5/LKBSsYnv0G2EIg9H5OgBkd0V5oRLpeCuZTzgJ1zfU9E0rpwPyUEhuVgi8lzyZZ36aDEsLVhoZ4zbEyCnS/LG3VPK2ppt8cg9JQmbvTmlaN5wYZoljbyQ0oF390g4T0SefLVojdUsvikQpwA0KwicUOduoLrOEe+S303ZSUh5SsaOJ2uLiLicAYKbijeo4jwF8L46NNXLCrOHlslddLFuMwbL0fl05dHXqcGAew5YitztXjq5PvWa9notJaiR53dJF+MZfX4YnHJzUC9Uxg19fU6Qs2WoM0TpL+8LtNlsqHx0zBvYPPdsuHzSnJTsaUwpo/yIfk9DJfOD6STMpVR2g6aT6M6lRk2 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: All callers of generic_perform_write need to updated ki_pos, move it into common code. Signed-off-by: Christoph Hellwig Reviewed-by: Xiubo Li Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Acked-by: Darrick J. Wong --- fs/ceph/file.c | 2 -- fs/ext4/file.c | 9 +++------ fs/f2fs/file.c | 1 - fs/nfs/file.c | 1 - mm/filemap.c | 8 ++++---- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index c8ef72f723badd..767f4dfe7def64 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1891,8 +1891,6 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from) * can not run at the same time */ written = generic_perform_write(iocb, from); - if (likely(written >= 0)) - iocb->ki_pos = pos + written; ceph_end_io_write(inode); } diff --git a/fs/ext4/file.c b/fs/ext4/file.c index bc430270c23c19..ea0ada3985cba2 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -289,12 +289,9 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb, out: inode_unlock(inode); - if (likely(ret > 0)) { - iocb->ki_pos += ret; - ret = generic_write_sync(iocb, ret); - } - - return ret; + if (unlikely(ret <= 0)) + return ret; + return generic_write_sync(iocb, ret); } static ssize_t ext4_handle_inode_extension(struct inode *inode, loff_t offset, diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 4f423d367a44b9..7134fe8bd008cb 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4520,7 +4520,6 @@ static ssize_t f2fs_buffered_write_iter(struct kiocb *iocb, ret = generic_perform_write(iocb, from); if (ret > 0) { - iocb->ki_pos += ret; f2fs_update_iostat(F2FS_I_SB(inode), inode, APP_BUFFERED_IO, ret); } diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 665ce3fc62eaf4..e8bb4c48a3210a 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -655,7 +655,6 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) goto out; written = result; - iocb->ki_pos += written; nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written); if (mntflags & NFS_MOUNT_WRITE_EAGER) { diff --git a/mm/filemap.c b/mm/filemap.c index 33b54660ad2b39..15907af4a57ff5 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3957,7 +3957,10 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) balance_dirty_pages_ratelimited(mapping); } while (iov_iter_count(i)); - return written ? written : status; + if (!written) + return status; + iocb->ki_pos += written; + return written; } EXPORT_SYMBOL(generic_perform_write); @@ -4034,7 +4037,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) endbyte = pos + status - 1; err = filemap_write_and_wait_range(mapping, pos, endbyte); if (err == 0) { - iocb->ki_pos = endbyte + 1; written += status; invalidate_mapping_pages(mapping, pos >> PAGE_SHIFT, @@ -4047,8 +4049,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) } } else { written = generic_perform_write(iocb, from); - if (likely(written > 0)) - iocb->ki_pos += written; } out: return written ? written : err;