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