render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Daniel P. Berrange a05e64
diff -rup libvirt-0.2.2/qemud/conf.c libvirt-0.2.2.new/qemud/conf.c
Daniel P. Berrange a05e64
--- libvirt-0.2.2/qemud/conf.c	2007-04-17 04:34:42.000000000 -0400
Daniel P. Berrange 338630
+++ libvirt-0.2.2.new/qemud/conf.c	2007-05-14 10:36:12.000000000 -0400
Daniel P. Berrange a05e64
@@ -245,21 +245,25 @@ static int qemudExtractVersionInfo(const
Daniel P. Berrange a05e64
     cleanup1:
Daniel P. Berrange a05e64
         _exit(-1); /* Just in case */
Daniel P. Berrange a05e64
     } else { /* Parent */
Daniel P. Berrange a05e64
-        char help[4096]; /* Ought to be enough to hold QEMU help screen */
Daniel P. Berrange 338630
-        int got, ret = -1;
Daniel P. Berrange a05e64
+        char help[8192]; /* Ought to be enough to hold QEMU help screen */
Daniel P. Berrange 338630
+        int got = 0, ret = -1;
Daniel P. Berrange a05e64
         int major, minor, micro;
Daniel P. Berrange a05e64
 
Daniel P. Berrange a05e64
         if (close(newstdout[1]) < 0)
Daniel P. Berrange a05e64
             goto cleanup2;
Daniel P. Berrange a05e64
 
Daniel P. Berrange a05e64
-    reread:
Daniel P. Berrange a05e64
-        if ((got = read(newstdout[0], help, sizeof(help)-1)) < 0) {
Daniel P. Berrange a05e64
-            if (errno == EINTR)
Daniel P. Berrange a05e64
-                goto reread;
Daniel P. Berrange a05e64
-            goto cleanup2;
Daniel P. Berrange a05e64
+        while (got < (sizeof(help)-1)) {
Daniel P. Berrange a05e64
+            int len;
Daniel P. Berrange a05e64
+            if ((len = read(newstdout[0], help+got, sizeof(help)-got-1)) <= 0) {
Daniel P. Berrange a05e64
+                if (!len)
Daniel P. Berrange a05e64
+                    break;
Daniel P. Berrange a05e64
+                if (errno == EINTR)
Daniel P. Berrange a05e64
+                    continue;
Daniel P. Berrange a05e64
+                goto cleanup2;
Daniel P. Berrange a05e64
+            }
Daniel P. Berrange a05e64
+            got += len;
Daniel P. Berrange a05e64
         }
Daniel P. Berrange a05e64
         help[got] = '\0';
Daniel P. Berrange a05e64
-
Daniel P. Berrange a05e64
         if (sscanf(help, "QEMU PC emulator version %d.%d.%d", &major,&minor, &micro) != 3) {
Daniel P. Berrange a05e64
             goto cleanup2;
Daniel P. Berrange a05e64
         }
Daniel P. Berrange a05e64
@@ -267,6 +271,8 @@ static int qemudExtractVersionInfo(const
Daniel P. Berrange a05e64
         *version = (major * 1000 * 1000) + (minor * 1000) + micro;
Daniel P. Berrange a05e64
         if (strstr(help, "-no-kqemu"))
Daniel P. Berrange a05e64
             *flags |= QEMUD_CMD_FLAG_KQEMU;
Daniel P. Berrange a05e64
+        if (strstr(help, "-no-reboot"))
Daniel P. Berrange a05e64
+            *flags |= QEMUD_CMD_FLAG_NO_REBOOT;
Daniel P. Berrange a05e64
         if (*version >= 9000)
Daniel P. Berrange a05e64
             *flags |= QEMUD_CMD_FLAG_VNC_COLON;
Daniel P. Berrange a05e64
         ret = 0;
Daniel P. Berrange a05e64
@@ -858,6 +864,22 @@ static struct qemud_vm_def *qemudParseXM
Daniel P. Berrange a05e64
     }
Daniel P. Berrange a05e64
     xmlXPathFreeObject(obj);
Daniel P. Berrange a05e64
 
Daniel P. Berrange a05e64
+
Daniel P. Berrange a05e64
+    /* See if we disable reboots */
Daniel P. Berrange a05e64
+    obj = xmlXPathEval(BAD_CAST "string(/domain/on_reboot)", ctxt);
Daniel P. Berrange a05e64
+    if ((obj == NULL) || (obj->type != XPATH_STRING) ||
Daniel P. Berrange a05e64
+        (obj->stringval == NULL) || (obj->stringval[0] == 0)) {
Daniel P. Berrange a05e64
+        def->noReboot = 0;
Daniel P. Berrange a05e64
+    } else {
Daniel P. Berrange a05e64
+        if (!strcmp((char*)obj->stringval, "destroy"))
Daniel P. Berrange a05e64
+            def->noReboot = 1;
Daniel P. Berrange a05e64
+        else
Daniel P. Berrange a05e64
+            def->noReboot = 0;
Daniel P. Berrange a05e64
+    }
Daniel P. Berrange a05e64
+    if (obj)
Daniel P. Berrange a05e64
+        xmlXPathFreeObject(obj);
Daniel P. Berrange a05e64
+
Daniel P. Berrange a05e64
+
Daniel P. Berrange a05e64
     /* Extract OS type info */
Daniel P. Berrange a05e64
     obj = xmlXPathEval(BAD_CAST "string(/domain/os/type[1])", ctxt);
Daniel P. Berrange a05e64
     if ((obj == NULL) || (obj->type != XPATH_STRING) ||
Daniel P. Berrange a05e64
@@ -1220,6 +1242,8 @@ int qemudBuildCommandLine(struct qemud_s
Daniel P. Berrange a05e64
         2 + /* cpus */
Daniel P. Berrange a05e64
         2 + /* boot device */
Daniel P. Berrange a05e64
         2 + /* monitor */
Daniel P. Berrange a05e64
+        (server->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT &&
Daniel P. Berrange a05e64
+         vm->def->noReboot ? 1 : 0) + /* no-reboot */
Daniel P. Berrange a05e64
         (vm->def->features & QEMUD_FEATURE_ACPI ? 0 : 1) + /* acpi */
Daniel P. Berrange a05e64
         (vm->def->os.kernel[0] ? 2 : 0) + /* kernel */
Daniel P. Berrange a05e64
         (vm->def->os.initrd[0] ? 2 : 0) + /* initrd */
Daniel P. Berrange a05e64
@@ -1255,6 +1279,11 @@ int qemudBuildCommandLine(struct qemud_s
Daniel P. Berrange a05e64
         goto no_memory;
Daniel P. Berrange a05e64
     if (!((*argv)[++n] = strdup("pty")))
Daniel P. Berrange a05e64
         goto no_memory;
Daniel P. Berrange a05e64
+    if (server->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT &&
Daniel P. Berrange a05e64
+        vm->def->noReboot) {
Daniel P. Berrange a05e64
+        if (!((*argv)[++n] = strdup("-no-reboot")))
Daniel P. Berrange a05e64
+            goto no_memory;
Daniel P. Berrange a05e64
+    }
Daniel P. Berrange a05e64
 
Daniel P. Berrange a05e64
     if (!(vm->def->features & QEMUD_FEATURE_ACPI)) {
Daniel P. Berrange a05e64
         if (!((*argv)[++n] = strdup("-no-acpi")))
Daniel P. Berrange a05e64
@@ -2517,6 +2546,17 @@ char *qemudGenerateXML(struct qemud_serv
Daniel P. Berrange a05e64
             goto no_memory;
Daniel P. Berrange a05e64
     }
Daniel P. Berrange a05e64
 
Daniel P. Berrange a05e64
+    if (bufferAdd(buf, "  <on_poweroff>destroy</on_poweroff>\n", -1) < 0)
Daniel P. Berrange a05e64
+        goto no_memory;
Daniel P. Berrange a05e64
+    if (def->noReboot) {
Daniel P. Berrange a05e64
+        if (bufferAdd(buf, "  <on_reboot>destroy</on_reboot>\n", -1) < 0)
Daniel P. Berrange a05e64
+            goto no_memory;
Daniel P. Berrange a05e64
+    } else {
Daniel P. Berrange a05e64
+        if (bufferAdd(buf, "  <on_reboot>restart</on_reboot>\n", -1) < 0)
Daniel P. Berrange a05e64
+            goto no_memory;
Daniel P. Berrange a05e64
+    }
Daniel P. Berrange a05e64
+    if (bufferAdd(buf, "  <on_crash>destroy</on_crash>\n", -1) < 0)
Daniel P. Berrange a05e64
+        goto no_memory;
Daniel P. Berrange a05e64
 
Daniel P. Berrange a05e64
     if (bufferAdd(buf, "  <devices>\n", -1) < 0)
Daniel P. Berrange a05e64
         goto no_memory;
Daniel P. Berrange a05e64
diff -rup libvirt-0.2.2/qemud/internal.h libvirt-0.2.2.new/qemud/internal.h
Daniel P. Berrange a05e64
--- libvirt-0.2.2/qemud/internal.h	2007-04-11 10:13:36.000000000 -0400
Daniel P. Berrange 338630
+++ libvirt-0.2.2.new/qemud/internal.h	2007-05-14 10:36:02.000000000 -0400
Daniel P. Berrange a05e64
@@ -161,6 +161,7 @@ enum qemud_vm_grapics_type {
Daniel P. Berrange a05e64
 enum qemud_cmd_flags {
Daniel P. Berrange a05e64
     QEMUD_CMD_FLAG_KQEMU = 1,
Daniel P. Berrange a05e64
     QEMUD_CMD_FLAG_VNC_COLON = 2,
Daniel P. Berrange a05e64
+    QEMUD_CMD_FLAG_NO_REBOOT = 4,
Daniel P. Berrange a05e64
 };
Daniel P. Berrange a05e64
 
Daniel P. Berrange a05e64
 
Daniel P. Berrange a05e64
@@ -191,6 +192,8 @@ struct qemud_vm_def {
Daniel P. Berrange a05e64
     int maxmem;
Daniel P. Berrange a05e64
     int vcpus;
Daniel P. Berrange a05e64
 
Daniel P. Berrange a05e64
+    int noReboot;
Daniel P. Berrange a05e64
+
Daniel P. Berrange a05e64
     struct qemud_vm_os_def os;
Daniel P. Berrange a05e64
 
Daniel P. Berrange a05e64
     int features;