xref: /onnv-gate/usr/src/common/zfs/zpool_prop.c (revision 13049:bda0decf867b)
15094Slling /*
25094Slling  * CDDL HEADER START
35094Slling  *
45094Slling  * The contents of this file are subject to the terms of the
55094Slling  * Common Development and Distribution License (the "License").
65094Slling  * You may not use this file except in compliance with the License.
75094Slling  *
85094Slling  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95094Slling  * or http://www.opensolaris.org/os/licensing.
105094Slling  * See the License for the specific language governing permissions
115094Slling  * and limitations under the License.
125094Slling  *
135094Slling  * When distributing Covered Code, include this CDDL HEADER in each
145094Slling  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155094Slling  * If applicable, add the following below this CDDL HEADER, with the
165094Slling  * fields enclosed by brackets "[]" replaced with your own identifying
175094Slling  * information: Portions Copyright [yyyy] [name of copyright owner]
185094Slling  *
195094Slling  * CDDL HEADER END
205094Slling  */
215094Slling /*
22*13049SGeorge.Wilson@Sun.COM  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
235094Slling  */
245094Slling 
255094Slling #include <sys/zio.h>
265094Slling #include <sys/spa.h>
275094Slling #include <sys/zfs_acl.h>
285094Slling #include <sys/zfs_ioctl.h>
295094Slling #include <sys/fs/zfs.h>
305094Slling 
315094Slling #include "zfs_prop.h"
325094Slling 
335094Slling #if defined(_KERNEL)
345094Slling #include <sys/systm.h>
355094Slling #else
365094Slling #include <stdlib.h>
375094Slling #include <string.h>
385094Slling #include <ctype.h>
395094Slling #endif
405094Slling 
415094Slling static zprop_desc_t zpool_prop_table[ZPOOL_NUM_PROPS];
425094Slling 
435094Slling zprop_desc_t *
zpool_prop_get_table(void)445094Slling zpool_prop_get_table(void)
455094Slling {
465094Slling 	return (zpool_prop_table);
475094Slling }
485094Slling 
495094Slling void
zpool_prop_init(void)505094Slling zpool_prop_init(void)
515094Slling {
525094Slling 	static zprop_index_t boolean_table[] = {
535094Slling 		{ "off",	0},
545094Slling 		{ "on",		1},
555094Slling 		{ NULL }
565094Slling 	};
575094Slling 
585329Sgw25295 	static zprop_index_t failuremode_table[] = {
595329Sgw25295 		{ "wait",	ZIO_FAILURE_MODE_WAIT },
605329Sgw25295 		{ "continue",	ZIO_FAILURE_MODE_CONTINUE },
615329Sgw25295 		{ "panic",	ZIO_FAILURE_MODE_PANIC },
625329Sgw25295 		{ NULL }
635329Sgw25295 	};
645329Sgw25295 
655094Slling 	/* string properties */
6611976STom.Erickson@Sun.COM 	zprop_register_string(ZPOOL_PROP_ALTROOT, "altroot", NULL, PROP_DEFAULT,
675094Slling 	    ZFS_TYPE_POOL, "<path>", "ALTROOT");
6811976STom.Erickson@Sun.COM 	zprop_register_string(ZPOOL_PROP_BOOTFS, "bootfs", NULL, PROP_DEFAULT,
695094Slling 	    ZFS_TYPE_POOL, "<filesystem>", "BOOTFS");
7011976STom.Erickson@Sun.COM 	zprop_register_string(ZPOOL_PROP_CACHEFILE, "cachefile", NULL,
7111976STom.Erickson@Sun.COM 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<file> | none", "CACHEFILE");
725094Slling 
735094Slling 	/* readonly number properties */
7411976STom.Erickson@Sun.COM 	zprop_register_number(ZPOOL_PROP_SIZE, "size", 0, PROP_READONLY,
755094Slling 	    ZFS_TYPE_POOL, "<size>", "SIZE");
7611976STom.Erickson@Sun.COM 	zprop_register_number(ZPOOL_PROP_FREE, "free", 0, PROP_READONLY,
7710956SGeorge.Wilson@Sun.COM 	    ZFS_TYPE_POOL, "<size>", "FREE");
7811976STom.Erickson@Sun.COM 	zprop_register_number(ZPOOL_PROP_ALLOCATED, "allocated", 0,
7911976STom.Erickson@Sun.COM 	    PROP_READONLY, ZFS_TYPE_POOL, "<size>", "ALLOC");
8011976STom.Erickson@Sun.COM 	zprop_register_number(ZPOOL_PROP_CAPACITY, "capacity", 0, PROP_READONLY,
815094Slling 	    ZFS_TYPE_POOL, "<size>", "CAP");
8211976STom.Erickson@Sun.COM 	zprop_register_number(ZPOOL_PROP_GUID, "guid", 0, PROP_READONLY,
835094Slling 	    ZFS_TYPE_POOL, "<guid>", "GUID");
8411976STom.Erickson@Sun.COM 	zprop_register_number(ZPOOL_PROP_HEALTH, "health", 0, PROP_READONLY,
855094Slling 	    ZFS_TYPE_POOL, "<state>", "HEALTH");
8611976STom.Erickson@Sun.COM 	zprop_register_number(ZPOOL_PROP_DEDUPRATIO, "dedupratio", 0,
8711976STom.Erickson@Sun.COM 	    PROP_READONLY, ZFS_TYPE_POOL, "<1.00x or higher if deduped>",
8811976STom.Erickson@Sun.COM 	    "DEDUP");
895094Slling 
905094Slling 	/* default number properties */
9111976STom.Erickson@Sun.COM 	zprop_register_number(ZPOOL_PROP_VERSION, "version", SPA_VERSION,
925094Slling 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<version>", "VERSION");
9311976STom.Erickson@Sun.COM 	zprop_register_number(ZPOOL_PROP_DEDUPDITTO, "dedupditto", 0,
9411125SJeff.Bonwick@Sun.COM 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<threshold (min 100)>", "DEDUPDITTO");
955094Slling 
965094Slling 	/* default index (boolean) properties */
9711976STom.Erickson@Sun.COM 	zprop_register_index(ZPOOL_PROP_DELEGATION, "delegation", 1,
9811976STom.Erickson@Sun.COM 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "DELEGATION",
9911976STom.Erickson@Sun.COM 	    boolean_table);
10011976STom.Erickson@Sun.COM 	zprop_register_index(ZPOOL_PROP_AUTOREPLACE, "autoreplace", 0,
10111976STom.Erickson@Sun.COM 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "REPLACE", boolean_table);
10211976STom.Erickson@Sun.COM 	zprop_register_index(ZPOOL_PROP_LISTSNAPS, "listsnapshots", 0,
10311976STom.Erickson@Sun.COM 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "LISTSNAPS",
10411976STom.Erickson@Sun.COM 	    boolean_table);
10511976STom.Erickson@Sun.COM 	zprop_register_index(ZPOOL_PROP_AUTOEXPAND, "autoexpand", 0,
10611976STom.Erickson@Sun.COM 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "EXPAND", boolean_table);
107*13049SGeorge.Wilson@Sun.COM 	zprop_register_index(ZPOOL_PROP_READONLY, "readonly", 0,
108*13049SGeorge.Wilson@Sun.COM 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "RDONLY", boolean_table);
1095094Slling 
1105329Sgw25295 	/* default index properties */
11111976STom.Erickson@Sun.COM 	zprop_register_index(ZPOOL_PROP_FAILUREMODE, "failmode",
1125329Sgw25295 	    ZIO_FAILURE_MODE_WAIT, PROP_DEFAULT, ZFS_TYPE_POOL,
1135329Sgw25295 	    "wait | continue | panic", "FAILMODE", failuremode_table);
1145329Sgw25295 
1155094Slling 	/* hidden properties */
11611976STom.Erickson@Sun.COM 	zprop_register_hidden(ZPOOL_PROP_NAME, "name", PROP_TYPE_STRING,
1175094Slling 	    PROP_READONLY, ZFS_TYPE_POOL, "NAME");
1185094Slling }
1195094Slling 
1205094Slling /*
1215094Slling  * Given a property name and its type, returns the corresponding property ID.
1225094Slling  */
1235094Slling zpool_prop_t
zpool_name_to_prop(const char * propname)1245094Slling zpool_name_to_prop(const char *propname)
1255094Slling {
1265094Slling 	return (zprop_name_to_prop(propname, ZFS_TYPE_POOL));
1275094Slling }
1285094Slling 
1295094Slling /*
1305094Slling  * Given a pool property ID, returns the corresponding name.
1315094Slling  * Assuming the pool propety ID is valid.
1325094Slling  */
1335094Slling const char *
zpool_prop_to_name(zpool_prop_t prop)1345094Slling zpool_prop_to_name(zpool_prop_t prop)
1355094Slling {
1365094Slling 	return (zpool_prop_table[prop].pd_name);
1375094Slling }
1385094Slling 
1395094Slling zprop_type_t
zpool_prop_get_type(zpool_prop_t prop)1405094Slling zpool_prop_get_type(zpool_prop_t prop)
1415094Slling {
1425094Slling 	return (zpool_prop_table[prop].pd_proptype);
1435094Slling }
1445094Slling 
1455094Slling boolean_t
zpool_prop_readonly(zpool_prop_t prop)1465094Slling zpool_prop_readonly(zpool_prop_t prop)
1475094Slling {
1485094Slling 	return (zpool_prop_table[prop].pd_attr == PROP_READONLY);
1495094Slling }
1505094Slling 
1515094Slling const char *
zpool_prop_default_string(zpool_prop_t prop)1525094Slling zpool_prop_default_string(zpool_prop_t prop)
1535094Slling {
1545094Slling 	return (zpool_prop_table[prop].pd_strdefault);
1555094Slling }
1565094Slling 
1575094Slling uint64_t
zpool_prop_default_numeric(zpool_prop_t prop)1585094Slling zpool_prop_default_numeric(zpool_prop_t prop)
1595094Slling {
1605094Slling 	return (zpool_prop_table[prop].pd_numdefault);
1615094Slling }
1625094Slling 
1635094Slling int
zpool_prop_string_to_index(zpool_prop_t prop,const char * string,uint64_t * index)1645094Slling zpool_prop_string_to_index(zpool_prop_t prop, const char *string,
1655094Slling     uint64_t *index)
1665094Slling {
1675094Slling 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_POOL));
1685094Slling }
1695094Slling 
1705094Slling int
zpool_prop_index_to_string(zpool_prop_t prop,uint64_t index,const char ** string)1715094Slling zpool_prop_index_to_string(zpool_prop_t prop, uint64_t index,
1725094Slling     const char **string)
1735094Slling {
1745094Slling 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_POOL));
1755094Slling }
1765094Slling 
17710922SJeff.Bonwick@Sun.COM uint64_t
zpool_prop_random_value(zpool_prop_t prop,uint64_t seed)17810922SJeff.Bonwick@Sun.COM zpool_prop_random_value(zpool_prop_t prop, uint64_t seed)
17910922SJeff.Bonwick@Sun.COM {
18010922SJeff.Bonwick@Sun.COM 	return (zprop_random_value(prop, seed, ZFS_TYPE_POOL));
18110922SJeff.Bonwick@Sun.COM }
18210922SJeff.Bonwick@Sun.COM 
1835094Slling #ifndef _KERNEL
1845094Slling 
1855094Slling const char *
zpool_prop_values(zpool_prop_t prop)1865094Slling zpool_prop_values(zpool_prop_t prop)
1875094Slling {
1885094Slling 	return (zpool_prop_table[prop].pd_values);
1895094Slling }
1905094Slling 
1915094Slling const char *
zpool_prop_column_name(zpool_prop_t prop)1925094Slling zpool_prop_column_name(zpool_prop_t prop)
1935094Slling {
1945094Slling 	return (zpool_prop_table[prop].pd_colname);
1955094Slling }
1965094Slling 
1975094Slling boolean_t
zpool_prop_align_right(zpool_prop_t prop)1985094Slling zpool_prop_align_right(zpool_prop_t prop)
1995094Slling {
2005094Slling 	return (zpool_prop_table[prop].pd_rightalign);
2015094Slling }
2025094Slling #endif
203