Xen: consolidate and simplify struct xenbus_driver instantiation
[linux-2.6/libata-dev.git] / drivers / xen / xenfs / super.c
bloba84b53c01436334b68688dca58e75bd54462b023
1 /*
2 * xenfs.c - a filesystem for passing info between the a domain and
3 * the hypervisor.
5 * 2008-10-07 Alex Zeffertt Replaced /proc/xen/xenbus with xenfs filesystem
6 * and /proc/xen compatibility mount point.
7 * Turned xenfs into a loadable module.
8 */
10 #include <linux/kernel.h>
11 #include <linux/errno.h>
12 #include <linux/module.h>
13 #include <linux/fs.h>
14 #include <linux/magic.h>
16 #include <xen/xen.h>
18 #include "xenfs.h"
19 #include "../privcmd.h"
20 #include "../xenbus/xenbus_comms.h"
22 #include <asm/xen/hypervisor.h>
24 MODULE_DESCRIPTION("Xen filesystem");
25 MODULE_LICENSE("GPL");
27 static struct inode *xenfs_make_inode(struct super_block *sb, int mode)
29 struct inode *ret = new_inode(sb);
31 if (ret) {
32 ret->i_mode = mode;
33 ret->i_uid = ret->i_gid = 0;
34 ret->i_blocks = 0;
35 ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
37 return ret;
40 static struct dentry *xenfs_create_file(struct super_block *sb,
41 struct dentry *parent,
42 const char *name,
43 const struct file_operations *fops,
44 void *data,
45 int mode)
47 struct dentry *dentry;
48 struct inode *inode;
50 dentry = d_alloc_name(parent, name);
51 if (!dentry)
52 return NULL;
54 inode = xenfs_make_inode(sb, S_IFREG | mode);
55 if (!inode) {
56 dput(dentry);
57 return NULL;
60 inode->i_fop = fops;
61 inode->i_private = data;
63 d_add(dentry, inode);
64 return dentry;
67 static ssize_t capabilities_read(struct file *file, char __user *buf,
68 size_t size, loff_t *off)
70 char *tmp = "";
72 if (xen_initial_domain())
73 tmp = "control_d\n";
75 return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
78 static const struct file_operations capabilities_file_ops = {
79 .read = capabilities_read,
80 .llseek = default_llseek,
83 static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
85 static struct tree_descr xenfs_files[] = {
86 [1] = {},
87 { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
88 { "capabilities", &capabilities_file_ops, S_IRUGO },
89 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
90 {""},
92 int rc;
94 rc = simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files);
95 if (rc < 0)
96 return rc;
98 if (xen_initial_domain()) {
99 xenfs_create_file(sb, sb->s_root, "xsd_kva",
100 &xsd_kva_file_ops, NULL, S_IRUSR|S_IWUSR);
101 xenfs_create_file(sb, sb->s_root, "xsd_port",
102 &xsd_port_file_ops, NULL, S_IRUSR|S_IWUSR);
105 return rc;
108 static struct dentry *xenfs_mount(struct file_system_type *fs_type,
109 int flags, const char *dev_name,
110 void *data)
112 return mount_single(fs_type, flags, data, xenfs_fill_super);
115 static struct file_system_type xenfs_type = {
116 .owner = THIS_MODULE,
117 .name = "xenfs",
118 .mount = xenfs_mount,
119 .kill_sb = kill_litter_super,
122 static int __init xenfs_init(void)
124 if (xen_domain())
125 return register_filesystem(&xenfs_type);
127 printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
128 return 0;
131 static void __exit xenfs_exit(void)
133 if (xen_domain())
134 unregister_filesystem(&xenfs_type);
137 module_init(xenfs_init);
138 module_exit(xenfs_exit);