Implement FLUSH command and honour FUA flag

I changed the request struct to break the 32 bits reserved for the
request type into two.  The first part of this is used for the flags
(such as FUA), and the second part for the command type.  Previously
we'd masked the top two bytes, thus ignoring any flags.
This commit is contained in:
Patrick J Cherry
2018-02-01 22:13:59 +00:00
parent 25cc084108
commit 1f0ef0aad6
4 changed files with 50 additions and 23 deletions

View File

@@ -28,7 +28,8 @@ void nbd_h2r_init( struct nbd_init * from, struct nbd_init_raw * to)
void nbd_r2h_request( struct nbd_request_raw *from, struct nbd_request * to )
{
to->magic = htobe32( from->magic );
to->type = htobe32( from->type );
to->flags = htobe16( from->flags );
to->type = htobe16( from->type );
to->handle.w = from->handle.w;
to->from = htobe64( from->from );
to->len = htobe32( from->len );
@@ -37,7 +38,8 @@ void nbd_r2h_request( struct nbd_request_raw *from, struct nbd_request * to )
void nbd_h2r_request( struct nbd_request * from, struct nbd_request_raw * to )
{
to->magic = be32toh( from->magic );
to->type = be32toh( from->type );
to->flags = be16toh( from->flags );
to->type = be16toh( from->type );
to->handle.w = from->handle.w;
to->from = be64toh( from->from );
to->len = be32toh( from->len );

View File

@@ -8,20 +8,27 @@
#define REQUEST_MAGIC 0x25609513
#define REPLY_MAGIC 0x67446698
#define REQUEST_READ 0
#define REQUEST_WRITE 1
#define REQUEST_DISCONNECT 2
#define REQUEST_FLUSH 3
#define REQUEST_TRIM 4
#define REQUEST_WRITE_ZEROES 6
#define NBD_FLAG_HAS_FLAGS (1 << 0)
#define NBD_FLAG_READ_ONLY (1 << 1)
#define NBD_FLAG_SEND_FLUSH (1 << 2)
#define NBD_FLAG_SEND_FUA (1 << 3)
#define NBD_FLAG_ROTATIONAL (1 << 4)
#define NBD_FLAG_SEND_TRIM (1 << 5)
#define NBD_FLAG_SEND_WRITE_ZEROES (1 << 6)
#define FLAG_HAS_FLAGS (1 << 0)
#define FLAG_READ_ONLY (1 << 1)
#define FLAG_SEND_FLUSH (1 << 2)
#define FLAG_SEND_FUA (1 << 3)
#define FLAG_ROTATIONAL (1 << 4)
#define FLAG_SEND_TRIM (1 << 5)
#define FLAG_SEND_WRITE_ZEROES (1 << 6)
#define FLAG_CAN_MULTI_CONN (1 << 8) /* multiple connections are okay */
#define CMD_FLAG_FUA (1 << 0)
#define CMD_FLAG_NO_HOLE (1 << 1)
/* The top 2 bytes of the type field are overloaded and can contain flags */
#define REQUEST_MASK 0x0000ffff
// #define REQUEST_MASK 0x0000ffff
/* 1MiB is the de-facto standard for maximum size of header + data */
#define NBD_MAX_SIZE ( 32 * 1024 * 1024 )
@@ -52,7 +59,8 @@ struct nbd_init_raw {
struct nbd_request_raw {
__be32 magic;
__be32 type; /* == READ || == WRITE */
__be16 flags;
__be16 type; /* == READ || == WRITE || == FLUSH */
nbd_handle_t handle;
__be64 from;
__be32 len;
@@ -74,7 +82,8 @@ struct nbd_init {
struct nbd_request {
uint32_t magic;
uint32_t type; /* == READ || == WRITE || == DISCONNECT */
uint16_t flags;
uint16_t type; /* == READ || == WRITE || == DISCONNECT || == FLUSH */
nbd_handle_t handle;
uint64_t from;
uint32_t len;