super.c 3.1 KB

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