From patchwork Fri Mar 6 17:14:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11424463 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 26D3714BC for ; Fri, 6 Mar 2020 17:22:15 +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 F0EC620658 for ; Fri, 6 Mar 2020 17:22:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e5Wx+XnD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F0EC620658 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]:39890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAGfu-0006eB-4Z for patchwork-qemu-devel@patchwork.kernel.org; Fri, 06 Mar 2020 12:22:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48553) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAGZV-0004zT-3T for qemu-devel@nongnu.org; Fri, 06 Mar 2020 12:15:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAGZR-0007wF-9M for qemu-devel@nongnu.org; Fri, 06 Mar 2020 12:15:36 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:29936 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-0007hz-Ek 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=1583514929; 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=tboAIphVvqU1ZFgI6+jiEo1h3mxn9y2aYL7rSvanyKM=; b=e5Wx+XnDSt/cJNhOCug22t113m15yllEMRY33moBBw+hSeTifZeDEj5YdZuTEqt+CCIvfU RgQX0ReTHljYndBIySwtCobTov2K6Nhu+ppwqmyO1dggoM0/XJlhmGfTJ9NF3o8U/OqahV /zMLUhrjDOH4MhtWeg12NumeqjiGqLo= 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-425-atHyNf73OeqRTLra91MlRw-1; Fri, 06 Mar 2020 12:15:27 -0500 X-MC-Unique: atHyNf73OeqRTLra91MlRw-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 9CC4E184C805; Fri, 6 Mar 2020 17:15:26 +0000 (UTC) Received: from linux.fritz.box.com (unknown [10.36.118.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CC9473873; Fri, 6 Mar 2020 17:15:25 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 16/29] blockdev-nbd: Boxed argument type for nbd-server-add Date: Fri, 6 Mar 2020 18:14:45 +0100 Message-Id: <20200306171458.1848-17-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] [fuzzy] X-Received-From: 207.211.31.81 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" Move the arguments of nbd-server-add to a new struct BlockExportNbd and convert the command to 'boxed': true. This makes it easier to share code with the storage daemon. Signed-off-by: Kevin Wolf Message-Id: <20200224143008.13362-11-kwolf@redhat.com> Acked-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- qapi/block-core.json | 18 ++++++++++++++---- blockdev-nbd.c | 35 ++++++++++++++++------------------- monitor/hmp-cmds.c | 21 +++++++++++++++++---- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index f8888f06c8..cdc585385c 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -5112,9 +5112,9 @@ '*tls-authz': 'str'} } ## -# @nbd-server-add: +# @BlockExportNbd: # -# Export a block node to QEMU's embedded NBD server. +# An NBD block export. # # @device: The device name or node name of the node to be exported # @@ -5131,14 +5131,24 @@ # NBD client can use NBD_OPT_SET_META_CONTEXT with # "qemu:dirty-bitmap:NAME" to inspect the bitmap. (since 4.0) # +# Since: 5.0 +## +{ 'struct': 'BlockExportNbd', + 'data': {'device': 'str', '*name': 'str', '*description': 'str', + '*writable': 'bool', '*bitmap': 'str' } } + +## +# @nbd-server-add: +# +# Export a block node to QEMU's embedded NBD server. +# # Returns: error if the server is not running, or export with the same name # already exists. # # Since: 1.3.0 ## { 'command': 'nbd-server-add', - 'data': {'device': 'str', '*name': 'str', '*description': 'str', - '*writable': 'bool', '*bitmap': 'str' } } + 'data': 'BlockExportNbd', 'boxed': true } ## # @NbdServerRemoveMode: diff --git a/blockdev-nbd.c b/blockdev-nbd.c index d8c892f7da..1a95d89f00 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -148,10 +148,7 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr, qapi_free_SocketAddress(addr_flat); } -void qmp_nbd_server_add(const char *device, bool has_name, const char *name, - bool has_description, const char *description, - bool has_writable, bool writable, - bool has_bitmap, const char *bitmap, Error **errp) +void qmp_nbd_server_add(BlockExportNbd *arg, Error **errp) { BlockDriverState *bs = NULL; BlockBackend *on_eject_blk; @@ -164,28 +161,28 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name, return; } - if (!has_name) { - name = device; + if (!arg->has_name) { + arg->name = arg->device; } - if (strlen(name) > NBD_MAX_STRING_SIZE) { - error_setg(errp, "export name '%s' too long", name); + if (strlen(arg->name) > NBD_MAX_STRING_SIZE) { + error_setg(errp, "export name '%s' too long", arg->name); return; } - if (has_description && strlen(description) > NBD_MAX_STRING_SIZE) { - error_setg(errp, "description '%s' too long", description); + if (arg->description && strlen(arg->description) > NBD_MAX_STRING_SIZE) { + error_setg(errp, "description '%s' too long", arg->description); return; } - if (nbd_export_find(name)) { - error_setg(errp, "NBD server already has export named '%s'", name); + if (nbd_export_find(arg->name)) { + error_setg(errp, "NBD server already has export named '%s'", arg->name); return; } - on_eject_blk = blk_by_name(device); + on_eject_blk = blk_by_name(arg->device); - bs = bdrv_lookup_bs(device, device, errp); + bs = bdrv_lookup_bs(arg->device, arg->device, errp); if (!bs) { return; } @@ -199,15 +196,15 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name, goto out; } - if (!has_writable) { - writable = false; + if (!arg->has_writable) { + arg->writable = false; } if (bdrv_is_read_only(bs)) { - writable = false; + arg->writable = false; } - exp = nbd_export_new(bs, 0, len, name, description, bitmap, - !writable, !writable, + exp = nbd_export_new(bs, 0, len, arg->name, arg->description, arg->bitmap, + !arg->writable, !arg->writable, NULL, false, on_eject_blk, errp); if (!exp) { goto out; diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 30313858c2..fb4c2fd2a8 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -2341,6 +2341,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) Error *local_err = NULL; BlockInfoList *block_list, *info; SocketAddress *addr; + BlockExportNbd export; if (writable && !all) { error_setg(&local_err, "-w only valid together with -a"); @@ -2373,8 +2374,13 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) continue; } - qmp_nbd_server_add(info->value->device, false, NULL, false, NULL, - true, writable, false, NULL, &local_err); + export = (BlockExportNbd) { + .device = info->value->device, + .has_writable = true, + .writable = writable, + }; + + qmp_nbd_server_add(&export, &local_err); if (local_err != NULL) { qmp_nbd_server_stop(NULL); @@ -2395,8 +2401,15 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) bool writable = qdict_get_try_bool(qdict, "writable", false); Error *local_err = NULL; - qmp_nbd_server_add(device, !!name, name, false, NULL, true, writable, - false, NULL, &local_err); + BlockExportNbd export = { + .device = (char *) device, + .has_name = !!name, + .name = (char *) name, + .has_writable = true, + .writable = writable, + }; + + qmp_nbd_server_add(&export, &local_err); hmp_handle_error(mon, local_err); }