Home | History | Annotate | Line # | Download | only in raidframe
rf_psstatus.c revision 1.5.8.3
      1  1.5.8.3  jdolecek /*	$NetBSD: rf_psstatus.c,v 1.5.8.3 2002/10/10 18:41:55 jdolecek 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.5.8.2   thorpej #include <sys/cdefs.h>
     40  1.5.8.3  jdolecek __KERNEL_RCSID(0, "$NetBSD: rf_psstatus.c,v 1.5.8.3 2002/10/10 18:41:55 jdolecek Exp $");
     41  1.5.8.2   thorpej 
     42  1.5.8.2   thorpej #include <dev/raidframe/raidframevar.h>
     43  1.5.8.2   thorpej 
     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_freelist.h"
     48      1.1     oster #include "rf_psstatus.h"
     49      1.1     oster #include "rf_shutdown.h"
     50      1.1     oster 
     51  1.5.8.3  jdolecek #if RF_DEBUG_PSS
     52      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)
     53      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)
     54      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)
     55  1.5.8.3  jdolecek #else
     56  1.5.8.3  jdolecek #define Dprintf1(s,a)
     57  1.5.8.3  jdolecek #define Dprintf2(s,a,b)
     58  1.5.8.3  jdolecek #define Dprintf3(s,a,b,c)
     59  1.5.8.3  jdolecek #endif
     60      1.1     oster 
     61      1.3     oster static void
     62      1.3     oster RealPrintPSStatusTable(RF_Raid_t * raidPtr,
     63      1.3     oster     RF_PSStatusHeader_t * pssTable);
     64      1.1     oster 
     65      1.1     oster #define RF_MAX_FREE_PSS  32
     66      1.1     oster #define RF_PSS_INC        8
     67      1.1     oster #define RF_PSS_INITIAL    4
     68      1.1     oster 
     69      1.3     oster static int init_pss(RF_ReconParityStripeStatus_t *, RF_Raid_t *);
     70      1.1     oster static void clean_pss(RF_ReconParityStripeStatus_t *, RF_Raid_t *);
     71      1.1     oster static void rf_ShutdownPSStatus(void *);
     72      1.1     oster 
     73      1.3     oster static int
     74      1.3     oster init_pss(p, raidPtr)
     75      1.3     oster 	RF_ReconParityStripeStatus_t *p;
     76      1.3     oster 	RF_Raid_t *raidPtr;
     77      1.3     oster {
     78      1.3     oster 	RF_Calloc(p->issued, raidPtr->numCol, sizeof(char), (char *));
     79      1.3     oster 	if (p->issued == NULL)
     80      1.3     oster 		return (ENOMEM);
     81      1.3     oster 	return (0);
     82      1.3     oster }
     83      1.3     oster 
     84      1.3     oster static void
     85      1.3     oster clean_pss(p, raidPtr)
     86      1.3     oster 	RF_ReconParityStripeStatus_t *p;
     87      1.3     oster 	RF_Raid_t *raidPtr;
     88      1.3     oster {
     89      1.3     oster 	RF_Free(p->issued, raidPtr->numCol * sizeof(char));
     90      1.3     oster }
     91      1.3     oster 
     92      1.3     oster static void
     93      1.3     oster rf_ShutdownPSStatus(arg)
     94      1.3     oster 	void   *arg;
     95      1.3     oster {
     96      1.3     oster 	RF_Raid_t *raidPtr = (RF_Raid_t *) arg;
     97      1.3     oster 
     98      1.3     oster 	RF_FREELIST_DESTROY_CLEAN_ARG(raidPtr->pss_freelist, next, (RF_ReconParityStripeStatus_t *), clean_pss, raidPtr);
     99      1.3     oster }
    100      1.3     oster 
    101      1.3     oster int
    102      1.3     oster rf_ConfigurePSStatus(
    103      1.3     oster     RF_ShutdownList_t ** listp,
    104      1.3     oster     RF_Raid_t * raidPtr,
    105      1.3     oster     RF_Config_t * cfgPtr)
    106      1.3     oster {
    107      1.3     oster 	int     rc;
    108      1.3     oster 
    109      1.3     oster 	raidPtr->pssTableSize = RF_PSS_DEFAULT_TABLESIZE;
    110      1.3     oster 	RF_FREELIST_CREATE(raidPtr->pss_freelist, RF_MAX_FREE_PSS,
    111      1.3     oster 	    RF_PSS_INC, sizeof(RF_ReconParityStripeStatus_t));
    112      1.3     oster 	if (raidPtr->pss_freelist == NULL)
    113      1.3     oster 		return (ENOMEM);
    114      1.3     oster 	rc = rf_ShutdownCreate(listp, rf_ShutdownPSStatus, raidPtr);
    115      1.3     oster 	if (rc) {
    116  1.5.8.3  jdolecek 		rf_print_unable_to_add_shutdown(__FILE__, __LINE__, rc);
    117      1.3     oster 		rf_ShutdownPSStatus(raidPtr);
    118      1.3     oster 		return (rc);
    119      1.3     oster 	}
    120      1.3     oster 	RF_FREELIST_PRIME_INIT_ARG(raidPtr->pss_freelist, RF_PSS_INITIAL, next,
    121      1.3     oster 	    (RF_ReconParityStripeStatus_t *), init_pss, raidPtr);
    122      1.3     oster 	return (0);
    123      1.1     oster }
    124      1.1     oster /*****************************************************************************************
    125      1.1     oster  * sets up the pss table
    126      1.1     oster  * We pre-allocate a bunch of entries to avoid as much as possible having to
    127      1.1     oster  * malloc up hash chain entries.
    128      1.1     oster  ****************************************************************************************/
    129      1.3     oster RF_PSStatusHeader_t *
    130      1.3     oster rf_MakeParityStripeStatusTable(raidPtr)
    131      1.3     oster 	RF_Raid_t *raidPtr;
    132      1.3     oster {
    133      1.3     oster 	RF_PSStatusHeader_t *pssTable;
    134      1.3     oster 	int     i, j, rc;
    135      1.3     oster 
    136      1.3     oster 	RF_Calloc(pssTable, raidPtr->pssTableSize, sizeof(RF_PSStatusHeader_t), (RF_PSStatusHeader_t *));
    137      1.3     oster 	for (i = 0; i < raidPtr->pssTableSize; i++) {
    138      1.3     oster 		rc = rf_mutex_init(&pssTable[i].mutex);
    139      1.3     oster 		if (rc) {
    140  1.5.8.3  jdolecek 			rf_print_unable_to_init_mutex(__FILE__, __LINE__, rc);
    141      1.3     oster 			/* fail and deallocate */
    142      1.3     oster 			for (j = 0; j < i; j++) {
    143      1.3     oster 				rf_mutex_destroy(&pssTable[i].mutex);
    144      1.3     oster 			}
    145      1.3     oster 			RF_Free(pssTable, raidPtr->pssTableSize * sizeof(RF_PSStatusHeader_t));
    146      1.3     oster 			return (NULL);
    147      1.3     oster 		}
    148      1.3     oster 	}
    149      1.3     oster 	return (pssTable);
    150      1.3     oster }
    151      1.3     oster 
    152      1.3     oster void
    153      1.3     oster rf_FreeParityStripeStatusTable(raidPtr, pssTable)
    154      1.3     oster 	RF_Raid_t *raidPtr;
    155      1.3     oster 	RF_PSStatusHeader_t *pssTable;
    156      1.3     oster {
    157      1.3     oster 	int     i;
    158      1.3     oster 
    159  1.5.8.3  jdolecek #if RF_DEBUG_PSS
    160      1.3     oster 	if (rf_pssDebug)
    161      1.3     oster 		RealPrintPSStatusTable(raidPtr, pssTable);
    162  1.5.8.3  jdolecek #endif
    163      1.3     oster 	for (i = 0; i < raidPtr->pssTableSize; i++) {
    164      1.3     oster 		if (pssTable[i].chain) {
    165      1.3     oster 			printf("ERROR: pss hash chain not null at recon shutdown\n");
    166      1.3     oster 		}
    167      1.3     oster 		rf_mutex_destroy(&pssTable[i].mutex);
    168      1.3     oster 	}
    169      1.3     oster 	RF_Free(pssTable, raidPtr->pssTableSize * sizeof(RF_PSStatusHeader_t));
    170      1.1     oster }
    171      1.1     oster 
    172      1.1     oster 
    173      1.1     oster /* looks up the status structure for a parity stripe.
    174      1.1     oster  * if the create_flag is on, creates and returns the status structure it it doesn't exist
    175      1.1     oster  * otherwise returns NULL if the status structure does not exist
    176      1.1     oster  *
    177      1.1     oster  * ASSUMES THE PSS DESCRIPTOR IS LOCKED UPON ENTRY
    178      1.1     oster  */
    179      1.3     oster RF_ReconParityStripeStatus_t *
    180      1.3     oster rf_LookupRUStatus(
    181      1.3     oster     RF_Raid_t * raidPtr,
    182      1.3     oster     RF_PSStatusHeader_t * pssTable,
    183      1.3     oster     RF_StripeNum_t psID,
    184      1.3     oster     RF_ReconUnitNum_t which_ru,
    185      1.3     oster     RF_PSSFlags_t flags,	/* whether or not to create it if it doesn't
    186      1.3     oster 				 * exist + what flags to set initially */
    187      1.3     oster     int *created)
    188      1.3     oster {
    189      1.3     oster 	RF_PSStatusHeader_t *hdr = &pssTable[RF_HASH_PSID(raidPtr, psID)];
    190      1.3     oster 	RF_ReconParityStripeStatus_t *p, *pssPtr = hdr->chain;
    191      1.3     oster 
    192      1.3     oster 	*created = 0;
    193      1.3     oster 	for (p = pssPtr; p; p = p->next) {
    194      1.3     oster 		if (p->parityStripeID == psID && p->which_ru == which_ru)
    195      1.3     oster 			break;
    196      1.3     oster 	}
    197      1.3     oster 
    198      1.3     oster 	if (!p && (flags & RF_PSS_CREATE)) {
    199      1.3     oster 		Dprintf2("PSS: creating pss for psid %ld ru %d\n", psID, which_ru);
    200      1.3     oster 		p = rf_AllocPSStatus(raidPtr);
    201      1.3     oster 		p->next = hdr->chain;
    202      1.3     oster 		hdr->chain = p;
    203      1.3     oster 
    204      1.3     oster 		p->parityStripeID = psID;
    205      1.3     oster 		p->which_ru = which_ru;
    206      1.3     oster 		p->flags = flags;
    207      1.3     oster 		p->rbuf = NULL;
    208      1.3     oster 		p->writeRbuf = NULL;
    209      1.3     oster 		p->blockCount = 0;
    210      1.3     oster 		p->procWaitList = NULL;
    211      1.3     oster 		p->blockWaitList = NULL;
    212      1.3     oster 		p->bufWaitList = NULL;
    213      1.3     oster 		*created = 1;
    214      1.3     oster 	} else
    215      1.3     oster 		if (p) {	/* we didn't create, but we want to specify
    216      1.3     oster 				 * some new status */
    217      1.3     oster 			p->flags |= flags;	/* add in whatever flags we're
    218      1.3     oster 						 * specifying */
    219      1.3     oster 		}
    220      1.3     oster 	if (p && (flags & RF_PSS_RECON_BLOCKED)) {
    221      1.3     oster 		p->blockCount++;/* if we're asking to block recon, bump the
    222      1.3     oster 				 * count */
    223      1.5     oster 		Dprintf3("raid%d: Blocked recon on psid %ld.  count now %d\n",
    224      1.5     oster 			 raidPtr->raidid, psID, p->blockCount);
    225      1.3     oster 	}
    226      1.3     oster 	return (p);
    227      1.1     oster }
    228      1.1     oster /* deletes an entry from the parity stripe status table.  typically used
    229      1.1     oster  * when an entry has been allocated solely to block reconstruction, and
    230      1.1     oster  * no recon was requested while recon was blocked.  Assumes the hash
    231      1.1     oster  * chain is ALREADY LOCKED.
    232      1.1     oster  */
    233      1.3     oster void
    234      1.3     oster rf_PSStatusDelete(raidPtr, pssTable, pssPtr)
    235      1.3     oster 	RF_Raid_t *raidPtr;
    236      1.3     oster 	RF_PSStatusHeader_t *pssTable;
    237      1.3     oster 	RF_ReconParityStripeStatus_t *pssPtr;
    238      1.3     oster {
    239      1.3     oster 	RF_PSStatusHeader_t *hdr = &(pssTable[RF_HASH_PSID(raidPtr, pssPtr->parityStripeID)]);
    240      1.3     oster 	RF_ReconParityStripeStatus_t *p = hdr->chain, *pt = NULL;
    241      1.3     oster 
    242      1.3     oster 	while (p) {
    243      1.3     oster 		if (p == pssPtr) {
    244      1.3     oster 			if (pt)
    245      1.3     oster 				pt->next = p->next;
    246      1.3     oster 			else
    247      1.3     oster 				hdr->chain = p->next;
    248      1.3     oster 			p->next = NULL;
    249      1.3     oster 			rf_FreePSStatus(raidPtr, p);
    250      1.3     oster 			return;
    251      1.3     oster 		}
    252      1.3     oster 		pt = p;
    253      1.3     oster 		p = p->next;
    254      1.3     oster 	}
    255      1.3     oster 	RF_ASSERT(0);		/* we must find it here */
    256      1.1     oster }
    257      1.1     oster /* deletes an entry from the ps status table after reconstruction has completed */
    258      1.3     oster void
    259      1.3     oster rf_RemoveFromActiveReconTable(raidPtr, row, psid, which_ru)
    260      1.3     oster 	RF_Raid_t *raidPtr;
    261      1.3     oster 	RF_RowCol_t row;
    262      1.3     oster 	RF_ReconUnitNum_t which_ru;
    263      1.3     oster 	RF_StripeNum_t psid;
    264      1.3     oster {
    265      1.3     oster 	RF_PSStatusHeader_t *hdr = &(raidPtr->reconControl[row]->pssTable[RF_HASH_PSID(raidPtr, psid)]);
    266      1.3     oster 	RF_ReconParityStripeStatus_t *p, *pt;
    267      1.3     oster 	RF_CallbackDesc_t *cb, *cb1;
    268      1.3     oster 
    269      1.3     oster 	RF_LOCK_MUTEX(hdr->mutex);
    270      1.3     oster 	for (pt = NULL, p = hdr->chain; p; pt = p, p = p->next) {
    271      1.3     oster 		if ((p->parityStripeID == psid) && (p->which_ru == which_ru))
    272      1.3     oster 			break;
    273      1.3     oster 	}
    274      1.3     oster 	if (p == NULL) {
    275      1.3     oster 		rf_PrintPSStatusTable(raidPtr, row);
    276      1.3     oster 	}
    277      1.3     oster 	RF_ASSERT(p);		/* it must be there */
    278      1.3     oster 
    279      1.3     oster 	Dprintf2("PSS: deleting pss for psid %ld ru %d\n", psid, which_ru);
    280      1.3     oster 
    281      1.3     oster 	/* delete this entry from the hash chain */
    282      1.3     oster 	if (pt)
    283      1.3     oster 		pt->next = p->next;
    284      1.3     oster 	else
    285      1.3     oster 		hdr->chain = p->next;
    286      1.3     oster 	p->next = NULL;
    287      1.3     oster 
    288      1.3     oster 	RF_UNLOCK_MUTEX(hdr->mutex);
    289      1.3     oster 
    290      1.3     oster 	/* wakup anyone waiting on the parity stripe ID */
    291      1.3     oster 	cb = p->procWaitList;
    292      1.3     oster 	p->procWaitList = NULL;
    293      1.3     oster 	while (cb) {
    294      1.3     oster 		Dprintf1("Waking up access waiting on parity stripe ID %ld\n", p->parityStripeID);
    295      1.3     oster 		cb1 = cb->next;
    296      1.3     oster 		(cb->callbackFunc) (cb->callbackArg);
    297      1.3     oster 
    298      1.3     oster 		/* THIS IS WHAT THE ORIGINAL CODE HAD... the extra 0 is bogus,
    299      1.3     oster 		 * IMHO */
    300      1.3     oster 		/* (cb->callbackFunc)(cb->callbackArg, 0); */
    301      1.3     oster 		rf_FreeCallbackDesc(cb);
    302      1.3     oster 		cb = cb1;
    303      1.3     oster 	}
    304      1.3     oster 
    305      1.3     oster 	rf_FreePSStatus(raidPtr, p);
    306      1.3     oster }
    307      1.3     oster 
    308      1.3     oster RF_ReconParityStripeStatus_t *
    309      1.3     oster rf_AllocPSStatus(raidPtr)
    310      1.3     oster 	RF_Raid_t *raidPtr;
    311      1.3     oster {
    312      1.3     oster 	RF_ReconParityStripeStatus_t *p;
    313      1.3     oster 
    314      1.3     oster 	RF_FREELIST_GET_INIT_ARG(raidPtr->pss_freelist, p, next, (RF_ReconParityStripeStatus_t *), init_pss, raidPtr);
    315      1.3     oster 	if (p) {
    316  1.5.8.1     lukem 		memset(p->issued, 0, raidPtr->numCol);
    317      1.3     oster 	}
    318      1.3     oster 	p->next = NULL;
    319      1.3     oster 	/* no need to initialize here b/c the only place we're called from is
    320      1.3     oster 	 * the above Lookup */
    321      1.3     oster 	return (p);
    322      1.3     oster }
    323      1.3     oster 
    324      1.3     oster void
    325      1.3     oster rf_FreePSStatus(raidPtr, p)
    326      1.3     oster 	RF_Raid_t *raidPtr;
    327      1.3     oster 	RF_ReconParityStripeStatus_t *p;
    328      1.3     oster {
    329      1.3     oster 	RF_ASSERT(p->procWaitList == NULL);
    330      1.3     oster 	RF_ASSERT(p->blockWaitList == NULL);
    331      1.3     oster 	RF_ASSERT(p->bufWaitList == NULL);
    332      1.3     oster 
    333      1.3     oster 	RF_FREELIST_FREE_CLEAN_ARG(raidPtr->pss_freelist, p, next, clean_pss, raidPtr);
    334      1.3     oster }
    335      1.3     oster 
    336      1.3     oster static void
    337      1.3     oster RealPrintPSStatusTable(raidPtr, pssTable)
    338      1.3     oster 	RF_Raid_t *raidPtr;
    339      1.3     oster 	RF_PSStatusHeader_t *pssTable;
    340      1.3     oster {
    341      1.3     oster 	int     i, j, procsWaiting, blocksWaiting, bufsWaiting;
    342      1.3     oster 	RF_ReconParityStripeStatus_t *p;
    343      1.3     oster 	RF_CallbackDesc_t *cb;
    344      1.3     oster 
    345      1.3     oster 	printf("\nParity Stripe Status Table\n");
    346      1.3     oster 	for (i = 0; i < raidPtr->pssTableSize; i++) {
    347      1.3     oster 		for (p = pssTable[i].chain; p; p = p->next) {
    348      1.3     oster 			procsWaiting = blocksWaiting = bufsWaiting = 0;
    349      1.3     oster 			for (cb = p->procWaitList; cb; cb = cb->next)
    350      1.3     oster 				procsWaiting++;
    351      1.3     oster 			for (cb = p->blockWaitList; cb; cb = cb->next)
    352      1.3     oster 				blocksWaiting++;
    353      1.3     oster 			for (cb = p->bufWaitList; cb; cb = cb->next)
    354      1.3     oster 				bufsWaiting++;
    355      1.3     oster 			printf("PSID %ld RU %d : blockCount %d %d/%d/%d proc/block/buf waiting, issued ",
    356      1.3     oster 			    (long) p->parityStripeID, p->which_ru, p->blockCount, procsWaiting, blocksWaiting, bufsWaiting);
    357      1.3     oster 			for (j = 0; j < raidPtr->numCol; j++)
    358      1.3     oster 				printf("%c", (p->issued[j]) ? '1' : '0');
    359      1.3     oster 			if (!p->flags)
    360      1.3     oster 				printf(" flags: (none)");
    361      1.3     oster 			else {
    362      1.3     oster 				if (p->flags & RF_PSS_UNDER_RECON)
    363      1.3     oster 					printf(" under-recon");
    364      1.3     oster 				if (p->flags & RF_PSS_FORCED_ON_WRITE)
    365      1.3     oster 					printf(" forced-w");
    366      1.3     oster 				if (p->flags & RF_PSS_FORCED_ON_READ)
    367      1.3     oster 					printf(" forced-r");
    368      1.3     oster 				if (p->flags & RF_PSS_RECON_BLOCKED)
    369      1.3     oster 					printf(" blocked");
    370      1.3     oster 				if (p->flags & RF_PSS_BUFFERWAIT)
    371      1.3     oster 					printf(" bufwait");
    372      1.3     oster 			}
    373      1.3     oster 			printf("\n");
    374      1.3     oster 		}
    375      1.3     oster 	}
    376      1.3     oster }
    377      1.3     oster 
    378      1.3     oster void
    379      1.3     oster rf_PrintPSStatusTable(raidPtr, row)
    380      1.3     oster 	RF_Raid_t *raidPtr;
    381      1.3     oster 	RF_RowCol_t row;
    382      1.1     oster {
    383      1.3     oster 	RF_PSStatusHeader_t *pssTable = raidPtr->reconControl[row]->pssTable;
    384      1.3     oster 	RealPrintPSStatusTable(raidPtr, pssTable);
    385      1.1     oster }
    386