[PATCH 1/2] qemu_conf: Move paths initialization to qemudLoadDriverConfig

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is needed as next patch allows their
modification via qemu.conf.
---
 src/qemu/qemu_conf.c   |   51 ++++++++++++++++++++++++-
 src/qemu/qemu_conf.h   |    4 +-
 src/qemu/qemu_driver.c |  101 ++++++++++++++----------------------------------
 3 files changed, 82 insertions(+), 74 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index e95c7a5..a22f3c7 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -67,7 +67,9 @@ void qemuDriverUnlock(struct qemud_driver *driver)
 
 
 int qemudLoadDriverConfig(struct qemud_driver *driver,
-                          const char *filename) {
+                          const char *filename,
+                          const char *userdir,
+                          const char *base) {
     virConfPtr conf;
     virConfValuePtr p;
     char *user;
@@ -486,6 +488,53 @@ int qemudLoadDriverConfig(struct qemud_driver *driver,
     CHECK_TYPE("keepalive_count", VIR_CONF_LONG);
     if (p) driver->keepAliveCount = p->l;
 
+
+    if (driver->privileged) {
+        if (virAsprintf(&driver->logDir,
+                        "%s/log/libvirt/qemu", LOCALSTATEDIR) == -1)
+            goto out_of_memory;
+
+        if (virAsprintf(&driver->stateDir,
+                      "%s/run/libvirt/qemu", LOCALSTATEDIR) == -1)
+            goto out_of_memory;
+
+        if (virAsprintf(&driver->libDir,
+                      "%s/lib/libvirt/qemu", LOCALSTATEDIR) == -1)
+            goto out_of_memory;
+
+        if (virAsprintf(&driver->cacheDir,
+                      "%s/cache/libvirt/qemu", LOCALSTATEDIR) == -1)
+            goto out_of_memory;
+        if (virAsprintf(&driver->saveDir,
+                      "%s/lib/libvirt/qemu/save", LOCALSTATEDIR) == -1)
+            goto out_of_memory;
+        if (virAsprintf(&driver->snapshotDir,
+                        "%s/lib/libvirt/qemu/snapshot", LOCALSTATEDIR) == -1)
+            goto out_of_memory;
+        if (virAsprintf(&driver->autoDumpPath,
+                        "%s/lib/libvirt/qemu/dump", LOCALSTATEDIR) == -1)
+            goto out_of_memory;
+    } else {
+        if (virAsprintf(&driver->logDir,
+                        "%s/.libvirt/qemu/log", userdir) == -1)
+            goto out_of_memory;
+        if (virAsprintf(&driver->stateDir, "%s/qemu/run", base) == -1)
+            goto out_of_memory;
+        if (virAsprintf(&driver->libDir, "%s/qemu/lib", base) == -1)
+            goto out_of_memory;
+        if (virAsprintf(&driver->cacheDir, "%s/qemu/cache", base) == -1)
+            goto out_of_memory;
+        if (virAsprintf(&driver->saveDir, "%s/qemu/save", base) == -1)
+            goto out_of_memory;
+        if (virAsprintf(&driver->snapshotDir, "%s/qemu/snapshot", base) == -1)
+            goto out_of_memory;
+        if (virAsprintf(&driver->autoDumpPath, "%s/qemu/dump", base) == -1)
+            goto out_of_memory;
+    }
     virConfFree (conf);
     return 0;
+
+out_of_memory:
+    virReportOOMError();
+    return -1;
 }
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 36f1c4c..186404b 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -171,7 +171,9 @@ struct _qemuDomainCmdlineDef {
 void qemuDriverLock(struct qemud_driver *driver);
 void qemuDriverUnlock(struct qemud_driver *driver);
 int qemudLoadDriverConfig(struct qemud_driver *driver,
-                          const char *filename);
+                          const char *filename,
+                          const char *userdir,
+                          const char *base);
 
 struct qemuDomainDiskInfo {
     bool removable;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c6bdd29..7e11d15 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -420,6 +420,7 @@ cleanup:
 static int
 qemudStartup(int privileged) {
     char *base = NULL;
+    char *userdir = NULL;
     char *driverConf = NULL;
     int rc;
     virConnectPtr conn = NULL;
@@ -451,70 +452,47 @@ qemudStartup(int privileged) {
          virBitmapAlloc(QEMU_VNC_PORT_MAX - QEMU_VNC_PORT_MIN)) == NULL)
         goto out_of_memory;
 
-    /* read the host sysinfo */
-    if (privileged)
-        qemu_driver->hostsysinfo = virSysinfoRead();
-
+    /* Configuration paths are either ~/.libvirt/qemu/... (session) or
+     * /etc/libvirt/qemu/... (system).
+     */
     if (privileged) {
-        if (virAsprintf(&qemu_driver->logDir,
-                        "%s/log/libvirt/qemu", LOCALSTATEDIR) == -1)
-            goto out_of_memory;
-
         if ((base = strdup (SYSCONFDIR "/libvirt")) == NULL)
             goto out_of_memory;
-
-        if (virAsprintf(&qemu_driver->stateDir,
-                      "%s/run/libvirt/qemu", LOCALSTATEDIR) == -1)
-            goto out_of_memory;
-
-        if (virAsprintf(&qemu_driver->libDir,
-                      "%s/lib/libvirt/qemu", LOCALSTATEDIR) == -1)
-            goto out_of_memory;
-
-        if (virAsprintf(&qemu_driver->cacheDir,
-                      "%s/cache/libvirt/qemu", LOCALSTATEDIR) == -1)
-            goto out_of_memory;
-        if (virAsprintf(&qemu_driver->saveDir,
-                      "%s/lib/libvirt/qemu/save", LOCALSTATEDIR) == -1)
-            goto out_of_memory;
-        if (virAsprintf(&qemu_driver->snapshotDir,
-                        "%s/lib/libvirt/qemu/snapshot", LOCALSTATEDIR) == -1)
-            goto out_of_memory;
-        if (virAsprintf(&qemu_driver->autoDumpPath,
-                        "%s/lib/libvirt/qemu/dump", LOCALSTATEDIR) == -1)
-            goto out_of_memory;
     } else {
         uid_t uid = geteuid();
-        char *userdir = virGetUserDirectory(uid);
+        userdir = virGetUserDirectory(uid);
         if (!userdir)
             goto error;
 
-        if (virAsprintf(&qemu_driver->logDir,
-                        "%s/.libvirt/qemu/log", userdir) == -1) {
-            VIR_FREE(userdir);
-            goto out_of_memory;
-        }
-
         if (virAsprintf(&base, "%s/.libvirt", userdir) == -1) {
             VIR_FREE(userdir);
             goto out_of_memory;
         }
-        VIR_FREE(userdir);
-
-        if (virAsprintf(&qemu_driver->stateDir, "%s/qemu/run", base) == -1)
-            goto out_of_memory;
-        if (virAsprintf(&qemu_driver->libDir, "%s/qemu/lib", base) == -1)
-            goto out_of_memory;
-        if (virAsprintf(&qemu_driver->cacheDir, "%s/qemu/cache", base) == -1)
-            goto out_of_memory;
-        if (virAsprintf(&qemu_driver->saveDir, "%s/qemu/save", base) == -1)
-            goto out_of_memory;
-        if (virAsprintf(&qemu_driver->snapshotDir, "%s/qemu/snapshot", base) == -1)
-            goto out_of_memory;
-        if (virAsprintf(&qemu_driver->autoDumpPath, "%s/qemu/dump", base) == -1)
-            goto out_of_memory;
     }
 
+    if (virAsprintf(&driverConf, "%s/qemu.conf", base) < 0 ||
+        virAsprintf(&qemu_driver->configDir, "%s/qemu", base) < 0 ||
+        virAsprintf(&qemu_driver->autostartDir, "%s/qemu/autostart", base) < 0)
+        goto out_of_memory;
+
+    rc = virCgroupForDriver("qemu", &qemu_driver->cgroup, privileged, 1);
+    if (rc < 0) {
+        char buf[1024];
+        VIR_INFO("Unable to create cgroup for driver: %s",
+                 virStrerror(-rc, buf, sizeof(buf)));
+    }
+
+    if (qemudLoadDriverConfig(qemu_driver, driverConf, userdir, base) < 0) {
+        goto error;
+    }
+    VIR_FREE(base);
+    VIR_FREE(userdir);
+    VIR_FREE(driverConf);
+
+    /* read the host sysinfo */
+    if (privileged)
+        qemu_driver->hostsysinfo = virSysinfoRead();
+
     if (virFileMakePath(qemu_driver->stateDir) < 0) {
         char ebuf[1024];
         VIR_ERROR(_("Failed to create state dir '%s': %s"),
@@ -552,28 +530,6 @@ qemudStartup(int privileged) {
         goto error;
     }
 
-    /* Configuration paths are either ~/.libvirt/qemu/... (session) or
-     * /etc/libvirt/qemu/... (system).
-     */
-    if (virAsprintf(&driverConf, "%s/qemu.conf", base) < 0 ||
-        virAsprintf(&qemu_driver->configDir, "%s/qemu", base) < 0 ||
-        virAsprintf(&qemu_driver->autostartDir, "%s/qemu/autostart", base) < 0)
-        goto out_of_memory;
-
-    VIR_FREE(base);
-
-    rc = virCgroupForDriver("qemu", &qemu_driver->cgroup, privileged, 1);
-    if (rc < 0) {
-        char buf[1024];
-        VIR_INFO("Unable to create cgroup for driver: %s",
-                 virStrerror(-rc, buf, sizeof(buf)));
-    }
-
-    if (qemudLoadDriverConfig(qemu_driver, driverConf) < 0) {
-        goto error;
-    }
-    VIR_FREE(driverConf);
-
     /* We should always at least have the 'nop' manager, so
      * NULLs here are a fatal error
      */
@@ -708,6 +664,7 @@ error:
     if (conn)
         virConnectClose(conn);
     VIR_FREE(base);
+    VIR_FREE(userdir);
     VIR_FREE(driverConf);
     qemudShutdown();
     return -1;
-- 
1.7.3.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]