source: rtems/cpukit/libblock/include/rtems/bdbuf.h @ 1c554014

4.115
Last change on this file since 1c554014 was 1c554014, checked in by Ralf Corsépius <ralf.corsepius@…>, on 07/19/12 at 14:14:53

Remove CVS-Ids.

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