Whamcloud - gitweb
LU-1714 lnet: Properly initialize sg_magic value
[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 have cpumask_of_node])
218         LB_LINUX_TRY_COMPILE([
219                 #include <linux/topology.h>
220         ],[
221                 cpumask_t *mask = cpumask_of_node(0);
222         ],[
223                 AC_DEFINE(HAVE_CPUMASK_OF_NODE, 1, [have cpumask_of_node])
224                 AC_MSG_RESULT(yes)
225         ],[
226                 AC_MSG_RESULT(no)
227         ])
228
229         AC_MSG_CHECKING([whether have node_to_cpumask])
230         LB_LINUX_TRY_COMPILE([
231                 #include <linux/topology.h>
232         ],[
233                 cpumask_t mask = node_to_cpumask(0);
234         ],[
235                 AC_DEFINE(HAVE_NODE_TO_CPUMASK, 1, [have node_to_cpumask])
236                 AC_MSG_RESULT(yes)
237         ],[
238                 AC_MSG_RESULT(no)
239         ])
240 ],[
241         AC_MSG_RESULT(NO)
242 ])
243 ])
244
245
246 # 2.6.20 API change INIT_WORK use 2 args and not
247 # store data inside
248 AC_DEFUN([LIBCFS_3ARGS_INIT_WORK],
249 [AC_MSG_CHECKING([check INIT_WORK want 3 args])
250 LB_LINUX_TRY_COMPILE([
251         #include <linux/workqueue.h>
252 ],[
253         struct work_struct work __attribute__ ((unused));
254
255         INIT_WORK(&work, NULL, NULL);
256 ],[
257         AC_MSG_RESULT(yes)
258         AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
259                   [INIT_WORK use 3 args and store data inside])
260 ],[
261         AC_MSG_RESULT(NO)
262 ])
263 ])
264
265 # 2.6.21 api change. 'register_sysctl_table' use only one argument,
266 # instead of more old which need two.
267 AC_DEFUN([LIBCFS_2ARGS_REGISTER_SYSCTL],
268 [AC_MSG_CHECKING([check register_sysctl_table want 2 args])
269 LB_LINUX_TRY_COMPILE([
270         #include <linux/sysctl.h>
271 ],[
272         register_sysctl_table(NULL,0);
273 ],[
274         AC_MSG_RESULT(yes)
275         AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
276                   [register_sysctl_table want 2 args])
277 ],[
278         AC_MSG_RESULT(NO)
279 ])
280 ])
281
282 # 2.6.23 lost dtor argument
283 AC_DEFUN([LIBCFS_KMEM_CACHE_CREATE_DTOR],
284 [AC_MSG_CHECKING([check kmem_cache_create has dtor argument])
285 LB_LINUX_TRY_COMPILE([
286         #include <linux/slab.h>
287 ],[
288         kmem_cache_create(NULL, 0, 0, 0, NULL, NULL);
289 ],[
290         AC_MSG_RESULT(yes)
291         AC_DEFINE(HAVE_KMEM_CACHE_CREATE_DTOR, 1,
292                   [kmem_cache_create has dtor argument])
293 ],[
294         AC_MSG_RESULT(NO)
295 ])
296 ])
297
298 #2.6.23 has new shrinker API
299 AC_DEFUN([LC_REGISTER_SHRINKER],
300 [AC_MSG_CHECKING([if kernel has register_shrinker])
301 LB_LINUX_TRY_COMPILE([
302         #include <linux/mm.h>
303 ],[
304         register_shrinker(NULL);
305 ], [
306         AC_MSG_RESULT([yes])
307         AC_DEFINE(HAVE_REGISTER_SHRINKER, 1,
308                 [kernel has register_shrinker])
309 ],[
310         AC_MSG_RESULT([no])
311 ])
312 ])
313
314 # 2.6.24 request not use real numbers for ctl_name
315 AC_DEFUN([LIBCFS_SYSCTL_UNNUMBERED],
316 [AC_MSG_CHECKING([for CTL_UNNUMBERED])
317 LB_LINUX_TRY_COMPILE([
318         #include <linux/sysctl.h>
319 ],[
320         #ifndef CTL_UNNUMBERED
321         #error CTL_UNNUMBERED not exist in kernel
322         #endif
323 ],[
324         AC_MSG_RESULT(yes)
325         AC_DEFINE(HAVE_SYSCTL_UNNUMBERED, 1,
326                   [sysctl has CTL_UNNUMBERED])
327 ],[
328         AC_MSG_RESULT(NO)
329 ])
330 ])
331
332 # 2.6.24 lost scatterlist->page
333 AC_DEFUN([LIBCFS_SCATTERLIST_SETPAGE],
334 [AC_MSG_CHECKING([for exist sg_set_page])
335 LB_LINUX_TRY_COMPILE([
336         #include <asm/types.h>
337         #include <linux/scatterlist.h>
338 ],[
339         sg_set_page(NULL,NULL,0,0);
340 ],[
341         AC_MSG_RESULT(yes)
342         AC_DEFINE(HAVE_SCATTERLIST_SETPAGE, 1,
343                   [struct scatterlist has page member])
344 ],[
345         AC_MSG_RESULT(NO)
346 ])
347 ])
348
349 # 2.6.24-rc1 sg_init_table
350 AC_DEFUN([LIBCFS_SCATTERLIST_INITTABLE],
351 [AC_MSG_CHECKING([for sg_init_table])
352 LB_LINUX_TRY_COMPILE([
353         #include <asm/types.h>
354         #include <linux/scatterlist.h>
355 ],[
356         sg_init_table(NULL,0);
357 ],[
358         AC_MSG_RESULT(yes)
359         AC_DEFINE(HAVE_SCATTERLIST_INITTABLE, 1,
360                   [scatterlist has sg_init_table])
361 ],[
362         AC_MSG_RESULT(NO)
363 ])
364 ])
365
366 # 2.6.24
367 AC_DEFUN([LIBCFS_NETWORK_NAMESPACE],
368 [AC_MSG_CHECKING([for network stack has namespaces])
369 LB_LINUX_TRY_COMPILE([
370         #include <net/net_namespace.h>
371 ],[
372         struct net *net __attribute__ ((unused));
373         net = &init_net;
374 ],[
375         AC_MSG_RESULT(yes)
376         AC_DEFINE(HAVE_INIT_NET, 1,
377                   [kernel is support network namespaces ])
378 ],[
379         AC_MSG_RESULT(NO)
380 ])
381 ])
382
383 #
384 # LIBCFS_FUNC_DUMP_TRACE
385 #
386 # 2.6.23 exports dump_trace() so we can dump_stack() on any task
387 # 2.6.24 has stacktrace_ops.address with "reliable" parameter
388 #
389 AC_DEFUN([LIBCFS_FUNC_DUMP_TRACE],
390 [LB_CHECK_SYMBOL_EXPORT([dump_trace],
391 [kernel/ksyms.c arch/${LINUX_ARCH%_64}/kernel/traps_64.c arch/x86/kernel/dumpstack_32.c arch/x86/kernel/dumpstack_64.c],[
392         tmp_flags="$EXTRA_KCFLAGS"
393         EXTRA_KCFLAGS="-Werror"
394         AC_MSG_CHECKING([whether we can really use dump_trace])
395         LB_LINUX_TRY_COMPILE([
396                 struct task_struct;
397                 struct pt_regs;
398                 #include <asm/stacktrace.h>
399         ],[
400         ],[
401                 AC_MSG_RESULT(yes)
402                 AC_DEFINE(HAVE_DUMP_TRACE, 1, [dump_trace is exported])
403         ],[
404                 AC_MSG_RESULT(no)
405         ],[
406         ])
407         AC_MSG_CHECKING([whether print_trace_address has reliable argument])
408         LB_LINUX_TRY_COMPILE([
409                 struct task_struct;
410                 struct pt_regs;
411                 #include <asm/stacktrace.h>
412         ],[
413                 ((struct stacktrace_ops *)0)->address(NULL, 0, 0);
414         ],[
415                 AC_MSG_RESULT(yes)
416                 AC_DEFINE(HAVE_TRACE_ADDRESS_RELIABLE, 1,
417                           [print_trace_address has reliable argument])
418         ],[
419                 AC_MSG_RESULT(no)
420         ],[
421         ])
422         AC_MSG_CHECKING([whether stacktrace_ops.warning is exist])
423         LB_LINUX_TRY_COMPILE([
424                 struct task_struct;
425                 struct pt_regs;
426                 #include <asm/stacktrace.h>
427         ],[
428                 ((struct stacktrace_ops *)0)->warning(NULL, NULL);
429         ],[
430                 AC_MSG_RESULT(yes)
431                 AC_DEFINE(HAVE_STACKTRACE_WARNING, 1, [stacktrace_ops.warning is exist])
432         ],[
433                 AC_MSG_RESULT(no)
434         ],[
435         ])
436         AC_MSG_CHECKING([dump_trace want address])
437         LB_LINUX_TRY_COMPILE([
438                 struct task_struct;
439                 struct pt_regs;
440                 #include <asm/stacktrace.h>
441         ],[
442                 dump_trace(NULL, NULL, NULL, 0, NULL, NULL);
443         ],[
444                 AC_MSG_RESULT(yes)
445                 AC_DEFINE(HAVE_DUMP_TRACE_ADDRESS, 1,
446                           [dump_trace want address argument])
447         ],[
448                 AC_MSG_RESULT(no)
449         ],[
450         ])
451
452 EXTRA_KCFLAGS="$tmp_flags"
453 ])
454 ])
455
456
457 # 2.6.26 use int instead of atomic for sem.count
458 AC_DEFUN([LIBCFS_SEM_COUNT],
459 [AC_MSG_CHECKING([atomic sem.count])
460 LB_LINUX_TRY_COMPILE([
461         #include <asm/semaphore.h>
462 ],[
463         struct semaphore s __attribute__ ((unused));
464
465         atomic_read(&s.count);
466 ],[
467         AC_MSG_RESULT(yes)
468         AC_DEFINE(HAVE_SEM_COUNT_ATOMIC, 1,
469                   [semaphore counter is atomic])
470 ],[
471         AC_MSG_RESULT(NO)
472 ])
473 ])
474
475 # 2.6.27 have second argument to sock_map_fd
476 AC_DEFUN([LIBCFS_SOCK_MAP_FD_2ARG],
477 [AC_MSG_CHECKING([sock_map_fd have second argument])
478 LB_LINUX_TRY_COMPILE([
479         #include <linux/net.h>
480 ],[
481         sock_map_fd(NULL, 0);
482 ],[
483         AC_MSG_RESULT(yes)
484         AC_DEFINE(HAVE_SOCK_MAP_FD_2ARG, 1,
485                   [sock_map_fd have second argument])
486 ],[
487         AC_MSG_RESULT(NO)
488 ])
489 ])
490
491 # LIBCFS_CRED_WRAPPERS
492 #
493 # wrappers for task's credentials are in sles11
494 #
495 AC_DEFUN([LIBCFS_CRED_WRAPPERS],
496 [AC_MSG_CHECKING([if kernel has wrappers for task's credentials])
497 LB_LINUX_TRY_COMPILE([
498        #include <linux/sched.h>
499 ],[
500        uid_t uid;
501
502        uid = current_uid() + sizeof(uid);
503 ],[
504        AC_MSG_RESULT([yes])
505        AC_DEFINE(HAVE_CRED_WRAPPERS, 1, [task's cred wrappers found])
506 ],[
507        AC_MSG_RESULT([no])
508 ])
509 ])
510
511 #
512 # LN_STRUCT_CRED_IN_TASK
513 #
514 # struct cred was introduced in 2.6.29 to streamline credentials in task struct
515 #
516 AC_DEFUN([LIBCFS_STRUCT_CRED_IN_TASK],
517 [AC_MSG_CHECKING([if kernel has struct cred])
518 LB_LINUX_TRY_COMPILE([
519        #include <linux/sched.h>
520 ],[
521        struct task_struct *tsk = NULL;
522        tsk->real_cred = NULL;
523 ],[
524        AC_MSG_RESULT([yes])
525        AC_DEFINE(HAVE_STRUCT_CRED, 1, [struct cred found])
526 ],[
527        AC_MSG_RESULT([no])
528 ])
529 ])
530
531 # LIBCFS_STRUCT_SHASH_ALG
532 # struct shash_alg was introduced in 2.6.29
533 #
534 AC_DEFUN([LIBCFS_STRUCT_SHASH_ALG],
535 [AC_MSG_CHECKING([if kernel has struct shash_alg])
536 LB_LINUX_TRY_COMPILE([
537         #include <linux/err.h>
538         #include <crypto/internal/hash.h>
539 ],[
540         struct shash_alg foo;
541 ],[
542         AC_MSG_RESULT([yes])
543         AC_DEFINE(HAVE_STRUCT_SHASH_ALG, 1, [kernel has struct shash_alg])
544 ],[
545         AC_MSG_RESULT([no])
546 ])
547 ])
548
549
550 #
551 # LIBCFS_FUNC_UNSHARE_FS_STRUCT
552 #
553 # unshare_fs_struct was introduced in 2.6.30 to prevent others to directly
554 # mess with copy_fs_struct
555 #
556 AC_DEFUN([LIBCFS_FUNC_UNSHARE_FS_STRUCT],
557 [AC_MSG_CHECKING([if kernel defines unshare_fs_struct()])
558 tmp_flags="$EXTRA_KCFLAGS"
559 EXTRA_KCFLAGS="-Werror"
560 LB_LINUX_TRY_COMPILE([
561        #include <linux/sched.h>
562        #include <linux/fs_struct.h>
563 ],[
564        unshare_fs_struct();
565 ],[
566        AC_MSG_RESULT([yes])
567        AC_DEFINE(HAVE_UNSHARE_FS_STRUCT, 1, [unshare_fs_struct found])
568 ],[
569        AC_MSG_RESULT([no])
570 ])
571 EXTRA_KCFLAGS="$tmp_flags"
572 ])
573
574 #
575 # LIBCFS_HAVE_IS_COMPAT_TASK
576 #
577 # Added in 2.6.17, it wasn't until 2.6.29 that all
578 # Linux architectures have is_compat_task()
579 #
580 AC_DEFUN([LIBCFS_HAVE_IS_COMPAT_TASK],
581 [AC_MSG_CHECKING([if is_compat_task() is declared])
582 LB_LINUX_TRY_COMPILE([
583         #include <linux/compat.h>
584 ],[
585         int i __attribute__ ((unused));
586         i = is_compat_task();
587 ],[
588         AC_MSG_RESULT([yes])
589         AC_DEFINE(HAVE_IS_COMPAT_TASK, 1, [is_compat_task() is available])
590 ],[
591         AC_MSG_RESULT([no])
592 ])
593 ])
594
595 #
596 # LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
597 #
598 # 2.6.32-30.el6 adds a new 'walk_stack' field in 'struct stacktrace_ops'
599 #
600 AC_DEFUN([LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK],
601 [AC_MSG_CHECKING([if 'struct stacktrace_ops' has 'walk_stack' field])
602 LB_LINUX_TRY_COMPILE([
603         #include <asm/stacktrace.h>
604 ],[
605         ((struct stacktrace_ops *)0)->walk_stack(NULL, NULL, 0, NULL, NULL, NULL, NULL);
606 ],[
607         AC_MSG_RESULT([yes])
608         AC_DEFINE(STACKTRACE_OPS_HAVE_WALK_STACK, 1, ['struct stacktrace_ops' has 'walk_stack' field])
609 ],[
610         AC_MSG_RESULT([no])
611 ])
612 ])
613
614 AC_DEFUN([LIBCFS_HAVE_OOM_H],
615 [LB_CHECK_FILE([$LINUX/include/linux/oom.h], [
616         AC_DEFINE(HAVE_LINUX_OOM_H, 1,
617                 [kernel has include/oom.h])
618 ],[
619         AC_MSG_RESULT([no])
620 ])
621 ])
622
623 #
624 # check set_mems_allowed
625 # 2.6.31 adds function set_mems_allowed in cpuset.h
626 #
627 AC_DEFUN([LIBCFS_HAVE_SET_MEMS_ALLOWED],
628 [AC_MSG_CHECKING([whether have set_mems_allowed()])
629 LB_LINUX_TRY_COMPILE([
630         #include <linux/cpuset.h>
631 ],[
632         nodemask_t mask;
633
634         set_mems_allowed(mask);
635 ],[
636         AC_MSG_RESULT(yes)
637         AC_DEFINE(HAVE_SET_MEMS_ALLOWED, 1, [have set_mems_allowed()])
638 ],[
639         AC_MSG_RESULT(NO)
640 ])
641 ])
642
643
644 #
645 # RHEL6/2.6.32 want to have pointer to shrinker self pointer in handler function
646 #
647 AC_DEFUN([LC_SHRINKER_WANT_SHRINK_PTR],
648 [AC_MSG_CHECKING([shrinker want self pointer in handler])
649 LB_LINUX_TRY_COMPILE([
650         #include <linux/mm.h>
651 ],[
652         struct shrinker *tmp = NULL;
653         tmp->shrink(tmp, 0, 0);
654 ],[
655         AC_MSG_RESULT(yes)
656         AC_DEFINE(HAVE_SHRINKER_WANT_SHRINK_PTR, 1,
657                   [shrinker want self pointer in handler])
658 ],[
659         AC_MSG_RESULT(no)
660 ])
661 ])
662
663 # 2.6.18 store oom parameters in task struct.
664 # 2.6.32 store oom parameters in signal struct
665 AC_DEFUN([LIBCFS_OOMADJ_IN_SIG],
666 [AC_MSG_CHECKING([kernel store oom parameters in task])
667 LB_LINUX_TRY_COMPILE([
668         #include <linux/sched.h>
669 ],[
670         ((struct signal_struct *)0)->oom_adj = 0;
671 ],[
672         AC_MSG_RESULT(yes)
673         AC_DEFINE(HAVE_OOMADJ_IN_SIG, 1,
674                   [kernel store a oom parameters in signal struct])
675 ],[
676         AC_MSG_RESULT(no)
677 ])
678 ])
679
680 #
681 # 2.6.33 no longer has ctl_name & strategy field in struct ctl_table.
682 #
683 AC_DEFUN([LIBCFS_SYSCTL_CTLNAME],
684 [AC_MSG_CHECKING([if ctl_table has a ctl_name field])
685 LB_LINUX_TRY_COMPILE([
686         #include <linux/sysctl.h>
687 ],[
688         struct ctl_table ct;
689         ct.ctl_name = sizeof(ct);
690 ],[
691         AC_MSG_RESULT(yes)
692         AC_DEFINE(HAVE_SYSCTL_CTLNAME, 1,
693                   [ctl_table has ctl_name field])
694 ],[
695         AC_MSG_RESULT(no)
696 ])
697 ])
698
699 #
700 # LIBCFS_ADD_WAIT_QUEUE_EXCLUSIVE
701 #
702 # 2.6.34 adds __add_wait_queue_exclusive
703 #
704 AC_DEFUN([LIBCFS_ADD_WAIT_QUEUE_EXCLUSIVE],
705 [AC_MSG_CHECKING([if __add_wait_queue_exclusive exists])
706 LB_LINUX_TRY_COMPILE([
707         #include <linux/wait.h>
708 ],[
709         wait_queue_head_t queue;
710         wait_queue_t      wait;
711
712         __add_wait_queue_exclusive(&queue, &wait);
713 ],[
714         AC_MSG_RESULT(yes)
715         AC_DEFINE(HAVE___ADD_WAIT_QUEUE_EXCLUSIVE, 1,
716                   [__add_wait_queue_exclusive exists])
717 ],[
718         AC_MSG_RESULT(no)
719 ])
720 ])
721
722 #
723 # 2.6.35 kernel has sk_sleep function
724 #
725 AC_DEFUN([LC_SK_SLEEP],
726 [AC_MSG_CHECKING([if kernel has sk_sleep])
727 LB_LINUX_TRY_COMPILE([
728         #include <net/sock.h>
729 ],[
730         sk_sleep(NULL);
731 ],[
732         AC_MSG_RESULT(yes)
733         AC_DEFINE(HAVE_SK_SLEEP, 1, [kernel has sk_sleep])
734 ],[
735         AC_MSG_RESULT(no)
736 ])
737 ])
738
739 #
740 # FC15 2.6.40-5 backported the "shrink_control" parameter to the memory
741 # pressure shrinker from Linux 3.0
742 #
743 AC_DEFUN([LC_SHRINK_CONTROL],
744 [AC_MSG_CHECKING([shrink_control is present])
745 LB_LINUX_TRY_COMPILE([
746         #include <linux/mm.h>
747 ],[
748         struct shrink_control tmp = {0};
749         tmp.nr_to_scan = sizeof(tmp);
750 ],[
751         AC_MSG_RESULT(yes)
752         AC_DEFINE(HAVE_SHRINK_CONTROL, 1,
753                   [shrink_control is present])
754 ],[
755         AC_MSG_RESULT(no)
756 ])
757 ])
758
759 #
760 # LIBCFS_PROG_LINUX
761 #
762 # LNet linux kernel checks
763 #
764 AC_DEFUN([LIBCFS_PROG_LINUX],
765 [
766 LIBCFS_CONFIG_PANIC_DUMPLOG
767
768 LIBCFS_U64_LONG_LONG_LINUX
769 # 2.6.18
770 LIBCFS_TASKLIST_LOCK
771 LIBCFS_HAVE_IS_COMPAT_TASK
772 LIBCFS_DIGEST_SETKEY_FLAGS
773 # 2.6.19
774 LIBCFS_KMEM_CACHE_DESTROY_INT
775 # 2.6.20
776 LIBCFS_3ARGS_INIT_WORK
777 # 2.6.21
778 LIBCFS_2ARGS_REGISTER_SYSCTL
779 # 2.6.23
780 LIBCFS_KMEM_CACHE_CREATE_DTOR
781 LC_REGISTER_SHRINKER
782 # 2.6.24
783 LIBCFS_SYSCTL_UNNUMBERED
784 LIBCFS_SCATTERLIST_SETPAGE
785 LIBCFS_SCATTERLIST_INITTABLE
786 LIBCFS_NETWORK_NAMESPACE
787 LIBCFS_FUNC_DUMP_TRACE
788 # 2.6.26
789 LIBCFS_SEM_COUNT
790 # 2.6.27
791 LIBCFS_CRED_WRAPPERS
792 # 2.6.28
793 LIBCFS_CPUMASK_SIZE
794 # 2.6.29
795 LIBCFS_STRUCT_CRED_IN_TASK
796 LIBCFS_CPU_TOPOLOGY
797 LIBCFS_STRUCT_SHASH_ALG
798 # 2.6.30
799 LIBCFS_FUNC_UNSHARE_FS_STRUCT
800 LIBCFS_SOCK_MAP_FD_2ARG
801 # 2.6.31
802 LIBCFS_HAVE_SET_MEMS_ALLOWED
803 # 2.6.32
804 LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
805 LC_SHRINKER_WANT_SHRINK_PTR
806 LIBCFS_HAVE_OOM_H
807 LIBCFS_OOMADJ_IN_SIG
808 # 2.6.33
809 LIBCFS_SYSCTL_CTLNAME
810 # 2.6.34
811 LIBCFS_ADD_WAIT_QUEUE_EXCLUSIVE
812 # 2.6.35
813 LC_SK_SLEEP
814 # 2.6.40 fc15
815 LC_SHRINK_CONTROL
816 ])
817
818 #
819 # LIBCFS_PROG_DARWIN
820 #
821 # Darwin checks
822 #
823 AC_DEFUN([LIBCFS_PROG_DARWIN],
824 [LB_DARWIN_CHECK_FUNCS([get_preemption_level])
825 ])
826
827 #
828 # LIBCFS_PATH_DEFAULTS
829 #
830 # default paths for installed files
831 #
832 AC_DEFUN([LIBCFS_PATH_DEFAULTS],
833 [
834 ])
835
836 #
837 # LIBCFS_CONFIGURE
838 #
839 # other configure checks
840 #
841 AC_DEFUN([LIBCFS_CONFIGURE],
842 [# lnet/utils/portals.c
843 AC_CHECK_HEADERS([asm/types.h endian.h sys/ioctl.h])
844
845 # lnet/utils/debug.c
846 AC_CHECK_HEADERS([linux/version.h])
847
848 AC_CHECK_TYPE([spinlock_t],
849         [AC_DEFINE(HAVE_SPINLOCK_T, 1, [spinlock_t is defined])],
850         [],
851         [#include <linux/spinlock.h>])
852
853 # lnet/utils/wirecheck.c
854 AC_CHECK_FUNCS([strnlen])
855
856 # lnet/libcfs/user-prim.c, missing for RHEL5 and earlier userspace
857 AC_CHECK_FUNCS([strlcpy])
858
859 # libcfs/libcfs/user-prim.c, missing for RHEL5 and earlier userspace
860 AC_CHECK_FUNCS([strlcat])
861
862 AC_CHECK_TYPE([umode_t],
863         [AC_DEFINE(HAVE_UMODE_T, 1, [umode_t is defined])],
864         [],
865         [#include <asm/types.h>])
866
867 AC_CHECK_TYPE([__s8],
868         [AC_DEFINE(HAVE___S8, 1, [__s8 is defined])],
869         [],
870         [#include <asm/types.h>])
871
872 AC_CHECK_TYPE([__u8],
873         [AC_DEFINE(HAVE___U8, 1, [__u8 is defined])],
874         [],
875         [#include <asm/types.h>])
876
877 AC_CHECK_TYPE([__s16],
878         [AC_DEFINE(HAVE___S16, 1, [__s16 is defined])],
879         [],
880         [#include <asm/types.h>])
881
882 AC_CHECK_TYPE([__u16],
883         [AC_DEFINE(HAVE___U16, 1, [__u16 is defined])],
884         [],
885         [#include <asm/types.h>])
886
887 AC_CHECK_TYPE([__s32],
888         [AC_DEFINE(HAVE___S32, 1, [__s32 is defined])],
889         [],
890         [#include <asm/types.h>])
891
892 AC_CHECK_TYPE([__u32],
893         [AC_DEFINE(HAVE___U32, 1, [__u32 is defined])],
894         [],
895         [#include <asm/types.h>])
896
897 AC_CHECK_TYPE([__u64],
898         [AC_DEFINE(HAVE___U64, 1, [__u64 is defined])],
899         [],
900         [#include <asm/types.h>])
901
902 AC_CHECK_TYPE([__s64],
903         [AC_DEFINE(HAVE___S64, 1, [__s64 is defined])],
904         [],
905         [#include <asm/types.h>])
906
907 # check userland __u64 type
908 AC_MSG_CHECKING([userspace __u64 is long long type])
909 tmp_flags="$CFLAGS"
910 CFLAGS="$CFLAGS -Werror"
911 AC_COMPILE_IFELSE([
912         #include <stdio.h>
913         #include <linux/types.h>
914         #include <linux/stddef.h>
915         int main(void) {
916                 unsigned long long *data1;
917                 __u64 *data2 = NULL;
918
919                 data1 = data2;
920                 return 0;
921         }
922 ],[
923         AC_MSG_RESULT([yes])
924         AC_DEFINE(HAVE_USER__U64_LONG_LONG, 1,
925                   [__u64 is long long type])
926 ],[
927         AC_MSG_RESULT([no])
928 ])
929 CFLAGS="$tmp_flags"
930
931 # --------  Check for required packages  --------------
932
933
934 AC_MSG_CHECKING([if efence debugging support is requested])
935 AC_ARG_ENABLE(efence,
936         AC_HELP_STRING([--enable-efence],
937                         [use efence library]),
938         [],[enable_efence='no'])
939 AC_MSG_RESULT([$enable_efence])
940 if test "$enable_efence" = "yes" ; then
941         LIBEFENCE="-lefence"
942         AC_DEFINE(HAVE_LIBEFENCE, 1, [libefence support is requested])
943 else
944         LIBEFENCE=""
945 fi
946 AC_SUBST(LIBEFENCE)
947
948
949 # -------- check for -lpthread support ----
950 AC_MSG_CHECKING([whether to use libpthread for libcfs library])
951 AC_ARG_ENABLE([libpthread],
952         AC_HELP_STRING([--disable-libpthread],
953                 [disable libpthread]),
954         [],[enable_libpthread=yes])
955 if test "$enable_libpthread" = "yes" ; then
956         AC_CHECK_LIB([pthread], [pthread_create],
957                 [ENABLE_LIBPTHREAD="yes"],
958                 [ENABLE_LIBPTHREAD="no"])
959         if test "$ENABLE_LIBPTHREAD" = "yes" ; then
960                 AC_MSG_RESULT([$ENABLE_LIBPTHREAD])
961                 PTHREAD_LIBS="-lpthread"
962                 AC_DEFINE([HAVE_LIBPTHREAD], 1, [use libpthread])
963         else
964                 PTHREAD_LIBS=""
965                 AC_MSG_RESULT([no libpthread is found])
966         fi
967         AC_SUBST(PTHREAD_LIBS)
968 else
969         AC_MSG_RESULT([no (disabled explicitly)])
970         ENABLE_LIBPTHREAD="no"
971 fi
972 AC_SUBST(ENABLE_LIBPTHREAD)
973
974
975 ])
976
977 #
978 # LIBCFS_CONDITIONALS
979 #
980 # AM_CONDITOINAL defines for lnet
981 #
982 AC_DEFUN([LIBCFS_CONDITIONALS],
983 [
984 ])
985
986 #
987 # LIBCFS_CONFIG_FILES
988 #
989 # files that should be generated with AC_OUTPUT
990 #
991 AC_DEFUN([LIBCFS_CONFIG_FILES],
992 [AC_CONFIG_FILES([
993 libcfs/Kernelenv
994 libcfs/Makefile
995 libcfs/autoMakefile
996 libcfs/autoconf/Makefile
997 libcfs/include/Makefile
998 libcfs/include/libcfs/Makefile
999 libcfs/include/libcfs/linux/Makefile
1000 libcfs/include/libcfs/posix/Makefile
1001 libcfs/include/libcfs/util/Makefile
1002 libcfs/libcfs/Makefile
1003 libcfs/libcfs/autoMakefile
1004 libcfs/libcfs/linux/Makefile
1005 libcfs/libcfs/posix/Makefile
1006 libcfs/libcfs/util/Makefile
1007 libcfs/include/libcfs/darwin/Makefile
1008 libcfs/libcfs/darwin/Makefile
1009 ])
1010 ])