First steps towards implementing flags as part of oldstyle negotiation

This commit is contained in:
Patrick J Cherry
2018-02-01 19:25:36 +00:00
parent f2fa00260b
commit 25cc084108
3 changed files with 17 additions and 5 deletions

View File

@@ -13,6 +13,7 @@ void nbd_r2h_init( struct nbd_init_raw * from, struct nbd_init * to )
memcpy( to->passwd, from->passwd, 8 ); memcpy( to->passwd, from->passwd, 8 );
to->magic = be64toh( from->magic ); to->magic = be64toh( from->magic );
to->size = be64toh( from->size ); to->size = be64toh( from->size );
to->flags = be32toh( from->flags );
} }
void nbd_h2r_init( struct nbd_init * from, struct nbd_init_raw * to) void nbd_h2r_init( struct nbd_init * from, struct nbd_init_raw * to)
@@ -20,6 +21,7 @@ void nbd_h2r_init( struct nbd_init * from, struct nbd_init_raw * to)
memcpy( to->passwd, from->passwd, 8 ); memcpy( to->passwd, from->passwd, 8 );
to->magic = htobe64( from->magic ); to->magic = htobe64( from->magic );
to->size = htobe64( from->size ); to->size = htobe64( from->size );
to->flags = htobe32( from->flags );
} }

View File

@@ -11,6 +11,14 @@
#define REQUEST_WRITE 1 #define REQUEST_WRITE 1
#define REQUEST_DISCONNECT 2 #define REQUEST_DISCONNECT 2
#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)
/* The top 2 bytes of the type field are overloaded and can contain flags */ /* The top 2 bytes of the type field are overloaded and can contain flags */
#define REQUEST_MASK 0x0000ffff #define REQUEST_MASK 0x0000ffff
@@ -38,7 +46,8 @@ struct nbd_init_raw {
char passwd[8]; char passwd[8];
__be64 magic; __be64 magic;
__be64 size; __be64 size;
char reserved[128]; __be32 flags;
char reserved[124];
}; };
struct nbd_request_raw { struct nbd_request_raw {
@@ -55,13 +64,12 @@ struct nbd_reply_raw {
nbd_handle_t handle; /* handle you got from request */ nbd_handle_t handle; /* handle you got from request */
}; };
struct nbd_init { struct nbd_init {
char passwd[8]; char passwd[8];
uint64_t magic; uint64_t magic;
uint64_t size; uint64_t size;
char reserved[128]; uint32_t flags;
char reserved[124];
}; };
struct nbd_request { struct nbd_request {

View File

@@ -307,7 +307,9 @@ void client_write_init( struct client * client, uint64_t size )
memcpy( init.passwd, INIT_PASSWD, sizeof( init.passwd ) ); memcpy( init.passwd, INIT_PASSWD, sizeof( init.passwd ) );
init.magic = INIT_MAGIC; init.magic = INIT_MAGIC;
init.size = size; init.size = size;
memset( init.reserved, 0, 128 ); // TODO actually implement these flags!
init.flags = NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA;
// memset( init.reserved, 0, 124 );
nbd_h2r_init( &init, &init_raw ); nbd_h2r_init( &init, &init_raw );