class_hash.c

来自「lustre 1.6.5 source code」· C语言 代码 · 共 757 行 · 第 1/2 页

C
757
字号
#endif                spin_lock(&bucket->lhb_lock); /* lock the bucket */                hlist_for_each_safe(actual_hnode, pos, &(bucket->lhb_head)) {                        obj = hop->lustre_hash_object_refcount_get(actual_hnode);                        func(obj, data);                        hop->lustre_hash_object_refcount_put(actual_hnode);                }                spin_unlock(&bucket->lhb_lock);        }        EXIT;}EXPORT_SYMBOL(lustre_hash_iterate_all);void * lustre_hash_get_object_by_key(struct lustre_class_hash_body *hash_body,                                     void *key){        int hashent ;        struct hlist_node * hash_item_hnode = NULL;        void * obj_value = NULL;        struct lustre_hash_bucket *bucket = NULL;        struct lustre_hash_operations * hop = hash_body->lchb_hash_operations;        ENTRY;        /* get the hash value from the given item */        hashent = hop->lustre_hashfn(hash_body, key);        bucket = &hash_body->lchb_hash_tables[hashent];        spin_lock(&bucket->lhb_lock); /* lock the bucket */        hash_item_hnode = lustre_hash_getitem_in_bucket_nolock(hash_body,                                                                hashent, key);        if (hash_item_hnode == NULL) {                spin_unlock(&bucket->lhb_lock); /* lock the bucket */                RETURN(NULL);        }        obj_value = hop->lustre_hash_object_refcount_get(hash_item_hnode);        spin_unlock(&bucket->lhb_lock); /* lock the bucket */        RETURN(obj_value);}EXPORT_SYMBOL(lustre_hash_get_object_by_key);/* string hashing using djb2 hash algorithm */__u32 djb2_hashfn(struct lustre_class_hash_body *hash_body,  void* key,                   size_t size){        __u32 hash = 5381;        int i;        char *ptr = key;        LASSERT(key != NULL);        for (i=0; i<size; i++)                 hash = hash * 33 + ptr[i];        hash &= (hash_body->lchb_hash_max_size - 1);        RETURN(hash);}/* * define (uuid <-> export) hash operations and function define *//* define the uuid hash operations */struct lustre_hash_operations uuid_hash_operations = {        .lustre_hashfn = uuid_hashfn,        .lustre_hash_key_compare = uuid_hash_key_compare,        .lustre_hash_object_refcount_get = uuid_export_refcount_get,        .lustre_hash_object_refcount_put = uuid_export_refcount_put,};__u32 uuid_hashfn(struct lustre_class_hash_body *hash_body,  void * key){        struct obd_uuid * uuid_key = key;        return djb2_hashfn(hash_body, uuid_key->uuid, sizeof(uuid_key->uuid));}/* 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;        struct obd_uuid *uuid_key = NULL, *compared_uuid = NULL;        LASSERT( key != NULL);        uuid_key = (struct obd_uuid*)key;        export = hlist_entry(compared_hnode, struct obd_export, exp_uuid_hash);        compared_uuid = &export->exp_client_uuid;        RETURN(obd_uuid_equals(uuid_key, compared_uuid) &&               !export->exp_failed);}void * uuid_export_refcount_get(struct hlist_node * actual_hnode){        struct obd_export *export = NULL;        LASSERT(actual_hnode != NULL);        export = hlist_entry(actual_hnode, struct obd_export, exp_uuid_hash);        LASSERT(export != NULL);        class_export_get(export);        RETURN(export);}void uuid_export_refcount_put(struct hlist_node * actual_hnode){        struct obd_export *export = NULL;        LASSERT(actual_hnode != NULL);        export = hlist_entry(actual_hnode, struct obd_export, exp_uuid_hash);        LASSERT(export != NULL);        class_export_put(export);}/* * define (nid <-> export) hash operations and function define *//* define the nid hash operations */struct lustre_hash_operations nid_hash_operations = {        .lustre_hashfn = nid_hashfn,        .lustre_hash_key_compare = nid_hash_key_compare,        .lustre_hash_object_refcount_get = nid_export_refcount_get,        .lustre_hash_object_refcount_put = nid_export_refcount_put,};__u32 nid_hashfn(struct lustre_class_hash_body *hash_body,  void * key){        return djb2_hashfn(hash_body, key, sizeof(lnet_nid_t));}/* 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;        LASSERT( key != NULL);        nid_key = (lnet_nid_t*)key;        export = hlist_entry(compared_hnode, struct obd_export, exp_nid_hash);        return (export->exp_connection->c_peer.nid == *nid_key &&                !export->exp_failed);}void *nid_export_refcount_get(struct hlist_node *actual_hnode){        struct obd_export *export = NULL;        LASSERT(actual_hnode != NULL);        export = hlist_entry(actual_hnode, struct obd_export, exp_nid_hash);        LASSERT(export != NULL);        class_export_get(export);        RETURN(export);}void nid_export_refcount_put(struct hlist_node *actual_hnode){        struct obd_export *export = NULL;        LASSERT(actual_hnode != NULL);        export = hlist_entry(actual_hnode, struct obd_export, exp_nid_hash);        LASSERT(export != NULL);        class_export_put(export);}/* * define (net_peer <-> connection) hash operations and function define *//* define the conn hash operations */struct lustre_hash_operations conn_hash_operations = {        .lustre_hashfn = conn_hashfn,        .lustre_hash_key_compare = conn_hash_key_compare,        .lustre_hash_object_refcount_get = conn_refcount_get,        .lustre_hash_object_refcount_put = conn_refcount_put,};EXPORT_SYMBOL(conn_hash_operations);__u32 conn_hashfn(struct lustre_class_hash_body *hash_body,  void * key){        return djb2_hashfn(hash_body, key, sizeof(lnet_process_id_t));}int conn_hash_key_compare(void *key, struct hlist_node *compared_hnode){        struct ptlrpc_connection *c = NULL;        lnet_process_id_t *conn_key = NULL;        LASSERT( key != NULL);        conn_key = (lnet_process_id_t*)key;        c = hlist_entry(compared_hnode, struct ptlrpc_connection, c_hash);        return (conn_key->nid == c->c_peer.nid &&                conn_key->pid == c->c_peer.pid);}void *conn_refcount_get(struct hlist_node *actual_hnode){        struct ptlrpc_connection *c = NULL;        LASSERT(actual_hnode != NULL);        c = hlist_entry(actual_hnode, struct ptlrpc_connection, c_hash);        LASSERT(c != NULL);        atomic_inc(&c->c_refcount);        RETURN(c);}void conn_refcount_put(struct hlist_node *actual_hnode){        struct ptlrpc_connection *c = NULL;        LASSERT(actual_hnode != NULL);        c = hlist_entry(actual_hnode, struct ptlrpc_connection, c_hash);        LASSERT(c != NULL);        atomic_dec(&c->c_refcount);}/*******************************************************************************//* ( nid<>nidstats ) hash operations define */struct lustre_hash_operations nid_stat_hash_operations = {        .lustre_hashfn = nid_hashfn,        .lustre_hash_key_compare = nidstats_hash_key_compare,        .lustre_hash_object_refcount_get = nidstats_refcount_get,        .lustre_hash_object_refcount_put = nidstats_refcount_put,};EXPORT_SYMBOL(nid_stat_hash_operations);int nidstats_hash_key_compare(void *key, struct hlist_node * compared_hnode){        struct nid_stat *data;        lnet_nid_t *nid_key;        LASSERT( key != NULL);        nid_key = (lnet_nid_t*)key;        data = hlist_entry(compared_hnode, struct nid_stat, nid_hash);        return (data->nid == *nid_key);}void* nidstats_refcount_get(struct hlist_node * actual_hnode){        struct nid_stat *data;        data = hlist_entry(actual_hnode, struct nid_stat, nid_hash);        data->nid_exp_ref_count++;        RETURN(data);}void nidstats_refcount_put(struct hlist_node * actual_hnode){        struct nid_stat *data;        data = hlist_entry(actual_hnode, struct nid_stat, nid_hash);        data->nid_exp_ref_count--;}/*******************************************************************************/#ifdef __KERNEL__/* * define ( lqs <-> qctxt ) hash operations and function define *//* define the conn hash operations */struct lustre_hash_operations lqs_hash_operations = {        .lustre_hashfn = lqs_hashfn,        .lustre_hash_key_compare = lqs_hash_key_compare,        .lustre_hash_object_refcount_get = lqs_refcount_get,        .lustre_hash_object_refcount_put = lqs_refcount_put,};EXPORT_SYMBOL(lqs_hash_operations);/* string hashing using djb2 hash algorithm */__u32 lqs_hashfn(struct lustre_class_hash_body *hash_body,  void * key){        struct quota_adjust_qunit *lqs_key = NULL;        __u32 hash;        LASSERT(key != NULL);        lqs_key = (struct quota_adjust_qunit *)key;        hash = QAQ_IS_GRP(lqs_key) ? 5381 : 5387;        hash *= lqs_key->qaq_id;        hash &= (hash_body->lchb_hash_max_size - 1);        RETURN(hash);}int lqs_hash_key_compare(void *key, struct hlist_node *compared_hnode){        struct quota_adjust_qunit *lqs_key = NULL;        struct lustre_qunit_size *q = NULL;        int retval = 0;        LASSERT( key != NULL);        lqs_key = (struct quota_adjust_qunit *)key;        q = hlist_entry(compared_hnode, struct lustre_qunit_size, lqs_hash);        spin_lock(&q->lqs_lock);        if (lqs_key->qaq_id == q->lqs_id && QAQ_IS_GRP(lqs_key) == LQS_IS_GRP(q))                 retval = 1;        spin_unlock(&q->lqs_lock);        return retval;}void * lqs_refcount_get(struct hlist_node * actual_hnode){        struct lustre_qunit_size *q = NULL;        LASSERT(actual_hnode != NULL);        q = hlist_entry(actual_hnode, struct lustre_qunit_size, lqs_hash);        LASSERT(q != NULL);        lqs_getref(q);        RETURN(q);}void lqs_refcount_put(struct hlist_node * actual_hnode){        struct lustre_qunit_size *q = NULL;        LASSERT(actual_hnode != NULL);        q = hlist_entry(actual_hnode, struct lustre_qunit_size, lqs_hash);        LASSERT(q != NULL);        lqs_putref(q);}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?