Rather than have two API's doing different things for different callers, let's make one API that will always return a locked and ref counted object. That way, the callers will always know that they must call virDomainObjEndAPI and not have to decide whether they should call virObjectUnlock instead. This will make things consistent with LookupByName which returns the locked and ref counted object. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/vz/vz_driver.c | 111 ++++++++++++++++++++++++++--------------------------- src/vz/vz_utils.c | 32 +-------------- src/vz/vz_utils.h | 1 - 3 files changed, 56 insertions(+), 88 deletions(-) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 6d02ef274..1118ef92f 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -654,7 +654,7 @@ vzDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) vzDomObjPtr privdom; int ret = -1; - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) goto cleanup; if (virDomainGetInfoEnsureACL(domain->conn, dom->def) < 0) @@ -703,7 +703,7 @@ vzDomainGetOSType(virDomainPtr domain) ignore_value(VIR_STRDUP(ret, virDomainOSTypeToString(dom->def->os.type))); cleanup: - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } @@ -722,7 +722,7 @@ vzDomainIsPersistent(virDomainPtr domain) ret = 1; cleanup: - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } @@ -745,7 +745,7 @@ vzDomainGetState(virDomainPtr domain, ret = 0; cleanup: - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } @@ -771,7 +771,7 @@ vzDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) ret = virDomainDefFormat(def, privconn->driver->caps, flags); cleanup: - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } @@ -791,7 +791,7 @@ vzDomainGetAutostart(virDomainPtr domain, int *autostart) ret = 0; cleanup: - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } @@ -985,7 +985,7 @@ vzDomainGetVcpus(virDomainPtr domain, size_t i; int ret = -1; - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainGetVcpusEnsureACL(domain->conn, dom->def) < 0) @@ -1087,7 +1087,7 @@ vzDomainSuspend(virDomainPtr domain) int ret = -1; bool job = false; - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainSuspendEnsureACL(domain->conn, dom->def) < 0) @@ -1124,7 +1124,7 @@ vzDomainResume(virDomainPtr domain) int ret = -1; bool job = false; - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainResumeEnsureACL(domain->conn, dom->def) < 0) @@ -1163,7 +1163,7 @@ vzDomainCreateWithFlags(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainCreateWithFlagsEnsureACL(domain->conn, dom->def) < 0) @@ -1202,7 +1202,7 @@ vzDomainDestroyFlags(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainDestroyFlagsEnsureACL(domain->conn, dom->def) < 0) @@ -1247,7 +1247,7 @@ vzDomainShutdownFlags(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainShutdownFlagsEnsureACL(domain->conn, dom->def, flags) < 0) @@ -1291,7 +1291,7 @@ vzDomainReboot(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainRebootEnsureACL(domain->conn, dom->def, flags) < 0) @@ -1334,7 +1334,7 @@ static int vzDomainIsActive(virDomainPtr domain) ret = virDomainObjIsActive(dom); cleanup: - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } @@ -1357,7 +1357,7 @@ vzDomainUndefineFlags(virDomainPtr domain, virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE | VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainUndefineFlagsEnsureACL(domain->conn, dom->def) < 0) @@ -1409,7 +1409,7 @@ vzDomainHasManagedSaveImage(virDomainPtr domain, unsigned int flags) ret = 0; cleanup: - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } @@ -1426,7 +1426,7 @@ vzDomainManagedSave(virDomainPtr domain, unsigned int flags) virCheckFlags(VIR_DOMAIN_SAVE_RUNNING | VIR_DOMAIN_SAVE_PAUSED, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainManagedSaveEnsureACL(domain->conn, dom->def) < 0) @@ -1469,7 +1469,7 @@ vzDomainManagedSaveRemove(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainManagedSaveRemoveEnsureACL(domain->conn, dom->def) < 0) @@ -1522,7 +1522,7 @@ static int vzDomainAttachDeviceFlags(virDomainPtr domain, const char *xml, virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (vzCheckConfigUpdateFlags(dom, &flags) < 0) @@ -1577,7 +1577,7 @@ static int vzDomainDetachDeviceFlags(virDomainPtr domain, const char *xml, virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); - dom = vzDomObjFromDomainRef(domain); + dom = vzDomObjFromDomain(domain); if (dom == NULL) return -1; @@ -1634,7 +1634,7 @@ vzDomainSetUserPassword(virDomainPtr domain, bool job = false; virCheckFlags(0, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainSetUserPasswordEnsureACL(domain->conn, dom->def) < 0) @@ -1670,7 +1670,7 @@ static int vzDomainUpdateDeviceFlags(virDomainPtr domain, virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainUpdateDeviceFlagsEnsureACL(domain->conn, dom->def, flags) < 0) @@ -1723,7 +1723,7 @@ vzDomainGetMaxMemory(virDomainPtr domain) ret = virDomainDefGetMemoryTotal(dom->def); cleanup: - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } @@ -1784,7 +1784,7 @@ vzDomainBlockStats(virDomainPtr domain, virDomainObjPtr dom; int ret = -1; - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainBlockStatsEnsureACL(domain->conn, dom->def) < 0) @@ -1851,7 +1851,7 @@ vzDomainBlockStatsFlags(virDomainPtr domain, /* We don't return strings, and thus trivially support this flag. */ flags &= ~VIR_TYPED_PARAM_STRING_OKAY; - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainBlockStatsFlagsEnsureACL(domain->conn, dom->def) < 0) @@ -1880,7 +1880,7 @@ vzDomainInterfaceStats(virDomainPtr domain, vzDomObjPtr privdom; int ret = -1; - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainInterfaceStatsEnsureACL(domain->conn, dom->def) < 0) @@ -1907,7 +1907,7 @@ vzDomainMemoryStats(virDomainPtr domain, int ret = -1; virCheckFlags(0, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainMemoryStatsEnsureACL(domain->conn, dom->def) < 0) @@ -1946,7 +1946,7 @@ vzDomainGetVcpusFlags(virDomainPtr domain, ret = virDomainDefGetVcpus(dom->def); cleanup: - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } @@ -1973,7 +1973,7 @@ static int vzDomainIsUpdated(virDomainPtr domain) ret = 0; cleanup: - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } @@ -2110,7 +2110,7 @@ static int vzDomainSetMemoryFlags(virDomainPtr domain, unsigned long memory, virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (vzCheckConfigUpdateFlags(dom, &flags) < 0) @@ -2142,7 +2142,7 @@ static int vzDomainSetMemory(virDomainPtr domain, unsigned long memory) int ret = -1; bool job = false; - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainSetMemoryEnsureACL(domain->conn, dom->def) < 0) @@ -2217,7 +2217,7 @@ vzDomainSnapshotNum(virDomainPtr domain, unsigned int flags) virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainSnapshotNumEnsureACL(domain->conn, dom->def) < 0) @@ -2248,7 +2248,7 @@ vzDomainSnapshotListNames(virDomainPtr domain, virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainSnapshotListNamesEnsureACL(domain->conn, dom->def) < 0) @@ -2278,7 +2278,7 @@ vzDomainListAllSnapshots(virDomainPtr domain, virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainListAllSnapshotsEnsureACL(domain->conn, dom->def) < 0) @@ -2308,7 +2308,7 @@ vzDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, unsigned int flags) virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL); - if (!(dom = vzDomObjFromDomainRef(snapshot->domain))) + if (!(dom = vzDomObjFromDomain(snapshot->domain))) return NULL; if (virDomainSnapshotGetXMLDescEnsureACL(snapshot->domain->conn, dom->def, flags) < 0) @@ -2345,7 +2345,7 @@ vzDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot, unsigned int flags) virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); - if (!(dom = vzDomObjFromDomainRef(snapshot->domain))) + if (!(dom = vzDomObjFromDomain(snapshot->domain))) return -1; if (virDomainSnapshotNumChildrenEnsureACL(snapshot->domain->conn, dom->def) < 0) @@ -2380,7 +2380,7 @@ vzDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot, virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); - if (!(dom = vzDomObjFromDomainRef(snapshot->domain))) + if (!(dom = vzDomObjFromDomain(snapshot->domain))) return -1; if (virDomainSnapshotListChildrenNamesEnsureACL(snapshot->domain->conn, dom->def) < 0) @@ -2414,7 +2414,7 @@ vzDomainSnapshotListAllChildren(virDomainSnapshotPtr snapshot, virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); - if (!(dom = vzDomObjFromDomainRef(snapshot->domain))) + if (!(dom = vzDomObjFromDomain(snapshot->domain))) return -1; if (virDomainSnapshotListAllChildrenEnsureACL(snapshot->domain->conn, dom->def) < 0) @@ -2447,7 +2447,7 @@ vzDomainSnapshotLookupByName(virDomainPtr domain, virCheckFlags(0, NULL); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return NULL; if (virDomainSnapshotLookupByNameEnsureACL(domain->conn, dom->def) < 0) @@ -2477,7 +2477,7 @@ vzDomainHasCurrentSnapshot(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainHasCurrentSnapshotEnsureACL(domain->conn, dom->def) < 0) @@ -2505,7 +2505,7 @@ vzDomainSnapshotGetParent(virDomainSnapshotPtr snapshot, unsigned int flags) virCheckFlags(0, NULL); - if (!(dom = vzDomObjFromDomainRef(snapshot->domain))) + if (!(dom = vzDomObjFromDomain(snapshot->domain))) return NULL; if (virDomainSnapshotGetParentEnsureACL(snapshot->domain->conn, dom->def) < 0) @@ -2543,7 +2543,7 @@ vzDomainSnapshotCurrent(virDomainPtr domain, unsigned int flags) virCheckFlags(0, NULL); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return NULL; if (virDomainSnapshotCurrentEnsureACL(domain->conn, dom->def) < 0) @@ -2577,7 +2577,7 @@ vzDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot, unsigned int flags) virCheckFlags(0, -1); - if (!(dom = vzDomObjFromDomainRef(snapshot->domain))) + if (!(dom = vzDomObjFromDomain(snapshot->domain))) return -1; if (virDomainSnapshotIsCurrentEnsureACL(snapshot->domain->conn, dom->def) < 0) @@ -2607,7 +2607,7 @@ vzDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot, virCheckFlags(0, -1); - if (!(dom = vzDomObjFromDomainRef(snapshot->domain))) + if (!(dom = vzDomObjFromDomain(snapshot->domain))) return -1; if (virDomainSnapshotHasMetadataEnsureACL(snapshot->domain->conn, dom->def) < 0) @@ -2645,7 +2645,7 @@ vzDomainSnapshotCreateXML(virDomainPtr domain, virCheckFlags(0, NULL); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return NULL; if (virDomainSnapshotCreateXMLEnsureACL(domain->conn, dom->def, flags) < 0) @@ -2708,7 +2708,7 @@ vzDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags) virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN, -1); - if (!(dom = vzDomObjFromDomainRef(snapshot->domain))) + if (!(dom = vzDomObjFromDomain(snapshot->domain))) return -1; if (virDomainSnapshotDeleteEnsureACL(snapshot->domain->conn, dom->def) < 0) @@ -2732,7 +2732,7 @@ vzDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags) virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED, -1); - if (!(dom = vzDomObjFromDomainRef(snapshot->domain))) + if (!(dom = vzDomObjFromDomain(snapshot->domain))) return -1; if (virDomainRevertToSnapshotEnsureACL(snapshot->domain->conn, dom->def) < 0) @@ -2978,8 +2978,7 @@ vzDomainMigrateBegin3Params(virDomainPtr domain, cleanup: - if (dom) - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return xml; } @@ -3309,7 +3308,7 @@ vzDomainMigratePerform3Params(virDomainPtr domain, if (virTypedParamsValidate(params, nparams, VZ_MIGRATION_PARAMETERS) < 0) return -1; - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainMigratePerform3ParamsEnsureACL(domain->conn, dom->def) < 0) @@ -3432,7 +3431,7 @@ vzDomainGetJobInfo(virDomainPtr domain, virDomainJobInfoPtr info) ret = vzDomainGetJobInfoImpl(dom, info); cleanup: - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } @@ -3504,7 +3503,7 @@ vzDomainGetJobStats(virDomainPtr domain, ret = vzDomainJobInfoToParams(&info, type, params, nparams); cleanup: - virObjectUnlock(dom); + virDomainObjEndAPI(&dom); return ret; } @@ -3883,7 +3882,7 @@ vzDomainAbortJob(virDomainPtr domain) virDomainObjPtr dom; int ret = -1; - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainAbortJobEnsureACL(domain->conn, dom->def) < 0) @@ -3906,7 +3905,7 @@ vzDomainReset(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) return -1; if (virDomainResetEnsureACL(domain->conn, dom->def) < 0) @@ -3938,7 +3937,7 @@ static int vzDomainSetVcpusFlags(virDomainPtr domain, unsigned int nvcpus, virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) goto cleanup; if (vzCheckConfigUpdateFlags(dom, &flags) < 0) @@ -3981,7 +3980,7 @@ vzDomainBlockResize(virDomainPtr domain, virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES, -1); - if (!(dom = vzDomObjFromDomainRef(domain))) + if (!(dom = vzDomObjFromDomain(domain))) goto cleanup; if (virDomainBlockResizeEnsureACL(domain->conn, dom->def) < 0) diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c index 6fb27169a..8f4e3e347 100644 --- a/src/vz/vz_utils.c +++ b/src/vz/vz_utils.c @@ -63,43 +63,13 @@ static virDomainControllerType vz7ControllerTypes[] = {VIR_DOMAIN_CONTROLLER_TYP * @domain: Domain pointer that has to be looked up * * This function looks up @domain and returns the appropriate virDomainObjPtr - * that has to be unlocked by virObjectUnlock(). - * - * Returns the domain object without incremented reference counter which is locked - * on success, NULL otherwise. - */ -virDomainObjPtr -vzDomObjFromDomain(virDomainPtr domain) -{ - virDomainObjPtr vm; - vzConnPtr privconn = domain->conn->privateData; - char uuidstr[VIR_UUID_STRING_BUFLEN]; - vzDriverPtr driver = privconn->driver; - - vm = virDomainObjListFindByUUID(driver->domains, domain->uuid); - if (!vm) { - virUUIDFormat(domain->uuid, uuidstr); - virReportError(VIR_ERR_NO_DOMAIN, - _("no domain with matching uuid '%s' (%s)"), - uuidstr, domain->name); - return NULL; - } - - return vm; -} - -/** - * vzDomObjFromDomainRef: - * @domain: Domain pointer that has to be looked up - * - * This function looks up @domain and returns the appropriate virDomainObjPtr * that has to be released by calling virDomainObjEndAPI(). * * Returns the domain object with incremented reference counter which is locked * on success, NULL otherwise. */ virDomainObjPtr -vzDomObjFromDomainRef(virDomainPtr domain) +vzDomObjFromDomain(virDomainPtr domain) { virDomainObjPtr vm; vzConnPtr privconn = domain->conn->privateData; diff --git a/src/vz/vz_utils.h b/src/vz/vz_utils.h index f9e9dee42..40a1ce23d 100644 --- a/src/vz/vz_utils.h +++ b/src/vz/vz_utils.h @@ -120,7 +120,6 @@ void* vzDomObjAlloc(void *opaque); void vzDomObjFree(void *p); virDomainObjPtr vzDomObjFromDomain(virDomainPtr domain); -virDomainObjPtr vzDomObjFromDomainRef(virDomainPtr domain); char * vzGetOutput(const char *binary, ...) ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL; -- 2.13.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list