From patchwork Mon Jan 11 15:00:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 565938 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FE5E1402A1 for ; Tue, 12 Jan 2016 02:08:22 +1100 (AEDT) Received: from localhost ([::1]:54930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIe4y-0000Op-0K for incoming@patchwork.ozlabs.org; Mon, 11 Jan 2016 10:08:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36164) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIdyI-0004dx-RF for qemu-devel@nongnu.org; Mon, 11 Jan 2016 10:01:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIdy9-0004rX-0Y for qemu-devel@nongnu.org; Mon, 11 Jan 2016 10:01:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46986) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIdy8-0004rS-PV for qemu-devel@nongnu.org; Mon, 11 Jan 2016 10:01:16 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 544A28E00F for ; Mon, 11 Jan 2016 15:01:16 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (dhcp-1-180.lcy.redhat.com [10.32.224.180]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0BF150o015393; Mon, 11 Jan 2016 10:01:15 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Mon, 11 Jan 2016 15:00:54 +0000 Message-Id: <1452524459-4132-11-git-send-email-berrange@redhat.com> In-Reply-To: <1452524459-4132-1-git-send-email-berrange@redhat.com> References: <1452524459-4132-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini Subject: [Qemu-devel] [PATCH v2 10/15] nbd: allow setting of an export name for qemu-nbd server X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The qemu-nbd server currently always uses the old style protocol since it never sets any export name. This is a problem because future TLS support will require use of the new style protocol negotiation. This adds a "--exportname NAME" argument to qemu-nbd which allows the user to set an explicit export name. When --exportname is set the server will always use the new style protocol. Signed-off-by: Daniel P. Berrange --- qemu-nbd.c | 14 ++++++++++++-- qemu-nbd.texi | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 2c47fc6..7933ff5 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -47,6 +47,7 @@ #define QEMU_NBD_OPT_OBJECT 5 static NBDExport *exp; +static bool newproto; static int verbose; static char *srcpath; static SocketAddress *saddr; @@ -341,7 +342,7 @@ static gboolean nbd_accept(QIOChannel *ioc, GIOCondition cond, gpointer opaque) return TRUE; } - if (nbd_client_new(exp, cioc, nbd_client_closed)) { + if (nbd_client_new(newproto ? NULL : exp, cioc, nbd_client_closed)) { nb_fds++; nbd_update_server_watch(); } @@ -437,7 +438,7 @@ int main(int argc, char **argv) off_t fd_size; QemuOpts *sn_opts = NULL; const char *sn_id_or_name = NULL; - const char *sopt = "hVb:o:p:rsnP:c:dvk:e:f:tl:"; + const char *sopt = "hVb:o:p:rsnP:c:dvk:e:f:tl:x:"; struct option lopt[] = { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, @@ -461,6 +462,7 @@ int main(int argc, char **argv) { "persistent", 0, NULL, 't' }, { "verbose", 0, NULL, 'v' }, { "object", 1, NULL, QEMU_NBD_OPT_OBJECT }, + { "exportname", 1, NULL, 'x' }, { NULL, 0, NULL, 0 } }; int ch; @@ -478,6 +480,7 @@ int main(int argc, char **argv) BlockdevDetectZeroesOptions detect_zeroes = BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF; QDict *options = NULL; QemuOpts *opts; + const char *exportname = NULL; /* The client thread uses SIGTERM to interrupt the server. A signal * handler ensures that "qemu-nbd -v -c" exits with a nice status code. @@ -613,6 +616,9 @@ int main(int argc, char **argv) case 't': persistent = 1; break; + case 'x': + exportname = optarg; + break; case 'v': verbose = 1; break; @@ -780,6 +786,10 @@ int main(int argc, char **argv) if (!exp) { errx(EXIT_FAILURE, "%s", error_get_pretty(local_err)); } + if (exportname) { + nbd_export_set_name(exp, exportname); + newproto = true; + } server_ioc = qio_channel_socket_new(); if (qio_channel_socket_listen_sync(server_ioc, saddr, &local_err) < 0) { diff --git a/qemu-nbd.texi b/qemu-nbd.texi index 9f9daca..22d6b5a 100644 --- a/qemu-nbd.texi +++ b/qemu-nbd.texi @@ -63,6 +63,9 @@ Export QEMU disk image using NBD protocol. force block driver for format @var{fmt} instead of auto-detecting @item -t, --persistent don't exit on the last connection +@item -x NAME, --exportname=NAME + set the NDB volume export name. This switches the server to use + the new style NBD protocol negotiation @item -v, --verbose display extra debugging information @item -h, --help