Home | History | Annotate | Line # | Download | only in raidframe
rf_driver.c revision 1.97
      1 /*	$NetBSD: rf_driver.c,v 1.97 2004/03/20 04:22:05 oster Exp $	*/
      2 /*-
      3  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to The NetBSD Foundation
      7  * by Greg Oster
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *        This product includes software developed by the NetBSD
     20  *        Foundation, Inc. and its contributors.
     21  * 4. Neither the name of The NetBSD Foundation nor the names of its
     22  *    contributors may be used to endorse or promote products derived
     23  *    from this software without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 /*
     39  * Copyright (c) 1995 Carnegie-Mellon University.
     40  * All rights reserved.
     41  *
     42  * Author: Mark Holland, Khalil Amiri, Claudson Bornstein, William V. Courtright II,
     43  *         Robby Findler, Daniel Stodolsky, Rachad Youssef, Jim Zelenka
     44  *
     45  * Permission to use, copy, modify and distribute this software and
     46  * its documentation is hereby granted, provided that both the copyright
     47  * notice and this permission notice appear in all copies of the
     48  * software, derivative works or modified versions, and any portions
     49  * thereof, and that both notices appear in supporting documentation.
     50  *
     51  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     52  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     53  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     54  *
     55  * Carnegie Mellon requests users of this software to return to
     56  *
     57  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     58  *  School of Computer Science
     59  *  Carnegie Mellon University
     60  *  Pittsburgh PA 15213-3890
     61  *
     62  * any improvements or extensions that they make and grant Carnegie the
     63  * rights to redistribute these changes.
     64  */
     65 
     66 /******************************************************************************
     67  *
     68  * rf_driver.c -- main setup, teardown, and access routines for the RAID driver
     69  *
     70  * all routines are prefixed with rf_ (raidframe), to avoid conficts.
     71  *
     72  ******************************************************************************/
     73 
     74 
     75 #include <sys/cdefs.h>
     76 __KERNEL_RCSID(0, "$NetBSD: rf_driver.c,v 1.97 2004/03/20 04:22:05 oster Exp $");
     77 
     78 #include "opt_raid_diagnostic.h"
     79 
     80 #include <sys/param.h>
     81 #include <sys/systm.h>
     82 #include <sys/ioctl.h>
     83 #include <sys/fcntl.h>
     84 #include <sys/vnode.h>
     85 
     86 
     87 #include "rf_archs.h"
     88 #include "rf_threadstuff.h"
     89 
     90 #include <sys/errno.h>
     91 
     92 #include "rf_raid.h"
     93 #include "rf_dag.h"
     94 #include "rf_aselect.h"
     95 #include "rf_diskqueue.h"
     96 #include "rf_parityscan.h"
     97 #include "rf_alloclist.h"
     98 #include "rf_dagutils.h"
     99 #include "rf_utils.h"
    100 #include "rf_etimer.h"
    101 #include "rf_acctrace.h"
    102 #include "rf_general.h"
    103 #include "rf_desc.h"
    104 #include "rf_states.h"
    105 #include "rf_decluster.h"
    106 #include "rf_map.h"
    107 #include "rf_revent.h"
    108 #include "rf_callback.h"
    109 #include "rf_engine.h"
    110 #include "rf_mcpair.h"
    111 #include "rf_nwayxor.h"
    112 #include "rf_copyback.h"
    113 #include "rf_driver.h"
    114 #include "rf_options.h"
    115 #include "rf_shutdown.h"
    116 #include "rf_kintf.h"
    117 
    118 #include <sys/buf.h>
    119 
    120 #ifndef RF_ACCESS_DEBUG
    121 #define RF_ACCESS_DEBUG 0
    122 #endif
    123 
    124 /* rad == RF_RaidAccessDesc_t */
    125 RF_DECLARE_MUTEX(rf_rad_lock)
    126 #define RF_MAX_FREE_RAD 128
    127 #define RF_MIN_FREE_RAD  32
    128 
    129 /* debug variables */
    130 char    rf_panicbuf[2048];	/* a buffer to hold an error msg when we panic */
    131 
    132 /* main configuration routines */
    133 static int raidframe_booted = 0;
    134 
    135 static void rf_ConfigureDebug(RF_Config_t * cfgPtr);
    136 static void set_debug_option(char *name, long val);
    137 static void rf_UnconfigureArray(void);
    138 static void rf_ShutdownRDFreeList(void *);
    139 static int rf_ConfigureRDFreeList(RF_ShutdownList_t **);
    140 
    141 RF_DECLARE_MUTEX(rf_printf_mutex)	/* debug only:  avoids interleaved
    142 					 * printfs by different stripes */
    143 
    144 #define SIGNAL_QUIESCENT_COND(_raid_)  wakeup(&((_raid_)->accesses_suspended))
    145 #define WAIT_FOR_QUIESCENCE(_raid_) \
    146 	ltsleep(&((_raid_)->accesses_suspended), PRIBIO, \
    147 		"raidframe quiesce", 0, &((_raid_)->access_suspend_mutex))
    148 
    149 static int configureCount = 0;	/* number of active configurations */
    150 static int isconfigged = 0;	/* is basic raidframe (non per-array)
    151 				 * stuff configged */
    152 RF_DECLARE_LKMGR_STATIC_MUTEX(configureMutex)	/* used to lock the configuration
    153 					 * stuff */
    154 static RF_ShutdownList_t *globalShutdown;	/* non array-specific
    155 						 * stuff */
    156 
    157 static int rf_ConfigureRDFreeList(RF_ShutdownList_t ** listp);
    158 
    159 /* called at system boot time */
    160 int
    161 rf_BootRaidframe()
    162 {
    163 
    164 	if (raidframe_booted)
    165 		return (EBUSY);
    166 	raidframe_booted = 1;
    167 	lockinit(&configureMutex, PRIBIO, "RAIDframe lock", 0, 0);
    168  	configureCount = 0;
    169 	isconfigged = 0;
    170 	globalShutdown = NULL;
    171 	return (0);
    172 }
    173 
    174 /*
    175  * Called whenever an array is shutdown
    176  */
    177 static void
    178 rf_UnconfigureArray()
    179 {
    180 
    181 	RF_LOCK_LKMGR_MUTEX(configureMutex);
    182 	if (--configureCount == 0) {	/* if no active configurations, shut
    183 					 * everything down */
    184 		isconfigged = 0;
    185 		rf_ShutdownList(&globalShutdown);
    186 
    187 		/*
    188 	         * We must wait until now, because the AllocList module
    189 	         * uses the DebugMem module.
    190 	         */
    191 #if RF_DEBUG_MEM
    192 		if (rf_memDebug)
    193 			rf_print_unfreed();
    194 #endif
    195 	}
    196 	RF_UNLOCK_LKMGR_MUTEX(configureMutex);
    197 }
    198 
    199 /*
    200  * Called to shut down an array.
    201  */
    202 int
    203 rf_Shutdown(RF_Raid_t *raidPtr)
    204 {
    205 	if (!raidPtr->valid) {
    206 		RF_ERRORMSG("Attempt to shut down unconfigured RAIDframe driver.  Aborting shutdown\n");
    207 		return (EINVAL);
    208 	}
    209 	/*
    210          * wait for outstanding IOs to land
    211          * As described in rf_raid.h, we use the rad_freelist lock
    212          * to protect the per-array info about outstanding descs
    213          * since we need to do freelist locking anyway, and this
    214          * cuts down on the amount of serialization we've got going
    215          * on.
    216          */
    217 	RF_LOCK_MUTEX(rf_rad_lock);
    218 	if (raidPtr->waitShutdown) {
    219 		RF_UNLOCK_MUTEX(rf_rad_lock);
    220 		return (EBUSY);
    221 	}
    222 	raidPtr->waitShutdown = 1;
    223 	while (raidPtr->nAccOutstanding) {
    224 		RF_WAIT_COND(raidPtr->outstandingCond, rf_rad_lock);
    225 	}
    226 	RF_UNLOCK_MUTEX(rf_rad_lock);
    227 
    228 	/* Wait for any parity re-writes to stop... */
    229 	while (raidPtr->parity_rewrite_in_progress) {
    230 		printf("Waiting for parity re-write to exit...\n");
    231 		tsleep(&raidPtr->parity_rewrite_in_progress, PRIBIO,
    232 		       "rfprwshutdown", 0);
    233 	}
    234 
    235 	raidPtr->valid = 0;
    236 
    237 	rf_update_component_labels(raidPtr, RF_FINAL_COMPONENT_UPDATE);
    238 
    239 	rf_UnconfigureVnodes(raidPtr);
    240 
    241 	rf_ShutdownList(&raidPtr->shutdownList);
    242 
    243 	rf_UnconfigureArray();
    244 
    245 	return (0);
    246 }
    247 
    248 
    249 #define DO_INIT_CONFIGURE(f) { \
    250 	rc = f (&globalShutdown); \
    251 	if (rc) { \
    252 		RF_ERRORMSG2("RAIDFRAME: failed %s with %d\n", RF_STRING(f), rc); \
    253 		rf_ShutdownList(&globalShutdown); \
    254 		configureCount--; \
    255 		RF_UNLOCK_LKMGR_MUTEX(configureMutex); \
    256 		return(rc); \
    257 	} \
    258 }
    259 
    260 #define DO_RAID_FAIL() { \
    261 	rf_UnconfigureVnodes(raidPtr); \
    262 	rf_ShutdownList(&raidPtr->shutdownList); \
    263 	rf_UnconfigureArray(); \
    264 }
    265 
    266 #define DO_RAID_INIT_CONFIGURE(f) { \
    267 	rc = f (&raidPtr->shutdownList, raidPtr, cfgPtr); \
    268 	if (rc) { \
    269 		RF_ERRORMSG2("RAIDFRAME: failed %s with %d\n", RF_STRING(f), rc); \
    270 		DO_RAID_FAIL(); \
    271 		return(rc); \
    272 	} \
    273 }
    274 
    275 #define DO_RAID_MUTEX(_m_) { \
    276 	rf_mutex_init((_m_)); \
    277 }
    278 
    279 int
    280 rf_Configure(RF_Raid_t *raidPtr, RF_Config_t *cfgPtr, RF_AutoConfig_t *ac)
    281 {
    282 	RF_RowCol_t col;
    283 	RF_IOBufHeader_t *tmpbuf;
    284 	int rc, i;
    285 
    286 	RF_LOCK_LKMGR_MUTEX(configureMutex);
    287 	configureCount++;
    288 	if (isconfigged == 0) {
    289 		rf_mutex_init(&rf_printf_mutex);
    290 
    291 		/* initialize globals */
    292 
    293 		DO_INIT_CONFIGURE(rf_ConfigureAllocList);
    294 
    295 		/*
    296 	         * Yes, this does make debugging general to the whole
    297 	         * system instead of being array specific. Bummer, drag.
    298 		 */
    299 		rf_ConfigureDebug(cfgPtr);
    300 		DO_INIT_CONFIGURE(rf_ConfigureDebugMem);
    301 #if RF_ACC_TRACE > 0
    302 		DO_INIT_CONFIGURE(rf_ConfigureAccessTrace);
    303 #endif
    304 		DO_INIT_CONFIGURE(rf_ConfigureMapModule);
    305 		DO_INIT_CONFIGURE(rf_ConfigureReconEvent);
    306 		DO_INIT_CONFIGURE(rf_ConfigureCallback);
    307 		DO_INIT_CONFIGURE(rf_ConfigureRDFreeList);
    308 		DO_INIT_CONFIGURE(rf_ConfigureNWayXor);
    309 		DO_INIT_CONFIGURE(rf_ConfigureStripeLockFreeList);
    310 		DO_INIT_CONFIGURE(rf_ConfigureMCPair);
    311 		DO_INIT_CONFIGURE(rf_ConfigureDAGs);
    312 		DO_INIT_CONFIGURE(rf_ConfigureDAGFuncs);
    313 		DO_INIT_CONFIGURE(rf_ConfigureReconstruction);
    314 		DO_INIT_CONFIGURE(rf_ConfigureCopyback);
    315 		DO_INIT_CONFIGURE(rf_ConfigureDiskQueueSystem);
    316 		isconfigged = 1;
    317 	}
    318 	RF_UNLOCK_LKMGR_MUTEX(configureMutex);
    319 
    320 	DO_RAID_MUTEX(&raidPtr->mutex);
    321 	/* set up the cleanup list.  Do this after ConfigureDebug so that
    322 	 * value of memDebug will be set */
    323 
    324 	rf_MakeAllocList(raidPtr->cleanupList);
    325 	if (raidPtr->cleanupList == NULL) {
    326 		DO_RAID_FAIL();
    327 		return (ENOMEM);
    328 	}
    329 	rf_ShutdownCreate(&raidPtr->shutdownList,
    330 			  (void (*) (void *)) rf_FreeAllocList,
    331 			  raidPtr->cleanupList);
    332 
    333 	raidPtr->numCol = cfgPtr->numCol;
    334 	raidPtr->numSpare = cfgPtr->numSpare;
    335 
    336 	raidPtr->status = rf_rs_optimal;
    337 	raidPtr->reconControl = NULL;
    338 
    339 	TAILQ_INIT(&(raidPtr->iodone));
    340 	simple_lock_init(&(raidPtr->iodone_lock));
    341 
    342 	DO_RAID_INIT_CONFIGURE(rf_ConfigureEngine);
    343 	DO_RAID_INIT_CONFIGURE(rf_ConfigureStripeLocks);
    344 
    345 	raidPtr->outstandingCond = 0;
    346 
    347 	raidPtr->nAccOutstanding = 0;
    348 	raidPtr->waitShutdown = 0;
    349 
    350 	DO_RAID_MUTEX(&raidPtr->access_suspend_mutex);
    351 
    352 	raidPtr->waitForReconCond = 0;
    353 
    354 	if (ac!=NULL) {
    355 		/* We have an AutoConfig structure..  Don't do the
    356 		   normal disk configuration... call the auto config
    357 		   stuff */
    358 		rf_AutoConfigureDisks(raidPtr, cfgPtr, ac);
    359 	} else {
    360 		DO_RAID_INIT_CONFIGURE(rf_ConfigureDisks);
    361 		DO_RAID_INIT_CONFIGURE(rf_ConfigureSpareDisks);
    362 	}
    363 	/* do this after ConfigureDisks & ConfigureSpareDisks to be sure dev
    364 	 * no. is set */
    365 	DO_RAID_INIT_CONFIGURE(rf_ConfigureDiskQueues);
    366 
    367 	DO_RAID_INIT_CONFIGURE(rf_ConfigureLayout);
    368 
    369 	DO_RAID_INIT_CONFIGURE(rf_ConfigurePSStatus);
    370 
    371 #if RF_INCLUDE_CHAINDECLUSTER > 0
    372 	for (col = 0; col < raidPtr->numCol; col++) {
    373 		/*
    374 		 * XXX better distribution
    375 		 */
    376 		raidPtr->hist_diskreq[col] = 0;
    377 	}
    378 #endif
    379 	raidPtr->numNewFailures = 0;
    380 	raidPtr->copyback_in_progress = 0;
    381 	raidPtr->parity_rewrite_in_progress = 0;
    382 	raidPtr->adding_hot_spare = 0;
    383 	raidPtr->recon_in_progress = 0;
    384 	raidPtr->maxOutstanding = cfgPtr->maxOutstandingDiskReqs;
    385 
    386 	/* autoconfigure and root_partition will actually get filled in
    387 	   after the config is done */
    388 	raidPtr->autoconfigure = 0;
    389 	raidPtr->root_partition = 0;
    390 	raidPtr->last_unit = raidPtr->raidid;
    391 	raidPtr->config_order = 0;
    392 
    393 	if (rf_keepAccTotals) {
    394 		raidPtr->keep_acc_totals = 1;
    395 	}
    396 
    397 	/* Allocate a bunch of buffers to be used in low-memory conditions */
    398 	raidPtr->iobuf = NULL;
    399 	/* XXX next line needs tuning... */
    400 	raidPtr->numEmergencyBuffers = 10 * raidPtr->numCol;
    401 #if DEBUG
    402 	printf("raid%d: allocating %d buffers of %d bytes.\n",
    403 	       raidPtr->raidid,
    404 	       raidPtr->numEmergencyBuffers,
    405 	       (int)(raidPtr->Layout.sectorsPerStripeUnit <<
    406 	       raidPtr->logBytesPerSector));
    407 #endif
    408 	for (i = 0; i < raidPtr->numEmergencyBuffers; i++) {
    409 		tmpbuf = malloc( raidPtr->Layout.sectorsPerStripeUnit <<
    410 				 raidPtr->logBytesPerSector,
    411 				 M_RAIDFRAME, M_NOWAIT);
    412 		if (tmpbuf) {
    413 			tmpbuf->next = raidPtr->iobuf;
    414 			raidPtr->iobuf = tmpbuf;
    415 			raidPtr->iobuf_count++;
    416 		} else {
    417 			printf("raid%d: failed to allocate emergency buffer!\n",
    418 			       raidPtr->raidid);
    419 		}
    420 	}
    421 
    422 	raidPtr->valid = 1;
    423 
    424 	printf("raid%d: %s\n", raidPtr->raidid,
    425 	       raidPtr->Layout.map->configName);
    426 	printf("raid%d: Components:", raidPtr->raidid);
    427 
    428 	for (col = 0; col < raidPtr->numCol; col++) {
    429 		printf(" %s", raidPtr->Disks[col].devname);
    430 		if (RF_DEAD_DISK(raidPtr->Disks[col].status)) {
    431 			printf("[**FAILED**]");
    432 		}
    433 	}
    434 	printf("\n");
    435 	printf("raid%d: Total Sectors: %lu (%lu MB)\n",
    436 	       raidPtr->raidid,
    437 	       (unsigned long) raidPtr->totalSectors,
    438 	       (unsigned long) (raidPtr->totalSectors / 1024 *
    439 				(1 << raidPtr->logBytesPerSector) / 1024));
    440 
    441 	return (0);
    442 }
    443 
    444 static void
    445 rf_ShutdownRDFreeList(void *ignored)
    446 {
    447 	pool_destroy(&rf_pools.rad);
    448 }
    449 
    450 static int
    451 rf_ConfigureRDFreeList(RF_ShutdownList_t **listp)
    452 {
    453 
    454 	rf_pool_init(&rf_pools.rad, sizeof(RF_RaidAccessDesc_t),
    455 		     "rf_rad_pl", RF_MIN_FREE_RAD, RF_MAX_FREE_RAD);
    456 	rf_ShutdownCreate(listp, rf_ShutdownRDFreeList, NULL);
    457 	simple_lock_init(&rf_rad_lock);
    458 	return (0);
    459 }
    460 
    461 RF_RaidAccessDesc_t *
    462 rf_AllocRaidAccDesc(RF_Raid_t *raidPtr, RF_IoType_t type,
    463 		    RF_RaidAddr_t raidAddress, RF_SectorCount_t numBlocks,
    464 		    caddr_t bufPtr, void *bp, RF_RaidAccessFlags_t flags,
    465 		    RF_AccessState_t *states)
    466 {
    467 	RF_RaidAccessDesc_t *desc;
    468 
    469 	desc = pool_get(&rf_pools.rad, PR_WAITOK);
    470 
    471 	RF_LOCK_MUTEX(rf_rad_lock);
    472 	if (raidPtr->waitShutdown) {
    473 		/*
    474 	         * Actually, we're shutting the array down. Free the desc
    475 	         * and return NULL.
    476 	         */
    477 
    478 		RF_UNLOCK_MUTEX(rf_rad_lock);
    479 		pool_put(&rf_pools.rad, desc);
    480 		return (NULL);
    481 	}
    482 	raidPtr->nAccOutstanding++;
    483 
    484 	RF_UNLOCK_MUTEX(rf_rad_lock);
    485 
    486 	desc->raidPtr = (void *) raidPtr;
    487 	desc->type = type;
    488 	desc->raidAddress = raidAddress;
    489 	desc->numBlocks = numBlocks;
    490 	desc->bufPtr = bufPtr;
    491 	desc->bp = bp;
    492 	desc->flags = flags;
    493 	desc->states = states;
    494 	desc->state = 0;
    495 
    496 	desc->status = 0;
    497 #if RF_ACC_TRACE > 0
    498 	memset((char *) &desc->tracerec, 0, sizeof(RF_AccTraceEntry_t));
    499 #endif
    500 	desc->callbackFunc = NULL;
    501 	desc->callbackArg = NULL;
    502 	desc->next = NULL;
    503 	desc->cleanupList = NULL;
    504 	rf_MakeAllocList(desc->cleanupList);
    505 	return (desc);
    506 }
    507 
    508 void
    509 rf_FreeRaidAccDesc(RF_RaidAccessDesc_t *desc)
    510 {
    511 	RF_Raid_t *raidPtr = desc->raidPtr;
    512 	RF_DagList_t *dagList, *temp;
    513 
    514 	RF_ASSERT(desc);
    515 
    516 	/* Cleanup the dagList(s) */
    517 	dagList = desc->dagList;
    518 	while(dagList != NULL) {
    519 		temp = dagList;
    520 		dagList = dagList->next;
    521 		rf_FreeDAGList(temp);
    522 	}
    523 
    524 	rf_FreeAllocList(desc->cleanupList);
    525 	pool_put(&rf_pools.rad, desc);
    526 	RF_LOCK_MUTEX(rf_rad_lock);
    527 	raidPtr->nAccOutstanding--;
    528 	if (raidPtr->waitShutdown) {
    529 		RF_SIGNAL_COND(raidPtr->outstandingCond);
    530 	}
    531 	RF_UNLOCK_MUTEX(rf_rad_lock);
    532 }
    533 /*********************************************************************
    534  * Main routine for performing an access.
    535  * Accesses are retried until a DAG can not be selected.  This occurs
    536  * when either the DAG library is incomplete or there are too many
    537  * failures in a parity group.
    538  *
    539  * type should be read or write async_flag should be RF_TRUE or
    540  * RF_FALSE bp_in is a buf pointer.  void * to facilitate ignoring it
    541  * outside the kernel
    542  ********************************************************************/
    543 int
    544 rf_DoAccess(RF_Raid_t * raidPtr, RF_IoType_t type, int async_flag,
    545 	    RF_RaidAddr_t raidAddress, RF_SectorCount_t numBlocks,
    546 	    caddr_t bufPtr, void *bp_in, RF_RaidAccessFlags_t flags)
    547 {
    548 	RF_RaidAccessDesc_t *desc;
    549 	caddr_t lbufPtr = bufPtr;
    550 	struct buf *bp = (struct buf *) bp_in;
    551 
    552 	raidAddress += rf_raidSectorOffset;
    553 
    554 #if RF_ACCESS_DEBUG
    555 	if (rf_accessDebug) {
    556 
    557 		printf("logBytes is: %d %d %d\n", raidPtr->raidid,
    558 		    raidPtr->logBytesPerSector,
    559 		    (int) rf_RaidAddressToByte(raidPtr, numBlocks));
    560 		printf("raid%d: %s raidAddr %d (stripeid %d-%d) numBlocks %d (%d bytes) buf 0x%lx\n", raidPtr->raidid,
    561 		    (type == RF_IO_TYPE_READ) ? "READ" : "WRITE", (int) raidAddress,
    562 		    (int) rf_RaidAddressToStripeID(&raidPtr->Layout, raidAddress),
    563 		    (int) rf_RaidAddressToStripeID(&raidPtr->Layout, raidAddress + numBlocks - 1),
    564 		    (int) numBlocks,
    565 		    (int) rf_RaidAddressToByte(raidPtr, numBlocks),
    566 		    (long) bufPtr);
    567 	}
    568 #endif
    569 	if (raidAddress + numBlocks > raidPtr->totalSectors) {
    570 
    571 		printf("DoAccess: raid addr %lu too large to access %lu sectors.  Max legal addr is %lu\n",
    572 		    (u_long) raidAddress, (u_long) numBlocks, (u_long) raidPtr->totalSectors);
    573 
    574 
    575 		bp->b_flags |= B_ERROR;
    576 		bp->b_resid = bp->b_bcount;
    577 		bp->b_error = ENOSPC;
    578 		biodone(bp);
    579 		return (ENOSPC);
    580 	}
    581 	desc = rf_AllocRaidAccDesc(raidPtr, type, raidAddress,
    582 	    numBlocks, lbufPtr, bp, flags, raidPtr->Layout.map->states);
    583 
    584 	if (desc == NULL) {
    585 		return (ENOMEM);
    586 	}
    587 #if RF_ACC_TRACE > 0
    588 	RF_ETIMER_START(desc->tracerec.tot_timer);
    589 #endif
    590 	desc->async_flag = async_flag;
    591 
    592 	rf_ContinueRaidAccess(desc);
    593 
    594 	return (0);
    595 }
    596 #if 0
    597 /* force the array into reconfigured mode without doing reconstruction */
    598 int
    599 rf_SetReconfiguredMode(RF_Raid_t *raidPtr, int col)
    600 {
    601 	if (!(raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE)) {
    602 		printf("Can't set reconfigured mode in dedicated-spare array\n");
    603 		RF_PANIC();
    604 	}
    605 	RF_LOCK_MUTEX(raidPtr->mutex);
    606 	raidPtr->numFailures++;
    607 	raidPtr->Disks[col].status = rf_ds_dist_spared;
    608 	raidPtr->status = rf_rs_reconfigured;
    609 	rf_update_component_labels(raidPtr, RF_NORMAL_COMPONENT_UPDATE);
    610 	/* install spare table only if declustering + distributed sparing
    611 	 * architecture. */
    612 	if (raidPtr->Layout.map->flags & RF_BD_DECLUSTERED)
    613 		rf_InstallSpareTable(raidPtr, col);
    614 	RF_UNLOCK_MUTEX(raidPtr->mutex);
    615 	return (0);
    616 }
    617 #endif
    618 
    619 int
    620 rf_FailDisk(RF_Raid_t *raidPtr, int fcol, int initRecon)
    621 {
    622 	RF_LOCK_MUTEX(raidPtr->mutex);
    623 	if (raidPtr->Disks[fcol].status != rf_ds_failed) {
    624 		/* must be failing something that is valid, or else it's
    625 		   already marked as failed (in which case we don't
    626 		   want to mark it failed again!) */
    627 		raidPtr->numFailures++;
    628 		raidPtr->Disks[fcol].status = rf_ds_failed;
    629 		raidPtr->status = rf_rs_degraded;
    630 	}
    631 	RF_UNLOCK_MUTEX(raidPtr->mutex);
    632 
    633 	rf_update_component_labels(raidPtr, RF_NORMAL_COMPONENT_UPDATE);
    634 
    635 	/* Close the component, so that it's not "locked" if someone
    636 	   else want's to use it! */
    637 
    638 	rf_close_component(raidPtr, raidPtr->raid_cinfo[fcol].ci_vp,
    639 			   raidPtr->Disks[fcol].auto_configured);
    640 
    641 	RF_LOCK_MUTEX(raidPtr->mutex);
    642 	raidPtr->raid_cinfo[fcol].ci_vp = NULL;
    643 
    644 	/* Need to mark the component as not being auto_configured
    645 	   (in case it was previously). */
    646 
    647 	raidPtr->Disks[fcol].auto_configured = 0;
    648 	RF_UNLOCK_MUTEX(raidPtr->mutex);
    649 
    650 	if (initRecon)
    651 		rf_ReconstructFailedDisk(raidPtr, fcol);
    652 	return (0);
    653 }
    654 /* releases a thread that is waiting for the array to become quiesced.
    655  * access_suspend_mutex should be locked upon calling this
    656  */
    657 void
    658 rf_SignalQuiescenceLock(RF_Raid_t *raidPtr)
    659 {
    660 #if RF_DEBUG_QUIESCE
    661 	if (rf_quiesceDebug) {
    662 		printf("raid%d: Signalling quiescence lock\n",
    663 		       raidPtr->raidid);
    664 	}
    665 #endif
    666 	raidPtr->access_suspend_release = 1;
    667 
    668 	if (raidPtr->waiting_for_quiescence) {
    669 		SIGNAL_QUIESCENT_COND(raidPtr);
    670 	}
    671 }
    672 /* suspends all new requests to the array.  No effect on accesses that are in flight.  */
    673 int
    674 rf_SuspendNewRequestsAndWait(RF_Raid_t *raidPtr)
    675 {
    676 #if RF_DEBUG_QUIESCE
    677 	if (rf_quiesceDebug)
    678 		printf("raid%d: Suspending new reqs\n", raidPtr->raidid);
    679 #endif
    680 	RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
    681 	raidPtr->accesses_suspended++;
    682 	raidPtr->waiting_for_quiescence = (raidPtr->accs_in_flight == 0) ? 0 : 1;
    683 
    684 	if (raidPtr->waiting_for_quiescence) {
    685 		raidPtr->access_suspend_release = 0;
    686 		while (!raidPtr->access_suspend_release) {
    687 #if RF_DEBUG_QUIESCE
    688 			printf("raid%d: Suspending: Waiting for Quiescence\n",
    689 			       raidPtr->raidid);
    690 #endif
    691 			WAIT_FOR_QUIESCENCE(raidPtr);
    692 			raidPtr->waiting_for_quiescence = 0;
    693 		}
    694 	}
    695 #if RF_DEBUG_QUIESCE
    696 	printf("raid%d: Quiescence reached..\n", raidPtr->raidid);
    697 #endif
    698 
    699 	RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
    700 	return (raidPtr->waiting_for_quiescence);
    701 }
    702 /* wake up everyone waiting for quiescence to be released */
    703 void
    704 rf_ResumeNewRequests(RF_Raid_t *raidPtr)
    705 {
    706 	RF_CallbackDesc_t *t, *cb;
    707 
    708 #if RF_DEBUG_QUIESCE
    709 	if (rf_quiesceDebug)
    710 		printf("Resuming new reqs\n");
    711 #endif
    712 
    713 	RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
    714 	raidPtr->accesses_suspended--;
    715 	if (raidPtr->accesses_suspended == 0)
    716 		cb = raidPtr->quiesce_wait_list;
    717 	else
    718 		cb = NULL;
    719 	raidPtr->quiesce_wait_list = NULL;
    720 	RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
    721 
    722 	while (cb) {
    723 		t = cb;
    724 		cb = cb->next;
    725 		(t->callbackFunc) (t->callbackArg);
    726 		rf_FreeCallbackDesc(t);
    727 	}
    728 }
    729 /*****************************************************************************************
    730  *
    731  * debug routines
    732  *
    733  ****************************************************************************************/
    734 
    735 static void
    736 set_debug_option(char *name, long val)
    737 {
    738 	RF_DebugName_t *p;
    739 
    740 	for (p = rf_debugNames; p->name; p++) {
    741 		if (!strcmp(p->name, name)) {
    742 			*(p->ptr) = val;
    743 			printf("[Set debug variable %s to %ld]\n", name, val);
    744 			return;
    745 		}
    746 	}
    747 	RF_ERRORMSG1("Unknown debug string \"%s\"\n", name);
    748 }
    749 
    750 
    751 /* would like to use sscanf here, but apparently not available in kernel */
    752 /*ARGSUSED*/
    753 static void
    754 rf_ConfigureDebug(RF_Config_t *cfgPtr)
    755 {
    756 	char   *val_p, *name_p, *white_p;
    757 	long    val;
    758 	int     i;
    759 
    760 	rf_ResetDebugOptions();
    761 	for (i = 0; cfgPtr->debugVars[i][0] && i < RF_MAXDBGV; i++) {
    762 		name_p = rf_find_non_white(&cfgPtr->debugVars[i][0]);
    763 		white_p = rf_find_white(name_p);	/* skip to start of 2nd
    764 							 * word */
    765 		val_p = rf_find_non_white(white_p);
    766 		if (*val_p == '0' && *(val_p + 1) == 'x')
    767 			val = rf_htoi(val_p + 2);
    768 		else
    769 			val = rf_atoi(val_p);
    770 		*white_p = '\0';
    771 		set_debug_option(name_p, val);
    772 	}
    773 }
    774 
    775 void
    776 rf_print_panic_message(int line, char *file)
    777 {
    778 	sprintf(rf_panicbuf,"raidframe error at line %d file %s",
    779 		line, file);
    780 }
    781 
    782 #ifdef RAID_DIAGNOSTIC
    783 void
    784 rf_print_assert_panic_message(int line,	char *file, char *condition)
    785 {
    786 	sprintf(rf_panicbuf,
    787 		"raidframe error at line %d file %s (failed asserting %s)\n",
    788 		line, file, condition);
    789 }
    790 #endif
    791 
    792 void
    793 rf_print_unable_to_init_mutex(char *file, int line, int rc)
    794 {
    795 	RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n",
    796 		     file, line, rc);
    797 }
    798 
    799 void
    800 rf_print_unable_to_add_shutdown(char *file, int line, int rc)
    801 {
    802 	RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n",
    803 		     file, line, rc);
    804 }
    805