7712 mandoc -Tlint does always exit with error code 0
[unleashed.git] / usr / src / cmd / lvm / metassist / common / volume_defaults.c
blobcb6909f77fd2c210bcb78a425e978995d53354ef
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <string.h>
30 #include <libintl.h>
31 #include "volume_defaults.h"
32 #include "volume_error.h"
35 * Methods which manipulate a defaults_t struct
38 static int defaults_get_singleton_component(
39 defaults_t *defaults, char *disksetname,
40 component_type_t type, devconfig_t **component, boolean_t create);
43 * Constructor: Create a defaults_t struct populated with default
44 * values. This defaults_t must be freed.
46 * @param defaults
47 * RETURN: a pointer to a new defaults_t
49 * @return 0
50 * if successful
52 * @return non-zero
53 * if an error occurred. Use get_error_string() to
54 * retrieve the associated error message.
56 int
57 new_defaults(
58 defaults_t **defaults)
60 devconfig_t *diskset;
61 int error = 0;
63 *defaults = (defaults_t *)calloc(1, sizeof (defaults_t));
64 if (*defaults == NULL) {
65 volume_set_error(gettext("new_defaults calloc() failed"));
66 return (-1);
70 * Create initial "global" (disk set-independent) defaults, as
71 * a devconfig_t of type disk set with NULL name
73 if ((error = new_devconfig(&diskset, TYPE_DISKSET)) != 0) {
74 free_defaults(*defaults);
75 return (error);
78 /* Append global defaults disk set to disksets */
79 defaults_set_disksets(
80 *defaults, dlist_append(dlist_new_item(diskset),
81 defaults_get_disksets(*defaults), AT_TAIL));
83 /* Set defaults */
84 if ((error = defaults_set_mirror_nsubs(
85 *defaults, NULL, DEFAULT_MIRROR_NSUBS)) != 0 ||
87 (error = defaults_set_mirror_read(
88 *defaults, NULL, DEFAULT_MIRROR_READ)) != 0 ||
90 (error = defaults_set_mirror_write(
91 *defaults, NULL, DEFAULT_MIRROR_WRITE)) != 0 ||
93 (error = defaults_set_mirror_pass(
94 *defaults, NULL, DEFAULT_MIRROR_PASS)) != 0 ||
96 (error = defaults_set_mirror_usehsp(
97 *defaults, NULL, DEFAULT_MIRROR_USEHSP)) != 0 ||
99 (error = defaults_set_concat_usehsp(
100 *defaults, NULL, DEFAULT_CONCAT_USEHSP)) != 0 ||
102 (error = defaults_set_stripe_interlace(
103 *defaults, NULL, DEFAULT_STRIPE_INTERLACE)) != 0 ||
105 (error = defaults_set_stripe_mincomp(
106 *defaults, NULL, DEFAULT_STRIPE_MINCOMP)) != 0 ||
108 (error = defaults_set_stripe_maxcomp(
109 *defaults, NULL, DEFAULT_STRIPE_MAXCOMP)) != 0 ||
111 (error = defaults_set_stripe_usehsp(
112 *defaults, NULL, DEFAULT_STRIPE_USEHSP)) != 0 ||
114 (error = defaults_set_volume_redundancy_level(
115 *defaults, NULL, DEFAULT_VOLUME_REDUND_LEVEL)) != 0 ||
117 (error = defaults_set_volume_npaths(
118 *defaults, NULL, DEFAULT_VOLUME_NPATHS)) != 0 ||
120 (error = defaults_set_volume_usehsp(
121 *defaults, NULL, DEFAULT_VOLUME_USEHSP)) != 0) {
123 free_defaults(*defaults);
124 return (error);
127 return (0);
131 * Free memory (recursively) allocated to a defaults_t struct
133 * @param arg
134 * pointer to the defaults_t struct to free
136 void
137 free_defaults(
138 void *arg)
140 defaults_t *defaults = (defaults_t *)arg;
142 if (defaults == NULL) {
143 return;
146 /* Free the disksets */
147 if (defaults->disksets != NULL) {
148 dlist_free_items(defaults->disksets, free_devconfig);
151 /* Free the devconfig itself */
152 free(defaults);
156 * Set list of diskset specific defaults
158 * @param defaults
159 * a defaults_t hierarchy representing default settings
160 * for all disk sets and specific disk sets
162 * @param disksets
163 * a dlist_t representing the defaults for specific
164 * named disk sets
166 void
167 defaults_set_disksets(
168 defaults_t *defaults,
169 dlist_t *disksets)
171 defaults->disksets = disksets;
175 * Get list of diskset specific defaults
177 * @param defaults
178 * a defaults_t hierarchy representing default settings
179 * for all disk sets and specific disk sets
181 * @return a dlist_t representing the defaults for specific
182 * named disk sets
184 dlist_t *
185 defaults_get_disksets(
186 defaults_t *defaults)
188 return (defaults->disksets);
192 * Get a disk set with the given name from the given defaults_t
194 * @param defaults
195 * a defaults_t hierarchy representing default settings
196 * for all disk sets and specific disk sets
198 * @param name
199 * the name of the disk set whose defaults to retrieve,
200 * or NULL to get the defaults for all disk sets
202 * @param diskset
203 * RETURN: defaults for the given named disk set, or
204 * defaults for all disk sets if name is NULL
206 * @return ENOENT
207 * if the named disk set does not exist
209 * @return 0
210 * if the named disk set exists
213 defaults_get_diskset_by_name(
214 defaults_t *defaults,
215 char *name,
216 devconfig_t **diskset)
218 dlist_t *list;
219 *diskset = NULL;
221 /* Get list of disk sets */
222 list = defaults_get_disksets(defaults);
223 if (list != NULL) {
225 /* For each disk set-specific defaults... */
226 for (; list != NULL; list = list->next) {
228 char *dname = NULL;
229 devconfig_t *d = (devconfig_t *)list->obj;
231 /* Get the name if this disk set */
232 devconfig_get_name(d, &dname);
234 /* Do the names match? */
235 if (
236 /* Global defaults disk set */
237 (name == NULL && dname == NULL) ||
239 /* Named disk set */
240 (name != NULL && dname != NULL &&
241 strcmp(name, dname) == 0)) {
243 *diskset = d;
244 break;
249 /* Diskset doesn't exist */
250 if (*diskset == NULL) {
251 return (ENOENT);
254 return (0);
258 * Get the first component of the given type from the given disk set.
259 * If not found, create the component if requested.
261 * @return ENOENT
262 * if the given disk set does not exist, or it exists,
263 * but the requested component does not exist under it
264 * and its creation was not requested
266 * @return 0
267 * if the requested component exists or was created
269 * @return non-zero
270 * if the requested component does not exist and could
271 * not be created
273 static int
274 defaults_get_singleton_component(
275 defaults_t *defaults,
276 char *disksetname,
277 component_type_t type,
278 devconfig_t **component,
279 boolean_t create)
281 int error;
282 devconfig_t *diskset;
284 /* Get the disk set referred to */
285 if ((error = defaults_get_diskset_by_name(
286 defaults, disksetname, &diskset)) != 0) {
288 volume_set_error(
289 gettext("could not get defaults for disk set %s"),
290 disksetname == NULL ? gettext("<NULL>") : disksetname);
292 return (error);
296 * Get the singleton component under this disk set, create if
297 * requested
299 return (devconfig_get_component(diskset, type, component, create));
303 * Set name of the the default HSP to use
305 * @param defaults
306 * a defaults_t hierarchy representing default settings
307 * for all disk sets and specific disk sets
309 * @param diskset
310 * the name of the disk set to which to apply this
311 * default setting, or NULL to apply default
312 * setting to all disk sets
314 * @param name
315 * the name of the default HSP to use
317 * @return 0
318 * if successful
320 * @return non-zero
321 * if an error occurred. Use get_error_string() to
322 * retrieve the associated error message.
325 defaults_set_hsp_name(
326 defaults_t *defaults,
327 char *diskset,
328 char *name)
330 devconfig_t *hsp = NULL;
331 int error = 0;
333 /* Get/create singleton HSP element for this disk set */
334 if ((error = defaults_get_singleton_component(
335 defaults, diskset, TYPE_HSP, &hsp, TRUE)) != 0) {
336 /* volume_set_error already called */
337 return (error);
340 /* Set the name attribute */
341 return (devconfig_set_hsp_name(hsp, name));
345 * Get the name of the default HSP to use
347 * @param defaults
348 * a defaults_t hierarchy representing default settings
349 * for all disk sets and specific disk sets
351 * @param diskset
352 * the name of the disk set to which to apply this
353 * default setting, or NULL to apply default
354 * setting to all disk sets
356 * @param name
357 * RETURN: the name of the default HSP to use
359 * @return 0
360 * if successful
362 * @return non-zero
363 * if an error occurred. Use get_error_string() to
364 * retrieve the associated error message.
367 defaults_get_hsp_name(
368 defaults_t *defaults,
369 char *diskset,
370 char **name)
372 char *disksets[2];
373 devconfig_t *hsp;
374 int error;
375 int i = 0;
377 /* Check both the given and global (NULL) disk sets for the value */
378 disksets[0] = diskset;
379 disksets[1] = NULL;
380 do {
381 /* Get/create singleton HSP element for this disk set */
382 error = defaults_get_singleton_component(
383 defaults, disksets[i], TYPE_HSP, &hsp, FALSE);
385 switch (error) {
386 /* HSP found for this disk set */
387 case 0:
388 /* Get the nsubs attribute */
389 if ((error = devconfig_get_name(hsp, name)) == 0) {
390 /* nsubs attribute found */
391 return (0);
394 /* FALLTHROUGH */
396 /* HSP not found for this disk set */
397 case ENOENT:
398 break;
400 /* Invalid disk set, or HSP couldn't be created */
401 default:
402 /* volume_set_error already called */
403 return (error);
406 /* Stop after the global (NULL) disk set has been searched */
407 } while (disksets[i++] != NULL);
409 return (ENOENT);
413 * Set the default number of submirrors for mirrored volumes
415 * @param defaults
416 * a defaults_t hierarchy representing default settings
417 * for all disk sets and specific disk sets
419 * @param diskset
420 * the name of the disk set to which to apply this
421 * default setting, or NULL to apply default
422 * setting to all disk sets
424 * @param val
425 * the value to set as the default number of submirrors
426 * for mirrored volumes
428 * @return 0
429 * if successful
431 * @return non-zero
432 * if an error occurred. Use get_error_string() to
433 * retrieve the associated error message.
436 defaults_set_mirror_nsubs(
437 defaults_t *defaults,
438 char *diskset,
439 uint16_t val)
441 devconfig_t *mirror = NULL;
442 int error = 0;
444 /* Get/create singleton mirror element for this disk set */
445 if ((error = defaults_get_singleton_component(
446 defaults, diskset, TYPE_MIRROR, &mirror, TRUE)) != 0) {
447 /* volume_set_error already called */
448 return (error);
451 /* Set the nsubs attribute */
452 return (devconfig_set_mirror_nsubs(mirror, val));
456 * Get the default number of submirrors for mirrored volumes
458 * @param defaults
459 * a defaults_t hierarchy representing default settings
460 * for all disk sets and specific disk sets
462 * @param diskset
463 * the name of the disk set to which to apply this
464 * default setting, or NULL to apply default
465 * setting to all disk sets
467 * @param val
468 * RETURN: the default number of submirrors for mirrored
469 * volumes
471 * @return 0
472 * if successful
474 * @return non-zero
475 * if an error occurred. Use get_error_string() to
476 * retrieve the associated error message.
479 defaults_get_mirror_nsubs(
480 defaults_t *defaults,
481 char *diskset,
482 uint16_t *val)
484 char *disksets[2];
485 devconfig_t *mirror;
486 int error;
487 int i = 0;
489 /* Check both the given and global (NULL) disk sets for the value */
490 disksets[0] = diskset;
491 disksets[1] = NULL;
492 do {
493 /* Get/create singleton mirror element for this disk set */
494 error = defaults_get_singleton_component(
495 defaults, disksets[i], TYPE_MIRROR, &mirror, FALSE);
497 switch (error) {
498 /* mirror found for this disk set */
499 case 0:
500 /* Get the nsubs attribute */
501 if ((error = devconfig_get_mirror_nsubs(
502 mirror, val)) == 0) {
503 /* nsubs attribute found */
504 return (0);
507 /* FALLTHROUGH */
509 /* mirror not found for this disk set */
510 case ENOENT:
511 break;
513 /* Invalid disk set, or mirror couldn't be created */
514 default:
515 /* volume_set_error already called */
516 return (error);
519 /* Stop after the global (NULL) disk set has been searched */
520 } while (disksets[i++] != NULL);
522 return (ENOENT);
526 * Set the default read strategy for mirrored volumes
528 * @param defaults
529 * a defaults_t hierarchy representing default settings
530 * for all disk sets and specific disk sets
532 * @param diskset
533 * the name of the disk set to which to apply this
534 * default setting, or NULL to apply default
535 * setting to all disk sets
537 * @param val
538 * the value to set as the default read strategy for
539 * mirrored volumes
541 * @return 0
542 * if successful
544 * @return non-zero
545 * if an error occurred. Use get_error_string() to
546 * retrieve the associated error message.
549 defaults_set_mirror_read(
550 defaults_t *defaults,
551 char *diskset,
552 mirror_read_strategy_t val)
554 devconfig_t *mirror = NULL;
555 int error = 0;
557 /* Get/create singleton mirror element for this disk set */
558 if ((error = defaults_get_singleton_component(
559 defaults, diskset, TYPE_MIRROR, &mirror, TRUE)) != 0) {
560 /* volume_set_error already called */
561 return (error);
564 /* Set the read attribute */
565 return (devconfig_set_mirror_read(mirror, val));
569 * Get the default read strategy for mirrored volumes
571 * @param defaults
572 * a defaults_t hierarchy representing default settings
573 * for all disk sets and specific disk sets
575 * @param diskset
576 * the name of the disk set to which to apply this
577 * default setting, or NULL to apply default
578 * setting to all disk sets
580 * @param val
581 * RETURN: the default read strategy for mirrored volumes
583 * @return 0
584 * if successful
586 * @return non-zero
587 * if an error occurred. Use get_error_string() to
588 * retrieve the associated error message.
591 defaults_get_mirror_read(
592 defaults_t *defaults,
593 char *diskset,
594 mirror_read_strategy_t *val)
596 char *disksets[2];
597 devconfig_t *mirror;
598 int error;
599 int i = 0;
601 /* Check both the given and global (NULL) disk sets for the value */
602 disksets[0] = diskset;
603 disksets[1] = NULL;
604 do {
605 /* Get/create singleton mirror element for this disk set */
606 error = defaults_get_singleton_component(
607 defaults, disksets[i], TYPE_MIRROR, &mirror, FALSE);
609 switch (error) {
610 /* mirror found for this disk set */
611 case 0:
612 /* Get the read attribute */
613 if ((error = devconfig_get_mirror_read(mirror, val)) == 0) {
614 /* read attribute found */
615 return (0);
618 /* FALLTHROUGH */
620 /* mirror not found for this disk set */
621 case ENOENT:
622 break;
624 /* Invalid disk set, or mirror couldn't be created */
625 default:
626 /* volume_set_error already called */
627 return (error);
630 /* Stop after the global (NULL) disk set has been searched */
631 } while (disksets[i++] != NULL);
633 return (ENOENT);
637 * Set the default write strategy for mirrored volumes
639 * @param defaults
640 * a defaults_t hierarchy representing default settings
641 * for all disk sets and specific disk sets
643 * @param diskset
644 * the name of the disk set to which to apply this
645 * default setting, or NULL to apply default
646 * setting to all disk sets
648 * @param val
649 * the value to set as the default write strategy for
650 * mirrored volumes
652 * @return 0
653 * if successful
655 * @return non-zero
656 * if an error occurred. Use get_error_string() to
657 * retrieve the associated error message.
660 defaults_set_mirror_write(
661 defaults_t *defaults,
662 char *diskset,
663 mirror_write_strategy_t val)
665 devconfig_t *mirror = NULL;
666 int error = 0;
668 /* Get/create singleton mirror element for this disk set */
669 if ((error = defaults_get_singleton_component(
670 defaults, diskset, TYPE_MIRROR, &mirror, TRUE)) != 0) {
671 /* volume_set_error already called */
672 return (error);
675 /* Set the write attribute */
676 return (devconfig_set_mirror_write(mirror, val));
680 * Get the default write strategy for mirrored volumes
682 * @param defaults
683 * a defaults_t hierarchy representing default settings
684 * for all disk sets and specific disk sets
686 * @param diskset
687 * the name of the disk set to which to apply this
688 * default setting, or NULL to apply default
689 * setting to all disk sets
691 * @param val
692 * RETURN: the default write strategy for mirrored
693 * volumes
695 * @return 0
696 * if successful
698 * @return non-zero
699 * if an error occurred. Use get_error_string() to
700 * retrieve the associated error message.
703 defaults_get_mirror_write(
704 defaults_t *defaults,
705 char *diskset,
706 mirror_write_strategy_t *val)
708 char *disksets[2];
709 devconfig_t *mirror;
710 int error;
711 int i = 0;
713 /* Check both the given and global (NULL) disk sets for the value */
714 disksets[0] = diskset;
715 disksets[1] = NULL;
716 do {
717 /* Get/create singleton mirror element for this disk set */
718 error = defaults_get_singleton_component(
719 defaults, disksets[i], TYPE_MIRROR, &mirror, FALSE);
721 switch (error) {
722 /* mirror found for this disk set */
723 case 0:
724 /* Get the write attribute */
725 if ((error = devconfig_get_mirror_write(
726 mirror, val)) == 0) {
727 /* write attribute found */
728 return (0);
731 /* FALLTHROUGH */
733 /* mirror not found for this disk set */
734 case ENOENT:
735 break;
737 /* Invalid disk set, or mirror couldn't be created */
738 default:
739 /* volume_set_error already called */
740 return (error);
743 /* Stop after the global (NULL) disk set has been searched */
744 } while (disksets[i++] != NULL);
746 return (ENOENT);
750 * Set the default resync pass for mirrored volumes
752 * @param defaults
753 * a defaults_t hierarchy representing default settings
754 * for all disk sets and specific disk sets
756 * @param diskset
757 * the name of the disk set to which to apply this
758 * default setting, or NULL to apply default
759 * setting to all disk sets
761 * @param val
762 * the value to set as the default resync pass for
763 * mirrored volumes
765 * @return 0
766 * if successful
768 * @return non-zero
769 * if an error occurred. Use get_error_string() to
770 * retrieve the associated error message.
773 defaults_set_mirror_pass(
774 defaults_t *defaults,
775 char *diskset,
776 uint16_t val)
778 devconfig_t *mirror = NULL;
779 int error = 0;
781 /* Get/create singleton mirror element for this disk set */
782 if ((error = defaults_get_singleton_component(
783 defaults, diskset, TYPE_MIRROR, &mirror, TRUE)) != 0) {
784 /* volume_set_error already called */
785 return (error);
788 /* Set the pass attribute */
789 return (devconfig_set_mirror_pass(mirror, val));
793 * Get the default resync pass for mirrored volumes
795 * @param defaults
796 * a defaults_t hierarchy representing default settings
797 * for all disk sets and specific disk sets
799 * @param diskset
800 * the name of the disk set to which to apply this
801 * default setting, or NULL to apply default
802 * setting to all disk sets
804 * @param val
805 * RETURN: the default resync pass for mirrored volumes
807 * @return 0
808 * if successful
810 * @return non-zero
811 * if an error occurred. Use get_error_string() to
812 * retrieve the associated error message.
815 defaults_get_mirror_pass(
816 defaults_t *defaults,
817 char *diskset,
818 uint16_t *val)
820 char *disksets[2];
821 devconfig_t *mirror;
822 int error;
823 int i = 0;
825 /* Check both the given and global (NULL) disk sets for the value */
826 disksets[0] = diskset;
827 disksets[1] = NULL;
828 do {
829 /* Get/create singleton mirror element for this disk set */
830 error = defaults_get_singleton_component(
831 defaults, disksets[i], TYPE_MIRROR, &mirror, FALSE);
833 switch (error) {
834 /* mirror found for this disk set */
835 case 0:
836 /* Get the pass attribute */
837 if ((error = devconfig_get_mirror_pass(mirror, val)) == 0) {
838 /* pass attribute found */
839 return (0);
842 /* FALLTHROUGH */
844 /* mirror not found for this disk set */
845 case ENOENT:
846 break;
848 /* Invalid disk set, or mirror couldn't be created */
849 default:
850 /* volume_set_error already called */
851 return (error);
854 /* Stop after the global (NULL) disk set has been searched */
855 } while (disksets[i++] != NULL);
857 return (ENOENT);
861 * Set the default HSP creation flag for mirrored volumes
863 * @param defaults
864 * a defaults_t hierarchy representing default settings
865 * for all disk sets and specific disk sets
867 * @param diskset
868 * the name of the disk set to which to apply this
869 * default setting, or NULL to apply default
870 * setting to all disk sets
872 * @param val
873 * the value to set as the default HSP creation flag for
874 * mirrored volumes
876 * @return 0
877 * if successful
879 * @return non-zero
880 * if an error occurred. Use get_error_string() to
881 * retrieve the associated error message.
884 defaults_set_mirror_usehsp(
885 defaults_t *defaults,
886 char *diskset,
887 boolean_t val)
889 devconfig_t *mirror = NULL;
890 int error = 0;
892 /* Get/create singleton mirror element for this disk set */
893 if ((error = defaults_get_singleton_component(
894 defaults, diskset, TYPE_MIRROR, &mirror, TRUE)) != 0) {
895 /* volume_set_error already called */
896 return (error);
899 /* Set the usehsp attribute */
900 return (devconfig_set_volume_usehsp(mirror, val));
904 * Get the default HSP creation flag for mirrored volumes
906 * @param defaults
907 * a defaults_t hierarchy representing default settings
908 * for all disk sets and specific disk sets
910 * @param diskset
911 * the name of the disk set to which to apply this
912 * default setting, or NULL to apply default
913 * setting to all disk sets
915 * @param val
916 * RETURN: the default HSP creation flag for mirrored
917 * volumes
919 * @return 0
920 * if successful
922 * @return non-zero
923 * if an error occurred. Use get_error_string() to
924 * retrieve the associated error message.
927 defaults_get_mirror_usehsp(
928 defaults_t *defaults,
929 char *diskset,
930 boolean_t *val)
932 char *disksets[2];
933 devconfig_t *mirror;
934 int error;
935 int i = 0;
937 /* Check both the given and global (NULL) disk sets for the value */
938 disksets[0] = diskset;
939 disksets[1] = NULL;
940 do {
941 /* Get/create singleton mirror element for this disk set */
942 error = defaults_get_singleton_component(
943 defaults, disksets[i], TYPE_MIRROR, &mirror, FALSE);
945 switch (error) {
946 /* mirror found for this disk set */
947 case 0:
948 /* Get the usehsp attribute */
949 if ((error = devconfig_get_volume_usehsp(
950 mirror, val)) == 0) {
951 /* usehsp attribute found */
952 return (0);
955 /* FALLTHROUGH */
957 /* mirror not found for this disk set */
958 case ENOENT:
959 break;
961 /* Invalid disk set, or mirror couldn't be created */
962 default:
963 /* volume_set_error already called */
964 return (error);
967 /* Stop after the global (NULL) disk set has been searched */
968 } while (disksets[i++] != NULL);
970 return (ENOENT);
974 * Set the default HSP creation flag for concatenated volumes
976 * @param defaults
977 * a defaults_t hierarchy representing default settings
978 * for all disk sets and specific disk sets
980 * @param diskset
981 * the name of the disk set to which to apply this
982 * default setting, or NULL to apply default
983 * setting to all disk sets
985 * @param val
986 * the value to set as the default HSP creation flag for
987 * concatenated volumes
989 * @return 0
990 * if successful
992 * @return non-zero
993 * if an error occurred. Use get_error_string() to
994 * retrieve the associated error message.
997 defaults_set_concat_usehsp(
998 defaults_t *defaults,
999 char *diskset,
1000 boolean_t val)
1002 devconfig_t *concat = NULL;
1003 int error = 0;
1005 /* Get/create singleton concat element for this disk set */
1006 if ((error = defaults_get_singleton_component(
1007 defaults, diskset, TYPE_CONCAT, &concat, TRUE)) != 0) {
1008 /* volume_set_error already called */
1009 return (error);
1012 /* Set the usehsp attribute */
1013 return (devconfig_set_volume_usehsp(concat, val));
1017 * Get the default HSP creation flag for concatenated volumes
1019 * @param defaults
1020 * a defaults_t hierarchy representing default settings
1021 * for all disk sets and specific disk sets
1023 * @param diskset
1024 * the name of the disk set to which to apply this
1025 * default setting, or NULL to apply default
1026 * setting to all disk sets
1028 * @param val
1029 * RETURN: the default HSP creation flag for concatenated
1030 * volumes
1032 * @return 0
1033 * if successful
1035 * @return non-zero
1036 * if an error occurred. Use get_error_string() to
1037 * retrieve the associated error message.
1040 defaults_get_concat_usehsp(
1041 defaults_t *defaults,
1042 char *diskset,
1043 boolean_t *val)
1045 char *disksets[2];
1046 devconfig_t *concat;
1047 int error;
1048 int i = 0;
1050 /* Check both the given and global (NULL) disk sets for the value */
1051 disksets[0] = diskset;
1052 disksets[1] = NULL;
1053 do {
1054 /* Get/create singleton concat element for this disk set */
1055 error = defaults_get_singleton_component(
1056 defaults, disksets[i], TYPE_CONCAT, &concat, FALSE);
1058 switch (error) {
1059 /* concat found for this disk set */
1060 case 0:
1061 /* Get the usehsp attribute */
1062 if ((error = devconfig_get_volume_usehsp(
1063 concat, val)) == 0) {
1064 /* usehsp attribute found */
1065 return (0);
1068 /* FALLTHROUGH */
1070 /* concat not found for this disk set */
1071 case ENOENT:
1072 break;
1074 /* Invalid disk set, or concat couldn't be created */
1075 default:
1076 /* volume_set_error already called */
1077 return (error);
1080 /* Stop after the global (NULL) disk set has been searched */
1081 } while (disksets[i++] != NULL);
1083 return (ENOENT);
1087 * Set the default minimum number of components for striped volumes
1089 * @param defaults
1090 * a defaults_t hierarchy representing default settings
1091 * for all disk sets and specific disk sets
1093 * @param diskset
1094 * the name of the disk set to which to apply this
1095 * default setting, or NULL to apply default
1096 * setting to all disk sets
1098 * @param val
1099 * the value to set as the default minimum number of
1100 * components for striped volumes
1102 * @return 0
1103 * if successful
1105 * @return non-zero
1106 * if an error occurred. Use get_error_string() to
1107 * retrieve the associated error message.
1110 defaults_set_stripe_mincomp(
1111 defaults_t *defaults,
1112 char *diskset,
1113 uint16_t val)
1115 devconfig_t *stripe = NULL;
1116 int error = 0;
1118 /* Get/create singleton stripe element for this disk set */
1119 if ((error = defaults_get_singleton_component(
1120 defaults, diskset, TYPE_STRIPE, &stripe, TRUE)) != 0) {
1121 /* volume_set_error already called */
1122 return (error);
1125 /* Set the mincomp attribute */
1126 return (devconfig_set_stripe_mincomp(stripe, val));
1130 * Get the default minimum number of components for striped volumes
1132 * @param defaults
1133 * a defaults_t hierarchy representing default settings
1134 * for all disk sets and specific disk sets
1136 * @param diskset
1137 * the name of the disk set to which to apply this
1138 * default setting, or NULL to apply default
1139 * setting to all disk sets
1141 * @param val
1142 * RETURN: the default minimum number of components for
1143 * striped volumes
1145 * @return 0
1146 * if successful
1148 * @return non-zero
1149 * if an error occurred. Use get_error_string() to
1150 * retrieve the associated error message.
1153 defaults_get_stripe_mincomp(
1154 defaults_t *defaults,
1155 char *diskset,
1156 uint16_t *val)
1158 char *disksets[2];
1159 devconfig_t *stripe;
1160 int error;
1161 int i = 0;
1163 /* Check both the given and global (NULL) disk sets for the value */
1164 disksets[0] = diskset;
1165 disksets[1] = NULL;
1166 do {
1167 /* Get/create singleton stripe element for this disk set */
1168 error = defaults_get_singleton_component(
1169 defaults, disksets[i], TYPE_STRIPE, &stripe, FALSE);
1171 switch (error) {
1172 /* stripe found for this disk set */
1173 case 0:
1174 /* Get the mincomp attribute */
1175 if ((error = devconfig_get_stripe_mincomp(
1176 stripe, val)) == 0) {
1177 /* mincomp attribute found */
1178 return (0);
1181 /* FALLTHROUGH */
1183 /* stripe not found for this disk set */
1184 case ENOENT:
1185 break;
1187 /* Invalid disk set, or stripe couldn't be created */
1188 default:
1189 /* volume_set_error already called */
1190 return (error);
1193 /* Stop after the global (NULL) disk set has been searched */
1194 } while (disksets[i++] != NULL);
1196 return (ENOENT);
1200 * Set the default maximum number of components for striped volumes
1202 * @param defaults
1203 * a defaults_t hierarchy representing default settings
1204 * for all disk sets and specific disk sets
1206 * @param diskset
1207 * the name of the disk set to which to apply this
1208 * default setting, or NULL to apply default
1209 * setting to all disk sets
1211 * @param val
1212 * the value to set as the default maximum number of
1213 * components for striped volumes
1215 * @return 0
1216 * if successful
1218 * @return non-zero
1219 * if an error occurred. Use get_error_string() to
1220 * retrieve the associated error message.
1223 defaults_set_stripe_maxcomp(
1224 defaults_t *defaults,
1225 char *diskset,
1226 uint16_t val)
1228 devconfig_t *stripe = NULL;
1229 int error = 0;
1231 /* Get/create singleton stripe element for this disk set */
1232 if ((error = defaults_get_singleton_component(
1233 defaults, diskset, TYPE_STRIPE, &stripe, TRUE)) != 0) {
1234 /* volume_set_error already called */
1235 return (error);
1238 /* Set the maxcomp attribute */
1239 return (devconfig_set_stripe_maxcomp(stripe, val));
1243 * Get the default maximum number of components for striped volumes
1245 * @param defaults
1246 * a defaults_t hierarchy representing default settings
1247 * for all disk sets and specific disk sets
1249 * @param diskset
1250 * the name of the disk set to which to apply this
1251 * default setting, or NULL to apply default
1252 * setting to all disk sets
1254 * @param val
1255 * RETURN: the default maximum number of components for
1256 * striped volumes
1258 * @return 0
1259 * if successful
1261 * @return non-zero
1262 * if an error occurred. Use get_error_string() to
1263 * retrieve the associated error message.
1266 defaults_get_stripe_maxcomp(
1267 defaults_t *defaults,
1268 char *diskset,
1269 uint16_t *val)
1271 char *disksets[2];
1272 devconfig_t *stripe;
1273 int error;
1274 int i = 0;
1276 /* Check both the given and global (NULL) disk sets for the value */
1277 disksets[0] = diskset;
1278 disksets[1] = NULL;
1279 do {
1280 /* Get/create singleton stripe element for this disk set */
1281 error = defaults_get_singleton_component(
1282 defaults, disksets[i], TYPE_STRIPE, &stripe, FALSE);
1284 switch (error) {
1285 /* stripe found for this disk set */
1286 case 0:
1287 /* Get the maxcomp attribute */
1288 if ((error = devconfig_get_stripe_maxcomp(
1289 stripe, val)) == 0) {
1290 /* maxcomp attribute found */
1291 return (0);
1294 /* FALLTHROUGH */
1296 /* stripe not found for this disk set */
1297 case ENOENT:
1298 break;
1300 /* Invalid disk set, or stripe couldn't be created */
1301 default:
1302 /* volume_set_error already called */
1303 return (error);
1306 /* Stop after the global (NULL) disk set has been searched */
1307 } while (disksets[i++] != NULL);
1309 return (ENOENT);
1313 * Set the default interlace for striped volumes
1315 * @param defaults
1316 * a defaults_t hierarchy representing default settings
1317 * for all disk sets and specific disk sets
1319 * @param diskset
1320 * the name of the disk set to which to apply this
1321 * default setting, or NULL to apply default
1322 * setting to all disk sets
1324 * @param val
1325 * the value to set as the default interlace for striped
1326 * volumes
1328 * @return 0
1329 * if successful
1331 * @return non-zero
1332 * if an error occurred. Use get_error_string() to
1333 * retrieve the associated error message.
1336 defaults_set_stripe_interlace(
1337 defaults_t *defaults,
1338 char *diskset,
1339 uint64_t val)
1341 devconfig_t *stripe = NULL;
1342 int error = 0;
1344 /* Get/create singleton stripe element for this disk set */
1345 if ((error = defaults_get_singleton_component(
1346 defaults, diskset, TYPE_STRIPE, &stripe, TRUE)) != 0) {
1347 /* volume_set_error already called */
1348 return (error);
1351 /* Set the interlace attribute */
1352 return (devconfig_set_stripe_interlace(stripe, val));
1356 * Get the default interlace for striped volumes
1358 * @param defaults
1359 * a defaults_t hierarchy representing default settings
1360 * for all disk sets and specific disk sets
1362 * @param diskset
1363 * the name of the disk set to which to apply this
1364 * default setting, or NULL to apply default
1365 * setting to all disk sets
1367 * @param val
1368 * RETURN: the default interlace for striped volumes
1370 * @return 0
1371 * if successful
1373 * @return non-zero
1374 * if an error occurred. Use get_error_string() to
1375 * retrieve the associated error message.
1378 defaults_get_stripe_interlace(
1379 defaults_t *defaults,
1380 char *diskset,
1381 uint64_t *val)
1383 char *disksets[2];
1384 devconfig_t *stripe;
1385 int error;
1386 int i = 0;
1388 /* Check both the given and global (NULL) disk sets for the value */
1389 disksets[0] = diskset;
1390 disksets[1] = NULL;
1391 do {
1392 /* Get/create singleton stripe element for this disk set */
1393 error = defaults_get_singleton_component(
1394 defaults, disksets[i], TYPE_STRIPE, &stripe, FALSE);
1396 switch (error) {
1397 /* stripe found for this disk set */
1398 case 0:
1399 /* Get the interlace attribute */
1400 if ((error = devconfig_get_stripe_interlace(
1401 stripe, val)) == 0) {
1402 /* interlace attribute found */
1403 return (0);
1406 /* FALLTHROUGH */
1408 /* stripe not found for this disk set */
1409 case ENOENT:
1410 break;
1412 /* Invalid disk set, or stripe couldn't be created */
1413 default:
1414 /* volume_set_error already called */
1415 return (error);
1418 /* Stop after the global (NULL) disk set has been searched */
1419 } while (disksets[i++] != NULL);
1421 return (ENOENT);
1425 * Set the default HSP creation flag for striped volumes
1427 * @param defaults
1428 * a defaults_t hierarchy representing default settings
1429 * for all disk sets and specific disk sets
1431 * @param diskset
1432 * the name of the disk set to which to apply this
1433 * default setting, or NULL to apply default
1434 * setting to all disk sets
1436 * @param val
1437 * the value to set as the default HSP creation flag for
1438 * striped volumes
1440 * @return 0
1441 * if successful
1443 * @return non-zero
1444 * if an error occurred. Use get_error_string() to
1445 * retrieve the associated error message.
1448 defaults_set_stripe_usehsp(
1449 defaults_t *defaults,
1450 char *diskset,
1451 boolean_t val)
1453 devconfig_t *stripe = NULL;
1454 int error = 0;
1456 /* Get/create singleton stripe element for this disk set */
1457 if ((error = defaults_get_singleton_component(
1458 defaults, diskset, TYPE_STRIPE, &stripe, TRUE)) != 0) {
1459 /* volume_set_error already called */
1460 return (error);
1463 /* Set the usehsp attribute */
1464 return (devconfig_set_volume_usehsp(stripe, val));
1468 * Get the default HSP creation flag for striped volumes
1470 * @param defaults
1471 * a defaults_t hierarchy representing default settings
1472 * for all disk sets and specific disk sets
1474 * @param diskset
1475 * the name of the disk set to which to apply this
1476 * default setting, or NULL to apply default
1477 * setting to all disk sets
1479 * @param val
1480 * RETURN: the default HSP creation flag for striped
1481 * volumes
1483 * @return 0
1484 * if successful
1486 * @return non-zero
1487 * if an error occurred. Use get_error_string() to
1488 * retrieve the associated error message.
1491 defaults_get_stripe_usehsp(
1492 defaults_t *defaults,
1493 char *diskset,
1494 boolean_t *val)
1496 char *disksets[2];
1497 devconfig_t *stripe;
1498 int error;
1499 int i = 0;
1501 /* Check both the given and global (NULL) disk sets for the value */
1502 disksets[0] = diskset;
1503 disksets[1] = NULL;
1504 do {
1505 /* Get/create singleton stripe element for this disk set */
1506 error = defaults_get_singleton_component(
1507 defaults, disksets[i], TYPE_STRIPE, &stripe, FALSE);
1509 switch (error) {
1510 /* stripe found for this disk set */
1511 case 0:
1512 /* Get the usehsp attribute */
1513 if ((error = devconfig_get_volume_usehsp(
1514 stripe, val)) == 0) {
1515 /* usehsp attribute found */
1516 return (0);
1519 /* FALLTHROUGH */
1521 /* stripe not found for this disk set */
1522 case ENOENT:
1523 break;
1525 /* Invalid disk set, or stripe couldn't be created */
1526 default:
1527 /* volume_set_error already called */
1528 return (error);
1531 /* Stop after the global (NULL) disk set has been searched */
1532 } while (disksets[i++] != NULL);
1534 return (ENOENT);
1538 * Set the default redundancy level for generic volumes.
1540 * @param defaults
1541 * a defaults_t hierarchy representing default settings
1542 * for all disk sets and specific disk sets
1544 * @param diskset
1545 * the name of the disk set to which to apply this
1546 * default setting, or NULL to apply default
1547 * setting to all disk sets
1549 * @param val
1550 * If 0, a stripe will be created by default. If > 0, a
1551 * mirror with this number of submirrors will be created
1552 * by default.
1554 * @return 0
1555 * if successful
1557 * @return non-zero
1558 * if an error occurred. Use get_error_string() to
1559 * retrieve the associated error message.
1562 defaults_set_volume_redundancy_level(
1563 defaults_t *defaults,
1564 char *diskset,
1565 uint16_t val)
1567 devconfig_t *volume = NULL;
1568 int error = 0;
1570 /* Get/create singleton volume element for this disk set */
1571 if ((error = defaults_get_singleton_component(
1572 defaults, diskset, TYPE_VOLUME, &volume, TRUE)) != 0) {
1573 /* volume_set_error already called */
1574 return (error);
1577 /* Set the redundancy level */
1578 return (devconfig_set_volume_redundancy_level(volume, val));
1582 * Get the default redundancy level for generic volumes.
1584 * @param defaults
1585 * a defaults_t hierarchy representing default settings
1586 * for all disk sets and specific disk sets
1588 * @param diskset
1589 * the name of the disk set to which to apply this
1590 * default setting, or NULL to apply default
1591 * setting to all disk sets
1593 * @param val
1594 * RETURN: the default redundancy level for generic
1595 * volumes
1597 * @return 0
1598 * if successful
1600 * @return non-zero
1601 * if an error occurred. Use get_error_string() to
1602 * retrieve the associated error message.
1605 defaults_get_volume_redundancy_level(
1606 defaults_t *defaults,
1607 char *diskset,
1608 uint16_t *val)
1610 char *disksets[2];
1611 devconfig_t *volume;
1612 int error;
1613 int i = 0;
1615 /* Check both the given and global (NULL) disk sets for the value */
1616 disksets[0] = diskset;
1617 disksets[1] = NULL;
1618 do {
1619 /* Get/create singleton volume element for this disk set */
1620 error = defaults_get_singleton_component(
1621 defaults, disksets[i], TYPE_VOLUME, &volume, FALSE);
1623 switch (error) {
1624 /* volume found for this disk set */
1625 case 0:
1626 /* Get the redundancy level */
1627 if ((error = devconfig_get_volume_redundancy_level(
1628 volume, val)) == 0) {
1629 /* redundancy level found */
1630 return (0);
1633 /* FALLTHROUGH */
1635 /* volume not found for this disk set */
1636 case ENOENT:
1637 break;
1639 /* Invalid disk set, or volume couldn't be created */
1640 default:
1641 /* volume_set_error already called */
1642 return (error);
1645 /* Stop after the global (NULL) disk set has been searched */
1646 } while (disksets[i++] != NULL);
1648 return (ENOENT);
1652 * Set the default number of data paths for generic volume
1654 * @param defaults
1655 * a defaults_t hierarchy representing default settings
1656 * for all disk sets and specific disk sets
1658 * @param diskset
1659 * the name of the disk set to which to apply this
1660 * default setting, or NULL to apply default
1661 * setting to all disk sets
1663 * @param val
1664 * the value to set as the default number of data paths
1665 * for generic volume
1667 * @return 0
1668 * if successful
1670 * @return non-zero
1671 * if an error occurred. Use get_error_string() to
1672 * retrieve the associated error message.
1675 defaults_set_volume_npaths(
1676 defaults_t *defaults,
1677 char *diskset,
1678 uint16_t val)
1680 devconfig_t *volume = NULL;
1681 int error = 0;
1683 /* Get/create singleton volume element for this disk set */
1684 if ((error = defaults_get_singleton_component(
1685 defaults, diskset, TYPE_VOLUME, &volume, TRUE)) != 0) {
1686 /* volume_set_error already called */
1687 return (error);
1690 /* Set the npaths attribute */
1691 return (devconfig_set_volume_npaths(volume, val));
1695 * Get the default number of data paths for generic volume
1697 * @param defaults
1698 * a defaults_t hierarchy representing default settings
1699 * for all disk sets and specific disk sets
1701 * @param diskset
1702 * the name of the disk set to which to apply this
1703 * default setting, or NULL to apply default
1704 * setting to all disk sets
1706 * @param val
1707 * RETURN: the default number of data paths for generic
1708 * volume
1710 * @return 0
1711 * if successful
1713 * @return non-zero
1714 * if an error occurred. Use get_error_string() to
1715 * retrieve the associated error message.
1718 defaults_get_volume_npaths(
1719 defaults_t *defaults,
1720 char *diskset,
1721 uint16_t *val)
1723 char *disksets[2];
1724 devconfig_t *volume;
1725 int error;
1726 int i = 0;
1728 /* Check both the given and global (NULL) disk sets for the value */
1729 disksets[0] = diskset;
1730 disksets[1] = NULL;
1731 do {
1732 /* Get/create singleton volume element for this disk set */
1733 error = defaults_get_singleton_component(
1734 defaults, disksets[i], TYPE_VOLUME, &volume, FALSE);
1736 switch (error) {
1737 /* volume found for this disk set */
1738 case 0:
1739 /* Get the npaths attribute */
1740 if ((error = devconfig_get_volume_npaths(
1741 volume, val)) == 0) {
1742 /* npaths attribute found */
1743 return (0);
1746 /* FALLTHROUGH */
1748 /* volume not found for this disk set */
1749 case ENOENT:
1750 break;
1752 /* Invalid disk set, or volume couldn't be created */
1753 default:
1754 /* volume_set_error already called */
1755 return (error);
1758 /* Stop after the global (NULL) disk set has been searched */
1759 } while (disksets[i++] != NULL);
1761 return (ENOENT);
1765 * Set the default HSP creation flag for generic volume
1767 * @param defaults
1768 * a defaults_t hierarchy representing default settings
1769 * for all disk sets and specific disk sets
1771 * @param diskset
1772 * the name of the disk set to which to apply this
1773 * default setting, or NULL to apply default
1774 * setting to all disk sets
1776 * @param val
1777 * the value to set as the default HSP creation flag for
1778 * generic volume
1780 * @return 0
1781 * if successful
1783 * @return non-zero
1784 * if an error occurred. Use get_error_string() to
1785 * retrieve the associated error message.
1788 defaults_set_volume_usehsp(
1789 defaults_t *defaults,
1790 char *diskset,
1791 boolean_t val)
1793 devconfig_t *volume = NULL;
1794 int error = 0;
1796 /* Get/create singleton volume element for this disk set */
1797 if ((error = defaults_get_singleton_component(
1798 defaults, diskset, TYPE_VOLUME, &volume, TRUE)) != 0) {
1799 /* volume_set_error already called */
1800 return (error);
1803 /* Set the usehsp attribute */
1804 return (devconfig_set_volume_usehsp(volume, val));
1808 * Get the default HSP creation flag for generic volume
1810 * @param defaults
1811 * a defaults_t hierarchy representing default settings
1812 * for all disk sets and specific disk sets
1814 * @param diskset
1815 * the name of the disk set to which to apply this
1816 * default setting, or NULL to apply default
1817 * setting to all disk sets
1819 * @param val
1820 * RETURN: the default HSP creation flag for generic
1821 * volume
1823 * @return 0
1824 * if successful
1826 * @return non-zero
1827 * if an error occurred. Use get_error_string() to
1828 * retrieve the associated error message.
1831 defaults_get_volume_usehsp(
1832 defaults_t *defaults,
1833 char *diskset,
1834 boolean_t *val)
1836 char *disksets[2];
1837 devconfig_t *volume;
1838 int error;
1839 int i = 0;
1841 /* Check both the given and global (NULL) disk sets for the value */
1842 disksets[0] = diskset;
1843 disksets[1] = NULL;
1844 do {
1845 /* Get/create singleton volume element for this disk set */
1846 error = defaults_get_singleton_component(
1847 defaults, disksets[i], TYPE_VOLUME, &volume, FALSE);
1849 switch (error) {
1850 /* volume found for this disk set */
1851 case 0:
1852 /* Get the usehsp attribute */
1853 if ((error = devconfig_get_volume_usehsp(
1854 volume, val)) == 0) {
1855 /* usehsp attribute found */
1856 return (0);
1859 /* FALLTHROUGH */
1861 /* volume not found for this disk set */
1862 case ENOENT:
1863 break;
1865 /* Invalid disk set, or volume couldn't be created */
1866 default:
1867 /* volume_set_error already called */
1868 return (error);
1871 /* Stop after the global (NULL) disk set has been searched */
1872 } while (disksets[i++] != NULL);
1874 return (ENOENT);