rf_psstatus.c revision 1.1 1 /* $NetBSD: rf_psstatus.c,v 1.1 1998/11/13 04:20:32 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 /* :
40 * Log: rf_psstatus.c,v
41 * Revision 1.29 1996/07/27 23:36:08 jimz
42 * Solaris port of simulator
43 *
44 * Revision 1.28 1996/07/15 17:22:18 jimz
45 * nit-pick code cleanup
46 * resolve stdlib problems on DEC OSF
47 *
48 * Revision 1.27 1996/07/13 00:00:59 jimz
49 * sanitized generalized reconstruction architecture
50 * cleaned up head sep, rbuf problems
51 *
52 * Revision 1.26 1996/06/10 11:55:47 jimz
53 * Straightened out some per-array/not-per-array distinctions, fixed
54 * a couple bugs related to confusion. Added shutdown lists. Removed
55 * layout shutdown function (now subsumed by shutdown lists).
56 *
57 * Revision 1.25 1996/06/07 22:26:27 jimz
58 * type-ify which_ru (RF_ReconUnitNum_t)
59 *
60 * Revision 1.24 1996/06/07 21:33:04 jimz
61 * begin using consistent types for sector numbers,
62 * stripe numbers, row+col numbers, recon unit numbers
63 *
64 * Revision 1.23 1996/06/05 18:06:02 jimz
65 * Major code cleanup. The Great Renaming is now done.
66 * Better modularity. Better typing. Fixed a bunch of
67 * synchronization bugs. Made a lot of global stuff
68 * per-desc or per-array. Removed dead code.
69 *
70 * Revision 1.22 1996/06/02 17:31:48 jimz
71 * Moved a lot of global stuff into array structure, where it belongs.
72 * Fixed up paritylogging, pss modules in this manner. Some general
73 * code cleanup. Removed lots of dead code, some dead files.
74 *
75 * Revision 1.21 1996/05/30 23:22:16 jimz
76 * bugfixes of serialization, timing problems
77 * more cleanup
78 *
79 * Revision 1.20 1996/05/27 18:56:37 jimz
80 * more code cleanup
81 * better typing
82 * compiles in all 3 environments
83 *
84 * Revision 1.19 1996/05/24 22:17:04 jimz
85 * continue code + namespace cleanup
86 * typed a bunch of flags
87 *
88 * Revision 1.18 1996/05/23 21:46:35 jimz
89 * checkpoint in code cleanup (release prep)
90 * lots of types, function names have been fixed
91 *
92 * Revision 1.17 1996/05/23 00:33:23 jimz
93 * code cleanup: move all debug decls to rf_options.c, all extern
94 * debug decls to rf_options.h, all debug vars preceded by rf_
95 *
96 * Revision 1.16 1996/05/20 16:15:27 jimz
97 * switch to rf_{mutex,cond}_{init,destroy}
98 *
99 * Revision 1.15 1996/05/18 19:51:34 jimz
100 * major code cleanup- fix syntax, make some types consistent,
101 * add prototypes, clean out dead code, et cetera
102 *
103 * Revision 1.14 1995/12/12 18:10:06 jimz
104 * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT
105 * fix 80-column brain damage in comments
106 *
107 * Revision 1.13 1995/11/30 16:17:18 wvcii
108 * added copyright info
109 *
110 */
111
112 #include "rf_types.h"
113 #include "rf_raid.h"
114 #include "rf_threadid.h"
115 #include "rf_general.h"
116 #include "rf_debugprint.h"
117 #include "rf_freelist.h"
118 #include "rf_psstatus.h"
119 #include "rf_shutdown.h"
120 #include "rf_sys.h"
121
122 #define Dprintf1(s,a) if (rf_pssDebug) rf_debug_printf(s,(void *)((unsigned long)a),NULL,NULL,NULL,NULL,NULL,NULL,NULL)
123 #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)
124 #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)
125
126 static void RealPrintPSStatusTable(RF_Raid_t *raidPtr,
127 RF_PSStatusHeader_t *pssTable);
128
129 #define RF_MAX_FREE_PSS 32
130 #define RF_PSS_INC 8
131 #define RF_PSS_INITIAL 4
132
133 static int init_pss( RF_ReconParityStripeStatus_t *, RF_Raid_t *);
134 static void clean_pss(RF_ReconParityStripeStatus_t *, RF_Raid_t *);
135 static void rf_ShutdownPSStatus(void *);
136
137 static int init_pss(p, raidPtr)
138 RF_ReconParityStripeStatus_t *p;
139 RF_Raid_t *raidPtr;
140 {
141 RF_Calloc(p->issued, raidPtr->numCol, sizeof(char), (char *));
142 if (p->issued == NULL)
143 return(ENOMEM);
144 return(0);
145 }
146
147 static void clean_pss(p, raidPtr)
148 RF_ReconParityStripeStatus_t *p;
149 RF_Raid_t *raidPtr;
150 {
151 RF_Free(p->issued, raidPtr->numCol*sizeof(char));
152 }
153
154 static void rf_ShutdownPSStatus(arg)
155 void *arg;
156 {
157 RF_Raid_t *raidPtr = (RF_Raid_t *)arg;
158
159 RF_FREELIST_DESTROY_CLEAN_ARG(raidPtr->pss_freelist,next,(RF_ReconParityStripeStatus_t *),clean_pss,raidPtr);
160 }
161
162 int rf_ConfigurePSStatus(
163 RF_ShutdownList_t **listp,
164 RF_Raid_t *raidPtr,
165 RF_Config_t *cfgPtr)
166 {
167 int rc;
168
169 raidPtr->pssTableSize = RF_PSS_DEFAULT_TABLESIZE;
170 RF_FREELIST_CREATE(raidPtr->pss_freelist, RF_MAX_FREE_PSS,
171 RF_PSS_INC, sizeof(RF_ReconParityStripeStatus_t));
172 if (raidPtr->pss_freelist == NULL)
173 return(ENOMEM);
174 rc = rf_ShutdownCreate(listp, rf_ShutdownPSStatus, raidPtr);
175 if (rc) {
176 RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n",
177 __FILE__, __LINE__, rc);
178 rf_ShutdownPSStatus(raidPtr);
179 return(rc);
180 }
181 RF_FREELIST_PRIME_INIT_ARG(raidPtr->pss_freelist, RF_PSS_INITIAL,next,
182 (RF_ReconParityStripeStatus_t *),init_pss,raidPtr);
183 return(0);
184 }
185
186 /*****************************************************************************************
187 * sets up the pss table
188 * We pre-allocate a bunch of entries to avoid as much as possible having to
189 * malloc up hash chain entries.
190 ****************************************************************************************/
191 RF_PSStatusHeader_t *rf_MakeParityStripeStatusTable(raidPtr)
192 RF_Raid_t *raidPtr;
193 {
194 RF_PSStatusHeader_t *pssTable;
195 int i, j, rc;
196
197 RF_Calloc(pssTable, raidPtr->pssTableSize, sizeof(RF_PSStatusHeader_t), (RF_PSStatusHeader_t *));
198 for (i=0; i<raidPtr->pssTableSize; i++) {
199 rc = rf_mutex_init(&pssTable[i].mutex);
200 if (rc) {
201 RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
202 __LINE__, rc);
203 /* fail and deallocate */
204 for(j=0;j<i;j++) {
205 rf_mutex_destroy(&pssTable[i].mutex);
206 }
207 RF_Free(pssTable, raidPtr->pssTableSize*sizeof(RF_PSStatusHeader_t));
208 return(NULL);
209 }
210 }
211 return(pssTable);
212 }
213
214 void rf_FreeParityStripeStatusTable(raidPtr, pssTable)
215 RF_Raid_t *raidPtr;
216 RF_PSStatusHeader_t *pssTable;
217 {
218 int i;
219
220 if (rf_pssDebug)
221 RealPrintPSStatusTable(raidPtr, pssTable);
222 for (i=0; i<raidPtr->pssTableSize; i++) {
223 if (pssTable[i].chain) {
224 printf("ERROR: pss hash chain not null at recon shutdown\n");
225 }
226 rf_mutex_destroy(&pssTable[i].mutex);
227 }
228 RF_Free(pssTable, raidPtr->pssTableSize * sizeof(RF_PSStatusHeader_t));
229 }
230
231
232 /* looks up the status structure for a parity stripe.
233 * if the create_flag is on, creates and returns the status structure it it doesn't exist
234 * otherwise returns NULL if the status structure does not exist
235 *
236 * ASSUMES THE PSS DESCRIPTOR IS LOCKED UPON ENTRY
237 */
238 RF_ReconParityStripeStatus_t *rf_LookupRUStatus(
239 RF_Raid_t *raidPtr,
240 RF_PSStatusHeader_t *pssTable,
241 RF_StripeNum_t psID,
242 RF_ReconUnitNum_t which_ru,
243 RF_PSSFlags_t flags, /* whether or not to create it if it doesn't exist + what flags to set initially */
244 int *created)
245 {
246 RF_PSStatusHeader_t *hdr = &pssTable[ RF_HASH_PSID(raidPtr,psID) ];
247 RF_ReconParityStripeStatus_t *p, *pssPtr = hdr->chain;
248
249 *created = 0;
250 for (p = pssPtr; p; p=p->next) {
251 if (p->parityStripeID == psID && p->which_ru == which_ru)
252 break;
253 }
254
255 if (!p && (flags&RF_PSS_CREATE)) {
256 Dprintf2("PSS: creating pss for psid %ld ru %d\n",psID,which_ru);
257 p = rf_AllocPSStatus(raidPtr);
258 p->next = hdr->chain; hdr->chain = p;
259
260 p->parityStripeID = psID;
261 p->which_ru = which_ru;
262 p->flags = flags;
263 p->rbuf = NULL;
264 p->writeRbuf = NULL;
265 p->blockCount = 0;
266 p->procWaitList = NULL;
267 p->blockWaitList = NULL;
268 p->bufWaitList = NULL;
269 *created = 1;
270 } else if (p) { /* we didn't create, but we want to specify some new status */
271 p->flags |= flags; /* add in whatever flags we're specifying */
272 }
273 if (p && (flags & RF_PSS_RECON_BLOCKED)) {
274 int tid;
275 rf_get_threadid(tid);
276 p->blockCount++; /* if we're asking to block recon, bump the count */
277 Dprintf3("[%d] Blocked recon on psid %ld. count now %d\n",tid,psID,p->blockCount);
278 }
279 return(p);
280 }
281
282 /* deletes an entry from the parity stripe status table. typically used
283 * when an entry has been allocated solely to block reconstruction, and
284 * no recon was requested while recon was blocked. Assumes the hash
285 * chain is ALREADY LOCKED.
286 */
287 void rf_PSStatusDelete(raidPtr, pssTable, pssPtr)
288 RF_Raid_t *raidPtr;
289 RF_PSStatusHeader_t *pssTable;
290 RF_ReconParityStripeStatus_t *pssPtr;
291 {
292 RF_PSStatusHeader_t *hdr = &(pssTable[ RF_HASH_PSID(raidPtr,pssPtr->parityStripeID) ] );
293 RF_ReconParityStripeStatus_t *p = hdr->chain, *pt = NULL;
294
295 while (p) {
296 if (p == pssPtr) {
297 if (pt) pt->next = p->next; else hdr->chain = p->next;
298 p->next = NULL;
299 rf_FreePSStatus(raidPtr, p);
300 return;
301 }
302 pt = p; p=p->next;
303 }
304 RF_ASSERT(0); /* we must find it here */
305 }
306
307 /* deletes an entry from the ps status table after reconstruction has completed */
308 void rf_RemoveFromActiveReconTable(raidPtr, row, psid, which_ru)
309 RF_Raid_t *raidPtr;
310 RF_RowCol_t row;
311 RF_ReconUnitNum_t which_ru;
312 RF_StripeNum_t psid;
313 {
314 RF_PSStatusHeader_t *hdr = &(raidPtr->reconControl[row]->pssTable[ RF_HASH_PSID(raidPtr,psid) ]);
315 RF_ReconParityStripeStatus_t *p, *pt;
316 RF_CallbackDesc_t *cb, *cb1;
317
318 RF_LOCK_MUTEX( hdr->mutex );
319 for (pt=NULL, p = hdr->chain; p; pt=p,p=p->next) {
320 if ((p->parityStripeID == psid) && (p->which_ru == which_ru))
321 break;
322 }
323 if (p == NULL) {
324 rf_PrintPSStatusTable(raidPtr, row);
325 }
326 RF_ASSERT(p); /* it must be there */
327
328 Dprintf2("PSS: deleting pss for psid %ld ru %d\n",psid,which_ru);
329
330 /* delete this entry from the hash chain */
331 if (pt) pt->next = p->next;
332 else hdr->chain = p->next;
333 p->next = NULL;
334
335 RF_UNLOCK_MUTEX( hdr->mutex );
336
337 /* wakup anyone waiting on the parity stripe ID */
338 cb = p->procWaitList;
339 p->procWaitList = NULL;
340 while (cb) {
341 Dprintf1("Waking up access waiting on parity stripe ID %ld\n",p->parityStripeID);
342 cb1 = cb->next;
343 (cb->callbackFunc)(cb->callbackArg);
344
345 /* THIS IS WHAT THE ORIGINAL CODE HAD... the extra 0 is bogus, IMHO */
346 /* (cb->callbackFunc)(cb->callbackArg, 0); */
347 rf_FreeCallbackDesc(cb);
348 cb = cb1;
349 }
350
351 rf_FreePSStatus(raidPtr, p);
352 }
353
354 RF_ReconParityStripeStatus_t *rf_AllocPSStatus(raidPtr)
355 RF_Raid_t *raidPtr;
356 {
357 RF_ReconParityStripeStatus_t *p;
358
359 RF_FREELIST_GET_INIT_ARG(raidPtr->pss_freelist,p,next,(RF_ReconParityStripeStatus_t *),init_pss,raidPtr);
360 if (p) {
361 bzero(p->issued, raidPtr->numCol);
362 }
363 p->next = NULL;
364 /* no need to initialize here b/c the only place we're called from is the above Lookup */
365 return(p);
366 }
367
368 void rf_FreePSStatus(raidPtr, p)
369 RF_Raid_t *raidPtr;
370 RF_ReconParityStripeStatus_t *p;
371 {
372 RF_ASSERT(p->procWaitList == NULL);
373 RF_ASSERT(p->blockWaitList == NULL);
374 RF_ASSERT(p->bufWaitList == NULL);
375
376 RF_FREELIST_FREE_CLEAN_ARG(raidPtr->pss_freelist,p,next,clean_pss,raidPtr);
377 }
378
379 static void RealPrintPSStatusTable(raidPtr, pssTable)
380 RF_Raid_t *raidPtr;
381 RF_PSStatusHeader_t *pssTable;
382 {
383 int i, j, procsWaiting, blocksWaiting, bufsWaiting;
384 RF_ReconParityStripeStatus_t *p;
385 RF_CallbackDesc_t *cb;
386
387 printf("\nParity Stripe Status Table\n");
388 for (i=0; i< raidPtr->pssTableSize; i++) {
389 for (p = pssTable[i].chain; p; p=p->next) {
390 procsWaiting = blocksWaiting = bufsWaiting = 0;
391 for (cb = p->procWaitList; cb; cb=cb->next) procsWaiting++;
392 for (cb = p->blockWaitList; cb; cb=cb->next) blocksWaiting++;
393 for (cb = p->bufWaitList; cb; cb=cb->next) bufsWaiting++;
394 printf("PSID %ld RU %d : blockCount %d %d/%d/%d proc/block/buf waiting, issued ",
395 (long)p->parityStripeID, p->which_ru, p->blockCount, procsWaiting, blocksWaiting, bufsWaiting);
396 for (j=0;j<raidPtr->numCol; j++) printf("%c", (p->issued[j]) ? '1' : '0');
397 if (!p->flags) printf(" flags: (none)");
398 else {
399 if (p->flags & RF_PSS_UNDER_RECON) printf(" under-recon");
400 if (p->flags & RF_PSS_FORCED_ON_WRITE) printf(" forced-w");
401 if (p->flags & RF_PSS_FORCED_ON_READ) printf(" forced-r");
402 if (p->flags & RF_PSS_RECON_BLOCKED) printf(" blocked");
403 if (p->flags & RF_PSS_BUFFERWAIT) printf(" bufwait");
404 }
405 printf("\n");
406 }
407 }
408 }
409
410 void rf_PrintPSStatusTable(raidPtr, row)
411 RF_Raid_t *raidPtr;
412 RF_RowCol_t row;
413 {
414 RF_PSStatusHeader_t *pssTable = raidPtr->reconControl[row]->pssTable;
415 RealPrintPSStatusTable(raidPtr, pssTable);
416 }
417