Changeset 062d900 in mainline for uspace/srv/vfs/vfs_node.c


Ignore:
Timestamp:
2012-10-09T11:49:43Z (12 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4e00f87
Parents:
87e9392
git-author:
Adam Hraska <adam.hraska+hos@…> (2012-10-09 11:49:43)
git-committer:
Jakub Jermar <jakub@…> (2012-10-09 11:49:43)
Message:

Cherrypick userspace hash table changes from lp:~adam-hraska+lp/helenos/rcu/.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs_node.c

    r87e9392 r062d900  
    4141#include <fibril_synch.h>
    4242#include <adt/hash_table.h>
     43#include <adt/hash.h>
    4344#include <assert.h>
    4445#include <async.h>
     
    5859#define KEY_INDEX       2
    5960
    60 static hash_index_t nodes_hash(unsigned long []);
    61 static int nodes_compare(unsigned long [], hash_count_t, link_t *);
    62 static void nodes_remove_callback(link_t *);
     61static size_t nodes_key_hash(void *);
     62static size_t nodes_hash(const ht_link_t *);
     63static bool nodes_key_equal(void *, const ht_link_t *);
     64static vfs_triplet_t node_triplet(vfs_node_t *node);
    6365
    6466/** VFS node hash table operations. */
    65 hash_table_operations_t nodes_ops = {
     67hash_table_ops_t nodes_ops = {
    6668        .hash = nodes_hash,
    67         .compare = nodes_compare,
    68         .remove_callback = nodes_remove_callback
     69        .key_hash = nodes_key_hash,
     70        .key_equal = nodes_key_equal,
     71        .equal = 0,
     72        .remove_callback = 0,
    6973};
    7074
     
    7579bool vfs_nodes_init(void)
    7680{
    77         return hash_table_create(&nodes, NODES_BUCKETS, 3, &nodes_ops);
     81        return hash_table_create(&nodes, 0, 0, &nodes_ops);
    7882}
    7983
     
    114118                 */
    115119               
    116                 unsigned long key[] = {
    117                         [KEY_FS_HANDLE] = node->fs_handle,
    118                         [KEY_DEV_HANDLE] = node->service_id,
    119                         [KEY_INDEX] = node->index
    120                 };
    121                
    122                 hash_table_remove(&nodes, key, 3);
     120                hash_table_remove_item(&nodes, &node->nh_link);
    123121                free_vfs_node = true;
    124122               
     
    158156{
    159157        fibril_mutex_lock(&nodes_mutex);
    160         unsigned long key[] = {
    161                 [KEY_FS_HANDLE] = node->fs_handle,
    162                 [KEY_DEV_HANDLE] = node->service_id,
    163                 [KEY_INDEX] = node->index
    164         };
    165         hash_table_remove(&nodes, key, 3);
     158        hash_table_remove_item(&nodes, &node->nh_link);
    166159        fibril_mutex_unlock(&nodes_mutex);
    167160        free(node);
     
    182175vfs_node_t *vfs_node_get(vfs_lookup_res_t *result)
    183176{
    184         unsigned long key[] = {
    185                 [KEY_FS_HANDLE] = result->triplet.fs_handle,
    186                 [KEY_DEV_HANDLE] = result->triplet.service_id,
    187                 [KEY_INDEX] = result->triplet.index
    188         };
    189         link_t *tmp;
    190177        vfs_node_t *node;
    191178
    192179        fibril_mutex_lock(&nodes_mutex);
    193         tmp = hash_table_find(&nodes, key);
     180        ht_link_t *tmp = hash_table_find(&nodes, &result->triplet);
    194181        if (!tmp) {
    195182                node = (vfs_node_t *) malloc(sizeof(vfs_node_t));
     
    205192                node->lnkcnt = result->lnkcnt;
    206193                node->type = result->type;
    207                 link_initialize(&node->nh_link);
    208194                fibril_rwlock_initialize(&node->contents_rwlock);
    209                 hash_table_insert(&nodes, key, &node->nh_link);
     195                hash_table_insert(&nodes, &node->nh_link);
    210196        } else {
    211                 node = hash_table_get_instance(tmp, vfs_node_t, nh_link);
     197                node = hash_table_get_inst(tmp, vfs_node_t, nh_link);
    212198                if (node->type == VFS_NODE_UNKNOWN &&
    213199                    result->type != VFS_NODE_UNKNOWN) {
     
    240226}
    241227
    242 hash_index_t nodes_hash(unsigned long key[])
    243 {
    244         hash_index_t a = key[KEY_FS_HANDLE] << (NODES_BUCKETS_LOG / 4);
    245         hash_index_t b = (a | key[KEY_DEV_HANDLE]) << (NODES_BUCKETS_LOG / 2);
    246        
    247         return (b | key[KEY_INDEX]) & (NODES_BUCKETS - 1);
    248 }
    249 
    250 int nodes_compare(unsigned long key[], hash_count_t keys, link_t *item)
    251 {
    252         vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link);
    253         return (node->fs_handle == (fs_handle_t) key[KEY_FS_HANDLE]) &&
    254             (node->service_id == key[KEY_DEV_HANDLE]) &&
    255             (node->index == key[KEY_INDEX]);
    256 }
    257 
    258 void nodes_remove_callback(link_t *item)
    259 {
    260 }
    261 
    262228struct refcnt_data {
    263229        /** Sum of all reference counts for this file system instance. */
     
    267233};
    268234
    269 static void refcnt_visitor(link_t *item, void *arg)
    270 {
    271         vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link);
     235static bool refcnt_visitor(ht_link_t *item, void *arg)
     236{
     237        vfs_node_t *node = hash_table_get_inst(item, vfs_node_t, nh_link);
    272238        struct refcnt_data *rd = (void *) arg;
    273239
     
    275241            (node->service_id == rd->service_id))
    276242                rd->refcnt += node->refcnt;
     243       
     244        return true;
    277245}
    278246
     
    315283}
    316284
     285
     286static size_t nodes_key_hash(void *key)
     287{
     288        vfs_triplet_t *tri = key;
     289        size_t hash = hash_combine(tri->fs_handle, tri->index);
     290        return hash_combine(hash, tri->service_id);
     291}
     292
     293static size_t nodes_hash(const ht_link_t *item)
     294{
     295        vfs_node_t *node = hash_table_get_inst(item, vfs_node_t, nh_link);
     296        vfs_triplet_t tri = node_triplet(node);
     297        return nodes_key_hash(&tri);
     298}
     299
     300static bool nodes_key_equal(void *key, const ht_link_t *item)
     301{
     302        vfs_triplet_t *tri = key;
     303        vfs_node_t *node = hash_table_get_inst(item, vfs_node_t, nh_link);
     304        return node->fs_handle == tri->fs_handle
     305                && node->service_id == tri->service_id
     306                && node->index == tri->index;
     307}
     308
     309static inline vfs_triplet_t node_triplet(vfs_node_t *node)
     310{
     311        vfs_triplet_t tri = {
     312                .fs_handle = node->fs_handle,
     313                .service_id = node->service_id,
     314                .index = node->index
     315        };
     316       
     317        return tri;
     318}
     319
    317320/**
    318321 * @}
Note: See TracChangeset for help on using the changeset viewer.