[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] RFC: Remove all object hashtable caches from virConnectPtr



The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.

This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.

The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.

This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.

The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.

This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.

Other options include

 - Explicitly overrite the 'name' field in the cached
   objects every time they are looked up, to ensure
   fully up2date objects
 - Add a flag to virConnectOpen to allow apps to
   turn off caching themselves.

* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
---
 src/datatypes.c |  657 +++++++++++++------------------------------------------
 src/datatypes.h |   10 -
 2 files changed, 149 insertions(+), 518 deletions(-)

diff --git a/src/datatypes.c b/src/datatypes.c
index 46009ae..66dbc99 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -41,120 +41,6 @@
  *									*
  ************************************************************************/
 
-/**
- * virDomainFreeName:
- * @domain: a domain object
- *
- * Destroy the domain object, this is just used by the domain hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virDomainFreeName(virDomainPtr domain, const char *name ATTRIBUTE_UNUSED)
-{
-    return (virUnrefDomain(domain));
-}
-
-/**
- * virNetworkFreeName:
- * @network: a network object
- *
- * Destroy the network object, this is just used by the network hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virNetworkFreeName(virNetworkPtr network, const char *name ATTRIBUTE_UNUSED)
-{
-    return (virUnrefNetwork(network));
-}
-
-/**
- * virInterfaceFreeName:
- * @interface: an interface object
- *
- * Destroy the interface object, this is just used by the interface hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virInterfaceFreeName(virInterfacePtr iface, const char *name ATTRIBUTE_UNUSED)
-{
-    return (virUnrefInterface(iface));
-}
-
-/**
- * virStoragePoolFreeName:
- * @pool: a pool object
- *
- * Destroy the pool object, this is just used by the pool hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virStoragePoolFreeName(virStoragePoolPtr pool, const char *name ATTRIBUTE_UNUSED)
-{
-    return (virUnrefStoragePool(pool));
-}
-
-/**
- * virStorageVolFreeName:
- * @vol: a vol object
- *
- * Destroy the vol object, this is just used by the vol hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virStorageVolFreeName(virStorageVolPtr vol, const char *name ATTRIBUTE_UNUSED)
-{
-    return (virUnrefStorageVol(vol));
-}
-
-/**
- * virSecretFreeName:
- * @secret_: a secret object
- *
- * Destroy the secret object, this is just used by the secret hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static void
-virSecretFreeName(void *secret_, const char *name ATTRIBUTE_UNUSED)
-{
-    virSecretPtr secret;
-
-    secret = secret_;
-    virUnrefSecret(secret);
-}
-
-/**
- * virNWFilterPoolFreeName:
- * @pool: a nwfilter pool object
- *
- * Destroy the nwfilter pool object, this is just used by the nwfilter pool hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virNWFilterPoolFreeName(virNWFilterPtr pool, const char *name ATTRIBUTE_UNUSED)
-{
-    return (virUnrefNWFilter(pool));
-}
-
-/**
- * virDomainSnapshotFreeName:
- * @snapshot: a domain snapshotobject
- *
- * Destroy the domain snapshot object, this is just used by the domain hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virDomainSnapshotFreeName(virDomainSnapshotPtr snapshot, const char *name ATTRIBUTE_UNUSED)
-{
-    return (virUnrefDomainSnapshot(snapshot));
-}
 
 /**
  * virGetConnect:
@@ -182,53 +68,12 @@ virGetConnect(void) {
     ret->privateData = NULL;
     ret->networkPrivateData = NULL;
     ret->interfacePrivateData = NULL;
-    ret->domains = virHashCreate(20);
-    if (ret->domains == NULL)
-        goto failed;
-    ret->networks = virHashCreate(20);
-    if (ret->networks == NULL)
-        goto failed;
-    ret->interfaces = virHashCreate(20);
-    if (ret->interfaces == NULL)
-        goto failed;
-    ret->storagePools = virHashCreate(20);
-    if (ret->storagePools == NULL)
-        goto failed;
-    ret->storageVols = virHashCreate(20);
-    if (ret->storageVols == NULL)
-        goto failed;
-    ret->nodeDevices = virHashCreate(256);
-    if (ret->nodeDevices == NULL)
-        goto failed;
-    ret->secrets = virHashCreate(20);
-    if (ret->secrets == NULL)
-        goto failed;
-    ret->nwfilterPools = virHashCreate(20);
-    if (ret->nwfilterPools == NULL)
-        goto failed;
 
     ret->refs = 1;
     return(ret);
 
 failed:
     if (ret != NULL) {
-        if (ret->domains != NULL)
-            virHashFree(ret->domains, (virHashDeallocator) virDomainFreeName);
-        if (ret->networks != NULL)
-            virHashFree(ret->networks, (virHashDeallocator) virNetworkFreeName);
-        if (ret->interfaces != NULL)
-           virHashFree(ret->interfaces, (virHashDeallocator) virInterfaceFreeName);
-        if (ret->storagePools != NULL)
-            virHashFree(ret->storagePools, (virHashDeallocator) virStoragePoolFreeName);
-        if (ret->storageVols != NULL)
-            virHashFree(ret->storageVols, (virHashDeallocator) virStorageVolFreeName);
-        if (ret->nodeDevices != NULL)
-            virHashFree(ret->nodeDevices, (virHashDeallocator) virNodeDeviceFree);
-        if (ret->secrets != NULL)
-            virHashFree(ret->secrets, virSecretFreeName);
-        if (ret->nwfilterPools != NULL)
-            virHashFree(ret->nwfilterPools, (virHashDeallocator) virNWFilterPoolFreeName);
-
         virMutexDestroy(&ret->lock);
         VIR_FREE(ret);
     }
@@ -247,22 +92,6 @@ failed:
 static void
 virReleaseConnect(virConnectPtr conn) {
     DEBUG("release connection %p", conn);
-    if (conn->domains != NULL)
-        virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
-    if (conn->networks != NULL)
-        virHashFree(conn->networks, (virHashDeallocator) virNetworkFreeName);
-    if (conn->interfaces != NULL)
-        virHashFree(conn->interfaces, (virHashDeallocator) virInterfaceFreeName);
-    if (conn->storagePools != NULL)
-        virHashFree(conn->storagePools, (virHashDeallocator) virStoragePoolFreeName);
-    if (conn->storageVols != NULL)
-        virHashFree(conn->storageVols, (virHashDeallocator) virStorageVolFreeName);
-    if (conn->nodeDevices != NULL)
-        virHashFree(conn->nodeDevices, (virHashDeallocator) virNodeDeviceFree);
-    if (conn->secrets != NULL)
-        virHashFree(conn->secrets, virSecretFreeName);
-    if (conn->nwfilterPools != NULL)
-        virHashFree(conn->nwfilterPools, (virHashDeallocator) virNWFilterPoolFreeName);
 
     virResetError(&conn->err);
 
@@ -353,36 +182,23 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
 
     virUUIDFormat(uuid, uuidstr);
 
-    ret = (virDomainPtr) virHashLookup(conn->domains, uuidstr);
-    if (ret == NULL) {
-        if (VIR_ALLOC(ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->name = strdup(name);
-        if (ret->name == NULL) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->magic = VIR_DOMAIN_MAGIC;
-        ret->conn = conn;
-        ret->id = -1;
-        memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
-        ret->snapshots = virHashCreate(20);
-
-        if (virHashAddEntry(conn->domains, uuidstr, ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
-                            _("failed to add domain to connection hash table"));
-            goto error;
-        }
-        conn->refs++;
-        DEBUG("New hash entry %p", ret);
-    } else {
-        DEBUG("Existing hash entry %p: refs now %d", ret, ret->refs+1);
+    if (VIR_ALLOC(ret) < 0) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
+    }
+    ret->name = strdup(name);
+    if (ret->name == NULL) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
     }
+    ret->magic = VIR_DOMAIN_MAGIC;
+    ret->conn = conn;
+    ret->id = -1;
+    memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
+
+    conn->refs++;
     ret->refs++;
     virMutexUnlock(&conn->lock);
     return(ret);
@@ -415,18 +231,9 @@ virReleaseDomain(virDomainPtr domain) {
     virUUIDFormat(domain->uuid, uuidstr);
     DEBUG("release domain %p %s %s", domain, domain->name, uuidstr);
 
-    if (virHashRemoveEntry(conn->domains, uuidstr, NULL) < 0) {
-        virMutexUnlock(&conn->lock);
-        virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
-                        _("domain missing from connection hash table"));
-        conn = NULL;
-    }
-
     domain->magic = -1;
     domain->id = -1;
     VIR_FREE(domain->name);
-    if (domain->snapshots != NULL)
-        virHashFree(domain->snapshots, (virHashDeallocator) virDomainSnapshotFreeName);
     VIR_FREE(domain);
 
     if (conn) {
@@ -499,31 +306,22 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
 
     virUUIDFormat(uuid, uuidstr);
 
-    ret = (virNetworkPtr) virHashLookup(conn->networks, uuidstr);
-    if (ret == NULL) {
-        if (VIR_ALLOC(ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->name = strdup(name);
-        if (ret->name == NULL) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->magic = VIR_NETWORK_MAGIC;
-        ret->conn = conn;
-        memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
-
-        if (virHashAddEntry(conn->networks, uuidstr, ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
-                            _("failed to add network to connection hash table"));
-            goto error;
-        }
-        conn->refs++;
+    if (VIR_ALLOC(ret) < 0) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
     }
+    ret->name = strdup(name);
+    if (ret->name == NULL) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
+    }
+    ret->magic = VIR_NETWORK_MAGIC;
+    ret->conn = conn;
+    memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
+
+    conn->refs++;
     ret->refs++;
     virMutexUnlock(&conn->lock);
     return(ret);
@@ -556,13 +354,6 @@ virReleaseNetwork(virNetworkPtr network) {
     virUUIDFormat(network->uuid, uuidstr);
     DEBUG("release network %p %s %s", network, network->name, uuidstr);
 
-    if (virHashRemoveEntry(conn->networks, uuidstr, NULL) < 0) {
-        virMutexUnlock(&conn->lock);
-        virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
-                        _("network missing from connection hash table"));
-        conn = NULL;
-    }
-
     network->magic = -1;
     VIR_FREE(network->name);
     VIR_FREE(network);
@@ -641,70 +432,28 @@ virGetInterface(virConnectPtr conn, const char *name, const char *mac) {
 
     virMutexLock(&conn->lock);
 
-    ret = (virInterfacePtr) virHashLookup(conn->interfaces, name);
-
-    if (ret != NULL) {
-        if (STRCASENEQ(ret->mac, mac)) {
-            /*
-             * If the mac address has changed, try to modify it in
-             * place, which will only work if the new mac is the
-             * same length as, or shorter than, the old mac.
-             */
-            size_t newmaclen = strlen(mac);
-            size_t oldmaclen = strlen(ret->mac);
-            if (newmaclen <= oldmaclen) {
-                strcpy(ret->mac, mac);
-            } else {
-                /*
-                 * If it's longer, we're kind of screwed, because we
-                 * can't add a new hashtable entry (it would clash
-                 * with the existing entry of same name), and we can't
-                 * free/re-alloc the existing entry's mac, as some
-                 * other thread may already be using the existing mac
-                 * pointer.  Fortunately, this should never happen,
-                 * since the length of the mac address for any
-                 * interface is determined by the type of the
-                 * interface, and that is unlikely to change.
-                 */
-                virMutexUnlock(&conn->lock);
-                virLibConnError(VIR_ERR_INTERNAL_ERROR,
-                                _("Failed to change interface mac address "
-                                  "from %s to %s due to differing lengths."),
-                                ret->mac, mac);
-                ret = NULL;
-                goto error;
-            }
-        }
-    } else {
-        if (VIR_ALLOC(ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->name = strdup(name);
-        if (ret->name == NULL) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->mac = strdup(mac);
-        if (ret->mac == NULL) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
+    if (VIR_ALLOC(ret) < 0) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
+    }
+    ret->name = strdup(name);
+    if (ret->name == NULL) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
+    }
+    ret->mac = strdup(mac);
+    if (ret->mac == NULL) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
+    }
 
-        ret->magic = VIR_INTERFACE_MAGIC;
-        ret->conn = conn;
+    ret->magic = VIR_INTERFACE_MAGIC;
+    ret->conn = conn;
 
-        if (virHashAddEntry(conn->interfaces, name, ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
-                            _("failed to add interface to connection hash table"));
-            goto error;
-        }
-        conn->refs++;
-    }
+    conn->refs++;
     ret->refs++;
     virMutexUnlock(&conn->lock);
     return(ret);
@@ -735,15 +484,6 @@ virReleaseInterface(virInterfacePtr iface) {
     virConnectPtr conn = iface->conn;
     DEBUG("release interface %p %s", iface, iface->name);
 
-    if (virHashRemoveEntry(conn->interfaces, iface->name, NULL) < 0) {
-        /* unlock before reporting error because error report grabs lock */
-        virMutexUnlock(&conn->lock);
-        virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
-                        _("interface missing from connection hash table"));
-        /* don't decr the conn refct if we weren't connected to it */
-        conn = NULL;
-    }
-
     iface->magic = -1;
     VIR_FREE(iface->name);
     VIR_FREE(iface->mac);
@@ -820,31 +560,22 @@ virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uui
 
     virUUIDFormat(uuid, uuidstr);
 
-    ret = (virStoragePoolPtr) virHashLookup(conn->storagePools, uuidstr);
-    if (ret == NULL) {
-        if (VIR_ALLOC(ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->name = strdup(name);
-        if (ret->name == NULL) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->magic = VIR_STORAGE_POOL_MAGIC;
-        ret->conn = conn;
-        memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
-
-        if (virHashAddEntry(conn->storagePools, uuidstr, ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virLibConnError(VIR_ERR_INTERNAL_ERROR,
-                            "%s", _("failed to add storage pool to connection hash table"));
-            goto error;
-        }
-        conn->refs++;
+    if (VIR_ALLOC(ret) < 0) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
+    }
+    ret->name = strdup(name);
+    if (ret->name == NULL) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
     }
+    ret->magic = VIR_STORAGE_POOL_MAGIC;
+    ret->conn = conn;
+    memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
+
+    conn->refs++;
     ret->refs++;
     virMutexUnlock(&conn->lock);
     return(ret);
@@ -878,13 +609,6 @@ virReleaseStoragePool(virStoragePoolPtr pool) {
     virUUIDFormat(pool->uuid, uuidstr);
     DEBUG("release pool %p %s %s", pool, pool->name, uuidstr);
 
-    if (virHashRemoveEntry(conn->storagePools, uuidstr, NULL) < 0) {
-        virMutexUnlock(&conn->lock);
-        virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
-                        _("pool missing from connection hash table"));
-        conn = NULL;
-    }
-
     pool->magic = -1;
     VIR_FREE(pool->name);
     VIR_FREE(pool);
@@ -958,42 +682,33 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, const c
     }
     virMutexLock(&conn->lock);
 
-    ret = (virStorageVolPtr) virHashLookup(conn->storageVols, key);
-    if (ret == NULL) {
-        if (VIR_ALLOC(ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->pool = strdup(pool);
-        if (ret->pool == NULL) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->name = strdup(name);
-        if (ret->name == NULL) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        if (virStrcpyStatic(ret->key, key) == NULL) {
-            virMutexUnlock(&conn->lock);
-            virLibConnError(VIR_ERR_INTERNAL_ERROR,
-                            _("Volume key %s too large for destination"), key);
-            goto error;
-        }
-        ret->magic = VIR_STORAGE_VOL_MAGIC;
-        ret->conn = conn;
-
-        if (virHashAddEntry(conn->storageVols, key, ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
-                            _("failed to add storage vol to connection hash table"));
-            goto error;
-        }
-        conn->refs++;
+    if (VIR_ALLOC(ret) < 0) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
+    }
+    ret->pool = strdup(pool);
+    if (ret->pool == NULL) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
+    }
+    ret->name = strdup(name);
+    if (ret->name == NULL) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
+    }
+    if (virStrcpyStatic(ret->key, key) == NULL) {
+        virMutexUnlock(&conn->lock);
+        virLibConnError(VIR_ERR_INTERNAL_ERROR,
+                        _("Volume key %s too large for destination"), key);
+        goto error;
     }
+    ret->magic = VIR_STORAGE_VOL_MAGIC;
+    ret->conn = conn;
+
+    conn->refs++;
     ret->refs++;
     virMutexUnlock(&conn->lock);
     return(ret);
@@ -1025,13 +740,6 @@ virReleaseStorageVol(virStorageVolPtr vol) {
     virConnectPtr conn = vol->conn;
     DEBUG("release vol %p %s", vol, vol->name);
 
-    if (virHashRemoveEntry(conn->storageVols, vol->key, NULL) < 0) {
-        virMutexUnlock(&conn->lock);
-        virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
-                        _("vol missing from connection hash table"));
-        conn = NULL;
-    }
-
     vol->magic = -1;
     VIR_FREE(vol->name);
     VIR_FREE(vol->pool);
@@ -1105,30 +813,21 @@ virGetNodeDevice(virConnectPtr conn, const char *name)
     }
     virMutexLock(&conn->lock);
 
-    ret = (virNodeDevicePtr) virHashLookup(conn->nodeDevices, name);
-    if (ret == NULL) {
-        if (VIR_ALLOC(ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->magic = VIR_NODE_DEVICE_MAGIC;
-        ret->conn = conn;
-        ret->name = strdup(name);
-        if (ret->name == NULL) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-
-        if (virHashAddEntry(conn->nodeDevices, name, ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virLibConnError(VIR_ERR_INTERNAL_ERROR,
-                            "%s", _("failed to add node dev to conn hash table"));
-            goto error;
-        }
-        conn->refs++;
+    if (VIR_ALLOC(ret) < 0) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
     }
+    ret->magic = VIR_NODE_DEVICE_MAGIC;
+    ret->conn = conn;
+    ret->name = strdup(name);
+    if (ret->name == NULL) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
+    }
+
+    conn->refs++;
     ret->refs++;
     virMutexUnlock(&conn->lock);
     return(ret);
@@ -1159,13 +858,6 @@ virReleaseNodeDevice(virNodeDevicePtr dev) {
     virConnectPtr conn = dev->conn;
     DEBUG("release dev %p %s", dev, dev->name);
 
-    if (virHashRemoveEntry(conn->nodeDevices, dev->name, NULL) < 0) {
-        virMutexUnlock(&conn->lock);
-        virLibConnError(VIR_ERR_INTERNAL_ERROR,
-                        "%s", _("dev missing from connection hash table"));
-        conn = NULL;
-    }
-
     dev->magic = -1;
     VIR_FREE(dev->name);
     VIR_FREE(dev->parent);
@@ -1239,30 +931,21 @@ virGetSecret(virConnectPtr conn, const unsigned char *uuid,
 
     virUUIDFormat(uuid, uuidstr);
 
-    ret = virHashLookup(conn->secrets, uuidstr);
-    if (ret == NULL) {
-        if (VIR_ALLOC(ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->magic = VIR_SECRET_MAGIC;
-        ret->conn = conn;
-        memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
-        ret->usageType = usageType;
-        if (!(ret->usageID = strdup(usageID))) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        if (virHashAddEntry(conn->secrets, uuidstr, ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
-                            _("failed to add secret to conn hash table"));
-            goto error;
-        }
-        conn->refs++;
+    if (VIR_ALLOC(ret) < 0) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
+    }
+    ret->magic = VIR_SECRET_MAGIC;
+    ret->conn = conn;
+    memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
+    ret->usageType = usageType;
+    if (!(ret->usageID = strdup(usageID))) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
     }
+    conn->refs++;
     ret->refs++;
     virMutexUnlock(&conn->lock);
     return ret;
@@ -1294,13 +977,6 @@ virReleaseSecret(virSecretPtr secret) {
     virUUIDFormat(secret->uuid, uuidstr);
     DEBUG("release secret %p %s", secret, uuidstr);
 
-    if (virHashRemoveEntry(conn->secrets, uuidstr, NULL) < 0) {
-        virMutexUnlock(&conn->lock);
-        virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
-                        _("secret missing from connection hash table"));
-        conn = NULL;
-    }
-
     VIR_FREE(secret->usageID);
     secret->magic = -1;
     VIR_FREE(secret);
@@ -1433,31 +1109,22 @@ virGetNWFilter(virConnectPtr conn, const char *name, const unsigned char *uuid)
 
     virUUIDFormat(uuid, uuidstr);
 
-    ret = (virNWFilterPtr) virHashLookup(conn->nwfilterPools, uuidstr);
-    if (ret == NULL) {
-        if (VIR_ALLOC(ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->name = strdup(name);
-        if (ret->name == NULL) {
-            virMutexUnlock(&conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->magic = VIR_NWFILTER_MAGIC;
-        ret->conn = conn;
-        memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
-
-        if (virHashAddEntry(conn->nwfilterPools, uuidstr, ret) < 0) {
-            virMutexUnlock(&conn->lock);
-            virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
-                            _("failed to add network filter pool to connection hash table"));
-            goto error;
-        }
-        conn->refs++;
+    if (VIR_ALLOC(ret) < 0) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
+    }
+    ret->name = strdup(name);
+    if (ret->name == NULL) {
+        virMutexUnlock(&conn->lock);
+        virReportOOMError();
+        goto error;
     }
+    ret->magic = VIR_NWFILTER_MAGIC;
+    ret->conn = conn;
+    memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
+
+    conn->refs++;
     ret->refs++;
     virMutexUnlock(&conn->lock);
     return(ret);
@@ -1491,13 +1158,6 @@ virReleaseNWFilterPool(virNWFilterPtr pool) {
     virUUIDFormat(pool->uuid, uuidstr);
     DEBUG("release pool %p %s %s", pool, pool->name, uuidstr);
 
-    if (virHashRemoveEntry(conn->nwfilterPools, uuidstr, NULL) < 0) {
-        virMutexUnlock(&conn->lock);
-        virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
-                        _("pool missing from connection hash table"));
-        conn = NULL;
-    }
-
     pool->magic = -1;
     VIR_FREE(pool->name);
     VIR_FREE(pool);
@@ -1558,33 +1218,21 @@ virGetDomainSnapshot(virDomainPtr domain, const char *name)
     }
     virMutexLock(&domain->conn->lock);
 
-    ret = (virDomainSnapshotPtr) virHashLookup(domain->snapshots, name);
-    if (ret == NULL) {
-        if (VIR_ALLOC(ret) < 0) {
-            virMutexUnlock(&domain->conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->name = strdup(name);
-        if (ret->name == NULL) {
-            virMutexUnlock(&domain->conn->lock);
-            virReportOOMError();
-            goto error;
-        }
-        ret->magic = VIR_SNAPSHOT_MAGIC;
-        ret->domain = domain;
-
-        if (virHashAddEntry(domain->snapshots, name, ret) < 0) {
-            virMutexUnlock(&domain->conn->lock);
-            virLibConnError(VIR_ERR_INTERNAL_ERROR,
-                            "%s", _("failed to add snapshot to domain hash table"));
-            goto error;
-        }
-        domain->refs++;
-        DEBUG("New hash entry %p", ret);
-    } else {
-        DEBUG("Existing hash entry %p: refs now %d", ret, ret->refs+1);
+    if (VIR_ALLOC(ret) < 0) {
+        virMutexUnlock(&domain->conn->lock);
+        virReportOOMError();
+        goto error;
+    }
+    ret->name = strdup(name);
+    if (ret->name == NULL) {
+        virMutexUnlock(&domain->conn->lock);
+        virReportOOMError();
+        goto error;
     }
+    ret->magic = VIR_SNAPSHOT_MAGIC;
+    ret->domain = domain;
+
+    domain->refs++;
     ret->refs++;
     virMutexUnlock(&domain->conn->lock);
     return(ret);
@@ -1604,13 +1252,6 @@ virReleaseDomainSnapshot(virDomainSnapshotPtr snapshot)
     virDomainPtr domain = snapshot->domain;
     DEBUG("release snapshot %p %s", snapshot, snapshot->name);
 
-    if (virHashRemoveEntry(domain->snapshots, snapshot->name, NULL) < 0) {
-        virMutexUnlock(&domain->conn->lock);
-        virLibConnError(VIR_ERR_INTERNAL_ERROR,
-                        "%s", _("snapshot missing from domain hash table"));
-        domain = NULL;
-    }
-
     snapshot->magic = -1;
     VIR_FREE(snapshot->name);
     VIR_FREE(snapshot);
diff --git a/src/datatypes.h b/src/datatypes.h
index bbeb7cf..0409ab1 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -24,7 +24,6 @@
 
 # include "internal.h"
 
-# include "hash.h"
 # include "driver.h"
 # include "threads.h"
 
@@ -188,14 +187,6 @@ struct _virConnect {
     virErrorFunc handler;   /* associated handlet */
     void *userData;         /* the user data */
 
-    virHashTablePtr domains;  /* hash table for known domains */
-    virHashTablePtr networks; /* hash table for known domains */
-    virHashTablePtr interfaces; /* hash table for known interfaces */
-    virHashTablePtr storagePools;/* hash table for known storage pools */
-    virHashTablePtr storageVols;/* hash table for known storage vols */
-    virHashTablePtr nodeDevices; /* hash table for known node devices */
-    virHashTablePtr secrets;  /* hash taboe for known secrets */
-    virHashTablePtr nwfilterPools; /* hash tables ofr known nw filter pools */
     int refs;                 /* reference count */
 };
 
@@ -211,7 +202,6 @@ struct _virDomain {
     char *name;                          /* the domain external name */
     int id;                              /* the domain ID */
     unsigned char uuid[VIR_UUID_BUFLEN]; /* the domain unique identifier */
-    virHashTablePtr snapshots; /* hash table for known snapshots */
 };
 
 /**
-- 
1.7.2.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]