On 08/30/2014 10:02 PM, Eric Blake wrote: > Another layer of overly-multiplexed code that deserves to be > split into obviously separate paths for query vs. modify. > This continues the cleanup started in the previous patch. > > In the process, make some tweaks to simplify the logic when > parsing the JSON reply. There should be no user-visible > semantic changes. >
In addition to the ATTRIBUTE_NONNULL addition, I found a bug that needs
fixing:
> +int
> +qemuMonitorJSONBlockJobInfo(qemuMonitorPtr mon,
> + const char *device,
> + virDomainBlockJobInfoPtr info)
> {
> + virJSONValuePtr cmd = NULL;
> + virJSONValuePtr reply = NULL;
> virJSONValuePtr data;
> int nr_results;
> size_t i;
> + int ret;
>
> - if (!info)
> + cmd = qemuMonitorJSONMakeCommand("query-block-jobs", NULL);
> + if (!cmd)
> return -1;
> + ret = qemuMonitorJSONCommand(mon, cmd, &reply);
> + if (ret < 0)
> + goto cleanup;
If we haven't errored out yet, then ret is now 0...
>
> if ((data = virJSONValueObjectGet(reply, "return")) == NULL) {
> virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> _("reply was missing return data"));
> - return -1;
> + goto cleanup;
...and we have changed the return code from -1 to 0 here. Oops. I'm
squashing this in, before pushing:
diff --git i/src/qemu/qemu_monitor_json.c w/src/qemu/qemu_monitor_json.c
index 68ba084..2b58c78 100644
--- i/src/qemu/qemu_monitor_json.c
+++ w/src/qemu/qemu_monitor_json.c
@@ -3753,13 +3753,12 @@ qemuMonitorJSONBlockJobInfo(qemuMonitorPtr mon,
virJSONValuePtr data;
int nr_results;
size_t i;
- int ret;
+ int ret = -1;
cmd = qemuMonitorJSONMakeCommand("query-block-jobs", NULL);
if (!cmd)
return -1;
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
- if (ret < 0)
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
if ((data = virJSONValueObjectGet(reply, "return")) == NULL) {
@@ -3780,7 +3779,7 @@ qemuMonitorJSONBlockJobInfo(qemuMonitorPtr mon,
goto cleanup;
}
- for (i = 0, ret = 0; i < nr_results && ret == 0; i++) {
+ for (i = ret = 0; i < nr_results && ret == 0; i++) {
virJSONValuePtr entry = virJSONValueArrayGet(data, i);
if (!entry) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
-- libvir-list mailing list [email protected] https://www.redhat.com/mailman/listinfo/libvir-list
