Commit | Line | Data |
---|---|---|
09c434b8 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1107ba88 AZ |
2 | /* |
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 | ||
283c0972 JP |
11 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
12 | ||
1107ba88 AZ |
13 | #include <linux/kernel.h> |
14 | #include <linux/errno.h> | |
15 | #include <linux/module.h> | |
16 | #include <linux/fs.h> | |
2345771f | 17 | #include <linux/fs_context.h> |
1107ba88 AZ |
18 | #include <linux/magic.h> |
19 | ||
1ccbf534 | 20 | #include <xen/xen.h> |
332f791d | 21 | #include <xen/xenbus.h> |
1ccbf534 | 22 | |
1107ba88 | 23 | #include "xenfs.h" |
d8414d3c | 24 | #include "../privcmd.h" |
1107ba88 AZ |
25 | |
26 | #include <asm/xen/hypervisor.h> | |
27 | ||
28 | MODULE_DESCRIPTION("Xen filesystem"); | |
29 | MODULE_LICENSE("GPL"); | |
30 | ||
818fd206 JF |
31 | static 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 | ||
42 | static const struct file_operations capabilities_file_ops = { | |
43 | .read = capabilities_read, | |
6038f373 | 44 | .llseek = default_llseek, |
818fd206 JF |
45 | }; |
46 | ||
2345771f | 47 | static int xenfs_fill_super(struct super_block *sb, struct fs_context *fc) |
1107ba88 | 48 | { |
cda37124 | 49 | static const struct tree_descr xenfs_files[] = { |
78c3e473 | 50 | [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR }, |
818fd206 | 51 | { "capabilities", &capabilities_file_ops, S_IRUGO }, |
d8414d3c | 52 | { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR }, |
1107ba88 AZ |
53 | {""}, |
54 | }; | |
55 | ||
cda37124 | 56 | static const struct tree_descr xenfs_init_files[] = { |
78c3e473 AV |
57 | [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}, | |
a11f4f0a BO |
62 | #ifdef CONFIG_XEN_SYMS |
63 | { "xensyms", &xensyms_ops, S_IRUSR}, | |
64 | #endif | |
78c3e473 AV |
65 | {""}, |
66 | }; | |
1107ba88 | 67 | |
78c3e473 AV |
68 | return simple_fill_super(sb, XENFS_SUPER_MAGIC, |
69 | xen_initial_domain() ? xenfs_init_files : xenfs_files); | |
1107ba88 AZ |
70 | } |
71 | ||
2345771f | 72 | static int xenfs_get_tree(struct fs_context *fc) |
1107ba88 | 73 | { |
2345771f DH |
74 | return get_tree_single(fc, xenfs_fill_super); |
75 | } | |
76 | ||
77 | static const struct fs_context_operations xenfs_context_ops = { | |
78 | .get_tree = xenfs_get_tree, | |
79 | }; | |
80 | ||
81 | static int xenfs_init_fs_context(struct fs_context *fc) | |
82 | { | |
83 | fc->ops = &xenfs_context_ops; | |
84 | return 0; | |
1107ba88 AZ |
85 | } |
86 | ||
87 | static struct file_system_type xenfs_type = { | |
88 | .owner = THIS_MODULE, | |
89 | .name = "xenfs", | |
2345771f | 90 | .init_fs_context = xenfs_init_fs_context, |
1107ba88 AZ |
91 | .kill_sb = kill_litter_super, |
92 | }; | |
7f78e035 | 93 | MODULE_ALIAS_FS("xenfs"); |
1107ba88 AZ |
94 | |
95 | static int __init xenfs_init(void) | |
96 | { | |
9045d47e JF |
97 | if (xen_domain()) |
98 | return register_filesystem(&xenfs_type); | |
1107ba88 | 99 | |
9045d47e | 100 | return 0; |
1107ba88 AZ |
101 | } |
102 | ||
103 | static void __exit xenfs_exit(void) | |
104 | { | |
43df95c4 | 105 | if (xen_domain()) |
1107ba88 AZ |
106 | unregister_filesystem(&xenfs_type); |
107 | } | |
108 | ||
109 | module_init(xenfs_init); | |
110 | module_exit(xenfs_exit); | |
111 |