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