btrfs: qgroup: Switch self test to extent-oriented qgroup mechanism.
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Thu, 16 Apr 2015 09:18:36 +0000 (17:18 +0800)
committerChris Mason <clm@fb.com>
Wed, 10 Jun 2015 16:26:05 +0000 (09:26 -0700)
Since the self test transaction don't have delayed_ref_roots, so use
find_all_roots() and export btrfs_qgroup_account_extent() to simulate it

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/qgroup.c
fs/btrfs/qgroup.h
fs/btrfs/tests/qgroup-tests.c

index 70c366f..693533d 100644 (file)
@@ -2455,7 +2455,7 @@ static int btrfs_qgroup_account(struct btrfs_trans_handle *trans,
        return ret;
 }
 
-static int
+int
 btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
                            struct btrfs_fs_info *fs_info,
                            u64 bytenr, u64 num_bytes,
index cb703f8..90998b5 100644 (file)
@@ -103,6 +103,11 @@ int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans,
 struct btrfs_qgroup_extent_record
 *btrfs_qgroup_insert_dirty_extent(struct btrfs_delayed_ref_root *delayed_refs,
                                  struct btrfs_qgroup_extent_record *record);
+int
+btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
+                           struct btrfs_fs_info *fs_info,
+                           u64 bytenr, u64 num_bytes,
+                           struct ulist *old_roots, struct ulist *new_roots);
 int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans,
                                 struct btrfs_fs_info *fs_info);
 int btrfs_delayed_qgroup_accounting(struct btrfs_trans_handle *trans,
index c32a7ba..846d277 100644 (file)
@@ -21,6 +21,7 @@
 #include "../transaction.h"
 #include "../disk-io.h"
 #include "../qgroup.h"
+#include "../backref.h"
 
 static void init_dummy_trans(struct btrfs_trans_handle *trans)
 {
@@ -227,6 +228,8 @@ static int test_no_shared_qgroup(struct btrfs_root *root)
 {
        struct btrfs_trans_handle trans;
        struct btrfs_fs_info *fs_info = root->fs_info;
+       struct ulist *old_roots = NULL;
+       struct ulist *new_roots = NULL;
        int ret;
 
        init_dummy_trans(&trans);
@@ -238,10 +241,15 @@ static int test_no_shared_qgroup(struct btrfs_root *root)
                return ret;
        }
 
-       ret = btrfs_qgroup_record_ref(&trans, fs_info, 5, 4096, 4096,
-                                     BTRFS_QGROUP_OPER_ADD_EXCL, 0);
+       /*
+        * Since the test trans doesn't havee the complicated delayed refs,
+        * we can only call btrfs_qgroup_account_extent() directly to test
+        * quota.
+        */
+       ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots);
        if (ret) {
-               test_msg("Couldn't add space to a qgroup %d\n", ret);
+               ulist_free(old_roots);
+               test_msg("Couldn't find old roots: %d\n", ret);
                return ret;
        }
 
@@ -249,9 +257,18 @@ static int test_no_shared_qgroup(struct btrfs_root *root)
        if (ret)
                return ret;
 
-       ret = btrfs_delayed_qgroup_accounting(&trans, fs_info);
+       ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots);
+       if (ret) {
+               ulist_free(old_roots);
+               ulist_free(new_roots);
+               test_msg("Couldn't find old roots: %d\n", ret);
+               return ret;
+       }
+
+       ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096,
+                                         old_roots, new_roots);
        if (ret) {
-               test_msg("Delayed qgroup accounting failed %d\n", ret);
+               test_msg("Couldn't account space for a qgroup %d\n", ret);
                return ret;
        }
 
@@ -259,21 +276,32 @@ static int test_no_shared_qgroup(struct btrfs_root *root)
                test_msg("Qgroup counts didn't match expected values\n");
                return -EINVAL;
        }
+       old_roots = NULL;
+       new_roots = NULL;
+
+       ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots);
+       if (ret) {
+               ulist_free(old_roots);
+               test_msg("Couldn't find old roots: %d\n", ret);
+               return ret;
+       }
 
        ret = remove_extent_item(root, 4096, 4096);
        if (ret)
                return -EINVAL;
 
-       ret = btrfs_qgroup_record_ref(&trans, fs_info, 5, 4096, 4096,
-                                     BTRFS_QGROUP_OPER_SUB_EXCL, 0);
+       ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots);
        if (ret) {
-               test_msg("Couldn't remove space from the qgroup %d\n", ret);
-               return -EINVAL;
+               ulist_free(old_roots);
+               ulist_free(new_roots);
+               test_msg("Couldn't find old roots: %d\n", ret);
+               return ret;
        }
 
-       ret = btrfs_delayed_qgroup_accounting(&trans, fs_info);
+       ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096,
+                                         old_roots, new_roots);
        if (ret) {
-               test_msg("Qgroup accounting failed %d\n", ret);
+               test_msg("Couldn't account space for a qgroup %d\n", ret);
                return -EINVAL;
        }
 
@@ -294,6 +322,8 @@ static int test_multiple_refs(struct btrfs_root *root)
 {
        struct btrfs_trans_handle trans;
        struct btrfs_fs_info *fs_info = root->fs_info;
+       struct ulist *old_roots = NULL;
+       struct ulist *new_roots = NULL;
        int ret;
 
        init_dummy_trans(&trans);
@@ -307,20 +337,29 @@ static int test_multiple_refs(struct btrfs_root *root)
                return ret;
        }
 
+       ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots);
+       if (ret) {
+               ulist_free(old_roots);
+               test_msg("Couldn't find old roots: %d\n", ret);
+               return ret;
+       }
+
        ret = insert_normal_tree_ref(root, 4096, 4096, 0, 5);
        if (ret)
                return ret;
 
-       ret = btrfs_qgroup_record_ref(&trans, fs_info, 5, 4096, 4096,
-                                     BTRFS_QGROUP_OPER_ADD_EXCL, 0);
+       ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots);
        if (ret) {
-               test_msg("Couldn't add space to a qgroup %d\n", ret);
+               ulist_free(old_roots);
+               ulist_free(new_roots);
+               test_msg("Couldn't find old roots: %d\n", ret);
                return ret;
        }
 
-       ret = btrfs_delayed_qgroup_accounting(&trans, fs_info);
+       ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096,
+                                         old_roots, new_roots);
        if (ret) {
-               test_msg("Delayed qgroup accounting failed %d\n", ret);
+               test_msg("Couldn't account space for a qgroup %d\n", ret);
                return ret;
        }
 
@@ -329,20 +368,29 @@ static int test_multiple_refs(struct btrfs_root *root)
                return -EINVAL;
        }
 
+       ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots);
+       if (ret) {
+               ulist_free(old_roots);
+               test_msg("Couldn't find old roots: %d\n", ret);
+               return ret;
+       }
+
        ret = add_tree_ref(root, 4096, 4096, 0, 256);
        if (ret)
                return ret;
 
-       ret = btrfs_qgroup_record_ref(&trans, fs_info, 256, 4096, 4096,
-                                     BTRFS_QGROUP_OPER_ADD_SHARED, 0);
+       ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots);
        if (ret) {
-               test_msg("Qgroup record ref failed %d\n", ret);
+               ulist_free(old_roots);
+               ulist_free(new_roots);
+               test_msg("Couldn't find old roots: %d\n", ret);
                return ret;
        }
 
-       ret = btrfs_delayed_qgroup_accounting(&trans, fs_info);
+       ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096,
+                                         old_roots, new_roots);
        if (ret) {
-               test_msg("Qgroup accounting failed %d\n", ret);
+               test_msg("Couldn't account space for a qgroup %d\n", ret);
                return ret;
        }
 
@@ -356,20 +404,29 @@ static int test_multiple_refs(struct btrfs_root *root)
                return -EINVAL;
        }
 
+       ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &old_roots);
+       if (ret) {
+               ulist_free(old_roots);
+               test_msg("Couldn't find old roots: %d\n", ret);
+               return ret;
+       }
+
        ret = remove_extent_ref(root, 4096, 4096, 0, 256);
        if (ret)
                return ret;
 
-       ret = btrfs_qgroup_record_ref(&trans, fs_info, 256, 4096, 4096,
-                                     BTRFS_QGROUP_OPER_SUB_SHARED, 0);
+       ret = btrfs_find_all_roots(&trans, fs_info, 4096, 0, &new_roots);
        if (ret) {
-               test_msg("Qgroup record ref failed %d\n", ret);
+               ulist_free(old_roots);
+               ulist_free(new_roots);
+               test_msg("Couldn't find old roots: %d\n", ret);
                return ret;
        }
 
-       ret = btrfs_delayed_qgroup_accounting(&trans, fs_info);
+       ret = btrfs_qgroup_account_extent(&trans, fs_info, 4096, 4096,
+                                         old_roots, new_roots);
        if (ret) {
-               test_msg("Qgroup accounting failed %d\n", ret);
+               test_msg("Couldn't account space for a qgroup %d\n", ret);
                return ret;
        }