1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 1994, 2000 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate * All rights reserved.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include "mhd_local.h"
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate #include <stropts.h>
32*0Sstevel@tonic-gate #include "ff.h"
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate /*
35*0Sstevel@tonic-gate * manipulate failfast driver
36*0Sstevel@tonic-gate */
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate /*
39*0Sstevel@tonic-gate * disarm failfast
40*0Sstevel@tonic-gate */
41*0Sstevel@tonic-gate int
mhd_ff_disarm(mhd_drive_set_t * sp,mhd_error_t * mhep)42*0Sstevel@tonic-gate mhd_ff_disarm(
43*0Sstevel@tonic-gate mhd_drive_set_t *sp,
44*0Sstevel@tonic-gate mhd_error_t *mhep
45*0Sstevel@tonic-gate )
46*0Sstevel@tonic-gate {
47*0Sstevel@tonic-gate struct strioctl si;
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate MHDPRINTF1(("%s: disarm\n", sp->sr_name));
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate /* check locks */
52*0Sstevel@tonic-gate assert(MUTEX_HELD(&sp->sr_mx));
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate /* ignore not open */
55*0Sstevel@tonic-gate if (sp->sr_ff < 0)
56*0Sstevel@tonic-gate return (0);
57*0Sstevel@tonic-gate
58*0Sstevel@tonic-gate /* disarm any existing failfast */
59*0Sstevel@tonic-gate (void) memset(&si, 0, sizeof (si));
60*0Sstevel@tonic-gate si.ic_cmd = FAILFAST_DISARM;
61*0Sstevel@tonic-gate si.ic_timout = INFTIM;
62*0Sstevel@tonic-gate if (ioctl(sp->sr_ff, I_STR, &si) != 0)
63*0Sstevel@tonic-gate return (mhd_error(mhep, errno, "/dev/ff"));
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate /* return success */
66*0Sstevel@tonic-gate return (0);
67*0Sstevel@tonic-gate }
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate /*
70*0Sstevel@tonic-gate * open failfast
71*0Sstevel@tonic-gate */
72*0Sstevel@tonic-gate int
mhd_ff_open(mhd_drive_set_t * sp,mhd_error_t * mhep)73*0Sstevel@tonic-gate mhd_ff_open(
74*0Sstevel@tonic-gate mhd_drive_set_t *sp,
75*0Sstevel@tonic-gate mhd_error_t *mhep
76*0Sstevel@tonic-gate )
77*0Sstevel@tonic-gate {
78*0Sstevel@tonic-gate struct strioctl si;
79*0Sstevel@tonic-gate
80*0Sstevel@tonic-gate /* check locks */
81*0Sstevel@tonic-gate assert(MUTEX_HELD(&sp->sr_mx));
82*0Sstevel@tonic-gate assert((sp->sr_ff_mode == MHD_FF_DEBUG) ||
83*0Sstevel@tonic-gate (sp->sr_ff_mode == MHD_FF_HALT) ||
84*0Sstevel@tonic-gate (sp->sr_ff_mode == MHD_FF_PANIC));
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate /* open if not already */
87*0Sstevel@tonic-gate if ((sp->sr_ff < 0) &&
88*0Sstevel@tonic-gate ((sp->sr_ff = open("/dev/ff", O_RDWR, 0)) < 0)) {
89*0Sstevel@tonic-gate return (mhd_error(mhep, errno, "/dev/ff"));
90*0Sstevel@tonic-gate }
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gate /* disarm any existing failfast */
93*0Sstevel@tonic-gate if (mhd_ff_disarm(sp, mhep) != 0)
94*0Sstevel@tonic-gate return (-1);
95*0Sstevel@tonic-gate
96*0Sstevel@tonic-gate /* load setname */
97*0Sstevel@tonic-gate (void) memset(&si, 0, sizeof (si));
98*0Sstevel@tonic-gate si.ic_cmd = FAILFAST_SETNAME;
99*0Sstevel@tonic-gate si.ic_timout = INFTIM;
100*0Sstevel@tonic-gate si.ic_len = strlen(sp->sr_name);
101*0Sstevel@tonic-gate si.ic_dp = sp->sr_name;
102*0Sstevel@tonic-gate if (ioctl(sp->sr_ff, I_STR, &si) != 0)
103*0Sstevel@tonic-gate return (mhd_error(mhep, errno, "/dev/ff"));
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gate /* load failfast mode */
106*0Sstevel@tonic-gate (void) memset(&si, 0, sizeof (si));
107*0Sstevel@tonic-gate switch (sp->sr_ff_mode) {
108*0Sstevel@tonic-gate case MHD_FF_DEBUG:
109*0Sstevel@tonic-gate si.ic_cmd = FAILFAST_DEBUG_MODE;
110*0Sstevel@tonic-gate break;
111*0Sstevel@tonic-gate case MHD_FF_HALT:
112*0Sstevel@tonic-gate si.ic_cmd = FAILFAST_HALT_MODE;
113*0Sstevel@tonic-gate break;
114*0Sstevel@tonic-gate default:
115*0Sstevel@tonic-gate assert(0);
116*0Sstevel@tonic-gate /* FALLTHROUGH */
117*0Sstevel@tonic-gate case MHD_FF_PANIC:
118*0Sstevel@tonic-gate si.ic_cmd = FAILFAST_PANIC_MODE;
119*0Sstevel@tonic-gate break;
120*0Sstevel@tonic-gate }
121*0Sstevel@tonic-gate si.ic_timout = INFTIM;
122*0Sstevel@tonic-gate if (ioctl(sp->sr_ff, I_STR, &si) != 0)
123*0Sstevel@tonic-gate return (mhd_error(mhep, errno, "/dev/ff"));
124*0Sstevel@tonic-gate
125*0Sstevel@tonic-gate /* return success */
126*0Sstevel@tonic-gate return (0);
127*0Sstevel@tonic-gate }
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate /*
130*0Sstevel@tonic-gate * close failfast
131*0Sstevel@tonic-gate */
132*0Sstevel@tonic-gate int
mhd_ff_close(mhd_drive_set_t * sp,mhd_error_t * mhep)133*0Sstevel@tonic-gate mhd_ff_close(
134*0Sstevel@tonic-gate mhd_drive_set_t *sp,
135*0Sstevel@tonic-gate mhd_error_t *mhep
136*0Sstevel@tonic-gate )
137*0Sstevel@tonic-gate {
138*0Sstevel@tonic-gate int rval = 0;
139*0Sstevel@tonic-gate
140*0Sstevel@tonic-gate /* check locks */
141*0Sstevel@tonic-gate assert(MUTEX_HELD(&sp->sr_mx));
142*0Sstevel@tonic-gate
143*0Sstevel@tonic-gate /* ignore not open */
144*0Sstevel@tonic-gate if (sp->sr_ff < 0)
145*0Sstevel@tonic-gate return (0);
146*0Sstevel@tonic-gate
147*0Sstevel@tonic-gate /* disarm any existing failfast */
148*0Sstevel@tonic-gate if (mhd_ff_disarm(sp, mhep) != 0)
149*0Sstevel@tonic-gate rval = -1;
150*0Sstevel@tonic-gate
151*0Sstevel@tonic-gate /* close device */
152*0Sstevel@tonic-gate if (close(sp->sr_ff) != 0)
153*0Sstevel@tonic-gate rval = mhd_error(mhep, errno, "/dev/ff");
154*0Sstevel@tonic-gate sp->sr_ff = -1;
155*0Sstevel@tonic-gate
156*0Sstevel@tonic-gate /* return success */
157*0Sstevel@tonic-gate return (rval);
158*0Sstevel@tonic-gate }
159*0Sstevel@tonic-gate
160*0Sstevel@tonic-gate /*
161*0Sstevel@tonic-gate * reset failfast
162*0Sstevel@tonic-gate */
163*0Sstevel@tonic-gate int
mhd_ff_rearm(mhd_drive_set_t * sp,mhd_error_t * mhep)164*0Sstevel@tonic-gate mhd_ff_rearm(
165*0Sstevel@tonic-gate mhd_drive_set_t *sp,
166*0Sstevel@tonic-gate mhd_error_t *mhep
167*0Sstevel@tonic-gate )
168*0Sstevel@tonic-gate {
169*0Sstevel@tonic-gate uint_t ff = sp->sr_timeouts.mh_ff;
170*0Sstevel@tonic-gate struct strioctl si;
171*0Sstevel@tonic-gate
172*0Sstevel@tonic-gate MHDPRINTF1(("%s: rearm\n", sp->sr_name));
173*0Sstevel@tonic-gate
174*0Sstevel@tonic-gate /* check locks */
175*0Sstevel@tonic-gate assert(MUTEX_HELD(&sp->sr_mx));
176*0Sstevel@tonic-gate assert(sp->sr_ff >= 0);
177*0Sstevel@tonic-gate
178*0Sstevel@tonic-gate /* if timeout is 0, disarm */
179*0Sstevel@tonic-gate if (ff == 0)
180*0Sstevel@tonic-gate return (mhd_ff_disarm(sp, mhep));
181*0Sstevel@tonic-gate
182*0Sstevel@tonic-gate /* rearm failfast */
183*0Sstevel@tonic-gate (void) memset(&si, 0, sizeof (si));
184*0Sstevel@tonic-gate si.ic_cmd = FAILFAST_ARM;
185*0Sstevel@tonic-gate si.ic_timout = INFTIM;
186*0Sstevel@tonic-gate si.ic_len = sizeof (ff);
187*0Sstevel@tonic-gate si.ic_dp = (char *)&ff;
188*0Sstevel@tonic-gate if (ioctl(sp->sr_ff, I_STR, &si) != 0)
189*0Sstevel@tonic-gate return (mhd_error(mhep, errno, "/dev/ff"));
190*0Sstevel@tonic-gate
191*0Sstevel@tonic-gate /* return success */
192*0Sstevel@tonic-gate return (0);
193*0Sstevel@tonic-gate }
194*0Sstevel@tonic-gate
195*0Sstevel@tonic-gate /*
196*0Sstevel@tonic-gate * die right now
197*0Sstevel@tonic-gate */
198*0Sstevel@tonic-gate void
mhd_ff_die(mhd_drive_set_t * sp)199*0Sstevel@tonic-gate mhd_ff_die(
200*0Sstevel@tonic-gate mhd_drive_set_t *sp
201*0Sstevel@tonic-gate )
202*0Sstevel@tonic-gate {
203*0Sstevel@tonic-gate uint_t ff = 0;
204*0Sstevel@tonic-gate struct strioctl si;
205*0Sstevel@tonic-gate
206*0Sstevel@tonic-gate MHDPRINTF(("%s: die\n", sp->sr_name));
207*0Sstevel@tonic-gate
208*0Sstevel@tonic-gate /* check locks */
209*0Sstevel@tonic-gate assert(MUTEX_HELD(&sp->sr_mx));
210*0Sstevel@tonic-gate assert(sp->sr_ff >= 0);
211*0Sstevel@tonic-gate
212*0Sstevel@tonic-gate /* rearm failfast for now */
213*0Sstevel@tonic-gate (void) memset(&si, 0, sizeof (si));
214*0Sstevel@tonic-gate si.ic_cmd = FAILFAST_ARM;
215*0Sstevel@tonic-gate si.ic_timout = INFTIM;
216*0Sstevel@tonic-gate si.ic_len = sizeof (ff);
217*0Sstevel@tonic-gate si.ic_dp = (char *)&ff;
218*0Sstevel@tonic-gate if (ioctl(sp->sr_ff, I_STR, &si) != 0)
219*0Sstevel@tonic-gate mhd_perror("/dev/ff");
220*0Sstevel@tonic-gate }
221*0Sstevel@tonic-gate
222*0Sstevel@tonic-gate /*
223*0Sstevel@tonic-gate * check set and reset failfast
224*0Sstevel@tonic-gate */
225*0Sstevel@tonic-gate void
mhd_ff_check(mhd_drive_set_t * sp)226*0Sstevel@tonic-gate mhd_ff_check(
227*0Sstevel@tonic-gate mhd_drive_set_t *sp
228*0Sstevel@tonic-gate )
229*0Sstevel@tonic-gate {
230*0Sstevel@tonic-gate mhd_drive_list_t *dlp = &sp->sr_drives;
231*0Sstevel@tonic-gate mhd_msec_t ff = sp->sr_timeouts.mh_ff;
232*0Sstevel@tonic-gate mhd_msec_t now = mhd_time();
233*0Sstevel@tonic-gate uint_t i, ok, cnt;
234*0Sstevel@tonic-gate
235*0Sstevel@tonic-gate /* check locks */
236*0Sstevel@tonic-gate assert(MUTEX_HELD(&sp->sr_mx));
237*0Sstevel@tonic-gate assert(sp->sr_ff >= 0);
238*0Sstevel@tonic-gate assert((sp->sr_ff_mode == MHD_FF_DEBUG) ||
239*0Sstevel@tonic-gate (sp->sr_ff_mode == MHD_FF_HALT) ||
240*0Sstevel@tonic-gate (sp->sr_ff_mode == MHD_FF_PANIC));
241*0Sstevel@tonic-gate
242*0Sstevel@tonic-gate /* see how many drives are within alloted time */
243*0Sstevel@tonic-gate for (ok = cnt = 0, i = 0; (i < dlp->dl_ndrive); ++i) {
244*0Sstevel@tonic-gate mhd_drive_t *dp = dlp->dl_drives[i];
245*0Sstevel@tonic-gate
246*0Sstevel@tonic-gate if (dp->dr_state != DRIVE_PROBING)
247*0Sstevel@tonic-gate continue;
248*0Sstevel@tonic-gate ++cnt;
249*0Sstevel@tonic-gate
250*0Sstevel@tonic-gate MHDPRINTF2(("%s: now %llu dr_time %llu diff %llu ff %llu\n",
251*0Sstevel@tonic-gate dp->dr_rname, now, dp->dr_time, (now - dp->dr_time), ff));
252*0Sstevel@tonic-gate if ((now - dp->dr_time) <= ff)
253*0Sstevel@tonic-gate ++ok;
254*0Sstevel@tonic-gate }
255*0Sstevel@tonic-gate
256*0Sstevel@tonic-gate /* check for majority */
257*0Sstevel@tonic-gate if ((cnt == 0) || (ok >= ((cnt / 2) + 1))) {
258*0Sstevel@tonic-gate mhd_error_t status = mhd_null_error;
259*0Sstevel@tonic-gate
260*0Sstevel@tonic-gate if (mhd_ff_rearm(sp, &status) == 0)
261*0Sstevel@tonic-gate return;
262*0Sstevel@tonic-gate mhd_clrerror(&status);
263*0Sstevel@tonic-gate }
264*0Sstevel@tonic-gate
265*0Sstevel@tonic-gate /* die */
266*0Sstevel@tonic-gate mhd_eprintf("%s: failed majority cnt %d ok %d\n",
267*0Sstevel@tonic-gate sp->sr_name, cnt, ok);
268*0Sstevel@tonic-gate mhd_ff_die(sp);
269*0Sstevel@tonic-gate }
270