Skip to content

btrfs-progs: check that device byte values in superblock match those in chunk root #991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions check/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8593,6 +8593,7 @@ static int check_device_used(struct device_record *dev_rec,
if (opt_check_repair) {
ret = repair_dev_item_bytes_used(gfs_info,
dev_rec->devid, total_byte);
dev_rec->byte_used = total_byte;
}
return ret;
} else {
Expand Down Expand Up @@ -8650,6 +8651,30 @@ static bool is_super_size_valid(void)
return true;
}

static int check_super_dev_item(struct device_record *dev_rec)
{
struct btrfs_dev_item *super_di = &gfs_info->super_copy->dev_item;
int ret = 0;

if (btrfs_stack_device_total_bytes(super_di) != dev_rec->total_byte) {
fprintf(stderr,
"device %llu's total_bytes was %llu in tree but %llu in superblock\n",
dev_rec->devid, dev_rec->total_byte,
btrfs_stack_device_total_bytes(super_di));
ret = 1;
}

if (btrfs_stack_device_bytes_used(super_di) != dev_rec->byte_used) {
fprintf(stderr,
"device %llu's bytes_used was %llu in tree but %llu in superblock\n",
dev_rec->devid, dev_rec->byte_used,
btrfs_stack_device_bytes_used(super_di));
ret = 1;
}

return ret;
}

/* check btrfs_dev_item -> btrfs_dev_extent */
static int check_devices(struct rb_root *dev_cache,
struct device_extent_tree *dev_extent_cache)
Expand All @@ -8671,6 +8696,13 @@ static int check_devices(struct rb_root *dev_cache,
gfs_info->sectorsize);
if (dev_rec->bad_block_dev_size && !ret)
ret = 1;

if (dev_rec->devid == gfs_info->super_copy->dev_item.devid) {
err = check_super_dev_item(dev_rec);
if (err)
ret = err;
}

dev_node = rb_next(dev_node);
}
list_for_each_entry(dext_rec, &dev_extent_cache->no_device_orphans,
Expand Down
Loading