Changeset 3d5515b in rtems


Ignore:
Timestamp:
Oct 30, 2009, 10:57:39 AM (10 years ago)
Author:
Thomas Doerfler <Thomas.Doerfler@…>
Branches:
4.10, 4.11, master
Children:
2960c42
Parents:
3fd5ece0
Message:

Fixed group usage counting. See test "libtests/block02".

Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r3fd5ece0 r3d5515b  
     12009-10-30      Sebastian Huber <sebastian.huber@embedded-brains.de>
     2
     3        * libblock/src/bdbuf.c: Fixed group usage counting.  See test
     4        "libtests/block02".
     5
    162009-10-30      Ralf Corsépius <ralf.corsepiu@rtems.org>
    27
  • cpukit/libblock/src/bdbuf.c

    r3fd5ece0 r3d5515b  
    13861386}
    13871387
     1388static inline void
     1389rtems_bdbuf_group_obtain (rtems_bdbuf_buffer *bd)
     1390{
     1391  ++bd->group->users;
     1392}
     1393
     1394static inline void
     1395rtems_bdbuf_group_release (rtems_bdbuf_buffer *bd)
     1396{
     1397  --bd->group->users;
     1398}
     1399
    13881400/**
    13891401 * Get a buffer for this device and block. This function returns a buffer once
     
    14331445 * different the buffer size for the block has changed. The buffer needs to be
    14341446 * invalidated.
     1447 *
     1448 * The returned buffer will be a user its group.
    14351449 *
    14361450 * @param dd The disk device. Has the configured block size.
     
    15881602          rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_5);
    15891603
     1604        rtems_bdbuf_group_obtain (bd);
     1605
    15901606        return bd;
    15911607      }
     
    16221638
    16231639  /*
     1640   * Before we wait for the buffer, we have to obtain its group.  This prevents
     1641   * a reallocation.
     1642   */
     1643  rtems_bdbuf_group_obtain (bd);
     1644
     1645  /*
    16241646   * Loop waiting for the buffer to enter the cached state. If the buffer is in
    16251647   * the access or transfer state then wait until it is not.
     
    16601682  rtems_chain_extract (&bd->link);
    16611683
     1684  /*
     1685   * The modified list is no longer a user of the buffers group.
     1686   */
     1687  if (bd->state == RTEMS_BDBUF_STATE_MODIFIED)
     1688    rtems_bdbuf_group_release (bd);
     1689
    16621690  return bd;
    16631691}
     
    17181746
    17191747  /*
    1720    * This could be considered a bug in the caller because you should not be
    1721    * getting an already modified buffer but user may have modified a byte in a
    1722    * block then decided to seek the start and write the whole block and the
    1723    * file system will have no record of this so just gets the block to fill.
    1724    */
    1725   if (bd->state == RTEMS_BDBUF_STATE_MODIFIED)
     1748   * To get a modified buffer could be considered a bug in the caller because
     1749   * you should not be getting an already modified buffer but user may have
     1750   * modified a byte in a block then decided to seek the start and write the
     1751   * whole block and the file system will have no record of this so just gets
     1752   * the block to fill.
     1753   */
     1754  if (bd->state != RTEMS_BDBUF_STATE_MODIFIED)
     1755    bd->state = RTEMS_BDBUF_STATE_ACCESS;
     1756  else
    17261757    bd->state = RTEMS_BDBUF_STATE_ACCESS_MODIFIED;
    1727   else
    1728   {
    1729     bd->state = RTEMS_BDBUF_STATE_ACCESS;
    1730     /*
    1731      * Indicate a buffer in this group is being used.
    1732      */
    1733     bd->group->users++;
    1734   }
    17351758 
    17361759  if (rtems_bdbuf_tracer)
     
    17821805  rtems_blkdev_bnum     media_block;
    17831806  rtems_blkdev_bnum     media_block_count;
     1807  bool                  read_ahead = false;
    17841808 
    17851809  if (!bdbuf_cache.initialised)
     
    18601884     */
    18611885    bd = rtems_bdbuf_get_buffer (dd, bds_per_group, media_block + dd->start,
    1862                                  req->bufnum == 0 ? false : true);
     1886                                 read_ahead);
    18631887
    18641888    /*
     
    18741898    if ((bd->state == RTEMS_BDBUF_STATE_CACHED) ||
    18751899        (bd->state == RTEMS_BDBUF_STATE_MODIFIED))
     1900    {
     1901      if (read_ahead)
     1902        rtems_bdbuf_group_release (bd);
     1903
    18761904      break;
     1905    }
    18771906
    18781907    bd->state = RTEMS_BDBUF_STATE_TRANSFER;
    18791908    bd->error = 0;
    1880 
    1881     /*
    1882      * The buffer will be passed to the driver so this buffer has a user.
    1883      */
    1884     bd->group->users++;
    18851909
    18861910    if (rtems_bdbuf_tracer)
     
    19061930     */
    19071931    media_block += media_block_count;
     1932
     1933    /*
     1934     * After the first buffer we have read ahead buffers.
     1935     */
     1936    read_ahead = true;
    19081937  }
    19091938
     
    19792008        bd->error = req->error;
    19802009      bd->state = RTEMS_BDBUF_STATE_READ_AHEAD;
    1981       bd->group->users--;
     2010
     2011      rtems_bdbuf_group_release (bd);
    19822012
    19832013      if (rtems_bdbuf_tracer)
     
    20092039    bd = req->bufs[0].user;
    20102040
    2011     /*
    2012      * One less user for the BD we return. The loop above is only for the read
    2013      * head buffers. We do this here then increment again so the case of the
    2014      * buffer in the cache or modified and no read leaves the user counts at
    2015      * the correct level.
    2016      */
    2017     bd->group->users--;
    2018 
    20192041    if (rtems_bdbuf_tracer)
    20202042      rtems_bdbuf_show_users ("read-done", bd);
    20212043  }
    20222044
    2023   /*
    2024    * The data for this block is cached in the buffer.
    2025    */
    2026   if (bd->state == RTEMS_BDBUF_STATE_MODIFIED)
     2045  if (bd->state != RTEMS_BDBUF_STATE_MODIFIED)
     2046    bd->state = RTEMS_BDBUF_STATE_ACCESS;
     2047  else
    20272048    bd->state = RTEMS_BDBUF_STATE_ACCESS_MODIFIED;
    2028   else
    2029   {
    2030     /*
    2031      * The file system is a user of the buffer.
    2032      */
    2033     bd->group->users++;
    2034     bd->state = RTEMS_BDBUF_STATE_ACCESS;
    2035   }
    20362049
    20372050  if (rtems_bdbuf_tracer)
     
    20722085    rtems_chain_append (&bdbuf_cache.lru, &bd->link);
    20732086
    2074     /*
    2075      * One less user for the group of bds.
    2076      */
    2077     bd->group->users--;
     2087    rtems_bdbuf_group_release (bd);
    20782088  }
    20792089 
     
    24122422              bd->error = 0;
    24132423
    2414               /*
    2415                * The buffer is now not modified so lower the user count for the group.
    2416                */
    2417               bd->group->users--;
     2424              rtems_bdbuf_group_release (bd);
    24182425
    24192426              if (rtems_bdbuf_tracer)
Note: See TracChangeset for help on using the changeset viewer.