Changeset 062d900 in mainline for uspace/srv/fs/mfs/mfs_ops.c
- Timestamp:
- 2012-10-09T11:49:43Z (13 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/mfs/mfs_ops.c
r87e9392 r062d900 35 35 #include <align.h> 36 36 #include <adt/hash_table.h> 37 #include <adt/hash.h> 37 38 #include "mfs.h" 38 39 39 #define OPEN_NODES_KEYS 240 #define OPEN_NODES_SERVICE_KEY 041 #define OPEN_NODES_INODE_KEY 142 #define OPEN_NODES_BUCKETS 25643 40 44 41 static bool check_magic_number(uint16_t magic, bool *native, … … 61 58 static int mfs_unlink(fs_node_t *, fs_node_t *, const char *name); 62 59 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);67 60 static int mfs_node_get(fs_node_t **rfn, service_id_t service_id, 68 61 fs_index_t index); … … 95 88 96 89 /* 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 { 108 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_op erations_t open_nodes_ops = {90 91 typedef struct { 92 service_id_t service_id; 93 fs_index_t index; 94 } node_key_t; 95 96 static size_t 97 open_nodes_key_hash(void *key) 98 { 99 node_key_t *node_key = (node_key_t*)key; 100 return hash_combine(node_key->service_id, node_key->index); 101 } 102 103 static size_t 104 open_nodes_hash(const ht_link_t *item) 105 { 106 struct mfs_node *m = hash_table_get_inst(item, struct mfs_node, link); 107 return hash_combine(m->instance->service_id, m->ino_i->index); 108 } 109 110 static bool 111 open_nodes_key_equal(void *key, const ht_link_t *item) 112 { 113 node_key_t *node_key = (node_key_t*)key; 114 struct mfs_node *mnode = hash_table_get_inst(item, struct mfs_node, link); 115 116 return node_key->service_id == mnode->instance->service_id 117 && node_key->index == mnode->ino_i->index; 118 } 119 120 static hash_table_ops_t open_nodes_ops = { 128 121 .hash = open_nodes_hash, 129 .compare = open_nodes_compare, 130 .remove_callback = open_nodes_remove_cb, 122 .key_hash = open_nodes_key_hash, 123 .key_equal = open_nodes_key_equal, 124 .equal = 0, 125 .remove_callback = 0, 131 126 }; 132 127 … … 134 129 mfs_global_init(void) 135 130 { 136 if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS, 137 OPEN_NODES_KEYS, &open_nodes_ops)) { 131 if (!hash_table_create(&open_nodes, 0, 0, &open_nodes_ops)) { 138 132 return ENOMEM; 139 133 } … … 406 400 mnode->refcnt = 1; 407 401 408 link_initialize(&mnode->link);409 410 unsigned long key[] = {411 [OPEN_NODES_SERVICE_KEY] = inst->service_id,412 [OPEN_NODES_INODE_KEY] = inum,413 };414 415 402 fibril_mutex_lock(&open_nodes_lock); 416 hash_table_insert(&open_nodes, key,&mnode->link);403 hash_table_insert(&open_nodes, &mnode->link); 417 404 fibril_mutex_unlock(&open_nodes_lock); 418 405 inst->open_nodes_cnt++; … … 513 500 mnode->refcnt--; 514 501 if (mnode->refcnt == 0) { 515 unsigned long key[] = { 516 [OPEN_NODES_SERVICE_KEY] = mnode->instance->service_id, 517 [OPEN_NODES_INODE_KEY] = mnode->ino_i->index 518 }; 519 hash_table_remove(&open_nodes, key, OPEN_NODES_KEYS); 502 hash_table_remove_item(&open_nodes, &mnode->link); 520 503 assert(mnode->instance->open_nodes_cnt > 0); 521 504 mnode->instance->open_nodes_cnt--; … … 576 559 577 560 /* Check if the node is not already open */ 578 unsigned long key[]= {579 [OPEN_NODES_SERVICE_KEY]= inst->service_id,580 [OPEN_NODES_INODE_KEY] = index,561 node_key_t key = { 562 .service_id = inst->service_id, 563 .index = index 581 564 }; 582 link_t *already_open = hash_table_find(&open_nodes, key); 565 566 ht_link_t *already_open = hash_table_find(&open_nodes, &key); 583 567 584 568 if (already_open) { 585 mnode = hash_table_get_inst ance(already_open, struct mfs_node, link);569 mnode = hash_table_get_inst(already_open, struct mfs_node, link); 586 570 *rfn = mnode->fsnode; 587 571 mnode->refcnt++; … … 614 598 mnode->ino_i = ino_i; 615 599 mnode->refcnt = 1; 616 link_initialize(&mnode->link);617 600 618 601 mnode->instance = inst; … … 621 604 *rfn = node; 622 605 623 hash_table_insert(&open_nodes, key,&mnode->link);606 hash_table_insert(&open_nodes, &mnode->link); 624 607 inst->open_nodes_cnt++; 625 608
Note:
See TracChangeset
for help on using the changeset viewer.