From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 1D7342222A9 for ; Wed, 19 Aug 2026 00:14:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787098490; cv=none; b=mF0PvSmHYroR5Pgh725wgbTw5x4JbNEbY9fUXjeL0IVWRh84UY6KJL8LHndCTgJ/ScP5chIyMeqDQdKrwNBRw+OzyLA25CC3CtYYqSI2ii5jWREubeox9EDC1Si2a4azV0/iF2aR7YgH2W+NpM1WqlFPW7GnBQHuebudBZelQbw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787098490; c=relaxed/simple; bh=fOpCBeFV+Rg/rTL5w67wDPrWTg3czLzAZDUMXGL5kDI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BoXyvpDsEQxa4jgSTItipzQpYTVYIakJGWckgeLsirwaJ2Ab8l9X410ak3a0tKuveOhu/OJwmJQ3CKDLGsP6L3keFVyl4RIkUe5/y28oBRVxbik8fp7zAfc8abs0iAsIbMnhjlj37WyBBZFgAo3qq8/fDMPxtnMJbY1Ae2F/gHE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FQ9Q7DaN; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FQ9Q7DaN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A48A1F00A3D; Wed, 19 Aug 2026 00:14:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787098488; bh=aCu5LIfqFAp6nIiFs8KI2Ikh1Li7iftABTkdZjCVM4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FQ9Q7DaN6/Q0bi3XdrIuZ82af3n0Ki1kYTARIAkE/Nsgm1m16booeXbwXDKlq6LWf bLg2KiXXgY4u7A+47Av4bhkvS1lAwVq9ztNSCwJxYHgrpS/DFdiKeg7s7E+q8b5+29 YYFdYt8OjftL9h0pxJomx9rpHHX3Bc3Ils6TiMQFUmhIIxwn+qeJgj8q1JCnYB2TxH ZZDMdeOZu+L1OlL6cClkVQJFlkpmwTcCz/P/XrDs1zgBfaB/q7wZnSf0nLjSF51LPS RiyMdQJLDBQb7eK8eH5Bnzsqu93qaE1d8bPagg8J04CX0afAqZd0YiBVsh8a+6ZD6C MaG9ixACU4UCA== From: Dave Chinner To: linux-xfs@vger.kernel.org Cc: cem@kernel.org Subject: [PATCH 01/38] xfs: fix dirty transaction cancellation in xfs_bmapi_convert_one_delalloc Date: Wed, 19 Aug 2026 10:12:04 +1000 Message-ID: <20260819001442.1451892-2-dgc@kernel.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260819001442.1451892-1-dgc@kernel.org> References: <20260819001442.1451892-1-dgc@kernel.org> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit xfs_bmapi_convert_one_delalloc() calls xfs_iext_count_extend() before checking whether there is actually a delalloc extent to convert. If xfs_iext_count_extend() modifies the inode's extent count fields it will dirty the transaction. If the subsequent extent lookup finds nothing to convert (e.g. a racing COW completion moved the extent to the data fork), the function returns -EAGAIN and the caller cancels the transaction. Cancelling a dirty transaction triggers a filesystem shutdown. Fix this by moving the extent lookup and validation ahead of the xfs_iext_count_extend() call. This ensures that if there is no extent to convert, or the extent has already been converted by a racing thread, the function returns before the transaction is dirtied and can be safely cancelled. Fixes: 4f86bb4b66c9 ("xfs: Conditionally upgrade existing inodes to use large extent counters") Assisted-by: LLM Signed-off-by: Dave Chinner --- fs/xfs/libxfs/xfs_bmap.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index d64defeda645..47c4d5c52b95 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -4380,11 +4380,11 @@ xfs_bmapi_convert_one_delalloc( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); - error = xfs_iext_count_extend(tp, ip, whichfork, - XFS_IEXT_ADD_NOSPLIT_CNT); - if (error) - goto out_trans_cancel; - + /* + * Look up the extent before extending the extent count so that we + * don't dirty the transaction if there is nothing to convert. A + * dirty transaction cancellation on -EAGAIN would shutdown the fs. + */ if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &bma.icur, &bma.got) || bma.got.br_startoff > offset_fsb) { /* @@ -4409,6 +4409,11 @@ xfs_bmapi_convert_one_delalloc( goto out_trans_cancel; } + error = xfs_iext_count_extend(tp, ip, whichfork, + XFS_IEXT_ADD_NOSPLIT_CNT); + if (error) + goto out_trans_cancel; + bma.tp = tp; bma.ip = ip; bma.wasdel = true; -- 2.55.0