xref: /openbmc/linux/fs/btrfs/tests/btrfs-tests.c (revision 294e30fee35d3151d100cfe59e839c2dbc16a374)
1*294e30feSJosef Bacik /*
2*294e30feSJosef Bacik  * Copyright (C) 2013 Fusion IO.  All rights reserved.
3*294e30feSJosef Bacik  *
4*294e30feSJosef Bacik  * This program is free software; you can redistribute it and/or
5*294e30feSJosef Bacik  * modify it under the terms of the GNU General Public
6*294e30feSJosef Bacik  * License v2 as published by the Free Software Foundation.
7*294e30feSJosef Bacik  *
8*294e30feSJosef Bacik  * This program is distributed in the hope that it will be useful,
9*294e30feSJosef Bacik  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10*294e30feSJosef Bacik  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11*294e30feSJosef Bacik  * General Public License for more details.
12*294e30feSJosef Bacik  *
13*294e30feSJosef Bacik  * You should have received a copy of the GNU General Public
14*294e30feSJosef Bacik  * License along with this program; if not, write to the
15*294e30feSJosef Bacik  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16*294e30feSJosef Bacik  * Boston, MA 021110-1307, USA.
17*294e30feSJosef Bacik  */
18*294e30feSJosef Bacik 
19*294e30feSJosef Bacik #include <linux/fs.h>
20*294e30feSJosef Bacik #include <linux/mount.h>
21*294e30feSJosef Bacik #include <linux/magic.h>
22*294e30feSJosef Bacik #include "btrfs-tests.h"
23*294e30feSJosef Bacik #include "../ctree.h"
24*294e30feSJosef Bacik 
25*294e30feSJosef Bacik static struct vfsmount *test_mnt = NULL;
26*294e30feSJosef Bacik 
27*294e30feSJosef Bacik static struct dentry *btrfs_test_mount(struct file_system_type *fs_type,
28*294e30feSJosef Bacik 				       int flags, const char *dev_name,
29*294e30feSJosef Bacik 				       void *data)
30*294e30feSJosef Bacik {
31*294e30feSJosef Bacik 	return mount_pseudo(fs_type, "btrfs_test:", NULL, NULL, BTRFS_TEST_MAGIC);
32*294e30feSJosef Bacik }
33*294e30feSJosef Bacik 
34*294e30feSJosef Bacik static struct file_system_type test_type = {
35*294e30feSJosef Bacik 	.name		= "btrfs_test_fs",
36*294e30feSJosef Bacik 	.mount		= btrfs_test_mount,
37*294e30feSJosef Bacik 	.kill_sb	= kill_anon_super,
38*294e30feSJosef Bacik };
39*294e30feSJosef Bacik 
40*294e30feSJosef Bacik struct inode *btrfs_new_test_inode(void)
41*294e30feSJosef Bacik {
42*294e30feSJosef Bacik 	return new_inode(test_mnt->mnt_sb);
43*294e30feSJosef Bacik }
44*294e30feSJosef Bacik 
45*294e30feSJosef Bacik int btrfs_init_test_fs(void)
46*294e30feSJosef Bacik {
47*294e30feSJosef Bacik 	int ret;
48*294e30feSJosef Bacik 
49*294e30feSJosef Bacik 	ret = register_filesystem(&test_type);
50*294e30feSJosef Bacik 	if (ret) {
51*294e30feSJosef Bacik 		printk(KERN_ERR "btrfs: cannot register test file system\n");
52*294e30feSJosef Bacik 		return ret;
53*294e30feSJosef Bacik 	}
54*294e30feSJosef Bacik 
55*294e30feSJosef Bacik 	test_mnt = kern_mount(&test_type);
56*294e30feSJosef Bacik 	if (IS_ERR(test_mnt)) {
57*294e30feSJosef Bacik 		printk(KERN_ERR "btrfs: cannot mount test file system\n");
58*294e30feSJosef Bacik 		unregister_filesystem(&test_type);
59*294e30feSJosef Bacik 		return ret;
60*294e30feSJosef Bacik 	}
61*294e30feSJosef Bacik 	return 0;
62*294e30feSJosef Bacik }
63*294e30feSJosef Bacik 
64*294e30feSJosef Bacik void btrfs_destroy_test_fs(void)
65*294e30feSJosef Bacik {
66*294e30feSJosef Bacik 	kern_unmount(test_mnt);
67*294e30feSJosef Bacik 	unregister_filesystem(&test_type);
68*294e30feSJosef Bacik }
69