Changeset 1d8cdb1 in mainline for uspace/lib


Ignore:
Timestamp:
2008-11-18T20:28:17Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
18c485a
Parents:
26fa0f9f
Message:

Avoid unnecessary block reads in block_get().

Location:
uspace/lib/libblock
Files:
2 edited

Legend:

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

    r26fa0f9f r1d8cdb1  
    297297 * @param dev_handle            Device handle of the block device.
    298298 * @param boff                  Block offset.
     299 * @param flags                 If BLOCK_FLAGS_NOREAD is specified, block_get()
     300 *                              will not read the contents of the block from the
     301 *                              device.
    299302 *
    300303 * @return                      Block structure.
    301304 */
    302 block_t *block_get(dev_handle_t dev_handle, bn_t boff)
     305block_t *block_get(dev_handle_t dev_handle, bn_t boff, int flags)
    303306{
    304307        devcon_t *devcon;
     
    386389                        abort();        /* TODO: block_write() */
    387390                }
    388                 /*
    389                  * The block contains old or no data. We need to read the new
    390                  * contents from the device.
    391                  */
    392                 rc = block_read(dev_handle, &bufpos, &buflen, &pos, b->data,
    393                     cache->block_size, cache->block_size);
    394                 assert(rc == EOK);
     391                if (!(flags & BLOCK_FLAGS_NOREAD)) {
     392                        /*
     393                         * The block contains old or no data. We need to read
     394                         * the new contents from the device.
     395                         */
     396                        rc = block_read(dev_handle, &bufpos, &buflen, &pos,
     397                            b->data, cache->block_size, cache->block_size);
     398                        assert(rc == EOK);
     399                }
    395400
    396401                futex_up(&b->lock);
  • uspace/lib/libblock/libblock.h

    r26fa0f9f r1d8cdb1  
    4545#include <libadt/list.h>
    4646
     47/*
     48 * Flags that can be used with block_get().
     49 */
     50
     51/**
     52 * This macro is a symbolic value for situations where no special flags are
     53 * needed.
     54 */
     55#define BLOCK_FLAGS_NONE        0
     56
     57/**
     58 * When the client of block_get() intends to overwrite the current contents of
     59 * the block, this flag is used to avoid the unnecessary read.
     60 */
     61#define BLOCK_FLAGS_NOREAD      1
     62
    4763typedef unsigned bn_t;  /**< Block number type. */
    4864
     
    7894extern int block_cache_init(dev_handle_t, size_t, unsigned);
    7995
    80 extern block_t *block_get(dev_handle_t, bn_t);
     96extern block_t *block_get(dev_handle_t, bn_t, int flags);
    8197extern void block_put(block_t *);
    8298
Note: See TracChangeset for help on using the changeset viewer.