]> git.proxmox.com Git - mirror_spl.git/blob - config/spl-build.m4
d8eadb7e98c20c50d5d528ca8686a5083ba68e12
[mirror_spl.git] / config / spl-build.m4
1 ###############################################################################
2 # Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 # Copyright (C) 2007 The Regents of the University of California.
4 # Written by Brian Behlendorf <behlendorf1@llnl.gov>.
5 ###############################################################################
6 # SPL_AC_CONFIG_KERNEL: Default SPL kernel configuration.
7 ###############################################################################
8
9 AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
10 SPL_AC_KERNEL
11
12 if test "${LINUX_OBJ}" != "${LINUX}"; then
13 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
14 fi
15 AC_SUBST(KERNELMAKE_PARAMS)
16
17 KERNELCPPFLAGS="$KERNELCPPFLAGS -Wstrict-prototypes"
18 AC_SUBST(KERNELCPPFLAGS)
19
20 SPL_AC_DEBUG
21 SPL_AC_DEBUG_KMEM
22 SPL_AC_DEBUG_KMEM_TRACKING
23 SPL_AC_ATOMIC_SPINLOCK
24 SPL_AC_TYPE_ATOMIC64_CMPXCHG
25 SPL_AC_TYPE_ATOMIC64_XCHG
26 SPL_AC_TYPE_UINTPTR_T
27 SPL_AC_3ARGS_INIT_WORK
28 SPL_AC_2ARGS_REGISTER_SYSCTL
29 SPL_AC_SET_SHRINKER
30 SPL_AC_3ARGS_SHRINKER_CALLBACK
31 SPL_AC_PATH_IN_NAMEIDATA
32 SPL_AC_TASK_CURR
33 SPL_AC_CTL_UNNUMBERED
34 SPL_AC_CTL_NAME
35 SPL_AC_FLS64
36 SPL_AC_DEVICE_CREATE
37 SPL_AC_5ARGS_DEVICE_CREATE
38 SPL_AC_CLASS_DEVICE_CREATE
39 SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT
40 SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE
41 SPL_AC_TIMESPEC_SUB
42 SPL_AC_INIT_UTSNAME
43 SPL_AC_FDTABLE_HEADER
44 SPL_AC_FILES_FDTABLE
45 SPL_AC_UACCESS_HEADER
46 SPL_AC_KMALLOC_NODE
47 SPL_AC_MONOTONIC_CLOCK
48 SPL_AC_INODE_I_MUTEX
49 SPL_AC_MUTEX_OWNER
50 SPL_AC_MUTEX_LOCK_NESTED
51 SPL_AC_3ARGS_ON_EACH_CPU
52 SPL_AC_KALLSYMS_LOOKUP_NAME
53 SPL_AC_GET_VMALLOC_INFO
54 SPL_AC_PGDAT_HELPERS
55 SPL_AC_FIRST_ONLINE_PGDAT
56 SPL_AC_NEXT_ONLINE_PGDAT
57 SPL_AC_NEXT_ZONE
58 SPL_AC_PGDAT_LIST
59 SPL_AC_GLOBAL_PAGE_STATE
60 SPL_AC_ZONE_STAT_ITEM_FREE
61 SPL_AC_ZONE_STAT_ITEM_INACTIVE
62 SPL_AC_ZONE_STAT_ITEM_ACTIVE
63 SPL_AC_GET_ZONE_COUNTS
64 SPL_AC_USER_PATH_DIR
65 SPL_AC_SET_FS_PWD
66 SPL_AC_2ARGS_SET_FS_PWD
67 SPL_AC_2ARGS_VFS_UNLINK
68 SPL_AC_4ARGS_VFS_RENAME
69 SPL_AC_FS_STRUCT_SPINLOCK
70 SPL_AC_CRED_STRUCT
71 SPL_AC_GROUPS_SEARCH
72 SPL_AC_PUT_TASK_STRUCT
73 SPL_AC_5ARGS_PROC_HANDLER
74 SPL_AC_KVASPRINTF
75 SPL_AC_3ARGS_FILE_FSYNC
76 SPL_AC_EXPORTED_RWSEM_IS_LOCKED
77 ])
78
79 AC_DEFUN([SPL_AC_MODULE_SYMVERS], [
80 modpost=$LINUX/scripts/Makefile.modpost
81 AC_MSG_CHECKING([kernel file name for module symbols])
82 if test -f "$modpost"; then
83 if grep -q Modules.symvers $modpost; then
84 LINUX_SYMBOLS=Modules.symvers
85 else
86 LINUX_SYMBOLS=Module.symvers
87 fi
88 else
89 LINUX_SYMBOLS=NONE
90 fi
91 AC_MSG_RESULT($LINUX_SYMBOLS)
92 AC_SUBST(LINUX_SYMBOLS)
93 ])
94
95 AC_DEFUN([SPL_AC_KERNEL], [
96 AC_ARG_WITH([linux],
97 AS_HELP_STRING([--with-linux=PATH],
98 [Path to kernel source]),
99 [kernelsrc="$withval"])
100
101 AC_ARG_WITH([linux-obj],
102 AS_HELP_STRING([--with-linux-obj=PATH],
103 [Path to kernel build objects]),
104 [kernelbuild="$withval"])
105
106 AC_MSG_CHECKING([kernel source directory])
107 if test -z "$kernelsrc"; then
108 if test -e "/lib/modules/$(uname -r)/source"; then
109 headersdir="/lib/modules/$(uname -r)/source"
110 sourcelink=$(readlink -f "$headersdir")
111 elif test -e "/lib/modules/$(uname -r)/build"; then
112 headersdir="/lib/modules/$(uname -r)/build"
113 sourcelink=$(readlink -f "$headersdir")
114 else
115 sourcelink=$(ls -1d /usr/src/kernels/* \
116 /usr/src/linux-* \
117 2>/dev/null | grep -v obj | tail -1)
118 fi
119
120 if test -n "$sourcelink" && test -e ${sourcelink}; then
121 kernelsrc=`readlink -f ${sourcelink}`
122 else
123 AC_MSG_RESULT([Not found])
124 AC_MSG_ERROR([
125 *** Please make sure the kernel devel package for your distribution
126 *** is installed then try again. If that fails you can specify the
127 *** location of the kernel source with the '--with-linux=PATH' option.])
128 fi
129 else
130 if test "$kernelsrc" = "NONE"; then
131 kernsrcver=NONE
132 fi
133 fi
134
135 AC_MSG_RESULT([$kernelsrc])
136 AC_MSG_CHECKING([kernel build directory])
137 if test -z "$kernelbuild"; then
138 if test -e "/lib/modules/$(uname -r)/build"; then
139 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
140 elif test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
141 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
142 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
143 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
144 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
145 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
146 else
147 kernelbuild=${kernelsrc}
148 fi
149 fi
150 AC_MSG_RESULT([$kernelbuild])
151
152 AC_MSG_CHECKING([kernel source version])
153 utsrelease1=$kernelbuild/include/linux/version.h
154 utsrelease2=$kernelbuild/include/linux/utsrelease.h
155 utsrelease3=$kernelbuild/include/generated/utsrelease.h
156 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
157 utsrelease=linux/version.h
158 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
159 utsrelease=linux/utsrelease.h
160 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
161 utsrelease=generated/utsrelease.h
162 fi
163
164 if test "$utsrelease"; then
165 kernsrcver=`(echo "#include <$utsrelease>";
166 echo "kernsrcver=UTS_RELEASE") |
167 cpp -I $kernelbuild/include |
168 grep "^kernsrcver=" | cut -d \" -f 2`
169
170 if test -z "$kernsrcver"; then
171 AC_MSG_RESULT([Not found])
172 AC_MSG_ERROR([*** Cannot determine kernel version.])
173 fi
174 else
175 AC_MSG_RESULT([Not found])
176 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
177 fi
178
179 AC_MSG_RESULT([$kernsrcver])
180
181 LINUX=${kernelsrc}
182 LINUX_OBJ=${kernelbuild}
183 LINUX_VERSION=${kernsrcver}
184
185 AC_SUBST(LINUX)
186 AC_SUBST(LINUX_OBJ)
187 AC_SUBST(LINUX_VERSION)
188
189 SPL_AC_MODULE_SYMVERS
190 ])
191
192 dnl #
193 dnl # Explicitly check for gawk, we require it for the the usermode
194 dnl # helper. For some reason the standard awk command does not
195 dnl # behave correctly when invoked from the usermode helper.
196 dnl #
197 AC_DEFUN([SPL_AC_GAWK], [
198 AS_IF([test "x$AWK" != xgawk], [
199 AC_MSG_ERROR([
200 *** Required util gawk missing. Please install the required
201 *** gawk package for your distribution and try again.])
202 ])
203 ])
204
205 dnl #
206 dnl # Default SPL user configuration
207 dnl #
208 AC_DEFUN([SPL_AC_CONFIG_USER], [
209 SPL_AC_GAWK
210 ])
211
212 dnl #
213 dnl # Check for rpm+rpmbuild to build RPM packages. If these tools
214 dnl # are missing it is non-fatal but you will not be able to build
215 dnl # RPM packages and will be warned if you try too.
216 dnl #
217 AC_DEFUN([SPL_AC_RPM], [
218 RPM=rpm
219 RPMBUILD=rpmbuild
220
221 AC_MSG_CHECKING([whether $RPM is available])
222 AS_IF([tmp=$($RPM --version 2>/dev/null)], [
223 RPM_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
224 HAVE_RPM=yes
225 AC_MSG_RESULT([$HAVE_RPM ($RPM_VERSION)])
226 ],[
227 HAVE_RPM=no
228 AC_MSG_RESULT([$HAVE_RPM])
229 ])
230
231 AC_MSG_CHECKING([whether $RPMBUILD is available])
232 AS_IF([tmp=$($RPMBUILD --version 2>/dev/null)], [
233 RPMBUILD_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
234 HAVE_RPMBUILD=yes
235 AC_MSG_RESULT([$HAVE_RPMBUILD ($RPMBUILD_VERSION)])
236 ],[
237 HAVE_RPMBUILD=no
238 AC_MSG_RESULT([$HAVE_RPMBUILD])
239 ])
240
241 AC_SUBST(HAVE_RPM)
242 AC_SUBST(RPM)
243 AC_SUBST(RPM_VERSION)
244
245 AC_SUBST(HAVE_RPMBUILD)
246 AC_SUBST(RPMBUILD)
247 AC_SUBST(RPMBUILD_VERSION)
248 ])
249
250 dnl #
251 dnl # Check for dpkg+dpkg-buildpackage to build DEB packages. If these
252 dnl # tools are missing it is non-fatal but you will not be able to build
253 dnl # DEB packages and will be warned if you try too.
254 dnl #
255 AC_DEFUN([SPL_AC_DPKG], [
256 DPKG=dpkg
257 DPKGBUILD=dpkg-buildpackage
258
259 AC_MSG_CHECKING([whether $DPKG is available])
260 AS_IF([tmp=$($DPKG --version 2>/dev/null)], [
261 DPKG_VERSION=$(echo $tmp | $AWK '/Debian/ { print $[7] }')
262 HAVE_DPKG=yes
263 AC_MSG_RESULT([$HAVE_DPKG ($DPKG_VERSION)])
264 ],[
265 HAVE_DPKG=no
266 AC_MSG_RESULT([$HAVE_DPKG])
267 ])
268
269 AC_MSG_CHECKING([whether $DPKGBUILD is available])
270 AS_IF([tmp=$($DPKGBUILD --version 2>/dev/null)], [
271 DPKGBUILD_VERSION=$(echo $tmp | \
272 $AWK '/Debian/ { print $[4] }' | cut -f-4 -d'.')
273 HAVE_DPKGBUILD=yes
274 AC_MSG_RESULT([$HAVE_DPKGBUILD ($DPKGBUILD_VERSION)])
275 ],[
276 HAVE_DPKGBUILD=no
277 AC_MSG_RESULT([$HAVE_DPKGBUILD])
278 ])
279
280 AC_SUBST(HAVE_DPKG)
281 AC_SUBST(DPKG)
282 AC_SUBST(DPKG_VERSION)
283
284 AC_SUBST(HAVE_DPKGBUILD)
285 AC_SUBST(DPKGBUILD)
286 AC_SUBST(DPKGBUILD_VERSION)
287 ])
288
289 dnl #
290 dnl # Until native packaging for various different packing systems
291 dnl # can be added the least we can do is attempt to use alien to
292 dnl # convert the RPM packages to the needed package type. This is
293 dnl # a hack but so far it has worked reasonable well.
294 dnl #
295 AC_DEFUN([SPL_AC_ALIEN], [
296 ALIEN=alien
297
298 AC_MSG_CHECKING([whether $ALIEN is available])
299 AS_IF([tmp=$($ALIEN --version 2>/dev/null)], [
300 ALIEN_VERSION=$(echo $tmp | $AWK '{ print $[3] }')
301 HAVE_ALIEN=yes
302 AC_MSG_RESULT([$HAVE_ALIEN ($ALIEN_VERSION)])
303 ],[
304 HAVE_ALIEN=no
305 AC_MSG_RESULT([$HAVE_ALIEN])
306 ])
307
308 AC_SUBST(HAVE_ALIEN)
309 AC_SUBST(ALIEN)
310 AC_SUBST(ALIEN_VERSION)
311 ])
312
313 dnl #
314 dnl # Using the VENDOR tag from config.guess set the default
315 dnl # package type for 'make pkg': (rpm | deb | tgz)
316 dnl #
317 AC_DEFUN([SPL_AC_DEFAULT_PACKAGE], [
318 AC_MSG_CHECKING([linux distribution])
319 if test -f /etc/redhat-release ; then
320 VENDOR=redhat ;
321 elif test -f /etc/fedora-release ; then
322 VENDOR=fedora ;
323 elif test -f /etc/lsb-release ; then
324 VENDOR=ubuntu ;
325 elif test -f /etc/debian_version ; then
326 VENDOR=debian ;
327 elif test -f /etc/SuSE-release ; then
328 VENDOR=sles ;
329 elif test -f /etc/slackware-version ; then
330 VENDOR=slackware ;
331 elif test -f /etc/gentoo-release ; then
332 VENDOR=gentoo ;
333 else
334 VENDOR= ;
335 fi
336 AC_MSG_RESULT([$VENDOR])
337 AC_SUBST(VENDOR)
338
339 AC_MSG_CHECKING([default package type])
340 case "$VENDOR" in
341 fedora) DEFAULT_PACKAGE=rpm ;;
342 redhat) DEFAULT_PACKAGE=rpm ;;
343 sles) DEFAULT_PACKAGE=rpm ;;
344 ubuntu) DEFAULT_PACKAGE=deb ;;
345 debian) DEFAULT_PACKAGE=deb ;;
346 slackware) DEFAULT_PACKAGE=tgz ;;
347 *) DEFAULT_PACKAGE=rpm ;;
348 esac
349
350 AC_MSG_RESULT([$DEFAULT_PACKAGE])
351 AC_SUBST(DEFAULT_PACKAGE)
352 ])
353
354 dnl #
355 dnl # Default SPL user configuration
356 dnl #
357 AC_DEFUN([SPL_AC_PACKAGE], [
358 SPL_AC_RPM
359 SPL_AC_DPKG
360 SPL_AC_ALIEN
361 SPL_AC_DEFAULT_PACKAGE
362 ])
363
364 AC_DEFUN([SPL_AC_LICENSE], [
365 AC_MSG_CHECKING([spl license])
366 LICENSE=GPL
367 AC_MSG_RESULT([$LICENSE])
368 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DHAVE_GPL_ONLY_SYMBOLS"
369 AC_SUBST(LICENSE)
370 ])
371
372 AC_DEFUN([SPL_AC_CONFIG], [
373 SPL_CONFIG=all
374 AC_ARG_WITH([config],
375 AS_HELP_STRING([--with-config=CONFIG],
376 [Config file 'kernel|user|all|srpm']),
377 [SPL_CONFIG="$withval"])
378
379 AC_MSG_CHECKING([spl config])
380 AC_MSG_RESULT([$SPL_CONFIG]);
381 AC_SUBST(SPL_CONFIG)
382
383 case "$SPL_CONFIG" in
384 kernel) SPL_AC_CONFIG_KERNEL ;;
385 user) SPL_AC_CONFIG_USER ;;
386 all) SPL_AC_CONFIG_KERNEL
387 SPL_AC_CONFIG_USER ;;
388 srpm) ;;
389 *)
390 AC_MSG_RESULT([Error!])
391 AC_MSG_ERROR([Bad value "$SPL_CONFIG" for --with-config,
392 user kernel|user|all|srpm]) ;;
393 esac
394
395 AM_CONDITIONAL([CONFIG_USER],
396 [test "$SPL_CONFIG" = user] ||
397 [test "$SPL_CONFIG" = all])
398 AM_CONDITIONAL([CONFIG_KERNEL],
399 [test "$SPL_CONFIG" = kernel] ||
400 [test "$SPL_CONFIG" = all])
401 ])
402
403 dnl #
404 dnl # Enable if the SPL should be compiled with internal debugging enabled.
405 dnl # By default this support is disabled.
406 dnl #
407 AC_DEFUN([SPL_AC_DEBUG], [
408 AC_MSG_CHECKING([whether debugging is enabled])
409 AC_ARG_ENABLE([debug],
410 [AS_HELP_STRING([--enable-debug],
411 [Enable generic debug support @<:@default=no@:>@])],
412 [],
413 [enable_debug=no])
414
415 AS_IF([test "x$enable_debug" = xyes],
416 [
417 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG -Werror"
418 DEBUG_CFLAGS="-DDEBUG -Werror"
419 ],
420 [
421 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
422 DEBUG_CFLAGS="-DNDEBUG"
423 ])
424
425 AC_SUBST(DEBUG_CFLAGS)
426 AC_MSG_RESULT([$enable_debug])
427 ])
428
429 dnl #
430 dnl # Enabled by default it provides a minimal level of memory tracking.
431 dnl # A total count of bytes allocated is kept for each alloc and free.
432 dnl # Then at module unload time a report to the console will be printed
433 dnl # if memory was leaked. Additionally, /proc/spl/kmem/slab will exist
434 dnl # and provide an easy way to inspect the kmem based slab.
435 dnl #
436 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
437 AC_ARG_ENABLE([debug-kmem],
438 [AS_HELP_STRING([--enable-debug-kmem],
439 [Enable basic kmem accounting @<:@default=yes@:>@])],
440 [],
441 [enable_debug_kmem=yes])
442
443 AS_IF([test "x$enable_debug_kmem" = xyes],
444 [AC_DEFINE([DEBUG_KMEM], [1],
445 [Define to 1 to enable basic kmem accounting])
446 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"])
447
448 AC_MSG_CHECKING([whether basic kmem accounting is enabled])
449 AC_MSG_RESULT([$enable_debug_kmem])
450 ])
451
452 dnl #
453 dnl # Disabled by default it provides detailed memory tracking. This
454 dnl # feature also requires --enable-debug-kmem to be set. When enabled
455 dnl # not only will total bytes be tracked but also the location of every
456 dnl # alloc and free. When the SPL module is unloaded a list of all leaked
457 dnl # addresses and where they were allocated will be dumped to the console.
458 dnl # Enabling this feature has a significant impact on performance but it
459 dnl # makes finding memory leaks pretty straight forward.
460 dnl #
461 AC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [
462 AC_ARG_ENABLE([debug-kmem-tracking],
463 [AS_HELP_STRING([--enable-debug-kmem-tracking],
464 [Enable detailed kmem tracking @<:@default=no@:>@])],
465 [],
466 [enable_debug_kmem_tracking=no])
467
468 AS_IF([test "x$enable_debug_kmem_tracking" = xyes],
469 [AC_DEFINE([DEBUG_KMEM_TRACKING], [1],
470 [Define to 1 to enable detailed kmem tracking])
471 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM_TRACKING"])
472
473 AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
474 AC_MSG_RESULT([$enable_debug_kmem_tracking])
475 ])
476
477 dnl #
478 dnl # SPL_LINUX_CONFTEST
479 dnl #
480 AC_DEFUN([SPL_LINUX_CONFTEST], [
481 cat confdefs.h - <<_ACEOF >conftest.c
482 $1
483 _ACEOF
484 ])
485
486 dnl #
487 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
488 dnl #
489 m4_define([SPL_LANG_PROGRAM], [
490 $1
491 int
492 main (void)
493 {
494 dnl Do *not* indent the following line: there may be CPP directives.
495 dnl Don't move the `;' right after for the same reason.
496 $2
497 ;
498 return 0;
499 }
500 ])
501
502 dnl #
503 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
504 dnl #
505 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
506 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])
507 rm -Rf build && mkdir -p build
508 echo "obj-m := conftest.o" >build/Makefile
509 AS_IF(
510 [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) >/dev/null && AC_TRY_COMMAND([$3])],
511 [$4],
512 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
513 )
514 rm -Rf build
515 ])
516
517 dnl #
518 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
519 dnl #
520 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
521 [SPL_LINUX_COMPILE_IFELSE(
522 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
523 [modules],
524 [test -s build/conftest.o],
525 [$3], [$4])
526 ])
527
528 dnl #
529 dnl # SPL_LINUX_CONFIG
530 dnl #
531 AC_DEFUN([SPL_LINUX_CONFIG],
532 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
533 SPL_LINUX_TRY_COMPILE([
534 #ifndef AUTOCONF_INCLUDED
535 #include <linux/config.h>
536 #endif
537 ],[
538 #ifndef CONFIG_$1
539 #error CONFIG_$1 not #defined
540 #endif
541 ],[
542 AC_MSG_RESULT([yes])
543 $2
544 ],[
545 AC_MSG_RESULT([no])
546 $3
547 ])
548 ])
549
550 dnl #
551 dnl # SPL_CHECK_SYMBOL_EXPORT
552 dnl # check symbol exported or not
553 dnl #
554 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT],
555 [AC_MSG_CHECKING([whether symbol $1 is exported])
556 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
557 $LINUX_OBJ/Module*.symvers 2>/dev/null
558 rc=$?
559 if test $rc -ne 0; then
560 export=0
561 for file in $2; do
562 grep -q -E "EXPORT_SYMBOL.*($1)" \
563 "$LINUX_OBJ/$file" 2>/dev/null
564 rc=$?
565 if test $rc -eq 0; then
566 export=1
567 break;
568 fi
569 done
570 if test $export -eq 0; then
571 AC_MSG_RESULT([no])
572 $4
573 else
574 AC_MSG_RESULT([yes])
575 $3
576 fi
577 else
578 AC_MSG_RESULT([yes])
579 $3
580 fi
581 ])
582
583 dnl #
584 dnl # SPL_CHECK_HEADER
585 dnl # check whether header exists and define HAVE_$2_HEADER
586 dnl #
587 AC_DEFUN([SPL_CHECK_HEADER],
588 [AC_MSG_CHECKING([whether header $1 exists])
589 SPL_LINUX_TRY_COMPILE([
590 #include <$1>
591 ],[
592 return 0;
593 ],[
594 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
595 AC_MSG_RESULT(yes)
596 $3
597 ],[
598 AC_MSG_RESULT(no)
599 $4
600 ])
601 ])
602
603 dnl #
604 dnl # Use the atomic implemenation based on global spinlocks. This
605 dnl # should only be needed by 32-bit kernels which do not provide
606 dnl # the atomic64_* API. It may be optionally enabled as a fallback
607 dnl # if problems are observed with the direct mapping to the native
608 dnl # Linux atomic operations. You may not disable atomic spinlocks
609 dnl # if you kernel does not an atomic64_* API.
610 dnl #
611 AC_DEFUN([SPL_AC_ATOMIC_SPINLOCK], [
612 AC_ARG_ENABLE([atomic-spinlocks],
613 [AS_HELP_STRING([--enable-atomic-spinlocks],
614 [Atomic types use spinlocks @<:@default=check@:>@])],
615 [],
616 [enable_atomic_spinlocks=check])
617
618 SPL_LINUX_TRY_COMPILE([
619 #include <asm/atomic.h>
620 ],[
621 atomic64_t *ptr;
622 ],[
623 have_atomic64_t=yes
624 AC_DEFINE(HAVE_ATOMIC64_T, 1,
625 [kernel defines atomic64_t])
626 ],[
627 have_atomic64_t=no
628 ])
629
630 AS_IF([test "x$enable_atomic_spinlocks" = xcheck], [
631 AS_IF([test "x$have_atomic64_t" = xyes], [
632 enable_atomic_spinlocks=no
633 ],[
634 enable_atomic_spinlocks=yes
635 ])
636 ])
637
638 AS_IF([test "x$enable_atomic_spinlocks" = xyes], [
639 AC_DEFINE([ATOMIC_SPINLOCK], [1],
640 [Atomic types use spinlocks])
641 ],[
642 AS_IF([test "x$have_atomic64_t" = xno], [
643 AC_MSG_FAILURE(
644 [--disable-atomic-spinlocks given but required atomic64 support is unavailable])
645 ])
646 ])
647
648 AC_MSG_CHECKING([whether atomic types use spinlocks])
649 AC_MSG_RESULT([$enable_atomic_spinlocks])
650
651 AC_MSG_CHECKING([whether kernel defines atomic64_t])
652 AC_MSG_RESULT([$have_atomic64_t])
653 ])
654
655 dnl #
656 dnl # 2.6.24 API change,
657 dnl # check if atomic64_cmpxchg is defined
658 dnl #
659 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_CMPXCHG],
660 [AC_MSG_CHECKING([whether kernel defines atomic64_cmpxchg])
661 SPL_LINUX_TRY_COMPILE([
662 #include <asm/atomic.h>
663 #include <asm/system.h>
664 ],[
665 atomic64_cmpxchg((atomic64_t *)NULL, 0, 0);
666 ],[
667 AC_MSG_RESULT([yes])
668 AC_DEFINE(HAVE_ATOMIC64_CMPXCHG, 1,
669 [kernel defines atomic64_cmpxchg])
670 ],[
671 AC_MSG_RESULT([no])
672 ])
673 ])
674
675 dnl #
676 dnl # 2.6.24 API change,
677 dnl # check if atomic64_xchg is defined
678 dnl #
679 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_XCHG],
680 [AC_MSG_CHECKING([whether kernel defines atomic64_xchg])
681 SPL_LINUX_TRY_COMPILE([
682 #include <asm/atomic.h>
683 ],[
684 atomic64_xchg((atomic64_t *)NULL, 0);
685 ],[
686 AC_MSG_RESULT([yes])
687 AC_DEFINE(HAVE_ATOMIC64_XCHG, 1,
688 [kernel defines atomic64_xchg])
689 ],[
690 AC_MSG_RESULT([no])
691 ])
692 ])
693
694 dnl #
695 dnl # 2.6.24 API change,
696 dnl # check if uintptr_t typedef is defined
697 dnl #
698 AC_DEFUN([SPL_AC_TYPE_UINTPTR_T],
699 [AC_MSG_CHECKING([whether kernel defines uintptr_t])
700 SPL_LINUX_TRY_COMPILE([
701 #include <linux/types.h>
702 ],[
703 uintptr_t *ptr;
704 ],[
705 AC_MSG_RESULT([yes])
706 AC_DEFINE(HAVE_UINTPTR_T, 1,
707 [kernel defines uintptr_t])
708 ],[
709 AC_MSG_RESULT([no])
710 ])
711 ])
712
713 dnl #
714 dnl # 2.6.20 API change,
715 dnl # INIT_WORK use 2 args and not store data inside
716 dnl #
717 AC_DEFUN([SPL_AC_3ARGS_INIT_WORK],
718 [AC_MSG_CHECKING([whether INIT_WORK wants 3 args])
719 SPL_LINUX_TRY_COMPILE([
720 #include <linux/workqueue.h>
721 ],[
722 struct work_struct work;
723 INIT_WORK(&work, NULL, NULL);
724 ],[
725 AC_MSG_RESULT(yes)
726 AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
727 [INIT_WORK wants 3 args])
728 ],[
729 AC_MSG_RESULT(no)
730 ])
731 ])
732
733 dnl #
734 dnl # 2.6.21 API change,
735 dnl # 'register_sysctl_table' use only one argument instead of two
736 dnl #
737 AC_DEFUN([SPL_AC_2ARGS_REGISTER_SYSCTL],
738 [AC_MSG_CHECKING([whether register_sysctl_table() wants 2 args])
739 SPL_LINUX_TRY_COMPILE([
740 #include <linux/sysctl.h>
741 ],[
742 return register_sysctl_table(NULL,0);
743 ],[
744 AC_MSG_RESULT(yes)
745 AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
746 [register_sysctl_table() wants 2 args])
747 ],[
748 AC_MSG_RESULT(no)
749 ])
750 ])
751
752 dnl #
753 dnl # 2.6.23 API change
754 dnl # Old set_shrinker API replaced with register_shrinker
755 dnl #
756 AC_DEFUN([SPL_AC_SET_SHRINKER], [
757 AC_MSG_CHECKING([whether set_shrinker() available])
758 SPL_LINUX_TRY_COMPILE([
759 #include <linux/mm.h>
760 ],[
761 return set_shrinker(DEFAULT_SEEKS, NULL);
762 ],[
763 AC_MSG_RESULT([yes])
764 AC_DEFINE(HAVE_SET_SHRINKER, 1,
765 [set_shrinker() available])
766 ],[
767 AC_MSG_RESULT([no])
768 ])
769 ])
770
771 dnl #
772 dnl # 2.6.35 API change,
773 dnl # Add context to shrinker callback
774 dnl #
775 AC_DEFUN([SPL_AC_3ARGS_SHRINKER_CALLBACK],
776 [AC_MSG_CHECKING([whether shrinker callback wants 3 args])
777 tmp_flags="$EXTRA_KCFLAGS"
778 EXTRA_KCFLAGS="-Werror"
779 SPL_LINUX_TRY_COMPILE([
780 #include <linux/mm.h>
781
782 int shrinker_cb(struct shrinker *, int, unsigned int);
783 ],[
784 struct shrinker cache_shrinker = {
785 .shrink = shrinker_cb,
786 .seeks = DEFAULT_SEEKS,
787 };
788 register_shrinker(&cache_shrinker);
789 ],[
790 AC_MSG_RESULT(yes)
791 AC_DEFINE(HAVE_3ARGS_SHRINKER_CALLBACK, 1,
792 [shrinker callback wants 3 args])
793 ],[
794 AC_MSG_RESULT(no)
795 ])
796 EXTRA_KCFLAGS="$tmp_flags"
797 ])
798
799 dnl #
800 dnl # 2.6.25 API change,
801 dnl # struct path entry added to struct nameidata
802 dnl #
803 AC_DEFUN([SPL_AC_PATH_IN_NAMEIDATA],
804 [AC_MSG_CHECKING([whether struct path used in struct nameidata])
805 SPL_LINUX_TRY_COMPILE([
806 #include <linux/namei.h>
807 ],[
808 struct nameidata nd;
809
810 nd.path.mnt = NULL;
811 nd.path.dentry = NULL;
812 ],[
813 AC_MSG_RESULT(yes)
814 AC_DEFINE(HAVE_PATH_IN_NAMEIDATA, 1,
815 [struct path used in struct nameidata])
816 ],[
817 AC_MSG_RESULT(no)
818 ])
819 ])
820
821 dnl #
822 dnl # Custom SPL patch may export this system it is not required
823 dnl #
824 AC_DEFUN([SPL_AC_TASK_CURR], [
825 SPL_CHECK_SYMBOL_EXPORT([task_curr], [kernel/sched.c],
826 [AC_DEFINE(HAVE_TASK_CURR, 1, [task_curr() exported])],
827 [])
828 ])
829
830 dnl #
831 dnl # 2.6.19 API change,
832 dnl # Use CTL_UNNUMBERED when binary sysctl is not required
833 dnl #
834 AC_DEFUN([SPL_AC_CTL_UNNUMBERED],
835 [AC_MSG_CHECKING([whether unnumbered sysctl support exists])
836 SPL_LINUX_TRY_COMPILE([
837 #include <linux/sysctl.h>
838 ],[
839 #ifndef CTL_UNNUMBERED
840 #error CTL_UNNUMBERED undefined
841 #endif
842 ],[
843 AC_MSG_RESULT(yes)
844 AC_DEFINE(HAVE_CTL_UNNUMBERED, 1,
845 [unnumbered sysctl support exists])
846 ],[
847 AC_MSG_RESULT(no)
848 ])
849 ])
850
851 dnl #
852 dnl # 2.6.33 API change,
853 dnl # Removed .ctl_name from struct ctl_table.
854 dnl #
855 AC_DEFUN([SPL_AC_CTL_NAME], [
856 AC_MSG_CHECKING([whether struct ctl_table has ctl_name])
857 SPL_LINUX_TRY_COMPILE([
858 #include <linux/sysctl.h>
859 ],[
860 struct ctl_table ctl;
861 ctl.ctl_name = 0;
862 ],[
863 AC_MSG_RESULT(yes)
864 AC_DEFINE(HAVE_CTL_NAME, 1, [struct ctl_table has ctl_name])
865 ],[
866 AC_MSG_RESULT(no)
867 ])
868 ])
869
870 dnl #
871 dnl # 2.6.16 API change.
872 dnl # Check if 'fls64()' is available
873 dnl #
874 AC_DEFUN([SPL_AC_FLS64],
875 [AC_MSG_CHECKING([whether fls64() is available])
876 SPL_LINUX_TRY_COMPILE([
877 #include <linux/bitops.h>
878 ],[
879 return fls64(0);
880 ],[
881 AC_MSG_RESULT(yes)
882 AC_DEFINE(HAVE_FLS64, 1, [fls64() is available])
883 ],[
884 AC_MSG_RESULT(no)
885 ])
886 ])
887
888 dnl #
889 dnl # 2.6.18 API change, check whether device_create() is available.
890 dnl # Device_create() was introduced in 2.6.18 and depricated
891 dnl # class_device_create() which was fully removed in 2.6.26.
892 dnl #
893 AC_DEFUN([SPL_AC_DEVICE_CREATE], [
894 SPL_CHECK_SYMBOL_EXPORT(
895 [device_create],
896 [drivers/base/core.c],
897 [AC_DEFINE(HAVE_DEVICE_CREATE, 1,
898 [device_create() is available])],
899 [])
900 ])
901
902 dnl #
903 dnl # 2.6.27 API change,
904 dnl # device_create() uses 5 args, new 'drvdata' argument.
905 dnl #
906 AC_DEFUN([SPL_AC_5ARGS_DEVICE_CREATE], [
907 AC_MSG_CHECKING([whether device_create() wants 5 args])
908 tmp_flags="$EXTRA_KCFLAGS"
909 EXTRA_KCFLAGS="-Werror"
910 SPL_LINUX_TRY_COMPILE([
911 #include <linux/device.h>
912 ],[
913 device_create(NULL, NULL, 0, NULL, "%d", 1);
914 ],[
915 AC_MSG_RESULT(yes)
916 AC_DEFINE(HAVE_5ARGS_DEVICE_CREATE, 1,
917 [device_create wants 5 args])
918 ],[
919 AC_MSG_RESULT(no)
920 ])
921 EXTRA_KCFLAGS="$tmp_flags"
922 ])
923
924 dnl #
925 dnl # 2.6.13 API change, check whether class_device_create() is available.
926 dnl # Class_device_create() was introduced in 2.6.13 and depricated
927 dnl # class_simple_device_add() which was fully removed in 2.6.13.
928 dnl #
929 AC_DEFUN([SPL_AC_CLASS_DEVICE_CREATE], [
930 SPL_CHECK_SYMBOL_EXPORT(
931 [class_device_create],
932 [drivers/base/class.c],
933 [AC_DEFINE(HAVE_CLASS_DEVICE_CREATE, 1,
934 [class_device_create() is available])],
935 [])
936 ])
937
938 dnl #
939 dnl # 2.6.26 API change, set_normalized_timespec() is exported.
940 dnl #
941 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT], [
942 SPL_CHECK_SYMBOL_EXPORT(
943 [set_normalized_timespec],
944 [kernel/time.c],
945 [AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT, 1,
946 [set_normalized_timespec() is available as export])],
947 [])
948 ])
949
950 dnl #
951 dnl # 2.6.16 API change, set_normalize_timespec() moved to time.c
952 dnl # previously it was available in time.h as an inline.
953 dnl #
954 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE], [
955 AC_MSG_CHECKING([whether set_normalized_timespec() is an inline])
956 SPL_LINUX_TRY_COMPILE([
957 #include <linux/time.h>
958 void set_normalized_timespec(struct timespec *ts,
959 time_t sec, long nsec) { }
960 ],
961 [],
962 [
963 AC_MSG_RESULT(no)
964 ],[
965 AC_MSG_RESULT(yes)
966 AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_INLINE, 1,
967 [set_normalized_timespec() is available as inline])
968 ])
969 ])
970
971 dnl #
972 dnl # 2.6.18 API change,
973 dnl # timespec_sub() inline function available in linux/time.h
974 dnl #
975 AC_DEFUN([SPL_AC_TIMESPEC_SUB], [
976 AC_MSG_CHECKING([whether timespec_sub() is available])
977 SPL_LINUX_TRY_COMPILE([
978 #include <linux/time.h>
979 ],[
980 struct timespec a, b, c = { 0 };
981 c = timespec_sub(a, b);
982 ],[
983 AC_MSG_RESULT(yes)
984 AC_DEFINE(HAVE_TIMESPEC_SUB, 1, [timespec_sub() is available])
985 ],[
986 AC_MSG_RESULT(no)
987 ])
988 ])
989
990 dnl #
991 dnl # 2.6.19 API change,
992 dnl # check if init_utsname() is available in linux/utsname.h
993 dnl #
994 AC_DEFUN([SPL_AC_INIT_UTSNAME], [
995 AC_MSG_CHECKING([whether init_utsname() is available])
996 SPL_LINUX_TRY_COMPILE([
997 #include <linux/utsname.h>
998 ],[
999 struct new_utsname *a = init_utsname();
1000 ],[
1001 AC_MSG_RESULT(yes)
1002 AC_DEFINE(HAVE_INIT_UTSNAME, 1, [init_utsname() is available])
1003 ],[
1004 AC_MSG_RESULT(no)
1005 ])
1006 ])
1007
1008 dnl #
1009 dnl # 2.6.26 API change,
1010 dnl # definition of struct fdtable relocated to linux/fdtable.h
1011 dnl #
1012 AC_DEFUN([SPL_AC_FDTABLE_HEADER], [
1013 SPL_CHECK_HEADER([linux/fdtable.h], [FDTABLE], [], [])
1014 ])
1015
1016 dnl #
1017 dnl # 2.6.14 API change,
1018 dnl # check whether 'files_fdtable()' exists
1019 dnl #
1020 AC_DEFUN([SPL_AC_FILES_FDTABLE], [
1021 AC_MSG_CHECKING([whether files_fdtable() is available])
1022 SPL_LINUX_TRY_COMPILE([
1023 #include <linux/sched.h>
1024 #include <linux/file.h>
1025 #ifdef HAVE_FDTABLE_HEADER
1026 #include <linux/fdtable.h>
1027 #endif
1028 ],[
1029 struct files_struct *files = current->files;
1030 struct fdtable *fdt = files_fdtable(files);
1031 ],[
1032 AC_MSG_RESULT(yes)
1033 AC_DEFINE(HAVE_FILES_FDTABLE, 1, [files_fdtable() is available])
1034 ],[
1035 AC_MSG_RESULT(no)
1036 ])
1037 ])
1038
1039 dnl #
1040 dnl # 2.6.18 API change,
1041 dnl # added linux/uaccess.h
1042 dnl #
1043 AC_DEFUN([SPL_AC_UACCESS_HEADER], [
1044 SPL_CHECK_HEADER([linux/uaccess.h], [UACCESS], [], [])
1045 ])
1046
1047 dnl #
1048 dnl # 2.6.12 API change,
1049 dnl # check whether 'kmalloc_node()' is available.
1050 dnl #
1051 AC_DEFUN([SPL_AC_KMALLOC_NODE], [
1052 AC_MSG_CHECKING([whether kmalloc_node() is available])
1053 SPL_LINUX_TRY_COMPILE([
1054 #include <linux/slab.h>
1055 ],[
1056 void *a = kmalloc_node(1, GFP_KERNEL, 0);
1057 ],[
1058 AC_MSG_RESULT(yes)
1059 AC_DEFINE(HAVE_KMALLOC_NODE, 1, [kmalloc_node() is available])
1060 ],[
1061 AC_MSG_RESULT(no)
1062 ])
1063 ])
1064
1065 dnl #
1066 dnl # 2.6.9 API change,
1067 dnl # check whether 'monotonic_clock()' is available it may
1068 dnl # be available for some archs but not others.
1069 dnl #
1070 AC_DEFUN([SPL_AC_MONOTONIC_CLOCK], [
1071 SPL_CHECK_SYMBOL_EXPORT(
1072 [monotonic_clock],
1073 [],
1074 [AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1,
1075 [monotonic_clock() is available])],
1076 [])
1077 ])
1078
1079 dnl #
1080 dnl # 2.6.16 API change,
1081 dnl # check whether 'struct inode' has i_mutex
1082 dnl #
1083 AC_DEFUN([SPL_AC_INODE_I_MUTEX], [
1084 AC_MSG_CHECKING([whether struct inode has i_mutex])
1085 SPL_LINUX_TRY_COMPILE([
1086 #include <linux/fs.h>
1087 #include <linux/mutex.h>
1088 ],[
1089 struct inode i;
1090 mutex_init(&i.i_mutex);
1091 ],[
1092 AC_MSG_RESULT(yes)
1093 AC_DEFINE(HAVE_INODE_I_MUTEX, 1, [struct inode has i_mutex])
1094 ],[
1095 AC_MSG_RESULT(no)
1096 ])
1097 ])
1098
1099 dnl #
1100 dnl # 2.6.29 API change,
1101 dnl # Adaptive mutexs introduced.
1102 dnl #
1103 AC_DEFUN([SPL_AC_MUTEX_OWNER], [
1104 AC_MSG_CHECKING([whether struct mutex has owner])
1105 SPL_LINUX_TRY_COMPILE([
1106 #include <linux/mutex.h>
1107 ],[
1108 struct mutex mtx;
1109 mtx.owner = NULL;
1110 ],[
1111 AC_MSG_RESULT(yes)
1112 AC_DEFINE(HAVE_MUTEX_OWNER, 1, [struct mutex has owner])
1113 ],[
1114 AC_MSG_RESULT(no)
1115 ])
1116 ])
1117
1118 dnl #
1119 dnl # 2.6.18 API change,
1120 dnl # First introduced 'mutex_lock_nested()' in include/linux/mutex.h,
1121 dnl # as part of the mutex validator. Fallback to using 'mutex_lock()'
1122 dnl # if the mutex validator is disabled or otherwise unavailable.
1123 dnl #
1124 AC_DEFUN([SPL_AC_MUTEX_LOCK_NESTED], [
1125 AC_MSG_CHECKING([whether mutex_lock_nested() is available])
1126 SPL_LINUX_TRY_COMPILE([
1127 #include <linux/mutex.h>
1128 ],[
1129 struct mutex mutex;
1130 mutex_init(&mutex);
1131 mutex_lock_nested(&mutex, 0);
1132 ],[
1133 AC_MSG_RESULT(yes)
1134 AC_DEFINE(HAVE_MUTEX_LOCK_NESTED, 1,
1135 [mutex_lock_nested() is available])
1136 ],[
1137 AC_MSG_RESULT(no)
1138 ])
1139 ])
1140
1141 dnl #
1142 dnl # 2.6.27 API change,
1143 dnl # on_each_cpu() uses 3 args, no 'retry' argument
1144 dnl #
1145 AC_DEFUN([SPL_AC_3ARGS_ON_EACH_CPU], [
1146 AC_MSG_CHECKING([whether on_each_cpu() wants 3 args])
1147 SPL_LINUX_TRY_COMPILE([
1148 #include <linux/smp.h>
1149 ],[
1150 on_each_cpu(NULL, NULL, 0);
1151 ],[
1152 AC_MSG_RESULT(yes)
1153 AC_DEFINE(HAVE_3ARGS_ON_EACH_CPU, 1,
1154 [on_each_cpu wants 3 args])
1155 ],[
1156 AC_MSG_RESULT(no)
1157 ])
1158 ])
1159
1160 dnl #
1161 dnl # 2.6.18 API change,
1162 dnl # kallsyms_lookup_name no longer exported
1163 dnl #
1164 AC_DEFUN([SPL_AC_KALLSYMS_LOOKUP_NAME], [
1165 SPL_CHECK_SYMBOL_EXPORT(
1166 [kallsyms_lookup_name],
1167 [],
1168 [AC_DEFINE(HAVE_KALLSYMS_LOOKUP_NAME, 1,
1169 [kallsyms_lookup_name() is available])],
1170 [])
1171 ])
1172
1173 dnl #
1174 dnl # Proposed API change,
1175 dnl # This symbol is not available in stock kernels. You may build a
1176 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1177 dnl # these symbols for use. If your already rolling a custom kernel for
1178 dnl # your environment this is recommended.
1179 dnl #
1180 AC_DEFUN([SPL_AC_GET_VMALLOC_INFO], [
1181 SPL_CHECK_SYMBOL_EXPORT(
1182 [get_vmalloc_info],
1183 [],
1184 [AC_DEFINE(HAVE_GET_VMALLOC_INFO, 1,
1185 [get_vmalloc_info() is available])],
1186 [])
1187 ])
1188
1189 dnl #
1190 dnl # 2.6.17 API change
1191 dnl # The helper functions first_online_pgdat(), next_online_pgdat(), and
1192 dnl # next_zone() are introduced to simplify for_each_zone(). These symbols
1193 dnl # were exported in 2.6.17 for use by modules which was consistent with
1194 dnl # the previous implementation of for_each_zone(). From 2.6.18 - 2.6.19
1195 dnl # the symbols were exported as 'unused', and by 2.6.20 they exports
1196 dnl # were dropped entirely leaving modules no way to directly iterate over
1197 dnl # the zone list. Because we need access to the zone helpers we check
1198 dnl # if the kernel contains the old or new implementation. Then we check
1199 dnl # to see if the symbols we need for each version are available. If they
1200 dnl # are not, dynamically aquire the addresses with kallsyms_lookup_name().
1201 dnl #
1202 AC_DEFUN([SPL_AC_PGDAT_HELPERS], [
1203 AC_MSG_CHECKING([whether symbol *_pgdat exist])
1204 grep -q -E 'first_online_pgdat' $LINUX/include/linux/mmzone.h 2>/dev/null
1205 rc=$?
1206 if test $rc -eq 0; then
1207 AC_MSG_RESULT([yes])
1208 AC_DEFINE(HAVE_PGDAT_HELPERS, 1, [pgdat helpers are available])
1209 else
1210 AC_MSG_RESULT([no])
1211 fi
1212 ])
1213
1214 dnl #
1215 dnl # Proposed API change,
1216 dnl # This symbol is not available in stock kernels. You may build a
1217 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1218 dnl # these symbols for use. If your already rolling a custom kernel for
1219 dnl # your environment this is recommended.
1220 dnl #
1221 AC_DEFUN([SPL_AC_FIRST_ONLINE_PGDAT], [
1222 SPL_CHECK_SYMBOL_EXPORT(
1223 [first_online_pgdat],
1224 [],
1225 [AC_DEFINE(HAVE_FIRST_ONLINE_PGDAT, 1,
1226 [first_online_pgdat() is available])],
1227 [])
1228 ])
1229
1230 dnl #
1231 dnl # Proposed API change,
1232 dnl # This symbol is not available in stock kernels. You may build a
1233 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1234 dnl # these symbols for use. If your already rolling a custom kernel for
1235 dnl # your environment this is recommended.
1236 dnl #
1237 AC_DEFUN([SPL_AC_NEXT_ONLINE_PGDAT], [
1238 SPL_CHECK_SYMBOL_EXPORT(
1239 [next_online_pgdat],
1240 [],
1241 [AC_DEFINE(HAVE_NEXT_ONLINE_PGDAT, 1,
1242 [next_online_pgdat() is available])],
1243 [])
1244 ])
1245
1246 dnl #
1247 dnl # Proposed API change,
1248 dnl # This symbol is not available in stock kernels. You may build a
1249 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1250 dnl # these symbols for use. If your already rolling a custom kernel for
1251 dnl # your environment this is recommended.
1252 dnl #
1253 AC_DEFUN([SPL_AC_NEXT_ZONE], [
1254 SPL_CHECK_SYMBOL_EXPORT(
1255 [next_zone],
1256 [],
1257 [AC_DEFINE(HAVE_NEXT_ZONE, 1,
1258 [next_zone() is available])],
1259 [])
1260 ])
1261
1262 dnl #
1263 dnl # 2.6.17 API change,
1264 dnl # See SPL_AC_PGDAT_HELPERS for details.
1265 dnl #
1266 AC_DEFUN([SPL_AC_PGDAT_LIST], [
1267 SPL_CHECK_SYMBOL_EXPORT(
1268 [pgdat_list],
1269 [],
1270 [AC_DEFINE(HAVE_PGDAT_LIST, 1,
1271 [pgdat_list is available])],
1272 [])
1273 ])
1274
1275 dnl #
1276 dnl # 2.6.18 API change,
1277 dnl # First introduced global_page_state() support as an inline.
1278 dnl #
1279 AC_DEFUN([SPL_AC_GLOBAL_PAGE_STATE], [
1280 AC_MSG_CHECKING([whether global_page_state() is available])
1281 SPL_LINUX_TRY_COMPILE([
1282 #include <linux/mm.h>
1283 ],[
1284 unsigned long state;
1285 state = global_page_state(0);
1286 ],[
1287 AC_MSG_RESULT(yes)
1288 AC_DEFINE(HAVE_GLOBAL_PAGE_STATE, 1,
1289 [global_page_state() is available])
1290 ],[
1291 AC_MSG_RESULT(no)
1292 ])
1293 ])
1294
1295 dnl #
1296 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1297 dnl # Public global zone stats now include a free page count. However
1298 dnl # the enumerated names of the counters have changed since this API
1299 dnl # was introduced. We need to deduce the corrent name to use. This
1300 dnl # replaces the priviate get_zone_counts() interface.
1301 dnl #
1302 dnl # NR_FREE_PAGES was available from 2.6.21 to current kernels, which
1303 dnl # is 2.6.30 as of when this was written.
1304 dnl #
1305 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_FREE], [
1306 AC_MSG_CHECKING([whether page state NR_FREE_PAGES is available])
1307 SPL_LINUX_TRY_COMPILE([
1308 #include <linux/mm.h>
1309 ],[
1310 enum zone_stat_item zsi;
1311 zsi = NR_FREE_PAGES;
1312 ],[
1313 AC_MSG_RESULT(yes)
1314 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES, 1,
1315 [Page state NR_FREE_PAGES is available])
1316 ],[
1317 AC_MSG_RESULT(no)
1318 ])
1319 ])
1320
1321 dnl #
1322 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1323 dnl # Public global zone stats now include an inactive page count. However
1324 dnl # the enumerated names of the counters have changed since this API
1325 dnl # was introduced. We need to deduce the corrent name to use. This
1326 dnl # replaces the priviate get_zone_counts() interface.
1327 dnl #
1328 dnl # NR_INACTIVE was available from 2.6.21 to 2.6.27 and included both
1329 dnl # anonymous and file inactive pages. As of 2.6.28 it was split in
1330 dnl # to NR_INACTIVE_ANON and NR_INACTIVE_FILE.
1331 dnl #
1332 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_INACTIVE], [
1333 AC_MSG_CHECKING([whether page state NR_INACTIVE is available])
1334 SPL_LINUX_TRY_COMPILE([
1335 #include <linux/mm.h>
1336 ],[
1337 enum zone_stat_item zsi;
1338 zsi = NR_INACTIVE;
1339 ],[
1340 AC_MSG_RESULT(yes)
1341 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE, 1,
1342 [Page state NR_INACTIVE is available])
1343 ],[
1344 AC_MSG_RESULT(no)
1345 ])
1346
1347 AC_MSG_CHECKING([whether page state NR_INACTIVE_ANON is available])
1348 SPL_LINUX_TRY_COMPILE([
1349 #include <linux/mm.h>
1350 ],[
1351 enum zone_stat_item zsi;
1352 zsi = NR_INACTIVE_ANON;
1353 ],[
1354 AC_MSG_RESULT(yes)
1355 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON, 1,
1356 [Page state NR_INACTIVE_ANON is available])
1357 ],[
1358 AC_MSG_RESULT(no)
1359 ])
1360
1361 AC_MSG_CHECKING([whether page state NR_INACTIVE_FILE is available])
1362 SPL_LINUX_TRY_COMPILE([
1363 #include <linux/mm.h>
1364 ],[
1365 enum zone_stat_item zsi;
1366 zsi = NR_INACTIVE_FILE;
1367 ],[
1368 AC_MSG_RESULT(yes)
1369 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE, 1,
1370 [Page state NR_INACTIVE_FILE is available])
1371 ],[
1372 AC_MSG_RESULT(no)
1373 ])
1374 ])
1375
1376 dnl #
1377 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1378 dnl # Public global zone stats now include an active page count. However
1379 dnl # the enumerated names of the counters have changed since this API
1380 dnl # was introduced. We need to deduce the corrent name to use. This
1381 dnl # replaces the priviate get_zone_counts() interface.
1382 dnl #
1383 dnl # NR_ACTIVE was available from 2.6.21 to 2.6.27 and included both
1384 dnl # anonymous and file active pages. As of 2.6.28 it was split in
1385 dnl # to NR_ACTIVE_ANON and NR_ACTIVE_FILE.
1386 dnl #
1387 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_ACTIVE], [
1388 AC_MSG_CHECKING([whether page state NR_ACTIVE is available])
1389 SPL_LINUX_TRY_COMPILE([
1390 #include <linux/mm.h>
1391 ],[
1392 enum zone_stat_item zsi;
1393 zsi = NR_ACTIVE;
1394 ],[
1395 AC_MSG_RESULT(yes)
1396 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE, 1,
1397 [Page state NR_ACTIVE is available])
1398 ],[
1399 AC_MSG_RESULT(no)
1400 ])
1401
1402 AC_MSG_CHECKING([whether page state NR_ACTIVE_ANON is available])
1403 SPL_LINUX_TRY_COMPILE([
1404 #include <linux/mm.h>
1405 ],[
1406 enum zone_stat_item zsi;
1407 zsi = NR_ACTIVE_ANON;
1408 ],[
1409 AC_MSG_RESULT(yes)
1410 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON, 1,
1411 [Page state NR_ACTIVE_ANON is available])
1412 ],[
1413 AC_MSG_RESULT(no)
1414 ])
1415
1416 AC_MSG_CHECKING([whether page state NR_ACTIVE_FILE is available])
1417 SPL_LINUX_TRY_COMPILE([
1418 #include <linux/mm.h>
1419 ],[
1420 enum zone_stat_item zsi;
1421 zsi = NR_ACTIVE_FILE;
1422 ],[
1423 AC_MSG_RESULT(yes)
1424 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE, 1,
1425 [Page state NR_ACTIVE_FILE is available])
1426 ],[
1427 AC_MSG_RESULT(no)
1428 ])
1429 ])
1430
1431 dnl #
1432 dnl # Proposed API change for legacy kernels.
1433 dnl # This symbol is not available in older kernels. For kernels post
1434 dnl # 2.6.21 the global_page_state() API is used to get free/inactive/active
1435 dnl # page state information. This symbol is only used in legacy kernels
1436 dnl # any only as a last resort.
1437 dnl
1438 AC_DEFUN([SPL_AC_GET_ZONE_COUNTS], [
1439 AC_MSG_CHECKING([whether symbol get_zone_counts is needed])
1440 SPL_LINUX_TRY_COMPILE([
1441 ],[
1442 #if !defined(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES)
1443 #error "global_page_state needs NR_FREE_PAGES"
1444 #endif
1445
1446 #if !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE) && \
1447 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON) && \
1448 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE)
1449 #error "global_page_state needs NR_ACTIVE*"
1450 #endif
1451
1452 #if !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE) && \
1453 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON) && \
1454 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE)
1455 #error "global_page_state needs NR_INACTIVE*"
1456 #endif
1457 ],[
1458 AC_MSG_RESULT(no)
1459 ],[
1460 AC_MSG_RESULT(yes)
1461 AC_DEFINE(NEED_GET_ZONE_COUNTS, 1,
1462 [get_zone_counts() is needed])
1463
1464 SPL_CHECK_SYMBOL_EXPORT(
1465 [get_zone_counts],
1466 [],
1467 [AC_DEFINE(HAVE_GET_ZONE_COUNTS, 1,
1468 [get_zone_counts() is available])],
1469 [])
1470 ])
1471 ])
1472
1473 dnl #
1474 dnl # 2.6.27 API change,
1475 dnl # The user_path_dir() replaces __user_walk()
1476 dnl #
1477 AC_DEFUN([SPL_AC_USER_PATH_DIR], [
1478 SPL_CHECK_SYMBOL_EXPORT(
1479 [user_path_at],
1480 [],
1481 [AC_DEFINE(HAVE_USER_PATH_DIR, 1,
1482 [user_path_dir() is available])],
1483 [])
1484 ])
1485
1486 dnl #
1487 dnl # Symbol available in RHEL kernels not in stock kernels.
1488 dnl #
1489 AC_DEFUN([SPL_AC_SET_FS_PWD], [
1490 SPL_CHECK_SYMBOL_EXPORT(
1491 [set_fs_pwd],
1492 [],
1493 [AC_DEFINE(HAVE_SET_FS_PWD, 1,
1494 [set_fs_pwd() is available])],
1495 [])
1496 ])
1497
1498 dnl #
1499 dnl # 2.6.25 API change,
1500 dnl # Simplied API by replacing mnt+dentry args with a single path arg.
1501 dnl #
1502 AC_DEFUN([SPL_AC_2ARGS_SET_FS_PWD],
1503 [AC_MSG_CHECKING([whether set_fs_pwd() wants 2 args])
1504 SPL_LINUX_TRY_COMPILE([
1505 #include <linux/sched.h>
1506 #include <linux/fs_struct.h>
1507 ],[
1508 set_fs_pwd(NULL, NULL);
1509 ],[
1510 AC_MSG_RESULT(yes)
1511 AC_DEFINE(HAVE_2ARGS_SET_FS_PWD, 1,
1512 [set_fs_pwd() wants 2 args])
1513 ],[
1514 AC_MSG_RESULT(no)
1515 ])
1516 ])
1517
1518 dnl #
1519 dnl # SLES API change, never adopted in mainline,
1520 dnl # Third 'struct vfsmount *' argument removed.
1521 dnl #
1522 AC_DEFUN([SPL_AC_2ARGS_VFS_UNLINK],
1523 [AC_MSG_CHECKING([whether vfs_unlink() wants 2 args])
1524 SPL_LINUX_TRY_COMPILE([
1525 #include <linux/fs.h>
1526 ],[
1527 vfs_unlink(NULL, NULL);
1528 ],[
1529 AC_MSG_RESULT(yes)
1530 AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
1531 [vfs_unlink() wants 2 args])
1532 ],[
1533 AC_MSG_RESULT(no)
1534 ])
1535 ])
1536
1537 dnl #
1538 dnl # SLES API change, never adopted in mainline,
1539 dnl # Third and sixth 'struct vfsmount *' argument removed.
1540 dnl #
1541 AC_DEFUN([SPL_AC_4ARGS_VFS_RENAME],
1542 [AC_MSG_CHECKING([whether vfs_rename() wants 4 args])
1543 SPL_LINUX_TRY_COMPILE([
1544 #include <linux/fs.h>
1545 ],[
1546 vfs_rename(NULL, NULL, NULL, NULL);
1547 ],[
1548 AC_MSG_RESULT(yes)
1549 AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
1550 [vfs_rename() wants 4 args])
1551 ],[
1552 AC_MSG_RESULT(no)
1553 ])
1554 ])
1555
1556 dnl #
1557 dnl # 2.6.36 API change,
1558 dnl # The 'struct fs_struct->lock' was changed from a rwlock_t to
1559 dnl # a spinlock_t to improve the fastpath performance.
1560 dnl #
1561 AC_DEFUN([SPL_AC_FS_STRUCT_SPINLOCK], [
1562 AC_MSG_CHECKING([whether struct fs_struct uses spinlock_t])
1563 SPL_LINUX_TRY_COMPILE([
1564 #include <linux/sched.h>
1565 #include <linux/fs_struct.h>
1566 ],[
1567 struct fs_struct fs;
1568 spin_lock_init(&fs.lock);
1569 ],[
1570 AC_MSG_RESULT(yes)
1571 AC_DEFINE(HAVE_FS_STRUCT_SPINLOCK, 1,
1572 [struct fs_struct uses spinlock_t])
1573 ],[
1574 AC_MSG_RESULT(no)
1575 ])
1576 ])
1577
1578 dnl #
1579 dnl # 2.6.29 API change,
1580 dnl # check whether 'struct cred' exists
1581 dnl #
1582 AC_DEFUN([SPL_AC_CRED_STRUCT], [
1583 AC_MSG_CHECKING([whether struct cred exists])
1584 SPL_LINUX_TRY_COMPILE([
1585 #include <linux/cred.h>
1586 ],[
1587 struct cred *cr;
1588 cr = NULL;
1589 ],[
1590 AC_MSG_RESULT(yes)
1591 AC_DEFINE(HAVE_CRED_STRUCT, 1, [struct cred exists])
1592 ],[
1593 AC_MSG_RESULT(no)
1594 ])
1595 ])
1596
1597 dnl #
1598 dnl # Custom SPL patch may export this symbol.
1599 dnl #
1600 AC_DEFUN([SPL_AC_GROUPS_SEARCH], [
1601 SPL_CHECK_SYMBOL_EXPORT(
1602 [groups_search],
1603 [],
1604 [AC_DEFINE(HAVE_GROUPS_SEARCH, 1,
1605 [groups_search() is available])],
1606 [])
1607 ])
1608
1609 dnl #
1610 dnl # 2.6.x API change,
1611 dnl # __put_task_struct() was exported in RHEL5 but unavailable elsewhere.
1612 dnl #
1613 AC_DEFUN([SPL_AC_PUT_TASK_STRUCT], [
1614 SPL_CHECK_SYMBOL_EXPORT(
1615 [__put_task_struct],
1616 [],
1617 [AC_DEFINE(HAVE_PUT_TASK_STRUCT, 1,
1618 [__put_task_struct() is available])],
1619 [])
1620 ])
1621
1622 dnl #
1623 dnl # 2.6.32 API change,
1624 dnl # Unused 'struct file *' removed from prototype.
1625 dnl #
1626 AC_DEFUN([SPL_AC_5ARGS_PROC_HANDLER], [
1627 AC_MSG_CHECKING([whether proc_handler() wants 5 args])
1628 SPL_LINUX_TRY_COMPILE([
1629 #include <linux/sysctl.h>
1630 ],[
1631 proc_dostring(NULL, 0, NULL, NULL, NULL);
1632 ],[
1633 AC_MSG_RESULT(yes)
1634 AC_DEFINE(HAVE_5ARGS_PROC_HANDLER, 1,
1635 [proc_handler() wants 5 args])
1636 ],[
1637 AC_MSG_RESULT(no)
1638 ])
1639 ])
1640
1641 dnl #
1642 dnl # 2.6.x API change,
1643 dnl # kvasprintf() function added.
1644 dnl #
1645 AC_DEFUN([SPL_AC_KVASPRINTF], [
1646 SPL_CHECK_SYMBOL_EXPORT(
1647 [kvasprintf],
1648 [],
1649 [AC_DEFINE(HAVE_KVASPRINTF, 1,
1650 [kvasprintf() is available])],
1651 [])
1652 ])
1653
1654 dnl #
1655 dnl # 2.6.35 API change,
1656 dnl # Unused 'struct dentry *' removed from prototype.
1657 dnl #
1658 AC_DEFUN([SPL_AC_3ARGS_FILE_FSYNC], [
1659 AC_MSG_CHECKING([whether file_fsync() wants 3 args])
1660 SPL_LINUX_TRY_COMPILE([
1661 #include <linux/buffer_head.h>
1662 ],[
1663 file_fsync(NULL, NULL, 0);
1664 ],[
1665 AC_MSG_RESULT(yes)
1666 AC_DEFINE(HAVE_3ARGS_FILE_FSYNC, 1,
1667 [file_fsync() wants 3 args])
1668 ],[
1669 AC_MSG_RESULT(no)
1670 ])
1671 ])
1672
1673 dnl #
1674 dnl # 2.6.33 API change. Also backported in RHEL5 as of 2.6.18-190.el5.
1675 dnl # Earlier versions of rwsem_is_locked() were inline and had a race
1676 dnl # condition. The fixed version is exported as a symbol. The race
1677 dnl # condition is fixed by acquiring sem->wait_lock, so we must not
1678 dnl # call that version while holding sem->wait_lock.
1679 dnl #
1680 AC_DEFUN([SPL_AC_EXPORTED_RWSEM_IS_LOCKED], [
1681 SPL_CHECK_SYMBOL_EXPORT(
1682 [rwsem_is_locked],
1683 [lib/rwsem-spinlock.c],
1684 [AC_DEFINE(RWSEM_IS_LOCKED_TAKES_WAIT_LOCK, 1,
1685 [rwsem_is_locked() acquires sem->wait_lock])],
1686 [])
1687 ])