Home | History | Annotate | Line # | Download | only in raidframe
rf_raid5_rotatedspare.c revision 1.8.10.1
      1  1.8.10.1   yamt /*	$NetBSD: rf_raid5_rotatedspare.c,v 1.8.10.1 2005/03/19 08:35:41 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.1  oster  * rf_raid5_rotated_spare.c -- implements RAID Level 5 with rotated sparing
     32       1.1  oster  *
     33       1.1  oster  **************************************************************************/
     34       1.6  lukem 
     35       1.6  lukem #include <sys/cdefs.h>
     36  1.8.10.1   yamt __KERNEL_RCSID(0, "$NetBSD: rf_raid5_rotatedspare.c,v 1.8.10.1 2005/03/19 08:35:41 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_RAID5_RS > 0
     41       1.5  oster 
     42       1.1  oster #include "rf_raid.h"
     43       1.1  oster #include "rf_raid5.h"
     44       1.1  oster #include "rf_dag.h"
     45       1.1  oster #include "rf_dagutils.h"
     46       1.1  oster #include "rf_dagfuncs.h"
     47       1.1  oster #include "rf_general.h"
     48       1.1  oster #include "rf_utils.h"
     49       1.1  oster #include "rf_raid5_rotatedspare.h"
     50       1.1  oster 
     51       1.3  oster typedef struct RF_Raid5RSConfigInfo_s {
     52       1.3  oster 	RF_RowCol_t **stripeIdentifier;	/* filled in at config time & used by
     53       1.3  oster 					 * IdentifyStripe */
     54       1.3  oster }       RF_Raid5RSConfigInfo_t;
     55       1.3  oster 
     56  1.8.10.1   yamt int
     57       1.3  oster rf_ConfigureRAID5_RS(
     58       1.3  oster     RF_ShutdownList_t ** listp,
     59       1.3  oster     RF_Raid_t * raidPtr,
     60       1.3  oster     RF_Config_t * cfgPtr)
     61       1.3  oster {
     62       1.3  oster 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
     63       1.3  oster 	RF_Raid5RSConfigInfo_t *info;
     64       1.3  oster 	RF_RowCol_t i, j, startdisk;
     65       1.3  oster 
     66       1.3  oster 	/* create a RAID level 5 configuration structure */
     67       1.3  oster 	RF_MallocAndAdd(info, sizeof(RF_Raid5RSConfigInfo_t), (RF_Raid5RSConfigInfo_t *), raidPtr->cleanupList);
     68       1.3  oster 	if (info == NULL)
     69       1.3  oster 		return (ENOMEM);
     70       1.3  oster 	layoutPtr->layoutSpecificInfo = (void *) info;
     71       1.3  oster 
     72       1.3  oster 	RF_ASSERT(raidPtr->numCol >= 3);
     73       1.3  oster 
     74       1.3  oster 	/* the stripe identifier must identify the disks in each stripe, IN
     75       1.3  oster 	 * THE ORDER THAT THEY APPEAR IN THE STRIPE. */
     76       1.3  oster 	info->stripeIdentifier = rf_make_2d_array(raidPtr->numCol, raidPtr->numCol, raidPtr->cleanupList);
     77       1.3  oster 	if (info->stripeIdentifier == NULL)
     78       1.3  oster 		return (ENOMEM);
     79       1.3  oster 	startdisk = 0;
     80       1.3  oster 	for (i = 0; i < raidPtr->numCol; i++) {
     81       1.3  oster 		for (j = 0; j < raidPtr->numCol; j++) {
     82       1.3  oster 			info->stripeIdentifier[i][j] = (startdisk + j) % raidPtr->numCol;
     83       1.3  oster 		}
     84       1.3  oster 		if ((--startdisk) < 0)
     85       1.3  oster 			startdisk = raidPtr->numCol - 1;
     86       1.3  oster 	}
     87       1.3  oster 
     88       1.3  oster 	/* fill in the remaining layout parameters */
     89       1.3  oster 	layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk;
     90       1.3  oster 	layoutPtr->numDataCol = raidPtr->numCol - 2;
     91       1.3  oster 	layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
     92       1.3  oster 	layoutPtr->numParityCol = 1;
     93       1.3  oster 	layoutPtr->dataStripeUnitsPerDisk = layoutPtr->stripeUnitsPerDisk;
     94       1.3  oster 	raidPtr->sectorsPerDisk = layoutPtr->stripeUnitsPerDisk * layoutPtr->sectorsPerStripeUnit;
     95       1.3  oster 
     96       1.3  oster 	raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
     97       1.3  oster 
     98       1.3  oster 	return (0);
     99       1.3  oster }
    100       1.3  oster 
    101  1.8.10.1   yamt RF_ReconUnitCount_t
    102       1.3  oster rf_GetNumSpareRUsRAID5_RS(raidPtr)
    103       1.3  oster 	RF_Raid_t *raidPtr;
    104       1.3  oster {
    105       1.3  oster 	return (raidPtr->Layout.stripeUnitsPerDisk / raidPtr->numCol);
    106       1.3  oster }
    107       1.3  oster 
    108  1.8.10.1   yamt void
    109       1.3  oster rf_MapSectorRAID5_RS(
    110       1.3  oster     RF_Raid_t * raidPtr,
    111       1.3  oster     RF_RaidAddr_t raidSector,
    112       1.3  oster     RF_RowCol_t * col,
    113       1.3  oster     RF_SectorNum_t * diskSector,
    114       1.3  oster     int remap)
    115       1.3  oster {
    116       1.3  oster 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    117       1.3  oster 
    118       1.3  oster 	if (remap) {
    119       1.3  oster 		*col = raidPtr->numCol - 1 - (1 + SUID / raidPtr->Layout.numDataCol) % raidPtr->numCol;
    120       1.3  oster 		*col = (*col + 1) % raidPtr->numCol;	/* spare unit is rotated
    121       1.3  oster 							 * with parity; line
    122       1.3  oster 							 * above maps to parity */
    123       1.3  oster 	} else {
    124       1.3  oster 		*col = (SUID + (SUID / raidPtr->Layout.numDataCol)) % raidPtr->numCol;
    125       1.3  oster 	}
    126       1.3  oster 	*diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
    127       1.3  oster 	    (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    128       1.3  oster }
    129       1.3  oster 
    130  1.8.10.1   yamt void
    131       1.3  oster rf_MapParityRAID5_RS(
    132       1.3  oster     RF_Raid_t * raidPtr,
    133       1.3  oster     RF_RaidAddr_t raidSector,
    134       1.3  oster     RF_RowCol_t * col,
    135       1.3  oster     RF_SectorNum_t * diskSector,
    136       1.3  oster     int remap)
    137       1.3  oster {
    138       1.3  oster 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    139       1.3  oster 
    140       1.3  oster 	*col = raidPtr->numCol - 1 - (1 + SUID / raidPtr->Layout.numDataCol) % raidPtr->numCol;
    141       1.3  oster 	*diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
    142       1.3  oster 	    (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    143       1.3  oster 	if (remap)
    144       1.3  oster 		*col = (*col + 1) % raidPtr->numCol;
    145       1.3  oster }
    146       1.3  oster 
    147  1.8.10.1   yamt void
    148       1.3  oster rf_IdentifyStripeRAID5_RS(
    149       1.3  oster     RF_Raid_t * raidPtr,
    150       1.3  oster     RF_RaidAddr_t addr,
    151       1.8  oster     RF_RowCol_t ** diskids)
    152       1.3  oster {
    153       1.3  oster 	RF_StripeNum_t stripeID = rf_RaidAddressToStripeID(&raidPtr->Layout, addr);
    154       1.3  oster 	RF_Raid5RSConfigInfo_t *info = (RF_Raid5RSConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
    155       1.3  oster 	*diskids = info->stripeIdentifier[stripeID % raidPtr->numCol];
    156       1.3  oster 
    157       1.3  oster }
    158       1.3  oster 
    159  1.8.10.1   yamt void
    160       1.3  oster rf_MapSIDToPSIDRAID5_RS(
    161       1.3  oster     RF_RaidLayout_t * layoutPtr,
    162       1.3  oster     RF_StripeNum_t stripeID,
    163       1.3  oster     RF_StripeNum_t * psID,
    164       1.3  oster     RF_ReconUnitNum_t * which_ru)
    165       1.1  oster {
    166       1.3  oster 	*which_ru = 0;
    167       1.3  oster 	*psID = stripeID;
    168       1.1  oster }
    169       1.5  oster #endif /* RF_INCLUDE_RAID5_RS > 0 */
    170