super.c 2.4 KB

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