mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-09 14:35:25 +00:00
qemu: Add a new domain lookup helper and improve the docs
This patch adds a new domain lookup helper qemuDomObjFromDomainDriver that lookups the domain and leaves the driver locked. The driver is returned as the second argument of that function. If the lookup fails the driver is unlocked to help avoid cleanup codepaths. This patch also improves docs for the helpers.
This commit is contained in:
parent
ab8d323319
commit
7fc06b0480
@ -187,11 +187,20 @@ struct qemuAutostartData {
|
|||||||
virConnectPtr conn;
|
virConnectPtr conn;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
/* Looks up the domain object and unlocks the driver. The returned domain
|
* qemuDomObjFromDomainDriver:
|
||||||
* object is locked and the caller is responsible for unlocking it. */
|
* @domain: Domain pointer that has to be looked up
|
||||||
|
* @drv: Pointer to virQEMUDriverPtr to return the driver object
|
||||||
|
*
|
||||||
|
* This function looks up @domain in the domain list and returns the
|
||||||
|
* appropriate virDomainObjPtr. On successful lookup, both driver and domain
|
||||||
|
* object are returned locked.
|
||||||
|
*
|
||||||
|
* Returns the domain object if it's found and the driver. Both are locked.
|
||||||
|
* In case of failure NULL is returned and the driver isn't locked.
|
||||||
|
*/
|
||||||
static virDomainObjPtr
|
static virDomainObjPtr
|
||||||
qemuDomObjFromDomain(virDomainPtr domain)
|
qemuDomObjFromDomainDriver(virDomainPtr domain, virQEMUDriverPtr *drv)
|
||||||
{
|
{
|
||||||
virQEMUDriverPtr driver = domain->conn->privateData;
|
virQEMUDriverPtr driver = domain->conn->privateData;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
@ -199,16 +208,42 @@ qemuDomObjFromDomain(virDomainPtr domain)
|
|||||||
|
|
||||||
qemuDriverLock(driver);
|
qemuDriverLock(driver);
|
||||||
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
|
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
|
||||||
qemuDriverUnlock(driver);
|
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
virUUIDFormat(domain->uuid, uuidstr);
|
virUUIDFormat(domain->uuid, uuidstr);
|
||||||
virReportError(VIR_ERR_NO_DOMAIN,
|
virReportError(VIR_ERR_NO_DOMAIN,
|
||||||
_("no domain with matching uuid '%s'"), uuidstr);
|
_("no domain with matching uuid '%s'"), uuidstr);
|
||||||
|
qemuDriverUnlock(driver);
|
||||||
|
*drv = NULL;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*drv = driver;
|
||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qemuDomObjFromDomain:
|
||||||
|
* @domain: Domain pointer that has to be looked up
|
||||||
|
*
|
||||||
|
* This function looks up @domain and returns the appropriate
|
||||||
|
* virDomainObjPtr. The driver is unlocked after the call.
|
||||||
|
*
|
||||||
|
* Returns the domain object which is locked on success, NULL
|
||||||
|
* otherwise. The driver remains unlocked after the call.
|
||||||
|
*/
|
||||||
|
static virDomainObjPtr
|
||||||
|
qemuDomObjFromDomain(virDomainPtr domain)
|
||||||
|
{
|
||||||
|
virDomainObjPtr vm;
|
||||||
|
virQEMUDriverPtr driver;
|
||||||
|
|
||||||
|
if (!(vm = qemuDomObjFromDomainDriver(domain, &driver)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
qemuDriverUnlock(driver);
|
||||||
|
|
||||||
|
return vm;
|
||||||
|
}
|
||||||
|
|
||||||
/* Looks up the domain object from snapshot and unlocks the driver. The
|
/* Looks up the domain object from snapshot and unlocks the driver. The
|
||||||
* returned domain object is locked and the caller is responsible for
|
* returned domain object is locked and the caller is responsible for
|
||||||
|
Loading…
Reference in New Issue
Block a user