diff options
Diffstat (limited to 'sys/dev/raidframe/rf_driver.c')
-rw-r--r-- | sys/dev/raidframe/rf_driver.c | 710 |
1 files changed, 387 insertions, 323 deletions
diff --git a/sys/dev/raidframe/rf_driver.c b/sys/dev/raidframe/rf_driver.c index 57580f7b390..3a5e00f74b3 100644 --- a/sys/dev/raidframe/rf_driver.c +++ b/sys/dev/raidframe/rf_driver.c @@ -1,6 +1,7 @@ -/* $OpenBSD: rf_driver.c,v 1.10 2002/08/09 15:10:20 tdeval Exp $ */ +/* $OpenBSD: rf_driver.c,v 1.11 2002/12/16 07:01:03 tdeval Exp $ */ /* $NetBSD: rf_driver.c,v 1.37 2000/06/04 02:05:13 oster Exp $ */ -/*- + +/* * Copyright (c) 1999 The NetBSD Foundation, Inc. * All rights reserved. * @@ -17,8 +18,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. @@ -40,8 +41,9 @@ * Copyright (c) 1995 Carnegie-Mellon University. * All rights reserved. * - * Author: Mark Holland, Khalil Amiri, Claudson Bornstein, William V. Courtright II, - * Robby Findler, Daniel Stodolsky, Rachad Youssef, Jim Zelenka + * Author: Mark Holland, Khalil Amiri, Claudson Bornstein, + * William V. Courtright II, Robby Findler, Daniel Stodolsky, + * Rachad Youssef, Jim Zelenka * * Permission to use, copy, modify and distribute this software and * its documentation is hereby granted, provided that both the copyright @@ -64,20 +66,21 @@ * rights to redistribute these changes. */ -/****************************************************************************** +/***************************************************************************** * - * rf_driver.c -- main setup, teardown, and access routines for the RAID driver + * rf_driver.c -- Main setup, teardown, and access routines for the RAID + * driver * - * all routines are prefixed with rf_ (raidframe), to avoid conficts. + * All routines are prefixed with rf_ (RAIDframe), to avoid conficts. * - ******************************************************************************/ + *****************************************************************************/ #include <sys/types.h> #include <sys/param.h> #include <sys/systm.h> #include <sys/ioctl.h> #include <sys/fcntl.h> -#ifdef __NetBSD__ +#ifdef __NetBSD__ #include <sys/vnode.h> #endif @@ -122,51 +125,61 @@ /* rad == RF_RaidAccessDesc_t */ static RF_FreeList_t *rf_rad_freelist; -#define RF_MAX_FREE_RAD 128 -#define RF_RAD_INC 16 -#define RF_RAD_INITIAL 32 +#define RF_MAX_FREE_RAD 128 +#define RF_RAD_INC 16 +#define RF_RAD_INITIAL 32 -/* debug variables */ -char rf_panicbuf[2048]; /* a buffer to hold an error msg when we panic */ +/* Debug variables. */ +char rf_panicbuf[2048]; /* + * A buffer to hold an error msg when we panic. + */ -/* main configuration routines */ +/* Main configuration routines. */ static int raidframe_booted = 0; -static void rf_ConfigureDebug(RF_Config_t * cfgPtr); -static void set_debug_option(char *name, long val); -static void rf_UnconfigureArray(void); -static int init_rad(RF_RaidAccessDesc_t *); -static void clean_rad(RF_RaidAccessDesc_t *); -static void rf_ShutdownRDFreeList(void *); -static int rf_ConfigureRDFreeList(RF_ShutdownList_t **); - -RF_DECLARE_MUTEX(rf_printf_mutex) /* debug only: avoids interleaved - * printfs by different stripes */ - -#define SIGNAL_QUIESCENT_COND(_raid_) wakeup(&((_raid_)->accesses_suspended)) -#define WAIT_FOR_QUIESCENCE(_raid_) \ - tsleep(&((_raid_)->accesses_suspended),PRIBIO,"raidframe quiesce", 0); - -#define IO_BUF_ERR(bp, err) { \ - bp->b_flags |= B_ERROR; \ - bp->b_resid = bp->b_bcount; \ - bp->b_error = err; \ - biodone(bp); \ -} - -static int configureCount = 0; /* number of active configurations */ -static int isconfigged = 0; /* is basic raidframe (non per-array) - * stuff configged */ -RF_DECLARE_STATIC_MUTEX(configureMutex) /* used to lock the configuration - * stuff */ -static RF_ShutdownList_t *globalShutdown; /* non array-specific stuff */ -static int rf_ConfigureRDFreeList(RF_ShutdownList_t ** listp); - -/* called at system boot time */ +void rf_ConfigureDebug(RF_Config_t *); +void rf_set_debug_option(char *, long); +void rf_UnconfigureArray(void); +int rf_init_rad(RF_RaidAccessDesc_t *); +void rf_clean_rad(RF_RaidAccessDesc_t *); +void rf_ShutdownRDFreeList(void *); +int rf_ConfigureRDFreeList(RF_ShutdownList_t **); + +RF_DECLARE_MUTEX(rf_printf_mutex); /* + * Debug only: Avoids interleaved + * printfs by different stripes. + */ + +#define SIGNAL_QUIESCENT_COND(_raid_) wakeup(&((_raid_)->accesses_suspended)) +#define WAIT_FOR_QUIESCENCE(_raid_) \ + tsleep(&((_raid_)->accesses_suspended), PRIBIO, "RAIDframe quiesce", 0); + +#define IO_BUF_ERR(bp, err) \ +do { \ + bp->b_flags |= B_ERROR; \ + bp->b_resid = bp->b_bcount; \ + bp->b_error = err; \ + biodone(bp); \ +} while (0) + +static int configureCount = 0; /* Number of active configurations. */ +static int isconfigged = 0; /* + * Is basic RAIDframe (non per-array) + * stuff configured ? + */ +RF_DECLARE_STATIC_MUTEX(configureMutex); /* + * Used to lock the + * configuration stuff. + */ +static RF_ShutdownList_t *globalShutdown; /* Non array-specific stuff. */ +int rf_ConfigureRDFreeList(RF_ShutdownList_t **); + + +/* Called at system boot time. */ int -rf_BootRaidframe() +rf_BootRaidframe(void) { - int rc; + int rc; if (raidframe_booted) return (EBUSY); @@ -174,8 +187,8 @@ rf_BootRaidframe() rc = rf_mutex_init(&configureMutex); if (rc) { - RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__, - __LINE__, rc); + RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d.\n", + __FILE__, __LINE__, rc); RF_PANIC(); } configureCount = 0; @@ -183,16 +196,18 @@ rf_BootRaidframe() globalShutdown = NULL; return (0); } + + /* - * This function is really just for debugging user-level stuff: it - * frees up all memory, other RAIDframe resources which might otherwise + * This function is really just for debugging user-level stuff: It + * frees up all memory, other RAIDframe resources that might otherwise * be kept around. This is used with systems like "sentinel" to detect * memory leaks. */ -int -rf_UnbootRaidframe() +int +rf_UnbootRaidframe(void) { - int rc; + int rc; RF_LOCK_MUTEX(configureMutex); if (configureCount) { @@ -203,58 +218,65 @@ rf_UnbootRaidframe() RF_UNLOCK_MUTEX(configureMutex); rc = rf_mutex_destroy(&configureMutex); if (rc) { - RF_ERRORMSG3("Unable to destroy mutex file %s line %d rc=%d\n", __FILE__, - __LINE__, rc); + RF_ERRORMSG3("Unable to destroy mutex file %s line %d" + " rc=%d.\n", __FILE__, __LINE__, rc); RF_PANIC(); } return (0); } + + /* - * Called whenever an array is shutdown + * Called whenever an array is shutdown. */ -static void -rf_UnconfigureArray() +void +rf_UnconfigureArray(void) { - int rc; + int rc; RF_LOCK_MUTEX(configureMutex); - if (--configureCount == 0) { /* if no active configurations, shut - * everything down */ + if (--configureCount == 0) { /* + * If no active configurations, shut + * everything down. + */ isconfigged = 0; rc = rf_ShutdownList(&globalShutdown); if (rc) { - RF_ERRORMSG1("RAIDFRAME: unable to do global shutdown, rc=%d\n", rc); + RF_ERRORMSG1("RAIDFRAME: unable to do global shutdown," + " rc=%d.\n", rc); } /* - * We must wait until now, because the AllocList module - * uses the DebugMem module. - */ + * We must wait until now, because the AllocList module + * uses the DebugMem module. + */ if (rf_memDebug) rf_print_unfreed(); } RF_UNLOCK_MUTEX(configureMutex); } + + /* * Called to shut down an array. */ -int -rf_Shutdown(raidPtr) - RF_Raid_t *raidPtr; +int +rf_Shutdown(RF_Raid_t *raidPtr) { if (!raidPtr->valid) { - RF_ERRORMSG("Attempt to shut down unconfigured RAIDframe driver. Aborting shutdown\n"); + RF_ERRORMSG("Attempt to shut down unconfigured RAIDframe" + " driver. Aborting shutdown.\n"); return (EINVAL); } /* - * wait for outstanding IOs to land - * As described in rf_raid.h, we use the rad_freelist lock - * to protect the per-array info about outstanding descs - * since we need to do freelist locking anyway, and this - * cuts down on the amount of serialization we've got going - * on. - */ + * Wait for outstanding IOs to land. + * As described in rf_raid.h, we use the rad_freelist lock + * to protect the per-array info about outstanding descs, + * since we need to do freelist locking anyway, and this + * cuts down on the amount of serialization we've got going + * on. + */ RF_FREELIST_DO_LOCK(rf_rad_freelist); if (raidPtr->waitShutdown) { RF_FREELIST_DO_UNLOCK(rf_rad_freelist); @@ -286,67 +308,73 @@ rf_Shutdown(raidPtr) return (0); } -#define DO_INIT_CONFIGURE(f) { \ - rc = f (&globalShutdown); \ - if (rc) { \ - RF_ERRORMSG2("RAIDFRAME: failed %s with %d\n", RF_STRING(f), rc); \ - rf_ShutdownList(&globalShutdown); \ - configureCount--; \ - RF_UNLOCK_MUTEX(configureMutex); \ - return(rc); \ - } \ -} - -#define DO_RAID_FAIL() { \ - rf_UnconfigureVnodes(raidPtr); \ - rf_ShutdownList(&raidPtr->shutdownList); \ - rf_UnconfigureArray(); \ -} - -#define DO_RAID_INIT_CONFIGURE(f) { \ - rc = f (&raidPtr->shutdownList, raidPtr, cfgPtr); \ - if (rc) { \ - RF_ERRORMSG2("RAIDFRAME: failed %s with %d\n", RF_STRING(f), rc); \ - DO_RAID_FAIL(); \ - return(rc); \ - } \ -} - -#define DO_RAID_MUTEX(_m_) { \ - rc = rf_create_managed_mutex(&raidPtr->shutdownList, (_m_)); \ - if (rc) { \ - RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", \ - __FILE__, __LINE__, rc); \ - DO_RAID_FAIL(); \ - return(rc); \ - } \ -} - -#define DO_RAID_COND(_c_) { \ - rc = rf_create_managed_cond(&raidPtr->shutdownList, (_c_)); \ - if (rc) { \ - RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n", \ - __FILE__, __LINE__, rc); \ - DO_RAID_FAIL(); \ - return(rc); \ - } \ -} +#define DO_INIT_CONFIGURE(f) \ +do { \ + rc = f (&globalShutdown); \ + if (rc) { \ + RF_ERRORMSG2("RAIDFRAME: failed %s with %d.\n", \ + RF_STRING(f), rc); \ + rf_ShutdownList(&globalShutdown); \ + configureCount--; \ + RF_UNLOCK_MUTEX(configureMutex); \ + return(rc); \ + } \ +} while (0) + +#define DO_RAID_FAIL() \ +do { \ + rf_UnconfigureVnodes(raidPtr); \ + rf_ShutdownList(&raidPtr->shutdownList); \ + rf_UnconfigureArray(); \ +} while (0) + +#define DO_RAID_INIT_CONFIGURE(f) \ +do { \ + rc = (f)(&raidPtr->shutdownList, raidPtr, cfgPtr); \ + if (rc) { \ + RF_ERRORMSG2("RAIDFRAME: failed %s with %d.\n", \ + RF_STRING(f), rc); \ + DO_RAID_FAIL(); \ + return(rc); \ + } \ +} while (0) + +#define DO_RAID_MUTEX(_m_) \ +do { \ + rc = rf_create_managed_mutex(&raidPtr->shutdownList, (_m_)); \ + if (rc) { \ + RF_ERRORMSG3("Unable to init mutex file %s line %d" \ + " rc=%d.\n", __FILE__, __LINE__, rc); \ + DO_RAID_FAIL(); \ + return(rc); \ + } \ +} while (0) + +#define DO_RAID_COND(_c_) \ +do { \ + rc = rf_create_managed_cond(&raidPtr->shutdownList, (_c_)); \ + if (rc) { \ + RF_ERRORMSG3("Unable to init cond file %s line %d" \ + " rc=%d.\n", __FILE__, __LINE__, rc); \ + DO_RAID_FAIL(); \ + return(rc); \ + } \ +} while (0) -int -rf_Configure(raidPtr, cfgPtr, ac) - RF_Raid_t *raidPtr; - RF_Config_t *cfgPtr; - RF_AutoConfig_t *ac; +int +rf_Configure(RF_Raid_t *raidPtr, RF_Config_t *cfgPtr, RF_AutoConfig_t *ac) { RF_RowCol_t row, col; - int i, rc; + int i, rc; - /* XXX This check can probably be removed now, since - RAIDFRAME_CONFIGURRE now checks to make sure that the - RAID set is not already valid - */ + /* + * XXX This check can probably be removed now, since + * RAIDFRAME_CONFIGURE now checks to make sure that the + * RAID set is not already valid. + */ if (raidPtr->valid) { - RF_ERRORMSG("RAIDframe configuration not shut down. Aborting configure.\n"); + RF_ERRORMSG("RAIDframe configuration not shut down." + " Aborting configure.\n"); return (EINVAL); } RF_LOCK_MUTEX(configureMutex); @@ -354,14 +382,14 @@ rf_Configure(raidPtr, cfgPtr, ac) if (isconfigged == 0) { rc = rf_create_managed_mutex(&globalShutdown, &rf_printf_mutex); if (rc) { - RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__, - __LINE__, rc); + RF_ERRORMSG3("Unable to init mutex file %s line %d" + " rc=%d.\n", __FILE__, __LINE__, rc); rf_ShutdownList(&globalShutdown); return (rc); } - /* initialize globals */ + /* Initialize globals. */ #ifdef RAIDDEBUG - printf("RAIDFRAME: protectedSectors is %ld\n", + printf("RAIDFRAME: protectedSectors is %ld.\n", rf_protectedSectors); #endif /* RAIDDEBUG */ @@ -370,8 +398,8 @@ rf_Configure(raidPtr, cfgPtr, ac) DO_INIT_CONFIGURE(rf_ConfigureAllocList); /* - * Yes, this does make debugging general to the whole - * system instead of being array specific. Bummer, drag. + * Yes, this does make debugging general to the whole + * system instead of being array specific. Bummer, drag. */ rf_ConfigureDebug(cfgPtr); DO_INIT_CONFIGURE(rf_ConfigureDebugMem); @@ -395,8 +423,10 @@ rf_Configure(raidPtr, cfgPtr, ac) RF_UNLOCK_MUTEX(configureMutex); DO_RAID_MUTEX(&raidPtr->mutex); - /* set up the cleanup list. Do this after ConfigureDebug so that - * value of memDebug will be set */ + /* + * Set up the cleanup list. Do this after ConfigureDebug so that + * value of memDebug will be set. + */ rf_MakeAllocList(raidPtr->cleanupList); if (raidPtr->cleanupList == NULL) { @@ -404,11 +434,10 @@ rf_Configure(raidPtr, cfgPtr, ac) return (ENOMEM); } rc = rf_ShutdownCreate(&raidPtr->shutdownList, - (void (*) (void *)) rf_FreeAllocList, - raidPtr->cleanupList); + (void (*) (void *)) rf_FreeAllocList, raidPtr->cleanupList); if (rc) { - RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n", - __FILE__, __LINE__, rc); + RF_ERRORMSG3("Unable to add to shutdown list file %s line %d" + " rc=%d.\n", __FILE__, __LINE__, rc); DO_RAID_FAIL(); return (rc); } @@ -416,15 +445,17 @@ rf_Configure(raidPtr, cfgPtr, ac) raidPtr->numCol = cfgPtr->numCol; raidPtr->numSpare = cfgPtr->numSpare; - /* XXX we don't even pretend to support more than one row in the - * kernel... */ + /* + * XXX We don't even pretend to support more than one row in the + * kernel... + */ if (raidPtr->numRow != 1) { RF_ERRORMSG("Only one row supported in kernel.\n"); DO_RAID_FAIL(); return (EINVAL); } - RF_CallocAndAdd(raidPtr->status, raidPtr->numRow, sizeof(RF_RowStatus_t), - (RF_RowStatus_t *), raidPtr->cleanupList); + RF_CallocAndAdd(raidPtr->status, raidPtr->numRow, + sizeof(RF_RowStatus_t), (RF_RowStatus_t *), raidPtr->cleanupList); if (raidPtr->status == NULL) { DO_RAID_FAIL(); return (ENOMEM); @@ -455,17 +486,21 @@ rf_Configure(raidPtr, cfgPtr, ac) DO_RAID_MUTEX(&raidPtr->recon_done_proc_mutex); - if (ac!=NULL) { - /* We have an AutoConfig structure.. Don't do the - normal disk configuration... call the auto config - stuff */ + if (ac != NULL) { + /* + * We have an AutoConfig structure... Don't do the + * normal disk configuration... call the auto config + * stuff. + */ rf_AutoConfigureDisks(raidPtr, cfgPtr, ac); } else { DO_RAID_INIT_CONFIGURE(rf_ConfigureDisks); DO_RAID_INIT_CONFIGURE(rf_ConfigureSpareDisks); } - /* do this after ConfigureDisks & ConfigureSpareDisks to be sure dev - * no. is set */ + /* + * Do this after ConfigureDisks & ConfigureSpareDisks to be sure + * devno is set. + */ DO_RAID_INIT_CONFIGURE(rf_ConfigureDiskQueues); DO_RAID_INIT_CONFIGURE(rf_ConfigureLayout); @@ -475,8 +510,8 @@ rf_Configure(raidPtr, cfgPtr, ac) for (row = 0; row < raidPtr->numRow; row++) { for (col = 0; col < raidPtr->numCol; col++) { /* - * XXX better distribution - */ + * XXX Better distribution. + */ raidPtr->hist_diskreq[row][col] = 0; } } @@ -487,8 +522,10 @@ rf_Configure(raidPtr, cfgPtr, ac) raidPtr->recon_in_progress = 0; raidPtr->maxOutstanding = cfgPtr->maxOutstandingDiskReqs; - /* autoconfigure and root_partition will actually get filled in - after the config is done */ + /* + * Autoconfigure and root_partition will actually get filled in + * after the config is done. + */ raidPtr->autoconfigure = 0; raidPtr->root_partition = 0; raidPtr->last_unit = raidPtr->raidid; @@ -503,21 +540,20 @@ rf_Configure(raidPtr, cfgPtr, ac) return (0); } -static int -init_rad(desc) - RF_RaidAccessDesc_t *desc; +int +rf_init_rad(RF_RaidAccessDesc_t *desc) { - int rc; + int rc; rc = rf_mutex_init(&desc->mutex); if (rc) { - RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__, + RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d.\n", __FILE__, __LINE__, rc); return (rc); } rc = rf_cond_init(&desc->cond); if (rc) { - RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n", __FILE__, + RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d.\n", __FILE__, __LINE__, rc); rf_mutex_destroy(&desc->mutex); return (rc); @@ -525,26 +561,24 @@ init_rad(desc) return (0); } -static void -clean_rad(desc) - RF_RaidAccessDesc_t *desc; +void +rf_clean_rad(RF_RaidAccessDesc_t *desc) { rf_mutex_destroy(&desc->mutex); rf_cond_destroy(&desc->cond); } -static void -rf_ShutdownRDFreeList(ignored) - void *ignored; +void +rf_ShutdownRDFreeList(void *ignored) { - RF_FREELIST_DESTROY_CLEAN(rf_rad_freelist, next, (RF_RaidAccessDesc_t *), clean_rad); + RF_FREELIST_DESTROY_CLEAN(rf_rad_freelist, next, + (RF_RaidAccessDesc_t *), rf_clean_rad); } -static int -rf_ConfigureRDFreeList(listp) - RF_ShutdownList_t **listp; +int +rf_ConfigureRDFreeList(RF_ShutdownList_t **listp) { - int rc; + int rc; RF_FREELIST_CREATE(rf_rad_freelist, RF_MAX_FREE_RAD, RF_RAD_INC, sizeof(RF_RaidAccessDesc_t)); @@ -553,41 +587,44 @@ rf_ConfigureRDFreeList(listp) } rc = rf_ShutdownCreate(listp, rf_ShutdownRDFreeList, NULL); if (rc) { - RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n", __FILE__, + RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d.\n", __FILE__, __LINE__, rc); rf_ShutdownRDFreeList(NULL); return (rc); } RF_FREELIST_PRIME_INIT(rf_rad_freelist, RF_RAD_INITIAL, next, - (RF_RaidAccessDesc_t *), init_rad); + (RF_RaidAccessDesc_t *), rf_init_rad); return (0); } RF_RaidAccessDesc_t * rf_AllocRaidAccDesc( - RF_Raid_t * raidPtr, - RF_IoType_t type, - RF_RaidAddr_t raidAddress, - RF_SectorCount_t numBlocks, - caddr_t bufPtr, - void *bp, - RF_DagHeader_t ** paramDAG, - RF_AccessStripeMapHeader_t ** paramASM, - RF_RaidAccessFlags_t flags, - void (*cbF) (struct buf *), - void *cbA, - RF_AccessState_t * states) + RF_Raid_t *raidPtr, + RF_IoType_t type, + RF_RaidAddr_t raidAddress, + RF_SectorCount_t numBlocks, + caddr_t bufPtr, + void *bp, + RF_DagHeader_t **paramDAG, + RF_AccessStripeMapHeader_t **paramASM, + RF_RaidAccessFlags_t flags, + void (*cbF) (struct buf *), + void *cbA, + RF_AccessState_t *states +) { RF_RaidAccessDesc_t *desc; - RF_FREELIST_GET_INIT_NOUNLOCK(rf_rad_freelist, desc, next, (RF_RaidAccessDesc_t *), init_rad); + RF_FREELIST_GET_INIT_NOUNLOCK(rf_rad_freelist, desc, next, + (RF_RaidAccessDesc_t *), rf_init_rad); if (raidPtr->waitShutdown) { /* - * Actually, we're shutting the array down. Free the desc - * and return NULL. - */ + * Actually, we're shutting the array down. Free the desc + * and return NULL. + */ RF_FREELIST_DO_UNLOCK(rf_rad_freelist); - RF_FREELIST_FREE_CLEAN(rf_rad_freelist, desc, next, clean_rad); + RF_FREELIST_FREE_CLEAN(rf_rad_freelist, desc, next, + rf_clean_rad); return (NULL); } raidPtr->nAccOutstanding++; @@ -617,7 +654,7 @@ rf_AllocRaidAccDesc( return (desc); } -void +void rf_FreeRaidAccDesc(RF_RaidAccessDesc_t * desc) { RF_Raid_t *raidPtr = desc->raidPtr; @@ -625,39 +662,45 @@ rf_FreeRaidAccDesc(RF_RaidAccessDesc_t * desc) RF_ASSERT(desc); rf_FreeAllocList(desc->cleanupList); - RF_FREELIST_FREE_CLEAN_NOUNLOCK(rf_rad_freelist, desc, next, clean_rad); + RF_FREELIST_FREE_CLEAN_NOUNLOCK(rf_rad_freelist, desc, next, rf_clean_rad); raidPtr->nAccOutstanding--; if (raidPtr->waitShutdown) { RF_SIGNAL_COND(raidPtr->outstandingCond); } RF_FREELIST_DO_UNLOCK(rf_rad_freelist); } -/********************************************************************* + + +/******************************************************************** * Main routine for performing an access. - * Accesses are retried until a DAG can not be selected. This occurs + * Accesses are retried until a DAG can not be selected. This occurs * when either the DAG library is incomplete or there are too many * failures in a parity group. ********************************************************************/ -int +int rf_DoAccess( - RF_Raid_t * raidPtr, - RF_IoType_t type, - int async_flag, - RF_RaidAddr_t raidAddress, - RF_SectorCount_t numBlocks, - caddr_t bufPtr, - void *bp_in, - RF_DagHeader_t ** paramDAG, - RF_AccessStripeMapHeader_t ** paramASM, - RF_RaidAccessFlags_t flags, - RF_RaidAccessDesc_t ** paramDesc, - void (*cbF) (struct buf *), - void *cbA) -/* -type should be read or write -async_flag should be RF_TRUE or RF_FALSE -bp_in is a buf pointer. void * to facilitate ignoring it outside the kernel -*/ + RF_Raid_t *raidPtr, + RF_IoType_t type, /* Should be read or write. */ + int async_flag, /* + * Should be RF_TRUE + * or RF_FALSE. + */ + RF_RaidAddr_t raidAddress, + RF_SectorCount_t numBlocks, + caddr_t bufPtr, + void *bp_in, /* + * It's a buf pointer. + * void * to facilitate + * ignoring it outside + * the kernel. + */ + RF_DagHeader_t **paramDAG, + RF_AccessStripeMapHeader_t **paramASM, + RF_RaidAccessFlags_t flags, + RF_RaidAccessDesc_t **paramDesc, + void (*cbF) (struct buf *), + void *cbA +) { RF_RaidAccessDesc_t *desc; caddr_t lbufPtr = bufPtr; @@ -666,17 +709,18 @@ bp_in is a buf pointer. void * to facilitate ignoring it outside the kernel raidAddress += rf_raidSectorOffset; if (!raidPtr->valid) { - RF_ERRORMSG("RAIDframe driver not successfully configured. Rejecting access.\n"); + RF_ERRORMSG("RAIDframe driver not successfully configured." + " Rejecting access.\n"); IO_BUF_ERR(bp, EINVAL); return (EINVAL); } if (rf_accessDebug) { - printf("logBytes is: %d %d %d\n", raidPtr->raidid, + printf("logBytes is: %d %d %d.\n", raidPtr->raidid, raidPtr->logBytesPerSector, (int) rf_RaidAddressToByte(raidPtr, numBlocks)); - printf("raid%d: %s raidAddr %d (stripeid %d-%d) numBlocks %d (%d bytes) buf 0x%lx\n", raidPtr->raidid, + printf("raid%d: %s raidAddr %d (stripeid %d-%d) numBlocks %d (%d bytes) buf 0x%lx.\n", raidPtr->raidid, (type == RF_IO_TYPE_READ) ? "READ" : "WRITE", (int) raidAddress, (int) rf_RaidAddressToStripeID(&raidPtr->Layout, raidAddress), (int) rf_RaidAddressToStripeID(&raidPtr->Layout, raidAddress + numBlocks - 1), @@ -686,7 +730,7 @@ bp_in is a buf pointer. void * to facilitate ignoring it outside the kernel } if (raidAddress + numBlocks > raidPtr->totalSectors) { - printf("DoAccess: raid addr %lu too large to access %lu sectors. Max legal addr is %lu\n", + printf("DoAccess: raid addr %lu too large to access %lu sectors. Max legal addr is %lu.\n", (u_long) raidAddress, (u_long) numBlocks, (u_long) raidPtr->totalSectors); IO_BUF_ERR(bp, ENOSPC); @@ -707,15 +751,15 @@ bp_in is a buf pointer. void * to facilitate ignoring it outside the kernel return (0); } -/* force the array into reconfigured mode without doing reconstruction */ -int -rf_SetReconfiguredMode(raidPtr, row, col) - RF_Raid_t *raidPtr; - int row; - int col; + + +/* Force the array into reconfigured mode without doing reconstruction. */ +int +rf_SetReconfiguredMode(RF_Raid_t *raidPtr, int row, int col) { if (!(raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE)) { - printf("Can't set reconfigured mode in dedicated-spare array\n"); + printf("Can't set reconfigured mode in dedicated-spare" + " array.\n"); RF_PANIC(); } RF_LOCK_MUTEX(raidPtr->mutex); @@ -723,8 +767,10 @@ rf_SetReconfiguredMode(raidPtr, row, col) raidPtr->Disks[row][col].status = rf_ds_dist_spared; raidPtr->status[row] = rf_rs_reconfigured; rf_update_component_labels(raidPtr, RF_NORMAL_COMPONENT_UPDATE); - /* install spare table only if declustering + distributed sparing - * architecture. */ + /* + * Install spare table only if declustering + distributed sparing + * architecture. + */ if (raidPtr->Layout.map->flags & RF_BD_DECLUSTERED) rf_InstallSpareTable(raidPtr, row, col); RF_UNLOCK_MUTEX(raidPtr->mutex); @@ -734,14 +780,10 @@ rf_SetReconfiguredMode(raidPtr, row, col) extern int fail_row, fail_col, fail_time; extern int delayed_recon; -int -rf_FailDisk( - RF_Raid_t * raidPtr, - int frow, - int fcol, - int initRecon) +int +rf_FailDisk(RF_Raid_t *raidPtr, int frow, int fcol, int initRecon) { - printf("raid%d: Failing disk r%d c%d\n", raidPtr->raidid, frow, fcol); + printf("raid%d: Failing disk r%d c%d.\n", raidPtr->raidid, frow, fcol); RF_LOCK_MUTEX(raidPtr->mutex); raidPtr->numFailures++; raidPtr->Disks[frow][fcol].status = rf_ds_failed; @@ -752,16 +794,17 @@ rf_FailDisk( rf_ReconstructFailedDisk(raidPtr, frow, fcol); return (0); } -/* releases a thread that is waiting for the array to become quiesced. - * access_suspend_mutex should be locked upon calling this + + +/* + * Releases a thread that is waiting for the array to become quiesced. + * access_suspend_mutex should be locked upon calling this. */ -void -rf_SignalQuiescenceLock(raidPtr, reconDesc) - RF_Raid_t *raidPtr; - RF_RaidReconDesc_t *reconDesc; +void +rf_SignalQuiescenceLock(RF_Raid_t *raidPtr, RF_RaidReconDesc_t *reconDesc) { if (rf_quiesceDebug) { - printf("raid%d: Signalling quiescence lock\n", + printf("raid%d: Signalling quiescence lock.\n", raidPtr->raidid); } raidPtr->access_suspend_release = 1; @@ -770,13 +813,17 @@ rf_SignalQuiescenceLock(raidPtr, reconDesc) SIGNAL_QUIESCENT_COND(raidPtr); } } -/* suspends all new requests to the array. No effect on accesses that are in flight. */ -int -rf_SuspendNewRequestsAndWait(raidPtr) - RF_Raid_t *raidPtr; + + +/* + * Suspends all new requests to the array. No effect on accesses that are + * in flight. + */ +int +rf_SuspendNewRequestsAndWait(RF_Raid_t *raidPtr) { if (rf_quiesceDebug) - printf("Suspending new reqs\n"); + printf("Suspending new reqs.\n"); RF_LOCK_MUTEX(raidPtr->access_suspend_mutex); raidPtr->accesses_suspended++; @@ -785,25 +832,26 @@ rf_SuspendNewRequestsAndWait(raidPtr) if (raidPtr->waiting_for_quiescence) { raidPtr->access_suspend_release = 0; while (!raidPtr->access_suspend_release) { - printf("Suspending: Waiting for Quiescence\n"); + printf("Suspending: Waiting for Quiescence.\n"); WAIT_FOR_QUIESCENCE(raidPtr); raidPtr->waiting_for_quiescence = 0; } } - printf("Quiescence reached..\n"); + printf("Quiescence reached...\n"); RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex); return (raidPtr->waiting_for_quiescence); } -/* wake up everyone waiting for quiescence to be released */ -void -rf_ResumeNewRequests(raidPtr) - RF_Raid_t *raidPtr; + + +/* Wake up everyone waiting for quiescence to be released. */ +void +rf_ResumeNewRequests(RF_Raid_t *raidPtr) { RF_CallbackDesc_t *t, *cb; if (rf_quiesceDebug) - printf("Resuming new reqs\n"); + printf("Resuming new reqs.\n"); RF_LOCK_MUTEX(raidPtr->access_suspend_mutex); raidPtr->accesses_suspended--; @@ -821,16 +869,16 @@ rf_ResumeNewRequests(raidPtr) rf_FreeCallbackDesc(t); } } -/***************************************************************************************** + + +/***************************************************************************** * - * debug routines + * Debug routines. * - ****************************************************************************************/ + *****************************************************************************/ -static void -set_debug_option(name, val) - char *name; - long val; +void +rf_set_debug_option(char *name, long val) { RF_DebugName_t *p; @@ -845,51 +893,52 @@ set_debug_option(name, val) } -/* would like to use sscanf here, but apparently not available in kernel */ +/* Would like to use sscanf here, but apparently not available in kernel. */ /*ARGSUSED*/ -static void -rf_ConfigureDebug(cfgPtr) - RF_Config_t *cfgPtr; +void +rf_ConfigureDebug(RF_Config_t *cfgPtr) { - char *val_p, *name_p, *white_p; - long val; - int i; + char *val_p, *name_p, *white_p; + long val; + int i; rf_ResetDebugOptions(); for (i = 0; cfgPtr->debugVars[i][0] && i < RF_MAXDBGV; i++) { name_p = rf_find_non_white(&cfgPtr->debugVars[i][0]); - white_p = rf_find_white(name_p); /* skip to start of 2nd - * word */ + white_p = rf_find_white(name_p); /* + * Skip to start of 2nd + * word. + */ val_p = rf_find_non_white(white_p); if (*val_p == '0' && *(val_p + 1) == 'x') val = rf_htoi(val_p + 2); else val = rf_atoi(val_p); *white_p = '\0'; - set_debug_option(name_p, val); + rf_set_debug_option(name_p, val); } } -/* performance monitoring stuff */ -#if !defined(_KERNEL) && !defined(SIMULATE) + +/* Performance monitoring stuff. */ + +#if !defined(_KERNEL) && !defined(SIMULATE) /* - * Throughput stats currently only used in user-level RAIDframe + * Throughput stats currently only used in user-level RAIDframe. */ -static int -rf_InitThroughputStats( - RF_ShutdownList_t ** listp, - RF_Raid_t * raidPtr, - RF_Config_t * cfgPtr) +int +rf_InitThroughputStats(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr, + RF_Config_t *cfgPtr) { - int rc; + int rc; - /* these used by user-level raidframe only */ + /* These used by user-level RAIDframe only. */ rc = rf_create_managed_mutex(listp, &raidPtr->throughputstats.mutex); if (rc) { - RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__, - __LINE__, rc); + RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d.\n", + __FILE__, __LINE__, rc); return (rc); } raidPtr->throughputstats.sum_io_us = 0; @@ -898,8 +947,8 @@ rf_InitThroughputStats( return (0); } -void -rf_StartThroughputStats(RF_Raid_t * raidPtr) +void +rf_StartThroughputStats(RF_Raid_t *raidPtr) { RF_LOCK_MUTEX(raidPtr->throughputstats.mutex); raidPtr->throughputstats.num_ios++; @@ -909,8 +958,8 @@ rf_StartThroughputStats(RF_Raid_t * raidPtr) RF_UNLOCK_MUTEX(raidPtr->throughputstats.mutex); } -static void -rf_StopThroughputStats(RF_Raid_t * raidPtr) +void +rf_StopThroughputStats(RF_Raid_t *raidPtr) { struct timeval diff; @@ -918,25 +967,28 @@ rf_StopThroughputStats(RF_Raid_t * raidPtr) raidPtr->throughputstats.num_out_ios--; if (raidPtr->throughputstats.num_out_ios == 0) { RF_GETTIME(raidPtr->throughputstats.stop); - RF_TIMEVAL_DIFF(&raidPtr->throughputstats.start, &raidPtr->throughputstats.stop, &diff); + RF_TIMEVAL_DIFF(&raidPtr->throughputstats.start, + &raidPtr->throughputstats.stop, &diff); raidPtr->throughputstats.sum_io_us += RF_TIMEVAL_TO_US(diff); } RF_UNLOCK_MUTEX(raidPtr->throughputstats.mutex); } -static void -rf_PrintThroughputStats(RF_Raid_t * raidPtr) +void +rf_PrintThroughputStats(RF_Raid_t *raidPtr) { RF_ASSERT(raidPtr->throughputstats.num_out_ios == 0); if (raidPtr->throughputstats.sum_io_us != 0) { - printf("[Througphut: %8.2f IOs/second]\n", raidPtr->throughputstats.num_ios - / (raidPtr->throughputstats.sum_io_us / 1000000.0)); + printf("[Througphut: %8.2f IOs/second]\n", + raidPtr->throughputstats.num_ios / + (raidPtr->throughputstats.sum_io_us / 1000000.0)); } } -#endif /* !_KERNEL && !SIMULATE */ -void -rf_StartUserStats(RF_Raid_t * raidPtr) +#endif /* !_KERNEL && !SIMULATE */ + +void +rf_StartUserStats(RF_Raid_t *raidPtr) { RF_GETTIME(raidPtr->userstats.start); raidPtr->userstats.sum_io_us = 0; @@ -944,51 +996,63 @@ rf_StartUserStats(RF_Raid_t * raidPtr) raidPtr->userstats.num_sect_moved = 0; } -void -rf_StopUserStats(RF_Raid_t * raidPtr) +void +rf_StopUserStats(RF_Raid_t *raidPtr) { RF_GETTIME(raidPtr->userstats.stop); } -void -rf_UpdateUserStats(raidPtr, rt, numsect) - RF_Raid_t *raidPtr; - int rt; /* resp time in us */ - int numsect; /* number of sectors for this access */ +void +rf_UpdateUserStats( + RF_Raid_t *raidPtr, + int rt, /* Response time in us. */ + int numsect /* Number of sectors for this access. */ +) { raidPtr->userstats.sum_io_us += rt; raidPtr->userstats.num_ios++; raidPtr->userstats.num_sect_moved += numsect; } -void -rf_PrintUserStats(RF_Raid_t * raidPtr) +void +rf_PrintUserStats(RF_Raid_t *raidPtr) { long elapsed_us, mbs, mbs_frac; struct timeval diff; - RF_TIMEVAL_DIFF(&raidPtr->userstats.start, &raidPtr->userstats.stop, &diff); + RF_TIMEVAL_DIFF(&raidPtr->userstats.start, &raidPtr->userstats.stop, + &diff); elapsed_us = RF_TIMEVAL_TO_US(diff); - /* 2000 sectors per megabyte, 10000000 microseconds per second */ + /* 2000 sectors per megabyte, 10000000 microseconds per second. */ if (elapsed_us) - mbs = (raidPtr->userstats.num_sect_moved / 2000) / (elapsed_us / 1000000); + mbs = (raidPtr->userstats.num_sect_moved / 2000) / + (elapsed_us / 1000000); else mbs = 0; - /* this computes only the first digit of the fractional mb/s moved */ + /* This computes only the first digit of the fractional mb/s moved. */ if (elapsed_us) { - mbs_frac = ((raidPtr->userstats.num_sect_moved / 200) / (elapsed_us / 1000000)) - - (mbs * 10); + mbs_frac = ((raidPtr->userstats.num_sect_moved / 200) / + (elapsed_us / 1000000)) - (mbs * 10); } else { mbs_frac = 0; } - printf("Number of I/Os: %ld\n", raidPtr->userstats.num_ios); - printf("Elapsed time (us): %ld\n", elapsed_us); - printf("User I/Os per second: %ld\n", RF_DB0_CHECK(raidPtr->userstats.num_ios, (elapsed_us / 1000000))); - printf("Average user response time: %ld us\n", RF_DB0_CHECK(raidPtr->userstats.sum_io_us, raidPtr->userstats.num_ios)); - printf("Total sectors moved: %ld\n", raidPtr->userstats.num_sect_moved); - printf("Average access size (sect): %ld\n", RF_DB0_CHECK(raidPtr->userstats.num_sect_moved, raidPtr->userstats.num_ios)); - printf("Achieved data rate: %ld.%ld MB/sec\n", mbs, mbs_frac); + printf("Number of I/Os: %ld\n", + raidPtr->userstats.num_ios); + printf("Elapsed time (us): %ld\n", + elapsed_us); + printf("User I/Os per second: %ld\n", + RF_DB0_CHECK(raidPtr->userstats.num_ios, (elapsed_us / 1000000))); + printf("Average user response time: %ld us\n", + RF_DB0_CHECK(raidPtr->userstats.sum_io_us, + raidPtr->userstats.num_ios)); + printf("Total sectors moved: %ld\n", + raidPtr->userstats.num_sect_moved); + printf("Average access size (sect): %ld\n", + RF_DB0_CHECK(raidPtr->userstats.num_sect_moved, + raidPtr->userstats.num_ios)); + printf("Achieved data rate: %ld.%ld MB/sec\n", + mbs, mbs_frac); } |