[libvirt] [PATCHv2] 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. --- This version adds an extra check for hash collisions and keeps the generic failure message for all other errors in virHashAddEntry. Cheers, -- Guido src/openvz/openvz_conf.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 503c8a0..91cd125 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -684,8 +684,18 @@ int openvzLoadDomains(struct openvz_driver *driver) { openvzReadMemConf(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; -- 1.7.10.4

On 07/10/2012 12:54 PM, Guido Günther wrote:
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. --- This version adds an extra check for hash collisions and keeps the generic failure message for all other errors in virHashAddEntry. Cheers, -- Guido
ACK. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Tue, Jul 10, 2012 at 05:31:27PM -0600, Eric Blake wrote:
On 07/10/2012 12:54 PM, Guido Günther wrote:
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. --- This version adds an extra check for hash collisions and keeps the generic failure message for all other errors in virHashAddEntry. Cheers, -- Guido
ACK.
Pushed. Thanks, -- Guido
-- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Guido Günther