From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoV4m-0002kc-3u for qemu-devel@nongnu.org; Sun, 25 May 2014 05:50:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WoV4e-0005TI-DO for qemu-devel@nongnu.org; Sun, 25 May 2014 05:50:44 -0400 Received: from mail-wg0-x231.google.com ([2a00:1450:400c:c00::231]:58422) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoV4e-0005TC-6u for qemu-devel@nongnu.org; Sun, 25 May 2014 05:50:36 -0400 Received: by mail-wg0-f49.google.com with SMTP id m15so6706698wgh.20 for ; Sun, 25 May 2014 02:50:35 -0700 (PDT) From: Hani Benhabiles Date: Sun, 25 May 2014 10:50:07 +0100 Message-Id: <1401011408-8033-2-git-send-email-kroosec@gmail.com> In-Reply-To: <1401011408-8033-1-git-send-email-kroosec@gmail.com> References: <1401011408-8033-1-git-send-email-kroosec@gmail.com> Subject: [Qemu-devel] [PATCH 1/2] nbd: Handle fixed new-style clients. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, famz@redhat.com, kraxel@redhat.com, stefanha@redhat.com Signed-off-by: Hani Benhabiles --- include/block/nbd.h | 6 ++++++ nbd.c | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 79502a0..95d52ab 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -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) diff --git a/nbd.c b/nbd.c index e5084b6..fb0a9cf 100644 --- a/nbd.c +++ b/nbd.c @@ -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) { -- 1.8.3.2