File: patch-kernel

package info (click to toggle)
drbd8 2%3A8.3.13-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,520 kB
  • sloc: ansic: 30,486; xml: 4,399; sh: 2,219; makefile: 741; perl: 587
file content (175 lines) | stat: -rw-r--r-- 5,455 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
#
# Create a patch against a kernel tree which adds the DRBD sources.
#
# original script:
# Copyright (C) 2003 Kees Cook, OSDL
# kees@osdl.org, http://developer.osdl.org/kees/
#
# heavily modified:
# Copyright (C) 2003-2008 LINBIT Information Technologies GmbH, Lars Ellenberg
# lars@linbit.com, http://www.linbit.com
#
# 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
#

set -o errexit
fatal() { echo >&2 "$*" ; exit 1; }

KERNEL=$1
  DRBD=$2
    [[ $3 == full ]] && INCREMENT=false || INCREMENT=true

#
# naive sanity checks
#

test -n "$KERNEL" -a -n "$DRBD" ||
	fatal "Usage: kernel-patch KERNEL_SOURCE_DIR DRBD_PACKAGE_DIR"
test -d "$KERNEL/Documentation" ||
	fatal "Please specify the kernel tree to patch"
test -d "$DRBD/documentation"   ||
	fatal "Please specify the drbd tree to use"

# only allow 2.6
KDIR_PATCHLEVEL=$(grep "^PATCHLEVEL = " $KERNEL/Makefile | cut -d " " -f 3)
test "$KDIR_PATCHLEVEL" = 6 ||
	fatal "wrong kernel version patchlevel ($KDIR_PATCHLEVEL), expected 6."

test -e "$KERNEL/drivers/connector/Kconfig" ||
	fatal "this won't work: your kernel lacks the connector :("
#
# convert to absolute pathnames
# maybe even do a "test -L $d && readlink $d" first?
# as a side effect this makes sure that KERNEL and DRBD are accessible
# directories, and do not contain whitespace or something...
#
KERNEL=$(cd $KERNEL && pwd)
KERNEL_BASE=$(basename $KERNEL)

DRBD=$(cd $DRBD && pwd)
DRBD_BASE=$KERNEL_BASE-drbd
DRBD_SUB=$DRBD_BASE/drivers/block/drbd

#
# Seems that there are mktemp proggies out there that do not understand
# the -d flag (reportedly Slackware 9.1); We do not need to waste
# entropy anyways.
#
mymktemp() { umask 077 && mkdir "$1" && cd "$1" && pwd; }
TEMPDIR=$(mymktemp /tmp/drbd-patch-$$) ||
	fatal "Could Could not make temp directory"
# cleanup on              0   1   2    3   13   15
trap 'rm -r "$TEMPDIR"' EXIT HUP INT QUIT PIPE TERM

#
# Set up our work area
#

cd $TEMPDIR

# Set up the diff directories
for d in include/linux drivers/block/drbd arch/um ; do
	mkdir -p $KERNEL_BASE/$d
	mkdir -p $DRBD_BASE/$d
done

#
# Pull in the base drbd source
#
include_linux="drbd.h drbd_limits.h drbd_nl.h drbd_tag_magic.h lru_cache.h"
drbd_source="drbd_actlog.c drbd_bitmap.c drbd_buildtag.c
	drbd_wrappers.h drbd_int.h drbd_main.c drbd_nl.c drbd_proc.c
	drbd_receiver.c drbd_req.c drbd_req.h drbd_strings.c drbd_worker.c
	lru_cache.c drbd_vli.h drbd_tracing.c drbd_tracing.h"

# clean it first
make -s -C $DRBD/drbd clean

# FIXME drbd_config.h probably needs different treatment,
# these should become Kconfig options or go away!
cp -a $DRBD/drbd/linux/drbd_config.h	$DRBD_BASE/include/linux/
for f in $include_linux; do
	cp -a $DRBD/drbd/linux/$f	$DRBD_BASE/include/linux/
done

cp -a $DRBD/drbd/Kconfig		$DRBD_SUB
for f in $drbd_source; do
	cp -a $DRBD/drbd/$f		$DRBD_SUB
done
# we also need the in-kernel-tree Makefile
# remove the trace of the connector backport
sed -e '/^ifndef CONFIG_CONNECTOR/,/^$/d' \
	< $DRBD/drbd/Makefile-2.6 > $DRBD_SUB/Makefile

sed -e '/#ifndef DRBD_MAJOR/','/#endif/d' \
	< $DRBD/drbd/drbd_int.h > $DRBD_SUB/drbd_int.h

# and, in case this kernel was already patched:
if test -e $KERNEL/include/linux/drbd.h ; then
	$INCREMENT || fatal "drbd already in $KERNEL"
	cp -a $KERNEL/include/linux/drbd*.h \
	 $KERNEL_BASE/include/linux/
	cp -a $KERNEL/drivers/block/drbd/{*.[ch],Makefile,Kconfig} \
	 $KERNEL_BASE/drivers/block/drbd/
	# remove dangling drbd.mod.c, if it hangs around
	rm -f $KERNEL_BASE/drivers/block/drbd/drbd.mod.c
fi

# Bring over the current kernel Kconfig and Makefile
for f in drivers/block/{Kconfig,Makefile} arch/um/Kconfig_block \
		include/linux/major.h; do
	test -e $KERNEL/$f || continue
	cp -a $KERNEL/$f $KERNEL_BASE/$f
	cp -a $KERNEL/$f $DRBD_BASE/$f
done

# 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

patch_Kconfig() { sed -e '
/^config BLK_DEV_NBD/,/^config /{
	/^config BLK_DEV_NBD/i\
source "drivers/block/drbd/Kconfig"\

}'
}
for f in drivers/block/Kconfig arch/um/Kconfig_block ; do
	test -e $KERNEL_BASE/$f || continue
	grep drbd/ $DRBD_BASE/$f >/dev/null && continue
	patch_Kconfig < $KERNEL_BASE/$f > $DRBD_BASE/$f
done

patch_major.h() { sed -e '/#define RTF_MAJOR/i\
#define DRBD_MAJOR		147' < $KERNEL_BASE/$f > $DRBD_BASE/$f
}
f=include/linux/major.h
patch_major.h < $KERNEL_BASE/$f > $DRBD_BASE/$f

#
# finally: Create diff!
#
if diff -uNrp $KERNEL_BASE $DRBD_BASE ; then
	echo "$KERNEL already completely patched."
	test /proc/$$/fd/1 -ef /proc/$$/fd/2 ||
		echo >&2 "$KERNEL already completely patched."
fi

cd -
## clean up done by trap on EXIT