From nobody Fri May 3 05:06:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1505241450969185.57169741049165; Tue, 12 Sep 2017 11:37:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2D41B5F723; Tue, 12 Sep 2017 18:37:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5838B61981; Tue, 12 Sep 2017 18:37:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6CC6E180884A; Tue, 12 Sep 2017 18:37:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v8CIC5J4012461 for ; Tue, 12 Sep 2017 14:12:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id C6B2C17BB4; Tue, 12 Sep 2017 18:12:05 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-114.phx2.redhat.com [10.3.117.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A07E5FCA2 for ; Tue, 12 Sep 2017 18:12:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2D41B5F723 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Tue, 12 Sep 2017 14:12:01 -0400 Message-Id: <20170912181201.12315-1-jferlan@redhat.com> In-Reply-To: <20170901170955.20281-1-jferlan@redhat.com> References: <20170901170955.20281-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v7 05.5/13] qemu: Refactor qemuBlockStorageSourceBuildHostsJSONSocketAddress X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 12 Sep 2017 18:37:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Extract out the "guts" of building a server entry into it's own separately callable/usable function in order to allow building a server entry for a consumer with src->nhosts =3D=3D 1. Signed-off-by: John Ferlan --- This patch would go after patch 5 and before patch 6 in the order of things. All it does is extract out the "single" server syntax into it's own function so that it can be used by code that supports only 1 host. It's also usable by the multiple hosts support via the array append call. src/qemu/qemu_block.c | 106 +++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 70 insertions(+), 36 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index d07269f4e..c97b787c5 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -380,6 +380,74 @@ qemuBlockGetNodeData(virJSONValuePtr data) =20 =20 /** + * qemuBlockStorageSourceBuildJSONSocketAddress + * @host: the virStorageNetHostDefPtr definition to build + * @legacy: use 'tcp' instead of 'inet' for compatibility reasons + * + * Formats @hosts into a json object conforming to the 'SocketAddress' type + * in qemu. + * + * This function can be used when only 1 src->nhosts is expected in order + * to build a command without the array indices after "server.". That is + * to see "server.type", "server.host", and "server.port" instead of + * "server.#.type", "server.#.host", and "server.#.port". + * + * Returns a virJSONValuePtr for a single server. + */ +static virJSONValuePtr +qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr host, + bool legacy) +{ + virJSONValuePtr server =3D NULL; + virJSONValuePtr ret =3D NULL; + const char *transport; + char *port =3D NULL; + + switch ((virStorageNetHostTransport) host->transport) { + case VIR_STORAGE_NET_HOST_TRANS_TCP: + if (legacy) + transport =3D "tcp"; + else + transport =3D "inet"; + + if (virAsprintf(&port, "%u", host->port) < 0) + goto cleanup; + + if (virJSONValueObjectCreate(&server, + "s:type", transport, + "s:host", host->name, + "s:port", port, + NULL) < 0) + goto cleanup; + break; + + case VIR_STORAGE_NET_HOST_TRANS_UNIX: + if (virJSONValueObjectCreate(&server, + "s:type", "unix", + "s:socket", host->socket, + NULL) < 0) + goto cleanup; + break; + + case VIR_STORAGE_NET_HOST_TRANS_RDMA: + case VIR_STORAGE_NET_HOST_TRANS_LAST: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("transport protocol '%s' is not yet supported"), + virStorageNetHostTransportTypeToString(host->transp= ort)); + goto cleanup; + } + + VIR_STEAL_PTR(ret, server); + + cleanup: + VIR_FREE(port); + virJSONValueFree(server); + + return ret; +} + + +/** * qemuBlockStorageSourceBuildHostsJSONSocketAddress: * @src: disk storage source * @legacy: use 'tcp' instead of 'inet' for compatibility reasons @@ -395,8 +463,6 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virSt= orageSourcePtr src, virJSONValuePtr server =3D NULL; virJSONValuePtr ret =3D NULL; virStorageNetHostDefPtr host; - const char *transport; - char *port =3D NULL; size_t i; =20 if (!(servers =3D virJSONValueNewArray())) @@ -405,39 +471,8 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virS= torageSourcePtr src, for (i =3D 0; i < src->nhosts; i++) { host =3D src->hosts + i; =20 - switch ((virStorageNetHostTransport) host->transport) { - case VIR_STORAGE_NET_HOST_TRANS_TCP: - if (legacy) - transport =3D "tcp"; - else - transport =3D "inet"; - - if (virAsprintf(&port, "%u", host->port) < 0) - goto cleanup; - - if (virJSONValueObjectCreate(&server, - "s:type", transport, - "s:host", host->name, - "s:port", port, - NULL) < 0) - goto cleanup; - break; - - case VIR_STORAGE_NET_HOST_TRANS_UNIX: - if (virJSONValueObjectCreate(&server, - "s:type", "unix", - "s:socket", host->socket, - NULL) < 0) - goto cleanup; - break; - - case VIR_STORAGE_NET_HOST_TRANS_RDMA: - case VIR_STORAGE_NET_HOST_TRANS_LAST: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("transport protocol '%s' is not yet supported= "), - virStorageNetHostTransportTypeToString(host->tr= ansport)); - goto cleanup; - } + if (!(server =3D qemuBlockStorageSourceBuildJSONSocketAddress(host= , legacy))) + goto cleanup; =20 if (virJSONValueArrayAppend(servers, server) < 0) goto cleanup; @@ -450,7 +485,6 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virSt= orageSourcePtr src, cleanup: virJSONValueFree(servers); virJSONValueFree(server); - VIR_FREE(port); =20 return ret; } --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list