[CentOS] qemu-kvm-0.15 + CentOS 5.6 + vanilla 2.6.35.14 (working, patch included)

Tue Aug 23 09:07:43 UTC 2011
Walter Haidinger <walter at doxlock.com>

Hi!

Just in case somebody else needs this. Below is a patch which
allows building qemu-kvm-0.15 unter CentOS 5.6 with vanilla
kernel 2.6.35.14 and (optionally) vde2 [1].

FYI: qemu-kvm-0.15 compiles fine on CentOS 6 with distro-kernel,
     no patches needed.

For CentOS 5.6, unpack 0.15 qemu-kvm tarball [2], apply the path
below, configure and compile. Make sure to export the kernel include
path before building, otherwise the kernel mman-common.h header
won't be found:
export CPATH=/lib/modules/2.6.35.14/build/include

The patch also adds some #error pragmas to make sure that
KSM is used. This isn't a requirement to run, though.

If you'd like to use vde2 too, then additionally export the paths to
the vde2 installation (here: /opt/vde2) before configure (if vde2 is
not installed in /opt/vde2 then change your paths accordingly):
export CCFLAGS="-I/opt/vde2/include"
export LDFLAGS="-L/opt/vde2/lib"
export LD_LIBRARY_PATH="/opt/vde2/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"

With the above, ./configure --enable-vde works (for me).

I'm posting this here, rather than on a kvm list, because this is
rather CentOS 5 specific, IMHO.

Anyways, if you reply to this, please be sure to add a CC: to my email
address. While I am subscribed to this list, your email might get buried
by the list traffic. Thanks.

Best regards,
Walter

References:
[1] http://vde.sourceforge.net/
[2] http://sourceforge.net/projects/kvm/files/qemu-kvm/0.15.0/qemu-kvm-0.15.0.tar.gz/download

PS: The g_strcmp0() function was ripped from the URL below, just happened to be 
    on top of Google's search results. (c) therefore of authors "Sysadmin Ramblings".
    http://ramblings.narrabilis.com/patches/nautilus-dropbox-0.6.3-puias.patch

--- qemu-kvm-0.15.0/exec.c.orig 2011-08-19 11:36:04.000000000 +0200
+++ qemu-kvm-0.15.0/exec.c      2011-08-19 11:36:35.000000000 +0200
@@ -72,6 +72,15 @@
 //#define DEBUG_IOPORT
 //#define DEBUG_SUBPAGE
 
+#include <asm-generic/mman-common.h>
+#ifndef MADV_MERGEABLE
+#error MADV_MERGEABLE
+#endif 
+
+#ifndef QEMU_MADV_MERGEABLE
+#error QEMU_MADV_MERGEABLE
+#endif
+
 #if !defined(CONFIG_USER_ONLY)
 /* TB consistency checks only implemented for usermode emulation.  */
 #undef DEBUG_TB_CHECK
--- qemu-kvm-0.15.0/qemu-common.h.orig  2011-08-19 11:34:22.000000000 +0200
+++ qemu-kvm-0.15.0/qemu-common.h       2011-08-19 11:17:18.000000000 +0200
@@ -33,6 +33,7 @@
 #include <sys/time.h>
 #include <assert.h>
 #include <signal.h>
+#include <asm-generic/mman-common.h>
 
 #ifdef _WIN32
 #include "qemu-os-win32.h"
--- qemu-kvm-0.15.0/osdep.h.orig        2011-08-19 11:34:22.000000000 +0200
+++ qemu-kvm-0.15.0/osdep.h     2011-08-19 11:17:18.000000000 +0200
@@ -10,6 +10,11 @@
 
 #include <sys/time.h>
 
+#include <asm-generic/mman-common.h>
+#ifndef MADV_MERGEABLE
+#error MADV_MERGEABLE undefined
+#endif 
+
 #ifndef glue
 #define xglue(x, y) x ## y
 #define glue(x, y) xglue(x, y)
@@ -95,6 +100,11 @@
 
 #define QEMU_MADV_INVALID -1
 
+#include "config-host.h"
+#ifndef CONFIG_MADVISE
+#error CONFIG_MADVISE undefined
+#endif
+
 #if defined(CONFIG_MADVISE)
 
 #define QEMU_MADV_WILLNEED  MADV_WILLNEED
@@ -102,11 +112,13 @@
 #ifdef MADV_DONTFORK
 #define QEMU_MADV_DONTFORK  MADV_DONTFORK
 #else
+#error QEMU_MADV_DONTFORK undefined
 #define QEMU_MADV_DONTFORK  QEMU_MADV_INVALID
 #endif
 #ifdef MADV_MERGEABLE
 #define QEMU_MADV_MERGEABLE MADV_MERGEABLE
 #else
+#error MADV_MERGEABLE undefined
 #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID
 #endif
--- qemu-kvm-0.15.0/qemu-ga.c.orig      2011-08-19 11:34:22.000000000 +0200
+++ qemu-kvm-0.15.0/qemu-ga.c   2011-08-19 11:17:18.000000000 +0200
@@ -33,6 +33,9 @@
 #define QGA_BAUDRATE_DEFAULT B38400 /* for isa-serial channels */
 #define QGA_TIMEOUT_DEFAULT 30*1000 /* ms */
 
+/* add g_strcmp0() here which isn't available in CentOS 5 glib library */
+int g_strcmp0(const char *str1, const char *str2);     /* prototype */
+
 struct GAState {
     JSONMessageParser parser;
     GMainLoop *main_loop;
@@ -134,6 +137,15 @@
     s->logging_enabled = true;
 }
 
+/* add g_strcmp0() here which isn't available in CentOS 5 glib library */
+int g_strcmp0(const char *str1, const char *str2)
+{
+     if( str1 == NULL && str2 == NULL ) return 0;
+     if( str1 == NULL ) return -1;
+     if( str2 == NULL ) return 1;
+     return g_strcasecmp(str1, str2);
+};
+
 static void ga_log(const gchar *domain, GLogLevelFlags level,
                    const gchar *msg, gpointer opaque)
 {