提交 d9f19c30 编写于 作者: J Jim Fehlig

libxl: Introduce libxlDriverConfig object

The libxlDriverPrivate struct contains an variety of data with
varying access needs. Similar to the QEMU and LXC drivers,
move all the static config data into a dedicated libxlDriverConfig
object. The only locking requirement is to hold the driver lock
while obtaining an instance of libxlDriverConfig. Once a reference
is held on the config object, it can be used completely lockless
since it is immutable.
上级 41475876
...@@ -64,6 +64,41 @@ static const char *xen_cap_re = "(xen|hvm)-[[:digit:]]+\\.[[:digit:]]+-(x86_32|x ...@@ -64,6 +64,41 @@ static const char *xen_cap_re = "(xen|hvm)-[[:digit:]]+\\.[[:digit:]]+-(x86_32|x
static regex_t xen_cap_rec; static regex_t xen_cap_rec;
static virClassPtr libxlDriverConfigClass;
static void libxlDriverConfigDispose(void *obj);
static int libxlConfigOnceInit(void)
{
if (!(libxlDriverConfigClass = virClassNew(virClassForObject(),
"libxlDriverConfig",
sizeof(libxlDriverConfig),
libxlDriverConfigDispose)))
return -1;
return 0;
}
VIR_ONCE_GLOBAL_INIT(libxlConfig)
static void
libxlDriverConfigDispose(void *obj)
{
libxlDriverConfigPtr cfg = obj;
virObjectUnref(cfg->caps);
libxl_ctx_free(cfg->ctx);
xtl_logger_destroy(cfg->logger);
if (cfg->logger_file)
VIR_FORCE_FCLOSE(cfg->logger_file);
VIR_FREE(cfg->configDir);
VIR_FREE(cfg->autostartDir);
VIR_FREE(cfg->logDir);
VIR_FREE(cfg->stateDir);
VIR_FREE(cfg->libDir);
VIR_FREE(cfg->saveDir);
}
static int static int
libxlCapsInitHost(libxl_ctx *ctx, virCapsPtr caps) libxlCapsInitHost(libxl_ctx *ctx, virCapsPtr caps)
{ {
...@@ -978,8 +1013,8 @@ error: ...@@ -978,8 +1013,8 @@ error:
return -1; return -1;
} }
bool static bool
libxlGetAutoballoonConf(libxlDriverPrivatePtr driver) libxlGetAutoballoonConf(libxlDriverConfigPtr cfg)
{ {
regex_t regex; regex_t regex;
int ret; int ret;
...@@ -990,11 +1025,94 @@ libxlGetAutoballoonConf(libxlDriverPrivatePtr driver) ...@@ -990,11 +1025,94 @@ libxlGetAutoballoonConf(libxlDriverPrivatePtr driver)
if (ret) if (ret)
return true; return true;
ret = regexec(&regex, driver->verInfo->commandline, 0, NULL, 0); ret = regexec(&regex, cfg->verInfo->commandline, 0, NULL, 0);
regfree(&regex); regfree(&regex);
return ret == REG_NOMATCH; return ret == REG_NOMATCH;
} }
libxlDriverConfigPtr
libxlDriverConfigNew(void)
{
libxlDriverConfigPtr cfg;
char *log_file = NULL;
char ebuf[1024];
unsigned int free_mem;
if (libxlConfigInitialize() < 0)
return NULL;
if (!(cfg = virObjectNew(libxlDriverConfigClass)))
return NULL;
if (VIR_STRDUP(cfg->configDir, LIBXL_CONFIG_DIR) < 0)
goto error;
if (VIR_STRDUP(cfg->autostartDir, LIBXL_AUTOSTART_DIR) < 0)
goto error;
if (VIR_STRDUP(cfg->logDir, LIBXL_LOG_DIR) < 0)
goto error;
if (VIR_STRDUP(cfg->stateDir, LIBXL_STATE_DIR) < 0)
goto error;
if (VIR_STRDUP(cfg->libDir, LIBXL_LIB_DIR) < 0)
goto error;
if (VIR_STRDUP(cfg->saveDir, LIBXL_SAVE_DIR) < 0)
goto error;
if (virAsprintf(&log_file, "%s/libxl-driver.log", cfg->logDir) < 0)
goto error;
if ((cfg->logger_file = fopen(log_file, "a")) == NULL) {
VIR_ERROR(_("Failed to create log file '%s': %s"),
log_file, virStrerror(errno, ebuf, sizeof(ebuf)));
goto error;
}
VIR_FREE(log_file);
cfg->logger =
(xentoollog_logger *)xtl_createlogger_stdiostream(cfg->logger_file,
XTL_DEBUG, 0);
if (!cfg->logger) {
VIR_ERROR(_("cannot create logger for libxenlight, disabling driver"));
goto error;
}
if (libxl_ctx_alloc(&cfg->ctx, LIBXL_VERSION, 0, cfg->logger)) {
VIR_ERROR(_("cannot initialize libxenlight context, probably not "
"running in a Xen Dom0, disabling driver"));
goto error;
}
if ((cfg->verInfo = libxl_get_version_info(cfg->ctx)) == NULL) {
VIR_ERROR(_("cannot version information from libxenlight, "
"disabling driver"));
goto error;
}
cfg->version = (cfg->verInfo->xen_version_major * 1000000) +
(cfg->verInfo->xen_version_minor * 1000);
/* This will fill xenstore info about free and dom0 memory if missing,
* should be called before starting first domain */
if (libxl_get_free_memory(cfg->ctx, &free_mem)) {
VIR_ERROR(_("Unable to configure libxl's memory management parameters"));
goto error;
}
/* setup autoballoon */
cfg->autoballoon = libxlGetAutoballoonConf(cfg);
return cfg;
error:
VIR_FREE(log_file);
virObjectUnref(cfg);
return NULL;
}
libxlDriverConfigPtr
libxlDriverConfigGet(libxlDriverPrivatePtr driver)
{
return virObjectRef(driver->config);
}
virCapsPtr virCapsPtr
libxlMakeCapabilities(libxl_ctx *ctx) libxlMakeCapabilities(libxl_ctx *ctx)
{ {
......
...@@ -51,10 +51,13 @@ ...@@ -51,10 +51,13 @@
typedef struct _libxlDriverPrivate libxlDriverPrivate; typedef struct _libxlDriverPrivate libxlDriverPrivate;
typedef libxlDriverPrivate *libxlDriverPrivatePtr; typedef libxlDriverPrivate *libxlDriverPrivatePtr;
struct _libxlDriverPrivate {
virMutex lock; typedef struct _libxlDriverConfig libxlDriverConfig;
virCapsPtr caps; typedef libxlDriverConfig *libxlDriverConfigPtr;
virDomainXMLOptionPtr xmlopt;
struct _libxlDriverConfig {
virObject parent;
const libxl_version_info *verInfo; const libxl_version_info *verInfo;
unsigned int version; unsigned int version;
...@@ -64,27 +67,43 @@ struct _libxlDriverPrivate { ...@@ -64,27 +67,43 @@ struct _libxlDriverPrivate {
/* libxl ctx for driver wide ops; getVersion, getNodeInfo, ... */ /* libxl ctx for driver wide ops; getVersion, getNodeInfo, ... */
libxl_ctx *ctx; libxl_ctx *ctx;
virPortAllocatorPtr reservedVNCPorts;
/* Controls automatic ballooning of domain0. If true, attempt to get /* Controls automatic ballooning of domain0. If true, attempt to get
* memory for new domains from domain0. */ * memory for new domains from domain0. */
bool autoballoon; bool autoballoon;
/* Once created, caps are immutable */
virCapsPtr caps;
char *configDir;
char *autostartDir;
char *logDir;
char *stateDir;
char *libDir;
char *saveDir;
};
struct _libxlDriverPrivate {
virMutex lock;
/* Require lock to get reference on 'config',
* then lockless thereafter */
libxlDriverConfigPtr config;
size_t nactive; size_t nactive;
virStateInhibitCallback inhibitCallback; virStateInhibitCallback inhibitCallback;
void *inhibitOpaque; void *inhibitOpaque;
virDomainObjListPtr domains; virDomainObjListPtr domains;
virDomainXMLOptionPtr xmlopt;
virDomainEventStatePtr domainEventState; virDomainEventStatePtr domainEventState;
virSysinfoDefPtr hostsysinfo;
char *configDir; virPortAllocatorPtr reservedVNCPorts;
char *autostartDir;
char *logDir; virSysinfoDefPtr hostsysinfo;
char *stateDir;
char *libDir;
char *saveDir;
}; };
typedef struct _libxlEventHookInfo libxlEventHookInfo; typedef struct _libxlEventHookInfo libxlEventHookInfo;
...@@ -103,8 +122,11 @@ struct _libxlSavefileHeader { ...@@ -103,8 +122,11 @@ struct _libxlSavefileHeader {
uint32_t unused[10]; uint32_t unused[10];
}; };
bool libxlDriverConfigPtr
libxlGetAutoballoonConf(libxlDriverPrivatePtr driver); libxlDriverConfigNew(void);
libxlDriverConfigPtr
libxlDriverConfigGet(libxlDriverPrivatePtr driver);
virCapsPtr virCapsPtr
libxlMakeCapabilities(libxl_ctx *ctx); libxlMakeCapabilities(libxl_ctx *ctx);
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册