Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 1fbe064b in mainline


Ignore:
Timestamp:
2009-06-26T21:34:47Z (12 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master
Children:
00fe6bb
Parents:
af65b72
Message:

Allow libblock to operate in write-through mode. With 'wtcache' mount option, FAT sets write-through mode on the cache.

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/bdd/bdd.c

    raf65b72 r1fbe064b  
    103103        }
    104104
    105         rc = block_cache_init(handle, BLOCK_SIZE, 2);
     105        rc = block_cache_init(handle, BLOCK_SIZE, 2, CACHE_MODE_WB);
    106106        if (rc != EOK) {
    107107                printf("Error: could not init block cache.\n");
  • uspace/lib/libblock/libblock.c

    raf65b72 r1fbe064b  
    6666        hash_table_t block_hash;
    6767        link_t free_head;
     68        enum cache_mode mode;
    6869} cache_t;
    6970
     
    8081} devcon_t;
    8182
     83static int write_block(devcon_t *devcon, bn_t boff, size_t block_size,
     84    const void *src);
     85
    8286static devcon_t *devcon_search(dev_handle_t dev_handle)
    8387{
     
    251255};
    252256
    253 int block_cache_init(dev_handle_t dev_handle, size_t size, unsigned blocks)
     257int block_cache_init(dev_handle_t dev_handle, size_t size, unsigned blocks,
     258    enum cache_mode mode)
    254259{
    255260        devcon_t *devcon = devcon_search(dev_handle);
     
    267272        cache->block_size = size;
    268273        cache->block_count = blocks;
     274        cache->mode = mode;
    269275
    270276        if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1,
     
    414420        devcon_t *devcon = devcon_search(block->dev_handle);
    415421        cache_t *cache;
     422        int rc;
    416423
    417424        assert(devcon);
     
    427434                 */
    428435                list_append(&block->free_link, &cache->free_head);
     436                if (cache->mode != CACHE_MODE_WB && block->dirty) {
     437                        rc = write_block(devcon, block->boff, block->size,
     438                            block->data);
     439                        assert(rc == EOK);
     440
     441                        block->dirty = false;
     442                }
    429443        }
    430444        fibril_mutex_unlock(&block->lock);
     
    491505}
    492506
     507/** Write block to block device.
     508 *
     509 * @param devcon        Device connection.
     510 * @param boff          Block index.
     511 * @param block_size    Block size.
     512 * @param src           Buffer containing the data to write.
     513 *
     514 * @return              EOK on success or negative error code on failure.
     515 */
     516static int write_block(devcon_t *devcon, bn_t boff, size_t block_size,
     517    const void *src)
     518{
     519        ipcarg_t retval;
     520        int rc;
     521
     522        assert(devcon);
     523        memcpy(devcon->com_area, src, block_size);
     524       
     525        rc = async_req_2_1(devcon->dev_phone, BD_WRITE_BLOCK,
     526            boff, block_size, &retval);
     527        if ((rc != EOK) || (retval != EOK))
     528                return (rc != EOK ? rc : (int) retval);
     529
     530        return EOK;
     531}
     532
    493533/** @}
    494534 */
  • uspace/lib/libblock/libblock.h

    raf65b72 r1fbe064b  
    8585} block_t;
    8686
     87/** Caching mode */
     88enum cache_mode {
     89        /** Write-Through */
     90        CACHE_MODE_WT,
     91        /** Write-Back */
     92        CACHE_MODE_WB
     93};
     94
    8795extern int block_init(dev_handle_t, size_t);
    8896extern void block_fini(dev_handle_t);
     
    9199extern void *block_bb_get(dev_handle_t);
    92100
    93 extern int block_cache_init(dev_handle_t, size_t, unsigned);
     101extern int block_cache_init(dev_handle_t, size_t, unsigned, enum cache_mode);
    94102
    95103extern block_t *block_get(dev_handle_t, bn_t, int flags);
  • uspace/srv/fs/fat/fat_ops.c

    raf65b72 r1fbe064b  
    771771{
    772772        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     773        enum cache_mode cmode;
    773774        fat_bs_t *bs;
    774775        uint16_t bps;
     
    798799        opts[size] = '\0';
    799800
     801        /* Check for option enabling write through. */
     802        if (str_cmp(opts, "wtcache") == 0)
     803                cmode = CACHE_MODE_WT;
     804        else
     805                cmode = CACHE_MODE_WB;
     806
    800807        /* initialize libblock */
    801808        rc = block_init(dev_handle, BS_SIZE);
     
    827834
    828835        /* Initialize the block cache */
    829         rc = block_cache_init(dev_handle, bps, 0 /* XXX */);
     836        rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode);
    830837        if (rc != EOK) {
    831838                block_fini(dev_handle);
Note: See TracChangeset for help on using the changeset viewer.