Changeset 796967c in rtems for cpukit/libblock


Ignore:
Timestamp:
Feb 28, 2012, 4:19:49 PM (8 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
3ee7b84
Parents:
1024561
git-author:
Sebastian Huber <sebastian.huber@…> (02/28/12 16:19:49)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/13/12 11:24:18)
Message:

libblock: Change bdbuf API

The functions

o rtems_bdbuf_get(),
o rtems_bdbuf_read(),
o rtems_bdbuf_syncdev(), and
o rtems_bdbuf_purge_dev(),

use now the disk device instead of the device identifier. This makes
bdbuf independent of rtems_disk_obtain() and rtems_disk_release(). It
is the responsiblity of the file system to obtain the disk device. This
also reduces the overhead to get a buffer.

The key for the AVL tree uses now the disk device instead of the device
identifier. The pointer is interpreted as an unsigned integer. This
reduces the memory overhead and makes the comparison operation a bit
faster.

Removed function rtems_bdbuf_purge_major(). This function was too
destructive and could have unpredictable side effects.

Location:
cpukit/libblock
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libblock/include/rtems/bdbuf.h

    r1024561 r796967c  
    302302 * a range of other information related to managing the buffer in the cache. To
    303303 * speed-up buffer lookup descriptors are organized in AVL-Tree. The fields
    304  * 'dev' and 'block' are search keys.
     304 * 'dd' and 'block' are search keys.
    305305 */
    306306typedef struct rtems_bdbuf_buffer
     
    316316  } avl;
    317317
    318   dev_t             dev;        /**< device number */
     318  const rtems_disk_device *dd;  /**< disk device */
    319319
    320320  rtems_blkdev_bnum block;      /**< block number on the device */
     
    471471 * of the partition on the media.
    472472 *
    473  * @param device [in] Device number (constructed of major and minor device
    474  * number).
     473 * @param dd [in] The disk device.
    475474 * @param block [in] Linear media block number.
    476475 * @param bd [out] Reference to the buffer descriptor pointer.
     
    482481 */
    483482rtems_status_code
    484 rtems_bdbuf_get (dev_t device, rtems_blkdev_bnum block, rtems_bdbuf_buffer** bd);
     483rtems_bdbuf_get (
     484  const rtems_disk_device *dd,
     485  rtems_blkdev_bnum block,
     486  rtems_bdbuf_buffer** bd
     487);
    485488
    486489/**
     
    499502 * first.
    500503 *
    501  * @param device [in] Device number (constructed of major and minor device
    502  * number).
     504 * @param dd [in] The disk device.
    503505 * @param block [in] Linear media block number.
    504506 * @param bd [out] Reference to the buffer descriptor pointer.
     
    511513 */
    512514rtems_status_code
    513 rtems_bdbuf_read (dev_t device, rtems_blkdev_bnum block, rtems_bdbuf_buffer** bd);
     515rtems_bdbuf_read (
     516  const rtems_disk_device *dd,
     517  rtems_blkdev_bnum block,
     518  rtems_bdbuf_buffer** bd
     519);
    514520
    515521/**
     
    576582 * nested call will be blocked until the first sync request has complete.
    577583 *
    578  * @param dev [in] Device number (constructed of major and minor device
    579  * number).
     584 * @param dd [in] The disk device.
    580585 *
    581586 * @retval RTEMS_SUCCESSFUL Successful operation.
     
    584589 */
    585590rtems_status_code
    586 rtems_bdbuf_syncdev (dev_t dev);
    587 
    588 /**
    589  * @brief Purges all buffers that matches the device identifier @a dev.
     591rtems_bdbuf_syncdev (const rtems_disk_device *dd);
     592
     593/**
     594 * @brief Purges all buffers corresponding to the disk device @a dd.
    590595 *
    591596 * This may result in loss of data.
    592597 */
    593598void
    594 rtems_bdbuf_purge_dev (dev_t dev);
    595 
    596 /**
    597  * @brief Purges all buffers that matches the device major number @a major.
    598  *
    599  * This may result in loss of data.
    600  */
    601 void
    602 rtems_bdbuf_purge_major (rtems_device_major_number major);
     599rtems_bdbuf_purge_dev (const rtems_disk_device *dd);
    603600
    604601/** @} */
  • cpukit/libblock/include/rtems/bdpart.h

    r1024561 r796967c  
    88
    99/*
    10  * Copyright (c) 2009, 2010
    11  * embedded brains GmbH
    12  * Obere Lagerstr. 30
    13  * D-82178 Puchheim
    14  * Germany
    15  * <rtems@embedded-brains.de>
     10 * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
     11 *
     12 *  embedded brains GmbH
     13 *  Obere Lagerstr. 30
     14 *  82178 Puchheim
     15 *  Germany
     16 *  <rtems@embedded-brains.de>
    1617 *
    1718 * The license and distribution terms for this file may be
     
    399400rtems_status_code rtems_bdpart_get_disk_data(
    400401  const char *disk_name,
    401   dev_t *disk,
     402  int *fd_ptr,
     403  const rtems_disk_device **dd_ptr,
    402404  rtems_blkdev_bnum *disk_end
    403405);
  • cpukit/libblock/src/bdbuf.c

    r1024561 r796967c  
    2020 *    issues.
    2121 *
    22  * Copyright (c) 2009 embedded brains GmbH.
     22 * Copyright (c) 2009-2012 embedded brains GmbH.
    2323 *
    2424 * @(#) bdbuf.c,v 1.14 2004/04/17 08:15:17 ralf Exp
     
    4545#include "rtems/bdbuf.h"
    4646
    47 #define BDBUF_INVALID_DEV ((dev_t) -1)
     47#define BDBUF_INVALID_DEV NULL
    4848
    4949/*
     
    5959{
    6060  rtems_chain_control   bds;         /**< The transfer list of BDs. */
    61   dev_t                 dev;         /**< The device the transfer is for. */
     61  const rtems_disk_device *dd;       /**< The device the transfer is for. */
    6262  bool                  syncing;     /**< The data is a sync'ing. */
    6363  rtems_blkdev_request* write_req;   /**< The write request array. */
     
    114114  bool                sync_active;       /**< True if a sync is active. */
    115115  rtems_id            sync_requester;    /**< The sync requester. */
    116   dev_t               sync_device;       /**< The device to sync and
     116  const rtems_disk_device *sync_device;  /**< The device to sync and
    117117                                          * BDBUF_INVALID_DEV not a device
    118118                                          * sync. */
     
    175175#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_1       RTEMS_BLKDEV_FATAL_ERROR(29)
    176176#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_2       RTEMS_BLKDEV_FATAL_ERROR(30)
    177 #define RTEMS_BLKDEV_FATAL_BDBUF_DISK_REL      RTEMS_BLKDEV_FATAL_ERROR(31)
    178177
    179178/**
     
    323322
    324323/**
    325  * Searches for the node with specified dev/block.
     324 * Searches for the node with specified dd/block.
    326325 *
    327326 * @param root pointer to the root node of the AVL-Tree
    328  * @param dev device search key
     327 * @param dd disk device search key
    329328 * @param block block search key
    330  * @retval NULL node with the specified dev/block is not found
    331  * @return pointer to the node with specified dev/block
     329 * @retval NULL node with the specified dd/block is not found
     330 * @return pointer to the node with specified dd/block
    332331 */
    333332static rtems_bdbuf_buffer *
    334333rtems_bdbuf_avl_search (rtems_bdbuf_buffer** root,
    335                         dev_t                dev,
     334                        const rtems_disk_device *dd,
    336335                        rtems_blkdev_bnum    block)
    337336{
    338337  rtems_bdbuf_buffer* p = *root;
    339338
    340   while ((p != NULL) && ((p->dev != dev) || (p->block != block)))
    341   {
    342     if ((p->dev < dev) || ((p->dev == dev) && (p->block < block)))
     339  while ((p != NULL) && ((p->dd != dd) || (p->block != block)))
     340  {
     341    if (((uintptr_t) p->dd < (uintptr_t) dd)
     342        || ((p->dd == dd) && (p->block < block)))
    343343    {
    344344      p = p->avl.right;
     
    365365                       rtems_bdbuf_buffer*  node)
    366366{
    367   dev_t             dev = node->dev;
     367  const rtems_disk_device *dd = node->dd;
    368368  rtems_blkdev_bnum block = node->block;
    369369
     
    390390    *buf_prev++ = p;
    391391
    392     if ((p->dev < dev) || ((p->dev == dev) && (p->block < block)))
     392    if (((uintptr_t) p->dd < (uintptr_t) dd)
     393        || ((p->dd == dd) && (p->block < block)))
    393394    {
    394395      p->avl.cache = 1;
     
    401402      }
    402403    }
    403     else if ((p->dev != dev) || (p->block != block))
     404    else if ((p->dd != dd) || (p->block != block))
    404405    {
    405406      p->avl.cache = -1;
     
    546547                       const rtems_bdbuf_buffer* node)
    547548{
    548   dev_t             dev = node->dev;
     549  const rtems_disk_device *dd = node->dd;
    549550  rtems_blkdev_bnum block = node->block;
    550551
     
    566567    *buf_prev++ = p;
    567568
    568     if ((p->dev < dev) || ((p->dev == dev) && (p->block < block)))
     569    if (((uintptr_t) p->dd < (uintptr_t) dd)
     570        || ((p->dd == dd) && (p->block < block)))
    569571    {
    570572      p->avl.cache = 1;
    571573      p = p->avl.right;
    572574    }
    573     else if ((p->dev != dev) || (p->block != block))
     575    else if ((p->dd != dd) || (p->block != block))
    574576    {
    575577      p->avl.cache = -1;
     
    10931095rtems_bdbuf_add_to_modified_list_after_access (rtems_bdbuf_buffer *bd)
    10941096{
    1095   if (bdbuf_cache.sync_active && bdbuf_cache.sync_device == bd->dev)
     1097  if (bdbuf_cache.sync_active && bdbuf_cache.sync_device == bd->dd)
    10961098  {
    10971099    rtems_bdbuf_unlock_cache ();
     
    12221224static void
    12231225rtems_bdbuf_setup_empty_buffer (rtems_bdbuf_buffer *bd,
    1224                                 dev_t               dev,
     1226                                const rtems_disk_device *dd,
    12251227                                rtems_blkdev_bnum   block)
    12261228{
    1227   bd->dev       = dev;
     1229  bd->dd        = dd ;
    12281230  bd->block     = block;
    12291231  bd->avl.left  = NULL;
     
    12381240
    12391241static rtems_bdbuf_buffer *
    1240 rtems_bdbuf_get_buffer_from_lru_list (dev_t             dev,
     1242rtems_bdbuf_get_buffer_from_lru_list (const rtems_disk_device *dd,
    12411243                                      rtems_blkdev_bnum block,
    12421244                                      size_t            bds_per_group)
     
    12721274    if (empty_bd != NULL)
    12731275    {
    1274       rtems_bdbuf_setup_empty_buffer (empty_bd, dev, block);
     1276      rtems_bdbuf_setup_empty_buffer (empty_bd, dd, block);
    12751277
    12761278      return empty_bd;
     
    14231425       b++, bd++, buffer += bdbuf_config.buffer_min)
    14241426  {
    1425     bd->dev    = BDBUF_INVALID_DEV;
     1427    bd->dd    = BDBUF_INVALID_DEV;
    14261428    bd->group  = group;
    14271429    bd->buffer = buffer;
     
    16691671
    16701672static rtems_bdbuf_buffer *
    1671 rtems_bdbuf_get_buffer_for_read_ahead (dev_t             dev,
     1673rtems_bdbuf_get_buffer_for_read_ahead (const rtems_disk_device *dd,
    16721674                                       rtems_blkdev_bnum block,
    16731675                                       size_t            bds_per_group)
     
    16751677  rtems_bdbuf_buffer *bd = NULL;
    16761678
    1677   bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dev, block);
     1679  bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dd, block);
    16781680
    16791681  if (bd == NULL)
    16801682  {
    1681     bd = rtems_bdbuf_get_buffer_from_lru_list (dev, block, bds_per_group);
     1683    bd = rtems_bdbuf_get_buffer_from_lru_list (dd, block, bds_per_group);
    16821684
    16831685    if (bd != NULL)
     
    16951697
    16961698static rtems_bdbuf_buffer *
    1697 rtems_bdbuf_get_buffer_for_access (dev_t             dev,
     1699rtems_bdbuf_get_buffer_for_access (const rtems_disk_device *dd,
    16981700                                   rtems_blkdev_bnum block,
    16991701                                   size_t            bds_per_group)
     
    17031705  do
    17041706  {
    1705     bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dev, block);
     1707    bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dd, block);
    17061708
    17071709    if (bd != NULL)
     
    17201722    else
    17211723    {
    1722       bd = rtems_bdbuf_get_buffer_from_lru_list (dev, block, bds_per_group);
     1724      bd = rtems_bdbuf_get_buffer_from_lru_list (dd, block, bds_per_group);
    17231725
    17241726      if (bd == NULL)
     
    17351737
    17361738static rtems_status_code
    1737 rtems_bdbuf_obtain_disk (dev_t               dev,
     1739rtems_bdbuf_obtain_disk (const rtems_disk_device *dd,
    17381740                         rtems_blkdev_bnum   block,
    1739                          rtems_disk_device **dd_ptr,
    17401741                         rtems_blkdev_bnum  *media_block_ptr,
    17411742                         size_t             *bds_per_group_ptr)
    17421743{
    1743   rtems_disk_device *dd = NULL;
    1744 
    17451744  if (!bdbuf_cache.initialised)
    17461745    return RTEMS_NOT_CONFIGURED;
    1747 
    1748   /*
    1749    * Do not hold the cache lock when obtaining the disk table.
    1750    */
    1751   dd = rtems_disk_obtain (dev);
    1752   if (dd == NULL)
    1753     return RTEMS_INVALID_ID;
    1754 
    1755   *dd_ptr = dd;
    17561746
    17571747  if (media_block_ptr != NULL)
     
    17671757    if (mb >= dd->size)
    17681758    {
    1769       rtems_disk_release(dd);
    17701759      return RTEMS_INVALID_NUMBER;
    17711760    }
     
    17801769    if (bds_per_group == 0)
    17811770    {
    1782       rtems_disk_release (dd);
    17831771      return RTEMS_INVALID_NUMBER;
    17841772    }
     
    17901778}
    17911779
    1792 static void
    1793 rtems_bdbuf_release_disk (rtems_disk_device *dd)
    1794 {
    1795   rtems_status_code sc = RTEMS_SUCCESSFUL;
    1796 
    1797   sc = rtems_disk_release (dd);
    1798   if (sc != RTEMS_SUCCESSFUL)
    1799     rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_DISK_REL);
    1800 }
    1801 
    18021780rtems_status_code
    1803 rtems_bdbuf_get (dev_t                dev,
     1781rtems_bdbuf_get (const rtems_disk_device *dd,
    18041782                 rtems_blkdev_bnum    block,
    18051783                 rtems_bdbuf_buffer **bd_ptr)
    18061784{
    18071785  rtems_status_code   sc = RTEMS_SUCCESSFUL;
    1808   rtems_disk_device  *dd = NULL;
    18091786  rtems_bdbuf_buffer *bd = NULL;
    18101787  rtems_blkdev_bnum   media_block = 0;
    18111788  size_t              bds_per_group = 0;
    18121789
    1813   sc = rtems_bdbuf_obtain_disk (dev, block, &dd, &media_block, &bds_per_group);
     1790  sc = rtems_bdbuf_obtain_disk (dd, block, &media_block, &bds_per_group);
    18141791  if (sc != RTEMS_SUCCESSFUL)
    18151792    return sc;
     
    18221799  if (rtems_bdbuf_tracer)
    18231800    printf ("bdbuf:get: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
    1824             media_block, block, (unsigned) dev);
    1825 
    1826   bd = rtems_bdbuf_get_buffer_for_access (dev, media_block, bds_per_group);
     1801            media_block, block, (unsigned) dd->dev);
     1802
     1803  bd = rtems_bdbuf_get_buffer_for_access (dd, media_block, bds_per_group);
    18271804
    18281805  switch (bd->state)
     
    18571834  rtems_bdbuf_unlock_cache ();
    18581835
    1859   rtems_bdbuf_release_disk (dd);
    1860 
    18611836  *bd_ptr = bd;
    18621837
     
    18931868  rtems_blkdev_bnum   media_block_end = dd->start + dd->size;
    18941869  rtems_blkdev_bnum   media_block_count = dd->block_size / dd->media_block_size;
    1895   dev_t               dev = dd->dev;
    18961870  uint32_t            block_size = dd->block_size;
    18971871  uint32_t            transfer_index = 1;
     
    19081882  req->bufnum = 0;
    19091883
    1910   bd = rtems_bdbuf_get_buffer_for_access (dev, media_block, bds_per_group);
     1884  bd = rtems_bdbuf_get_buffer_for_access (dd, media_block, bds_per_group);
    19111885
    19121886  *bd_ptr = bd;
     
    19371911    media_block += media_block_count;
    19381912
    1939     bd = rtems_bdbuf_get_buffer_for_read_ahead (dev, media_block,
     1913    bd = rtems_bdbuf_get_buffer_for_read_ahead (dd, media_block,
    19401914                                                bds_per_group);
    19411915
     
    20221996
    20231997rtems_status_code
    2024 rtems_bdbuf_read (dev_t                dev,
     1998rtems_bdbuf_read (const rtems_disk_device *dd,
    20251999                  rtems_blkdev_bnum    block,
    20262000                  rtems_bdbuf_buffer **bd_ptr)
    20272001{
    20282002  rtems_status_code     sc = RTEMS_SUCCESSFUL;
    2029   rtems_disk_device    *dd = NULL;
    20302003  rtems_blkdev_request *req = NULL;
    20312004  rtems_bdbuf_buffer   *bd = NULL;
     
    20332006  size_t                bds_per_group = 0;
    20342007
    2035   sc = rtems_bdbuf_obtain_disk (dev, block, &dd, &media_block, &bds_per_group);
     2008  sc = rtems_bdbuf_obtain_disk (dd, block, &media_block, &bds_per_group);
    20362009  if (sc != RTEMS_SUCCESSFUL)
    20372010    return sc;
     
    20482021  if (rtems_bdbuf_tracer)
    20492022    printf ("bdbuf:read: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
    2050             media_block + dd->start, block, (unsigned) dev);
     2023            media_block + dd->start, block, (unsigned) dd->dev);
    20512024
    20522025  rtems_bdbuf_lock_cache ();
     
    20902063
    20912064  rtems_bdbuf_unlock_cache ();
    2092   rtems_bdbuf_release_disk (dd);
    20932065
    20942066  return sc;
     
    22112183
    22122184rtems_status_code
    2213 rtems_bdbuf_syncdev (dev_t dev)
     2185rtems_bdbuf_syncdev (const rtems_disk_device *dd)
    22142186{
    22152187  rtems_status_code  sc = RTEMS_SUCCESSFUL;
    2216   rtems_disk_device *dd = NULL;
    22172188
    22182189  if (rtems_bdbuf_tracer)
    2219     printf ("bdbuf:syncdev: %08x\n", (unsigned) dev);
    2220 
    2221   sc = rtems_bdbuf_obtain_disk (dev, 0, &dd, NULL, NULL);
     2190    printf ("bdbuf:syncdev: %08x\n", (unsigned) dd->dev);
     2191
     2192  sc = rtems_bdbuf_obtain_disk (dd, 0, NULL, NULL);
    22222193  if (sc != RTEMS_SUCCESSFUL)
    22232194    return sc;
     
    22412212  bdbuf_cache.sync_active    = true;
    22422213  bdbuf_cache.sync_requester = rtems_task_self ();
    2243   bdbuf_cache.sync_device    = dev;
     2214  bdbuf_cache.sync_device    = dd;
    22442215
    22452216  rtems_bdbuf_wake_swapper ();
     
    22472218  rtems_bdbuf_wait_for_event (RTEMS_BDBUF_TRANSFER_SYNC);
    22482219  rtems_bdbuf_unlock_sync ();
    2249   rtems_bdbuf_release_disk (dd);
    22502220
    22512221  return RTEMS_SUCCESSFUL;
    2252 }
    2253 
    2254 static int
    2255 rtems_bdbuf_null_disk_ioctl (rtems_disk_device *dd, uint32_t req, void *arg)
    2256 {
    2257   return -1;
    22582222}
    22592223
     
    22692233{
    22702234  rtems_chain_node *node;
    2271   static rtems_disk_device null_disk = {
    2272     .phys_dev = &null_disk,
    2273     .capabilities = 0,
    2274     .ioctl = rtems_bdbuf_null_disk_ioctl
    2275   };
    22762235
    22772236  if (rtems_bdbuf_tracer)
    2278     printf ("bdbuf:swapout transfer: %08x\n", (unsigned) transfer->dev);
     2237    printf ("bdbuf:swapout transfer: %08x\n", (unsigned) transfer->dd->dev);
    22792238
    22802239  /*
     
    22952254    uint32_t bufs_per_bd = 0;
    22962255
    2297     /*
    2298      * Obtain the disk device. The cache's mutex has been released to avoid a
    2299      * dead lock.
    2300      */
    2301     rtems_disk_device *dd = rtems_disk_obtain (transfer->dev);
    2302 
    2303     if (dd == NULL)
    2304       dd = &null_disk;
     2256    const rtems_disk_device *dd = transfer->dd;
    23052257
    23062258    bufs_per_bd = dd->block_size / bdbuf_config.buffer_min;
     
    23732325    }
    23742326
    2375     if (dd != &null_disk)
    2376     {
    2377       /*
    2378        * If sync'ing and the deivce is capability of handling a sync IO control
    2379        * call perform the call.
    2380        */
    2381       if (transfer->syncing &&
    2382           (dd->phys_dev->capabilities & RTEMS_BLKDEV_CAP_SYNC))
    2383       {
    2384         /* int result = */ dd->ioctl (dd->phys_dev, RTEMS_BLKDEV_REQ_SYNC, NULL);
    2385         /* How should the error be handled ? */
    2386       }
    2387      
    2388       rtems_disk_release (dd);
     2327    /*
     2328     * If sync'ing and the deivce is capability of handling a sync IO control
     2329     * call perform the call.
     2330     */
     2331    if (transfer->syncing &&
     2332        (dd->phys_dev->capabilities & RTEMS_BLKDEV_CAP_SYNC))
     2333    {
     2334      /* int result = */ dd->ioctl (dd->phys_dev, RTEMS_BLKDEV_REQ_SYNC, NULL);
     2335      /* How should the error be handled ? */
    23892336    }
    23902337  }
     
    23952342 * needs to be handled so we have a common function to do the work.
    23962343 *
    2397  * @param dev The device to handle. If BDBUF_INVALID_DEV no device is selected
    2398  * so select the device of the first buffer to be written to disk.
     2344 * @param dd_ptr Pointer to the device to handle. If BDBUF_INVALID_DEV no
     2345 * device is selected so select the device of the first buffer to be written to
     2346 * disk.
    23992347 * @param chain The modified chain to process.
    24002348 * @param transfer The chain to append buffers to be written too.
     
    24052353 */
    24062354static void
    2407 rtems_bdbuf_swapout_modified_processing (dev_t*               dev,
     2355rtems_bdbuf_swapout_modified_processing (const rtems_disk_device **dd_ptr,
    24082356                                         rtems_chain_control* chain,
    24092357                                         rtems_chain_control* transfer,
     
    24222370     * A sync active with no valid dev means sync all.
    24232371     */
    2424     if (sync_active && (*dev == BDBUF_INVALID_DEV))
     2372    if (sync_active && (*dd_ptr == BDBUF_INVALID_DEV))
    24252373      sync_all = true;
    24262374    else
     
    24382386       *       on TOD to be accurate. Does it matter ?
    24392387       */
    2440       if (sync_all || (sync_active && (*dev == bd->dev))
     2388      if (sync_all || (sync_active && (*dd_ptr == bd->dd))
    24412389          || rtems_bdbuf_has_buffer_waiters ())
    24422390        bd->hold_timer = 0;
     
    24602408
    24612409      /*
    2462        * This assumes we can set dev_t to BDBUF_INVALID_DEV which is just an
     2410       * This assumes we can set it to BDBUF_INVALID_DEV which is just an
    24632411       * assumption. Cannot use the transfer list being empty the sync dev
    24642412       * calls sets the dev to use.
    24652413       */
    2466       if (*dev == BDBUF_INVALID_DEV)
    2467         *dev = bd->dev;
    2468 
    2469       if (bd->dev == *dev)
     2414      if (*dd_ptr == BDBUF_INVALID_DEV)
     2415        *dd_ptr = bd->dd;
     2416
     2417      if (bd->dd == *dd_ptr)
    24702418      {
    24712419        rtems_chain_node* next_node = node->next;
     
    25572505
    25582506  rtems_chain_initialize_empty (&transfer->bds);
    2559   transfer->dev = BDBUF_INVALID_DEV;
     2507  transfer->dd = BDBUF_INVALID_DEV;
    25602508  transfer->syncing = bdbuf_cache.sync_active;
    25612509 
     
    25662514   */
    25672515  if (bdbuf_cache.sync_active)
    2568     transfer->dev = bdbuf_cache.sync_device;
     2516    transfer->dd = bdbuf_cache.sync_device;
    25692517   
    25702518  /*
     
    25722520   * list. The first sync buffer will select the device we use.
    25732521   */
    2574   rtems_bdbuf_swapout_modified_processing (&transfer->dev,
     2522  rtems_bdbuf_swapout_modified_processing (&transfer->dd,
    25752523                                           &bdbuf_cache.sync,
    25762524                                           &transfer->bds,
     
    25812529   * Process the cache's modified list.
    25822530   */
    2583   rtems_bdbuf_swapout_modified_processing (&transfer->dev,
     2531  rtems_bdbuf_swapout_modified_processing (&transfer->dd,
    25842532                                           &bdbuf_cache.modified,
    25852533                                           &transfer->bds,
     
    26792627
    26802628    rtems_chain_initialize_empty (&worker->transfer.bds);
    2681     worker->transfer.dev = BDBUF_INVALID_DEV;
     2629    worker->transfer.dd = BDBUF_INVALID_DEV;
    26822630
    26832631    rtems_chain_append (&bdbuf_cache.swapout_workers, &worker->link);
     
    27162664
    27172665    rtems_chain_initialize_empty (&worker->transfer.bds);
    2718     worker->transfer.dev = BDBUF_INVALID_DEV;
     2666    worker->transfer.dd = BDBUF_INVALID_DEV;
    27192667
    27202668    sc = rtems_task_create (rtems_build_name('B', 'D', 'o', 'a' + w),
     
    27782726  transfer.write_req = rtems_bdbuf_swapout_writereq_alloc ();
    27792727  rtems_chain_initialize_empty (&transfer.bds);
    2780   transfer.dev = BDBUF_INVALID_DEV;
     2728  transfer.dd = BDBUF_INVALID_DEV;
    27812729  transfer.syncing = false;
    27822730
     
    28722820}
    28732821
    2874 typedef bool (*rtems_bdbuf_purge_compare)(dev_t a, dev_t b);
    2875 
    28762822static void
    28772823rtems_bdbuf_gather_for_purge (rtems_chain_control *purge_list,
    2878                               rtems_bdbuf_purge_compare compare,
    2879                               dev_t dev)
     2824                              const rtems_disk_device *dd)
    28802825{
    28812826  rtems_bdbuf_buffer *stack [RTEMS_BDBUF_AVL_MAX_HEIGHT];
     
    28872832  while (cur != NULL)
    28882833  {
    2889     if ((*compare) (cur->dev, dev))
     2834    if (cur->dd == dd)
    28902835    {
    28912836      switch (cur->state)
     
    29512896}
    29522897
    2953 static void
    2954 rtems_bdbuf_purge (rtems_bdbuf_purge_compare compare, dev_t dev)
     2898void
     2899rtems_bdbuf_purge_dev (const rtems_disk_device *dd)
    29552900{
    29562901  rtems_chain_control purge_list;
     
    29582903  rtems_chain_initialize_empty (&purge_list);
    29592904  rtems_bdbuf_lock_cache ();
    2960   rtems_bdbuf_gather_for_purge (&purge_list, compare, dev);
     2905  rtems_bdbuf_gather_for_purge (&purge_list, dd);
    29612906  rtems_bdbuf_purge_list (&purge_list);
    29622907  rtems_bdbuf_unlock_cache ();
    29632908}
    2964 
    2965 static bool
    2966 rtems_bdbuf_purge_compare_dev (dev_t a, dev_t b)
    2967 {
    2968   return a == b;
    2969 }
    2970 
    2971 void
    2972 rtems_bdbuf_purge_dev (dev_t dev)
    2973 {
    2974   rtems_bdbuf_purge (rtems_bdbuf_purge_compare_dev, dev);
    2975 }
    2976 
    2977 static bool
    2978 rtems_bdbuf_purge_compare_major (dev_t a, dev_t b)
    2979 {
    2980   return rtems_filesystem_dev_major_t (a) == rtems_filesystem_dev_major_t (b);
    2981 }
    2982 
    2983 void
    2984 rtems_bdbuf_purge_major (rtems_device_major_number major)
    2985 {
    2986   dev_t dev = rtems_filesystem_make_dev_t (major, 0);
    2987 
    2988   rtems_bdbuf_purge (rtems_bdbuf_purge_compare_major, dev);
    2989 }
  • cpukit/libblock/src/bdpart-create.c

    r1024561 r796967c  
    4646  rtems_blkdev_bnum overhead = 0;
    4747  rtems_blkdev_bnum free_space = 0;
    48   dev_t disk = 0;
    4948  size_t i = 0;
    5049
     
    6160
    6261  /* Get disk data */
    63   sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
     62  sc = rtems_bdpart_get_disk_data( disk_name, NULL, NULL, &disk_end);
    6463  if (sc != RTEMS_SUCCESSFUL) {
    6564    return sc;
     
    143142    s += record_space - (s % record_space);
    144143
     144    /* Reserve space for the EBR if necessary */
     145    if (count > 4 && i > 2) {
     146      pos += record_space;
     147    }
     148
    145149    /* Partition begin and end */
    146150    p->begin = pos;
    147151    pos += s;
    148152    p->end = pos;
    149 
    150     /* Reserve space for the EBR if necessary */
    151     if (count > 4 && i > 2) {
    152       p->begin += record_space;
    153     }
    154153  }
    155154
  • cpukit/libblock/src/bdpart-read.c

    r1024561 r796967c  
    2424#endif
    2525
     26#include <sys/stat.h>
     27#include <fcntl.h>
     28
    2629#include <rtems.h>
    2730#include <rtems/bdbuf.h>
     
    6568rtems_status_code rtems_bdpart_get_disk_data(
    6669  const char *disk_name,
    67   dev_t *disk,
     70  int *fd_ptr,
     71  const rtems_disk_device **dd_ptr,
    6872  rtems_blkdev_bnum *disk_end
    6973)
     
    7175  rtems_status_code sc = RTEMS_SUCCESSFUL;
    7276  int rv = 0;
     77  int fd = -1;
     78  const rtems_disk_device *dd = NULL;
    7379  rtems_blkdev_bnum disk_begin = 0;
    7480  rtems_blkdev_bnum block_size = 0;
    75   rtems_disk_device *dd = NULL;
    76   struct stat st;
     81
     82  /* Open device file */
     83  fd = open( disk_name, O_RDWR);
     84  if (fd < 0) {
     85    sc = RTEMS_INVALID_NAME;
     86    goto error;
     87  }
    7788
    7889  /* Get disk handle */
    79   rv = stat( disk_name, &st);
     90  rv = rtems_disk_fd_get_disk_device( fd, &dd);
    8091  if (rv != 0) {
    81     return RTEMS_INVALID_NAME;
    82   }
    83   *disk = st.st_rdev;
     92    sc = RTEMS_INVALID_NAME;
     93    goto error;
     94  }
    8495
    8596  /* Get disk begin, end and block size */
    86   dd = rtems_disk_obtain( *disk);
    87   if (dd == NULL) {
    88     return RTEMS_INVALID_NAME;
    89   }
    9097  disk_begin = dd->start;
    9198  *disk_end = dd->size;
    9299  block_size = dd->block_size;
    93   sc = rtems_disk_release( dd);
    94   if (sc != RTEMS_SUCCESSFUL) {
    95     return sc;
    96   }
    97100
    98101  /* Check block size */
    99102  if (block_size < RTEMS_BDPART_BLOCK_SIZE) {
    100     return RTEMS_IO_ERROR;
     103    sc = RTEMS_IO_ERROR;
     104    goto error;
    101105  }
    102106
    103107  /* Check that we have do not have a logical disk */
    104108  if (disk_begin != 0) {
    105     return RTEMS_IO_ERROR;
    106   }
    107 
    108   return RTEMS_SUCCESSFUL;
     109    sc = RTEMS_IO_ERROR;
     110    goto error;
     111  }
     112
     113error:
     114
     115  if (sc == RTEMS_SUCCESSFUL && fd_ptr != NULL && dd_ptr != NULL) {
     116    *fd_ptr = fd;
     117    *dd_ptr = dd;
     118  } else {
     119    close( fd);
     120  }
     121
     122  return sc;
    109123}
    110124
     
    172186
    173187static rtems_status_code rtems_bdpart_read_record(
    174   dev_t disk,
     188  const rtems_disk_device *dd,
    175189  rtems_blkdev_bnum index,
    176190  rtems_bdbuf_buffer **block
     
    188202
    189203  /* Read the record block */
    190   sc = rtems_bdbuf_read( disk, index, block);
     204  sc = rtems_bdbuf_read( dd, index, block);
    191205  if (sc != RTEMS_SUCCESSFUL) {
    192206    return sc;
     
    221235  rtems_blkdev_bnum ebr = 0; /* Extended boot record block index */
    222236  rtems_blkdev_bnum disk_end = 0;
    223   dev_t disk = 0;
    224237  size_t i = 0;
    225238  const uint8_t *data = NULL;
     239  int fd = -1;
     240  const rtems_disk_device *dd = NULL;
    226241
    227242  /* Check parameter */
     
    234249
    235250  /* Get disk data */
    236   sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
     251  sc = rtems_bdpart_get_disk_data( disk_name, &fd, &dd, &disk_end);
    237252  if (sc != RTEMS_SUCCESSFUL) {
    238253    return sc;
     
    240255
    241256  /* Read MBR */
    242   sc = rtems_bdpart_read_record( disk, 0, &block);
     257  sc = rtems_bdpart_read_record( dd, 0, &block);
    243258  if (sc != RTEMS_SUCCESSFUL) {
    244259    esc = sc;
     
    284299
    285300    /* Read EBR */
    286     sc = rtems_bdpart_read_record( disk, ebr, &block);
     301    sc = rtems_bdpart_read_record( dd, ebr, &block);
    287302    if (sc != RTEMS_SUCCESSFUL) {
    288303      esc = sc;
     
    341356cleanup:
    342357
     358  if (fd >= 0) {
     359    close( fd);
     360  }
     361
    343362  if (block != NULL) {
    344363    rtems_bdbuf_release( block);
  • cpukit/libblock/src/bdpart-register.c

    r1024561 r796967c  
    4848  size_t disk_name_size = strlen( disk_name);
    4949  size_t i = 0;
     50  int fd = -1;
     51  const rtems_disk_device *dd = NULL;
    5052
    5153  /* Get disk data */
    52   sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
     54  sc = rtems_bdpart_get_disk_data( disk_name, &fd, &dd, &disk_end);
    5355  if (sc != RTEMS_SUCCESSFUL) {
    5456    return sc;
    5557  }
     58  disk = rtems_disk_get_device_identifier( dd);
     59  close( fd);
    5660
    5761  /* Get the disk device identifier */
     
    135139  dev_t logical_disk = 0;
    136140  size_t i = 0;
     141  int fd = -1;
     142  const rtems_disk_device *dd = NULL;
    137143
    138144  /* Get disk data */
    139   sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
     145  sc = rtems_bdpart_get_disk_data( disk_name, &fd, &dd, &disk_end);
    140146  if (sc != RTEMS_SUCCESSFUL) {
    141147    return sc;
    142148  }
     149  disk = rtems_disk_get_device_identifier( dd);
     150  close( fd);
    143151
    144152  /* Get the disk device identifier */
  • cpukit/libblock/src/bdpart-write.c

    r1024561 r796967c  
    4646
    4747static rtems_status_code rtems_bdpart_new_record(
    48   dev_t disk,
     48  const rtems_disk_device *dd,
    4949  rtems_blkdev_bnum index,
    5050  rtems_bdbuf_buffer **block
     
    6262
    6363  /* Read the new record block (this accounts for disk block sizes > 512) */
    64   sc = rtems_bdbuf_read( disk, index, block);
     64  sc = rtems_bdbuf_read( dd, index, block);
    6565  if (sc != RTEMS_SUCCESSFUL) {
    6666    return sc;
     
    100100  rtems_blkdev_bnum record_space =
    101101    dos_compatibility ? RTEMS_BDPART_MBR_CYLINDER_SIZE : 1;
    102   dev_t disk = 0;
    103102  size_t ppc = 0; /* Primary partition count */
    104103  size_t i = 0;
    105104  uint8_t *data = NULL;
     105  int fd = -1;
     106  const rtems_disk_device *dd = NULL;
    106107
    107108  /* Check if we have something to do */
     
    117118
    118119  /* Get disk data */
    119   sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
     120  sc = rtems_bdpart_get_disk_data( disk_name, &fd, &dd, &disk_end);
    120121  if (sc != RTEMS_SUCCESSFUL) {
    121122    return sc;
     
    212213
    213214  /* New MBR */
    214   sc = rtems_bdpart_new_record( disk, 0, &block);
     215  sc = rtems_bdpart_new_record( dd, 0, &block);
    215216  if (sc != RTEMS_SUCCESSFUL) {
    216217    esc = sc;
     
    276277      /* New EBR */
    277278      ebr = p->begin - record_space;
    278       sc = rtems_bdpart_new_record( disk, ebr, &block);
     279      sc = rtems_bdpart_new_record( dd, ebr, &block);
    279280      if (sc != RTEMS_SUCCESSFUL) {
    280281        esc = sc;
     
    295296cleanup:
    296297
     298  if (fd >= 0) {
     299    close( fd);
     300  }
     301
    297302  if (block != NULL) {
    298303    rtems_bdbuf_sync( block);
  • cpukit/libblock/src/blkdev.c

    r1024561 r796967c  
    4747    rtems_blkdev_bnum block = (rtems_blkdev_bnum) (args->offset / block_size);
    4848    uint32_t blkofs = (uint32_t) (args->offset % block_size);
    49     dev_t dev = dd->dev;
    5049
    5150    args->bytes_moved = 0;
     
    5655        uint32_t            copy;
    5756
    58         rc = rtems_bdbuf_read(dev, block, &diskbuf);
     57        rc = rtems_bdbuf_read(dd, block, &diskbuf);
    5958        if (rc != RTEMS_SUCCESSFUL)
    6059            break;
     
    9594    rtems_blkdev_bnum block = (rtems_blkdev_bnum) (args->offset / block_size);
    9695    uint32_t blkofs = (uint32_t) (args->offset % block_size);
    97     dev_t dev = dd->dev;
    9896
    9997    args->bytes_moved = 0;
     
    105103
    106104        if ((blkofs == 0) && (count >= block_size))
    107             rc = rtems_bdbuf_get(dev, block, &diskbuf);
     105            rc = rtems_bdbuf_get(dd, block, &diskbuf);
    108106        else
    109             rc = rtems_bdbuf_read(dev, block, &diskbuf);
     107            rc = rtems_bdbuf_read(dd, block, &diskbuf);
    110108        if (rc != RTEMS_SUCCESSFUL)
    111109            break;
     
    208206
    209207        case RTEMS_BLKIO_SYNCDEV:
    210             rc = rtems_bdbuf_syncdev(dd->dev);
     208            rc = rtems_bdbuf_syncdev(dd);
    211209            args->ioctl_return = (uint32_t) (rc == RTEMS_SUCCESSFUL ? 0 : -1);
    212210            break;
  • cpukit/libblock/src/media.c

    r1024561 r796967c  
    813813  if (state == RTEMS_MEDIA_STATE_READY) {
    814814    dev_t dev = 0;
     815    rtems_disk_device *dd = NULL;
    815816
    816817    sc = rtems_media_get_device_identifier(src, &dev);
     
    819820    }
    820821
    821     sc = rtems_bdbuf_syncdev(dev);
    822     if (sc != RTEMS_SUCCESSFUL) {
    823       rsc = RTEMS_IO_ERROR;
     822    dd = rtems_disk_obtain(dev);
     823    if (dd != NULL) {
     824      sc = rtems_bdbuf_syncdev(dd);
     825      if (sc != RTEMS_SUCCESSFUL) {
     826        rsc = RTEMS_IO_ERROR;
     827      }
    824828    }
    825829
     
    829833    }
    830834
    831     rtems_bdbuf_purge_dev(dev);
     835    if (dd != NULL) {
     836      rtems_bdbuf_purge_dev(dd);
     837      rtems_disk_release(dd);
     838    }
    832839
    833840    if (rtems_filesystem_dev_minor_t(dev) == 0) {
Note: See TracChangeset for help on using the changeset viewer.