Whamcloud - gitweb
a0739d462345f229ee88c4437d2dea761097d47c
[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_STRUCT_PAGE_LIST
64 #
65 # 2.6.4 no longer has page->list
66 #
67 AC_DEFUN([LIBCFS_STRUCT_PAGE_LIST],
68 [AC_MSG_CHECKING([if struct page has a list field])
69 LB_LINUX_TRY_COMPILE([
70         #include <linux/mm.h>
71 ],[
72         struct page page;
73         &page.list;
74 ],[
75         AC_MSG_RESULT([yes])
76         AC_DEFINE(HAVE_PAGE_LIST, 1, [struct page has a list field])
77 ],[
78         AC_MSG_RESULT([no])
79 ])
80 ])
81
82 #
83 # LIBCFS_STRUCT_SIGHAND
84 #
85 # red hat 2.4 adds sighand to struct task_struct
86 #
87 AC_DEFUN([LIBCFS_STRUCT_SIGHAND],
88 [AC_MSG_CHECKING([if task_struct has a sighand field])
89 LB_LINUX_TRY_COMPILE([
90         #include <linux/sched.h>
91 ],[
92         struct task_struct p;
93         p.sighand = NULL;
94 ],[
95         AC_DEFINE(CONFIG_RH_2_4_20, 1, [this kernel contains Red Hat 2.4.20 patches])
96         AC_MSG_RESULT([yes])
97 ],[
98         AC_MSG_RESULT([no])
99 ])
100 ])
101
102 #
103 # LIBCFS_FUNC_CPU_ONLINE
104 #
105 # cpu_online is different in rh 2.4, vanilla 2.4, and 2.6
106 #
107 AC_DEFUN([LIBCFS_FUNC_CPU_ONLINE],
108 [AC_MSG_CHECKING([if kernel defines cpu_online()])
109 LB_LINUX_TRY_COMPILE([
110         #include <linux/sched.h>
111 ],[
112         cpu_online(0);
113 ],[
114         AC_MSG_RESULT([yes])
115         AC_DEFINE(HAVE_CPU_ONLINE, 1, [cpu_online found])
116 ],[
117         AC_MSG_RESULT([no])
118 ])
119 ])
120
121 #
122 # LIBCFS_TYPE_GFP_T
123 #
124 # check if gfp_t is typedef-ed
125 #
126 AC_DEFUN([LIBCFS_TYPE_GFP_T],
127 [AC_MSG_CHECKING([if kernel defines gfp_t])
128 LB_LINUX_TRY_COMPILE([
129         #include <linux/gfp.h>
130 ],[
131         return sizeof(gfp_t);
132 ],[
133         AC_MSG_RESULT([yes])
134         AC_DEFINE(HAVE_GFP_T, 1, [gfp_t found])
135 ],[
136         AC_MSG_RESULT([no])
137 ])
138 ])
139
140 #
141 # LIBCFS_TYPE_CPUMASK_T
142 #
143 # same goes for cpumask_t
144 #
145 AC_DEFUN([LIBCFS_TYPE_CPUMASK_T],
146 [AC_MSG_CHECKING([if kernel defines cpumask_t])
147 LB_LINUX_TRY_COMPILE([
148         #include <linux/sched.h>
149 ],[
150         return sizeof (cpumask_t);
151 ],[
152         AC_MSG_RESULT([yes])
153         AC_DEFINE(HAVE_CPUMASK_T, 1, [cpumask_t found])
154 ],[
155         AC_MSG_RESULT([no])
156 ])
157 ])
158
159 #
160 # LIBCFS_FUNC_SHOW_TASK
161 #
162 # we export show_task(), but not all kernels have it (yet)
163 #
164 AC_DEFUN([LIBCFS_FUNC_SHOW_TASK],
165 [LB_CHECK_SYMBOL_EXPORT([show_task],
166 [kernel/ksyms.c kernel/sched.c],[
167 AC_DEFINE(HAVE_SHOW_TASK, 1, [show_task is exported])
168 ],[
169 ])
170 ])
171
172 # check userland & kernel __u64 type
173 AC_DEFUN([LIBCFS_U64_LONG_LONG],
174 [AC_MSG_CHECKING([u64 is long long type])
175 tmp_flags="$CFLAGS"
176 CFLAGS="$CFLAGS -Werror"
177 AC_COMPILE_IFELSE([
178         #include <linux/types.h>
179         #include <linux/stddef.h>
180         int main(void) {
181                 unsigned long long *data1;
182                 __u64 *data2 = NULL;
183
184                 data1 = data2;
185                 return 0;
186         }
187 ],[
188         AC_MSG_RESULT([yes])
189         AC_DEFINE(HAVE_USER__U64_LONG_LONG, 1,
190                   [__u64 is long long type])
191 ],[
192         AC_MSG_RESULT([no])
193 ])
194 CFLAGS="$tmp_flags"
195 AC_MSG_CHECKING([kernel __u64 is long long type])
196 tmp_flags="$EXTRA_KCFLAGS"
197 EXTRA_KCFLAGS="$EXTRA_KCFLAGS -Werror"
198 LB_LINUX_TRY_COMPILE([
199         #include <linux/types.h>
200         #include <linux/stddef.h>
201 ],[
202         unsigned long long *data1;
203         __u64 *data2 = NULL;
204
205         data1 = data2;
206 ],[
207         AC_MSG_RESULT([yes])
208         AC_DEFINE(HAVE_KERN__U64_LONG_LONG, 1,
209                   [kernel __u64 is long long type])
210 ],[
211         AC_MSG_RESULT([no])
212 ])
213 EXTRA_KCFLAGS="$tmp_flags"
214 ])
215
216 # check if task_struct with rcu memeber
217 AC_DEFUN([LIBCFS_TASK_RCU],
218 [AC_MSG_CHECKING([if task_struct has a rcu field])
219 LB_LINUX_TRY_COMPILE([
220         #include <linux/sched.h>
221 ],[
222         struct task_struct tsk;
223
224         tsk.rcu.next = NULL;
225 ],[
226         AC_MSG_RESULT([yes])
227         AC_DEFINE(HAVE_TASK_RCU, 1,
228                   [task_struct has rcu field])
229 ],[
230         AC_MSG_RESULT([no])
231 ])
232 ])
233
234 # LIBCFS_TASKLIST_LOCK
235 # 2.6.18 remove tasklist_lock export
236 AC_DEFUN([LIBCFS_TASKLIST_LOCK],
237 [LB_CHECK_SYMBOL_EXPORT([tasklist_lock],
238 [kernel/fork.c],[
239 AC_DEFINE(HAVE_TASKLIST_LOCK, 1,
240          [tasklist_lock exported])
241 ],[
242 ])
243 ])
244
245 # 2.6.19 API changes
246 # kmem_cache_destroy(cachep) return void instead of
247 # int
248 AC_DEFUN([LIBCFS_KMEM_CACHE_DESTROY_INT],
249 [AC_MSG_CHECKING([kmem_cache_destroy(cachep) return int])
250 LB_LINUX_TRY_COMPILE([
251         #include <linux/slab.h>
252 ],[
253         int i = kmem_cache_destroy(NULL);
254 ],[
255         AC_MSG_RESULT(yes)
256         AC_DEFINE(HAVE_KMEM_CACHE_DESTROY_INT, 1,
257                 [kmem_cache_destroy(cachep) return int])
258 ],[
259         AC_MSG_RESULT(NO)
260 ])
261 ])
262
263 # 2.6.19 API change
264 #panic_notifier_list use atomic_notifier operations
265 #
266 AC_DEFUN([LIBCFS_ATOMIC_PANIC_NOTIFIER],
267 [AC_MSG_CHECKING([panic_notifier_list is atomic])
268 LB_LINUX_TRY_COMPILE([
269         #include <linux/notifier.h>
270         #include <linux/kernel.h>
271 ],[
272         struct atomic_notifier_head panic_notifier_list;
273 ],[
274         AC_MSG_RESULT(yes)
275         AC_DEFINE(HAVE_ATOMIC_PANIC_NOTIFIER, 1,
276                 [panic_notifier_list is atomic_notifier_head])
277 ],[
278         AC_MSG_RESULT(NO)
279 ])
280 ])
281
282 # since 2.6.19 nlmsg_multicast() needs 5 argument.
283 AC_DEFUN([LIBCFS_NLMSG_MULTICAST],
284 [AC_MSG_CHECKING([nlmsg_multicast needs 5 argument])
285 LB_LINUX_TRY_COMPILE([
286         #include <net/netlink.h>
287 ],[
288         nlmsg_multicast(NULL, NULL, 0, 0, 0);
289 ],[
290         AC_MSG_RESULT(yes)
291         AC_DEFINE(HAVE_NLMSG_MULTICAST_5ARGS, 1,
292                   [nlmsg_multicast needs 5 argument])
293 ],[
294         AC_MSG_RESULT(NO)
295 ])
296 ])
297
298 #
299 # LIBCFS_NETLINK
300 #
301 # If we have netlink.h, and nlmsg_new takes 2 args (2.6.19)
302 #
303 AC_DEFUN([LIBCFS_NETLINK],
304 [AC_MSG_CHECKING([if netlink.h can be compiled])
305 LB_LINUX_TRY_COMPILE([
306         #include <net/netlink.h>
307 ],[],[
308         AC_MSG_RESULT([yes])
309         AC_DEFINE(HAVE_NETLINK, 1, [net/netlink.h found])
310
311         AC_MSG_CHECKING([if nlmsg_new takes a 2nd argument])
312         LB_LINUX_TRY_COMPILE([
313                 #include <net/netlink.h>
314         ],[
315                 nlmsg_new(100, GFP_KERNEL);
316         ],[
317                 AC_MSG_RESULT([yes])
318                 AC_DEFINE(HAVE_NETLINK_NL2, 1, [nlmsg_new takes 2 args])
319         ],[
320                 AC_MSG_RESULT([no])
321         ])
322 ],[
323         AC_MSG_RESULT([no])
324 ])
325 ])
326
327 # 2.6.20 API change INIT_WORK use 2 args and not
328 # store data inside
329 AC_DEFUN([LIBCFS_3ARGS_INIT_WORK],
330 [AC_MSG_CHECKING([check INIT_WORK want 3 args])
331 LB_LINUX_TRY_COMPILE([
332         #include <linux/workqueue.h>
333 ],[
334         struct work_struct work;
335
336         INIT_WORK(&work, NULL, NULL);
337 ],[
338         AC_MSG_RESULT(yes)
339         AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
340                   [INIT_WORK use 3 args and store data inside])
341 ],[
342         AC_MSG_RESULT(NO)
343 ])
344 ])
345
346 # 2.6.21 api change. 'register_sysctl_table' use only one argument,
347 # instead of more old which need two.
348 AC_DEFUN([LIBCFS_2ARGS_REGISTER_SYSCTL],
349 [AC_MSG_CHECKING([check register_sysctl_table want 2 args])
350 LB_LINUX_TRY_COMPILE([
351         #include <linux/sysctl.h>
352 ],[
353         return register_sysctl_table(NULL,0);
354 ],[
355         AC_MSG_RESULT(yes)
356         AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
357                   [register_sysctl_table want 2 args])
358 ],[
359         AC_MSG_RESULT(NO)
360 ])
361 ])
362
363 # 2.6.21 marks kmem_cache_t deprecated and uses struct kmem_cache
364 # instead
365 AC_DEFUN([LIBCFS_KMEM_CACHE],
366 [AC_MSG_CHECKING([check kernel has struct kmem_cache])
367 tmp_flags="$EXTRA_KCFLAGS"
368 EXTRA_KCFLAGS="-Werror"
369 LB_LINUX_TRY_COMPILE([
370         #include <linux/slab.h>
371         typedef struct kmem_cache cache_t;
372 ],[
373         cache_t *cachep = NULL;
374
375         kmem_cache_alloc(cachep, 0);
376 ],[
377         AC_MSG_RESULT(yes)
378         AC_DEFINE(HAVE_KMEM_CACHE, 1,
379                   [kernel has struct kmem_cache])
380 ],[
381         AC_MSG_RESULT(NO)
382 ])
383 EXTRA_KCFLAGS="$tmp_flags"
384 ])
385
386 # 2.6.23 lost dtor argument
387 AC_DEFUN([LIBCFS_KMEM_CACHE_CREATE_DTOR],
388 [AC_MSG_CHECKING([check kmem_cache_create has dtor argument])
389 LB_LINUX_TRY_COMPILE([
390         #include <linux/slab.h>
391 ],[
392         kmem_cache_create(NULL, 0, 0, 0, NULL, NULL);
393 ],[
394         AC_MSG_RESULT(yes)
395         AC_DEFINE(HAVE_KMEM_CACHE_CREATE_DTOR, 1,
396                   [kmem_cache_create has dtor argument])
397 ],[
398         AC_MSG_RESULT(NO)
399 ])
400 ])
401
402 # 2.6.24 
403 AC_DEFUN([LIBCFS_NETLINK_CBMUTEX],
404 [AC_MSG_CHECKING([for mutex in netlink_kernel_create])
405 LB_LINUX_TRY_COMPILE([
406         #include <linux/netlink.h>
407 ],[
408         struct mutex *lock = NULL;
409
410         netlink_kernel_create(0, 0, NULL, lock, NULL);
411 ],[
412         AC_MSG_RESULT(yes)
413         AC_DEFINE(HAVE_NETLINK_CBMUTEX, 1,
414                   [netlink_kernel_create want mutex for callback])
415 ],[
416         AC_MSG_RESULT(NO)
417 ])
418 ])
419
420 # 2.6.24 request not use real numbers for ctl_name
421 AC_DEFUN([LIBCFS_SYSCTL_UNNUMBERED],
422 [AC_MSG_CHECKING([for CTL_UNNUMBERED])
423 LB_LINUX_TRY_COMPILE([
424         #include <linux/sysctl.h>
425 ],[
426         #ifndef CTL_UNNUMBERED
427         #error CTL_UNNUMBERED not exist in kernel
428         #endif
429 ],[
430         AC_MSG_RESULT(yes)
431         AC_DEFINE(HAVE_SYSCTL_UNNUMBERED, 1,
432                   [sysctl has CTL_UNNUMBERED])
433 ],[
434         AC_MSG_RESULT(NO)
435 ])
436 ])
437
438 # 2.6.24 lost scatterlist->page
439 AC_DEFUN([LIBCFS_SCATTERLIST_SETPAGE],
440 [AC_MSG_CHECKING([for exist sg_set_page])
441 LB_LINUX_TRY_COMPILE([
442         #include <asm/types.h>
443         #include <linux/scatterlist.h>
444 ],[
445         sg_set_page(NULL,NULL,0,0);
446 ],[
447         AC_MSG_RESULT(yes)
448         AC_DEFINE(HAVE_SCATTERLIST_SETPAGE, 1,
449                   [struct scatterlist has page member])
450 ],[
451         AC_MSG_RESULT(NO)
452 ])
453 ])
454
455 # from 2.6.24 please use sg_init_table
456 AC_DEFUN([LIBCFS_SCATTERLIST_INITTABLE],
457 [AC_MSG_CHECKING([if sg_init_table is defined])
458 LB_LINUX_TRY_COMPILE([
459         #include <linux/scatterlist.h>
460 ],[
461        sg_init_table(NULL,0);
462 ],[
463         AC_MSG_RESULT(yes)
464         AC_DEFINE(HAVE_SCATTERLIST_INITTABLE, 1,
465                   [sg_init_table is defined])
466 ],[
467         AC_MSG_RESULT(NO)
468 ])
469 ])
470
471 # 2.6.24 
472 AC_DEFUN([LIBCFS_NETWORK_NAMESPACE],
473 [AC_MSG_CHECKING([for network stack has namespaces])
474 LB_LINUX_TRY_COMPILE([
475         #include <net/net_namespace.h>
476 ],[
477         struct net *net = &init_net;
478 ],[
479         AC_MSG_RESULT(yes)
480         AC_DEFINE(HAVE_INIT_NET, 1,
481                   [kernel is support network namespaces ])
482 ],[
483         AC_MSG_RESULT(NO)
484 ])
485 ])
486
487
488 # 2.6.24 
489 AC_DEFUN([LIBCFS_NETLINK_NETNS],
490 [AC_MSG_CHECKING([for netlink support net ns])
491 LB_LINUX_TRY_COMPILE([
492         #include <linux/netlink.h>
493 ],[
494         struct net *net = NULL;
495         struct mutex *lock = NULL;
496
497         netlink_kernel_create(net, 0, 0, NULL,
498                               lock,
499                               NULL);
500 ],[
501         AC_MSG_RESULT(yes)
502         AC_DEFINE(HAVE_NETLINK_NS, 1,
503                   [netlink is support network namespace])
504 # XXX
505 # for now - if kernel have netlink ns - he uses cbmutex
506         AC_DEFINE(HAVE_NETLINK_CBMUTEX, 1,
507                   [netlink_kernel_create want mutex for callback])
508
509 ],[
510         AC_MSG_RESULT(NO)
511 ])
512 ])
513
514 # ~2.6.24
515 AC_DEFUN([LIBCFS_NL_BROADCAST_GFP],
516 [AC_MSG_CHECKING([for netlink_broadcast is want to have gfp parameter])
517 LB_LINUX_TRY_COMPILE([
518         #include <linux/netlink.h>
519 ],[
520         gfp_t gfp = GFP_KERNEL;
521
522         netlink_broadcast(NULL, NULL, 0, 0, gfp);
523 ],[
524         AC_MSG_RESULT(yes)
525         AC_DEFINE(HAVE_NL_BROADCAST_GFP, 1,
526                   [netlink brouacast is want to have gfp paramter])
527 ],[
528         AC_MSG_RESULT(NO)
529 ])
530 ])
531
532 #
533 # LIBCFS_FUNC_DUMP_TRACE
534 #
535 # 2.6.23 exports dump_trace() so we can dump_stack() on any task
536 # 2.6.24 has stacktrace_ops.address with "reliable" parameter
537 #
538 AC_DEFUN([LIBCFS_FUNC_DUMP_TRACE],
539 [LB_CHECK_SYMBOL_EXPORT([dump_trace],
540 [kernel/ksyms.c arch/${LINUX_ARCH%_64}/kernel/traps_64.c],[
541         tmp_flags="$EXTRA_KCFLAGS"
542         EXTRA_KCFLAGS="-Werror"
543         AC_MSG_CHECKING([whether we can really use dump_trace])
544         LB_LINUX_TRY_COMPILE([
545                 struct task_struct;
546                 struct pt_regs;
547                 #include <asm/stacktrace.h>
548         ],[
549         ],[
550                 AC_MSG_RESULT(yes)
551                 AC_DEFINE(HAVE_DUMP_TRACE, 1, [dump_trace is exported])
552         ],[
553                 AC_MSG_RESULT(no)
554         ],[
555         ])
556         AC_MSG_CHECKING([whether print_trace_address has reliable argument])
557         LB_LINUX_TRY_COMPILE([
558                 struct task_struct;
559                 struct pt_regs;
560                 void print_addr(void *data, unsigned long addr, int reliable);
561                 #include <asm/stacktrace.h>
562         ],[
563                 struct stacktrace_ops ops;
564
565                 ops.address = print_addr;
566         ],[
567                 AC_MSG_RESULT(yes)
568                 AC_DEFINE(HAVE_TRACE_ADDRESS_RELIABLE, 1,
569                           [print_trace_address has reliable argument])
570         ],[
571                 AC_MSG_RESULT(no)
572         ],[
573         ])
574 EXTRA_KCFLAGS="$tmp_flags"
575 ])
576 ])
577
578
579 # 2.6.26 use int instead of atomic for sem.count
580 AC_DEFUN([LIBCFS_SEM_COUNT],
581 [AC_MSG_CHECKING([atomic sem.count])
582 LB_LINUX_TRY_COMPILE([
583         #include <asm/semaphore.h>
584 ],[
585         struct semaphore s;
586         
587         atomic_read(&s.count);
588 ],[
589         AC_MSG_RESULT(yes)
590         AC_DEFINE(HAVE_SEM_COUNT_ATOMIC, 1,
591                   [semaphore counter is atomic])
592 ],[
593         AC_MSG_RESULT(NO)
594 ])
595 ])
596
597 # 2.6.27 have second argument to sock_map_fd
598 AC_DEFUN([LIBCFS_SOCK_MAP_FD_2ARG],
599 [AC_MSG_CHECKING([sock_map_fd have second argument])
600 LB_LINUX_TRY_COMPILE([
601         #include <linux/net.h>
602 ],[
603         sock_map_fd(NULL, 0);
604 ],[
605         AC_MSG_RESULT(yes)
606         AC_DEFINE(HAVE_SOCK_MAP_FD_2ARG, 1,
607                   [sock_map_fd have second argument])
608 ],[
609         AC_MSG_RESULT(NO)
610 ])
611 ])
612
613 # LIBCFS_CRED_WRAPPERS
614 #
615 # wrappers for task's credentials are in sles11
616 #
617 AC_DEFUN([LIBCFS_CRED_WRAPPERS],
618 [AC_MSG_CHECKING([if kernel has wrappers for task's credentials])
619 LB_LINUX_TRY_COMPILE([
620        #include <linux/sched.h>
621 ],[
622        uid_t uid;
623
624        uid = current_uid();
625 ],[
626        AC_MSG_RESULT([yes])
627        AC_DEFINE(HAVE_CRED_WRAPPERS, 1, [task's cred wrappers found])
628 ],[
629        AC_MSG_RESULT([no])
630 ])
631 ])
632
633 #
634 # LN_STRUCT_CRED_IN_TASK
635 #
636 # struct cred was introduced in 2.6.29 to streamline credentials in task struct
637 #
638 AC_DEFUN([LIBCFS_STRUCT_CRED_IN_TASK],
639 [AC_MSG_CHECKING([if kernel has struct cred])
640 LB_LINUX_TRY_COMPILE([
641        #include <linux/sched.h>
642 ],[
643        struct task_struct *tsk = NULL;
644        tsk->real_cred = NULL;
645 ],[
646        AC_MSG_RESULT([yes])
647        AC_DEFINE(HAVE_STRUCT_CRED, 1, [struct cred found])
648 ],[
649        AC_MSG_RESULT([no])
650 ])
651 ])
652
653 #
654 # LIBCFS_FUNC_UNSHARE_FS_STRUCT
655 #
656 # unshare_fs_struct was introduced in 2.6.30 to prevent others to directly
657 # mess with copy_fs_struct
658 #
659 AC_DEFUN([LIBCFS_FUNC_UNSHARE_FS_STRUCT],
660 [AC_MSG_CHECKING([if kernel defines unshare_fs_struct()])
661 tmp_flags="$EXTRA_KCFLAGS"
662 EXTRA_KCFLAGS="-Werror"
663 LB_LINUX_TRY_COMPILE([
664        #include <linux/sched.h>
665        #include <linux/fs_struct.h>
666 ],[
667        unshare_fs_struct();
668 ],[
669        AC_MSG_RESULT([yes])
670        AC_DEFINE(HAVE_UNSHARE_FS_STRUCT, 1, [unshare_fs_struct found])
671 ],[
672        AC_MSG_RESULT([no])
673 ])
674 EXTRA_KCFLAGS="$tmp_flags"
675 ])
676
677 #
678 # LIBCFS_HAVE_IS_COMPAT_TASK
679 #
680 # Added in 2.6.17, it wasn't until 2.6.29 that all
681 # Linux architectures have is_compat_task()
682 #
683 AC_DEFUN([LIBCFS_HAVE_IS_COMPAT_TASK],
684 [AC_MSG_CHECKING([if is_compat_task() is declared])
685 LB_LINUX_TRY_COMPILE([
686         #include <linux/compat.h>
687 ],[
688         int i = is_compat_task();
689 ],[
690         AC_MSG_RESULT([yes])
691         AC_DEFINE(HAVE_IS_COMPAT_TASK, 1, [is_compat_task() is available])
692 ],[
693         AC_MSG_RESULT([no])
694 ])
695 ])
696
697 #
698 # LIBCFS_PROG_LINUX
699 #
700 # LNet linux kernel checks
701 #
702 AC_DEFUN([LIBCFS_PROG_LINUX],
703 [
704 LIBCFS_FUNC_CPU_ONLINE
705 LIBCFS_TYPE_GFP_T
706 LIBCFS_TYPE_CPUMASK_T
707 LIBCFS_CONFIG_PANIC_DUMPLOG
708
709 LIBCFS_STRUCT_PAGE_LIST
710 LIBCFS_STRUCT_SIGHAND
711 LIBCFS_FUNC_SHOW_TASK
712 LIBCFS_U64_LONG_LONG
713 LIBCFS_TASK_RCU
714 # 2.6.18
715 LIBCFS_TASKLIST_LOCK
716 LIBCFS_HAVE_IS_COMPAT_TASK
717 # 2.6.19
718 LIBCFS_NETLINK
719 LIBCFS_NLMSG_MULTICAST
720 LIBCFS_KMEM_CACHE_DESTROY_INT
721 LIBCFS_ATOMIC_PANIC_NOTIFIER
722 # 2.6.20
723 LIBCFS_3ARGS_INIT_WORK
724 # 2.6.21
725 LIBCFS_2ARGS_REGISTER_SYSCTL
726 LIBCFS_KMEM_CACHE
727 # 2.6.23
728 LIBCFS_KMEM_CACHE_CREATE_DTOR
729 LIBCFS_NETLINK_CBMUTEX
730 # 2.6.24
731 LIBCFS_SYSCTL_UNNUMBERED
732 LIBCFS_SCATTERLIST_SETPAGE
733 LIBCFS_SCATTERLIST_INITTABLE
734 LIBCFS_NL_BROADCAST_GFP
735 LIBCFS_NETWORK_NAMESPACE
736 LIBCFS_NETLINK_NETNS
737 LIBCFS_FUNC_DUMP_TRACE
738 # 2.6.26
739 LIBCFS_SEM_COUNT
740 # 2.6.27
741 LIBCFS_CRED_WRAPPERS
742 # 2.6.29
743 LIBCFS_STRUCT_CRED_IN_TASK
744 # 2.6.30
745 LIBCFS_FUNC_UNSHARE_FS_STRUCT
746 LIBCFS_SOCK_MAP_FD_2ARG
747 ])
748
749 #
750 # LIBCFS_PROG_DARWIN
751 #
752 # Darwin checks
753 #
754 AC_DEFUN([LIBCFS_PROG_DARWIN],
755 [LB_DARWIN_CHECK_FUNCS([get_preemption_level])
756 ])
757
758 #
759 # LIBCFS_PATH_DEFAULTS
760 #
761 # default paths for installed files
762 #
763 AC_DEFUN([LIBCFS_PATH_DEFAULTS],
764 [
765 ])
766
767 #
768 # LIBCFS_CONFIGURE
769 #
770 # other configure checks
771 #
772 AC_DEFUN([LIBCFS_CONFIGURE],
773 [# lnet/utils/portals.c
774 AC_CHECK_HEADERS([asm/types.h endian.h sys/ioctl.h])
775
776 # lnet/utils/debug.c
777 AC_CHECK_HEADERS([linux/version.h])
778
779 AC_CHECK_TYPE([spinlock_t],
780         [AC_DEFINE(HAVE_SPINLOCK_T, 1, [spinlock_t is defined])],
781         [],
782         [#include <linux/spinlock.h>])
783
784 # lnet/utils/wirecheck.c
785 AC_CHECK_FUNCS([strnlen])
786
787 AC_CHECK_TYPE([umode_t],
788         [AC_DEFINE(HAVE_UMODE_T, 1, [umode_t is defined])],
789         [],
790         [#include <asm/types.h>])
791
792 AC_CHECK_TYPE([__s8],
793         [AC_DEFINE(HAVE___S8, 1, [__s8 is defined])],
794         [],
795         [#include <asm/types.h>])
796
797 AC_CHECK_TYPE([__u8],
798         [AC_DEFINE(HAVE___U8, 1, [__u8 is defined])],
799         [],
800         [#include <asm/types.h>])
801
802 AC_CHECK_TYPE([__s16],
803         [AC_DEFINE(HAVE___S16, 1, [__s16 is defined])],
804         [],
805         [#include <asm/types.h>])
806
807 AC_CHECK_TYPE([__u16],
808         [AC_DEFINE(HAVE___U16, 1, [__u16 is defined])],
809         [],
810         [#include <asm/types.h>])
811
812 AC_CHECK_TYPE([__s32],
813         [AC_DEFINE(HAVE___S32, 1, [__s32 is defined])],
814         [],
815         [#include <asm/types.h>])
816
817 AC_CHECK_TYPE([__u32],
818         [AC_DEFINE(HAVE___U32, 1, [__u32 is defined])],
819         [],
820         [#include <asm/types.h>])
821
822 AC_CHECK_TYPE([__u64],
823         [AC_DEFINE(HAVE___U64, 1, [__u64 is defined])],
824         [],
825         [#include <asm/types.h>])
826
827 AC_CHECK_TYPE([__s64],
828         [AC_DEFINE(HAVE___S64, 1, [__s64 is defined])],
829         [],
830         [#include <asm/types.h>])
831
832 # --------  Check for required packages  --------------
833
834
835 AC_MSG_CHECKING([if efence debugging support is requested])
836 AC_ARG_ENABLE(efence,
837         AC_HELP_STRING([--enable-efence],
838                         [use efence library]),
839         [],[enable_efence='no'])
840 AC_MSG_RESULT([$enable_efence])
841 if test "$enable_efence" = "yes" ; then
842         LIBEFENCE="-lefence"
843         AC_DEFINE(HAVE_LIBEFENCE, 1, [libefence support is requested])
844 else
845         LIBEFENCE=""
846 fi
847 AC_SUBST(LIBEFENCE)
848
849 # ===========================================================================
850 #        http://www.gnu.org/software/autoconf-archive/ax_pthread.html
851 # ===========================================================================
852 #
853 # SYNOPSIS
854 #
855 #   AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
856 #
857 # DESCRIPTION
858 #
859 #   This macro figures out how to build C programs using POSIX threads. It
860 #   sets the PTHREAD_LIBS output variable to the threads library and linker
861 #   flags, and the PTHREAD_CFLAGS output variable to any special C compiler
862 #   flags that are needed. (The user can also force certain compiler
863 #   flags/libs to be tested by setting these environment variables.)
864 #
865 #   Also sets PTHREAD_CC to any special C compiler that is needed for
866 #   multi-threaded programs (defaults to the value of CC otherwise). (This
867 #   is necessary on AIX to use the special cc_r compiler alias.)
868 #
869 #   NOTE: You are assumed to not only compile your program with these flags,
870 #   but also link it with them as well. e.g. you should link with
871 #   $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
872 #
873 #   If you are only building threads programs, you may wish to use these
874 #   variables in your default LIBS, CFLAGS, and CC:
875 #
876 #     LIBS="$PTHREAD_LIBS $LIBS"
877 #     CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
878 #     CC="$PTHREAD_CC"
879 #
880 #   In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
881 #   has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name
882 #   (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
883 #
884 #   ACTION-IF-FOUND is a list of shell commands to run if a threads library
885 #   is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
886 #   is not found. If ACTION-IF-FOUND is not specified, the default action
887 #   will define HAVE_PTHREAD.
888 #
889 #   Please let the authors know if this macro fails on any platform, or if
890 #   you have any other suggestions or comments. This macro was based on work
891 #   by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
892 #   from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
893 #   Alejandro Forero Cuervo to the autoconf macro repository. We are also
894 #   grateful for the helpful feedback of numerous users.
895 #
896 # LICENSE
897 #
898 #   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
899 #
900 #   This program is free software: you can redistribute it and/or modify it
901 #   under the terms of the GNU General Public License as published by the
902 #   Free Software Foundation, either version 3 of the License, or (at your
903 #   option) any later version.
904 #
905 #   This program is distributed in the hope that it will be useful, but
906 #   WITHOUT ANY WARRANTY; without even the implied warranty of
907 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
908 #   Public License for more details.
909 #
910 #   You should have received a copy of the GNU General Public License along
911 #   with this program. If not, see <http://www.gnu.org/licenses/>.
912 #
913 #   As a special exception, the respective Autoconf Macro's copyright owner
914 #   gives unlimited permission to copy, distribute and modify the configure
915 #   scripts that are the output of Autoconf when processing the Macro. You
916 #   need not follow the terms of the GNU General Public License when using
917 #   or distributing such scripts, even though portions of the text of the
918 #   Macro appear in them. The GNU General Public License (GPL) does govern
919 #   all other use of the material that constitutes the Autoconf Macro.
920 #
921 #   This special exception to the GPL applies to versions of the Autoconf
922 #   Macro released by the Autoconf Archive. When you make and distribute a
923 #   modified version of the Autoconf Macro, you may extend this special
924 #   exception to the GPL to apply to your modified version as well.
925
926 #serial 8
927
928 AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
929 AC_DEFUN([AX_PTHREAD], [
930 AC_REQUIRE([AC_CANONICAL_HOST])
931 AC_LANG_SAVE
932 AC_LANG_C
933 ax_pthread_ok=no
934
935 # We used to check for pthread.h first, but this fails if pthread.h
936 # requires special compiler flags (e.g. on True64 or Sequent).
937 # It gets checked for in the link test anyway.
938
939 # First of all, check if the user has set any of the PTHREAD_LIBS,
940 # etcetera environment variables, and if threads linking works using
941 # them:
942 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
943         save_CFLAGS="$CFLAGS"
944         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
945         save_LIBS="$LIBS"
946         LIBS="$PTHREAD_LIBS $LIBS"
947         AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
948         AC_TRY_LINK_FUNC(pthread_join, ax_pthread_ok=yes)
949         AC_MSG_RESULT($ax_pthread_ok)
950         if test x"$ax_pthread_ok" = xno; then
951                 PTHREAD_LIBS=""
952                 PTHREAD_CFLAGS=""
953         fi
954         LIBS="$save_LIBS"
955         CFLAGS="$save_CFLAGS"
956 fi
957
958 # We must check for the threads library under a number of different
959 # names; the ordering is very important because some systems
960 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
961 # libraries is broken (non-POSIX).
962
963 # Create a list of thread flags to try.  Items starting with a "-" are
964 # C compiler flags, and other items are library names, except for "none"
965 # which indicates that we try without any flags at all, and "pthread-config"
966 # which is a program returning the flags for the Pth emulation library.
967
968 ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
969
970 # The ordering *is* (sometimes) important.  Some notes on the
971 # individual items follow:
972
973 # pthreads: AIX (must check this before -lpthread)
974 # none: in case threads are in libc; should be tried before -Kthread and
975 #       other compiler flags to prevent continual compiler warnings
976 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
977 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
978 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
979 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
980 # -pthreads: Solaris/gcc
981 # -mthreads: Mingw32/gcc, Lynx/gcc
982 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
983 #      doesn't hurt to check since this sometimes defines pthreads too;
984 #      also defines -D_REENTRANT)
985 #      ... -mt is also the pthreads flag for HP/aCC
986 # pthread: Linux, etcetera
987 # --thread-safe: KAI C++
988 # pthread-config: use pthread-config program (for GNU Pth library)
989
990 case "${host_cpu}-${host_os}" in
991         *solaris*)
992
993         # On Solaris (at least, for some versions), libc contains stubbed
994         # (non-functional) versions of the pthreads routines, so link-based
995         # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
996         # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
997         # a function called by this macro, so we could check for that, but
998         # who knows whether they'll stub that too in a future libc.)  So,
999         # we'll just look for -pthreads and -lpthread first:
1000
1001         ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags"
1002         ;;
1003
1004         *-darwin*)
1005         ax_pthread_flags="-pthread $ax_pthread_flags"
1006         ;;
1007 esac
1008
1009 if test x"$ax_pthread_ok" = xno; then
1010 for flag in $ax_pthread_flags; do
1011
1012         case $flag in
1013                 none)
1014                 AC_MSG_CHECKING([whether pthreads work without any flags])
1015                 ;;
1016
1017                 -*)
1018                 AC_MSG_CHECKING([whether pthreads work with $flag])
1019                 PTHREAD_CFLAGS="$flag"
1020                 ;;
1021
1022                 pthread-config)
1023                 AC_CHECK_PROG(ax_pthread_config, pthread-config, yes, no)
1024                 if test x"$ax_pthread_config" = xno; then continue; fi
1025                 PTHREAD_CFLAGS="`pthread-config --cflags`"
1026                 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
1027                 ;;
1028
1029                 *)
1030                 AC_MSG_CHECKING([for the pthreads library -l$flag])
1031                 PTHREAD_LIBS="-l$flag"
1032                 ;;
1033         esac
1034
1035         save_LIBS="$LIBS"
1036         save_CFLAGS="$CFLAGS"
1037         LIBS="$PTHREAD_LIBS $LIBS"
1038         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1039
1040         # Check for various functions.  We must include pthread.h,
1041         # since some functions may be macros.  (On the Sequent, we
1042         # need a special flag -Kthread to make this header compile.)
1043         # We check for pthread_join because it is in -lpthread on IRIX
1044         # while pthread_create is in libc.  We check for pthread_attr_init
1045         # due to DEC craziness with -lpthreads.  We check for
1046         # pthread_cleanup_push because it is one of the few pthread
1047         # functions on Solaris that doesn't have a non-functional libc stub.
1048         # We try pthread_create on general principles.
1049         AC_TRY_LINK([#include <pthread.h>
1050                      static void routine(void* a) {a=0;}
1051                      static void* start_routine(void* a) {return a;}],
1052                     [pthread_t th; pthread_attr_t attr;
1053                      pthread_join(th, 0);
1054                      pthread_attr_init(&attr);
1055                      pthread_cleanup_push(routine, 0);
1056                      pthread_create(&th,0,start_routine,0);
1057                      pthread_cleanup_pop(0); ],
1058                     [ax_pthread_ok=yes])
1059
1060         LIBS="$save_LIBS"
1061         CFLAGS="$save_CFLAGS"
1062
1063         AC_MSG_RESULT($ax_pthread_ok)
1064         if test "x$ax_pthread_ok" = xyes; then
1065                 break;
1066         fi
1067
1068         PTHREAD_LIBS=""
1069         PTHREAD_CFLAGS=""
1070 done
1071 fi
1072
1073 # Various other checks:
1074 if test "x$ax_pthread_ok" = xyes; then
1075         save_LIBS="$LIBS"
1076         LIBS="$PTHREAD_LIBS $LIBS"
1077         save_CFLAGS="$CFLAGS"
1078         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1079
1080         # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
1081         AC_MSG_CHECKING([for joinable pthread attribute])
1082         attr_name=unknown
1083         for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
1084             AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
1085                         [attr_name=$attr; break])
1086         done
1087         AC_MSG_RESULT($attr_name)
1088         if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
1089             AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
1090                                [Define to necessary symbol if this constant
1091                                 uses a non-standard name on your system.])
1092         fi
1093
1094         AC_MSG_CHECKING([if more special flags are required for pthreads])
1095         flag=no
1096         case "${host_cpu}-${host_os}" in
1097             *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
1098             *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
1099         esac
1100         AC_MSG_RESULT(${flag})
1101         if test "x$flag" != xno; then
1102             PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
1103         fi
1104
1105         LIBS="$save_LIBS"
1106         CFLAGS="$save_CFLAGS"
1107
1108         # More AIX lossage: must compile with xlc_r or cc_r
1109         if test x"$GCC" != xyes; then
1110           AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
1111         else
1112           PTHREAD_CC=$CC
1113         fi
1114 else
1115         PTHREAD_CC="$CC"
1116 fi
1117
1118 AC_SUBST(PTHREAD_LIBS)
1119 AC_SUBST(PTHREAD_CFLAGS)
1120 AC_SUBST(PTHREAD_CC)
1121
1122 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
1123 if test x"$ax_pthread_ok" = xyes; then
1124         ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
1125         :
1126 else
1127         ax_pthread_ok=no
1128         $2
1129 fi
1130 AC_LANG_RESTORE
1131 ])dnl AX_PTHREAD
1132
1133 AX_PTHREAD([[]])
1134
1135
1136 ])
1137
1138 #
1139 # LIBCFS_CONDITIONALS
1140 #
1141 # AM_CONDITOINAL defines for lnet
1142 #
1143 AC_DEFUN([LIBCFS_CONDITIONALS],
1144 [
1145 ])
1146
1147 #
1148 # LIBCFS_CONFIG_FILES
1149 #
1150 # files that should be generated with AC_OUTPUT
1151 #
1152 AC_DEFUN([LIBCFS_CONFIG_FILES],
1153 [AC_CONFIG_FILES([
1154 libcfs/Kernelenv
1155 libcfs/Makefile
1156 libcfs/autoMakefile
1157 libcfs/autoconf/Makefile
1158 libcfs/include/Makefile
1159 libcfs/include/libcfs/Makefile
1160 libcfs/include/libcfs/linux/Makefile
1161 libcfs/include/libcfs/posix/Makefile
1162 libcfs/include/libcfs/util/Makefile
1163 libcfs/libcfs/Makefile
1164 libcfs/libcfs/autoMakefile
1165 libcfs/libcfs/linux/Makefile
1166 libcfs/libcfs/posix/Makefile
1167 libcfs/libcfs/util/Makefile
1168 libcfs/include/libcfs/darwin/Makefile
1169 libcfs/libcfs/darwin/Makefile
1170 ])
1171 ])