]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
libxl: split out DriverConfigInit out of DriverConfigNew
authorJán Tomko <jtomko@redhat.com>
Sat, 22 Feb 2020 12:01:38 +0000 (13:01 +0100)
committerJán Tomko <jtomko@redhat.com>
Tue, 25 Feb 2020 11:05:00 +0000 (12:05 +0100)
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 <jtomko@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
src/libxl/libxl_conf.c
src/libxl/libxl_conf.h
src/libxl/libxl_driver.c
tests/testutilsxen.c

index 9c722342ba6f9cc6729b956c74c4f68a045f94ab..907df525c5455307960422f40a0b14595ef087bd 100644 (file)
@@ -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)
 {
index b61c52f1a55ad3af288c9980c5a4fd97d788365f..07b33731708fa88dfb88def94319d5d2a036dd3f 100644 (file)
@@ -164,6 +164,8 @@ struct _libxlSavefileHeader {
 
 libxlDriverConfigPtr
 libxlDriverConfigNew(void);
+int
+libxlDriverConfigInit(libxlDriverConfigPtr cfg);
 
 libxlDriverConfigPtr
 libxlDriverConfigGet(libxlDriverPrivatePtr driver);
index 5de3bcd2a6379917cce3b8ddbb5f8e1b209418e8..f2387e2a20601ed3e03038a7dca67fd5eefadacc 100644 (file)
@@ -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);
 
index 76da33826c6cbc2dd5dbaa3f8ee25e4dcd1c09d5..b1260dcebff1620afa1cf22539bbaf20f11c3866 100644 (file)
@@ -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);