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