Home | History | Annotate | Line # | Download | only in raidframe
rf_raid5_rotatedspare.c revision 1.1
      1  1.1  oster /*	$NetBSD: rf_raid5_rotatedspare.c,v 1.1 1998/11/13 04:20:33 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_raid5_rotated_spare.c -- implements RAID Level 5 with rotated sparing
     32  1.1  oster  *
     33  1.1  oster  **************************************************************************/
     34  1.1  oster 
     35  1.1  oster /* :
     36  1.1  oster  * Log: rf_raid5_rotatedspare.c,v
     37  1.1  oster  * Revision 1.22  1996/07/31 16:56:18  jimz
     38  1.1  oster  * dataBytesPerStripe, sectorsPerDisk init arch-indep.
     39  1.1  oster  *
     40  1.1  oster  * Revision 1.21  1996/07/29  14:05:12  jimz
     41  1.1  oster  * fix numPUs/numRUs confusion (everything is now numRUs)
     42  1.1  oster  * clean up some commenting, return values
     43  1.1  oster  *
     44  1.1  oster  * Revision 1.20  1996/07/18  22:57:14  jimz
     45  1.1  oster  * port simulator to AIX
     46  1.1  oster  *
     47  1.1  oster  * Revision 1.19  1996/07/13  00:00:59  jimz
     48  1.1  oster  * sanitized generalized reconstruction architecture
     49  1.1  oster  * cleaned up head sep, rbuf problems
     50  1.1  oster  *
     51  1.1  oster  * Revision 1.18  1996/06/19  17:53:48  jimz
     52  1.1  oster  * move GetNumSparePUs, InstallSpareTable ops into layout switch
     53  1.1  oster  *
     54  1.1  oster  * Revision 1.17  1996/06/11  08:54:27  jimz
     55  1.1  oster  * improved error-checking at configuration time
     56  1.1  oster  *
     57  1.1  oster  * Revision 1.16  1996/06/10  11:55:47  jimz
     58  1.1  oster  * Straightened out some per-array/not-per-array distinctions, fixed
     59  1.1  oster  * a couple bugs related to confusion. Added shutdown lists. Removed
     60  1.1  oster  * layout shutdown function (now subsumed by shutdown lists).
     61  1.1  oster  *
     62  1.1  oster  * Revision 1.15  1996/06/07  22:26:27  jimz
     63  1.1  oster  * type-ify which_ru (RF_ReconUnitNum_t)
     64  1.1  oster  *
     65  1.1  oster  * Revision 1.14  1996/06/07  21:33:04  jimz
     66  1.1  oster  * begin using consistent types for sector numbers,
     67  1.1  oster  * stripe numbers, row+col numbers, recon unit numbers
     68  1.1  oster  *
     69  1.1  oster  * Revision 1.13  1996/06/03  23:28:26  jimz
     70  1.1  oster  * more bugfixes
     71  1.1  oster  * check in tree to sync for IPDS runs with current bugfixes
     72  1.1  oster  * there still may be a problem with threads in the script test
     73  1.1  oster  * getting I/Os stuck- not trivially reproducible (runs ~50 times
     74  1.1  oster  * in a row without getting stuck)
     75  1.1  oster  *
     76  1.1  oster  * Revision 1.12  1996/06/02  17:31:48  jimz
     77  1.1  oster  * Moved a lot of global stuff into array structure, where it belongs.
     78  1.1  oster  * Fixed up paritylogging, pss modules in this manner. Some general
     79  1.1  oster  * code cleanup. Removed lots of dead code, some dead files.
     80  1.1  oster  *
     81  1.1  oster  * Revision 1.11  1996/05/31  22:26:54  jimz
     82  1.1  oster  * fix a lot of mapping problems, memory allocation problems
     83  1.1  oster  * found some weird lock issues, fixed 'em
     84  1.1  oster  * more code cleanup
     85  1.1  oster  *
     86  1.1  oster  * Revision 1.10  1996/05/27  18:56:37  jimz
     87  1.1  oster  * more code cleanup
     88  1.1  oster  * better typing
     89  1.1  oster  * compiles in all 3 environments
     90  1.1  oster  *
     91  1.1  oster  * Revision 1.9  1996/05/24  01:59:45  jimz
     92  1.1  oster  * another checkpoint in code cleanup for release
     93  1.1  oster  * time to sync kernel tree
     94  1.1  oster  *
     95  1.1  oster  * Revision 1.8  1996/05/23  00:33:23  jimz
     96  1.1  oster  * code cleanup: move all debug decls to rf_options.c, all extern
     97  1.1  oster  * debug decls to rf_options.h, all debug vars preceded by rf_
     98  1.1  oster  *
     99  1.1  oster  * Revision 1.7  1996/05/18  19:51:34  jimz
    100  1.1  oster  * major code cleanup- fix syntax, make some types consistent,
    101  1.1  oster  * add prototypes, clean out dead code, et cetera
    102  1.1  oster  *
    103  1.1  oster  * Revision 1.6  1996/05/03  19:48:36  wvcii
    104  1.1  oster  * removed include of rf_redstripe.h
    105  1.1  oster  *
    106  1.1  oster  * Revision 1.5  1995/12/12  18:10:06  jimz
    107  1.1  oster  * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT
    108  1.1  oster  * fix 80-column brain damage in comments
    109  1.1  oster  *
    110  1.1  oster  * Revision 1.4  1995/12/06  15:05:53  root
    111  1.1  oster  * added copyright info
    112  1.1  oster  *
    113  1.1  oster  * Revision 1.3  1995/11/19  21:26:29  amiri
    114  1.1  oster  * Added an assert to make sure numCol >= 3
    115  1.1  oster  *
    116  1.1  oster  * Revision 1.2  1995/11/17  19:03:18  wvcii
    117  1.1  oster  * added prototyping to MapParity
    118  1.1  oster  *
    119  1.1  oster  */
    120  1.1  oster 
    121  1.1  oster #include "rf_raid.h"
    122  1.1  oster #include "rf_raid5.h"
    123  1.1  oster #include "rf_dag.h"
    124  1.1  oster #include "rf_dagutils.h"
    125  1.1  oster #include "rf_dagfuncs.h"
    126  1.1  oster #include "rf_threadid.h"
    127  1.1  oster #include "rf_general.h"
    128  1.1  oster #include "rf_utils.h"
    129  1.1  oster #include "rf_raid5_rotatedspare.h"
    130  1.1  oster 
    131  1.1  oster typedef struct RF_Raid5RSConfigInfo_s  {
    132  1.1  oster   RF_RowCol_t  **stripeIdentifier;                    /* filled in at config time & used by IdentifyStripe */
    133  1.1  oster } RF_Raid5RSConfigInfo_t;
    134  1.1  oster 
    135  1.1  oster int rf_ConfigureRAID5_RS(
    136  1.1  oster   RF_ShutdownList_t  **listp,
    137  1.1  oster   RF_Raid_t           *raidPtr,
    138  1.1  oster   RF_Config_t         *cfgPtr)
    139  1.1  oster {
    140  1.1  oster   RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
    141  1.1  oster   RF_Raid5RSConfigInfo_t *info;
    142  1.1  oster   RF_RowCol_t i, j, startdisk;
    143  1.1  oster 
    144  1.1  oster   /* create a RAID level 5 configuration structure */
    145  1.1  oster   RF_MallocAndAdd(info, sizeof(RF_Raid5RSConfigInfo_t), (RF_Raid5RSConfigInfo_t *), raidPtr->cleanupList);
    146  1.1  oster   if (info == NULL)
    147  1.1  oster     return(ENOMEM);
    148  1.1  oster   layoutPtr->layoutSpecificInfo = (void *) info;
    149  1.1  oster 
    150  1.1  oster   RF_ASSERT(raidPtr->numRow == 1);
    151  1.1  oster   RF_ASSERT(raidPtr->numCol >= 3);
    152  1.1  oster 
    153  1.1  oster   /* the stripe identifier must identify the disks in each stripe,
    154  1.1  oster    * IN THE ORDER THAT THEY APPEAR IN THE STRIPE.
    155  1.1  oster    */
    156  1.1  oster   info->stripeIdentifier = rf_make_2d_array(raidPtr->numCol, raidPtr->numCol, raidPtr->cleanupList);
    157  1.1  oster   if (info->stripeIdentifier == NULL)
    158  1.1  oster     return(ENOMEM);
    159  1.1  oster   startdisk = 0;
    160  1.1  oster   for (i=0; i<raidPtr->numCol; i++) {
    161  1.1  oster     for (j=0; j<raidPtr->numCol; j++) {
    162  1.1  oster       info->stripeIdentifier[i][j] = (startdisk + j) % raidPtr->numCol;
    163  1.1  oster     }
    164  1.1  oster     if ((--startdisk) < 0) startdisk = raidPtr->numCol-1;
    165  1.1  oster   }
    166  1.1  oster 
    167  1.1  oster   /* fill in the remaining layout parameters */
    168  1.1  oster   layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk;
    169  1.1  oster   layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit << raidPtr->logBytesPerSector;
    170  1.1  oster   layoutPtr->numDataCol = raidPtr->numCol-2;
    171  1.1  oster   layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
    172  1.1  oster   layoutPtr->numParityCol = 1;
    173  1.1  oster   layoutPtr->dataStripeUnitsPerDisk = layoutPtr->stripeUnitsPerDisk;
    174  1.1  oster   raidPtr->sectorsPerDisk = layoutPtr->stripeUnitsPerDisk * layoutPtr->sectorsPerStripeUnit;
    175  1.1  oster 
    176  1.1  oster   raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
    177  1.1  oster 
    178  1.1  oster   return(0);
    179  1.1  oster }
    180  1.1  oster 
    181  1.1  oster RF_ReconUnitCount_t rf_GetNumSpareRUsRAID5_RS(raidPtr)
    182  1.1  oster   RF_Raid_t  *raidPtr;
    183  1.1  oster {
    184  1.1  oster   return ( raidPtr->Layout.stripeUnitsPerDisk / raidPtr->numCol );
    185  1.1  oster }
    186  1.1  oster 
    187  1.1  oster void rf_MapSectorRAID5_RS(
    188  1.1  oster   RF_Raid_t         *raidPtr,
    189  1.1  oster   RF_RaidAddr_t      raidSector,
    190  1.1  oster   RF_RowCol_t       *row,
    191  1.1  oster   RF_RowCol_t       *col,
    192  1.1  oster   RF_SectorNum_t    *diskSector,
    193  1.1  oster   int                remap)
    194  1.1  oster {
    195  1.1  oster   RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    196  1.1  oster 
    197  1.1  oster   *row = 0;
    198  1.1  oster   if (remap) {
    199  1.1  oster     *col =  raidPtr->numCol-1-(1+SUID/raidPtr->Layout.numDataCol)%raidPtr->numCol;
    200  1.1  oster     *col = (*col+1)%raidPtr->numCol; /*spare unit is rotated with parity; line above maps to parity */
    201  1.1  oster   }
    202  1.1  oster   else {
    203  1.1  oster       *col = ( SUID + (SUID/raidPtr->Layout.numDataCol) ) % raidPtr->numCol;
    204  1.1  oster   }
    205  1.1  oster   *diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
    206  1.1  oster     (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    207  1.1  oster }
    208  1.1  oster 
    209  1.1  oster void rf_MapParityRAID5_RS(
    210  1.1  oster   RF_Raid_t       *raidPtr,
    211  1.1  oster   RF_RaidAddr_t    raidSector,
    212  1.1  oster   RF_RowCol_t     *row,
    213  1.1  oster   RF_RowCol_t     *col,
    214  1.1  oster   RF_SectorNum_t  *diskSector,
    215  1.1  oster   int              remap)
    216  1.1  oster {
    217  1.1  oster   RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    218  1.1  oster 
    219  1.1  oster   *row = 0;
    220  1.1  oster   *col = raidPtr->numCol-1-(1+SUID/raidPtr->Layout.numDataCol)%raidPtr->numCol;
    221  1.1  oster   *diskSector =(SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
    222  1.1  oster     (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    223  1.1  oster   if (remap)
    224  1.1  oster 	*col = (*col+1)%raidPtr->numCol;
    225  1.1  oster }
    226  1.1  oster 
    227  1.1  oster void rf_IdentifyStripeRAID5_RS(
    228  1.1  oster   RF_Raid_t        *raidPtr,
    229  1.1  oster   RF_RaidAddr_t     addr,
    230  1.1  oster   RF_RowCol_t     **diskids,
    231  1.1  oster   RF_RowCol_t      *outRow)
    232  1.1  oster {
    233  1.1  oster   RF_StripeNum_t stripeID = rf_RaidAddressToStripeID(&raidPtr->Layout, addr);
    234  1.1  oster   RF_Raid5RSConfigInfo_t *info = (RF_Raid5RSConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
    235  1.1  oster   *outRow = 0;
    236  1.1  oster   *diskids = info->stripeIdentifier[ stripeID % raidPtr->numCol ];
    237  1.1  oster 
    238  1.1  oster }
    239  1.1  oster 
    240  1.1  oster void rf_MapSIDToPSIDRAID5_RS(
    241  1.1  oster   RF_RaidLayout_t    *layoutPtr,
    242  1.1  oster   RF_StripeNum_t      stripeID,
    243  1.1  oster   RF_StripeNum_t     *psID,
    244  1.1  oster   RF_ReconUnitNum_t  *which_ru)
    245  1.1  oster {
    246  1.1  oster   *which_ru = 0;
    247  1.1  oster   *psID = stripeID;
    248  1.1  oster }
    249  1.1  oster 
    250