From nobody Sun Feb 8 23:04:59 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 1490896030222374.3325891321814; Thu, 30 Mar 2017 10:47:10 -0700 (PDT) Received: from localhost ([::1]:36975 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cteA9-0007MS-4N for importer@patchew.org; Thu, 30 Mar 2017 13:47:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35443) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cte6Z-0004PI-3K for qemu-devel@nongnu.org; Thu, 30 Mar 2017 13:43:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cte6X-00030s-J8 for qemu-devel@nongnu.org; Thu, 30 Mar 2017 13:43:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42940) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cte6U-0002vF-83; Thu, 30 Mar 2017 13:43:22 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2EEF9F6257; Thu, 30 Mar 2017 17:43:21 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BCC2C17AFA; Thu, 30 Mar 2017 17:43:20 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 64E3E1138609; Thu, 30 Mar 2017 19:43:17 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2EEF9F6257 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2EEF9F6257 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 30 Mar 2017 19:43:17 +0200 Message-Id: <1490895797-29094-10-git-send-email-armbru@redhat.com> In-Reply-To: <1490895797-29094-1-git-send-email-armbru@redhat.com> References: <1490895797-29094-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 30 Mar 2017 17:43:21 +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] [PATCH v3 for-2.9 9/9] 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: kwolf@redhat.com, qemu-block@nongnu.org, mitake.hitoshi@lab.ntt.co.jp, jcody@redhat.com, mreitz@redhat.com, pbonzini@redhat.com, namei.unix@gmail.com 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" 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 --- block/sheepdog.c | 90 +++++++++++++++++++++++++++++++++---------------= ---- qapi/block-core.json | 4 +-- 2 files changed, 60 insertions(+), 34 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 89e98ed..1b71fc8 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); diff --git a/qapi/block-core.json b/qapi/block-core.json index 8d87962..b5f0e99 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' } } --=20 2.7.4