2012-05-17 20:14:22 +01:00
|
|
|
#ifndef __NBDTYPES_H
|
|
|
|
#define __NBDTYPES_H
|
|
|
|
|
2012-05-31 17:44:11 +01:00
|
|
|
|
2012-05-17 20:14:22 +01:00
|
|
|
/* http://linux.derkeiler.com/Mailing-Lists/Kernel/2003-09/2332.html */
|
2013-02-08 17:05:22 +00:00
|
|
|
#define INIT_PASSWD "NBDMAGIC"
|
|
|
|
#define INIT_MAGIC 0x0000420281861253
|
|
|
|
#define REQUEST_MAGIC 0x25609513
|
|
|
|
#define REPLY_MAGIC 0x67446698
|
2018-02-01 22:13:59 +00:00
|
|
|
|
2018-02-02 20:34:49 +00:00
|
|
|
#define REQUEST_READ 0
|
2013-02-08 17:05:22 +00:00
|
|
|
#define REQUEST_WRITE 1
|
|
|
|
#define REQUEST_DISCONNECT 2
|
2018-02-01 22:13:59 +00:00
|
|
|
#define REQUEST_FLUSH 3
|
|
|
|
|
2018-02-02 20:34:49 +00:00
|
|
|
/* values for transmission flag field */
|
2018-02-02 16:17:01 +00:00
|
|
|
#define FLAG_HAS_FLAGS (1 << 0) /* Flags are there */
|
|
|
|
#define FLAG_SEND_FLUSH (1 << 2) /* Send FLUSH */
|
|
|
|
#define FLAG_SEND_FUA (1 << 3) /* Send FUA (Force Unit Access) */
|
|
|
|
|
2018-02-02 20:34:49 +00:00
|
|
|
/* values for command flag field */
|
2018-02-02 20:46:25 +00:00
|
|
|
#define CMD_FLAG_FUA (1 << 0)
|
2018-02-02 20:34:49 +00:00
|
|
|
|
|
|
|
#if 0
|
2018-02-02 16:17:01 +00:00
|
|
|
/* Not yet implemented by flexnbd */
|
2018-02-02 20:34:49 +00:00
|
|
|
#define REQUEST_TRIM 4
|
|
|
|
#define REQUEST_WRITE_ZEROES 6
|
|
|
|
|
2018-02-02 16:17:01 +00:00
|
|
|
#define FLAG_READ_ONLY (1 << 1) /* Device is read-only */
|
|
|
|
#define FLAG_ROTATIONAL (1 << 4) /* Use elevator algorithm - rotational media */
|
|
|
|
#define FLAG_SEND_TRIM (1 << 5) /* Send TRIM (discard) */
|
|
|
|
#define FLAG_SEND_WRITE_ZEROES (1 << 6) /* Send NBD_CMD_WRITE_ZEROES */
|
|
|
|
#define FLAG_CAN_MULTI_CONN (1 << 8) /* multiple connections are okay */
|
2018-02-01 22:13:59 +00:00
|
|
|
|
|
|
|
#define CMD_FLAG_NO_HOLE (1 << 1)
|
2018-02-02 20:34:49 +00:00
|
|
|
#endif
|
|
|
|
|
2018-02-01 19:25:36 +00:00
|
|
|
|
2018-02-02 16:17:01 +00:00
|
|
|
/* 32 MiB is the maximum qemu will send you:
|
|
|
|
* https://github.com/qemu/qemu/blob/v2.11.0/include/block/nbd.h#L183
|
|
|
|
*/
|
2018-01-18 17:08:32 +00:00
|
|
|
#define NBD_MAX_SIZE ( 32 * 1024 * 1024 )
|
2013-02-08 17:05:22 +00:00
|
|
|
|
|
|
|
#define NBD_REQUEST_SIZE ( sizeof( struct nbd_request_raw ) )
|
|
|
|
#define NBD_REPLY_SIZE ( sizeof( struct nbd_reply_raw ) )
|
2012-05-31 17:44:11 +01:00
|
|
|
|
2012-05-17 20:14:22 +01:00
|
|
|
#include <linux/types.h>
|
2012-05-31 17:44:11 +01:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2016-09-13 21:35:46 +01:00
|
|
|
typedef union nbd_handle_t {
|
|
|
|
uint8_t b[8];
|
|
|
|
uint64_t w;
|
|
|
|
} nbd_handle_t;
|
|
|
|
|
2012-05-31 17:44:11 +01:00
|
|
|
/* The _raw types are the types as they appear on the wire. Non-_raw
|
|
|
|
* types are in host-format.
|
|
|
|
* Conversion functions are _r2h_ for converting raw to host, and _h2r_
|
|
|
|
* for converting host to raw.
|
|
|
|
*/
|
|
|
|
struct nbd_init_raw {
|
2012-05-17 20:14:22 +01:00
|
|
|
char passwd[8];
|
|
|
|
__be64 magic;
|
|
|
|
__be64 size;
|
2018-02-01 19:25:36 +00:00
|
|
|
__be32 flags;
|
|
|
|
char reserved[124];
|
2012-05-17 20:14:22 +01:00
|
|
|
};
|
|
|
|
|
2012-05-31 17:44:11 +01:00
|
|
|
struct nbd_request_raw {
|
|
|
|
__be32 magic;
|
2018-02-02 20:46:25 +00:00
|
|
|
__be16 flags;
|
2018-02-01 22:13:59 +00:00
|
|
|
__be16 type; /* == READ || == WRITE || == FLUSH */
|
2016-09-13 21:35:46 +01:00
|
|
|
nbd_handle_t handle;
|
2012-05-31 17:44:11 +01:00
|
|
|
__be64 from;
|
|
|
|
__be32 len;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct nbd_reply_raw {
|
|
|
|
__be32 magic;
|
|
|
|
__be32 error; /* 0 = ok, else error */
|
2016-09-13 21:35:46 +01:00
|
|
|
nbd_handle_t handle; /* handle you got from request */
|
2012-05-31 17:44:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct nbd_init {
|
|
|
|
char passwd[8];
|
|
|
|
uint64_t magic;
|
|
|
|
uint64_t size;
|
2018-02-01 19:25:36 +00:00
|
|
|
uint32_t flags;
|
|
|
|
char reserved[124];
|
2012-05-31 17:44:11 +01:00
|
|
|
};
|
|
|
|
|
2012-05-17 20:14:22 +01:00
|
|
|
struct nbd_request {
|
2012-05-31 17:44:11 +01:00
|
|
|
uint32_t magic;
|
2018-02-02 20:46:25 +00:00
|
|
|
uint16_t flags;
|
2018-02-01 22:13:59 +00:00
|
|
|
uint16_t type; /* == READ || == WRITE || == DISCONNECT || == FLUSH */
|
2016-09-13 21:35:46 +01:00
|
|
|
nbd_handle_t handle;
|
2012-05-31 17:44:11 +01:00
|
|
|
uint64_t from;
|
|
|
|
uint32_t len;
|
2012-05-17 20:14:22 +01:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct nbd_reply {
|
2012-05-31 17:44:11 +01:00
|
|
|
uint32_t magic;
|
|
|
|
uint32_t error; /* 0 = ok, else error */
|
2016-09-13 21:35:46 +01:00
|
|
|
nbd_handle_t handle; /* handle you got from request */
|
2012-05-17 20:14:22 +01:00
|
|
|
};
|
|
|
|
|
2012-05-31 17:44:11 +01:00
|
|
|
void nbd_r2h_init( struct nbd_init_raw * from, struct nbd_init * to );
|
|
|
|
void nbd_r2h_request( struct nbd_request_raw *from, struct nbd_request * to );
|
|
|
|
void nbd_r2h_reply( struct nbd_reply_raw * from, struct nbd_reply * to );
|
|
|
|
|
|
|
|
void nbd_h2r_init( struct nbd_init * from, struct nbd_init_raw * to);
|
|
|
|
void nbd_h2r_request( struct nbd_request * from, struct nbd_request_raw * to );
|
|
|
|
void nbd_h2r_reply( struct nbd_reply * from, struct nbd_reply_raw * to );
|
|
|
|
|
2012-05-17 20:14:22 +01:00
|
|
|
#endif
|
|
|
|
|