xref: /titanic_41/usr/src/cmd/lvm/metassist/layout/layout_messages.c (revision e4d060fb4c00d44cd578713eb9a921f594b733b8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <libintl.h>
30 #include <stdlib.h>
31 
32 #include "volume_error.h"
33 #include "volume_output.h"
34 #include "volume_string.h"
35 
36 #include "layout_messages.h"
37 
38 /*
39  * FUNCTION:	print_layout_volume_msg(char *type, uint64_t nbytes)
40  *
41  * PURPOSE:	Prints a generic message indicating the start of the
42  *		layout process for a volume of the indicated type and
43  *		capacity.
44  */
45 void
46 print_layout_volume_msg(
47 	char *type,
48 	uint64_t nbytes)
49 {
50 	char *spstr = NULL;
51 
52 	(void) bytes_to_sizestr(nbytes, &spstr, universal_units, B_FALSE);
53 
54 	oprintf(OUTPUT_VERBOSE,
55 		gettext("  ->Layout a %s with capacity %s\n"),
56 		type, spstr);
57 
58 	free(spstr);
59 }
60 
61 /*
62  * FUNCTION:	print_layout_explicit_msg(char *type)
63  *
64  * PURPOSE:	Prints a generic message indicating the start of the
65  *		layout population process using explicit components
66  *		for a volume of the indicated type.
67  */
68 void
69 print_layout_explicit_msg(
70 	char *type)
71 {
72 	oprintf(OUTPUT_TERSE,
73 		gettext("  ->Layout a %s with explicitly specified "
74 			"components\n"),
75 		type);
76 }
77 
78 /*
79  * FUNCTION:	print_layout_explicit_added_msg(char *comp)
80  *
81  * PURPOSE:	Prints a generic message indicating the named component
82  *		was added to a volume.
83  */
84 void
85 print_layout_explicit_added_msg(
86 	char *comp)
87 {
88 	oprintf(OUTPUT_TERSE, gettext("  ---->added '%s'\n"), comp);
89 }
90 
91 /*
92  * FUNCTION:	print_success_msg()
93  *
94  * PURPOSE:	Prints a generic layout success message.
95  */
96 void
97 print_layout_success_msg()
98 {
99 	oprintf(OUTPUT_TERSE, gettext("  <-Success!\n"));
100 }
101 
102 /*
103  * FUNCTION:	print_insufficient_resources_msg(char *type)
104  *
105  * PURPOSE:	Prints a message indicating that there are insufficient
106  *		resources.
107  *
108  *		Also sets the metassist error string indicating why
109  *		the metassist command failed.  The volume type is included
110  *		for context in this message.
111  */
112 void
113 print_insufficient_resources_msg(
114 	char *type)
115 {
116 	oprintf(OUTPUT_TERSE,
117 		gettext("  <-Failed: insufficient resources available\n"));
118 
119 	volume_set_error(
120 		gettext("insufficient resources available to complete "
121 			"requested %s\n"),
122 		type);
123 }
124 
125 /*
126  * FUNCTION:	print_insufficient_hbas_msg(int n)
127  *
128  * PURPOSE:	Prints a status message indicating that there are insufficient
129  *		HBAs and that only 'n' are available.
130  *
131  *		Used to indicate strategy selection during layouts.
132  */
133 void
134 print_insufficient_hbas_msg(
135 	int n)
136 {
137 	if (n == 0) {
138 	    oprintf(OUTPUT_VERBOSE,
139 		gettext("  <--Failed: no HBA has sufficient disks\n"));
140 	} else if (n == 1) {
141 	    oprintf(OUTPUT_VERBOSE,
142 		gettext("  <--Failed: only 1 HBA has sufficient disks\n"));
143 	} else {
144 	    oprintf(OUTPUT_VERBOSE,
145 		gettext("  <--Failed: only %d HBAs have sufficient disks\n"),
146 		n);
147 	}
148 }
149 
150 /*
151  * FUNCTION:	print_insufficient_disks_msg(int n)
152  *
153  * PURPOSE:	Prints a status message indicating that there are insufficient
154  *		disks and that only 'n' are available.
155  *
156  *		Used to indicate strategy selection during layouts.
157  */
158 void
159 print_insufficient_disks_msg(
160 	int n)
161 {
162 	if (n == 0) {
163 	    oprintf(OUTPUT_VERBOSE,
164 		    gettext("  <--Failed: no disks available\n"),
165 		    n);
166 	} else if (n == 1) {
167 	    oprintf(OUTPUT_VERBOSE,
168 		gettext("  <--Failed: only 1 disk available\n"),
169 		    n);
170 	} else {
171 	    oprintf(OUTPUT_VERBOSE,
172 		    gettext("  <--Failed: only %d disks available\n"),
173 		    n);
174 	}
175 }
176 
177 /*
178  * FUNCTION:	print_no_hbas_msg()
179  *
180  * PURPOSE:	Prints a layout failure due to no usable HBAs message.
181  */
182 void
183 print_no_hbas_msg()
184 {
185 	oprintf(OUTPUT_TERSE,
186 		gettext("  There are no usable HBAs.\n"));
187 }
188 
189 /*
190  * FUNCTION:	print_debug_failure_msg(char *type, char *err)
191  *
192  * PURPOSE:	Prints a generic message for unexpected failures
193  *		during layout.
194  */
195 void
196 print_debug_failure_msg(
197 	char *type,
198 	char *err)
199 {
200 	oprintf(OUTPUT_DEBUG,
201 		gettext("    layout of %s failed: %s\n"),
202 		type, err);
203 }
204 
205 /*
206  * FUNCTION:	print_insufficient_components_msg(int ncomp)
207  *
208  * INPUT:	ncomp	- number of available components
209  *
210  * PURPOSE:	Helper to print out a message indicating that there
211  *		are insufficient components for a volume, only ncomps
212  *		are actually available.
213  */
214 void
215 print_insufficient_components_msg(
216 	int	ncomp)
217 {
218 	oprintf(OUTPUT_VERBOSE,
219 		gettext("  <---Failed: only found %d components\n"), ncomp);
220 }
221 
222 /*
223  * FUNCTION:	print_hba_insufficient_space_msg(char *name, uint64_t nbytes)
224  *
225  * INPUT:	name	- a char * HBA name
226  *
227  * RETURNS:	int	- 0 on success
228  *			 !0 otherwise.
229  *
230  * PURPOSE:	Helper to print out a message indicating the the HBA has
231  *		insufficient space for use by the mirror layout strategy.
232  */
233 void
234 print_hba_insufficient_space_msg(
235 	char		*name,
236 	uint64_t	nbytes)
237 {
238 	char *spstr = NULL;
239 
240 	(void) bytes_to_sizestr(nbytes, &spstr, universal_units, B_FALSE);
241 
242 	oprintf(OUTPUT_VERBOSE,
243 		gettext("  <--Failed: '%s' only has %s available\n"),
244 		name, spstr);
245 
246 	free(spstr);
247 }
248 
249 /*
250  * FUNCTION:	print_insufficient_capacity_msg(uint64_t nbytes)
251  *
252  * INPUT:	nbytes	- available capacity in bytes
253  *
254  * PURPOSE:	Helper to print out a message indicating that there
255  *		is insufficient space for a volume, only nbytes are
256  *		actually available.
257  */
258 void
259 print_insufficient_capacity_msg(
260 	uint64_t nbytes)
261 {
262 	char *spstr = NULL;
263 
264 	(void) bytes_to_sizestr(nbytes, &spstr, universal_units, B_FALSE);
265 
266 	oprintf(OUTPUT_VERBOSE,
267 		gettext("  <---Failed: only found %s capacity\n"), spstr);
268 
269 	free(spstr);
270 }
271 
272 /*
273  * FUNCTION:	print_layout_submirrors_msg(char *type, uint64_t nbytes,
274  *		int nsubs)
275  *
276  * PURPOSE:	Prints a generic status message indicating that layout of
277  *		nsub submirrors of the indicated type and size has begun.
278  */
279 void
280 print_layout_submirrors_msg(
281 	char	*type,
282 	uint64_t nbytes,
283 	int	nsubs)
284 {
285 	char *spstr = NULL;
286 
287 	(void) bytes_to_sizestr(nbytes, &spstr, universal_units, B_FALSE);
288 
289 	oprintf(OUTPUT_TERSE,
290 		gettext("  -->Layout %d %s submirrors with capacity %s\n"),
291 		nsubs, type, spstr);
292 
293 	free(spstr);
294 }
295 
296 /*
297  * FUNCTION:	print_layout_submirrors_failed_msg(char *type, int count,
298  *			int nsubs)
299  *
300  * PURPOSE:	Prints a generic status message indicating that only count
301  *		submirrors (out of nsubs) of the indicated type could be
302  *		composed.
303  */
304 void
305 print_layout_submirrors_failed_msg(
306 	char	*type,
307 	int	count,
308 	int	nsubs)
309 {
310 	if (count == 0) {
311 	    oprintf(OUTPUT_VERBOSE,
312 		    gettext("  <---Failed, no %s submirrors could "
313 			    "be composed.\n"),
314 		    type);
315 	} else {
316 	    oprintf(OUTPUT_VERBOSE,
317 		    gettext("  <---Failed, only %d of %d %s submirror(s) "
318 			    "could be composed.\n"),
319 		    count, nsubs, type);
320 	}
321 }
322 
323 /*
324  * FUNCTION:	print_populate_volume_msg(char *type, uint64_t nbytes)
325  *
326  * PURPOSE:	Prints a generic message indicating a population process
327  *		for a volume of the indicated type and size is beginning.
328  */
329 void
330 print_populate_volume_msg(
331 	char *type,
332 	uint64_t nbytes)
333 {
334 	char *spstr = NULL;
335 
336 	(void) bytes_to_sizestr(nbytes, &spstr, universal_units, B_FALSE);
337 
338 	oprintf(OUTPUT_TERSE,
339 		gettext("  --->Populate a %s of capacity %s\n"),
340 		type, spstr);
341 
342 	free(spstr);
343 }
344 
345 /*
346  * FUNCTION:	print_populate_volume_ncomps_msg(char *type, uint64_t nbytes,
347  *			int ncomps)
348  *
349  * PURPOSE:	Prints a generic message indicating a population process
350  *		for a volume of the indicated type, size and number of
351  *		components is beginning.
352  */
353 void
354 print_populate_volume_ncomps_msg(
355 	char *type,
356 	uint64_t nbytes,
357 	int ncomps)
358 {
359 	char *spstr = NULL;
360 
361 	(void) bytes_to_sizestr(nbytes, &spstr, universal_units, B_FALSE);
362 
363 	oprintf(OUTPUT_TERSE,
364 		gettext("  --->Populate a %s of capacity %s (%d components)\n"),
365 		type, spstr, ncomps);
366 
367 	free(spstr);
368 }
369 
370 /*
371  * FUNCTION:	print_populate_success_msg()
372  *
373  * PURPOSE:	Prints a generic message indicating a population process
374  *		completed successfully.
375  */
376 void
377 print_populate_success_msg()
378 {
379 	oprintf(OUTPUT_TERSE,
380 		gettext("  <---Success!\n"));
381 }
382 
383 /*
384  * FUNCTION:	print_populate_choose_slices_msg()
385  *
386  * PURPOSE:	Prints a generic message indicating a population process
387  *		is beginning to choose slices.
388  */
389 void
390 print_populate_choose_slices_msg()
391 {
392 	oprintf(OUTPUT_VERBOSE,
393 		gettext("      choosing \"best\" slices from "
394 			"those available...\n"));
395 }
396 
397 /*
398  * FUNCTION:	print_populate_no_slices_msg()
399  *
400  * PURPOSE:	Prints a layout failure due to no available slices message.
401  */
402 void
403 print_populate_no_slices_msg()
404 {
405 	oprintf(OUTPUT_VERBOSE,
406 		gettext("  <---Failed: there are no slices available.\n"));
407 }
408