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