blkif.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /******************************************************************************
  2. * blkif.h
  3. *
  4. * Unified block-device I/O interface for Xen guest OSes.
  5. *
  6. * Copyright (c) 2003-2004, Keir Fraser
  7. */
  8. #ifndef __XEN_PUBLIC_IO_BLKIF_H__
  9. #define __XEN_PUBLIC_IO_BLKIF_H__
  10. #include "ring.h"
  11. #include "../grant_table.h"
  12. /*
  13. * Front->back notifications: When enqueuing a new request, sending a
  14. * notification can be made conditional on req_event (i.e., the generic
  15. * hold-off mechanism provided by the ring macros). Backends must set
  16. * req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).
  17. *
  18. * Back->front notifications: When enqueuing a new response, sending a
  19. * notification can be made conditional on rsp_event (i.e., the generic
  20. * hold-off mechanism provided by the ring macros). Frontends must set
  21. * rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).
  22. */
  23. typedef uint16_t blkif_vdev_t;
  24. typedef uint64_t blkif_sector_t;
  25. /*
  26. * REQUEST CODES.
  27. */
  28. #define BLKIF_OP_READ 0
  29. #define BLKIF_OP_WRITE 1
  30. /*
  31. * Recognised only if "feature-barrier" is present in backend xenbus info.
  32. * The "feature_barrier" node contains a boolean indicating whether barrier
  33. * requests are likely to succeed or fail. Either way, a barrier request
  34. * may fail at any time with BLKIF_RSP_EOPNOTSUPP if it is unsupported by
  35. * the underlying block-device hardware. The boolean simply indicates whether
  36. * or not it is worthwhile for the frontend to attempt barrier requests.
  37. * If a backend does not recognise BLKIF_OP_WRITE_BARRIER, it should *not*
  38. * create the "feature-barrier" node!
  39. */
  40. #define BLKIF_OP_WRITE_BARRIER 2
  41. /*
  42. * Maximum scatter/gather segments per request.
  43. * This is carefully chosen so that sizeof(struct blkif_ring) <= PAGE_SIZE.
  44. * NB. This could be 12 if the ring indexes weren't stored in the same page.
  45. */
  46. #define BLKIF_MAX_SEGMENTS_PER_REQUEST 11
  47. struct blkif_request_rw {
  48. blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
  49. struct blkif_request_segment {
  50. grant_ref_t gref; /* reference to I/O buffer frame */
  51. /* @first_sect: first sector in frame to transfer (inclusive). */
  52. /* @last_sect: last sector in frame to transfer (inclusive). */
  53. uint8_t first_sect, last_sect;
  54. } seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
  55. };
  56. struct blkif_request {
  57. uint8_t operation; /* BLKIF_OP_??? */
  58. uint8_t nr_segments; /* number of segments */
  59. blkif_vdev_t handle; /* only for read/write requests */
  60. uint64_t id; /* private guest value, echoed in resp */
  61. union {
  62. struct blkif_request_rw rw;
  63. } u;
  64. };
  65. struct blkif_response {
  66. uint64_t id; /* copied from request */
  67. uint8_t operation; /* copied from request */
  68. int16_t status; /* BLKIF_RSP_??? */
  69. };
  70. /*
  71. * STATUS RETURN CODES.
  72. */
  73. /* Operation not supported (only happens on barrier writes). */
  74. #define BLKIF_RSP_EOPNOTSUPP -2
  75. /* Operation failed for some unspecified reason (-EIO). */
  76. #define BLKIF_RSP_ERROR -1
  77. /* Operation completed successfully. */
  78. #define BLKIF_RSP_OKAY 0
  79. /*
  80. * Generate blkif ring structures and types.
  81. */
  82. DEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response);
  83. #define VDISK_CDROM 0x1
  84. #define VDISK_REMOVABLE 0x2
  85. #define VDISK_READONLY 0x4
  86. /* Xen-defined major numbers for virtual disks, they look strangely
  87. * familiar */
  88. #define XEN_IDE0_MAJOR 3
  89. #define XEN_IDE1_MAJOR 22
  90. #define XEN_SCSI_DISK0_MAJOR 8
  91. #define XEN_SCSI_DISK1_MAJOR 65
  92. #define XEN_SCSI_DISK2_MAJOR 66
  93. #define XEN_SCSI_DISK3_MAJOR 67
  94. #define XEN_SCSI_DISK4_MAJOR 68
  95. #define XEN_SCSI_DISK5_MAJOR 69
  96. #define XEN_SCSI_DISK6_MAJOR 70
  97. #define XEN_SCSI_DISK7_MAJOR 71
  98. #define XEN_SCSI_DISK8_MAJOR 128
  99. #define XEN_SCSI_DISK9_MAJOR 129
  100. #define XEN_SCSI_DISK10_MAJOR 130
  101. #define XEN_SCSI_DISK11_MAJOR 131
  102. #define XEN_SCSI_DISK12_MAJOR 132
  103. #define XEN_SCSI_DISK13_MAJOR 133
  104. #define XEN_SCSI_DISK14_MAJOR 134
  105. #define XEN_SCSI_DISK15_MAJOR 135
  106. #endif /* __XEN_PUBLIC_IO_BLKIF_H__ */