Home | History | Annotate | Line # | Download | only in raidframe
rf_interdecluster.c revision 1.6
      1 /*	$NetBSD: rf_interdecluster.c,v 1.6 2001/10/04 15:58:54 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_interdecluster.c -- implements interleaved declustering
     32  *
     33  ************************************************************/
     34 
     35 #include "rf_archs.h"
     36 
     37 #if RF_INCLUDE_INTERDECLUSTER > 0
     38 
     39 #include <dev/raidframe/raidframevar.h>
     40 
     41 #include "rf_raid.h"
     42 #include "rf_interdecluster.h"
     43 #include "rf_dag.h"
     44 #include "rf_dagutils.h"
     45 #include "rf_dagfuncs.h"
     46 #include "rf_general.h"
     47 #include "rf_utils.h"
     48 #include "rf_dagffrd.h"
     49 #include "rf_dagdegrd.h"
     50 #include "rf_dagffwr.h"
     51 #include "rf_dagdegwr.h"
     52 
     53 typedef struct RF_InterdeclusterConfigInfo_s {
     54 	RF_RowCol_t **stripeIdentifier;	/* filled in at config time and used
     55 					 * by IdentifyStripe */
     56 	RF_StripeCount_t numSparingRegions;
     57 	RF_StripeCount_t stripeUnitsPerSparingRegion;
     58 	RF_SectorNum_t mirrorStripeOffset;
     59 }       RF_InterdeclusterConfigInfo_t;
     60 
     61 int
     62 rf_ConfigureInterDecluster(
     63     RF_ShutdownList_t ** listp,
     64     RF_Raid_t * raidPtr,
     65     RF_Config_t * cfgPtr)
     66 {
     67 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
     68 	RF_StripeCount_t num_used_stripeUnitsPerDisk;
     69 	RF_InterdeclusterConfigInfo_t *info;
     70 	RF_RowCol_t i, tmp, SUs_per_region;
     71 
     72 	/* create an Interleaved Declustering configuration structure */
     73 	RF_MallocAndAdd(info, sizeof(RF_InterdeclusterConfigInfo_t), (RF_InterdeclusterConfigInfo_t *),
     74 	    raidPtr->cleanupList);
     75 	if (info == NULL)
     76 		return (ENOMEM);
     77 	layoutPtr->layoutSpecificInfo = (void *) info;
     78 
     79 	/* fill in the config structure.  */
     80 	SUs_per_region = raidPtr->numCol * (raidPtr->numCol - 1);
     81 	info->stripeIdentifier = rf_make_2d_array(SUs_per_region, 2, raidPtr->cleanupList);
     82 	if (info->stripeIdentifier == NULL)
     83 		return (ENOMEM);
     84 	for (i = 0; i < SUs_per_region; i++) {
     85 		info->stripeIdentifier[i][0] = i / (raidPtr->numCol - 1);
     86 		tmp = i / raidPtr->numCol;
     87 		info->stripeIdentifier[i][1] = (i + 1 + tmp) % raidPtr->numCol;
     88 	}
     89 
     90 	/* no spare tables */
     91 	RF_ASSERT(raidPtr->numRow == 1);
     92 
     93 	/* fill in the remaining layout parameters */
     94 
     95 	/* total number of stripes should a multiple of 2*numCol: Each sparing
     96 	 * region consists of 2*numCol stripes: n-1 primary copy, n-1
     97 	 * secondary copy and 2 for spare .. */
     98 	num_used_stripeUnitsPerDisk = layoutPtr->stripeUnitsPerDisk - (layoutPtr->stripeUnitsPerDisk %
     99 	    (2 * raidPtr->numCol));
    100 	info->numSparingRegions = num_used_stripeUnitsPerDisk / (2 * raidPtr->numCol);
    101 	/* this is in fact the number of stripe units (that are primary data
    102 	 * copies) in the sparing region */
    103 	info->stripeUnitsPerSparingRegion = raidPtr->numCol * (raidPtr->numCol - 1);
    104 	info->mirrorStripeOffset = info->numSparingRegions * (raidPtr->numCol + 1);
    105 	layoutPtr->numStripe = info->numSparingRegions * info->stripeUnitsPerSparingRegion;
    106 	layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit << raidPtr->logBytesPerSector;
    107 	layoutPtr->numDataCol = 1;
    108 	layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
    109 	layoutPtr->numParityCol = 1;
    110 
    111 	layoutPtr->dataStripeUnitsPerDisk = num_used_stripeUnitsPerDisk;
    112 
    113 	raidPtr->sectorsPerDisk =
    114 	    num_used_stripeUnitsPerDisk * layoutPtr->sectorsPerStripeUnit;
    115 
    116 	raidPtr->totalSectors =
    117 	    (layoutPtr->numStripe) * layoutPtr->sectorsPerStripeUnit;
    118 
    119 	layoutPtr->stripeUnitsPerDisk = raidPtr->sectorsPerDisk / layoutPtr->sectorsPerStripeUnit;
    120 
    121 	return (0);
    122 }
    123 
    124 int
    125 rf_GetDefaultNumFloatingReconBuffersInterDecluster(RF_Raid_t * raidPtr)
    126 {
    127 	return (30);
    128 }
    129 
    130 RF_HeadSepLimit_t
    131 rf_GetDefaultHeadSepLimitInterDecluster(RF_Raid_t * raidPtr)
    132 {
    133 	return (raidPtr->sectorsPerDisk);
    134 }
    135 
    136 RF_ReconUnitCount_t
    137 rf_GetNumSpareRUsInterDecluster(
    138     RF_Raid_t * raidPtr)
    139 {
    140 	RF_InterdeclusterConfigInfo_t *info = (RF_InterdeclusterConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
    141 
    142 	return (2 * ((RF_ReconUnitCount_t) info->numSparingRegions));
    143 	/* the layout uses two stripe units per disk as spare within each
    144 	 * sparing region */
    145 }
    146 /* Maps to the primary copy of the data, i.e. the first mirror pair */
    147 void
    148 rf_MapSectorInterDecluster(
    149     RF_Raid_t * raidPtr,
    150     RF_RaidAddr_t raidSector,
    151     RF_RowCol_t * row,
    152     RF_RowCol_t * col,
    153     RF_SectorNum_t * diskSector,
    154     int remap)
    155 {
    156 	RF_InterdeclusterConfigInfo_t *info = (RF_InterdeclusterConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
    157 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    158 	RF_StripeNum_t su_offset_into_disk, mirror_su_offset_into_disk;
    159 	RF_StripeNum_t sparing_region_id, index_within_region;
    160 	int     col_before_remap;
    161 
    162 	*row = 0;
    163 	sparing_region_id = SUID / info->stripeUnitsPerSparingRegion;
    164 	index_within_region = SUID % info->stripeUnitsPerSparingRegion;
    165 	su_offset_into_disk = index_within_region % (raidPtr->numCol - 1);
    166 	mirror_su_offset_into_disk = index_within_region / raidPtr->numCol;
    167 	col_before_remap = index_within_region / (raidPtr->numCol - 1);
    168 
    169 	if (!remap) {
    170 		*col = col_before_remap;;
    171 		*diskSector = (su_offset_into_disk + ((raidPtr->numCol - 1) * sparing_region_id)) *
    172 		    raidPtr->Layout.sectorsPerStripeUnit;
    173 		*diskSector += (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    174 	} else {
    175 		/* remap sector to spare space... */
    176 		*diskSector = sparing_region_id * (raidPtr->numCol + 1) * raidPtr->Layout.sectorsPerStripeUnit;
    177 		*diskSector += (raidPtr->numCol - 1) * raidPtr->Layout.sectorsPerStripeUnit;
    178 		*diskSector += (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    179 		*col = (index_within_region + 1 + mirror_su_offset_into_disk) % raidPtr->numCol;
    180 		*col = (*col + 1) % raidPtr->numCol;
    181 		if (*col == col_before_remap)
    182 			*col = (*col + 1) % raidPtr->numCol;
    183 	}
    184 }
    185 /* Maps to the second copy of the mirror pair. */
    186 void
    187 rf_MapParityInterDecluster(
    188     RF_Raid_t * raidPtr,
    189     RF_RaidAddr_t raidSector,
    190     RF_RowCol_t * row,
    191     RF_RowCol_t * col,
    192     RF_SectorNum_t * diskSector,
    193     int remap)
    194 {
    195 	RF_InterdeclusterConfigInfo_t *info = (RF_InterdeclusterConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
    196 	RF_StripeNum_t sparing_region_id, index_within_region, mirror_su_offset_into_disk;
    197 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    198 	int     col_before_remap;
    199 
    200 	sparing_region_id = SUID / info->stripeUnitsPerSparingRegion;
    201 	index_within_region = SUID % info->stripeUnitsPerSparingRegion;
    202 	mirror_su_offset_into_disk = index_within_region / raidPtr->numCol;
    203 	col_before_remap = (index_within_region + 1 + mirror_su_offset_into_disk) % raidPtr->numCol;
    204 
    205 	*row = 0;
    206 	if (!remap) {
    207 		*col = col_before_remap;
    208 		*diskSector = info->mirrorStripeOffset * raidPtr->Layout.sectorsPerStripeUnit;
    209 		*diskSector += sparing_region_id * (raidPtr->numCol - 1) * raidPtr->Layout.sectorsPerStripeUnit;
    210 		*diskSector += mirror_su_offset_into_disk * raidPtr->Layout.sectorsPerStripeUnit;
    211 		*diskSector += (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    212 	} else {
    213 		/* remap parity to spare space ... */
    214 		*diskSector = sparing_region_id * (raidPtr->numCol + 1) * raidPtr->Layout.sectorsPerStripeUnit;
    215 		*diskSector += (raidPtr->numCol) * raidPtr->Layout.sectorsPerStripeUnit;
    216 		*diskSector += (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    217 		*col = index_within_region / (raidPtr->numCol - 1);
    218 		*col = (*col + 1) % raidPtr->numCol;
    219 		if (*col == col_before_remap)
    220 			*col = (*col + 1) % raidPtr->numCol;
    221 	}
    222 }
    223 
    224 void
    225 rf_IdentifyStripeInterDecluster(
    226     RF_Raid_t * raidPtr,
    227     RF_RaidAddr_t addr,
    228     RF_RowCol_t ** diskids,
    229     RF_RowCol_t * outRow)
    230 {
    231 	RF_InterdeclusterConfigInfo_t *info = (RF_InterdeclusterConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
    232 	RF_StripeNum_t SUID;
    233 
    234 	SUID = addr / raidPtr->Layout.sectorsPerStripeUnit;
    235 	SUID = SUID % info->stripeUnitsPerSparingRegion;
    236 
    237 	*outRow = 0;
    238 	*diskids = info->stripeIdentifier[SUID];
    239 }
    240 
    241 void
    242 rf_MapSIDToPSIDInterDecluster(
    243     RF_RaidLayout_t * layoutPtr,
    244     RF_StripeNum_t stripeID,
    245     RF_StripeNum_t * psID,
    246     RF_ReconUnitNum_t * which_ru)
    247 {
    248 	*which_ru = 0;
    249 	*psID = stripeID;
    250 }
    251 /******************************************************************************
    252  * select a graph to perform a single-stripe access
    253  *
    254  * Parameters:  raidPtr    - description of the physical array
    255  *              type       - type of operation (read or write) requested
    256  *              asmap      - logical & physical addresses for this access
    257  *              createFunc - name of function to use to create the graph
    258  *****************************************************************************/
    259 
    260 void
    261 rf_RAIDIDagSelect(
    262     RF_Raid_t * raidPtr,
    263     RF_IoType_t type,
    264     RF_AccessStripeMap_t * asmap,
    265     RF_VoidFuncPtr * createFunc)
    266 {
    267 	RF_ASSERT(RF_IO_IS_R_OR_W(type));
    268 
    269 	if (asmap->numDataFailed + asmap->numParityFailed > 1) {
    270 		RF_ERRORMSG("Multiple disks failed in a single group!  Aborting I/O operation.\n");
    271 		*createFunc = NULL;
    272 		return;
    273 	}
    274 	*createFunc = (type == RF_IO_TYPE_READ) ? (RF_VoidFuncPtr) rf_CreateFaultFreeReadDAG : (RF_VoidFuncPtr) rf_CreateRaidOneWriteDAG;
    275 	if (type == RF_IO_TYPE_READ) {
    276 		if (asmap->numDataFailed == 0)
    277 			*createFunc = (RF_VoidFuncPtr) rf_CreateMirrorPartitionReadDAG;
    278 		else
    279 			*createFunc = (RF_VoidFuncPtr) rf_CreateRaidOneDegradedReadDAG;
    280 	} else
    281 		*createFunc = (RF_VoidFuncPtr) rf_CreateRaidOneWriteDAG;
    282 }
    283 #endif /* RF_INCLUDE_INTERDECLUSTER > 0 */
    284