Changeset b800b0e in mainline for uspace/srv/fs/ext4fs/ext4fs_ops.c
- Timestamp:
- 2012-10-23T13:16:49Z (12 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/ext4fs/ext4fs_ops.c
r32b3a12 rb800b0e 42 42 #include <malloc.h> 43 43 #include <adt/hash_table.h> 44 #include <adt/hash.h> 44 45 #include <ipc/loc.h> 45 46 #include "ext4fs.h" … … 48 49 #define EXT4FS_NODE(node) \ 49 50 ((node) ? (ext4fs_node_t *) (node)->data : NULL) 50 51 #define OPEN_NODES_KEYS 252 53 #define OPEN_NODES_DEV_HANDLE_KEY 054 #define OPEN_NODES_INODE_KEY 155 56 #define OPEN_NODES_BUCKETS 25657 51 58 52 /** … … 73 67 ext4_inode_ref_t *inode_ref; 74 68 fs_node_t *fs_node; 75 link_t link;69 ht_link_t link; 76 70 unsigned int references; 77 71 } ext4fs_node_t; … … 115 109 116 110 /* 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 112 typedef struct { 113 service_id_t service_id; 114 fs_index_t index; 115 } node_key_t; 116 117 static 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 123 static 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 129 static 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 138 static hash_table_ops_t open_nodes_ops = { 155 139 .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, 158 144 }; 159 145 … … 168 154 int ext4fs_global_init(void) 169 155 { 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)) 172 157 return ENOMEM; 173 158 … … 315 300 316 301 /* 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]= index302 node_key_t key = { 303 .service_id = inst->service_id, 304 .index = index 320 305 }; 321 306 322 link_t *already_open = hash_table_find(&open_nodes,key);307 ht_link_t *already_open = hash_table_find(&open_nodes, &key); 323 308 ext4fs_node_t *enode = NULL; 324 309 if (already_open) { 325 enode = hash_table_get_inst ance(already_open, ext4fs_node_t, link);310 enode = hash_table_get_inst(already_open, ext4fs_node_t, link); 326 311 *rfn = enode->fs_node; 327 312 enode->references++; … … 364 349 enode->references = 1; 365 350 enode->fs_node = fs_node; 366 link_initialize(&enode->link);367 351 368 352 fs_node->data = enode; 369 353 *rfn = fs_node; 370 354 371 hash_table_insert(&open_nodes, key,&enode->link);355 hash_table_insert(&open_nodes, &enode->link); 372 356 inst->open_nodes_count++; 373 357 … … 386 370 int ext4fs_node_put_core(ext4fs_node_t *enode) 387 371 { 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); 394 373 assert(enode->instance->open_nodes_count > 0); 395 374 enode->instance->open_nodes_count--; … … 498 477 enode->references = 1; 499 478 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->index505 };506 507 479 fibril_mutex_lock(&open_nodes_lock); 508 hash_table_insert(&open_nodes, key,&enode->link);480 hash_table_insert(&open_nodes, &enode->link); 509 481 fibril_mutex_unlock(&open_nodes_lock); 510 482 inst->open_nodes_count++;
Note:
See TracChangeset
for help on using the changeset viewer.