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