diff --git a/ChangeLog b/ChangeLog index d41cf3335886c135770e6e2e9a743d3cad02896c..108fe8affb4a11f771a6643ef70de56d77ddaa56 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Tue Nov 4 22:14:31 UTC 2008 Daniel P. Berrange + + Support passing UUID and ID to qemu/xenner + * src/qemu_conf.c, src/qemu_conf.h, src/qemu_driver.c: Detect + availability of -uuid and -domid args in QEMU, and use them if + available + * tests/qemuxml2argvtest.c, + tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.args, + tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.xml: Add test + case for -uuid and -domid args + Tue Nov 4 21:50:31 UTC 2008 Daniel P. Berrange Remove use of virStringList diff --git a/src/qemu_conf.c b/src/qemu_conf.c index 47c407a6590e4e5f04de88f9d48727ec1d24f3e8..e7cbdf606e750771b3331917e3125a022f9f1842 100644 --- a/src/qemu_conf.c +++ b/src/qemu_conf.c @@ -439,6 +439,10 @@ int qemudExtractVersionInfo(const char *qemu, flags |= QEMUD_CMD_FLAG_NO_REBOOT; if (strstr(help, "-name")) flags |= QEMUD_CMD_FLAG_NAME; + if (strstr(help, "-uuid")) + flags |= QEMUD_CMD_FLAG_UUID; + if (strstr(help, "-domid")) + flags |= QEMUD_CMD_FLAG_DOMID; if (strstr(help, "-drive")) flags |= QEMUD_CMD_FLAG_DRIVE; if (strstr(help, "boot=on")) @@ -713,6 +717,8 @@ int qemudBuildCommandLine(virConnectPtr conn, int qenvc = 0, qenva = 0; const char **qenv = NULL; const char *emulator; + char uuid[VIR_UUID_STRING_BUFLEN]; + char domid[50]; uname(&ut); @@ -723,6 +729,8 @@ int qemudBuildCommandLine(virConnectPtr conn, !ut.machine[4]) ut.machine[1] = '6'; + virUUIDFormat(vm->def->uuid, uuid); + /* Need to explicitly disable KQEMU if * 1. Arch matches host arch * 2. Guest is 'qemu' @@ -802,6 +810,7 @@ int qemudBuildCommandLine(virConnectPtr conn, snprintf(memory, sizeof(memory), "%lu", vm->def->memory/1024); snprintf(vcpus, sizeof(vcpus), "%lu", vm->def->vcpus); + snprintf(domid, sizeof(domid), "%d", vm->def->id); ADD_ENV_LIT("LC_ALL=C"); @@ -834,6 +843,15 @@ int qemudBuildCommandLine(virConnectPtr conn, ADD_ARG_LIT("-name"); ADD_ARG_LIT(vm->def->name); } + if (qemuCmdFlags & QEMUD_CMD_FLAG_UUID) { + ADD_ARG_LIT("-uuid"); + ADD_ARG_LIT(uuid); + } + if (qemuCmdFlags & QEMUD_CMD_FLAG_DOMID) { + ADD_ARG_LIT("-domid"); + ADD_ARG_LIT(domid); + } + /* * NB, -nographic *MUST* come before any serial, or monitor * or parallel port flags due to QEMU craziness, where it diff --git a/src/qemu_conf.h b/src/qemu_conf.h index d06c4d7691f3461c7903c9285228db718858b67f..2fb5ae2f968a5b39c89870451fe3ed2cfaec5c11 100644 --- a/src/qemu_conf.h +++ b/src/qemu_conf.h @@ -44,6 +44,8 @@ enum qemud_cmd_flags { QEMUD_CMD_FLAG_DRIVE = (1 << 3), QEMUD_CMD_FLAG_DRIVE_BOOT = (1 << 4), QEMUD_CMD_FLAG_NAME = (1 << 5), + QEMUD_CMD_FLAG_UUID = (1 << 6), + QEMUD_CMD_FLAG_DOMID = (1 << 7), /* Xenner only */ }; /* Main driver state */ diff --git a/src/qemu_driver.c b/src/qemu_driver.c index f974b132ad7d8b45c003dfd653b63d46e5c74acd..cea071ae390758982d52273a461c12ab6df6c76f 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -860,10 +860,12 @@ static int qemudStartVMDaemon(virConnectPtr conn, return -1; } + vm->def->id = driver->nextvmid++; if (qemudBuildCommandLine(conn, driver, vm, qemuCmdFlags, &argv, &progenv, &tapfds, &ntapfds, migrateFrom) < 0) { close(vm->logfile); + vm->def->id = -1; vm->logfile = -1; return -1; } @@ -901,10 +903,10 @@ static int qemudStartVMDaemon(virConnectPtr conn, ret = virExec(conn, argv, progenv, &keepfd, &vm->pid, vm->stdin_fd, &vm->stdout_fd, &vm->stderr_fd, VIR_EXEC_NONBLOCK); - if (ret == 0) { - vm->def->id = driver->nextvmid++; + if (ret == 0) vm->state = migrateFrom ? VIR_DOMAIN_PAUSED : VIR_DOMAIN_RUNNING; - } + else + vm->def->id = -1; for (i = 0 ; argv[i] ; i++) VIR_FREE(argv[i]); diff --git a/tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.args b/tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.args new file mode 100644 index 0000000000000000000000000000000000000000..de9a7df4d07cb59dad9bda484268d4b33a1e8a15 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.args @@ -0,0 +1 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -name QEMUGuest1 -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 -domid 6 -nographic -monitor pty -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb diff --git a/tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.xml b/tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.xml new file mode 100644 index 0000000000000000000000000000000000000000..1b37bdc6f21614e3de543280e89163d023caf633 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.xml @@ -0,0 +1,25 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 263eaec8f3636bd5f72ddd6f75bb6b7e07945b35..b6a7f68a6d13dd6ee16775fe41da4635b92d25be 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -43,7 +43,10 @@ static int testCompareXMLToArgvFiles(const char *xml, memset(&vm, 0, sizeof vm); vm.def = vmdef; - vm.def->id = -1; + if (extraFlags & QEMUD_CMD_FLAG_DOMID) + vm.def->id = 6; + else + vm.def->id = -1; vm.pid = -1; flags = QEMUD_CMD_FLAG_VNC_COLON | @@ -196,6 +199,8 @@ mymain(int argc, char **argv) DO_TEST("input-xen", 0); DO_TEST("misc-acpi", 0); DO_TEST("misc-no-reboot", 0); + DO_TEST("misc-uuid", QEMUD_CMD_FLAG_NAME | + QEMUD_CMD_FLAG_UUID | QEMUD_CMD_FLAG_DOMID); DO_TEST("net-user", 0); DO_TEST("net-virtio", 0);