super.c 2.5 KB

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