Whamcloud - gitweb
LU-12485 obdclass: 0-nlink race in lu_object_find_at()
[fs/lustre-release.git] / lnet / autoconf / lustre-lnet.m4
1 #
2 # LN_CHECK_GCC_VERSION
3 #
4 # Check compiler version
5 #
6 AC_DEFUN([LN_CHECK_GCC_VERSION], [
7 AC_MSG_CHECKING([compiler version])
8 PTL_CC_VERSION=`$CC --version | awk '/^gcc/{print $ 3}'`
9 PTL_MIN_CC_VERSION="3.2.2"
10 v2n() {
11         awk -F. '{printf "%d\n", (($ 1)*100+($ 2))*100+($ 3)}'
12 }
13 if test -z "$PTL_CC_VERSION" -o \
14         $(echo $PTL_CC_VERSION | v2n) -ge $(echo $PTL_MIN_CC_VERSION | v2n); then
15         AC_MSG_RESULT([ok])
16 else
17         AC_MSG_RESULT([Buggy compiler found])
18         AC_MSG_ERROR([Need gcc version >= $PTL_MIN_CC_VERSION])
19 fi
20 ]) # LN_CHECK_GCC_VERSION
21
22 #
23 # LN_CONFIG_AFFINITY
24 #
25 # check if cpu affinity is available/wanted
26 #
27 AC_DEFUN([LN_CONFIG_AFFINITY], [
28 AC_MSG_CHECKING([whether to enable CPU affinity support])
29 AC_ARG_ENABLE([affinity],
30         AC_HELP_STRING([--disable-affinity],
31                 [disable process/irq affinity]),
32         [], [enable_affinity="yes"])
33 AC_MSG_RESULT([$enable_affinity])
34 AS_IF([test "x$enable_affinity" = xyes], [
35         LB_CHECK_COMPILE([if Linux kernel has cpu affinity support],
36         set_cpus_allowed_ptr, [
37                 #include <linux/sched.h>
38         ],[
39                 struct task_struct *t = NULL;
40                 cpumask_t m = { };
41
42                 set_cpus_allowed_ptr(t, &m);
43         ],[
44                 AC_DEFINE(CPU_AFFINITY, 1,
45                         [kernel has cpu affinity support])
46         ])
47 ])
48 ]) # LN_CONFIG_AFFINITY
49
50 #
51 # LN_CONFIG_BACKOFF
52 #
53 # check if tunable tcp backoff is available/wanted
54 #
55 AC_DEFUN([LN_CONFIG_BACKOFF], [
56 AC_MSG_CHECKING([whether to enable tunable backoff TCP support])
57 AC_ARG_ENABLE([backoff],
58         AC_HELP_STRING([--disable-backoff],
59                 [disable socknal tunable backoff]),
60         [], [enable_backoff="yes"])
61 AC_MSG_RESULT([$enable_backoff])
62 AS_IF([test "x$enable_backoff" = xyes], [
63         AC_MSG_CHECKING([if Linux kernel has tunable backoff TCP support])
64         AS_IF([grep -c TCP_BACKOFF $LINUX/include/linux/tcp.h >/dev/null], [
65                 AC_MSG_RESULT([yes])
66                 AC_DEFINE(SOCKNAL_BACKOFF, 1, [use tunable backoff TCP])
67                 AS_IF([grep rto_max $LINUX/include/linux/tcp.h | grep -q __u16 >/dev/null],
68                         [AC_DEFINE(SOCKNAL_BACKOFF_MS, 1,
69                                 [tunable backoff TCP in ms])])
70         ], [
71                 AC_MSG_RESULT([no])
72         ])
73 ])
74 ]) # LN_CONFIG_BACKOFF
75
76 #
77 # LN_CONFIG_DLC
78 #
79 # Configure dlc
80 #
81 # fail to build if libyaml is not installed
82 #
83 AC_DEFUN([LN_CONFIG_DLC], [
84         AS_IF([test "x$enable_dist" = xno], [
85                 AC_CHECK_LIB([yaml], [yaml_parser_initialize],
86                              [LIBYAML="libyaml"],
87                              [AC_MSG_ERROR([YAML development libraries not not installed])],
88                              [-lm])
89         ])
90 ])
91
92 #
93 # LN_CONFIG_O2IB
94 #
95 # If current OFED installed (assume with "ofed_info") and devel
96 # headers are not found, error because we assume OFED infiniband
97 # driver needs to be used and we must configure/build with it.
98 # Current OFED headers detection mechanism allow for non-standard
99 # prefix but relies on "ofed_info" command and on "%prefix/openib"
100 # link (both are ok for 1.5.x and 3.x versions), and should work
101 # for both source and DKMS builds.
102 #
103 AC_DEFUN([LN_CONFIG_O2IB], [
104 AC_MSG_CHECKING([whether to use Compat RDMA])
105 AC_ARG_WITH([o2ib],
106         AC_HELP_STRING([--with-o2ib=[yes|no|<path>]],
107                 [build o2iblnd against path]),
108         [], [with_o2ib="yes"])
109
110 case $with_o2ib in
111         yes)    AS_IF([which ofed_info 2>/dev/null], [
112                         AS_IF([test x$uses_dpkg = xyes], [
113                                 OFED_INFO="ofed_info | awk '{print \[$]2}'"
114                                 LSPKG="dpkg --listfiles"
115                         ], [
116                                 OFED_INFO="ofed_info"
117                                 LSPKG="rpm -ql"
118                         ])
119                         O2IBPATHS=$(eval $OFED_INFO | egrep -w 'mlnx-ofed-kernel-dkms|mlnx-ofa_kernel-devel|compat-rdma-devel|kernel-ib-devel|ofa_kernel-devel' | xargs $LSPKG | grep '\(/openib\|/ofa_kernel/default\|/ofa_kernel\)$' | head -n1)
120                         AS_IF([test -z "$O2IBPATHS"], [
121                                 AC_MSG_ERROR([
122 You seem to have an OFED installed but have not installed it's devel package.
123 If you still want to build Lustre for your OFED I/B stack, you need to install its devel headers RPM.
124 Instead, if you want to build Lustre for your kernel's built-in I/B stack rather than your installed OFED stack, either remove the OFED package(s) or use --with-o2ib=no.
125                                              ])
126                         ])
127                         AS_IF([test $(echo $O2IBPATHS | wc -w) -ge 2], [
128                                 AC_MSG_ERROR([
129 It appears that you have multiple OFED versions installed.
130 If you still want to build Lustre for your OFED I/B stack, you need to install a single version with its devel headers RPM.
131 Instead, if you want to build Lustre for your kernel's built-in I/B stack rather than your installed OFED stack, either remove the OFED package(s) or use --with-o2ib=no.
132                                              ])
133                         ])
134                         if test -e $O2IBPATHS/${LINUXRELEASE}; then
135                             O2IBPATHS=$O2IBPATHS/${LINUXRELEASE}
136                         elif test -e $O2IBPATHS/default; then
137                             O2IBPATHS=$O2IBPATHS/default
138                         fi
139                         OFED="yes"
140                 ], [
141                         O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
142                 ])
143                 ENABLEO2IB="yes"
144                 ;;
145         no)     ENABLEO2IB="no"
146                 ;;
147         *)      O2IBPATHS=$with_o2ib
148                 ENABLEO2IB="withpath"
149                 OFED="yes"
150                 ;;
151 esac
152
153 AS_IF([test $ENABLEO2IB = "no"], [
154         AC_MSG_RESULT([no])
155 ], [
156         o2ib_found=false
157         for O2IBPATH in $O2IBPATHS; do
158                 AS_IF([test \( -f ${O2IBPATH}/include/rdma/rdma_cm.h -a \
159                            -f ${O2IBPATH}/include/rdma/ib_cm.h -a \
160                            -f ${O2IBPATH}/include/rdma/ib_verbs.h -a \
161                            -f ${O2IBPATH}/include/rdma/ib_fmr_pool.h \)], [
162                         o2ib_found=true
163                         break
164                 ])
165         done
166         if ! $o2ib_found; then
167                 AC_MSG_RESULT([no])
168                 case $ENABLEO2IB in
169                         "yes") AC_MSG_ERROR([no OFED nor kernel OpenIB gen2 headers present]) ;;
170                         "withpath") AC_MSG_ERROR([bad --with-o2ib path]) ;;
171                         *) AC_MSG_ERROR([internal error]) ;;
172                 esac
173         else
174                 COMPAT_AUTOCONF=""
175                 compatrdma_found=false
176                 if test -f ${O2IBPATH}/include/linux/compat-2.6.h; then
177                         AC_MSG_RESULT([yes])
178                         compatrdma_found=true
179                         AC_DEFINE(HAVE_COMPAT_RDMA, 1, [compat rdma found])
180                         EXTRA_OFED_CONFIG="$EXTRA_OFED_CONFIG -include ${O2IBPATH}/include/linux/compat-2.6.h"
181                         if test -f "$O2IBPATH/include/linux/compat_autoconf.h"; then
182                                 COMPAT_AUTOCONF="$O2IBPATH/include/linux/compat_autoconf.h"
183                         fi
184                 else
185                         AC_MSG_RESULT([no])
186                 fi
187                 if ! $compatrdma_found; then
188                         if test -f "$O2IBPATH/config.mk"; then
189                                 . "$O2IBPATH/config.mk"
190                         elif test -f "$O2IBPATH/ofed_patch.mk"; then
191                                 . "$O2IBPATH/ofed_patch.mk"
192                         fi
193                 elif test -z "$COMPAT_AUTOCONF"; then
194                         # Depreciated checks
195                         if test "x$RHEL_KERNEL" = xyes; then
196                                 RHEL_MAJOR=$(awk '/ RHEL_MAJOR / { print [$]3 }' $LINUX_OBJ/include/$VERSION_HDIR/version.h)
197                                 I=$(awk '/ RHEL_MINOR / { print [$]3 }' $LINUX_OBJ/include/$VERSION_HDIR/version.h)
198                                 while test "$I" -ge 0; do
199                                         EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -DCONFIG_COMPAT_RHEL_${RHEL_MAJOR}_$I"
200                                         I=$(($I-1))
201                                 done
202                         elif test "x$SUSE_KERNEL" = xyes; then
203                                 SP=$(grep PATCHLEVEL /etc/SuSE-release | sed -e 's/.*= *//')
204                                 EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -DCONFIG_COMPAT_SLES_11_$SP"
205                         fi
206                 fi
207
208                 AC_MSG_CHECKING([whether to use any OFED backport headers])
209                 if test -n "$BACKPORT_INCLUDES"; then
210                         AC_MSG_RESULT([yes])
211                         OFED_BACKPORT_PATH="$O2IBPATH/${BACKPORT_INCLUDES/*\/kernel_addons/kernel_addons}/"
212                         EXTRA_OFED_INCLUDE="-I$OFED_BACKPORT_PATH $EXTRA_OFED_INCLUDE"
213                 else
214                         AC_MSG_RESULT([no])
215                 fi
216
217                 O2IBLND=""
218                 O2IBPATH=$(readlink --canonicalize $O2IBPATH)
219                 EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -I$O2IBPATH/include -I$O2IBPATH/include/uapi"
220                 EXTRA_CHECK_INCLUDE="$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE"
221                 LB_CHECK_COMPILE([whether to enable OpenIB gen2 support],
222                 openib_gen2_support, [
223                         #ifdef HAVE_COMPAT_RDMA
224                         #undef PACKAGE_NAME
225                         #undef PACKAGE_TARNAME
226                         #undef PACKAGE_VERSION
227                         #undef PACKAGE_STRING
228                         #undef PACKAGE_BUGREPORT
229                         #undef PACKAGE_URL
230                         #include <linux/compat-2.6.h>
231                         #endif
232                         #include <linux/version.h>
233                         #include <linux/pci.h>
234                         #include <linux/gfp.h>
235                         #include <rdma/rdma_cm.h>
236                         #include <rdma/ib_cm.h>
237                         #include <rdma/ib_verbs.h>
238                         #include <rdma/ib_fmr_pool.h>
239                 ],[
240                         struct rdma_cm_id      *cm_idi __attribute__ ((unused));
241                         struct rdma_conn_param  conn_param __attribute__ ((unused));
242                         struct ib_device_attr   device_attr __attribute__ ((unused));
243                         struct ib_qp_attr       qp_attr __attribute__ ((unused));
244                         struct ib_pool_fmr      pool_fmr __attribute__ ((unused));
245                         enum   ib_cm_rej_reason rej_reason __attribute__ ((unused));
246                         rdma_destroy_id(NULL);
247                 ],[
248                         O2IBLND="o2iblnd"
249                 ],[
250                         case $ENABLEO2IB in
251                         "yes") AC_MSG_ERROR([can't compile with OpenIB gen2 headers]) ;;
252                         "withpath") AC_MSG_ERROR([can't compile with OpenIB gen2 headers under $O2IBPATH]) ;;
253                         *) AC_MSG_ERROR([internal error]) ;;
254                         esac
255                 ])
256                 # we know at this point that the found OFED source is good
257                 O2IB_SYMVER=""
258                 if test $ENABLEO2IB = "withpath" -o "x$OFED" = "xyes" ; then
259                         if test -f $O2IBPATH/Module.symvers; then
260                                 O2IB_SYMVER=$O2IBPATH/Module.symvers;
261                                 break;
262                         fi
263                         if test -n "$O2IB_SYMVER"; then
264                                 AC_MSG_NOTICE([adding $O2IB_SYMVER to Symbol Path])
265                                 EXTRA_SYMBOLS="$EXTRA_SYMBOLS $O2IB_SYMVER"
266                                 AC_SUBST(EXTRA_SYMBOLS)
267                         else
268                                 AC_MSG_ERROR([an external source tree was, either specified or detected, for o2iblnd however I could not find a $O2IBPATH/Module.symvers there])
269                         fi
270                 fi
271
272                 LB_CHECK_COMPILE([if Linux kernel has kthread_worker],
273                 linux_kthread_worker, [
274                         #ifdef HAVE_COMPAT_RDMA
275                         #undef PACKAGE_NAME
276                         #undef PACKAGE_TARNAME
277                         #undef PACKAGE_VERSION
278                         #undef PACKAGE_STRING
279                         #undef PACKAGE_BUGREPORT
280                         #undef PACKAGE_URL
281                         #include <linux/compat-2.6.h>
282                         #endif
283                         #include <linux/kthread.h>
284                 ],[
285                         struct kthread_work *kth_wrk = NULL;
286                         flush_kthread_work(kth_wrk);
287                 ],[
288                         AC_DEFINE(HAVE_KTHREAD_WORK, 1, [kthread_worker found])
289                         if test -z "$COMPAT_AUTOCONF"; then
290                                 EXTRA_OFED_INCLUDE="$EXTRA_OFED_INCLUDE -DCONFIG_COMPAT_IS_KTHREAD"
291                         fi
292                 ])
293                 EXTRA_CHECK_INCLUDE=""
294         fi
295 ])
296 AC_SUBST(EXTRA_OFED_CONFIG)
297 AC_SUBST(EXTRA_OFED_INCLUDE)
298 AC_SUBST(O2IBLND)
299 AC_SUBST(O2IBPATH)
300 AC_SUBST(ENABLEO2IB)
301
302 AS_IF([test $ENABLEO2IB != "no"], [
303         EXTRA_CHECK_INCLUDE="$EXTRA_OFED_CONFIG $EXTRA_OFED_INCLUDE"
304
305         # In RHEL 6.2, rdma_create_id() takes the queue-pair type as a fourth argument
306         LB_CHECK_COMPILE([if 'rdma_create_id' wants four args],
307         rdma_create_id_4args, [
308                 #ifdef HAVE_COMPAT_RDMA
309                 #undef PACKAGE_NAME
310                 #undef PACKAGE_TARNAME
311                 #undef PACKAGE_VERSION
312                 #undef PACKAGE_STRING
313                 #undef PACKAGE_BUGREPORT
314                 #undef PACKAGE_URL
315                 #include <linux/compat-2.6.h>
316                 #endif
317                 #include <rdma/rdma_cm.h>
318         ],[
319                 rdma_create_id(NULL, NULL, 0, 0);
320         ],[
321                 AC_DEFINE(HAVE_RDMA_CREATE_ID_4ARG, 1,
322                         [rdma_create_id wants 4 args])
323         ])
324
325         # 4.4 added network namespace parameter for rdma_create_id()
326         LB_CHECK_COMPILE([if 'rdma_create_id' wants five args],
327         rdma_create_id_5args, [
328                 #ifdef HAVE_COMPAT_RDMA
329                 #undef PACKAGE_NAME
330                 #undef PACKAGE_TARNAME
331                 #undef PACKAGE_VERSION
332                 #undef PACKAGE_STRING
333                 #undef PACKAGE_BUGREPORT
334                 #undef PACKAGE_URL
335                 #include <linux/compat-2.6.h>
336                 #endif
337                 #include <rdma/rdma_cm.h>
338         ],[
339                 rdma_create_id(NULL, NULL, NULL, 0, 0);
340         ],[
341                 AC_DEFINE(HAVE_RDMA_CREATE_ID_5ARG, 1,
342                         [rdma_create_id wants 5 args])
343         ])
344
345         # 4.2 introduced struct ib_cq_init_attr which is used
346         # by ib_create_cq(). Note some OFED stacks only keep
347         # their headers in sync with latest kernels but not
348         # the functionality which means for infiniband testing
349         # we need to always test functionality testings.
350         LB_CHECK_COMPILE([if 'struct ib_cq_init_attr' is used],
351         ib_cq_init_attr, [
352                 #ifdef HAVE_COMPAT_RDMA
353                 #undef PACKAGE_NAME
354                 #undef PACKAGE_TARNAME
355                 #undef PACKAGE_VERSION
356                 #undef PACKAGE_STRING
357                 #undef PACKAGE_BUGREPORT
358                 #undef PACKAGE_URL
359                 #include <linux/compat-2.6.h>
360                 #endif
361                 #include <rdma/ib_verbs.h>
362         ],[
363                 struct ib_cq_init_attr cq_attr;
364
365                 ib_create_cq(NULL, NULL, NULL, NULL, &cq_attr);
366         ],[
367                 AC_DEFINE(HAVE_IB_CQ_INIT_ATTR, 1,
368                         [struct ib_cq_init_attr is used by ib_create_cq])
369         ])
370
371         # 4.3 removed ib_alloc_fast_reg_mr()
372         LB_CHECK_COMPILE([if 'ib_alloc_fast_reg_mr' exists],
373         ib_alloc_fast_reg_mr, [
374                 #ifdef HAVE_COMPAT_RDMA
375                 #undef PACKAGE_NAME
376                 #undef PACKAGE_TARNAME
377                 #undef PACKAGE_VERSION
378                 #undef PACKAGE_STRING
379                 #undef PACKAGE_BUGREPORT
380                 #undef PACKAGE_URL
381                 #include <linux/compat-2.6.h>
382                 #endif
383                 #include <rdma/ib_verbs.h>
384         ],[
385                 ib_alloc_fast_reg_mr(NULL, 0);
386         ],[
387                 AC_DEFINE(HAVE_IB_ALLOC_FAST_REG_MR, 1,
388                         [ib_alloc_fast_reg_mr is defined])
389         ])
390
391         # 4.9 must stop using ib_get_dma_mr and the global MR
392         # We then have to use FMR/Fastreg for all RDMA.
393         LB_CHECK_COMPILE([if 'ib_get_dma_mr' exists],
394         ib_get_dma_mr, [
395                 #ifdef HAVE_COMPAT_RDMA
396                 #undef PACKAGE_NAME
397                 #undef PACKAGE_TARNAME
398                 #undef PACKAGE_VERSION
399                 #undef PACKAGE_STRING
400                 #undef PACKAGE_BUGREPORT
401                 #undef PACKAGE_URL
402                 #include <linux/compat-2.6.h>
403                 #endif
404                 #include <rdma/ib_verbs.h>
405         ],[
406                 ib_get_dma_mr(NULL, 0);
407         ],[
408                 AC_DEFINE(HAVE_IB_GET_DMA_MR, 1,
409                         [ib_get_dma_mr is defined])
410         ])
411
412         # In v4.4 Linux kernel,
413         # commit e622f2f4ad2142d2a613a57fb85f8cf737935ef5
414         # split up struct ib_send_wr so that all non-trivial verbs
415         # use their own structure which embedds struct ib_send_wr.
416         LB_CHECK_COMPILE([if 'struct ib_rdma_wr' is defined],
417         ib_rdma_wr, [
418                 #ifdef HAVE_COMPAT_RDMA
419                 #undef PACKAGE_NAME
420                 #undef PACKAGE_TARNAME
421                 #undef PACKAGE_VERSION
422                 #undef PACKAGE_STRING
423                 #undef PACKAGE_BUGREPORT
424                 #undef PACKAGE_URL
425                 #include <linux/compat-2.6.h>
426                 #endif
427                 #include <rdma/ib_verbs.h>
428         ],[
429                 struct ib_rdma_wr *wr __attribute__ ((unused));
430
431                 wr = rdma_wr(NULL);
432         ],[
433                 AC_DEFINE(HAVE_IB_RDMA_WR, 1,
434                         [struct ib_rdma_wr is defined])
435         ])
436
437         # new fast registration API introduced in 4.4
438         LB_CHECK_COMPILE([if 4arg 'ib_map_mr_sg' exists],
439         ib_map_mr_sg_4args, [
440                 #ifdef HAVE_COMPAT_RDMA
441                 #undef PACKAGE_NAME
442                 #undef PACKAGE_TARNAME
443                 #undef PACKAGE_VERSION
444                 #undef PACKAGE_STRING
445                 #undef PACKAGE_BUGREPORT
446                 #undef PACKAGE_URL
447                 #include <linux/compat-2.6.h>
448                 #endif
449                 #include <rdma/ib_verbs.h>
450         ],[
451                 ib_map_mr_sg(NULL, NULL, 0, 0);
452         ],[
453                 AC_DEFINE(HAVE_IB_MAP_MR_SG, 1,
454                         [ib_map_mr_sg exists])
455         ])
456
457         # ib_map_mr_sg changes from 4 to 5 args (adding sg_offset_p)
458         # in kernel 4.7 (and RHEL 7.3)
459         LB_CHECK_COMPILE([if 5arg 'ib_map_mr_sg' exists],
460         ib_map_mr_sg_5args, [
461                 #ifdef HAVE_COMPAT_RDMA
462                 #undef PACKAGE_NAME
463                 #undef PACKAGE_TARNAME
464                 #undef PACKAGE_VERSION
465                 #undef PACKAGE_STRING
466                 #undef PACKAGE_BUGREPORT
467                 #undef PACKAGE_URL
468                 #include <linux/compat-2.6.h>
469                 #endif
470                 #include <rdma/ib_verbs.h>
471         ],[
472                 ib_map_mr_sg(NULL, NULL, 0, NULL, 0);
473         ],[
474                 AC_DEFINE(HAVE_IB_MAP_MR_SG, 1,
475                         [ib_map_mr_sg exists])
476                 AC_DEFINE(HAVE_IB_MAP_MR_SG_5ARGS, 1,
477                         [ib_map_mr_sg has 5 arguments])
478         ])
479
480         # ib_query_device() removed in 4.5
481         LB_CHECK_COMPILE([if 'struct ib_device' has member 'attrs'],
482         ib_device.attrs, [
483                 #ifdef HAVE_COMPAT_RDMA
484                 #undef PACKAGE_NAME
485                 #undef PACKAGE_TARNAME
486                 #undef PACKAGE_VERSION
487                 #undef PACKAGE_STRING
488                 #undef PACKAGE_BUGREPORT
489                 #undef PACKAGE_URL
490                 #include <linux/compat-2.6.h>
491                 #endif
492                 #include <rdma/ib_verbs.h>
493         ],[
494                 struct ib_device dev;
495                 struct ib_device_attr dev_attr = {};
496                 dev.attrs = dev_attr;
497         ],[
498                 AC_DEFINE(HAVE_IB_DEVICE_ATTRS, 1,
499                         [struct ib_device.attrs is defined])
500         ])
501
502         # A flags argument was added to ib_alloc_pd() in Linux 4.9,
503         # commit ed082d36a7b2c27d1cda55fdfb28af18040c4a89
504         LB_CHECK_COMPILE([if 2arg 'ib_alloc_pd' exists],
505         ib_alloc_pd, [
506                 #ifdef HAVE_COMPAT_RDMA
507                 #undef PACKAGE_NAME
508                 #undef PACKAGE_TARNAME
509                 #undef PACKAGE_VERSION
510                 #undef PACKAGE_STRING
511                 #undef PACKAGE_BUGREPORT
512                 #undef PACKAGE_URL
513                 #include <linux/compat-2.6.h>
514                 #endif
515                 #include <rdma/ib_verbs.h>
516         ],[
517                 ib_alloc_pd(NULL, 0);
518         ],[
519                 AC_DEFINE(HAVE_IB_ALLOC_PD_2ARGS, 1,
520                         [ib_alloc_pd has 2 arguments])
521         ])
522
523         LB_CHECK_COMPILE([if function 'ib_inc_rkey' is defined],
524         ib_inc_rkey, [
525                 #ifdef HAVE_COMPAT_RDMA
526                 #undef PACKAGE_NAME
527                 #undef PACKAGE_TARNAME
528                 #undef PACKAGE_VERSION
529                 #undef PACKAGE_STRING
530                 #undef PACKAGE_BUGREPORT
531                 #undef PACKAGE_URL
532                 #include <linux/compat-2.6.h>
533                 #endif
534                 #include <rdma/ib_verbs.h>
535         ],[
536                 (void)ib_inc_rkey(0);
537         ],[
538                 AC_DEFINE(HAVE_IB_INC_RKEY, 1,
539                           [function ib_inc_rkey exist])
540         ])
541
542         # In MOFED 4.6, the second and third parameters for
543         # ib_post_send() and ib_post_recv() are declared with
544         # 'const'.
545         tmp_flags="$EXTRA_KCFLAGS"
546         EXTRA_KCFLAGS="-Werror"
547         LB_CHECK_COMPILE([if 'ib_post_send() and ib_post_recv()' have const parameters],
548         ib_post_send_recv_const, [
549                 #ifdef HAVE_COMPAT_RDMA
550                 #undef PACKAGE_NAME
551                 #undef PACKAGE_TARNAME
552                 #undef PACKAGE_VERSION
553                 #undef PACKAGE_STRING
554                 #undef PACKAGE_BUGREPORT
555                 #undef PACKAGE_URL
556                 #include <linux/compat-2.6.h>
557                 #endif
558                 #include <rdma/ib_verbs.h>
559         ],[
560                 ib_post_send(NULL, (const struct ib_send_wr *)NULL,
561                              (const struct ib_send_wr **)NULL);
562         ],[
563                 AC_DEFINE(HAVE_IB_POST_SEND_RECV_CONST, 1,
564                         [ib_post_send and ib_post_recv have const parameters])
565         ])
566         EXTRA_KCFLAGS="$tmp_flags"
567
568         EXTRA_CHECK_INCLUDE=""
569 ]) # ENABLEO2IB != "no"
570 ]) # LN_CONFIG_O2IB
571
572 #
573 # LN_CONFIG_GNILND
574 #
575 # check whether to use the Gemini Network Interface lnd
576 #
577 AC_DEFUN([LN_CONFIG_GNILND], [
578 AC_MSG_CHECKING([whether to enable GNI lnd])
579 AC_ARG_ENABLE([gni],
580         AC_HELP_STRING([--enable-gni],
581                 [enable GNI lnd]),
582         [], [enable_gni="no"])
583 AC_MSG_RESULT([$enable_gni])
584
585 AS_IF([test "x$enable_gni" = xyes], [
586         # GNICPPFLAGS was set in spec file
587         EXTRA_KCFLAGS_save="$EXTRA_KCFLAGS"
588         EXTRA_KCFLAGS="$EXTRA_KCFLAGS $GNICPPFLAGS"
589         LB_CHECK_COMPILE([if GNI kernel headers are present],
590         GNI_header, [
591                 #include <linux/types.h>
592                 #include <gni_pub.h>
593         ],[
594                 gni_cdm_handle_t kgni_domain;
595                 gni_return_t     rc;
596                 int              rrc;
597                 rc = gni_cdm_create(0, 1, 1, 0, &kgni_domain);
598                 rrc = (rc == GNI_RC_SUCCESS) ? 0 : 1;
599                 return rrc;
600         ],[
601                 GNILND="gnilnd"
602         ],[
603                 AC_MSG_ERROR([can't compile gnilnd with given GNICPPFLAGS: $GNICPPFLAGS])
604         ])
605         # at this point, we have gnilnd basic support,
606         # now check for extra features
607         LB_CHECK_COMPILE([to use RCA in gnilnd],
608         RCA_gnilnd, [
609                 #include <linux/types.h>
610                 #include <gni_pub.h>
611                 #include <krca_lib.h>
612         ],[
613                 gni_cdm_handle_t kgni_domain;
614                 gni_return_t     rc;
615                 krca_ticket_t    ticket = KRCA_NULL_TICKET;
616                 int              rrc;
617                 __u32            nid = 0, nic_addr;
618                 rc = gni_cdm_create(0, 1, 1, 0, &kgni_domain);
619                 rrc = (rc == GNI_RC_SUCCESS) ? 0 : 1;
620                 rrc += krca_nid_to_nicaddrs(nid, 1, &nic_addr);
621                 rrc += krca_register(&ticket, RCA_MAKE_SERVICE_INDEX(RCA_IO_CLASS, 9), 99, 0);
622                 return rrc;
623         ],[
624                 GNICPPFLAGS="$GNICPPFLAGS -DGNILND_USE_RCA=1"
625         ])
626         EXTRA_KCFLAGS="$EXTRA_KCFLAGS_save"
627 ])
628 AC_SUBST(GNICPPFLAGS)
629 AC_SUBST(GNILND)
630 ]) # LN_CONFIG_GNILND
631
632 #
633 # LN_CONFIG_SK_SLEEP
634 #
635 # 2.6.35 kernel has sk_sleep function
636 #
637 AC_DEFUN([LN_CONFIG_SK_SLEEP], [
638 LB_CHECK_COMPILE([if Linux kernel has 'sk_sleep'],
639 sk_sleep, [
640         #include <net/sock.h>
641 ],[
642         sk_sleep(NULL);
643 ],[
644         AC_DEFINE(HAVE_SK_SLEEP, 1,
645                   [kernel has sk_sleep])
646 ])
647 ]) # LN_CONFIG_SK_SLEEP
648
649 #
650 # LN_CONFIG_TCP_SENDPAGE
651 #
652 # 2.6.36 tcp_sendpage() first parameter is 'struct sock'
653 # instead of 'struct socket'.
654 #
655 AC_DEFUN([LN_CONFIG_TCP_SENDPAGE], [
656 tmp_flags="$EXTRA_KCFLAGS"
657 EXTRA_KCFLAGS="-Werror"
658 LB_CHECK_COMPILE([if 'tcp_sendpage' first parameter is socket],
659 tcp_sendpage_socket, [
660         #include <linux/net.h>
661         #include <net/tcp.h>
662 ],[
663         tcp_sendpage((struct socket*)0, NULL, 0, 0, 0);
664 ],[
665         AC_DEFINE(HAVE_TCP_SENDPAGE_USE_SOCKET, 1,
666                 [tcp_sendpage use socket as first parameter])
667 ])
668 EXTRA_KCFLAGS="$tmp_flags"
669 ]) # LN_CONFIG_TCP_SENDPAGE
670
671 # LN_CONFIG_SOCK_CREATE_KERN
672 #
673 # 4.x sock_create_kern() added a first parameter as 'struct net *'
674 # instead of int.
675 #
676 AC_DEFUN([LN_CONFIG_SOCK_CREATE_KERN], [
677 tmp_flags="$EXTRA_KCFLAGS"
678 EXTRA_KCFLAGS="-Werror"
679 LB_CHECK_COMPILE([if 'sock_create_kern' first parameter is net],
680 sock_create_kern_net, [
681         #include <linux/net.h>
682         #include <net/net_namespace.h>
683 ],[
684         sock_create_kern((struct net*)0, 0, 0, 0, NULL);
685 ],[
686         AC_DEFINE(HAVE_SOCK_CREATE_KERN_USE_NET, 1,
687                 [sock_create_kern use net as first parameter])
688 ])
689 EXTRA_KCFLAGS="$tmp_flags"
690 ]) # LN_CONFIG_SOCK_CREATE_KERN
691
692 #
693 # LN_CONFIG_SK_DATA_READY
694 #
695 # 3.15 for struct sock the *sk_data_ready() field only takes one argument now
696 #
697 AC_DEFUN([LN_CONFIG_SK_DATA_READY], [
698 tmp_flags="$EXTRA_KCFLAGS"
699 EXTRA_KCFLAGS="-Werror"
700 LB_CHECK_COMPILE([if 'sk_data_ready' takes only one argument],
701 sk_data_ready, [
702         #include <linux/net.h>
703         #include <net/sock.h>
704 ],[
705         ((struct sock *)0)->sk_data_ready(NULL);
706 ],[
707         AC_DEFINE(HAVE_SK_DATA_READY_ONE_ARG, 1,
708                 [sk_data_ready uses only one argument])
709 ])
710 EXTRA_KCFLAGS="$tmp_flags"
711 ]) # LN_CONFIG_SK_DATA_READY
712
713 #
714 # LN_EXPORT_KMAP_TO_PAGE
715 #
716 # 3.10 Export kmap_to_page
717 #
718 AC_DEFUN([LN_EXPORT_KMAP_TO_PAGE], [
719 LB_CHECK_EXPORT([kmap_to_page], [mm/highmem.c],
720         [AC_DEFINE(HAVE_KMAP_TO_PAGE, 1,
721                 [kmap_to_page is exported by the kernel])])
722 ]) # LN_EXPORT_KMAP_TO_PAG
723
724 #
725 # LN_CONFIG_SOCK_ACCEPT
726 #
727 # 4.11 commit cdfbabfb2f0ce983fdaa42f20e5f7842178fc01e added a flag
728 # to handle a possible lockdep condition kernel socket accept.
729 #
730 AC_DEFUN([LN_CONFIG_SOCK_ACCEPT], [
731 tmp_flags="$EXTRA_KCFLAGS"
732 EXTRA_KCFLAGS="-Werror"
733 LB_CHECK_COMPILE([if 'struct sock' accept function requires a bool argument],
734 kern_sock_flag, [
735         #include <linux/net.h>
736 ],[
737         ((struct socket *)0)->ops->accept(NULL, NULL, O_NONBLOCK, false);
738 ],[
739         AC_DEFINE(HAVE_KERN_SOCK_ACCEPT_FLAG_ARG, 1,
740                 ['struct sock' accept function requires bool argument])
741 ])
742 EXTRA_KCFLAGS="$tmp_flags"
743 ]) # LN_CONFIG_SOCK_ACCEPT
744
745 #
746 # LN_HAVE_ORACLE_OFED_EXTENSIONS
747 #
748 # Oracle UEK 5
749 #
750 AC_DEFUN([LN_HAVE_ORACLE_OFED_EXTENSIONS], [
751 LB_CHECK_COMPILE([if Oracle OFED Extensions are enabled],
752 oracle_ofed_ext, [
753         #include <rdma/ib_fmr_pool.h>
754 ],[
755         struct ib_fmr_pool_param param = {
756                 .relaxed           = 0
757         };
758         (void)param;
759 ],[
760         AC_DEFINE(HAVE_ORACLE_OFED_EXTENSIONS, 1,
761                 [if Oracle OFED Extensions are enabled])
762 ])
763 ]) # LN_HAVE_ORACLE_OFED_EXTENSIONS
764
765 #
766 # LN_CONFIG_SOCK_GETNAME
767 #
768 # 4.17 commit 9b2c45d479d0fb8647c9e83359df69162b5fbe5f getname()
769 # does not take the length *int argument and returns the length
770 #
771 AC_DEFUN([LN_CONFIG_SOCK_GETNAME], [
772 tmp_flags="$EXTRA_KCFLAGS"
773 EXTRA_KCFLAGS="-Werror"
774 LB_CHECK_COMPILE([if 'getname' has two args],
775 kern_sock_getname_2args, [
776         #include <linux/net.h>
777 ],[
778         kernel_getsockname(NULL, NULL);
779 ],[
780         AC_DEFINE(HAVE_KERN_SOCK_GETNAME_2ARGS, 1,
781                 ['getname' has two args])
782 ])
783 EXTRA_KCFLAGS="$tmp_flags"
784 ]) # LN_CONFIG_SOCK_GETNAME
785
786 #
787 # LN_IB_DEVICE_OPS_EXISTS
788 #
789 # kernel 5.0 commit 521ed0d92ab0db3edd17a5f4716b7f698f4fce61
790 # RDMA/core: Introduce ib_device_ops
791 # ... introduces the ib_device_ops structure that defines all the
792 # InfiniBand device operations in one place ...
793 #
794 AC_DEFUN([LN_IB_DEVICE_OPS_EXISTS], [
795 tmp_flags="$EXTRA_KCFLAGS"
796 EXTRA_KCFLAGS="-Werror"
797 LB_CHECK_COMPILE([if struct ib_device_ops is defined],
798 ib_device_ops_test, [
799         #include <rdma/ib_verbs.h>
800 ],[
801         int x = offsetof(struct ib_device_ops, unmap_fmr);
802         x = x;
803         (void)x;
804 ],[
805         AC_DEFINE(HAVE_IB_DEVICE_OPS, 1,
806                 [if struct ib_device_ops is defined])
807 ])
808 EXTRA_KCFLAGS="$tmp_flags"
809 ]) # LN_IB_DEVICE_OPS_EXISTS
810
811 #
812 # LN_IB_SG_DMA_ADDRESS_EXISTS
813 #
814 # kernel 5.1 commit a163afc88556e099271a7b423295bc5176fcecce
815 # IB/core: Remove ib_sg_dma_address() and ib_sg_dma_len()
816 # ... when dma_ops existed (3.6) ib_sg_dma_address() was not trivial ...
817 #
818 AC_DEFUN([LN_IB_SG_DMA_ADDRESS_EXISTS], [
819 tmp_flags="$EXTRA_KCFLAGS"
820 EXTRA_KCFLAGS="-Werror"
821 LB_CHECK_COMPILE([if ib_sg_dma_address wrapper exists],
822 ib_sg_dma_address_test, [
823         #include <rdma/ib_verbs.h>
824 ],[
825         u64 x = ib_sg_dma_address(NULL, NULL);
826         x = x;
827         (void)x;
828 ],[
829         AC_DEFINE(HAVE_IB_SG_DMA_ADDRESS, 1,
830                 [if ib_sg_dma_address wrapper exists])
831 ])
832 EXTRA_KCFLAGS="$tmp_flags"
833 ]) # LN_IB_SG_DMA_ADDRESS_EXISTS
834
835 #
836 # LN_PROG_LINUX
837 #
838 # LNet linux kernel checks
839 #
840 AC_DEFUN([LN_PROG_LINUX], [
841 AC_MSG_NOTICE([LNet kernel checks
842 ==============================================================================])
843
844 LN_CONFIG_AFFINITY
845 LN_CONFIG_BACKOFF
846 LN_CONFIG_O2IB
847 LN_CONFIG_GNILND
848 # 2.6.35
849 LN_CONFIG_SK_SLEEP
850 # 2.6.36
851 LN_CONFIG_TCP_SENDPAGE
852 # 3.10
853 LN_EXPORT_KMAP_TO_PAGE
854 # 3.15
855 LN_CONFIG_SK_DATA_READY
856 # 4.x
857 LN_CONFIG_SOCK_CREATE_KERN
858 # 4.11
859 LN_CONFIG_SOCK_ACCEPT
860 # 4.14
861 LN_HAVE_ORACLE_OFED_EXTENSIONS
862 # 4.17
863 LN_CONFIG_SOCK_GETNAME
864 # 5.0
865 LN_IB_DEVICE_OPS_EXISTS
866 # 5.1
867 LN_IB_SG_DMA_ADDRESS_EXISTS
868 ]) # LN_PROG_LINUX
869
870 #
871 # LN_PATH_DEFAULTS
872 #
873 # default paths for installed files
874 #
875 AC_DEFUN([LN_PATH_DEFAULTS], [
876 ]) # LN_PATH_DEFAULTS
877
878 #
879 # LN_CONFIGURE
880 #
881 # other configure checks
882 #
883 AC_DEFUN([LN_CONFIGURE], [
884 AC_MSG_NOTICE([LNet core checks
885 ==============================================================================])
886
887 # lnet/utils/portals.c
888 AC_CHECK_HEADERS([netdb.h])
889 AC_CHECK_FUNCS([gethostbyname])
890
891 # lnet/utils/wirecheck.c
892 AC_CHECK_FUNCS([strnlen])
893
894 # --------  Check for required packages  --------------
895
896 AC_MSG_CHECKING([whether to enable 'efence' debugging support])
897 AC_ARG_ENABLE(efence,
898         AC_HELP_STRING([--enable-efence],
899                 [use efence library]),
900         [], [enable_efence="no"])
901 AC_MSG_RESULT([$enable_efence])
902
903 LIBEFENCE=""
904 AS_IF([test "$enable_efence" = yes], [
905         LIBEFENCE="-lefence"
906         AC_DEFINE(HAVE_LIBEFENCE, 1,
907                 [libefence support is requested])
908 ])
909 AC_SUBST(LIBEFENCE)
910
911 LN_CONFIG_DLC
912 ]) # LN_CONFIGURE
913
914 #
915 # LN_CONDITIONALS
916 #
917 # AM_CONDITIONAL defines for lnet
918 #
919 AC_DEFUN([LN_CONDITIONALS], [
920 AM_CONDITIONAL(BUILD_O2IBLND,    test x$O2IBLND = "xo2iblnd")
921 AM_CONDITIONAL(BUILD_GNILND,     test x$GNILND  = "xgnilnd")
922 ]) # LN_CONDITIONALS
923
924 #
925 # LN_CONFIG_FILES
926 #
927 # files that should be generated with AC_OUTPUT
928 #
929 AC_DEFUN([LN_CONFIG_FILES], [
930 AC_CONFIG_FILES([
931 lnet/Makefile
932 lnet/autoMakefile
933 lnet/autoconf/Makefile
934 lnet/doc/Makefile
935 lnet/include/Makefile
936 lnet/include/lnet/Makefile
937 lnet/include/uapi/linux/lnet/Makefile
938 lnet/klnds/Makefile
939 lnet/klnds/autoMakefile
940 lnet/klnds/o2iblnd/Makefile
941 lnet/klnds/o2iblnd/autoMakefile
942 lnet/klnds/gnilnd/Makefile
943 lnet/klnds/gnilnd/autoMakefile
944 lnet/klnds/socklnd/Makefile
945 lnet/klnds/socklnd/autoMakefile
946 lnet/lnet/Makefile
947 lnet/lnet/autoMakefile
948 lnet/selftest/Makefile
949 lnet/selftest/autoMakefile
950 lnet/utils/Makefile
951 lnet/utils/lnetconfig/Makefile
952 ])
953 ]) # LN_CONFIG_FILES