From 6ddb1f803ea38d8d709b984fa9539e34318a9dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Wed, 7 Oct 2020 14:33:08 +0200 Subject: [PATCH] qemu: agent: split out qemuAgentGetAllInterfaceAddresses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove more logic from qemuAgentGetInterfaces. Signed-off-by: Ján Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 57 ++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 60247e1616..c9c4b034d3 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2201,6 +2201,37 @@ qemuAgentGetInterfaceAddresses(virDomainInterfacePtr **ifaces_ret, } +static int +qemuAgentGetAllInterfaceAddresses(virDomainInterfacePtr **ifaces_ret, + virJSONValuePtr ret_array) +{ + g_autoptr(virHashTable) ifaces_store = NULL; + size_t ifaces_count = 0; + size_t i; + + /* Hash table to handle the interface alias */ + ifaces_store = virHashNew(NULL); + + for (i = 0; i < virJSONValueArraySize(ret_array); i++) { + virJSONValuePtr iface_obj = virJSONValueArrayGet(ret_array, i); + + if (qemuAgentGetInterfaceAddresses(ifaces_ret, &ifaces_count, + ifaces_store, iface_obj) < 0) + goto error; + } + + return ifaces_count; + + error: + if (ifaces_ret) { + for (i = 0; i < ifaces_count; i++) + virDomainInterfaceFree(*ifaces_ret[i]); + } + VIR_FREE(*ifaces_ret); + return -1; +} + + /* * qemuAgentGetInterfaces: * @agent: agent object @@ -2216,16 +2247,9 @@ int qemuAgentGetInterfaces(qemuAgentPtr agent, virDomainInterfacePtr **ifaces) { - size_t i; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virJSONValuePtr ret_array = NULL; - size_t ifaces_count = 0; - virDomainInterfacePtr *ifaces_ret = NULL; - g_autoptr(virHashTable) ifaces_store = NULL; - - /* Hash table to handle the interface alias */ - ifaces_store = virHashNew(NULL); if (!(cmd = qemuAgentMakeCommand("guest-network-get-interfaces", NULL))) return -1; @@ -2239,24 +2263,7 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, return -1; } - for (i = 0; i < virJSONValueArraySize(ret_array); i++) { - virJSONValuePtr iface_obj = virJSONValueArrayGet(ret_array, i); - - if (qemuAgentGetInterfaceAddresses(&ifaces_ret, &ifaces_count, - ifaces_store, iface_obj) < 0) - goto error; - } - - *ifaces = g_steal_pointer(&ifaces_ret); - return ifaces_count; - - error: - if (ifaces_ret) { - for (i = 0; i < ifaces_count; i++) - virDomainInterfaceFree(ifaces_ret[i]); - } - VIR_FREE(ifaces_ret); - return -1; + return qemuAgentGetAllInterfaceAddresses(ifaces, ret_array); }