mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
qemu: Refactor qemuBlockStorageSourceBuildHostsJSONSocketAddress
Extract out the "guts" of building a server entry into it's own separately callable/usable function in order to allow building a server entry for a consumer with src->nhosts == 1.
This commit is contained in:
parent
2a48252bb5
commit
8b5e76e913
@ -380,30 +380,28 @@ qemuBlockGetNodeData(virJSONValuePtr data)
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qemuBlockStorageSourceBuildHostsJSONSocketAddress:
|
* qemuBlockStorageSourceBuildJSONSocketAddress
|
||||||
* @src: disk storage source
|
* @host: the virStorageNetHostDefPtr definition to build
|
||||||
* @legacy: use 'tcp' instead of 'inet' for compatibility reasons
|
* @legacy: use 'tcp' instead of 'inet' for compatibility reasons
|
||||||
*
|
*
|
||||||
* Formats src->hosts into a json object conforming to the 'SocketAddress' type
|
* Formats @hosts into a json object conforming to the 'SocketAddress' type
|
||||||
* in qemu.
|
* in qemu.
|
||||||
|
*
|
||||||
|
* This function can be used when only 1 src->nhosts is expected in order
|
||||||
|
* to build a command without the array indices after "server.". That is
|
||||||
|
* to see "server.type", "server.host", and "server.port" instead of
|
||||||
|
* "server.#.type", "server.#.host", and "server.#.port".
|
||||||
|
*
|
||||||
|
* Returns a virJSONValuePtr for a single server.
|
||||||
*/
|
*/
|
||||||
static virJSONValuePtr
|
static virJSONValuePtr
|
||||||
qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src,
|
qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr host,
|
||||||
bool legacy)
|
bool legacy)
|
||||||
{
|
{
|
||||||
virJSONValuePtr servers = NULL;
|
|
||||||
virJSONValuePtr server = NULL;
|
virJSONValuePtr server = NULL;
|
||||||
virJSONValuePtr ret = NULL;
|
virJSONValuePtr ret = NULL;
|
||||||
virStorageNetHostDefPtr host;
|
|
||||||
const char *transport;
|
const char *transport;
|
||||||
char *port = NULL;
|
char *port = NULL;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (!(servers = virJSONValueNewArray()))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
for (i = 0; i < src->nhosts; i++) {
|
|
||||||
host = src->hosts + i;
|
|
||||||
|
|
||||||
switch ((virStorageNetHostTransport) host->transport) {
|
switch ((virStorageNetHostTransport) host->transport) {
|
||||||
case VIR_STORAGE_NET_HOST_TRANS_TCP:
|
case VIR_STORAGE_NET_HOST_TRANS_TCP:
|
||||||
@ -439,6 +437,43 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VIR_STEAL_PTR(ret, server);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(port);
|
||||||
|
virJSONValueFree(server);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src,
|
||||||
|
bool legacy)
|
||||||
|
{
|
||||||
|
virJSONValuePtr servers = NULL;
|
||||||
|
virJSONValuePtr server = NULL;
|
||||||
|
virJSONValuePtr ret = NULL;
|
||||||
|
virStorageNetHostDefPtr host;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (!(servers = virJSONValueNewArray()))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
for (i = 0; i < src->nhosts; i++) {
|
||||||
|
host = src->hosts + i;
|
||||||
|
|
||||||
|
if (!(server = qemuBlockStorageSourceBuildJSONSocketAddress(host, legacy)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (virJSONValueArrayAppend(servers, server) < 0)
|
if (virJSONValueArrayAppend(servers, server) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -450,7 +485,6 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src,
|
|||||||
cleanup:
|
cleanup:
|
||||||
virJSONValueFree(servers);
|
virJSONValueFree(servers);
|
||||||
virJSONValueFree(server);
|
virJSONValueFree(server);
|
||||||
VIR_FREE(port);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user