Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / obdclass / class_hash.c
index 790d975..766e16d 100644 (file)
@@ -70,7 +70,7 @@ int lustre_hash_init(struct lustre_class_hash_body **hash_body_new,
 
         spin_lock_init(&hash_body->lchb_lock); /* initialize the body lock */
 
-        for(i =0 ; i < hash_body->lchb_hash_max_size; i++) {
+        for(i = 0 ; i < hash_body->lchb_hash_max_size; i++) {
                 /* initial the bucket lock and list_head */
                 INIT_HLIST_HEAD(&hash_body->lchb_hash_tables[i].lhb_head);
                 spin_lock_init(&hash_body->lchb_hash_tables[i].lhb_lock);
@@ -144,6 +144,7 @@ int lustre_hash_additem_unique(struct lustre_class_hash_body *hash_body,
         struct lustre_hash_operations *hop = hash_body->lchb_hash_operations;
         ENTRY;
 
+        LASSERT(hlist_unhashed(actual_hnode));
         hashent = hop->lustre_hashfn(hash_body, key);
 
         /* get the hash-bucket and lock it */
@@ -190,6 +191,8 @@ int lustre_hash_additem(struct lustre_class_hash_body *hash_body, void *key,
         struct lustre_hash_operations *hop = hash_body->lchb_hash_operations;
         ENTRY;
 
+        LASSERT(hlist_unhashed(actual_hnode));
+
         hashent = hop->lustre_hashfn(hash_body, key);
 
         /* get the hashbucket and lock it */
@@ -242,6 +245,7 @@ int lustre_hash_delitem_by_key(struct lustre_class_hash_body *hash_body,
                                                          key);
 
         if (hash_item == NULL) {
+                spin_unlock(&bucket->lhb_lock);
                 RETURN(-ENOENT);
         }
 
@@ -347,6 +351,8 @@ __u32 uuid_hashfn(struct lustre_class_hash_body *hash_body,  void * key)
         RETURN(hash);             
 }
 
+/* Note, it is impossible to find an export that is in failed state with
+ * this function */
 int uuid_hash_key_compare(void *key, struct hlist_node *compared_hnode)
 {
         struct obd_export *export = NULL;
@@ -360,7 +366,8 @@ int uuid_hash_key_compare(void *key, struct hlist_node *compared_hnode)
 
         compared_uuid = &export->exp_client_uuid;
 
-        RETURN(obd_uuid_equals(uuid_key, compared_uuid));
+        RETURN(obd_uuid_equals(uuid_key, compared_uuid) &&
+               !export->exp_failed);
 }
 
 void * uuid_export_refcount_get(struct hlist_node * actual_hnode)
@@ -407,29 +414,25 @@ struct lustre_hash_operations nid_hash_operations = {
 __u32 nid_hashfn(struct lustre_class_hash_body *hash_body,  void * key)
 {
         __u32 hash = 5381;
-        lnet_nid_t *nid_key = NULL;
-        int c;
-        char *ptr = NULL;
+        int i;
+        char *ptr = key;
 
         LASSERT(key != NULL); 
 
-        nid_key = (lnet_nid_t*)key;
-        ptr = libcfs_nid2str(*nid_key);
-
-        while ((c = *ptr++)) {
-                hash = hash * 33 + c;
-        }
+        for(i = 0 ; i < sizeof(lnet_nid_t) ; i ++)
+                hash = hash * 33 + ptr[i];
 
         hash &= (hash_body->lchb_hash_max_size - 1);
 
         RETURN(hash);             
 }
 
+/* Note, it is impossible to find an export that is in failed state with
+ * this function */
 int nid_hash_key_compare(void *key, struct hlist_node *compared_hnode)
 {
         struct obd_export *export = NULL;
         lnet_nid_t *nid_key = NULL;
-        int retval = 0;
 
         LASSERT( key != NULL);
 
@@ -437,13 +440,11 @@ int nid_hash_key_compare(void *key, struct hlist_node *compared_hnode)
 
         export = hlist_entry(compared_hnode, struct obd_export, exp_nid_hash);
 
-        if (strcmp(obd_export_nid2str(export), libcfs_nid2str(*nid_key)) == 0)
-                 retval = 1;
-
-        return retval;
+        return (export->exp_connection->c_peer.nid == *nid_key &&
+                !export->exp_failed);
 }
 
-void * nid_export_refcount_get(struct hlist_node * actual_hnode)
+void *nid_export_refcount_get(struct hlist_node *actual_hnode)
 {
         struct obd_export *export = NULL;
 
@@ -458,7 +459,7 @@ void * nid_export_refcount_get(struct hlist_node * actual_hnode)
         RETURN(export);
 }
 
-void nid_export_refcount_put(struct hlist_node * actual_hnode)
+void nid_export_refcount_put(struct hlist_node *actual_hnode)
 {
         struct obd_export *export = NULL;
 
@@ -488,18 +489,13 @@ EXPORT_SYMBOL(conn_hash_operations);
 __u32 conn_hashfn(struct lustre_class_hash_body *hash_body,  void * key)
 {
         __u32 hash = 5381;
-        lnet_process_id_t *conn_key = NULL;
-        char *ptr = NULL;
-        int c;
+        char *ptr = key;
+        int i;
 
         LASSERT(key != NULL); 
 
-        conn_key = (lnet_process_id_t*)key;
-        ptr = libcfs_id2str(*conn_key);
-
-        while ((c = *ptr++)) {
-                hash = hash * 33 + c;
-        }
+        for(i = 0 ; i < sizeof(lnet_process_id_t) ; i ++)
+                hash = hash * 33 + ptr[i];
 
         hash &= (hash_body->lchb_hash_max_size - 1);
 
@@ -510,7 +506,6 @@ int conn_hash_key_compare(void *key, struct hlist_node *compared_hnode)
 {
         struct ptlrpc_connection *c = NULL;
         lnet_process_id_t *conn_key = NULL;
-        int retval = 0;
 
         LASSERT( key != NULL);
 
@@ -518,14 +513,11 @@ int conn_hash_key_compare(void *key, struct hlist_node *compared_hnode)
 
         c = hlist_entry(compared_hnode, struct ptlrpc_connection, c_hash);
 
-        if (conn_key->nid == c->c_peer.nid &&
-            conn_key->pid == c->c_peer.pid)
-                 retval = 1;
-
-        return retval;
+        return (conn_key->nid == c->c_peer.nid &&
+                conn_key->pid == c->c_peer.pid);
 }
 
-void * conn_refcount_get(struct hlist_node * actual_hnode)
+void *conn_refcount_get(struct hlist_node *actual_hnode)
 {
         struct ptlrpc_connection *c = NULL;
 
@@ -540,7 +532,7 @@ void * conn_refcount_get(struct hlist_node * actual_hnode)
         RETURN(c);
 }
 
-void conn_refcount_put(struct hlist_node * actual_hnode)
+void conn_refcount_put(struct hlist_node *actual_hnode)
 {
         struct ptlrpc_connection *c = NULL;