summaryrefslogtreecommitdiff
path: root/usr/src/cmd/lvm/metassist/layout/layout_messages.c
blob: c652972b7bf91c242c2432b66985651b4eef33ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <libintl.h>
#include <stdlib.h>

#include "volume_error.h"
#include "volume_output.h"
#include "volume_string.h"

#include "layout_messages.h"

/*
 * FUNCTION:	print_layout_volume_msg(char *type, uint64_t nbytes)
 *
 * PURPOSE:	Prints a generic message indicating the start of the
 *		layout process for a volume of the indicated type and
 *		capacity.
 */
void
print_layout_volume_msg(
	char *type,
	uint64_t nbytes)
{
	char *spstr = NULL;

	(void) bytes_to_sizestr(nbytes, &spstr, universal_units, B_FALSE);

	oprintf(OUTPUT_VERBOSE,
		gettext("  ->Layout a %s with capacity %s\n"),
		type, spstr);

	free(spstr);
}

/*
 * FUNCTION:	print_layout_explicit_msg(char *type)
 *
 * PURPOSE:	Prints a generic message indicating the start of the
 *		layout population process using explicit components
 *		for a volume of the indicated type.
 */
void
print_layout_explicit_msg(
	char *type)
{
	oprintf(OUTPUT_TERSE,
		gettext("  ->Layout a %s with explicitly specified "
			"components\n"),
		type);
}

/*
 * FUNCTION:	print_layout_explicit_added_msg(char *comp)
 *
 * PURPOSE:	Prints a generic message indicating the named component
 *		was added to a volume.
 */
void
print_layout_explicit_added_msg(
	char *comp)
{
	oprintf(OUTPUT_TERSE, gettext("  ---->added '%s'\n"), comp);
}

/*
 * FUNCTION:	print_success_msg()
 *
 * PURPOSE:	Prints a generic layout success message.
 */
void
print_layout_success_msg()
{
	oprintf(OUTPUT_TERSE, gettext("  <-Success!\n"));
}

/*
 * FUNCTION:	print_insufficient_resources_msg(char *type)
 *
 * PURPOSE:	Prints a message indicating that there are insufficient
 *		resources.
 *
 *		Also sets the metassist error string indicating why
 *		the metassist command failed.  The volume type is included
 *		for context in this message.
 */
void
print_insufficient_resources_msg(
	char *type)
{
	oprintf(OUTPUT_TERSE,
		gettext("  <-Failed: insufficient resources available\n"));

	volume_set_error(
		gettext("insufficient resources available to complete "
			"requested %s\n"),
		type);
}

/*
 * FUNCTION:	print_insufficient_hbas_msg(int n)
 *
 * PURPOSE:	Prints a status message indicating that there are insufficient
 *		HBAs and that only 'n' are available.
 *
 *		Used to indicate strategy selection during layouts.
 */
void
print_insufficient_hbas_msg(
	int n)
{
	if (n == 0) {
	    oprintf(OUTPUT_VERBOSE,
		gettext("  <--Failed: no HBA has sufficient disks\n"));
	} else if (n == 1) {
	    oprintf(OUTPUT_VERBOSE,
		gettext("  <--Failed: only 1 HBA has sufficient disks\n"));
	} else {
	    oprintf(OUTPUT_VERBOSE,
		gettext("  <--Failed: only %d HBAs have sufficient disks\n"),
		n);
	}
}

/*
 * FUNCTION:	print_insufficient_disks_msg(int n)
 *
 * PURPOSE:	Prints a status message indicating that there are insufficient
 *		disks and that only 'n' are available.
 *
 *		Used to indicate strategy selection during layouts.
 */
void
print_insufficient_disks_msg(
	int n)
{
	if (n == 0) {
	    oprintf(OUTPUT_VERBOSE,
		    gettext("  <--Failed: no disks available\n"),
		    n);
	} else if (n == 1) {
	    oprintf(OUTPUT_VERBOSE,
		gettext("  <--Failed: only 1 disk available\n"),
		    n);
	} else {
	    oprintf(OUTPUT_VERBOSE,
		    gettext("  <--Failed: only %d disks available\n"),
		    n);
	}
}

/*
 * FUNCTION:	print_no_hbas_msg()
 *
 * PURPOSE:	Prints a layout failure due to no usable HBAs message.
 */
void
print_no_hbas_msg()
{
	oprintf(OUTPUT_TERSE,
		gettext("  There are no usable HBAs.\n"));
}

/*
 * FUNCTION:	print_debug_failure_msg(char *type, char *err)
 *
 * PURPOSE:	Prints a generic message for unexpected failures
 *		during layout.
 */
void
print_debug_failure_msg(
	char *type,
	char *err)
{
	oprintf(OUTPUT_DEBUG,
		gettext("    layout of %s failed: %s\n"),
		type, err);
}

/*
 * FUNCTION:	print_insufficient_components_msg(int ncomp)
 *
 * INPUT:	ncomp	- number of available components
 *
 * PURPOSE:	Helper to print out a message indicating that there
 *		are insufficient components for a volume, only ncomps
 *		are actually available.
 */
void
print_insufficient_components_msg(
	int	ncomp)
{
	oprintf(OUTPUT_VERBOSE,
		gettext("  <---Failed: only found %d components\n"), ncomp);
}

/*
 * FUNCTION:	print_hba_insufficient_space_msg(char *name, uint64_t nbytes)
 *
 * INPUT:	name	- a char * HBA name
 *
 * RETURNS:	int	- 0 on success
 *			 !0 otherwise.
 *
 * PURPOSE:	Helper to print out a message indicating the the HBA has
 *		insufficient space for use by the mirror layout strategy.
 */
void
print_hba_insufficient_space_msg(
	char		*name,
	uint64_t	nbytes)
{
	char *spstr = NULL;

	(void) bytes_to_sizestr(nbytes, &spstr, universal_units, B_FALSE);

	oprintf(OUTPUT_VERBOSE,
		gettext("  <--Failed: '%s' only has %s available\n"),
		name, spstr);

	free(spstr);
}

/*
 * FUNCTION:	print_insufficient_capacity_msg(uint64_t nbytes)
 *
 * INPUT:	nbytes	- available capacity in bytes
 *
 * PURPOSE:	Helper to print out a message indicating that there
 *		is insufficient space for a volume, only nbytes are
 *		actually available.
 */
void
print_insufficient_capacity_msg(
	uint64_t nbytes)
{
	char *spstr = NULL;

	(void) bytes_to_sizestr(nbytes, &spstr, universal_units, B_FALSE);

	oprintf(OUTPUT_VERBOSE,
		gettext("  <---Failed: only found %s capacity\n"), spstr);

	free(spstr);
}

/*
 * FUNCTION:	print_layout_submirrors_msg(char *type, uint64_t nbytes,
 *		int nsubs)
 *
 * PURPOSE:	Prints a generic status message indicating that layout of
 *		nsub submirrors of the indicated type and size has begun.
 */
void
print_layout_submirrors_msg(
	char	*type,
	uint64_t nbytes,
	int	nsubs)
{
	char *spstr = NULL;

	(void) bytes_to_sizestr(nbytes, &spstr, universal_units, B_FALSE);

	oprintf(OUTPUT_TERSE,
		gettext("  -->Layout %d %s submirrors with capacity %s\n"),
		nsubs, type, spstr);

	free(spstr);
}

/*
 * FUNCTION:	print_layout_submirrors_failed_msg(char *type, int count,
 *			int nsubs)
 *
 * PURPOSE:	Prints a generic status message indicating that only count
 *		submirrors (out of nsubs) of the indicated type could be
 *		composed.
 */
void
print_layout_submirrors_failed_msg(
	char	*type,
	int	count,
	int	nsubs)
{
	if (count == 0) {
	    oprintf(OUTPUT_VERBOSE,
		    gettext("  <---Failed, no %s submirrors could "
			    "be composed.\n"),
		    type);
	} else {
	    oprintf(OUTPUT_VERBOSE,
		    gettext("  <---Failed, only %d of %d %s submirror(s) "
			    "could be composed.\n"),
		    count, nsubs, type);
	}
}

/*
 * FUNCTION:	print_populate_volume_msg(char *type, uint64_t nbytes)
 *
 * PURPOSE:	Prints a generic message indicating a population process
 *		for a volume of the indicated type and size is beginning.
 */
void
print_populate_volume_msg(
	char *type,
	uint64_t nbytes)
{
	char *spstr = NULL;

	(void) bytes_to_sizestr(nbytes, &spstr, universal_units, B_FALSE);

	oprintf(OUTPUT_TERSE,
		gettext("  --->Populate a %s of capacity %s\n"),
		type, spstr);

	free(spstr);
}

/*
 * FUNCTION:	print_populate_volume_ncomps_msg(char *type, uint64_t nbytes,
 *			int ncomps)
 *
 * PURPOSE:	Prints a generic message indicating a population process
 *		for a volume of the indicated type, size and number of
 *		components is beginning.
 */
void
print_populate_volume_ncomps_msg(
	char *type,
	uint64_t nbytes,
	int ncomps)
{
	char *spstr = NULL;

	(void) bytes_to_sizestr(nbytes, &spstr, universal_units, B_FALSE);

	oprintf(OUTPUT_TERSE,
		gettext("  --->Populate a %s of capacity %s (%d components)\n"),
		type, spstr, ncomps);

	free(spstr);
}

/*
 * FUNCTION:	print_populate_success_msg()
 *
 * PURPOSE:	Prints a generic message indicating a population process
 *		completed successfully.
 */
void
print_populate_success_msg()
{
	oprintf(OUTPUT_TERSE,
		gettext("  <---Success!\n"));
}

/*
 * FUNCTION:	print_populate_choose_slices_msg()
 *
 * PURPOSE:	Prints a generic message indicating a population process
 *		is beginning to choose slices.
 */
void
print_populate_choose_slices_msg()
{
	oprintf(OUTPUT_VERBOSE,
		gettext("      choosing \"best\" slices from "
			"those available...\n"));
}

/*
 * FUNCTION:	print_populate_no_slices_msg()
 *
 * PURPOSE:	Prints a layout failure due to no available slices message.
 */
void
print_populate_no_slices_msg()
{
	oprintf(OUTPUT_VERBOSE,
		gettext("  <---Failed: there are no slices available.\n"));
}