[DRBD-cvs] svn commit by lars - r2678 - in trunk: drbd drbd/linux scripts - add some auto-adjust magic this now should compile out

drbd-cvs at lists.linbit.com drbd-cvs at lists.linbit.com
Tue Jan 9 22:21:13 CET 2007


Author: lars
Date: 2007-01-09 22:21:12 +0100 (Tue, 09 Jan 2007)
New Revision: 2678

Modified:
   trunk/drbd/drbd_compat_wrappers.h
   trunk/drbd/drbd_int.h
   trunk/drbd/drbd_main.c
   trunk/drbd/linux/drbd_config.h
   trunk/scripts/adjust_drbd_config_h.sh
Log:
add some auto-adjust magic
this now should compile out of the box
 against various vendor kernel-header packages
 as well as kernel.org up to 2.6.18

(crypto api changed in 2.6.19, so we need to adjust that later...)


Modified: trunk/drbd/drbd_compat_wrappers.h
===================================================================
--- trunk/drbd/drbd_compat_wrappers.h	2007-01-09 16:39:21 UTC (rev 2677)
+++ trunk/drbd/drbd_compat_wrappers.h	2007-01-09 21:21:12 UTC (rev 2678)
@@ -167,8 +167,18 @@
 	return ret;
 }
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
+#ifdef DEFINE_SOCK_CREATE_KERN
+#define sock_create_kern sock_create
+#endif
 
+#ifdef USE_KMEM_CACHE_S
+typedef struct kmem_cache_s drbd_kmem_cache_t;
+#else
+typedef struct kmem_cache drbd_kmem_cache_t;
+#endif
+
+#ifdef NEED_BACKPORT_OF_ATOMIC_ADD
+
 #if defined(__x86_64__)
 
 static __inline__ int atomic_add_return(int i, atomic_t *v)
@@ -225,7 +235,7 @@
 #define atomic_inc_return(v)  (atomic_add_return(1,v))
 #define atomic_dec_return(v)  (atomic_sub_return(1,v))
 
-#else 
+#else
 # error "You need to copy/past atomic_inc_return()/atomic_dec_return() here"
 # error "for your architecture. (Hint: Kernels after 2.6.10 have those"
 # error "by default! Using a later kernel might be less effort!)"

Modified: trunk/drbd/drbd_int.h
===================================================================
--- trunk/drbd/drbd_int.h	2007-01-09 16:39:21 UTC (rev 2677)
+++ trunk/drbd/drbd_int.h	2007-01-09 21:21:12 UTC (rev 2678)
@@ -1151,11 +1151,15 @@
 extern void drbd_bm_unlock    (drbd_dev *mdev);
 #define drbd_bm_lock(mdev)    __drbd_bm_lock(mdev, __FILE__, __LINE__ )
 
+// drbd_main.c
 
-// drbd_main.c
+/* needs to be included here,
+ * because of kmem_cache_t weirdness */
+#include "drbd_compat_wrappers.h"
+
 extern int minor_count;
-extern kmem_cache_t *drbd_request_cache;
-extern kmem_cache_t *drbd_ee_cache;
+extern drbd_kmem_cache_t *drbd_request_cache;
+extern drbd_kmem_cache_t *drbd_ee_cache;
 extern mempool_t *drbd_request_mempool;
 extern mempool_t *drbd_ee_mempool;
 
@@ -1407,8 +1411,6 @@
  * inline helper functions
  *************************/
 
-#include "drbd_compat_wrappers.h"
-
 #define peer_mask role_mask
 #define pdsk_mask disk_mask
 #define susp_mask 1

Modified: trunk/drbd/drbd_main.c
===================================================================
--- trunk/drbd/drbd_main.c	2007-01-09 16:39:21 UTC (rev 2677)
+++ trunk/drbd/drbd_main.c	2007-01-09 21:21:12 UTC (rev 2678)
@@ -125,8 +125,8 @@
  */
 struct Drbd_Conf **minor_table = NULL;
 
-kmem_cache_t *drbd_request_cache;
-kmem_cache_t *drbd_ee_cache;
+drbd_kmem_cache_t *drbd_request_cache;
+drbd_kmem_cache_t *drbd_ee_cache;
 mempool_t *drbd_request_mempool;
 mempool_t *drbd_ee_mempool;
 

Modified: trunk/drbd/linux/drbd_config.h
===================================================================
--- trunk/drbd/linux/drbd_config.h	2007-01-09 16:39:21 UTC (rev 2677)
+++ trunk/drbd/linux/drbd_config.h	2007-01-09 21:21:12 UTC (rev 2678)
@@ -54,7 +54,19 @@
 
 // RedHat's 2.6.9 kernels have the gfp_t type. Mainline has this feature
 // since 2.6.16. If you build for RedHat enable the line below.
-// #define KERNEL_HAS_GFP_T
+#define KERNEL_HAS_GFP_T
 
+// kernel.org has atomic_add_return since 2.6.10. some vendor kernels
+// have it backported, though. Others don't.
+//#define NEED_BACKPORT_OF_ATOMIC_ADD
 
+// 2.6.something has deprecated kmem_cache_t
+// some older still use it.
+// some have it defined as struct kmem_cache_s, some as struct kmem_cache
+//#define USE_KMEM_CACHE_S
+
+// 2.6.something has sock_create_kern (SE-linux security context stuff)
+// some older distribution kernels don't.
+//#define DEFINE_SOCK_CREATE_KERN
+
 #endif

Modified: trunk/scripts/adjust_drbd_config_h.sh
===================================================================
--- trunk/scripts/adjust_drbd_config_h.sh	2007-01-09 16:39:21 UTC (rev 2677)
+++ trunk/scripts/adjust_drbd_config_h.sh	2007-01-09 21:21:12 UTC (rev 2678)
@@ -21,21 +21,34 @@
 }
 
 test -n "$KDIR"
+
+# ok, now we have a KDIR; cd into it, in case we detect relative pathes
+pushd $KDIR
+
 KDIR=${KDIR%/}
 if test -z "$O"; then
-	O=$KDIR;
+	## just in case...
+	## detect if $KDIR points to something which is actually $O ...
+	X=$( make help | sed -ne '/ -C .* O=.* help$/p' | tr -s ' ' )
+	if [[ -n $X ]]; then
+		KDIR=${X##* -C }; KDIR=${KDIR%% *}; KDIR=$(cd $KDIR && pwd)
+		O=${X##* O=}; O=${O%% *}; O=$(cd $KDIR && cd $O && pwd)
+	else
+		O=$KDIR;
+	fi
 else
 	O=${O%/}
 fi
 
 # some paranoia: check that all files are where we expect them
 ls > /dev/null \
-$KDIR/{Makefile,include/linux/{gfp,types}.h}
+$KDIR/{Makefile,include/linux/{gfp,types,slab,net}.h}
 ls > /dev/null \
 $O/{.config,Makefile,include/linux/version.h}
-# test -e $KDIR/include/asm/bitops.h ||
-# test -e $O/include2/asm/bitops.h   ||
-# exit 1
+test -e $O/include/asm/atomic.h  ||
+test -e $O/include/asm/arch/atomic.h  ||
+test -e $O/include2/asm/atomic.h ||
+exit 1
 
 if grep_q "^PATCHLEVEL *= *6" $KDIR/Makefile ; then
   # do we have gfp_t?
@@ -44,20 +57,52 @@
   else
     have_gfp_t=0
   fi
+  # stupid vendor kernels grrr...
+  have_atomic_add=0
+  # btw, don't ask why I don't use grep -qs $a $b $c 
+  # it simply does not work always...
+  for f in $O/include/asm/atomic.h \
+    $O/include/asm/arch/atomic.h \
+    $O/include2/asm/atomic.h
+  do
+    if grep_q "atomic_add_return" $f; then
+      have_atomic_add=1
+      break
+    fi
+  done
+  if grep_q "typedef.*kmem_cache_s" $KDIR/include/linux/slab.h ; then
+    have_kmem_cache_s=1
+  else
+    have_kmem_cache_s=0
+  fi
+  if grep_q "sock_create_kern" $KDIR/include/linux/net.h ; then
+    have_sock_create_kern=1
+  else
+    have_sock_create_kern=0
+  fi
 else
     # not a 2.6. kernel. just leave it alone...
     exit 0
 fi
 
+# and back do drbd source
+popd
+
 test -e ./linux/drbd_config.h.orig || cp ./linux/drbd_config.h{,.orig}
 
 perl -pe "
  s{.*(#define KERNEL_HAS_GFP_T.*)}
-  { ( $have_gfp_t ? '' : '//' ) . \$1}e;" \
+  { ( $have_gfp_t ? '' : '//' ) . \$1}e;
+ s{.*(#define NEED_BACKPORT_OF_ATOMIC_ADD.*)}
+  { ( $have_atomic_add ? '//' : '' ) . \$1}e;
+ s{.*(#define USE_KMEM_CACHE_S.*)}
+  { ( $have_kmem_cache_s ? '' : '//' ) . \$1}e;
+ s{.*(#define DEFINE_SOCK_CREATE_KERN.*)}
+  { ( $have_sock_create_kern ? '//' : '' ) . \$1}e;
+ " \
 	  < ./linux/drbd_config.h \
 	  > ./linux/drbd_config.h.new
 
-
 if ! DIFF=$(diff -s -U0 ./linux/drbd_config.h{,.new}) ; then
   mv ./linux/drbd_config.h{.new,}
   sed -e 's/^/  /' <<___



More information about the drbd-cvs mailing list