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