btrfs: tests: pass fs_info to extent_map tests
authorDavid Sterba <dsterba@suse.com>
Tue, 3 Apr 2018 19:55:17 +0000 (21:55 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 28 May 2018 16:07:17 +0000 (18:07 +0200)
Preparatory work to pass fs_info to btrfs_add_extent_mapping so we can
get a better tracepoint message. Extent maps do not need fs_info for
anything so we only add a dummy one without any other initialization.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/tests/extent-map-tests.c

index 79e0a5f4d9c9a591e02f0a9854e9b09721170ffc..8a39de4453e43edf8cc897a6c28455344caec6de 100644 (file)
@@ -47,7 +47,8 @@ static void free_extent_map_tree(struct extent_map_tree *em_tree)
  *                                    ->add_extent_mapping(0, 16K)
  *                                    -> #handle -EEXIST
  */
-static void test_case_1(struct extent_map_tree *em_tree)
+static void test_case_1(struct btrfs_fs_info *fs_info,
+               struct extent_map_tree *em_tree)
 {
        struct extent_map *em;
        u64 start = 0;
@@ -112,7 +113,8 @@ out:
  * Reading the inline ending up with EEXIST, ie. read an inline
  * extent and discard page cache and read it again.
  */
-static void test_case_2(struct extent_map_tree *em_tree)
+static void test_case_2(struct btrfs_fs_info *fs_info,
+               struct extent_map_tree *em_tree)
 {
        struct extent_map *em;
        int ret;
@@ -169,7 +171,8 @@ out:
        free_extent_map_tree(em_tree);
 }
 
-static void __test_case_3(struct extent_map_tree *em_tree, u64 start)
+static void __test_case_3(struct btrfs_fs_info *fs_info,
+               struct extent_map_tree *em_tree, u64 start)
 {
        struct extent_map *em;
        u64 len = SZ_4K;
@@ -235,14 +238,16 @@ out:
  *   -> add_extent_mapping()
  *                            -> add_extent_mapping()
  */
-static void test_case_3(struct extent_map_tree *em_tree)
+static void test_case_3(struct btrfs_fs_info *fs_info,
+               struct extent_map_tree *em_tree)
 {
-       __test_case_3(em_tree, 0);
-       __test_case_3(em_tree, SZ_8K);
-       __test_case_3(em_tree, (12 * 1024ULL));
+       __test_case_3(fs_info, em_tree, 0);
+       __test_case_3(fs_info, em_tree, SZ_8K);
+       __test_case_3(fs_info, em_tree, (12 * 1024ULL));
 }
 
-static void __test_case_4(struct extent_map_tree *em_tree, u64 start)
+static void __test_case_4(struct btrfs_fs_info *fs_info,
+               struct extent_map_tree *em_tree, u64 start)
 {
        struct extent_map *em;
        u64 len = SZ_4K;
@@ -324,30 +329,45 @@ out:
  *                                             # handle -EEXIST when adding
  *                                             # [0, 32K)
  */
-static void test_case_4(struct extent_map_tree *em_tree)
+static void test_case_4(struct btrfs_fs_info *fs_info,
+               struct extent_map_tree *em_tree)
 {
-       __test_case_4(em_tree, 0);
-       __test_case_4(em_tree, SZ_4K);
+       __test_case_4(fs_info, em_tree, 0);
+       __test_case_4(fs_info, em_tree, SZ_4K);
 }
 
 int btrfs_test_extent_map(void)
 {
+       struct btrfs_fs_info *fs_info = NULL;
        struct extent_map_tree *em_tree;
 
        test_msg("Running extent_map tests\n");
 
+       /*
+        * Note: the fs_info is not set up completely, we only need
+        * fs_info::fsid for the tracepoint.
+        */
+       fs_info = btrfs_alloc_dummy_fs_info(PAGE_SIZE, PAGE_SIZE);
+       if (!fs_info) {
+               test_msg("Couldn't allocate dummy fs info\n");
+               return -ENOMEM;
+       }
+
        em_tree = kzalloc(sizeof(*em_tree), GFP_KERNEL);
        if (!em_tree)
                /* Skip the test on error. */
-               return 0;
+               goto out;
 
        extent_map_tree_init(em_tree);
 
-       test_case_1(em_tree);
-       test_case_2(em_tree);
-       test_case_3(em_tree);
-       test_case_4(em_tree);
+       test_case_1(fs_info, em_tree);
+       test_case_2(fs_info, em_tree);
+       test_case_3(fs_info, em_tree);
+       test_case_4(fs_info, em_tree);
 
        kfree(em_tree);
+out:
+       btrfs_free_dummy_fs_info(fs_info);
+
        return 0;
 }