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