xref: /illumos-gate/usr/src/common/zfs/zpool_prop.c (revision b24ab6762772a3f6a89393947930c7fa61306783)
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 /*
22573ca77eSGeorge Wilson  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23990b4856Slling  * Use is subject to license terms.
24990b4856Slling  */
25990b4856Slling 
26990b4856Slling #include <sys/zio.h>
27990b4856Slling #include <sys/spa.h>
28990b4856Slling #include <sys/zfs_acl.h>
29990b4856Slling #include <sys/zfs_ioctl.h>
30990b4856Slling #include <sys/fs/zfs.h>
31990b4856Slling 
32990b4856Slling #include "zfs_prop.h"
33990b4856Slling 
34990b4856Slling #if defined(_KERNEL)
35990b4856Slling #include <sys/systm.h>
36990b4856Slling #else
37990b4856Slling #include <stdlib.h>
38990b4856Slling #include <string.h>
39990b4856Slling #include <ctype.h>
40990b4856Slling #endif
41990b4856Slling 
42990b4856Slling static zprop_desc_t zpool_prop_table[ZPOOL_NUM_PROPS];
43990b4856Slling 
44990b4856Slling zprop_desc_t *
45990b4856Slling zpool_prop_get_table(void)
46990b4856Slling {
47990b4856Slling 	return (zpool_prop_table);
48990b4856Slling }
49990b4856Slling 
50990b4856Slling void
51990b4856Slling zpool_prop_init(void)
52990b4856Slling {
53990b4856Slling 	static zprop_index_t boolean_table[] = {
54990b4856Slling 		{ "off",	0},
55990b4856Slling 		{ "on",		1},
56990b4856Slling 		{ NULL }
57990b4856Slling 	};
58990b4856Slling 
590a4e9518Sgw 	static zprop_index_t failuremode_table[] = {
600a4e9518Sgw 		{ "wait",	ZIO_FAILURE_MODE_WAIT },
610a4e9518Sgw 		{ "continue",	ZIO_FAILURE_MODE_CONTINUE },
620a4e9518Sgw 		{ "panic",	ZIO_FAILURE_MODE_PANIC },
630a4e9518Sgw 		{ NULL }
640a4e9518Sgw 	};
650a4e9518Sgw 
66990b4856Slling 	/* string properties */
67990b4856Slling 	register_string(ZPOOL_PROP_ALTROOT, "altroot", NULL, PROP_DEFAULT,
68990b4856Slling 	    ZFS_TYPE_POOL, "<path>", "ALTROOT");
69990b4856Slling 	register_string(ZPOOL_PROP_BOOTFS, "bootfs", NULL, PROP_DEFAULT,
70990b4856Slling 	    ZFS_TYPE_POOL, "<filesystem>", "BOOTFS");
712f8aaab3Seschrock 	register_string(ZPOOL_PROP_CACHEFILE, "cachefile", NULL, PROP_DEFAULT,
72c6765aabSeschrock 	    ZFS_TYPE_POOL, "<file> | none", "CACHEFILE");
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");
87*b24ab676SJeff Bonwick 	register_number(ZPOOL_PROP_DEDUPRATIO, "dedupratio", 0, PROP_READONLY,
88*b24ab676SJeff Bonwick 	    ZFS_TYPE_POOL, "<1.00x or higher if deduped>", "DEDUP");
89990b4856Slling 
90990b4856Slling 	/* default number properties */
91990b4856Slling 	register_number(ZPOOL_PROP_VERSION, "version", SPA_VERSION,
92990b4856Slling 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<version>", "VERSION");
93990b4856Slling 
94990b4856Slling 	/* default index (boolean) properties */
95990b4856Slling 	register_index(ZPOOL_PROP_DELEGATION, "delegation", 1, PROP_DEFAULT,
96990b4856Slling 	    ZFS_TYPE_POOL, "on | off", "DELEGATION", boolean_table);
97990b4856Slling 	register_index(ZPOOL_PROP_AUTOREPLACE, "autoreplace", 0, PROP_DEFAULT,
98990b4856Slling 	    ZFS_TYPE_POOL, "on | off", "REPLACE", boolean_table);
99d5b5bb25SRich Morris 	register_index(ZPOOL_PROP_LISTSNAPS, "listsnapshots", 0, PROP_DEFAULT,
100d5b5bb25SRich Morris 	    ZFS_TYPE_POOL, "on | off", "LISTSNAPS", boolean_table);
101573ca77eSGeorge Wilson 	register_index(ZPOOL_PROP_AUTOEXPAND, "autoexpand", 0, PROP_DEFAULT,
102573ca77eSGeorge Wilson 	    ZFS_TYPE_POOL, "on | off", "EXPAND", boolean_table);
103990b4856Slling 
1040a4e9518Sgw 	/* default index properties */
1050a4e9518Sgw 	register_index(ZPOOL_PROP_FAILUREMODE, "failmode",
1060a4e9518Sgw 	    ZIO_FAILURE_MODE_WAIT, PROP_DEFAULT, ZFS_TYPE_POOL,
1070a4e9518Sgw 	    "wait | continue | panic", "FAILMODE", failuremode_table);
1080a4e9518Sgw 
109990b4856Slling 	/* hidden properties */
110990b4856Slling 	register_hidden(ZPOOL_PROP_NAME, "name", PROP_TYPE_STRING,
111990b4856Slling 	    PROP_READONLY, ZFS_TYPE_POOL, "NAME");
112*b24ab676SJeff Bonwick 	register_hidden(ZPOOL_PROP_DEDUPDITTO, "dedupditto", PROP_TYPE_NUMBER,
113*b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_POOL, "DEDUPDITTO");
114990b4856Slling }
115990b4856Slling 
116990b4856Slling /*
117990b4856Slling  * Given a property name and its type, returns the corresponding property ID.
118990b4856Slling  */
119990b4856Slling zpool_prop_t
120990b4856Slling zpool_name_to_prop(const char *propname)
121990b4856Slling {
122990b4856Slling 	return (zprop_name_to_prop(propname, ZFS_TYPE_POOL));
123990b4856Slling }
124990b4856Slling 
125990b4856Slling /*
126990b4856Slling  * Given a pool property ID, returns the corresponding name.
127990b4856Slling  * Assuming the pool propety ID is valid.
128990b4856Slling  */
129990b4856Slling const char *
130990b4856Slling zpool_prop_to_name(zpool_prop_t prop)
131990b4856Slling {
132990b4856Slling 	return (zpool_prop_table[prop].pd_name);
133990b4856Slling }
134990b4856Slling 
135990b4856Slling zprop_type_t
136990b4856Slling zpool_prop_get_type(zpool_prop_t prop)
137990b4856Slling {
138990b4856Slling 	return (zpool_prop_table[prop].pd_proptype);
139990b4856Slling }
140990b4856Slling 
141990b4856Slling boolean_t
142990b4856Slling zpool_prop_readonly(zpool_prop_t prop)
143990b4856Slling {
144990b4856Slling 	return (zpool_prop_table[prop].pd_attr == PROP_READONLY);
145990b4856Slling }
146990b4856Slling 
147990b4856Slling const char *
148990b4856Slling zpool_prop_default_string(zpool_prop_t prop)
149990b4856Slling {
150990b4856Slling 	return (zpool_prop_table[prop].pd_strdefault);
151990b4856Slling }
152990b4856Slling 
153990b4856Slling uint64_t
154990b4856Slling zpool_prop_default_numeric(zpool_prop_t prop)
155990b4856Slling {
156990b4856Slling 	return (zpool_prop_table[prop].pd_numdefault);
157990b4856Slling }
158990b4856Slling 
159990b4856Slling int
160990b4856Slling zpool_prop_string_to_index(zpool_prop_t prop, const char *string,
161990b4856Slling     uint64_t *index)
162990b4856Slling {
163990b4856Slling 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_POOL));
164990b4856Slling }
165990b4856Slling 
166990b4856Slling int
167990b4856Slling zpool_prop_index_to_string(zpool_prop_t prop, uint64_t index,
168990b4856Slling     const char **string)
169990b4856Slling {
170990b4856Slling 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_POOL));
171990b4856Slling }
172990b4856Slling 
173*b24ab676SJeff Bonwick uint64_t
174*b24ab676SJeff Bonwick zpool_prop_random_value(zpool_prop_t prop, uint64_t seed)
175*b24ab676SJeff Bonwick {
176*b24ab676SJeff Bonwick 	return (zprop_random_value(prop, seed, ZFS_TYPE_POOL));
177*b24ab676SJeff Bonwick }
178*b24ab676SJeff Bonwick 
179990b4856Slling #ifndef _KERNEL
180990b4856Slling 
181990b4856Slling const char *
182990b4856Slling zpool_prop_values(zpool_prop_t prop)
183990b4856Slling {
184990b4856Slling 	return (zpool_prop_table[prop].pd_values);
185990b4856Slling }
186990b4856Slling 
187990b4856Slling const char *
188990b4856Slling zpool_prop_column_name(zpool_prop_t prop)
189990b4856Slling {
190990b4856Slling 	return (zpool_prop_table[prop].pd_colname);
191990b4856Slling }
192990b4856Slling 
193990b4856Slling boolean_t
194990b4856Slling zpool_prop_align_right(zpool_prop_t prop)
195990b4856Slling {
196990b4856Slling 	return (zpool_prop_table[prop].pd_rightalign);
197990b4856Slling }
198990b4856Slling #endif
199