Support <on_reboot> action

This commit is contained in:
Daniel P. Berrange 2007-05-03 16:10:40 +00:00
parent 3ac6e102da
commit 6723c50b5c
3 changed files with 58 additions and 7 deletions

View File

@ -1,4 +1,10 @@
Thu May 3 18:00:41 CEST 2007 Daiel Veillard <veillard@redhat.com> Thu May 3 12:09:41 EST 2007 Daniel P. Berange <berrange@redhat.com>
* qemud/conf.c, qemud/internal.c: Read upto 8k from QEMU
help output. Support the <on_reboot> attribute to set the
-no-reboot flag in QEMU
Thu May 3 18:00:41 CEST 2007 Daniel Veillard <veillard@redhat.com>
* src/virsh.c: fix help for dumpxml and net-dumpxml commands * src/virsh.c: fix help for dumpxml and net-dumpxml commands
based on Chris Wright feedback based on Chris Wright feedback

View File

@ -245,19 +245,24 @@ static int qemudExtractVersionInfo(const char *qemu, int *version, int *flags) {
cleanup1: cleanup1:
_exit(-1); /* Just in case */ _exit(-1); /* Just in case */
} else { /* Parent */ } else { /* Parent */
char help[4096]; /* Ought to be enough to hold QEMU help screen */ char help[8192]; /* Ought to be enough to hold QEMU help screen */
int got, ret = -1; int got, ret = -1;
int major, minor, micro; int major, minor, micro;
if (close(newstdout[1]) < 0) if (close(newstdout[1]) < 0)
goto cleanup2; goto cleanup2;
reread: while (got < (sizeof(help)-1)) {
if ((got = read(newstdout[0], help, sizeof(help)-1)) < 0) { int len;
if ((len = read(newstdout[0], help+got, sizeof(help)-got-1)) <= 0) {
if (!len)
break;
if (errno == EINTR) if (errno == EINTR)
goto reread; continue;
goto cleanup2; goto cleanup2;
} }
got += len;
}
help[got] = '\0'; help[got] = '\0';
if (sscanf(help, "QEMU PC emulator version %d.%d.%d", &major,&minor, &micro) != 3) { if (sscanf(help, "QEMU PC emulator version %d.%d.%d", &major,&minor, &micro) != 3) {
@ -267,6 +272,8 @@ static int qemudExtractVersionInfo(const char *qemu, int *version, int *flags) {
*version = (major * 1000 * 1000) + (minor * 1000) + micro; *version = (major * 1000 * 1000) + (minor * 1000) + micro;
if (strstr(help, "-no-kqemu")) if (strstr(help, "-no-kqemu"))
*flags |= QEMUD_CMD_FLAG_KQEMU; *flags |= QEMUD_CMD_FLAG_KQEMU;
if (strstr(help, "-no-reboot"))
*flags |= QEMUD_CMD_FLAG_NO_REBOOT;
if (*version >= 9000) if (*version >= 9000)
*flags |= QEMUD_CMD_FLAG_VNC_COLON; *flags |= QEMUD_CMD_FLAG_VNC_COLON;
ret = 0; ret = 0;
@ -858,6 +865,22 @@ static struct qemud_vm_def *qemudParseXML(struct qemud_server *server,
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
/* See if we disable reboots */
obj = xmlXPathEval(BAD_CAST "string(/domain/on_reboot)", ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
def->noReboot = 0;
} else {
if (!strcmp((char*)obj->stringval, "destroy"))
def->noReboot = 1;
else
def->noReboot = 0;
}
if (obj)
xmlXPathFreeObject(obj);
/* Extract OS type info */ /* Extract OS type info */
obj = xmlXPathEval(BAD_CAST "string(/domain/os/type[1])", ctxt); obj = xmlXPathEval(BAD_CAST "string(/domain/os/type[1])", ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) || if ((obj == NULL) || (obj->type != XPATH_STRING) ||
@ -1220,6 +1243,8 @@ int qemudBuildCommandLine(struct qemud_server *server,
2 + /* cpus */ 2 + /* cpus */
2 + /* boot device */ 2 + /* boot device */
2 + /* monitor */ 2 + /* monitor */
(server->qemuCmdFlags & QEMUD_CMD_FLAG_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 */
(vm->def->os.initrd[0] ? 2 : 0) + /* initrd */ (vm->def->os.initrd[0] ? 2 : 0) + /* initrd */
@ -1256,6 +1281,12 @@ int qemudBuildCommandLine(struct qemud_server *server,
if (!((*argv)[++n] = strdup("pty"))) if (!((*argv)[++n] = strdup("pty")))
goto no_memory; goto no_memory;
if (server->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT &&
vm->def->noReboot) {
if (!((*argv)[++n] = strdup("-no-reboot")))
goto no_memory;
}
if (!(vm->def->features & QEMUD_FEATURE_ACPI)) { if (!(vm->def->features & QEMUD_FEATURE_ACPI)) {
if (!((*argv)[++n] = strdup("-no-acpi"))) if (!((*argv)[++n] = strdup("-no-acpi")))
goto no_memory; goto no_memory;
@ -2517,6 +2548,17 @@ char *qemudGenerateXML(struct qemud_server *server,
goto no_memory; goto no_memory;
} }
if (bufferAdd(buf, " <on_poweroff>destroy</on_poweroff>\n", -1) < 0)
goto no_memory;
if (def->noReboot) {
if (bufferAdd(buf, " <on_reboot>destroy</on_reboot>\n", -1) < 0)
goto no_memory;
} else {
if (bufferAdd(buf, " <on_reboot>restart</on_reboot>\n", -1) < 0)
goto no_memory;
}
if (bufferAdd(buf, " <on_crash>destroy</on_crash>\n", -1) < 0)
goto no_memory;
if (bufferAdd(buf, " <devices>\n", -1) < 0) if (bufferAdd(buf, " <devices>\n", -1) < 0)
goto no_memory; goto no_memory;

View File

@ -161,6 +161,7 @@ enum qemud_vm_grapics_type {
enum qemud_cmd_flags { enum qemud_cmd_flags {
QEMUD_CMD_FLAG_KQEMU = 1, QEMUD_CMD_FLAG_KQEMU = 1,
QEMUD_CMD_FLAG_VNC_COLON = 2, QEMUD_CMD_FLAG_VNC_COLON = 2,
QEMUD_CMD_FLAG_NO_REBOOT = 4,
}; };
@ -191,6 +192,8 @@ struct qemud_vm_def {
int maxmem; int maxmem;
int vcpus; int vcpus;
int noReboot;
struct qemud_vm_os_def os; struct qemud_vm_os_def os;
int features; int features;