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