[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] PATCH: Fix QEMU arg detection for kvm >= 85



The -help output from KVM >= 85 is now large than we expected. This patch
increases the buffer from 8k to 64k when reading help. It also provides
more detailed error messages should something go wrong in the future.

Two examples of improved error reporting

# virsh -c qemu:///system start VirtTest
error: Failed to start domain VirtTest
error: Unable to read QEMU help output: Value too large for defined data type

# virsh -c qemu:///system start VirtTest
error: Failed to start domain VirtTest
error: internal error cannot parse QEMU version number in 'QEMU PC emulator version 0.9.1 (kvm-79), Copyright (c) 2003-2008 Fabrice Bellard'


Daniel

Index: src/qemu_conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_conf.c,v
retrieving revision 1.145
diff -u -p -r1.145 qemu_conf.c
--- src/qemu_conf.c	8 May 2009 10:07:16 -0000	1.145
+++ src/qemu_conf.c	8 May 2009 10:37:22 -0000
@@ -431,18 +431,28 @@ int qemudExtractVersionInfo(const char *
         return -1;
 
     char *help = NULL;
-    enum { MAX_HELP_OUTPUT_SIZE = 8192 };
+    enum { MAX_HELP_OUTPUT_SIZE = 1024*64 };
     int len = virFileReadLimFD(newstdout, MAX_HELP_OUTPUT_SIZE, &help);
-    if (len < 0)
+    if (len < 0) {
+        virReportSystemError(NULL, errno, "%s",
+                             _("Unable to read QEMU help output"));
         goto cleanup2;
+    }
 
     if (sscanf(help, "QEMU PC emulator version %u.%u.%u (kvm-%u)",
                &major, &minor, &micro, &kvm_version) != 4)
         kvm_version = 0;
 
-    if (!kvm_version && sscanf(help, "QEMU PC emulator version %u.%u.%u",
-               &major, &minor, &micro) != 3)
+    if (!kvm_version &&
+        sscanf(help, "QEMU PC emulator version %u.%u.%u",
+               &major, &minor, &micro) != 3) {
+        char *eol = strchr(help, '\n');
+        if (eol) *eol = '\0';
+        qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                         _("cannot parse QEMU version number in '%s'"),
+                         help);
         goto cleanup2;
+    }
 
     version = (major * 1000 * 1000) + (minor * 1000) + micro;
 
Index: src/qemu_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_driver.c,v
retrieving revision 1.236
diff -u -p -r1.236 qemu_driver.c
--- src/qemu_driver.c	8 May 2009 10:11:14 -0000	1.236
+++ src/qemu_driver.c	8 May 2009 10:37:22 -0000
@@ -1379,12 +1379,8 @@ static int qemudStartVMDaemon(virConnect
 
     if (qemudExtractVersionInfo(emulator,
                                 NULL,
-                                &qemuCmdFlags) < 0) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
-                         _("Cannot determine QEMU argv syntax %s"),
-                         emulator);
+                                &qemuCmdFlags) < 0)
         goto cleanup;
-    }
 
     if (qemuPrepareHostDevices(conn, vm->def) < 0)
         goto cleanup;
@@ -3703,12 +3699,8 @@ static int qemudDomainChangeEjectableMed
 
     if (qemudExtractVersionInfo(vm->def->emulator,
                                 NULL,
-                                &qemuCmdFlags) < 0) {
-        qemudReportError(conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
-                         _("Cannot determine QEMU argv syntax %s"),
-                         vm->def->emulator);
+                                &qemuCmdFlags) < 0)
         return -1;
-    }
 
     if (qemuCmdFlags & QEMUD_CMD_FLAG_DRIVE) {
         if (!(devname = qemudDiskDeviceName(conn, newdisk)))


-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]