From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Chandan Babu R <chandan.babu@oracle.com>,
Dave Chinner <david@fromorbit.com>,
linux-xfs@vger.kernel.org
Subject: Re: [PATCH 7/9] xfs: fix xfs_bmap_add_extent_delay_real for partial conversions
Date: Mon, 29 Apr 2024 08:48:55 -0700 [thread overview]
Message-ID: <20240429154855.GC360919@frogsfrogsfrogs> (raw)
In-Reply-To: <20240429061529.1550204-8-hch@lst.de>
On Mon, Apr 29, 2024 at 08:15:27AM +0200, Christoph Hellwig wrote:
> 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 <hch@lst.de>
Looks good now,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> ---
> 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
>
>
next prev parent reply other threads:[~2024-04-29 15:48 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-29 6:15 xfs_bmapi_write retval fix v2 Christoph Hellwig
2024-04-29 6:15 ` [PATCH 1/9] xfs: fix error returns from xfs_bmapi_write Christoph Hellwig
[not found] ` <CAEJPjCu5CWEMHHpLS2yB7tk9Hh52EsQ5npifKiw--U-50PLEng@mail.gmail.com>
2024-05-06 12:39 ` 刘通
2024-10-15 15:56 ` 刘通
2024-04-29 6:15 ` [PATCH 2/9] xfs: remove the unusued tmp_logflags variable in xfs_bmapi_allocate Christoph Hellwig
2024-04-29 6:15 ` [PATCH 3/9] xfs: lift a xfs_valid_startblock into xfs_bmapi_allocate Christoph Hellwig
2024-04-29 6:15 ` [PATCH 4/9] xfs: don't open code XFS_FILBLKS_MIN in xfs_bmapi_write Christoph Hellwig
2024-04-29 6:15 ` [PATCH 5/9] xfs: pass the actual offset and len to allocate to xfs_bmapi_allocate Christoph Hellwig
2024-04-29 15:48 ` Darrick J. Wong
2024-04-29 17:18 ` Christoph Hellwig
2024-04-29 17:20 ` Darrick J. Wong
2024-04-29 6:15 ` [PATCH 6/9] xfs: remove the xfs_iext_peek_prev_extent call in xfs_bmapi_allocate Christoph Hellwig
2024-04-29 6:15 ` [PATCH 7/9] xfs: fix xfs_bmap_add_extent_delay_real for partial conversions Christoph Hellwig
2024-04-29 15:48 ` Darrick J. Wong [this message]
2024-04-29 6:15 ` [PATCH 8/9] xfs: do not allocate the entire delalloc extent in xfs_bmapi_write Christoph Hellwig
2024-04-29 6:15 ` [PATCH 9/9] mm,page_owner: don't remove GFP flags in add_stack_record_to_list Christoph Hellwig
2024-04-29 6:17 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240429154855.GC360919@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=chandan.babu@oracle.com \
--cc=david@fromorbit.com \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox