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