1294e30feSJosef Bacik /* 2294e30feSJosef Bacik * Copyright (C) 2013 Fusion IO. All rights reserved. 3294e30feSJosef Bacik * 4294e30feSJosef Bacik * This program is free software; you can redistribute it and/or 5294e30feSJosef Bacik * modify it under the terms of the GNU General Public 6294e30feSJosef Bacik * License v2 as published by the Free Software Foundation. 7294e30feSJosef Bacik * 8294e30feSJosef Bacik * This program is distributed in the hope that it will be useful, 9294e30feSJosef Bacik * but WITHOUT ANY WARRANTY; without even the implied warranty of 10294e30feSJosef Bacik * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11294e30feSJosef Bacik * General Public License for more details. 12294e30feSJosef Bacik * 13294e30feSJosef Bacik * You should have received a copy of the GNU General Public 14294e30feSJosef Bacik * License along with this program; if not, write to the 15294e30feSJosef Bacik * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16294e30feSJosef Bacik * Boston, MA 021110-1307, USA. 17294e30feSJosef Bacik */ 18294e30feSJosef Bacik 19294e30feSJosef Bacik #include <linux/fs.h> 20294e30feSJosef Bacik #include <linux/mount.h> 21294e30feSJosef Bacik #include <linux/magic.h> 22294e30feSJosef Bacik #include "btrfs-tests.h" 23294e30feSJosef Bacik #include "../ctree.h" 24294e30feSJosef Bacik 25294e30feSJosef Bacik static struct vfsmount *test_mnt = NULL; 26294e30feSJosef Bacik 27*aaedb55bSJosef Bacik static const struct super_operations btrfs_test_super_ops = { 28*aaedb55bSJosef Bacik .alloc_inode = btrfs_alloc_inode, 29*aaedb55bSJosef Bacik .destroy_inode = btrfs_test_destroy_inode, 30*aaedb55bSJosef Bacik }; 31*aaedb55bSJosef Bacik 32294e30feSJosef Bacik static struct dentry *btrfs_test_mount(struct file_system_type *fs_type, 33294e30feSJosef Bacik int flags, const char *dev_name, 34294e30feSJosef Bacik void *data) 35294e30feSJosef Bacik { 36*aaedb55bSJosef Bacik return mount_pseudo(fs_type, "btrfs_test:", &btrfs_test_super_ops, 37*aaedb55bSJosef Bacik NULL, BTRFS_TEST_MAGIC); 38294e30feSJosef Bacik } 39294e30feSJosef Bacik 40294e30feSJosef Bacik static struct file_system_type test_type = { 41294e30feSJosef Bacik .name = "btrfs_test_fs", 42294e30feSJosef Bacik .mount = btrfs_test_mount, 43294e30feSJosef Bacik .kill_sb = kill_anon_super, 44294e30feSJosef Bacik }; 45294e30feSJosef Bacik 46294e30feSJosef Bacik struct inode *btrfs_new_test_inode(void) 47294e30feSJosef Bacik { 48294e30feSJosef Bacik return new_inode(test_mnt->mnt_sb); 49294e30feSJosef Bacik } 50294e30feSJosef Bacik 51294e30feSJosef Bacik int btrfs_init_test_fs(void) 52294e30feSJosef Bacik { 53294e30feSJosef Bacik int ret; 54294e30feSJosef Bacik 55294e30feSJosef Bacik ret = register_filesystem(&test_type); 56294e30feSJosef Bacik if (ret) { 57294e30feSJosef Bacik printk(KERN_ERR "btrfs: cannot register test file system\n"); 58294e30feSJosef Bacik return ret; 59294e30feSJosef Bacik } 60294e30feSJosef Bacik 61294e30feSJosef Bacik test_mnt = kern_mount(&test_type); 62294e30feSJosef Bacik if (IS_ERR(test_mnt)) { 63294e30feSJosef Bacik printk(KERN_ERR "btrfs: cannot mount test file system\n"); 64294e30feSJosef Bacik unregister_filesystem(&test_type); 65294e30feSJosef Bacik return ret; 66294e30feSJosef Bacik } 67294e30feSJosef Bacik return 0; 68294e30feSJosef Bacik } 69294e30feSJosef Bacik 70294e30feSJosef Bacik void btrfs_destroy_test_fs(void) 71294e30feSJosef Bacik { 72294e30feSJosef Bacik kern_unmount(test_mnt); 73294e30feSJosef Bacik unregister_filesystem(&test_type); 74294e30feSJosef Bacik } 75