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