rf_driver.c revision 1.81 1 /* $NetBSD: rf_driver.c,v 1.81 2004/01/01 19:27:36 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.81 2004/01/01 19:27:36 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_pool_lock)
126 static struct pool rf_rad_pool;
127 #define RF_MAX_FREE_RAD 128
128 #define RF_RAD_INC 16
129 #define RF_RAD_INITIAL 32
130
131 /* debug variables */
132 char rf_panicbuf[2048]; /* a buffer to hold an error msg when we panic */
133
134 /* main configuration routines */
135 static int raidframe_booted = 0;
136
137 static void rf_ConfigureDebug(RF_Config_t * cfgPtr);
138 static void set_debug_option(char *name, long val);
139 static void rf_UnconfigureArray(void);
140 static void rf_ShutdownRDFreeList(void *);
141 static int rf_ConfigureRDFreeList(RF_ShutdownList_t **);
142
143 RF_DECLARE_MUTEX(rf_printf_mutex) /* debug only: avoids interleaved
144 * printfs by different stripes */
145
146 #define SIGNAL_QUIESCENT_COND(_raid_) wakeup(&((_raid_)->accesses_suspended))
147 #define WAIT_FOR_QUIESCENCE(_raid_) \
148 ltsleep(&((_raid_)->accesses_suspended), PRIBIO, \
149 "raidframe quiesce", 0, &((_raid_)->access_suspend_mutex))
150
151 static int configureCount = 0; /* number of active configurations */
152 static int isconfigged = 0; /* is basic raidframe (non per-array)
153 * stuff configged */
154 RF_DECLARE_LKMGR_STATIC_MUTEX(configureMutex) /* used to lock the configuration
155 * stuff */
156 static RF_ShutdownList_t *globalShutdown; /* non array-specific
157 * stuff */
158
159 static int rf_ConfigureRDFreeList(RF_ShutdownList_t ** listp);
160
161 /* called at system boot time */
162 int
163 rf_BootRaidframe()
164 {
165
166 if (raidframe_booted)
167 return (EBUSY);
168 raidframe_booted = 1;
169 lockinit(&configureMutex, PRIBIO, "RAIDframe lock", 0, 0);
170 configureCount = 0;
171 isconfigged = 0;
172 globalShutdown = NULL;
173 return (0);
174 }
175
176 /*
177 * Called whenever an array is shutdown
178 */
179 static void
180 rf_UnconfigureArray()
181 {
182 int rc;
183
184 RF_LOCK_LKMGR_MUTEX(configureMutex);
185 if (--configureCount == 0) { /* if no active configurations, shut
186 * everything down */
187 isconfigged = 0;
188
189 rc = rf_ShutdownList(&globalShutdown);
190 if (rc) {
191 RF_ERRORMSG1("RAIDFRAME: unable to do global shutdown, rc=%d\n", rc);
192 }
193
194 /*
195 * We must wait until now, because the AllocList module
196 * uses the DebugMem module.
197 */
198 #if RF_DEBUG_MEM
199 if (rf_memDebug)
200 rf_print_unfreed();
201 #endif
202 }
203 RF_UNLOCK_LKMGR_MUTEX(configureMutex);
204 }
205
206 /*
207 * Called to shut down an array.
208 */
209 int
210 rf_Shutdown(RF_Raid_t *raidPtr)
211 {
212
213 if (!raidPtr->valid) {
214 RF_ERRORMSG("Attempt to shut down unconfigured RAIDframe driver. Aborting shutdown\n");
215 return (EINVAL);
216 }
217 /*
218 * wait for outstanding IOs to land
219 * As described in rf_raid.h, we use the rad_freelist lock
220 * to protect the per-array info about outstanding descs
221 * since we need to do freelist locking anyway, and this
222 * cuts down on the amount of serialization we've got going
223 * on.
224 */
225 RF_LOCK_MUTEX(rf_rad_pool_lock);
226 if (raidPtr->waitShutdown) {
227 RF_UNLOCK_MUTEX(rf_rad_pool_lock);
228 return (EBUSY);
229 }
230 raidPtr->waitShutdown = 1;
231 while (raidPtr->nAccOutstanding) {
232 RF_WAIT_COND(raidPtr->outstandingCond, rf_rad_pool_lock);
233 }
234 RF_UNLOCK_MUTEX(rf_rad_pool_lock);
235
236 /* Wait for any parity re-writes to stop... */
237 while (raidPtr->parity_rewrite_in_progress) {
238 printf("Waiting for parity re-write to exit...\n");
239 tsleep(&raidPtr->parity_rewrite_in_progress, PRIBIO,
240 "rfprwshutdown", 0);
241 }
242
243 raidPtr->valid = 0;
244
245 rf_update_component_labels(raidPtr, RF_FINAL_COMPONENT_UPDATE);
246
247 rf_UnconfigureVnodes(raidPtr);
248
249 rf_ShutdownList(&raidPtr->shutdownList);
250
251 rf_UnconfigureArray();
252
253 return (0);
254 }
255
256
257 #define DO_INIT_CONFIGURE(f) { \
258 rc = f (&globalShutdown); \
259 if (rc) { \
260 RF_ERRORMSG2("RAIDFRAME: failed %s with %d\n", RF_STRING(f), rc); \
261 rf_ShutdownList(&globalShutdown); \
262 configureCount--; \
263 RF_UNLOCK_LKMGR_MUTEX(configureMutex); \
264 return(rc); \
265 } \
266 }
267
268 #define DO_RAID_FAIL() { \
269 rf_UnconfigureVnodes(raidPtr); \
270 rf_ShutdownList(&raidPtr->shutdownList); \
271 rf_UnconfigureArray(); \
272 }
273
274 #define DO_RAID_INIT_CONFIGURE(f) { \
275 rc = f (&raidPtr->shutdownList, raidPtr, cfgPtr); \
276 if (rc) { \
277 RF_ERRORMSG2("RAIDFRAME: failed %s with %d\n", RF_STRING(f), rc); \
278 DO_RAID_FAIL(); \
279 return(rc); \
280 } \
281 }
282
283 #define DO_RAID_MUTEX(_m_) { \
284 rf_mutex_init((_m_)); \
285 }
286
287 int
288 rf_Configure(RF_Raid_t *raidPtr, RF_Config_t *cfgPtr, RF_AutoConfig_t *ac)
289 {
290 RF_RowCol_t col;
291 int rc;
292
293 RF_LOCK_LKMGR_MUTEX(configureMutex);
294 configureCount++;
295 if (isconfigged == 0) {
296 rf_mutex_init(&rf_printf_mutex);
297
298 /* initialize globals */
299
300 DO_INIT_CONFIGURE(rf_ConfigureAllocList);
301
302 /*
303 * Yes, this does make debugging general to the whole
304 * system instead of being array specific. Bummer, drag.
305 */
306 rf_ConfigureDebug(cfgPtr);
307 DO_INIT_CONFIGURE(rf_ConfigureDebugMem);
308 DO_INIT_CONFIGURE(rf_ConfigureAccessTrace);
309 DO_INIT_CONFIGURE(rf_ConfigureMapModule);
310 DO_INIT_CONFIGURE(rf_ConfigureReconEvent);
311 DO_INIT_CONFIGURE(rf_ConfigureCallback);
312 DO_INIT_CONFIGURE(rf_ConfigureRDFreeList);
313 DO_INIT_CONFIGURE(rf_ConfigureNWayXor);
314 DO_INIT_CONFIGURE(rf_ConfigureStripeLockFreeList);
315 DO_INIT_CONFIGURE(rf_ConfigureMCPair);
316 DO_INIT_CONFIGURE(rf_ConfigureDAGs);
317 DO_INIT_CONFIGURE(rf_ConfigureDAGFuncs);
318 DO_INIT_CONFIGURE(rf_ConfigureReconstruction);
319 DO_INIT_CONFIGURE(rf_ConfigureCopyback);
320 DO_INIT_CONFIGURE(rf_ConfigureDiskQueueSystem);
321 isconfigged = 1;
322 }
323 RF_UNLOCK_LKMGR_MUTEX(configureMutex);
324
325 DO_RAID_MUTEX(&raidPtr->mutex);
326 /* set up the cleanup list. Do this after ConfigureDebug so that
327 * value of memDebug will be set */
328
329 rf_MakeAllocList(raidPtr->cleanupList);
330 if (raidPtr->cleanupList == NULL) {
331 DO_RAID_FAIL();
332 return (ENOMEM);
333 }
334 rc = rf_ShutdownCreate(&raidPtr->shutdownList,
335 (void (*) (void *)) rf_FreeAllocList,
336 raidPtr->cleanupList);
337 if (rc) {
338 rf_print_unable_to_add_shutdown(__FILE__, __LINE__, rc);
339 DO_RAID_FAIL();
340 return (rc);
341 }
342 raidPtr->numCol = cfgPtr->numCol;
343 raidPtr->numSpare = cfgPtr->numSpare;
344
345 raidPtr->status = rf_rs_optimal;
346 raidPtr->reconControl = NULL;
347
348 TAILQ_INIT(&(raidPtr->iodone));
349 simple_lock_init(&(raidPtr->iodone_lock));
350
351 DO_RAID_INIT_CONFIGURE(rf_ConfigureEngine);
352 DO_RAID_INIT_CONFIGURE(rf_ConfigureStripeLocks);
353
354 raidPtr->outstandingCond = 0;
355
356 raidPtr->nAccOutstanding = 0;
357 raidPtr->waitShutdown = 0;
358
359 DO_RAID_MUTEX(&raidPtr->access_suspend_mutex);
360
361 raidPtr->waitForReconCond = 0;
362
363 if (ac!=NULL) {
364 /* We have an AutoConfig structure.. Don't do the
365 normal disk configuration... call the auto config
366 stuff */
367 rf_AutoConfigureDisks(raidPtr, cfgPtr, ac);
368 } else {
369 DO_RAID_INIT_CONFIGURE(rf_ConfigureDisks);
370 DO_RAID_INIT_CONFIGURE(rf_ConfigureSpareDisks);
371 }
372 /* do this after ConfigureDisks & ConfigureSpareDisks to be sure dev
373 * no. is set */
374 DO_RAID_INIT_CONFIGURE(rf_ConfigureDiskQueues);
375
376 DO_RAID_INIT_CONFIGURE(rf_ConfigureLayout);
377
378 DO_RAID_INIT_CONFIGURE(rf_ConfigurePSStatus);
379
380 for (col = 0; col < raidPtr->numCol; col++) {
381 /*
382 * XXX better distribution
383 */
384 raidPtr->hist_diskreq[col] = 0;
385 }
386
387 raidPtr->numNewFailures = 0;
388 raidPtr->copyback_in_progress = 0;
389 raidPtr->parity_rewrite_in_progress = 0;
390 raidPtr->adding_hot_spare = 0;
391 raidPtr->recon_in_progress = 0;
392 raidPtr->maxOutstanding = cfgPtr->maxOutstandingDiskReqs;
393
394 /* autoconfigure and root_partition will actually get filled in
395 after the config is done */
396 raidPtr->autoconfigure = 0;
397 raidPtr->root_partition = 0;
398 raidPtr->last_unit = raidPtr->raidid;
399 raidPtr->config_order = 0;
400
401 if (rf_keepAccTotals) {
402 raidPtr->keep_acc_totals = 1;
403 }
404 rf_StartUserStats(raidPtr);
405
406 raidPtr->valid = 1;
407
408 printf("raid%d: %s\n", raidPtr->raidid,
409 raidPtr->Layout.map->configName);
410 printf("raid%d: Components:", raidPtr->raidid);
411
412 for (col = 0; col < raidPtr->numCol; col++) {
413 printf(" %s", raidPtr->Disks[col].devname);
414 if (RF_DEAD_DISK(raidPtr->Disks[col].status)) {
415 printf("[**FAILED**]");
416 }
417 }
418 printf("\n");
419 printf("raid%d: Total Sectors: %lu (%lu MB)\n",
420 raidPtr->raidid,
421 (unsigned long) raidPtr->totalSectors,
422 (unsigned long) (raidPtr->totalSectors / 1024 *
423 (1 << raidPtr->logBytesPerSector) / 1024));
424
425 return (0);
426 }
427
428 static void
429 rf_ShutdownRDFreeList(void *ignored)
430 {
431 pool_destroy(&rf_rad_pool);
432 }
433
434 static int
435 rf_ConfigureRDFreeList(RF_ShutdownList_t **listp)
436 {
437 int rc;
438
439 pool_init(&rf_rad_pool, sizeof(RF_RaidAccessDesc_t), 0, 0, 0,
440 "rf_rad_pl", NULL);
441 pool_sethiwat(&rf_rad_pool, RF_MAX_FREE_RAD);
442 pool_prime(&rf_rad_pool, RF_RAD_INITIAL);
443 rc = rf_ShutdownCreate(listp, rf_ShutdownRDFreeList, NULL);
444 if (rc) {
445 rf_print_unable_to_add_shutdown(__FILE__, __LINE__, rc);
446 rf_ShutdownRDFreeList(NULL);
447 return (rc);
448 }
449 return (0);
450 }
451
452 RF_RaidAccessDesc_t *
453 rf_AllocRaidAccDesc(RF_Raid_t *raidPtr, RF_IoType_t type,
454 RF_RaidAddr_t raidAddress, RF_SectorCount_t numBlocks,
455 caddr_t bufPtr, void *bp, RF_RaidAccessFlags_t flags,
456 RF_AccessState_t *states)
457 {
458 RF_RaidAccessDesc_t *desc;
459
460 desc = pool_get(&rf_rad_pool, PR_WAITOK);
461 simple_lock_init(&desc->mutex);
462
463 if (raidPtr->waitShutdown) {
464 /*
465 * Actually, we're shutting the array down. Free the desc
466 * and return NULL.
467 */
468
469 RF_UNLOCK_MUTEX(rf_rad_pool_lock);
470 pool_put(&rf_rad_pool, desc);
471 return (NULL);
472 }
473 raidPtr->nAccOutstanding++;
474
475 RF_UNLOCK_MUTEX(rf_rad_pool_lock);
476
477 desc->raidPtr = (void *) raidPtr;
478 desc->type = type;
479 desc->raidAddress = raidAddress;
480 desc->numBlocks = numBlocks;
481 desc->bufPtr = bufPtr;
482 desc->bp = bp;
483 desc->paramDAG = NULL;
484 desc->paramASM = NULL;
485 desc->flags = flags;
486 desc->states = states;
487 desc->state = 0;
488
489 desc->status = 0;
490 memset((char *) &desc->tracerec, 0, sizeof(RF_AccTraceEntry_t));
491 desc->callbackFunc = NULL;
492 desc->callbackArg = NULL;
493 desc->next = NULL;
494 desc->cleanupList = NULL;
495 rf_MakeAllocList(desc->cleanupList);
496 return (desc);
497 }
498
499 void
500 rf_FreeRaidAccDesc(RF_RaidAccessDesc_t *desc)
501 {
502 RF_Raid_t *raidPtr = desc->raidPtr;
503
504 RF_ASSERT(desc);
505
506 rf_FreeAllocList(desc->cleanupList);
507 pool_put(&rf_rad_pool, desc);
508 raidPtr->nAccOutstanding--;
509 if (raidPtr->waitShutdown) {
510 RF_SIGNAL_COND(raidPtr->outstandingCond);
511 }
512 RF_UNLOCK_MUTEX(rf_rad_pool_lock);
513 }
514 /*********************************************************************
515 * Main routine for performing an access.
516 * Accesses are retried until a DAG can not be selected. This occurs
517 * when either the DAG library is incomplete or there are too many
518 * failures in a parity group.
519 *
520 * type should be read or write async_flag should be RF_TRUE or
521 * RF_FALSE bp_in is a buf pointer. void * to facilitate ignoring it
522 * outside the kernel
523 ********************************************************************/
524 int
525 rf_DoAccess(RF_Raid_t * raidPtr, RF_IoType_t type, int async_flag,
526 RF_RaidAddr_t raidAddress, RF_SectorCount_t numBlocks,
527 caddr_t bufPtr, void *bp_in, RF_RaidAccessFlags_t flags)
528 {
529 RF_RaidAccessDesc_t *desc;
530 caddr_t lbufPtr = bufPtr;
531 struct buf *bp = (struct buf *) bp_in;
532
533 raidAddress += rf_raidSectorOffset;
534
535 #if RF_ACCESS_DEBUG
536 if (rf_accessDebug) {
537
538 printf("logBytes is: %d %d %d\n", raidPtr->raidid,
539 raidPtr->logBytesPerSector,
540 (int) rf_RaidAddressToByte(raidPtr, numBlocks));
541 printf("raid%d: %s raidAddr %d (stripeid %d-%d) numBlocks %d (%d bytes) buf 0x%lx\n", raidPtr->raidid,
542 (type == RF_IO_TYPE_READ) ? "READ" : "WRITE", (int) raidAddress,
543 (int) rf_RaidAddressToStripeID(&raidPtr->Layout, raidAddress),
544 (int) rf_RaidAddressToStripeID(&raidPtr->Layout, raidAddress + numBlocks - 1),
545 (int) numBlocks,
546 (int) rf_RaidAddressToByte(raidPtr, numBlocks),
547 (long) bufPtr);
548 }
549 #endif
550 if (raidAddress + numBlocks > raidPtr->totalSectors) {
551
552 printf("DoAccess: raid addr %lu too large to access %lu sectors. Max legal addr is %lu\n",
553 (u_long) raidAddress, (u_long) numBlocks, (u_long) raidPtr->totalSectors);
554
555
556 bp->b_flags |= B_ERROR;
557 bp->b_resid = bp->b_bcount;
558 bp->b_error = ENOSPC;
559 biodone(bp);
560 return (ENOSPC);
561 }
562 desc = rf_AllocRaidAccDesc(raidPtr, type, raidAddress,
563 numBlocks, lbufPtr, bp, flags, raidPtr->Layout.map->states);
564
565 if (desc == NULL) {
566 return (ENOMEM);
567 }
568 RF_ETIMER_START(desc->tracerec.tot_timer);
569
570 desc->async_flag = async_flag;
571
572 rf_ContinueRaidAccess(desc);
573
574 return (0);
575 }
576 #if 0
577 /* force the array into reconfigured mode without doing reconstruction */
578 int
579 rf_SetReconfiguredMode(RF_Raid_t *raidPtr, int col)
580 {
581 if (!(raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE)) {
582 printf("Can't set reconfigured mode in dedicated-spare array\n");
583 RF_PANIC();
584 }
585 RF_LOCK_MUTEX(raidPtr->mutex);
586 raidPtr->numFailures++;
587 raidPtr->Disks[col].status = rf_ds_dist_spared;
588 raidPtr->status = rf_rs_reconfigured;
589 rf_update_component_labels(raidPtr, RF_NORMAL_COMPONENT_UPDATE);
590 /* install spare table only if declustering + distributed sparing
591 * architecture. */
592 if (raidPtr->Layout.map->flags & RF_BD_DECLUSTERED)
593 rf_InstallSpareTable(raidPtr, col);
594 RF_UNLOCK_MUTEX(raidPtr->mutex);
595 return (0);
596 }
597 #endif
598
599 int
600 rf_FailDisk(RF_Raid_t *raidPtr, int fcol, int initRecon)
601 {
602 RF_LOCK_MUTEX(raidPtr->mutex);
603 if (raidPtr->Disks[fcol].status != rf_ds_failed) {
604 /* must be failing something that is valid, or else it's
605 already marked as failed (in which case we don't
606 want to mark it failed again!) */
607 raidPtr->numFailures++;
608 raidPtr->Disks[fcol].status = rf_ds_failed;
609 raidPtr->status = rf_rs_degraded;
610 }
611 RF_UNLOCK_MUTEX(raidPtr->mutex);
612
613 rf_update_component_labels(raidPtr, RF_NORMAL_COMPONENT_UPDATE);
614
615 /* Close the component, so that it's not "locked" if someone
616 else want's to use it! */
617
618 rf_close_component(raidPtr, raidPtr->raid_cinfo[fcol].ci_vp,
619 raidPtr->Disks[fcol].auto_configured);
620
621 RF_LOCK_MUTEX(raidPtr->mutex);
622 raidPtr->raid_cinfo[fcol].ci_vp = NULL;
623
624 /* Need to mark the component as not being auto_configured
625 (in case it was previously). */
626
627 raidPtr->Disks[fcol].auto_configured = 0;
628 RF_UNLOCK_MUTEX(raidPtr->mutex);
629
630 if (initRecon)
631 rf_ReconstructFailedDisk(raidPtr, fcol);
632 return (0);
633 }
634 /* releases a thread that is waiting for the array to become quiesced.
635 * access_suspend_mutex should be locked upon calling this
636 */
637 void
638 rf_SignalQuiescenceLock(RF_Raid_t *raidPtr)
639 {
640 #if RF_DEBUG_QUIESCE
641 if (rf_quiesceDebug) {
642 printf("raid%d: Signalling quiescence lock\n",
643 raidPtr->raidid);
644 }
645 #endif
646 raidPtr->access_suspend_release = 1;
647
648 if (raidPtr->waiting_for_quiescence) {
649 SIGNAL_QUIESCENT_COND(raidPtr);
650 }
651 }
652 /* suspends all new requests to the array. No effect on accesses that are in flight. */
653 int
654 rf_SuspendNewRequestsAndWait(RF_Raid_t *raidPtr)
655 {
656 #if RF_DEBUG_QUIESCE
657 if (rf_quiesceDebug)
658 printf("raid%d: Suspending new reqs\n", raidPtr->raidid);
659 #endif
660 RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
661 raidPtr->accesses_suspended++;
662 raidPtr->waiting_for_quiescence = (raidPtr->accs_in_flight == 0) ? 0 : 1;
663
664 if (raidPtr->waiting_for_quiescence) {
665 raidPtr->access_suspend_release = 0;
666 while (!raidPtr->access_suspend_release) {
667 printf("raid%d: Suspending: Waiting for Quiescence\n",
668 raidPtr->raidid);
669 WAIT_FOR_QUIESCENCE(raidPtr);
670 raidPtr->waiting_for_quiescence = 0;
671 }
672 }
673 printf("raid%d: Quiescence reached..\n", raidPtr->raidid);
674
675 RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
676 return (raidPtr->waiting_for_quiescence);
677 }
678 /* wake up everyone waiting for quiescence to be released */
679 void
680 rf_ResumeNewRequests(RF_Raid_t *raidPtr)
681 {
682 RF_CallbackDesc_t *t, *cb;
683
684 #if RF_DEBUG_QUIESCE
685 if (rf_quiesceDebug)
686 printf("Resuming new reqs\n");
687 #endif
688
689 RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
690 raidPtr->accesses_suspended--;
691 if (raidPtr->accesses_suspended == 0)
692 cb = raidPtr->quiesce_wait_list;
693 else
694 cb = NULL;
695 raidPtr->quiesce_wait_list = NULL;
696 RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
697
698 while (cb) {
699 t = cb;
700 cb = cb->next;
701 (t->callbackFunc) (t->callbackArg);
702 rf_FreeCallbackDesc(t);
703 }
704 }
705 /*****************************************************************************************
706 *
707 * debug routines
708 *
709 ****************************************************************************************/
710
711 static void
712 set_debug_option(char *name, long val)
713 {
714 RF_DebugName_t *p;
715
716 for (p = rf_debugNames; p->name; p++) {
717 if (!strcmp(p->name, name)) {
718 *(p->ptr) = val;
719 printf("[Set debug variable %s to %ld]\n", name, val);
720 return;
721 }
722 }
723 RF_ERRORMSG1("Unknown debug string \"%s\"\n", name);
724 }
725
726
727 /* would like to use sscanf here, but apparently not available in kernel */
728 /*ARGSUSED*/
729 static void
730 rf_ConfigureDebug(RF_Config_t *cfgPtr)
731 {
732 char *val_p, *name_p, *white_p;
733 long val;
734 int i;
735
736 rf_ResetDebugOptions();
737 for (i = 0; cfgPtr->debugVars[i][0] && i < RF_MAXDBGV; i++) {
738 name_p = rf_find_non_white(&cfgPtr->debugVars[i][0]);
739 white_p = rf_find_white(name_p); /* skip to start of 2nd
740 * word */
741 val_p = rf_find_non_white(white_p);
742 if (*val_p == '0' && *(val_p + 1) == 'x')
743 val = rf_htoi(val_p + 2);
744 else
745 val = rf_atoi(val_p);
746 *white_p = '\0';
747 set_debug_option(name_p, val);
748 }
749 }
750 /* performance monitoring stuff */
751
752 #define TIMEVAL_TO_US(t) (((long) t.tv_sec) * 1000000L + (long) t.tv_usec)
753
754 #if !defined(_KERNEL) && !defined(SIMULATE)
755
756 /*
757 * Throughput stats currently only used in user-level RAIDframe
758 */
759
760 static int
761 rf_InitThroughputStats(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr,
762 RF_Config_t *cfgPtr)
763 {
764 int rc;
765
766 /* these used by user-level raidframe only */
767 rf_mutex_init(&raidPtr->throughputstats.mutex);
768 raidPtr->throughputstats.sum_io_us = 0;
769 raidPtr->throughputstats.num_ios = 0;
770 raidPtr->throughputstats.num_out_ios = 0;
771 return (0);
772 }
773
774 void
775 rf_StartThroughputStats(RF_Raid_t *raidPtr)
776 {
777 RF_LOCK_MUTEX(raidPtr->throughputstats.mutex);
778 raidPtr->throughputstats.num_ios++;
779 raidPtr->throughputstats.num_out_ios++;
780 if (raidPtr->throughputstats.num_out_ios == 1)
781 RF_GETTIME(raidPtr->throughputstats.start);
782 RF_UNLOCK_MUTEX(raidPtr->throughputstats.mutex);
783 }
784
785 static void
786 rf_StopThroughputStats(RF_Raid_t *raidPtr)
787 {
788 struct timeval diff;
789
790 RF_LOCK_MUTEX(raidPtr->throughputstats.mutex);
791 raidPtr->throughputstats.num_out_ios--;
792 if (raidPtr->throughputstats.num_out_ios == 0) {
793 RF_GETTIME(raidPtr->throughputstats.stop);
794 RF_TIMEVAL_DIFF(&raidPtr->throughputstats.start, &raidPtr->throughputstats.stop, &diff);
795 raidPtr->throughputstats.sum_io_us += TIMEVAL_TO_US(diff);
796 }
797 RF_UNLOCK_MUTEX(raidPtr->throughputstats.mutex);
798 }
799
800 static void
801 rf_PrintThroughputStats(RF_Raid_t *raidPtr)
802 {
803 RF_ASSERT(raidPtr->throughputstats.num_out_ios == 0);
804 if (raidPtr->throughputstats.sum_io_us != 0) {
805 printf("[Througphut: %8.2f IOs/second]\n", raidPtr->throughputstats.num_ios
806 / (raidPtr->throughputstats.sum_io_us / 1000000.0));
807 }
808 }
809 #endif /* !KERNEL && !SIMULATE */
810
811 void
812 rf_StartUserStats(RF_Raid_t *raidPtr)
813 {
814 RF_GETTIME(raidPtr->userstats.start);
815 raidPtr->userstats.sum_io_us = 0;
816 raidPtr->userstats.num_ios = 0;
817 raidPtr->userstats.num_sect_moved = 0;
818 }
819
820 void
821 rf_StopUserStats(RF_Raid_t *raidPtr)
822 {
823 RF_GETTIME(raidPtr->userstats.stop);
824 }
825
826 /* rt: resp time in us
827 numsect: number of sectors for this access */
828 void
829 rf_UpdateUserStats(RF_Raid_t *raidPtr, int rt, int numsect)
830 {
831 raidPtr->userstats.sum_io_us += rt;
832 raidPtr->userstats.num_ios++;
833 raidPtr->userstats.num_sect_moved += numsect;
834 }
835
836 void
837 rf_PrintUserStats(RF_Raid_t *raidPtr)
838 {
839 long elapsed_us, mbs, mbs_frac;
840 struct timeval diff;
841
842 RF_TIMEVAL_DIFF(&raidPtr->userstats.start,
843 &raidPtr->userstats.stop, &diff);
844 elapsed_us = TIMEVAL_TO_US(diff);
845
846 /* 2000 sectors per megabyte, 10000000 microseconds per second */
847 if (elapsed_us)
848 mbs = (raidPtr->userstats.num_sect_moved / 2000) /
849 (elapsed_us / 1000000);
850 else
851 mbs = 0;
852
853 /* this computes only the first digit of the fractional mb/s moved */
854 if (elapsed_us) {
855 mbs_frac = ((raidPtr->userstats.num_sect_moved / 200) /
856 (elapsed_us / 1000000)) - (mbs * 10);
857 } else {
858 mbs_frac = 0;
859 }
860
861 printf("raid%d: Number of I/Os: %ld\n",
862 raidPtr->raidid, raidPtr->userstats.num_ios);
863 printf("raid%d: Elapsed time (us): %ld\n",
864 raidPtr->raidid, elapsed_us);
865 printf("raid%d: User I/Os per second: %ld\n",
866 raidPtr->raidid, RF_DB0_CHECK(raidPtr->userstats.num_ios,
867 (elapsed_us / 1000000)));
868 printf("raid%d: Average user response time: %ld us\n",
869 raidPtr->raidid, RF_DB0_CHECK(raidPtr->userstats.sum_io_us,
870 raidPtr->userstats.num_ios));
871 printf("raid%d: Total sectors moved: %ld\n",
872 raidPtr->raidid, raidPtr->userstats.num_sect_moved);
873 printf("raid%d: Average access size (sect): %ld\n",
874 raidPtr->raidid, RF_DB0_CHECK(raidPtr->userstats.num_sect_moved,
875 raidPtr->userstats.num_ios));
876 printf("raid%d: Achieved data rate: %ld.%ld MB/sec\n",
877 raidPtr->raidid, mbs, mbs_frac);
878 }
879
880
881 void
882 rf_print_panic_message(int line, char *file)
883 {
884 sprintf(rf_panicbuf,"raidframe error at line %d file %s",
885 line, file);
886 }
887
888 #ifdef RAID_DIAGNOSTIC
889 void
890 rf_print_assert_panic_message(int line, char *file, char *condition)
891 {
892 sprintf(rf_panicbuf,
893 "raidframe error at line %d file %s (failed asserting %s)\n",
894 line, file, condition);
895 }
896 #endif
897
898 void
899 rf_print_unable_to_init_mutex(char *file, int line, int rc)
900 {
901 RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n",
902 file, line, rc);
903 }
904
905 void
906 rf_print_unable_to_add_shutdown(char *file, int line, int rc)
907 {
908 RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n",
909 file, line, rc);
910 }
911