blkif.h 30 KB

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