From nobody Fri May 16 04:53:32 2025 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 1499688497264894.2642547826767; Mon, 10 Jul 2017 05:08:17 -0700 (PDT) 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 C81767F3FC; Mon, 10 Jul 2017 12:08:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 86A8D17269; Mon, 10 Jul 2017 12:08:12 +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 21C4A157CB; Mon, 10 Jul 2017 12:08:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6AC7pSb018609 for ; Mon, 10 Jul 2017 08:07:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4046E182EB; Mon, 10 Jul 2017 12:07:51 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BD15182E7; Mon, 10 Jul 2017 12:07:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C81767F3FC Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C81767F3FC From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 10 Jul 2017 14:07:39 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 07/10] qemu: Move qemuGetDriveSourceProps to qemu_block 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 10 Jul 2017 12:08:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Pure code movement except for the tweaks necessary for cross-usage. --- po/POTFILES.in | 1 + src/qemu/qemu_block.c | 126 ++++++++++++++++++++++++++++++++++++++++++++= +++ src/qemu/qemu_block.h | 5 ++ src/qemu/qemu_command.c | 127 +-------------------------------------------= ---- 4 files changed, 133 insertions(+), 126 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 275df1f29..b5e99e084 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -129,6 +129,7 @@ src/openvz/openvz_util.c src/phyp/phyp_driver.c src/qemu/qemu_agent.c src/qemu/qemu_alias.c +src/qemu/qemu_block.c src/qemu/qemu_capabilities.c src/qemu/qemu_cgroup.c src/qemu/qemu_command.c diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 29b5c4756..e6b909015 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -428,3 +428,129 @@ qemuBlockGetNodeData(virJSONValuePtr data) virHashFree(ret); return NULL; } + + +/* builds the hosts array */ +static virJSONValuePtr +qemuBuildGlusterDriveJSONHosts(virStorageSourcePtr src) +{ + virJSONValuePtr servers =3D NULL; + virJSONValuePtr server =3D NULL; + virJSONValuePtr ret =3D NULL; + virStorageNetHostDefPtr host; + const char *transport; + size_t i; + + if (!(servers =3D virJSONValueNewArray())) + goto cleanup; + + for (i =3D 0; i < src->nhosts; i++) { + host =3D src->hosts + i; + transport =3D virStorageNetHostTransportTypeToString(host->transpo= rt); + + if (virJSONValueObjectCreate(&server, "s:type", transport, NULL) <= 0) + goto cleanup; + + switch ((virStorageNetHostTransport) host->transport) { + case VIR_STORAGE_NET_HOST_TRANS_TCP: + if (virJSONValueObjectAdd(server, + "s:host", host->name, + "s:port", host->port, + NULL) < 0) + goto cleanup; + break; + + case VIR_STORAGE_NET_HOST_TRANS_UNIX: + if (virJSONValueObjectAdd(server, + "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= "), + transport); + goto cleanup; + } + + if (virJSONValueArrayAppend(servers, server) < 0) + goto cleanup; + + server =3D NULL; + } + + ret =3D servers; + servers =3D NULL; + + cleanup: + virJSONValueFree(servers); + virJSONValueFree(server); + + return ret; +} + + +static virJSONValuePtr +qemuBuildGlusterDriveJSON(virStorageSourcePtr src) +{ + const char *protocol =3D virStorageNetProtocolTypeToString(src->protoc= ol); + virJSONValuePtr servers =3D NULL; + virJSONValuePtr ret =3D NULL; + + if (!(servers =3D qemuBuildGlusterDriveJSONHosts(src))) + return NULL; + + /* { driver:"gluster", + * volume:"testvol", + * path:"/a.img", + * server :[{type:"tcp", host:"1.2.3.4", port:24007}, + * {type:"unix", socket:"/tmp/glusterd.socket"}, ...]} + */ + if (virJSONValueObjectCreate(&ret, + "s:driver", protocol, + "s:volume", src->volume, + "s:path", src->path, + "a:server", servers, NULL) < 0) + virJSONValueFree(servers); + + return ret; +} + + +int +qemuGetDriveSourceProps(virStorageSourcePtr src, + virJSONValuePtr *props) +{ + int actualType =3D virStorageSourceGetActualType(src); + virJSONValuePtr fileprops =3D NULL; + + *props =3D NULL; + + switch ((virStorageType) actualType) { + case VIR_STORAGE_TYPE_BLOCK: + case VIR_STORAGE_TYPE_FILE: + case VIR_STORAGE_TYPE_DIR: + case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NONE: + case VIR_STORAGE_TYPE_LAST: + break; + + case VIR_STORAGE_TYPE_NETWORK: + if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_GLUSTER && + src->nhosts > 1) { + if (!(fileprops =3D qemuBuildGlusterDriveJSON(src))) + return -1; + } + break; + } + + if (fileprops && + virJSONValueObjectCreate(props, "a:file", fileprops, NULL) < 0) { + virJSONValueFree(fileprops); + return -1; + } + + return 0; +} diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 2af15a65a..3a8950b13 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -53,4 +53,9 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver, virHashTablePtr qemuBlockGetNodeData(virJSONValuePtr data); + +int +qemuGetDriveSourceProps(virStorageSourcePtr src, + virJSONValuePtr *props); + #endif /* __QEMU_BLOCK_H__ */ diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 376082320..963224335 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -29,6 +29,7 @@ #include "qemu_interface.h" #include "qemu_alias.h" #include "qemu_security.h" +#include "qemu_block.h" #include "cpu/cpu.h" #include "dirname.h" #include "viralloc.h" @@ -792,95 +793,6 @@ qemuBuildTLSx509CommandLine(virCommandPtr cmd, } -/* builds the hosts array */ -static virJSONValuePtr -qemuBuildGlusterDriveJSONHosts(virStorageSourcePtr src) -{ - virJSONValuePtr servers =3D NULL; - virJSONValuePtr server =3D NULL; - virJSONValuePtr ret =3D NULL; - virStorageNetHostDefPtr host; - const char *transport; - size_t i; - - if (!(servers =3D virJSONValueNewArray())) - goto cleanup; - - for (i =3D 0; i < src->nhosts; i++) { - host =3D src->hosts + i; - transport =3D virStorageNetHostTransportTypeToString(host->transpo= rt); - - if (virJSONValueObjectCreate(&server, "s:type", transport, NULL) <= 0) - goto cleanup; - - switch ((virStorageNetHostTransport) host->transport) { - case VIR_STORAGE_NET_HOST_TRANS_TCP: - if (virJSONValueObjectAdd(server, - "s:host", host->name, - "s:port", host->port, - NULL) < 0) - goto cleanup; - break; - - case VIR_STORAGE_NET_HOST_TRANS_UNIX: - if (virJSONValueObjectAdd(server, - "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= "), - transport); - goto cleanup; - } - - if (virJSONValueArrayAppend(servers, server) < 0) - goto cleanup; - - server =3D NULL; - } - - ret =3D servers; - servers =3D NULL; - - cleanup: - virJSONValueFree(servers); - virJSONValueFree(server); - - return ret; -} - - -static virJSONValuePtr -qemuBuildGlusterDriveJSON(virStorageSourcePtr src) -{ - const char *protocol =3D virStorageNetProtocolTypeToString(src->protoc= ol); - virJSONValuePtr servers =3D NULL; - virJSONValuePtr ret =3D NULL; - - if (!(servers =3D qemuBuildGlusterDriveJSONHosts(src))) - return NULL; - - /* { driver:"gluster", - * volume:"testvol", - * path:"/a.img", - * server :[{type:"tcp", host:"1.2.3.4", port:24007}, - * {type:"unix", socket:"/tmp/glusterd.socket"}, ...]} - */ - if (virJSONValueObjectCreate(&ret, - "s:driver", protocol, - "s:volume", src->volume, - "s:path", src->path, - "a:server", servers, NULL) < 0) - virJSONValueFree(servers); - - return ret; -} - - static char * qemuBuildNetworkDriveURI(virStorageSourcePtr src, qemuDomainSecretInfoPtr secinfo) @@ -1103,43 +1015,6 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, } -static int -qemuGetDriveSourceProps(virStorageSourcePtr src, - virJSONValuePtr *props) -{ - int actualType =3D virStorageSourceGetActualType(src); - virJSONValuePtr fileprops =3D NULL; - - *props =3D NULL; - - switch ((virStorageType) actualType) { - case VIR_STORAGE_TYPE_BLOCK: - case VIR_STORAGE_TYPE_FILE: - case VIR_STORAGE_TYPE_DIR: - case VIR_STORAGE_TYPE_VOLUME: - case VIR_STORAGE_TYPE_NONE: - case VIR_STORAGE_TYPE_LAST: - break; - - case VIR_STORAGE_TYPE_NETWORK: - if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_GLUSTER && - src->nhosts > 1) { - if (!(fileprops =3D qemuBuildGlusterDriveJSON(src))) - return -1; - } - break; - } - - if (fileprops && - virJSONValueObjectCreate(props, "a:file", fileprops, NULL) < 0) { - virJSONValueFree(fileprops); - return -1; - } - - return 0; -} - - int qemuGetDriveSourceString(virStorageSourcePtr src, qemuDomainSecretInfoPtr secinfo, --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list