datapath: Define kmemdup() for kernels older than 2.6.19
authorJustin Pettit <jpettit@nicira.com>
Wed, 21 Apr 2010 05:42:35 +0000 (22:42 -0700)
committerJustin Pettit <jpettit@nicira.com>
Thu, 22 Apr 2010 10:37:45 +0000 (03:37 -0700)
The new GRE code requires the kmemdup function, but it's not available
on 2.6.18 kernels.  It has been backported to Xen, so only define it for
non-Xen kernels older than 2.6.19.

acinclude.m4
datapath/linux-2.6/Modules.mk
datapath/linux-2.6/compat-2.6/include/linux/slab.h [new file with mode: 0644]
datapath/linux-2.6/compat-2.6/kmemdup.c [new file with mode: 0644]

index 23097b2e3a04968de230f7630f2ae88783474928..64384d90fb4ba69234a7c5727b6e66e15c5e4abe 100644 (file)
@@ -162,6 +162,8 @@ AC_DEFUN([OVS_CHECK_LINUX26_COMPAT], [
                   [OVS_DEFINE([HAVE_NLA_GET_BE16])])
   OVS_GREP_IFELSE([$KSRC26/include/linux/in.h], [ipv4_is_multicast],
                   [OVS_DEFINE([HAVE_IPV4_IS_MULTICAST])])
+  OVS_GREP_IFELSE([$KSRC26/include/linux/string.h $KSRC26/include/linux/slab.h],
+                  [kmemdup], [OVS_DEFINE([HAVE_KMEMDUP])])
   # Check for the proto_data_valid member in struct sk_buff.  The [^@]
   # is necessary because some versions of this header remove the
   # member but retain the kerneldoc comment that describes it (which
index 1e22a088cef16ba68fcf44b8e3617068dc2fe611..75e885c19e1f09143b9c66d5fa8842d69ed3cbd2 100644 (file)
@@ -3,6 +3,7 @@ openvswitch_sources += \
        linux-2.6/compat-2.6/dev-openvswitch.c \
        linux-2.6/compat-2.6/genetlink-openvswitch.c \
        linux-2.6/compat-2.6/ip_output-openvswitch.c \
+       linux-2.6/compat-2.6/kmemdup.c \
        linux-2.6/compat-2.6/random32.c \
        linux-2.6/compat-2.6/skbuff-openvswitch.c
 openvswitch_headers += \
@@ -34,6 +35,7 @@ openvswitch_headers += \
        linux-2.6/compat-2.6/include/linux/rculist.h \
        linux-2.6/compat-2.6/include/linux/rtnetlink.h \
        linux-2.6/compat-2.6/include/linux/skbuff.h \
+       linux-2.6/compat-2.6/include/linux/slab.h \
        linux-2.6/compat-2.6/include/linux/tcp.h \
        linux-2.6/compat-2.6/include/linux/timer.h \
        linux-2.6/compat-2.6/include/linux/types.h \
diff --git a/datapath/linux-2.6/compat-2.6/include/linux/slab.h b/datapath/linux-2.6/compat-2.6/include/linux/slab.h
new file mode 100644 (file)
index 0000000..5c54c18
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef __LINUX_SLAB_WRAPPER_H
+#define __LINUX_SLAB_WRAPPER_H 1
+
+#include_next <linux/slab.h>
+
+#ifndef HAVE_KMEMDUP
+extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
+#endif
+
+#endif
diff --git a/datapath/linux-2.6/compat-2.6/kmemdup.c b/datapath/linux-2.6/compat-2.6/kmemdup.c
new file mode 100644 (file)
index 0000000..b5188fd
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef HAVE_KMEMDUP
+
+#include <linux/slab.h>
+#include <linux/string.h>
+
+/**
+ * kmemdup - duplicate region of memory
+ *
+ * @src: memory region to duplicate
+ * @len: memory region length
+ * @gfp: GFP mask to use
+ */
+void *kmemdup(const void *src, size_t len, gfp_t gfp)
+{
+       void *p;
+
+       p = kmalloc(len, gfp);
+       if (p)
+               memcpy(p, src, len);
+       return p;
+}
+#endif