super.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <asm/xen/hypervisor.h>
  18. MODULE_DESCRIPTION("Xen filesystem");
  19. MODULE_LICENSE("GPL");
  20. static struct inode *xenfs_make_inode(struct super_block *sb, int mode)
  21. {
  22. struct inode *ret = new_inode(sb);
  23. if (ret) {
  24. ret->i_mode = mode;
  25. ret->i_uid = ret->i_gid = 0;
  26. ret->i_blocks = 0;
  27. ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
  28. }
  29. return ret;
  30. }
  31. static struct dentry *xenfs_create_file(struct super_block *sb,
  32. struct dentry *parent,
  33. const char *name,
  34. const struct file_operations *fops,
  35. void *data,
  36. int mode)
  37. {
  38. struct dentry *dentry;
  39. struct inode *inode;
  40. dentry = d_alloc_name(parent, name);
  41. if (!dentry)
  42. return NULL;
  43. inode = xenfs_make_inode(sb, S_IFREG | mode);
  44. if (!inode) {
  45. dput(dentry);
  46. return NULL;
  47. }
  48. inode->i_fop = fops;
  49. inode->i_private = data;
  50. d_add(dentry, inode);
  51. return dentry;
  52. }
  53. static ssize_t capabilities_read(struct file *file, char __user *buf,
  54. size_t size, loff_t *off)
  55. {
  56. char *tmp = "";
  57. if (xen_initial_domain())
  58. tmp = "control_d\n";
  59. return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
  60. }
  61. static const struct file_operations capabilities_file_ops = {
  62. .read = capabilities_read,
  63. .llseek = default_llseek,
  64. };
  65. static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
  66. {
  67. static struct tree_descr xenfs_files[] = {
  68. [1] = {},
  69. { "xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR },
  70. { "capabilities", &capabilities_file_ops, S_IRUGO },
  71. { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
  72. {""},
  73. };
  74. int rc;
  75. rc = simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files);
  76. if (rc < 0)
  77. return rc;
  78. if (xen_initial_domain()) {
  79. xenfs_create_file(sb, sb->s_root, "xsd_kva",
  80. &xsd_kva_file_ops, NULL, S_IRUSR|S_IWUSR);
  81. xenfs_create_file(sb, sb->s_root, "xsd_port",
  82. &xsd_port_file_ops, NULL, S_IRUSR|S_IWUSR);
  83. }
  84. return rc;
  85. }
  86. static struct dentry *xenfs_mount(struct file_system_type *fs_type,
  87. int flags, const char *dev_name,
  88. void *data)
  89. {
  90. return mount_single(fs_type, flags, data, xenfs_fill_super);
  91. }
  92. static struct file_system_type xenfs_type = {
  93. .owner = THIS_MODULE,
  94. .name = "xenfs",
  95. .mount = xenfs_mount,
  96. .kill_sb = kill_litter_super,
  97. };
  98. static int __init xenfs_init(void)
  99. {
  100. if (xen_domain())
  101. return register_filesystem(&xenfs_type);
  102. printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
  103. return 0;
  104. }
  105. static void __exit xenfs_exit(void)
  106. {
  107. if (xen_domain())
  108. unregister_filesystem(&xenfs_type);
  109. }
  110. module_init(xenfs_init);
  111. module_exit(xenfs_exit);