+AC_DEFUN([LDISKFS_AC_LINUX_VERSION], [
+ AC_MSG_CHECKING([kernel source version])
+
+ utsrelease1=${LINUX_OBJ}/include/linux/version.h
+ utsrelease2=${LINUX_OBJ}/include/linux/utsrelease.h
+ utsrelease3=${LINUX_OBJ}/include/generated/utsrelease.h
+ AS_IF([test -r ${utsrelease1} && fgrep -q UTS_RELEASE ${utsrelease1}], [
+ utsrelease=linux/version.h
+ ], [test -r ${utsrelease2} && fgrep -q UTS_RELEASE ${utsrelease2}], [
+ utsrelease=linux/utsrelease.h
+ ], [test -r ${utsrelease3} && fgrep -q UTS_RELEASE ${utsrelease3}], [
+ utsrelease=generated/utsrelease.h
+ ])
+
+ AS_IF([test "${utsrelease}"], [
+ kernsrcver=$((echo "#include <$utsrelease>";
+ echo "kernsrcver=UTS_RELEASE") |
+ cpp -I ${LINUX_OBJ}/include |
+ grep "^kernsrcver=" | cut -d \" -f 2)
+
+ AS_IF([test -z "$kernsrcver"], [
+ AC_MSG_RESULT([Not found])
+ AC_MSG_ERROR([*** Cannot determine kernel version.])
+ ])
+ ], [
+ AC_MSG_RESULT([Not found])
+ AC_MSG_ERROR([
+ *** Cannot find UTS_RELEASE definition.
+ *** This is often provided by the kernel-devel package.])
+ ])
+
+ AC_MSG_RESULT([${kernsrcver}])
+
+ LINUX_VERSION=${kernsrcver}
+ AC_SUBST(LINUX_VERSION)
+ LINUXRELEASE=${kernsrcver}
+ AC_SUBST(LINUXRELEASE)
+])
+
+#
+# LB_LINUX_RELEASE
+#
+# get the release version of linux
+#
+
+AC_DEFUN([LB_LINUX_RELEASE],
+[
+LDISKFS_AC_LINUX_VERSION
+
+# ------------ RELEASE --------------------------------
+AC_MSG_CHECKING([for ldiskfs release])
+AC_ARG_WITH([release],
+ AC_HELP_STRING([--with-release=string],
+ [set the release string (default=$kvers_YYYYMMDDhhmm)]),
+ [RELEASE=$withval],
+ RELEASE=""
+ if test -n "$DOWNSTREAM_RELEASE"; then
+ RELEASE="${DOWNSTREAM_RELEASE}_"
+ fi
+ RELEASE="$RELEASE`echo ${LINUXRELEASE} | tr '-' '_'`_$BUILDID")
+AC_MSG_RESULT($RELEASE)
+AC_SUBST(RELEASE)
+
+# check is redhat/suse kernels
+AC_MSG_CHECKING([that RedHat kernel])
+LB_LINUX_TRY_COMPILE([
+ #include <linux/version.h>
+ ],[
+ #ifndef RHEL_RELEASE_CODE
+ #error "not redhat kernel"
+ #endif
+ ],[
+ RHEL_KERNEL="yes"
+ AC_MSG_RESULT([yes])
+ ],[
+ AC_MSG_RESULT([no])
+])
+
+LB_LINUX_CONFIG([SUSE_KERNEL],[SUSE_KERNEL="yes"],[])
+
+])
+
+# LB_ARG_REPLACE_PATH(PACKAGE, PATH)
+AC_DEFUN([LB_ARG_REPLACE_PATH],[
+ new_configure_args=
+ eval "set x $ac_configure_args"
+ shift
+ for arg; do
+ case $arg in
+ --with-[$1]=*)
+ arg=--with-[$1]=[$2]
+ ;;
+ *\'*)
+ arg=$(printf %s\n ["$arg"] | \
+ sed "s/'/'\\\\\\\\''/g")
+ ;;
+ esac
+ dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
+ new_configure_args="$new_configure_args \"$arg\""
+ done
+ ac_configure_args=$new_configure_args
+])
+
+# this is the work-horse of the next function
+AC_DEFUN([__LB_ARG_CANON_PATH], [
+ [$3]=$(readlink -f $with_$2)
+ LB_ARG_REPLACE_PATH([$1], $[$3])
+])
+
+# a front-end for the above function that transforms - and . in the
+# PACKAGE portion of --with-PACKAGE into _ suitable for variable names
+AC_DEFUN([LB_ARG_CANON_PATH], [
+ __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
+])
+
+#
+#
+# LB_LINUX_PATH
+#
+# Find paths for linux, handling kernel-source rpms
+#
+AC_DEFUN([LB_LINUX_PATH],
+[# prep some default values
+for DEFAULT_LINUX in /lib/modules/$(uname -r)/{source,build} /usr/src/linux; do
+ if readlink -q -e $DEFAULT_LINUX; then
+ break
+ fi
+done
+if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
+ PATHS="/lib/modules/$(uname -r)/build"
+fi
+PATHS+=" $DEFAULT_LINUX"
+for DEFAULT_LINUX_OBJ in $PATHS; do
+ if readlink -q -e $DEFAULT_LINUX_OBJ; then
+ break
+ fi
+done
+AC_MSG_CHECKING([for Linux sources])
+AC_ARG_WITH([linux],
+ AC_HELP_STRING([--with-linux=path],
+ [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
+ [LB_ARG_CANON_PATH([linux], [LINUX])
+ DEFAULT_LINUX_OBJ=$LINUX],
+ [LINUX=$DEFAULT_LINUX])
+AC_MSG_RESULT([$LINUX])
+AC_SUBST(LINUX)
+
+# -------- check for linux --------
+LB_CHECK_FILE([$LINUX],[],
+ [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
+
+# -------- linux objects (for 2.6) --
+AC_MSG_CHECKING([for Linux objects dir])
+AC_ARG_WITH([linux-obj],
+ AC_HELP_STRING([--with-linux-obj=path],
+ [set path to Linux objects dir (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
+ [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
+ [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
+
+AC_MSG_RESULT([$LINUX_OBJ])
+AC_SUBST(LINUX_OBJ)
+
+# -------- check for .config --------
+AC_ARG_WITH([linux-config],
+ [AC_HELP_STRING([--with-linux-config=path],
+ [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
+ [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
+ [LINUX_CONFIG=$LINUX_OBJ/.config])
+AC_SUBST(LINUX_CONFIG)
+
+LB_CHECK_FILE([/boot/kernel.h],
+ [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
+ [LB_CHECK_FILE([/var/adm/running-kernel.h],
+ [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
+
+AC_ARG_WITH([kernel-source-header],
+ AC_HELP_STRING([--with-kernel-source-header=path],
+ [Use a different kernel version header. Consult build/README.kernel-source for details.]),
+ [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
+
+# ------------ .config exists ----------------
+LB_CHECK_FILE([$LINUX_CONFIG],[],
+ [AC_MSG_ERROR([Kernel config could not be found. If you are building from a kernel-source rpm consult build/README.kernel-source])])
+
+# ----------- make dep run? ------------------
+# at 2.6.19 # $LINUX/include/linux/config.h is removed
+# and at more old has only one line
+# include <autoconf.h>
+LB_CHECK_FILE([$LINUX_OBJ/include/generated/autoconf.h],[AUTOCONF_HDIR=generated],
+ [LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],[AUTOCONF_HDIR=linux],
+ [AC_MSG_ERROR([Run make config in $LINUX.])])])
+ AC_SUBST(AUTOCONF_HDIR)
+LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],[],
+ [AC_MSG_ERROR([Run make config in $LINUX.])])
+
+# ----------- kconfig.h exists ---------------
+# kernel 3.1, $LINUX/include/linux/kconfig.h is added
+# see kernel commit 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99
+LB_CHECK_FILE([$LINUX_OBJ/include/linux/kconfig.h],
+ [CONFIG_INCLUDE=include/linux/kconfig.h],
+ [CONFIG_INCLUDE=include/$AUTOCONF_HDIR/autoconf.h])
+ AC_SUBST(CONFIG_INCLUDE)
+
+# ------------ rhconfig.h includes runtime-generated bits --
+# red hat kernel-source checks
+
+# we know this exists after the check above. if the user
+# tarred up the tree and ran make dep etc. in it, then
+# version.h gets overwritten with a standard linux one.
+
+if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
+ # This is a clean kernel-source tree, we need to
+ # enable extensive workarounds to get this to build
+ # modules
+ LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
+ [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
+ AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
+ AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
+ AC_MSG_WARN([Consult build/README.kernel-source for details.])
+ fi],
+ [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found. Consult build/README.kernel-source for details.])])
+ EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
+fi
+
+# --- check that we can build modules at all
+AC_MSG_CHECKING([that modules can be built at all])
+LB_LINUX_TRY_COMPILE([],[],[
+ AC_MSG_RESULT([yes])
+],[
+ AC_MSG_RESULT([no])
+ AC_MSG_WARN([Consult config.log for details.])
+ AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
+ AC_MSG_ERROR([Kernel modules cannot be built.])
+])
+
+LB_LINUX_RELEASE
+]) # end of LB_LINUX_PATH
+
+# LB_LINUX_SYMVERFILE
+# SLES 9 uses a different name for this file - unsure about vanilla kernels
+# around this version, but it matters for servers only.
+AC_DEFUN([LB_LINUX_SYMVERFILE],
+ [AC_MSG_CHECKING([name of module symbol version file])
+ if grep -q Modules.symvers $LINUX/scripts/Makefile.modpost ; then
+ SYMVERFILE=Modules.symvers
+ else
+ SYMVERFILE=Module.symvers
+ fi
+ AC_MSG_RESULT($SYMVERFILE)
+ AC_SUBST(SYMVERFILE)
+])
+
+# these are like AC_TRY_COMPILE, but try to build modules against the
+# kernel, inside the build directory
+
+# LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
+# --------------------------------------
+m4_define([LB_LANG_PROGRAM],
+[
+#include <linux/kernel.h>
+$1
+int
+main (void)
+{
+dnl Do *not* indent the following line: there may be CPP directives.
+dnl Don't move the `;' right after for the same reason.
+$2
+ ;
+ return 0;
+}])
+
+#
+# LB_LINUX_COMPILE_IFELSE
+#
+# like AC_COMPILE_IFELSE
+#
+AC_DEFUN([LB_LINUX_COMPILE_IFELSE], [
+ m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])
+ rm -Rf build-test && mkdir -p build-test
+ echo "obj-m := conftest.o" >build-test/Makefile
+ AS_IF(
+ [AC_TRY_COMMAND(cp conftest.c build-test && make [$2] -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" M=$PWD/build-test) >/dev/null && AC_TRY_COMMAND([$3])],
+ [$4],
+ [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
+ )
+ rm -Rf build-test
+])
+
+
+#
+# LB_LINUX_TRY_COMPILE
+#
+# like AC_TRY_COMPILE
+#
+AC_DEFUN([LB_LINUX_TRY_COMPILE],
+[LB_LINUX_COMPILE_IFELSE(
+ [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
+ [modules],
+ [test -s build-test/conftest.o],
+ [$3], [$4])])
+
+#
+# LB_LINUX_CONFIG
+#
+# check if a given config option is defined
+#
+AC_DEFUN([LB_LINUX_CONFIG],[
+ AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
+ LB_LINUX_TRY_COMPILE([
+ #include <$AUTOCONF_HDIR/autoconf.h>
+ ],[
+ #ifndef CONFIG_$1
+ #error CONFIG_$1 not #defined
+ #endif
+ ],[
+ AC_MSG_RESULT([yes])
+ $2
+ ],[
+ AC_MSG_RESULT([no])
+ $3
+ ])
+])
+
+#
+# LB_LINUX_CONFIG_IM
+#
+# check if a given config option is builtin or as module
+#
+AC_DEFUN([LB_LINUX_CONFIG_IM],[
+ AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
+ LB_LINUX_TRY_COMPILE([
+ #include <$AUTOCONF_HDIR/autoconf.h>
+ ],[
+ #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
+ #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
+ #endif
+ ],[
+ AC_MSG_RESULT([yes])
+ $2
+ ],[
+ AC_MSG_RESULT([no])
+ $3
+ ])
+])
+
+#
+# LB_CHECK_SYMBOL_EXPORT
+# check symbol exported or not
+# $1 - symbol
+# $2 - file(s) for find.
+# $3 - do 'yes'
+# $4 - do 'no'
+#
+# 2.6 based kernels - put modversion info into $LINUX/Module.modvers
+# or check
+AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
+[AC_MSG_CHECKING([if Linux was built with symbol $1 exported])
+grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/$SYMVERFILE 2>/dev/null
+rc=$?
+if test $rc -ne 0; then
+ export=0
+ for file in $2; do
+ grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null
+ rc=$?
+ if test $rc -eq 0; then
+ export=1
+ break;
+ fi
+ done
+ if test $export -eq 0; then
+ AC_MSG_RESULT([no])
+ $4
+ else
+ AC_MSG_RESULT([yes])
+ $3
+ fi
+else
+ AC_MSG_RESULT([yes])
+ $3
+fi
+])
+
+#
+# Like AC_CHECK_HEADER but checks for a kernel-space header
+#
+m4_define([LB_CHECK_LINUX_HEADER],
+[AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
+AC_CACHE_CHECK([for $1], ac_Header,
+ [LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
+ [modules],
+ [test -s build-test/conftest.o],
+ [AS_VAR_SET(ac_Header, [yes])],
+ [AS_VAR_SET(ac_Header, [no])])])
+AS_IF([test AS_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
+AS_VAR_POPDEF([ac_Header])dnl
+])
+#
+# LB_DOWNSTREAM_RELEASE
+#
+AC_DEFUN([LB_DOWNSTREAM_RELEASE],
+[AC_ARG_WITH([downstream-release],
+ AC_HELP_STRING([--with-downstream-release=string],
+ [set a string in the BUILD_VERSION and RPM Release: (default is nothing)]),
+ [DOWNSTREAM_RELEASE=$with_downstream_release],
+ [
+ # if not specified, see if it's in the META file
+ if test -f META; then
+ DOWNSTREAM_RELEASE=$(sed -ne '/^LOCAL_VERSION =/s/.*= *//p' META)
+ fi
+ ])
+AC_SUBST(DOWNSTREAM_RELEASE)
+])
+
+#
+# LB_BUILDID
+#
+# Check if the source is a GA release and if not, set a "BUILDID"
+#
+# Currently there are at least two ways/modes of/for doing this. One
+# is if we are in a valid git repository, the other is if we are in a
+# non-git source tree of some form. Building the latter from the former
+# will be handled here.
+AC_DEFUN([LB_BUILDID],
+[
+AC_MSG_CHECKING([for buildid])
+BUILDID=""
+if git branch >/dev/null 2>&1; then
+ ffw=0
+ hash=""
+ ver=$(git describe --match v[[0-9]]_*_[[0-9]]* --tags)
+ if [[[ $ver = *-*-* ]]]; then
+ hash=${ver##*-}
+ ffw=${ver#*-}
+ ffw=${ffw%-*}
+ ver=${ver%%-*}
+ fi
+ # it's tempting to use [[ $ver =~ ^v([0-9]+_)+([0-9]+|RC[0-9]+)$ ]]
+ # here but the portability of the regex on the right is dismal
+ # (thanx suse)
+ if echo "$ver" | egrep -q "^v([[0-9]]+_)+([[0-9]]+|RC[[0-9]]+)$"; then
+ ver=$(echo $ver | sed -e 's/^v\(.*\)/\1/' \
+ -e 's/_RC[[0-9]].*$//' -e 's/_/./g')
+ fi
+
+ # a "lustre fix" value of .0 should be truncated
+ if [[[ $ver = *.*.*.0 ]]]; then
+ ver=${ver%.0}
+ fi
+ # ditto for a "lustre fix" value of _0
+ if [[[ $ver = v*_*_*_0 ]]]; then
+ ver=${ver%_0}
+ fi
+ if [[[ $ver = v*_*_* ]]]; then
+ ver=${ver#v}
+ ver=${ver//_/.}
+ fi
+
+ if test "$ffw" != "0"; then
+ BUILDID="$hash"
+ msg="$BUILDID (ahead by $ffw commits)"
+ AC_MSG_RESULT([$msg])
+ else
+ AC_MSG_RESULT([none... congratulations, you must be on a tag])
+ fi
+elif test -f META; then
+ BUILDID=$(sed -ne '/^BUILDID =/s/.*= *//p' META)
+ msg="$BUILDID (from META file)"
+ AC_MSG_RESULT([$msg])
+else
+ AC_MSG_WARN([FIXME: I don't know how to deal with source trees outside of git that don't have a META file. Not setting a buildid.])
+fi
+AC_SUBST(BUILDID)
+])
+
+#
+# LB_CHECK_FILE
+#
+# Check for file existance even when cross compiling
+#
+AC_DEFUN([LB_CHECK_FILE],
+[AS_VAR_PUSHDEF([lb_File], [lb_cv_file_$1])dnl
+AC_CACHE_CHECK([for $1], lb_File,
+[if test -r "$1"; then
+ AS_VAR_SET(lb_File, yes)
+else
+ AS_VAR_SET(lb_File, no)
+fi])
+AS_IF([test AS_VAR_GET(lb_File) = yes], [$2], [$3])[]dnl
+AS_VAR_POPDEF([lb_File])dnl
+])# LB_CHECK_FILE
+
+#
+# LB_CONFIG_HEADERS
+#
+# add -include config.h
+#
+AC_DEFUN([LB_CONFIG_HEADERS],[
+ AC_CONFIG_HEADERS([config.h])
+ CPPFLAGS="-include $PWD/config.h $CPPFLAGS"
+ EXTRA_KCFLAGS="-include $PWD/config.h $EXTRA_KCFLAGS"
+ AC_SUBST(EXTRA_KCFLAGS)
+])
+
+#
+# LB_PROG_CC
+#
+# checks on the C compiler
+#
+AC_DEFUN([LB_PROG_CC],
+[AC_PROG_RANLIB
+
+# --------- unsigned long long sane? -------
+AC_CHECK_SIZEOF(unsigned long long, 0)
+echo "---> size SIZEOF $SIZEOF_unsigned_long_long"
+echo "---> size SIZEOF $ac_cv_sizeof_unsigned_long_long"
+if test $ac_cv_sizeof_unsigned_long_long != 8 ; then
+ AC_MSG_ERROR([** we assume that sizeof(long long) == 8.])
+fi
+
+if test $target_cpu == "powerpc64"; then
+ AC_MSG_WARN([set compiler with -m64])
+ CFLAGS="$CFLAGS -m64"
+ CC="$CC -m64"
+fi
+
+LLCPPFLAGS="-D__arch_lib__ -D_LARGEFILE64_SOURCE=1"
+AC_SUBST(LLCPPFLAGS)
+
+# Add _GNU_SOURCE for strnlen on linux
+LLCFLAGS="-g -Wall -fPIC -D_GNU_SOURCE"
+AC_SUBST(LLCFLAGS)
+
+CCASFLAGS="-Wall -fPIC -D_GNU_SOURCE"
+AC_SUBST(CCASFLAGS)
+])
+
+
+#
+# LB_LDISKFS_EXT_DIR
+#
+# Determine the location of the ext4 source code. It is required
+# for several configure tests and to build ldiskfs.
+#
+AC_DEFUN([LB_LDISKFS_EXT_DIR],
+[
+# Kernel ext source located with devel headers
+linux_src=$LINUX
+if test -e "$linux_src/fs/ext4/super.c"; then
+ EXT_DIR=$linux_src/fs/ext4
+else
+ # Kernel ext source provided by kernel-debuginfo-common package
+ linux_src=$(ls -1d /usr/src/debug/*/linux-$LINUXRELEASE \
+ 2>/dev/null | tail -1)
+ if test -e "$linux_src/fs/ext4/super.c"; then
+ EXT_DIR=$linux_src/fs/ext4
+ else
+ EXT_DIR=
+ fi
+fi
+
+AC_MSG_CHECKING([ext4 source directory])
+AC_MSG_RESULT([$EXT_DIR])
+AC_SUBST(EXT_DIR)
+])
+
+#
+# LB_LDISKFS_EXT_SOURCE
+#
+# Spot check the existance of several source files common to ext4.
+# Detecting this at configure time allows us to avoid a potential build
+# failure and provide a useful error message to explain what is wrong.
+#
+AC_DEFUN([LB_LDISKFS_EXT_SOURCE],
+[
+if test x$EXT_DIR = x; then
+ enable_ldiskfs_build='no'
+else
+ LB_CHECK_FILE([$EXT_DIR/dir.c], [], [
+ enable_ldiskfs_build='no'
+ AC_MSG_WARN([ext4 must exist for ldiskfs build])])
+ LB_CHECK_FILE([$EXT_DIR/file.c], [], [
+ enable_ldiskfs_build='no'
+ AC_MSG_WARN([ext4 must exist for ldiskfs build])])
+ LB_CHECK_FILE([$EXT_DIR/inode.c], [], [
+ enable_ldiskfs_build='no'
+ AC_MSG_WARN([ext4 must exist for ldiskfs build])])
+ LB_CHECK_FILE([$EXT_DIR/super.c], [], [
+ enable_ldiskfs_build='no'
+ AC_MSG_WARN([ext4 must exist for ldiskfs build])])
+fi
+
+if test x$enable_ldiskfs_build = xno; then
+ enable_server='no'
+ enable_ldiskfs_build='no'
+ with_ldiskfs='no'
+ LDISKFS_SUBDIR=
+
+ AC_MSG_WARN([
+
+Disabling server because complete ext4 source does not exist.
+
+If you are building using kernel-devel packages and require ldiskfs
+server support then ensure that the matching kernel-debuginfo-common
+and kernel-debuginfo-common-<arch> packages are installed.
+
+])
+
+fi
+])
+
+#
+# LB_LDISKFS_DEFINE_OPTIONS
+#
+# Enable config options related to ldiskfs. These are used by ldiskfs,
+# lvfs, and the osd-ldiskfs code (which includes ldiskfs headers.)
+#
+AC_DEFUN([LB_LDISKFS_DEFINE_OPTIONS],
+[
+AC_DEFINE(HAVE_LDISKFS_OSD, 1, Enable ldiskfs osd)
+
+with_ldiskfs_pdo=no
+case $LINUXRELEASE in
+2.6.32*)
+ if test x$RHEL_KERNEL = xyes; then
+ with_ldiskfs_pdo=yes
+ AC_DEFINE(HAVE_LDISKFS_PDO, 1, [have ldiskfs PDO patch])
+ fi
+ if test x$SUSE_KERNEL = xyes; then
+ with_ldiskfs_pdo=yes
+ AC_DEFINE(HAVE_LDISKFS_PDO, 1, [have ldiskfs PDO patch])
+ fi
+ ;;
+esac
+LB_LDISKFS_JBD2_JOURNAL_CALLBACK_SET
+
+AC_DEFINE(CONFIG_LDISKFS_FS_XATTR, 1,
+ [enable extended attributes for ldiskfs])
+AC_DEFINE(CONFIG_LDISKFS_FS_POSIX_ACL, 1,
+ [enable posix acls for ldiskfs])
+AC_DEFINE(CONFIG_LDISKFS_FS_SECURITY, 1,
+ [enable fs security for ldiskfs])
+AC_DEFINE(CONFIG_LDISKFSDEV_FS_POSIX_ACL, 1,
+ [enable posix acls for ldiskfs])
+AC_DEFINE(CONFIG_LDISKFSDEV_FS_XATTR, 1,
+ [enable extented attributes for ldiskfs])
+AC_DEFINE(CONFIG_LDISKFSDEV_FS_SECURITY, 1,
+ [enable fs security for ldiskfs])
+])
+
+#
+# Check for jbd2_journal_callback_set(), which is needed for commit
+# callbacks. When LU-433 lands jbd2_journal_callback_set() will only
+# remain for legacy reasons and AC_MSG_ERROR can be removed.
+#
+AC_DEFUN([LB_LDISKFS_JBD2_JOURNAL_CALLBACK_SET],
+[
+ LB_CHECK_SYMBOL_EXPORT([jbd2_journal_callback_set],
+ [fs/jbd2/journal.c],
+ [AC_DEFINE(HAVE_JBD2_JOURNAL_CALLBACK_SET, 1,
+ [kernel exports jbd2_journal_callback_set])])
+])
+
+
+AC_DEFUN([LB_LDISKFS_SYMVERS],
+[
+AC_MSG_CHECKING([ldiskfs module symbols])
+if test -r $LDISKFS_OBJ/Module.symvers; then
+ LDISKFS_SYMBOLS=Module.symvers
+elif test -r $LDISKFS_OBJ/Modules.symvers; then
+ LDISKFS_SYMBOLS=Modules.symvers
+elif test -r $LDISKFS_OBJ/ldiskfs/Module.symvers; then
+ LDISKFS_SYMBOLS=Module.symvers
+elif test -r $LDISKFS_OBJ/ldiskfs/Modules.symvers; then
+ LDISKFS_SYMBOLS=Modules.symvers
+else
+ LDISKFS_SYMBOLS=$SYMVERFILE
+fi
+
+AC_MSG_RESULT([$LDISKFS_SYMBOLS])
+AC_SUBST(LDISKFS_SYMBOLS)
+])
+
+AC_DEFUN([LB_LDISKFS_RELEASE],
+[
+AC_MSG_CHECKING([ldiskfs source release])
+if test -r $LDISKFS_OBJ/config.h; then
+ tmp_flags="$EXTRA_KCFLAGS"
+ EXTRA_KCFLAGS="-I$LDISKFS_DIR $EXTRA_KCFLAGS"
+ LB_LINUX_TRY_MAKE([
+ #undef PACKAGE_NAME
+ #undef PACKAGE_TARNAME
+ #undef PACKAGE_VERSION
+ #undef PACKAGE_STRING
+ #undef PACKAGE_BUGREPORT
+ #undef PACKAGE
+ #undef VERSION
+ #undef STDC_HEADERS
+
+ #include <$LDISKFS_OBJ/config.h>
+ ],[
+ char *LDISKFS_RELEASE;
+ LDISKFS_RELEASE=VERSION;
+ ],[
+ $makerule LUSTRE_KERNEL_TEST=conftest.i
+ ],[
+ test -s build/conftest.i
+ ],[
+ eval $(grep "LDISKFS_RELEASE=" build/conftest.i)
+ ],[
+ AC_MSG_RESULT([unknown])
+ AC_MSG_ERROR([Could not preprocess test program.])
+ ])
+ EXTRA_KCFLAGS="$tmp_flags"
+ rm build/conftest.i
+elif test -r $LDISKFS_DIR/configure.ac; then
+ LDISKFS_RELEASE=$(awk '/AC\_INIT/ { print [$]3 }' \
+ $LDISKFS_DIR/configure.ac | tr ',' '\n')
+else
+ AC_MSG_RESULT([unknown])
+ AC_MSG_ERROR([Could not locate config.h, META, or configure.ac to check release.])
+fi
+
+if test x$LDISKFS_RELEASE = x; then
+ AC_MSG_RESULT([unknown])
+ AC_MSG_ERROR([Could not determine ldiskfs release.])
+fi
+
+AC_MSG_RESULT([$LDISKFS_RELEASE])
+AC_SUBST(LDISKFS_RELEASE)
+])
+
+AC_DEFUN([LB_LDISKFS_SERIES],
+[
+if $1; then
+ AC_MSG_CHECKING([which ldiskfs series to use])
+ case $LINUXRELEASE in
+ 2.6.18*)
+ if test x$RHEL_KERNEL = xyes; then
+ LDISKFS_SERIES="2.6-rhel5-ext4.series"
+ fi
+ ;;
+ 2.6.32*)
+ if test x$RHEL_KERNEL = xyes; then
+ LDISKFS_SERIES="2.6-rhel6.series"
+ fi
+ if test x$SUSE_KERNEL = xyes; then
+ LDISKFS_SERIES="2.6-sles11.series"
+ fi
+ ;;
+ *)
+ AC_MSG_WARN([Unknown kernel version $LINUXRELEASE])
+ LDISKFS_SERIES=
+ ;;
+ esac
+ AC_MSG_RESULT([$LDISKFS_SERIES])
+else
+ LDISKFS_SERIES=
+fi
+AC_SUBST(LDISKFS_SERIES)
+])
+
+
+#
+# LDISKFS_AC_PATCH_PROGRAM
+#
+# Determine which program should be used to apply the patches to
+# the ext4 source code to produce the ldiskfs source code.
+#
+AC_DEFUN([LDISKFS_AC_PATCH_PROGRAM], [
+ AC_ARG_ENABLE([quilt],
+ [AC_HELP_STRING([--disable-quilt],
+ [disable use of quilt for ldiskfs])],
+ [AS_IF([test "x$enableval" = xno],
+ [use_quilt=no],
+ [use_quilt=maybe])],
+ [use_quilt=maybe]
+ )
+
+ AS_IF([test x$use_quilt = xmaybe], [
+ AC_PATH_PROG([quilt_avail], [quilt], [no])
+ AS_IF([test x$quilt_avail = xno], [
+ use_quilt=no
+ ], [
+ use_quilt=yes
+ ])
+ ])
+
+ AS_IF([test x$use_quilt = xno], [
+ AC_PATH_PROG([patch_avail], [patch], [no])
+ AS_IF([test x$patch_avail = xno], [
+ AC_MSG_ERROR([*** Need "quilt" or "patch" command])
+ ])
+ ])
+
+ AM_CONDITIONAL([USE_QUILT], [test x$use_quilt = xyes])
+])