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