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