Changeset b800b0e in mainline for uspace/srv/fs/ext4fs/ext4fs_ops.c


Ignore:
Timestamp:
2012-10-23T13:16:49Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6ecf5b8
Parents:
32b3a12 (diff), b2ac3998 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/ext4fs/ext4fs_ops.c

    r32b3a12 rb800b0e  
    4242#include <malloc.h>
    4343#include <adt/hash_table.h>
     44#include <adt/hash.h>
    4445#include <ipc/loc.h>
    4546#include "ext4fs.h"
     
    4849#define EXT4FS_NODE(node) \
    4950        ((node) ? (ext4fs_node_t *) (node)->data : NULL)
    50 
    51 #define OPEN_NODES_KEYS  2
    52 
    53 #define OPEN_NODES_DEV_HANDLE_KEY  0
    54 #define OPEN_NODES_INODE_KEY       1
    55 
    56 #define OPEN_NODES_BUCKETS  256
    5751
    5852/**
     
    7367        ext4_inode_ref_t *inode_ref;
    7468        fs_node_t *fs_node;
    75         link_t link;
     69        ht_link_t link;
    7670        unsigned int references;
    7771} ext4fs_node_t;
     
    115109
    116110/* Hash table interface for open nodes hash table */
    117 static hash_index_t open_nodes_hash(unsigned long key[])
    118 {
    119         /* TODO: This is very simple and probably can be improved */
    120         return key[OPEN_NODES_INODE_KEY] % OPEN_NODES_BUCKETS;
    121 }
    122 
    123 /** Compare given item with values in hash table.
    124  *
    125  */
    126 static int open_nodes_compare(unsigned long key[], hash_count_t keys,
    127     link_t *item)
    128 {
    129         assert(keys > 0);
    130        
    131         ext4fs_node_t *enode =
    132             hash_table_get_instance(item, ext4fs_node_t, link);
    133        
    134         if (enode->instance->service_id !=
    135             ((service_id_t) key[OPEN_NODES_DEV_HANDLE_KEY]))
    136                 return false;
    137        
    138         if (keys == 1)
    139                 return true;
    140        
    141         assert(keys == 2);
    142        
    143         return (enode->inode_ref->index == key[OPEN_NODES_INODE_KEY]);
    144 }
    145 
    146 /** Empty callback to correct hash table initialization.
    147  *
    148  */
    149 static void open_nodes_remove_cb(link_t *link)
    150 {
    151         /* We don't use remove callback for this hash table */
    152 }
    153 
    154 static hash_table_operations_t open_nodes_ops = {
     111
     112typedef struct {
     113        service_id_t service_id;
     114        fs_index_t index;
     115} node_key_t;
     116
     117static size_t open_nodes_key_hash(void *key_arg)
     118{
     119        node_key_t *key = (node_key_t *)key_arg;
     120        return hash_combine(key->service_id, key->index);
     121}
     122
     123static size_t open_nodes_hash(const ht_link_t *item)
     124{
     125        ext4fs_node_t *enode = hash_table_get_inst(item, ext4fs_node_t, link);
     126        return hash_combine(enode->instance->service_id, enode->inode_ref->index);     
     127}
     128
     129static bool open_nodes_key_equal(void *key_arg, const ht_link_t *item)
     130{
     131        node_key_t *key = (node_key_t *)key_arg;
     132        ext4fs_node_t *enode = hash_table_get_inst(item, ext4fs_node_t, link);
     133       
     134        return key->service_id == enode->instance->service_id
     135                && key->index == enode->inode_ref->index;
     136}
     137
     138static hash_table_ops_t open_nodes_ops = {
    155139        .hash = open_nodes_hash,
    156         .compare = open_nodes_compare,
    157         .remove_callback = open_nodes_remove_cb,
     140        .key_hash = open_nodes_key_hash,
     141        .key_equal = open_nodes_key_equal,
     142        .equal = NULL,
     143        .remove_callback = NULL,
    158144};
    159145
     
    168154int ext4fs_global_init(void)
    169155{
    170         if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS,
    171             OPEN_NODES_KEYS, &open_nodes_ops))
     156        if (!hash_table_create(&open_nodes, 0, 0, &open_nodes_ops))
    172157                return ENOMEM;
    173158       
     
    315300       
    316301        /* Check if the node is not already open */
    317         unsigned long key[] = {
    318                 [OPEN_NODES_DEV_HANDLE_KEY] = inst->service_id,
    319                 [OPEN_NODES_INODE_KEY] = index
     302        node_key_t key = {
     303                .service_id = inst->service_id,
     304                .index = index
    320305        };
    321306       
    322         link_t *already_open = hash_table_find(&open_nodes, key);
     307        ht_link_t *already_open = hash_table_find(&open_nodes, &key);
    323308        ext4fs_node_t *enode = NULL;
    324309        if (already_open) {
    325                 enode = hash_table_get_instance(already_open, ext4fs_node_t, link);
     310                enode = hash_table_get_inst(already_open, ext4fs_node_t, link);
    326311                *rfn = enode->fs_node;
    327312                enode->references++;
     
    364349        enode->references = 1;
    365350        enode->fs_node = fs_node;
    366         link_initialize(&enode->link);
    367351       
    368352        fs_node->data = enode;
    369353        *rfn = fs_node;
    370354       
    371         hash_table_insert(&open_nodes, key, &enode->link);
     355        hash_table_insert(&open_nodes, &enode->link);
    372356        inst->open_nodes_count++;
    373357       
     
    386370int ext4fs_node_put_core(ext4fs_node_t *enode)
    387371{
    388         unsigned long key[] = {
    389                 [OPEN_NODES_DEV_HANDLE_KEY] = enode->instance->service_id,
    390                 [OPEN_NODES_INODE_KEY] = enode->inode_ref->index
    391         };
    392        
    393         hash_table_remove(&open_nodes, key, OPEN_NODES_KEYS);
     372        hash_table_remove_item(&open_nodes, &enode->link);
    394373        assert(enode->instance->open_nodes_count > 0);
    395374        enode->instance->open_nodes_count--;
     
    498477        enode->references = 1;
    499478       
    500         link_initialize(&enode->link);
    501        
    502         unsigned long key[] = {
    503                 [OPEN_NODES_DEV_HANDLE_KEY] = inst->service_id,
    504                 [OPEN_NODES_INODE_KEY] = inode_ref->index
    505         };
    506        
    507479        fibril_mutex_lock(&open_nodes_lock);
    508         hash_table_insert(&open_nodes, key, &enode->link);
     480        hash_table_insert(&open_nodes, &enode->link);
    509481        fibril_mutex_unlock(&open_nodes_lock);
    510482        inst->open_nodes_count++;
Note: See TracChangeset for help on using the changeset viewer.