Introduce 'rc' for collecting state from monitor commands so that we can initialize 'ret' to -1. This also fixes few cases which could return 0 from the fucntion despite an error condition. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_driver.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 220a5846d8..17270d5f83 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -15239,7 +15239,8 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, qemuDomainObjPrivatePtr priv = vm->privateData; VIR_AUTOPTR(virJSONValue) actions = NULL; bool do_transaction = false; - int ret = 0; + int rc; + int ret = -1; size_t i; bool reuse = (flags & VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT) != 0; qemuDomainSnapshotDiskDataPtr diskdata = NULL; @@ -15263,11 +15264,9 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, * VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL with a valid file name and * qcow2 format. */ for (i = 0; i < ndiskdata; i++) { - ret = qemuDomainSnapshotCreateSingleDiskActive(driver, vm, - &diskdata[i], - actions, reuse); - - if (ret < 0) + if (qemuDomainSnapshotCreateSingleDiskActive(driver, vm, + &diskdata[i], + actions, reuse) < 0) goto error; do_transaction = true; @@ -15277,24 +15276,26 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) goto cleanup; - ret = qemuMonitorTransaction(priv->mon, &actions); + rc = qemuMonitorTransaction(priv->mon, &actions); if (qemuDomainObjExitMonitor(driver, vm) < 0) - ret = -1; + rc = -1; for (i = 0; i < ndiskdata; i++) { qemuDomainSnapshotDiskDataPtr dd = &diskdata[i]; - virDomainAuditDisk(vm, dd->disk->src, dd->src, "snapshot", ret >= 0); + virDomainAuditDisk(vm, dd->disk->src, dd->src, "snapshot", rc >= 0); - if (ret == 0) + if (rc == 0) qemuDomainSnapshotUpdateDiskSources(dd); } - if (ret < 0) + if (rc < 0) goto error; } + ret = 0; + error: if (ret < 0) { virErrorPreserveLast(&orig_err); -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list