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