blkif.h revision 251767
1214571Sdim/****************************************************************************** 2214571Sdim * blkif.h 3214571Sdim * 4214571Sdim * Unified block-device I/O interface for Xen guest OSes. 5214571Sdim * 6214571Sdim * Permission is hereby granted, free of charge, to any person obtaining a copy 7214571Sdim * of this software and associated documentation files (the "Software"), to 8214571Sdim * deal in the Software without restriction, including without limitation the 9214571Sdim * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10214571Sdim * sell copies of the Software, and to permit persons to whom the Software is 11214571Sdim * furnished to do so, subject to the following conditions: 12214571Sdim * 13214571Sdim * The above copyright notice and this permission notice shall be included in 14214571Sdim * all copies or substantial portions of the Software. 15214571Sdim * 16214571Sdim * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17214571Sdim * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18214571Sdim * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19214571Sdim * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20214571Sdim * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21214571Sdim * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22214571Sdim * DEALINGS IN THE SOFTWARE. 23214571Sdim * 24214571Sdim * Copyright (c) 2003-2004, Keir Fraser 25214571Sdim * Copyright (c) 2012, Spectra Logic Corporation 26214571Sdim */ 27214571Sdim 28214571Sdim#ifndef __XEN_PUBLIC_IO_BLKIF_H__ 29214571Sdim#define __XEN_PUBLIC_IO_BLKIF_H__ 30214571Sdim 31214571Sdim#include "ring.h" 32214571Sdim#include "../grant_table.h" 33214571Sdim 34214571Sdim/* 35214571Sdim * Front->back notifications: When enqueuing a new request, sending a 36214571Sdim * notification can be made conditional on req_event (i.e., the generic 37214571Sdim * hold-off mechanism provided by the ring macros). Backends must set 38214571Sdim * req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()). 39214571Sdim * 40214571Sdim * Back->front notifications: When enqueuing a new response, sending a 41214571Sdim * notification can be made conditional on rsp_event (i.e., the generic 42214571Sdim * hold-off mechanism provided by the ring macros). Frontends must set 43214571Sdim * rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()). 44214571Sdim */ 45214571Sdim 46214571Sdim#ifndef blkif_vdev_t 47214571Sdim#define blkif_vdev_t uint16_t 48214571Sdim#endif 49214571Sdim#define blkif_sector_t uint64_t 50214571Sdim 51214571Sdim/* 52214571Sdim * Feature and Parameter Negotiation 53214571Sdim * ================================= 54214571Sdim * The two halves of a Xen block driver utilize nodes within the XenStore to 55214571Sdim * communicate capabilities and to negotiate operating parameters. This 56214571Sdim * section enumerates these nodes which reside in the respective front and 57214571Sdim * backend portions of the XenStore, following the XenBus convention. 58214571Sdim * 59214571Sdim * All data in the XenStore is stored as strings. Nodes specifying numeric 60214571Sdim * values are encoded in decimal. Integer value ranges listed below are 61214571Sdim * expressed as fixed sized integer types capable of storing the conversion 62214571Sdim * of a properly formatted node string, without loss of information. 63214571Sdim * 64214571Sdim * Any specified default value is in effect if the corresponding XenBus node 65214571Sdim * is not present in the XenStore. 66214571Sdim * 67214571Sdim * XenStore nodes in sections marked "PRIVATE" are solely for use by the 68214571Sdim * driver side whose XenBus tree contains them. 69214571Sdim * 70214571Sdim * XenStore nodes marked "DEPRECATED" in their notes section should only be 71214571Sdim * used to provide interoperability with legacy implementations. 72214571Sdim * 73214571Sdim * See the XenBus state transition diagram below for details on when XenBus 74214571Sdim * nodes must be published and when they can be queried. 75214571Sdim * 76214571Sdim ***************************************************************************** 77214571Sdim * Backend XenBus Nodes 78214571Sdim ***************************************************************************** 79214571Sdim * 80214571Sdim *------------------ Backend Device Identification (PRIVATE) ------------------ 81214571Sdim * 82214571Sdim * mode 83214571Sdim * Values: "r" (read only), "w" (writable) 84214571Sdim * 85214571Sdim * The read or write access permissions to the backing store to be 86214571Sdim * granted to the frontend. 87214571Sdim * 88214571Sdim * params 89214571Sdim * Values: string 90214571Sdim * 91214571Sdim * Data used by the backend driver to locate and configure the backing 92214571Sdim * device. The format and semantics of this data vary according to the 93214571Sdim * backing device in use and are outside the scope of this specification. 94214571Sdim * 95214571Sdim * type 96214571Sdim * Values: "file", "phy", "tap" 97214571Sdim * 98214571Sdim * The type of the backing device/object. 99214571Sdim * 100214571Sdim *--------------------------------- Features --------------------------------- 101214571Sdim * 102214571Sdim * feature-barrier 103214571Sdim * Values: 0/1 (boolean) 104214571Sdim * Default Value: 0 105214571Sdim * 106214571Sdim * A value of "1" indicates that the backend can process requests 107214571Sdim * containing the BLKIF_OP_WRITE_BARRIER request opcode. Requests 108214571Sdim * of this type may still be returned at any time with the 109214571Sdim * BLKIF_RSP_EOPNOTSUPP result code. 110214571Sdim * 111214571Sdim * feature-flush-cache 112214571Sdim * Values: 0/1 (boolean) 113214571Sdim * Default Value: 0 114214571Sdim * 115214571Sdim * A value of "1" indicates that the backend can process requests 116214571Sdim * containing the BLKIF_OP_FLUSH_DISKCACHE request opcode. Requests 117214571Sdim * of this type may still be returned at any time with the 118214571Sdim * BLKIF_RSP_EOPNOTSUPP result code. 119214571Sdim * 120214571Sdim * feature-discard 121214571Sdim * Values: 0/1 (boolean) 122214571Sdim * Default Value: 0 123214571Sdim * 124214571Sdim * A value of "1" indicates that the backend can process requests 125214571Sdim * containing the BLKIF_OP_DISCARD request opcode. Requests 126214571Sdim * of this type may still be returned at any time with the 127214571Sdim * BLKIF_RSP_EOPNOTSUPP result code. 128214571Sdim * 129214571Sdim *----------------------- Request Transport Parameters ------------------------ 130214571Sdim * 131214571Sdim * max-ring-page-order 132214571Sdim * Values: <uint32_t> 133214571Sdim * Default Value: 0 134214571Sdim * Notes: 1, 3 135214571Sdim * 136214571Sdim * The maximum supported size of the request ring buffer in units of 137214571Sdim * lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages, 138214571Sdim * etc.). 139214571Sdim * 140214571Sdim * max-ring-pages 141214571Sdim * Values: <uint32_t> 142214571Sdim * Default Value: 1 143214571Sdim * Notes: DEPRECATED, 2, 3 144214571Sdim * 145214571Sdim * The maximum supported size of the request ring buffer in units of 146214571Sdim * machine pages. The value must be a power of 2. 147214571Sdim * 148214571Sdim * max-requests <uint32_t> 149214571Sdim * Default Value: BLKIF_MAX_RING_REQUESTS(PAGE_SIZE) 150214571Sdim * Maximum Value: BLKIF_MAX_RING_REQUESTS(PAGE_SIZE * max-ring-pages) 151214571Sdim * 152214571Sdim * The maximum number of concurrent, logical requests supported by 153214571Sdim * the backend. 154214571Sdim * 155214571Sdim * Note: A logical request may span multiple ring entries. 156214571Sdim * 157214571Sdim * max-request-segments 158214571Sdim * Values: <uint8_t> 159214571Sdim * Default Value: BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK 160214571Sdim * Maximum Value: BLKIF_MAX_SEGMENTS_PER_REQUEST 161214571Sdim * 162214571Sdim * The maximum value of blkif_request.nr_segments supported by 163214571Sdim * the backend. 164214571Sdim * 165214571Sdim * max-request-size 166214571Sdim * Values: <uint32_t> 167214571Sdim * Default Value: BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK * PAGE_SIZE 168214571Sdim * Maximum Value: BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE 169214571Sdim * 170214571Sdim * The maximum amount of data, in bytes, that can be referenced by a 171214571Sdim * request type that accesses frontend memory (currently BLKIF_OP_READ, 172214571Sdim * BLKIF_OP_WRITE, or BLKIF_OP_WRITE_BARRIER). 173214571Sdim * 174214571Sdim *------------------------- Backend Device Properties ------------------------- 175214571Sdim * 176214571Sdim * discard-alignment 177214571Sdim * Values: <uint32_t> 178214571Sdim * Default Value: 0 179214571Sdim * Notes: 4, 5 180214571Sdim * 181214571Sdim * The offset, in bytes from the beginning of the virtual block device, 182214571Sdim * to the first, addressable, discard extent on the underlying device. 183214571Sdim * 184214571Sdim * discard-granularity 185214571Sdim * Values: <uint32_t> 186214571Sdim * Default Value: <"sector-size"> 187214571Sdim * Notes: 4 188214571Sdim * 189214571Sdim * The size, in bytes, of the individually addressable discard extents 190214571Sdim * of the underlying device. 191214571Sdim * 192214571Sdim * discard-secure 193214571Sdim * Values: 0/1 (boolean) 194214571Sdim * Default Value: 0 195214571Sdim * 196214571Sdim * A value of "1" indicates that the backend can process BLKIF_OP_DISCARD 197214571Sdim * requests with the BLKIF_DISCARD_SECURE flag set. 198214571Sdim * 199214571Sdim * info 200214571Sdim * Values: <uint32_t> (bitmap) 201214571Sdim * 202214571Sdim * A collection of bit flags describing attributes of the backing 203214571Sdim * device. The VDISK_* macros define the meaning of each bit 204214571Sdim * location. 205214571Sdim * 206214571Sdim * sector-size 207214571Sdim * Values: <uint32_t> 208214571Sdim * 209214571Sdim * The size, in bytes, of the individually addressible data blocks 210214571Sdim * on the backend device. 211214571Sdim * 212214571Sdim * sectors 213214571Sdim * Values: <uint64_t> 214214571Sdim * 215214571Sdim * The size of the backend device, expressed in units of its native 216214571Sdim * sector size ("sector-size"). 217214571Sdim * 218214571Sdim ***************************************************************************** 219214571Sdim * Frontend XenBus Nodes 220214571Sdim ***************************************************************************** 221214571Sdim * 222214571Sdim *----------------------- Request Transport Parameters ----------------------- 223214571Sdim * 224214571Sdim * event-channel 225214571Sdim * Values: <uint32_t> 226214571Sdim * 227214571Sdim * The identifier of the Xen event channel used to signal activity 228214571Sdim * in the ring buffer. 229214571Sdim * 230214571Sdim * ring-ref 231214571Sdim * Values: <uint32_t> 232214571Sdim * Notes: 6 233214571Sdim * 234214571Sdim * The Xen grant reference granting permission for the backend to map 235214571Sdim * the sole page in a single page sized ring buffer. 236214571Sdim * 237214571Sdim * ring-ref%u 238214571Sdim * Values: <uint32_t> 239214571Sdim * Notes: 6 240214571Sdim * 241214571Sdim * For a frontend providing a multi-page ring, a "number of ring pages" 242214571Sdim * sized list of nodes, each containing a Xen grant reference granting 243214571Sdim * permission for the backend to map the page of the ring located 244214571Sdim * at page index "%u". Page indexes are zero based. 245214571Sdim * 246214571Sdim * protocol 247214571Sdim * Values: string (XEN_IO_PROTO_ABI_*) 248214571Sdim * Default Value: XEN_IO_PROTO_ABI_NATIVE 249214571Sdim * 250214571Sdim * The machine ABI rules governing the format of all ring request and 251214571Sdim * response structures. 252214571Sdim * 253214571Sdim * ring-page-order 254214571Sdim * Values: <uint32_t> 255214571Sdim * Default Value: 0 256214571Sdim * Maximum Value: MAX(ffs(max-ring-pages) - 1, max-ring-page-order) 257214571Sdim * Notes: 1, 3 258214571Sdim * 259214571Sdim * The size of the frontend allocated request ring buffer in units 260214571Sdim * of lb(machine pages). (e.g. 0 == 1 page, 1 = 2 pages, 2 == 4 pages, 261214571Sdim * etc.). 262214571Sdim * 263214571Sdim * num-ring-pages 264214571Sdim * Values: <uint32_t> 265214571Sdim * Default Value: 1 266214571Sdim * Maximum Value: MAX(max-ring-pages,(0x1 << max-ring-page-order)) 267214571Sdim * Notes: DEPRECATED, 2, 3 268214571Sdim * 269214571Sdim * The size of the frontend allocated request ring buffer in units of 270214571Sdim * machine pages. The value must be a power of 2. 271214571Sdim * 272214571Sdim * max-requests 273214571Sdim * Values: <uint32_t> 274214571Sdim * Default Value: BLKIF_MAX_RING_REQUESTS(PAGE_SIZE) 275214571Sdim * Maximum Value: BLKIF_MAX_RING_REQUESTS(PAGE_SIZE * max-ring-pages) 276214571Sdim * 277214571Sdim * The maximum number of concurrent, logical requests that will be 278214571Sdim * issued by the frontend. 279214571Sdim * 280214571Sdim * Note: A logical request may span multiple ring entries. 281214571Sdim * 282214571Sdim * max-request-segments 283214571Sdim * Values: <uint8_t> 284214571Sdim * Default Value: BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK 285214571Sdim * Maximum Value: MIN(255, backend/max-request-segments) 286214571Sdim * 287214571Sdim * The maximum value the frontend will set in the 288214571Sdim * blkif_request.nr_segments field. 289214571Sdim * 290214571Sdim * max-request-size 291214571Sdim * Values: <uint32_t> 292214571Sdim * Default Value: BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK * PAGE_SIZE 293214571Sdim * Maximum Value: max-request-segments * PAGE_SIZE 294214571Sdim * 295214571Sdim * The maximum amount of data, in bytes, that can be referenced by 296214571Sdim * a request type that accesses frontend memory (currently BLKIF_OP_READ, 297214571Sdim * BLKIF_OP_WRITE, or BLKIF_OP_WRITE_BARRIER). 298214571Sdim * 299214571Sdim *------------------------- Virtual Device Properties ------------------------- 300214571Sdim * 301214571Sdim * device-type 302214571Sdim * Values: "disk", "cdrom", "floppy", etc. 303214571Sdim * 304214571Sdim * virtual-device 305214571Sdim * Values: <uint32_t> 306214571Sdim * 307214571Sdim * A value indicating the physical device to virtualize within the 308214571Sdim * frontend's domain. (e.g. "The first ATA disk", "The third SCSI 309214571Sdim * disk", etc.) 310214571Sdim * 311214571Sdim * See docs/misc/vbd-interface.txt for details on the format of this 312214571Sdim * value. 313214571Sdim * 314214571Sdim * Notes 315214571Sdim * ----- 316214571Sdim * (1) Multi-page ring buffer scheme first developed in the Citrix XenServer 317214571Sdim * PV drivers. 318214571Sdim * (2) Multi-page ring buffer scheme first used in some Red Hat distributions 319214571Sdim * including a distribution deployed on certain nodes of the Amazon 320214571Sdim * EC2 cluster. 321214571Sdim * (3) Support for multi-page ring buffers was implemented independently, 322214571Sdim * in slightly different forms, by both Citrix and Red Hat/Amazon. 323214571Sdim * For full interoperability, block front and backends should publish 324214571Sdim * identical ring parameters, adjusted for unit differences, to the 325214571Sdim * XenStore nodes used in both schemes. 326214571Sdim * (4) Devices that support discard functionality may internally allocate 327214571Sdim * space (discardable extents) in units that are larger than the 328214571Sdim * exported logical block size. 329214571Sdim * (5) The discard-alignment parameter allows a physical device to be 330214571Sdim * partitioned into virtual devices that do not necessarily begin or 331214571Sdim * end on a discardable extent boundary. 332214571Sdim * (6) When there is only a single page allocated to the request ring, 333214571Sdim * 'ring-ref' is used to communicate the grant reference for this 334214571Sdim * page to the backend. When using a multi-page ring, the 'ring-ref' 335214571Sdim * node is not created. Instead 'ring-ref0' - 'ring-refN' are used. 336214571Sdim */ 337214571Sdim 338214571Sdim/* 339214571Sdim * STATE DIAGRAMS 340214571Sdim * 341214571Sdim ***************************************************************************** 342214571Sdim * Startup * 343 ***************************************************************************** 344 * 345 * Tool stack creates front and back nodes with state XenbusStateInitialising. 346 * 347 * Front Back 348 * ================================= ===================================== 349 * XenbusStateInitialising XenbusStateInitialising 350 * o Query virtual device o Query backend device identification 351 * properties. data. 352 * o Setup OS device instance. o Open and validate backend device. 353 * o Publish backend features and 354 * transport parameters. 355 * | 356 * | 357 * V 358 * XenbusStateInitWait 359 * 360 * o Query backend features and 361 * transport parameters. 362 * o Allocate and initialize the 363 * request ring. 364 * o Publish transport parameters 365 * that will be in effect during 366 * this connection. 367 * | 368 * | 369 * V 370 * XenbusStateInitialised 371 * 372 * o Query frontend transport parameters. 373 * o Connect to the request ring and 374 * event channel. 375 * o Publish backend device properties. 376 * | 377 * | 378 * V 379 * XenbusStateConnected 380 * 381 * o Query backend device properties. 382 * o Finalize OS virtual device 383 * instance. 384 * | 385 * | 386 * V 387 * XenbusStateConnected 388 * 389 * Note: Drivers that do not support any optional features, or the negotiation 390 * of transport parameters, can skip certain states in the state machine: 391 * 392 * o A frontend may transition to XenbusStateInitialised without 393 * waiting for the backend to enter XenbusStateInitWait. In this 394 * case, default transport parameters are in effect and any 395 * transport parameters published by the frontend must contain 396 * their default values. 397 * 398 * o A backend may transition to XenbusStateInitialised, bypassing 399 * XenbusStateInitWait, without waiting for the frontend to first 400 * enter the XenbusStateInitialised state. In this case, default 401 * transport parameters are in effect and any transport parameters 402 * published by the backend must contain their default values. 403 * 404 * Drivers that support optional features and/or transport parameter 405 * negotiation must tolerate these additional state transition paths. 406 * In general this means performing the work of any skipped state 407 * transition, if it has not already been performed, in addition to the 408 * work associated with entry into the current state. 409 */ 410 411/* 412 * REQUEST CODES. 413 */ 414#define BLKIF_OP_READ 0 415#define BLKIF_OP_WRITE 1 416/* 417 * All writes issued prior to a request with the BLKIF_OP_WRITE_BARRIER 418 * operation code ("barrier request") must be completed prior to the 419 * execution of the barrier request. All writes issued after the barrier 420 * request must not execute until after the completion of the barrier request. 421 * 422 * Optional. See "feature-barrier" XenBus node documentation above. 423 */ 424#define BLKIF_OP_WRITE_BARRIER 2 425/* 426 * Commit any uncommitted contents of the backing device's volatile cache 427 * to stable storage. 428 * 429 * Optional. See "feature-flush-cache" XenBus node documentation above. 430 */ 431#define BLKIF_OP_FLUSH_DISKCACHE 3 432/* 433 * Used in SLES sources for device specific command packet 434 * contained within the request. Reserved for that purpose. 435 */ 436#define BLKIF_OP_RESERVED_1 4 437/* 438 * Indicate to the backend device that a region of storage is no longer in 439 * use, and may be discarded at any time without impact to the client. If 440 * the BLKIF_DISCARD_SECURE flag is set on the request, all copies of the 441 * discarded region on the device must be rendered unrecoverable before the 442 * command returns. 443 * 444 * This operation is analogous to performing a trim (ATA) or unmap (SCSI), 445 * command on a native device. 446 * 447 * More information about trim/unmap operations can be found at: 448 * http://t13.org/Documents/UploadedDocuments/docs2008/ 449 * e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc 450 * http://www.seagate.com/staticfiles/support/disc/manuals/ 451 * Interface%20manuals/100293068c.pdf 452 * 453 * Optional. See "feature-discard", "discard-alignment", 454 * "discard-granularity", and "discard-secure" in the XenBus node 455 * documentation above. 456 */ 457#define BLKIF_OP_DISCARD 5 458 459/* 460 * Maximum scatter/gather segments associated with a request header block. 461 * This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE. 462 * NB. This could be 12 if the ring indexes weren't stored in the same page. 463 */ 464#define BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK 11 465 466/* 467 * Maximum scatter/gather segments associated with a segment block. 468 */ 469#define BLKIF_MAX_SEGMENTS_PER_SEGMENT_BLOCK 14 470 471/* 472 * Maximum scatter/gather segments per request (header + segment blocks). 473 */ 474#define BLKIF_MAX_SEGMENTS_PER_REQUEST 255 475 476/* 477 * NB. first_sect and last_sect in blkif_request_segment, as well as 478 * sector_number in blkif_request, are always expressed in 512-byte units. 479 * However they must be properly aligned to the real sector size of the 480 * physical disk, which is reported in the "sector-size" node in the backend 481 * xenbus info. Also the xenbus "sectors" node is expressed in 512-byte units. 482 */ 483struct blkif_request_segment { 484 grant_ref_t gref; /* reference to I/O buffer frame */ 485 /* @first_sect: first sector in frame to transfer (inclusive). */ 486 /* @last_sect: last sector in frame to transfer (inclusive). */ 487 uint8_t first_sect, last_sect; 488}; 489typedef struct blkif_request_segment blkif_request_segment_t; 490 491/* 492 * Starting ring element for any I/O request. 493 * 494 * One or more segment blocks can be inserted into the request ring 495 * just after a blkif_request_t, allowing requests to operate on 496 * up to BLKIF_MAX_SEGMENTS_PER_REQUEST. 497 * 498 * BLKIF_SEGS_TO_BLOCKS() can be used on blkif_requst.nr_segments 499 * to determine the number of contiguous ring entries associated 500 * with this request. 501 * 502 * Note: Due to the way Xen request rings operate, the producer and 503 * consumer indices of the ring must be incremented by the 504 * BLKIF_SEGS_TO_BLOCKS() value of the associated request. 505 * (e.g. a response to a 3 ring entry request must also consume 506 * 3 entries in the ring, even though only the first ring entry 507 * in the response has any data.) 508 */ 509struct blkif_request { 510 uint8_t operation; /* BLKIF_OP_??? */ 511 uint8_t nr_segments; /* number of segments */ 512 blkif_vdev_t handle; /* only for read/write requests */ 513 uint64_t id; /* private guest value, echoed in resp */ 514 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ 515 blkif_request_segment_t seg[BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK]; 516}; 517typedef struct blkif_request blkif_request_t; 518 519/* 520 * A segment block is a ring request structure that contains only 521 * segment data. 522 * 523 * sizeof(struct blkif_segment_block) <= sizeof(struct blkif_request) 524 */ 525struct blkif_segment_block { 526 blkif_request_segment_t seg[BLKIF_MAX_SEGMENTS_PER_SEGMENT_BLOCK]; 527}; 528typedef struct blkif_segment_block blkif_segment_block_t; 529 530/* 531 * Cast to this structure when blkif_request.operation == BLKIF_OP_DISCARD 532 * sizeof(struct blkif_request_discard) <= sizeof(struct blkif_request) 533 */ 534struct 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}; 543typedef struct blkif_request_discard blkif_request_discard_t; 544 545struct blkif_response { 546 uint64_t id; /* copied from request */ 547 uint8_t operation; /* copied from request */ 548 int16_t status; /* BLKIF_RSP_??? */ 549}; 550typedef struct blkif_response blkif_response_t; 551 552/* 553 * STATUS RETURN CODES. 554 */ 555 /* Operation not supported (only happens on barrier writes). */ 556#define BLKIF_RSP_EOPNOTSUPP -2 557 /* Operation failed for some unspecified reason (-EIO). */ 558#define BLKIF_RSP_ERROR -1 559 /* Operation completed successfully. */ 560#define BLKIF_RSP_OKAY 0 561 562/* 563 * Generate blkif ring structures and types. 564 */ 565DEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response); 566 567/* 568 * Index to, and treat as a segment block, an entry in the ring. 569 */ 570#define BLKRING_GET_SEG_BLOCK(_r, _idx) \ 571 (((blkif_segment_block_t *)RING_GET_REQUEST(_r, _idx))->seg) 572 573/* 574 * The number of ring request blocks required to handle an I/O 575 * request containing _segs segments. 576 */ 577#define BLKIF_SEGS_TO_BLOCKS(_segs) \ 578 ((((_segs - BLKIF_MAX_SEGMENTS_PER_HEADER_BLOCK) \ 579 + (BLKIF_MAX_SEGMENTS_PER_SEGMENT_BLOCK - 1)) \ 580 / BLKIF_MAX_SEGMENTS_PER_SEGMENT_BLOCK) + /*header_block*/1) 581 582#define VDISK_CDROM 0x1 583#define VDISK_REMOVABLE 0x2 584#define VDISK_READONLY 0x4 585 586#endif /* __XEN_PUBLIC_IO_BLKIF_H__ */ 587 588/* 589 * Local variables: 590 * mode: C 591 * c-set-style: "BSD" 592 * c-basic-offset: 4 593 * tab-width: 4 594 * indent-tabs-mode: nil 595 * End: 596 */ 597