blob: a55fbf9a1519e5507cc3f368e70aa2a1b337a58d [file] [log] [blame]
Alex Zeffertt1107ba82009-01-07 18:07:11 -08001/*
2 * xenfs.c - a filesystem for passing info between the a domain and
3 * the hypervisor.
4 *
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 */
9
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>
15
Jeremy Fitzhardinge1ccbf532009-10-06 15:11:14 -070016#include <xen/xen.h>
17
Alex Zeffertt1107ba82009-01-07 18:07:11 -080018#include "xenfs.h"
Bastian Blankd8414d32011-12-16 11:34:33 -050019#include "../privcmd.h"
Alex Zeffertt1107ba82009-01-07 18:07:11 -080020
21#include <asm/xen/hypervisor.h>
22
23MODULE_DESCRIPTION("Xen filesystem");
24MODULE_LICENSE("GPL");
25
Ian Campbell655d4062009-02-06 18:46:48 -080026static struct inode *xenfs_make_inode(struct super_block *sb, int mode)
27{
28 struct inode *ret = new_inode(sb);
29
30 if (ret) {
31 ret->i_mode = mode;
32 ret->i_uid = ret->i_gid = 0;
33 ret->i_blocks = 0;
34 ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
35 }
36 return ret;
37}
38
39static struct dentry *xenfs_create_file(struct super_block *sb,
40 struct dentry *parent,
41 const char *name,
42 const struct file_operations *fops,
43 void *data,
44 int mode)
45{
46 struct dentry *dentry;
47 struct inode *inode;
48
49 dentry = d_alloc_name(parent, name);
50 if (!dentry)
51 return NULL;
52
53 inode = xenfs_make_inode(sb, S_IFREG | mode);
54 if (!inode) {
55 dput(dentry);
56 return NULL;
57 }
58
59 inode->i_fop = fops;
60 inode->i_private = data;
61
62 d_add(dentry, inode);
63 return dentry;
64}
65
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080066static ssize_t capabilities_read(struct file *file, char __user *buf,
67 size_t size, loff_t *off)
68{
69 char *tmp = "";
70
71 if (xen_initial_domain())
72 tmp = "control_d\n";
73
74 return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
75}
76
77static const struct file_operations capabilities_file_ops = {
78 .read = capabilities_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +020079 .llseek = default_llseek,
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080080};
81
Alex Zeffertt1107ba82009-01-07 18:07:11 -080082static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
83{
84 static struct tree_descr xenfs_files[] = {
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080085 [1] = {},
86 { "xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR },
87 { "capabilities", &capabilities_file_ops, S_IRUGO },
Bastian Blankd8414d32011-12-16 11:34:33 -050088 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
Alex Zeffertt1107ba82009-01-07 18:07:11 -080089 {""},
90 };
Ian Campbell655d4062009-02-06 18:46:48 -080091 int rc;
Alex Zeffertt1107ba82009-01-07 18:07:11 -080092
Ian Campbell655d4062009-02-06 18:46:48 -080093 rc = simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files);
94 if (rc < 0)
95 return rc;
96
97 if (xen_initial_domain()) {
98 xenfs_create_file(sb, sb->s_root, "xsd_kva",
99 &xsd_kva_file_ops, NULL, S_IRUSR|S_IWUSR);
100 xenfs_create_file(sb, sb->s_root, "xsd_port",
101 &xsd_port_file_ops, NULL, S_IRUSR|S_IWUSR);
102 }
103
104 return rc;
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800105}
106
Jeremy Fitzhardingefe61f1d2010-11-16 11:06:46 -0800107static struct dentry *xenfs_mount(struct file_system_type *fs_type,
108 int flags, const char *dev_name,
109 void *data)
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800110{
Al Virofc14f2f2010-07-25 01:48:30 +0400111 return mount_single(fs_type, flags, data, xenfs_fill_super);
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800112}
113
114static struct file_system_type xenfs_type = {
115 .owner = THIS_MODULE,
116 .name = "xenfs",
Al Virofc14f2f2010-07-25 01:48:30 +0400117 .mount = xenfs_mount,
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800118 .kill_sb = kill_litter_super,
119};
120
121static int __init xenfs_init(void)
122{
Jeremy Fitzhardinge9045d472010-11-18 17:14:46 -0800123 if (xen_domain())
124 return register_filesystem(&xenfs_type);
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800125
Jeremy Fitzhardinge9045d472010-11-18 17:14:46 -0800126 printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
127 return 0;
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800128}
129
130static void __exit xenfs_exit(void)
131{
Jeremy Fitzhardinge43df95c2010-07-21 22:51:39 -0700132 if (xen_domain())
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800133 unregister_filesystem(&xenfs_type);
134}
135
136module_init(xenfs_init);
137module_exit(xenfs_exit);
138