Return failure right away when the domain object can't be looked up
instead of jumping to cleanup. This allows to remove the condition
before unlocking the domain object.
---
src/qemu/qemu_driver.c | 65 ++++++++++++++++++++------------------------------
1 file changed, 26 insertions(+), 39 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9b2d355..838200d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13602,7 +13602,7 @@ qemuDomainSnapshotListNames(virDomainPtr domain,
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
if (!(vm = qemuDomObjFromDomain(domain)))
- goto cleanup;
+ return -1;
if (virDomainSnapshotListNamesEnsureACL(domain->conn, vm->def) < 0)
goto cleanup;
@@ -13611,8 +13611,7 @@ qemuDomainSnapshotListNames(virDomainPtr domain,
flags);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
return n;
}
@@ -13627,7 +13626,7 @@ qemuDomainSnapshotNum(virDomainPtr domain,
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
if (!(vm = qemuDomObjFromDomain(domain)))
- goto cleanup;
+ return -1;
if (virDomainSnapshotNumEnsureACL(domain->conn, vm->def) < 0)
goto cleanup;
@@ -13635,8 +13634,7 @@ qemuDomainSnapshotNum(virDomainPtr domain,
n = virDomainSnapshotObjListNum(vm->snapshots, NULL, flags);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
return n;
}
@@ -13652,7 +13650,7 @@ qemuDomainListAllSnapshots(virDomainPtr domain,
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
if (!(vm = qemuDomObjFromDomain(domain)))
- goto cleanup;
+ return -1;
if (virDomainListAllSnapshotsEnsureACL(domain->conn, vm->def) < 0)
goto cleanup;
@@ -13660,8 +13658,7 @@ qemuDomainListAllSnapshots(virDomainPtr domain,
n = virDomainListSnapshots(vm->snapshots, NULL, domain, snaps, flags);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
return n;
}
@@ -13679,7 +13676,7 @@ qemuDomainSnapshotListChildrenNames(virDomainSnapshotPtr
snapshot,
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
- goto cleanup;
+ return -1;
if (virDomainSnapshotListChildrenNamesEnsureACL(snapshot->domain->conn,
vm->def) < 0)
goto cleanup;
@@ -13691,8 +13688,7 @@ qemuDomainSnapshotListChildrenNames(virDomainSnapshotPtr
snapshot,
flags);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
return n;
}
@@ -13708,7 +13704,7 @@ qemuDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot,
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
- goto cleanup;
+ return -1;
if (virDomainSnapshotNumChildrenEnsureACL(snapshot->domain->conn, vm->def)
< 0)
goto cleanup;
@@ -13719,8 +13715,7 @@ qemuDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot,
n = virDomainSnapshotObjListNum(vm->snapshots, snap, flags);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
return n;
}
@@ -13737,7 +13732,7 @@ qemuDomainSnapshotListAllChildren(virDomainSnapshotPtr snapshot,
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
- goto cleanup;
+ return -1;
if (virDomainSnapshotListAllChildrenEnsureACL(snapshot->domain->conn,
vm->def) < 0)
goto cleanup;
@@ -13749,8 +13744,7 @@ qemuDomainSnapshotListAllChildren(virDomainSnapshotPtr snapshot,
flags);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
return n;
}
@@ -13766,7 +13760,7 @@ qemuDomainSnapshotLookupByName(virDomainPtr domain,
virCheckFlags(0, NULL);
if (!(vm = qemuDomObjFromDomain(domain)))
- goto cleanup;
+ return NULL;
if (virDomainSnapshotLookupByNameEnsureACL(domain->conn, vm->def) < 0)
goto cleanup;
@@ -13777,8 +13771,7 @@ qemuDomainSnapshotLookupByName(virDomainPtr domain,
snapshot = virGetDomainSnapshot(domain, snap->def->name);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
return snapshot;
}
@@ -13792,7 +13785,7 @@ qemuDomainHasCurrentSnapshot(virDomainPtr domain,
virCheckFlags(0, -1);
if (!(vm = qemuDomObjFromDomain(domain)))
- goto cleanup;
+ return -1;
if (virDomainHasCurrentSnapshotEnsureACL(domain->conn, vm->def) < 0)
goto cleanup;
@@ -13800,8 +13793,7 @@ qemuDomainHasCurrentSnapshot(virDomainPtr domain,
ret = (vm->current_snapshot != NULL);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
return ret;
}
@@ -13816,7 +13808,7 @@ qemuDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
virCheckFlags(0, NULL);
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
- goto cleanup;
+ return NULL;
if (virDomainSnapshotGetParentEnsureACL(snapshot->domain->conn, vm->def)
< 0)
goto cleanup;
@@ -13834,8 +13826,7 @@ qemuDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
parent = virGetDomainSnapshot(snapshot->domain, snap->def->parent);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
return parent;
}
@@ -13849,7 +13840,7 @@ qemuDomainSnapshotCurrent(virDomainPtr domain,
virCheckFlags(0, NULL);
if (!(vm = qemuDomObjFromDomain(domain)))
- goto cleanup;
+ return NULL;
if (virDomainSnapshotCurrentEnsureACL(domain->conn, vm->def) < 0)
goto cleanup;
@@ -13863,8 +13854,7 @@ qemuDomainSnapshotCurrent(virDomainPtr domain,
snapshot = virGetDomainSnapshot(domain, vm->current_snapshot->def->name);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
return snapshot;
}
@@ -13880,7 +13870,7 @@ qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL);
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
- goto cleanup;
+ return NULL;
if (virDomainSnapshotGetXMLDescEnsureACL(snapshot->domain->conn, vm->def)
< 0)
goto cleanup;
@@ -13893,8 +13883,7 @@ qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
xml = virDomainSnapshotDefFormat(uuidstr, snap->def, flags, 0);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
return xml;
}
@@ -13909,7 +13898,7 @@ qemuDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
virCheckFlags(0, -1);
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
- goto cleanup;
+ return -1;
if (virDomainSnapshotIsCurrentEnsureACL(snapshot->domain->conn, vm->def)
< 0)
goto cleanup;
@@ -13921,8 +13910,7 @@ qemuDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
STREQ(snapshot->name, vm->current_snapshot->def->name));
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
return ret;
}
@@ -13938,7 +13926,7 @@ qemuDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
virCheckFlags(0, -1);
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
- goto cleanup;
+ return -1;
if (virDomainSnapshotHasMetadataEnsureACL(snapshot->domain->conn, vm->def)
< 0)
goto cleanup;
@@ -13952,8 +13940,7 @@ qemuDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
ret = 1;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
return ret;
}
--
2.0.2