From: Ben Pfaff Date: Tue, 30 Dec 2008 18:01:06 +0000 (-0800) Subject: Make datapath compile with Xen kernel. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae2a9a7560f879c79a80c0e954fbe5b372ebafc0;p=openvswitch Make datapath compile with Xen kernel. The Xen kernel is based on 2.6.18 but backports many features from later kernels. It is not always possible, therefore, to detect whether we need to use compatibility code based on LINUX_VERSION_CODE. This commit fixes the problem by using configure-time tests to check for the need for the compatibility code. Build-tested on Linux 2.6.15 through 2.6.28 with the default configuration (except that some kernels needed preemption turned off) and with Xen kernel 2.6.18-92.1.10.el5.xs5.0.0.394.644. Fixes bug #548. --- diff --git a/acinclude.m4 b/acinclude.m4 index 0036ac1b..1380940e 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1,3 +1,5 @@ +# -*- autoconf -*- + # Copyright (c) 2008 The Board of Trustees of The Leland Stanford # Junior University # @@ -61,10 +63,60 @@ AC_DEFUN([OFP_CHECK_LINUX], [ ! test -e "$path"/include/linux/autoconf.h; then AC_MSG_ERROR([Linux kernel source in $path is not configured]) fi + m4_if($3, [2.6], [OFP_CHECK_LINUX26_COMPAT]) fi AM_CONDITIONAL($5, test -n "$path") ]) +dnl OFP_GREP_IFELSE(FILE, REGEX, IF-MATCH, IF-NO-MATCH) +dnl +dnl Greps FILE for REGEX. If it matches, runs IF-MATCH, otherwise IF-NO-MATCH. +AC_DEFUN([OFP_GREP_IFELSE], [ + AC_MSG_CHECKING([whether $2 matches in $1]) + grep '$2' $1 >/dev/null 2>&1 + status=$? + case $status in + 0) + AC_MSG_RESULT([yes]) + $3 + ;; + 1) + AC_MSG_RESULT([no]) + $4 + ;; + *) + AC_MSG_ERROR([grep exited with status $status]) + ;; + esac +]) + +dnl OFP_DEFINE(NAME) +dnl +dnl Defines NAME to 1 in kcompat.h. +AC_DEFUN([OFP_DEFINE], [ + echo '#define $1 1' >> datapath/linux-2.6/kcompat.h.new +]) + +dnl OFP_CHECK_LINUX26_COMPAT +dnl +dnl Runs various Autoconf checks on the Linux 2.6 kernel source in +dnl the directory in $KSRC26. +AC_DEFUN([OFP_CHECK_LINUX26_COMPAT], [ + rm -f datapath/linux-2.6/kcompat.h.new + mkdir -p datapath/linux-2.6 + : > datapath/linux-2.6/kcompat.h.new + OFP_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_transport_header], + [OFP_DEFINE([HAVE_SKBUFF_HEADER_HELPERS])]) + OFP_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [raw], + [OFP_DEFINE([HAVE_MAC_RAW])]) + if cmp -s datapath/linux-2.6/kcompat.h.new \ + datapath/linux-2.6/kcompat.h >/dev/null 2>&1; then + rm datapath/linux-2.6/kcompat.h.new + else + mv datapath/linux-2.6/kcompat.h.new datapath/linux-2.6/kcompat.h + fi +]) + dnl Checks for --enable-hw-tables and substitutes HW_TABLES to any dnl requested hardware table modules. AC_DEFUN([OFP_CHECK_HWTABLES], diff --git a/datapath/linux-2.6/Kbuild.in b/datapath/linux-2.6/Kbuild.in index 11990026..1d405cce 100644 --- a/datapath/linux-2.6/Kbuild.in +++ b/datapath/linux-2.6/Kbuild.in @@ -20,6 +20,7 @@ else EXTRA_CFLAGS += -DBUILDNR=\"+build$(BUILDNR)\" endif EXTRA_CFLAGS += -g +EXTRA_CFLAGS += -include $(builddir)/kcompat.h # These include directories have to go before -I$(KSRC)/include. # NOSTDINC_FLAGS just happens to be a variable that goes in the diff --git a/datapath/linux-2.6/Makefile.main.in b/datapath/linux-2.6/Makefile.main.in index a93b86e0..7847c835 100644 --- a/datapath/linux-2.6/Makefile.main.in +++ b/datapath/linux-2.6/Makefile.main.in @@ -16,12 +16,13 @@ $(foreach m,$(all_modules), \ $(eval $(notdir $(s)): ; ln -s $(srcdir)/../$(s) $@))) distclean: clean + rm -f kcompat.h distdir: clean install: all: default check: all clean: - rm -f *.o *.ko *_mod.* Module.symvers *.cmd + rm -f *.o *.ko *_mod.* Module.symvers *.cmd kcompat.h.new for d in $(all_links); do if test -h $$d; then rm $$d; fi; done ifneq ($(KSRC),) diff --git a/datapath/linux-2.6/compat-2.6/include/asm-generic/bug.h b/datapath/linux-2.6/compat-2.6/include/asm-generic/bug.h index f3b54882..1d9b3140 100644 --- a/datapath/linux-2.6/compat-2.6/include/asm-generic/bug.h +++ b/datapath/linux-2.6/compat-2.6/include/asm-generic/bug.h @@ -3,10 +3,7 @@ #include_next -#include - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) - +#ifndef WARN_ON_ONCE #define WARN_ON_ONCE(condition) ({ \ static int __warned; \ int __ret_warn_once = !!(condition); \ @@ -17,7 +14,6 @@ } \ unlikely(__ret_warn_once); \ }) - -#endif /* linux kernel < 2.6.19 */ +#endif #endif diff --git a/datapath/linux-2.6/compat-2.6/include/linux/icmp.h b/datapath/linux-2.6/compat-2.6/include/linux/icmp.h index b02678b8..89b354e4 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/icmp.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/icmp.h @@ -3,16 +3,11 @@ #include_next -#include -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) - -#ifdef __KERNEL__ +#ifndef HAVE_SKBUFF_HEADER_HELPERS static inline struct icmphdr *icmp_hdr(const struct sk_buff *skb) { return (struct icmphdr *)skb_transport_header(skb); } -#endif /* __KERNEL__ */ - -#endif /* linux kernel < 2.6.22 */ +#endif #endif diff --git a/datapath/linux-2.6/compat-2.6/include/linux/if_arp.h b/datapath/linux-2.6/compat-2.6/include/linux/if_arp.h index b21c98d5..e48d6ba0 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/if_arp.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/if_arp.h @@ -3,18 +3,13 @@ #include_next -#include -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) - -#ifdef __KERNEL__ +#ifndef HAVE_SKBUFF_HEADER_HELPERS #include static inline struct arphdr *arp_hdr(const struct sk_buff *skb) { return (struct arphdr *)skb_network_header(skb); } -#endif /* __KERNEL__ */ - -#endif /* linux kernel < 2.6.22 */ +#endif /* !HAVE_SKBUFF_HEADER_HELPERS */ #endif diff --git a/datapath/linux-2.6/compat-2.6/include/linux/ip.h b/datapath/linux-2.6/compat-2.6/include/linux/ip.h index 9c8d5746..36765396 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/ip.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/ip.h @@ -3,12 +3,7 @@ #include_next -#include -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) - -#ifdef __KERNEL__ -#include - +#ifndef HAVE_SKBUFF_HEADER_HELPERS static inline struct iphdr *ip_hdr(const struct sk_buff *skb) { return (struct iphdr *)skb_network_header(skb); @@ -18,8 +13,6 @@ static inline unsigned int ip_hdrlen(const struct sk_buff *skb) { return ip_hdr(skb)->ihl * 4; } -#endif /* __KERNEL__ */ - -#endif /* linux kernel < 2.6.22 */ +#endif /* !HAVE_SKBUFF_HEADER_HELPERS */ #endif diff --git a/datapath/linux-2.6/compat-2.6/include/linux/ipv6.h b/datapath/linux-2.6/compat-2.6/include/linux/ipv6.h index e735a780..25a5431a 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/ipv6.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/ipv6.h @@ -3,18 +3,11 @@ #include_next -#include -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) - -#ifdef __KERNEL__ -#include - +#ifndef HAVE_SKBUFF_HEADER_HELPERS static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb) { return (struct ipv6hdr *)skb_network_header(skb); } -#endif /* __KERNEL__ */ - -#endif /* linux kernel < 2.6.22 */ +#endif #endif diff --git a/datapath/linux-2.6/compat-2.6/include/linux/skbuff.h b/datapath/linux-2.6/compat-2.6/include/linux/skbuff.h index a0111fb2..1464e728 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/skbuff.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/skbuff.h @@ -17,19 +17,21 @@ static inline void kfree_skb_maybe_null(struct sk_buff *skb) #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) +#ifndef CHECKSUM_PARTIAL /* Note that CHECKSUM_PARTIAL is not implemented, but this allows us to at * least test against it: see update_csum() in forward.c. */ #define CHECKSUM_PARTIAL 3 +#endif +#ifndef CHECKSUM_COMPLETE #define CHECKSUM_COMPLETE CHECKSUM_HW -#endif /* linux kernel < 2.6.19 */ - - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) +#endif +#ifdef HAVE_MAC_RAW #define mac_header mac.raw #define network_header nh.raw +#endif +#ifndef HAVE_SKBUFF_HEADER_HELPERS static inline unsigned char *skb_transport_header(const struct sk_buff *skb) { return skb->h.raw; @@ -87,6 +89,6 @@ static inline void skb_copy_to_linear_data(struct sk_buff *skb, { memcpy(skb->data, from, len); } -#endif /* linux kernel < 2.6.22 */ +#endif /* !HAVE_SKBUFF_HEADER_HELPERS */ #endif diff --git a/datapath/linux-2.6/compat-2.6/include/linux/tcp.h b/datapath/linux-2.6/compat-2.6/include/linux/tcp.h index e8b51977..6fad1933 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/tcp.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/tcp.h @@ -3,10 +3,7 @@ #include_next -#include -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) - -#ifdef __KERNEL__ +#ifndef HAVE_SKBUFF_HEADER_HELPERS static inline struct tcphdr *tcp_hdr(const struct sk_buff *skb) { return (struct tcphdr *)skb_transport_header(skb); @@ -16,8 +13,6 @@ static inline unsigned int tcp_hdrlen(const struct sk_buff *skb) { return tcp_hdr(skb)->doff * 4; } -#endif /* __KERNEL__ */ - -#endif /* linux kernel < 2.6.22 */ +#endif /* !HAVE_SKBUFF_HEADER_HELPERS */ #endif diff --git a/datapath/linux-2.6/compat-2.6/include/linux/udp.h b/datapath/linux-2.6/compat-2.6/include/linux/udp.h index ffab1873..6fe4721b 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/udp.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/udp.h @@ -3,17 +3,11 @@ #include_next -#include -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) - -#ifdef __KERNEL__ +#ifndef HAVE_SKBUFF_HEADER_HELPERS static inline struct udphdr *udp_hdr(const struct sk_buff *skb) { return (struct udphdr *)skb_transport_header(skb); } -#endif /* __KERNEL__ */ - - -#endif /* linux kernel < 2.6.22 */ +#endif /* HAVE_SKBUFF_HEADER_HELPERS */ #endif