Whamcloud - gitweb
LU-11986 libcfs: add compat for d_hash_and_lookup() 29/38529/4
authorAndreas Dilger <adilger@whamcloud.com>
Thu, 7 May 2020 11:19:58 +0000 (05:19 -0600)
committerOleg Drokin <green@whamcloud.com>
Mon, 11 May 2020 23:02:31 +0000 (23:02 +0000)
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 <adilger@whamcloud.com>
Change-Id: I10d6547f6b17665880cacfbf87d4dbfd386b92ff
Reviewed-on: https://review.whamcloud.com/38529
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/autoconf/lustre-libcfs.m4
libcfs/libcfs/module.c

index 08e49d0..b4d208f 100644 (file)
@@ -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
index 208565c..ebbf85e 100644 (file)
@@ -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++) {