treewide: Add SPDX license identifier for more missed files
[linux-2.6-block.git] / drivers / xen / xenfs / super.c
1 // SPDX-License-Identifier: GPL-2.0-only
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
11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/module.h>
16 #include <linux/fs.h>
17 #include <linux/magic.h>
18
19 #include <xen/xen.h>
20 #include <xen/xenbus.h>
21
22 #include "xenfs.h"
23 #include "../privcmd.h"
24
25 #include <asm/xen/hypervisor.h>
26
27 MODULE_DESCRIPTION("Xen filesystem");
28 MODULE_LICENSE("GPL");
29
30 static ssize_t capabilities_read(struct file *file, char __user *buf,
31                                  size_t size, loff_t *off)
32 {
33         char *tmp = "";
34
35         if (xen_initial_domain())
36                 tmp = "control_d\n";
37
38         return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
39 }
40
41 static const struct file_operations capabilities_file_ops = {
42         .read = capabilities_read,
43         .llseek = default_llseek,
44 };
45
46 static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
47 {
48         static const struct tree_descr xenfs_files[] = {
49                 [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
50                 { "capabilities", &capabilities_file_ops, S_IRUGO },
51                 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
52                 {""},
53         };
54
55         static const struct tree_descr xenfs_init_files[] = {
56                 [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
57                 { "capabilities", &capabilities_file_ops, S_IRUGO },
58                 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
59                 { "xsd_kva", &xsd_kva_file_ops, S_IRUSR|S_IWUSR},
60                 { "xsd_port", &xsd_port_file_ops, S_IRUSR|S_IWUSR},
61 #ifdef CONFIG_XEN_SYMS
62                 { "xensyms", &xensyms_ops, S_IRUSR},
63 #endif
64                 {""},
65         };
66
67         return simple_fill_super(sb, XENFS_SUPER_MAGIC,
68                         xen_initial_domain() ? xenfs_init_files : xenfs_files);
69 }
70
71 static struct dentry *xenfs_mount(struct file_system_type *fs_type,
72                                   int flags, const char *dev_name,
73                                   void *data)
74 {
75         return mount_single(fs_type, flags, data, xenfs_fill_super);
76 }
77
78 static struct file_system_type xenfs_type = {
79         .owner =        THIS_MODULE,
80         .name =         "xenfs",
81         .mount =        xenfs_mount,
82         .kill_sb =      kill_litter_super,
83 };
84 MODULE_ALIAS_FS("xenfs");
85
86 static int __init xenfs_init(void)
87 {
88         if (xen_domain())
89                 return register_filesystem(&xenfs_type);
90
91         return 0;
92 }
93
94 static void __exit xenfs_exit(void)
95 {
96         if (xen_domain())
97                 unregister_filesystem(&xenfs_type);
98 }
99
100 module_init(xenfs_init);
101 module_exit(xenfs_exit);
102