This source file includes following definitions.
- rf_FifoCreate
- rf_FifoEnqueue
- rf_FifoDequeue
- rf_FifoPeek
- rf_FifoPromote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 #include "rf_types.h"
41 #include "rf_alloclist.h"
42 #include "rf_stripelocks.h"
43 #include "rf_layout.h"
44 #include "rf_diskqueue.h"
45 #include "rf_fifo.h"
46 #include "rf_debugMem.h"
47 #include "rf_general.h"
48 #include "rf_options.h"
49 #include "rf_raid.h"
50 #include "rf_types.h"
51
52
53
54 void *
55 rf_FifoCreate(RF_SectorCount_t sectPerDisk, RF_AllocListElem_t *clList,
56 RF_ShutdownList_t **listp)
57 {
58 RF_FifoHeader_t *q;
59
60 RF_CallocAndAdd(q, 1, sizeof(RF_FifoHeader_t), (RF_FifoHeader_t *),
61 clList);
62 q->hq_count = q->lq_count = 0;
63 return ((void *) q);
64 }
65
66 void
67 rf_FifoEnqueue(void *q_in, RF_DiskQueueData_t *elem, int priority)
68 {
69 RF_FifoHeader_t *q = (RF_FifoHeader_t *) q_in;
70
71 RF_ASSERT(priority == RF_IO_NORMAL_PRIORITY ||
72 priority == RF_IO_LOW_PRIORITY);
73
74 elem->next = NULL;
75 if (priority == RF_IO_NORMAL_PRIORITY) {
76 if (!q->hq_tail) {
77 RF_ASSERT(q->hq_count == 0 && q->hq_head == NULL);
78 q->hq_head = q->hq_tail = elem;
79 } else {
80 RF_ASSERT(q->hq_count != 0 && q->hq_head != NULL);
81 q->hq_tail->next = elem;
82 q->hq_tail = elem;
83 }
84 q->hq_count++;
85 } else {
86 RF_ASSERT(elem->next == NULL);
87 if (rf_fifoDebug) {
88 printf("raid%d: fifo: ENQ lopri\n",
89 elem->raidPtr->raidid);
90 }
91 if (!q->lq_tail) {
92 RF_ASSERT(q->lq_count == 0 && q->lq_head == NULL);
93 q->lq_head = q->lq_tail = elem;
94 } else {
95 RF_ASSERT(q->lq_count != 0 && q->lq_head != NULL);
96 q->lq_tail->next = elem;
97 q->lq_tail = elem;
98 }
99 q->lq_count++;
100 }
101 if ((q->hq_count + q->lq_count) != elem->queue->queueLength) {
102 printf("Queue lengths differ ! : %d %d %d\n",
103 q->hq_count, q->lq_count, (int) elem->queue->queueLength);
104 printf("%d %d %d %d\n",
105 (int) elem->queue->numOutstanding,
106 (int) elem->queue->maxOutstanding,
107 (int) elem->queue->row,
108 (int) elem->queue->col);
109 }
110 RF_ASSERT((q->hq_count + q->lq_count) == elem->queue->queueLength);
111 }
112
113 RF_DiskQueueData_t *
114 rf_FifoDequeue(void *q_in)
115 {
116 RF_FifoHeader_t *q = (RF_FifoHeader_t *) q_in;
117 RF_DiskQueueData_t *nd;
118
119 RF_ASSERT(q);
120 if (q->hq_head) {
121 RF_ASSERT(q->hq_count != 0 && q->hq_tail != NULL);
122 nd = q->hq_head;
123 q->hq_head = q->hq_head->next;
124 if (!q->hq_head)
125 q->hq_tail = NULL;
126 nd->next = NULL;
127 q->hq_count--;
128 } else
129 if (q->lq_head) {
130 RF_ASSERT(q->lq_count != 0 && q->lq_tail != NULL);
131 nd = q->lq_head;
132 q->lq_head = q->lq_head->next;
133 if (!q->lq_head)
134 q->lq_tail = NULL;
135 nd->next = NULL;
136 q->lq_count--;
137 if (rf_fifoDebug) {
138 printf("raid%d: fifo: DEQ lopri %lx\n",
139 nd->raidPtr->raidid, (long) nd);
140 }
141 } else {
142 RF_ASSERT(q->hq_count == 0 && q->lq_count == 0 &&
143 q->hq_tail == NULL && q->lq_tail == NULL);
144 nd = NULL;
145 }
146 return (nd);
147 }
148
149
150
151
152
153 RF_DiskQueueData_t *
154 rf_FifoPeek(void *q_in)
155 {
156 RF_DiskQueueData_t *headElement = NULL;
157 RF_FifoHeader_t *q = (RF_FifoHeader_t *) q_in;
158
159 RF_ASSERT(q);
160 if (q->hq_head)
161 headElement = q->hq_head;
162 else
163 if (q->lq_head)
164 headElement = q->lq_head;
165 return (headElement);
166 }
167
168
169
170
171
172
173
174
175
176
177 int
178 rf_FifoPromote(void *q_in, RF_StripeNum_t parityStripeID,
179 RF_ReconUnitNum_t which_ru)
180 {
181 RF_FifoHeader_t *q = (RF_FifoHeader_t *) q_in;
182
183 RF_DiskQueueData_t *lp = q->lq_head, *pt = NULL;
184 int retval = 0;
185
186 while (lp) {
187
188
189
190
191 if (lp->parityStripeID == parityStripeID &&
192 lp->which_ru == which_ru) {
193
194
195 if (pt)
196
197 pt->next = lp->next;
198 else
199
200 q->lq_head = lp->next;
201
202 if (!q->lq_head)
203
204 q->lq_tail = NULL;
205 else
206 if (lp == q->lq_tail)
207
208 q->lq_tail = pt;
209
210 lp->next = NULL;
211 q->lq_count--;
212
213 if (q->hq_tail) {
214 q->hq_tail->next = lp;
215 q->hq_tail = lp;
216 }
217
218 else {
219 q->hq_head = q->hq_tail = lp;
220 }
221 q->hq_count++;
222
223
224
225
226
227
228 lp = (pt) ? pt->next : q->lq_head;
229 retval++;
230
231 } else {
232 pt = lp;
233 lp = lp->next;
234 }
235 }
236
237
238
239
240
241 RF_ASSERT(retval == 0 || retval == 1);
242 return (retval);
243 }