Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2013 Fusion IO.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/pseudo_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/magic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "btrfs-tests.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "../ctree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "../free-space-cache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "../free-space-tree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "../transaction.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "../volumes.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "../disk-io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "../qgroup.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "../block-group.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static struct vfsmount *test_mnt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) const char *test_error[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	[TEST_ALLOC_FS_INFO]	     = "cannot allocate fs_info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	[TEST_ALLOC_ROOT]	     = "cannot allocate root",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	[TEST_ALLOC_EXTENT_BUFFER]   = "cannot extent buffer",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	[TEST_ALLOC_PATH]	     = "cannot allocate path",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	[TEST_ALLOC_INODE]	     = "cannot allocate inode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	[TEST_ALLOC_BLOCK_GROUP]     = "cannot allocate block group",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	[TEST_ALLOC_EXTENT_MAP]      = "cannot allocate extent map",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static const struct super_operations btrfs_test_super_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	.alloc_inode	= btrfs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	.destroy_inode	= btrfs_test_destroy_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int btrfs_test_init_fs_context(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct pseudo_fs_context *ctx = init_pseudo(fc, BTRFS_TEST_MAGIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (!ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	ctx->ops = &btrfs_test_super_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static struct file_system_type test_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.name		= "btrfs_test_fs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.init_fs_context = btrfs_test_init_fs_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.kill_sb	= kill_anon_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) struct inode *btrfs_new_test_inode(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	inode = new_inode(test_mnt->mnt_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		inode_init_owner(inode, NULL, S_IFREG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static int btrfs_init_test_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	ret = register_filesystem(&test_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		printk(KERN_ERR "btrfs: cannot register test file system\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	test_mnt = kern_mount(&test_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (IS_ERR(test_mnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		printk(KERN_ERR "btrfs: cannot mount test file system\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		unregister_filesystem(&test_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return PTR_ERR(test_mnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static void btrfs_destroy_test_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	kern_unmount(test_mnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	unregister_filesystem(&test_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) struct btrfs_device *btrfs_alloc_dummy_device(struct btrfs_fs_info *fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct btrfs_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	extent_io_tree_init(NULL, &dev->alloc_state, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	INIT_LIST_HEAD(&dev->dev_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	list_add(&dev->dev_list, &fs_info->fs_devices->devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static void btrfs_free_dummy_device(struct btrfs_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	extent_io_tree_release(&dev->alloc_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct btrfs_fs_info *fs_info = kzalloc(sizeof(struct btrfs_fs_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 						GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (!fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	fs_info->fs_devices = kzalloc(sizeof(struct btrfs_fs_devices),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 				      GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (!fs_info->fs_devices) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		kfree(fs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	INIT_LIST_HEAD(&fs_info->fs_devices->devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	fs_info->super_copy = kzalloc(sizeof(struct btrfs_super_block),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				      GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (!fs_info->super_copy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		kfree(fs_info->fs_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		kfree(fs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	btrfs_init_fs_info(fs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	fs_info->nodesize = nodesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	fs_info->sectorsize = sectorsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	set_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	test_mnt->mnt_sb->s_fs_info = fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct radix_tree_iter iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	void **slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct btrfs_device *dev, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (!fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (WARN_ON(!test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			      &fs_info->fs_state)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	test_mnt->mnt_sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	spin_lock(&fs_info->buffer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	radix_tree_for_each_slot(slot, &fs_info->buffer_radix, &iter, 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		struct extent_buffer *eb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		eb = radix_tree_deref_slot_protected(slot, &fs_info->buffer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		if (!eb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		/* Shouldn't happen but that kind of thinking creates CVE's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		if (radix_tree_exception(eb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			if (radix_tree_deref_retry(eb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				slot = radix_tree_iter_retry(&iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		slot = radix_tree_iter_resume(slot, &iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		spin_unlock(&fs_info->buffer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		free_extent_buffer_stale(eb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		spin_lock(&fs_info->buffer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	spin_unlock(&fs_info->buffer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	btrfs_mapping_tree_free(&fs_info->mapping_tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	list_for_each_entry_safe(dev, tmp, &fs_info->fs_devices->devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 				 dev_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		btrfs_free_dummy_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	btrfs_free_qgroup_config(fs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	btrfs_free_fs_roots(fs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	kfree(fs_info->super_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	btrfs_check_leaked_roots(fs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	btrfs_extent_buffer_leak_debug_check(fs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	kfree(fs_info->fs_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	kfree(fs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) void btrfs_free_dummy_root(struct btrfs_root *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (!root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	/* Will be freed by btrfs_free_fs_roots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (WARN_ON(test_bit(BTRFS_ROOT_IN_RADIX, &root->state)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	btrfs_put_root(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct btrfs_block_group *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) btrfs_alloc_dummy_block_group(struct btrfs_fs_info *fs_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			      unsigned long length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct btrfs_block_group *cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	cache = kzalloc(sizeof(*cache), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (!cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 					GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (!cache->free_space_ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		kfree(cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	cache->start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	cache->length = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	cache->full_stripe_len = fs_info->sectorsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	cache->fs_info = fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	INIT_LIST_HEAD(&cache->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	INIT_LIST_HEAD(&cache->cluster_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	INIT_LIST_HEAD(&cache->bg_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	btrfs_init_free_space_ctl(cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	mutex_init(&cache->free_space_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	return cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) void btrfs_free_dummy_block_group(struct btrfs_block_group *cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (!cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	__btrfs_remove_free_space_cache(cache->free_space_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	kfree(cache->free_space_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	kfree(cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			    struct btrfs_fs_info *fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	memset(trans, 0, sizeof(*trans));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	trans->transid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	trans->type = __TRANS_DUMMY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	trans->fs_info = fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) int btrfs_run_sanity_tests(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	u32 sectorsize, nodesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	u32 test_sectorsize[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	ret = btrfs_init_test_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	for (i = 0; i < ARRAY_SIZE(test_sectorsize); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		sectorsize = test_sectorsize[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		for (nodesize = sectorsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		     nodesize <= BTRFS_MAX_METADATA_BLOCKSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		     nodesize <<= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			pr_info("BTRFS: selftest: sectorsize: %u  nodesize: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 				sectorsize, nodesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			ret = btrfs_test_free_space_cache(sectorsize, nodesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			ret = btrfs_test_extent_buffer_operations(sectorsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 				nodesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			ret = btrfs_test_extent_io(sectorsize, nodesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			ret = btrfs_test_inodes(sectorsize, nodesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			ret = btrfs_test_qgroups(sectorsize, nodesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			ret = btrfs_test_free_space_tree(sectorsize, nodesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	ret = btrfs_test_extent_map();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	btrfs_destroy_test_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }