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