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