Home | History | Annotate | Line # | Download | only in raidframe
rf_reconutil.c revision 1.12
      1  1.12  oster /*	$NetBSD: rf_reconutil.c,v 1.12 2002/11/19 01:49:42 oster 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  * rf_reconutil.c -- reconstruction utilities
     31   1.1  oster  ********************************************/
     32   1.5  lukem 
     33   1.5  lukem #include <sys/cdefs.h>
     34  1.12  oster __KERNEL_RCSID(0, "$NetBSD: rf_reconutil.c,v 1.12 2002/11/19 01:49:42 oster Exp $");
     35   1.1  oster 
     36   1.4  oster #include <dev/raidframe/raidframevar.h>
     37   1.4  oster 
     38   1.1  oster #include "rf_raid.h"
     39   1.1  oster #include "rf_desc.h"
     40   1.1  oster #include "rf_reconutil.h"
     41   1.1  oster #include "rf_reconbuffer.h"
     42   1.1  oster #include "rf_general.h"
     43   1.1  oster #include "rf_decluster.h"
     44   1.1  oster #include "rf_raid5_rotatedspare.h"
     45   1.1  oster #include "rf_interdecluster.h"
     46   1.1  oster #include "rf_chaindecluster.h"
     47   1.1  oster 
     48   1.1  oster /*******************************************************************
     49   1.1  oster  * allocates/frees the reconstruction control information structures
     50   1.1  oster  *******************************************************************/
     51   1.3  oster RF_ReconCtrl_t *
     52   1.3  oster rf_MakeReconControl(reconDesc, frow, fcol, srow, scol)
     53   1.3  oster 	RF_RaidReconDesc_t *reconDesc;
     54   1.3  oster 	RF_RowCol_t frow;	/* failed row and column */
     55   1.3  oster 	RF_RowCol_t fcol;
     56   1.3  oster 	RF_RowCol_t srow;	/* identifies which spare we're using */
     57   1.3  oster 	RF_RowCol_t scol;
     58   1.1  oster {
     59   1.3  oster 	RF_Raid_t *raidPtr = reconDesc->raidPtr;
     60   1.3  oster 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
     61   1.3  oster 	RF_ReconUnitCount_t RUsPerPU = layoutPtr->SUsPerPU / layoutPtr->SUsPerRU;
     62   1.3  oster 	RF_ReconUnitCount_t numSpareRUs;
     63   1.3  oster 	RF_ReconCtrl_t *reconCtrlPtr;
     64   1.3  oster 	RF_ReconBuffer_t *rbuf;
     65   1.3  oster 	RF_LayoutSW_t *lp;
     66  1.12  oster #if (RF_INCLUDE_PARITY_DECLUSTERING_DS > 0)
     67  1.12  oster 	int     retcode;
     68  1.12  oster #endif
     69  1.12  oster 	int rc;
     70   1.3  oster 	RF_RowCol_t i;
     71   1.3  oster 
     72   1.3  oster 	lp = raidPtr->Layout.map;
     73   1.3  oster 
     74   1.3  oster 	/* make and zero the global reconstruction structure and the per-disk
     75   1.3  oster 	 * structure */
     76   1.3  oster 	RF_Calloc(reconCtrlPtr, 1, sizeof(RF_ReconCtrl_t), (RF_ReconCtrl_t *));
     77  1.11  oster 
     78  1.11  oster 	/* note: this zeros the perDiskInfo */
     79  1.11  oster 	RF_Calloc(reconCtrlPtr->perDiskInfo, raidPtr->numCol,
     80  1.11  oster 		  sizeof(RF_PerDiskReconCtrl_t), (RF_PerDiskReconCtrl_t *));
     81   1.3  oster 	reconCtrlPtr->reconDesc = reconDesc;
     82   1.3  oster 	reconCtrlPtr->fcol = fcol;
     83   1.3  oster 	reconCtrlPtr->spareRow = srow;
     84   1.3  oster 	reconCtrlPtr->spareCol = scol;
     85   1.3  oster 	reconCtrlPtr->lastPSID = layoutPtr->numStripe / layoutPtr->SUsPerPU;
     86   1.3  oster 	reconCtrlPtr->percentComplete = 0;
     87   1.3  oster 
     88   1.3  oster 	/* initialize each per-disk recon information structure */
     89   1.3  oster 	for (i = 0; i < raidPtr->numCol; i++) {
     90   1.3  oster 		reconCtrlPtr->perDiskInfo[i].reconCtrl = reconCtrlPtr;
     91   1.3  oster 		reconCtrlPtr->perDiskInfo[i].row = frow;
     92   1.3  oster 		reconCtrlPtr->perDiskInfo[i].col = i;
     93  1.11  oster 		/* make it appear as if we just finished an RU */
     94  1.11  oster 		reconCtrlPtr->perDiskInfo[i].curPSID = -1;
     95   1.3  oster 		reconCtrlPtr->perDiskInfo[i].ru_count = RUsPerPU - 1;
     96   1.3  oster 	}
     97   1.3  oster 
     98   1.3  oster 	/* Get the number of spare units per disk and the sparemap in case
     99   1.3  oster 	 * spare is distributed  */
    100   1.3  oster 
    101   1.3  oster 	if (lp->GetNumSpareRUs) {
    102   1.3  oster 		numSpareRUs = lp->GetNumSpareRUs(raidPtr);
    103   1.3  oster 	} else {
    104   1.3  oster 		numSpareRUs = 0;
    105   1.3  oster 	}
    106   1.3  oster 
    107  1.12  oster #if (RF_INCLUDE_PARITY_DECLUSTERING_DS > 0)
    108   1.3  oster 	/*
    109   1.3  oster          * Not all distributed sparing archs need dynamic mappings
    110   1.3  oster          */
    111   1.3  oster 	if (lp->InstallSpareTable) {
    112   1.3  oster 		retcode = rf_InstallSpareTable(raidPtr, frow, fcol);
    113   1.3  oster 		if (retcode) {
    114   1.3  oster 			RF_PANIC();	/* XXX fix this */
    115   1.3  oster 		}
    116   1.3  oster 	}
    117  1.12  oster #endif
    118   1.3  oster 	/* make the reconstruction map */
    119   1.3  oster 	reconCtrlPtr->reconMap = rf_MakeReconMap(raidPtr, (int) (layoutPtr->SUsPerRU * layoutPtr->sectorsPerStripeUnit),
    120   1.3  oster 	    raidPtr->sectorsPerDisk, numSpareRUs);
    121   1.3  oster 
    122   1.3  oster 	/* make the per-disk reconstruction buffers */
    123   1.3  oster 	for (i = 0; i < raidPtr->numCol; i++) {
    124   1.3  oster 		reconCtrlPtr->perDiskInfo[i].rbuf = (i == fcol) ? NULL : rf_MakeReconBuffer(raidPtr, frow, i, RF_RBUF_TYPE_EXCLUSIVE);
    125   1.3  oster 	}
    126   1.3  oster 
    127   1.3  oster 	/* initialize the event queue */
    128   1.3  oster 	rc = rf_mutex_init(&reconCtrlPtr->eq_mutex);
    129   1.3  oster 	if (rc) {
    130   1.3  oster 		/* XXX deallocate, cleanup */
    131   1.6  oster 		rf_print_unable_to_init_mutex(__FILE__, __LINE__, rc);
    132   1.3  oster 		return (NULL);
    133   1.3  oster 	}
    134   1.3  oster 	rc = rf_cond_init(&reconCtrlPtr->eq_cond);
    135   1.3  oster 	if (rc) {
    136   1.3  oster 		/* XXX deallocate, cleanup */
    137   1.6  oster 		rf_print_unable_to_init_cond(__FILE__, __LINE__, rc);
    138   1.3  oster 		return (NULL);
    139   1.3  oster 	}
    140   1.3  oster 	reconCtrlPtr->eventQueue = NULL;
    141   1.3  oster 	reconCtrlPtr->eq_count = 0;
    142   1.3  oster 
    143   1.3  oster 	/* make the floating recon buffers and append them to the free list */
    144   1.3  oster 	rc = rf_mutex_init(&reconCtrlPtr->rb_mutex);
    145   1.3  oster 	if (rc) {
    146   1.3  oster 		/* XXX deallocate, cleanup */
    147   1.6  oster 		rf_print_unable_to_init_mutex(__FILE__, __LINE__, rc);
    148   1.3  oster 		return (NULL);
    149   1.3  oster 	}
    150   1.3  oster 	reconCtrlPtr->fullBufferList = NULL;
    151   1.3  oster 	reconCtrlPtr->priorityList = NULL;
    152   1.3  oster 	reconCtrlPtr->floatingRbufs = NULL;
    153   1.3  oster 	reconCtrlPtr->committedRbufs = NULL;
    154   1.3  oster 	for (i = 0; i < raidPtr->numFloatingReconBufs; i++) {
    155  1.11  oster 		rbuf = rf_MakeReconBuffer(raidPtr, frow, fcol,
    156  1.11  oster 					  RF_RBUF_TYPE_FLOATING);
    157   1.3  oster 		rbuf->next = reconCtrlPtr->floatingRbufs;
    158   1.3  oster 		reconCtrlPtr->floatingRbufs = rbuf;
    159   1.3  oster 	}
    160   1.3  oster 
    161   1.3  oster 	/* create the parity stripe status table */
    162   1.3  oster 	reconCtrlPtr->pssTable = rf_MakeParityStripeStatusTable(raidPtr);
    163   1.3  oster 
    164   1.3  oster 	/* set the initial min head sep counter val */
    165   1.3  oster 	reconCtrlPtr->minHeadSepCounter = 0;
    166   1.3  oster 
    167   1.3  oster 	return (reconCtrlPtr);
    168   1.1  oster }
    169   1.1  oster 
    170   1.3  oster void
    171   1.3  oster rf_FreeReconControl(raidPtr, row)
    172   1.3  oster 	RF_Raid_t *raidPtr;
    173   1.3  oster 	RF_RowCol_t row;
    174   1.1  oster {
    175   1.3  oster 	RF_ReconCtrl_t *reconCtrlPtr = raidPtr->reconControl[row];
    176   1.3  oster 	RF_ReconBuffer_t *t;
    177   1.3  oster 	RF_ReconUnitNum_t i;
    178   1.3  oster 
    179   1.3  oster 	RF_ASSERT(reconCtrlPtr);
    180   1.3  oster 	for (i = 0; i < raidPtr->numCol; i++)
    181   1.3  oster 		if (reconCtrlPtr->perDiskInfo[i].rbuf)
    182   1.3  oster 			rf_FreeReconBuffer(reconCtrlPtr->perDiskInfo[i].rbuf);
    183   1.3  oster 	for (i = 0; i < raidPtr->numFloatingReconBufs; i++) {
    184   1.3  oster 		t = reconCtrlPtr->floatingRbufs;
    185   1.3  oster 		RF_ASSERT(t);
    186   1.3  oster 		reconCtrlPtr->floatingRbufs = t->next;
    187   1.3  oster 		rf_FreeReconBuffer(t);
    188   1.3  oster 	}
    189   1.3  oster 	rf_mutex_destroy(&reconCtrlPtr->rb_mutex);
    190   1.3  oster 	rf_mutex_destroy(&reconCtrlPtr->eq_mutex);
    191   1.3  oster 	rf_cond_destroy(&reconCtrlPtr->eq_cond);
    192   1.3  oster 	rf_FreeReconMap(reconCtrlPtr->reconMap);
    193   1.3  oster 	rf_FreeParityStripeStatusTable(raidPtr, reconCtrlPtr->pssTable);
    194  1.11  oster 	RF_Free(reconCtrlPtr->perDiskInfo,
    195  1.11  oster 		raidPtr->numCol * sizeof(RF_PerDiskReconCtrl_t));
    196   1.3  oster 	RF_Free(reconCtrlPtr, sizeof(*reconCtrlPtr));
    197   1.1  oster }
    198   1.1  oster 
    199   1.1  oster 
    200   1.1  oster /******************************************************************************
    201   1.1  oster  * computes the default head separation limit
    202   1.1  oster  *****************************************************************************/
    203   1.3  oster RF_HeadSepLimit_t
    204   1.3  oster rf_GetDefaultHeadSepLimit(raidPtr)
    205   1.3  oster 	RF_Raid_t *raidPtr;
    206   1.1  oster {
    207   1.3  oster 	RF_HeadSepLimit_t hsl;
    208   1.3  oster 	RF_LayoutSW_t *lp;
    209   1.1  oster 
    210   1.3  oster 	lp = raidPtr->Layout.map;
    211   1.3  oster 	if (lp->GetDefaultHeadSepLimit == NULL)
    212   1.3  oster 		return (-1);
    213   1.3  oster 	hsl = lp->GetDefaultHeadSepLimit(raidPtr);
    214   1.3  oster 	return (hsl);
    215   1.1  oster }
    216   1.1  oster 
    217   1.1  oster 
    218   1.1  oster /******************************************************************************
    219   1.1  oster  * computes the default number of floating recon buffers
    220   1.1  oster  *****************************************************************************/
    221   1.3  oster int
    222   1.3  oster rf_GetDefaultNumFloatingReconBuffers(raidPtr)
    223   1.3  oster 	RF_Raid_t *raidPtr;
    224   1.1  oster {
    225   1.3  oster 	RF_LayoutSW_t *lp;
    226   1.3  oster 	int     nrb;
    227   1.1  oster 
    228   1.3  oster 	lp = raidPtr->Layout.map;
    229   1.3  oster 	if (lp->GetDefaultNumFloatingReconBuffers == NULL)
    230   1.3  oster 		return (3 * raidPtr->numCol);
    231   1.3  oster 	nrb = lp->GetDefaultNumFloatingReconBuffers(raidPtr);
    232   1.3  oster 	return (nrb);
    233   1.1  oster }
    234   1.1  oster 
    235   1.1  oster 
    236   1.1  oster /******************************************************************************
    237   1.1  oster  * creates and initializes a reconstruction buffer
    238   1.1  oster  *****************************************************************************/
    239   1.3  oster RF_ReconBuffer_t *
    240   1.3  oster rf_MakeReconBuffer(
    241   1.3  oster     RF_Raid_t * raidPtr,
    242   1.3  oster     RF_RowCol_t row,
    243   1.3  oster     RF_RowCol_t col,
    244   1.3  oster     RF_RbufType_t type)
    245   1.1  oster {
    246   1.3  oster 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
    247   1.3  oster 	RF_ReconBuffer_t *t;
    248   1.3  oster 	u_int   recon_buffer_size = rf_RaidAddressToByte(raidPtr, layoutPtr->SUsPerRU * layoutPtr->sectorsPerStripeUnit);
    249   1.3  oster 
    250   1.3  oster 	RF_Malloc(t, sizeof(RF_ReconBuffer_t), (RF_ReconBuffer_t *));
    251   1.3  oster 	RF_Malloc(t->buffer, recon_buffer_size, (caddr_t));
    252   1.3  oster 	t->raidPtr = raidPtr;
    253   1.3  oster 	t->row = row;
    254   1.3  oster 	t->col = col;
    255   1.3  oster 	t->priority = RF_IO_RECON_PRIORITY;
    256   1.3  oster 	t->type = type;
    257   1.3  oster 	t->pssPtr = NULL;
    258   1.3  oster 	t->next = NULL;
    259   1.3  oster 	return (t);
    260   1.1  oster }
    261   1.1  oster /******************************************************************************
    262   1.1  oster  * frees a reconstruction buffer
    263   1.1  oster  *****************************************************************************/
    264   1.3  oster void
    265   1.3  oster rf_FreeReconBuffer(rbuf)
    266   1.3  oster 	RF_ReconBuffer_t *rbuf;
    267   1.1  oster {
    268   1.3  oster 	RF_Raid_t *raidPtr = rbuf->raidPtr;
    269   1.9  oster 	u_int   recon_buffer_size;
    270   1.9  oster 
    271   1.9  oster 	recon_buffer_size = rf_RaidAddressToByte(raidPtr, raidPtr->Layout.SUsPerRU * raidPtr->Layout.sectorsPerStripeUnit);
    272   1.3  oster 
    273   1.3  oster 	RF_Free(rbuf->buffer, recon_buffer_size);
    274   1.3  oster 	RF_Free(rbuf, sizeof(*rbuf));
    275   1.1  oster }
    276   1.1  oster 
    277  1.10  oster #if RF_DEBUG_RECON
    278   1.1  oster /******************************************************************************
    279   1.1  oster  * debug only:  sanity check the number of floating recon bufs in use
    280   1.1  oster  *****************************************************************************/
    281   1.3  oster void
    282   1.3  oster rf_CheckFloatingRbufCount(raidPtr, dolock)
    283   1.3  oster 	RF_Raid_t *raidPtr;
    284   1.3  oster 	int     dolock;
    285   1.1  oster {
    286   1.3  oster 	RF_ReconParityStripeStatus_t *p;
    287   1.3  oster 	RF_PSStatusHeader_t *pssTable;
    288   1.3  oster 	RF_ReconBuffer_t *rbuf;
    289   1.3  oster 	int     i, j, sum = 0;
    290   1.3  oster 	RF_RowCol_t frow = 0;
    291   1.3  oster 
    292   1.3  oster 	for (i = 0; i < raidPtr->numRow; i++)
    293   1.3  oster 		if (raidPtr->reconControl[i]) {
    294   1.3  oster 			frow = i;
    295   1.3  oster 			break;
    296   1.3  oster 		}
    297   1.3  oster 	RF_ASSERT(frow >= 0);
    298   1.3  oster 
    299   1.3  oster 	if (dolock)
    300   1.3  oster 		RF_LOCK_MUTEX(raidPtr->reconControl[frow]->rb_mutex);
    301   1.3  oster 	pssTable = raidPtr->reconControl[frow]->pssTable;
    302   1.3  oster 
    303   1.3  oster 	for (i = 0; i < raidPtr->pssTableSize; i++) {
    304   1.3  oster 		RF_LOCK_MUTEX(pssTable[i].mutex);
    305   1.3  oster 		for (p = pssTable[i].chain; p; p = p->next) {
    306   1.3  oster 			rbuf = (RF_ReconBuffer_t *) p->rbuf;
    307   1.3  oster 			if (rbuf && rbuf->type == RF_RBUF_TYPE_FLOATING)
    308   1.3  oster 				sum++;
    309   1.3  oster 
    310   1.3  oster 			rbuf = (RF_ReconBuffer_t *) p->writeRbuf;
    311   1.3  oster 			if (rbuf && rbuf->type == RF_RBUF_TYPE_FLOATING)
    312   1.3  oster 				sum++;
    313   1.3  oster 
    314   1.3  oster 			for (j = 0; j < p->xorBufCount; j++) {
    315   1.3  oster 				rbuf = (RF_ReconBuffer_t *) p->rbufsForXor[j];
    316   1.3  oster 				RF_ASSERT(rbuf);
    317   1.3  oster 				if (rbuf->type == RF_RBUF_TYPE_FLOATING)
    318   1.3  oster 					sum++;
    319   1.3  oster 			}
    320   1.3  oster 		}
    321   1.3  oster 		RF_UNLOCK_MUTEX(pssTable[i].mutex);
    322   1.3  oster 	}
    323   1.3  oster 
    324  1.11  oster 	for (rbuf = raidPtr->reconControl[frow]->floatingRbufs; rbuf;
    325  1.11  oster 	     rbuf = rbuf->next) {
    326   1.3  oster 		if (rbuf->type == RF_RBUF_TYPE_FLOATING)
    327   1.3  oster 			sum++;
    328   1.3  oster 	}
    329  1.11  oster 	for (rbuf = raidPtr->reconControl[frow]->committedRbufs; rbuf;
    330  1.11  oster 	     rbuf = rbuf->next) {
    331   1.3  oster 		if (rbuf->type == RF_RBUF_TYPE_FLOATING)
    332   1.3  oster 			sum++;
    333   1.3  oster 	}
    334  1.11  oster 	for (rbuf = raidPtr->reconControl[frow]->fullBufferList; rbuf;
    335  1.11  oster 	     rbuf = rbuf->next) {
    336   1.3  oster 		if (rbuf->type == RF_RBUF_TYPE_FLOATING)
    337   1.3  oster 			sum++;
    338   1.3  oster 	}
    339  1.11  oster 	for (rbuf = raidPtr->reconControl[frow]->priorityList; rbuf;
    340  1.11  oster 	     rbuf = rbuf->next) {
    341   1.3  oster 		if (rbuf->type == RF_RBUF_TYPE_FLOATING)
    342   1.3  oster 			sum++;
    343   1.3  oster 	}
    344   1.1  oster 
    345   1.3  oster 	RF_ASSERT(sum == raidPtr->numFloatingReconBufs);
    346   1.1  oster 
    347   1.3  oster 	if (dolock)
    348   1.3  oster 		RF_UNLOCK_MUTEX(raidPtr->reconControl[frow]->rb_mutex);
    349   1.1  oster }
    350   1.7  oster #endif
    351   1.7  oster 
    352