xref: /onnv-gate/usr/src/lib/lvm/libmeta/common/meta_error.c (revision 5109:0876b6c2ea48)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51623Stw21770  * Common Development and Distribution License (the "License").
61623Stw21770  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*5109Spetede  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * Just in case we're not in a build environment, make sure that
300Sstevel@tonic-gate  * TEXT_DOMAIN gets set to something.
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
330Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate 
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate  * print metedevice errors
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #include <meta.h>
410Sstevel@tonic-gate #include <sys/lvm/md_mddb.h>
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #include <syslog.h>
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate  * clear error
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate void
mdclrerror(md_error_t * ep)490Sstevel@tonic-gate mdclrerror(
500Sstevel@tonic-gate 	md_error_t	*ep
510Sstevel@tonic-gate )
520Sstevel@tonic-gate {
530Sstevel@tonic-gate 	if (ep->name != NULL)
540Sstevel@tonic-gate 		Free(ep->name);
550Sstevel@tonic-gate 	if (ep->host != NULL)
560Sstevel@tonic-gate 		Free(ep->host);
570Sstevel@tonic-gate 	if (ep->extra != NULL)
580Sstevel@tonic-gate 		Free(ep->extra);
590Sstevel@tonic-gate 	(void) memset(ep, '\0', sizeof (*ep));
600Sstevel@tonic-gate }
610Sstevel@tonic-gate 
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate  * cook names
640Sstevel@tonic-gate  */
650Sstevel@tonic-gate static char *
md_name(minor_t mnum)660Sstevel@tonic-gate md_name(
670Sstevel@tonic-gate 	minor_t	mnum
680Sstevel@tonic-gate )
690Sstevel@tonic-gate {
700Sstevel@tonic-gate 	char	*name;
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	/* get name, or fake it */
731623Stw21770 	if ((name = get_mdname(NULL, mnum)) == NULL) {
740Sstevel@tonic-gate 		char	buf[40];
750Sstevel@tonic-gate 
761623Stw21770 		(void) sprintf(buf, "%lu/%lu", MD_MIN2SET(mnum),
770Sstevel@tonic-gate 		    MD_MIN2UNIT(mnum));
780Sstevel@tonic-gate 		return (Strdup(buf));
790Sstevel@tonic-gate 	}
800Sstevel@tonic-gate 	return (Strdup(name));
810Sstevel@tonic-gate }
820Sstevel@tonic-gate 
830Sstevel@tonic-gate static char *
dev_name(set_t setno,md_dev64_t dev)840Sstevel@tonic-gate dev_name(
850Sstevel@tonic-gate 	set_t	setno,
860Sstevel@tonic-gate 	md_dev64_t dev
870Sstevel@tonic-gate )
880Sstevel@tonic-gate {
890Sstevel@tonic-gate 	char	*name;
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 	/* get name or fake it */
920Sstevel@tonic-gate 	if (dev == NODEV64)
930Sstevel@tonic-gate 		return (Strdup(dgettext(TEXT_DOMAIN, "unknown device")));
940Sstevel@tonic-gate 	if ((name = get_devname(setno, dev)) == NULL) {
950Sstevel@tonic-gate 		char	buf[40];
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 		(void) sprintf(buf, "%lu.%lu", meta_getmajor(dev),
980Sstevel@tonic-gate 		    meta_getminor(dev));
990Sstevel@tonic-gate 		return (Strdup(buf));
1000Sstevel@tonic-gate 	}
1010Sstevel@tonic-gate 	return (Strdup(name));
1020Sstevel@tonic-gate }
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate static char *
hsp_name(hsp_t hsp)1050Sstevel@tonic-gate hsp_name(
1060Sstevel@tonic-gate 	hsp_t	hsp
1070Sstevel@tonic-gate )
1080Sstevel@tonic-gate {
1090Sstevel@tonic-gate 	char	*name;
1100Sstevel@tonic-gate 
1111623Stw21770 	if ((name = get_hspname(NULL, hsp)) == NULL) {
1120Sstevel@tonic-gate 		char	buf[40];
1130Sstevel@tonic-gate 
1141623Stw21770 		(void) sprintf(buf, "%u/%u", HSP_SET(hsp), HSP_ID(hsp));
1150Sstevel@tonic-gate 		return (Strdup(buf));
1160Sstevel@tonic-gate 	}
1170Sstevel@tonic-gate 	return (Strdup(name));
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate static char *
set_name(set_t setno)1210Sstevel@tonic-gate set_name(
1220Sstevel@tonic-gate 	set_t		setno
1230Sstevel@tonic-gate )
1240Sstevel@tonic-gate {
1250Sstevel@tonic-gate 	mdsetname_t	*sp;
1260Sstevel@tonic-gate 	md_error_t	xep = mdnullerror;
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	if (setno == MD_SET_BAD)
1290Sstevel@tonic-gate 		return (NULL);
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 	if ((sp = metasetnosetname(setno, &xep)) == NULL) {
1320Sstevel@tonic-gate 		char	buf[40];
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 		mdclrerror(&xep);
1350Sstevel@tonic-gate 		(void) sprintf(buf, "setno %u", setno);
1360Sstevel@tonic-gate 		return (Strdup(buf));
1370Sstevel@tonic-gate 	}
1380Sstevel@tonic-gate 	return (Strdup(sp->setname));
1390Sstevel@tonic-gate }
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate /*
1420Sstevel@tonic-gate  * fill in all the appropriate md_error_t fields
1430Sstevel@tonic-gate  */
1440Sstevel@tonic-gate static void
metacookerror(md_error_t * ep,char * name)1450Sstevel@tonic-gate metacookerror(
1460Sstevel@tonic-gate 	md_error_t	*ep,		/* generic error */
1470Sstevel@tonic-gate 	char		*name		/* optional name or host */
1480Sstevel@tonic-gate )
1490Sstevel@tonic-gate {
1500Sstevel@tonic-gate 	/* get host name */
1510Sstevel@tonic-gate 	if (ep->host != NULL) {
1520Sstevel@tonic-gate 		Free(ep->host);
1530Sstevel@tonic-gate 		ep->host = NULL;
1540Sstevel@tonic-gate 	}
1550Sstevel@tonic-gate 	if ((ep->info.errclass == MDEC_RPC) &&
1560Sstevel@tonic-gate 	    (name != NULL) && (*name != '\0')) {
1570Sstevel@tonic-gate 		ep->host = Strdup(name);
1580Sstevel@tonic-gate 		name = NULL;
1590Sstevel@tonic-gate 	} else
1600Sstevel@tonic-gate 		ep->host = Strdup(mynode());
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 	/* get appropriate name */
1630Sstevel@tonic-gate 	if (ep->name != NULL) {
1640Sstevel@tonic-gate 		Free(ep->name);
1650Sstevel@tonic-gate 		ep->name = NULL;
1660Sstevel@tonic-gate 	}
1670Sstevel@tonic-gate 	if ((name != NULL) && (*name != '\0')) {
1680Sstevel@tonic-gate 		ep->name = Strdup(name);
1690Sstevel@tonic-gate 	} else {
1700Sstevel@tonic-gate 		switch (ep->info.errclass) {
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 		/* can't do anything about these */
1730Sstevel@tonic-gate 		case MDEC_VOID:
1740Sstevel@tonic-gate 		case MDEC_SYS:
1750Sstevel@tonic-gate 		case MDEC_RPC:
1760Sstevel@tonic-gate 		default:
1770Sstevel@tonic-gate 			break;
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate 		/* device name */
1800Sstevel@tonic-gate 		case MDEC_DEV:
1810Sstevel@tonic-gate 		{
1820Sstevel@tonic-gate 			md_dev_error_t	*ip =
183*5109Spetede 			    &ep->info.md_error_info_t_u.dev_error;
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 			ep->name = dev_name(MD_SET_BAD, ip->dev);
1860Sstevel@tonic-gate 			break;
1870Sstevel@tonic-gate 		}
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate 		/* device name */
1900Sstevel@tonic-gate 		case MDEC_USE:
1910Sstevel@tonic-gate 		{
1920Sstevel@tonic-gate 			md_use_error_t	*ip =
193*5109Spetede 			    &ep->info.md_error_info_t_u.use_error;
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate 			ep->name = dev_name(MD_SET_BAD, ip->dev);
1960Sstevel@tonic-gate 			if (ip->where == NULL) {
1970Sstevel@tonic-gate 				ip->where = Strdup(dgettext(TEXT_DOMAIN,
1980Sstevel@tonic-gate 				    "unknown"));
1990Sstevel@tonic-gate 			}
2000Sstevel@tonic-gate 			break;
2010Sstevel@tonic-gate 		}
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 		/* metadevice name */
2040Sstevel@tonic-gate 		case MDEC_MD:
2050Sstevel@tonic-gate 		{
2060Sstevel@tonic-gate 			md_md_error_t	*ip =
207*5109Spetede 			    &ep->info.md_error_info_t_u.md_error;
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate 			ep->name = md_name(ip->mnum);
2100Sstevel@tonic-gate 			break;
2110Sstevel@tonic-gate 		}
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 		/* component name */
2140Sstevel@tonic-gate 		case MDEC_COMP:
2150Sstevel@tonic-gate 		{
2160Sstevel@tonic-gate 			md_comp_error_t	*ip =
217*5109Spetede 			    &ep->info.md_error_info_t_u.comp_error;
2180Sstevel@tonic-gate 			char		*mdname, *devname;
2190Sstevel@tonic-gate 			size_t 		len;
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate 			mdname = md_name(ip->comp.mnum);
2220Sstevel@tonic-gate 			devname = dev_name(MD_MIN2SET(ip->comp.mnum),
2230Sstevel@tonic-gate 			    ip->comp.dev);
2240Sstevel@tonic-gate 			len = strlen(mdname) + strlen(": ")
2250Sstevel@tonic-gate 			    + strlen(devname) + 1;
2260Sstevel@tonic-gate 			ep->name = Malloc(len);
2270Sstevel@tonic-gate 			(void) snprintf(ep->name, len, "%s: %s",
2280Sstevel@tonic-gate 			    mdname, devname);
2290Sstevel@tonic-gate 			Free(mdname);
2300Sstevel@tonic-gate 			Free(devname);
2310Sstevel@tonic-gate 			break;
2320Sstevel@tonic-gate 		}
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate 		/* hotspare pool name */
2350Sstevel@tonic-gate 		case MDEC_HSP:
2360Sstevel@tonic-gate 		{
2370Sstevel@tonic-gate 			md_hsp_error_t	*ip =
238*5109Spetede 			    &ep->info.md_error_info_t_u.hsp_error;
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 			ep->name = hsp_name(ip->hsp);
2410Sstevel@tonic-gate 			break;
2420Sstevel@tonic-gate 		}
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 		/* hotspare name */
2450Sstevel@tonic-gate 		case MDEC_HS:
2460Sstevel@tonic-gate 		{
2470Sstevel@tonic-gate 			md_hs_error_t	*ip =
248*5109Spetede 			    &ep->info.md_error_info_t_u.hs_error;
2490Sstevel@tonic-gate 			char		*hspname, *devname;
2500Sstevel@tonic-gate 			size_t 		len;
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate 			hspname = hsp_name(ip->hs.hsp);
2530Sstevel@tonic-gate 			devname = dev_name(HSP_SET(ip->hs.hsp), ip->hs.dev);
2540Sstevel@tonic-gate 			len = strlen(hspname) + strlen(": ")
2550Sstevel@tonic-gate 			    + strlen(devname) + 1;
2560Sstevel@tonic-gate 			ep->name = Malloc(len);
2570Sstevel@tonic-gate 			(void) snprintf(ep->name, len, "%s: %s",
2580Sstevel@tonic-gate 			    hspname, devname);
2590Sstevel@tonic-gate 			Free(hspname);
2600Sstevel@tonic-gate 			Free(devname);
2610Sstevel@tonic-gate 			break;
2620Sstevel@tonic-gate 		}
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate 		/* mddb name */
2650Sstevel@tonic-gate 		case MDEC_MDDB:
2660Sstevel@tonic-gate 		{
2670Sstevel@tonic-gate 			md_mddb_error_t	*ip =
268*5109Spetede 			    &ep->info.md_error_info_t_u.mddb_error;
2690Sstevel@tonic-gate 			if (ip->mnum != NODEV32)
2700Sstevel@tonic-gate 				ep->name = md_name(ip->mnum);
2710Sstevel@tonic-gate 			ep->name = set_name(ip->setno);
2720Sstevel@tonic-gate 			break;
2730Sstevel@tonic-gate 		}
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate 		/* set name */
2760Sstevel@tonic-gate 		case MDEC_DS:
2770Sstevel@tonic-gate 		{
2780Sstevel@tonic-gate 			md_ds_error_t	*ip =
2790Sstevel@tonic-gate 			    &ep->info.md_error_info_t_u.ds_error;
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate 			ep->name = set_name(ip->setno);
2820Sstevel@tonic-gate 			break;
2830Sstevel@tonic-gate 		}
2840Sstevel@tonic-gate 		}
2850Sstevel@tonic-gate 	}
2860Sstevel@tonic-gate }
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate /*
2890Sstevel@tonic-gate  * simple error
2900Sstevel@tonic-gate  */
2910Sstevel@tonic-gate int
mderror(md_error_t * ep,md_void_errno_t errnum,char * name)2920Sstevel@tonic-gate mderror(
2930Sstevel@tonic-gate 	md_error_t	*ep,
2940Sstevel@tonic-gate 	md_void_errno_t	errnum,
2950Sstevel@tonic-gate 	char		*name
2960Sstevel@tonic-gate )
2970Sstevel@tonic-gate {
2980Sstevel@tonic-gate 	md_void_error_t	*ip = &ep->info.md_error_info_t_u.void_error;
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate 	mdclrerror(ep);
3010Sstevel@tonic-gate 	ep->info.errclass = MDEC_VOID;
3020Sstevel@tonic-gate 	ip->errnum = errnum;
3030Sstevel@tonic-gate 
3040Sstevel@tonic-gate 	metacookerror(ep, name);
3050Sstevel@tonic-gate 	return (-1);
3060Sstevel@tonic-gate }
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate /*
3090Sstevel@tonic-gate  * system error
3100Sstevel@tonic-gate  */
3110Sstevel@tonic-gate int
mdsyserror(md_error_t * ep,int errnum,char * name)3120Sstevel@tonic-gate mdsyserror(
3130Sstevel@tonic-gate 	md_error_t	*ep,
3140Sstevel@tonic-gate 	int		errnum,
3150Sstevel@tonic-gate 	char		*name
3160Sstevel@tonic-gate )
3170Sstevel@tonic-gate {
3180Sstevel@tonic-gate 	md_sys_error_t	*ip = &ep->info.md_error_info_t_u.sys_error;
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate 	mdclrerror(ep);
3210Sstevel@tonic-gate 	if (errnum != 0) {
3220Sstevel@tonic-gate 		ep->info.errclass = MDEC_SYS;
3230Sstevel@tonic-gate 		ip->errnum = errnum;
3240Sstevel@tonic-gate 	}
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate 	metacookerror(ep, name);
3270Sstevel@tonic-gate 	return (-1);
3280Sstevel@tonic-gate }
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate /*
3310Sstevel@tonic-gate  * RPC error
3320Sstevel@tonic-gate  */
3330Sstevel@tonic-gate int
mdrpcerror(md_error_t * ep,CLIENT * clntp,char * host,char * extra)3340Sstevel@tonic-gate mdrpcerror(
3350Sstevel@tonic-gate 	md_error_t	*ep,
3360Sstevel@tonic-gate 	CLIENT		*clntp,
3370Sstevel@tonic-gate 	char		*host,
3380Sstevel@tonic-gate 	char		*extra
3390Sstevel@tonic-gate )
3400Sstevel@tonic-gate {
3410Sstevel@tonic-gate 	md_rpc_error_t	*ip = &ep->info.md_error_info_t_u.rpc_error;
3420Sstevel@tonic-gate 	struct rpc_err	rpcerr;
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate 	mdclrerror(ep);
3450Sstevel@tonic-gate 	clnt_geterr(clntp, &rpcerr);
3460Sstevel@tonic-gate 	ep->info.errclass = MDEC_RPC;
3470Sstevel@tonic-gate 	ip->errnum = rpcerr.re_status;
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate 	metacookerror(ep, host);
3500Sstevel@tonic-gate 	mderrorextra(ep, extra);
3510Sstevel@tonic-gate 	return (-1);
3520Sstevel@tonic-gate }
3530Sstevel@tonic-gate 
3540Sstevel@tonic-gate /*
3550Sstevel@tonic-gate  * RPC create error
3560Sstevel@tonic-gate  */
3570Sstevel@tonic-gate int
mdrpccreateerror(md_error_t * ep,char * host,char * extra)3580Sstevel@tonic-gate mdrpccreateerror(
3590Sstevel@tonic-gate 	md_error_t	*ep,
3600Sstevel@tonic-gate 	char		*host,
3610Sstevel@tonic-gate 	char		*extra
3620Sstevel@tonic-gate )
3630Sstevel@tonic-gate {
3640Sstevel@tonic-gate 	md_rpc_error_t	*ip = &ep->info.md_error_info_t_u.rpc_error;
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate 	mdclrerror(ep);
3670Sstevel@tonic-gate 	ep->info.errclass = MDEC_RPC;
3680Sstevel@tonic-gate 	ip->errnum = rpc_createerr.cf_stat;
3690Sstevel@tonic-gate 
3700Sstevel@tonic-gate 	metacookerror(ep, host);
3710Sstevel@tonic-gate 	mderrorextra(ep, extra);
3720Sstevel@tonic-gate 	return (-1);
3730Sstevel@tonic-gate }
3740Sstevel@tonic-gate 
3750Sstevel@tonic-gate /*
3760Sstevel@tonic-gate  * device error
3770Sstevel@tonic-gate  */
3780Sstevel@tonic-gate int
mddeverror(md_error_t * ep,md_dev_errno_t errnum,md_dev64_t dev,char * name)3790Sstevel@tonic-gate mddeverror(
3800Sstevel@tonic-gate 	md_error_t	*ep,
3810Sstevel@tonic-gate 	md_dev_errno_t	errnum,
3820Sstevel@tonic-gate 	md_dev64_t	dev,
3830Sstevel@tonic-gate 	char		*name
3840Sstevel@tonic-gate )
3850Sstevel@tonic-gate {
3860Sstevel@tonic-gate 	md_dev_error_t	*ip = &ep->info.md_error_info_t_u.dev_error;
3870Sstevel@tonic-gate 
3880Sstevel@tonic-gate 	mdclrerror(ep);
3890Sstevel@tonic-gate 	ep->info.errclass = MDEC_DEV;
3900Sstevel@tonic-gate 	ip->errnum = errnum;
3910Sstevel@tonic-gate 	ip->dev = dev;
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate 	metacookerror(ep, name);
3940Sstevel@tonic-gate 	return (-1);
3950Sstevel@tonic-gate }
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate /*
3980Sstevel@tonic-gate  * use error
3990Sstevel@tonic-gate  */
4000Sstevel@tonic-gate int
mduseerror(md_error_t * ep,md_use_errno_t errnum,md_dev64_t dev,char * where,char * name)4010Sstevel@tonic-gate mduseerror(
4020Sstevel@tonic-gate 	md_error_t	*ep,
4030Sstevel@tonic-gate 	md_use_errno_t	errnum,
4040Sstevel@tonic-gate 	md_dev64_t	dev,
4050Sstevel@tonic-gate 	char		*where,
4060Sstevel@tonic-gate 	char		*name
4070Sstevel@tonic-gate )
4080Sstevel@tonic-gate {
4090Sstevel@tonic-gate 	md_use_error_t	*ip = &ep->info.md_error_info_t_u.use_error;
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate 	assert(where != NULL);
4120Sstevel@tonic-gate 	mdclrerror(ep);
4130Sstevel@tonic-gate 	ep->info.errclass = MDEC_USE;
4140Sstevel@tonic-gate 	ip->errnum = errnum;
4150Sstevel@tonic-gate 	ip->dev = dev;
4160Sstevel@tonic-gate 	ip->where = Strdup(where);
4170Sstevel@tonic-gate 
4180Sstevel@tonic-gate 	metacookerror(ep, name);
4190Sstevel@tonic-gate 	return (-1);
4200Sstevel@tonic-gate }
4210Sstevel@tonic-gate 
4220Sstevel@tonic-gate /*
4230Sstevel@tonic-gate  * overlap error
4240Sstevel@tonic-gate  */
4250Sstevel@tonic-gate int
mdoverlaperror(md_error_t * ep,md_overlap_errno_t errnum,char * name,char * where,char * overlap)4260Sstevel@tonic-gate mdoverlaperror(
4270Sstevel@tonic-gate 	md_error_t		*ep,
4280Sstevel@tonic-gate 	md_overlap_errno_t	errnum,
4290Sstevel@tonic-gate 	char			*name,
4300Sstevel@tonic-gate 	char			*where,
4310Sstevel@tonic-gate 	char			*overlap
4320Sstevel@tonic-gate )
4330Sstevel@tonic-gate {
4340Sstevel@tonic-gate 	md_overlap_error_t *ip =
435*5109Spetede 	    &ep->info.md_error_info_t_u.overlap_error;
4360Sstevel@tonic-gate 
4370Sstevel@tonic-gate 	assert(overlap != NULL);
4380Sstevel@tonic-gate 	mdclrerror(ep);
4390Sstevel@tonic-gate 	ep->info.errclass = MDEC_OVERLAP;
4400Sstevel@tonic-gate 	ip->errnum = errnum;
4410Sstevel@tonic-gate 	ip->overlap = Strdup(overlap);
4420Sstevel@tonic-gate 	ip->where = NULL;
4430Sstevel@tonic-gate 	if (where != NULL)
444*5109Spetede 		ip->where = Strdup(where);
4450Sstevel@tonic-gate 
4460Sstevel@tonic-gate 	metacookerror(ep, name);
4470Sstevel@tonic-gate 	return (-1);
4480Sstevel@tonic-gate }
4490Sstevel@tonic-gate 
4500Sstevel@tonic-gate /*
4510Sstevel@tonic-gate  * metadevice error
4520Sstevel@tonic-gate  */
4530Sstevel@tonic-gate int
mdmderror(md_error_t * ep,md_md_errno_t errnum,minor_t mnum,char * name)4540Sstevel@tonic-gate mdmderror(
4550Sstevel@tonic-gate 	md_error_t	*ep,
4560Sstevel@tonic-gate 	md_md_errno_t	errnum,
4570Sstevel@tonic-gate 	minor_t		mnum,
4580Sstevel@tonic-gate 	char		*name
4590Sstevel@tonic-gate )
4600Sstevel@tonic-gate {
4610Sstevel@tonic-gate 	md_md_error_t	*ip = &ep->info.md_error_info_t_u.md_error;
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate 	mdclrerror(ep);
4640Sstevel@tonic-gate 	ep->info.errclass = MDEC_MD;
4650Sstevel@tonic-gate 	ip->errnum = errnum;
4660Sstevel@tonic-gate 	ip->mnum = mnum;
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 	metacookerror(ep, name);
4690Sstevel@tonic-gate 	return (-1);
4700Sstevel@tonic-gate }
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate /*
4730Sstevel@tonic-gate  * component error
4740Sstevel@tonic-gate  */
4750Sstevel@tonic-gate int
mdcomperror(md_error_t * ep,md_comp_errno_t errnum,minor_t mnum,md_dev64_t dev,char * name)4760Sstevel@tonic-gate mdcomperror(
4770Sstevel@tonic-gate 	md_error_t	*ep,
4780Sstevel@tonic-gate 	md_comp_errno_t	errnum,
4790Sstevel@tonic-gate 	minor_t		mnum,
4800Sstevel@tonic-gate 	md_dev64_t	dev,
4810Sstevel@tonic-gate 	char		*name
4820Sstevel@tonic-gate )
4830Sstevel@tonic-gate {
4840Sstevel@tonic-gate 	md_comp_error_t	*ip = &ep->info.md_error_info_t_u.comp_error;
4850Sstevel@tonic-gate 
4860Sstevel@tonic-gate 	mdclrerror(ep);
4870Sstevel@tonic-gate 	ep->info.errclass = MDEC_COMP;
4880Sstevel@tonic-gate 	ip->errnum = errnum;
4890Sstevel@tonic-gate 	ip->comp.mnum = mnum;
4900Sstevel@tonic-gate 	ip->comp.dev = dev;
4910Sstevel@tonic-gate 
4920Sstevel@tonic-gate 	metacookerror(ep, name);
4930Sstevel@tonic-gate 	return (-1);
4940Sstevel@tonic-gate }
4950Sstevel@tonic-gate 
4960Sstevel@tonic-gate /*
4970Sstevel@tonic-gate  * hotspare pool error
4980Sstevel@tonic-gate  */
4990Sstevel@tonic-gate int
mdhsperror(md_error_t * ep,md_hsp_errno_t errnum,hsp_t hsp,char * name)5000Sstevel@tonic-gate mdhsperror(
5010Sstevel@tonic-gate 	md_error_t	*ep,
5020Sstevel@tonic-gate 	md_hsp_errno_t	errnum,
5030Sstevel@tonic-gate 	hsp_t		hsp,
5040Sstevel@tonic-gate 	char		*name
5050Sstevel@tonic-gate )
5060Sstevel@tonic-gate {
5070Sstevel@tonic-gate 	md_hsp_error_t	*ip = &ep->info.md_error_info_t_u.hsp_error;
5080Sstevel@tonic-gate 
5090Sstevel@tonic-gate 	mdclrerror(ep);
5100Sstevel@tonic-gate 	ep->info.errclass = MDEC_HSP;
5110Sstevel@tonic-gate 	ip->errnum = errnum;
5120Sstevel@tonic-gate 	ip->hsp = hsp;
5130Sstevel@tonic-gate 
5140Sstevel@tonic-gate 	metacookerror(ep, name);
5150Sstevel@tonic-gate 	return (-1);
5160Sstevel@tonic-gate }
5170Sstevel@tonic-gate 
5180Sstevel@tonic-gate /*
5190Sstevel@tonic-gate  * hotspare error
5200Sstevel@tonic-gate  */
5210Sstevel@tonic-gate int
mdhserror(md_error_t * ep,md_hs_errno_t errnum,hsp_t hsp,md_dev64_t dev,char * name)5220Sstevel@tonic-gate mdhserror(
5230Sstevel@tonic-gate 	md_error_t	*ep,
5240Sstevel@tonic-gate 	md_hs_errno_t	errnum,
5250Sstevel@tonic-gate 	hsp_t		hsp,
5260Sstevel@tonic-gate 	md_dev64_t	dev,
5270Sstevel@tonic-gate 	char		*name
5280Sstevel@tonic-gate )
5290Sstevel@tonic-gate {
5300Sstevel@tonic-gate 	md_hs_error_t	*ip = &ep->info.md_error_info_t_u.hs_error;
5310Sstevel@tonic-gate 
5320Sstevel@tonic-gate 	mdclrerror(ep);
5330Sstevel@tonic-gate 	ep->info.errclass = MDEC_HS;
5340Sstevel@tonic-gate 	ip->errnum = errnum;
5350Sstevel@tonic-gate 	ip->hs.hsp = hsp;
5360Sstevel@tonic-gate 	ip->hs.dev = dev;
5370Sstevel@tonic-gate 
5380Sstevel@tonic-gate 	metacookerror(ep, name);
5390Sstevel@tonic-gate 	return (-1);
5400Sstevel@tonic-gate }
5410Sstevel@tonic-gate 
5420Sstevel@tonic-gate /*
5430Sstevel@tonic-gate  * MDDB error
5440Sstevel@tonic-gate  */
5450Sstevel@tonic-gate int
mdmddberror(md_error_t * ep,md_mddb_errno_t errnum,minor_t mnum,set_t setno,size_t size,char * name)5460Sstevel@tonic-gate mdmddberror(
5470Sstevel@tonic-gate 	md_error_t	*ep,
5480Sstevel@tonic-gate 	md_mddb_errno_t	errnum,
5490Sstevel@tonic-gate 	minor_t		mnum,
5500Sstevel@tonic-gate 	set_t		setno,
5510Sstevel@tonic-gate 	size_t		size,
5520Sstevel@tonic-gate 	char		*name
5530Sstevel@tonic-gate )
5540Sstevel@tonic-gate {
5550Sstevel@tonic-gate 	md_mddb_error_t	*ip = &ep->info.md_error_info_t_u.mddb_error;
5560Sstevel@tonic-gate 
5570Sstevel@tonic-gate 	mdclrerror(ep);
5580Sstevel@tonic-gate 	ep->info.errclass = MDEC_MDDB;
5590Sstevel@tonic-gate 	ip->errnum = errnum;
5600Sstevel@tonic-gate 	ip->mnum = mnum;
5610Sstevel@tonic-gate 	ip->setno = setno;
5620Sstevel@tonic-gate 	ip->size = size;
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate 	metacookerror(ep, name);
5650Sstevel@tonic-gate 	return (-1);
5660Sstevel@tonic-gate }
5670Sstevel@tonic-gate 
5680Sstevel@tonic-gate /*
5690Sstevel@tonic-gate  * metadevice diskset (ds) error
5700Sstevel@tonic-gate  */
5710Sstevel@tonic-gate int
mddserror(md_error_t * ep,md_ds_errno_t errnum,set_t setno,char * node,char * drive,char * name)5720Sstevel@tonic-gate mddserror(
5730Sstevel@tonic-gate 	md_error_t	*ep,
5740Sstevel@tonic-gate 	md_ds_errno_t	errnum,
5750Sstevel@tonic-gate 	set_t		setno,
5760Sstevel@tonic-gate 	char		*node,
5770Sstevel@tonic-gate 	char		*drive,
5780Sstevel@tonic-gate 	char		*name
5790Sstevel@tonic-gate )
5800Sstevel@tonic-gate {
5810Sstevel@tonic-gate 	md_ds_error_t	*ip = &ep->info.md_error_info_t_u.ds_error;
5820Sstevel@tonic-gate 
5830Sstevel@tonic-gate 	mdclrerror(ep);
5840Sstevel@tonic-gate 	ep->info.errclass = MDEC_DS;
5850Sstevel@tonic-gate 	ip->errnum = errnum;
5860Sstevel@tonic-gate 	ip->setno = setno;
5870Sstevel@tonic-gate 	ip->node = ((node != NULL) ? Strdup(node) : NULL);
5880Sstevel@tonic-gate 	ip->drive = ((drive != NULL) ? Strdup(drive) : NULL);
5890Sstevel@tonic-gate 
5900Sstevel@tonic-gate 	metacookerror(ep, name);
5910Sstevel@tonic-gate 	return (-1);
5920Sstevel@tonic-gate }
5930Sstevel@tonic-gate 
5940Sstevel@tonic-gate /*
5950Sstevel@tonic-gate  * clear/attach extra context information
5960Sstevel@tonic-gate  */
5970Sstevel@tonic-gate void
mderrorextra(md_error_t * ep,char * extra)5980Sstevel@tonic-gate mderrorextra(
5990Sstevel@tonic-gate 	md_error_t	*ep,
6000Sstevel@tonic-gate 	char		*extra
6010Sstevel@tonic-gate )
6020Sstevel@tonic-gate {
6030Sstevel@tonic-gate 	if (ep->extra != NULL)
6040Sstevel@tonic-gate 		Free(ep->extra);
6050Sstevel@tonic-gate 	if (extra != NULL)
6060Sstevel@tonic-gate 		ep->extra = Strdup(extra);
6070Sstevel@tonic-gate 	else
6080Sstevel@tonic-gate 		ep->extra = NULL;
6090Sstevel@tonic-gate }
6100Sstevel@tonic-gate 
6110Sstevel@tonic-gate /*
6120Sstevel@tonic-gate  * steal (copy) an error code safely
6130Sstevel@tonic-gate  */
6140Sstevel@tonic-gate int
mdstealerror(md_error_t * to,md_error_t * from)6150Sstevel@tonic-gate mdstealerror(
6160Sstevel@tonic-gate 	md_error_t	*to,
6170Sstevel@tonic-gate 	md_error_t	*from
6180Sstevel@tonic-gate )
6190Sstevel@tonic-gate {
6200Sstevel@tonic-gate 	mdclrerror(to);
6210Sstevel@tonic-gate 	*to = *from;
6220Sstevel@tonic-gate 	(void) memset(from, '\0', sizeof (*from));
6230Sstevel@tonic-gate 	return (-1);
6240Sstevel@tonic-gate }
6250Sstevel@tonic-gate 
6260Sstevel@tonic-gate /*
6270Sstevel@tonic-gate  * do an ioctl, cook the error, and return status
6280Sstevel@tonic-gate  */
6290Sstevel@tonic-gate int
metaioctl(int cmd,void * data,md_error_t * ep,char * name)6300Sstevel@tonic-gate metaioctl(
6310Sstevel@tonic-gate 	int		cmd,
6320Sstevel@tonic-gate 	void		*data,
6330Sstevel@tonic-gate 	md_error_t	*ep,
6340Sstevel@tonic-gate 	char		*name
6350Sstevel@tonic-gate )
6360Sstevel@tonic-gate {
6370Sstevel@tonic-gate 	int		fd;
6380Sstevel@tonic-gate 
6390Sstevel@tonic-gate 	/* open admin device */
6400Sstevel@tonic-gate 	if ((fd = open_admin(ep)) < 0)
6410Sstevel@tonic-gate 		return (-1);
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate 	/* do ioctl */
6440Sstevel@tonic-gate 	mdclrerror(ep);
6450Sstevel@tonic-gate 	if (ioctl(fd, cmd, data) != 0) {
6460Sstevel@tonic-gate 		return (mdsyserror(ep, errno, name));
6470Sstevel@tonic-gate 	} else if (! mdisok(ep)) {
6480Sstevel@tonic-gate 		metacookerror(ep, name);
6490Sstevel@tonic-gate 		return (-1);
6500Sstevel@tonic-gate 	}
6510Sstevel@tonic-gate 
6520Sstevel@tonic-gate 	/* return success */
6530Sstevel@tonic-gate 	return (0);
6540Sstevel@tonic-gate }
6550Sstevel@tonic-gate 
6560Sstevel@tonic-gate /*
6570Sstevel@tonic-gate  * print void class errors
6580Sstevel@tonic-gate  */
6590Sstevel@tonic-gate static char *
void_to_str(md_error_t * ep,char * buf,size_t size)6600Sstevel@tonic-gate void_to_str(
6610Sstevel@tonic-gate 	md_error_t	*ep,
6620Sstevel@tonic-gate 	char		*buf,
6630Sstevel@tonic-gate 	size_t		size
6640Sstevel@tonic-gate )
6650Sstevel@tonic-gate {
6660Sstevel@tonic-gate 	md_void_error_t	*ip = &ep->info.md_error_info_t_u.void_error;
6670Sstevel@tonic-gate 	char		*p = buf + strlen(buf);
6680Sstevel@tonic-gate 	size_t		psize = size - strlen(buf);
6690Sstevel@tonic-gate 
6700Sstevel@tonic-gate 	switch (ip->errnum) {
6710Sstevel@tonic-gate 	case MDE_NONE:
6720Sstevel@tonic-gate 		(void) snprintf(p, psize,
6730Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "no error"));
6740Sstevel@tonic-gate 		break;
6750Sstevel@tonic-gate 	case MDE_UNIT_NOT_FOUND:
6760Sstevel@tonic-gate 		(void) snprintf(p, psize,
6770Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unit not found"));
6780Sstevel@tonic-gate 		break;
6790Sstevel@tonic-gate 	case MDE_DUPDRIVE:
6800Sstevel@tonic-gate 		(void) snprintf(p, psize,
6810Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "drive specified more than once"));
6820Sstevel@tonic-gate 		break;
6830Sstevel@tonic-gate 	case MDE_INVAL_HSOP:
6840Sstevel@tonic-gate 		(void) snprintf(p, psize,
6850Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "illegal hot spare operation"));
6860Sstevel@tonic-gate 		break;
6870Sstevel@tonic-gate 	case MDE_NO_SET:
6880Sstevel@tonic-gate 		(void) snprintf(p, psize,
6890Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "no such set"));
6900Sstevel@tonic-gate 		break;
6910Sstevel@tonic-gate 	case MDE_SET_DIFF:
6920Sstevel@tonic-gate 		(void) snprintf(p, psize,
6930Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "set name is inconsistent"));
6940Sstevel@tonic-gate 		break;
6950Sstevel@tonic-gate 	case MDE_BAD_RD_OPT:
6960Sstevel@tonic-gate 		(void) snprintf(p, psize,
6970Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "invalid read option"));
6980Sstevel@tonic-gate 		break;
6990Sstevel@tonic-gate 	case MDE_BAD_WR_OPT:
7000Sstevel@tonic-gate 		(void) snprintf(p, psize,
7010Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "invalid write option"));
7020Sstevel@tonic-gate 		break;
7030Sstevel@tonic-gate 	case MDE_BAD_PASS_NUM:
7040Sstevel@tonic-gate 		(void) snprintf(p, psize,
7050Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "invalid pass number"));
7060Sstevel@tonic-gate 		break;
7070Sstevel@tonic-gate 	case MDE_BAD_RESYNC_OPT:
7080Sstevel@tonic-gate 		(void) snprintf(p, psize,
7090Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "invalid resync option"));
7100Sstevel@tonic-gate 		break;
7110Sstevel@tonic-gate 	case MDE_BAD_INTERLACE:
7120Sstevel@tonic-gate 		(void) snprintf(p, psize,
7130Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "invalid interlace"));
7140Sstevel@tonic-gate 		break;
7150Sstevel@tonic-gate 	case MDE_NO_HSPS:
7160Sstevel@tonic-gate 		(void) snprintf(p, psize,
7170Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "no hotspare pools found"));
7180Sstevel@tonic-gate 		break;
7190Sstevel@tonic-gate 	case MDE_NOTENOUGH_DB:
7200Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
721*5109Spetede 		    "must have at least 1 database (-f overrides)"));
7220Sstevel@tonic-gate 		break;
7230Sstevel@tonic-gate 	case MDE_DELDB_NOTALLOWED:
7240Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
7250Sstevel@tonic-gate 		    "cannot delete the last database replica in the diskset"));
7260Sstevel@tonic-gate 		break;
7270Sstevel@tonic-gate 	case MDE_DEL_VALIDDB_NOTALLOWED:
7280Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
7290Sstevel@tonic-gate 		    "Deleting specified valid replicas results in stale "
7300Sstevel@tonic-gate 		    "state database. Configuration changes with stale "
7310Sstevel@tonic-gate 		    "database result in panic(-f overrides)"));
7320Sstevel@tonic-gate 		break;
7330Sstevel@tonic-gate 	case MDE_SYSTEM_FILE:
7340Sstevel@tonic-gate 		(void) snprintf(p, psize,
7350Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "error in system file"));
7360Sstevel@tonic-gate 		break;
7370Sstevel@tonic-gate 	case MDE_MDDB_FILE:
7380Sstevel@tonic-gate 		(void) snprintf(p, psize,
7390Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "error in mddb.cf file"));
7400Sstevel@tonic-gate 		break;
7410Sstevel@tonic-gate 	case MDE_MDDB_CKSUM:
7420Sstevel@tonic-gate 		(void) snprintf(p, psize,
7430Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "checksum error in mddb.cf file"));
7440Sstevel@tonic-gate 		break;
7450Sstevel@tonic-gate 	case MDE_VFSTAB_FILE:
7460Sstevel@tonic-gate 		(void) snprintf(p, psize,
7470Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "error in vfstab file"));
7480Sstevel@tonic-gate 		break;
7490Sstevel@tonic-gate 	case MDE_NOSLICE:
7500Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
7510Sstevel@tonic-gate 		    "invalid slice number for drive name"));
7520Sstevel@tonic-gate 		break;
7530Sstevel@tonic-gate 	case MDE_SYNTAX:
7540Sstevel@tonic-gate 		(void) snprintf(p, psize,
7550Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "syntax error"));
7560Sstevel@tonic-gate 		break;
7570Sstevel@tonic-gate 	case MDE_OPTION:
7580Sstevel@tonic-gate 		(void) snprintf(p, psize,
7590Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "illegal option"));
7600Sstevel@tonic-gate 		break;
7610Sstevel@tonic-gate 	case MDE_TAKE_OWN:
7620Sstevel@tonic-gate 		(void) snprintf(p, psize,
7630Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "failed to reserve any drives"));
7640Sstevel@tonic-gate 		break;
7650Sstevel@tonic-gate 	case MDE_NOT_DRIVENAME:
7660Sstevel@tonic-gate 		(void) snprintf(p, psize,
7670Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "not a valid drive name"));
7680Sstevel@tonic-gate 		break;
7690Sstevel@tonic-gate 	case MDE_RESERVED:
7700Sstevel@tonic-gate 		(void) snprintf(p, psize,
7710Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "reserved by another host"));
7720Sstevel@tonic-gate 		break;
7730Sstevel@tonic-gate 	case MDE_DVERSION:
7740Sstevel@tonic-gate 		(void) snprintf(p, psize,
7750Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "driver version mismatch"));
7760Sstevel@tonic-gate 		break;
7770Sstevel@tonic-gate 	case MDE_MVERSION:
7780Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
7790Sstevel@tonic-gate 		    "metadevice state database version mismatch"));
7800Sstevel@tonic-gate 		break;
7810Sstevel@tonic-gate 	case MDE_TESTERROR:
7820Sstevel@tonic-gate 		(void) snprintf(p, psize,
7830Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "TEST ERROR MESSAGE"));
7840Sstevel@tonic-gate 		break;
7850Sstevel@tonic-gate 	case MDE_BAD_ORIG_NCOL:
7860Sstevel@tonic-gate 		(void) snprintf(p, psize,
7870Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "invalid column count"));
7880Sstevel@tonic-gate 		break;
7890Sstevel@tonic-gate 	case MDE_RAID_INVALID:
7900Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
7910Sstevel@tonic-gate 		    "devices were not RAIDed previously or "
7920Sstevel@tonic-gate 		    "are specified in the wrong order"));
7930Sstevel@tonic-gate 		break;
7940Sstevel@tonic-gate 	case MDE_MED_ERROR:
7950Sstevel@tonic-gate 		break;
7960Sstevel@tonic-gate 	case MDE_TOOMANYMED:
7970Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
7980Sstevel@tonic-gate 		    "too many mediator hosts requested"));
7990Sstevel@tonic-gate 		break;
8000Sstevel@tonic-gate 	case MDE_NOMED:
8010Sstevel@tonic-gate 		(void) snprintf(p, psize,
8020Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "no mediator hosts found"));
8030Sstevel@tonic-gate 		break;
8040Sstevel@tonic-gate 	case MDE_ONLYNODENAME:
8050Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8060Sstevel@tonic-gate 		    "only the nodename of a host is required for deletes"));
8070Sstevel@tonic-gate 		break;
8080Sstevel@tonic-gate 	case MDE_RAID_BAD_PW_CNT:
8090Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8100Sstevel@tonic-gate 		    "simultaneous writes out of range"));
8110Sstevel@tonic-gate 		break;
8120Sstevel@tonic-gate 	case MDE_DEVID_TOOBIG:
8130Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8140Sstevel@tonic-gate 		    "relocation information size is greater than reported"));
8150Sstevel@tonic-gate 		break;
8160Sstevel@tonic-gate 	case MDE_NOPERM:
8170Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8180Sstevel@tonic-gate 		    "Permission denied.  You must have root privilege "
8190Sstevel@tonic-gate 		    "to execute this command."));
8200Sstevel@tonic-gate 		break;
8210Sstevel@tonic-gate 	case MDE_NODEVID:
8220Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8230Sstevel@tonic-gate 		    "Device relocation information not available "
8240Sstevel@tonic-gate 		    "for this device"));
8250Sstevel@tonic-gate 		break;
8260Sstevel@tonic-gate 	case MDE_NOROOT:
8270Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8280Sstevel@tonic-gate 		    "no root filesystem in /etc/mnttab"));
8290Sstevel@tonic-gate 		break;
8300Sstevel@tonic-gate 	case MDE_EOF_TRANS:
8310Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8320Sstevel@tonic-gate 		    MD_EOF_TRANS_MSG));
8330Sstevel@tonic-gate 		break;
8340Sstevel@tonic-gate 	case MDE_NOT_MN:
8350Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8360Sstevel@tonic-gate 		    "option only valid within a multi-owner set"));
8370Sstevel@tonic-gate 		break;
8380Sstevel@tonic-gate 	case MDE_ABR_SET:
8390Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8400Sstevel@tonic-gate 		    "Invalid command for mirror with ABR set"));
8410Sstevel@tonic-gate 		break;
8420Sstevel@tonic-gate 	case MDE_INVAL_MNOP:
8430Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8440Sstevel@tonic-gate 		    "Invalid operation on multi-owner set"));
8450Sstevel@tonic-gate 		break;
8460Sstevel@tonic-gate 	case MDE_MNSET_NOTRANS:
8470Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8480Sstevel@tonic-gate 		    "Trans metadevice not supported on multi-owner set"));
8490Sstevel@tonic-gate 		break;
8500Sstevel@tonic-gate 	case MDE_MNSET_NORAID:
8510Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8520Sstevel@tonic-gate 		    "RAID-5 metadevice not supported on multi-owner set"));
8530Sstevel@tonic-gate 		break;
8540Sstevel@tonic-gate 	case MDE_FORCE_DEL_ALL_DRV:
8550Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8560Sstevel@tonic-gate 		    "Must specify -f option to delete all drives from set"));
8570Sstevel@tonic-gate 		break;
8580Sstevel@tonic-gate 	case MDE_STRIPE_TRUNC_SINGLE:
8590Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8600Sstevel@tonic-gate 		    "The necessary rounding would result in data loss.  "
8610Sstevel@tonic-gate 		    "You can avoid this by concatenating additional devices "
8620Sstevel@tonic-gate 		    "totaling at least %s blocks, or by increasing the size "
8630Sstevel@tonic-gate 		    "of the specified component by exactly %s blocks."),
8640Sstevel@tonic-gate 		    ep->extra, ep->extra);
8650Sstevel@tonic-gate 		break;
8660Sstevel@tonic-gate 	case MDE_STRIPE_TRUNC_MULTIPLE:
8670Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8680Sstevel@tonic-gate 		    "The necessary rounding would result in data loss.  "
8690Sstevel@tonic-gate 		    "You can avoid this by concatenating additional devices "
8700Sstevel@tonic-gate 		    "totaling at least %s blocks."), ep->extra);
8710Sstevel@tonic-gate 		break;
8720Sstevel@tonic-gate 	case MDE_SMF_FAIL:
8730Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8740Sstevel@tonic-gate 		    "failed to enable/disable SVM service"));
8750Sstevel@tonic-gate 		break;
8760Sstevel@tonic-gate 	case MDE_SMF_NO_SERVICE:
8770Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8780Sstevel@tonic-gate 		    "service(s) not online in SMF"));
8790Sstevel@tonic-gate 		break;
8801623Stw21770 	case MDE_AMBIGUOUS_DEV:
8811623Stw21770 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8821623Stw21770 		    "Specify complete path to avoid ambiguity."));
8831623Stw21770 		break;
8841623Stw21770 	case MDE_NAME_IN_USE:
8851623Stw21770 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8861623Stw21770 		    "Name already in use for metadevice or hot spare pool."));
8871623Stw21770 		break;
8881623Stw21770 	case MDE_NAME_ILLEGAL:
8891623Stw21770 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
8901623Stw21770 		    "Invalid name for metadevice or hot spare pool."));
8911623Stw21770 		break;
892645Sgjelinek 	case MDE_ZONE_ADMIN:
893645Sgjelinek 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
894645Sgjelinek 		"Volume administration unavailable within non-global zones."));
895645Sgjelinek 		break;
896*5109Spetede 	case MDE_MISSING_DEVID_DISK:
897*5109Spetede 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
898*5109Spetede 		    "device id does not exist."));
899*5109Spetede 		break;
9000Sstevel@tonic-gate 	default:
9010Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
9020Sstevel@tonic-gate 		    "unknown void error code %d"), ip->errnum);
9030Sstevel@tonic-gate 		break;
9040Sstevel@tonic-gate 	}
9050Sstevel@tonic-gate 
9060Sstevel@tonic-gate 	return (buf);
9070Sstevel@tonic-gate }
9080Sstevel@tonic-gate 
9090Sstevel@tonic-gate /*
9100Sstevel@tonic-gate  * print sys class errors
9110Sstevel@tonic-gate  */
9120Sstevel@tonic-gate static char *
sys_to_str(md_error_t * ep,char * buf,size_t size)9130Sstevel@tonic-gate sys_to_str(
9140Sstevel@tonic-gate 	md_error_t	*ep,
9150Sstevel@tonic-gate 	char		*buf,
9160Sstevel@tonic-gate 	size_t		size
9170Sstevel@tonic-gate )
9180Sstevel@tonic-gate {
9190Sstevel@tonic-gate 	md_sys_error_t	*ip = &ep->info.md_error_info_t_u.sys_error;
9200Sstevel@tonic-gate 	char		*emsg;
9210Sstevel@tonic-gate 	char		*p = buf + strlen(buf);
9220Sstevel@tonic-gate 	size_t		psize = size - strlen(buf);
9230Sstevel@tonic-gate 
9240Sstevel@tonic-gate 	if ((emsg = strerror(ip->errnum)) == NULL) {
9250Sstevel@tonic-gate 		(void) snprintf(p, psize,
9260Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unknown errno %d out of range"),
9270Sstevel@tonic-gate 		    ip->errnum);
9280Sstevel@tonic-gate 	} else {
9290Sstevel@tonic-gate 		(void) snprintf(p, psize, "%s", emsg);
9300Sstevel@tonic-gate 	}
9310Sstevel@tonic-gate 
9320Sstevel@tonic-gate 	return (buf);
9330Sstevel@tonic-gate }
9340Sstevel@tonic-gate 
9350Sstevel@tonic-gate /*
9360Sstevel@tonic-gate  * print RPC class errors
9370Sstevel@tonic-gate  */
9380Sstevel@tonic-gate static char *
rpc_to_str(md_error_t * ep,char * buf,size_t size)9390Sstevel@tonic-gate rpc_to_str(
9400Sstevel@tonic-gate 	md_error_t	*ep,
9410Sstevel@tonic-gate 	char		*buf,
9420Sstevel@tonic-gate 	size_t		size
9430Sstevel@tonic-gate )
9440Sstevel@tonic-gate {
9450Sstevel@tonic-gate 	md_rpc_error_t	*ip = &ep->info.md_error_info_t_u.rpc_error;
9460Sstevel@tonic-gate 	char		*p = buf + strlen(buf);
9470Sstevel@tonic-gate 	size_t		psize = size - strlen(buf);
9480Sstevel@tonic-gate 
9490Sstevel@tonic-gate 	(void) snprintf(p, psize, "%s", clnt_sperrno(ip->errnum));
9500Sstevel@tonic-gate 	return (buf);
9510Sstevel@tonic-gate }
9520Sstevel@tonic-gate 
9530Sstevel@tonic-gate /*
9540Sstevel@tonic-gate  * print dev class errors
9550Sstevel@tonic-gate  */
9560Sstevel@tonic-gate static char *
dev_to_str(md_error_t * ep,char * buf,size_t size)9570Sstevel@tonic-gate dev_to_str(
9580Sstevel@tonic-gate 	md_error_t	*ep,
9590Sstevel@tonic-gate 	char		*buf,
9600Sstevel@tonic-gate 	size_t		size
9610Sstevel@tonic-gate )
9620Sstevel@tonic-gate {
9630Sstevel@tonic-gate 	md_dev_error_t	*ip = &ep->info.md_error_info_t_u.dev_error;
9640Sstevel@tonic-gate 	char		*p = buf + strlen(buf);
9650Sstevel@tonic-gate 	size_t		psize = size - strlen(buf);
9660Sstevel@tonic-gate 
9670Sstevel@tonic-gate 	switch (ip->errnum) {
9680Sstevel@tonic-gate 	case MDE_INVAL_HS:
9690Sstevel@tonic-gate 		(void) snprintf(p, psize,
9700Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "hotspare doesn't exist"));
9710Sstevel@tonic-gate 		break;
9720Sstevel@tonic-gate 	case MDE_FIX_INVAL_STATE:
9730Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
9740Sstevel@tonic-gate 		    "cannot enable hotspared device"));
9750Sstevel@tonic-gate 		break;
9760Sstevel@tonic-gate 	case MDE_FIX_INVAL_HS_STATE:
9770Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
9780Sstevel@tonic-gate 		    "hotspare isn't broken, can't enable"));
9790Sstevel@tonic-gate 		break;
9800Sstevel@tonic-gate 	case MDE_NOT_META:
9810Sstevel@tonic-gate 		(void) snprintf(p, psize,
9820Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "not a metadevice"));
9830Sstevel@tonic-gate 		break;
9840Sstevel@tonic-gate 	case MDE_IS_DUMP:
9850Sstevel@tonic-gate 		(void) snprintf(p, psize,
9860Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "is a dump device"));
9870Sstevel@tonic-gate 		break;
9880Sstevel@tonic-gate 	case MDE_IS_META:
9890Sstevel@tonic-gate 		(void) snprintf(p, psize,
9900Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "is a metadevice"));
9910Sstevel@tonic-gate 		break;
9920Sstevel@tonic-gate 	case MDE_IS_SWAPPED:
9930Sstevel@tonic-gate 		(void) snprintf(p, psize,
9940Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "is swapped on"));
9950Sstevel@tonic-gate 		break;
9960Sstevel@tonic-gate 	case MDE_NAME_SPACE:
9970Sstevel@tonic-gate 		(void) snprintf(p, psize,
9980Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "namespace error"));
9990Sstevel@tonic-gate 		break;
10000Sstevel@tonic-gate 	case MDE_IN_SHARED_SET:
10010Sstevel@tonic-gate 		(void) snprintf(p, psize,
10020Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "device in shared set"));
10030Sstevel@tonic-gate 		break;
10040Sstevel@tonic-gate 	case MDE_NOT_IN_SET:
10050Sstevel@tonic-gate 		(void) snprintf(p, psize,
10060Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "device not in set"));
10070Sstevel@tonic-gate 		break;
10080Sstevel@tonic-gate 	case MDE_NOT_DISK:
10090Sstevel@tonic-gate 		(void) snprintf(p, psize,
10100Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "not a disk device"));
10110Sstevel@tonic-gate 		break;
10120Sstevel@tonic-gate 	case MDE_CANT_CONFIRM:
10130Sstevel@tonic-gate 		(void) snprintf(p, psize,
10140Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "can't confirm device"));
10150Sstevel@tonic-gate 		break;
10160Sstevel@tonic-gate 	case MDE_INVALID_PART:
10170Sstevel@tonic-gate 		(void) snprintf(p, psize,
10180Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "invalid partition"));
10190Sstevel@tonic-gate 		break;
10200Sstevel@tonic-gate 	case MDE_HAS_MDDB:
10210Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
10220Sstevel@tonic-gate 		    "has a metadevice database replica"));
10230Sstevel@tonic-gate 		break;
10240Sstevel@tonic-gate 	case MDE_NO_DB:
10250Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
10260Sstevel@tonic-gate 		    "no metadevice database replica on device"));
10270Sstevel@tonic-gate 		break;
10280Sstevel@tonic-gate 	case MDE_CANTVERIFY_VTOC:
10290Sstevel@tonic-gate 		(void) snprintf(p, psize,
10300Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unable to verify the vtoc"));
10310Sstevel@tonic-gate 		break;
10320Sstevel@tonic-gate 	case MDE_NOT_LOCAL:
10330Sstevel@tonic-gate 		(void) snprintf(p, psize,
10340Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "not in local set"));
10350Sstevel@tonic-gate 		break;
10360Sstevel@tonic-gate 	case MDE_DEVICES_NAME:
10370Sstevel@tonic-gate 		(void) snprintf(p, psize,
10380Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "can't parse /devices name"));
10390Sstevel@tonic-gate 		break;
10400Sstevel@tonic-gate 	case MDE_REPCOMP_INVAL:
10410Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
10420Sstevel@tonic-gate 		    "replica slice is not usable as a metadevice component"));
10430Sstevel@tonic-gate 		break;
10440Sstevel@tonic-gate 	case MDE_REPCOMP_ONLY:
10450Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
10460Sstevel@tonic-gate 		    "only replica slice is usable for a diskset "
10470Sstevel@tonic-gate 		    "database replica"));
10480Sstevel@tonic-gate 		break;
10490Sstevel@tonic-gate 	case MDE_INV_ROOT:
10500Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
10510Sstevel@tonic-gate 		    "invalid root device for this operation"));
10520Sstevel@tonic-gate 		break;
10530Sstevel@tonic-gate 	case MDE_MULTNM:
10540Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
10550Sstevel@tonic-gate 		    "multiple entries for device in Solaris Volume Manager "
10560Sstevel@tonic-gate 		    "configuration"));
10570Sstevel@tonic-gate 		break;
10580Sstevel@tonic-gate 	case MDE_TOO_MANY_PARTS:
10590Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
10600Sstevel@tonic-gate 		    "Disks with more than %d partitions are not supported "
10610Sstevel@tonic-gate 		    "in Solaris Volume Manager"), MD_MAX_PARTS);
10620Sstevel@tonic-gate 		break;
10630Sstevel@tonic-gate 	case MDE_REPART_REPLICA:
10640Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
10650Sstevel@tonic-gate 		    "cannot repartition a slice with an existing replica"));
10660Sstevel@tonic-gate 		break;
1067*5109Spetede 	case MDE_DISKNAMETOOLONG:
1068*5109Spetede 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
1069*5109Spetede 		    "disk name is too long with device ids disabled "
1070*5109Spetede 		    "in Solaris Volume Manager. Check /kernel/drv/md.conf "
1071*5109Spetede 		    "for md_devid_destroy, remove it and reboot"));
1072*5109Spetede 		break;
10730Sstevel@tonic-gate 	default:
10740Sstevel@tonic-gate 		(void) snprintf(p, psize,
10750Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unknown dev error code %d"),
10760Sstevel@tonic-gate 		    ip->errnum);
10770Sstevel@tonic-gate 		break;
10780Sstevel@tonic-gate 	}
10790Sstevel@tonic-gate 
10800Sstevel@tonic-gate 	return (buf);
10810Sstevel@tonic-gate }
10820Sstevel@tonic-gate 
10830Sstevel@tonic-gate /*
10840Sstevel@tonic-gate  * print overlap class errors
10850Sstevel@tonic-gate  */
10860Sstevel@tonic-gate static char *
overlap_to_str(md_error_t * ep,char * buf,size_t size)10870Sstevel@tonic-gate overlap_to_str(
10880Sstevel@tonic-gate 	md_error_t	*ep,
10890Sstevel@tonic-gate 	char		*buf,
10900Sstevel@tonic-gate 	size_t		size
10910Sstevel@tonic-gate )
10920Sstevel@tonic-gate {
10930Sstevel@tonic-gate 	md_overlap_error_t	*ip =
1094*5109Spetede 	    &ep->info.md_error_info_t_u.overlap_error;
10950Sstevel@tonic-gate 	char		*p = buf + strlen(buf);
10960Sstevel@tonic-gate 	size_t		psize = size - strlen(buf);
10970Sstevel@tonic-gate 
10980Sstevel@tonic-gate 	switch (ip->errnum) {
10990Sstevel@tonic-gate 	case MDE_OVERLAP_MOUNTED:
11000Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
11010Sstevel@tonic-gate 		    "overlaps with %s which is mounted as \'%s\'"),
1102*5109Spetede 		    ip->overlap, ip->where);
11030Sstevel@tonic-gate 		break;
11040Sstevel@tonic-gate 	case MDE_OVERLAP_SWAP:
11050Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
11060Sstevel@tonic-gate 		    "overlaps with %s which is a swap device"), ip->overlap);
11070Sstevel@tonic-gate 		break;
11080Sstevel@tonic-gate 	case MDE_OVERLAP_DUMP:
11090Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
11100Sstevel@tonic-gate 		    "overlaps with %s which is the dump device"), ip->overlap);
11110Sstevel@tonic-gate 		break;
11120Sstevel@tonic-gate 	default:
11130Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
11140Sstevel@tonic-gate 		    "unknown overlap error code %d"), ip->errnum);
11150Sstevel@tonic-gate 		break;
11160Sstevel@tonic-gate 	}
11170Sstevel@tonic-gate 
11180Sstevel@tonic-gate 	return (buf);
11190Sstevel@tonic-gate }
11200Sstevel@tonic-gate 
11210Sstevel@tonic-gate /*
11220Sstevel@tonic-gate  * print use class errors
11230Sstevel@tonic-gate  */
11240Sstevel@tonic-gate static char *
use_to_str(md_error_t * ep,char * buf,size_t size)11250Sstevel@tonic-gate use_to_str(
11260Sstevel@tonic-gate 	md_error_t	*ep,
11270Sstevel@tonic-gate 	char		*buf,
11280Sstevel@tonic-gate 	size_t		size
11290Sstevel@tonic-gate )
11300Sstevel@tonic-gate {
11310Sstevel@tonic-gate 	md_use_error_t	*ip = &ep->info.md_error_info_t_u.use_error;
11320Sstevel@tonic-gate 	char		*p = buf + strlen(buf);
11330Sstevel@tonic-gate 	size_t		psize = size - strlen(buf);
11340Sstevel@tonic-gate 
11350Sstevel@tonic-gate 	switch (ip->errnum) {
11360Sstevel@tonic-gate 	case MDE_IS_MOUNTED:
11370Sstevel@tonic-gate 		(void) snprintf(p, psize,
11380Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "is mounted on %s"),
11390Sstevel@tonic-gate 		    ip->where);
11400Sstevel@tonic-gate 		break;
11410Sstevel@tonic-gate 	case MDE_ALREADY:
11420Sstevel@tonic-gate 		/*
11430Sstevel@tonic-gate 		 * when the object of the error (existing device that
11440Sstevel@tonic-gate 		 * would being used by SVM) is the metadb then it is necessary
11450Sstevel@tonic-gate 		 * to explicitly specify the string in the error message so
11460Sstevel@tonic-gate 		 * that it can be successfully localized for the Asian locales.
11470Sstevel@tonic-gate 		 */
11480Sstevel@tonic-gate 		if (strcmp(ip->where, MDB_STR) != 0) {
11490Sstevel@tonic-gate 			(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
1150*5109Spetede 			    "has appeared more than once in the "
1151*5109Spetede 			    "specification of %s"), ip->where);
11520Sstevel@tonic-gate 		} else {
11530Sstevel@tonic-gate 			(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
1154*5109Spetede 			    "has appeared more than once in the "
1155*5109Spetede 			    "specification of " MDB_STR));
11560Sstevel@tonic-gate 		}
11570Sstevel@tonic-gate 		break;
11580Sstevel@tonic-gate 	case MDE_OVERLAP:
11590Sstevel@tonic-gate 		/*
11600Sstevel@tonic-gate 		 * when the object of the error (existing device that
11610Sstevel@tonic-gate 		 * would overlap) is the metadb then it is necessary
11620Sstevel@tonic-gate 		 * to explicitly specify the string in the error message so
11630Sstevel@tonic-gate 		 * that it can be successfully localized for the Asian locales.
11640Sstevel@tonic-gate 		 */
11650Sstevel@tonic-gate 		if (strcmp(ip->where, MDB_STR) != 0) {
11660Sstevel@tonic-gate 			(void) snprintf(p, psize,
11670Sstevel@tonic-gate 			    dgettext(TEXT_DOMAIN, "overlaps with device in %s"),
11680Sstevel@tonic-gate 			    ip->where);
11690Sstevel@tonic-gate 		} else {
11700Sstevel@tonic-gate 			(void) snprintf(p, psize,
11710Sstevel@tonic-gate 			    dgettext(TEXT_DOMAIN, "overlaps with device in "
11720Sstevel@tonic-gate 			    MDB_STR));
11730Sstevel@tonic-gate 		}
11740Sstevel@tonic-gate 		break;
1175127Shshaw 	case MDE_SAME_DEVID:
1176127Shshaw 		/*
1177127Shshaw 		 * when the object of the error (existing device in the
1178127Shshaw 		 * metaconfiguration that has the same devid)
1179127Shshaw 		 * is the metadb then it is necessary
1180127Shshaw 		 * to explicitly specify the string in the error message so
1181127Shshaw 		 * that it can be successfully localized for the Asian locales.
1182127Shshaw 		 */
1183127Shshaw 		if (strcmp(ip->where, MDB_STR) != 0) {
1184127Shshaw 			(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
1185127Shshaw 			    "identical devid detected on %s"), ip->where);
1186127Shshaw 		} else {
1187127Shshaw 			(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
1188127Shshaw 			    "identical devid detected in " MDB_STR));
1189127Shshaw 		}
1190127Shshaw 		break;
11910Sstevel@tonic-gate 	default:
11920Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
11930Sstevel@tonic-gate 		    "unknown dev error code %d"), ip->errnum);
11940Sstevel@tonic-gate 		break;
11950Sstevel@tonic-gate 	}
11960Sstevel@tonic-gate 
11970Sstevel@tonic-gate 	return (buf);
11980Sstevel@tonic-gate }
11990Sstevel@tonic-gate 
12000Sstevel@tonic-gate /*
12010Sstevel@tonic-gate  * print md class errors
12020Sstevel@tonic-gate  */
12030Sstevel@tonic-gate static char *
md_to_str(md_error_t * ep,char * buf,size_t size)12040Sstevel@tonic-gate md_to_str(
12050Sstevel@tonic-gate 	md_error_t	*ep,
12060Sstevel@tonic-gate 	char		*buf,
12070Sstevel@tonic-gate 	size_t		size
12080Sstevel@tonic-gate )
12090Sstevel@tonic-gate {
12100Sstevel@tonic-gate 	md_md_error_t	*ip = &ep->info.md_error_info_t_u.md_error;
12110Sstevel@tonic-gate 	char		*p = buf + strlen(buf);
12120Sstevel@tonic-gate 	size_t		psize = size - strlen(buf);
12130Sstevel@tonic-gate 
12140Sstevel@tonic-gate 	switch (ip->errnum) {
12150Sstevel@tonic-gate 	case MDE_INVAL_UNIT:
12160Sstevel@tonic-gate 		(void) snprintf(p, psize,
12170Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "invalid unit"));
12180Sstevel@tonic-gate 		break;
12190Sstevel@tonic-gate 	case MDE_UNIT_NOT_SETUP:
12200Sstevel@tonic-gate 		(void) snprintf(p, psize,
12210Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unit not set up"));
12220Sstevel@tonic-gate 		break;
12230Sstevel@tonic-gate 	case MDE_UNIT_ALREADY_SETUP:
12240Sstevel@tonic-gate 		(void) snprintf(p, psize,
12250Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unit already set up"));
12260Sstevel@tonic-gate 		break;
12270Sstevel@tonic-gate 	case MDE_NOT_MM:
12280Sstevel@tonic-gate 		(void) snprintf(p, psize,
12290Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unit is not a mirror"));
12300Sstevel@tonic-gate 		break;
12310Sstevel@tonic-gate 	case MDE_IS_SM:
12320Sstevel@tonic-gate 		(void) snprintf(p, psize,
12330Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "illegal to clear submirror"));
12340Sstevel@tonic-gate 		break;
12350Sstevel@tonic-gate 	case MDE_IS_OPEN:
12360Sstevel@tonic-gate 		(void) snprintf(p, psize,
12370Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "metadevice is open"));
12380Sstevel@tonic-gate 		break;
12390Sstevel@tonic-gate 	case MDE_C_WITH_INVAL_SM:
12400Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
12410Sstevel@tonic-gate 		    "attempted to clear mirror with submirror(s) "
12420Sstevel@tonic-gate 		    "in invalid state"));
12430Sstevel@tonic-gate 		break;
12440Sstevel@tonic-gate 	case MDE_RESYNC_ACTIVE:
12450Sstevel@tonic-gate 		(void) snprintf(p, psize,
12460Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "resync in progress"));
12470Sstevel@tonic-gate 		break;
12480Sstevel@tonic-gate 	case MDE_LAST_SM_RE:
12490Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
12500Sstevel@tonic-gate 		    "attempt to replace a component on the last "
12510Sstevel@tonic-gate 		    "running submirror"));
12520Sstevel@tonic-gate 		break;
12530Sstevel@tonic-gate 	case MDE_MIRROR_FULL:
12540Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
12550Sstevel@tonic-gate 		    "mirror has maximum number of submirrors"));
12560Sstevel@tonic-gate 		break;
12570Sstevel@tonic-gate 	case MDE_IN_UNAVAIL_STATE:
12580Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
12590Sstevel@tonic-gate 		    "component is in unavailable state; run 'metastat -i'"));
12600Sstevel@tonic-gate 		break;
12610Sstevel@tonic-gate 	case MDE_IN_USE:
12620Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
12630Sstevel@tonic-gate 		    "metadevice in use"));
12640Sstevel@tonic-gate 		break;
12650Sstevel@tonic-gate 	case MDE_SM_TOO_SMALL:
12660Sstevel@tonic-gate 		(void) snprintf(p, psize,
12670Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "submirror too small to attach"));
12680Sstevel@tonic-gate 		break;
12690Sstevel@tonic-gate 	case MDE_NO_LABELED_SM:
12700Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
12710Sstevel@tonic-gate 		    "can't attach labeled submirror to an unlabeled mirror"));
12720Sstevel@tonic-gate 		break;
12730Sstevel@tonic-gate 	case MDE_SM_OPEN_ERR:
12740Sstevel@tonic-gate 		(void) snprintf(p, psize,
12750Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "submirror open error"));
12760Sstevel@tonic-gate 		break;
12770Sstevel@tonic-gate 	case MDE_CANT_FIND_SM:
12780Sstevel@tonic-gate 		(void) snprintf(p, psize,
12790Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "can't find submirror in mirror"));
12800Sstevel@tonic-gate 		break;
12810Sstevel@tonic-gate 	case MDE_LAST_SM:
12820Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
1283*5109Spetede 		    "attempt to detach last running submirror"));
12840Sstevel@tonic-gate 		break;
12850Sstevel@tonic-gate 	case MDE_NO_READABLE_SM:
12860Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
12870Sstevel@tonic-gate 		    "operation would result in no readable submirrors"));
12880Sstevel@tonic-gate 		break;
12890Sstevel@tonic-gate 	case MDE_SM_FAILED_COMPS:
12900Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
12910Sstevel@tonic-gate 		    "attempt an operation on a submirror "
12920Sstevel@tonic-gate 		    "that has erred components"));
12930Sstevel@tonic-gate 		break;
12940Sstevel@tonic-gate 	case MDE_ILLEGAL_SM_STATE:
12950Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
12960Sstevel@tonic-gate 		    "attempt operation on a submirror in illegal state"));
12970Sstevel@tonic-gate 		break;
12980Sstevel@tonic-gate 	case MDE_RR_ALLOC_ERROR:
12990Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
13000Sstevel@tonic-gate 		    "attach failed, unable to allocate new resync info"));
13010Sstevel@tonic-gate 		break;
13020Sstevel@tonic-gate 	case MDE_MIRROR_OPEN_FAILURE:
13030Sstevel@tonic-gate 		(void) snprintf(p, psize,
13040Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "insufficient devices to open"));
13050Sstevel@tonic-gate 		break;
13060Sstevel@tonic-gate 	case MDE_MIRROR_THREAD_FAILURE:
13070Sstevel@tonic-gate 		(void) snprintf(p, psize,
13080Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "mirror thread failure"));
13090Sstevel@tonic-gate 		break;
13100Sstevel@tonic-gate 	case MDE_GROW_DELAYED:
13110Sstevel@tonic-gate 		(void) snprintf(p, psize,
13120Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "growing of metadevice delayed"));
13130Sstevel@tonic-gate 		break;
13140Sstevel@tonic-gate 	case MDE_NOT_MT:
13150Sstevel@tonic-gate 		(void) snprintf(p, psize,
13160Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unit is not a trans"));
13170Sstevel@tonic-gate 		break;
13180Sstevel@tonic-gate 	case MDE_HS_IN_USE:
13190Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
13200Sstevel@tonic-gate 		    "can't modify hot spare pool, hot spare in use"));
13210Sstevel@tonic-gate 		break;
13220Sstevel@tonic-gate 	case MDE_HAS_LOG:
13230Sstevel@tonic-gate 		(void) snprintf(p, psize,
13240Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "already has log"));
13250Sstevel@tonic-gate 		break;
13260Sstevel@tonic-gate 	case MDE_UNKNOWN_TYPE:
13270Sstevel@tonic-gate 		(void) snprintf(p, psize,
13280Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unknown metadevice type"));
13290Sstevel@tonic-gate 		break;
13300Sstevel@tonic-gate 	case MDE_NOT_STRIPE:
13310Sstevel@tonic-gate 		(void) snprintf(p, psize,
13320Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unit is not a concat/stripe"));
13330Sstevel@tonic-gate 		break;
13340Sstevel@tonic-gate 	case MDE_NOT_RAID:
13350Sstevel@tonic-gate 		(void) snprintf(p, psize,
13360Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unit is not a RAID"));
13370Sstevel@tonic-gate 		break;
13380Sstevel@tonic-gate 	case MDE_NROWS:
13390Sstevel@tonic-gate 		(void) snprintf(p, psize,
13400Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "not enough stripes specified"));
13410Sstevel@tonic-gate 		break;
13420Sstevel@tonic-gate 	case MDE_NCOMPS:
13430Sstevel@tonic-gate 		(void) snprintf(p, psize,
13440Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "not enough components specified"));
13450Sstevel@tonic-gate 		break;
13460Sstevel@tonic-gate 	case MDE_NSUBMIRS:
13470Sstevel@tonic-gate 		(void) snprintf(p, psize,
13480Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "not enough submirrors specified"));
13490Sstevel@tonic-gate 		break;
13500Sstevel@tonic-gate 	case MDE_BAD_STRIPE:
13510Sstevel@tonic-gate 		(void) snprintf(p, psize,
13520Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "invalid stripe configuration"));
13530Sstevel@tonic-gate 		break;
13540Sstevel@tonic-gate 	case MDE_BAD_MIRROR:
13550Sstevel@tonic-gate 		(void) snprintf(p, psize,
13560Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "invalid mirror configuration"));
13570Sstevel@tonic-gate 		break;
13580Sstevel@tonic-gate 	case MDE_BAD_TRANS:
13590Sstevel@tonic-gate 		(void) snprintf(p, psize,
13600Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "invalid trans configuration"));
13610Sstevel@tonic-gate 		break;
13620Sstevel@tonic-gate 	case MDE_BAD_RAID:
13630Sstevel@tonic-gate 		(void) snprintf(p, psize,
13640Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "invalid RAID configuration"));
13650Sstevel@tonic-gate 		break;
13660Sstevel@tonic-gate 	case MDE_RAID_OPEN_FAILURE:
13670Sstevel@tonic-gate 		(void) snprintf(p, psize,
13680Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "resync unable to open RAID unit"));
13690Sstevel@tonic-gate 		break;
13700Sstevel@tonic-gate 	case MDE_RAID_THREAD_FAILURE:
13710Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
13720Sstevel@tonic-gate 		    "attempt to start resync thread failed"));
13730Sstevel@tonic-gate 		break;
13740Sstevel@tonic-gate 	case MDE_RAID_NEED_FORCE:
13750Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
13760Sstevel@tonic-gate 		    "operation requires -f (force) flag"));
13770Sstevel@tonic-gate 		break;
13780Sstevel@tonic-gate 	case MDE_NO_LOG:
13790Sstevel@tonic-gate 		(void) snprintf(p, psize,
13800Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "log has already been detached"));
13810Sstevel@tonic-gate 		break;
13820Sstevel@tonic-gate 	case MDE_RAID_DOI:
13830Sstevel@tonic-gate 		(void) snprintf(p, psize,
13840Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "only valid action is metaclear"));
13850Sstevel@tonic-gate 		break;
13860Sstevel@tonic-gate 	case MDE_RAID_LAST_ERRED:
13870Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
13880Sstevel@tonic-gate 		    "in Last Erred state, "
13890Sstevel@tonic-gate 		    "errored components must be replaced"));
13900Sstevel@tonic-gate 		break;
13910Sstevel@tonic-gate 	case MDE_RAID_NOT_OKAY:
13920Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
13930Sstevel@tonic-gate 		    "all components must be Okay to perform this operation"));
13940Sstevel@tonic-gate 		break;
13950Sstevel@tonic-gate 	case MDE_RENAME_BUSY:
13960Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
13970Sstevel@tonic-gate 		    "metadevice is temporarily too busy for renames"));
13980Sstevel@tonic-gate 		break;
13990Sstevel@tonic-gate 	case MDE_RENAME_SOURCE_BAD:
14000Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
14010Sstevel@tonic-gate 		    "source metadevice is not able to be renamed"));
14020Sstevel@tonic-gate 		break;
14030Sstevel@tonic-gate 	case MDE_RENAME_TARGET_BAD:
14040Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
14050Sstevel@tonic-gate 		    "target metadevice is not able to be renamed"));
14060Sstevel@tonic-gate 		break;
14070Sstevel@tonic-gate 	case MDE_RENAME_TARGET_UNRELATED:
14080Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
14090Sstevel@tonic-gate 		    "target metadevice is not related to source metadevice"));
14100Sstevel@tonic-gate 		break;
14110Sstevel@tonic-gate 	case MDE_RENAME_CONFIG_ERROR:
14120Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
14130Sstevel@tonic-gate 		    "metadevice driver configuration error; "
14140Sstevel@tonic-gate 		    "rename can't occur"));
14150Sstevel@tonic-gate 		break;
14160Sstevel@tonic-gate 	case MDE_RENAME_ORDER:
14170Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
14180Sstevel@tonic-gate 		    "units may not be renamed in that order"));
14190Sstevel@tonic-gate 		break;
14200Sstevel@tonic-gate 	case MDE_RECOVER_FAILED:
14210Sstevel@tonic-gate 		(void) snprintf(p, psize,
14220Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "recovery failed"));
14230Sstevel@tonic-gate 		break;
14240Sstevel@tonic-gate 	case MDE_SP_NOSPACE:
14250Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
14260Sstevel@tonic-gate 		    "not enough space available for request"));
14270Sstevel@tonic-gate 		break;
14280Sstevel@tonic-gate 	case MDE_SP_BADWMREAD:
14290Sstevel@tonic-gate 		(void) snprintf(p, psize,
14300Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "error reading extent header"));
14310Sstevel@tonic-gate 		break;
14320Sstevel@tonic-gate 	case MDE_SP_BADWMWRITE:
14330Sstevel@tonic-gate 		(void) snprintf(p, psize,
14340Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "error writing extent header"));
14350Sstevel@tonic-gate 		break;
14360Sstevel@tonic-gate 	case MDE_SP_BADWMMAGIC:
14370Sstevel@tonic-gate 		(void) snprintf(p, psize,
14380Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "bad magic number in extent header"));
14390Sstevel@tonic-gate 		break;
14400Sstevel@tonic-gate 	case MDE_SP_BADWMCRC:
14410Sstevel@tonic-gate 		(void) snprintf(p, psize,
14420Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "bad checksum in extent header"));
14430Sstevel@tonic-gate 		break;
14440Sstevel@tonic-gate 	case MDE_NOT_SP:
14450Sstevel@tonic-gate 		(void) snprintf(p, psize,
14460Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unit is not a soft partition"));
14470Sstevel@tonic-gate 		break;
14480Sstevel@tonic-gate 	case MDE_SP_OVERLAP:
14490Sstevel@tonic-gate 		(void) snprintf(p, psize,
14500Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "overlapping extents specified"));
14510Sstevel@tonic-gate 		break;
14520Sstevel@tonic-gate 	case MDE_SP_BAD_LENGTH:
14530Sstevel@tonic-gate 		(void) snprintf(p, psize,
14540Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "bad length specified"));
14550Sstevel@tonic-gate 		break;
14560Sstevel@tonic-gate 	case MDE_SP_NOSP:
14570Sstevel@tonic-gate 		(void) snprintf(p, psize,
14580Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "no soft partitions on this device"));
14590Sstevel@tonic-gate 		break;
14600Sstevel@tonic-gate 	case MDE_UNIT_TOO_LARGE:
14610Sstevel@tonic-gate 		(void) snprintf(p, psize,
14620Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "Volume size cannot exceed 1 TByte"));
14630Sstevel@tonic-gate 		break;
14640Sstevel@tonic-gate 	case MDE_LOG_TOO_LARGE:
14650Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
14660Sstevel@tonic-gate 		    "Trans log size must be less than 1 TByte"));
14670Sstevel@tonic-gate 		break;
14680Sstevel@tonic-gate 	default:
14690Sstevel@tonic-gate 		(void) snprintf(p, psize,
14700Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unknown md error code %d"),
14710Sstevel@tonic-gate 		    ip->errnum);
14720Sstevel@tonic-gate 		break;
14730Sstevel@tonic-gate 	}
14740Sstevel@tonic-gate 
14750Sstevel@tonic-gate 	return (buf);
14760Sstevel@tonic-gate }
14770Sstevel@tonic-gate 
14780Sstevel@tonic-gate /*
14790Sstevel@tonic-gate  * print comp class errors
14800Sstevel@tonic-gate  */
14810Sstevel@tonic-gate static char *
comp_to_str(md_error_t * ep,char * buf,size_t size)14820Sstevel@tonic-gate comp_to_str(
14830Sstevel@tonic-gate 	md_error_t	*ep,
14840Sstevel@tonic-gate 	char		*buf,
14850Sstevel@tonic-gate 	size_t		size
14860Sstevel@tonic-gate )
14870Sstevel@tonic-gate {
14880Sstevel@tonic-gate 	md_comp_error_t	*ip = &ep->info.md_error_info_t_u.comp_error;
14890Sstevel@tonic-gate 	char		*p = buf + strlen(buf);
14900Sstevel@tonic-gate 	size_t		psize = size - strlen(buf);
14910Sstevel@tonic-gate 
14920Sstevel@tonic-gate 	switch (ip->errnum) {
14930Sstevel@tonic-gate 	case MDE_CANT_FIND_COMP:
14940Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
14950Sstevel@tonic-gate 		    "can't find component in unit"));
14960Sstevel@tonic-gate 		break;
14970Sstevel@tonic-gate 	case MDE_REPL_INVAL_STATE:
14980Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
14990Sstevel@tonic-gate 		    "component in invalid state to replace - "
15000Sstevel@tonic-gate 		    "Replace \"Maintenance\" components first"));
15010Sstevel@tonic-gate 		break;
15020Sstevel@tonic-gate 	case MDE_COMP_TOO_SMALL:
15030Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15040Sstevel@tonic-gate 		    "replace failure, new component is too small"));
15050Sstevel@tonic-gate 		break;
15060Sstevel@tonic-gate 	case MDE_COMP_OPEN_ERR:
15070Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15080Sstevel@tonic-gate 		    "unable to open concat/stripe component"));
15090Sstevel@tonic-gate 		break;
15100Sstevel@tonic-gate 	case MDE_RAID_COMP_ERRED:
15110Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15120Sstevel@tonic-gate 		    "must replace errored component first"));
15130Sstevel@tonic-gate 		break;
15140Sstevel@tonic-gate 	case MDE_MAXIO:
15150Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15160Sstevel@tonic-gate 		    "maxtransfer is too small"));
15170Sstevel@tonic-gate 		break;
15180Sstevel@tonic-gate 	case MDE_SP_COMP_OPEN_ERR:
15190Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15200Sstevel@tonic-gate 		    "error opening device under soft partition. Check"
15210Sstevel@tonic-gate 		    " device status, then use metadevadm(1M)."));
15220Sstevel@tonic-gate 		break;
15230Sstevel@tonic-gate 	default:
15240Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15250Sstevel@tonic-gate 		    "unknown comp error code %d"), ip->errnum);
15260Sstevel@tonic-gate 		break;
15270Sstevel@tonic-gate 	}
15280Sstevel@tonic-gate 
15290Sstevel@tonic-gate 	return (buf);
15300Sstevel@tonic-gate }
15310Sstevel@tonic-gate 
15320Sstevel@tonic-gate /*
15330Sstevel@tonic-gate  * print hsp class errors
15340Sstevel@tonic-gate  */
15350Sstevel@tonic-gate static char *
hsp_to_str(md_error_t * ep,char * buf,size_t size)15360Sstevel@tonic-gate hsp_to_str(
15370Sstevel@tonic-gate 	md_error_t	*ep,
15380Sstevel@tonic-gate 	char		*buf,
15390Sstevel@tonic-gate 	size_t		size
15400Sstevel@tonic-gate )
15410Sstevel@tonic-gate {
15420Sstevel@tonic-gate 	md_hsp_error_t	*ip = &ep->info.md_error_info_t_u.hsp_error;
15430Sstevel@tonic-gate 	char		*p = buf + strlen(buf);
15440Sstevel@tonic-gate 	size_t		psize = size - strlen(buf);
15450Sstevel@tonic-gate 
15460Sstevel@tonic-gate 	switch (ip->errnum) {
15470Sstevel@tonic-gate 	case MDE_HSP_CREATE_FAILURE:
15480Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15490Sstevel@tonic-gate 		    "hotspare pool database create failure"));
15500Sstevel@tonic-gate 		break;
15510Sstevel@tonic-gate 	case MDE_HSP_IN_USE:
15520Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15530Sstevel@tonic-gate 		    "hotspare pool in use"));
15540Sstevel@tonic-gate 		break;
15550Sstevel@tonic-gate 	case MDE_INVAL_HSP:
15560Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15570Sstevel@tonic-gate 		    "invalid hotspare pool"));
15580Sstevel@tonic-gate 		break;
15590Sstevel@tonic-gate 	case MDE_HSP_BUSY:
15600Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15610Sstevel@tonic-gate 		    "hotspare pool is busy"));
15620Sstevel@tonic-gate 		break;
15630Sstevel@tonic-gate 	case MDE_HSP_REF:
15640Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15650Sstevel@tonic-gate 		    "hotspare pool is referenced"));
15660Sstevel@tonic-gate 		break;
15670Sstevel@tonic-gate 	case MDE_HSP_ALREADY_SETUP:
15680Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15690Sstevel@tonic-gate 		    "hotspare pool is already setup"));
15700Sstevel@tonic-gate 		break;
15710Sstevel@tonic-gate 	case MDE_BAD_HSP:
15720Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15730Sstevel@tonic-gate 		    "invalid hotspare pool configuration"));
15740Sstevel@tonic-gate 		break;
15750Sstevel@tonic-gate 	case MDE_HSP_UNIT_TOO_LARGE:
15760Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15770Sstevel@tonic-gate 		    "units in the hotspare pool cannot exceed 1 TByte"));
15780Sstevel@tonic-gate 		break;
15790Sstevel@tonic-gate 	default:
15800Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
15810Sstevel@tonic-gate 		    "unknown hsp error code %d"), ip->errnum);
15820Sstevel@tonic-gate 		break;
15830Sstevel@tonic-gate 	}
15840Sstevel@tonic-gate 
15850Sstevel@tonic-gate 	return (buf);
15860Sstevel@tonic-gate }
15870Sstevel@tonic-gate 
15880Sstevel@tonic-gate /*
15890Sstevel@tonic-gate  * print hs class errors
15900Sstevel@tonic-gate  */
15910Sstevel@tonic-gate static char *
hs_to_str(md_error_t * ep,char * buf,size_t size)15920Sstevel@tonic-gate hs_to_str(
15930Sstevel@tonic-gate 	md_error_t	*ep,
15940Sstevel@tonic-gate 	char		*buf,
15950Sstevel@tonic-gate 	size_t		size
15960Sstevel@tonic-gate )
15970Sstevel@tonic-gate {
15980Sstevel@tonic-gate 	md_hs_error_t	*ip = &ep->info.md_error_info_t_u.hs_error;
15990Sstevel@tonic-gate 	char		*p = buf + strlen(buf);
16000Sstevel@tonic-gate 	size_t		psize = size - strlen(buf);
16010Sstevel@tonic-gate 
16020Sstevel@tonic-gate 	switch (ip->errnum) {
16030Sstevel@tonic-gate 	case MDE_HS_RESVD:
16040Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16050Sstevel@tonic-gate 		    "hotspare is in use"));
16060Sstevel@tonic-gate 		break;
16070Sstevel@tonic-gate 	case MDE_HS_CREATE_FAILURE:
16080Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16090Sstevel@tonic-gate 		    "hotspare database create failure"));
16100Sstevel@tonic-gate 		break;
16110Sstevel@tonic-gate 	case MDE_HS_INUSE:
16120Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16130Sstevel@tonic-gate 		    "add or replace failed, hot spare is already in use"));
16140Sstevel@tonic-gate 		break;
16150Sstevel@tonic-gate 	case MDE_HS_UNIT_TOO_LARGE:
16160Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16170Sstevel@tonic-gate 		    "hotspare size cannot exceed 1 TByte"));
16180Sstevel@tonic-gate 		break;
16190Sstevel@tonic-gate 	default:
16200Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16210Sstevel@tonic-gate 		    "unknown hs error code %d"), ip->errnum);
16220Sstevel@tonic-gate 		break;
16230Sstevel@tonic-gate 	}
16240Sstevel@tonic-gate 
16250Sstevel@tonic-gate 	return (buf);
16260Sstevel@tonic-gate }
16270Sstevel@tonic-gate 
16280Sstevel@tonic-gate /*
16290Sstevel@tonic-gate  * print mddb class errors
16300Sstevel@tonic-gate  */
16310Sstevel@tonic-gate static char *
mddb_to_str(md_error_t * ep,char * buf,size_t size)16320Sstevel@tonic-gate mddb_to_str(
16330Sstevel@tonic-gate 	md_error_t	*ep,
16340Sstevel@tonic-gate 	char		*buf,
16350Sstevel@tonic-gate 	size_t		size
16360Sstevel@tonic-gate )
16370Sstevel@tonic-gate {
16380Sstevel@tonic-gate 	md_mddb_error_t	*ip = &ep->info.md_error_info_t_u.mddb_error;
16390Sstevel@tonic-gate 	char		*p = buf + strlen(buf);
16400Sstevel@tonic-gate 	size_t		psize = size - strlen(buf);
16410Sstevel@tonic-gate 
16420Sstevel@tonic-gate 	switch (ip->errnum) {
16430Sstevel@tonic-gate 	case MDE_TOOMANY_REPLICAS:
16440Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16450Sstevel@tonic-gate 	"%d metadevice database replicas is too many; the maximum is %d"),
16460Sstevel@tonic-gate 		    ip->size, MDDB_NLB);
16470Sstevel@tonic-gate 		break;
16480Sstevel@tonic-gate 	case MDE_REPLICA_TOOSMALL:
16490Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16500Sstevel@tonic-gate 	"device size %d is too small for metadevice database replica"),
16510Sstevel@tonic-gate 		    ip->size);
16520Sstevel@tonic-gate 		break;
16530Sstevel@tonic-gate 	case MDE_NOTVERIFIED:
16540Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16550Sstevel@tonic-gate 		    "data not returned correctly from disk"));
16560Sstevel@tonic-gate 		break;
16570Sstevel@tonic-gate 	case MDE_DB_INVALID:
16580Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16590Sstevel@tonic-gate 		    "invalid argument"));
16600Sstevel@tonic-gate 		break;
16610Sstevel@tonic-gate 	case MDE_DB_EXISTS:
16620Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16630Sstevel@tonic-gate 		    "metadevice database replica exists on device"));
16640Sstevel@tonic-gate 		break;
16650Sstevel@tonic-gate 	case MDE_DB_MASTER:
16660Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16670Sstevel@tonic-gate 		    "has bad master block on device"));
16680Sstevel@tonic-gate 		break;
16690Sstevel@tonic-gate 	case MDE_DB_TOOSMALL:
16700Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16710Sstevel@tonic-gate 		    "device is too small"));
16720Sstevel@tonic-gate 		break;
16730Sstevel@tonic-gate 	case MDE_DB_NORECORD:
16740Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16750Sstevel@tonic-gate 		    "no such metadevice database record"));
16760Sstevel@tonic-gate 		break;
16770Sstevel@tonic-gate 	case MDE_DB_NOSPACE:
16780Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16790Sstevel@tonic-gate 		    "metadevice database is full, can't create new records"));
16800Sstevel@tonic-gate 		break;
16810Sstevel@tonic-gate 	case MDE_DB_NOTNOW:
16820Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16830Sstevel@tonic-gate 		    "metadevice database has too few replicas, for "
16840Sstevel@tonic-gate 		    "metadevice database operation"));
16850Sstevel@tonic-gate 		break;
16860Sstevel@tonic-gate 	case MDE_DB_NODB:
16870Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16880Sstevel@tonic-gate 		    "there are no existing databases"));
16890Sstevel@tonic-gate 		break;
16900Sstevel@tonic-gate 	case MDE_DB_NOTOWNER:
16910Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16920Sstevel@tonic-gate 		    "not owner of metadevice database"));
16930Sstevel@tonic-gate 		break;
16940Sstevel@tonic-gate 	case MDE_DB_STALE:
16950Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
16960Sstevel@tonic-gate 		    "stale databases"));
16970Sstevel@tonic-gate 		break;
16980Sstevel@tonic-gate 	case MDE_DB_TOOFEW:
16990Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17000Sstevel@tonic-gate 		    "not enough databases"));
17010Sstevel@tonic-gate 		break;
17020Sstevel@tonic-gate 	case MDE_DB_TAGDATA:
17030Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17040Sstevel@tonic-gate 		    "tagged data detected, user intervention required"));
17050Sstevel@tonic-gate 		break;
17060Sstevel@tonic-gate 	case MDE_DB_ACCOK:
17070Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17080Sstevel@tonic-gate 		    "50% replicas & 50% mediator hosts available, "
17090Sstevel@tonic-gate 		    "user intervention required"));
17100Sstevel@tonic-gate 		break;
17110Sstevel@tonic-gate 	case MDE_DB_NTAGDATA:
17120Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17130Sstevel@tonic-gate 		    "no tagged data available or only one tag found"));
17140Sstevel@tonic-gate 		break;
17150Sstevel@tonic-gate 	case MDE_DB_ACCNOTOK:
17160Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17170Sstevel@tonic-gate 		    "50% replicas & 50% mediator hosts not available"));
17180Sstevel@tonic-gate 		break;
17190Sstevel@tonic-gate 	case MDE_DB_NOLOCBLK:
17200Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17210Sstevel@tonic-gate 		    "no valid locator blocks were found"));
17220Sstevel@tonic-gate 		break;
17230Sstevel@tonic-gate 	case MDE_DB_NOLOCNMS:
17240Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17250Sstevel@tonic-gate 		    "no valid locator name information was found"));
17260Sstevel@tonic-gate 		break;
17270Sstevel@tonic-gate 	case MDE_DB_NODIRBLK:
17280Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17290Sstevel@tonic-gate 		    "no valid directory blocks were found"));
17300Sstevel@tonic-gate 		break;
17310Sstevel@tonic-gate 	case MDE_DB_NOTAGREC:
17320Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17330Sstevel@tonic-gate 		    "no tag record was allocated, so data "
17340Sstevel@tonic-gate 		    "tagging is disabled"));
17350Sstevel@tonic-gate 		break;
17360Sstevel@tonic-gate 	case MDE_DB_NOTAG:
17370Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17380Sstevel@tonic-gate 		    "no tag records exist or no matching tag was found"));
17390Sstevel@tonic-gate 		break;
17400Sstevel@tonic-gate 	case MDE_DB_BLKRANGE:
17410Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17420Sstevel@tonic-gate 		    "logical block number %d out of range"), ip->size);
17430Sstevel@tonic-gate 		break;
17440Sstevel@tonic-gate 	default:
17450Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17460Sstevel@tonic-gate 		    "unknown mddb error code %d"), ip->errnum);
17470Sstevel@tonic-gate 		break;
17480Sstevel@tonic-gate 	}
17490Sstevel@tonic-gate 
17500Sstevel@tonic-gate 	return (buf);
17510Sstevel@tonic-gate }
17520Sstevel@tonic-gate 
17530Sstevel@tonic-gate /*
17540Sstevel@tonic-gate  * print diskset (ds) class errors
17550Sstevel@tonic-gate  */
17560Sstevel@tonic-gate static char *
ds_to_str(md_error_t * ep,char * buf,size_t size)17570Sstevel@tonic-gate ds_to_str(
17580Sstevel@tonic-gate 	md_error_t	*ep,
17590Sstevel@tonic-gate 	char		*buf,
17600Sstevel@tonic-gate 	size_t		size
17610Sstevel@tonic-gate )
17620Sstevel@tonic-gate {
17630Sstevel@tonic-gate 	md_ds_error_t	*ip = &ep->info.md_error_info_t_u.ds_error;
17640Sstevel@tonic-gate 	char		*p = buf + strlen(buf);
17650Sstevel@tonic-gate 	size_t		psize = size - strlen(buf);
17660Sstevel@tonic-gate 
17670Sstevel@tonic-gate 	switch (ip->errnum) {
17680Sstevel@tonic-gate 	case MDE_DS_DUPHOST:
17690Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17700Sstevel@tonic-gate 		    "host %s is specified more than once"), ip->node);
17710Sstevel@tonic-gate 		break;
17720Sstevel@tonic-gate 	case MDE_DS_NOTNODENAME:
17730Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17740Sstevel@tonic-gate 		    "\"%s\" is not a nodename, but a network name"), ip->node);
17750Sstevel@tonic-gate 		break;
17760Sstevel@tonic-gate 	case MDE_DS_SELFNOTIN:
17770Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17780Sstevel@tonic-gate 		    "nodename of host %s creating the set must be included"),
17790Sstevel@tonic-gate 		    ip->node);
17800Sstevel@tonic-gate 		break;
17810Sstevel@tonic-gate 	case MDE_DS_NODEHASSET:
17820Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17830Sstevel@tonic-gate 		    "host %s already has set"), ip->node);
17840Sstevel@tonic-gate 		break;
17850Sstevel@tonic-gate 	case MDE_DS_NODENOSET:
17860Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17870Sstevel@tonic-gate 		    "host %s does not have set"), ip->node);
17880Sstevel@tonic-gate 		break;
17890Sstevel@tonic-gate 	case MDE_DS_NOOWNER:
17900Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17910Sstevel@tonic-gate 		    "must be owner of the set for this command"));
17920Sstevel@tonic-gate 		break;
17930Sstevel@tonic-gate 	case MDE_DS_NOTOWNER:
17940Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
17950Sstevel@tonic-gate 		    "only the current owner %s may operate on this set"),
17960Sstevel@tonic-gate 		    ip->node);
17970Sstevel@tonic-gate 		break;
17980Sstevel@tonic-gate 	case MDE_DS_NODEISNOTOWNER:
17990Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18000Sstevel@tonic-gate 		    "host %s is not the owner"), ip->node);
18010Sstevel@tonic-gate 		break;
18020Sstevel@tonic-gate 	case MDE_DS_NODEINSET:
18030Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18040Sstevel@tonic-gate 		    "host %s is already in the set"), ip->node);
18050Sstevel@tonic-gate 		break;
18060Sstevel@tonic-gate 	case MDE_DS_NODENOTINSET:
18070Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18080Sstevel@tonic-gate 		    "host %s is not in the set"), ip->node);
18090Sstevel@tonic-gate 		break;
18100Sstevel@tonic-gate 	case MDE_DS_SETNUMBUSY:
18110Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18120Sstevel@tonic-gate 		    "host %s already has a set numbered %ld"),
18130Sstevel@tonic-gate 		    ip->node, ip->setno);
18140Sstevel@tonic-gate 		break;
18150Sstevel@tonic-gate 	case MDE_DS_SETNUMNOTAVAIL:
18160Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18170Sstevel@tonic-gate 		    "no available set numbers"));
18180Sstevel@tonic-gate 		break;
18190Sstevel@tonic-gate 	case MDE_DS_SETNAMEBUSY:
18200Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18210Sstevel@tonic-gate 		    "set name is in-use or invalid on host %s"), ip->node);
18220Sstevel@tonic-gate 		break;
18230Sstevel@tonic-gate 	case MDE_DS_DRIVENOTCOMMON:
18240Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18250Sstevel@tonic-gate 		    "drive %s is not common with host %s"),
18260Sstevel@tonic-gate 		    ip->drive, ip->node);
18270Sstevel@tonic-gate 		break;
18280Sstevel@tonic-gate 	case MDE_DS_DRIVEINSET:
18290Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18300Sstevel@tonic-gate 		    "drive %s is in set %s"), ip->drive, ip->node);
18310Sstevel@tonic-gate 		break;
18320Sstevel@tonic-gate 	case MDE_DS_DRIVENOTINSET:
18330Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18340Sstevel@tonic-gate 		    "drive %s is not in set"), ip->drive);
18350Sstevel@tonic-gate 		break;
18360Sstevel@tonic-gate 	case MDE_DS_DRIVEINUSE:
18370Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18380Sstevel@tonic-gate 		    "drive %s is in use"), ip->drive);
18390Sstevel@tonic-gate 		break;
18400Sstevel@tonic-gate 	case MDE_DS_DUPDRIVE:
18410Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18420Sstevel@tonic-gate 		    "drive %s is specified more than once"), ip->drive);
18430Sstevel@tonic-gate 		break;
18440Sstevel@tonic-gate 	case MDE_DS_INVALIDSETNAME:
18450Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18460Sstevel@tonic-gate 		    "set name contains invalid characters"));
18470Sstevel@tonic-gate 		break;
18480Sstevel@tonic-gate 	case MDE_DS_HASDRIVES:
18490Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18500Sstevel@tonic-gate 		    "unable to delete set, it still has drives"));
18510Sstevel@tonic-gate 		break;
18520Sstevel@tonic-gate 	case MDE_DS_SIDENUMNOTAVAIL:
18530Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18540Sstevel@tonic-gate 		    "maximum number of nodenames exceeded"));
18550Sstevel@tonic-gate 		break;
18560Sstevel@tonic-gate 	case MDE_DS_SETNAMETOOLONG:
18570Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18580Sstevel@tonic-gate 		    "set name is too long"));
18590Sstevel@tonic-gate 		break;
18600Sstevel@tonic-gate 	case MDE_DS_NODENAMETOOLONG:
18610Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18620Sstevel@tonic-gate 		    "host name %s is too long"), ip->node);
18630Sstevel@tonic-gate 		break;
18640Sstevel@tonic-gate 	case MDE_DS_OHACANTDELSELF:
18650Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18660Sstevel@tonic-gate "administrator host %s deletion disallowed in one host admin mode"),
18670Sstevel@tonic-gate 		    ip->node);
18680Sstevel@tonic-gate 		break;
18690Sstevel@tonic-gate 	case MDE_DS_HOSTNOSIDE:
18700Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18710Sstevel@tonic-gate 		    "side information missing for host %s"), ip->node);
18720Sstevel@tonic-gate 		break;
18730Sstevel@tonic-gate 	case MDE_DS_SETLOCKED:
18740Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18750Sstevel@tonic-gate 	    "host %s is modifying set - try later or restart rpc.metad"),
18760Sstevel@tonic-gate 		    ip->drive);
18770Sstevel@tonic-gate 		break;
18780Sstevel@tonic-gate 	case MDE_DS_ULKSBADKEY:
18790Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18800Sstevel@tonic-gate 		    "set unlock failed - bad key"));
18810Sstevel@tonic-gate 		break;
18820Sstevel@tonic-gate 	case MDE_DS_LKSBADKEY:
18830Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18840Sstevel@tonic-gate 		    "set lock failed - bad key"));
18850Sstevel@tonic-gate 		break;
18860Sstevel@tonic-gate 	case MDE_DS_WRITEWITHSULK:
18870Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18880Sstevel@tonic-gate 		    "write operation attempted on set with set unlocked"));
18890Sstevel@tonic-gate 		break;
18900Sstevel@tonic-gate 	case MDE_DS_SETCLEANUP:
18910Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18920Sstevel@tonic-gate 		    "set \"%s\" is out of date - cleaning up - take failed"),
18930Sstevel@tonic-gate 		    ip->node);
18940Sstevel@tonic-gate 		break;
18950Sstevel@tonic-gate 	case MDE_DS_CANTDELSELF:
18960Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
18970Sstevel@tonic-gate "administrator host %s can't be deleted, other hosts still in set\n"
18980Sstevel@tonic-gate "Use -f to override"), ip->node);
18990Sstevel@tonic-gate 		break;
19000Sstevel@tonic-gate 	case MDE_DS_HASMED:
19010Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19020Sstevel@tonic-gate 		    "unable to delete set, it still has mediator hosts"));
19030Sstevel@tonic-gate 		break;
19040Sstevel@tonic-gate 	case MDE_DS_TOOMANYALIAS:
19050Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19060Sstevel@tonic-gate 		    "%s causes there to be more aliases than allowed"),
19070Sstevel@tonic-gate 		    ip->node);
19080Sstevel@tonic-gate 		break;
19090Sstevel@tonic-gate 	case MDE_DS_ISMED:
19100Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19110Sstevel@tonic-gate 		    "%s is already a mediator host"), ip->node);
19120Sstevel@tonic-gate 		break;
19130Sstevel@tonic-gate 	case MDE_DS_ISNOTMED:
19140Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19150Sstevel@tonic-gate 		    "%s is not a mediator host"), ip->node);
19160Sstevel@tonic-gate 		break;
19170Sstevel@tonic-gate 	case MDE_DS_INVALIDMEDNAME:
19180Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19190Sstevel@tonic-gate 		    "mediator name \"%s\" contains invalid characters"),
19200Sstevel@tonic-gate 		    ip->node);
19210Sstevel@tonic-gate 		break;
19220Sstevel@tonic-gate 	case MDE_DS_ALIASNOMATCH:
19230Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19240Sstevel@tonic-gate 		    "mediator alias \"%s\" is not an alias for host "
19250Sstevel@tonic-gate 		    "\"%s\""), ip->node, ip->drive);
19260Sstevel@tonic-gate 		break;
19270Sstevel@tonic-gate 	case MDE_DS_NOMEDONHOST:
19280Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19290Sstevel@tonic-gate 		    "unable to contact %s on host \"%s\""),
19300Sstevel@tonic-gate 		    MED_SERVNAME, ip->node);
19310Sstevel@tonic-gate 		break;
19320Sstevel@tonic-gate 	case MDE_DS_DRIVENOTONHOST:
19330Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19340Sstevel@tonic-gate 		    "drive %s is not present on host %s"),
19350Sstevel@tonic-gate 		    ip->drive, ip->node);
19360Sstevel@tonic-gate 		break;
19370Sstevel@tonic-gate 	case MDE_DS_CANTDELMASTER:
19380Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19390Sstevel@tonic-gate 		    "master %s can't be deleted, other hosts still in set"),
19400Sstevel@tonic-gate 		    ip->node);
19410Sstevel@tonic-gate 		break;
19420Sstevel@tonic-gate 	case MDE_DS_NOTINMEMBERLIST:
19430Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19440Sstevel@tonic-gate 		    "node %s is not in membership list"),
19450Sstevel@tonic-gate 		    ip->node);
19460Sstevel@tonic-gate 		break;
19470Sstevel@tonic-gate 	case MDE_DS_MNCANTDELSELF:
19480Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19490Sstevel@tonic-gate 		    "host %s can't delete self from multi-owner set\n"
19500Sstevel@tonic-gate 		    "while other hosts still in set"),
19510Sstevel@tonic-gate 		    ip->node);
19520Sstevel@tonic-gate 		break;
19530Sstevel@tonic-gate 	case MDE_DS_RPCVERSMISMATCH:
19540Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19550Sstevel@tonic-gate 		    "host %s does not support multi-owner diskset"),
19560Sstevel@tonic-gate 		    ip->node);
19570Sstevel@tonic-gate 		break;
19580Sstevel@tonic-gate 	case MDE_DS_WITHDRAWMASTER:
19590Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19600Sstevel@tonic-gate 		    "master host %s cannot withdraw from multi-owner diskset "
19610Sstevel@tonic-gate 		    "when other owner nodes are still present in diskset"),
19620Sstevel@tonic-gate 		    ip->node);
19630Sstevel@tonic-gate 		break;
19640Sstevel@tonic-gate 	case MDE_DS_CANTRESNARF:
19650Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19660Sstevel@tonic-gate 		    "imported set could not be loaded"));
19670Sstevel@tonic-gate 		break;
19680Sstevel@tonic-gate 	case MDE_DS_INSUFQUORUM:
19690Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19700Sstevel@tonic-gate 		    "insufficient replica quorum detected. Use "
19710Sstevel@tonic-gate 		    "-f to force import of the set"));
19720Sstevel@tonic-gate 		break;
19730Sstevel@tonic-gate 	case MDE_DS_EXTENDEDNM:
19740Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19750Sstevel@tonic-gate 		    "multiple namespace records detected"));
19760Sstevel@tonic-gate 		break;
19770Sstevel@tonic-gate 	case MDE_DS_COMMDCTL_SUSPEND_NYD:
19780Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19790Sstevel@tonic-gate 		    "rpc.mdcommd on host %s is not yet drained during "
19800Sstevel@tonic-gate 		    "suspend operation"),
19810Sstevel@tonic-gate 		    ip->node);
19820Sstevel@tonic-gate 		break;
19830Sstevel@tonic-gate 	case MDE_DS_COMMDCTL_SUSPEND_FAIL:
19840Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19850Sstevel@tonic-gate 		    "rpc.mdcommd on host %s failed suspend operation"),
19860Sstevel@tonic-gate 		    ip->node);
19870Sstevel@tonic-gate 		break;
19880Sstevel@tonic-gate 	case MDE_DS_COMMDCTL_REINIT_FAIL:
19890Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19900Sstevel@tonic-gate 		    "rpc.mdcommd on host %s failed reinitialization operation"),
19910Sstevel@tonic-gate 		    ip->node);
19920Sstevel@tonic-gate 		break;
19930Sstevel@tonic-gate 	case MDE_DS_COMMDCTL_RESUME_FAIL:
19940Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
19950Sstevel@tonic-gate 		    "rpc.mdcommd on host %s failed resume operation"),
19960Sstevel@tonic-gate 		    ip->node);
19970Sstevel@tonic-gate 		break;
19980Sstevel@tonic-gate 	case MDE_DS_NOTNOW_RECONFIG:
19990Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
20000Sstevel@tonic-gate 		    "command terminated, host %s starting reconfig cycle"),
20010Sstevel@tonic-gate 		    ip->node);
20020Sstevel@tonic-gate 		break;
20030Sstevel@tonic-gate 	case MDE_DS_NOTNOW_CMD:
20040Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
20050Sstevel@tonic-gate 		    "metaset or metadb command already running on diskset "
20060Sstevel@tonic-gate 		    "on host %s"), ip->node);
20070Sstevel@tonic-gate 		break;
20080Sstevel@tonic-gate 	case MDE_DS_COMMD_SEND_FAIL:
20090Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
20100Sstevel@tonic-gate 		    "rpc.mdcommd on host %s failed operation"),
20110Sstevel@tonic-gate 		    ip->node);
20120Sstevel@tonic-gate 		break;
20130Sstevel@tonic-gate 	case MDE_DS_MASTER_ONLY:
20140Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
20150Sstevel@tonic-gate 		    "this command must be run on the master node of the set,"
20160Sstevel@tonic-gate 		    " which is currently %s"), ip->node);
20170Sstevel@tonic-gate 		break;
20180Sstevel@tonic-gate 	case MDE_DS_SINGLEHOST:
20190Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
20200Sstevel@tonic-gate 		    "diskset is auto-take; cannot accept additional hosts"));
20210Sstevel@tonic-gate 		break;
20220Sstevel@tonic-gate 	case MDE_DS_AUTONOTSET:
20230Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
20240Sstevel@tonic-gate 		    "auto-take is not enabled on diskset"));
20250Sstevel@tonic-gate 		break;
20260Sstevel@tonic-gate 	case MDE_DS_INVALIDDEVID:
20270Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
20280Sstevel@tonic-gate 		    "Invalid device id on drive %s on host %s"), ip->drive,
20290Sstevel@tonic-gate 		    ip->node);
20300Sstevel@tonic-gate 		break;
20310Sstevel@tonic-gate 	case MDE_DS_SETNOTIMP:
20320Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
20330Sstevel@tonic-gate 		    "Unable to import set on node %s"), ip->node);
20340Sstevel@tonic-gate 		break;
20350Sstevel@tonic-gate 	case MDE_DS_NOTSELFIDENTIFY:
20360Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
20370Sstevel@tonic-gate 		    "Drive %s won't be self identifying"), ip->drive);
20380Sstevel@tonic-gate 		break;
20390Sstevel@tonic-gate 	default:
20400Sstevel@tonic-gate 		(void) snprintf(p, psize, dgettext(TEXT_DOMAIN,
20410Sstevel@tonic-gate 		    "unknown diskset error code %d"), ip->errnum);
20420Sstevel@tonic-gate 		break;
20430Sstevel@tonic-gate 	}
20440Sstevel@tonic-gate 
20450Sstevel@tonic-gate 	return (buf);
20460Sstevel@tonic-gate }
20470Sstevel@tonic-gate 
20480Sstevel@tonic-gate /*
20490Sstevel@tonic-gate  * convert error to printable string
20500Sstevel@tonic-gate  */
20510Sstevel@tonic-gate static char *
mde_to_str(md_error_t * ep)20520Sstevel@tonic-gate mde_to_str(
20530Sstevel@tonic-gate 	md_error_t	*ep
20540Sstevel@tonic-gate )
20550Sstevel@tonic-gate {
20560Sstevel@tonic-gate 	static char	buf[BUFSIZ];
20570Sstevel@tonic-gate 	size_t		bufsz;
20580Sstevel@tonic-gate 
20590Sstevel@tonic-gate 	/* intialize buf */
20600Sstevel@tonic-gate 	buf[0] = '\0';
20610Sstevel@tonic-gate 	bufsz  = sizeof (buf);
20620Sstevel@tonic-gate 
20630Sstevel@tonic-gate 	/* class specific */
20640Sstevel@tonic-gate 	switch (ep->info.errclass) {
20650Sstevel@tonic-gate 	case MDEC_VOID:
20660Sstevel@tonic-gate 		return (void_to_str(ep, buf, bufsz));
20670Sstevel@tonic-gate 	case MDEC_SYS:
20680Sstevel@tonic-gate 		return (sys_to_str(ep, buf, bufsz));
20690Sstevel@tonic-gate 	case MDEC_RPC:
20700Sstevel@tonic-gate 		return (rpc_to_str(ep, buf, bufsz));
20710Sstevel@tonic-gate 	case MDEC_DEV:
20720Sstevel@tonic-gate 		return (dev_to_str(ep, buf, bufsz));
20730Sstevel@tonic-gate 	case MDEC_USE:
20740Sstevel@tonic-gate 		return (use_to_str(ep, buf, bufsz));
20750Sstevel@tonic-gate 	case MDEC_MD:
20760Sstevel@tonic-gate 		return (md_to_str(ep, buf, bufsz));
20770Sstevel@tonic-gate 	case MDEC_COMP:
20780Sstevel@tonic-gate 		return (comp_to_str(ep, buf, bufsz));
20790Sstevel@tonic-gate 	case MDEC_HSP:
20800Sstevel@tonic-gate 		return (hsp_to_str(ep, buf, bufsz));
20810Sstevel@tonic-gate 	case MDEC_HS:
20820Sstevel@tonic-gate 		return (hs_to_str(ep, buf, bufsz));
20830Sstevel@tonic-gate 	case MDEC_MDDB:
20840Sstevel@tonic-gate 		return (mddb_to_str(ep, buf, bufsz));
20850Sstevel@tonic-gate 	case MDEC_DS:
20860Sstevel@tonic-gate 		return (ds_to_str(ep, buf, bufsz));
20870Sstevel@tonic-gate 	case MDEC_OVERLAP:
20880Sstevel@tonic-gate 		return (overlap_to_str(ep, buf, bufsz));
20890Sstevel@tonic-gate 	default:
20900Sstevel@tonic-gate 		(void) snprintf(buf, bufsz,
20910Sstevel@tonic-gate 		    dgettext(TEXT_DOMAIN, "unknown error class %d"),
20920Sstevel@tonic-gate 		    ep->info.errclass);
20930Sstevel@tonic-gate 		return (buf);
20940Sstevel@tonic-gate 	}
20950Sstevel@tonic-gate }
20960Sstevel@tonic-gate 
20970Sstevel@tonic-gate /*
20980Sstevel@tonic-gate  * print log prefix
20990Sstevel@tonic-gate  */
21000Sstevel@tonic-gate void
md_logpfx(FILE * fp)21010Sstevel@tonic-gate md_logpfx(
21020Sstevel@tonic-gate 	FILE		*fp
21030Sstevel@tonic-gate )
21040Sstevel@tonic-gate {
21050Sstevel@tonic-gate 	time_t		t;
21060Sstevel@tonic-gate 	struct tm	*tm;
21070Sstevel@tonic-gate 	char		buf[100];
21080Sstevel@tonic-gate 
21090Sstevel@tonic-gate 	if ((time(&t) != (time_t)-1) &&
21100Sstevel@tonic-gate 	    ((tm = localtime(&t)) != NULL) &&
21110Sstevel@tonic-gate 	    (strftime(buf, sizeof (buf), (char *)0, tm) < sizeof (buf))) {
21120Sstevel@tonic-gate 		(void) fprintf(fp, "%s: ", buf);
21130Sstevel@tonic-gate 	}
21140Sstevel@tonic-gate 	(void) fprintf(fp, "%s: ", myname);
21150Sstevel@tonic-gate }
21160Sstevel@tonic-gate 
21170Sstevel@tonic-gate /*
21180Sstevel@tonic-gate  * varargs sperror()
21190Sstevel@tonic-gate  */
21200Sstevel@tonic-gate /*PRINTFLIKE2*/
21210Sstevel@tonic-gate static char *
mde_vsperror(md_error_t * ep,const char * fmt,va_list ap)21220Sstevel@tonic-gate mde_vsperror(
21230Sstevel@tonic-gate 	md_error_t	*ep,
21240Sstevel@tonic-gate 	const char	*fmt,
21250Sstevel@tonic-gate 	va_list		ap
21260Sstevel@tonic-gate )
21270Sstevel@tonic-gate {
21280Sstevel@tonic-gate 	static char	buf[BUFSIZ];
21290Sstevel@tonic-gate 	size_t		bufsz = sizeof (buf);
21300Sstevel@tonic-gate 	char		*p = buf;
21310Sstevel@tonic-gate 	char		*host1 = "";
21320Sstevel@tonic-gate 	char		*host2 = "";
21330Sstevel@tonic-gate 	char		*extra1 = "";
21340Sstevel@tonic-gate 	char		*extra2 = "";
21350Sstevel@tonic-gate 	char		*name1 = "";
21360Sstevel@tonic-gate 	char		*name2 = "";
21370Sstevel@tonic-gate 
21380Sstevel@tonic-gate 	/* get stuff */
21390Sstevel@tonic-gate 	if ((ep->host != NULL) && (*(ep->host) != '\0')) {
21400Sstevel@tonic-gate 		host1 = ep->host;
21410Sstevel@tonic-gate 		host2 = ": ";
21420Sstevel@tonic-gate 	}
21430Sstevel@tonic-gate 	if ((ep->extra != NULL) && (*(ep->extra) != '\0')) {
21440Sstevel@tonic-gate 		extra1 = ep->extra;
21450Sstevel@tonic-gate 		extra2 = ": ";
21460Sstevel@tonic-gate 	}
21470Sstevel@tonic-gate 	if ((ep->name != NULL) && (*(ep->name) != '\0')) {
21480Sstevel@tonic-gate 		name1 = ep->name;
21490Sstevel@tonic-gate 		name2 = ": ";
21500Sstevel@tonic-gate 	}
21510Sstevel@tonic-gate 
21520Sstevel@tonic-gate 	/* context */
21530Sstevel@tonic-gate 	(void) snprintf(p, bufsz, "%s%s%s%s%s%s",
21540Sstevel@tonic-gate 	    host1, host2, extra1, extra2, name1, name2);
21550Sstevel@tonic-gate 	p = &buf[strlen(buf)];
21560Sstevel@tonic-gate 	bufsz -= strlen(buf);
21570Sstevel@tonic-gate 
21580Sstevel@tonic-gate 	/* user defined part */
21590Sstevel@tonic-gate 	if ((fmt != NULL) && (*fmt != '\0')) {
21600Sstevel@tonic-gate 		(void) vsnprintf(p, bufsz, fmt, ap);
21610Sstevel@tonic-gate 		p = &buf[strlen(buf)];
21620Sstevel@tonic-gate 		bufsz = sizeof (buf) - strlen(buf);
21630Sstevel@tonic-gate 		(void) snprintf(p, bufsz, ": ");
21640Sstevel@tonic-gate 		p = &buf[strlen(buf)];
21650Sstevel@tonic-gate 		bufsz = sizeof (buf) - strlen(buf);
21660Sstevel@tonic-gate 	}
21670Sstevel@tonic-gate 
21680Sstevel@tonic-gate 	/* error code */
21690Sstevel@tonic-gate 	(void) snprintf(p, bufsz, "%s\n", mde_to_str(ep));
21700Sstevel@tonic-gate 
21710Sstevel@tonic-gate 	/* return error message */
21720Sstevel@tonic-gate 	return (buf);
21730Sstevel@tonic-gate }
21740Sstevel@tonic-gate 
21750Sstevel@tonic-gate /*
21760Sstevel@tonic-gate  * printf-like sperror()
21770Sstevel@tonic-gate  */
21780Sstevel@tonic-gate /*PRINTFLIKE2*/
21790Sstevel@tonic-gate char *
mde_sperror(md_error_t * ep,const char * fmt,...)21800Sstevel@tonic-gate mde_sperror(
21810Sstevel@tonic-gate 	md_error_t	*ep,
21820Sstevel@tonic-gate 	const char	*fmt,
21830Sstevel@tonic-gate 	...
21840Sstevel@tonic-gate )
21850Sstevel@tonic-gate {
21860Sstevel@tonic-gate 	va_list		ap;
21870Sstevel@tonic-gate 	char		*emsg;
21880Sstevel@tonic-gate 
21890Sstevel@tonic-gate 	va_start(ap, fmt);
21900Sstevel@tonic-gate 	emsg = mde_vsperror(ep, fmt, ap);
21910Sstevel@tonic-gate 	va_end(ap);
21920Sstevel@tonic-gate 	return (emsg);
21930Sstevel@tonic-gate }
21940Sstevel@tonic-gate 
21950Sstevel@tonic-gate /*
21960Sstevel@tonic-gate  * printf-like perror()
21970Sstevel@tonic-gate  */
21980Sstevel@tonic-gate /*PRINTFLIKE2*/
21990Sstevel@tonic-gate void
mde_perror(md_error_t * ep,const char * fmt,...)22000Sstevel@tonic-gate mde_perror(
22010Sstevel@tonic-gate 	md_error_t	*ep,
22020Sstevel@tonic-gate 	const char	*fmt,
22030Sstevel@tonic-gate 	...
22040Sstevel@tonic-gate )
22050Sstevel@tonic-gate {
22060Sstevel@tonic-gate 	va_list		ap;
22070Sstevel@tonic-gate 	char		*emsg;
22080Sstevel@tonic-gate 
22090Sstevel@tonic-gate 	/* get error message */
22100Sstevel@tonic-gate 	va_start(ap, fmt);
22110Sstevel@tonic-gate 	emsg = mde_vsperror(ep, fmt, ap);
22120Sstevel@tonic-gate 	va_end(ap);
22130Sstevel@tonic-gate 	assert((emsg != NULL) && (*emsg != '\0'));
22140Sstevel@tonic-gate 
22150Sstevel@tonic-gate 	/* stderr */
22160Sstevel@tonic-gate 	(void) fprintf(stderr, "%s: %s\n", myname, emsg);
22170Sstevel@tonic-gate 	(void) fflush(stderr);
22180Sstevel@tonic-gate 
22190Sstevel@tonic-gate 	/* metalog */
22200Sstevel@tonic-gate 	if (metalogfp != NULL) {
22210Sstevel@tonic-gate 		md_logpfx(metalogfp);
22220Sstevel@tonic-gate 		(void) fprintf(metalogfp, "%s\n", emsg);
22230Sstevel@tonic-gate 		(void) fflush(metalogfp);
22240Sstevel@tonic-gate 		(void) fsync(fileno(metalogfp));
22250Sstevel@tonic-gate 	}
22260Sstevel@tonic-gate 
22270Sstevel@tonic-gate 	/* syslog */
22280Sstevel@tonic-gate 	if (metasyslog) {
22290Sstevel@tonic-gate 		syslog(LOG_ERR, emsg);
22300Sstevel@tonic-gate 	}
22310Sstevel@tonic-gate }
22320Sstevel@tonic-gate 
22330Sstevel@tonic-gate /*
22340Sstevel@tonic-gate  * printf-like perror()
22350Sstevel@tonic-gate  */
22360Sstevel@tonic-gate /*PRINTFLIKE1*/
22370Sstevel@tonic-gate void
md_perror(const char * fmt,...)22380Sstevel@tonic-gate md_perror(
22390Sstevel@tonic-gate 	const char	*fmt,
22400Sstevel@tonic-gate 	...
22410Sstevel@tonic-gate )
22420Sstevel@tonic-gate {
22430Sstevel@tonic-gate 	md_error_t	status = mdnullerror;
22440Sstevel@tonic-gate 	va_list		ap;
22450Sstevel@tonic-gate 	char		*emsg;
22460Sstevel@tonic-gate 
22470Sstevel@tonic-gate 	/* get error message */
22480Sstevel@tonic-gate 	(void) mdsyserror(&status, errno, NULL);
22490Sstevel@tonic-gate 	va_start(ap, fmt);
22500Sstevel@tonic-gate 	emsg = mde_vsperror(&status, fmt, ap);
22510Sstevel@tonic-gate 	va_end(ap);
22520Sstevel@tonic-gate 	assert((emsg != NULL) && (*emsg != '\0'));
22530Sstevel@tonic-gate 	mdclrerror(&status);
22540Sstevel@tonic-gate 
22550Sstevel@tonic-gate 	/* stderr */
22560Sstevel@tonic-gate 	(void) fprintf(stderr, "%s: %s\n", myname, emsg);
22570Sstevel@tonic-gate 	(void) fflush(stderr);
22580Sstevel@tonic-gate 
22590Sstevel@tonic-gate 	/* metalog */
22600Sstevel@tonic-gate 	if (metalogfp != NULL) {
22610Sstevel@tonic-gate 		md_logpfx(metalogfp);
22620Sstevel@tonic-gate 		(void) fprintf(metalogfp, "%s\n", emsg);
22630Sstevel@tonic-gate 		(void) fflush(metalogfp);
22640Sstevel@tonic-gate 		(void) fsync(fileno(metalogfp));
22650Sstevel@tonic-gate 	}
22660Sstevel@tonic-gate 
22670Sstevel@tonic-gate 	/* syslog */
22680Sstevel@tonic-gate 	if (metasyslog) {
22690Sstevel@tonic-gate 		syslog(LOG_ERR, emsg);
22700Sstevel@tonic-gate 	}
22710Sstevel@tonic-gate }
22720Sstevel@tonic-gate 
22730Sstevel@tonic-gate /*
22740Sstevel@tonic-gate  * printf-like log
22750Sstevel@tonic-gate  */
22760Sstevel@tonic-gate /*PRINTFLIKE1*/
22770Sstevel@tonic-gate void
md_eprintf(const char * fmt,...)22780Sstevel@tonic-gate md_eprintf(
22790Sstevel@tonic-gate 	const char	*fmt,
22800Sstevel@tonic-gate 	...
22810Sstevel@tonic-gate )
22820Sstevel@tonic-gate {
22830Sstevel@tonic-gate 	va_list		ap;
22840Sstevel@tonic-gate 
22850Sstevel@tonic-gate 	/* begin */
22860Sstevel@tonic-gate 	va_start(ap, fmt);
22870Sstevel@tonic-gate 
22880Sstevel@tonic-gate 	/* stderr */
22890Sstevel@tonic-gate 	(void) fprintf(stderr, "%s: ", myname);
22900Sstevel@tonic-gate 	(void) vfprintf(stderr, fmt, ap);
22910Sstevel@tonic-gate 	(void) fflush(stderr);
22920Sstevel@tonic-gate 
22930Sstevel@tonic-gate 	/* metalog */
22940Sstevel@tonic-gate 	if (metalogfp != NULL) {
22950Sstevel@tonic-gate 		md_logpfx(metalogfp);
22960Sstevel@tonic-gate 		(void) vfprintf(metalogfp, fmt, ap);
22970Sstevel@tonic-gate 		(void) fflush(metalogfp);
22980Sstevel@tonic-gate 		(void) fsync(fileno(metalogfp));
22990Sstevel@tonic-gate 	}
23000Sstevel@tonic-gate 
23010Sstevel@tonic-gate 	/* syslog */
23020Sstevel@tonic-gate 	if (metasyslog) {
23030Sstevel@tonic-gate 		vsyslog(LOG_ERR, fmt, ap);
23040Sstevel@tonic-gate 	}
23050Sstevel@tonic-gate 
23060Sstevel@tonic-gate 	/* end */
23070Sstevel@tonic-gate 	va_end(ap);
23080Sstevel@tonic-gate }
23090Sstevel@tonic-gate 
23100Sstevel@tonic-gate /*
23110Sstevel@tonic-gate  * metaclust timing messages logging routine
23120Sstevel@tonic-gate  *
23130Sstevel@tonic-gate  * level	- The class of the message to be logged. Message will be logged
23140Sstevel@tonic-gate  *		  if this is less than or equal to the verbosity level.
23150Sstevel@tonic-gate  */
23160Sstevel@tonic-gate void
meta_mc_log(int level,const char * fmt,...)23170Sstevel@tonic-gate meta_mc_log(int level, const char *fmt, ...)
23180Sstevel@tonic-gate {
23190Sstevel@tonic-gate 	va_list	args;
23200Sstevel@tonic-gate 
23210Sstevel@tonic-gate 	va_start(args, fmt);
23220Sstevel@tonic-gate 	/*
23230Sstevel@tonic-gate 	 * Log all messages upto MC_LOG2 to syslog regardless of the
23240Sstevel@tonic-gate 	 * verbosity level
23250Sstevel@tonic-gate 	 */
23260Sstevel@tonic-gate 	if (metasyslog && (level <= MC_LOG2)) {
23270Sstevel@tonic-gate 		if (level <= MC_LOG1)
23280Sstevel@tonic-gate 			(void) vsyslog(LOG_ERR, fmt, args);
23290Sstevel@tonic-gate 		else
23300Sstevel@tonic-gate 			(void) vsyslog(LOG_INFO, fmt, args);
23310Sstevel@tonic-gate 	}
23320Sstevel@tonic-gate 	/*
23330Sstevel@tonic-gate 	 * Print all messages to stderr provided the message level is
23340Sstevel@tonic-gate 	 * within the verbosity level
23350Sstevel@tonic-gate 	 */
23360Sstevel@tonic-gate 	if (level <= verbosity) {
23370Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: ", myname);
23380Sstevel@tonic-gate 		(void) vfprintf(stderr, fmt, args);
23390Sstevel@tonic-gate 		(void) fprintf(stderr, "\n");
23400Sstevel@tonic-gate 		(void) fflush(stderr);
23410Sstevel@tonic-gate 	}
23420Sstevel@tonic-gate 	va_end(args);
23430Sstevel@tonic-gate }
2344