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