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