]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: use default machine type if missing it in qemu command line
authorGuannan Ren <gren@redhat.com>
Thu, 1 Nov 2012 11:43:03 +0000 (19:43 +0800)
committerGuannan Ren <gren@redhat.com>
Fri, 2 Nov 2012 04:55:29 +0000 (12:55 +0800)
BZ:https://bugzilla.redhat.com/show_bug.cgi?id=871273
when using virsh qemu-attach to attach an existing qemu process,
if it misses the -M option in qemu command line, libvirtd crashed
because the NULL value of def->os.machine in later use.

Example:
/usr/libexec/qemu-kvm -name foo \
                      -cdrom /var/lib/libvirt/images/boot.img \
                      -monitor unix:/tmp/demo,server,nowait \

error: End of file while reading data: Input/output error
error: Failed to reconnect to the hypervisor

This patch tries to set default machine type if the value of
def->os.machine is still NULL after qemu command line parsing.

src/qemu/qemu_capabilities.c
src/qemu/qemu_command.c
src/qemu/qemu_driver.c

index 9396a9b704d54396d952222b6fe597a66ef5b7b3..5c4f5185b7136fb59cc16e1f06ecf7724837a59c 100644 (file)
@@ -1845,10 +1845,12 @@ no_memory:
 
 const char *qemuCapsGetCanonicalMachine(qemuCapsPtr caps,
                                         const char *name)
-
 {
     size_t i;
 
+    if (!name)
+        return NULL;
+
     for (i = 0 ; i < caps->nmachineTypes ; i++) {
         if (!caps->machineAliases[i])
             continue;
index fe99f5d64a9a1944a63b67ef5aaff9d181970e2c..0b6d2f8143be22784ad3f49711030acf9a2520af 100644 (file)
@@ -8768,6 +8768,17 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
         }
     }
 
+    if (!def->os.machine) {
+        const char *defaultMachine =
+                        virCapabilitiesDefaultGuestMachine(caps,
+                                                           def->os.type,
+                                                           def->os.arch,
+                                                           virDomainVirtTypeToString(def->virtType));
+        if (defaultMachine != NULL)
+            if (!(def->os.machine = strdup(defaultMachine)))
+                goto no_memory;
+    }
+
     if (!nographics && def->ngraphics == 0) {
         virDomainGraphicsDefPtr sdl;
         const char *display = qemuFindEnv(progenv, "DISPLAY");
index 267bbf175c6c178bac97c91c12a73249d22c095e..15f421182525dab4422b3ad41f71323e5c415832 100644 (file)
@@ -1517,9 +1517,12 @@ static int qemudNumDomains(virConnectPtr conn) {
 static int
 qemuCanonicalizeMachine(virDomainDefPtr def, qemuCapsPtr caps)
 {
-    const char *canon = qemuCapsGetCanonicalMachine(caps, def->os.machine);
+    const char *canon;
 
-    if (canon != def->os.machine) {
+    if (!(canon = qemuCapsGetCanonicalMachine(caps, def->os.machine)))
+        return 0;
+
+    if (STRNEQ(canon, def->os.machine)) {
         char *tmp;
         if (!(tmp = strdup(canon))) {
             virReportOOMError();