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