Changes in uspace/lib/block/libblock.c [9d58539:bc216a0] in mainline
- File:
-
- 1 edited
-
uspace/lib/block/libblock.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
r9d58539 rbc216a0 62 62 static LIST_INITIALIZE(dcl); 63 63 64 #define CACHE_BUCKETS_LOG2 1065 #define CACHE_BUCKETS (1 << CACHE_BUCKETS_LOG2)66 64 67 65 typedef struct { … … 256 254 } 257 255 258 static hash_index_t cache_hash(unsigned long *key) 259 { 260 return MERGE_LOUP32(key[0], key[1]) & (CACHE_BUCKETS - 1); 261 } 262 263 static int cache_compare(unsigned long *key, hash_count_t keys, link_t *item) 264 { 265 block_t *b = hash_table_get_instance(item, block_t, hash_link); 266 return b->lba == MERGE_LOUP32(key[0], key[1]); 267 } 268 269 static void cache_remove_callback(link_t *item) 270 { 271 } 272 273 static hash_table_operations_t cache_ops = { 256 static size_t cache_key_hash(void *key) 257 { 258 aoff64_t *lba = (aoff64_t*)key; 259 return *lba; 260 } 261 262 static size_t cache_hash(const ht_link_t *item) 263 { 264 block_t *b = hash_table_get_inst(item, block_t, hash_link); 265 return b->lba; 266 } 267 268 static bool cache_key_equal(void *key, const ht_link_t *item) 269 { 270 aoff64_t *lba = (aoff64_t*)key; 271 block_t *b = hash_table_get_inst(item, block_t, hash_link); 272 return b->lba == *lba; 273 } 274 275 276 static hash_table_ops_t cache_ops = { 274 277 .hash = cache_hash, 275 .compare = cache_compare, 276 .remove_callback = cache_remove_callback 278 .key_hash = cache_key_hash, 279 .key_equal = cache_key_equal, 280 .equal = 0, 281 .remove_callback = 0 277 282 }; 278 283 … … 305 310 cache->blocks_cluster = cache->lblock_size / devcon->pblock_size; 306 311 307 if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 2, 308 &cache_ops)) { 312 if (!hash_table_create(&cache->block_hash, 0, 0, &cache_ops)) { 309 313 free(cache); 310 314 return ENOMEM; … … 344 348 } 345 349 346 unsigned long key[2] = { 347 LOWER32(b->lba), 348 UPPER32(b->lba) 349 }; 350 hash_table_remove(&cache->block_hash, key, 2); 350 hash_table_remove_item(&cache->block_hash, &b->hash_link); 351 351 352 352 free(b->data); … … 380 380 fibril_rwlock_initialize(&b->contents_lock); 381 381 link_initialize(&b->free_link); 382 link_initialize(&b->hash_link);383 382 } 384 383 … … 400 399 cache_t *cache; 401 400 block_t *b; 402 link_t *l; 403 unsigned long key[2] = { 404 LOWER32(ba), 405 UPPER32(ba) 406 }; 401 link_t *link; 407 402 408 403 int rc; … … 420 415 421 416 fibril_mutex_lock(&cache->lock); 422 l = hash_table_find(&cache->block_hash, key);423 if ( l) {417 ht_link_t *hlink = hash_table_find(&cache->block_hash, &ba); 418 if (hlink) { 424 419 found: 425 420 /* 426 421 * We found the block in the cache. 427 422 */ 428 b = hash_table_get_inst ance(l, block_t, hash_link);423 b = hash_table_get_inst(hlink, block_t, hash_link); 429 424 fibril_mutex_lock(&b->lock); 430 425 if (b->refcnt++ == 0) … … 464 459 goto out; 465 460 } 466 l = list_first(&cache->free_list);467 b = list_get_instance(l , block_t, free_link);461 link = list_first(&cache->free_list); 462 b = list_get_instance(link, block_t, free_link); 468 463 469 464 fibril_mutex_lock(&b->lock); … … 505 500 goto retry; 506 501 } 507 l = hash_table_find(&cache->block_hash, key);508 if ( l) {502 hlink = hash_table_find(&cache->block_hash, &ba); 503 if (hlink) { 509 504 /* 510 505 * Someone else must have already … … 528 523 */ 529 524 list_remove(&b->free_link); 530 unsigned long temp_key[2] = { 531 LOWER32(b->lba), 532 UPPER32(b->lba) 533 }; 534 hash_table_remove(&cache->block_hash, temp_key, 2); 525 hash_table_remove_item(&cache->block_hash, &b->hash_link); 535 526 } 536 527 … … 540 531 b->lba = ba; 541 532 b->pba = ba_ltop(devcon, b->lba); 542 hash_table_insert(&cache->block_hash, key,&b->hash_link);533 hash_table_insert(&cache->block_hash, &b->hash_link); 543 534 544 535 /* … … 652 643 * Take the block out of the cache and free it. 653 644 */ 654 unsigned long key[2] = { 655 LOWER32(block->lba), 656 UPPER32(block->lba) 657 }; 658 hash_table_remove(&cache->block_hash, key, 2); 645 hash_table_remove_item(&cache->block_hash, &block->hash_link); 659 646 fibril_mutex_unlock(&block->lock); 660 647 free(block->data);
Note:
See TracChangeset
for help on using the changeset viewer.
