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 C6BBB134DE for ; Mon, 29 Apr 2024 06:15:50 +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=1714371352; cv=none; b=HnN10n1YbLlbWhCUH2sQD2Cn6ULy3UA2jmKZSSRrJd/mpexT4Mg0MBX6VXaUI9CX9x+FliBTAoaGvdAHWcKCrbLY3dSJZiyTYcNVkYPFf1pqbln1yi5jHMqBymbYZX95GmzxjispB+iYKxgoVFWsqvzusjSCsnYzWKQ9EkIATh8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714371352; c=relaxed/simple; bh=VamDX7Hz8gDgr43cFn+nvfl78SUVTVTO2mO3BmqurZM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D1PkmAp3h5ZrY1wQDXeR30xv/YxXDcg6CvSOnACqrSVq0TgA4gYvKA3/UW5Oz9dLWI0jWog6x7j5AudFvjNH8dgPDcLq/YRXCTUD+D1VUjewOI4CZJ9N/4u0j5tt8SVX1FHbQagmGb4Xf6Cxsz8bk0LV9Y8DaUOu7A+hC1moIKs= 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=TMz16zDm; 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="TMz16zDm" 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=omZPRAxrXfcXg3AvCfX2DjCl1BQe5B1jL+WmzZWd5i8=; b=TMz16zDm1GA1D67UlpkNGKAlbU khvlT2mny3fAv6l2B1zpg1kwS7I2ObnuUx6TOuNeD0/p7tWI/tTzBXYwcuCNbDwY78Idc7PPzEYSN ZCAt4xkVe8BwlSpF2U2llcuaqBKR878aRzmhHVXy2GCTY/eT1OeFXu3vdPU1nZznKhNBcKqHa5Vq8 kmhPRdWB09FGWGmPZ0nXRzeg+dF9HixQ8BX0FN/h3qwpwGFBIWq5t3a7RT9RACIb/R5OPVCHZdcTP kpW1fn1hSQ0Y/C4pBYq7dPB3uEAMULPe4wPtcC/YmnKYaA97A3fY4L/lL1JwX6U9cNbaK1Gf/ZCpl bhXFlcjg==; 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 1s1KIn-00000001cmc-2vlV; Mon, 29 Apr 2024 06:15:50 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: Dave Chinner , linux-xfs@vger.kernel.org Subject: [PATCH 7/9] xfs: fix xfs_bmap_add_extent_delay_real for partial conversions Date: Mon, 29 Apr 2024 08:15:27 +0200 Message-Id: <20240429061529.1550204-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240429061529.1550204-1-hch@lst.de> References: <20240429061529.1550204-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_old). 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 | 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 472c795beb8add..42c5a2efa656a5 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -1570,6 +1570,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: @@ -1600,6 +1601,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: @@ -1634,6 +1636,7 @@ xfs_bmap_add_extent_delay_real( if (error) goto done; } + ASSERT(da_new <= da_old); break; case BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING: @@ -1668,6 +1671,7 @@ xfs_bmap_add_extent_delay_real( goto done; } } + ASSERT(da_new <= da_old); break; case BMAP_LEFT_FILLING | BMAP_LEFT_CONTIG: @@ -1706,6 +1710,7 @@ xfs_bmap_add_extent_delay_real( if (error) goto done; } + ASSERT(da_new <= da_old); break; case BMAP_LEFT_FILLING: @@ -1796,6 +1801,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: @@ -1845,6 +1851,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: @@ -1967,12 +1974,10 @@ xfs_bmap_add_extent_delay_real( } /* adjust for changes in reserved delayed indirect blocks */ - if (da_new < da_old) { + if (da_new < da_old) xfs_add_fdblocks(mp, da_old - da_new); - } else if (da_new > da_old) { - ASSERT(state == 0); - error = xfs_dec_fdblocks(mp, da_new - da_old, false); - } + else if (da_new > da_old) + error = xfs_dec_fdblocks(mp, da_new - da_old, true); xfs_bmap_check_leaf_extents(bma->cur, bma->ip, whichfork); done: -- 2.39.2