Tue Feb 14 14:58:35 EST 2007 Mark McLoughlin <markmc@redhat.com

* src/hash.c, src/internal.h: Re-name virConnect->domains_mux
        to virConnect->hashes_mux since it will also be used to
        protect the networks hash.
This commit is contained in:
Mark McLoughlin 2007-02-14 15:59:40 +00:00
parent 36d597380e
commit e018cbc74f
3 changed files with 28 additions and 22 deletions

View File

@ -1,6 +1,12 @@
Tue Feb 14 14:58:35 EST 2007 Mark McLoughlin <markmc@redhat.com
* src/hash.c, src/internal.h: Re-name virConnect->domains_mux
to virConnect->hashes_mux since it will also be used to
protect the networks hash.
Tue Feb 14 14:57:52 EST 2007 Mark McLoughlin <markmc@redhat.com Tue Feb 14 14:57:52 EST 2007 Mark McLoughlin <markmc@redhat.com
* src/conf.c: qemudSaveConfig() will always report a * qemud/conf.c: qemudSaveConfig() will always report a
more specific error, so we should avoid overwriting more specific error, so we should avoid overwriting
this error. this error.

View File

@ -660,8 +660,8 @@ virGetConnect(void) {
ret->domains = virHashCreate(20); ret->domains = virHashCreate(20);
if (ret->domains == NULL) if (ret->domains == NULL)
goto failed; goto failed;
ret->domains_mux = xmlNewMutex(); ret->hashes_mux = xmlNewMutex();
if (ret->domains_mux == NULL) if (ret->hashes_mux == NULL)
goto failed; goto failed;
ret->uses = 1; ret->uses = 1;
@ -671,8 +671,8 @@ failed:
if (ret != NULL) { if (ret != NULL) {
if (ret->domains != NULL) if (ret->domains != NULL)
virHashFree(ret->domains, (virHashDeallocator) virDomainFreeName); virHashFree(ret->domains, (virHashDeallocator) virDomainFreeName);
if (ret->domains_mux != NULL) if (ret->hashes_mux != NULL)
xmlFreeMutex(ret->domains_mux); xmlFreeMutex(ret->hashes_mux);
free(ret); free(ret);
} }
return(NULL); return(NULL);
@ -691,22 +691,22 @@ int
virFreeConnect(virConnectPtr conn) { virFreeConnect(virConnectPtr conn) {
int ret; int ret;
if ((!VIR_IS_CONNECT(conn)) || (conn->domains_mux == NULL)) { if ((!VIR_IS_CONNECT(conn)) || (conn->hashes_mux == NULL)) {
virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__); virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(-1); return(-1);
} }
xmlMutexLock(conn->domains_mux); xmlMutexLock(conn->hashes_mux);
conn->uses--; conn->uses--;
ret = conn->uses; ret = conn->uses;
if (ret > 0) { if (ret > 0) {
xmlMutexUnlock(conn->domains_mux); xmlMutexUnlock(conn->hashes_mux);
return(ret); return(ret);
} }
if (conn->domains != NULL) if (conn->domains != NULL)
virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName); virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
if (conn->domains_mux != NULL) if (conn->hashes_mux != NULL)
xmlFreeMutex(conn->domains_mux); xmlFreeMutex(conn->hashes_mux);
free(conn); free(conn);
return(0); return(0);
} }
@ -729,11 +729,11 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
virDomainPtr ret = NULL; virDomainPtr ret = NULL;
if ((!VIR_IS_CONNECT(conn)) || ((name == NULL) && (uuid == NULL)) || if ((!VIR_IS_CONNECT(conn)) || ((name == NULL) && (uuid == NULL)) ||
(conn->domains_mux == NULL)) { (conn->hashes_mux == NULL)) {
virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__); virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(NULL); return(NULL);
} }
xmlMutexLock(conn->domains_mux); xmlMutexLock(conn->hashes_mux);
/* TODO search by UUID first as they are better differenciators */ /* TODO search by UUID first as they are better differenciators */
@ -771,11 +771,11 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
conn->uses++; conn->uses++;
done: done:
ret->uses++; ret->uses++;
xmlMutexUnlock(conn->domains_mux); xmlMutexUnlock(conn->hashes_mux);
return(ret); return(ret);
error: error:
xmlMutexUnlock(conn->domains_mux); xmlMutexUnlock(conn->hashes_mux);
if (ret != NULL) { if (ret != NULL) {
if (ret->name != NULL) if (ret->name != NULL)
free(ret->name ); free(ret->name );
@ -799,11 +799,11 @@ virFreeDomain(virConnectPtr conn, virDomainPtr domain) {
int ret = 0; int ret = 0;
if ((!VIR_IS_CONNECT(conn)) || (!VIR_IS_CONNECTED_DOMAIN(domain)) || if ((!VIR_IS_CONNECT(conn)) || (!VIR_IS_CONNECTED_DOMAIN(domain)) ||
(domain->conn != conn) || (conn->domains_mux == NULL)) { (domain->conn != conn) || (conn->hashes_mux == NULL)) {
virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__); virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(-1); return(-1);
} }
xmlMutexLock(conn->domains_mux); xmlMutexLock(conn->hashes_mux);
/* /*
* decrement the count for the domain * decrement the count for the domain
@ -839,13 +839,13 @@ virFreeDomain(virConnectPtr conn, virDomainPtr domain) {
if (conn->domains != NULL) if (conn->domains != NULL)
virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName); virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
if (conn->domains_mux != NULL) if (conn->hashes_mux != NULL)
xmlFreeMutex(conn->domains_mux); xmlFreeMutex(conn->hashes_mux);
free(conn); free(conn);
return(0); return(0);
done: done:
xmlMutexUnlock(conn->domains_mux); xmlMutexUnlock(conn->hashes_mux);
return(ret); return(ret);
} }
@ -870,7 +870,7 @@ virGetDomainByID(virConnectPtr conn, int id) {
virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__); virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(NULL); return(NULL);
} }
xmlMutexLock(conn->domains_mux); xmlMutexLock(conn->hashes_mux);
table = conn->domains; table = conn->domains;
if ((table == NULL) || (table->nbElems == 0)) if ((table == NULL) || (table->nbElems == 0))
@ -890,7 +890,7 @@ virGetDomainByID(virConnectPtr conn, int id) {
} }
} }
done: done:
xmlMutexUnlock(conn->domains_mux); xmlMutexUnlock(conn->hashes_mux);
return(ret); return(ret);
} }
/* /*

View File

@ -125,7 +125,7 @@ struct _virConnect {
void *userData; /* the user data */ void *userData; /* the user data */
/* misc */ /* misc */
xmlMutexPtr domains_mux;/* a mutex to protect the domain hash table */ xmlMutexPtr hashes_mux;/* a mutex to protect the domain hash table */
virHashTablePtr domains;/* hash table for known domains */ virHashTablePtr domains;/* hash table for known domains */
int flags; /* a set of connection flags */ int flags; /* a set of connection flags */
}; };