1dnl # 2dnl # Default ZFS kernel configuration 3dnl # 4AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [ 5 AM_COND_IF([BUILD_LINUX], [ 6 dnl # Setup the kernel build environment. 7 ZFS_AC_KERNEL 8 ZFS_AC_QAT 9 10 dnl # Sanity checks for module building and CONFIG_* defines 11 ZFS_AC_KERNEL_TEST_MODULE 12 ZFS_AC_KERNEL_CONFIG_DEFINED 13 14 dnl # Sequential ZFS_LINUX_TRY_COMPILE tests 15 ZFS_AC_KERNEL_FPU_HEADER 16 ZFS_AC_KERNEL_OBJTOOL_HEADER 17 ZFS_AC_KERNEL_WAIT_QUEUE_ENTRY_T 18 ZFS_AC_KERNEL_MISC_MINOR 19 ZFS_AC_KERNEL_DECLARE_EVENT_CLASS 20 21 dnl # Parallel ZFS_LINUX_TEST_SRC / ZFS_LINUX_TEST_RESULT tests 22 ZFS_AC_KERNEL_TEST_SRC 23 ZFS_AC_KERNEL_TEST_RESULT 24 25 AS_IF([test "$LINUX_OBJ" != "$LINUX"], [ 26 KERNEL_MAKE="$KERNEL_MAKE O=$LINUX_OBJ" 27 ]) 28 29 AC_SUBST(KERNEL_MAKE) 30 ]) 31]) 32 33dnl # 34dnl # Generate and compile all of the kernel API test cases to determine 35dnl # which interfaces are available. By invoking the kernel build system 36dnl # only once the compilation can be done in parallel significantly 37dnl # speeding up the process. 38dnl # 39AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [ 40 ZFS_AC_KERNEL_SRC_OBJTOOL 41 ZFS_AC_KERNEL_SRC_GLOBAL_PAGE_STATE 42 ZFS_AC_KERNEL_SRC_ACCESS_OK_TYPE 43 ZFS_AC_KERNEL_SRC_PDE_DATA 44 ZFS_AC_KERNEL_SRC_FALLOCATE 45 ZFS_AC_KERNEL_SRC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE 46 ZFS_AC_KERNEL_SRC_RWSEM 47 ZFS_AC_KERNEL_SRC_SCHED 48 ZFS_AC_KERNEL_SRC_USLEEP_RANGE 49 ZFS_AC_KERNEL_SRC_KMEM_CACHE 50 ZFS_AC_KERNEL_SRC_KVMALLOC 51 ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL 52 ZFS_AC_KERNEL_SRC_WAIT 53 ZFS_AC_KERNEL_SRC_INODE_TIMES 54 ZFS_AC_KERNEL_SRC_INODE_LOCK 55 ZFS_AC_KERNEL_SRC_GROUP_INFO_GID 56 ZFS_AC_KERNEL_SRC_RW 57 ZFS_AC_KERNEL_SRC_TIMER_SETUP 58 ZFS_AC_KERNEL_SRC_SUPER_USER_NS 59 ZFS_AC_KERNEL_SRC_PROC_OPERATIONS 60 ZFS_AC_KERNEL_SRC_BLOCK_DEVICE_OPERATIONS 61 ZFS_AC_KERNEL_SRC_BIO 62 ZFS_AC_KERNEL_SRC_BLKDEV 63 ZFS_AC_KERNEL_SRC_BLK_QUEUE 64 ZFS_AC_KERNEL_SRC_REVALIDATE_DISK 65 ZFS_AC_KERNEL_SRC_GET_DISK_RO 66 ZFS_AC_KERNEL_SRC_GENERIC_READLINK_GLOBAL 67 ZFS_AC_KERNEL_SRC_DISCARD_GRANULARITY 68 ZFS_AC_KERNEL_SRC_INODE_OWNER_OR_CAPABLE 69 ZFS_AC_KERNEL_SRC_XATTR 70 ZFS_AC_KERNEL_SRC_ACL 71 ZFS_AC_KERNEL_SRC_INODE_GETATTR 72 ZFS_AC_KERNEL_SRC_INODE_SET_FLAGS 73 ZFS_AC_KERNEL_SRC_INODE_SET_IVERSION 74 ZFS_AC_KERNEL_SRC_SHOW_OPTIONS 75 ZFS_AC_KERNEL_SRC_FILE_INODE 76 ZFS_AC_KERNEL_SRC_FILE_DENTRY 77 ZFS_AC_KERNEL_SRC_FSYNC 78 ZFS_AC_KERNEL_SRC_AIO_FSYNC 79 ZFS_AC_KERNEL_SRC_EVICT_INODE 80 ZFS_AC_KERNEL_SRC_DIRTY_INODE 81 ZFS_AC_KERNEL_SRC_SHRINKER 82 ZFS_AC_KERNEL_SRC_MKDIR_UMODE_T 83 ZFS_AC_KERNEL_SRC_LOOKUP_FLAGS 84 ZFS_AC_KERNEL_SRC_CREATE_FLAGS 85 ZFS_AC_KERNEL_SRC_GET_LINK 86 ZFS_AC_KERNEL_SRC_PUT_LINK 87 ZFS_AC_KERNEL_SRC_TMPFILE 88 ZFS_AC_KERNEL_SRC_AUTOMOUNT 89 ZFS_AC_KERNEL_SRC_ENCODE_FH_WITH_INODE 90 ZFS_AC_KERNEL_SRC_COMMIT_METADATA 91 ZFS_AC_KERNEL_SRC_CLEAR_INODE 92 ZFS_AC_KERNEL_SRC_SETATTR_PREPARE 93 ZFS_AC_KERNEL_SRC_INSERT_INODE_LOCKED 94 ZFS_AC_KERNEL_SRC_DENTRY 95 ZFS_AC_KERNEL_SRC_TRUNCATE_SETSIZE 96 ZFS_AC_KERNEL_SRC_SECURITY_INODE 97 ZFS_AC_KERNEL_SRC_FST_MOUNT 98 ZFS_AC_KERNEL_SRC_BDI 99 ZFS_AC_KERNEL_SRC_SET_NLINK 100 ZFS_AC_KERNEL_SRC_SGET 101 ZFS_AC_KERNEL_SRC_LSEEK_EXECUTE 102 ZFS_AC_KERNEL_SRC_VFS_GETATTR 103 ZFS_AC_KERNEL_SRC_VFS_FSYNC_2ARGS 104 ZFS_AC_KERNEL_SRC_VFS_ITERATE 105 ZFS_AC_KERNEL_SRC_VFS_DIRECT_IO 106 ZFS_AC_KERNEL_SRC_VFS_RW_ITERATE 107 ZFS_AC_KERNEL_SRC_VFS_GENERIC_WRITE_CHECKS 108 ZFS_AC_KERNEL_SRC_VFS_IOV_ITER 109 ZFS_AC_KERNEL_SRC_KMAP_ATOMIC_ARGS 110 ZFS_AC_KERNEL_SRC_FOLLOW_DOWN_ONE 111 ZFS_AC_KERNEL_SRC_MAKE_REQUEST_FN 112 ZFS_AC_KERNEL_SRC_GENERIC_IO_ACCT 113 ZFS_AC_KERNEL_SRC_FPU 114 ZFS_AC_KERNEL_SRC_FMODE_T 115 ZFS_AC_KERNEL_SRC_KUIDGID_T 116 ZFS_AC_KERNEL_SRC_KUID_HELPERS 117 ZFS_AC_KERNEL_SRC_MODULE_PARAM_CALL_CONST 118 ZFS_AC_KERNEL_SRC_RENAME_WANTS_FLAGS 119 ZFS_AC_KERNEL_SRC_CURRENT_TIME 120 ZFS_AC_KERNEL_SRC_USERNS_CAPABILITIES 121 ZFS_AC_KERNEL_SRC_IN_COMPAT_SYSCALL 122 ZFS_AC_KERNEL_SRC_KTIME 123 ZFS_AC_KERNEL_SRC_TOTALRAM_PAGES_FUNC 124 ZFS_AC_KERNEL_SRC_TOTALHIGH_PAGES 125 ZFS_AC_KERNEL_SRC_KSTRTOUL 126 ZFS_AC_KERNEL_SRC_PERCPU 127 ZFS_AC_KERNEL_SRC_CPU_HOTPLUG 128 129 AC_MSG_CHECKING([for available kernel interfaces]) 130 ZFS_LINUX_TEST_COMPILE_ALL([kabi]) 131 AC_MSG_RESULT([done]) 132]) 133 134dnl # 135dnl # Check results of kernel interface tests. 136dnl # 137AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [ 138 ZFS_AC_KERNEL_ACCESS_OK_TYPE 139 ZFS_AC_KERNEL_GLOBAL_PAGE_STATE 140 ZFS_AC_KERNEL_OBJTOOL 141 ZFS_AC_KERNEL_PDE_DATA 142 ZFS_AC_KERNEL_FALLOCATE 143 ZFS_AC_KERNEL_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE 144 ZFS_AC_KERNEL_RWSEM 145 ZFS_AC_KERNEL_SCHED 146 ZFS_AC_KERNEL_USLEEP_RANGE 147 ZFS_AC_KERNEL_KMEM_CACHE 148 ZFS_AC_KERNEL_KVMALLOC 149 ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL 150 ZFS_AC_KERNEL_WAIT 151 ZFS_AC_KERNEL_INODE_TIMES 152 ZFS_AC_KERNEL_INODE_LOCK 153 ZFS_AC_KERNEL_GROUP_INFO_GID 154 ZFS_AC_KERNEL_RW 155 ZFS_AC_KERNEL_TIMER_SETUP 156 ZFS_AC_KERNEL_SUPER_USER_NS 157 ZFS_AC_KERNEL_PROC_OPERATIONS 158 ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS 159 ZFS_AC_KERNEL_BIO 160 ZFS_AC_KERNEL_BLKDEV 161 ZFS_AC_KERNEL_BLK_QUEUE 162 ZFS_AC_KERNEL_REVALIDATE_DISK 163 ZFS_AC_KERNEL_GET_DISK_RO 164 ZFS_AC_KERNEL_GENERIC_READLINK_GLOBAL 165 ZFS_AC_KERNEL_DISCARD_GRANULARITY 166 ZFS_AC_KERNEL_INODE_OWNER_OR_CAPABLE 167 ZFS_AC_KERNEL_XATTR 168 ZFS_AC_KERNEL_ACL 169 ZFS_AC_KERNEL_INODE_GETATTR 170 ZFS_AC_KERNEL_INODE_SET_FLAGS 171 ZFS_AC_KERNEL_INODE_SET_IVERSION 172 ZFS_AC_KERNEL_SHOW_OPTIONS 173 ZFS_AC_KERNEL_FILE_INODE 174 ZFS_AC_KERNEL_FILE_DENTRY 175 ZFS_AC_KERNEL_FSYNC 176 ZFS_AC_KERNEL_AIO_FSYNC 177 ZFS_AC_KERNEL_EVICT_INODE 178 ZFS_AC_KERNEL_DIRTY_INODE 179 ZFS_AC_KERNEL_SHRINKER 180 ZFS_AC_KERNEL_MKDIR_UMODE_T 181 ZFS_AC_KERNEL_LOOKUP_FLAGS 182 ZFS_AC_KERNEL_CREATE_FLAGS 183 ZFS_AC_KERNEL_GET_LINK 184 ZFS_AC_KERNEL_PUT_LINK 185 ZFS_AC_KERNEL_TMPFILE 186 ZFS_AC_KERNEL_AUTOMOUNT 187 ZFS_AC_KERNEL_ENCODE_FH_WITH_INODE 188 ZFS_AC_KERNEL_COMMIT_METADATA 189 ZFS_AC_KERNEL_CLEAR_INODE 190 ZFS_AC_KERNEL_SETATTR_PREPARE 191 ZFS_AC_KERNEL_INSERT_INODE_LOCKED 192 ZFS_AC_KERNEL_DENTRY 193 ZFS_AC_KERNEL_TRUNCATE_SETSIZE 194 ZFS_AC_KERNEL_SECURITY_INODE 195 ZFS_AC_KERNEL_FST_MOUNT 196 ZFS_AC_KERNEL_BDI 197 ZFS_AC_KERNEL_SET_NLINK 198 ZFS_AC_KERNEL_SGET 199 ZFS_AC_KERNEL_LSEEK_EXECUTE 200 ZFS_AC_KERNEL_VFS_GETATTR 201 ZFS_AC_KERNEL_VFS_FSYNC_2ARGS 202 ZFS_AC_KERNEL_VFS_ITERATE 203 ZFS_AC_KERNEL_VFS_DIRECT_IO 204 ZFS_AC_KERNEL_VFS_RW_ITERATE 205 ZFS_AC_KERNEL_VFS_GENERIC_WRITE_CHECKS 206 ZFS_AC_KERNEL_VFS_IOV_ITER 207 ZFS_AC_KERNEL_KMAP_ATOMIC_ARGS 208 ZFS_AC_KERNEL_FOLLOW_DOWN_ONE 209 ZFS_AC_KERNEL_MAKE_REQUEST_FN 210 ZFS_AC_KERNEL_GENERIC_IO_ACCT 211 ZFS_AC_KERNEL_FPU 212 ZFS_AC_KERNEL_FMODE_T 213 ZFS_AC_KERNEL_KUIDGID_T 214 ZFS_AC_KERNEL_KUID_HELPERS 215 ZFS_AC_KERNEL_MODULE_PARAM_CALL_CONST 216 ZFS_AC_KERNEL_RENAME_WANTS_FLAGS 217 ZFS_AC_KERNEL_CURRENT_TIME 218 ZFS_AC_KERNEL_USERNS_CAPABILITIES 219 ZFS_AC_KERNEL_IN_COMPAT_SYSCALL 220 ZFS_AC_KERNEL_KTIME 221 ZFS_AC_KERNEL_TOTALRAM_PAGES_FUNC 222 ZFS_AC_KERNEL_TOTALHIGH_PAGES 223 ZFS_AC_KERNEL_KSTRTOUL 224 ZFS_AC_KERNEL_PERCPU 225 ZFS_AC_KERNEL_CPU_HOTPLUG 226]) 227 228dnl # 229dnl # Detect name used for Module.symvers file in kernel 230dnl # 231AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [ 232 modpost=$LINUX/scripts/Makefile.modpost 233 AC_MSG_CHECKING([kernel file name for module symbols]) 234 AS_IF([test "x$enable_linux_builtin" != xyes -a -f "$modpost"], [ 235 AS_IF([grep -q Modules.symvers $modpost], [ 236 LINUX_SYMBOLS=Modules.symvers 237 ], [ 238 LINUX_SYMBOLS=Module.symvers 239 ]) 240 241 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [ 242 AC_MSG_ERROR([ 243 *** Please make sure the kernel devel package for your distribution 244 *** is installed. If you are building with a custom kernel, make sure 245 *** the kernel is configured, built, and the '--with-linux=PATH' 246 *** configure option refers to the location of the kernel source. 247 ]) 248 ]) 249 ], [ 250 LINUX_SYMBOLS=NONE 251 ]) 252 AC_MSG_RESULT($LINUX_SYMBOLS) 253 AC_SUBST(LINUX_SYMBOLS) 254]) 255 256dnl # 257dnl # Detect the kernel to be built against 258dnl # 259AC_DEFUN([ZFS_AC_KERNEL], [ 260 AC_ARG_WITH([linux], 261 AS_HELP_STRING([--with-linux=PATH], 262 [Path to kernel source]), 263 [kernelsrc="$withval"]) 264 265 AC_ARG_WITH(linux-obj, 266 AS_HELP_STRING([--with-linux-obj=PATH], 267 [Path to kernel build objects]), 268 [kernelbuild="$withval"]) 269 270 AC_MSG_CHECKING([kernel source directory]) 271 AS_IF([test -z "$kernelsrc"], [ 272 AS_IF([test -e "/lib/modules/$(uname -r)/source"], [ 273 headersdir="/lib/modules/$(uname -r)/source" 274 sourcelink=$(readlink -f "$headersdir") 275 ], [test -e "/lib/modules/$(uname -r)/build"], [ 276 headersdir="/lib/modules/$(uname -r)/build" 277 sourcelink=$(readlink -f "$headersdir") 278 ], [ 279 sourcelink=$(ls -1d /usr/src/kernels/* \ 280 /usr/src/linux-* \ 281 2>/dev/null | grep -v obj | tail -1) 282 ]) 283 284 AS_IF([test -n "$sourcelink" && test -e ${sourcelink}], [ 285 kernelsrc=`readlink -f ${sourcelink}` 286 ], [ 287 kernelsrc="[Not found]" 288 ]) 289 ], [ 290 AS_IF([test "$kernelsrc" = "NONE"], [ 291 kernsrcver=NONE 292 ]) 293 withlinux=yes 294 ]) 295 296 AC_MSG_RESULT([$kernelsrc]) 297 AS_IF([test ! -d "$kernelsrc"], [ 298 AC_MSG_ERROR([ 299 *** Please make sure the kernel devel package for your distribution 300 *** is installed and then try again. If that fails, you can specify the 301 *** location of the kernel source with the '--with-linux=PATH' option.]) 302 ]) 303 304 AC_MSG_CHECKING([kernel build directory]) 305 AS_IF([test -z "$kernelbuild"], [ 306 AS_IF([test x$withlinux != xyes -a -e "/lib/modules/$(uname -r)/build"], [ 307 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build` 308 ], [test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}], [ 309 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu} 310 ], [test -d ${kernelsrc}-obj/${target_cpu}/default], [ 311 kernelbuild=${kernelsrc}-obj/${target_cpu}/default 312 ], [test -d `dirname ${kernelsrc}`/build-${target_cpu}], [ 313 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu} 314 ], [ 315 kernelbuild=${kernelsrc} 316 ]) 317 ]) 318 AC_MSG_RESULT([$kernelbuild]) 319 320 AC_MSG_CHECKING([kernel source version]) 321 utsrelease1=$kernelbuild/include/linux/version.h 322 utsrelease2=$kernelbuild/include/linux/utsrelease.h 323 utsrelease3=$kernelbuild/include/generated/utsrelease.h 324 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1], [ 325 utsrelease=$utsrelease1 326 ], [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2], [ 327 utsrelease=$utsrelease2 328 ], [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3], [ 329 utsrelease=$utsrelease3 330 ]) 331 332 AS_IF([test -n "$utsrelease"], [ 333 kernsrcver=$($AWK '/UTS_RELEASE/ { gsub(/"/, "", $[3]); print $[3] }' $utsrelease) 334 AS_IF([test -z "$kernsrcver"], [ 335 AC_MSG_RESULT([Not found]) 336 AC_MSG_ERROR([ 337 *** Cannot determine kernel version. 338 ]) 339 ]) 340 ], [ 341 AC_MSG_RESULT([Not found]) 342 if test "x$enable_linux_builtin" != xyes; then 343 AC_MSG_ERROR([ 344 *** Cannot find UTS_RELEASE definition. 345 ]) 346 else 347 AC_MSG_ERROR([ 348 *** Cannot find UTS_RELEASE definition. 349 *** Please run 'make prepare' inside the kernel source tree.]) 350 fi 351 ]) 352 353 AC_MSG_RESULT([$kernsrcver]) 354 355 AS_VERSION_COMPARE([$kernsrcver], [$ZFS_META_KVER_MIN], [ 356 AC_MSG_ERROR([ 357 *** Cannot build against kernel version $kernsrcver. 358 *** The minimum supported kernel version is $ZFS_META_KVER_MIN. 359 ]) 360 ]) 361 362 LINUX=${kernelsrc} 363 LINUX_OBJ=${kernelbuild} 364 LINUX_VERSION=${kernsrcver} 365 366 AC_SUBST(LINUX) 367 AC_SUBST(LINUX_OBJ) 368 AC_SUBST(LINUX_VERSION) 369 370 ZFS_AC_MODULE_SYMVERS 371]) 372 373dnl # 374dnl # Detect the QAT module to be built against, QAT provides hardware 375dnl # acceleration for data compression: 376dnl # 377dnl # https://01.org/intel-quickassist-technology 378dnl # 379dnl # 1) Download and install QAT driver from the above link 380dnl # 2) Start QAT driver in your system: 381dnl # service qat_service start 382dnl # 3) Enable QAT in ZFS, e.g.: 383dnl # ./configure --with-qat=<qat-driver-path>/QAT1.6 384dnl # make 385dnl # 4) Set GZIP compression in ZFS dataset: 386dnl # zfs set compression = gzip <dataset> 387dnl # 388dnl # Then the data written to this ZFS pool is compressed by QAT accelerator 389dnl # automatically, and de-compressed by QAT when read from the pool. 390dnl # 391dnl # 1) Get QAT hardware statistics with: 392dnl # cat /proc/icp_dh895xcc_dev/qat 393dnl # 2) To disable QAT: 394dnl # insmod zfs.ko zfs_qat_disable=1 395dnl # 396AC_DEFUN([ZFS_AC_QAT], [ 397 AC_ARG_WITH([qat], 398 AS_HELP_STRING([--with-qat=PATH], 399 [Path to qat source]), 400 AS_IF([test "$withval" = "yes"], 401 AC_MSG_ERROR([--with-qat=PATH requires a PATH]), 402 [qatsrc="$withval"])) 403 404 AC_ARG_WITH([qat-obj], 405 AS_HELP_STRING([--with-qat-obj=PATH], 406 [Path to qat build objects]), 407 [qatbuild="$withval"]) 408 409 AS_IF([test ! -z "${qatsrc}"], [ 410 AC_MSG_CHECKING([qat source directory]) 411 AC_MSG_RESULT([$qatsrc]) 412 QAT_SRC="${qatsrc}/quickassist" 413 AS_IF([ test ! -e "$QAT_SRC/include/cpa.h"], [ 414 AC_MSG_ERROR([ 415 *** Please make sure the qat driver package is installed 416 *** and specify the location of the qat source with the 417 *** '--with-qat=PATH' option then try again. Failed to 418 *** find cpa.h in: 419 ${QAT_SRC}/include]) 420 ]) 421 ]) 422 423 AS_IF([test ! -z "${qatsrc}"], [ 424 AC_MSG_CHECKING([qat build directory]) 425 AS_IF([test -z "$qatbuild"], [ 426 qatbuild="${qatsrc}/build" 427 ]) 428 429 AC_MSG_RESULT([$qatbuild]) 430 QAT_OBJ=${qatbuild} 431 AS_IF([ ! test -e "$QAT_OBJ/icp_qa_al.ko" && ! test -e "$QAT_OBJ/qat_api.ko"], [ 432 AC_MSG_ERROR([ 433 *** Please make sure the qat driver is installed then try again. 434 *** Failed to find icp_qa_al.ko or qat_api.ko in: 435 $QAT_OBJ]) 436 ]) 437 438 AC_SUBST(QAT_SRC) 439 AC_SUBST(QAT_OBJ) 440 441 AC_DEFINE(HAVE_QAT, 1, 442 [qat is enabled and existed]) 443 ]) 444 445 dnl # 446 dnl # Detect the name used for the QAT Module.symvers file. 447 dnl # 448 AS_IF([test ! -z "${qatsrc}"], [ 449 AC_MSG_CHECKING([qat file for module symbols]) 450 QAT_SYMBOLS=$QAT_SRC/lookaside/access_layer/src/Module.symvers 451 452 AS_IF([test -r $QAT_SYMBOLS], [ 453 AC_MSG_RESULT([$QAT_SYMBOLS]) 454 AC_SUBST(QAT_SYMBOLS) 455 ],[ 456 AC_MSG_ERROR([ 457 *** Please make sure the qat driver is installed then try again. 458 *** Failed to find Module.symvers in: 459 $QAT_SYMBOLS 460 ]) 461 ]) 462 ]) 463]) 464 465dnl # 466dnl # Basic toolchain sanity check. 467dnl # 468AC_DEFUN([ZFS_AC_KERNEL_TEST_MODULE], [ 469 AC_MSG_CHECKING([whether modules can be built]) 470 ZFS_LINUX_TRY_COMPILE([], [], [ 471 AC_MSG_RESULT([yes]) 472 ],[ 473 AC_MSG_RESULT([no]) 474 if test "x$enable_linux_builtin" != xyes; then 475 AC_MSG_ERROR([ 476 *** Unable to build an empty module. 477 ]) 478 else 479 AC_MSG_ERROR([ 480 *** Unable to build an empty module. 481 *** Please run 'make scripts' inside the kernel source tree.]) 482 fi 483 ]) 484]) 485 486dnl # 487dnl # ZFS_LINUX_CONFTEST_H 488dnl # 489AC_DEFUN([ZFS_LINUX_CONFTEST_H], [ 490test -d build/$2 || mkdir -p build/$2 491cat - <<_ACEOF >build/$2/$2.h 492$1 493_ACEOF 494]) 495 496dnl # 497dnl # ZFS_LINUX_CONFTEST_C 498dnl # 499AC_DEFUN([ZFS_LINUX_CONFTEST_C], [ 500test -d build/$2 || mkdir -p build/$2 501cat confdefs.h - <<_ACEOF >build/$2/$2.c 502$1 503_ACEOF 504]) 505 506dnl # 507dnl # ZFS_LINUX_CONFTEST_MAKEFILE 508dnl # 509dnl # $1 - test case name 510dnl # $2 - add to top-level Makefile 511dnl # $3 - additional build flags 512dnl # 513AC_DEFUN([ZFS_LINUX_CONFTEST_MAKEFILE], [ 514 test -d build || mkdir -p build 515 test -d build/$1 || mkdir -p build/$1 516 517 file=build/$1/Makefile 518 519 dnl # Example command line to manually build source. 520 cat - <<_ACEOF >$file 521# Example command line to manually build source 522# make modules -C $LINUX_OBJ $ARCH_UM M=$PWD/build/$1 523 524ccflags-y := -Werror $FRAME_LARGER_THAN 525_ACEOF 526 527 dnl # Additional custom CFLAGS as requested. 528 m4_ifval($3, [echo "ccflags-y += $3" >>$file], []) 529 530 dnl # Test case source 531 echo "obj-m := $1.o" >>$file 532 533 AS_IF([test "x$2" = "xyes"], [echo "obj-m += $1/" >>build/Makefile], []) 534]) 535 536dnl # 537dnl # ZFS_LINUX_TEST_PROGRAM(C)([PROLOGUE], [BODY]) 538dnl # 539m4_define([ZFS_LINUX_TEST_PROGRAM], [ 540#include <linux/module.h> 541$1 542 543int 544main (void) 545{ 546$2 547 ; 548 return 0; 549} 550 551MODULE_DESCRIPTION("conftest"); 552MODULE_AUTHOR(ZFS_META_AUTHOR); 553MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE); 554MODULE_LICENSE($3); 555]) 556 557dnl # 558dnl # ZFS_LINUX_TEST_REMOVE 559dnl # 560dnl # Removes the specified test source and results. 561dnl # 562AC_DEFUN([ZFS_LINUX_TEST_REMOVE], [ 563 test -d build/$1 && rm -Rf build/$1 564 test -f build/Makefile && sed '/$1/d' build/Makefile 565]) 566 567dnl # 568dnl # ZFS_LINUX_COMPILE 569dnl # 570dnl # $1 - build dir 571dnl # $2 - test command 572dnl # $3 - pass command 573dnl # $4 - fail command 574dnl # $5 - set KBUILD_MODPOST_NOFINAL='yes' 575dnl # $6 - set KBUILD_MODPOST_WARN='yes' 576dnl # 577dnl # Used internally by ZFS_LINUX_TEST_{COMPILE,MODPOST} 578dnl # 579AC_DEFUN([ZFS_LINUX_COMPILE], [ 580 AC_TRY_COMMAND([ 581 KBUILD_MODPOST_NOFINAL="$5" KBUILD_MODPOST_WARN="$6" 582 make modules -k -j$TEST_JOBS -C $LINUX_OBJ $ARCH_UM 583 M=$PWD/$1 >$1/build.log 2>&1]) 584 AS_IF([AC_TRY_COMMAND([$2])], [$3], [$4]) 585]) 586 587dnl # 588dnl # ZFS_LINUX_TEST_COMPILE 589dnl # 590dnl # Perform a full compile excluding the final modpost phase. 591dnl # 592AC_DEFUN([ZFS_LINUX_TEST_COMPILE], [ 593 ZFS_LINUX_COMPILE([$2], [test -f $2/build.log], [ 594 mv $2/Makefile $2/Makefile.compile.$1 595 mv $2/build.log $2/build.log.$1 596 ],[ 597 AC_MSG_ERROR([ 598 *** Unable to compile test source to determine kernel interfaces.]) 599 ], [yes], []) 600]) 601 602dnl # 603dnl # ZFS_LINUX_TEST_MODPOST 604dnl # 605dnl # Perform a full compile including the modpost phase. This may 606dnl # be an incremental build if the objects have already been built. 607dnl # 608AC_DEFUN([ZFS_LINUX_TEST_MODPOST], [ 609 ZFS_LINUX_COMPILE([$2], [test -f $2/build.log], [ 610 mv $2/Makefile $2/Makefile.modpost.$1 611 cat $2/build.log >>build/build.log.$1 612 ],[ 613 AC_MSG_ERROR([ 614 *** Unable to modpost test source to determine kernel interfaces.]) 615 ], [], [yes]) 616]) 617 618dnl # 619dnl # Perform the compilation of the test cases in two phases. 620dnl # 621dnl # Phase 1) attempt to build the object files for all of the tests 622dnl # defined by the ZFS_LINUX_TEST_SRC macro. But do not 623dnl # perform the final modpost stage. 624dnl # 625dnl # Phase 2) disable all tests which failed the initial compilation, 626dnl # then invoke the final modpost step for the remaining tests. 627dnl # 628dnl # This allows us efficiently build the test cases in parallel while 629dnl # remaining resilient to build failures which are expected when 630dnl # detecting the available kernel interfaces. 631dnl # 632dnl # The maximum allowed parallelism can be controlled by setting the 633dnl # TEST_JOBS environment variable. Otherwise, it default to $(nproc). 634dnl # 635AC_DEFUN([ZFS_LINUX_TEST_COMPILE_ALL], [ 636 dnl # Phase 1 - Compilation only, final linking is skipped. 637 ZFS_LINUX_TEST_COMPILE([$1], [build]) 638 639 dnl # 640 dnl # Phase 2 - When building external modules disable test cases 641 dnl # which failed to compile and invoke modpost to verify the 642 dnl # final linking. 643 dnl # 644 dnl # Test names suffixed with '_license' call modpost independently 645 dnl # to ensure that a single incompatibility does not result in the 646 dnl # modpost phase exiting early. This check is not performed on 647 dnl # every symbol since the majority are compatible and doing so 648 dnl # would significantly slow down this phase. 649 dnl # 650 dnl # When configuring for builtin (--enable-linux-builtin) 651 dnl # fake the linking step artificially create the expected .ko 652 dnl # files for tests which did compile. This is required for 653 dnl # kernels which do not have loadable module support or have 654 dnl # not yet been built. 655 dnl # 656 AS_IF([test "x$enable_linux_builtin" = "xno"], [ 657 for dir in $(awk '/^obj-m/ { print [$]3 }' \ 658 build/Makefile.compile.$1); do 659 name=${dir%/} 660 AS_IF([test -f build/$name/$name.o], [ 661 AS_IF([test "${name##*_}" = "license"], [ 662 ZFS_LINUX_TEST_MODPOST([$1], 663 [build/$name]) 664 echo "obj-n += $dir" >>build/Makefile 665 ], [ 666 echo "obj-m += $dir" >>build/Makefile 667 ]) 668 ], [ 669 echo "obj-n += $dir" >>build/Makefile 670 ]) 671 done 672 673 ZFS_LINUX_TEST_MODPOST([$1], [build]) 674 ], [ 675 for dir in $(awk '/^obj-m/ { print [$]3 }' \ 676 build/Makefile.compile.$1); do 677 name=${dir%/} 678 AS_IF([test -f build/$name/$name.o], [ 679 touch build/$name/$name.ko 680 ]) 681 done 682 ]) 683]) 684 685dnl # 686dnl # ZFS_LINUX_TEST_SRC 687dnl # 688dnl # $1 - name 689dnl # $2 - global 690dnl # $3 - source 691dnl # $4 - extra cflags 692dnl # $5 - check license-compatibility 693dnl # 694dnl # Check if the test source is buildable at all and then if it is 695dnl # license compatible. 696dnl # 697dnl # N.B because all of the test cases are compiled in parallel they 698dnl # must never depend on the results of previous tests. Each test 699dnl # needs to be entirely independent. 700dnl # 701AC_DEFUN([ZFS_LINUX_TEST_SRC], [ 702 ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM([[$2]], [[$3]], 703 [["Dual BSD/GPL"]])], [$1]) 704 ZFS_LINUX_CONFTEST_MAKEFILE([$1], [yes], [$4]) 705 706 AS_IF([ test -n "$5" ], [ 707 ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM( 708 [[$2]], [[$3]], [[$5]])], [$1_license]) 709 ZFS_LINUX_CONFTEST_MAKEFILE([$1_license], [yes], [$4]) 710 ]) 711]) 712 713dnl # 714dnl # ZFS_LINUX_TEST_RESULT 715dnl # 716dnl # $1 - name of a test source (ZFS_LINUX_TEST_SRC) 717dnl # $2 - run on success (valid .ko generated) 718dnl # $3 - run on failure (unable to compile) 719dnl # 720AC_DEFUN([ZFS_LINUX_TEST_RESULT], [ 721 AS_IF([test -d build/$1], [ 722 AS_IF([test -f build/$1/$1.ko], [$2], [$3]) 723 ], [ 724 AC_MSG_ERROR([ 725 *** No matching source for the "$1" test, check that 726 *** both the test source and result macros refer to the same name. 727 ]) 728 ]) 729]) 730 731dnl # 732dnl # ZFS_LINUX_TEST_ERROR 733dnl # 734dnl # Generic error message which can be used when none of the expected 735dnl # kernel interfaces were detected. 736dnl # 737AC_DEFUN([ZFS_LINUX_TEST_ERROR], [ 738 AC_MSG_ERROR([ 739 *** None of the expected "$1" interfaces were detected. 740 *** This may be because your kernel version is newer than what is 741 *** supported, or you are using a patched custom kernel with 742 *** incompatible modifications. 743 *** 744 *** ZFS Version: $ZFS_META_ALIAS 745 *** Compatible Kernels: $ZFS_META_KVER_MIN - $ZFS_META_KVER_MAX 746 ]) 747]) 748 749dnl # 750dnl # ZFS_LINUX_TEST_RESULT_SYMBOL 751dnl # 752dnl # Like ZFS_LINUX_TEST_RESULT except ZFS_CHECK_SYMBOL_EXPORT is called to 753dnl # verify symbol exports, unless --enable-linux-builtin was provided to 754dnl # configure. 755dnl # 756AC_DEFUN([ZFS_LINUX_TEST_RESULT_SYMBOL], [ 757 AS_IF([ ! test -f build/$1/$1.ko], [ 758 $5 759 ], [ 760 AS_IF([test "x$enable_linux_builtin" != "xyes"], [ 761 ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [$4], [$5]) 762 ], [ 763 $4 764 ]) 765 ]) 766]) 767 768dnl # 769dnl # ZFS_LINUX_COMPILE_IFELSE 770dnl # 771AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [ 772 ZFS_LINUX_TEST_REMOVE([conftest]) 773 774 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST_C([$1], [conftest])]) 775 m4_ifvaln([$5], [ZFS_LINUX_CONFTEST_H([$5], [conftest])], 776 [ZFS_LINUX_CONFTEST_H([], [conftest])]) 777 778 ZFS_LINUX_CONFTEST_MAKEFILE([conftest], [no], 779 [m4_ifvaln([$5], [-I$PWD/build/conftest], [])]) 780 ZFS_LINUX_COMPILE([build/conftest], [$2], [$3], [$4], [], []) 781]) 782 783dnl # 784dnl # ZFS_LINUX_TRY_COMPILE 785dnl # 786dnl # $1 - global 787dnl # $2 - source 788dnl # $3 - run on success (valid .ko generated) 789dnl # $4 - run on failure (unable to compile) 790dnl # 791dnl # When configuring as builtin (--enable-linux-builtin) for kernels 792dnl # without loadable module support (CONFIG_MODULES=n) only the object 793dnl # file is created. See ZFS_LINUX_TEST_COMPILE_ALL for details. 794dnl # 795AC_DEFUN([ZFS_LINUX_TRY_COMPILE], [ 796 AS_IF([test "x$enable_linux_builtin" = "xyes"], [ 797 ZFS_LINUX_COMPILE_IFELSE( 798 [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]], 799 [[ZFS_META_LICENSE]])], 800 [test -f build/conftest/conftest.o], [$3], [$4]) 801 ], [ 802 ZFS_LINUX_COMPILE_IFELSE( 803 [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]], 804 [[ZFS_META_LICENSE]])], 805 [test -f build/conftest/conftest.ko], [$3], [$4]) 806 ]) 807]) 808 809dnl # 810dnl # ZFS_CHECK_SYMBOL_EXPORT 811dnl # 812dnl # Check if a symbol is exported on not by consulting the symbols 813dnl # file, or optionally the source code. 814dnl # 815AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT], [ 816 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \ 817 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null 818 rc=$? 819 if test $rc -ne 0; then 820 export=0 821 for file in $2; do 822 grep -q -E "EXPORT_SYMBOL.*($1)" \ 823 "$LINUX/$file" 2>/dev/null 824 rc=$? 825 if test $rc -eq 0; then 826 export=1 827 break; 828 fi 829 done 830 if test $export -eq 0; then : 831 $4 832 else : 833 $3 834 fi 835 else : 836 $3 837 fi 838]) 839 840dnl # 841dnl # ZFS_LINUX_TRY_COMPILE_SYMBOL 842dnl # 843dnl # Like ZFS_LINUX_TRY_COMPILER except ZFS_CHECK_SYMBOL_EXPORT is called 844dnl # to verify symbol exports, unless --enable-linux-builtin was provided 845dnl # to configure. 846dnl # 847AC_DEFUN([ZFS_LINUX_TRY_COMPILE_SYMBOL], [ 848 ZFS_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1]) 849 if test $rc -ne 0; then : 850 $6 851 else 852 if test "x$enable_linux_builtin" != xyes; then 853 ZFS_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1]) 854 fi 855 if test $rc -ne 0; then : 856 $6 857 else : 858 $5 859 fi 860 fi 861]) 862 863dnl # 864dnl # ZFS_LINUX_TRY_COMPILE_HEADER 865dnl # like ZFS_LINUX_TRY_COMPILE, except the contents conftest.h are 866dnl # provided via the fifth parameter 867dnl # 868AC_DEFUN([ZFS_LINUX_TRY_COMPILE_HEADER], [ 869 ZFS_LINUX_COMPILE_IFELSE( 870 [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]], [[ZFS_META_LICENSE]])], 871 [test -f build/conftest/conftest.ko], 872 [$3], [$4], [$5]) 873]) 874