libblock: Change error status to fatal error

Calling the bdbuf API functions in the not configured state is now a
fatal error.
This commit is contained in:
Sebastian Huber
2012-04-12 10:12:03 +02:00
parent 462ee70f9b
commit 3d60c1b22a
2 changed files with 47 additions and 24 deletions

View File

@@ -470,13 +470,15 @@ rtems_bdbuf_init (void);
* The block number is the linear block number. This is relative to the start * The block number is the linear block number. This is relative to the start
* of the partition on the media. * of the partition on the media.
* *
* Before you can use this function, the rtems_bdbuf_init() routine must be
* called at least once to initialize the cache, otherwise a fatal error will
* occur.
*
* @param dd [in] The disk device. * @param dd [in] The disk device.
* @param block [in] Linear media block number. * @param block [in] Linear media block number.
* @param bd [out] Reference to the buffer descriptor pointer. * @param bd [out] Reference to the buffer descriptor pointer.
* *
* @retval RTEMS_SUCCESSFUL Successful operation. * @retval RTEMS_SUCCESSFUL Successful operation.
* @retval RTEMS_NOT_CONFIGURED Not initialized.
* @retval RTEMS_INVALID_ID No such device.
* @retval RTEMS_INVALID_NUMBER Invalid block size. * @retval RTEMS_INVALID_NUMBER Invalid block size.
*/ */
rtems_status_code rtems_status_code
@@ -501,13 +503,15 @@ rtems_bdbuf_get (
* buffer is returned. The highest priority waiter will obtain the buffer * buffer is returned. The highest priority waiter will obtain the buffer
* first. * first.
* *
* Before you can use this function, the rtems_bdbuf_init() routine must be
* called at least once to initialize the cache, otherwise a fatal error will
* occur.
*
* @param dd [in] The disk device. * @param dd [in] The disk device.
* @param block [in] Linear media block number. * @param block [in] Linear media block number.
* @param bd [out] Reference to the buffer descriptor pointer. * @param bd [out] Reference to the buffer descriptor pointer.
* *
* @retval RTEMS_SUCCESSFUL Successful operation. * @retval RTEMS_SUCCESSFUL Successful operation.
* @retval RTEMS_NOT_CONFIGURED Not initialized.
* @retval RTEMS_INVALID_ID No such device.
* @retval RTEMS_INVALID_NUMBER Invalid block size. * @retval RTEMS_INVALID_NUMBER Invalid block size.
* @retval RTEMS_IO_ERROR IO error. * @retval RTEMS_IO_ERROR IO error.
*/ */
@@ -526,10 +530,15 @@ rtems_bdbuf_read (
* the cache and modified before this call it will be returned to the modified * the cache and modified before this call it will be returned to the modified
* queue. The buffers is returned to the end of the LRU list. * queue. The buffers is returned to the end of the LRU list.
* *
* @param bd [in] Reference to the buffer descriptor. * Before you can use this function, the rtems_bdbuf_init() routine must be
* called at least once to initialize the cache, otherwise a fatal error will
* occur.
*
* @param bd [in] Reference to the buffer descriptor. The buffer descriptor
* reference must not be @c NULL and must be obtained via rtems_bdbuf_get() or
* rtems_bdbuf_read().
* *
* @retval RTEMS_SUCCESSFUL Successful operation. * @retval RTEMS_SUCCESSFUL Successful operation.
* @retval RTEMS_NOT_CONFIGURED Not initialized.
* @retval RTEMS_INVALID_ADDRESS The reference is NULL. * @retval RTEMS_INVALID_ADDRESS The reference is NULL.
*/ */
rtems_status_code rtems_status_code
@@ -545,10 +554,15 @@ rtems_bdbuf_release (rtems_bdbuf_buffer* bd);
* or a sync call has been made. If the buffer is obtained with a get or read * or a sync call has been made. If the buffer is obtained with a get or read
* before the hold timer has expired the buffer will be returned to the user. * before the hold timer has expired the buffer will be returned to the user.
* *
* @param bd [in] Reference to the buffer descriptor. * Before you can use this function, the rtems_bdbuf_init() routine must be
* called at least once to initialize the cache, otherwise a fatal error will
* occur.
*
* @param bd [in] Reference to the buffer descriptor. The buffer descriptor
* reference must not be @c NULL and must be obtained via rtems_bdbuf_get() or
* rtems_bdbuf_read().
* *
* @retval RTEMS_SUCCESSFUL Successful operation. * @retval RTEMS_SUCCESSFUL Successful operation.
* @retval RTEMS_NOT_CONFIGURED Not initialized.
* @retval RTEMS_INVALID_ADDRESS The reference is NULL. * @retval RTEMS_INVALID_ADDRESS The reference is NULL.
*/ */
rtems_status_code rtems_status_code
@@ -562,11 +576,16 @@ rtems_bdbuf_release_modified (rtems_bdbuf_buffer* bd);
* *
* @note This code does not lock the sync mutex and stop additions to the * @note This code does not lock the sync mutex and stop additions to the
* modified queue. * modified queue.
*
* @param bd [in] Reference to the buffer descriptor. * Before you can use this function, the rtems_bdbuf_init() routine must be
* called at least once to initialize the cache, otherwise a fatal error will
* occur.
*
* @param bd [in] Reference to the buffer descriptor. The buffer descriptor
* reference must not be @c NULL and must be obtained via rtems_bdbuf_get() or
* rtems_bdbuf_read().
* *
* @retval RTEMS_SUCCESSFUL Successful operation. * @retval RTEMS_SUCCESSFUL Successful operation.
* @retval RTEMS_NOT_CONFIGURED Not initialized.
* @retval RTEMS_INVALID_ADDRESS The reference is NULL. * @retval RTEMS_INVALID_ADDRESS The reference is NULL.
*/ */
rtems_status_code rtems_status_code
@@ -581,11 +600,13 @@ rtems_bdbuf_sync (rtems_bdbuf_buffer* bd);
* @note Nesting calls to sync multiple devices will be handled sequentially. A * @note Nesting calls to sync multiple devices will be handled sequentially. A
* nested call will be blocked until the first sync request has complete. * nested call will be blocked until the first sync request has complete.
* *
* Before you can use this function, the rtems_bdbuf_init() routine must be
* called at least once to initialize the cache, otherwise a fatal error will
* occur.
*
* @param dd [in] The disk device. * @param dd [in] The disk device.
* *
* @retval RTEMS_SUCCESSFUL Successful operation. * @retval RTEMS_SUCCESSFUL Successful operation.
* @retval RTEMS_NOT_CONFIGURED Not initialized.
* @retval RTEMS_INVALID_ID No such device.
*/ */
rtems_status_code rtems_status_code
rtems_bdbuf_syncdev (const rtems_disk_device *dd); rtems_bdbuf_syncdev (const rtems_disk_device *dd);
@@ -594,6 +615,12 @@ rtems_bdbuf_syncdev (const rtems_disk_device *dd);
* @brief Purges all buffers corresponding to the disk device @a dd. * @brief Purges all buffers corresponding to the disk device @a dd.
* *
* This may result in loss of data. * This may result in loss of data.
*
* Before you can use this function, the rtems_bdbuf_init() routine must be
* called at least once to initialize the cache, otherwise a fatal error will
* occur.
*
* @param dd [in] The disk device.
*/ */
void void
rtems_bdbuf_purge_dev (const rtems_disk_device *dd); rtems_bdbuf_purge_dev (const rtems_disk_device *dd);

View File

@@ -154,10 +154,17 @@ typedef struct rtems_bdbuf_cache
#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_10 RTEMS_BLKDEV_FATAL_ERROR(8) #define RTEMS_BLKDEV_FATAL_BDBUF_STATE_10 RTEMS_BLKDEV_FATAL_ERROR(8)
#define RTEMS_BLKDEV_FATAL_BDBUF_TREE_RM RTEMS_BLKDEV_FATAL_ERROR(9) #define RTEMS_BLKDEV_FATAL_BDBUF_TREE_RM RTEMS_BLKDEV_FATAL_ERROR(9)
#define RTEMS_BLKDEV_FATAL_BDBUF_SWAPOUT RTEMS_BLKDEV_FATAL_ERROR(10) #define RTEMS_BLKDEV_FATAL_BDBUF_SWAPOUT RTEMS_BLKDEV_FATAL_ERROR(10)
/*
* The lock/unlock fatal errors occur in case the bdbuf is not initialized with
* rtems_bdbuf_init(). General system corruption like stack overflow etc. may
* also trigger these fatal errors.
*/
#define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_LOCK RTEMS_BLKDEV_FATAL_ERROR(11) #define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_LOCK RTEMS_BLKDEV_FATAL_ERROR(11)
#define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_UNLOCK RTEMS_BLKDEV_FATAL_ERROR(12) #define RTEMS_BLKDEV_FATAL_BDBUF_SYNC_UNLOCK RTEMS_BLKDEV_FATAL_ERROR(12)
#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_LOCK RTEMS_BLKDEV_FATAL_ERROR(13) #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_LOCK RTEMS_BLKDEV_FATAL_ERROR(13)
#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_UNLOCK RTEMS_BLKDEV_FATAL_ERROR(14) #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_UNLOCK RTEMS_BLKDEV_FATAL_ERROR(14)
#define RTEMS_BLKDEV_FATAL_BDBUF_PREEMPT_DIS RTEMS_BLKDEV_FATAL_ERROR(15) #define RTEMS_BLKDEV_FATAL_BDBUF_PREEMPT_DIS RTEMS_BLKDEV_FATAL_ERROR(15)
#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_2 RTEMS_BLKDEV_FATAL_ERROR(16) #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_2 RTEMS_BLKDEV_FATAL_ERROR(16)
#define RTEMS_BLKDEV_FATAL_BDBUF_PREEMPT_RST RTEMS_BLKDEV_FATAL_ERROR(17) #define RTEMS_BLKDEV_FATAL_BDBUF_PREEMPT_RST RTEMS_BLKDEV_FATAL_ERROR(17)
@@ -1741,9 +1748,6 @@ rtems_bdbuf_obtain_disk (const rtems_disk_device *dd,
rtems_blkdev_bnum *media_block_ptr, rtems_blkdev_bnum *media_block_ptr,
size_t *bds_per_group_ptr) size_t *bds_per_group_ptr)
{ {
if (!bdbuf_cache.initialised)
return RTEMS_NOT_CONFIGURED;
if (media_block_ptr != NULL) if (media_block_ptr != NULL)
{ {
/* /*
@@ -2069,8 +2073,6 @@ rtems_bdbuf_read (const rtems_disk_device *dd,
static rtems_status_code static rtems_status_code
rtems_bdbuf_check_bd_and_lock_cache (rtems_bdbuf_buffer *bd, const char *kind) rtems_bdbuf_check_bd_and_lock_cache (rtems_bdbuf_buffer *bd, const char *kind)
{ {
if (!bdbuf_cache.initialised)
return RTEMS_NOT_CONFIGURED;
if (bd == NULL) if (bd == NULL)
return RTEMS_INVALID_ADDRESS; return RTEMS_INVALID_ADDRESS;
if (rtems_bdbuf_tracer) if (rtems_bdbuf_tracer)
@@ -2184,15 +2186,9 @@ rtems_bdbuf_sync (rtems_bdbuf_buffer *bd)
rtems_status_code rtems_status_code
rtems_bdbuf_syncdev (const rtems_disk_device *dd) rtems_bdbuf_syncdev (const rtems_disk_device *dd)
{ {
rtems_status_code sc = RTEMS_SUCCESSFUL;
if (rtems_bdbuf_tracer) if (rtems_bdbuf_tracer)
printf ("bdbuf:syncdev: %08x\n", (unsigned) dd->dev); printf ("bdbuf:syncdev: %08x\n", (unsigned) dd->dev);
sc = rtems_bdbuf_obtain_disk (dd, 0, NULL, NULL);
if (sc != RTEMS_SUCCESSFUL)
return sc;
/* /*
* Take the sync lock before locking the cache. Once we have the sync lock we * Take the sync lock before locking the cache. Once we have the sync lock we
* can lock the cache. If another thread has the sync lock it will cause this * can lock the cache. If another thread has the sync lock it will cause this