super.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  11. #include <linux/kernel.h>
  12. #include <linux/errno.h>
  13. #include <linux/module.h>
  14. #include <linux/fs.h>
  15. #include <linux/fs_context.h>
  16. #include <linux/magic.h>
  17. #include <xen/xen.h>
  18. #include <xen/xenbus.h>
  19. #include "xenfs.h"
  20. #include "../privcmd.h"
  21. #include <asm/xen/hypervisor.h>
  22. MODULE_DESCRIPTION("Xen filesystem");
  23. MODULE_LICENSE("GPL");
  24. static ssize_t capabilities_read(struct file *file, char __user *buf,
  25. size_t size, loff_t *off)
  26. {
  27. char *tmp = "";
  28. if (xen_initial_domain())
  29. tmp = "control_d\n";
  30. return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
  31. }
  32. static const struct file_operations capabilities_file_ops = {
  33. .read = capabilities_read,
  34. .llseek = default_llseek,
  35. };
  36. static int xenfs_fill_super(struct super_block *sb, struct fs_context *fc)
  37. {
  38. static const struct tree_descr xenfs_files[] = {
  39. [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
  40. { "capabilities", &capabilities_file_ops, S_IRUGO },
  41. { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
  42. {""},
  43. };
  44. static const struct tree_descr xenfs_init_files[] = {
  45. [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
  46. { "capabilities", &capabilities_file_ops, S_IRUGO },
  47. { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
  48. { "xsd_kva", &xsd_kva_file_ops, S_IRUSR|S_IWUSR},
  49. { "xsd_port", &xsd_port_file_ops, S_IRUSR|S_IWUSR},
  50. #ifdef CONFIG_XEN_SYMS
  51. { "xensyms", &xensyms_ops, S_IRUSR},
  52. #endif
  53. {""},
  54. };
  55. return simple_fill_super(sb, XENFS_SUPER_MAGIC,
  56. xen_initial_domain() ? xenfs_init_files : xenfs_files);
  57. }
  58. static int xenfs_get_tree(struct fs_context *fc)
  59. {
  60. return get_tree_single(fc, xenfs_fill_super);
  61. }
  62. static const struct fs_context_operations xenfs_context_ops = {
  63. .get_tree = xenfs_get_tree,
  64. };
  65. static int xenfs_init_fs_context(struct fs_context *fc)
  66. {
  67. fc->ops = &xenfs_context_ops;
  68. return 0;
  69. }
  70. static struct file_system_type xenfs_type = {
  71. .owner = THIS_MODULE,
  72. .name = "xenfs",
  73. .init_fs_context = xenfs_init_fs_context,
  74. .kill_sb = kill_litter_super,
  75. };
  76. MODULE_ALIAS_FS("xenfs");
  77. static int __init xenfs_init(void)
  78. {
  79. if (xen_domain())
  80. return register_filesystem(&xenfs_type);
  81. return 0;
  82. }
  83. static void __exit xenfs_exit(void)
  84. {
  85. if (xen_domain())
  86. unregister_filesystem(&xenfs_type);
  87. }
  88. module_init(xenfs_init);
  89. module_exit(xenfs_exit);