root/dev/raidframe/rf_raid5_rotatedspare.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. RF_Raid5RSConfigInfo_t
  2. rf_ConfigureRAID5_RS
  3. rf_GetNumSpareRUsRAID5_RS
  4. rf_MapSectorRAID5_RS
  5. rf_MapParityRAID5_RS
  6. rf_IdentifyStripeRAID5_RS
  7. rf_MapSIDToPSIDRAID5_RS

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

/* [<][>][^][v][top][bottom][index][help] */