From patchwork Fri Mar 6 17:14:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11424461 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6CA6F14BC for ; Fri, 6 Mar 2020 17:22:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1DF2420658 for ; Fri, 6 Mar 2020 17:22:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Qxba1+p2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1DF2420658 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:39884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAGfj-0006SA-2W for patchwork-qemu-devel@patchwork.kernel.org; Fri, 06 Mar 2020 12:22:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48548) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAGZV-0004zJ-1p for qemu-devel@nongnu.org; Fri, 06 Mar 2020 12:15:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAGZR-0007wA-AN for qemu-devel@nongnu.org; Fri, 06 Mar 2020 12:15:36 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:33742 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jAGZP-0007nW-E6 for qemu-devel@nongnu.org; Fri, 06 Mar 2020 12:15:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583514930; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sbiw7ViEEU1KfN5mtAV3IGyjNqQC+EGx8FNxWzm7jPA=; b=Qxba1+p2YPY/AvBmATAcUqvEzJ9yxtzyM5EELg6XDIRhnH1i3We9KpDLCkAVgH/gbF9q4/ 2XUHXwO5XDoGDtHWutV0Dz79L3/8MCZm1d3e2Dw3TbVURVqGz1OTdhMYDiRBC8GboJkZ+h yvf8Yhwxo8+dfdyaAUjQtM3byqq2DeM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-248-mxwFAvv6Pge9A-rAbBTotw-1; Fri, 06 Mar 2020 12:15:29 -0500 X-MC-Unique: mxwFAvv6Pge9A-rAbBTotw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC382801E67; Fri, 6 Mar 2020 17:15:27 +0000 (UTC) Received: from linux.fritz.box.com (unknown [10.36.118.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id E055673884; Fri, 6 Mar 2020 17:15:26 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 17/29] qemu-storage-daemon: Add --export option Date: Fri, 6 Mar 2020 18:14:46 +0100 Message-Id: <20200306171458.1848-18-kwolf@redhat.com> In-Reply-To: <20200306171458.1848-1-kwolf@redhat.com> References: <20200306171458.1848-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Add a --export option to qemu-storage-daemon to export a block node. For now, only NBD exports are implemented. Apart from the 'type' option (which is the implied key), it maps the arguments for nbd-server-add to the command line. Example: --export nbd,device=disk,name=test-export,writable=on Signed-off-by: Kevin Wolf Message-Id: <20200224143008.13362-12-kwolf@redhat.com> Acked-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- qapi/block-core.json | 27 +++++++++++++++++++++++++++ qemu-storage-daemon.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index cdc585385c..48631218fa 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -5201,6 +5201,33 @@ ## { 'command': 'nbd-server-stop' } +## +# @BlockExportType: +# +# An enumeration of block export types +# +# @nbd: NBD export +# +# Since: 4.2 +## +{ 'enum': 'BlockExportType', + 'data': [ 'nbd' ] } + +## +# @BlockExport: +# +# Describes a block export, i.e. how single node should be exported on an +# external interface. +# +# Since: 4.2 +## +{ 'union': 'BlockExport', + 'base': { 'type': 'BlockExportType' }, + 'discriminator': 'type', + 'data': { + 'nbd': 'BlockExportNbd' + } } + ## # @QuorumOpType: # diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index 276a412915..5904d3c5b4 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -70,6 +70,11 @@ static void help(void) " [,driver specific parameters...]\n" " configure a block backend\n" "\n" +" --export [type=]nbd,device=[,name=]\n" +" [,writable=on|off][,bitmap=]\n" +" export the specified block node over NBD\n" +" (requires --nbd-server)\n" +"\n" " --nbd-server addr.type=inet,addr.host=,addr.port=\n" " [,tls-creds=][,tls-authz=]\n" " --nbd-server addr.type=unix,addr.path=\n" @@ -91,6 +96,7 @@ QEMU_HELP_BOTTOM "\n", enum { OPTION_BLOCKDEV = 256, + OPTION_EXPORT, OPTION_NBD_SERVER, OPTION_OBJECT, }; @@ -104,12 +110,24 @@ static QemuOptsList qemu_object_opts = { }, }; +static void init_export(BlockExport *export, Error **errp) +{ + switch (export->type) { + case BLOCK_EXPORT_TYPE_NBD: + qmp_nbd_server_add(&export->u.nbd, errp); + break; + default: + g_assert_not_reached(); + } +} + static void process_options(int argc, char *argv[]) { int c; static const struct option long_options[] = { {"blockdev", required_argument, NULL, OPTION_BLOCKDEV}, + {"export", required_argument, NULL, OPTION_EXPORT}, {"help", no_argument, NULL, 'h'}, {"nbd-server", required_argument, NULL, OPTION_NBD_SERVER}, {"object", required_argument, NULL, OPTION_OBJECT}, @@ -156,6 +174,19 @@ static void process_options(int argc, char *argv[]) qapi_free_BlockdevOptions(options); break; } + case OPTION_EXPORT: + { + Visitor *v; + BlockExport *export; + + v = qobject_input_visitor_new_str(optarg, "type", &error_fatal); + visit_type_BlockExport(v, NULL, &export, &error_fatal); + visit_free(v); + + init_export(export, &error_fatal); + qapi_free_BlockExport(export); + break; + } case OPTION_NBD_SERVER: { Visitor *v;