Skip to content

Commit 1164c01

Browse files
committed
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 96d5e91 commit 1164c01

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

check/main.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8593,6 +8593,7 @@ static int check_device_used(struct device_record *dev_rec,
85938593
if (opt_check_repair) {
85948594
ret = repair_dev_item_bytes_used(gfs_info,
85958595
dev_rec->devid, total_byte);
8596+
dev_rec->byte_used = total_byte;
85968597
}
85978598
return ret;
85988599
} else {
@@ -8650,6 +8651,30 @@ static bool is_super_size_valid(void)
86508651
return true;
86518652
}
86528653

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

0 commit comments

Comments
 (0)