summaryrefslogtreecommitdiff
path: root/usr/src/cmd/lvm/metassist/common/volume_devconfig.c
blob: 1146b894664889c21b6cc3d57c1276b2db3f2c8e (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
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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
/*
 * 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 "volume_devconfig.h"

#include <string.h>
#include <ctype.h>
#include <meta.h>
#include "volume_nvpair.h"
#include "volume_error.h"
#include "volume_output.h"
#include "volume_string.h"

/*
 * Methods which manipulate a devconfig_t struct
 */

/*
 * Constructor: Create a devconfig_t struct.  This devconfig_t must be
 * freed with free_devconfig().
 *
 * @param       devconfig
 *              RETURN: a new devconfig_t
 *
 * @param       type
 *              the type of devconfig_t to create
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
new_devconfig(
	devconfig_t **devconfig,
	component_type_t type)
{
	int error;

	*devconfig = (devconfig_t *)calloc(1, sizeof (devconfig_t));
	if (*devconfig == NULL) {
	    volume_set_error(gettext("new_devconfig() calloc() failed\n"));
	    return (-1);
	}

	/* Create attribute list */
	if ((error = nvlist_alloc(&((*devconfig)->attributes),
	    NV_UNIQUE_NAME_TYPE, 0)) != 0) {
	    volume_set_error(gettext("devconfig_t nvlist_alloc() failed\n"));
	    free_devconfig(*devconfig);
	    return (error);
	}

	if ((error = devconfig_set_type(*devconfig, type)) != 0) {
	    free_devconfig(*devconfig);
	    return (error);
	}

	return (0);
}

/*
 * Free memory (recursively) allocated to a devconfig_t struct
 *
 * @param       arg
 *              pointer to the devconfig_t to be freed
 */
void
free_devconfig(
	void *arg)
{
	devconfig_t *devconfig = (devconfig_t *)arg;

	if (devconfig == NULL) {
	    return;
	}

	/* Free the attributes nvlist */
	if (devconfig->attributes != NULL) {
	    nvlist_free(devconfig->attributes);
	}

	/* Free available devices */
	if (devconfig->available != NULL) {
	    free_string_array(devconfig->available);
	}

	/* Free unavailable devices */
	if (devconfig->unavailable != NULL) {
	    free_string_array(devconfig->unavailable);
	}

	/* Free the components */
	if (devconfig->components != NULL) {
	    dlist_free_items(devconfig->components, free_devconfig);
	}

	/* Free the devconfig itself */
	free(devconfig);
}

/*
 * Check the type of the given device.
 *
 * @param       device
 *              the device whose type to check
 *
 * @param       type
 *              the type of the device against which to compare
 *
 * @return      B_TRUE if the device is of the given type, B_FALSE
 *              otherwise
 */
boolean_t
devconfig_isA(
	devconfig_t *device,
	component_type_t type)
{
	component_type_t curtype;

	if (device == NULL) {
	    return (B_FALSE);
	}

	if (devconfig_get_type(device, &curtype) != 0) {
	    return (B_FALSE);
	}

	if (curtype != type) {
	    return (B_FALSE);
	}

	return (B_TRUE);
}

/*
 * Get the first component of the given type from the given
 * devconfig_t.  Create the component if create is B_TRUE.
 *
 * @return      ENOENT
 *              if the requested component does not exist and its
 *              creation was not requested
 *
 * @return      0
 *              if the requested component exists or was created
 *
 * @return      non-zero
 *              if the requested component did not exist and could not
 *              be created
 */
int
devconfig_get_component(
	devconfig_t *device,
	component_type_t type,
	devconfig_t **component,
	boolean_t create)
{
	dlist_t *list;
	int error = 0;
	char *typestr = devconfig_type_to_str(type);

	oprintf(OUTPUT_DEBUG, gettext("Searching for singleton %s\n"), typestr);

	/* For each component of this device... */
	for (list = devconfig_get_components(device);
	    list != NULL; list = list->next) {

	    *component = (devconfig_t *)list->obj;

	    /* Is this subcomponent an instance of the given type? */
	    if (*component != NULL && devconfig_isA(*component, type)) {
		oprintf(OUTPUT_DEBUG, gettext("Found %s\n"), typestr);
		return (0);
	    }
	}

	/* No component found */
	error = ENOENT;
	*component = NULL;

	oprintf(OUTPUT_DEBUG, gettext("%s not found\n"), typestr);

	if (create == B_TRUE) {
	    oprintf(OUTPUT_DEBUG, gettext("Creating %s\n"), typestr);

		/*
		 * An existing singleton component of the given type was
		 * not found under the given disk set.  So, create one.
		 */
	    if ((error = new_devconfig(component, type)) == 0) {
		/* Attach new component to given device */
		devconfig_set_components(
		    device, dlist_append(dlist_new_item(*component),
		    devconfig_get_components(device), AT_TAIL));
	    }
	}

	return (error);
}

/*
 * Set the available devices for use in creating this device
 *
 * @param       device
 *              a devconfig_t representing the device to modify
 *
 * @param       available
 *              A NULL-terminated array of device names
 */
void
devconfig_set_available(
	devconfig_t *device,
	char **available)
{
	device->available = available;
}

/*
 * Get the available devices for use in creating this device
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @return      available
 *              A NULL-terminated array of device names
 */
char **
devconfig_get_available(
	devconfig_t *device)
{
	return (device->available);
}

/*
 * Set the unavailable devices which may not be used in creating this
 * device
 *
 * @param       device
 *              a devconfig_t representing the device to modify
 *
 * @param       available
 *              A NULL-terminated array of device names
 */
void
devconfig_set_unavailable(
	devconfig_t *device,
	char **unavailable)
{
	device->unavailable = unavailable;
}

/*
 * Get the unavailable devices for use in creating this device
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @return      unavailable
 *              A NULL-terminated array of device names
 */
char **
devconfig_get_unavailable(
	devconfig_t *device)
{
	return (device->unavailable);
}

/*
 * Set the subcomponent devices of a given device
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       components
 *              A dlist_t containing devconfig_t devices
 */
void
devconfig_set_components(
	devconfig_t *device,
	dlist_t *components)
{
	device->components = components;
}

/*
 * Get the subcomponent devices of a given device
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @return      A dlist_t containing devconfig_t devices
 */
dlist_t *
devconfig_get_components(
	devconfig_t *device)
{
	return (device->components);
}

/*
 * Set the device name
 *
 * @param       device
 *              a devconfig_t representing the device to modify
 *
 * @param       name
 *              the value to set as the device name
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_name(
	devconfig_t *device,
	char *name)
{
	return (set_string(device->attributes, ATTR_NAME, name));
}

/*
 * Set the disk set name
 *
 * @param       diskset
 *              a devconfig_t representing the diskset to modify
 *
 * @param       name
 *              the value to set as the device name
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_diskset_name(
	devconfig_t *diskset,
	char *name)
{
	md_error_t error = mdnullerror;

	/* Verify syntax of disk set name */
	if (meta_set_checkname(name, &error)) {
	    volume_set_error(gettext("invalid disk set name: %s"), name);
	    return (-1);
	}

	return (devconfig_set_name(diskset, name));
}

/*
 * Set the device name
 *
 * @param       hsp
 *              a devconfig_t representing the hsp to modify
 *
 * @param       name
 *              the value to set as the device name
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_hsp_name(
	devconfig_t *hsp,
	char *name)
{
	/* Validate name */
	if (!is_hspname(name)) {
	    volume_set_error(gettext("invalid hot spare pool name: %s"), name);
	    return (-1);
	}

	return (devconfig_set_name(hsp, name));
}

/*
 * Set the device name
 *
 * @param       volume
 *              a devconfig_t representing the volume to modify
 *
 * @param       name
 *              the value to set as the device name
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_volume_name(
	devconfig_t *volume,
	char *name)
{
	/* Validate name */
	if (!is_metaname(name)) {
	    volume_set_error(gettext("invalid volume name: %s"), name);
	    return (-1);
	}

	return (devconfig_set_name(volume, name));
}

/*
 * Get the device name
 *
 * @param       volume
 *              a devconfig_t representing the volume to examine
 *
 * @param       name
 *              RETURN: the device name
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_name(
	devconfig_t *device,
	char **name)
{
	int error = get_string(device->attributes, ATTR_NAME, name);

	/* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	if (error == ENOENT) {
	    volume_set_error(gettext("device name not set"));
	    error = ERR_ATTR_UNSET;
	}

	return (error);
}

/*
 * Set the device type
 *
 * @param       device
 *              a devconfig_t representing the device to modify
 *
 * @param       type
 *              the value to set as the device type
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_type(
	devconfig_t *device,
	component_type_t type)
{
	return (set_uint16(device->attributes, ATTR_TYPE, (uint16_t)type));
}

/*
 * Get the device type
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       type
 *              RETURN: the device type
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_type(
	devconfig_t *device,
	component_type_t *type)
{
	uint16_t val;
	int error = get_uint16(device->attributes, ATTR_TYPE, &val);

	switch (error) {
	    /* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	    case ENOENT:
		volume_set_error(gettext("device type not set"));
		error = ERR_ATTR_UNSET;
	    break;

	    /* Success */
	    case 0:
		*type = (component_type_t)val;
	}

	return (error);
}

/*
 * Set the device size (for volume, mirror, stripe, concat) in bytes
 *
 * Note that size in bytes in a 64-bit field cannot hold the size that
 * can be accessed in a 16 byte CDB.  Since CDBs operate on blocks,
 * the max capacity is 2^73 bytes with 512 byte blocks.
 *
 * @param       device
 *              a devconfig_t representing the device to modify
 *
 * @param       size_in_bytes
 *              the value to set as the device size in bytes
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_size(
	devconfig_t *device,
	uint64_t size_in_bytes)
{

	/* Validate against limits */
	/* LINTED -- MIN_SIZE may be 0 */
	if (size_in_bytes < MIN_SIZE) {
	    volume_set_error(gettext("size (in bytes) too small: %llu"),
		(unsigned long long)size_in_bytes);
	    return (-1);
	}

	return (set_uint64(device->attributes,
	    ATTR_SIZEINBYTES, size_in_bytes));
}

/*
 * Get the device size (for volume, mirror, stripe, concat) in bytes
 *
 * Note that size in bytes in a 64-bit field cannot hold the size that
 * can be accessed in a 16 byte CDB.  Since CDBs operate on blocks,
 * the max capacity is 2^73 bytes with 512 byte blocks.
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       size_in_bytes
 *              RETURN: the device size in bytes
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_size(
	devconfig_t *device,
	uint64_t *size_in_bytes)
{
	int error = get_uint64(
	    device->attributes, ATTR_SIZEINBYTES, size_in_bytes);

	/* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	if (error == ENOENT) {
	    volume_set_error(gettext("size (in bytes) not set"));
	    error = ERR_ATTR_UNSET;
	}

	return (error);
}

/*
 * Set the device size in blocks
 *
 * @param       device
 *              a devconfig_t representing the device to modify
 *
 * @param       type
 *              the value to set as the device size in blocks
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_size_in_blocks(
	devconfig_t *device,
	uint64_t size_in_blocks)
{
	/* Validate against limits */
	/* LINTED -- MIN_SIZE_IN_BLOCKS may be 0 */
	if (size_in_blocks < MIN_SIZE_IN_BLOCKS) {
	    volume_set_error(gettext("size (in blocks) too small: %llu"),
		(unsigned long long)size_in_blocks);
	    return (-1);
	}

	return (set_uint64(device->attributes,
	    ATTR_SIZEINBLOCKS, size_in_blocks));
}

/*
 * Get the device size in blocks
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       size_in_blocks
 *              RETURN: the device size in blocks
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_size_in_blocks(
	devconfig_t *device,
	uint64_t *size_in_blocks)
{
	int error = get_uint64(
	    device->attributes, ATTR_SIZEINBLOCKS, size_in_blocks);

	/* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	if (error == ENOENT) {
	    volume_set_error(gettext("size (in blocks) not set"));
	    error = ERR_ATTR_UNSET;
	}

	return (error);
}

/*
 * Set the the slice index
 *
 * @param       slice
 *              a devconfig_t representing the slice to modify
 *
 * @param       index
 *              the value to set as the the slice index
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_slice_index(
	devconfig_t *slice,
	uint16_t index)
{
	return (set_uint16(slice->attributes, ATTR_SLICE_INDEX, index));
}

/*
 * Get the slice index
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       index
 *              RETURN: the slice index
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_slice_index(
	devconfig_t *slice,
	uint16_t *index)
{
	int error = get_uint16(slice->attributes, ATTR_SLICE_INDEX, index);

	/* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	if (error == ENOENT) {
	    volume_set_error(gettext("slice index not set"));
	    error = ERR_ATTR_UNSET;
	}

	return (error);
}

/*
 * Set the the slice start block
 *
 * @param       slice
 *              a devconfig_t representing the slice to modify
 *
 * @param       start_block
 *              the value to set as the the slice start block
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_slice_start_block(
	devconfig_t *slice,
	uint64_t start_block)
{
	return (set_uint64(slice->attributes,
	    ATTR_SLICE_STARTSECTOR, start_block));
}

/*
 * Get the slice start block
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       start_block
 *              RETURN: the slice start block
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_slice_start_block(
	devconfig_t *slice,
	uint64_t *start_block)
{
	int error = get_uint64(
	    slice->attributes, ATTR_SLICE_STARTSECTOR, start_block);

	/* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	if (error == ENOENT) {
	    volume_set_error(gettext("slice start block not set"));
	    error = ERR_ATTR_UNSET;
	}

	return (error);
}

/*
 * Set the number of subcomponents in mirror
 *
 * @param       mirror
 *              a devconfig_t representing the mirror to modify
 *
 * @param       nsubs
 *              the value to set as the number of subcomponents in
 *              mirror
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_mirror_nsubs(
	devconfig_t *mirror,
	uint16_t nsubs)
{
	/* Validate against limits */
	if (nsubs < 1 || nsubs > NMIRROR) {
	    volume_set_error(
		gettext("number of submirrors (%d) out of valid range (%d-%d)"),
		nsubs, 1, NMIRROR);
	    return (-1);
	}

	return (set_uint16(mirror->attributes, ATTR_MIRROR_NSUBMIRRORS, nsubs));
}

/*
 * Get number of subcomponents in mirror
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       nsubs
 *              RETURN: number of subcomponents in mirror
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_mirror_nsubs(
	devconfig_t *mirror,
	uint16_t *nsubs)
{
	int error = get_uint16(
	    mirror->attributes, ATTR_MIRROR_NSUBMIRRORS, nsubs);

	/* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	if (error == ENOENT) {
	    volume_set_error(gettext("number or submirrors not set"));
	    error = ERR_ATTR_UNSET;
	}

	return (error);
}

/*
 * Set the read strategy for mirror
 *
 * @param       mirror
 *              a devconfig_t representing the mirror to modify
 *
 * @param       read
 *              the value to set as the read strategy for mirror
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_mirror_read(
	devconfig_t *mirror,
	mirror_read_strategy_t read)
{
	return (set_uint16(mirror->attributes,
	    ATTR_MIRROR_READ, (uint16_t)read));
}

/*
 * Get read strategy for mirror
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       read
 *              RETURN: read strategy for mirror
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_mirror_read(
	devconfig_t *mirror,
	mirror_read_strategy_t *read)
{
	uint16_t val;
	int error = get_uint16(mirror->attributes, ATTR_MIRROR_READ, &val);

	switch (error) {
	    /* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	    case ENOENT:
		volume_set_error(gettext("mirror read strategy not set"));
		error = ERR_ATTR_UNSET;
	    break;

	    /* Success */
	    case 0:
		*read = (mirror_read_strategy_t)val;
	}

	return (error);
}

/*
 * Set the write strategy for mirror
 *
 * @param       mirror
 *              a devconfig_t representing the mirror to modify
 *
 * @param       write
 *              the value to set as the write strategy for mirror
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_mirror_write(
	devconfig_t *mirror,
	mirror_write_strategy_t write)
{
	return (set_uint16(mirror->attributes,
	    ATTR_MIRROR_WRITE, (uint16_t)write));
}

/*
 * Get write strategy for mirror
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       write
 *              RETURN: write strategy for mirror
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_mirror_write(
	devconfig_t *mirror,
	mirror_write_strategy_t *write)
{
	uint16_t val;
	int error = get_uint16(mirror->attributes, ATTR_MIRROR_WRITE, &val);

	switch (error) {
	    /* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	    case ENOENT:
		volume_set_error(gettext("mirror write strategy not set"));
		error = ERR_ATTR_UNSET;
	    break;

	    /* Success */
	    case 0:
		*write = (mirror_write_strategy_t)val;
	}

	return (error);
}

/*
 * Set the resync pass for mirror
 *
 * @param       mirror
 *              a devconfig_t representing the mirror to modify
 *
 * @param       pass
 *              the value to set as the resync pass for mirror
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_mirror_pass(
	devconfig_t *mirror,
	uint16_t pass)
{
	/* Validate against max value */
	if (pass > MD_PASS_MAX) {
	    volume_set_error(
		gettext("mirror pass number (%d) out of valid range (0-%d)"),
		pass, MD_PASS_MAX);
	    return (-1);
	}

	return (set_uint16(mirror->attributes, ATTR_MIRROR_PASSNUM, pass));
}

/*
 * Get resync pass for mirror
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       pass
 *              RETURN: resync pass for mirror
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_mirror_pass(
	devconfig_t *mirror,
	uint16_t *pass)
{
	int error = get_uint16(mirror->attributes, ATTR_MIRROR_PASSNUM, pass);

	/* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	if (error == ENOENT) {
	    volume_set_error(gettext("mirror pass number not set"));
	    error = ERR_ATTR_UNSET;
	}

	return (error);
}

/*
 * Set the minimum number of components in stripe
 *
 * @param       stripe
 *              a devconfig_t representing the stripe to modify
 *
 * @param       mincomp
 *              the value to set as the minimum number of components
 *              in stripe
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_stripe_mincomp(
	devconfig_t *stripe,
	uint16_t mincomp)
{
	/* Validate against minimum value */
	if (mincomp < MIN_NSTRIPE_COMP) {
	    volume_set_error(gettext(
		"minimum stripe components (%d) below minimum allowable (%d)"),
		mincomp, MIN_NSTRIPE_COMP);
	    return (-1);
	}

	return (set_uint16(stripe->attributes, ATTR_STRIPE_MINCOMP, mincomp));
}

/*
 * Get minimum number of components in stripe
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       mincomp
 *              RETURN: minimum number of components in stripe
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_stripe_mincomp(
	devconfig_t *stripe,
	uint16_t *mincomp)
{
	int error = get_uint16(
	    stripe->attributes, ATTR_STRIPE_MINCOMP, mincomp);

	/* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	if (error == ENOENT) {
	    volume_set_error(
		gettext("minimum number of stripe components not set"));
	    error = ERR_ATTR_UNSET;
	}

	return (error);
}

/*
 * Set the maximum number of components in stripe
 *
 * @param       stripe
 *              a devconfig_t representing the stripe to modify
 *
 * @param       maxcomp
 *              the value to set as the maximum number of components
 *              in stripe
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_stripe_maxcomp(
	devconfig_t *stripe,
	uint16_t maxcomp)
{
	/* Validate against minimum value */
	if (maxcomp < MIN_NSTRIPE_COMP) {
	    volume_set_error(gettext(
		"maximum stripe components (%d) below minimum allowable (%d)"),
		maxcomp, MIN_NSTRIPE_COMP);
	    return (-1);
	}

	return (set_uint16(stripe->attributes, ATTR_STRIPE_MAXCOMP, maxcomp));
}

/*
 * Get maximum number of components in stripe
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       maxcomp
 *              RETURN: maximum number of components in stripe
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_stripe_maxcomp(
	devconfig_t *stripe,
	uint16_t *maxcomp)
{
	int error = get_uint16(
	    stripe->attributes, ATTR_STRIPE_MAXCOMP, maxcomp);

	/* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	if (error == ENOENT) {
	    volume_set_error(
		gettext("maximum number of stripe components not set"));
	    error = ERR_ATTR_UNSET;
	}

	return (error);
}

/*
 * Set the stripe interlace
 *
 * @param       stripe
 *              a devconfig_t representing the stripe to modify
 *
 * @param       interlace
 *              the value to set as the stripe interlace
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_stripe_interlace(
	devconfig_t *stripe,
	uint64_t interlace)
{
	if (interlace < MININTERLACE || interlace > MAXINTERLACE) {
	    char *intstr = NULL;
	    char *minstr = NULL;
	    char *maxstr = NULL;

	    /* Get string representations of interlaces */
	    bytes_to_sizestr(interlace, &intstr, universal_units, B_FALSE);
	    bytes_to_sizestr(MININTERLACE, &minstr, universal_units, B_FALSE);
	    bytes_to_sizestr(MAXINTERLACE, &maxstr, universal_units, B_FALSE);

	    volume_set_error(
		gettext("interlace (%s) out of valid range (%s - %s)"),
		intstr, minstr, maxstr);

	    free(intstr);
	    free(minstr);
	    free(maxstr);

	    return (-1);
	}

	return (set_uint64(stripe->attributes,
	    ATTR_STRIPE_INTERLACE, interlace));
}

/*
 * Get stripe interlace
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       interlace
 *              RETURN: stripe interlace
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_stripe_interlace(
	devconfig_t *stripe,
	uint64_t *interlace)
{
	int error = get_uint64(
	    stripe->attributes, ATTR_STRIPE_INTERLACE, interlace);

	/* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	if (error == ENOENT) {
	    volume_set_error(gettext("stripe interlace not set"));
	    error = ERR_ATTR_UNSET;
	}

	return (error);
}

/*
 * Set the redundancy level for a volume.
 *
 * @param       volume
 *              a devconfig_t representing the volume to modify
 *
 * @param       rlevel
 *              If 0, a stripe will be created.  If > 0, a mirror with
 *              this number of submirrors will be created.
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_volume_redundancy_level(
	devconfig_t *volume,
	uint16_t rlevel)
{
	/* Validate against limits */
	if (rlevel > NMIRROR) {
	    volume_set_error(gettext(
		"volume redundancy level (%d) out of valid range (%d-%d)"),
		rlevel, 0, NMIRROR);
	    return (-1);
	}

	return (set_uint16(volume->attributes, ATTR_VOLUME_REDUNDANCY, rlevel));
}

/*
 * Get the redundancy level for a volume.
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       rlevel
 *              RETURN: the redundancy level for a volume
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_volume_redundancy_level(
	devconfig_t *volume,
	uint16_t *rlevel)
{
	int error = get_uint16(
	    volume->attributes, ATTR_VOLUME_REDUNDANCY, rlevel);

	/* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	if (error == ENOENT) {
	    volume_set_error(gettext("volume redundancy level not set"));
	    error = ERR_ATTR_UNSET;
	}

	return (error);
}

/*
 * Set the number of paths in volume
 *
 * @param       volume
 *              a devconfig_t representing the volume to modify
 *
 * @param       npaths
 *              the value to set as the number of paths in volume
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_volume_npaths(
	devconfig_t *volume,
	uint16_t npaths)
{
	/* Validate against limits */
	if (npaths < MIN_NDATAPATHS || npaths > MAX_NDATAPATHS) {
	    volume_set_error(
		gettext("number of data paths (%d) out of valid range (%d-%d)"),
		npaths, MIN_NDATAPATHS, MAX_NDATAPATHS);
	    return (-1);
	}

	return (set_uint16(volume->attributes, ATTR_VOLUME_DATAPATHS, npaths));
}

/*
 * Get number of paths in volume
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       npaths
 *              RETURN: number of paths in volume
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_volume_npaths(
	devconfig_t *volume,
	uint16_t *npaths)
{
	int error = get_uint16(
	    volume->attributes, ATTR_VOLUME_DATAPATHS, npaths);

	/* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	if (error == ENOENT) {
	    volume_set_error(gettext("number of data paths not set"));
	    error = ERR_ATTR_UNSET;
	}

	return (error);
}

/*
 * Set the HSP creation option (for volume, stripe, concat, mirror)
 *
 * @param       volume
 *              a devconfig_t representing the volume to modify
 *
 * @param       usehsp
 *              the value to set as the HSP creation option
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_set_volume_usehsp(
	devconfig_t *volume,
	boolean_t usehsp)
{
	return (set_boolean(volume->attributes, ATTR_VOLUME_USEHSP, usehsp));
}

/*
 * Get HSP creation option (for volume, stripe, concat, mirror)
 *
 * @param       device
 *              a devconfig_t representing the device to examine
 *
 * @param       usehsp
 *              RETURN: HSP creation option (for volume, stripe,
 *              concat, mirror)
 *
 * @return      0
 *              if successful
 *
 * @return      non-zero
 *              if an error occurred.  Use get_error_string() to
 *              retrieve the associated error message.
 */
int
devconfig_get_volume_usehsp(
	devconfig_t *volume,
	boolean_t *usehsp)
{
	int error = get_boolean(
	    volume->attributes, ATTR_VOLUME_USEHSP, usehsp);

	/* Convert ENOENT to ERR_ATTR_UNSET for a custom error message */
	if (error == ENOENT) {
	    volume_set_error(gettext("volume usehsp not set"));
	    error = ERR_ATTR_UNSET;
	}

	return (error);
}

/*
 * Get the string representation of the volume's type
 *
 * @param       type
 *              a valid component_type_t
 *
 * @return      an internationalized string representing the given
 *              type
 */
char *
devconfig_type_to_str(
	component_type_t type)
{
	char *str;

	switch (type) {
	    case TYPE_CONCAT:	    str = gettext("Concat");	    break;
	    case TYPE_CONTROLLER:   str = gettext("Controller");    break;
	    case TYPE_DISKSET:	    str = gettext("Diskset");	    break;
	    case TYPE_DRIVE:	    str = gettext("Disk");	    break;
	    case TYPE_EXTENT:	    str = gettext("Extent");	    break;
	    case TYPE_HOST:	    str = gettext("Host");	    break;
	    case TYPE_HSP:	    str = gettext("Hot Spare Pool"); break;
	    case TYPE_MIRROR:	    str = gettext("Mirror");	    break;
	    case TYPE_RAID5:	    str = gettext("Raid5");	    break;
	    case TYPE_SLICE:	    str = gettext("Slice");	    break;
	    case TYPE_SOFTPART:	    str = gettext("Soft Partition"); break;
	    case TYPE_STRIPE:	    str = gettext("Stripe");	    break;
	    case TYPE_TRANS:	    str = gettext("Trans");	    break;
	    case TYPE_VOLUME:	    str = gettext("Volume");	    break;
	    default:
	    case TYPE_UNKNOWN:	    str = gettext("Unknown");	    break;
	}

	return (str);
}

/*
 * Get the string representation of the mirror's read strategy
 *
 * @param       read
 *              a valid mirror_read_strategy_t
 *
 * @return      an internationalized string representing the given
 *              read strategy
 */
char *
devconfig_read_strategy_to_str(
	mirror_read_strategy_t read)
{
	char *str;

	switch (read) {
	    case MIRROR_READ_ROUNDROBIN: str = gettext("ROUNDROBIN");	break;
	    case MIRROR_READ_GEOMETRIC:	 str = gettext("GEOMETRIC");	break;
	    case MIRROR_READ_FIRST:	 str = gettext("FIRST");	break;
	    default:			 str = "";
	}

	return (str);
}

/*
 * Get the string representation of the mirror's write strategy
 *
 * @param       write
 *              a valid mirror_write_strategy_t
 *
 * @return      an internationalized string representing the given
 *              write strategy
 */
char *
devconfig_write_strategy_to_str(
	mirror_write_strategy_t write)
{
	char *str;

	switch (write) {
	    case MIRROR_WRITE_PARALLEL:	str = gettext("PARALLEL");	break;
	    case MIRROR_WRITE_SERIAL:	str = gettext("SERIAL");	break;
	    default:			str = "";
	}

	return (str);
}

#ifdef DEBUG
/*
 * Dump the contents of a devconfig_t struct to stdout.
 *
 * @param       device
 *              the devconfig_t to examine
 *
 * @param       prefix
 *              a prefix string to print before each line
 */
void
devconfig_dump(
	devconfig_t *device,
	char *prefix)
{
	dlist_t *comps = NULL;
	char **array = NULL;
	char *str = NULL;
	int i = 0;

	component_type_t type = TYPE_UNKNOWN;
	boolean_t bool = B_FALSE;
	uint16_t val16 = 0;
	uint64_t val64 = 0;
	mirror_read_strategy_t read;
	mirror_write_strategy_t write;

	if (device == NULL) {
	    return;
	}

	/* Type */
	if (devconfig_get_type(device, &type) == 0) {
	    printf("%s%s\n", prefix, devconfig_type_to_str(type));
	}

	/* Name */
	if (devconfig_get_name(device, &str) == 0) {
	    printf("%s  name: %s\n", prefix, str);
	}

	/* Size in bytes */
	if (devconfig_get_size(device, &val64) == 0) {
	    printf("%s  size in bytes: %llu\n", prefix, val64);
	}

	/* Size in blocks */
	if (devconfig_get_size_in_blocks(device, &val64) == 0) {
	    printf("%s  size in blocks: %llu\n", prefix, val64);
	}

	/* Use HSP */
	if (devconfig_get_volume_usehsp(device, &bool) == 0) {
	    printf("%s  usehsp: %s\n", prefix, bool? "TRUE" : "FALSE");
	}

	switch (type) {
	    case TYPE_VOLUME:
		/* Volume rlevel */
		if (devconfig_get_volume_redundancy_level(
		    device, &val16) == 0) {
		    printf("%s  volume redundancy level: %d\n", prefix, val16);
		}

		/* Volume npaths */
		if (devconfig_get_volume_npaths(device, &val16) == 0) {
		    printf("%s  volume npaths: %d\n", prefix, val16);
		}
	    break;

	    case TYPE_MIRROR:

		/* Mirror nsubs */
		if (devconfig_get_mirror_nsubs(device, &val16) == 0) {
		    printf("%s  mirror nsubs: %d\n", prefix, val16);
		}

		/* Mirror read */
		if (devconfig_get_mirror_read(device, &read) == 0) {
		    printf("%s  mirror read: %s\n", prefix,
			devconfig_read_strategy_to_str(read));
		}

		/* Mirror write */
		if (devconfig_get_mirror_write(device, &write) == 0) {
		    printf("%s  mirror write: %s\n", prefix,
			devconfig_write_strategy_to_str(write));
		}

		/* Mirror pass */
		if (devconfig_get_mirror_pass(device, &val16) == 0) {
		    printf("%s  mirror pass: %d\n", prefix, val16);
		}
	    break;

	    case TYPE_STRIPE:
		/* Stripe mincomp */
		if (devconfig_get_stripe_mincomp(device, &val16) == 0) {
		    printf("%s  stripe mincomp: %d\n", prefix, val16);
		}

		/* Stripe maxcomp */
		if (devconfig_get_stripe_maxcomp(device, &val16) == 0) {
		    printf("%s  stripe maxcomp: %d\n", prefix, val16);
		}

		/* Stripe interlace */
		if (devconfig_get_stripe_interlace(device, &val64) == 0) {
		    printf("%s  stripe interlace: %lld\n", prefix, val64);
		}
	    break;

	    case TYPE_SLICE:
		/* Slice index */
		if (devconfig_get_slice_index(device, &val16) == 0) {
		    printf("%s  slice index: %d\n", prefix, val16);
		}

		/* Slice start block */
		if (devconfig_get_slice_start_block(device, &val64) == 0) {
		    printf("%s  slice start block: %llu\n", prefix, val64);
		}
	    break;
	}

	array = devconfig_get_available(device);
	if (array != NULL) {
	    printf("%s  available:\n", prefix);
	    for (i = 0; array[i] != NULL; i++) {
		printf("%s    %s\n", prefix, array[i]);
	    }
	}

	array = devconfig_get_unavailable(device);
	if (array != NULL) {
	    printf("%s  unavailable:\n", prefix);
	    for (i = 0; array[i] != NULL; i++) {
		printf("%s    %s\n", prefix, array[i]);
	    }
	}

	printf("\n");

	comps = devconfig_get_components(device);
	if (comps != NULL) {
	    char buf[128];
	    snprintf(buf, 128, "%s%s", prefix, "    ");
	    for (; comps != NULL; comps = comps->next) {
		devconfig_dump((devconfig_t *)comps->obj, buf);
	    }
	}
}
#endif /* DEBUG */