]> git.proxmox.com Git - mirror_spl-debian.git/blob - config/spl-build.m4
New upstream version 0.7.2
[mirror_spl-debian.git] / config / spl-build.m4
1 ###############################################################################
2 # Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 # Copyright (C) 2007 The Regents of the University of California.
4 # Written by Brian Behlendorf <behlendorf1@llnl.gov>.
5 ###############################################################################
6 # SPL_AC_CONFIG_KERNEL: Default SPL kernel configuration.
7 ###############################################################################
8
9 AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
10 SPL_AC_KERNEL
11
12 if test "${LINUX_OBJ}" != "${LINUX}"; then
13 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
14 fi
15 AC_SUBST(KERNELMAKE_PARAMS)
16
17 KERNELCPPFLAGS="$KERNELCPPFLAGS -Wstrict-prototypes"
18 AC_SUBST(KERNELCPPFLAGS)
19
20 SPL_AC_DEBUG
21 SPL_AC_DEBUG_KMEM
22 SPL_AC_DEBUG_KMEM_TRACKING
23 SPL_AC_TEST_MODULE
24 SPL_AC_ATOMIC_SPINLOCK
25 SPL_AC_SHRINKER_CALLBACK
26 SPL_AC_CTL_NAME
27 SPL_AC_CONFIG_TRIM_UNUSED_KSYMS
28 SPL_AC_PDE_DATA
29 SPL_AC_SET_FS_PWD_WITH_CONST
30 SPL_AC_2ARGS_VFS_UNLINK
31 SPL_AC_4ARGS_VFS_RENAME
32 SPL_AC_2ARGS_VFS_FSYNC
33 SPL_AC_INODE_TRUNCATE_RANGE
34 SPL_AC_FS_STRUCT_SPINLOCK
35 SPL_AC_KUIDGID_T
36 SPL_AC_KERNEL_FALLOCATE
37 SPL_AC_CONFIG_ZLIB_INFLATE
38 SPL_AC_CONFIG_ZLIB_DEFLATE
39 SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE
40 SPL_AC_SHRINK_CONTROL_STRUCT
41 SPL_AC_RWSEM_SPINLOCK_IS_RAW
42 SPL_AC_RWSEM_ACTIVITY
43 SPL_AC_RWSEM_ATOMIC_LONG_COUNT
44 SPL_AC_SCHED_RT_HEADER
45 SPL_AC_SCHED_SIGNAL_HEADER
46 SPL_AC_4ARGS_VFS_GETATTR
47 SPL_AC_3ARGS_VFS_GETATTR
48 SPL_AC_2ARGS_VFS_GETATTR
49 SPL_AC_USLEEP_RANGE
50 SPL_AC_KMEM_CACHE_ALLOCFLAGS
51 SPL_AC_WAIT_ON_BIT
52 SPL_AC_INODE_LOCK
53 SPL_AC_GROUP_INFO_GID
54 SPL_AC_KMEM_CACHE_CREATE_USERCOPY
55 SPL_AC_WAIT_QUEUE_ENTRY_T
56 SPL_AC_WAIT_QUEUE_HEAD_ENTRY
57 ])
58
59 AC_DEFUN([SPL_AC_MODULE_SYMVERS], [
60 modpost=$LINUX/scripts/Makefile.modpost
61 AC_MSG_CHECKING([kernel file name for module symbols])
62 if test "x$enable_linux_builtin" != xyes -a -f "$modpost"; then
63 if grep -q Modules.symvers $modpost; then
64 LINUX_SYMBOLS=Modules.symvers
65 else
66 LINUX_SYMBOLS=Module.symvers
67 fi
68
69 if ! test -f "$LINUX_OBJ/$LINUX_SYMBOLS"; then
70 AC_MSG_ERROR([
71 *** Please make sure the kernel devel package for your distribution
72 *** is installed. If you are building with a custom kernel, make sure the
73 *** kernel is configured, built, and the '--with-linux=PATH' configure
74 *** option refers to the location of the kernel source.])
75 fi
76 else
77 LINUX_SYMBOLS=NONE
78 fi
79 AC_MSG_RESULT($LINUX_SYMBOLS)
80 AC_SUBST(LINUX_SYMBOLS)
81 ])
82
83 AC_DEFUN([SPL_AC_KERNEL], [
84 AC_ARG_WITH([linux],
85 AS_HELP_STRING([--with-linux=PATH],
86 [Path to kernel source]),
87 [kernelsrc="$withval"])
88
89 AC_ARG_WITH([linux-obj],
90 AS_HELP_STRING([--with-linux-obj=PATH],
91 [Path to kernel build objects]),
92 [kernelbuild="$withval"])
93
94 AC_MSG_CHECKING([kernel source directory])
95 if test -z "$kernelsrc"; then
96 if test -e "/lib/modules/$(uname -r)/source"; then
97 headersdir="/lib/modules/$(uname -r)/source"
98 sourcelink=$(readlink -f "$headersdir")
99 elif test -e "/lib/modules/$(uname -r)/build"; then
100 headersdir="/lib/modules/$(uname -r)/build"
101 sourcelink=$(readlink -f "$headersdir")
102 else
103 sourcelink=$(ls -1d /usr/src/kernels/* \
104 /usr/src/linux-* \
105 2>/dev/null | grep -v obj | tail -1)
106 fi
107
108 if test -n "$sourcelink" && test -e ${sourcelink}; then
109 kernelsrc=`readlink -f ${sourcelink}`
110 else
111 kernelsrc="[Not found]"
112 fi
113 else
114 if test "$kernelsrc" = "NONE"; then
115 kernsrcver=NONE
116 fi
117 withlinux=yes
118 fi
119
120 AC_MSG_RESULT([$kernelsrc])
121 if test ! -d "$kernelsrc"; then
122 AC_MSG_ERROR([
123 *** Please make sure the kernel devel package for your distribution
124 *** is installed and then try again. If that fails, you can specify the
125 *** location of the kernel source with the '--with-linux=PATH' option.])
126 fi
127
128 AC_MSG_CHECKING([kernel build directory])
129 if test -z "$kernelbuild"; then
130 if test x$withlinux != xyes -a -e "/lib/modules/$(uname -r)/build"; then
131 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
132 elif test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
133 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
134 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
135 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
136 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
137 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
138 else
139 kernelbuild=${kernelsrc}
140 fi
141 fi
142 AC_MSG_RESULT([$kernelbuild])
143
144 AC_MSG_CHECKING([kernel source version])
145 utsrelease1=$kernelbuild/include/linux/version.h
146 utsrelease2=$kernelbuild/include/linux/utsrelease.h
147 utsrelease3=$kernelbuild/include/generated/utsrelease.h
148 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
149 utsrelease=linux/version.h
150 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
151 utsrelease=linux/utsrelease.h
152 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
153 utsrelease=generated/utsrelease.h
154 fi
155
156 if test "$utsrelease"; then
157 kernsrcver=`(echo "#include <$utsrelease>";
158 echo "kernsrcver=UTS_RELEASE") |
159 cpp -I $kernelbuild/include |
160 grep "^kernsrcver=" | cut -d \" -f 2`
161
162 if test -z "$kernsrcver"; then
163 AC_MSG_RESULT([Not found])
164 AC_MSG_ERROR([*** Cannot determine kernel version.])
165 fi
166 else
167 AC_MSG_RESULT([Not found])
168 if test "x$enable_linux_builtin" != xyes; then
169 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
170 else
171 AC_MSG_ERROR([
172 *** Cannot find UTS_RELEASE definition.
173 *** Please run 'make prepare' inside the kernel source tree.])
174 fi
175 fi
176
177 AC_MSG_RESULT([$kernsrcver])
178
179 LINUX=${kernelsrc}
180 LINUX_OBJ=${kernelbuild}
181 LINUX_VERSION=${kernsrcver}
182
183 AC_SUBST(LINUX)
184 AC_SUBST(LINUX_OBJ)
185 AC_SUBST(LINUX_VERSION)
186
187 SPL_AC_MODULE_SYMVERS
188 ])
189
190 dnl #
191 dnl # Default SPL user configuration
192 dnl #
193 AC_DEFUN([SPL_AC_CONFIG_USER], [])
194
195 dnl #
196 dnl # Check for rpm+rpmbuild to build RPM packages. If these tools
197 dnl # are missing, it is non-fatal, but you will not be able to build
198 dnl # RPM packages and will be warned if you try too.
199 dnl #
200 dnl # By default, the generic spec file will be used because it requires
201 dnl # minimal dependencies. Distribution specific spec files can be
202 dnl # placed under the 'rpm/<distribution>' directory and enabled using
203 dnl # the --with-spec=<distribution> configure option.
204 dnl #
205 AC_DEFUN([SPL_AC_RPM], [
206 RPM=rpm
207 RPMBUILD=rpmbuild
208
209 AC_MSG_CHECKING([whether $RPM is available])
210 AS_IF([tmp=$($RPM --version 2>/dev/null)], [
211 RPM_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
212 HAVE_RPM=yes
213 AC_MSG_RESULT([$HAVE_RPM ($RPM_VERSION)])
214 ],[
215 HAVE_RPM=no
216 AC_MSG_RESULT([$HAVE_RPM])
217 ])
218
219 AC_MSG_CHECKING([whether $RPMBUILD is available])
220 AS_IF([tmp=$($RPMBUILD --version 2>/dev/null)], [
221 RPMBUILD_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
222 HAVE_RPMBUILD=yes
223 AC_MSG_RESULT([$HAVE_RPMBUILD ($RPMBUILD_VERSION)])
224 ],[
225 HAVE_RPMBUILD=no
226 AC_MSG_RESULT([$HAVE_RPMBUILD])
227 ])
228
229 RPM_DEFINE_COMMON='--define "$(DEBUG_SPL) 1" --define "$(DEBUG_KMEM) 1" --define "$(DEBUG_KMEM_TRACKING) 1"'
230 RPM_DEFINE_UTIL=
231 RPM_DEFINE_KMOD='--define "kernels $(LINUX_VERSION)"'
232 RPM_DEFINE_DKMS=
233
234 SRPM_DEFINE_COMMON='--define "build_src_rpm 1"'
235 SRPM_DEFINE_UTIL=
236 SRPM_DEFINE_KMOD=
237 SRPM_DEFINE_DKMS=
238
239 RPM_SPEC_DIR="rpm/generic"
240 AC_ARG_WITH([spec],
241 AS_HELP_STRING([--with-spec=SPEC],
242 [Spec files 'generic|redhat']),
243 [RPM_SPEC_DIR="rpm/$withval"])
244
245 AC_MSG_CHECKING([whether spec files are available])
246 AC_MSG_RESULT([yes ($RPM_SPEC_DIR/*.spec.in)])
247
248 AC_SUBST(HAVE_RPM)
249 AC_SUBST(RPM)
250 AC_SUBST(RPM_VERSION)
251
252 AC_SUBST(HAVE_RPMBUILD)
253 AC_SUBST(RPMBUILD)
254 AC_SUBST(RPMBUILD_VERSION)
255
256 AC_SUBST(RPM_SPEC_DIR)
257 AC_SUBST(RPM_DEFINE_UTIL)
258 AC_SUBST(RPM_DEFINE_KMOD)
259 AC_SUBST(RPM_DEFINE_DKMS)
260 AC_SUBST(RPM_DEFINE_COMMON)
261 AC_SUBST(SRPM_DEFINE_UTIL)
262 AC_SUBST(SRPM_DEFINE_KMOD)
263 AC_SUBST(SRPM_DEFINE_DKMS)
264 AC_SUBST(SRPM_DEFINE_COMMON)
265 ])
266
267 dnl #
268 dnl # Check for dpkg+dpkg-buildpackage to build DEB packages. If these
269 dnl # tools are missing it is non-fatal but you will not be able to build
270 dnl # DEB packages and will be warned if you try too.
271 dnl #
272 AC_DEFUN([SPL_AC_DPKG], [
273 DPKG=dpkg
274 DPKGBUILD=dpkg-buildpackage
275
276 AC_MSG_CHECKING([whether $DPKG is available])
277 AS_IF([tmp=$($DPKG --version 2>/dev/null)], [
278 DPKG_VERSION=$(echo $tmp | $AWK '/Debian/ { print $[7] }')
279 HAVE_DPKG=yes
280 AC_MSG_RESULT([$HAVE_DPKG ($DPKG_VERSION)])
281 ],[
282 HAVE_DPKG=no
283 AC_MSG_RESULT([$HAVE_DPKG])
284 ])
285
286 AC_MSG_CHECKING([whether $DPKGBUILD is available])
287 AS_IF([tmp=$($DPKGBUILD --version 2>/dev/null)], [
288 DPKGBUILD_VERSION=$(echo $tmp | \
289 $AWK '/Debian/ { print $[4] }' | cut -f-4 -d'.')
290 HAVE_DPKGBUILD=yes
291 AC_MSG_RESULT([$HAVE_DPKGBUILD ($DPKGBUILD_VERSION)])
292 ],[
293 HAVE_DPKGBUILD=no
294 AC_MSG_RESULT([$HAVE_DPKGBUILD])
295 ])
296
297 AC_SUBST(HAVE_DPKG)
298 AC_SUBST(DPKG)
299 AC_SUBST(DPKG_VERSION)
300
301 AC_SUBST(HAVE_DPKGBUILD)
302 AC_SUBST(DPKGBUILD)
303 AC_SUBST(DPKGBUILD_VERSION)
304 ])
305
306 dnl #
307 dnl # Until native packaging for various different packing systems
308 dnl # can be added the least we can do is attempt to use alien to
309 dnl # convert the RPM packages to the needed package type. This is
310 dnl # a hack but so far it has worked reasonable well.
311 dnl #
312 AC_DEFUN([SPL_AC_ALIEN], [
313 ALIEN=alien
314
315 AC_MSG_CHECKING([whether $ALIEN is available])
316 AS_IF([tmp=$($ALIEN --version 2>/dev/null)], [
317 ALIEN_VERSION=$(echo $tmp | $AWK '{ print $[3] }')
318 HAVE_ALIEN=yes
319 AC_MSG_RESULT([$HAVE_ALIEN ($ALIEN_VERSION)])
320 ],[
321 HAVE_ALIEN=no
322 AC_MSG_RESULT([$HAVE_ALIEN])
323 ])
324
325 AC_SUBST(HAVE_ALIEN)
326 AC_SUBST(ALIEN)
327 AC_SUBST(ALIEN_VERSION)
328 ])
329
330 dnl #
331 dnl # Using the VENDOR tag from config.guess set the default
332 dnl # package type for 'make pkg': (rpm | deb | tgz)
333 dnl #
334 AC_DEFUN([SPL_AC_DEFAULT_PACKAGE], [
335 AC_MSG_CHECKING([linux distribution])
336 if test -f /etc/toss-release ; then
337 VENDOR=toss ;
338 elif test -f /etc/fedora-release ; then
339 VENDOR=fedora ;
340 elif test -f /etc/redhat-release ; then
341 VENDOR=redhat ;
342 elif test -f /etc/gentoo-release ; then
343 VENDOR=gentoo ;
344 elif test -f /etc/arch-release ; then
345 VENDOR=arch ;
346 elif test -f /etc/SuSE-release ; then
347 VENDOR=sles ;
348 elif test -f /etc/slackware-version ; then
349 VENDOR=slackware ;
350 elif test -f /etc/lunar.release ; then
351 VENDOR=lunar ;
352 elif test -f /etc/lsb-release ; then
353 VENDOR=ubuntu ;
354 elif test -f /etc/debian_version ; then
355 VENDOR=debian ;
356 else
357 VENDOR= ;
358 fi
359 AC_MSG_RESULT([$VENDOR])
360 AC_SUBST(VENDOR)
361
362 AC_MSG_CHECKING([default package type])
363 case "$VENDOR" in
364 toss) DEFAULT_PACKAGE=rpm ;;
365 redhat) DEFAULT_PACKAGE=rpm ;;
366 fedora) DEFAULT_PACKAGE=rpm ;;
367 gentoo) DEFAULT_PACKAGE=tgz ;;
368 arch) DEFAULT_PACKAGE=tgz ;;
369 sles) DEFAULT_PACKAGE=rpm ;;
370 slackware) DEFAULT_PACKAGE=tgz ;;
371 lunar) DEFAULT_PACKAGE=tgz ;;
372 ubuntu) DEFAULT_PACKAGE=deb ;;
373 debian) DEFAULT_PACKAGE=deb ;;
374 *) DEFAULT_PACKAGE=rpm ;;
375 esac
376
377 AC_MSG_RESULT([$DEFAULT_PACKAGE])
378 AC_SUBST(DEFAULT_PACKAGE)
379 ])
380
381 dnl #
382 dnl # Default SPL user configuration
383 dnl #
384 AC_DEFUN([SPL_AC_PACKAGE], [
385 SPL_AC_DEFAULT_PACKAGE
386 SPL_AC_RPM
387 SPL_AC_DPKG
388 SPL_AC_ALIEN
389 ])
390
391 AC_DEFUN([SPL_AC_LICENSE], [
392 AC_MSG_CHECKING([spl author])
393 AC_MSG_RESULT([$SPL_META_AUTHOR])
394
395 AC_MSG_CHECKING([spl license])
396 AC_MSG_RESULT([$SPL_META_LICENSE])
397 ])
398
399 AC_DEFUN([SPL_AC_CONFIG], [
400 SPL_CONFIG=all
401 AC_ARG_WITH([config],
402 AS_HELP_STRING([--with-config=CONFIG],
403 [Config file 'kernel|user|all|srpm']),
404 [SPL_CONFIG="$withval"])
405 AC_ARG_ENABLE([linux-builtin],
406 [AC_HELP_STRING([--enable-linux-builtin],
407 [Configure for builtin in-tree kernel modules @<:@default=no@:>@])],
408 [],
409 [enable_linux_builtin=no])
410
411 AC_MSG_CHECKING([spl config])
412 AC_MSG_RESULT([$SPL_CONFIG]);
413 AC_SUBST(SPL_CONFIG)
414
415 case "$SPL_CONFIG" in
416 kernel) SPL_AC_CONFIG_KERNEL ;;
417 user) SPL_AC_CONFIG_USER ;;
418 all) SPL_AC_CONFIG_KERNEL
419 SPL_AC_CONFIG_USER ;;
420 srpm) ;;
421 *)
422 AC_MSG_RESULT([Error!])
423 AC_MSG_ERROR([Bad value "$SPL_CONFIG" for --with-config,
424 user kernel|user|all|srpm]) ;;
425 esac
426
427 AM_CONDITIONAL([CONFIG_USER],
428 [test "$SPL_CONFIG" = user -o "$SPL_CONFIG" = all])
429 AM_CONDITIONAL([CONFIG_KERNEL],
430 [test "$SPL_CONFIG" = kernel -o "$SPL_CONFIG" = all] &&
431 [test "x$enable_linux_builtin" != xyes ])
432 ])
433
434 dnl #
435 dnl # Enable if the SPL should be compiled with internal debugging enabled.
436 dnl # By default this support is disabled.
437 dnl #
438 AC_DEFUN([SPL_AC_DEBUG], [
439 AC_MSG_CHECKING([whether debugging is enabled])
440 AC_ARG_ENABLE([debug],
441 [AS_HELP_STRING([--enable-debug],
442 [Enable generic debug support @<:@default=no@:>@])],
443 [],
444 [enable_debug=no])
445
446 AS_IF([test "x$enable_debug" = xyes],
447 [
448 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG -Werror"
449 DEBUG_CFLAGS="-DDEBUG -Werror"
450 DEBUG_SPL="_with_debug"
451 ], [
452 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
453 DEBUG_CFLAGS="-DNDEBUG"
454 DEBUG_SPL="_without_debug"
455 ])
456
457 AC_SUBST(DEBUG_CFLAGS)
458 AC_SUBST(DEBUG_SPL)
459 AC_MSG_RESULT([$enable_debug])
460 ])
461
462 dnl #
463 dnl # Enabled by default it provides a minimal level of memory tracking.
464 dnl # A total count of bytes allocated is kept for each alloc and free.
465 dnl # Then at module unload time a report to the console will be printed
466 dnl # if memory was leaked.
467 dnl #
468 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
469 AC_ARG_ENABLE([debug-kmem],
470 [AS_HELP_STRING([--enable-debug-kmem],
471 [Enable basic kmem accounting @<:@default=no@:>@])],
472 [],
473 [enable_debug_kmem=no])
474
475 AS_IF([test "x$enable_debug_kmem" = xyes],
476 [
477 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"
478 DEBUG_KMEM="_with_debug_kmem"
479 AC_DEFINE([DEBUG_KMEM], [1],
480 [Define to 1 to enable basic kmem accounting])
481 ], [
482 DEBUG_KMEM="_without_debug_kmem"
483 ])
484
485 AC_SUBST(DEBUG_KMEM)
486 AC_MSG_CHECKING([whether basic kmem accounting is enabled])
487 AC_MSG_RESULT([$enable_debug_kmem])
488 ])
489
490 dnl #
491 dnl # Disabled by default it provides detailed memory tracking. This
492 dnl # feature also requires --enable-debug-kmem to be set. When enabled
493 dnl # not only will total bytes be tracked but also the location of every
494 dnl # alloc and free. When the SPL module is unloaded a list of all leaked
495 dnl # addresses and where they were allocated will be dumped to the console.
496 dnl # Enabling this feature has a significant impact on performance but it
497 dnl # makes finding memory leaks pretty straight forward.
498 dnl #
499 AC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [
500 AC_ARG_ENABLE([debug-kmem-tracking],
501 [AS_HELP_STRING([--enable-debug-kmem-tracking],
502 [Enable detailed kmem tracking @<:@default=no@:>@])],
503 [],
504 [enable_debug_kmem_tracking=no])
505
506 AS_IF([test "x$enable_debug_kmem_tracking" = xyes],
507 [
508 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM_TRACKING"
509 DEBUG_KMEM_TRACKING="_with_debug_kmem_tracking"
510 AC_DEFINE([DEBUG_KMEM_TRACKING], [1],
511 [Define to 1 to enable detailed kmem tracking])
512 ], [
513 DEBUG_KMEM_TRACKING="_without_debug_kmem_tracking"
514 ])
515
516 AC_SUBST(DEBUG_KMEM_TRACKING)
517 AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
518 AC_MSG_RESULT([$enable_debug_kmem_tracking])
519 ])
520
521 dnl #
522 dnl # SPL_LINUX_CONFTEST
523 dnl #
524 AC_DEFUN([SPL_LINUX_CONFTEST], [
525 cat confdefs.h - <<_ACEOF >conftest.c
526 $1
527 _ACEOF
528 ])
529
530 dnl #
531 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
532 dnl #
533 m4_define([SPL_LANG_PROGRAM], [
534 $1
535 int
536 main (void)
537 {
538 dnl Do *not* indent the following line: there may be CPP directives.
539 dnl Don't move the `;' right after for the same reason.
540 $2
541 ;
542 return 0;
543 }
544 ])
545
546 dnl #
547 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
548 dnl #
549 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
550 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])
551 rm -Rf build && mkdir -p build && touch build/conftest.mod.c
552 echo "obj-m := conftest.o" >build/Makefile
553 modpost_flag=''
554 test "x$enable_linux_builtin" = xyes && modpost_flag='modpost=true' # fake modpost stage
555 AS_IF(
556 [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 $modpost_flag) >/dev/null && AC_TRY_COMMAND([$3])],
557 [$4],
558 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
559 )
560 rm -Rf build
561 ])
562
563 dnl #
564 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
565 dnl #
566 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
567 [SPL_LINUX_COMPILE_IFELSE(
568 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
569 [modules],
570 [test -s build/conftest.o],
571 [$3], [$4])
572 ])
573
574 dnl #
575 dnl # SPL_CHECK_SYMBOL_EXPORT
576 dnl # check symbol exported or not
577 dnl #
578 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT], [
579 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
580 $LINUX_OBJ/Module*.symvers 2>/dev/null
581 rc=$?
582 if test $rc -ne 0; then
583 export=0
584 for file in $2; do
585 grep -q -E "EXPORT_SYMBOL.*($1)" \
586 "$LINUX_OBJ/$file" 2>/dev/null
587 rc=$?
588 if test $rc -eq 0; then
589 export=1
590 break;
591 fi
592 done
593 if test $export -eq 0; then :
594 $4
595 else :
596 $3
597 fi
598 else :
599 $3
600 fi
601 ])
602
603 dnl #
604 dnl # SPL_LINUX_TRY_COMPILE_SYMBOL
605 dnl # like SPL_LINUX_TRY_COMPILE, except SPL_CHECK_SYMBOL_EXPORT
606 dnl # is called if not compiling for builtin
607 dnl #
608 AC_DEFUN([SPL_LINUX_TRY_COMPILE_SYMBOL], [
609 SPL_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
610 if test $rc -ne 0; then :
611 $6
612 else
613 if test "x$enable_linux_builtin" != xyes; then
614 SPL_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
615 fi
616 if test $rc -ne 0; then :
617 $6
618 else :
619 $5
620 fi
621 fi
622 ])
623
624 dnl #
625 dnl # SPL_CHECK_SYMBOL_HEADER
626 dnl # check if a symbol prototype is defined in listed headers.
627 dnl #
628 AC_DEFUN([SPL_CHECK_SYMBOL_HEADER], [
629 AC_MSG_CHECKING([whether symbol $1 exists in header])
630 header=0
631 for file in $3; do
632 grep -q "$2" "$LINUX/$file" 2>/dev/null
633 rc=$?
634 if test $rc -eq 0; then
635 header=1
636 break;
637 fi
638 done
639 if test $header -eq 0; then
640 AC_MSG_RESULT([no])
641 $5
642 else
643 AC_MSG_RESULT([yes])
644 $4
645 fi
646 ])
647
648 dnl #
649 dnl # SPL_CHECK_HEADER
650 dnl # check whether header exists and define HAVE_$2_HEADER
651 dnl #
652 AC_DEFUN([SPL_CHECK_HEADER],
653 [AC_MSG_CHECKING([whether header $1 exists])
654 SPL_LINUX_TRY_COMPILE([
655 #include <$1>
656 ],[
657 return 0;
658 ],[
659 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
660 AC_MSG_RESULT(yes)
661 $3
662 ],[
663 AC_MSG_RESULT(no)
664 $4
665 ])
666 ])
667
668 dnl #
669 dnl # Basic toolchain sanity check. Verify that kernel modules can
670 dnl # be built and which symbols can be used.
671 dnl #
672 AC_DEFUN([SPL_AC_TEST_MODULE],
673 [AC_MSG_CHECKING([whether modules can be built])
674 SPL_LINUX_TRY_COMPILE([],[],[
675 AC_MSG_RESULT([yes])
676 ],[
677 AC_MSG_RESULT([no])
678 if test "x$enable_linux_builtin" != xyes; then
679 AC_MSG_ERROR([*** Unable to build an empty module.])
680 else
681 AC_MSG_ERROR([
682 *** Unable to build an empty module.
683 *** Please run 'make scripts' inside the kernel source tree.])
684 fi
685 ])
686
687 AS_IF([test "x$cross_compiling" != xyes], [
688 AC_RUN_IFELSE([
689 AC_LANG_PROGRAM([
690 #include "$LINUX/include/linux/license.h"
691 ], [
692 return !license_is_gpl_compatible(
693 "$SPL_META_LICENSE");
694 ])
695 ], [
696 AC_DEFINE([SPL_IS_GPL_COMPATIBLE], [1],
697 [Define to 1 if GPL-only symbols can be used])
698 ], [
699 ])
700 ])
701 ])
702
703 dnl #
704 dnl # Use the atomic implemenation based on global spinlocks. This
705 dnl # should only be needed by 32-bit kernels which do not provide
706 dnl # the atomic64_* API. It may be optionally enabled as a fallback
707 dnl # if problems are observed with the direct mapping to the native
708 dnl # Linux atomic operations. You may not disable atomic spinlocks
709 dnl # if you kernel does not an atomic64_* API.
710 dnl #
711 AC_DEFUN([SPL_AC_ATOMIC_SPINLOCK], [
712 AC_ARG_ENABLE([atomic-spinlocks],
713 [AS_HELP_STRING([--enable-atomic-spinlocks],
714 [Atomic types use spinlocks @<:@default=check@:>@])],
715 [],
716 [enable_atomic_spinlocks=check])
717
718 SPL_LINUX_TRY_COMPILE([
719 #include <linux/fs.h>
720 ],[
721 atomic64_t *ptr __attribute__ ((unused));
722 ],[
723 have_atomic64_t=yes
724 AC_DEFINE(HAVE_ATOMIC64_T, 1,
725 [kernel defines atomic64_t])
726 ],[
727 have_atomic64_t=no
728 ])
729
730 AS_IF([test "x$enable_atomic_spinlocks" = xcheck], [
731 AS_IF([test "x$have_atomic64_t" = xyes], [
732 enable_atomic_spinlocks=no
733 ],[
734 enable_atomic_spinlocks=yes
735 ])
736 ])
737
738 AS_IF([test "x$enable_atomic_spinlocks" = xyes], [
739 AC_DEFINE([ATOMIC_SPINLOCK], [1],
740 [Atomic types use spinlocks])
741 ],[
742 AS_IF([test "x$have_atomic64_t" = xno], [
743 AC_MSG_FAILURE(
744 [--disable-atomic-spinlocks given but required atomic64 support is unavailable])
745 ])
746 ])
747
748 AC_MSG_CHECKING([whether atomic types use spinlocks])
749 AC_MSG_RESULT([$enable_atomic_spinlocks])
750
751 AC_MSG_CHECKING([whether kernel defines atomic64_t])
752 AC_MSG_RESULT([$have_atomic64_t])
753 ])
754
755 AC_DEFUN([SPL_AC_SHRINKER_CALLBACK],[
756 tmp_flags="$EXTRA_KCFLAGS"
757 EXTRA_KCFLAGS="-Werror"
758 dnl #
759 dnl # 2.6.23 to 2.6.34 API change
760 dnl # ->shrink(int nr_to_scan, gfp_t gfp_mask)
761 dnl #
762 AC_MSG_CHECKING([whether old 2-argument shrinker exists])
763 SPL_LINUX_TRY_COMPILE([
764 #include <linux/mm.h>
765
766 int shrinker_cb(int nr_to_scan, gfp_t gfp_mask);
767 ],[
768 struct shrinker cache_shrinker = {
769 .shrink = shrinker_cb,
770 .seeks = DEFAULT_SEEKS,
771 };
772 register_shrinker(&cache_shrinker);
773 ],[
774 AC_MSG_RESULT(yes)
775 AC_DEFINE(HAVE_2ARGS_OLD_SHRINKER_CALLBACK, 1,
776 [old shrinker callback wants 2 args])
777 ],[
778 AC_MSG_RESULT(no)
779 dnl #
780 dnl # 2.6.35 - 2.6.39 API change
781 dnl # ->shrink(struct shrinker *,
782 dnl # int nr_to_scan, gfp_t gfp_mask)
783 dnl #
784 AC_MSG_CHECKING([whether old 3-argument shrinker exists])
785 SPL_LINUX_TRY_COMPILE([
786 #include <linux/mm.h>
787
788 int shrinker_cb(struct shrinker *, int nr_to_scan,
789 gfp_t gfp_mask);
790 ],[
791 struct shrinker cache_shrinker = {
792 .shrink = shrinker_cb,
793 .seeks = DEFAULT_SEEKS,
794 };
795 register_shrinker(&cache_shrinker);
796 ],[
797 AC_MSG_RESULT(yes)
798 AC_DEFINE(HAVE_3ARGS_SHRINKER_CALLBACK, 1,
799 [old shrinker callback wants 3 args])
800 ],[
801 AC_MSG_RESULT(no)
802 dnl #
803 dnl # 3.0 - 3.11 API change
804 dnl # ->shrink(struct shrinker *,
805 dnl # struct shrink_control *sc)
806 dnl #
807 AC_MSG_CHECKING(
808 [whether new 2-argument shrinker exists])
809 SPL_LINUX_TRY_COMPILE([
810 #include <linux/mm.h>
811
812 int shrinker_cb(struct shrinker *,
813 struct shrink_control *sc);
814 ],[
815 struct shrinker cache_shrinker = {
816 .shrink = shrinker_cb,
817 .seeks = DEFAULT_SEEKS,
818 };
819 register_shrinker(&cache_shrinker);
820 ],[
821 AC_MSG_RESULT(yes)
822 AC_DEFINE(HAVE_2ARGS_NEW_SHRINKER_CALLBACK, 1,
823 [new shrinker callback wants 2 args])
824 ],[
825 AC_MSG_RESULT(no)
826 dnl #
827 dnl # 3.12 API change,
828 dnl # ->shrink() is logically split in to
829 dnl # ->count_objects() and ->scan_objects()
830 dnl #
831 AC_MSG_CHECKING(
832 [whether ->count_objects callback exists])
833 SPL_LINUX_TRY_COMPILE([
834 #include <linux/mm.h>
835
836 unsigned long shrinker_cb(
837 struct shrinker *,
838 struct shrink_control *sc);
839 ],[
840 struct shrinker cache_shrinker = {
841 .count_objects = shrinker_cb,
842 .scan_objects = shrinker_cb,
843 .seeks = DEFAULT_SEEKS,
844 };
845 register_shrinker(&cache_shrinker);
846 ],[
847 AC_MSG_RESULT(yes)
848 AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK,
849 1, [->count_objects exists])
850 ],[
851 AC_MSG_ERROR(error)
852 ])
853 ])
854 ])
855 ])
856 EXTRA_KCFLAGS="$tmp_flags"
857 ])
858
859 dnl #
860 dnl # 2.6.33 API change,
861 dnl # Removed .ctl_name from struct ctl_table.
862 dnl #
863 AC_DEFUN([SPL_AC_CTL_NAME], [
864 AC_MSG_CHECKING([whether struct ctl_table has ctl_name])
865 SPL_LINUX_TRY_COMPILE([
866 #include <linux/sysctl.h>
867 ],[
868 struct ctl_table ctl __attribute__ ((unused));
869 ctl.ctl_name = 0;
870 ],[
871 AC_MSG_RESULT(yes)
872 AC_DEFINE(HAVE_CTL_NAME, 1, [struct ctl_table has ctl_name])
873 ],[
874 AC_MSG_RESULT(no)
875 ])
876 ])
877
878 dnl #
879 dnl # 3.10 API change,
880 dnl # PDE is replaced by PDE_DATA
881 dnl #
882 AC_DEFUN([SPL_AC_PDE_DATA], [
883 AC_MSG_CHECKING([whether PDE_DATA() is available])
884 SPL_LINUX_TRY_COMPILE_SYMBOL([
885 #include <linux/proc_fs.h>
886 ], [
887 PDE_DATA(NULL);
888 ], [PDE_DATA], [], [
889 AC_MSG_RESULT(yes)
890 AC_DEFINE(HAVE_PDE_DATA, 1, [yes])
891 ],[
892 AC_MSG_RESULT(no)
893 ])
894 ])
895
896 dnl #
897 dnl # 3.9 API change
898 dnl # set_fs_pwd takes const struct path *
899 dnl #
900 AC_DEFUN([SPL_AC_SET_FS_PWD_WITH_CONST],
901 tmp_flags="$EXTRA_KCFLAGS"
902 EXTRA_KCFLAGS="-Werror"
903 [AC_MSG_CHECKING([whether set_fs_pwd() requires const struct path *])
904 SPL_LINUX_TRY_COMPILE([
905 #include <linux/spinlock.h>
906 #include <linux/fs_struct.h>
907 #include <linux/path.h>
908 void (*const set_fs_pwd_func)
909 (struct fs_struct *, const struct path *)
910 = set_fs_pwd;
911 ],[
912 return 0;
913 ],[
914 AC_MSG_RESULT(yes)
915 AC_DEFINE(HAVE_SET_FS_PWD_WITH_CONST, 1,
916 [set_fs_pwd() needs const path *])
917 ],[
918 SPL_LINUX_TRY_COMPILE([
919 #include <linux/spinlock.h>
920 #include <linux/fs_struct.h>
921 #include <linux/path.h>
922 void (*const set_fs_pwd_func)
923 (struct fs_struct *, struct path *)
924 = set_fs_pwd;
925 ],[
926 return 0;
927 ],[
928 AC_MSG_RESULT(no)
929 ],[
930 AC_MSG_ERROR(unknown)
931 ])
932 ])
933 EXTRA_KCFLAGS="$tmp_flags"
934 ])
935
936 dnl #
937 dnl # 3.13 API change
938 dnl # vfs_unlink() updated to take a third delegated_inode argument.
939 dnl #
940 AC_DEFUN([SPL_AC_2ARGS_VFS_UNLINK],
941 [AC_MSG_CHECKING([whether vfs_unlink() wants 2 args])
942 SPL_LINUX_TRY_COMPILE([
943 #include <linux/fs.h>
944 ],[
945 vfs_unlink((struct inode *) NULL, (struct dentry *) NULL);
946 ],[
947 AC_MSG_RESULT(yes)
948 AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
949 [vfs_unlink() wants 2 args])
950 ],[
951 AC_MSG_RESULT(no)
952 dnl #
953 dnl # Linux 3.13 API change
954 dnl # Added delegated inode
955 dnl #
956 AC_MSG_CHECKING([whether vfs_unlink() wants 3 args])
957 SPL_LINUX_TRY_COMPILE([
958 #include <linux/fs.h>
959 ],[
960 vfs_unlink((struct inode *) NULL,
961 (struct dentry *) NULL,
962 (struct inode **) NULL);
963 ],[
964 AC_MSG_RESULT(yes)
965 AC_DEFINE(HAVE_3ARGS_VFS_UNLINK, 1,
966 [vfs_unlink() wants 3 args])
967 ],[
968 AC_MSG_ERROR(no)
969 ])
970
971 ])
972 ])
973
974 dnl #
975 dnl # 3.13 and 3.15 API changes
976 dnl # Added delegated inode and flags argument.
977 dnl #
978 AC_DEFUN([SPL_AC_4ARGS_VFS_RENAME],
979 [AC_MSG_CHECKING([whether vfs_rename() wants 4 args])
980 SPL_LINUX_TRY_COMPILE([
981 #include <linux/fs.h>
982 ],[
983 vfs_rename((struct inode *) NULL, (struct dentry *) NULL,
984 (struct inode *) NULL, (struct dentry *) NULL);
985 ],[
986 AC_MSG_RESULT(yes)
987 AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
988 [vfs_rename() wants 4 args])
989 ],[
990 AC_MSG_RESULT(no)
991 dnl #
992 dnl # Linux 3.13 API change
993 dnl # Added delegated inode
994 dnl #
995 AC_MSG_CHECKING([whether vfs_rename() wants 5 args])
996 SPL_LINUX_TRY_COMPILE([
997 #include <linux/fs.h>
998 ],[
999 vfs_rename((struct inode *) NULL,
1000 (struct dentry *) NULL,
1001 (struct inode *) NULL,
1002 (struct dentry *) NULL,
1003 (struct inode **) NULL);
1004 ],[
1005 AC_MSG_RESULT(yes)
1006 AC_DEFINE(HAVE_5ARGS_VFS_RENAME, 1,
1007 [vfs_rename() wants 5 args])
1008 ],[
1009 AC_MSG_RESULT(no)
1010 dnl #
1011 dnl # Linux 3.15 API change
1012 dnl # Added flags
1013 dnl #
1014 AC_MSG_CHECKING([whether vfs_rename() wants 6 args])
1015 SPL_LINUX_TRY_COMPILE([
1016 #include <linux/fs.h>
1017 ],[
1018 vfs_rename((struct inode *) NULL,
1019 (struct dentry *) NULL,
1020 (struct inode *) NULL,
1021 (struct dentry *) NULL,
1022 (struct inode **) NULL,
1023 (unsigned int) 0);
1024 ],[
1025 AC_MSG_RESULT(yes)
1026 AC_DEFINE(HAVE_6ARGS_VFS_RENAME, 1,
1027 [vfs_rename() wants 6 args])
1028 ],[
1029 AC_MSG_ERROR(no)
1030 ])
1031 ])
1032 ])
1033 ])
1034
1035 dnl #
1036 dnl # 2.6.36 API change,
1037 dnl # The 'struct fs_struct->lock' was changed from a rwlock_t to
1038 dnl # a spinlock_t to improve the fastpath performance.
1039 dnl #
1040 AC_DEFUN([SPL_AC_FS_STRUCT_SPINLOCK], [
1041 AC_MSG_CHECKING([whether struct fs_struct uses spinlock_t])
1042 tmp_flags="$EXTRA_KCFLAGS"
1043 EXTRA_KCFLAGS="-Werror"
1044 SPL_LINUX_TRY_COMPILE([
1045 #include <linux/sched.h>
1046 #include <linux/fs_struct.h>
1047 ],[
1048 static struct fs_struct fs;
1049 spin_lock_init(&fs.lock);
1050 ],[
1051 AC_MSG_RESULT(yes)
1052 AC_DEFINE(HAVE_FS_STRUCT_SPINLOCK, 1,
1053 [struct fs_struct uses spinlock_t])
1054 ],[
1055 AC_MSG_RESULT(no)
1056 ])
1057 EXTRA_KCFLAGS="$tmp_flags"
1058 ])
1059
1060 dnl #
1061 dnl # User namespaces, use kuid_t in place of uid_t
1062 dnl # where available. Not strictly a user namespaces thing
1063 dnl # but it should prevent surprises
1064 dnl #
1065 AC_DEFUN([SPL_AC_KUIDGID_T], [
1066 AC_MSG_CHECKING([whether kuid_t/kgid_t is available])
1067 SPL_LINUX_TRY_COMPILE([
1068 #include <linux/uidgid.h>
1069 ], [
1070 kuid_t userid = KUIDT_INIT(0);
1071 kgid_t groupid = KGIDT_INIT(0);
1072 ],[
1073 SPL_LINUX_TRY_COMPILE([
1074 #include <linux/uidgid.h>
1075 ], [
1076 kuid_t userid = 0;
1077 kgid_t groupid = 0;
1078 ],[
1079 AC_MSG_RESULT(yes; optional)
1080 ],[
1081 AC_MSG_RESULT(yes; mandatory)
1082 AC_DEFINE(HAVE_KUIDGID_T, 1, [kuid_t/kgid_t in use])
1083 ])
1084 ],[
1085 AC_MSG_RESULT(no)
1086 ])
1087 ])
1088
1089 dnl #
1090 dnl # 2.6.35 API change,
1091 dnl # Unused 'struct dentry *' removed from vfs_fsync() prototype.
1092 dnl #
1093 AC_DEFUN([SPL_AC_2ARGS_VFS_FSYNC], [
1094 AC_MSG_CHECKING([whether vfs_fsync() wants 2 args])
1095 SPL_LINUX_TRY_COMPILE([
1096 #include <linux/fs.h>
1097 ],[
1098 vfs_fsync(NULL, 0);
1099 ],[
1100 AC_MSG_RESULT(yes)
1101 AC_DEFINE(HAVE_2ARGS_VFS_FSYNC, 1, [vfs_fsync() wants 2 args])
1102 ],[
1103 AC_MSG_RESULT(no)
1104 ])
1105 ])
1106
1107 dnl #
1108 dnl # 3.5 API change,
1109 dnl # inode_operations.truncate_range removed
1110 dnl #
1111 AC_DEFUN([SPL_AC_INODE_TRUNCATE_RANGE], [
1112 AC_MSG_CHECKING([whether truncate_range() inode operation is available])
1113 SPL_LINUX_TRY_COMPILE([
1114 #include <linux/fs.h>
1115 ],[
1116 struct inode_operations ops;
1117 ops.truncate_range = NULL;
1118 ],[
1119 AC_MSG_RESULT(yes)
1120 AC_DEFINE(HAVE_INODE_TRUNCATE_RANGE, 1,
1121 [truncate_range() inode operation is available])
1122 ],[
1123 AC_MSG_RESULT(no)
1124 ])
1125 ])
1126
1127 dnl #
1128 dnl # Linux 2.6.38 - 3.x API
1129 dnl #
1130 AC_DEFUN([SPL_AC_KERNEL_FILE_FALLOCATE], [
1131 AC_MSG_CHECKING([whether fops->fallocate() exists])
1132 SPL_LINUX_TRY_COMPILE([
1133 #include <linux/fs.h>
1134 ],[
1135 long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
1136 struct file_operations fops __attribute__ ((unused)) = {
1137 .fallocate = fallocate,
1138 };
1139 ],[
1140 AC_MSG_RESULT(yes)
1141 AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
1142 ],[
1143 AC_MSG_RESULT(no)
1144 ])
1145 ])
1146
1147 dnl #
1148 dnl # Linux 2.6.x - 2.6.37 API
1149 dnl #
1150 AC_DEFUN([SPL_AC_KERNEL_INODE_FALLOCATE], [
1151 AC_MSG_CHECKING([whether iops->fallocate() exists])
1152 SPL_LINUX_TRY_COMPILE([
1153 #include <linux/fs.h>
1154 ],[
1155 long (*fallocate) (struct inode *, int, loff_t, loff_t) = NULL;
1156 struct inode_operations fops __attribute__ ((unused)) = {
1157 .fallocate = fallocate,
1158 };
1159 ],[
1160 AC_MSG_RESULT(yes)
1161 AC_DEFINE(HAVE_INODE_FALLOCATE, 1, [fops->fallocate() exists])
1162 ],[
1163 AC_MSG_RESULT(no)
1164 ])
1165 ])
1166
1167 dnl #
1168 dnl # PaX Linux 2.6.38 - 3.x API
1169 dnl #
1170 AC_DEFUN([SPL_AC_PAX_KERNEL_FILE_FALLOCATE], [
1171 AC_MSG_CHECKING([whether fops->fallocate() exists])
1172 SPL_LINUX_TRY_COMPILE([
1173 #include <linux/fs.h>
1174 ],[
1175 long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
1176 struct file_operations_no_const fops __attribute__ ((unused)) = {
1177 .fallocate = fallocate,
1178 };
1179 ],[
1180 AC_MSG_RESULT(yes)
1181 AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
1182 ],[
1183 AC_MSG_RESULT(no)
1184 ])
1185 ])
1186
1187 dnl #
1188 dnl # The fallocate callback was moved from the inode_operations
1189 dnl # structure to the file_operations structure.
1190 dnl #
1191 AC_DEFUN([SPL_AC_KERNEL_FALLOCATE], [
1192 SPL_AC_KERNEL_FILE_FALLOCATE
1193 SPL_AC_KERNEL_INODE_FALLOCATE
1194 SPL_AC_PAX_KERNEL_FILE_FALLOCATE
1195 ])
1196
1197 dnl #
1198 dnl # zlib inflate compat,
1199 dnl # Verify the kernel has CONFIG_ZLIB_INFLATE support enabled.
1200 dnl #
1201 AC_DEFUN([SPL_AC_CONFIG_ZLIB_INFLATE], [
1202 AC_MSG_CHECKING([whether CONFIG_ZLIB_INFLATE is defined])
1203 SPL_LINUX_TRY_COMPILE([
1204 #if !defined(CONFIG_ZLIB_INFLATE) && \
1205 !defined(CONFIG_ZLIB_INFLATE_MODULE)
1206 #error CONFIG_ZLIB_INFLATE not defined
1207 #endif
1208 ],[ ],[
1209 AC_MSG_RESULT([yes])
1210 ],[
1211 AC_MSG_RESULT([no])
1212 AC_MSG_ERROR([
1213 *** This kernel does not include the required zlib inflate support.
1214 *** Rebuild the kernel with CONFIG_ZLIB_INFLATE=y|m set.])
1215 ])
1216 ])
1217
1218 dnl #
1219 dnl # zlib deflate compat,
1220 dnl # Verify the kernel has CONFIG_ZLIB_DEFLATE support enabled.
1221 dnl #
1222 AC_DEFUN([SPL_AC_CONFIG_ZLIB_DEFLATE], [
1223 AC_MSG_CHECKING([whether CONFIG_ZLIB_DEFLATE is defined])
1224 SPL_LINUX_TRY_COMPILE([
1225 #if !defined(CONFIG_ZLIB_DEFLATE) && \
1226 !defined(CONFIG_ZLIB_DEFLATE_MODULE)
1227 #error CONFIG_ZLIB_DEFLATE not defined
1228 #endif
1229 ],[ ],[
1230 AC_MSG_RESULT([yes])
1231 ],[
1232 AC_MSG_RESULT([no])
1233 AC_MSG_ERROR([
1234 *** This kernel does not include the required zlib deflate support.
1235 *** Rebuild the kernel with CONFIG_ZLIB_DEFLATE=y|m set.])
1236 ])
1237 ])
1238
1239 dnl #
1240 dnl # config trim unused symbols,
1241 dnl # Verify the kernel has CONFIG_TRIM_UNUSED_KSYMS DISABLED.
1242 dnl #
1243 AC_DEFUN([SPL_AC_CONFIG_TRIM_UNUSED_KSYMS], [
1244 AC_MSG_CHECKING([whether CONFIG_TRIM_UNUSED_KSYM is disabled])
1245 SPL_LINUX_TRY_COMPILE([
1246 #if defined(CONFIG_TRIM_UNUSED_KSYMS)
1247 #error CONFIG_TRIM_UNUSED_KSYMS not defined
1248 #endif
1249 ],[ ],[
1250 AC_MSG_RESULT([yes])
1251 ],[
1252 AC_MSG_RESULT([no])
1253 AC_MSG_ERROR([
1254 *** This kernel has unused symbols trimming enabled, please disable.
1255 *** Rebuild the kernel with CONFIG_TRIM_UNUSED_KSYMS=n set.])
1256 ])
1257 ])
1258
1259 dnl #
1260 dnl # 2.6.39 API compat,
1261 dnl # The function zlib_deflate_workspacesize() now take 2 arguments.
1262 dnl # This was done to avoid always having to allocate the maximum size
1263 dnl # workspace (268K). The caller can now specific the windowBits and
1264 dnl # memLevel compression parameters to get a smaller workspace.
1265 dnl #
1266 AC_DEFUN([SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE],
1267 [AC_MSG_CHECKING([whether zlib_deflate_workspacesize() wants 2 args])
1268 SPL_LINUX_TRY_COMPILE([
1269 #include <linux/zlib.h>
1270 ],[
1271 return zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL);
1272 ],[
1273 AC_MSG_RESULT(yes)
1274 AC_DEFINE(HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE, 1,
1275 [zlib_deflate_workspacesize() wants 2 args])
1276 ],[
1277 AC_MSG_RESULT(no)
1278 ])
1279 ])
1280
1281 dnl #
1282 dnl # 2.6.39 API change,
1283 dnl # Shrinker adjust to use common shrink_control structure.
1284 dnl #
1285 AC_DEFUN([SPL_AC_SHRINK_CONTROL_STRUCT], [
1286 AC_MSG_CHECKING([whether struct shrink_control exists])
1287 SPL_LINUX_TRY_COMPILE([
1288 #include <linux/mm.h>
1289 ],[
1290 struct shrink_control sc __attribute__ ((unused));
1291
1292 sc.nr_to_scan = 0;
1293 sc.gfp_mask = GFP_KERNEL;
1294 ],[
1295 AC_MSG_RESULT(yes)
1296 AC_DEFINE(HAVE_SHRINK_CONTROL_STRUCT, 1,
1297 [struct shrink_control exists])
1298 ],[
1299 AC_MSG_RESULT(no)
1300 ])
1301 ])
1302
1303 dnl #
1304 dnl # 3.1 API Change
1305 dnl #
1306 dnl # The rw_semaphore.wait_lock member was changed from spinlock_t to
1307 dnl # raw_spinlock_t at commit ddb6c9b58a19edcfac93ac670b066c836ff729f1.
1308 dnl #
1309 AC_DEFUN([SPL_AC_RWSEM_SPINLOCK_IS_RAW], [
1310 AC_MSG_CHECKING([whether struct rw_semaphore member wait_lock is raw])
1311 tmp_flags="$EXTRA_KCFLAGS"
1312 EXTRA_KCFLAGS="-Werror"
1313 SPL_LINUX_TRY_COMPILE([
1314 #include <linux/rwsem.h>
1315 ],[
1316 struct rw_semaphore dummy_semaphore __attribute__ ((unused));
1317 raw_spinlock_t dummy_lock __attribute__ ((unused)) =
1318 __RAW_SPIN_LOCK_INITIALIZER(dummy_lock);
1319 dummy_semaphore.wait_lock = dummy_lock;
1320 ],[
1321 AC_MSG_RESULT(yes)
1322 AC_DEFINE(RWSEM_SPINLOCK_IS_RAW, 1,
1323 [struct rw_semaphore member wait_lock is raw_spinlock_t])
1324 ],[
1325 AC_MSG_RESULT(no)
1326 ])
1327 EXTRA_KCFLAGS="$tmp_flags"
1328 ])
1329
1330 dnl #
1331 dnl # 3.16 API Change
1332 dnl #
1333 dnl # rwsem-spinlock "->activity" changed to "->count"
1334 dnl #
1335 AC_DEFUN([SPL_AC_RWSEM_ACTIVITY], [
1336 AC_MSG_CHECKING([whether struct rw_semaphore has member activity])
1337 tmp_flags="$EXTRA_KCFLAGS"
1338 EXTRA_KCFLAGS="-Werror"
1339 SPL_LINUX_TRY_COMPILE([
1340 #include <linux/rwsem.h>
1341 ],[
1342 struct rw_semaphore dummy_semaphore __attribute__ ((unused));
1343 dummy_semaphore.activity = 0;
1344 ],[
1345 AC_MSG_RESULT(yes)
1346 AC_DEFINE(HAVE_RWSEM_ACTIVITY, 1,
1347 [struct rw_semaphore has member activity])
1348 ],[
1349 AC_MSG_RESULT(no)
1350 ])
1351 EXTRA_KCFLAGS="$tmp_flags"
1352 ])
1353
1354 dnl #
1355 dnl # 4.8 API Change
1356 dnl #
1357 dnl # rwsem "->count" changed to atomic_long_t type
1358 dnl #
1359 AC_DEFUN([SPL_AC_RWSEM_ATOMIC_LONG_COUNT], [
1360 AC_MSG_CHECKING(
1361 [whether struct rw_semaphore has atomic_long_t member count])
1362 tmp_flags="$EXTRA_KCFLAGS"
1363 EXTRA_KCFLAGS="-Werror"
1364 SPL_LINUX_TRY_COMPILE([
1365 #include <linux/rwsem.h>
1366 ],[
1367 DECLARE_RWSEM(dummy_semaphore);
1368 (void) atomic_long_read(&dummy_semaphore.count);
1369 ],[
1370 AC_MSG_RESULT(yes)
1371 AC_DEFINE(HAVE_RWSEM_ATOMIC_LONG_COUNT, 1,
1372 [struct rw_semaphore has atomic_long_t member count])
1373 ],[
1374 AC_MSG_RESULT(no)
1375 ])
1376 EXTRA_KCFLAGS="$tmp_flags"
1377 ])
1378
1379 dnl #
1380 dnl # 3.9 API change,
1381 dnl # Moved things from linux/sched.h to linux/sched/rt.h
1382 dnl #
1383 AC_DEFUN([SPL_AC_SCHED_RT_HEADER],
1384 [AC_MSG_CHECKING([whether header linux/sched/rt.h exists])
1385 SPL_LINUX_TRY_COMPILE([
1386 #include <linux/sched.h>
1387 #include <linux/sched/rt.h>
1388 ],[
1389 return 0;
1390 ],[
1391 AC_DEFINE(HAVE_SCHED_RT_HEADER, 1, [linux/sched/rt.h exists])
1392 AC_MSG_RESULT(yes)
1393 ],[
1394 AC_MSG_RESULT(no)
1395 ])
1396 ])
1397
1398 dnl #
1399 dnl # 4.11 API change,
1400 dnl # Moved things from linux/sched.h to linux/sched/signal.h
1401 dnl #
1402 AC_DEFUN([SPL_AC_SCHED_SIGNAL_HEADER],
1403 [AC_MSG_CHECKING([whether header linux/sched/signal.h exists])
1404 SPL_LINUX_TRY_COMPILE([
1405 #include <linux/sched.h>
1406 #include <linux/sched/signal.h>
1407 ],[
1408 return 0;
1409 ],[
1410 AC_DEFINE(HAVE_SCHED_SIGNAL_HEADER, 1, [linux/sched/signal.h exists])
1411 AC_MSG_RESULT(yes)
1412 ],[
1413 AC_MSG_RESULT(no)
1414 ])
1415 ])
1416
1417 dnl #
1418 dnl # 4.11 API, a528d35e@torvalds/linux
1419 dnl # vfs_getattr(const struct path *p, struct kstat *s, u32 m, unsigned int f)
1420 dnl #
1421 AC_DEFUN([SPL_AC_4ARGS_VFS_GETATTR], [
1422 AC_MSG_CHECKING([whether vfs_getattr() wants 4 args])
1423 SPL_LINUX_TRY_COMPILE([
1424 #include <linux/fs.h>
1425 ],[
1426 vfs_getattr((const struct path *)NULL,
1427 (struct kstat *)NULL,
1428 (u32)0,
1429 (unsigned int)0);
1430 ],[
1431 AC_MSG_RESULT(yes)
1432 AC_DEFINE(HAVE_4ARGS_VFS_GETATTR, 1,
1433 [vfs_getattr wants 4 args])
1434 ],[
1435 AC_MSG_RESULT(no)
1436 ])
1437 ])
1438
1439 dnl #
1440 dnl # 3.9 API
1441 dnl # vfs_getattr(struct path *p, struct kstat *s)
1442 dnl #
1443 AC_DEFUN([SPL_AC_2ARGS_VFS_GETATTR], [
1444 AC_MSG_CHECKING([whether vfs_getattr() wants 2 args])
1445 SPL_LINUX_TRY_COMPILE([
1446 #include <linux/fs.h>
1447 ],[
1448 vfs_getattr((struct path *) NULL,
1449 (struct kstat *)NULL);
1450 ],[
1451 AC_MSG_RESULT(yes)
1452 AC_DEFINE(HAVE_2ARGS_VFS_GETATTR, 1,
1453 [vfs_getattr wants 2 args])
1454 ],[
1455 AC_MSG_RESULT(no)
1456 ])
1457 ])
1458
1459 dnl #
1460 dnl # <3.9 API
1461 dnl # vfs_getattr(struct vfsmount *v, struct dentry *d, struct kstat *k)
1462 dnl #
1463 AC_DEFUN([SPL_AC_3ARGS_VFS_GETATTR], [
1464 AC_MSG_CHECKING([whether vfs_getattr() wants 3 args])
1465 SPL_LINUX_TRY_COMPILE([
1466 #include <linux/fs.h>
1467 ],[
1468 vfs_getattr((struct vfsmount *)NULL,
1469 (struct dentry *)NULL,
1470 (struct kstat *)NULL);
1471 ],[
1472 AC_MSG_RESULT(yes)
1473 AC_DEFINE(HAVE_3ARGS_VFS_GETATTR, 1,
1474 [vfs_getattr wants 3 args])
1475 ],[
1476 AC_MSG_RESULT(no)
1477 ])
1478 ])
1479
1480 dnl #
1481 dnl # 2.6.36 API compatibility.
1482 dnl # Added usleep_range timer.
1483 dnl # usleep_range is a finer precision implementation of msleep
1484 dnl # designed to be a drop-in replacement for udelay where a precise
1485 dnl # sleep / busy-wait is unnecessary.
1486 dnl #
1487 AC_DEFUN([SPL_AC_USLEEP_RANGE], [
1488 AC_MSG_CHECKING([whether usleep_range() is available])
1489 SPL_LINUX_TRY_COMPILE([
1490 #include <linux/delay.h>
1491 ],[
1492 usleep_range(0, 0);
1493 ],[
1494 AC_MSG_RESULT(yes)
1495 AC_DEFINE(HAVE_USLEEP_RANGE, 1,
1496 [usleep_range is available])
1497 ],[
1498 AC_MSG_RESULT(no)
1499 ])
1500 ])
1501
1502 dnl #
1503 dnl # 2.6.35 API change,
1504 dnl # The cachep->gfpflags member was renamed cachep->allocflags. These are
1505 dnl # private allocation flags which are applied when allocating a new slab
1506 dnl # in kmem_getpages(). Unfortunately there is no public API for setting
1507 dnl # non-default flags.
1508 dnl #
1509 AC_DEFUN([SPL_AC_KMEM_CACHE_ALLOCFLAGS], [
1510 AC_MSG_CHECKING([whether struct kmem_cache has allocflags])
1511 SPL_LINUX_TRY_COMPILE([
1512 #include <linux/slab.h>
1513 ],[
1514 struct kmem_cache cachep __attribute__ ((unused));
1515 cachep.allocflags = GFP_KERNEL;
1516 ],[
1517 AC_MSG_RESULT(yes)
1518 AC_DEFINE(HAVE_KMEM_CACHE_ALLOCFLAGS, 1,
1519 [struct kmem_cache has allocflags])
1520 ],[
1521 AC_MSG_RESULT(no)
1522
1523 AC_MSG_CHECKING([whether struct kmem_cache has gfpflags])
1524 SPL_LINUX_TRY_COMPILE([
1525 #include <linux/slab.h>
1526 ],[
1527 struct kmem_cache cachep __attribute__ ((unused));
1528 cachep.gfpflags = GFP_KERNEL;
1529 ],[
1530 AC_MSG_RESULT(yes)
1531 AC_DEFINE(HAVE_KMEM_CACHE_GFPFLAGS, 1,
1532 [struct kmem_cache has gfpflags])
1533 ],[
1534 AC_MSG_RESULT(no)
1535 ])
1536 ])
1537 ])
1538
1539 dnl #
1540 dnl # 3.17 API change,
1541 dnl # wait_on_bit() no longer requires an action argument. The former
1542 dnl # "wait_on_bit" interface required an 'action' function to be provided
1543 dnl # which does the actual waiting. There were over 20 such functions in the
1544 dnl # kernel, many of them identical, though most cases can be satisfied by one
1545 dnl # of just two functions: one which uses io_schedule() and one which just
1546 dnl # uses schedule(). This API change was made to consolidate all of those
1547 dnl # redundant wait functions.
1548 dnl #
1549 AC_DEFUN([SPL_AC_WAIT_ON_BIT], [
1550 AC_MSG_CHECKING([whether wait_on_bit() takes an action])
1551 SPL_LINUX_TRY_COMPILE([
1552 #include <linux/wait.h>
1553 ],[
1554 int (*action)(void *) = NULL;
1555 wait_on_bit(NULL, 0, action, 0);
1556 ],[
1557 AC_MSG_RESULT(yes)
1558 AC_DEFINE(HAVE_WAIT_ON_BIT_ACTION, 1, [yes])
1559 ],[
1560 AC_MSG_RESULT(no)
1561 ])
1562 ])
1563
1564 dnl #
1565 dnl # 4.7 API change
1566 dnl # i_mutex is changed to i_rwsem. Instead of directly using
1567 dnl # i_mutex/i_rwsem, we should use inode_lock() and inode_lock_shared()
1568 dnl # We test inode_lock_shared because inode_lock is introduced earlier.
1569 dnl #
1570 AC_DEFUN([SPL_AC_INODE_LOCK], [
1571 AC_MSG_CHECKING([whether inode_lock_shared() exists])
1572 tmp_flags="$EXTRA_KCFLAGS"
1573 EXTRA_KCFLAGS="-Werror"
1574 SPL_LINUX_TRY_COMPILE([
1575 #include <linux/fs.h>
1576 ],[
1577 struct inode *inode = NULL;
1578 inode_lock_shared(inode);
1579 ],[
1580 AC_MSG_RESULT(yes)
1581 AC_DEFINE(HAVE_INODE_LOCK_SHARED, 1, [yes])
1582 ],[
1583 AC_MSG_RESULT(no)
1584 ])
1585 EXTRA_KCFLAGS="$tmp_flags"
1586 ])
1587
1588 dnl #
1589 dnl # 4.9 API change
1590 dnl # group_info changed from 2d array via >blocks to 1d array via ->gid
1591 dnl #
1592 AC_DEFUN([SPL_AC_GROUP_INFO_GID], [
1593 AC_MSG_CHECKING([whether group_info->gid exists])
1594 tmp_flags="$EXTRA_KCFLAGS"
1595 EXTRA_KCFLAGS="-Werror"
1596 SPL_LINUX_TRY_COMPILE([
1597 #include <linux/cred.h>
1598 ],[
1599 struct group_info *gi = groups_alloc(1);
1600 gi->gid[0] = KGIDT_INIT(0);
1601 ],[
1602 AC_MSG_RESULT(yes)
1603 AC_DEFINE(HAVE_GROUP_INFO_GID, 1, [group_info->gid exists])
1604 ],[
1605 AC_MSG_RESULT(no)
1606 ])
1607 EXTRA_KCFLAGS="$tmp_flags"
1608 ])
1609
1610 dnl #
1611 dnl # grsecurity API change,
1612 dnl # kmem_cache_create() with SLAB_USERCOPY flag replaced by
1613 dnl # kmem_cache_create_usercopy().
1614 dnl #
1615 AC_DEFUN([SPL_AC_KMEM_CACHE_CREATE_USERCOPY], [
1616 AC_MSG_CHECKING([whether kmem_cache_create_usercopy() exists])
1617 tmp_flags="$EXTRA_KCFLAGS"
1618 EXTRA_KCFLAGS="-Werror"
1619 SPL_LINUX_TRY_COMPILE([
1620 #include <linux/slab.h>
1621 static void ctor(void *foo)
1622 {
1623 // fake ctor
1624 }
1625 ],[
1626 struct kmem_cache *skc_linux_cache;
1627 const char *name = "test";
1628 size_t size = 4096;
1629 size_t align = 8;
1630 unsigned long flags = 0;
1631 size_t useroffset = 0;
1632 size_t usersize = size - useroffset;
1633
1634 skc_linux_cache = kmem_cache_create_usercopy(
1635 name, size, align, flags, useroffset, usersize, ctor);
1636 ],[
1637 AC_MSG_RESULT(yes)
1638 AC_DEFINE(HAVE_KMEM_CACHE_CREATE_USERCOPY, 1,
1639 [kmem_cache_create_usercopy() exists])
1640 ],[
1641 AC_MSG_RESULT(no)
1642 ])
1643 EXTRA_KCFLAGS="$tmp_flags"
1644 ])
1645
1646 dnl #
1647 dnl # 4.13 API change
1648 dnl # Renamed struct wait_queue -> struct wait_queue_entry.
1649 dnl #
1650 AC_DEFUN([SPL_AC_WAIT_QUEUE_ENTRY_T], [
1651 AC_MSG_CHECKING([whether wait_queue_entry_t exists])
1652 SPL_LINUX_TRY_COMPILE([
1653 #include <linux/wait.h>
1654 ],[
1655 wait_queue_entry_t *entry __attribute__ ((unused));
1656 ],[
1657 AC_MSG_RESULT(yes)
1658 AC_DEFINE(HAVE_WAIT_QUEUE_ENTRY_T, 1,
1659 [wait_queue_entry_t exists])
1660 ],[
1661 AC_MSG_RESULT(no)
1662 ])
1663 ])
1664
1665 dnl #
1666 dnl # 4.13 API change
1667 dnl # Renamed wait_queue_head::task_list -> wait_queue_head::head
1668 dnl # Renamed wait_queue_entry::task_list -> wait_queue_entry::entry
1669 dnl #
1670 AC_DEFUN([SPL_AC_WAIT_QUEUE_HEAD_ENTRY], [
1671 AC_MSG_CHECKING([whether wq_head->head and wq_entry->entry exist])
1672 SPL_LINUX_TRY_COMPILE([
1673 #include <linux/wait.h>
1674
1675 #ifdef HAVE_WAIT_QUEUE_ENTRY_T
1676 typedef wait_queue_head_t spl_wait_queue_head_t;
1677 typedef wait_queue_entry_t spl_wait_queue_entry_t;
1678 #else
1679 typedef wait_queue_head_t spl_wait_queue_head_t;
1680 typedef wait_queue_t spl_wait_queue_entry_t;
1681 #endif
1682 ],[
1683 spl_wait_queue_head_t wq_head;
1684 spl_wait_queue_entry_t wq_entry;
1685 struct list_head *head __attribute__ ((unused));
1686 struct list_head *entry __attribute__ ((unused));
1687
1688 head = &wq_head.head;
1689 entry = &wq_entry.entry;
1690 ],[
1691 AC_MSG_RESULT(yes)
1692 AC_DEFINE(HAVE_WAIT_QUEUE_HEAD_ENTRY, 1,
1693 [wq_head->head and wq_entry->entry exist])
1694 ],[
1695 AC_MSG_RESULT(no)
1696 ])
1697 ])