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