From patchwork Fri Dec 13 14:36:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13907258 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 58AFE1E0DD9 for ; Fri, 13 Dec 2024 14:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100471; cv=none; b=XBExnuXb0KlihjtDANgtbzyPt3b+gYBL8G4YN9f8Cv/rSjGZ3+i6dC00jTtEFzdyhSsL5ygCLyrj4pQArbCCTxQfwMS7V4ad8z4FbnOAg2cUW/6yC3OO6JQqGuSySYPDxG1DrWcn6EwzV6lG3yEKeGxwb4TB8Kn3E4bbyZtfsO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100471; c=relaxed/simple; bh=2bmrKHhqOpVWhf6RD9mPw9AxLKa0i/f5Bd0yrpSbJcU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ag5x4FpWnrPOHJdouxWqTtFfFyQe0nDzrHGLt7OmUyHpbR91MAvjzUIzHhlpLp6PzRa4clP3dBgxdresTqaw3avv38dd1lkeRvRmQqbdL0cArJ/RTslc1WczqvBTWRR391CfEycTNEG4loKQjhuTD1izKZ3lsY0qFgm7LKKK7ok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bzp5M4Ai; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bzp5M4Ai" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734100468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZxXfeI9zaN9MHchiaDhg4YyqSHugkBb7MViLt4OQWk8=; b=bzp5M4AisARq1ISGqcU/ncWtxBOAuPKZFV3bzklhgi6phCo7w9UckQ9pb/+DktrFgFIRlc vSA4zOHhzF/EqvvQdukdl42ZI/XorFWqd4IsX4I6vBaYFbvPjD1+21Unfw/vnNXeUfUtrp w+x3BGyeMtm5X7UfNiaErvKgmqKRWL8= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-364-oQjTGvIFOMefS1F98dw7Iw-1; Fri, 13 Dec 2024 09:34:25 -0500 X-MC-Unique: oQjTGvIFOMefS1F98dw7Iw-1 X-Mimecast-MFC-AGG-ID: oQjTGvIFOMefS1F98dw7Iw Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2FA201955F3E; Fri, 13 Dec 2024 14:34:24 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.90.12]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 887AD195605A; Fri, 13 Dec 2024 14:34:23 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH 1/6] iomap: split out iomap check and reset logic from iter advance Date: Fri, 13 Dec 2024 09:36:05 -0500 Message-ID: <20241213143610.1002526-2-bfoster@redhat.com> In-Reply-To: <20241213143610.1002526-1-bfoster@redhat.com> References: <20241213143610.1002526-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 In preparation for more granular iomap_iter advancing, break out some of the logic associated with higher level iteration from iomap_advance_iter(). Specifically, factor the iomap reset code into a separate helper and lift the iomap.length check into the calling code, similar to how ->iomap_end() calls are handled. Signed-off-by: Brian Foster --- fs/iomap/iter.c | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index 3790918646af..731ea7267f27 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -7,6 +7,13 @@ #include #include "trace.h" +static inline void iomap_iter_reset_iomap(struct iomap_iter *iter) +{ + iter->processed = 0; + memset(&iter->iomap, 0, sizeof(iter->iomap)); + memset(&iter->srcmap, 0, sizeof(iter->srcmap)); +} + /* * Advance to the next range we need to map. * @@ -14,32 +21,24 @@ * processed - it was aborted because the extent the iomap spanned may have been * changed during the operation. In this case, the iteration behaviour is to * remap the unprocessed range of the iter, and that means we may need to remap - * even when we've made no progress (i.e. iter->processed = 0). Hence the - * "finished iterating" case needs to distinguish between - * (processed = 0) meaning we are done and (processed = 0 && stale) meaning we - * need to remap the entire remaining range. + * even when we've made no progress (i.e. count = 0). Hence the "finished + * iterating" case needs to distinguish between (count = 0) meaning we are done + * and (count = 0 && stale) meaning we need to remap the entire remaining range. */ -static inline int iomap_iter_advance(struct iomap_iter *iter) +static inline int iomap_iter_advance(struct iomap_iter *iter, s64 count) { bool stale = iter->iomap.flags & IOMAP_F_STALE; int ret = 1; - /* handle the previous iteration (if any) */ - if (iter->iomap.length) { - if (iter->processed < 0) - return iter->processed; - if (WARN_ON_ONCE(iter->processed > iomap_length(iter))) - return -EIO; - iter->pos += iter->processed; - iter->len -= iter->processed; - if (!iter->len || (!iter->processed && !stale)) - ret = 0; - } + if (count < 0) + return count; + if (WARN_ON_ONCE(count > iomap_length(iter))) + return -EIO; + iter->pos += count; + iter->len -= count; + if (!iter->len || (!count && !stale)) + ret = 0; - /* clear the per iteration state */ - iter->processed = 0; - memset(&iter->iomap, 0, sizeof(iter->iomap)); - memset(&iter->srcmap, 0, sizeof(iter->srcmap)); return ret; } @@ -82,10 +81,14 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) return ret; } + /* advance and clear state from the previous iteration */ trace_iomap_iter(iter, ops, _RET_IP_); - ret = iomap_iter_advance(iter); - if (ret <= 0) - return ret; + if (iter->iomap.length) { + ret = iomap_iter_advance(iter, iter->processed); + iomap_iter_reset_iomap(iter); + if (ret <= 0) + return ret; + } ret = ops->iomap_begin(iter->inode, iter->pos, iter->len, iter->flags, &iter->iomap, &iter->srcmap); From patchwork Fri Dec 13 14:36:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13907261 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 33BB11E1A2D for ; Fri, 13 Dec 2024 14:34:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100472; cv=none; b=aE8gjFn+FscJ6kqC3uXndaO23gV7JkwFRpgwMgK06EqLo6DlVmATs+UmqhoQ+qKn5xy8MY7eeh5BxnrLeDVta+BO/qTKzYOdellVFTSzTJn498X7JrJcDNk2zptCITOqwHF+UciKRfNFEOuQ8P+tZ3bzQRxQYh9GnD6T/jLoyFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100472; c=relaxed/simple; bh=iOgQQylLMrtcvG6U9Yq+SXyo5Ad4O/vHOE1AWCM7Syw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BiTE3KDfARinAWGtYAnCazTN9VaZYeHx9FUhOkAbCyvix5/IR2sH9WllD1cCxy17g7ptL/JdUu1xIMlNvrqCoaIBWsedcFz5rjt76ZzWKCH821vJNXM4dTYIY/ya4EQF3BuLQRxojsK4gKa3Jm1uIhagDSJO3YWPX/YsNrkCkQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dpQN9J9x; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dpQN9J9x" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734100470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T+pyrgRUSK030l+dOQQ2M+Rf2PxL5PCacIPzx7MI32c=; b=dpQN9J9x1cV/+UtokqzzDpM717U9n++lqbDrtGiF74Qvqu3sDJa0RBFUDPKyha87TNKlgl tq1G0HAKeBVtvrYWo7Zzpr3rno7MV1hLZ7RcU3pT6wPhZSWrt/UNQKpHT4or77vXUjK1O7 fyERcgNZFLxo853JUcm6Dcn73PanS/U= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-86-nuVn901UOy2hjXBLI5VTpg-1; Fri, 13 Dec 2024 09:34:27 -0500 X-MC-Unique: nuVn901UOy2hjXBLI5VTpg-1 X-Mimecast-MFC-AGG-ID: nuVn901UOy2hjXBLI5VTpg Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1BFD319560AA; Fri, 13 Dec 2024 14:34:25 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.90.12]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 707A9195605A; Fri, 13 Dec 2024 14:34:24 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH 2/6] iomap: factor out iomap length helper Date: Fri, 13 Dec 2024 09:36:06 -0500 Message-ID: <20241213143610.1002526-3-bfoster@redhat.com> In-Reply-To: <20241213143610.1002526-1-bfoster@redhat.com> References: <20241213143610.1002526-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 In preparation to support more granular iomap iter advancing, factor the pos/len values as parameters to length calculation. Signed-off-by: Brian Foster --- include/linux/iomap.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 5675af6b740c..cbacccb3fb14 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -236,13 +236,19 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops); * * Returns the length that the operation applies to for the current iteration. */ -static inline u64 iomap_length(const struct iomap_iter *iter) +static inline u64 __iomap_length(const struct iomap_iter *iter, loff_t pos, + u64 len) { u64 end = iter->iomap.offset + iter->iomap.length; if (iter->srcmap.type != IOMAP_HOLE) end = min(end, iter->srcmap.offset + iter->srcmap.length); - return min(iter->len, end - iter->pos); + return min(len, end - pos); +} + +static inline u64 iomap_length(const struct iomap_iter *iter) +{ + return __iomap_length(iter, iter->pos, iter->len); } /** From patchwork Fri Dec 13 14:36:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13907259 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 63AF61E0E10 for ; Fri, 13 Dec 2024 14:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100471; cv=none; b=t05RzaGqtTD83jnnrh3L16XgZ82DyCvNvBqU3Rd50hCVJEe8XMtPlzexRXlsQye4Q7NAtQ2DLntiEimqvHEbvqngRi5GLJBh32X5/UmR9Bt2/jrC49e6pxcMzsmTJey8m+CbkfWj95+2pRajJ5tNeLQ5AcoKxtCWkfhazIOiiSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100471; c=relaxed/simple; bh=IYQ/xUS0lTvkHbAW76Lcj4NkZoF+W8014YmzTDWAKXA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qSX0DaHYnzDbhaNNAIOdo5qmMEnLOurhN8HEZWSaeQafLheTwu8Q+xyq/P8e4KxwW5TLFc1hdSFI+GQ4F3iVg9tpQ284PHu8f0YeqqDkF2sORazEO/95637rKCTuPljubuJypQRbqHegCfbs9EJ3zuUI8AS+IrqMpMIDAZ3PyKQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=AL9LNKzp; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AL9LNKzp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734100468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s61qkuGL8kimAslrSvPqTtDGHX0G4zgPijrCuN+q7/U=; b=AL9LNKzp3JYDFuYzeE1bC0NZkLrgx8aT8AT9A5Tr8rO0mX+qg2Igi2xYxySRZCGy5RkaIS AoDm4OJhK6I5QOmN4GSBTRt6/2JOrSON6y5g3HbAgQ1+bsH3n2m4WKmfHfy3ROWIdJM9Hp EEUwMrPppKdNMoZxmyVu3o1LLXelNIQ= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-511-rSAcv_aWOBistHFqLnm7Wg-1; Fri, 13 Dec 2024 09:34:26 -0500 X-MC-Unique: rSAcv_aWOBistHFqLnm7Wg-1 X-Mimecast-MFC-AGG-ID: rSAcv_aWOBistHFqLnm7Wg Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 074E219560AB; Fri, 13 Dec 2024 14:34:26 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.90.12]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5EB4C195605A; Fri, 13 Dec 2024 14:34:25 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH 3/6] iomap: support incremental iomap_iter advances Date: Fri, 13 Dec 2024 09:36:07 -0500 Message-ID: <20241213143610.1002526-4-bfoster@redhat.com> In-Reply-To: <20241213143610.1002526-1-bfoster@redhat.com> References: <20241213143610.1002526-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 The current iomap_iter iteration model reads the mapping from the filesystem, processes the subrange of the operation associated with the current mapping, and returns the number of bytes processed back to the iteration code. The latter advances the position and remaining length of the iter in preparation for the next iteration. At the _iter() handler level, this tends to produce a processing loop where the local code pulls the current position and remaining length out of the iter, iterates it locally based on file offset, and then breaks out when the associated range has been fully processed. This works well enough for current handlers, but upcoming enhancements require a bit more flexibility in certain situations. Enhancements for zero range will lead to a situation where the processing loop is no longer a pure ascending offset walk, but rather dictated by pagecache state and folio lookup. Since folio lookup and write preparation occur at different levels, it is more difficult to manage position and length outside of the iter. To provide more flexibility to certain iomap operations, introduce support for incremental iomap_iter advances from within the operation itself. This allows more granular advances for operations that might not use the typical file offset based walk. Note that the semantics for operations that use incremental advances is slightly different than traditional operations. Operations that advance the iter directly are expected to return success or failure (i.e. 0 or negative error code) in iter.processed rather than the number of bytes processed. Signed-off-by: Brian Foster --- fs/iomap/iter.c | 27 +++++++++++++++++++++------ include/linux/iomap.h | 4 ++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index 731ea7267f27..5fe0edb51fe5 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -25,7 +25,7 @@ static inline void iomap_iter_reset_iomap(struct iomap_iter *iter) * iterating" case needs to distinguish between (count = 0) meaning we are done * and (count = 0 && stale) meaning we need to remap the entire remaining range. */ -static inline int iomap_iter_advance(struct iomap_iter *iter, s64 count) +int iomap_iter_advance(struct iomap_iter *iter, s64 count) { bool stale = iter->iomap.flags & IOMAP_F_STALE; int ret = 1; @@ -36,7 +36,7 @@ static inline int iomap_iter_advance(struct iomap_iter *iter, s64 count) return -EIO; iter->pos += count; iter->len -= count; - if (!iter->len || (!count && !stale)) + if (!iter->len || (!count && !stale && iomap_length(iter))) ret = 0; return ret; @@ -49,6 +49,8 @@ static inline void iomap_iter_done(struct iomap_iter *iter) WARN_ON_ONCE(iter->iomap.offset + iter->iomap.length <= iter->pos); WARN_ON_ONCE(iter->iomap.flags & IOMAP_F_STALE); + iter->iter_spos = iter->pos; + trace_iomap_iter_dstmap(iter->inode, &iter->iomap); if (iter->srcmap.type != IOMAP_HOLE) trace_iomap_iter_srcmap(iter->inode, &iter->srcmap); @@ -74,10 +76,23 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) int ret; if (iter->iomap.length && ops->iomap_end) { - ret = ops->iomap_end(iter->inode, iter->pos, iomap_length(iter), - iter->processed > 0 ? iter->processed : 0, - iter->flags, &iter->iomap); - if (ret < 0 && !iter->processed) + ssize_t processed = iter->processed > 0 ? iter->processed : 0; + u64 olen = iter->len; + + /* + * If processed is zero, the op may have advanced the iter + * itself. Update the processed and original length bytes based + * on how far ->pos has advanced. + */ + if (!processed) { + processed = iter->pos - iter->iter_spos; + olen += processed; + } + + ret = ops->iomap_end(iter->inode, iter->iter_spos, + __iomap_length(iter, iter->iter_spos, olen), + processed, iter->flags, &iter->iomap); + if (ret < 0 && !processed) return ret; } diff --git a/include/linux/iomap.h b/include/linux/iomap.h index cbacccb3fb14..704ed98159f7 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -211,6 +211,8 @@ struct iomap_ops { * calls to iomap_iter(). Treat as read-only in the body. * @len: The remaining length of the file segment we're operating on. * It is updated at the same time as @pos. + * @iter_spos: The original start pos for the current iomap. Used for + * incremental iter advance. * @processed: The number of bytes processed by the body in the most recent * iteration, or a negative errno. 0 causes the iteration to stop. * @flags: Zero or more of the iomap_begin flags above. @@ -221,6 +223,7 @@ struct iomap_iter { struct inode *inode; loff_t pos; u64 len; + loff_t iter_spos; s64 processed; unsigned flags; struct iomap iomap; @@ -229,6 +232,7 @@ struct iomap_iter { }; int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops); +int iomap_iter_advance(struct iomap_iter *iter, s64 count); /** * iomap_length - length of the current iomap iteration From patchwork Fri Dec 13 14:36:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13907262 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 04C031E2009 for ; Fri, 13 Dec 2024 14:34:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100473; cv=none; b=OJyrfwVfS4+wR4IFm9JiUOo4iT7cl3gK6k8bAOiHTdw4IfdFgB1XvohCSeWgGRQKLTLjyrUUalRJr2Uj/9D79q3vWfKXmpIzSSzpHMzh6LsMR1kLrGy2PASJ59TH8FA0m0L4C8KULEE5mTwv4prJ6x+/B7iAdC9qVae1TNwkrJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100473; c=relaxed/simple; bh=OKAIQS7yoj53v6aPmr/2QbPOoplwTQWSySIf6C79NBs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BiTsFMfqhKWn0nOiyCxcQQ5y2fAypSYZCxiU6iWwepiwCAQMkP4ye08ifJBTdnH76XHdQtSMIcOqSvC9lz3/6VQpWBwYuQhPbHSAkMB21kaB9iYWDK255KiOQYPLMCWufbw/RqsKHzvic1bKyHS6KuS6Xpqg7LyXMrjXXUZgZh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ObCIjUaB; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ObCIjUaB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734100471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pofMAyHFR1hGi6iQD9ByZ17lIz/vNbdpdYcS8TQbk7Q=; b=ObCIjUaB7eoHoZ7Szu08iqtHfDcggO8xA/Bg/EXYvwE2p9WlIGOQLTq4WK2E6niS8eGDii Kl/EJoHItDubNFWaV30q++G/w7zybQh3BJtBIP+HSa5JHEWQscvPxL76cEjPYipCBH7ip9 prDx1D4UVVeVacbjYZTx6uuB51HsfLE= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-21-nsQQE1qkM8u7SQBDncD88Q-1; Fri, 13 Dec 2024 09:34:27 -0500 X-MC-Unique: nsQQE1qkM8u7SQBDncD88Q-1 X-Mimecast-MFC-AGG-ID: nsQQE1qkM8u7SQBDncD88Q Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E21651955F09; Fri, 13 Dec 2024 14:34:26 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.90.12]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 48485195605A; Fri, 13 Dec 2024 14:34:26 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH 4/6] iomap: advance the iter directly on buffered writes Date: Fri, 13 Dec 2024 09:36:08 -0500 Message-ID: <20241213143610.1002526-5-bfoster@redhat.com> In-Reply-To: <20241213143610.1002526-1-bfoster@redhat.com> References: <20241213143610.1002526-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Modify the buffered write path to advance the iter directly. Replace the local pos and length calculations with direct advances and loop based on iter state instead. Also remove the -EAGAIN return hack as it is no longer necessary now that separate return channels exist for processing progress and error returns. For example, the existing write handler must return either a count of bytes written or error if the write is interrupted, but presumably wants to return -EAGAIN directly in order to break the higher level iomap_iter() loop. Since the current iteration may have made some progress, it unwinds the iter on the way out to return the error while ensuring that portion of the write can be retried. If -EAGAIN occurs at any point beyond the first iteration, iomap_file_buffered_write() will then observe progress based on iter->pos to return a short write. With incremental advances on the iomap_iter, iomap_write_iter() can simply return the error. iomap_iter() completes whatever progress was made based on iomap_iter position and still breaks out of the iter loop based on the error code in iter.processed. The end result of the write is similar in terms of being a short write if progress was made or error return otherwise. Signed-off-by: Brian Foster --- fs/iomap/buffered-io.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 955f19e27e47..3ece0bee803d 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -909,8 +909,6 @@ static bool iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) { - loff_t length = iomap_length(iter); - loff_t pos = iter->pos; ssize_t total_written = 0; long status = 0; struct address_space *mapping = iter->inode->i_mapping; @@ -924,6 +922,8 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) size_t bytes; /* Bytes to write to folio */ size_t copied; /* Bytes copied from user */ size_t written; /* Bytes have been written */ + loff_t pos = iter->pos; + loff_t length = iomap_length(iter); bytes = iov_iter_count(i); retry: @@ -1006,17 +1006,12 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) goto retry; } } else { - pos += written; total_written += written; - length -= written; + iomap_iter_advance(iter, written); } - } while (iov_iter_count(i) && length); + } while (iov_iter_count(i) && iomap_length(iter)); - if (status == -EAGAIN) { - iov_iter_revert(i, total_written); - return -EAGAIN; - } - return total_written ? total_written : status; + return total_written ? 0 : status; } ssize_t From patchwork Fri Dec 13 14:36:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13907264 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 0FBBE1E2307 for ; Fri, 13 Dec 2024 14:34:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100474; cv=none; b=g5h2qNHG7TM2yYSq0iRtQLct3jweXC02I0FLv5gTYiE9NzojypGc2bsbQgWibsUmKqZR9WHukoFtu3KkpWXI9UvPznsVTgwNlOHRQGMhTbK3k62QtEAycm7qdV8sTzssgXmYxUGIb7sCP5+YhiYeBtB+Pj4RNYSu/kjou0oPC0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100474; c=relaxed/simple; bh=VpcK74VQzHYA+NX8kvw5noZ7DBJzXn4eXuf/FfV4zJI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=p9UEN3zptjeF9QlUbJHpw0kFPwe8pzZQXh/JFMnT2jo+PziVnqIKi+qidhOJItzkILnxO9OOetQDZLZxVVaFKEdcPFUKT8feC+DWZp3YcyMJp885DRXsslfRvbsbFRW3h+ykmqTVep5s2/emo4pfw4Mb+kVH3DO7Rs/TgWIwaRA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gL0KiBKu; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gL0KiBKu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734100472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KYhRuj26be0LS/4XAkGR4xpbIjWtWXYTpjNftN6/7K0=; b=gL0KiBKu2+pwN3wbaykLRvYDv1HXu6HD+x+pVBF3PxR58jIdq5CS7cjC+x5LsTuoW1hU7Q ExbTFNVKY9d1hg9IJnDV/szRgzVsFOLPoOjrIfV4l/8YMO69yT0vywQpsZPKNEzb91jNwq UDrySNj+3m5jUgbcH6qzWvqcLjuU3VA= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-75-nNyB6c4iNe2IvCPYuIqexQ-1; Fri, 13 Dec 2024 09:34:28 -0500 X-MC-Unique: nNyB6c4iNe2IvCPYuIqexQ-1 X-Mimecast-MFC-AGG-ID: nNyB6c4iNe2IvCPYuIqexQ Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C55BA1956054; Fri, 13 Dec 2024 14:34:27 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.90.12]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2DE99195605A; Fri, 13 Dec 2024 14:34:27 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH 5/6] iomap: advance the iter directly on unshare range Date: Fri, 13 Dec 2024 09:36:09 -0500 Message-ID: <20241213143610.1002526-6-bfoster@redhat.com> In-Reply-To: <20241213143610.1002526-1-bfoster@redhat.com> References: <20241213143610.1002526-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Modify unshare range to advance the iter directly. Replace the local pos and length calculations with direct advances and loop based on iter state instead. Signed-off-by: Brian Foster --- fs/iomap/buffered-io.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 3ece0bee803d..5e33e52eff15 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1268,18 +1268,16 @@ EXPORT_SYMBOL_GPL(iomap_write_delalloc_release); static loff_t iomap_unshare_iter(struct iomap_iter *iter) { struct iomap *iomap = &iter->iomap; - loff_t pos = iter->pos; - loff_t length = iomap_length(iter); - loff_t written = 0; if (!iomap_want_unshare_iter(iter)) - return length; + return iomap_length(iter); do { struct folio *folio; int status; size_t offset; - size_t bytes = min_t(u64, SIZE_MAX, length); + size_t bytes = min_t(u64, SIZE_MAX, iomap_length(iter)); + loff_t pos = iter->pos; bool ret; status = iomap_write_begin(iter, pos, bytes, &folio); @@ -1299,14 +1297,12 @@ static loff_t iomap_unshare_iter(struct iomap_iter *iter) cond_resched(); - pos += bytes; - written += bytes; - length -= bytes; + iomap_iter_advance(iter, bytes); balance_dirty_pages_ratelimited(iter->inode->i_mapping); - } while (length > 0); + } while (iomap_length(iter) > 0); - return written; + return 0; } int From patchwork Fri Dec 13 14:36:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13907263 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 4F12E1E22E8 for ; Fri, 13 Dec 2024 14:34:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100473; cv=none; b=Y/37Xv5cWI61PAZM3UCz+qYBZHODRKgOhabCUdumriUlJD620nVKfg5WnLmfO++xaY3HyeorvgNkPUev3J5K8dtBlz+FjBqCjThkSLQq5PfdQYUdkQK7+Fi6JYCe6lD2priL0F1oxTXnmtOjFmHlLLxqb9GbOdYlNArOXmQHMs4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100473; c=relaxed/simple; bh=peow5fQTuWi8AJxKriqerb0wfKWZpsGa0STw8wGnGNk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nJxoURxGaW97CZYJTGwF5aV1NsenfujXE7CfDaMVzj9EecZMLCp1X+Lo+ggorlnoM/aDZTX0ljoSSml3lLltU0tFptPQc9M0aY3i9s4SJd5OYG895h0xbTSlPPzwyes78p7sPp71r8an5ukZnxTQXtwj209hZMRcJd1siYyOF5w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FwYRSq5r; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FwYRSq5r" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734100471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o2VEA2dRQqqSc04MHk0RHgROz3bcefB7YZh9xI6D7Dc=; b=FwYRSq5rNVjM/bUwYlJEd4aQzlECBvVk84NKD1/J4KqFe71Dgvl2SfVU6hwadN6A3GPDPb e6CsR0CPPr+5rhXsFWG8uuOXQYKa8PLMZDNMTvMwUWX/1zpl1XERB0AWesJtbSewmDcY8I wOUSFWuSG/kKgvlDbTC/sXiSwLDVSf8= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-257-6o--Zv1yN12de_I3ZUKIgQ-1; Fri, 13 Dec 2024 09:34:29 -0500 X-MC-Unique: 6o--Zv1yN12de_I3ZUKIgQ-1 X-Mimecast-MFC-AGG-ID: 6o--Zv1yN12de_I3ZUKIgQ Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AC13B1955BF4; Fri, 13 Dec 2024 14:34:28 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.90.12]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 127F91955F3C; Fri, 13 Dec 2024 14:34:27 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH 6/6] iomap: advance the iter directly on zero range Date: Fri, 13 Dec 2024 09:36:10 -0500 Message-ID: <20241213143610.1002526-7-bfoster@redhat.com> In-Reply-To: <20241213143610.1002526-1-bfoster@redhat.com> References: <20241213143610.1002526-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Modify zero range to advance the iter directly. Replace the local pos and length calculations with direct advances and loop based on iter state instead. Signed-off-by: Brian Foster --- fs/iomap/buffered-io.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 5e33e52eff15..e0ae46b11413 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1343,15 +1343,12 @@ static inline int iomap_zero_iter_flush_and_stale(struct iomap_iter *i) static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero) { - loff_t pos = iter->pos; - loff_t length = iomap_length(iter); - loff_t written = 0; - do { struct folio *folio; int status; size_t offset; - size_t bytes = min_t(u64, SIZE_MAX, length); + size_t bytes = min_t(u64, SIZE_MAX, iomap_length(iter)); + loff_t pos = iter->pos; bool ret; status = iomap_write_begin(iter, pos, bytes, &folio); @@ -1374,14 +1371,12 @@ static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero) if (WARN_ON_ONCE(!ret)) return -EIO; - pos += bytes; - length -= bytes; - written += bytes; - } while (length > 0); + iomap_iter_advance(iter, bytes); + } while (iomap_length(iter) > 0); if (did_zero) *did_zero = true; - return written; + return 0; } int