Commit 570c80c
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 <boris@bur.io>
Signed-off-by: Qu Wenruo <wqu@suse.com>1 parent b664933 commit 570c80c
1 file changed
+11
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5502 | 5502 | | |
5503 | 5503 | | |
5504 | 5504 | | |
| 5505 | + | |
| 5506 | + | |
| 5507 | + | |
| 5508 | + | |
| 5509 | + | |
| 5510 | + | |
| 5511 | + | |
| 5512 | + | |
| 5513 | + | |
| 5514 | + | |
| 5515 | + | |
5505 | 5516 | | |
5506 | 5517 | | |
5507 | 5518 | | |
| |||
0 commit comments