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: 13907266 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 78DFB1AAC9 for ; Fri, 13 Dec 2024 14:34:27 +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=1734100469; cv=none; b=NYUm4lMaeGGqkCFyKqu98RHd9uydvV1g3ESDyCklelZcDd+t4Hulsn5QMl/saGsdPzryn1jQPe0vClvw4t8efysrV6yrNWPxZyhRc3hunXUbXhK99MKXGScfVhaEyVvY/c5J10CGdag51V8P8QA9p40MbXQJKjmx4YeDyCHSXDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100469; c=relaxed/simple; bh=2bmrKHhqOpVWhf6RD9mPw9AxLKa0i/f5Bd0yrpSbJcU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oUgWW2EcmGuPkZ+ZWMo+i60qipjsyCjn3/uU/OMDfuZPSmB7qkF714S66Gs+x+iyRdiXRuDSchlQaTY4XB+cTfMxfO21GULdXL5KwFIGl0KdFFYwTkNSA0yH94j9VkoV0KinrrgvWHDaTSvVtbJ9oWpT0L5w+7IJLyS/kmhC5b0= 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=h5rXLKTy; 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="h5rXLKTy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734100466; 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=h5rXLKTynlV4ZsO4qjVDyHvlI88QrpfUnBsWjyrrp1mALF/2521lvvAwTXSMc2loST3ySe kX3DO/TJebhPzr0amNIQJkQ1aDKJ+Kp0bJG/EUoO6mzMInPuQjmk8cRrLXF9cnTERGbMgb Wt6L/cYC1zA9x4PEI9MLEHFijOIjJPk= 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-xfs@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: 13907267 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 622D01E0E08 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=QPkDsGeauWw567u9lLB44LKespotlELuIbQ1EUd0QiIRfRb3/fzEthPy9czOmYeuZ5UN7qejgbkeEeVtXxsIBhSwQXBv3J/3rRX7ohLv0xMUqBpVej97zPGCTliZ77yO8t0Ow2hPCBh+tECVlam8Dvf8RMntlFmP75e8jgeH7kw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100471; c=relaxed/simple; bh=iOgQQylLMrtcvG6U9Yq+SXyo5Ad4O/vHOE1AWCM7Syw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JwoopI2SWacqHYGPbyM5vryUOID+BGgF7Z52Xa9ayNob5Tpo7rmUd4OAMVpYZg2soDRCOQyK8TmlSf0MBhbevYp/DgO07glkCQIT82As6p+5/OD3X3w8SIkswglXm1mG/5yogQ7MxMxZt7XNoZdkU95Fb0+F2i6PszvHinDvLfY= 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=Wr7VRTN/; 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="Wr7VRTN/" 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=T+pyrgRUSK030l+dOQQ2M+Rf2PxL5PCacIPzx7MI32c=; b=Wr7VRTN/yo5Mn5wjfEH20cKvVs8kHWpNSxj6I6b482qHlJIqIi325R79q5HMXUOT0xb9fJ SHYE86rOQRUECftX8IDDgC01RVRsG16zu0q8/UdWqaxSg4+4dOjVUuu1ZbPeydkdP8Gw7W H9ngRLF/tQtMSKjDtulphposctzHibE= 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-xfs@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: 13907270 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 4D89B1E1A3E for ; Fri, 13 Dec 2024 14:34:30 +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=LeXYEVnKKQyqUwXHa1v9BMVV3UxMJCjFucKs0Tf666VmvqsXGK17HyFgc7fk0FyhhgkWZ18pSpXtZjh/MzE2WgjoPr52i+h1szptFvSKcqseuae9GO8nJNCcBYOEQNC13Y0JgaOw90T1OEFPqCeuR6XUbAjwLidLVvisI7ELiWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100473; c=relaxed/simple; bh=IYQ/xUS0lTvkHbAW76Lcj4NkZoF+W8014YmzTDWAKXA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ciR2O2SiYGQoBmzx+cwYhiruQYYY+f3goy9NZ2TPGVweik0KQME6xY38Keqcnc3Xk5Z0SN2t/H+6t9lDKBCsAbCkXNCEaL+GN8DthE/D7j5C7kn0KwWNXtF8s1cHLUMnerEAz/FWANs7BTK7m8RH5jPPjhU+txy+alVXwOIJFqE= 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=a5UnRq13; 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="a5UnRq13" 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=s61qkuGL8kimAslrSvPqTtDGHX0G4zgPijrCuN+q7/U=; b=a5UnRq13NQOaFCUFvsIIUB/iu+j8F3CbmBInrAW1TDzl8mQ5IEDLB77vdTr+ruXFRAhOuQ VBhhOdTSexoJeUnYxa/PVZR6djb0DvnIvxb0gditMB0dqjKLZJA5/wbHdoy3VILYuV//LQ NscrovLXx6S2iZknmvy/T+5lbP1DMqk= 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-xfs@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: 13907268 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 5E4461AAC9 for ; Fri, 13 Dec 2024 14:34:30 +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=1734100472; cv=none; b=BucN3amX/gctNO1+HrUBonYYmnX9a8ngTUfqVQy3DS/HUH8JGNNgT5saBPgUApz/tWaWlgSM+bP7t6OPN06iy8CsEjmRzeETaU6zrqmg85DvLzONXXT1CLM+uIwxEv8tPpGzbTQzu0KbF6GdtYE/W4+dMReR5SsrzaxqaQhbuBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100472; c=relaxed/simple; bh=OKAIQS7yoj53v6aPmr/2QbPOoplwTQWSySIf6C79NBs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pjBEHtSzBc5WcVMmnv3zatphupygC0C52lQQlFY1c7hp13Jw6VSBSSTwdTU5dp0DuS8GkecVKOn3Y/+PznhNMlFL47uae/J1VTRZl6tWWunMg4Iay8HPHE0iR5/MKI+DjLZbXttcvkSxcAJlrZU7Buj4MECDinEFtv37onbC/30= 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=BAtz6K2X; 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="BAtz6K2X" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734100469; 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=BAtz6K2XGDYcs7zB+B15+D4HUs+2jzviuZq2v01H9vlST0FriCtcd/Iv8JJCHWtdP2PqnA ZyREXun+luMIk6OiVEifJeGHH5vPIeX7ENh+qGfsslkJRr4Qwu2PKcw5AJO6PCLURFptUr J0w+MCsmUme0hWBhBf4Wob1kb7cetdk= 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-xfs@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: 13907269 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 1D1531E1A23 for ; Fri, 13 Dec 2024 14:34:30 +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=1734100472; cv=none; b=sAUTl7WkVw2lgu1RkJzapHy1KiV7HnedAptx6kAfbhX26bmTg83qYDi7vI97LDPMiGctw5uCJA518RWUXw1erI3ZIIN87DwRi/jnYAyKaa3vBtvCB+0SblQ7aqjZrCRgSmDCawa6YQY+wSCrVyoFGhpPB0CX3EhTqQh5vBbY0HA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734100472; c=relaxed/simple; bh=VpcK74VQzHYA+NX8kvw5noZ7DBJzXn4eXuf/FfV4zJI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mIm7zABQ+YzML238sAipb0SZ14JEPaxTRkhOYiyQph9wEgJJZLTTATW03VbsrmryHZLuwLNKwmLZh6UwUNXOFhppkFMg9Y+hxVv//pUvV6T21GAwZDmmzTZs77qJxem3wKWAuPS+q00vo/mhUEsmZuX/NUaSOeaKrE8lZelJCi0= 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=h1yfiydd; 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="h1yfiydd" 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=KYhRuj26be0LS/4XAkGR4xpbIjWtWXYTpjNftN6/7K0=; b=h1yfiyddUf9rtfZE8ZfWHc/DELnE9QbfYKLDU+y5feV1a+WAW9tK59UeEfCsYKLsakDvjr 0Z0uUP0vCf3SjlN8I3nON0qcKRTGKu1UZOgPZxyN/eUeYHj8SN7lsUJXyL1gZr+eP/jRxd 55Jhar2ko3TZyqbf6YVihRb9o0wOW4A= 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-xfs@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: 13907271 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 4F1881E22ED 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-xfs@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