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