[DRBD-user] [patch] in-kernel builds

Kees Cook kees at osdl.org
Sat Apr 17 01:58:34 CEST 2004

Note: "permalinks" may not be as permanent as we would like,
direct links of old sources may well be a few messages off.


Hi!  It's me again.  :)

This is a patch against 0.7 CVS for three things:
- add a "Kconfig" file for drbd being built in a kernel tree
- inside/outside kernel tree test added to Makefile
- script to generate a kernel patch against a kernel tree and drbd tree

With these, I think anyone can build drbd inside and outside of a kernel 
tree, monolithic or modular.

-- 
Kees Cook
Open Source Development Lab
kees at osdl.org
-------------- next part --------------
diff -uNrp drbd/drbd/Kconfig drbd-0.7-kees/drbd/Kconfig
--- drbd/drbd/Kconfig	1969-12-31 16:00:00.000000000 -0800
+++ drbd-0.7-kees/drbd/Kconfig	2004-04-16 16:40:15.000000000 -0700
@@ -0,0 +1,27 @@
+#
+# DRBD device driver configuration
+#
+config BLK_DEV_DRBD
+	tristate "Distributed redundant block device support"
+	depends on NET && PROC_FS && !BLK_DEV_NBD
+	---help---
+	  Drbd is a block device which is designed to build high availability
+	  clusters.  This is done by mirroring a whole block device via (a
+	  dedicated) network.  You could see it as a network RAID 1.
+
+	  This device replaces the regular "network block device".
+
+	  Each device (drbd provides more than one of these devices) has a
+	  state, which can be 'primary' or 'secondary'. On the node with the
+	  primary device the application is supposed to run and to access the
+	  device (/dev/nbX). Every write is sent to the local 'lower level
+	  block device' and to the node with the device in 'secondary' state.
+	  The secondary device simply writes the data to its lower level block
+	  device. Reads are always carried out locally.
+
+	  Drbd management is done through user-space tools.
+
+	  http://www.drbd.org/
+
+	  If unsure, say N.
+
diff -uNrp drbd/drbd/Makefile drbd-0.7-kees/drbd/Makefile
--- drbd/drbd/Makefile	2004-04-08 23:53:43.000000000 -0700
+++ drbd-0.7-kees/drbd/Makefile	2004-04-16 16:53:31.000000000 -0700
@@ -32,8 +32,14 @@ ifneq ($(KERNELRELEASE),)
     $(error "won't compile with this kernel version")
   endif
 
-  # override needed for 2.4.X kbuild
-  override CFLAGS    += -I$(DRBDSRC)
+  # override needed for 2.4.X+ kbuild
+  ifneq ($(DRBDSRC),)
+    # outside the kernel tree
+    override CFLAGS    += -I$(DRBDSRC)
+  else
+    # inside the kernel tree
+    EXTRA_CFLAGS += -Idrivers/block/drbd
+  endif
 
   obj-m     += drbd.o
   drbd-objs := drbd_fs.o drbd_main.o drbd_proc.o drbd_dsender.o \
diff -uNrp drbd/scripts/patch-kernel drbd-0.7-kees/scripts/patch-kernel
--- drbd/scripts/patch-kernel	1969-12-31 16:00:00.000000000 -0800
+++ drbd-0.7-kees/scripts/patch-kernel	2004-04-16 16:40:03.000000000 -0700
@@ -0,0 +1,99 @@
+#!/bin/bash
+#
+# Create a patch against a kernel tree which adds the DRBD sources.
+#
+# $Id:$
+#
+# Copyright (C) 2003 Kees Cook, OSDL
+# kees at osdl.org, http://developer.osdl.org/kees/
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+# http://www.gnu.org/copyleft/gpl.html
+#
+KERNEL=$1
+DRBD=$2
+if [ -z "$KERNEL" ] || [ -z "$DRBD" ]; then
+	echo "Usage: kernel-patch KERNEL_SOURCE_DIR DRBD_PACKAGE_DIR" >&2
+	exit 1
+fi
+if [ ! -d "$KERNEL/Documentation" ]; then
+	echo "Please specify the kernel tree to patch" >&2
+	exit 1
+fi
+KERNEL=`(cd $KERNEL && pwd)`
+KERNEL_BASE=`basename $KERNEL`
+
+if [ ! -d "$DRBD/documentation" ]; then
+	echo "Please specify the drbd tree to use" >&2
+	exit 1
+fi
+DRBD=`(cd $DRBD && pwd)`
+DRBD_BASE="$KERNEL_BASE"-drbd
+
+TEMPDIR=`mktemp -d /tmp/drbd-patch-XXXXXX`
+if [ $? -gt 0 ]; then
+	echo "Could not make temp directory" >&2
+	exit 1
+fi
+
+# Set up our work area
+cd $TEMPDIR || exit 1
+
+# Set up the diff directories
+mkdir -p $KERNEL_BASE/drivers/block || exit 1
+mkdir -p $DRBD_BASE/drivers/block || exit 1
+
+# Pull in the base drbd source
+cp -a $DRBD/drbd $DRBD_BASE/drivers/block/ || exit 1
+# Convert the Makefile to just what's needed in 2.6
+# ... nothing?
+
+# Bring over the current kernel Kconfig and Makefiles
+cp -a $KERNEL/drivers/block/{Kconfig,Makefile} $KERNEL_BASE/drivers/block || exit 1
+cp -a $KERNEL/drivers/block/{Kconfig,Makefile} $DRBD_BASE/drivers/block || exit 1
+
+# Add drbd to the block drivers Makefile and Kconfig if we need to
+grep drbd/ $DRBD_BASE/drivers/block/Makefile >/dev/null || \
+	echo 'obj-$(CONFIG_BLK_DEV_DRBD)     += drbd/' >> \
+		$DRBD_BASE/drivers/block/Makefile \
+	|| exit 1
+grep drbd/ $DRBD_BASE/drivers/block/Kconfig >/dev/null || \
+	perl -pi -e 'if ($go && /^config /) {
+			print "source \"drivers/block/drbd/Kconfig\"\n\n";
+			$go=0;
+		  } elsif (/^config BLK_DEV_NBD/) {
+			$go=1;
+		  }' $DRBD_BASE/drivers/block/Kconfig \
+	|| exit 1
+
+# Create diff!
+diff -uNrp --exclude=CVS $KERNEL_BASE $DRBD_BASE && exit 1
+
+# Clean up kernel stub
+rm $KERNEL_BASE/drivers/block/{Kconfig,Makefile} || exit 1
+rmdir $KERNEL_BASE/drivers/block || exit 1
+rmdir $KERNEL_BASE/drivers || exit 1
+rmdir $KERNEL_BASE || exit 1
+
+# Clean up drbd copies
+cd $DRBD_BASE/drivers/block || exit 1
+rm -r Kconfig Makefile drbd || exit 1
+cd $TEMPDIR || exit 1
+rmdir $DRBD_BASE/drivers/block || exit 1
+rmdir $DRBD_BASE/drivers || exit 1
+rmdir $DRBD_BASE || exit 1
+
+cd / || exit 1
+rmdir $TEMPDIR


More information about the drbd-user mailing list