]>
Commit | Line | Data |
---|---|---|
34dc7c2f BB |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
5 | * Common Development and Distribution License (the "License"). | |
6 | * You may not use this file except in compliance with the License. | |
7 | * | |
8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
1d3ba0bf | 9 | * or https://opensource.org/licenses/CDDL-1.0. |
34dc7c2f BB |
10 | * See the License for the specific language governing permissions |
11 | * and limitations under the License. | |
12 | * | |
13 | * When distributing Covered Code, include this CDDL HEADER in each | |
14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 | * If applicable, add the following below this CDDL HEADER, with the | |
16 | * fields enclosed by brackets "[]" replaced with your own identifying | |
17 | * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 | * | |
19 | * CDDL HEADER END | |
20 | */ | |
21 | /* | |
572e2857 | 22 | * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. |
d96eb2b1 | 23 | * Copyright 2011 Nexenta Systems, Inc. All rights reserved. |
a448a255 | 24 | * Copyright (c) 2012, 2018 by Delphix. All rights reserved. |
658fb802 | 25 | * Copyright (c) 2021, Colm Buckley <colm@tuatha.org> |
2a673e76 | 26 | * Copyright (c) 2021, Klara Inc. |
34dc7c2f BB |
27 | */ |
28 | ||
34dc7c2f BB |
29 | #include <sys/zio.h> |
30 | #include <sys/spa.h> | |
31 | #include <sys/zfs_acl.h> | |
32 | #include <sys/zfs_ioctl.h> | |
33 | #include <sys/fs/zfs.h> | |
34 | ||
35 | #include "zfs_prop.h" | |
36 | ||
93ce2b4c | 37 | #if !defined(_KERNEL) |
34dc7c2f BB |
38 | #include <stdlib.h> |
39 | #include <string.h> | |
40 | #include <ctype.h> | |
41 | #endif | |
42 | ||
43 | static zprop_desc_t zpool_prop_table[ZPOOL_NUM_PROPS]; | |
2a673e76 | 44 | static zprop_desc_t vdev_prop_table[VDEV_NUM_PROPS]; |
34dc7c2f BB |
45 | |
46 | zprop_desc_t * | |
47 | zpool_prop_get_table(void) | |
48 | { | |
49 | return (zpool_prop_table); | |
50 | } | |
51 | ||
52 | void | |
53 | zpool_prop_init(void) | |
54 | { | |
8fdc6f61 | 55 | static const zprop_index_t boolean_table[] = { |
34dc7c2f BB |
56 | { "off", 0}, |
57 | { "on", 1}, | |
58 | { NULL } | |
59 | }; | |
60 | ||
8fdc6f61 | 61 | static const zprop_index_t failuremode_table[] = { |
34dc7c2f BB |
62 | { "wait", ZIO_FAILURE_MODE_WAIT }, |
63 | { "continue", ZIO_FAILURE_MODE_CONTINUE }, | |
64 | { "panic", ZIO_FAILURE_MODE_PANIC }, | |
65 | { NULL } | |
66 | }; | |
67 | ||
eb51a9d7 AZ |
68 | struct zfs_mod_supported_features *sfeatures = |
69 | zfs_mod_list_supported(ZFS_SYSFS_POOL_PROPERTIES); | |
70 | ||
34dc7c2f | 71 | /* string properties */ |
428870ff | 72 | zprop_register_string(ZPOOL_PROP_ALTROOT, "altroot", NULL, PROP_DEFAULT, |
eb51a9d7 | 73 | ZFS_TYPE_POOL, "<path>", "ALTROOT", sfeatures); |
428870ff | 74 | zprop_register_string(ZPOOL_PROP_BOOTFS, "bootfs", NULL, PROP_DEFAULT, |
eb51a9d7 | 75 | ZFS_TYPE_POOL, "<filesystem>", "BOOTFS", sfeatures); |
428870ff | 76 | zprop_register_string(ZPOOL_PROP_CACHEFILE, "cachefile", NULL, |
eb51a9d7 AZ |
77 | PROP_DEFAULT, ZFS_TYPE_POOL, "<file> | none", "CACHEFILE", |
78 | sfeatures); | |
d96eb2b1 | 79 | zprop_register_string(ZPOOL_PROP_COMMENT, "comment", NULL, |
eb51a9d7 AZ |
80 | PROP_DEFAULT, ZFS_TYPE_POOL, "<comment-string>", "COMMENT", |
81 | sfeatures); | |
658fb802 CB |
82 | zprop_register_string(ZPOOL_PROP_COMPATIBILITY, "compatibility", |
83 | "off", PROP_DEFAULT, ZFS_TYPE_POOL, | |
eb51a9d7 | 84 | "<file[,file...]> | off | legacy", "COMPATIBILITY", sfeatures); |
34dc7c2f BB |
85 | |
86 | /* readonly number properties */ | |
428870ff | 87 | zprop_register_number(ZPOOL_PROP_SIZE, "size", 0, PROP_READONLY, |
be8e1d81 | 88 | ZFS_TYPE_POOL, "<size>", "SIZE", B_FALSE, sfeatures); |
428870ff | 89 | zprop_register_number(ZPOOL_PROP_FREE, "free", 0, PROP_READONLY, |
be8e1d81 | 90 | ZFS_TYPE_POOL, "<size>", "FREE", B_FALSE, sfeatures); |
9ae529ec | 91 | zprop_register_number(ZPOOL_PROP_FREEING, "freeing", 0, PROP_READONLY, |
be8e1d81 | 92 | ZFS_TYPE_POOL, "<size>", "FREEING", B_FALSE, sfeatures); |
d2734cce | 93 | zprop_register_number(ZPOOL_PROP_CHECKPOINT, "checkpoint", 0, |
be8e1d81 AZ |
94 | PROP_READONLY, ZFS_TYPE_POOL, "<size>", "CKPOINT", B_FALSE, |
95 | sfeatures); | |
fbeddd60 | 96 | zprop_register_number(ZPOOL_PROP_LEAKED, "leaked", 0, PROP_READONLY, |
be8e1d81 | 97 | ZFS_TYPE_POOL, "<size>", "LEAKED", B_FALSE, sfeatures); |
428870ff | 98 | zprop_register_number(ZPOOL_PROP_ALLOCATED, "allocated", 0, |
be8e1d81 AZ |
99 | PROP_READONLY, ZFS_TYPE_POOL, "<size>", "ALLOC", B_FALSE, |
100 | sfeatures); | |
1bd201e7 | 101 | zprop_register_number(ZPOOL_PROP_EXPANDSZ, "expandsize", 0, |
be8e1d81 AZ |
102 | PROP_READONLY, ZFS_TYPE_POOL, "<size>", "EXPANDSZ", B_FALSE, |
103 | sfeatures); | |
f3a7f661 | 104 | zprop_register_number(ZPOOL_PROP_FRAGMENTATION, "fragmentation", 0, |
be8e1d81 AZ |
105 | PROP_READONLY, ZFS_TYPE_POOL, "<percent>", "FRAG", B_FALSE, |
106 | sfeatures); | |
428870ff | 107 | zprop_register_number(ZPOOL_PROP_CAPACITY, "capacity", 0, PROP_READONLY, |
be8e1d81 | 108 | ZFS_TYPE_POOL, "<size>", "CAP", B_FALSE, sfeatures); |
428870ff | 109 | zprop_register_number(ZPOOL_PROP_GUID, "guid", 0, PROP_READONLY, |
be8e1d81 | 110 | ZFS_TYPE_POOL, "<guid>", "GUID", B_TRUE, sfeatures); |
a448a255 | 111 | zprop_register_number(ZPOOL_PROP_LOAD_GUID, "load_guid", 0, |
eb51a9d7 | 112 | PROP_READONLY, ZFS_TYPE_POOL, "<load_guid>", "LOAD_GUID", |
be8e1d81 | 113 | B_TRUE, sfeatures); |
428870ff | 114 | zprop_register_number(ZPOOL_PROP_HEALTH, "health", 0, PROP_READONLY, |
be8e1d81 | 115 | ZFS_TYPE_POOL, "<state>", "HEALTH", B_FALSE, sfeatures); |
428870ff BB |
116 | zprop_register_number(ZPOOL_PROP_DEDUPRATIO, "dedupratio", 0, |
117 | PROP_READONLY, ZFS_TYPE_POOL, "<1.00x or higher if deduped>", | |
be8e1d81 | 118 | "DEDUP", B_FALSE, sfeatures); |
67a1b037 PJD |
119 | zprop_register_number(ZPOOL_PROP_BCLONEUSED, "bcloneused", 0, |
120 | PROP_READONLY, ZFS_TYPE_POOL, "<size>", | |
121 | "BCLONE_USED", B_FALSE, sfeatures); | |
122 | zprop_register_number(ZPOOL_PROP_BCLONESAVED, "bclonesaved", 0, | |
123 | PROP_READONLY, ZFS_TYPE_POOL, "<size>", | |
124 | "BCLONE_SAVED", B_FALSE, sfeatures); | |
125 | zprop_register_number(ZPOOL_PROP_BCLONERATIO, "bcloneratio", 0, | |
126 | PROP_READONLY, ZFS_TYPE_POOL, "<1.00x or higher if cloned>", | |
127 | "BCLONE_RATIO", B_FALSE, sfeatures); | |
34dc7c2f BB |
128 | |
129 | /* default number properties */ | |
428870ff | 130 | zprop_register_number(ZPOOL_PROP_VERSION, "version", SPA_VERSION, |
be8e1d81 AZ |
131 | PROP_DEFAULT, ZFS_TYPE_POOL, "<version>", "VERSION", B_FALSE, |
132 | sfeatures); | |
dddef7d6 | 133 | zprop_register_number(ZPOOL_PROP_ASHIFT, "ashift", 0, PROP_DEFAULT, |
be8e1d81 AZ |
134 | ZFS_TYPE_POOL, "<ashift, 9-16, or 0=default>", "ASHIFT", B_FALSE, |
135 | sfeatures); | |
34dc7c2f BB |
136 | |
137 | /* default index (boolean) properties */ | |
428870ff BB |
138 | zprop_register_index(ZPOOL_PROP_DELEGATION, "delegation", 1, |
139 | PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "DELEGATION", | |
eb51a9d7 | 140 | boolean_table, sfeatures); |
428870ff | 141 | zprop_register_index(ZPOOL_PROP_AUTOREPLACE, "autoreplace", 0, |
eb51a9d7 AZ |
142 | PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "REPLACE", boolean_table, |
143 | sfeatures); | |
428870ff BB |
144 | zprop_register_index(ZPOOL_PROP_LISTSNAPS, "listsnapshots", 0, |
145 | PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "LISTSNAPS", | |
eb51a9d7 | 146 | boolean_table, sfeatures); |
428870ff | 147 | zprop_register_index(ZPOOL_PROP_AUTOEXPAND, "autoexpand", 0, |
eb51a9d7 AZ |
148 | PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "EXPAND", boolean_table, |
149 | sfeatures); | |
572e2857 | 150 | zprop_register_index(ZPOOL_PROP_READONLY, "readonly", 0, |
eb51a9d7 AZ |
151 | PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "RDONLY", boolean_table, |
152 | sfeatures); | |
379ca9cf OF |
153 | zprop_register_index(ZPOOL_PROP_MULTIHOST, "multihost", 0, |
154 | PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "MULTIHOST", | |
eb51a9d7 | 155 | boolean_table, sfeatures); |
34dc7c2f BB |
156 | |
157 | /* default index properties */ | |
428870ff | 158 | zprop_register_index(ZPOOL_PROP_FAILUREMODE, "failmode", |
34dc7c2f | 159 | ZIO_FAILURE_MODE_WAIT, PROP_DEFAULT, ZFS_TYPE_POOL, |
eb51a9d7 AZ |
160 | "wait | continue | panic", "FAILMODE", failuremode_table, |
161 | sfeatures); | |
1b939560 | 162 | zprop_register_index(ZPOOL_PROP_AUTOTRIM, "autotrim", |
8beabfd3 | 163 | SPA_AUTOTRIM_OFF, PROP_DEFAULT, ZFS_TYPE_POOL, |
eb51a9d7 | 164 | "on | off", "AUTOTRIM", boolean_table, sfeatures); |
34dc7c2f BB |
165 | |
166 | /* hidden properties */ | |
428870ff | 167 | zprop_register_hidden(ZPOOL_PROP_NAME, "name", PROP_TYPE_STRING, |
be8e1d81 | 168 | PROP_READONLY, ZFS_TYPE_POOL, "NAME", B_TRUE, sfeatures); |
f1512ee6 | 169 | zprop_register_hidden(ZPOOL_PROP_MAXBLOCKSIZE, "maxblocksize", |
eb51a9d7 | 170 | PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_POOL, "MAXBLOCKSIZE", |
be8e1d81 | 171 | B_FALSE, sfeatures); |
83e9986f | 172 | zprop_register_hidden(ZPOOL_PROP_TNAME, "tname", PROP_TYPE_STRING, |
be8e1d81 | 173 | PROP_ONETIME, ZFS_TYPE_POOL, "TNAME", B_TRUE, sfeatures); |
50c957f7 | 174 | zprop_register_hidden(ZPOOL_PROP_MAXDNODESIZE, "maxdnodesize", |
eb51a9d7 | 175 | PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_POOL, "MAXDNODESIZE", |
be8e1d81 | 176 | B_FALSE, sfeatures); |
050d720c | 177 | zprop_register_hidden(ZPOOL_PROP_DEDUPDITTO, "dedupditto", |
eb51a9d7 | 178 | PROP_TYPE_NUMBER, PROP_DEFAULT, ZFS_TYPE_POOL, "DEDUPDITTO", |
be8e1d81 | 179 | B_FALSE, sfeatures); |
eb51a9d7 AZ |
180 | |
181 | zfs_mod_list_supported_free(sfeatures); | |
34dc7c2f BB |
182 | } |
183 | ||
184 | /* | |
185 | * Given a property name and its type, returns the corresponding property ID. | |
186 | */ | |
187 | zpool_prop_t | |
188 | zpool_name_to_prop(const char *propname) | |
189 | { | |
190 | return (zprop_name_to_prop(propname, ZFS_TYPE_POOL)); | |
191 | } | |
192 | ||
193 | /* | |
194 | * Given a pool property ID, returns the corresponding name. | |
9f5c1bc6 | 195 | * Assuming the pool property ID is valid. |
34dc7c2f BB |
196 | */ |
197 | const char * | |
198 | zpool_prop_to_name(zpool_prop_t prop) | |
199 | { | |
200 | return (zpool_prop_table[prop].pd_name); | |
201 | } | |
202 | ||
203 | zprop_type_t | |
204 | zpool_prop_get_type(zpool_prop_t prop) | |
205 | { | |
206 | return (zpool_prop_table[prop].pd_proptype); | |
207 | } | |
208 | ||
209 | boolean_t | |
210 | zpool_prop_readonly(zpool_prop_t prop) | |
211 | { | |
212 | return (zpool_prop_table[prop].pd_attr == PROP_READONLY); | |
213 | } | |
214 | ||
edf60b86 CC |
215 | boolean_t |
216 | zpool_prop_setonce(zpool_prop_t prop) | |
217 | { | |
218 | return (zpool_prop_table[prop].pd_attr == PROP_ONETIME); | |
219 | } | |
220 | ||
34dc7c2f BB |
221 | const char * |
222 | zpool_prop_default_string(zpool_prop_t prop) | |
223 | { | |
224 | return (zpool_prop_table[prop].pd_strdefault); | |
225 | } | |
226 | ||
227 | uint64_t | |
228 | zpool_prop_default_numeric(zpool_prop_t prop) | |
229 | { | |
230 | return (zpool_prop_table[prop].pd_numdefault); | |
231 | } | |
232 | ||
9ae529ec CS |
233 | /* |
234 | * Returns true if this is a valid feature@ property. | |
235 | */ | |
236 | boolean_t | |
237 | zpool_prop_feature(const char *name) | |
238 | { | |
239 | static const char *prefix = "feature@"; | |
240 | return (strncmp(name, prefix, strlen(prefix)) == 0); | |
241 | } | |
242 | ||
243 | /* | |
244 | * Returns true if this is a valid unsupported@ property. | |
245 | */ | |
246 | boolean_t | |
247 | zpool_prop_unsupported(const char *name) | |
248 | { | |
249 | static const char *prefix = "unsupported@"; | |
250 | return (strncmp(name, prefix, strlen(prefix)) == 0); | |
251 | } | |
252 | ||
34dc7c2f BB |
253 | int |
254 | zpool_prop_string_to_index(zpool_prop_t prop, const char *string, | |
255 | uint64_t *index) | |
256 | { | |
257 | return (zprop_string_to_index(prop, string, index, ZFS_TYPE_POOL)); | |
258 | } | |
259 | ||
260 | int | |
261 | zpool_prop_index_to_string(zpool_prop_t prop, uint64_t index, | |
262 | const char **string) | |
263 | { | |
264 | return (zprop_index_to_string(prop, index, string, ZFS_TYPE_POOL)); | |
265 | } | |
266 | ||
428870ff BB |
267 | uint64_t |
268 | zpool_prop_random_value(zpool_prop_t prop, uint64_t seed) | |
269 | { | |
270 | return (zprop_random_value(prop, seed, ZFS_TYPE_POOL)); | |
271 | } | |
272 | ||
34dc7c2f | 273 | #ifndef _KERNEL |
60356b1a | 274 | #include <libzfs.h> |
34dc7c2f BB |
275 | |
276 | const char * | |
277 | zpool_prop_values(zpool_prop_t prop) | |
278 | { | |
279 | return (zpool_prop_table[prop].pd_values); | |
280 | } | |
281 | ||
282 | const char * | |
283 | zpool_prop_column_name(zpool_prop_t prop) | |
284 | { | |
285 | return (zpool_prop_table[prop].pd_colname); | |
286 | } | |
287 | ||
288 | boolean_t | |
289 | zpool_prop_align_right(zpool_prop_t prop) | |
290 | { | |
291 | return (zpool_prop_table[prop].pd_rightalign); | |
292 | } | |
293 | #endif | |
c28b2279 | 294 | |
2a673e76 AJ |
295 | zprop_desc_t * |
296 | vdev_prop_get_table(void) | |
297 | { | |
298 | return (vdev_prop_table); | |
299 | } | |
300 | ||
301 | void | |
302 | vdev_prop_init(void) | |
303 | { | |
8fdc6f61 | 304 | static const zprop_index_t boolean_table[] = { |
2a673e76 AJ |
305 | { "off", 0}, |
306 | { "on", 1}, | |
307 | { NULL } | |
308 | }; | |
8fdc6f61 | 309 | static const zprop_index_t boolean_na_table[] = { |
2a673e76 AJ |
310 | { "off", 0}, |
311 | { "on", 1}, | |
312 | { "-", 2}, /* ZPROP_BOOLEAN_NA */ | |
313 | { NULL } | |
314 | }; | |
315 | ||
eb51a9d7 AZ |
316 | struct zfs_mod_supported_features *sfeatures = |
317 | zfs_mod_list_supported(ZFS_SYSFS_VDEV_PROPERTIES); | |
318 | ||
2a673e76 AJ |
319 | /* string properties */ |
320 | zprop_register_string(VDEV_PROP_COMMENT, "comment", NULL, | |
eb51a9d7 AZ |
321 | PROP_DEFAULT, ZFS_TYPE_VDEV, "<comment-string>", "COMMENT", |
322 | sfeatures); | |
2a673e76 | 323 | zprop_register_string(VDEV_PROP_PATH, "path", NULL, |
eb51a9d7 | 324 | PROP_DEFAULT, ZFS_TYPE_VDEV, "<device-path>", "PATH", sfeatures); |
2a673e76 | 325 | zprop_register_string(VDEV_PROP_DEVID, "devid", NULL, |
eb51a9d7 | 326 | PROP_READONLY, ZFS_TYPE_VDEV, "<devid>", "DEVID", sfeatures); |
2a673e76 | 327 | zprop_register_string(VDEV_PROP_PHYS_PATH, "physpath", NULL, |
eb51a9d7 | 328 | PROP_READONLY, ZFS_TYPE_VDEV, "<physpath>", "PHYSPATH", sfeatures); |
2a673e76 | 329 | zprop_register_string(VDEV_PROP_ENC_PATH, "encpath", NULL, |
eb51a9d7 | 330 | PROP_READONLY, ZFS_TYPE_VDEV, "<encpath>", "ENCPATH", sfeatures); |
2a673e76 | 331 | zprop_register_string(VDEV_PROP_FRU, "fru", NULL, |
eb51a9d7 | 332 | PROP_READONLY, ZFS_TYPE_VDEV, "<fru>", "FRU", sfeatures); |
2a673e76 | 333 | zprop_register_string(VDEV_PROP_PARENT, "parent", NULL, |
eb51a9d7 | 334 | PROP_READONLY, ZFS_TYPE_VDEV, "<parent>", "PARENT", sfeatures); |
2a673e76 | 335 | zprop_register_string(VDEV_PROP_CHILDREN, "children", NULL, |
eb51a9d7 AZ |
336 | PROP_READONLY, ZFS_TYPE_VDEV, "<child[,...]>", "CHILDREN", |
337 | sfeatures); | |
2a673e76 AJ |
338 | |
339 | /* readonly number properties */ | |
340 | zprop_register_number(VDEV_PROP_SIZE, "size", 0, PROP_READONLY, | |
be8e1d81 | 341 | ZFS_TYPE_VDEV, "<size>", "SIZE", B_FALSE, sfeatures); |
2a673e76 | 342 | zprop_register_number(VDEV_PROP_FREE, "free", 0, PROP_READONLY, |
be8e1d81 | 343 | ZFS_TYPE_VDEV, "<size>", "FREE", B_FALSE, sfeatures); |
2a673e76 | 344 | zprop_register_number(VDEV_PROP_ALLOCATED, "allocated", 0, |
be8e1d81 AZ |
345 | PROP_READONLY, ZFS_TYPE_VDEV, "<size>", "ALLOC", B_FALSE, |
346 | sfeatures); | |
2a673e76 | 347 | zprop_register_number(VDEV_PROP_EXPANDSZ, "expandsize", 0, |
be8e1d81 AZ |
348 | PROP_READONLY, ZFS_TYPE_VDEV, "<size>", "EXPANDSZ", B_FALSE, |
349 | sfeatures); | |
2a673e76 | 350 | zprop_register_number(VDEV_PROP_FRAGMENTATION, "fragmentation", 0, |
be8e1d81 AZ |
351 | PROP_READONLY, ZFS_TYPE_VDEV, "<percent>", "FRAG", B_FALSE, |
352 | sfeatures); | |
2a673e76 | 353 | zprop_register_number(VDEV_PROP_CAPACITY, "capacity", 0, PROP_READONLY, |
be8e1d81 | 354 | ZFS_TYPE_VDEV, "<size>", "CAP", B_FALSE, sfeatures); |
2a673e76 | 355 | zprop_register_number(VDEV_PROP_GUID, "guid", 0, PROP_READONLY, |
be8e1d81 | 356 | ZFS_TYPE_VDEV, "<guid>", "GUID", B_TRUE, sfeatures); |
2a673e76 | 357 | zprop_register_number(VDEV_PROP_STATE, "state", 0, PROP_READONLY, |
be8e1d81 | 358 | ZFS_TYPE_VDEV, "<state>", "STATE", B_FALSE, sfeatures); |
2a673e76 | 359 | zprop_register_number(VDEV_PROP_BOOTSIZE, "bootsize", 0, PROP_READONLY, |
be8e1d81 | 360 | ZFS_TYPE_VDEV, "<size>", "BOOTSIZE", B_FALSE, sfeatures); |
2a673e76 | 361 | zprop_register_number(VDEV_PROP_ASIZE, "asize", 0, PROP_READONLY, |
be8e1d81 | 362 | ZFS_TYPE_VDEV, "<asize>", "ASIZE", B_FALSE, sfeatures); |
2a673e76 | 363 | zprop_register_number(VDEV_PROP_PSIZE, "psize", 0, PROP_READONLY, |
be8e1d81 | 364 | ZFS_TYPE_VDEV, "<psize>", "PSIZE", B_FALSE, sfeatures); |
2a673e76 | 365 | zprop_register_number(VDEV_PROP_ASHIFT, "ashift", 0, PROP_READONLY, |
be8e1d81 | 366 | ZFS_TYPE_VDEV, "<ashift>", "ASHIFT", B_FALSE, sfeatures); |
2a673e76 | 367 | zprop_register_number(VDEV_PROP_PARITY, "parity", 0, PROP_READONLY, |
be8e1d81 | 368 | ZFS_TYPE_VDEV, "<parity>", "PARITY", B_FALSE, sfeatures); |
2a673e76 | 369 | zprop_register_number(VDEV_PROP_NUMCHILDREN, "numchildren", 0, |
eb51a9d7 | 370 | PROP_READONLY, ZFS_TYPE_VDEV, "<number-of-children>", "NUMCHILD", |
be8e1d81 | 371 | B_FALSE, sfeatures); |
2a673e76 | 372 | zprop_register_number(VDEV_PROP_READ_ERRORS, "read_errors", 0, |
be8e1d81 AZ |
373 | PROP_READONLY, ZFS_TYPE_VDEV, "<errors>", "RDERR", B_FALSE, |
374 | sfeatures); | |
2a673e76 | 375 | zprop_register_number(VDEV_PROP_WRITE_ERRORS, "write_errors", 0, |
be8e1d81 AZ |
376 | PROP_READONLY, ZFS_TYPE_VDEV, "<errors>", "WRERR", B_FALSE, |
377 | sfeatures); | |
2a673e76 | 378 | zprop_register_number(VDEV_PROP_CHECKSUM_ERRORS, "checksum_errors", 0, |
be8e1d81 AZ |
379 | PROP_READONLY, ZFS_TYPE_VDEV, "<errors>", "CKERR", B_FALSE, |
380 | sfeatures); | |
2a673e76 AJ |
381 | zprop_register_number(VDEV_PROP_INITIALIZE_ERRORS, |
382 | "initialize_errors", 0, PROP_READONLY, ZFS_TYPE_VDEV, "<errors>", | |
be8e1d81 | 383 | "INITERR", B_FALSE, sfeatures); |
2a673e76 | 384 | zprop_register_number(VDEV_PROP_OPS_NULL, "null_ops", 0, |
be8e1d81 AZ |
385 | PROP_READONLY, ZFS_TYPE_VDEV, "<operations>", "NULLOP", B_FALSE, |
386 | sfeatures); | |
2a673e76 | 387 | zprop_register_number(VDEV_PROP_OPS_READ, "read_ops", 0, |
be8e1d81 AZ |
388 | PROP_READONLY, ZFS_TYPE_VDEV, "<operations>", "READOP", B_FALSE, |
389 | sfeatures); | |
2a673e76 | 390 | zprop_register_number(VDEV_PROP_OPS_WRITE, "write_ops", 0, |
be8e1d81 AZ |
391 | PROP_READONLY, ZFS_TYPE_VDEV, "<operations>", "WRITEOP", B_FALSE, |
392 | sfeatures); | |
2a673e76 | 393 | zprop_register_number(VDEV_PROP_OPS_FREE, "free_ops", 0, |
be8e1d81 AZ |
394 | PROP_READONLY, ZFS_TYPE_VDEV, "<operations>", "FREEOP", B_FALSE, |
395 | sfeatures); | |
2a673e76 | 396 | zprop_register_number(VDEV_PROP_OPS_CLAIM, "claim_ops", 0, |
be8e1d81 AZ |
397 | PROP_READONLY, ZFS_TYPE_VDEV, "<operations>", "CLAIMOP", B_FALSE, |
398 | sfeatures); | |
2a673e76 | 399 | zprop_register_number(VDEV_PROP_OPS_TRIM, "trim_ops", 0, |
be8e1d81 AZ |
400 | PROP_READONLY, ZFS_TYPE_VDEV, "<operations>", "TRIMOP", B_FALSE, |
401 | sfeatures); | |
2a673e76 | 402 | zprop_register_number(VDEV_PROP_BYTES_NULL, "null_bytes", 0, |
be8e1d81 AZ |
403 | PROP_READONLY, ZFS_TYPE_VDEV, "<bytes>", "NULLBYTE", B_FALSE, |
404 | sfeatures); | |
2a673e76 | 405 | zprop_register_number(VDEV_PROP_BYTES_READ, "read_bytes", 0, |
be8e1d81 AZ |
406 | PROP_READONLY, ZFS_TYPE_VDEV, "<bytes>", "READBYTE", B_FALSE, |
407 | sfeatures); | |
2a673e76 | 408 | zprop_register_number(VDEV_PROP_BYTES_WRITE, "write_bytes", 0, |
be8e1d81 AZ |
409 | PROP_READONLY, ZFS_TYPE_VDEV, "<bytes>", "WRITEBYTE", B_FALSE, |
410 | sfeatures); | |
2a673e76 | 411 | zprop_register_number(VDEV_PROP_BYTES_FREE, "free_bytes", 0, |
be8e1d81 AZ |
412 | PROP_READONLY, ZFS_TYPE_VDEV, "<bytes>", "FREEBYTE", B_FALSE, |
413 | sfeatures); | |
2a673e76 | 414 | zprop_register_number(VDEV_PROP_BYTES_CLAIM, "claim_bytes", 0, |
be8e1d81 AZ |
415 | PROP_READONLY, ZFS_TYPE_VDEV, "<bytes>", "CLAIMBYTE", B_FALSE, |
416 | sfeatures); | |
2a673e76 | 417 | zprop_register_number(VDEV_PROP_BYTES_TRIM, "trim_bytes", 0, |
be8e1d81 AZ |
418 | PROP_READONLY, ZFS_TYPE_VDEV, "<bytes>", "TRIMBYTE", B_FALSE, |
419 | sfeatures); | |
2a673e76 AJ |
420 | |
421 | /* default numeric properties */ | |
69f024a5 RW |
422 | zprop_register_number(VDEV_PROP_CHECKSUM_N, "checksum_n", UINT64_MAX, |
423 | PROP_DEFAULT, ZFS_TYPE_VDEV, "<events>", "CKSUM_N", B_FALSE, | |
424 | sfeatures); | |
425 | zprop_register_number(VDEV_PROP_CHECKSUM_T, "checksum_t", UINT64_MAX, | |
426 | PROP_DEFAULT, ZFS_TYPE_VDEV, "<seconds>", "CKSUM_T", B_FALSE, | |
427 | sfeatures); | |
428 | zprop_register_number(VDEV_PROP_IO_N, "io_n", UINT64_MAX, | |
429 | PROP_DEFAULT, ZFS_TYPE_VDEV, "<events>", "IO_N", B_FALSE, | |
430 | sfeatures); | |
431 | zprop_register_number(VDEV_PROP_IO_T, "io_t", UINT64_MAX, | |
432 | PROP_DEFAULT, ZFS_TYPE_VDEV, "<seconds>", "IO_T", B_FALSE, | |
433 | sfeatures); | |
cbe88229 DB |
434 | zprop_register_number(VDEV_PROP_SLOW_IO_N, "slow_io_n", UINT64_MAX, |
435 | PROP_DEFAULT, ZFS_TYPE_VDEV, "<events>", "SLOW_IO_N", B_FALSE, | |
436 | sfeatures); | |
437 | zprop_register_number(VDEV_PROP_SLOW_IO_T, "slow_io_t", UINT64_MAX, | |
438 | PROP_DEFAULT, ZFS_TYPE_VDEV, "<seconds>", "SLOW_IO_T", B_FALSE, | |
439 | sfeatures); | |
2a673e76 AJ |
440 | |
441 | /* default index (boolean) properties */ | |
442 | zprop_register_index(VDEV_PROP_REMOVING, "removing", 0, | |
443 | PROP_READONLY, ZFS_TYPE_VDEV, "on | off", "REMOVING", | |
eb51a9d7 | 444 | boolean_table, sfeatures); |
2a673e76 AJ |
445 | zprop_register_index(VDEV_PROP_ALLOCATING, "allocating", 1, |
446 | PROP_DEFAULT, ZFS_TYPE_VDEV, "on | off", "ALLOCATING", | |
eb51a9d7 | 447 | boolean_na_table, sfeatures); |
5caeef02 DB |
448 | zprop_register_index(VDEV_PROP_RAIDZ_EXPANDING, "raidz_expanding", 0, |
449 | PROP_READONLY, ZFS_TYPE_VDEV, "on | off", "RAIDZ_EXPANDING", | |
450 | boolean_table, sfeatures); | |
2a673e76 AJ |
451 | |
452 | /* default index properties */ | |
16f0fdad MZ |
453 | zprop_register_index(VDEV_PROP_FAILFAST, "failfast", B_TRUE, |
454 | PROP_DEFAULT, ZFS_TYPE_VDEV, "on | off", "FAILFAST", boolean_table, | |
455 | sfeatures); | |
2a673e76 AJ |
456 | |
457 | /* hidden properties */ | |
458 | zprop_register_hidden(VDEV_PROP_NAME, "name", PROP_TYPE_STRING, | |
be8e1d81 | 459 | PROP_READONLY, ZFS_TYPE_VDEV, "NAME", B_TRUE, sfeatures); |
eb51a9d7 AZ |
460 | |
461 | zfs_mod_list_supported_free(sfeatures); | |
2a673e76 AJ |
462 | } |
463 | ||
464 | /* | |
465 | * Given a property name and its type, returns the corresponding property ID. | |
466 | */ | |
467 | vdev_prop_t | |
468 | vdev_name_to_prop(const char *propname) | |
469 | { | |
470 | return (zprop_name_to_prop(propname, ZFS_TYPE_VDEV)); | |
471 | } | |
472 | ||
473 | /* | |
474 | * Returns true if this is a valid user-defined property (one with a ':'). | |
475 | */ | |
476 | boolean_t | |
477 | vdev_prop_user(const char *name) | |
478 | { | |
479 | int i; | |
480 | char c; | |
481 | boolean_t foundsep = B_FALSE; | |
482 | ||
483 | for (i = 0; i < strlen(name); i++) { | |
484 | c = name[i]; | |
485 | if (!zprop_valid_char(c)) | |
486 | return (B_FALSE); | |
487 | if (c == ':') | |
488 | foundsep = B_TRUE; | |
489 | } | |
490 | ||
491 | return (foundsep); | |
492 | } | |
493 | ||
494 | /* | |
495 | * Given a pool property ID, returns the corresponding name. | |
496 | * Assuming the pool property ID is valid. | |
497 | */ | |
498 | const char * | |
499 | vdev_prop_to_name(vdev_prop_t prop) | |
500 | { | |
501 | return (vdev_prop_table[prop].pd_name); | |
502 | } | |
503 | ||
504 | zprop_type_t | |
505 | vdev_prop_get_type(vdev_prop_t prop) | |
506 | { | |
507 | return (vdev_prop_table[prop].pd_proptype); | |
508 | } | |
509 | ||
510 | boolean_t | |
511 | vdev_prop_readonly(vdev_prop_t prop) | |
512 | { | |
513 | return (vdev_prop_table[prop].pd_attr == PROP_READONLY); | |
514 | } | |
515 | ||
516 | const char * | |
517 | vdev_prop_default_string(vdev_prop_t prop) | |
518 | { | |
519 | return (vdev_prop_table[prop].pd_strdefault); | |
520 | } | |
521 | ||
522 | uint64_t | |
523 | vdev_prop_default_numeric(vdev_prop_t prop) | |
524 | { | |
525 | return (vdev_prop_table[prop].pd_numdefault); | |
526 | } | |
527 | ||
528 | int | |
529 | vdev_prop_string_to_index(vdev_prop_t prop, const char *string, | |
530 | uint64_t *index) | |
531 | { | |
532 | return (zprop_string_to_index(prop, string, index, ZFS_TYPE_VDEV)); | |
533 | } | |
534 | ||
535 | int | |
536 | vdev_prop_index_to_string(vdev_prop_t prop, uint64_t index, | |
537 | const char **string) | |
538 | { | |
539 | return (zprop_index_to_string(prop, index, string, ZFS_TYPE_VDEV)); | |
540 | } | |
541 | ||
542 | /* | |
543 | * Returns true if this is a valid vdev property. | |
544 | */ | |
545 | boolean_t | |
546 | zpool_prop_vdev(const char *name) | |
547 | { | |
548 | return (vdev_name_to_prop(name) != VDEV_PROP_INVAL); | |
549 | } | |
550 | ||
551 | uint64_t | |
552 | vdev_prop_random_value(vdev_prop_t prop, uint64_t seed) | |
553 | { | |
554 | return (zprop_random_value(prop, seed, ZFS_TYPE_VDEV)); | |
555 | } | |
556 | ||
557 | #ifndef _KERNEL | |
558 | const char * | |
559 | vdev_prop_values(vdev_prop_t prop) | |
560 | { | |
561 | return (vdev_prop_table[prop].pd_values); | |
562 | } | |
563 | ||
564 | const char * | |
565 | vdev_prop_column_name(vdev_prop_t prop) | |
566 | { | |
567 | return (vdev_prop_table[prop].pd_colname); | |
568 | } | |
569 | ||
570 | boolean_t | |
571 | vdev_prop_align_right(vdev_prop_t prop) | |
572 | { | |
573 | return (vdev_prop_table[prop].pd_rightalign); | |
574 | } | |
575 | #endif | |
576 | ||
93ce2b4c | 577 | #if defined(_KERNEL) |
c28b2279 BB |
578 | /* zpool property functions */ |
579 | EXPORT_SYMBOL(zpool_prop_init); | |
580 | EXPORT_SYMBOL(zpool_prop_get_type); | |
581 | EXPORT_SYMBOL(zpool_prop_get_table); | |
582 | ||
2a673e76 AJ |
583 | /* vdev property functions */ |
584 | EXPORT_SYMBOL(vdev_prop_init); | |
585 | EXPORT_SYMBOL(vdev_prop_get_type); | |
586 | EXPORT_SYMBOL(vdev_prop_get_table); | |
587 | ||
c28b2279 BB |
588 | /* Pool property functions shared between libzfs and kernel. */ |
589 | EXPORT_SYMBOL(zpool_name_to_prop); | |
590 | EXPORT_SYMBOL(zpool_prop_to_name); | |
591 | EXPORT_SYMBOL(zpool_prop_default_string); | |
592 | EXPORT_SYMBOL(zpool_prop_default_numeric); | |
593 | EXPORT_SYMBOL(zpool_prop_readonly); | |
9ae529ec CS |
594 | EXPORT_SYMBOL(zpool_prop_feature); |
595 | EXPORT_SYMBOL(zpool_prop_unsupported); | |
c28b2279 BB |
596 | EXPORT_SYMBOL(zpool_prop_index_to_string); |
597 | EXPORT_SYMBOL(zpool_prop_string_to_index); | |
2a673e76 AJ |
598 | EXPORT_SYMBOL(zpool_prop_vdev); |
599 | ||
600 | /* vdev property functions shared between libzfs and kernel. */ | |
601 | EXPORT_SYMBOL(vdev_name_to_prop); | |
602 | EXPORT_SYMBOL(vdev_prop_user); | |
603 | EXPORT_SYMBOL(vdev_prop_to_name); | |
604 | EXPORT_SYMBOL(vdev_prop_default_string); | |
605 | EXPORT_SYMBOL(vdev_prop_default_numeric); | |
606 | EXPORT_SYMBOL(vdev_prop_readonly); | |
607 | EXPORT_SYMBOL(vdev_prop_index_to_string); | |
608 | EXPORT_SYMBOL(vdev_prop_string_to_index); | |
c28b2279 | 609 | #endif |