From: Brian Foster <bfoster@redhat.com>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: linux-xfs@vger.kernel.org, david@fromorbit.com
Subject: Re: [PATCH 4/6] xfs: fix infinite loop when reserving free block pool
Date: Fri, 18 Mar 2022 08:18:44 -0400 [thread overview]
Message-ID: <YjR4pKJtbDuUcsmd@bfoster> (raw)
In-Reply-To: <164755207773.4194202.7639088962184690301.stgit@magnolia>
On Thu, Mar 17, 2022 at 02:21:17PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> Don't spin in an infinite loop trying to reserve blocks -- if we can't
> do it after 30 tries, we're racing with a nearly full filesystem, so
> just give up.
>
> Cc: Brian Foster <bfoster@redhat.com>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
Reviewed-by: Brian Foster <bfoster@redhat.com>
> fs/xfs/xfs_fsops.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
>
> diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
> index b71799a3acd3..4076b9004077 100644
> --- a/fs/xfs/xfs_fsops.c
> +++ b/fs/xfs/xfs_fsops.c
> @@ -379,6 +379,7 @@ xfs_reserve_blocks(
> int64_t fdblks_delta = 0;
> uint64_t request;
> int64_t free;
> + unsigned int tries;
> int error = 0;
>
> /* If inval is null, report current values and return */
> @@ -430,9 +431,16 @@ xfs_reserve_blocks(
> * If the request is larger than the current reservation, reserve the
> * blocks before we update the reserve counters. Sample m_fdblocks and
> * perform a partial reservation if the request exceeds free space.
> + *
> + * The loop body estimates how many blocks it can request from fdblocks
> + * to stash in the reserve pool. This is a classic TOCTOU race since
> + * fdblocks updates are not always coordinated via m_sb_lock. We also
> + * cannot tell if @free remaining unchanged between iterations is due
> + * to an idle system or freed blocks being consumed immediately, so
> + * we'll try a finite number of times to satisfy the request.
> */
> error = -ENOSPC;
> - do {
> + for (tries = 0; tries < 30 && error == -ENOSPC; tries++) {
> /*
> * The reservation pool cannot take space that xfs_mod_fdblocks
> * will not give us.
> @@ -462,7 +470,7 @@ xfs_reserve_blocks(
> spin_unlock(&mp->m_sb_lock);
> error = xfs_mod_fdblocks(mp, -fdblks_delta, 0);
> spin_lock(&mp->m_sb_lock);
> - } while (error == -ENOSPC);
> + }
>
> /*
> * Update the reserve counters if blocks have been successfully
>
next prev parent reply other threads:[~2022-03-18 12:18 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-17 21:20 [PATCHSET v2 0/6] xfs: fix incorrect reserve pool calculations and reporting Darrick J. Wong
2022-03-17 21:21 ` [PATCH 1/6] xfs: document the XFS_ALLOC_AGFL_RESERVE constant Darrick J. Wong
2022-03-18 12:17 ` Brian Foster
2022-03-17 21:21 ` [PATCH 2/6] xfs: actually set aside enough space to handle a bmbt split Darrick J. Wong
2022-03-18 12:17 ` Brian Foster
2022-03-18 20:52 ` Darrick J. Wong
2022-03-17 21:21 ` [PATCH 3/6] xfs: don't include bnobt blocks when reserving free block pool Darrick J. Wong
2022-03-18 12:18 ` Brian Foster
2022-03-18 21:01 ` Darrick J. Wong
2022-03-17 21:21 ` [PATCH 4/6] xfs: fix infinite loop " Darrick J. Wong
2022-03-18 12:18 ` Brian Foster [this message]
2022-03-17 21:21 ` [PATCH 5/6] xfs: don't report reserved bnobt space as available Darrick J. Wong
2022-03-18 12:19 ` Brian Foster
2022-03-18 21:19 ` Darrick J. Wong
2022-03-17 21:21 ` [PATCH 6/6] xfs: rename "alloc_set_aside" to be more descriptive Darrick J. Wong
2022-03-18 12:21 ` Brian Foster
-- strict thread matches above, loose matches on Subject: below --
2022-03-20 16:43 [PATCHSET v3 0/6] xfs: fix incorrect reserve pool calculations and reporting Darrick J. Wong
2022-03-20 16:43 ` [PATCH 4/6] xfs: fix infinite loop when reserving free block pool Darrick J. Wong
2022-03-23 21:11 ` Dave Chinner
2022-03-24 5:24 ` Darrick J. Wong
2022-03-24 6:21 ` Dave Chinner
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=YjR4pKJtbDuUcsmd@bfoster \
--to=bfoster@redhat.com \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--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