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