提交 68a68619 编写于 作者: J John Ferlan

vmware: Create accessors to virDomainObjListFindByUUID

Rather than repeat code throughout, create and use a couple of
accessors in order to lookup by UUID.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
Reviewed-by: NPavel Hrdina <phrdina@redhat.com>
上级 950ca9e7
...@@ -59,6 +59,39 @@ vmwareDriverUnlock(struct vmware_driver *driver) ...@@ -59,6 +59,39 @@ vmwareDriverUnlock(struct vmware_driver *driver)
virMutexUnlock(&driver->lock); virMutexUnlock(&driver->lock);
} }
static virDomainObjPtr
vmwareDomObjFromDomainLocked(struct vmware_driver *driver,
const unsigned char *uuid)
{
virDomainObjPtr vm;
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (!(vm = virDomainObjListFindByUUID(driver->domains, uuid))) {
virUUIDFormat(uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
return NULL;
}
return vm;
}
static virDomainObjPtr
vmwareDomObjFromDomain(struct vmware_driver *driver,
const unsigned char *uuid)
{
virDomainObjPtr vm;
vmwareDriverLock(driver);
vm = vmwareDomObjFromDomainLocked(driver, uuid);
vmwareDriverUnlock(driver);
return vm;
}
static void * static void *
vmwareDataAllocFunc(void *opaque ATTRIBUTE_UNUSED) vmwareDataAllocFunc(void *opaque ATTRIBUTE_UNUSED)
{ {
...@@ -454,13 +487,8 @@ vmwareDomainShutdownFlags(virDomainPtr dom, ...@@ -454,13 +487,8 @@ vmwareDomainShutdownFlags(virDomainPtr dom,
vmwareDriverLock(driver); vmwareDriverLock(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (!(vm = vmwareDomObjFromDomainLocked(driver, dom->uuid)))
if (!vm) {
virReportError(VIR_ERR_NO_DOMAIN, "%s",
_("no domain with matching uuid"));
goto cleanup; goto cleanup;
}
if (vmwareUpdateVMStatus(driver, vm) < 0) if (vmwareUpdateVMStatus(driver, vm) < 0)
goto cleanup; goto cleanup;
...@@ -525,15 +553,8 @@ vmwareDomainSuspend(virDomainPtr dom) ...@@ -525,15 +553,8 @@ vmwareDomainSuspend(virDomainPtr dom)
return ret; return ret;
} }
vmwareDriverLock(driver); if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); return -1;
vmwareDriverUnlock(driver);
if (!vm) {
virReportError(VIR_ERR_NO_DOMAIN, "%s",
_("no domain with matching uuid"));
goto cleanup;
}
vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type)); vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type));
vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath); vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath);
...@@ -574,15 +595,8 @@ vmwareDomainResume(virDomainPtr dom) ...@@ -574,15 +595,8 @@ vmwareDomainResume(virDomainPtr dom)
return ret; return ret;
} }
vmwareDriverLock(driver); if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); return -1;
vmwareDriverUnlock(driver);
if (!vm) {
virReportError(VIR_ERR_NO_DOMAIN, "%s",
_("no domain with matching uuid"));
goto cleanup;
}
vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type)); vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type));
vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath); vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath);
...@@ -618,15 +632,8 @@ vmwareDomainReboot(virDomainPtr dom, unsigned int flags) ...@@ -618,15 +632,8 @@ vmwareDomainReboot(virDomainPtr dom, unsigned int flags)
virCheckFlags(0, -1); virCheckFlags(0, -1);
vmwareDriverLock(driver); if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); return -1;
vmwareDriverUnlock(driver);
if (!vm) {
virReportError(VIR_ERR_NO_DOMAIN, "%s",
_("no domain with matching uuid"));
goto cleanup;
}
vmxPath = ((vmwareDomainPtr) vm->privateData)->vmxPath; vmxPath = ((vmwareDomainPtr) vm->privateData)->vmxPath;
vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type)); vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type));
...@@ -744,14 +751,8 @@ vmwareDomainCreateWithFlags(virDomainPtr dom, ...@@ -744,14 +751,8 @@ vmwareDomainCreateWithFlags(virDomainPtr dom,
virCheckFlags(0, -1); virCheckFlags(0, -1);
vmwareDriverLock(driver); vmwareDriverLock(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (!(vm = vmwareDomObjFromDomainLocked(driver, dom->uuid)))
if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(dom->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
if (vmwareUpdateVMStatus(driver, vm) < 0) if (vmwareUpdateVMStatus(driver, vm) < 0)
goto cleanup; goto cleanup;
...@@ -788,16 +789,8 @@ vmwareDomainUndefineFlags(virDomainPtr dom, ...@@ -788,16 +789,8 @@ vmwareDomainUndefineFlags(virDomainPtr dom,
virCheckFlags(0, -1); virCheckFlags(0, -1);
vmwareDriverLock(driver); vmwareDriverLock(driver);
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); if (!(vm = vmwareDomObjFromDomainLocked(driver, dom->uuid)))
if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(dom->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
}
if (!vm->persistent) { if (!vm->persistent) {
virReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,
...@@ -861,18 +854,11 @@ vmwareDomainGetOSType(virDomainPtr dom) ...@@ -861,18 +854,11 @@ vmwareDomainGetOSType(virDomainPtr dom)
virDomainObjPtr vm; virDomainObjPtr vm;
char *ret = NULL; char *ret = NULL;
vmwareDriverLock(driver); if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); return NULL;
vmwareDriverUnlock(driver);
if (!vm) {
virReportError(VIR_ERR_NO_DOMAIN, NULL);
goto cleanup;
}
ignore_value(VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type))); ignore_value(VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)));
cleanup:
if (vm) if (vm)
virObjectUnlock(vm); virObjectUnlock(vm);
return ret; return ret;
...@@ -886,18 +872,11 @@ vmwareDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) ...@@ -886,18 +872,11 @@ vmwareDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
virDomainObjPtr vm; virDomainObjPtr vm;
virDomainPtr dom = NULL; virDomainPtr dom = NULL;
vmwareDriverLock(driver); if (!(vm = vmwareDomObjFromDomain(driver, uuid)))
vm = virDomainObjListFindByUUID(driver->domains, uuid); return NULL;
vmwareDriverUnlock(driver);
if (!vm) {
virReportError(VIR_ERR_NO_DOMAIN, NULL);
goto cleanup;
}
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
cleanup:
if (vm) if (vm)
virObjectUnlock(vm); virObjectUnlock(vm);
return dom; return dom;
...@@ -933,16 +912,11 @@ vmwareDomainIsActive(virDomainPtr dom) ...@@ -933,16 +912,11 @@ vmwareDomainIsActive(virDomainPtr dom)
virDomainObjPtr obj; virDomainObjPtr obj;
int ret = -1; int ret = -1;
vmwareDriverLock(driver); if (!(obj = vmwareDomObjFromDomain(driver, dom->uuid)))
obj = virDomainObjListFindByUUID(driver->domains, dom->uuid); return -1;
vmwareDriverUnlock(driver);
if (!obj) {
virReportError(VIR_ERR_NO_DOMAIN, NULL);
goto cleanup;
}
ret = virDomainObjIsActive(obj); ret = virDomainObjIsActive(obj);
cleanup:
if (obj) if (obj)
virObjectUnlock(obj); virObjectUnlock(obj);
return ret; return ret;
...@@ -956,16 +930,11 @@ vmwareDomainIsPersistent(virDomainPtr dom) ...@@ -956,16 +930,11 @@ vmwareDomainIsPersistent(virDomainPtr dom)
virDomainObjPtr obj; virDomainObjPtr obj;
int ret = -1; int ret = -1;
vmwareDriverLock(driver); if (!(obj = vmwareDomObjFromDomain(driver, dom->uuid)))
obj = virDomainObjListFindByUUID(driver->domains, dom->uuid); return -1;
vmwareDriverUnlock(driver);
if (!obj) {
virReportError(VIR_ERR_NO_DOMAIN, NULL);
goto cleanup;
}
ret = obj->persistent; ret = obj->persistent;
cleanup:
if (obj) if (obj)
virObjectUnlock(obj); virObjectUnlock(obj);
return ret; return ret;
...@@ -981,20 +950,12 @@ vmwareDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) ...@@ -981,20 +950,12 @@ vmwareDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
/* Flags checked by virDomainDefFormat */ /* Flags checked by virDomainDefFormat */
vmwareDriverLock(driver); if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); return NULL;
vmwareDriverUnlock(driver);
if (!vm) {
virReportError(VIR_ERR_NO_DOMAIN, "%s",
_("no domain with matching uuid"));
goto cleanup;
}
ret = virDomainDefFormat(vm->def, driver->caps, ret = virDomainDefFormat(vm->def, driver->caps,
virDomainDefFormatConvertXMLFlags(flags)); virDomainDefFormatConvertXMLFlags(flags));
cleanup:
if (vm) if (vm)
virObjectUnlock(vm); virObjectUnlock(vm);
return ret; return ret;
...@@ -1114,15 +1075,8 @@ vmwareDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) ...@@ -1114,15 +1075,8 @@ vmwareDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info)
virDomainObjPtr vm; virDomainObjPtr vm;
int ret = -1; int ret = -1;
vmwareDriverLock(driver); if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); return -1;
vmwareDriverUnlock(driver);
if (!vm) {
virReportError(VIR_ERR_NO_DOMAIN, "%s",
_("no domain with matching uuid"));
goto cleanup;
}
if (vmwareUpdateVMStatus(driver, vm) < 0) if (vmwareUpdateVMStatus(driver, vm) < 0)
goto cleanup; goto cleanup;
...@@ -1152,15 +1106,8 @@ vmwareDomainGetState(virDomainPtr dom, ...@@ -1152,15 +1106,8 @@ vmwareDomainGetState(virDomainPtr dom,
virCheckFlags(0, -1); virCheckFlags(0, -1);
vmwareDriverLock(driver); if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); return -1;
vmwareDriverUnlock(driver);
if (!vm) {
virReportError(VIR_ERR_NO_DOMAIN, "%s",
_("no domain with matching uuid"));
goto cleanup;
}
if (vmwareUpdateVMStatus(driver, vm) < 0) if (vmwareUpdateVMStatus(driver, vm) < 0)
goto cleanup; goto cleanup;
...@@ -1207,16 +1154,11 @@ vmwareDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags) ...@@ -1207,16 +1154,11 @@ vmwareDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
virCheckFlags(0, -1); virCheckFlags(0, -1);
vmwareDriverLock(driver); if (!(obj = vmwareDomObjFromDomain(driver, dom->uuid)))
obj = virDomainObjListFindByUUID(driver->domains, dom->uuid); return -1;
vmwareDriverUnlock(driver);
if (!obj) {
virReportError(VIR_ERR_NO_DOMAIN, NULL);
goto cleanup;
}
ret = 0; ret = 0;
cleanup:
if (obj) if (obj)
virObjectUnlock(obj); virObjectUnlock(obj);
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册