Home | History | Annotate | Download | only in md
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License, Version 1.0 only
      6  * (the "License").  You may not use this file except in compliance
      7  * with the License.
      8  *
      9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  * or http://www.opensolaris.org/os/licensing.
     11  * See the License for the specific language governing permissions
     12  * and limitations under the License.
     13  *
     14  * When distributing Covered Code, include this CDDL HEADER in each
     15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  * If applicable, add the following below this CDDL HEADER, with the
     17  * fields enclosed by brackets "[]" replaced with your own identifying
     18  * information: Portions Copyright [yyyy] [name of copyright owner]
     19  *
     20  * CDDL HEADER END
     21  */
     22 /*
     23  * Copyright 1994, 1999, 2000-2002 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  */
     26 
     27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
     28 
     29 /*
     30  * error functions
     31  */
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/sysmacros.h>
     35 #include <sys/lvm/mdvar.h>
     36 
     37 /*
     38  * null error constant
     39  */
     40 const md_error_t	mdnullerror = {{MDEC_VOID}, NULL, NULL, NULL};
     41 
     42 /*
     43  * clear error
     44  */
     45 void
     46 mdclrerror(
     47 	md_error_t	*ep
     48 )
     49 {
     50 	bzero((caddr_t)ep, sizeof (*ep));
     51 }
     52 
     53 /*
     54  * steal (copy) an error code safely
     55  */
     56 int
     57 mdstealerror(
     58 	md_error_t	*to,
     59 	md_error_t	*from
     60 )
     61 {
     62 	mdclrerror(to);
     63 	*to = *from;
     64 	(void) bzero((caddr_t)from, sizeof (*from));
     65 	return (0);
     66 }
     67 
     68 /*
     69  * simple error
     70  */
     71 int
     72 mderror(
     73 	md_error_t	*ep,
     74 	md_void_errno_t	errnum
     75 )
     76 {
     77 	md_void_error_t	*ip = &ep->info.md_error_info_t_u.void_error;
     78 
     79 	mdclrerror(ep);
     80 	ep->info.errclass = MDEC_VOID;
     81 	ip->errnum = errnum;
     82 
     83 	return (0);
     84 }
     85 
     86 /*
     87  * system error
     88  */
     89 int
     90 mdsyserror(
     91 	md_error_t	*ep,
     92 	int		errnum
     93 )
     94 {
     95 	md_sys_error_t	*ip = &ep->info.md_error_info_t_u.sys_error;
     96 
     97 	mdclrerror(ep);
     98 	ep->info.errclass = MDEC_SYS;
     99 	ip->errnum = errnum;
    100 
    101 	return (0);
    102 }
    103 
    104 /*
    105  * device error
    106  */
    107 int
    108 mddeverror(
    109 	md_error_t	*ep,
    110 	md_dev_errno_t	errnum,
    111 	md_dev64_t	dev
    112 )
    113 {
    114 	md_dev_error_t	*ip = &ep->info.md_error_info_t_u.dev_error;
    115 
    116 	mdclrerror(ep);
    117 	ep->info.errclass = MDEC_DEV;
    118 	ip->errnum = errnum;
    119 	ip->dev = (md_dev64_t)dev;
    120 
    121 	return (0);
    122 }
    123 
    124 /*
    125  * metadevice error
    126  */
    127 int
    128 mdmderror(
    129 	md_error_t	*ep,
    130 	md_md_errno_t	errnum,
    131 	minor_t		mnum
    132 )
    133 {
    134 	md_md_error_t	*ip = &ep->info.md_error_info_t_u.md_error;
    135 
    136 	mdclrerror(ep);
    137 	ep->info.errclass = MDEC_MD;
    138 	ip->errnum = errnum;
    139 	ip->mnum = mnum;
    140 
    141 	return (0);
    142 }
    143 
    144 /*
    145  * component error
    146  */
    147 int
    148 mdcomperror(
    149 	md_error_t	*ep,
    150 	md_comp_errno_t	errnum,
    151 	minor_t		mnum,
    152 	md_dev64_t	dev
    153 )
    154 {
    155 	md_comp_error_t	*ip = &ep->info.md_error_info_t_u.comp_error;
    156 
    157 	mdclrerror(ep);
    158 	ep->info.errclass = MDEC_COMP;
    159 	ip->errnum = errnum;
    160 	ip->comp.mnum = mnum;
    161 	ip->comp.dev = dev;
    162 
    163 	return (0);
    164 }
    165 
    166 /*
    167  * hotspare pool error
    168  */
    169 int
    170 mdhsperror(
    171 	md_error_t	*ep,
    172 	md_hsp_errno_t	errnum,
    173 	hsp_t		hsp
    174 )
    175 {
    176 	md_hsp_error_t	*ip = &ep->info.md_error_info_t_u.hsp_error;
    177 
    178 	mdclrerror(ep);
    179 	ep->info.errclass = MDEC_HSP;
    180 	ip->errnum = errnum;
    181 	ip->hsp = hsp;
    182 
    183 	return (0);
    184 }
    185 
    186 /*
    187  * hotspare error
    188  */
    189 int
    190 mdhserror(
    191 	md_error_t	*ep,
    192 	md_hs_errno_t	errnum,
    193 	hsp_t		hsp,
    194 	md_dev64_t	dev
    195 )
    196 {
    197 	md_hs_error_t	*ip = &ep->info.md_error_info_t_u.hs_error;
    198 
    199 	mdclrerror(ep);
    200 	ep->info.errclass = MDEC_HS;
    201 	ip->errnum = errnum;
    202 	ip->hs.hsp = hsp;
    203 	ip->hs.dev = dev;
    204 
    205 	return (0);
    206 }
    207 
    208 /*
    209  * MDDB error
    210  */
    211 int
    212 mdmddberror(
    213 	md_error_t	*ep,
    214 	md_mddb_errno_t	errnum,
    215 	minor_t		mnum,
    216 	set_t		setno
    217 )
    218 {
    219 	md_mddb_error_t	*ip = &ep->info.md_error_info_t_u.mddb_error;
    220 
    221 	mdclrerror(ep);
    222 	ep->info.errclass = MDEC_MDDB;
    223 	ip->errnum = errnum;
    224 	ip->mnum = mnum;
    225 	ip->setno = setno;
    226 
    227 	return (0);
    228 }
    229 
    230 int
    231 mddbstatus2error(
    232 	md_error_t	*ep,
    233 	int		status,
    234 	minor_t		mnum,
    235 	set_t		setno
    236 )
    237 {
    238 	md_mddb_errno_t	errnum;
    239 
    240 	switch (status) {
    241 	case MDDB_E_INVALID:
    242 		errnum = MDE_DB_INVALID;
    243 		break;
    244 	case MDDB_E_EXISTS:
    245 		errnum = MDE_DB_EXISTS;
    246 		break;
    247 	case MDDB_E_MASTER:
    248 		errnum = MDE_DB_MASTER;
    249 		break;
    250 	case MDDB_E_TOOSMALL:
    251 		errnum = MDE_DB_TOOSMALL;
    252 		break;
    253 	case MDDB_E_NORECORD:
    254 		errnum = MDE_DB_NORECORD;
    255 		break;
    256 	case MDDB_E_NOSPACE:
    257 		errnum = MDE_DB_NOSPACE;
    258 		break;
    259 	case MDDB_E_NOTNOW:
    260 		errnum = MDE_DB_NOTNOW;
    261 		break;
    262 	case MDDB_E_NODB:
    263 		errnum = MDE_DB_NODB;
    264 		break;
    265 	case MDDB_E_NOTOWNER:
    266 		errnum = MDE_DB_NOTOWNER;
    267 		break;
    268 	case MDDB_E_STALE:
    269 		errnum = MDE_DB_STALE;
    270 		break;
    271 	case MDDB_E_TOOFEW:
    272 		errnum = MDE_DB_TOOFEW;
    273 		break;
    274 	case MDDB_E_TAGDATA:
    275 		errnum = MDE_DB_TAGDATA;
    276 		break;
    277 	case MDDB_E_ACCOK:
    278 		errnum = MDE_DB_ACCOK;
    279 		break;
    280 	case MDDB_E_NTAGDATA:
    281 		errnum = MDE_DB_NTAGDATA;
    282 		break;
    283 	case MDDB_E_ACCNOTOK:
    284 		errnum = MDE_DB_ACCNOTOK;
    285 		break;
    286 	case MDDB_E_NOLOCBLK:
    287 		errnum = MDE_DB_NOLOCBLK;
    288 		break;
    289 	case MDDB_E_NOLOCNMS:
    290 		errnum = MDE_DB_NOLOCNMS;
    291 		break;
    292 	case MDDB_E_NODIRBLK:
    293 		errnum = MDE_DB_NODIRBLK;
    294 		break;
    295 	case MDDB_E_NOTAGREC:
    296 		errnum = MDE_DB_NOTAGREC;
    297 		break;
    298 	case MDDB_E_NOTAG:
    299 		errnum = MDE_DB_NOTAG;
    300 		break;
    301 	default:
    302 		ASSERT(0);
    303 		errnum = (md_mddb_errno_t)status;
    304 		break;
    305 	}
    306 	return (mdmddberror(ep, errnum, mnum, setno));
    307 }
    308