xref: /titanic_41/usr/src/cmd/lvm/metassist/layout/layout_concat.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <string.h>
30*7c478bd9Sstevel@tonic-gate #include <libintl.h>
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include "libdiskmgt.h"
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include "volume_error.h"
35*7c478bd9Sstevel@tonic-gate #include "volume_defaults.h"
36*7c478bd9Sstevel@tonic-gate #include "volume_devconfig.h"
37*7c478bd9Sstevel@tonic-gate #include "volume_dlist.h"
38*7c478bd9Sstevel@tonic-gate #include "volume_output.h"
39*7c478bd9Sstevel@tonic-gate #include "volume_request.h"
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #include "layout_concat.h"
42*7c478bd9Sstevel@tonic-gate #include "layout_device_cache.h"
43*7c478bd9Sstevel@tonic-gate #include "layout_device_util.h"
44*7c478bd9Sstevel@tonic-gate #include "layout_discovery.h"
45*7c478bd9Sstevel@tonic-gate #include "layout_dlist_util.h"
46*7c478bd9Sstevel@tonic-gate #include "layout_messages.h"
47*7c478bd9Sstevel@tonic-gate #include "layout_request.h"
48*7c478bd9Sstevel@tonic-gate #include "layout_slice.h"
49*7c478bd9Sstevel@tonic-gate #include "layout_svm_util.h"
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate #define	_LAYOUT_CONCAT_C
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate static int
54*7c478bd9Sstevel@tonic-gate compose_concat_within_hba(
55*7c478bd9Sstevel@tonic-gate 	devconfig_t	*request,
56*7c478bd9Sstevel@tonic-gate 	dlist_t		*hbas,
57*7c478bd9Sstevel@tonic-gate 	uint64_t	nbytes,
58*7c478bd9Sstevel@tonic-gate 	devconfig_t	**concat);
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate static int
61*7c478bd9Sstevel@tonic-gate assemble_concat(
62*7c478bd9Sstevel@tonic-gate 	devconfig_t	*request,
63*7c478bd9Sstevel@tonic-gate 	dlist_t		*comps,
64*7c478bd9Sstevel@tonic-gate 	devconfig_t	**concat);
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate /*
67*7c478bd9Sstevel@tonic-gate  * FUNCTION:	layout_concat(devconfig_t *request, uint64_t nbytes,
68*7c478bd9Sstevel@tonic-gate  *			dlist_t **results)
69*7c478bd9Sstevel@tonic-gate  *
70*7c478bd9Sstevel@tonic-gate  * INPUT:	request	- pointer to a devconfig_t of the current request
71*7c478bd9Sstevel@tonic-gate  *		nbytes	- the desired capacity of the concat
72*7c478bd9Sstevel@tonic-gate  *
73*7c478bd9Sstevel@tonic-gate  * OUPUT:	results	- pointer to a list of composed volumes
74*7c478bd9Sstevel@tonic-gate  *
75*7c478bd9Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
76*7c478bd9Sstevel@tonic-gate  *			 !0 otherwise.
77*7c478bd9Sstevel@tonic-gate  *
78*7c478bd9Sstevel@tonic-gate  * PURPOSE:	Main layout driver for composing concat volumes.
79*7c478bd9Sstevel@tonic-gate  *
80*7c478bd9Sstevel@tonic-gate  *		Attempts to construct a concat of size nbytes.
81*7c478bd9Sstevel@tonic-gate  *
82*7c478bd9Sstevel@tonic-gate  *		Several different layout strategies are tried in order
83*7c478bd9Sstevel@tonic-gate  *		of preference until one succeeds or there are none left.
84*7c478bd9Sstevel@tonic-gate  *
85*7c478bd9Sstevel@tonic-gate  *		1 - concat within an HBA
86*7c478bd9Sstevel@tonic-gate  *		    . requires sufficient space available on the HBA
87*7c478bd9Sstevel@tonic-gate  *
88*7c478bd9Sstevel@tonic-gate  *		2 - concat across all available similar HBAs
89*7c478bd9Sstevel@tonic-gate  *
90*7c478bd9Sstevel@tonic-gate  *		3 - concat across all available HBAs
91*7c478bd9Sstevel@tonic-gate  *
92*7c478bd9Sstevel@tonic-gate  *		get available HBAs
93*7c478bd9Sstevel@tonic-gate  *
94*7c478bd9Sstevel@tonic-gate  *		group HBAs by characteristics
95*7c478bd9Sstevel@tonic-gate  *		for (each HBA grouping) and (concat not composed) {
96*7c478bd9Sstevel@tonic-gate  *		    select next HBA group
97*7c478bd9Sstevel@tonic-gate  *		    for (strategy[1,2]) and (concat not composed) {
98*7c478bd9Sstevel@tonic-gate  *			compose concat using HBAs in group
99*7c478bd9Sstevel@tonic-gate  *		    }
100*7c478bd9Sstevel@tonic-gate  *		}
101*7c478bd9Sstevel@tonic-gate  *
102*7c478bd9Sstevel@tonic-gate  *		if (concat not composed) {
103*7c478bd9Sstevel@tonic-gate  *		    for (strategy[3]) and (concat not composed) {
104*7c478bd9Sstevel@tonic-gate  *			compose concat using all HBAs
105*7c478bd9Sstevel@tonic-gate  *		    }
106*7c478bd9Sstevel@tonic-gate  *		}
107*7c478bd9Sstevel@tonic-gate  *
108*7c478bd9Sstevel@tonic-gate  *		if (concat composed) {
109*7c478bd9Sstevel@tonic-gate  *		    append composed concat to results
110*7c478bd9Sstevel@tonic-gate  *		}
111*7c478bd9Sstevel@tonic-gate  */
112*7c478bd9Sstevel@tonic-gate int
layout_concat(devconfig_t * request,uint64_t nbytes,dlist_t ** results)113*7c478bd9Sstevel@tonic-gate layout_concat(
114*7c478bd9Sstevel@tonic-gate 	devconfig_t	*request,
115*7c478bd9Sstevel@tonic-gate 	uint64_t	nbytes,
116*7c478bd9Sstevel@tonic-gate 	dlist_t		**results)
117*7c478bd9Sstevel@tonic-gate {
118*7c478bd9Sstevel@tonic-gate 	/*
119*7c478bd9Sstevel@tonic-gate 	 * these enums define the # of strategies and the preference order
120*7c478bd9Sstevel@tonic-gate 	 * in which they are tried
121*7c478bd9Sstevel@tonic-gate 	 */
122*7c478bd9Sstevel@tonic-gate 	typedef enum {
123*7c478bd9Sstevel@tonic-gate 		CONCAT_WITHIN_SIMILAR_HBA = 0,
124*7c478bd9Sstevel@tonic-gate 		CONCAT_ACROSS_SIMILAR_HBAS,
125*7c478bd9Sstevel@tonic-gate 		N_SIMILAR_HBA_STRATEGIES
126*7c478bd9Sstevel@tonic-gate 	} similar_hba_strategy_order_t;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	typedef enum {
129*7c478bd9Sstevel@tonic-gate 		CONCAT_ACROSS_ANY_HBAS = 0,
130*7c478bd9Sstevel@tonic-gate 		N_ANY_HBA_STRATEGIES
131*7c478bd9Sstevel@tonic-gate 	} any_hba_strategy_order_t;
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate 	dlist_t		*usable_hbas = NULL;
134*7c478bd9Sstevel@tonic-gate 	dlist_t		*similar_hba_groups = NULL;
135*7c478bd9Sstevel@tonic-gate 	dlist_t		*iter = NULL;
136*7c478bd9Sstevel@tonic-gate 	devconfig_t  	*concat = NULL;
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 	int		error = 0;
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate 	(error = get_usable_hbas(&usable_hbas));
141*7c478bd9Sstevel@tonic-gate 	if (error != 0) {
142*7c478bd9Sstevel@tonic-gate 	    volume_set_error(gettext("There are no usable HBAs."));
143*7c478bd9Sstevel@tonic-gate 	    return (error);
144*7c478bd9Sstevel@tonic-gate 	}
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate 	print_layout_volume_msg(devconfig_type_to_str(TYPE_CONCAT), nbytes);
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate 	if (dlist_length(usable_hbas) == 0) {
149*7c478bd9Sstevel@tonic-gate 	    print_no_hbas_msg();
150*7c478bd9Sstevel@tonic-gate 	    return (-1);
151*7c478bd9Sstevel@tonic-gate 	}
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate 	error = group_similar_hbas(usable_hbas, &similar_hba_groups);
154*7c478bd9Sstevel@tonic-gate 	if (error != 0) {
155*7c478bd9Sstevel@tonic-gate 	    return (error);
156*7c478bd9Sstevel@tonic-gate 	}
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate 	for (iter = similar_hba_groups;
159*7c478bd9Sstevel@tonic-gate 	    (error == 0) && (concat == NULL) && (iter != NULL);
160*7c478bd9Sstevel@tonic-gate 	    iter = iter->next) {
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate 	    dlist_t *hbas = (dlist_t *)iter->obj;
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate 	    similar_hba_strategy_order_t order;
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 	    for (order = CONCAT_WITHIN_SIMILAR_HBA;
167*7c478bd9Sstevel@tonic-gate 		(order < N_SIMILAR_HBA_STRATEGIES) &&
168*7c478bd9Sstevel@tonic-gate 			(concat == NULL) && (error == 0);
169*7c478bd9Sstevel@tonic-gate 		order++) {
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate 		dlist_t	*selhbas = NULL;
172*7c478bd9Sstevel@tonic-gate 		dlist_t	*disks = NULL;
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate 		switch (order) {
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate 		case CONCAT_WITHIN_SIMILAR_HBA:
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 		    error = select_hbas_with_n_disks(
179*7c478bd9Sstevel@tonic-gate 			    request, hbas, 1, &selhbas, &disks);
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate 		    if (error == 0) {
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate /* BEGIN CSTYLED */
184*7c478bd9Sstevel@tonic-gate oprintf(OUTPUT_TERSE,
185*7c478bd9Sstevel@tonic-gate 	gettext("  -->Strategy 1: use disks from a single HBA - concat within HBA\n"));
186*7c478bd9Sstevel@tonic-gate /* END CSTYLED */
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate 			error = compose_concat_within_hba(
189*7c478bd9Sstevel@tonic-gate 				request, selhbas, nbytes, &concat);
190*7c478bd9Sstevel@tonic-gate 		    }
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate 		    break;
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate 		case CONCAT_ACROSS_SIMILAR_HBAS:
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate 		    error = select_hbas_with_n_disks(
197*7c478bd9Sstevel@tonic-gate 			    request, hbas, 1, &selhbas, &disks);
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate 		    if (error == 0) {
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate /* BEGIN CSTYLED */
202*7c478bd9Sstevel@tonic-gate oprintf(OUTPUT_TERSE,
203*7c478bd9Sstevel@tonic-gate 	gettext("  -->Strategy 2: use disks from all similar HBAs - concat across HBAs\n"));
204*7c478bd9Sstevel@tonic-gate /* END CSTYLED */
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate 			error = populate_concat(
207*7c478bd9Sstevel@tonic-gate 				request, nbytes, disks,
208*7c478bd9Sstevel@tonic-gate 				NULL, &concat);
209*7c478bd9Sstevel@tonic-gate 		    }
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate 		    break;
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate 		default:
214*7c478bd9Sstevel@tonic-gate 		    break;
215*7c478bd9Sstevel@tonic-gate 		}
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate 		dlist_free_items(disks, NULL);
218*7c478bd9Sstevel@tonic-gate 		dlist_free_items(selhbas, NULL);
219*7c478bd9Sstevel@tonic-gate 	    }
220*7c478bd9Sstevel@tonic-gate 	}
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate 	for (iter = similar_hba_groups; iter != NULL; iter = iter->next) {
223*7c478bd9Sstevel@tonic-gate 	    dlist_free_items((dlist_t *)iter->obj, NULL);
224*7c478bd9Sstevel@tonic-gate 	}
225*7c478bd9Sstevel@tonic-gate 	dlist_free_items(similar_hba_groups, NULL);
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate 	/* try all HBAs */
228*7c478bd9Sstevel@tonic-gate 	if (concat == NULL && error == 0) {
229*7c478bd9Sstevel@tonic-gate 
230*7c478bd9Sstevel@tonic-gate 	    any_hba_strategy_order_t order;
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate 	    for (order = CONCAT_ACROSS_ANY_HBAS;
233*7c478bd9Sstevel@tonic-gate 		(order < N_ANY_HBA_STRATEGIES) &&
234*7c478bd9Sstevel@tonic-gate 			(concat == NULL) && (error == 0);
235*7c478bd9Sstevel@tonic-gate 		order++) {
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate 		dlist_t	*selhbas = NULL;
238*7c478bd9Sstevel@tonic-gate 		dlist_t	*disks = NULL;
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate 		switch (order) {
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate 		case CONCAT_ACROSS_ANY_HBAS:
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate 		    error = select_hbas_with_n_disks(
245*7c478bd9Sstevel@tonic-gate 			    request, usable_hbas, 1, &selhbas, &disks);
246*7c478bd9Sstevel@tonic-gate 
247*7c478bd9Sstevel@tonic-gate 		    if (error == 0) {
248*7c478bd9Sstevel@tonic-gate 
249*7c478bd9Sstevel@tonic-gate /* BEGIN CSTYLED */
250*7c478bd9Sstevel@tonic-gate oprintf(OUTPUT_VERBOSE,
251*7c478bd9Sstevel@tonic-gate 	gettext("  -->Strategy 3: use disks from all available HBAs - concat across HBAs\n"));
252*7c478bd9Sstevel@tonic-gate /* END CSTYLED */
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate 			error = populate_concat(
255*7c478bd9Sstevel@tonic-gate 				request, nbytes, disks,
256*7c478bd9Sstevel@tonic-gate 				NULL, &concat);
257*7c478bd9Sstevel@tonic-gate 		    }
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate 		    break;
260*7c478bd9Sstevel@tonic-gate 
261*7c478bd9Sstevel@tonic-gate 		default:
262*7c478bd9Sstevel@tonic-gate 		    break;
263*7c478bd9Sstevel@tonic-gate 		}
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate 		dlist_free_items(disks, NULL);
266*7c478bd9Sstevel@tonic-gate 		dlist_free_items(selhbas, NULL);
267*7c478bd9Sstevel@tonic-gate 	    }
268*7c478bd9Sstevel@tonic-gate 	}
269*7c478bd9Sstevel@tonic-gate 
270*7c478bd9Sstevel@tonic-gate 	if (concat != NULL) {
271*7c478bd9Sstevel@tonic-gate 
272*7c478bd9Sstevel@tonic-gate 	    dlist_t *item = dlist_new_item(concat);
273*7c478bd9Sstevel@tonic-gate 	    if (item == NULL) {
274*7c478bd9Sstevel@tonic-gate 		error = ENOMEM;
275*7c478bd9Sstevel@tonic-gate 	    } else {
276*7c478bd9Sstevel@tonic-gate 
277*7c478bd9Sstevel@tonic-gate 		*results = dlist_append(item, *results, AT_TAIL);
278*7c478bd9Sstevel@tonic-gate 
279*7c478bd9Sstevel@tonic-gate 		print_layout_success_msg();
280*7c478bd9Sstevel@tonic-gate 	    }
281*7c478bd9Sstevel@tonic-gate 
282*7c478bd9Sstevel@tonic-gate 	} else if (error != 0) {
283*7c478bd9Sstevel@tonic-gate 
284*7c478bd9Sstevel@tonic-gate 	    print_debug_failure_msg(
285*7c478bd9Sstevel@tonic-gate 		    devconfig_type_to_str(TYPE_CONCAT),
286*7c478bd9Sstevel@tonic-gate 		    get_error_string(error));
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate 	} else {
289*7c478bd9Sstevel@tonic-gate 
290*7c478bd9Sstevel@tonic-gate 	    print_insufficient_resources_msg(
291*7c478bd9Sstevel@tonic-gate 		    devconfig_type_to_str(TYPE_CONCAT));
292*7c478bd9Sstevel@tonic-gate 	    error = -1;
293*7c478bd9Sstevel@tonic-gate 	}
294*7c478bd9Sstevel@tonic-gate 
295*7c478bd9Sstevel@tonic-gate 	return (error);
296*7c478bd9Sstevel@tonic-gate }
297*7c478bd9Sstevel@tonic-gate 
298*7c478bd9Sstevel@tonic-gate static int
compose_concat_within_hba(devconfig_t * request,dlist_t * hbas,uint64_t nbytes,devconfig_t ** concat)299*7c478bd9Sstevel@tonic-gate compose_concat_within_hba(
300*7c478bd9Sstevel@tonic-gate 	devconfig_t	*request,
301*7c478bd9Sstevel@tonic-gate 	dlist_t		*hbas,
302*7c478bd9Sstevel@tonic-gate 	uint64_t	nbytes,
303*7c478bd9Sstevel@tonic-gate 	devconfig_t	**concat)
304*7c478bd9Sstevel@tonic-gate {
305*7c478bd9Sstevel@tonic-gate 	int		error = 0;
306*7c478bd9Sstevel@tonic-gate 
307*7c478bd9Sstevel@tonic-gate 	dlist_t		*iter = NULL;
308*7c478bd9Sstevel@tonic-gate 
309*7c478bd9Sstevel@tonic-gate 	for (iter = hbas;
310*7c478bd9Sstevel@tonic-gate 	    (iter != NULL) && (*concat == NULL) && (error == 0);
311*7c478bd9Sstevel@tonic-gate 	    iter = iter->next) {
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate 	    dm_descriptor_t hba = (uintptr_t)iter->obj;
314*7c478bd9Sstevel@tonic-gate 	    dlist_t	*disks = NULL;
315*7c478bd9Sstevel@tonic-gate 	    uint64_t	space = 0;
316*7c478bd9Sstevel@tonic-gate 	    char	*name;
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate 	    /* check for sufficient space on the HBA */
319*7c478bd9Sstevel@tonic-gate 	    ((error = get_display_name(hba, &name)) != 0) ||
320*7c478bd9Sstevel@tonic-gate 	    (error = hba_get_avail_disks_and_space(request,
321*7c478bd9Sstevel@tonic-gate 		    hba, &disks, &space));
322*7c478bd9Sstevel@tonic-gate 
323*7c478bd9Sstevel@tonic-gate 	    if (error == 0) {
324*7c478bd9Sstevel@tonic-gate 		if (space >= nbytes) {
325*7c478bd9Sstevel@tonic-gate 		    error = populate_concat(request, nbytes, disks,
326*7c478bd9Sstevel@tonic-gate 			    NULL, concat);
327*7c478bd9Sstevel@tonic-gate 		} else {
328*7c478bd9Sstevel@tonic-gate 		    print_hba_insufficient_space_msg(name, space);
329*7c478bd9Sstevel@tonic-gate 		}
330*7c478bd9Sstevel@tonic-gate 	    }
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate 	    dlist_free_items(disks, NULL);
333*7c478bd9Sstevel@tonic-gate 	}
334*7c478bd9Sstevel@tonic-gate 
335*7c478bd9Sstevel@tonic-gate 	return (error);
336*7c478bd9Sstevel@tonic-gate }
337*7c478bd9Sstevel@tonic-gate 
338*7c478bd9Sstevel@tonic-gate /*
339*7c478bd9Sstevel@tonic-gate  * FUNCTION:	populate_concat(devconfig_t *request, uint64_t nbytes,
340*7c478bd9Sstevel@tonic-gate  *			dlist_t *disks, dlist_t *othervols,
341*7c478bd9Sstevel@tonic-gate  *			devconfig_t **concat)
342*7c478bd9Sstevel@tonic-gate  *
343*7c478bd9Sstevel@tonic-gate  * INPUT:	request	- pointer to a request devconfig_t
344*7c478bd9Sstevel@tonic-gate  *		nbytes	- desired concat size
345*7c478bd9Sstevel@tonic-gate  *		disks	- pointer to a list of availalb disks
346*7c478bd9Sstevel@tonic-gate  *		othervols - pointer to a list of other volumes whose
347*7c478bd9Sstevel@tonic-gate  *				composition may affect this concat
348*7c478bd9Sstevel@tonic-gate  *				(e.g., submirrors of the same mirror)
349*7c478bd9Sstevel@tonic-gate  *
350*7c478bd9Sstevel@tonic-gate  * OUTPUT:	concat	- pointer to a devconfig_t to hold resulting concat
351*7c478bd9Sstevel@tonic-gate  *
352*7c478bd9Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
353*7c478bd9Sstevel@tonic-gate  *			 !0 otherwise.
354*7c478bd9Sstevel@tonic-gate  *
355*7c478bd9Sstevel@tonic-gate  * PURPOSE:	Helper to populate a concat with the specified aggregate
356*7c478bd9Sstevel@tonic-gate  *		capacity using slices on disks in the input list.
357*7c478bd9Sstevel@tonic-gate  *
358*7c478bd9Sstevel@tonic-gate  *		If the othervols list is not empty, the slice components
359*7c478bd9Sstevel@tonic-gate  *		chosen for the concat must not on the same disks as any
360*7c478bd9Sstevel@tonic-gate  *		of the other volumes.
361*7c478bd9Sstevel@tonic-gate  *
362*7c478bd9Sstevel@tonic-gate  *		If sufficient slice components can be found, the concat
363*7c478bd9Sstevel@tonic-gate  *		is assembled and returned.
364*7c478bd9Sstevel@tonic-gate  */
365*7c478bd9Sstevel@tonic-gate int
populate_concat(devconfig_t * request,uint64_t nbytes,dlist_t * disks,dlist_t * othervols,devconfig_t ** concat)366*7c478bd9Sstevel@tonic-gate populate_concat(
367*7c478bd9Sstevel@tonic-gate 	devconfig_t	*request,
368*7c478bd9Sstevel@tonic-gate 	uint64_t	nbytes,
369*7c478bd9Sstevel@tonic-gate 	dlist_t		*disks,
370*7c478bd9Sstevel@tonic-gate 	dlist_t		*othervols,
371*7c478bd9Sstevel@tonic-gate 	devconfig_t	**concat)
372*7c478bd9Sstevel@tonic-gate {
373*7c478bd9Sstevel@tonic-gate 	dlist_t		*other_hbas = NULL;
374*7c478bd9Sstevel@tonic-gate 	dlist_t		*other_disks = NULL;
375*7c478bd9Sstevel@tonic-gate 
376*7c478bd9Sstevel@tonic-gate 	dlist_t		*slices = NULL;
377*7c478bd9Sstevel@tonic-gate 	dlist_t		*comps = NULL;
378*7c478bd9Sstevel@tonic-gate 
379*7c478bd9Sstevel@tonic-gate 	uint16_t	npaths	= 0;
380*7c478bd9Sstevel@tonic-gate 	uint64_t	capacity = 0;
381*7c478bd9Sstevel@tonic-gate 	int		error = 0;
382*7c478bd9Sstevel@tonic-gate 
383*7c478bd9Sstevel@tonic-gate 	*concat = NULL;
384*7c478bd9Sstevel@tonic-gate 
385*7c478bd9Sstevel@tonic-gate 	((error = disks_get_avail_slices(request, disks, &slices)) != 0) ||
386*7c478bd9Sstevel@tonic-gate 	(error = get_volume_npaths(request, &npaths));
387*7c478bd9Sstevel@tonic-gate 	if (error != 0) {
388*7c478bd9Sstevel@tonic-gate 	    dlist_free_items(slices, NULL);
389*7c478bd9Sstevel@tonic-gate 	    return (error);
390*7c478bd9Sstevel@tonic-gate 	}
391*7c478bd9Sstevel@tonic-gate 
392*7c478bd9Sstevel@tonic-gate 	print_populate_volume_msg(devconfig_type_to_str(TYPE_CONCAT), nbytes);
393*7c478bd9Sstevel@tonic-gate 
394*7c478bd9Sstevel@tonic-gate 	if (slices == NULL) {
395*7c478bd9Sstevel@tonic-gate 	    print_populate_no_slices_msg();
396*7c478bd9Sstevel@tonic-gate 	    return (0);
397*7c478bd9Sstevel@tonic-gate 	}
398*7c478bd9Sstevel@tonic-gate 
399*7c478bd9Sstevel@tonic-gate 	/* determine HBAs and disks used by othervols */
400*7c478bd9Sstevel@tonic-gate 	error = get_hbas_and_disks_used_by_volumes(othervols,
401*7c478bd9Sstevel@tonic-gate 		&other_hbas, &other_disks);
402*7c478bd9Sstevel@tonic-gate 	if (error != 0) {
403*7c478bd9Sstevel@tonic-gate 	    dlist_free_items(other_hbas, NULL);
404*7c478bd9Sstevel@tonic-gate 	    dlist_free_items(other_disks, NULL);
405*7c478bd9Sstevel@tonic-gate 	    return (error);
406*7c478bd9Sstevel@tonic-gate 	}
407*7c478bd9Sstevel@tonic-gate 
408*7c478bd9Sstevel@tonic-gate 	print_populate_choose_slices_msg();
409*7c478bd9Sstevel@tonic-gate 
410*7c478bd9Sstevel@tonic-gate 	while (capacity < nbytes) {
411*7c478bd9Sstevel@tonic-gate 
412*7c478bd9Sstevel@tonic-gate 	    devconfig_t	*comp = NULL;
413*7c478bd9Sstevel@tonic-gate 	    dlist_t	*item = NULL;
414*7c478bd9Sstevel@tonic-gate 	    dlist_t	*rmvd = NULL;
415*7c478bd9Sstevel@tonic-gate 	    char	*cname = NULL;
416*7c478bd9Sstevel@tonic-gate 	    uint64_t	csize = 0;
417*7c478bd9Sstevel@tonic-gate 
418*7c478bd9Sstevel@tonic-gate 	    /* BEGIN CSTYLED */
419*7c478bd9Sstevel@tonic-gate 	    /*
420*7c478bd9Sstevel@tonic-gate 	     * 1st B_TRUE: require a different disk than those used by
421*7c478bd9Sstevel@tonic-gate 	     *		comps and othervols
422*7c478bd9Sstevel@tonic-gate 	     * 1st B_FALSE: slice with size less that requested is acceptable
423*7c478bd9Sstevel@tonic-gate 	     * 2nd B_FALSE: do not add an extra cylinder when resizing slice,
424*7c478bd9Sstevel@tonic-gate 	     *		this is only necessary for Stripe components whose sizes
425*7c478bd9Sstevel@tonic-gate 	     *		get rounded down to an interlace multiple and then down
426*7c478bd9Sstevel@tonic-gate 	     *		to a cylinder boundary.
427*7c478bd9Sstevel@tonic-gate 	     *
428*7c478bd9Sstevel@tonic-gate 	     */
429*7c478bd9Sstevel@tonic-gate 	    /* END CSTYLED */
430*7c478bd9Sstevel@tonic-gate 	    error = choose_slice((nbytes-capacity), npaths, slices, comps,
431*7c478bd9Sstevel@tonic-gate 		    other_hbas, other_disks, B_TRUE, B_FALSE, B_FALSE, &comp);
432*7c478bd9Sstevel@tonic-gate 
433*7c478bd9Sstevel@tonic-gate 	    if ((error == 0) && (comp != NULL)) {
434*7c478bd9Sstevel@tonic-gate 
435*7c478bd9Sstevel@tonic-gate 		item = dlist_new_item(comp);
436*7c478bd9Sstevel@tonic-gate 		if (item == NULL) {
437*7c478bd9Sstevel@tonic-gate 		    error = ENOMEM;
438*7c478bd9Sstevel@tonic-gate 		} else  {
439*7c478bd9Sstevel@tonic-gate 
440*7c478bd9Sstevel@tonic-gate 		    /* add selected component to comp list */
441*7c478bd9Sstevel@tonic-gate 		    comps = dlist_append(item, comps, AT_HEAD);
442*7c478bd9Sstevel@tonic-gate 
443*7c478bd9Sstevel@tonic-gate 		    /* remove it from the available list */
444*7c478bd9Sstevel@tonic-gate 		    slices = dlist_remove_equivalent_item(slices, (void *) comp,
445*7c478bd9Sstevel@tonic-gate 			    compare_devconfig_and_descriptor_names, &rmvd);
446*7c478bd9Sstevel@tonic-gate 
447*7c478bd9Sstevel@tonic-gate 		    if (rmvd != NULL) {
448*7c478bd9Sstevel@tonic-gate 			free(rmvd);
449*7c478bd9Sstevel@tonic-gate 		    }
450*7c478bd9Sstevel@tonic-gate 
451*7c478bd9Sstevel@tonic-gate 		    /* add the component slice to the used list */
452*7c478bd9Sstevel@tonic-gate 		    if ((error = devconfig_get_name(comp, &cname)) == 0) {
453*7c478bd9Sstevel@tonic-gate 			error = add_used_slice_by_name(cname);
454*7c478bd9Sstevel@tonic-gate 		    }
455*7c478bd9Sstevel@tonic-gate 
456*7c478bd9Sstevel@tonic-gate 		    /* increment concat's capacity */
457*7c478bd9Sstevel@tonic-gate 		    if ((error == 0) &&
458*7c478bd9Sstevel@tonic-gate 			(error = devconfig_get_size(comp, &csize)) == 0) {
459*7c478bd9Sstevel@tonic-gate 			capacity += csize;
460*7c478bd9Sstevel@tonic-gate 		    }
461*7c478bd9Sstevel@tonic-gate 		}
462*7c478bd9Sstevel@tonic-gate 
463*7c478bd9Sstevel@tonic-gate 	    } else {
464*7c478bd9Sstevel@tonic-gate 		/* no possible slice */
465*7c478bd9Sstevel@tonic-gate 		break;
466*7c478bd9Sstevel@tonic-gate 	    }
467*7c478bd9Sstevel@tonic-gate 	}
468*7c478bd9Sstevel@tonic-gate 
469*7c478bd9Sstevel@tonic-gate 	dlist_free_items(slices, NULL);
470*7c478bd9Sstevel@tonic-gate 	dlist_free_items(other_hbas, NULL);
471*7c478bd9Sstevel@tonic-gate 	dlist_free_items(other_disks, NULL);
472*7c478bd9Sstevel@tonic-gate 
473*7c478bd9Sstevel@tonic-gate 	if (capacity >= nbytes) {
474*7c478bd9Sstevel@tonic-gate 
475*7c478bd9Sstevel@tonic-gate 	    error = assemble_concat(request, comps, concat);
476*7c478bd9Sstevel@tonic-gate 
477*7c478bd9Sstevel@tonic-gate 	    if (error == 0) {
478*7c478bd9Sstevel@tonic-gate 		print_populate_success_msg();
479*7c478bd9Sstevel@tonic-gate 	    } else {
480*7c478bd9Sstevel@tonic-gate 		/* undo any slicing done for the concat */
481*7c478bd9Sstevel@tonic-gate 		dlist_free_items(comps, free_devconfig_object);
482*7c478bd9Sstevel@tonic-gate 	    }
483*7c478bd9Sstevel@tonic-gate 
484*7c478bd9Sstevel@tonic-gate 	} else if (error == 0) {
485*7c478bd9Sstevel@tonic-gate 
486*7c478bd9Sstevel@tonic-gate 	    if (capacity > 0) {
487*7c478bd9Sstevel@tonic-gate 		dlist_free_items(comps, free_devconfig_object);
488*7c478bd9Sstevel@tonic-gate 		print_insufficient_capacity_msg(capacity);
489*7c478bd9Sstevel@tonic-gate 	    } else {
490*7c478bd9Sstevel@tonic-gate 		print_populate_no_slices_msg();
491*7c478bd9Sstevel@tonic-gate 	    }
492*7c478bd9Sstevel@tonic-gate 
493*7c478bd9Sstevel@tonic-gate 	}
494*7c478bd9Sstevel@tonic-gate 
495*7c478bd9Sstevel@tonic-gate 	return (error);
496*7c478bd9Sstevel@tonic-gate }
497*7c478bd9Sstevel@tonic-gate 
498*7c478bd9Sstevel@tonic-gate /*
499*7c478bd9Sstevel@tonic-gate  * FUNCTION:	populate_explicit_concat(devconfig_t *request,
500*7c478bd9Sstevel@tonic-gate  *			dlist_t **results)
501*7c478bd9Sstevel@tonic-gate  *
502*7c478bd9Sstevel@tonic-gate  * INPUT:	request	- pointer to a request devconfig_t
503*7c478bd9Sstevel@tonic-gate  *
504*7c478bd9Sstevel@tonic-gate  * OUTPUT:	results	- pointer to a list of volume devconfig_t results
505*7c478bd9Sstevel@tonic-gate  *
506*7c478bd9Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
507*7c478bd9Sstevel@tonic-gate  *			 !0 otherwise.
508*7c478bd9Sstevel@tonic-gate  *
509*7c478bd9Sstevel@tonic-gate  * PURPOSE:	Processes the input concat request that specifies explicit
510*7c478bd9Sstevel@tonic-gate  *		slice components.
511*7c478bd9Sstevel@tonic-gate  *
512*7c478bd9Sstevel@tonic-gate  *		The components have already been validated and reserved,
513*7c478bd9Sstevel@tonic-gate  *		all that is required is to create devconfig_t structs
514*7c478bd9Sstevel@tonic-gate  *		for each requested slice.
515*7c478bd9Sstevel@tonic-gate  *
516*7c478bd9Sstevel@tonic-gate  *		The net size of the concat is determined by the slice
517*7c478bd9Sstevel@tonic-gate  *		components.
518*7c478bd9Sstevel@tonic-gate  *
519*7c478bd9Sstevel@tonic-gate  *		The concat devconfig_t is assembled and appended to the
520*7c478bd9Sstevel@tonic-gate  *		results list.
521*7c478bd9Sstevel@tonic-gate  *
522*7c478bd9Sstevel@tonic-gate  *		This function is also called from
523*7c478bd9Sstevel@tonic-gate  *		    layout_mirror.populate_explicit_mirror()
524*7c478bd9Sstevel@tonic-gate  */
525*7c478bd9Sstevel@tonic-gate int
populate_explicit_concat(devconfig_t * request,dlist_t ** results)526*7c478bd9Sstevel@tonic-gate populate_explicit_concat(
527*7c478bd9Sstevel@tonic-gate 	devconfig_t	*request,
528*7c478bd9Sstevel@tonic-gate 	dlist_t		**results)
529*7c478bd9Sstevel@tonic-gate {
530*7c478bd9Sstevel@tonic-gate 	int		error = 0;
531*7c478bd9Sstevel@tonic-gate 
532*7c478bd9Sstevel@tonic-gate 	dlist_t		*comps = NULL;
533*7c478bd9Sstevel@tonic-gate 	dlist_t		*iter = NULL;
534*7c478bd9Sstevel@tonic-gate 	dlist_t		*item = NULL;
535*7c478bd9Sstevel@tonic-gate 
536*7c478bd9Sstevel@tonic-gate 	devconfig_t	*concat = NULL;
537*7c478bd9Sstevel@tonic-gate 
538*7c478bd9Sstevel@tonic-gate 	print_layout_explicit_msg(devconfig_type_to_str(TYPE_CONCAT));
539*7c478bd9Sstevel@tonic-gate 
540*7c478bd9Sstevel@tonic-gate 	/* assemble components */
541*7c478bd9Sstevel@tonic-gate 	iter = devconfig_get_components(request);
542*7c478bd9Sstevel@tonic-gate 	for (; (iter != NULL) && (error == 0); iter = iter->next) {
543*7c478bd9Sstevel@tonic-gate 
544*7c478bd9Sstevel@tonic-gate 	    devconfig_t	*rqst = (devconfig_t *)iter->obj;
545*7c478bd9Sstevel@tonic-gate 	    dm_descriptor_t rqst_slice = NULL;
546*7c478bd9Sstevel@tonic-gate 	    char	*rqst_name = NULL;
547*7c478bd9Sstevel@tonic-gate 	    devconfig_t	*comp = NULL;
548*7c478bd9Sstevel@tonic-gate 
549*7c478bd9Sstevel@tonic-gate 	    /* slice components have been validated */
550*7c478bd9Sstevel@tonic-gate 	    /* turn each into a devconfig_t */
551*7c478bd9Sstevel@tonic-gate 	    ((error = devconfig_get_name(rqst, &rqst_name)) != 0) ||
552*7c478bd9Sstevel@tonic-gate 	    (error = slice_get_by_name(rqst_name, &rqst_slice)) ||
553*7c478bd9Sstevel@tonic-gate 	    (error = create_devconfig_for_slice(rqst_slice, &comp));
554*7c478bd9Sstevel@tonic-gate 
555*7c478bd9Sstevel@tonic-gate 	    if (error == 0) {
556*7c478bd9Sstevel@tonic-gate 
557*7c478bd9Sstevel@tonic-gate 		print_layout_explicit_added_msg(rqst_name);
558*7c478bd9Sstevel@tonic-gate 
559*7c478bd9Sstevel@tonic-gate 		item = dlist_new_item((void *)comp);
560*7c478bd9Sstevel@tonic-gate 		if (item == NULL) {
561*7c478bd9Sstevel@tonic-gate 		    error = ENOMEM;
562*7c478bd9Sstevel@tonic-gate 		} else {
563*7c478bd9Sstevel@tonic-gate 		    comps = dlist_append(item, comps, AT_TAIL);
564*7c478bd9Sstevel@tonic-gate 		}
565*7c478bd9Sstevel@tonic-gate 	    }
566*7c478bd9Sstevel@tonic-gate 	}
567*7c478bd9Sstevel@tonic-gate 
568*7c478bd9Sstevel@tonic-gate 	if (error == 0) {
569*7c478bd9Sstevel@tonic-gate 	    error = assemble_concat(request, comps, &concat);
570*7c478bd9Sstevel@tonic-gate 	}
571*7c478bd9Sstevel@tonic-gate 
572*7c478bd9Sstevel@tonic-gate 	if (error == 0) {
573*7c478bd9Sstevel@tonic-gate 	    if ((item = dlist_new_item(concat)) == NULL) {
574*7c478bd9Sstevel@tonic-gate 		error = ENOMEM;
575*7c478bd9Sstevel@tonic-gate 	    } else {
576*7c478bd9Sstevel@tonic-gate 		*results = dlist_append(item, *results, AT_TAIL);
577*7c478bd9Sstevel@tonic-gate 		print_populate_success_msg();
578*7c478bd9Sstevel@tonic-gate 	    }
579*7c478bd9Sstevel@tonic-gate 	} else {
580*7c478bd9Sstevel@tonic-gate 	    dlist_free_items(comps, free_devconfig);
581*7c478bd9Sstevel@tonic-gate 	}
582*7c478bd9Sstevel@tonic-gate 
583*7c478bd9Sstevel@tonic-gate 	return (error);
584*7c478bd9Sstevel@tonic-gate }
585*7c478bd9Sstevel@tonic-gate 
586*7c478bd9Sstevel@tonic-gate /*
587*7c478bd9Sstevel@tonic-gate  * FUNCTION:	assemble_concat(devconfig_t *request, dlist_t *comps,
588*7c478bd9Sstevel@tonic-gate  *			devconfig_t **concat)
589*7c478bd9Sstevel@tonic-gate  *
590*7c478bd9Sstevel@tonic-gate  * INPUT:	request	- pointer to a devconfig_t of the current request
591*7c478bd9Sstevel@tonic-gate  *		comps	- pointer to a list of slice components
592*7c478bd9Sstevel@tonic-gate  *
593*7c478bd9Sstevel@tonic-gate  * OUPUT:	concat	- pointer to a devconfig_t to hold final concat
594*7c478bd9Sstevel@tonic-gate  *
595*7c478bd9Sstevel@tonic-gate  * RETURNS:	int	- 0 on success
596*7c478bd9Sstevel@tonic-gate  *			 !0 otherwise.
597*7c478bd9Sstevel@tonic-gate  *
598*7c478bd9Sstevel@tonic-gate  * PURPOSE:	Helper which creates and populates a concat devconfig_t
599*7c478bd9Sstevel@tonic-gate  *		struct using information from the input request and the
600*7c478bd9Sstevel@tonic-gate  *		list of slice components.
601*7c478bd9Sstevel@tonic-gate  *
602*7c478bd9Sstevel@tonic-gate  *		Determines the name of the concat either from the request
603*7c478bd9Sstevel@tonic-gate  *		or from the default naming scheme.
604*7c478bd9Sstevel@tonic-gate  *
605*7c478bd9Sstevel@tonic-gate  *		Attaches the input list of components to the devconfig.
606*7c478bd9Sstevel@tonic-gate  */
607*7c478bd9Sstevel@tonic-gate static int
assemble_concat(devconfig_t * request,dlist_t * comps,devconfig_t ** concat)608*7c478bd9Sstevel@tonic-gate assemble_concat(
609*7c478bd9Sstevel@tonic-gate 	devconfig_t	*request,
610*7c478bd9Sstevel@tonic-gate 	dlist_t		*comps,
611*7c478bd9Sstevel@tonic-gate 	devconfig_t	**concat)
612*7c478bd9Sstevel@tonic-gate {
613*7c478bd9Sstevel@tonic-gate 	char		*name = NULL;
614*7c478bd9Sstevel@tonic-gate 	int		error = 0;
615*7c478bd9Sstevel@tonic-gate 
616*7c478bd9Sstevel@tonic-gate 	if ((error = new_devconfig(concat, TYPE_CONCAT)) == 0) {
617*7c478bd9Sstevel@tonic-gate 	    /* set concat name, use requested name if specified */
618*7c478bd9Sstevel@tonic-gate 	    if ((error = devconfig_get_name(request, &name)) != 0) {
619*7c478bd9Sstevel@tonic-gate 		if (error != ERR_ATTR_UNSET) {
620*7c478bd9Sstevel@tonic-gate 		    volume_set_error(gettext("error getting requested name\n"));
621*7c478bd9Sstevel@tonic-gate 		} else {
622*7c478bd9Sstevel@tonic-gate 		    error = 0;
623*7c478bd9Sstevel@tonic-gate 		}
624*7c478bd9Sstevel@tonic-gate 	    }
625*7c478bd9Sstevel@tonic-gate 
626*7c478bd9Sstevel@tonic-gate 	    if (error == 0) {
627*7c478bd9Sstevel@tonic-gate 		if (name == NULL) {
628*7c478bd9Sstevel@tonic-gate 		    if ((error = get_next_volume_name(&name,
629*7c478bd9Sstevel@tonic-gate 			TYPE_CONCAT)) == 0) {
630*7c478bd9Sstevel@tonic-gate 			error = devconfig_set_name(*concat, name);
631*7c478bd9Sstevel@tonic-gate 			free(name);
632*7c478bd9Sstevel@tonic-gate 		    }
633*7c478bd9Sstevel@tonic-gate 		} else {
634*7c478bd9Sstevel@tonic-gate 		    error = devconfig_set_name(*concat, name);
635*7c478bd9Sstevel@tonic-gate 		}
636*7c478bd9Sstevel@tonic-gate 	    }
637*7c478bd9Sstevel@tonic-gate 	}
638*7c478bd9Sstevel@tonic-gate 
639*7c478bd9Sstevel@tonic-gate 	if (error == 0) {
640*7c478bd9Sstevel@tonic-gate 
641*7c478bd9Sstevel@tonic-gate 	    /* compute and save true size of concat */
642*7c478bd9Sstevel@tonic-gate 	    if (error == 0) {
643*7c478bd9Sstevel@tonic-gate 		uint64_t nblks = 0;
644*7c478bd9Sstevel@tonic-gate 		dlist_t *iter;
645*7c478bd9Sstevel@tonic-gate 
646*7c478bd9Sstevel@tonic-gate 		for (iter = comps;
647*7c478bd9Sstevel@tonic-gate 		    (error == 0) && (iter != NULL);
648*7c478bd9Sstevel@tonic-gate 		    iter = iter->next) {
649*7c478bd9Sstevel@tonic-gate 
650*7c478bd9Sstevel@tonic-gate 		    devconfig_t *comp = (devconfig_t *)iter->obj;
651*7c478bd9Sstevel@tonic-gate 		    uint64_t comp_nblks = 0;
652*7c478bd9Sstevel@tonic-gate 
653*7c478bd9Sstevel@tonic-gate 		    if ((error = devconfig_get_size_in_blocks(comp,
654*7c478bd9Sstevel@tonic-gate 			&comp_nblks)) == 0) {
655*7c478bd9Sstevel@tonic-gate 			nblks += comp_nblks;
656*7c478bd9Sstevel@tonic-gate 		    }
657*7c478bd9Sstevel@tonic-gate 		}
658*7c478bd9Sstevel@tonic-gate 
659*7c478bd9Sstevel@tonic-gate 		if (error == 0) {
660*7c478bd9Sstevel@tonic-gate 		    error = devconfig_set_size_in_blocks(*concat, nblks);
661*7c478bd9Sstevel@tonic-gate 		}
662*7c478bd9Sstevel@tonic-gate 	    }
663*7c478bd9Sstevel@tonic-gate 	}
664*7c478bd9Sstevel@tonic-gate 
665*7c478bd9Sstevel@tonic-gate 	if (error == 0) {
666*7c478bd9Sstevel@tonic-gate 	    devconfig_set_components(*concat, comps);
667*7c478bd9Sstevel@tonic-gate 	} else {
668*7c478bd9Sstevel@tonic-gate 	    free_devconfig(*concat);
669*7c478bd9Sstevel@tonic-gate 	    *concat = NULL;
670*7c478bd9Sstevel@tonic-gate 	}
671*7c478bd9Sstevel@tonic-gate 
672*7c478bd9Sstevel@tonic-gate 	return (error);
673*7c478bd9Sstevel@tonic-gate }
674