Home | History | Annotate | Line # | Download | only in raidframe
rf_map.c revision 1.23
      1  1.23    oster /*	$NetBSD: rf_map.c,v 1.23 2003/12/29 02:38:18 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  * map.c -- main code for mapping RAID addresses to physical disk addresses
     32   1.1    oster  *
     33   1.1    oster  **************************************************************************/
     34   1.9    lukem 
     35   1.9    lukem #include <sys/cdefs.h>
     36  1.23    oster __KERNEL_RCSID(0, "$NetBSD: rf_map.c,v 1.23 2003/12/29 02:38:18 oster Exp $");
     37   1.1    oster 
     38   1.7    oster #include <dev/raidframe/raidframevar.h>
     39   1.7    oster 
     40   1.1    oster #include "rf_threadstuff.h"
     41   1.1    oster #include "rf_raid.h"
     42   1.1    oster #include "rf_general.h"
     43   1.1    oster #include "rf_map.h"
     44   1.1    oster #include "rf_freelist.h"
     45   1.1    oster #include "rf_shutdown.h"
     46   1.1    oster 
     47   1.3    oster static void rf_FreePDAList(RF_PhysDiskAddr_t * start, RF_PhysDiskAddr_t * end, int count);
     48   1.3    oster static void
     49   1.3    oster rf_FreeASMList(RF_AccessStripeMap_t * start, RF_AccessStripeMap_t * end,
     50   1.3    oster     int count);
     51   1.1    oster 
     52  1.21    oster /***************************************************************************
     53   1.1    oster  *
     54  1.21    oster  * MapAccess -- main 1st order mapping routine.  Maps an access in the
     55  1.21    oster  * RAID address space to the corresponding set of physical disk
     56  1.21    oster  * addresses.  The result is returned as a list of AccessStripeMap
     57  1.21    oster  * structures, one per stripe accessed.  Each ASM structure contains a
     58  1.21    oster  * pointer to a list of PhysDiskAddr structures, which describe the
     59  1.21    oster  * physical locations touched by the user access.  Note that this routine
     60  1.21    oster  * returns only static mapping information, i.e. the list of physical
     61  1.21    oster  * addresses returned does not necessarily identify the set of physical
     62  1.21    oster  * locations that will actually be read or written.  The routine also
     63  1.21    oster  * maps the parity.  The physical disk location returned always indicates
     64  1.21    oster  * the entire parity unit, even when only a subset of it is being
     65  1.21    oster  * accessed.  This is because an access that is not stripe unit aligned
     66  1.21    oster  * but that spans a stripe unit boundary may require access two distinct
     67  1.21    oster  * portions of the parity unit, and we can't yet tell which portion(s)
     68  1.21    oster  * we'll actually need.  We leave it up to the algorithm selection code
     69  1.21    oster  * to decide what subset of the parity unit to access.  Note that
     70  1.21    oster  * addresses in the RAID address space must always be maintained as
     71   1.1    oster  * longs, instead of ints.
     72  1.21    oster  *
     73   1.1    oster  * This routine returns NULL if numBlocks is 0
     74   1.1    oster  *
     75  1.21    oster  ***************************************************************************/
     76   1.1    oster 
     77   1.3    oster RF_AccessStripeMapHeader_t *
     78   1.3    oster rf_MapAccess(raidPtr, raidAddress, numBlocks, buffer, remap)
     79   1.3    oster 	RF_Raid_t *raidPtr;
     80   1.3    oster 	RF_RaidAddr_t raidAddress;	/* starting address in RAID address
     81   1.3    oster 					 * space */
     82   1.3    oster 	RF_SectorCount_t numBlocks;	/* number of blocks in RAID address
     83   1.3    oster 					 * space to access */
     84   1.3    oster 	caddr_t buffer;		/* buffer to supply/receive data */
     85   1.3    oster 	int     remap;		/* 1 => remap addresses to spare space */
     86   1.3    oster {
     87   1.3    oster 	RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
     88   1.3    oster 	RF_AccessStripeMapHeader_t *asm_hdr = NULL;
     89   1.3    oster 	RF_AccessStripeMap_t *asm_list = NULL, *asm_p = NULL;
     90   1.3    oster 	int     faultsTolerated = layoutPtr->map->faultsTolerated;
     91   1.3    oster 	RF_RaidAddr_t startAddress = raidAddress;	/* we'll change
     92   1.3    oster 							 * raidAddress along the
     93   1.3    oster 							 * way */
     94   1.3    oster 	RF_RaidAddr_t endAddress = raidAddress + numBlocks;
     95  1.23    oster 	RF_RaidDisk_t *disks = raidPtr->Disks;
     96   1.3    oster 
     97   1.3    oster 	RF_PhysDiskAddr_t *pda_p, *pda_q;
     98   1.3    oster 	RF_StripeCount_t numStripes = 0;
     99   1.3    oster 	RF_RaidAddr_t stripeRealEndAddress, stripeEndAddress, nextStripeUnitAddress;
    100   1.3    oster 	RF_RaidAddr_t startAddrWithinStripe, lastRaidAddr;
    101   1.3    oster 	RF_StripeCount_t totStripes;
    102   1.3    oster 	RF_StripeNum_t stripeID, lastSID, SUID, lastSUID;
    103   1.3    oster 	RF_AccessStripeMap_t *asmList, *t_asm;
    104   1.3    oster 	RF_PhysDiskAddr_t *pdaList, *t_pda;
    105   1.3    oster 
    106   1.3    oster 	/* allocate all the ASMs and PDAs up front */
    107   1.3    oster 	lastRaidAddr = raidAddress + numBlocks - 1;
    108   1.3    oster 	stripeID = rf_RaidAddressToStripeID(layoutPtr, raidAddress);
    109   1.3    oster 	lastSID = rf_RaidAddressToStripeID(layoutPtr, lastRaidAddr);
    110   1.3    oster 	totStripes = lastSID - stripeID + 1;
    111   1.3    oster 	SUID = rf_RaidAddressToStripeUnitID(layoutPtr, raidAddress);
    112   1.3    oster 	lastSUID = rf_RaidAddressToStripeUnitID(layoutPtr, lastRaidAddr);
    113   1.3    oster 
    114   1.3    oster 	asmList = rf_AllocASMList(totStripes);
    115   1.3    oster 	pdaList = rf_AllocPDAList(lastSUID - SUID + 1 + faultsTolerated * totStripes);	/* may also need pda(s)
    116   1.3    oster 											 * per stripe for parity */
    117   1.3    oster 
    118   1.3    oster 	if (raidAddress + numBlocks > raidPtr->totalSectors) {
    119   1.3    oster 		RF_ERRORMSG1("Unable to map access because offset (%d) was invalid\n",
    120   1.3    oster 		    (int) raidAddress);
    121   1.3    oster 		return (NULL);
    122   1.3    oster 	}
    123  1.15    oster #if RF_DEBUG_MAP
    124   1.3    oster 	if (rf_mapDebug)
    125   1.3    oster 		rf_PrintRaidAddressInfo(raidPtr, raidAddress, numBlocks);
    126  1.15    oster #endif
    127   1.3    oster 	for (; raidAddress < endAddress;) {
    128   1.3    oster 		/* make the next stripe structure */
    129   1.3    oster 		RF_ASSERT(asmList);
    130   1.3    oster 		t_asm = asmList;
    131   1.3    oster 		asmList = asmList->next;
    132   1.6  thorpej 		memset((char *) t_asm, 0, sizeof(RF_AccessStripeMap_t));
    133   1.3    oster 		if (!asm_p)
    134   1.3    oster 			asm_list = asm_p = t_asm;
    135   1.3    oster 		else {
    136   1.3    oster 			asm_p->next = t_asm;
    137   1.3    oster 			asm_p = asm_p->next;
    138   1.3    oster 		}
    139   1.3    oster 		numStripes++;
    140   1.3    oster 
    141   1.3    oster 		/* map SUs from current location to the end of the stripe */
    142   1.3    oster 		asm_p->stripeID =	/* rf_RaidAddressToStripeID(layoutPtr,
    143   1.3    oster 		        raidAddress) */ stripeID++;
    144   1.3    oster 		stripeRealEndAddress = rf_RaidAddressOfNextStripeBoundary(layoutPtr, raidAddress);
    145   1.3    oster 		stripeEndAddress = RF_MIN(endAddress, stripeRealEndAddress);
    146   1.3    oster 		asm_p->raidAddress = raidAddress;
    147   1.3    oster 		asm_p->endRaidAddress = stripeEndAddress;
    148   1.3    oster 
    149   1.3    oster 		/* map each stripe unit in the stripe */
    150   1.3    oster 		pda_p = NULL;
    151   1.3    oster 		startAddrWithinStripe = raidAddress;	/* Raid addr of start of
    152   1.3    oster 							 * portion of access
    153   1.3    oster 							 * that is within this
    154   1.3    oster 							 * stripe */
    155   1.3    oster 		for (; raidAddress < stripeEndAddress;) {
    156   1.3    oster 			RF_ASSERT(pdaList);
    157   1.3    oster 			t_pda = pdaList;
    158   1.3    oster 			pdaList = pdaList->next;
    159   1.6  thorpej 			memset((char *) t_pda, 0, sizeof(RF_PhysDiskAddr_t));
    160   1.3    oster 			if (!pda_p)
    161   1.3    oster 				asm_p->physInfo = pda_p = t_pda;
    162   1.3    oster 			else {
    163   1.3    oster 				pda_p->next = t_pda;
    164   1.3    oster 				pda_p = pda_p->next;
    165   1.3    oster 			}
    166   1.3    oster 
    167   1.3    oster 			pda_p->type = RF_PDA_TYPE_DATA;
    168  1.23    oster 			(layoutPtr->map->MapSector) (raidPtr, raidAddress, &(pda_p->col), &(pda_p->startSector), remap);
    169   1.3    oster 
    170   1.3    oster 			/* mark any failures we find.  failedPDA is don't-care
    171   1.3    oster 			 * if there is more than one failure */
    172   1.3    oster 			pda_p->raidAddress = raidAddress;	/* the RAID address
    173   1.3    oster 								 * corresponding to this
    174   1.3    oster 								 * physical disk address */
    175   1.3    oster 			nextStripeUnitAddress = rf_RaidAddressOfNextStripeUnitBoundary(layoutPtr, raidAddress);
    176   1.3    oster 			pda_p->numSector = RF_MIN(endAddress, nextStripeUnitAddress) - raidAddress;
    177   1.3    oster 			RF_ASSERT(pda_p->numSector != 0);
    178   1.3    oster 			rf_ASMCheckStatus(raidPtr, pda_p, asm_p, disks, 0);
    179   1.3    oster 			pda_p->bufPtr = buffer + rf_RaidAddressToByte(raidPtr, (raidAddress - startAddress));
    180   1.3    oster 			asm_p->totalSectorsAccessed += pda_p->numSector;
    181   1.3    oster 			asm_p->numStripeUnitsAccessed++;
    182   1.3    oster 
    183   1.3    oster 			raidAddress = RF_MIN(endAddress, nextStripeUnitAddress);
    184   1.3    oster 		}
    185   1.3    oster 
    186   1.3    oster 		/* Map the parity. At this stage, the startSector and
    187   1.3    oster 		 * numSector fields for the parity unit are always set to
    188   1.3    oster 		 * indicate the entire parity unit. We may modify this after
    189   1.3    oster 		 * mapping the data portion. */
    190   1.3    oster 		switch (faultsTolerated) {
    191   1.3    oster 		case 0:
    192   1.3    oster 			break;
    193   1.3    oster 		case 1:	/* single fault tolerant */
    194   1.3    oster 			RF_ASSERT(pdaList);
    195   1.3    oster 			t_pda = pdaList;
    196   1.3    oster 			pdaList = pdaList->next;
    197   1.6  thorpej 			memset((char *) t_pda, 0, sizeof(RF_PhysDiskAddr_t));
    198   1.3    oster 			pda_p = asm_p->parityInfo = t_pda;
    199   1.3    oster 			pda_p->type = RF_PDA_TYPE_PARITY;
    200   1.3    oster 			(layoutPtr->map->MapParity) (raidPtr, rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, startAddrWithinStripe),
    201  1.23    oster 			    &(pda_p->col), &(pda_p->startSector), remap);
    202   1.3    oster 			pda_p->numSector = layoutPtr->sectorsPerStripeUnit;
    203   1.3    oster 			/* raidAddr may be needed to find unit to redirect to */
    204   1.3    oster 			pda_p->raidAddress = rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, startAddrWithinStripe);
    205   1.3    oster 			rf_ASMCheckStatus(raidPtr, pda_p, asm_p, disks, 1);
    206   1.3    oster 			rf_ASMParityAdjust(asm_p->parityInfo, startAddrWithinStripe, endAddress, layoutPtr, asm_p);
    207   1.3    oster 
    208   1.3    oster 			break;
    209   1.3    oster 		case 2:	/* two fault tolerant */
    210   1.3    oster 			RF_ASSERT(pdaList && pdaList->next);
    211   1.3    oster 			t_pda = pdaList;
    212   1.3    oster 			pdaList = pdaList->next;
    213   1.6  thorpej 			memset((char *) t_pda, 0, sizeof(RF_PhysDiskAddr_t));
    214   1.3    oster 			pda_p = asm_p->parityInfo = t_pda;
    215   1.3    oster 			pda_p->type = RF_PDA_TYPE_PARITY;
    216   1.3    oster 			t_pda = pdaList;
    217   1.3    oster 			pdaList = pdaList->next;
    218   1.6  thorpej 			memset((char *) t_pda, 0, sizeof(RF_PhysDiskAddr_t));
    219   1.3    oster 			pda_q = asm_p->qInfo = t_pda;
    220   1.3    oster 			pda_q->type = RF_PDA_TYPE_Q;
    221   1.3    oster 			(layoutPtr->map->MapParity) (raidPtr, rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, startAddrWithinStripe),
    222  1.23    oster 			    &(pda_p->col), &(pda_p->startSector), remap);
    223   1.3    oster 			(layoutPtr->map->MapQ) (raidPtr, rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, startAddrWithinStripe),
    224  1.23    oster 			    &(pda_q->col), &(pda_q->startSector), remap);
    225   1.3    oster 			pda_q->numSector = pda_p->numSector = layoutPtr->sectorsPerStripeUnit;
    226   1.3    oster 			/* raidAddr may be needed to find unit to redirect to */
    227   1.3    oster 			pda_p->raidAddress = rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, startAddrWithinStripe);
    228   1.3    oster 			pda_q->raidAddress = rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, startAddrWithinStripe);
    229   1.3    oster 			/* failure mode stuff */
    230   1.3    oster 			rf_ASMCheckStatus(raidPtr, pda_p, asm_p, disks, 1);
    231   1.3    oster 			rf_ASMCheckStatus(raidPtr, pda_q, asm_p, disks, 1);
    232   1.3    oster 			rf_ASMParityAdjust(asm_p->parityInfo, startAddrWithinStripe, endAddress, layoutPtr, asm_p);
    233   1.3    oster 			rf_ASMParityAdjust(asm_p->qInfo, startAddrWithinStripe, endAddress, layoutPtr, asm_p);
    234   1.3    oster 			break;
    235   1.3    oster 		}
    236   1.3    oster 	}
    237   1.3    oster 	RF_ASSERT(asmList == NULL && pdaList == NULL);
    238   1.3    oster 	/* make the header structure */
    239   1.3    oster 	asm_hdr = rf_AllocAccessStripeMapHeader();
    240   1.3    oster 	RF_ASSERT(numStripes == totStripes);
    241   1.3    oster 	asm_hdr->numStripes = numStripes;
    242   1.3    oster 	asm_hdr->stripeMap = asm_list;
    243   1.3    oster 
    244  1.15    oster #if RF_DEBUG_MAP
    245   1.3    oster 	if (rf_mapDebug)
    246   1.3    oster 		rf_PrintAccessStripeMap(asm_hdr);
    247  1.15    oster #endif
    248   1.3    oster 	return (asm_hdr);
    249   1.1    oster }
    250  1.21    oster 
    251  1.21    oster /***************************************************************************
    252  1.21    oster  * This routine walks through an ASM list and marks the PDAs that have
    253  1.21    oster  * failed.  It's called only when a disk failure causes an in-flight
    254  1.21    oster  * DAG to fail.  The parity may consist of two components, but we want
    255  1.21    oster  * to use only one failedPDA pointer.  Thus we set failedPDA to point
    256  1.21    oster  * to the first parity component, and rely on the rest of the code to
    257  1.21    oster  * do the right thing with this.
    258  1.21    oster  ***************************************************************************/
    259   1.1    oster 
    260   1.3    oster void
    261   1.3    oster rf_MarkFailuresInASMList(raidPtr, asm_h)
    262   1.3    oster 	RF_Raid_t *raidPtr;
    263   1.3    oster 	RF_AccessStripeMapHeader_t *asm_h;
    264   1.3    oster {
    265  1.23    oster 	RF_RaidDisk_t *disks = raidPtr->Disks;
    266   1.3    oster 	RF_AccessStripeMap_t *asmap;
    267   1.3    oster 	RF_PhysDiskAddr_t *pda;
    268   1.3    oster 
    269   1.3    oster 	for (asmap = asm_h->stripeMap; asmap; asmap = asmap->next) {
    270   1.3    oster 		asmap->numDataFailed = asmap->numParityFailed = asmap->numQFailed = 0;
    271   1.3    oster 		asmap->numFailedPDAs = 0;
    272   1.6  thorpej 		memset((char *) asmap->failedPDAs, 0,
    273   1.3    oster 		    RF_MAX_FAILED_PDA * sizeof(RF_PhysDiskAddr_t *));
    274   1.3    oster 		for (pda = asmap->physInfo; pda; pda = pda->next) {
    275  1.23    oster 			if (RF_DEAD_DISK(disks[pda->col].status)) {
    276   1.3    oster 				asmap->numDataFailed++;
    277   1.3    oster 				asmap->failedPDAs[asmap->numFailedPDAs] = pda;
    278   1.3    oster 				asmap->numFailedPDAs++;
    279   1.3    oster 			}
    280   1.3    oster 		}
    281   1.3    oster 		pda = asmap->parityInfo;
    282  1.23    oster 		if (pda && RF_DEAD_DISK(disks[pda->col].status)) {
    283   1.3    oster 			asmap->numParityFailed++;
    284   1.3    oster 			asmap->failedPDAs[asmap->numFailedPDAs] = pda;
    285   1.3    oster 			asmap->numFailedPDAs++;
    286   1.3    oster 		}
    287   1.3    oster 		pda = asmap->qInfo;
    288  1.23    oster 		if (pda && RF_DEAD_DISK(disks[pda->col].status)) {
    289   1.3    oster 			asmap->numQFailed++;
    290   1.3    oster 			asmap->failedPDAs[asmap->numFailedPDAs] = pda;
    291   1.3    oster 			asmap->numFailedPDAs++;
    292   1.3    oster 		}
    293   1.3    oster 	}
    294   1.1    oster }
    295   1.3    oster 
    296  1.21    oster /***************************************************************************
    297   1.1    oster  *
    298  1.21    oster  * routines to allocate and free list elements.  All allocation
    299  1.21    oster  * routines zero the structure before returning it.
    300   1.1    oster  *
    301  1.21    oster  * FreePhysDiskAddr is static.  It should never be called directly,
    302  1.21    oster  * because FreeAccessStripeMap takes care of freeing the PhysDiskAddr
    303  1.21    oster  * list.
    304   1.1    oster  *
    305  1.21    oster  ***************************************************************************/
    306   1.1    oster 
    307   1.1    oster static RF_FreeList_t *rf_asmhdr_freelist;
    308   1.1    oster #define RF_MAX_FREE_ASMHDR 128
    309   1.1    oster #define RF_ASMHDR_INC       16
    310   1.1    oster #define RF_ASMHDR_INITIAL   32
    311   1.1    oster 
    312   1.1    oster static RF_FreeList_t *rf_asm_freelist;
    313   1.1    oster #define RF_MAX_FREE_ASM 192
    314   1.1    oster #define RF_ASM_INC       24
    315   1.1    oster #define RF_ASM_INITIAL   64
    316   1.1    oster 
    317   1.1    oster static RF_FreeList_t *rf_pda_freelist;
    318   1.1    oster #define RF_MAX_FREE_PDA 192
    319   1.1    oster #define RF_PDA_INC       24
    320   1.1    oster #define RF_PDA_INITIAL   64
    321   1.1    oster 
    322   1.1    oster /* called at shutdown time.  So far, all that is necessary is to release all the free lists */
    323   1.1    oster static void rf_ShutdownMapModule(void *);
    324   1.3    oster static void
    325   1.3    oster rf_ShutdownMapModule(ignored)
    326   1.3    oster 	void   *ignored;
    327   1.1    oster {
    328   1.3    oster 	RF_FREELIST_DESTROY(rf_asmhdr_freelist, next, (RF_AccessStripeMapHeader_t *));
    329   1.3    oster 	RF_FREELIST_DESTROY(rf_pda_freelist, next, (RF_PhysDiskAddr_t *));
    330   1.3    oster 	RF_FREELIST_DESTROY(rf_asm_freelist, next, (RF_AccessStripeMap_t *));
    331   1.1    oster }
    332   1.1    oster 
    333   1.3    oster int
    334   1.3    oster rf_ConfigureMapModule(listp)
    335   1.3    oster 	RF_ShutdownList_t **listp;
    336   1.1    oster {
    337   1.3    oster 	int     rc;
    338   1.1    oster 
    339   1.1    oster 	RF_FREELIST_CREATE(rf_asmhdr_freelist, RF_MAX_FREE_ASMHDR,
    340   1.3    oster 	    RF_ASMHDR_INC, sizeof(RF_AccessStripeMapHeader_t));
    341   1.1    oster 	if (rf_asmhdr_freelist == NULL) {
    342   1.3    oster 		return (ENOMEM);
    343   1.1    oster 	}
    344   1.1    oster 	RF_FREELIST_CREATE(rf_asm_freelist, RF_MAX_FREE_ASM,
    345   1.3    oster 	    RF_ASM_INC, sizeof(RF_AccessStripeMap_t));
    346   1.1    oster 	if (rf_asm_freelist == NULL) {
    347   1.3    oster 		RF_FREELIST_DESTROY(rf_asmhdr_freelist, next, (RF_AccessStripeMapHeader_t *));
    348   1.3    oster 		return (ENOMEM);
    349   1.1    oster 	}
    350   1.1    oster 	RF_FREELIST_CREATE(rf_pda_freelist, RF_MAX_FREE_PDA,
    351   1.3    oster 	    RF_PDA_INC, sizeof(RF_PhysDiskAddr_t));
    352   1.1    oster 	if (rf_pda_freelist == NULL) {
    353   1.3    oster 		RF_FREELIST_DESTROY(rf_asmhdr_freelist, next, (RF_AccessStripeMapHeader_t *));
    354  1.22    oster 		RF_FREELIST_DESTROY(rf_asm_freelist, next, (RF_AccessStripeMap_t *));
    355   1.3    oster 		return (ENOMEM);
    356   1.1    oster 	}
    357   1.1    oster 	rc = rf_ShutdownCreate(listp, rf_ShutdownMapModule, NULL);
    358   1.1    oster 	if (rc) {
    359  1.14    oster 		rf_print_unable_to_add_shutdown(__FILE__, __LINE__, rc);
    360   1.1    oster 		rf_ShutdownMapModule(NULL);
    361   1.3    oster 		return (rc);
    362   1.1    oster 	}
    363   1.3    oster 	RF_FREELIST_PRIME(rf_asmhdr_freelist, RF_ASMHDR_INITIAL, next,
    364   1.3    oster 	    (RF_AccessStripeMapHeader_t *));
    365   1.3    oster 	RF_FREELIST_PRIME(rf_asm_freelist, RF_ASM_INITIAL, next,
    366   1.3    oster 	    (RF_AccessStripeMap_t *));
    367   1.3    oster 	RF_FREELIST_PRIME(rf_pda_freelist, RF_PDA_INITIAL, next,
    368   1.3    oster 	    (RF_PhysDiskAddr_t *));
    369   1.1    oster 
    370   1.3    oster 	return (0);
    371   1.1    oster }
    372   1.1    oster 
    373   1.3    oster RF_AccessStripeMapHeader_t *
    374   1.3    oster rf_AllocAccessStripeMapHeader()
    375   1.1    oster {
    376   1.1    oster 	RF_AccessStripeMapHeader_t *p;
    377   1.1    oster 
    378   1.3    oster 	RF_FREELIST_GET(rf_asmhdr_freelist, p, next, (RF_AccessStripeMapHeader_t *));
    379   1.6  thorpej 	memset((char *) p, 0, sizeof(RF_AccessStripeMapHeader_t));
    380   1.1    oster 
    381   1.3    oster 	return (p);
    382   1.1    oster }
    383   1.1    oster 
    384   1.1    oster 
    385   1.3    oster void
    386   1.3    oster rf_FreeAccessStripeMapHeader(p)
    387   1.3    oster 	RF_AccessStripeMapHeader_t *p;
    388   1.1    oster {
    389   1.3    oster 	RF_FREELIST_FREE(rf_asmhdr_freelist, p, next);
    390   1.1    oster }
    391   1.1    oster 
    392   1.3    oster RF_PhysDiskAddr_t *
    393   1.3    oster rf_AllocPhysDiskAddr()
    394   1.1    oster {
    395   1.1    oster 	RF_PhysDiskAddr_t *p;
    396   1.1    oster 
    397   1.3    oster 	RF_FREELIST_GET(rf_pda_freelist, p, next, (RF_PhysDiskAddr_t *));
    398   1.6  thorpej 	memset((char *) p, 0, sizeof(RF_PhysDiskAddr_t));
    399   1.1    oster 
    400   1.3    oster 	return (p);
    401   1.1    oster }
    402   1.1    oster /* allocates a list of PDAs, locking the free list only once
    403   1.1    oster  * when we have to call calloc, we do it one component at a time to simplify
    404   1.1    oster  * the process of freeing the list at program shutdown.  This should not be
    405   1.1    oster  * much of a performance hit, because it should be very infrequently executed.
    406   1.1    oster  */
    407   1.3    oster RF_PhysDiskAddr_t *
    408   1.3    oster rf_AllocPDAList(count)
    409   1.3    oster 	int     count;
    410   1.1    oster {
    411   1.1    oster 	RF_PhysDiskAddr_t *p = NULL;
    412   1.1    oster 
    413   1.3    oster 	RF_FREELIST_GET_N(rf_pda_freelist, p, next, (RF_PhysDiskAddr_t *), count);
    414   1.3    oster 	return (p);
    415   1.1    oster }
    416   1.1    oster 
    417  1.18    oster #if RF_INCLUDE_PARITYLOGGING > 0
    418   1.3    oster void
    419   1.3    oster rf_FreePhysDiskAddr(p)
    420   1.3    oster 	RF_PhysDiskAddr_t *p;
    421   1.1    oster {
    422   1.3    oster 	RF_FREELIST_FREE(rf_pda_freelist, p, next);
    423   1.1    oster }
    424  1.18    oster #endif
    425   1.1    oster 
    426   1.3    oster static void
    427   1.3    oster rf_FreePDAList(l_start, l_end, count)
    428   1.3    oster 	RF_PhysDiskAddr_t *l_start, *l_end;	/* pointers to start and end
    429   1.3    oster 						 * of list */
    430   1.3    oster 	int     count;		/* number of elements in list */
    431   1.1    oster {
    432   1.3    oster 	RF_FREELIST_FREE_N(rf_pda_freelist, l_start, next, (RF_PhysDiskAddr_t *), count);
    433   1.1    oster }
    434   1.1    oster 
    435   1.1    oster /* this is essentially identical to AllocPDAList.  I should combine the two.
    436   1.1    oster  * when we have to call calloc, we do it one component at a time to simplify
    437   1.1    oster  * the process of freeing the list at program shutdown.  This should not be
    438   1.1    oster  * much of a performance hit, because it should be very infrequently executed.
    439   1.1    oster  */
    440   1.3    oster RF_AccessStripeMap_t *
    441   1.3    oster rf_AllocASMList(count)
    442   1.3    oster 	int     count;
    443   1.1    oster {
    444   1.1    oster 	RF_AccessStripeMap_t *p = NULL;
    445   1.1    oster 
    446   1.3    oster 	RF_FREELIST_GET_N(rf_asm_freelist, p, next, (RF_AccessStripeMap_t *), count);
    447   1.3    oster 	return (p);
    448   1.1    oster }
    449   1.1    oster 
    450   1.3    oster static void
    451   1.3    oster rf_FreeASMList(l_start, l_end, count)
    452   1.3    oster 	RF_AccessStripeMap_t *l_start, *l_end;
    453   1.3    oster 	int     count;
    454   1.3    oster {
    455   1.3    oster 	RF_FREELIST_FREE_N(rf_asm_freelist, l_start, next, (RF_AccessStripeMap_t *), count);
    456   1.3    oster }
    457   1.3    oster 
    458   1.3    oster void
    459   1.3    oster rf_FreeAccessStripeMap(hdr)
    460   1.3    oster 	RF_AccessStripeMapHeader_t *hdr;
    461   1.3    oster {
    462   1.3    oster 	RF_AccessStripeMap_t *p, *pt = NULL;
    463   1.3    oster 	RF_PhysDiskAddr_t *pdp, *trailer, *pdaList = NULL, *pdaEnd = NULL;
    464   1.3    oster 	int     count = 0, t, asm_count = 0;
    465   1.3    oster 
    466   1.3    oster 	for (p = hdr->stripeMap; p; p = p->next) {
    467   1.3    oster 
    468   1.3    oster 		/* link the 3 pda lists into the accumulating pda list */
    469   1.3    oster 
    470   1.3    oster 		if (!pdaList)
    471   1.3    oster 			pdaList = p->qInfo;
    472   1.3    oster 		else
    473   1.3    oster 			pdaEnd->next = p->qInfo;
    474   1.3    oster 		for (trailer = NULL, pdp = p->qInfo; pdp;) {
    475   1.3    oster 			trailer = pdp;
    476   1.3    oster 			pdp = pdp->next;
    477   1.3    oster 			count++;
    478   1.3    oster 		}
    479   1.3    oster 		if (trailer)
    480   1.3    oster 			pdaEnd = trailer;
    481   1.3    oster 
    482   1.3    oster 		if (!pdaList)
    483   1.3    oster 			pdaList = p->parityInfo;
    484   1.3    oster 		else
    485   1.3    oster 			pdaEnd->next = p->parityInfo;
    486   1.3    oster 		for (trailer = NULL, pdp = p->parityInfo; pdp;) {
    487   1.3    oster 			trailer = pdp;
    488   1.3    oster 			pdp = pdp->next;
    489   1.3    oster 			count++;
    490   1.3    oster 		}
    491   1.3    oster 		if (trailer)
    492   1.3    oster 			pdaEnd = trailer;
    493   1.3    oster 
    494   1.3    oster 		if (!pdaList)
    495   1.3    oster 			pdaList = p->physInfo;
    496   1.3    oster 		else
    497   1.3    oster 			pdaEnd->next = p->physInfo;
    498   1.3    oster 		for (trailer = NULL, pdp = p->physInfo; pdp;) {
    499   1.3    oster 			trailer = pdp;
    500   1.3    oster 			pdp = pdp->next;
    501   1.3    oster 			count++;
    502   1.3    oster 		}
    503   1.3    oster 		if (trailer)
    504   1.3    oster 			pdaEnd = trailer;
    505   1.3    oster 
    506   1.3    oster 		pt = p;
    507   1.3    oster 		asm_count++;
    508   1.3    oster 	}
    509   1.3    oster 
    510   1.3    oster 	/* debug only */
    511   1.3    oster 	for (t = 0, pdp = pdaList; pdp; pdp = pdp->next)
    512   1.3    oster 		t++;
    513   1.3    oster 	RF_ASSERT(t == count);
    514   1.3    oster 
    515   1.3    oster 	if (pdaList)
    516   1.3    oster 		rf_FreePDAList(pdaList, pdaEnd, count);
    517   1.3    oster 	rf_FreeASMList(hdr->stripeMap, pt, asm_count);
    518   1.3    oster 	rf_FreeAccessStripeMapHeader(hdr);
    519   1.1    oster }
    520  1.21    oster /* We can't use the large write optimization if there are any failures
    521  1.21    oster  * in the stripe.  In the declustered layout, there is no way to
    522  1.21    oster  * immediately determine what disks constitute a stripe, so we
    523  1.21    oster  * actually have to hunt through the stripe looking for failures.  The
    524  1.21    oster  * reason we map the parity instead of just using asm->parityInfo->col
    525  1.21    oster  * is because the latter may have been already redirected to a spare
    526  1.21    oster  * drive, which would mess up the computation of the stripe offset.
    527   1.1    oster  *
    528  1.21    oster  * ASSUMES AT MOST ONE FAILURE IN THE STRIPE.  */
    529   1.3    oster int
    530   1.3    oster rf_CheckStripeForFailures(raidPtr, asmap)
    531   1.3    oster 	RF_Raid_t *raidPtr;
    532   1.3    oster 	RF_AccessStripeMap_t *asmap;
    533   1.3    oster {
    534  1.23    oster 	RF_RowCol_t tcol, pcol, *diskids, i;
    535   1.3    oster 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
    536   1.3    oster 	RF_StripeCount_t stripeOffset;
    537   1.3    oster 	int     numFailures;
    538   1.3    oster 	RF_RaidAddr_t sosAddr;
    539   1.3    oster 	RF_SectorNum_t diskOffset, poffset;
    540   1.3    oster 
    541   1.3    oster 	/* quick out in the fault-free case.  */
    542   1.3    oster 	RF_LOCK_MUTEX(raidPtr->mutex);
    543   1.3    oster 	numFailures = raidPtr->numFailures;
    544   1.3    oster 	RF_UNLOCK_MUTEX(raidPtr->mutex);
    545   1.3    oster 	if (numFailures == 0)
    546   1.3    oster 		return (0);
    547   1.3    oster 
    548   1.3    oster 	sosAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, asmap->raidAddress);
    549  1.23    oster 	(layoutPtr->map->IdentifyStripe) (raidPtr, asmap->raidAddress, &diskids);
    550  1.23    oster 	(layoutPtr->map->MapParity) (raidPtr, asmap->raidAddress, &pcol, &poffset, 0);	/* get pcol */
    551   1.3    oster 
    552   1.3    oster 	/* this need not be true if we've redirected the access to a spare in
    553   1.3    oster 	 * another row RF_ASSERT(row == testrow); */
    554   1.3    oster 	stripeOffset = 0;
    555   1.3    oster 	for (i = 0; i < layoutPtr->numDataCol + layoutPtr->numParityCol; i++) {
    556   1.3    oster 		if (diskids[i] != pcol) {
    557  1.23    oster 			if (RF_DEAD_DISK(raidPtr->Disks[diskids[i]].status)) {
    558  1.23    oster 				if (raidPtr->status != rf_rs_reconstructing)
    559   1.3    oster 					return (1);
    560  1.23    oster 				RF_ASSERT(raidPtr->reconControl->fcol == diskids[i]);
    561   1.3    oster 				layoutPtr->map->MapSector(raidPtr,
    562   1.3    oster 				    sosAddr + stripeOffset * layoutPtr->sectorsPerStripeUnit,
    563  1.23    oster 				    &tcol, &diskOffset, 0);
    564  1.23    oster 				RF_ASSERT(tcol == diskids[i]);
    565  1.23    oster 				if (!rf_CheckRUReconstructed(raidPtr->reconControl->reconMap, diskOffset))
    566   1.3    oster 					return (1);
    567   1.3    oster 				asmap->flags |= RF_ASM_REDIR_LARGE_WRITE;
    568   1.3    oster 				return (0);
    569   1.3    oster 			}
    570   1.3    oster 			stripeOffset++;
    571   1.3    oster 		}
    572   1.3    oster 	}
    573   1.3    oster 	return (0);
    574   1.1    oster }
    575  1.18    oster #if (RF_INCLUDE_DECL_PQ > 0) || (RF_INCLUDE_RAID6 > 0) || (RF_INCLUDE_EVENODD >0)
    576   1.1    oster /*
    577   1.1    oster    return the number of failed data units in the stripe.
    578   1.1    oster */
    579   1.1    oster 
    580   1.3    oster int
    581   1.3    oster rf_NumFailedDataUnitsInStripe(raidPtr, asmap)
    582   1.3    oster 	RF_Raid_t *raidPtr;
    583   1.3    oster 	RF_AccessStripeMap_t *asmap;
    584   1.3    oster {
    585   1.3    oster 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
    586  1.23    oster 	RF_RowCol_t tcol, i;
    587   1.3    oster 	RF_SectorNum_t diskOffset;
    588   1.3    oster 	RF_RaidAddr_t sosAddr;
    589   1.3    oster 	int     numFailures;
    590   1.3    oster 
    591   1.3    oster 	/* quick out in the fault-free case.  */
    592   1.3    oster 	RF_LOCK_MUTEX(raidPtr->mutex);
    593   1.3    oster 	numFailures = raidPtr->numFailures;
    594   1.3    oster 	RF_UNLOCK_MUTEX(raidPtr->mutex);
    595   1.3    oster 	if (numFailures == 0)
    596   1.3    oster 		return (0);
    597   1.3    oster 	numFailures = 0;
    598   1.3    oster 
    599   1.3    oster 	sosAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, asmap->raidAddress);
    600   1.3    oster 	for (i = 0; i < layoutPtr->numDataCol; i++) {
    601   1.3    oster 		(layoutPtr->map->MapSector) (raidPtr, sosAddr + i * layoutPtr->sectorsPerStripeUnit,
    602   1.3    oster 		    &trow, &tcol, &diskOffset, 0);
    603  1.23    oster 		if (RF_DEAD_DISK(raidPtr->Disks[tcol].status))
    604   1.3    oster 			numFailures++;
    605   1.3    oster 	}
    606   1.1    oster 
    607   1.3    oster 	return numFailures;
    608   1.1    oster }
    609  1.18    oster #endif
    610   1.1    oster 
    611   1.1    oster /*****************************************************************************************
    612   1.1    oster  *
    613   1.1    oster  * debug routines
    614   1.1    oster  *
    615   1.1    oster  ****************************************************************************************/
    616  1.18    oster #if RF_DEBUG_MAP
    617   1.3    oster void
    618   1.3    oster rf_PrintAccessStripeMap(asm_h)
    619   1.3    oster 	RF_AccessStripeMapHeader_t *asm_h;
    620   1.1    oster {
    621   1.3    oster 	rf_PrintFullAccessStripeMap(asm_h, 0);
    622   1.1    oster }
    623  1.18    oster #endif
    624   1.1    oster 
    625   1.3    oster void
    626   1.3    oster rf_PrintFullAccessStripeMap(asm_h, prbuf)
    627   1.3    oster 	RF_AccessStripeMapHeader_t *asm_h;
    628   1.3    oster 	int     prbuf;		/* flag to print buffer pointers */
    629   1.3    oster {
    630   1.3    oster 	int     i;
    631   1.3    oster 	RF_AccessStripeMap_t *asmap = asm_h->stripeMap;
    632   1.3    oster 	RF_PhysDiskAddr_t *p;
    633   1.3    oster 	printf("%d stripes total\n", (int) asm_h->numStripes);
    634   1.3    oster 	for (; asmap; asmap = asmap->next) {
    635   1.3    oster 		/* printf("Num failures: %d\n",asmap->numDataFailed); */
    636   1.3    oster 		/* printf("Num sectors:
    637   1.3    oster 		 * %d\n",(int)asmap->totalSectorsAccessed); */
    638   1.3    oster 		printf("Stripe %d (%d sectors), failures: %d data, %d parity: ",
    639   1.3    oster 		    (int) asmap->stripeID,
    640   1.3    oster 		    (int) asmap->totalSectorsAccessed,
    641   1.3    oster 		    (int) asmap->numDataFailed,
    642   1.3    oster 		    (int) asmap->numParityFailed);
    643   1.3    oster 		if (asmap->parityInfo) {
    644  1.23    oster 			printf("Parity [c%d s%d-%d", asmap->parityInfo->col,
    645   1.3    oster 			    (int) asmap->parityInfo->startSector,
    646   1.3    oster 			    (int) (asmap->parityInfo->startSector +
    647   1.3    oster 				asmap->parityInfo->numSector - 1));
    648   1.3    oster 			if (prbuf)
    649   1.3    oster 				printf(" b0x%lx", (unsigned long) asmap->parityInfo->bufPtr);
    650   1.3    oster 			if (asmap->parityInfo->next) {
    651  1.23    oster 				printf(", c%d s%d-%d", asmap->parityInfo->next->col,
    652   1.3    oster 				    (int) asmap->parityInfo->next->startSector,
    653   1.3    oster 				    (int) (asmap->parityInfo->next->startSector +
    654   1.3    oster 					asmap->parityInfo->next->numSector - 1));
    655   1.3    oster 				if (prbuf)
    656   1.3    oster 					printf(" b0x%lx", (unsigned long) asmap->parityInfo->next->bufPtr);
    657   1.3    oster 				RF_ASSERT(asmap->parityInfo->next->next == NULL);
    658   1.3    oster 			}
    659   1.3    oster 			printf("]\n\t");
    660   1.3    oster 		}
    661   1.3    oster 		for (i = 0, p = asmap->physInfo; p; p = p->next, i++) {
    662  1.23    oster 			printf("SU c%d s%d-%d ", p->col, (int) p->startSector,
    663   1.3    oster 			    (int) (p->startSector + p->numSector - 1));
    664   1.3    oster 			if (prbuf)
    665   1.3    oster 				printf("b0x%lx ", (unsigned long) p->bufPtr);
    666   1.3    oster 			if (i && !(i & 1))
    667   1.3    oster 				printf("\n\t");
    668   1.3    oster 		}
    669   1.3    oster 		printf("\n");
    670   1.3    oster 		p = asm_h->stripeMap->failedPDAs[0];
    671   1.3    oster 		if (asm_h->stripeMap->numDataFailed + asm_h->stripeMap->numParityFailed > 1)
    672   1.3    oster 			printf("[multiple failures]\n");
    673   1.3    oster 		else
    674   1.3    oster 			if (asm_h->stripeMap->numDataFailed + asm_h->stripeMap->numParityFailed > 0)
    675  1.23    oster 				printf("\t[Failed PDA: c%d s%d-%d]\n", p->col,
    676   1.3    oster 				    (int) p->startSector, (int) (p->startSector + p->numSector - 1));
    677   1.3    oster 	}
    678   1.1    oster }
    679   1.1    oster 
    680  1.15    oster #if RF_MAP_DEBUG
    681   1.3    oster void
    682   1.3    oster rf_PrintRaidAddressInfo(raidPtr, raidAddr, numBlocks)
    683   1.3    oster 	RF_Raid_t *raidPtr;
    684   1.3    oster 	RF_RaidAddr_t raidAddr;
    685   1.3    oster 	RF_SectorCount_t numBlocks;
    686   1.3    oster {
    687   1.3    oster 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
    688   1.3    oster 	RF_RaidAddr_t ra, sosAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, raidAddr);
    689   1.3    oster 
    690   1.3    oster 	printf("Raid addrs of SU boundaries from start of stripe to end of access:\n\t");
    691   1.3    oster 	for (ra = sosAddr; ra <= raidAddr + numBlocks; ra += layoutPtr->sectorsPerStripeUnit) {
    692   1.3    oster 		printf("%d (0x%x), ", (int) ra, (int) ra);
    693   1.3    oster 	}
    694   1.3    oster 	printf("\n");
    695   1.3    oster 	printf("Offset into stripe unit: %d (0x%x)\n",
    696   1.3    oster 	    (int) (raidAddr % layoutPtr->sectorsPerStripeUnit),
    697   1.3    oster 	    (int) (raidAddr % layoutPtr->sectorsPerStripeUnit));
    698   1.3    oster }
    699  1.15    oster #endif
    700   1.1    oster /*
    701   1.1    oster    given a parity descriptor and the starting address within a stripe,
    702   1.1    oster    range restrict the parity descriptor to touch only the correct stuff.
    703   1.1    oster */
    704   1.3    oster void
    705   1.3    oster rf_ASMParityAdjust(
    706   1.3    oster     RF_PhysDiskAddr_t * toAdjust,
    707   1.3    oster     RF_StripeNum_t startAddrWithinStripe,
    708   1.3    oster     RF_SectorNum_t endAddress,
    709   1.3    oster     RF_RaidLayout_t * layoutPtr,
    710   1.3    oster     RF_AccessStripeMap_t * asm_p)
    711   1.3    oster {
    712   1.3    oster 	RF_PhysDiskAddr_t *new_pda;
    713   1.3    oster 
    714   1.3    oster 	/* when we're accessing only a portion of one stripe unit, we want the
    715   1.3    oster 	 * parity descriptor to identify only the chunk of parity associated
    716   1.3    oster 	 * with the data.  When the access spans exactly one stripe unit
    717   1.3    oster 	 * boundary and is less than a stripe unit in size, it uses two
    718   1.3    oster 	 * disjoint regions of the parity unit.  When an access spans more
    719   1.3    oster 	 * than one stripe unit boundary, it uses all of the parity unit.
    720   1.3    oster 	 *
    721   1.3    oster 	 * To better handle the case where stripe units are small, we may
    722   1.3    oster 	 * eventually want to change the 2nd case so that if the SU size is
    723   1.3    oster 	 * below some threshold, we just read/write the whole thing instead of
    724   1.3    oster 	 * breaking it up into two accesses. */
    725   1.3    oster 	if (asm_p->numStripeUnitsAccessed == 1) {
    726   1.3    oster 		int     x = (startAddrWithinStripe % layoutPtr->sectorsPerStripeUnit);
    727   1.3    oster 		toAdjust->startSector += x;
    728   1.3    oster 		toAdjust->raidAddress += x;
    729   1.3    oster 		toAdjust->numSector = asm_p->physInfo->numSector;
    730   1.3    oster 		RF_ASSERT(toAdjust->numSector != 0);
    731   1.3    oster 	} else
    732   1.3    oster 		if (asm_p->numStripeUnitsAccessed == 2 && asm_p->totalSectorsAccessed < layoutPtr->sectorsPerStripeUnit) {
    733   1.3    oster 			int     x = (startAddrWithinStripe % layoutPtr->sectorsPerStripeUnit);
    734   1.3    oster 
    735   1.3    oster 			/* create a second pda and copy the parity map info
    736   1.3    oster 			 * into it */
    737   1.3    oster 			RF_ASSERT(toAdjust->next == NULL);
    738   1.3    oster 			new_pda = toAdjust->next = rf_AllocPhysDiskAddr();
    739   1.3    oster 			*new_pda = *toAdjust;	/* structure assignment */
    740   1.3    oster 			new_pda->next = NULL;
    741   1.3    oster 
    742   1.3    oster 			/* adjust the start sector & number of blocks for the
    743   1.3    oster 			 * first parity pda */
    744   1.3    oster 			toAdjust->startSector += x;
    745   1.3    oster 			toAdjust->raidAddress += x;
    746   1.3    oster 			toAdjust->numSector = rf_RaidAddressOfNextStripeUnitBoundary(layoutPtr, startAddrWithinStripe) - startAddrWithinStripe;
    747   1.3    oster 			RF_ASSERT(toAdjust->numSector != 0);
    748   1.3    oster 
    749   1.3    oster 			/* adjust the second pda */
    750   1.3    oster 			new_pda->numSector = endAddress - rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, endAddress);
    751   1.3    oster 			/* new_pda->raidAddress =
    752   1.3    oster 			 * rf_RaidAddressOfNextStripeUnitBoundary(layoutPtr,
    753   1.3    oster 			 * toAdjust->raidAddress); */
    754   1.3    oster 			RF_ASSERT(new_pda->numSector != 0);
    755   1.3    oster 		}
    756   1.1    oster }
    757  1.11    oster 
    758   1.1    oster /*
    759   1.1    oster    Check if a disk has been spared or failed. If spared,
    760   1.3    oster    redirect the I/O.
    761   1.1    oster    If it has been failed, record it in the asm pointer.
    762   1.1    oster    Fourth arg is whether data or parity.
    763   1.1    oster */
    764   1.3    oster void
    765   1.3    oster rf_ASMCheckStatus(
    766   1.3    oster     RF_Raid_t * raidPtr,
    767   1.3    oster     RF_PhysDiskAddr_t * pda_p,
    768   1.3    oster     RF_AccessStripeMap_t * asm_p,
    769  1.23    oster     RF_RaidDisk_t * disks,
    770   1.3    oster     int parity)
    771   1.3    oster {
    772   1.3    oster 	RF_DiskStatus_t dstatus;
    773  1.23    oster 	RF_RowCol_t fcol;
    774   1.3    oster 
    775  1.23    oster 	dstatus = disks[pda_p->col].status;
    776   1.3    oster 
    777   1.3    oster 	if (dstatus == rf_ds_spared) {
    778   1.3    oster 		/* if the disk has been spared, redirect access to the spare */
    779   1.3    oster 		fcol = pda_p->col;
    780  1.23    oster 		pda_p->col = disks[fcol].spareCol;
    781   1.3    oster 	} else
    782   1.3    oster 		if (dstatus == rf_ds_dist_spared) {
    783   1.3    oster 			/* ditto if disk has been spared to dist spare space */
    784  1.15    oster #if RF_DEBUG_MAP
    785  1.23    oster 			RF_RowCol_t oc = pda_p->col;
    786   1.3    oster 			RF_SectorNum_t oo = pda_p->startSector;
    787  1.15    oster #endif
    788   1.3    oster 			if (pda_p->type == RF_PDA_TYPE_DATA)
    789  1.23    oster 				raidPtr->Layout.map->MapSector(raidPtr, pda_p->raidAddress, &pda_p->col, &pda_p->startSector, RF_REMAP);
    790   1.3    oster 			else
    791  1.23    oster 				raidPtr->Layout.map->MapParity(raidPtr, pda_p->raidAddress, &pda_p->col, &pda_p->startSector, RF_REMAP);
    792   1.3    oster 
    793  1.15    oster #if RF_DEBUG_MAP
    794   1.3    oster 			if (rf_mapDebug) {
    795  1.23    oster 				printf("Redirected c %d o %d -> c %d o %d\n", oc, (int) oo,
    796  1.23    oster 				    pda_p->col, (int) pda_p->startSector);
    797   1.3    oster 			}
    798  1.15    oster #endif
    799   1.3    oster 		} else
    800   1.3    oster 			if (RF_DEAD_DISK(dstatus)) {
    801   1.3    oster 				/* if the disk is inaccessible, mark the
    802   1.3    oster 				 * failure */
    803   1.3    oster 				if (parity)
    804   1.3    oster 					asm_p->numParityFailed++;
    805   1.3    oster 				else {
    806   1.3    oster 					asm_p->numDataFailed++;
    807   1.3    oster 				}
    808   1.3    oster 				asm_p->failedPDAs[asm_p->numFailedPDAs] = pda_p;
    809   1.3    oster 				asm_p->numFailedPDAs++;
    810   1.1    oster #if 0
    811   1.3    oster 				switch (asm_p->numParityFailed + asm_p->numDataFailed) {
    812   1.3    oster 				case 1:
    813   1.3    oster 					asm_p->failedPDAs[0] = pda_p;
    814   1.3    oster 					break;
    815   1.3    oster 				case 2:
    816   1.3    oster 					asm_p->failedPDAs[1] = pda_p;
    817   1.3    oster 				default:
    818   1.3    oster 					break;
    819   1.3    oster 				}
    820   1.1    oster #endif
    821   1.3    oster 			}
    822   1.3    oster 	/* the redirected access should never span a stripe unit boundary */
    823   1.3    oster 	RF_ASSERT(rf_RaidAddressToStripeUnitID(&raidPtr->Layout, pda_p->raidAddress) ==
    824   1.3    oster 	    rf_RaidAddressToStripeUnitID(&raidPtr->Layout, pda_p->raidAddress + pda_p->numSector - 1));
    825   1.3    oster 	RF_ASSERT(pda_p->col != -1);
    826   1.1    oster }
    827