Index hashes by UUID instead of name

Per-connection hashes for domains, networks, storage pools and network
filter pools were indexed by names which was not the best choice. UUIDs
are better identifiers, so lets use them.
This commit is contained in:
Jiri Denemark 2010-06-17 16:45:26 +02:00
parent ff5f7d7204
commit 30ec755ecb

View File

@ -343,6 +343,7 @@ virUnrefConnect(virConnectPtr conn) {
virDomainPtr
virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
virDomainPtr ret = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (uuid == NULL)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
@ -350,10 +351,9 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
}
virMutexLock(&conn->lock);
/* TODO search by UUID first as they are better differentiators */
virUUIDFormat(uuid, uuidstr);
ret = (virDomainPtr) virHashLookup(conn->domains, name);
/* TODO check the UUID */
ret = (virDomainPtr) virHashLookup(conn->domains, uuidstr);
if (ret == NULL) {
if (VIR_ALLOC(ret) < 0) {
virMutexUnlock(&conn->lock);
@ -373,7 +373,7 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
ret->snapshots = virHashCreate(20);
if (virHashAddEntry(conn->domains, name, ret) < 0) {
if (virHashAddEntry(conn->domains, uuidstr, ret) < 0) {
virMutexUnlock(&conn->lock);
virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to add domain to connection hash table"));
@ -411,10 +411,12 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
static void
virReleaseDomain(virDomainPtr domain) {
virConnectPtr conn = domain->conn;
DEBUG("release domain %p %s", domain, domain->name);
char uuidstr[VIR_UUID_STRING_BUFLEN];
/* TODO search by UUID first as they are better differentiators */
if (virHashRemoveEntry(conn->domains, domain->name, NULL) < 0) {
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"));
@ -488,6 +490,7 @@ virUnrefDomain(virDomainPtr domain) {
virNetworkPtr
virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
virNetworkPtr ret = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (uuid == NULL)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
@ -495,10 +498,9 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
}
virMutexLock(&conn->lock);
/* TODO search by UUID first as they are better differentiators */
virUUIDFormat(uuid, uuidstr);
ret = (virNetworkPtr) virHashLookup(conn->networks, name);
/* TODO check the UUID */
ret = (virNetworkPtr) virHashLookup(conn->networks, uuidstr);
if (ret == NULL) {
if (VIR_ALLOC(ret) < 0) {
virMutexUnlock(&conn->lock);
@ -516,7 +518,7 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
if (uuid != NULL)
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
if (virHashAddEntry(conn->networks, name, ret) < 0) {
if (virHashAddEntry(conn->networks, uuidstr, ret) < 0) {
virMutexUnlock(&conn->lock);
virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to add network to connection hash table"));
@ -551,10 +553,12 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
static void
virReleaseNetwork(virNetworkPtr network) {
virConnectPtr conn = network->conn;
DEBUG("release network %p %s", network, network->name);
char uuidstr[VIR_UUID_STRING_BUFLEN];
/* TODO search by UUID first as they are better differentiators */
if (virHashRemoveEntry(conn->networks, network->name, NULL) < 0) {
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"));
@ -808,6 +812,7 @@ virUnrefInterface(virInterfacePtr iface) {
virStoragePoolPtr
virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uuid) {
virStoragePoolPtr ret = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (uuid == NULL)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
@ -815,10 +820,9 @@ virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uui
}
virMutexLock(&conn->lock);
/* TODO search by UUID first as they are better differentiators */
virUUIDFormat(uuid, uuidstr);
ret = (virStoragePoolPtr) virHashLookup(conn->storagePools, name);
/* TODO check the UUID */
ret = (virStoragePoolPtr) virHashLookup(conn->storagePools, uuidstr);
if (ret == NULL) {
if (VIR_ALLOC(ret) < 0) {
virMutexUnlock(&conn->lock);
@ -836,7 +840,7 @@ virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uui
if (uuid != NULL)
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
if (virHashAddEntry(conn->storagePools, name, ret) < 0) {
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"));
@ -872,10 +876,12 @@ error:
static void
virReleaseStoragePool(virStoragePoolPtr pool) {
virConnectPtr conn = pool->conn;
DEBUG("release pool %p %s", pool, pool->name);
char uuidstr[VIR_UUID_STRING_BUFLEN];
/* TODO search by UUID first as they are better differentiators */
if (virHashRemoveEntry(conn->storagePools, pool->name, NULL) < 0) {
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"));
@ -1421,6 +1427,7 @@ int virUnrefStream(virStreamPtr st) {
virNWFilterPtr
virGetNWFilter(virConnectPtr conn, const char *name, const unsigned char *uuid) {
virNWFilterPtr ret = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
if ((!VIR_IS_CONNECT(conn)) || (name == NULL) || (uuid == NULL)) {
virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
@ -1428,10 +1435,9 @@ virGetNWFilter(virConnectPtr conn, const char *name, const unsigned char *uuid)
}
virMutexLock(&conn->lock);
/* TODO search by UUID first as they are better differentiators */
virUUIDFormat(uuid, uuidstr);
ret = (virNWFilterPtr) virHashLookup(conn->nwfilterPools, name);
/* TODO check the UUID */
ret = (virNWFilterPtr) virHashLookup(conn->nwfilterPools, uuidstr);
if (ret == NULL) {
if (VIR_ALLOC(ret) < 0) {
virMutexUnlock(&conn->lock);
@ -1449,7 +1455,7 @@ virGetNWFilter(virConnectPtr conn, const char *name, const unsigned char *uuid)
if (uuid != NULL)
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
if (virHashAddEntry(conn->nwfilterPools, name, ret) < 0) {
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"));
@ -1485,10 +1491,12 @@ error:
static void
virReleaseNWFilterPool(virNWFilterPtr pool) {
virConnectPtr conn = pool->conn;
DEBUG("release pool %p %s", pool, pool->name);
char uuidstr[VIR_UUID_STRING_BUFLEN];
/* TODO search by UUID first as they are better differentiators */
if (virHashRemoveEntry(conn->nwfilterPools, pool->name, NULL) < 0) {
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"));