Added QEMU driver config file

This commit is contained in:
Daniel P. Berrange 2007-10-12 16:05:44 +00:00
parent af10d71cc2
commit 912c18afa3
4 changed files with 117 additions and 14 deletions

View File

@ -1,3 +1,9 @@
Fri Oct 12 12:05:53 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* src/qemu_driver.c, src/qemu_conf.c, src/qemu_conf.h: Add a
/etc/libvirt/qemu.conf for storing system wide QEMU driver
default settings, such as VNC server options.
Wed Oct 10 15:44:53 EST 2007 Daniel P. Berrange <berrange@redhat.com> Wed Oct 10 15:44:53 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* src/qemu_driver.c: Reset migration source after failed attempt * src/qemu_driver.c: Reset migration source after failed attempt

View File

@ -45,6 +45,7 @@
#include "qemu_conf.h" #include "qemu_conf.h"
#include "uuid.h" #include "uuid.h"
#include "buf.h" #include "buf.h"
#include "conf.h"
#define qemudLog(level, msg...) fprintf(stderr, msg) #define qemudLog(level, msg...) fprintf(stderr, msg)
@ -66,6 +67,68 @@ void qemudReportError(virConnectPtr conn,
NULL, NULL, NULL, -1, -1, errorMessage); NULL, NULL, NULL, -1, -1, errorMessage);
} }
int qemudLoadDriverConfig(struct qemud_driver *driver,
const char *filename) {
virConfPtr conf;
virConfValuePtr p;
/* Setup 2 critical defaults */
strcpy(driver->vncListen, "127.0.0.1");
if (!(driver->vncTLSx509certdir = strdup(SYSCONF_DIR "/pki/libvirt-vnc"))) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY,
"vncTLSx509certdir");
return -1;
}
/* Just check the file is readable before opening it, otherwise
* libvirt emits an error.
*/
if (access (filename, R_OK) == -1) return 0;
conf = virConfReadFile (filename);
if (!conf) return 0;
#define CHECK_TYPE(name,typ) if (p && p->type != (typ)) { \
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, \
"remoteReadConfigFile: %s: %s: expected type " #typ "\n", \
filename, (name)); \
virConfFree(conf); \
return -1; \
}
p = virConfGetValue (conf, "vnc_tls");
CHECK_TYPE ("vnc_tls", VIR_CONF_LONG);
if (p) driver->vncTLS = p->l;
p = virConfGetValue (conf, "vnc_tls_x509_verify");
CHECK_TYPE ("vnc_tls_x509_verify", VIR_CONF_LONG);
if (p) driver->vncTLSx509verify = p->l;
p = virConfGetValue (conf, "vnc_tls_x509_cert_dir");
CHECK_TYPE ("vnc_tls_x509_cert_dir", VIR_CONF_STRING);
if (p && p->str) {
free(driver->vncTLSx509certdir);
if (!(driver->vncTLSx509certdir = strdup(p->str))) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY,
"vncTLSx509certdir");
virConfFree(conf);
return -1;
}
}
p = virConfGetValue (conf, "vnc_listen");
CHECK_TYPE ("vnc_listen", VIR_CONF_STRING);
if (p && p->str) {
strncpy(driver->vncListen, p->str, sizeof(driver->vncListen));
driver->vncListen[sizeof(driver->vncListen)-1] = '\0';
}
virConfFree (conf);
return 0;
}
struct qemud_vm *qemudFindVMByID(const struct qemud_driver *driver, int id) { struct qemud_vm *qemudFindVMByID(const struct qemud_driver *driver, int id) {
struct qemud_vm *vm = driver->vms; struct qemud_vm *vm = driver->vms;
@ -1234,7 +1297,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
if (vnclisten && *vnclisten) if (vnclisten && *vnclisten)
strncpy(def->vncListen, (char *)vnclisten, BR_INET_ADDR_MAXLEN-1); strncpy(def->vncListen, (char *)vnclisten, BR_INET_ADDR_MAXLEN-1);
else else
strcpy(def->vncListen, "127.0.0.1"); strcpy(def->vncListen, driver->vncListen);
def->vncListen[BR_INET_ADDR_MAXLEN-1] = '\0'; def->vncListen[BR_INET_ADDR_MAXLEN-1] = '\0';
xmlFree(vncport); xmlFree(vncport);
xmlFree(vnclisten); xmlFree(vnclisten);
@ -1750,15 +1813,30 @@ int qemudBuildCommandLine(virConnectPtr conn,
} }
if (vm->def->graphicsType == QEMUD_GRAPHICS_VNC) { if (vm->def->graphicsType == QEMUD_GRAPHICS_VNC) {
char vncdisplay[BR_INET_ADDR_MAXLEN+20]; char vncdisplay[PATH_MAX];
int ret; int ret;
if (vm->qemuCmdFlags & QEMUD_CMD_FLAG_VNC_COLON)
ret = snprintf(vncdisplay, sizeof(vncdisplay), "%s:%d", if (vm->qemuCmdFlags & QEMUD_CMD_FLAG_VNC_COLON) {
char options[PATH_MAX] = "";
if (driver->vncTLS) {
strcat(options, ",tls");
if (driver->vncTLSx509verify) {
strcat(options, ",x509verify=");
} else {
strcat(options, ",x509=");
}
strncat(options, driver->vncTLSx509certdir,
sizeof(options) - (strlen(driver->vncTLSx509certdir)-1));
options[sizeof(options)-1] = '\0';
}
ret = snprintf(vncdisplay, sizeof(vncdisplay), "%s:%d%s",
vm->def->vncListen, vm->def->vncListen,
vm->def->vncActivePort - 5900); vm->def->vncActivePort - 5900,
else options);
} else {
ret = snprintf(vncdisplay, sizeof(vncdisplay), "%d", ret = snprintf(vncdisplay, sizeof(vncdisplay), "%d",
vm->def->vncActivePort - 5900); vm->def->vncActivePort - 5900);
}
if (ret < 0 || ret >= (int)sizeof(vncdisplay)) if (ret < 0 || ret >= (int)sizeof(vncdisplay))
goto error; goto error;

View File

@ -289,6 +289,10 @@ struct qemud_driver {
char *networkConfigDir; char *networkConfigDir;
char *networkAutostartDir; char *networkAutostartDir;
char logDir[PATH_MAX]; char logDir[PATH_MAX];
int vncTLS : 1;
int vncTLSx509verify : 1;
char *vncTLSx509certdir;
char vncListen[BR_INET_ADDR_MAXLEN];
}; };
@ -311,6 +315,8 @@ void qemudReportError(virConnectPtr conn,
ATTRIBUTE_FORMAT(printf,5,6); ATTRIBUTE_FORMAT(printf,5,6);
int qemudLoadDriverConfig(struct qemud_driver *driver,
const char *filename);
struct qemud_vm *qemudFindVMByID(const struct qemud_driver *driver, struct qemud_vm *qemudFindVMByID(const struct qemud_driver *driver,
int id); int id);

View File

@ -155,6 +155,7 @@ qemudStartup(void) {
uid_t uid = geteuid(); uid_t uid = geteuid();
struct passwd *pw; struct passwd *pw;
char *base = NULL; char *base = NULL;
char driverConf[PATH_MAX];
if (!(qemu_driver = calloc(1, sizeof(struct qemud_driver)))) { if (!(qemu_driver = calloc(1, sizeof(struct qemud_driver)))) {
return -1; return -1;
@ -167,7 +168,7 @@ qemudStartup(void) {
if (snprintf(qemu_driver->logDir, PATH_MAX, "%s/log/libvirt/qemu", LOCAL_STATE_DIR) >= PATH_MAX) if (snprintf(qemu_driver->logDir, PATH_MAX, "%s/log/libvirt/qemu", LOCAL_STATE_DIR) >= PATH_MAX)
goto snprintf_error; goto snprintf_error;
if ((base = strdup (SYSCONF_DIR "/libvirt/qemu")) == NULL) if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
goto out_of_memory; goto out_of_memory;
} else { } else {
if (!(pw = getpwuid(uid))) { if (!(pw = getpwuid(uid))) {
@ -179,7 +180,7 @@ qemudStartup(void) {
if (snprintf(qemu_driver->logDir, PATH_MAX, "%s/.libvirt/qemu/log", pw->pw_dir) >= PATH_MAX) if (snprintf(qemu_driver->logDir, PATH_MAX, "%s/.libvirt/qemu/log", pw->pw_dir) >= PATH_MAX)
goto snprintf_error; goto snprintf_error;
if (asprintf (&base, "%s/.libvirt/qemu", pw->pw_dir) == -1) { if (asprintf (&base, "%s/.libvirt", pw->pw_dir) == -1) {
qemudLog (QEMUD_ERR, "out of memory in asprintf"); qemudLog (QEMUD_ERR, "out of memory in asprintf");
goto out_of_memory; goto out_of_memory;
} }
@ -188,24 +189,36 @@ qemudStartup(void) {
/* Configuration paths are either ~/.libvirt/qemu/... (session) or /* Configuration paths are either ~/.libvirt/qemu/... (session) or
* /etc/libvirt/qemu/... (system). * /etc/libvirt/qemu/... (system).
*/ */
if (asprintf (&qemu_driver->configDir, "%s", base) == -1) if (snprintf (driverConf, sizeof(driverConf), "%s/qemu.conf", base) == -1)
goto out_of_memory;
driverConf[sizeof(driverConf)-1] = '\0';
if (asprintf (&qemu_driver->configDir, "%s/qemu", base) == -1)
goto out_of_memory; goto out_of_memory;
if (asprintf (&qemu_driver->autostartDir, "%s/autostart", base) == -1) if (asprintf (&qemu_driver->autostartDir, "%s/qemu/autostart", base) == -1)
goto out_of_memory; goto out_of_memory;
if (asprintf (&qemu_driver->networkConfigDir, "%s/networks", base) == -1) if (asprintf (&qemu_driver->networkConfigDir, "%s/qemu/networks", base) == -1)
goto out_of_memory; goto out_of_memory;
if (asprintf (&qemu_driver->networkAutostartDir, "%s/networks/autostart", if (asprintf (&qemu_driver->networkAutostartDir, "%s/qemu/networks/autostart",
base) == -1) base) == -1)
goto out_of_memory; goto out_of_memory;
if (qemudScanConfigs(qemu_driver) < 0) free(base);
if (qemudLoadDriverConfig(qemu_driver, driverConf) < 0) {
qemudShutdown(); qemudShutdown();
return -1;
}
if (qemudScanConfigs(qemu_driver) < 0) {
qemudShutdown();
return -1;
}
qemudAutostartConfigs(qemu_driver); qemudAutostartConfigs(qemu_driver);
free(base);
return 0; return 0;
snprintf_error: snprintf_error: