openvz: Handle domain obj hash map errors

This makes the driver fail with a clear error message in case of UUID
collisions (for example if somebody copied a container configuration
without updating the UUID) and also raises an error on other hash map
failures.

OpenVZ itself doesn't complain about duplicate UUIDs since this
parameter is only used by libvirt.
(cherry picked from commit 31351c316f)
This commit is contained in:
Guido Günther 2012-07-09 12:11:17 +02:00 committed by Cole Robinson
parent 00b610c8e9
commit f7ebe9d012

View File

@ -537,8 +537,18 @@ int openvzLoadDomains(struct openvz_driver *driver) {
openvzReadFSConf(dom->def, veid);
virUUIDFormat(dom->def->uuid, uuidstr);
if (virHashAddEntry(driver->domains.objs, uuidstr, dom) < 0)
if (virHashLookup(driver->domains.objs, uuidstr)) {
openvzError(VIR_ERR_INTERNAL_ERROR,
_("Duplicate container UUID %s detected for %d"),
uuidstr,
veid);
goto cleanup;
}
if (virHashAddEntry(driver->domains.objs, uuidstr, dom) < 0) {
openvzError(VIR_ERR_INTERNAL_ERROR,
_("Could not add UUID for container %d"), veid);
goto cleanup;
}
virDomainObjUnlock(dom);
dom = NULL;