#include <time.h>
#include <sys/stat.h>
#include <limits.h>
+#include <string.h>
+#include <errno.h>
#include <unistd.h>
#include <stdint.h>
environment variable) and process any domain configs. It
has rate-limited so never rescans more frequently than
once every X seconds */
-static int xenXMConfigCacheRefresh(void) {
+static int xenXMConfigCacheRefresh (virConnectPtr conn) {
DIR *dh;
struct dirent *ent;
time_t now = time(NULL);
int ret = -1;
if (now == ((time_t)-1)) {
+ xenXMError (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
return (-1);
}
/* Process the files in the config dir */
if (!(dh = opendir(configDir))) {
+ xenXMError (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
return (-1);
}
} else { /* Completely new entry */
newborn = 1;
if (!(entry = malloc(sizeof(xenXMConfCache)))) {
+ xenXMError (conn, VIR_ERR_NO_MEMORY, strerror (errno));
goto cleanup;
}
memcpy(entry->filename, path, PATH_MAX);
virHashRemoveEntry(configCache, path, NULL);
}
free(entry);
+ xenXMError (conn, VIR_ERR_INTERNAL_ERROR, "xenXMConfigCacheRefresh: name");
goto cleanup;
}
if (virHashAddEntry(configCache, entry->filename, entry) < 0) {
virConfFree(entry->conf);
free(entry);
+ xenXMError (conn, VIR_ERR_INTERNAL_ERROR, "xenXMConfigCacheRefresh: virHashAddEntry");
goto cleanup;
}
}
xenXMOpen (virConnectPtr conn ATTRIBUTE_UNUSED,
const char *name ATTRIBUTE_UNUSED, int flags ATTRIBUTE_UNUSED)
{
- if (nconnections == 0) {
+ if (configCache == NULL) {
configCache = virHashCreate(50);
if (!configCache)
return (-1);
configCache = NULL;
return (-1);
}
+ /* Force the cache to be reloaded next time that
+ * xenXMConfigCacheRefresh is called.
+ */
+ lastRefresh = 0;
}
nconnections++;
* last connection
*/
int xenXMClose(virConnectPtr conn ATTRIBUTE_UNUSED) {
- if (!nconnections--) {
+ nconnections--;
+ if (nconnections <= 0) {
virHashFree(nameConfigMap, NULL);
nameConfigMap = NULL;
virHashFree(configCache, xenXMConfigFree);
return (NULL);
}
- if (xenXMConfigCacheRefresh() < 0)
+ if (xenXMConfigCacheRefresh (conn) < 0)
return (NULL);
if (!(filename = virHashLookup(nameConfigMap, domname)))
return (NULL);
}
- if (xenXMConfigCacheRefresh() < 0)
+ if (xenXMConfigCacheRefresh (conn) < 0)
return (NULL);
if (!(entry = virHashSearch(configCache, xenXMDomainSearchForUUID, (const void *)uuid))) {
if (conn->flags & VIR_CONNECT_RO)
return (NULL);
- if (xenXMConfigCacheRefresh() < 0)
+ if (xenXMConfigCacheRefresh (conn) < 0)
return (NULL);
if (!(conf = xenXMParseXMLToConfig(conn, xml)))
return (-1);
}
- if (xenXMConfigCacheRefresh() < 0)
+ if (xenXMConfigCacheRefresh (conn) < 0)
return (-1);
if (maxnames > virHashSize(configCache))
return (-1);
}
- if (xenXMConfigCacheRefresh() < 0)
+ if (xenXMConfigCacheRefresh (conn) < 0)
return (-1);
return virHashSize(nameConfigMap);