Currently, we are building InetSocketAddress qemu json type
within the qemuMonitorJSONNBDServerStart function. However, other
future functions may profit from the code as well. So it should
be moved into a static function.
---
src/qemu/qemu_monitor_json.c | 53 +++++++++++++++++++++++++++-----------------
1 file changed, 33 insertions(+), 20 deletions(-)
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 2b73884..b87b8b5 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -4734,36 +4734,50 @@ no_memory:
goto cleanup;
}
-int
-qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon,
- const char *host,
- unsigned int port)
+static virJSONValuePtr
+qemuMonitorJSONBuildInetSocketAddress(const char *host,
+ const char *port)
{
- int ret = -1;
- virJSONValuePtr cmd = NULL;
- virJSONValuePtr reply = NULL;
- virJSONValuePtr data = NULL;
virJSONValuePtr addr = NULL;
- char *port_str = NULL;
+ virJSONValuePtr data = NULL;
if (!(data = virJSONValueNewObject()) ||
- !(addr = virJSONValueNewObject()) ||
- (virAsprintf(&port_str, "%u", port) < 0)) {
- virReportOOMError();
- goto cleanup;
- }
+ !(addr = virJSONValueNewObject()))
+ goto error;
/* port is really expected as a string here by qemu */
if (virJSONValueObjectAppendString(data, "host", host) < 0 ||
- virJSONValueObjectAppendString(data, "port", port_str) < 0 ||
+ virJSONValueObjectAppendString(data, "port", port) < 0 ||
virJSONValueObjectAppendString(addr, "type", "inet") < 0
||
- virJSONValueObjectAppend(addr, "data", data) < 0) {
+ virJSONValueObjectAppend(addr, "data", data) < 0)
+ goto error;
+
+ return addr;
+error:
+ virReportOOMError();
+ virJSONValueFree(data);
+ virJSONValueFree(addr);
+ return NULL;
+}
+
+int
+qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon,
+ const char *host,
+ unsigned int port)
+{
+ int ret = -1;
+ virJSONValuePtr cmd = NULL;
+ virJSONValuePtr reply = NULL;
+ virJSONValuePtr addr = NULL;
+ char *port_str = NULL;
+
+ if (virAsprintf(&port_str, "%u", port) < 0) {
virReportOOMError();
- goto cleanup;
+ return ret;
}
- /* From now on, @data is part of @addr */
- data = NULL;
+ if (!(addr = qemuMonitorJSONBuildInetSocketAddress(host, port_str)))
+ return ret;
if (!(cmd = qemuMonitorJSONMakeCommand("nbd-server-start",
"a:addr", addr,
@@ -4786,7 +4800,6 @@ cleanup:
virJSONValueFree(reply);
virJSONValueFree(cmd);
virJSONValueFree(addr);
- virJSONValueFree(data);
return ret;
}
--
1.8.2.1