Changeset 945884fe in rtems


Ignore:
Timestamp:
Aug 6, 2009, 3:58:09 AM (10 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.10, 4.11, master
Children:
b9ff10f3
Parents:
14d9ae4
Message:

2009-08-06 Chris Johns <chrisj@…>

  • libblock/src/bdbuf.c: Fix group user logic.
  • libblock/include/rtems/blkdev.h, libblock/src/blkdev.c, libblock/src/nvdisk.c, libblock/src/flashdisk.c: Add set block size, and get media block size support.
Location:
cpukit
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r14d9ae4 r945884fe  
     12009-08-06      Chris Johns <chrisj@rtems.org>
     2
     3        * libblock/src/bdbuf.c: Fix group user logic.
     4        * libblock/include/rtems/blkdev.h, libblock/src/blkdev.c,
     5        libblock/src/nvdisk.c, libblock/src/flashdisk.c: Add set block
     6        size, and get media block size support.
     7
    182009-08-05      Joel Sherrill <joel.sherrill@oarcorp.com>
    29
  • cpukit/libblock/include/rtems/blkdev.h

    r14d9ae4 r945884fe  
    4949 */
    5050typedef enum rtems_blkdev_request_op {
    51   RTEMS_BLKDEV_REQ_READ,
    52   RTEMS_BLKDEV_REQ_WRITE,
    53   RTEMS_BLKDEV_CAPABILITIES
     51  RTEMS_BLKDEV_REQ_READ,       /**< Read the requested blocks of data. */
     52  RTEMS_BLKDEV_REQ_WRITE,      /**< Write the requested blocks of data. */
     53  RTEMS_BLKDEV_CAPABILITIES    /**< Return the driver capabilities set. */
    5454} rtems_blkdev_request_op;
    5555
     
    161161 */
    162162
    163 #define RTEMS_BLKIO_REQUEST _IOWR('B', 1, rtems_blkdev_request)
    164 #define RTEMS_BLKIO_GETBLKSIZE _IO('B', 2)
    165 #define RTEMS_BLKIO_GETSIZE _IO('B', 3)
    166 #define RTEMS_BLKIO_SYNCDEV _IO('B', 4)
     163#define RTEMS_BLKIO_REQUEST         _IOWR('B', 1, rtems_blkdev_request)
     164#define RTEMS_BLKIO_GETMEDIABLKSIZE _IO('B', 2)
     165#define RTEMS_BLKIO_GETBLKSIZE      _IO('B', 3)
     166#define RTEMS_BLKIO_SETBLKSIZE      _IO('B', 4)
     167#define RTEMS_BLKIO_GETSIZE         _IO('B', 5)
     168#define RTEMS_BLKIO_SYNCDEV         _IO('B', 6)
    167169
    168170/** @} */
     
    243245);
    244246
     247/**
     248 * Common IO control primitive.
     249 *
     250 * Use this in all block devices to handle the common set of ioctl requests.
     251 */
     252int
     253rtems_blkdev_ioctl(dev_t dev, uint32_t req, void *argp);
     254
    245255/** @} */
    246256
  • cpukit/libblock/src/bdbuf.c

    r14d9ae4 r945884fe  
    135135  (((uint32_t)'B' << 24) | ((uint32_t)(n) & (uint32_t)0x00FFFFFF))
    136136
    137 #define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY  RTEMS_BLKDEV_FATAL_ERROR(1)
    138 #define RTEMS_BLKDEV_FATAL_BDBUF_SWAPOUT      RTEMS_BLKDEV_FATAL_ERROR(2)
    139 #define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_LOCK    RTEMS_BLKDEV_FATAL_ERROR(3)
    140 #define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_UNLOCK  RTEMS_BLKDEV_FATAL_ERROR(4)
    141 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_LOCK   RTEMS_BLKDEV_FATAL_ERROR(5)
    142 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_UNLOCK RTEMS_BLKDEV_FATAL_ERROR(6)
    143 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_1 RTEMS_BLKDEV_FATAL_ERROR(7)
    144 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_2 RTEMS_BLKDEV_FATAL_ERROR(8)
    145 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_3 RTEMS_BLKDEV_FATAL_ERROR(9)
    146 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAKE   RTEMS_BLKDEV_FATAL_ERROR(10)
    147 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WAKE      RTEMS_BLKDEV_FATAL_ERROR(11)
    148 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_NOMEM     RTEMS_BLKDEV_FATAL_ERROR(12)
    149 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_CREATE RTEMS_BLKDEV_FATAL_ERROR(13)
    150 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_START  RTEMS_BLKDEV_FATAL_ERROR(14)
    151 #define BLKDEV_FATAL_BDBUF_SWAPOUT_RE         RTEMS_BLKDEV_FATAL_ERROR(15)
    152 #define BLKDEV_FATAL_BDBUF_SWAPOUT_TS         RTEMS_BLKDEV_FATAL_ERROR(16)
     137#define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_1 RTEMS_BLKDEV_FATAL_ERROR(1)
     138#define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_2 RTEMS_BLKDEV_FATAL_ERROR(2)
     139#define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_3 RTEMS_BLKDEV_FATAL_ERROR(3)
     140#define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_4 RTEMS_BLKDEV_FATAL_ERROR(4)
     141#define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_5 RTEMS_BLKDEV_FATAL_ERROR(5)
     142#define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_6 RTEMS_BLKDEV_FATAL_ERROR(6)
     143#define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_7 RTEMS_BLKDEV_FATAL_ERROR(7)
     144#define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_8 RTEMS_BLKDEV_FATAL_ERROR(8)
     145#define RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_9 RTEMS_BLKDEV_FATAL_ERROR(9)
     146#define RTEMS_BLKDEV_FATAL_BDBUF_SWAPOUT       RTEMS_BLKDEV_FATAL_ERROR(10)
     147#define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_LOCK     RTEMS_BLKDEV_FATAL_ERROR(11)
     148#define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_UNLOCK   RTEMS_BLKDEV_FATAL_ERROR(12)
     149#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_LOCK    RTEMS_BLKDEV_FATAL_ERROR(13)
     150#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_UNLOCK  RTEMS_BLKDEV_FATAL_ERROR(14)
     151#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_1  RTEMS_BLKDEV_FATAL_ERROR(15)
     152#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_2  RTEMS_BLKDEV_FATAL_ERROR(16)
     153#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_3  RTEMS_BLKDEV_FATAL_ERROR(17)
     154#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAKE    RTEMS_BLKDEV_FATAL_ERROR(18)
     155#define RTEMS_BLKDEV_FATAL_BDBUF_SO_WAKE       RTEMS_BLKDEV_FATAL_ERROR(19)
     156#define RTEMS_BLKDEV_FATAL_BDBUF_SO_NOMEM      RTEMS_BLKDEV_FATAL_ERROR(20)
     157#define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_CREATE  RTEMS_BLKDEV_FATAL_ERROR(21)
     158#define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_START   RTEMS_BLKDEV_FATAL_ERROR(22)
     159#define BLKDEV_FATAL_BDBUF_SWAPOUT_RE          RTEMS_BLKDEV_FATAL_ERROR(23)
     160#define BLKDEV_FATAL_BDBUF_SWAPOUT_TS          RTEMS_BLKDEV_FATAL_ERROR(24)
    153161
    154162/**
     
    877885 * time.
    878886 *
    879  * and you must
    880  * hold the sync lock. The sync lock is used to block writes while a sync is
    881  * active.
     887 * @note Do not lower the group user count as the modified list is a user of
     888 * the buffer.
    882889 *
    883890 * @param bd The bd to queue to the cache's modified list.
     
    962969       b++, bd += bufs_per_bd)
    963970  {
     971    if ((bd->state == RTEMS_BDBUF_STATE_MODIFIED) ||
     972        (bd->state == RTEMS_BDBUF_STATE_ACCESS) ||
     973        (bd->state == RTEMS_BDBUF_STATE_ACCESS_MODIFIED) ||
     974        (bd->state == RTEMS_BDBUF_STATE_SYNC) ||
     975        (bd->state == RTEMS_BDBUF_STATE_TRANSFER))
     976      rtems_fatal_error_occurred ((bd->state << 16) |
     977                                  RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_8);
     978   
    964979    if ((bd->state == RTEMS_BDBUF_STATE_CACHED) ||
    965         (bd->state == RTEMS_BDBUF_STATE_MODIFIED) ||
    966980        (bd->state == RTEMS_BDBUF_STATE_READ_AHEAD))
    967981    {
    968982      if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0)
    969         rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY);
    970       rtems_chain_extract (&bd->link);
    971     }
     983        rtems_fatal_error_occurred ((bd->state << 16) |
     984                                    RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_1);
     985    }
     986   
     987    rtems_chain_extract (&bd->link);
    972988  }
    973989 
     
    978994       b < group->bds_per_group;
    979995       b++, bd += bufs_per_bd)
     996  {
     997    bd->state = RTEMS_BDBUF_STATE_EMPTY;
    980998    rtems_chain_prepend (&bdbuf_cache.ready, &bd->link);
     999  }
    9811000}
    9821001
     
    10051024    {
    10061025      rtems_chain_extract (node);
    1007       bd->group->users++;
    10081026      return bd;
    10091027    }
     
    14301448           */
    14311449          if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0)
    1432             rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY);
     1450            rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_2);
    14331451        }
    14341452        else
     
    14721490        if ((bd->state != RTEMS_BDBUF_STATE_EMPTY) &&
    14731491            (bd->state != RTEMS_BDBUF_STATE_READ_AHEAD))
    1474           rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY);
     1492          rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_3);
    14751493
    14761494        if (bd->state == RTEMS_BDBUF_STATE_READ_AHEAD)
    14771495        {
    14781496          if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0)
    1479             rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY);
     1497            rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_4);
    14801498        }
    14811499      }
     
    14921510
    14931511        if (rtems_bdbuf_avl_insert (&bdbuf_cache.tree, bd) != 0)
    1494           rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY);
     1512          rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_5);
    14951513
    14961514        return bd;
     
    15531571
    15541572      default:
    1555         rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY);
     1573        rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_6);
    15561574    }
    15571575  }
     
    16111629    bd->state = RTEMS_BDBUF_STATE_ACCESS;
    16121630
     1631  /*
     1632   * Indicate a buffer in this group is being used.
     1633   */
     1634  bd->group->users++;
     1635 
    16131636  rtems_bdbuf_unlock_cache ();
    16141637
     
    17351758    bd->error = 0;
    17361759
     1760    /*
     1761     * The buffer will be passed to the driver so this buffer has a user.
     1762     */
     1763    bd->group->users++;
     1764   
    17371765    /*
    17381766     * @todo The use of these req blocks is not a great design. The req is a
     
    18171845      bd->error = req->error;
    18181846      bd->state = RTEMS_BDBUF_STATE_READ_AHEAD;
    1819       rtems_bdbuf_release (bd);
     1847      bd->group->users--;
     1848      rtems_chain_prepend (&bdbuf_cache.ready, &bd->link);
     1849
     1850      /*
     1851       * If there is an error remove the BD from the AVL tree as it does is
     1852       * invalid, then wake any threads that may be waiting. A thread may have
     1853       * been waiting for this block and assumed it was in the tree.
     1854       */
     1855      if (bd->error)
     1856      {
     1857        bd->state = RTEMS_BDBUF_STATE_EMPTY;
     1858        if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0)
     1859          rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_9);
     1860      }
     1861
     1862      if (bd->waiters)
     1863        rtems_bdbuf_wake (bdbuf_cache.access, &bdbuf_cache.access_waiters);
     1864      else
     1865      {
     1866        if (rtems_chain_has_only_one_node (&bdbuf_cache.ready))
     1867          rtems_bdbuf_wake (bdbuf_cache.waiting, &bdbuf_cache.wait_waiters);
     1868      }
    18201869    }
    18211870
    18221871    bd = req->bufs[0].user;
     1872
     1873    /*
     1874     * One less user. We do this here then increment again so the case of the
     1875     * buffer in the the cache and no read leaves the user counts at the
     1876     * correct level.
     1877     */
     1878    bd->group->users--;
    18231879  }
    18241880
     
    18291885    bd->state = RTEMS_BDBUF_STATE_ACCESS_MODIFIED;
    18301886  else
     1887  {
     1888    /*
     1889     * The file system is a user of the buffer.
     1890     */
     1891    bd->group->users++;
    18311892    bd->state = RTEMS_BDBUF_STATE_ACCESS;
     1893  }
    18321894
    18331895  rtems_bdbuf_unlock_cache ();
     
    19702032      case RTEMS_BDBUF_STATE_TRANSFER:
    19712033        bd->waiters++;
    1972         rtems_bdbuf_wait (&bdbuf_cache.transfer, &bdbuf_cache.transfer_waiters);
     2034        rtems_bdbuf_wait (&bdbuf_cache.transfer,
     2035                          &bdbuf_cache.transfer_waiters);
    19732036        bd->waiters--;
    19742037        break;
    19752038
    19762039      default:
    1977         rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY);
     2040        rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_7);
    19782041    }
    19792042  }
     
    22122275              bd->state = RTEMS_BDBUF_STATE_CACHED;
    22132276              bd->error = 0;
     2277
     2278              /*
     2279               * The buffer is now not modified so lower the user count for the group.
     2280               */
    22142281              bd->group->users--;
    22152282             
  • cpukit/libblock/src/blkdev.c

    r14d9ae4 r945884fe  
    1818#endif
    1919
     20#include <errno.h>
    2021#include <string.h>
    2122
     
    219220    switch (args->command)
    220221    {
     222        case RTEMS_BLKIO_GETMEDIABLKSIZE:
     223            args->ioctl_return = dd->media_block_size;
     224            break;
     225
    221226        case RTEMS_BLKIO_GETBLKSIZE:
    222227            args->ioctl_return = dd->block_size;
     228            break;
     229
     230        case RTEMS_BLKIO_SETBLKSIZE:
     231            dd->block_size = *((size_t*) args->buffer);
    223232            break;
    224233
     
    249258    return RTEMS_SUCCESSFUL;
    250259}
     260
     261int
     262rtems_blkdev_ioctl(dev_t dev, uint32_t req, void *argp)
     263{
     264    rtems_disk_device *dd;
     265    size_t            *arg_size = argp;
     266
     267    dd = rtems_disk_obtain(dev);
     268    if (dd == NULL)
     269    {
     270        errno = ENODEV;
     271        return -1;
     272    }
     273   
     274    switch (req)
     275    {
     276        case RTEMS_BLKIO_GETMEDIABLKSIZE:
     277            *arg_size = dd->media_block_size;
     278            break;
     279
     280        case RTEMS_BLKIO_GETBLKSIZE:
     281            *arg_size = dd->block_size;
     282            break;
     283
     284        case RTEMS_BLKIO_SETBLKSIZE:
     285            dd->block_size = *arg_size;
     286            break;
     287
     288        case RTEMS_BLKIO_GETSIZE:
     289            *arg_size = dd->size;
     290            break;
     291
     292        default:
     293            errno = EINVAL;
     294            return -1;
     295            break;
     296    }
     297   
     298    rtems_disk_release(dd);
     299
     300    return 0;
     301}
  • cpukit/libblock/src/flashdisk.c

    r14d9ae4 r945884fe  
    24112411
    24122412      default:
    2413         errno = EINVAL;
     2413        return rtems_blkdev_ioctl (dev, req, argp);
    24142414        break;
    24152415    }
  • cpukit/libblock/src/nvdisk.c

    r14d9ae4 r945884fe  
    745745       
    746746      default:
    747         errno = EINVAL;
     747        return rtems_blkdev_ioctl (dev, req, argp);
    748748        break;
    749749    }
  • cpukit/libblock/src/ramdisk.c

    r14d9ae4 r945884fe  
    207207            break;
    208208        }
    209 
     209 
    210210        default:
    211             errno = EINVAL;
    212             return -1;
    213     }
     211            return rtems_blkdev_ioctl (dev, req, argp);
     212            break;
     213    }
     214
     215    errno = EINVAL;
     216    return -1;
    214217}
    215218
Note: See TracChangeset for help on using the changeset viewer.