xref: /onnv-gate/usr/src/cmd/lvm/metassist/layout/layout_request.c (revision 62:5e51ad5d0496)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*62Sjeanm  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <assert.h>
300Sstevel@tonic-gate #include <string.h>
310Sstevel@tonic-gate #include <libintl.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include "volume_error.h"
340Sstevel@tonic-gate #include "volume_defaults.h"
350Sstevel@tonic-gate #include "volume_dlist.h"
360Sstevel@tonic-gate #include "volume_output.h"
370Sstevel@tonic-gate #include "volume_request.h"
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #include "layout_device_cache.h"
400Sstevel@tonic-gate #include "layout_discovery.h"
410Sstevel@tonic-gate #include "layout_dlist_util.h"
420Sstevel@tonic-gate #include "layout_request.h"
430Sstevel@tonic-gate #include "layout_slice.h"
440Sstevel@tonic-gate #include "layout_validate.h"
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #define	_LAYOUT_REQUEST_C
470Sstevel@tonic-gate 
480Sstevel@tonic-gate static char *_request_diskset = NULL;
490Sstevel@tonic-gate static devconfig_t *_toplevel_request = NULL;
500Sstevel@tonic-gate static defaults_t *_defaults = NULL;
510Sstevel@tonic-gate 
520Sstevel@tonic-gate /*
530Sstevel@tonic-gate  * This file contains code which handles various aspects of the
540Sstevel@tonic-gate  * request and defaults devconfig_t structs passed to the layout
550Sstevel@tonic-gate  * module.
560Sstevel@tonic-gate  *
570Sstevel@tonic-gate  * Functions are provided which determine what devices are available
580Sstevel@tonic-gate  * for use by the various volume layout mechanisms. These are based
590Sstevel@tonic-gate  * on the user specified available/unavailable devices included in
600Sstevel@tonic-gate  * a request or in the defaults associated with the destination diskset.
610Sstevel@tonic-gate  */
620Sstevel@tonic-gate 
630Sstevel@tonic-gate /*
640Sstevel@tonic-gate  * A struct to hold device "specifications" extracted from a user
650Sstevel@tonic-gate  * specified device name.  This struct is used to compare the user's
660Sstevel@tonic-gate  * available and unavailable device specifications against physical
670Sstevel@tonic-gate  * devices attached to the system.
680Sstevel@tonic-gate  *
690Sstevel@tonic-gate  * The spec struct holds one of two different specifications: if the
700Sstevel@tonic-gate  * user supplied device name is parsable as a CTD name, it is parsed
710Sstevel@tonic-gate  * into the component ids.  Otherwise, it is stored as is.
720Sstevel@tonic-gate  *
730Sstevel@tonic-gate  * The CTD name space implies a device hierarchy and metassist
740Sstevel@tonic-gate  * supports an implied wildcarding scheme for the CTD name space.
750Sstevel@tonic-gate  * A CTD specification from the user is of the form cX, cXdX,
760Sstevel@tonic-gate  * cXdXsX, cXtX, cXtXdX, or cXtXdXsX, so it may or may nor
770Sstevel@tonic-gate  * correspond to an individual physical device depending on
780Sstevel@tonic-gate  * the context.
790Sstevel@tonic-gate  *
800Sstevel@tonic-gate  * For example, "c1" can mean the controller/HBA with the
810Sstevel@tonic-gate  * name "c1" or it can mean all devices attached to the
820Sstevel@tonic-gate  * controller named "c1".
830Sstevel@tonic-gate  *
840Sstevel@tonic-gate  * The ctd specs make matching physical devices against a
850Sstevel@tonic-gate  * user specification easier since the matching is based on
860Sstevel@tonic-gate  * the numeric values extracted from the cXtXdXsX string
870Sstevel@tonic-gate  * and not on the strings themselves.  The strings are
880Sstevel@tonic-gate  * troublesome because of situations like "c1" being
890Sstevel@tonic-gate  * compared to "c11t1d0s0" and getting false matches.
900Sstevel@tonic-gate  *
910Sstevel@tonic-gate  * The ID_UNSPECIFIED value is used to flag components
920Sstevel@tonic-gate  * that were not in the CTD name:
930Sstevel@tonic-gate  *
940Sstevel@tonic-gate  * "c3" -> { ctrl=3, target=ID_UNSPECIFIED,
950Sstevel@tonic-gate  *		lun=ID_UNSPECIFIED, slice=ID_UNSPECIFIED }
960Sstevel@tonic-gate  *
970Sstevel@tonic-gate  * "c3t2" -> { ctrl=3, target=2,
980Sstevel@tonic-gate  *		lun=ID_UNSPECIFIED, slice=ID_UNSPECIFIED }
990Sstevel@tonic-gate  */
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate #define	ID_UNSPECIFIED	-1
1020Sstevel@tonic-gate typedef struct {
1030Sstevel@tonic-gate 	int	ctrl;
1040Sstevel@tonic-gate 	int	target;
1050Sstevel@tonic-gate 	int	lun;
1060Sstevel@tonic-gate 	int	slice;
1070Sstevel@tonic-gate 	boolean_t is_ide;
1080Sstevel@tonic-gate } ctd_spec_t;
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate typedef enum {
1110Sstevel@tonic-gate 	SPEC_TYPE_CTD = 0,
1120Sstevel@tonic-gate 	SPEC_TYPE_RAW,
1130Sstevel@tonic-gate 	SPEC_TYPE_OTHER
1140Sstevel@tonic-gate } spec_type_t;
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate typedef struct {
1170Sstevel@tonic-gate 	spec_type_t type;
1180Sstevel@tonic-gate 	union {
1190Sstevel@tonic-gate 		ctd_spec_t *ctd;
1200Sstevel@tonic-gate 		char	*raw;
1210Sstevel@tonic-gate 	} data;
1220Sstevel@tonic-gate } device_spec_t;
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate static int get_spec_for_name(
1250Sstevel@tonic-gate 	char	*name,
1260Sstevel@tonic-gate 	device_spec_t **id);
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate static int create_device_spec(
1290Sstevel@tonic-gate 	char	*name,
1300Sstevel@tonic-gate 	device_spec_t **spec);
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate static int create_device_ctd_spec(
1330Sstevel@tonic-gate 	char	*name,
1340Sstevel@tonic-gate 	device_spec_t **spec);
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate static int create_device_raw_spec(
1370Sstevel@tonic-gate 	char	*name,
1380Sstevel@tonic-gate 	device_spec_t **spec);
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate static void destroy_device_spec(
1410Sstevel@tonic-gate 	device_spec_t *spec);
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate static boolean_t ctd_spec_includes_device(
1440Sstevel@tonic-gate 	device_spec_t *spec,
1450Sstevel@tonic-gate 	device_spec_t *device);
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate static boolean_t raw_spec_includes_device(
1480Sstevel@tonic-gate 	device_spec_t *spec,
1490Sstevel@tonic-gate 	device_spec_t *device);
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate /*
1520Sstevel@tonic-gate  * get_spec_for_name builds up a cached mapping of device
1530Sstevel@tonic-gate  * names to the corresponding device_spec_t structs.
1540Sstevel@tonic-gate  *
1550Sstevel@tonic-gate  * This saves repeatedly converting the device names, which
1560Sstevel@tonic-gate  * could get expensive since devices are checked against the
1570Sstevel@tonic-gate  * user specified available/unavailable devices a lot.
1580Sstevel@tonic-gate  *
1590Sstevel@tonic-gate  * The cache is implemented as a list of these structs:
1600Sstevel@tonic-gate  */
1610Sstevel@tonic-gate typedef struct {
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	char		*name;
1640Sstevel@tonic-gate 	device_spec_t	*device_spec;
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate } spec_cache_t;
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate static dlist_t	*_spec_cache = NULL;
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate static int destroy_spec_cache();
1710Sstevel@tonic-gate static int compare_name_to_spec_cache_name(
1720Sstevel@tonic-gate 	void *name, void *list_item);
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate /*
1750Sstevel@tonic-gate  * The user specified available/unavailable devices are
1760Sstevel@tonic-gate  * accessed frequently during layout. To make this more
1770Sstevel@tonic-gate  * efficient, the char *arrays of available/unavailable
1780Sstevel@tonic-gate  * specifications for a request or defaults devconfig_t
1790Sstevel@tonic-gate  * object are converted to device_spec_ts the first time
1800Sstevel@tonic-gate  * they're accessed and then cached using this struct:
1810Sstevel@tonic-gate  */
1820Sstevel@tonic-gate typedef struct {
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate 	devconfig_t	*request;
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate 	/*
1870Sstevel@tonic-gate 	 * avail_specs_list is a list of device spec_t
1880Sstevel@tonic-gate 	 * corresponding to available devices specified
1890Sstevel@tonic-gate 	 * in the request object
1900Sstevel@tonic-gate 	 */
1910Sstevel@tonic-gate 	dlist_t *avail_specs_list;
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate 	/*
1940Sstevel@tonic-gate 	 * unavail_specs_list is a list of device spec_t
1950Sstevel@tonic-gate 	 * corresponding to unavailable devices specified
1960Sstevel@tonic-gate 	 * in the request object
1970Sstevel@tonic-gate 	 */
1980Sstevel@tonic-gate 	dlist_t *unavail_specs_list;
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate } request_spec_list_t;
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate dlist_t *_request_spec_list_cache = NULL;
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate static int destroy_request_spec_list_cache();
2050Sstevel@tonic-gate static void destroy_request_spec_list_entry(void *obj);
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate static int compare_request_to_request_spec_list_request(
2080Sstevel@tonic-gate 	void *object,
2090Sstevel@tonic-gate 	void *list_item);
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate static int convert_usernames_to_specs(
2120Sstevel@tonic-gate 	char **specs,
2130Sstevel@tonic-gate 	dlist_t **list);
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate /* other private functions */
2160Sstevel@tonic-gate static int is_device_avail(
2170Sstevel@tonic-gate 	dm_descriptor_t	desc,
2180Sstevel@tonic-gate 	devconfig_t	*request,
2190Sstevel@tonic-gate 	boolean_t	*avail);
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate static int is_named_device_avail(
2220Sstevel@tonic-gate 	devconfig_t	*request,
2230Sstevel@tonic-gate 	char		*device_name,
2240Sstevel@tonic-gate 	boolean_t	check_aliases,
2250Sstevel@tonic-gate 	boolean_t	*avail);
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate static int avail_list_includes_device_name(
2280Sstevel@tonic-gate 	dlist_t		*list,
2290Sstevel@tonic-gate 	char		*device_name,
2300Sstevel@tonic-gate 	boolean_t	check_aliases,
2310Sstevel@tonic-gate 	boolean_t	*includes);
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate static int unavail_list_includes_device_name(
2340Sstevel@tonic-gate 	dlist_t		*list,
2350Sstevel@tonic-gate 	char		*device_name,
2360Sstevel@tonic-gate 	boolean_t	check_aliases,
2370Sstevel@tonic-gate 	boolean_t	*includes);
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate static int spec_includes_device_name(
2400Sstevel@tonic-gate 	device_spec_t *spec,
2410Sstevel@tonic-gate 	char		 *device_name,
2420Sstevel@tonic-gate 	boolean_t	check_aliases,
2430Sstevel@tonic-gate 	boolean_t	*includes);
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate static boolean_t spec_includes_device(
2460Sstevel@tonic-gate 	device_spec_t *spec,
2470Sstevel@tonic-gate 	device_spec_t *device);
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate static int disk_get_avail_space(
2500Sstevel@tonic-gate 	devconfig_t	*request,
2510Sstevel@tonic-gate 	dm_descriptor_t disk,
2520Sstevel@tonic-gate 	uint64_t	*avail);
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate static int compare_hba_n_avail_disks(
2550Sstevel@tonic-gate 	void		*obj1,
2560Sstevel@tonic-gate 	void		*obj2);
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate /*
2590Sstevel@tonic-gate  * FUNCTION:	release_request_caches()
2600Sstevel@tonic-gate  *
2610Sstevel@tonic-gate  * RETURNS:	0
2620Sstevel@tonic-gate  *
2630Sstevel@tonic-gate  * PURPOSE:	cleanup the module private caches.
2640Sstevel@tonic-gate  */
2650Sstevel@tonic-gate int
release_request_caches()2660Sstevel@tonic-gate release_request_caches()
2670Sstevel@tonic-gate {
2680Sstevel@tonic-gate 	(void) destroy_request_spec_list_cache();
2690Sstevel@tonic-gate 	(void) destroy_spec_cache();
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate 	return (0);
2720Sstevel@tonic-gate }
2730Sstevel@tonic-gate /*
2740Sstevel@tonic-gate  * FUNCTION:	int set_request_diskset(char *)
2750Sstevel@tonic-gate  *
2760Sstevel@tonic-gate  * INPUT:	char * - pointer to the diskset name
2770Sstevel@tonic-gate  * OUTPUT:	0 - success
2780Sstevel@tonic-gate  *		!0 - validation failure
2790Sstevel@tonic-gate  * RETURNS:
2800Sstevel@tonic-gate  *
2810Sstevel@tonic-gate  * PURPOSE:	set the module global diskset name.
2820Sstevel@tonic-gate  */
2830Sstevel@tonic-gate int
set_request_diskset(char * dsname)2840Sstevel@tonic-gate set_request_diskset(
2850Sstevel@tonic-gate 	char	*dsname)
2860Sstevel@tonic-gate {
2870Sstevel@tonic-gate 	_request_diskset = dsname;
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate 	if (dsname == NULL || dsname[0] == '\0') {
2900Sstevel@tonic-gate 	    volume_set_error(
2910Sstevel@tonic-gate 		    gettext("No disk set specified in request\n"));
2920Sstevel@tonic-gate 	    return (-1);
2930Sstevel@tonic-gate 	}
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate 	return (0);
2960Sstevel@tonic-gate }
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate /*
2990Sstevel@tonic-gate  * FUNCTION:	char *get_request_diskset()
3000Sstevel@tonic-gate  *
3010Sstevel@tonic-gate  * INPUT:	none   -
3020Sstevel@tonic-gate  * OUTPUT:	none   -
3030Sstevel@tonic-gate  * RETURNS:	char * - pointer to the currently set diskset name
3040Sstevel@tonic-gate  *
3050Sstevel@tonic-gate  * PURPOSE:	get the global name of the current diskset.
3060Sstevel@tonic-gate  */
3070Sstevel@tonic-gate char *
get_request_diskset()3080Sstevel@tonic-gate get_request_diskset()
3090Sstevel@tonic-gate {
3100Sstevel@tonic-gate 	return (_request_diskset);
3110Sstevel@tonic-gate }
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate /*
3140Sstevel@tonic-gate  * FUNCTION:	void unset_request_diskset()
3150Sstevel@tonic-gate  *
3160Sstevel@tonic-gate  * PURPOSE:	unset the module global diskset name.
3170Sstevel@tonic-gate  */
3180Sstevel@tonic-gate void
unset_request_diskset(char * dsname)3190Sstevel@tonic-gate unset_request_diskset(
3200Sstevel@tonic-gate 	char	*dsname)
3210Sstevel@tonic-gate {
3220Sstevel@tonic-gate 	_request_diskset = NULL;
3230Sstevel@tonic-gate }
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate /*
3260Sstevel@tonic-gate  * FUNCTION:	int set_toplevel_request(devconfig_t *)
3270Sstevel@tonic-gate  *
3280Sstevel@tonic-gate  * INPUT:	devconfig_t * - pointer to the diskset request
3290Sstevel@tonic-gate  * OUTPUT:	0 - success
3300Sstevel@tonic-gate  *		!0 - validation failure
3310Sstevel@tonic-gate  * RETURNS:
3320Sstevel@tonic-gate  *
3330Sstevel@tonic-gate  * PURPOSE:	set the module global toplevel request struct.
3340Sstevel@tonic-gate  *		this will be set within the only public entry
3350Sstevel@tonic-gate  *		point to the module -- get_layout()
3360Sstevel@tonic-gate  *
3370Sstevel@tonic-gate  * SIDEEFFECT:	The devconfig_t's list of available and unavailable
3380Sstevel@tonic-gate  * 		devices will be validated.
3390Sstevel@tonic-gate  */
3400Sstevel@tonic-gate int
set_toplevel_request(devconfig_t * req)3410Sstevel@tonic-gate set_toplevel_request(
3420Sstevel@tonic-gate 	devconfig_t	*req)
3430Sstevel@tonic-gate {
3440Sstevel@tonic-gate 	_toplevel_request = req;
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate 	return (validate_request_avail_unavail(req));
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate /*
3500Sstevel@tonic-gate  * FUNCTION:	void unset_toplevel_request()
3510Sstevel@tonic-gate  *
3520Sstevel@tonic-gate  * PURPOSE:	unset the layout module global toplevel request struct.
3530Sstevel@tonic-gate  *
3540Sstevel@tonic-gate  */
3550Sstevel@tonic-gate void
unset_toplevel_request()3560Sstevel@tonic-gate unset_toplevel_request()
3570Sstevel@tonic-gate {
3580Sstevel@tonic-gate 	_toplevel_request = NULL;
3590Sstevel@tonic-gate }
3600Sstevel@tonic-gate 
3610Sstevel@tonic-gate /*
3620Sstevel@tonic-gate  * FUNCTION:	int set_defaults(devconfig_t *)
3630Sstevel@tonic-gate  *
3640Sstevel@tonic-gate  * INPUT:	devconfig_t * - pointer to the global defaults devconfig_t
3650Sstevel@tonic-gate  * OUTPUT:	0 - success
3660Sstevel@tonic-gate  *		!0 - validation failure
3670Sstevel@tonic-gate  * RETURNS:
3680Sstevel@tonic-gate  *
3690Sstevel@tonic-gate  * PURPOSE:	set the module global defaults struct.
3700Sstevel@tonic-gate  *		this will be set within the only public entry
3710Sstevel@tonic-gate  *		point to the module -- get_layout()
3720Sstevel@tonic-gate  *
3730Sstevel@tonic-gate  * SIDEEFFECT:	The devconfig_t's list of available and unavailable
3740Sstevel@tonic-gate  * 		devices will be validated.
3750Sstevel@tonic-gate  */
3760Sstevel@tonic-gate int
set_request_defaults(defaults_t * defaults)3770Sstevel@tonic-gate set_request_defaults(
3780Sstevel@tonic-gate 	defaults_t *defaults)
3790Sstevel@tonic-gate {
3800Sstevel@tonic-gate 	int	error = 0;
3810Sstevel@tonic-gate 	devconfig_t *diskset = NULL;
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate 	_defaults = defaults;
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate 	if ((error = defaults_get_diskset_by_name(
3860Sstevel@tonic-gate 	    _defaults, get_request_diskset(), &diskset)) == 0) {
3870Sstevel@tonic-gate 
3880Sstevel@tonic-gate 	    error = validate_request_avail_unavail(diskset);
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate 	} else if (error == ENOENT) {
3910Sstevel@tonic-gate 	    /* no defaults to verify */
3920Sstevel@tonic-gate 	    error = 0;
3930Sstevel@tonic-gate 	}
3940Sstevel@tonic-gate 
3950Sstevel@tonic-gate 	return (error);
3960Sstevel@tonic-gate }
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate /*
3990Sstevel@tonic-gate  * FUNCTION:	void unset_request_defaults()
4000Sstevel@tonic-gate  *
4010Sstevel@tonic-gate  * PURPOSE:	unset the layout module global defaults struct.
4020Sstevel@tonic-gate  *
4030Sstevel@tonic-gate  */
4040Sstevel@tonic-gate void
unset_request_defaults()4050Sstevel@tonic-gate unset_request_defaults()
4060Sstevel@tonic-gate {
4070Sstevel@tonic-gate 	_defaults = NULL;
4080Sstevel@tonic-gate }
4090Sstevel@tonic-gate 
4100Sstevel@tonic-gate /*
4110Sstevel@tonic-gate  * FUNCTION:	get_stripe_min_comp(devconfig_t *req, uint16_t *val)
4120Sstevel@tonic-gate  * INPUT:	req	- a devconfig_t pointer to the current request
4130Sstevel@tonic-gate  *		val	- pointer to a uint64_t to hold the result
4140Sstevel@tonic-gate  *
4150Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
4160Sstevel@tonic-gate  *			  !0 - otherwise
4170Sstevel@tonic-gate  *
4180Sstevel@tonic-gate  * PURPOSE:	helper which determines the minimum of components
4190Sstevel@tonic-gate  *		for striped volumes satisfying the input request.
4200Sstevel@tonic-gate  *
4210Sstevel@tonic-gate  *		The value to use is taken from the input request, the
4220Sstevel@tonic-gate  *		toplevel diskset request, the diskset defaults or the
4230Sstevel@tonic-gate  *		global defaults.
4240Sstevel@tonic-gate  */
4250Sstevel@tonic-gate int
get_stripe_min_comp(devconfig_t * req,uint16_t * val)4260Sstevel@tonic-gate get_stripe_min_comp(
4270Sstevel@tonic-gate 	devconfig_t	*req,
4280Sstevel@tonic-gate 	uint16_t	*val)
4290Sstevel@tonic-gate {
4300Sstevel@tonic-gate 	int		error = 0;
4310Sstevel@tonic-gate 
4320Sstevel@tonic-gate 	*val = 0;
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate 	if ((error = devconfig_get_stripe_mincomp(req, val)) != 0) {
4350Sstevel@tonic-gate 	    if (error != ERR_ATTR_UNSET) {
4360Sstevel@tonic-gate 		return (error);
4370Sstevel@tonic-gate 	    }
4380Sstevel@tonic-gate 	}
4390Sstevel@tonic-gate 
4400Sstevel@tonic-gate 	if (*val == 0) {
4410Sstevel@tonic-gate 	    if ((error = defaults_get_stripe_mincomp(
4420Sstevel@tonic-gate 		_defaults, get_request_diskset(), val)) != 0) {
4430Sstevel@tonic-gate 		if (error != ERR_ATTR_UNSET) {
4440Sstevel@tonic-gate 		    return (error);
4450Sstevel@tonic-gate 		}
4460Sstevel@tonic-gate 	    }
4470Sstevel@tonic-gate 	}
4480Sstevel@tonic-gate 
4490Sstevel@tonic-gate 	return (error);
4500Sstevel@tonic-gate }
4510Sstevel@tonic-gate 
4520Sstevel@tonic-gate /*
4530Sstevel@tonic-gate  * FUNCTION:	get_stripe_max_comp(devconfig_t *req, uint16_t *val)
4540Sstevel@tonic-gate  * INPUT:	req	- a devconfig_t pointer to the current request
4550Sstevel@tonic-gate  *		val	- pointer to a uint64_t to hold the result
4560Sstevel@tonic-gate  *
4570Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
4580Sstevel@tonic-gate  *			  !0 - otherwise
4590Sstevel@tonic-gate  *
4600Sstevel@tonic-gate  * PURPOSE:	helper which determines the maximum number of components
4610Sstevel@tonic-gate  *		for striped volumes satisfying the input request.
4620Sstevel@tonic-gate  *
4630Sstevel@tonic-gate  *		The value to use is taken from the input request, the
4640Sstevel@tonic-gate  *		toplevel diskset request, the diskset defaults or the
4650Sstevel@tonic-gate  *		global defaults.
4660Sstevel@tonic-gate  */
4670Sstevel@tonic-gate int
get_stripe_max_comp(devconfig_t * req,uint16_t * val)4680Sstevel@tonic-gate get_stripe_max_comp(
4690Sstevel@tonic-gate 	devconfig_t	*req,
4700Sstevel@tonic-gate 	uint16_t	*val)
4710Sstevel@tonic-gate {
4720Sstevel@tonic-gate 	int		error = 0;
4730Sstevel@tonic-gate 
4740Sstevel@tonic-gate 	*val = 0;
4750Sstevel@tonic-gate 
4760Sstevel@tonic-gate 	if ((error = devconfig_get_stripe_maxcomp(req, val)) != 0) {
4770Sstevel@tonic-gate 	    if (error != ERR_ATTR_UNSET) {
4780Sstevel@tonic-gate 		return (error);
4790Sstevel@tonic-gate 	    }
4800Sstevel@tonic-gate 	}
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate 	if (*val == 0) {
4830Sstevel@tonic-gate 	    if ((error = defaults_get_stripe_maxcomp(
4840Sstevel@tonic-gate 		_defaults, get_request_diskset(), val)) != 0) {
4850Sstevel@tonic-gate 		if (error != ERR_ATTR_UNSET) {
4860Sstevel@tonic-gate 		    return (error);
4870Sstevel@tonic-gate 		}
4880Sstevel@tonic-gate 	    }
4890Sstevel@tonic-gate 	}
4900Sstevel@tonic-gate 
4910Sstevel@tonic-gate 	return (error);
4920Sstevel@tonic-gate }
4930Sstevel@tonic-gate 
4940Sstevel@tonic-gate /*
4950Sstevel@tonic-gate  * FUNCTION:	get_stripe_interlace(devconfig_t *req, uint64_t *val)
4960Sstevel@tonic-gate  * INPUT:	req	- a devconfig_t pointer to the current request
4970Sstevel@tonic-gate  *		val	- pointer to a uint64_t to hold the result
4980Sstevel@tonic-gate  *
4990Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
5000Sstevel@tonic-gate  *			  !0 - otherwise
5010Sstevel@tonic-gate  *
5020Sstevel@tonic-gate  * PURPOSE:	helper which determines the interlace value for striped
5030Sstevel@tonic-gate  *		volumes satisfying the input request.
5040Sstevel@tonic-gate  *
5050Sstevel@tonic-gate  *		The value to use is taken from the input request, the
5060Sstevel@tonic-gate  *		toplevel diskset request, the diskset defaults or the
5070Sstevel@tonic-gate  *		global defaults.
5080Sstevel@tonic-gate  *
5090Sstevel@tonic-gate  *		If no value is explictly specified, ERR_ATTR_UNSET is
5100Sstevel@tonic-gate  *		returned.
5110Sstevel@tonic-gate  */
5120Sstevel@tonic-gate int
get_stripe_interlace(devconfig_t * req,uint64_t * val)5130Sstevel@tonic-gate get_stripe_interlace(
5140Sstevel@tonic-gate 	devconfig_t	*req,
5150Sstevel@tonic-gate 	uint64_t	*val)
5160Sstevel@tonic-gate {
5170Sstevel@tonic-gate 	int		error = 0;
5180Sstevel@tonic-gate 
5190Sstevel@tonic-gate 	*val = 0;
5200Sstevel@tonic-gate 
5210Sstevel@tonic-gate 	if ((error = devconfig_get_stripe_interlace(req, val)) != 0) {
5220Sstevel@tonic-gate 	    if (error != ERR_ATTR_UNSET) {
5230Sstevel@tonic-gate 		return (error);
5240Sstevel@tonic-gate 	    }
5250Sstevel@tonic-gate 	    error = 0;
5260Sstevel@tonic-gate 	}
5270Sstevel@tonic-gate 
5280Sstevel@tonic-gate 	if (*val == 0) {
5290Sstevel@tonic-gate 	    if ((error = defaults_get_stripe_interlace(
5300Sstevel@tonic-gate 		_defaults, get_request_diskset(), val)) != 0) {
5310Sstevel@tonic-gate 		if (error != ERR_ATTR_UNSET) {
5320Sstevel@tonic-gate 		    return (error);
5330Sstevel@tonic-gate 		}
5340Sstevel@tonic-gate 	    }
5350Sstevel@tonic-gate 	}
5360Sstevel@tonic-gate 
5370Sstevel@tonic-gate 	return (error);
5380Sstevel@tonic-gate }
5390Sstevel@tonic-gate 
5400Sstevel@tonic-gate /*
5410Sstevel@tonic-gate  * FUNCTION:	get_mirror_read_strategy(devconfig_t *req,
5420Sstevel@tonic-gate  *			mirror_read_strategy_t *val)
5430Sstevel@tonic-gate  * INPUT:	req	- a devconfig_t pointer to the current request
5440Sstevel@tonic-gate  *		val	- pointer to a mirror_read_strategy_t to hold the result
5450Sstevel@tonic-gate  *
5460Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
5470Sstevel@tonic-gate  *			  !0 - otherwise
5480Sstevel@tonic-gate  *
5490Sstevel@tonic-gate  * PURPOSE:	helper which determines the write strategy mirrored volumes
5500Sstevel@tonic-gate  *		should have for volumes satisfying the input request.
5510Sstevel@tonic-gate  *
5520Sstevel@tonic-gate  *		The value to use is taken from the input request, the
5530Sstevel@tonic-gate  *		toplevel diskset request, the diskset defaults or the
5540Sstevel@tonic-gate  *		global defaults.
5550Sstevel@tonic-gate  *
5560Sstevel@tonic-gate  *		If no value is explictly specified, ERR_ATTR_UNSET is
5570Sstevel@tonic-gate  *		returned.
5580Sstevel@tonic-gate  */
5590Sstevel@tonic-gate int
get_mirror_read_strategy(devconfig_t * req,mirror_read_strategy_t * val)5600Sstevel@tonic-gate get_mirror_read_strategy(
5610Sstevel@tonic-gate 	devconfig_t	*req,
5620Sstevel@tonic-gate 	mirror_read_strategy_t	*val)
5630Sstevel@tonic-gate {
5640Sstevel@tonic-gate 	int		error = 0;
5650Sstevel@tonic-gate 
5660Sstevel@tonic-gate 	*val = 0;
5670Sstevel@tonic-gate 
5680Sstevel@tonic-gate 	if ((error = devconfig_get_mirror_read(req, val)) != 0) {
5690Sstevel@tonic-gate 	    if (error != ERR_ATTR_UNSET) {
5700Sstevel@tonic-gate 		return (error);
5710Sstevel@tonic-gate 	    }
5720Sstevel@tonic-gate 	}
5730Sstevel@tonic-gate 
5740Sstevel@tonic-gate 	if (*val == 0) {
5750Sstevel@tonic-gate 	    if ((error = defaults_get_mirror_read(
5760Sstevel@tonic-gate 		_defaults, get_request_diskset(), val)) != 0) {
5770Sstevel@tonic-gate 		if (error != ERR_ATTR_UNSET) {
5780Sstevel@tonic-gate 		    return (error);
5790Sstevel@tonic-gate 		}
5800Sstevel@tonic-gate 	    }
5810Sstevel@tonic-gate 	}
5820Sstevel@tonic-gate 
5830Sstevel@tonic-gate 	return (error);
5840Sstevel@tonic-gate }
5850Sstevel@tonic-gate 
5860Sstevel@tonic-gate /*
5870Sstevel@tonic-gate  * FUNCTION:	get_mirror_write_strategy(devconfig_t *req,
5880Sstevel@tonic-gate  *			mirror_write_strategy_t *val)
5890Sstevel@tonic-gate  * INPUT:	req	- a devconfig_t pointer to the current request
5900Sstevel@tonic-gate  *		val	- pointer to a mirror_write_strategy_t to hold result
5910Sstevel@tonic-gate  *
5920Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
5930Sstevel@tonic-gate  *			  !0 - otherwise
5940Sstevel@tonic-gate  *
5950Sstevel@tonic-gate  * PURPOSE:	helper which determines the write strategy mirrored volumes
5960Sstevel@tonic-gate  *		should have for volumes satisfying the input request.
5970Sstevel@tonic-gate  *
5980Sstevel@tonic-gate  *		The value to use is taken from the input request, the
5990Sstevel@tonic-gate  *		toplevel diskset request, the diskset defaults or the
6000Sstevel@tonic-gate  *		global defaults.
6010Sstevel@tonic-gate  *
6020Sstevel@tonic-gate  *		If no value is explictly specified, ERR_ATTR_UNSET is
6030Sstevel@tonic-gate  *		returned.
6040Sstevel@tonic-gate  */
6050Sstevel@tonic-gate int
get_mirror_write_strategy(devconfig_t * req,mirror_write_strategy_t * val)6060Sstevel@tonic-gate get_mirror_write_strategy(
6070Sstevel@tonic-gate 	devconfig_t	*req,
6080Sstevel@tonic-gate 	mirror_write_strategy_t	*val)
6090Sstevel@tonic-gate {
6100Sstevel@tonic-gate 	int		error = 0;
6110Sstevel@tonic-gate 
6120Sstevel@tonic-gate 	*val = 0;
6130Sstevel@tonic-gate 
6140Sstevel@tonic-gate 	if ((error = devconfig_get_mirror_write(req, val)) != 0) {
6150Sstevel@tonic-gate 	    if (error != ERR_ATTR_UNSET) {
6160Sstevel@tonic-gate 		return (error);
6170Sstevel@tonic-gate 	    }
6180Sstevel@tonic-gate 	}
6190Sstevel@tonic-gate 
6200Sstevel@tonic-gate 	if (*val == 0) {
6210Sstevel@tonic-gate 	    if ((error = defaults_get_mirror_write(
6220Sstevel@tonic-gate 		_defaults, get_request_diskset(), val)) != 0) {
6230Sstevel@tonic-gate 		if (error != ERR_ATTR_UNSET) {
6240Sstevel@tonic-gate 		    return (error);
6250Sstevel@tonic-gate 		}
6260Sstevel@tonic-gate 	    }
6270Sstevel@tonic-gate 	}
6280Sstevel@tonic-gate 
6290Sstevel@tonic-gate 	return (error);
6300Sstevel@tonic-gate }
6310Sstevel@tonic-gate 
6320Sstevel@tonic-gate /*
6330Sstevel@tonic-gate  * FUNCTION:	get_mirror_pass(devconfig_t *req, uint16_t *val)
6340Sstevel@tonic-gate  * INPUT:	req	- a devconfig_t pointer to the current request
6350Sstevel@tonic-gate  *		val	- pointer to a uint16_t to hold the result
6360Sstevel@tonic-gate  *
6370Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
6380Sstevel@tonic-gate  *			  !0 - otherwise
6390Sstevel@tonic-gate  *
6400Sstevel@tonic-gate  * PURPOSE:	helper which determines the resync pass mirrored volumes
6410Sstevel@tonic-gate  *		should have for volumes satisfying the input request.
6420Sstevel@tonic-gate  *
6430Sstevel@tonic-gate  *		The value to use is taken from the input request, the
6440Sstevel@tonic-gate  *		toplevel diskset request, the diskset defaults or the
6450Sstevel@tonic-gate  *		global defaults.
6460Sstevel@tonic-gate  *
6470Sstevel@tonic-gate  *		If no value is explictly specified, ERR_ATTR_UNSET is
6480Sstevel@tonic-gate  *		returned.
6490Sstevel@tonic-gate  */
6500Sstevel@tonic-gate int
get_mirror_pass(devconfig_t * req,uint16_t * val)6510Sstevel@tonic-gate get_mirror_pass(
6520Sstevel@tonic-gate 	devconfig_t	*req,
6530Sstevel@tonic-gate 	uint16_t	*val)
6540Sstevel@tonic-gate {
6550Sstevel@tonic-gate 	int		error = 0;
6560Sstevel@tonic-gate 
6570Sstevel@tonic-gate 	*val = 0;
6580Sstevel@tonic-gate 
6590Sstevel@tonic-gate 	if ((error = devconfig_get_mirror_pass(req, val)) != 0) {
6600Sstevel@tonic-gate 	    if (error != ERR_ATTR_UNSET) {
6610Sstevel@tonic-gate 		return (error);
6620Sstevel@tonic-gate 	    }
6630Sstevel@tonic-gate 	}
6640Sstevel@tonic-gate 
6650Sstevel@tonic-gate 	if (*val == 0) {
6660Sstevel@tonic-gate 	    if ((error = defaults_get_mirror_pass(
6670Sstevel@tonic-gate 		_defaults, get_request_diskset(), val)) != 0) {
6680Sstevel@tonic-gate 		if (error != ERR_ATTR_UNSET) {
6690Sstevel@tonic-gate 		    return (error);
6700Sstevel@tonic-gate 		}
6710Sstevel@tonic-gate 	    }
6720Sstevel@tonic-gate 	}
6730Sstevel@tonic-gate 
6740Sstevel@tonic-gate 	return (error);
6750Sstevel@tonic-gate }
6760Sstevel@tonic-gate 
6770Sstevel@tonic-gate /*
6780Sstevel@tonic-gate  * FUNCTION:	get_mirror_nsubs(devconfig_t *req, uint16_t *val)
6790Sstevel@tonic-gate  * INPUT:	req	- a devconfig_t pointer to the current request
6800Sstevel@tonic-gate  *		val	- pointer to a uint16_t to hold the result
6810Sstevel@tonic-gate  *
6820Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
6830Sstevel@tonic-gate  *			  !0 - otherwise
6840Sstevel@tonic-gate  *
6850Sstevel@tonic-gate  * PURPOSE:	helper which determines how many submirrors mirrored
6860Sstevel@tonic-gate  *		volumes should have for volumes satisfying the input
6870Sstevel@tonic-gate  *		request.
6880Sstevel@tonic-gate  *
6890Sstevel@tonic-gate  *		The value to use is taken from the input request, the
6900Sstevel@tonic-gate  *		toplevel diskset request, the diskset defaults or the
6910Sstevel@tonic-gate  *		global defaults.
6920Sstevel@tonic-gate  */
6930Sstevel@tonic-gate int
get_mirror_nsubs(devconfig_t * req,uint16_t * val)6940Sstevel@tonic-gate get_mirror_nsubs(
6950Sstevel@tonic-gate 	devconfig_t	*req,
6960Sstevel@tonic-gate 	uint16_t	*val)
6970Sstevel@tonic-gate {
6980Sstevel@tonic-gate 	int		error = 0;
6990Sstevel@tonic-gate 
7000Sstevel@tonic-gate 	*val = 0;
7010Sstevel@tonic-gate 
7020Sstevel@tonic-gate 	if ((error = devconfig_get_mirror_nsubs(req, val)) != 0) {
7030Sstevel@tonic-gate 	    if (error != ERR_ATTR_UNSET) {
7040Sstevel@tonic-gate 		return (error);
7050Sstevel@tonic-gate 	    }
7060Sstevel@tonic-gate 	}
7070Sstevel@tonic-gate 
7080Sstevel@tonic-gate 	if (*val == 0) {
7090Sstevel@tonic-gate 	    if ((error = defaults_get_mirror_nsubs(
7100Sstevel@tonic-gate 		_defaults, get_request_diskset(), val)) != 0) {
7110Sstevel@tonic-gate 		if (error != ERR_ATTR_UNSET) {
7120Sstevel@tonic-gate 		    return (error);
7130Sstevel@tonic-gate 		}
7140Sstevel@tonic-gate 	    }
7150Sstevel@tonic-gate 	}
7160Sstevel@tonic-gate 
7170Sstevel@tonic-gate 	return (error);
7180Sstevel@tonic-gate }
7190Sstevel@tonic-gate 
7200Sstevel@tonic-gate /*
7210Sstevel@tonic-gate  * FUNCTION:	get_volume_faultrecov(devconfig_t *req, boolean_t *val)
7220Sstevel@tonic-gate  * INPUT:	req	- a devconfig_t pointer to the current request
7230Sstevel@tonic-gate  *		val	- pointer to a boolean_t to hold the result
7240Sstevel@tonic-gate  *
7250Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
7260Sstevel@tonic-gate  *			  !0 - otherwise
7270Sstevel@tonic-gate  *
7280Sstevel@tonic-gate  * PURPOSE:	helper which determines whether data redundant volumes
7290Sstevel@tonic-gate  *		should also have fault recovery (e.g., HSPs) for volumes
7300Sstevel@tonic-gate  *		satisfying the input request.
7310Sstevel@tonic-gate  *
7320Sstevel@tonic-gate  *		The value to use is taken from the input request, the
7330Sstevel@tonic-gate  *		toplevel diskset request, the diskset defaults or the
7340Sstevel@tonic-gate  *		global defaults.
7350Sstevel@tonic-gate  */
7360Sstevel@tonic-gate int
get_volume_faultrecov(devconfig_t * req,boolean_t * val)7370Sstevel@tonic-gate get_volume_faultrecov(
7380Sstevel@tonic-gate 	devconfig_t	*req,
7390Sstevel@tonic-gate 	boolean_t	*val)
7400Sstevel@tonic-gate {
7410Sstevel@tonic-gate 	int		error = 0;
7420Sstevel@tonic-gate 
7430Sstevel@tonic-gate 	*val = B_FALSE;
7440Sstevel@tonic-gate 
7450Sstevel@tonic-gate 	if ((error = devconfig_get_volume_usehsp(req, val)) != 0) {
7460Sstevel@tonic-gate 	    if (error == ERR_ATTR_UNSET) {
7470Sstevel@tonic-gate 		component_type_t	type = TYPE_UNKNOWN;
7480Sstevel@tonic-gate 		(void) devconfig_get_type(req, &type);
7490Sstevel@tonic-gate 
7500Sstevel@tonic-gate 		switch (type) {
7510Sstevel@tonic-gate 		case TYPE_MIRROR:
7520Sstevel@tonic-gate 		    error = defaults_get_mirror_usehsp(
7530Sstevel@tonic-gate 			    _defaults, get_request_diskset(), val);
7540Sstevel@tonic-gate 		    break;
7550Sstevel@tonic-gate 
7560Sstevel@tonic-gate 		case TYPE_STRIPE:
7570Sstevel@tonic-gate 		    error = defaults_get_stripe_usehsp(
7580Sstevel@tonic-gate 			    _defaults, get_request_diskset(), val);
7590Sstevel@tonic-gate 		    break;
7600Sstevel@tonic-gate 
7610Sstevel@tonic-gate 		case TYPE_CONCAT:
7620Sstevel@tonic-gate 		    error = defaults_get_concat_usehsp(
7630Sstevel@tonic-gate 			    _defaults, get_request_diskset(), val);
7640Sstevel@tonic-gate 		    break;
7650Sstevel@tonic-gate 
7660Sstevel@tonic-gate 		case TYPE_VOLUME:
7670Sstevel@tonic-gate 		    error = defaults_get_volume_usehsp(
7680Sstevel@tonic-gate 			    _defaults, get_request_diskset(), val);
7690Sstevel@tonic-gate 		    break;
7700Sstevel@tonic-gate 		}
7710Sstevel@tonic-gate 	    }
7720Sstevel@tonic-gate 	}
7730Sstevel@tonic-gate 
7740Sstevel@tonic-gate 	return (error);
7750Sstevel@tonic-gate }
7760Sstevel@tonic-gate 
7770Sstevel@tonic-gate /*
7780Sstevel@tonic-gate  * FUNCTION:	get_volume_redundancy_level(devconfig_t *req, uint16_t val)
7790Sstevel@tonic-gate  * INPUT:	req	- a devconfig_t pointer to the current request
7800Sstevel@tonic-gate  *		val	- pointer to a uint16-t to hold the result
7810Sstevel@tonic-gate  *
7820Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
7830Sstevel@tonic-gate  *			  !0 - otherwise
7840Sstevel@tonic-gate  *
7850Sstevel@tonic-gate  * PURPOSE:	helper which determines the appropriate level of data
7860Sstevel@tonic-gate  *		redundancy a volume should have for volumes satisfying
7870Sstevel@tonic-gate  *		the input request.
7880Sstevel@tonic-gate  *
7890Sstevel@tonic-gate  *		The value to use is taken from the input request, the
7900Sstevel@tonic-gate  *		toplevel diskset request, the diskset defaults or the
7910Sstevel@tonic-gate  *		global defaults.
7920Sstevel@tonic-gate  */
7930Sstevel@tonic-gate int
get_volume_redundancy_level(devconfig_t * req,uint16_t * val)7940Sstevel@tonic-gate get_volume_redundancy_level(
7950Sstevel@tonic-gate 	devconfig_t	*req,
7960Sstevel@tonic-gate 	uint16_t	*val)
7970Sstevel@tonic-gate {
7980Sstevel@tonic-gate 	int		error = 0;
7990Sstevel@tonic-gate 
8000Sstevel@tonic-gate 	*val = 0;
8010Sstevel@tonic-gate 
8020Sstevel@tonic-gate 	if ((error = devconfig_get_volume_redundancy_level(req, val)) != 0) {
8030Sstevel@tonic-gate 	    if (error != ERR_ATTR_UNSET) {
8040Sstevel@tonic-gate 		return (error);
8050Sstevel@tonic-gate 	    }
8060Sstevel@tonic-gate 	}
8070Sstevel@tonic-gate 
8080Sstevel@tonic-gate 	if (*val == 0) {
8090Sstevel@tonic-gate 	    if ((error = defaults_get_volume_redundancy_level(
8100Sstevel@tonic-gate 		_defaults, get_request_diskset(), val)) != 0) {
8110Sstevel@tonic-gate 		if (error != ERR_ATTR_UNSET) {
8120Sstevel@tonic-gate 		    return (error);
8130Sstevel@tonic-gate 		}
8140Sstevel@tonic-gate 	    }
8150Sstevel@tonic-gate 	}
8160Sstevel@tonic-gate 
8170Sstevel@tonic-gate 	return (error);
8180Sstevel@tonic-gate }
8190Sstevel@tonic-gate 
8200Sstevel@tonic-gate /*
8210Sstevel@tonic-gate  * FUNCTION:	get_volume_npaths(devconfig_t *req, uint16_t val)
8220Sstevel@tonic-gate  * INPUT:	req	- a devconfig_t pointer to the current request
8230Sstevel@tonic-gate  *		val	- pointer to a uint16-t to hold the result
8240Sstevel@tonic-gate  *
8250Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
8260Sstevel@tonic-gate  *			  !0 - otherwise
8270Sstevel@tonic-gate  *
8280Sstevel@tonic-gate  * PURPOSE:	helper which determines the appropriate level of datapath
8290Sstevel@tonic-gate  *		redundancy a slice component should have for volumes
8300Sstevel@tonic-gate  *		satisfying the input request.
8310Sstevel@tonic-gate  *
8320Sstevel@tonic-gate  *		The value to use is taken from the input request, the
8330Sstevel@tonic-gate  *		toplevel diskset request, the diskset defaults or the
8340Sstevel@tonic-gate  *		global defaults.
8350Sstevel@tonic-gate  */
8360Sstevel@tonic-gate int
get_volume_npaths(devconfig_t * req,uint16_t * val)8370Sstevel@tonic-gate get_volume_npaths(
8380Sstevel@tonic-gate 	devconfig_t	*req,
8390Sstevel@tonic-gate 	uint16_t	*val)
8400Sstevel@tonic-gate {
8410Sstevel@tonic-gate 	int		error = 0;
8420Sstevel@tonic-gate 
8430Sstevel@tonic-gate 	*val = 0;
8440Sstevel@tonic-gate 
8450Sstevel@tonic-gate 	if ((error = devconfig_get_volume_npaths(req, val)) != 0) {
8460Sstevel@tonic-gate 	    if (error != ERR_ATTR_UNSET) {
8470Sstevel@tonic-gate 		return (error);
8480Sstevel@tonic-gate 	    }
8490Sstevel@tonic-gate 	}
8500Sstevel@tonic-gate 
8510Sstevel@tonic-gate 	if (*val == 0) {
8520Sstevel@tonic-gate 	    if ((error = defaults_get_volume_npaths(
8530Sstevel@tonic-gate 		_defaults, get_request_diskset(), val)) != 0) {
8540Sstevel@tonic-gate 		if (error != ERR_ATTR_UNSET) {
8550Sstevel@tonic-gate 		    return (error);
8560Sstevel@tonic-gate 		}
8570Sstevel@tonic-gate 	    }
8580Sstevel@tonic-gate 	}
8590Sstevel@tonic-gate 
8600Sstevel@tonic-gate 	return (error);
8610Sstevel@tonic-gate }
8620Sstevel@tonic-gate 
8630Sstevel@tonic-gate /*
8640Sstevel@tonic-gate  * FUNCTION:	get_default_hsp_name(devconfig_t *req, char **hspname)
8650Sstevel@tonic-gate  * INPUT:	req	- a devconfig_t pointer to the current request
8660Sstevel@tonic-gate  *		hspname	- pointer to a char * to hold the result, if any
8670Sstevel@tonic-gate  *
8680Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
8690Sstevel@tonic-gate  *			  !0 - otherwise
8700Sstevel@tonic-gate  *
8710Sstevel@tonic-gate  * PURPOSE:	helper which determines the default HSP name for the
8720Sstevel@tonic-gate  *		input request.
8730Sstevel@tonic-gate  *
8740Sstevel@tonic-gate  *		The value to use is taken from the input request, the
8750Sstevel@tonic-gate  *		toplevel diskset request, the diskset defaults or the
8760Sstevel@tonic-gate  *		global defaults.
8770Sstevel@tonic-gate  */
8780Sstevel@tonic-gate int
get_default_hsp_name(devconfig_t * req,char ** name)8790Sstevel@tonic-gate get_default_hsp_name(
8800Sstevel@tonic-gate 	devconfig_t	*req,
8810Sstevel@tonic-gate 	char		**name)
8820Sstevel@tonic-gate {
8830Sstevel@tonic-gate 	int		error = 0;
8840Sstevel@tonic-gate 
8850Sstevel@tonic-gate 	*name = NULL;
8860Sstevel@tonic-gate 
8870Sstevel@tonic-gate 	if ((error = defaults_get_hsp_name(_defaults,
8880Sstevel@tonic-gate 	    get_request_diskset(), name)) != 0) {
8890Sstevel@tonic-gate 	    if (error != ENOENT) {
8900Sstevel@tonic-gate 		return (error);
8910Sstevel@tonic-gate 	    }
8920Sstevel@tonic-gate 	    error = 0;
8930Sstevel@tonic-gate 	}
8940Sstevel@tonic-gate 
8950Sstevel@tonic-gate 	return (error);
8960Sstevel@tonic-gate }
8970Sstevel@tonic-gate 
8980Sstevel@tonic-gate /*
8990Sstevel@tonic-gate  * FUNCTION:	slice_is_available(char *sname, devconfig_t *request,
9000Sstevel@tonic-gate  *			boolean_t bool)
9010Sstevel@tonic-gate  * INPUT:	sname	- a slice name
9020Sstevel@tonic-gate  *		request	- pointer to a devconfig_t struct representing
9030Sstevel@tonic-gate  *				the current layout request being processed
9040Sstevel@tonic-gate  * 		bool	- pointer to a boolean to hold the result
9050Sstevel@tonic-gate  *
9060Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
9070Sstevel@tonic-gate  *			  !0 - otherwise
9080Sstevel@tonic-gate  *
9090Sstevel@tonic-gate  * PURPOSE:	Validation helper which determines if the named slice can
9100Sstevel@tonic-gate  *		be used as a volume component when satisfying the input
9110Sstevel@tonic-gate  *		request.
9120Sstevel@tonic-gate  *
9130Sstevel@tonic-gate  *		Check if the slice appears in the known slice list,
9140Sstevel@tonic-gate  *		then check the request's available and unavailable
9150Sstevel@tonic-gate  *		device specifications.
9160Sstevel@tonic-gate  */
9170Sstevel@tonic-gate int
slice_is_available(char * sname,devconfig_t * request,boolean_t * bool)9180Sstevel@tonic-gate slice_is_available(
9190Sstevel@tonic-gate 	char		*sname,
9200Sstevel@tonic-gate 	devconfig_t	*request,
9210Sstevel@tonic-gate 	boolean_t	*bool)
9220Sstevel@tonic-gate {
9230Sstevel@tonic-gate 	dm_descriptor_t	slice = (dm_descriptor_t)0;
9240Sstevel@tonic-gate 	int		error = 0;
9250Sstevel@tonic-gate 
9260Sstevel@tonic-gate 	*bool = B_FALSE;
9270Sstevel@tonic-gate 
9280Sstevel@tonic-gate 	if ((error = slice_get_by_name(sname, &slice)) != 0) {
9290Sstevel@tonic-gate 	    return (error);
9300Sstevel@tonic-gate 	}
9310Sstevel@tonic-gate 
9320Sstevel@tonic-gate 	if (slice == (dm_descriptor_t)0) {
9330Sstevel@tonic-gate 	    /* no slice found */
9340Sstevel@tonic-gate 	    return (ENODEV);
9350Sstevel@tonic-gate 	}
9360Sstevel@tonic-gate 
9370Sstevel@tonic-gate 	if (error == 0) {
9380Sstevel@tonic-gate 	    error = is_named_device_avail(request, sname, B_TRUE, bool);
9390Sstevel@tonic-gate 	}
9400Sstevel@tonic-gate 
9410Sstevel@tonic-gate 	return (error);
9420Sstevel@tonic-gate }
9430Sstevel@tonic-gate 
9440Sstevel@tonic-gate /*
9450Sstevel@tonic-gate  * FUNCTION:	get_disks_for_target(char *name, dlist_t **disks)
9460Sstevel@tonic-gate  *
9470Sstevel@tonic-gate  * INPUT:	name	- a char* device CTD name
9480Sstevel@tonic-gate  *
9490Sstevel@tonic-gate  * OUTPUT:	disks	- disks matching the input target name
9500Sstevel@tonic-gate  *
9510Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
9520Sstevel@tonic-gate  *			 !0 otherwise
9530Sstevel@tonic-gate  *
9540Sstevel@tonic-gate  * PURPOSE:	Validation helper function which finds all disks "on" the
9550Sstevel@tonic-gate  *		input target.
9560Sstevel@tonic-gate  *
9570Sstevel@tonic-gate  *		The input name is assumed to be a target name, cXtX, and
9580Sstevel@tonic-gate  *		the list of known disks is searched to find any disk that
9590Sstevel@tonic-gate  *		looks to be "on" that target.
9600Sstevel@tonic-gate  *
9610Sstevel@tonic-gate  *		"On" is determined by comparing a disk's name and
9620Sstevel@tonic-gate  *		aliases to the target to see if they match.
9630Sstevel@tonic-gate  */
9640Sstevel@tonic-gate int
get_disks_for_target(char * name,dlist_t ** disks)9650Sstevel@tonic-gate get_disks_for_target(
9660Sstevel@tonic-gate 	char *name,
9670Sstevel@tonic-gate 	dlist_t **disks)
9680Sstevel@tonic-gate {
9690Sstevel@tonic-gate 	int error = 0;
9700Sstevel@tonic-gate 	device_spec_t *targetid = NULL;
9710Sstevel@tonic-gate 
9720Sstevel@tonic-gate 	error = get_spec_for_name(name, &targetid);
9730Sstevel@tonic-gate 	if (error == 0) {
9740Sstevel@tonic-gate 	    dlist_t *known_disks = NULL;
9750Sstevel@tonic-gate 	    dlist_t *iter = NULL;
9760Sstevel@tonic-gate 
9770Sstevel@tonic-gate 	    get_known_disks(&known_disks);
9780Sstevel@tonic-gate 	    for (iter = known_disks;
9790Sstevel@tonic-gate 		(iter != NULL) && (error == 0);
9800Sstevel@tonic-gate 		iter = iter->next) {
9810Sstevel@tonic-gate 
9820Sstevel@tonic-gate 		dm_descriptor_t disk = (uintptr_t)iter->obj;
9830Sstevel@tonic-gate 		device_spec_t *diskid = NULL;
9840Sstevel@tonic-gate 		char	*diskname = NULL;
9850Sstevel@tonic-gate 		dlist_t *diskaliases = NULL;
9860Sstevel@tonic-gate 		dlist_t *item;
9870Sstevel@tonic-gate 
9880Sstevel@tonic-gate 		((error = get_display_name(disk, &diskname)) != 0) ||
9890Sstevel@tonic-gate 		(error = get_aliases(disk, &diskaliases)) ||
9900Sstevel@tonic-gate 		(error = get_spec_for_name(diskname, &diskid));
9910Sstevel@tonic-gate 
9920Sstevel@tonic-gate 		if (error == 0) {
9930Sstevel@tonic-gate 		    if (spec_includes_device(targetid, diskid) == B_TRUE) {
9940Sstevel@tonic-gate 			/* add disk */
995*62Sjeanm 			if ((item = dlist_new_item((void *)(uintptr_t)disk)) ==
996*62Sjeanm 			    NULL) {
9970Sstevel@tonic-gate 			    error = ENOMEM;
9980Sstevel@tonic-gate 			} else {
9990Sstevel@tonic-gate 			    *disks = dlist_append(item, *disks, AT_HEAD);
10000Sstevel@tonic-gate 			}
10010Sstevel@tonic-gate 		    } else {
10020Sstevel@tonic-gate 			/* check disk's aliases */
10030Sstevel@tonic-gate 			dlist_t *iter2;
10040Sstevel@tonic-gate 			for (iter2 = diskaliases;
10050Sstevel@tonic-gate 			    (iter2 != NULL) && (error == 0);
10060Sstevel@tonic-gate 			    iter2 = iter2->next) {
10070Sstevel@tonic-gate 
10080Sstevel@tonic-gate 			    char *aliasname = NULL;
10090Sstevel@tonic-gate 			    device_spec_t *aliasid = NULL;
10100Sstevel@tonic-gate 			    error = get_display_name(disk, &aliasname);
10110Sstevel@tonic-gate 			    error = get_spec_for_name(aliasname, &aliasid);
10120Sstevel@tonic-gate 
10130Sstevel@tonic-gate 			    if (spec_includes_device(
10140Sstevel@tonic-gate 					targetid, aliasid) == B_TRUE) {
10150Sstevel@tonic-gate 
10160Sstevel@tonic-gate 				/* alias matched, add disk */
1017*62Sjeanm 				item = dlist_new_item((void *)(uintptr_t)disk);
10180Sstevel@tonic-gate 				if (item == NULL) {
10190Sstevel@tonic-gate 				    error = ENOMEM;
10200Sstevel@tonic-gate 				} else {
10210Sstevel@tonic-gate 				    *disks =
10220Sstevel@tonic-gate 					dlist_append(item, *disks, AT_HEAD);
10230Sstevel@tonic-gate 				}
10240Sstevel@tonic-gate 			    }
10250Sstevel@tonic-gate 			}
10260Sstevel@tonic-gate 		    }
10270Sstevel@tonic-gate 		}
10280Sstevel@tonic-gate 	    }
10290Sstevel@tonic-gate 	}
10300Sstevel@tonic-gate 
10310Sstevel@tonic-gate 	return (error);
10320Sstevel@tonic-gate }
10330Sstevel@tonic-gate 
10340Sstevel@tonic-gate /*
10350Sstevel@tonic-gate  * FUNCTION:	select_hbas_with_n_disks(devconfig_t *request,
10360Sstevel@tonic-gate  *			dlist_t	*hbas, int mindisks, dlist_t **selhbas,
10370Sstevel@tonic-gate  *			dlist_t **seldisks)
10380Sstevel@tonic-gate  *
10390Sstevel@tonic-gate  * INPUT:	request	- pointer to a devconfig_t struct representing
10400Sstevel@tonic-gate  *				the current layout request being processed
10410Sstevel@tonic-gate  * 		hbas	- pointer to a list of HBAs
10420Sstevel@tonic-gate  *		mindisks - minimum number of disks required on the HBAs
10430Sstevel@tonic-gate  *
10440Sstevel@tonic-gate  * OUTPUT:	selhbas	- pointer to a list containing the HBAs with at
10450Sstevel@tonic-gate  *				least mindisks available disks.
10460Sstevel@tonic-gate  *		seldisks - pointer to a list containing the available disks
10470Sstevel@tonic-gate  *				for the HBAs in selhbas
10480Sstevel@tonic-gate  *
10490Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
10500Sstevel@tonic-gate  *			  !0 - otherwise
10510Sstevel@tonic-gate  *
10520Sstevel@tonic-gate  * PURPOSE:	helper which counts the number of available disks associated
10530Sstevel@tonic-gate  *		with each of the input HBAs and adds those that have at
10540Sstevel@tonic-gate  *		least mindisks to the output list.
10550Sstevel@tonic-gate  *
10560Sstevel@tonic-gate  *		Only available disks that have available space are counted.
10570Sstevel@tonic-gate  *
10580Sstevel@tonic-gate  *		Disks connected thru multiple HBAs are only counted for
10590Sstevel@tonic-gate  *		the first HBA they're accessed through.
10600Sstevel@tonic-gate  *
10610Sstevel@tonic-gate  *		The list of HBAs returned will be in descending order,
10620Sstevel@tonic-gate  *		i.e., HBAs with more disks come before those with fewer.
10630Sstevel@tonic-gate  *
10640Sstevel@tonic-gate  *		The returned lists of HBAs and disks must be passed to
10650Sstevel@tonic-gate  *		dlist_free_items() to recover the space allocated to hold
10660Sstevel@tonic-gate  *		each list item.
10670Sstevel@tonic-gate  *
10680Sstevel@tonic-gate  *		for (each HBA) {
10690Sstevel@tonic-gate  *
10700Sstevel@tonic-gate  *		    select HBA
10710Sstevel@tonic-gate  *		    get available disks on HBA
10720Sstevel@tonic-gate  *
10730Sstevel@tonic-gate  *		    for (each disk) {
10740Sstevel@tonic-gate  *			if (disk is not in selected disk list)
10750Sstevel@tonic-gate  *			    add it to the list
10760Sstevel@tonic-gate  *			else
10770Sstevel@tonic-gate  *			    count it as a distinct disk on this HBA
10780Sstevel@tonic-gate  *		    }
10790Sstevel@tonic-gate  *
10800Sstevel@tonic-gate  *		    if (this HBA has >= mindisks distinct disks)
10810Sstevel@tonic-gate  *			add this HBA to the list of returned HBAs
10820Sstevel@tonic-gate  *
10830Sstevel@tonic-gate  *		}
10840Sstevel@tonic-gate  */
10850Sstevel@tonic-gate int
select_hbas_with_n_disks(devconfig_t * request,dlist_t * hbas,int mindisks,dlist_t ** selhbas,dlist_t ** seldisks)10860Sstevel@tonic-gate select_hbas_with_n_disks(
10870Sstevel@tonic-gate 	devconfig_t	*request,
10880Sstevel@tonic-gate 	dlist_t		*hbas,
10890Sstevel@tonic-gate 	int		mindisks,
10900Sstevel@tonic-gate 	dlist_t		**selhbas,
10910Sstevel@tonic-gate 	dlist_t		**seldisks)
10920Sstevel@tonic-gate {
10930Sstevel@tonic-gate 	dlist_t		*iter = NULL;
10940Sstevel@tonic-gate 	int		error = 0;
10950Sstevel@tonic-gate 
10960Sstevel@tonic-gate 	*selhbas = NULL;
10970Sstevel@tonic-gate 	*seldisks = NULL;
10980Sstevel@tonic-gate 
10990Sstevel@tonic-gate 	/* for each input HBA */
11000Sstevel@tonic-gate 	for (iter = hbas; (error == 0) && (iter != NULL); iter = iter->next) {
11010Sstevel@tonic-gate 
11020Sstevel@tonic-gate 	    dm_descriptor_t hba = (uintptr_t)iter->obj;
11030Sstevel@tonic-gate 	    dlist_t *iter2 = NULL;
11040Sstevel@tonic-gate 	    dlist_t *disks = NULL;
11050Sstevel@tonic-gate 	    uint64_t space = 0;
11060Sstevel@tonic-gate 	    uint16_t ndistinct = 0;
11070Sstevel@tonic-gate 
11080Sstevel@tonic-gate 	    error = hba_get_avail_disks_and_space(request, hba, &disks, &space);
11090Sstevel@tonic-gate 
11100Sstevel@tonic-gate 	    /* for each of this HBA's disks */
11110Sstevel@tonic-gate 	    for (iter2 = disks;
11120Sstevel@tonic-gate 		(iter2 != NULL) && (error == 0);
11130Sstevel@tonic-gate 		iter2 = iter2->next) {
11140Sstevel@tonic-gate 
11150Sstevel@tonic-gate 		dm_descriptor_t disk = (uintptr_t)iter2->obj;
11160Sstevel@tonic-gate 
11170Sstevel@tonic-gate 		/* unique disk? has it been seen thru some other HBA? */
1118*62Sjeanm 		if (dlist_contains(*seldisks, (void *)(uintptr_t)disk,
11190Sstevel@tonic-gate 		    compare_descriptor_names) != B_TRUE) {
11200Sstevel@tonic-gate 
11210Sstevel@tonic-gate 		    /* distinct, add to list of all_distinct */
1122*62Sjeanm 		    dlist_t *item = dlist_new_item((void *)(uintptr_t)disk);
11230Sstevel@tonic-gate 		    if (item == NULL) {
11240Sstevel@tonic-gate 			error = ENOMEM;
11250Sstevel@tonic-gate 		    } else {
11260Sstevel@tonic-gate 
11270Sstevel@tonic-gate 			*seldisks =
11280Sstevel@tonic-gate 			    dlist_append(item, *seldisks, AT_HEAD);
11290Sstevel@tonic-gate 
11300Sstevel@tonic-gate 			/* increment this HBA's distinct disk count */
11310Sstevel@tonic-gate 			++ndistinct;
11320Sstevel@tonic-gate 		    }
11330Sstevel@tonic-gate 		}
11340Sstevel@tonic-gate 	    }
11350Sstevel@tonic-gate 
11360Sstevel@tonic-gate 	    if (ndistinct >= mindisks) {
11370Sstevel@tonic-gate 
11380Sstevel@tonic-gate 		/* this HBA has minimum # of disks, add to output list */
1139*62Sjeanm 		dlist_t	*item = dlist_new_item((void *)(uintptr_t)hba);
11400Sstevel@tonic-gate 		if (item == NULL) {
11410Sstevel@tonic-gate 		    error = ENOMEM;
11420Sstevel@tonic-gate 		} else {
11430Sstevel@tonic-gate 		    *selhbas =
11440Sstevel@tonic-gate 			dlist_insert_ordered(
11450Sstevel@tonic-gate 				item, *selhbas, DESCENDING,
11460Sstevel@tonic-gate 				compare_hba_n_avail_disks);
11470Sstevel@tonic-gate 
11480Sstevel@tonic-gate 		    /* save # of disks for ordering the list */
11490Sstevel@tonic-gate 		    hba_set_n_avail_disks(hba, ndistinct);
11500Sstevel@tonic-gate 		}
11510Sstevel@tonic-gate 	    }
11520Sstevel@tonic-gate 
11530Sstevel@tonic-gate 	    dlist_free_items(disks, NULL);
11540Sstevel@tonic-gate 	}
11550Sstevel@tonic-gate 
11560Sstevel@tonic-gate 	if (error != 0) {
11570Sstevel@tonic-gate 	    oprintf(OUTPUT_TERSE,
11580Sstevel@tonic-gate 		    gettext("failed selecting HBAs with n disks: %d\n"),
11590Sstevel@tonic-gate 		    error);
11600Sstevel@tonic-gate 
11610Sstevel@tonic-gate 	    dlist_free_items(*selhbas, NULL);
11620Sstevel@tonic-gate 	    *selhbas = NULL;
11630Sstevel@tonic-gate 	    dlist_free_items(*seldisks, NULL);
11640Sstevel@tonic-gate 	    *seldisks = NULL;
11650Sstevel@tonic-gate 	}
11660Sstevel@tonic-gate 
11670Sstevel@tonic-gate 	return (error);
11680Sstevel@tonic-gate }
11690Sstevel@tonic-gate 
11700Sstevel@tonic-gate /*
11710Sstevel@tonic-gate  * FUNCTION:	hba_get_avail_disks_and_space(devconfig_t *request,
11720Sstevel@tonic-gate  *			dm_descriptor_t hba, dlist_t **disks, uint64_t *space)
11730Sstevel@tonic-gate  *
11740Sstevel@tonic-gate  * INPUT:	request	- pointer to a devconfig_t struct representing
11750Sstevel@tonic-gate  *				the current layout request being processed
11760Sstevel@tonic-gate  * 		hba	- dm_descriptor_t handle for an HBA
11770Sstevel@tonic-gate  *
11780Sstevel@tonic-gate  * OUTPUT:	disks	- pointer to a list to hold the computed available
11790Sstevel@tonic-gate  *				disks
11800Sstevel@tonic-gate  * 		avail	- pointer to a uint64_t to hold the aggregate
11810Sstevel@tonic-gate  *				available space on the available disks
11820Sstevel@tonic-gate  *
11830Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
11840Sstevel@tonic-gate  *			  !0 - otherwise
11850Sstevel@tonic-gate  *
11860Sstevel@tonic-gate  * PURPOSE:	helper which examines the disks associated with the
11870Sstevel@tonic-gate  *		input HBA and assembles a list of those that are available.
11880Sstevel@tonic-gate  *
11890Sstevel@tonic-gate  *		Available is defined as being in the usable list, having
11900Sstevel@tonic-gate  *		unused space and not specifically excluded by the request's
11910Sstevel@tonic-gate  *		list of unavailable devices.
11920Sstevel@tonic-gate  *
11930Sstevel@tonic-gate  *		The returned list must be passed to dlist_free_items()
11940Sstevel@tonic-gate  *		to recover the memory allocated to hold each list item.
11950Sstevel@tonic-gate  */
11960Sstevel@tonic-gate int
hba_get_avail_disks_and_space(devconfig_t * request,dm_descriptor_t hba,dlist_t ** disks,uint64_t * space)11970Sstevel@tonic-gate hba_get_avail_disks_and_space(
11980Sstevel@tonic-gate 	devconfig_t	*request,
11990Sstevel@tonic-gate 	dm_descriptor_t	hba,
12000Sstevel@tonic-gate 	dlist_t		**disks,
12010Sstevel@tonic-gate 	uint64_t	*space)
12020Sstevel@tonic-gate {
12030Sstevel@tonic-gate 	dlist_t		*usable_disks = NULL;
12040Sstevel@tonic-gate 	dlist_t		*iter = NULL;
12050Sstevel@tonic-gate 	int		error = 0;
12060Sstevel@tonic-gate 
12070Sstevel@tonic-gate 	*disks = NULL;
12080Sstevel@tonic-gate 
12090Sstevel@tonic-gate 	/* for each usable disk */
12100Sstevel@tonic-gate 	error = get_usable_disks(&usable_disks);
12110Sstevel@tonic-gate 	for (iter = usable_disks;
12120Sstevel@tonic-gate 	    (error == 0) && (iter != NULL);
12130Sstevel@tonic-gate 	    iter = iter->next) {
12140Sstevel@tonic-gate 
12150Sstevel@tonic-gate 	    dm_descriptor_t disk = (uintptr_t)iter->obj;
12160Sstevel@tonic-gate 	    boolean_t	avail = B_FALSE;
12170Sstevel@tonic-gate 	    dlist_t	*hbas = NULL;
12180Sstevel@tonic-gate 
12190Sstevel@tonic-gate 	    /* is disk attached to HBA in question? */
12200Sstevel@tonic-gate 	    error = disk_get_hbas(disk, &hbas);
12210Sstevel@tonic-gate 	    if (error != 0) {
12220Sstevel@tonic-gate 		continue;
12230Sstevel@tonic-gate 	    }
12240Sstevel@tonic-gate 
1225*62Sjeanm 	    if (dlist_contains(hbas, (void *)(uintptr_t)hba,
12260Sstevel@tonic-gate 			compare_descriptor_names) == B_TRUE) {
12270Sstevel@tonic-gate 
12280Sstevel@tonic-gate 		/* is disk available? */
12290Sstevel@tonic-gate 		error = is_device_avail(disk, request, &avail);
12300Sstevel@tonic-gate 		if ((error == 0) && (avail == B_TRUE)) {
12310Sstevel@tonic-gate 		    uint64_t disk_space = 0;
12320Sstevel@tonic-gate 
12330Sstevel@tonic-gate 		    /* does disk have available space? */
12340Sstevel@tonic-gate 		    error = disk_get_avail_space(request, disk, &disk_space);
12350Sstevel@tonic-gate 		    if ((error == 0) && (disk_space > 0)) {
12360Sstevel@tonic-gate 
1237*62Sjeanm 			dlist_t *item = dlist_new_item((void *)(uintptr_t)disk);
12380Sstevel@tonic-gate 			if (item == NULL) {
12390Sstevel@tonic-gate 			    error = ENOMEM;
12400Sstevel@tonic-gate 			} else {
12410Sstevel@tonic-gate 			    *disks = dlist_append(item, *disks, AT_HEAD);
12420Sstevel@tonic-gate 			}
12430Sstevel@tonic-gate 
12440Sstevel@tonic-gate 			*space += disk_space;
12450Sstevel@tonic-gate 		    }
12460Sstevel@tonic-gate 		}
12470Sstevel@tonic-gate 	    }
12480Sstevel@tonic-gate 
12490Sstevel@tonic-gate 	    dlist_free_items(hbas, NULL);
12500Sstevel@tonic-gate 	}
12510Sstevel@tonic-gate 
12520Sstevel@tonic-gate 	if (error != 0) {
12530Sstevel@tonic-gate 	    dlist_free_items(*disks, NULL);
12540Sstevel@tonic-gate 	    *disks = NULL;
12550Sstevel@tonic-gate 	}
12560Sstevel@tonic-gate 
12570Sstevel@tonic-gate 	return (error);
12580Sstevel@tonic-gate }
12590Sstevel@tonic-gate 
12600Sstevel@tonic-gate /*
12610Sstevel@tonic-gate  * FUNCTION:	disk_get_avail_space(devconfig_t *request,
12620Sstevel@tonic-gate  *			dlist_t *disks, uint64_t space)
12630Sstevel@tonic-gate  *
12640Sstevel@tonic-gate  * INPUT:	request	- pointer to a devconfig_t struct representing
12650Sstevel@tonic-gate  *				the current layout request being processed
12660Sstevel@tonic-gate  * 		disks	- pointer to a list of disks
12670Sstevel@tonic-gate  * 		space	- pointer to a uint64_t to hold the computed available
12680Sstevel@tonic-gate  *				space
12690Sstevel@tonic-gate  *
12700Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
12710Sstevel@tonic-gate  *			  !0 - otherwise
12720Sstevel@tonic-gate  *
12730Sstevel@tonic-gate  * PURPOSE:	helper which iterates the input list of disks and determines
12740Sstevel@tonic-gate  *		the aggregate amount of available space they represent.
12750Sstevel@tonic-gate  *
12760Sstevel@tonic-gate  *		Only disk slices that are in the usable slice list and not
12770Sstevel@tonic-gate  *		specifically excluded by the request's list of unavailable
12780Sstevel@tonic-gate  *		devices	will contribute to the aggregate space computation.
12790Sstevel@tonic-gate  */
12800Sstevel@tonic-gate static int
disk_get_avail_space(devconfig_t * request,dm_descriptor_t disk,uint64_t * space)12810Sstevel@tonic-gate disk_get_avail_space(
12820Sstevel@tonic-gate 	devconfig_t	*request,
12830Sstevel@tonic-gate 	dm_descriptor_t	disk,
12840Sstevel@tonic-gate 	uint64_t	*space)
12850Sstevel@tonic-gate {
12860Sstevel@tonic-gate 	dlist_t		*usable_slices = NULL;
12870Sstevel@tonic-gate 	dlist_t		*iter = NULL;
12880Sstevel@tonic-gate 	int		error = 0;
12890Sstevel@tonic-gate 
12900Sstevel@tonic-gate 	*space = 0;
12910Sstevel@tonic-gate 
12920Sstevel@tonic-gate 	/* for each usable slice */
12930Sstevel@tonic-gate 	error = get_usable_slices(&usable_slices);
12940Sstevel@tonic-gate 	for (iter = usable_slices;
12950Sstevel@tonic-gate 	    (error == 0) && (iter != NULL);
12960Sstevel@tonic-gate 	    iter = iter->next) {
12970Sstevel@tonic-gate 
12980Sstevel@tonic-gate 	    dm_descriptor_t slice = (uintptr_t)iter->obj;
12990Sstevel@tonic-gate 	    dm_descriptor_t slice_disk;
13000Sstevel@tonic-gate 	    boolean_t	avail = B_FALSE;
13010Sstevel@tonic-gate 	    boolean_t	reserved = B_FALSE;
13020Sstevel@tonic-gate 	    boolean_t	used = B_FALSE;
13030Sstevel@tonic-gate 
13040Sstevel@tonic-gate 	    /* is slice on disk in question? */
13050Sstevel@tonic-gate 	    if (((error = slice_get_disk(slice, &slice_disk)) != 0) ||
1306*62Sjeanm 		(compare_descriptor_names((void *)(uintptr_t)slice_disk,
1307*62Sjeanm 			(void *)(uintptr_t)disk) != 0)) {
13080Sstevel@tonic-gate 		continue;
13090Sstevel@tonic-gate 	    }
13100Sstevel@tonic-gate 
13110Sstevel@tonic-gate 	    /* is slice reserved by an explicit layout request? */
13120Sstevel@tonic-gate 	    if (((error = is_reserved_slice(slice, &reserved)) != 0) ||
13130Sstevel@tonic-gate 		(reserved == B_TRUE)) {
13140Sstevel@tonic-gate 		continue;
13150Sstevel@tonic-gate 	    }
13160Sstevel@tonic-gate 
13170Sstevel@tonic-gate 	    /* is slice used by a pending layout request? */
13180Sstevel@tonic-gate 	    if (((error = is_used_slice(slice, &used)) != 0) ||
13190Sstevel@tonic-gate 		(used == B_TRUE)) {
13200Sstevel@tonic-gate 		continue;
13210Sstevel@tonic-gate 	    }
13220Sstevel@tonic-gate 
13230Sstevel@tonic-gate 	    /* is slice available? */
13240Sstevel@tonic-gate 	    if (((error = is_device_avail(slice, request, &avail)) == 0) &&
13250Sstevel@tonic-gate 		(avail == B_TRUE)) {
13260Sstevel@tonic-gate 
13270Sstevel@tonic-gate 		/* does slice have usable space? */
13280Sstevel@tonic-gate 		uint64_t size = 0;
13290Sstevel@tonic-gate 		if ((error = slice_get_size(slice, &size)) == 0) {
13300Sstevel@tonic-gate 		    *space += size;
13310Sstevel@tonic-gate 		}
13320Sstevel@tonic-gate 	    }
13330Sstevel@tonic-gate 	}
13340Sstevel@tonic-gate 
13350Sstevel@tonic-gate 	return (error);
13360Sstevel@tonic-gate }
13370Sstevel@tonic-gate 
13380Sstevel@tonic-gate /*
13390Sstevel@tonic-gate  * FUNCTION:	disks_get_avail_slices(devconfig_t *request,
13400Sstevel@tonic-gate  *			dlist_t *disks, dlist_t **slices)
13410Sstevel@tonic-gate  *
13420Sstevel@tonic-gate  * INPUT:	request	- pointer to a devconfig_t struct representing
13430Sstevel@tonic-gate  *				the current layout request being processed
13440Sstevel@tonic-gate  * 		disks	- pointer to a list of disks
13450Sstevel@tonic-gate  * 		slices	- pointer to an output list of disks
13460Sstevel@tonic-gate  *
13470Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
13480Sstevel@tonic-gate  *			  !0 - otherwise
13490Sstevel@tonic-gate  *
13500Sstevel@tonic-gate  * PURPOSE:	helper which iterates the input list of disks and builds a
13510Sstevel@tonic-gate  *		new list which contains disks that are determined to be
13520Sstevel@tonic-gate  * 		available for satisfying the input request.
13530Sstevel@tonic-gate  *
13540Sstevel@tonic-gate  *		A disk must contain at least one slice in the available
13550Sstevel@tonic-gate  * 		slice list as well as have available space in order
13560Sstevel@tonic-gate  *		to be available.
13570Sstevel@tonic-gate  */
13580Sstevel@tonic-gate int
disks_get_avail_slices(devconfig_t * request,dlist_t * disks,dlist_t ** slices)13590Sstevel@tonic-gate disks_get_avail_slices(
13600Sstevel@tonic-gate 	devconfig_t	*request,
13610Sstevel@tonic-gate 	dlist_t		*disks,
13620Sstevel@tonic-gate 	dlist_t		**slices)
13630Sstevel@tonic-gate {
13640Sstevel@tonic-gate 	dlist_t		*usable_slices = NULL;
13650Sstevel@tonic-gate 	dlist_t		*iter = NULL;
13660Sstevel@tonic-gate 	int		error = 0;
13670Sstevel@tonic-gate 
13680Sstevel@tonic-gate 	*slices = NULL;
13690Sstevel@tonic-gate 
13700Sstevel@tonic-gate 	/* for each usable slice */
13710Sstevel@tonic-gate 	error = get_usable_slices(&usable_slices);
13720Sstevel@tonic-gate 	for (iter = usable_slices;
13730Sstevel@tonic-gate 	    (error == 0) && (iter != NULL);
13740Sstevel@tonic-gate 	    iter = iter->next) {
13750Sstevel@tonic-gate 
13760Sstevel@tonic-gate 	    dm_descriptor_t slice = (uintptr_t)iter->obj;
13770Sstevel@tonic-gate 	    dm_descriptor_t disk = (dm_descriptor_t)0;
13780Sstevel@tonic-gate 	    boolean_t	avail = B_FALSE;
13790Sstevel@tonic-gate 	    boolean_t	reserved = B_FALSE;
13800Sstevel@tonic-gate 	    boolean_t	used = B_FALSE;
13810Sstevel@tonic-gate 
13820Sstevel@tonic-gate 	    /* is slice on a disk in the input list? */
13830Sstevel@tonic-gate 	    if (((error = slice_get_disk(slice, &disk)) != 0) ||
1384*62Sjeanm 		(dlist_contains(disks, (void *)(uintptr_t)disk,
13850Sstevel@tonic-gate 			compare_descriptor_names) != B_TRUE)) {
13860Sstevel@tonic-gate 		continue;
13870Sstevel@tonic-gate 	    }
13880Sstevel@tonic-gate 
13890Sstevel@tonic-gate 	    /* is slice reserved by an explicit layout request? */
13900Sstevel@tonic-gate 	    if (((error = is_reserved_slice(slice, &reserved)) != 0) ||
13910Sstevel@tonic-gate 		(reserved == B_TRUE)) {
13920Sstevel@tonic-gate 		continue;
13930Sstevel@tonic-gate 	    }
13940Sstevel@tonic-gate 
13950Sstevel@tonic-gate 	    /* is slice used by a pending layout request? */
13960Sstevel@tonic-gate 	    if (((error = is_used_slice(slice, &used)) != 0) ||
13970Sstevel@tonic-gate 		(used == B_TRUE)) {
13980Sstevel@tonic-gate 		continue;
13990Sstevel@tonic-gate 	    }
14000Sstevel@tonic-gate 
14010Sstevel@tonic-gate 	    /* is slice available? */
14020Sstevel@tonic-gate 	    if (((error = is_device_avail(slice, request, &avail)) == 0) &&
14030Sstevel@tonic-gate 		(avail == B_TRUE)) {
14040Sstevel@tonic-gate 
14050Sstevel@tonic-gate 		/* does slice have available space? */
14060Sstevel@tonic-gate 		uint64_t size = 0;
14070Sstevel@tonic-gate 		error = slice_get_size(slice, &size);
14080Sstevel@tonic-gate 		if ((error == 0) && (size > 0)) {
1409*62Sjeanm 		    dlist_t *item = dlist_new_item((void *)(uintptr_t)slice);
14100Sstevel@tonic-gate 		    if (item == NULL) {
14110Sstevel@tonic-gate 			error = ENOMEM;
14120Sstevel@tonic-gate 		    } else {
14130Sstevel@tonic-gate 			*slices = dlist_append(item, *slices, AT_TAIL);
14140Sstevel@tonic-gate 		    }
14150Sstevel@tonic-gate 		}
14160Sstevel@tonic-gate 	    }
14170Sstevel@tonic-gate 	}
14180Sstevel@tonic-gate 
14190Sstevel@tonic-gate 	if (error != 0) {
14200Sstevel@tonic-gate 	    dlist_free_items(*slices, NULL);
14210Sstevel@tonic-gate 	    *slices = NULL;
14220Sstevel@tonic-gate 	}
14230Sstevel@tonic-gate 
14240Sstevel@tonic-gate 	return (error);
14250Sstevel@tonic-gate }
14260Sstevel@tonic-gate 
14270Sstevel@tonic-gate 
14280Sstevel@tonic-gate /*
14290Sstevel@tonic-gate  * FUNCTION:	get_hbas_and_disks_used_by_volumes(dlist_t *volumes,
14300Sstevel@tonic-gate  *			dlist_t **hbas,	dlist_t **disks)
14310Sstevel@tonic-gate  *
14320Sstevel@tonic-gate  * INPUT:	volumes	- pointer to a list of devconfig_t volumes
14330Sstevel@tonic-gate  *
14340Sstevel@tonic-gate  * OUTPUT:	hbas - a list of HBAs utilized by the input volumes
14350Sstevel@tonic-gate  *		disks - a list of disks utilized by the input volumes
14360Sstevel@tonic-gate  *
14370Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
14380Sstevel@tonic-gate  *			 !0 otherwise
14390Sstevel@tonic-gate  *
14400Sstevel@tonic-gate  * PURPOSE:	An aggregate list of HBAs and disks used by the input volumes
14410Sstevel@tonic-gate  *		is built up by iterating the list of volumes and calling
14420Sstevel@tonic-gate  *		get_hbas_disks_used_by_volume() to determine the HBAs and disk
14430Sstevel@tonic-gate  *		used by each volume.
14440Sstevel@tonic-gate  *
14450Sstevel@tonic-gate  *		The returned lists of HBAs and disks may contain duplicates.
14460Sstevel@tonic-gate  */
14470Sstevel@tonic-gate int
get_hbas_and_disks_used_by_volumes(dlist_t * volumes,dlist_t ** hbas,dlist_t ** disks)14480Sstevel@tonic-gate get_hbas_and_disks_used_by_volumes(
14490Sstevel@tonic-gate 	dlist_t		*volumes,
14500Sstevel@tonic-gate 	dlist_t		**hbas,
14510Sstevel@tonic-gate 	dlist_t		**disks)
14520Sstevel@tonic-gate {
14530Sstevel@tonic-gate 	dlist_t		*iter = NULL;
14540Sstevel@tonic-gate 	int		error = 0;
14550Sstevel@tonic-gate 
14560Sstevel@tonic-gate 	for (iter = volumes;
14570Sstevel@tonic-gate 	    (iter != NULL) && (error == 0);
14580Sstevel@tonic-gate 	    iter = iter->next) {
14590Sstevel@tonic-gate 	    error = get_hbas_and_disks_used_by_volume(
14600Sstevel@tonic-gate 		    (devconfig_t *)iter->obj, hbas, disks);
14610Sstevel@tonic-gate 	}
14620Sstevel@tonic-gate 
14630Sstevel@tonic-gate 	return (error);
14640Sstevel@tonic-gate }
14650Sstevel@tonic-gate 
14660Sstevel@tonic-gate /*
14670Sstevel@tonic-gate  * FUNCTION:	get_hbas_and_disks_used_by_volume(devconfig_t *volume,
14680Sstevel@tonic-gate  *			dlist_t **hbas, dlist_t **disks)
14690Sstevel@tonic-gate  *
14700Sstevel@tonic-gate  * INPUT:	volume	- pointer to a devconfig_t volume
14710Sstevel@tonic-gate  *
14720Sstevel@tonic-gate  * OUTPUT:	hbas - a list of HBAs updated to include those utilized
14730Sstevel@tonic-gate  *			by the input volume
14740Sstevel@tonic-gate  *		disks - a list of disks updated to inlclude those utilized
14750Sstevel@tonic-gate  *			by the input volume
14760Sstevel@tonic-gate  *
14770Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
14780Sstevel@tonic-gate  *			 !0 otherwise
14790Sstevel@tonic-gate  *
14800Sstevel@tonic-gate  * PURPOSE:	The volume's components are iterated and the disks and HBAs
14810Sstevel@tonic-gate  *		for each component are determined and appended to the input
14820Sstevel@tonic-gate  *		lists of HBAs and disks.
14830Sstevel@tonic-gate  *
14840Sstevel@tonic-gate  *		The returned lists of HBAs and disks may contain duplicates.
14850Sstevel@tonic-gate  */
14860Sstevel@tonic-gate int
get_hbas_and_disks_used_by_volume(devconfig_t * volume,dlist_t ** hbas,dlist_t ** disks)14870Sstevel@tonic-gate get_hbas_and_disks_used_by_volume(
14880Sstevel@tonic-gate 	devconfig_t	*volume,
14890Sstevel@tonic-gate 	dlist_t		**hbas,
14900Sstevel@tonic-gate 	dlist_t		**disks)
14910Sstevel@tonic-gate {
14920Sstevel@tonic-gate 	dlist_t		*iter = NULL;
14930Sstevel@tonic-gate 	int		error = 0;
14940Sstevel@tonic-gate 
14950Sstevel@tonic-gate 	for (iter = devconfig_get_components(volume);
14960Sstevel@tonic-gate 	    (iter != NULL) && (error == 0);
14970Sstevel@tonic-gate 	    iter = iter->next) {
14980Sstevel@tonic-gate 
14990Sstevel@tonic-gate 	    devconfig_t	*dev = (devconfig_t *)iter->obj;
15000Sstevel@tonic-gate 	    if (devconfig_isA(dev, TYPE_SLICE)) {
15010Sstevel@tonic-gate 
15020Sstevel@tonic-gate 		dm_descriptor_t	disk = NULL;
15030Sstevel@tonic-gate 		char		*name = NULL;
15040Sstevel@tonic-gate 
15050Sstevel@tonic-gate 		/* get disk for component slice */
15060Sstevel@tonic-gate 		((error = devconfig_get_name(dev, &name)) != 0) ||
15070Sstevel@tonic-gate 		(error = get_disk_for_named_slice(name, &disk));
15080Sstevel@tonic-gate 		if (error == 0) {
1509*62Sjeanm 		    dlist_t *item = dlist_new_item((void *)(uintptr_t)disk);
15100Sstevel@tonic-gate 		    if (item == NULL) {
15110Sstevel@tonic-gate 			error = ENOMEM;
15120Sstevel@tonic-gate 		    } else {
15130Sstevel@tonic-gate 			*disks = dlist_append(item, *disks, AT_HEAD);
15140Sstevel@tonic-gate 		    }
15150Sstevel@tonic-gate 		}
15160Sstevel@tonic-gate 
15170Sstevel@tonic-gate 		/* get HBAs for disk */
15180Sstevel@tonic-gate 		if (error == 0) {
15190Sstevel@tonic-gate 		    dlist_t *disk_hbas = NULL;
15200Sstevel@tonic-gate 		    if ((error = disk_get_hbas(disk, &disk_hbas)) == 0) {
15210Sstevel@tonic-gate 			/* the hba list may contain dups, but that's ok */
15220Sstevel@tonic-gate 			*hbas = dlist_append(disk_hbas, *hbas, AT_HEAD);
15230Sstevel@tonic-gate 		    }
15240Sstevel@tonic-gate 		}
15250Sstevel@tonic-gate 
15260Sstevel@tonic-gate 	    } else if (devconfig_isA(dev, TYPE_MIRROR)) {
15270Sstevel@tonic-gate 
15280Sstevel@tonic-gate 		/* collect info for submirrors */
15290Sstevel@tonic-gate 		dlist_t *iter1;
15300Sstevel@tonic-gate 		for (iter1 = devconfig_get_components(dev);
15310Sstevel@tonic-gate 		    (iter1 != NULL) && (error == 0);
15320Sstevel@tonic-gate 		    iter1 = iter1->next) {
15330Sstevel@tonic-gate 		    error = get_hbas_and_disks_used_by_volume(
15340Sstevel@tonic-gate 			    (devconfig_t *)iter1->obj, hbas, disks);
15350Sstevel@tonic-gate 		}
15360Sstevel@tonic-gate 
15370Sstevel@tonic-gate 	    }
15380Sstevel@tonic-gate 	}
15390Sstevel@tonic-gate 
15400Sstevel@tonic-gate 	return (error);
15410Sstevel@tonic-gate }
15420Sstevel@tonic-gate 
15430Sstevel@tonic-gate /*
15440Sstevel@tonic-gate  * FUNCTION:	compare_hba_n_avail_disks(void *obj1, void *obj2)
15450Sstevel@tonic-gate  *
15460Sstevel@tonic-gate  * INPUT:	obj1	- opaque pointer
15470Sstevel@tonic-gate  * 		obj2	- opaque pointer
15480Sstevel@tonic-gate  *
15490Sstevel@tonic-gate  * RETURNS:	int	- <0 - if obj1 has fewer available disks than obj2
15500Sstevel@tonic-gate  *			   0 - if obj1 has the same # of available disks as obj2
15510Sstevel@tonic-gate  *			  >0 - if obj1 has more available disks than obj2
15520Sstevel@tonic-gate  *
15530Sstevel@tonic-gate  * PURPOSE:	dlist_t helper which compares the number of available disks
15540Sstevel@tonic-gate  *		for two HBAs represented as dm_descriptor_t handles.
15550Sstevel@tonic-gate  *
15560Sstevel@tonic-gate  *		Both input objects are assumed to be dm_descriptor_t handles.
15570Sstevel@tonic-gate  *
15580Sstevel@tonic-gate  *		The number of available disks associated with the HBAs was
15590Sstevel@tonic-gate  *		computed and saved in select_hbas_with_n_disks(), this
15600Sstevel@tonic-gate  *		function just checks the saved values.
15610Sstevel@tonic-gate  */
15620Sstevel@tonic-gate static int
compare_hba_n_avail_disks(void * obj1,void * obj2)15630Sstevel@tonic-gate compare_hba_n_avail_disks(
15640Sstevel@tonic-gate 	void		*obj1,
15650Sstevel@tonic-gate 	void		*obj2)
15660Sstevel@tonic-gate {
15670Sstevel@tonic-gate 	uint16_t	n1 = 0;
15680Sstevel@tonic-gate 	uint16_t	n2 = 0;
15690Sstevel@tonic-gate 
15700Sstevel@tonic-gate 	assert(obj1 != NULL);
15710Sstevel@tonic-gate 	assert(obj2 != NULL);
15720Sstevel@tonic-gate 
15730Sstevel@tonic-gate 	(void) hba_get_n_avail_disks((uintptr_t)obj1, &n1);
15740Sstevel@tonic-gate 	(void) hba_get_n_avail_disks((uintptr_t)obj2, &n2);
15750Sstevel@tonic-gate 
15760Sstevel@tonic-gate 	return ((int)n1 - n2);
15770Sstevel@tonic-gate }
15780Sstevel@tonic-gate 
15790Sstevel@tonic-gate /*
15800Sstevel@tonic-gate  * FUNCTION:	is_device_avail(dm_descriptor_t desc,
15810Sstevel@tonic-gate  *			devconfig_t *request, boolean_t *avail)
15820Sstevel@tonic-gate  *
15830Sstevel@tonic-gate  * INPUT:	desc	- a dm_descriptor_t device handle
15840Sstevel@tonic-gate  *		request	- pointer to a devconfig_t struct representing
15850Sstevel@tonic-gate  *				the current layout request being processed
15860Sstevel@tonic-gate  * 		avail	- pointer to a boolean to hold the result
15870Sstevel@tonic-gate  *
15880Sstevel@tonic-gate  * RETURNS:	int	-  0 - on success
15890Sstevel@tonic-gate  *			  !0 - otherwise
15900Sstevel@tonic-gate  *
15910Sstevel@tonic-gate  * PURPOSE:	Internal helper which determines if the input device can
15920Sstevel@tonic-gate  *		be used as a volume component when satisfying the input
15930Sstevel@tonic-gate  *		request.
15940Sstevel@tonic-gate  *
15950Sstevel@tonic-gate  *		The device is assumed to be a known valid device.
15960Sstevel@tonic-gate  *
15970Sstevel@tonic-gate  *		The function checks if the device passes the request's
15980Sstevel@tonic-gate  *		available and unavailable device specifications.
15990Sstevel@tonic-gate  *
16000Sstevel@tonic-gate  *		The input device name may be either a DID name or a CTD
16010Sstevel@tonic-gate  *		name.  All name comparisons are done using the CTD name.
16020Sstevel@tonic-gate  */
16030Sstevel@tonic-gate static int
is_device_avail(dm_descriptor_t desc,devconfig_t * request,boolean_t * avail)16040Sstevel@tonic-gate is_device_avail(
16050Sstevel@tonic-gate 	dm_descriptor_t	desc,
16060Sstevel@tonic-gate 	devconfig_t	*request,
16070Sstevel@tonic-gate 	boolean_t	*avail)
16080Sstevel@tonic-gate {
16090Sstevel@tonic-gate 	char		*name = NULL;
16100Sstevel@tonic-gate 	int		error = 0;
16110Sstevel@tonic-gate 
16120Sstevel@tonic-gate 	*avail = B_FALSE;
16130Sstevel@tonic-gate 
16140Sstevel@tonic-gate 	if ((error = get_display_name(desc, &name)) == 0) {
16150Sstevel@tonic-gate 	    error = is_named_device_avail(request, name, B_TRUE, avail);
16160Sstevel@tonic-gate 	}
16170Sstevel@tonic-gate 
16180Sstevel@tonic-gate 	return (error);
16190Sstevel@tonic-gate }
16200Sstevel@tonic-gate 
16210Sstevel@tonic-gate /*
16220Sstevel@tonic-gate  * FUNCTION:	compare_request_to_request_spec_list_request(
16230Sstevel@tonic-gate  *			void *request, void *list_item)
16240Sstevel@tonic-gate  *
16250Sstevel@tonic-gate  * INPUT:	request	- opaque pointer to a devconfig_t
16260Sstevel@tonic-gate  * 		list_item - opaque pointer to a request_spec_list_t
16270Sstevel@tonic-gate  *
16280Sstevel@tonic-gate  * RETURNS:	int	- 0 - if request is the same as list_item->request
16290Sstevel@tonic-gate  *			  !0 - otherwise
16300Sstevel@tonic-gate  *
16310Sstevel@tonic-gate  * PURPOSE:	dlist_t helper which compares the input request pointer
16320Sstevel@tonic-gate  *		to the list_item's request pointer for equality.
16330Sstevel@tonic-gate  *
16340Sstevel@tonic-gate  *		This function is the lookup mechanism for the lists of
16350Sstevel@tonic-gate  *		cached device_spec_ts representing available/unavailable
16360Sstevel@tonic-gate  *		devices for a given defaults_t request/defaults struct.
16370Sstevel@tonic-gate  *
16380Sstevel@tonic-gate  *		The defaults_t struct pointer is the lookup key.
16390Sstevel@tonic-gate  */
16400Sstevel@tonic-gate static int
compare_request_to_request_spec_list_request(void * request,void * list_item)16410Sstevel@tonic-gate compare_request_to_request_spec_list_request(
16420Sstevel@tonic-gate 	void *request,
16430Sstevel@tonic-gate 	void *list_item)
16440Sstevel@tonic-gate {
16450Sstevel@tonic-gate 	request_spec_list_t *entry =
16460Sstevel@tonic-gate 	    (request_spec_list_t *)list_item;
16470Sstevel@tonic-gate 
16480Sstevel@tonic-gate 	assert(request != NULL);
16490Sstevel@tonic-gate 	assert(entry != NULL);
16500Sstevel@tonic-gate 
16510Sstevel@tonic-gate 	/* compare two devconfig_t pointers, if identical, return 0 */
16520Sstevel@tonic-gate 	return ((devconfig_t *)request != entry->request);
16530Sstevel@tonic-gate }
16540Sstevel@tonic-gate 
16550Sstevel@tonic-gate /*
16560Sstevel@tonic-gate  * FUNCTION:	compare_device_spec_specificity(void *spec1, void *spec2)
16570Sstevel@tonic-gate  *
16580Sstevel@tonic-gate  * INPUT:	spec1	- opaque pointer to a device_spec_t
16590Sstevel@tonic-gate  * 		spec2	- opaque pointer to a device_spec_t
16600Sstevel@tonic-gate  *
16610Sstevel@tonic-gate  * RETURNS:	int	- <0 - if spec1 is less specific than spec2
16620Sstevel@tonic-gate  *			   0 - if spec1 is as specific than spec2
16630Sstevel@tonic-gate  *			  >0 - if spec1 is more specific than spec2
16640Sstevel@tonic-gate  *
16650Sstevel@tonic-gate  * PURPOSE:	dlist_t helper which compares the level of specificity
16660Sstevel@tonic-gate  *		in the two input device_spec_t structs.  The one
16670Sstevel@tonic-gate  *		which specifies more "components" of a cXtXdXsX device
16680Sstevel@tonic-gate  *		name is considered more specific.
16690Sstevel@tonic-gate  */
16700Sstevel@tonic-gate static int
compare_device_spec_specificity(void * spec1,void * spec2)16710Sstevel@tonic-gate compare_device_spec_specificity(
16720Sstevel@tonic-gate 	void	*spec1,
16730Sstevel@tonic-gate 	void	*spec2)
16740Sstevel@tonic-gate {
16750Sstevel@tonic-gate 	if (spec1 == NULL || spec2 == NULL) {
16760Sstevel@tonic-gate 	    return (-1);
16770Sstevel@tonic-gate 	}
16780Sstevel@tonic-gate 
16790Sstevel@tonic-gate 	if ((((device_spec_t *)spec1)->data.ctd->slice != ID_UNSPECIFIED) &&
16800Sstevel@tonic-gate 	    (((device_spec_t *)spec2)->data.ctd->slice == ID_UNSPECIFIED)) {
16810Sstevel@tonic-gate 	    /* spec1 has slice, spec2 does not, spec1 more specific */
16820Sstevel@tonic-gate 	    return (1);
16830Sstevel@tonic-gate 	}
16840Sstevel@tonic-gate 
16850Sstevel@tonic-gate 	if ((((device_spec_t *)spec2)->data.ctd->slice != ID_UNSPECIFIED) &&
16860Sstevel@tonic-gate 	    (((device_spec_t *)spec1)->data.ctd->slice == ID_UNSPECIFIED)) {
16870Sstevel@tonic-gate 	    /* spec2 has slice, spec1 does not, spec2 more specific */
16880Sstevel@tonic-gate 	    return (-1);
16890Sstevel@tonic-gate 	}
16900Sstevel@tonic-gate 
16910Sstevel@tonic-gate 	if ((((device_spec_t *)spec2)->data.ctd->slice != ID_UNSPECIFIED) &&
16920Sstevel@tonic-gate 	    (((device_spec_t *)spec1)->data.ctd->slice != ID_UNSPECIFIED)) {
16930Sstevel@tonic-gate 	    /* both spec1 and spec2 have slice */
16940Sstevel@tonic-gate 	    return (0);
16950Sstevel@tonic-gate 	}
16960Sstevel@tonic-gate 
16970Sstevel@tonic-gate 	if ((((device_spec_t *)spec1)->data.ctd->lun != ID_UNSPECIFIED) &&
16980Sstevel@tonic-gate 	    (((device_spec_t *)spec2)->data.ctd->lun == ID_UNSPECIFIED)) {
16990Sstevel@tonic-gate 	    /* spec1 has lun, spec2 does not, spec1 more specific */
17000Sstevel@tonic-gate 	    return (1);
17010Sstevel@tonic-gate 	}
17020Sstevel@tonic-gate 
17030Sstevel@tonic-gate 	if ((((device_spec_t *)spec2)->data.ctd->lun != ID_UNSPECIFIED) &&
17040Sstevel@tonic-gate 	    (((device_spec_t *)spec1)->data.ctd->lun == ID_UNSPECIFIED)) {
17050Sstevel@tonic-gate 	    /* spec2 has lun, spec1 does not, spec2 more specific */
17060Sstevel@tonic-gate 	    return (-1);
17070Sstevel@tonic-gate 	}
17080Sstevel@tonic-gate 
17090Sstevel@tonic-gate 	if ((((device_spec_t *)spec2)->data.ctd->lun != ID_UNSPECIFIED) &&
17100Sstevel@tonic-gate 	    (((device_spec_t *)spec1)->data.ctd->lun != ID_UNSPECIFIED)) {
17110Sstevel@tonic-gate 	    /* both spec1 and spec2 have lun */
17120Sstevel@tonic-gate 	    return (0);
17130Sstevel@tonic-gate 	}
17140Sstevel@tonic-gate 
17150Sstevel@tonic-gate 	if ((((device_spec_t *)spec1)->data.ctd->target != ID_UNSPECIFIED) &&
17160Sstevel@tonic-gate 	    (((device_spec_t *)spec2)->data.ctd->target == ID_UNSPECIFIED)) {
17170Sstevel@tonic-gate 	    /* spec1 has target, spec2 does not, spec1 more specific */
17180Sstevel@tonic-gate 	    return (1);
17190Sstevel@tonic-gate 	}
17200Sstevel@tonic-gate 
17210Sstevel@tonic-gate 	if ((((device_spec_t *)spec2)->data.ctd->target != ID_UNSPECIFIED) &&
17220Sstevel@tonic-gate 	    (((device_spec_t *)spec1)->data.ctd->target == ID_UNSPECIFIED)) {
17230Sstevel@tonic-gate 	    /* spec2 has target, spec1 does not, spec2 more specific */
17240Sstevel@tonic-gate 	    return (-1);
17250Sstevel@tonic-gate 	}
17260Sstevel@tonic-gate 
17270Sstevel@tonic-gate 	if ((((device_spec_t *)spec2)->data.ctd->target != ID_UNSPECIFIED) &&
17280Sstevel@tonic-gate 	    (((device_spec_t *)spec1)->data.ctd->target != ID_UNSPECIFIED)) {
17290Sstevel@tonic-gate 	    /* both spec1 and spec2 have target */
17300Sstevel@tonic-gate 	    return (0);
17310Sstevel@tonic-gate 	}
17320Sstevel@tonic-gate 
17330Sstevel@tonic-gate 	/* both specify just ctrl */
17340Sstevel@tonic-gate 	return (0);
17350Sstevel@tonic-gate }
17360Sstevel@tonic-gate 
17370Sstevel@tonic-gate /*
17380Sstevel@tonic-gate  * FUNCTION:	find_request_spec_list_entry(devconfig_t *request)
17390Sstevel@tonic-gate  *
17400Sstevel@tonic-gate  * INPUT:	request	- pointer to a devconfig_t struct
17410Sstevel@tonic-gate  *
17420Sstevel@tonic-gate  * RETURNS:	request_spec_list_entry - pointer to a
17430Sstevel@tonic-gate  *			request_spec_list_entry struct
17440Sstevel@tonic-gate  *
17450Sstevel@tonic-gate  * PURPOSE:	Lookup function which encapsulates the details of locating
17460Sstevel@tonic-gate  *		the device_spec_list_t cache entry for the input request.
17470Sstevel@tonic-gate  */
17480Sstevel@tonic-gate static request_spec_list_t *
find_request_spec_list_entry(devconfig_t * request)17490Sstevel@tonic-gate find_request_spec_list_entry(
17500Sstevel@tonic-gate 	devconfig_t *request)
17510Sstevel@tonic-gate {
17520Sstevel@tonic-gate 	dlist_t *list_item = NULL;
17530Sstevel@tonic-gate 	request_spec_list_t *entry = NULL;
17540Sstevel@tonic-gate 
17550Sstevel@tonic-gate 	list_item = dlist_find(
17560Sstevel@tonic-gate 		_request_spec_list_cache,
17570Sstevel@tonic-gate 		(void *)request,
17580Sstevel@tonic-gate 		compare_request_to_request_spec_list_request);
17590Sstevel@tonic-gate 
17600Sstevel@tonic-gate 	if (list_item != NULL) {
17610Sstevel@tonic-gate 	    entry = (request_spec_list_t *)list_item->obj;
17620Sstevel@tonic-gate 	}
17630Sstevel@tonic-gate 
17640Sstevel@tonic-gate 	return (entry);
17650Sstevel@tonic-gate }
17660Sstevel@tonic-gate 
17670Sstevel@tonic-gate /*
17680Sstevel@tonic-gate  * FUNCTION:	add_request_spec_list_entry(devconfig_t *request,
17690Sstevel@tonic-gate  *			char **avail_device_specs, char **unavail_device_specs,
17700Sstevel@tonic-gate  *			request_spec_list_entry_t **entry)
17710Sstevel@tonic-gate  *
17720Sstevel@tonic-gate  * INPUT:	entry - pointer to the request_spec_list_entry struct to be
17730Sstevel@tonic-gate  *			added to the cache.
17740Sstevel@tonic-gate  *
17750Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
17760Sstevel@tonic-gate  *			 !0 otherwise.
17770Sstevel@tonic-gate  *
17780Sstevel@tonic-gate  * PURPOSE:	Function which encapsulates the details of adding a
17790Sstevel@tonic-gate  *		device_spec_list_t cache entry.
17800Sstevel@tonic-gate  */
17810Sstevel@tonic-gate static int
add_request_spec_list_entry(request_spec_list_t * entry)17820Sstevel@tonic-gate add_request_spec_list_entry(
17830Sstevel@tonic-gate 	request_spec_list_t *entry)
17840Sstevel@tonic-gate {
17850Sstevel@tonic-gate 	dlist_t *list_item = dlist_new_item((void *)entry);
17860Sstevel@tonic-gate 
17870Sstevel@tonic-gate 	if (list_item == NULL) {
17880Sstevel@tonic-gate 	    return (ENOMEM);
17890Sstevel@tonic-gate 	}
17900Sstevel@tonic-gate 
17910Sstevel@tonic-gate 	_request_spec_list_cache = dlist_append(list_item,
17920Sstevel@tonic-gate 		_request_spec_list_cache, AT_HEAD);
17930Sstevel@tonic-gate 
17940Sstevel@tonic-gate 	return (0);
17950Sstevel@tonic-gate }
17960Sstevel@tonic-gate 
17970Sstevel@tonic-gate /*
17980Sstevel@tonic-gate  * FUNCTION:	make_request_spec_list_entry(devconfig_t *request,
17990Sstevel@tonic-gate  *			char **avail_device_specs, char **unavail_device_specs,
18000Sstevel@tonic-gate  *			request_spec_list_entry_t **entry)
18010Sstevel@tonic-gate  *
18020Sstevel@tonic-gate  * INPUT:	request	- pointer to a devconfig_t struct
18030Sstevel@tonic-gate  *		avail_device_specs - char * array of user specified available
18040Sstevel@tonic-gate  *			devices associated with the input request
18050Sstevel@tonic-gate  *		unavail_device_specs - char * array of user specified
18060Sstevel@tonic-gate  *			unavailable devices associated with the input
18070Sstevel@tonic-gate  *			request
18080Sstevel@tonic-gate  *
18090Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
18100Sstevel@tonic-gate  *			 !0 otherwise.
18110Sstevel@tonic-gate  *
18120Sstevel@tonic-gate  * PURPOSE:	Function which encapsulates the details of generating a new
18130Sstevel@tonic-gate  *		the device_spec_list_t cache entry for the input request
18140Sstevel@tonic-gate  *		and its lists of avail/unavail devices.
18150Sstevel@tonic-gate  *
18160Sstevel@tonic-gate  *		Converts the input arrays of (un)available device names into
18170Sstevel@tonic-gate  *		equivalent lists of device_spec_t structs.
18180Sstevel@tonic-gate  *
18190Sstevel@tonic-gate  *		Creates a new cache entry, populates it and adds it to the
18200Sstevel@tonic-gate  *		cache.
18210Sstevel@tonic-gate  */
18220Sstevel@tonic-gate static int
make_request_spec_list_entry(devconfig_t * request,char ** avail_device_specs,char ** unavail_device_specs,request_spec_list_t ** entry)18230Sstevel@tonic-gate make_request_spec_list_entry(
18240Sstevel@tonic-gate 	devconfig_t *request,
18250Sstevel@tonic-gate 	char	**avail_device_specs,
18260Sstevel@tonic-gate 	char	**unavail_device_specs,
18270Sstevel@tonic-gate 	request_spec_list_t **entry)
18280Sstevel@tonic-gate {
18290Sstevel@tonic-gate 	int error = 0;
18300Sstevel@tonic-gate 	dlist_t *list = NULL;
18310Sstevel@tonic-gate 
18320Sstevel@tonic-gate 	*entry = calloc(1, sizeof (request_spec_list_t));
18330Sstevel@tonic-gate 	if (*entry == NULL) {
18340Sstevel@tonic-gate 	    return (ENOMEM);
18350Sstevel@tonic-gate 	}
18360Sstevel@tonic-gate 
18370Sstevel@tonic-gate 	(*entry)->request = request;
18380Sstevel@tonic-gate 
18390Sstevel@tonic-gate 	/*
18400Sstevel@tonic-gate 	 * map the avail_device_name array into a list of device_spec_t
18410Sstevel@tonic-gate 	 * and save the list as the entry's available list
18420Sstevel@tonic-gate 	 */
18430Sstevel@tonic-gate 	error = convert_usernames_to_specs(
18440Sstevel@tonic-gate 		avail_device_specs, &list);
18450Sstevel@tonic-gate 
18460Sstevel@tonic-gate 	if (error == 0) {
18470Sstevel@tonic-gate 	    (*entry)->avail_specs_list = list;
18480Sstevel@tonic-gate 	}
18490Sstevel@tonic-gate 
18500Sstevel@tonic-gate 	/*
18510Sstevel@tonic-gate 	 * map the unavail_device_name array into a list of device_spec_t
18520Sstevel@tonic-gate 	 * and save the list as the entry's unavailable list
18530Sstevel@tonic-gate 	 */
18540Sstevel@tonic-gate 	list = NULL;
18550Sstevel@tonic-gate 	error = convert_usernames_to_specs(
18560Sstevel@tonic-gate 		unavail_device_specs, &list);
18570Sstevel@tonic-gate 
18580Sstevel@tonic-gate 	if (error == 0) {
18590Sstevel@tonic-gate 	    (*entry)->unavail_specs_list = list;
18600Sstevel@tonic-gate 	}
18610Sstevel@tonic-gate 
18620Sstevel@tonic-gate 	if (error != 0) {
18630Sstevel@tonic-gate 	    /* delete the partial entry */
18640Sstevel@tonic-gate 	    destroy_request_spec_list_entry((void *)*entry);
18650Sstevel@tonic-gate 	    *entry = NULL;
18660Sstevel@tonic-gate 	}
18670Sstevel@tonic-gate 
18680Sstevel@tonic-gate 	return (error);
18690Sstevel@tonic-gate }
18700Sstevel@tonic-gate 
18710Sstevel@tonic-gate /*
18720Sstevel@tonic-gate  * FUNCTION:	convert_usernames_to_specs(char **specs, dlist_t **list)
18730Sstevel@tonic-gate  *
18740Sstevel@tonic-gate  * INPUT:	specs	- char * array of device CTD names
18750Sstevel@tonic-gate  *
18760Sstevel@tonic-gate  * OUTPUT:	list	- pointer to a list of device_spec_t corresponding
18770Sstevel@tonic-gate  *				to each name in the input array
18780Sstevel@tonic-gate  *
18790Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
18800Sstevel@tonic-gate  *			 !0 otherwise.
18810Sstevel@tonic-gate  *
18820Sstevel@tonic-gate  * PURPOSE:	Function which converts the input CTD device names to the
18830Sstevel@tonic-gate  *		equivalent device_spec_t structs.
18840Sstevel@tonic-gate  *
18850Sstevel@tonic-gate  *		Iterates the input array and converts each CTD name to a
18860Sstevel@tonic-gate  *		device_spec_t using get_spec_for_name().
18870Sstevel@tonic-gate  */
18880Sstevel@tonic-gate static int
convert_usernames_to_specs(char ** specs,dlist_t ** list)18890Sstevel@tonic-gate convert_usernames_to_specs(
18900Sstevel@tonic-gate 	char	**specs,
18910Sstevel@tonic-gate 	dlist_t **list)
18920Sstevel@tonic-gate {
18930Sstevel@tonic-gate 	int i = 0;
18940Sstevel@tonic-gate 	int error = 0;
18950Sstevel@tonic-gate 
18960Sstevel@tonic-gate 	/*
18970Sstevel@tonic-gate 	 * For each spec in the array, get the corresponding
18980Sstevel@tonic-gate 	 * device_spec_t and add it to the list.
18990Sstevel@tonic-gate 	 *
19000Sstevel@tonic-gate 	 * Any spec in the array that looks to be a DID name
19010Sstevel@tonic-gate 	 * is first converted to its equivalent CTD name.
19020Sstevel@tonic-gate 	 */
19030Sstevel@tonic-gate 	for (i = 0;
19040Sstevel@tonic-gate 	    (specs != NULL) && (specs[i] != NULL) && (error == 0);
19050Sstevel@tonic-gate 	    i++) {
19060Sstevel@tonic-gate 
19070Sstevel@tonic-gate 	    device_spec_t *spec = NULL;
19080Sstevel@tonic-gate 	    char *userspec = specs[i];
19090Sstevel@tonic-gate 
19100Sstevel@tonic-gate 	    error = get_spec_for_name(userspec, &spec);
19110Sstevel@tonic-gate 	    if ((error == 0) && (spec != NULL)) {
19120Sstevel@tonic-gate 		dlist_t *list_item = dlist_new_item((void *)spec);
19130Sstevel@tonic-gate 		if (spec == NULL) {
19140Sstevel@tonic-gate 		    error = ENOMEM;
19150Sstevel@tonic-gate 		} else {
19160Sstevel@tonic-gate 		    *list = dlist_insert_ordered
19170Sstevel@tonic-gate 			(list_item, *list, DESCENDING,
19180Sstevel@tonic-gate 				compare_device_spec_specificity);
19190Sstevel@tonic-gate 		}
19200Sstevel@tonic-gate 	    }
19210Sstevel@tonic-gate 	}
19220Sstevel@tonic-gate 
19230Sstevel@tonic-gate 	if (error != 0) {
19240Sstevel@tonic-gate 	    /* the device_spec_t in the list items are maintained */
19250Sstevel@tonic-gate 	    /* in a cache elsewhere, so don't free them here. */
19260Sstevel@tonic-gate 	    dlist_free_items(*list, NULL);
19270Sstevel@tonic-gate 	    *list = NULL;
19280Sstevel@tonic-gate 	}
19290Sstevel@tonic-gate 
19300Sstevel@tonic-gate 	return (error);
19310Sstevel@tonic-gate }
19320Sstevel@tonic-gate 
19330Sstevel@tonic-gate /*
19340Sstevel@tonic-gate  * FUNCTION:	destroy_request_spec_list_entry(void *entry)
19350Sstevel@tonic-gate  *
19360Sstevel@tonic-gate  * INPUT:	entry	- opaque pointer to a request_spec_list_t
19370Sstevel@tonic-gate  *
19380Sstevel@tonic-gate  * RETURNS:	nothing
19390Sstevel@tonic-gate  *
19400Sstevel@tonic-gate  * PURPOSE:	Function which reclaims memory allocated to a
19410Sstevel@tonic-gate  *		request_spec_list_t.
19420Sstevel@tonic-gate  *
19430Sstevel@tonic-gate  *		Frees memory allocated to the avail_spec_list and
19440Sstevel@tonic-gate  *		unavail_spec_list.  Entries in the list are not freed,
19450Sstevel@tonic-gate  *		since they are owned by the device_spec cache.
19460Sstevel@tonic-gate  */
19470Sstevel@tonic-gate static void
destroy_request_spec_list_entry(void * obj)19480Sstevel@tonic-gate destroy_request_spec_list_entry(
19490Sstevel@tonic-gate 	void *obj)
19500Sstevel@tonic-gate {
19510Sstevel@tonic-gate 	request_spec_list_t *entry = (request_spec_list_t *)obj;
19520Sstevel@tonic-gate 
19530Sstevel@tonic-gate 	if (entry != NULL) {
19540Sstevel@tonic-gate 	    /* items in the list are in the spec_cache and will */
19550Sstevel@tonic-gate 	    /* be cleaned up when it is destroyed. */
19560Sstevel@tonic-gate 	    dlist_free_items(entry->avail_specs_list, NULL);
19570Sstevel@tonic-gate 	    dlist_free_items(entry->unavail_specs_list, NULL);
19580Sstevel@tonic-gate 	    free(entry);
19590Sstevel@tonic-gate 	}
19600Sstevel@tonic-gate }
19610Sstevel@tonic-gate 
19620Sstevel@tonic-gate /*
19630Sstevel@tonic-gate  * FUNCTION:	destroy_request_spec_list_cache()
19640Sstevel@tonic-gate  *
19650Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
19660Sstevel@tonic-gate  *			 !0 otherwise.
19670Sstevel@tonic-gate  *
19680Sstevel@tonic-gate  * PURPOSE:	Function which destroys all entries in the request_spec_list
19690Sstevel@tonic-gate  *		cache.
19700Sstevel@tonic-gate  */
19710Sstevel@tonic-gate static int
destroy_request_spec_list_cache()19720Sstevel@tonic-gate destroy_request_spec_list_cache()
19730Sstevel@tonic-gate {
19740Sstevel@tonic-gate 	dlist_free_items(_request_spec_list_cache,
19750Sstevel@tonic-gate 		destroy_request_spec_list_entry);
19760Sstevel@tonic-gate 	_request_spec_list_cache = NULL;
19770Sstevel@tonic-gate 
19780Sstevel@tonic-gate 	return (0);
19790Sstevel@tonic-gate }
19800Sstevel@tonic-gate 
19810Sstevel@tonic-gate /*
19820Sstevel@tonic-gate  * FUNCTION:	get_request_avail_spec_list(devconfig_t *request,
19830Sstevel@tonic-gate  *			dlist_t **list)
19840Sstevel@tonic-gate  *
19850Sstevel@tonic-gate  * INPUT:	request	- a pointer to a devconfig_t
19860Sstevel@tonic-gate  *
19870Sstevel@tonic-gate  * OUTPUT:	list	- pointer to a list of device_spec_t corresponding
19880Sstevel@tonic-gate  *				to the devices specified as available by the
19890Sstevel@tonic-gate  *				input request.
19900Sstevel@tonic-gate  *
19910Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
19920Sstevel@tonic-gate  *			 !0 otherwise.
19930Sstevel@tonic-gate  *
19940Sstevel@tonic-gate  * PURPOSE:	Function which locates or builds the list of device_spec_t
19950Sstevel@tonic-gate  *		for the available devices specified in the input request.
19960Sstevel@tonic-gate  *
19970Sstevel@tonic-gate  *		Looks up the input request in the request_spec_list cache.
19980Sstevel@tonic-gate  *		If there is currently no entry in the cache for the request,
19990Sstevel@tonic-gate  *		an entry is built and added.
20000Sstevel@tonic-gate  *
20010Sstevel@tonic-gate  *		The entry's list of available device_spec_t is returned.
20020Sstevel@tonic-gate  */
20030Sstevel@tonic-gate static int
get_request_avail_spec_list(devconfig_t * request,dlist_t ** list)20040Sstevel@tonic-gate get_request_avail_spec_list(
20050Sstevel@tonic-gate 	devconfig_t *request,
20060Sstevel@tonic-gate 	dlist_t	    **list)
20070Sstevel@tonic-gate {
20080Sstevel@tonic-gate 	request_spec_list_t *entry = NULL;
20090Sstevel@tonic-gate 	int error = 0;
20100Sstevel@tonic-gate 
20110Sstevel@tonic-gate 	if ((entry = find_request_spec_list_entry(request)) == NULL) {
20120Sstevel@tonic-gate 
20130Sstevel@tonic-gate 	    /* create cache entry for this request */
20140Sstevel@tonic-gate 	    error = make_request_spec_list_entry(
20150Sstevel@tonic-gate 		    request,
20160Sstevel@tonic-gate 		    devconfig_get_available(request),
20170Sstevel@tonic-gate 		    devconfig_get_unavailable(request),
20180Sstevel@tonic-gate 		    &entry);
20190Sstevel@tonic-gate 
20200Sstevel@tonic-gate 	    if ((error == 0) && (entry != NULL)) {
20210Sstevel@tonic-gate 		if ((error = add_request_spec_list_entry(entry)) != 0) {
20220Sstevel@tonic-gate 		    destroy_request_spec_list_entry(entry);
20230Sstevel@tonic-gate 		    entry = NULL;
20240Sstevel@tonic-gate 		}
20250Sstevel@tonic-gate 	    }
20260Sstevel@tonic-gate 	}
20270Sstevel@tonic-gate 
20280Sstevel@tonic-gate 	if ((error == 0) && (entry != NULL)) {
20290Sstevel@tonic-gate 	    *list = entry->avail_specs_list;
20300Sstevel@tonic-gate 	}
20310Sstevel@tonic-gate 
20320Sstevel@tonic-gate 	return (error);
20330Sstevel@tonic-gate }
20340Sstevel@tonic-gate 
20350Sstevel@tonic-gate /*
20360Sstevel@tonic-gate  * FUNCTION:	get_request_unavail_spec_list(devconfig_t *request,
20370Sstevel@tonic-gate  *			dlist_t **list)
20380Sstevel@tonic-gate  *
20390Sstevel@tonic-gate  * INPUT:	request	- a pointer to a devconfig_t
20400Sstevel@tonic-gate  *
20410Sstevel@tonic-gate  * OUTPUT:	list	- pointer to a list of device_spec_t corresponding
20420Sstevel@tonic-gate  *				to the devices specified as unavailable by the
20430Sstevel@tonic-gate  *				input request.
20440Sstevel@tonic-gate  *
20450Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
20460Sstevel@tonic-gate  *			 !0 otherwise.
20470Sstevel@tonic-gate  *
20480Sstevel@tonic-gate  * PURPOSE:	Function which locates or builds the list of device_spec_t
20490Sstevel@tonic-gate  *		for the unavailable devices specified in the input request.
20500Sstevel@tonic-gate  *
20510Sstevel@tonic-gate  *		Looks up the input request in the request_spec_list cache.
20520Sstevel@tonic-gate  *		If there is currently no entry in the cache for the request,
20530Sstevel@tonic-gate  *		an entry is built and added.
20540Sstevel@tonic-gate  *
20550Sstevel@tonic-gate  *		The entry's list of unavailable device_spec_t is returned.
20560Sstevel@tonic-gate  */
20570Sstevel@tonic-gate static int
get_request_unavail_spec_list(devconfig_t * request,dlist_t ** list)20580Sstevel@tonic-gate get_request_unavail_spec_list(
20590Sstevel@tonic-gate 	devconfig_t *request,
20600Sstevel@tonic-gate 	dlist_t	    **list)
20610Sstevel@tonic-gate {
20620Sstevel@tonic-gate 	request_spec_list_t *entry = NULL;
20630Sstevel@tonic-gate 	int error = 0;
20640Sstevel@tonic-gate 
20650Sstevel@tonic-gate 	if ((entry = find_request_spec_list_entry(request)) == NULL) {
20660Sstevel@tonic-gate 
20670Sstevel@tonic-gate 	    /* create new entry for this request */
20680Sstevel@tonic-gate 	    error = make_request_spec_list_entry(
20690Sstevel@tonic-gate 		    request,
20700Sstevel@tonic-gate 		    devconfig_get_available(request),
20710Sstevel@tonic-gate 		    devconfig_get_unavailable(request),
20720Sstevel@tonic-gate 		    &entry);
20730Sstevel@tonic-gate 
20740Sstevel@tonic-gate 	    if ((error == 0) && (entry != NULL)) {
20750Sstevel@tonic-gate 		if ((error = add_request_spec_list_entry(entry)) != 0) {
20760Sstevel@tonic-gate 		    destroy_request_spec_list_entry(entry);
20770Sstevel@tonic-gate 		    entry = NULL;
20780Sstevel@tonic-gate 		}
20790Sstevel@tonic-gate 	    }
20800Sstevel@tonic-gate 	}
20810Sstevel@tonic-gate 
20820Sstevel@tonic-gate 	if ((error == 0) && (entry != NULL)) {
20830Sstevel@tonic-gate 	    *list = entry->unavail_specs_list;
20840Sstevel@tonic-gate 	}
20850Sstevel@tonic-gate 
20860Sstevel@tonic-gate 	return (error);
20870Sstevel@tonic-gate }
20880Sstevel@tonic-gate 
20890Sstevel@tonic-gate /*
20900Sstevel@tonic-gate  * FUNCTION:	get_default_avail_spec_list(defaults_t *defaults,
20910Sstevel@tonic-gate  *			char *dsname, dlist_t **list)
20920Sstevel@tonic-gate  *
20930Sstevel@tonic-gate  * INPUT:	defaults - a pointer to a defaults_t struct
20940Sstevel@tonic-gate  *		dsname	- the name of the diskset whose defaults should be used
20950Sstevel@tonic-gate  *
20960Sstevel@tonic-gate  * OUTPUT:	list	- pointer to a list of device_spec_t corresponding
20970Sstevel@tonic-gate  *				to the devices specified as available by the
20980Sstevel@tonic-gate  *				defaults for the named diskset, or the global
20990Sstevel@tonic-gate  *				defaults for all disksets.
21000Sstevel@tonic-gate  *
21010Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
21020Sstevel@tonic-gate  *			 !0 otherwise.
21030Sstevel@tonic-gate  *
21040Sstevel@tonic-gate  * PURPOSE:	Function which locates or builds the list of device_spec_t
21050Sstevel@tonic-gate  *		for the available devices for the named diskset.
21060Sstevel@tonic-gate  *
21070Sstevel@tonic-gate  *		Locates the defaults for the named diskset, if there are none,
21080Sstevel@tonic-gate  *		locates the global defaults for all disksets.
21090Sstevel@tonic-gate  *
21100Sstevel@tonic-gate  *		The defaults devconfig_t struct is then used to look up the
21110Sstevel@tonic-gate  *		the corresponding entry in the request_spec_list cache.
21120Sstevel@tonic-gate  *
21130Sstevel@tonic-gate  *		If there is currently no entry in the cache for the defaults,
21140Sstevel@tonic-gate  *		an entry is built and added.
21150Sstevel@tonic-gate  *
21160Sstevel@tonic-gate  *		The entry's list of available device_spec_t is returned.
21170Sstevel@tonic-gate  */
21180Sstevel@tonic-gate static int
get_default_avail_spec_list(defaults_t * alldefaults,char * dsname,dlist_t ** list)21190Sstevel@tonic-gate get_default_avail_spec_list(
21200Sstevel@tonic-gate 	defaults_t *alldefaults,
21210Sstevel@tonic-gate 	char	*dsname,
21220Sstevel@tonic-gate 	dlist_t	    **list)
21230Sstevel@tonic-gate {
21240Sstevel@tonic-gate 	request_spec_list_t *entry = NULL;
21250Sstevel@tonic-gate 	devconfig_t *defaults = NULL;
21260Sstevel@tonic-gate 	int error = 0;
21270Sstevel@tonic-gate 
21280Sstevel@tonic-gate 	/* Get diskset defaults, or global if none for diskset */
21290Sstevel@tonic-gate 	error = defaults_get_diskset_by_name(
21300Sstevel@tonic-gate 		alldefaults, dsname, &defaults);
21310Sstevel@tonic-gate 
21320Sstevel@tonic-gate 	if (error != 0) {
21330Sstevel@tonic-gate 	    if (error == ENOENT) {
21340Sstevel@tonic-gate 		/* to get global defaults, pass a NULL diskset name */
21350Sstevel@tonic-gate 		error = defaults_get_diskset_by_name(
21360Sstevel@tonic-gate 			alldefaults, NULL, &defaults);
21370Sstevel@tonic-gate 	    }
21380Sstevel@tonic-gate 
21390Sstevel@tonic-gate 	    if (error != 0) {
21400Sstevel@tonic-gate 		if (error != ENOENT) {
21410Sstevel@tonic-gate 		    oprintf(OUTPUT_DEBUG,
21420Sstevel@tonic-gate 			    gettext("get defaults for %s returned %d\n"),
21430Sstevel@tonic-gate 			    dsname, error);
21440Sstevel@tonic-gate 		} else {
21450Sstevel@tonic-gate 		    error = 0;
21460Sstevel@tonic-gate 		}
21470Sstevel@tonic-gate 	    }
21480Sstevel@tonic-gate 	}
21490Sstevel@tonic-gate 
21500Sstevel@tonic-gate 	if ((entry = find_request_spec_list_entry(defaults)) == NULL) {
21510Sstevel@tonic-gate 
21520Sstevel@tonic-gate 	    /* create new entry for these defaults */
21530Sstevel@tonic-gate 	    error = make_request_spec_list_entry(
21540Sstevel@tonic-gate 		    defaults,
21550Sstevel@tonic-gate 		    devconfig_get_available(defaults),
21560Sstevel@tonic-gate 		    devconfig_get_unavailable(defaults),
21570Sstevel@tonic-gate 		    &entry);
21580Sstevel@tonic-gate 
21590Sstevel@tonic-gate 	    if ((error == 0) && (entry != NULL)) {
21600Sstevel@tonic-gate 		if ((error = add_request_spec_list_entry(entry)) != 0) {
21610Sstevel@tonic-gate 		    destroy_request_spec_list_entry(entry);
21620Sstevel@tonic-gate 		    entry = NULL;
21630Sstevel@tonic-gate 		}
21640Sstevel@tonic-gate 	    }
21650Sstevel@tonic-gate 	}
21660Sstevel@tonic-gate 
21670Sstevel@tonic-gate 	if ((error == 0) && (entry != NULL)) {
21680Sstevel@tonic-gate 	    *list = entry->avail_specs_list;
21690Sstevel@tonic-gate 	}
21700Sstevel@tonic-gate 
21710Sstevel@tonic-gate 	return (error);
21720Sstevel@tonic-gate }
21730Sstevel@tonic-gate 
21740Sstevel@tonic-gate /*
21750Sstevel@tonic-gate  * FUNCTION:	get_default_unavail_spec_list(defaults_t *defaults,
21760Sstevel@tonic-gate  *			char *dsname, dlist_t **list)
21770Sstevel@tonic-gate  *
21780Sstevel@tonic-gate  * INPUT:	defaults - a pointer to a defaults_t struct
21790Sstevel@tonic-gate  *		dsname	- the name of the diskset whose defaults should be used
21800Sstevel@tonic-gate  *
21810Sstevel@tonic-gate  * OUTPUT:	list	- pointer to a list of device_spec_t corresponding
21820Sstevel@tonic-gate  *				to the devices specified as unavailable by the
21830Sstevel@tonic-gate  *				defaults for the named diskset, or the global
21840Sstevel@tonic-gate  *				defaults for all disksets.
21850Sstevel@tonic-gate  *
21860Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
21870Sstevel@tonic-gate  *			 !0 otherwise.
21880Sstevel@tonic-gate  *
21890Sstevel@tonic-gate  * PURPOSE:	Function which locates or builds the list of device_spec_t
21900Sstevel@tonic-gate  *		for the unavailable devices for the named diskset.
21910Sstevel@tonic-gate  *
21920Sstevel@tonic-gate  *		Locates the defaults for the named diskset, if there are none,
21930Sstevel@tonic-gate  *		locates the global defaults for all disksets.
21940Sstevel@tonic-gate  *
21950Sstevel@tonic-gate  *		The defaults devconfig_t struct is then used to look up the
21960Sstevel@tonic-gate  *		the corresponding entry in the request_spec_list cache.
21970Sstevel@tonic-gate  *
21980Sstevel@tonic-gate  *		If there is currently no entry in the cache for the defaults,
21990Sstevel@tonic-gate  *		an entry is built and added.
22000Sstevel@tonic-gate  *
22010Sstevel@tonic-gate  *		The entry's list of unavailable device_spec_t is returned.
22020Sstevel@tonic-gate  */
22030Sstevel@tonic-gate static int
get_default_unavail_spec_list(defaults_t * alldefaults,char * dsname,dlist_t ** list)22040Sstevel@tonic-gate get_default_unavail_spec_list(
22050Sstevel@tonic-gate 	defaults_t *alldefaults,
22060Sstevel@tonic-gate 	char	*dsname,
22070Sstevel@tonic-gate 	dlist_t	    **list)
22080Sstevel@tonic-gate {
22090Sstevel@tonic-gate 	request_spec_list_t *entry = NULL;
22100Sstevel@tonic-gate 	devconfig_t *defaults = NULL;
22110Sstevel@tonic-gate 	int error = 0;
22120Sstevel@tonic-gate 
22130Sstevel@tonic-gate 	/* Get diskset defaults, or global if none for diskset */
22140Sstevel@tonic-gate 	error = defaults_get_diskset_by_name(
22150Sstevel@tonic-gate 		alldefaults, dsname, &defaults);
22160Sstevel@tonic-gate 
22170Sstevel@tonic-gate 	if (error != 0) {
22180Sstevel@tonic-gate 
22190Sstevel@tonic-gate 	    if (error == ENOENT) {
22200Sstevel@tonic-gate 		/* to get global defaults, pass a NULL diskset name */
22210Sstevel@tonic-gate 		error = defaults_get_diskset_by_name(
22220Sstevel@tonic-gate 			alldefaults, NULL, &defaults);
22230Sstevel@tonic-gate 	    }
22240Sstevel@tonic-gate 
22250Sstevel@tonic-gate 	    if (error != 0) {
22260Sstevel@tonic-gate 		if (error != ENOENT) {
22270Sstevel@tonic-gate 		    oprintf(OUTPUT_DEBUG,
22280Sstevel@tonic-gate 			    gettext("get defaults for %s returned %d\n"),
22290Sstevel@tonic-gate 			    dsname, error);
22300Sstevel@tonic-gate 		} else {
22310Sstevel@tonic-gate 		    error = 0;
22320Sstevel@tonic-gate 		}
22330Sstevel@tonic-gate 	    }
22340Sstevel@tonic-gate 	}
22350Sstevel@tonic-gate 
22360Sstevel@tonic-gate 	if ((entry = find_request_spec_list_entry(defaults)) == NULL) {
22370Sstevel@tonic-gate 
22380Sstevel@tonic-gate 	    /* create new entry for these defaults */
22390Sstevel@tonic-gate 	    error = make_request_spec_list_entry(
22400Sstevel@tonic-gate 		    defaults,
22410Sstevel@tonic-gate 		    devconfig_get_available(defaults),
22420Sstevel@tonic-gate 		    devconfig_get_unavailable(defaults),
22430Sstevel@tonic-gate 		    &entry);
22440Sstevel@tonic-gate 
22450Sstevel@tonic-gate 	    if ((error == 0) && (entry != NULL)) {
22460Sstevel@tonic-gate 		if ((error = add_request_spec_list_entry(entry)) != 0) {
22470Sstevel@tonic-gate 		    destroy_request_spec_list_entry(entry);
22480Sstevel@tonic-gate 		    entry = NULL;
22490Sstevel@tonic-gate 		}
22500Sstevel@tonic-gate 	    }
22510Sstevel@tonic-gate 	}
22520Sstevel@tonic-gate 
22530Sstevel@tonic-gate 	if ((error == 0) && (entry != NULL)) {
22540Sstevel@tonic-gate 	    *list = entry->unavail_specs_list;
22550Sstevel@tonic-gate 	}
22560Sstevel@tonic-gate 
22570Sstevel@tonic-gate 	return (error);
22580Sstevel@tonic-gate }
22590Sstevel@tonic-gate 
22600Sstevel@tonic-gate /*
22610Sstevel@tonic-gate  * FUNCTION:	is_named_device_avail(devconfig_t *request, char *device_name,
22620Sstevel@tonic-gate  *			boolean_t check_aliases, boolean_t *avail)
22630Sstevel@tonic-gate  *
22640Sstevel@tonic-gate  * INPUT:	request - the current request devconfig_t
22650Sstevel@tonic-gate  *		device_name - char * device name
22660Sstevel@tonic-gate  *		check_aliases - boolean_t which indicates whether the device's
22670Sstevel@tonic-gate  *			aliases should be considered by the availability checks.
22680Sstevel@tonic-gate  *
22690Sstevel@tonic-gate  * OUTPUT:	avail	- a boolean_t * to hold the result
22700Sstevel@tonic-gate  *
22710Sstevel@tonic-gate  * RETURNS:	int	- !0 on error
22720Sstevel@tonic-gate  *
22730Sstevel@tonic-gate  *		avail is set to B_TRUE if the named device is available for
22740Sstevel@tonic-gate  * 		the input request, B_FALSE otherwise.
22750Sstevel@tonic-gate  *
22760Sstevel@tonic-gate  * PURPOSE:	Determine if the named device can be used to satisfy the
22770Sstevel@tonic-gate  *		input request.
22780Sstevel@tonic-gate  *
22790Sstevel@tonic-gate  *		There are several levels at which device availabiity or
22800Sstevel@tonic-gate  *		unavailability may be specifed:
22810Sstevel@tonic-gate  *
22820Sstevel@tonic-gate  *		1. the volume subrequest,
22830Sstevel@tonic-gate  *		2. the toplevel (diskset) request,
22840Sstevel@tonic-gate  *		3. the diskset-specific defaults
22850Sstevel@tonic-gate  *		4. the global defaults
22860Sstevel@tonic-gate  *
22870Sstevel@tonic-gate  *		If the diskset-specific defaults exist, only they are checked.
22880Sstevel@tonic-gate  *
22890Sstevel@tonic-gate  *		The precedence ordering that is enforced:
22900Sstevel@tonic-gate  *
22910Sstevel@tonic-gate  *		1. if request has an avail list, the name must be in it
22920Sstevel@tonic-gate  * 			and not in the request's unavail list.
22930Sstevel@tonic-gate  *		2. if request has an unavail list, the name must not be in it.
22940Sstevel@tonic-gate  *		3. if toplevel request has an avail list, the name must be
22950Sstevel@tonic-gate  *			in it and not in the toplevel request's unavailable
22960Sstevel@tonic-gate  *			list.
22970Sstevel@tonic-gate  *		4. if toplevel request has an unavail list, the name must
22980Sstevel@tonic-gate  *			not be in it.
22990Sstevel@tonic-gate  *		5. if defaults have an avail list, the name must be in it
23000Sstevel@tonic-gate  *			and not in the defaults unavailable list.
23010Sstevel@tonic-gate  *		6. if defaults have an unavail list, the name must not be
23020Sstevel@tonic-gate  *			in it.
23030Sstevel@tonic-gate  */
23040Sstevel@tonic-gate static int
is_named_device_avail(devconfig_t * request,char * device_name,boolean_t check_aliases,boolean_t * avail)23050Sstevel@tonic-gate is_named_device_avail(
23060Sstevel@tonic-gate 	devconfig_t	*request,
23070Sstevel@tonic-gate 	char		*device_name,
23080Sstevel@tonic-gate 	boolean_t	check_aliases,
23090Sstevel@tonic-gate 	boolean_t	*avail)
23100Sstevel@tonic-gate {
23110Sstevel@tonic-gate 	typedef enum check_types {
23120Sstevel@tonic-gate 		DEVICE_REQUEST = 0,
23130Sstevel@tonic-gate 		DISKSET_REQUEST,
23140Sstevel@tonic-gate 		DEFAULTS,
23150Sstevel@tonic-gate 		N_CHECKS
23160Sstevel@tonic-gate 	} check_type_t;
23170Sstevel@tonic-gate 
23180Sstevel@tonic-gate 	check_type_t	check_type;
23190Sstevel@tonic-gate 
23200Sstevel@tonic-gate 	typedef enum list_types {
23210Sstevel@tonic-gate 		AVAIL = 0,
23220Sstevel@tonic-gate 		UNAVAIL,
23230Sstevel@tonic-gate 		N_LISTS
23240Sstevel@tonic-gate 	} list_type_t;
23250Sstevel@tonic-gate 
23260Sstevel@tonic-gate 	dlist_t		*lists[N_CHECKS][N_LISTS];
23270Sstevel@tonic-gate 	boolean_t	includes;
23280Sstevel@tonic-gate 	int		error = 0;
23290Sstevel@tonic-gate 
23300Sstevel@tonic-gate 	memset(lists, 0, (N_CHECKS * N_LISTS) * sizeof (dlist_t *));
23310Sstevel@tonic-gate 
23320Sstevel@tonic-gate 	if (request != NULL) {
23330Sstevel@tonic-gate 	    /* get avail/unavail specs for request */
23340Sstevel@tonic-gate 	    ((error = get_request_avail_spec_list(
23350Sstevel@tonic-gate 		    request, &lists[DEVICE_REQUEST][AVAIL])) != 0) ||
23360Sstevel@tonic-gate 	    (error = get_request_unavail_spec_list(
23370Sstevel@tonic-gate 		    request, &lists[DEVICE_REQUEST][UNAVAIL]));
23380Sstevel@tonic-gate 	}
23390Sstevel@tonic-gate 
23400Sstevel@tonic-gate 	if ((error == 0) && (_toplevel_request != NULL)) {
23410Sstevel@tonic-gate 	    /* diskset request */
23420Sstevel@tonic-gate 	    ((error = get_request_avail_spec_list(
23430Sstevel@tonic-gate 		    _toplevel_request, &lists[DISKSET_REQUEST][AVAIL])) != 0) ||
23440Sstevel@tonic-gate 	    (error = get_request_unavail_spec_list(
23450Sstevel@tonic-gate 		    _toplevel_request, &lists[DISKSET_REQUEST][UNAVAIL]));
23460Sstevel@tonic-gate 	}
23470Sstevel@tonic-gate 
23480Sstevel@tonic-gate 	if ((error == 0) && (_defaults != NULL)) {
23490Sstevel@tonic-gate 	    /* and diskset/global defaults */
23500Sstevel@tonic-gate 	    ((error = get_default_avail_spec_list(_defaults,
23510Sstevel@tonic-gate 		    get_request_diskset(), &lists[DEFAULTS][AVAIL])) != 0) ||
23520Sstevel@tonic-gate 	    (error = get_default_unavail_spec_list(_defaults,
23530Sstevel@tonic-gate 		    get_request_diskset(), &lists[DEFAULTS][UNAVAIL]));
23540Sstevel@tonic-gate 	}
23550Sstevel@tonic-gate 
23560Sstevel@tonic-gate 	if (error != 0) {
23570Sstevel@tonic-gate 	    return (error);
23580Sstevel@tonic-gate 	}
23590Sstevel@tonic-gate 
23600Sstevel@tonic-gate 	*avail = B_TRUE;
23610Sstevel@tonic-gate 
23620Sstevel@tonic-gate 	for (check_type = DEVICE_REQUEST;
23630Sstevel@tonic-gate 	    (check_type < N_CHECKS) && (error == 0);
23640Sstevel@tonic-gate 	    check_type++) {
23650Sstevel@tonic-gate 
23660Sstevel@tonic-gate 	    if (lists[check_type][AVAIL] != NULL) {
23670Sstevel@tonic-gate 
23680Sstevel@tonic-gate 		/* does avail spec list include named device? */
23690Sstevel@tonic-gate 		if ((error = avail_list_includes_device_name(
23700Sstevel@tonic-gate 		    lists[check_type][AVAIL], device_name, check_aliases,
23710Sstevel@tonic-gate 		    &includes)) == 0) {
23720Sstevel@tonic-gate 
23730Sstevel@tonic-gate 		    if (includes != B_TRUE) {
23740Sstevel@tonic-gate 			*avail = B_FALSE;
23750Sstevel@tonic-gate 		    }
23760Sstevel@tonic-gate 
23770Sstevel@tonic-gate 		    if ((includes == B_TRUE) &&
23780Sstevel@tonic-gate 			(lists[check_type][UNAVAIL] != NULL)) {
23790Sstevel@tonic-gate 
23800Sstevel@tonic-gate 			/* device is available, is it in the unavail list? */
23810Sstevel@tonic-gate 			if ((error = unavail_list_includes_device_name(
23820Sstevel@tonic-gate 			    lists[check_type][UNAVAIL], device_name,
23830Sstevel@tonic-gate 			    check_aliases, &includes)) == 0) {
23840Sstevel@tonic-gate 
23850Sstevel@tonic-gate 			    if (includes == B_TRUE) {
23860Sstevel@tonic-gate 				*avail = B_FALSE;
23870Sstevel@tonic-gate 			    }
23880Sstevel@tonic-gate 			}
23890Sstevel@tonic-gate 		    }
23900Sstevel@tonic-gate 		}
23910Sstevel@tonic-gate 
23920Sstevel@tonic-gate 		/* lists at this level checked, skip remainder */
23930Sstevel@tonic-gate 		break;
23940Sstevel@tonic-gate 
23950Sstevel@tonic-gate 	    } else if (lists[check_type][UNAVAIL] != NULL) {
23960Sstevel@tonic-gate 
23970Sstevel@tonic-gate 		/* does unavail spec list include named device? */
23980Sstevel@tonic-gate 		if ((error = unavail_list_includes_device_name(
23990Sstevel@tonic-gate 		    lists[check_type][UNAVAIL], device_name,
24000Sstevel@tonic-gate 		    check_aliases, &includes)) == 0) {
24010Sstevel@tonic-gate 
24020Sstevel@tonic-gate 		    if (includes == B_TRUE) {
24030Sstevel@tonic-gate 			*avail = B_FALSE;
24040Sstevel@tonic-gate 		    }
24050Sstevel@tonic-gate 		}
24060Sstevel@tonic-gate 
24070Sstevel@tonic-gate 		/* list at this level checked, skip remainder */
24080Sstevel@tonic-gate 		break;
24090Sstevel@tonic-gate 	    }
24100Sstevel@tonic-gate 	}
24110Sstevel@tonic-gate 
24120Sstevel@tonic-gate 	return (error);
24130Sstevel@tonic-gate }
24140Sstevel@tonic-gate 
24150Sstevel@tonic-gate /*
24160Sstevel@tonic-gate  * FUNCTION:	avail_list_includes_device_name(dlist_t *list,
24170Sstevel@tonic-gate  *			char *device_name, boolean_t check_aliases,
24180Sstevel@tonic-gate  *			boolean_t *includes)
24190Sstevel@tonic-gate  *
24200Sstevel@tonic-gate  * INPUT:	list	- a dlist_t list of available device_spec_t
24210Sstevel@tonic-gate  *		device_name  - a char * device CTD name
24220Sstevel@tonic-gate  *		check_aliases - boolean_t which indicates if the device's
24230Sstevel@tonic-gate  *			aliases	should be considered in the availability
24240Sstevel@tonic-gate  *			checking.
24250Sstevel@tonic-gate  *
24260Sstevel@tonic-gate  * OUTPUT:	includes - B_TRUE - if named device is "included" by any
24270Sstevel@tonic-gate  *				specification in the input list
24280Sstevel@tonic-gate  *			   B_FALSE - otherwise
24290Sstevel@tonic-gate  *
24300Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
24310Sstevel@tonic-gate  *			- !0 otherwise
24320Sstevel@tonic-gate  *
24330Sstevel@tonic-gate  * PURPOSE:	Helper used by is_named_device_avail that determines
24340Sstevel@tonic-gate  *		if the input list of device specifications "includes"
24350Sstevel@tonic-gate  *		a specific device.
24360Sstevel@tonic-gate  *
24370Sstevel@tonic-gate  *		Iterates the elements of the input array and searches
24380Sstevel@tonic-gate  *		for a match using spec_includes_device_name().
24390Sstevel@tonic-gate  */
24400Sstevel@tonic-gate static int
avail_list_includes_device_name(dlist_t * list,char * device_name,boolean_t check_aliases,boolean_t * includes)24410Sstevel@tonic-gate avail_list_includes_device_name(
24420Sstevel@tonic-gate 	dlist_t	*list,
24430Sstevel@tonic-gate 	char	*device_name,
24440Sstevel@tonic-gate 	boolean_t check_aliases,
24450Sstevel@tonic-gate 	boolean_t *includes)
24460Sstevel@tonic-gate {
24470Sstevel@tonic-gate 	dlist_t *iter = NULL;
24480Sstevel@tonic-gate 	int	error = 0;
24490Sstevel@tonic-gate 
24500Sstevel@tonic-gate 	*includes = B_FALSE;
24510Sstevel@tonic-gate 
24520Sstevel@tonic-gate 	for (iter = list;
24530Sstevel@tonic-gate 	    (*includes == B_FALSE) && (iter != NULL) && (error == 0);
24540Sstevel@tonic-gate 	    iter = iter->next) {
24550Sstevel@tonic-gate 
24560Sstevel@tonic-gate 	    device_spec_t *spec = (device_spec_t *)iter->obj;
24570Sstevel@tonic-gate 	    error = spec_includes_device_name(spec, device_name,
24580Sstevel@tonic-gate 		    check_aliases, includes);
24590Sstevel@tonic-gate 	}
24600Sstevel@tonic-gate 
24610Sstevel@tonic-gate 	return (0);
24620Sstevel@tonic-gate }
24630Sstevel@tonic-gate 
24640Sstevel@tonic-gate /*
24650Sstevel@tonic-gate  * FUNCTION:	unavail_list_includes_device_name(dlist_t *list,
24660Sstevel@tonic-gate  *			char *device_name, boolean_t check_aliases,
24670Sstevel@tonic-gate  *			boolean_t *includes)
24680Sstevel@tonic-gate  *
24690Sstevel@tonic-gate  * INPUT:	list	- a dlist_t list of unavailable device_spec_t
24700Sstevel@tonic-gate  *		device_name  - a char * device CTD name
24710Sstevel@tonic-gate  *		check_aliases - boolean_t which indicates if the device's
24720Sstevel@tonic-gate  *			aliases	should be considered in the availability
24730Sstevel@tonic-gate  *			checking.
24740Sstevel@tonic-gate  *
24750Sstevel@tonic-gate  * OUTPUT:	includes - B_TRUE - if named device is "included" by any
24760Sstevel@tonic-gate  *				specification in the input list
24770Sstevel@tonic-gate  *			   B_FALSE - otherwise
24780Sstevel@tonic-gate  *
24790Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
24800Sstevel@tonic-gate  *			- !0 otherwise
24810Sstevel@tonic-gate  *
24820Sstevel@tonic-gate  * PURPOSE:	Helper used by is_named_device_avail that determines
24830Sstevel@tonic-gate  *		if the input list of device specifications "includes"
24840Sstevel@tonic-gate  *		a specific device.
24850Sstevel@tonic-gate  *
24860Sstevel@tonic-gate  *		Iterates the elements of the input array and searches
24870Sstevel@tonic-gate  *		for a match using spec_includes_device_name_or_alias().
24880Sstevel@tonic-gate  */
24890Sstevel@tonic-gate static int
unavail_list_includes_device_name(dlist_t * list,char * device_name,boolean_t check_aliases,boolean_t * includes)24900Sstevel@tonic-gate unavail_list_includes_device_name(
24910Sstevel@tonic-gate 	dlist_t	*list,
24920Sstevel@tonic-gate 	char	*device_name,
24930Sstevel@tonic-gate 	boolean_t check_aliases,
24940Sstevel@tonic-gate 	boolean_t *includes)
24950Sstevel@tonic-gate {
24960Sstevel@tonic-gate 	dlist_t *iter = NULL;
24970Sstevel@tonic-gate 	int	error = 0;
24980Sstevel@tonic-gate 	device_spec_t *unavail_spec;
24990Sstevel@tonic-gate 	boolean_t	check_for_alternate_hba = B_FALSE;
25000Sstevel@tonic-gate 
25010Sstevel@tonic-gate 	*includes = B_FALSE;
25020Sstevel@tonic-gate 
25030Sstevel@tonic-gate 	/*
25040Sstevel@tonic-gate 	 * the specs in the list are in descending order of specificity.
25050Sstevel@tonic-gate 	 * so a more exact spec will rule the device out before a less
25060Sstevel@tonic-gate 	 * exact spec.
25070Sstevel@tonic-gate 	 *
25080Sstevel@tonic-gate 	 * Meaning: if the list has { "c3t0d0", ..., "c3", ... } and the
25090Sstevel@tonic-gate 	 * input device name is "c3t0d0s0", it will match "c3t0d0"
25100Sstevel@tonic-gate 	 * before "c3".
25110Sstevel@tonic-gate 	 *
25120Sstevel@tonic-gate 	 * This is important for the multi-path alias checking below.
25130Sstevel@tonic-gate 	 * If the input device name is ruled out by a non-controller
25140Sstevel@tonic-gate 	 * specification, it is really unavailable.
25150Sstevel@tonic-gate 	 */
25160Sstevel@tonic-gate 	for (iter = list;
25170Sstevel@tonic-gate 	    (*includes == B_FALSE) && (iter != NULL);
25180Sstevel@tonic-gate 	    iter = iter->next) {
25190Sstevel@tonic-gate 
25200Sstevel@tonic-gate 	    unavail_spec = (device_spec_t *)iter->obj;
25210Sstevel@tonic-gate 	    error = spec_includes_device_name(
25220Sstevel@tonic-gate 		    unavail_spec, device_name, check_aliases, includes);
25230Sstevel@tonic-gate 
25240Sstevel@tonic-gate 	}
25250Sstevel@tonic-gate 
25260Sstevel@tonic-gate 	if ((error == 0) && (*includes == B_TRUE)) {
25270Sstevel@tonic-gate 
25280Sstevel@tonic-gate 	    /* matched an unavailable spec, was it a controller/HBA? */
25290Sstevel@tonic-gate 	    oprintf(OUTPUT_DEBUG,
25300Sstevel@tonic-gate 		    "device \"%s\" is unavailable, "
25310Sstevel@tonic-gate 		    "it matched \"c(%d)t(%d)d(%d)s(%d)\"\n",
25320Sstevel@tonic-gate 		    device_name,
25330Sstevel@tonic-gate 		    unavail_spec->data.ctd->ctrl,
25340Sstevel@tonic-gate 		    unavail_spec->data.ctd->target,
25350Sstevel@tonic-gate 		    unavail_spec->data.ctd->lun,
25360Sstevel@tonic-gate 		    unavail_spec->data.ctd->slice);
25370Sstevel@tonic-gate 
25380Sstevel@tonic-gate 	    if ((unavail_spec->data.ctd->ctrl != ID_UNSPECIFIED) &&
25390Sstevel@tonic-gate 		(unavail_spec->data.ctd->target == ID_UNSPECIFIED) &&
25400Sstevel@tonic-gate 		(unavail_spec->data.ctd->lun == ID_UNSPECIFIED) &&
25410Sstevel@tonic-gate 		(unavail_spec->data.ctd->slice == ID_UNSPECIFIED)) {
25420Sstevel@tonic-gate 
25430Sstevel@tonic-gate 		/*
25440Sstevel@tonic-gate 		 * Need to see if the named device is a disk or slice,
25450Sstevel@tonic-gate 		 * and if so check to see if the it is multipathed
25460Sstevel@tonic-gate 		 * and possibly accessible thru another controller/HBA.
25470Sstevel@tonic-gate 		 */
25480Sstevel@tonic-gate 		check_for_alternate_hba = B_TRUE;
25490Sstevel@tonic-gate 	    }
25500Sstevel@tonic-gate 	}
25510Sstevel@tonic-gate 
25520Sstevel@tonic-gate 	if ((error == 0) && (check_for_alternate_hba == B_TRUE)) {
25530Sstevel@tonic-gate 
25540Sstevel@tonic-gate 	    dm_descriptor_t slice = (dm_descriptor_t)0;
25550Sstevel@tonic-gate 	    dm_descriptor_t disk = (dm_descriptor_t)0;
25560Sstevel@tonic-gate 
25570Sstevel@tonic-gate 	    ((error = slice_get_by_name(device_name, &slice)) != 0) ||
25580Sstevel@tonic-gate 	    (error = disk_get_by_name(device_name, &disk));
25590Sstevel@tonic-gate 	    if (error != 0) {
25600Sstevel@tonic-gate 		return (error);
25610Sstevel@tonic-gate 	    }
25620Sstevel@tonic-gate 
25630Sstevel@tonic-gate 	    /* if it is a slice, get its disk */
25640Sstevel@tonic-gate 	    if ((error == 0) && (slice != (dm_descriptor_t)0)) {
25650Sstevel@tonic-gate 		error = slice_get_disk(slice, &disk);
25660Sstevel@tonic-gate 	    }
25670Sstevel@tonic-gate 
25680Sstevel@tonic-gate 	    if ((error == 0) && (disk != (dm_descriptor_t)0)) {
25690Sstevel@tonic-gate 
25700Sstevel@tonic-gate 		/* see if all the disk's HBAs are unavailable */
25710Sstevel@tonic-gate 		dlist_t *hbas = NULL;
25720Sstevel@tonic-gate 		dlist_t *iter = NULL;
25730Sstevel@tonic-gate 
25740Sstevel@tonic-gate 		error = disk_get_hbas(disk, &hbas);
25750Sstevel@tonic-gate 
25760Sstevel@tonic-gate 		if (hbas != NULL) {
25770Sstevel@tonic-gate 		    oprintf(OUTPUT_DEBUG,
25780Sstevel@tonic-gate 			    gettext("    checking alternate paths for %s\n"),
25790Sstevel@tonic-gate 			    device_name);
25800Sstevel@tonic-gate 		} else {
25810Sstevel@tonic-gate 		    oprintf(OUTPUT_DEBUG,
25820Sstevel@tonic-gate 			    gettext("    no alternate paths for %s\n"),
25830Sstevel@tonic-gate 			    device_name);
25840Sstevel@tonic-gate 		}
25850Sstevel@tonic-gate 
25860Sstevel@tonic-gate 		/* for each of the disk's HBAs */
25870Sstevel@tonic-gate 		for (iter = hbas;
25880Sstevel@tonic-gate 		    (iter != NULL) && (*includes == B_TRUE) && (error == 0);
25890Sstevel@tonic-gate 		    iter = iter->next) {
25900Sstevel@tonic-gate 
25910Sstevel@tonic-gate 		    dm_descriptor_t hba = (uintptr_t)iter->obj;
25920Sstevel@tonic-gate 		    device_spec_t *hbaspec;
25930Sstevel@tonic-gate 		    char *hbaname = NULL;
25940Sstevel@tonic-gate 		    dlist_t *iter2 = NULL;
25950Sstevel@tonic-gate 
25960Sstevel@tonic-gate 		    *includes = B_FALSE;
25970Sstevel@tonic-gate 
25980Sstevel@tonic-gate 		    ((error = get_display_name(hba, &hbaname)) != 0) ||
25990Sstevel@tonic-gate 		    (error = get_spec_for_name(hbaname, &hbaspec));
26000Sstevel@tonic-gate 
26010Sstevel@tonic-gate 		    /* is HBA unavailable? */
26020Sstevel@tonic-gate 		    for (iter2 = list;
26030Sstevel@tonic-gate 			(iter2 != NULL) && (error == 0) &&
26040Sstevel@tonic-gate 				(*includes == B_FALSE);
26050Sstevel@tonic-gate 			iter2 = iter2->next) {
26060Sstevel@tonic-gate 
26070Sstevel@tonic-gate 			device_spec_t *spec =
26080Sstevel@tonic-gate 			    (device_spec_t *)iter2->obj;
26090Sstevel@tonic-gate 
26100Sstevel@tonic-gate 			*includes = spec_includes_device(spec, hbaspec);
26110Sstevel@tonic-gate 		    }
26120Sstevel@tonic-gate 		}
26130Sstevel@tonic-gate 		dlist_free_items(hbas, NULL);
26140Sstevel@tonic-gate 
26150Sstevel@tonic-gate 		/* if *includes==B_TRUE here, all HBAs are unavailable */
26160Sstevel@tonic-gate 	    }
26170Sstevel@tonic-gate 	}
26180Sstevel@tonic-gate 
26190Sstevel@tonic-gate 	return (error);
26200Sstevel@tonic-gate }
26210Sstevel@tonic-gate 
26220Sstevel@tonic-gate /*
26230Sstevel@tonic-gate  * FUNCTION:	spec_includes_device_name(device_spec_t *spec,
26240Sstevel@tonic-gate  *			char *device_name, boolean_t check_aliases,
26250Sstevel@tonic-gate  *			boolean_t *includes)
26260Sstevel@tonic-gate  *
26270Sstevel@tonic-gate  * INPUT:	spec	- a device_spec_t CTD specification.
26280Sstevel@tonic-gate  *		device_name  - a char * device CTD name
26290Sstevel@tonic-gate  *		check_aliases - boolean_t which indicates if the device's
26300Sstevel@tonic-gate  *			aliases	should be considered in the checking.
26310Sstevel@tonic-gate  *
26320Sstevel@tonic-gate  * OUTPUT:	includes - B_TRUE - if device is "included" by the input
26330Sstevel@tonic-gate  *				specification
26340Sstevel@tonic-gate  *			    B_FALSE - otherwise
26350Sstevel@tonic-gate  *
26360Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
26370Sstevel@tonic-gate  *			- !0 otherwise
26380Sstevel@tonic-gate  *
26390Sstevel@tonic-gate  * PURPOSE:	Helper used by (un)avail_specs_includes_device_name() that
26400Sstevel@tonic-gate  *		determines if the input device specification "includes"
26410Sstevel@tonic-gate  *		the named device.
26420Sstevel@tonic-gate  *
26430Sstevel@tonic-gate  *		If check_aliases is true and the named device is a slice or
26440Sstevel@tonic-gate  *		a disk drive, its multi-pathed aliases are also checked
26450Sstevel@tonic-gate  *		against the spec.
26460Sstevel@tonic-gate  */
26470Sstevel@tonic-gate static int
spec_includes_device_name(device_spec_t * spec,char * device_name,boolean_t check_aliases,boolean_t * includes)26480Sstevel@tonic-gate spec_includes_device_name(
26490Sstevel@tonic-gate 	device_spec_t *spec,
26500Sstevel@tonic-gate 	char		 *device_name,
26510Sstevel@tonic-gate 	boolean_t	check_aliases,
26520Sstevel@tonic-gate 	boolean_t	*includes)
26530Sstevel@tonic-gate {
26540Sstevel@tonic-gate 	device_spec_t *device_spec;
26550Sstevel@tonic-gate 	int error = 0;
26560Sstevel@tonic-gate 
26570Sstevel@tonic-gate 	error = get_spec_for_name(device_name, &device_spec);
26580Sstevel@tonic-gate 	if (error == 0) {
26590Sstevel@tonic-gate 
26600Sstevel@tonic-gate 	    *includes = spec_includes_device(spec, device_spec);
26610Sstevel@tonic-gate 
26620Sstevel@tonic-gate 	    if ((*includes == B_FALSE) && (check_aliases == B_TRUE)) {
26630Sstevel@tonic-gate 
26640Sstevel@tonic-gate 		/* spec doesn't include name, check aliases */
26650Sstevel@tonic-gate 
26660Sstevel@tonic-gate 		dm_descriptor_t device = (dm_descriptor_t)0;
26670Sstevel@tonic-gate 		dlist_t *aliases = NULL;
26680Sstevel@tonic-gate 
26690Sstevel@tonic-gate 		/* only slices and disks have aliases */
26700Sstevel@tonic-gate 		error = slice_get_by_name(device_name, &device);
26710Sstevel@tonic-gate 		if (device != (dm_descriptor_t)0) {
26720Sstevel@tonic-gate 		    error = get_aliases(device, &aliases);
26730Sstevel@tonic-gate 		} else if (error == 0) {
26740Sstevel@tonic-gate 		    error = disk_get_by_name(device_name, &device);
26750Sstevel@tonic-gate 		    if (device != (dm_descriptor_t)0) {
26760Sstevel@tonic-gate 			error = get_aliases(device, &aliases);
26770Sstevel@tonic-gate 		    }
26780Sstevel@tonic-gate 		}
26790Sstevel@tonic-gate 
26800Sstevel@tonic-gate 		if ((error == 0) && (aliases != NULL)) {
26810Sstevel@tonic-gate 
26820Sstevel@tonic-gate 		    dlist_t *iter;
26830Sstevel@tonic-gate 		    for (iter = aliases;
26840Sstevel@tonic-gate 			(iter != NULL) && (*includes == B_FALSE) &&
26850Sstevel@tonic-gate 				(error == 0);
26860Sstevel@tonic-gate 			iter = iter->next) {
26870Sstevel@tonic-gate 
26880Sstevel@tonic-gate 			char *alias = (char *)iter->obj;
26890Sstevel@tonic-gate 			device_spec_t *alias_spec;
26900Sstevel@tonic-gate 
26910Sstevel@tonic-gate 			error = get_spec_for_name(alias, &alias_spec);
26920Sstevel@tonic-gate 			if (error == 0) {
26930Sstevel@tonic-gate 			    /* does spec include alias? */
26940Sstevel@tonic-gate 			    *includes =	spec_includes_device(spec, alias_spec);
26950Sstevel@tonic-gate 			}
26960Sstevel@tonic-gate 		    }
26970Sstevel@tonic-gate 		}
26980Sstevel@tonic-gate 		dlist_free_items(aliases, free);
26990Sstevel@tonic-gate 	    }
27000Sstevel@tonic-gate 	}
27010Sstevel@tonic-gate 
27020Sstevel@tonic-gate 	return (error);
27030Sstevel@tonic-gate }
27040Sstevel@tonic-gate 
27050Sstevel@tonic-gate /*
27060Sstevel@tonic-gate  * FUNCTION:	destroy_device_spec(device_spec_t *spec)
27070Sstevel@tonic-gate  *
27080Sstevel@tonic-gate  * INPUT:	spec	- pointer to a device_spec_t
27090Sstevel@tonic-gate  *
27100Sstevel@tonic-gate  * RETURNS:	nothing
27110Sstevel@tonic-gate  *
27120Sstevel@tonic-gate  * PURPOSE:	Function which reclaims memory allocated to a device_spec_t.
27130Sstevel@tonic-gate  *
27140Sstevel@tonic-gate  *		Frees memory allocated to hold the specific data in the spec.
27150Sstevel@tonic-gate  */
27160Sstevel@tonic-gate static void
destroy_device_spec(device_spec_t * spec)27170Sstevel@tonic-gate destroy_device_spec(
27180Sstevel@tonic-gate 	device_spec_t *spec)
27190Sstevel@tonic-gate {
27200Sstevel@tonic-gate 	if (spec != NULL) {
27210Sstevel@tonic-gate 	    if (spec->type == SPEC_TYPE_CTD) {
27220Sstevel@tonic-gate 		free(spec->data.ctd);
27230Sstevel@tonic-gate 	    } else if (spec->type == SPEC_TYPE_RAW) {
27240Sstevel@tonic-gate 		free(spec->data.raw);
27250Sstevel@tonic-gate 	    }
27260Sstevel@tonic-gate 	    free(spec);
27270Sstevel@tonic-gate 	}
27280Sstevel@tonic-gate }
27290Sstevel@tonic-gate 
27300Sstevel@tonic-gate /*
27310Sstevel@tonic-gate  * FUNCTION:	create_device_spec(char *name, device_spec_t **spec);
27320Sstevel@tonic-gate  *
27330Sstevel@tonic-gate  * INPUT:	name	- pointer to a char* device name
27340Sstevel@tonic-gate  *
27350Sstevel@tonic-gate  * OUTPUT:	spec	- pointer to a device_spec_t to hold the result
27360Sstevel@tonic-gate  *
27370Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
27380Sstevel@tonic-gate  *			 !0 otherwise
27390Sstevel@tonic-gate  *
27400Sstevel@tonic-gate  * PURPOSE:	Function which creates a device_spec_t for the input
27410Sstevel@tonic-gate  *		device name.
27420Sstevel@tonic-gate  *
27430Sstevel@tonic-gate  */
27440Sstevel@tonic-gate static int
create_device_spec(char * name,device_spec_t ** spec)27450Sstevel@tonic-gate create_device_spec(
27460Sstevel@tonic-gate 	char	*name,
27470Sstevel@tonic-gate 	device_spec_t **spec)
27480Sstevel@tonic-gate {
27490Sstevel@tonic-gate 	int error = 0;
27500Sstevel@tonic-gate 
27510Sstevel@tonic-gate 	/* allocate the device spec and try various parsing schemes */
27520Sstevel@tonic-gate 	*spec = (device_spec_t *)calloc(1, sizeof (device_spec_t));
27530Sstevel@tonic-gate 	if (*spec == NULL) {
27540Sstevel@tonic-gate 	    error = ENOMEM;
27550Sstevel@tonic-gate 	} else {
27560Sstevel@tonic-gate 	    if (((error = create_device_ctd_spec(name, spec)) != 0) &&
27570Sstevel@tonic-gate 		    (error != ENOMEM)) {
27580Sstevel@tonic-gate 		/* CTD failed, try other parsing schemes */
27590Sstevel@tonic-gate 		error = create_device_raw_spec(name, spec);
27600Sstevel@tonic-gate 	    }
27610Sstevel@tonic-gate 	}
27620Sstevel@tonic-gate 
27630Sstevel@tonic-gate 	return (error);
27640Sstevel@tonic-gate }
27650Sstevel@tonic-gate 
27660Sstevel@tonic-gate /*
27670Sstevel@tonic-gate  * FUNCTION:	create_device_ctd_spec(char *name, device_spec_t **spec);
27680Sstevel@tonic-gate  *
27690Sstevel@tonic-gate  * INPUT:	name	- pointer to a char* device name
27700Sstevel@tonic-gate  *
27710Sstevel@tonic-gate  * OUTPUT:	spec	- pointer to a device_spec_t updated with the parsed
27720Sstevel@tonic-gate  *				CTD spec, if successful
27730Sstevel@tonic-gate  *
27740Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
27750Sstevel@tonic-gate  *			 !0 otherwise
27760Sstevel@tonic-gate  *
27770Sstevel@tonic-gate  * PURPOSE:	Function which atttempts to parse the input device name into
27780Sstevel@tonic-gate  *		cXtXdXsX component ids. The ids are the integer values of each
27790Sstevel@tonic-gate  *		specified segment of the input name.
27800Sstevel@tonic-gate  *
27810Sstevel@tonic-gate  *		If the name doesn't contain a segment, the id is set to
27820Sstevel@tonic-gate  *		ID_UNSPECIFIED.
27830Sstevel@tonic-gate  *
27840Sstevel@tonic-gate  *		The input name must be well-formed.
27850Sstevel@tonic-gate  *
27860Sstevel@tonic-gate  *		These are the acceptable forms:
27870Sstevel@tonic-gate  *
27880Sstevel@tonic-gate  *		cXtXdXsX
27890Sstevel@tonic-gate  *		cXtXdX
27900Sstevel@tonic-gate  *		cXtX
27910Sstevel@tonic-gate  *		cXdXsX
27920Sstevel@tonic-gate  *		cXdX
27930Sstevel@tonic-gate  *		cX
27940Sstevel@tonic-gate  */
27950Sstevel@tonic-gate static int
create_device_ctd_spec(char * name,device_spec_t ** spec)27960Sstevel@tonic-gate create_device_ctd_spec(
27970Sstevel@tonic-gate 	char	*name,
27980Sstevel@tonic-gate 	device_spec_t **spec)
27990Sstevel@tonic-gate {
28000Sstevel@tonic-gate 	uint_t	ctrl;
28010Sstevel@tonic-gate 	uint_t	target;
28020Sstevel@tonic-gate 	uint_t	lun;
28030Sstevel@tonic-gate 	uint_t	slice;
28040Sstevel@tonic-gate 
28050Sstevel@tonic-gate 	uint_t	nscan;
28060Sstevel@tonic-gate 	uint_t	nchars;
28070Sstevel@tonic-gate 
28080Sstevel@tonic-gate 	char	*device_str;
28090Sstevel@tonic-gate 	char	*target_str;
28100Sstevel@tonic-gate 	char	*ctd_str;
28110Sstevel@tonic-gate 	char	*t_ptr;
28120Sstevel@tonic-gate 	char	*d_ptr;
28130Sstevel@tonic-gate 	char	*s_ptr;
28140Sstevel@tonic-gate 
28150Sstevel@tonic-gate 	boolean_t is_ide = B_FALSE;
28160Sstevel@tonic-gate 	boolean_t got_slice = B_FALSE;
28170Sstevel@tonic-gate 	boolean_t got_lun = B_FALSE;
28180Sstevel@tonic-gate 	boolean_t got_target = B_FALSE;
28190Sstevel@tonic-gate 	boolean_t got_ctrl = B_FALSE;
28200Sstevel@tonic-gate 
28210Sstevel@tonic-gate 	int 	error = 0;
28220Sstevel@tonic-gate 
28230Sstevel@tonic-gate 	ctd_str = strdup(name);
28240Sstevel@tonic-gate 	if (ctd_str == NULL) {
28250Sstevel@tonic-gate 	    return (ENOMEM);
28260Sstevel@tonic-gate 	}
28270Sstevel@tonic-gate 
28280Sstevel@tonic-gate 	/* trim any leading path (/dev/dsk/cXtXdXsX) */
28290Sstevel@tonic-gate 	if ((device_str = strrchr(ctd_str, '/')) != NULL) {
28300Sstevel@tonic-gate 	    ++device_str;
28310Sstevel@tonic-gate 	} else {
28320Sstevel@tonic-gate 	    device_str = ctd_str;
28330Sstevel@tonic-gate 	}
28340Sstevel@tonic-gate 
28350Sstevel@tonic-gate 	/* find each segment start position */
28360Sstevel@tonic-gate 	t_ptr = strrchr(device_str, 't');
28370Sstevel@tonic-gate 	d_ptr = strrchr(device_str, 'd');
28380Sstevel@tonic-gate 	s_ptr = strrchr(device_str, 's');
28390Sstevel@tonic-gate 
28400Sstevel@tonic-gate 	/*
28410Sstevel@tonic-gate 	 * scan ids from each existing segment working backwards
28420Sstevel@tonic-gate 	 * so as to leave the device_str in the correct state
28430Sstevel@tonic-gate 	 * for the next expected segment
28440Sstevel@tonic-gate 	 */
28450Sstevel@tonic-gate 	if (s_ptr != NULL) {
28460Sstevel@tonic-gate 
28470Sstevel@tonic-gate 	    /* found 's', try to get slice */
28480Sstevel@tonic-gate 	    nchars = strlen(s_ptr);
28490Sstevel@tonic-gate 	    if ((sscanf(s_ptr, "s%u%n", &slice, &nscan) != 1) ||
28500Sstevel@tonic-gate 		(nscan != nchars)) {
28510Sstevel@tonic-gate 
28520Sstevel@tonic-gate 		error = -1;
28530Sstevel@tonic-gate 		oprintf(OUTPUT_DEBUG,
28540Sstevel@tonic-gate 			gettext("no slice component in device "
28550Sstevel@tonic-gate 				"name \"%s\".\n"),
28560Sstevel@tonic-gate 			name);
28570Sstevel@tonic-gate 
28580Sstevel@tonic-gate 	    } else {
28590Sstevel@tonic-gate 		got_slice = B_TRUE;
28600Sstevel@tonic-gate 		*s_ptr = '\0';
28610Sstevel@tonic-gate 	    }
28620Sstevel@tonic-gate 	}
28630Sstevel@tonic-gate 
28640Sstevel@tonic-gate 	if ((error == 0) && (d_ptr != NULL)) {
28650Sstevel@tonic-gate 
28660Sstevel@tonic-gate 	    /* found 'd', try to get disk/lun */
28670Sstevel@tonic-gate 	    nchars = strlen(d_ptr);
28680Sstevel@tonic-gate 	    if ((sscanf(d_ptr, "d%u%n", &lun, &nscan) != 1) ||
28690Sstevel@tonic-gate 		(nscan != nchars)) {
28700Sstevel@tonic-gate 
28710Sstevel@tonic-gate 		error = -1;
28720Sstevel@tonic-gate 		oprintf(OUTPUT_DEBUG,
28730Sstevel@tonic-gate 			gettext("no disk/lun component "
28740Sstevel@tonic-gate 				"in device name \"%s\".\n"),
28750Sstevel@tonic-gate 			name);
28760Sstevel@tonic-gate 
28770Sstevel@tonic-gate 	    } else {
28780Sstevel@tonic-gate 		got_lun = B_TRUE;
28790Sstevel@tonic-gate 		*d_ptr = '\0';
28800Sstevel@tonic-gate 	    }
28810Sstevel@tonic-gate 	}
28820Sstevel@tonic-gate 
28830Sstevel@tonic-gate 	if ((error == 0) && (t_ptr != NULL)) {
28840Sstevel@tonic-gate 
28850Sstevel@tonic-gate 	    /* found 't', try to get target, it may be a hex WWN id */
28860Sstevel@tonic-gate 
28870Sstevel@tonic-gate 	    /* skip leading 't' and add two for the 'OX' */
28880Sstevel@tonic-gate 	    nchars = strlen(t_ptr + 1) + 2;
28890Sstevel@tonic-gate 	    if ((target_str = (char *)malloc(nchars+1)) == NULL) {
28900Sstevel@tonic-gate 
28910Sstevel@tonic-gate 		error = ENOMEM;
28920Sstevel@tonic-gate 
28930Sstevel@tonic-gate 	    } else {
28940Sstevel@tonic-gate 
28950Sstevel@tonic-gate 		strcpy(target_str, "0X");
28960Sstevel@tonic-gate 		strcpy(target_str+2, t_ptr + 1);
28970Sstevel@tonic-gate 		target_str[nchars] = '\0';
28980Sstevel@tonic-gate 
28990Sstevel@tonic-gate 		if ((sscanf(target_str, "%x%n", &target, &nscan) != 1) ||
29000Sstevel@tonic-gate 		    (nscan != nchars)) {
29010Sstevel@tonic-gate 
29020Sstevel@tonic-gate 		    error = -1;
29030Sstevel@tonic-gate 		    oprintf(OUTPUT_DEBUG,
29040Sstevel@tonic-gate 			    gettext("no target/WWN component "
29050Sstevel@tonic-gate 				    "in device name \"%s\".\n"),
29060Sstevel@tonic-gate 			    name);
29070Sstevel@tonic-gate 
29080Sstevel@tonic-gate 		} else {
29090Sstevel@tonic-gate 		    got_target = B_TRUE;
29100Sstevel@tonic-gate 		    *t_ptr = '\0';
29110Sstevel@tonic-gate 		}
29120Sstevel@tonic-gate 
29130Sstevel@tonic-gate 		free(target_str);
29140Sstevel@tonic-gate 	    }
29150Sstevel@tonic-gate 
29160Sstevel@tonic-gate 	} else {
29170Sstevel@tonic-gate 	    is_ide = B_TRUE;
29180Sstevel@tonic-gate 	}
29190Sstevel@tonic-gate 
29200Sstevel@tonic-gate 	if ((error == 0) && (device_str != NULL)) {
29210Sstevel@tonic-gate 
29220Sstevel@tonic-gate 	    /* get controller/hba/channel */
29230Sstevel@tonic-gate 	    nchars = strlen(device_str);
29240Sstevel@tonic-gate 	    if ((sscanf(device_str, "c%u%n", &ctrl, &nscan) != 1) ||
29250Sstevel@tonic-gate 		    (nscan != nchars)) {
29260Sstevel@tonic-gate 
29270Sstevel@tonic-gate 		error = -1;
29280Sstevel@tonic-gate 		oprintf(OUTPUT_DEBUG,
29290Sstevel@tonic-gate 			gettext("no channel/HBA component "
29300Sstevel@tonic-gate 				"in device name \"%s\".\n"),
29310Sstevel@tonic-gate 			name);
29320Sstevel@tonic-gate 
29330Sstevel@tonic-gate 	    } else {
29340Sstevel@tonic-gate 		got_ctrl = B_TRUE;
29350Sstevel@tonic-gate 	    }
29360Sstevel@tonic-gate 	}
29370Sstevel@tonic-gate 
29380Sstevel@tonic-gate 	free(ctd_str);
29390Sstevel@tonic-gate 
29400Sstevel@tonic-gate 	if (error == 0) {
29410Sstevel@tonic-gate 
29420Sstevel@tonic-gate 	    /* allocate the ctd_spec_t struct and store the ids */
29430Sstevel@tonic-gate 	    (*spec)->type = SPEC_TYPE_CTD;
29440Sstevel@tonic-gate 	    (*spec)->data.ctd = (ctd_spec_t *)calloc(1, sizeof (ctd_spec_t));
29450Sstevel@tonic-gate 
29460Sstevel@tonic-gate 	    if ((*spec)->data.ctd == NULL) {
29470Sstevel@tonic-gate 		error = ENOMEM;
29480Sstevel@tonic-gate 	    }
29490Sstevel@tonic-gate 
29500Sstevel@tonic-gate 	    (*spec)->data.ctd->slice = ID_UNSPECIFIED;
29510Sstevel@tonic-gate 	    (*spec)->data.ctd->lun = ID_UNSPECIFIED;
29520Sstevel@tonic-gate 	    (*spec)->data.ctd->target = ID_UNSPECIFIED;
29530Sstevel@tonic-gate 	    (*spec)->data.ctd->ctrl = ID_UNSPECIFIED;
29540Sstevel@tonic-gate 
29550Sstevel@tonic-gate 	    if (got_slice == B_TRUE) {
29560Sstevel@tonic-gate 		(*spec)->data.ctd->slice = slice;
29570Sstevel@tonic-gate 	    }
29580Sstevel@tonic-gate 
29590Sstevel@tonic-gate 	    if (got_lun == B_TRUE) {
29600Sstevel@tonic-gate 		(*spec)->data.ctd->lun = lun;
29610Sstevel@tonic-gate 	    }
29620Sstevel@tonic-gate 
29630Sstevel@tonic-gate 	    if (got_target == B_TRUE) {
29640Sstevel@tonic-gate 		(*spec)->data.ctd->target = target;
29650Sstevel@tonic-gate 	    }
29660Sstevel@tonic-gate 
29670Sstevel@tonic-gate 	    if (got_ctrl == B_TRUE) {
29680Sstevel@tonic-gate 		(*spec)->data.ctd->ctrl = ctrl;
29690Sstevel@tonic-gate 	    }
29700Sstevel@tonic-gate 
29710Sstevel@tonic-gate 	    (*spec)->data.ctd->is_ide = is_ide;
29720Sstevel@tonic-gate 	}
29730Sstevel@tonic-gate 
29740Sstevel@tonic-gate 	return (error);
29750Sstevel@tonic-gate }
29760Sstevel@tonic-gate 
29770Sstevel@tonic-gate /*
29780Sstevel@tonic-gate  * FUNCTION:	create_device_raw_spec(char *name, device_spec_t **spec);
29790Sstevel@tonic-gate  *
29800Sstevel@tonic-gate  * INPUT:	name	- pointer to a char* device name
29810Sstevel@tonic-gate  *
29820Sstevel@tonic-gate  * OUTPUT:	spec	- pointer to a device_spec_t updated with the raw spec
29830Sstevel@tonic-gate  *
29840Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
29850Sstevel@tonic-gate  *			 !0 otherwise
29860Sstevel@tonic-gate  *
29870Sstevel@tonic-gate  * PURPOSE:	Function which creates a "raw" spec for the input name.
29880Sstevel@tonic-gate  *
29890Sstevel@tonic-gate  *		This is a last resort if all other spec parsing schemes failed,
29900Sstevel@tonic-gate  *		the "raw" spec is just the input device name.
29910Sstevel@tonic-gate  */
29920Sstevel@tonic-gate static int
create_device_raw_spec(char * name,device_spec_t ** spec)29930Sstevel@tonic-gate create_device_raw_spec(
29940Sstevel@tonic-gate 	char	*name,
29950Sstevel@tonic-gate 	device_spec_t **spec)
29960Sstevel@tonic-gate {
29970Sstevel@tonic-gate 	int 	error = 0;
29980Sstevel@tonic-gate 	char	*ctd_str = strdup(name);
29990Sstevel@tonic-gate 
30000Sstevel@tonic-gate 	if (ctd_str == NULL) {
30010Sstevel@tonic-gate 	    return (ENOMEM);
30020Sstevel@tonic-gate 	}
30030Sstevel@tonic-gate 
30040Sstevel@tonic-gate 	(*spec)->type = SPEC_TYPE_RAW;
30050Sstevel@tonic-gate 	(*spec)->data.raw = ctd_str;
30060Sstevel@tonic-gate 
30070Sstevel@tonic-gate 	oprintf(OUTPUT_DEBUG,
30080Sstevel@tonic-gate 		gettext("made raw device spec for \"%s\"\n"), ctd_str);
30090Sstevel@tonic-gate 
30100Sstevel@tonic-gate 	return (error);
30110Sstevel@tonic-gate }
30120Sstevel@tonic-gate 
30130Sstevel@tonic-gate /*
30140Sstevel@tonic-gate  * FUNCTION:	get_spec_for_name(char *name, device_spec_t **id);
30150Sstevel@tonic-gate  *
30160Sstevel@tonic-gate  * INPUT:	name	- pointer to a char* device name
30170Sstevel@tonic-gate  *
30180Sstevel@tonic-gate  * OUTPUT:	id	- pointer to a device_spec_t to hold the result
30190Sstevel@tonic-gate  *
30200Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
30210Sstevel@tonic-gate  *			 !0 otherwise
30220Sstevel@tonic-gate  *
30230Sstevel@tonic-gate  * PURPOSE:	Function which finds the device_spec_t that already
30240Sstevel@tonic-gate  *		exists for the input name or creates it.
30250Sstevel@tonic-gate  *
30260Sstevel@tonic-gate  *		The returned struct should not be freed, it is maintained
30270Sstevel@tonic-gate  *		in a cache that will be purged when the layout process
30280Sstevel@tonic-gate  *		is complete.
30290Sstevel@tonic-gate  */
30300Sstevel@tonic-gate int
get_spec_for_name(char * name,device_spec_t ** id)30310Sstevel@tonic-gate get_spec_for_name(
30320Sstevel@tonic-gate 	char	*name,
30330Sstevel@tonic-gate 	device_spec_t **id)
30340Sstevel@tonic-gate {
30350Sstevel@tonic-gate 	dlist_t *item;
30360Sstevel@tonic-gate 	int	error = 0;
30370Sstevel@tonic-gate 
30380Sstevel@tonic-gate 	item = dlist_find(_spec_cache, (void *)name,
30390Sstevel@tonic-gate 		compare_name_to_spec_cache_name);
30400Sstevel@tonic-gate 
30410Sstevel@tonic-gate 	if (item == NULL) {
30420Sstevel@tonic-gate 	    if ((error = create_device_spec(name, id)) == 0) {
30430Sstevel@tonic-gate 
30440Sstevel@tonic-gate 		spec_cache_t *entry = (spec_cache_t *)
30450Sstevel@tonic-gate 		    calloc(1, sizeof (spec_cache_t));
30460Sstevel@tonic-gate 
30470Sstevel@tonic-gate 		if (entry == NULL) {
30480Sstevel@tonic-gate 		    destroy_device_spec(*id);
30490Sstevel@tonic-gate 		    error = ENOMEM;
30500Sstevel@tonic-gate 		} else {
30510Sstevel@tonic-gate 		    char *dup = strdup(name);
30520Sstevel@tonic-gate 		    if (dup == NULL) {
30530Sstevel@tonic-gate 			free(entry);
30540Sstevel@tonic-gate 			destroy_device_spec(*id);
30550Sstevel@tonic-gate 			*id = NULL;
30560Sstevel@tonic-gate 			error = ENOMEM;
30570Sstevel@tonic-gate 		    } else {
30580Sstevel@tonic-gate 			entry->name = dup;
30590Sstevel@tonic-gate 			entry->device_spec = *id;
30600Sstevel@tonic-gate 		    }
30610Sstevel@tonic-gate 
30620Sstevel@tonic-gate 		    if (error == 0) {
30630Sstevel@tonic-gate 			dlist_t *item = dlist_new_item((void *)entry);
30640Sstevel@tonic-gate 			if (item == NULL) {
30650Sstevel@tonic-gate 			    free(entry);
30660Sstevel@tonic-gate 			    destroy_device_spec(*id);
30670Sstevel@tonic-gate 			    *id = NULL;
30680Sstevel@tonic-gate 			    error = ENOMEM;
30690Sstevel@tonic-gate 			} else {
30700Sstevel@tonic-gate 			    _spec_cache =
30710Sstevel@tonic-gate 				dlist_append(item, _spec_cache, AT_HEAD);
30720Sstevel@tonic-gate 			}
30730Sstevel@tonic-gate 		    }
30740Sstevel@tonic-gate 		}
30750Sstevel@tonic-gate 	    }
30760Sstevel@tonic-gate 	} else {
30770Sstevel@tonic-gate 	    *id = ((spec_cache_t *)item->obj)->device_spec;
30780Sstevel@tonic-gate 	}
30790Sstevel@tonic-gate 
30800Sstevel@tonic-gate 	return (error);
30810Sstevel@tonic-gate }
30820Sstevel@tonic-gate 
30830Sstevel@tonic-gate /*
30840Sstevel@tonic-gate  * FUNCTION:	spec_includes_device(device_spec_t *spec,
30850Sstevel@tonic-gate  *			device_spec_t *device)
30860Sstevel@tonic-gate  *
30870Sstevel@tonic-gate  * INPUT:	spec	- pointer to a device_spec struct
30880Sstevel@tonic-gate  *		device	- pointer to a device_spec struct
30890Sstevel@tonic-gate  *
30900Sstevel@tonic-gate  * RETURNS:	boolean_t - B_TRUE if the device is included in the spec
30910Sstevel@tonic-gate  *			 B_FALSE otherwise
30920Sstevel@tonic-gate  *
30930Sstevel@tonic-gate  * PURPOSE:	Function which determines if the input device matches the
30940Sstevel@tonic-gate  *		input spec.
30950Sstevel@tonic-gate  *
30960Sstevel@tonic-gate  *		If both specs are of the same type, the appropriate
30970Sstevel@tonic-gate  *		comparison function is called.
30980Sstevel@tonic-gate  *
30990Sstevel@tonic-gate  *		If the two specs are of different types, no comparison
31000Sstevel@tonic-gate  *		is done and B_FALSE is returned.
31010Sstevel@tonic-gate  */
31020Sstevel@tonic-gate boolean_t
spec_includes_device(device_spec_t * spec,device_spec_t * device)31030Sstevel@tonic-gate spec_includes_device(
31040Sstevel@tonic-gate 	device_spec_t *spec,
31050Sstevel@tonic-gate 	device_spec_t *device)
31060Sstevel@tonic-gate {
31070Sstevel@tonic-gate 	if ((spec->type == SPEC_TYPE_CTD) && (device->type == SPEC_TYPE_CTD)) {
31080Sstevel@tonic-gate 	    return (ctd_spec_includes_device(spec, device));
31090Sstevel@tonic-gate 	} else if ((spec->type == SPEC_TYPE_RAW) &&
31100Sstevel@tonic-gate 	    (device->type == SPEC_TYPE_RAW)) {
31110Sstevel@tonic-gate 	    return (raw_spec_includes_device(spec, device));
31120Sstevel@tonic-gate 	}
31130Sstevel@tonic-gate 
31140Sstevel@tonic-gate 	return (B_FALSE);
31150Sstevel@tonic-gate }
31160Sstevel@tonic-gate 
31170Sstevel@tonic-gate /*
31180Sstevel@tonic-gate  * FUNCTION:	ctd_spec_includes_device(device_spec_t *spec,
31190Sstevel@tonic-gate  *			device_spec_t *device)
31200Sstevel@tonic-gate  *
31210Sstevel@tonic-gate  * INPUT:	spec	- pointer to a device_spec struct
31220Sstevel@tonic-gate  *		device	- pointer to a device_spec struct
31230Sstevel@tonic-gate  *
31240Sstevel@tonic-gate  * RETURNS:	boolean_t - B_TRUE if the device is included in the spec
31250Sstevel@tonic-gate  *			 B_FALSE otherwise
31260Sstevel@tonic-gate  *
31270Sstevel@tonic-gate  * PURPOSE:	Function which determines if the input CTD device spec
31280Sstevel@tonic-gate  *		matches the input CTD spec.
31290Sstevel@tonic-gate  *
31300Sstevel@tonic-gate  *		The device_spec_t structs contain component "ids" for
31310Sstevel@tonic-gate  *		both the specification and the device.
31320Sstevel@tonic-gate  *
31330Sstevel@tonic-gate  *		The device must match each of the ids in the spec that
31340Sstevel@tonic-gate  *		are specified.
31350Sstevel@tonic-gate  *
31360Sstevel@tonic-gate  *		spec		devices matched
31370Sstevel@tonic-gate  *		--------------------------------------------------------
31380Sstevel@tonic-gate  *		cX		cX, cXtX, cXtXdX, cXtXdXsX, cXdX, cXdXsX
31390Sstevel@tonic-gate  *		cXtX		cXtX, cXtXdX, cXtXdXsX
31400Sstevel@tonic-gate  *		cXtXdX		cXtXdX, cXtXdXsX
31410Sstevel@tonic-gate  *		cXtXdXsX	cXtXdXsX
31420Sstevel@tonic-gate  *		cXdX		cXdX, cXdXsX
31430Sstevel@tonic-gate  *		cXdXsX		cXdXsX
31440Sstevel@tonic-gate  */
31450Sstevel@tonic-gate static boolean_t
ctd_spec_includes_device(device_spec_t * spec,device_spec_t * device)31460Sstevel@tonic-gate ctd_spec_includes_device(
31470Sstevel@tonic-gate 	device_spec_t *spec,
31480Sstevel@tonic-gate 	device_spec_t *device)
31490Sstevel@tonic-gate {
31500Sstevel@tonic-gate 	boolean_t match = B_FALSE;
31510Sstevel@tonic-gate 
31520Sstevel@tonic-gate 	if (spec->data.ctd->is_ide) {
31530Sstevel@tonic-gate 
31540Sstevel@tonic-gate 	    /* valid IDE names are cX, cXdX, cXdXsX, no target */
31550Sstevel@tonic-gate 
31560Sstevel@tonic-gate 	    if ((spec->data.ctd->ctrl != ID_UNSPECIFIED) &&
31570Sstevel@tonic-gate 		(spec->data.ctd->lun != ID_UNSPECIFIED) &&
31580Sstevel@tonic-gate 		(spec->data.ctd->slice != ID_UNSPECIFIED)) {
31590Sstevel@tonic-gate 
31600Sstevel@tonic-gate 		match = (spec->data.ctd->ctrl == device->data.ctd->ctrl) &&
31610Sstevel@tonic-gate 		    (spec->data.ctd->lun == device->data.ctd->lun) &&
31620Sstevel@tonic-gate 		    (spec->data.ctd->slice == device->data.ctd->slice);
31630Sstevel@tonic-gate 
31640Sstevel@tonic-gate 	    } else if ((spec->data.ctd->ctrl != ID_UNSPECIFIED) &&
31650Sstevel@tonic-gate 		(spec->data.ctd->lun != ID_UNSPECIFIED)) {
31660Sstevel@tonic-gate 
31670Sstevel@tonic-gate 		match = (spec->data.ctd->ctrl == device->data.ctd->ctrl) &&
31680Sstevel@tonic-gate 		    (spec->data.ctd->lun == device->data.ctd->lun);
31690Sstevel@tonic-gate 
31700Sstevel@tonic-gate 	    } else if (spec->data.ctd->ctrl != ID_UNSPECIFIED) {
31710Sstevel@tonic-gate 
31720Sstevel@tonic-gate 		match = (spec->data.ctd->ctrl == device->data.ctd->ctrl);
31730Sstevel@tonic-gate 
31740Sstevel@tonic-gate 	    }
31750Sstevel@tonic-gate 
31760Sstevel@tonic-gate 	} else {
31770Sstevel@tonic-gate 
31780Sstevel@tonic-gate 	    /* valid names are cX, cXtX, cXtXdX, cXtXdXsX */
31790Sstevel@tonic-gate 
31800Sstevel@tonic-gate 	    if ((spec->data.ctd->ctrl != ID_UNSPECIFIED) &&
31810Sstevel@tonic-gate 		(spec->data.ctd->target != ID_UNSPECIFIED) &&
31820Sstevel@tonic-gate 		(spec->data.ctd->lun != ID_UNSPECIFIED) &&
31830Sstevel@tonic-gate 		(spec->data.ctd->slice != ID_UNSPECIFIED)) {
31840Sstevel@tonic-gate 
31850Sstevel@tonic-gate 		match = (spec->data.ctd->ctrl == device->data.ctd->ctrl) &&
31860Sstevel@tonic-gate 		    (spec->data.ctd->target == device->data.ctd->target) &&
31870Sstevel@tonic-gate 		    (spec->data.ctd->lun == device->data.ctd->lun) &&
31880Sstevel@tonic-gate 		    (spec->data.ctd->slice == device->data.ctd->slice);
31890Sstevel@tonic-gate 
31900Sstevel@tonic-gate 	    } else if ((spec->data.ctd->ctrl != ID_UNSPECIFIED) &&
31910Sstevel@tonic-gate 		(spec->data.ctd->target != ID_UNSPECIFIED) &&
31920Sstevel@tonic-gate 		(spec->data.ctd->lun != ID_UNSPECIFIED)) {
31930Sstevel@tonic-gate 
31940Sstevel@tonic-gate 		match = (spec->data.ctd->ctrl == device->data.ctd->ctrl) &&
31950Sstevel@tonic-gate 		    (spec->data.ctd->target == device->data.ctd->target) &&
31960Sstevel@tonic-gate 		    (spec->data.ctd->lun == device->data.ctd->lun);
31970Sstevel@tonic-gate 
31980Sstevel@tonic-gate 	    } else if ((spec->data.ctd->ctrl != ID_UNSPECIFIED) &&
31990Sstevel@tonic-gate 		(spec->data.ctd->target != ID_UNSPECIFIED)) {
32000Sstevel@tonic-gate 
32010Sstevel@tonic-gate 		match = (spec->data.ctd->ctrl == device->data.ctd->ctrl) &&
32020Sstevel@tonic-gate 		    (spec->data.ctd->target == device->data.ctd->target);
32030Sstevel@tonic-gate 
32040Sstevel@tonic-gate 	    } else if (spec->data.ctd->ctrl != ID_UNSPECIFIED) {
32050Sstevel@tonic-gate 
32060Sstevel@tonic-gate 		match = (spec->data.ctd->ctrl == device->data.ctd->ctrl);
32070Sstevel@tonic-gate 
32080Sstevel@tonic-gate 	    }
32090Sstevel@tonic-gate 	}
32100Sstevel@tonic-gate 
32110Sstevel@tonic-gate 	oprintf(OUTPUT_DEBUG,
32120Sstevel@tonic-gate 		gettext("spec: c(%d) t(%d) d(%d) s(%d) "
32130Sstevel@tonic-gate 			"%s: c(%d) t(%d) d(%d) s(%d)\n"),
32140Sstevel@tonic-gate 		spec->data.ctd->ctrl, spec->data.ctd->target,
32150Sstevel@tonic-gate 		spec->data.ctd->lun, spec->data.ctd->slice,
32160Sstevel@tonic-gate 		(match ? gettext("includes") : gettext("does not include")),
32170Sstevel@tonic-gate 		device->data.ctd->ctrl, device->data.ctd->target,
32180Sstevel@tonic-gate 		device->data.ctd->lun, device->data.ctd->slice);
32190Sstevel@tonic-gate 
32200Sstevel@tonic-gate 	return (match);
32210Sstevel@tonic-gate }
32220Sstevel@tonic-gate 
32230Sstevel@tonic-gate /*
32240Sstevel@tonic-gate  * FUNCTION:	raw_spec_includes_device(device_spec_t *spec,
32250Sstevel@tonic-gate  *			device_spec_t *device)
32260Sstevel@tonic-gate  *
32270Sstevel@tonic-gate  * INPUT:	spec	- pointer to a device_spec struct
32280Sstevel@tonic-gate  *		device	- pointer to a device_spec struct
32290Sstevel@tonic-gate  *
32300Sstevel@tonic-gate  * RETURNS:	boolean_t - B_TRUE if the device is included in the spec
32310Sstevel@tonic-gate  *			 B_FALSE otherwise
32320Sstevel@tonic-gate  *
32330Sstevel@tonic-gate  * PURPOSE:	Function which determines if the input raw device spec
32340Sstevel@tonic-gate  *		matches the input spec.
32350Sstevel@tonic-gate  *
32360Sstevel@tonic-gate  *		The device_spec_t raw elements are checked.
32370Sstevel@tonic-gate  *
32380Sstevel@tonic-gate  *		If the spec's raw device name is exactly contained at the
32390Sstevel@tonic-gate  *		beginning of the device spec's raw name, then the function
32400Sstevel@tonic-gate  *		evaluates to true.
32410Sstevel@tonic-gate  */
32420Sstevel@tonic-gate static boolean_t
raw_spec_includes_device(device_spec_t * spec,device_spec_t * device)32430Sstevel@tonic-gate raw_spec_includes_device(
32440Sstevel@tonic-gate 	device_spec_t *spec,
32450Sstevel@tonic-gate 	device_spec_t *device)
32460Sstevel@tonic-gate {
32470Sstevel@tonic-gate 	return (strncasecmp(spec->data.raw,
32480Sstevel@tonic-gate 			device->data.raw, strlen(spec->data.raw)) == 0);
32490Sstevel@tonic-gate }
32500Sstevel@tonic-gate 
32510Sstevel@tonic-gate /*
32520Sstevel@tonic-gate  * FUNCTION:	compare_name_to_spec_cache_name(void *name, void *list_item)
32530Sstevel@tonic-gate  *
32540Sstevel@tonic-gate  * INPUT:	name	- opaque pointer to a char * device name
32550Sstevel@tonic-gate  * 		list_item - opaque pointer to a spec_cache_t entry
32560Sstevel@tonic-gate  *
32570Sstevel@tonic-gate  * RETURNS:	int	- 0 - if request is the same as list_item->request
32580Sstevel@tonic-gate  *			  !0 - otherwise
32590Sstevel@tonic-gate  *
32600Sstevel@tonic-gate  * PURPOSE:	dlist_t helper which compares the input device name
32610Sstevel@tonic-gate  *		to the list_item's device name for equality.
32620Sstevel@tonic-gate  *
32630Sstevel@tonic-gate  *		This function is the lookup mechanism for the device_spec
32640Sstevel@tonic-gate  *		associated with the name.
32650Sstevel@tonic-gate  */
32660Sstevel@tonic-gate static int
compare_name_to_spec_cache_name(void * name,void * list_item)32670Sstevel@tonic-gate compare_name_to_spec_cache_name(
32680Sstevel@tonic-gate 	void *name,
32690Sstevel@tonic-gate 	void *list_item)
32700Sstevel@tonic-gate {
32710Sstevel@tonic-gate 	spec_cache_t *entry = (spec_cache_t *)list_item;
32720Sstevel@tonic-gate 
32730Sstevel@tonic-gate 	assert(name != NULL);
32740Sstevel@tonic-gate 	assert(entry != NULL);
32750Sstevel@tonic-gate 
32760Sstevel@tonic-gate 	return (string_case_compare((char *)name, entry->name));
32770Sstevel@tonic-gate }
32780Sstevel@tonic-gate 
32790Sstevel@tonic-gate /*
32800Sstevel@tonic-gate  * FUNCTION:	destroy_spec_cache_entry(void *entry)
32810Sstevel@tonic-gate  *
32820Sstevel@tonic-gate  * INPUT:	entry	- opaque pointer to a spec_cache_t
32830Sstevel@tonic-gate  *
32840Sstevel@tonic-gate  * RETURNS:	nothing
32850Sstevel@tonic-gate  *
32860Sstevel@tonic-gate  * PURPOSE:	Function which reclaims memory allocated to a
32870Sstevel@tonic-gate  *		spec_cache_t entry.
32880Sstevel@tonic-gate  *
32890Sstevel@tonic-gate  *		Frees memory allocated to hold the CTD name and the
32900Sstevel@tonic-gate  *		corresponding device_spec_t.
32910Sstevel@tonic-gate  */
32920Sstevel@tonic-gate static void
destroy_spec_cache_entry(void * obj)32930Sstevel@tonic-gate destroy_spec_cache_entry(
32940Sstevel@tonic-gate 	void *obj)
32950Sstevel@tonic-gate {
32960Sstevel@tonic-gate 	spec_cache_t *entry = (spec_cache_t *)obj;
32970Sstevel@tonic-gate 
32980Sstevel@tonic-gate 	if (entry != NULL) {
32990Sstevel@tonic-gate 	    free(entry->name);
33000Sstevel@tonic-gate 	    destroy_device_spec(entry->device_spec);
33010Sstevel@tonic-gate 	    free(entry);
33020Sstevel@tonic-gate 	}
33030Sstevel@tonic-gate }
33040Sstevel@tonic-gate 
33050Sstevel@tonic-gate /*
33060Sstevel@tonic-gate  * FUNCTION:	destroy_spec_cache()
33070Sstevel@tonic-gate  *
33080Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
33090Sstevel@tonic-gate  *			 !0 otherwise.
33100Sstevel@tonic-gate  *
33110Sstevel@tonic-gate  * PURPOSE:	Function which destroys all entries in the device_spec
33120Sstevel@tonic-gate  *		cache.
33130Sstevel@tonic-gate  */
33140Sstevel@tonic-gate static int
destroy_spec_cache()33150Sstevel@tonic-gate destroy_spec_cache()
33160Sstevel@tonic-gate {
33170Sstevel@tonic-gate 	dlist_free_items(_spec_cache, destroy_spec_cache_entry);
33180Sstevel@tonic-gate 	_spec_cache = NULL;
33190Sstevel@tonic-gate 
33200Sstevel@tonic-gate 	return (0);
33210Sstevel@tonic-gate }
33220Sstevel@tonic-gate 
33230Sstevel@tonic-gate /*
33240Sstevel@tonic-gate  * FUNCTION:	get_device_access_name(devconfig_t *request,
33250Sstevel@tonic-gate  *			dm_descriptor_t desc, char **name)
33260Sstevel@tonic-gate  *
33270Sstevel@tonic-gate  * INPUT:	request	- a devconfig_t request
33280Sstevel@tonic-gate  *		desc	- a dm_descriptor_t device handle
33290Sstevel@tonic-gate  *
33300Sstevel@tonic-gate  * OUTPUT:	name	- a char * pointer to hold the preferred name
33310Sstevel@tonic-gate  *
33320Sstevel@tonic-gate  * RETURNS:	int	- 0 - if request is the same as list_item->request
33330Sstevel@tonic-gate  *			  !0 - otherwise
33340Sstevel@tonic-gate  *
33350Sstevel@tonic-gate  * PURPOSE:	Utility function to determine which of the possible device
33360Sstevel@tonic-gate  *		names should be used to access a known available device.
33370Sstevel@tonic-gate  *
33380Sstevel@tonic-gate  *		Devices handled are slices and disks.
33390Sstevel@tonic-gate  *
33400Sstevel@tonic-gate  *		If the input device is a multipathed disk or slice, it
33410Sstevel@tonic-gate  *		can have several possible names.  Determine which of the
33420Sstevel@tonic-gate  *		names should be used based on the input request's available
33430Sstevel@tonic-gate  *		or unavailable device specifications.
33440Sstevel@tonic-gate  *
33450Sstevel@tonic-gate  */
33460Sstevel@tonic-gate int
get_device_access_name(devconfig_t * request,dm_descriptor_t desc,char ** name)33470Sstevel@tonic-gate get_device_access_name(
33480Sstevel@tonic-gate 	devconfig_t	*request,
33490Sstevel@tonic-gate 	dm_descriptor_t desc,
33500Sstevel@tonic-gate 	char		**name)
33510Sstevel@tonic-gate {
33520Sstevel@tonic-gate 	int		error = 0;
33530Sstevel@tonic-gate 	boolean_t	avail = B_FALSE;
33540Sstevel@tonic-gate 	dlist_t		*aliases = NULL;
33550Sstevel@tonic-gate 
33560Sstevel@tonic-gate 	assert(desc != (dm_descriptor_t)0);
33570Sstevel@tonic-gate 
33580Sstevel@tonic-gate 	*name = NULL;
33590Sstevel@tonic-gate 
33600Sstevel@tonic-gate 	if ((error = get_display_name(desc, name)) != 0) {
33610Sstevel@tonic-gate 	    return (error);
33620Sstevel@tonic-gate 	}
33630Sstevel@tonic-gate 
33640Sstevel@tonic-gate 	if (is_did_name(*name) == B_TRUE) {
33650Sstevel@tonic-gate 	    oprintf(OUTPUT_DEBUG,
33660Sstevel@tonic-gate 		    gettext("device DID name %s is preferred\n"),
33670Sstevel@tonic-gate 		    *name);
33680Sstevel@tonic-gate 	    return (0);
33690Sstevel@tonic-gate 	}
33700Sstevel@tonic-gate 
33710Sstevel@tonic-gate 	error = is_named_device_avail(request, *name, B_FALSE, &avail);
33720Sstevel@tonic-gate 	if (error != 0) {
33730Sstevel@tonic-gate 	    return (error);
33740Sstevel@tonic-gate 	}
33750Sstevel@tonic-gate 
33760Sstevel@tonic-gate 	if (avail == B_TRUE) {
33770Sstevel@tonic-gate 	    oprintf(OUTPUT_DEBUG,
33780Sstevel@tonic-gate 		    gettext("device name %s is accessible\n"),
33790Sstevel@tonic-gate 		    *name);
33800Sstevel@tonic-gate 	    return (0);
33810Sstevel@tonic-gate 	}
33820Sstevel@tonic-gate 
33830Sstevel@tonic-gate 	/* search aliases for an 'available' name, prefer DID names */
33840Sstevel@tonic-gate 	if ((error = get_aliases(desc, &aliases)) == 0) {
33850Sstevel@tonic-gate 
33860Sstevel@tonic-gate 	    dlist_t *iter = aliases;
33870Sstevel@tonic-gate 	    char *availname = NULL;
33880Sstevel@tonic-gate 	    char *didname = NULL;
33890Sstevel@tonic-gate 
33900Sstevel@tonic-gate 	    for (; (iter != NULL) && (error == 0); iter = iter->next) {
33910Sstevel@tonic-gate 
33920Sstevel@tonic-gate 		char *alias = (char *)iter->obj;
33930Sstevel@tonic-gate 		error = is_named_device_avail(request, alias, B_FALSE, &avail);
33940Sstevel@tonic-gate 
33950Sstevel@tonic-gate 		if ((error == 0) && (avail == B_TRUE)) {
33960Sstevel@tonic-gate 		    oprintf(OUTPUT_DEBUG,
33970Sstevel@tonic-gate 			    gettext("device alias %s is accessible for %s\n"),
33980Sstevel@tonic-gate 			    alias, *name);
33990Sstevel@tonic-gate 
34000Sstevel@tonic-gate 		    availname = alias;
34010Sstevel@tonic-gate 
34020Sstevel@tonic-gate 		    if (is_did_name(availname) == B_TRUE) {
34030Sstevel@tonic-gate 			didname = alias;
34040Sstevel@tonic-gate 			break;
34050Sstevel@tonic-gate 		    }
34060Sstevel@tonic-gate 		}
34070Sstevel@tonic-gate 	    }
34080Sstevel@tonic-gate 
34090Sstevel@tonic-gate 	    if (error == 0) {
34100Sstevel@tonic-gate 		if (didname != NULL) {
34110Sstevel@tonic-gate 		    *name = didname;
34120Sstevel@tonic-gate 		} else if (availname != NULL) {
34130Sstevel@tonic-gate 		    *name = availname;
34140Sstevel@tonic-gate 		}
34150Sstevel@tonic-gate 	    }
34160Sstevel@tonic-gate 	}
34170Sstevel@tonic-gate 
34180Sstevel@tonic-gate 	return (error);
34190Sstevel@tonic-gate }
3420