Whamcloud - gitweb
864620551616dd2ca7248e63210d2434fcb0d013
[fs/lustre-release.git] / libcfs / autoconf / lustre-libcfs.m4
1 #
2 # LIBCFS_CONFIG_CDEBUG
3 #
4 # whether to enable various libcfs debugs (CDEBUG, ENTRY/EXIT, LASSERT, etc.)
5 #
6 AC_DEFUN([LIBCFS_CONFIG_CDEBUG], [
7 AC_MSG_CHECKING([whether to enable CDEBUG, CWARN])
8 AC_ARG_ENABLE([libcfs_cdebug],
9         AC_HELP_STRING([--disable-libcfs-cdebug],
10                 [disable libcfs CDEBUG, CWARN]),
11         [], [enable_libcfs_cdebug="yes"])
12 AC_MSG_RESULT([$enable_libcfs_cdebug])
13 AS_IF([test "x$enable_libcfs_cdebug" = xyes],
14         [AC_DEFINE(CDEBUG_ENABLED, 1, [enable libcfs CDEBUG, CWARN])])
15
16 AC_MSG_CHECKING([whether to enable ENTRY/EXIT])
17 AC_ARG_ENABLE([libcfs_trace],
18         AC_HELP_STRING([--disable-libcfs-trace],
19                 [disable libcfs ENTRY/EXIT]),
20         [], [enable_libcfs_trace="yes"])
21 AC_MSG_RESULT([$enable_libcfs_trace])
22 AS_IF([test "x$enable_libcfs_trace" = xyes],
23         [AC_DEFINE(CDEBUG_ENTRY_EXIT, 1, [enable libcfs ENTRY/EXIT])])
24
25 AC_MSG_CHECKING([whether to enable LASSERT, LASSERTF])
26 AC_ARG_ENABLE([libcfs_assert],
27         AC_HELP_STRING([--disable-libcfs-assert],
28                 [disable libcfs LASSERT, LASSERTF]),
29         [], [enable_libcfs_assert="yes"])
30 AC_MSG_RESULT([$enable_libcfs_assert])
31 AS_IF([test x$enable_libcfs_assert = xyes],
32         [AC_DEFINE(LIBCFS_DEBUG, 1, [enable libcfs LASSERT, LASSERTF])])
33 ]) # LIBCFS_CONFIG_CDEBUG
34
35 #
36 # LIBCFS_CONFIG_PANIC_DUMPLOG
37 #
38 # check if tunable panic_dumplog is wanted
39 #
40 AC_DEFUN([LIBCFS_CONFIG_PANIC_DUMPLOG], [
41 AC_MSG_CHECKING([whether to use tunable 'panic_dumplog' support])
42 AC_ARG_ENABLE([panic_dumplog],
43         AC_HELP_STRING([--enable-panic_dumplog],
44                 [enable panic_dumplog]),
45         [], [enable_panic_dumplog="no"])
46 AC_MSG_RESULT([$enable_panic_dumplog])
47 AS_IF([test "x$enable_panic_dumplog" = xyes],
48         [AC_DEFINE(LNET_DUMP_ON_PANIC, 1, [use dumplog on panic])])
49 ]) # LIBCFS_CONFIG_PANIC_DUMPLOG
50
51 #
52 # LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
53 #
54 # 2.6.32-30.el6 adds a new 'walk_stack' field in 'struct stacktrace_ops'
55 #
56 AC_DEFUN([LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK], [
57 LB_CHECK_COMPILE([if 'struct stacktrace_ops' has 'walk_stack' field],
58 stacktrace_ops_walk_stack, [
59         #include <asm/stacktrace.h>
60 ],[
61         ((struct stacktrace_ops *)0)->walk_stack(NULL, NULL, 0, NULL, NULL, NULL, NULL);
62 ],[
63         AC_DEFINE(STACKTRACE_OPS_HAVE_WALK_STACK, 1,
64                 ['struct stacktrace_ops' has 'walk_stack' field])
65 ])
66 ]) # LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
67
68 #
69 # LIBCFS_STACKTRACE_WARNING
70 #
71 # 3.0 removes stacktrace_ops warning* functions
72 #
73 AC_DEFUN([LIBCFS_STACKTRACE_WARNING], [
74 LB_CHECK_COMPILE([if 'stacktrace_ops.warning' is exist],
75 stacktrace_ops_warning, [
76         struct task_struct;
77         struct pt_regs;
78         #include <asm/stacktrace.h>
79 ],[
80         ((struct stacktrace_ops *)0)->warning(NULL, NULL);
81 ],[
82         AC_DEFINE(HAVE_STACKTRACE_WARNING, 1,
83                 [stacktrace_ops.warning is exist])
84 ])
85 ]) # LIBCFS_STACKTRACE_WARNING
86
87 #
88 # LC_SHRINKER_WANT_SHRINK_PTR
89 #
90 # RHEL6/2.6.32 want to have pointer to shrinker self pointer in handler function
91 #
92 AC_DEFUN([LC_SHRINKER_WANT_SHRINK_PTR], [
93 LB_CHECK_COMPILE([if 'shrinker' want self pointer in handler],
94 shrink_self_pointer, [
95         #include <linux/mm.h>
96 ],[
97         struct shrinker *tmp = NULL;
98         tmp->shrink(tmp, 0, 0);
99 ],[
100         AC_DEFINE(HAVE_SHRINKER_WANT_SHRINK_PTR, 1,
101                 [shrinker want self pointer in handler])
102 ])
103 ]) # LC_SHRINKER_WANT_SHRINK_PTR
104
105 #
106 # LIBCFS_SYSCTL_CTLNAME
107 #
108 # 2.6.33 no longer has ctl_name & strategy field in struct ctl_table.
109 #
110 AC_DEFUN([LIBCFS_SYSCTL_CTLNAME], [
111 LB_CHECK_COMPILE([if 'ctl_table' has a 'ctl_name' field],
112 ctl_table_ctl_name, [
113         #include <linux/sysctl.h>
114 ],[
115         struct ctl_table ct;
116         ct.ctl_name = sizeof(ct);
117 ],[
118         AC_DEFINE(HAVE_SYSCTL_CTLNAME, 1,
119                 [ctl_table has ctl_name field])
120 ])
121 ]) # LIBCFS_SYSCTL_CTLNAME
122
123 #
124 # LIBCFS_MODULE_LOCKING
125 #
126 # 2.6.36 introduced locking to module params. RHEL6 lacks this support
127 #
128 AC_DEFUN([LIBCFS_MODULE_LOCKING],[
129 LB_CHECK_COMPILE([does the kernel support module param locking],
130 module_param_locking, [
131         #include <linux/moduleparam.h>
132 ],[
133         __kernel_param_lock(NULL);
134         __kernel_param_unlock(NULL);
135 ],[
136         AC_DEFINE(HAVE_MODULE_PARAM_LOCKING, 1,
137                 [locking module param is supported])
138 ])
139 ]) # LIBCFS_MODULE_LOCKING
140
141 #
142 # LIBCFS_KSTRTOUL
143 #
144 # 2.6.38 kstrtoul is added
145 #
146 AC_DEFUN([LIBCFS_KSTRTOUL], [
147 LB_CHECK_COMPILE([if Linux kernel has 'kstrtoul'],
148 kstrtoul, [
149         #include <linux/kernel.h>
150 ],[
151         unsigned long result;
152         return kstrtoul("12345", 0, &result);
153 ],[
154         AC_DEFINE(HAVE_KSTRTOUL, 1,
155                 [kernel has kstrtoul])
156 ])
157 ]) # LIBCFS_KSTRTOUL
158
159 #
160 # LIBCFS_DUMP_TRACE_ADDRESS
161 #
162 # 2.6.39 adds a base pointer address argument to dump_trace
163 #
164 AC_DEFUN([LIBCFS_DUMP_TRACE_ADDRESS], [
165 LB_CHECK_COMPILE([if 'dump_trace' want address],
166 dump_trace_address, [
167         struct task_struct;
168         struct pt_regs;
169         #include <asm/stacktrace.h>
170 ],[
171         dump_trace(NULL, NULL, NULL, 0, NULL, NULL);
172 ],[
173         AC_DEFINE(HAVE_DUMP_TRACE_ADDRESS, 1,
174                 [dump_trace want address argument])
175 ])
176 ]) # LIBCFS_DUMP_TRACE_ADDRESS
177
178 #
179 # LC_SHRINK_CONTROL
180 #
181 # FC15 2.6.40-5 backported the "shrink_control" parameter to the memory
182 # pressure shrinker from Linux 3.0
183 #
184 AC_DEFUN([LC_SHRINK_CONTROL], [
185 LB_CHECK_COMPILE([if 'shrink_control' is present],
186 shrink_control, [
187         #include <linux/atomic.h>
188         #include <linux/mm.h>
189 ],[
190         struct shrink_control tmp = {0};
191         tmp.nr_to_scan = sizeof(tmp);
192 ],[
193         AC_DEFINE(HAVE_SHRINK_CONTROL, 1,
194                 [shrink_control is present])
195 ])
196 ]) # LC_SHRINK_CONTROL
197
198 #
199 # LIBCFS_PROCESS_NAMESPACE
200 #
201 # 3.5 introduced process namespace
202 AC_DEFUN([LIBCFS_PROCESS_NAMESPACE], [
203 LB_CHECK_LINUX_HEADER([linux/uidgid.h], [
204         AC_DEFINE(HAVE_UIDGID_HEADER, 1,
205                 [uidgid.h is present])])
206 ]) # LIBCFS_PROCESS_NAMESPACE
207
208 #
209 # LIBCFS_I_UID_READ
210 #
211 # 3.5 added helpers to read the new uid/gid types from VFS structures
212 # SLE11 SP3 has uidgid.h but not the helpers
213 #
214 AC_DEFUN([LIBCFS_I_UID_READ], [
215 LB_CHECK_COMPILE([if 'i_uid_read' is present],
216 i_uid_read, [
217         #include <linux/fs.h>
218 ],[
219         i_uid_read(NULL);
220 ],[
221         AC_DEFINE(HAVE_I_UID_READ, 1, [i_uid_read is present])
222 ])
223 ]) # LIBCFS_I_UID_READ
224
225 #
226 # LIBCFS_HAVE_CRC32
227 #
228 AC_DEFUN([LIBCFS_HAVE_CRC32], [
229 LB_CHECK_CONFIG_IM([CRC32],
230         [have_crc32="yes"], [have_crc32="no"])
231 AS_IF([test "x$have_crc32" = xyes],
232         [AC_DEFINE(HAVE_CRC32, 1,
233                 [kernel compiled with CRC32 functions])])
234 ]) # LIBCFS_HAVE_CRC32
235
236 #
237 # LIBCFS_ENABLE_CRC32_ACCEL
238 #
239 AC_DEFUN([LIBCFS_ENABLE_CRC32_ACCEL], [
240 LB_CHECK_CONFIG_IM([CRYPTO_CRC32_PCLMUL],
241         [enable_crc32_crypto="no"], [enable_crc32_crypto="yes"])
242 AS_IF([test "x$have_crc32" = xyes -a "x$enable_crc32_crypto" = xyes], [
243         AC_DEFINE(NEED_CRC32_ACCEL, 1, [need pclmulqdq based crc32])
244         AC_MSG_WARN([No crc32 pclmulqdq crypto api found, enable internal pclmulqdq based crc32])])
245 ]) # LIBCFS_ENABLE_CRC32_ACCEL
246
247 #
248 # LIBCFS_ENABLE_CRC32C_ACCEL
249 #
250 AC_DEFUN([LIBCFS_ENABLE_CRC32C_ACCEL], [
251 LB_CHECK_CONFIG_IM([CRYPTO_CRC32C_INTEL],
252         [enable_crc32c_crypto="no"], [enable_crc32c_crypto="yes"])
253 AS_IF([test "x$enable_crc32c_crypto" = xyes], [
254         AC_DEFINE(NEED_CRC32C_ACCEL, 1, [need pclmulqdq based crc32c])
255         AC_MSG_WARN([No crc32c pclmulqdq crypto api found, enable internal pclmulqdq based crc32c])])
256 ]) # LIBCFS_ENABLE_CRC32C_ACCEL
257
258 #
259 # Kernel version v3.8-rc4-82-g4f522a247bc2 exported d_hash_and_lookup()
260 # It was added in v2.6.16-3821-g3e7e241f8c5c, so no worries about header.
261 #
262 AC_DEFUN([LIBCFS_D_HASH_AND_LOOKUP],[
263 LB_CHECK_EXPORT([d_hash_and_lookup], [fs/dcache.c],
264         [AC_DEFINE(HAVE_D_HASH_AND_LOOKUP, 1,
265                 [d_hash_and_lookup is exported by the kernel])])
266 ]) # LIBCFS_D_HASH_AND_LOOKUP
267
268 #
269 # Kernel version 3.11 introduced ktime_get_ts64
270 #
271 AC_DEFUN([LIBCFS_KTIME_GET_TS64],[
272 LB_CHECK_COMPILE([does function 'ktime_get_ts64' exist],
273 ktime_get_ts64, [
274         #include <linux/hrtimer.h>
275         #include <linux/ktime.h>
276 ],[
277         struct timespec64 *ts = NULL;
278
279         ktime_get_ts64(ts);
280 ],[
281         AC_DEFINE(HAVE_KTIME_GET_TS64, 1,
282                 ['ktime_get_ts64' is available])
283 ])
284 ]) # LIBCFS_KTIME_GET_TS64
285
286 #
287 # Kernel version 3.12-rc4 commit c2d816443ef30 added prepare_to_wait_event()
288 #
289 AC_DEFUN([LIBCFS_PREPARE_TO_WAIT_EVENT],[
290 LB_CHECK_COMPILE([does function 'prepare_to_wait_event' exist],
291 prepare_to_wait_event, [
292         #include <linux/wait.h>
293 ],[
294         prepare_to_wait_event(NULL, NULL, 0);
295 ],[
296         AC_DEFINE(HAVE_PREPARE_TO_WAIT_EVENT, 1,
297                 ['prepare_to_wait_event' is available])
298 ])
299 ]) # LIBCFS_PREPARE_TO_WAIT_EVENT
300
301 #
302 # Linux kernel 3.12 introduced struct kernel_param_ops
303 # This has been backported to all lustre supported
304 # clients except RHEL6. We have to handle the differences.
305 #
306 AC_DEFUN([LIBCFS_KERNEL_PARAM_OPS],[
307 LB_CHECK_COMPILE([does 'struct kernel_param_ops' exist],
308 kernel_param_ops, [
309         #include <linux/module.h>
310 ],[
311         struct kernel_param_ops ops;
312
313         ops.set = NULL;
314 ],[
315         AC_DEFINE(HAVE_KERNEL_PARAM_OPS, 1,
316                 ['struct kernel_param_ops' is available])
317 ])
318 ]) # LIBCFS_KERNEL_PARAM_OPS
319
320 #
321 # Kernel version 3.12 introduced ktime_add
322 #
323 AC_DEFUN([LIBCFS_KTIME_ADD],[
324 LB_CHECK_COMPILE([does function 'ktime_add' exist],
325 ktime_add, [
326         #include <linux/hrtimer.h>
327         #include <linux/ktime.h>
328 ],[
329         ktime_t start = ktime_set(0, 0);
330         ktime_t end = start;
331         ktime_t total;
332
333         total = ktime_add(start, end);
334 ],[
335         AC_DEFINE(HAVE_KTIME_ADD, 1,
336                 [ktime_add is available])
337 ])
338 ]) # LIBCFS_KTIME_ADD
339
340 #
341 # Kernel version 3.12 introduced ktime_after
342 #
343 AC_DEFUN([LIBCFS_KTIME_AFTER],[
344 LB_CHECK_COMPILE([does function 'ktime_after' exist],
345 ktime_after, [
346         #include <linux/hrtimer.h>
347         #include <linux/ktime.h>
348 ],[
349         ktime_t start = ktime_set(0, 0);
350         ktime_t end = start;
351
352         ktime_after(start, end);
353 ],[
354         AC_DEFINE(HAVE_KTIME_AFTER, 1,
355                 [ktime_after is available])
356 ])
357 ]) # LIBCFS_KTIME_AFTER
358
359 #
360 # Kernel version 3.12 introduced ktime_before
361 # See linux commit 67cb9366ff5f99868100198efba5ca88aaa6ad25
362 #
363 AC_DEFUN([LIBCFS_KTIME_BEFORE],[
364 LB_CHECK_COMPILE([does function 'ktime_before' exist],
365 ktime_before, [
366         #include <linux/hrtimer.h>
367         #include <linux/ktime.h>
368 ],[
369         ktime_t start = ktime_set(0, 0);
370         ktime_t end = start;
371
372         ktime_before(start, end);
373 ],[
374         AC_DEFINE(HAVE_KTIME_BEFORE, 1,
375                 [ktime_before is available])
376 ])
377 ]) # LIBCFS_KTIME_BEFORE
378
379 #
380 # Kernel version 3.12 introduced ktime_compare
381 #
382 AC_DEFUN([LIBCFS_KTIME_COMPARE],[
383 LB_CHECK_COMPILE([does function 'ktime_compare' exist],
384 ktime_compare, [
385         #include <linux/hrtimer.h>
386         #include <linux/ktime.h>
387 ],[
388         ktime_t start = ktime_set(0, 0);
389         ktime_t end = start;
390
391         ktime_compare(start, end);
392 ],[
393         AC_DEFINE(HAVE_KTIME_COMPARE, 1,
394                 [ktime_compare is available])
395 ])
396 ]) # LIBCFS_KTIME_COMPARE
397
398 #
399 # FC19 3.12 kernel struct shrinker change
400 #
401 AC_DEFUN([LIBCFS_SHRINKER_COUNT],[
402 LB_CHECK_COMPILE([shrinker has 'count_objects'],
403 shrinker_count_objects, [
404         #include <linux/mmzone.h>
405         #include <linux/shrinker.h>
406 ],[
407         struct shrinker shrinker;
408
409         shrinker.count_objects = NULL;
410 ],[
411         AC_DEFINE(HAVE_SHRINKER_COUNT, 1,
412                 [shrinker has count_objects member])
413 ])
414 ]) # LIBCFS_SHRINKER_COUNT
415
416 #
417 # LIBCFS_IOV_ITER_HAS_TYPE
418 #
419 # kernel 3.15-rc4 commit 71d8e532b1549a478e6a6a8a44f309d050294d00
420 # start adding the tag to iov_iter
421 #
422 AC_DEFUN([LIBCFS_IOV_ITER_HAS_TYPE], [
423 tmp_flags="$EXTRA_KCFLAGS"
424 EXTRA_KCFLAGS="-Werror"
425 LB_CHECK_COMPILE([if iov_iter has member type],
426 iov_iter_has_type_member, [
427         #include <linux/uio.h>
428 ],[
429         struct iov_iter iter = { .type = ITER_KVEC };
430         (void)iter;
431 ],[
432         AC_DEFINE(HAVE_IOV_ITER_HAS_TYPE_MEMBER, 1,
433                 [if iov_iter has member type])
434 ])
435 EXTRA_KCFLAGS="$tmp_flags"
436 ]) # LIBCFS_IOV_ITER_HAS_TYPE
437
438 #
439 # Kernel version 3.16 added rhashtable.h in 7e1e77636e36075eb
440 #
441 AC_DEFUN([LIBCFS_LINUX_RHASHTABLE_H],[
442 LB_CHECK_LINUX_HEADER([linux/rhashtable.h], [
443         AC_DEFINE(HAVE_LINUX_RHASHTABLE_H, 1,
444                 [linux/rhashtable.h is present])
445 ])
446 ]) # LIBCFS_LINUX_RHASHTABLE_H
447
448 #
449 # Kernel version 3.17 changed hlist_add_after to
450 # hlist_add_behind
451 #
452 AC_DEFUN([LIBCFS_HLIST_ADD_AFTER],[
453 LB_CHECK_COMPILE([does function 'hlist_add_after' exist],
454 hlist_add_after, [
455         #include <linux/list.h>
456 ],[
457         hlist_add_after(NULL, NULL);
458 ],[
459         AC_DEFINE(HAVE_HLIST_ADD_AFTER, 1,
460                 [hlist_add_after is available])
461 ])
462 ]) # LIBCFS_HLIST_ADD_AFTER
463
464 #
465 # Kernel version 3.17 introduced struct timespec64
466 #
467 AC_DEFUN([LIBCFS_TIMESPEC64],[
468 LB_CHECK_COMPILE([does 'struct timespec64' exist],
469 timespec64, [
470         #include <linux/time.h>
471 ],[
472         struct timespec64 ts;
473
474         ts.tv_sec = 0;
475         ts.tv_nsec = 0;
476 ],[
477         AC_DEFINE(HAVE_TIMESPEC64, 1,
478                 ['struct timespec64' is available])
479 ])
480 ]) # LIBCFS_TIMESPEC64
481
482 #
483 # Kernel version 3.17 introduced ktime_get_real_ts64
484 #
485 AC_DEFUN([LIBCFS_KTIME_GET_REAL_TS64],[
486 LB_CHECK_COMPILE([does function 'ktime_get_real_ts64' exist],
487 ktime_get_real_ts64, [
488         #include <linux/ktime.h>
489 ],[
490         struct timespec64 *ts = NULL;
491
492         ktime_get_real_ts64(ts);
493 ],[
494         AC_DEFINE(HAVE_KTIME_GET_REAL_TS64, 1,
495                 ['ktime_get_real_ts64' is available])
496 ])
497 ]) # LIBCFS_KTIME_GET_REAL_TS64
498
499 #
500 # Kernel version 3.17 introduced ktime_get_real_seconds
501 #
502 AC_DEFUN([LIBCFS_KTIME_GET_REAL_SECONDS],[
503 LB_CHECK_COMPILE([does function 'ktime_get_real_seconds' exist],
504 ktime_get_real_seconds, [
505         #include <linux/hrtimer.h>
506         #include <linux/ktime.h>
507 ],[
508         time64_t now;
509
510         now = ktime_get_real_seconds();
511 ],[
512         AC_DEFINE(HAVE_KTIME_GET_REAL_SECONDS, 1,
513                 ['ktime_get_real_seconds' is available])
514 ])
515 ]) # LIBCFS_KTIME_GET_REAL_SECONDS
516
517 #
518 # Kernel version 3.17 created ktime_get_ns wrapper
519 #
520 AC_DEFUN([LIBCFS_KTIME_GET_NS],[
521 LB_CHECK_COMPILE([does function 'ktime_get_ns' exist],
522 ktime_get_ns, [
523         #include <linux/hrtimer.h>
524         #include <linux/ktime.h>
525 ],[
526         u64 nanoseconds;
527
528         nanoseconds = ktime_get_ns();
529 ],[],[
530         AC_DEFINE(NEED_KTIME_GET_NS, 1,
531                 ['ktime_get_ns' is not available])
532 ])
533 ]) # LIBCFS_KTIME_GET_NS
534
535 #
536 # Kernel version 3.17 created ktime_get_real_ns wrapper
537 #
538 AC_DEFUN([LIBCFS_KTIME_GET_REAL_NS],[
539 LB_CHECK_COMPILE([does function 'ktime_get_real_ns' exist],
540 ktime_get_real_ns, [
541         #include <linux/hrtimer.h>
542         #include <linux/ktime.h>
543 ],[
544         u64 nanoseconds;
545
546         nanoseconds = ktime_get_real_ns();
547 ],[],[
548         AC_DEFINE(NEED_KTIME_GET_REAL_NS, 1,
549                 ['ktime_get_real_ns' is not available])
550 ])
551 ]) # LIBCFS_KTIME_GET_REAL_NS
552
553 #
554 # Kernel version 3.17 introduced ktime_to_timespec64
555 #
556 AC_DEFUN([LIBCFS_KTIME_TO_TIMESPEC64],[
557 LB_CHECK_COMPILE([does function 'ktime_to_timespec64' exist],
558 ktime_to_timespec64, [
559         #include <linux/hrtimer.h>
560         #include <linux/ktime.h>
561 ],[
562         ktime_t now = ktime_set(0, 0);
563         struct timespec64 ts;
564
565         ts = ktime_to_timespec64(now);
566 ],[
567         AC_DEFINE(HAVE_KTIME_TO_TIMESPEC64, 1,
568                 ['ktime_to_timespec64' is available])
569 ])
570 ]) # LIBCFS_KTIME_TO_TIMESPEC64
571
572 #
573 # Kernel version 3.17 introduced timespec64_sub
574 #
575 AC_DEFUN([LIBCFS_TIMESPEC64_SUB],[
576 LB_CHECK_COMPILE([does function 'timespec64_sub' exist],
577 timespec64_sub, [
578         #include <linux/time.h>
579 ],[
580         struct timespec64 later = { }, earlier = { }, diff;
581
582         diff = timespec64_sub(later, earlier);
583 ],[
584         AC_DEFINE(HAVE_TIMESPEC64_SUB, 1,
585                 ['timespec64_sub' is available])
586 ])
587 ]) # LIBCFS_TIMESPEC64_SUB
588
589 #
590 # Kernel version 3.17 introduced timespec64_to_ktime
591 #
592 AC_DEFUN([LIBCFS_TIMESPEC64_TO_KTIME],[
593 LB_CHECK_COMPILE([does function 'timespec64_to_ktime' exist],
594 timespec64_to_ktime, [
595         #include <linux/ktime.h>
596 ],[
597         struct timespec64 ts;
598         ktime_t now;
599
600         now = timespec64_to_ktime(ts);
601 ],[
602         AC_DEFINE(HAVE_TIMESPEC64_TO_KTIME, 1,
603                 ['timespec64_to_ktime' is available])
604 ])
605 ]) # LIBCFS_TIMESPEC64_TO_KTIME
606
607 #
608 # Kernel version 3.19 introduced ktime_get_seconds
609 #
610 AC_DEFUN([LIBCFS_KTIME_GET_SECONDS],[
611 LB_CHECK_COMPILE([does function 'ktime_get_seconds' exist],
612 ktime_get_seconds, [
613         #include <linux/ktime.h>
614 ],[
615         time64_t now;
616
617         now = ktime_get_seconds();
618 ],[
619         AC_DEFINE(HAVE_KTIME_GET_SECONDS, 1,
620                 ['ktime_get_seconds' is available])
621 ])
622 ]) # LIBCFS_KTIME_GET_SECONDS
623
624 #
625 # Kernel version 4.0 commit 41fbf3b39d5eca01527338b4d0ee15ee1ae1023c
626 # introduced the helper function ktime_ms_delta.
627 #
628 AC_DEFUN([LIBCFS_KTIME_MS_DELTA],[
629 LB_CHECK_COMPILE([does function 'ktime_ms_delta' exist],
630 ktime_ms_delta, [
631         #include <linux/ktime.h>
632 ],[
633         ktime_t start = ktime_set(0, 0);
634         ktime_t end = start;
635
636         ktime_ms_delta(start, end);
637 ],[
638         AC_DEFINE(HAVE_KTIME_MS_DELTA, 1,
639                 ['ktime_ms_delta' is available])
640 ])
641 ]) # LIBCFS_KTIME_MS_DELTA
642
643 #
644 # Kernel version 4.1 commit b51d23e4e9fea6f264d39535c2a62d1f51e7ccc3
645 # create per module locks which added kernel_param_[un]lock(). Older
646 # kernels you have to use __kernel_param_[un]lock(). In that case its
647 # a global lock for all modules but that is okay since its a rare event.
648 #
649 AC_DEFUN([LIBCFS_KERNEL_PARAM_LOCK],[
650 LB_CHECK_COMPILE([does function 'kernel_param_[un]lock' exist],
651 kernel_param_lock, [
652         #include <linux/moduleparam.h>
653 ],[
654         kernel_param_lock(NULL);
655         kernel_param_unlock(NULL);
656 ],[
657         AC_DEFINE(HAVE_KERNEL_PARAM_LOCK, 1,
658                 ['kernel_param_[un]lock' is available])
659 ])
660 ]) # LIBCFS_KERNEL_PARAM_LOCK
661
662 #
663 # Kernel version 4.2 changed topology_thread_cpumask
664 # to topology_sibling_cpumask
665 #
666 AC_DEFUN([LIBCFS_HAVE_TOPOLOGY_SIBLING_CPUMASK],[
667 LB_CHECK_COMPILE([does function 'topology_sibling_cpumask' exist],
668 topology_sibling_cpumask, [
669         #include <linux/topology.h>
670 ],[
671         const struct cpumask *mask;
672
673         mask = topology_sibling_cpumask(0);
674 ],[
675         AC_DEFINE(HAVE_TOPOLOGY_SIBLING_CPUMASK, 1,
676                 [topology_sibling_cpumask is available])
677 ])
678 ]) # LIBCFS_HAVE_TOPOLOGY_SIBLING_CPUMASK
679
680 #
681 # Kernel version 4.2 commit df6b35f409af0a8ff1ef62f552b8402f3fef8665
682 # header file i387.h was renamed to fpu/api.h
683 #
684 AC_DEFUN([LIBCFS_FPU_API], [
685 LB_CHECK_LINUX_HEADER([asm/fpu/api.h], [
686         AC_DEFINE(HAVE_FPU_API_HEADER, 1,
687                 [fpu/api.h is present])])
688 ]) # LIBCFS_FPU_API
689
690 #
691 # Kernel version 4.4 commit ef951599074ba4fad2d0efa0a977129b41e6d203
692 # introduced kstrtobool and kstrtobool_from_user.
693 #
694 AC_DEFUN([LIBCFS_KSTRTOBOOL_FROM_USER], [
695 LB_CHECK_COMPILE([if Linux kernel has 'kstrtobool_from_user'],
696 kstrtobool_from_user, [
697         #include <linux/kernel.h>
698 ],[
699         bool result;
700         return kstrtobool_from_user(NULL, 0, &result);
701 ],[
702         AC_DEFINE(HAVE_KSTRTOBOOL_FROM_USER, 1,
703                 [kernel has kstrtobool_from_user])
704 ])
705 ]) # LIBCFS_KSTRTOBOOL_FROM_USER
706
707 #
708 # Kernel version 4.5-rc1 commit d12481bc58fba89427565f8592e88446ec084a24
709 # added crypto hash helpers
710 #
711 AC_DEFUN([LIBCFS_CRYPTO_HASH_HELPERS], [
712 LB_CHECK_COMPILE([does crypto hash helper functions exist],
713 crypto_hash_helpers, [
714         #include <crypto/hash.h>
715 ],[
716         crypto_ahash_alg_name(NULL);
717         crypto_ahash_driver_name(NULL);
718 ],[
719         AC_DEFINE(HAVE_CRYPTO_HASH_HELPERS, 1,
720                 [crypto hash helper functions are available])
721 ])
722 ]) # LIBCFS_CRYPTO_HASH_HELPERS
723
724 #
725 # Kernerl version 4.5-rc3 commit 2fe829aca9d7bed5fd6b49c6a1452e5e486b6cc3dd
726 # made kset_find_obj() exportable to modules
727 #
728 AC_DEFUN([LIBCFS_EXPORT_KSET_FIND_OBJ], [
729 LB_CHECK_EXPORT([kset_find_obj], [lib/kobject.c],
730         [AC_DEFINE(HAVE_KSET_FIND_OBJ, 1,
731                 [kset_find_obj is exported by the kernel])])
732 ]) # LIBCFS_EXPORT_KSET_FIND_OBJ
733
734 #
735 # Kernel version 4.6+ commit ef703f49a6c5b909a85149bb6625c4ed0d697186
736 # fixed the brokenness of hash_64(). The fix removed GOLDEN_RATIO_PRIME_64
737 # since it was a poor prime value.
738 #
739 AC_DEFUN([LIBCFS_BROKEN_HASH_64], [
740 LB_CHECK_COMPILE([kernel has fixed hash_64()],
741 broken_hash_64, [
742         #include <linux/hash.h>
743 ],[
744         int tmp = GOLDEN_RATIO_PRIME_64;
745 ],[
746         AC_DEFINE(HAVE_BROKEN_HASH_64, 1, [kernel hash_64() is broken])
747 ])
748 ]) # LIBCFS_BROKEN_HASH_64
749
750 #
751 # LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT
752 #
753 # linux 4.6 kernel changed stacktrace_ops address to return an int
754 #
755 AC_DEFUN([LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT], [
756 LB_CHECK_COMPILE([if 'struct stacktrace_ops' address function returns an int],
757 stacktrace_ops_address_return_int, [
758         #include <asm/stacktrace.h>
759 ],[
760         int rc;
761
762         rc = ((struct stacktrace_ops *)0)->address(NULL, 0, 0);
763 ],[
764         AC_DEFINE(STACKTRACE_OPS_ADDRESS_RETURN_INT, 1,
765                 ['struct stacktrace_ops' address function returns an int])
766 ])
767 ]) # LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT
768
769 #
770 # Kernel version 4.6 removed both struct task_struct and struct mm_struct
771 # arguments to get_user_pages
772 #
773 AC_DEFUN([LIBCFS_GET_USER_PAGES_6ARG], [
774 LB_CHECK_COMPILE([if 'get_user_pages()' takes 6 arguments],
775 get_user_pages_6arg, [
776         #include <linux/mm.h>
777 ],[
778         int rc;
779
780         rc = get_user_pages(0, 0, 0, 0, NULL, NULL);
781 ],[
782         AC_DEFINE(HAVE_GET_USER_PAGES_6ARG, 1,
783                 [get_user_pages takes 6 arguments])
784 ])
785 ]) # LIBCFS_GET_USER_PAGES_6ARG
786
787 #
788 # LIBCFS_STRINGHASH
789 #
790 # 4.6 kernel created stringhash.h which moved stuff out of dcache.h
791 # commit f4bcbe792b8f434e32487cff9d9e30ab45a3ce02
792 #
793 AC_DEFUN([LIBCFS_STRINGHASH], [
794 LB_CHECK_LINUX_HEADER([linux/stringhash.h], [
795         AC_DEFINE(HAVE_STRINGHASH, 1,
796                 [stringhash.h is present])])
797 ]) # LIBCFS_STRINGHASH
798
799 #
800 # LIBCFS_RHASHTABLE_INSERT_FAST
801 #
802 # 4.7+ kernel commit 5ca8cc5bf11faed257c762018aea9106d529232f
803 # changed __rhashtable_insert_fast to support the new function
804 # rhashtable_lookup_get_insert_key().
805 #
806 AC_DEFUN([LIBCFS_RHASHTABLE_INSERT_FAST], [
807 tmp_flags="$EXTRA_KCFLAGS"
808 EXTRA_KCFLAGS="-Werror"
809 LB_CHECK_COMPILE([if internal '__rhashtable_insert_fast()' returns int],
810 rhashtable_insert_fast, [
811         #include <linux/rhashtable.h>
812 ],[
813         const struct rhashtable_params params = { 0 };
814         int rc;
815
816         rc = __rhashtable_insert_fast(NULL, NULL, NULL, params);
817 ],[
818         AC_DEFINE(HAVE_HASHTABLE_INSERT_FAST_RETURN_INT, 1,
819                   ['__rhashtable_insert_fast()' returns int])
820 ])
821 EXTRA_KCFLAGS="$tmp_flags"
822 ]) # LIBCFS_RHASHTABLE_INSERT_FAST
823
824 #
825 # Kernel version 4.8-rc6 commit ca26893f05e86497a86732768ec53cd38c0819ca
826 # introduced rhashtable_lookup
827 #
828 AC_DEFUN([LIBCFS_RHASHTABLE_LOOKUP], [
829 LB_CHECK_COMPILE([if 'rhashtable_lookup' exist],
830 rhashtable_lookup, [
831         #include <linux/rhashtable.h>
832 ],[
833         const struct rhashtable_params params = { 0 };
834         void *ret;
835
836         ret = rhashtable_lookup(NULL, NULL, params);
837 ],[
838         AC_DEFINE(HAVE_RHASHTABLE_LOOKUP, 1,
839                 [rhashtable_lookup() is available])
840 ])
841 ]) # LIBCFS_RHASHTABLE_LOOKUP
842
843 #
844 # LIBCFS_RHLTABLE
845 # Kernel version 4.8-rc6 commit ca26893f05e86497a86732768ec53cd38c0819ca
846 # created the rhlist interface to allow inserting duplicate objects
847 # into the same table.
848 #
849 AC_DEFUN([LIBCFS_RHLTABLE], [
850 LB_CHECK_COMPILE([does 'struct rhltable' exist],
851 rhtable, [
852         #include <linux/rhashtable.h>
853 ],[
854         struct rhltable *hlt;
855
856         rhltable_destroy(hlt);
857 ],[
858         AC_DEFINE(HAVE_RHLTABLE, 1,
859                   [struct rhltable exist])
860 ])
861 ]) # LIBCFS_RHLTABLE
862
863 #
864 # LIBCFS_STACKTRACE_OPS
865 #
866 # Kernel version 4.8 commit c8fe4609827aedc9c4b45de80e7cdc8ccfa8541b
867 # removed both struct stacktrace_ops and dump_trace() function
868 #
869 AC_DEFUN([LIBCFS_STACKTRACE_OPS], [
870 LB_CHECK_COMPILE([if 'struct stacktrace_ops' exists],
871 stacktrace_ops, [
872         struct task_struct;
873         struct pt_regs;
874         #include <asm/stacktrace.h>
875 ],[
876         struct stacktrace_ops ops;
877         ops.stack = NULL;
878 ],[
879         AC_DEFINE(HAVE_STACKTRACE_OPS, 1,
880                 [struct stacktrace_ops exists])
881 ])
882 ]) # LIBCFS_STACKTRACE_OPS
883
884 #
885 # Kernel version 4.9 commit 768ae309a96103ed02eb1e111e838c87854d8b51
886 # mm: replace get_user_pages() write/force parameters with gup_flags
887 #
888 AC_DEFUN([LIBCFS_GET_USER_PAGES_GUP_FLAGS], [
889 LB_CHECK_COMPILE([if 'get_user_pages()' takes gup_flags in arguments],
890 get_user_pages_gup_flags, [
891         #include <linux/mm.h>
892 ],[
893         int rc;
894         rc = get_user_pages(0, 0, FOLL_WRITE, NULL, NULL);
895 ],[
896         AC_DEFINE(HAVE_GET_USER_PAGES_GUP_FLAGS, 1,
897                 [get_user_pages takes gup_flags in arguments])
898 ])
899 ]) # LIBCFS_GET_USER_PAGES_GUP_FLAGS
900
901 #
902 # Kernel version 4.10 commit 7b737965b33188bd3dbb44e938535c4006d97fbb
903 # libcfs: Convert to hotplug state machine
904 #
905 AC_DEFUN([LIBCFS_HOTPLUG_STATE_MACHINE], [
906 LB_CHECK_COMPILE([if libcfs supports CPU hotplug state machine],
907 cpu_hotplug_state_machine, [
908         #include <linux/cpuhotplug.h>
909 ],[
910         cpuhp_remove_state(CPUHP_LUSTRE_CFS_DEAD);
911 ],[
912         AC_DEFINE(HAVE_HOTPLUG_STATE_MACHINE, 1,
913                 [hotplug state machine is supported])
914 ])
915 ]) # LIBCFS_HOTPLUG_STATE_MACHINE
916
917 #
918 # LIBCFS_SCHED_HEADERS
919 #
920 # 4.11 has broken up sched.h into more headers.
921 #
922 AC_DEFUN([LIBCFS_SCHED_HEADERS], [
923 LB_CHECK_LINUX_HEADER([linux/sched/signal.h], [
924         AC_DEFINE(HAVE_SCHED_HEADERS, 1,
925                 [linux/sched header directory exist])])
926 ]) # LIBCFS_SCHED_HEADERS
927
928 #
929 # Kernel version 4.11 commit f9fe1c12d126f9887441fa5bb165046f30ddd4b5
930 # introduced rhashtable_lookup_get_insert_fast
931 #
932 AC_DEFUN([LIBCFS_RHASHTABLE_LOOKUP_GET_INSERT_FAST], [
933 LB_CHECK_COMPILE([if 'rhashtable_lookup_get_insert_fast' exist],
934 rhashtable_lookup_get_insert_fast, [
935         #include <linux/rhashtable.h>
936 ],[
937         const struct rhashtable_params params = { 0 };
938         void *ret;
939
940         ret = rhashtable_lookup_get_insert_fast(NULL, NULL, params);
941 ],[
942         AC_DEFINE(HAVE_RHASHTABLE_LOOKUP_GET_INSERT_FAST, 1,
943                 [rhashtable_lookup_get_insert_fast() is available])
944 ])
945 ]) # LIBCFS_RHASHTABLE_LOOKUP_GET_INSERT_FAST
946
947 #
948 # Kernel verison 4.12-rc6 commit 5dd43ce2f69d42a71dcacdb13d17d8c0ac1fe8f7
949 # created wait_bit.h
950 #
951 AC_DEFUN([LIBCFS_HAVE_WAIT_BIT_HEADER], [
952 LB_CHECK_LINUX_HEADER([linux/wait_bit.h], [
953         AC_DEFINE(HAVE_WAIT_BIT_HEADER_H, 1,
954                 [wait_bit.h is present])])
955 ]) # LIBCFS_HAVE_WAIT_BIT_HEADER
956
957 #
958 # Kernel version 4.12-rc6 commmit 2055da97389a605c8a00d163d40903afbe413921
959 # changed:
960 #       struct wait_queue_head::task_list       => ::head
961 #       struct wait_queue_entry::task_list      => ::entry
962 #
963 AC_DEFUN([LIBCFS_WAIT_QUEUE_TASK_LIST_RENAME], [
964 LB_CHECK_COMPILE([if linux wait_queue_head list_head is named head],
965 wait_queue_task_list, [
966         #include <linux/wait.h>
967 ],[
968         wait_queue_head_t e;
969
970         INIT_LIST_HEAD(&e.head);
971 ],[
972         AC_DEFINE(HAVE_WAIT_QUEUE_ENTRY_LIST, 1,
973                 [linux wait_queue_head_t list_head is name head])
974 ])
975 ]) # LIBCFS_WAIT_QUEUE_TASK_LIST_RENAME
976
977 #
978 # LIBCFS_WAIT_QUEUE_ENTRY
979 #
980 # Kernel version 4.13 ac6424b981bce1c4bc55675c6ce11bfe1bbfa64f
981 # Rename wait_queue_t => wait_queue_entry_t
982 #
983 AC_DEFUN([LIBCFS_WAIT_QUEUE_ENTRY], [
984 LB_CHECK_COMPILE([if 'wait_queue_entry_t' exists],
985 wait_queue_entry, [
986         #include <linux/wait.h>
987 ],[
988         wait_queue_entry_t e;
989
990         e.flags = 0;
991 ],[
992         AC_DEFINE(HAVE_WAIT_QUEUE_ENTRY, 1,
993                 ['wait_queue_entry_t' is available])
994 ])
995 ]) # LIBCFS_WAIT_QUEUE_ENTRY
996
997 #
998 # LIBCFS_NEW_KERNEL_WRITE
999 #
1000 # Kernel version 4.14 e13ec939e96b13e664bb6cee361cc976a0ee621a
1001 # changed kernel_write prototype to make is plug compatible
1002 # with the unexported vfs_write()
1003 #
1004 AC_DEFUN([LIBCFS_NEW_KERNEL_WRITE], [
1005 tmp_flags="$EXTRA_KCFLAGS"
1006 EXTRA_KCFLAGS="-Werror"
1007 LB_CHECK_COMPILE([if 'kernel_write' matches other read/write helpers],
1008 kernel_write_match, [
1009         #include <linux/fs.h>
1010 ],[
1011         const void *buf = NULL;
1012         loff_t pos = 0;
1013         return kernel_write(NULL, buf, 0, &pos);
1014 ],[
1015         AC_DEFINE(HAVE_NEW_KERNEL_WRITE, 1,
1016                 ['kernel_write' aligns with read/write helpers])
1017 ])
1018 EXTRA_KCFLAGS="$tmp_flags"
1019 ]) # LIBCFS_NEW_KERNEL_WRITE
1020
1021 #
1022 # LIBCFS_MM_TOTALRAM_PAGES_FUNC
1023 #
1024 # kernel 5.0 commit ca79b0c211af63fa3276f0e3fd7dd9ada2439839
1025 # mm: convert totalram_pages and totalhigh_pages variables to atomic
1026 #
1027 AC_DEFUN([LIBCFS_MM_TOTALRAM_PAGES_FUNC], [
1028 tmp_flags="$EXTRA_KCFLAGS"
1029 EXTRA_KCFLAGS="-Werror"
1030 LB_CHECK_COMPILE([if totalram_pages is a function],
1031 totalram_pages, [
1032         #include <linux/mm.h>
1033 ],[
1034         totalram_pages_inc();
1035 ],[
1036         AC_DEFINE(HAVE_TOTALRAM_PAGES_AS_FUNC, 1,
1037                 [if totalram_pages is a function])
1038 ])
1039 EXTRA_KCFLAGS="$tmp_flags"
1040 ]) # LIBCFS_MM_TOTALRAM_PAGES_FUNC
1041
1042 #
1043 # LIBCFS_DEFINE_TIMER
1044 #
1045 # Kernel version 4.14 commit 1d27e3e2252ba9d949ca82fbdb73cde102cb2067
1046 # remove expires and data arguments from DEFINE_TIMER. Also the callback
1047 # when from using unsigned long argument to using struct timer_list pointer.
1048 #
1049 AC_DEFUN([LIBCFS_DEFINE_TIMER], [
1050 LB_CHECK_COMPILE([if DEFINE_TIMER takes only 2 arguments],
1051 define_timer, [
1052         #include <linux/timer.h>
1053 ],[
1054         static DEFINE_TIMER(my_timer, NULL);
1055 ],[
1056         AC_DEFINE(HAVE_NEW_DEFINE_TIMER, 1,
1057                 [DEFINE_TIMER uses only 2 arguements])
1058 ])
1059 ]) # LIBCFS_DEFINE_TIMER
1060
1061 #
1062 # LIBCFS_EXPORT_SAVE_STACK_TRACE_TSK
1063 #
1064 # Kernel 2.6.27 commit 8594698ebddeef5443b7da8258ae33b3eaca61d5
1065 # exported save_stack_trace_tsk for x86.
1066 # Kernel 2.6.27 commit 01f4b8b8b8db09b88be7df7e51192e4e678b69d3
1067 # exported save_stack_trace_tsk for powerpc
1068 # Kernel 4.13 commit e27c7fa015d61c8be6a2c32b2144aad2ae6ec975
1069 # exported save_stack_trace_tsk for arm64
1070 # Kernel 4.14 commit 9a3dc3186fc3795e076a4122da9e0258651a9631
1071 # exported save_stack_trace_tsk for arm
1072 #
1073 AC_DEFUN([LIBCFS_EXPORT_SAVE_STACK_TRACE_TSK], [
1074 LB_CHECK_EXPORT([save_stack_trace_tsk], [arch/$SUBARCH/kernel/stacktrace.c],
1075         [AC_DEFINE(HAVE_SAVE_STACK_TRACE_TSK, 1,
1076                 [save_stack_trace_tsk is exported])])
1077 ]) # LIBCFS_EXPORT_SAVE_STACK_TRACE_TSK
1078
1079 #
1080 # LIBCFS_TIMER_SETUP
1081 #
1082 # Kernel version 4.15 commit e99e88a9d2b067465adaa9c111ada99a041bef9a
1083 # setup_timer() was replaced by timer_setup(), where the callback
1084 # argument is the structure already holding the struct timer_list.
1085 #
1086 AC_DEFUN([LIBCFS_TIMER_SETUP], [
1087 LB_CHECK_COMPILE([if setup_timer has been replaced with timer_setup],
1088 timer_setup, [
1089         #include <linux/timer.h>
1090 ],[
1091         timer_setup(NULL, NULL, 0);
1092 ],[
1093         AC_DEFINE(HAVE_TIMER_SETUP, 1,
1094                 [timer_setup has replaced setup_timer])
1095 ])
1096 ]) # LIBCFS_TIMER_SETUP
1097
1098 #
1099 # LIBCFS_WAIT_VAR_EVENT
1100 #
1101 # Kernel version 4.16-rc4 commit 6b2bb7265f0b62605e8caee3613449ed0db270b9
1102 # added wait_var_event()
1103 #
1104 AC_DEFUN([LIBCFS_WAIT_VAR_EVENT], [
1105 LB_CHECK_COMPILE([if 'wait_var_event' exist],
1106 wait_var_event, [
1107         #ifdef HAVE_WAIT_BIT_HEADER_H
1108         #include <linux/wait_bit.h>
1109         #endif
1110         #include <linux/wait.h>
1111 ],[
1112         wake_up_var(NULL);
1113 ],[
1114         AC_DEFINE(HAVE_WAIT_VAR_EVENT, 1,
1115                 ['wait_var_event' is available])
1116 ])
1117 ]) # LIBCFS_WAIT_VAR_EVENT
1118
1119 #
1120 # LIBCFS_CLEAR_AND_WAKE_UP_BIT
1121 #
1122 # Kernel version 4.17-rc2 commit 8236b0ae31c837d2b3a2565c5f8d77f637e824cc
1123 # added clear_and_wake_up_bit()
1124 #
1125 AC_DEFUN([LIBCFS_CLEAR_AND_WAKE_UP_BIT], [
1126 LB_CHECK_COMPILE([if 'clear_and_wake_up_bit' exist],
1127 clear_and_wake_up_bit, [
1128         #ifdef HAVE_WAIT_BIT_HEADER_H
1129         #include <linux/wait_bit.h>
1130         #endif
1131         #include <linux/wait.h>
1132 ],[
1133         clear_and_wake_up_bit(0, NULL);
1134 ],[
1135         AC_DEFINE(HAVE_CLEAR_AND_WAKE_UP_BIT, 1,
1136                 ['clear_and_wake_up_bit' is available])
1137 ])
1138 ]) # LIBCFS_CLEAR_AND_WAKE_UP_BIT
1139
1140 #
1141 # LIBCFS_HAVE_IOV_ITER_TYPE
1142 #
1143 # kernel 4.20 commit 00e23707442a75b404392cef1405ab4fd498de6b
1144 # iov_iter: Use accessor functions to access an iterator's type and direction.
1145 #
1146 AC_DEFUN([LIBCFS_HAVE_IOV_ITER_TYPE], [
1147 tmp_flags="$EXTRA_KCFLAGS"
1148 EXTRA_KCFLAGS="-Werror"
1149 LB_CHECK_COMPILE([if iov_iter_type exists],
1150 macro_iov_iter_type_exists, [
1151         #include <linux/uio.h>
1152 ],[
1153         struct iov_iter iter = { .type = ITER_KVEC };
1154         enum iter_type type = iov_iter_type(&iter);
1155         (void)type;
1156 ],[
1157         AC_DEFINE(HAVE_IOV_ITER_TYPE, 1,
1158                 [if iov_iter_type exists])
1159 ])
1160 EXTRA_KCFLAGS="$tmp_flags"
1161 ]) # LIBCFS_HAVE_IOV_ITER_TYPE
1162
1163 #
1164 # LIBCFS_GET_REQUEST_KEY_AUTH
1165 #
1166 # kernel 5.0 commit 822ad64d7e46a8e2c8b8a796738d7b657cbb146d
1167 # keys: Fix dependency loop between construction record and auth key
1168 #
1169 # Added <keys/request_key_auth-type.h> and get_request_key_auth()
1170 # which was propagated to stable
1171 #
1172 AC_DEFUN([LIBCFS_GET_REQUEST_KEY_AUTH], [
1173 tmp_flags="$EXTRA_KCFLAGS"
1174 EXTRA_KCFLAGS="-Werror"
1175 LB_CHECK_COMPILE([if get_request_key_auth() is available],
1176 get_request_key_auth_exported, [
1177         #include <linux/key.h>
1178         #include <linux/keyctl.h>
1179         #include <keys/request_key_auth-type.h>
1180 ],[
1181         struct key *ring;
1182         const struct key *key = NULL;
1183         struct request_key_auth *rka = get_request_key_auth(key);
1184
1185         ring = key_get(rka->dest_keyring);
1186 ],[
1187         AC_DEFINE(HAVE_GET_REQUEST_KEY_AUTH, 1,
1188                 [get_request_key_auth() is available])
1189 ])
1190 EXTRA_KCFLAGS="$tmp_flags"
1191 ]) # LIBCFS_GET_REQUEST_KEY_AUTH
1192
1193 #
1194 # LIBCFS_LOOKUP_USER_KEY
1195 #
1196 # kernel 5.3 commit 3cf5d076fb4d48979f382bc9452765bf8b79e740
1197 # signal: Remove task parameter from force_sig
1198 #
1199 AC_DEFUN([LIBCFS_LOOKUP_USER_KEY], [
1200 tmp_flags="$EXTRA_KCFLAGS"
1201 EXTRA_KCFLAGS="-Werror"
1202 LB_CHECK_COMPILE([if lookup_user_key() is available],
1203 lookup_user_key_exported, [
1204         #include <linux/key.h>
1205         #include <linux/keyctl.h>
1206 ],[
1207         lookup_user_key(KEY_SPEC_USER_KEYRING, 0, 0);
1208 ],[
1209         AC_DEFINE(HAVE_LOOKUP_USER_KEY, 1,
1210                 [lookup_user_key() is available])
1211 ])
1212 EXTRA_KCFLAGS="$tmp_flags"
1213 ]) # LIBCFS_LOOKUP_USER_KEY
1214
1215 #
1216 # LIBCFS_CACHE_DETAIL_WRITERS
1217 #
1218 # kernel v5.3-rc2-1-g64a38e840ce5
1219 # SUNRPC: Track writers of the 'channel' file to improve cache_listeners_exist
1220 #
1221 AC_DEFUN([LIBCFS_CACHE_DETAIL_WRITERS], [
1222 tmp_flags="$EXTRA_KCFLAGS"
1223 EXTRA_KCFLAGS="-Werror"
1224 LB_CHECK_COMPILE([if struct cache_detail has writers],
1225 cache_detail_writers_atomic, [
1226         #include <linux/sunrpc/cache.h>
1227
1228         static struct cache_detail rsi_cache;
1229 ],[
1230         atomic_set(&rsi_cache.writers, 0);
1231 ],[
1232         AC_DEFINE(HAVE_CACHE_DETAIL_WRITERS, 1,
1233                 [struct cache_detail has writers])
1234 ])
1235 EXTRA_KCFLAGS="$tmp_flags"
1236 ]) # LIBCFS_CACHE_DETAIL_WRITERS
1237
1238 #
1239 # LIBCFS_HAVE_NR_UNSTABLE_NFS
1240 #
1241 # kernel v5.8-rc1~201^2~75
1242 # mm/writeback: discard NR_UNSTABLE_NFS, use NR_WRITEBACK instead
1243 #
1244 AC_DEFUN([LIBCFS_HAVE_NR_UNSTABLE_NFS], [
1245 tmp_flags="$EXTRA_KCFLAGS"
1246 EXTRA_KCFLAGS="-Werror"
1247 LB_CHECK_COMPILE([if NR_UNSTABLE_NFS still in use],
1248 nr_unstable_nfs_exists, [
1249         #include <linux/mm.h>
1250
1251         int i;
1252 ],[
1253         i = NR_UNSTABLE_NFS;
1254 ],[
1255         AC_DEFINE(HAVE_NR_UNSTABLE_NFS, 1,
1256                 [NR_UNSTABLE_NFS is still in use.])
1257 ])
1258 EXTRA_KCFLAGS="$tmp_flags"
1259 ]) # LIBCFS_HAVE_NR_UNSTABLE_NFS
1260
1261 #
1262 # LIBCFS_PROG_LINUX
1263 #
1264 # LibCFS linux kernel checks
1265 #
1266 AC_DEFUN([LIBCFS_PROG_LINUX], [
1267 AC_MSG_NOTICE([LibCFS kernel checks
1268 ==============================================================================])
1269 LIBCFS_CONFIG_PANIC_DUMPLOG
1270
1271 # 2.6.32
1272 LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
1273 LC_SHRINKER_WANT_SHRINK_PTR
1274 # 2.6.33
1275 LIBCFS_SYSCTL_CTLNAME
1276 # 2.6.36
1277 LIBCFS_MODULE_LOCKING
1278 # 2.6.38
1279 LIBCFS_KSTRTOUL
1280 # 2.6.39
1281 LIBCFS_DUMP_TRACE_ADDRESS
1282 # 2.6.40 fc15
1283 LC_SHRINK_CONTROL
1284 # 3.0
1285 LIBCFS_STACKTRACE_WARNING
1286 # 3.5
1287 LIBCFS_PROCESS_NAMESPACE
1288 LIBCFS_I_UID_READ
1289 # 3.8
1290 LIBCFS_HAVE_CRC32
1291 LIBCFS_D_HASH_AND_LOOKUP
1292 LIBCFS_ENABLE_CRC32_ACCEL
1293 # 3.10
1294 LIBCFS_ENABLE_CRC32C_ACCEL
1295 # 3.11
1296 LIBCFS_KTIME_GET_TS64
1297 # 3.12
1298 LIBCFS_PREPARE_TO_WAIT_EVENT
1299 LIBCFS_KERNEL_PARAM_OPS
1300 LIBCFS_KTIME_ADD
1301 LIBCFS_KTIME_AFTER
1302 LIBCFS_KTIME_BEFORE
1303 LIBCFS_KTIME_COMPARE
1304 LIBCFS_SHRINKER_COUNT
1305 # 3.15
1306 LIBCFS_IOV_ITER_HAS_TYPE
1307 # 3.16
1308 LIBCFS_LINUX_RHASHTABLE_H
1309 # 3.17
1310 LIBCFS_HLIST_ADD_AFTER
1311 LIBCFS_TIMESPEC64
1312 LIBCFS_KTIME_GET_NS
1313 LIBCFS_KTIME_GET_REAL_TS64
1314 LIBCFS_KTIME_GET_REAL_SECONDS
1315 LIBCFS_KTIME_GET_REAL_NS
1316 LIBCFS_KTIME_TO_TIMESPEC64
1317 LIBCFS_TIMESPEC64_SUB
1318 LIBCFS_TIMESPEC64_TO_KTIME
1319 # 3.19
1320 LIBCFS_KTIME_GET_SECONDS
1321 # 4.0
1322 LIBCFS_KTIME_MS_DELTA
1323 # 4.1
1324 LIBCFS_KERNEL_PARAM_LOCK
1325 # 4.2
1326 LIBCFS_HAVE_TOPOLOGY_SIBLING_CPUMASK
1327 LIBCFS_FPU_API
1328 # 4.4
1329 LIBCFS_KSTRTOBOOL_FROM_USER
1330 # 4.5
1331 LIBCFS_CRYPTO_HASH_HELPERS
1332 LIBCFS_EXPORT_KSET_FIND_OBJ
1333 # 4.6
1334 LIBCFS_BROKEN_HASH_64
1335 LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT
1336 LIBCFS_GET_USER_PAGES_6ARG
1337 LIBCFS_STRINGHASH
1338 # 4.7
1339 LIBCFS_RHASHTABLE_INSERT_FAST
1340 # 4.8
1341 LIBCFS_RHASHTABLE_LOOKUP
1342 LIBCFS_RHLTABLE
1343 LIBCFS_STACKTRACE_OPS
1344 # 4.9
1345 LIBCFS_GET_USER_PAGES_GUP_FLAGS
1346 # 4.10
1347 LIBCFS_HOTPLUG_STATE_MACHINE
1348 # 4.11
1349 LIBCFS_RHASHTABLE_LOOKUP_GET_INSERT_FAST
1350 LIBCFS_SCHED_HEADERS
1351 # 4.12
1352 LIBCFS_HAVE_WAIT_BIT_HEADER
1353 LIBCFS_WAIT_QUEUE_TASK_LIST_RENAME
1354 # 4.13
1355 LIBCFS_WAIT_QUEUE_ENTRY
1356 # 4.14
1357 LIBCFS_DEFINE_TIMER
1358 LIBCFS_NEW_KERNEL_WRITE
1359 LIBCFS_EXPORT_SAVE_STACK_TRACE_TSK
1360 # 4.15
1361 LIBCFS_TIMER_SETUP
1362 # 4.16
1363 LIBCFS_WAIT_VAR_EVENT
1364 # 4.17
1365 LIBCFS_CLEAR_AND_WAKE_UP_BIT
1366 # 4.20
1367 LIBCFS_HAVE_IOV_ITER_TYPE
1368 # 5.0
1369 LIBCFS_MM_TOTALRAM_PAGES_FUNC
1370 LIBCFS_GET_REQUEST_KEY_AUTH
1371 # 5.3
1372 LIBCFS_LOOKUP_USER_KEY
1373 LIBCFS_CACHE_DETAIL_WRITERS
1374 LIBCFS_HAVE_NR_UNSTABLE_NFS
1375 ]) # LIBCFS_PROG_LINUX
1376
1377 #
1378 # LIBCFS_PATH_DEFAULTS
1379 #
1380 # default paths for installed files
1381 #
1382 AC_DEFUN([LIBCFS_PATH_DEFAULTS], [
1383 ]) # LIBCFS_PATH_DEFAULTS
1384
1385 #
1386 # LIBCFS_CONFIGURE
1387 #
1388 # other configure checks
1389 #
1390 AC_DEFUN([LIBCFS_CONFIGURE], [
1391 AC_MSG_NOTICE([LibCFS core checks
1392 ==============================================================================])
1393
1394 # libcfs/libcfs/util/nidstrings.c
1395 AC_CHECK_HEADERS([netdb.h asm/types.h endian.h])
1396 AC_CHECK_FUNCS([gethostbyname])
1397
1398 # --------  Check for required packages  --------------
1399
1400 AC_MSG_NOTICE([LibCFS required packages checks
1401 ==============================================================================])
1402
1403 AC_MSG_CHECKING([whether to enable readline support])
1404 AC_ARG_ENABLE(readline,
1405         AC_HELP_STRING([--disable-readline],
1406                 [disable readline support]),
1407         [], [enable_readline="yes"])
1408 AC_MSG_RESULT([$enable_readline])
1409
1410 LIBREADLINE=""
1411 AS_IF([test "x$enable_readline" = xyes], [
1412         AC_CHECK_LIB([readline], [readline], [
1413                 LIBREADLINE="-lreadline"
1414                 AC_DEFINE(HAVE_LIBREADLINE, 1,
1415                         [readline library is available])
1416         ])
1417 ])
1418 AC_SUBST(LIBREADLINE)
1419
1420 AC_MSG_CHECKING([whether to use libpthread for libcfs library])
1421 AC_ARG_ENABLE([libpthread],
1422         AC_HELP_STRING([--disable-libpthread],
1423                 [disable libpthread]),
1424         [], [enable_libpthread="yes"])
1425 AC_MSG_RESULT([$enable_libpthread])
1426
1427 PTHREAD_LIBS=""
1428 AS_IF([test "x$enable_libpthread" = xyes], [
1429         AC_CHECK_LIB([pthread], [pthread_create], [
1430                 PTHREAD_LIBS="-lpthread"
1431                 AC_DEFINE([HAVE_LIBPTHREAD], 1,
1432                         [use libpthread for libcfs library])
1433         ])
1434 ], [
1435         AC_MSG_WARN([Using libpthread for libcfs library is disabled explicitly])
1436 ])
1437 AC_SUBST(PTHREAD_LIBS)
1438 ]) # LIBCFS_CONFIGURE
1439
1440 #
1441 # LIBCFS_CONDITIONALS
1442 #
1443 AC_DEFUN([LIBCFS_CONDITIONALS], [
1444 AM_CONDITIONAL(HAVE_CRC32, [test "x$have_crc32" = xyes])
1445 AM_CONDITIONAL(NEED_PCLMULQDQ_CRC32,  [test "x$have_crc32" = xyes -a "x$enable_crc32_crypto" = xyes])
1446 AM_CONDITIONAL(NEED_PCLMULQDQ_CRC32C, [test "x$enable_crc32c_crypto" = xyes])
1447 ]) # LIBCFS_CONDITIONALS
1448
1449 #
1450 # LIBCFS_CONFIG_FILES
1451 #
1452 # files that should be generated with AC_OUTPUT
1453 #
1454 AC_DEFUN([LIBCFS_CONFIG_FILES], [
1455 AC_CONFIG_FILES([
1456 libcfs/Makefile
1457 libcfs/autoMakefile
1458 libcfs/autoconf/Makefile
1459 libcfs/include/Makefile
1460 libcfs/include/libcfs/Makefile
1461 libcfs/include/libcfs/linux/Makefile
1462 libcfs/include/libcfs/util/Makefile
1463 libcfs/libcfs/Makefile
1464 libcfs/libcfs/autoMakefile
1465 libcfs/libcfs/linux/Makefile
1466 libcfs/libcfs/util/Makefile
1467 ])
1468 ]) # LIBCFS_CONFIG_FILES