Whamcloud - gitweb
LU-3778 sptlrpc: OSP and LWP don't know sptlrpc
[fs/lustre-release.git] / lustre / ptlrpc / nodemap_handler.c
index 4648514..7445c94 100644 (file)
@@ -21,6 +21,9 @@
  */
 /*
  * Copyright (C) 2013, Trustees of Indiana University
+ *
+ * Copyright (c) 2014, Intel Corporation.
+ *
  * Author: Joshua Walgenbach <jjw@iu.edu>
  */
 #include <linux/module.h>
@@ -63,7 +66,7 @@ rwlock_t nm_range_tree_lock;
  * Hash keyed on nodemap name containing all
  * nodemaps
  */
-static cfs_hash_t *nodemap_hash;
+static struct cfs_hash *nodemap_hash;
 
 /**
  * Nodemap destructor
@@ -111,7 +114,7 @@ void nodemap_putref(struct lu_nodemap *nodemap)
                nodemap_destroy(nodemap);
 }
 
-static __u32 nodemap_hashfn(cfs_hash_t *hash_body,
+static __u32 nodemap_hashfn(struct cfs_hash *hash_body,
                            const void *key, unsigned mask)
 {
        return cfs_hash_djb2_hash(key, strlen(key), mask);
@@ -141,7 +144,7 @@ static void *nodemap_hs_hashobject(struct hlist_node *hnode)
        return hlist_entry(hnode, struct lu_nodemap, nm_hash);
 }
 
-static void nodemap_hs_get(cfs_hash_t *hs, struct hlist_node *hnode)
+static void nodemap_hs_get(struct cfs_hash *hs, struct hlist_node *hnode)
 {
        struct lu_nodemap *nodemap;
 
@@ -149,7 +152,7 @@ static void nodemap_hs_get(cfs_hash_t *hs, struct hlist_node *hnode)
        nodemap_getref(nodemap);
 }
 
-static void nodemap_hs_put_locked(cfs_hash_t *hs,
+static void nodemap_hs_put_locked(struct cfs_hash *hs,
                                  struct hlist_node *hnode)
 {
        struct lu_nodemap *nodemap;
@@ -158,7 +161,7 @@ static void nodemap_hs_put_locked(cfs_hash_t *hs,
        nodemap_putref(nodemap);
 }
 
-static cfs_hash_ops_t nodemap_hash_operations = {
+static struct cfs_hash_ops nodemap_hash_operations = {
        .hs_hash        = nodemap_hashfn,
        .hs_key         = nodemap_hs_key,
        .hs_keycmp      = nodemap_hs_keycmp,
@@ -170,20 +173,21 @@ static cfs_hash_ops_t nodemap_hash_operations = {
 /* end of cfs_hash functions */
 
 /**
- * Helper iterator to clean up nodemap on module exit.
+ * Helper iterator to convert nodemap hash to list.
  *
- * \param      hs              hash structure
- * \param      bd              bucket descriptor
- * \param      hnode           hash node
- * \param      data            not used here
+ * \param      hs                      hash structure
+ * \param      bd                      bucket descriptor
+ * \param      hnode                   hash node
+ * \param      nodemap_list_head       list head for list of nodemaps in hash
  */
-static int nodemap_cleanup_iter_cb(cfs_hash_t *hs, cfs_hash_bd_t *bd,
-                                  struct hlist_node *hnode, void *data)
+static int nodemap_cleanup_iter_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
+                                  struct hlist_node *hnode,
+                                  void *nodemap_list_head)
 {
-       struct lu_nodemap *nodemap;
+       struct lu_nodemap       *nodemap;
 
        nodemap = hlist_entry(hnode, struct lu_nodemap, nm_hash);
-       nodemap_putref(nodemap);
+       list_add(&nodemap->nm_list, (struct list_head *)nodemap_list_head);
 
        return 0;
 }
@@ -193,8 +197,21 @@ static int nodemap_cleanup_iter_cb(cfs_hash_t *hs, cfs_hash_bd_t *bd,
  */
 void nodemap_cleanup_all(void)
 {
-       cfs_hash_for_each_safe(nodemap_hash, nodemap_cleanup_iter_cb, NULL);
+       struct lu_nodemap *nodemap = NULL;
+       struct list_head *pos, *next;
+       struct list_head nodemap_list_head = LIST_HEAD_INIT(nodemap_list_head);
+
+       cfs_hash_for_each_safe(nodemap_hash, nodemap_cleanup_iter_cb,
+                              &nodemap_list_head);
        cfs_hash_putref(nodemap_hash);
+
+       /* Because nodemap_destroy might sleep, we can't destroy them
+        * in cfs_hash_for_each. Instead we build a list and destroy here
+        */
+       list_for_each_safe(pos, next, &nodemap_list_head) {
+               nodemap = list_entry(pos, struct lu_nodemap, nm_list);
+               nodemap_putref(nodemap);
+       }
 }
 
 /**
@@ -760,6 +777,7 @@ static int nodemap_create(const char *name, bool is_default)
        }
 
        INIT_LIST_HEAD(&nodemap->nm_ranges);
+       INIT_LIST_HEAD(&nodemap->nm_list);
 
        rwlock_init(&nodemap->nm_idmap_lock);
        nodemap->nm_fs_to_client_uidmap = RB_ROOT;
@@ -1016,7 +1034,7 @@ cleanup:
        return rc;
 }
 
-static int nm_member_revoke_all_cb(cfs_hash_t *hs, cfs_hash_bd_t *bd,
+static int nm_member_revoke_all_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
                                   struct hlist_node *hnode, void *data)
 {
        struct lu_nodemap *nodemap;