]> git.proxmox.com Git - mirror_zfs.git/blame - config/kernel.m4
Add kernel module auto-loading
[mirror_zfs.git] / config / kernel.m4
CommitLineData
c9c0d073 1dnl #
fc0c72b1 2dnl # Default ZFS kernel configuration
c9c0d073
BB
3dnl #
4AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
5 ZFS_AC_KERNEL
6 ZFS_AC_SPL
6a9d6359 7 ZFS_AC_QAT
319a99a3 8 ZFS_AC_TEST_MODULE
a6cc9756 9 ZFS_AC_KERNEL_MISC_MINOR
650383f2 10 ZFS_AC_KERNEL_OBJTOOL
c9c0d073 11 ZFS_AC_KERNEL_CONFIG
0b39b9f9 12 ZFS_AC_KERNEL_DECLARE_EVENT_CLASS
37f9dac5 13 ZFS_AC_KERNEL_CURRENT_BIO_TAIL
938cfeb0 14 ZFS_AC_KERNEL_SUPER_USER_NS
bbb1b6ce 15 ZFS_AC_KERNEL_SUBMIT_BIO
c9c0d073 16 ZFS_AC_KERNEL_BDEV_BLOCK_DEVICE_OPERATIONS
a1d9543a 17 ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS_RELEASE_VOID
c9c0d073 18 ZFS_AC_KERNEL_TYPE_FMODE_T
b5a28807 19 ZFS_AC_KERNEL_3ARG_BLKDEV_GET
45066d1f 20 ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH
c9c0d073 21 ZFS_AC_KERNEL_OPEN_BDEV_EXCLUSIVE
2b7ab9d4 22 ZFS_AC_KERNEL_LOOKUP_BDEV
c9c0d073
BB
23 ZFS_AC_KERNEL_INVALIDATE_BDEV_ARGS
24 ZFS_AC_KERNEL_BDEV_LOGICAL_BLOCK_SIZE
2404b014 25 ZFS_AC_KERNEL_BDEV_PHYSICAL_BLOCK_SIZE
d4541210 26 ZFS_AC_KERNEL_BIO_BVEC_ITER
f4af6bb7 27 ZFS_AC_KERNEL_BIO_FAILFAST_DTD
787acae0 28 ZFS_AC_KERNEL_BIO_SET_DEV
f4af6bb7 29 ZFS_AC_KERNEL_REQ_FAILFAST_MASK
cf41432c
BB
30 ZFS_AC_KERNEL_REQ_OP_DISCARD
31 ZFS_AC_KERNEL_REQ_OP_SECURE_ERASE
32 ZFS_AC_KERNEL_REQ_OP_FLUSH
33 ZFS_AC_KERNEL_BIO_BI_OPF
c9c0d073 34 ZFS_AC_KERNEL_BIO_END_IO_T_ARGS
36ba27e9 35 ZFS_AC_KERNEL_BIO_BI_STATUS
37f9dac5
RY
36 ZFS_AC_KERNEL_BIO_RW_BARRIER
37 ZFS_AC_KERNEL_BIO_RW_DISCARD
bc17f104 38 ZFS_AC_KERNEL_BLK_QUEUE_BDI
b18019d2 39 ZFS_AC_KERNEL_BLK_QUEUE_FLUSH
34037afe
ED
40 ZFS_AC_KERNEL_BLK_QUEUE_MAX_HW_SECTORS
41 ZFS_AC_KERNEL_BLK_QUEUE_MAX_SEGMENTS
e6603b7c 42 ZFS_AC_KERNEL_BLK_QUEUE_HAVE_BIO_RW_UNPLUG
e8ac4557 43 ZFS_AC_KERNEL_BLK_QUEUE_HAVE_BLK_PLUG
dd3e1e30 44 ZFS_AC_KERNEL_GET_DISK_AND_MODULE
c9c0d073 45 ZFS_AC_KERNEL_GET_DISK_RO
b5a28807 46 ZFS_AC_KERNEL_GET_GENDISK
a5e046ea
TC
47 ZFS_AC_KERNEL_HAVE_BIO_SET_OP_ATTRS
48 ZFS_AC_KERNEL_GENERIC_READLINK_GLOBAL
ee5fd0bb 49 ZFS_AC_KERNEL_DISCARD_GRANULARITY
777d4af8 50 ZFS_AC_KERNEL_CONST_XATTR_HANDLER
232604b5 51 ZFS_AC_KERNEL_XATTR_HANDLER_NAME
f9637c6c
BB
52 ZFS_AC_KERNEL_XATTR_HANDLER_GET
53 ZFS_AC_KERNEL_XATTR_HANDLER_SET
023699cd
MM
54 ZFS_AC_KERNEL_XATTR_HANDLER_LIST
55 ZFS_AC_KERNEL_INODE_OWNER_OR_CAPABLE
56 ZFS_AC_KERNEL_POSIX_ACL_FROM_XATTR_USERNS
57 ZFS_AC_KERNEL_POSIX_ACL_RELEASE
3779913b 58 ZFS_AC_KERNEL_SET_CACHED_ACL_USABLE
023699cd 59 ZFS_AC_KERNEL_POSIX_ACL_CHMOD
023699cd 60 ZFS_AC_KERNEL_POSIX_ACL_EQUIV_MODE_WANTS_UMODE_T
4b908d32 61 ZFS_AC_KERNEL_POSIX_ACL_VALID_WITH_NS
023699cd
MM
62 ZFS_AC_KERNEL_INODE_OPERATIONS_PERMISSION
63 ZFS_AC_KERNEL_INODE_OPERATIONS_PERMISSION_WITH_NAMEIDATA
64 ZFS_AC_KERNEL_INODE_OPERATIONS_CHECK_ACL
65 ZFS_AC_KERNEL_INODE_OPERATIONS_CHECK_ACL_WITH_FLAGS
66 ZFS_AC_KERNEL_INODE_OPERATIONS_GET_ACL
0420c126 67 ZFS_AC_KERNEL_INODE_OPERATIONS_SET_ACL
a3478c07 68 ZFS_AC_KERNEL_INODE_OPERATIONS_GETATTR
a5248129 69 ZFS_AC_KERNEL_INODE_SET_FLAGS
18f57327 70 ZFS_AC_KERNEL_INODE_SET_IVERSION
3779913b 71 ZFS_AC_KERNEL_GET_ACL_HANDLE_CACHE
47621f3d 72 ZFS_AC_KERNEL_SHOW_OPTIONS
534759fa 73 ZFS_AC_KERNEL_FILE_INODE
d9c97ec0 74 ZFS_AC_KERNEL_FILE_DENTRY
adcd70bd 75 ZFS_AC_KERNEL_FSYNC
2c395def 76 ZFS_AC_KERNEL_EVICT_INODE
8780c539 77 ZFS_AC_KERNEL_DIRTY_INODE_WITH_FLAGS
ab26409d
BB
78 ZFS_AC_KERNEL_NR_CACHED_OBJECTS
79 ZFS_AC_KERNEL_FREE_CACHED_OBJECTS
cb2d1901 80 ZFS_AC_KERNEL_FALLOCATE
7ca25051 81 ZFS_AC_KERNEL_AIO_FSYNC
95f5c63b 82 ZFS_AC_KERNEL_MKDIR_UMODE_T
8f195a90 83 ZFS_AC_KERNEL_LOOKUP_NAMEIDATA
558ef6d0 84 ZFS_AC_KERNEL_CREATE_NAMEIDATA
beeed459 85 ZFS_AC_KERNEL_GET_LINK
bd29109f 86 ZFS_AC_KERNEL_PUT_LINK
ace1eae8 87 ZFS_AC_KERNEL_TMPFILE
ea1fdf46 88 ZFS_AC_KERNEL_TRUNCATE_RANGE
ebe7e575 89 ZFS_AC_KERNEL_AUTOMOUNT
756c3e5a 90 ZFS_AC_KERNEL_ENCODE_FH_WITH_INODE
393b44c7 91 ZFS_AC_KERNEL_COMMIT_METADATA
739a1a82 92 ZFS_AC_KERNEL_CLEAR_INODE
3b0ba3ba 93 ZFS_AC_KERNEL_SETATTR_PREPARE
bdf4328b 94 ZFS_AC_KERNEL_INSERT_INODE_LOCKED
6a0936ba 95 ZFS_AC_KERNEL_D_MAKE_ROOT
055656d4 96 ZFS_AC_KERNEL_D_OBTAIN_ALIAS
218b4e0a 97 ZFS_AC_KERNEL_D_PRUNE_ALIASES
f1a05fa1
NB
98 ZFS_AC_KERNEL_D_SET_D_OP
99 ZFS_AC_KERNEL_D_REVALIDATE_NAMEIDATA
100 ZFS_AC_KERNEL_CONST_DENTRY_OPERATIONS
b3129792 101 ZFS_AC_KERNEL_TRUNCATE_SETSIZE
5c03efc3 102 ZFS_AC_KERNEL_6ARGS_SECURITY_INODE_INIT_SECURITY
166dd49d 103 ZFS_AC_KERNEL_CALLBACK_SECURITY_INODE_INIT_SECURITY
2cf7f52b 104 ZFS_AC_KERNEL_MOUNT_NODEV
ab26409d 105 ZFS_AC_KERNEL_SHRINK
90947b23 106 ZFS_AC_KERNEL_SHRINK_CONTROL_HAS_NID
dba1d705 107 ZFS_AC_KERNEL_S_INSTANCES_LIST_HEAD
ee930353 108 ZFS_AC_KERNEL_S_D_OP
7dae2c81 109 ZFS_AC_KERNEL_BDI
28eb9213 110 ZFS_AC_KERNEL_SET_NLINK
6d1d976b 111 ZFS_AC_KERNEL_ELEVATOR_CHANGE
3c203610 112 ZFS_AC_KERNEL_5ARG_SGET
802e7b5f 113 ZFS_AC_KERNEL_LSEEK_EXECUTE
0f37d0c8 114 ZFS_AC_KERNEL_VFS_ITERATE
57ae8400 115 ZFS_AC_KERNEL_VFS_RW_ITERATE
933ec999 116 ZFS_AC_KERNEL_GENERIC_WRITE_CHECKS
17888ae3 117 ZFS_AC_KERNEL_KMAP_ATOMIC_ARGS
278bee93 118 ZFS_AC_KERNEL_FOLLOW_DOWN_ONE
37f9dac5 119 ZFS_AC_KERNEL_MAKE_REQUEST_FN
787acae0
GDN
120 ZFS_AC_KERNEL_GENERIC_IO_ACCT_3ARG
121 ZFS_AC_KERNEL_GENERIC_IO_ACCT_4ARG
fc0c72b1 122 ZFS_AC_KERNEL_FPU
82a1b2d6 123 ZFS_AC_KERNEL_KUID_HELPERS
9cc1844a 124 ZFS_AC_KERNEL_MODULE_PARAM_CALL_CONST
b8d9e264 125 ZFS_AC_KERNEL_RENAME_WANTS_FLAGS
0fedeedd 126 ZFS_AC_KERNEL_HAVE_GENERIC_SETXATTR
2946a1a1 127 ZFS_AC_KERNEL_CURRENT_TIME
e9a77290 128 ZFS_AC_KERNEL_GLOBAL_PAGE_STATE
a5369b61 129 ZFS_AC_KERNEL_ACL_HAS_REFCOUNT
0e85048f 130 ZFS_AC_KERNEL_USERNS_CAPABILITIES
c9c0d073 131
8366cd6a 132 AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
fed90353 133 KERNEL_MAKE="$KERNEL_MAKE O=$LINUX_OBJ"
8366cd6a 134 ])
6283f55e 135
fed90353 136 AC_SUBST(KERNEL_MAKE)
c9c0d073
BB
137])
138
139dnl #
140dnl # Detect name used for Module.symvers file in kernel
141dnl #
142AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
143 modpost=$LINUX/scripts/Makefile.modpost
144 AC_MSG_CHECKING([kernel file name for module symbols])
319a99a3 145 AS_IF([test "x$enable_linux_builtin" != xyes -a -f "$modpost"], [
8366cd6a 146 AS_IF([grep -q Modules.symvers $modpost], [
c9c0d073 147 LINUX_SYMBOLS=Modules.symvers
8366cd6a 148 ], [
c9c0d073 149 LINUX_SYMBOLS=Module.symvers
8366cd6a 150 ])
a60b1c0a 151
8366cd6a 152 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
a60b1c0a
BB
153 AC_MSG_ERROR([
154 *** Please make sure the kernel devel package for your distribution
4e95cc99 155 *** is installed. If you are building with a custom kernel, make sure the
a60b1c0a
BB
156 *** kernel is configured, built, and the '--with-linux=PATH' configure
157 *** option refers to the location of the kernel source.])
8366cd6a
PS
158 ])
159 ], [
c9c0d073 160 LINUX_SYMBOLS=NONE
8366cd6a 161 ])
c9c0d073
BB
162 AC_MSG_RESULT($LINUX_SYMBOLS)
163 AC_SUBST(LINUX_SYMBOLS)
164])
165
166dnl #
167dnl # Detect the kernel to be built against
168dnl #
169AC_DEFUN([ZFS_AC_KERNEL], [
170 AC_ARG_WITH([linux],
171 AS_HELP_STRING([--with-linux=PATH],
172 [Path to kernel source]),
173 [kernelsrc="$withval"])
174
175 AC_ARG_WITH(linux-obj,
176 AS_HELP_STRING([--with-linux-obj=PATH],
177 [Path to kernel build objects]),
178 [kernelbuild="$withval"])
179
180 AC_MSG_CHECKING([kernel source directory])
8366cd6a
PS
181 AS_IF([test -z "$kernelsrc"], [
182 AS_IF([test -e "/lib/modules/$(uname -r)/source"], [
1b94c25c
BB
183 headersdir="/lib/modules/$(uname -r)/source"
184 sourcelink=$(readlink -f "$headersdir")
8366cd6a 185 ], [test -e "/lib/modules/$(uname -r)/build"], [
1b94c25c 186 headersdir="/lib/modules/$(uname -r)/build"
c9c0d073 187 sourcelink=$(readlink -f "$headersdir")
8366cd6a 188 ], [
c9c0d073 189 sourcelink=$(ls -1d /usr/src/kernels/* \
8366cd6a 190 /usr/src/linux-* \
c9c0d073 191 2>/dev/null | grep -v obj | tail -1)
8366cd6a 192 ])
c9c0d073 193
8366cd6a 194 AS_IF([test -n "$sourcelink" && test -e ${sourcelink}], [
c9c0d073 195 kernelsrc=`readlink -f ${sourcelink}`
8366cd6a 196 ], [
56a517ae 197 kernelsrc="[Not found]"
8366cd6a
PS
198 ])
199 ], [
200 AS_IF([test "$kernelsrc" = "NONE"], [
c9c0d073 201 kernsrcver=NONE
8366cd6a 202 ])
1d8da991 203 withlinux=yes
8366cd6a 204 ])
c9c0d073
BB
205
206 AC_MSG_RESULT([$kernelsrc])
56a517ae
BB
207 AS_IF([test ! -d "$kernelsrc"], [
208 AC_MSG_ERROR([
209 *** Please make sure the kernel devel package for your distribution
4e95cc99 210 *** is installed and then try again. If that fails, you can specify the
56a517ae
BB
211 *** location of the kernel source with the '--with-linux=PATH' option.])
212 ])
213
c9c0d073 214 AC_MSG_CHECKING([kernel build directory])
8366cd6a 215 AS_IF([test -z "$kernelbuild"], [
1d8da991 216 AS_IF([test x$withlinux != xyes -a -e "/lib/modules/$(uname -r)/build"], [
1b94c25c 217 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
8366cd6a 218 ], [test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}], [
c9c0d073 219 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
8366cd6a 220 ], [test -d ${kernelsrc}-obj/${target_cpu}/default], [
70574182 221 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
8366cd6a 222 ], [test -d `dirname ${kernelsrc}`/build-${target_cpu}], [
c9c0d073 223 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
8366cd6a 224 ], [
c9c0d073 225 kernelbuild=${kernelsrc}
8366cd6a
PS
226 ])
227 ])
c9c0d073
BB
228 AC_MSG_RESULT([$kernelbuild])
229
230 AC_MSG_CHECKING([kernel source version])
231 utsrelease1=$kernelbuild/include/linux/version.h
232 utsrelease2=$kernelbuild/include/linux/utsrelease.h
233 utsrelease3=$kernelbuild/include/generated/utsrelease.h
8366cd6a 234 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1], [
c9c0d073 235 utsrelease=linux/version.h
8366cd6a 236 ], [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2], [
c9c0d073 237 utsrelease=linux/utsrelease.h
8366cd6a 238 ], [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3], [
c9c0d073 239 utsrelease=generated/utsrelease.h
8366cd6a 240 ])
c9c0d073 241
8366cd6a 242 AS_IF([test "$utsrelease"], [
c9c0d073
BB
243 kernsrcver=`(echo "#include <$utsrelease>";
244 echo "kernsrcver=UTS_RELEASE") |
245 cpp -I $kernelbuild/include |
246 grep "^kernsrcver=" | cut -d \" -f 2`
247
8366cd6a 248 AS_IF([test -z "$kernsrcver"], [
c9c0d073
BB
249 AC_MSG_RESULT([Not found])
250 AC_MSG_ERROR([*** Cannot determine kernel version.])
8366cd6a
PS
251 ])
252 ], [
c9c0d073 253 AC_MSG_RESULT([Not found])
319a99a3
ED
254 if test "x$enable_linux_builtin" != xyes; then
255 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
256 else
257 AC_MSG_ERROR([
258 *** Cannot find UTS_RELEASE definition.
259 *** Please run 'make prepare' inside the kernel source tree.])
260 fi
8366cd6a 261 ])
c9c0d073
BB
262
263 AC_MSG_RESULT([$kernsrcver])
264
265 LINUX=${kernelsrc}
266 LINUX_OBJ=${kernelbuild}
267 LINUX_VERSION=${kernsrcver}
268
269 AC_SUBST(LINUX)
270 AC_SUBST(LINUX_OBJ)
271 AC_SUBST(LINUX_VERSION)
272
273 ZFS_AC_MODULE_SYMVERS
274])
275
c9c0d073
BB
276
277dnl #
278dnl # Detect the SPL module to be built against
279dnl #
280AC_DEFUN([ZFS_AC_SPL], [
281 AC_ARG_WITH([spl],
282 AS_HELP_STRING([--with-spl=PATH],
283 [Path to spl source]),
c7e7ec19
OF
284 AS_IF([test "$withval" = "yes"],
285 AC_MSG_ERROR([--with-spl=PATH requires a PATH]),
286 [splsrc="$withval"]))
c9c0d073
BB
287
288 AC_ARG_WITH([spl-obj],
289 AS_HELP_STRING([--with-spl-obj=PATH],
290 [Path to spl build objects]),
291 [splbuild="$withval"])
292
51654737
CALP
293 AC_ARG_WITH([spl-timeout],
294 AS_HELP_STRING([--with-spl-timeout=SECS],
295 [Wait SECS for SPL header and symver file @<:@default=0@:>@]),
296 [timeout="$withval"], [timeout=0])
297
9b2af9a0
BB
298 dnl #
299 dnl # The existence of spl.release.in is used to identify a valid
300 dnl # source directory. In order of preference:
301 dnl #
302 splsrc0="/var/lib/dkms/spl/${VERSION}/build"
d8d78267
RY
303 splsrc1="/usr/local/src/spl-${VERSION}/${LINUX_VERSION}"
304 splsrc2="/usr/local/src/spl-${VERSION}"
305 splsrc3="/usr/src/spl-${VERSION}/${LINUX_VERSION}"
306 splsrc4="/usr/src/spl-${VERSION}"
307 splsrc5="../spl/"
308 splsrc6="$LINUX"
c9c0d073
BB
309
310 AC_MSG_CHECKING([spl source directory])
9b2af9a0 311 AS_IF([test -z "${splsrc}"], [
c7e7ec19
OF
312 [all_spl_sources="
313 ${splsrc0}
314 ${splsrc1}
315 ${splsrc2}
316 ${splsrc3}
317 ${splsrc4}
318 ${splsrc5}
319 ${splsrc6}"],
9b2af9a0
BB
320 AS_IF([ test -e "${splsrc0}/spl.release.in"], [
321 splsrc=${splsrc0}
322 ], [ test -e "${splsrc1}/spl.release.in"], [
323 splsrc=${splsrc1}
324 ], [ test -e "${splsrc2}/spl.release.in"], [
325 splsrc=${splsrc2}
326 ], [ test -e "${splsrc3}/spl.release.in"], [
327 splsrc=$(readlink -f "${splsrc3}")
328 ], [ test -e "${splsrc4}/spl.release.in" ], [
329 splsrc=${splsrc4}
d8d78267
RY
330 ], [ test -e "${splsrc5}/spl.release.in"], [
331 splsrc=$(readlink -f "${splsrc5}")
332 ], [ test -e "${splsrc6}/spl.release.in" ], [
333 splsrc=${splsrc6}
8366cd6a 334 ], [
9b2af9a0 335 splsrc="[Not found]"
8366cd6a
PS
336 ])
337 ], [
c7e7ec19 338 [all_spl_sources="$withval"],
8366cd6a 339 AS_IF([test "$splsrc" = "NONE"], [
c9c0d073
BB
340 splbuild=NONE
341 splsrcver=NONE
8366cd6a
PS
342 ])
343 ])
c9c0d073
BB
344
345 AC_MSG_RESULT([$splsrc])
9b2af9a0
BB
346 AS_IF([ test ! -e "$splsrc/spl.release.in"], [
347 AC_MSG_ERROR([
348 *** Please make sure the kmod spl devel package for your distribution
349 *** is installed then try again. If that fails you can specify the
c7e7ec19
OF
350 *** location of the spl source with the '--with-spl=PATH' option.
351 *** The spl version must match the version of ZFS you are building,
352 *** ${VERSION}. Failed to find spl.release.in in the following:
353 $all_spl_sources])
9b2af9a0
BB
354 ])
355
356 dnl #
357 dnl # The existence of the spl_config.h is used to identify a valid
358 dnl # spl object directory. In many cases the object and source
359 dnl # directory are the same, however the objects may also reside
360 dnl # is a subdirectory named after the kernel version.
361 dnl #
51654737
CALP
362 dnl # This file is supposed to be available after DKMS finishes
363 dnl # building the SPL kernel module for the target kernel. The
364 dnl # '--with-spl-timeout' option can be passed to pause here,
365 dnl # waiting for the file to appear from a concurrently building
366 dnl # SPL package.
367 dnl #
c9c0d073 368 AC_MSG_CHECKING([spl build directory])
c7e7ec19
OF
369
370 all_spl_config_locs="${splsrc}/${LINUX_VERSION}
371 ${splsrc}"
372
51654737
CALP
373 while true; do
374 AS_IF([test -z "$splbuild"], [
375 AS_IF([ test -e "${splsrc}/${LINUX_VERSION}/spl_config.h" ], [
376 splbuild="${splsrc}/${LINUX_VERSION}"
377 ], [ test -e "${splsrc}/spl_config.h" ], [
378 splbuild="${splsrc}"
47a4a6fd
TF
379 ], [ find -L "${splsrc}" -name spl_config.h 2> /dev/null | grep -wq spl_config.h ], [
380 splbuild=$(find -L "${splsrc}" -name spl_config.h | sed 's,/spl_config.h,,')
51654737
CALP
381 ], [
382 splbuild="[Not found]"
383 ])
384 ])
385 AS_IF([test -e "$splbuild/spl_config.h" -o $timeout -le 0], [
386 break;
9b2af9a0 387 ], [
51654737
CALP
388 sleep 1
389 timeout=$((timeout-1))
9b2af9a0 390 ])
51654737 391 done
9b2af9a0 392
c9c0d073 393 AC_MSG_RESULT([$splbuild])
9b2af9a0
BB
394 AS_IF([ ! test -e "$splbuild/spl_config.h"], [
395 AC_MSG_ERROR([
396 *** Please make sure the kmod spl devel <kernel> package for your
397 *** distribution is installed then try again. If that fails you
398 *** can specify the location of the spl objects with the
c7e7ec19
OF
399 *** '--with-spl-obj=PATH' option. Failed to find spl_config.h in
400 *** any of the following:
401 $all_spl_config_locs])
9b2af9a0 402 ])
c9c0d073
BB
403
404 AC_MSG_CHECKING([spl source version])
8366cd6a
PS
405 AS_IF([test -r $splbuild/spl_config.h &&
406 fgrep -q SPL_META_VERSION $splbuild/spl_config.h], [
c9c0d073
BB
407
408 splsrcver=`(echo "#include <spl_config.h>";
b40a77ae 409 echo "splsrcver=SPL_META_VERSION-SPL_META_RELEASE") |
5e612145 410 cpp -I $splbuild |
b40a77ae 411 grep "^splsrcver=" | tr -d \" | cut -d= -f2`
8366cd6a 412 ])
c9c0d073 413
8366cd6a 414 AS_IF([test -z "$splsrcver"], [
c9c0d073
BB
415 AC_MSG_RESULT([Not found])
416 AC_MSG_ERROR([
2984e0bb
PS
417 *** Cannot determine the version of the spl source.
418 *** Please prepare the spl source before running this script])
8366cd6a 419 ])
c9c0d073
BB
420
421 AC_MSG_RESULT([$splsrcver])
422
423 SPL=${splsrc}
424 SPL_OBJ=${splbuild}
425 SPL_VERSION=${splsrcver}
426
427 AC_SUBST(SPL)
428 AC_SUBST(SPL_OBJ)
429 AC_SUBST(SPL_VERSION)
430
51654737
CALP
431 dnl #
432 dnl # Detect the name used for the SPL Module.symvers file. If one
433 dnl # does not exist this is likely because the SPL has been configured
434 dnl # but not built. The '--with-spl-timeout' option can be passed
435 dnl # to pause here, waiting for the file to appear from a concurrently
436 dnl # building SPL package. If the file does not appear in time, a good
437 dnl # guess is made as to what this file will be named based on what it
438 dnl # is named in the kernel build products. This file will first be
439 dnl # used at link time so if the guess is wrong the build will fail
440 dnl # then. This unfortunately means the ZFS package does not contain a
441 dnl # reliable mechanism to detect symbols exported by the SPL at
442 dnl # configure time.
443 dnl #
444 AC_MSG_CHECKING([spl file name for module symbols])
445 SPL_SYMBOLS=NONE
446
447 while true; do
448 AS_IF([test -r $SPL_OBJ/Module.symvers], [
449 SPL_SYMBOLS=Module.symvers
450 ], [test -r $SPL_OBJ/Modules.symvers], [
451 SPL_SYMBOLS=Modules.symvers
452 ], [test -r $SPL_OBJ/module/Module.symvers], [
453 SPL_SYMBOLS=Module.symvers
454 ], [test -r $SPL_OBJ/module/Modules.symvers], [
455 SPL_SYMBOLS=Modules.symvers
456 ])
457
458 AS_IF([test $SPL_SYMBOLS != NONE -o $timeout -le 0], [
459 break;
460 ], [
461 sleep 1
462 timeout=$((timeout-1))
463 ])
464 done
465
466 AS_IF([test "$SPL_SYMBOLS" = NONE], [
467 SPL_SYMBOLS=$LINUX_SYMBOLS
468 ])
469
470 AC_MSG_RESULT([$SPL_SYMBOLS])
471 AC_SUBST(SPL_SYMBOLS)
c9c0d073
BB
472])
473
6a9d6359 474dnl #
475dnl # Detect the QAT module to be built against
476dnl # QAT provides hardware acceleration for data compression:
477dnl # https://01.org/intel-quickassist-technology
478dnl # * Download and install QAT driver from the above link
479dnl # * Start QAT driver in your system:
480dnl # service qat_service start
481dnl # * Enable QAT in ZFS, e.g.:
482dnl # ./configure --with-qat=<qat-driver-path>/QAT1.6
483dnl # make
484dnl # * Set GZIP compression in ZFS dataset:
485dnl # zfs set compression = gzip <dataset>
486dnl # Then the data written to this ZFS pool is compressed
487dnl # by QAT accelerator automatically, and de-compressed by
488dnl # QAT when read from the pool.
489dnl # * Get QAT hardware statistics by:
490dnl # cat /proc/icp_dh895xcc_dev/qat
491dnl # * To disable QAT:
492dnl # insmod zfs.ko zfs_qat_disable=1
493dnl #
494AC_DEFUN([ZFS_AC_QAT], [
495 AC_ARG_WITH([qat],
496 AS_HELP_STRING([--with-qat=PATH],
497 [Path to qat source]),
498 AS_IF([test "$withval" = "yes"],
499 AC_MSG_ERROR([--with-qat=PATH requires a PATH]),
500 [qatsrc="$withval"]))
501
502 AC_ARG_WITH([qat-obj],
503 AS_HELP_STRING([--with-qat-obj=PATH],
504 [Path to qat build objects]),
505 [qatbuild="$withval"])
506
507 AS_IF([test ! -z "${qatsrc}"], [
508 AC_MSG_CHECKING([qat source directory])
509 AC_MSG_RESULT([$qatsrc])
510 QAT_SRC="${qatsrc}/quickassist"
511 AS_IF([ test ! -e "$QAT_SRC/include/cpa.h"], [
512 AC_MSG_ERROR([
513 *** Please make sure the qat driver package is installed
514 *** and specify the location of the qat source with the
515 *** '--with-qat=PATH' option then try again. Failed to
516 *** find cpa.h in:
517 ${QAT_SRC}/include])
518 ])
519 ])
520
521 AS_IF([test ! -z "${qatsrc}"], [
522 AC_MSG_CHECKING([qat build directory])
523 AS_IF([test -z "$qatbuild"], [
524 qatbuild="${qatsrc}/build"
525 ])
526
527 AC_MSG_RESULT([$qatbuild])
528 QAT_OBJ=${qatbuild}
1cfdb0e6 529 AS_IF([ ! test -e "$QAT_OBJ/icp_qa_al.ko" && ! test -e "$QAT_OBJ/qat_api.ko"], [
6a9d6359 530 AC_MSG_ERROR([
531 *** Please make sure the qat driver is installed then try again.
1cfdb0e6 532 *** Failed to find icp_qa_al.ko or qat_api.ko in:
6a9d6359 533 $QAT_OBJ])
534 ])
535
536 AC_SUBST(QAT_SRC)
537 AC_SUBST(QAT_OBJ)
538
539 AC_DEFINE(HAVE_QAT, 1,
540 [qat is enabled and existed])
541 ])
542
543 dnl #
544 dnl # Detect the name used for the QAT Module.symvers file.
545 dnl #
546 AS_IF([test ! -z "${qatsrc}"], [
547 AC_MSG_CHECKING([qat file for module symbols])
548 QAT_SYMBOLS=$QAT_SRC/lookaside/access_layer/src/Module.symvers
549
550 AS_IF([test -r $QAT_SYMBOLS], [
551 AC_MSG_RESULT([$QAT_SYMBOLS])
552 AC_SUBST(QAT_SYMBOLS)
553 ],[
554 AC_MSG_ERROR([
555 *** Please make sure the qat driver is installed then try again.
556 *** Failed to find Module.symvers in:
557 $QAT_SYMBOLS])
558 ])
559 ])
560 ])
561])
562
319a99a3
ED
563dnl #
564dnl # Basic toolchain sanity check.
565dnl #
e33045ee
BB
566AC_DEFUN([ZFS_AC_TEST_MODULE], [
567 AC_MSG_CHECKING([whether modules can be built])
319a99a3
ED
568 ZFS_LINUX_TRY_COMPILE([],[],[
569 AC_MSG_RESULT([yes])
570 ],[
571 AC_MSG_RESULT([no])
572 if test "x$enable_linux_builtin" != xyes; then
573 AC_MSG_ERROR([*** Unable to build an empty module.])
574 else
575 AC_MSG_ERROR([
576 *** Unable to build an empty module.
577 *** Please run 'make scripts' inside the kernel source tree.])
578 fi
579 ])
580])
581
15805c77
BB
582dnl #
583dnl # Certain kernel build options are not supported. These must be
584dnl # detected at configure time and cause a build failure. Otherwise
585dnl # modules may be successfully built that behave incorrectly.
586dnl #
e5b85622 587AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
76d5bf19
KD
588 AS_IF([test "x$cross_compiling" != xyes], [
589 AC_RUN_IFELSE([
590 AC_LANG_PROGRAM([
591 #include "$LINUX/include/linux/license.h"
592 ], [
593 return !license_is_gpl_compatible("$ZFS_META_LICENSE");
594 ])
595 ], [
596 AC_DEFINE([ZFS_IS_GPL_COMPATIBLE], [1],
597 [Define to 1 if GPL-only symbols can be used])
e33045ee 598 ], [
e33045ee 599 ])
e5b85622
BB
600 ])
601
b58986ee 602 ZFS_AC_KERNEL_CONFIG_THREAD_SIZE
e5b85622
BB
603 ZFS_AC_KERNEL_CONFIG_DEBUG_LOCK_ALLOC
604])
605
b58986ee
BB
606dnl #
607dnl # Check configured THREAD_SIZE
608dnl #
609dnl # The stack size will vary by architecture, but as of Linux 3.15 on x86_64
610dnl # the default thread stack size was increased to 16K from 8K. Therefore,
611dnl # on newer kernels and some architectures stack usage optimizations can be
612dnl # conditionally applied to improve performance without negatively impacting
613dnl # stability.
614dnl #
615AC_DEFUN([ZFS_AC_KERNEL_CONFIG_THREAD_SIZE], [
616 AC_MSG_CHECKING([whether kernel was built with 16K or larger stacks])
617 ZFS_LINUX_TRY_COMPILE([
618 #include <linux/module.h>
619 ],[
620 #if (THREAD_SIZE < 16384)
621 #error "THREAD_SIZE is less than 16K"
622 #endif
623 ],[
624 AC_MSG_RESULT([yes])
625 AC_DEFINE(HAVE_LARGE_STACKS, 1, [kernel has large stacks])
626 ],[
627 AC_MSG_RESULT([no])
628 ])
629])
630
e5b85622
BB
631dnl #
632dnl # Check CONFIG_DEBUG_LOCK_ALLOC
633dnl #
634dnl # This is typically only set for debug kernels because it comes with
635dnl # a performance penalty. However, when it is set it maps the non-GPL
636dnl # symbol mutex_lock() to the GPL-only mutex_lock_nested() symbol.
637dnl # This will cause a failure at link time which we'd rather know about
638dnl # at compile time.
639dnl #
640dnl # Since we plan to pursue making mutex_lock_nested() a non-GPL symbol
641dnl # with the upstream community we add a check to detect this case.
642dnl #
643AC_DEFUN([ZFS_AC_KERNEL_CONFIG_DEBUG_LOCK_ALLOC], [
644
645 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC], [
646 AC_MSG_CHECKING([whether mutex_lock() is GPL-only])
647 tmp_flags="$EXTRA_KCFLAGS"
648 ZFS_LINUX_TRY_COMPILE([
649 #include <linux/module.h>
650 #include <linux/mutex.h>
651
652 MODULE_LICENSE("$ZFS_META_LICENSE");
653 ],[
654 struct mutex lock;
655
656 mutex_init(&lock);
657 mutex_lock(&lock);
658 mutex_unlock(&lock);
659 ],[
660 AC_MSG_RESULT(no)
661 ],[
662 AC_MSG_RESULT(yes)
663 AC_MSG_ERROR([
664 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is incompatible
cac1f230
NB
665 *** with the CDDL license and will prevent the module linking stage
666 *** from succeeding. You must rebuild your kernel without this
667 *** option enabled.])
e5b85622
BB
668 ])
669 EXTRA_KCFLAGS="$tmp_flags"
670 ], [])
c9c0d073
BB
671])
672
673dnl #
0b39b9f9 674dnl # ZFS_LINUX_CONFTEST_H
c9c0d073 675dnl #
0b39b9f9
PS
676AC_DEFUN([ZFS_LINUX_CONFTEST_H], [
677cat - <<_ACEOF >conftest.h
678$1
679_ACEOF
680])
681
682dnl #
683dnl # ZFS_LINUX_CONFTEST_C
684dnl #
685AC_DEFUN([ZFS_LINUX_CONFTEST_C], [
c9c0d073
BB
686cat confdefs.h - <<_ACEOF >conftest.c
687$1
688_ACEOF
689])
690
691dnl #
692dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
693dnl #
694m4_define([ZFS_LANG_PROGRAM], [
695$1
696int
697main (void)
698{
699dnl Do *not* indent the following line: there may be CPP directives.
700dnl Don't move the `;' right after for the same reason.
701$2
702 ;
703 return 0;
704}
705])
706
707dnl #
708dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
709dnl #
710AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
0b39b9f9
PS
711 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST_C([$1])])
712 m4_ifvaln([$6], [ZFS_LINUX_CONFTEST_H([$6])], [ZFS_LINUX_CONFTEST_H([])])
fc88a6dd 713 rm -Rf build && mkdir -p build && touch build/conftest.mod.c
c9c0d073 714 echo "obj-m := conftest.o" >build/Makefile
fc88a6dd
ED
715 modpost_flag=''
716 test "x$enable_linux_builtin" = xyes && modpost_flag='modpost=true' # fake modpost stage
c9c0d073 717 AS_IF(
e921f650 718 [AC_TRY_COMMAND(cp conftest.c conftest.h build && make [$2] -C $LINUX_OBJ EXTRA_CFLAGS="-Werror $FRAME_LARGER_THAN $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build $modpost_flag) >/dev/null && AC_TRY_COMMAND([$3])],
c9c0d073
BB
719 [$4],
720 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
721 )
722 rm -Rf build
723])
724
725dnl #
726dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
727dnl #
728AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
729 [ZFS_LINUX_COMPILE_IFELSE(
730 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
731 [modules],
732 [test -s build/conftest.o],
733 [$3], [$4])
734])
735
736dnl #
737dnl # ZFS_LINUX_CONFIG
738dnl #
739AC_DEFUN([ZFS_LINUX_CONFIG],
b58986ee 740 [AC_MSG_CHECKING([whether kernel was built with CONFIG_$1])
c9c0d073 741 ZFS_LINUX_TRY_COMPILE([
0da78696 742 #include <linux/module.h>
c9c0d073
BB
743 ],[
744 #ifndef CONFIG_$1
745 #error CONFIG_$1 not #defined
746 #endif
747 ],[
748 AC_MSG_RESULT([yes])
749 $2
750 ],[
751 AC_MSG_RESULT([no])
752 $3
753 ])
754])
755
756dnl #
757dnl # ZFS_CHECK_SYMBOL_EXPORT
758dnl # check symbol exported or not
759dnl #
70574182 760AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT], [
c9c0d073
BB
761 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
762 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
763 rc=$?
70574182 764 if test $rc -ne 0; then
c9c0d073
BB
765 export=0
766 for file in $2; do
70574182
ED
767 grep -q -E "EXPORT_SYMBOL.*($1)" \
768 "$LINUX/$file" 2>/dev/null
c9c0d073 769 rc=$?
70574182 770 if test $rc -eq 0; then
8366cd6a
PS
771 export=1
772 break;
70574182 773 fi
c9c0d073 774 done
70574182 775 if test $export -eq 0; then :
c9c0d073 776 $4
70574182 777 else :
c9c0d073 778 $3
70574182
ED
779 fi
780 else :
c9c0d073 781 $3
70574182
ED
782 fi
783])
784
785dnl #
786dnl # ZFS_LINUX_TRY_COMPILE_SYMBOL
787dnl # like ZFS_LINUX_TRY_COMPILE, except ZFS_CHECK_SYMBOL_EXPORT
788dnl # is called if not compiling for builtin
789dnl #
790AC_DEFUN([ZFS_LINUX_TRY_COMPILE_SYMBOL], [
791 ZFS_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
792 if test $rc -ne 0; then :
793 $6
794 else
795 if test "x$enable_linux_builtin" != xyes; then
796 ZFS_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
797 fi
798 if test $rc -ne 0; then :
799 $6
800 else :
801 $5
802 fi
803 fi
c9c0d073 804])
0b39b9f9
PS
805
806dnl #
807dnl # ZFS_LINUX_TRY_COMPILE_HEADER
808dnl # like ZFS_LINUX_TRY_COMPILE, except the contents conftest.h are
809dnl # provided via the fifth parameter
810dnl #
811AC_DEFUN([ZFS_LINUX_TRY_COMPILE_HEADER],
812 [ZFS_LINUX_COMPILE_IFELSE(
813 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
814 [modules],
815 [test -s build/conftest.o],
4e30e68c 816 [$3], [$4], [$5])
0b39b9f9 817])