Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 E429613F426 for ; Mon, 8 Apr 2024 14:55:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712588117; cv=none; b=jSWabrgxktI9GQnQauIHGezDoFVZl6z6QEZgCudHVXbSvDAk7h8ca5QUx5yaNRuPzErdl6nqGZNkh9eW/2Z+WEXZtZXdkeRqqLyPWNF7iWpBcdmzCdjlr7IAEFhxe2Bgo1hd8XiAVwqAMNlAIwhwqFcfBqdF7hhvqs7fa8u0o3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712588117; c=relaxed/simple; bh=7Zx5Pb3Kh7ijaZq/KmecXEjvyKxpm0xfQRlWh/OM6os=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=esn0XgtOZLv6i/JKso1BUCgZQqlnOkFfOdbFqbAJsBf1uWz9/1EvqcyQ7szqQEx1sAFq1qOTZCopPx6W01KpEHsEDq+hc1AjNDz5UPj0jyeuk5snkAzQx/553Lg0JiBRDiawoW0MhdE/8FL8PgdXJWfrnktssSTOJHXBTBXkmoo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=AHIJCAsu; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="AHIJCAsu" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=mPMajuCaJ13QLD4psAgAYOmAwlUp/oDV/+CUDYkmnrM=; b=AHIJCAsuwpCIJ4853eKyghqgdQ Pm0Eyr5Ex2DV4hW9De/GySKBHHNRYp7rOew9gGoDz0xuBfEqkIqpKlVbDJpNFmx3pn42uHc6jP/9o xT0rNzXH+b3HcqSBdU3E90XYC8D8TYahZnEEZQ1twsrdzBBfbJSj6zqNPUztmuoqtJIkPiWja2ITV DH81DEF/FPQNgGIeMrQAyrQSKInScRK4Ut9emjMe9wBb0UN+pnFMCSh0irtznCTAbNAjRFoncQdkF +/sX8Inb4gT9VnwxlMk+s6Oaio8E2ASAzIPlpQySHO5S2Pas8iRMidaSW2zYl40pc6rDPYYxUm2X9 rkIvv0fA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rtqOw-0000000FwaG-0TR6; Mon, 08 Apr 2024 14:55:14 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: Dave Chinner , linux-xfs@vger.kernel.org (open list:XFS FILESYSTEM) Subject: [PATCH 7/8] xfs: fix xfs_bmap_add_extent_delay_real for partial conversions Date: Mon, 8 Apr 2024 16:54:53 +0200 Message-Id: <20240408145454.718047-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240408145454.718047-1-hch@lst.de> References: <20240408145454.718047-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html xfs_bmap_add_extent_delay_real takes parts or all of a delalloc extent and converts them to a real extent. It is written to deal with any potential overlap of the to be converted range with the delalloc extent, but it turns out that currently only converting the entire extents, or a part starting at the beginning is actually exercised, as the only caller always tries to convert the entire delalloc extent, and either succeeds or at least progresses partially from the start. If it only converts a tiny part of a delalloc extent, the indirect block calculation for the new delalloc extent (da_new) might be equivalent to that of the existing delalloc extent (da_new). If this extent conversion now requires allocating an indirect block that gets accounted into da_new, leading to the assert that da_new must be smaller or equal to da_new unless we split the extent to trigger. Except for the assert that case is actually handled by just trying to allocate more space, as that already handled for the split case (which currently can't be reached at all), so just reusing it should be fine. Except that without dipping into the reserved block pool that would make it a bit too easy to trigger a fs shutdown due to ENOSPC. So in addition to adjusting the assert, also dip into the reserved block pool. Note that I could only reproduce the assert with a change to only convert the actually asked range instead of the full delalloc extent from xfs_bmapi_write. Signed-off-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_bmap.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 08e13ebdee1b53..7700a48e013d5a 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -1586,6 +1586,7 @@ xfs_bmap_add_extent_delay_real( if (error) goto done; } + ASSERT(da_new <= da_old); break; case BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING | BMAP_LEFT_CONTIG: @@ -1616,6 +1617,7 @@ xfs_bmap_add_extent_delay_real( if (error) goto done; } + ASSERT(da_new <= da_old); break; case BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING | BMAP_RIGHT_CONTIG: @@ -1650,6 +1652,7 @@ xfs_bmap_add_extent_delay_real( if (error) goto done; } + ASSERT(da_new <= da_old); break; case BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING: @@ -1684,6 +1687,7 @@ xfs_bmap_add_extent_delay_real( goto done; } } + ASSERT(da_new <= da_old); break; case BMAP_LEFT_FILLING | BMAP_LEFT_CONTIG: @@ -1722,6 +1726,7 @@ xfs_bmap_add_extent_delay_real( if (error) goto done; } + ASSERT(da_new <= da_old); break; case BMAP_LEFT_FILLING: @@ -1812,6 +1817,7 @@ xfs_bmap_add_extent_delay_real( xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV); xfs_iext_next(ifp, &bma->icur); xfs_iext_update_extent(bma->ip, state, &bma->icur, &RIGHT); + ASSERT(da_new <= da_old); break; case BMAP_RIGHT_FILLING: @@ -1861,6 +1867,7 @@ xfs_bmap_add_extent_delay_real( PREV.br_blockcount = temp; xfs_iext_insert(bma->ip, &bma->icur, &PREV, state); xfs_iext_next(ifp, &bma->icur); + ASSERT(da_new <= da_old); break; case 0: @@ -1983,11 +1990,9 @@ xfs_bmap_add_extent_delay_real( } /* adjust for changes in reserved delayed indirect blocks */ - if (da_new != da_old) { - ASSERT(state == 0 || da_new < da_old); + if (da_new != da_old) error = xfs_mod_fdblocks(mp, (int64_t)(da_old - da_new), - false); - } + da_new > da_old); xfs_bmap_check_leaf_extents(bma->cur, bma->ip, whichfork); done: -- 2.39.2