common.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License version 2
  4. * as published by the Free Software Foundation; or, when distributed
  5. * separately from the Linux kernel or incorporated into other
  6. * software packages, subject to the following license:
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this source file (the "Software"), to deal in the Software without
  10. * restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software,
  12. * and to permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  23. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  24. * IN THE SOFTWARE.
  25. */
  26. #ifndef __BLKIF__BACKEND__COMMON_H__
  27. #define __BLKIF__BACKEND__COMMON_H__
  28. #include <linux/version.h>
  29. #include <linux/module.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/slab.h>
  32. #include <linux/blkdev.h>
  33. #include <linux/vmalloc.h>
  34. #include <linux/wait.h>
  35. #include <linux/io.h>
  36. #include <asm/setup.h>
  37. #include <asm/pgalloc.h>
  38. #include <asm/hypervisor.h>
  39. #include <xen/blkif.h>
  40. #include <xen/grant_table.h>
  41. #include <xen/xenbus.h>
  42. #define DPRINTK(_f, _a...) \
  43. pr_debug("(file=%s, line=%d) " _f, \
  44. __FILE__ , __LINE__ , ## _a)
  45. struct vbd {
  46. blkif_vdev_t handle; /* what the domain refers to this vbd as */
  47. unsigned char readonly; /* Non-zero -> read-only */
  48. unsigned char type; /* VDISK_xxx */
  49. u32 pdevice; /* phys device that this vbd maps to */
  50. struct block_device *bdev;
  51. sector_t size; /* Cached size parameter */
  52. bool flush_support;
  53. };
  54. struct backend_info;
  55. struct blkif_st {
  56. /* Unique identifier for this interface. */
  57. domid_t domid;
  58. unsigned int handle;
  59. /* Physical parameters of the comms window. */
  60. unsigned int irq;
  61. /* Comms information. */
  62. enum blkif_protocol blk_protocol;
  63. union blkif_back_rings blk_rings;
  64. struct vm_struct *blk_ring_area;
  65. /* The VBD attached to this interface. */
  66. struct vbd vbd;
  67. /* Back pointer to the backend_info. */
  68. struct backend_info *be;
  69. /* Private fields. */
  70. spinlock_t blk_ring_lock;
  71. atomic_t refcnt;
  72. wait_queue_head_t wq;
  73. /* One thread per one blkif. */
  74. struct task_struct *xenblkd;
  75. unsigned int waiting_reqs;
  76. /* statistics */
  77. unsigned long st_print;
  78. int st_rd_req;
  79. int st_wr_req;
  80. int st_oo_req;
  81. int st_f_req;
  82. int st_rd_sect;
  83. int st_wr_sect;
  84. wait_queue_head_t waiting_to_free;
  85. grant_handle_t shmem_handle;
  86. grant_ref_t shmem_ref;
  87. };
  88. #define vbd_sz(_v) ((_v)->bdev->bd_part ? \
  89. (_v)->bdev->bd_part->nr_sects : \
  90. get_capacity((_v)->bdev->bd_disk))
  91. #define xen_blkif_get(_b) (atomic_inc(&(_b)->refcnt))
  92. #define xen_blkif_put(_b) \
  93. do { \
  94. if (atomic_dec_and_test(&(_b)->refcnt)) \
  95. wake_up(&(_b)->waiting_to_free);\
  96. } while (0)
  97. struct phys_req {
  98. unsigned short dev;
  99. unsigned short nr_sects;
  100. struct block_device *bdev;
  101. blkif_sector_t sector_number;
  102. };
  103. int xen_blkif_interface_init(void);
  104. int xen_blkif_xenbus_init(void);
  105. irqreturn_t xen_blkif_be_int(int irq, void *dev_id);
  106. int xen_blkif_schedule(void *arg);
  107. int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt,
  108. struct backend_info *be, int state);
  109. struct xenbus_device *xen_blkbk_xenbus(struct backend_info *be);
  110. #endif /* __BLKIF__BACKEND__COMMON_H__ */