]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: do not reject a valid running dev-replace
authorQu Wenruo <wqu@suse.com>
Tue, 31 Mar 2026 23:02:57 +0000 (09:32 +1030)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 Apr 2026 16:56:08 +0000 (18:56 +0200)
[BUG]
There is a bug report that a btrfs with running dev-replace got rejected
with the following messages:

  BTRFS error (device sdk1): devid 0 path /dev/sdk1 is registered but not found in chunk tree
  BTRFS error (device sdk1): remove the above devices or use 'btrfs device scan --forget <dev>' to unregister them before mount
  BTRFS error (device sdk1): open_ctree failed: -117

[CAUSE]
The tree and super block dumps show the fs is completely sane, except
one thing, there is no dev item for devid 0 in chunk tree.

However this is not a bug, as we do not insert dev item for devid 0 in
the first place.
Since the devid 0 is only there temporarily we do not really need to
insert a dev item for it and then later remove it again.

It is the commit 34308187395f ("btrfs: add extra device item checks at
mount") adding a overly strict check that triggers a false alert and
rejected the valid filesystem.

[FIX]
Add a special handling for devid 0, and doesn't require devid 0 to
have a device item in chunk tree.

Reported-by: Jaron Viƫtor <jaron@vietors.com>
Link: https://lore.kernel.org/linux-btrfs/CAF1bhLVYLZvD=j2XyuxXDKD-NWNJAwDnpVN+UYeQW-HbzNRn1A@mail.gmail.com/
Fixes: 34308187395f ("btrfs: add extra device item checks at mount")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c

index 33fa7366853474f09e7f506da49d0ffba5bc5feb..d8f2722311c88ba8a4ec1d005c8d7ea4549d4fd4 100644 (file)
@@ -8667,7 +8667,12 @@ bool btrfs_verify_dev_items(const struct btrfs_fs_info *fs_info)
 
        mutex_lock(&uuid_mutex);
        list_for_each_entry(dev, &fs_info->fs_devices->devices, dev_list) {
-               if (!test_bit(BTRFS_DEV_STATE_ITEM_FOUND, &dev->dev_state)) {
+               /*
+                * Replace target dev item (devid 0) is not inserted into chunk tree.
+                * So skip the DEV_STATE_ITEM check.
+                */
+               if (dev->devid != BTRFS_DEV_REPLACE_DEVID &&
+                   !test_bit(BTRFS_DEV_STATE_ITEM_FOUND, &dev->dev_state)) {
                        btrfs_err(fs_info,
                        "devid %llu path %s is registered but not found in chunk tree",
                                  dev->devid, btrfs_dev_name(dev));