[rtems commit] libblock: Move rtems_bdbuf_get_media_block() call

Sebastian Huber sebh at rtems.org
Thu May 31 09:03:03 UTC 2012


Module:    rtems
Branch:    master
Commit:    f164ae751af2ac0a67afcf154fee9da38c071d62
Changeset: http://git.rtems.org/rtems/commit/?id=f164ae751af2ac0a67afcf154fee9da38c071d62

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed May 30 13:41:31 2012 +0200

libblock: Move rtems_bdbuf_get_media_block() call

Move rtems_bdbuf_get_media_block() call inside the bdbuf lock.

---

 cpukit/libblock/src/bdbuf.c |  153 ++++++++++++++++++++++---------------------
 1 files changed, 78 insertions(+), 75 deletions(-)

diff --git a/cpukit/libblock/src/bdbuf.c b/cpukit/libblock/src/bdbuf.c
index c0744c6..82c442f 100644
--- a/cpukit/libblock/src/bdbuf.c
+++ b/cpukit/libblock/src/bdbuf.c
@@ -1780,57 +1780,57 @@ rtems_bdbuf_get (rtems_disk_device   *dd,
 {
   rtems_status_code   sc = RTEMS_SUCCESSFUL;
   rtems_bdbuf_buffer *bd = NULL;
-  rtems_blkdev_bnum   media_block = 0;
-
-  sc = rtems_bdbuf_get_media_block (dd, block, &media_block);
-  if (sc != RTEMS_SUCCESSFUL)
-    return sc;
+  rtems_blkdev_bnum   media_block;
 
   rtems_bdbuf_lock_cache ();
 
-  /*
-   * Print the block index relative to the physical disk.
-   */
-  if (rtems_bdbuf_tracer)
-    printf ("bdbuf:get: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
-            media_block, block, (unsigned) dd->dev);
+  sc = rtems_bdbuf_get_media_block (dd, block, &media_block);
+  if (sc == RTEMS_SUCCESSFUL)
+  {
+    /*
+     * Print the block index relative to the physical disk.
+     */
+    if (rtems_bdbuf_tracer)
+      printf ("bdbuf:get: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
+              media_block, block, (unsigned) dd->dev);
 
-  bd = rtems_bdbuf_get_buffer_for_access (dd, media_block);
+    bd = rtems_bdbuf_get_buffer_for_access (dd, media_block);
 
-  switch (bd->state)
-  {
-    case RTEMS_BDBUF_STATE_CACHED:
-      rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_CACHED);
-      break;
-    case RTEMS_BDBUF_STATE_EMPTY:
-      rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_EMPTY);
-      break;
-    case RTEMS_BDBUF_STATE_MODIFIED:
-      /*
-       * To get a modified buffer could be considered a bug in the caller
-       * because you should not be getting an already modified buffer but user
-       * may have modified a byte in a block then decided to seek the start and
-       * write the whole block and the file system will have no record of this
-       * so just gets the block to fill.
-       */
-      rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_MODIFIED);
-      break;
-    default:
-      rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_2);
-      break;
-  }
+    switch (bd->state)
+    {
+      case RTEMS_BDBUF_STATE_CACHED:
+        rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_CACHED);
+        break;
+      case RTEMS_BDBUF_STATE_EMPTY:
+        rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_EMPTY);
+        break;
+      case RTEMS_BDBUF_STATE_MODIFIED:
+        /*
+         * To get a modified buffer could be considered a bug in the caller
+         * because you should not be getting an already modified buffer but
+         * user may have modified a byte in a block then decided to seek the
+         * start and write the whole block and the file system will have no
+         * record of this so just gets the block to fill.
+         */
+        rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_MODIFIED);
+        break;
+      default:
+        rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_2);
+        break;
+    }
 
-  if (rtems_bdbuf_tracer)
-  {
-    rtems_bdbuf_show_users ("get", bd);
-    rtems_bdbuf_show_usage ();
+    if (rtems_bdbuf_tracer)
+    {
+      rtems_bdbuf_show_users ("get", bd);
+      rtems_bdbuf_show_usage ();
+    }
   }
 
   rtems_bdbuf_unlock_cache ();
 
   *bd_ptr = bd;
 
-  return RTEMS_SUCCESSFUL;
+  return sc;
 }
 
 /**
@@ -1997,11 +1997,7 @@ rtems_bdbuf_read (rtems_disk_device   *dd,
   rtems_status_code     sc = RTEMS_SUCCESSFUL;
   rtems_blkdev_request *req = NULL;
   rtems_bdbuf_buffer   *bd = NULL;
-  rtems_blkdev_bnum     media_block = 0;
-
-  sc = rtems_bdbuf_get_media_block (dd, block, &media_block);
-  if (sc != RTEMS_SUCCESSFUL)
-    return sc;
+  rtems_blkdev_bnum     media_block;
 
   /*
    * TODO: This type of request structure is wrong and should be removed.
@@ -2012,51 +2008,58 @@ rtems_bdbuf_read (rtems_disk_device   *dd,
                      sizeof (rtems_blkdev_sg_buffer) *
                       (bdbuf_config.max_read_ahead_blocks + 1));
 
-  if (rtems_bdbuf_tracer)
-    printf ("bdbuf:read: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
-            media_block + dd->start, block, (unsigned) dd->dev);
-
   rtems_bdbuf_lock_cache ();
-  rtems_bdbuf_create_read_request (dd, media_block, req, &bd);
 
-  if (req->bufnum > 0)
+  sc = rtems_bdbuf_get_media_block (dd, block, &media_block);
+  if (sc == RTEMS_SUCCESSFUL)
   {
-    sc = rtems_bdbuf_execute_transfer_request (dd, req, true);
-    if (sc == RTEMS_SUCCESSFUL)
+    if (rtems_bdbuf_tracer)
+      printf ("bdbuf:read: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
+              media_block + dd->start, block, (unsigned) dd->dev);
+
+    rtems_bdbuf_create_read_request (dd, media_block, req, &bd);
+
+    if (req->bufnum > 0)
     {
-      rtems_chain_extract_unprotected (&bd->link);
-      rtems_bdbuf_group_obtain (bd);
+      sc = rtems_bdbuf_execute_transfer_request (dd, req, true);
+      if (sc == RTEMS_SUCCESSFUL)
+      {
+        rtems_chain_extract_unprotected (&bd->link);
+        rtems_bdbuf_group_obtain (bd);
+      }
     }
-  }
 
-  if (sc == RTEMS_SUCCESSFUL)
-  {
-    switch (bd->state)
+    if (sc == RTEMS_SUCCESSFUL)
     {
-      case RTEMS_BDBUF_STATE_CACHED:
-        rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_CACHED);
-        break;
-      case RTEMS_BDBUF_STATE_MODIFIED:
-        rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_MODIFIED);
-        break;
-      default:
-        rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_4);
-        break;
-    }
+      switch (bd->state)
+      {
+        case RTEMS_BDBUF_STATE_CACHED:
+          rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_CACHED);
+          break;
+        case RTEMS_BDBUF_STATE_MODIFIED:
+          rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_MODIFIED);
+          break;
+        default:
+          rtems_bdbuf_fatal (bd->state, RTEMS_BLKDEV_FATAL_BDBUF_STATE_4);
+          break;
+      }
 
-    if (rtems_bdbuf_tracer)
+      if (rtems_bdbuf_tracer)
+      {
+        rtems_bdbuf_show_users ("read", bd);
+        rtems_bdbuf_show_usage ();
+      }
+    }
+    else
     {
-      rtems_bdbuf_show_users ("read", bd);
-      rtems_bdbuf_show_usage ();
+      bd = NULL;
     }
-
-    *bd_ptr = bd;
   }
-  else
-    *bd_ptr = NULL;
 
   rtems_bdbuf_unlock_cache ();
 
+  *bd_ptr = bd;
+
   return sc;
 }
 




More information about the vc mailing list