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