+# LB_EXT4_JOURNAL_START_3ARGS
+#
+# 3.9 added a type argument to ext4_journal_start and friends
+#
+AC_DEFUN([LB_EXT4_JOURNAL_START_3ARGS], [
+LB_CHECK_COMPILE([if ext4_journal_start takes 3 arguments],
+ext4_journal_start, [
+ #include <linux/fs.h>
+ #include "$EXT4_SRC_DIR/ext4_jbd2.h"
+],[
+ ext4_journal_start(NULL, 0, 0);
+],[
+ AC_DEFINE(JOURNAL_START_HAS_3ARGS, 1, [ext4_journal_start takes 3 arguments])
+])
+]) # LB_EXT4_JOURNAL_START_3ARGS
+
+#
+# LB_EXT4_BREAD_4ARGS
+#
+# 3.18 ext4_bread has 4 arguments
+# NOTE: It may not be exported for modules, use a positive compiler test here.
+#
+AC_DEFUN([LB_EXT4_BREAD_4ARGS], [
+LB_CHECK_COMPILE([if ext4_bread takes 4 arguments],
+ext4_bread, [
+ #include <linux/fs.h>
+ #include "$EXT4_SRC_DIR/ext4.h"
+
+ struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode,
+ ext4_lblk_t block, int map_flags)
+ {
+ struct buffer_head *bh = NULL;
+ (void)handle;
+ (void)inode;
+ (void)block;
+ (void)map_flags;
+ return bh;
+ }
+],[
+ ext4_bread(NULL, NULL, 0, 0);
+],[
+ AC_DEFINE(HAVE_EXT4_BREAD_4ARGS, 1, [ext4_bread takes 4 arguments])
+])
+]) # LB_EXT4_BREAD_4ARGS
+
+#
+# LB_EXT4_HAVE_INFO_DQUOT
+#
+# in linux 4.4 i_dqout is in ext4_inode_info, not in struct inode
+#
+AC_DEFUN([LB_EXT4_HAVE_INFO_DQUOT], [
+LB_CHECK_COMPILE([if i_dquot is in ext4_inode_info],
+ext4_info_dquot, [
+ #include <linux/fs.h>
+ #include <linux/quota.h>
+ #include "$EXT4_SRC_DIR/ext4.h"
+],[
+ struct ext4_inode_info in;
+ struct dquot *dq;
+
+ dq = in.i_dquot[0];
+],[
+ AC_DEFINE(HAVE_EXT4_INFO_DQUOT, 1, [i_dquot is in ext4_inode_info])
+])
+]) # LB_EXT4_HAVE_INFO_DQUOT
+
+#
+# LB_EXT4_HAVE_I_CRYPT_INFO
+#
+# in linux 4.8 i_crypt_info moved from ext4_inode_info to struct inode
+#
+# Determine if we need to enable CONFIG_LDISKFS_FS_ENCRYPTION.
+# If we have i_crypt_info in ext4_inode_info, the config option
+# should be enabled to make the ldiskfs module compilation happy.
+# Otherwise i_crypy_info is in struct inode, we need to check kernel
+# config option to determine that.
+#
+AC_DEFUN([LB_EXT4_HAVE_I_CRYPT_INFO], [
+LB_CHECK_COMPILE([if i_crypt_info is in ext4_inode_info],
+ext4_i_crypt_info, [
+ #define CONFIG_EXT4_FS_ENCRYPTION 1
+ #include <linux/fs.h>
+ #include "$EXT4_SRC_DIR/ext4.h"
+],[
+ struct ext4_inode_info in;
+
+ in.i_crypt_info = NULL;
+],[
+ AC_DEFINE(
+ CONFIG_LDISKFS_FS_ENCRYPTION, 1,
+ [enable encryption for ldiskfs]
+ )
+],[
+ LB_CHECK_CONFIG([EXT4_FS_ENCRYPTION],[
+ AC_DEFINE(
+ CONFIG_LDISKFS_FS_ENCRYPTION, 1,
+ [enable encryption for ldiskfs]
+ )
+ ])
+])
+]) # LB_EXT4_HAVE_I_CRYPT_INFO
+
+#
+# LB_LDISKFS_JOURNAL_ENSURE_CREDITS
+#
+# kernel 4.18.0-240.1.1.el8 and
+# kernel 5.4 commit a413036791d040e33badcc634453a4d0c0705499
+#
+# ext4_journal_ensure_credits was introduced to ensure given handle
+# has at least requested amount of credits available, and possibly
+# restarting transaction if needed.
+#
+AC_DEFUN([LB_LDISKFS_JOURNAL_ENSURE_CREDITS], [
+tmp_flags="$EXTRA_KCFLAGS"
+EXTRA_KCFLAGS="-Werror"
+LB_CHECK_COMPILE([if 'ext4_journal_ensure_credits' exists],
+ext4_journal_ensure_credits, [
+ #include "$EXT4_SRC_DIR/ext4_jbd2.h"
+ int __ext4_journal_ensure_credits(handle_t *handle, int check_cred,
+ int extend_cred, int revoke_cred) { return 0; }
+],[
+ ext4_journal_ensure_credits(NULL, 0, 0);
+],[
+ AC_DEFINE(HAVE_LDISKFS_JOURNAL_ENSURE_CREDITS, 1,
+ ['ext4_journal_ensure_credits' exists])
+])
+EXTRA_KCFLAGS="$tmp_flags"
+]) # LB_LDISKFS_JOURNAL_ENSURE_CREDITS
+
+#
+# LB_LDISKFS_IGET_HAS_FLAGS_ARG