Detect QEMU flags per VM instead of once for driver as a whole

This commit is contained in:
Daniel P. Berrange 2007-09-21 21:20:32 +00:00
parent b32f429849
commit 136ebc6e3c
5 changed files with 49 additions and 33 deletions

View File

@ -1,3 +1,11 @@
Fri Sep 21 17:14:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* src/qemu_conf.c, src/qemu_conf.h: Detect QEMU flags per-VM,
not per driver, since different QEMU binaries have their own
requirements.
* tests/qemuxml2xmltest.c, tests/qemuxml2argvtets.c: Update
to changed internal QEMU api/structs.
Fri Sep 21 16:22:00 EST 2007 Daniel P. Berrange <berrange@redhat.com> Fri Sep 21 16:22:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* src/remote_internal.c: Add a no_tty flag to stop SSH prompting * src/remote_internal.c: Add a no_tty flag to stop SSH prompting
@ -6,11 +14,11 @@ Fri Sep 21 16:22:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
Fri Sep 21 15:06:00 EST 2007 Daniel P. Berrange <berrange@redhat.com> Fri Sep 21 15:06:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* acinclude.m4: Check all compiler flags link successfully * acinclude.m4: Check all compiler flags link successfully
instead of just compiling, to deal with broken debian linker instead of just compiling, to deal with broken debian linker
with stack protector with stack protector
* configure.in: Remove redundant -fno-stack-protector workaround * configure.in: Remove redundant -fno-stack-protector workaround
Fri Sep 21 15:06:00 EST 2007 Daniel P. Berrange <berrange@redhat.com> Fri Sep 21 15:06:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* src/qemu_driver.c: Use libxml for parsing & checking URIs * src/qemu_driver.c: Use libxml for parsing & checking URIs

View File

@ -287,7 +287,6 @@ static const char *qemudDefaultBinaryForArch(const char *arch) {
/* Find the fully qualified path to the binary for an architecture */ /* Find the fully qualified path to the binary for an architecture */
static char *qemudLocateBinaryForArch(virConnectPtr conn, static char *qemudLocateBinaryForArch(virConnectPtr conn,
struct qemud_driver *driver ATTRIBUTE_UNUSED,
int virtType, const char *arch) { int virtType, const char *arch) {
const char *name; const char *name;
char *path; char *path;
@ -408,14 +407,15 @@ static int qemudExtractVersionInfo(const char *qemu, int *version, int *flags) {
} }
int qemudExtractVersion(virConnectPtr conn, int qemudExtractVersion(virConnectPtr conn,
struct qemud_driver *driver) { struct qemud_driver *driver ATTRIBUTE_UNUSED) {
char *binary = NULL; char *binary = NULL;
struct stat sb; struct stat sb;
int ignored;
if (driver->qemuVersion > 0) if (driver->qemuVersion > 0)
return 0; return 0;
if (!(binary = qemudLocateBinaryForArch(conn, driver, QEMUD_VIRT_QEMU, "i686"))) if (!(binary = qemudLocateBinaryForArch(conn, QEMUD_VIRT_QEMU, "i686")))
return -1; return -1;
if (stat(binary, &sb) < 0) { if (stat(binary, &sb) < 0) {
@ -426,7 +426,7 @@ int qemudExtractVersion(virConnectPtr conn,
return -1; return -1;
} }
if (qemudExtractVersionInfo(binary, &driver->qemuVersion, &driver->qemuCmdFlags) < 0) { if (qemudExtractVersionInfo(binary, &driver->qemuVersion, &ignored) < 0) {
free(binary); free(binary);
return -1; return -1;
} }
@ -1199,7 +1199,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/emulator[1])", ctxt); obj = xmlXPathEval(BAD_CAST "string(/domain/devices/emulator[1])", ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) || if ((obj == NULL) || (obj->type != XPATH_STRING) ||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) { (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
char *tmp = qemudLocateBinaryForArch(conn, driver, def->virtType, def->os.arch); char *tmp = qemudLocateBinaryForArch(conn, def->virtType, def->os.arch);
if (!tmp) { if (!tmp) {
goto error; goto error;
} }
@ -1466,8 +1466,23 @@ int qemudBuildCommandLine(virConnectPtr conn,
struct utsname ut; struct utsname ut;
int disableKQEMU = 0; int disableKQEMU = 0;
if (qemudExtractVersion(conn, driver) < 0) /* Make sure the binary we are about to try exec'ing exists.
* Technically we could catch the exec() failure, but that's
* in a sub-process so its hard to feed back a useful error
*/
if (stat(vm->def->os.binary, &sb) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"Cannot find QEMU binary %s: %s", vm->def->os.binary,
strerror(errno));
return -1; return -1;
}
if (vm->qemuVersion == 0) {
if (qemudExtractVersionInfo(vm->def->os.binary,
&(vm->qemuVersion),
&(vm->qemuCmdFlags)) < 0)
return -1;
}
uname(&ut); uname(&ut);
@ -1483,22 +1498,11 @@ int qemudBuildCommandLine(virConnectPtr conn,
* 2. Guest is 'qemu' * 2. Guest is 'qemu'
* 3. The qemu binary has the -no-kqemu flag * 3. The qemu binary has the -no-kqemu flag
*/ */
if ((driver->qemuCmdFlags & QEMUD_CMD_FLAG_KQEMU) && if ((vm->qemuCmdFlags & QEMUD_CMD_FLAG_KQEMU) &&
!strcmp(ut.machine, vm->def->os.arch) && !strcmp(ut.machine, vm->def->os.arch) &&
vm->def->virtType == QEMUD_VIRT_QEMU) vm->def->virtType == QEMUD_VIRT_QEMU)
disableKQEMU = 1; disableKQEMU = 1;
/* Make sure the binary we are about to try exec'ing exists.
* Technically we could catch the exec() failure, but that's
* in a sub-process so its hard to feed back a useful error
*/
if (stat(vm->def->os.binary, &sb) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"Cannot find QEMU binary %s: %s", vm->def->os.binary,
strerror(errno));
return -1;
}
len = 1 + /* qemu */ len = 1 + /* qemu */
2 + /* machine type */ 2 + /* machine type */
disableKQEMU + /* Disable kqemu */ disableKQEMU + /* Disable kqemu */
@ -1511,7 +1515,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
2 + /* boot device */ 2 + /* boot device */
2 + /* monitor */ 2 + /* monitor */
(vm->def->localtime ? 1 : 0) + /* localtime */ (vm->def->localtime ? 1 : 0) + /* localtime */
(driver->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT && (vm->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT &&
vm->def->noReboot ? 1 : 0) + /* no-reboot */ vm->def->noReboot ? 1 : 0) + /* no-reboot */
(vm->def->features & QEMUD_FEATURE_ACPI ? 0 : 1) + /* acpi */ (vm->def->features & QEMUD_FEATURE_ACPI ? 0 : 1) + /* acpi */
(vm->def->os.kernel[0] ? 2 : 0) + /* kernel */ (vm->def->os.kernel[0] ? 2 : 0) + /* kernel */
@ -1567,7 +1571,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
goto no_memory; goto no_memory;
} }
if (driver->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT && if (vm->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT &&
vm->def->noReboot) { vm->def->noReboot) {
if (!((*argv)[++n] = strdup("-no-reboot"))) if (!((*argv)[++n] = strdup("-no-reboot")))
goto no_memory; goto no_memory;
@ -1748,7 +1752,7 @@ 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[BR_INET_ADDR_MAXLEN+20];
int ret; int ret;
if (driver->qemuCmdFlags & QEMUD_CMD_FLAG_VNC_COLON) if (vm->qemuCmdFlags & QEMUD_CMD_FLAG_VNC_COLON)
ret = snprintf(vncdisplay, sizeof(vncdisplay), "%s:%d", ret = snprintf(vncdisplay, sizeof(vncdisplay), "%s:%d",
vm->def->vncListen, vm->def->vncListen,
vm->def->vncActivePort - 5900); vm->def->vncActivePort - 5900);
@ -1885,7 +1889,9 @@ qemudAssignVMDef(virConnectPtr conn,
qemudFreeVMDef(vm->newDef); qemudFreeVMDef(vm->newDef);
vm->newDef = def; vm->newDef = def;
} }
/* Reset version, because the emulator path might have changed */
vm->qemuVersion = 0;
vm->qemuCmdFlags = 0;
return vm; return vm;
} }

View File

@ -211,6 +211,9 @@ struct qemud_vm {
int *tapfds; int *tapfds;
int ntapfds; int ntapfds;
int qemuVersion;
int qemuCmdFlags; /* values from enum qemud_cmd_flags */
char configFile[PATH_MAX]; char configFile[PATH_MAX];
char autostartLink[PATH_MAX]; char autostartLink[PATH_MAX];
char migrateFrom[PATH_MAX]; char migrateFrom[PATH_MAX];
@ -272,7 +275,6 @@ struct qemud_network {
/* Main driver state */ /* Main driver state */
struct qemud_driver { struct qemud_driver {
int qemuVersion; int qemuVersion;
int qemuCmdFlags; /* values from enum qemud_cmd_flags */
int nactivevms; int nactivevms;
int ninactivevms; int ninactivevms;
struct qemud_vm *vms; struct qemud_vm *vms;

View File

@ -37,6 +37,10 @@ static int testCompareXMLToArgvFiles(const char *xml, const char *cmd) {
vm.def = vmdef; vm.def = vmdef;
vm.pid = -1; vm.pid = -1;
vm.id = -1; vm.id = -1;
vm.qemuVersion = 0 * 1000 * 100 + (8 * 1000) + 1;
vm.qemuCmdFlags = QEMUD_CMD_FLAG_VNC_COLON |
QEMUD_CMD_FLAG_NO_REBOOT;
vmdef->vncActivePort = vmdef->vncPort; vmdef->vncActivePort = vmdef->vncPort;
if (qemudBuildCommandLine(NULL, &driver, &vm, &argv) < 0) if (qemudBuildCommandLine(NULL, &driver, &vm, &argv) < 0)
@ -107,10 +111,6 @@ main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
driver.qemuVersion = 0 * 1000 * 100 + (8 * 1000) + 1;
driver.qemuCmdFlags = QEMUD_CMD_FLAG_VNC_COLON |
QEMUD_CMD_FLAG_NO_REBOOT;
if (virtTestRun("QEMU XML-2-ARGV minimal", if (virtTestRun("QEMU XML-2-ARGV minimal",
1, testCompareXMLToArgvHelper, "minimal") < 0) 1, testCompareXMLToArgvHelper, "minimal") < 0)
ret = -1; ret = -1;

View File

@ -31,6 +31,10 @@ static int testCompareXMLToXMLFiles(const char *xml) {
vm.def = vmdef; vm.def = vmdef;
vm.pid = -1; vm.pid = -1;
vm.id = -1; vm.id = -1;
vm.qemuVersion = 0 * 1000 * 100 + (8 * 1000) + 1;
vm.qemuCmdFlags = QEMUD_CMD_FLAG_VNC_COLON |
QEMUD_CMD_FLAG_NO_REBOOT;
vmdef->vncActivePort = vmdef->vncPort; vmdef->vncActivePort = vmdef->vncPort;
if (!(actual = qemudGenerateXML(NULL, &driver, &vm, vmdef, 0))) if (!(actual = qemudGenerateXML(NULL, &driver, &vm, vmdef, 0)))
@ -72,10 +76,6 @@ main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
driver.qemuVersion = 0 * 1000 * 100 + (8 * 1000) + 1;
driver.qemuCmdFlags = QEMUD_CMD_FLAG_VNC_COLON |
QEMUD_CMD_FLAG_NO_REBOOT;
if (virtTestRun("QEMU XML-2-ARGV minimal", if (virtTestRun("QEMU XML-2-ARGV minimal",
1, testCompareXMLToXMLHelper, "minimal") < 0) 1, testCompareXMLToXMLHelper, "minimal") < 0)
ret = -1; ret = -1;