mirror of https://gitee.com/openkylin/libvirt.git
qemu: Move qemuGetDriveSourceProps to qemu_block
Pure code movement except for the tweaks necessary for cross-usage.
This commit is contained in:
parent
f96e97737b
commit
7677f8a7d9
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -53,4 +53,9 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver,
|
|||
virHashTablePtr
|
||||
qemuBlockGetNodeData(virJSONValuePtr data);
|
||||
|
||||
|
||||
int
|
||||
qemuGetDriveSourceProps(virStorageSourcePtr src,
|
||||
virJSONValuePtr *props);
|
||||
|
||||
#endif /* __QEMU_BLOCK_H__ */
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue