rf_psstatus.c revision 1.20 1 /* $NetBSD: rf_psstatus.c,v 1.20 2003/12/31 00:42:46 oster Exp $ */
2 /*
3 * Copyright (c) 1995 Carnegie-Mellon University.
4 * All rights reserved.
5 *
6 * Author: Mark Holland
7 *
8 * Permission to use, copy, modify and distribute this software and
9 * its documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 *
18 * Carnegie Mellon requests users of this software to return to
19 *
20 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
24 *
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
27 */
28
29 /*****************************************************************************
30 *
31 * psstatus.c
32 *
33 * The reconstruction code maintains a bunch of status related to the parity
34 * stripes that are currently under reconstruction. This header file defines
35 * the status structures.
36 *
37 *****************************************************************************/
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: rf_psstatus.c,v 1.20 2003/12/31 00:42:46 oster Exp $");
41
42 #include <dev/raidframe/raidframevar.h>
43
44 #include "rf_raid.h"
45 #include "rf_general.h"
46 #include "rf_debugprint.h"
47 #include "rf_psstatus.h"
48 #include "rf_shutdown.h"
49
50 #if RF_DEBUG_PSS
51 #define Dprintf1(s,a) if (rf_pssDebug) rf_debug_printf(s,(void *)((unsigned long)a),NULL,NULL,NULL,NULL,NULL,NULL,NULL)
52 #define Dprintf2(s,a,b) if (rf_pssDebug) rf_debug_printf(s,(void *)((unsigned long)a),(void *)((unsigned long)b),NULL,NULL,NULL,NULL,NULL,NULL)
53 #define Dprintf3(s,a,b,c) if (rf_pssDebug) rf_debug_printf(s,(void *)((unsigned long)a),(void *)((unsigned long)b),(void *)((unsigned long)c),NULL,NULL,NULL,NULL,NULL)
54 #else
55 #define Dprintf1(s,a)
56 #define Dprintf2(s,a,b)
57 #define Dprintf3(s,a,b,c)
58 #endif
59
60 static void
61 RealPrintPSStatusTable(RF_Raid_t * raidPtr,
62 RF_PSStatusHeader_t * pssTable);
63
64 #define RF_MAX_FREE_PSS 32
65 #define RF_PSS_INC 8
66 #define RF_PSS_INITIAL 4
67
68 static void rf_ShutdownPSStatus(void *);
69
70 static void
71 rf_ShutdownPSStatus(void *arg)
72 {
73 RF_Raid_t *raidPtr = (RF_Raid_t *) arg;
74
75 pool_destroy(&raidPtr->pss_pool);
76 pool_destroy(&raidPtr->pss_issued_pool);
77 }
78
79 int
80 rf_ConfigurePSStatus(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr,
81 RF_Config_t *cfgPtr)
82 {
83 int rc;
84
85 raidPtr->pssTableSize = RF_PSS_DEFAULT_TABLESIZE;
86 pool_init(&raidPtr->pss_pool, sizeof(RF_ReconParityStripeStatus_t), 0,
87 0, 0, "raidpsspl", NULL);
88 pool_init(&raidPtr->pss_issued_pool,
89 raidPtr->numCol * sizeof(char), 0,
90 0, 0, "raidpssissuedpl", NULL);
91 rc = rf_ShutdownCreate(listp, rf_ShutdownPSStatus, raidPtr);
92 if (rc) {
93 rf_print_unable_to_add_shutdown(__FILE__, __LINE__, rc);
94 rf_ShutdownPSStatus(raidPtr);
95 return (rc);
96 }
97 pool_sethiwat(&raidPtr->pss_pool, RF_MAX_FREE_PSS);
98 pool_sethiwat(&raidPtr->pss_issued_pool, RF_MAX_FREE_PSS);
99 pool_prime(&raidPtr->pss_pool, RF_PSS_INITIAL);
100 pool_prime(&raidPtr->pss_issued_pool, RF_PSS_INITIAL);
101 return (0);
102 }
103 /*****************************************************************************************
104 * sets up the pss table
105 * We pre-allocate a bunch of entries to avoid as much as possible having to
106 * malloc up hash chain entries.
107 ****************************************************************************************/
108 RF_PSStatusHeader_t *
109 rf_MakeParityStripeStatusTable(RF_Raid_t *raidPtr)
110 {
111 RF_PSStatusHeader_t *pssTable;
112 int i;
113
114 RF_Malloc(pssTable,
115 raidPtr->pssTableSize * sizeof(RF_PSStatusHeader_t),
116 (RF_PSStatusHeader_t *));
117 for (i = 0; i < raidPtr->pssTableSize; i++) {
118 rf_mutex_init(&pssTable[i].mutex);
119 }
120 return (pssTable);
121 }
122
123 void
124 rf_FreeParityStripeStatusTable(RF_Raid_t *raidPtr,
125 RF_PSStatusHeader_t *pssTable)
126 {
127 #if RF_DEBUG_PSS
128 int i;
129
130 if (rf_pssDebug)
131 RealPrintPSStatusTable(raidPtr, pssTable);
132
133 for (i = 0; i < raidPtr->pssTableSize; i++) {
134 if (pssTable[i].chain) {
135 printf("ERROR: pss hash chain not null at recon shutdown\n");
136 }
137 }
138 #endif
139 RF_Free(pssTable, raidPtr->pssTableSize * sizeof(RF_PSStatusHeader_t));
140 }
141
142
143 /* looks up the status structure for a parity stripe.
144 * if the create_flag is on, creates and returns the status structure it it doesn't exist
145 * otherwise returns NULL if the status structure does not exist
146 *
147 * ASSUMES THE PSS DESCRIPTOR IS LOCKED UPON ENTRY
148 *
149 * flags - whether or not to create it if it doesn't exist and what flags
150 * to set it to initially
151 */
152 RF_ReconParityStripeStatus_t *
153 rf_LookupRUStatus(RF_Raid_t *raidPtr, RF_PSStatusHeader_t *pssTable,
154 RF_StripeNum_t psID, RF_ReconUnitNum_t which_ru,
155 RF_PSSFlags_t flags, int *created)
156 {
157 RF_PSStatusHeader_t *hdr = &pssTable[RF_HASH_PSID(raidPtr, psID)];
158 RF_ReconParityStripeStatus_t *p, *pssPtr = hdr->chain;
159
160 *created = 0;
161 for (p = pssPtr; p; p = p->next) {
162 if (p->parityStripeID == psID && p->which_ru == which_ru)
163 break;
164 }
165
166 if (!p && (flags & RF_PSS_CREATE)) {
167 Dprintf2("PSS: creating pss for psid %ld ru %d\n", psID, which_ru);
168 p = rf_AllocPSStatus(raidPtr);
169 p->next = hdr->chain;
170 hdr->chain = p;
171
172 p->parityStripeID = psID;
173 p->which_ru = which_ru;
174 p->flags = flags;
175 p->rbuf = NULL;
176 p->writeRbuf = NULL;
177 p->xorBufCount = 0;
178 p->blockCount = 0;
179 p->procWaitList = NULL;
180 p->blockWaitList = NULL;
181 p->bufWaitList = NULL;
182 *created = 1;
183 } else
184 if (p) { /* we didn't create, but we want to specify
185 * some new status */
186 p->flags |= flags; /* add in whatever flags we're
187 * specifying */
188 }
189 if (p && (flags & RF_PSS_RECON_BLOCKED)) {
190 p->blockCount++;/* if we're asking to block recon, bump the
191 * count */
192 Dprintf3("raid%d: Blocked recon on psid %ld. count now %d\n",
193 raidPtr->raidid, psID, p->blockCount);
194 }
195 return (p);
196 }
197 /* deletes an entry from the parity stripe status table. typically used
198 * when an entry has been allocated solely to block reconstruction, and
199 * no recon was requested while recon was blocked. Assumes the hash
200 * chain is ALREADY LOCKED.
201 */
202 void
203 rf_PSStatusDelete(RF_Raid_t *raidPtr, RF_PSStatusHeader_t *pssTable,
204 RF_ReconParityStripeStatus_t *pssPtr)
205 {
206 RF_PSStatusHeader_t *hdr = &(pssTable[RF_HASH_PSID(raidPtr, pssPtr->parityStripeID)]);
207 RF_ReconParityStripeStatus_t *p = hdr->chain, *pt = NULL;
208
209 while (p) {
210 if (p == pssPtr) {
211 if (pt)
212 pt->next = p->next;
213 else
214 hdr->chain = p->next;
215 p->next = NULL;
216 rf_FreePSStatus(raidPtr, p);
217 return;
218 }
219 pt = p;
220 p = p->next;
221 }
222 RF_ASSERT(0); /* we must find it here */
223 }
224 /* deletes an entry from the ps status table after reconstruction has completed */
225 void
226 rf_RemoveFromActiveReconTable(RF_Raid_t *raidPtr, RF_StripeNum_t psid,
227 RF_ReconUnitNum_t which_ru)
228 {
229 RF_PSStatusHeader_t *hdr = &(raidPtr->reconControl->pssTable[RF_HASH_PSID(raidPtr, psid)]);
230 RF_ReconParityStripeStatus_t *p, *pt;
231 RF_CallbackDesc_t *cb, *cb1;
232
233 RF_LOCK_MUTEX(hdr->mutex);
234 for (pt = NULL, p = hdr->chain; p; pt = p, p = p->next) {
235 if ((p->parityStripeID == psid) && (p->which_ru == which_ru))
236 break;
237 }
238 if (p == NULL) {
239 rf_PrintPSStatusTable(raidPtr);
240 }
241 RF_ASSERT(p); /* it must be there */
242
243 Dprintf2("PSS: deleting pss for psid %ld ru %d\n", psid, which_ru);
244
245 /* delete this entry from the hash chain */
246 if (pt)
247 pt->next = p->next;
248 else
249 hdr->chain = p->next;
250 p->next = NULL;
251
252 RF_UNLOCK_MUTEX(hdr->mutex);
253
254 /* wakup anyone waiting on the parity stripe ID */
255 cb = p->procWaitList;
256 p->procWaitList = NULL;
257 while (cb) {
258 Dprintf1("Waking up access waiting on parity stripe ID %ld\n", p->parityStripeID);
259 cb1 = cb->next;
260 (cb->callbackFunc) (cb->callbackArg);
261
262 /* THIS IS WHAT THE ORIGINAL CODE HAD... the extra 0 is bogus,
263 * IMHO */
264 /* (cb->callbackFunc)(cb->callbackArg, 0); */
265 rf_FreeCallbackDesc(cb);
266 cb = cb1;
267 }
268
269 rf_FreePSStatus(raidPtr, p);
270 }
271
272 RF_ReconParityStripeStatus_t *
273 rf_AllocPSStatus(RF_Raid_t *raidPtr)
274 {
275 RF_ReconParityStripeStatus_t *p;
276
277 p = pool_get(&raidPtr->pss_pool, PR_WAITOK);
278 p->issued = pool_get(&raidPtr->pss_issued_pool, PR_WAITOK);
279 memset(p->issued, 0, raidPtr->numCol);
280 p->next = NULL;
281 /* no need to initialize here b/c the only place we're called from is
282 * the above Lookup */
283 return (p);
284 }
285
286 void
287 rf_FreePSStatus(RF_Raid_t *raidPtr, RF_ReconParityStripeStatus_t *p)
288 {
289 RF_ASSERT(p->procWaitList == NULL);
290 RF_ASSERT(p->blockWaitList == NULL);
291 RF_ASSERT(p->bufWaitList == NULL);
292
293 pool_put(&raidPtr->pss_issued_pool, p->issued);
294 pool_put(&raidPtr->pss_pool, p);
295 }
296
297 static void
298 RealPrintPSStatusTable(RF_Raid_t *raidPtr, RF_PSStatusHeader_t *pssTable)
299 {
300 int i, j, procsWaiting, blocksWaiting, bufsWaiting;
301 RF_ReconParityStripeStatus_t *p;
302 RF_CallbackDesc_t *cb;
303
304 printf("\nParity Stripe Status Table\n");
305 for (i = 0; i < raidPtr->pssTableSize; i++) {
306 for (p = pssTable[i].chain; p; p = p->next) {
307 procsWaiting = blocksWaiting = bufsWaiting = 0;
308 for (cb = p->procWaitList; cb; cb = cb->next)
309 procsWaiting++;
310 for (cb = p->blockWaitList; cb; cb = cb->next)
311 blocksWaiting++;
312 for (cb = p->bufWaitList; cb; cb = cb->next)
313 bufsWaiting++;
314 printf("PSID %ld RU %d : blockCount %d %d/%d/%d proc/block/buf waiting, issued ",
315 (long) p->parityStripeID, p->which_ru, p->blockCount, procsWaiting, blocksWaiting, bufsWaiting);
316 for (j = 0; j < raidPtr->numCol; j++)
317 printf("%c", (p->issued[j]) ? '1' : '0');
318 if (!p->flags)
319 printf(" flags: (none)");
320 else {
321 if (p->flags & RF_PSS_UNDER_RECON)
322 printf(" under-recon");
323 if (p->flags & RF_PSS_FORCED_ON_WRITE)
324 printf(" forced-w");
325 if (p->flags & RF_PSS_FORCED_ON_READ)
326 printf(" forced-r");
327 if (p->flags & RF_PSS_RECON_BLOCKED)
328 printf(" blocked");
329 if (p->flags & RF_PSS_BUFFERWAIT)
330 printf(" bufwait");
331 }
332 printf("\n");
333 }
334 }
335 }
336
337 void
338 rf_PrintPSStatusTable(RF_Raid_t *raidPtr)
339 {
340 RF_PSStatusHeader_t *pssTable = raidPtr->reconControl->pssTable;
341 RealPrintPSStatusTable(raidPtr, pssTable);
342 }
343