Whamcloud - gitweb
312542dad3956c61771c1a818c19c03307b027c5
[fs/lustre-release.git] / libcfs / autoconf / lustre-libcfs.m4
1 #
2 # LN_CONFIG_CDEBUG
3 #
4 # whether to enable various libcfs debugs (CDEBUG, ENTRY/EXIT, LASSERT, etc.)
5 #
6 AC_DEFUN([LN_CONFIG_CDEBUG],
7 [
8 AC_MSG_CHECKING([whether to enable CDEBUG, CWARN])
9 AC_ARG_ENABLE([libcfs_cdebug],
10         AC_HELP_STRING([--disable-libcfs-cdebug],
11                         [disable libcfs CDEBUG, CWARN]),
12         [],[enable_libcfs_cdebug='yes'])
13 AC_MSG_RESULT([$enable_libcfs_cdebug])
14 if test x$enable_libcfs_cdebug = xyes; then
15    AC_DEFINE(CDEBUG_ENABLED, 1, [enable libcfs CDEBUG, CWARN])
16 else
17    AC_DEFINE(CDEBUG_ENABLED, 0, [disable libcfs CDEBUG, CWARN])
18 fi
19
20 AC_MSG_CHECKING([whether to enable ENTRY/EXIT])
21 AC_ARG_ENABLE([libcfs_trace],
22         AC_HELP_STRING([--disable-libcfs-trace],
23                         [disable libcfs ENTRY/EXIT]),
24         [],[enable_libcfs_trace='yes'])
25 AC_MSG_RESULT([$enable_libcfs_trace])
26 if test x$enable_libcfs_trace = xyes; then
27    AC_DEFINE(CDEBUG_ENTRY_EXIT, 1, [enable libcfs ENTRY/EXIT])
28 else
29    AC_DEFINE(CDEBUG_ENTRY_EXIT, 0, [disable libcfs ENTRY/EXIT])
30 fi
31
32 AC_MSG_CHECKING([whether to enable LASSERT, LASSERTF])
33 AC_ARG_ENABLE([libcfs_assert],
34         AC_HELP_STRING([--disable-libcfs-assert],
35                         [disable libcfs LASSERT, LASSERTF]),
36         [],[enable_libcfs_assert='yes'])
37 AC_MSG_RESULT([$enable_libcfs_assert])
38 if test x$enable_libcfs_assert = xyes; then
39    AC_DEFINE(LIBCFS_DEBUG, 1, [enable libcfs LASSERT, LASSERTF])
40 fi
41 ])
42
43 #
44 # LIBCFS_CONFIG_PANIC_DUMPLOG
45 #
46 # check if tunable panic_dumplog is wanted
47 #
48 AC_DEFUN([LIBCFS_CONFIG_PANIC_DUMPLOG],
49 [AC_MSG_CHECKING([for tunable panic_dumplog support])
50 AC_ARG_ENABLE([panic_dumplog],
51        AC_HELP_STRING([--enable-panic_dumplog],
52                       [enable panic_dumplog]),
53        [],[enable_panic_dumplog='no'])
54 if test x$enable_panic_dumplog = xyes ; then
55        AC_DEFINE(LNET_DUMP_ON_PANIC, 1, [use dumplog on panic])
56        AC_MSG_RESULT([yes (by request)])
57 else
58        AC_MSG_RESULT([no])
59 fi
60 ])
61
62 # check kernel __u64 type
63 AC_DEFUN([LIBCFS_U64_LONG_LONG_LINUX],
64 [
65 AC_MSG_CHECKING([kernel __u64 is long long type])
66 tmp_flags="$EXTRA_KCFLAGS"
67 EXTRA_KCFLAGS="$EXTRA_KCFLAGS -Werror"
68 LB_LINUX_TRY_COMPILE([
69         #include <linux/types.h>
70         #include <linux/stddef.h>
71 ],[
72         unsigned long long *data;
73
74         data = (__u64*)sizeof(data);
75 ],[
76         AC_MSG_RESULT([yes])
77         AC_DEFINE(HAVE_KERN__U64_LONG_LONG, 1,
78                   [kernel __u64 is long long type])
79 ],[
80         AC_MSG_RESULT([no])
81 ])
82 EXTRA_KCFLAGS="$tmp_flags"
83 ])
84
85 # LIBCFS_TASKLIST_LOCK
86 # 2.6.18 remove tasklist_lock export
87 AC_DEFUN([LIBCFS_TASKLIST_LOCK],
88 [LB_CHECK_SYMBOL_EXPORT([tasklist_lock],
89 [kernel/fork.c],[
90 AC_DEFINE(HAVE_TASKLIST_LOCK, 1,
91          [tasklist_lock exported])
92 ],[
93 ])
94 ])
95
96 # LIBCFS_DIGEST_SETKEY_FLAGS
97 # digest_alg.dia_setkey takes 4 args (2.6.18)
98 #
99 AC_DEFUN([LIBCFS_DIGEST_SETKEY_FLAGS],
100 [AC_MSG_CHECKING([if kernel dia_setkey takes 4 args])
101 LB_LINUX_TRY_COMPILE([
102         #include <linux/err.h>
103         #include <linux/crypto.h>
104 ],[
105         struct digest_alg alg;
106
107         alg.dia_setkey(NULL, NULL, 0, NULL);
108 ],[
109         AC_MSG_RESULT([yes])
110         AC_DEFINE(HAVE_DIGEST_SETKEY_FLAGS, 1, [kernel dia_setkey takes 4 args])
111 ],[
112         AC_MSG_RESULT([no])
113 ])
114 ])
115
116 # 2.6.19 API changes
117 # kmem_cache_destroy(cachep) return void instead of
118 # int
119 AC_DEFUN([LIBCFS_KMEM_CACHE_DESTROY_INT],
120 [AC_MSG_CHECKING([kmem_cache_destroy(cachep) return int])
121 LB_LINUX_TRY_COMPILE([
122         #include <linux/slab.h>
123 ],[
124         int i __attribute__ ((unused));
125         i = kmem_cache_destroy(NULL);
126 ],[
127         AC_MSG_RESULT(yes)
128         AC_DEFINE(HAVE_KMEM_CACHE_DESTROY_INT, 1,
129                 [kmem_cache_destroy(cachep) return int])
130 ],[
131         AC_MSG_RESULT(NO)
132 ])
133 ])
134
135 # check cpumask_size (2.6.28)
136 AC_DEFUN([LIBCFS_CPUMASK_SIZE],
137 [AC_MSG_CHECKING([whether have cpumask_size()])
138 LB_LINUX_TRY_COMPILE([
139         #include <linux/cpumask.h>
140 ],[
141         int size = cpumask_size();
142 ],[
143         AC_MSG_RESULT(yes)
144         AC_DEFINE(HAVE_CPUMASK_SIZE, 1, [have cpumask_size()])
145 ],[
146         AC_MSG_RESULT(NO)
147 ])
148 ])
149
150 # check cpu topology functions
151 #
152 # topology_core_cpumask (2.6.29, not on all archs)
153 # topology_core_siblings (not on all archs)
154 # topology_thread_cpumask (2.6.29, not on all archs)
155 # topology_thread_siblings (not on all archs)
156 # cpumask_of_node/node_to_cpumask (not always exported)
157 AC_DEFUN([LIBCFS_CPU_TOPOLOGY],
158 [AC_MSG_CHECKING([whether have topology.h])
159 LB_LINUX_TRY_COMPILE([
160         #include <linux/topology.h>
161 ],[],[
162         AC_DEFINE(HAVE_CPU_TOPOLOGY, 1, [have CPU topology])
163         AC_MSG_RESULT(yes)
164
165         AC_MSG_CHECKING([whether have topology_core_cpumask])
166         LB_LINUX_TRY_COMPILE([
167                 #include <linux/topology.h>
168         ],[
169                 cpumask_t *mask = topology_core_cpumask(0);
170         ],[
171                 AC_DEFINE(HAVE_TOPOLOGY_CORE_CPUMASK, 1,
172                           [have topology_core_cpumask])
173                 AC_MSG_RESULT(yes)
174         ],[
175                 AC_MSG_RESULT(no)
176         ])
177
178         AC_MSG_CHECKING([whether have topology_core_siblings])
179         LB_LINUX_TRY_COMPILE([
180                 #include <linux/topology.h>
181         ],[
182                 cpumask_t mask = topology_core_siblings(0);
183         ],[
184                 AC_DEFINE(HAVE_TOPOLOGY_CORE_SIBLINGS, 1,
185                           [have topology_core_siblings])
186                 AC_MSG_RESULT(yes)
187         ],[
188                 AC_MSG_RESULT(no)
189         ])
190
191         AC_MSG_CHECKING([whether have topology_thread_cpumask])
192         LB_LINUX_TRY_COMPILE([
193                 #include <linux/topology.h>
194         ],[
195                 cpumask_t *mask = topology_thread_cpumask(0);
196         ],[
197                 AC_DEFINE(HAVE_TOPOLOGY_THREAD_CPUMASK, 1,
198                           [have topology_thread_cpumask])
199                 AC_MSG_RESULT(yes)
200         ],[
201                 AC_MSG_RESULT(no)
202         ])
203
204         AC_MSG_CHECKING([whether have topology_thread_siblings])
205         LB_LINUX_TRY_COMPILE([
206                 #include <linux/topology.h>
207         ],[
208                 cpumask_t mask = topology_thread_siblings(0);
209         ],[
210                 AC_DEFINE(HAVE_TOPOLOGY_THREAD_SIBLINGS, 1,
211                           [have topology_thread_siblings])
212                 AC_MSG_RESULT(yes)
213         ],[
214                 AC_MSG_RESULT(no)
215         ])
216
217         AC_MSG_CHECKING([whether OFED backports have cpumask_of_node])
218         # Some OFED has cpumask_of_node backports defined in
219         # its private include/linux/cpumask.h. However, it is
220         # defined conflictingly with kernel's cpumask_of_node.
221         if test -f $OFED_BACKPORT_PATH/linux/cpumask.h; then
222                 grep -q cpumask_of_node $OFED_BACKPORT_PATH/linux/cpumask.h 2>/dev/null
223                 rc=$?
224                 if test $rc -eq 0; then
225                         AC_DEFINE(HAVE_OFED_CPUMASK_OF_NODE, 1, [have cpumask_of_node])
226                         AC_MSG_RESULT(yes)
227                 else
228                         AC_MSG_RESULT(no)
229                 fi
230         fi
231
232         AC_MSG_CHECKING([whether have cpumask_of_node])
233         LB_LINUX_TRY_COMPILE([
234                 #include <linux/topology.h>
235         ],[
236                 cpumask_t *mask = cpumask_of_node(0);
237         ],[
238                 AC_DEFINE(HAVE_CPUMASK_OF_NODE, 1, [have cpumask_of_node])
239                 AC_MSG_RESULT(yes)
240         ],[
241                 AC_MSG_RESULT(no)
242         ])
243
244         AC_MSG_CHECKING([whether have cpumask_copy])
245         LB_LINUX_TRY_COMPILE([
246                 #include <linux/cpumask.h>
247         ],[
248                 cpumask_copy(NULL, NULL);
249         ],[
250                 AC_DEFINE(HAVE_CPUMASK_COPY, 1, [have cpumask_copy])
251                 AC_MSG_RESULT(yes)
252         ],[
253                 AC_MSG_RESULT(no)
254         ])
255
256         AC_MSG_CHECKING([whether have node_to_cpumask])
257         LB_LINUX_TRY_COMPILE([
258                 #include <linux/topology.h>
259         ],[
260                 cpumask_t mask = node_to_cpumask(0);
261         ],[
262                 AC_DEFINE(HAVE_NODE_TO_CPUMASK, 1, [have node_to_cpumask])
263                 AC_MSG_RESULT(yes)
264         ],[
265                 AC_MSG_RESULT(no)
266         ])
267 ],[
268         AC_MSG_RESULT(NO)
269 ])
270 ])
271
272
273 # 2.6.20 API change INIT_WORK use 2 args and not
274 # store data inside
275 AC_DEFUN([LIBCFS_3ARGS_INIT_WORK],
276 [AC_MSG_CHECKING([check INIT_WORK want 3 args])
277 LB_LINUX_TRY_COMPILE([
278         #include <linux/workqueue.h>
279 ],[
280         struct work_struct work __attribute__ ((unused));
281
282         INIT_WORK(&work, NULL, NULL);
283 ],[
284         AC_MSG_RESULT(yes)
285         AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
286                   [INIT_WORK use 3 args and store data inside])
287 ],[
288         AC_MSG_RESULT(NO)
289 ])
290 ])
291
292 # 2.6.21 api change. 'register_sysctl_table' use only one argument,
293 # instead of more old which need two.
294 AC_DEFUN([LIBCFS_2ARGS_REGISTER_SYSCTL],
295 [AC_MSG_CHECKING([check register_sysctl_table want 2 args])
296 LB_LINUX_TRY_COMPILE([
297         #include <linux/sysctl.h>
298 ],[
299         register_sysctl_table(NULL,0);
300 ],[
301         AC_MSG_RESULT(yes)
302         AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
303                   [register_sysctl_table want 2 args])
304 ],[
305         AC_MSG_RESULT(NO)
306 ])
307 ])
308
309 # 2.6.23 lost dtor argument
310 AC_DEFUN([LIBCFS_KMEM_CACHE_CREATE_DTOR],
311 [AC_MSG_CHECKING([check kmem_cache_create has dtor argument])
312 LB_LINUX_TRY_COMPILE([
313         #include <linux/slab.h>
314 ],[
315         kmem_cache_create(NULL, 0, 0, 0, NULL, NULL);
316 ],[
317         AC_MSG_RESULT(yes)
318         AC_DEFINE(HAVE_KMEM_CACHE_CREATE_DTOR, 1,
319                   [kmem_cache_create has dtor argument])
320 ],[
321         AC_MSG_RESULT(NO)
322 ])
323 ])
324
325 #2.6.23 has new shrinker API
326 AC_DEFUN([LC_REGISTER_SHRINKER],
327 [AC_MSG_CHECKING([if kernel has register_shrinker])
328 LB_LINUX_TRY_COMPILE([
329         #include <linux/mm.h>
330 ],[
331         register_shrinker(NULL);
332 ], [
333         AC_MSG_RESULT([yes])
334         AC_DEFINE(HAVE_REGISTER_SHRINKER, 1,
335                 [kernel has register_shrinker])
336 ],[
337         AC_MSG_RESULT([no])
338 ])
339 ])
340
341 # 2.6.24 request not use real numbers for ctl_name
342 AC_DEFUN([LIBCFS_SYSCTL_UNNUMBERED],
343 [AC_MSG_CHECKING([for CTL_UNNUMBERED])
344 LB_LINUX_TRY_COMPILE([
345         #include <linux/sysctl.h>
346 ],[
347         #ifndef CTL_UNNUMBERED
348         #error CTL_UNNUMBERED not exist in kernel
349         #endif
350 ],[
351         AC_MSG_RESULT(yes)
352         AC_DEFINE(HAVE_SYSCTL_UNNUMBERED, 1,
353                   [sysctl has CTL_UNNUMBERED])
354 ],[
355         AC_MSG_RESULT(NO)
356 ])
357 ])
358
359 # 2.6.24 lost scatterlist->page
360 AC_DEFUN([LIBCFS_SCATTERLIST_SETPAGE],
361 [AC_MSG_CHECKING([for exist sg_set_page])
362 LB_LINUX_TRY_COMPILE([
363         #include <asm/types.h>
364         #include <linux/scatterlist.h>
365 ],[
366         sg_set_page(NULL,NULL,0,0);
367 ],[
368         AC_MSG_RESULT(yes)
369         AC_DEFINE(HAVE_SCATTERLIST_SETPAGE, 1,
370                   [struct scatterlist has no page member])
371 ],[
372         AC_MSG_RESULT(NO)
373 ])
374 ])
375
376 # 2.6.24-rc1 sg_init_table
377 AC_DEFUN([LIBCFS_SCATTERLIST_INITTABLE],
378 [AC_MSG_CHECKING([for sg_init_table])
379 LB_LINUX_TRY_COMPILE([
380         #include <asm/types.h>
381         #include <linux/scatterlist.h>
382 ],[
383         sg_init_table(NULL,0);
384 ],[
385         AC_MSG_RESULT(yes)
386         AC_DEFINE(HAVE_SCATTERLIST_INITTABLE, 1,
387                   [scatterlist has sg_init_table])
388 ],[
389         AC_MSG_RESULT(NO)
390 ])
391 ])
392
393 # 2.6.24
394 AC_DEFUN([LIBCFS_NETWORK_NAMESPACE],
395 [AC_MSG_CHECKING([for network stack has namespaces])
396 LB_LINUX_TRY_COMPILE([
397         #include <net/net_namespace.h>
398 ],[
399         struct net *net __attribute__ ((unused));
400         net = &init_net;
401 ],[
402         AC_MSG_RESULT(yes)
403         AC_DEFINE(HAVE_INIT_NET, 1,
404                   [kernel is support network namespaces ])
405 ],[
406         AC_MSG_RESULT(NO)
407 ])
408 ])
409
410 #
411 # LIBCFS_FUNC_DUMP_TRACE
412 #
413 # 2.6.23 exports dump_trace() so we can dump_stack() on any task
414 # 2.6.24 has stacktrace_ops.address with "reliable" parameter
415 #
416 AC_DEFUN([LIBCFS_FUNC_DUMP_TRACE],
417 [LB_CHECK_SYMBOL_EXPORT([dump_trace],
418 [kernel/ksyms.c arch/${LINUX_ARCH%_64}/kernel/traps_64.c arch/x86/kernel/dumpstack_32.c arch/x86/kernel/dumpstack_64.c],[
419         tmp_flags="$EXTRA_KCFLAGS"
420         EXTRA_KCFLAGS="-Werror"
421         AC_MSG_CHECKING([whether we can really use dump_trace])
422         LB_LINUX_TRY_COMPILE([
423                 struct task_struct;
424                 struct pt_regs;
425                 #include <asm/stacktrace.h>
426         ],[
427         ],[
428                 AC_MSG_RESULT(yes)
429                 AC_DEFINE(HAVE_DUMP_TRACE, 1, [dump_trace is exported])
430         ],[
431                 AC_MSG_RESULT(no)
432         ],[
433         ])
434         AC_MSG_CHECKING([whether print_trace_address has reliable argument])
435         LB_LINUX_TRY_COMPILE([
436                 struct task_struct;
437                 struct pt_regs;
438                 #include <asm/stacktrace.h>
439         ],[
440                 ((struct stacktrace_ops *)0)->address(NULL, 0, 0);
441         ],[
442                 AC_MSG_RESULT(yes)
443                 AC_DEFINE(HAVE_TRACE_ADDRESS_RELIABLE, 1,
444                           [print_trace_address has reliable argument])
445         ],[
446                 AC_MSG_RESULT(no)
447         ],[
448         ])
449         AC_MSG_CHECKING([whether stacktrace_ops.warning is exist])
450         LB_LINUX_TRY_COMPILE([
451                 struct task_struct;
452                 struct pt_regs;
453                 #include <asm/stacktrace.h>
454         ],[
455                 ((struct stacktrace_ops *)0)->warning(NULL, NULL);
456         ],[
457                 AC_MSG_RESULT(yes)
458                 AC_DEFINE(HAVE_STACKTRACE_WARNING, 1, [stacktrace_ops.warning is exist])
459         ],[
460                 AC_MSG_RESULT(no)
461         ],[
462         ])
463         AC_MSG_CHECKING([dump_trace want address])
464         LB_LINUX_TRY_COMPILE([
465                 struct task_struct;
466                 struct pt_regs;
467                 #include <asm/stacktrace.h>
468         ],[
469                 dump_trace(NULL, NULL, NULL, 0, NULL, NULL);
470         ],[
471                 AC_MSG_RESULT(yes)
472                 AC_DEFINE(HAVE_DUMP_TRACE_ADDRESS, 1,
473                           [dump_trace want address argument])
474         ],[
475                 AC_MSG_RESULT(no)
476         ],[
477         ])
478
479 EXTRA_KCFLAGS="$tmp_flags"
480 ])
481 ])
482
483
484 # 2.6.26 use int instead of atomic for sem.count
485 AC_DEFUN([LIBCFS_SEM_COUNT],
486 [AC_MSG_CHECKING([atomic sem.count])
487 LB_LINUX_TRY_COMPILE([
488         #include <asm/semaphore.h>
489 ],[
490         struct semaphore s __attribute__ ((unused));
491
492         atomic_read(&s.count);
493 ],[
494         AC_MSG_RESULT(yes)
495         AC_DEFINE(HAVE_SEM_COUNT_ATOMIC, 1,
496                   [semaphore counter is atomic])
497 ],[
498         AC_MSG_RESULT(NO)
499 ])
500 ])
501
502 # 2.6.27 have second argument to sock_map_fd
503 AC_DEFUN([LIBCFS_SOCK_MAP_FD_2ARG],
504 [AC_MSG_CHECKING([sock_map_fd have second argument])
505 LB_LINUX_TRY_COMPILE([
506         #include <linux/net.h>
507 ],[
508         sock_map_fd(NULL, 0);
509 ],[
510         AC_MSG_RESULT(yes)
511         AC_DEFINE(HAVE_SOCK_MAP_FD_2ARG, 1,
512                   [sock_map_fd have second argument])
513 ],[
514         AC_MSG_RESULT(NO)
515 ])
516 ])
517
518 # LIBCFS_CRED_WRAPPERS
519 #
520 # wrappers for task's credentials are in sles11
521 #
522 AC_DEFUN([LIBCFS_CRED_WRAPPERS],
523 [AC_MSG_CHECKING([if kernel has wrappers for task's credentials])
524 LB_LINUX_TRY_COMPILE([
525        #include <linux/sched.h>
526 ],[
527        uid_t uid;
528
529        uid = current_uid() + sizeof(uid);
530 ],[
531        AC_MSG_RESULT([yes])
532        AC_DEFINE(HAVE_CRED_WRAPPERS, 1, [task's cred wrappers found])
533 ],[
534        AC_MSG_RESULT([no])
535 ])
536 ])
537
538 #
539 # LN_STRUCT_CRED_IN_TASK
540 #
541 # struct cred was introduced in 2.6.29 to streamline credentials in task struct
542 #
543 AC_DEFUN([LIBCFS_STRUCT_CRED_IN_TASK],
544 [AC_MSG_CHECKING([if kernel has struct cred])
545 LB_LINUX_TRY_COMPILE([
546        #include <linux/sched.h>
547 ],[
548        struct task_struct *tsk = NULL;
549        tsk->real_cred = NULL;
550 ],[
551        AC_MSG_RESULT([yes])
552        AC_DEFINE(HAVE_STRUCT_CRED, 1, [struct cred found])
553 ],[
554        AC_MSG_RESULT([no])
555 ])
556 ])
557
558 # LIBCFS_STRUCT_SHASH_ALG
559 # struct shash_alg was introduced in 2.6.29
560 #
561 AC_DEFUN([LIBCFS_STRUCT_SHASH_ALG],
562 [AC_MSG_CHECKING([if kernel has struct shash_alg])
563 LB_LINUX_TRY_COMPILE([
564         #include <linux/err.h>
565         #include <crypto/internal/hash.h>
566 ],[
567         struct shash_alg foo;
568 ],[
569         AC_MSG_RESULT([yes])
570         AC_DEFINE(HAVE_STRUCT_SHASH_ALG, 1, [kernel has struct shash_alg])
571 ],[
572         AC_MSG_RESULT([no])
573 ])
574 ])
575
576
577 #
578 # LIBCFS_FUNC_UNSHARE_FS_STRUCT
579 #
580 # unshare_fs_struct was introduced in 2.6.30 to prevent others to directly
581 # mess with copy_fs_struct
582 #
583 AC_DEFUN([LIBCFS_FUNC_UNSHARE_FS_STRUCT],
584 [AC_MSG_CHECKING([if kernel defines unshare_fs_struct()])
585 tmp_flags="$EXTRA_KCFLAGS"
586 EXTRA_KCFLAGS="-Werror"
587 LB_LINUX_TRY_COMPILE([
588        #include <linux/sched.h>
589        #include <linux/fs_struct.h>
590 ],[
591        unshare_fs_struct();
592 ],[
593        AC_MSG_RESULT([yes])
594        AC_DEFINE(HAVE_UNSHARE_FS_STRUCT, 1, [unshare_fs_struct found])
595 ],[
596        AC_MSG_RESULT([no])
597 ])
598 EXTRA_KCFLAGS="$tmp_flags"
599 ])
600
601 #
602 # LIBCFS_HAVE_IS_COMPAT_TASK
603 #
604 # Added in 2.6.17, it wasn't until 2.6.29 that all
605 # Linux architectures have is_compat_task()
606 #
607 AC_DEFUN([LIBCFS_HAVE_IS_COMPAT_TASK],
608 [AC_MSG_CHECKING([if is_compat_task() is declared])
609 LB_LINUX_TRY_COMPILE([
610         #include <linux/compat.h>
611 ],[
612         int i __attribute__ ((unused));
613         i = is_compat_task();
614 ],[
615         AC_MSG_RESULT([yes])
616         AC_DEFINE(HAVE_IS_COMPAT_TASK, 1, [is_compat_task() is available])
617 ],[
618         AC_MSG_RESULT([no])
619 ])
620 ])
621
622 #
623 # LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
624 #
625 # 2.6.32-30.el6 adds a new 'walk_stack' field in 'struct stacktrace_ops'
626 #
627 AC_DEFUN([LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK],
628 [AC_MSG_CHECKING([if 'struct stacktrace_ops' has 'walk_stack' field])
629 LB_LINUX_TRY_COMPILE([
630         #include <asm/stacktrace.h>
631 ],[
632         ((struct stacktrace_ops *)0)->walk_stack(NULL, NULL, 0, NULL, NULL, NULL, NULL);
633 ],[
634         AC_MSG_RESULT([yes])
635         AC_DEFINE(STACKTRACE_OPS_HAVE_WALK_STACK, 1, ['struct stacktrace_ops' has 'walk_stack' field])
636 ],[
637         AC_MSG_RESULT([no])
638 ])
639 ])
640
641 AC_DEFUN([LIBCFS_HAVE_OOM_H],
642 [LB_CHECK_FILE([$LINUX/include/linux/oom.h], [
643         AC_DEFINE(HAVE_LINUX_OOM_H, 1,
644                 [kernel has include/oom.h])
645 ],[
646         AC_MSG_RESULT([no])
647 ])
648 ])
649
650 AC_DEFUN([LIBCFS_HAVE_KEYTYPE_H],
651 [LB_CHECK_FILE([$LINUX/include/linux/key-type.h], [
652         AC_DEFINE(HAVE_LINUX_KEYTYPE_H, 1,
653                 [kernel has include/key-type.h])
654 ],[
655         AC_MSG_RESULT([no])
656 ])
657 ])
658
659 #
660 # check set_mems_allowed
661 # 2.6.31 adds function set_mems_allowed in cpuset.h
662 #
663 AC_DEFUN([LIBCFS_HAVE_SET_MEMS_ALLOWED],
664 [AC_MSG_CHECKING([whether have set_mems_allowed()])
665 LB_LINUX_TRY_COMPILE([
666         #include <linux/cpuset.h>
667 ],[
668         nodemask_t mask;
669
670         set_mems_allowed(mask);
671 ],[
672         AC_MSG_RESULT(yes)
673         AC_DEFINE(HAVE_SET_MEMS_ALLOWED, 1, [have set_mems_allowed()])
674 ],[
675         AC_MSG_RESULT(NO)
676 ])
677 ])
678
679
680 #
681 # RHEL6/2.6.32 want to have pointer to shrinker self pointer in handler function
682 #
683 AC_DEFUN([LC_SHRINKER_WANT_SHRINK_PTR],
684 [AC_MSG_CHECKING([shrinker want self pointer in handler])
685 LB_LINUX_TRY_COMPILE([
686         #include <linux/mm.h>
687 ],[
688         struct shrinker *tmp = NULL;
689         tmp->shrink(tmp, 0, 0);
690 ],[
691         AC_MSG_RESULT(yes)
692         AC_DEFINE(HAVE_SHRINKER_WANT_SHRINK_PTR, 1,
693                   [shrinker want self pointer in handler])
694 ],[
695         AC_MSG_RESULT(no)
696 ])
697 ])
698
699 # 2.6.18 store oom parameters in task struct.
700 # 2.6.32 store oom parameters in signal struct
701 AC_DEFUN([LIBCFS_OOMADJ_IN_SIG],
702 [AC_MSG_CHECKING([kernel store oom parameters in task])
703 LB_LINUX_TRY_COMPILE([
704         #include <linux/sched.h>
705 ],[
706         ((struct signal_struct *)0)->oom_adj = 0;
707 ],[
708         AC_MSG_RESULT(yes)
709         AC_DEFINE(HAVE_OOMADJ_IN_SIG, 1,
710                   [kernel store a oom parameters in signal struct])
711 ],[
712         AC_MSG_RESULT(no)
713 ])
714 ])
715
716 #
717 # 2.6.33 no longer has ctl_name & strategy field in struct ctl_table.
718 #
719 AC_DEFUN([LIBCFS_SYSCTL_CTLNAME],
720 [AC_MSG_CHECKING([if ctl_table has a ctl_name field])
721 LB_LINUX_TRY_COMPILE([
722         #include <linux/sysctl.h>
723 ],[
724         struct ctl_table ct;
725         ct.ctl_name = sizeof(ct);
726 ],[
727         AC_MSG_RESULT(yes)
728         AC_DEFINE(HAVE_SYSCTL_CTLNAME, 1,
729                   [ctl_table has ctl_name field])
730 ],[
731         AC_MSG_RESULT(no)
732 ])
733 ])
734
735 #
736 # LIBCFS_ADD_WAIT_QUEUE_EXCLUSIVE
737 #
738 # 2.6.34 adds __add_wait_queue_exclusive
739 #
740 AC_DEFUN([LIBCFS_ADD_WAIT_QUEUE_EXCLUSIVE],
741 [AC_MSG_CHECKING([if __add_wait_queue_exclusive exists])
742 LB_LINUX_TRY_COMPILE([
743         #include <linux/wait.h>
744 ],[
745         wait_queue_head_t queue;
746         wait_queue_t      wait;
747
748         __add_wait_queue_exclusive(&queue, &wait);
749 ],[
750         AC_MSG_RESULT(yes)
751         AC_DEFINE(HAVE___ADD_WAIT_QUEUE_EXCLUSIVE, 1,
752                   [__add_wait_queue_exclusive exists])
753 ],[
754         AC_MSG_RESULT(no)
755 ])
756 ])
757
758 #
759 # 2.6.35 kernel has sk_sleep function
760 #
761 AC_DEFUN([LC_SK_SLEEP],
762 [AC_MSG_CHECKING([if kernel has sk_sleep])
763 LB_LINUX_TRY_COMPILE([
764         #include <net/sock.h>
765 ],[
766         sk_sleep(NULL);
767 ],[
768         AC_MSG_RESULT(yes)
769         AC_DEFINE(HAVE_SK_SLEEP, 1, [kernel has sk_sleep])
770 ],[
771         AC_MSG_RESULT(no)
772 ])
773 ])
774
775 #
776 # FC15 2.6.40-5 backported the "shrink_control" parameter to the memory
777 # pressure shrinker from Linux 3.0
778 #
779 AC_DEFUN([LC_SHRINK_CONTROL],
780 [AC_MSG_CHECKING([shrink_control is present])
781 LB_LINUX_TRY_COMPILE([
782         #include <linux/mm.h>
783 ],[
784         struct shrink_control tmp = {0};
785         tmp.nr_to_scan = sizeof(tmp);
786 ],[
787         AC_MSG_RESULT(yes)
788         AC_DEFINE(HAVE_SHRINK_CONTROL, 1,
789                   [shrink_control is present])
790 ],[
791         AC_MSG_RESULT(no)
792 ])
793 ])
794
795 #
796 # LIBCFS_PROG_LINUX
797 #
798 # LNet linux kernel checks
799 #
800 AC_DEFUN([LIBCFS_PROG_LINUX],
801 [
802 LIBCFS_CONFIG_PANIC_DUMPLOG
803
804 LIBCFS_U64_LONG_LONG_LINUX
805 # 2.6.18
806 LIBCFS_TASKLIST_LOCK
807 LIBCFS_HAVE_IS_COMPAT_TASK
808 LIBCFS_DIGEST_SETKEY_FLAGS
809 # 2.6.19
810 LIBCFS_KMEM_CACHE_DESTROY_INT
811 # 2.6.20
812 LIBCFS_3ARGS_INIT_WORK
813 # 2.6.21
814 LIBCFS_2ARGS_REGISTER_SYSCTL
815 # 2.6.23
816 LIBCFS_KMEM_CACHE_CREATE_DTOR
817 LC_REGISTER_SHRINKER
818 # 2.6.24
819 LIBCFS_SYSCTL_UNNUMBERED
820 LIBCFS_SCATTERLIST_SETPAGE
821 LIBCFS_SCATTERLIST_INITTABLE
822 LIBCFS_NETWORK_NAMESPACE
823 LIBCFS_FUNC_DUMP_TRACE
824 LIBCFS_HAVE_KEYTYPE_H
825 # 2.6.26
826 LIBCFS_SEM_COUNT
827 # 2.6.27
828 LIBCFS_CRED_WRAPPERS
829 # 2.6.28
830 LIBCFS_CPUMASK_SIZE
831 # 2.6.29
832 LIBCFS_STRUCT_CRED_IN_TASK
833 LIBCFS_CPU_TOPOLOGY
834 LIBCFS_STRUCT_SHASH_ALG
835 # 2.6.30
836 LIBCFS_FUNC_UNSHARE_FS_STRUCT
837 LIBCFS_SOCK_MAP_FD_2ARG
838 # 2.6.31
839 LIBCFS_HAVE_SET_MEMS_ALLOWED
840 # 2.6.32
841 LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
842 LC_SHRINKER_WANT_SHRINK_PTR
843 LIBCFS_HAVE_OOM_H
844 LIBCFS_OOMADJ_IN_SIG
845 # 2.6.33
846 LIBCFS_SYSCTL_CTLNAME
847 # 2.6.34
848 LIBCFS_ADD_WAIT_QUEUE_EXCLUSIVE
849 # 2.6.35
850 LC_SK_SLEEP
851 # 2.6.40 fc15
852 LC_SHRINK_CONTROL
853 ])
854
855 #
856 # LIBCFS_PROG_DARWIN
857 #
858 # Darwin checks
859 #
860 AC_DEFUN([LIBCFS_PROG_DARWIN],
861 [LB_DARWIN_CHECK_FUNCS([get_preemption_level])
862 ])
863
864 #
865 # LIBCFS_PATH_DEFAULTS
866 #
867 # default paths for installed files
868 #
869 AC_DEFUN([LIBCFS_PATH_DEFAULTS],
870 [
871 ])
872
873 #
874 # LIBCFS_CONFIGURE
875 #
876 # other configure checks
877 #
878 AC_DEFUN([LIBCFS_CONFIGURE],
879 [# lnet/utils/portals.c
880 AC_CHECK_HEADERS([asm/types.h endian.h sys/ioctl.h])
881
882 # lnet/utils/debug.c
883 AC_CHECK_HEADERS([linux/version.h])
884
885 AC_CHECK_TYPE([spinlock_t],
886         [AC_DEFINE(HAVE_SPINLOCK_T, 1, [spinlock_t is defined])],
887         [],
888         [#include <linux/spinlock.h>])
889
890 # lnet/utils/wirecheck.c
891 AC_CHECK_FUNCS([strnlen])
892
893 # lnet/libcfs/user-prim.c, missing for RHEL5 and earlier userspace
894 AC_CHECK_FUNCS([strlcpy])
895
896 # libcfs/libcfs/user-prim.c, missing for RHEL5 and earlier userspace
897 AC_CHECK_FUNCS([strlcat])
898
899 AC_CHECK_TYPE([umode_t],
900         [AC_DEFINE(HAVE_UMODE_T, 1, [umode_t is defined])],
901         [],
902         [#include <asm/types.h>])
903
904 AC_CHECK_TYPE([__s8],
905         [AC_DEFINE(HAVE___S8, 1, [__s8 is defined])],
906         [],
907         [#include <asm/types.h>])
908
909 AC_CHECK_TYPE([__u8],
910         [AC_DEFINE(HAVE___U8, 1, [__u8 is defined])],
911         [],
912         [#include <asm/types.h>])
913
914 AC_CHECK_TYPE([__s16],
915         [AC_DEFINE(HAVE___S16, 1, [__s16 is defined])],
916         [],
917         [#include <asm/types.h>])
918
919 AC_CHECK_TYPE([__u16],
920         [AC_DEFINE(HAVE___U16, 1, [__u16 is defined])],
921         [],
922         [#include <asm/types.h>])
923
924 AC_CHECK_TYPE([__s32],
925         [AC_DEFINE(HAVE___S32, 1, [__s32 is defined])],
926         [],
927         [#include <asm/types.h>])
928
929 AC_CHECK_TYPE([__u32],
930         [AC_DEFINE(HAVE___U32, 1, [__u32 is defined])],
931         [],
932         [#include <asm/types.h>])
933
934 AC_CHECK_TYPE([__u64],
935         [AC_DEFINE(HAVE___U64, 1, [__u64 is defined])],
936         [],
937         [#include <asm/types.h>])
938
939 AC_CHECK_TYPE([__s64],
940         [AC_DEFINE(HAVE___S64, 1, [__s64 is defined])],
941         [],
942         [#include <asm/types.h>])
943
944 # check userland __u64 type
945 AC_MSG_CHECKING([userspace __u64 is long long type])
946 tmp_flags="$CFLAGS"
947 CFLAGS="$CFLAGS -Werror"
948 AC_COMPILE_IFELSE([
949         #include <stdio.h>
950         #include <linux/types.h>
951         #include <linux/stddef.h>
952         int main(void) {
953                 unsigned long long *data1;
954                 __u64 *data2 = NULL;
955
956                 data1 = data2;
957                 data2 = data1;
958                 return 0;
959         }
960 ],[
961         AC_MSG_RESULT([yes])
962         AC_DEFINE(HAVE_USER__U64_LONG_LONG, 1,
963                   [__u64 is long long type])
964 ],[
965         AC_MSG_RESULT([no])
966 ])
967 CFLAGS="$tmp_flags"
968
969 # --------  Check for required packages  --------------
970
971
972 AC_MSG_CHECKING([if efence debugging support is requested])
973 AC_ARG_ENABLE(efence,
974         AC_HELP_STRING([--enable-efence],
975                         [use efence library]),
976         [],[enable_efence='no'])
977 AC_MSG_RESULT([$enable_efence])
978 if test "$enable_efence" = "yes" ; then
979         LIBEFENCE="-lefence"
980         AC_DEFINE(HAVE_LIBEFENCE, 1, [libefence support is requested])
981 else
982         LIBEFENCE=""
983 fi
984 AC_SUBST(LIBEFENCE)
985
986
987 # -------- check for -lpthread support ----
988 AC_MSG_CHECKING([whether to use libpthread for libcfs library])
989 AC_ARG_ENABLE([libpthread],
990         AC_HELP_STRING([--disable-libpthread],
991                 [disable libpthread]),
992         [],[enable_libpthread=yes])
993 if test "$enable_libpthread" = "yes" ; then
994         AC_CHECK_LIB([pthread], [pthread_create],
995                 [ENABLE_LIBPTHREAD="yes"],
996                 [ENABLE_LIBPTHREAD="no"])
997         if test "$ENABLE_LIBPTHREAD" = "yes" ; then
998                 AC_MSG_RESULT([$ENABLE_LIBPTHREAD])
999                 PTHREAD_LIBS="-lpthread"
1000                 AC_DEFINE([HAVE_LIBPTHREAD], 1, [use libpthread])
1001         else
1002                 PTHREAD_LIBS=""
1003                 AC_MSG_RESULT([no libpthread is found])
1004         fi
1005         AC_SUBST(PTHREAD_LIBS)
1006 else
1007         AC_MSG_RESULT([no (disabled explicitly)])
1008         ENABLE_LIBPTHREAD="no"
1009 fi
1010 AC_SUBST(ENABLE_LIBPTHREAD)
1011
1012
1013 ])
1014
1015 #
1016 # LIBCFS_CONDITIONALS
1017 #
1018 # AM_CONDITOINAL defines for lnet
1019 #
1020 AC_DEFUN([LIBCFS_CONDITIONALS],
1021 [
1022 ])
1023
1024 #
1025 # LIBCFS_CONFIG_FILES
1026 #
1027 # files that should be generated with AC_OUTPUT
1028 #
1029 AC_DEFUN([LIBCFS_CONFIG_FILES],
1030 [AC_CONFIG_FILES([
1031 libcfs/Kernelenv
1032 libcfs/Makefile
1033 libcfs/autoMakefile
1034 libcfs/autoconf/Makefile
1035 libcfs/include/Makefile
1036 libcfs/include/libcfs/Makefile
1037 libcfs/include/libcfs/linux/Makefile
1038 libcfs/include/libcfs/posix/Makefile
1039 libcfs/include/libcfs/util/Makefile
1040 libcfs/libcfs/Makefile
1041 libcfs/libcfs/autoMakefile
1042 libcfs/libcfs/linux/Makefile
1043 libcfs/libcfs/posix/Makefile
1044 libcfs/libcfs/util/Makefile
1045 libcfs/include/libcfs/darwin/Makefile
1046 libcfs/libcfs/darwin/Makefile
1047 ])
1048 ])