Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

btrfs: selftests: Add support for dummy devices

Add basic infrastructure to create and link dummy btrfs_devices. This
will be used in the pending btrfs_rmap_block test which deals with
the block groups.

Calling btrfs_alloc_dummy_device will link the newly created device to
the passed fs_info and the test framework will free them once the test
is finished.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Nikolay Borisov and committed by
David Sterba
b3ad2c17 96a14336

+30
+29
fs/btrfs/tests/btrfs-tests.c
··· 86 86 unregister_filesystem(&test_type); 87 87 } 88 88 89 + struct btrfs_device *btrfs_alloc_dummy_device(struct btrfs_fs_info *fs_info) 90 + { 91 + struct btrfs_device *dev; 92 + 93 + dev = kzalloc(sizeof(*dev), GFP_KERNEL); 94 + if (!dev) 95 + return ERR_PTR(-ENOMEM); 96 + 97 + extent_io_tree_init(NULL, &dev->alloc_state, 0, NULL); 98 + INIT_LIST_HEAD(&dev->dev_list); 99 + list_add(&dev->dev_list, &fs_info->fs_devices->devices); 100 + 101 + return dev; 102 + } 103 + 104 + static void btrfs_free_dummy_device(struct btrfs_device *dev) 105 + { 106 + extent_io_tree_release(&dev->alloc_state); 107 + kfree(dev); 108 + } 109 + 89 110 struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize) 90 111 { 91 112 struct btrfs_fs_info *fs_info = kzalloc(sizeof(struct btrfs_fs_info), ··· 153 132 INIT_LIST_HEAD(&fs_info->dirty_qgroups); 154 133 INIT_LIST_HEAD(&fs_info->dead_roots); 155 134 INIT_LIST_HEAD(&fs_info->tree_mod_seq_list); 135 + INIT_LIST_HEAD(&fs_info->fs_devices->devices); 156 136 INIT_RADIX_TREE(&fs_info->buffer_radix, GFP_ATOMIC); 157 137 INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC); 158 138 extent_io_tree_init(fs_info, &fs_info->freed_extents[0], 159 139 IO_TREE_FS_INFO_FREED_EXTENTS0, NULL); 160 140 extent_io_tree_init(fs_info, &fs_info->freed_extents[1], 161 141 IO_TREE_FS_INFO_FREED_EXTENTS1, NULL); 142 + extent_map_tree_init(&fs_info->mapping_tree); 162 143 fs_info->pinned_extents = &fs_info->freed_extents[0]; 163 144 set_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state); 164 145 ··· 173 150 { 174 151 struct radix_tree_iter iter; 175 152 void **slot; 153 + struct btrfs_device *dev, *tmp; 176 154 177 155 if (!fs_info) 178 156 return; ··· 204 180 } 205 181 spin_unlock(&fs_info->buffer_lock); 206 182 183 + btrfs_mapping_tree_free(&fs_info->mapping_tree); 184 + list_for_each_entry_safe(dev, tmp, &fs_info->fs_devices->devices, 185 + dev_list) { 186 + btrfs_free_dummy_device(dev); 187 + } 207 188 btrfs_free_qgroup_config(fs_info); 208 189 btrfs_free_fs_roots(fs_info); 209 190 cleanup_srcu_struct(&fs_info->subvol_srcu);
+1
fs/btrfs/tests/btrfs-tests.h
··· 46 46 void btrfs_free_dummy_block_group(struct btrfs_block_group *cache); 47 47 void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans, 48 48 struct btrfs_fs_info *fs_info); 49 + struct btrfs_device *btrfs_alloc_dummy_device(struct btrfs_fs_info *fs_info); 49 50 #else 50 51 static inline int btrfs_run_sanity_tests(void) 51 52 {