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