Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp372603lql; Mon, 11 Mar 2024 05:34:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVRe/6M1Vwi0y3ekANSp31sCiLni5TFgQTlbWQ1/d1Fie7c+FVEIan3aQrcJsuH5PWTS2b0x9mbcqiabYU7u8Hu2v+OsgXlT5t6lZkswA== X-Google-Smtp-Source: AGHT+IGbW4psfVXnYsXpS+92NWiWOK9LUJuMcRVLRHCKrO3SeEdO/Oo25Shy449ePwtRxt9/7WQE X-Received: by 2002:a05:6a20:428a:b0:1a3:1180:1aed with SMTP id o10-20020a056a20428a00b001a311801aedmr5680506pzj.13.1710160457356; Mon, 11 Mar 2024 05:34:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710160457; cv=pass; d=google.com; s=arc-20160816; b=rsdssdAIMrNbZOzql43T96QeyGS62CsmtNV7GOO+aXfsFGhVtvHMFRrnjYQxfe+P9B e+K7khVU9nbmVldb+zz8mxyxQ0Q4hwy6XYE04PhNIShTMfmSfGWrVFlugv+cgMuW7ZQZ E10iaejoZVPn00V50IFRrIOWgC75L4uTSmyFeysJ2x/vuIv4tqb/Y1B4RThFS/1ZiUWx D0YPLvuWF75OCAvsg49Hl8p2qYfYrD7OVwYV34Cx2vBdcNCOZHuXWfVBqbGYrvQqpsbp SlOiI2eaoXPIgzvd7XVsW7faYvFkjFDmIjk0cGBipMI4jSXzu/hjILLUIidhASqUIG3J 8i9g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=UcMYNHO9AjFInGgs3XS0DNriOQknuU6PguvE4Np23FY=; fh=5dB93T9RUScPXiJBPgMY9ddAKXpKWIKqxrLOkZR5g5k=; b=ZBDbxCYryCbtQJ9L1wLEVFN4WbsfuwT2fCxLOpIC9HHnhXFkYwjFpdd8CVnYCV2dKN oS1z2UEQtyaRgdr1eeHjiGmcgt8M9vouPk6losgv5LReAgFN1qkZEKLWqH33y3nKmCUM BTs6knGx37whByOtwuw5aUAGQZg7dtiROdkcZMDiwxuRvbLMNFLmhndaLWgaesXeUqPw Uyh5iT+UnjSYxZ9J7IyXq4hwHY9MLkAZkYCeEdyB5xWL4RDraFADtJh/0qUjj/uI8Kd5 5YSfAf7iW5O/FjsjOTB4ib3hjJnk8qX3i/kjOCDjlKM93OOu6evO06Xd9iOdE5A7Drqg 777A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-98830-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98830-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k24-20020a63ba18000000b005cf94b8d9ddsi4904865pgf.869.2024.03.11.05.34.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 05:34:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-98830-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-98830-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98830-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 42136B225B0 for ; Mon, 11 Mar 2024 12:31:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 92CA73C478; Mon, 11 Mar 2024 12:30:06 +0000 (UTC) Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAB463C699; Mon, 11 Mar 2024 12:30:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710160205; cv=none; b=NVrYIcggKAGwMvPYeEGVYT24dgbmOAkM7cQi4aVHZfJH87pDXwVaj7jaS4xdQoRO4lLDOywHRWFzz4yxRmFuHslL/YcPpDLDfkrs0n9ozbmTB7llqXERa7hdELr/F/XdP89I6rPXLZ2cGafaL0xPYNlbsi+fRZzf2S/102Z3Pj4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710160205; c=relaxed/simple; bh=ERGB+uRnYTuNnKGc+MsbXEt6gLbLEGXQxvrvJ4rByP4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fPKGWLMa1pzCDByNOry03OmtVn21SPhtDmtOqM87onYyA//eiqIuZRLu23IbBbO8p0R5a7embvjLhp817MJ6G01I1/KsvdRiLkLwK/DSst1hvVKMbwupiIWJrw6HqOst+PtGi9vs1aq1tAaxtGbeQoiskCihOQa9XrNcGPoUu9Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Ttbh15Kgqz4f3jR9; Mon, 11 Mar 2024 20:29:53 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 5ECD61A016E; Mon, 11 Mar 2024 20:29:59 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgDHlxAt+e5lAE9+Gg--.62739S8; Mon, 11 Mar 2024 20:29:59 +0800 (CST) From: Zhang Yi To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, djwong@kernel.org, hch@infradead.org, brauner@kernel.org, david@fromorbit.com, tytso@mit.edu, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [PATCH 4/4] iomap: cleanup iomap_write_iter() Date: Mon, 11 Mar 2024 20:22:55 +0800 Message-Id: <20240311122255.2637311-5-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240311122255.2637311-1-yi.zhang@huaweicloud.com> References: <20240311122255.2637311-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgDHlxAt+e5lAE9+Gg--.62739S8 X-Coremail-Antispam: 1UD129KBjvJXoWxXF4UAr48KF43urWfZF1DZFb_yoW5tr17p3 45Ka95CrW8Xw47Wrn5JFy5WFyYkFyfKFW7GryUGwsIvFn0yrZ8KF18WayYv3W5Jas3Ar4f tF4vyryrGF1UAr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPF14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUF18B UUUUU X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi The status variable in iomap_write_iter() is confusing and iomap_write_end() always return 0 or copied bytes, so replace it with a new written variable to represent the written bytes in each cycle, and also do some cleanup, no logic changes. Signed-off-by: Zhang Yi --- fs/iomap/buffered-io.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 19f91324c690..767af6e67ed4 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -851,7 +851,7 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) loff_t length = iomap_length(iter); size_t chunk = PAGE_SIZE << MAX_PAGECACHE_ORDER; loff_t pos = iter->pos; - ssize_t written = 0; + ssize_t total_written = 0; long status = 0; struct address_space *mapping = iter->inode->i_mapping; unsigned int bdp_flags = (iter->flags & IOMAP_NOWAIT) ? BDP_ASYNC : 0; @@ -862,6 +862,7 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) size_t offset; /* Offset into folio */ size_t bytes; /* Bytes to write to folio */ size_t copied; /* Bytes copied from user */ + size_t written; /* Bytes have been written */ bytes = iov_iter_count(i); retry: @@ -906,7 +907,7 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) flush_dcache_folio(folio); copied = copy_folio_from_iter_atomic(folio, offset, bytes, i); - status = iomap_write_end(iter, pos, bytes, copied, folio); + written = iomap_write_end(iter, pos, bytes, copied, folio); /* * Update the in-memory inode size after copying the data into @@ -915,28 +916,26 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) * no stale data is exposed. */ old_size = iter->inode->i_size; - if (pos + status > old_size) { - i_size_write(iter->inode, pos + status); + if (pos + written > old_size) { + i_size_write(iter->inode, pos + written); iter->iomap.flags |= IOMAP_F_SIZE_CHANGED; } - __iomap_put_folio(iter, pos, status, folio); + __iomap_put_folio(iter, pos, written, folio); if (old_size < pos) pagecache_isize_extended(iter->inode, old_size, pos); - if (status < bytes) - iomap_write_failed(iter->inode, pos + status, - bytes - status); - if (unlikely(copied != status)) - iov_iter_revert(i, copied - status); cond_resched(); - if (unlikely(status == 0)) { + if (unlikely(written == 0)) { /* * A short copy made iomap_write_end() reject the * thing entirely. Might be memory poisoning * halfway through, might be a race with munmap, * might be severe memory pressure. */ + iomap_write_failed(iter->inode, pos, bytes); + iov_iter_revert(i, copied); + if (chunk > PAGE_SIZE) chunk /= 2; if (copied) { @@ -944,17 +943,17 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) goto retry; } } else { - pos += status; - written += status; - length -= status; + pos += written; + total_written += written; + length -= written; } } while (iov_iter_count(i) && length); if (status == -EAGAIN) { - iov_iter_revert(i, written); + iov_iter_revert(i, total_written); return -EAGAIN; } - return written ? written : status; + return total_written ? total_written : status; } ssize_t -- 2.39.2