Changes in uspace/srv/fs/mfs/mfs_ops.c [7769ec9:44ecf89] in mainline
- File:
-
- 1 edited
-
uspace/srv/fs/mfs/mfs_ops.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/mfs/mfs_ops.c
r7769ec9 r44ecf89 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, 109 struct mfs_node, link); 110 assert(keys > 0); 111 if (mnode->instance->service_id != 112 ((service_id_t) key[OPEN_NODES_SERVICE_KEY])) { 113 return false; 114 } 115 if (keys == 1) { 116 return true; 117 } 118 assert(keys == 2); 119 return (mnode->ino_i->index == key[OPEN_NODES_INODE_KEY]); 120 } 121 122 static void 123 open_nodes_remove_cb(link_t *link) 124 { 125 /* We don't use remove callback for this hash table */ 126 } 127 128 static hash_table_operations_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 = { 129 121 .hash = open_nodes_hash, 130 .compare = open_nodes_compare, 131 .remove_callback = open_nodes_remove_cb, 122 .key_hash = open_nodes_key_hash, 123 .key_equal = open_nodes_key_equal, 124 .equal = NULL, 125 .remove_callback = NULL, 132 126 }; 133 127 … … 135 129 mfs_global_init(void) 136 130 { 137 if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS, 138 OPEN_NODES_KEYS, &open_nodes_ops)) { 131 if (!hash_table_create(&open_nodes, 0, 0, &open_nodes_ops)) { 139 132 return ENOMEM; 140 133 } … … 197 190 /* This is a V1 or V2 Minix filesystem */ 198 191 magic = sb->s_magic; 199 } else if (check_magic_number(sb3->s_magic, &native, 200 &version, &longnames)) { 192 } else if (check_magic_number(sb3->s_magic, &native, &version, &longnames)) { 201 193 /* This is a V3 Minix filesystem */ 202 194 magic = sb3->s_magic; … … 408 400 mnode->refcnt = 1; 409 401 410 link_initialize(&mnode->link);411 412 unsigned long key[] = {413 [OPEN_NODES_SERVICE_KEY] = inst->service_id,414 [OPEN_NODES_INODE_KEY] = inum,415 };416 417 402 fibril_mutex_lock(&open_nodes_lock); 418 hash_table_insert(&open_nodes, key,&mnode->link);403 hash_table_insert(&open_nodes, &mnode->link); 419 404 fibril_mutex_unlock(&open_nodes_lock); 420 405 inst->open_nodes_cnt++; … … 467 452 468 453 if (comp_size == dentry_name_size && 469 !bcmp(component, d_info.d_name, dentry_name_size)) {454 memcmp(component, d_info.d_name, dentry_name_size) == 0) { 470 455 /* Hit! */ 471 456 mfs_node_core_get(rfn, mnode->instance, … … 515 500 mnode->refcnt--; 516 501 if (mnode->refcnt == 0) { 517 unsigned long key[] = { 518 [OPEN_NODES_SERVICE_KEY] = mnode->instance->service_id, 519 [OPEN_NODES_INODE_KEY] = mnode->ino_i->index 520 }; 521 hash_table_remove(&open_nodes, key, OPEN_NODES_KEYS); 502 hash_table_remove_item(&open_nodes, &mnode->link); 522 503 assert(mnode->instance->open_nodes_cnt > 0); 523 504 mnode->instance->open_nodes_cnt--; … … 578 559 579 560 /* Check if the node is not already open */ 580 unsigned long key[]= {581 [OPEN_NODES_SERVICE_KEY]= inst->service_id,582 [OPEN_NODES_INODE_KEY] = index,561 node_key_t key = { 562 .service_id = inst->service_id, 563 .index = index 583 564 }; 584 link_t *already_open = hash_table_find(&open_nodes, key); 565 566 ht_link_t *already_open = hash_table_find(&open_nodes, &key); 585 567 586 568 if (already_open) { 587 mnode = hash_table_get_instance(already_open, 588 struct mfs_node, link); 569 mnode = hash_table_get_inst(already_open, struct mfs_node, link); 589 570 *rfn = mnode->fsnode; 590 571 mnode->refcnt++; … … 617 598 mnode->ino_i = ino_i; 618 599 mnode->refcnt = 1; 619 link_initialize(&mnode->link);620 600 621 601 mnode->instance = inst; … … 624 604 *rfn = node; 625 605 626 hash_table_insert(&open_nodes, key,&mnode->link);606 hash_table_insert(&open_nodes, &mnode->link); 627 607 inst->open_nodes_cnt++; 628 608 … … 793 773 { 794 774 int rc; 795 fs_node_t *fn ;775 fs_node_t *fn = NULL; 796 776 797 777 rc = mfs_node_get(&fn, service_id, index); … … 1128 1108 mfs_sync(service_id_t service_id, fs_index_t index) 1129 1109 { 1130 fs_node_t *fn ;1110 fs_node_t *fn = NULL; 1131 1111 int rc = mfs_node_get(&fn, service_id, index); 1132 1112 if (rc != EOK)
Note:
See TracChangeset
for help on using the changeset viewer.
