1990b485lling/*
2990b485lling * CDDL HEADER START
3990b485lling *
4990b485lling * The contents of this file are subject to the terms of the
5990b485lling * Common Development and Distribution License (the "License").
6990b485lling * You may not use this file except in compliance with the License.
7990b485lling *
8990b485lling * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9990b485lling * or http://www.opensolaris.org/os/licensing.
10990b485lling * See the License for the specific language governing permissions
11990b485lling * and limitations under the License.
12990b485lling *
13990b485lling * When distributing Covered Code, include this CDDL HEADER in each
14990b485lling * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15990b485lling * If applicable, add the following below this CDDL HEADER, with the
16990b485lling * fields enclosed by brackets "[]" replaced with your own identifying
17990b485lling * information: Portions Copyright [yyyy] [name of copyright owner]
18990b485lling *
19990b485lling * CDDL HEADER END
20990b485lling */
21990b485lling/*
22f9af39bGeorge Wilson * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
238704186Dan McDonald * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
248671400Serapheim Dimitropoulos * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
25c3d26abMatthew Ahrens * Copyright (c) 2014 Integros [integros.com]
26990b485lling */
27990b485lling
28990b485lling#include <sys/zio.h>
29990b485lling#include <sys/spa.h>
30990b485lling#include <sys/zfs_acl.h>
31990b485lling#include <sys/zfs_ioctl.h>
32990b485lling#include <sys/fs/zfs.h>
33990b485lling
34990b485lling#include "zfs_prop.h"
35990b485lling
36990b485lling#if defined(_KERNEL)
37990b485lling#include <sys/systm.h>
38990b485lling#else
39990b485lling#include <stdlib.h>
40990b485lling#include <string.h>
41990b485lling#include <ctype.h>
42990b485lling#endif
43990b485lling
44990b485llingstatic zprop_desc_t zpool_prop_table[ZPOOL_NUM_PROPS];
45990b485lling
46990b485llingzprop_desc_t *
47990b485llingzpool_prop_get_table(void)
48990b485lling{
49990b485lling	return (zpool_prop_table);
50990b485lling}
51990b485lling
52990b485llingvoid
53990b485llingzpool_prop_init(void)
54990b485lling{
55990b485lling	static zprop_index_t boolean_table[] = {
56990b485lling		{ "off",	0},
57990b485lling		{ "on",		1},
58990b485lling		{ NULL }
59990b485lling	};
60990b485lling
610a4e951gw	static zprop_index_t failuremode_table[] = {
620a4e951gw		{ "wait",	ZIO_FAILURE_MODE_WAIT },
630a4e951gw		{ "continue",	ZIO_FAILURE_MODE_CONTINUE },
640a4e951gw		{ "panic",	ZIO_FAILURE_MODE_PANIC },
650a4e951gw		{ NULL }
660a4e951gw	};
670a4e951gw
68990b485lling	/* string properties */
6983d7f9fTom Erickson	zprop_register_string(ZPOOL_PROP_ALTROOT, "altroot", NULL, PROP_DEFAULT,
70990b485lling	    ZFS_TYPE_POOL, "<path>", "ALTROOT");
7183d7f9fTom Erickson	zprop_register_string(ZPOOL_PROP_BOOTFS, "bootfs", NULL, PROP_DEFAULT,
72990b485lling	    ZFS_TYPE_POOL, "<filesystem>", "BOOTFS");
7383d7f9fTom Erickson	zprop_register_string(ZPOOL_PROP_CACHEFILE, "cachefile", NULL,
7483d7f9fTom Erickson	    PROP_DEFAULT, ZFS_TYPE_POOL, "<file> | none", "CACHEFILE");
758704186Dan McDonald	zprop_register_string(ZPOOL_PROP_COMMENT, "comment", NULL,
768704186Dan McDonald	    PROP_DEFAULT, ZFS_TYPE_POOL, "<comment-string>", "COMMENT");
77990b485lling
78990b485lling	/* readonly number properties */
7983d7f9fTom Erickson	zprop_register_number(ZPOOL_PROP_SIZE, "size", 0, PROP_READONLY,
80990b485lling	    ZFS_TYPE_POOL, "<size>", "SIZE");
8183d7f9fTom Erickson	zprop_register_number(ZPOOL_PROP_FREE, "free", 0, PROP_READONLY,
82485bbbfGeorge Wilson	    ZFS_TYPE_POOL, "<size>", "FREE");
83ad135b5Christopher Siden	zprop_register_number(ZPOOL_PROP_FREEING, "freeing", 0, PROP_READONLY,
84ad135b5Christopher Siden	    ZFS_TYPE_POOL, "<size>", "FREEING");
858671400Serapheim Dimitropoulos	zprop_register_number(ZPOOL_PROP_CHECKPOINT, "checkpoint", 0,
868671400Serapheim Dimitropoulos	    PROP_READONLY, ZFS_TYPE_POOL, "<size>", "CKPOINT");
877fd05acMatthew Ahrens	zprop_register_number(ZPOOL_PROP_LEAKED, "leaked", 0, PROP_READONLY,
887fd05acMatthew Ahrens	    ZFS_TYPE_POOL, "<size>", "LEAKED");
8983d7f9fTom Erickson	zprop_register_number(ZPOOL_PROP_ALLOCATED, "allocated", 0,
9083d7f9fTom Erickson	    PROP_READONLY, ZFS_TYPE_POOL, "<size>", "ALLOC");
914263d13George Wilson	zprop_register_number(ZPOOL_PROP_EXPANDSZ, "expandsize", 0,
924263d13George Wilson	    PROP_READONLY, ZFS_TYPE_POOL, "<size>", "EXPANDSZ");
932e4c998George Wilson	zprop_register_number(ZPOOL_PROP_FRAGMENTATION, "fragmentation", 0,
942e4c998George Wilson	    PROP_READONLY, ZFS_TYPE_POOL, "<percent>", "FRAG");
9583d7f9fTom Erickson	zprop_register_number(ZPOOL_PROP_CAPACITY, "capacity", 0, PROP_READONLY,
96990b485lling	    ZFS_TYPE_POOL, "<size>", "CAP");
9783d7f9fTom Erickson	zprop_register_number(ZPOOL_PROP_GUID, "guid", 0, PROP_READONLY,
98990b485lling	    ZFS_TYPE_POOL, "<guid>", "GUID");
9983d7f9fTom Erickson	zprop_register_number(ZPOOL_PROP_HEALTH, "health", 0, PROP_READONLY,
100990b485lling	    ZFS_TYPE_POOL, "<state>", "HEALTH");
10183d7f9fTom Erickson	zprop_register_number(ZPOOL_PROP_DEDUPRATIO, "dedupratio", 0,
10283d7f9fTom Erickson	    PROP_READONLY, ZFS_TYPE_POOL, "<1.00x or higher if deduped>",
10383d7f9fTom Erickson	    "DEDUP");
104990b485lling
1057855d95Toomas Soome	/* system partition size */
1067855d95Toomas Soome	zprop_register_number(ZPOOL_PROP_BOOTSIZE, "bootsize", 0, PROP_ONETIME,
1077855d95Toomas Soome	    ZFS_TYPE_POOL, "<size>", "BOOTSIZE");
1087855d95Toomas Soome
109990b485lling	/* default number properties */
11083d7f9fTom Erickson	zprop_register_number(ZPOOL_PROP_VERSION, "version", SPA_VERSION,
111990b485lling	    PROP_DEFAULT, ZFS_TYPE_POOL, "<version>", "VERSION");
11283d7f9fTom Erickson	zprop_register_number(ZPOOL_PROP_DEDUPDITTO, "dedupditto", 0,
113bbfd46cJeff Bonwick	    PROP_DEFAULT, ZFS_TYPE_POOL, "<threshold (min 100)>", "DEDUPDITTO");
1145711d39loli	zprop_register_number(ZPOOL_PROP_ASHIFT, "ashift", 0, PROP_DEFAULT,
1155711d39loli	    ZFS_TYPE_POOL, "<ashift, 9-16, or 0=default>", "ASHIFT");
116990b485lling
117990b485lling	/* default index (boolean) properties */
11883d7f9fTom Erickson	zprop_register_index(ZPOOL_PROP_DELEGATION, "delegation", 1,
11983d7f9fTom Erickson	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "DELEGATION",
12083d7f9fTom Erickson	    boolean_table);
12183d7f9fTom Erickson	zprop_register_index(ZPOOL_PROP_AUTOREPLACE, "autoreplace", 0,
12283d7f9fTom Erickson	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "REPLACE", boolean_table);
12383d7f9fTom Erickson	zprop_register_index(ZPOOL_PROP_LISTSNAPS, "listsnapshots", 0,
12483d7f9fTom Erickson	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "LISTSNAPS",
12583d7f9fTom Erickson	    boolean_table);
12683d7f9fTom Erickson	zprop_register_index(ZPOOL_PROP_AUTOEXPAND, "autoexpand", 0,
12783d7f9fTom Erickson	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "EXPAND", boolean_table);
128f9af39bGeorge Wilson	zprop_register_index(ZPOOL_PROP_READONLY, "readonly", 0,
129f9af39bGeorge Wilson	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "RDONLY", boolean_table);
130e0f1c0aOlaf Faaland	zprop_register_index(ZPOOL_PROP_MULTIHOST, "multihost", 0,
131e0f1c0aOlaf Faaland	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "MULTIHOST",
132e0f1c0aOlaf Faaland	    boolean_table);
133990b485lling
1340a4e951gw	/* default index properties */
13583d7f9fTom Erickson	zprop_register_index(ZPOOL_PROP_FAILUREMODE, "failmode",
1360a4e951gw	    ZIO_FAILURE_MODE_WAIT, PROP_DEFAULT, ZFS_TYPE_POOL,
1370a4e951gw	    "wait | continue | panic", "FAILMODE", failuremode_table);
138084fd14Brian Behlendorf	zprop_register_index(ZPOOL_PROP_AUTOTRIM, "autotrim",
139084fd14Brian Behlendorf	    SPA_AUTOTRIM_OFF, PROP_DEFAULT, ZFS_TYPE_POOL,
140084fd14Brian Behlendorf	    "on | off", "AUTOTRIM", boolean_table);
1410a4e951gw
142990b485lling	/* hidden properties */
14383d7f9fTom Erickson	zprop_register_hidden(ZPOOL_PROP_NAME, "name", PROP_TYPE_STRING,
144990b485lling	    PROP_READONLY, ZFS_TYPE_POOL, "NAME");
145b515258Matthew Ahrens	zprop_register_hidden(ZPOOL_PROP_MAXBLOCKSIZE, "maxblocksize",
146b515258Matthew Ahrens	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_POOL, "MAXBLOCKSIZE");
14704e5635Andriy Gapon	zprop_register_hidden(ZPOOL_PROP_TNAME, "tname", PROP_TYPE_STRING,
14804e5635Andriy Gapon	    PROP_ONETIME, ZFS_TYPE_POOL, "TNAME");
14954811daToomas Soome	zprop_register_hidden(ZPOOL_PROP_MAXDNODESIZE, "maxdnodesize",
15054811daToomas Soome	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_POOL, "MAXDNODESIZE");
151990b485lling}
152990b485lling
153990b485lling/*
154990b485lling * Given a property name and its type, returns the corresponding property ID.
155990b485lling */
156990b485llingzpool_prop_t
157990b485llingzpool_name_to_prop(const char *propname)
158990b485lling{
159990b485lling	return (zprop_name_to_prop(propname, ZFS_TYPE_POOL));
160990b485lling}
161990b485lling
162990b485lling/*
163990b485lling * Given a pool property ID, returns the corresponding name.
164990b485lling * Assuming the pool propety ID is valid.
165990b485lling */
166990b485llingconst char *
167990b485llingzpool_prop_to_name(zpool_prop_t prop)
168990b485lling{
169990b485lling	return (zpool_prop_table[prop].pd_name);
170990b485lling}
171990b485lling
172990b485llingzprop_type_t
173990b485llingzpool_prop_get_type(zpool_prop_t prop)
174990b485lling{
175990b485lling	return (zpool_prop_table[prop].pd_proptype);
176990b485lling}
177990b485lling
178990b485llingboolean_t
179990b485llingzpool_prop_readonly(zpool_prop_t prop)
180990b485lling{
181990b485lling	return (zpool_prop_table[prop].pd_attr == PROP_READONLY);
182990b485lling}
183990b485lling
184990b485llingconst char *
185990b485llingzpool_prop_default_string(zpool_prop_t prop)
186990b485lling{
187990b485lling	return (zpool_prop_table[prop].pd_strdefault);
188990b485lling}
189990b485lling
190990b485llinguint64_t
191990b485llingzpool_prop_default_numeric(zpool_prop_t prop)
192990b485lling{
193990b485lling	return (zpool_prop_table[prop].pd_numdefault);
194990b485lling}
195990b485lling
196ad135b5Christopher Siden/*
197ad135b5Christopher Siden * Returns true if this is a valid feature@ property.
198ad135b5Christopher Siden */
199ad135b5Christopher Sidenboolean_t
200ad135b5Christopher Sidenzpool_prop_feature(const char *name)
201ad135b5Christopher Siden{
202ad135b5Christopher Siden	static const char *prefix = "feature@";
203ad135b5Christopher Siden	return (strncmp(name, prefix, strlen(prefix)) == 0);
204ad135b5Christopher Siden}
205ad135b5Christopher Siden
206ad135b5Christopher Siden/*
207ad135b5Christopher Siden * Returns true if this is a valid unsupported@ property.
208ad135b5Christopher Siden */
209ad135b5Christopher Sidenboolean_t
210ad135b5Christopher Sidenzpool_prop_unsupported(const char *name)
211ad135b5Christopher Siden{
212ad135b5Christopher Siden	static const char *prefix = "unsupported@";
213ad135b5Christopher Siden	return (strncmp(name, prefix, strlen(prefix)) == 0);
214ad135b5Christopher Siden}
215ad135b5Christopher Siden
216990b485llingint
217990b485llingzpool_prop_string_to_index(zpool_prop_t prop, const char *string,
218990b485lling    uint64_t *index)
219990b485lling{
220990b485lling	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_POOL));
221990b485lling}
222990b485lling
223990b485llingint
224990b485llingzpool_prop_index_to_string(zpool_prop_t prop, uint64_t index,
225990b485lling    const char **string)
226990b485lling{
227990b485lling	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_POOL));
228990b485lling}
229990b485lling
230b24ab67Jeff Bonwickuint64_t
231b24ab67Jeff Bonwickzpool_prop_random_value(zpool_prop_t prop, uint64_t seed)
232b24ab67Jeff Bonwick{
233b24ab67Jeff Bonwick	return (zprop_random_value(prop, seed, ZFS_TYPE_POOL));
234b24ab67Jeff Bonwick}
235b24ab67Jeff Bonwick
236990b485lling#ifndef _KERNEL
237990b485lling
238990b485llingconst char *
239990b485llingzpool_prop_values(zpool_prop_t prop)
240990b485lling{
241990b485lling	return (zpool_prop_table[prop].pd_values);
242990b485lling}
243990b485lling
244990b485llingconst char *
245990b485llingzpool_prop_column_name(zpool_prop_t prop)
246990b485lling{
247990b485lling	return (zpool_prop_table[prop].pd_colname);
248990b485lling}
249990b485lling
250990b485llingboolean_t
251990b485llingzpool_prop_align_right(zpool_prop_t prop)
252990b485lling{
253990b485lling	return (zpool_prop_table[prop].pd_rightalign);
254990b485lling}
255990b485lling#endif
256