blob: d7d64235010d415922b174a3a1c1a39cdb96be4f [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Alex Zeffertt1107ba82009-01-07 18:07:11 -08002/*
3 * xenfs.c - a filesystem for passing info between the a domain and
4 * the hypervisor.
5 *
6 * 2008-10-07 Alex Zeffertt Replaced /proc/xen/xenbus with xenfs filesystem
7 * and /proc/xen compatibility mount point.
8 * Turned xenfs into a loadable module.
9 */
10
Joe Perches283c0972013-06-28 03:21:41 -070011#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
Alex Zeffertt1107ba82009-01-07 18:07:11 -080013#include <linux/kernel.h>
14#include <linux/errno.h>
15#include <linux/module.h>
16#include <linux/fs.h>
David Howells23457712019-03-25 16:38:30 +000017#include <linux/fs_context.h>
Alex Zeffertt1107ba82009-01-07 18:07:11 -080018#include <linux/magic.h>
19
Jeremy Fitzhardinge1ccbf532009-10-06 15:11:14 -070020#include <xen/xen.h>
Juergen Gross332f7912017-02-09 14:39:56 +010021#include <xen/xenbus.h>
Jeremy Fitzhardinge1ccbf532009-10-06 15:11:14 -070022
Alex Zeffertt1107ba82009-01-07 18:07:11 -080023#include "xenfs.h"
Bastian Blankd8414d32011-12-16 11:34:33 -050024#include "../privcmd.h"
Alex Zeffertt1107ba82009-01-07 18:07:11 -080025
26#include <asm/xen/hypervisor.h>
27
28MODULE_DESCRIPTION("Xen filesystem");
29MODULE_LICENSE("GPL");
30
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080031static ssize_t capabilities_read(struct file *file, char __user *buf,
32 size_t size, loff_t *off)
33{
34 char *tmp = "";
35
36 if (xen_initial_domain())
37 tmp = "control_d\n";
38
39 return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
40}
41
42static const struct file_operations capabilities_file_ops = {
43 .read = capabilities_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +020044 .llseek = default_llseek,
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080045};
46
David Howells23457712019-03-25 16:38:30 +000047static int xenfs_fill_super(struct super_block *sb, struct fs_context *fc)
Alex Zeffertt1107ba82009-01-07 18:07:11 -080048{
Eric Biggerscda37122017-03-25 21:15:37 -070049 static const struct tree_descr xenfs_files[] = {
Al Viro78c3e472013-01-27 22:31:55 -050050 [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
Jeremy Fitzhardinge818fd202009-02-06 18:46:47 -080051 { "capabilities", &capabilities_file_ops, S_IRUGO },
Bastian Blankd8414d32011-12-16 11:34:33 -050052 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
Alex Zeffertt1107ba82009-01-07 18:07:11 -080053 {""},
54 };
55
Eric Biggerscda37122017-03-25 21:15:37 -070056 static const struct tree_descr xenfs_init_files[] = {
Al Viro78c3e472013-01-27 22:31:55 -050057 [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
58 { "capabilities", &capabilities_file_ops, S_IRUGO },
59 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
60 { "xsd_kva", &xsd_kva_file_ops, S_IRUSR|S_IWUSR},
61 { "xsd_port", &xsd_port_file_ops, S_IRUSR|S_IWUSR},
Boris Ostrovskya11f4f02015-08-10 16:34:32 -040062#ifdef CONFIG_XEN_SYMS
63 { "xensyms", &xensyms_ops, S_IRUSR},
64#endif
Al Viro78c3e472013-01-27 22:31:55 -050065 {""},
66 };
Ian Campbell655d4062009-02-06 18:46:48 -080067
Al Viro78c3e472013-01-27 22:31:55 -050068 return simple_fill_super(sb, XENFS_SUPER_MAGIC,
69 xen_initial_domain() ? xenfs_init_files : xenfs_files);
Alex Zeffertt1107ba82009-01-07 18:07:11 -080070}
71
David Howells23457712019-03-25 16:38:30 +000072static int xenfs_get_tree(struct fs_context *fc)
Alex Zeffertt1107ba82009-01-07 18:07:11 -080073{
David Howells23457712019-03-25 16:38:30 +000074 return get_tree_single(fc, xenfs_fill_super);
75}
76
77static const struct fs_context_operations xenfs_context_ops = {
78 .get_tree = xenfs_get_tree,
79};
80
81static int xenfs_init_fs_context(struct fs_context *fc)
82{
83 fc->ops = &xenfs_context_ops;
84 return 0;
Alex Zeffertt1107ba82009-01-07 18:07:11 -080085}
86
87static struct file_system_type xenfs_type = {
88 .owner = THIS_MODULE,
89 .name = "xenfs",
David Howells23457712019-03-25 16:38:30 +000090 .init_fs_context = xenfs_init_fs_context,
Alex Zeffertt1107ba82009-01-07 18:07:11 -080091 .kill_sb = kill_litter_super,
92};
Eric W. Biederman7f78e032013-03-02 19:39:14 -080093MODULE_ALIAS_FS("xenfs");
Alex Zeffertt1107ba82009-01-07 18:07:11 -080094
95static int __init xenfs_init(void)
96{
Jeremy Fitzhardinge9045d472010-11-18 17:14:46 -080097 if (xen_domain())
98 return register_filesystem(&xenfs_type);
Alex Zeffertt1107ba82009-01-07 18:07:11 -080099
Jeremy Fitzhardinge9045d472010-11-18 17:14:46 -0800100 return 0;
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800101}
102
103static void __exit xenfs_exit(void)
104{
Jeremy Fitzhardinge43df95c2010-07-21 22:51:39 -0700105 if (xen_domain())
Alex Zeffertt1107ba82009-01-07 18:07:11 -0800106 unregister_filesystem(&xenfs_type);
107}
108
109module_init(xenfs_init);
110module_exit(xenfs_exit);
111