Home | History | Annotate | Line # | Download | only in raidframe
rf_raid5_rotatedspare.c revision 1.5
      1 /*	$NetBSD: rf_raid5_rotatedspare.c,v 1.5 2001/01/26 05:16:58 oster Exp $	*/
      2 /*
      3  * Copyright (c) 1995 Carnegie-Mellon University.
      4  * All rights reserved.
      5  *
      6  * Author: Khalil Amiri
      7  *
      8  * Permission to use, copy, modify and distribute this software and
      9  * its documentation is hereby granted, provided that both the copyright
     10  * notice and this permission notice appear in all copies of the
     11  * software, derivative works or modified versions, and any portions
     12  * thereof, and that both notices appear in supporting documentation.
     13  *
     14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     16  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17  *
     18  * Carnegie Mellon requests users of this software to return to
     19  *
     20  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21  *  School of Computer Science
     22  *  Carnegie Mellon University
     23  *  Pittsburgh PA 15213-3890
     24  *
     25  * any improvements or extensions that they make and grant Carnegie the
     26  * rights to redistribute these changes.
     27  */
     28 
     29 /**************************************************************************
     30  *
     31  * rf_raid5_rotated_spare.c -- implements RAID Level 5 with rotated sparing
     32  *
     33  **************************************************************************/
     34 
     35 #include "rf_archs.h"
     36 
     37 #if RF_INCLUDE_RAID5_RS > 0
     38 
     39 #include "rf_raid.h"
     40 #include "rf_raid5.h"
     41 #include "rf_dag.h"
     42 #include "rf_dagutils.h"
     43 #include "rf_dagfuncs.h"
     44 #include "rf_general.h"
     45 #include "rf_utils.h"
     46 #include "rf_raid5_rotatedspare.h"
     47 
     48 typedef struct RF_Raid5RSConfigInfo_s {
     49 	RF_RowCol_t **stripeIdentifier;	/* filled in at config time & used by
     50 					 * IdentifyStripe */
     51 }       RF_Raid5RSConfigInfo_t;
     52 
     53 int
     54 rf_ConfigureRAID5_RS(
     55     RF_ShutdownList_t ** listp,
     56     RF_Raid_t * raidPtr,
     57     RF_Config_t * cfgPtr)
     58 {
     59 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
     60 	RF_Raid5RSConfigInfo_t *info;
     61 	RF_RowCol_t i, j, startdisk;
     62 
     63 	/* create a RAID level 5 configuration structure */
     64 	RF_MallocAndAdd(info, sizeof(RF_Raid5RSConfigInfo_t), (RF_Raid5RSConfigInfo_t *), raidPtr->cleanupList);
     65 	if (info == NULL)
     66 		return (ENOMEM);
     67 	layoutPtr->layoutSpecificInfo = (void *) info;
     68 
     69 	RF_ASSERT(raidPtr->numRow == 1);
     70 	RF_ASSERT(raidPtr->numCol >= 3);
     71 
     72 	/* the stripe identifier must identify the disks in each stripe, IN
     73 	 * THE ORDER THAT THEY APPEAR IN THE STRIPE. */
     74 	info->stripeIdentifier = rf_make_2d_array(raidPtr->numCol, raidPtr->numCol, raidPtr->cleanupList);
     75 	if (info->stripeIdentifier == NULL)
     76 		return (ENOMEM);
     77 	startdisk = 0;
     78 	for (i = 0; i < raidPtr->numCol; i++) {
     79 		for (j = 0; j < raidPtr->numCol; j++) {
     80 			info->stripeIdentifier[i][j] = (startdisk + j) % raidPtr->numCol;
     81 		}
     82 		if ((--startdisk) < 0)
     83 			startdisk = raidPtr->numCol - 1;
     84 	}
     85 
     86 	/* fill in the remaining layout parameters */
     87 	layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk;
     88 	layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit << raidPtr->logBytesPerSector;
     89 	layoutPtr->numDataCol = raidPtr->numCol - 2;
     90 	layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
     91 	layoutPtr->numParityCol = 1;
     92 	layoutPtr->dataStripeUnitsPerDisk = layoutPtr->stripeUnitsPerDisk;
     93 	raidPtr->sectorsPerDisk = layoutPtr->stripeUnitsPerDisk * layoutPtr->sectorsPerStripeUnit;
     94 
     95 	raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
     96 
     97 	return (0);
     98 }
     99 
    100 RF_ReconUnitCount_t
    101 rf_GetNumSpareRUsRAID5_RS(raidPtr)
    102 	RF_Raid_t *raidPtr;
    103 {
    104 	return (raidPtr->Layout.stripeUnitsPerDisk / raidPtr->numCol);
    105 }
    106 
    107 void
    108 rf_MapSectorRAID5_RS(
    109     RF_Raid_t * raidPtr,
    110     RF_RaidAddr_t raidSector,
    111     RF_RowCol_t * row,
    112     RF_RowCol_t * col,
    113     RF_SectorNum_t * diskSector,
    114     int remap)
    115 {
    116 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    117 
    118 	*row = 0;
    119 	if (remap) {
    120 		*col = raidPtr->numCol - 1 - (1 + SUID / raidPtr->Layout.numDataCol) % raidPtr->numCol;
    121 		*col = (*col + 1) % raidPtr->numCol;	/* spare unit is rotated
    122 							 * with parity; line
    123 							 * above maps to parity */
    124 	} else {
    125 		*col = (SUID + (SUID / raidPtr->Layout.numDataCol)) % raidPtr->numCol;
    126 	}
    127 	*diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
    128 	    (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    129 }
    130 
    131 void
    132 rf_MapParityRAID5_RS(
    133     RF_Raid_t * raidPtr,
    134     RF_RaidAddr_t raidSector,
    135     RF_RowCol_t * row,
    136     RF_RowCol_t * col,
    137     RF_SectorNum_t * diskSector,
    138     int remap)
    139 {
    140 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    141 
    142 	*row = 0;
    143 	*col = raidPtr->numCol - 1 - (1 + SUID / raidPtr->Layout.numDataCol) % raidPtr->numCol;
    144 	*diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
    145 	    (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    146 	if (remap)
    147 		*col = (*col + 1) % raidPtr->numCol;
    148 }
    149 
    150 void
    151 rf_IdentifyStripeRAID5_RS(
    152     RF_Raid_t * raidPtr,
    153     RF_RaidAddr_t addr,
    154     RF_RowCol_t ** diskids,
    155     RF_RowCol_t * outRow)
    156 {
    157 	RF_StripeNum_t stripeID = rf_RaidAddressToStripeID(&raidPtr->Layout, addr);
    158 	RF_Raid5RSConfigInfo_t *info = (RF_Raid5RSConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
    159 	*outRow = 0;
    160 	*diskids = info->stripeIdentifier[stripeID % raidPtr->numCol];
    161 
    162 }
    163 
    164 void
    165 rf_MapSIDToPSIDRAID5_RS(
    166     RF_RaidLayout_t * layoutPtr,
    167     RF_StripeNum_t stripeID,
    168     RF_StripeNum_t * psID,
    169     RF_ReconUnitNum_t * which_ru)
    170 {
    171 	*which_ru = 0;
    172 	*psID = stripeID;
    173 }
    174 #endif /* RF_INCLUDE_RAID5_RS > 0 */
    175