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