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