diff options
author | Daniel Veillard <veillard@redhat.com> | 2006-04-05 09:31:29 +0000 |
---|---|---|
committer | Daniel Veillard <veillard@redhat.com> | 2006-04-05 09:31:29 +0000 |
commit | 6bd95bf2a3a4c1515a6afba2a487bbc1a322658b (patch) | |
tree | 576a41fa2abe048be6959e73759c2993bba1b2f5 | |
parent | virsh command names cleanup (diff) | |
download | libvirt-6bd95bf2a3a4c1515a6afba2a487bbc1a322658b.tar.gz libvirt-6bd95bf2a3a4c1515a6afba2a487bbc1a322658b.tar.bz2 libvirt-6bd95bf2a3a4c1515a6afba2a487bbc1a322658b.zip |
* 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
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/hash.c | 2 | ||||
-rw-r--r-- | src/internal.h | 4 | ||||
-rw-r--r-- | src/libvirt.c | 56 |
4 files changed, 47 insertions, 22 deletions
@@ -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, diff --git a/src/hash.c b/src/hash.c index 052f49e0f..65fb21b8a 100644 --- a/src/hash.c +++ b/src/hash.c @@ -17,8 +17,6 @@ * Author: breese@users.sourceforge.net */ -#define IN_LIBXML - #include <string.h> #include <stdlib.h> #include "hash.h" diff --git a/src/internal.h b/src/internal.h index 6cacaa20a..97d7d0ee6 100644 --- a/src/internal.h +++ b/src/internal.h @@ -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,7 +115,8 @@ struct _virConnect { void *userData; /* the user data */ /* misc */ - virHashTablePtr domains; /* hash table for known domains */ + 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 */ }; diff --git a/src/libvirt.c b/src/libvirt.c index b10c20629..048664700 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -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,27 +643,25 @@ 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; - - if (names != NULL) { - while (*tmp != NULL) { - ident = xenDaemonDomainLookupByName_ids(conn, *tmp, &uuid[0]); - if (ident == id) { - name = strdup(*tmp); - break; - } - tmp++; - } - free(names); - } + + /* path does not contain name, use xend API to retrieve name */ + names = xenDaemonListDomains(conn); + tmp = names; + + if (names != NULL) { + while (*tmp != NULL) { + ident = xenDaemonDomainLookupByName_ids(conn, *tmp, &uuid[0]); + if (ident == id) { + name = strdup(*tmp); + break; + } + tmp++; + } + free(names); } ret = (virDomainPtr) malloc(sizeof(virDomain)); |