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