Whamcloud - gitweb
LU-17743 o2iblnd: fix privileged port check in passive_connect
[fs/lustre-release.git] / config / lustre-build-ldiskfs.m4
1 # SPDX-License-Identifier: GPL-2.0
2
3 #
4 # This file is part of Lustre, http://www.lustre.org/
5 #
6 # config/lustre-build-ldiskfs.m4
7 #
8 # ldiskfs OSD related configuration
9 #
10
11 #
12 # LDISKFS_LINUX_SERIES
13 #
14 AC_DEFUN([LDISKFS_LINUX_SERIES], [
15 AC_MSG_CHECKING([which ldiskfs series to use])
16 case x$LDISKFS_SERIES in
17         x)                      # not set
18                 ;;
19         *.series)               # set externally
20                 ;;
21         *) LDISKFS_SERIES=
22 esac
23 AS_IF([test -z "$LDISKFS_SERIES"], [
24 AS_IF([test x$RHEL_KERNEL = xyes], [
25         case $RHEL_RELEASE_NO in
26         93)     LDISKFS_SERIES="5.14-rhel9.3.series"    ;;
27         92)     LDISKFS_SERIES="5.14-rhel9.2.series"    ;;
28         91)     LDISKFS_SERIES="5.14-rhel9.1.series"    ;;
29         90)     LDISKFS_SERIES="5.14-rhel9.series"      ;;
30         89)     LDISKFS_SERIES="4.18-rhel8.9.series"    ;;
31         88)     LDISKFS_SERIES="4.18-rhel8.8.series"    ;;
32         87)     LDISKFS_SERIES="4.18-rhel8.7.series"    ;;
33         86)     LDISKFS_SERIES="4.18-rhel8.6.series"    ;;
34         85)     LDISKFS_SERIES="4.18-rhel8.5.series"    ;;
35         84)     LDISKFS_SERIES="4.18-rhel8.4.series"    ;;
36         79)     LDISKFS_SERIES="3.10-rhel7.9.series"    ;;
37         esac
38 ], [test x$SUSE_KERNEL = xyes], [
39         AS_VERSION_COMPARE([$LINUXRELEASE],[5.3.18],[
40         AS_VERSION_COMPARE([$LINUXRELEASE],[4.12.14],[], [], [
41                 suse_conf=$LINUX_OBJ/include/generated/uapi/linux/suse_version.h
42                 suse_vers=$(awk '[$]2 == "SUSE_VERSION" {print [$]3 }' $suse_conf)
43                 suse_patchlevel=$(awk '[$]2 == "SUSE_PATCHLEVEL" {print [$]3 }' $suse_conf)
44                 case ${suse_vers}sp$suse_patchlevel in # (
45                 15sp0 ) LDISKFS_SERIES="4.12-sles15.series"
46                         if test ! -f $LINUX/arch/x86/kernel/cpu/hygon.c ; then
47                                 # This file was added shortly after -150.22 so
48                                 # this must be 150.22 or earlier
49                                 LDISKFS_SERIES="4.12-sles15-22.series"
50                         fi
51                         ;; # (
52                 15sp1 ) LDISKFS_SERIES="4.12-sles15sp1.series"
53                         if test ! -f $LINUX/arch/x86/kernel/cpu/umwait.c ; then
54                                 # This file was added after -197.7 so
55                                 # this must be -197.7 or earlier
56                                 LDISKFS_SERIES="4.12-sles15sp1-7.series"
57                         fi
58                         ;;
59                 esac
60         ]
61         )], [LDISKFS_SERIES="5.4.21-ml.series"],
62             [
63                 suse_conf=$LINUX_OBJ/include/generated/uapi/linux/suse_version.h
64                 suse_vers=$(awk '[$]2 == "SUSE_VERSION" {print [$]3 }' $suse_conf)
65                 suse_patchlevel=$(awk '[$]2 == "SUSE_PATCHLEVEL" {print [$]3 }' $suse_conf)
66                 case ${suse_vers}sp${suse_patchlevel} in # (
67                 15sp2 ) LDISKFS_SERIES="5.4.21-ml.series"
68                         grep -A3 ext4_update_dx_flag $LINUX/fs/ext4/ext4.h \
69                           | grep ext4_test_inode_flag
70                         if test $? -eq 0; then
71                                 LDISKFS_SERIES="5.4.0-66-ubuntu20.series"
72                         fi
73                         ;; # (
74                 15sp3 ) LDISKFS_SERIES="5.3.18-sles15sp3.series"
75                         update=$(echo $LINUXRELEASE | cut -d- -f2 | cut -d. -f2)
76                         if test $update -ge 59; then
77                                 LDISKFS_SERIES="5.3.18-sles15sp3-59.series"
78                         fi
79                         ;;
80                 15sp4 ) LDISKFS_SERIES="5.14.21-sles15sp4.series"
81                         ;;
82                 15sp5 ) LDISKFS_SERIES="5.14.21-sles15sp5.series"
83                         ;;
84                 esac
85             ])
86 ], [test x$UBUNTU_KERNEL = xyes], [
87         BASEVER=$(echo $LINUXRELEASE | cut -d'-' -f1)
88         AS_VERSION_COMPARE([$BASEVER],[5.19.0],[
89         AS_VERSION_COMPARE([$BASEVER],[5.15.0],[
90         AS_VERSION_COMPARE([$BASEVER],[5.11.0],[
91         AS_VERSION_COMPARE([$BASEVER],[5.8.0],[
92         AS_VERSION_COMPARE([$BASEVER],[5.4.0],[
93         AS_VERSION_COMPARE([$BASEVER],[5.0.0],[
94         AS_VERSION_COMPARE([$BASEVER],[4.15.0],[
95         AS_VERSION_COMPARE([$BASEVER],[4.4.0], [],
96         [
97                 KPLEV=$(echo $LINUXRELEASE | cut -d'-' -f2)
98                 AS_IF(
99                         [test -z "$KPLEV"], [
100                                 AC_MSG_WARN([Failed to determine Kernel patch level. Assume latest.])
101                                 LDISKFS_SERIES="4.4.0-73-ubuntu14+16.series"
102                         ],
103                         [test $KPLEV -ge 73], [LDISKFS_SERIES="4.4.0-73-ubuntu14+16.series"],
104                         [test $KPLEV -ge 62], [LDISKFS_SERIES="4.4.0-62-ubuntu14+16.series"],
105                         [test $KPLEV -ge 49], [LDISKFS_SERIES="4.4.0-49-ubuntu14+16.series"],
106                         [LDISKFS_SERIES="4.4.0-45-ubuntu14+16.series"]
107                 )
108         ],
109         [LDISKFS_SERIES="4.4.0-73-ubuntu14+16.series"])],
110         [
111                 KPLEV=$(echo $LINUXRELEASE | cut -d'-' -f2)
112                 AS_IF(
113                         [test -z "$KPLEV"], [
114                                 AC_MSG_WARN([Failed to determine Kernel patch level. Assume latest.])
115                                 LDISKFS_SERIES="4.15.0-24-ubuntu18.series"
116                         ],
117                         [test $KPLEV -ge 24], [LDISKFS_SERIES="4.15.0-24-ubuntu18.series"],
118                         [test $KPLEV -ge 20], [LDISKFS_SERIES="4.15.0-20-ubuntu18.series"]
119                 )
120         ],
121         [LDISKFS_SERIES="4.15.0-24-ubuntu18.series"])],
122         [LDISKFS_SERIES="5.0.0-13-ubuntu19.series"],
123         [LDISKFS_SERIES="5.0.0-13-ubuntu19.series"])],
124         [
125                 KPLEV=$(echo $LINUXRELEASE | cut -d'-' -f2)
126                 AS_IF(
127                         [test -z "$KPLEV"], [
128                                 AC_MSG_WARN([Failed to determine Kernel patch level. Assume latest.])
129                                 LDISKFS_SERIES="5.4.0-90-ubuntu20.series"
130                         ],
131                         [test $KPLEV -eq 1007], [LDISKFS_SERIES="5.4.0-42-ubuntu20.series"],
132                         [test $KPLEV -ge 90], [LDISKFS_SERIES="5.4.0-90-ubuntu20.series"],
133                         [test $KPLEV -ge 80], [LDISKFS_SERIES="5.4.0-80-ubuntu20.series"],
134                         [test $KPLEV -ge 66], [LDISKFS_SERIES="5.4.0-66-ubuntu20.series"],
135                         [LDISKFS_SERIES="5.4.0-42-ubuntu20.series"]
136                 )
137         ],
138         [LDISKFS_SERIES="5.4.0-ml.series"])],
139         [
140                 KPLEV=$(echo $LINUXRELEASE | cut -d'-' -f2)
141                 AS_IF(
142                         [test -z "$KPLEV"], [
143                                 AC_MSG_WARN([Failed to determine Kernel patch level. Assume latest.])
144                                 LDISKFS_SERIES="5.8.0-63-ubuntu20.series"
145                         ],
146                         [test $KPLEV -ge 63], [LDISKFS_SERIES="5.8.0-63-ubuntu20.series"],
147                         [LDISKFS_SERIES="5.8.0-53-ubuntu20.series"]
148                 )
149         ],
150         [LDISKFS_SERIES="5.8.0-ml.series"])],
151         [LDISKFS_SERIES="5.11.0-40-ubuntu20.series"],
152         [LDISKFS_SERIES="5.11.0-40-ubuntu20.series"])],
153         [
154                 PLEV=$(echo $LINUXRELEASE | cut -d'-' -f2)
155                 AS_IF(
156                         [test -z "$KPLEV"], [
157                                 AC_MSG_WARN([Failed to determine Kernel patch level. Assume latest.])
158                                 LDISKFS_SERIES="5.15.0-106-ubuntu20.series"
159                         ],
160                         [test $KPLEV -ge 106], [LDISKFS_SERIES="5.15.0-106-ubuntu20.series"],
161                         [LDISKFS_SERIES="5.15.0-83-ubuntu20.series"]
162                 )
163         ],
164         [LDISKFS_SERIES="5.15.0-83-ubuntu20.series"])],
165         [LDISKFS_SERIES="5.19.0-35-ubuntu.series"],
166         [LDISKFS_SERIES="5.19.0-35-ubuntu.series"])
167 ], [test x$OPENEULER_KERNEL = xyes], [
168         case $OPENEULER_VERSION_NO in
169         2203.0) LDISKFS_SERIES="5.10.0-oe2203.series" ;;
170         2203.*) LDISKFS_SERIES="5.10.0-oe2203sp1.series" ;;
171         esac
172 ])
173 ])
174 # Not RHEL/SLES/openEuler or Ubuntu .. probably mainline
175 AS_IF([test -z "$LDISKFS_SERIES"],
176         [
177         AS_VERSION_COMPARE([$LINUXRELEASE],[5.4.0],[
178                 ], [
179                 LDISKFS_SERIES="5.4.0-ml.series"],[
180         AS_VERSION_COMPARE([$LINUXRELEASE],[5.4.21],[
181                 LDISKFS_SERIES="5.4.0-ml.series"], [
182                 LDISKFS_SERIES="5.4.21-ml.series"],[
183         AS_VERSION_COMPARE([$LINUXRELEASE],[5.10.0], [
184                 LDISKFS_SERIES="5.4.136-ml.series"], [
185                 LDISKFS_SERIES="5.10.0-ml.series"], [
186         AS_VERSION_COMPARE([$LINUXRELEASE],[6.1.0], [
187                 LDISKFS_SERIES="5.10.0-ml.series"], [
188                 LDISKFS_SERIES="6.1.38-ml.series"], [
189                 LDISKFS_SERIES="6.1.38-ml.series"]
190         )] # 6.1 LTS
191         )] # 5.10 LTS
192         )] # 5.4 LTS
193         )],
194 [])
195 AS_IF([test -z "$LDISKFS_SERIES"],
196         [AC_MSG_RESULT([failed to identify series])],
197         [AC_MSG_RESULT([$LDISKFS_SERIES for $LINUXRELEASE])])
198 AC_SUBST(LDISKFS_SERIES)
199 ]) # LDISKFS_LINUX_SERIES
200
201 #
202 # LB_EXT4_BREAD_4ARGS
203 #
204 # 3.18 ext4_bread has 4 arguments
205 # NOTE: It may not be exported for modules, use a positive compiler test here.
206 #
207 AC_DEFUN([LB_SRC_EXT4_BREAD_4ARGS], [
208         LB2_LINUX_TEST_SRC([ext4_bread], [
209                 #include <linux/fs.h>
210                 #include "$EXT4_SRC_DIR/ext4.h"
211
212                 struct buffer_head *ext4_bread(handle_t *handle,
213                                                struct inode *inode,
214                                                ext4_lblk_t block, int map_flags)
215                 {
216                         struct buffer_head *bh = NULL;
217                         (void)handle;
218                         (void)inode;
219                         (void)block;
220                         (void)map_flags;
221                         return bh;
222                 }
223         ],[
224                 ext4_bread(NULL, NULL, 0, 0);
225         ],[],[],[ext4_bread])
226 ])
227 AC_DEFUN([LB_EXT4_BREAD_4ARGS], [
228         LB2_MSG_LINUX_TEST_RESULT([if ext4_bread takes 4 arguments],
229         [ext4_bread], [
230                 AC_DEFINE(HAVE_EXT4_BREAD_4ARGS, 1,
231                         [ext4_bread takes 4 arguments])
232         ])
233 ]) # LB_EXT4_BREAD_4ARGS
234
235 #
236 # LB_EXT4_HAVE_INFO_DQUOT
237 #
238 # in linux 4.4 i_dqout is in ext4_inode_info, not in struct inode
239 #
240 AC_DEFUN([LB_SRC_EXT4_HAVE_INFO_DQUOT], [
241         LB2_LINUX_TEST_SRC([ext4_info_dquot], [
242                 #include <linux/fs.h>
243                 #include <linux/quota.h>
244                 #include "$EXT4_SRC_DIR/ext4.h"
245         ],[
246                 struct ext4_inode_info in;
247                 struct dquot *dq;
248
249                 dq = in.i_dquot[0];
250         ])
251 ])
252 AC_DEFUN([LB_EXT4_HAVE_INFO_DQUOT], [
253         LB2_MSG_LINUX_TEST_RESULT([if i_dquot is in ext4_inode_info],
254         [ext4_info_dquot], [
255                 AC_DEFINE(HAVE_EXT4_INFO_DQUOT, 1,
256                         [i_dquot is in ext4_inode_info])
257         ])
258 ]) # LB_EXT4_HAVE_INFO_DQUOT
259
260 #
261 # LB_EXT4_HAVE_I_CRYPT_INFO
262 #
263 # in linux 4.8 i_crypt_info moved from ext4_inode_info to struct inode
264 #
265 # Determine if we need to enable CONFIG_LDISKFS_FS_ENCRYPTION.
266 # If we have i_crypt_info in ext4_inode_info, the config option
267 # should be enabled to make the ldiskfs module compilation happy.
268 # Otherwise i_crypy_info is in struct inode, we need to check kernel
269 # config option to determine that.
270 #
271 AC_DEFUN([LB_SRC_EXT4_HAVE_I_CRYPT_INFO], [
272         LB2_SRC_CHECK_CONFIG([EXT4_FS_ENCRYPTION])
273         LB2_LINUX_TEST_SRC([ext4_i_crypt_info], [
274                 #define CONFIG_EXT4_FS_ENCRYPTION 1
275                 #include <linux/fs.h>
276                 #include "$EXT4_SRC_DIR/ext4.h"
277         ],[
278                 struct ext4_inode_info in;
279
280                 in.i_crypt_info = NULL;
281         ])
282 ])
283 AC_DEFUN([LB_EXT4_HAVE_I_CRYPT_INFO], [
284         LB2_MSG_LINUX_TEST_RESULT([if i_crypt_info is in ext4_inode_info],
285         [ext4_i_crypt_info], [
286                 AC_DEFINE(CONFIG_LDISKFS_FS_ENCRYPTION, 1,
287                         [enable encryption for ldiskfs])
288                 test_have_i_crypt_info=yes
289         ],[
290                 test_have_i_crypt_info=no
291         ])
292         AS_IF([test x$test_have_i_crypt_info = xno], [
293                 LB2_TEST_CHECK_CONFIG([EXT4_FS_ENCRYPTION],[
294                         AC_DEFINE(CONFIG_LDISKFS_FS_ENCRYPTION, 1,
295                                 [enable encryption for ldiskfs])
296                 ])
297         ])
298 ]) # LB_EXT4_HAVE_I_CRYPT_INFO
299
300 #
301 # LB_LDISKFS_JOURNAL_ENSURE_CREDITS
302 #
303 # kernel 4.18.0-240.1.1.el8 and
304 # kernel 5.4 commit a413036791d040e33badcc634453a4d0c0705499
305 #
306 # ext4_journal_ensure_credits was introduced to ensure given handle
307 # has at least requested amount of credits available, and possibly
308 # restarting transaction if needed.
309 #
310 AC_DEFUN([LB_SRC_LDISKFS_JOURNAL_ENSURE_CREDITS], [
311         LB2_LINUX_TEST_SRC([ext4_journal_ensure_credits], [
312                 #include "$EXT4_SRC_DIR/ext4_jbd2.h"
313                 int __ext4_journal_ensure_credits(handle_t *handle, int check_cred,
314                         int extend_cred, int revoke_cred) { return 0; }
315         ],[
316                 ext4_journal_ensure_credits(NULL, 0, 0);
317         ],[-Werror],[],[__ext4_journal_ensure_credits])
318 ])
319 AC_DEFUN([LB_LDISKFS_JOURNAL_ENSURE_CREDITS], [
320         LB2_MSG_LINUX_TEST_RESULT([if 'ext4_journal_ensure_credits' exists],
321         [ext4_journal_ensure_credits], [
322                 AC_DEFINE(HAVE_LDISKFS_JOURNAL_ENSURE_CREDITS, 1,
323                         ['ext4_journal_ensure_credits' exists])
324         ])
325 ]) # LB_LDISKFS_JOURNAL_ENSURE_CREDITS
326
327 #
328 # LB_LDISKFS_IGET_HAS_FLAGS_ARG
329 #
330 # kernel 4.19 commit 8a363970d1dc38c4ec4ad575c862f776f468d057
331 # ext4_iget changed to a macro with 3 args was function with 2 args
332 #
333 AC_DEFUN([LB_SRC_LDISKFS_IGET_HAS_FLAGS_ARG], [
334         LB2_LINUX_TEST_SRC([ext4_iget_3args], [
335                 #include <linux/fs.h>
336                 #include "$EXT4_SRC_DIR/ext4.h"
337         ],[
338                 int f = EXT4_IGET_SPECIAL;
339                 (void)f;
340         ],[-Werror])
341 ])
342 AC_DEFUN([LB_LDISKFS_IGET_HAS_FLAGS_ARG], [
343         LB2_MSG_LINUX_TEST_RESULT([if ldiskfs_iget takes a flags argument],
344         [ext4_iget_3args], [
345                 AC_DEFINE(HAVE_LDISKFS_IGET_WITH_FLAGS, 1,
346                         [if ldiskfs_iget takes a flags argument])
347         ])
348 ]) # LB_LDISKFS_IGET_HAS_FLAGS_ARG
349
350 #
351 # LDISKFS_AC_PATCH_PROGRAM
352 #
353 # Determine which program should be used to apply the patches to
354 # the ext4 source code to produce the ldiskfs source code.
355 #
356 AC_DEFUN([LDISKFS_AC_PATCH_PROGRAM], [
357         AC_ARG_ENABLE([quilt],
358                 [AS_HELP_STRING([--disable-quilt],
359                         [disable use of quilt for ldiskfs])],
360                 [AS_IF([test "x$enableval" = xno],
361                         [use_quilt=no],
362                         [use_quilt=maybe])],
363                 [use_quilt=maybe]
364         )
365
366         AS_IF([test x$use_quilt = xmaybe], [
367                 AC_PATH_PROG([quilt_avail], [quilt], [no])
368                 AS_IF([test x$quilt_avail = xno], [
369                         use_quilt=no
370                 ], [
371                         use_quilt=yes
372                 ])
373         ])
374
375         AS_IF([test x$use_quilt = xno], [
376                 AC_PATH_PROG([patch_avail], [patch], [no])
377                 AS_IF([test x$patch_avail = xno], [
378                         AC_MSG_ERROR([*** Need "quilt" or "patch" command])
379                 ])
380         ])
381 ]) # LDISKFS_AC_PATCH_PROGRAM
382
383 #
384 # LB_LDISKFS_FIND_ENTRY_LOCKED_EXISTS
385 #
386 # kernel 5.2 commit 8a363970d1dc38c4ec4ad575c862f776f468d057
387 # ext4: avoid declaring fs inconsistent due to invalid file handles
388 # __ext4_find_entry became a helper function for ext4_find_entry
389 # conflicting with previous ldiskfs patches.
390 # ldiskfs patches map ext4_find_entry to ldiskfs_find_entry_locked to
391 # avoid conflicting with __ext4_find_entry
392 #
393 # When the following check succeeds __ext4_find_entry helper is not
394 # used.
395 #
396 AC_DEFUN([LB_SRC_LDISKFS_FIND_ENTRY_LOCKED_EXISTS], [
397         LB2_LINUX_TEST_SRC([ldiskfs_find_entry_locked], [
398                 #include <linux/fs.h>
399                 #include "$EXT4_SRC_DIR/ext4.h"
400                 #include "$EXT4_SRC_DIR/namei.c"
401
402                 static int __ext4_find_entry(void) { return 0; }
403         ],[
404                 int x = __ext4_find_entry();
405                 (void)x;
406         ],[-Werror])
407 ])
408 AC_DEFUN([LB_LDISKFS_FIND_ENTRY_LOCKED_EXISTS], [
409         LB2_MSG_LINUX_TEST_RESULT([if __ldiskfs_find_entry is available],
410         [ldiskfs_find_entry_locked], [
411                 AC_DEFINE(HAVE___LDISKFS_FIND_ENTRY, 1,
412                         [if __ldiskfs_find_entry is available])
413         ])
414 ]) # LB_LDISKFS_FIND_ENTRY_LOCKED_EXISTS
415
416 #
417 # LB_LDISKFSFS_DIRHASH_WANTS_DIR
418 #
419 # kernel 5.2 commit 8a363970d1dc38c4ec4ad575c862f776f468d057
420 # ext4fs_dirhash UNICODE support
421 #
422 AC_DEFUN([LB_SRC_LDISKFSFS_DIRHASH_WANTS_DIR], [
423         LB2_LINUX_TEST_SRC([ext4fs_dirhash], [
424                 #include <linux/fs.h>
425                 #include "$EXT4_SRC_DIR/ext4.h"
426         ],[
427                 int f = ext4fs_dirhash(NULL, NULL, 0, NULL);
428                 (void)f;
429         ],[-Werror],[],[ext4fs_dirhash])
430 ])
431 AC_DEFUN([LB_LDISKFSFS_DIRHASH_WANTS_DIR], [
432         LB2_MSG_LINUX_TEST_RESULT([if ldiskfsfs_dirhash takes an inode argument],
433         [ext4fs_dirhash], [
434                 AC_DEFINE(HAVE_LDISKFSFS_DIRHASH_WITH_DIR, 1,
435                         [if ldiskfsfs_dirhash takes an inode argument])
436         ])
437 ]) # LB_LDISKFSFS_DIRHASH_WANTS_DIR
438
439 #
440 # LB_JBD2_H_TOTAL_CREDITS
441 #
442 # kernel 5.5 commit 933f1c1e0b75bbc29730eef07c9e196c6dfd37e5
443 # jbd2: Reserve space for revoke descriptor blocks
444 #
445 AC_DEFUN([LB_SRC_JBD2_H_TOTAL_CREDITS], [
446         LB2_LINUX_TEST_SRC([handle_t_h_revoke_credits], [
447                 #include <linux/jbd2.h>
448         ],[
449                 int x = offsetof(struct jbd2_journal_handle, h_total_credits);
450                 (void)x;
451         ],[-Werror])
452 ])
453 AC_DEFUN([LB_JBD2_H_TOTAL_CREDITS], [
454         LB2_MSG_LINUX_TEST_RESULT([if struct jbd2_journal_handle has h_total_credits member],
455         [handle_t_h_revoke_credits], [
456                 AC_DEFINE(HAVE_JOURNAL_TOTAL_CREDITS, 1,
457                         [struct jbd2_journal_handle has h_total_credits member])
458         ])
459 ]) # LB_JBD2_H_TOTAL_CREDITS
460
461 #
462 # LB_EXT4_INC_DEC_COUNT_2ARGS
463 #
464 # Linux v5.9-rc7-8-g15ed2851b0f4
465 # ext4: remove unused argument from ext4_(inc|dec)_count
466 #
467 AC_DEFUN([LB_EXT4_INC_DEC_COUNT_2ARGS], [
468         AC_MSG_CHECKING([if ext4_(inc|dec)_count() have 2 arguments])
469         AS_IF([grep -q -E 'void ext4_inc_count.handle_t \*handle' $EXT4_SRC_DIR/namei.c],[
470                 AC_DEFINE(HAVE_EXT4_INC_DEC_COUNT_2ARGS, 1,
471                         [ext4_(inc|dec)_count() has 2 arguments])
472                 AC_MSG_RESULT(yes)
473         ],[
474                 AC_MSG_RESULT(no)
475         ])
476 ]) # LB_EXT4_INC_DEC_COUNT_2ARGS
477
478 #
479 # LB_JBD2_JOURNAL_GET_MAX_TXN_BUFS
480 # Linux commit v5.10-rc2-9-gede7dc7fa0af
481 #  jbd2: rename j_maxlen to j_total_len and add jbd2_journal_max_txn_bufs
482 #
483 AC_DEFUN([LB_SRC_JBD2_JOURNAL_GET_MAX_TXN_BUFS], [
484         LB2_LINUX_TEST_SRC([jbd2_journal_get_max_txn_bufs], [
485                 #include <linux/jbd2.h>
486         ],[
487                 journal_t *journal = NULL;
488                 int x = jbd2_journal_get_max_txn_bufs(journal);
489                 (void)x;
490         ],[-Werror],[],[])
491 ])
492 AC_DEFUN([LB_JBD2_JOURNAL_GET_MAX_TXN_BUFS], [
493         LB2_MSG_LINUX_TEST_RESULT([if jbd2_journal_get_max_txn_bufs is available],
494         [jbd2_journal_get_max_txn_bufs], [
495                 AC_DEFINE(HAVE_JBD2_JOURNAL_GET_MAX_TXN_BUFS, 1,
496                         [if jbd2_journal_get_max_txn_bufs is available])
497         ])
498 ]) # LB_JBD2_JOURNAL_GET_MAX_TXN_BUFS
499
500 #
501 # LB_EXT4_JOURNAL_GET_WRITE_ACCESS_4A
502 #
503 # Linux v5.14-rc2-19-g188c299e2a26
504 #    ext4: Support for checksumming from journal triggers
505 #
506 AC_DEFUN([LB_EXT4_JOURNAL_GET_WRITE_ACCESS_4A], [
507 tmp_flags="$EXTRA_KCFLAGS"
508 EXTRA_KCFLAGS="-Werror"
509 LB_CHECK_COMPILE([if jbd2_journal_get_max_txn_bufs is available],
510 ext4_journal_get_write_access, [
511         #include <linux/fs.h>
512         #include "$EXT4_SRC_DIR/ext4.h"
513         #include "$EXT4_SRC_DIR/ext4_jbd2.h"
514
515         int __ext4_journal_get_write_access(const char *where, unsigned int line,
516                                     handle_t *handle,
517                                     struct super_block *sb,
518                                     struct buffer_head *bh,
519                                     enum ext4_journal_trigger_type trigger_type)
520         {
521                 return 0;
522         }
523 ],[
524         handle_t *handle = NULL;
525         struct super_block *sb = NULL;
526         struct buffer_head *bh = NULL;
527         enum ext4_journal_trigger_type trigger_type = EXT4_JTR_NONE;
528         int err = ext4_journal_get_write_access(handle, sb, bh, trigger_type);
529
530         (void)err;
531 ],[
532         AC_DEFINE(HAVE_EXT4_JOURNAL_GET_WRITE_ACCESS_4ARGS, 1,
533                 [ext4_journal_get_write_access() has 4 arguments])
534 ])
535 EXTRA_KCFLAGS="$tmp_flags"
536 ]) # LB_EXT4_JOURNAL_GET_WRITE_ACCESS_4A
537
538 #
539 # LB_HAVE_INODE_LOCK_SHARED
540 #
541 AC_DEFUN([LB_HAVE_INODE_LOCK_SHARED], [
542 LB_CHECK_COMPILE([if inode_lock_shared() defined],
543 inode_lock_shared, [
544         #include <linux/fs.h>
545 ],[
546         struct inode i;
547
548         inode_lock_shared(&i);
549 ],[
550         AC_DEFINE(HAVE_INODE_LOCK_SHARED, 1,
551                 [inode_lock_shared() defined])
552 ])
553 ]) # LB_HAVE_INODE_LOCK_SHARED
554
555 #
556 # LB_HAVE_INODE_IVERSION
557 #
558 AC_DEFUN([LB_HAVE_INODE_IVERSION], [
559 LB_CHECK_COMPILE([if iversion primitives defined],
560 inode_set_iversion, [
561         #include <linux/iversion.h>
562 ],[
563         struct inode i;
564
565         inode_set_iversion(&i, 0);
566 ],[
567         AC_DEFINE(HAVE_INODE_IVERSION, 1,
568                 [iversion primitives defined])
569 ])
570 ]) # LB_HAVE_INODE_IVERSION
571
572 #
573 # LB_CONFIG_LDISKFS
574 #
575 AC_DEFUN([LB_CONFIG_LDISKFS], [
576 # --with-ldiskfs is deprecated now that ldiskfs is fully merged with lustre.
577 # However we continue to support this option through Lustre 2.5.
578 AC_ARG_WITH([ldiskfs],
579         [],
580         [AC_MSG_WARN([--with-ldiskfs is deprecated, please use --enable-ldiskfs])
581         AS_IF([test x$withval != xyes -a x$withval != xno],
582                 [AC_MSG_ERROR([
583
584 The ldiskfs option is deprecated,
585 and no longer supports paths to external ldiskfs source
586 ])])
587 ])
588
589 AC_ARG_ENABLE([ldiskfs],
590         [AS_HELP_STRING([--disable-ldiskfs],
591                 [disable ldiskfs osd (default is enable)])],
592         [AS_IF([test x$enable_ldiskfs != xyes -a x$enable_ldiskfs != xno],
593                 [AC_MSG_ERROR([ldiskfs valid options are "yes" or "no"])])],
594         [AS_IF([test "${with_ldiskfs+set}" = set],
595                 [enable_ldiskfs=$with_ldiskfs],
596                 [enable_ldiskfs=maybe])
597 ])
598
599 AS_IF([test x$enable_server = xno],
600         [AS_CASE([$enable_ldiskfs],
601                 [maybe], [enable_ldiskfs=no],
602                 [yes], [AC_MSG_ERROR([cannot build ldiskfs when servers are disabled])]
603         )])
604
605 AS_IF([test x$enable_ldiskfs != xno],[
606         # In the future, we chould change enable_ldiskfs from maybe to
607         # either yes or no based on additional tests, e.g.  whether a patch
608         # set is available for the detected kernel.  For now, we just always
609         # set it to "yes".
610         AS_IF([test x$enable_ldiskfs = xmaybe], [enable_ldiskfs=yes])
611         AC_SUBST(ENABLE_LDISKFS, yes)
612
613         LDISKFS_LINUX_SERIES
614         LDISKFS_AC_PATCH_PROGRAM
615         LB_EXT4_INC_DEC_COUNT_2ARGS
616         LB_EXT4_JOURNAL_GET_WRITE_ACCESS_4A
617         LB_HAVE_INODE_LOCK_SHARED
618         LB_HAVE_INODE_IVERSION
619         AC_DEFINE(CONFIG_LDISKFS_FS_POSIX_ACL, 1, [posix acls for ldiskfs])
620         AC_DEFINE(CONFIG_LDISKFS_FS_SECURITY, 1, [fs security for ldiskfs])
621         AC_DEFINE(CONFIG_LDISKFS_FS_XATTR, 1, [extened attributes for ldiskfs])
622         AC_DEFINE(CONFIG_LDISKFS_FS_RW, 1, [enable rw access for ldiskfs])
623         AC_SUBST(LDISKFS_SUBDIR, ldiskfs)
624         AC_DEFINE(HAVE_LDISKFS_OSD, 1, Enable ldiskfs osd)
625 ], [
626         AC_SUBST(ENABLE_LDISKFS, no)
627 ])
628
629 AC_MSG_CHECKING([whether to build ldiskfs])
630 AC_MSG_RESULT([$enable_ldiskfs])
631
632 AM_CONDITIONAL([LDISKFS_ENABLED], [test x$enable_ldiskfs = xyes])
633 ]) # LB_CONFIG_LDISKFS
634
635 AC_DEFUN([LB_KABI_LDISKFS], [AS_IF([test x$enable_ldiskfs != xno],[
636         AC_DEFUN([LB_EXT4_LDISKFS_TESTS],[
637                 LB_SRC_EXT4_BREAD_4ARGS
638                 LB_SRC_EXT4_HAVE_INFO_DQUOT
639                 LB_SRC_EXT4_HAVE_I_CRYPT_INFO
640                 LB_SRC_LDISKFS_JOURNAL_ENSURE_CREDITS
641                 LB_SRC_LDISKFS_IGET_HAS_FLAGS_ARG
642                 LB_SRC_LDISKFS_FIND_ENTRY_LOCKED_EXISTS
643                 LB_SRC_LDISKFSFS_DIRHASH_WANTS_DIR
644                 LB_SRC_JBD2_H_TOTAL_CREDITS
645                 LB_SRC_JBD2_JOURNAL_GET_MAX_TXN_BUFS
646                 LB2_SRC_CHECK_CONFIG_IM([FS_ENCRYPTION])
647         ])
648         AC_DEFUN([LB_EXT4_LDISKFS_CHECKS], [
649                 LB_EXT4_BREAD_4ARGS
650                 LB_EXT4_HAVE_INFO_DQUOT
651                 LB_EXT4_HAVE_I_CRYPT_INFO
652                 LB_LDISKFS_JOURNAL_ENSURE_CREDITS
653                 LB_LDISKFS_IGET_HAS_FLAGS_ARG
654                 LB_LDISKFS_FIND_ENTRY_LOCKED_EXISTS
655                 LB_LDISKFSFS_DIRHASH_WANTS_DIR
656                 LB_JBD2_H_TOTAL_CREDITS
657                 LB_JBD2_JOURNAL_GET_MAX_TXN_BUFS
658                 LB2_TEST_CHECK_CONFIG_IM([FS_ENCRYPTION], [
659                         EXT4_CRYPTO=],[
660                         EXT4_CRYPTO='%/crypto.c'])
661         ])
662         AC_SUBST(EXT4_CRYPTO)
663 ])])
664
665 #
666 # LB_VALIDATE_EXT4_SRC_DIR
667 #
668 # Spot check the existence of several source files common to ext4.
669 # Detecting this at configure time allows us to avoid a potential build
670 # failure and provide a useful error message to explain what is wrong.
671 #
672 AC_DEFUN([LB_VALIDATE_EXT4_SRC_DIR], [
673 enable_ldiskfs_build="no"
674 AS_IF([test -n "$EXT4_SRC_DIR"], [
675         enable_ldiskfs_build="yes"
676         LB_CHECK_FILE([$EXT4_SRC_DIR/dir.c], [], [
677                 enable_ldiskfs_build="no"
678                 AC_MSG_WARN([ext4 must exist for ldiskfs build])
679         ])
680         LB_CHECK_FILE([$EXT4_SRC_DIR/file.c], [], [
681                 enable_ldiskfs_build="no"
682                 AC_MSG_WARN([ext4 must exist for ldiskfs build])
683         ])
684         LB_CHECK_FILE([$EXT4_SRC_DIR/inode.c], [], [
685                 enable_ldiskfs_build="no"
686                 AC_MSG_WARN([ext4 must exist for ldiskfs build])
687         ])
688         LB_CHECK_FILE([$EXT4_SRC_DIR/super.c], [], [
689                 enable_ldiskfs_build="no"
690                 AC_MSG_WARN([ext4 must exist for ldiskfs build])
691         ])
692 ])
693
694 AS_IF([test "x$enable_ldiskfs_build" = xno], [
695         enable_ldiskfs="no"
696
697         AC_MSG_WARN([
698
699 Disabling ldiskfs support because complete ext4 source does not exist.
700
701 If you are building using kernel-devel packages and require ldiskfs
702 server support then ensure that the matching kernel-debuginfo-common
703 and kernel-debuginfo-common-<arch> packages are installed.
704 ])
705 ])
706 ]) # LB_VALIDATE_EXT4_SRC_DIR
707
708 #
709 # LB_EXT4_SOURCE_PATH
710 #
711 # Determine the location of the ext4 source code.  It it required
712 # for several configure tests and to build ldiskfs.
713 #
714 AC_DEFUN([LB_EXT4_SOURCE_PATH], [
715 AC_MSG_CHECKING([ext4 source directory])
716 # Kernel ext source located with devel headers
717 linux_src=$LINUX
718 AS_IF([test -e "$linux_src/fs/ext4/super.c"], [
719         EXT4_SRC_DIR="$linux_src/fs/ext4"
720 ], [
721         # Kernel ext source provided by kernel-debuginfo-common package
722         # that extracted to $LINUX
723         linux_src=$(ls -1d $linux_src/../../debug/*/linux-${LINUXRELEASE%.*}* \
724                 2>/dev/null | tail -1)
725         AS_IF([test -e "$linux_src/fs/ext4/super.c"], [
726                 EXT4_SRC_DIR="$linux_src/fs/ext4"
727         ], [
728                 # Kernel ext source provided by kernel-debuginfo-common package
729                 linux_src=$(ls -1d /usr/src/debug/*/linux-${LINUXRELEASE%.*}* \
730                         2>/dev/null | tail -1)
731                 AS_IF([test -e "$linux_src/fs/ext4/super.c"], [
732                         EXT4_SRC_DIR="$linux_src/fs/ext4"
733                 ], [
734                         EXT4_SRC_DIR=""
735                 ])
736         ])
737 ])
738 AC_MSG_RESULT([$EXT4_SRC_DIR])
739 AC_SUBST(EXT4_SRC_DIR)
740
741 LB_VALIDATE_EXT4_SRC_DIR
742 ]) # LB_EXT4_SOURCE_PATH
743
744 #
745 # LB_DEFINE_E2FSPROGS_NAMES
746 #
747 # Enable the use of alternate naming of ldiskfs-enabled e2fsprogs package.
748 #
749 AC_DEFUN([LB_DEFINE_E2FSPROGS_NAMES], [
750 AC_MSG_CHECKING([whether to use alternate names for e2fsprogs])
751 AC_ARG_WITH([ldiskfsprogs],
752         AS_HELP_STRING([--with-ldiskfsprogs],
753                 [use alternate names for ldiskfs-enabled e2fsprogs]),
754         [], [withval="no"])
755
756 AS_IF([test "x$withval" = xyes], [
757         AC_MSG_RESULT([enabled])
758         AC_DEFINE(HAVE_LDISKFSPROGS, 1, [enable use of ldiskfsprogs package])
759         E2FSPROGS="ldiskfsprogs"
760         MKE2FS="mkfs.ldiskfs"
761         DEBUGFS="debugfs.ldiskfs"
762         TUNE2FS="tunefs.ldiskfs"
763         E2LABEL="label.ldiskfs"
764         DUMPE2FS="dumpfs.ldiskfs"
765         E2FSCK="fsck.ldiskfs"
766         PFSCK="pfsck.ldiskfs"
767 ], [
768         AC_MSG_RESULT([disabled])
769         E2FSPROGS="e2fsprogs"
770         MKE2FS="mke2fs"
771         DEBUGFS="debugfs"
772         TUNE2FS="tune2fs"
773         E2LABEL="e2label"
774         DUMPE2FS="dumpe2fs"
775         E2FSCK="e2fsck"
776         PFSCK="fsck"
777 ])
778
779 AC_DEFINE_UNQUOTED(E2FSPROGS, "$E2FSPROGS", [name of ldiskfs e2fsprogs package])
780 AC_DEFINE_UNQUOTED(MKE2FS, "$MKE2FS", [name of ldiskfs mkfs program])
781 AC_DEFINE_UNQUOTED(DEBUGFS, "$DEBUGFS", [name of ldiskfs debug program])
782 AC_DEFINE_UNQUOTED(TUNE2FS, "$TUNE2FS", [name of ldiskfs tune program])
783 AC_DEFINE_UNQUOTED(E2LABEL, "$E2LABEL", [name of ldiskfs label program])
784 AC_DEFINE_UNQUOTED(DUMPE2FS,"$DUMPE2FS", [name of ldiskfs dump program])
785 AC_DEFINE_UNQUOTED(E2FSCK, "$E2FSCK", [name of ldiskfs fsck program])
786 AC_DEFINE_UNQUOTED(PFSCK, "$PFSCK", [name of parallel fsck program])
787
788 AC_SUBST([E2FSPROGS], [$E2FSPROGS])
789 AC_SUBST([MKE2FS], [$MKE2FS])
790 AC_SUBST([DEBUGFS], [$DEBUGFS])
791 AC_SUBST([TUNE2FS], [$TUNE2FS])
792 AC_SUBST([E2LABEL], [$E2LABEL])
793 AC_SUBST([DUMPE2FS], [$DUMPE2FS])
794 AC_SUBST([E2FSCK], [$E2FSCK])
795 AC_SUBST([PFSCK], [$PFSCK])
796 ]) # LB_DEFINE_E2FSPROGS_NAMES