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