rf_driver.c revision 1.105 1 /* $NetBSD: rf_driver.c,v 1.105 2004/11/16 16:45:51 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.105 2004/11/16 16:45:51 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 static int rf_AllocEmergBuffers(RF_Raid_t *);
159 static void rf_FreeEmergBuffers(RF_Raid_t *);
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
183 RF_LOCK_LKMGR_MUTEX(configureMutex);
184 if (--configureCount == 0) { /* if no active configurations, shut
185 * everything down */
186 isconfigged = 0;
187 rf_ShutdownList(&globalShutdown);
188
189 /*
190 * We must wait until now, because the AllocList module
191 * uses the DebugMem module.
192 */
193 #if RF_DEBUG_MEM
194 if (rf_memDebug)
195 rf_print_unfreed();
196 #endif
197 }
198 RF_UNLOCK_LKMGR_MUTEX(configureMutex);
199 }
200
201 /*
202 * Called to shut down an array.
203 */
204 int
205 rf_Shutdown(RF_Raid_t *raidPtr)
206 {
207
208 if (!raidPtr->valid) {
209 RF_ERRORMSG("Attempt to shut down unconfigured RAIDframe driver. Aborting shutdown\n");
210 return (EINVAL);
211 }
212 /*
213 * wait for outstanding IOs to land
214 * As described in rf_raid.h, we use the rad_freelist lock
215 * to protect the per-array info about outstanding descs
216 * since we need to do freelist locking anyway, and this
217 * cuts down on the amount of serialization we've got going
218 * on.
219 */
220 RF_LOCK_MUTEX(rf_rad_lock);
221 if (raidPtr->waitShutdown) {
222 RF_UNLOCK_MUTEX(rf_rad_lock);
223 return (EBUSY);
224 }
225 raidPtr->waitShutdown = 1;
226 while (raidPtr->nAccOutstanding) {
227 RF_WAIT_COND(raidPtr->outstandingCond, rf_rad_lock);
228 }
229 RF_UNLOCK_MUTEX(rf_rad_lock);
230
231 /* Wait for any parity re-writes to stop... */
232 while (raidPtr->parity_rewrite_in_progress) {
233 printf("Waiting for parity re-write to exit...\n");
234 tsleep(&raidPtr->parity_rewrite_in_progress, PRIBIO,
235 "rfprwshutdown", 0);
236 }
237
238 raidPtr->valid = 0;
239
240 rf_update_component_labels(raidPtr, RF_FINAL_COMPONENT_UPDATE);
241
242 rf_UnconfigureVnodes(raidPtr);
243
244 rf_FreeEmergBuffers(raidPtr);
245
246 rf_ShutdownList(&raidPtr->shutdownList);
247
248 rf_UnconfigureArray();
249
250 return (0);
251 }
252
253
254 #define DO_INIT_CONFIGURE(f) { \
255 rc = f (&globalShutdown); \
256 if (rc) { \
257 RF_ERRORMSG2("RAIDFRAME: failed %s with %d\n", RF_STRING(f), rc); \
258 rf_ShutdownList(&globalShutdown); \
259 configureCount--; \
260 RF_UNLOCK_LKMGR_MUTEX(configureMutex); \
261 return(rc); \
262 } \
263 }
264
265 #define DO_RAID_FAIL() { \
266 rf_UnconfigureVnodes(raidPtr); \
267 rf_FreeEmergBuffers(raidPtr); \
268 rf_ShutdownList(&raidPtr->shutdownList); \
269 rf_UnconfigureArray(); \
270 }
271
272 #define DO_RAID_INIT_CONFIGURE(f) { \
273 rc = f (&raidPtr->shutdownList, raidPtr, cfgPtr); \
274 if (rc) { \
275 RF_ERRORMSG2("RAIDFRAME: failed %s with %d\n", RF_STRING(f), rc); \
276 DO_RAID_FAIL(); \
277 return(rc); \
278 } \
279 }
280
281 #define DO_RAID_MUTEX(_m_) { \
282 rf_mutex_init((_m_)); \
283 }
284
285 int
286 rf_Configure(RF_Raid_t *raidPtr, RF_Config_t *cfgPtr, RF_AutoConfig_t *ac)
287 {
288 RF_RowCol_t col;
289 int rc;
290
291 RF_LOCK_LKMGR_MUTEX(configureMutex);
292 configureCount++;
293 if (isconfigged == 0) {
294 rf_mutex_init(&rf_printf_mutex);
295
296 /* initialize globals */
297
298 DO_INIT_CONFIGURE(rf_ConfigureAllocList);
299
300 /*
301 * Yes, this does make debugging general to the whole
302 * system instead of being array specific. Bummer, drag.
303 */
304 rf_ConfigureDebug(cfgPtr);
305 DO_INIT_CONFIGURE(rf_ConfigureDebugMem);
306 #if RF_ACC_TRACE > 0
307 DO_INIT_CONFIGURE(rf_ConfigureAccessTrace);
308 #endif
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 rf_ShutdownCreate(&raidPtr->shutdownList,
335 (void (*) (void *)) rf_FreeAllocList,
336 raidPtr->cleanupList);
337
338 raidPtr->numCol = cfgPtr->numCol;
339 raidPtr->numSpare = cfgPtr->numSpare;
340
341 raidPtr->status = rf_rs_optimal;
342 raidPtr->reconControl = NULL;
343
344 TAILQ_INIT(&(raidPtr->iodone));
345 simple_lock_init(&(raidPtr->iodone_lock));
346
347 DO_RAID_INIT_CONFIGURE(rf_ConfigureEngine);
348 DO_RAID_INIT_CONFIGURE(rf_ConfigureStripeLocks);
349
350 raidPtr->outstandingCond = 0;
351
352 raidPtr->nAccOutstanding = 0;
353 raidPtr->waitShutdown = 0;
354
355 DO_RAID_MUTEX(&raidPtr->access_suspend_mutex);
356
357 raidPtr->waitForReconCond = 0;
358
359 if (ac!=NULL) {
360 /* We have an AutoConfig structure.. Don't do the
361 normal disk configuration... call the auto config
362 stuff */
363 rf_AutoConfigureDisks(raidPtr, cfgPtr, ac);
364 } else {
365 DO_RAID_INIT_CONFIGURE(rf_ConfigureDisks);
366 DO_RAID_INIT_CONFIGURE(rf_ConfigureSpareDisks);
367 }
368 /* do this after ConfigureDisks & ConfigureSpareDisks to be sure dev
369 * no. is set */
370 DO_RAID_INIT_CONFIGURE(rf_ConfigureDiskQueues);
371
372 DO_RAID_INIT_CONFIGURE(rf_ConfigureLayout);
373
374 DO_RAID_INIT_CONFIGURE(rf_ConfigurePSStatus);
375
376 #if RF_INCLUDE_CHAINDECLUSTER > 0
377 for (col = 0; col < raidPtr->numCol; col++) {
378 /*
379 * XXX better distribution
380 */
381 raidPtr->hist_diskreq[col] = 0;
382 }
383 #endif
384 raidPtr->numNewFailures = 0;
385 raidPtr->copyback_in_progress = 0;
386 raidPtr->parity_rewrite_in_progress = 0;
387 raidPtr->adding_hot_spare = 0;
388 raidPtr->recon_in_progress = 0;
389 raidPtr->maxOutstanding = cfgPtr->maxOutstandingDiskReqs;
390
391 /* autoconfigure and root_partition will actually get filled in
392 after the config is done */
393 raidPtr->autoconfigure = 0;
394 raidPtr->root_partition = 0;
395 raidPtr->last_unit = raidPtr->raidid;
396 raidPtr->config_order = 0;
397
398 if (rf_keepAccTotals) {
399 raidPtr->keep_acc_totals = 1;
400 }
401
402 /* Allocate a bunch of buffers to be used in low-memory conditions */
403 raidPtr->iobuf = NULL;
404
405 rc = rf_AllocEmergBuffers(raidPtr);
406 if (rc) {
407 printf("raid%d: Unable to allocate emergency buffers.\n",
408 raidPtr->raidid);
409 DO_RAID_FAIL();
410 return(rc);
411 }
412
413 raidPtr->valid = 1;
414
415 printf("raid%d: %s\n", raidPtr->raidid,
416 raidPtr->Layout.map->configName);
417 printf("raid%d: Components:", raidPtr->raidid);
418
419 for (col = 0; col < raidPtr->numCol; col++) {
420 printf(" %s", raidPtr->Disks[col].devname);
421 if (RF_DEAD_DISK(raidPtr->Disks[col].status)) {
422 printf("[**FAILED**]");
423 }
424 }
425 printf("\n");
426 printf("raid%d: Total Sectors: %lu (%lu MB)\n",
427 raidPtr->raidid,
428 (unsigned long) raidPtr->totalSectors,
429 (unsigned long) (raidPtr->totalSectors / 1024 *
430 (1 << raidPtr->logBytesPerSector) / 1024));
431
432 return (0);
433 }
434
435
436 /*
437
438 Routines to allocate and free the "emergency buffers" for a given
439 RAID set. These emergency buffers will be used when the kernel runs
440 out of kernel memory.
441
442 */
443
444 static int
445 rf_AllocEmergBuffers(RF_Raid_t *raidPtr)
446 {
447 void *tmpbuf;
448 RF_VoidPointerListElem_t *vple;
449 int i;
450
451 /* XXX next line needs tuning... */
452 raidPtr->numEmergencyBuffers = 10 * raidPtr->numCol;
453 #if DEBUG
454 printf("raid%d: allocating %d buffers of %d bytes.\n",
455 raidPtr->raidid,
456 raidPtr->numEmergencyBuffers,
457 (int)(raidPtr->Layout.sectorsPerStripeUnit <<
458 raidPtr->logBytesPerSector));
459 #endif
460 for (i = 0; i < raidPtr->numEmergencyBuffers; i++) {
461 tmpbuf = malloc( raidPtr->Layout.sectorsPerStripeUnit <<
462 raidPtr->logBytesPerSector,
463 M_RAIDFRAME, M_NOWAIT);
464 if (tmpbuf) {
465 vple = rf_AllocVPListElem();
466 vple->p= tmpbuf;
467 vple->next = raidPtr->iobuf;
468 raidPtr->iobuf = vple;
469 raidPtr->iobuf_count++;
470 } else {
471 printf("raid%d: failed to allocate emergency buffer!\n",
472 raidPtr->raidid);
473 break;
474 }
475 }
476
477 /* XXX next line needs tuning too... */
478 raidPtr->numEmergencyStripeBuffers = 10;
479 for (i = 0; i < raidPtr->numEmergencyStripeBuffers; i++) {
480 tmpbuf = malloc( raidPtr->numCol * (raidPtr->Layout.sectorsPerStripeUnit <<
481 raidPtr->logBytesPerSector),
482 M_RAIDFRAME, M_NOWAIT);
483 if (tmpbuf) {
484 vple = rf_AllocVPListElem();
485 vple->p= tmpbuf;
486 vple->next = raidPtr->stripebuf;
487 raidPtr->stripebuf = vple;
488 raidPtr->stripebuf_count++;
489 } else {
490 printf("raid%d: failed to allocate emergency stripe buffer!\n",
491 raidPtr->raidid);
492 break;
493 }
494 }
495
496 return (0);
497 }
498
499 static void
500 rf_FreeEmergBuffers(RF_Raid_t *raidPtr)
501 {
502 RF_VoidPointerListElem_t *tmp;
503
504 /* Free the emergency IO buffers */
505 while (raidPtr->iobuf != NULL) {
506 tmp = raidPtr->iobuf;
507 raidPtr->iobuf = raidPtr->iobuf->next;
508 free(tmp->p, M_RAIDFRAME);
509 rf_FreeVPListElem(tmp);
510 }
511
512 /* Free the emergency stripe buffers */
513 while (raidPtr->stripebuf != NULL) {
514 tmp = raidPtr->stripebuf;
515 raidPtr->stripebuf = raidPtr->stripebuf->next;
516 free(tmp->p, M_RAIDFRAME);
517 rf_FreeVPListElem(tmp);
518 }
519 }
520
521
522 static void
523 rf_ShutdownRDFreeList(void *ignored)
524 {
525 pool_destroy(&rf_pools.rad);
526 }
527
528 static int
529 rf_ConfigureRDFreeList(RF_ShutdownList_t **listp)
530 {
531
532 rf_pool_init(&rf_pools.rad, sizeof(RF_RaidAccessDesc_t),
533 "rf_rad_pl", RF_MIN_FREE_RAD, RF_MAX_FREE_RAD);
534 rf_ShutdownCreate(listp, rf_ShutdownRDFreeList, NULL);
535 simple_lock_init(&rf_rad_lock);
536 return (0);
537 }
538
539 RF_RaidAccessDesc_t *
540 rf_AllocRaidAccDesc(RF_Raid_t *raidPtr, RF_IoType_t type,
541 RF_RaidAddr_t raidAddress, RF_SectorCount_t numBlocks,
542 caddr_t bufPtr, void *bp, RF_RaidAccessFlags_t flags,
543 const RF_AccessState_t *states)
544 {
545 RF_RaidAccessDesc_t *desc;
546
547 desc = pool_get(&rf_pools.rad, PR_WAITOK);
548
549 RF_LOCK_MUTEX(rf_rad_lock);
550 if (raidPtr->waitShutdown) {
551 /*
552 * Actually, we're shutting the array down. Free the desc
553 * and return NULL.
554 */
555
556 RF_UNLOCK_MUTEX(rf_rad_lock);
557 pool_put(&rf_pools.rad, desc);
558 return (NULL);
559 }
560 raidPtr->nAccOutstanding++;
561
562 RF_UNLOCK_MUTEX(rf_rad_lock);
563
564 desc->raidPtr = (void *) raidPtr;
565 desc->type = type;
566 desc->raidAddress = raidAddress;
567 desc->numBlocks = numBlocks;
568 desc->bufPtr = bufPtr;
569 desc->bp = bp;
570 desc->flags = flags;
571 desc->states = states;
572 desc->state = 0;
573 desc->dagList = NULL;
574
575 desc->status = 0;
576 desc->numRetries = 0;
577 #if RF_ACC_TRACE > 0
578 memset((char *) &desc->tracerec, 0, sizeof(RF_AccTraceEntry_t));
579 #endif
580 desc->callbackFunc = NULL;
581 desc->callbackArg = NULL;
582 desc->next = NULL;
583 desc->iobufs = NULL;
584 desc->stripebufs = NULL;
585
586 return (desc);
587 }
588
589 void
590 rf_FreeRaidAccDesc(RF_RaidAccessDesc_t *desc)
591 {
592 RF_Raid_t *raidPtr = desc->raidPtr;
593 RF_DagList_t *dagList, *temp;
594 RF_VoidPointerListElem_t *tmp;
595
596 RF_ASSERT(desc);
597
598 /* Cleanup the dagList(s) */
599 dagList = desc->dagList;
600 while(dagList != NULL) {
601 temp = dagList;
602 dagList = dagList->next;
603 rf_FreeDAGList(temp);
604 }
605
606 while (desc->iobufs) {
607 tmp = desc->iobufs;
608 desc->iobufs = desc->iobufs->next;
609 rf_FreeIOBuffer(raidPtr, tmp);
610 }
611
612 while (desc->stripebufs) {
613 tmp = desc->stripebufs;
614 desc->stripebufs = desc->stripebufs->next;
615 rf_FreeStripeBuffer(raidPtr, tmp);
616 }
617
618 pool_put(&rf_pools.rad, desc);
619 RF_LOCK_MUTEX(rf_rad_lock);
620 raidPtr->nAccOutstanding--;
621 if (raidPtr->waitShutdown) {
622 RF_SIGNAL_COND(raidPtr->outstandingCond);
623 }
624 RF_UNLOCK_MUTEX(rf_rad_lock);
625 }
626 /*********************************************************************
627 * Main routine for performing an access.
628 * Accesses are retried until a DAG can not be selected. This occurs
629 * when either the DAG library is incomplete or there are too many
630 * failures in a parity group.
631 *
632 * type should be read or write async_flag should be RF_TRUE or
633 * RF_FALSE bp_in is a buf pointer. void * to facilitate ignoring it
634 * outside the kernel
635 ********************************************************************/
636 int
637 rf_DoAccess(RF_Raid_t * raidPtr, RF_IoType_t type, int async_flag,
638 RF_RaidAddr_t raidAddress, RF_SectorCount_t numBlocks,
639 caddr_t bufPtr, void *bp_in, RF_RaidAccessFlags_t flags)
640 {
641 RF_RaidAccessDesc_t *desc;
642 caddr_t lbufPtr = bufPtr;
643 struct buf *bp = (struct buf *) bp_in;
644
645 raidAddress += rf_raidSectorOffset;
646
647 #if RF_ACCESS_DEBUG
648 if (rf_accessDebug) {
649
650 printf("logBytes is: %d %d %d\n", raidPtr->raidid,
651 raidPtr->logBytesPerSector,
652 (int) rf_RaidAddressToByte(raidPtr, numBlocks));
653 printf("raid%d: %s raidAddr %d (stripeid %d-%d) numBlocks %d (%d bytes) buf 0x%lx\n", raidPtr->raidid,
654 (type == RF_IO_TYPE_READ) ? "READ" : "WRITE", (int) raidAddress,
655 (int) rf_RaidAddressToStripeID(&raidPtr->Layout, raidAddress),
656 (int) rf_RaidAddressToStripeID(&raidPtr->Layout, raidAddress + numBlocks - 1),
657 (int) numBlocks,
658 (int) rf_RaidAddressToByte(raidPtr, numBlocks),
659 (long) bufPtr);
660 }
661 #endif
662
663 desc = rf_AllocRaidAccDesc(raidPtr, type, raidAddress,
664 numBlocks, lbufPtr, bp, flags, raidPtr->Layout.map->states);
665
666 if (desc == NULL) {
667 return (ENOMEM);
668 }
669 #if RF_ACC_TRACE > 0
670 RF_ETIMER_START(desc->tracerec.tot_timer);
671 #endif
672 desc->async_flag = async_flag;
673
674 rf_ContinueRaidAccess(desc);
675
676 return (0);
677 }
678 #if 0
679 /* force the array into reconfigured mode without doing reconstruction */
680 int
681 rf_SetReconfiguredMode(RF_Raid_t *raidPtr, int col)
682 {
683 if (!(raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE)) {
684 printf("Can't set reconfigured mode in dedicated-spare array\n");
685 RF_PANIC();
686 }
687 RF_LOCK_MUTEX(raidPtr->mutex);
688 raidPtr->numFailures++;
689 raidPtr->Disks[col].status = rf_ds_dist_spared;
690 raidPtr->status = rf_rs_reconfigured;
691 rf_update_component_labels(raidPtr, RF_NORMAL_COMPONENT_UPDATE);
692 /* install spare table only if declustering + distributed sparing
693 * architecture. */
694 if (raidPtr->Layout.map->flags & RF_BD_DECLUSTERED)
695 rf_InstallSpareTable(raidPtr, col);
696 RF_UNLOCK_MUTEX(raidPtr->mutex);
697 return (0);
698 }
699 #endif
700
701 int
702 rf_FailDisk(RF_Raid_t *raidPtr, int fcol, int initRecon)
703 {
704
705 /* need to suspend IO's here -- if there are DAGs in flight
706 and we pull the rug out from under ci_vp, Bad Things
707 can happen. */
708
709 rf_SuspendNewRequestsAndWait(raidPtr);
710
711 RF_LOCK_MUTEX(raidPtr->mutex);
712 if (raidPtr->Disks[fcol].status != rf_ds_failed) {
713 /* must be failing something that is valid, or else it's
714 already marked as failed (in which case we don't
715 want to mark it failed again!) */
716 raidPtr->numFailures++;
717 raidPtr->Disks[fcol].status = rf_ds_failed;
718 raidPtr->status = rf_rs_degraded;
719 }
720 RF_UNLOCK_MUTEX(raidPtr->mutex);
721
722 rf_update_component_labels(raidPtr, RF_NORMAL_COMPONENT_UPDATE);
723
724 /* Close the component, so that it's not "locked" if someone
725 else want's to use it! */
726
727 rf_close_component(raidPtr, raidPtr->raid_cinfo[fcol].ci_vp,
728 raidPtr->Disks[fcol].auto_configured);
729
730 RF_LOCK_MUTEX(raidPtr->mutex);
731 raidPtr->raid_cinfo[fcol].ci_vp = NULL;
732
733 /* Need to mark the component as not being auto_configured
734 (in case it was previously). */
735
736 raidPtr->Disks[fcol].auto_configured = 0;
737 RF_UNLOCK_MUTEX(raidPtr->mutex);
738 /* now we can allow IO to continue -- we'll be suspending it
739 again in rf_ReconstructFailedDisk() if we have to.. */
740
741 rf_ResumeNewRequests(raidPtr);
742
743 if (initRecon)
744 rf_ReconstructFailedDisk(raidPtr, fcol);
745 return (0);
746 }
747 /* releases a thread that is waiting for the array to become quiesced.
748 * access_suspend_mutex should be locked upon calling this
749 */
750 void
751 rf_SignalQuiescenceLock(RF_Raid_t *raidPtr)
752 {
753 #if RF_DEBUG_QUIESCE
754 if (rf_quiesceDebug) {
755 printf("raid%d: Signalling quiescence lock\n",
756 raidPtr->raidid);
757 }
758 #endif
759 raidPtr->access_suspend_release = 1;
760
761 if (raidPtr->waiting_for_quiescence) {
762 SIGNAL_QUIESCENT_COND(raidPtr);
763 }
764 }
765 /* suspends all new requests to the array. No effect on accesses that are in flight. */
766 int
767 rf_SuspendNewRequestsAndWait(RF_Raid_t *raidPtr)
768 {
769 #if RF_DEBUG_QUIESCE
770 if (rf_quiesceDebug)
771 printf("raid%d: Suspending new reqs\n", raidPtr->raidid);
772 #endif
773 RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
774 raidPtr->accesses_suspended++;
775 raidPtr->waiting_for_quiescence = (raidPtr->accs_in_flight == 0) ? 0 : 1;
776
777 if (raidPtr->waiting_for_quiescence) {
778 raidPtr->access_suspend_release = 0;
779 while (!raidPtr->access_suspend_release) {
780 #if RF_DEBUG_QUIESCE
781 printf("raid%d: Suspending: Waiting for Quiescence\n",
782 raidPtr->raidid);
783 #endif
784 WAIT_FOR_QUIESCENCE(raidPtr);
785 raidPtr->waiting_for_quiescence = 0;
786 }
787 }
788 #if RF_DEBUG_QUIESCE
789 printf("raid%d: Quiescence reached..\n", raidPtr->raidid);
790 #endif
791
792 RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
793 return (raidPtr->waiting_for_quiescence);
794 }
795 /* wake up everyone waiting for quiescence to be released */
796 void
797 rf_ResumeNewRequests(RF_Raid_t *raidPtr)
798 {
799 RF_CallbackDesc_t *t, *cb;
800
801 #if RF_DEBUG_QUIESCE
802 if (rf_quiesceDebug)
803 printf("Resuming new reqs\n");
804 #endif
805
806 RF_LOCK_MUTEX(raidPtr->access_suspend_mutex);
807 raidPtr->accesses_suspended--;
808 if (raidPtr->accesses_suspended == 0)
809 cb = raidPtr->quiesce_wait_list;
810 else
811 cb = NULL;
812 raidPtr->quiesce_wait_list = NULL;
813 RF_UNLOCK_MUTEX(raidPtr->access_suspend_mutex);
814
815 while (cb) {
816 t = cb;
817 cb = cb->next;
818 (t->callbackFunc) (t->callbackArg);
819 rf_FreeCallbackDesc(t);
820 }
821 }
822 /*****************************************************************************************
823 *
824 * debug routines
825 *
826 ****************************************************************************************/
827
828 static void
829 set_debug_option(char *name, long val)
830 {
831 RF_DebugName_t *p;
832
833 for (p = rf_debugNames; p->name; p++) {
834 if (!strcmp(p->name, name)) {
835 *(p->ptr) = val;
836 printf("[Set debug variable %s to %ld]\n", name, val);
837 return;
838 }
839 }
840 RF_ERRORMSG1("Unknown debug string \"%s\"\n", name);
841 }
842
843
844 /* would like to use sscanf here, but apparently not available in kernel */
845 /*ARGSUSED*/
846 static void
847 rf_ConfigureDebug(RF_Config_t *cfgPtr)
848 {
849 char *val_p, *name_p, *white_p;
850 long val;
851 int i;
852
853 rf_ResetDebugOptions();
854 for (i = 0; cfgPtr->debugVars[i][0] && i < RF_MAXDBGV; i++) {
855 name_p = rf_find_non_white(&cfgPtr->debugVars[i][0]);
856 white_p = rf_find_white(name_p); /* skip to start of 2nd
857 * word */
858 val_p = rf_find_non_white(white_p);
859 if (*val_p == '0' && *(val_p + 1) == 'x')
860 val = rf_htoi(val_p + 2);
861 else
862 val = rf_atoi(val_p);
863 *white_p = '\0';
864 set_debug_option(name_p, val);
865 }
866 }
867
868 void
869 rf_print_panic_message(int line, char *file)
870 {
871 snprintf(rf_panicbuf, sizeof(rf_panicbuf),
872 "raidframe error at line %d file %s", line, file);
873 }
874
875 #ifdef RAID_DIAGNOSTIC
876 void
877 rf_print_assert_panic_message(int line, char *file, char *condition)
878 {
879 snprintf(rf_panicbuf, sizeof(rf_panicbuf),
880 "raidframe error at line %d file %s (failed asserting %s)\n",
881 line, file, condition);
882 }
883 #endif
884
885 void
886 rf_print_unable_to_init_mutex(char *file, int line, int rc)
887 {
888 RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n",
889 file, line, rc);
890 }
891
892 void
893 rf_print_unable_to_add_shutdown(char *file, int line, int rc)
894 {
895 RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n",
896 file, line, rc);
897 }
898