+AC_DEFUN([LIBCFS_KTIME_GET_TS64],[
+LB_CHECK_COMPILE([does function 'ktime_get_ts64' exist],
+ktime_get_ts64, [
+ #include <linux/hrtimer.h>
+ #include <linux/ktime.h>
+],[
+ struct timespec64 *ts = NULL;
+
+ ktime_get_ts64(ts);
+],[
+ AC_DEFINE(HAVE_KTIME_GET_TS64, 1,
+ ['ktime_get_ts64' is available])
+])
+]) # LIBCFS_KTIME_GET_TS64
+
+#
+# Kernel version 3.12-rc4 commit c2d816443ef30 added prepare_to_wait_event()
+#
+AC_DEFUN([LIBCFS_PREPARE_TO_WAIT_EVENT],[
+LB_CHECK_COMPILE([does function 'prepare_to_wait_event' exist],
+prepare_to_wait_event, [
+ #include <linux/wait.h>
+],[
+ prepare_to_wait_event(NULL, NULL, 0);
+],[
+ AC_DEFINE(HAVE_PREPARE_TO_WAIT_EVENT, 1,
+ ['prepare_to_wait_event' is available])
+])
+]) # LIBCFS_PREPARE_TO_WAIT_EVENT
+
+#
+# Linux kernel 3.12 introduced struct kernel_param_ops
+# This has been backported to all lustre supported
+# clients except RHEL6. We have to handle the differences.
+#
+AC_DEFUN([LIBCFS_KERNEL_PARAM_OPS],[
+LB_CHECK_COMPILE([does 'struct kernel_param_ops' exist],
+kernel_param_ops, [
+ #include <linux/module.h>
+],[
+ struct kernel_param_ops ops;
+
+ ops.set = NULL;
+],[
+ AC_DEFINE(HAVE_KERNEL_PARAM_OPS, 1,
+ ['struct kernel_param_ops' is available])
+])
+]) # LIBCFS_KERNEL_PARAM_OPS
+
+#
+# Kernel version 3.12 introduced ktime_add
+#
+AC_DEFUN([LIBCFS_KTIME_ADD],[
+LB_CHECK_COMPILE([does function 'ktime_add' exist],
+ktime_add, [
+ #include <linux/hrtimer.h>
+ #include <linux/ktime.h>
+],[
+ ktime_t start = ktime_set(0, 0);
+ ktime_t end = start;
+ ktime_t total;
+
+ total = ktime_add(start, end);
+],[
+ AC_DEFINE(HAVE_KTIME_ADD, 1,
+ [ktime_add is available])
+])
+]) # LIBCFS_KTIME_ADD
+
+#
+# Kernel version 3.12 introduced ktime_after
+#
+AC_DEFUN([LIBCFS_KTIME_AFTER],[
+LB_CHECK_COMPILE([does function 'ktime_after' exist],
+ktime_after, [
+ #include <linux/hrtimer.h>
+ #include <linux/ktime.h>
+],[
+ ktime_t start = ktime_set(0, 0);
+ ktime_t end = start;
+
+ ktime_after(start, end);
+],[
+ AC_DEFINE(HAVE_KTIME_AFTER, 1,
+ [ktime_after is available])
+])
+]) # LIBCFS_KTIME_AFTER
+
+#
+# Kernel version 3.12 introduced ktime_before
+# See linux commit 67cb9366ff5f99868100198efba5ca88aaa6ad25
+#
+AC_DEFUN([LIBCFS_KTIME_BEFORE],[
+LB_CHECK_COMPILE([does function 'ktime_before' exist],
+ktime_before, [
+ #include <linux/hrtimer.h>
+ #include <linux/ktime.h>
+],[
+ ktime_t start = ktime_set(0, 0);
+ ktime_t end = start;
+
+ ktime_before(start, end);
+],[
+ AC_DEFINE(HAVE_KTIME_BEFORE, 1,
+ [ktime_before is available])
+])
+]) # LIBCFS_KTIME_BEFORE
+
+#
+# Kernel version 3.12 introduced ktime_compare
+#
+AC_DEFUN([LIBCFS_KTIME_COMPARE],[
+LB_CHECK_COMPILE([does function 'ktime_compare' exist],
+ktime_compare, [
+ #include <linux/hrtimer.h>
+ #include <linux/ktime.h>
+],[
+ ktime_t start = ktime_set(0, 0);
+ ktime_t end = start;
+
+ ktime_compare(start, end);
+],[
+ AC_DEFINE(HAVE_KTIME_COMPARE, 1,
+ [ktime_compare is available])
+])
+]) # LIBCFS_KTIME_COMPARE
+
+#
+# FC19 3.12 kernel struct shrinker change
+#
+AC_DEFUN([LIBCFS_SHRINKER_COUNT],[
+LB_CHECK_COMPILE([shrinker has 'count_objects'],
+shrinker_count_objects, [
+ #include <linux/mmzone.h>
+ #include <linux/shrinker.h>
+],[
+ struct shrinker shrinker;
+
+ shrinker.count_objects = NULL;
+],[
+ AC_DEFINE(HAVE_SHRINKER_COUNT, 1,
+ [shrinker has count_objects member])
+])
+]) # LIBCFS_SHRINKER_COUNT
+
+#
+# LIBCFS_IOV_ITER_HAS_TYPE
+#
+# kernel 3.15-rc4 commit 71d8e532b1549a478e6a6a8a44f309d050294d00
+# start adding the tag to iov_iter
+#
+AC_DEFUN([LIBCFS_IOV_ITER_HAS_TYPE], [
+tmp_flags="$EXTRA_KCFLAGS"
+EXTRA_KCFLAGS="-Werror"
+LB_CHECK_COMPILE([if iov_iter has member type],
+iov_iter_has_type_member, [
+ #include <linux/uio.h>
+],[
+ struct iov_iter iter = { .type = ITER_KVEC };
+ (void)iter;
+],[
+ AC_DEFINE(HAVE_IOV_ITER_HAS_TYPE_MEMBER, 1,
+ [if iov_iter has member type])
+])
+EXTRA_KCFLAGS="$tmp_flags"
+]) # LIBCFS_IOV_ITER_HAS_TYPE
+
+#
+# LIBCFS_HAVE_NS_TO_TIMESPEC64
+#
+# Kernel version 4.16-rc3 commit a84d1169164b274f13b97a23ff235c000efe3b49
+# introduced struct __kernel_old_timeval
+#
+AC_DEFUN([LIBCFS_HAVE_NS_TO_TIMESPEC64],[
+LB_CHECK_COMPILE([does 'ns_to_timespec64()' exist],
+kernel_old_timeval, [
+ #include <linux/time.h>
+],[
+ struct timespec64 kts;
+
+ kts = ns_to_timespec64(0);
+],[
+ AC_DEFINE(HAVE_NS_TO_TIMESPEC64, 1,
+ [ns_to_timespec64() is available])
+])
+]) # LIBCFS_HAVE_NS_TO_TIMESPEC64
+
+#
+# Kernel version 3.17 changed hlist_add_after to
+# hlist_add_behind
+#
+AC_DEFUN([LIBCFS_HLIST_ADD_AFTER],[
+LB_CHECK_COMPILE([does function 'hlist_add_after' exist],
+hlist_add_after, [
+ #include <linux/list.h>
+],[
+ hlist_add_after(NULL, NULL);
+],[
+ AC_DEFINE(HAVE_HLIST_ADD_AFTER, 1,
+ [hlist_add_after is available])
+])
+]) # LIBCFS_HLIST_ADD_AFTER
+
+#
+# Kernel version 3.17 introduced struct timespec64
+#
+AC_DEFUN([LIBCFS_TIMESPEC64],[
+LB_CHECK_COMPILE([does 'struct timespec64' exist],
+timespec64, [
+ #include <linux/time.h>
+],[
+ struct timespec64 ts;
+
+ ts.tv_sec = 0;
+ ts.tv_nsec = 0;
+],[
+ AC_DEFINE(HAVE_TIMESPEC64, 1,
+ ['struct timespec64' is available])
+])
+]) # LIBCFS_TIMESPEC64
+
+#
+# Kernel version 3.17 introduced ktime_get_real_ts64
+#
+AC_DEFUN([LIBCFS_KTIME_GET_REAL_TS64],[
+LB_CHECK_COMPILE([does function 'ktime_get_real_ts64' exist],
+ktime_get_real_ts64, [
+ #include <linux/ktime.h>
+],[
+ struct timespec64 *ts = NULL;
+
+ ktime_get_real_ts64(ts);
+],[
+ AC_DEFINE(HAVE_KTIME_GET_REAL_TS64, 1,
+ ['ktime_get_real_ts64' is available])
+])
+]) # LIBCFS_KTIME_GET_REAL_TS64
+
+#
+# Kernel version 3.17 introduced ktime_get_real_seconds
+#
+AC_DEFUN([LIBCFS_KTIME_GET_REAL_SECONDS],[
+LB_CHECK_COMPILE([does function 'ktime_get_real_seconds' exist],
+ktime_get_real_seconds, [
+ #include <linux/hrtimer.h>
+ #include <linux/ktime.h>
+],[
+ time64_t now;
+
+ now = ktime_get_real_seconds();
+],[
+ AC_DEFINE(HAVE_KTIME_GET_REAL_SECONDS, 1,
+ ['ktime_get_real_seconds' is available])
+])
+]) # LIBCFS_KTIME_GET_REAL_SECONDS
+
+#
+# Kernel version 3.17 created ktime_get_ns wrapper
+#
+AC_DEFUN([LIBCFS_KTIME_GET_NS],[
+LB_CHECK_COMPILE([does function 'ktime_get_ns' exist],
+ktime_get_ns, [
+ #include <linux/hrtimer.h>
+ #include <linux/ktime.h>
+],[
+ u64 nanoseconds;
+
+ nanoseconds = ktime_get_ns();
+],[],[
+ AC_DEFINE(NEED_KTIME_GET_NS, 1,
+ ['ktime_get_ns' is not available])
+])
+]) # LIBCFS_KTIME_GET_NS
+
+#
+# Kernel version 3.17 created ktime_get_real_ns wrapper
+#
+AC_DEFUN([LIBCFS_KTIME_GET_REAL_NS],[
+LB_CHECK_COMPILE([does function 'ktime_get_real_ns' exist],
+ktime_get_real_ns, [
+ #include <linux/hrtimer.h>
+ #include <linux/ktime.h>
+],[
+ u64 nanoseconds;
+
+ nanoseconds = ktime_get_real_ns();
+],[],[
+ AC_DEFINE(NEED_KTIME_GET_REAL_NS, 1,
+ ['ktime_get_real_ns' is not available])
+])
+]) # LIBCFS_KTIME_GET_REAL_NS
+
+#
+# Kernel version 3.17 introduced ktime_to_timespec64
+#
+AC_DEFUN([LIBCFS_KTIME_TO_TIMESPEC64],[
+LB_CHECK_COMPILE([does function 'ktime_to_timespec64' exist],
+ktime_to_timespec64, [
+ #include <linux/hrtimer.h>
+ #include <linux/ktime.h>
+],[
+ ktime_t now = ktime_set(0, 0);
+ struct timespec64 ts;
+
+ ts = ktime_to_timespec64(now);
+],[
+ AC_DEFINE(HAVE_KTIME_TO_TIMESPEC64, 1,
+ ['ktime_to_timespec64' is available])
+])
+]) # LIBCFS_KTIME_TO_TIMESPEC64
+
+#
+# Kernel version 3.17 introduced timespec64_sub
+#
+AC_DEFUN([LIBCFS_TIMESPEC64_SUB],[
+LB_CHECK_COMPILE([does function 'timespec64_sub' exist],
+timespec64_sub, [
+ #include <linux/time.h>
+],[
+ struct timespec64 later = { }, earlier = { }, diff;
+
+ diff = timespec64_sub(later, earlier);
+],[
+ AC_DEFINE(HAVE_TIMESPEC64_SUB, 1,
+ ['timespec64_sub' is available])
+])
+]) # LIBCFS_TIMESPEC64_SUB
+
+#
+# Kernel version 3.17 introduced timespec64_to_ktime
+#
+AC_DEFUN([LIBCFS_TIMESPEC64_TO_KTIME],[
+LB_CHECK_COMPILE([does function 'timespec64_to_ktime' exist],
+timespec64_to_ktime, [
+ #include <linux/ktime.h>
+],[
+ struct timespec64 ts;
+ ktime_t now;
+
+ now = timespec64_to_ktime(ts);
+],[
+ AC_DEFINE(HAVE_TIMESPEC64_TO_KTIME, 1,
+ ['timespec64_to_ktime' is available])
+])
+]) # LIBCFS_TIMESPEC64_TO_KTIME
+
+#
+# Kernel version 3.19 introduced ktime_get_seconds
+#
+AC_DEFUN([LIBCFS_KTIME_GET_SECONDS],[
+LB_CHECK_COMPILE([does function 'ktime_get_seconds' exist],
+ktime_get_seconds, [
+ #include <linux/ktime.h>
+],[
+ time64_t now;
+
+ now = ktime_get_seconds();
+],[
+ AC_DEFINE(HAVE_KTIME_GET_SECONDS, 1,
+ ['ktime_get_seconds' is available])
+])
+]) # LIBCFS_KTIME_GET_SECONDS
+
+#
+# Kernel version 4.0 commit 41fbf3b39d5eca01527338b4d0ee15ee1ae1023c
+# introduced the helper function ktime_ms_delta.
+#
+AC_DEFUN([LIBCFS_KTIME_MS_DELTA],[
+LB_CHECK_COMPILE([does function 'ktime_ms_delta' exist],
+ktime_ms_delta, [
+ #include <linux/ktime.h>
+],[
+ ktime_t start = ktime_set(0, 0);
+ ktime_t end = start;
+
+ ktime_ms_delta(start, end);
+],[
+ AC_DEFINE(HAVE_KTIME_MS_DELTA, 1,
+ ['ktime_ms_delta' is available])
+])
+]) # LIBCFS_KTIME_MS_DELTA
+
+#
+# Kernel version 4.1 commit b51d23e4e9fea6f264d39535c2a62d1f51e7ccc3
+# create per module locks which added kernel_param_[un]lock(). Older
+# kernels you have to use __kernel_param_[un]lock(). In that case its
+# a global lock for all modules but that is okay since its a rare event.
+#
+AC_DEFUN([LIBCFS_KERNEL_PARAM_LOCK],[
+LB_CHECK_COMPILE([does function 'kernel_param_[un]lock' exist],
+kernel_param_lock, [
+ #include <linux/moduleparam.h>
+],[
+ kernel_param_lock(NULL);
+ kernel_param_unlock(NULL);
+],[
+ AC_DEFINE(HAVE_KERNEL_PARAM_LOCK, 1,
+ ['kernel_param_[un]lock' is available])
+])
+]) # LIBCFS_KERNEL_PARAM_LOCK
+
+#
+# Kernel version 4.2 changed topology_thread_cpumask
+# to topology_sibling_cpumask
+#
+AC_DEFUN([LIBCFS_HAVE_TOPOLOGY_SIBLING_CPUMASK],[
+LB_CHECK_COMPILE([does function 'topology_sibling_cpumask' exist],
+topology_sibling_cpumask, [
+ #include <linux/topology.h>
+],[
+ const struct cpumask *mask;
+
+ mask = topology_sibling_cpumask(0);
+],[
+ AC_DEFINE(HAVE_TOPOLOGY_SIBLING_CPUMASK, 1,
+ [topology_sibling_cpumask is available])
+])
+]) # LIBCFS_HAVE_TOPOLOGY_SIBLING_CPUMASK
+
+#
+# Kernel version 4.4 commit ef951599074ba4fad2d0efa0a977129b41e6d203
+# introduced kstrtobool and kstrtobool_from_user.
+#
+AC_DEFUN([LIBCFS_KSTRTOBOOL_FROM_USER], [
+LB_CHECK_COMPILE([if Linux kernel has 'kstrtobool_from_user'],
+kstrtobool_from_user, [
+ #include <linux/kernel.h>
+],[
+ bool result;
+ return kstrtobool_from_user(NULL, 0, &result);
+],[
+ AC_DEFINE(HAVE_KSTRTOBOOL_FROM_USER, 1,
+ [kernel has kstrtobool_from_user])
+])
+]) # LIBCFS_KSTRTOBOOL_FROM_USER
+
+#
+# Kernel version 4.5-rc1 commit d12481bc58fba89427565f8592e88446ec084a24
+# added crypto hash helpers
+#
+AC_DEFUN([LIBCFS_CRYPTO_HASH_HELPERS], [
+LB_CHECK_COMPILE([does crypto hash helper functions exist],
+crypto_hash_helpers, [
+ #include <crypto/hash.h>
+],[
+ crypto_ahash_alg_name(NULL);
+ crypto_ahash_driver_name(NULL);
+],[
+ AC_DEFINE(HAVE_CRYPTO_HASH_HELPERS, 1,
+ [crypto hash helper functions are available])
+])
+]) # LIBCFS_CRYPTO_HASH_HELPERS
+
+#
+# Kernel version 4.5-rc1 commit 3502cad73c4bbf8f6365d539e814159275252c59
+# introduced rhashtable_replace_fast
+#
+AC_DEFUN([LIBCFS_RHASHTABLE_REPLACE], [
+LB_CHECK_COMPILE([if 'rhashtable_replace_fast' exists],
+rhashtable_replace_fast, [
+ #include <linux/rhashtable.h>
+],[
+ const struct rhashtable_params params = { 0 };
+
+ rhashtable_replace_fast(NULL, NULL, NULL, params);
+],[
+ AC_DEFINE(HAVE_RHASHTABLE_REPLACE, 1,
+ [rhashtable_replace_fast() is available])
+])
+]) # LIBCFS_RHASHTABLE_REPLACE
+
+#
+# Kernel version 4.5-rc3 commit 2fe829aca9d7bed5fd6b49c6a1452e5e486b6cc3dd
+# made kset_find_obj() exportable to modules
+#
+AC_DEFUN([LIBCFS_EXPORT_KSET_FIND_OBJ], [
+LB_CHECK_EXPORT([kset_find_obj], [lib/kobject.c],
+ [AC_DEFINE(HAVE_KSET_FIND_OBJ, 1,
+ [kset_find_obj is exported by the kernel])])
+]) # LIBCFS_EXPORT_KSET_FIND_OBJ
+
+#
+# Kernel version 4.6+ commit ef703f49a6c5b909a85149bb6625c4ed0d697186
+# fixed the brokenness of hash_64(). The fix removed GOLDEN_RATIO_PRIME_64
+# since it was a poor prime value.