xref: /illumos-gate/usr/src/common/zfs/zpool_prop.c (revision 8671400134a11c848244896ca51a7db4d0f69da4)
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.
24*86714001SSerapheim Dimitropoulos  * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
25c3d26abcSMatthew Ahrens  * Copyright (c) 2014 Integros [integros.com]
26990b4856Slling  */
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 
610a4e9518Sgw 	static zprop_index_t failuremode_table[] = {
620a4e9518Sgw 		{ "wait",	ZIO_FAILURE_MODE_WAIT },
630a4e9518Sgw 		{ "continue",	ZIO_FAILURE_MODE_CONTINUE },
640a4e9518Sgw 		{ "panic",	ZIO_FAILURE_MODE_PANIC },
650a4e9518Sgw 		{ NULL }
660a4e9518Sgw 	};
670a4e9518Sgw 
68990b4856Slling 	/* string properties */
6983d7f9feSTom Erickson 	zprop_register_string(ZPOOL_PROP_ALTROOT, "altroot", NULL, PROP_DEFAULT,
70990b4856Slling 	    ZFS_TYPE_POOL, "<path>", "ALTROOT");
7183d7f9feSTom Erickson 	zprop_register_string(ZPOOL_PROP_BOOTFS, "bootfs", NULL, PROP_DEFAULT,
72990b4856Slling 	    ZFS_TYPE_POOL, "<filesystem>", "BOOTFS");
7383d7f9feSTom Erickson 	zprop_register_string(ZPOOL_PROP_CACHEFILE, "cachefile", NULL,
7483d7f9feSTom Erickson 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<file> | none", "CACHEFILE");
758704186eSDan McDonald 	zprop_register_string(ZPOOL_PROP_COMMENT, "comment", NULL,
768704186eSDan McDonald 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<comment-string>", "COMMENT");
77990b4856Slling 
78990b4856Slling 	/* readonly number properties */
7983d7f9feSTom Erickson 	zprop_register_number(ZPOOL_PROP_SIZE, "size", 0, PROP_READONLY,
80990b4856Slling 	    ZFS_TYPE_POOL, "<size>", "SIZE");
8183d7f9feSTom Erickson 	zprop_register_number(ZPOOL_PROP_FREE, "free", 0, PROP_READONLY,
82485bbbf5SGeorge Wilson 	    ZFS_TYPE_POOL, "<size>", "FREE");
83ad135b5dSChristopher Siden 	zprop_register_number(ZPOOL_PROP_FREEING, "freeing", 0, PROP_READONLY,
84ad135b5dSChristopher Siden 	    ZFS_TYPE_POOL, "<size>", "FREEING");
85*86714001SSerapheim Dimitropoulos 	zprop_register_number(ZPOOL_PROP_CHECKPOINT, "checkpoint", 0,
86*86714001SSerapheim Dimitropoulos 	    PROP_READONLY, ZFS_TYPE_POOL, "<size>", "CKPOINT");
877fd05ac4SMatthew Ahrens 	zprop_register_number(ZPOOL_PROP_LEAKED, "leaked", 0, PROP_READONLY,
887fd05ac4SMatthew Ahrens 	    ZFS_TYPE_POOL, "<size>", "LEAKED");
8983d7f9feSTom Erickson 	zprop_register_number(ZPOOL_PROP_ALLOCATED, "allocated", 0,
9083d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_POOL, "<size>", "ALLOC");
914263d13fSGeorge Wilson 	zprop_register_number(ZPOOL_PROP_EXPANDSZ, "expandsize", 0,
924263d13fSGeorge Wilson 	    PROP_READONLY, ZFS_TYPE_POOL, "<size>", "EXPANDSZ");
932e4c9986SGeorge Wilson 	zprop_register_number(ZPOOL_PROP_FRAGMENTATION, "fragmentation", 0,
942e4c9986SGeorge Wilson 	    PROP_READONLY, ZFS_TYPE_POOL, "<percent>", "FRAG");
9583d7f9feSTom Erickson 	zprop_register_number(ZPOOL_PROP_CAPACITY, "capacity", 0, PROP_READONLY,
96990b4856Slling 	    ZFS_TYPE_POOL, "<size>", "CAP");
9783d7f9feSTom Erickson 	zprop_register_number(ZPOOL_PROP_GUID, "guid", 0, PROP_READONLY,
98990b4856Slling 	    ZFS_TYPE_POOL, "<guid>", "GUID");
9983d7f9feSTom Erickson 	zprop_register_number(ZPOOL_PROP_HEALTH, "health", 0, PROP_READONLY,
100990b4856Slling 	    ZFS_TYPE_POOL, "<state>", "HEALTH");
10183d7f9feSTom Erickson 	zprop_register_number(ZPOOL_PROP_DEDUPRATIO, "dedupratio", 0,
10283d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_POOL, "<1.00x or higher if deduped>",
10383d7f9feSTom Erickson 	    "DEDUP");
104990b4856Slling 
1057855d95bSToomas Soome 	/* system partition size */
1067855d95bSToomas Soome 	zprop_register_number(ZPOOL_PROP_BOOTSIZE, "bootsize", 0, PROP_ONETIME,
1077855d95bSToomas Soome 	    ZFS_TYPE_POOL, "<size>", "BOOTSIZE");
1087855d95bSToomas Soome 
109990b4856Slling 	/* default number properties */
11083d7f9feSTom Erickson 	zprop_register_number(ZPOOL_PROP_VERSION, "version", SPA_VERSION,
111990b4856Slling 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<version>", "VERSION");
11283d7f9feSTom Erickson 	zprop_register_number(ZPOOL_PROP_DEDUPDITTO, "dedupditto", 0,
113bbfd46c4SJeff Bonwick 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<threshold (min 100)>", "DEDUPDITTO");
114990b4856Slling 
115990b4856Slling 	/* default index (boolean) properties */
11683d7f9feSTom Erickson 	zprop_register_index(ZPOOL_PROP_DELEGATION, "delegation", 1,
11783d7f9feSTom Erickson 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "DELEGATION",
11883d7f9feSTom Erickson 	    boolean_table);
11983d7f9feSTom Erickson 	zprop_register_index(ZPOOL_PROP_AUTOREPLACE, "autoreplace", 0,
12083d7f9feSTom Erickson 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "REPLACE", boolean_table);
12183d7f9feSTom Erickson 	zprop_register_index(ZPOOL_PROP_LISTSNAPS, "listsnapshots", 0,
12283d7f9feSTom Erickson 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "LISTSNAPS",
12383d7f9feSTom Erickson 	    boolean_table);
12483d7f9feSTom Erickson 	zprop_register_index(ZPOOL_PROP_AUTOEXPAND, "autoexpand", 0,
12583d7f9feSTom Erickson 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "EXPAND", boolean_table);
126f9af39baSGeorge Wilson 	zprop_register_index(ZPOOL_PROP_READONLY, "readonly", 0,
127f9af39baSGeorge Wilson 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "RDONLY", boolean_table);
128990b4856Slling 
1290a4e9518Sgw 	/* default index properties */
13083d7f9feSTom Erickson 	zprop_register_index(ZPOOL_PROP_FAILUREMODE, "failmode",
1310a4e9518Sgw 	    ZIO_FAILURE_MODE_WAIT, PROP_DEFAULT, ZFS_TYPE_POOL,
1320a4e9518Sgw 	    "wait | continue | panic", "FAILMODE", failuremode_table);
1330a4e9518Sgw 
134990b4856Slling 	/* hidden properties */
13583d7f9feSTom Erickson 	zprop_register_hidden(ZPOOL_PROP_NAME, "name", PROP_TYPE_STRING,
136990b4856Slling 	    PROP_READONLY, ZFS_TYPE_POOL, "NAME");
137b5152584SMatthew Ahrens 	zprop_register_hidden(ZPOOL_PROP_MAXBLOCKSIZE, "maxblocksize",
138b5152584SMatthew Ahrens 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_POOL, "MAXBLOCKSIZE");
139990b4856Slling }
140990b4856Slling 
141990b4856Slling /*
142990b4856Slling  * Given a property name and its type, returns the corresponding property ID.
143990b4856Slling  */
144990b4856Slling zpool_prop_t
145990b4856Slling zpool_name_to_prop(const char *propname)
146990b4856Slling {
147990b4856Slling 	return (zprop_name_to_prop(propname, ZFS_TYPE_POOL));
148990b4856Slling }
149990b4856Slling 
150990b4856Slling /*
151990b4856Slling  * Given a pool property ID, returns the corresponding name.
152990b4856Slling  * Assuming the pool propety ID is valid.
153990b4856Slling  */
154990b4856Slling const char *
155990b4856Slling zpool_prop_to_name(zpool_prop_t prop)
156990b4856Slling {
157990b4856Slling 	return (zpool_prop_table[prop].pd_name);
158990b4856Slling }
159990b4856Slling 
160990b4856Slling zprop_type_t
161990b4856Slling zpool_prop_get_type(zpool_prop_t prop)
162990b4856Slling {
163990b4856Slling 	return (zpool_prop_table[prop].pd_proptype);
164990b4856Slling }
165990b4856Slling 
166990b4856Slling boolean_t
167990b4856Slling zpool_prop_readonly(zpool_prop_t prop)
168990b4856Slling {
169990b4856Slling 	return (zpool_prop_table[prop].pd_attr == PROP_READONLY);
170990b4856Slling }
171990b4856Slling 
172990b4856Slling const char *
173990b4856Slling zpool_prop_default_string(zpool_prop_t prop)
174990b4856Slling {
175990b4856Slling 	return (zpool_prop_table[prop].pd_strdefault);
176990b4856Slling }
177990b4856Slling 
178990b4856Slling uint64_t
179990b4856Slling zpool_prop_default_numeric(zpool_prop_t prop)
180990b4856Slling {
181990b4856Slling 	return (zpool_prop_table[prop].pd_numdefault);
182990b4856Slling }
183990b4856Slling 
184ad135b5dSChristopher Siden /*
185ad135b5dSChristopher Siden  * Returns true if this is a valid feature@ property.
186ad135b5dSChristopher Siden  */
187ad135b5dSChristopher Siden boolean_t
188ad135b5dSChristopher Siden zpool_prop_feature(const char *name)
189ad135b5dSChristopher Siden {
190ad135b5dSChristopher Siden 	static const char *prefix = "feature@";
191ad135b5dSChristopher Siden 	return (strncmp(name, prefix, strlen(prefix)) == 0);
192ad135b5dSChristopher Siden }
193ad135b5dSChristopher Siden 
194ad135b5dSChristopher Siden /*
195ad135b5dSChristopher Siden  * Returns true if this is a valid unsupported@ property.
196ad135b5dSChristopher Siden  */
197ad135b5dSChristopher Siden boolean_t
198ad135b5dSChristopher Siden zpool_prop_unsupported(const char *name)
199ad135b5dSChristopher Siden {
200ad135b5dSChristopher Siden 	static const char *prefix = "unsupported@";
201ad135b5dSChristopher Siden 	return (strncmp(name, prefix, strlen(prefix)) == 0);
202ad135b5dSChristopher Siden }
203ad135b5dSChristopher Siden 
204990b4856Slling int
205990b4856Slling zpool_prop_string_to_index(zpool_prop_t prop, const char *string,
206990b4856Slling     uint64_t *index)
207990b4856Slling {
208990b4856Slling 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_POOL));
209990b4856Slling }
210990b4856Slling 
211990b4856Slling int
212990b4856Slling zpool_prop_index_to_string(zpool_prop_t prop, uint64_t index,
213990b4856Slling     const char **string)
214990b4856Slling {
215990b4856Slling 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_POOL));
216990b4856Slling }
217990b4856Slling 
218b24ab676SJeff Bonwick uint64_t
219b24ab676SJeff Bonwick zpool_prop_random_value(zpool_prop_t prop, uint64_t seed)
220b24ab676SJeff Bonwick {
221b24ab676SJeff Bonwick 	return (zprop_random_value(prop, seed, ZFS_TYPE_POOL));
222b24ab676SJeff Bonwick }
223b24ab676SJeff Bonwick 
224990b4856Slling #ifndef _KERNEL
225990b4856Slling 
226990b4856Slling const char *
227990b4856Slling zpool_prop_values(zpool_prop_t prop)
228990b4856Slling {
229990b4856Slling 	return (zpool_prop_table[prop].pd_values);
230990b4856Slling }
231990b4856Slling 
232990b4856Slling const char *
233990b4856Slling zpool_prop_column_name(zpool_prop_t prop)
234990b4856Slling {
235990b4856Slling 	return (zpool_prop_table[prop].pd_colname);
236990b4856Slling }
237990b4856Slling 
238990b4856Slling boolean_t
239990b4856Slling zpool_prop_align_right(zpool_prop_t prop)
240990b4856Slling {
241990b4856Slling 	return (zpool_prop_table[prop].pd_rightalign);
242990b4856Slling }
243990b4856Slling #endif
244