* src/hash.c: tiny fix

* src/internal.h: starting to work on reentrancy
* src/libvirt.c: applied patch from Jim Fehlig to fix
  virDomainLookupByID when run as root.
Daniel
This commit is contained in:
Daniel Veillard 2006-04-05 09:31:29 +00:00
parent 48e85b5c41
commit 6bd95bf2a3
4 changed files with 46 additions and 21 deletions

View File

@ -1,3 +1,10 @@
Wed Apr 5 09:32:54 EDT 2006 Daniel Veillard <veillard@redhat.com>
* src/hash.c: tiny fix
* src/internal.h: starting to work on reentrancy
* src/libvirt.c: applied patch from Jim Fehlig to fix
virDomainLookupByID when run as root.
Tue Apr 4 22:49:33 CEST 2006 Karel Zak <kzak@redhat.com>
* src/virsh.c: rename dstate, idof and nameof to domstate,

View File

@ -17,8 +17,6 @@
* Author: breese@users.sourceforge.net
*/
#define IN_LIBXML
#include <string.h>
#include <stdlib.h>
#include "hash.h"

View File

@ -10,6 +10,7 @@
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <libxml/threads.h>
#include "hash.h"
#include "libvirt.h"
@ -114,6 +115,7 @@ struct _virConnect {
void *userData; /* the user data */
/* misc */
xmlMutexPtr domains_mux;/* a mutex to protect the domain hash table */
virHashTablePtr domains;/* hash table for known domains */
int flags; /* a set of connection flags */
};

View File

@ -33,10 +33,11 @@
* TODO:
* - use lock to protect against concurrent accesses ?
* - use reference counting to garantee coherent pointer state ?
* - error reporting layer
* - memory wrappers for malloc/free ?
*/
static int virDomainFreeName(virDomainPtr domain, const char *name);
static virDriverPtr virDriverTab[MAX_DRIVERS];
static int initialized = 0;
@ -254,6 +255,9 @@ virConnectOpen(const char *name)
ret->domains = virHashCreate(20);
if (ret->domains == NULL)
goto failed;
ret->domains_mux = xmlNewMutex();
if (ret->domains_mux == NULL)
goto failed;
ret->flags = 0;
return (ret);
@ -264,6 +268,10 @@ failed:
if ((ret->drivers[i] != NULL) && (ret->drivers[i]->close != NULL))
ret->drivers[i]->close(ret);
}
if (ret->domains != NULL)
virHashFree(ret->domains, (virHashDeallocator) virDomainFreeName);
if (ret->domains_mux != NULL)
xmlFreeMutex(ret->domains_mux);
free(ret);
}
return (NULL);
@ -318,6 +326,9 @@ virConnectOpenReadOnly(const char *name)
ret->domains = virHashCreate(20);
if (ret->domains == NULL)
goto failed;
ret->domains_mux = xmlNewMutex();
if (ret->domains_mux == NULL)
goto failed;
ret->flags = VIR_CONNECT_RO;
return (ret);
@ -328,6 +339,10 @@ failed:
if ((ret->drivers[i] != NULL) && (ret->drivers[i]->close != NULL))
ret->drivers[i]->close(ret);
}
if (ret->domains != NULL)
virHashFree(ret->domains, (virHashDeallocator) virDomainFreeName);
if (ret->domains_mux != NULL)
xmlFreeMutex(ret->domains_mux);
free(ret);
}
return (NULL);
@ -367,6 +382,8 @@ virConnectClose(virConnectPtr conn)
return (-1);
virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
conn->domains = NULL;
xmlFreeMutex(conn->domains_mux);
conn->domains_mux = NULL;
for (i = 0;i < conn->nb_drivers;i++) {
if ((conn->drivers[i] != NULL) && (conn->drivers[i]->close != NULL))
conn->drivers[i]->close(conn);
@ -610,6 +627,9 @@ virDomainPtr
virDomainLookupByID(virConnectPtr conn, int id)
{
char *path = NULL;
char **names;
char **tmp;
int ident;
virDomainPtr ret;
char *name = NULL;
unsigned char uuid[16];
@ -623,15 +643,14 @@ virDomainLookupByID(virConnectPtr conn, int id)
return (NULL);
}
/* lookup is easier with the Xen store so try it first */
/* retrieve home path of the domain */
if (conn->xshandle != NULL) {
path = xs_get_domain_path(conn->xshandle, (unsigned int) id);
}
/* fallback to xend API then */
if (path == NULL) {
char **names = xenDaemonListDomains(conn);
char **tmp = names;
int ident;
/* path does not contain name, use xend API to retrieve name */
names = xenDaemonListDomains(conn);
tmp = names;
if (names != NULL) {
while (*tmp != NULL) {
@ -644,7 +663,6 @@ virDomainLookupByID(virConnectPtr conn, int id)
}
free(names);
}
}
ret = (virDomainPtr) malloc(sizeof(virDomain));
if (ret == NULL) {