blob: a84b53c01436334b68688dca58e75bd54462b023 [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"
Bastian Blank2fb36832011-12-10 19:29:47 +010020#include "../xenbus/xenbus_comms.h"
Alex Zeffertt1107ba82009-01-07 18:07:11 -080021
22#include <asm/xen/hypervisor.h>
23
24MODULE_DESCRIPTION("Xen filesystem");
25MODULE_LICENSE("GPL");
26
Ian Campbell655d4062009-02-06 18:46:48 -080027static struct inode *xenfs_make_inode(struct super_block *sb, int mode)
28{
29 struct inode *ret = new_inode(sb);
30
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;
36 }
37 return ret;
38}
39
40static 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)
46{
47 struct dentry *dentry;
48 struct inode *inode;
49
50 dentry = d_alloc_name(parent, name);
51 if (!dentry)
52 return NULL;
53
54 inode = xenfs_make_inode(sb, S_IFREG | mode);
55 if (!inode) {
56 dput(dentry);
57 return NULL;
58 }
59
60 inode->i_fop = fops;
61 inode->i_private = data;
62
63 d_add(dentry, inode);
64 return dentry;
65}
66
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080067static ssize_t capabilities_read(struct file *file, char __user *buf,
68 size_t size, loff_t *off)
69{
70 char *tmp = "";
71
72 if (xen_initial_domain())
73 tmp = "control_d\n";
74
75 return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
76}
77
78static const struct file_operations capabilities_file_ops = {
79 .read = capabilities_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +020080 .llseek = default_llseek,
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080081};
82
Alex Zeffertt1107ba82009-01-07 18:07:11 -080083static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
84{
85 static struct tree_descr xenfs_files[] = {
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080086 [1] = {},
Bastian Blank2fb36832011-12-10 19:29:47 +010087 { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080088 { "capabilities", &capabilities_file_ops, S_IRUGO },
Bastian Blankd8414d32011-12-16 11:34:33 -050089 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
Alex Zeffertt1107ba82009-01-07 18:07:11 -080090 {""},
91 };
Ian Campbell655d4062009-02-06 18:46:48 -080092 int rc;
Alex Zeffertt1107ba82009-01-07 18:07:11 -080093
Ian Campbell655d4062009-02-06 18:46:48 -080094 rc = simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files);
95 if (rc < 0)
96 return rc;
97
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);
103 }
104
105 return rc;
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800106}
107
Jeremy Fitzhardingefe61f1d2010-11-16 11:06:46 -0800108static struct dentry *xenfs_mount(struct file_system_type *fs_type,
109 int flags, const char *dev_name,
110 void *data)
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800111{
Al Virofc14f2f2010-07-25 01:48:30 +0400112 return mount_single(fs_type, flags, data, xenfs_fill_super);
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800113}
114
115static struct file_system_type xenfs_type = {
116 .owner = THIS_MODULE,
117 .name = "xenfs",
Al Virofc14f2f2010-07-25 01:48:30 +0400118 .mount = xenfs_mount,
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800119 .kill_sb = kill_litter_super,
120};
121
122static int __init xenfs_init(void)
123{
Jeremy Fitzhardinge9045d472010-11-18 17:14:46 -0800124 if (xen_domain())
125 return register_filesystem(&xenfs_type);
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800126
Jeremy Fitzhardinge9045d472010-11-18 17:14:46 -0800127 printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
128 return 0;
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800129}
130
131static void __exit xenfs_exit(void)
132{
Jeremy Fitzhardinge43df95c2010-07-21 22:51:39 -0700133 if (xen_domain())
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800134 unregister_filesystem(&xenfs_type);
135}
136
137module_init(xenfs_init);
138module_exit(xenfs_exit);
139