Changeset a6d97fb9 in mainline for uspace/lib/libblock/libblock.c
- Timestamp:
- 2008-11-02T20:16:16Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ab579fa
- Parents:
- d5a720cf
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libblock/libblock.c
rd5a720cf ra6d97fb9 325 325 list_remove(&b->free_link); 326 326 futex_up(&b->lock); 327 futex_up(&cache->lock); 327 328 } else { 328 329 /* … … 333 334 size_t buflen = 0; 334 335 off_t pos = boff * cache->block_size; 336 bool sync = false; 335 337 336 338 if (cache_can_grow(cache)) { … … 358 360 list_remove(l); 359 361 b = hash_table_get_instance(l, block_t, hash_link); 360 assert(!b->dirty);362 sync = b->dirty; 361 363 temp_key = b->boff; 362 364 hash_table_remove(&cache->block_hash, &temp_key, 1); … … 367 369 b->size = cache->block_size; 368 370 b->boff = boff; 369 /* read block from the device */ 371 hash_table_insert(&cache->block_hash, &key, &b->hash_link); 372 373 /* 374 * Lock the block before releasing the cache lock. Thus we don't 375 * kill concurent operations on the cache while doing I/O on the 376 * block. 377 */ 378 futex_down(&b->lock); 379 futex_up(&cache->lock); 380 381 if (sync) { 382 /* 383 * The block is dirty and needs to be written back to 384 * the device before we can read in the new contents. 385 */ 386 abort(); /* TODO: block_write() */ 387 } 388 /* 389 * The block contains old or no data. We need to read the new 390 * contents from the device. 391 */ 370 392 rc = block_read(dev_handle, &bufpos, &buflen, &pos, b->data, 371 393 cache->block_size, cache->block_size); 372 394 assert(rc == EOK); 373 hash_table_insert(&cache->block_hash, &key, &b->hash_link); 374 } 375 376 futex_up(&cache->lock); 395 396 futex_up(&b->lock); 397 } 377 398 return b; 378 399 } … … 380 401 /** Release a reference to a block. 381 402 * 382 * If the last reference is dropped, the block is put on the free list. If the 383 * last reference is dropped and the block is dirty, it is first synced with the 384 * block device. 403 * If the last reference is dropped, the block is put on the free list. 385 404 * 386 405 * @param block Block of which a reference is to be released. … … 403 422 */ 404 423 list_append(&block->free_link, &cache->free_head); 405 /* Unlock the cache, but not the block. */406 futex_up(&cache->lock);407 if (block->dirty) {408 /*409 * The block is dirty and there is no one using it410 * at the moment, write it back to the device.411 */412 413 /* TODO: block_write() */414 block->dirty = false;415 }416 } else {417 futex_up(&cache->lock);418 424 } 419 425 futex_up(&block->lock); 426 futex_up(&cache->lock); 420 427 } 421 428
Note:
See TracChangeset
for help on using the changeset viewer.