blkif.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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. * hotplug script to attach the device and provide a suitable
  88. * handler (ie: a block device) for blkback to use.
  89. *
  90. * physical-device
  91. * Values: "MAJOR:MINOR"
  92. * Notes: 11
  93. *
  94. * MAJOR and MINOR are the major number and minor number of the
  95. * backing device respectively.
  96. *
  97. * physical-device-path
  98. * Values: path string
  99. *
  100. * A string that contains the absolute path to the disk image. On
  101. * NetBSD and Linux this is always a block device, while on FreeBSD
  102. * it can be either a block device or a regular file.
  103. *
  104. * type
  105. * Values: "file", "phy", "tap"
  106. *
  107. * The type of the backing device/object.
  108. *
  109. *
  110. * direct-io-safe
  111. * Values: 0/1 (boolean)
  112. * Default Value: 0
  113. *
  114. * The underlying storage is not affected by the direct IO memory
  115. * lifetime bug. See:
  116. * http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html
  117. *
  118. * Therefore this option gives the backend permission to use
  119. * O_DIRECT, notwithstanding that bug.
  120. *
  121. * That is, if this option is enabled, use of O_DIRECT is safe,
  122. * in circumstances where we would normally have avoided it as a
  123. * workaround for that bug. This option is not relevant for all
  124. * backends, and even not necessarily supported for those for
  125. * which it is relevant. A backend which knows that it is not
  126. * affected by the bug can ignore this option.
  127. *
  128. * This option doesn't require a backend to use O_DIRECT, so it
  129. * should not be used to try to control the caching behaviour.
  130. *
  131. *--------------------------------- Features ---------------------------------
  132. *
  133. * feature-barrier
  134. * Values: 0/1 (boolean)
  135. * Default Value: 0
  136. *
  137. * A value of "1" indicates that the backend can process requests
  138. * containing the BLKIF_OP_WRITE_BARRIER request opcode. Requests
  139. * of this type may still be returned at any time with the
  140. * BLKIF_RSP_EOPNOTSUPP result code.
  141. *
  142. * feature-flush-cache
  143. * Values: 0/1 (boolean)
  144. * Default Value: 0
  145. *
  146. * A value of "1" indicates that the backend can process requests
  147. * containing the BLKIF_OP_FLUSH_DISKCACHE request opcode. Requests
  148. * of this type may still be returned at any time with the
  149. * BLKIF_RSP_EOPNOTSUPP result code.
  150. *
  151. * feature-discard
  152. * Values: 0/1 (boolean)
  153. * Default Value: 0
  154. *
  155. * A value of "1" indicates that the backend can process requests
  156. * containing the BLKIF_OP_DISCARD request opcode. Requests
  157. * of this type may still be returned at any time with the
  158. * BLKIF_RSP_EOPNOTSUPP result code.
  159. *
  160. * feature-persistent
  161. * Values: 0/1 (boolean)
  162. * Default Value: 0
  163. * Notes: 7
  164. *
  165. * A value of "1" indicates that the backend can keep the grants used
  166. * by the frontend driver mapped, so the same set of grants should be
  167. * used in all transactions. The maximum number of grants the backend
  168. * can map persistently depends on the implementation, but ideally it
  169. * should be RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST. Using this
  170. * feature the backend doesn't need to unmap each grant, preventing
  171. * costly TLB flushes. The backend driver should only map grants
  172. * persistently if the frontend supports it. If a backend driver chooses
  173. * to use the persistent protocol when the frontend doesn't support it,
  174. * it will probably hit the maximum number of persistently mapped grants
  175. * (due to the fact that the frontend won't be reusing the same grants),
  176. * and fall back to non-persistent mode. Backend implementations may
  177. * shrink or expand the number of persistently mapped grants without
  178. * notifying the frontend depending on memory constraints (this might
  179. * cause a performance degradation).
  180. *
  181. * If a backend driver wants to limit the maximum number of persistently
  182. * mapped grants to a value less than RING_SIZE *
  183. * BLKIF_MAX_SEGMENTS_PER_REQUEST a LRU strategy should be used to
  184. * discard the grants that are less commonly used. Using a LRU in the
  185. * backend driver paired with a LIFO queue in the frontend will
  186. * allow us to have better performance in this scenario.
  187. *
  188. *----------------------- Request Transport Parameters ------------------------
  189. *
  190. * max-ring-page-order
  191. * Values: <uint32_t>
  192. * Default Value: 0
  193. * Notes: 1, 3
  194. *
  195. * The maximum supported size of the request ring buffer in units of
  196. * lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages,
  197. * etc.).
  198. *
  199. * max-ring-pages
  200. * Values: <uint32_t>
  201. * Default Value: 1
  202. * Notes: DEPRECATED, 2, 3
  203. *
  204. * The maximum supported size of the request ring buffer in units of
  205. * machine pages. The value must be a power of 2.
  206. *
  207. *------------------------- Backend Device Properties -------------------------
  208. *
  209. * discard-enable
  210. * Values: 0/1 (boolean)
  211. * Default Value: 1
  212. *
  213. * This optional property, set by the toolstack, instructs the backend
  214. * to offer (or not to offer) discard to the frontend. If the property
  215. * is missing the backend should offer discard if the backing storage
  216. * actually supports it.
  217. *
  218. * discard-alignment
  219. * Values: <uint32_t>
  220. * Default Value: 0
  221. * Notes: 4, 5
  222. *
  223. * The offset, in bytes from the beginning of the virtual block device,
  224. * to the first, addressable, discard extent on the underlying device.
  225. *
  226. * discard-granularity
  227. * Values: <uint32_t>
  228. * Default Value: <"sector-size">
  229. * Notes: 4
  230. *
  231. * The size, in bytes, of the individually addressable discard extents
  232. * of the underlying device.
  233. *
  234. * discard-secure
  235. * Values: 0/1 (boolean)
  236. * Default Value: 0
  237. * Notes: 10
  238. *
  239. * A value of "1" indicates that the backend can process BLKIF_OP_DISCARD
  240. * requests with the BLKIF_DISCARD_SECURE flag set.
  241. *
  242. * info
  243. * Values: <uint32_t> (bitmap)
  244. *
  245. * A collection of bit flags describing attributes of the backing
  246. * device. The VDISK_* macros define the meaning of each bit
  247. * location.
  248. *
  249. * sector-size
  250. * Values: <uint32_t>
  251. *
  252. * The logical block size, in bytes, of the underlying storage. This
  253. * must be a power of two with a minimum value of 512.
  254. *
  255. * NOTE: Because of implementation bugs in some frontends this must be
  256. * set to 512, unless the frontend advertizes a non-zero value
  257. * in its "feature-large-sector-size" xenbus node. (See below).
  258. *
  259. * physical-sector-size
  260. * Values: <uint32_t>
  261. * Default Value: <"sector-size">
  262. *
  263. * The physical block size, in bytes, of the backend storage. This
  264. * must be an integer multiple of "sector-size".
  265. *
  266. * sectors
  267. * Values: <uint64_t>
  268. *
  269. * The size of the backend device, expressed in units of "sector-size".
  270. * The product of "sector-size" and "sectors" must also be an integer
  271. * multiple of "physical-sector-size", if that node is present.
  272. *
  273. *****************************************************************************
  274. * Frontend XenBus Nodes
  275. *****************************************************************************
  276. *
  277. *----------------------- Request Transport Parameters -----------------------
  278. *
  279. * event-channel
  280. * Values: <uint32_t>
  281. *
  282. * The identifier of the Xen event channel used to signal activity
  283. * in the ring buffer.
  284. *
  285. * ring-ref
  286. * Values: <uint32_t>
  287. * Notes: 6
  288. *
  289. * The Xen grant reference granting permission for the backend to map
  290. * the sole page in a single page sized ring buffer.
  291. *
  292. * ring-ref%u
  293. * Values: <uint32_t>
  294. * Notes: 6
  295. *
  296. * For a frontend providing a multi-page ring, a "number of ring pages"
  297. * sized list of nodes, each containing a Xen grant reference granting
  298. * permission for the backend to map the page of the ring located
  299. * at page index "%u". Page indexes are zero based.
  300. *
  301. * protocol
  302. * Values: string (XEN_IO_PROTO_ABI_*)
  303. * Default Value: XEN_IO_PROTO_ABI_NATIVE
  304. *
  305. * The machine ABI rules governing the format of all ring request and
  306. * response structures.
  307. *
  308. * ring-page-order
  309. * Values: <uint32_t>
  310. * Default Value: 0
  311. * Maximum Value: MAX(ffs(max-ring-pages) - 1, max-ring-page-order)
  312. * Notes: 1, 3
  313. *
  314. * The size of the frontend allocated request ring buffer in units
  315. * of lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages,
  316. * etc.).
  317. *
  318. * num-ring-pages
  319. * Values: <uint32_t>
  320. * Default Value: 1
  321. * Maximum Value: MAX(max-ring-pages,(0x1 << max-ring-page-order))
  322. * Notes: DEPRECATED, 2, 3
  323. *
  324. * The size of the frontend allocated request ring buffer in units of
  325. * machine pages. The value must be a power of 2.
  326. *
  327. *--------------------------------- Features ---------------------------------
  328. *
  329. * feature-persistent
  330. * Values: 0/1 (boolean)
  331. * Default Value: 0
  332. * Notes: 7, 8, 9
  333. *
  334. * A value of "1" indicates that the frontend will reuse the same grants
  335. * for all transactions, allowing the backend to map them with write
  336. * access (even when it should be read-only). If the frontend hits the
  337. * maximum number of allowed persistently mapped grants, it can fallback
  338. * to non persistent mode. This will cause a performance degradation,
  339. * since the backend driver will still try to map those grants
  340. * persistently. Since the persistent grants protocol is compatible with
  341. * the previous protocol, a frontend driver can choose to work in
  342. * persistent mode even when the backend doesn't support it.
  343. *
  344. * It is recommended that the frontend driver stores the persistently
  345. * mapped grants in a LIFO queue, so a subset of all persistently mapped
  346. * grants gets used commonly. This is done in case the backend driver
  347. * decides to limit the maximum number of persistently mapped grants
  348. * to a value less than RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST.
  349. *
  350. * feature-large-sector-size
  351. * Values: 0/1 (boolean)
  352. * Default Value: 0
  353. *
  354. * A value of "1" indicates that the frontend will correctly supply and
  355. * interpret all sector-based quantities in terms of the "sector-size"
  356. * value supplied in the backend info, whatever that may be set to.
  357. * If this node is not present or its value is "0" then it is assumed
  358. * that the frontend requires that the logical block size is 512 as it
  359. * is hardcoded (which is the case in some frontend implementations).
  360. *
  361. *------------------------- Virtual Device Properties -------------------------
  362. *
  363. * device-type
  364. * Values: "disk", "cdrom", "floppy", etc.
  365. *
  366. * virtual-device
  367. * Values: <uint32_t>
  368. *
  369. * A value indicating the physical device to virtualize within the
  370. * frontend's domain. (e.g. "The first ATA disk", "The third SCSI
  371. * disk", etc.)
  372. *
  373. * See docs/misc/vbd-interface.txt for details on the format of this
  374. * value.
  375. *
  376. * Notes
  377. * -----
  378. * (1) Multi-page ring buffer scheme first developed in the Citrix XenServer
  379. * PV drivers.
  380. * (2) Multi-page ring buffer scheme first used in some RedHat distributions
  381. * including a distribution deployed on certain nodes of the Amazon
  382. * EC2 cluster.
  383. * (3) Support for multi-page ring buffers was implemented independently,
  384. * in slightly different forms, by both Citrix and RedHat/Amazon.
  385. * For full interoperability, block front and backends should publish
  386. * identical ring parameters, adjusted for unit differences, to the
  387. * XenStore nodes used in both schemes.
  388. * (4) Devices that support discard functionality may internally allocate space
  389. * (discardable extents) in units that are larger than the exported logical
  390. * block size. If the backing device has such discardable extents the
  391. * backend should provide both discard-granularity and discard-alignment.
  392. * Providing just one of the two may be considered an error by the frontend.
  393. * Backends supporting discard should include discard-granularity and
  394. * discard-alignment even if it supports discarding individual sectors.
  395. * Frontends should assume discard-alignment == 0 and discard-granularity
  396. * == sector size if these keys are missing.
  397. * (5) The discard-alignment parameter allows a physical device to be
  398. * partitioned into virtual devices that do not necessarily begin or
  399. * end on a discardable extent boundary.
  400. * (6) When there is only a single page allocated to the request ring,
  401. * 'ring-ref' is used to communicate the grant reference for this
  402. * page to the backend. When using a multi-page ring, the 'ring-ref'
  403. * node is not created. Instead 'ring-ref0' - 'ring-refN' are used.
  404. * (7) When using persistent grants data has to be copied from/to the page
  405. * where the grant is currently mapped. The overhead of doing this copy
  406. * however doesn't suppress the speed improvement of not having to unmap
  407. * the grants.
  408. * (8) The frontend driver has to allow the backend driver to map all grants
  409. * with write access, even when they should be mapped read-only, since
  410. * further requests may reuse these grants and require write permissions.
  411. * (9) Linux implementation doesn't have a limit on the maximum number of
  412. * grants that can be persistently mapped in the frontend driver, but
  413. * due to the frontent driver implementation it should never be bigger
  414. * than RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST.
  415. *(10) The discard-secure property may be present and will be set to 1 if the
  416. * backing device supports secure discard.
  417. *(11) Only used by Linux and NetBSD.
  418. */
  419. /*
  420. * Multiple hardware queues/rings:
  421. * If supported, the backend will write the key "multi-queue-max-queues" to
  422. * the directory for that vbd, and set its value to the maximum supported
  423. * number of queues.
  424. * Frontends that are aware of this feature and wish to use it can write the
  425. * key "multi-queue-num-queues" with the number they wish to use, which must be
  426. * greater than zero, and no more than the value reported by the backend in
  427. * "multi-queue-max-queues".
  428. *
  429. * For frontends requesting just one queue, the usual event-channel and
  430. * ring-ref keys are written as before, simplifying the backend processing
  431. * to avoid distinguishing between a frontend that doesn't understand the
  432. * multi-queue feature, and one that does, but requested only one queue.
  433. *
  434. * Frontends requesting two or more queues must not write the toplevel
  435. * event-channel and ring-ref keys, instead writing those keys under sub-keys
  436. * having the name "queue-N" where N is the integer ID of the queue/ring for
  437. * which those keys belong. Queues are indexed from zero.
  438. * For example, a frontend with two queues must write the following set of
  439. * queue-related keys:
  440. *
  441. * /local/domain/1/device/vbd/0/multi-queue-num-queues = "2"
  442. * /local/domain/1/device/vbd/0/queue-0 = ""
  443. * /local/domain/1/device/vbd/0/queue-0/ring-ref = "<ring-ref#0>"
  444. * /local/domain/1/device/vbd/0/queue-0/event-channel = "<evtchn#0>"
  445. * /local/domain/1/device/vbd/0/queue-1 = ""
  446. * /local/domain/1/device/vbd/0/queue-1/ring-ref = "<ring-ref#1>"
  447. * /local/domain/1/device/vbd/0/queue-1/event-channel = "<evtchn#1>"
  448. *
  449. * It is also possible to use multiple queues/rings together with
  450. * feature multi-page ring buffer.
  451. * For example, a frontend requests two queues/rings and the size of each ring
  452. * buffer is two pages must write the following set of related keys:
  453. *
  454. * /local/domain/1/device/vbd/0/multi-queue-num-queues = "2"
  455. * /local/domain/1/device/vbd/0/ring-page-order = "1"
  456. * /local/domain/1/device/vbd/0/queue-0 = ""
  457. * /local/domain/1/device/vbd/0/queue-0/ring-ref0 = "<ring-ref#0>"
  458. * /local/domain/1/device/vbd/0/queue-0/ring-ref1 = "<ring-ref#1>"
  459. * /local/domain/1/device/vbd/0/queue-0/event-channel = "<evtchn#0>"
  460. * /local/domain/1/device/vbd/0/queue-1 = ""
  461. * /local/domain/1/device/vbd/0/queue-1/ring-ref0 = "<ring-ref#2>"
  462. * /local/domain/1/device/vbd/0/queue-1/ring-ref1 = "<ring-ref#3>"
  463. * /local/domain/1/device/vbd/0/queue-1/event-channel = "<evtchn#1>"
  464. *
  465. */
  466. /*
  467. * STATE DIAGRAMS
  468. *
  469. *****************************************************************************
  470. * Startup *
  471. *****************************************************************************
  472. *
  473. * Tool stack creates front and back nodes with state XenbusStateInitialising.
  474. *
  475. * Front Back
  476. * ================================= =====================================
  477. * XenbusStateInitialising XenbusStateInitialising
  478. * o Query virtual device o Query backend device identification
  479. * properties. data.
  480. * o Setup OS device instance. o Open and validate backend device.
  481. * o Publish backend features and
  482. * transport parameters.
  483. * |
  484. * |
  485. * V
  486. * XenbusStateInitWait
  487. *
  488. * o Query backend features and
  489. * transport parameters.
  490. * o Allocate and initialize the
  491. * request ring.
  492. * o Publish transport parameters
  493. * that will be in effect during
  494. * this connection.
  495. * |
  496. * |
  497. * V
  498. * XenbusStateInitialised
  499. *
  500. * o Query frontend transport parameters.
  501. * o Connect to the request ring and
  502. * event channel.
  503. * o Publish backend device properties.
  504. * |
  505. * |
  506. * V
  507. * XenbusStateConnected
  508. *
  509. * o Query backend device properties.
  510. * o Finalize OS virtual device
  511. * instance.
  512. * |
  513. * |
  514. * V
  515. * XenbusStateConnected
  516. *
  517. * Note: Drivers that do not support any optional features, or the negotiation
  518. * of transport parameters, can skip certain states in the state machine:
  519. *
  520. * o A frontend may transition to XenbusStateInitialised without
  521. * waiting for the backend to enter XenbusStateInitWait. In this
  522. * case, default transport parameters are in effect and any
  523. * transport parameters published by the frontend must contain
  524. * their default values.
  525. *
  526. * o A backend may transition to XenbusStateInitialised, bypassing
  527. * XenbusStateInitWait, without waiting for the frontend to first
  528. * enter the XenbusStateInitialised state. In this case, default
  529. * transport parameters are in effect and any transport parameters
  530. * published by the backend must contain their default values.
  531. *
  532. * Drivers that support optional features and/or transport parameter
  533. * negotiation must tolerate these additional state transition paths.
  534. * In general this means performing the work of any skipped state
  535. * transition, if it has not already been performed, in addition to the
  536. * work associated with entry into the current state.
  537. */
  538. /*
  539. * REQUEST CODES.
  540. */
  541. #define BLKIF_OP_READ 0
  542. #define BLKIF_OP_WRITE 1
  543. /*
  544. * All writes issued prior to a request with the BLKIF_OP_WRITE_BARRIER
  545. * operation code ("barrier request") must be completed prior to the
  546. * execution of the barrier request. All writes issued after the barrier
  547. * request must not execute until after the completion of the barrier request.
  548. *
  549. * Optional. See "feature-barrier" XenBus node documentation above.
  550. */
  551. #define BLKIF_OP_WRITE_BARRIER 2
  552. /*
  553. * Commit any uncommitted contents of the backing device's volatile cache
  554. * to stable storage.
  555. *
  556. * Optional. See "feature-flush-cache" XenBus node documentation above.
  557. */
  558. #define BLKIF_OP_FLUSH_DISKCACHE 3
  559. /*
  560. * Used in SLES sources for device specific command packet
  561. * contained within the request. Reserved for that purpose.
  562. */
  563. #define BLKIF_OP_RESERVED_1 4
  564. /*
  565. * Indicate to the backend device that a region of storage is no longer in
  566. * use, and may be discarded at any time without impact to the client. If
  567. * the BLKIF_DISCARD_SECURE flag is set on the request, all copies of the
  568. * discarded region on the device must be rendered unrecoverable before the
  569. * command returns.
  570. *
  571. * This operation is analogous to performing a trim (ATA) or unamp (SCSI),
  572. * command on a native device.
  573. *
  574. * More information about trim/unmap operations can be found at:
  575. * http://t13.org/Documents/UploadedDocuments/docs2008/
  576. * e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc
  577. * http://www.seagate.com/staticfiles/support/disc/manuals/
  578. * Interface%20manuals/100293068c.pdf
  579. *
  580. * Optional. See "feature-discard", "discard-alignment",
  581. * "discard-granularity", and "discard-secure" in the XenBus node
  582. * documentation above.
  583. */
  584. #define BLKIF_OP_DISCARD 5
  585. /*
  586. * Recognized if "feature-max-indirect-segments" in present in the backend
  587. * xenbus info. The "feature-max-indirect-segments" node contains the maximum
  588. * number of segments allowed by the backend per request. If the node is
  589. * present, the frontend might use blkif_request_indirect structs in order to
  590. * issue requests with more than BLKIF_MAX_SEGMENTS_PER_REQUEST (11). The
  591. * maximum number of indirect segments is fixed by the backend, but the
  592. * frontend can issue requests with any number of indirect segments as long as
  593. * it's less than the number provided by the backend. The indirect_grefs field
  594. * in blkif_request_indirect should be filled by the frontend with the
  595. * grant references of the pages that are holding the indirect segments.
  596. * These pages are filled with an array of blkif_request_segment that hold the
  597. * information about the segments. The number of indirect pages to use is
  598. * determined by the number of segments an indirect request contains. Every
  599. * indirect page can contain a maximum of
  600. * (PAGE_SIZE / sizeof(struct blkif_request_segment)) segments, so to
  601. * calculate the number of indirect pages to use we have to do
  602. * ceil(indirect_segments / (PAGE_SIZE / sizeof(struct blkif_request_segment))).
  603. *
  604. * If a backend does not recognize BLKIF_OP_INDIRECT, it should *not*
  605. * create the "feature-max-indirect-segments" node!
  606. */
  607. #define BLKIF_OP_INDIRECT 6
  608. /*
  609. * Maximum scatter/gather segments per request.
  610. * This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE.
  611. * NB. This could be 12 if the ring indexes weren't stored in the same page.
  612. */
  613. #define BLKIF_MAX_SEGMENTS_PER_REQUEST 11
  614. /*
  615. * Maximum number of indirect pages to use per request.
  616. */
  617. #define BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST 8
  618. /*
  619. * NB. 'first_sect' and 'last_sect' in blkif_request_segment, as well as
  620. * 'sector_number' in blkif_request, blkif_request_discard and
  621. * blkif_request_indirect are sector-based quantities. See the description
  622. * of the "feature-large-sector-size" frontend xenbus node above for
  623. * more information.
  624. */
  625. struct blkif_request_segment {
  626. grant_ref_t gref; /* reference to I/O buffer frame */
  627. /* @first_sect: first sector in frame to transfer (inclusive). */
  628. /* @last_sect: last sector in frame to transfer (inclusive). */
  629. uint8_t first_sect, last_sect;
  630. };
  631. /*
  632. * Starting ring element for any I/O request.
  633. */
  634. struct blkif_request {
  635. uint8_t operation; /* BLKIF_OP_??? */
  636. uint8_t nr_segments; /* number of segments */
  637. blkif_vdev_t handle; /* only for read/write requests */
  638. uint64_t id; /* private guest value, echoed in resp */
  639. blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
  640. struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
  641. };
  642. typedef struct blkif_request blkif_request_t;
  643. /*
  644. * Cast to this structure when blkif_request.operation == BLKIF_OP_DISCARD
  645. * sizeof(struct blkif_request_discard) <= sizeof(struct blkif_request)
  646. */
  647. struct blkif_request_discard {
  648. uint8_t operation; /* BLKIF_OP_DISCARD */
  649. uint8_t flag; /* BLKIF_DISCARD_SECURE or zero */
  650. #define BLKIF_DISCARD_SECURE (1<<0) /* ignored if discard-secure=0 */
  651. blkif_vdev_t handle; /* same as for read/write requests */
  652. uint64_t id; /* private guest value, echoed in resp */
  653. blkif_sector_t sector_number;/* start sector idx on disk */
  654. uint64_t nr_sectors; /* number of contiguous sectors to discard*/
  655. };
  656. typedef struct blkif_request_discard blkif_request_discard_t;
  657. struct blkif_request_indirect {
  658. uint8_t operation; /* BLKIF_OP_INDIRECT */
  659. uint8_t indirect_op; /* BLKIF_OP_{READ/WRITE} */
  660. uint16_t nr_segments; /* number of segments */
  661. uint64_t id; /* private guest value, echoed in resp */
  662. blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
  663. blkif_vdev_t handle; /* same as for read/write requests */
  664. grant_ref_t indirect_grefs[BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST];
  665. #ifdef __i386__
  666. uint64_t pad; /* Make it 64 byte aligned on i386 */
  667. #endif
  668. };
  669. typedef struct blkif_request_indirect blkif_request_indirect_t;
  670. struct blkif_response {
  671. uint64_t id; /* copied from request */
  672. uint8_t operation; /* copied from request */
  673. int16_t status; /* BLKIF_RSP_??? */
  674. };
  675. typedef struct blkif_response blkif_response_t;
  676. /*
  677. * STATUS RETURN CODES.
  678. */
  679. /* Operation not supported (only happens on barrier writes). */
  680. #define BLKIF_RSP_EOPNOTSUPP -2
  681. /* Operation failed for some unspecified reason (-EIO). */
  682. #define BLKIF_RSP_ERROR -1
  683. /* Operation completed successfully. */
  684. #define BLKIF_RSP_OKAY 0
  685. /*
  686. * Generate blkif ring structures and types.
  687. */
  688. DEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response);
  689. #define VDISK_CDROM 0x1
  690. #define VDISK_REMOVABLE 0x2
  691. #define VDISK_READONLY 0x4
  692. #endif /* __XEN_PUBLIC_IO_BLKIF_H__ */