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