Skip to contentSkip to conversation

btrfs: show correct warning if can't read data reloc tree

PATCH In review Mark Harmstone 3 participants 3 messages Dec 19, 2025 – Dec 20, 2025 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: show correct warning if can't read data reloc tree

If a filesystem is missing its data reloc tree, we get something like this in dmesg:

BTRFS warning (device loop11): failed to read root (objectid=4): -2 BTRFS error (device loop11): open_ctree failed: -2

objectid is BTRFS_DEV_TREE_OBJECTID, but this should actually be the value of BTRFS_DATA_RELOC_TREE_OBJECTID.

btrfs_read_roots() prints location.objectid on failure, but this isn't set when reading the data reloc tree. Set location.objectid to the correct value on failure, so that the error message makes sense.

---
 fs/btrfs/disk-io.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/disk-io.c +1 -0
index e5535bdc5b0c..f1e58c1d6c38 100644
@@ -2221,6 +2221,7 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
 				 BTRFS_DATA_RELOC_TREE_OBJECTID, true);
 	if (IS_ERR(root)) {
 		if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) {
+			location.objectid = BTRFS_DATA_RELOC_TREE_OBJECTID;
 			ret = PTR_ERR(root);
 			goto out;
 		}
Signature · 1 line
2.51.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Mark Harmstone

If a filesystem is missing its data reloc tree, we get something like this in dmesg:

BTRFS warning (device loop11): failed to read root (objectid=4): -2 BTRFS error (device loop11): open_ctree failed: -2

Quoted 8 lines

objectid is BTRFS_DEV_TREE_OBJECTID, but this should actually be the value of BTRFS_DATA_RELOC_TREE_OBJECTID.

btrfs_read_roots() prints location.objectid on failure, but this isn't set when reading the data reloc tree. Set location.objectid to the correct value on failure, so that the error message makes sense.

Thanks,
Qu

Quoted 16 lines
---
  fs/btrfs/disk-io.c | 1 +
  1 file changed, 1 insertion(+)
fs/btrfs/disk-io.c +1 -0
index e5535bdc5b0c..f1e58c1d6c38 100644
@@ -2221,6 +2221,7 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
  				 BTRFS_DATA_RELOC_TREE_OBJECTID, true);
  	if (IS_ERR(root)) {
  		if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) {
+			location.objectid = BTRFS_DATA_RELOC_TREE_OBJECTID;
  			ret = PTR_ERR(root);
  			goto out;
  		}
#2 lore raw
In reply to Mark Harmstone
Quoted 6 lines · Mark Harmstone

If a filesystem is missing its data reloc tree, we get something like this in dmesg:

BTRFS warning (device loop11): failed to read root (objectid=4): -2 BTRFS error (device loop11): open_ctree failed: -2

Quoted 8 lines

objectid is BTRFS_DEV_TREE_OBJECTID, but this should actually be the value of BTRFS_DATA_RELOC_TREE_OBJECTID.

btrfs_read_roots() prints location.objectid on failure, but this isn't set when reading the data reloc tree. Set location.objectid to the correct value on failure, so that the error message makes sense.

Added to for-next, thanks.