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