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