Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795039097; b=IJGYK0WwlSb/hRXAQmcvDfYsbZSbKoZE4pFl0NtxBv/pxG4OpPZ64bpZOfYX5Kc2fpnF BcLCByogHsmF9ekE2X7gMjcV3bRdjd3RMB1gw//UgLZAom+7WqcwmTHwhSWi9YrzqWdVG cqz7HjNPrgjKg4SNKzdy6qWngV6nquYG7Z8Oh2DjTqMXP784f9cURgWXkrv2k2MoyLprp l6E9kLUAmu4G/Qd557oxkPvgsO5CMpLQgERBPm5UbU2ttEMekDiMkrD+oULCFwd68oq7/ UzKZ0gdyXz5YB2sDxtRbZXX8JO6JLMZeTWNnbfOtTFEMpV12G84eE68wMRduVETQ5Lg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795039097; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=C5u31JcWa/e4vLl22B1bkRJSioHhFzS+zB0Mux8xfUU=; b=M0ZNdj7F9yTN7e02NBuDAtH0wvkeixGBPw9I7O7LMTM7FtByC52kz6ga7W54F58eR9ub FbFeZSHJDrIFzGwxWnzJFKGq8OMBk2fQJn3wI4tMGCAPRSpYIABnkONSD/TX86P2jHWjJ jjPFne5IsjJXoHMA1I2UeDG8b2GkpVRzJ7YkRY+7cfbsfb/Tc2IoARCo33zlkYgLMWM+h iv/vu+tFaGgh1YI+uB2TkT1aIIv5WBidd1CovKUtvNuTiHyRslTajStpx59Vl/TALqrme ialI6rByM/8PQm+EmztHY26wnDiKGaLsjs0KQRRP5j6zx/MPL9M2Z1X5+v+hD8d9EuQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=v9xPYhO5; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C02A4606A320; Wed, 18 Nov 2026 21:58:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=v9xPYhO5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE7F91F000C4; Wed, 18 Nov 2026 21:58:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795039097; bh=C5u31JcWa/e4vLl22B1bkRJSioHhFzS+zB0Mux8xfUU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=v9xPYhO5oXVu0+D2QFq99ZiYqCyUQjNfBzgK+R6spmbCgYkQitgYOeZv++UMiTSNT Fhlg2KJNds7DNjc7QqQihOIbybHgVVUD9W4MTLsoq94lYmuI82jOhb093MQ+MSbo+s K7KDowfim6DvtXE4QmN1Le01HaZW+mp/BZ7KzxUU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Christoph Hellwig , Daejun Park , Pankaj Raghav , Carlos Maiolino , Sasha Levin Subject: [PATCH 6.6 1979/3318] xfs: add a flag to convert unwritten extents without allocating blocks Date: Wed, 18 Nov 2026 15:43:21 +0100 Message-ID: <20261118150421.444306957@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daejun Park [ Upstream commit f3ca3498dfe624f9b604c934263538a3acd55af5 ] xfs_bmapi_write() with XFS_BMAPI_CONVERT also allocates blocks for holes and delalloc extents in the range. Add XFS_BMAPI_CONVERT_ONLY for callers that may only convert already allocated blocks. It stops at a hole or delalloc extent, and returns -ENOSR if it stops before mapping anything. Marked for stable because "xfs: refuse a pNFS LAYOUTCOMMIT of a range without blocks" needs it. Suggested-by: Christoph Hellwig Link: https://lore.kernel.org/r/20261013120359.GB2944@lst.de Cc: stable@vger.kernel.org Signed-off-by: Daejun Park Reviewed-by: Christoph Hellwig Reviewed-by: Pankaj Raghav Signed-off-by: Carlos Maiolino [ sashal: adapted flag insertion to follow XFS_BMAPI_NORMAP because XFS_BMAPI_EXTSZALIGN is absent ] Signed-off-by: Sasha Levin --- fs/xfs/libxfs/xfs_bmap.c | 14 ++++++++++++-- fs/xfs/libxfs/xfs_bmap.h | 10 +++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index c111f691ea51a..974dd4cd38e50 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -4296,6 +4296,8 @@ xfs_bmapi_finish( * Returns a negative error code on failure, including -ENOSPC when it could not * allocate any blocks and -ENOSR when it did allocate blocks to convert a * delalloc range, but those blocks were before the passed in range. + * With XFS_BMAPI_CONVERT_ONLY, it stops at a hole or a delalloc extent instead + * of allocating blocks, and returns -ENOSR if it stops before mapping anything. */ int xfs_bmapi_write( @@ -4355,6 +4357,8 @@ xfs_bmapi_write( */ ASSERT((flags & (XFS_BMAPI_PREALLOC | XFS_BMAPI_ZERO)) != (XFS_BMAPI_PREALLOC | XFS_BMAPI_ZERO)); + ASSERT(!(flags & XFS_BMAPI_CONVERT_ONLY) || + (flags & XFS_BMAPI_CONVERT)); if (XFS_IS_CORRUPT(mp, !xfs_ifork_has_extents(ifp)) || XFS_TEST_ERROR(false, mp, XFS_ERRTAG_BMAPIFORMAT)) { @@ -4402,6 +4406,9 @@ xfs_bmapi_write( * that we found, if any. */ if (need_alloc || wasdelay) { + if (flags & XFS_BMAPI_CONVERT_ONLY) + break; + bma.eof = eof; bma.conv = !!(flags & XFS_BMAPI_CONVERT); bma.wasdel = wasdelay; @@ -4489,10 +4496,13 @@ xfs_bmapi_write( * * To avoid a successful return with *nmap set to 0, return the magic * -ENOSR error code for this particular case so that the caller can - * handle it. + * handle it. The same goes for XFS_BMAPI_CONVERT_ONLY stopping at a + * hole or a delalloc extent at the start of the range, in which case + * nothing has been changed. */ if (!n) { - ASSERT(bma.nallocs >= *nmap); + ASSERT((flags & XFS_BMAPI_CONVERT_ONLY) ? bma.nallocs == 0 : + bma.nallocs >= *nmap); return -ENOSR; } *nmap = n; diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h index e33470e39728d..8bcb1a9b5fed3 100644 --- a/fs/xfs/libxfs/xfs_bmap.h +++ b/fs/xfs/libxfs/xfs_bmap.h @@ -87,6 +87,13 @@ struct xfs_bmalloca { /* Do not update the rmap btree. Used for reconstructing bmbt from rmapbt. */ #define XFS_BMAPI_NORMAP (1u << 10) +/* + * Use with XFS_BMAPI_CONVERT to convert unwritten extents without allocating + * blocks. Stop at a hole or a delalloc extent: return the mappings found so + * far, or -ENOSR if there are none. + */ +#define XFS_BMAPI_CONVERT_ONLY (1u << 12) + #define XFS_BMAPI_FLAGS \ { XFS_BMAPI_ENTIRE, "ENTIRE" }, \ { XFS_BMAPI_METADATA, "METADATA" }, \ @@ -98,7 +105,8 @@ struct xfs_bmalloca { { XFS_BMAPI_REMAP, "REMAP" }, \ { XFS_BMAPI_COWFORK, "COWFORK" }, \ { XFS_BMAPI_NODISCARD, "NODISCARD" }, \ - { XFS_BMAPI_NORMAP, "NORMAP" } + { XFS_BMAPI_NORMAP, "NORMAP" }, \ + { XFS_BMAPI_CONVERT_ONLY, "CONVERT_ONLY" } static inline int xfs_bmapi_aflag(int w) -- 2.53.0