[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] PATCH: 13/25: Remove global state from XM driver



The 'xm' driver currently keeps all its state in a global static
variables. Not cool, since we access this from all sorts of places
and its hard to guarentee thread safety. So we move the state into
the virConnect object. This will increase memory usage if a single
process has multiple Xen connections open though.

Undecided whether this is a big problem or not. If so, I'll can
try and redo the next thread locking patch to use a lock over the
existing global state.

 xen_inotify.c |    4 
 xen_unified.c |    1 
 xen_unified.h |   14 ++-
 xm_internal.c |  262 +++++++++++++++++++++++++++++-----------------------------
 xm_internal.h |    3 
 5 files changed, 149 insertions(+), 135 deletions(-)

Daniel

diff --git a/src/xen_inotify.c b/src/xen_inotify.c
--- a/src/xen_inotify.c
+++ b/src/xen_inotify.c
@@ -383,9 +383,7 @@ xenInotifyOpen(virConnectPtr conn ATTRIB
     char path[PATH_MAX];
     xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
 
-    if(priv->xendConfigVersion <= 2) {
-        /* /etc/xen */
-        priv->configDir = xenXMGetConfigDir();
+    if (priv->configDir) {
         priv->useXenConfigCache = 1;
     } else {
         /* /var/lib/xend/domains/<uuid>/config.sxp */
diff --git a/src/xen_unified.c b/src/xen_unified.c
--- a/src/xen_unified.c
+++ b/src/xen_unified.c
@@ -1465,7 +1465,6 @@ xenRegister (void)
 {
     /* Ignore failures here. */
     (void) xenHypervisorInit ();
-    (void) xenXMInit ();
 
     return virRegisterDriver (&xenUnifiedDriver);
 }
diff --git a/src/xen_unified.h b/src/xen_unified.h
--- a/src/xen_unified.h
+++ b/src/xen_unified.h
@@ -20,6 +20,7 @@
 #include "xen_inotify.h"
 #endif
 #include "domain_event.h"
+#include "hash.h"
 
 #ifndef HAVE_WINSOCK2_H
 #include <sys/un.h>
@@ -163,15 +164,26 @@ struct _xenUnifiedPrivate {
     /* An list of callbacks */
     virDomainEventCallbackListPtr domainEventCallbacks;
 
+    /* Location of config files, either /etc
+     * or /var/lib/xen */
+    const char *configDir;
+
 #if WITH_XEN_INOTIFY
     /* The inotify fd */
     int inotifyFD;
     int inotifyWatch;
 
-    const char *configDir;
     int  useXenConfigCache ;
     xenUnifiedDomainInfoListPtr configInfoList;
 #endif
+
+    /* For the 'xm' driver */
+    /* Primary config file name -> virDomainDef map */
+    virHashTablePtr configCache;
+    /* Domain name to config file name */
+    virHashTablePtr nameConfigMap;
+    /* So we don't refresh too often */
+    time_t lastRefresh;
 };
 
 typedef struct _xenUnifiedPrivate *xenUnifiedPrivatePtr;
diff --git a/src/xm_internal.c b/src/xm_internal.c
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -56,15 +56,6 @@
 
 static int xenXMConfigSetString(virConfPtr conf, const char *setting,
                                 const char *str);
-
-static char configDir[PATH_MAX];
-/* Config file name to config object */
-static virHashTablePtr configCache = NULL;
-/* Name to config file name */
-static virHashTablePtr nameConfigMap = NULL;
-static int nconnections = 0;
-static time_t lastRefresh = 0;
-
 char * xenXMAutoAssignMac(void);
 static int xenXMDomainAttachDevice(virDomainPtr domain, const char *xml);
 static int xenXMDomainDetachDevice(virDomainPtr domain, const char *xml);
@@ -120,41 +111,10 @@ struct xenUnifiedDriver xenXMDriver = {
     NULL, /* domainSetSchedulerParameters */
 };
 
-virHashTablePtr xenXMGetConfigCache (void) {
-    return configCache;
-}
-
-char *xenXMGetConfigDir (void) {
-    return configDir;
-}
-
 #define xenXMError(conn, code, fmt...)                                       \
         virReportErrorHelper(conn, VIR_FROM_XENXM, code, __FILE__,         \
                                __FUNCTION__, __LINE__, fmt)
 
-int
-xenXMInit (void)
-{
-    char *envConfigDir;
-    int safeMode = 0;
-
-    /* Disable use of env variable if running setuid */
-    if ((geteuid() != getuid()) ||
-        (getegid() != getgid()))
-        safeMode = 1;
-
-    if (!safeMode &&
-        (envConfigDir = getenv("LIBVIRT_XM_CONFIG_DIR")) != NULL) {
-        strncpy(configDir, envConfigDir, PATH_MAX-1);
-        configDir[PATH_MAX-1] = '\0';
-    } else {
-        strcpy(configDir, XM_CONFIG_DIR);
-    }
-
-    return 0;
-}
-
-
 /* Convenience method to grab a int from the config file object */
 static int xenXMConfigGetBool(virConnectPtr conn,
                               virConfPtr conf,
@@ -328,19 +288,23 @@ static void xenXMConfigFree(void *payloa
     VIR_FREE(entry);
 }
 
+struct xenXMConfigReaperData {
+    xenUnifiedPrivatePtr priv;
+    time_t now;
+};
 
 /* Remove any configs which were not refreshed recently */
 static int xenXMConfigReaper(const void *payload, const char *key ATTRIBUTE_UNUSED, const void *data) {
-    time_t now = *(const time_t *)data;
+    const struct xenXMConfigReaperData *args = data;
     xenXMConfCachePtr entry = (xenXMConfCachePtr)payload;
 
     /* We're going to purge this config file, so check if it
        is currently mapped as owner of a named domain. */
-    if (entry->refreshedAt != now) {
+    if (entry->refreshedAt != args->now) {
         const char *olddomname = entry->def->name;
-        char *nameowner = (char *)virHashLookup(nameConfigMap, olddomname);
+        char *nameowner = (char *)virHashLookup(args->priv->nameConfigMap, olddomname);
         if (nameowner && STREQ(nameowner, key)) {
-            virHashRemoveEntry(nameConfigMap, olddomname, NULL);
+            virHashRemoveEntry(args->priv->nameConfigMap, olddomname, NULL);
         }
         return (1);
     }
@@ -376,19 +340,20 @@ xenXMConfigSaveFile(virConnectPtr conn, 
 }
 
 int
-xenXMConfigCacheRemoveFile(virConnectPtr conn ATTRIBUTE_UNUSED,
+xenXMConfigCacheRemoveFile(virConnectPtr conn,
                            const char *filename)
 {
+    xenUnifiedPrivatePtr priv = conn->privateData;
     xenXMConfCachePtr entry;
 
-    entry = virHashLookup(configCache, filename);
+    entry = virHashLookup(priv->configCache, filename);
     if (!entry) {
         DEBUG("No config entry for %s", filename);
         return 0;
     }
 
-    virHashRemoveEntry(nameConfigMap, entry->def->name, NULL);
-    virHashRemoveEntry(configCache, filename, xenXMConfigFree);
+    virHashRemoveEntry(priv->nameConfigMap, entry->def->name, NULL);
+    virHashRemoveEntry(priv->configCache, filename, xenXMConfigFree);
     DEBUG("Removed %s %s", entry->def->name, filename);
     return 0;
 }
@@ -397,6 +362,7 @@ xenXMConfigCacheRemoveFile(virConnectPtr
 int
 xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename)
 {
+    xenUnifiedPrivatePtr priv = conn->privateData;
     xenXMConfCachePtr entry;
     struct stat st;
     int newborn = 0;
@@ -421,7 +387,7 @@ xenXMConfigCacheAddFile(virConnectPtr co
 
     /* If we already have a matching entry and it is not
     modified, then carry on to next one*/
-    if ((entry = virHashLookup(configCache, filename))) {
+    if ((entry = virHashLookup(priv->configCache, filename))) {
         char *nameowner;
 
         if (entry->refreshedAt >= st.st_mtime) {
@@ -432,9 +398,9 @@ xenXMConfigCacheAddFile(virConnectPtr co
 
         /* If we currently own the name, then release it and
             re-acquire it later - just in case it was renamed */
-        nameowner = (char *)virHashLookup(nameConfigMap, entry->def->name);
+        nameowner = (char *)virHashLookup(priv->nameConfigMap, entry->def->name);
         if (nameowner && STREQ(nameowner, filename)) {
-            virHashRemoveEntry(nameConfigMap, entry->def->name, NULL);
+            virHashRemoveEntry(priv->nameConfigMap, entry->def->name, NULL);
         }
 
         /* Clear existing config entry which needs refresh */
@@ -453,7 +419,7 @@ xenXMConfigCacheAddFile(virConnectPtr co
     if (!(entry->def = xenXMConfigReadFile(conn, entry->filename))) {
         DEBUG("Failed to read %s", entry->filename);
         if (!newborn)
-            virHashRemoveEntry(configCache, filename, NULL);
+            virHashRemoveEntry(priv->configCache, filename, NULL);
         VIR_FREE(entry);
         return -1;
     }
@@ -461,7 +427,7 @@ xenXMConfigCacheAddFile(virConnectPtr co
     /* If its a completely new entry, it must be stuck into
         the cache (refresh'd entries are already registered) */
     if (newborn) {
-        if (virHashAddEntry(configCache, entry->filename, entry) < 0) {
+        if (virHashAddEntry(priv->configCache, entry->filename, entry) < 0) {
             virDomainDefFree(entry->def);
             VIR_FREE(entry);
             xenXMError (conn, VIR_ERR_INTERNAL_ERROR,
@@ -473,9 +439,9 @@ xenXMConfigCacheAddFile(virConnectPtr co
     /* See if we need to map this config file in as the primary owner
         * of the domain in question
         */
-    if (!virHashLookup(nameConfigMap, entry->def->name)) {
-        if (virHashAddEntry(nameConfigMap, entry->def->name, entry->filename) < 0) {
-            virHashRemoveEntry(configCache, filename, NULL);
+    if (!virHashLookup(priv->nameConfigMap, entry->def->name)) {
+        if (virHashAddEntry(priv->nameConfigMap, entry->def->name, entry->filename) < 0) {
+            virHashRemoveEntry(priv->configCache, filename, NULL);
             virDomainDefFree(entry->def);
             VIR_FREE(entry);
         }
@@ -491,10 +457,12 @@ xenXMConfigCacheAddFile(virConnectPtr co
    has rate-limited so never rescans more frequently than
    once every X seconds */
 int xenXMConfigCacheRefresh (virConnectPtr conn) {
+    xenUnifiedPrivatePtr priv = conn->privateData;
     DIR *dh;
     struct dirent *ent;
     time_t now = time(NULL);
     int ret = -1;
+    struct xenXMConfigReaperData args;
 
     if (now == ((time_t)-1)) {
         virReportSystemError(conn, errno,
@@ -503,16 +471,16 @@ int xenXMConfigCacheRefresh (virConnectP
     }
 
     /* Rate limit re-scans */
-    if ((now - lastRefresh) < XM_REFRESH_INTERVAL)
+    if ((now - priv->lastRefresh) < XM_REFRESH_INTERVAL)
         return (0);
 
-    lastRefresh = now;
+    priv->lastRefresh = now;
 
     /* Process the files in the config dir */
-    if (!(dh = opendir(configDir))) {
+    if (!(dh = opendir(priv->configDir))) {
         virReportSystemError(conn, errno,
                              _("cannot read directory %s"),
-                             configDir);
+                             priv->configDir);
         return (-1);
     }
 
@@ -547,9 +515,9 @@ int xenXMConfigCacheRefresh (virConnectP
             continue;
 
         /* Build the full file path */
-        if ((strlen(configDir) + 1 + strlen(ent->d_name) + 1) > PATH_MAX)
+        if ((strlen(priv->configDir) + 1 + strlen(ent->d_name) + 1) > PATH_MAX)
             continue;
-        strcpy(path, configDir);
+        strcpy(path, priv->configDir);
         strcat(path, "/");
         strcat(path, ent->d_name);
 
@@ -570,7 +538,9 @@ int xenXMConfigCacheRefresh (virConnectP
        their refresh timestamp - the timestamp should match
        'now' if they were refreshed. If timestamp doesn't match
        then the config is no longer on disk */
-    virHashRemoveSet(configCache, xenXMConfigReaper, xenXMConfigFree, (const void*) &now);
+    args.now = now;
+    args.priv = priv;
+    virHashRemoveSet(priv->configCache, xenXMConfigReaper, xenXMConfigFree, &args);
     ret = 0;
 
     if (dh)
@@ -587,26 +557,27 @@ int xenXMConfigCacheRefresh (virConnectP
  * to open all end up using the same cache of files
  */
 virDrvOpenStatus
-xenXMOpen (virConnectPtr conn ATTRIBUTE_UNUSED,
+xenXMOpen (virConnectPtr conn,
            virConnectAuthPtr auth ATTRIBUTE_UNUSED,
            int flags ATTRIBUTE_UNUSED)
 {
-    if (configCache == NULL) {
-        configCache = virHashCreate(50);
-        if (!configCache)
-            return (-1);
-        nameConfigMap = virHashCreate(50);
-        if (!nameConfigMap) {
-            virHashFree(configCache, NULL);
-            configCache = NULL;
-            return (-1);
-        }
-        /* Force the cache to be reloaded next time that
-         * xenXMConfigCacheRefresh is called.
-         */
-        lastRefresh = 0;
+    xenUnifiedPrivatePtr priv = conn->privateData;
+
+    priv->configDir = XM_CONFIG_DIR;
+
+    priv->configCache = virHashCreate(50);
+    if (!priv->configCache)
+        return (-1);
+    priv->nameConfigMap = virHashCreate(50);
+    if (!priv->nameConfigMap) {
+        virHashFree(priv->configCache, NULL);
+        priv->configCache = NULL;
+        return (-1);
     }
-    nconnections++;
+    /* Force the cache to be reloaded next time that
+     * xenXMConfigCacheRefresh is called.
+     */
+    priv->lastRefresh = 0;
 
     return (0);
 }
@@ -615,14 +586,12 @@ xenXMOpen (virConnectPtr conn ATTRIBUTE_
  * Free the config files in the cache if this is the
  * last connection
  */
-int xenXMClose(virConnectPtr conn ATTRIBUTE_UNUSED) {
-    nconnections--;
-    if (nconnections <= 0) {
-        virHashFree(nameConfigMap, NULL);
-        nameConfigMap = NULL;
-        virHashFree(configCache, xenXMConfigFree);
-        configCache = NULL;
-    }
+int xenXMClose(virConnectPtr conn) {
+    xenUnifiedPrivatePtr priv = conn->privateData;
+
+    virHashFree(priv->nameConfigMap, NULL);
+    virHashFree(priv->configCache, xenXMConfigFree);
+
     return (0);
 }
 
@@ -631,6 +600,7 @@ int xenXMClose(virConnectPtr conn ATTRIB
  * VCPUs and memory.
  */
 int xenXMDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) {
+    xenUnifiedPrivatePtr priv;
     const char *filename;
     xenXMConfCachePtr entry;
     if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
@@ -642,10 +612,12 @@ int xenXMDomainGetInfo(virDomainPtr doma
     if (domain->id != -1)
         return (-1);
 
-    if (!(filename = virHashLookup(nameConfigMap, domain->name)))
+    priv = domain->conn->privateData;
+
+    if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
         return (-1);
 
-    if (!(entry = virHashLookup(configCache, filename)))
+    if (!(entry = virHashLookup(priv->configCache, filename)))
         return (-1);
 
     memset(info, 0, sizeof(virDomainInfo));
@@ -1310,6 +1282,7 @@ no_memory:
  * domain, suitable for later feeding for virDomainCreateXML
  */
 char *xenXMDomainDumpXML(virDomainPtr domain, int flags) {
+    xenUnifiedPrivatePtr priv = domain->conn->privateData;
     const char *filename;
     xenXMConfCachePtr entry;
 
@@ -1321,10 +1294,12 @@ char *xenXMDomainDumpXML(virDomainPtr do
     if (domain->id != -1)
         return (NULL);
 
-    if (!(filename = virHashLookup(nameConfigMap, domain->name)))
+    priv = domain->conn->privateData;
+
+    if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
         return (NULL);
 
-    if (!(entry = virHashLookup(configCache, filename)))
+    if (!(entry = virHashLookup(priv->configCache, filename)))
         return (NULL);
 
     return virDomainDefFormat(domain->conn, entry->def, flags);
@@ -1335,6 +1310,7 @@ char *xenXMDomainDumpXML(virDomainPtr do
  * Update amount of memory in the config file
  */
 int xenXMDomainSetMemory(virDomainPtr domain, unsigned long memory) {
+    xenUnifiedPrivatePtr priv;
     const char *filename;
     xenXMConfCachePtr entry;
 
@@ -1350,10 +1326,12 @@ int xenXMDomainSetMemory(virDomainPtr do
     if (memory < 1024 * MIN_XEN_GUEST_SIZE)
         return (-1);
 
-    if (!(filename = virHashLookup(nameConfigMap, domain->name)))
+    priv = domain->conn->privateData;
+
+    if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
         return (-1);
 
-    if (!(entry = virHashLookup(configCache, filename)))
+    if (!(entry = virHashLookup(priv->configCache, filename)))
         return (-1);
 
     entry->def->memory = memory;
@@ -1373,6 +1351,7 @@ int xenXMDomainSetMemory(virDomainPtr do
  * Update maximum memory limit in config
  */
 int xenXMDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
+    xenUnifiedPrivatePtr priv;
     const char *filename;
     xenXMConfCachePtr entry;
 
@@ -1386,10 +1365,12 @@ int xenXMDomainSetMaxMemory(virDomainPtr
     if (domain->id != -1)
         return (-1);
 
-    if (!(filename = virHashLookup(nameConfigMap, domain->name)))
+    priv = domain->conn->privateData;
+
+    if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
         return (-1);
 
-    if (!(entry = virHashLookup(configCache, filename)))
+    if (!(entry = virHashLookup(priv->configCache, filename)))
         return (-1);
 
     entry->def->maxmem = memory;
@@ -1409,6 +1390,7 @@ int xenXMDomainSetMaxMemory(virDomainPtr
  * Get max memory limit from config
  */
 unsigned long xenXMDomainGetMaxMemory(virDomainPtr domain) {
+    xenUnifiedPrivatePtr priv;
     const char *filename;
     xenXMConfCachePtr entry;
 
@@ -1420,10 +1402,12 @@ unsigned long xenXMDomainGetMaxMemory(vi
     if (domain->id != -1)
         return (-1);
 
-    if (!(filename = virHashLookup(nameConfigMap, domain->name)))
+    priv = domain->conn->privateData;
+
+    if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
         return (-1);
 
-    if (!(entry = virHashLookup(configCache, filename)))
+    if (!(entry = virHashLookup(priv->configCache, filename)))
         return (-1);
 
     return entry->def->maxmem;
@@ -1433,6 +1417,7 @@ unsigned long xenXMDomainGetMaxMemory(vi
  * Set the VCPU count in config
  */
 int xenXMDomainSetVcpus(virDomainPtr domain, unsigned int vcpus) {
+    xenUnifiedPrivatePtr priv;
     const char *filename;
     xenXMConfCachePtr entry;
 
@@ -1446,10 +1431,12 @@ int xenXMDomainSetVcpus(virDomainPtr dom
     if (domain->id != -1)
         return (-1);
 
-    if (!(filename = virHashLookup(nameConfigMap, domain->name)))
+    priv = domain->conn->privateData;
+
+    if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
         return (-1);
 
-    if (!(entry = virHashLookup(configCache, filename)))
+    if (!(entry = virHashLookup(priv->configCache, filename)))
         return (-1);
 
     entry->def->vcpus = vcpus;
@@ -1478,6 +1465,7 @@ int xenXMDomainPinVcpu(virDomainPtr doma
                        unsigned int vcpu ATTRIBUTE_UNUSED,
                        unsigned char *cpumap, int maplen)
 {
+    xenUnifiedPrivatePtr priv;
     const char *filename;
     xenXMConfCachePtr entry;
     virBuffer mapbuf = VIR_BUFFER_INITIALIZER;
@@ -1504,11 +1492,13 @@ int xenXMDomainPinVcpu(virDomainPtr doma
         return -1;
     }
 
-    if (!(filename = virHashLookup(nameConfigMap, domain->name))) {
+    priv = domain->conn->privateData;
+
+    if (!(filename = virHashLookup(priv->nameConfigMap, domain->name))) {
         xenXMError (domain->conn, VIR_ERR_INTERNAL_ERROR, "%s", _("virHashLookup"));
         return -1;
     }
-    if (!(entry = virHashLookup(configCache, filename))) {
+    if (!(entry = virHashLookup(priv->configCache, filename))) {
         xenXMError (domain->conn, VIR_ERR_INTERNAL_ERROR,
                     "%s", _("can't retrieve config file for domain"));
         return -1;
@@ -1563,6 +1553,7 @@ int xenXMDomainPinVcpu(virDomainPtr doma
  * Find an inactive domain based on its name
  */
 virDomainPtr xenXMDomainLookupByName(virConnectPtr conn, const char *domname) {
+    xenUnifiedPrivatePtr priv;
     const char *filename;
     xenXMConfCachePtr entry;
     virDomainPtr ret;
@@ -1576,15 +1567,17 @@ virDomainPtr xenXMDomainLookupByName(vir
         return (NULL);
     }
 
+    priv = conn->privateData;
+
 #ifndef WITH_XEN_INOTIFY
     if (xenXMConfigCacheRefresh (conn) < 0)
         return (NULL);
 #endif
 
-    if (!(filename = virHashLookup(nameConfigMap, domname)))
+    if (!(filename = virHashLookup(priv->nameConfigMap, domname)))
         return (NULL);
 
-    if (!(entry = virHashLookup(configCache, filename))) {
+    if (!(entry = virHashLookup(priv->configCache, filename))) {
         return (NULL);
     }
 
@@ -1618,6 +1611,7 @@ static int xenXMDomainSearchForUUID(cons
  */
 virDomainPtr xenXMDomainLookupByUUID(virConnectPtr conn,
                                      const unsigned char *uuid) {
+    xenUnifiedPrivatePtr priv;
     xenXMConfCachePtr entry;
     virDomainPtr ret;
 
@@ -1630,12 +1624,14 @@ virDomainPtr xenXMDomainLookupByUUID(vir
         return (NULL);
     }
 
+    priv = conn->privateData;
+
 #ifndef WITH_XEN_INOTIFY
     if (xenXMConfigCacheRefresh (conn) < 0)
         return (NULL);
 #endif
 
-    if (!(entry = virHashSearch(configCache, xenXMDomainSearchForUUID, (const void *)uuid))) {
+    if (!(entry = virHashSearch(priv->configCache, xenXMDomainSearchForUUID, (const void *)uuid))) {
         return (NULL);
     }
 
@@ -1666,10 +1662,10 @@ int xenXMDomainCreate(virDomainPtr domai
     if (domain->id != -1)
         return (-1);
 
-    if (!(filename = virHashLookup(nameConfigMap, domain->name)))
+    if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
         return (-1);
 
-    if (!(entry = virHashLookup(configCache, filename)))
+    if (!(entry = virHashLookup(priv->configCache, filename)))
         return (-1);
 
     if (!(sexpr = xenDaemonFormatSxpr(domain->conn, entry->def, priv->xendConfigVersion))) {
@@ -2294,16 +2290,16 @@ virDomainPtr xenXMDomainDefineXML(virCon
                                         VIR_DOMAIN_XML_INACTIVE)))
         return (NULL);
 
-    if (virHashLookup(nameConfigMap, def->name)) {
+    if (virHashLookup(priv->nameConfigMap, def->name)) {
         /* domain exists, we will overwrite it */
 
-        if (!(oldfilename = (char *)virHashLookup(nameConfigMap, def->name))) {
+        if (!(oldfilename = (char *)virHashLookup(priv->nameConfigMap, def->name))) {
             xenXMError(conn, VIR_ERR_INTERNAL_ERROR,
                        "%s", _("can't retrieve config filename for domain to overwrite"));
             goto error;
         }
 
-        if (!(entry = virHashLookup(configCache, oldfilename))) {
+        if (!(entry = virHashLookup(priv->configCache, oldfilename))) {
             xenXMError(conn, VIR_ERR_INTERNAL_ERROR,
                        "%s", _("can't retrieve config entry for domain to overwrite"));
             goto error;
@@ -2314,14 +2310,14 @@ virDomainPtr xenXMDomainDefineXML(virCon
             goto error;
 
         /* Remove the name -> filename mapping */
-        if (virHashRemoveEntry(nameConfigMap, def->name, NULL) < 0) {
+        if (virHashRemoveEntry(priv->nameConfigMap, def->name, NULL) < 0) {
             xenXMError(conn, VIR_ERR_INTERNAL_ERROR,
                        "%s", _("failed to remove old domain from config map"));
             goto error;
         }
 
         /* Remove the config record itself */
-        if (virHashRemoveEntry(configCache, oldfilename, xenXMConfigFree) < 0) {
+        if (virHashRemoveEntry(priv->configCache, oldfilename, xenXMConfigFree) < 0) {
             xenXMError(conn, VIR_ERR_INTERNAL_ERROR,
                        "%s", _("failed to remove old domain from config map"));
             goto error;
@@ -2330,13 +2326,13 @@ virDomainPtr xenXMDomainDefineXML(virCon
         entry = NULL;
     }
 
-    if ((strlen(configDir) + 1 + strlen(def->name) + 1) > PATH_MAX) {
+    if ((strlen(priv->configDir) + 1 + strlen(def->name) + 1) > PATH_MAX) {
         xenXMError(conn, VIR_ERR_INTERNAL_ERROR,
                    "%s", _("config file name is too long"));
         goto error;
     }
 
-    strcpy(filename, configDir);
+    strcpy(filename, priv->configDir);
     strcat(filename, "/");
     strcat(filename, def->name);
 
@@ -2357,14 +2353,14 @@ virDomainPtr xenXMDomainDefineXML(virCon
     memmove(entry->filename, filename, PATH_MAX);
     entry->def = def;
 
-    if (virHashAddEntry(configCache, filename, entry) < 0) {
+    if (virHashAddEntry(priv->configCache, filename, entry) < 0) {
         xenXMError(conn, VIR_ERR_INTERNAL_ERROR,
                    "%s", _("unable to store config file handle"));
         goto error;
     }
 
-    if (virHashAddEntry(nameConfigMap, def->name, entry->filename) < 0) {
-        virHashRemoveEntry(configCache, filename, NULL);
+    if (virHashAddEntry(priv->nameConfigMap, def->name, entry->filename) < 0) {
+        virHashRemoveEntry(priv->configCache, filename, NULL);
         xenXMError(conn, VIR_ERR_INTERNAL_ERROR,
                    "%s", _("unable to store config file handle"));
         goto error;
@@ -2387,6 +2383,7 @@ virDomainPtr xenXMDomainDefineXML(virCon
  * Delete a domain from disk
  */
 int xenXMDomainUndefine(virDomainPtr domain) {
+    xenUnifiedPrivatePtr priv;
     const char *filename;
     xenXMConfCachePtr entry;
     if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
@@ -2400,21 +2397,23 @@ int xenXMDomainUndefine(virDomainPtr dom
     if (domain->conn->flags & VIR_CONNECT_RO)
         return (-1);
 
-    if (!(filename = virHashLookup(nameConfigMap, domain->name)))
+    priv = domain->conn->privateData;
+
+    if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
         return (-1);
 
-    if (!(entry = virHashLookup(configCache, filename)))
+    if (!(entry = virHashLookup(priv->configCache, filename)))
         return (-1);
 
     if (unlink(entry->filename) < 0)
         return (-1);
 
     /* Remove the name -> filename mapping */
-    if (virHashRemoveEntry(nameConfigMap, domain->name, NULL) < 0)
+    if (virHashRemoveEntry(priv->nameConfigMap, domain->name, NULL) < 0)
         return(-1);
 
     /* Remove the config record itself */
-    if (virHashRemoveEntry(configCache, entry->filename, xenXMConfigFree) < 0)
+    if (virHashRemoveEntry(priv->configCache, entry->filename, xenXMConfigFree) < 0)
         return (-1);
 
     return (0);
@@ -2449,6 +2448,7 @@ static void xenXMListIterator(const void
  * are currently running
  */
 int xenXMListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) {
+    xenUnifiedPrivatePtr priv;
     struct xenXMListIteratorContext ctx;
 
     if (!VIR_IS_CONNECT(conn)) {
@@ -2456,20 +2456,22 @@ int xenXMListDefinedDomains(virConnectPt
         return (-1);
     }
 
+    priv = conn->privateData;
+
 #ifndef WITH_XEN_INOTIFY
     if (xenXMConfigCacheRefresh (conn) < 0)
         return (-1);
 #endif
 
-    if (maxnames > virHashSize(configCache))
-        maxnames = virHashSize(configCache);
+    if (maxnames > virHashSize(priv->configCache))
+        maxnames = virHashSize(priv->configCache);
 
     ctx.conn = conn;
     ctx.count = 0;
     ctx.max = maxnames;
     ctx.names = names;
 
-    virHashForEach(nameConfigMap, xenXMListIterator, &ctx);
+    virHashForEach(priv->nameConfigMap, xenXMListIterator, &ctx);
     return (ctx.count);
 }
 
@@ -2478,17 +2480,21 @@ int xenXMListDefinedDomains(virConnectPt
  * based on number running
  */
 int xenXMNumOfDefinedDomains(virConnectPtr conn) {
+    xenUnifiedPrivatePtr priv;
+
     if (!VIR_IS_CONNECT(conn)) {
         xenXMError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
         return (-1);
     }
 
+    priv = conn->privateData;
+
 #ifndef WITH_XEN_INOTIFY
     if (xenXMConfigCacheRefresh (conn) < 0)
         return (-1);
 #endif
 
-    return virHashSize(nameConfigMap);
+    return virHashSize(priv->nameConfigMap);
 }
 
 
@@ -2524,9 +2530,9 @@ xenXMDomainAttachDevice(virDomainPtr dom
     if (domain->id != -1)
         return -1;
 
-    if (!(filename = virHashLookup(nameConfigMap, domain->name)))
+    if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
         return -1;
-    if (!(entry = virHashLookup(configCache, filename)))
+    if (!(entry = virHashLookup(priv->configCache, filename)))
         return -1;
     def = entry->def;
 
@@ -2613,9 +2619,9 @@ xenXMDomainDetachDevice(virDomainPtr dom
         return -1;
     if (domain->id != -1)
         return -1;
-    if (!(filename = virHashLookup(nameConfigMap, domain->name)))
+    if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
         return -1;
-    if (!(entry = virHashLookup(configCache, filename)))
+    if (!(entry = virHashLookup(priv->configCache, filename)))
         return -1;
     def = entry->def;
 
diff --git a/src/xm_internal.h b/src/xm_internal.h
--- a/src/xm_internal.h
+++ b/src/xm_internal.h
@@ -31,10 +31,9 @@
 #include "domain_conf.h"
 
 extern struct xenUnifiedDriver xenXMDriver;
-int xenXMInit (void);
 
 virHashTablePtr xenXMGetConfigCache(void);
-char *xenXMGetConfigDir(void);
+
 int xenXMConfigCacheRefresh (virConnectPtr conn);
 int xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename);
 int xenXMConfigCacheRemoveFile(virConnectPtr conn, const char *filename);

-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]