Skip to content

Commit 570c80c

Browse files
committed
btrfs-progs: check/lowmem: detect missing orphan items correctly
[BUG] If we have a filesystem with a subvolume that has 0 refs but without an orphan item, btrfs check won't report any error on it. $ btrfs ins dump-tree -t root /dev/test/scratch1 btrfs-progs v6.15 root tree node 5242880 level 1 items 2 free space 119 generation 11 owner ROOT_TREE node 5242880 flags 0x1(WRITTEN) backref revision 1 fs uuid ff32309e-4e90-4402-b1ef-0a1f9f28bfff chunk uuid 6c373b6d-c866-4c8c-81fa-608bf5ef25e3 key (EXTENT_TREE ROOT_ITEM 0) block 5267456 gen 11 key (ROOT_TREE_DIR DIR_ITEM 2378154706) block 5246976 gen 11 leaf 5267456 items 6 free space 2339 generation 11 owner ROOT_TREE leaf 5267456 flags 0x1(WRITTEN) backref revision 1 fs uuid ff32309e-4e90-4402-b1ef-0a1f9f28bfff [...] leaf 5246976 items 6 free space 1613 generation 11 owner ROOT_TREE leaf 5246976 flags 0x1(WRITTEN) backref revision 1 checksum stored 47620783 checksum calced 47620783 fs uuid ff32309e-4e90-4402-b1ef-0a1f9f28bfff chunk uuid 6c373b6d-c866-4c8c-81fa-608bf5ef25e3 [...] item 4 key (256 ROOT_ITEM 0) itemoff 2202 itemsize 439 generation 9 root_dirid 256 bytenr 5898240 byte_limit 0 bytes_used 581632 last_snapshot 0 flags 0x1000000000000(none) refs 0 <<< drop_progress key (0 UNKNOWN.0 0) drop_level 0 level 2 generation_v2 9 item 5 key (DATA_RELOC_TREE ROOT_ITEM 0) itemoff 1763 itemsize 439 generation 5 root_dirid 256 bytenr 5287936 byte_limit 0 bytes_used 4096 last_snapshot 0 flags 0x0(none) refs 1 drop_progress key (0 UNKNOWN.0 0) drop_level 0 level 0 generation_v2 5 ^^^ No orphan item for subvolume 256. Then "btrfs check --mode=lowmem" will not report anything wrong with it: Opening filesystem to check... Checking filesystem on /dev/test/scratch1 UUID: ff32309e-4e90-4402-b1ef-0a1f9f28bfff [1/8] checking log skipped (none written) [2/8] checking root items [3/8] checking extents [4/8] checking free space tree [5/8] checking fs roots [6/8] checking only csums items (without verifying data) [7/8] checking root refs done with fs roots in lowmem mode, skipping [8/8] checking quota groups skipped (not enabled on this FS) found 638976 bytes used, no error found << total csum bytes: 0 total tree bytes: 638976 total fs tree bytes: 589824 total extent tree bytes: 16384 btree space waste bytes: 289501 file data blocks allocated: 0 referenced 0 [CAUSE] In lowmem's check_btrfs_root() we have no special handling for refs 0, as long as there is no ROOT_BACKREF for the orphan root, everything will be reported as OK. But we should expect an orphan item for an orphan subvolume, this means lowmem doesn't do any checks against the orphan item for a subvolume. [FIX] For subvolume trees, if its refs is 0, also check if we have an orphan item for it. If not, report this as an error. Reviewed-by: Boris Burkov <[email protected]> Signed-off-by: Qu Wenruo <[email protected]>
1 parent b664933 commit 570c80c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

check/mode-lowmem.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5502,6 +5502,17 @@ static int check_btrfs_root(struct btrfs_root *root, int check_all)
55025502
}
55035503
}
55045504
}
5505+
/*
5506+
* If this tree is a subvolume (not a reloc tree) and has no refs, there
5507+
* should be an orphan item for it, or this subvolume will never be deleted.
5508+
*/
5509+
if (btrfs_root_refs(root_item) == 0 && is_fstree(btrfs_root_id(root))) {
5510+
if (!has_orphan_item(root->fs_info->tree_root,
5511+
btrfs_root_id(root))) {
5512+
error("missing orphan item for root %lld", btrfs_root_id(root));
5513+
err |= REFERENCER_MISSING;
5514+
}
5515+
}
55055516
if (btrfs_root_refs(root_item) > 0 ||
55065517
btrfs_disk_key_objectid(&root_item->drop_progress) == 0) {
55075518
path.nodes[level] = root->node;

0 commit comments

Comments
 (0)