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 /* 22990b4856Slling * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23990b4856Slling * Use is subject to license terms. 24990b4856Slling */ 25990b4856Slling 26990b4856Slling #pragma ident "%Z%%M% %I% %E% SMI" 27990b4856Slling 28990b4856Slling #include <sys/zio.h> 29990b4856Slling #include <sys/spa.h> 30990b4856Slling #include <sys/zfs_acl.h> 31990b4856Slling #include <sys/zfs_ioctl.h> 32990b4856Slling #include <sys/fs/zfs.h> 33990b4856Slling 34990b4856Slling #include "zfs_prop.h" 35990b4856Slling 36990b4856Slling #if defined(_KERNEL) 37990b4856Slling #include <sys/systm.h> 38990b4856Slling #else 39990b4856Slling #include <stdlib.h> 40990b4856Slling #include <string.h> 41990b4856Slling #include <ctype.h> 42990b4856Slling #endif 43990b4856Slling 44990b4856Slling static zprop_desc_t zpool_prop_table[ZPOOL_NUM_PROPS]; 45990b4856Slling 46990b4856Slling zprop_desc_t * 47990b4856Slling zpool_prop_get_table(void) 48990b4856Slling { 49990b4856Slling return (zpool_prop_table); 50990b4856Slling } 51990b4856Slling 52990b4856Slling void 53990b4856Slling zpool_prop_init(void) 54990b4856Slling { 55990b4856Slling static zprop_index_t boolean_table[] = { 56990b4856Slling { "off", 0}, 57990b4856Slling { "on", 1}, 58990b4856Slling { NULL } 59990b4856Slling }; 60990b4856Slling 61*0a4e9518Sgw static zprop_index_t failuremode_table[] = { 62*0a4e9518Sgw { "wait", ZIO_FAILURE_MODE_WAIT }, 63*0a4e9518Sgw { "continue", ZIO_FAILURE_MODE_CONTINUE }, 64*0a4e9518Sgw { "panic", ZIO_FAILURE_MODE_PANIC }, 65*0a4e9518Sgw { NULL } 66*0a4e9518Sgw }; 67*0a4e9518Sgw 68990b4856Slling /* string properties */ 69990b4856Slling register_string(ZPOOL_PROP_ALTROOT, "altroot", NULL, PROP_DEFAULT, 70990b4856Slling ZFS_TYPE_POOL, "<path>", "ALTROOT"); 71990b4856Slling register_string(ZPOOL_PROP_BOOTFS, "bootfs", NULL, PROP_DEFAULT, 72990b4856Slling ZFS_TYPE_POOL, "<filesystem>", "BOOTFS"); 73990b4856Slling 74990b4856Slling /* readonly number properties */ 75990b4856Slling register_number(ZPOOL_PROP_SIZE, "size", 0, PROP_READONLY, 76990b4856Slling ZFS_TYPE_POOL, "<size>", "SIZE"); 77990b4856Slling register_number(ZPOOL_PROP_USED, "used", 0, PROP_READONLY, 78990b4856Slling ZFS_TYPE_POOL, "<size>", "USED"); 79990b4856Slling register_number(ZPOOL_PROP_AVAILABLE, "available", 0, PROP_READONLY, 80990b4856Slling ZFS_TYPE_POOL, "<size>", "AVAIL"); 81990b4856Slling register_number(ZPOOL_PROP_CAPACITY, "capacity", 0, PROP_READONLY, 82990b4856Slling ZFS_TYPE_POOL, "<size>", "CAP"); 83990b4856Slling register_number(ZPOOL_PROP_GUID, "guid", 0, PROP_READONLY, 84990b4856Slling ZFS_TYPE_POOL, "<guid>", "GUID"); 85990b4856Slling register_number(ZPOOL_PROP_HEALTH, "health", 0, PROP_READONLY, 86990b4856Slling ZFS_TYPE_POOL, "<state>", "HEALTH"); 87990b4856Slling 88990b4856Slling /* default number properties */ 89990b4856Slling register_number(ZPOOL_PROP_VERSION, "version", SPA_VERSION, 90990b4856Slling PROP_DEFAULT, ZFS_TYPE_POOL, "<version>", "VERSION"); 91990b4856Slling 92990b4856Slling /* default index (boolean) properties */ 93990b4856Slling register_index(ZPOOL_PROP_DELEGATION, "delegation", 1, PROP_DEFAULT, 94990b4856Slling ZFS_TYPE_POOL, "on | off", "DELEGATION", boolean_table); 95990b4856Slling register_index(ZPOOL_PROP_AUTOREPLACE, "autoreplace", 0, PROP_DEFAULT, 96990b4856Slling ZFS_TYPE_POOL, "on | off", "REPLACE", boolean_table); 97990b4856Slling register_index(ZPOOL_PROP_TEMPORARY, "temporary", 0, PROP_DEFAULT, 98990b4856Slling ZFS_TYPE_POOL, "on | off", "TEMP", boolean_table); 99990b4856Slling 100*0a4e9518Sgw /* default index properties */ 101*0a4e9518Sgw register_index(ZPOOL_PROP_FAILUREMODE, "failmode", 102*0a4e9518Sgw ZIO_FAILURE_MODE_WAIT, PROP_DEFAULT, ZFS_TYPE_POOL, 103*0a4e9518Sgw "wait | continue | panic", "FAILMODE", failuremode_table); 104*0a4e9518Sgw 105990b4856Slling /* hidden properties */ 106990b4856Slling register_hidden(ZPOOL_PROP_NAME, "name", PROP_TYPE_STRING, 107990b4856Slling PROP_READONLY, ZFS_TYPE_POOL, "NAME"); 108990b4856Slling } 109990b4856Slling 110990b4856Slling /* 111990b4856Slling * Given a property name and its type, returns the corresponding property ID. 112990b4856Slling */ 113990b4856Slling zpool_prop_t 114990b4856Slling zpool_name_to_prop(const char *propname) 115990b4856Slling { 116990b4856Slling return (zprop_name_to_prop(propname, ZFS_TYPE_POOL)); 117990b4856Slling } 118990b4856Slling 119990b4856Slling /* 120990b4856Slling * Given a pool property ID, returns the corresponding name. 121990b4856Slling * Assuming the pool propety ID is valid. 122990b4856Slling */ 123990b4856Slling const char * 124990b4856Slling zpool_prop_to_name(zpool_prop_t prop) 125990b4856Slling { 126990b4856Slling return (zpool_prop_table[prop].pd_name); 127990b4856Slling } 128990b4856Slling 129990b4856Slling zprop_type_t 130990b4856Slling zpool_prop_get_type(zpool_prop_t prop) 131990b4856Slling { 132990b4856Slling return (zpool_prop_table[prop].pd_proptype); 133990b4856Slling } 134990b4856Slling 135990b4856Slling boolean_t 136990b4856Slling zpool_prop_readonly(zpool_prop_t prop) 137990b4856Slling { 138990b4856Slling return (zpool_prop_table[prop].pd_attr == PROP_READONLY); 139990b4856Slling } 140990b4856Slling 141990b4856Slling const char * 142990b4856Slling zpool_prop_default_string(zpool_prop_t prop) 143990b4856Slling { 144990b4856Slling return (zpool_prop_table[prop].pd_strdefault); 145990b4856Slling } 146990b4856Slling 147990b4856Slling uint64_t 148990b4856Slling zpool_prop_default_numeric(zpool_prop_t prop) 149990b4856Slling { 150990b4856Slling return (zpool_prop_table[prop].pd_numdefault); 151990b4856Slling } 152990b4856Slling 153990b4856Slling int 154990b4856Slling zpool_prop_string_to_index(zpool_prop_t prop, const char *string, 155990b4856Slling uint64_t *index) 156990b4856Slling { 157990b4856Slling return (zprop_string_to_index(prop, string, index, ZFS_TYPE_POOL)); 158990b4856Slling } 159990b4856Slling 160990b4856Slling int 161990b4856Slling zpool_prop_index_to_string(zpool_prop_t prop, uint64_t index, 162990b4856Slling const char **string) 163990b4856Slling { 164990b4856Slling return (zprop_index_to_string(prop, index, string, ZFS_TYPE_POOL)); 165990b4856Slling } 166990b4856Slling 167990b4856Slling #ifndef _KERNEL 168990b4856Slling 169990b4856Slling const char * 170990b4856Slling zpool_prop_values(zpool_prop_t prop) 171990b4856Slling { 172990b4856Slling return (zpool_prop_table[prop].pd_values); 173990b4856Slling } 174990b4856Slling 175990b4856Slling const char * 176990b4856Slling zpool_prop_column_name(zpool_prop_t prop) 177990b4856Slling { 178990b4856Slling return (zpool_prop_table[prop].pd_colname); 179990b4856Slling } 180990b4856Slling 181990b4856Slling boolean_t 182990b4856Slling zpool_prop_align_right(zpool_prop_t prop) 183990b4856Slling { 184990b4856Slling return (zpool_prop_table[prop].pd_rightalign); 185990b4856Slling } 186990b4856Slling #endif 187