From patchwork Thu Jan 21 16:37:21 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: 8083021 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D1519BEEE5 for ; Thu, 21 Jan 2016 16:39:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2CDB3203F7 for ; Thu, 21 Jan 2016 16:39:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 68BF620390 for ; Thu, 21 Jan 2016 16:39:52 +0000 (UTC) Received: from localhost ([::1]:48644 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMIH1-0008Jv-PX for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Jan 2016 11:39:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMIF3-0004ln-VP for qemu-devel@nongnu.org; Thu, 21 Jan 2016 11:37:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMIF2-0004DX-Vo for qemu-devel@nongnu.org; Thu, 21 Jan 2016 11:37:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54401) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMIF0-0004BQ-Pd; Thu, 21 Jan 2016 11:37:46 -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 6AEB83B75A; Thu, 21 Jan 2016 16:37:46 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-6-170.ams2.redhat.com [10.36.6.170]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0LGbXn5001020; Thu, 21 Jan 2016 11:37:45 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 21 Jan 2016 16:37:21 +0000 Message-Id: <1453394247-2267-9-git-send-email-berrange@redhat.com> In-Reply-To: <1453394247-2267-1-git-send-email-berrange@redhat.com> References: <1453394247-2267-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 , qemu-block@nongnu.org Subject: [Qemu-devel] [PATCH v4 08/14] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 "--exportname NAME" / "-x NAME" arguments to qemu-nbd which allow the user to set an explicit export name. When an export name is set the server will always use the new style NBD 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 45eb416..d494112 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -47,6 +47,7 @@ #define QEMU_NBD_OPT_IMAGE_OPTS 261 static NBDExport *exp; +static bool newproto; static int verbose; static char *srcpath; static SocketAddress *saddr; @@ -342,7 +343,7 @@ static gboolean nbd_accept(QIOChannel *ioc, GIOCondition cond, gpointer opaque) nb_fds++; nbd_update_server_watch(); - nbd_client_new(exp, cioc, nbd_client_closed); + nbd_client_new(newproto ? NULL : exp, cioc, nbd_client_closed); object_unref(OBJECT(cioc)); return TRUE; @@ -445,7 +446,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", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, @@ -471,6 +472,7 @@ int main(int argc, char **argv) { "verbose", no_argument, NULL, 'v' }, { "object", required_argument, NULL, QEMU_NBD_OPT_OBJECT }, { "image-opts", no_argument, NULL, QEMU_NBD_OPT_IMAGE_OPTS }, + { "export-name", required_argument, NULL, 'x' }, { NULL, 0, NULL, 0 } }; int ch; @@ -489,6 +491,7 @@ int main(int argc, char **argv) QDict *options = NULL; QemuOpts *opts; bool imageOpts = false; + const char *export_name = 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. @@ -640,6 +643,9 @@ int main(int argc, char **argv) case 't': persistent = 1; break; + case 'x': + export_name = optarg; + break; case 'v': verbose = 1; break; @@ -840,6 +846,10 @@ int main(int argc, char **argv) error_report_err(local_err); exit(EXIT_FAILURE); } + if (export_name) { + nbd_export_set_name(exp, export_name); + 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..5fbe486 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, --export-name=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