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