1 /******************************************************************************
4 * Unified block-device I/O interface for Xen guest OSes.
6 * Copyright (c) 2003-2004, Keir Fraser
9 #ifndef __XEN_PUBLIC_IO_BLKIF_H__
10 #define __XEN_PUBLIC_IO_BLKIF_H__
13 #include "../grant_table.h"
16 * Front->back notifications: When enqueuing a new request, sending a
17 * notification can be made conditional on req_event (i.e., the generic
18 * hold-off mechanism provided by the ring macros). Backends must set
19 * req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).
21 * Back->front notifications: When enqueuing a new response, sending a
22 * notification can be made conditional on rsp_event (i.e., the generic
23 * hold-off mechanism provided by the ring macros). Frontends must set
24 * rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).
27 typedef uint16_t blkif_vdev_t
;
28 typedef uint64_t blkif_sector_t
;
33 #define BLKIF_OP_READ 0
34 #define BLKIF_OP_WRITE 1
36 * Recognised only if "feature-barrier" is present in backend xenbus info.
37 * The "feature_barrier" node contains a boolean indicating whether barrier
38 * requests are likely to succeed or fail. Either way, a barrier request
39 * may fail at any time with BLKIF_RSP_EOPNOTSUPP if it is unsupported by
40 * the underlying block-device hardware. The boolean simply indicates whether
41 * or not it is worthwhile for the frontend to attempt barrier requests.
42 * If a backend does not recognise BLKIF_OP_WRITE_BARRIER, it should *not*
43 * create the "feature-barrier" node!
45 #define BLKIF_OP_WRITE_BARRIER 2
48 * Maximum scatter/gather segments per request.
49 * This is carefully chosen so that sizeof(struct blkif_ring) <= PAGE_SIZE.
50 * NB. This could be 12 if the ring indexes weren't stored in the same page.
52 #define BLKIF_MAX_SEGMENTS_PER_REQUEST 11
54 struct blkif_request
{
55 uint8_t operation
; /* BLKIF_OP_??? */
56 uint8_t nr_segments
; /* number of segments */
57 blkif_vdev_t handle
; /* only for read/write requests */
58 uint64_t id
; /* private guest value, echoed in resp */
59 blkif_sector_t sector_number
;/* start sector idx on disk (r/w only) */
60 struct blkif_request_segment
{
61 grant_ref_t gref
; /* reference to I/O buffer frame */
62 /* @first_sect: first sector in frame to transfer (inclusive). */
63 /* @last_sect: last sector in frame to transfer (inclusive). */
64 uint8_t first_sect
, last_sect
;
65 } seg
[BLKIF_MAX_SEGMENTS_PER_REQUEST
];
68 struct blkif_response
{
69 uint64_t id
; /* copied from request */
70 uint8_t operation
; /* copied from request */
71 int16_t status
; /* BLKIF_RSP_??? */
75 * STATUS RETURN CODES.
77 /* Operation not supported (only happens on barrier writes). */
78 #define BLKIF_RSP_EOPNOTSUPP -2
79 /* Operation failed for some unspecified reason (-EIO). */
80 #define BLKIF_RSP_ERROR -1
81 /* Operation completed successfully. */
82 #define BLKIF_RSP_OKAY 0
85 * Generate blkif ring structures and types.
88 DEFINE_RING_TYPES(blkif
, struct blkif_request
, struct blkif_response
);
90 #define VDISK_CDROM 0x1
91 #define VDISK_REMOVABLE 0x2
92 #define VDISK_READONLY 0x4
94 #endif /* __XEN_PUBLIC_IO_BLKIF_H__ */