Home | History | Annotate | Line # | Download | only in raidframe
rf_raid5.c revision 1.4
      1  1.4  oster /*	$NetBSD: rf_raid5.c,v 1.4 2000/01/08 22:57:30 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  *
     31  1.1  oster  * rf_raid5.c -- implements RAID Level 5
     32  1.1  oster  *
     33  1.1  oster  *****************************************************************************/
     34  1.1  oster 
     35  1.1  oster #include "rf_types.h"
     36  1.1  oster #include "rf_raid.h"
     37  1.1  oster #include "rf_raid5.h"
     38  1.1  oster #include "rf_dag.h"
     39  1.1  oster #include "rf_dagffrd.h"
     40  1.1  oster #include "rf_dagffwr.h"
     41  1.1  oster #include "rf_dagdegrd.h"
     42  1.1  oster #include "rf_dagdegwr.h"
     43  1.1  oster #include "rf_dagutils.h"
     44  1.1  oster #include "rf_general.h"
     45  1.1  oster #include "rf_map.h"
     46  1.1  oster #include "rf_utils.h"
     47  1.1  oster 
     48  1.1  oster typedef struct RF_Raid5ConfigInfo_s {
     49  1.3  oster 	RF_RowCol_t **stripeIdentifier;	/* filled in at config time and used
     50  1.3  oster 					 * by IdentifyStripe */
     51  1.3  oster }       RF_Raid5ConfigInfo_t;
     52  1.3  oster 
     53  1.3  oster int
     54  1.3  oster rf_ConfigureRAID5(
     55  1.3  oster     RF_ShutdownList_t ** listp,
     56  1.3  oster     RF_Raid_t * raidPtr,
     57  1.3  oster     RF_Config_t * cfgPtr)
     58  1.3  oster {
     59  1.3  oster 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
     60  1.3  oster 	RF_Raid5ConfigInfo_t *info;
     61  1.3  oster 	RF_RowCol_t i, j, startdisk;
     62  1.3  oster 
     63  1.3  oster 	/* create a RAID level 5 configuration structure */
     64  1.3  oster 	RF_MallocAndAdd(info, sizeof(RF_Raid5ConfigInfo_t), (RF_Raid5ConfigInfo_t *), raidPtr->cleanupList);
     65  1.3  oster 	if (info == NULL)
     66  1.3  oster 		return (ENOMEM);
     67  1.3  oster 	layoutPtr->layoutSpecificInfo = (void *) info;
     68  1.3  oster 
     69  1.3  oster 	RF_ASSERT(raidPtr->numRow == 1);
     70  1.3  oster 
     71  1.3  oster 	/* the stripe identifier must identify the disks in each stripe, IN
     72  1.3  oster 	 * THE ORDER THAT THEY APPEAR IN THE STRIPE. */
     73  1.3  oster 	info->stripeIdentifier = rf_make_2d_array(raidPtr->numCol, raidPtr->numCol, raidPtr->cleanupList);
     74  1.3  oster 	if (info->stripeIdentifier == NULL)
     75  1.3  oster 		return (ENOMEM);
     76  1.3  oster 	startdisk = 0;
     77  1.3  oster 	for (i = 0; i < raidPtr->numCol; i++) {
     78  1.3  oster 		for (j = 0; j < raidPtr->numCol; j++) {
     79  1.3  oster 			info->stripeIdentifier[i][j] = (startdisk + j) % raidPtr->numCol;
     80  1.3  oster 		}
     81  1.3  oster 		if ((--startdisk) < 0)
     82  1.3  oster 			startdisk = raidPtr->numCol - 1;
     83  1.3  oster 	}
     84  1.1  oster 
     85  1.3  oster 	/* fill in the remaining layout parameters */
     86  1.3  oster 	layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk;
     87  1.3  oster 	layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit << raidPtr->logBytesPerSector;
     88  1.3  oster 	layoutPtr->numDataCol = raidPtr->numCol - 1;
     89  1.3  oster 	layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
     90  1.3  oster 	layoutPtr->numParityCol = 1;
     91  1.3  oster 	layoutPtr->dataStripeUnitsPerDisk = layoutPtr->stripeUnitsPerDisk;
     92  1.1  oster 
     93  1.3  oster 	raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
     94  1.1  oster 
     95  1.3  oster 	return (0);
     96  1.1  oster }
     97  1.1  oster 
     98  1.3  oster int
     99  1.3  oster rf_GetDefaultNumFloatingReconBuffersRAID5(RF_Raid_t * raidPtr)
    100  1.1  oster {
    101  1.3  oster 	return (20);
    102  1.1  oster }
    103  1.1  oster 
    104  1.3  oster RF_HeadSepLimit_t
    105  1.3  oster rf_GetDefaultHeadSepLimitRAID5(RF_Raid_t * raidPtr)
    106  1.1  oster {
    107  1.3  oster 	return (10);
    108  1.1  oster }
    109  1.1  oster #if !defined(__NetBSD__) && !defined(_KERNEL)
    110  1.1  oster /* not currently used */
    111  1.3  oster int
    112  1.3  oster rf_ShutdownRAID5(RF_Raid_t * raidPtr)
    113  1.1  oster {
    114  1.3  oster 	return (0);
    115  1.1  oster }
    116  1.1  oster #endif
    117  1.1  oster 
    118  1.3  oster void
    119  1.3  oster rf_MapSectorRAID5(
    120  1.3  oster     RF_Raid_t * raidPtr,
    121  1.3  oster     RF_RaidAddr_t raidSector,
    122  1.3  oster     RF_RowCol_t * row,
    123  1.3  oster     RF_RowCol_t * col,
    124  1.3  oster     RF_SectorNum_t * diskSector,
    125  1.3  oster     int remap)
    126  1.1  oster {
    127  1.3  oster 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    128  1.3  oster 	*row = 0;
    129  1.3  oster 	*col = (SUID % raidPtr->numCol);
    130  1.3  oster 	*diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
    131  1.3  oster 	    (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    132  1.1  oster }
    133  1.1  oster 
    134  1.3  oster void
    135  1.3  oster rf_MapParityRAID5(
    136  1.3  oster     RF_Raid_t * raidPtr,
    137  1.3  oster     RF_RaidAddr_t raidSector,
    138  1.3  oster     RF_RowCol_t * row,
    139  1.3  oster     RF_RowCol_t * col,
    140  1.3  oster     RF_SectorNum_t * diskSector,
    141  1.3  oster     int remap)
    142  1.1  oster {
    143  1.3  oster 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    144  1.3  oster 
    145  1.3  oster 	*row = 0;
    146  1.3  oster 	*col = raidPtr->Layout.numDataCol - (SUID / raidPtr->Layout.numDataCol) % raidPtr->numCol;
    147  1.3  oster 	*diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
    148  1.3  oster 	    (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    149  1.1  oster }
    150  1.1  oster 
    151  1.3  oster void
    152  1.3  oster rf_IdentifyStripeRAID5(
    153  1.3  oster     RF_Raid_t * raidPtr,
    154  1.3  oster     RF_RaidAddr_t addr,
    155  1.3  oster     RF_RowCol_t ** diskids,
    156  1.3  oster     RF_RowCol_t * outRow)
    157  1.1  oster {
    158  1.3  oster 	RF_StripeNum_t stripeID = rf_RaidAddressToStripeID(&raidPtr->Layout, addr);
    159  1.3  oster 	RF_Raid5ConfigInfo_t *info = (RF_Raid5ConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
    160  1.1  oster 
    161  1.3  oster 	*outRow = 0;
    162  1.3  oster 	*diskids = info->stripeIdentifier[stripeID % raidPtr->numCol];
    163  1.1  oster }
    164  1.1  oster 
    165  1.3  oster void
    166  1.3  oster rf_MapSIDToPSIDRAID5(
    167  1.3  oster     RF_RaidLayout_t * layoutPtr,
    168  1.3  oster     RF_StripeNum_t stripeID,
    169  1.3  oster     RF_StripeNum_t * psID,
    170  1.3  oster     RF_ReconUnitNum_t * which_ru)
    171  1.1  oster {
    172  1.3  oster 	*which_ru = 0;
    173  1.3  oster 	*psID = stripeID;
    174  1.1  oster }
    175  1.1  oster /* select an algorithm for performing an access.  Returns two pointers,
    176  1.1  oster  * one to a function that will return information about the DAG, and
    177  1.1  oster  * another to a function that will create the dag.
    178  1.1  oster  */
    179  1.3  oster void
    180  1.3  oster rf_RaidFiveDagSelect(
    181  1.3  oster     RF_Raid_t * raidPtr,
    182  1.3  oster     RF_IoType_t type,
    183  1.3  oster     RF_AccessStripeMap_t * asmap,
    184  1.3  oster     RF_VoidFuncPtr * createFunc)
    185  1.1  oster {
    186  1.3  oster 	RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
    187  1.3  oster 	RF_PhysDiskAddr_t *failedPDA = NULL;
    188  1.3  oster 	RF_RowCol_t frow, fcol;
    189  1.3  oster 	RF_RowStatus_t rstat;
    190  1.3  oster 	int     prior_recon;
    191  1.3  oster 
    192  1.3  oster 	RF_ASSERT(RF_IO_IS_R_OR_W(type));
    193  1.3  oster 
    194  1.3  oster 	if (asmap->numDataFailed + asmap->numParityFailed > 1) {
    195  1.3  oster 		RF_ERRORMSG("Multiple disks failed in a single group!  Aborting I/O operation.\n");
    196  1.3  oster 		 /* *infoFunc = */ *createFunc = NULL;
    197  1.3  oster 		return;
    198  1.3  oster 	} else
    199  1.3  oster 		if (asmap->numDataFailed + asmap->numParityFailed == 1) {
    200  1.3  oster 
    201  1.3  oster 			/* if under recon & already reconstructed, redirect
    202  1.3  oster 			 * the access to the spare drive and eliminate the
    203  1.3  oster 			 * failure indication */
    204  1.3  oster 			failedPDA = asmap->failedPDAs[0];
    205  1.3  oster 			frow = failedPDA->row;
    206  1.3  oster 			fcol = failedPDA->col;
    207  1.3  oster 			rstat = raidPtr->status[failedPDA->row];
    208  1.3  oster 			prior_recon = (rstat == rf_rs_reconfigured) || (
    209  1.3  oster 			    (rstat == rf_rs_reconstructing) ?
    210  1.3  oster 			    rf_CheckRUReconstructed(raidPtr->reconControl[frow]->reconMap, failedPDA->startSector) : 0
    211  1.3  oster 			    );
    212  1.3  oster 			if (prior_recon) {
    213  1.3  oster 				RF_RowCol_t or = failedPDA->row, oc = failedPDA->col;
    214  1.3  oster 				RF_SectorNum_t oo = failedPDA->startSector;
    215  1.3  oster 
    216  1.3  oster 				if (layoutPtr->map->flags & RF_DISTRIBUTE_SPARE) {	/* redirect to dist
    217  1.3  oster 											 * spare space */
    218  1.3  oster 
    219  1.3  oster 					if (failedPDA == asmap->parityInfo) {
    220  1.3  oster 
    221  1.3  oster 						/* parity has failed */
    222  1.3  oster 						(layoutPtr->map->MapParity) (raidPtr, failedPDA->raidAddress, &failedPDA->row,
    223  1.3  oster 						    &failedPDA->col, &failedPDA->startSector, RF_REMAP);
    224  1.3  oster 
    225  1.3  oster 						if (asmap->parityInfo->next) {	/* redir 2nd component,
    226  1.3  oster 										 * if any */
    227  1.3  oster 							RF_PhysDiskAddr_t *p = asmap->parityInfo->next;
    228  1.3  oster 							RF_SectorNum_t SUoffs = p->startSector % layoutPtr->sectorsPerStripeUnit;
    229  1.3  oster 							p->row = failedPDA->row;
    230  1.3  oster 							p->col = failedPDA->col;
    231  1.3  oster 							p->startSector = rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, failedPDA->startSector) +
    232  1.3  oster 							    SUoffs;	/* cheating:
    233  1.3  oster 									 * startSector is not
    234  1.3  oster 									 * really a RAID address */
    235  1.3  oster 						}
    236  1.3  oster 					} else
    237  1.3  oster 						if (asmap->parityInfo->next && failedPDA == asmap->parityInfo->next) {
    238  1.3  oster 							RF_ASSERT(0);	/* should not ever
    239  1.3  oster 									 * happen */
    240  1.3  oster 						} else {
    241  1.3  oster 
    242  1.3  oster 							/* data has failed */
    243  1.3  oster 							(layoutPtr->map->MapSector) (raidPtr, failedPDA->raidAddress, &failedPDA->row,
    244  1.3  oster 							    &failedPDA->col, &failedPDA->startSector, RF_REMAP);
    245  1.3  oster 
    246  1.3  oster 						}
    247  1.3  oster 
    248  1.3  oster 				} else {	/* redirect to dedicated spare
    249  1.3  oster 						 * space */
    250  1.3  oster 
    251  1.3  oster 					failedPDA->row = raidPtr->Disks[frow][fcol].spareRow;
    252  1.3  oster 					failedPDA->col = raidPtr->Disks[frow][fcol].spareCol;
    253  1.3  oster 
    254  1.3  oster 					/* the parity may have two distinct
    255  1.3  oster 					 * components, both of which may need
    256  1.3  oster 					 * to be redirected */
    257  1.3  oster 					if (asmap->parityInfo->next) {
    258  1.3  oster 						if (failedPDA == asmap->parityInfo) {
    259  1.3  oster 							failedPDA->next->row = failedPDA->row;
    260  1.3  oster 							failedPDA->next->col = failedPDA->col;
    261  1.3  oster 						} else
    262  1.3  oster 							if (failedPDA == asmap->parityInfo->next) {	/* paranoid:  should
    263  1.3  oster 													 * never occur */
    264  1.3  oster 								asmap->parityInfo->row = failedPDA->row;
    265  1.3  oster 								asmap->parityInfo->col = failedPDA->col;
    266  1.3  oster 							}
    267  1.3  oster 					}
    268  1.3  oster 				}
    269  1.3  oster 
    270  1.3  oster 				RF_ASSERT(failedPDA->col != -1);
    271  1.3  oster 
    272  1.3  oster 				if (rf_dagDebug || rf_mapDebug) {
    273  1.4  oster 					printf("raid%d: Redirected type '%c' r %d c %d o %ld -> r %d c %d o %ld\n",
    274  1.4  oster 					       raidPtr->raidid, type, or, oc,
    275  1.4  oster 					       (long) oo, failedPDA->row,
    276  1.4  oster 					       failedPDA->col,
    277  1.4  oster 					       (long) failedPDA->startSector);
    278  1.3  oster 				}
    279  1.3  oster 				asmap->numDataFailed = asmap->numParityFailed = 0;
    280  1.3  oster 			}
    281  1.3  oster 		}
    282  1.3  oster 	/* all dags begin/end with block/unblock node therefore, hdrSucc &
    283  1.3  oster 	 * termAnt counts should always be 1 also, these counts should not be
    284  1.3  oster 	 * visible outside dag creation routines - manipulating the counts
    285  1.3  oster 	 * here should be removed */
    286  1.3  oster 	if (type == RF_IO_TYPE_READ) {
    287  1.3  oster 		if (asmap->numDataFailed == 0)
    288  1.3  oster 			*createFunc = (RF_VoidFuncPtr) rf_CreateFaultFreeReadDAG;
    289  1.3  oster 		else
    290  1.3  oster 			*createFunc = (RF_VoidFuncPtr) rf_CreateRaidFiveDegradedReadDAG;
    291  1.1  oster 	} else {
    292  1.1  oster 
    293  1.1  oster 
    294  1.3  oster 		/* if mirroring, always use large writes.  If the access
    295  1.3  oster 		 * requires two distinct parity updates, always do a small
    296  1.3  oster 		 * write.  If the stripe contains a failure but the access
    297  1.3  oster 		 * does not, do a small write. The first conditional
    298  1.3  oster 		 * (numStripeUnitsAccessed <= numDataCol/2) uses a
    299  1.3  oster 		 * less-than-or-equal rather than just a less-than because
    300  1.3  oster 		 * when G is 3 or 4, numDataCol/2 is 1, and I want
    301  1.3  oster 		 * single-stripe-unit updates to use just one disk. */
    302  1.3  oster 		if ((asmap->numDataFailed + asmap->numParityFailed) == 0) {
    303  1.3  oster 			if (rf_suppressLocksAndLargeWrites ||
    304  1.3  oster 			    (((asmap->numStripeUnitsAccessed <= (layoutPtr->numDataCol / 2)) && (layoutPtr->numDataCol != 1)) ||
    305  1.3  oster 				(asmap->parityInfo->next != NULL) || rf_CheckStripeForFailures(raidPtr, asmap))) {
    306  1.3  oster 				*createFunc = (RF_VoidFuncPtr) rf_CreateSmallWriteDAG;
    307  1.3  oster 			} else
    308  1.3  oster 				*createFunc = (RF_VoidFuncPtr) rf_CreateLargeWriteDAG;
    309  1.3  oster 		} else {
    310  1.3  oster 			if (asmap->numParityFailed == 1)
    311  1.3  oster 				*createFunc = (RF_VoidFuncPtr) rf_CreateNonRedundantWriteDAG;
    312  1.3  oster 			else
    313  1.3  oster 				if (asmap->numStripeUnitsAccessed != 1 && failedPDA->numSector != layoutPtr->sectorsPerStripeUnit)
    314  1.3  oster 					*createFunc = NULL;
    315  1.3  oster 				else
    316  1.3  oster 					*createFunc = (RF_VoidFuncPtr) rf_CreateDegradedWriteDAG;
    317  1.3  oster 		}
    318  1.1  oster 	}
    319  1.1  oster }
    320