zpool_prop.c revision 1.1.1.2 1 1.1 haad /*
2 1.1 haad * CDDL HEADER START
3 1.1 haad *
4 1.1 haad * The contents of this file are subject to the terms of the
5 1.1 haad * Common Development and Distribution License (the "License").
6 1.1 haad * You may not use this file except in compliance with the License.
7 1.1 haad *
8 1.1 haad * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 1.1 haad * or http://www.opensolaris.org/os/licensing.
10 1.1 haad * See the License for the specific language governing permissions
11 1.1 haad * and limitations under the License.
12 1.1 haad *
13 1.1 haad * When distributing Covered Code, include this CDDL HEADER in each
14 1.1 haad * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 1.1 haad * If applicable, add the following below this CDDL HEADER, with the
16 1.1 haad * fields enclosed by brackets "[]" replaced with your own identifying
17 1.1 haad * information: Portions Copyright [yyyy] [name of copyright owner]
18 1.1 haad *
19 1.1 haad * CDDL HEADER END
20 1.1 haad */
21 1.1 haad /*
22 1.1.1.2 haad * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 1.1 haad * Use is subject to license terms.
24 1.1 haad */
25 1.1 haad
26 1.1 haad #include <sys/zio.h>
27 1.1 haad #include <sys/spa.h>
28 1.1 haad #include <sys/zfs_acl.h>
29 1.1 haad #include <sys/zfs_ioctl.h>
30 1.1 haad #include <sys/fs/zfs.h>
31 1.1 haad
32 1.1 haad #include "zfs_prop.h"
33 1.1 haad
34 1.1 haad #if defined(_KERNEL)
35 1.1 haad #include <sys/systm.h>
36 1.1 haad #else
37 1.1 haad #include <stdlib.h>
38 1.1 haad #include <string.h>
39 1.1 haad #include <ctype.h>
40 1.1 haad #endif
41 1.1 haad
42 1.1 haad static zprop_desc_t zpool_prop_table[ZPOOL_NUM_PROPS];
43 1.1 haad
44 1.1 haad zprop_desc_t *
45 1.1 haad zpool_prop_get_table(void)
46 1.1 haad {
47 1.1 haad return (zpool_prop_table);
48 1.1 haad }
49 1.1 haad
50 1.1 haad void
51 1.1 haad zpool_prop_init(void)
52 1.1 haad {
53 1.1 haad static zprop_index_t boolean_table[] = {
54 1.1 haad { "off", 0},
55 1.1 haad { "on", 1},
56 1.1 haad { NULL }
57 1.1 haad };
58 1.1 haad
59 1.1 haad static zprop_index_t failuremode_table[] = {
60 1.1 haad { "wait", ZIO_FAILURE_MODE_WAIT },
61 1.1 haad { "continue", ZIO_FAILURE_MODE_CONTINUE },
62 1.1 haad { "panic", ZIO_FAILURE_MODE_PANIC },
63 1.1 haad { NULL }
64 1.1 haad };
65 1.1 haad
66 1.1 haad /* string properties */
67 1.1 haad register_string(ZPOOL_PROP_ALTROOT, "altroot", NULL, PROP_DEFAULT,
68 1.1 haad ZFS_TYPE_POOL, "<path>", "ALTROOT");
69 1.1 haad register_string(ZPOOL_PROP_BOOTFS, "bootfs", NULL, PROP_DEFAULT,
70 1.1 haad ZFS_TYPE_POOL, "<filesystem>", "BOOTFS");
71 1.1 haad register_string(ZPOOL_PROP_CACHEFILE, "cachefile", NULL, PROP_DEFAULT,
72 1.1 haad ZFS_TYPE_POOL, "<file> | none", "CACHEFILE");
73 1.1 haad
74 1.1 haad /* readonly number properties */
75 1.1 haad register_number(ZPOOL_PROP_SIZE, "size", 0, PROP_READONLY,
76 1.1 haad ZFS_TYPE_POOL, "<size>", "SIZE");
77 1.1.1.2 haad register_number(ZPOOL_PROP_FREE, "free", 0, PROP_READONLY,
78 1.1.1.2 haad ZFS_TYPE_POOL, "<size>", "FREE");
79 1.1.1.2 haad register_number(ZPOOL_PROP_ALLOCATED, "allocated", 0, PROP_READONLY,
80 1.1.1.2 haad ZFS_TYPE_POOL, "<size>", "ALLOC");
81 1.1 haad register_number(ZPOOL_PROP_CAPACITY, "capacity", 0, PROP_READONLY,
82 1.1 haad ZFS_TYPE_POOL, "<size>", "CAP");
83 1.1 haad register_number(ZPOOL_PROP_GUID, "guid", 0, PROP_READONLY,
84 1.1 haad ZFS_TYPE_POOL, "<guid>", "GUID");
85 1.1 haad register_number(ZPOOL_PROP_HEALTH, "health", 0, PROP_READONLY,
86 1.1 haad ZFS_TYPE_POOL, "<state>", "HEALTH");
87 1.1.1.2 haad register_number(ZPOOL_PROP_DEDUPRATIO, "dedupratio", 0, PROP_READONLY,
88 1.1.1.2 haad ZFS_TYPE_POOL, "<1.00x or higher if deduped>", "DEDUP");
89 1.1 haad
90 1.1 haad /* default number properties */
91 1.1 haad register_number(ZPOOL_PROP_VERSION, "version", SPA_VERSION,
92 1.1 haad PROP_DEFAULT, ZFS_TYPE_POOL, "<version>", "VERSION");
93 1.1.1.2 haad register_number(ZPOOL_PROP_DEDUPDITTO, "dedupditto", 0,
94 1.1.1.2 haad PROP_DEFAULT, ZFS_TYPE_POOL, "<threshold (min 100)>", "DEDUPDITTO");
95 1.1 haad
96 1.1 haad /* default index (boolean) properties */
97 1.1 haad register_index(ZPOOL_PROP_DELEGATION, "delegation", 1, PROP_DEFAULT,
98 1.1 haad ZFS_TYPE_POOL, "on | off", "DELEGATION", boolean_table);
99 1.1 haad register_index(ZPOOL_PROP_AUTOREPLACE, "autoreplace", 0, PROP_DEFAULT,
100 1.1 haad ZFS_TYPE_POOL, "on | off", "REPLACE", boolean_table);
101 1.1 haad register_index(ZPOOL_PROP_LISTSNAPS, "listsnapshots", 0, PROP_DEFAULT,
102 1.1 haad ZFS_TYPE_POOL, "on | off", "LISTSNAPS", boolean_table);
103 1.1.1.2 haad register_index(ZPOOL_PROP_AUTOEXPAND, "autoexpand", 0, PROP_DEFAULT,
104 1.1.1.2 haad ZFS_TYPE_POOL, "on | off", "EXPAND", boolean_table);
105 1.1 haad
106 1.1 haad /* default index properties */
107 1.1 haad register_index(ZPOOL_PROP_FAILUREMODE, "failmode",
108 1.1 haad ZIO_FAILURE_MODE_WAIT, PROP_DEFAULT, ZFS_TYPE_POOL,
109 1.1 haad "wait | continue | panic", "FAILMODE", failuremode_table);
110 1.1 haad
111 1.1 haad /* hidden properties */
112 1.1 haad register_hidden(ZPOOL_PROP_NAME, "name", PROP_TYPE_STRING,
113 1.1 haad PROP_READONLY, ZFS_TYPE_POOL, "NAME");
114 1.1 haad }
115 1.1 haad
116 1.1 haad /*
117 1.1 haad * Given a property name and its type, returns the corresponding property ID.
118 1.1 haad */
119 1.1 haad zpool_prop_t
120 1.1 haad zpool_name_to_prop(const char *propname)
121 1.1 haad {
122 1.1 haad return (zprop_name_to_prop(propname, ZFS_TYPE_POOL));
123 1.1 haad }
124 1.1 haad
125 1.1 haad /*
126 1.1 haad * Given a pool property ID, returns the corresponding name.
127 1.1 haad * Assuming the pool propety ID is valid.
128 1.1 haad */
129 1.1 haad const char *
130 1.1 haad zpool_prop_to_name(zpool_prop_t prop)
131 1.1 haad {
132 1.1 haad return (zpool_prop_table[prop].pd_name);
133 1.1 haad }
134 1.1 haad
135 1.1 haad zprop_type_t
136 1.1 haad zpool_prop_get_type(zpool_prop_t prop)
137 1.1 haad {
138 1.1 haad return (zpool_prop_table[prop].pd_proptype);
139 1.1 haad }
140 1.1 haad
141 1.1 haad boolean_t
142 1.1 haad zpool_prop_readonly(zpool_prop_t prop)
143 1.1 haad {
144 1.1 haad return (zpool_prop_table[prop].pd_attr == PROP_READONLY);
145 1.1 haad }
146 1.1 haad
147 1.1 haad const char *
148 1.1 haad zpool_prop_default_string(zpool_prop_t prop)
149 1.1 haad {
150 1.1 haad return (zpool_prop_table[prop].pd_strdefault);
151 1.1 haad }
152 1.1 haad
153 1.1 haad uint64_t
154 1.1 haad zpool_prop_default_numeric(zpool_prop_t prop)
155 1.1 haad {
156 1.1 haad return (zpool_prop_table[prop].pd_numdefault);
157 1.1 haad }
158 1.1 haad
159 1.1 haad int
160 1.1 haad zpool_prop_string_to_index(zpool_prop_t prop, const char *string,
161 1.1 haad uint64_t *index)
162 1.1 haad {
163 1.1 haad return (zprop_string_to_index(prop, string, index, ZFS_TYPE_POOL));
164 1.1 haad }
165 1.1 haad
166 1.1 haad int
167 1.1 haad zpool_prop_index_to_string(zpool_prop_t prop, uint64_t index,
168 1.1 haad const char **string)
169 1.1 haad {
170 1.1 haad return (zprop_index_to_string(prop, index, string, ZFS_TYPE_POOL));
171 1.1 haad }
172 1.1 haad
173 1.1.1.2 haad uint64_t
174 1.1.1.2 haad zpool_prop_random_value(zpool_prop_t prop, uint64_t seed)
175 1.1.1.2 haad {
176 1.1.1.2 haad return (zprop_random_value(prop, seed, ZFS_TYPE_POOL));
177 1.1.1.2 haad }
178 1.1.1.2 haad
179 1.1 haad #ifndef _KERNEL
180 1.1 haad
181 1.1 haad const char *
182 1.1 haad zpool_prop_values(zpool_prop_t prop)
183 1.1 haad {
184 1.1 haad return (zpool_prop_table[prop].pd_values);
185 1.1 haad }
186 1.1 haad
187 1.1 haad const char *
188 1.1 haad zpool_prop_column_name(zpool_prop_t prop)
189 1.1 haad {
190 1.1 haad return (zpool_prop_table[prop].pd_colname);
191 1.1 haad }
192 1.1 haad
193 1.1 haad boolean_t
194 1.1 haad zpool_prop_align_right(zpool_prop_t prop)
195 1.1 haad {
196 1.1 haad return (zpool_prop_table[prop].pd_rightalign);
197 1.1 haad }
198 1.1 haad #endif
199