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