Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <wqu@suse.com>
Cc: Mark Harmstone <mark@harmstone.com>,
	linux-btrfs@vger.kernel.org, fdmanana@kernel.org
Subject: Re: [PATCH 2/2] btrfs: clear spurious free-space entries
Date: Thu, 25 Sep 2025 13:32:22 +0200	[thread overview]
Message-ID: <20250925113222.GO5333@twin.jikos.cz> (raw)
In-Reply-To: <a7ae58b2-6bdc-4f44-bb3f-9068fe51673d@suse.com>

On Wed, Sep 24, 2025 at 06:35:43AM +0930, Qu Wenruo wrote:
> 
> 
> 在 2025/9/24 01:24, Mark Harmstone 写道:
> > Version 6.16.1 of btrfs-progs fixes a broken btrfs check test for
> > spurious entries in the free-space tree, those that don't belong to any
> > block group. Unfortunately mkfs.btrfs had been generating these, meaning
> > that these filesystems will now fail btrfs check.
> > 
> > Add a compat flag BTRFS_FEATURE_COMPAT_NO_SPURIOUS_FREE_SPACE, and if on
> > mount we find this isn't set, clean any spurious entries from the
> > beginning of the free-space tree.
> 
> I found this compat flag a little overkilled.
> 
> Are we really going to introduce a new compat flag every time there is 
> something wrong with the free space tree?

Agreed, the compat flag does not make sense to me in this case.

> > +	ret = btrfs_search_slot(trans, fst, &key, path, 0, 0);
> > +	if (ret < 0)
> > +		goto end_trans;
> > +
> > +	while (true) {
> > +		leaf = path->nodes[0];
> > +		if (path->slots[0] >= btrfs_header_nritems(leaf)) {
> > +			ret = btrfs_next_leaf(fst, path);
> > +			if (ret < 0)
> > +				goto end_trans;
> > +			if (ret > 0)
> > +				break;
> > +			leaf = path->nodes[0];
> > +		}
> > +
> > +		btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
> > +
> > +		bg = btrfs_lookup_first_block_group(fs_info, key.objectid);
> 
> We can do the lookup out of the loop. With a parameter 0 for @bytenr.
> 
> As we just need to delete any entry before the first bg, there is no 
> need to lookup the bg every time.
> 
> Furthermore, since the stale entries are just from the temporary chunks, 
> they should be pretty small, thus we are able to afford the check at 
> every mount.

A one time check per mount sounds like the best solution, it has
negligible cost, compared to compat bits.

      reply	other threads:[~2025-09-25 11:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-23 15:54 [PATCH 1/2] btrfs: add compat flag functions Mark Harmstone
2025-09-23 15:54 ` [PATCH 2/2] btrfs: clear spurious free-space entries Mark Harmstone
2025-09-23 16:35   ` Filipe Manana
2025-09-23 21:05   ` Qu Wenruo
2025-09-25 11:32     ` David Sterba [this message]

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=20250925113222.GO5333@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=mark@harmstone.com \
    --cc=wqu@suse.com \
    /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