Changeset 73c09b3b in rtems


Ignore:
Timestamp:
05/30/12 11:40:34 (11 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
f164ae75
Parents:
2c6cc3c
git-author:
Sebastian Huber <sebastian.huber@…> (05/30/12 11:40:34)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/31/12 09:05:48)
Message:

libblock: Simplify disk management

Add block_count and media_blocks_per_block to rtems_disk_device. Add
and use rtems_disk_init_phys() and rtems_disk_init_log().

Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libblock/Makefile.am

    r2c6cc3c r73c09b3b  
    99    src/blkdev-ops.c \
    1010    src/diskdevs.c \
     11    src/diskdevs-init.c \
    1112    src/flashdisk.c \
    1213    src/ramdisk-driver.c \
  • cpukit/libblock/include/rtems/bdbuf.h

    r2c6cc3c r73c09b3b  
    142142 * to another requester until released back to the cache.  The same goes to a
    143143 * buffer in the transfer state.  The transfer state means being read or
    144  * written.  If the file system has modifed the block and releases it as
     144 * written.  If the file system has modified the block and releases it as
    145145 * modified it placed on the cache's modified list and a hold timer
    146146 * initialised.  The buffer is held for the hold time before being written to
     
    463463/**
    464464 * Get block buffer for data to be written into. The buffers is set to the
    465  * access or modifed access state. If the buffer is in the cache and modified
     465 * access or modified access state. If the buffer is in the cache and modified
    466466 * the state is access modified else the state is access. This buffer contents
    467467 * are not initialised if the buffer is not already in the cache. If the block
     
    499499 * Get the block buffer and if not already in the cache read from the disk. If
    500500 * specified block already cached return. The buffer is set to the access or
    501  * modifed access state. If the buffer is in the cache and modified the state
     501 * modified access state. If the buffer is in the cache and modified the state
    502502 * is access modified else the state is access. If block is already being read
    503503 * from disk for being written to disk this call blocks. If the buffer is
     
    602602 * Synchronize all modified buffers for this device with the disk and wait
    603603 * until the transfers have completed. The sync mutex for the cache is locked
    604  * stopping the addition of any further modifed buffers. It is only the
     604 * stopping the addition of any further modified buffers. It is only the
    605605 * currently modified buffers that are written.
    606606 *
     
    636636 * @brief Sets the block size of a disk device.
    637637 *
    638  * This will also change the block_to_media_block_shift and bds_per_group
    639  * fields of the disk device.
     638 * This will set the block size derived fields of the disk device.
    640639 *
    641640 * Before you can use this function, the rtems_bdbuf_init() routine must be
  • cpukit/libblock/include/rtems/diskdevs.h

    r2c6cc3c r73c09b3b  
    9393
    9494  /**
    95    * @brief Start block number.
    96    *
    97    * Equals zero for physical devices.  It is a block offset to the related
    98    * physical device for logical device.
     95   * @brief Start media block number.
     96   *
     97   * Equals zero for physical devices.  It is a media block offset to the
     98   * related physical device for logical device.
    9999   */
    100100  rtems_blkdev_bnum start;
    101101
    102102  /**
    103    * @brief Size of the physical or logical disk in blocks.
     103   * @brief Size of the physical or logical disk in media blocks.
    104104   */
    105105  rtems_blkdev_bnum size;
    106106
    107107  /**
    108    * @brief Device block size in bytes.
    109    *
    110    * This is the minimum transfer unit.  It must be positive.
     108   * @brief Media block size in bytes.
     109   *
     110   * This is the media transfer unit the hardware defaults to.
     111   */
     112  uint32_t media_block_size;
     113
     114  /**
     115   * @brief Block size in bytes.
     116   *
     117   * This is the minimum transfer unit.  It may be a multiple of the media
     118   * block size. It must be positive.
    111119   *
    112120   * @see rtems_bdbuf_set_block_size().
     
    115123
    116124  /**
    117    * @brief Device media block size in bytes.
    118    *
    119    * This is the media transfer unit the hardware defaults to.
    120    */
    121   uint32_t media_block_size;
     125   * @brief Block count.
     126   *
     127   * @see rtems_bdbuf_set_block_size().
     128   */
     129  rtems_blkdev_bnum block_count;
     130
     131  /**
     132   * @brief Media blocks per device blocks.
     133   *
     134   * @see rtems_bdbuf_set_block_size().
     135   */
     136  uint32_t media_blocks_per_block;
    122137
    123138  /**
     
    260275 * A logical disk manages a subset of consecutive blocks contained in the
    261276 * physical disk with identifier @a phys.  The start block index of the logical
    262  * disk device is @a begin_block.  The block count of the logcal disk will be
     277 * disk device is @a block_begin.  The block count of the logcal disk will be
    263278 * @a block_count.  The blocks must be within the range of blocks managed by
    264279 * the associated physical disk device.  A device node will be registered in
     
    279294  dev_t dev,
    280295  dev_t phys,
    281   rtems_blkdev_bnum begin_block,
     296  rtems_blkdev_bnum block_begin,
    282297  rtems_blkdev_bnum block_count,
    283298  const char *name
     
    374389rtems_disk_device *rtems_disk_next(dev_t dev);
    375390
     391/* Internal function, do not use */
     392rtems_status_code rtems_disk_init_phys(
     393  rtems_disk_device *dd,
     394  uint32_t block_size,
     395  rtems_blkdev_bnum block_count,
     396  rtems_block_device_ioctl handler,
     397  void *driver_data
     398);
     399
     400/* Internal function, do not use */
     401rtems_status_code rtems_disk_init_log(
     402  rtems_disk_device *dd,
     403  rtems_disk_device *phys_dd,
     404  rtems_blkdev_bnum block_begin,
     405  rtems_blkdev_bnum block_count
     406);
     407
    376408#ifdef __cplusplus
    377409}
  • cpukit/libblock/src/bdbuf.c

    r2c6cc3c r73c09b3b  
    17551755                             rtems_blkdev_bnum       *media_block_ptr)
    17561756{
    1757   /*
    1758    * Compute the media block number. Drivers work with media block number not
    1759    * the block number a BD may have as this depends on the block size set by
    1760    * the user.
    1761    */
    1762   rtems_blkdev_bnum mb = rtems_bdbuf_media_block (dd, block);
    1763   if (mb >= dd->size)
    1764   {
    1765     return RTEMS_INVALID_ID;
    1766   }
    1767 
    1768   *media_block_ptr = mb + dd->start;
    1769 
    1770   return RTEMS_SUCCESSFUL;
     1757  rtems_status_code sc = RTEMS_SUCCESSFUL;
     1758
     1759  if (block < dd->block_count)
     1760  {
     1761    /*
     1762     * Compute the media block number. Drivers work with media block number not
     1763     * the block number a BD may have as this depends on the block size set by
     1764     * the user.
     1765     */
     1766    *media_block_ptr = rtems_bdbuf_media_block (dd, block) + dd->start;
     1767  }
     1768  else
     1769  {
     1770    sc = RTEMS_INVALID_ID;
     1771  }
     1772
     1773  return sc;
    17711774}
    17721775
     
    29102913
    29112914      dd->block_size = block_size;
     2915      dd->block_count = dd->size / media_blocks_per_block;
     2916      dd->media_blocks_per_block = media_blocks_per_block;
    29122917      dd->block_to_media_block_shift = block_to_media_block_shift;
    29132918      dd->bds_per_group = bds_per_group;
  • cpukit/libblock/src/blkdev-imfs.c

    r2c6cc3c r73c09b3b  
    270270{
    271271  rtems_status_code sc = RTEMS_SUCCESSFUL;
    272 
    273   if (block_count > 0) {
    274     rtems_blkdev_imfs_context *ctx = calloc(1, sizeof(*ctx));
    275 
    276     if (ctx != NULL) {
    277       rtems_disk_device *dd = &ctx->dd;
    278 
    279       ctx->fd = -1;
    280 
    281       dd->phys_dev = dd;
    282       dd->size = block_count;
    283       dd->media_block_size = block_size;
    284       dd->ioctl = handler;
    285       dd->driver_data = driver_data;
    286 
    287       if ((*handler)(dd, RTEMS_BLKIO_CAPABILITIES, &dd->capabilities) != 0) {
    288         dd->capabilities = 0;
    289       }
    290 
    291       sc = rtems_bdbuf_set_block_size(dd, block_size);
    292       if (sc == RTEMS_SUCCESSFUL) {
    293         int rv = IMFS_make_generic_node(
    294           device,
    295           S_IFBLK | S_IRWXU | S_IRWXG | S_IRWXO,
    296           &rtems_blkdev_imfs_control,
    297           ctx
    298         );
    299 
    300         if (rv != 0) {
    301           free(ctx);
    302           sc = RTEMS_UNSATISFIED;
    303         }
    304       } else {
     272  rtems_blkdev_imfs_context *ctx = malloc(sizeof(*ctx));
     273
     274  if (ctx != NULL) {
     275    sc = rtems_disk_init_phys(
     276      &ctx->dd,
     277      block_size,
     278      block_count,
     279      handler,
     280      driver_data
     281    );
     282
     283    ctx->fd = -1;
     284
     285    if (sc == RTEMS_SUCCESSFUL) {
     286      int rv = IMFS_make_generic_node(
     287        device,
     288        S_IFBLK | S_IRWXU | S_IRWXG | S_IRWXO,
     289        &rtems_blkdev_imfs_control,
     290        ctx
     291      );
     292
     293      if (rv != 0) {
    305294        free(ctx);
    306       }
    307     } else {
    308       sc = RTEMS_NO_MEMORY;
    309     }
    310   } else {
    311     sc = RTEMS_INVALID_NUMBER;
     295        sc = RTEMS_UNSATISFIED;
     296      }
     297    } else {
     298      free(ctx);
     299    }
     300  } else {
     301    sc = RTEMS_NO_MEMORY;
    312302  }
    313303
     
    331321    rv = fstat(fd, &st);
    332322    if (rv == 0 && S_ISBLK(st.st_mode)) {
    333       rtems_disk_device *dd;
    334 
    335       rv = rtems_disk_fd_get_disk_device(fd, &dd);
     323      rtems_disk_device *phys_dd;
     324
     325      rv = rtems_disk_fd_get_disk_device(fd, &phys_dd);
    336326      if (rv == 0) {
    337         rtems_blkdev_bnum device_block_count = rtems_disk_get_block_count(dd);
    338 
    339         if (
    340           block_begin < device_block_count
    341             && block_count > 0
    342             && block_count <= device_block_count - block_begin
    343         ) {
    344           rtems_blkdev_imfs_context *ctx = malloc(sizeof(*ctx));
    345 
    346           if (ctx != NULL) {
    347             memcpy(&ctx->dd, dd, sizeof(ctx->dd));
    348 
    349             ctx->dd.start = block_begin;
    350             ctx->dd.size = block_count;
     327        rtems_blkdev_imfs_context *ctx = malloc(sizeof(*ctx));
     328
     329        if (ctx != NULL) {
     330          sc = rtems_disk_init_log(
     331            &ctx->dd,
     332            phys_dd,
     333            block_begin,
     334            block_count
     335          );
     336
     337          if (sc == RTEMS_SUCCESSFUL) {
    351338            ctx->fd = fd;
    352339
     
    363350            }
    364351          } else {
    365             sc = RTEMS_NO_MEMORY;
     352            free(ctx);
    366353          }
    367354        } else {
    368           sc = RTEMS_INVALID_NUMBER;
     355          sc = RTEMS_NO_MEMORY;
    369356        }
    370357      } else {
  • cpukit/libblock/src/diskdevs.c

    r2c6cc3c r73c09b3b  
    1111 * Author: Victor V. Vengerov <vvv@oktet.ru>
    1212 *
    13  * Copyright (c) 2009 embedded brains GmbH.
     13 * Copyright (c) 2009-2012 embedded brains GmbH.
    1414 */
    1515
     
    171171
    172172static rtems_status_code
    173 create_disk(dev_t dev, const char *name, rtems_disk_device **dd_ptr)
     173create_disk(
     174  dev_t dev,
     175  const char *name,
     176  rtems_disk_device **dd_ptr,
     177  char **alloc_name_ptr
     178)
    174179{
    175180  rtems_disk_device **dd_entry = create_disk_table_entry(dev);
     
    208213  }
    209214
    210   dd->dev = dev;
    211   dd->name = alloc_name;
    212   dd->uses = 0;
    213   dd->deleted = false;
    214 
    215215  *dd_entry = dd;
    216216  *dd_ptr = dd;
     217  *alloc_name_ptr = alloc_name;
    217218
    218219  return RTEMS_SUCCESSFUL;
     
    239240  rtems_disk_device *dd = NULL;
    240241  rtems_status_code sc = RTEMS_SUCCESSFUL;
     242  char *alloc_name = NULL;
    241243
    242244  if (handler == NULL) {
     
    249251  }
    250252
    251   sc = create_disk(dev, name, &dd);
     253  sc = create_disk(dev, name, &dd, &alloc_name);
    252254  if (sc != RTEMS_SUCCESSFUL) {
    253255    disk_unlock();
     
    256258  }
    257259
    258   dd->phys_dev = dd;
    259   dd->start = 0;
    260   dd->size = block_count;
    261   dd->media_block_size = block_size;
    262   dd->ioctl = handler;
    263   dd->driver_data = driver_data;
    264 
    265   if ((*handler)(dd, RTEMS_BLKIO_CAPABILITIES, &dd->capabilities) < 0) {
    266     dd->capabilities = 0;
    267   }
    268 
    269   sc = rtems_bdbuf_set_block_size(dd, block_size);
     260  sc = rtems_disk_init_phys(
     261    dd,
     262    block_size,
     263    block_count,
     264    handler,
     265    driver_data
     266  );
     267
     268  dd->dev = dev;
     269  dd->name = alloc_name;
     270
    270271  if (sc != RTEMS_SUCCESSFUL) {
    271272    dd->ioctl = null_handler;
     
    290291  dev_t dev,
    291292  dev_t phys,
    292   rtems_blkdev_bnum begin_block,
     293  rtems_blkdev_bnum block_begin,
    293294  rtems_blkdev_bnum block_count,
    294295  const char *name
     
    296297{
    297298  rtems_status_code sc = RTEMS_SUCCESSFUL;
    298   rtems_disk_device *physical_disk = NULL;
     299  rtems_disk_device *phys_dd = NULL;
    299300  rtems_disk_device *dd = NULL;
    300   rtems_blkdev_bnum end_block = begin_block + block_count;
     301  char *alloc_name = NULL;
    301302
    302303  sc = disk_lock();
     
    305306  }
    306307
    307   physical_disk = get_disk_entry(phys, true);
    308   if (physical_disk == NULL || !is_physical_disk(physical_disk)) {
     308  phys_dd = get_disk_entry(phys, true);
     309  if (phys_dd == NULL) {
    309310    disk_unlock();
    310311
     
    312313  }
    313314
    314   if (
    315     begin_block >= physical_disk->size
    316       || end_block <= begin_block
    317       || end_block > physical_disk->size
    318   ) {
     315  sc = create_disk(dev, name, &dd, &alloc_name);
     316  if (sc != RTEMS_SUCCESSFUL) {
    319317    disk_unlock();
    320318
    321     return RTEMS_INVALID_NUMBER;
    322   }
    323 
    324   sc = create_disk(dev, name, &dd);
    325   if (sc != RTEMS_SUCCESSFUL) {
     319    return sc;
     320  }
     321
     322  sc = rtems_disk_init_log(
     323    dd,
     324    phys_dd,
     325    block_begin,
     326    block_count
     327  );
     328
     329  dd->dev = dev;
     330  dd->name = alloc_name;
     331
     332  ++phys_dd->uses;
     333
     334  if (sc != RTEMS_SUCCESSFUL) {
     335    dd->ioctl = null_handler;
     336    rtems_disk_delete(dev);
    326337    disk_unlock();
    327338
    328339    return sc;
    329340  }
    330 
    331   dd->phys_dev = physical_disk;
    332   dd->start = begin_block;
    333   dd->size = block_count;
    334   dd->block_size = physical_disk->block_size;
    335   dd->media_block_size = physical_disk->media_block_size;
    336   dd->block_to_media_block_shift = physical_disk->block_to_media_block_shift;
    337   dd->bds_per_group = physical_disk->bds_per_group;
    338   dd->ioctl = physical_disk->ioctl;
    339   dd->driver_data = physical_disk->driver_data;
    340 
    341   ++physical_disk->uses;
    342341
    343342  disk_unlock();
  • testsuites/libtests/block01/init.c

    r2c6cc3c r73c09b3b  
    184184  ASSERT_SC_EQ(sc, RTEMS_RESOURCE_IN_USE);
    185185
    186   sc = rtems_disk_create_log(logical_2_dev, logical_dev, 0, 1, "/dev/rda1");
     186  sc = rtems_disk_create_log(logical_2_dev, logical_dev, 0, 1, "/dev/rda2");
    187187  ASSERT_SC_EQ(sc, RTEMS_INVALID_ID);
    188188
Note: See TracChangeset for help on using the changeset viewer.