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