Linux 3.2 compat, security_inode_init_security()
[zfs.git] / config / kernel.m4
1 dnl #
2 dnl # Default ZFS kernel configuration 
3 dnl #
4 AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
5         ZFS_AC_KERNEL
6         ZFS_AC_SPL
7         ZFS_AC_KERNEL_CONFIG
8         ZFS_AC_KERNEL_BDEV_BLOCK_DEVICE_OPERATIONS
9         ZFS_AC_KERNEL_TYPE_FMODE_T
10         ZFS_AC_KERNEL_KOBJ_NAME_LEN
11         ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH
12         ZFS_AC_KERNEL_OPEN_BDEV_EXCLUSIVE
13         ZFS_AC_KERNEL_INVALIDATE_BDEV_ARGS
14         ZFS_AC_KERNEL_BDEV_LOGICAL_BLOCK_SIZE
15         ZFS_AC_KERNEL_BIO_EMPTY_BARRIER
16         ZFS_AC_KERNEL_BIO_FAILFAST
17         ZFS_AC_KERNEL_BIO_FAILFAST_DTD
18         ZFS_AC_KERNEL_REQ_FAILFAST_MASK
19         ZFS_AC_KERNEL_BIO_END_IO_T_ARGS
20         ZFS_AC_KERNEL_BIO_RW_SYNC
21         ZFS_AC_KERNEL_BIO_RW_SYNCIO
22         ZFS_AC_KERNEL_REQ_SYNC
23         ZFS_AC_KERNEL_BLK_END_REQUEST
24         ZFS_AC_KERNEL_BLK_FETCH_REQUEST
25         ZFS_AC_KERNEL_BLK_REQUEUE_REQUEST
26         ZFS_AC_KERNEL_BLK_RQ_BYTES
27         ZFS_AC_KERNEL_BLK_RQ_POS
28         ZFS_AC_KERNEL_BLK_RQ_SECTORS
29         ZFS_AC_KERNEL_GET_DISK_RO
30         ZFS_AC_KERNEL_RQ_IS_SYNC
31         ZFS_AC_KERNEL_RQ_FOR_EACH_SEGMENT
32         ZFS_AC_KERNEL_CONST_XATTR_HANDLER
33         ZFS_AC_KERNEL_XATTR_HANDLER_GET
34         ZFS_AC_KERNEL_XATTR_HANDLER_SET
35         ZFS_AC_KERNEL_FSYNC
36         ZFS_AC_KERNEL_EVICT_INODE
37         ZFS_AC_KERNEL_NR_CACHED_OBJECTS
38         ZFS_AC_KERNEL_FREE_CACHED_OBJECTS
39         ZFS_AC_KERNEL_INSERT_INODE_LOCKED
40         ZFS_AC_KERNEL_D_OBTAIN_ALIAS
41         ZFS_AC_KERNEL_CHECK_DISK_SIZE_CHANGE
42         ZFS_AC_KERNEL_TRUNCATE_SETSIZE
43         ZFS_AC_KERNEL_6ARGS_SECURITY_INODE_INIT_SECURITY
44         ZFS_AC_KERNEL_CALLBACK_SECURITY_INODE_INIT_SECURITY
45         ZFS_AC_KERNEL_MOUNT_NODEV
46         ZFS_AC_KERNEL_SHRINK
47         ZFS_AC_KERNEL_BDI
48         ZFS_AC_KERNEL_BDI_SETUP_AND_REGISTER
49         ZFS_AC_KERNEL_SET_NLINK
50
51         AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
52                 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
53         ])
54         AC_SUBST(KERNELMAKE_PARAMS)
55
56
57         dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
58         dnl # compiler options are added by the kernel build system.
59         KERNELCPPFLAGS="$KERNELCPPFLAGS $NO_UNUSED_BUT_SET_VARIABLE"
60         KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
61         KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
62
63         AC_SUBST(KERNELCPPFLAGS)
64 ])
65
66 dnl #
67 dnl # Detect name used for Module.symvers file in kernel
68 dnl #
69 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
70         modpost=$LINUX/scripts/Makefile.modpost
71         AC_MSG_CHECKING([kernel file name for module symbols])
72         AS_IF([test -f "$modpost"], [
73                 AS_IF([grep -q Modules.symvers $modpost], [
74                         LINUX_SYMBOLS=Modules.symvers
75                 ], [
76                         LINUX_SYMBOLS=Module.symvers
77                 ])
78
79                 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
80                         AC_MSG_ERROR([
81         *** Please make sure the kernel devel package for your distribution
82         *** is installed.  If your building with a custom kernel make sure the
83         *** kernel is configured, built, and the '--with-linux=PATH' configure
84         *** option refers to the location of the kernel source.])
85                 ])
86         ], [
87                 LINUX_SYMBOLS=NONE
88         ])
89         AC_MSG_RESULT($LINUX_SYMBOLS)
90         AC_SUBST(LINUX_SYMBOLS)
91 ])
92
93 dnl #
94 dnl # Detect the kernel to be built against
95 dnl #
96 AC_DEFUN([ZFS_AC_KERNEL], [
97         AC_ARG_WITH([linux],
98                 AS_HELP_STRING([--with-linux=PATH],
99                 [Path to kernel source]),
100                 [kernelsrc="$withval"])
101
102         AC_ARG_WITH(linux-obj,
103                 AS_HELP_STRING([--with-linux-obj=PATH],
104                 [Path to kernel build objects]),
105                 [kernelbuild="$withval"])
106
107         AC_MSG_CHECKING([kernel source directory])
108         AS_IF([test -z "$kernelsrc"], [
109                 AS_IF([test -e "/lib/modules/$(uname -r)/source"], [
110                         headersdir="/lib/modules/$(uname -r)/source"
111                         sourcelink=$(readlink -f "$headersdir")
112                 ], [test -e "/lib/modules/$(uname -r)/build"], [
113                         headersdir="/lib/modules/$(uname -r)/build"
114                         sourcelink=$(readlink -f "$headersdir")
115                 ], [
116                         sourcelink=$(ls -1d /usr/src/kernels/* \
117                                      /usr/src/linux-* \
118                                      2>/dev/null | grep -v obj | tail -1)
119                 ])
120
121                 AS_IF([test -n "$sourcelink" && test -e ${sourcelink}], [
122                         kernelsrc=`readlink -f ${sourcelink}`
123                 ], [
124                         AC_MSG_RESULT([Not found])
125                         AC_MSG_ERROR([
126         *** Please make sure the kernel devel package for your distribution
127         *** is installed then try again.  If that fails you can specify the
128         *** location of the kernel source with the '--with-linux=PATH' option.])
129                 ])
130         ], [
131                 AS_IF([test "$kernelsrc" = "NONE"], [
132                         kernsrcver=NONE
133                 ])
134         ])
135
136         AC_MSG_RESULT([$kernelsrc])
137         AC_MSG_CHECKING([kernel build directory])
138         AS_IF([test -z "$kernelbuild"], [
139                 AS_IF([test -e "/lib/modules/$(uname -r)/build"], [
140                         kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
141                 ], [test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}], [
142                         kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
143                 ], [test -d ${kernelsrc}-obj/${target_cpu}/default], [
144                         kernelbuild=${kernelsrc}-obj/${target_cpu}/default
145                 ], [test -d `dirname ${kernelsrc}`/build-${target_cpu}], [
146                         kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
147                 ], [
148                         kernelbuild=${kernelsrc}
149                 ])
150         ])
151         AC_MSG_RESULT([$kernelbuild])
152
153         AC_MSG_CHECKING([kernel source version])
154         utsrelease1=$kernelbuild/include/linux/version.h
155         utsrelease2=$kernelbuild/include/linux/utsrelease.h
156         utsrelease3=$kernelbuild/include/generated/utsrelease.h
157         AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1], [
158                 utsrelease=linux/version.h
159         ], [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2], [
160                 utsrelease=linux/utsrelease.h
161         ], [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3], [
162                 utsrelease=generated/utsrelease.h
163         ])
164
165         AS_IF([test "$utsrelease"], [
166                 kernsrcver=`(echo "#include <$utsrelease>";
167                              echo "kernsrcver=UTS_RELEASE") |
168                              cpp -I $kernelbuild/include |
169                              grep "^kernsrcver=" | cut -d \" -f 2`
170
171                 AS_IF([test -z "$kernsrcver"], [
172                         AC_MSG_RESULT([Not found])
173                         AC_MSG_ERROR([*** Cannot determine kernel version.])
174                 ])
175         ], [
176                 AC_MSG_RESULT([Not found])
177                 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
178         ])
179
180         AC_MSG_RESULT([$kernsrcver])
181
182         LINUX=${kernelsrc}
183         LINUX_OBJ=${kernelbuild}
184         LINUX_VERSION=${kernsrcver}
185
186         AC_SUBST(LINUX)
187         AC_SUBST(LINUX_OBJ)
188         AC_SUBST(LINUX_VERSION)
189
190         ZFS_AC_MODULE_SYMVERS
191 ])
192
193 dnl #
194 dnl # Detect name used for the additional SPL Module.symvers file.  If one
195 dnl # does not exist this is likely because the SPL has been configured
196 dnl # but not built.  To allow recursive builds a good guess is made as to
197 dnl # what this file will be named based on what it is named in the kernel
198 dnl # build products.  This file will first be used at link time so if
199 dnl # the guess is wrong the build will fail then.  This unfortunately
200 dnl # means the ZFS package does not contain a reliable mechanism to
201 dnl # detect symbols exported by the SPL at configure time.
202 dnl #
203 AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
204         AC_MSG_CHECKING([spl file name for module symbols])
205         AS_IF([test -r $SPL_OBJ/Module.symvers], [
206                 SPL_SYMBOLS=Module.symvers
207         ], [test -r $SPL_OBJ/Modules.symvers], [
208                 SPL_SYMBOLS=Modules.symvers
209         ], [test -r $SPL_OBJ/module/Module.symvers], [
210                 SPL_SYMBOLS=Module.symvers
211         ], [test -r $SPL_OBJ/module/Modules.symvers], [
212                 SPL_SYMBOLS=Modules.symvers
213         ], [
214                 SPL_SYMBOLS=$LINUX_SYMBOLS
215         ])
216
217         AC_MSG_RESULT([$SPL_SYMBOLS])
218         AC_SUBST(SPL_SYMBOLS)
219 ])
220
221 dnl #
222 dnl # Detect the SPL module to be built against
223 dnl #
224 AC_DEFUN([ZFS_AC_SPL], [
225         AC_ARG_WITH([spl],
226                 AS_HELP_STRING([--with-spl=PATH],
227                 [Path to spl source]),
228                 [splsrc="$withval"])
229
230         AC_ARG_WITH([spl-obj],
231                 AS_HELP_STRING([--with-spl-obj=PATH],
232                 [Path to spl build objects]),
233                 [splbuild="$withval"])
234
235
236         AC_MSG_CHECKING([spl source directory])
237         AS_IF([test -z "$splsrc"], [
238                 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
239                             2>/dev/null | tail -1`
240
241                 AS_IF([test -z "$sourcelink" || test ! -e $sourcelink], [
242                         sourcelink=../spl
243                 ])
244
245                 AS_IF([test -e $sourcelink], [
246                         splsrc=`readlink -f ${sourcelink}`
247                 ], [
248                         AC_MSG_RESULT([Not found])
249                         AC_MSG_ERROR([
250         *** Please make sure the spl devel package for your distribution
251         *** is installed then try again.  If that fails you can specify the
252         *** location of the spl source with the '--with-spl=PATH' option.])
253                 ])
254         ], [
255                 AS_IF([test "$splsrc" = "NONE"], [
256                         splbuild=NONE
257                         splsrcver=NONE
258                 ])
259         ])
260
261         AC_MSG_RESULT([$splsrc])
262         AC_MSG_CHECKING([spl build directory])
263         AS_IF([test -z "$splbuild"], [
264                 splbuild=${splsrc}
265         ])
266         AC_MSG_RESULT([$splbuild])
267
268         AC_MSG_CHECKING([spl source version])
269         AS_IF([test -r $splbuild/spl_config.h &&
270                 fgrep -q SPL_META_VERSION $splbuild/spl_config.h], [
271
272                 splsrcver=`(echo "#include <spl_config.h>";
273                             echo "splsrcver=SPL_META_VERSION") |
274                             cpp -I $splbuild |
275                             grep "^splsrcver=" | cut -d \" -f 2`
276         ])
277
278         AS_IF([test -z "$splsrcver"], [
279                 AC_MSG_RESULT([Not found])
280                 AC_MSG_ERROR([
281         *** Cannot determine the version of the spl source.
282         *** Please prepare the spl source before running this script])
283         ])
284
285         AC_MSG_RESULT([$splsrcver])
286
287         SPL=${splsrc}
288         SPL_OBJ=${splbuild}
289         SPL_VERSION=${splsrcver}
290
291         AC_SUBST(SPL)
292         AC_SUBST(SPL_OBJ)
293         AC_SUBST(SPL_VERSION)
294
295         ZFS_AC_SPL_MODULE_SYMVERS
296 ])
297
298 dnl #
299 dnl # Certain kernel build options are not supported.  These must be
300 dnl # detected at configure time and cause a build failure.  Otherwise
301 dnl # modules may be successfully built that behave incorrectly.
302 dnl #
303 dnl # CONFIG_PREEMPT - Preempt kernels require special handling.
304 dnl #
305 dnl # There are certain kernel build options which when enabled are
306 dnl # completely incompatible with non GPL kernel modules.  It is best
307 dnl # to detect these at configure time and fail with a clear error
308 dnl # rather than build everything and fail during linking.
309 dnl #
310 dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
311 dnl #
312 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
313
314         ZFS_LINUX_CONFIG([PREEMPT],
315                 AC_MSG_ERROR([
316         *** Kernel built with CONFIG_PREEMPT which is not supported.
317         *** You must rebuild your kernel without this option.]), [])
318
319         AS_IF([test "$ZFS_META_LICENSE" = CDDL], [
320                 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
321                 AC_MSG_ERROR([
322         *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is
323         *** incompatible with the CDDL license.  You must rebuild
324         *** your kernel without this option.]), [])
325         ])
326
327         AS_IF([test "$ZFS_META_LICENSE" = GPL], [
328                 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
329                         [Define to 1 if licensed under the GPL])
330         ])
331 ])
332
333 dnl #
334 dnl # ZFS_LINUX_CONFTEST
335 dnl #
336 AC_DEFUN([ZFS_LINUX_CONFTEST], [
337 cat confdefs.h - <<_ACEOF >conftest.c
338 $1
339 _ACEOF
340 ])
341
342 dnl #
343 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
344 dnl #
345 m4_define([ZFS_LANG_PROGRAM], [
346 $1
347 int
348 main (void)
349 {
350 dnl Do *not* indent the following line: there may be CPP directives.
351 dnl Don't move the `;' right after for the same reason.
352 $2
353   ;
354   return 0;
355 }
356 ])
357
358 dnl #
359 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
360 dnl #
361 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
362         m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
363         rm -Rf build && mkdir -p build
364         echo "obj-m := conftest.o" >build/Makefile
365         AS_IF(
366                 [AC_TRY_COMMAND(cp conftest.c build && make [$2] -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
367                 [$4],
368                 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
369         )
370         rm -Rf build
371 ])
372
373 dnl #
374 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
375 dnl #
376 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
377         [ZFS_LINUX_COMPILE_IFELSE(
378         [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
379         [modules],
380         [test -s build/conftest.o],
381         [$3], [$4])
382 ])
383
384 dnl #
385 dnl # ZFS_LINUX_CONFIG
386 dnl #
387 AC_DEFUN([ZFS_LINUX_CONFIG],
388         [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
389         ZFS_LINUX_TRY_COMPILE([
390                 #include <linux/module.h>
391         ],[
392                 #ifndef CONFIG_$1
393                 #error CONFIG_$1 not #defined
394                 #endif
395         ],[
396                 AC_MSG_RESULT([yes])
397                 $2
398         ],[
399                 AC_MSG_RESULT([no])
400                 $3
401         ])
402 ])
403
404 dnl #
405 dnl # ZFS_CHECK_SYMBOL_EXPORT
406 dnl # check symbol exported or not
407 dnl #
408 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
409         [AC_MSG_CHECKING([whether symbol $1 is exported])
410         grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
411                 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
412         rc=$?
413         AS_IF([test $rc -ne 0], [
414                 export=0
415                 for file in $2; do
416                         grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
417                         rc=$?
418                         AS_IF([test $rc -eq 0], [
419                                 export=1
420                                 break;
421                         ])
422                 done
423                 AS_IF([test $export -eq 0], [
424                         AC_MSG_RESULT([no])
425                         $4
426                 ], [
427                         AC_MSG_RESULT([yes])
428                         $3
429                 ])
430         ], [
431                 AC_MSG_RESULT([yes])
432                 $3
433         ])
434 ])