Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs: do not reject a valid running dev-replace
@ 2026-03-31 23:02 Qu Wenruo
  2026-04-01  0:17 ` David Sterba
  2026-04-01 13:09 ` Anand Jain
  0 siblings, 2 replies; 3+ messages in thread
From: Qu Wenruo @ 2026-03-31 23:02 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Jaron Viëtor

[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>
---
 fs/btrfs/volumes.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 33fa73668534..d8f2722311c8 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -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));
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: do not reject a valid running dev-replace
  2026-03-31 23:02 [PATCH] btrfs: do not reject a valid running dev-replace Qu Wenruo
@ 2026-04-01  0:17 ` David Sterba
  2026-04-01 13:09 ` Anand Jain
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2026-04-01  0:17 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, Jaron Viëtor

On Wed, Apr 01, 2026 at 09:32:57AM +1030, Qu Wenruo wrote:
> [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>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: do not reject a valid running dev-replace
  2026-03-31 23:02 [PATCH] btrfs: do not reject a valid running dev-replace Qu Wenruo
  2026-04-01  0:17 ` David Sterba
@ 2026-04-01 13:09 ` Anand Jain
  1 sibling, 0 replies; 3+ messages in thread
From: Anand Jain @ 2026-04-01 13:09 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs; +Cc: Jaron Viëtor


looks good

Reviewed-by: Anand Jain <asj@kernel.org>


On 1/4/26 07:02, Qu Wenruo wrote:
> [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>
> ---
>  fs/btrfs/volumes.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 33fa73668534..d8f2722311c8 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -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));


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-01 13:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-31 23:02 [PATCH] btrfs: do not reject a valid running dev-replace Qu Wenruo
2026-04-01  0:17 ` David Sterba
2026-04-01 13:09 ` Anand Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox