blob: bd96340063c1d6175f633fa507e8c7e2bf34ba93 [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"
19
20#include <asm/xen/hypervisor.h>
21
22MODULE_DESCRIPTION("Xen filesystem");
23MODULE_LICENSE("GPL");
24
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080025static ssize_t capabilities_read(struct file *file, char __user *buf,
26 size_t size, loff_t *off)
27{
28 char *tmp = "";
29
30 if (xen_initial_domain())
31 tmp = "control_d\n";
32
33 return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
34}
35
36static const struct file_operations capabilities_file_ops = {
37 .read = capabilities_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +020038 .llseek = default_llseek,
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080039};
40
Alex Zeffertt1107ba82009-01-07 18:07:11 -080041static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
42{
43 static struct tree_descr xenfs_files[] = {
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080044 [1] = {},
45 { "xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR },
46 { "capabilities", &capabilities_file_ops, S_IRUGO },
Alex Zeffertt1107ba82009-01-07 18:07:11 -080047 {""},
48 };
49
50 return simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files);
51}
52
53static int xenfs_get_sb(struct file_system_type *fs_type,
54 int flags, const char *dev_name,
55 void *data, struct vfsmount *mnt)
56{
57 return get_sb_single(fs_type, flags, data, xenfs_fill_super, mnt);
58}
59
60static struct file_system_type xenfs_type = {
61 .owner = THIS_MODULE,
62 .name = "xenfs",
63 .get_sb = xenfs_get_sb,
64 .kill_sb = kill_litter_super,
65};
66
67static int __init xenfs_init(void)
68{
Jeremy Fitzhardinge43df95c2010-07-21 22:51:39 -070069 if (xen_domain())
Alex Zeffertt1107ba82009-01-07 18:07:11 -080070 return register_filesystem(&xenfs_type);
71
72 printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
73 return 0;
74}
75
76static void __exit xenfs_exit(void)
77{
Jeremy Fitzhardinge43df95c2010-07-21 22:51:39 -070078 if (xen_domain())
Alex Zeffertt1107ba82009-01-07 18:07:11 -080079 unregister_filesystem(&xenfs_type);
80}
81
82module_init(xenfs_init);
83module_exit(xenfs_exit);
84