Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 1 | /* |
| 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 Perches | 283c097 | 2013-06-28 03:21:41 -0700 | [diff] [blame^] | 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 11 | |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 12 | #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 Fitzhardinge | 1ccbf53 | 2009-10-06 15:11:14 -0700 | [diff] [blame] | 18 | #include <xen/xen.h> |
| 19 | |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 20 | #include "xenfs.h" |
Bastian Blank | d8414d3 | 2011-12-16 11:34:33 -0500 | [diff] [blame] | 21 | #include "../privcmd.h" |
Bastian Blank | 2fb3683 | 2011-12-10 19:29:47 +0100 | [diff] [blame] | 22 | #include "../xenbus/xenbus_comms.h" |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 23 | |
| 24 | #include <asm/xen/hypervisor.h> |
| 25 | |
| 26 | MODULE_DESCRIPTION("Xen filesystem"); |
| 27 | MODULE_LICENSE("GPL"); |
| 28 | |
Jeremy Fitzhardinge | 818fd20 | 2009-02-06 18:46:47 -0800 | [diff] [blame] | 29 | static 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 | |
| 40 | static const struct file_operations capabilities_file_ops = { |
| 41 | .read = capabilities_read, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 42 | .llseek = default_llseek, |
Jeremy Fitzhardinge | 818fd20 | 2009-02-06 18:46:47 -0800 | [diff] [blame] | 43 | }; |
| 44 | |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 45 | static int xenfs_fill_super(struct super_block *sb, void *data, int silent) |
| 46 | { |
| 47 | static struct tree_descr xenfs_files[] = { |
Al Viro | 78c3e47 | 2013-01-27 22:31:55 -0500 | [diff] [blame] | 48 | [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR }, |
Jeremy Fitzhardinge | 818fd20 | 2009-02-06 18:46:47 -0800 | [diff] [blame] | 49 | { "capabilities", &capabilities_file_ops, S_IRUGO }, |
Bastian Blank | d8414d3 | 2011-12-16 11:34:33 -0500 | [diff] [blame] | 50 | { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR }, |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 51 | {""}, |
| 52 | }; |
| 53 | |
Al Viro | 78c3e47 | 2013-01-27 22:31:55 -0500 | [diff] [blame] | 54 | static struct tree_descr xenfs_init_files[] = { |
| 55 | [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}, |
| 60 | {""}, |
| 61 | }; |
Ian Campbell | 655d406 | 2009-02-06 18:46:48 -0800 | [diff] [blame] | 62 | |
Al Viro | 78c3e47 | 2013-01-27 22:31:55 -0500 | [diff] [blame] | 63 | return simple_fill_super(sb, XENFS_SUPER_MAGIC, |
| 64 | xen_initial_domain() ? xenfs_init_files : xenfs_files); |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Jeremy Fitzhardinge | fe61f1d | 2010-11-16 11:06:46 -0800 | [diff] [blame] | 67 | static struct dentry *xenfs_mount(struct file_system_type *fs_type, |
| 68 | int flags, const char *dev_name, |
| 69 | void *data) |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 70 | { |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 71 | return mount_single(fs_type, flags, data, xenfs_fill_super); |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static struct file_system_type xenfs_type = { |
| 75 | .owner = THIS_MODULE, |
| 76 | .name = "xenfs", |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 77 | .mount = xenfs_mount, |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 78 | .kill_sb = kill_litter_super, |
| 79 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 80 | MODULE_ALIAS_FS("xenfs"); |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 81 | |
| 82 | static int __init xenfs_init(void) |
| 83 | { |
Jeremy Fitzhardinge | 9045d47 | 2010-11-18 17:14:46 -0800 | [diff] [blame] | 84 | if (xen_domain()) |
| 85 | return register_filesystem(&xenfs_type); |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 86 | |
Joe Perches | 283c097 | 2013-06-28 03:21:41 -0700 | [diff] [blame^] | 87 | pr_info("not registering filesystem on non-xen platform\n"); |
Jeremy Fitzhardinge | 9045d47 | 2010-11-18 17:14:46 -0800 | [diff] [blame] | 88 | return 0; |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static void __exit xenfs_exit(void) |
| 92 | { |
Jeremy Fitzhardinge | 43df95c | 2010-07-21 22:51:39 -0700 | [diff] [blame] | 93 | if (xen_domain()) |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 94 | unregister_filesystem(&xenfs_type); |
| 95 | } |
| 96 | |
| 97 | module_init(xenfs_init); |
| 98 | module_exit(xenfs_exit); |
| 99 | |