[libvirt] [PATCH 4/4] qemu: monitor: Use VIR_AUTOPTR in qemuMonitorJSON(Drive/Blockdev)Mirror
Ján Tomko
jtomko at redhat.com
Tue May 21 10:53:32 UTC 2019
On Mon, May 20, 2019 at 04:16:33PM +0200, Peter Krempa wrote:
>Signed-off-by: Peter Krempa <pkrempa at redhat.com>
>---
> src/qemu/qemu_monitor_json.c | 71 ++++++++++++++----------------------
> 1 file changed, 28 insertions(+), 43 deletions(-)
>
>diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
>index 4152d44331..4f9a0cb960 100644
>--- a/src/qemu/qemu_monitor_json.c
>+++ b/src/qemu/qemu_monitor_json.c
>@@ -4280,34 +4280,25 @@ qemuMonitorJSONDriveMirror(qemuMonitorPtr mon,
> bool shallow,
> bool reuse)
> {
>- int ret = -1;
>- virJSONValuePtr cmd;
>- virJSONValuePtr reply = NULL;
>+ VIR_AUTOPTR(virJSONValue) cmd = NULL;
>+ VIR_AUTOPTR(virJSONValue) reply = NULL;
>
>- cmd = qemuMonitorJSONMakeCommand("drive-mirror",
>- "s:device", device,
>- "s:target", file,
>- "Y:speed", speed,
>- "z:granularity", granularity,
>- "P:buf-size", buf_size,
>- "s:sync", shallow ? "top" : "full",
>- "s:mode", reuse ? "existing" : "absolute-paths",
>- "S:format", format,
>- NULL);
>- if (!cmd)
>+ if (!(cmd = qemuMonitorJSONMakeCommand("drive-mirror",
>+ "s:device", device,
>+ "s:target", file,
>+ "Y:speed", speed,
>+ "z:granularity", granularity,
>+ "P:buf-size", buf_size,
>+ "s:sync", shallow ? "top" : "full",
>+ "s:mode", reuse ? "existing" : "absolute-paths",
>+ "S:format", format,
>+ NULL)))
> return -1;
>
Merging the assignment and the condition is not necessary for using AUTOPTR.
> if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
>- goto cleanup;
>-
>- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
>- goto cleanup;
>+ return -1;
>
>- ret = 0;
>- cleanup:
>- virJSONValueFree(cmd);
>- virJSONValueFree(reply);
>- return ret;
>+ return qemuMonitorJSONCheckError(cmd, reply);
> }
>
>
>@@ -4321,30 +4312,24 @@ qemuMonitorJSONBlockdevMirror(qemuMonitorPtr mon,
> unsigned long long buf_size,
> bool shallow)
> {
>- int ret = -1;
>- virJSONValuePtr cmd;
>- virJSONValuePtr reply = NULL;
>+ VIR_AUTOPTR(virJSONValue) cmd = NULL;
>+ VIR_AUTOPTR(virJSONValue) reply = NULL;
>
>- cmd = qemuMonitorJSONMakeCommand("blockdev-mirror",
>- "S:job-id", jobname,
>- "s:device", device,
>- "s:target", target,
>- "Y:speed", speed,
>- "z:granularity", granularity,
>- "P:buf-size", buf_size,
>- "s:sync", shallow ? "top" : "full",
>- NULL);
>- if (!cmd)
>+ if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-mirror",
>+ "S:job-id", jobname,
>+ "s:device", device,
>+ "s:target", target,
>+ "Y:speed", speed,
>+ "z:granularity", granularity,
>+ "P:buf-size", buf_size,
>+ "s:sync", shallow ? "top" : "full",
>+ NULL)))
> return -1;
Same here.
>
Reviewed-by: Ján Tomko <jtomko at redhat.com>
Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190521/a88be7ce/attachment-0001.sig>
More information about the libvir-list
mailing list