Whamcloud - gitweb
LU-9859 libcfs: initialize bit_wait_table
[fs/lustre-release.git] / libcfs / libcfs / module.c
index dba4bab..b0e9c94 100644 (file)
@@ -53,6 +53,7 @@
 
 #include <libcfs/libcfs.h>
 #include <libcfs/libcfs_crypto.h>
+#include <libcfs/linux/linux-fs.h>
 #include <lnet/lib-lnet.h>
 #include "tracefile.h"
 
@@ -109,9 +110,8 @@ int libcfs_ioctl(unsigned long cmd, void __user *uparam)
                        err = -EINVAL;
                else
                        err = notifier_to_errno(err);
-               if (!err)
-                       if (copy_to_user(uparam, hdr, hdr->ioc_len))
-                               err = -EFAULT;
+               if (copy_to_user(uparam, hdr, hdr->ioc_len) && !err)
+                       err = -EFAULT;
                break;
        }
 out:
@@ -548,8 +548,7 @@ static const struct file_operations *lnet_debugfs_fops_select(umode_t mode)
        return &lnet_debugfs_file_operations_rw;
 }
 
-void lnet_insert_debugfs(struct ctl_table *table,
-                        const struct lnet_debugfs_symlink_def *symlinks)
+void lnet_insert_debugfs(struct ctl_table *table)
 {
        if (!lnet_debugfs_root)
                lnet_debugfs_root = debugfs_create_dir("lnet", NULL);
@@ -565,24 +564,62 @@ void lnet_insert_debugfs(struct ctl_table *table,
                debugfs_create_file(table->procname, table->mode,
                                    lnet_debugfs_root, table,
                                    lnet_debugfs_fops_select(table->mode));
+}
+EXPORT_SYMBOL_GPL(lnet_insert_debugfs);
 
+static void lnet_insert_debugfs_links(
+               const struct lnet_debugfs_symlink_def *symlinks)
+{
        for (; symlinks && symlinks->name; symlinks++)
                debugfs_create_symlink(symlinks->name, lnet_debugfs_root,
                                       symlinks->target);
 }
-EXPORT_SYMBOL_GPL(lnet_insert_debugfs);
 
-static void lnet_remove_debugfs(void)
+#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)
 {
-       debugfs_remove_recursive(lnet_debugfs_root);
+       /*
+        * 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
 
-       lnet_debugfs_root = NULL;
+void lnet_remove_debugfs(struct ctl_table *table)
+{
+       for (; table && table->procname; table++) {
+               struct qstr dname = QSTR_INIT(table->procname,
+                                             strlen(table->procname));
+               struct dentry *dentry;
+
+               dentry = d_hash_and_lookup(lnet_debugfs_root, &dname);
+               debugfs_remove(dentry);
+       }
 }
+EXPORT_SYMBOL_GPL(lnet_remove_debugfs);
 
 static int __init libcfs_init(void)
 {
        int rc;
 
+#ifndef HAVE_WAIT_VAR_EVENT
+       wait_bit_init();
+#endif
        rc = libcfs_debug_init(5 * 1024 * 1024);
        if (rc < 0) {
                printk(KERN_ERR "LustreError: libcfs_debug_init: %d\n", rc);
@@ -620,7 +657,9 @@ static int __init libcfs_init(void)
                goto cleanup_wi;
        }
 
-       lnet_insert_debugfs(lnet_table, lnet_debugfs_symlinks);
+       lnet_insert_debugfs(lnet_table);
+       if (!IS_ERR_OR_NULL(lnet_debugfs_root))
+               lnet_insert_debugfs_links(lnet_debugfs_symlinks);
 
        CDEBUG (D_OTHER, "portals setup OK\n");
        return 0;
@@ -639,7 +678,9 @@ static void __exit libcfs_exit(void)
 {
        int rc;
 
-       lnet_remove_debugfs();
+       /* Remove everthing */
+       debugfs_remove_recursive(lnet_debugfs_root);
+       lnet_debugfs_root = NULL;
 
        CDEBUG(D_MALLOC, "before Portals cleanup: kmem %d\n",
               atomic_read(&libcfs_kmemory));