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