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