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