From fa72fe50b9b4ee8ca2165607e32360a6bebd86e4 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Thu, 7 May 2020 05:19:58 -0600 Subject: [PATCH] LU-11986 libcfs: add compat for d_hash_and_lookup() Add compatibility for older kernels that do not export the d_hash_and_lookup() function, even though it exists forever. Fixes: 9d42660e173e ("LU-11986 lnet: properly cleanup lnet debugfs files") Test-Parameters: trivial Signed-off-by: Andreas Dilger Change-Id: I10d6547f6b17665880cacfbf87d4dbfd386b92ff Reviewed-on: https://review.whamcloud.com/38529 Reviewed-by: Shaun Tancheff Tested-by: jenkins Reviewed-by: James Simmons Tested-by: Maloo Reviewed-by: Oleg Drokin --- libcfs/autoconf/lustre-libcfs.m4 | 11 +++++++++++ libcfs/libcfs/module.c | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 08e49d0..b4d208f 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -256,6 +256,16 @@ AS_IF([test "x$enable_crc32c_crypto" = xyes], [ ]) # LIBCFS_ENABLE_CRC32C_ACCEL # +# Kernel version v3.8-rc4-82-g4f522a247bc2 exported d_hash_and_lookup() +# It was added in v2.6.16-3821-g3e7e241f8c5c, so no worries about header. +# +AC_DEFUN([LIBCFS_D_HASH_AND_LOOKUP],[ +LB_CHECK_EXPORT([d_hash_and_lookup], [fs/dcache.c], + [AC_DEFINE(HAVE_D_HASH_AND_LOOKUP, 1, + [d_hash_and_lookup is exported by the kernel])]) +]) # LIBCFS_D_HASH_AND_LOOKUP + +# # Kernel version 3.11 introduced ktime_get_ts64 # AC_DEFUN([LIBCFS_KTIME_GET_TS64],[ @@ -1050,6 +1060,7 @@ LIBCFS_PROCESS_NAMESPACE LIBCFS_I_UID_READ # 3.8 LIBCFS_HAVE_CRC32 +LIBCFS_D_HASH_AND_LOOKUP LIBCFS_ENABLE_CRC32_ACCEL # 3.10 LIBCFS_ENABLE_CRC32C_ACCEL diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index 208565c..ebbf85e 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -575,6 +575,31 @@ static void lnet_insert_debugfs_links( symlinks->target); } +#ifndef HAVE_D_HASH_AND_LOOKUP +/** + * d_hash_and_lookup - hash the qstr then search for a dentry + * @dir: Directory to search in + * @name: qstr of name we wish to find + * + * On lookup failure NULL is returned; on bad name - ERR_PTR(-error) + */ +struct dentry *d_hash_and_lookup(struct dentry *dir, struct qstr *name) +{ + /* + * Check for a fs-specific hash function. Note that we must + * calculate the standard hash first, as the d_op->d_hash() + * routine may choose to leave the hash value unchanged. + */ + name->hash = full_name_hash(name->name, name->len); + if (dir->d_op && dir->d_op->d_hash) { + int err = dir->d_op->d_hash(dir, name); + if (unlikely(err < 0)) + return ERR_PTR(err); + } + return d_lookup(dir, name); +} +#endif + void lnet_remove_debugfs(struct ctl_table *table) { for (; table && table->procname; table++) { -- 1.8.3.1