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