From ea32310720d9d07eeb668e404a5062bd9bce832d Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Tue, 20 Apr 2010 22:42:35 -0700 Subject: [PATCH] datapath: Define kmemdup() for kernels older than 2.6.19 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 | 2 ++ datapath/linux-2.6/Modules.mk | 2 ++ .../linux-2.6/compat-2.6/include/linux/slab.h | 10 +++++++++ datapath/linux-2.6/compat-2.6/kmemdup.c | 22 +++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 datapath/linux-2.6/compat-2.6/include/linux/slab.h create mode 100644 datapath/linux-2.6/compat-2.6/kmemdup.c diff --git a/acinclude.m4 b/acinclude.m4 index 23097b2e..64384d90 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -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 diff --git a/datapath/linux-2.6/Modules.mk b/datapath/linux-2.6/Modules.mk index 1e22a088..75e885c1 100644 --- a/datapath/linux-2.6/Modules.mk +++ b/datapath/linux-2.6/Modules.mk @@ -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 index 00000000..5c54c18a --- /dev/null +++ b/datapath/linux-2.6/compat-2.6/include/linux/slab.h @@ -0,0 +1,10 @@ +#ifndef __LINUX_SLAB_WRAPPER_H +#define __LINUX_SLAB_WRAPPER_H 1 + +#include_next + +#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 index 00000000..b5188fdb --- /dev/null +++ b/datapath/linux-2.6/compat-2.6/kmemdup.c @@ -0,0 +1,22 @@ +#ifndef HAVE_KMEMDUP + +#include +#include + +/** + * 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 -- 2.30.2