提交 7ee3df57 编写于 作者: P Peter Krempa

qemu: block: refactor and rename qemuBuildGlusterDriveJSONHosts

New name is qemuBlockStorageSourceBuildHostsJSONSocketAddress since it
formats the JSON object in accordance with qemu's SocketAddress type.

Since the new naming in qemu uses 'inet' instead of 'tcp' add a
compatibility layer for gluster which uses the old name.
上级 bb8ebe69
......@@ -430,9 +430,17 @@ qemuBlockGetNodeData(virJSONValuePtr data)
}
/* builds the hosts array */
/**
* qemuBlockStorageSourceBuildHostsJSONSocketAddress:
* @src: disk storage source
* @legacy: use 'tcp' instead of 'inet' for compatibility reasons
*
* Formats src->hosts into a json object conforming to the 'SocketAddress' type
* in qemu.
*/
static virJSONValuePtr
qemuBuildGlusterDriveJSONHosts(virStorageSourcePtr src)
qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src,
bool legacy)
{
virJSONValuePtr servers = NULL;
virJSONValuePtr server = NULL;
......@@ -446,14 +454,16 @@ qemuBuildGlusterDriveJSONHosts(virStorageSourcePtr src)
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,
if (legacy)
transport = "tcp";
else
transport = "inet";
if (virJSONValueObjectCreate(&server,
"s:type", transport,
"s:host", host->name,
"s:port", host->port,
NULL) < 0)
......@@ -461,7 +471,8 @@ qemuBuildGlusterDriveJSONHosts(virStorageSourcePtr src)
break;
case VIR_STORAGE_NET_HOST_TRANS_UNIX:
if (virJSONValueObjectAdd(server,
if (virJSONValueObjectCreate(&server,
"s:type", "unix",
"s:socket", host->socket,
NULL) < 0)
goto cleanup;
......@@ -481,8 +492,7 @@ qemuBuildGlusterDriveJSONHosts(virStorageSourcePtr src)
server = NULL;
}
ret = servers;
servers = NULL;
VIR_STEAL_PTR(ret, servers);
cleanup:
virJSONValueFree(servers);
......@@ -499,7 +509,7 @@ qemuBuildGlusterDriveJSON(virStorageSourcePtr src)
virJSONValuePtr servers = NULL;
virJSONValuePtr ret = NULL;
if (!(servers = qemuBuildGlusterDriveJSONHosts(src)))
if (!(servers = qemuBlockStorageSourceBuildHostsJSONSocketAddress(src, true)))
return NULL;
/* { driver:"gluster",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册