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 1994, 1999, 2000-2002 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
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 /*
30*0Sstevel@tonic-gate * error functions
31*0Sstevel@tonic-gate */
32*0Sstevel@tonic-gate #include <sys/param.h>
33*0Sstevel@tonic-gate #include <sys/systm.h>
34*0Sstevel@tonic-gate #include <sys/sysmacros.h>
35*0Sstevel@tonic-gate #include <sys/lvm/mdvar.h>
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate /*
38*0Sstevel@tonic-gate * null error constant
39*0Sstevel@tonic-gate */
40*0Sstevel@tonic-gate const md_error_t mdnullerror = {{MDEC_VOID}, NULL, NULL, NULL};
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate /*
43*0Sstevel@tonic-gate * clear error
44*0Sstevel@tonic-gate */
45*0Sstevel@tonic-gate void
mdclrerror(md_error_t * ep)46*0Sstevel@tonic-gate mdclrerror(
47*0Sstevel@tonic-gate md_error_t *ep
48*0Sstevel@tonic-gate )
49*0Sstevel@tonic-gate {
50*0Sstevel@tonic-gate bzero((caddr_t)ep, sizeof (*ep));
51*0Sstevel@tonic-gate }
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate /*
54*0Sstevel@tonic-gate * steal (copy) an error code safely
55*0Sstevel@tonic-gate */
56*0Sstevel@tonic-gate int
mdstealerror(md_error_t * to,md_error_t * from)57*0Sstevel@tonic-gate mdstealerror(
58*0Sstevel@tonic-gate md_error_t *to,
59*0Sstevel@tonic-gate md_error_t *from
60*0Sstevel@tonic-gate )
61*0Sstevel@tonic-gate {
62*0Sstevel@tonic-gate mdclrerror(to);
63*0Sstevel@tonic-gate *to = *from;
64*0Sstevel@tonic-gate (void) bzero((caddr_t)from, sizeof (*from));
65*0Sstevel@tonic-gate return (0);
66*0Sstevel@tonic-gate }
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate /*
69*0Sstevel@tonic-gate * simple error
70*0Sstevel@tonic-gate */
71*0Sstevel@tonic-gate int
mderror(md_error_t * ep,md_void_errno_t errnum)72*0Sstevel@tonic-gate mderror(
73*0Sstevel@tonic-gate md_error_t *ep,
74*0Sstevel@tonic-gate md_void_errno_t errnum
75*0Sstevel@tonic-gate )
76*0Sstevel@tonic-gate {
77*0Sstevel@tonic-gate md_void_error_t *ip = &ep->info.md_error_info_t_u.void_error;
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate mdclrerror(ep);
80*0Sstevel@tonic-gate ep->info.errclass = MDEC_VOID;
81*0Sstevel@tonic-gate ip->errnum = errnum;
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate return (0);
84*0Sstevel@tonic-gate }
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate /*
87*0Sstevel@tonic-gate * system error
88*0Sstevel@tonic-gate */
89*0Sstevel@tonic-gate int
mdsyserror(md_error_t * ep,int errnum)90*0Sstevel@tonic-gate mdsyserror(
91*0Sstevel@tonic-gate md_error_t *ep,
92*0Sstevel@tonic-gate int errnum
93*0Sstevel@tonic-gate )
94*0Sstevel@tonic-gate {
95*0Sstevel@tonic-gate md_sys_error_t *ip = &ep->info.md_error_info_t_u.sys_error;
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gate mdclrerror(ep);
98*0Sstevel@tonic-gate ep->info.errclass = MDEC_SYS;
99*0Sstevel@tonic-gate ip->errnum = errnum;
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gate return (0);
102*0Sstevel@tonic-gate }
103*0Sstevel@tonic-gate
104*0Sstevel@tonic-gate /*
105*0Sstevel@tonic-gate * device error
106*0Sstevel@tonic-gate */
107*0Sstevel@tonic-gate int
mddeverror(md_error_t * ep,md_dev_errno_t errnum,md_dev64_t dev)108*0Sstevel@tonic-gate mddeverror(
109*0Sstevel@tonic-gate md_error_t *ep,
110*0Sstevel@tonic-gate md_dev_errno_t errnum,
111*0Sstevel@tonic-gate md_dev64_t dev
112*0Sstevel@tonic-gate )
113*0Sstevel@tonic-gate {
114*0Sstevel@tonic-gate md_dev_error_t *ip = &ep->info.md_error_info_t_u.dev_error;
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gate mdclrerror(ep);
117*0Sstevel@tonic-gate ep->info.errclass = MDEC_DEV;
118*0Sstevel@tonic-gate ip->errnum = errnum;
119*0Sstevel@tonic-gate ip->dev = (md_dev64_t)dev;
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gate return (0);
122*0Sstevel@tonic-gate }
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate /*
125*0Sstevel@tonic-gate * metadevice error
126*0Sstevel@tonic-gate */
127*0Sstevel@tonic-gate int
mdmderror(md_error_t * ep,md_md_errno_t errnum,minor_t mnum)128*0Sstevel@tonic-gate mdmderror(
129*0Sstevel@tonic-gate md_error_t *ep,
130*0Sstevel@tonic-gate md_md_errno_t errnum,
131*0Sstevel@tonic-gate minor_t mnum
132*0Sstevel@tonic-gate )
133*0Sstevel@tonic-gate {
134*0Sstevel@tonic-gate md_md_error_t *ip = &ep->info.md_error_info_t_u.md_error;
135*0Sstevel@tonic-gate
136*0Sstevel@tonic-gate mdclrerror(ep);
137*0Sstevel@tonic-gate ep->info.errclass = MDEC_MD;
138*0Sstevel@tonic-gate ip->errnum = errnum;
139*0Sstevel@tonic-gate ip->mnum = mnum;
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gate return (0);
142*0Sstevel@tonic-gate }
143*0Sstevel@tonic-gate
144*0Sstevel@tonic-gate /*
145*0Sstevel@tonic-gate * component error
146*0Sstevel@tonic-gate */
147*0Sstevel@tonic-gate int
mdcomperror(md_error_t * ep,md_comp_errno_t errnum,minor_t mnum,md_dev64_t dev)148*0Sstevel@tonic-gate mdcomperror(
149*0Sstevel@tonic-gate md_error_t *ep,
150*0Sstevel@tonic-gate md_comp_errno_t errnum,
151*0Sstevel@tonic-gate minor_t mnum,
152*0Sstevel@tonic-gate md_dev64_t dev
153*0Sstevel@tonic-gate )
154*0Sstevel@tonic-gate {
155*0Sstevel@tonic-gate md_comp_error_t *ip = &ep->info.md_error_info_t_u.comp_error;
156*0Sstevel@tonic-gate
157*0Sstevel@tonic-gate mdclrerror(ep);
158*0Sstevel@tonic-gate ep->info.errclass = MDEC_COMP;
159*0Sstevel@tonic-gate ip->errnum = errnum;
160*0Sstevel@tonic-gate ip->comp.mnum = mnum;
161*0Sstevel@tonic-gate ip->comp.dev = dev;
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate return (0);
164*0Sstevel@tonic-gate }
165*0Sstevel@tonic-gate
166*0Sstevel@tonic-gate /*
167*0Sstevel@tonic-gate * hotspare pool error
168*0Sstevel@tonic-gate */
169*0Sstevel@tonic-gate int
mdhsperror(md_error_t * ep,md_hsp_errno_t errnum,hsp_t hsp)170*0Sstevel@tonic-gate mdhsperror(
171*0Sstevel@tonic-gate md_error_t *ep,
172*0Sstevel@tonic-gate md_hsp_errno_t errnum,
173*0Sstevel@tonic-gate hsp_t hsp
174*0Sstevel@tonic-gate )
175*0Sstevel@tonic-gate {
176*0Sstevel@tonic-gate md_hsp_error_t *ip = &ep->info.md_error_info_t_u.hsp_error;
177*0Sstevel@tonic-gate
178*0Sstevel@tonic-gate mdclrerror(ep);
179*0Sstevel@tonic-gate ep->info.errclass = MDEC_HSP;
180*0Sstevel@tonic-gate ip->errnum = errnum;
181*0Sstevel@tonic-gate ip->hsp = hsp;
182*0Sstevel@tonic-gate
183*0Sstevel@tonic-gate return (0);
184*0Sstevel@tonic-gate }
185*0Sstevel@tonic-gate
186*0Sstevel@tonic-gate /*
187*0Sstevel@tonic-gate * hotspare error
188*0Sstevel@tonic-gate */
189*0Sstevel@tonic-gate int
mdhserror(md_error_t * ep,md_hs_errno_t errnum,hsp_t hsp,md_dev64_t dev)190*0Sstevel@tonic-gate mdhserror(
191*0Sstevel@tonic-gate md_error_t *ep,
192*0Sstevel@tonic-gate md_hs_errno_t errnum,
193*0Sstevel@tonic-gate hsp_t hsp,
194*0Sstevel@tonic-gate md_dev64_t dev
195*0Sstevel@tonic-gate )
196*0Sstevel@tonic-gate {
197*0Sstevel@tonic-gate md_hs_error_t *ip = &ep->info.md_error_info_t_u.hs_error;
198*0Sstevel@tonic-gate
199*0Sstevel@tonic-gate mdclrerror(ep);
200*0Sstevel@tonic-gate ep->info.errclass = MDEC_HS;
201*0Sstevel@tonic-gate ip->errnum = errnum;
202*0Sstevel@tonic-gate ip->hs.hsp = hsp;
203*0Sstevel@tonic-gate ip->hs.dev = dev;
204*0Sstevel@tonic-gate
205*0Sstevel@tonic-gate return (0);
206*0Sstevel@tonic-gate }
207*0Sstevel@tonic-gate
208*0Sstevel@tonic-gate /*
209*0Sstevel@tonic-gate * MDDB error
210*0Sstevel@tonic-gate */
211*0Sstevel@tonic-gate int
mdmddberror(md_error_t * ep,md_mddb_errno_t errnum,minor_t mnum,set_t setno)212*0Sstevel@tonic-gate mdmddberror(
213*0Sstevel@tonic-gate md_error_t *ep,
214*0Sstevel@tonic-gate md_mddb_errno_t errnum,
215*0Sstevel@tonic-gate minor_t mnum,
216*0Sstevel@tonic-gate set_t setno
217*0Sstevel@tonic-gate )
218*0Sstevel@tonic-gate {
219*0Sstevel@tonic-gate md_mddb_error_t *ip = &ep->info.md_error_info_t_u.mddb_error;
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gate mdclrerror(ep);
222*0Sstevel@tonic-gate ep->info.errclass = MDEC_MDDB;
223*0Sstevel@tonic-gate ip->errnum = errnum;
224*0Sstevel@tonic-gate ip->mnum = mnum;
225*0Sstevel@tonic-gate ip->setno = setno;
226*0Sstevel@tonic-gate
227*0Sstevel@tonic-gate return (0);
228*0Sstevel@tonic-gate }
229*0Sstevel@tonic-gate
230*0Sstevel@tonic-gate int
mddbstatus2error(md_error_t * ep,int status,minor_t mnum,set_t setno)231*0Sstevel@tonic-gate mddbstatus2error(
232*0Sstevel@tonic-gate md_error_t *ep,
233*0Sstevel@tonic-gate int status,
234*0Sstevel@tonic-gate minor_t mnum,
235*0Sstevel@tonic-gate set_t setno
236*0Sstevel@tonic-gate )
237*0Sstevel@tonic-gate {
238*0Sstevel@tonic-gate md_mddb_errno_t errnum;
239*0Sstevel@tonic-gate
240*0Sstevel@tonic-gate switch (status) {
241*0Sstevel@tonic-gate case MDDB_E_INVALID:
242*0Sstevel@tonic-gate errnum = MDE_DB_INVALID;
243*0Sstevel@tonic-gate break;
244*0Sstevel@tonic-gate case MDDB_E_EXISTS:
245*0Sstevel@tonic-gate errnum = MDE_DB_EXISTS;
246*0Sstevel@tonic-gate break;
247*0Sstevel@tonic-gate case MDDB_E_MASTER:
248*0Sstevel@tonic-gate errnum = MDE_DB_MASTER;
249*0Sstevel@tonic-gate break;
250*0Sstevel@tonic-gate case MDDB_E_TOOSMALL:
251*0Sstevel@tonic-gate errnum = MDE_DB_TOOSMALL;
252*0Sstevel@tonic-gate break;
253*0Sstevel@tonic-gate case MDDB_E_NORECORD:
254*0Sstevel@tonic-gate errnum = MDE_DB_NORECORD;
255*0Sstevel@tonic-gate break;
256*0Sstevel@tonic-gate case MDDB_E_NOSPACE:
257*0Sstevel@tonic-gate errnum = MDE_DB_NOSPACE;
258*0Sstevel@tonic-gate break;
259*0Sstevel@tonic-gate case MDDB_E_NOTNOW:
260*0Sstevel@tonic-gate errnum = MDE_DB_NOTNOW;
261*0Sstevel@tonic-gate break;
262*0Sstevel@tonic-gate case MDDB_E_NODB:
263*0Sstevel@tonic-gate errnum = MDE_DB_NODB;
264*0Sstevel@tonic-gate break;
265*0Sstevel@tonic-gate case MDDB_E_NOTOWNER:
266*0Sstevel@tonic-gate errnum = MDE_DB_NOTOWNER;
267*0Sstevel@tonic-gate break;
268*0Sstevel@tonic-gate case MDDB_E_STALE:
269*0Sstevel@tonic-gate errnum = MDE_DB_STALE;
270*0Sstevel@tonic-gate break;
271*0Sstevel@tonic-gate case MDDB_E_TOOFEW:
272*0Sstevel@tonic-gate errnum = MDE_DB_TOOFEW;
273*0Sstevel@tonic-gate break;
274*0Sstevel@tonic-gate case MDDB_E_TAGDATA:
275*0Sstevel@tonic-gate errnum = MDE_DB_TAGDATA;
276*0Sstevel@tonic-gate break;
277*0Sstevel@tonic-gate case MDDB_E_ACCOK:
278*0Sstevel@tonic-gate errnum = MDE_DB_ACCOK;
279*0Sstevel@tonic-gate break;
280*0Sstevel@tonic-gate case MDDB_E_NTAGDATA:
281*0Sstevel@tonic-gate errnum = MDE_DB_NTAGDATA;
282*0Sstevel@tonic-gate break;
283*0Sstevel@tonic-gate case MDDB_E_ACCNOTOK:
284*0Sstevel@tonic-gate errnum = MDE_DB_ACCNOTOK;
285*0Sstevel@tonic-gate break;
286*0Sstevel@tonic-gate case MDDB_E_NOLOCBLK:
287*0Sstevel@tonic-gate errnum = MDE_DB_NOLOCBLK;
288*0Sstevel@tonic-gate break;
289*0Sstevel@tonic-gate case MDDB_E_NOLOCNMS:
290*0Sstevel@tonic-gate errnum = MDE_DB_NOLOCNMS;
291*0Sstevel@tonic-gate break;
292*0Sstevel@tonic-gate case MDDB_E_NODIRBLK:
293*0Sstevel@tonic-gate errnum = MDE_DB_NODIRBLK;
294*0Sstevel@tonic-gate break;
295*0Sstevel@tonic-gate case MDDB_E_NOTAGREC:
296*0Sstevel@tonic-gate errnum = MDE_DB_NOTAGREC;
297*0Sstevel@tonic-gate break;
298*0Sstevel@tonic-gate case MDDB_E_NOTAG:
299*0Sstevel@tonic-gate errnum = MDE_DB_NOTAG;
300*0Sstevel@tonic-gate break;
301*0Sstevel@tonic-gate default:
302*0Sstevel@tonic-gate ASSERT(0);
303*0Sstevel@tonic-gate errnum = (md_mddb_errno_t)status;
304*0Sstevel@tonic-gate break;
305*0Sstevel@tonic-gate }
306*0Sstevel@tonic-gate return (mdmddberror(ep, errnum, mnum, setno));
307*0Sstevel@tonic-gate }
308