Changeset 0ca7286 in mainline for uspace/srv/fs/mfs/mfs_ops.c
- Timestamp:
- 2012-07-21T11:19:27Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2732c94
- Parents:
- 1c1da4b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/mfs/mfs_ops.c
r1c1da4b r0ca7286 40 40 #define OPEN_NODES_SERVICE_KEY 0 41 41 #define OPEN_NODES_INODE_KEY 1 42 #define OPEN_NODES_BUCKETS 25643 42 44 43 static bool check_magic_number(uint16_t magic, bool *native, … … 61 60 static int mfs_unlink(fs_node_t *, fs_node_t *, const char *name); 62 61 static int mfs_destroy_node(fs_node_t *fn); 63 static hash_index_t open_nodes_hash(unsigned long key[]);64 static int open_nodes_compare(unsigned long key[], hash_count_t keys,65 link_t *item); 66 static void open_nodes_remove_cb(link_t *link);62 static size_t open_nodes_hash(const link_t *item); 63 static size_t open_nodes_key_hash(unsigned long key[]); 64 static bool open_nodes_match(unsigned long key[], size_t keys, 65 const link_t *item); 67 66 static int mfs_node_get(fs_node_t **rfn, service_id_t service_id, 68 67 fs_index_t index); … … 95 94 96 95 /* Hash table interface for open nodes hash table */ 97 static hash_index_t 98 open_nodes_hash(unsigned long key[]) 99 { 100 /* TODO: This is very simple and probably can be improved */ 101 return key[OPEN_NODES_INODE_KEY] % OPEN_NODES_BUCKETS; 102 } 103 104 static int 105 open_nodes_compare(unsigned long key[], hash_count_t keys, 106 link_t *item) 107 { 96 97 static size_t 98 open_nodes_key_hash(unsigned long key[]) 99 { 100 /* As recommended by Effective Java, 2nd Edition. */ 101 size_t hash = 17; 102 hash = 37 * hash + key[OPEN_NODES_SERVICE_KEY]; 103 hash = 37 * hash + key[OPEN_NODES_INODE_KEY]; 104 return hash; 105 } 106 107 static size_t 108 open_nodes_hash(const link_t *item) 109 { 110 struct mfs_node *m = hash_table_get_instance(item, struct mfs_node, link); 111 112 unsigned long key[] = { 113 [OPEN_NODES_SERVICE_KEY] = m->instance->service_id, 114 [OPEN_NODES_INODE_KEY] = m->ino_i->index, 115 }; 116 117 return open_nodes_key_hash(key); 118 } 119 120 static bool 121 open_nodes_match(unsigned long key[], size_t keys, const link_t *item) 122 { 123 assert(keys == 2); 108 124 struct mfs_node *mnode = hash_table_get_instance(item, struct mfs_node, link); 109 assert(keys > 0); 110 if (mnode->instance->service_id != 111 ((service_id_t) key[OPEN_NODES_SERVICE_KEY])) { 112 return false; 113 } 114 if (keys == 1) { 115 return true; 116 } 117 assert(keys == 2); 118 return (mnode->ino_i->index == key[OPEN_NODES_INODE_KEY]); 119 } 120 121 static void 122 open_nodes_remove_cb(link_t *link) 123 { 124 /* We don't use remove callback for this hash table */ 125 } 126 127 static hash_table_operations_t open_nodes_ops = { 125 126 service_id_t service_id = ((service_id_t) key[OPEN_NODES_SERVICE_KEY]); 127 128 return mnode->instance->service_id == service_id 129 && mnode->ino_i->index == key[OPEN_NODES_INODE_KEY]; 130 } 131 132 133 static hash_table_ops_t open_nodes_ops = { 128 134 .hash = open_nodes_hash, 129 .compare = open_nodes_compare, 130 .remove_callback = open_nodes_remove_cb, 135 .key_hash = open_nodes_key_hash, 136 .match = open_nodes_match, 137 .equal = 0, 138 .remove_callback = 0, 131 139 }; 132 140 … … 134 142 mfs_global_init(void) 135 143 { 136 if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS, 137 OPEN_NODES_KEYS, &open_nodes_ops)) { 144 if (!hash_table_create(&open_nodes, 0, OPEN_NODES_KEYS, &open_nodes_ops)) { 138 145 return ENOMEM; 139 146 } … … 408 415 link_initialize(&mnode->link); 409 416 410 unsigned long key[] = {411 [OPEN_NODES_SERVICE_KEY] = inst->service_id,412 [OPEN_NODES_INODE_KEY] = inum,413 };414 415 417 fibril_mutex_lock(&open_nodes_lock); 416 hash_table_insert(&open_nodes, key,&mnode->link);418 hash_table_insert(&open_nodes, &mnode->link); 417 419 fibril_mutex_unlock(&open_nodes_lock); 418 420 inst->open_nodes_cnt++; … … 621 623 *rfn = node; 622 624 623 hash_table_insert(&open_nodes, key,&mnode->link);625 hash_table_insert(&open_nodes, &mnode->link); 624 626 inst->open_nodes_cnt++; 625 627
Note:
See TracChangeset
for help on using the changeset viewer.