]> git.proxmox.com Git - mirror_zfs.git/blob - config/spl-build.m4
Remove linux/uaccess.h header 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_VMALLOC_INFO
29 SPL_AC_PDE_DATA
30 SPL_AC_KMALLOC_NODE
31 SPL_AC_INODE_I_MUTEX
32 SPL_AC_MUTEX_OWNER
33 SPL_AC_MUTEX_OWNER_TASK_STRUCT
34 SPL_AC_MUTEX_LOCK_NESTED
35 SPL_AC_3ARGS_ON_EACH_CPU
36 SPL_AC_KALLSYMS_LOOKUP_NAME
37 SPL_AC_GET_VMALLOC_INFO
38 SPL_AC_PGDAT_HELPERS
39 SPL_AC_FIRST_ONLINE_PGDAT
40 SPL_AC_NEXT_ONLINE_PGDAT
41 SPL_AC_NEXT_ZONE
42 SPL_AC_PGDAT_LIST
43 SPL_AC_GLOBAL_PAGE_STATE
44 SPL_AC_ZONE_STAT_ITEM_FREE
45 SPL_AC_ZONE_STAT_ITEM_INACTIVE
46 SPL_AC_ZONE_STAT_ITEM_ACTIVE
47 SPL_AC_GET_ZONE_COUNTS
48 SPL_AC_USER_PATH_DIR
49 SPL_AC_SET_FS_PWD
50 SPL_AC_SET_FS_PWD_WITH_CONST
51 SPL_AC_2ARGS_VFS_UNLINK
52 SPL_AC_4ARGS_VFS_RENAME
53 SPL_AC_VFS_FSYNC
54 SPL_AC_2ARGS_VFS_FSYNC
55 SPL_AC_INODE_TRUNCATE_RANGE
56 SPL_AC_FS_STRUCT_SPINLOCK
57 SPL_AC_CRED_STRUCT
58 SPL_AC_KUIDGID_T
59 SPL_AC_GROUPS_SEARCH
60 SPL_AC_PUT_TASK_STRUCT
61 SPL_AC_5ARGS_PROC_HANDLER
62 SPL_AC_KVASPRINTF
63 SPL_AC_EXPORTED_RWSEM_IS_LOCKED
64 SPL_AC_KERNEL_FALLOCATE
65 SPL_AC_SHRINK_DCACHE_MEMORY
66 SPL_AC_SHRINK_ICACHE_MEMORY
67 SPL_AC_KERN_PATH
68 SPL_AC_CONFIG_KALLSYMS
69 SPL_AC_CONFIG_ZLIB_INFLATE
70 SPL_AC_CONFIG_ZLIB_DEFLATE
71 SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE
72 SPL_AC_SHRINK_CONTROL_STRUCT
73 SPL_AC_RWSEM_SPINLOCK_IS_RAW
74 SPL_AC_SCHED_RT_HEADER
75 SPL_AC_2ARGS_VFS_GETATTR
76 SPL_AC_USLEEP_RANGE
77 SPL_AC_KMEM_CACHE_ALLOCFLAGS
78 SPL_AC_WAIT_ON_BIT
79 ])
80
81 AC_DEFUN([SPL_AC_MODULE_SYMVERS], [
82 modpost=$LINUX/scripts/Makefile.modpost
83 AC_MSG_CHECKING([kernel file name for module symbols])
84 if test "x$enable_linux_builtin" != xyes -a -f "$modpost"; then
85 if grep -q Modules.symvers $modpost; then
86 LINUX_SYMBOLS=Modules.symvers
87 else
88 LINUX_SYMBOLS=Module.symvers
89 fi
90
91 if ! test -f "$LINUX_OBJ/$LINUX_SYMBOLS"; then
92 AC_MSG_ERROR([
93 *** Please make sure the kernel devel package for your distribution
94 *** is installed. If you are building with a custom kernel, make sure the
95 *** kernel is configured, built, and the '--with-linux=PATH' configure
96 *** option refers to the location of the kernel source.])
97 fi
98 else
99 LINUX_SYMBOLS=NONE
100 fi
101 AC_MSG_RESULT($LINUX_SYMBOLS)
102 AC_SUBST(LINUX_SYMBOLS)
103 ])
104
105 AC_DEFUN([SPL_AC_KERNEL], [
106 AC_ARG_WITH([linux],
107 AS_HELP_STRING([--with-linux=PATH],
108 [Path to kernel source]),
109 [kernelsrc="$withval"])
110
111 AC_ARG_WITH([linux-obj],
112 AS_HELP_STRING([--with-linux-obj=PATH],
113 [Path to kernel build objects]),
114 [kernelbuild="$withval"])
115
116 AC_MSG_CHECKING([kernel source directory])
117 if test -z "$kernelsrc"; then
118 if test -e "/lib/modules/$(uname -r)/source"; then
119 headersdir="/lib/modules/$(uname -r)/source"
120 sourcelink=$(readlink -f "$headersdir")
121 elif test -e "/lib/modules/$(uname -r)/build"; then
122 headersdir="/lib/modules/$(uname -r)/build"
123 sourcelink=$(readlink -f "$headersdir")
124 else
125 sourcelink=$(ls -1d /usr/src/kernels/* \
126 /usr/src/linux-* \
127 2>/dev/null | grep -v obj | tail -1)
128 fi
129
130 if test -n "$sourcelink" && test -e ${sourcelink}; then
131 kernelsrc=`readlink -f ${sourcelink}`
132 else
133 kernelsrc="[Not found]"
134 fi
135 else
136 if test "$kernelsrc" = "NONE"; then
137 kernsrcver=NONE
138 fi
139 fi
140
141 AC_MSG_RESULT([$kernelsrc])
142 if test ! -d "$kernelsrc"; then
143 AC_MSG_ERROR([
144 *** Please make sure the kernel devel package for your distribution
145 *** is installed and then try again. If that fails, you can specify the
146 *** location of the kernel source with the '--with-linux=PATH' option.])
147 fi
148
149 AC_MSG_CHECKING([kernel build directory])
150 if test -z "$kernelbuild"; then
151 if test -e "/lib/modules/$(uname -r)/build"; then
152 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
153 elif test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
154 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
155 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
156 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
157 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
158 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
159 else
160 kernelbuild=${kernelsrc}
161 fi
162 fi
163 AC_MSG_RESULT([$kernelbuild])
164
165 AC_MSG_CHECKING([kernel source version])
166 utsrelease1=$kernelbuild/include/linux/version.h
167 utsrelease2=$kernelbuild/include/linux/utsrelease.h
168 utsrelease3=$kernelbuild/include/generated/utsrelease.h
169 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
170 utsrelease=linux/version.h
171 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
172 utsrelease=linux/utsrelease.h
173 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
174 utsrelease=generated/utsrelease.h
175 fi
176
177 if test "$utsrelease"; then
178 kernsrcver=`(echo "#include <$utsrelease>";
179 echo "kernsrcver=UTS_RELEASE") |
180 cpp -I $kernelbuild/include |
181 grep "^kernsrcver=" | cut -d \" -f 2`
182
183 if test -z "$kernsrcver"; then
184 AC_MSG_RESULT([Not found])
185 AC_MSG_ERROR([*** Cannot determine kernel version.])
186 fi
187 else
188 AC_MSG_RESULT([Not found])
189 if test "x$enable_linux_builtin" != xyes; then
190 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
191 else
192 AC_MSG_ERROR([
193 *** Cannot find UTS_RELEASE definition.
194 *** Please run 'make prepare' inside the kernel source tree.])
195 fi
196 fi
197
198 AC_MSG_RESULT([$kernsrcver])
199
200 LINUX=${kernelsrc}
201 LINUX_OBJ=${kernelbuild}
202 LINUX_VERSION=${kernsrcver}
203
204 AC_SUBST(LINUX)
205 AC_SUBST(LINUX_OBJ)
206 AC_SUBST(LINUX_VERSION)
207
208 SPL_AC_MODULE_SYMVERS
209 ])
210
211 dnl #
212 dnl # Default SPL user configuration
213 dnl #
214 AC_DEFUN([SPL_AC_CONFIG_USER], [])
215
216 dnl #
217 dnl # Check for rpm+rpmbuild to build RPM packages. If these tools
218 dnl # are missing, it is non-fatal, but you will not be able to build
219 dnl # RPM packages and will be warned if you try too.
220 dnl #
221 dnl # By default, the generic spec file will be used because it requires
222 dnl # minimal dependencies. Distribution specific spec files can be
223 dnl # placed under the 'rpm/<distribution>' directory and enabled using
224 dnl # the --with-spec=<distribution> configure option.
225 dnl #
226 AC_DEFUN([SPL_AC_RPM], [
227 RPM=rpm
228 RPMBUILD=rpmbuild
229
230 AC_MSG_CHECKING([whether $RPM is available])
231 AS_IF([tmp=$($RPM --version 2>/dev/null)], [
232 RPM_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
233 HAVE_RPM=yes
234 AC_MSG_RESULT([$HAVE_RPM ($RPM_VERSION)])
235 ],[
236 HAVE_RPM=no
237 AC_MSG_RESULT([$HAVE_RPM])
238 ])
239
240 AC_MSG_CHECKING([whether $RPMBUILD is available])
241 AS_IF([tmp=$($RPMBUILD --version 2>/dev/null)], [
242 RPMBUILD_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
243 HAVE_RPMBUILD=yes
244 AC_MSG_RESULT([$HAVE_RPMBUILD ($RPMBUILD_VERSION)])
245 ],[
246 HAVE_RPMBUILD=no
247 AC_MSG_RESULT([$HAVE_RPMBUILD])
248 ])
249
250 RPM_DEFINE_COMMON='--define "$(DEBUG_SPL) 1" --define "$(DEBUG_LOG) 1" --define "$(DEBUG_KMEM) 1" --define "$(DEBUG_KMEM_TRACKING) 1"'
251 RPM_DEFINE_UTIL=
252 RPM_DEFINE_KMOD='--define "kernels $(LINUX_VERSION)"'
253 RPM_DEFINE_DKMS=
254
255 SRPM_DEFINE_COMMON='--define "build_src_rpm 1"'
256 SRPM_DEFINE_UTIL=
257 SRPM_DEFINE_KMOD=
258 SRPM_DEFINE_DKMS=
259
260 RPM_SPEC_DIR="rpm/generic"
261 AC_ARG_WITH([spec],
262 AS_HELP_STRING([--with-spec=SPEC],
263 [Spec files 'generic|fedora']),
264 [RPM_SPEC_DIR="rpm/$withval"])
265
266 AC_MSG_CHECKING([whether spec files are available])
267 AC_MSG_RESULT([yes ($RPM_SPEC_DIR/*.spec.in)])
268
269 AC_SUBST(HAVE_RPM)
270 AC_SUBST(RPM)
271 AC_SUBST(RPM_VERSION)
272
273 AC_SUBST(HAVE_RPMBUILD)
274 AC_SUBST(RPMBUILD)
275 AC_SUBST(RPMBUILD_VERSION)
276
277 AC_SUBST(RPM_SPEC_DIR)
278 AC_SUBST(RPM_DEFINE_UTIL)
279 AC_SUBST(RPM_DEFINE_KMOD)
280 AC_SUBST(RPM_DEFINE_DKMS)
281 AC_SUBST(RPM_DEFINE_COMMON)
282 AC_SUBST(SRPM_DEFINE_UTIL)
283 AC_SUBST(SRPM_DEFINE_KMOD)
284 AC_SUBST(SRPM_DEFINE_DKMS)
285 AC_SUBST(SRPM_DEFINE_COMMON)
286 ])
287
288 dnl #
289 dnl # Check for dpkg+dpkg-buildpackage to build DEB packages. If these
290 dnl # tools are missing it is non-fatal but you will not be able to build
291 dnl # DEB packages and will be warned if you try too.
292 dnl #
293 AC_DEFUN([SPL_AC_DPKG], [
294 DPKG=dpkg
295 DPKGBUILD=dpkg-buildpackage
296
297 AC_MSG_CHECKING([whether $DPKG is available])
298 AS_IF([tmp=$($DPKG --version 2>/dev/null)], [
299 DPKG_VERSION=$(echo $tmp | $AWK '/Debian/ { print $[7] }')
300 HAVE_DPKG=yes
301 AC_MSG_RESULT([$HAVE_DPKG ($DPKG_VERSION)])
302 ],[
303 HAVE_DPKG=no
304 AC_MSG_RESULT([$HAVE_DPKG])
305 ])
306
307 AC_MSG_CHECKING([whether $DPKGBUILD is available])
308 AS_IF([tmp=$($DPKGBUILD --version 2>/dev/null)], [
309 DPKGBUILD_VERSION=$(echo $tmp | \
310 $AWK '/Debian/ { print $[4] }' | cut -f-4 -d'.')
311 HAVE_DPKGBUILD=yes
312 AC_MSG_RESULT([$HAVE_DPKGBUILD ($DPKGBUILD_VERSION)])
313 ],[
314 HAVE_DPKGBUILD=no
315 AC_MSG_RESULT([$HAVE_DPKGBUILD])
316 ])
317
318 AC_SUBST(HAVE_DPKG)
319 AC_SUBST(DPKG)
320 AC_SUBST(DPKG_VERSION)
321
322 AC_SUBST(HAVE_DPKGBUILD)
323 AC_SUBST(DPKGBUILD)
324 AC_SUBST(DPKGBUILD_VERSION)
325 ])
326
327 dnl #
328 dnl # Until native packaging for various different packing systems
329 dnl # can be added the least we can do is attempt to use alien to
330 dnl # convert the RPM packages to the needed package type. This is
331 dnl # a hack but so far it has worked reasonable well.
332 dnl #
333 AC_DEFUN([SPL_AC_ALIEN], [
334 ALIEN=alien
335
336 AC_MSG_CHECKING([whether $ALIEN is available])
337 AS_IF([tmp=$($ALIEN --version 2>/dev/null)], [
338 ALIEN_VERSION=$(echo $tmp | $AWK '{ print $[3] }')
339 HAVE_ALIEN=yes
340 AC_MSG_RESULT([$HAVE_ALIEN ($ALIEN_VERSION)])
341 ],[
342 HAVE_ALIEN=no
343 AC_MSG_RESULT([$HAVE_ALIEN])
344 ])
345
346 AC_SUBST(HAVE_ALIEN)
347 AC_SUBST(ALIEN)
348 AC_SUBST(ALIEN_VERSION)
349 ])
350
351 dnl #
352 dnl # Using the VENDOR tag from config.guess set the default
353 dnl # package type for 'make pkg': (rpm | deb | tgz)
354 dnl #
355 AC_DEFUN([SPL_AC_DEFAULT_PACKAGE], [
356 AC_MSG_CHECKING([linux distribution])
357 if test -f /etc/toss-release ; then
358 VENDOR=toss ;
359 elif test -f /etc/fedora-release ; then
360 VENDOR=fedora ;
361 elif test -f /etc/redhat-release ; then
362 VENDOR=redhat ;
363 elif test -f /etc/gentoo-release ; then
364 VENDOR=gentoo ;
365 elif test -f /etc/arch-release ; then
366 VENDOR=arch ;
367 elif test -f /etc/SuSE-release ; then
368 VENDOR=sles ;
369 elif test -f /etc/slackware-version ; then
370 VENDOR=slackware ;
371 elif test -f /etc/lunar.release ; then
372 VENDOR=lunar ;
373 elif test -f /etc/lsb-release ; then
374 VENDOR=ubuntu ;
375 elif test -f /etc/debian_version ; then
376 VENDOR=debian ;
377 else
378 VENDOR= ;
379 fi
380 AC_MSG_RESULT([$VENDOR])
381 AC_SUBST(VENDOR)
382
383 AC_MSG_CHECKING([default package type])
384 case "$VENDOR" in
385 toss) DEFAULT_PACKAGE=rpm ;;
386 redhat) DEFAULT_PACKAGE=rpm ;;
387 fedora) DEFAULT_PACKAGE=rpm ;;
388 gentoo) DEFAULT_PACKAGE=tgz ;;
389 arch) DEFAULT_PACKAGE=tgz ;;
390 sles) DEFAULT_PACKAGE=rpm ;;
391 slackware) DEFAULT_PACKAGE=tgz ;;
392 lunar) DEFAULT_PACKAGE=tgz ;;
393 ubuntu) DEFAULT_PACKAGE=deb ;;
394 debian) DEFAULT_PACKAGE=deb ;;
395 *) DEFAULT_PACKAGE=rpm ;;
396 esac
397
398 AC_MSG_RESULT([$DEFAULT_PACKAGE])
399 AC_SUBST(DEFAULT_PACKAGE)
400 ])
401
402 dnl #
403 dnl # Default SPL user configuration
404 dnl #
405 AC_DEFUN([SPL_AC_PACKAGE], [
406 SPL_AC_DEFAULT_PACKAGE
407 SPL_AC_RPM
408 SPL_AC_DPKG
409 SPL_AC_ALIEN
410 ])
411
412 AC_DEFUN([SPL_AC_LICENSE], [
413 AC_MSG_CHECKING([spl author])
414 AC_MSG_RESULT([$SPL_META_AUTHOR])
415
416 AC_MSG_CHECKING([spl license])
417 AC_MSG_RESULT([$SPL_META_LICENSE])
418 ])
419
420 AC_DEFUN([SPL_AC_CONFIG], [
421 SPL_CONFIG=all
422 AC_ARG_WITH([config],
423 AS_HELP_STRING([--with-config=CONFIG],
424 [Config file 'kernel|user|all|srpm']),
425 [SPL_CONFIG="$withval"])
426 AC_ARG_ENABLE([linux-builtin],
427 [AC_HELP_STRING([--enable-linux-builtin],
428 [Configure for builtin in-tree kernel modules @<:@default=no@:>@])],
429 [],
430 [enable_linux_builtin=no])
431
432 AC_MSG_CHECKING([spl config])
433 AC_MSG_RESULT([$SPL_CONFIG]);
434 AC_SUBST(SPL_CONFIG)
435
436 case "$SPL_CONFIG" in
437 kernel) SPL_AC_CONFIG_KERNEL ;;
438 user) SPL_AC_CONFIG_USER ;;
439 all) SPL_AC_CONFIG_KERNEL
440 SPL_AC_CONFIG_USER ;;
441 srpm) ;;
442 *)
443 AC_MSG_RESULT([Error!])
444 AC_MSG_ERROR([Bad value "$SPL_CONFIG" for --with-config,
445 user kernel|user|all|srpm]) ;;
446 esac
447
448 AM_CONDITIONAL([CONFIG_USER],
449 [test "$SPL_CONFIG" = user -o "$SPL_CONFIG" = all])
450 AM_CONDITIONAL([CONFIG_KERNEL],
451 [test "$SPL_CONFIG" = kernel -o "$SPL_CONFIG" = all] &&
452 [test "x$enable_linux_builtin" != xyes ])
453 ])
454
455 dnl #
456 dnl # Enable if the SPL should be compiled with internal debugging enabled.
457 dnl # By default this support is disabled.
458 dnl #
459 AC_DEFUN([SPL_AC_DEBUG], [
460 AC_MSG_CHECKING([whether debugging is enabled])
461 AC_ARG_ENABLE([debug],
462 [AS_HELP_STRING([--enable-debug],
463 [Enable generic debug support @<:@default=no@:>@])],
464 [],
465 [enable_debug=no])
466
467 AS_IF([test "x$enable_debug" = xyes],
468 [
469 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG -Werror"
470 DEBUG_CFLAGS="-DDEBUG -Werror"
471 DEBUG_SPL="_with_debug"
472 ], [
473 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
474 DEBUG_CFLAGS="-DNDEBUG"
475 DEBUG_SPL="_without_debug"
476 ])
477
478 AC_SUBST(DEBUG_CFLAGS)
479 AC_SUBST(DEBUG_SPL)
480 AC_MSG_RESULT([$enable_debug])
481 ])
482
483 dnl #
484 dnl # Enabled by default it provides a basic debug log infrastructure.
485 dnl # Each subsystem registers itself with a name and logs messages
486 dnl # using predefined types. If the debug mask it set to allow the
487 dnl # message type it will be written to the internal log. The log
488 dnl # can be dumped to a file by echoing 1 to the 'dump' proc entry,
489 dnl # after dumping the log it must be decoded using the spl utility.
490 dnl #
491 dnl # echo 1 >/proc/sys/kernel/spl/debug/dump
492 dnl # spl /tmp/spl-log.xxx.yyy /tmp/spl-log.xxx.yyy.txt
493 dnl #
494 AC_DEFUN([SPL_AC_DEBUG_LOG], [
495 AC_ARG_ENABLE([debug-log],
496 [AS_HELP_STRING([--enable-debug-log],
497 [Enable basic debug logging @<:@default=yes@:>@])],
498 [],
499 [enable_debug_log=yes])
500
501 AS_IF([test "x$enable_debug_log" = xyes],
502 [
503 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_LOG"
504 DEBUG_LOG="_with_debug_log"
505 AC_DEFINE([DEBUG_LOG], [1],
506 [Define to 1 to enable basic debug logging])
507 ], [
508 DEBUG_LOG="_without_debug_log"
509 ])
510
511 AC_SUBST(DEBUG_LOG)
512 AC_MSG_CHECKING([whether basic debug logging is enabled])
513 AC_MSG_RESULT([$enable_debug_log])
514 ])
515
516 dnl #
517 dnl # Enabled by default it provides a minimal level of memory tracking.
518 dnl # A total count of bytes allocated is kept for each alloc and free.
519 dnl # Then at module unload time a report to the console will be printed
520 dnl # if memory was leaked. Additionally, /proc/spl/kmem/slab will exist
521 dnl # and provide an easy way to inspect the kmem based slab.
522 dnl #
523 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
524 AC_ARG_ENABLE([debug-kmem],
525 [AS_HELP_STRING([--enable-debug-kmem],
526 [Enable basic kmem accounting @<:@default=yes@:>@])],
527 [],
528 [enable_debug_kmem=yes])
529
530 AS_IF([test "x$enable_debug_kmem" = xyes],
531 [
532 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"
533 DEBUG_KMEM="_with_debug_kmem"
534 AC_DEFINE([DEBUG_KMEM], [1],
535 [Define to 1 to enable basic kmem accounting])
536 ], [
537 DEBUG_KMEM="_without_debug_kmem"
538 ])
539
540 AC_SUBST(DEBUG_KMEM)
541 AC_MSG_CHECKING([whether basic kmem accounting is enabled])
542 AC_MSG_RESULT([$enable_debug_kmem])
543 ])
544
545 dnl #
546 dnl # Disabled by default it provides detailed memory tracking. This
547 dnl # feature also requires --enable-debug-kmem to be set. When enabled
548 dnl # not only will total bytes be tracked but also the location of every
549 dnl # alloc and free. When the SPL module is unloaded a list of all leaked
550 dnl # addresses and where they were allocated will be dumped to the console.
551 dnl # Enabling this feature has a significant impact on performance but it
552 dnl # makes finding memory leaks pretty straight forward.
553 dnl #
554 AC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [
555 AC_ARG_ENABLE([debug-kmem-tracking],
556 [AS_HELP_STRING([--enable-debug-kmem-tracking],
557 [Enable detailed kmem tracking @<:@default=no@:>@])],
558 [],
559 [enable_debug_kmem_tracking=no])
560
561 AS_IF([test "x$enable_debug_kmem_tracking" = xyes],
562 [
563 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM_TRACKING"
564 DEBUG_KMEM_TRACKING="_with_debug_kmem_tracking"
565 AC_DEFINE([DEBUG_KMEM_TRACKING], [1],
566 [Define to 1 to enable detailed kmem tracking])
567 ], [
568 DEBUG_KMEM_TRACKING="_without_debug_kmem_tracking"
569 ])
570
571 AC_SUBST(DEBUG_KMEM_TRACKING)
572 AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
573 AC_MSG_RESULT([$enable_debug_kmem_tracking])
574 ])
575
576 dnl #
577 dnl # SPL_LINUX_CONFTEST
578 dnl #
579 AC_DEFUN([SPL_LINUX_CONFTEST], [
580 cat confdefs.h - <<_ACEOF >conftest.c
581 $1
582 _ACEOF
583 ])
584
585 dnl #
586 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
587 dnl #
588 m4_define([SPL_LANG_PROGRAM], [
589 $1
590 int
591 main (void)
592 {
593 dnl Do *not* indent the following line: there may be CPP directives.
594 dnl Don't move the `;' right after for the same reason.
595 $2
596 ;
597 return 0;
598 }
599 ])
600
601 dnl #
602 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
603 dnl #
604 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
605 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])
606 rm -Rf build && mkdir -p build && touch build/conftest.mod.c
607 echo "obj-m := conftest.o" >build/Makefile
608 modpost_flag=''
609 test "x$enable_linux_builtin" = xyes && modpost_flag='modpost=true' # fake modpost stage
610 AS_IF(
611 [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])],
612 [$4],
613 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
614 )
615 rm -Rf build
616 ])
617
618 dnl #
619 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
620 dnl #
621 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
622 [SPL_LINUX_COMPILE_IFELSE(
623 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
624 [modules],
625 [test -s build/conftest.o],
626 [$3], [$4])
627 ])
628
629 dnl #
630 dnl # SPL_CHECK_SYMBOL_EXPORT
631 dnl # check symbol exported or not
632 dnl #
633 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT], [
634 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
635 $LINUX_OBJ/Module*.symvers 2>/dev/null
636 rc=$?
637 if test $rc -ne 0; then
638 export=0
639 for file in $2; do
640 grep -q -E "EXPORT_SYMBOL.*($1)" \
641 "$LINUX_OBJ/$file" 2>/dev/null
642 rc=$?
643 if test $rc -eq 0; then
644 export=1
645 break;
646 fi
647 done
648 if test $export -eq 0; then :
649 $4
650 else :
651 $3
652 fi
653 else :
654 $3
655 fi
656 ])
657
658 dnl #
659 dnl # SPL_LINUX_TRY_COMPILE_SYMBOL
660 dnl # like SPL_LINUX_TRY_COMPILE, except SPL_CHECK_SYMBOL_EXPORT
661 dnl # is called if not compiling for builtin
662 dnl #
663 AC_DEFUN([SPL_LINUX_TRY_COMPILE_SYMBOL], [
664 SPL_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
665 if test $rc -ne 0; then :
666 $6
667 else
668 if test "x$enable_linux_builtin" != xyes; then
669 SPL_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
670 fi
671 if test $rc -ne 0; then :
672 $6
673 else :
674 $5
675 fi
676 fi
677 ])
678
679 dnl #
680 dnl # SPL_CHECK_SYMBOL_HEADER
681 dnl # check if a symbol prototype is defined in listed headers.
682 dnl #
683 AC_DEFUN([SPL_CHECK_SYMBOL_HEADER], [
684 AC_MSG_CHECKING([whether symbol $1 exists in header])
685 header=0
686 for file in $3; do
687 grep -q "$2" "$LINUX/$file" 2>/dev/null
688 rc=$?
689 if test $rc -eq 0; then
690 header=1
691 break;
692 fi
693 done
694 if test $header -eq 0; then
695 AC_MSG_RESULT([no])
696 $5
697 else
698 AC_MSG_RESULT([yes])
699 $4
700 fi
701 ])
702
703 dnl #
704 dnl # SPL_CHECK_HEADER
705 dnl # check whether header exists and define HAVE_$2_HEADER
706 dnl #
707 AC_DEFUN([SPL_CHECK_HEADER],
708 [AC_MSG_CHECKING([whether header $1 exists])
709 SPL_LINUX_TRY_COMPILE([
710 #include <$1>
711 ],[
712 return 0;
713 ],[
714 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
715 AC_MSG_RESULT(yes)
716 $3
717 ],[
718 AC_MSG_RESULT(no)
719 $4
720 ])
721 ])
722
723 dnl #
724 dnl # Basic toolchain sanity check. Verify that kernel modules can
725 dnl # be built and which symbols can be used.
726 dnl #
727 AC_DEFUN([SPL_AC_TEST_MODULE],
728 [AC_MSG_CHECKING([whether modules can be built])
729 SPL_LINUX_TRY_COMPILE([],[],[
730 AC_MSG_RESULT([yes])
731 ],[
732 AC_MSG_RESULT([no])
733 if test "x$enable_linux_builtin" != xyes; then
734 AC_MSG_ERROR([*** Unable to build an empty module.])
735 else
736 AC_MSG_ERROR([
737 *** Unable to build an empty module.
738 *** Please run 'make scripts' inside the kernel source tree.])
739 fi
740 ])
741
742 AC_RUN_IFELSE([
743 AC_LANG_PROGRAM([
744 #include "$LINUX/include/linux/license.h"
745 ], [
746 return !license_is_gpl_compatible("$SPL_META_LICENSE");
747 ])
748 ], [
749 AC_DEFINE([SPL_IS_GPL_COMPATIBLE], [1],
750 [Define to 1 if GPL-only symbols can be used])
751 ], [
752 ])
753 ])
754
755 dnl #
756 dnl # Use the atomic implemenation based on global spinlocks. This
757 dnl # should only be needed by 32-bit kernels which do not provide
758 dnl # the atomic64_* API. It may be optionally enabled as a fallback
759 dnl # if problems are observed with the direct mapping to the native
760 dnl # Linux atomic operations. You may not disable atomic spinlocks
761 dnl # if you kernel does not an atomic64_* API.
762 dnl #
763 AC_DEFUN([SPL_AC_ATOMIC_SPINLOCK], [
764 AC_ARG_ENABLE([atomic-spinlocks],
765 [AS_HELP_STRING([--enable-atomic-spinlocks],
766 [Atomic types use spinlocks @<:@default=check@:>@])],
767 [],
768 [enable_atomic_spinlocks=check])
769
770 SPL_LINUX_TRY_COMPILE([
771 #include <linux/fs.h>
772 ],[
773 atomic64_t *ptr __attribute__ ((unused));
774 ],[
775 have_atomic64_t=yes
776 AC_DEFINE(HAVE_ATOMIC64_T, 1,
777 [kernel defines atomic64_t])
778 ],[
779 have_atomic64_t=no
780 ])
781
782 AS_IF([test "x$enable_atomic_spinlocks" = xcheck], [
783 AS_IF([test "x$have_atomic64_t" = xyes], [
784 enable_atomic_spinlocks=no
785 ],[
786 enable_atomic_spinlocks=yes
787 ])
788 ])
789
790 AS_IF([test "x$enable_atomic_spinlocks" = xyes], [
791 AC_DEFINE([ATOMIC_SPINLOCK], [1],
792 [Atomic types use spinlocks])
793 ],[
794 AS_IF([test "x$have_atomic64_t" = xno], [
795 AC_MSG_FAILURE(
796 [--disable-atomic-spinlocks given but required atomic64 support is unavailable])
797 ])
798 ])
799
800 AC_MSG_CHECKING([whether atomic types use spinlocks])
801 AC_MSG_RESULT([$enable_atomic_spinlocks])
802
803 AC_MSG_CHECKING([whether kernel defines atomic64_t])
804 AC_MSG_RESULT([$have_atomic64_t])
805 ])
806
807 AC_DEFUN([SPL_AC_SHRINKER_CALLBACK],[
808 tmp_flags="$EXTRA_KCFLAGS"
809 EXTRA_KCFLAGS="-Werror"
810 dnl #
811 dnl # 2.6.23 to 2.6.34 API change
812 dnl # ->shrink(int nr_to_scan, gfp_t gfp_mask)
813 dnl #
814 AC_MSG_CHECKING([whether old 2-argument shrinker exists])
815 SPL_LINUX_TRY_COMPILE([
816 #include <linux/mm.h>
817
818 int shrinker_cb(int nr_to_scan, gfp_t gfp_mask);
819 ],[
820 struct shrinker cache_shrinker = {
821 .shrink = shrinker_cb,
822 .seeks = DEFAULT_SEEKS,
823 };
824 register_shrinker(&cache_shrinker);
825 ],[
826 AC_MSG_RESULT(yes)
827 AC_DEFINE(HAVE_2ARGS_OLD_SHRINKER_CALLBACK, 1,
828 [old shrinker callback wants 2 args])
829 ],[
830 AC_MSG_RESULT(no)
831 dnl #
832 dnl # 2.6.35 - 2.6.39 API change
833 dnl # ->shrink(struct shrinker *,
834 dnl # int nr_to_scan, gfp_t gfp_mask)
835 dnl #
836 AC_MSG_CHECKING([whether old 3-argument shrinker exists])
837 SPL_LINUX_TRY_COMPILE([
838 #include <linux/mm.h>
839
840 int shrinker_cb(struct shrinker *, int nr_to_scan,
841 gfp_t gfp_mask);
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_3ARGS_SHRINKER_CALLBACK, 1,
851 [old shrinker callback wants 3 args])
852 ],[
853 AC_MSG_RESULT(no)
854 dnl #
855 dnl # 3.0 - 3.11 API change
856 dnl # ->shrink(struct shrinker *,
857 dnl # struct shrink_control *sc)
858 dnl #
859 AC_MSG_CHECKING(
860 [whether new 2-argument shrinker exists])
861 SPL_LINUX_TRY_COMPILE([
862 #include <linux/mm.h>
863
864 int shrinker_cb(struct shrinker *,
865 struct shrink_control *sc);
866 ],[
867 struct shrinker cache_shrinker = {
868 .shrink = shrinker_cb,
869 .seeks = DEFAULT_SEEKS,
870 };
871 register_shrinker(&cache_shrinker);
872 ],[
873 AC_MSG_RESULT(yes)
874 AC_DEFINE(HAVE_2ARGS_NEW_SHRINKER_CALLBACK, 1,
875 [new shrinker callback wants 2 args])
876 ],[
877 AC_MSG_RESULT(no)
878 dnl #
879 dnl # 3.12 API change,
880 dnl # ->shrink() is logically split in to
881 dnl # ->count_objects() and ->scan_objects()
882 dnl #
883 AC_MSG_CHECKING(
884 [whether ->count_objects callback exists])
885 SPL_LINUX_TRY_COMPILE([
886 #include <linux/mm.h>
887
888 unsigned long shrinker_cb(
889 struct shrinker *,
890 struct shrink_control *sc);
891 ],[
892 struct shrinker cache_shrinker = {
893 .count_objects = shrinker_cb,
894 .scan_objects = shrinker_cb,
895 .seeks = DEFAULT_SEEKS,
896 };
897 register_shrinker(&cache_shrinker);
898 ],[
899 AC_MSG_RESULT(yes)
900 AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK,
901 1, [->count_objects exists])
902 ],[
903 AC_MSG_ERROR(error)
904 ])
905 ])
906 ])
907 ])
908 EXTRA_KCFLAGS="$tmp_flags"
909 ])
910
911 dnl #
912 dnl # 2.6.33 API change,
913 dnl # Removed .ctl_name from struct ctl_table.
914 dnl #
915 AC_DEFUN([SPL_AC_CTL_NAME], [
916 AC_MSG_CHECKING([whether struct ctl_table has ctl_name])
917 SPL_LINUX_TRY_COMPILE([
918 #include <linux/sysctl.h>
919 ],[
920 struct ctl_table ctl __attribute__ ((unused));
921 ctl.ctl_name = 0;
922 ],[
923 AC_MSG_RESULT(yes)
924 AC_DEFINE(HAVE_CTL_NAME, 1, [struct ctl_table has ctl_name])
925 ],[
926 AC_MSG_RESULT(no)
927 ])
928 ])
929
930 dnl #
931 dnl # 2.6.12 API change,
932 dnl # check whether 'kmalloc_node()' is available.
933 dnl #
934 AC_DEFUN([SPL_AC_KMALLOC_NODE], [
935 AC_MSG_CHECKING([whether kmalloc_node() is available])
936 SPL_LINUX_TRY_COMPILE([
937 #include <linux/slab.h>
938 ],[
939 void *a __attribute__ ((unused));
940 a = kmalloc_node(1, GFP_KERNEL, 0);
941 ],[
942 AC_MSG_RESULT(yes)
943 AC_DEFINE(HAVE_KMALLOC_NODE, 1, [kmalloc_node() is available])
944 ],[
945 AC_MSG_RESULT(no)
946 ])
947 ])
948
949 dnl #
950 dnl # 2.6.16 API change,
951 dnl # check whether 'struct inode' has i_mutex
952 dnl #
953 AC_DEFUN([SPL_AC_INODE_I_MUTEX], [
954 AC_MSG_CHECKING([whether struct inode has i_mutex])
955 SPL_LINUX_TRY_COMPILE([
956 #include <linux/fs.h>
957 #include <linux/mutex.h>
958 ],[
959 struct inode i;
960 mutex_init(&i.i_mutex);
961 ],[
962 AC_MSG_RESULT(yes)
963 AC_DEFINE(HAVE_INODE_I_MUTEX, 1, [struct inode has i_mutex])
964 ],[
965 AC_MSG_RESULT(no)
966 ])
967 ])
968
969 dnl #
970 dnl # 2.6.29 API change,
971 dnl # Adaptive mutexs were introduced which track the mutex owner. The
972 dnl # mutex wrappers leverage this functionality to avoid tracking the
973 dnl # owner multipe times.
974 dnl #
975 AC_DEFUN([SPL_AC_MUTEX_OWNER], [
976 AC_MSG_CHECKING([whether struct mutex has owner])
977 SPL_LINUX_TRY_COMPILE([
978 #include <linux/mutex.h>
979 ],[
980 struct mutex mtx __attribute__ ((unused));
981 mtx.owner = NULL;
982 ],[
983 AC_MSG_RESULT(yes)
984 AC_DEFINE(HAVE_MUTEX_OWNER, 1, [struct mutex has owner])
985 ],[
986 AC_MSG_RESULT(no)
987 ])
988 ])
989
990 dnl #
991 dnl # 2.6.39 API change,
992 dnl # Owner type change. A Linux mutex prior to 2.6.39 would store
993 dnl # the owner as a thread_info pointer when CONFIG_DEBUG_MUTEXES
994 dnl # was defined. As of 2.6.39 this was changed to a task_struct
995 dnl # pointer which frankly makes a lot more sense.
996 dnl #
997 AC_DEFUN([SPL_AC_MUTEX_OWNER_TASK_STRUCT], [
998 AC_MSG_CHECKING([whether struct mutex owner is a task_struct])
999 tmp_flags="$EXTRA_KCFLAGS"
1000 EXTRA_KCFLAGS="-Werror"
1001 SPL_LINUX_TRY_COMPILE([
1002 #include <linux/mutex.h>
1003 #include <linux/sched.h>
1004 ],[
1005 struct mutex mtx __attribute__ ((unused));
1006 mtx.owner = current;
1007 ],[
1008 AC_MSG_RESULT(yes)
1009 AC_DEFINE(HAVE_MUTEX_OWNER_TASK_STRUCT, 1,
1010 [struct mutex owner is a task_struct])
1011 ],[
1012 AC_MSG_RESULT(no)
1013 ])
1014 EXTRA_KCFLAGS="$tmp_flags"
1015 ])
1016
1017 dnl #
1018 dnl # 2.6.18 API change,
1019 dnl # First introduced 'mutex_lock_nested()' in include/linux/mutex.h,
1020 dnl # as part of the mutex validator. Fallback to using 'mutex_lock()'
1021 dnl # if the mutex validator is disabled or otherwise unavailable.
1022 dnl #
1023 AC_DEFUN([SPL_AC_MUTEX_LOCK_NESTED], [
1024 AC_MSG_CHECKING([whether mutex_lock_nested() is available])
1025 SPL_LINUX_TRY_COMPILE([
1026 #include <linux/mutex.h>
1027 ],[
1028 struct mutex mutex;
1029 mutex_init(&mutex);
1030 mutex_lock_nested(&mutex, 0);
1031 ],[
1032 AC_MSG_RESULT(yes)
1033 AC_DEFINE(HAVE_MUTEX_LOCK_NESTED, 1,
1034 [mutex_lock_nested() is available])
1035 ],[
1036 AC_MSG_RESULT(no)
1037 ])
1038 ])
1039
1040 dnl #
1041 dnl # 2.6.27 API change,
1042 dnl # on_each_cpu() uses 3 args, no 'retry' argument
1043 dnl #
1044 AC_DEFUN([SPL_AC_3ARGS_ON_EACH_CPU], [
1045 AC_MSG_CHECKING([whether on_each_cpu() wants 3 args])
1046 SPL_LINUX_TRY_COMPILE([
1047 #include <linux/interrupt.h>
1048 #include <linux/smp.h>
1049
1050 void on_each_cpu_func(void *data) { return; }
1051 ],[
1052 on_each_cpu(on_each_cpu_func, NULL, 0);
1053 ],[
1054 AC_MSG_RESULT(yes)
1055 AC_DEFINE(HAVE_3ARGS_ON_EACH_CPU, 1,
1056 [on_each_cpu wants 3 args])
1057 ],[
1058 AC_MSG_RESULT(no)
1059 ])
1060 ])
1061
1062 dnl #
1063 dnl # 2.6.18 API change,
1064 dnl # kallsyms_lookup_name no longer exported
1065 dnl #
1066 AC_DEFUN([SPL_AC_KALLSYMS_LOOKUP_NAME],
1067 [AC_MSG_CHECKING([whether kallsyms_lookup_name() is available])
1068 SPL_LINUX_TRY_COMPILE_SYMBOL([
1069 #include <linux/kallsyms.h>
1070 ], [
1071 kallsyms_lookup_name(NULL);
1072 ], [kallsyms_lookup_name], [], [
1073 AC_MSG_RESULT(yes)
1074 AC_DEFINE(HAVE_KALLSYMS_LOOKUP_NAME, 1,
1075 [kallsyms_lookup_name() is available])
1076 ], [
1077 AC_MSG_RESULT(no)
1078 ])
1079 ])
1080
1081 dnl #
1082 dnl # Proposed API change,
1083 dnl # This symbol is not available in stock kernels. You may build a
1084 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1085 dnl # these symbols for use. If your already rolling a custom kernel for
1086 dnl # your environment this is recommended.
1087 dnl #
1088 AC_DEFUN([SPL_AC_GET_VMALLOC_INFO],
1089 [AC_MSG_CHECKING([whether get_vmalloc_info() is available])
1090 SPL_CHECK_SYMBOL_EXPORT([get_vmalloc_info], [], [
1091 AC_MSG_RESULT(yes)
1092 AC_DEFINE(HAVE_GET_VMALLOC_INFO, 1,
1093 [get_vmalloc_info() is available])
1094 ], [
1095 AC_MSG_RESULT(no)
1096 ])
1097 ])
1098
1099 dnl #
1100 dnl # 3.10 API change,
1101 dnl # struct vmalloc_info is now declared in linux/vmalloc.h
1102 dnl #
1103 AC_DEFUN([SPL_AC_VMALLOC_INFO], [
1104 AC_MSG_CHECKING([whether struct vmalloc_info is declared])
1105 SPL_LINUX_TRY_COMPILE([
1106 #include <linux/vmalloc.h>
1107 struct vmalloc_info { void *a; };
1108 ],[
1109 return 0;
1110 ],[
1111 AC_MSG_RESULT(no)
1112 ],[
1113 AC_MSG_RESULT(yes)
1114 AC_DEFINE(HAVE_VMALLOC_INFO, 1, [yes])
1115 ])
1116 ])
1117
1118 dnl #
1119 dnl # 3.10 API change,
1120 dnl # PDE is replaced by PDE_DATA
1121 dnl #
1122 AC_DEFUN([SPL_AC_PDE_DATA], [
1123 AC_MSG_CHECKING([whether PDE_DATA() is available])
1124 SPL_LINUX_TRY_COMPILE_SYMBOL([
1125 #include <linux/proc_fs.h>
1126 ], [
1127 PDE_DATA(NULL);
1128 ], [PDE_DATA], [], [
1129 AC_MSG_RESULT(yes)
1130 AC_DEFINE(HAVE_PDE_DATA, 1, [yes])
1131 ],[
1132 AC_MSG_RESULT(no)
1133 ])
1134 ])
1135
1136 dnl #
1137 dnl # 2.6.17 API change
1138 dnl # The helper functions first_online_pgdat(), next_online_pgdat(), and
1139 dnl # next_zone() are introduced to simplify for_each_zone(). These symbols
1140 dnl # were exported in 2.6.17 for use by modules which was consistent with
1141 dnl # the previous implementation of for_each_zone(). From 2.6.18 - 2.6.19
1142 dnl # the symbols were exported as 'unused', and by 2.6.20 they exports
1143 dnl # were dropped entirely leaving modules no way to directly iterate over
1144 dnl # the zone list. Because we need access to the zone helpers we check
1145 dnl # if the kernel contains the old or new implementation. Then we check
1146 dnl # to see if the symbols we need for each version are available. If they
1147 dnl # are not, dynamically aquire the addresses with kallsyms_lookup_name().
1148 dnl #
1149 AC_DEFUN([SPL_AC_PGDAT_HELPERS], [
1150 AC_MSG_CHECKING([whether symbol *_pgdat exist])
1151 grep -q -E 'first_online_pgdat' $LINUX/include/linux/mmzone.h 2>/dev/null
1152 rc=$?
1153 if test $rc -eq 0; then
1154 AC_MSG_RESULT([yes])
1155 AC_DEFINE(HAVE_PGDAT_HELPERS, 1, [pgdat helpers are available])
1156 else
1157 AC_MSG_RESULT([no])
1158 fi
1159 ])
1160
1161 dnl #
1162 dnl # Proposed API change,
1163 dnl # This symbol is not available in stock kernels. You may build a
1164 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1165 dnl # these symbols for use. If your already rolling a custom kernel for
1166 dnl # your environment this is recommended.
1167 dnl #
1168 AC_DEFUN([SPL_AC_FIRST_ONLINE_PGDAT],
1169 [AC_MSG_CHECKING([whether first_online_pgdat() is available])
1170 SPL_LINUX_TRY_COMPILE_SYMBOL([
1171 #include <linux/mmzone.h>
1172 ], [
1173 first_online_pgdat();
1174 ], [first_online_pgdat], [], [
1175 AC_MSG_RESULT(yes)
1176 AC_DEFINE(HAVE_FIRST_ONLINE_PGDAT, 1,
1177 [first_online_pgdat() is available])
1178 ], [
1179 AC_MSG_RESULT(no)
1180 ])
1181 ])
1182
1183 dnl #
1184 dnl # Proposed API change,
1185 dnl # This symbol is not available in stock kernels. You may build a
1186 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1187 dnl # these symbols for use. If your already rolling a custom kernel for
1188 dnl # your environment this is recommended.
1189 dnl #
1190 AC_DEFUN([SPL_AC_NEXT_ONLINE_PGDAT],
1191 [AC_MSG_CHECKING([whether next_online_pgdat() is available])
1192 SPL_LINUX_TRY_COMPILE_SYMBOL([
1193 #include <linux/mmzone.h>
1194 ], [
1195 next_online_pgdat(NULL);
1196 ], [next_online_pgdat], [], [
1197 AC_MSG_RESULT(yes)
1198 AC_DEFINE(HAVE_NEXT_ONLINE_PGDAT, 1,
1199 [next_online_pgdat() is available])
1200 ], [
1201 AC_MSG_RESULT(no)
1202 ])
1203 ])
1204
1205 dnl #
1206 dnl # Proposed API change,
1207 dnl # This symbol is not available in stock kernels. You may build a
1208 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1209 dnl # these symbols for use. If your already rolling a custom kernel for
1210 dnl # your environment this is recommended.
1211 dnl #
1212 AC_DEFUN([SPL_AC_NEXT_ZONE],
1213 [AC_MSG_CHECKING([whether next_zone() is available])
1214 SPL_LINUX_TRY_COMPILE_SYMBOL([
1215 #include <linux/mmzone.h>
1216 ], [
1217 next_zone(NULL);
1218 ], [next_zone], [], [
1219 AC_MSG_RESULT(yes)
1220 AC_DEFINE(HAVE_NEXT_ZONE, 1, [next_zone() is available])
1221 ], [
1222 AC_MSG_RESULT(no)
1223 ])
1224 ])
1225
1226 dnl #
1227 dnl # 2.6.17 API change,
1228 dnl # See SPL_AC_PGDAT_HELPERS for details.
1229 dnl #
1230 AC_DEFUN([SPL_AC_PGDAT_LIST],
1231 [AC_MSG_CHECKING([whether pgdat_list is available])
1232 SPL_LINUX_TRY_COMPILE_SYMBOL([
1233 #include <linux/topology.h>
1234 pg_data_t *tmp = pgdat_list;
1235 ], [], [pgdat_list], [], [
1236 AC_MSG_RESULT(yes)
1237 AC_DEFINE(HAVE_PGDAT_LIST, 1, [pgdat_list is available])
1238 ], [
1239 AC_MSG_RESULT(no)
1240 ])
1241 ])
1242
1243 dnl #
1244 dnl # 2.6.18 API change,
1245 dnl # First introduced global_page_state() support as an inline.
1246 dnl #
1247 AC_DEFUN([SPL_AC_GLOBAL_PAGE_STATE], [
1248 AC_MSG_CHECKING([whether global_page_state() is available])
1249 SPL_LINUX_TRY_COMPILE([
1250 #include <linux/mm.h>
1251 ],[
1252 unsigned long state __attribute__ ((unused));
1253 state = global_page_state(0);
1254 ],[
1255 AC_MSG_RESULT(yes)
1256 AC_DEFINE(HAVE_GLOBAL_PAGE_STATE, 1,
1257 [global_page_state() is available])
1258 ],[
1259 AC_MSG_RESULT(no)
1260 ])
1261 ])
1262
1263 dnl #
1264 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1265 dnl # Public global zone stats now include a free page count. However
1266 dnl # the enumerated names of the counters have changed since this API
1267 dnl # was introduced. We need to deduce the corrent name to use. This
1268 dnl # replaces the priviate get_zone_counts() interface.
1269 dnl #
1270 dnl # NR_FREE_PAGES was available from 2.6.21 to current kernels, which
1271 dnl # is 2.6.30 as of when this was written.
1272 dnl #
1273 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_FREE], [
1274 AC_MSG_CHECKING([whether page state NR_FREE_PAGES is available])
1275 SPL_LINUX_TRY_COMPILE([
1276 #include <linux/mm.h>
1277 ],[
1278 enum zone_stat_item zsi __attribute__ ((unused));
1279 zsi = NR_FREE_PAGES;
1280 ],[
1281 AC_MSG_RESULT(yes)
1282 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES, 1,
1283 [Page state NR_FREE_PAGES is available])
1284 ],[
1285 AC_MSG_RESULT(no)
1286 ])
1287 ])
1288
1289 dnl #
1290 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1291 dnl # Public global zone stats now include an inactive page count. However
1292 dnl # the enumerated names of the counters have changed since this API
1293 dnl # was introduced. We need to deduce the corrent name to use. This
1294 dnl # replaces the priviate get_zone_counts() interface.
1295 dnl #
1296 dnl # NR_INACTIVE was available from 2.6.21 to 2.6.27 and included both
1297 dnl # anonymous and file inactive pages. As of 2.6.28 it was split in
1298 dnl # to NR_INACTIVE_ANON and NR_INACTIVE_FILE.
1299 dnl #
1300 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_INACTIVE], [
1301 AC_MSG_CHECKING([whether page state NR_INACTIVE is available])
1302 SPL_LINUX_TRY_COMPILE([
1303 #include <linux/mm.h>
1304 ],[
1305 enum zone_stat_item zsi __attribute__ ((unused));
1306 zsi = NR_INACTIVE;
1307 ],[
1308 AC_MSG_RESULT(yes)
1309 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE, 1,
1310 [Page state NR_INACTIVE is available])
1311 ],[
1312 AC_MSG_RESULT(no)
1313 ])
1314
1315 AC_MSG_CHECKING([whether page state NR_INACTIVE_ANON is available])
1316 SPL_LINUX_TRY_COMPILE([
1317 #include <linux/mm.h>
1318 ],[
1319 enum zone_stat_item zsi __attribute__ ((unused));
1320 zsi = NR_INACTIVE_ANON;
1321 ],[
1322 AC_MSG_RESULT(yes)
1323 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON, 1,
1324 [Page state NR_INACTIVE_ANON is available])
1325 ],[
1326 AC_MSG_RESULT(no)
1327 ])
1328
1329 AC_MSG_CHECKING([whether page state NR_INACTIVE_FILE is available])
1330 SPL_LINUX_TRY_COMPILE([
1331 #include <linux/mm.h>
1332 ],[
1333 enum zone_stat_item zsi __attribute__ ((unused));
1334 zsi = NR_INACTIVE_FILE;
1335 ],[
1336 AC_MSG_RESULT(yes)
1337 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE, 1,
1338 [Page state NR_INACTIVE_FILE is available])
1339 ],[
1340 AC_MSG_RESULT(no)
1341 ])
1342 ])
1343
1344 dnl #
1345 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1346 dnl # Public global zone stats now include an active page count. However
1347 dnl # the enumerated names of the counters have changed since this API
1348 dnl # was introduced. We need to deduce the corrent name to use. This
1349 dnl # replaces the priviate get_zone_counts() interface.
1350 dnl #
1351 dnl # NR_ACTIVE was available from 2.6.21 to 2.6.27 and included both
1352 dnl # anonymous and file active pages. As of 2.6.28 it was split in
1353 dnl # to NR_ACTIVE_ANON and NR_ACTIVE_FILE.
1354 dnl #
1355 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_ACTIVE], [
1356 AC_MSG_CHECKING([whether page state NR_ACTIVE is available])
1357 SPL_LINUX_TRY_COMPILE([
1358 #include <linux/mm.h>
1359 ],[
1360 enum zone_stat_item zsi __attribute__ ((unused));
1361 zsi = NR_ACTIVE;
1362 ],[
1363 AC_MSG_RESULT(yes)
1364 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE, 1,
1365 [Page state NR_ACTIVE is available])
1366 ],[
1367 AC_MSG_RESULT(no)
1368 ])
1369
1370 AC_MSG_CHECKING([whether page state NR_ACTIVE_ANON is available])
1371 SPL_LINUX_TRY_COMPILE([
1372 #include <linux/mm.h>
1373 ],[
1374 enum zone_stat_item zsi __attribute__ ((unused));
1375 zsi = NR_ACTIVE_ANON;
1376 ],[
1377 AC_MSG_RESULT(yes)
1378 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON, 1,
1379 [Page state NR_ACTIVE_ANON is available])
1380 ],[
1381 AC_MSG_RESULT(no)
1382 ])
1383
1384 AC_MSG_CHECKING([whether page state NR_ACTIVE_FILE is available])
1385 SPL_LINUX_TRY_COMPILE([
1386 #include <linux/mm.h>
1387 ],[
1388 enum zone_stat_item zsi __attribute__ ((unused));
1389 zsi = NR_ACTIVE_FILE;
1390 ],[
1391 AC_MSG_RESULT(yes)
1392 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE, 1,
1393 [Page state NR_ACTIVE_FILE is available])
1394 ],[
1395 AC_MSG_RESULT(no)
1396 ])
1397 ])
1398
1399 dnl #
1400 dnl # Proposed API change for legacy kernels.
1401 dnl # This symbol is not available in older kernels. For kernels post
1402 dnl # 2.6.21 the global_page_state() API is used to get free/inactive/active
1403 dnl # page state information. This symbol is only used in legacy kernels
1404 dnl # any only as a last resort.
1405 dnl
1406 AC_DEFUN([SPL_AC_GET_ZONE_COUNTS], [
1407 AC_MSG_CHECKING([whether symbol get_zone_counts is needed])
1408 SPL_LINUX_TRY_COMPILE([
1409 ],[
1410 #if !defined(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES)
1411 #error "global_page_state needs NR_FREE_PAGES"
1412 #endif
1413
1414 #if !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE) && \
1415 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON) && \
1416 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE)
1417 #error "global_page_state needs NR_ACTIVE*"
1418 #endif
1419
1420 #if !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE) && \
1421 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON) && \
1422 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE)
1423 #error "global_page_state needs NR_INACTIVE*"
1424 #endif
1425 ],[
1426 AC_MSG_RESULT(no)
1427 ],[
1428 AC_MSG_RESULT(yes)
1429 AC_DEFINE(NEED_GET_ZONE_COUNTS, 1,
1430 [get_zone_counts() is needed])
1431
1432 AC_MSG_CHECKING([whether get_zone_counts() is available])
1433 SPL_LINUX_TRY_COMPILE_SYMBOL([
1434 #include <linux/mmzone.h>
1435 ], [
1436 get_zone_counts(NULL, NULL, NULL);
1437 ], [get_zone_counts], [], [
1438 AC_MSG_RESULT(yes)
1439 AC_DEFINE(HAVE_GET_ZONE_COUNTS, 1,
1440 [get_zone_counts() is available])
1441 ], [
1442 AC_MSG_RESULT(no)
1443 ])
1444 ])
1445 ])
1446
1447 dnl #
1448 dnl # 2.6.27 API change,
1449 dnl # The user_path_dir() replaces __user_walk()
1450 dnl #
1451 AC_DEFUN([SPL_AC_USER_PATH_DIR],
1452 [AC_MSG_CHECKING([whether user_path_dir() is available])
1453 SPL_LINUX_TRY_COMPILE_SYMBOL([
1454 #include <linux/fcntl.h>
1455 #include <linux/namei.h>
1456 ], [
1457 user_path_dir(NULL, NULL);
1458 ], [user_path_at], [], [
1459 AC_MSG_RESULT(yes)
1460 AC_DEFINE(HAVE_USER_PATH_DIR, 1, [user_path_dir() is available])
1461 ], [
1462 AC_MSG_RESULT(no)
1463 ])
1464 ])
1465
1466 dnl #
1467 dnl # Symbol available in RHEL kernels not in stock kernels.
1468 dnl #
1469 AC_DEFUN([SPL_AC_SET_FS_PWD],
1470 [AC_MSG_CHECKING([whether set_fs_pwd() is available])
1471 SPL_LINUX_TRY_COMPILE_SYMBOL([
1472 #include <linux/spinlock.h>
1473 #include <linux/fs_struct.h>
1474 ], [
1475 (void) set_fs_pwd;
1476 ], [set_fs_pwd], [], [
1477 AC_MSG_RESULT(yes)
1478 AC_DEFINE(HAVE_SET_FS_PWD, 1, [set_fs_pwd() is available])
1479 ], [
1480 AC_MSG_RESULT(no)
1481 ])
1482 ])
1483
1484 dnl #
1485 dnl # 3.9 API change
1486 dnl # set_fs_pwd takes const struct path *
1487 dnl #
1488 AC_DEFUN([SPL_AC_SET_FS_PWD_WITH_CONST],
1489 tmp_flags="$EXTRA_KCFLAGS"
1490 EXTRA_KCFLAGS="-Werror"
1491 [AC_MSG_CHECKING([whether set_fs_pwd() requires const struct path *])
1492 SPL_LINUX_TRY_COMPILE([
1493 #include <linux/spinlock.h>
1494 #include <linux/fs_struct.h>
1495 #include <linux/path.h>
1496 void (*const set_fs_pwd_func)
1497 (struct fs_struct *, const struct path *)
1498 = set_fs_pwd;
1499 ],[
1500 return 0;
1501 ],[
1502 AC_MSG_RESULT(yes)
1503 AC_DEFINE(HAVE_SET_FS_PWD_WITH_CONST, 1,
1504 [set_fs_pwd() needs const path *])
1505 ],[
1506 SPL_LINUX_TRY_COMPILE([
1507 #include <linux/spinlock.h>
1508 #include <linux/fs_struct.h>
1509 #include <linux/path.h>
1510 void (*const set_fs_pwd_func)
1511 (struct fs_struct *, struct path *)
1512 = set_fs_pwd;
1513 ],[
1514 return 0;
1515 ],[
1516 AC_MSG_RESULT(no)
1517 ],[
1518 AC_MSG_ERROR(unknown)
1519 ])
1520 ])
1521 EXTRA_KCFLAGS="$tmp_flags"
1522 ])
1523
1524 AC_DEFUN([SPL_AC_2ARGS_VFS_UNLINK],
1525 [AC_MSG_CHECKING([whether vfs_unlink() wants 2 args])
1526 SPL_LINUX_TRY_COMPILE([
1527 #include <linux/fs.h>
1528 ],[
1529 vfs_unlink((struct inode *) NULL, (struct dentry *) NULL);
1530 ],[
1531 AC_MSG_RESULT(yes)
1532 AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
1533 [vfs_unlink() wants 2 args])
1534 ],[
1535 AC_MSG_RESULT(no)
1536 dnl #
1537 dnl # Linux 3.13 API change
1538 dnl # Added delegated inode
1539 dnl #
1540 AC_MSG_CHECKING([whether vfs_unlink() wants 3 args])
1541 SPL_LINUX_TRY_COMPILE([
1542 #include <linux/fs.h>
1543 ],[
1544 vfs_unlink((struct inode *) NULL,
1545 (struct dentry *) NULL,
1546 (struct inode **) NULL);
1547 ],[
1548 AC_MSG_RESULT(yes)
1549 AC_DEFINE(HAVE_3ARGS_VFS_UNLINK, 1,
1550 [vfs_unlink() wants 3 args])
1551 ],[
1552 AC_MSG_ERROR(no)
1553 ])
1554
1555 ])
1556 ])
1557
1558 AC_DEFUN([SPL_AC_4ARGS_VFS_RENAME],
1559 [AC_MSG_CHECKING([whether vfs_rename() wants 4 args])
1560 SPL_LINUX_TRY_COMPILE([
1561 #include <linux/fs.h>
1562 ],[
1563 vfs_rename((struct inode *) NULL, (struct dentry *) NULL,
1564 (struct inode *) NULL, (struct dentry *) NULL);
1565 ],[
1566 AC_MSG_RESULT(yes)
1567 AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
1568 [vfs_rename() wants 4 args])
1569 ],[
1570 AC_MSG_RESULT(no)
1571 dnl #
1572 dnl # Linux 3.13 API change
1573 dnl # Added delegated inode
1574 dnl #
1575 AC_MSG_CHECKING([whether vfs_rename() wants 5 args])
1576 SPL_LINUX_TRY_COMPILE([
1577 #include <linux/fs.h>
1578 ],[
1579 vfs_rename((struct inode *) NULL,
1580 (struct dentry *) NULL,
1581 (struct inode *) NULL,
1582 (struct dentry *) NULL,
1583 (struct inode **) NULL);
1584 ],[
1585 AC_MSG_RESULT(yes)
1586 AC_DEFINE(HAVE_5ARGS_VFS_RENAME, 1,
1587 [vfs_rename() wants 5 args])
1588 ],[
1589 AC_MSG_RESULT(no)
1590 dnl #
1591 dnl # Linux 3.15 API change
1592 dnl # Added flags
1593 dnl #
1594 AC_MSG_CHECKING([whether vfs_rename() wants 6 args])
1595 SPL_LINUX_TRY_COMPILE([
1596 #include <linux/fs.h>
1597 ],[
1598 vfs_rename((struct inode *) NULL,
1599 (struct dentry *) NULL,
1600 (struct inode *) NULL,
1601 (struct dentry *) NULL,
1602 (struct inode **) NULL,
1603 (unsigned int) 0);
1604 ],[
1605 AC_MSG_RESULT(yes)
1606 AC_DEFINE(HAVE_6ARGS_VFS_RENAME, 1,
1607 [vfs_rename() wants 6 args])
1608 ],[
1609 AC_MSG_ERROR(no)
1610 ])
1611 ])
1612 ])
1613 ])
1614
1615 dnl #
1616 dnl # 2.6.36 API change,
1617 dnl # The 'struct fs_struct->lock' was changed from a rwlock_t to
1618 dnl # a spinlock_t to improve the fastpath performance.
1619 dnl #
1620 AC_DEFUN([SPL_AC_FS_STRUCT_SPINLOCK], [
1621 AC_MSG_CHECKING([whether struct fs_struct uses spinlock_t])
1622 tmp_flags="$EXTRA_KCFLAGS"
1623 EXTRA_KCFLAGS="-Werror"
1624 SPL_LINUX_TRY_COMPILE([
1625 #include <linux/sched.h>
1626 #include <linux/fs_struct.h>
1627 ],[
1628 struct fs_struct fs;
1629 spin_lock_init(&fs.lock);
1630 ],[
1631 AC_MSG_RESULT(yes)
1632 AC_DEFINE(HAVE_FS_STRUCT_SPINLOCK, 1,
1633 [struct fs_struct uses spinlock_t])
1634 ],[
1635 AC_MSG_RESULT(no)
1636 ])
1637 EXTRA_KCFLAGS="$tmp_flags"
1638 ])
1639
1640 dnl #
1641 dnl # 2.6.29 API change,
1642 dnl # check whether 'struct cred' exists
1643 dnl #
1644 AC_DEFUN([SPL_AC_CRED_STRUCT], [
1645 AC_MSG_CHECKING([whether struct cred exists])
1646 SPL_LINUX_TRY_COMPILE([
1647 #include <linux/cred.h>
1648 ],[
1649 struct cred *cr __attribute__ ((unused));
1650 cr = NULL;
1651 ],[
1652 AC_MSG_RESULT(yes)
1653 AC_DEFINE(HAVE_CRED_STRUCT, 1, [struct cred exists])
1654 ],[
1655 AC_MSG_RESULT(no)
1656 ])
1657 ])
1658
1659
1660 dnl #
1661 dnl # User namespaces, use kuid_t in place of uid_t
1662 dnl # where available. Not strictly a user namespaces thing
1663 dnl # but it should prevent surprises
1664 dnl #
1665 AC_DEFUN([SPL_AC_KUIDGID_T], [
1666 AC_MSG_CHECKING([whether kuid_t/kgid_t is available])
1667 SPL_LINUX_TRY_COMPILE([
1668 #include <linux/uidgid.h>
1669 ], [
1670 kuid_t userid = KUIDT_INIT(0);
1671 kgid_t groupid = KGIDT_INIT(0);
1672 ],[
1673 SPL_LINUX_TRY_COMPILE([
1674 #include <linux/uidgid.h>
1675 ], [
1676 kuid_t userid = 0;
1677 kgid_t groupid = 0;
1678 ],[
1679 AC_MSG_RESULT(yes; optional)
1680 ],[
1681 AC_MSG_RESULT(yes; mandatory)
1682 AC_DEFINE(HAVE_KUIDGID_T, 1, [kuid_t/kgid_t in use])
1683 ])
1684 ],[
1685 AC_MSG_RESULT(no)
1686 ])
1687 ])
1688
1689 dnl #
1690 dnl # Custom SPL patch may export this symbol.
1691 dnl #
1692 AC_DEFUN([SPL_AC_GROUPS_SEARCH],
1693 [AC_MSG_CHECKING([whether groups_search() is available])
1694 SPL_LINUX_TRY_COMPILE_SYMBOL([
1695 #include <linux/cred.h>
1696 #ifdef HAVE_KUIDGID_T
1697 #include <linux/uidgid.h>
1698 #endif
1699 ], [
1700 #ifdef HAVE_KUIDGID_T
1701 groups_search(NULL, KGIDT_INIT(0));
1702 #else
1703 groups_search(NULL, 0);
1704 #endif
1705 ], [groups_search], [], [
1706 AC_MSG_RESULT(yes)
1707 AC_DEFINE(HAVE_GROUPS_SEARCH, 1, [groups_search() is available])
1708 ], [
1709 AC_MSG_RESULT(no)
1710 ])
1711 ])
1712
1713 dnl #
1714 dnl # 2.6.x API change,
1715 dnl # __put_task_struct() was exported in RHEL5 but unavailable elsewhere.
1716 dnl #
1717 AC_DEFUN([SPL_AC_PUT_TASK_STRUCT],
1718 [AC_MSG_CHECKING([whether __put_task_struct() is available])
1719 SPL_LINUX_TRY_COMPILE_SYMBOL([
1720 #include <linux/sched.h>
1721 ], [
1722 __put_task_struct(NULL);
1723 ], [__put_task_struct], [], [
1724 AC_MSG_RESULT(yes)
1725 AC_DEFINE(HAVE_PUT_TASK_STRUCT, 1,
1726 [__put_task_struct() is available])
1727 ], [
1728 AC_MSG_RESULT(no)
1729 ])
1730 ])
1731
1732 dnl #
1733 dnl # 2.6.32 API change,
1734 dnl # Unused 'struct file *' removed from prototype.
1735 dnl #
1736 AC_DEFUN([SPL_AC_5ARGS_PROC_HANDLER], [
1737 AC_MSG_CHECKING([whether proc_handler() wants 5 args])
1738 SPL_LINUX_TRY_COMPILE([
1739 #include <linux/sysctl.h>
1740 ],[
1741 proc_dostring(NULL, 0, NULL, NULL, NULL);
1742 ],[
1743 AC_MSG_RESULT(yes)
1744 AC_DEFINE(HAVE_5ARGS_PROC_HANDLER, 1,
1745 [proc_handler() wants 5 args])
1746 ],[
1747 AC_MSG_RESULT(no)
1748 ])
1749 ])
1750
1751 dnl #
1752 dnl # 2.6.x API change,
1753 dnl # kvasprintf() function added.
1754 dnl #
1755 AC_DEFUN([SPL_AC_KVASPRINTF],
1756 [AC_MSG_CHECKING([whether kvasprintf() is available])
1757 SPL_LINUX_TRY_COMPILE_SYMBOL([
1758 #include <linux/kernel.h>
1759 ], [
1760 kvasprintf(0, NULL, *((va_list*)NULL));
1761 ], [kvasprintf], [], [
1762 AC_MSG_RESULT(yes)
1763 AC_DEFINE(HAVE_KVASPRINTF, 1, [kvasprintf() is available])
1764 ], [
1765 AC_MSG_RESULT(no)
1766 ])
1767 ])
1768
1769 dnl #
1770 dnl # 2.6.29 API change,
1771 dnl # vfs_fsync() funcation added, prior to this use file_fsync().
1772 dnl #
1773 AC_DEFUN([SPL_AC_VFS_FSYNC],
1774 [AC_MSG_CHECKING([whether vfs_fsync() is available])
1775 SPL_LINUX_TRY_COMPILE_SYMBOL([
1776 #include <linux/fs.h>
1777 ], [
1778 (void) vfs_fsync;
1779 ], [vfs_fsync], [fs/sync.c], [
1780 AC_MSG_RESULT(yes)
1781 AC_DEFINE(HAVE_VFS_FSYNC, 1, [vfs_fsync() is available])
1782 ], [
1783 AC_MSG_RESULT(no)
1784 ])
1785 ])
1786
1787 dnl #
1788 dnl # 2.6.35 API change,
1789 dnl # Unused 'struct dentry *' removed from vfs_fsync() prototype.
1790 dnl #
1791 AC_DEFUN([SPL_AC_2ARGS_VFS_FSYNC], [
1792 AC_MSG_CHECKING([whether vfs_fsync() wants 2 args])
1793 SPL_LINUX_TRY_COMPILE([
1794 #include <linux/fs.h>
1795 ],[
1796 vfs_fsync(NULL, 0);
1797 ],[
1798 AC_MSG_RESULT(yes)
1799 AC_DEFINE(HAVE_2ARGS_VFS_FSYNC, 1, [vfs_fsync() wants 2 args])
1800 ],[
1801 AC_MSG_RESULT(no)
1802 ])
1803 ])
1804
1805 dnl #
1806 dnl # 3.5 API change,
1807 dnl # inode_operations.truncate_range removed
1808 dnl #
1809 AC_DEFUN([SPL_AC_INODE_TRUNCATE_RANGE], [
1810 AC_MSG_CHECKING([whether truncate_range() inode operation is available])
1811 SPL_LINUX_TRY_COMPILE([
1812 #include <linux/fs.h>
1813 ],[
1814 struct inode_operations ops;
1815 ops.truncate_range = NULL;
1816 ],[
1817 AC_MSG_RESULT(yes)
1818 AC_DEFINE(HAVE_INODE_TRUNCATE_RANGE, 1,
1819 [truncate_range() inode operation is available])
1820 ],[
1821 AC_MSG_RESULT(no)
1822 ])
1823 ])
1824
1825 dnl #
1826 dnl # Linux 2.6.38 - 3.x API
1827 dnl #
1828 AC_DEFUN([SPL_AC_KERNEL_FILE_FALLOCATE], [
1829 AC_MSG_CHECKING([whether fops->fallocate() exists])
1830 SPL_LINUX_TRY_COMPILE([
1831 #include <linux/fs.h>
1832 ],[
1833 long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
1834 struct file_operations fops __attribute__ ((unused)) = {
1835 .fallocate = fallocate,
1836 };
1837 ],[
1838 AC_MSG_RESULT(yes)
1839 AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
1840 ],[
1841 AC_MSG_RESULT(no)
1842 ])
1843 ])
1844
1845 dnl #
1846 dnl # Linux 2.6.x - 2.6.37 API
1847 dnl #
1848 AC_DEFUN([SPL_AC_KERNEL_INODE_FALLOCATE], [
1849 AC_MSG_CHECKING([whether iops->fallocate() exists])
1850 SPL_LINUX_TRY_COMPILE([
1851 #include <linux/fs.h>
1852 ],[
1853 long (*fallocate) (struct inode *, int, loff_t, loff_t) = NULL;
1854 struct inode_operations fops __attribute__ ((unused)) = {
1855 .fallocate = fallocate,
1856 };
1857 ],[
1858 AC_MSG_RESULT(yes)
1859 AC_DEFINE(HAVE_INODE_FALLOCATE, 1, [fops->fallocate() exists])
1860 ],[
1861 AC_MSG_RESULT(no)
1862 ])
1863 ])
1864
1865 dnl #
1866 dnl # PaX Linux 2.6.38 - 3.x API
1867 dnl #
1868 AC_DEFUN([SPL_AC_PAX_KERNEL_FILE_FALLOCATE], [
1869 AC_MSG_CHECKING([whether fops->fallocate() exists])
1870 SPL_LINUX_TRY_COMPILE([
1871 #include <linux/fs.h>
1872 ],[
1873 long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
1874 struct file_operations_no_const fops __attribute__ ((unused)) = {
1875 .fallocate = fallocate,
1876 };
1877 ],[
1878 AC_MSG_RESULT(yes)
1879 AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
1880 ],[
1881 AC_MSG_RESULT(no)
1882 ])
1883 ])
1884
1885 dnl #
1886 dnl # The fallocate callback was moved from the inode_operations
1887 dnl # structure to the file_operations structure.
1888 dnl #
1889 AC_DEFUN([SPL_AC_KERNEL_FALLOCATE], [
1890 SPL_AC_KERNEL_FILE_FALLOCATE
1891 SPL_AC_KERNEL_INODE_FALLOCATE
1892 SPL_AC_PAX_KERNEL_FILE_FALLOCATE
1893 ])
1894
1895 dnl #
1896 dnl # 2.6.33 API change. Also backported in RHEL5 as of 2.6.18-190.el5.
1897 dnl # Earlier versions of rwsem_is_locked() were inline and had a race
1898 dnl # condition. The fixed version is exported as a symbol. The race
1899 dnl # condition is fixed by acquiring sem->wait_lock, so we must not
1900 dnl # call that version while holding sem->wait_lock.
1901 dnl #
1902 AC_DEFUN([SPL_AC_EXPORTED_RWSEM_IS_LOCKED],
1903 [AC_MSG_CHECKING([whether rwsem_is_locked() acquires sem->wait_lock])
1904 SPL_LINUX_TRY_COMPILE_SYMBOL([
1905 #include <linux/rwsem.h>
1906 int rwsem_is_locked(struct rw_semaphore *sem) { return 0; }
1907 ], [], [rwsem_is_locked], [lib/rwsem-spinlock.c], [
1908 AC_MSG_RESULT(yes)
1909 AC_DEFINE(RWSEM_IS_LOCKED_TAKES_WAIT_LOCK, 1,
1910 [rwsem_is_locked() acquires sem->wait_lock])
1911 ], [
1912 AC_MSG_RESULT(no)
1913 ])
1914 ])
1915
1916 dnl #
1917 dnl # 2.6.xx API compat,
1918 dnl # There currently exists no exposed API to partially shrink the dcache.
1919 dnl # The expected mechanism to shrink the cache is a registered shrinker
1920 dnl # which is called during memory pressure.
1921 dnl #
1922 AC_DEFUN([SPL_AC_SHRINK_DCACHE_MEMORY],
1923 [AC_MSG_CHECKING([whether shrink_dcache_memory() is available])
1924 SPL_LINUX_TRY_COMPILE_SYMBOL([
1925 #include <linux/dcache.h>
1926 ], [
1927 shrink_dcache_memory(0, 0);
1928 ], [shrink_dcache_memory], [fs/dcache.c], [
1929 AC_MSG_RESULT(yes)
1930 AC_DEFINE(HAVE_SHRINK_DCACHE_MEMORY, 1,
1931 [shrink_dcache_memory() is available])
1932 ], [
1933 AC_MSG_RESULT(no)
1934 ])
1935 ])
1936
1937 dnl #
1938 dnl # 2.6.xx API compat,
1939 dnl # There currently exists no exposed API to partially shrink the icache.
1940 dnl # The expected mechanism to shrink the cache is a registered shrinker
1941 dnl # which is called during memory pressure.
1942 dnl #
1943 AC_DEFUN([SPL_AC_SHRINK_ICACHE_MEMORY],
1944 [AC_MSG_CHECKING([whether shrink_icache_memory() is available])
1945 SPL_LINUX_TRY_COMPILE_SYMBOL([
1946 #include <linux/dcache.h>
1947 ], [
1948 shrink_icache_memory(0, 0);
1949 ], [shrink_icache_memory], [fs/inode.c], [
1950 AC_MSG_RESULT(yes)
1951 AC_DEFINE(HAVE_SHRINK_ICACHE_MEMORY, 1,
1952 [shrink_icache_memory() is available])
1953 ], [
1954 AC_MSG_RESULT(no)
1955 ])
1956 ])
1957
1958 dnl #
1959 dnl # 2.6.28 API change
1960 dnl # The kern_path() function has been introduced. We adopt it as the new way
1961 dnl # of looking up paths. When it is not available, we emulate it using the
1962 dnl # older interfaces.
1963 dnl #
1964 AC_DEFUN([SPL_AC_KERN_PATH],
1965 [AC_MSG_CHECKING([whether kern_path() is available])
1966 SPL_LINUX_TRY_COMPILE_SYMBOL([
1967 #include <linux/namei.h>
1968 ], [
1969 int r = kern_path(NULL, 0, NULL);
1970 ], [kern_path], [fs/namei.c], [
1971 AC_MSG_RESULT(yes)
1972 AC_DEFINE(HAVE_KERN_PATH, 1,
1973 [kern_path() is available])
1974 ], [
1975 AC_MSG_RESULT(no)
1976 AC_MSG_CHECKING([whether path_lookup() is available])
1977 SPL_LINUX_TRY_COMPILE_SYMBOL([
1978 #include <linux/namei.h>
1979 ], [
1980 int r = path_lookup(NULL, 0, NULL);
1981 ], [path_lookup], [fs/namei.c], [
1982 AC_MSG_RESULT(yes)
1983 AC_DEFINE(HAVE_KERN_PATH, 1,
1984 [kern_path() is available])
1985 ], [
1986 AC_MSG_RESULT(no)
1987 AC_MSG_ERROR([
1988 *** Neither kern_path() nor path_lookup() is available.
1989 *** Please file an issue:
1990 *** https://github.com/zfsonlinux/spl/issues/new])
1991
1992 ])
1993 ])
1994 ])
1995
1996 dnl #
1997 dnl # /proc/kallsyms support,
1998 dnl # Verify the kernel has CONFIG_KALLSYMS support enabled.
1999 dnl #
2000 AC_DEFUN([SPL_AC_CONFIG_KALLSYMS], [
2001 AC_MSG_CHECKING([whether CONFIG_KALLSYMS is defined])
2002 SPL_LINUX_TRY_COMPILE([
2003 #if !defined(CONFIG_KALLSYMS)
2004 #error CONFIG_KALLSYMS not defined
2005 #endif
2006 ],[ ],[
2007 AC_MSG_RESULT([yes])
2008 ],[
2009 AC_MSG_RESULT([no])
2010 AC_MSG_ERROR([
2011 *** This kernel does not include the required kallsyms support.
2012 *** Rebuild the kernel with CONFIG_KALLSYMS=y set.])
2013 ])
2014 ])
2015
2016 dnl #
2017 dnl # zlib inflate compat,
2018 dnl # Verify the kernel has CONFIG_ZLIB_INFLATE support enabled.
2019 dnl #
2020 AC_DEFUN([SPL_AC_CONFIG_ZLIB_INFLATE], [
2021 AC_MSG_CHECKING([whether CONFIG_ZLIB_INFLATE is defined])
2022 SPL_LINUX_TRY_COMPILE([
2023 #if !defined(CONFIG_ZLIB_INFLATE) && \
2024 !defined(CONFIG_ZLIB_INFLATE_MODULE)
2025 #error CONFIG_ZLIB_INFLATE not defined
2026 #endif
2027 ],[ ],[
2028 AC_MSG_RESULT([yes])
2029 ],[
2030 AC_MSG_RESULT([no])
2031 AC_MSG_ERROR([
2032 *** This kernel does not include the required zlib inflate support.
2033 *** Rebuild the kernel with CONFIG_ZLIB_INFLATE=y|m set.])
2034 ])
2035 ])
2036
2037 dnl #
2038 dnl # zlib deflate compat,
2039 dnl # Verify the kernel has CONFIG_ZLIB_DEFLATE support enabled.
2040 dnl #
2041 AC_DEFUN([SPL_AC_CONFIG_ZLIB_DEFLATE], [
2042 AC_MSG_CHECKING([whether CONFIG_ZLIB_DEFLATE is defined])
2043 SPL_LINUX_TRY_COMPILE([
2044 #if !defined(CONFIG_ZLIB_DEFLATE) && \
2045 !defined(CONFIG_ZLIB_DEFLATE_MODULE)
2046 #error CONFIG_ZLIB_DEFLATE not defined
2047 #endif
2048 ],[ ],[
2049 AC_MSG_RESULT([yes])
2050 ],[
2051 AC_MSG_RESULT([no])
2052 AC_MSG_ERROR([
2053 *** This kernel does not include the required zlib deflate support.
2054 *** Rebuild the kernel with CONFIG_ZLIB_DEFLATE=y|m set.])
2055 ])
2056 ])
2057
2058 dnl #
2059 dnl # 2.6.39 API compat,
2060 dnl # The function zlib_deflate_workspacesize() now take 2 arguments.
2061 dnl # This was done to avoid always having to allocate the maximum size
2062 dnl # workspace (268K). The caller can now specific the windowBits and
2063 dnl # memLevel compression parameters to get a smaller workspace.
2064 dnl #
2065 AC_DEFUN([SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE],
2066 [AC_MSG_CHECKING([whether zlib_deflate_workspacesize() wants 2 args])
2067 SPL_LINUX_TRY_COMPILE([
2068 #include <linux/zlib.h>
2069 ],[
2070 return zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL);
2071 ],[
2072 AC_MSG_RESULT(yes)
2073 AC_DEFINE(HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE, 1,
2074 [zlib_deflate_workspacesize() wants 2 args])
2075 ],[
2076 AC_MSG_RESULT(no)
2077 ])
2078 ])
2079
2080 dnl #
2081 dnl # 2.6.39 API change,
2082 dnl # Shrinker adjust to use common shrink_control structure.
2083 dnl #
2084 AC_DEFUN([SPL_AC_SHRINK_CONTROL_STRUCT], [
2085 AC_MSG_CHECKING([whether struct shrink_control exists])
2086 SPL_LINUX_TRY_COMPILE([
2087 #include <linux/mm.h>
2088 ],[
2089 struct shrink_control sc __attribute__ ((unused));
2090
2091 sc.nr_to_scan = 0;
2092 sc.gfp_mask = GFP_KERNEL;
2093 ],[
2094 AC_MSG_RESULT(yes)
2095 AC_DEFINE(HAVE_SHRINK_CONTROL_STRUCT, 1,
2096 [struct shrink_control exists])
2097 ],[
2098 AC_MSG_RESULT(no)
2099 ])
2100 ])
2101
2102 dnl #
2103 dnl # 3.1 API Change
2104 dnl #
2105 dnl # The rw_semaphore.wait_lock member was changed from spinlock_t to
2106 dnl # raw_spinlock_t at commit ddb6c9b58a19edcfac93ac670b066c836ff729f1.
2107 dnl #
2108 AC_DEFUN([SPL_AC_RWSEM_SPINLOCK_IS_RAW], [
2109 AC_MSG_CHECKING([whether struct rw_semaphore member wait_lock is raw])
2110 tmp_flags="$EXTRA_KCFLAGS"
2111 EXTRA_KCFLAGS="-Werror"
2112 SPL_LINUX_TRY_COMPILE([
2113 #include <linux/rwsem.h>
2114 ],[
2115 struct rw_semaphore dummy_semaphore __attribute__ ((unused));
2116 raw_spinlock_t dummy_lock __attribute__ ((unused));
2117 dummy_semaphore.wait_lock = dummy_lock;
2118 ],[
2119 AC_MSG_RESULT(yes)
2120 AC_DEFINE(RWSEM_SPINLOCK_IS_RAW, 1,
2121 [struct rw_semaphore member wait_lock is raw_spinlock_t])
2122 ],[
2123 AC_MSG_RESULT(no)
2124 ])
2125 EXTRA_KCFLAGS="$tmp_flags"
2126 ])
2127
2128 dnl #
2129 dnl # 3.9 API change,
2130 dnl # Moved things from linux/sched.h to linux/sched/rt.h
2131 dnl #
2132 AC_DEFUN([SPL_AC_SCHED_RT_HEADER],
2133 [AC_MSG_CHECKING([whether header linux/sched/rt.h exists])
2134 SPL_LINUX_TRY_COMPILE([
2135 #include <linux/sched.h>
2136 #include <linux/sched/rt.h>
2137 ],[
2138 return 0;
2139 ],[
2140 AC_DEFINE(HAVE_SCHED_RT_HEADER, 1, [linux/sched/rt.h exists])
2141 AC_MSG_RESULT(yes)
2142 ],[
2143 AC_MSG_RESULT(no)
2144 ])
2145 ])
2146
2147 dnl #
2148 dnl # 3.9 API change,
2149 dnl # vfs_getattr() uses 2 args
2150 dnl # It takes struct path * instead of struct vfsmount * and struct dentry *
2151 dnl #
2152 AC_DEFUN([SPL_AC_2ARGS_VFS_GETATTR], [
2153 AC_MSG_CHECKING([whether vfs_getattr() wants])
2154 SPL_LINUX_TRY_COMPILE([
2155 #include <linux/fs.h>
2156 ],[
2157 vfs_getattr((struct path *) NULL,
2158 (struct kstat *)NULL);
2159 ],[
2160 AC_MSG_RESULT(2 args)
2161 AC_DEFINE(HAVE_2ARGS_VFS_GETATTR, 1,
2162 [vfs_getattr wants 2 args])
2163 ],[
2164 SPL_LINUX_TRY_COMPILE([
2165 #include <linux/fs.h>
2166 ],[
2167 vfs_getattr((struct vfsmount *)NULL,
2168 (struct dentry *)NULL,
2169 (struct kstat *)NULL);
2170 ],[
2171 AC_MSG_RESULT(3 args)
2172 ],[
2173 AC_MSG_ERROR(unknown)
2174 ])
2175 ])
2176 ])
2177
2178 dnl #
2179 dnl # 2.6.36 API compatibility.
2180 dnl # Added usleep_range timer.
2181 dnl # usleep_range is a finer precision implementation of msleep
2182 dnl # designed to be a drop-in replacement for udelay where a precise
2183 dnl # sleep / busy-wait is unnecessary.
2184 dnl #
2185 AC_DEFUN([SPL_AC_USLEEP_RANGE], [
2186 AC_MSG_CHECKING([whether usleep_range() is available])
2187 SPL_LINUX_TRY_COMPILE([
2188 #include <linux/delay.h>
2189 ],[
2190 usleep_range(0, 0);
2191 ],[
2192 AC_MSG_RESULT(yes)
2193 AC_DEFINE(HAVE_USLEEP_RANGE, 1,
2194 [usleep_range is available])
2195 ],[
2196 AC_MSG_RESULT(no)
2197 ])
2198 ])
2199
2200 dnl #
2201 dnl # 2.6.35 API change,
2202 dnl # The cachep->gfpflags member was renamed cachep->allocflags. These are
2203 dnl # private allocation flags which are applied when allocating a new slab
2204 dnl # in kmem_getpages(). Unfortunately there is no public API for setting
2205 dnl # non-default flags.
2206 dnl #
2207 AC_DEFUN([SPL_AC_KMEM_CACHE_ALLOCFLAGS], [
2208 AC_MSG_CHECKING([whether struct kmem_cache has allocflags])
2209 SPL_LINUX_TRY_COMPILE([
2210 #include <linux/slab.h>
2211 ],[
2212 struct kmem_cache cachep __attribute__ ((unused));
2213 cachep.allocflags = GFP_KERNEL;
2214 ],[
2215 AC_MSG_RESULT(yes)
2216 AC_DEFINE(HAVE_KMEM_CACHE_ALLOCFLAGS, 1,
2217 [struct kmem_cache has allocflags])
2218 ],[
2219 AC_MSG_RESULT(no)
2220
2221 AC_MSG_CHECKING([whether struct kmem_cache has gfpflags])
2222 SPL_LINUX_TRY_COMPILE([
2223 #include <linux/slab.h>
2224 ],[
2225 struct kmem_cache cachep __attribute__ ((unused));
2226 cachep.gfpflags = GFP_KERNEL;
2227 ],[
2228 AC_MSG_RESULT(yes)
2229 AC_DEFINE(HAVE_KMEM_CACHE_GFPFLAGS, 1,
2230 [struct kmem_cache has gfpflags])
2231 ],[
2232 AC_MSG_RESULT(no)
2233 ])
2234 ])
2235 ])
2236
2237 dnl #
2238 dnl # 3.17 API change,
2239 dnl # wait_on_bit() no longer requires an action argument. The former
2240 dnl # "wait_on_bit" interface required an 'action' function to be provided
2241 dnl # which does the actual waiting. There were over 20 such functions in the
2242 dnl # kernel, many of them identical, though most cases can be satisfied by one
2243 dnl # of just two functions: one which uses io_schedule() and one which just
2244 dnl # uses schedule(). This API change was made to consolidate all of those
2245 dnl # redundant wait functions.
2246 dnl #
2247 AC_DEFUN([SPL_AC_WAIT_ON_BIT], [
2248 AC_MSG_CHECKING([whether wait_on_bit() takes an action])
2249 SPL_LINUX_TRY_COMPILE([
2250 #include <linux/wait.h>
2251 ],[
2252 int (*action)(void *) = NULL;
2253 wait_on_bit(NULL, 0, action, 0);
2254 ],[
2255 AC_MSG_RESULT(yes)
2256 AC_DEFINE(HAVE_WAIT_ON_BIT_ACTION, 1, [yes])
2257 ],[
2258 AC_MSG_RESULT(no)
2259 ])
2260 ])