qemu: Report better error message when renaming to existing domain name

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Martin Kletzander 2015-08-18 11:22:02 -07:00
parent 7b5acf9461
commit c7596cf0e0

View File

@ -19907,6 +19907,7 @@ static int qemuDomainRename(virDomainPtr dom,
virQEMUDriverPtr driver = dom->conn->privateData;
virQEMUDriverConfigPtr cfg = NULL;
virDomainObjPtr vm = NULL;
virDomainObjPtr tmp_dom = NULL;
virObjectEventPtr event_new = NULL;
virObjectEventPtr event_old = NULL;
int ret = -1;
@ -19961,6 +19962,21 @@ static int qemuDomainRename(virDomainPtr dom,
goto endjob;
}
/*
* This is a rather racy check, but still better than reporting
* internal error. And since new_name != name here, there's no
* deadlock imminent.
*/
tmp_dom = virDomainObjListFindByName(driver->domains, new_name);
if (tmp_dom) {
virObjectUnlock(tmp_dom);
virObjectUnref(tmp_dom);
virReportError(VIR_ERR_OPERATION_INVALID,
_("domain with name '%s' already exists"),
new_name);
goto endjob;
}
if (VIR_STRDUP(new_dom_name, new_name) < 0)
goto endjob;