rf_psstatus.c revision 1.17 1 /* $NetBSD: rf_psstatus.c,v 1.17 2003/12/29 04:56:26 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.17 2003/12/29 04:56:26 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(arg)
72 void *arg;
73 {
74 RF_Raid_t *raidPtr = (RF_Raid_t *) arg;
75
76 pool_destroy(&raidPtr->pss_pool);
77 pool_destroy(&raidPtr->pss_issued_pool);
78 }
79
80 int
81 rf_ConfigurePSStatus(
82 RF_ShutdownList_t ** listp,
83 RF_Raid_t * raidPtr,
84 RF_Config_t * cfgPtr)
85 {
86 int rc;
87
88 raidPtr->pssTableSize = RF_PSS_DEFAULT_TABLESIZE;
89 pool_init(&raidPtr->pss_pool, sizeof(RF_ReconParityStripeStatus_t), 0,
90 0, 0, "raidpsspl", NULL);
91 pool_init(&raidPtr->pss_issued_pool,
92 raidPtr->numCol * sizeof(char), 0,
93 0, 0, "raidpssissuedpl", NULL);
94 rc = rf_ShutdownCreate(listp, rf_ShutdownPSStatus, raidPtr);
95 if (rc) {
96 rf_print_unable_to_add_shutdown(__FILE__, __LINE__, rc);
97 rf_ShutdownPSStatus(raidPtr);
98 return (rc);
99 }
100 pool_sethiwat(&raidPtr->pss_pool, RF_MAX_FREE_PSS);
101 pool_sethiwat(&raidPtr->pss_issued_pool, RF_MAX_FREE_PSS);
102 pool_prime(&raidPtr->pss_pool, RF_PSS_INITIAL);
103 pool_prime(&raidPtr->pss_issued_pool, RF_PSS_INITIAL);
104 return (0);
105 }
106 /*****************************************************************************************
107 * sets up the pss table
108 * We pre-allocate a bunch of entries to avoid as much as possible having to
109 * malloc up hash chain entries.
110 ****************************************************************************************/
111 RF_PSStatusHeader_t *
112 rf_MakeParityStripeStatusTable(raidPtr)
113 RF_Raid_t *raidPtr;
114 {
115 RF_PSStatusHeader_t *pssTable;
116 int i;
117
118 RF_Malloc(pssTable,
119 raidPtr->pssTableSize * sizeof(RF_PSStatusHeader_t),
120 (RF_PSStatusHeader_t *));
121 for (i = 0; i < raidPtr->pssTableSize; i++) {
122 rf_mutex_init(&pssTable[i].mutex);
123 }
124 return (pssTable);
125 }
126
127 void
128 rf_FreeParityStripeStatusTable(raidPtr, pssTable)
129 RF_Raid_t *raidPtr;
130 RF_PSStatusHeader_t *pssTable;
131 {
132 int i;
133
134 #if RF_DEBUG_PSS
135 if (rf_pssDebug)
136 RealPrintPSStatusTable(raidPtr, pssTable);
137 #endif
138 for (i = 0; i < raidPtr->pssTableSize; i++) {
139 if (pssTable[i].chain) {
140 printf("ERROR: pss hash chain not null at recon shutdown\n");
141 }
142 rf_mutex_destroy(&pssTable[i].mutex);
143 }
144 RF_Free(pssTable, raidPtr->pssTableSize * sizeof(RF_PSStatusHeader_t));
145 }
146
147
148 /* looks up the status structure for a parity stripe.
149 * if the create_flag is on, creates and returns the status structure it it doesn't exist
150 * otherwise returns NULL if the status structure does not exist
151 *
152 * ASSUMES THE PSS DESCRIPTOR IS LOCKED UPON ENTRY
153 */
154 RF_ReconParityStripeStatus_t *
155 rf_LookupRUStatus(
156 RF_Raid_t * raidPtr,
157 RF_PSStatusHeader_t * pssTable,
158 RF_StripeNum_t psID,
159 RF_ReconUnitNum_t which_ru,
160 RF_PSSFlags_t flags, /* whether or not to create it if it doesn't
161 * exist + what flags to set initially */
162 int *created)
163 {
164 RF_PSStatusHeader_t *hdr = &pssTable[RF_HASH_PSID(raidPtr, psID)];
165 RF_ReconParityStripeStatus_t *p, *pssPtr = hdr->chain;
166
167 *created = 0;
168 for (p = pssPtr; p; p = p->next) {
169 if (p->parityStripeID == psID && p->which_ru == which_ru)
170 break;
171 }
172
173 if (!p && (flags & RF_PSS_CREATE)) {
174 Dprintf2("PSS: creating pss for psid %ld ru %d\n", psID, which_ru);
175 p = rf_AllocPSStatus(raidPtr);
176 p->next = hdr->chain;
177 hdr->chain = p;
178
179 p->parityStripeID = psID;
180 p->which_ru = which_ru;
181 p->flags = flags;
182 p->rbuf = NULL;
183 p->writeRbuf = NULL;
184 p->xorBufCount = 0;
185 p->blockCount = 0;
186 p->procWaitList = NULL;
187 p->blockWaitList = NULL;
188 p->bufWaitList = NULL;
189 *created = 1;
190 } else
191 if (p) { /* we didn't create, but we want to specify
192 * some new status */
193 p->flags |= flags; /* add in whatever flags we're
194 * specifying */
195 }
196 if (p && (flags & RF_PSS_RECON_BLOCKED)) {
197 p->blockCount++;/* if we're asking to block recon, bump the
198 * count */
199 Dprintf3("raid%d: Blocked recon on psid %ld. count now %d\n",
200 raidPtr->raidid, psID, p->blockCount);
201 }
202 return (p);
203 }
204 /* deletes an entry from the parity stripe status table. typically used
205 * when an entry has been allocated solely to block reconstruction, and
206 * no recon was requested while recon was blocked. Assumes the hash
207 * chain is ALREADY LOCKED.
208 */
209 void
210 rf_PSStatusDelete(raidPtr, pssTable, pssPtr)
211 RF_Raid_t *raidPtr;
212 RF_PSStatusHeader_t *pssTable;
213 RF_ReconParityStripeStatus_t *pssPtr;
214 {
215 RF_PSStatusHeader_t *hdr = &(pssTable[RF_HASH_PSID(raidPtr, pssPtr->parityStripeID)]);
216 RF_ReconParityStripeStatus_t *p = hdr->chain, *pt = NULL;
217
218 while (p) {
219 if (p == pssPtr) {
220 if (pt)
221 pt->next = p->next;
222 else
223 hdr->chain = p->next;
224 p->next = NULL;
225 rf_FreePSStatus(raidPtr, p);
226 return;
227 }
228 pt = p;
229 p = p->next;
230 }
231 RF_ASSERT(0); /* we must find it here */
232 }
233 /* deletes an entry from the ps status table after reconstruction has completed */
234 void
235 rf_RemoveFromActiveReconTable(raidPtr, psid, which_ru)
236 RF_Raid_t *raidPtr;
237 RF_ReconUnitNum_t which_ru;
238 RF_StripeNum_t psid;
239 {
240 RF_PSStatusHeader_t *hdr = &(raidPtr->reconControl->pssTable[RF_HASH_PSID(raidPtr, psid)]);
241 RF_ReconParityStripeStatus_t *p, *pt;
242 RF_CallbackDesc_t *cb, *cb1;
243
244 RF_LOCK_MUTEX(hdr->mutex);
245 for (pt = NULL, p = hdr->chain; p; pt = p, p = p->next) {
246 if ((p->parityStripeID == psid) && (p->which_ru == which_ru))
247 break;
248 }
249 if (p == NULL) {
250 rf_PrintPSStatusTable(raidPtr);
251 }
252 RF_ASSERT(p); /* it must be there */
253
254 Dprintf2("PSS: deleting pss for psid %ld ru %d\n", psid, which_ru);
255
256 /* delete this entry from the hash chain */
257 if (pt)
258 pt->next = p->next;
259 else
260 hdr->chain = p->next;
261 p->next = NULL;
262
263 RF_UNLOCK_MUTEX(hdr->mutex);
264
265 /* wakup anyone waiting on the parity stripe ID */
266 cb = p->procWaitList;
267 p->procWaitList = NULL;
268 while (cb) {
269 Dprintf1("Waking up access waiting on parity stripe ID %ld\n", p->parityStripeID);
270 cb1 = cb->next;
271 (cb->callbackFunc) (cb->callbackArg);
272
273 /* THIS IS WHAT THE ORIGINAL CODE HAD... the extra 0 is bogus,
274 * IMHO */
275 /* (cb->callbackFunc)(cb->callbackArg, 0); */
276 rf_FreeCallbackDesc(cb);
277 cb = cb1;
278 }
279
280 rf_FreePSStatus(raidPtr, p);
281 }
282
283 RF_ReconParityStripeStatus_t *
284 rf_AllocPSStatus(raidPtr)
285 RF_Raid_t *raidPtr;
286 {
287 RF_ReconParityStripeStatus_t *p;
288
289 p = pool_get(&raidPtr->pss_pool, PR_WAITOK);
290 p->issued = pool_get(&raidPtr->pss_issued_pool, PR_WAITOK);
291 memset(p->issued, 0, raidPtr->numCol);
292 p->next = NULL;
293 /* no need to initialize here b/c the only place we're called from is
294 * the above Lookup */
295 return (p);
296 }
297
298 void
299 rf_FreePSStatus(raidPtr, p)
300 RF_Raid_t *raidPtr;
301 RF_ReconParityStripeStatus_t *p;
302 {
303 RF_ASSERT(p->procWaitList == NULL);
304 RF_ASSERT(p->blockWaitList == NULL);
305 RF_ASSERT(p->bufWaitList == NULL);
306
307 pool_put(&raidPtr->pss_issued_pool, p->issued);
308 pool_put(&raidPtr->pss_pool, p);
309 }
310
311 static void
312 RealPrintPSStatusTable(raidPtr, pssTable)
313 RF_Raid_t *raidPtr;
314 RF_PSStatusHeader_t *pssTable;
315 {
316 int i, j, procsWaiting, blocksWaiting, bufsWaiting;
317 RF_ReconParityStripeStatus_t *p;
318 RF_CallbackDesc_t *cb;
319
320 printf("\nParity Stripe Status Table\n");
321 for (i = 0; i < raidPtr->pssTableSize; i++) {
322 for (p = pssTable[i].chain; p; p = p->next) {
323 procsWaiting = blocksWaiting = bufsWaiting = 0;
324 for (cb = p->procWaitList; cb; cb = cb->next)
325 procsWaiting++;
326 for (cb = p->blockWaitList; cb; cb = cb->next)
327 blocksWaiting++;
328 for (cb = p->bufWaitList; cb; cb = cb->next)
329 bufsWaiting++;
330 printf("PSID %ld RU %d : blockCount %d %d/%d/%d proc/block/buf waiting, issued ",
331 (long) p->parityStripeID, p->which_ru, p->blockCount, procsWaiting, blocksWaiting, bufsWaiting);
332 for (j = 0; j < raidPtr->numCol; j++)
333 printf("%c", (p->issued[j]) ? '1' : '0');
334 if (!p->flags)
335 printf(" flags: (none)");
336 else {
337 if (p->flags & RF_PSS_UNDER_RECON)
338 printf(" under-recon");
339 if (p->flags & RF_PSS_FORCED_ON_WRITE)
340 printf(" forced-w");
341 if (p->flags & RF_PSS_FORCED_ON_READ)
342 printf(" forced-r");
343 if (p->flags & RF_PSS_RECON_BLOCKED)
344 printf(" blocked");
345 if (p->flags & RF_PSS_BUFFERWAIT)
346 printf(" bufwait");
347 }
348 printf("\n");
349 }
350 }
351 }
352
353 void
354 rf_PrintPSStatusTable(raidPtr)
355 RF_Raid_t *raidPtr;
356 {
357 RF_PSStatusHeader_t *pssTable = raidPtr->reconControl->pssTable;
358 RealPrintPSStatusTable(raidPtr, pssTable);
359 }
360