1990b4856Slling /* 2990b4856Slling * CDDL HEADER START 3990b4856Slling * 4990b4856Slling * The contents of this file are subject to the terms of the 5990b4856Slling * Common Development and Distribution License (the "License"). 6990b4856Slling * You may not use this file except in compliance with the License. 7990b4856Slling * 8990b4856Slling * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9990b4856Slling * or http://www.opensolaris.org/os/licensing. 10990b4856Slling * See the License for the specific language governing permissions 11990b4856Slling * and limitations under the License. 12990b4856Slling * 13990b4856Slling * When distributing Covered Code, include this CDDL HEADER in each 14990b4856Slling * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15990b4856Slling * If applicable, add the following below this CDDL HEADER, with the 16990b4856Slling * fields enclosed by brackets "[]" replaced with your own identifying 17990b4856Slling * information: Portions Copyright [yyyy] [name of copyright owner] 18990b4856Slling * 19990b4856Slling * CDDL HEADER END 20990b4856Slling */ 21990b4856Slling /* 22f9af39baSGeorge Wilson * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. 238704186eSDan McDonald * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 244263d13fSGeorge Wilson * Copyright (c) 2012 by Delphix. All rights reserved. 25990b4856Slling */ 26990b4856Slling 27990b4856Slling #include <sys/zio.h> 28990b4856Slling #include <sys/spa.h> 29990b4856Slling #include <sys/zfs_acl.h> 30990b4856Slling #include <sys/zfs_ioctl.h> 31990b4856Slling #include <sys/fs/zfs.h> 32990b4856Slling 33990b4856Slling #include "zfs_prop.h" 34990b4856Slling 35990b4856Slling #if defined(_KERNEL) 36990b4856Slling #include <sys/systm.h> 37990b4856Slling #else 38990b4856Slling #include <stdlib.h> 39990b4856Slling #include <string.h> 40990b4856Slling #include <ctype.h> 41990b4856Slling #endif 42990b4856Slling 43990b4856Slling static zprop_desc_t zpool_prop_table[ZPOOL_NUM_PROPS]; 44990b4856Slling 45990b4856Slling zprop_desc_t * 46990b4856Slling zpool_prop_get_table(void) 47990b4856Slling { 48990b4856Slling return (zpool_prop_table); 49990b4856Slling } 50990b4856Slling 51990b4856Slling void 52990b4856Slling zpool_prop_init(void) 53990b4856Slling { 54990b4856Slling static zprop_index_t boolean_table[] = { 55990b4856Slling { "off", 0}, 56990b4856Slling { "on", 1}, 57990b4856Slling { NULL } 58990b4856Slling }; 59990b4856Slling 600a4e9518Sgw static zprop_index_t failuremode_table[] = { 610a4e9518Sgw { "wait", ZIO_FAILURE_MODE_WAIT }, 620a4e9518Sgw { "continue", ZIO_FAILURE_MODE_CONTINUE }, 630a4e9518Sgw { "panic", ZIO_FAILURE_MODE_PANIC }, 640a4e9518Sgw { NULL } 650a4e9518Sgw }; 660a4e9518Sgw 67990b4856Slling /* string properties */ 6883d7f9feSTom Erickson zprop_register_string(ZPOOL_PROP_ALTROOT, "altroot", NULL, PROP_DEFAULT, 69990b4856Slling ZFS_TYPE_POOL, "<path>", "ALTROOT"); 7083d7f9feSTom Erickson zprop_register_string(ZPOOL_PROP_BOOTFS, "bootfs", NULL, PROP_DEFAULT, 71990b4856Slling ZFS_TYPE_POOL, "<filesystem>", "BOOTFS"); 7283d7f9feSTom Erickson zprop_register_string(ZPOOL_PROP_CACHEFILE, "cachefile", NULL, 7383d7f9feSTom Erickson PROP_DEFAULT, ZFS_TYPE_POOL, "<file> | none", "CACHEFILE"); 748704186eSDan McDonald zprop_register_string(ZPOOL_PROP_COMMENT, "comment", NULL, 758704186eSDan McDonald PROP_DEFAULT, ZFS_TYPE_POOL, "<comment-string>", "COMMENT"); 76990b4856Slling 77990b4856Slling /* readonly number properties */ 7883d7f9feSTom Erickson zprop_register_number(ZPOOL_PROP_SIZE, "size", 0, PROP_READONLY, 79990b4856Slling ZFS_TYPE_POOL, "<size>", "SIZE"); 8083d7f9feSTom Erickson zprop_register_number(ZPOOL_PROP_FREE, "free", 0, PROP_READONLY, 81485bbbf5SGeorge Wilson ZFS_TYPE_POOL, "<size>", "FREE"); 82*ad135b5dSChristopher Siden zprop_register_number(ZPOOL_PROP_FREEING, "freeing", 0, PROP_READONLY, 83*ad135b5dSChristopher Siden ZFS_TYPE_POOL, "<size>", "FREEING"); 8483d7f9feSTom Erickson zprop_register_number(ZPOOL_PROP_ALLOCATED, "allocated", 0, 8583d7f9feSTom Erickson PROP_READONLY, ZFS_TYPE_POOL, "<size>", "ALLOC"); 864263d13fSGeorge Wilson zprop_register_number(ZPOOL_PROP_EXPANDSZ, "expandsize", 0, 874263d13fSGeorge Wilson PROP_READONLY, ZFS_TYPE_POOL, "<size>", "EXPANDSZ"); 8883d7f9feSTom Erickson zprop_register_number(ZPOOL_PROP_CAPACITY, "capacity", 0, PROP_READONLY, 89990b4856Slling ZFS_TYPE_POOL, "<size>", "CAP"); 9083d7f9feSTom Erickson zprop_register_number(ZPOOL_PROP_GUID, "guid", 0, PROP_READONLY, 91990b4856Slling ZFS_TYPE_POOL, "<guid>", "GUID"); 9283d7f9feSTom Erickson zprop_register_number(ZPOOL_PROP_HEALTH, "health", 0, PROP_READONLY, 93990b4856Slling ZFS_TYPE_POOL, "<state>", "HEALTH"); 9483d7f9feSTom Erickson zprop_register_number(ZPOOL_PROP_DEDUPRATIO, "dedupratio", 0, 9583d7f9feSTom Erickson PROP_READONLY, ZFS_TYPE_POOL, "<1.00x or higher if deduped>", 9683d7f9feSTom Erickson "DEDUP"); 97990b4856Slling 98990b4856Slling /* default number properties */ 9983d7f9feSTom Erickson zprop_register_number(ZPOOL_PROP_VERSION, "version", SPA_VERSION, 100990b4856Slling PROP_DEFAULT, ZFS_TYPE_POOL, "<version>", "VERSION"); 10183d7f9feSTom Erickson zprop_register_number(ZPOOL_PROP_DEDUPDITTO, "dedupditto", 0, 102bbfd46c4SJeff Bonwick PROP_DEFAULT, ZFS_TYPE_POOL, "<threshold (min 100)>", "DEDUPDITTO"); 103990b4856Slling 104990b4856Slling /* default index (boolean) properties */ 10583d7f9feSTom Erickson zprop_register_index(ZPOOL_PROP_DELEGATION, "delegation", 1, 10683d7f9feSTom Erickson PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "DELEGATION", 10783d7f9feSTom Erickson boolean_table); 10883d7f9feSTom Erickson zprop_register_index(ZPOOL_PROP_AUTOREPLACE, "autoreplace", 0, 10983d7f9feSTom Erickson PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "REPLACE", boolean_table); 11083d7f9feSTom Erickson zprop_register_index(ZPOOL_PROP_LISTSNAPS, "listsnapshots", 0, 11183d7f9feSTom Erickson PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "LISTSNAPS", 11283d7f9feSTom Erickson boolean_table); 11383d7f9feSTom Erickson zprop_register_index(ZPOOL_PROP_AUTOEXPAND, "autoexpand", 0, 11483d7f9feSTom Erickson PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "EXPAND", boolean_table); 115f9af39baSGeorge Wilson zprop_register_index(ZPOOL_PROP_READONLY, "readonly", 0, 116f9af39baSGeorge Wilson PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "RDONLY", boolean_table); 117990b4856Slling 1180a4e9518Sgw /* default index properties */ 11983d7f9feSTom Erickson zprop_register_index(ZPOOL_PROP_FAILUREMODE, "failmode", 1200a4e9518Sgw ZIO_FAILURE_MODE_WAIT, PROP_DEFAULT, ZFS_TYPE_POOL, 1210a4e9518Sgw "wait | continue | panic", "FAILMODE", failuremode_table); 1220a4e9518Sgw 123990b4856Slling /* hidden properties */ 12483d7f9feSTom Erickson zprop_register_hidden(ZPOOL_PROP_NAME, "name", PROP_TYPE_STRING, 125990b4856Slling PROP_READONLY, ZFS_TYPE_POOL, "NAME"); 126990b4856Slling } 127990b4856Slling 128990b4856Slling /* 129990b4856Slling * Given a property name and its type, returns the corresponding property ID. 130990b4856Slling */ 131990b4856Slling zpool_prop_t 132990b4856Slling zpool_name_to_prop(const char *propname) 133990b4856Slling { 134990b4856Slling return (zprop_name_to_prop(propname, ZFS_TYPE_POOL)); 135990b4856Slling } 136990b4856Slling 137990b4856Slling /* 138990b4856Slling * Given a pool property ID, returns the corresponding name. 139990b4856Slling * Assuming the pool propety ID is valid. 140990b4856Slling */ 141990b4856Slling const char * 142990b4856Slling zpool_prop_to_name(zpool_prop_t prop) 143990b4856Slling { 144990b4856Slling return (zpool_prop_table[prop].pd_name); 145990b4856Slling } 146990b4856Slling 147990b4856Slling zprop_type_t 148990b4856Slling zpool_prop_get_type(zpool_prop_t prop) 149990b4856Slling { 150990b4856Slling return (zpool_prop_table[prop].pd_proptype); 151990b4856Slling } 152990b4856Slling 153990b4856Slling boolean_t 154990b4856Slling zpool_prop_readonly(zpool_prop_t prop) 155990b4856Slling { 156990b4856Slling return (zpool_prop_table[prop].pd_attr == PROP_READONLY); 157990b4856Slling } 158990b4856Slling 159990b4856Slling const char * 160990b4856Slling zpool_prop_default_string(zpool_prop_t prop) 161990b4856Slling { 162990b4856Slling return (zpool_prop_table[prop].pd_strdefault); 163990b4856Slling } 164990b4856Slling 165990b4856Slling uint64_t 166990b4856Slling zpool_prop_default_numeric(zpool_prop_t prop) 167990b4856Slling { 168990b4856Slling return (zpool_prop_table[prop].pd_numdefault); 169990b4856Slling } 170990b4856Slling 171*ad135b5dSChristopher Siden /* 172*ad135b5dSChristopher Siden * Returns true if this is a valid feature@ property. 173*ad135b5dSChristopher Siden */ 174*ad135b5dSChristopher Siden boolean_t 175*ad135b5dSChristopher Siden zpool_prop_feature(const char *name) 176*ad135b5dSChristopher Siden { 177*ad135b5dSChristopher Siden static const char *prefix = "feature@"; 178*ad135b5dSChristopher Siden return (strncmp(name, prefix, strlen(prefix)) == 0); 179*ad135b5dSChristopher Siden } 180*ad135b5dSChristopher Siden 181*ad135b5dSChristopher Siden /* 182*ad135b5dSChristopher Siden * Returns true if this is a valid unsupported@ property. 183*ad135b5dSChristopher Siden */ 184*ad135b5dSChristopher Siden boolean_t 185*ad135b5dSChristopher Siden zpool_prop_unsupported(const char *name) 186*ad135b5dSChristopher Siden { 187*ad135b5dSChristopher Siden static const char *prefix = "unsupported@"; 188*ad135b5dSChristopher Siden return (strncmp(name, prefix, strlen(prefix)) == 0); 189*ad135b5dSChristopher Siden } 190*ad135b5dSChristopher Siden 191990b4856Slling int 192990b4856Slling zpool_prop_string_to_index(zpool_prop_t prop, const char *string, 193990b4856Slling uint64_t *index) 194990b4856Slling { 195990b4856Slling return (zprop_string_to_index(prop, string, index, ZFS_TYPE_POOL)); 196990b4856Slling } 197990b4856Slling 198990b4856Slling int 199990b4856Slling zpool_prop_index_to_string(zpool_prop_t prop, uint64_t index, 200990b4856Slling const char **string) 201990b4856Slling { 202990b4856Slling return (zprop_index_to_string(prop, index, string, ZFS_TYPE_POOL)); 203990b4856Slling } 204990b4856Slling 205b24ab676SJeff Bonwick uint64_t 206b24ab676SJeff Bonwick zpool_prop_random_value(zpool_prop_t prop, uint64_t seed) 207b24ab676SJeff Bonwick { 208b24ab676SJeff Bonwick return (zprop_random_value(prop, seed, ZFS_TYPE_POOL)); 209b24ab676SJeff Bonwick } 210b24ab676SJeff Bonwick 211990b4856Slling #ifndef _KERNEL 212990b4856Slling 213990b4856Slling const char * 214990b4856Slling zpool_prop_values(zpool_prop_t prop) 215990b4856Slling { 216990b4856Slling return (zpool_prop_table[prop].pd_values); 217990b4856Slling } 218990b4856Slling 219990b4856Slling const char * 220990b4856Slling zpool_prop_column_name(zpool_prop_t prop) 221990b4856Slling { 222990b4856Slling return (zpool_prop_table[prop].pd_colname); 223990b4856Slling } 224990b4856Slling 225990b4856Slling boolean_t 226990b4856Slling zpool_prop_align_right(zpool_prop_t prop) 227990b4856Slling { 228990b4856Slling return (zpool_prop_table[prop].pd_rightalign); 229990b4856Slling } 230990b4856Slling #endif 231