Whamcloud - gitweb
32c5cafc6a6e4cec9549356d215fe8e18ec32c87
[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 3.11 introduced ktime_get_ts64
260 #
261 AC_DEFUN([LIBCFS_KTIME_GET_TS64],[
262 LB_CHECK_COMPILE([does function 'ktime_get_ts64' exist],
263 ktime_get_ts64, [
264         #include <linux/hrtimer.h>
265         #include <linux/ktime.h>
266 ],[
267         struct timespec64 *ts = NULL;
268
269         ktime_get_ts64(ts);
270 ],[
271         AC_DEFINE(HAVE_KTIME_GET_TS64, 1,
272                 ['ktime_get_ts64' is available])
273 ])
274 ]) # LIBCFS_KTIME_GET_TS64
275
276 #
277 # Kernel version 3.12-rc4 commit c2d816443ef30 added prepare_to_wait_event()
278 #
279 AC_DEFUN([LIBCFS_PREPARE_TO_WAIT_EVENT],[
280 LB_CHECK_COMPILE([does function 'prepare_to_wait_event' exist],
281 prepare_to_wait_event, [
282         #include <linux/wait.h>
283 ],[
284         prepare_to_wait_event(NULL, NULL, 0);
285 ],[
286         AC_DEFINE(HAVE_PREPARE_TO_WAIT_EVENT, 1,
287                 ['prepare_to_wait_event' is available])
288 ])
289 ]) # LIBCFS_PREPARE_TO_WAIT_EVENT
290
291 #
292 # Linux kernel 3.12 introduced struct kernel_param_ops
293 # This has been backported to all lustre supported
294 # clients except RHEL6. We have to handle the differences.
295 #
296 AC_DEFUN([LIBCFS_KERNEL_PARAM_OPS],[
297 LB_CHECK_COMPILE([does 'struct kernel_param_ops' exist],
298 kernel_param_ops, [
299         #include <linux/module.h>
300 ],[
301         struct kernel_param_ops ops;
302
303         ops.set = NULL;
304 ],[
305         AC_DEFINE(HAVE_KERNEL_PARAM_OPS, 1,
306                 ['struct kernel_param_ops' is available])
307 ])
308 ]) # LIBCFS_KERNEL_PARAM_OPS
309
310 #
311 # Kernel version 3.12 introduced ktime_add
312 #
313 AC_DEFUN([LIBCFS_KTIME_ADD],[
314 LB_CHECK_COMPILE([does function 'ktime_add' exist],
315 ktime_add, [
316         #include <linux/hrtimer.h>
317         #include <linux/ktime.h>
318 ],[
319         ktime_t start = ktime_set(0, 0);
320         ktime_t end = start;
321         ktime_t total;
322
323         total = ktime_add(start, end);
324 ],[
325         AC_DEFINE(HAVE_KTIME_ADD, 1,
326                 [ktime_add is available])
327 ])
328 ]) # LIBCFS_KTIME_ADD
329
330 #
331 # Kernel version 3.12 introduced ktime_after
332 #
333 AC_DEFUN([LIBCFS_KTIME_AFTER],[
334 LB_CHECK_COMPILE([does function 'ktime_after' exist],
335 ktime_after, [
336         #include <linux/hrtimer.h>
337         #include <linux/ktime.h>
338 ],[
339         ktime_t start = ktime_set(0, 0);
340         ktime_t end = start;
341
342         ktime_after(start, end);
343 ],[
344         AC_DEFINE(HAVE_KTIME_AFTER, 1,
345                 [ktime_after is available])
346 ])
347 ]) # LIBCFS_KTIME_AFTER
348
349 #
350 # Kernel version 3.12 introduced ktime_before
351 # See linux commit 67cb9366ff5f99868100198efba5ca88aaa6ad25
352 #
353 AC_DEFUN([LIBCFS_KTIME_BEFORE],[
354 LB_CHECK_COMPILE([does function 'ktime_before' exist],
355 ktime_before, [
356         #include <linux/hrtimer.h>
357         #include <linux/ktime.h>
358 ],[
359         ktime_t start = ktime_set(0, 0);
360         ktime_t end = start;
361
362         ktime_before(start, end);
363 ],[
364         AC_DEFINE(HAVE_KTIME_BEFORE, 1,
365                 [ktime_before is available])
366 ])
367 ]) # LIBCFS_KTIME_BEFORE
368
369 #
370 # Kernel version 3.12 introduced ktime_compare
371 #
372 AC_DEFUN([LIBCFS_KTIME_COMPARE],[
373 LB_CHECK_COMPILE([does function 'ktime_compare' exist],
374 ktime_compare, [
375         #include <linux/hrtimer.h>
376         #include <linux/ktime.h>
377 ],[
378         ktime_t start = ktime_set(0, 0);
379         ktime_t end = start;
380
381         ktime_compare(start, end);
382 ],[
383         AC_DEFINE(HAVE_KTIME_COMPARE, 1,
384                 [ktime_compare is available])
385 ])
386 ]) # LIBCFS_KTIME_COMPARE
387
388 #
389 # FC19 3.12 kernel struct shrinker change
390 #
391 AC_DEFUN([LIBCFS_SHRINKER_COUNT],[
392 LB_CHECK_COMPILE([shrinker has 'count_objects'],
393 shrinker_count_objects, [
394         #include <linux/mmzone.h>
395         #include <linux/shrinker.h>
396 ],[
397         struct shrinker shrinker;
398
399         shrinker.count_objects = NULL;
400 ],[
401         AC_DEFINE(HAVE_SHRINKER_COUNT, 1,
402                 [shrinker has count_objects member])
403 ])
404 ]) # LIBCFS_SHRINKER_COUNT
405
406 #
407 # LIBCFS_IOV_ITER_HAS_TYPE
408 #
409 # kernel 3.15-rc4 commit 71d8e532b1549a478e6a6a8a44f309d050294d00
410 # start adding the tag to iov_iter
411 #
412 AC_DEFUN([LIBCFS_IOV_ITER_HAS_TYPE], [
413 tmp_flags="$EXTRA_KCFLAGS"
414 EXTRA_KCFLAGS="-Werror"
415 LB_CHECK_COMPILE([if iov_iter has member type],
416 iov_iter_has_type_member, [
417         #include <linux/uio.h>
418 ],[
419         struct iov_iter iter = { .type = ITER_KVEC };
420         (void)iter;
421 ],[
422         AC_DEFINE(HAVE_IOV_ITER_HAS_TYPE_MEMBER, 1,
423                 [if iov_iter has member type])
424 ])
425 EXTRA_KCFLAGS="$tmp_flags"
426 ]) # LIBCFS_IOV_ITER_HAS_TYPE
427
428 #
429 # Kernel version 3.17 changed hlist_add_after to
430 # hlist_add_behind
431 #
432 AC_DEFUN([LIBCFS_HLIST_ADD_AFTER],[
433 LB_CHECK_COMPILE([does function 'hlist_add_after' exist],
434 hlist_add_after, [
435         #include <linux/list.h>
436 ],[
437         hlist_add_after(NULL, NULL);
438 ],[
439         AC_DEFINE(HAVE_HLIST_ADD_AFTER, 1,
440                 [hlist_add_after is available])
441 ])
442 ]) # LIBCFS_HLIST_ADD_AFTER
443
444 #
445 # Kernel version 3.17 introduced struct timespec64
446 #
447 AC_DEFUN([LIBCFS_TIMESPEC64],[
448 LB_CHECK_COMPILE([does 'struct timespec64' exist],
449 timespec64, [
450         #include <linux/time.h>
451 ],[
452         struct timespec64 ts;
453
454         ts.tv_sec = 0;
455         ts.tv_nsec = 0;
456 ],[
457         AC_DEFINE(HAVE_TIMESPEC64, 1,
458                 ['struct timespec64' is available])
459 ])
460 ]) # LIBCFS_TIMESPEC64
461
462 #
463 # Kernel version 3.17 introduced ktime_get_real_ts64
464 #
465 AC_DEFUN([LIBCFS_KTIME_GET_REAL_TS64],[
466 LB_CHECK_COMPILE([does function 'ktime_get_real_ts64' exist],
467 ktime_get_real_ts64, [
468         #include <linux/ktime.h>
469 ],[
470         struct timespec64 *ts = NULL;
471
472         ktime_get_real_ts64(ts);
473 ],[
474         AC_DEFINE(HAVE_KTIME_GET_REAL_TS64, 1,
475                 ['ktime_get_real_ts64' is available])
476 ])
477 ]) # LIBCFS_KTIME_GET_REAL_TS64
478
479 #
480 # Kernel version 3.17 introduced ktime_get_real_seconds
481 #
482 AC_DEFUN([LIBCFS_KTIME_GET_REAL_SECONDS],[
483 LB_CHECK_COMPILE([does function 'ktime_get_real_seconds' exist],
484 ktime_get_real_seconds, [
485         #include <linux/hrtimer.h>
486         #include <linux/ktime.h>
487 ],[
488         time64_t now;
489
490         now = ktime_get_real_seconds();
491 ],[
492         AC_DEFINE(HAVE_KTIME_GET_REAL_SECONDS, 1,
493                 ['ktime_get_real_seconds' is available])
494 ])
495 ]) # LIBCFS_KTIME_GET_REAL_SECONDS
496
497 #
498 # Kernel version 3.17 created ktime_get_ns wrapper
499 #
500 AC_DEFUN([LIBCFS_KTIME_GET_NS],[
501 LB_CHECK_COMPILE([does function 'ktime_get_ns' exist],
502 ktime_get_ns, [
503         #include <linux/hrtimer.h>
504         #include <linux/ktime.h>
505 ],[
506         u64 nanoseconds;
507
508         nanoseconds = ktime_get_ns();
509 ],[],[
510         AC_DEFINE(NEED_KTIME_GET_NS, 1,
511                 ['ktime_get_ns' is not available])
512 ])
513 ]) # LIBCFS_KTIME_GET_NS
514
515 #
516 # Kernel version 3.17 created ktime_get_real_ns wrapper
517 #
518 AC_DEFUN([LIBCFS_KTIME_GET_REAL_NS],[
519 LB_CHECK_COMPILE([does function 'ktime_get_real_ns' exist],
520 ktime_get_real_ns, [
521         #include <linux/hrtimer.h>
522         #include <linux/ktime.h>
523 ],[
524         u64 nanoseconds;
525
526         nanoseconds = ktime_get_real_ns();
527 ],[],[
528         AC_DEFINE(NEED_KTIME_GET_REAL_NS, 1,
529                 ['ktime_get_real_ns' is not available])
530 ])
531 ]) # LIBCFS_KTIME_GET_REAL_NS
532
533 #
534 # Kernel version 3.17 introduced ktime_to_timespec64
535 #
536 AC_DEFUN([LIBCFS_KTIME_TO_TIMESPEC64],[
537 LB_CHECK_COMPILE([does function 'ktime_to_timespec64' exist],
538 ktime_to_timespec64, [
539         #include <linux/hrtimer.h>
540         #include <linux/ktime.h>
541 ],[
542         ktime_t now = ktime_set(0, 0);
543         struct timespec64 ts;
544
545         ts = ktime_to_timespec64(now);
546 ],[
547         AC_DEFINE(HAVE_KTIME_TO_TIMESPEC64, 1,
548                 ['ktime_to_timespec64' is available])
549 ])
550 ]) # LIBCFS_KTIME_TO_TIMESPEC64
551
552 #
553 # Kernel version 3.17 introduced timespec64_sub
554 #
555 AC_DEFUN([LIBCFS_TIMESPEC64_SUB],[
556 LB_CHECK_COMPILE([does function 'timespec64_sub' exist],
557 timespec64_sub, [
558         #include <linux/time.h>
559 ],[
560         struct timespec64 later = { }, earlier = { }, diff;
561
562         diff = timespec64_sub(later, earlier);
563 ],[
564         AC_DEFINE(HAVE_TIMESPEC64_SUB, 1,
565                 ['timespec64_sub' is available])
566 ])
567 ]) # LIBCFS_TIMESPEC64_SUB
568
569 #
570 # Kernel version 3.17 introduced timespec64_to_ktime
571 #
572 AC_DEFUN([LIBCFS_TIMESPEC64_TO_KTIME],[
573 LB_CHECK_COMPILE([does function 'timespec64_to_ktime' exist],
574 timespec64_to_ktime, [
575         #include <linux/ktime.h>
576 ],[
577         struct timespec64 ts;
578         ktime_t now;
579
580         now = timespec64_to_ktime(ts);
581 ],[
582         AC_DEFINE(HAVE_TIMESPEC64_TO_KTIME, 1,
583                 ['timespec64_to_ktime' is available])
584 ])
585 ]) # LIBCFS_TIMESPEC64_TO_KTIME
586
587 #
588 # Kernel version 3.19 introduced ktime_get_seconds
589 #
590 AC_DEFUN([LIBCFS_KTIME_GET_SECONDS],[
591 LB_CHECK_COMPILE([does function 'ktime_get_seconds' exist],
592 ktime_get_seconds, [
593         #include <linux/ktime.h>
594 ],[
595         time64_t now;
596
597         now = ktime_get_seconds();
598 ],[
599         AC_DEFINE(HAVE_KTIME_GET_SECONDS, 1,
600                 ['ktime_get_seconds' is available])
601 ])
602 ]) # LIBCFS_KTIME_GET_SECONDS
603
604 #
605 # Kernel version 4.0 commit 41fbf3b39d5eca01527338b4d0ee15ee1ae1023c
606 # introduced the helper function ktime_ms_delta.
607 #
608 AC_DEFUN([LIBCFS_KTIME_MS_DELTA],[
609 LB_CHECK_COMPILE([does function 'ktime_ms_delta' exist],
610 ktime_ms_delta, [
611         #include <linux/ktime.h>
612 ],[
613         ktime_t start = ktime_set(0, 0);
614         ktime_t end = start;
615
616         ktime_ms_delta(start, end);
617 ],[
618         AC_DEFINE(HAVE_KTIME_MS_DELTA, 1,
619                 ['ktime_ms_delta' is available])
620 ])
621 ]) # LIBCFS_KTIME_MS_DELTA
622
623 #
624 # Kernel version 4.1 commit b51d23e4e9fea6f264d39535c2a62d1f51e7ccc3
625 # create per module locks which added kernel_param_[un]lock(). Older
626 # kernels you have to use __kernel_param_[un]lock(). In that case its
627 # a global lock for all modules but that is okay since its a rare event.
628 #
629 AC_DEFUN([LIBCFS_KERNEL_PARAM_LOCK],[
630 LB_CHECK_COMPILE([does function 'kernel_param_[un]lock' exist],
631 kernel_param_lock, [
632         #include <linux/moduleparam.h>
633 ],[
634         kernel_param_lock(NULL);
635         kernel_param_unlock(NULL);
636 ],[
637         AC_DEFINE(HAVE_KERNEL_PARAM_LOCK, 1,
638                 ['kernel_param_[un]lock' is available])
639 ])
640 ]) # LIBCFS_KERNEL_PARAM_LOCK
641
642 #
643 # Kernel version 4.2 changed topology_thread_cpumask
644 # to topology_sibling_cpumask
645 #
646 AC_DEFUN([LIBCFS_HAVE_TOPOLOGY_SIBLING_CPUMASK],[
647 LB_CHECK_COMPILE([does function 'topology_sibling_cpumask' exist],
648 topology_sibling_cpumask, [
649         #include <linux/topology.h>
650 ],[
651         const struct cpumask *mask;
652
653         mask = topology_sibling_cpumask(0);
654 ],[
655         AC_DEFINE(HAVE_TOPOLOGY_SIBLING_CPUMASK, 1,
656                 [topology_sibling_cpumask is available])
657 ])
658 ]) # LIBCFS_HAVE_TOPOLOGY_SIBLING_CPUMASK
659
660 #
661 # Kernel version 4.2 commit df6b35f409af0a8ff1ef62f552b8402f3fef8665
662 # header file i387.h was renamed to fpu/api.h
663 #
664 AC_DEFUN([LIBCFS_FPU_API], [
665 LB_CHECK_LINUX_HEADER([asm/fpu/api.h], [
666         AC_DEFINE(HAVE_FPU_API_HEADER, 1,
667                 [fpu/api.h is present])])
668 ]) # LIBCFS_FPU_API
669
670 #
671 # Kernel version 4.4 commit ef951599074ba4fad2d0efa0a977129b41e6d203
672 # introduced kstrtobool and kstrtobool_from_user.
673 #
674 AC_DEFUN([LIBCFS_KSTRTOBOOL_FROM_USER], [
675 LB_CHECK_COMPILE([if Linux kernel has 'kstrtobool_from_user'],
676 kstrtobool_from_user, [
677         #include <linux/kernel.h>
678 ],[
679         bool result;
680         return kstrtobool_from_user(NULL, 0, &result);
681 ],[
682         AC_DEFINE(HAVE_KSTRTOBOOL_FROM_USER, 1,
683                 [kernel has kstrtobool_from_user])
684 ])
685 ]) # LIBCFS_KSTRTOBOOL_FROM_USER
686
687 #
688 # Kernel version 4.5-rc1 commit d12481bc58fba89427565f8592e88446ec084a24
689 # added crypto hash helpers
690 #
691 AC_DEFUN([LIBCFS_CRYPTO_HASH_HELPERS], [
692 LB_CHECK_COMPILE([does crypto hash helper functions exist],
693 crypto_hash_helpers, [
694         #include <crypto/hash.h>
695 ],[
696         crypto_ahash_alg_name(NULL);
697         crypto_ahash_driver_name(NULL);
698 ],[
699         AC_DEFINE(HAVE_CRYPTO_HASH_HELPERS, 1,
700                 [crypto hash helper functions are available])
701 ])
702 ]) # LIBCFS_CRYPTO_HASH_HELPERS
703
704 #
705 # Kernel version 4.5-rc1 commit 3502cad73c4bbf8f6365d539e814159275252c59
706 # introduced rhashtable_replace_fast
707 #
708 AC_DEFUN([LIBCFS_RHASHTABLE_REPLACE], [
709 LB_CHECK_COMPILE([if 'rhashtable_replace_fast' exists],
710 rhashtable_replace_fast, [
711         #include <linux/rhashtable.h>
712 ],[
713         const struct rhashtable_params params = { 0 };
714
715         rhashtable_replace_fast(NULL, NULL, NULL, params);
716 ],[
717         AC_DEFINE(HAVE_RHASHTABLE_REPLACE, 1,
718                 [rhashtable_replace_fast() is available])
719 ])
720 ]) # LIBCFS_RHASHTABLE_REPLACE
721
722 #
723 # Kernel version 4.5-rc3 commit 2fe829aca9d7bed5fd6b49c6a1452e5e486b6cc3dd
724 # made kset_find_obj() exportable to modules
725 #
726 AC_DEFUN([LIBCFS_EXPORT_KSET_FIND_OBJ], [
727 LB_CHECK_EXPORT([kset_find_obj], [lib/kobject.c],
728         [AC_DEFINE(HAVE_KSET_FIND_OBJ, 1,
729                 [kset_find_obj is exported by the kernel])])
730 ]) # LIBCFS_EXPORT_KSET_FIND_OBJ
731
732 #
733 # Kernel version 4.6+ commit ef703f49a6c5b909a85149bb6625c4ed0d697186
734 # fixed the brokenness of hash_64(). The fix removed GOLDEN_RATIO_PRIME_64
735 # since it was a poor prime value.
736 #
737 AC_DEFUN([LIBCFS_BROKEN_HASH_64], [
738 LB_CHECK_COMPILE([kernel has fixed hash_64()],
739 broken_hash_64, [
740         #include <linux/hash.h>
741 ],[
742         int tmp = GOLDEN_RATIO_PRIME_64;
743 ],[
744         AC_DEFINE(HAVE_BROKEN_HASH_64, 1, [kernel hash_64() is broken])
745 ])
746 ]) # LIBCFS_BROKEN_HASH_64
747
748 #
749 # LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT
750 #
751 # linux 4.6 kernel changed stacktrace_ops address to return an int
752 #
753 AC_DEFUN([LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT], [
754 LB_CHECK_COMPILE([if 'struct stacktrace_ops' address function returns an int],
755 stacktrace_ops_address_return_int, [
756         #include <asm/stacktrace.h>
757 ],[
758         int rc;
759
760         rc = ((struct stacktrace_ops *)0)->address(NULL, 0, 0);
761 ],[
762         AC_DEFINE(STACKTRACE_OPS_ADDRESS_RETURN_INT, 1,
763                 ['struct stacktrace_ops' address function returns an int])
764 ])
765 ]) # LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT
766
767 #
768 # Kernel version 4.6 removed both struct task_struct and struct mm_struct
769 # arguments to get_user_pages
770 #
771 AC_DEFUN([LIBCFS_GET_USER_PAGES_6ARG], [
772 LB_CHECK_COMPILE([if 'get_user_pages()' takes 6 arguments],
773 get_user_pages_6arg, [
774         #include <linux/mm.h>
775 ],[
776         int rc;
777
778         rc = get_user_pages(0, 0, 0, 0, NULL, NULL);
779 ],[
780         AC_DEFINE(HAVE_GET_USER_PAGES_6ARG, 1,
781                 [get_user_pages takes 6 arguments])
782 ])
783 ]) # LIBCFS_GET_USER_PAGES_6ARG
784
785 #
786 # LIBCFS_STRINGHASH
787 #
788 # 4.6 kernel created stringhash.h which moved stuff out of dcache.h
789 # commit f4bcbe792b8f434e32487cff9d9e30ab45a3ce02
790 #
791 AC_DEFUN([LIBCFS_STRINGHASH], [
792 LB_CHECK_LINUX_HEADER([linux/stringhash.h], [
793         AC_DEFINE(HAVE_STRINGHASH, 1,
794                 [stringhash.h is present])])
795 ]) # LIBCFS_STRINGHASH
796
797 #
798 # LIBCFS_RHASHTABLE_INSERT_FAST
799 #
800 # 4.7+ kernel commit 5ca8cc5bf11faed257c762018aea9106d529232f
801 # changed __rhashtable_insert_fast to support the new function
802 # rhashtable_lookup_get_insert_key().
803 #
804 AC_DEFUN([LIBCFS_RHASHTABLE_INSERT_FAST], [
805 tmp_flags="$EXTRA_KCFLAGS"
806 EXTRA_KCFLAGS="-Werror"
807 LB_CHECK_COMPILE([if internal '__rhashtable_insert_fast()' returns int],
808 rhashtable_insert_fast, [
809         #include <linux/rhashtable.h>
810 ],[
811         const struct rhashtable_params params = { 0 };
812         int rc;
813
814         rc = __rhashtable_insert_fast(NULL, NULL, NULL, params);
815 ],[
816         AC_DEFINE(HAVE_HASHTABLE_INSERT_FAST_RETURN_INT, 1,
817                   ['__rhashtable_insert_fast()' returns int])
818 ])
819 EXTRA_KCFLAGS="$tmp_flags"
820 ]) # LIBCFS_RHASHTABLE_INSERT_FAST
821
822 #
823 # Kernel version 4.7-rc1 commit 8f6fd83c6c5ec66a4a70c728535ddcdfef4f3697
824 # added 3rd arg to rhashtable_walk_init
825 #
826 AC_DEFUN([LIBCFS_RHASHTABLE_WALK_INIT_3ARG], [
827 LB_CHECK_COMPILE([if 'rhashtable_walk_init' has 3 args],
828 rhashtable_walk_init, [
829         #include <linux/gfp.h>
830         #include <linux/rhashtable.h>
831 ],[
832         rhashtable_walk_init(NULL, NULL, GFP_KERNEL);
833 ],[
834         AC_DEFINE(HAVE_3ARG_RHASHTABLE_WALK_INIT, 1,
835                 [rhashtable_walk_init() has 3 args])
836 ])
837 ]) # LIBCFS_RHASHTABLE_REPLACE
838
839 #
840 # Kernel version 4.8-rc6 commit ca26893f05e86497a86732768ec53cd38c0819ca
841 # introduced rhashtable_lookup
842 #
843 AC_DEFUN([LIBCFS_RHASHTABLE_LOOKUP], [
844 LB_CHECK_COMPILE([if 'rhashtable_lookup' exist],
845 rhashtable_lookup, [
846         #include <linux/rhashtable.h>
847 ],[
848         const struct rhashtable_params params = { 0 };
849         void *ret;
850
851         ret = rhashtable_lookup(NULL, NULL, params);
852 ],[
853         AC_DEFINE(HAVE_RHASHTABLE_LOOKUP, 1,
854                 [rhashtable_lookup() is available])
855 ])
856 ]) # LIBCFS_RHASHTABLE_LOOKUP
857
858 #
859 # LIBCFS_RHLTABLE
860 # Kernel version 4.8-rc6 commit ca26893f05e86497a86732768ec53cd38c0819ca
861 # created the rhlist interface to allow inserting duplicate objects
862 # into the same table.
863 #
864 AC_DEFUN([LIBCFS_RHLTABLE], [
865 LB_CHECK_COMPILE([does 'struct rhltable' exist],
866 rhtable, [
867         #include <linux/rhashtable.h>
868 ],[
869         struct rhltable *hlt;
870
871         rhltable_destroy(hlt);
872 ],[
873         AC_DEFINE(HAVE_RHLTABLE, 1,
874                   [struct rhltable exist])
875 ])
876 ]) # LIBCFS_RHLTABLE
877
878 #
879 # LIBCFS_STACKTRACE_OPS
880 #
881 # Kernel version 4.8 commit c8fe4609827aedc9c4b45de80e7cdc8ccfa8541b
882 # removed both struct stacktrace_ops and dump_trace() function
883 #
884 AC_DEFUN([LIBCFS_STACKTRACE_OPS], [
885 LB_CHECK_COMPILE([if 'struct stacktrace_ops' exists],
886 stacktrace_ops, [
887         struct task_struct;
888         struct pt_regs;
889         #include <asm/stacktrace.h>
890 ],[
891         struct stacktrace_ops ops;
892         ops.stack = NULL;
893 ],[
894         AC_DEFINE(HAVE_STACKTRACE_OPS, 1,
895                 [struct stacktrace_ops exists])
896 ])
897 ]) # LIBCFS_STACKTRACE_OPS
898
899 #
900 # Kernel version 4.9-rc1 commit 246779dd090bd1b74d2652b3a6ca7759f593b27a
901 # introduced rhashtable_walk_enter
902 #
903 AC_DEFUN([LIBCFS_RHASHTABLE_WALK_ENTER], [
904 LB_CHECK_COMPILE([if 'rhashtable_walk_enter' exists],
905 rhashtable_walk_enter, [
906         #include <linux/rhashtable.h>
907 ],[
908         rhashtable_walk_enter(NULL, NULL);
909 ],[
910         AC_DEFINE(HAVE_RHASHTABLE_WALK_ENTER, 1,
911                 [rhashtable_walk_enter() is available])
912 ])
913 ]) # LIBCFS_RHASHTABLE_REPLACE
914
915 #
916 # Kernel version 4.9 commit 768ae309a96103ed02eb1e111e838c87854d8b51
917 # mm: replace get_user_pages() write/force parameters with gup_flags
918 #
919 AC_DEFUN([LIBCFS_GET_USER_PAGES_GUP_FLAGS], [
920 LB_CHECK_COMPILE([if 'get_user_pages()' takes gup_flags in arguments],
921 get_user_pages_gup_flags, [
922         #include <linux/mm.h>
923 ],[
924         int rc;
925         rc = get_user_pages(0, 0, FOLL_WRITE, NULL, NULL);
926 ],[
927         AC_DEFINE(HAVE_GET_USER_PAGES_GUP_FLAGS, 1,
928                 [get_user_pages takes gup_flags in arguments])
929 ])
930 ]) # LIBCFS_GET_USER_PAGES_GUP_FLAGS
931
932 #
933 # Kernel version 4.10 commit 7b737965b33188bd3dbb44e938535c4006d97fbb
934 # libcfs: Convert to hotplug state machine
935 #
936 AC_DEFUN([LIBCFS_HOTPLUG_STATE_MACHINE], [
937 LB_CHECK_COMPILE([if libcfs supports CPU hotplug state machine],
938 cpu_hotplug_state_machine, [
939         #include <linux/cpuhotplug.h>
940 ],[
941         cpuhp_remove_state(CPUHP_LUSTRE_CFS_DEAD);
942 ],[
943         AC_DEFINE(HAVE_HOTPLUG_STATE_MACHINE, 1,
944                 [hotplug state machine is supported])
945 ])
946 ]) # LIBCFS_HOTPLUG_STATE_MACHINE
947
948 #
949 # Kernel version 4.10-rc3 commit f405df5de3170c00e5c54f8b7cf4766044a032ba
950 # introduced refcount_t which is atomic_t plus over flow guards.
951 #
952 AC_DEFUN([LIBCFS_REFCOUNT_T], [
953 LB_CHECK_LINUX_HEADER([linux/refcount.h], [
954         AC_DEFINE(HAVE_REFCOUNT_T, 1,
955                 [refcount_t is supported])])
956 ]) # LIBCFS_REFCOUNT_T
957
958 #
959 # LIBCFS_SCHED_HEADERS
960 #
961 # 4.11 has broken up sched.h into more headers.
962 #
963 AC_DEFUN([LIBCFS_SCHED_HEADERS], [
964 LB_CHECK_LINUX_HEADER([linux/sched/signal.h], [
965         AC_DEFINE(HAVE_SCHED_HEADERS, 1,
966                 [linux/sched header directory exist])])
967 ]) # LIBCFS_SCHED_HEADERS
968
969 #
970 # Kernel version 4.11-rc1 commit da20420f83ea0fbcf3d03afda08d971ea1d8a356
971 # introduced rht_bucket_var
972 #
973 AC_DEFUN([LIBCFS_RHT_BUCKET_VAR], [
974 LB_CHECK_COMPILE([if 'rht_bucket_var' exists],
975 rht_bucket_var, [
976         #include <linux/rhashtable.h>
977 ],[
978
979         rht_bucket_var(NULL, 0);
980 ],[
981         AC_DEFINE(HAVE_RHT_BUCKET_VAR, 1,
982                 [rht_bucket_var() is available])
983 ])
984 ]) # LIBCFS_RHT_BUCKET_VAR
985
986 #
987 # Kernel version 4.11 commit f9fe1c12d126f9887441fa5bb165046f30ddd4b5
988 # introduced rhashtable_lookup_get_insert_fast
989 #
990 AC_DEFUN([LIBCFS_RHASHTABLE_LOOKUP_GET_INSERT_FAST], [
991 LB_CHECK_COMPILE([if 'rhashtable_lookup_get_insert_fast' exist],
992 rhashtable_lookup_get_insert_fast, [
993         #include <linux/rhashtable.h>
994 ],[
995         const struct rhashtable_params params = { 0 };
996         void *ret;
997
998         ret = rhashtable_lookup_get_insert_fast(NULL, NULL, params);
999 ],[
1000         AC_DEFINE(HAVE_RHASHTABLE_LOOKUP_GET_INSERT_FAST, 1,
1001                 [rhashtable_lookup_get_insert_fast() is available])
1002 ])
1003 ]) # LIBCFS_RHASHTABLE_LOOKUP_GET_INSERT_FAST
1004
1005 #
1006 # Kernel version 4.12-rc3 f9727a17db9bab71ddae91f74f11a8a2f9a0ece6
1007 # renamed uuid_be to uuid_t
1008 #
1009 AC_DEFUN([LIBCFS_UUID_T], [
1010 LB_CHECK_COMPILE([if 'uuid_t' exist],
1011 uuid_t, [
1012         #include <linux/uuid.h>
1013 ],[
1014         uuid_t uuid;
1015
1016         memset(uuid.b, 0, 16);
1017 ],[
1018         AC_DEFINE(HAVE_UUID_T, 1, ['uuid_t' exist])
1019 ])
1020 ]) # LIBCFS_UUID_T
1021
1022 #
1023 # Kernel version 4.12-rc3 commit fd851a3cdc196bfc1d229b5f22369069af532bf8
1024 # introduce processor.h
1025 #
1026 AC_DEFUN([LIBCFS_HAVE_PROCESSOR_HEADER], [
1027 LB_CHECK_LINUX_HEADER([linux/processor.h], [
1028         AC_DEFINE(HAVE_PROCESSOR_H, 1,
1029                 [processor.h is present])])
1030 ]) # LIBCFS_HAVE_PROCESSOR_HEADER
1031
1032 #
1033 # Kernel verison 4.12-rc6 commit 5dd43ce2f69d42a71dcacdb13d17d8c0ac1fe8f7
1034 # created wait_bit.h
1035 #
1036 AC_DEFUN([LIBCFS_HAVE_WAIT_BIT_HEADER], [
1037 LB_CHECK_LINUX_HEADER([linux/wait_bit.h], [
1038         AC_DEFINE(HAVE_WAIT_BIT_HEADER_H, 1,
1039                 [wait_bit.h is present])])
1040 ]) # LIBCFS_HAVE_WAIT_BIT_HEADER
1041
1042 #
1043 # Kernel version 4.12-rc6 commmit 2055da97389a605c8a00d163d40903afbe413921
1044 # changed:
1045 #       struct wait_queue_head::task_list       => ::head
1046 #       struct wait_queue_entry::task_list      => ::entry
1047 #
1048 AC_DEFUN([LIBCFS_WAIT_QUEUE_TASK_LIST_RENAME], [
1049 LB_CHECK_COMPILE([if linux wait_queue_head list_head is named head],
1050 wait_queue_task_list, [
1051         #include <linux/wait.h>
1052 ],[
1053         wait_queue_head_t e;
1054
1055         INIT_LIST_HEAD(&e.head);
1056 ],[
1057         AC_DEFINE(HAVE_WAIT_QUEUE_ENTRY_LIST, 1,
1058                 [linux wait_queue_head_t list_head is name head])
1059 ])
1060 ]) # LIBCFS_WAIT_QUEUE_TASK_LIST_RENAME
1061
1062 #
1063 # LIBCFS_WAIT_QUEUE_ENTRY
1064 #
1065 # Kernel version 4.13 ac6424b981bce1c4bc55675c6ce11bfe1bbfa64f
1066 # Rename wait_queue_t => wait_queue_entry_t
1067 #
1068 AC_DEFUN([LIBCFS_WAIT_QUEUE_ENTRY], [
1069 LB_CHECK_COMPILE([if 'wait_queue_entry_t' exists],
1070 wait_queue_entry, [
1071         #include <linux/wait.h>
1072 ],[
1073         wait_queue_entry_t e;
1074
1075         e.flags = 0;
1076 ],[
1077         AC_DEFINE(HAVE_WAIT_QUEUE_ENTRY, 1,
1078                 ['wait_queue_entry_t' is available])
1079 ])
1080 ]) # LIBCFS_WAIT_QUEUE_ENTRY
1081
1082 #
1083 # LIBCFS_NEW_KERNEL_WRITE
1084 #
1085 # Kernel version 4.14 e13ec939e96b13e664bb6cee361cc976a0ee621a
1086 # changed kernel_write prototype to make is plug compatible
1087 # with the unexported vfs_write()
1088 #
1089 AC_DEFUN([LIBCFS_NEW_KERNEL_WRITE], [
1090 tmp_flags="$EXTRA_KCFLAGS"
1091 EXTRA_KCFLAGS="-Werror"
1092 LB_CHECK_COMPILE([if 'kernel_write' matches other read/write helpers],
1093 kernel_write_match, [
1094         #include <linux/fs.h>
1095 ],[
1096         const void *buf = NULL;
1097         loff_t pos = 0;
1098         return kernel_write(NULL, buf, 0, &pos);
1099 ],[
1100         AC_DEFINE(HAVE_NEW_KERNEL_WRITE, 1,
1101                 ['kernel_write' aligns with read/write helpers])
1102 ])
1103 EXTRA_KCFLAGS="$tmp_flags"
1104 ]) # LIBCFS_NEW_KERNEL_WRITE
1105
1106 #
1107 # LIBCFS_MM_TOTALRAM_PAGES_FUNC
1108 #
1109 # kernel 5.0 commit ca79b0c211af63fa3276f0e3fd7dd9ada2439839
1110 # mm: convert totalram_pages and totalhigh_pages variables to atomic
1111 #
1112 AC_DEFUN([LIBCFS_MM_TOTALRAM_PAGES_FUNC], [
1113 tmp_flags="$EXTRA_KCFLAGS"
1114 EXTRA_KCFLAGS="-Werror"
1115 LB_CHECK_COMPILE([if totalram_pages is a function],
1116 totalram_pages, [
1117         #include <linux/mm.h>
1118 ],[
1119         totalram_pages_inc();
1120 ],[
1121         AC_DEFINE(HAVE_TOTALRAM_PAGES_AS_FUNC, 1,
1122                 [if totalram_pages is a function])
1123 ])
1124 EXTRA_KCFLAGS="$tmp_flags"
1125 ]) # LIBCFS_MM_TOTALRAM_PAGES_FUNC
1126
1127 #
1128 # LIBCFS_NEW_KERNEL_WRITE
1129 #
1130 # 4.14 commit bdd1d2d3d251c65b74ac4493e08db18971c09240 changed
1131 # the signature of kernel_read to match other read/write helpers
1132 # and place offset last.
1133 #
1134 AC_DEFUN([LIBCFS_NEW_KERNEL_READ], [
1135 tmp_flags="$EXTRA_KCFLAGS"
1136 EXTRA_KCFLAGS="-Werror"
1137 LB_CHECK_COMPILE([if 'kernel_read()' has loff_t *pos as last parameter],
1138 kernel_read, [
1139         #include <linux/fs.h>
1140         ],[
1141         loff_t pos = 0;
1142         kernel_read(NULL, NULL, 0, &pos);
1143 ],[
1144         AC_DEFINE(HAVE_KERNEL_READ_LAST_POSP, 1,
1145                 [kernel_read() signature ends with loff_t *pos])
1146 ])
1147 EXTRA_KCFLAGS="$tmp_flags"
1148 ]) # LIBCFS_NEW_KERNEL_READ
1149
1150 #
1151 # LIBCFS_DEFINE_TIMER
1152 #
1153 # Kernel version 4.14 commit 1d27e3e2252ba9d949ca82fbdb73cde102cb2067
1154 # remove expires and data arguments from DEFINE_TIMER. Also the callback
1155 # when from using unsigned long argument to using struct timer_list pointer.
1156 #
1157 AC_DEFUN([LIBCFS_DEFINE_TIMER], [
1158 LB_CHECK_COMPILE([if DEFINE_TIMER takes only 2 arguments],
1159 define_timer, [
1160         #include <linux/timer.h>
1161 ],[
1162         static DEFINE_TIMER(my_timer, NULL);
1163 ],[
1164         AC_DEFINE(HAVE_NEW_DEFINE_TIMER, 1,
1165                 [DEFINE_TIMER uses only 2 arguements])
1166 ])
1167 ]) # LIBCFS_DEFINE_TIMER
1168
1169 #
1170 # LIBCFS_EXPORT_SAVE_STACK_TRACE_TSK
1171 #
1172 # Kernel 2.6.27 commit 8594698ebddeef5443b7da8258ae33b3eaca61d5
1173 # exported save_stack_trace_tsk for x86.
1174 # Kernel 2.6.27 commit 01f4b8b8b8db09b88be7df7e51192e4e678b69d3
1175 # exported save_stack_trace_tsk for powerpc
1176 # Kernel 4.13 commit e27c7fa015d61c8be6a2c32b2144aad2ae6ec975
1177 # exported save_stack_trace_tsk for arm64
1178 # Kernel 4.14 commit 9a3dc3186fc3795e076a4122da9e0258651a9631
1179 # exported save_stack_trace_tsk for arm
1180 #
1181 AC_DEFUN([LIBCFS_EXPORT_SAVE_STACK_TRACE_TSK], [
1182 LB_CHECK_EXPORT([save_stack_trace_tsk], [arch/$SUBARCH/kernel/stacktrace.c],
1183         [AC_DEFINE(HAVE_SAVE_STACK_TRACE_TSK, 1,
1184                 [save_stack_trace_tsk is exported])])
1185 ]) # LIBCFS_EXPORT_SAVE_STACK_TRACE_TSK
1186
1187 #
1188 # LIBCFS_TIMER_SETUP
1189 #
1190 # Kernel version 4.15 commit e99e88a9d2b067465adaa9c111ada99a041bef9a
1191 # setup_timer() was replaced by timer_setup(), where the callback
1192 # argument is the structure already holding the struct timer_list.
1193 #
1194 AC_DEFUN([LIBCFS_TIMER_SETUP], [
1195 LB_CHECK_COMPILE([if setup_timer has been replaced with timer_setup],
1196 timer_setup, [
1197         #include <linux/timer.h>
1198 ],[
1199         timer_setup(NULL, NULL, 0);
1200 ],[
1201         AC_DEFINE(HAVE_TIMER_SETUP, 1,
1202                 [timer_setup has replaced setup_timer])
1203 ])
1204 ]) # LIBCFS_TIMER_SETUP
1205
1206 #
1207 # LIBCFS_WAIT_VAR_EVENT
1208 #
1209 # Kernel version 4.16-rc4 commit 6b2bb7265f0b62605e8caee3613449ed0db270b9
1210 # added wait_var_event()
1211 #
1212 AC_DEFUN([LIBCFS_WAIT_VAR_EVENT], [
1213 LB_CHECK_COMPILE([if 'wait_var_event' exist],
1214 wait_var_event, [
1215         #ifdef HAVE_WAIT_BIT_HEADER_H
1216         #include <linux/wait_bit.h>
1217         #endif
1218         #include <linux/wait.h>
1219 ],[
1220         wake_up_var(NULL);
1221 ],[
1222         AC_DEFINE(HAVE_WAIT_VAR_EVENT, 1,
1223                 ['wait_var_event' is available])
1224 ])
1225 ]) # LIBCFS_WAIT_VAR_EVENT
1226
1227 #
1228 # LIBCFS_CLEAR_AND_WAKE_UP_BIT
1229 #
1230 # Kernel version 4.17-rc2 commit 8236b0ae31c837d2b3a2565c5f8d77f637e824cc
1231 # added clear_and_wake_up_bit()
1232 #
1233 AC_DEFUN([LIBCFS_CLEAR_AND_WAKE_UP_BIT], [
1234 LB_CHECK_COMPILE([if 'clear_and_wake_up_bit' exist],
1235 clear_and_wake_up_bit, [
1236         #ifdef HAVE_WAIT_BIT_HEADER_H
1237         #include <linux/wait_bit.h>
1238         #endif
1239         #include <linux/wait.h>
1240 ],[
1241         clear_and_wake_up_bit(0, NULL);
1242 ],[
1243         AC_DEFINE(HAVE_CLEAR_AND_WAKE_UP_BIT, 1,
1244                 ['clear_and_wake_up_bit' is available])
1245 ])
1246 ]) # LIBCFS_CLEAR_AND_WAKE_UP_BIT
1247
1248 #
1249 # LIBCFS_HAVE_IOV_ITER_TYPE
1250 #
1251 # kernel 4.20 commit 00e23707442a75b404392cef1405ab4fd498de6b
1252 # iov_iter: Use accessor functions to access an iterator's type and direction.
1253 #
1254 AC_DEFUN([LIBCFS_HAVE_IOV_ITER_TYPE], [
1255 tmp_flags="$EXTRA_KCFLAGS"
1256 EXTRA_KCFLAGS="-Werror"
1257 LB_CHECK_COMPILE([if iov_iter_type exists],
1258 macro_iov_iter_type_exists, [
1259         #include <linux/uio.h>
1260 ],[
1261         struct iov_iter iter = { .type = ITER_KVEC };
1262         enum iter_type type = iov_iter_type(&iter);
1263         (void)type;
1264 ],[
1265         AC_DEFINE(HAVE_IOV_ITER_TYPE, 1,
1266                 [if iov_iter_type exists])
1267 ])
1268 EXTRA_KCFLAGS="$tmp_flags"
1269 ]) # LIBCFS_HAVE_IOV_ITER_TYPE
1270
1271 #
1272 # LIBCFS_FORCE_SIG_WITH_TASK
1273 #
1274 # kernel 5.3 commit 3cf5d076fb4d48979f382bc9452765bf8b79e740
1275 # signal: Remove task parameter from force_sig
1276 #
1277 AC_DEFUN([LIBCFS_FORCE_SIG_WITH_TASK], [
1278 tmp_flags="$EXTRA_KCFLAGS"
1279 EXTRA_KCFLAGS="-Werror"
1280 LB_CHECK_COMPILE([if force_sig has task parameter],
1281 force_sig_with_task, [
1282         #include <linux/sched/signal.h>
1283 ],[
1284         force_sig(SIGINT, NULL);
1285 ],[
1286         AC_DEFINE(HAVE_FORCE_SIG_WITH_TASK, 1,
1287                 [force_sig() has task parameter])
1288 ])
1289 EXTRA_KCFLAGS="$tmp_flags"
1290 ]) # LIBCFS_FORCE_SIG_WITH_TASK
1291
1292 #
1293 # LIBCFS_CACHE_DETAIL_WRITERS
1294 #
1295 # kernel v5.3-rc2-1-g64a38e840ce5
1296 # SUNRPC: Track writers of the 'channel' file to improve cache_listeners_exist
1297 #
1298 AC_DEFUN([LIBCFS_CACHE_DETAIL_WRITERS], [
1299 tmp_flags="$EXTRA_KCFLAGS"
1300 EXTRA_KCFLAGS="-Werror"
1301 LB_CHECK_COMPILE([if struct cache_detail has writers],
1302 cache_detail_writers_atomic, [
1303         #include <linux/sunrpc/cache.h>
1304
1305         static struct cache_detail rsi_cache;
1306 ],[
1307         atomic_set(&rsi_cache.writers, 0);
1308 ],[
1309         AC_DEFINE(HAVE_CACHE_DETAIL_WRITERS, 1,
1310                 [struct cache_detail has writers])
1311 ])
1312 EXTRA_KCFLAGS="$tmp_flags"
1313 ]) # LIBCFS_CACHE_DETAIL_WRITERS
1314
1315 #
1316 # LIBCFS_PROG_LINUX
1317 #
1318 # LibCFS linux kernel checks
1319 #
1320 AC_DEFUN([LIBCFS_PROG_LINUX], [
1321 AC_MSG_NOTICE([LibCFS kernel checks
1322 ==============================================================================])
1323 LIBCFS_CONFIG_PANIC_DUMPLOG
1324
1325 # 2.6.32
1326 LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
1327 LC_SHRINKER_WANT_SHRINK_PTR
1328 # 2.6.33
1329 LIBCFS_SYSCTL_CTLNAME
1330 # 2.6.36
1331 LIBCFS_MODULE_LOCKING
1332 # 2.6.38
1333 LIBCFS_KSTRTOUL
1334 # 2.6.39
1335 LIBCFS_DUMP_TRACE_ADDRESS
1336 # 2.6.40 fc15
1337 LC_SHRINK_CONTROL
1338 # 3.0
1339 LIBCFS_STACKTRACE_WARNING
1340 # 3.5
1341 LIBCFS_PROCESS_NAMESPACE
1342 LIBCFS_I_UID_READ
1343 # 3.8
1344 LIBCFS_HAVE_CRC32
1345 LIBCFS_ENABLE_CRC32_ACCEL
1346 # 3.10
1347 LIBCFS_ENABLE_CRC32C_ACCEL
1348 # 3.11
1349 LIBCFS_KTIME_GET_TS64
1350 # 3.12
1351 LIBCFS_PREPARE_TO_WAIT_EVENT
1352 LIBCFS_KERNEL_PARAM_OPS
1353 LIBCFS_KTIME_ADD
1354 LIBCFS_KTIME_AFTER
1355 LIBCFS_KTIME_BEFORE
1356 LIBCFS_KTIME_COMPARE
1357 LIBCFS_SHRINKER_COUNT
1358 # 3.15
1359 LIBCFS_IOV_ITER_HAS_TYPE
1360 # 3.17
1361 LIBCFS_HLIST_ADD_AFTER
1362 LIBCFS_TIMESPEC64
1363 LIBCFS_KTIME_GET_NS
1364 LIBCFS_KTIME_GET_REAL_TS64
1365 LIBCFS_KTIME_GET_REAL_SECONDS
1366 LIBCFS_KTIME_GET_REAL_NS
1367 LIBCFS_KTIME_TO_TIMESPEC64
1368 LIBCFS_TIMESPEC64_SUB
1369 LIBCFS_TIMESPEC64_TO_KTIME
1370 # 3.19
1371 LIBCFS_KTIME_GET_SECONDS
1372 # 4.0
1373 LIBCFS_KTIME_MS_DELTA
1374 # 4.1
1375 LIBCFS_KERNEL_PARAM_LOCK
1376 # 4.2
1377 LIBCFS_HAVE_TOPOLOGY_SIBLING_CPUMASK
1378 LIBCFS_FPU_API
1379 # 4.4
1380 LIBCFS_KSTRTOBOOL_FROM_USER
1381 # 4.5
1382 LIBCFS_CRYPTO_HASH_HELPERS
1383 LIBCFS_EXPORT_KSET_FIND_OBJ
1384 LIBCFS_RHASHTABLE_REPLACE
1385 # 4.6
1386 LIBCFS_BROKEN_HASH_64
1387 LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT
1388 LIBCFS_GET_USER_PAGES_6ARG
1389 LIBCFS_STRINGHASH
1390 # 4.7
1391 LIBCFS_RHASHTABLE_INSERT_FAST
1392 LIBCFS_RHASHTABLE_WALK_INIT_3ARG
1393 # 4.8
1394 LIBCFS_RHASHTABLE_LOOKUP
1395 LIBCFS_RHLTABLE
1396 LIBCFS_STACKTRACE_OPS
1397 # 4.9
1398 LIBCFS_GET_USER_PAGES_GUP_FLAGS
1399 LIBCFS_RHASHTABLE_WALK_ENTER
1400 # 4.10
1401 LIBCFS_HOTPLUG_STATE_MACHINE
1402 LIBCFS_REFCOUNT_T
1403 # 4.11
1404 LIBCFS_RHASHTABLE_LOOKUP_GET_INSERT_FAST
1405 LIBCFS_SCHED_HEADERS
1406 LIBCFS_RHT_BUCKET_VAR
1407 # 4.12
1408 LIBCFS_HAVE_PROCESSOR_HEADER
1409 LIBCFS_HAVE_WAIT_BIT_HEADER
1410 LIBCFS_WAIT_QUEUE_TASK_LIST_RENAME
1411 LIBCFS_UUID_T
1412 # 4.13
1413 LIBCFS_WAIT_QUEUE_ENTRY
1414 # 4.14
1415 LIBCFS_DEFINE_TIMER
1416 LIBCFS_NEW_KERNEL_WRITE
1417 LIBCFS_NEW_KERNEL_READ
1418 LIBCFS_EXPORT_SAVE_STACK_TRACE_TSK
1419 # 4.15
1420 LIBCFS_TIMER_SETUP
1421 # 4.16
1422 LIBCFS_WAIT_VAR_EVENT
1423 # 4.17
1424 LIBCFS_CLEAR_AND_WAKE_UP_BIT
1425 # 4.20
1426 LIBCFS_HAVE_IOV_ITER_TYPE
1427 # 5.0
1428 LIBCFS_MM_TOTALRAM_PAGES_FUNC
1429 # 5.3
1430 LIBCFS_FORCE_SIG_WITH_TASK
1431 LIBCFS_CACHE_DETAIL_WRITERS
1432 ]) # LIBCFS_PROG_LINUX
1433
1434 #
1435 # LIBCFS_PATH_DEFAULTS
1436 #
1437 # default paths for installed files
1438 #
1439 AC_DEFUN([LIBCFS_PATH_DEFAULTS], [
1440 ]) # LIBCFS_PATH_DEFAULTS
1441
1442 #
1443 # LIBCFS_CONFIGURE
1444 #
1445 # other configure checks
1446 #
1447 AC_DEFUN([LIBCFS_CONFIGURE], [
1448 AC_MSG_NOTICE([LibCFS core checks
1449 ==============================================================================])
1450
1451 # libcfs/libcfs/util/nidstrings.c
1452 AC_CHECK_HEADERS([netdb.h asm/types.h endian.h])
1453 AC_CHECK_FUNCS([gethostbyname])
1454
1455 # --------  Check for required packages  --------------
1456
1457 AC_MSG_NOTICE([LibCFS required packages checks
1458 ==============================================================================])
1459
1460 AC_MSG_CHECKING([whether to enable readline support])
1461 AC_ARG_ENABLE(readline,
1462         AC_HELP_STRING([--disable-readline],
1463                 [disable readline support]),
1464         [], [enable_readline="yes"])
1465 AC_MSG_RESULT([$enable_readline])
1466
1467 LIBREADLINE=""
1468 AS_IF([test "x$enable_readline" = xyes], [
1469         AC_CHECK_LIB([readline], [readline], [
1470                 LIBREADLINE="-lreadline"
1471                 AC_DEFINE(HAVE_LIBREADLINE, 1,
1472                         [readline library is available])
1473         ])
1474 ])
1475 AC_SUBST(LIBREADLINE)
1476
1477 AC_MSG_CHECKING([whether to use libpthread for libcfs library])
1478 AC_ARG_ENABLE([libpthread],
1479         AC_HELP_STRING([--disable-libpthread],
1480                 [disable libpthread]),
1481         [], [enable_libpthread="yes"])
1482 AC_MSG_RESULT([$enable_libpthread])
1483
1484 PTHREAD_LIBS=""
1485 AS_IF([test "x$enable_libpthread" = xyes], [
1486         AC_CHECK_LIB([pthread], [pthread_create], [
1487                 PTHREAD_LIBS="-lpthread"
1488                 AC_DEFINE([HAVE_LIBPTHREAD], 1,
1489                         [use libpthread for libcfs library])
1490         ])
1491 ], [
1492         AC_MSG_WARN([Using libpthread for libcfs library is disabled explicitly])
1493 ])
1494 AC_SUBST(PTHREAD_LIBS)
1495 ]) # LIBCFS_CONFIGURE
1496
1497 #
1498 # LIBCFS_CONDITIONALS
1499 #
1500 AC_DEFUN([LIBCFS_CONDITIONALS], [
1501 AM_CONDITIONAL(HAVE_CRC32, [test "x$have_crc32" = xyes])
1502 AM_CONDITIONAL(NEED_PCLMULQDQ_CRC32,  [test "x$have_crc32" = xyes -a "x$enable_crc32_crypto" = xyes])
1503 AM_CONDITIONAL(NEED_PCLMULQDQ_CRC32C, [test "x$enable_crc32c_crypto" = xyes])
1504 ]) # LIBCFS_CONDITIONALS
1505
1506 #
1507 # LIBCFS_CONFIG_FILES
1508 #
1509 # files that should be generated with AC_OUTPUT
1510 #
1511 AC_DEFUN([LIBCFS_CONFIG_FILES], [
1512 AC_CONFIG_FILES([
1513 libcfs/Makefile
1514 libcfs/autoMakefile
1515 libcfs/autoconf/Makefile
1516 libcfs/include/Makefile
1517 libcfs/include/libcfs/Makefile
1518 libcfs/include/libcfs/linux/Makefile
1519 libcfs/include/libcfs/util/Makefile
1520 libcfs/libcfs/Makefile
1521 libcfs/libcfs/autoMakefile
1522 libcfs/libcfs/linux/Makefile
1523 libcfs/libcfs/util/Makefile
1524 ])
1525 ]) # LIBCFS_CONFIG_FILES