rf_disks.c revision 1.13.2.1 1 1.13.2.1 bouyer /* $NetBSD: rf_disks.c,v 1.13.2.1 2000/11/20 11:42:53 bouyer Exp $ */
2 1.6 oster /*-
3 1.6 oster * Copyright (c) 1999 The NetBSD Foundation, Inc.
4 1.6 oster * All rights reserved.
5 1.6 oster *
6 1.6 oster * This code is derived from software contributed to The NetBSD Foundation
7 1.6 oster * by Greg Oster
8 1.6 oster *
9 1.6 oster * Redistribution and use in source and binary forms, with or without
10 1.6 oster * modification, are permitted provided that the following conditions
11 1.6 oster * are met:
12 1.6 oster * 1. Redistributions of source code must retain the above copyright
13 1.6 oster * notice, this list of conditions and the following disclaimer.
14 1.6 oster * 2. Redistributions in binary form must reproduce the above copyright
15 1.6 oster * notice, this list of conditions and the following disclaimer in the
16 1.6 oster * documentation and/or other materials provided with the distribution.
17 1.6 oster * 3. All advertising materials mentioning features or use of this software
18 1.6 oster * must display the following acknowledgement:
19 1.6 oster * This product includes software developed by the NetBSD
20 1.6 oster * Foundation, Inc. and its contributors.
21 1.6 oster * 4. Neither the name of The NetBSD Foundation nor the names of its
22 1.6 oster * contributors may be used to endorse or promote products derived
23 1.6 oster * from this software without specific prior written permission.
24 1.6 oster *
25 1.6 oster * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 1.6 oster * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.6 oster * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.6 oster * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 1.6 oster * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.6 oster * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.6 oster * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.6 oster * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.6 oster * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.6 oster * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.6 oster * POSSIBILITY OF SUCH DAMAGE.
36 1.6 oster */
37 1.6 oster
38 1.1 oster /*
39 1.1 oster * Copyright (c) 1995 Carnegie-Mellon University.
40 1.1 oster * All rights reserved.
41 1.1 oster *
42 1.1 oster * Author: Mark Holland
43 1.1 oster *
44 1.1 oster * Permission to use, copy, modify and distribute this software and
45 1.1 oster * its documentation is hereby granted, provided that both the copyright
46 1.1 oster * notice and this permission notice appear in all copies of the
47 1.1 oster * software, derivative works or modified versions, and any portions
48 1.1 oster * thereof, and that both notices appear in supporting documentation.
49 1.1 oster *
50 1.1 oster * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
51 1.1 oster * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
52 1.1 oster * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
53 1.1 oster *
54 1.1 oster * Carnegie Mellon requests users of this software to return to
55 1.1 oster *
56 1.1 oster * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
57 1.1 oster * School of Computer Science
58 1.1 oster * Carnegie Mellon University
59 1.1 oster * Pittsburgh PA 15213-3890
60 1.1 oster *
61 1.1 oster * any improvements or extensions that they make and grant Carnegie the
62 1.1 oster * rights to redistribute these changes.
63 1.1 oster */
64 1.1 oster
65 1.1 oster /***************************************************************
66 1.1 oster * rf_disks.c -- code to perform operations on the actual disks
67 1.1 oster ***************************************************************/
68 1.1 oster
69 1.1 oster #include "rf_types.h"
70 1.1 oster #include "rf_raid.h"
71 1.1 oster #include "rf_alloclist.h"
72 1.1 oster #include "rf_utils.h"
73 1.1 oster #include "rf_configure.h"
74 1.1 oster #include "rf_general.h"
75 1.1 oster #include "rf_options.h"
76 1.13.2.1 bouyer #include "rf_kintf.h"
77 1.13.2.1 bouyer #include "rf_netbsd.h"
78 1.1 oster
79 1.1 oster #include <sys/types.h>
80 1.1 oster #include <sys/param.h>
81 1.1 oster #include <sys/systm.h>
82 1.1 oster #include <sys/proc.h>
83 1.1 oster #include <sys/ioctl.h>
84 1.1 oster #include <sys/fcntl.h>
85 1.1 oster #include <sys/vnode.h>
86 1.1 oster
87 1.13.2.1 bouyer static int rf_AllocDiskStructures(RF_Raid_t *, RF_Config_t *);
88 1.13.2.1 bouyer static void rf_print_label_status( RF_Raid_t *, int, int, char *,
89 1.13.2.1 bouyer RF_ComponentLabel_t *);
90 1.13.2.1 bouyer static int rf_check_label_vitals( RF_Raid_t *, int, int, char *,
91 1.13.2.1 bouyer RF_ComponentLabel_t *, int, int );
92 1.1 oster
93 1.1 oster #define DPRINTF6(a,b,c,d,e,f) if (rf_diskDebug) printf(a,b,c,d,e,f)
94 1.1 oster #define DPRINTF7(a,b,c,d,e,f,g) if (rf_diskDebug) printf(a,b,c,d,e,f,g)
95 1.1 oster
96 1.6 oster /**************************************************************************
97 1.1 oster *
98 1.1 oster * initialize the disks comprising the array
99 1.1 oster *
100 1.6 oster * We want the spare disks to have regular row,col numbers so that we can
101 1.6 oster * easily substitue a spare for a failed disk. But, the driver code assumes
102 1.6 oster * throughout that the array contains numRow by numCol _non-spare_ disks, so
103 1.6 oster * it's not clear how to fit in the spares. This is an unfortunate holdover
104 1.6 oster * from raidSim. The quick and dirty fix is to make row zero bigger than the
105 1.6 oster * rest, and put all the spares in it. This probably needs to get changed
106 1.6 oster * eventually.
107 1.1 oster *
108 1.6 oster **************************************************************************/
109 1.6 oster
110 1.5 oster int
111 1.6 oster rf_ConfigureDisks( listp, raidPtr, cfgPtr )
112 1.6 oster RF_ShutdownList_t **listp;
113 1.6 oster RF_Raid_t *raidPtr;
114 1.6 oster RF_Config_t *cfgPtr;
115 1.1 oster {
116 1.5 oster RF_RaidDisk_t **disks;
117 1.5 oster RF_SectorCount_t min_numblks = (RF_SectorCount_t) 0x7FFFFFFFFFFFLL;
118 1.5 oster RF_RowCol_t r, c;
119 1.6 oster int bs, ret;
120 1.5 oster unsigned i, count, foundone = 0, numFailuresThisRow;
121 1.7 oster int force;
122 1.5 oster
123 1.7 oster force = cfgPtr->force;
124 1.5 oster
125 1.13.2.1 bouyer ret = rf_AllocDiskStructures(raidPtr, cfgPtr);
126 1.13.2.1 bouyer if (ret)
127 1.5 oster goto fail;
128 1.5 oster
129 1.13.2.1 bouyer disks = raidPtr->Disks;
130 1.13.2.1 bouyer
131 1.5 oster for (r = 0; r < raidPtr->numRow; r++) {
132 1.5 oster numFailuresThisRow = 0;
133 1.5 oster for (c = 0; c < raidPtr->numCol; c++) {
134 1.6 oster ret = rf_ConfigureDisk(raidPtr,
135 1.6 oster &cfgPtr->devnames[r][c][0],
136 1.6 oster &disks[r][c], r, c);
137 1.13.2.1 bouyer
138 1.5 oster if (ret)
139 1.5 oster goto fail;
140 1.7 oster
141 1.6 oster if (disks[r][c].status == rf_ds_optimal) {
142 1.6 oster raidread_component_label(
143 1.6 oster raidPtr->raid_cinfo[r][c].ci_dev,
144 1.6 oster raidPtr->raid_cinfo[r][c].ci_vp,
145 1.6 oster &raidPtr->raid_cinfo[r][c].ci_label);
146 1.6 oster }
147 1.7 oster
148 1.5 oster if (disks[r][c].status != rf_ds_optimal) {
149 1.5 oster numFailuresThisRow++;
150 1.5 oster } else {
151 1.5 oster if (disks[r][c].numBlocks < min_numblks)
152 1.5 oster min_numblks = disks[r][c].numBlocks;
153 1.5 oster DPRINTF7("Disk at row %d col %d: dev %s numBlocks %ld blockSize %d (%ld MB)\n",
154 1.5 oster r, c, disks[r][c].devname,
155 1.5 oster (long int) disks[r][c].numBlocks,
156 1.5 oster disks[r][c].blockSize,
157 1.6 oster (long int) disks[r][c].numBlocks *
158 1.6 oster disks[r][c].blockSize / 1024 / 1024);
159 1.5 oster }
160 1.5 oster }
161 1.5 oster /* XXX fix for n-fault tolerant */
162 1.6 oster /* XXX this should probably check to see how many failures
163 1.6 oster we can handle for this configuration! */
164 1.5 oster if (numFailuresThisRow > 0)
165 1.5 oster raidPtr->status[r] = rf_rs_degraded;
166 1.5 oster }
167 1.6 oster
168 1.5 oster /* all disks must be the same size & have the same block size, bs must
169 1.5 oster * be a power of 2 */
170 1.5 oster bs = 0;
171 1.5 oster for (foundone = r = 0; !foundone && r < raidPtr->numRow; r++) {
172 1.5 oster for (c = 0; !foundone && c < raidPtr->numCol; c++) {
173 1.5 oster if (disks[r][c].status == rf_ds_optimal) {
174 1.5 oster bs = disks[r][c].blockSize;
175 1.5 oster foundone = 1;
176 1.5 oster }
177 1.5 oster }
178 1.5 oster }
179 1.5 oster if (!foundone) {
180 1.5 oster RF_ERRORMSG("RAIDFRAME: Did not find any live disks in the array.\n");
181 1.5 oster ret = EINVAL;
182 1.5 oster goto fail;
183 1.5 oster }
184 1.5 oster for (count = 0, i = 1; i; i <<= 1)
185 1.5 oster if (bs & i)
186 1.5 oster count++;
187 1.5 oster if (count != 1) {
188 1.5 oster RF_ERRORMSG1("Error: block size on disks (%d) must be a power of 2\n", bs);
189 1.5 oster ret = EINVAL;
190 1.5 oster goto fail;
191 1.5 oster }
192 1.6 oster
193 1.6 oster if (rf_CheckLabels( raidPtr, cfgPtr )) {
194 1.7 oster printf("raid%d: There were fatal errors\n", raidPtr->raidid);
195 1.7 oster if (force != 0) {
196 1.7 oster printf("raid%d: Fatal errors being ignored.\n",
197 1.7 oster raidPtr->raidid);
198 1.7 oster } else {
199 1.7 oster ret = EINVAL;
200 1.7 oster goto fail;
201 1.7 oster }
202 1.6 oster }
203 1.7 oster
204 1.5 oster for (r = 0; r < raidPtr->numRow; r++) {
205 1.5 oster for (c = 0; c < raidPtr->numCol; c++) {
206 1.5 oster if (disks[r][c].status == rf_ds_optimal) {
207 1.5 oster if (disks[r][c].blockSize != bs) {
208 1.5 oster RF_ERRORMSG2("Error: block size of disk at r %d c %d different from disk at r 0 c 0\n", r, c);
209 1.5 oster ret = EINVAL;
210 1.5 oster goto fail;
211 1.5 oster }
212 1.5 oster if (disks[r][c].numBlocks != min_numblks) {
213 1.5 oster RF_ERRORMSG3("WARNING: truncating disk at r %d c %d to %d blocks\n",
214 1.5 oster r, c, (int) min_numblks);
215 1.5 oster disks[r][c].numBlocks = min_numblks;
216 1.5 oster }
217 1.5 oster }
218 1.5 oster }
219 1.5 oster }
220 1.5 oster
221 1.5 oster raidPtr->sectorsPerDisk = min_numblks;
222 1.5 oster raidPtr->logBytesPerSector = ffs(bs) - 1;
223 1.5 oster raidPtr->bytesPerSector = bs;
224 1.5 oster raidPtr->sectorMask = bs - 1;
225 1.5 oster return (0);
226 1.1 oster
227 1.1 oster fail:
228 1.6 oster
229 1.6 oster rf_UnconfigureVnodes( raidPtr );
230 1.1 oster
231 1.5 oster return (ret);
232 1.1 oster }
233 1.1 oster
234 1.1 oster
235 1.6 oster /****************************************************************************
236 1.1 oster * set up the data structures describing the spare disks in the array
237 1.1 oster * recall from the above comment that the spare disk descriptors are stored
238 1.1 oster * in row zero, which is specially expanded to hold them.
239 1.6 oster ****************************************************************************/
240 1.5 oster int
241 1.6 oster rf_ConfigureSpareDisks( listp, raidPtr, cfgPtr )
242 1.6 oster RF_ShutdownList_t ** listp;
243 1.6 oster RF_Raid_t * raidPtr;
244 1.6 oster RF_Config_t * cfgPtr;
245 1.1 oster {
246 1.6 oster int i, ret;
247 1.6 oster unsigned int bs;
248 1.5 oster RF_RaidDisk_t *disks;
249 1.5 oster int num_spares_done;
250 1.1 oster
251 1.5 oster num_spares_done = 0;
252 1.5 oster
253 1.5 oster /* The space for the spares should have already been allocated by
254 1.5 oster * ConfigureDisks() */
255 1.5 oster
256 1.5 oster disks = &raidPtr->Disks[0][raidPtr->numCol];
257 1.5 oster for (i = 0; i < raidPtr->numSpare; i++) {
258 1.5 oster ret = rf_ConfigureDisk(raidPtr, &cfgPtr->spare_names[i][0],
259 1.6 oster &disks[i], 0, raidPtr->numCol + i);
260 1.5 oster if (ret)
261 1.5 oster goto fail;
262 1.5 oster if (disks[i].status != rf_ds_optimal) {
263 1.6 oster RF_ERRORMSG1("Warning: spare disk %s failed TUR\n",
264 1.6 oster &cfgPtr->spare_names[i][0]);
265 1.5 oster } else {
266 1.5 oster disks[i].status = rf_ds_spare; /* change status to
267 1.5 oster * spare */
268 1.5 oster DPRINTF6("Spare Disk %d: dev %s numBlocks %ld blockSize %d (%ld MB)\n", i,
269 1.5 oster disks[i].devname,
270 1.5 oster (long int) disks[i].numBlocks, disks[i].blockSize,
271 1.6 oster (long int) disks[i].numBlocks *
272 1.6 oster disks[i].blockSize / 1024 / 1024);
273 1.5 oster }
274 1.5 oster num_spares_done++;
275 1.5 oster }
276 1.1 oster
277 1.5 oster /* check sizes and block sizes on spare disks */
278 1.5 oster bs = 1 << raidPtr->logBytesPerSector;
279 1.5 oster for (i = 0; i < raidPtr->numSpare; i++) {
280 1.5 oster if (disks[i].blockSize != bs) {
281 1.5 oster RF_ERRORMSG3("Block size of %d on spare disk %s is not the same as on other disks (%d)\n", disks[i].blockSize, disks[i].devname, bs);
282 1.5 oster ret = EINVAL;
283 1.5 oster goto fail;
284 1.5 oster }
285 1.5 oster if (disks[i].numBlocks < raidPtr->sectorsPerDisk) {
286 1.5 oster RF_ERRORMSG3("Spare disk %s (%d blocks) is too small to serve as a spare (need %ld blocks)\n",
287 1.6 oster disks[i].devname, disks[i].blockSize,
288 1.6 oster (long int) raidPtr->sectorsPerDisk);
289 1.5 oster ret = EINVAL;
290 1.5 oster goto fail;
291 1.5 oster } else
292 1.5 oster if (disks[i].numBlocks > raidPtr->sectorsPerDisk) {
293 1.5 oster RF_ERRORMSG2("Warning: truncating spare disk %s to %ld blocks\n", disks[i].devname, (long int) raidPtr->sectorsPerDisk);
294 1.5 oster
295 1.5 oster disks[i].numBlocks = raidPtr->sectorsPerDisk;
296 1.5 oster }
297 1.5 oster }
298 1.5 oster
299 1.5 oster return (0);
300 1.1 oster
301 1.1 oster fail:
302 1.2 oster
303 1.5 oster /* Release the hold on the main components. We've failed to allocate
304 1.6 oster * a spare, and since we're failing, we need to free things..
305 1.6 oster
306 1.6 oster XXX failing to allocate a spare is *not* that big of a deal...
307 1.6 oster We *can* survive without it, if need be, esp. if we get hot
308 1.6 oster adding working.
309 1.1 oster
310 1.6 oster If we don't fail out here, then we need a way to remove this spare...
311 1.6 oster that should be easier to do here than if we are "live"...
312 1.1 oster
313 1.6 oster */
314 1.1 oster
315 1.6 oster rf_UnconfigureVnodes( raidPtr );
316 1.13.2.1 bouyer
317 1.5 oster return (ret);
318 1.1 oster }
319 1.1 oster
320 1.13.2.1 bouyer static int
321 1.13.2.1 bouyer rf_AllocDiskStructures(raidPtr, cfgPtr)
322 1.13.2.1 bouyer RF_Raid_t *raidPtr;
323 1.13.2.1 bouyer RF_Config_t *cfgPtr;
324 1.13.2.1 bouyer {
325 1.13.2.1 bouyer RF_RaidDisk_t **disks;
326 1.13.2.1 bouyer int ret;
327 1.13.2.1 bouyer int r;
328 1.13.2.1 bouyer
329 1.13.2.1 bouyer RF_CallocAndAdd(disks, raidPtr->numRow, sizeof(RF_RaidDisk_t *),
330 1.13.2.1 bouyer (RF_RaidDisk_t **), raidPtr->cleanupList);
331 1.13.2.1 bouyer if (disks == NULL) {
332 1.13.2.1 bouyer ret = ENOMEM;
333 1.13.2.1 bouyer goto fail;
334 1.13.2.1 bouyer }
335 1.13.2.1 bouyer raidPtr->Disks = disks;
336 1.13.2.1 bouyer /* get space for the device-specific stuff... */
337 1.13.2.1 bouyer RF_CallocAndAdd(raidPtr->raid_cinfo, raidPtr->numRow,
338 1.13.2.1 bouyer sizeof(struct raidcinfo *), (struct raidcinfo **),
339 1.13.2.1 bouyer raidPtr->cleanupList);
340 1.13.2.1 bouyer if (raidPtr->raid_cinfo == NULL) {
341 1.13.2.1 bouyer ret = ENOMEM;
342 1.13.2.1 bouyer goto fail;
343 1.13.2.1 bouyer }
344 1.13.2.1 bouyer
345 1.13.2.1 bouyer for (r = 0; r < raidPtr->numRow; r++) {
346 1.13.2.1 bouyer /* We allocate RF_MAXSPARE on the first row so that we
347 1.13.2.1 bouyer have room to do hot-swapping of spares */
348 1.13.2.1 bouyer RF_CallocAndAdd(disks[r], raidPtr->numCol
349 1.13.2.1 bouyer + ((r == 0) ? RF_MAXSPARE : 0),
350 1.13.2.1 bouyer sizeof(RF_RaidDisk_t), (RF_RaidDisk_t *),
351 1.13.2.1 bouyer raidPtr->cleanupList);
352 1.13.2.1 bouyer if (disks[r] == NULL) {
353 1.13.2.1 bouyer ret = ENOMEM;
354 1.13.2.1 bouyer goto fail;
355 1.13.2.1 bouyer }
356 1.13.2.1 bouyer /* get more space for device specific stuff.. */
357 1.13.2.1 bouyer RF_CallocAndAdd(raidPtr->raid_cinfo[r],
358 1.13.2.1 bouyer raidPtr->numCol + ((r == 0) ? raidPtr->numSpare : 0),
359 1.13.2.1 bouyer sizeof(struct raidcinfo), (struct raidcinfo *),
360 1.13.2.1 bouyer raidPtr->cleanupList);
361 1.13.2.1 bouyer if (raidPtr->raid_cinfo[r] == NULL) {
362 1.13.2.1 bouyer ret = ENOMEM;
363 1.13.2.1 bouyer goto fail;
364 1.13.2.1 bouyer }
365 1.13.2.1 bouyer }
366 1.13.2.1 bouyer return(0);
367 1.13.2.1 bouyer fail:
368 1.13.2.1 bouyer rf_UnconfigureVnodes( raidPtr );
369 1.13.2.1 bouyer
370 1.13.2.1 bouyer return(ret);
371 1.13.2.1 bouyer }
372 1.13.2.1 bouyer
373 1.13.2.1 bouyer
374 1.13.2.1 bouyer /* configure a single disk during auto-configuration at boot */
375 1.13.2.1 bouyer int
376 1.13.2.1 bouyer rf_AutoConfigureDisks(raidPtr, cfgPtr, auto_config)
377 1.13.2.1 bouyer RF_Raid_t *raidPtr;
378 1.13.2.1 bouyer RF_Config_t *cfgPtr;
379 1.13.2.1 bouyer RF_AutoConfig_t *auto_config;
380 1.13.2.1 bouyer {
381 1.13.2.1 bouyer RF_RaidDisk_t **disks;
382 1.13.2.1 bouyer RF_RaidDisk_t *diskPtr;
383 1.13.2.1 bouyer RF_RowCol_t r, c;
384 1.13.2.1 bouyer RF_SectorCount_t min_numblks = (RF_SectorCount_t) 0x7FFFFFFFFFFFLL;
385 1.13.2.1 bouyer int bs, ret;
386 1.13.2.1 bouyer int numFailuresThisRow;
387 1.13.2.1 bouyer int force;
388 1.13.2.1 bouyer RF_AutoConfig_t *ac;
389 1.13.2.1 bouyer int parity_good;
390 1.13.2.1 bouyer int mod_counter;
391 1.13.2.1 bouyer int mod_counter_found;
392 1.13.2.1 bouyer
393 1.13.2.1 bouyer #if DEBUG
394 1.13.2.1 bouyer printf("Starting autoconfiguration of RAID set...\n");
395 1.13.2.1 bouyer #endif
396 1.13.2.1 bouyer force = cfgPtr->force;
397 1.13.2.1 bouyer
398 1.13.2.1 bouyer ret = rf_AllocDiskStructures(raidPtr, cfgPtr);
399 1.13.2.1 bouyer if (ret)
400 1.13.2.1 bouyer goto fail;
401 1.13.2.1 bouyer
402 1.13.2.1 bouyer disks = raidPtr->Disks;
403 1.13.2.1 bouyer
404 1.13.2.1 bouyer /* assume the parity will be fine.. */
405 1.13.2.1 bouyer parity_good = RF_RAID_CLEAN;
406 1.13.2.1 bouyer
407 1.13.2.1 bouyer /* Check for mod_counters that are too low */
408 1.13.2.1 bouyer mod_counter_found = 0;
409 1.13.2.1 bouyer ac = auto_config;
410 1.13.2.1 bouyer while(ac!=NULL) {
411 1.13.2.1 bouyer if (mod_counter_found==0) {
412 1.13.2.1 bouyer mod_counter = ac->clabel->mod_counter;
413 1.13.2.1 bouyer mod_counter_found = 1;
414 1.13.2.1 bouyer } else {
415 1.13.2.1 bouyer if (ac->clabel->mod_counter > mod_counter) {
416 1.13.2.1 bouyer mod_counter = ac->clabel->mod_counter;
417 1.13.2.1 bouyer }
418 1.13.2.1 bouyer }
419 1.13.2.1 bouyer ac->flag = 0; /* clear the general purpose flag */
420 1.13.2.1 bouyer ac = ac->next;
421 1.13.2.1 bouyer }
422 1.13.2.1 bouyer
423 1.13.2.1 bouyer for (r = 0; r < raidPtr->numRow; r++) {
424 1.13.2.1 bouyer numFailuresThisRow = 0;
425 1.13.2.1 bouyer for (c = 0; c < raidPtr->numCol; c++) {
426 1.13.2.1 bouyer diskPtr = &disks[r][c];
427 1.13.2.1 bouyer
428 1.13.2.1 bouyer /* find this row/col in the autoconfig */
429 1.13.2.1 bouyer #if DEBUG
430 1.13.2.1 bouyer printf("Looking for %d,%d in autoconfig\n",r,c);
431 1.13.2.1 bouyer #endif
432 1.13.2.1 bouyer ac = auto_config;
433 1.13.2.1 bouyer while(ac!=NULL) {
434 1.13.2.1 bouyer if (ac->clabel==NULL) {
435 1.13.2.1 bouyer /* big-time bad news. */
436 1.13.2.1 bouyer goto fail;
437 1.13.2.1 bouyer }
438 1.13.2.1 bouyer if ((ac->clabel->row == r) &&
439 1.13.2.1 bouyer (ac->clabel->column == c) &&
440 1.13.2.1 bouyer (ac->clabel->mod_counter == mod_counter)) {
441 1.13.2.1 bouyer /* it's this one... */
442 1.13.2.1 bouyer /* flag it as 'used', so we don't
443 1.13.2.1 bouyer free it later. */
444 1.13.2.1 bouyer ac->flag = 1;
445 1.13.2.1 bouyer #if DEBUG
446 1.13.2.1 bouyer printf("Found: %s at %d,%d\n",
447 1.13.2.1 bouyer ac->devname,r,c);
448 1.13.2.1 bouyer #endif
449 1.13.2.1 bouyer
450 1.13.2.1 bouyer break;
451 1.13.2.1 bouyer }
452 1.13.2.1 bouyer ac=ac->next;
453 1.13.2.1 bouyer }
454 1.13.2.1 bouyer
455 1.13.2.1 bouyer if (ac==NULL) {
456 1.13.2.1 bouyer /* we didn't find an exact match with a
457 1.13.2.1 bouyer correct mod_counter above... can we
458 1.13.2.1 bouyer find one with an incorrect mod_counter
459 1.13.2.1 bouyer to use instead? (this one, if we find
460 1.13.2.1 bouyer it, will be marked as failed once the
461 1.13.2.1 bouyer set configures)
462 1.13.2.1 bouyer */
463 1.13.2.1 bouyer
464 1.13.2.1 bouyer ac = auto_config;
465 1.13.2.1 bouyer while(ac!=NULL) {
466 1.13.2.1 bouyer if (ac->clabel==NULL) {
467 1.13.2.1 bouyer /* big-time bad news. */
468 1.13.2.1 bouyer goto fail;
469 1.13.2.1 bouyer }
470 1.13.2.1 bouyer if ((ac->clabel->row == r) &&
471 1.13.2.1 bouyer (ac->clabel->column == c)) {
472 1.13.2.1 bouyer /* it's this one...
473 1.13.2.1 bouyer flag it as 'used', so we
474 1.13.2.1 bouyer don't free it later. */
475 1.13.2.1 bouyer ac->flag = 1;
476 1.13.2.1 bouyer #if DEBUG
477 1.13.2.1 bouyer printf("Found(low mod_counter): %s at %d,%d\n",
478 1.13.2.1 bouyer ac->devname,r,c);
479 1.13.2.1 bouyer #endif
480 1.13.2.1 bouyer
481 1.13.2.1 bouyer break;
482 1.13.2.1 bouyer }
483 1.13.2.1 bouyer ac=ac->next;
484 1.13.2.1 bouyer }
485 1.13.2.1 bouyer }
486 1.13.2.1 bouyer
487 1.13.2.1 bouyer
488 1.13.2.1 bouyer
489 1.13.2.1 bouyer if (ac!=NULL) {
490 1.13.2.1 bouyer /* Found it. Configure it.. */
491 1.13.2.1 bouyer diskPtr->blockSize = ac->clabel->blockSize;
492 1.13.2.1 bouyer diskPtr->numBlocks = ac->clabel->numBlocks;
493 1.13.2.1 bouyer /* Note: rf_protectedSectors is already
494 1.13.2.1 bouyer factored into numBlocks here */
495 1.13.2.1 bouyer raidPtr->raid_cinfo[r][c].ci_vp = ac->vp;
496 1.13.2.1 bouyer raidPtr->raid_cinfo[r][c].ci_dev = ac->dev;
497 1.13.2.1 bouyer
498 1.13.2.1 bouyer memcpy(&raidPtr->raid_cinfo[r][c].ci_label,
499 1.13.2.1 bouyer ac->clabel, sizeof(*ac->clabel));
500 1.13.2.1 bouyer sprintf(diskPtr->devname, "/dev/%s",
501 1.13.2.1 bouyer ac->devname);
502 1.13.2.1 bouyer
503 1.13.2.1 bouyer /* note the fact that this component was
504 1.13.2.1 bouyer autoconfigured. You'll need this info
505 1.13.2.1 bouyer later. Trust me :) */
506 1.13.2.1 bouyer diskPtr->auto_configured = 1;
507 1.13.2.1 bouyer diskPtr->dev = ac->dev;
508 1.13.2.1 bouyer
509 1.13.2.1 bouyer /*
510 1.13.2.1 bouyer * we allow the user to specify that
511 1.13.2.1 bouyer * only a fraction of the disks should
512 1.13.2.1 bouyer * be used this is just for debug: it
513 1.13.2.1 bouyer * speeds up the parity scan
514 1.13.2.1 bouyer */
515 1.13.2.1 bouyer
516 1.13.2.1 bouyer diskPtr->numBlocks = diskPtr->numBlocks *
517 1.13.2.1 bouyer rf_sizePercentage / 100;
518 1.13.2.1 bouyer
519 1.13.2.1 bouyer /* XXX these will get set multiple times,
520 1.13.2.1 bouyer but since we're autoconfiguring, they'd
521 1.13.2.1 bouyer better be always the same each time!
522 1.13.2.1 bouyer If not, this is the least of your worries */
523 1.13.2.1 bouyer
524 1.13.2.1 bouyer bs = diskPtr->blockSize;
525 1.13.2.1 bouyer min_numblks = diskPtr->numBlocks;
526 1.13.2.1 bouyer
527 1.13.2.1 bouyer /* this gets done multiple times, but that's
528 1.13.2.1 bouyer fine -- the serial number will be the same
529 1.13.2.1 bouyer for all components, guaranteed */
530 1.13.2.1 bouyer raidPtr->serial_number =
531 1.13.2.1 bouyer ac->clabel->serial_number;
532 1.13.2.1 bouyer /* check the last time the label
533 1.13.2.1 bouyer was modified */
534 1.13.2.1 bouyer if (ac->clabel->mod_counter !=
535 1.13.2.1 bouyer mod_counter) {
536 1.13.2.1 bouyer /* Even though we've filled in all
537 1.13.2.1 bouyer of the above, we don't trust
538 1.13.2.1 bouyer this component since it's
539 1.13.2.1 bouyer modification counter is not
540 1.13.2.1 bouyer in sync with the rest, and we really
541 1.13.2.1 bouyer consider it to be failed. */
542 1.13.2.1 bouyer disks[r][c].status = rf_ds_failed;
543 1.13.2.1 bouyer numFailuresThisRow++;
544 1.13.2.1 bouyer } else {
545 1.13.2.1 bouyer if (ac->clabel->clean !=
546 1.13.2.1 bouyer RF_RAID_CLEAN) {
547 1.13.2.1 bouyer parity_good = RF_RAID_DIRTY;
548 1.13.2.1 bouyer }
549 1.13.2.1 bouyer }
550 1.13.2.1 bouyer } else {
551 1.13.2.1 bouyer /* Didn't find it at all!!
552 1.13.2.1 bouyer Component must really be dead */
553 1.13.2.1 bouyer disks[r][c].status = rf_ds_failed;
554 1.13.2.1 bouyer sprintf(disks[r][c].devname,"component%d",
555 1.13.2.1 bouyer r * raidPtr->numCol + c);
556 1.13.2.1 bouyer numFailuresThisRow++;
557 1.13.2.1 bouyer }
558 1.13.2.1 bouyer }
559 1.13.2.1 bouyer /* XXX fix for n-fault tolerant */
560 1.13.2.1 bouyer /* XXX this should probably check to see how many failures
561 1.13.2.1 bouyer we can handle for this configuration! */
562 1.13.2.1 bouyer if (numFailuresThisRow > 0)
563 1.13.2.1 bouyer raidPtr->status[r] = rf_rs_degraded;
564 1.13.2.1 bouyer }
565 1.13.2.1 bouyer
566 1.13.2.1 bouyer /* close the device for the ones that didn't get used */
567 1.13.2.1 bouyer
568 1.13.2.1 bouyer ac = auto_config;
569 1.13.2.1 bouyer while(ac!=NULL) {
570 1.13.2.1 bouyer if (ac->flag == 0) {
571 1.13.2.1 bouyer vn_lock(ac->vp, LK_EXCLUSIVE | LK_RETRY);
572 1.13.2.1 bouyer VOP_CLOSE(ac->vp, FREAD | FWRITE, NOCRED, 0);
573 1.13.2.1 bouyer vput(ac->vp);
574 1.13.2.1 bouyer ac->vp = NULL;
575 1.13.2.1 bouyer #if DEBUG
576 1.13.2.1 bouyer printf("Released %s from auto-config set.\n",
577 1.13.2.1 bouyer ac->devname);
578 1.13.2.1 bouyer #endif
579 1.13.2.1 bouyer }
580 1.13.2.1 bouyer ac = ac->next;
581 1.13.2.1 bouyer }
582 1.13.2.1 bouyer
583 1.13.2.1 bouyer raidPtr->mod_counter = mod_counter;
584 1.13.2.1 bouyer
585 1.13.2.1 bouyer /* note the state of the parity, if any */
586 1.13.2.1 bouyer raidPtr->parity_good = parity_good;
587 1.13.2.1 bouyer raidPtr->sectorsPerDisk = min_numblks;
588 1.13.2.1 bouyer raidPtr->logBytesPerSector = ffs(bs) - 1;
589 1.13.2.1 bouyer raidPtr->bytesPerSector = bs;
590 1.13.2.1 bouyer raidPtr->sectorMask = bs - 1;
591 1.13.2.1 bouyer return (0);
592 1.13.2.1 bouyer
593 1.13.2.1 bouyer fail:
594 1.13.2.1 bouyer
595 1.13.2.1 bouyer rf_UnconfigureVnodes( raidPtr );
596 1.13.2.1 bouyer
597 1.13.2.1 bouyer return (ret);
598 1.1 oster
599 1.13.2.1 bouyer }
600 1.1 oster
601 1.1 oster /* configure a single disk in the array */
602 1.5 oster int
603 1.6 oster rf_ConfigureDisk(raidPtr, buf, diskPtr, row, col)
604 1.6 oster RF_Raid_t *raidPtr;
605 1.5 oster char *buf;
606 1.5 oster RF_RaidDisk_t *diskPtr;
607 1.5 oster RF_RowCol_t row;
608 1.5 oster RF_RowCol_t col;
609 1.1 oster {
610 1.5 oster char *p;
611 1.5 oster int retcode;
612 1.1 oster
613 1.1 oster struct partinfo dpart;
614 1.1 oster struct vnode *vp;
615 1.1 oster struct vattr va;
616 1.1 oster struct proc *proc;
617 1.5 oster int error;
618 1.1 oster
619 1.5 oster retcode = 0;
620 1.5 oster p = rf_find_non_white(buf);
621 1.5 oster if (p[strlen(p) - 1] == '\n') {
622 1.5 oster /* strip off the newline */
623 1.5 oster p[strlen(p) - 1] = '\0';
624 1.5 oster }
625 1.5 oster (void) strcpy(diskPtr->devname, p);
626 1.1 oster
627 1.13 oster proc = raidPtr->engine_thread;
628 1.5 oster
629 1.5 oster /* Let's start by claiming the component is fine and well... */
630 1.5 oster diskPtr->status = rf_ds_optimal;
631 1.5 oster
632 1.5 oster raidPtr->raid_cinfo[row][col].ci_vp = NULL;
633 1.5 oster raidPtr->raid_cinfo[row][col].ci_dev = NULL;
634 1.5 oster
635 1.5 oster error = raidlookup(diskPtr->devname, proc, &vp);
636 1.5 oster if (error) {
637 1.5 oster printf("raidlookup on device: %s failed!\n", diskPtr->devname);
638 1.5 oster if (error == ENXIO) {
639 1.6 oster /* the component isn't there... must be dead :-( */
640 1.5 oster diskPtr->status = rf_ds_failed;
641 1.5 oster } else {
642 1.5 oster return (error);
643 1.5 oster }
644 1.5 oster }
645 1.5 oster if (diskPtr->status == rf_ds_optimal) {
646 1.5 oster
647 1.5 oster if ((error = VOP_GETATTR(vp, &va, proc->p_ucred, proc)) != 0) {
648 1.5 oster return (error);
649 1.5 oster }
650 1.5 oster error = VOP_IOCTL(vp, DIOCGPART, (caddr_t) & dpart,
651 1.6 oster FREAD, proc->p_ucred, proc);
652 1.5 oster if (error) {
653 1.5 oster return (error);
654 1.5 oster }
655 1.6 oster
656 1.5 oster diskPtr->blockSize = dpart.disklab->d_secsize;
657 1.6 oster
658 1.5 oster diskPtr->numBlocks = dpart.part->p_size - rf_protectedSectors;
659 1.13.2.1 bouyer diskPtr->partitionSize = dpart.part->p_size;
660 1.13.2.1 bouyer
661 1.5 oster raidPtr->raid_cinfo[row][col].ci_vp = vp;
662 1.5 oster raidPtr->raid_cinfo[row][col].ci_dev = va.va_rdev;
663 1.6 oster
664 1.13.2.1 bouyer /* This component was not automatically configured */
665 1.13.2.1 bouyer diskPtr->auto_configured = 0;
666 1.6 oster diskPtr->dev = va.va_rdev;
667 1.6 oster
668 1.6 oster /* we allow the user to specify that only a fraction of the
669 1.6 oster * disks should be used this is just for debug: it speeds up
670 1.6 oster * the parity scan */
671 1.6 oster diskPtr->numBlocks = diskPtr->numBlocks *
672 1.6 oster rf_sizePercentage / 100;
673 1.6 oster }
674 1.6 oster return (0);
675 1.6 oster }
676 1.6 oster
677 1.7 oster static void
678 1.7 oster rf_print_label_status( raidPtr, row, column, dev_name, ci_label )
679 1.7 oster RF_Raid_t *raidPtr;
680 1.7 oster int row;
681 1.7 oster int column;
682 1.7 oster char *dev_name;
683 1.7 oster RF_ComponentLabel_t *ci_label;
684 1.7 oster {
685 1.7 oster
686 1.7 oster printf("raid%d: Component %s being configured at row: %d col: %d\n",
687 1.7 oster raidPtr->raidid, dev_name, row, column );
688 1.7 oster printf(" Row: %d Column: %d Num Rows: %d Num Columns: %d\n",
689 1.7 oster ci_label->row, ci_label->column,
690 1.7 oster ci_label->num_rows, ci_label->num_columns);
691 1.7 oster printf(" Version: %d Serial Number: %d Mod Counter: %d\n",
692 1.7 oster ci_label->version, ci_label->serial_number,
693 1.7 oster ci_label->mod_counter);
694 1.11 oster printf(" Clean: %s Status: %d\n",
695 1.11 oster ci_label->clean ? "Yes" : "No", ci_label->status );
696 1.7 oster }
697 1.7 oster
698 1.7 oster static int rf_check_label_vitals( raidPtr, row, column, dev_name, ci_label,
699 1.7 oster serial_number, mod_counter )
700 1.7 oster RF_Raid_t *raidPtr;
701 1.7 oster int row;
702 1.7 oster int column;
703 1.7 oster char *dev_name;
704 1.7 oster RF_ComponentLabel_t *ci_label;
705 1.7 oster int serial_number;
706 1.7 oster int mod_counter;
707 1.7 oster {
708 1.7 oster int fatal_error = 0;
709 1.7 oster
710 1.7 oster if (serial_number != ci_label->serial_number) {
711 1.7 oster printf("%s has a different serial number: %d %d\n",
712 1.7 oster dev_name, serial_number, ci_label->serial_number);
713 1.7 oster fatal_error = 1;
714 1.7 oster }
715 1.7 oster if (mod_counter != ci_label->mod_counter) {
716 1.7 oster printf("%s has a different modfication count: %d %d\n",
717 1.7 oster dev_name, mod_counter, ci_label->mod_counter);
718 1.7 oster }
719 1.7 oster
720 1.7 oster if (row != ci_label->row) {
721 1.7 oster printf("Row out of alignment for: %s\n", dev_name);
722 1.7 oster fatal_error = 1;
723 1.7 oster }
724 1.7 oster if (column != ci_label->column) {
725 1.7 oster printf("Column out of alignment for: %s\n", dev_name);
726 1.7 oster fatal_error = 1;
727 1.7 oster }
728 1.7 oster if (raidPtr->numRow != ci_label->num_rows) {
729 1.7 oster printf("Number of rows do not match for: %s\n", dev_name);
730 1.7 oster fatal_error = 1;
731 1.7 oster }
732 1.7 oster if (raidPtr->numCol != ci_label->num_columns) {
733 1.7 oster printf("Number of columns do not match for: %s\n", dev_name);
734 1.7 oster fatal_error = 1;
735 1.7 oster }
736 1.7 oster if (ci_label->clean == 0) {
737 1.7 oster /* it's not clean, but that's not fatal */
738 1.7 oster printf("%s is not clean!\n", dev_name);
739 1.7 oster }
740 1.7 oster return(fatal_error);
741 1.7 oster }
742 1.7 oster
743 1.7 oster
744 1.6 oster /*
745 1.6 oster
746 1.6 oster rf_CheckLabels() - check all the component labels for consistency.
747 1.6 oster Return an error if there is anything major amiss.
748 1.6 oster
749 1.6 oster */
750 1.1 oster
751 1.6 oster int
752 1.6 oster rf_CheckLabels( raidPtr, cfgPtr )
753 1.6 oster RF_Raid_t *raidPtr;
754 1.6 oster RF_Config_t *cfgPtr;
755 1.6 oster {
756 1.6 oster int r,c;
757 1.6 oster char *dev_name;
758 1.6 oster RF_ComponentLabel_t *ci_label;
759 1.6 oster int serial_number = 0;
760 1.7 oster int mod_number = 0;
761 1.6 oster int fatal_error = 0;
762 1.7 oster int mod_values[4];
763 1.7 oster int mod_count[4];
764 1.7 oster int ser_values[4];
765 1.7 oster int ser_count[4];
766 1.7 oster int num_ser;
767 1.7 oster int num_mod;
768 1.7 oster int i;
769 1.7 oster int found;
770 1.7 oster int hosed_row;
771 1.7 oster int hosed_column;
772 1.7 oster int too_fatal;
773 1.7 oster int parity_good;
774 1.7 oster int force;
775 1.7 oster
776 1.7 oster hosed_row = -1;
777 1.7 oster hosed_column = -1;
778 1.7 oster too_fatal = 0;
779 1.7 oster force = cfgPtr->force;
780 1.7 oster
781 1.7 oster /*
782 1.7 oster We're going to try to be a little intelligent here. If one
783 1.7 oster component's label is bogus, and we can identify that it's the
784 1.7 oster *only* one that's gone, we'll mark it as "failed" and allow
785 1.7 oster the configuration to proceed. This will be the *only* case
786 1.7 oster that we'll proceed if there would be (otherwise) fatal errors.
787 1.7 oster
788 1.7 oster Basically we simply keep a count of how many components had
789 1.7 oster what serial number. If all but one agree, we simply mark
790 1.7 oster the disagreeing component as being failed, and allow
791 1.7 oster things to come up "normally".
792 1.7 oster
793 1.7 oster We do this first for serial numbers, and then for "mod_counter".
794 1.6 oster
795 1.7 oster */
796 1.7 oster
797 1.7 oster num_ser = 0;
798 1.7 oster num_mod = 0;
799 1.7 oster for (r = 0; r < raidPtr->numRow && !fatal_error ; r++) {
800 1.7 oster for (c = 0; c < raidPtr->numCol; c++) {
801 1.7 oster ci_label = &raidPtr->raid_cinfo[r][c].ci_label;
802 1.7 oster found=0;
803 1.7 oster for(i=0;i<num_ser;i++) {
804 1.7 oster if (ser_values[i] == ci_label->serial_number) {
805 1.7 oster ser_count[i]++;
806 1.7 oster found=1;
807 1.7 oster break;
808 1.7 oster }
809 1.7 oster }
810 1.7 oster if (!found) {
811 1.7 oster ser_values[num_ser] = ci_label->serial_number;
812 1.7 oster ser_count[num_ser] = 1;
813 1.7 oster num_ser++;
814 1.7 oster if (num_ser>2) {
815 1.7 oster fatal_error = 1;
816 1.7 oster break;
817 1.7 oster }
818 1.7 oster }
819 1.7 oster found=0;
820 1.7 oster for(i=0;i<num_mod;i++) {
821 1.7 oster if (mod_values[i] == ci_label->mod_counter) {
822 1.7 oster mod_count[i]++;
823 1.7 oster found=1;
824 1.7 oster break;
825 1.7 oster }
826 1.7 oster }
827 1.7 oster if (!found) {
828 1.7 oster mod_values[num_mod] = ci_label->mod_counter;
829 1.7 oster mod_count[num_mod] = 1;
830 1.7 oster num_mod++;
831 1.7 oster if (num_mod>2) {
832 1.7 oster fatal_error = 1;
833 1.7 oster break;
834 1.7 oster }
835 1.7 oster }
836 1.7 oster }
837 1.7 oster }
838 1.7 oster #if DEBUG
839 1.7 oster printf("raid%d: Summary of serial numbers:\n", raidPtr->raidid);
840 1.7 oster for(i=0;i<num_ser;i++) {
841 1.7 oster printf("%d %d\n", ser_values[i], ser_count[i]);
842 1.7 oster }
843 1.7 oster printf("raid%d: Summary of mod counters:\n", raidPtr->raidid);
844 1.7 oster for(i=0;i<num_mod;i++) {
845 1.7 oster printf("%d %d\n", mod_values[i], mod_count[i]);
846 1.7 oster }
847 1.7 oster #endif
848 1.7 oster serial_number = ser_values[0];
849 1.7 oster if (num_ser == 2) {
850 1.7 oster if ((ser_count[0] == 1) || (ser_count[1] == 1)) {
851 1.7 oster /* Locate the maverick component */
852 1.7 oster if (ser_count[1] > ser_count[0]) {
853 1.7 oster serial_number = ser_values[1];
854 1.7 oster }
855 1.7 oster for (r = 0; r < raidPtr->numRow; r++) {
856 1.7 oster for (c = 0; c < raidPtr->numCol; c++) {
857 1.7 oster ci_label = &raidPtr->raid_cinfo[r][c].ci_label;
858 1.7 oster if (serial_number !=
859 1.7 oster ci_label->serial_number) {
860 1.7 oster hosed_row = r;
861 1.7 oster hosed_column = c;
862 1.7 oster break;
863 1.7 oster }
864 1.7 oster }
865 1.7 oster }
866 1.7 oster printf("Hosed component: %s\n",
867 1.7 oster &cfgPtr->devnames[hosed_row][hosed_column][0]);
868 1.7 oster if (!force) {
869 1.7 oster /* we'll fail this component, as if there are
870 1.7 oster other major errors, we arn't forcing things
871 1.7 oster and we'll abort the config anyways */
872 1.7 oster raidPtr->Disks[hosed_row][hosed_column].status
873 1.7 oster = rf_ds_failed;
874 1.7 oster raidPtr->numFailures++;
875 1.7 oster raidPtr->status[hosed_row] = rf_rs_degraded;
876 1.7 oster }
877 1.7 oster } else {
878 1.7 oster too_fatal = 1;
879 1.7 oster }
880 1.7 oster if (cfgPtr->parityConfig == '0') {
881 1.7 oster /* We've identified two different serial numbers.
882 1.7 oster RAID 0 can't cope with that, so we'll punt */
883 1.7 oster too_fatal = 1;
884 1.7 oster }
885 1.7 oster
886 1.7 oster }
887 1.7 oster
888 1.7 oster /* record the serial number for later. If we bail later, setting
889 1.7 oster this doesn't matter, otherwise we've got the best guess at the
890 1.7 oster correct serial number */
891 1.7 oster raidPtr->serial_number = serial_number;
892 1.7 oster
893 1.7 oster mod_number = mod_values[0];
894 1.7 oster if (num_mod == 2) {
895 1.7 oster if ((mod_count[0] == 1) || (mod_count[1] == 1)) {
896 1.7 oster /* Locate the maverick component */
897 1.7 oster if (mod_count[1] > mod_count[0]) {
898 1.7 oster mod_number = mod_values[1];
899 1.8 oster } else if (mod_count[1] < mod_count[0]) {
900 1.8 oster mod_number = mod_values[0];
901 1.8 oster } else {
902 1.8 oster /* counts of different modification values
903 1.8 oster are the same. Assume greater value is
904 1.8 oster the correct one, all other things
905 1.8 oster considered */
906 1.8 oster if (mod_values[0] > mod_values[1]) {
907 1.8 oster mod_number = mod_values[0];
908 1.8 oster } else {
909 1.8 oster mod_number = mod_values[1];
910 1.8 oster }
911 1.8 oster
912 1.8 oster }
913 1.7 oster for (r = 0; r < raidPtr->numRow && !too_fatal ; r++) {
914 1.7 oster for (c = 0; c < raidPtr->numCol; c++) {
915 1.7 oster ci_label = &raidPtr->raid_cinfo[r][c].ci_label;
916 1.7 oster if (mod_number !=
917 1.7 oster ci_label->mod_counter) {
918 1.7 oster if ( ( hosed_row == r ) &&
919 1.7 oster ( hosed_column == c )) {
920 1.7 oster /* same one. Can
921 1.7 oster deal with it. */
922 1.7 oster } else {
923 1.7 oster hosed_row = r;
924 1.7 oster hosed_column = c;
925 1.7 oster if (num_ser != 1) {
926 1.7 oster too_fatal = 1;
927 1.7 oster break;
928 1.7 oster }
929 1.7 oster }
930 1.7 oster }
931 1.7 oster }
932 1.7 oster }
933 1.7 oster printf("Hosed component: %s\n",
934 1.7 oster &cfgPtr->devnames[hosed_row][hosed_column][0]);
935 1.7 oster if (!force) {
936 1.7 oster /* we'll fail this component, as if there are
937 1.7 oster other major errors, we arn't forcing things
938 1.7 oster and we'll abort the config anyways */
939 1.9 oster if (raidPtr->Disks[hosed_row][hosed_column].status != rf_ds_failed) {
940 1.9 oster raidPtr->Disks[hosed_row][hosed_column].status
941 1.9 oster = rf_ds_failed;
942 1.9 oster raidPtr->numFailures++;
943 1.9 oster raidPtr->status[hosed_row] = rf_rs_degraded;
944 1.9 oster }
945 1.7 oster }
946 1.7 oster } else {
947 1.7 oster too_fatal = 1;
948 1.7 oster }
949 1.7 oster if (cfgPtr->parityConfig == '0') {
950 1.7 oster /* We've identified two different mod counters.
951 1.7 oster RAID 0 can't cope with that, so we'll punt */
952 1.7 oster too_fatal = 1;
953 1.7 oster }
954 1.7 oster }
955 1.7 oster
956 1.7 oster raidPtr->mod_counter = mod_number;
957 1.7 oster
958 1.7 oster if (too_fatal) {
959 1.7 oster /* we've had both a serial number mismatch, and a mod_counter
960 1.7 oster mismatch -- and they involved two different components!!
961 1.7 oster Bail -- make things fail so that the user must force
962 1.7 oster the issue... */
963 1.7 oster hosed_row = -1;
964 1.7 oster hosed_column = -1;
965 1.7 oster }
966 1.7 oster
967 1.7 oster if (num_ser > 2) {
968 1.7 oster printf("raid%d: Too many different serial numbers!\n",
969 1.7 oster raidPtr->raidid);
970 1.7 oster }
971 1.7 oster
972 1.7 oster if (num_mod > 2) {
973 1.7 oster printf("raid%d: Too many different mod counters!\n",
974 1.7 oster raidPtr->raidid);
975 1.7 oster }
976 1.7 oster
977 1.7 oster /* we start by assuming the parity will be good, and flee from
978 1.7 oster that notion at the slightest sign of trouble */
979 1.7 oster
980 1.7 oster parity_good = RF_RAID_CLEAN;
981 1.6 oster for (r = 0; r < raidPtr->numRow; r++) {
982 1.6 oster for (c = 0; c < raidPtr->numCol; c++) {
983 1.6 oster dev_name = &cfgPtr->devnames[r][c][0];
984 1.6 oster ci_label = &raidPtr->raid_cinfo[r][c].ci_label;
985 1.7 oster
986 1.7 oster if ((r == hosed_row) && (c == hosed_column)) {
987 1.7 oster printf("raid%d: Ignoring %s\n",
988 1.7 oster raidPtr->raidid, dev_name);
989 1.7 oster } else {
990 1.7 oster rf_print_label_status( raidPtr, r, c,
991 1.7 oster dev_name, ci_label );
992 1.7 oster if (rf_check_label_vitals( raidPtr, r, c,
993 1.7 oster dev_name, ci_label,
994 1.7 oster serial_number,
995 1.7 oster mod_number )) {
996 1.6 oster fatal_error = 1;
997 1.6 oster }
998 1.7 oster if (ci_label->clean != RF_RAID_CLEAN) {
999 1.7 oster parity_good = RF_RAID_DIRTY;
1000 1.6 oster }
1001 1.6 oster }
1002 1.6 oster }
1003 1.6 oster }
1004 1.7 oster if (fatal_error) {
1005 1.7 oster parity_good = RF_RAID_DIRTY;
1006 1.7 oster }
1007 1.7 oster
1008 1.7 oster /* we note the state of the parity */
1009 1.7 oster raidPtr->parity_good = parity_good;
1010 1.6 oster
1011 1.6 oster return(fatal_error);
1012 1.6 oster }
1013 1.6 oster
1014 1.6 oster int
1015 1.6 oster rf_add_hot_spare(raidPtr, sparePtr)
1016 1.6 oster RF_Raid_t *raidPtr;
1017 1.7 oster RF_SingleComponent_t *sparePtr;
1018 1.6 oster {
1019 1.6 oster RF_RaidDisk_t *disks;
1020 1.9 oster RF_DiskQueue_t *spareQueues;
1021 1.6 oster int ret;
1022 1.6 oster unsigned int bs;
1023 1.6 oster int spare_number;
1024 1.6 oster
1025 1.13.2.1 bouyer #if 0
1026 1.6 oster printf("Just in rf_add_hot_spare: %d\n",raidPtr->numSpare);
1027 1.6 oster printf("Num col: %d\n",raidPtr->numCol);
1028 1.13.2.1 bouyer #endif
1029 1.6 oster if (raidPtr->numSpare >= RF_MAXSPARE) {
1030 1.6 oster RF_ERRORMSG1("Too many spares: %d\n", raidPtr->numSpare);
1031 1.6 oster return(EINVAL);
1032 1.6 oster }
1033 1.9 oster
1034 1.10 oster RF_LOCK_MUTEX(raidPtr->mutex);
1035 1.10 oster
1036 1.6 oster /* the beginning of the spares... */
1037 1.6 oster disks = &raidPtr->Disks[0][raidPtr->numCol];
1038 1.6 oster
1039 1.6 oster spare_number = raidPtr->numSpare;
1040 1.1 oster
1041 1.7 oster ret = rf_ConfigureDisk(raidPtr, sparePtr->component_name,
1042 1.6 oster &disks[spare_number], 0,
1043 1.6 oster raidPtr->numCol + spare_number);
1044 1.1 oster
1045 1.6 oster if (ret)
1046 1.6 oster goto fail;
1047 1.6 oster if (disks[spare_number].status != rf_ds_optimal) {
1048 1.6 oster RF_ERRORMSG1("Warning: spare disk %s failed TUR\n",
1049 1.7 oster sparePtr->component_name);
1050 1.6 oster ret=EINVAL;
1051 1.6 oster goto fail;
1052 1.6 oster } else {
1053 1.6 oster disks[spare_number].status = rf_ds_spare;
1054 1.6 oster DPRINTF6("Spare Disk %d: dev %s numBlocks %ld blockSize %d (%ld MB)\n", spare_number,
1055 1.6 oster disks[spare_number].devname,
1056 1.6 oster (long int) disks[spare_number].numBlocks,
1057 1.6 oster disks[spare_number].blockSize,
1058 1.6 oster (long int) disks[spare_number].numBlocks *
1059 1.6 oster disks[spare_number].blockSize / 1024 / 1024);
1060 1.6 oster }
1061 1.6 oster
1062 1.1 oster
1063 1.6 oster /* check sizes and block sizes on the spare disk */
1064 1.6 oster bs = 1 << raidPtr->logBytesPerSector;
1065 1.6 oster if (disks[spare_number].blockSize != bs) {
1066 1.6 oster RF_ERRORMSG3("Block size of %d on spare disk %s is not the same as on other disks (%d)\n", disks[spare_number].blockSize, disks[spare_number].devname, bs);
1067 1.6 oster ret = EINVAL;
1068 1.6 oster goto fail;
1069 1.6 oster }
1070 1.6 oster if (disks[spare_number].numBlocks < raidPtr->sectorsPerDisk) {
1071 1.6 oster RF_ERRORMSG3("Spare disk %s (%d blocks) is too small to serve as a spare (need %ld blocks)\n",
1072 1.6 oster disks[spare_number].devname,
1073 1.6 oster disks[spare_number].blockSize,
1074 1.6 oster (long int) raidPtr->sectorsPerDisk);
1075 1.6 oster ret = EINVAL;
1076 1.6 oster goto fail;
1077 1.6 oster } else {
1078 1.6 oster if (disks[spare_number].numBlocks >
1079 1.6 oster raidPtr->sectorsPerDisk) {
1080 1.6 oster RF_ERRORMSG2("Warning: truncating spare disk %s to %ld blocks\n", disks[spare_number].devname,
1081 1.6 oster (long int) raidPtr->sectorsPerDisk);
1082 1.6 oster
1083 1.6 oster disks[spare_number].numBlocks = raidPtr->sectorsPerDisk;
1084 1.6 oster }
1085 1.5 oster }
1086 1.6 oster
1087 1.9 oster spareQueues = &raidPtr->Queues[0][raidPtr->numCol];
1088 1.13.2.1 bouyer ret = rf_ConfigureDiskQueue( raidPtr, &spareQueues[spare_number],
1089 1.9 oster 0, raidPtr->numCol + spare_number,
1090 1.13.2.1 bouyer raidPtr->qType,
1091 1.9 oster raidPtr->sectorsPerDisk,
1092 1.13.2.1 bouyer raidPtr->Disks[0][raidPtr->numCol +
1093 1.13.2.1 bouyer spare_number].dev,
1094 1.13.2.1 bouyer raidPtr->maxOutstanding,
1095 1.9 oster &raidPtr->shutdownList,
1096 1.9 oster raidPtr->cleanupList);
1097 1.9 oster
1098 1.9 oster
1099 1.6 oster raidPtr->numSpare++;
1100 1.10 oster RF_UNLOCK_MUTEX(raidPtr->mutex);
1101 1.5 oster return (0);
1102 1.6 oster
1103 1.6 oster fail:
1104 1.10 oster RF_UNLOCK_MUTEX(raidPtr->mutex);
1105 1.6 oster return(ret);
1106 1.6 oster }
1107 1.6 oster
1108 1.6 oster int
1109 1.6 oster rf_remove_hot_spare(raidPtr,sparePtr)
1110 1.6 oster RF_Raid_t *raidPtr;
1111 1.7 oster RF_SingleComponent_t *sparePtr;
1112 1.6 oster {
1113 1.6 oster int spare_number;
1114 1.6 oster
1115 1.6 oster
1116 1.6 oster if (raidPtr->numSpare==0) {
1117 1.6 oster printf("No spares to remove!\n");
1118 1.6 oster return(EINVAL);
1119 1.6 oster }
1120 1.6 oster
1121 1.7 oster spare_number = sparePtr->column;
1122 1.6 oster
1123 1.6 oster return(EINVAL); /* XXX not implemented yet */
1124 1.6 oster #if 0
1125 1.6 oster if (spare_number < 0 || spare_number > raidPtr->numSpare) {
1126 1.6 oster return(EINVAL);
1127 1.6 oster }
1128 1.6 oster
1129 1.6 oster /* verify that this spare isn't in use... */
1130 1.6 oster
1131 1.6 oster
1132 1.6 oster
1133 1.6 oster
1134 1.6 oster /* it's gone.. */
1135 1.6 oster
1136 1.6 oster raidPtr->numSpare--;
1137 1.6 oster
1138 1.6 oster return(0);
1139 1.6 oster #endif
1140 1.1 oster }
1141 1.6 oster
1142 1.6 oster
1143 1.13.2.1 bouyer int
1144 1.13.2.1 bouyer rf_delete_component(raidPtr,component)
1145 1.13.2.1 bouyer RF_Raid_t *raidPtr;
1146 1.13.2.1 bouyer RF_SingleComponent_t *component;
1147 1.13.2.1 bouyer {
1148 1.13.2.1 bouyer RF_RaidDisk_t *disks;
1149 1.13.2.1 bouyer
1150 1.13.2.1 bouyer if ((component->row < 0) ||
1151 1.13.2.1 bouyer (component->row >= raidPtr->numRow) ||
1152 1.13.2.1 bouyer (component->column < 0) ||
1153 1.13.2.1 bouyer (component->column >= raidPtr->numCol)) {
1154 1.13.2.1 bouyer return(EINVAL);
1155 1.13.2.1 bouyer }
1156 1.13.2.1 bouyer
1157 1.13.2.1 bouyer disks = &raidPtr->Disks[component->row][component->column];
1158 1.13.2.1 bouyer
1159 1.13.2.1 bouyer /* 1. This component must be marked as 'failed' */
1160 1.13.2.1 bouyer
1161 1.13.2.1 bouyer return(EINVAL); /* Not implemented yet. */
1162 1.13.2.1 bouyer }
1163 1.13.2.1 bouyer
1164 1.13.2.1 bouyer int
1165 1.13.2.1 bouyer rf_incorporate_hot_spare(raidPtr,component)
1166 1.13.2.1 bouyer RF_Raid_t *raidPtr;
1167 1.13.2.1 bouyer RF_SingleComponent_t *component;
1168 1.13.2.1 bouyer {
1169 1.13.2.1 bouyer
1170 1.13.2.1 bouyer /* Issues here include how to 'move' this in if there is IO
1171 1.13.2.1 bouyer taking place (e.g. component queues and such) */
1172 1.13.2.1 bouyer
1173 1.13.2.1 bouyer return(EINVAL); /* Not implemented yet. */
1174 1.13.2.1 bouyer }
1175