]> xenbits.xensource.com Git - libvirt.git/commitdiff
* src/hash.c: tiny fix
authorDaniel Veillard <veillard@redhat.com>
Wed, 5 Apr 2006 09:31:29 +0000 (09:31 +0000)
committerDaniel Veillard <veillard@redhat.com>
Wed, 5 Apr 2006 09:31:29 +0000 (09:31 +0000)
* src/internal.h: starting to work on reentrancy
* src/libvirt.c: applied patch from Jim Fehlig to fix
  virDomainLookupByID when run as root.
Daniel

ChangeLog
src/hash.c
src/internal.h
src/libvirt.c

index a414ca7b5f58fe3d69c06d8faf4f71d245a6322d..10a297d8e20ab8d17151792f8b598fce37f24cb3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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, 
index 052f49e0fc89fbf318c33244491d2e0dfe5ea252..65fb21b8ac8f5baebbb5b04d4abb23e835611f06 100644 (file)
@@ -17,8 +17,6 @@
  * Author: breese@users.sourceforge.net
  */
 
-#define IN_LIBXML
-
 #include <string.h>
 #include <stdlib.h>
 #include "hash.h"
index 6cacaa20a16fbde95431cbaf51cce4c2531a79e4..97d7d0ee6f6e7093809a3e1f7b3e483944923663 100644 (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,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 */
 };
 
index b10c206293dae770cc74b9eddeaad8893ece25af..048664700224421f5df5e720c66b861eab2ced2c 100644 (file)
  * 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));