nbd: Add exports listing support
Before the patches:
$ nbd-client -l localhost Negotiation: .. E: Server does not support listing exports
After the patches:
$ nbd-client -l localhost Negotiation: .. ide0-hd0 ide1-cd0
Hani Benhabiles (2):
nbd: Handle fixed new-style clients.
nbd: Handle NBD_OPT_LIST option.
include/block/nbd.h | 10 +++++ nbd.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 112 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.3.2
PATCH 1/2 nbd: Handle fixed new-style clients.
Signed-off-by Hani Benhabiles <[email protected]>
--- include/block/nbd.h | 6 ++++++ nbd.c | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-)
include/block/nbd.h +6 -0
@@ -45,6 +45,12 @@ struct nbd_reply {#define NBD_FLAG_ROTATIONAL (1 << 4)/* Use elevator algorithm - rotational media */ #define NBD_FLAG_SEND_TRIM (1 << 5)/* Send TRIM (discard) */ +/* New-style global flags. */ +#define NBD_FLAG_FIXED_NEWSTYLE (1 << 0)/* Fixed newstyle protocol. */ + +/* New-style client flags. */ +#define NBD_FLAG_C_FIXED_NEWSTYLE (1 << 0)/* Fixed newstyle protocol. */ +#define NBD_CMD_MASK_COMMAND 0x0000ffff#define NBD_CMD_FLAG_FUA (1 << 16)
nbd.c +7 -5
@@ -224,7 +224,7 @@ static int nbd_receive_options(NBDClient *client)int rc;/* Client sends: -[ 0 .. 3] reserved (0) +[ 0 .. 3] client flags [ 4 .. 11] NBD_OPTS_MAGIC [12 .. 15] NBD_OPT_EXPORT_NAME [16 .. 19] length
@@ -236,9 +236,10 @@ static int nbd_receive_options(NBDClient *client)LOG ("read failed" ); goto fail; } -TRACE ("Checking reserved" ); -if (tmp !=0 ) { -LOG ("Bad reserved received" ); +TRACE ("Checking client flags" ); + tmp =be32_to_cpu (tmp); +if (tmp !=0 && tmp !=NBD_FLAG_C_FIXED_NEWSTYLE ) { +LOG ("Bad client flags received" ); goto fail; }
@@ -246,7 +247,7 @@ static int nbd_receive_options(NBDClient *client)LOG ("read failed" ); goto fail; } -TRACE ("Checking reserved" ); +TRACE ("Checking opts magic" );if (magic !=be64_to_cpu (NBD_OPTS_MAGIC )) {LOG ("Bad magic received" ); goto fail;
@@ -333,6 +334,7 @@ static int nbd_send_negotiate(NBDClient *client)cpu_to_be16w ((uint16_t *)(buf +26 ), client->exp->nbdflags | myflags); }else {cpu_to_be64w ((uint64_t *)(buf +8 ),NBD_OPTS_MAGIC ); +cpu_to_be16w ((uint16_t *)(buf +16 ),NBD_FLAG_FIXED_NEWSTYLE ); }if (client->exp) {
Signature · 1 line
1.8.3.2
PATCH 2/2 nbd: Handle NBD_OPT_LIST option.
In reply to Hani BenhabilesSigned-off-by Hani Benhabiles <[email protected]>
--- include/block/nbd.h | 4 +++ nbd.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 99 insertions(+), 2 deletions(-)
include/block/nbd.h +4 -0
@@ -51,6 +51,10 @@ struct nbd_reply {/* New-style client flags. */ #define NBD_FLAG_C_FIXED_NEWSTYLE (1 << 0)/* Fixed newstyle protocol. */ +/* Reply types. */ +#define NBD_REP_ACK (1)/* Data sending finished. */ +#define NBD_REP_SERVER (2)/* Export description. */ +#define NBD_CMD_MASK_COMMAND 0x0000ffff#define NBD_CMD_FLAG_FUA (1 << 16)
nbd.c +95 -2
133 lines not on this page · raw message
Signature · 1 line
1.8.3.2