From nobody Tue Feb 10 05:10:31 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149123441568114.810741039046775; Mon, 3 Apr 2017 08:46:55 -0700 (PDT) Received: from localhost ([::1]:59882 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv4By-00086u-9k for importer@patchew.org; Mon, 03 Apr 2017 11:46:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv408-0006St-BA for qemu-devel@nongnu.org; Mon, 03 Apr 2017 11:34:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv406-0007Tw-RO for qemu-devel@nongnu.org; Mon, 03 Apr 2017 11:34:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35876) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cv3zz-0007Ry-Sd; Mon, 03 Apr 2017 11:34:32 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5439F80477; Mon, 3 Apr 2017 15:34:30 +0000 (UTC) Received: from localhost (ovpn-204-55.brq.redhat.com [10.40.204.55]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 043D15C890; Mon, 3 Apr 2017 15:34:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5439F80477 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mreitz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5439F80477 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 3 Apr 2017 17:33:50 +0200 Message-Id: <20170403153355.19722-11-mreitz@redhat.com> In-Reply-To: <20170403153355.19722-1-mreitz@redhat.com> References: <20170403153355.19722-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 03 Apr 2017 15:34:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 10/15] sheepdog: Fix blockdev-add X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Markus Armbruster Commit 831acdc "sheepdog: Implement bdrv_parse_filename()" and commit d282f34 "sheepdog: Support blockdev-add" have different ideas on how the QemuOpts parameters for the server address are named. Fix that. While there, rename BlockdevOptionsSheepdog member addr to server, for consistency with BlockdevOptionsSsh, BlockdevOptionsGluster, BlockdevOptionsNbd. Commit 831acdc's example becomes --drive driver=3Dsheepdog,server.type=3Dinet,server.host=3Dfido,server.= port=3D7000,vdi=3Ddolly instead of --drive driver=3Dsheepdog,host=3Dfido,vdi=3Ddolly Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Tested-by: Kashyap Chamarthy Message-id: 1490895797-29094-10-git-send-email-armbru@redhat.com Signed-off-by: Max Reitz --- qapi/block-core.json | 4 +-- block/sheepdog.c | 90 +++++++++++++++++++++++++++++++++---------------= ---- 2 files changed, 60 insertions(+), 34 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index e4d8a63575..033457ce86 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2623,7 +2623,7 @@ # Driver specific block device options for sheepdog # # @vdi: Virtual disk image name -# @addr: The Sheepdog server to connect to +# @server: The Sheepdog server to connect to # @snap-id: Snapshot ID # @tag: Snapshot tag name # @@ -2632,7 +2632,7 @@ # Since: 2.9 ## { 'struct': 'BlockdevOptionsSheepdog', - 'data': { 'addr': 'SocketAddressFlat', + 'data': { 'server': 'SocketAddressFlat', 'vdi': 'str', '*snap-id': 'uint32', '*tag': 'str' } } diff --git a/block/sheepdog.c b/block/sheepdog.c index 89e98edab6..1b71fc81ec 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -13,9 +13,11 @@ */ =20 #include "qemu/osdep.h" +#include "qapi-visit.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qint.h" +#include "qapi/qobject-input-visitor.h" #include "qemu/uri.h" #include "qemu/error-report.h" #include "qemu/sockets.h" @@ -547,6 +549,47 @@ static SocketAddress *sd_socket_address(const char *pa= th, return addr; } =20 +static SocketAddress *sd_server_config(QDict *options, Error **errp) +{ + QDict *server =3D NULL; + QObject *crumpled_server =3D NULL; + Visitor *iv =3D NULL; + SocketAddressFlat *saddr_flat =3D NULL; + SocketAddress *saddr =3D NULL; + Error *local_err =3D NULL; + + qdict_extract_subqdict(options, &server, "server."); + + crumpled_server =3D qdict_crumple(server, errp); + if (!crumpled_server) { + goto done; + } + + /* + * FIXME .numeric, .to, .ipv4 or .ipv6 don't work with -drive + * server.type=3Dinet. .to doesn't matter, it's ignored anyway. + * That's because when @options come from -blockdev or + * blockdev_add, members are typed according to the QAPI schema, + * but when they come from -drive, they're all QString. The + * visitor expects the former. + */ + iv =3D qobject_input_visitor_new(crumpled_server); + visit_type_SocketAddressFlat(iv, NULL, &saddr_flat, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto done; + } + + saddr =3D socket_address_crumple(saddr_flat); + +done: + qapi_free_SocketAddressFlat(saddr_flat); + visit_free(iv); + qobject_decref(crumpled_server); + QDECREF(server); + return saddr; +} + /* Return -EIO in case of error, file descriptor on success */ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) { @@ -1174,15 +1217,15 @@ static void sd_parse_filename(const char *filename,= QDict *options, return; } =20 - if (cfg.host) { - qdict_set_default_str(options, "host", cfg.host); - } - if (cfg.port) { - snprintf(buf, sizeof(buf), "%d", cfg.port); - qdict_set_default_str(options, "port", buf); - } if (cfg.path) { - qdict_set_default_str(options, "path", cfg.path); + qdict_set_default_str(options, "server.path", cfg.path); + qdict_set_default_str(options, "server.type", "unix"); + } else { + qdict_set_default_str(options, "server.type", "inet"); + qdict_set_default_str(options, "server.host", + cfg.host ?: SD_DEFAULT_ADDR); + snprintf(buf, sizeof(buf), "%d", cfg.port ?: SD_DEFAULT_PORT); + qdict_set_default_str(options, "server.port", buf); } qdict_set_default_str(options, "vdi", cfg.vdi); qdict_set_default_str(options, "tag", cfg.tag); @@ -1510,18 +1553,6 @@ static QemuOptsList runtime_opts =3D { .head =3D QTAILQ_HEAD_INITIALIZER(runtime_opts.head), .desc =3D { { - .name =3D "host", - .type =3D QEMU_OPT_STRING, - }, - { - .name =3D "port", - .type =3D QEMU_OPT_STRING, - }, - { - .name =3D "path", - .type =3D QEMU_OPT_STRING, - }, - { .name =3D "vdi", .type =3D QEMU_OPT_STRING, }, @@ -1543,7 +1574,7 @@ static int sd_open(BlockDriverState *bs, QDict *optio= ns, int flags, int ret, fd; uint32_t vid =3D 0; BDRVSheepdogState *s =3D bs->opaque; - const char *host, *port, *path, *vdi, *snap_id_str, *tag; + const char *vdi, *snap_id_str, *tag; uint64_t snap_id; char *buf =3D NULL; QemuOpts *opts; @@ -1560,20 +1591,17 @@ static int sd_open(BlockDriverState *bs, QDict *opt= ions, int flags, goto err_no_fd; } =20 - host =3D qemu_opt_get(opts, "host"); - port =3D qemu_opt_get(opts, "port"); - path =3D qemu_opt_get(opts, "path"); + s->addr =3D sd_server_config(options, errp); + if (!s->addr) { + ret =3D -EINVAL; + goto err_no_fd; + } + vdi =3D qemu_opt_get(opts, "vdi"); snap_id_str =3D qemu_opt_get(opts, "snap-id"); snap_id =3D qemu_opt_get_number(opts, "snap-id", CURRENT_VDI_ID); tag =3D qemu_opt_get(opts, "tag"); =20 - if ((host || port) && path) { - error_setg(errp, "can't use 'path' together with 'host' or 'port'"= ); - ret =3D -EINVAL; - goto err_no_fd; - } - if (!vdi) { error_setg(errp, "parameter 'vdi' is missing"); ret =3D -EINVAL; @@ -1604,8 +1632,6 @@ static int sd_open(BlockDriverState *bs, QDict *optio= ns, int flags, goto err_no_fd; } =20 - s->addr =3D sd_socket_address(path, host, port); - QLIST_INIT(&s->inflight_aio_head); QLIST_INIT(&s->failed_aio_head); QLIST_INIT(&s->inflight_aiocb_head); --=20 2.12.1