rf_raid4.c revision 1.2 1 /* $NetBSD: rf_raid4.c,v 1.2 1999/01/26 02:34:00 oster Exp $ */
2 /*
3 * Copyright (c) 1995 Carnegie-Mellon University.
4 * All rights reserved.
5 *
6 * Author: Rachad Youssef
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_raid4.c -- implements RAID Level 4
32 *
33 ***************************************/
34
35 #include "rf_raid.h"
36 #include "rf_dag.h"
37 #include "rf_dagutils.h"
38 #include "rf_dagfuncs.h"
39 #include "rf_dagffrd.h"
40 #include "rf_dagffwr.h"
41 #include "rf_dagdegrd.h"
42 #include "rf_dagdegwr.h"
43 #include "rf_threadid.h"
44 #include "rf_raid4.h"
45 #include "rf_general.h"
46
47 typedef struct RF_Raid4ConfigInfo_s {
48 RF_RowCol_t *stripeIdentifier; /* filled in at config time & used by IdentifyStripe */
49 } RF_Raid4ConfigInfo_t;
50
51
52
53 int rf_ConfigureRAID4(
54 RF_ShutdownList_t **listp,
55 RF_Raid_t *raidPtr,
56 RF_Config_t *cfgPtr)
57 {
58 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
59 RF_Raid4ConfigInfo_t *info;
60 int i;
61
62 /* create a RAID level 4 configuration structure ... */
63 RF_MallocAndAdd(info, sizeof(RF_Raid4ConfigInfo_t), (RF_Raid4ConfigInfo_t *), raidPtr->cleanupList);
64 if (info == NULL)
65 return(ENOMEM);
66 layoutPtr->layoutSpecificInfo = (void *) info;
67
68 /* ... and fill it in. */
69 RF_MallocAndAdd(info->stripeIdentifier, raidPtr->numCol * sizeof(RF_RowCol_t), (RF_RowCol_t *), raidPtr->cleanupList);
70 if (info->stripeIdentifier == NULL)
71 return(ENOMEM);
72 for (i=0; i<raidPtr->numCol; i++)
73 info->stripeIdentifier[i] = i;
74
75 RF_ASSERT(raidPtr->numRow == 1);
76
77 /* fill in the remaining layout parameters */
78 layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk;
79 layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit << raidPtr->logBytesPerSector;
80 layoutPtr->numDataCol = raidPtr->numCol-1;
81 layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
82 layoutPtr->numParityCol = 1;
83 raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
84
85 return(0);
86 }
87
88 int rf_GetDefaultNumFloatingReconBuffersRAID4(RF_Raid_t *raidPtr)
89 {
90 return(20);
91 }
92
93 RF_HeadSepLimit_t rf_GetDefaultHeadSepLimitRAID4(RF_Raid_t *raidPtr)
94 {
95 return(20);
96 }
97
98 void rf_MapSectorRAID4(
99 RF_Raid_t *raidPtr,
100 RF_RaidAddr_t raidSector,
101 RF_RowCol_t *row,
102 RF_RowCol_t *col,
103 RF_SectorNum_t *diskSector,
104 int remap)
105 {
106 RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
107 *row = 0;
108 *col = SUID % raidPtr->Layout.numDataCol;
109 *diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
110 (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
111 }
112
113 void rf_MapParityRAID4(
114 RF_Raid_t *raidPtr,
115 RF_RaidAddr_t raidSector,
116 RF_RowCol_t *row,
117 RF_RowCol_t *col,
118 RF_SectorNum_t *diskSector,
119 int remap)
120 {
121 RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
122
123 *row = 0;
124 *col = raidPtr->Layout.numDataCol;
125 *diskSector =(SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
126 (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
127 }
128
129 void rf_IdentifyStripeRAID4(
130 RF_Raid_t *raidPtr,
131 RF_RaidAddr_t addr,
132 RF_RowCol_t **diskids,
133 RF_RowCol_t *outRow)
134 {
135 RF_Raid4ConfigInfo_t *info = raidPtr->Layout.layoutSpecificInfo;
136
137 *outRow = 0;
138 *diskids = info->stripeIdentifier;
139 }
140
141 void rf_MapSIDToPSIDRAID4(
142 RF_RaidLayout_t *layoutPtr,
143 RF_StripeNum_t stripeID,
144 RF_StripeNum_t *psID,
145 RF_ReconUnitNum_t *which_ru)
146 {
147 *which_ru = 0;
148 *psID = stripeID;
149 }
150