Changeset b5b07cad in rtems


Ignore:
Timestamp:
Oct 29, 2009, 12:50:01 PM (10 years ago)
Author:
Thomas Doerfler <Thomas.Doerfler@…>
Branches:
4.10, 4.11, master
Children:
90d24022
Parents:
982ca110
Message:
  • - Reorderd AVL node fields to save space
  • Fixed printf() formats. New structure for waiters synchronization. Added BDBUF_INVALID_DEV define. New error handling in rtems_bdbuf_init().
  • Release disk in case of an error.
Location:
cpukit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r982ca110 rb5b07cad  
     12009-10-28      Sebastian Huber <sebastian.huber@embedded-brains.de>
     2
     3        * libblock/include/rtems/bdbuf.h: Reorderd AVL node fields to save
     4        space.
     5        * libblock/src/bdbuf.c: Fixed printf() formats. New structure for
     6        waiters synchronization. Added BDBUF_INVALID_DEV define. New error
     7        handling in rtems_bdbuf_init().
     8        * libblock/src/bdpart.c, libblock/src/blkdev.c: Release disk in case
     9        of an error.
     10
    1112009-10-28     Sebastian Huber <sebastian.huber@embedded-brains.de>
    212
  • cpukit/libblock/include/rtems/bdbuf.h

    r982ca110 rb5b07cad  
    3232extern "C" {
    3333#endif
    34        
     34
    3535/**
    3636 * @defgroup rtems_libblock Block Device Library
     
    184184  struct rtems_bdbuf_avl_node
    185185  {
    186     signed char                cache;  /**< Cache */
    187186    struct rtems_bdbuf_buffer* left;   /**< Left Child */
    188187    struct rtems_bdbuf_buffer* right;  /**< Right Child */
     188    signed char                cache;  /**< Cache */
    189189    signed char                bal;    /**< The balance of the sub-tree */
    190190  } avl;
  • cpukit/libblock/src/bdbuf.c

    r982ca110 rb5b07cad  
    3131#include "config.h"
    3232#endif
    33 
    34 #include <inttypes.h>
    35 
    36 #include <rtems.h>
    37 #include <rtems/error.h>
    38 #include <rtems/malloc.h>
    3933#include <limits.h>
    4034#include <errno.h>
    4135#include <assert.h>
    4236#include <stdio.h>
     37#include <string.h>
     38#include <inttypes.h>
     39
     40#include <rtems.h>
     41#include <rtems/error.h>
     42#include <rtems/malloc.h>
    4343
    4444#include "rtems/bdbuf.h"
     45
     46#define BDBUF_INVALID_DEV ((dev_t) -1)
    4547
    4648/*
     
    7779
    7880/**
     81 * Buffer waiters synchronization.
     82 */
     83typedef struct rtems_bdbuf_waiters {
     84  volatile unsigned count;
     85  rtems_id sema;
     86} rtems_bdbuf_waiters;
     87
     88/**
    7989 * The BD buffer cache.
    8090 */
     
    102112  volatile bool       sync_active;       /**< True if a sync is active. */
    103113  volatile rtems_id   sync_requester;    /**< The sync requester. */
    104   volatile dev_t      sync_device;       /**< The device to sync and -1 not a
    105                                           * device sync. */
     114  volatile dev_t      sync_device;       /**< The device to sync and
     115                                          * BDBUF_INVALID_DEV not a device
     116                                          * sync. */
    106117
    107118  rtems_bdbuf_buffer* tree;              /**< Buffer descriptor lookup AVL tree
     
    113124  rtems_chain_control sync;              /**< Buffers to sync list */
    114125
    115   rtems_id            access;            /**< Obtain if waiting for a buffer in
    116                                           * the ACCESS state. */
    117   volatile uint32_t   access_waiters;    /**< Count of access blockers. */
    118   rtems_id            transfer;          /**< Obtain if waiting for a buffer in
    119                                           * the TRANSFER state. */
    120   volatile uint32_t   transfer_waiters;  /**< Count of transfer blockers. */
    121   rtems_id            waiting;           /**< Obtain if waiting for a buffer
    122                                           * and the none are available. */
    123   volatile uint32_t   wait_waiters;      /**< Count of waiting blockers. */
     126  rtems_bdbuf_waiters access_waiters;    /**< Wait for a buffer in ACCESS
     127                                          * state. */
     128  rtems_bdbuf_waiters transfer_waiters;  /**< Wait for a buffer in TRANSFER
     129                                          * state. */
     130  rtems_bdbuf_waiters buffer_waiters;    /**< Wait for a buffer and no one is
     131                                          * available. */
    124132
    125133  size_t              group_count;       /**< The number of groups. */
     
    149157#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_LOCK    RTEMS_BLKDEV_FATAL_ERROR(13)
    150158#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)
     159#define RTEMS_BLKDEV_FATAL_BDBUF_PREEMPT_DIS   RTEMS_BLKDEV_FATAL_ERROR(15)
    152160#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)
     161#define RTEMS_BLKDEV_FATAL_BDBUF_PREEMPT_RST   RTEMS_BLKDEV_FATAL_ERROR(17)
    154162#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_TO RTEMS_BLKDEV_FATAL_ERROR(18)
    155163#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAKE    RTEMS_BLKDEV_FATAL_ERROR(19)
     
    249257  uint32_t total = 0;
    250258  uint32_t val;
     259
    251260  for (group = 0; group < bdbuf_cache.group_count; group++)
    252261    total += bdbuf_cache.groups[group].users;
     
    278287  const char* states[] =
    279288    { "EM", "RA", "CH", "AC", "MD", "AM", "SY", "TR" };
    280   printf ("bdbuf:users: %15s: [%ld (%s)] %ld:%ld = %lu %s\n",
     289
     290  printf ("bdbuf:users: %15s: [%" PRIu32 " (%s)] %td:%td = %" PRIu32 " %s\n",
    281291          where,
    282292          bd->block, states[bd->state],
     
    871881}
    872882
     883static rtems_mode
     884rtems_bdbuf_disable_preemption (void)
     885{
     886  rtems_status_code sc = RTEMS_SUCCESSFUL;
     887  rtems_mode prev_mode = 0;
     888
     889  sc = rtems_task_mode (RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &prev_mode);
     890  if (sc != RTEMS_SUCCESSFUL)
     891    rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_PREEMPT_DIS);
     892
     893  return prev_mode;
     894}
     895
     896static void
     897rtems_bdbuf_restore_preemption (rtems_mode prev_mode)
     898{
     899  rtems_status_code sc = RTEMS_SUCCESSFUL;
     900
     901  sc = rtems_task_mode (prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode);
     902  if (sc != RTEMS_SUCCESSFUL)
     903    rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_PREEMPT_RST);
     904}
     905
    873906/**
    874907 * Wait until woken. Semaphores are used so a number of tasks can wait and can
     
    890923 */
    891924static void
    892 rtems_bdbuf_wait (rtems_id* sema, volatile uint32_t* waiters)
     925rtems_bdbuf_wait (rtems_bdbuf_waiters* waiters)
    893926{
    894927  rtems_status_code sc;
     
    898931   * Indicate we are waiting.
    899932   */
    900   *waiters += 1;
     933  ++waiters->count;
    901934
    902935  /*
     
    910943   * semaphore.
    911944   */
    912   sc = rtems_task_mode (RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &prev_mode);
    913 
    914   if (sc != RTEMS_SUCCESSFUL)
    915     rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_1);
     945  prev_mode = rtems_bdbuf_disable_preemption ();
    916946 
    917947  /*
     
    920950  rtems_bdbuf_unlock_cache ();
    921951
    922   sc = rtems_semaphore_obtain (*sema, RTEMS_WAIT, RTEMS_BDBUF_WAIT_TIMEOUT);
     952  sc = rtems_semaphore_obtain (waiters->sema, RTEMS_WAIT, RTEMS_BDBUF_WAIT_TIMEOUT);
    923953
    924954  if (sc == RTEMS_TIMEOUT)
     
    930960  rtems_bdbuf_lock_cache ();
    931961
    932   sc = rtems_task_mode (prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode);
    933 
    934   if (sc != RTEMS_SUCCESSFUL)
    935     rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_3);
    936  
    937   *waiters -= 1;
     962  rtems_bdbuf_restore_preemption (prev_mode);
     963 
     964  --waiters->count;
    938965}
    939966
     
    941968 * Wake a blocked resource. The resource has a counter that lets us know if
    942969 * there are any waiters.
    943  *
    944  * @param sema The semaphore to release.
    945  * @param waiters The wait counter for this semaphore.
    946970 */
    947971static void
    948 rtems_bdbuf_wake (rtems_id sema, volatile uint32_t* waiters)
    949 {
    950   if (*waiters)
    951   {
    952     rtems_status_code sc;
    953 
    954     sc = rtems_semaphore_flush (sema);
    955  
     972rtems_bdbuf_wake (const rtems_bdbuf_waiters *waiters)
     973{
     974  rtems_status_code sc = RTEMS_SUCCESSFUL;
     975
     976  if (waiters->count > 0)
     977  {
     978    sc = rtems_semaphore_flush (waiters->sema);
    956979    if (sc != RTEMS_SUCCESSFUL)
    957980      rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAKE);
     
    11501173  uint8_t*            buffer;
    11511174  size_t              b;
    1152   int                 cache_aligment;
     1175  size_t              cache_aligment;
    11531176  rtems_status_code   sc;
     1177  rtems_mode          prev_mode;
    11541178
    11551179  if (rtems_bdbuf_tracer)
    11561180    printf ("bdbuf:init\n");
     1181
     1182  if (rtems_interrupt_is_in_progress())
     1183    return RTEMS_CALLED_FROM_ISR;
    11571184
    11581185  /*
     
    11671194   * makes a call and we have not finished initialisation.
    11681195   */
     1196  prev_mode = rtems_bdbuf_disable_preemption ();
    11691197  if (bdbuf_cache.initialised)
     1198  {
     1199    rtems_bdbuf_restore_preemption (prev_mode);
     1200
    11701201    return RTEMS_RESOURCE_IN_USE;
    1171 
     1202  }
     1203  memset(&bdbuf_cache, 0, sizeof(bdbuf_cache));
    11721204  bdbuf_cache.initialised = true;
     1205  rtems_bdbuf_restore_preemption (prev_mode);
    11731206 
    11741207  /*
     
    11791212    cache_aligment = CPU_ALIGNMENT;
    11801213
    1181   bdbuf_cache.sync_active    = false;
    1182   bdbuf_cache.sync_device    = -1;
    1183   bdbuf_cache.sync_requester = 0;
    1184   bdbuf_cache.tree           = NULL;
     1214  bdbuf_cache.sync_device = BDBUF_INVALID_DEV;
    11851215
    11861216  rtems_chain_initialize_empty (&bdbuf_cache.swapout_workers);
     
    11901220  rtems_chain_initialize_empty (&bdbuf_cache.sync);
    11911221
    1192   bdbuf_cache.access           = 0;
    1193   bdbuf_cache.access_waiters   = 0;
    1194   bdbuf_cache.transfer         = 0;
    1195   bdbuf_cache.transfer_waiters = 0;
    1196   bdbuf_cache.waiting          = 0;
    1197   bdbuf_cache.wait_waiters     = 0;
    1198 
    11991222  /*
    12001223   * Create the locks for the cache.
     
    12041227                               &bdbuf_cache.lock);
    12051228  if (sc != RTEMS_SUCCESSFUL)
    1206   {
    1207     bdbuf_cache.initialised = false;
    1208     return sc;
    1209   }
     1229    goto error;
    12101230
    12111231  rtems_bdbuf_lock_cache ();
     
    12151235                               &bdbuf_cache.sync_lock);
    12161236  if (sc != RTEMS_SUCCESSFUL)
    1217   {
    1218     rtems_bdbuf_unlock_cache ();
    1219     rtems_semaphore_delete (bdbuf_cache.lock);
    1220     bdbuf_cache.initialised = false;
    1221     return sc;
    1222   }
     1237    goto error;
    12231238 
    12241239  sc = rtems_semaphore_create (rtems_build_name ('B', 'D', 'C', 'a'),
    12251240                               0, RTEMS_BDBUF_CACHE_WAITER_ATTRIBS, 0,
    1226                                &bdbuf_cache.access);
     1241                               &bdbuf_cache.access_waiters.sema);
    12271242  if (sc != RTEMS_SUCCESSFUL)
    1228   {
    1229     rtems_semaphore_delete (bdbuf_cache.sync_lock);
    1230     rtems_bdbuf_unlock_cache ();
    1231     rtems_semaphore_delete (bdbuf_cache.lock);
    1232     bdbuf_cache.initialised = false;
    1233     return sc;
    1234   }
     1243    goto error;
    12351244
    12361245  sc = rtems_semaphore_create (rtems_build_name ('B', 'D', 'C', 't'),
    12371246                               0, RTEMS_BDBUF_CACHE_WAITER_ATTRIBS, 0,
    1238                                &bdbuf_cache.transfer);
     1247                               &bdbuf_cache.transfer_waiters.sema);
    12391248  if (sc != RTEMS_SUCCESSFUL)
    1240   {
    1241     rtems_semaphore_delete (bdbuf_cache.access);
    1242     rtems_semaphore_delete (bdbuf_cache.sync_lock);
    1243     rtems_bdbuf_unlock_cache ();
    1244     rtems_semaphore_delete (bdbuf_cache.lock);
    1245     bdbuf_cache.initialised = false;
    1246     return sc;
    1247   }
     1249    goto error;
    12481250
    12491251  sc = rtems_semaphore_create (rtems_build_name ('B', 'D', 'C', 'w'),
    12501252                               0, RTEMS_BDBUF_CACHE_WAITER_ATTRIBS, 0,
    1251                                &bdbuf_cache.waiting);
     1253                               &bdbuf_cache.buffer_waiters.sema);
    12521254  if (sc != RTEMS_SUCCESSFUL)
    1253   {
    1254     rtems_semaphore_delete (bdbuf_cache.transfer);
    1255     rtems_semaphore_delete (bdbuf_cache.access);
    1256     rtems_semaphore_delete (bdbuf_cache.sync_lock);
    1257     rtems_bdbuf_unlock_cache ();
    1258     rtems_semaphore_delete (bdbuf_cache.lock);
    1259     bdbuf_cache.initialised = false;
    1260     return sc;
    1261   }
     1255    goto error;
    12621256 
    12631257  /*
     
    12771271                            bdbuf_cache.buffer_min_count);
    12781272  if (!bdbuf_cache.bds)
    1279   {
    1280     rtems_semaphore_delete (bdbuf_cache.transfer);
    1281     rtems_semaphore_delete (bdbuf_cache.access);
    1282     rtems_semaphore_delete (bdbuf_cache.sync_lock);
    1283     rtems_bdbuf_unlock_cache ();
    1284     rtems_semaphore_delete (bdbuf_cache.lock);
    1285     bdbuf_cache.initialised = false;
    1286     return RTEMS_NO_MEMORY;
    1287   }
     1273    goto error;
    12881274
    12891275  /*
     
    12931279                               bdbuf_cache.group_count);
    12941280  if (!bdbuf_cache.groups)
    1295   {
    1296     free (bdbuf_cache.bds);
    1297     rtems_semaphore_delete (bdbuf_cache.transfer);
    1298     rtems_semaphore_delete (bdbuf_cache.access);
    1299     rtems_semaphore_delete (bdbuf_cache.sync_lock);
    1300     rtems_bdbuf_unlock_cache ();
    1301     rtems_semaphore_delete (bdbuf_cache.lock);
    1302     bdbuf_cache.initialised = false;
    1303     return RTEMS_NO_MEMORY;
    1304   }
     1281    goto error;
    13051282 
    13061283  /*
     
    13141291                      cache_aligment,
    13151292                      bdbuf_cache.buffer_min_count * bdbuf_config.buffer_min) != 0)
    1316   {
    1317     free (bdbuf_cache.groups);
    1318     free (bdbuf_cache.bds);
    1319     rtems_semaphore_delete (bdbuf_cache.transfer);
    1320     rtems_semaphore_delete (bdbuf_cache.access);
    1321     rtems_semaphore_delete (bdbuf_cache.sync_lock);
    1322     rtems_bdbuf_unlock_cache ();
    1323     rtems_semaphore_delete (bdbuf_cache.lock);
    1324     bdbuf_cache.initialised = false;
    1325     return RTEMS_NO_MEMORY;
    1326   }
     1293    goto error;
    13271294
    13281295  /*
     
    13351302       b++, bd++, buffer += bdbuf_config.buffer_min)
    13361303  {
    1337     bd->dev        = -1;
     1304    bd->dev        = BDBUF_INVALID_DEV;
    13381305    bd->group      = group;
    13391306    bd->buffer     = buffer;
     
    13821349                          &bdbuf_cache.swapout);
    13831350  if (sc != RTEMS_SUCCESSFUL)
    1384   {
    1385     free (bdbuf_cache.buffers);
    1386     free (bdbuf_cache.groups);
    1387     free (bdbuf_cache.bds);
    1388     rtems_semaphore_delete (bdbuf_cache.transfer);
    1389     rtems_semaphore_delete (bdbuf_cache.access);
    1390     rtems_semaphore_delete (bdbuf_cache.sync_lock);
    1391     rtems_bdbuf_unlock_cache ();
    1392     rtems_semaphore_delete (bdbuf_cache.lock);
    1393     bdbuf_cache.initialised = false;
    1394     return sc;
    1395   }
     1351    goto error;
    13961352
    13971353  sc = rtems_task_start (bdbuf_cache.swapout,
     
    13991355                         (rtems_task_argument) &bdbuf_cache);
    14001356  if (sc != RTEMS_SUCCESSFUL)
    1401   {
     1357    goto error;
     1358
     1359  rtems_bdbuf_unlock_cache ();
     1360
     1361  return RTEMS_SUCCESSFUL;
     1362
     1363error:
     1364
     1365  if (bdbuf_cache.swapout != 0)
    14021366    rtems_task_delete (bdbuf_cache.swapout);
    1403     free (bdbuf_cache.buffers);
    1404     free (bdbuf_cache.groups);
    1405     free (bdbuf_cache.bds);
    1406     rtems_semaphore_delete (bdbuf_cache.transfer);
    1407     rtems_semaphore_delete (bdbuf_cache.access);
    1408     rtems_semaphore_delete (bdbuf_cache.sync_lock);
     1367
     1368  free (bdbuf_cache.buffers);
     1369  free (bdbuf_cache.groups);
     1370  free (bdbuf_cache.bds);
     1371
     1372  rtems_semaphore_delete (bdbuf_cache.buffer_waiters.sema);
     1373  rtems_semaphore_delete (bdbuf_cache.access_waiters.sema);
     1374  rtems_semaphore_delete (bdbuf_cache.transfer_waiters.sema);
     1375  rtems_semaphore_delete (bdbuf_cache.sync_lock);
     1376
     1377  if (bdbuf_cache.lock != 0)
     1378  {
    14091379    rtems_bdbuf_unlock_cache ();
    14101380    rtems_semaphore_delete (bdbuf_cache.lock);
    1411     bdbuf_cache.initialised = false;
    1412     return sc;
    1413   }
    1414 
    1415   rtems_bdbuf_unlock_cache ();
    1416  
    1417   return RTEMS_SUCCESSFUL;
     1381  }
     1382
     1383  bdbuf_cache.initialised = false;
     1384
     1385  return RTEMS_UNSATISFIED;
    14181386}
    14191387
     
    15881556           * placed on the LRU list.
    15891557           */
    1590           rtems_bdbuf_wait (&bdbuf_cache.waiting, &bdbuf_cache.wait_waiters);
     1558          rtems_bdbuf_wait (&bdbuf_cache.buffer_waiters);
    15911559        }
    15921560      }
     
    16711639      case RTEMS_BDBUF_STATE_ACCESS_MODIFIED:
    16721640        bd->waiters++;
    1673         rtems_bdbuf_wait (&bdbuf_cache.access, &bdbuf_cache.access_waiters);
     1641        rtems_bdbuf_wait (&bdbuf_cache.access_waiters);
    16741642        bd->waiters--;
    16751643        break;
     
    16781646      case RTEMS_BDBUF_STATE_TRANSFER:
    16791647        bd->waiters++;
    1680         rtems_bdbuf_wait (&bdbuf_cache.transfer, &bdbuf_cache.transfer_waiters);
     1648        rtems_bdbuf_wait (&bdbuf_cache.transfer_waiters);
    16811649        bd->waiters--;
    16821650        break;
     
    17441712   */
    17451713  if (rtems_bdbuf_tracer)
    1746     printf ("bdbuf:get: %lu (%lu) (dev = %08x)\n",
    1747             media_block, block, (unsigned int) device);
     1714    printf ("bdbuf:get: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
     1715            media_block, block, (unsigned) device);
    17481716
    17491717  bd = rtems_bdbuf_get_buffer (dd, bds_per_group, media_block, false);
     
    18601828   */
    18611829  if (rtems_bdbuf_tracer)
    1862     printf ("bdbuf:read: %lu (%lu) (dev = %08x)\n",
    1863             media_block + dd->start, block, (unsigned int) device);
     1830    printf ("bdbuf:read: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
     1831            media_block + dd->start, block, (unsigned) device);
    18641832
    18651833  /*
     
    20352003
    20362004    if (wake_transfer)
    2037       rtems_bdbuf_wake (bdbuf_cache.transfer, &bdbuf_cache.transfer_waiters);
     2005      rtems_bdbuf_wake (&bdbuf_cache.transfer_waiters);
    20382006    else
    2039       rtems_bdbuf_wake (bdbuf_cache.waiting, &bdbuf_cache.wait_waiters);
     2007      rtems_bdbuf_wake (&bdbuf_cache.buffer_waiters);
    20402008   
    20412009    bd = req->bufs[0].user;
     
    20932061
    20942062  if (rtems_bdbuf_tracer)
    2095     printf ("bdbuf:release: %lu\n", bd->block);
     2063    printf ("bdbuf:release: %" PRIu32 "\n", bd->block);
    20962064 
    20972065  if (bd->state == RTEMS_BDBUF_STATE_ACCESS_MODIFIED)
     
    21182086   */
    21192087  if (bd->waiters)
    2120     rtems_bdbuf_wake (bdbuf_cache.access, &bdbuf_cache.access_waiters);
     2088    rtems_bdbuf_wake (&bdbuf_cache.access_waiters);
    21212089  else
    2122     rtems_bdbuf_wake (bdbuf_cache.waiting, &bdbuf_cache.wait_waiters);
     2090    rtems_bdbuf_wake (&bdbuf_cache.buffer_waiters);
    21232091 
    21242092  if (rtems_bdbuf_tracer)
     
    21422110
    21432111  if (rtems_bdbuf_tracer)
    2144     printf ("bdbuf:release modified: %lu\n", bd->block);
     2112    printf ("bdbuf:release modified: %" PRIu32 "\n", bd->block);
    21452113
    21462114  bd->hold_timer = rtems_bdbuf_configuration.swap_block_hold;
     
    21522120
    21532121  if (bd->waiters)
    2154     rtems_bdbuf_wake (bdbuf_cache.access, &bdbuf_cache.access_waiters);
     2122    rtems_bdbuf_wake (&bdbuf_cache.access_waiters);
    21552123 
    21562124  if (rtems_bdbuf_tracer)
     
    21682136
    21692137  if (rtems_bdbuf_tracer)
    2170     printf ("bdbuf:sync: %lu\n", bd->block);
     2138    printf ("bdbuf:sync: %" PRIu32 "\n", bd->block);
    21712139 
    21722140  if (!bdbuf_cache.initialised)
     
    22002168      case RTEMS_BDBUF_STATE_TRANSFER:
    22012169        bd->waiters++;
    2202         rtems_bdbuf_wait (&bdbuf_cache.transfer, &bdbuf_cache.transfer_waiters);
     2170        rtems_bdbuf_wait (&bdbuf_cache.transfer_waiters);
    22032171        bd->waiters--;
    22042172        break;
     
    22222190
    22232191  if (rtems_bdbuf_tracer)
    2224     printf ("bdbuf:syncdev: %08x\n", (unsigned int) dev);
     2192    printf ("bdbuf:syncdev: %08x\n", (unsigned) dev);
    22252193
    22262194  if (!bdbuf_cache.initialised)
     
    23042272 
    23052273  if (rtems_bdbuf_tracer)
    2306     printf ("bdbuf:swapout transfer: %08x\n", (unsigned int) transfer->dev);
     2274    printf ("bdbuf:swapout transfer: %08x\n", (unsigned) transfer->dev);
    23072275
    23082276  /*
     
    23582326       
    23592327        if (rtems_bdbuf_tracer)
    2360           printf ("bdbuf:swapout write: bd:%lu, bufnum:%lu mode:%s\n",
     2328          printf ("bdbuf:swapout write: bd:%" PRIu32 ", bufnum:%" PRIu32 " mode:%s\n",
    23612329                  bd->block, transfer->write_req->bufnum,
    23622330                  dd->phys_dev->capabilities &
     
    23972365
    23982366          if (rtems_bdbuf_tracer)
    2399             printf ("bdbuf:swapout write: writing bufnum:%lu\n",
     2367            printf ("bdbuf:swapout write: writing bufnum:%" PRIu32 "\n",
    24002368                    transfer->write_req->bufnum);
    24012369
     
    24552423             
    24562424              if (bd->waiters)
    2457                 rtems_bdbuf_wake (bdbuf_cache.transfer, &bdbuf_cache.transfer_waiters);
     2425                rtems_bdbuf_wake (&bdbuf_cache.transfer_waiters);
    24582426              else
    2459                 rtems_bdbuf_wake (bdbuf_cache.waiting, &bdbuf_cache.wait_waiters);
     2427                rtems_bdbuf_wake (&bdbuf_cache.buffer_waiters);
    24602428            }
    24612429          }
     
    24892457 * needs to be handled so we have a common function to do the work.
    24902458 *
    2491  * @param dev The device to handle. If -1 no device is selected so select the
    2492  *           device of the first buffer to be written to disk.
     2459 * @param dev The device to handle. If BDBUF_INVALID_DEV no device is selected
     2460 * so select the device of the first buffer to be written to disk.
    24932461 * @param chain The modified chain to process.
    24942462 * @param transfer The chain to append buffers to be written too.
     
    25432511
    25442512      /*
    2545        * This assumes we can set dev_t to -1 which is just an
     2513       * This assumes we can set dev_t to BDBUF_INVALID_DEV which is just an
    25462514       * assumption. Cannot use the transfer list being empty the sync dev
    25472515       * calls sets the dev to use.
    25482516       */
    2549       if (*dev == (dev_t)-1)
     2517      if (*dev == BDBUF_INVALID_DEV)
    25502518        *dev = bd->dev;
    25512519
     
    26402608 
    26412609  rtems_chain_initialize_empty (&transfer->bds);
    2642   transfer->dev = -1;
     2610  transfer->dev = BDBUF_INVALID_DEV;
    26432611 
    26442612  /*
    26452613   * When the sync is for a device limit the sync to that device. If the sync
    26462614   * is for a buffer handle process the devices in the order on the sync
    2647    * list. This means the dev is -1.
     2615   * list. This means the dev is BDBUF_INVALID_DEV.
    26482616   */
    26492617  if (bdbuf_cache.sync_active)
     
    27712739
    27722740    rtems_chain_initialize_empty (&worker->transfer.bds);
    2773     worker->transfer.dev = -1;
     2741    worker->transfer.dev = BDBUF_INVALID_DEV;
    27742742
    27752743    rtems_chain_append (&bdbuf_cache.swapout_workers, &worker->link);
     
    28082776   
    28092777    rtems_chain_initialize_empty (&worker->transfer.bds);
    2810     worker->transfer.dev = -1;
     2778    worker->transfer.dev = BDBUF_INVALID_DEV;
    28112779
    28122780    sc = rtems_task_create (rtems_build_name('B', 'D', 'o', 'a' + w),
     
    28702838  transfer.write_req = rtems_bdbuf_swapout_writereq_alloc ();
    28712839  rtems_chain_initialize_empty (&transfer.bds);
    2872   transfer.dev = -1;
     2840  transfer.dev = BDBUF_INVALID_DEV;
    28732841
    28742842  /*
     
    29422910  rtems_task_delete (RTEMS_SELF);
    29432911}
    2944 
  • cpukit/libblock/src/bdpart.c

    r982ca110 rb5b07cad  
    350350  sc = rtems_bdpart_read_record( disk, 0, &block);
    351351  if (sc != RTEMS_SUCCESSFUL) {
    352     return sc;
     352    esc = sc;
     353    goto cleanup;
    353354  }
    354355
     
    393394    sc = rtems_bdpart_read_record( disk, ebr, &block);
    394395    if (sc != RTEMS_SUCCESSFUL) {
    395       return sc;
     396      esc = sc;
     397      goto cleanup;
    396398    }
    397399
  • cpukit/libblock/src/blkdev.c

    r982ca110 rb5b07cad  
    3838    void                    * arg)
    3939{
     40    rtems_status_code rc = RTEMS_SUCCESSFUL;
    4041    rtems_libio_rw_args_t *args = arg;
    41     int block_size;
    42     char         *buf;
    43     unsigned int count;
    44     unsigned int block;
    45     unsigned int blkofs;
     42    uint32_t block_size;
     43    char *buf;
     44    uint32_t count;
     45    rtems_blkdev_bnum block;
     46    uint32_t blkofs;
    4647    dev_t dev;
    4748    rtems_disk_device *dd;
     
    5859    args->bytes_moved = 0;
    5960
    60     block = args->offset / block_size;
    61     blkofs = args->offset % block_size;
     61    block = (rtems_blkdev_bnum) (args->offset / block_size);
     62    blkofs = (uint32_t) (args->offset % block_size);
    6263
    6364    while (count > 0)
     
    6566        rtems_bdbuf_buffer *diskbuf;
    6667        uint32_t            copy;
    67         rtems_status_code   rc;
    6868
    6969        rc = rtems_bdbuf_read(dev, block, &diskbuf);
    7070        if (rc != RTEMS_SUCCESSFUL)
    71             return rc;
     71            break;
    7272        copy = block_size - blkofs;
    7373        if (copy > count)
     
    7777        args->bytes_moved += copy;
    7878        if (rc != RTEMS_SUCCESSFUL)
    79             return rc;
     79            break;
    8080        count -= copy;
    8181        buf += copy;
     
    8383        block++;
    8484    }
    85     return RTEMS_SUCCESSFUL;
     85
     86    rtems_disk_release(dd);
     87
     88    return rc;
    8689}
    8790
     
    9699    void                    * arg)
    97100{
     101    rtems_status_code rc = RTEMS_SUCCESSFUL;
    98102    rtems_libio_rw_args_t *args = arg;
    99     uint32_t      block_size;
    100     char         *buf;
    101     uint32_t      count;
    102     uint32_t      block;
    103     uint32_t      blkofs;
    104     dev_t dev;
    105     rtems_status_code rc;
     103    uint32_t block_size;
     104    char *buf;
     105    uint32_t count;
     106    rtems_blkdev_bnum block;
     107    uint32_t blkofs;
     108    dev_t dev;
    106109    rtems_disk_device *dd;
    107110
     
    117120    args->bytes_moved = 0;
    118121
    119     block = args->offset / block_size;
    120     blkofs = args->offset % block_size;
     122    block = (rtems_blkdev_bnum) (args->offset / block_size);
     123    blkofs = (uint32_t) (args->offset % block_size);
    121124
    122125    while (count > 0)
     
    130133            rc = rtems_bdbuf_read(dev, block, &diskbuf);
    131134        if (rc != RTEMS_SUCCESSFUL)
    132             return rc;
     135            break;
    133136
    134137        copy = block_size - blkofs;
     
    140143        rc = rtems_bdbuf_release_modified(diskbuf);
    141144        if (rc != RTEMS_SUCCESSFUL)
    142             return rc;
     145            break;
    143146
    144147        count -= copy;
     
    147150        block++;
    148151    }
    149     return RTEMS_SUCCESSFUL;
     152
     153    rtems_disk_release(dd);
     154
     155    return rc;
    150156}
    151157
Note: See TracChangeset for help on using the changeset viewer.