From patchwork Wed May 24 06:38:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13253306 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DE9CC77B7C for ; Wed, 24 May 2023 06:38:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7777D280003; Wed, 24 May 2023 02:38:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 72AAD280001; Wed, 24 May 2023 02:38:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C8CC280003; Wed, 24 May 2023 02:38:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4D559280001 for ; Wed, 24 May 2023 02:38:39 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 22AC3140867 for ; Wed, 24 May 2023 06:38:39 +0000 (UTC) X-FDA: 80824195158.16.94299EC Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP id 655E940012 for ; Wed, 24 May 2023 06:38:37 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=U875Nf6B; spf=none (imf07.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684910317; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eC4fKlJuAZk6Bs9zfH3GxbdW7XFrPuxkzUVDWdmQe5g=; b=L4+04BabAa2Tw4EAxkAJNu34+soE6OY22LJmVbO1RvteyTUXYysrrkSwqAEREEAgOL1cJl 860tbw1PksuhJCQpZ28rB9c+t+aqSzisL/vj152prP21hnlG5EdcxTyoGhEHywZyGkpb36 GyaGjX8kt44MxLHU6WUtqob9fFn+Ql4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684910317; a=rsa-sha256; cv=none; b=OWhIiWXTk2nAKTHXdcrjHdbiTzD3WsXvARLqS8tRgfO74AysQlueskYqxkfc+hJYsdn3Kw rN2/IB4Rv+BOMTNfia8FvOi3406BoPCoSSQYBqRQEI2AqxJBVj6+dbqW1duEkxw7PJKpzx iCphrEgL5WQ/crF9EdEA+p9HzDV4pKM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=U875Nf6B; spf=none (imf07.hostedemail.com: domain of BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8349dc162fb675e8d54f+7213+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=eC4fKlJuAZk6Bs9zfH3GxbdW7XFrPuxkzUVDWdmQe5g=; b=U875Nf6B+VixmZn3RCK57UbTUU IFC0MeeaeIlbgfB/LVshuRLIofQrNBg07H6ArsN/S4kztKs2Gdx3sBck98mxzZ6RTXhCQBVXC7/u7 i9xBhUMRbD7a1jKdA/JPzbaHfjiavwo4CIWKOoe1Yj8Z05UGrZF2AThxvYxwSQAyFfc87tXPIZ4vh V39JXltuaCnrdgxByGkJWT2mJPgbOnQgbZY/NGQM3agFFFH5l75VSVn8S/KTo2KbrkM03l+cEvvBf e/uITYC+j0JHWGaMUQ5DoVgNuR0TXMLu4m5OFU/iCDA+DzlVkPoKbiFDcpNMAlA0wT7qfVqH4Z4nE WHCJyCJw==; Received: from [2001:4bb8:188:23b2:cbb8:fcea:a637:5089] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q1i8c-00CVf8-2h; Wed, 24 May 2023 06:38:23 +0000 From: Christoph Hellwig To: Matthew Wilcox Cc: Jens Axboe , Xiubo Li , Ilya Dryomov , Alexander Viro , Christian Brauner , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Miklos Szeredi , Andreas Gruenbacher , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , Damien Le Moal , Andrew Morton , linux-block@vger.kernel.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 03/11] filemap: update ki_pos in generic_perform_write Date: Wed, 24 May 2023 08:38:02 +0200 Message-Id: <20230524063810.1595778-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524063810.1595778-1-hch@lst.de> References: <20230524063810.1595778-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 655E940012 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ysg1xf4nh1rmp6gze7eifujb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3SLAGs2YTndQ845Q0hef9Llj4Fz/boTZz3ut5g5R+Cx7c8XX53hN65H0hfGUXS2ApNsNonl0zWw1Lg8gdJhORjt9ybqM1JD/pYim9M6ZTaxMfH+VpoH7tzHFWrmidDuV4ALaorUi+sv+SxP/F+lv3o/BuULWSXzujk/1GU1xcEUTckDuG6DCskw/aaPSE2K/6FKxPYytDiYTxoOqauW2sqApI08KbmOEDL2ZLI0qy69ihDunn8K4xh+DNJhybRyFEweDxOBbIpzzm4s/grWb09Xxj4qsZp658owmDRx9AYIPLzSdCwr4X4rOjhRc3Jrl/2nTcXBgJX1cHRtQeicV89dbPgzwo+f6JJkOEl3hbBbgbHLETxzajuqAZsvbCfS2B3qHIPv1epBFj+b/NOkW+ZQJQaBZMzr7LlFOrzeumuGj0LQldxZzQEn6fWAwvzi0URJ9ppYz8/pe0MZHNae+teBalu0MgHKGf X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: All callers of generic_perform_write need to updated ki_pos, move it into common code. Signed-off-by: Christoph Hellwig Reviewed-by: Xiubo Li Reviewed-by: Damien Le Moal Acked-by: Darrick J. Wong Reviewed-by: Hannes Reinecke --- fs/ceph/file.c | 2 -- fs/ext4/file.c | 9 +++------ fs/f2fs/file.c | 1 - fs/nfs/file.c | 1 - mm/filemap.c | 8 ++++---- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index c8ef72f723badd..767f4dfe7def64 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1891,8 +1891,6 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from) * can not run at the same time */ written = generic_perform_write(iocb, from); - if (likely(written >= 0)) - iocb->ki_pos = pos + written; ceph_end_io_write(inode); } diff --git a/fs/ext4/file.c b/fs/ext4/file.c index bc430270c23c19..ea0ada3985cba2 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -289,12 +289,9 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb, out: inode_unlock(inode); - if (likely(ret > 0)) { - iocb->ki_pos += ret; - ret = generic_write_sync(iocb, ret); - } - - return ret; + if (unlikely(ret <= 0)) + return ret; + return generic_write_sync(iocb, ret); } static ssize_t ext4_handle_inode_extension(struct inode *inode, loff_t offset, diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 4f423d367a44b9..7134fe8bd008cb 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4520,7 +4520,6 @@ static ssize_t f2fs_buffered_write_iter(struct kiocb *iocb, ret = generic_perform_write(iocb, from); if (ret > 0) { - iocb->ki_pos += ret; f2fs_update_iostat(F2FS_I_SB(inode), inode, APP_BUFFERED_IO, ret); } diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 665ce3fc62eaf4..e8bb4c48a3210a 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -655,7 +655,6 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) goto out; written = result; - iocb->ki_pos += written; nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written); if (mntflags & NFS_MOUNT_WRITE_EAGER) { diff --git a/mm/filemap.c b/mm/filemap.c index 33b54660ad2b39..15907af4a57ff5 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3957,7 +3957,10 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) balance_dirty_pages_ratelimited(mapping); } while (iov_iter_count(i)); - return written ? written : status; + if (!written) + return status; + iocb->ki_pos += written; + return written; } EXPORT_SYMBOL(generic_perform_write); @@ -4034,7 +4037,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) endbyte = pos + status - 1; err = filemap_write_and_wait_range(mapping, pos, endbyte); if (err == 0) { - iocb->ki_pos = endbyte + 1; written += status; invalidate_mapping_pages(mapping, pos >> PAGE_SHIFT, @@ -4047,8 +4049,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) } } else { written = generic_perform_write(iocb, from); - if (likely(written > 0)) - iocb->ki_pos += written; } out: return written ? written : err;