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