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EL_RQ_FOR_EACH_SEGMENT
39 ZFS_AC_KERNEL_CONST_XATTR_HANDLER
40 ZFS_AC_KERNEL_XATTR_HANDLER_GET
41 ZFS_AC_KERNEL_XATTR_HANDLER_SET
42 ZFS_AC_KERNEL_SHOW_OPTIONS
44 ZFS_AC_KERNEL_EVICT_INODE
45 ZFS_AC_KERNEL_NR_CACHED_OBJECTS
46 ZFS_AC_KERNEL_FREE_CACHED_OBJECTS
47 ZFS_AC_KERNEL_FALLOCATE
48 ZFS_AC_KERNEL_CREATE_UMODE_T
49 ZFS_AC_KERNEL_AUTOMOUNT
50 ZFS_AC_KERNEL_INSERT_INODE_LOCKED
51 ZFS_AC_KERNEL_D_OBTAIN_ALIAS
52 ZFS_AC_KERNEL_CHECK_DISK_SIZE_CHANGE
53 ZFS_AC_KERNEL_TRUNCATE_SETSIZE
54 ZFS_AC_KERNEL_6ARGS_SECURITY_INODE_INIT_SECURITY
55 ZFS_AC_KERNEL_CALLBACK_SECURITY_INODE_INIT_SECURITY
56 ZFS_AC_KERNEL_MOUNT_NODEV
59 ZFS_AC_KERNEL_BDI_SETUP_AND_REGISTER
60 ZFS_AC_KERNEL_SET_NLINK
62 AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
63 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
65 AC_SUBST(KERNELMAKE_PARAMS)
68 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
69 dnl # compiler options are added by the kernel build system.
70 KERNELCPPFLAGS="$KERNELCPPFLAGS $NO_UNUSED_BUT_SET_VARIABLE"
71 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
72 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
74 AC_SUBST(KERNELCPPFLAGS)
78 dnl # Detect name used for Module.symvers file in kernel
80 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
81 modpost=$LINUX/scripts/Makefile.modpost
82 AC_MSG_CHECKING([kernel file name for module symbols])
83 AS_IF([test -f "$modpost"], [
84 AS_IF([grep -q Modules.symvers $modpost], [
85 LINUX_SYMBOLS=Modules.symvers
87 LINUX_SYMBOLS=Module.symvers
90 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
92 *** Please make sure the kernel devel package for your distribution
93 *** is installed. If your building with a custom kernel make sure the
94 *** kernel is configured, built, and the '--with-linux=PATH' configure
95 *** option refers to the location of the kernel source.])
100 AC_MSG_RESULT($LINUX_SYMBOLS)
101 AC_SUBST(LINUX_SYMBOLS)
105 dnl # Detect the kernel to be built against
107 AC_DEFUN([ZFS_AC_KERNEL], [
109 AS_HELP_STRING([--with-linux=PATH],
110 [Path to kernel source]),
111 [kernelsrc="$withval"])
113 AC_ARG_WITH(linux-obj,
114 AS_HELP_STRING([--with-linux-obj=PATH],
115 [Path to kernel build objects]),
116 [kernelbuild="$withval"])
118 AC_MSG_CHECKING([kernel source directory])
119 AS_IF([test -z "$kernelsrc"], [
120 AS_IF([test -e "/lib/modules/$(uname -r)/source"], [
121 headersdir="/lib/modules/$(uname -r)/source"
122 sourcelink=$(readlink -f "$headersdir")
123 ], [test -e "/lib/modules/$(uname -r)/build"], [
124 headersdir="/lib/modules/$(uname -r)/build"
125 sourcelink=$(readlink -f "$headersdir")
127 sourcelink=$(ls -1d /usr/src/kernels/* \
129 2>/dev/null | grep -v obj | tail -1)
132 AS_IF([test -n "$sourcelink" && test -e ${sourcelink}], [
133 kernelsrc=`readlink -f ${sourcelink}`
135 AC_MSG_RESULT([Not found])
137 *** Please make sure the kernel devel package for your distribution
138 *** is installed then try again. If that fails you can specify the
139 *** location of the kernel source with the '--with-linux=PATH' option.])
142 AS_IF([test "$kernelsrc" = "NONE"], [
147 AC_MSG_RESULT([$kernelsrc])
148 AC_MSG_CHECKING([kernel build directory])
149 AS_IF([test -z "$kernelbuild"], [
150 AS_IF([test -e "/lib/modules/$(uname -r)/build"], [
151 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
152 ], [test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}], [
153 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
154 ], [test -d ${kernelsrc}-obj/${target_cpu}/default], [
155 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
156 ], [test -d `dirname ${kernelsrc}`/build-${target_cpu}], [
157 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
159 kernelbuild=${kernelsrc}
162 AC_MSG_RESULT([$kernelbuild])
164 AC_MSG_CHECKING([kernel source version])
165 utsrelease1=$kernelbuild/include/linux/version.h
166 utsrelease2=$kernelbuild/include/linux/utsrelease.h
167 utsrelease3=$kernelbuild/include/generated/utsrelease.h
168 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1], [
169 utsrelease=linux/version.h
170 ], [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2], [
171 utsrelease=linux/utsrelease.h
172 ], [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3], [
173 utsrelease=generated/utsrelease.h
176 AS_IF([test "$utsrelease"], [
177 kernsrcver=`(echo "#include <$utsrelease>";
178 echo "kernsrcver=UTS_RELEASE") |
179 cpp -I $kernelbuild/include |
180 grep "^kernsrcver=" | cut -d \" -f 2`
182 AS_IF([test -z "$kernsrcver"], [
183 AC_MSG_RESULT([Not found])
184 AC_MSG_ERROR([*** Cannot determine kernel version.])
187 AC_MSG_RESULT([Not found])
188 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
191 AC_MSG_RESULT([$kernsrcver])
194 LINUX_OBJ=${kernelbuild}
195 LINUX_VERSION=${kernsrcver}
199 AC_SUBST(LINUX_VERSION)
201 ZFS_AC_MODULE_SYMVERS
205 dnl # Detect name used for the additional SPL Module.symvers file. If one
206 dnl # does not exist this is likely because the SPL has been configured
207 dnl # but not built. To allow recursive builds a good guess is made as to
208 dnl # what this file will be named based on what it is named in the kernel
209 dnl # build products. This file will first be used at link time so if
210 dnl # the guess is wrong the build will fail then. This unfortunately
211 dnl # means the ZFS package does not contain a reliable mechanism to
212 dnl # detect symbols exported by the SPL at configure time.
214 AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
215 AC_MSG_CHECKING([spl file name for module symbols])
216 AS_IF([test -r $SPL_OBJ/Module.symvers], [
217 SPL_SYMBOLS=Module.symvers
218 ], [test -r $SPL_OBJ/Modules.symvers], [
219 SPL_SYMBOLS=Modules.symvers
220 ], [test -r $SPL_OBJ/module/Module.symvers], [
221 SPL_SYMBOLS=Module.symvers
222 ], [test -r $SPL_OBJ/module/Modules.symvers], [
223 SPL_SYMBOLS=Modules.symvers
225 SPL_SYMBOLS=$LINUX_SYMBOLS
228 AC_MSG_RESULT([$SPL_SYMBOLS])
229 AC_SUBST(SPL_SYMBOLS)
233 dnl # Detect the SPL module to be built against
235 AC_DEFUN([ZFS_AC_SPL], [
237 AS_HELP_STRING([--with-spl=PATH],
238 [Path to spl source]),
241 AC_ARG_WITH([spl-obj],
242 AS_HELP_STRING([--with-spl-obj=PATH],
243 [Path to spl build objects]),
244 [splbuild="$withval"])
247 AC_MSG_CHECKING([spl source directory])
248 AS_IF([test -z "$splsrc"], [
249 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
250 2>/dev/null | tail -1`
252 AS_IF([test -z "$sourcelink" || test ! -e $sourcelink], [
256 AS_IF([test -e $sourcelink], [
257 splsrc=`readlink -f ${sourcelink}`
259 AC_MSG_RESULT([Not found])
261 *** Please make sure the spl devel package for your distribution
262 *** is installed then try again. If that fails you can specify the
263 *** location of the spl source with the '--with-spl=PATH' option.])
266 AS_IF([test "$splsrc" = "NONE"], [
272 AC_MSG_RESULT([$splsrc])
273 AC_MSG_CHECKING([spl build directory])
274 AS_IF([test -z "$splbuild"], [
277 AC_MSG_RESULT([$splbuild])
279 AC_MSG_CHECKING([spl source version])
280 AS_IF([test -r $splbuild/spl_config.h &&
281 fgrep -q SPL_META_VERSION $splbuild/spl_config.h], [
283 splsrcver=`(echo "#include <spl_config.h>";
284 echo "splsrcver=SPL_META_VERSION-SPL_META_RELEASE") |
286 grep "^splsrcver=" | tr -d \" | cut -d= -f2`
289 AS_IF([test -z "$splsrcver"], [
290 AC_MSG_RESULT([Not found])
292 *** Cannot determine the version of the spl source.
293 *** Please prepare the spl source before running this script])
296 AC_MSG_RESULT([$splsrcver])
300 SPL_VERSION=${splsrcver}
304 AC_SUBST(SPL_VERSION)
306 ZFS_AC_SPL_MODULE_SYMVERS
310 dnl # Certain kernel build options are not supported. These must be
311 dnl # detected at configure time and cause a build failure. Otherwise
312 dnl # modules may be successfully built that behave incorrectly.
314 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
316 AS_IF([test "$ZFS_META_LICENSE" = GPL], [
317 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
318 [Define to 1 if licensed under the GPL])
321 ZFS_AC_KERNEL_CONFIG_PREEMPT
322 ZFS_AC_KERNEL_CONFIG_DEBUG_LOCK_ALLOC
326 dnl # Check CONFIG_PREEMPT
328 dnl # Premptible kernels will be supported in the future. But at the
329 dnl # moment there are a few places in the code which need to be updated
330 dnl # to accomidate them. Until that work occurs we should detect this
331 dnl # at configure time and fail with a sensible message. Otherwise,
332 dnl # people will be able to build successfully, however they will have
333 dnl # stability problems. See https://github.com/zfsonlinux/zfs/issues/83
335 AC_DEFUN([ZFS_AC_KERNEL_CONFIG_PREEMPT], [
337 ZFS_LINUX_CONFIG([PREEMPT],
339 *** Kernel built with CONFIG_PREEMPT which is not supported.
340 *** You must rebuild your kernel without this option.]), [])
344 dnl # Check CONFIG_DEBUG_LOCK_ALLOC
346 dnl # This is typically only set for debug kernels because it comes with
347 dnl # a performance penalty. However, when it is set it maps the non-GPL
348 dnl # symbol mutex_lock() to the GPL-only mutex_lock_nested() symbol.
349 dnl # This will cause a failure at link time which we'd rather know about
350 dnl # at compile time.
352 dnl # Since we plan to pursue making mutex_lock_nested() a non-GPL symbol
353 dnl # with the upstream community we add a check to detect this case.
355 AC_DEFUN([ZFS_AC_KERNEL_CONFIG_DEBUG_LOCK_ALLOC], [
357 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC], [
358 AC_MSG_CHECKING([whether mutex_lock() is GPL-only])
359 tmp_flags="$EXTRA_KCFLAGS"
360 ZFS_LINUX_TRY_COMPILE([
361 #include <linux/module.h>
362 #include <linux/mutex.h>
364 MODULE_LICENSE("$ZFS_META_LICENSE");
376 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is incompatible
377 *** with the CDDL license and will prevent the module linking stage
378 *** from succeeding. You must rebuild your kernel without this
379 *** option enabled.])
381 EXTRA_KCFLAGS="$tmp_flags"
386 dnl # ZFS_LINUX_CONFTEST
388 AC_DEFUN([ZFS_LINUX_CONFTEST], [
389 cat confdefs.h - <<_ACEOF >conftest.c
395 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
397 m4_define([ZFS_LANG_PROGRAM], [
402 dnl Do *not* indent the following line: there may be CPP directives.
403 dnl Don't move the `;' right after for the same reason.
411 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
413 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
414 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
415 rm -Rf build && mkdir -p build
416 echo "obj-m := conftest.o" >build/Makefile
418 [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])],
420 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
426 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
428 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
429 [ZFS_LINUX_COMPILE_IFELSE(
430 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
432 [test -s build/conftest.o],
437 dnl # ZFS_LINUX_CONFIG
439 AC_DEFUN([ZFS_LINUX_CONFIG],
440 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
441 ZFS_LINUX_TRY_COMPILE([
442 #include <linux/module.h>
445 #error CONFIG_$1 not #defined
457 dnl # ZFS_CHECK_SYMBOL_EXPORT
458 dnl # check symbol exported or not
460 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
461 [AC_MSG_CHECKING([whether symbol $1 is exported])
462 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
463 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
465 AS_IF([test $rc -ne 0], [
468 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
470 AS_IF([test $rc -eq 0], [
475 AS_IF([test $export -eq 0], [