提交 54a401af 编写于 作者: J Ján Tomko

libxl: split out DriverConfigInit out of DriverConfigNew

Take the parts affected by the host state out of DriverConfigNew
and put them into a separate function.

Adjust all the callers to call both functions.
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NJim Fehlig <jfehlig@suse.com>
上级 fffb1226
......@@ -1686,8 +1686,6 @@ libxlDriverConfigPtr
libxlDriverConfigNew(void)
{
libxlDriverConfigPtr cfg;
char ebuf[1024];
unsigned int free_mem;
if (libxlConfigInitialize() < 0)
return NULL;
......@@ -1705,41 +1703,6 @@ libxlDriverConfigNew(void)
cfg->autoDumpDir = g_strdup(LIBXL_DUMP_DIR);
cfg->channelDir = g_strdup(LIBXL_CHANNEL_DIR);
if (virFileMakePath(cfg->logDir) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to create log dir '%s': %s"),
cfg->logDir,
virStrerror(errno, ebuf, sizeof(ebuf)));
goto error;
}
cfg->logger = libxlLoggerNew(cfg->logDir, virLogGetDefaultPriority());
if (!cfg->logger) {
VIR_ERROR(_("cannot create logger for libxenlight, disabling driver"));
goto error;
}
if (libxl_ctx_alloc(&cfg->ctx, LIBXL_VERSION, 0, (xentoollog_logger *)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;
}
#ifdef DEFAULT_LOADER_NVRAM
if (virFirmwareParseList(DEFAULT_LOADER_NVRAM,
&cfg->firmwares,
......@@ -1774,6 +1737,50 @@ libxlDriverConfigNew(void)
return NULL;
}
int
libxlDriverConfigInit(libxlDriverConfigPtr cfg)
{
char ebuf[1024];
unsigned int free_mem;
if (virFileMakePath(cfg->logDir) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to create log dir '%s': %s"),
cfg->logDir,
virStrerror(errno, ebuf, sizeof(ebuf)));
return -1;
}
cfg->logger = libxlLoggerNew(cfg->logDir, virLogGetDefaultPriority());
if (!cfg->logger) {
VIR_ERROR(_("cannot create logger for libxenlight, disabling driver"));
return -1;
}
if (libxl_ctx_alloc(&cfg->ctx, LIBXL_VERSION, 0, (xentoollog_logger *)cfg->logger)) {
VIR_ERROR(_("cannot initialize libxenlight context, probably not "
"running in a Xen Dom0, disabling driver"));
return -1;
}
if ((cfg->verInfo = libxl_get_version_info(cfg->ctx)) == NULL) {
VIR_ERROR(_("cannot version information from libxenlight, "
"disabling driver"));
return -1;
}
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"));
return -1;
}
return 0;
}
libxlDriverConfigPtr
libxlDriverConfigGet(libxlDriverPrivatePtr driver)
{
......
......@@ -164,6 +164,8 @@ struct _libxlSavefileHeader {
libxlDriverConfigPtr
libxlDriverConfigNew(void);
int
libxlDriverConfigInit(libxlDriverConfigPtr cfg);
libxlDriverConfigPtr
libxlDriverConfigGet(libxlDriverPrivatePtr driver);
......
......@@ -708,6 +708,9 @@ libxlStateInitialize(bool privileged,
if (libxlDriverConfigLoadFile(cfg, driverConf) < 0)
goto error;
if (libxlDriverConfigInit(cfg) < 0)
goto error;
/* Register the callbacks providing access to libvirt's event loop */
libxl_osevent_register_hooks(cfg->ctx, &libxl_osevent_callbacks, cfg->ctx);
......
......@@ -97,6 +97,9 @@ libxlDriverPrivatePtr testXLInitDriver(void)
if (!(driver->config = libxlDriverConfigNew()))
return NULL;
if (libxlDriverConfigInit(driver->config) < 0)
return NULL;
driver->config->caps = testXLInitCaps();
driver->xmlopt = libxlCreateXMLConf(driver);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册