Changeset bd5f3b7 in mainline for uspace/lib/block/libblock.c


Ignore:
Timestamp:
2011-08-21T13:07:35Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
00aece0, f1a9e87
Parents:
86a34d3e (diff), a6480d5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    r86a34d3e rbd5f3b7  
    3939#include "libblock.h"
    4040#include "../../srv/vfs/vfs.h"
    41 #include <ipc/devmap.h>
     41#include <ipc/loc.h>
    4242#include <ipc/bd.h>
    4343#include <ipc/services.h>
     
    7878typedef struct {
    7979        link_t link;
    80         devmap_handle_t devmap_handle;
     80        service_id_t service_id;
    8181        async_sess_t *sess;
    8282        fibril_mutex_t comm_area_lock;
     
    9595static aoff64_t ba_ltop(devcon_t *, aoff64_t);
    9696
    97 static devcon_t *devcon_search(devmap_handle_t devmap_handle)
     97static devcon_t *devcon_search(service_id_t service_id)
    9898{
    9999        fibril_mutex_lock(&dcl_lock);
     
    101101        list_foreach(dcl, cur) {
    102102                devcon_t *devcon = list_get_instance(cur, devcon_t, link);
    103                 if (devcon->devmap_handle == devmap_handle) {
     103                if (devcon->service_id == service_id) {
    104104                        fibril_mutex_unlock(&dcl_lock);
    105105                        return devcon;
     
    111111}
    112112
    113 static int devcon_add(devmap_handle_t devmap_handle, async_sess_t *sess,
     113static int devcon_add(service_id_t service_id, async_sess_t *sess,
    114114    size_t bsize, void *comm_area, size_t comm_size)
    115115{
     
    124124       
    125125        link_initialize(&devcon->link);
    126         devcon->devmap_handle = devmap_handle;
     126        devcon->service_id = service_id;
    127127        devcon->sess = sess;
    128128        fibril_mutex_initialize(&devcon->comm_area_lock);
     
    137137        list_foreach(dcl, cur) {
    138138                devcon_t *d = list_get_instance(cur, devcon_t, link);
    139                 if (d->devmap_handle == devmap_handle) {
     139                if (d->service_id == service_id) {
    140140                        fibril_mutex_unlock(&dcl_lock);
    141141                        free(devcon);
     
    155155}
    156156
    157 int block_init(exch_mgmt_t mgmt, devmap_handle_t devmap_handle,
     157int block_init(exch_mgmt_t mgmt, service_id_t service_id,
    158158    size_t comm_size)
    159159{
     
    163163                return ENOMEM;
    164164       
    165         async_sess_t *sess = devmap_device_connect(mgmt, devmap_handle,
     165        async_sess_t *sess = loc_service_connect(mgmt, service_id,
    166166            IPC_FLAG_BLOCKING);
    167167        if (!sess) {
     
    190190        }
    191191       
    192         rc = devcon_add(devmap_handle, sess, bsize, comm_area, comm_size);
     192        rc = devcon_add(service_id, sess, bsize, comm_area, comm_size);
    193193        if (rc != EOK) {
    194194                munmap(comm_area, comm_size);
     
    200200}
    201201
    202 void block_fini(devmap_handle_t devmap_handle)
    203 {
    204         devcon_t *devcon = devcon_search(devmap_handle);
     202void block_fini(service_id_t service_id)
     203{
     204        devcon_t *devcon = devcon_search(service_id);
    205205        assert(devcon);
    206206       
    207207        if (devcon->cache)
    208                 (void) block_cache_fini(devmap_handle);
     208                (void) block_cache_fini(service_id);
    209209       
    210210        devcon_remove(devcon);
     
    219219}
    220220
    221 int block_bb_read(devmap_handle_t devmap_handle, aoff64_t ba)
     221int block_bb_read(service_id_t service_id, aoff64_t ba)
    222222{
    223223        void *bb_buf;
    224224        int rc;
    225225
    226         devcon_t *devcon = devcon_search(devmap_handle);
     226        devcon_t *devcon = devcon_search(service_id);
    227227        if (!devcon)
    228228                return ENOENT;
     
    249249}
    250250
    251 void *block_bb_get(devmap_handle_t devmap_handle)
    252 {
    253         devcon_t *devcon = devcon_search(devmap_handle);
     251void *block_bb_get(service_id_t service_id)
     252{
     253        devcon_t *devcon = devcon_search(service_id);
    254254        assert(devcon);
    255255        return devcon->bb_buf;
     
    258258static hash_index_t cache_hash(unsigned long *key)
    259259{
    260         return *key & (CACHE_BUCKETS - 1);
     260        return MERGE_LOUP32(key[0], key[1]) & (CACHE_BUCKETS - 1);
    261261}
    262262
     
    264264{
    265265        block_t *b = hash_table_get_instance(item, block_t, hash_link);
    266         return b->lba == *key;
     266        return b->lba == MERGE_LOUP32(key[0], key[1]);
    267267}
    268268
     
    277277};
    278278
    279 int block_cache_init(devmap_handle_t devmap_handle, size_t size, unsigned blocks,
     279int block_cache_init(service_id_t service_id, size_t size, unsigned blocks,
    280280    enum cache_mode mode)
    281281{
    282         devcon_t *devcon = devcon_search(devmap_handle);
     282        devcon_t *devcon = devcon_search(service_id);
    283283        cache_t *cache;
    284284        if (!devcon)
     
    305305        cache->blocks_cluster = cache->lblock_size / devcon->pblock_size;
    306306
    307         if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1,
     307        if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 2,
    308308            &cache_ops)) {
    309309                free(cache);
     
    315315}
    316316
    317 int block_cache_fini(devmap_handle_t devmap_handle)
    318 {
    319         devcon_t *devcon = devcon_search(devmap_handle);
     317int block_cache_fini(service_id_t service_id)
     318{
     319        devcon_t *devcon = devcon_search(service_id);
    320320        cache_t *cache;
    321321        int rc;
     
    344344                }
    345345
    346                 unsigned long key = b->lba;
    347                 hash_table_remove(&cache->block_hash, &key, 1);
     346                unsigned long key[2] = {
     347                        LOWER32(b->lba),
     348                        UPPER32(b->lba)
     349                };
     350                hash_table_remove(&cache->block_hash, key, 2);
    348351               
    349352                free(b->data);
     
    384387 * @param block                 Pointer to where the function will store the
    385388 *                              block pointer on success.
    386  * @param devmap_handle         Device handle of the block device.
     389 * @param service_id            Service ID of the block device.
    387390 * @param ba                    Block address (logical).
    388391 * @param flags                 If BLOCK_FLAGS_NOREAD is specified, block_get()
     
    392395 * @return                      EOK on success or a negative error code.
    393396 */
    394 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags)
     397int block_get(block_t **block, service_id_t service_id, aoff64_t ba, int flags)
    395398{
    396399        devcon_t *devcon;
     
    398401        block_t *b;
    399402        link_t *l;
    400         unsigned long key = ba;
     403        unsigned long key[2] = {
     404                LOWER32(ba),
     405                UPPER32(ba)
     406        };
     407
    401408        int rc;
    402409       
    403         devcon = devcon_search(devmap_handle);
     410        devcon = devcon_search(service_id);
    404411
    405412        assert(devcon);
     
    413420
    414421        fibril_mutex_lock(&cache->lock);
    415         l = hash_table_find(&cache->block_hash, &key);
     422        l = hash_table_find(&cache->block_hash, key);
    416423        if (l) {
    417424found:
     
    451458                         * Try to recycle a block from the free list.
    452459                         */
    453                         unsigned long temp_key;
    454460recycle:
    455461                        if (list_empty(&cache->free_list)) {
     
    499505                                        goto retry;
    500506                                }
    501                                 l = hash_table_find(&cache->block_hash, &key);
     507                                l = hash_table_find(&cache->block_hash, key);
    502508                                if (l) {
    503509                                        /*
     
    522528                         */
    523529                        list_remove(&b->free_link);
    524                         temp_key = b->lba;
    525                         hash_table_remove(&cache->block_hash, &temp_key, 1);
     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);
    526535                }
    527536
    528537                block_initialize(b);
    529                 b->devmap_handle = devmap_handle;
     538                b->service_id = service_id;
    530539                b->size = cache->lblock_size;
    531540                b->lba = ba;
    532541                b->pba = ba_ltop(devcon, b->lba);
    533                 hash_table_insert(&cache->block_hash, &key, &b->hash_link);
     542                hash_table_insert(&cache->block_hash, key, &b->hash_link);
    534543
    535544                /*
     
    577586int block_put(block_t *block)
    578587{
    579         devcon_t *devcon = devcon_search(block->devmap_handle);
     588        devcon_t *devcon = devcon_search(block->service_id);
    580589        cache_t *cache;
    581590        unsigned blocks_cached;
     
    643652                         * Take the block out of the cache and free it.
    644653                         */
    645                         unsigned long key = block->lba;
    646                         hash_table_remove(&cache->block_hash, &key, 1);
     654                        unsigned long key[2] = {
     655                                LOWER32(block->lba),
     656                                UPPER32(block->lba)
     657                        };
     658                        hash_table_remove(&cache->block_hash, key, 2);
    647659                        fibril_mutex_unlock(&block->lock);
    648660                        free(block->data);
     
    675687/** Read sequential data from a block device.
    676688 *
    677  * @param devmap_handle Device handle of the block device.
     689 * @param service_id    Service ID of the block device.
    678690 * @param bufpos        Pointer to the first unread valid offset within the
    679691 *                      communication buffer.
     
    687699 * @return              EOK on success or a negative return code on failure.
    688700 */
    689 int block_seqread(devmap_handle_t devmap_handle, size_t *bufpos, size_t *buflen,
     701int block_seqread(service_id_t service_id, size_t *bufpos, size_t *buflen,
    690702    aoff64_t *pos, void *dst, size_t size)
    691703{
     
    695707        devcon_t *devcon;
    696708
    697         devcon = devcon_search(devmap_handle);
     709        devcon = devcon_search(service_id);
    698710        assert(devcon);
    699711        block_size = devcon->pblock_size;
     
    741753/** Read blocks directly from device (bypass cache).
    742754 *
    743  * @param devmap_handle Device handle of the block device.
     755 * @param service_id    Service ID of the block device.
    744756 * @param ba            Address of first block (physical).
    745757 * @param cnt           Number of blocks.
     
    748760 * @return              EOK on success or negative error code on failure.
    749761 */
    750 int block_read_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt, void *buf)
     762int block_read_direct(service_id_t service_id, aoff64_t ba, size_t cnt, void *buf)
    751763{
    752764        devcon_t *devcon;
    753765        int rc;
    754766
    755         devcon = devcon_search(devmap_handle);
     767        devcon = devcon_search(service_id);
    756768        assert(devcon);
    757769       
     
    769781/** Write blocks directly to device (bypass cache).
    770782 *
    771  * @param devmap_handle Device handle of the block device.
     783 * @param service_id    Service ID of the block device.
    772784 * @param ba            Address of first block (physical).
    773785 * @param cnt           Number of blocks.
     
    776788 * @return              EOK on success or negative error code on failure.
    777789 */
    778 int block_write_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt,
     790int block_write_direct(service_id_t service_id, aoff64_t ba, size_t cnt,
    779791    const void *data)
    780792{
     
    782794        int rc;
    783795
    784         devcon = devcon_search(devmap_handle);
     796        devcon = devcon_search(service_id);
    785797        assert(devcon);
    786798       
     
    797809/** Get device block size.
    798810 *
    799  * @param devmap_handle Device handle of the block device.
     811 * @param service_id    Service ID of the block device.
    800812 * @param bsize         Output block size.
    801813 *
    802814 * @return              EOK on success or negative error code on failure.
    803815 */
    804 int block_get_bsize(devmap_handle_t devmap_handle, size_t *bsize)
     816int block_get_bsize(service_id_t service_id, size_t *bsize)
    805817{
    806818        devcon_t *devcon;
    807819
    808         devcon = devcon_search(devmap_handle);
     820        devcon = devcon_search(service_id);
    809821        assert(devcon);
    810822       
     
    814826/** Get number of blocks on device.
    815827 *
    816  * @param devmap_handle Device handle of the block device.
     828 * @param service_id    Service ID of the block device.
    817829 * @param nblocks       Output number of blocks.
    818830 *
    819831 * @return              EOK on success or negative error code on failure.
    820832 */
    821 int block_get_nblocks(devmap_handle_t devmap_handle, aoff64_t *nblocks)
    822 {
    823         devcon_t *devcon = devcon_search(devmap_handle);
     833int block_get_nblocks(service_id_t service_id, aoff64_t *nblocks)
     834{
     835        devcon_t *devcon = devcon_search(service_id);
    824836        assert(devcon);
    825837       
     
    829841/** Read bytes directly from the device (bypass cache)
    830842 *
    831  * @param devmap_handle Device handle of the block device.
     843 * @param service_id    Service ID of the block device.
    832844 * @param abs_offset    Absolute offset in bytes where to start reading
    833845 * @param bytes                 Number of bytes to read
     
    836848 * @return              EOK on success or negative error code on failure.
    837849 */
    838 int block_read_bytes_direct(devmap_handle_t devmap_handle, aoff64_t abs_offset,
     850int block_read_bytes_direct(service_id_t service_id, aoff64_t abs_offset,
    839851    size_t bytes, void *data)
    840852{
     
    848860        size_t offset;
    849861       
    850         rc = block_get_bsize(devmap_handle, &phys_block_size);
     862        rc = block_get_bsize(service_id, &phys_block_size);
    851863        if (rc != EOK) {
    852864                return rc;
     
    866878        }
    867879       
    868         rc = block_read_direct(devmap_handle, first_block, blocks, buffer);
     880        rc = block_read_direct(service_id, first_block, blocks, buffer);
    869881        if (rc != EOK) {
    870882                free(buffer);
     
    900912                printf("Error %d reading %zu blocks starting at block %" PRIuOFF64
    901913                    " from device handle %" PRIun "\n", rc, cnt, ba,
    902                     devcon->devmap_handle);
     914                    devcon->service_id);
    903915#ifndef NDEBUG
    904916                stacktrace_print();
     
    929941        if (rc != EOK) {
    930942                printf("Error %d writing %zu blocks starting at block %" PRIuOFF64
    931                     " to device handle %" PRIun "\n", rc, cnt, ba, devcon->devmap_handle);
     943                    " to device handle %" PRIun "\n", rc, cnt, ba, devcon->service_id);
    932944#ifndef NDEBUG
    933945                stacktrace_print();
Note: See TracChangeset for help on using the changeset viewer.