xenstored.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <linux/slab.h>
  2. #include <linux/types.h>
  3. #include <linux/mm.h>
  4. #include <linux/fs.h>
  5. #include <xen/page.h>
  6. #include "xenfs.h"
  7. #include "../xenbus/xenbus_comms.h"
  8. static ssize_t xsd_read(struct file *file, char __user *buf,
  9. size_t size, loff_t *off)
  10. {
  11. const char *str = (const char *)file->private_data;
  12. return simple_read_from_buffer(buf, size, off, str, strlen(str));
  13. }
  14. static int xsd_release(struct inode *inode, struct file *file)
  15. {
  16. kfree(file->private_data);
  17. return 0;
  18. }
  19. static int xsd_kva_open(struct inode *inode, struct file *file)
  20. {
  21. file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
  22. xen_store_interface);
  23. if (!file->private_data)
  24. return -ENOMEM;
  25. return 0;
  26. }
  27. static int xsd_kva_mmap(struct file *file, struct vm_area_struct *vma)
  28. {
  29. size_t size = vma->vm_end - vma->vm_start;
  30. if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
  31. return -EINVAL;
  32. if (remap_pfn_range(vma, vma->vm_start,
  33. virt_to_pfn(xen_store_interface),
  34. size, vma->vm_page_prot))
  35. return -EAGAIN;
  36. return 0;
  37. }
  38. const struct file_operations xsd_kva_file_ops = {
  39. .open = xsd_kva_open,
  40. .mmap = xsd_kva_mmap,
  41. .read = xsd_read,
  42. .release = xsd_release,
  43. };
  44. static int xsd_port_open(struct inode *inode, struct file *file)
  45. {
  46. file->private_data = (void *)kasprintf(GFP_KERNEL, "%d",
  47. xen_store_evtchn);
  48. if (!file->private_data)
  49. return -ENOMEM;
  50. return 0;
  51. }
  52. const struct file_operations xsd_port_file_ops = {
  53. .open = xsd_port_open,
  54. .read = xsd_read,
  55. .release = xsd_release,
  56. };