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