Path: blob/master/include/xen/interface/io/blkif.h
10818 views
/******************************************************************************1* blkif.h2*3* Unified block-device I/O interface for Xen guest OSes.4*5* Copyright (c) 2003-2004, Keir Fraser6*/78#ifndef __XEN_PUBLIC_IO_BLKIF_H__9#define __XEN_PUBLIC_IO_BLKIF_H__1011#include "ring.h"12#include "../grant_table.h"1314/*15* Front->back notifications: When enqueuing a new request, sending a16* notification can be made conditional on req_event (i.e., the generic17* hold-off mechanism provided by the ring macros). Backends must set18* req_event appropriately (e.g., using RING_FINAL_CHECK_FOR_REQUESTS()).19*20* Back->front notifications: When enqueuing a new response, sending a21* notification can be made conditional on rsp_event (i.e., the generic22* hold-off mechanism provided by the ring macros). Frontends must set23* rsp_event appropriately (e.g., using RING_FINAL_CHECK_FOR_RESPONSES()).24*/2526typedef uint16_t blkif_vdev_t;27typedef uint64_t blkif_sector_t;2829/*30* REQUEST CODES.31*/32#define BLKIF_OP_READ 033#define BLKIF_OP_WRITE 134/*35* Recognised only if "feature-barrier" is present in backend xenbus info.36* The "feature_barrier" node contains a boolean indicating whether barrier37* requests are likely to succeed or fail. Either way, a barrier request38* may fail at any time with BLKIF_RSP_EOPNOTSUPP if it is unsupported by39* the underlying block-device hardware. The boolean simply indicates whether40* or not it is worthwhile for the frontend to attempt barrier requests.41* If a backend does not recognise BLKIF_OP_WRITE_BARRIER, it should *not*42* create the "feature-barrier" node!43*/44#define BLKIF_OP_WRITE_BARRIER 24546/*47* Recognised if "feature-flush-cache" is present in backend xenbus48* info. A flush will ask the underlying storage hardware to flush its49* non-volatile caches as appropriate. The "feature-flush-cache" node50* contains a boolean indicating whether flush requests are likely to51* succeed or fail. Either way, a flush request may fail at any time52* with BLKIF_RSP_EOPNOTSUPP if it is unsupported by the underlying53* block-device hardware. The boolean simply indicates whether or not it54* is worthwhile for the frontend to attempt flushes. If a backend does55* not recognise BLKIF_OP_WRITE_FLUSH_CACHE, it should *not* create the56* "feature-flush-cache" node!57*/58#define BLKIF_OP_FLUSH_DISKCACHE 359/*60* Maximum scatter/gather segments per request.61* This is carefully chosen so that sizeof(struct blkif_ring) <= PAGE_SIZE.62* NB. This could be 12 if the ring indexes weren't stored in the same page.63*/64#define BLKIF_MAX_SEGMENTS_PER_REQUEST 116566struct blkif_request_rw {67blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */68struct blkif_request_segment {69grant_ref_t gref; /* reference to I/O buffer frame */70/* @first_sect: first sector in frame to transfer (inclusive). */71/* @last_sect: last sector in frame to transfer (inclusive). */72uint8_t first_sect, last_sect;73} seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];74};7576struct blkif_request {77uint8_t operation; /* BLKIF_OP_??? */78uint8_t nr_segments; /* number of segments */79blkif_vdev_t handle; /* only for read/write requests */80uint64_t id; /* private guest value, echoed in resp */81union {82struct blkif_request_rw rw;83} u;84};8586struct blkif_response {87uint64_t id; /* copied from request */88uint8_t operation; /* copied from request */89int16_t status; /* BLKIF_RSP_??? */90};9192/*93* STATUS RETURN CODES.94*/95/* Operation not supported (only happens on barrier writes). */96#define BLKIF_RSP_EOPNOTSUPP -297/* Operation failed for some unspecified reason (-EIO). */98#define BLKIF_RSP_ERROR -199/* Operation completed successfully. */100#define BLKIF_RSP_OKAY 0101102/*103* Generate blkif ring structures and types.104*/105106DEFINE_RING_TYPES(blkif, struct blkif_request, struct blkif_response);107108#define VDISK_CDROM 0x1109#define VDISK_REMOVABLE 0x2110#define VDISK_READONLY 0x4111112/* Xen-defined major numbers for virtual disks, they look strangely113* familiar */114#define XEN_IDE0_MAJOR 3115#define XEN_IDE1_MAJOR 22116#define XEN_SCSI_DISK0_MAJOR 8117#define XEN_SCSI_DISK1_MAJOR 65118#define XEN_SCSI_DISK2_MAJOR 66119#define XEN_SCSI_DISK3_MAJOR 67120#define XEN_SCSI_DISK4_MAJOR 68121#define XEN_SCSI_DISK5_MAJOR 69122#define XEN_SCSI_DISK6_MAJOR 70123#define XEN_SCSI_DISK7_MAJOR 71124#define XEN_SCSI_DISK8_MAJOR 128125#define XEN_SCSI_DISK9_MAJOR 129126#define XEN_SCSI_DISK10_MAJOR 130127#define XEN_SCSI_DISK11_MAJOR 131128#define XEN_SCSI_DISK12_MAJOR 132129#define XEN_SCSI_DISK13_MAJOR 133130#define XEN_SCSI_DISK14_MAJOR 134131#define XEN_SCSI_DISK15_MAJOR 135132133#endif /* __XEN_PUBLIC_IO_BLKIF_H__ */134135136