|
|
9119d9 |
From 921e000d67265b2931772a89ee56b8309ac7b9e2 Mon Sep 17 00:00:00 2001
|
|
|
9119d9 |
Message-Id: <921e000d67265b2931772a89ee56b8309ac7b9e2@dist-git>
|
|
|
9119d9 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
9119d9 |
Date: Mon, 8 Sep 2014 13:24:20 +0200
|
|
|
9119d9 |
Subject: [PATCH] qemu: snapshot: Simplify error paths
|
|
|
9119d9 |
|
|
|
9119d9 |
https://bugzilla.redhat.com/show_bug.cgi?id=1134154
|
|
|
9119d9 |
|
|
|
9119d9 |
Return failure right away when the domain object can't be looked up
|
|
|
9119d9 |
instead of jumping to cleanup. This allows to remove the condition
|
|
|
9119d9 |
before unlocking the domain object.
|
|
|
9119d9 |
|
|
|
9119d9 |
(cherry picked from commit 2990db96b61d60a487152f9382881a2f56f4fca8)
|
|
|
9119d9 |
|
|
|
9119d9 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
9119d9 |
---
|
|
|
9119d9 |
src/qemu/qemu_driver.c | 65 ++++++++++++++++++++------------------------------
|
|
|
9119d9 |
1 file changed, 26 insertions(+), 39 deletions(-)
|
|
|
9119d9 |
|
|
|
9119d9 |
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
|
|
|
9119d9 |
index d02c76d..53baced 100644
|
|
|
9119d9 |
--- a/src/qemu/qemu_driver.c
|
|
|
9119d9 |
+++ b/src/qemu/qemu_driver.c
|
|
|
9119d9 |
@@ -13615,7 +13615,7 @@ qemuDomainSnapshotListNames(virDomainPtr domain,
|
|
|
9119d9 |
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(vm = qemuDomObjFromDomain(domain)))
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainSnapshotListNamesEnsureACL(domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -13624,8 +13624,7 @@ qemuDomainSnapshotListNames(virDomainPtr domain,
|
|
|
9119d9 |
flags);
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
- if (vm)
|
|
|
9119d9 |
- virObjectUnlock(vm);
|
|
|
9119d9 |
+ virObjectUnlock(vm);
|
|
|
9119d9 |
return n;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -13641,7 +13640,7 @@ qemuDomainSnapshotNum(virDomainPtr domain,
|
|
|
9119d9 |
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(vm = qemuDomObjFromDomain(domain)))
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainSnapshotNumEnsureACL(domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -13649,8 +13648,7 @@ qemuDomainSnapshotNum(virDomainPtr domain,
|
|
|
9119d9 |
n = virDomainSnapshotObjListNum(vm->snapshots, NULL, flags);
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
- if (vm)
|
|
|
9119d9 |
- virObjectUnlock(vm);
|
|
|
9119d9 |
+ virObjectUnlock(vm);
|
|
|
9119d9 |
return n;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -13667,7 +13665,7 @@ qemuDomainListAllSnapshots(virDomainPtr domain,
|
|
|
9119d9 |
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(vm = qemuDomObjFromDomain(domain)))
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainListAllSnapshotsEnsureACL(domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -13675,8 +13673,7 @@ qemuDomainListAllSnapshots(virDomainPtr domain,
|
|
|
9119d9 |
n = virDomainListSnapshots(vm->snapshots, NULL, domain, snaps, flags);
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
- if (vm)
|
|
|
9119d9 |
- virObjectUnlock(vm);
|
|
|
9119d9 |
+ virObjectUnlock(vm);
|
|
|
9119d9 |
return n;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -13695,7 +13692,7 @@ qemuDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainSnapshotListChildrenNamesEnsureACL(snapshot->domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -13707,8 +13704,7 @@ qemuDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
flags);
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
- if (vm)
|
|
|
9119d9 |
- virObjectUnlock(vm);
|
|
|
9119d9 |
+ virObjectUnlock(vm);
|
|
|
9119d9 |
return n;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -13725,7 +13721,7 @@ qemuDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainSnapshotNumChildrenEnsureACL(snapshot->domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -13736,8 +13732,7 @@ qemuDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
n = virDomainSnapshotObjListNum(vm->snapshots, snap, flags);
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
- if (vm)
|
|
|
9119d9 |
- virObjectUnlock(vm);
|
|
|
9119d9 |
+ virObjectUnlock(vm);
|
|
|
9119d9 |
return n;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -13755,7 +13750,7 @@ qemuDomainSnapshotListAllChildren(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainSnapshotListAllChildrenEnsureACL(snapshot->domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -13767,8 +13762,7 @@ qemuDomainSnapshotListAllChildren(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
flags);
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
- if (vm)
|
|
|
9119d9 |
- virObjectUnlock(vm);
|
|
|
9119d9 |
+ virObjectUnlock(vm);
|
|
|
9119d9 |
return n;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -13785,7 +13779,7 @@ qemuDomainSnapshotLookupByName(virDomainPtr domain,
|
|
|
9119d9 |
virCheckFlags(0, NULL);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(vm = qemuDomObjFromDomain(domain)))
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ return NULL;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainSnapshotLookupByNameEnsureACL(domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -13796,8 +13790,7 @@ qemuDomainSnapshotLookupByName(virDomainPtr domain,
|
|
|
9119d9 |
snapshot = virGetDomainSnapshot(domain, snap->def->name);
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
- if (vm)
|
|
|
9119d9 |
- virObjectUnlock(vm);
|
|
|
9119d9 |
+ virObjectUnlock(vm);
|
|
|
9119d9 |
return snapshot;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -13812,7 +13805,7 @@ qemuDomainHasCurrentSnapshot(virDomainPtr domain,
|
|
|
9119d9 |
virCheckFlags(0, -1);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(vm = qemuDomObjFromDomain(domain)))
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainHasCurrentSnapshotEnsureACL(domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -13820,8 +13813,7 @@ qemuDomainHasCurrentSnapshot(virDomainPtr domain,
|
|
|
9119d9 |
ret = (vm->current_snapshot != NULL);
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
- if (vm)
|
|
|
9119d9 |
- virObjectUnlock(vm);
|
|
|
9119d9 |
+ virObjectUnlock(vm);
|
|
|
9119d9 |
return ret;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -13837,7 +13829,7 @@ qemuDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
virCheckFlags(0, NULL);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ return NULL;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainSnapshotGetParentEnsureACL(snapshot->domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -13855,8 +13847,7 @@ qemuDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
parent = virGetDomainSnapshot(snapshot->domain, snap->def->parent);
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
- if (vm)
|
|
|
9119d9 |
- virObjectUnlock(vm);
|
|
|
9119d9 |
+ virObjectUnlock(vm);
|
|
|
9119d9 |
return parent;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -13871,7 +13862,7 @@ qemuDomainSnapshotCurrent(virDomainPtr domain,
|
|
|
9119d9 |
virCheckFlags(0, NULL);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(vm = qemuDomObjFromDomain(domain)))
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ return NULL;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainSnapshotCurrentEnsureACL(domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -13885,8 +13876,7 @@ qemuDomainSnapshotCurrent(virDomainPtr domain,
|
|
|
9119d9 |
snapshot = virGetDomainSnapshot(domain, vm->current_snapshot->def->name);
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
- if (vm)
|
|
|
9119d9 |
- virObjectUnlock(vm);
|
|
|
9119d9 |
+ virObjectUnlock(vm);
|
|
|
9119d9 |
return snapshot;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -13903,7 +13893,7 @@ qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ return NULL;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainSnapshotGetXMLDescEnsureACL(snapshot->domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -13916,8 +13906,7 @@ qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
xml = virDomainSnapshotDefFormat(uuidstr, snap->def, flags, 0);
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
- if (vm)
|
|
|
9119d9 |
- virObjectUnlock(vm);
|
|
|
9119d9 |
+ virObjectUnlock(vm);
|
|
|
9119d9 |
return xml;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -13933,7 +13922,7 @@ qemuDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
virCheckFlags(0, -1);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainSnapshotIsCurrentEnsureACL(snapshot->domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -13945,8 +13934,7 @@ qemuDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
STREQ(snapshot->name, vm->current_snapshot->def->name));
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
- if (vm)
|
|
|
9119d9 |
- virObjectUnlock(vm);
|
|
|
9119d9 |
+ virObjectUnlock(vm);
|
|
|
9119d9 |
return ret;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -13962,7 +13950,7 @@ qemuDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
virCheckFlags(0, -1);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(vm = qemuDomObjFromSnapshot(snapshot)))
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ return -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainSnapshotHasMetadataEnsureACL(snapshot->domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -13976,8 +13964,7 @@ qemuDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
ret = 1;
|
|
|
9119d9 |
|
|
|
9119d9 |
cleanup:
|
|
|
9119d9 |
- if (vm)
|
|
|
9119d9 |
- virObjectUnlock(vm);
|
|
|
9119d9 |
+ virObjectUnlock(vm);
|
|
|
9119d9 |
return ret;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
--
|
|
|
9119d9 |
2.1.0
|
|
|
9119d9 |
|