libblock: Move rtems_bdbuf_get_media_block() call

Move rtems_bdbuf_get_media_block() call inside the bdbuf lock.
This commit is contained in:
Sebastian Huber
2012-05-30 13:41:31 +02:00
parent 73c09b3b8e
commit f164ae751a

View File

@@ -1780,14 +1780,13 @@ rtems_bdbuf_get (rtems_disk_device *dd,
{ {
rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_status_code sc = RTEMS_SUCCESSFUL;
rtems_bdbuf_buffer *bd = NULL; rtems_bdbuf_buffer *bd = NULL;
rtems_blkdev_bnum media_block = 0; rtems_blkdev_bnum media_block;
sc = rtems_bdbuf_get_media_block (dd, block, &media_block);
if (sc != RTEMS_SUCCESSFUL)
return sc;
rtems_bdbuf_lock_cache (); rtems_bdbuf_lock_cache ();
sc = rtems_bdbuf_get_media_block (dd, block, &media_block);
if (sc == RTEMS_SUCCESSFUL)
{
/* /*
* Print the block index relative to the physical disk. * Print the block index relative to the physical disk.
*/ */
@@ -1808,10 +1807,10 @@ rtems_bdbuf_get (rtems_disk_device *dd,
case RTEMS_BDBUF_STATE_MODIFIED: case RTEMS_BDBUF_STATE_MODIFIED:
/* /*
* To get a modified buffer could be considered a bug in the caller * 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 * because you should not be getting an already modified buffer but
* may have modified a byte in a block then decided to seek the start and * user may have modified a byte in a block then decided to seek the
* write the whole block and the file system will have no record of this * start and write the whole block and the file system will have no
* so just gets the block to fill. * record of this so just gets the block to fill.
*/ */
rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_MODIFIED); rtems_bdbuf_set_state (bd, RTEMS_BDBUF_STATE_ACCESS_MODIFIED);
break; break;
@@ -1825,12 +1824,13 @@ rtems_bdbuf_get (rtems_disk_device *dd,
rtems_bdbuf_show_users ("get", bd); rtems_bdbuf_show_users ("get", bd);
rtems_bdbuf_show_usage (); rtems_bdbuf_show_usage ();
} }
}
rtems_bdbuf_unlock_cache (); rtems_bdbuf_unlock_cache ();
*bd_ptr = bd; *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_status_code sc = RTEMS_SUCCESSFUL;
rtems_blkdev_request *req = NULL; rtems_blkdev_request *req = NULL;
rtems_bdbuf_buffer *bd = NULL; rtems_bdbuf_buffer *bd = NULL;
rtems_blkdev_bnum media_block = 0; rtems_blkdev_bnum media_block;
sc = rtems_bdbuf_get_media_block (dd, block, &media_block);
if (sc != RTEMS_SUCCESSFUL)
return sc;
/* /*
* TODO: This type of request structure is wrong and should be removed. * TODO: This type of request structure is wrong and should be removed.
@@ -2012,11 +2008,15 @@ rtems_bdbuf_read (rtems_disk_device *dd,
sizeof (rtems_blkdev_sg_buffer) * sizeof (rtems_blkdev_sg_buffer) *
(bdbuf_config.max_read_ahead_blocks + 1)); (bdbuf_config.max_read_ahead_blocks + 1));
rtems_bdbuf_lock_cache ();
sc = rtems_bdbuf_get_media_block (dd, block, &media_block);
if (sc == RTEMS_SUCCESSFUL)
{
if (rtems_bdbuf_tracer) if (rtems_bdbuf_tracer)
printf ("bdbuf:read: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n", printf ("bdbuf:read: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
media_block + dd->start, block, (unsigned) dd->dev); media_block + dd->start, block, (unsigned) dd->dev);
rtems_bdbuf_lock_cache ();
rtems_bdbuf_create_read_request (dd, media_block, req, &bd); rtems_bdbuf_create_read_request (dd, media_block, req, &bd);
if (req->bufnum > 0) if (req->bufnum > 0)
@@ -2049,14 +2049,17 @@ rtems_bdbuf_read (rtems_disk_device *dd,
rtems_bdbuf_show_users ("read", bd); rtems_bdbuf_show_users ("read", bd);
rtems_bdbuf_show_usage (); rtems_bdbuf_show_usage ();
} }
*bd_ptr = bd;
} }
else else
*bd_ptr = NULL; {
bd = NULL;
}
}
rtems_bdbuf_unlock_cache (); rtems_bdbuf_unlock_cache ();
*bd_ptr = bd;
return sc; return sc;
} }