Changeset f0e1ac9 in mainline


Ignore:
Timestamp:
2010-11-27T17:13:30Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
41a7f62
Parents:
3e94678 (diff), d70d80ed (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 from lp:~jsvoboda/helenos/bd (small-to-large block translation).

Location:
uspace
Files:
3 edited

Legend:

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

    r3e94678 rf0e1ac9  
    6666        fibril_mutex_t lock;
    6767        size_t lblock_size;             /**< Logical block size. */
     68        unsigned blocks_cluster;        /**< Physical blocks per block_t */
    6869        unsigned block_count;           /**< Total number of blocks. */
    6970        unsigned blocks_cached;         /**< Number of cached blocks. */
     
    9091static int get_block_size(int dev_phone, size_t *bsize);
    9192static int get_num_blocks(int dev_phone, aoff64_t *nblocks);
     93static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba);
    9294
    9395static devcon_t *devcon_search(devmap_handle_t devmap_handle)
     
    259261{
    260262        block_t *b = hash_table_get_instance(item, block_t, hash_link);
    261         return b->boff == *key;
     263        return b->lba == *key;
    262264}
    263265
     
    292294        cache->mode = mode;
    293295
    294         /* No block size translation a.t.m. */
    295         assert(cache->lblock_size == devcon->pblock_size);
     296        /* Allow 1:1 or small-to-large block size translation */
     297        if (cache->lblock_size % devcon->pblock_size != 0)
     298                return ENOTSUP;
     299
     300        cache->blocks_cluster = cache->lblock_size / devcon->pblock_size;
    296301
    297302        if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1,
     
    329334                if (b->dirty) {
    330335                        memcpy(devcon->comm_area, b->data, b->size);
    331                         rc = write_blocks(devcon, b->boff, 1);
     336                        rc = write_blocks(devcon, b->pba, cache->blocks_cluster);
    332337                        if (rc != EOK)
    333338                                return rc;
    334339                }
    335340
    336                 unsigned long key = b->boff;
     341                unsigned long key = b->lba;
    337342                hash_table_remove(&cache->block_hash, &key, 1);
    338343               
     
    375380 *                              block pointer on success.
    376381 * @param devmap_handle         Device handle of the block device.
    377  * @param boff                  Block offset.
     382 * @param ba                    Block address (logical).
    378383 * @param flags                 If BLOCK_FLAGS_NOREAD is specified, block_get()
    379384 *                              will not read the contents of the block from the
     
    382387 * @return                      EOK on success or a negative error code.
    383388 */
    384 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t boff, int flags)
     389int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags)
    385390{
    386391        devcon_t *devcon;
     
    388393        block_t *b;
    389394        link_t *l;
    390         unsigned long key = boff;
     395        unsigned long key = ba;
    391396        int rc;
    392397       
     
    465470                                fibril_mutex_lock(&devcon->comm_area_lock);
    466471                                memcpy(devcon->comm_area, b->data, b->size);
    467                                 rc = write_blocks(devcon, b->boff, 1);
     472                                rc = write_blocks(devcon, b->pba,
     473                                    cache->blocks_cluster);
    468474                                fibril_mutex_unlock(&devcon->comm_area_lock);
    469475                                if (rc != EOK) {
     
    495501                         */
    496502                        list_remove(&b->free_link);
    497                         temp_key = b->boff;
     503                        temp_key = b->lba;
    498504                        hash_table_remove(&cache->block_hash, &temp_key, 1);
    499505                }
     
    502508                b->devmap_handle = devmap_handle;
    503509                b->size = cache->lblock_size;
    504                 b->boff = boff;
     510                b->lba = ba;
     511                b->pba = ba_ltop(devcon, b->lba);
    505512                hash_table_insert(&cache->block_hash, &key, &b->hash_link);
    506513
     
    519526                         */
    520527                        fibril_mutex_lock(&devcon->comm_area_lock);
    521                         rc = read_blocks(devcon, b->boff, 1);
     528                        rc = read_blocks(devcon, b->pba, cache->blocks_cluster);
    522529                        memcpy(b->data, devcon->comm_area, cache->lblock_size);
    523530                        fibril_mutex_unlock(&devcon->comm_area_lock);
     
    580587                fibril_mutex_lock(&devcon->comm_area_lock);
    581588                memcpy(devcon->comm_area, block->data, block->size);
    582                 rc = write_blocks(devcon, block->boff, 1);
     589                rc = write_blocks(devcon, block->pba, cache->blocks_cluster);
    583590                fibril_mutex_unlock(&devcon->comm_area_lock);
    584591                block->dirty = false;
     
    614621                         * Take the block out of the cache and free it.
    615622                         */
    616                         unsigned long key = block->boff;
     623                        unsigned long key = block->lba;
    617624                        hash_table_remove(&cache->block_hash, &key, 1);
    618625                        free(block);
     
    712719 *
    713720 * @param devmap_handle Device handle of the block device.
    714  * @param ba            Address of first block.
     721 * @param ba            Address of first block (physical).
    715722 * @param cnt           Number of blocks.
    716723 * @param src           Buffer for storing the data.
     
    740747 *
    741748 * @param devmap_handle Device handle of the block device.
    742  * @param ba            Address of first block.
     749 * @param ba            Address of first block (physical).
    743750 * @param cnt           Number of blocks.
    744751 * @param src           The data to be written.
     
    879886}
    880887
     888/** Convert logical block address to physical block address. */
     889static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba)
     890{
     891        assert(devcon->cache != NULL);
     892        return lba * devcon->cache->blocks_cluster;
     893}
     894
    881895/** @}
    882896 */
  • uspace/lib/block/libblock.h

    r3e94678 rf0e1ac9  
    7373        /** Handle of the device where the block resides. */
    7474        devmap_handle_t devmap_handle;
    75         /** Block offset on the block device. Counted in 'size'-byte blocks. */
    76         aoff64_t boff;
     75        /** Logical block address */
     76        aoff64_t lba;
     77        /** Physical block address */
     78        aoff64_t pba;
    7779        /** Size of the block. */
    7880        size_t size;
  • uspace/srv/bd/file_bd/file_bd.c

    r3e94678 rf0e1ac9  
    5656#define NAME "file_bd"
    5757
    58 static const size_t block_size = 512;
     58#define DEFAULT_BLOCK_SIZE 512
     59
     60static size_t block_size;
    5961static aoff64_t num_blocks;
    6062static FILE *img;
     
    6365static fibril_mutex_t dev_lock;
    6466
     67static void print_usage(void);
    6568static int file_bd_init(const char *fname);
    6669static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall);
     
    7174{
    7275        int rc;
     76        char *image_name;
     77        char *device_name;
    7378
    7479        printf(NAME ": File-backed block device driver\n");
    7580
    76         if (argc != 3) {
    77                 printf("Expected two arguments (image name, device name).\n");
     81        block_size = DEFAULT_BLOCK_SIZE;
     82
     83        ++argv; --argc;
     84        while (*argv != NULL && (*argv)[0] == '-') {
     85                /* Option */
     86                if (str_cmp(*argv, "-b") == 0) {
     87                        if (argc < 2) {
     88                                printf("Argument missing.\n");
     89                                print_usage();
     90                                return -1;
     91                        }
     92
     93                        rc = str_size_t(argv[1], NULL, 10, true, &block_size);
     94                        if (rc != EOK || block_size == 0) {
     95                                printf("Invalid block size '%s'.\n", argv[1]);
     96                                print_usage();
     97                                return -1;
     98                        }
     99                        ++argv; --argc;
     100                } else {
     101                        printf("Invalid option '%s'.\n", *argv);
     102                        print_usage();
     103                        return -1;
     104                }
     105                ++argv; --argc;
     106        }
     107
     108        if (argc < 2) {
     109                printf("Missing arguments.\n");
     110                print_usage();
    78111                return -1;
    79112        }
    80113
    81         if (file_bd_init(argv[1]) != EOK)
     114        image_name = argv[0];
     115        device_name = argv[1];
     116
     117        if (file_bd_init(image_name) != EOK)
    82118                return -1;
    83119
    84         rc = devmap_device_register(argv[2], &devmap_handle);
     120        rc = devmap_device_register(device_name, &devmap_handle);
    85121        if (rc != EOK) {
    86122                devmap_hangup_phone(DEVMAP_DRIVER);
    87                 printf(NAME ": Unable to register device %s.\n",
    88                         argv[2]);
     123                printf(NAME ": Unable to register device '%s'.\n",
     124                        device_name);
    89125                return rc;
    90126        }
     
    96132        /* Not reached */
    97133        return 0;
     134}
     135
     136static void print_usage(void)
     137{
     138        printf("Usage: " NAME " [-b <block_size>] <image_file> <device_name>\n");
    98139}
    99140
Note: See TracChangeset for help on using the changeset viewer.