Changes in uspace/srv/vfs/vfs_node.c [44451ee:4e00f87] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_node.c
r44451ee r4e00f87 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 hash_index_t nodes_hash(unsigned long []); 61 static int nodes_compare(unsigned long [], hash_count_t, link_t *); 62 static void nodes_remove_callback(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. */ 65 hash_table_op erations_t nodes_ops = {67 hash_table_ops_t nodes_ops = { 66 68 .hash = nodes_hash, 67 .compare = nodes_compare, 68 .remove_callback = nodes_remove_callback 69 .key_hash = nodes_key_hash, 70 .key_equal = nodes_key_equal, 71 .equal = NULL, 72 .remove_callback = NULL, 69 73 }; 70 74 … … 75 79 bool vfs_nodes_init(void) 76 80 { 77 return hash_table_create(&nodes, NODES_BUCKETS, 3, &nodes_ops);81 return hash_table_create(&nodes, 0, 0, &nodes_ops); 78 82 } 79 83 … … 114 118 */ 115 119 116 unsigned long key[] = { 117 [KEY_FS_HANDLE] = node->fs_handle, 118 [KEY_DEV_HANDLE] = node->devmap_handle, 119 [KEY_INDEX] = node->index 120 }; 121 122 hash_table_remove(&nodes, key, 3); 120 hash_table_remove_item(&nodes, &node->nh_link); 123 121 free_vfs_node = true; 124 122 … … 138 136 async_exch_t *exch = vfs_exchange_grab(node->fs_handle); 139 137 sysarg_t rc = async_req_2_0(exch, VFS_OUT_DESTROY, 140 (sysarg_t) node-> devmap_handle, (sysarg_t)node->index);138 (sysarg_t) node->service_id, (sysarg_t)node->index); 141 139 142 140 assert(rc == EOK); … … 158 156 { 159 157 fibril_mutex_lock(&nodes_mutex); 160 unsigned long key[] = { 161 [KEY_FS_HANDLE] = node->fs_handle, 162 [KEY_DEV_HANDLE] = node->devmap_handle, 163 [KEY_INDEX] = node->index 164 }; 165 hash_table_remove(&nodes, key, 3); 158 hash_table_remove_item(&nodes, &node->nh_link); 166 159 fibril_mutex_unlock(&nodes_mutex); 167 160 free(node); … … 182 175 vfs_node_t *vfs_node_get(vfs_lookup_res_t *result) 183 176 { 184 unsigned long key[] = {185 [KEY_FS_HANDLE] = result->triplet.fs_handle,186 [KEY_DEV_HANDLE] = result->triplet.devmap_handle,187 [KEY_INDEX] = result->triplet.index188 };189 link_t *tmp;190 177 vfs_node_t *node; 191 178 192 179 fibril_mutex_lock(&nodes_mutex); 193 tmp = hash_table_find(&nodes, key);180 ht_link_t *tmp = hash_table_find(&nodes, &result->triplet); 194 181 if (!tmp) { 195 182 node = (vfs_node_t *) malloc(sizeof(vfs_node_t)); … … 200 187 memset(node, 0, sizeof(vfs_node_t)); 201 188 node->fs_handle = result->triplet.fs_handle; 202 node-> devmap_handle = result->triplet.devmap_handle;189 node->service_id = result->triplet.service_id; 203 190 node->index = result->triplet.index; 204 191 node->size = result->size; 205 192 node->lnkcnt = result->lnkcnt; 206 193 node->type = result->type; 207 link_initialize(&node->nh_link);208 194 fibril_rwlock_initialize(&node->contents_rwlock); 209 hash_table_insert(&nodes, key,&node->nh_link);195 hash_table_insert(&nodes, &node->nh_link); 210 196 } else { 211 node = hash_table_get_inst ance(tmp, vfs_node_t, nh_link);197 node = hash_table_get_inst(tmp, vfs_node_t, nh_link); 212 198 if (node->type == VFS_NODE_UNKNOWN && 213 199 result->type != VFS_NODE_UNKNOWN) { … … 240 226 } 241 227 242 hash_index_t nodes_hash(unsigned long key[])243 {244 hash_index_t a = key[KEY_FS_HANDLE] << (NODES_BUCKETS_LOG / 4);245 hash_index_t b = (a | key[KEY_DEV_HANDLE]) << (NODES_BUCKETS_LOG / 2);246 247 return (b | key[KEY_INDEX]) & (NODES_BUCKETS - 1);248 }249 250 int nodes_compare(unsigned long key[], hash_count_t keys, link_t *item)251 {252 vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link);253 return (node->fs_handle == (fs_handle_t) key[KEY_FS_HANDLE]) &&254 (node->devmap_handle == key[KEY_DEV_HANDLE]) &&255 (node->index == key[KEY_INDEX]);256 }257 258 void nodes_remove_callback(link_t *item)259 {260 }261 262 228 struct refcnt_data { 263 229 /** Sum of all reference counts for this file system instance. */ 264 230 unsigned refcnt; 265 231 fs_handle_t fs_handle; 266 devmap_handle_t devmap_handle;232 service_id_t service_id; 267 233 }; 268 234 269 static void refcnt_visitor(link_t *item, void *arg)270 { 271 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); 272 238 struct refcnt_data *rd = (void *) arg; 273 239 274 240 if ((node->fs_handle == rd->fs_handle) && 275 (node-> devmap_handle == rd->devmap_handle))241 (node->service_id == rd->service_id)) 276 242 rd->refcnt += node->refcnt; 243 244 return true; 277 245 } 278 246 279 247 unsigned 280 vfs_nodes_refcount_sum_get(fs_handle_t fs_handle, devmap_handle_t devmap_handle)248 vfs_nodes_refcount_sum_get(fs_handle_t fs_handle, service_id_t service_id) 281 249 { 282 250 struct refcnt_data rd = { 283 251 .refcnt = 0, 284 252 .fs_handle = fs_handle, 285 . devmap_handle = devmap_handle253 .service_id = service_id 286 254 }; 287 255 … … 305 273 ipc_call_t answer; 306 274 aid_t req = async_send_2(exch, VFS_OUT_OPEN_NODE, 307 (sysarg_t) node-> devmap_handle, (sysarg_t) node->index, &answer);275 (sysarg_t) node->service_id, (sysarg_t) node->index, &answer); 308 276 309 277 vfs_exchange_release(exch); … … 315 283 } 316 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 317 320 /** 318 321 * @}
Note:
See TracChangeset
for help on using the changeset viewer.