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