Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5154771rwr; Sun, 23 Apr 2023 22:51:03 -0700 (PDT) X-Google-Smtp-Source: AKy350bwwZlYY7ap9MQAT5nGE4GiBU9U1FGxSgHS7/KysUrmEKcMGsbnnPqrk0XcEX9NluPaCkUv X-Received: by 2002:a05:6a00:b51:b0:5a8:8535:18b with SMTP id p17-20020a056a000b5100b005a88535018bmr16728511pfo.11.1682315463042; Sun, 23 Apr 2023 22:51:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682315463; cv=none; d=google.com; s=arc-20160816; b=k3qb9OFf6cak9IuZmWAMrKwdlhd9F+jGfY7tyV9ETYPvWaIvugsSXoGG7lwgbhPMtV sPg61rZw8ZS9VEeVu5Ipp2d06hewBBpo7QJeRGfBHoTcKafbTOlUMnYMsEiMW/pNO3Gn yuKCh8zG+zGpvxaloDPfuN8vE3eJiUVMk7fGshgk+kbxJ7vAvam2FgtPgjUZPWFtcZMf 5hXnu9jhllzoUfQfxkq7HFQG1OMN3IXIF2Uf6liYZLOZxsX5qyiojro6oaDnWn0Q1Ycm u7DSsrjHliqxJD9cILfJQ6objtVetnfbSvSj5w3fECJiRITMmkhZym3/lQ9gjjTDci0y sdoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3c56lCE/WpWmApGzGmNY2gwMFr2O/06RZiXwIkvRQAA=; b=YqadgE9MM5kxkWQn09V39jhEt8UOTyZQBaqscLidrrMonW1o546T2ywSpdZRtD+070 3sw/AmvEFVroVZqFmKxEOFh0QYX5PvhMKLDFYDFW8QOtKk202cMI332uD2XKUdrsFTsD zEsh55JsMyE6yQc9I1IgEiCsyF/w4efJhlYT+kO5Tvu4VPKkwp5LHpXvH0Kj8ACNCbV7 u5Cn3pRN1W8mICaQaPWzQY5ckdkGj0wkFRI6yk/1tnWkOsTMG6y7EKNOy2c+osAPzO9w VAdHczGfntx8Ou5ckhFJwuj7I2zSFC2n0pWI+mtYV8Dkee7OdzKPUhwVwwmMfqPUxVLB B4dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=cM1FMSAw; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s8-20020aa78bc8000000b006262bc88219si10094980pfd.160.2023.04.23.22.50.51; Sun, 23 Apr 2023 22:51:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=cM1FMSAw; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231245AbjDXFuR (ORCPT + 99 others); Mon, 24 Apr 2023 01:50:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230511AbjDXFtt (ORCPT ); Mon, 24 Apr 2023 01:49:49 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A40193588; Sun, 23 Apr 2023 22:49:48 -0700 (PDT) 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=3c56lCE/WpWmApGzGmNY2gwMFr2O/06RZiXwIkvRQAA=; b=cM1FMSAwc/AcWY9+ks8bZeTOQS HSRE1wj1RmlIHQ8bv8JqINzDuFQyl7YsoQO9Evk1tQKaU3yYt2c2UI9Wkit37h631rokvkd0z9B2l VVR+BaKxya/38EoJ2UI+TEap1+Ose9SVw/y8UrqGFhmlrsWIquEeWKjrX32vtILQS5aSgVf0A0uaL Ujm1de5SPOrTuaN6+/YdmMaLU7F/3TLvzgdhR5BVXO6OzWn5yVlHyHDIyq0elCmeLixuuC8FOmM6S Qn7nRM49zrqQDcjoKZ3gEI5dasf5T027NjT8LyJlv76Nt62r/CuI41r9aJ9HgIGXVKNKJ2N8Fjal6 Pdgu78vg==; Received: from [2001:4bb8:189:a74f:e8a5:5f73:6d2:23b8] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pqp57-00FOvQ-0r; Mon, 24 Apr 2023 05:49:45 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Miklos Szeredi , "Darrick J. Wong" , Andrew Morton , David Howells , Matthew Wilcox , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, ceph-devel@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, linux-kernel@vger.kernel.org Subject: [PATCH 05/17] filemap: update ki_pos in generic_perform_write Date: Mon, 24 Apr 2023 07:49:14 +0200 Message-Id: <20230424054926.26927-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230424054926.26927-1-hch@lst.de> References: <20230424054926.26927-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org All callers of generic_perform_write need to updated ki_pos, move it into common code. Signed-off-by: Christoph Hellwig --- 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 f4d8bf7dec88a8..feeb9882ef635a 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1894,8 +1894,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 0b8b4499e5ca18..1026acaf1235a0 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -291,12 +291,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 f4ab23efcf85f8..5a9ae054b6da7d 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4511,7 +4511,6 @@ static ssize_t f2fs_buffered_write_iter(struct kiocb *iocb, current->backing_dev_info = NULL; 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 893625eacab9fa..abdae2b29369be 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -666,7 +666,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 2723104cc06a12..0110bde3708b3f 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3960,7 +3960,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); @@ -4039,7 +4042,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, @@ -4052,8 +4054,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: current->backing_dev_info = NULL; -- 2.39.2