Skip to content

Conversation

adam900710
Copy link
Collaborator

Currently any orphan device extents will cause kernels to reject the mount.

But on the other hand, btrfs check is unable to repair such problem, so end users may fall into a situation where they are unable to mount the fs.

Add the repair functionality to btrfs check, for both original lowmem modes, and add a new test case for it.

There is a bug report that btrfs-check --repair didn't repair an orphan
dev extent, which makes kernel to reject the fs due to the overly strict
chunk related checks.

However for btrfs-check, it's pretty easy to remove orphan device
extents (which do not have corresponding chunks), and update the device
item to reflect the used_bytes changes.

Add a repair function, btrfs_remove_dev_extent() which does the repair,
and call that function for both original and lowmem modes.

Signed-off-by: Qu Wenruo <[email protected]>
The fs has the following chunk tree (minor members removed):

	item 0 key (DEV_ITEMS DEV_ITEM 1) itemoff 16185 itemsize 98
		devid 1 total_bytes 536870912 bytes_used 159383552
		io_align 4096 io_width 4096 sector_size 4096 type 0
	item 1 key (FIRST_CHUNK_TREE CHUNK_ITEM 13631488) itemoff 16105 itemsize 80
		length 8388608 owner 2 stripe_len 65536 type DATA|single
		io_align 65536 io_width 65536 sector_size 4096
		num_stripes 1 sub_stripes 1
	item 2 key (FIRST_CHUNK_TREE CHUNK_ITEM 22020096) itemoff 15993 itemsize 112
		length 8388608 owner 2 stripe_len 65536 type SYSTEM|DUP
		io_align 65536 io_width 65536 sector_size 4096
	item 3 key (FIRST_CHUNK_TREE CHUNK_ITEM 30408704) itemoff 15881 itemsize 112
		length 33554432 owner 2 stripe_len 65536 type METADATA|DUP
		io_align 65536 io_width 65536 sector_size 4096

And the following dev tree:

	item 0 key (DEV_STATS PERSISTENT_ITEM 1) itemoff 16243 itemsize 40
		persistent item objectid DEV_STATS offset 1
		device stats
		write_errs 0 read_errs 0 flush_errs 0 corruption_errs 0 generation 0
	item 1 key (1 DEV_EXTENT 13631488) itemoff 16195 itemsize 48
	item 2 key (1 DEV_EXTENT 22020096) itemoff 16147 itemsize 48
	item 3 key (1 DEV_EXTENT 30408704) itemoff 16099 itemsize 48
	item 4 key (1 DEV_EXTENT 38797312) itemoff 16051 itemsize 48
	item 5 key (1 DEV_EXTENT 72351744) itemoff 16003 itemsize 48
	item 6 key (1 DEV_EXTENT 105906176) itemoff 15955 itemsize 48
		dev extent chunk_tree 3
		chunk_objectid 256 chunk_offset 63963136 length 67108864
		chunk_tree_uuid b2408431-a79a-42b6-aadc-4e853d4caa82

Notice the last dev_extent item, which has no corresponding chunk.

The image is created by calling btrfs_insert_dev_extent(), then
btrfs_update_device() to update dev->bytes_used.

This image can be repaired by both original and lowmem modes.

Signed-off-by: Qu Wenruo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant