Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 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 | |
Joe Perches | 283c097 | 2013-06-28 03:21:41 -0700 | [diff] [blame] | 11 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 12 | |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/fs.h> |
David Howells | 2345771 | 2019-03-25 16:38:30 +0000 | [diff] [blame] | 17 | #include <linux/fs_context.h> |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 18 | #include <linux/magic.h> |
| 19 | |
Jeremy Fitzhardinge | 1ccbf53 | 2009-10-06 15:11:14 -0700 | [diff] [blame] | 20 | #include <xen/xen.h> |
Juergen Gross | 332f791 | 2017-02-09 14:39:56 +0100 | [diff] [blame] | 21 | #include <xen/xenbus.h> |
Jeremy Fitzhardinge | 1ccbf53 | 2009-10-06 15:11:14 -0700 | [diff] [blame] | 22 | |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 23 | #include "xenfs.h" |
Bastian Blank | d8414d3 | 2011-12-16 11:34:33 -0500 | [diff] [blame] | 24 | #include "../privcmd.h" |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 25 | |
| 26 | #include <asm/xen/hypervisor.h> |
| 27 | |
| 28 | MODULE_DESCRIPTION("Xen filesystem"); |
| 29 | MODULE_LICENSE("GPL"); |
| 30 | |
Jeremy Fitzhardinge | 818fd20 | 2009-02-06 18:46:47 -0800 | [diff] [blame] | 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, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 44 | .llseek = default_llseek, |
Jeremy Fitzhardinge | 818fd20 | 2009-02-06 18:46:47 -0800 | [diff] [blame] | 45 | }; |
| 46 | |
David Howells | 2345771 | 2019-03-25 16:38:30 +0000 | [diff] [blame] | 47 | static int xenfs_fill_super(struct super_block *sb, struct fs_context *fc) |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 48 | { |
Eric Biggers | cda3712 | 2017-03-25 21:15:37 -0700 | [diff] [blame] | 49 | static const struct tree_descr xenfs_files[] = { |
Al Viro | 78c3e47 | 2013-01-27 22:31:55 -0500 | [diff] [blame] | 50 | [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR }, |
Jeremy Fitzhardinge | 818fd20 | 2009-02-06 18:46:47 -0800 | [diff] [blame] | 51 | { "capabilities", &capabilities_file_ops, S_IRUGO }, |
Bastian Blank | d8414d3 | 2011-12-16 11:34:33 -0500 | [diff] [blame] | 52 | { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR }, |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 53 | {""}, |
| 54 | }; |
| 55 | |
Eric Biggers | cda3712 | 2017-03-25 21:15:37 -0700 | [diff] [blame] | 56 | static const struct tree_descr xenfs_init_files[] = { |
Al Viro | 78c3e47 | 2013-01-27 22:31:55 -0500 | [diff] [blame] | 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}, |
Boris Ostrovsky | a11f4f0 | 2015-08-10 16:34:32 -0400 | [diff] [blame] | 62 | #ifdef CONFIG_XEN_SYMS |
| 63 | { "xensyms", &xensyms_ops, S_IRUSR}, |
| 64 | #endif |
Al Viro | 78c3e47 | 2013-01-27 22:31:55 -0500 | [diff] [blame] | 65 | {""}, |
| 66 | }; |
Ian Campbell | 655d406 | 2009-02-06 18:46:48 -0800 | [diff] [blame] | 67 | |
Al Viro | 78c3e47 | 2013-01-27 22:31:55 -0500 | [diff] [blame] | 68 | return simple_fill_super(sb, XENFS_SUPER_MAGIC, |
| 69 | xen_initial_domain() ? xenfs_init_files : xenfs_files); |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 70 | } |
| 71 | |
David Howells | 2345771 | 2019-03-25 16:38:30 +0000 | [diff] [blame] | 72 | static int xenfs_get_tree(struct fs_context *fc) |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 73 | { |
David Howells | 2345771 | 2019-03-25 16:38:30 +0000 | [diff] [blame] | 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; |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static struct file_system_type xenfs_type = { |
| 88 | .owner = THIS_MODULE, |
| 89 | .name = "xenfs", |
David Howells | 2345771 | 2019-03-25 16:38:30 +0000 | [diff] [blame] | 90 | .init_fs_context = xenfs_init_fs_context, |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 91 | .kill_sb = kill_litter_super, |
| 92 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 93 | MODULE_ALIAS_FS("xenfs"); |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 94 | |
| 95 | static int __init xenfs_init(void) |
| 96 | { |
Jeremy Fitzhardinge | 9045d47 | 2010-11-18 17:14:46 -0800 | [diff] [blame] | 97 | if (xen_domain()) |
| 98 | return register_filesystem(&xenfs_type); |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 99 | |
Jeremy Fitzhardinge | 9045d47 | 2010-11-18 17:14:46 -0800 | [diff] [blame] | 100 | return 0; |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static void __exit xenfs_exit(void) |
| 104 | { |
Jeremy Fitzhardinge | 43df95c | 2010-07-21 22:51:39 -0700 | [diff] [blame] | 105 | if (xen_domain()) |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 106 | unregister_filesystem(&xenfs_type); |
| 107 | } |
| 108 | |
| 109 | module_init(xenfs_init); |
| 110 | module_exit(xenfs_exit); |
| 111 | |