]> git.proxmox.com Git - mirror_spl.git/blame - config/spl-build.m4
Add handling for kernel 4.7's CONFIG_TRIM_UNUSED_KSYMS
[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
21 SPL_AC_DEBUG_KMEM
055ffd98 22 SPL_AC_DEBUG_KMEM_TRACKING
0408008b 23 SPL_AC_TEST_MODULE
5e9b5d83 24 SPL_AC_ATOMIC_SPINLOCK
c3d9c0df 25 SPL_AC_SHRINKER_CALLBACK
79a3bf13 26 SPL_AC_CTL_NAME
4b9dddf4 27 SPL_AC_CONFIG_TRIM_UNUSED_KSYMS
1ddf9722 28 SPL_AC_PDE_DATA
a54718cf 29 SPL_AC_SET_FS_PWD_WITH_CONST
86933a6e
BB
30 SPL_AC_2ARGS_VFS_UNLINK
31 SPL_AC_4ARGS_VFS_RENAME
0d0b5237 32 SPL_AC_2ARGS_VFS_FSYNC
bbdc6ae4 33 SPL_AC_INODE_TRUNCATE_RANGE
9b2048c2 34 SPL_AC_FS_STRUCT_SPINLOCK
f7fd6ddd 35 SPL_AC_KUIDGID_T
e811949a 36 SPL_AC_PUT_TASK_STRUCT
1c7b3eaf 37 SPL_AC_KERNEL_FALLOCATE
42b3ce62
BB
38 SPL_AC_CONFIG_ZLIB_INFLATE
39 SPL_AC_CONFIG_ZLIB_DEFLATE
3dfc591a 40 SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE
a55bcaad 41 SPL_AC_SHRINK_CONTROL_STRUCT
588d9004 42 SPL_AC_RWSEM_SPINLOCK_IS_RAW
f58040c0 43 SPL_AC_RWSEM_ACTIVITY
b7c7008b 44 SPL_AC_RWSEM_ATOMIC_LONG_COUNT
10087fe1 45 SPL_AC_SCHED_RT_HEADER
2a305c34 46 SPL_AC_2ARGS_VFS_GETATTR
184c6873 47 SPL_AC_USLEEP_RANGE
a073aeb0 48 SPL_AC_KMEM_CACHE_ALLOCFLAGS
2fc44f66 49 SPL_AC_WAIT_ON_BIT
cdd39dd2 50 SPL_AC_MUTEX_OWNER
fdbc1ba9 51 SPL_AC_INODE_LOCK
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
8d9a23e8 223 RPM_DEFINE_COMMON='--define "$(DEBUG_SPL) 1" --define "$(DEBUG_KMEM) 1" --define "$(DEBUG_KMEM_TRACKING) 1"'
493972c8
BB
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],
fade6b00 236 [Spec files 'generic|redhat']),
493972c8
BB
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
055ffd98
BB
456dnl #
457dnl # Enabled by default it provides a minimal level of memory tracking.
458dnl # A total count of bytes allocated is kept for each alloc and free.
459dnl # Then at module unload time a report to the console will be printed
9eb361aa 460dnl # if memory was leaked.
055ffd98 461dnl #
57d86234 462AC_DEFUN([SPL_AC_DEBUG_KMEM], [
055ffd98
BB
463 AC_ARG_ENABLE([debug-kmem],
464 [AS_HELP_STRING([--enable-debug-kmem],
9eb361aa 465 [Enable basic kmem accounting @<:@default=no@:>@])],
055ffd98 466 [],
9eb361aa 467 [enable_debug_kmem=no])
57d86234 468
055ffd98 469 AS_IF([test "x$enable_debug_kmem" = xyes],
3c208a54
BB
470 [
471 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"
472 DEBUG_KMEM="_with_debug_kmem"
473 AC_DEFINE([DEBUG_KMEM], [1],
055ffd98 474 [Define to 1 to enable basic kmem accounting])
3c208a54
BB
475 ], [
476 DEBUG_KMEM="_without_debug_kmem"
477 ])
055ffd98 478
3c208a54 479 AC_SUBST(DEBUG_KMEM)
055ffd98
BB
480 AC_MSG_CHECKING([whether basic kmem accounting is enabled])
481 AC_MSG_RESULT([$enable_debug_kmem])
57d86234 482])
483
055ffd98
BB
484dnl #
485dnl # Disabled by default it provides detailed memory tracking. This
486dnl # feature also requires --enable-debug-kmem to be set. When enabled
487dnl # not only will total bytes be tracked but also the location of every
488dnl # alloc and free. When the SPL module is unloaded a list of all leaked
489dnl # addresses and where they were allocated will be dumped to the console.
490dnl # Enabling this feature has a significant impact on performance but it
491dnl # makes finding memory leaks pretty straight forward.
492dnl #
493AC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [
494 AC_ARG_ENABLE([debug-kmem-tracking],
495 [AS_HELP_STRING([--enable-debug-kmem-tracking],
496 [Enable detailed kmem tracking @<:@default=no@:>@])],
497 [],
498 [enable_debug_kmem_tracking=no])
499
500 AS_IF([test "x$enable_debug_kmem_tracking" = xyes],
3c208a54
BB
501 [
502 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM_TRACKING"
503 DEBUG_KMEM_TRACKING="_with_debug_kmem_tracking"
504 AC_DEFINE([DEBUG_KMEM_TRACKING], [1],
055ffd98 505 [Define to 1 to enable detailed kmem tracking])
3c208a54
BB
506 ], [
507 DEBUG_KMEM_TRACKING="_without_debug_kmem_tracking"
508 ])
055ffd98 509
3c208a54 510 AC_SUBST(DEBUG_KMEM_TRACKING)
055ffd98
BB
511 AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
512 AC_MSG_RESULT([$enable_debug_kmem_tracking])
57d86234 513])
514
515dnl #
516dnl # SPL_LINUX_CONFTEST
517dnl #
518AC_DEFUN([SPL_LINUX_CONFTEST], [
dbe561d8 519cat confdefs.h - <<_ACEOF >conftest.c
57d86234 520$1
521_ACEOF
522])
523
524dnl #
525dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
526dnl #
527m4_define([SPL_LANG_PROGRAM], [
528$1
529int
530main (void)
531{
532dnl Do *not* indent the following line: there may be CPP directives.
533dnl Don't move the `;' right after for the same reason.
534$2
535 ;
536 return 0;
537}
538])
539
540dnl #
541dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
542dnl #
543AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
c5f70460 544 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])
df7cc5bc 545 rm -Rf build && mkdir -p build && touch build/conftest.mod.c
c5f70460 546 echo "obj-m := conftest.o" >build/Makefile
df7cc5bc
ED
547 modpost_flag=''
548 test "x$enable_linux_builtin" = xyes && modpost_flag='modpost=true' # fake modpost stage
c5f70460 549 AS_IF(
df7cc5bc
ED
550 [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])],
551 [$4],
552 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
c5f70460
BB
553 )
554 rm -Rf build
57d86234 555])
556
557dnl #
558dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
559dnl #
560AC_DEFUN([SPL_LINUX_TRY_COMPILE],
561 [SPL_LINUX_COMPILE_IFELSE(
d50bd9e2 562 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
563 [modules],
564 [test -s build/conftest.o],
565 [$3], [$4])
57d86234 566])
567
57d86234 568dnl #
569dnl # SPL_CHECK_SYMBOL_EXPORT
570dnl # check symbol exported or not
571dnl #
723aa3b0 572AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT], [
2e0e7e69
BB
573 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
574 $LINUX_OBJ/Module*.symvers 2>/dev/null
57d86234 575 rc=$?
576 if test $rc -ne 0; then
577 export=0
578 for file in $2; do
2e0e7e69
BB
579 grep -q -E "EXPORT_SYMBOL.*($1)" \
580 "$LINUX_OBJ/$file" 2>/dev/null
57d86234 581 rc=$?
723aa3b0
ED
582 if test $rc -eq 0; then
583 export=1
584 break;
585 fi
57d86234 586 done
723aa3b0 587 if test $export -eq 0; then :
57d86234 588 $4
723aa3b0 589 else :
57d86234 590 $3
591 fi
723aa3b0 592 else :
57d86234 593 $3
594 fi
595])
596
723aa3b0
ED
597dnl #
598dnl # SPL_LINUX_TRY_COMPILE_SYMBOL
599dnl # like SPL_LINUX_TRY_COMPILE, except SPL_CHECK_SYMBOL_EXPORT
600dnl # is called if not compiling for builtin
601dnl #
602AC_DEFUN([SPL_LINUX_TRY_COMPILE_SYMBOL], [
603 SPL_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
604 if test $rc -ne 0; then :
605 $6
606 else
607 if test "x$enable_linux_builtin" != xyes; then
608 SPL_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
609 fi
610 if test $rc -ne 0; then :
611 $6
612 else :
613 $5
614 fi
615 fi
616])
617
12ff95ff
BB
618dnl #
619dnl # SPL_CHECK_SYMBOL_HEADER
620dnl # check if a symbol prototype is defined in listed headers.
621dnl #
622AC_DEFUN([SPL_CHECK_SYMBOL_HEADER], [
623 AC_MSG_CHECKING([whether symbol $1 exists in header])
624 header=0
625 for file in $3; do
626 grep -q "$2" "$LINUX/$file" 2>/dev/null
627 rc=$?
723aa3b0
ED
628 if test $rc -eq 0; then
629 header=1
630 break;
631 fi
12ff95ff
BB
632 done
633 if test $header -eq 0; then
634 AC_MSG_RESULT([no])
635 $5
636 else
637 AC_MSG_RESULT([yes])
638 $4
639 fi
640])
641
86de8532 642dnl #
643dnl # SPL_CHECK_HEADER
644dnl # check whether header exists and define HAVE_$2_HEADER
645dnl #
646AC_DEFUN([SPL_CHECK_HEADER],
647 [AC_MSG_CHECKING([whether header $1 exists])
648 SPL_LINUX_TRY_COMPILE([
d50bd9e2 649 #include <$1>
86de8532 650 ],[
651 return 0;
652 ],[
653 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
654 AC_MSG_RESULT(yes)
655 $3
656 ],[
657 AC_MSG_RESULT(no)
658 $4
659 ])
660])
6a6cafbe 661
0408008b 662dnl #
62032954
BB
663dnl # Basic toolchain sanity check. Verify that kernel modules can
664dnl # be built and which symbols can be used.
0408008b
ED
665dnl #
666AC_DEFUN([SPL_AC_TEST_MODULE],
667 [AC_MSG_CHECKING([whether modules can be built])
668 SPL_LINUX_TRY_COMPILE([],[],[
669 AC_MSG_RESULT([yes])
670 ],[
671 AC_MSG_RESULT([no])
672 if test "x$enable_linux_builtin" != xyes; then
673 AC_MSG_ERROR([*** Unable to build an empty module.])
674 else
675 AC_MSG_ERROR([
676 *** Unable to build an empty module.
677 *** Please run 'make scripts' inside the kernel source tree.])
678 fi
679 ])
62032954 680
e0ed96fa
KD
681 AS_IF([test "x$cross_compiling" != xyes], [
682 AC_RUN_IFELSE([
683 AC_LANG_PROGRAM([
684 #include "$LINUX/include/linux/license.h"
685 ], [
686 return !license_is_gpl_compatible(
687 "$SPL_META_LICENSE");
688 ])
689 ], [
690 AC_DEFINE([SPL_IS_GPL_COMPATIBLE], [1],
691 [Define to 1 if GPL-only symbols can be used])
62032954 692 ], [
62032954 693 ])
62032954 694 ])
0408008b
ED
695])
696
57d86234 697dnl #
d04c8a56
BB
698dnl # Use the atomic implemenation based on global spinlocks. This
699dnl # should only be needed by 32-bit kernels which do not provide
700dnl # the atomic64_* API. It may be optionally enabled as a fallback
701dnl # if problems are observed with the direct mapping to the native
702dnl # Linux atomic operations. You may not disable atomic spinlocks
703dnl # if you kernel does not an atomic64_* API.
57d86234 704dnl #
d04c8a56
BB
705AC_DEFUN([SPL_AC_ATOMIC_SPINLOCK], [
706 AC_ARG_ENABLE([atomic-spinlocks],
707 [AS_HELP_STRING([--enable-atomic-spinlocks],
708 [Atomic types use spinlocks @<:@default=check@:>@])],
709 [],
710 [enable_atomic_spinlocks=check])
57d86234 711
a0f6da3d 712 SPL_LINUX_TRY_COMPILE([
dd3678fc 713 #include <linux/fs.h>
a0f6da3d 714 ],[
03318641 715 atomic64_t *ptr __attribute__ ((unused));
a0f6da3d 716 ],[
d04c8a56 717 have_atomic64_t=yes
a0f6da3d 718 AC_DEFINE(HAVE_ATOMIC64_T, 1,
d04c8a56 719 [kernel defines atomic64_t])
a0f6da3d 720 ],[
d04c8a56
BB
721 have_atomic64_t=no
722 ])
723
724 AS_IF([test "x$enable_atomic_spinlocks" = xcheck], [
725 AS_IF([test "x$have_atomic64_t" = xyes], [
726 enable_atomic_spinlocks=no
727 ],[
728 enable_atomic_spinlocks=yes
729 ])
a0f6da3d 730 ])
d04c8a56
BB
731
732 AS_IF([test "x$enable_atomic_spinlocks" = xyes], [
733 AC_DEFINE([ATOMIC_SPINLOCK], [1],
734 [Atomic types use spinlocks])
735 ],[
736 AS_IF([test "x$have_atomic64_t" = xno], [
737 AC_MSG_FAILURE(
738 [--disable-atomic-spinlocks given but required atomic64 support is unavailable])
739 ])
740 ])
741
742 AC_MSG_CHECKING([whether atomic types use spinlocks])
743 AC_MSG_RESULT([$enable_atomic_spinlocks])
744
745 AC_MSG_CHECKING([whether kernel defines atomic64_t])
746 AC_MSG_RESULT([$have_atomic64_t])
a0f6da3d 747])
748
c3d9c0df 749AC_DEFUN([SPL_AC_SHRINKER_CALLBACK],[
23aa63cb
BB
750 tmp_flags="$EXTRA_KCFLAGS"
751 EXTRA_KCFLAGS="-Werror"
c3d9c0df
RY
752 dnl #
753 dnl # 2.6.23 to 2.6.34 API change
754 dnl # ->shrink(int nr_to_scan, gfp_t gfp_mask)
755 dnl #
756 AC_MSG_CHECKING([whether old 2-argument shrinker exists])
23aa63cb
BB
757 SPL_LINUX_TRY_COMPILE([
758 #include <linux/mm.h>
759
c3d9c0df 760 int shrinker_cb(int nr_to_scan, gfp_t gfp_mask);
23aa63cb
BB
761 ],[
762 struct shrinker cache_shrinker = {
763 .shrink = shrinker_cb,
764 .seeks = DEFAULT_SEEKS,
765 };
766 register_shrinker(&cache_shrinker);
767 ],[
768 AC_MSG_RESULT(yes)
c3d9c0df
RY
769 AC_DEFINE(HAVE_2ARGS_OLD_SHRINKER_CALLBACK, 1,
770 [old shrinker callback wants 2 args])
23aa63cb
BB
771 ],[
772 AC_MSG_RESULT(no)
c3d9c0df
RY
773 dnl #
774 dnl # 2.6.35 - 2.6.39 API change
775 dnl # ->shrink(struct shrinker *,
776 dnl # int nr_to_scan, gfp_t gfp_mask)
777 dnl #
778 AC_MSG_CHECKING([whether old 3-argument shrinker exists])
779 SPL_LINUX_TRY_COMPILE([
780 #include <linux/mm.h>
781
782 int shrinker_cb(struct shrinker *, int nr_to_scan,
783 gfp_t gfp_mask);
784 ],[
785 struct shrinker cache_shrinker = {
786 .shrink = shrinker_cb,
787 .seeks = DEFAULT_SEEKS,
788 };
789 register_shrinker(&cache_shrinker);
790 ],[
791 AC_MSG_RESULT(yes)
792 AC_DEFINE(HAVE_3ARGS_SHRINKER_CALLBACK, 1,
793 [old shrinker callback wants 3 args])
794 ],[
795 AC_MSG_RESULT(no)
796 dnl #
797 dnl # 3.0 - 3.11 API change
798 dnl # ->shrink(struct shrinker *,
799 dnl # struct shrink_control *sc)
800 dnl #
801 AC_MSG_CHECKING(
802 [whether new 2-argument shrinker exists])
803 SPL_LINUX_TRY_COMPILE([
804 #include <linux/mm.h>
805
806 int shrinker_cb(struct shrinker *,
807 struct shrink_control *sc);
808 ],[
809 struct shrinker cache_shrinker = {
810 .shrink = shrinker_cb,
811 .seeks = DEFAULT_SEEKS,
812 };
813 register_shrinker(&cache_shrinker);
814 ],[
815 AC_MSG_RESULT(yes)
816 AC_DEFINE(HAVE_2ARGS_NEW_SHRINKER_CALLBACK, 1,
817 [new shrinker callback wants 2 args])
818 ],[
819 AC_MSG_RESULT(no)
820 dnl #
821 dnl # 3.12 API change,
822 dnl # ->shrink() is logically split in to
823 dnl # ->count_objects() and ->scan_objects()
824 dnl #
825 AC_MSG_CHECKING(
826 [whether ->count_objects callback exists])
827 SPL_LINUX_TRY_COMPILE([
828 #include <linux/mm.h>
829
830 unsigned long shrinker_cb(
831 struct shrinker *,
832 struct shrink_control *sc);
833 ],[
834 struct shrinker cache_shrinker = {
835 .count_objects = shrinker_cb,
836 .scan_objects = shrinker_cb,
837 .seeks = DEFAULT_SEEKS,
838 };
839 register_shrinker(&cache_shrinker);
840 ],[
841 AC_MSG_RESULT(yes)
842 AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK,
843 1, [->count_objects exists])
844 ],[
845 AC_MSG_ERROR(error)
846 ])
847 ])
848 ])
23aa63cb
BB
849 ])
850 EXTRA_KCFLAGS="$tmp_flags"
851])
852
79a3bf13
BB
853dnl #
854dnl # 2.6.33 API change,
855dnl # Removed .ctl_name from struct ctl_table.
856dnl #
857AC_DEFUN([SPL_AC_CTL_NAME], [
858 AC_MSG_CHECKING([whether struct ctl_table has ctl_name])
859 SPL_LINUX_TRY_COMPILE([
860 #include <linux/sysctl.h>
861 ],[
03318641 862 struct ctl_table ctl __attribute__ ((unused));
79a3bf13
BB
863 ctl.ctl_name = 0;
864 ],[
865 AC_MSG_RESULT(yes)
866 AC_DEFINE(HAVE_CTL_NAME, 1, [struct ctl_table has ctl_name])
867 ],[
868 AC_MSG_RESULT(no)
869 ])
870])
871
1ddf9722
YS
872dnl #
873dnl # 3.10 API change,
874dnl # PDE is replaced by PDE_DATA
875dnl #
876AC_DEFUN([SPL_AC_PDE_DATA], [
877 AC_MSG_CHECKING([whether PDE_DATA() is available])
878 SPL_LINUX_TRY_COMPILE_SYMBOL([
879 #include <linux/proc_fs.h>
880 ], [
881 PDE_DATA(NULL);
882 ], [PDE_DATA], [], [
883 AC_MSG_RESULT(yes)
884 AC_DEFINE(HAVE_PDE_DATA, 1, [yes])
885 ],[
886 AC_MSG_RESULT(no)
887 ])
888])
889
a54718cf
RY
890dnl #
891dnl # 3.9 API change
892dnl # set_fs_pwd takes const struct path *
893dnl #
894AC_DEFUN([SPL_AC_SET_FS_PWD_WITH_CONST],
a54718cf
RY
895 tmp_flags="$EXTRA_KCFLAGS"
896 EXTRA_KCFLAGS="-Werror"
897 [AC_MSG_CHECKING([whether set_fs_pwd() requires const struct path *])
898 SPL_LINUX_TRY_COMPILE([
899 #include <linux/spinlock.h>
900 #include <linux/fs_struct.h>
901 #include <linux/path.h>
902 void (*const set_fs_pwd_func)
903 (struct fs_struct *, const struct path *)
904 = set_fs_pwd;
905 ],[
906 return 0;
907 ],[
908 AC_MSG_RESULT(yes)
909 AC_DEFINE(HAVE_SET_FS_PWD_WITH_CONST, 1,
910 [set_fs_pwd() needs const path *])
911 ],[
912 SPL_LINUX_TRY_COMPILE([
913 #include <linux/spinlock.h>
914 #include <linux/fs_struct.h>
915 #include <linux/path.h>
916 void (*const set_fs_pwd_func)
917 (struct fs_struct *, struct path *)
918 = set_fs_pwd;
919 ],[
920 return 0;
921 ],[
922 AC_MSG_RESULT(no)
923 ],[
924 AC_MSG_ERROR(unknown)
925 ])
926 ])
927 EXTRA_KCFLAGS="$tmp_flags"
a54718cf
RY
928])
929
e39174ed
BB
930dnl #
931dnl # 3.13 API change
932dnl # vfs_unlink() updated to take a third delegated_inode argument.
933dnl #
a093c6a4
BB
934AC_DEFUN([SPL_AC_2ARGS_VFS_UNLINK],
935 [AC_MSG_CHECKING([whether vfs_unlink() wants 2 args])
936 SPL_LINUX_TRY_COMPILE([
937 #include <linux/fs.h>
938 ],[
50a0749e 939 vfs_unlink((struct inode *) NULL, (struct dentry *) NULL);
a093c6a4
BB
940 ],[
941 AC_MSG_RESULT(yes)
942 AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
943 [vfs_unlink() wants 2 args])
944 ],[
945 AC_MSG_RESULT(no)
50a0749e
RY
946 dnl #
947 dnl # Linux 3.13 API change
948 dnl # Added delegated inode
949 dnl #
950 AC_MSG_CHECKING([whether vfs_unlink() wants 3 args])
951 SPL_LINUX_TRY_COMPILE([
952 #include <linux/fs.h>
953 ],[
954 vfs_unlink((struct inode *) NULL,
955 (struct dentry *) NULL,
956 (struct inode **) NULL);
957 ],[
958 AC_MSG_RESULT(yes)
959 AC_DEFINE(HAVE_3ARGS_VFS_UNLINK, 1,
960 [vfs_unlink() wants 3 args])
961 ],[
962 AC_MSG_ERROR(no)
963 ])
964
a093c6a4
BB
965 ])
966])
967
e39174ed
BB
968dnl #
969dnl # 3.13 and 3.15 API changes
970dnl # Added delegated inode and flags argument.
971dnl #
a093c6a4
BB
972AC_DEFUN([SPL_AC_4ARGS_VFS_RENAME],
973 [AC_MSG_CHECKING([whether vfs_rename() wants 4 args])
974 SPL_LINUX_TRY_COMPILE([
975 #include <linux/fs.h>
976 ],[
50a0749e
RY
977 vfs_rename((struct inode *) NULL, (struct dentry *) NULL,
978 (struct inode *) NULL, (struct dentry *) NULL);
a093c6a4
BB
979 ],[
980 AC_MSG_RESULT(yes)
981 AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
982 [vfs_rename() wants 4 args])
983 ],[
984 AC_MSG_RESULT(no)
50a0749e
RY
985 dnl #
986 dnl # Linux 3.13 API change
987 dnl # Added delegated inode
988 dnl #
989 AC_MSG_CHECKING([whether vfs_rename() wants 5 args])
990 SPL_LINUX_TRY_COMPILE([
991 #include <linux/fs.h>
992 ],[
993 vfs_rename((struct inode *) NULL,
994 (struct dentry *) NULL,
995 (struct inode *) NULL,
996 (struct dentry *) NULL,
997 (struct inode **) NULL);
998 ],[
999 AC_MSG_RESULT(yes)
1000 AC_DEFINE(HAVE_5ARGS_VFS_RENAME, 1,
1001 [vfs_rename() wants 5 args])
1002 ],[
ad3412ef
CC
1003 AC_MSG_RESULT(no)
1004 dnl #
1005 dnl # Linux 3.15 API change
1006 dnl # Added flags
1007 dnl #
1008 AC_MSG_CHECKING([whether vfs_rename() wants 6 args])
1009 SPL_LINUX_TRY_COMPILE([
1010 #include <linux/fs.h>
1011 ],[
1012 vfs_rename((struct inode *) NULL,
1013 (struct dentry *) NULL,
1014 (struct inode *) NULL,
1015 (struct dentry *) NULL,
1016 (struct inode **) NULL,
1017 (unsigned int) 0);
1018 ],[
1019 AC_MSG_RESULT(yes)
1020 AC_DEFINE(HAVE_6ARGS_VFS_RENAME, 1,
1021 [vfs_rename() wants 6 args])
1022 ],[
1023 AC_MSG_ERROR(no)
1024 ])
50a0749e 1025 ])
a093c6a4
BB
1026 ])
1027])
ec7d53e9 1028
9b2048c2
BB
1029dnl #
1030dnl # 2.6.36 API change,
1031dnl # The 'struct fs_struct->lock' was changed from a rwlock_t to
1032dnl # a spinlock_t to improve the fastpath performance.
1033dnl #
1034AC_DEFUN([SPL_AC_FS_STRUCT_SPINLOCK], [
1035 AC_MSG_CHECKING([whether struct fs_struct uses spinlock_t])
97fd6a07
BB
1036 tmp_flags="$EXTRA_KCFLAGS"
1037 EXTRA_KCFLAGS="-Werror"
9b2048c2
BB
1038 SPL_LINUX_TRY_COMPILE([
1039 #include <linux/sched.h>
1040 #include <linux/fs_struct.h>
1041 ],[
abb642b9 1042 static struct fs_struct fs;
9b2048c2
BB
1043 spin_lock_init(&fs.lock);
1044 ],[
1045 AC_MSG_RESULT(yes)
1046 AC_DEFINE(HAVE_FS_STRUCT_SPINLOCK, 1,
1047 [struct fs_struct uses spinlock_t])
1048 ],[
1049 AC_MSG_RESULT(no)
1050 ])
97fd6a07 1051 EXTRA_KCFLAGS="$tmp_flags"
9b2048c2
BB
1052])
1053
f7fd6ddd
RY
1054dnl #
1055dnl # User namespaces, use kuid_t in place of uid_t
1056dnl # where available. Not strictly a user namespaces thing
1057dnl # but it should prevent surprises
1058dnl #
1059AC_DEFUN([SPL_AC_KUIDGID_T], [
1060 AC_MSG_CHECKING([whether kuid_t/kgid_t is available])
1061 SPL_LINUX_TRY_COMPILE([
1062 #include <linux/uidgid.h>
1063 ], [
1064 kuid_t userid = KUIDT_INIT(0);
1065 kgid_t groupid = KGIDT_INIT(0);
1066 ],[
1067 SPL_LINUX_TRY_COMPILE([
1068 #include <linux/uidgid.h>
1069 ], [
1070 kuid_t userid = 0;
1071 kgid_t groupid = 0;
1072 ],[
1073 AC_MSG_RESULT(yes; optional)
1074 ],[
1075 AC_MSG_RESULT(yes; mandatory)
1076 AC_DEFINE(HAVE_KUIDGID_T, 1, [kuid_t/kgid_t in use])
1077 ])
1078 ],[
1079 AC_MSG_RESULT(no)
1080 ])
1081])
1082
e811949a 1083dnl #
e03119e8
BB
1084dnl # 2.6.39 API change,
1085dnl # __put_task_struct() was exported by the mainline kernel.
e811949a 1086dnl #
723aa3b0
ED
1087AC_DEFUN([SPL_AC_PUT_TASK_STRUCT],
1088 [AC_MSG_CHECKING([whether __put_task_struct() is available])
1089 SPL_LINUX_TRY_COMPILE_SYMBOL([
1090 #include <linux/sched.h>
1091 ], [
1092 __put_task_struct(NULL);
1093 ], [__put_task_struct], [], [
1094 AC_MSG_RESULT(yes)
1095 AC_DEFINE(HAVE_PUT_TASK_STRUCT, 1,
1096 [__put_task_struct() is available])
1097 ], [
1098 AC_MSG_RESULT(no)
1099 ])
e811949a 1100])
3977f837 1101
f0ff89fc
BB
1102dnl #
1103dnl # 2.6.35 API change,
0d0b5237 1104dnl # Unused 'struct dentry *' removed from vfs_fsync() prototype.
f0ff89fc 1105dnl #
0d0b5237
BB
1106AC_DEFUN([SPL_AC_2ARGS_VFS_FSYNC], [
1107 AC_MSG_CHECKING([whether vfs_fsync() wants 2 args])
f0ff89fc 1108 SPL_LINUX_TRY_COMPILE([
0d0b5237 1109 #include <linux/fs.h>
f0ff89fc 1110 ],[
0d0b5237 1111 vfs_fsync(NULL, 0);
f0ff89fc
BB
1112 ],[
1113 AC_MSG_RESULT(yes)
0d0b5237 1114 AC_DEFINE(HAVE_2ARGS_VFS_FSYNC, 1, [vfs_fsync() wants 2 args])
f0ff89fc
BB
1115 ],[
1116 AC_MSG_RESULT(no)
1117 ])
1118])
46aa7b39 1119
bbdc6ae4
ED
1120dnl #
1121dnl # 3.5 API change,
1122dnl # inode_operations.truncate_range removed
bbdc6ae4
ED
1123dnl #
1124AC_DEFUN([SPL_AC_INODE_TRUNCATE_RANGE], [
1125 AC_MSG_CHECKING([whether truncate_range() inode operation is available])
1126 SPL_LINUX_TRY_COMPILE([
1127 #include <linux/fs.h>
1128 ],[
1129 struct inode_operations ops;
1130 ops.truncate_range = NULL;
1131 ],[
1132 AC_MSG_RESULT(yes)
1133 AC_DEFINE(HAVE_INODE_TRUNCATE_RANGE, 1,
1134 [truncate_range() inode operation is available])
1135 ],[
1136 AC_MSG_RESULT(no)
1137 ])
1c7b3eaf
BB
1138])
1139
1140dnl #
1141dnl # Linux 2.6.38 - 3.x API
1142dnl #
1143AC_DEFUN([SPL_AC_KERNEL_FILE_FALLOCATE], [
1144 AC_MSG_CHECKING([whether fops->fallocate() exists])
1145 SPL_LINUX_TRY_COMPILE([
1146 #include <linux/fs.h>
1147 ],[
1148 long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
1149 struct file_operations fops __attribute__ ((unused)) = {
1150 .fallocate = fallocate,
1151 };
1152 ],[
1153 AC_MSG_RESULT(yes)
1154 AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
1155 ],[
1156 AC_MSG_RESULT(no)
1157 ])
1158])
1159
1160dnl #
1161dnl # Linux 2.6.x - 2.6.37 API
1162dnl #
1163AC_DEFUN([SPL_AC_KERNEL_INODE_FALLOCATE], [
1164 AC_MSG_CHECKING([whether iops->fallocate() exists])
1165 SPL_LINUX_TRY_COMPILE([
1166 #include <linux/fs.h>
1167 ],[
1168 long (*fallocate) (struct inode *, int, loff_t, loff_t) = NULL;
1169 struct inode_operations fops __attribute__ ((unused)) = {
1170 .fallocate = fallocate,
1171 };
1172 ],[
1173 AC_MSG_RESULT(yes)
1174 AC_DEFINE(HAVE_INODE_FALLOCATE, 1, [fops->fallocate() exists])
1175 ],[
1176 AC_MSG_RESULT(no)
1177 ])
1178])
1179
1180dnl #
1181dnl # PaX Linux 2.6.38 - 3.x API
1182dnl #
1183AC_DEFUN([SPL_AC_PAX_KERNEL_FILE_FALLOCATE], [
1184 AC_MSG_CHECKING([whether fops->fallocate() exists])
1185 SPL_LINUX_TRY_COMPILE([
1186 #include <linux/fs.h>
1187 ],[
1188 long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
1189 struct file_operations_no_const fops __attribute__ ((unused)) = {
1190 .fallocate = fallocate,
1191 };
1192 ],[
1193 AC_MSG_RESULT(yes)
1194 AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
1195 ],[
1196 AC_MSG_RESULT(no)
1197 ])
1198])
1199
1200dnl #
1201dnl # The fallocate callback was moved from the inode_operations
1202dnl # structure to the file_operations structure.
1203dnl #
1204AC_DEFUN([SPL_AC_KERNEL_FALLOCATE], [
1205 SPL_AC_KERNEL_FILE_FALLOCATE
1206 SPL_AC_KERNEL_INODE_FALLOCATE
1207 SPL_AC_PAX_KERNEL_FILE_FALLOCATE
1208])
bbdc6ae4 1209
42b3ce62
BB
1210dnl #
1211dnl # zlib inflate compat,
1212dnl # Verify the kernel has CONFIG_ZLIB_INFLATE support enabled.
1213dnl #
1214AC_DEFUN([SPL_AC_CONFIG_ZLIB_INFLATE], [
1215 AC_MSG_CHECKING([whether CONFIG_ZLIB_INFLATE is defined])
1216 SPL_LINUX_TRY_COMPILE([
1217 #if !defined(CONFIG_ZLIB_INFLATE) && \
1218 !defined(CONFIG_ZLIB_INFLATE_MODULE)
1219 #error CONFIG_ZLIB_INFLATE not defined
1220 #endif
1221 ],[ ],[
1222 AC_MSG_RESULT([yes])
1223 ],[
1224 AC_MSG_RESULT([no])
1225 AC_MSG_ERROR([
1226 *** This kernel does not include the required zlib inflate support.
1227 *** Rebuild the kernel with CONFIG_ZLIB_INFLATE=y|m set.])
1228 ])
1229])
1230
1231dnl #
1232dnl # zlib deflate compat,
1233dnl # Verify the kernel has CONFIG_ZLIB_DEFLATE support enabled.
1234dnl #
1235AC_DEFUN([SPL_AC_CONFIG_ZLIB_DEFLATE], [
1236 AC_MSG_CHECKING([whether CONFIG_ZLIB_DEFLATE is defined])
1237 SPL_LINUX_TRY_COMPILE([
1238 #if !defined(CONFIG_ZLIB_DEFLATE) && \
1239 !defined(CONFIG_ZLIB_DEFLATE_MODULE)
1240 #error CONFIG_ZLIB_DEFLATE not defined
1241 #endif
1242 ],[ ],[
1243 AC_MSG_RESULT([yes])
1244 ],[
1245 AC_MSG_RESULT([no])
1246 AC_MSG_ERROR([
1247 *** This kernel does not include the required zlib deflate support.
1248 *** Rebuild the kernel with CONFIG_ZLIB_DEFLATE=y|m set.])
1249 ])
1250])
1251
4b9dddf4
NB
1252dnl #
1253dnl # config trim unused symbols,
1254dnl # Verify the kernel has CONFIG_TRIM_UNUSED_KSYMS DISABLED.
1255dnl #
1256AC_DEFUN([SPL_AC_CONFIG_TRIM_UNUSED_KSYMS], [
1257 AC_MSG_CHECKING([whether CONFIG_TRIM_UNUSED_KSYM is disabled])
1258 SPL_LINUX_TRY_COMPILE([
1259 #if defined(CONFIG_TRIM_UNUSED_KSYMS)
1260 #error CONFIG_TRIM_UNUSED_KSYMS not defined
1261 #endif
1262 ],[ ],[
1263 AC_MSG_RESULT([yes])
1264 ],[
1265 AC_MSG_RESULT([no])
1266 AC_MSG_ERROR([
1267 *** This kernel has unused symbols trimming enabled, please disable.
1268 *** Rebuild the kernel with CONFIG_TRIM_UNUSED_KSYMS=n set.])
1269 ])
1270])
1271
3dfc591a
BB
1272dnl #
1273dnl # 2.6.39 API compat,
1274dnl # The function zlib_deflate_workspacesize() now take 2 arguments.
1275dnl # This was done to avoid always having to allocate the maximum size
1276dnl # workspace (268K). The caller can now specific the windowBits and
1277dnl # memLevel compression parameters to get a smaller workspace.
1278dnl #
1279AC_DEFUN([SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE],
1280 [AC_MSG_CHECKING([whether zlib_deflate_workspacesize() wants 2 args])
1281 SPL_LINUX_TRY_COMPILE([
1282 #include <linux/zlib.h>
1283 ],[
1284 return zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL);
1285 ],[
1286 AC_MSG_RESULT(yes)
1287 AC_DEFINE(HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE, 1,
1288 [zlib_deflate_workspacesize() wants 2 args])
1289 ],[
1290 AC_MSG_RESULT(no)
1291 ])
1292])
a55bcaad
BB
1293
1294dnl #
1295dnl # 2.6.39 API change,
1296dnl # Shrinker adjust to use common shrink_control structure.
1297dnl #
1298AC_DEFUN([SPL_AC_SHRINK_CONTROL_STRUCT], [
1299 AC_MSG_CHECKING([whether struct shrink_control exists])
1300 SPL_LINUX_TRY_COMPILE([
1301 #include <linux/mm.h>
1302 ],[
1303 struct shrink_control sc __attribute__ ((unused));
1304
1305 sc.nr_to_scan = 0;
1306 sc.gfp_mask = GFP_KERNEL;
1307 ],[
1308 AC_MSG_RESULT(yes)
1309 AC_DEFINE(HAVE_SHRINK_CONTROL_STRUCT, 1,
1310 [struct shrink_control exists])
1311 ],[
1312 AC_MSG_RESULT(no)
1313 ])
1314])
588d9004
DH
1315
1316dnl #
1317dnl # 3.1 API Change
1318dnl #
1319dnl # The rw_semaphore.wait_lock member was changed from spinlock_t to
1320dnl # raw_spinlock_t at commit ddb6c9b58a19edcfac93ac670b066c836ff729f1.
1321dnl #
1322AC_DEFUN([SPL_AC_RWSEM_SPINLOCK_IS_RAW], [
1323 AC_MSG_CHECKING([whether struct rw_semaphore member wait_lock is raw])
1324 tmp_flags="$EXTRA_KCFLAGS"
1325 EXTRA_KCFLAGS="-Werror"
1326 SPL_LINUX_TRY_COMPILE([
1327 #include <linux/rwsem.h>
1328 ],[
1329 struct rw_semaphore dummy_semaphore __attribute__ ((unused));
1330 raw_spinlock_t dummy_lock __attribute__ ((unused));
1331 dummy_semaphore.wait_lock = dummy_lock;
1332 ],[
1333 AC_MSG_RESULT(yes)
1334 AC_DEFINE(RWSEM_SPINLOCK_IS_RAW, 1,
1335 [struct rw_semaphore member wait_lock is raw_spinlock_t])
1336 ],[
1337 AC_MSG_RESULT(no)
1338 ])
1339 EXTRA_KCFLAGS="$tmp_flags"
1340])
10087fe1 1341
f58040c0
CC
1342dnl #
1343dnl # 3.16 API Change
1344dnl #
1345dnl # rwsem-spinlock "->activity" changed to "->count"
1346dnl #
1347AC_DEFUN([SPL_AC_RWSEM_ACTIVITY], [
1348 AC_MSG_CHECKING([whether struct rw_semaphore has member activity])
1349 tmp_flags="$EXTRA_KCFLAGS"
1350 EXTRA_KCFLAGS="-Werror"
1351 SPL_LINUX_TRY_COMPILE([
1352 #include <linux/rwsem.h>
1353 ],[
1354 struct rw_semaphore dummy_semaphore __attribute__ ((unused));
1355 dummy_semaphore.activity = 0;
1356 ],[
1357 AC_MSG_RESULT(yes)
1358 AC_DEFINE(HAVE_RWSEM_ACTIVITY, 1,
1359 [struct rw_semaphore has member activity])
1360 ],[
1361 AC_MSG_RESULT(no)
1362 ])
1363 EXTRA_KCFLAGS="$tmp_flags"
1364])
1365
b7c7008b
BB
1366dnl #
1367dnl # 4.8 API Change
1368dnl #
1369dnl # rwsem "->count" changed to atomic_long_t type
1370dnl #
1371AC_DEFUN([SPL_AC_RWSEM_ATOMIC_LONG_COUNT], [
1372 AC_MSG_CHECKING(
1373 [whether struct rw_semaphore has atomic_long_t member count])
1374 tmp_flags="$EXTRA_KCFLAGS"
1375 EXTRA_KCFLAGS="-Werror"
1376 SPL_LINUX_TRY_COMPILE([
1377 #include <linux/rwsem.h>
1378 ],[
1379 DECLARE_RWSEM(dummy_semaphore);
1380 (void) atomic_long_read(&dummy_semaphore.count);
1381 ],[
1382 AC_MSG_RESULT(yes)
1383 AC_DEFINE(HAVE_RWSEM_ATOMIC_LONG_COUNT, 1,
1384 [struct rw_semaphore has atomic_long_t member count])
1385 ],[
1386 AC_MSG_RESULT(no)
1387 ])
1388 EXTRA_KCFLAGS="$tmp_flags"
1389])
1390
10087fe1
RY
1391dnl #
1392dnl # 3.9 API change,
1393dnl # Moved things from linux/sched.h to linux/sched/rt.h
1394dnl #
1395AC_DEFUN([SPL_AC_SCHED_RT_HEADER],
1396 [AC_MSG_CHECKING([whether header linux/sched/rt.h exists])
1397 SPL_LINUX_TRY_COMPILE([
1398 #include <linux/sched.h>
1399 #include <linux/sched/rt.h>
1400 ],[
1401 return 0;
1402 ],[
1403 AC_DEFINE(HAVE_SCHED_RT_HEADER, 1, [linux/sched/rt.h exists])
1404 AC_MSG_RESULT(yes)
1405 ],[
1406 AC_MSG_RESULT(no)
1407 ])
1408])
2a305c34
RY
1409
1410dnl #
1411dnl # 3.9 API change,
1412dnl # vfs_getattr() uses 2 args
1413dnl # It takes struct path * instead of struct vfsmount * and struct dentry *
1414dnl #
1415AC_DEFUN([SPL_AC_2ARGS_VFS_GETATTR], [
1416 AC_MSG_CHECKING([whether vfs_getattr() wants])
1417 SPL_LINUX_TRY_COMPILE([
1418 #include <linux/fs.h>
1419 ],[
1420 vfs_getattr((struct path *) NULL,
1421 (struct kstat *)NULL);
1422 ],[
1423 AC_MSG_RESULT(2 args)
1424 AC_DEFINE(HAVE_2ARGS_VFS_GETATTR, 1,
1425 [vfs_getattr wants 2 args])
1426 ],[
1427 SPL_LINUX_TRY_COMPILE([
1428 #include <linux/fs.h>
1429 ],[
1430 vfs_getattr((struct vfsmount *)NULL,
1431 (struct dentry *)NULL,
1432 (struct kstat *)NULL);
1433 ],[
1434 AC_MSG_RESULT(3 args)
1435 ],[
1436 AC_MSG_ERROR(unknown)
1437 ])
1438 ])
1439])
184c6873
NB
1440
1441dnl #
1442dnl # 2.6.36 API compatibility.
1443dnl # Added usleep_range timer.
1444dnl # usleep_range is a finer precision implementation of msleep
1445dnl # designed to be a drop-in replacement for udelay where a precise
1446dnl # sleep / busy-wait is unnecessary.
1447dnl #
1448AC_DEFUN([SPL_AC_USLEEP_RANGE], [
1449 AC_MSG_CHECKING([whether usleep_range() is available])
1450 SPL_LINUX_TRY_COMPILE([
1451 #include <linux/delay.h>
1452 ],[
1453 usleep_range(0, 0);
1454 ],[
1455 AC_MSG_RESULT(yes)
1456 AC_DEFINE(HAVE_USLEEP_RANGE, 1,
1457 [usleep_range is available])
1458 ],[
1459 AC_MSG_RESULT(no)
1460 ])
1461])
a073aeb0
BB
1462
1463dnl #
1464dnl # 2.6.35 API change,
1465dnl # The cachep->gfpflags member was renamed cachep->allocflags. These are
1466dnl # private allocation flags which are applied when allocating a new slab
1467dnl # in kmem_getpages(). Unfortunately there is no public API for setting
1468dnl # non-default flags.
1469dnl #
1470AC_DEFUN([SPL_AC_KMEM_CACHE_ALLOCFLAGS], [
1471 AC_MSG_CHECKING([whether struct kmem_cache has allocflags])
1472 SPL_LINUX_TRY_COMPILE([
1473 #include <linux/slab.h>
1474 ],[
1475 struct kmem_cache cachep __attribute__ ((unused));
1476 cachep.allocflags = GFP_KERNEL;
1477 ],[
1478 AC_MSG_RESULT(yes)
1479 AC_DEFINE(HAVE_KMEM_CACHE_ALLOCFLAGS, 1,
1480 [struct kmem_cache has allocflags])
1481 ],[
1482 AC_MSG_RESULT(no)
1483
1484 AC_MSG_CHECKING([whether struct kmem_cache has gfpflags])
1485 SPL_LINUX_TRY_COMPILE([
1486 #include <linux/slab.h>
1487 ],[
1488 struct kmem_cache cachep __attribute__ ((unused));
1489 cachep.gfpflags = GFP_KERNEL;
1490 ],[
1491 AC_MSG_RESULT(yes)
1492 AC_DEFINE(HAVE_KMEM_CACHE_GFPFLAGS, 1,
1493 [struct kmem_cache has gfpflags])
1494 ],[
1495 AC_MSG_RESULT(no)
1496 ])
1497 ])
1498])
2fc44f66
NB
1499
1500dnl #
1501dnl # 3.17 API change,
1502dnl # wait_on_bit() no longer requires an action argument. The former
1503dnl # "wait_on_bit" interface required an 'action' function to be provided
1504dnl # which does the actual waiting. There were over 20 such functions in the
1505dnl # kernel, many of them identical, though most cases can be satisfied by one
1506dnl # of just two functions: one which uses io_schedule() and one which just
1507dnl # uses schedule(). This API change was made to consolidate all of those
1508dnl # redundant wait functions.
1509dnl #
1510AC_DEFUN([SPL_AC_WAIT_ON_BIT], [
1511 AC_MSG_CHECKING([whether wait_on_bit() takes an action])
1512 SPL_LINUX_TRY_COMPILE([
1513 #include <linux/wait.h>
1514 ],[
1515 int (*action)(void *) = NULL;
1516 wait_on_bit(NULL, 0, action, 0);
1517 ],[
1518 AC_MSG_RESULT(yes)
1519 AC_DEFINE(HAVE_WAIT_ON_BIT_ACTION, 1, [yes])
1520 ],[
1521 AC_MSG_RESULT(no)
1522 ])
1523])
cdd39dd2
CC
1524
1525dnl #
1526dnl # Check whether mutex has owner with task_struct type.
1527dnl #
1528dnl # Note that before Linux 3.0, mutex owner is of type thread_info.
1529dnl #
1530dnl # Note that in Linux 3.18, the condition for owner is changed from
1531dnl # defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP) to
1532dnl # defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_MUTEX_SPIN_ON_OWNER)
1533dnl #
1534AC_DEFUN([SPL_AC_MUTEX_OWNER], [
1535 AC_MSG_CHECKING([whether mutex has owner])
1536 tmp_flags="$EXTRA_KCFLAGS"
1537 EXTRA_KCFLAGS="-Werror"
1538 SPL_LINUX_TRY_COMPILE([
1539 #include <linux/mutex.h>
1540 ],[
1541 DEFINE_MUTEX(m);
1542 struct task_struct *t __attribute__ ((unused));
1543 t = m.owner;
1544 ],[
1545 AC_MSG_RESULT(yes)
1546 AC_DEFINE(HAVE_MUTEX_OWNER, 1, [yes])
1547 ],[
1548 AC_MSG_RESULT(no)
1549 ])
1550 EXTRA_KCFLAGS="$tmp_flags"
1551])
fdbc1ba9
CC
1552
1553dnl #
1554dnl # 4.7 API change
1555dnl # i_mutex is changed to i_rwsem. Instead of directly using
1556dnl # i_mutex/i_rwsem, we should use inode_lock() and inode_lock_shared()
1557dnl # We test inode_lock_shared because inode_lock is introduced earlier.
1558dnl #
1559AC_DEFUN([SPL_AC_INODE_LOCK], [
1560 AC_MSG_CHECKING([whether inode_lock_shared() exists])
1561 tmp_flags="$EXTRA_KCFLAGS"
1562 EXTRA_KCFLAGS="-Werror"
1563 SPL_LINUX_TRY_COMPILE([
1564 #include <linux/fs.h>
1565 ],[
1566 struct inode *inode = NULL;
1567 inode_lock_shared(inode);
1568 ],[
1569 AC_MSG_RESULT(yes)
1570 AC_DEFINE(HAVE_INODE_LOCK_SHARED, 1, [yes])
1571 ],[
1572 AC_MSG_RESULT(no)
1573 ])
1574 EXTRA_KCFLAGS="$tmp_flags"
1575])