blkif.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /******************************************************************************
  2. * blkif.h
  3. *
  4. * Unified block-device I/O interface for Xen guest OSes.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to
  8. * deal in the Software without restriction, including without limitation the
  9. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. * sell copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. * Copyright (c) 2003-2004, Keir Fraser
  25. * Copyright (c) 2012, Spectra Logic Corporation
  26. */
  27. #ifndef __XEN_PUBLIC_IO_BLKIF_H__
  28. #define __XEN_PUBLIC_IO_BLKIF_H__
  29. #include "ring.h"
  30. #include "../grant_table.h"
  31. /*
  32. * Front->back notifications: When enqueuing a new request, sending a
  33. * notification can be made conditional on req_event (i.e., the generic
  34. * hold-off mechanism provided by the ring macros). Backends must set
  35. * req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).
  36. *
  37. * Back->front notifications: When enqueuing a new response, sending a
  38. * notification can be made conditional on rsp_event (i.e., the generic
  39. * hold-off mechanism provided by the ring macros). Frontends must set
  40. * rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).
  41. */
  42. #ifndef blkif_vdev_t
  43. #define blkif_vdev_t uint16_t
  44. #endif
  45. #define blkif_sector_t uint64_t
  46. /*
  47. * Feature and Parameter Negotiation
  48. * =================================
  49. * The two halves of a Xen block driver utilize nodes within the XenStore to
  50. * communicate capabilities and to negotiate operating parameters. This
  51. * section enumerates these nodes which reside in the respective front and
  52. * backend portions of the XenStore, following the XenBus convention.
  53. *
  54. * All data in the XenStore is stored as strings. Nodes specifying numeric
  55. * values are encoded in decimal. Integer value ranges listed below are
  56. * expressed as fixed sized integer types capable of storing the conversion
  57. * of a properly formated node string, without loss of information.
  58. *
  59. * Any specified default value is in effect if the corresponding XenBus node
  60. * is not present in the XenStore.
  61. *
  62. * XenStore nodes in sections marked "PRIVATE" are solely for use by the
  63. * driver side whose XenBus tree contains them.
  64. *
  65. * XenStore nodes marked "DEPRECATED" in their notes section should only be
  66. * used to provide interoperability with legacy implementations.
  67. *
  68. * See the XenBus state transition diagram below for details on when XenBus
  69. * nodes must be published and when they can be queried.
  70. *
  71. *****************************************************************************
  72. * Backend XenBus Nodes
  73. *****************************************************************************
  74. *
  75. *------------------ Backend Device Identification (PRIVATE) ------------------
  76. *
  77. * mode
  78. * Values: "r" (read only), "w" (writable)
  79. *
  80. * The read or write access permissions to the backing store to be
  81. * granted to the frontend.
  82. *
  83. * params
  84. * Values: string
  85. *
  86. * A free formatted string providing sufficient information for the
  87. * backend driver to open the backing device. (e.g. the path to the
  88. * file or block device representing the backing store.)
  89. *
  90. * type
  91. * Values: "file", "phy", "tap"
  92. *
  93. * The type of the backing device/object.
  94. *
  95. *--------------------------------- Features ---------------------------------
  96. *
  97. * feature-barrier
  98. * Values: 0/1 (boolean)
  99. * Default Value: 0
  100. *
  101. * A value of "1" indicates that the backend can process requests
  102. * containing the BLKIF_OP_WRITE_BARRIER request opcode. Requests
  103. * of this type may still be returned at any time with the
  104. * BLKIF_RSP_EOPNOTSUPP result code.
  105. *
  106. * feature-flush-cache
  107. * Values: 0/1 (boolean)
  108. * Default Value: 0
  109. *
  110. * A value of "1" indicates that the backend can process requests
  111. * containing the BLKIF_OP_FLUSH_DISKCACHE request opcode. Requests
  112. * of this type may still be returned at any time with the
  113. * BLKIF_RSP_EOPNOTSUPP result code.
  114. *
  115. * feature-discard
  116. * Values: 0/1 (boolean)
  117. * Default Value: 0
  118. *
  119. * A value of "1" indicates that the backend can process requests
  120. * containing the BLKIF_OP_DISCARD request opcode. Requests
  121. * of this type may still be returned at any time with the
  122. * BLKIF_RSP_EOPNOTSUPP result code.
  123. *
  124. * feature-persistent
  125. * Values: 0/1 (boolean)
  126. * Default Value: 0
  127. * Notes: 7
  128. *
  129. * A value of "1" indicates that the backend can keep the grants used
  130. * by the frontend driver mapped, so the same set of grants should be
  131. * used in all transactions. The maximum number of grants the backend
  132. * can map persistently depends on the implementation, but ideally it
  133. * should be RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST. Using this
  134. * feature the backend doesn't need to unmap each grant, preventing
  135. * costly TLB flushes. The backend driver should only map grants
  136. * persistently if the frontend supports it. If a backend driver chooses
  137. * to use the persistent protocol when the frontend doesn't support it,
  138. * it will probably hit the maximum number of persistently mapped grants
  139. * (due to the fact that the frontend won't be reusing the same grants),
  140. * and fall back to non-persistent mode. Backend implementations may
  141. * shrink or expand the number of persistently mapped grants without
  142. * notifying the frontend depending on memory constraints (this might
  143. * cause a performance degradation).
  144. *
  145. * If a backend driver wants to limit the maximum number of persistently
  146. * mapped grants to a value less than RING_SIZE *
  147. * BLKIF_MAX_SEGMENTS_PER_REQUEST a LRU strategy should be used to
  148. * discard the grants that are less commonly used. Using a LRU in the
  149. * backend driver paired with a LIFO queue in the frontend will
  150. * allow us to have better performance in this scenario.
  151. *
  152. *----------------------- Request Transport Parameters ------------------------
  153. *
  154. * max-ring-page-order
  155. * Values: <uint32_t>
  156. * Default Value: 0
  157. * Notes: 1, 3
  158. *
  159. * The maximum supported size of the request ring buffer in units of
  160. * lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages,
  161. * etc.).
  162. *
  163. * max-ring-pages
  164. * Values: <uint32_t>
  165. * Default Value: 1
  166. * Notes: DEPRECATED, 2, 3
  167. *
  168. * The maximum supported size of the request ring buffer in units of
  169. * machine pages. The value must be a power of 2.
  170. *
  171. *------------------------- Backend Device Properties -------------------------
  172. *
  173. * discard-alignment
  174. * Values: <uint32_t>
  175. * Default Value: 0
  176. * Notes: 4, 5
  177. *
  178. * The offset, in bytes from the beginning of the virtual block device,
  179. * to the first, addressable, discard extent on the underlying device.
  180. *
  181. * discard-granularity
  182. * Values: <uint32_t>
  183. * Default Value: <"sector-size">
  184. * Notes: 4
  185. *
  186. * The size, in bytes, of the individually addressable discard extents
  187. * of the underlying device.
  188. *
  189. * discard-secure
  190. * Values: 0/1 (boolean)
  191. * Default Value: 0
  192. * Notes: 10
  193. *
  194. * A value of "1" indicates that the backend can process BLKIF_OP_DISCARD
  195. * requests with the BLKIF_DISCARD_SECURE flag set.
  196. *
  197. * info
  198. * Values: <uint32_t> (bitmap)
  199. *
  200. * A collection of bit flags describing attributes of the backing
  201. * device. The VDISK_* macros define the meaning of each bit
  202. * location.
  203. *
  204. * sector-size
  205. * Values: <uint32_t>
  206. *
  207. * The logical sector size, in bytes, of the backend device.
  208. *
  209. * physical-sector-size
  210. * Values: <uint32_t>
  211. *
  212. * The physical sector size, in bytes, of the backend device.
  213. *
  214. * sectors
  215. * Values: <uint64_t>
  216. *
  217. * The size of the backend device, expressed in units of its logical
  218. * sector size ("sector-size").
  219. *
  220. *****************************************************************************
  221. * Frontend XenBus Nodes
  222. *****************************************************************************
  223. *
  224. *----------------------- Request Transport Parameters -----------------------
  225. *
  226. * event-channel
  227. * Values: <uint32_t>
  228. *
  229. * The identifier of the Xen event channel used to signal activity
  230. * in the ring buffer.
  231. *
  232. * ring-ref
  233. * Values: <uint32_t>
  234. * Notes: 6
  235. *
  236. * The Xen grant reference granting permission for the backend to map
  237. * the sole page in a single page sized ring buffer.
  238. *
  239. * ring-ref%u
  240. * Values: <uint32_t>
  241. * Notes: 6
  242. *
  243. * For a frontend providing a multi-page ring, a "number of ring pages"
  244. * sized list of nodes, each containing a Xen grant reference granting
  245. * permission for the backend to map the page of the ring located
  246. * at page index "%u". Page indexes are zero based.
  247. *
  248. * protocol
  249. * Values: string (XEN_IO_PROTO_ABI_*)
  250. * Default Value: XEN_IO_PROTO_ABI_NATIVE
  251. *
  252. * The machine ABI rules governing the format of all ring request and
  253. * response structures.
  254. *
  255. * ring-page-order
  256. * Values: <uint32_t>
  257. * Default Value: 0
  258. * Maximum Value: MAX(ffs(max-ring-pages) - 1, max-ring-page-order)
  259. * Notes: 1, 3
  260. *
  261. * The size of the frontend allocated request ring buffer in units
  262. * of lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages,
  263. * etc.).
  264. *
  265. * num-ring-pages
  266. * Values: <uint32_t>
  267. * Default Value: 1
  268. * Maximum Value: MAX(max-ring-pages,(0x1 << max-ring-page-order))
  269. * Notes: DEPRECATED, 2, 3
  270. *
  271. * The size of the frontend allocated request ring buffer in units of
  272. * machine pages. The value must be a power of 2.
  273. *
  274. * feature-persistent
  275. * Values: 0/1 (boolean)
  276. * Default Value: 0
  277. * Notes: 7, 8, 9
  278. *
  279. * A value of "1" indicates that the frontend will reuse the same grants
  280. * for all transactions, allowing the backend to map them with write
  281. * access (even when it should be read-only). If the frontend hits the
  282. * maximum number of allowed persistently mapped grants, it can fallback
  283. * to non persistent mode. This will cause a performance degradation,
  284. * since the the backend driver will still try to map those grants
  285. * persistently. Since the persistent grants protocol is compatible with
  286. * the previous protocol, a frontend driver can choose to work in
  287. * persistent mode even when the backend doesn't support it.
  288. *
  289. * It is recommended that the frontend driver stores the persistently
  290. * mapped grants in a LIFO queue, so a subset of all persistently mapped
  291. * grants gets used commonly. This is done in case the backend driver
  292. * decides to limit the maximum number of persistently mapped grants
  293. * to a value less than RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST.
  294. *
  295. *------------------------- Virtual Device Properties -------------------------
  296. *
  297. * device-type
  298. * Values: "disk", "cdrom", "floppy", etc.
  299. *
  300. * virtual-device
  301. * Values: <uint32_t>
  302. *
  303. * A value indicating the physical device to virtualize within the
  304. * frontend's domain. (e.g. "The first ATA disk", "The third SCSI
  305. * disk", etc.)
  306. *
  307. * See docs/misc/vbd-interface.txt for details on the format of this
  308. * value.
  309. *
  310. * Notes
  311. * -----
  312. * (1) Multi-page ring buffer scheme first developed in the Citrix XenServer
  313. * PV drivers.
  314. * (2) Multi-page ring buffer scheme first used in some RedHat distributions
  315. * including a distribution deployed on certain nodes of the Amazon
  316. * EC2 cluster.
  317. * (3) Support for multi-page ring buffers was implemented independently,
  318. * in slightly different forms, by both Citrix and RedHat/Amazon.
  319. * For full interoperability, block front and backends should publish
  320. * identical ring parameters, adjusted for unit differences, to the
  321. * XenStore nodes used in both schemes.
  322. * (4) Devices that support discard functionality may internally allocate space
  323. * (discardable extents) in units that are larger than the exported logical
  324. * block size. If the backing device has such discardable extents the
  325. * backend should provide both discard-granularity and discard-alignment.
  326. * Providing just one of the two may be considered an error by the frontend.
  327. * Backends supporting discard should include discard-granularity and
  328. * discard-alignment even if it supports discarding individual sectors.
  329. * Frontends should assume discard-alignment == 0 and discard-granularity
  330. * == sector size if these keys are missing.
  331. * (5) The discard-alignment parameter allows a physical device to be
  332. * partitioned into virtual devices that do not necessarily begin or
  333. * end on a discardable extent boundary.
  334. * (6) When there is only a single page allocated to the request ring,
  335. * 'ring-ref' is used to communicate the grant reference for this
  336. * page to the backend. When using a multi-page ring, the 'ring-ref'
  337. * node is not created. Instead 'ring-ref0' - 'ring-refN' are used.
  338. * (7) When using persistent grants data has to be copied from/to the page
  339. * where the grant is currently mapped. The overhead of doing this copy
  340. * however doesn't suppress the speed improvement of not having to unmap
  341. * the grants.
  342. * (8) The frontend driver has to allow the backend driver to map all grants
  343. * with write access, even when they should be mapped read-only, since
  344. * further requests may reuse these grants and require write permissions.
  345. * (9) Linux implementation doesn't have a limit on the maximum number of
  346. * grants that can be persistently mapped in the frontend driver, but
  347. * due to the frontent driver implementation it should never be bigger
  348. * than RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST.
  349. *(10) The discard-secure property may be present and will be set to 1 if the
  350. * backing device supports secure discard.
  351. */
  352. /*
  353. * STATE DIAGRAMS
  354. *
  355. *****************************************************************************
  356. * Startup *
  357. *****************************************************************************
  358. *
  359. * Tool stack creates front and back nodes with state XenbusStateInitialising.
  360. *
  361. * Front Back
  362. * ================================= =====================================
  363. * XenbusStateInitialising XenbusStateInitialising
  364. * o Query virtual device o Query backend device identification
  365. * properties. data.
  366. * o Setup OS device instance. o Open and validate backend device.
  367. * o Publish backend features and
  368. * transport parameters.
  369. * |
  370. * |
  371. * V
  372. * XenbusStateInitWait
  373. *
  374. * o Query backend features and
  375. * transport parameters.
  376. * o Allocate and initialize the
  377. * request ring.
  378. * o Publish transport parameters
  379. * that will be in effect during
  380. * this connection.
  381. * |
  382. * |
  383. * V
  384. * XenbusStateInitialised
  385. *
  386. * o Query frontend transport parameters.
  387. * o Connect to the request ring and
  388. * event channel.
  389. * o Publish backend device properties.
  390. * |
  391. * |
  392. * V
  393. * XenbusStateConnected
  394. *
  395. * o Query backend device properties.
  396. * o Finalize OS virtual device
  397. * instance.
  398. * |
  399. * |
  400. * V
  401. * XenbusStateConnected
  402. *
  403. * Note: Drivers that do not support any optional features, or the negotiation
  404. * of transport parameters, can skip certain states in the state machine:
  405. *
  406. * o A frontend may transition to XenbusStateInitialised without
  407. * waiting for the backend to enter XenbusStateInitWait. In this
  408. * case, default transport parameters are in effect and any
  409. * transport parameters published by the frontend must contain
  410. * their default values.
  411. *
  412. * o A backend may transition to XenbusStateInitialised, bypassing
  413. * XenbusStateInitWait, without waiting for the frontend to first
  414. * enter the XenbusStateInitialised state. In this case, default
  415. * transport parameters are in effect and any transport parameters
  416. * published by the backend must contain their default values.
  417. *
  418. * Drivers that support optional features and/or transport parameter
  419. * negotiation must tolerate these additional state transition paths.
  420. * In general this means performing the work of any skipped state
  421. * transition, if it has not already been performed, in addition to the
  422. * work associated with entry into the current state.
  423. */
  424. /*
  425. * REQUEST CODES.
  426. */
  427. #define BLKIF_OP_READ 0
  428. #define BLKIF_OP_WRITE 1
  429. /*
  430. * All writes issued prior to a request with the BLKIF_OP_WRITE_BARRIER
  431. * operation code ("barrier request") must be completed prior to the
  432. * execution of the barrier request. All writes issued after the barrier
  433. * request must not execute until after the completion of the barrier request.
  434. *
  435. * Optional. See "feature-barrier" XenBus node documentation above.
  436. */
  437. #define BLKIF_OP_WRITE_BARRIER 2
  438. /*
  439. * Commit any uncommitted contents of the backing device's volatile cache
  440. * to stable storage.
  441. *
  442. * Optional. See "feature-flush-cache" XenBus node documentation above.
  443. */
  444. #define BLKIF_OP_FLUSH_DISKCACHE 3
  445. /*
  446. * Used in SLES sources for device specific command packet
  447. * contained within the request. Reserved for that purpose.
  448. */
  449. #define BLKIF_OP_RESERVED_1 4
  450. /*
  451. * Indicate to the backend device that a region of storage is no longer in
  452. * use, and may be discarded at any time without impact to the client. If
  453. * the BLKIF_DISCARD_SECURE flag is set on the request, all copies of the
  454. * discarded region on the device must be rendered unrecoverable before the
  455. * command returns.
  456. *
  457. * This operation is analogous to performing a trim (ATA) or unamp (SCSI),
  458. * command on a native device.
  459. *
  460. * More information about trim/unmap operations can be found at:
  461. * http://t13.org/Documents/UploadedDocuments/docs2008/
  462. * e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc
  463. * http://www.seagate.com/staticfiles/support/disc/manuals/
  464. * Interface%20manuals/100293068c.pdf
  465. *
  466. * Optional. See "feature-discard", "discard-alignment",
  467. * "discard-granularity", and "discard-secure" in the XenBus node
  468. * documentation above.
  469. */
  470. #define BLKIF_OP_DISCARD 5
  471. /*
  472. * Recognized if "feature-max-indirect-segments" in present in the backend
  473. * xenbus info. The "feature-max-indirect-segments" node contains the maximum
  474. * number of segments allowed by the backend per request. If the node is
  475. * present, the frontend might use blkif_request_indirect structs in order to
  476. * issue requests with more than BLKIF_MAX_SEGMENTS_PER_REQUEST (11). The
  477. * maximum number of indirect segments is fixed by the backend, but the
  478. * frontend can issue requests with any number of indirect segments as long as
  479. * it's less than the number provided by the backend. The indirect_grefs field
  480. * in blkif_request_indirect should be filled by the frontend with the
  481. * grant references of the pages that are holding the indirect segments.
  482. * These pages are filled with an array of blkif_request_segment that hold the
  483. * information about the segments. The number of indirect pages to use is
  484. * determined by the number of segments an indirect request contains. Every
  485. * indirect page can contain a maximum of
  486. * (PAGE_SIZE / sizeof(struct blkif_request_segment)) segments, so to
  487. * calculate the number of indirect pages to use we have to do
  488. * ceil(indirect_segments / (PAGE_SIZE / sizeof(struct blkif_request_segment))).
  489. *
  490. * If a backend does not recognize BLKIF_OP_INDIRECT, it should *not*
  491. * create the "feature-max-indirect-segments" node!
  492. */
  493. #define BLKIF_OP_INDIRECT 6
  494. /*
  495. * Maximum scatter/gather segments per request.
  496. * This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE.
  497. * NB. This could be 12 if the ring indexes weren't stored in the same page.
  498. */
  499. #define BLKIF_MAX_SEGMENTS_PER_REQUEST 11
  500. /*
  501. * Maximum number of indirect pages to use per request.
  502. */
  503. #define BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST 8
  504. /*
  505. * NB. first_sect and last_sect in blkif_request_segment, as well as
  506. * sector_number in blkif_request, are always expressed in 512-byte units.
  507. * However they must be properly aligned to the real sector size of the
  508. * physical disk, which is reported in the "physical-sector-size" node in
  509. * the backend xenbus info. Also the xenbus "sectors" node is expressed in
  510. * 512-byte units.
  511. */
  512. struct blkif_request_segment {
  513. grant_ref_t gref; /* reference to I/O buffer frame */
  514. /* @first_sect: first sector in frame to transfer (inclusive). */
  515. /* @last_sect: last sector in frame to transfer (inclusive). */
  516. uint8_t first_sect, last_sect;
  517. };
  518. /*
  519. * Starting ring element for any I/O request.
  520. */
  521. struct blkif_request {
  522. uint8_t operation; /* BLKIF_OP_??? */
  523. uint8_t nr_segments; /* number of segments */
  524. blkif_vdev_t handle; /* only for read/write requests */
  525. uint64_t id; /* private guest value, echoed in resp */
  526. blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
  527. struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
  528. };
  529. typedef struct blkif_request blkif_request_t;
  530. /*
  531. * Cast to this structure when blkif_request.operation == BLKIF_OP_DISCARD
  532. * sizeof(struct blkif_request_discard) <= sizeof(struct blkif_request)
  533. */
  534. struct blkif_request_discard {
  535. uint8_t operation; /* BLKIF_OP_DISCARD */
  536. uint8_t flag; /* BLKIF_DISCARD_SECURE or zero */
  537. #define BLKIF_DISCARD_SECURE (1<<0) /* ignored if discard-secure=0 */
  538. blkif_vdev_t handle; /* same as for read/write requests */
  539. uint64_t id; /* private guest value, echoed in resp */
  540. blkif_sector_t sector_number;/* start sector idx on disk */
  541. uint64_t nr_sectors; /* number of contiguous sectors to discard*/
  542. };
  543. typedef struct blkif_request_discard blkif_request_discard_t;
  544. struct blkif_request_indirect {
  545. uint8_t operation; /* BLKIF_OP_INDIRECT */
  546. uint8_t indirect_op; /* BLKIF_OP_{READ/WRITE} */
  547. uint16_t nr_segments; /* number of segments */
  548. uint64_t id; /* private guest value, echoed in resp */
  549. blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
  550. blkif_vdev_t handle; /* same as for read/write requests */
  551. grant_ref_t indirect_grefs[BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST];
  552. #ifdef __i386__
  553. uint64_t pad; /* Make it 64 byte aligned on i386 */
  554. #endif
  555. };
  556. typedef struct blkif_request_indirect blkif_request_indirect_t;
  557. struct blkif_response {
  558. uint64_t id; /* copied from request */
  559. uint8_t operation; /* copied from request */
  560. int16_t status; /* BLKIF_RSP_??? */
  561. };
  562. typedef struct blkif_response blkif_response_t;
  563. /*
  564. * STATUS RETURN CODES.
  565. */
  566. /* Operation not supported (only happens on barrier writes). */
  567. #define BLKIF_RSP_EOPNOTSUPP -2
  568. /* Operation failed for some unspecified reason (-EIO). */
  569. #define BLKIF_RSP_ERROR -1
  570. /* Operation completed successfully. */
  571. #define BLKIF_RSP_OKAY 0
  572. /*
  573. * Generate blkif ring structures and types.
  574. */
  575. DEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response);
  576. #define VDISK_CDROM 0x1
  577. #define VDISK_REMOVABLE 0x2
  578. #define VDISK_READONLY 0x4
  579. #endif /* __XEN_PUBLIC_IO_BLKIF_H__ */
  580. /*
  581. * Local variables:
  582. * mode: C
  583. * c-file-style: "BSD"
  584. * c-basic-offset: 4
  585. * tab-width: 4
  586. * indent-tabs-mode: nil
  587. * End:
  588. */