Changeset bc216a0 in mainline for uspace/srv/vfs/vfs_node.c
- Timestamp:
- 2012-08-07T22:13:44Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- da68871a
- Parents:
- b17518e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_node.c
rb17518e rbc216a0 41 41 #include <fibril_synch.h> 42 42 #include <adt/hash_table.h> 43 #include <adt/hash.h> 43 44 #include <assert.h> 44 45 #include <async.h> … … 58 59 #define KEY_INDEX 2 59 60 60 static size_t nodes_key_hash(unsigned long []); 61 static size_t nodes_hash(const link_t *); 62 static bool nodes_match(unsigned long [], size_t, const link_t *); 61 static size_t nodes_key_hash(void *); 62 static size_t nodes_hash(const ht_link_t *); 63 static bool nodes_key_equal(void *, const ht_link_t *); 64 static vfs_triplet_t node_triplet(vfs_node_t *node); 63 65 64 66 /** VFS node hash table operations. */ … … 66 68 .hash = nodes_hash, 67 69 .key_hash = nodes_key_hash, 68 . match = nodes_match,70 .key_equal = nodes_key_equal, 69 71 .equal = 0, 70 72 .remove_callback = 0, … … 77 79 bool vfs_nodes_init(void) 78 80 { 79 return hash_table_create(&nodes, 0, 3, &nodes_ops);81 return hash_table_create(&nodes, 0, 0, &nodes_ops); 80 82 } 81 83 … … 116 118 */ 117 119 118 unsigned long key[] = { 119 [KEY_FS_HANDLE] = node->fs_handle, 120 [KEY_DEV_HANDLE] = node->service_id, 121 [KEY_INDEX] = node->index 122 }; 123 124 hash_table_remove(&nodes, key, 3); 120 hash_table_remove_item(&nodes, &node->nh_link); 125 121 free_vfs_node = true; 126 122 … … 160 156 { 161 157 fibril_mutex_lock(&nodes_mutex); 162 unsigned long key[] = { 163 [KEY_FS_HANDLE] = node->fs_handle, 164 [KEY_DEV_HANDLE] = node->service_id, 165 [KEY_INDEX] = node->index 166 }; 167 hash_table_remove(&nodes, key, 3); 158 hash_table_remove_item(&nodes, &node->nh_link); 168 159 fibril_mutex_unlock(&nodes_mutex); 169 160 free(node); … … 184 175 vfs_node_t *vfs_node_get(vfs_lookup_res_t *result) 185 176 { 186 unsigned long key[] = {187 [KEY_FS_HANDLE] = result->triplet.fs_handle,188 [KEY_DEV_HANDLE] = result->triplet.service_id,189 [KEY_INDEX] = result->triplet.index190 };191 link_t *tmp;192 177 vfs_node_t *node; 193 178 194 179 fibril_mutex_lock(&nodes_mutex); 195 tmp = hash_table_find(&nodes, key);180 ht_link_t *tmp = hash_table_find(&nodes, &result->triplet); 196 181 if (!tmp) { 197 182 node = (vfs_node_t *) malloc(sizeof(vfs_node_t)); … … 207 192 node->lnkcnt = result->lnkcnt; 208 193 node->type = result->type; 209 link_initialize(&node->nh_link);210 194 fibril_rwlock_initialize(&node->contents_rwlock); 211 195 hash_table_insert(&nodes, &node->nh_link); 212 196 } else { 213 node = hash_table_get_inst ance(tmp, vfs_node_t, nh_link);197 node = hash_table_get_inst(tmp, vfs_node_t, nh_link); 214 198 if (node->type == VFS_NODE_UNKNOWN && 215 199 result->type != VFS_NODE_UNKNOWN) { … … 242 226 } 243 227 244 size_t nodes_key_hash(unsigned long key[])245 {246 /* Combine into a hash like they do in Effective Java, 2nd edition. */247 size_t hash = 17;248 hash = 37 * hash + key[KEY_FS_HANDLE];249 hash = 37 * hash + key[KEY_DEV_HANDLE];250 hash = 37 * hash + key[KEY_INDEX];251 return hash;252 }253 254 size_t nodes_hash(const link_t *item)255 {256 vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link);257 258 unsigned long key[] = {259 [KEY_FS_HANDLE] = node->fs_handle,260 [KEY_DEV_HANDLE] = node->service_id,261 [KEY_INDEX] = node->index262 };263 264 return nodes_key_hash(key);265 }266 267 268 bool nodes_match(unsigned long key[], size_t keys, const link_t *item)269 {270 vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link);271 return (node->fs_handle == (fs_handle_t) key[KEY_FS_HANDLE]) &&272 (node->service_id == key[KEY_DEV_HANDLE]) &&273 (node->index == key[KEY_INDEX]);274 }275 276 277 228 struct refcnt_data { 278 229 /** Sum of all reference counts for this file system instance. */ … … 282 233 }; 283 234 284 static bool refcnt_visitor( link_t *item, void *arg)285 { 286 vfs_node_t *node = hash_table_get_inst ance(item, vfs_node_t, nh_link);235 static bool refcnt_visitor(ht_link_t *item, void *arg) 236 { 237 vfs_node_t *node = hash_table_get_inst(item, vfs_node_t, nh_link); 287 238 struct refcnt_data *rd = (void *) arg; 288 239 … … 332 283 } 333 284 285 286 static size_t nodes_key_hash(void *key) 287 { 288 vfs_triplet_t *tri = key; 289 size_t hash = hash_combine(tri->fs_handle, tri->index); 290 return hash_combine(hash, tri->service_id); 291 } 292 293 static size_t nodes_hash(const ht_link_t *item) 294 { 295 vfs_node_t *node = hash_table_get_inst(item, vfs_node_t, nh_link); 296 vfs_triplet_t tri = node_triplet(node); 297 return nodes_key_hash(&tri); 298 } 299 300 static bool nodes_key_equal(void *key, const ht_link_t *item) 301 { 302 vfs_triplet_t *tri = key; 303 vfs_node_t *node = hash_table_get_inst(item, vfs_node_t, nh_link); 304 return node->fs_handle == tri->fs_handle 305 && node->service_id == tri->service_id 306 && node->index == tri->index; 307 } 308 309 static inline vfs_triplet_t node_triplet(vfs_node_t *node) 310 { 311 vfs_triplet_t tri = { 312 .fs_handle = node->fs_handle, 313 .service_id = node->service_id, 314 .index = node->index 315 }; 316 317 return tri; 318 } 319 334 320 /** 335 321 * @}
Note:
See TracChangeset
for help on using the changeset viewer.