blob: ec0abb6df3c303fa7ace7b0e8b6e018f39ce8fb7 [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
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080027static ssize_t capabilities_read(struct file *file, char __user *buf,
28 size_t size, loff_t *off)
29{
30 char *tmp = "";
31
32 if (xen_initial_domain())
33 tmp = "control_d\n";
34
35 return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
36}
37
38static const struct file_operations capabilities_file_ops = {
39 .read = capabilities_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +020040 .llseek = default_llseek,
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080041};
42
Alex Zeffertt1107ba82009-01-07 18:07:11 -080043static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
44{
45 static struct tree_descr xenfs_files[] = {
Al Viro78c3e472013-01-27 22:31:55 -050046 [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080047 { "capabilities", &capabilities_file_ops, S_IRUGO },
Bastian Blankd8414d32011-12-16 11:34:33 -050048 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
Alex Zeffertt1107ba82009-01-07 18:07:11 -080049 {""},
50 };
51
Al Viro78c3e472013-01-27 22:31:55 -050052 static struct tree_descr xenfs_init_files[] = {
53 [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
54 { "capabilities", &capabilities_file_ops, S_IRUGO },
55 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
56 { "xsd_kva", &xsd_kva_file_ops, S_IRUSR|S_IWUSR},
57 { "xsd_port", &xsd_port_file_ops, S_IRUSR|S_IWUSR},
58 {""},
59 };
Ian Campbell655d4062009-02-06 18:46:48 -080060
Al Viro78c3e472013-01-27 22:31:55 -050061 return simple_fill_super(sb, XENFS_SUPER_MAGIC,
62 xen_initial_domain() ? xenfs_init_files : xenfs_files);
Alex Zeffertt1107ba82009-01-07 18:07:11 -080063}
64
Jeremy Fitzhardingefe61f1d2010-11-16 11:06:46 -080065static struct dentry *xenfs_mount(struct file_system_type *fs_type,
66 int flags, const char *dev_name,
67 void *data)
Alex Zeffertt1107ba82009-01-07 18:07:11 -080068{
Al Virofc14f2f2010-07-25 01:48:30 +040069 return mount_single(fs_type, flags, data, xenfs_fill_super);
Alex Zeffertt1107ba82009-01-07 18:07:11 -080070}
71
72static struct file_system_type xenfs_type = {
73 .owner = THIS_MODULE,
74 .name = "xenfs",
Al Virofc14f2f2010-07-25 01:48:30 +040075 .mount = xenfs_mount,
Alex Zeffertt1107ba82009-01-07 18:07:11 -080076 .kill_sb = kill_litter_super,
77};
78
79static int __init xenfs_init(void)
80{
Jeremy Fitzhardinge9045d472010-11-18 17:14:46 -080081 if (xen_domain())
82 return register_filesystem(&xenfs_type);
Alex Zeffertt1107ba82009-01-07 18:07:11 -080083
Jeremy Fitzhardinge9045d472010-11-18 17:14:46 -080084 printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
85 return 0;
Alex Zeffertt1107ba82009-01-07 18:07:11 -080086}
87
88static void __exit xenfs_exit(void)
89{
Jeremy Fitzhardinge43df95c2010-07-21 22:51:39 -070090 if (xen_domain())
Alex Zeffertt1107ba82009-01-07 18:07:11 -080091 unregister_filesystem(&xenfs_type);
92}
93
94module_init(xenfs_init);
95module_exit(xenfs_exit);
96