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