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