From 7677f8a7d93e7c72af5b6523b0ff49f29d73002c Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 7 Jul 2017 16:29:01 +0200 Subject: [PATCH] qemu: Move qemuGetDriveSourceProps to qemu_block 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 87634d228b..b3891b5877 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 29b5c4756e..e6b9090151 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 = NULL; + virJSONValuePtr server = NULL; + virJSONValuePtr ret = NULL; + virStorageNetHostDefPtr host; + const char *transport; + size_t i; + + if (!(servers = virJSONValueNewArray())) + goto cleanup; + + for (i = 0; i < src->nhosts; i++) { + host = src->hosts + i; + transport = virStorageNetHostTransportTypeToString(host->transport); + + 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 = NULL; + } + + ret = servers; + servers = NULL; + + cleanup: + virJSONValueFree(servers); + virJSONValueFree(server); + + return ret; +} + + +static virJSONValuePtr +qemuBuildGlusterDriveJSON(virStorageSourcePtr src) +{ + const char *protocol = virStorageNetProtocolTypeToString(src->protocol); + virJSONValuePtr servers = NULL; + virJSONValuePtr ret = NULL; + + if (!(servers = 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 = virStorageSourceGetActualType(src); + virJSONValuePtr fileprops = NULL; + + *props = 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 == VIR_STORAGE_NET_PROTOCOL_GLUSTER && + src->nhosts > 1) { + if (!(fileprops = 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 2af15a65a0..3a8950b138 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 b69ff4ae5d..ebf24361b6 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 = NULL; - virJSONValuePtr server = NULL; - virJSONValuePtr ret = NULL; - virStorageNetHostDefPtr host; - const char *transport; - size_t i; - - if (!(servers = virJSONValueNewArray())) - goto cleanup; - - for (i = 0; i < src->nhosts; i++) { - host = src->hosts + i; - transport = virStorageNetHostTransportTypeToString(host->transport); - - 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 = NULL; - } - - ret = servers; - servers = NULL; - - cleanup: - virJSONValueFree(servers); - virJSONValueFree(server); - - return ret; -} - - -static virJSONValuePtr -qemuBuildGlusterDriveJSON(virStorageSourcePtr src) -{ - const char *protocol = virStorageNetProtocolTypeToString(src->protocol); - virJSONValuePtr servers = NULL; - virJSONValuePtr ret = NULL; - - if (!(servers = 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 = virStorageSourceGetActualType(src); - virJSONValuePtr fileprops = NULL; - - *props = 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 == VIR_STORAGE_NET_PROTOCOL_GLUSTER && - src->nhosts > 1) { - if (!(fileprops = 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,