source: rtems/cpukit/include/rtems/bdbuf.h @ e97806a

5
Last change on this file since e97806a was 8d7f3680, checked in by Sebastian Huber <sebastian.huber@…>, on 11/18/17 at 16:19:13

libblock: Use self-contained mutex and cond var

Update #2843.

  • Property mode set to 100644
File size: 26.0 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_bdbuf
5 * @brief Block Device Buffer Management
6 */
7
8/*
9 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
10 * Author: Victor V. Vengerov <vvv@oktet.ru>
11 *
12 * Copyright (C) 2008,2009 Chris Johns <chrisj@rtems.org>
13 *    Rewritten to remove score mutex access. Fixes many performance
14 *    issues.
15 *    Change to support demand driven variable buffer sizes.
16 *
17 * Copyright (c) 2009-2012 embedded brains GmbH.
18 */
19
20#ifndef _RTEMS_BDBUF_H
21#define _RTEMS_BDBUF_H
22
23#include <rtems.h>
24#include <rtems/libio.h>
25#include <rtems/chain.h>
26
27#include <rtems/blkdev.h>
28#include <rtems/diskdevs.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/**
35 * @defgroup rtems_libblock Block Device Library
36 *
37 * Block device modules.
38 */
39
40/**
41 * @defgroup rtems_bdbuf Block Device Buffer Management
42 *
43 * @ingroup rtems_libblock
44 *
45 * The Block Device Buffer Management implements a cache between the disk
46 * devices and file systems.  The code provides read-ahead and write queuing to
47 * the drivers and fast cache look-up using an AVL tree.
48 *
49 * The block size used by a file system can be set at runtime and must be a
50 * multiple of the disk device block size.  The disk device's physical block
51 * size is called the media block size.  The file system can set the block size
52 * it uses to a larger multiple of the media block size.  The driver must be
53 * able to handle buffers sizes larger than one media block.
54 *
55 * The user configures the amount of memory to be used as buffers in the cache,
56 * and the minimum and maximum buffer size.  The cache will allocate additional
57 * memory for the buffer descriptors and groups.  There are enough buffer
58 * descriptors allocated so all the buffer memory can be used as minimum sized
59 * buffers.
60 *
61 * The cache is a single pool of buffers.  The buffer memory is divided into
62 * groups where the size of buffer memory allocated to a group is the maximum
63 * buffer size.  A group's memory can be divided down into small buffer sizes
64 * that are a multiple of 2 of the minimum buffer size.  A group is the minimum
65 * allocation unit for buffers of a specific size.  If a buffer of maximum size
66 * is request the group will have a single buffer.  If a buffer of minimum size
67 * is requested the group is divided into minimum sized buffers and the
68 * remaining buffers are held ready for use.  A group keeps track of which
69 * buffers are with a file system or driver and groups who have buffer in use
70 * cannot be realloced.  Groups with no buffers in use can be taken and
71 * realloced to a new size.  This is how buffers of different sizes move around
72 * the cache.
73
74 * The buffers are held in various lists in the cache.  All buffers follow this
75 * state machine:
76 *
77 * @dot
78 * digraph state {
79 *   size="16,8";
80 *   f [label="FREE",style="filled",fillcolor="aquamarine"];
81 *   e [label="EMPTY",style="filled",fillcolor="seagreen"];
82 *   c [label="CACHED",style="filled",fillcolor="chartreuse"];
83 *   ac [label="ACCESS CACHED",style="filled",fillcolor="royalblue"];
84 *   am [label="ACCESS MODIFIED",style="filled",fillcolor="royalblue"];
85 *   ae [label="ACCESS EMPTY",style="filled",fillcolor="royalblue"];
86 *   ap [label="ACCESS PURGED",style="filled",fillcolor="royalblue"];
87 *   t [label="TRANSFER",style="filled",fillcolor="red"];
88 *   tp [label="TRANSFER PURGED",style="filled",fillcolor="red"];
89 *   s [label="SYNC",style="filled",fillcolor="red"];
90 *   m [label="MODIFIED",style="filled",fillcolor="gold"];
91 *   i [label="INITIAL"];
92 *
93 *   legend_transfer [label="Transfer Wake-Up",fontcolor="red",shape="none"];
94 *   legend_access [label="Access Wake-Up",fontcolor="royalblue",shape="none"];
95 *
96 *   i -> f [label="Init"];
97 *   f -> e [label="Buffer Recycle"];
98 *   e -> ae [label="Get"];
99 *   e -> t [label="Read"];
100 *   e -> f [label="Nobody Waits"];
101 *   c -> ac [label="Get\nRead"];
102 *   c -> e [label="Buffer Recycle\nPurge"];
103 *   c -> f [label="Reallocate\nBlock Size Changed"];
104 *   t -> c [label="Transfer Done",color="red",fontcolor="red"];
105 *   t -> e [label="Transfer Error",color="red",fontcolor="red"];
106 *   t -> tp [label="Purge"];
107 *   tp -> e [label="Transfer Done\nTransfer Error",color="red",fontcolor="red"];
108 *   m -> t [label="Swapout"];
109 *   m -> s [label="Block Size Changed"];
110 *   m -> am [label="Get\nRead"];
111 *   m -> e [label="Purge"];
112 *   ac -> m [label="Release Modified",color="royalblue",fontcolor="royalblue"];
113 *   ac -> s [label="Sync",color="royalblue",fontcolor="royalblue"];
114 *   ac -> c [label="Release",color="royalblue",fontcolor="royalblue"];
115 *   ac -> ap [label="Purge"];
116 *   am -> m [label="Release\nRelease Modified",color="royalblue",fontcolor="royalblue"];
117 *   am -> s [label="Sync",color="royalblue",fontcolor="royalblue"];
118 *   am -> ap [label="Purge"];
119 *   ae -> m [label="Release Modified",color="royalblue",fontcolor="royalblue"];
120 *   ae -> s [label="Sync",color="royalblue",fontcolor="royalblue"];
121 *   ae -> e [label="Release",color="royalblue",fontcolor="royalblue"];
122 *   ae -> ap [label="Purge"];
123 *   ap -> e [label="Release\nRelease Modified\nSync",color="royalblue",fontcolor="royalblue"];
124 *   s -> t [label="Swapout"];
125 *   s -> e [label="Purge",color="red",fontcolor="red"];
126 * }
127 * @enddot
128 *
129 * Empty or cached buffers are added to the LRU list and removed from this
130 * queue when a caller requests a buffer.  This is referred to as getting a
131 * buffer in the code and the event get in the state diagram.  The buffer is
132 * assigned to a block and inserted to the AVL based on the block/device key.
133 * If the block is to be read by the user and not in the cache it is transfered
134 * from the disk into memory.  If no buffers are on the LRU list the modified
135 * list is checked.  If buffers are on the modified the swap out task will be
136 * woken.  The request blocks until a buffer is available for recycle.
137 *
138 * A block being accessed is given to the file system layer and not accessible
139 * to another requester until released back to the cache.  The same goes to a
140 * buffer in the transfer state.  The transfer state means being read or
141 * written.  If the file system has modified the block and releases it as
142 * modified it placed on the cache's modified list and a hold timer
143 * initialised.  The buffer is held for the hold time before being written to
144 * disk.  Buffers are held for a configurable period of time on the modified
145 * list as a write sets the state to transfer and this locks the buffer out
146 * from the file system until the write completes.  Buffers are often accessed
147 * and modified in a series of small updates so if sent to the disk when
148 * released as modified the user would have to block waiting until it had been
149 * written.  This would be a performance problem.
150 *
151 * The code performs multiple block reads and writes.  Multiple block reads or
152 * read-ahead increases performance with hardware that supports it.  It also
153 * helps with a large cache as the disk head movement is reduced.  It however
154 * is a speculative operation so excessive use can remove valuable and needed
155 * blocks from the cache.  The read-ahead is triggered after two misses of
156 * ascending consecutive blocks or a read hit of a block read by the
157 * most-resent read-ahead transfer.  The read-ahead works per disk, but all
158 * transfers are issued by the read-ahead task.
159 *
160 * The cache has the following lists of buffers:
161 *  - LRU: Accessed or transfered buffers released in least recently used
162 *  order.  Empty buffers will be placed to the front.
163 *  - Modified: Buffers waiting to be written to disk.
164 *  - Sync: Buffers to be synchronized with the disk.
165 *
166 * A cache look-up will be performed to find a suitable buffer.  A suitable
167 * buffer is one that matches the same allocation size as the device the buffer
168 * is for.  The a buffer's group has no buffers in use with the file system or
169 * driver the group is reallocated.  This means the buffers in the group are
170 * invalidated, resized and placed on the LRU queue.  There is a performance
171 * issue with this design.  The reallocation of a group may forced recently
172 * accessed buffers out of the cache when they should not.  The design should be
173 * change to have groups on a LRU list if they have no buffers in use.
174 */
175/**@{**/
176
177/**
178 * @brief State of a buffer of the cache.
179 *
180 * The state has several implications.  Depending on the state a buffer can be
181 * in the AVL tree, in a list, in use by an entity and a group user or not.
182 *
183 * <table>
184 *   <tr>
185 *     <th>State</th><th>Valid Data</th><th>AVL Tree</th>
186 *     <th>LRU List</th><th>Modified List</th><th>Synchronization List</th>
187 *     <th>Group User</th><th>External User</th>
188 *   </tr>
189 *   <tr>
190 *     <td>FREE</td><td></td><td></td>
191 *     <td>X</td><td></td><td></td><td></td><td></td>
192 *   </tr>
193 *   <tr>
194 *     <td>EMPTY</td><td></td><td>X</td>
195 *     <td></td><td></td><td></td><td></td><td></td>
196 *   </tr>
197 *   <tr>
198 *     <td>CACHED</td><td>X</td><td>X</td>
199 *     <td>X</td><td></td><td></td><td></td><td></td>
200 *   </tr>
201 *   <tr>
202 *     <td>ACCESS CACHED</td><td>X</td><td>X</td>
203 *     <td></td><td></td><td></td><td>X</td><td>X</td>
204 *   </tr>
205 *   <tr>
206 *     <td>ACCESS MODIFIED</td><td>X</td><td>X</td>
207 *     <td></td><td></td><td></td><td>X</td><td>X</td>
208 *   </tr>
209 *   <tr>
210 *     <td>ACCESS EMPTY</td><td></td><td>X</td>
211 *     <td></td><td></td><td></td><td>X</td><td>X</td>
212 *   </tr>
213 *   <tr>
214 *     <td>ACCESS PURGED</td><td></td><td>X</td>
215 *     <td></td><td></td><td></td><td>X</td><td>X</td>
216 *   </tr>
217 *   <tr>
218 *     <td>MODIFIED</td><td>X</td><td>X</td>
219 *     <td></td><td>X</td><td></td><td>X</td><td></td>
220 *   </tr>
221 *   <tr>
222 *     <td>SYNC</td><td>X</td><td>X</td>
223 *     <td></td><td></td><td>X</td><td>X</td><td></td>
224 *   </tr>
225 *   <tr>
226 *     <td>TRANSFER</td><td>X</td><td>X</td>
227 *     <td></td><td></td><td></td><td>X</td><td>X</td>
228 *   </tr>
229 *   <tr>
230 *     <td>TRANSFER PURGED</td><td></td><td>X</td>
231 *     <td></td><td></td><td></td><td>X</td><td>X</td>
232 *   </tr>
233 * </table>
234 */
235typedef enum
236{
237  /**
238   * @brief Free.
239   */
240  RTEMS_BDBUF_STATE_FREE = 0,
241
242  /**
243   * @brief Empty.
244   */
245  RTEMS_BDBUF_STATE_EMPTY,
246
247  /**
248   * @brief Cached.
249   */
250  RTEMS_BDBUF_STATE_CACHED,
251
252  /**
253   * @brief Accessed by upper layer with cached data.
254   */
255  RTEMS_BDBUF_STATE_ACCESS_CACHED,
256
257  /**
258   * @brief Accessed by upper layer with modified data.
259   */
260  RTEMS_BDBUF_STATE_ACCESS_MODIFIED,
261
262  /**
263   * @brief Accessed by upper layer with invalid data.
264   */
265  RTEMS_BDBUF_STATE_ACCESS_EMPTY,
266
267  /**
268   * @brief Accessed by upper layer with purged data.
269   */
270  RTEMS_BDBUF_STATE_ACCESS_PURGED,
271
272  /**
273   * @brief Modified by upper layer.
274   */
275  RTEMS_BDBUF_STATE_MODIFIED,
276
277  /**
278   * @brief Scheduled for synchronization.
279   */
280  RTEMS_BDBUF_STATE_SYNC,
281
282  /**
283   * @brief In transfer by block device driver.
284   */
285  RTEMS_BDBUF_STATE_TRANSFER,
286
287  /**
288   * @brief In transfer by block device driver and purged.
289   */
290  RTEMS_BDBUF_STATE_TRANSFER_PURGED
291} rtems_bdbuf_buf_state;
292
293/**
294 * Forward reference to the block.
295 */
296struct rtems_bdbuf_group;
297typedef struct rtems_bdbuf_group rtems_bdbuf_group;
298
299/**
300 * To manage buffers we using buffer descriptors (BD). A BD holds a buffer plus
301 * a range of other information related to managing the buffer in the cache. To
302 * speed-up buffer lookup descriptors are organized in AVL-Tree. The fields
303 * 'dd' and 'block' are search keys.
304 */
305typedef struct rtems_bdbuf_buffer
306{
307  rtems_chain_node link;       /**< Link the BD onto a number of lists. */
308
309  struct rtems_bdbuf_avl_node
310  {
311    struct rtems_bdbuf_buffer* left;   /**< Left Child */
312    struct rtems_bdbuf_buffer* right;  /**< Right Child */
313    signed char                cache;  /**< Cache */
314    signed char                bal;    /**< The balance of the sub-tree */
315  } avl;
316
317  rtems_disk_device *dd;        /**< disk device */
318
319  rtems_blkdev_bnum block;      /**< block number on the device */
320
321  unsigned char*    buffer;     /**< Pointer to the buffer memory area */
322
323  rtems_bdbuf_buf_state state;           /**< State of the buffer. */
324
325  uint32_t waiters;              /**< The number of threads waiting on this
326                                  * buffer. */
327  rtems_bdbuf_group* group;      /**< Pointer to the group of BDs this BD is
328                                  * part of. */
329  uint32_t hold_timer;           /**< Timer to indicate how long a buffer
330                                  * has been held in the cache modified. */
331
332  int   references;              /**< Allow reference counting by owner. */
333  void* user;                    /**< User data. */
334} rtems_bdbuf_buffer;
335
336/**
337 * A group is a continuous block of buffer descriptors. A group covers the
338 * maximum configured buffer size and is the allocation size for the buffers to
339 * a specific buffer size. If you allocate a buffer to be a specific size, all
340 * buffers in the group, if there are more than 1 will also be that size. The
341 * number of buffers in a group is a multiple of 2, ie 1, 2, 4, 8, etc.
342 */
343struct rtems_bdbuf_group
344{
345  rtems_chain_node    link;          /**< Link the groups on a LRU list if they
346                                      * have no buffers in use. */
347  size_t              bds_per_group; /**< The number of BD allocated to this
348                                      * group. This value must be a multiple of
349                                      * 2. */
350  uint32_t            users;         /**< How many users the block has. */
351  rtems_bdbuf_buffer* bdbuf;         /**< First BD this block covers. */
352};
353
354/**
355 * Buffering configuration definition. See confdefs.h for support on using this
356 * structure.
357 */
358typedef struct rtems_bdbuf_config {
359  uint32_t            max_read_ahead_blocks;   /**< Number of blocks to read
360                                                * ahead. */
361  uint32_t            max_write_blocks;        /**< Number of blocks to write
362                                                * at once. */
363  rtems_task_priority swapout_priority;        /**< Priority of the swap out
364                                                * task. */
365  uint32_t            swapout_period;          /**< Period swap-out checks buf
366                                                * timers. */
367  uint32_t            swap_block_hold;         /**< Period a buffer is held. */
368  size_t              swapout_workers;         /**< The number of worker
369                                                * threads for the swap-out
370                                                * task. */
371  rtems_task_priority swapout_worker_priority; /**< Priority of the swap out
372                                                * task. */
373  size_t              task_stack_size;         /**< Task stack size for swap-out
374                                                * task and worker threads. */
375  size_t              size;                    /**< Size of memory in the
376                                                * cache */
377  uint32_t            buffer_min;              /**< Minimum buffer size. */
378  uint32_t            buffer_max;              /**< Maximum buffer size
379                                                * supported. It is also the
380                                                * allocation size. */
381  rtems_task_priority read_ahead_priority;     /**< Priority of the read-ahead
382                                                * task. */
383} rtems_bdbuf_config;
384
385/**
386 * External reference to the configuration.
387 *
388 * The configuration is provided by the application.
389 */
390extern const rtems_bdbuf_config rtems_bdbuf_configuration;
391
392/**
393 * The default value for the maximum read-ahead blocks disables the read-ahead
394 * feature.
395 */
396#define RTEMS_BDBUF_MAX_READ_AHEAD_BLOCKS_DEFAULT    0
397
398/**
399 * Default maximum number of blocks to write at once.
400 */
401#define RTEMS_BDBUF_MAX_WRITE_BLOCKS_DEFAULT         16
402
403/**
404 * Default swap-out task priority.
405 */
406#define RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT    15
407
408/**
409 * Default swap-out task swap period in milli seconds.
410 */
411#define RTEMS_BDBUF_SWAPOUT_TASK_SWAP_PERIOD_DEFAULT 250
412
413/**
414 * Default swap-out task block hold time in milli seconds.
415 */
416#define RTEMS_BDBUF_SWAPOUT_TASK_BLOCK_HOLD_DEFAULT  1000
417
418/**
419 * Default swap-out worker tasks. Currently disabled.
420 */
421#define RTEMS_BDBUF_SWAPOUT_WORKER_TASKS_DEFAULT     0
422
423/**
424 * Default swap-out worker task priority. The same as the swap-out task.
425 */
426#define RTEMS_BDBUF_SWAPOUT_WORKER_TASK_PRIORITY_DEFAULT \
427                             RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
428
429/**
430 * Default read-ahead task priority.  The same as the swap-out task.
431 */
432#define RTEMS_BDBUF_READ_AHEAD_TASK_PRIORITY_DEFAULT \
433  RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
434
435/**
436 * Default task stack size for swap-out and worker tasks.
437 */
438#define RTEMS_BDBUF_TASK_STACK_SIZE_DEFAULT RTEMS_MINIMUM_STACK_SIZE
439
440/**
441 * Default size of memory allocated to the cache.
442 */
443#define RTEMS_BDBUF_CACHE_MEMORY_SIZE_DEFAULT (64 * 512)
444
445/**
446 * Default minimum size of buffers.
447 */
448#define RTEMS_BDBUF_BUFFER_MIN_SIZE_DEFAULT (512)
449
450/**
451 * Default maximum size of buffers.
452 */
453#define RTEMS_BDBUF_BUFFER_MAX_SIZE_DEFAULT (4096)
454
455/**
456 * Prepare buffering layer to work - initialize buffer descritors and (if it is
457 * neccessary) buffers. After initialization all blocks is placed into the
458 * ready state.
459 *
460 * @retval RTEMS_SUCCESSFUL Successful operation.
461 * @retval RTEMS_CALLED_FROM_ISR Called from an interrupt context.
462 * @retval RTEMS_INVALID_NUMBER The buffer maximum is not an integral multiple
463 * of the buffer minimum.  The maximum read-ahead blocks count is too large.
464 * @retval RTEMS_RESOURCE_IN_USE Already initialized.
465 * @retval RTEMS_UNSATISFIED Not enough resources.
466 */
467rtems_status_code
468rtems_bdbuf_init (void);
469
470/**
471 * Get block buffer for data to be written into. The buffers is set to the
472 * access or modified access state. If the buffer is in the cache and modified
473 * the state is access modified else the state is access. This buffer contents
474 * are not initialised if the buffer is not already in the cache. If the block
475 * is already resident in memory it is returned how-ever if not in memory the
476 * buffer is not read from disk. This call is used when writing the whole block
477 * on a disk rather than just changing a part of it. If there is no buffers
478 * available this call will block. A buffer obtained with this call will not be
479 * involved in a transfer request and will not be returned to another user
480 * until released. If the buffer is already with a user when this call is made
481 * the call is blocked until the buffer is returned. The highest priority
482 * waiter will obtain the buffer first.
483 *
484 * The block number is the linear block number. This is relative to the start
485 * of the partition on the media.
486 *
487 * Before you can use this function, the rtems_bdbuf_init() routine must be
488 * called at least once to initialize the cache, otherwise a fatal error will
489 * occur.
490 *
491 * @param dd [in] The disk device.
492 * @param block [in] Linear media block number.
493 * @param bd [out] Reference to the buffer descriptor pointer.
494 *
495 * @retval RTEMS_SUCCESSFUL Successful operation.
496 * @retval RTEMS_INVALID_ID Invalid block number.
497 */
498rtems_status_code
499rtems_bdbuf_get (
500  rtems_disk_device *dd,
501  rtems_blkdev_bnum block,
502  rtems_bdbuf_buffer** bd
503);
504
505/**
506 * Get the block buffer and if not already in the cache read from the disk. If
507 * specified block already cached return. The buffer is set to the access or
508 * modified access state. If the buffer is in the cache and modified the state
509 * is access modified else the state is access. If block is already being read
510 * from disk for being written to disk this call blocks. If the buffer is
511 * waiting to be written it is removed from modified queue and returned to the
512 * user. If the buffer is not in the cache a new buffer is obtained and the
513 * data read from disk. The call may block until these operations complete. A
514 * buffer obtained with this call will not be involved in a transfer request
515 * and will not be returned to another user until released. If the buffer is
516 * already with a user when this call is made the call is blocked until the
517 * buffer is returned. The highest priority waiter will obtain the buffer
518 * first.
519 *
520 * Before you can use this function, the rtems_bdbuf_init() routine must be
521 * called at least once to initialize the cache, otherwise a fatal error will
522 * occur.
523 *
524 * @param dd [in] The disk device.
525 * @param block [in] Linear media block number.
526 * @param bd [out] Reference to the buffer descriptor pointer.
527 *
528 * @retval RTEMS_SUCCESSFUL Successful operation.
529 * @retval RTEMS_INVALID_ID Invalid block number.
530 * @retval RTEMS_IO_ERROR IO error.
531 */
532rtems_status_code
533rtems_bdbuf_read (
534  rtems_disk_device *dd,
535  rtems_blkdev_bnum block,
536  rtems_bdbuf_buffer** bd
537);
538
539/**
540 * Release the buffer obtained by a read call back to the cache. If the buffer
541 * was obtained by a get call and was not already in the cache the release
542 * modified call should be used. A buffer released with this call obtained by a
543 * get call may not be in sync with the contents on disk. If the buffer was in
544 * the cache and modified before this call it will be returned to the modified
545 * queue. The buffers is returned to the end of the LRU list.
546 *
547 * Before you can use this function, the rtems_bdbuf_init() routine must be
548 * called at least once to initialize the cache, otherwise a fatal error will
549 * occur.
550 *
551 * @param bd [in] Reference to the buffer descriptor.  The buffer descriptor
552 * reference must not be @c NULL and must be obtained via rtems_bdbuf_get() or
553 * rtems_bdbuf_read().
554 *
555 * @retval RTEMS_SUCCESSFUL Successful operation.
556 * @retval RTEMS_INVALID_ADDRESS The reference is NULL.
557 */
558rtems_status_code
559rtems_bdbuf_release (rtems_bdbuf_buffer* bd);
560
561/**
562 * Release the buffer allocated with a get or read call placing it on the
563 * modified list.  If the buffer was not released modified before the hold
564 * timer is set to the configuration value. If the buffer had been released
565 * modified before but not written to disk the hold timer is not updated. The
566 * buffer will be written to disk when the hold timer has expired, there are
567 * not more buffers available in the cache and a get or read buffer needs one
568 * or a sync call has been made. If the buffer is obtained with a get or read
569 * before the hold timer has expired the buffer will be returned to the user.
570 *
571 * Before you can use this function, the rtems_bdbuf_init() routine must be
572 * called at least once to initialize the cache, otherwise a fatal error will
573 * occur.
574 *
575 * @param bd [in] Reference to the buffer descriptor.  The buffer descriptor
576 * reference must not be @c NULL and must be obtained via rtems_bdbuf_get() or
577 * rtems_bdbuf_read().
578 *
579 * @retval RTEMS_SUCCESSFUL Successful operation.
580 * @retval RTEMS_INVALID_ADDRESS The reference is NULL.
581 */
582rtems_status_code
583rtems_bdbuf_release_modified (rtems_bdbuf_buffer* bd);
584
585/**
586 * Release the buffer as modified and wait until it has been synchronized with
587 * the disk by writing it. This buffer will be the first to be transfer to disk
588 * and other buffers may also be written if the maximum number of blocks in a
589 * requests allows it.
590 *
591 * @note This code does not lock the sync mutex and stop additions to the
592 *       modified queue.
593 *
594 * Before you can use this function, the rtems_bdbuf_init() routine must be
595 * called at least once to initialize the cache, otherwise a fatal error will
596 * occur.
597 *
598 * @param bd [in] Reference to the buffer descriptor.  The buffer descriptor
599 * reference must not be @c NULL and must be obtained via rtems_bdbuf_get() or
600 * rtems_bdbuf_read().
601 *
602 * @retval RTEMS_SUCCESSFUL Successful operation.
603 * @retval RTEMS_INVALID_ADDRESS The reference is NULL.
604 */
605rtems_status_code
606rtems_bdbuf_sync (rtems_bdbuf_buffer* bd);
607
608/**
609 * Synchronize all modified buffers for this device with the disk and wait
610 * until the transfers have completed. The sync mutex for the cache is locked
611 * stopping the addition of any further modified buffers. It is only the
612 * currently modified buffers that are written.
613 *
614 * @note Nesting calls to sync multiple devices will be handled sequentially. A
615 * nested call will be blocked until the first sync request has complete.
616 *
617 * Before you can use this function, the rtems_bdbuf_init() routine must be
618 * called at least once to initialize the cache, otherwise a fatal error will
619 * occur.
620 *
621 * @param dd [in] The disk device.
622 *
623 * @retval RTEMS_SUCCESSFUL Successful operation.
624 */
625rtems_status_code
626rtems_bdbuf_syncdev (rtems_disk_device *dd);
627
628/**
629 * @brief Purges all buffers corresponding to the disk device @a dd.
630 *
631 * This may result in loss of data.  The read-ahead state of this device is reset.
632 *
633 * Before you can use this function, the rtems_bdbuf_init() routine must be
634 * called at least once to initialize the cache, otherwise a fatal error will
635 * occur.
636 *
637 * @param dd [in] The disk device.
638 */
639void
640rtems_bdbuf_purge_dev (rtems_disk_device *dd);
641
642/**
643 * @brief Sets the block size of a disk device.
644 *
645 * This will set the block size derived fields of the disk device.  If
646 * requested the disk device is synchronized before the block size change
647 * occurs.  Since the cache is unlocked during the synchronization operation
648 * some tasks may access the disk device in the meantime.  This may result in
649 * loss of data.  After the synchronization the disk device is purged to ensure
650 * a consistent cache state and the block size change occurs.  This also resets
651 * the read-ahead state of this disk device.  Due to the purge operation this
652 * may result in loss of data.
653 *
654 * Before you can use this function, the rtems_bdbuf_init() routine must be
655 * called at least once to initialize the cache, otherwise a fatal error will
656 * occur.
657 *
658 * @param dd [in, out] The disk device.
659 * @param block_size [in] The new block size in bytes.
660 * @param sync [in] If @c true, then synchronize the disk device before the
661 * block size change.
662 *
663 * @retval RTEMS_SUCCESSFUL Successful operation.
664 * @retval RTEMS_INVALID_NUMBER Invalid block size.
665 */
666rtems_status_code
667rtems_bdbuf_set_block_size (rtems_disk_device *dd,
668                            uint32_t           block_size,
669                            bool               sync);
670
671/**
672 * @brief Returns the block device statistics.
673 */
674void
675rtems_bdbuf_get_device_stats (const rtems_disk_device *dd,
676                              rtems_blkdev_stats      *stats);
677
678/**
679 * @brief Resets the block device statistics.
680 */
681void
682rtems_bdbuf_reset_device_stats (rtems_disk_device *dd);
683
684/** @} */
685
686#ifdef __cplusplus
687}
688#endif
689
690#endif
Note: See TracBrowser for help on using the repository browser.