Skip to content

Commit 19a411b

Browse files
maharmstoneadam900710
authored andcommitted
btrfs-progs: check that device byte values in superblock match those in chunk root
The superblock of each device contains a copy of the corresponding struct btrfs_dev_item that lives in the chunk root. Add a check that the total_bytes and bytes_used values of these two copies match. Signed-off-by: Mark Harmstone <[email protected]>
1 parent b4eefe1 commit 19a411b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

check/main.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8650,6 +8650,30 @@ static bool is_super_size_valid(void)
86508650
return true;
86518651
}
86528652

8653+
static int check_super_dev_item(struct device_record *dev_rec)
8654+
{
8655+
struct btrfs_dev_item *super_di = &gfs_info->super_copy->dev_item;
8656+
int ret = 0;
8657+
8658+
if (btrfs_stack_device_total_bytes(super_di) != dev_rec->total_byte) {
8659+
fprintf(stderr,
8660+
"device %llu's total_bytes was %llu in tree but %llu in superblock\n",
8661+
dev_rec->devid, dev_rec->total_byte,
8662+
btrfs_stack_device_total_bytes(super_di));
8663+
ret = 1;
8664+
}
8665+
8666+
if (btrfs_stack_device_bytes_used(super_di) != dev_rec->byte_used) {
8667+
fprintf(stderr,
8668+
"device %llu's bytes_used was %llu in tree but %llu in superblock\n",
8669+
dev_rec->devid, dev_rec->byte_used,
8670+
btrfs_stack_device_bytes_used(super_di));
8671+
ret = 1;
8672+
}
8673+
8674+
return ret;
8675+
}
8676+
86538677
/* check btrfs_dev_item -> btrfs_dev_extent */
86548678
static int check_devices(struct rb_root *dev_cache,
86558679
struct device_extent_tree *dev_extent_cache)
@@ -8671,6 +8695,13 @@ static int check_devices(struct rb_root *dev_cache,
86718695
gfs_info->sectorsize);
86728696
if (dev_rec->bad_block_dev_size && !ret)
86738697
ret = 1;
8698+
8699+
if (dev_rec->devid == gfs_info->super_copy->dev_item.devid) {
8700+
err = check_super_dev_item(dev_rec);
8701+
if (err)
8702+
ret = err;
8703+
}
8704+
86748705
dev_node = rb_next(dev_node);
86758706
}
86768707
list_for_each_entry(dext_rec, &dev_extent_cache->no_device_orphans,

0 commit comments

Comments
 (0)