From 54a401af4780a7ebf70482bfe4736ff10c61586a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Sat, 22 Feb 2020 13:01:38 +0100 Subject: [PATCH] libxl: split out DriverConfigInit out of DriverConfigNew MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Ján Tomko Reviewed-by: Jim Fehlig --- src/libxl/libxl_conf.c | 81 ++++++++++++++++++++++------------------ src/libxl/libxl_conf.h | 2 + src/libxl/libxl_driver.c | 3 ++ tests/testutilsxen.c | 3 ++ 4 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 9c722342ba..907df525c5 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -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) { diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index b61c52f1a5..07b3373170 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -164,6 +164,8 @@ struct _libxlSavefileHeader { libxlDriverConfigPtr libxlDriverConfigNew(void); +int +libxlDriverConfigInit(libxlDriverConfigPtr cfg); libxlDriverConfigPtr libxlDriverConfigGet(libxlDriverPrivatePtr driver); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 5de3bcd2a6..f2387e2a20 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -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); diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c index 76da33826c..b1260dcebf 100644 --- a/tests/testutilsxen.c +++ b/tests/testutilsxen.c @@ -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); -- GitLab