Changeset a6d97fb9 in mainline


Ignore:
Timestamp:
2008-11-02T20:16:16Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ab579fa
Parents:
d5a720cf
Message:

Dirty blocks will be synced only before being recycled.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libblock/libblock.c

    rd5a720cf ra6d97fb9  
    325325                        list_remove(&b->free_link);
    326326                futex_up(&b->lock);
     327                futex_up(&cache->lock);
    327328        } else {
    328329                /*
     
    333334                size_t buflen = 0;
    334335                off_t pos = boff * cache->block_size;
     336                bool sync = false;
    335337
    336338                if (cache_can_grow(cache)) {
     
    358360                        list_remove(l);
    359361                        b = hash_table_get_instance(l, block_t, hash_link);
    360                         assert(!b->dirty);
     362                        sync = b->dirty;
    361363                        temp_key = b->boff;
    362364                        hash_table_remove(&cache->block_hash, &temp_key, 1);
     
    367369                b->size = cache->block_size;
    368370                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                 */
    370392                rc = block_read(dev_handle, &bufpos, &buflen, &pos, b->data,
    371393                    cache->block_size, cache->block_size);
    372394                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        }
    377398        return b;
    378399}
     
    380401/** Release a reference to a block.
    381402 *
    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.
    385404 *
    386405 * @param block         Block of which a reference is to be released.
     
    403422                 */
    404423                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 it
    410                          * 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);
    418424        }
    419425        futex_up(&block->lock);
     426        futex_up(&cache->lock);
    420427}
    421428
Note: See TracChangeset for help on using the changeset viewer.