[libvirt] [PATCH v2.1 03/11] qemu: Introduce nbd-server-start command
Jiri Denemark
jdenemar at redhat.com
Thu Jan 17 23:13:15 UTC 2013
On Fri, Jan 11, 2013 at 17:52:15 +0100, Michal Privoznik wrote:
> This will be used with new migration scheme.
> This patch creates basically just monitor stub
> functions. Wiring them into something useful
> is done in later patches.
> ---
> src/qemu/qemu_monitor.c | 22 ++++++++++++++++++++
> src/qemu/qemu_monitor.h | 3 +++
> src/qemu/qemu_monitor_json.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
> src/qemu/qemu_monitor_json.h | 3 +++
> 4 files changed, 77 insertions(+)
>
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index cb5a3e2..c38e3f9 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -3330,3 +3330,25 @@ char *qemuMonitorGetTargetArch(qemuMonitorPtr mon)
>
> return qemuMonitorJSONGetTargetArch(mon);
> }
> +
> +int qemuMonitorNBDServerStart(qemuMonitorPtr mon,
> + const char *host,
> + unsigned int port)
> +{
> + VIR_DEBUG("mon=%p host=%s port=%u",
> + mon, host, port);
> +
> + if (!mon) {
> + virReportError(VIR_ERR_INVALID_ARG, "%s",
> + _("monitor must not be NULL"));
> + return -1;
> + }
> +
> + if (!mon->json) {
> + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
VIR_ERR_OPERATION_UNSUPPORTED is the right error code used elsewhere in
qemu_monitor.c.
> + _("JSON monitor is required"));
> + return -1;
> + }
> +
> + return qemuMonitorJSONNBDServerStart(mon, host, port);
> +}
...
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index de5f115..d5285bc 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -4280,3 +4280,52 @@ cleanup:
> virJSONValueFree(reply);
> return ret;
> }
> +
> +int
> +qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon,
> + const char *host,
> + unsigned int port)
> +{
> + int ret = -1;
> + virJSONValuePtr cmd = NULL;
> + virJSONValuePtr reply = NULL;
> + virJSONValuePtr data = NULL;
> + virJSONValuePtr addr = NULL;
> + char *port_str = NULL;
> +
> + if (!(data = virJSONValueNewObject()) ||
> + !(addr = virJSONValueNewObject()) ||
> + virAsprintf(&port_str, "%d", port) < 0) {
> + virReportOOMError();
> + goto cleanup;
> + }
> +
> + if (virJSONValueObjectAppendString(data, "host", host) < 0 ||
> + virJSONValueObjectAppendString(data, "port", port_str) < 0 ||
Hm, why not virJSONValueObjectAppendNumberInt rather than virAsprintf
followed by virJSONValueObjectAppendString?
> + virJSONValueObjectAppendString(addr, "type", "inet") < 0 ||
> + virJSONValueObjectAppend(addr, "data", data) < 0) {
> + virReportOOMError();
> + goto cleanup;
> + }
> +
> + if (!(cmd = qemuMonitorJSONMakeCommand("nbd-server-start",
> + "a:addr", addr,
> + NULL)))
> + goto cleanup;
> +
> + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
> + goto cleanup;
> +
> + if (qemuMonitorJSONCheckError(cmd, reply) < 0)
> + goto cleanup;
> +
> + ret = 0;
> +
> +cleanup:
> + VIR_FREE(port_str);
> + virJSONValueFree(reply);
> + virJSONValueFree(cmd);
> + virJSONValueFree(addr);
> + virJSONValueFree(data);
AFAIK virJSONValueFree is recursive and freeing addr and data once they
are already assigned to cmd would free the same memory twice. Or am I
missing something?
> + return ret;
> +}
...
Jirka
More information about the libvir-list
mailing list