提交 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) ...@@ -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 static virJSONValuePtr
qemuBuildGlusterDriveJSONHosts(virStorageSourcePtr src) qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src,
bool legacy)
{ {
virJSONValuePtr servers = NULL; virJSONValuePtr servers = NULL;
virJSONValuePtr server = NULL; virJSONValuePtr server = NULL;
...@@ -446,24 +454,27 @@ qemuBuildGlusterDriveJSONHosts(virStorageSourcePtr src) ...@@ -446,24 +454,27 @@ qemuBuildGlusterDriveJSONHosts(virStorageSourcePtr src)
for (i = 0; i < src->nhosts; i++) { for (i = 0; i < src->nhosts; i++) {
host = src->hosts + i; host = src->hosts + i;
transport = virStorageNetHostTransportTypeToString(host->transport);
if (virJSONValueObjectCreate(&server, "s:type", transport, NULL) < 0)
goto cleanup;
switch ((virStorageNetHostTransport) host->transport) { switch ((virStorageNetHostTransport) host->transport) {
case VIR_STORAGE_NET_HOST_TRANS_TCP: case VIR_STORAGE_NET_HOST_TRANS_TCP:
if (virJSONValueObjectAdd(server, if (legacy)
"s:host", host->name, transport = "tcp";
"s:port", host->port, else
NULL) < 0) transport = "inet";
if (virJSONValueObjectCreate(&server,
"s:type", transport,
"s:host", host->name,
"s:port", host->port,
NULL) < 0)
goto cleanup; goto cleanup;
break; break;
case VIR_STORAGE_NET_HOST_TRANS_UNIX: case VIR_STORAGE_NET_HOST_TRANS_UNIX:
if (virJSONValueObjectAdd(server, if (virJSONValueObjectCreate(&server,
"s:socket", host->socket, "s:type", "unix",
NULL) < 0) "s:socket", host->socket,
NULL) < 0)
goto cleanup; goto cleanup;
break; break;
...@@ -481,8 +492,7 @@ qemuBuildGlusterDriveJSONHosts(virStorageSourcePtr src) ...@@ -481,8 +492,7 @@ qemuBuildGlusterDriveJSONHosts(virStorageSourcePtr src)
server = NULL; server = NULL;
} }
ret = servers; VIR_STEAL_PTR(ret, servers);
servers = NULL;
cleanup: cleanup:
virJSONValueFree(servers); virJSONValueFree(servers);
...@@ -499,7 +509,7 @@ qemuBuildGlusterDriveJSON(virStorageSourcePtr src) ...@@ -499,7 +509,7 @@ qemuBuildGlusterDriveJSON(virStorageSourcePtr src)
virJSONValuePtr servers = NULL; virJSONValuePtr servers = NULL;
virJSONValuePtr ret = NULL; virJSONValuePtr ret = NULL;
if (!(servers = qemuBuildGlusterDriveJSONHosts(src))) if (!(servers = qemuBlockStorageSourceBuildHostsJSONSocketAddress(src, true)))
return NULL; return NULL;
/* { driver:"gluster", /* { driver:"gluster",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册