source: rtems/cpukit/libblock/include/rtems/bdbuf.h @ e51bd96

4.104.114.84.95
Last change on this file since e51bd96 was e51bd96, checked in by Joel Sherrill <joel.sherrill@…>, on 02/28/02 at 20:39:54

2002-02-28 Joel Sherrill <joel@…>

  • Submitted by Victor V. Vengerov <vvv@…> and merged into the RTEMS source.
  • ChangeLog?, Makefile.am, README, configure.ac, include/Makefile.am, include/rtems/bdbuf.h, include/rtems/blkdev.h, include/rtems/diskdevs.h, include/rtems/ramdisk.h, include/rtems/.cvsignore, include/.cvsignore, src/Makefile.am, src/bdbuf.c, src/blkdev.c, src/diskdevs.c, src/ramdisk.c, src/.cvsignore, .cvsignore: New files.
  • Property mode set to 100644
File size: 10.1 KB
Line 
1/* bdbuf.h -- block device buffer management
2 *
3 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
4 * Author: Victor V. Vengerov <vvv@oktet.ru>
5 *
6 * @(#) $Id$
7 */
8
9#ifndef __RTEMS_LIBBLOCK_BDBUF_H__
10#define __RTEMS_LIBBLOCK_BDBUF_H__
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#include <rtems.h>
17#include <rtems/libio.h>
18#include <chain.h>
19
20#include "rtems/blkdev.h"
21#include "rtems/diskdevs.h"
22
23
24/*
25 * To manage buffers we using Buffer Descriptors.
26 * To speed-up buffer lookup descriptors are organized in AVL-Tree.
27 * The fields 'dev' and 'block' are search key.
28 */
29
30/* Buffer descriptors
31 * Descriptors organized in AVL-tree to speedup buffer lookup.
32 * dev and block fields are search key in AVL-tree.
33 * Modified buffers, free buffers and used buffers linked in 'mod', 'free' and
34 * 'lru' chains appropriately.
35 */
36
37typedef struct bdbuf_buffer {
38    Chain_Node link; /* Link in the lru, mod or free chains */
39
40#ifdef BINARY_TREE
41    struct bdbuf_avl_node {
42        struct bdbuf_buffer *left;  /* link to the left sub-tree */
43        struct bdbuf_buffer *right; /* link to the right sub-tree */
44
45        int              bf; /* AVL tree node balance factor */
46    }           avl;     /* AVL-tree links */
47#else /* AVL TREE */
48    struct bdbuf_avl_node {
49        char cache;           /* Cache */
50
51        struct bdbuf_buffer* link[2]; /* Left and Right Kids */
52
53        char bal;             /* The balance of the sub-tree */
54    } avl;
55#endif
56    dev_t       dev;     /* device number */
57    blkdev_bnum block;   /* block number on the device */
58   
59    char       *buffer;  /* Pointer to the buffer memory area */
60    rtems_status_code status; /* Last I/O operation completion status */
61    int         error;   /* If status != RTEMS_SUCCESSFUL, this field contains
62                            errno value which can be used by user later */
63    boolean     modified:1;    /* =1 if buffer was modified */
64    boolean     in_progress:1; /* =1 if exchange with disk is in progress;
65                                  need to wait on semaphore */
66    boolean     actual:1;      /* Buffer contains actual data */
67    int         use_count; /* Usage counter; incremented when somebody use
68                              this buffer; decremented when buffer released
69                              without modification or when buffer is flushed
70                              by swapout task */
71
72    rtems_bdpool_id pool;  /* Identifier of buffer pool to which this buffer
73                              belongs */
74    CORE_mutex_Control transfer_sema;
75                           /* Transfer operation semaphore */
76} bdbuf_buffer;
77
78
79
80/* bdbuf_config structure describes block configuration (size,
81 * amount, memory location) for buffering layer
82 */
83typedef struct rtems_bdbuf_config {
84    int     size;     /* Size of block */
85    int     num;      /* Number of blocks of appropriate size */
86    char   *mem_area; /* Pointer to the blocks location or NULL, in this
87                          case memory for blocks will be allocated by
88                          Buffering Layer with the help of RTEMS partition
89                          manager */
90} rtems_bdbuf_config;
91
92extern rtems_bdbuf_config rtems_bdbuf_configuration[];
93extern int rtems_bdbuf_configuration_size;
94
95/* rtems_bdbuf_init --
96 *     Prepare buffering layer to work - initialize buffer descritors
97 *     and (if it is neccessary) buffers. Buffers will be allocated accoriding
98 *     to the configuration table, each entry describes kind of block and
99 *     amount requested. After initialization all blocks is placed into
100 *     free elements lists.
101 *
102 * PARAMETERS:
103 *     conf_table - pointer to the buffers configuration table
104 *     size       - number of entries in configuration table
105 *
106 * RETURNS:
107 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
108 *     or error code if error is occured)
109 */
110rtems_status_code
111rtems_bdbuf_init(rtems_bdbuf_config *conf_table, int size);
112
113
114/* rtems_bdbuf_get --
115 *     Obtain block buffer. If specified block already cached (i.e. there's
116 *     block in the _modified_, or _recently_used_), return address
117 *     of appropriate buffer descriptor and increment reference counter to 1.
118 *     If block is not cached, allocate new buffer and return it. Data
119 *     shouldn't be read to the buffer from media; buffer may contains
120 *     arbitrary data. This primitive may be blocked if there are no free
121 *     buffer descriptors available and there are no unused non-modified
122 *     (or synchronized with media) buffers available.
123 *
124 * PARAMETERS:
125 *     device - device number (constructed of major and minor device number)
126 *     block  - linear media block number
127 *     bd     - address of variable to store pointer to the buffer descriptor
128 *
129 * RETURNS:
130 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
131 *     or error code if error is occured)
132 *
133 * SIDE EFFECTS:
134 *     bufget_sema semaphore obtained by this primitive.
135 */
136rtems_status_code
137rtems_bdbuf_get(dev_t device, blkdev_bnum block, bdbuf_buffer **bdb_ptr);
138
139/* rtems_bdbuf_read --
140 *     (Similar to the rtems_bdbuf_get, except reading data from media)
141 *     Obtain block buffer. If specified block already cached, return address
142 *     of appropriate buffer and increment reference counter to 1. If block is
143 *     not cached, allocate new buffer and read data to it from the media.
144 *     This primitive may be blocked on waiting until data to be read from
145 *     media, if there are no free buffer descriptors available and there are
146 *     no unused non-modified (or synchronized with media) buffers available.
147 *
148 * PARAMETERS:
149 *     device - device number (consists of major and minor device number)
150 *     block  - linear media block number
151 *     bd     - address of variable to store pointer to the buffer descriptor
152 *
153 * RETURNS:
154 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
155 *     or error code if error is occured)
156 *
157 * SIDE EFFECTS:
158 *     bufget_sema and transfer_sema semaphores obtained by this primitive.
159 */
160rtems_status_code
161rtems_bdbuf_read(dev_t device, blkdev_bnum block, bdbuf_buffer **bdb_ptr);
162
163/* rtems_bdbuf_release --
164 *     Release buffer allocated before. This primitive decrease the
165 *     usage counter. If it is zero, further destiny of buffer depends on
166 *     'modified' status. If buffer was modified, it is placed to the end of
167 *     mod list and flush task waken up. If buffer was not modified,
168 *     it is placed to the end of lru list, and bufget_sema released, allowing
169 *     to reuse this buffer.
170 *
171 * PARAMETERS:
172 *     bd_buf - pointer to the bdbuf_buffer structure previously obtained using
173 *              get/read primitive.
174 *
175 * RETURNS:
176 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
177 *     or error code if error is occured)
178 *
179 * SIDE EFFECTS:
180 *     flush_sema and bufget_sema semaphores may be released by this primitive.
181 */
182rtems_status_code
183rtems_bdbuf_release(bdbuf_buffer *bd_buf);
184
185/* rtems_bdbuf_release_modified --
186 *     Release buffer allocated before, assuming that it is _modified_ by
187 *     it's owner. This primitive decrease usage counter for buffer, mark
188 *     buffer descriptor as modified. If usage counter is 0, insert it at
189 *     end of mod chain and release flush_sema semaphore to activate the
190 *     flush task.
191 *
192 * PARAMETERS:
193 *     bd_buf - pointer to the bdbuf_buffer structure previously obtained using
194 *              get/read primitive.
195 *
196 * RETURNS:
197 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
198 *     or error code if error is occured)
199 *
200 * SIDE EFFECTS:
201 *     flush_sema semaphore may be released by this primitive.
202 */
203rtems_status_code
204rtems_bdbuf_release_modified(bdbuf_buffer *bd_buf);
205
206/* rtems_bdbuf_sync --
207 *     Wait until specified buffer synchronized with disk. Invoked on exchanges
208 *     critical for data consistency on the media. This primitive mark owned
209 *     block as modified, decrease usage counter. If usage counter is 0,
210 *     block inserted to the mod chain and flush_sema semaphore released.
211 *     Finally, primitives blocked on transfer_sema semaphore.
212 *
213 * PARAMETERS:
214 *     bd_buf - pointer to the bdbuf_buffer structure previously obtained using
215 *              get/read primitive.
216 *
217 * RETURNS:
218 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
219 *     or error code if error is occured)
220 *
221 * SIDE EFFECTS:
222 *     Primitive may be blocked on transfer_sema semaphore.
223 */
224rtems_status_code
225rtems_bdbuf_sync(bdbuf_buffer *bd_buf);
226
227/* rtems_bdbuf_syncdev --
228 *     Synchronize with disk all buffers containing the blocks belonging to
229 *     specified device.
230 *
231 * PARAMETERS:
232 *     dev - block device number
233 *
234 * RETURNS:
235 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
236 *     or error code if error is occured)
237 */
238rtems_status_code
239rtems_bdbuf_syncdev(dev_t dev);
240
241/* rtems_bdbuf_find_pool --
242 *     Find first appropriate buffer pool. This primitive returns the index
243 *     of first buffer pool which block size is greater than or equal to
244 *     specified size.
245 *
246 * PARAMETERS:
247 *     block_size - requested block size
248 *     pool       - placeholder for result
249 *
250 * RETURNS:
251 *     RTEMS status code: RTEMS_SUCCESSFUL if operation completed successfully,
252 *     RTEMS_INVALID_SIZE if specified block size is invalid (not a power
253 *     of 2), RTEMS_NOT_DEFINED if buffer pool for this or greater block size
254 *     is not configured.
255 */
256rtems_status_code
257rtems_bdbuf_find_pool(int block_size, rtems_bdpool_id *pool);
258
259/* rtems_bdbuf_get_pool_info --
260 *     Obtain characteristics of buffer pool with specified number.
261 *
262 * PARAMETERS:
263 *     pool       - buffer pool number
264 *     block_size - block size for which buffer pool is configured returned
265 *                  there
266 *     blocks     - number of buffers in buffer pool returned there
267 *
268 * RETURNS:
269 *     RTEMS status code: RTEMS_SUCCESSFUL if operation completed successfully,
270 *     RTEMS_INVALID_NUMBER if appropriate buffer pool is not configured.
271 *
272 * NOTE:
273 *     Buffer pools enumerated contiguously starting from 0.
274 */
275rtems_status_code
276rtems_bdbuf_get_pool_info(rtems_bdpool_id pool, int *block_size, int *blocks);
277
278#ifdef __cplusplus
279}
280#endif
281
282#endif
Note: See TracBrowser for help on using the repository browser.