path: root/disk-io.c
diff options
authorMark Fasheh <mfasheh@suse.de>2014-05-07 13:07:17 -0700
committerDavid Sterba <dsterba@suse.cz>2014-08-22 14:39:33 +0200
commit96ec888aad41969d728ba62c1778d6e8ebe6bd4e (patch)
tree413ea722f864ba14714ad47a57e479e29ce6d848 /disk-io.c
parent2ab405af95d43972b57c7806981220a6949df643 (diff)
btrfs-progs: add quota group verify code
This patch adds functionality (in qgroup-verify.c) to compute bytecounts in subvolume quota groups. The original groups are read in and stored in memory so that after we compute our own bytecounts, we can compare them with those on disk. A print function is provided to do this comparison and show the results on the console. A 'qgroup check' pass is added to btrfsck. If any subvolume quota groups differ from what we compute, the differences for them are printed. We also provide an option '--qgroup-report' which will run only the quota check code and print a report on all quota groups. Other than making it possible to verify that our qgroup changes work correctly, this mode can also be used in xfstests for automated checking after qgroup tests. This patch does not address the following: - compressed counts are identical to non compressed, because kernel doesn't make the distinction yet. Adding the code to verify compressed counts shouldn't be hard at all though once kernel can do this. - It is only concerned with subvolume quota groups (like most of btrfs-progs). Signed-off-by: Mark Fasheh <mfasheh@suse.de> Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'disk-io.c')
1 files changed, 14 insertions, 2 deletions
diff --git a/disk-io.c b/disk-io.c
index 8db0335..58f3f07 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -569,7 +569,6 @@ static int find_and_setup_log_root(struct btrfs_root *tree_root,
return 0;
int btrfs_free_fs_root(struct btrfs_root *root)
if (root->node)
@@ -695,6 +694,8 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
return fs_info->dev_root;
if (location->objectid == BTRFS_CSUM_TREE_OBJECTID)
return fs_info->csum_root;
+ if (location->objectid == BTRFS_QUOTA_TREE_OBJECTID)
+ return fs_info->csum_root;
BUG_ON(location->objectid == BTRFS_TREE_RELOC_OBJECTID ||
location->offset != (u64)-1);
@@ -721,6 +722,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
+ free(fs_info->quota_root);
@@ -741,11 +743,13 @@ struct btrfs_fs_info *btrfs_new_fs_info(int writable, u64 sb_bytenr)
fs_info->chunk_root = malloc(sizeof(struct btrfs_root));
fs_info->dev_root = malloc(sizeof(struct btrfs_root));
fs_info->csum_root = malloc(sizeof(struct btrfs_root));
+ fs_info->quota_root = malloc(sizeof(struct btrfs_root));
fs_info->super_copy = malloc(BTRFS_SUPER_INFO_SIZE);
if (!fs_info->tree_root || !fs_info->extent_root ||
!fs_info->chunk_root || !fs_info->dev_root ||
- !fs_info->csum_root || !fs_info->super_copy)
+ !fs_info->csum_root || !fs_info->quota_root ||
+ !fs_info->super_copy)
goto free_all;
memset(fs_info->super_copy, 0, BTRFS_SUPER_INFO_SIZE);
@@ -754,6 +758,7 @@ struct btrfs_fs_info *btrfs_new_fs_info(int writable, u64 sb_bytenr)
memset(fs_info->chunk_root, 0, sizeof(struct btrfs_root));
memset(fs_info->dev_root, 0, sizeof(struct btrfs_root));
memset(fs_info->csum_root, 0, sizeof(struct btrfs_root));
+ memset(fs_info->quota_root, 0, sizeof(struct btrfs_root));
@@ -912,6 +917,11 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
fs_info->csum_root->track_dirty = 1;
+ ret = find_and_setup_root(root, fs_info, BTRFS_QUOTA_TREE_OBJECTID,
+ fs_info->quota_root);
+ if (ret == 0)
+ fs_info->quota_enabled = 1;
ret = find_and_setup_log_root(root, fs_info, sb);
if (ret) {
printk("Couldn't setup log root tree\n");
@@ -936,6 +946,8 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
void btrfs_release_all_roots(struct btrfs_fs_info *fs_info)
+ if (fs_info->quota_root)
+ free_extent_buffer(fs_info->quota_root->node);
if (fs_info->csum_root)
if (fs_info->dev_root)