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