render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Daniel P. Berrange fdd7e8
changeset:   1146:c48e81e685a3
Daniel P. Berrange fdd7e8
user:        berrange
Daniel P. Berrange fdd7e8
date:        Fri Oct 12 15:05:44 2007 +0000
Daniel P. Berrange fdd7e8
files:       ChangeLog src/qemu_conf.c src/qemu_conf.h src/qemu_driver.c
Daniel P. Berrange fdd7e8
description:
Daniel P. Berrange fdd7e8
Added QEMU driver config file
Daniel P. Berrange fdd7e8
Daniel P. Berrange fdd7e8
Daniel P. Berrange fdd7e8
diff -r 522efe7f7e8f -r c48e81e685a3 src/qemu_conf.c
Daniel P. Berrange fdd7e8
--- a/src/qemu_conf.c	Wed Oct 10 18:46:17 2007 +0000
Daniel P. Berrange fdd7e8
+++ b/src/qemu_conf.c	Fri Oct 12 15:05:44 2007 +0000
Daniel P. Berrange fdd7e8
@@ -45,6 +45,7 @@
Daniel P. Berrange fdd7e8
 #include "qemu_conf.h"
Daniel P. Berrange fdd7e8
 #include "uuid.h"
Daniel P. Berrange fdd7e8
 #include "buf.h"
Daniel P. Berrange fdd7e8
+#include "conf.h"
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
 #define qemudLog(level, msg...) fprintf(stderr, msg)
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
@@ -65,6 +66,68 @@ void qemudReportError(virConnectPtr conn
Daniel P. Berrange fdd7e8
     __virRaiseError(conn, dom, net, VIR_FROM_QEMU, code, VIR_ERR_ERROR,
Daniel P. Berrange fdd7e8
                     NULL, NULL, NULL, -1, -1, errorMessage);
Daniel P. Berrange fdd7e8
 }
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+int qemudLoadDriverConfig(struct qemud_driver *driver,
Daniel P. Berrange fdd7e8
+                          const char *filename) {
Daniel P. Berrange fdd7e8
+    virConfPtr conf;
Daniel P. Berrange fdd7e8
+    virConfValuePtr p;
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+    /* Setup 2 critical defaults */
Daniel P. Berrange fdd7e8
+    strcpy(driver->vncListen, "127.0.0.1");
Daniel P. Berrange fdd7e8
+    if (!(driver->vncTLSx509certdir = strdup(SYSCONF_DIR "/pki/libvirt-vnc"))) {
Daniel P. Berrange fdd7e8
+        qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY,
Daniel P. Berrange fdd7e8
+                         "vncTLSx509certdir");
Daniel P. Berrange fdd7e8
+        return -1;
Daniel P. Berrange fdd7e8
+    }
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+    /* Just check the file is readable before opening it, otherwise
Daniel P. Berrange fdd7e8
+     * libvirt emits an error.
Daniel P. Berrange fdd7e8
+     */
Daniel P. Berrange fdd7e8
+    if (access (filename, R_OK) == -1) return 0;
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+    conf = virConfReadFile (filename);
Daniel P. Berrange fdd7e8
+    if (!conf) return 0;
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+#define CHECK_TYPE(name,typ) if (p && p->type != (typ)) {               \
Daniel P. Berrange fdd7e8
+        qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,      \
Daniel P. Berrange fdd7e8
+                         "remoteReadConfigFile: %s: %s: expected type " #typ "\n", \
Daniel P. Berrange fdd7e8
+                         filename, (name));                             \
Daniel P. Berrange fdd7e8
+        virConfFree(conf);                                              \
Daniel P. Berrange fdd7e8
+        return -1;                                                      \
Daniel P. Berrange fdd7e8
+    }
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+    p = virConfGetValue (conf, "vnc_tls");
Daniel P. Berrange fdd7e8
+    CHECK_TYPE ("vnc_tls", VIR_CONF_LONG);
Daniel P. Berrange fdd7e8
+    if (p) driver->vncTLS = p->l;
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+    p = virConfGetValue (conf, "vnc_tls_x509_verify");
Daniel P. Berrange fdd7e8
+    CHECK_TYPE ("vnc_tls_x509_verify", VIR_CONF_LONG);
Daniel P. Berrange fdd7e8
+    if (p) driver->vncTLSx509verify = p->l;
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+    p = virConfGetValue (conf, "vnc_tls_x509_cert_dir");
Daniel P. Berrange fdd7e8
+    CHECK_TYPE ("vnc_tls_x509_cert_dir", VIR_CONF_STRING);
Daniel P. Berrange fdd7e8
+    if (p && p->str) {
Daniel P. Berrange fdd7e8
+        free(driver->vncTLSx509certdir);
Daniel P. Berrange fdd7e8
+        if (!(driver->vncTLSx509certdir = strdup(p->str))) {
Daniel P. Berrange fdd7e8
+            qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY,
Daniel P. Berrange fdd7e8
+                             "vncTLSx509certdir");
Daniel P. Berrange fdd7e8
+            virConfFree(conf);
Daniel P. Berrange fdd7e8
+            return -1;
Daniel P. Berrange fdd7e8
+        }
Daniel P. Berrange fdd7e8
+    }
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+    p = virConfGetValue (conf, "vnc_listen");
Daniel P. Berrange fdd7e8
+    CHECK_TYPE ("vnc_listen", VIR_CONF_STRING);
Daniel P. Berrange fdd7e8
+    if (p && p->str) {
Daniel P. Berrange fdd7e8
+        strncpy(driver->vncListen, p->str, sizeof(driver->vncListen));
Daniel P. Berrange fdd7e8
+        driver->vncListen[sizeof(driver->vncListen)-1] = '\0';
Daniel P. Berrange fdd7e8
+    }
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+    virConfFree (conf);
Daniel P. Berrange fdd7e8
+    return 0;
Daniel P. Berrange fdd7e8
+}
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
 struct qemud_vm *qemudFindVMByID(const struct qemud_driver *driver, int id) {
Daniel P. Berrange fdd7e8
     struct qemud_vm *vm = driver->vms;
Daniel P. Berrange fdd7e8
@@ -1234,7 +1297,7 @@ static struct qemud_vm_def *qemudParseXM
Daniel P. Berrange fdd7e8
             if (vnclisten && *vnclisten)
Daniel P. Berrange fdd7e8
                 strncpy(def->vncListen, (char *)vnclisten, BR_INET_ADDR_MAXLEN-1);
Daniel P. Berrange fdd7e8
             else
Daniel P. Berrange fdd7e8
-                strcpy(def->vncListen, "127.0.0.1");
Daniel P. Berrange fdd7e8
+                strcpy(def->vncListen, driver->vncListen);
Daniel P. Berrange fdd7e8
             def->vncListen[BR_INET_ADDR_MAXLEN-1] = '\0';
Daniel P. Berrange fdd7e8
             xmlFree(vncport);
Daniel P. Berrange fdd7e8
             xmlFree(vnclisten);
Daniel P. Berrange fdd7e8
@@ -1750,15 +1813,30 @@ int qemudBuildCommandLine(virConnectPtr 
Daniel P. Berrange fdd7e8
     }
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
     if (vm->def->graphicsType == QEMUD_GRAPHICS_VNC) {
Daniel P. Berrange fdd7e8
-        char vncdisplay[BR_INET_ADDR_MAXLEN+20];
Daniel P. Berrange fdd7e8
+        char vncdisplay[PATH_MAX];
Daniel P. Berrange fdd7e8
         int ret;
Daniel P. Berrange fdd7e8
-        if (vm->qemuCmdFlags & QEMUD_CMD_FLAG_VNC_COLON)
Daniel P. Berrange fdd7e8
-            ret = snprintf(vncdisplay, sizeof(vncdisplay), "%s:%d",
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+        if (vm->qemuCmdFlags & QEMUD_CMD_FLAG_VNC_COLON) {
Daniel P. Berrange fdd7e8
+            char options[PATH_MAX] = "";
Daniel P. Berrange fdd7e8
+            if (driver->vncTLS) {
Daniel P. Berrange fdd7e8
+                strcat(options, ",tls");
Daniel P. Berrange fdd7e8
+                if (driver->vncTLSx509verify) {
Daniel P. Berrange fdd7e8
+                    strcat(options, ",x509verify=");
Daniel P. Berrange fdd7e8
+                } else {
Daniel P. Berrange fdd7e8
+                    strcat(options, ",x509=");
Daniel P. Berrange fdd7e8
+                }
Daniel P. Berrange fdd7e8
+                strncat(options, driver->vncTLSx509certdir,
Daniel P. Berrange fdd7e8
+                        sizeof(options) - (strlen(driver->vncTLSx509certdir)-1));
Daniel P. Berrange fdd7e8
+                options[sizeof(options)-1] = '\0';
Daniel P. Berrange fdd7e8
+            }
Daniel P. Berrange fdd7e8
+            ret = snprintf(vncdisplay, sizeof(vncdisplay), "%s:%d%s",
Daniel P. Berrange fdd7e8
                            vm->def->vncListen,
Daniel P. Berrange fdd7e8
-                           vm->def->vncActivePort - 5900);
Daniel P. Berrange fdd7e8
-        else
Daniel P. Berrange fdd7e8
+                           vm->def->vncActivePort - 5900,
Daniel P. Berrange fdd7e8
+                           options);
Daniel P. Berrange fdd7e8
+        } else {
Daniel P. Berrange fdd7e8
             ret = snprintf(vncdisplay, sizeof(vncdisplay), "%d",
Daniel P. Berrange fdd7e8
                            vm->def->vncActivePort - 5900);
Daniel P. Berrange fdd7e8
+        }
Daniel P. Berrange fdd7e8
         if (ret < 0 || ret >= (int)sizeof(vncdisplay))
Daniel P. Berrange fdd7e8
             goto error;
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
diff -r 522efe7f7e8f -r c48e81e685a3 src/qemu_conf.h
Daniel P. Berrange fdd7e8
--- a/src/qemu_conf.h	Wed Oct 10 18:46:17 2007 +0000
Daniel P. Berrange fdd7e8
+++ b/src/qemu_conf.h	Fri Oct 12 15:05:44 2007 +0000
Daniel P. Berrange fdd7e8
@@ -289,6 +289,10 @@ struct qemud_driver {
Daniel P. Berrange fdd7e8
     char *networkConfigDir;
Daniel P. Berrange fdd7e8
     char *networkAutostartDir;
Daniel P. Berrange fdd7e8
     char logDir[PATH_MAX];
Daniel P. Berrange fdd7e8
+    int vncTLS : 1;
Daniel P. Berrange fdd7e8
+    int vncTLSx509verify : 1;
Daniel P. Berrange fdd7e8
+    char *vncTLSx509certdir;
Daniel P. Berrange fdd7e8
+    char vncListen[BR_INET_ADDR_MAXLEN];
Daniel P. Berrange fdd7e8
 };
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
@@ -311,6 +315,8 @@ void qemudReportError(virConnectPtr conn
Daniel P. Berrange fdd7e8
     ATTRIBUTE_FORMAT(printf,5,6);
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
+int qemudLoadDriverConfig(struct qemud_driver *driver,
Daniel P. Berrange fdd7e8
+                          const char *filename);
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
 struct qemud_vm *qemudFindVMByID(const struct qemud_driver *driver,
Daniel P. Berrange fdd7e8
                                  int id);
Daniel P. Berrange fdd7e8
diff -r 522efe7f7e8f -r c48e81e685a3 src/qemu_driver.c
Daniel P. Berrange fdd7e8
--- a/src/qemu_driver.c	Wed Oct 10 18:46:17 2007 +0000
Daniel P. Berrange fdd7e8
+++ b/src/qemu_driver.c	Fri Oct 12 15:05:44 2007 +0000
Daniel P. Berrange fdd7e8
@@ -155,6 +155,7 @@ qemudStartup(void) {
Daniel P. Berrange fdd7e8
     uid_t uid = geteuid();
Daniel P. Berrange fdd7e8
     struct passwd *pw;
Daniel P. Berrange fdd7e8
     char *base = NULL;
Daniel P. Berrange fdd7e8
+    char driverConf[PATH_MAX];
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
     if (!(qemu_driver = calloc(1, sizeof(struct qemud_driver)))) {
Daniel P. Berrange fdd7e8
         return -1;
Daniel P. Berrange fdd7e8
@@ -167,7 +168,7 @@ qemudStartup(void) {
Daniel P. Berrange fdd7e8
         if (snprintf(qemu_driver->logDir, PATH_MAX, "%s/log/libvirt/qemu", LOCAL_STATE_DIR) >= PATH_MAX)
Daniel P. Berrange fdd7e8
             goto snprintf_error;
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
-        if ((base = strdup (SYSCONF_DIR "/libvirt/qemu")) == NULL)
Daniel P. Berrange fdd7e8
+        if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
Daniel P. Berrange fdd7e8
             goto out_of_memory;
Daniel P. Berrange fdd7e8
     } else {
Daniel P. Berrange fdd7e8
         if (!(pw = getpwuid(uid))) {
Daniel P. Berrange fdd7e8
@@ -179,7 +180,7 @@ qemudStartup(void) {
Daniel P. Berrange fdd7e8
         if (snprintf(qemu_driver->logDir, PATH_MAX, "%s/.libvirt/qemu/log", pw->pw_dir) >= PATH_MAX)
Daniel P. Berrange fdd7e8
             goto snprintf_error;
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
-        if (asprintf (&base, "%s/.libvirt/qemu", pw->pw_dir) == -1) {
Daniel P. Berrange fdd7e8
+        if (asprintf (&base, "%s/.libvirt", pw->pw_dir) == -1) {
Daniel P. Berrange fdd7e8
             qemudLog (QEMUD_ERR, "out of memory in asprintf");
Daniel P. Berrange fdd7e8
             goto out_of_memory;
Daniel P. Berrange fdd7e8
         }
Daniel P. Berrange fdd7e8
@@ -188,24 +189,36 @@ qemudStartup(void) {
Daniel P. Berrange fdd7e8
     /* Configuration paths are either ~/.libvirt/qemu/... (session) or
Daniel P. Berrange fdd7e8
      * /etc/libvirt/qemu/... (system).
Daniel P. Berrange fdd7e8
      */
Daniel P. Berrange fdd7e8
-    if (asprintf (&qemu_driver->configDir, "%s", base) == -1)
Daniel P. Berrange fdd7e8
+    if (snprintf (driverConf, sizeof(driverConf), "%s/qemu.conf", base) == -1)
Daniel P. Berrange fdd7e8
         goto out_of_memory;
Daniel P. Berrange fdd7e8
-
Daniel P. Berrange fdd7e8
-    if (asprintf (&qemu_driver->autostartDir, "%s/autostart", base) == -1)
Daniel P. Berrange fdd7e8
+    driverConf[sizeof(driverConf)-1] = '\0';
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+    if (asprintf (&qemu_driver->configDir, "%s/qemu", base) == -1)
Daniel P. Berrange fdd7e8
         goto out_of_memory;
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
-    if (asprintf (&qemu_driver->networkConfigDir, "%s/networks", base) == -1)
Daniel P. Berrange fdd7e8
+    if (asprintf (&qemu_driver->autostartDir, "%s/qemu/autostart", base) == -1)
Daniel P. Berrange fdd7e8
         goto out_of_memory;
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
-    if (asprintf (&qemu_driver->networkAutostartDir, "%s/networks/autostart",
Daniel P. Berrange fdd7e8
+    if (asprintf (&qemu_driver->networkConfigDir, "%s/qemu/networks", base) == -1)
Daniel P. Berrange fdd7e8
+        goto out_of_memory;
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+    if (asprintf (&qemu_driver->networkAutostartDir, "%s/qemu/networks/autostart",
Daniel P. Berrange fdd7e8
                   base) == -1)
Daniel P. Berrange fdd7e8
         goto out_of_memory;
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
-    if (qemudScanConfigs(qemu_driver) < 0)
Daniel P. Berrange fdd7e8
+    free(base);
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+    if (qemudLoadDriverConfig(qemu_driver, driverConf) < 0) {
Daniel P. Berrange fdd7e8
         qemudShutdown();
Daniel P. Berrange fdd7e8
+        return -1;
Daniel P. Berrange fdd7e8
+    }
Daniel P. Berrange fdd7e8
+
Daniel P. Berrange fdd7e8
+    if (qemudScanConfigs(qemu_driver) < 0) {
Daniel P. Berrange fdd7e8
+        qemudShutdown();
Daniel P. Berrange fdd7e8
+        return -1;
Daniel P. Berrange fdd7e8
+    }
Daniel P. Berrange fdd7e8
     qemudAutostartConfigs(qemu_driver);
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
-    free(base);
Daniel P. Berrange fdd7e8
     return 0;
Daniel P. Berrange fdd7e8
 
Daniel P. Berrange fdd7e8
  snprintf_error:
Daniel P. Berrange fdd7e8