You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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" 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
[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]
Although we have check_orphan_item() call inside check_root_refs(), it
relies the root record to have its 'found_root_item' member set.
Otherwise it will not report this as an error.
But that 'found_root_item' is always set to 0, if the subvolume has zero
ref. This means any subvolume with 0 refs will not have its orphan item
checked.
[FIX]
- Introduce root_record::expected_ref to record the refs in the root
item
So that we can properly compare the number of refs for each subvolume
tree.
- Set root_record::found_root_item to one unconditionally in
check_fs_root()
Since we're accessing the fs root through the root item, the root item
must exist, no need to bother if the root_refs is zero or not.
- Enhance check_root_refs()
* Always check if btrfs_root_item::refs match root_record::found_ref
* If the fs tree has no ref, check for the orphan item
Signed-off-by: Qu Wenruo <[email protected]>
0 commit comments