blob: 71ddfb4cf61ccfef375a07d6271715e9478c68c6 [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
Joe Perches283c0972013-06-28 03:21:41 -070010#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
Alex Zeffertt1107ba82009-01-07 18:07:11 -080012#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/module.h>
15#include <linux/fs.h>
16#include <linux/magic.h>
17
Jeremy Fitzhardinge1ccbf532009-10-06 15:11:14 -070018#include <xen/xen.h>
Juergen Gross332f7912017-02-09 14:39:56 +010019#include <xen/xenbus.h>
Jeremy Fitzhardinge1ccbf532009-10-06 15:11:14 -070020
Alex Zeffertt1107ba82009-01-07 18:07:11 -080021#include "xenfs.h"
Bastian Blankd8414d32011-12-16 11:34:33 -050022#include "../privcmd.h"
Alex Zeffertt1107ba82009-01-07 18:07:11 -080023
24#include <asm/xen/hypervisor.h>
25
26MODULE_DESCRIPTION("Xen filesystem");
27MODULE_LICENSE("GPL");
28
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080029static ssize_t capabilities_read(struct file *file, char __user *buf,
30 size_t size, loff_t *off)
31{
32 char *tmp = "";
33
34 if (xen_initial_domain())
35 tmp = "control_d\n";
36
37 return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
38}
39
40static const struct file_operations capabilities_file_ops = {
41 .read = capabilities_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +020042 .llseek = default_llseek,
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080043};
44
Alex Zeffertt1107ba82009-01-07 18:07:11 -080045static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
46{
Eric Biggerscda37122017-03-25 21:15:37 -070047 static const struct tree_descr xenfs_files[] = {
Al Viro78c3e472013-01-27 22:31:55 -050048 [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080049 { "capabilities", &capabilities_file_ops, S_IRUGO },
Bastian Blankd8414d32011-12-16 11:34:33 -050050 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
Alex Zeffertt1107ba82009-01-07 18:07:11 -080051 {""},
52 };
53
Eric Biggerscda37122017-03-25 21:15:37 -070054 static const struct tree_descr xenfs_init_files[] = {
Al Viro78c3e472013-01-27 22:31:55 -050055 [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
56 { "capabilities", &capabilities_file_ops, S_IRUGO },
57 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
58 { "xsd_kva", &xsd_kva_file_ops, S_IRUSR|S_IWUSR},
59 { "xsd_port", &xsd_port_file_ops, S_IRUSR|S_IWUSR},
Boris Ostrovskya11f4f02015-08-10 16:34:32 -040060#ifdef CONFIG_XEN_SYMS
61 { "xensyms", &xensyms_ops, S_IRUSR},
62#endif
Al Viro78c3e472013-01-27 22:31:55 -050063 {""},
64 };
Ian Campbell655d4062009-02-06 18:46:48 -080065
Al Viro78c3e472013-01-27 22:31:55 -050066 return simple_fill_super(sb, XENFS_SUPER_MAGIC,
67 xen_initial_domain() ? xenfs_init_files : xenfs_files);
Alex Zeffertt1107ba82009-01-07 18:07:11 -080068}
69
Jeremy Fitzhardingefe61f1d2010-11-16 11:06:46 -080070static struct dentry *xenfs_mount(struct file_system_type *fs_type,
71 int flags, const char *dev_name,
72 void *data)
Alex Zeffertt1107ba82009-01-07 18:07:11 -080073{
Al Virofc14f2f2010-07-25 01:48:30 +040074 return mount_single(fs_type, flags, data, xenfs_fill_super);
Alex Zeffertt1107ba82009-01-07 18:07:11 -080075}
76
77static struct file_system_type xenfs_type = {
78 .owner = THIS_MODULE,
79 .name = "xenfs",
Al Virofc14f2f2010-07-25 01:48:30 +040080 .mount = xenfs_mount,
Alex Zeffertt1107ba82009-01-07 18:07:11 -080081 .kill_sb = kill_litter_super,
82};
Eric W. Biederman7f78e032013-03-02 19:39:14 -080083MODULE_ALIAS_FS("xenfs");
Alex Zeffertt1107ba82009-01-07 18:07:11 -080084
85static int __init xenfs_init(void)
86{
Jeremy Fitzhardinge9045d472010-11-18 17:14:46 -080087 if (xen_domain())
88 return register_filesystem(&xenfs_type);
Alex Zeffertt1107ba82009-01-07 18:07:11 -080089
Jeremy Fitzhardinge9045d472010-11-18 17:14:46 -080090 return 0;
Alex Zeffertt1107ba82009-01-07 18:07:11 -080091}
92
93static void __exit xenfs_exit(void)
94{
Jeremy Fitzhardinge43df95c2010-07-21 22:51:39 -070095 if (xen_domain())
Alex Zeffertt1107ba82009-01-07 18:07:11 -080096 unregister_filesystem(&xenfs_type);
97}
98
99module_init(xenfs_init);
100module_exit(xenfs_exit);
101