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