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