lxc: Use virDomainFindByUUID for domain lookup

Consistently use virDomainFindByUUID instead of virDomainFindByID and
virDomainFindByName and report VIR_ERR_NO_DOMAIN when domain cannot be
found.
This commit is contained in:
Jiri Denemark 2010-05-03 13:59:03 +02:00
parent ee234bfd5b
commit e1fa3fb0fc

View File

@ -200,7 +200,8 @@ static virDomainPtr lxcDomainLookupByID(virConnectPtr conn,
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!vm) { if (!vm) {
lxcError(VIR_ERR_NO_DOMAIN, NULL); lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching id %d"), id);
goto cleanup; goto cleanup;
} }
@ -226,7 +227,10 @@ static virDomainPtr lxcDomainLookupByUUID(virConnectPtr conn,
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!vm) { if (!vm) {
lxcError(VIR_ERR_NO_DOMAIN, NULL); char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(uuid, uuidstr);
lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
@ -251,7 +255,8 @@ static virDomainPtr lxcDomainLookupByName(virConnectPtr conn,
vm = virDomainFindByName(&driver->domains, name); vm = virDomainFindByName(&driver->domains, name);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!vm) { if (!vm) {
lxcError(VIR_ERR_NO_DOMAIN, NULL); lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching name '%s'"), name);
goto cleanup; goto cleanup;
} }
@ -276,7 +281,10 @@ static int lxcDomainIsActive(virDomainPtr dom)
obj = virDomainFindByUUID(&driver->domains, dom->uuid); obj = virDomainFindByUUID(&driver->domains, dom->uuid);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!obj) { if (!obj) {
lxcError(VIR_ERR_NO_DOMAIN, NULL); char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(dom->uuid, uuidstr);
lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
ret = virDomainObjIsActive(obj); ret = virDomainObjIsActive(obj);
@ -298,7 +306,10 @@ static int lxcDomainIsPersistent(virDomainPtr dom)
obj = virDomainFindByUUID(&driver->domains, dom->uuid); obj = virDomainFindByUUID(&driver->domains, dom->uuid);
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!obj) { if (!obj) {
lxcError(VIR_ERR_NO_DOMAIN, NULL); char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(dom->uuid, uuidstr);
lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
ret = obj->persistent; ret = obj->persistent;
@ -424,8 +435,10 @@ static int lxcDomainUndefine(virDomainPtr dom)
lxcDriverLock(driver); lxcDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) { if (!vm) {
lxcError(VIR_ERR_INVALID_DOMAIN, char uuidstr[VIR_UUID_STRING_BUFLEN];
"%s", _("No domain with matching uuid")); virUUIDFormat(dom->uuid, uuidstr);
lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
@ -475,8 +488,10 @@ static int lxcDomainGetInfo(virDomainPtr dom,
vm = virDomainFindByUUID(&driver->domains, dom->uuid); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) { if (!vm) {
lxcError(VIR_ERR_INVALID_DOMAIN, char uuidstr[VIR_UUID_STRING_BUFLEN];
"%s", _("No domain with matching uuid")); virUUIDFormat(dom->uuid, uuidstr);
lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
@ -528,8 +543,10 @@ static char *lxcGetOSType(virDomainPtr dom)
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!vm) { if (!vm) {
lxcError(VIR_ERR_INVALID_DOMAIN, char uuidstr[VIR_UUID_STRING_BUFLEN];
"%s", _("No domain with matching uuid")); virUUIDFormat(dom->uuid, uuidstr);
lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
@ -668,8 +685,10 @@ static char *lxcDomainDumpXML(virDomainPtr dom,
lxcDriverUnlock(driver); lxcDriverUnlock(driver);
if (!vm) { if (!vm) {
lxcError(VIR_ERR_INVALID_DOMAIN, char uuidstr[VIR_UUID_STRING_BUFLEN];
"%s", _("No domain with matching uuid")); virUUIDFormat(dom->uuid, uuidstr);
lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
@ -1341,10 +1360,12 @@ static int lxcDomainStart(virDomainPtr dom)
int ret = -1; int ret = -1;
lxcDriverLock(driver); lxcDriverLock(driver);
vm = virDomainFindByName(&driver->domains, dom->name); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) { if (!vm) {
lxcError(VIR_ERR_INVALID_DOMAIN, char uuidstr[VIR_UUID_STRING_BUFLEN];
_("No domain named %s"), dom->name); virUUIDFormat(dom->uuid, uuidstr);
lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
@ -1450,10 +1471,12 @@ static int lxcDomainShutdown(virDomainPtr dom)
int ret = -1; int ret = -1;
lxcDriverLock(driver); lxcDriverLock(driver);
vm = virDomainFindByID(&driver->domains, dom->id); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) { if (!vm) {
lxcError(VIR_ERR_INVALID_DOMAIN, char uuidstr[VIR_UUID_STRING_BUFLEN];
_("No domain with id %d"), dom->id); virUUIDFormat(dom->uuid, uuidstr);
lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
@ -1627,10 +1650,12 @@ static int lxcDomainDestroy(virDomainPtr dom)
int ret = -1; int ret = -1;
lxcDriverLock(driver); lxcDriverLock(driver);
vm = virDomainFindByID(&driver->domains, dom->id); vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) { if (!vm) {
lxcError(VIR_ERR_INVALID_DOMAIN, char uuidstr[VIR_UUID_STRING_BUFLEN];
_("No domain with id %d"), dom->id); virUUIDFormat(dom->uuid, uuidstr);
lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
@ -1996,8 +2021,10 @@ static int lxcSetSchedulerParameters(virDomainPtr domain,
vm = virDomainFindByUUID(&driver->domains, domain->uuid); vm = virDomainFindByUUID(&driver->domains, domain->uuid);
if (vm == NULL) { if (vm == NULL) {
lxcError(VIR_ERR_INTERNAL_ERROR, char uuidstr[VIR_UUID_STRING_BUFLEN];
_("No such domain %s"), domain->uuid); virUUIDFormat(domain->uuid, uuidstr);
lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }
@ -2054,8 +2081,10 @@ static int lxcGetSchedulerParameters(virDomainPtr domain,
vm = virDomainFindByUUID(&driver->domains, domain->uuid); vm = virDomainFindByUUID(&driver->domains, domain->uuid);
if (vm == NULL) { if (vm == NULL) {
lxcError(VIR_ERR_INTERNAL_ERROR, char uuidstr[VIR_UUID_STRING_BUFLEN];
_("No such domain %s"), domain->uuid); virUUIDFormat(domain->uuid, uuidstr);
lxcError(VIR_ERR_NO_DOMAIN,
_("No domain with matching uuid '%s'"), uuidstr);
goto cleanup; goto cleanup;
} }