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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
|
/*
* 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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <string.h>
#include <libintl.h>
#include "libdiskmgt.h"
#include "volume_error.h"
#include "volume_defaults.h"
#include "volume_devconfig.h"
#include "volume_dlist.h"
#include "volume_output.h"
#include "volume_request.h"
#include "layout_concat.h"
#include "layout_device_cache.h"
#include "layout_device_util.h"
#include "layout_discovery.h"
#include "layout_dlist_util.h"
#include "layout_messages.h"
#include "layout_request.h"
#include "layout_slice.h"
#include "layout_svm_util.h"
#define _LAYOUT_CONCAT_C
static int
compose_concat_within_hba(
devconfig_t *request,
dlist_t *hbas,
uint64_t nbytes,
devconfig_t **concat);
static int
assemble_concat(
devconfig_t *request,
dlist_t *comps,
devconfig_t **concat);
/*
* FUNCTION: layout_concat(devconfig_t *request, uint64_t nbytes,
* dlist_t **results)
*
* INPUT: request - pointer to a devconfig_t of the current request
* nbytes - the desired capacity of the concat
*
* OUPUT: results - pointer to a list of composed volumes
*
* RETURNS: int - 0 on success
* !0 otherwise.
*
* PURPOSE: Main layout driver for composing concat volumes.
*
* Attempts to construct a concat of size nbytes.
*
* Several different layout strategies are tried in order
* of preference until one succeeds or there are none left.
*
* 1 - concat within an HBA
* . requires sufficient space available on the HBA
*
* 2 - concat across all available similar HBAs
*
* 3 - concat across all available HBAs
*
* get available HBAs
*
* group HBAs by characteristics
* for (each HBA grouping) and (concat not composed) {
* select next HBA group
* for (strategy[1,2]) and (concat not composed) {
* compose concat using HBAs in group
* }
* }
*
* if (concat not composed) {
* for (strategy[3]) and (concat not composed) {
* compose concat using all HBAs
* }
* }
*
* if (concat composed) {
* append composed concat to results
* }
*/
int
layout_concat(
devconfig_t *request,
uint64_t nbytes,
dlist_t **results)
{
/*
* these enums define the # of strategies and the preference order
* in which they are tried
*/
typedef enum {
CONCAT_WITHIN_SIMILAR_HBA = 0,
CONCAT_ACROSS_SIMILAR_HBAS,
N_SIMILAR_HBA_STRATEGIES
} similar_hba_strategy_order_t;
typedef enum {
CONCAT_ACROSS_ANY_HBAS = 0,
N_ANY_HBA_STRATEGIES
} any_hba_strategy_order_t;
dlist_t *usable_hbas = NULL;
dlist_t *similar_hba_groups = NULL;
dlist_t *iter = NULL;
devconfig_t *concat = NULL;
int error = 0;
(error = get_usable_hbas(&usable_hbas));
if (error != 0) {
volume_set_error(gettext("There are no usable HBAs."));
return (error);
}
print_layout_volume_msg(devconfig_type_to_str(TYPE_CONCAT), nbytes);
if (dlist_length(usable_hbas) == 0) {
print_no_hbas_msg();
return (-1);
}
error = group_similar_hbas(usable_hbas, &similar_hba_groups);
if (error != 0) {
return (error);
}
for (iter = similar_hba_groups;
(error == 0) && (concat == NULL) && (iter != NULL);
iter = iter->next) {
dlist_t *hbas = (dlist_t *)iter->obj;
similar_hba_strategy_order_t order;
for (order = CONCAT_WITHIN_SIMILAR_HBA;
(order < N_SIMILAR_HBA_STRATEGIES) &&
(concat == NULL) && (error == 0);
order++) {
dlist_t *selhbas = NULL;
dlist_t *disks = NULL;
switch (order) {
case CONCAT_WITHIN_SIMILAR_HBA:
error = select_hbas_with_n_disks(
request, hbas, 1, &selhbas, &disks);
if (error == 0) {
/* BEGIN CSTYLED */
oprintf(OUTPUT_TERSE,
gettext(" -->Strategy 1: use disks from a single HBA - concat within HBA\n"));
/* END CSTYLED */
error = compose_concat_within_hba(
request, selhbas, nbytes, &concat);
}
break;
case CONCAT_ACROSS_SIMILAR_HBAS:
error = select_hbas_with_n_disks(
request, hbas, 1, &selhbas, &disks);
if (error == 0) {
/* BEGIN CSTYLED */
oprintf(OUTPUT_TERSE,
gettext(" -->Strategy 2: use disks from all similar HBAs - concat across HBAs\n"));
/* END CSTYLED */
error = populate_concat(
request, nbytes, disks,
NULL, &concat);
}
break;
default:
break;
}
dlist_free_items(disks, NULL);
dlist_free_items(selhbas, NULL);
}
}
for (iter = similar_hba_groups; iter != NULL; iter = iter->next) {
dlist_free_items((dlist_t *)iter->obj, NULL);
}
dlist_free_items(similar_hba_groups, NULL);
/* try all HBAs */
if (concat == NULL && error == 0) {
any_hba_strategy_order_t order;
for (order = CONCAT_ACROSS_ANY_HBAS;
(order < N_ANY_HBA_STRATEGIES) &&
(concat == NULL) && (error == 0);
order++) {
dlist_t *selhbas = NULL;
dlist_t *disks = NULL;
switch (order) {
case CONCAT_ACROSS_ANY_HBAS:
error = select_hbas_with_n_disks(
request, usable_hbas, 1, &selhbas, &disks);
if (error == 0) {
/* BEGIN CSTYLED */
oprintf(OUTPUT_VERBOSE,
gettext(" -->Strategy 3: use disks from all available HBAs - concat across HBAs\n"));
/* END CSTYLED */
error = populate_concat(
request, nbytes, disks,
NULL, &concat);
}
break;
default:
break;
}
dlist_free_items(disks, NULL);
dlist_free_items(selhbas, NULL);
}
}
if (concat != NULL) {
dlist_t *item = dlist_new_item(concat);
if (item == NULL) {
error = ENOMEM;
} else {
*results = dlist_append(item, *results, AT_TAIL);
print_layout_success_msg();
}
} else if (error != 0) {
print_debug_failure_msg(
devconfig_type_to_str(TYPE_CONCAT),
get_error_string(error));
} else {
print_insufficient_resources_msg(
devconfig_type_to_str(TYPE_CONCAT));
error = -1;
}
return (error);
}
static int
compose_concat_within_hba(
devconfig_t *request,
dlist_t *hbas,
uint64_t nbytes,
devconfig_t **concat)
{
int error = 0;
dlist_t *iter = NULL;
for (iter = hbas;
(iter != NULL) && (*concat == NULL) && (error == 0);
iter = iter->next) {
dm_descriptor_t hba = (uintptr_t)iter->obj;
dlist_t *disks = NULL;
uint64_t space = 0;
char *name;
/* check for sufficient space on the HBA */
((error = get_display_name(hba, &name)) != 0) ||
(error = hba_get_avail_disks_and_space(request,
hba, &disks, &space));
if (error == 0) {
if (space >= nbytes) {
error = populate_concat(request, nbytes, disks,
NULL, concat);
} else {
print_hba_insufficient_space_msg(name, space);
}
}
dlist_free_items(disks, NULL);
}
return (error);
}
/*
* FUNCTION: populate_concat(devconfig_t *request, uint64_t nbytes,
* dlist_t *disks, dlist_t *othervols,
* devconfig_t **concat)
*
* INPUT: request - pointer to a request devconfig_t
* nbytes - desired concat size
* disks - pointer to a list of availalb disks
* othervols - pointer to a list of other volumes whose
* composition may affect this concat
* (e.g., submirrors of the same mirror)
*
* OUTPUT: concat - pointer to a devconfig_t to hold resulting concat
*
* RETURNS: int - 0 on success
* !0 otherwise.
*
* PURPOSE: Helper to populate a concat with the specified aggregate
* capacity using slices on disks in the input list.
*
* If the othervols list is not empty, the slice components
* chosen for the concat must not on the same disks as any
* of the other volumes.
*
* If sufficient slice components can be found, the concat
* is assembled and returned.
*/
int
populate_concat(
devconfig_t *request,
uint64_t nbytes,
dlist_t *disks,
dlist_t *othervols,
devconfig_t **concat)
{
dlist_t *other_hbas = NULL;
dlist_t *other_disks = NULL;
dlist_t *slices = NULL;
dlist_t *comps = NULL;
uint16_t npaths = 0;
uint64_t capacity = 0;
int error = 0;
*concat = NULL;
((error = disks_get_avail_slices(request, disks, &slices)) != 0) ||
(error = get_volume_npaths(request, &npaths));
if (error != 0) {
dlist_free_items(slices, NULL);
return (error);
}
print_populate_volume_msg(devconfig_type_to_str(TYPE_CONCAT), nbytes);
if (slices == NULL) {
print_populate_no_slices_msg();
return (0);
}
/* determine HBAs and disks used by othervols */
error = get_hbas_and_disks_used_by_volumes(othervols,
&other_hbas, &other_disks);
if (error != 0) {
dlist_free_items(other_hbas, NULL);
dlist_free_items(other_disks, NULL);
return (error);
}
print_populate_choose_slices_msg();
while (capacity < nbytes) {
devconfig_t *comp = NULL;
dlist_t *item = NULL;
dlist_t *rmvd = NULL;
char *cname = NULL;
uint64_t csize = 0;
/* BEGIN CSTYLED */
/*
* 1st B_TRUE: require a different disk than those used by
* comps and othervols
* 1st B_FALSE: slice with size less that requested is acceptable
* 2nd B_FALSE: do not add an extra cylinder when resizing slice,
* this is only necessary for Stripe components whose sizes
* get rounded down to an interlace multiple and then down
* to a cylinder boundary.
*
*/
/* END CSTYLED */
error = choose_slice((nbytes-capacity), npaths, slices, comps,
other_hbas, other_disks, B_TRUE, B_FALSE, B_FALSE, &comp);
if ((error == 0) && (comp != NULL)) {
item = dlist_new_item(comp);
if (item == NULL) {
error = ENOMEM;
} else {
/* add selected component to comp list */
comps = dlist_append(item, comps, AT_HEAD);
/* remove it from the available list */
slices = dlist_remove_equivalent_item(slices, (void *) comp,
compare_devconfig_and_descriptor_names, &rmvd);
if (rmvd != NULL) {
free(rmvd);
}
/* add the component slice to the used list */
if ((error = devconfig_get_name(comp, &cname)) == 0) {
error = add_used_slice_by_name(cname);
}
/* increment concat's capacity */
if ((error == 0) &&
(error = devconfig_get_size(comp, &csize)) == 0) {
capacity += csize;
}
}
} else {
/* no possible slice */
break;
}
}
dlist_free_items(slices, NULL);
dlist_free_items(other_hbas, NULL);
dlist_free_items(other_disks, NULL);
if (capacity >= nbytes) {
error = assemble_concat(request, comps, concat);
if (error == 0) {
print_populate_success_msg();
} else {
/* undo any slicing done for the concat */
dlist_free_items(comps, free_devconfig_object);
}
} else if (error == 0) {
if (capacity > 0) {
dlist_free_items(comps, free_devconfig_object);
print_insufficient_capacity_msg(capacity);
} else {
print_populate_no_slices_msg();
}
}
return (error);
}
/*
* FUNCTION: populate_explicit_concat(devconfig_t *request,
* dlist_t **results)
*
* INPUT: request - pointer to a request devconfig_t
*
* OUTPUT: results - pointer to a list of volume devconfig_t results
*
* RETURNS: int - 0 on success
* !0 otherwise.
*
* PURPOSE: Processes the input concat request that specifies explicit
* slice components.
*
* The components have already been validated and reserved,
* all that is required is to create devconfig_t structs
* for each requested slice.
*
* The net size of the concat is determined by the slice
* components.
*
* The concat devconfig_t is assembled and appended to the
* results list.
*
* This function is also called from
* layout_mirror.populate_explicit_mirror()
*/
int
populate_explicit_concat(
devconfig_t *request,
dlist_t **results)
{
int error = 0;
dlist_t *comps = NULL;
dlist_t *iter = NULL;
dlist_t *item = NULL;
devconfig_t *concat = NULL;
print_layout_explicit_msg(devconfig_type_to_str(TYPE_CONCAT));
/* assemble components */
iter = devconfig_get_components(request);
for (; (iter != NULL) && (error == 0); iter = iter->next) {
devconfig_t *rqst = (devconfig_t *)iter->obj;
dm_descriptor_t rqst_slice = NULL;
char *rqst_name = NULL;
devconfig_t *comp = NULL;
/* slice components have been validated */
/* turn each into a devconfig_t */
((error = devconfig_get_name(rqst, &rqst_name)) != 0) ||
(error = slice_get_by_name(rqst_name, &rqst_slice)) ||
(error = create_devconfig_for_slice(rqst_slice, &comp));
if (error == 0) {
print_layout_explicit_added_msg(rqst_name);
item = dlist_new_item((void *)comp);
if (item == NULL) {
error = ENOMEM;
} else {
comps = dlist_append(item, comps, AT_TAIL);
}
}
}
if (error == 0) {
error = assemble_concat(request, comps, &concat);
}
if (error == 0) {
if ((item = dlist_new_item(concat)) == NULL) {
error = ENOMEM;
} else {
*results = dlist_append(item, *results, AT_TAIL);
print_populate_success_msg();
}
} else {
dlist_free_items(comps, free_devconfig);
}
return (error);
}
/*
* FUNCTION: assemble_concat(devconfig_t *request, dlist_t *comps,
* devconfig_t **concat)
*
* INPUT: request - pointer to a devconfig_t of the current request
* comps - pointer to a list of slice components
*
* OUPUT: concat - pointer to a devconfig_t to hold final concat
*
* RETURNS: int - 0 on success
* !0 otherwise.
*
* PURPOSE: Helper which creates and populates a concat devconfig_t
* struct using information from the input request and the
* list of slice components.
*
* Determines the name of the concat either from the request
* or from the default naming scheme.
*
* Attaches the input list of components to the devconfig.
*/
static int
assemble_concat(
devconfig_t *request,
dlist_t *comps,
devconfig_t **concat)
{
char *name = NULL;
int error = 0;
if ((error = new_devconfig(concat, TYPE_CONCAT)) == 0) {
/* set concat name, use requested name if specified */
if ((error = devconfig_get_name(request, &name)) != 0) {
if (error != ERR_ATTR_UNSET) {
volume_set_error(gettext("error getting requested name\n"));
} else {
error = 0;
}
}
if (error == 0) {
if (name == NULL) {
if ((error = get_next_volume_name(&name,
TYPE_CONCAT)) == 0) {
error = devconfig_set_name(*concat, name);
free(name);
}
} else {
error = devconfig_set_name(*concat, name);
}
}
}
if (error == 0) {
/* compute and save true size of concat */
if (error == 0) {
uint64_t nblks = 0;
dlist_t *iter;
for (iter = comps;
(error == 0) && (iter != NULL);
iter = iter->next) {
devconfig_t *comp = (devconfig_t *)iter->obj;
uint64_t comp_nblks = 0;
if ((error = devconfig_get_size_in_blocks(comp,
&comp_nblks)) == 0) {
nblks += comp_nblks;
}
}
if (error == 0) {
error = devconfig_set_size_in_blocks(*concat, nblks);
}
}
}
if (error == 0) {
devconfig_set_components(*concat, comps);
} else {
free_devconfig(*concat);
*concat = NULL;
}
return (error);
}
|