xref: /titanic_50/usr/src/common/zfs/zpool_prop.c (revision 990b4856d0eaada6f8140335733a1b1771ed2746)
1*990b4856Slling /*
2*990b4856Slling  * CDDL HEADER START
3*990b4856Slling  *
4*990b4856Slling  * The contents of this file are subject to the terms of the
5*990b4856Slling  * Common Development and Distribution License (the "License").
6*990b4856Slling  * You may not use this file except in compliance with the License.
7*990b4856Slling  *
8*990b4856Slling  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*990b4856Slling  * or http://www.opensolaris.org/os/licensing.
10*990b4856Slling  * See the License for the specific language governing permissions
11*990b4856Slling  * and limitations under the License.
12*990b4856Slling  *
13*990b4856Slling  * When distributing Covered Code, include this CDDL HEADER in each
14*990b4856Slling  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*990b4856Slling  * If applicable, add the following below this CDDL HEADER, with the
16*990b4856Slling  * fields enclosed by brackets "[]" replaced with your own identifying
17*990b4856Slling  * information: Portions Copyright [yyyy] [name of copyright owner]
18*990b4856Slling  *
19*990b4856Slling  * CDDL HEADER END
20*990b4856Slling  */
21*990b4856Slling /*
22*990b4856Slling  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*990b4856Slling  * Use is subject to license terms.
24*990b4856Slling  */
25*990b4856Slling 
26*990b4856Slling #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*990b4856Slling 
28*990b4856Slling #include <sys/zio.h>
29*990b4856Slling #include <sys/spa.h>
30*990b4856Slling #include <sys/zfs_acl.h>
31*990b4856Slling #include <sys/zfs_ioctl.h>
32*990b4856Slling #include <sys/fs/zfs.h>
33*990b4856Slling 
34*990b4856Slling #include "zfs_prop.h"
35*990b4856Slling 
36*990b4856Slling #if defined(_KERNEL)
37*990b4856Slling #include <sys/systm.h>
38*990b4856Slling #else
39*990b4856Slling #include <stdlib.h>
40*990b4856Slling #include <string.h>
41*990b4856Slling #include <ctype.h>
42*990b4856Slling #endif
43*990b4856Slling 
44*990b4856Slling static zprop_desc_t zpool_prop_table[ZPOOL_NUM_PROPS];
45*990b4856Slling 
46*990b4856Slling zprop_desc_t *
47*990b4856Slling zpool_prop_get_table(void)
48*990b4856Slling {
49*990b4856Slling 	return (zpool_prop_table);
50*990b4856Slling }
51*990b4856Slling 
52*990b4856Slling void
53*990b4856Slling zpool_prop_init(void)
54*990b4856Slling {
55*990b4856Slling 	static zprop_index_t boolean_table[] = {
56*990b4856Slling 		{ "off",	0},
57*990b4856Slling 		{ "on",		1},
58*990b4856Slling 		{ NULL }
59*990b4856Slling 	};
60*990b4856Slling 
61*990b4856Slling 	/* string properties */
62*990b4856Slling 	register_string(ZPOOL_PROP_ALTROOT, "altroot", NULL, PROP_DEFAULT,
63*990b4856Slling 	    ZFS_TYPE_POOL, "<path>", "ALTROOT");
64*990b4856Slling 	register_string(ZPOOL_PROP_BOOTFS, "bootfs", NULL, PROP_DEFAULT,
65*990b4856Slling 	    ZFS_TYPE_POOL, "<filesystem>", "BOOTFS");
66*990b4856Slling 
67*990b4856Slling 	/* readonly number properties */
68*990b4856Slling 	register_number(ZPOOL_PROP_SIZE, "size", 0, PROP_READONLY,
69*990b4856Slling 	    ZFS_TYPE_POOL, "<size>", "SIZE");
70*990b4856Slling 	register_number(ZPOOL_PROP_USED, "used", 0, PROP_READONLY,
71*990b4856Slling 	    ZFS_TYPE_POOL, "<size>", "USED");
72*990b4856Slling 	register_number(ZPOOL_PROP_AVAILABLE, "available", 0, PROP_READONLY,
73*990b4856Slling 	    ZFS_TYPE_POOL, "<size>", "AVAIL");
74*990b4856Slling 	register_number(ZPOOL_PROP_CAPACITY, "capacity", 0, PROP_READONLY,
75*990b4856Slling 	    ZFS_TYPE_POOL, "<size>", "CAP");
76*990b4856Slling 	register_number(ZPOOL_PROP_GUID, "guid", 0, PROP_READONLY,
77*990b4856Slling 	    ZFS_TYPE_POOL, "<guid>", "GUID");
78*990b4856Slling 	register_number(ZPOOL_PROP_HEALTH, "health", 0, PROP_READONLY,
79*990b4856Slling 	    ZFS_TYPE_POOL, "<state>", "HEALTH");
80*990b4856Slling 
81*990b4856Slling 	/* default number properties */
82*990b4856Slling 	register_number(ZPOOL_PROP_VERSION, "version", SPA_VERSION,
83*990b4856Slling 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<version>", "VERSION");
84*990b4856Slling 
85*990b4856Slling 	/* default index (boolean) properties */
86*990b4856Slling 	register_index(ZPOOL_PROP_DELEGATION, "delegation", 1, PROP_DEFAULT,
87*990b4856Slling 	    ZFS_TYPE_POOL, "on | off", "DELEGATION", boolean_table);
88*990b4856Slling 	register_index(ZPOOL_PROP_AUTOREPLACE, "autoreplace", 0, PROP_DEFAULT,
89*990b4856Slling 	    ZFS_TYPE_POOL, "on | off", "REPLACE", boolean_table);
90*990b4856Slling 	register_index(ZPOOL_PROP_TEMPORARY, "temporary", 0, PROP_DEFAULT,
91*990b4856Slling 	    ZFS_TYPE_POOL, "on | off", "TEMP", boolean_table);
92*990b4856Slling 
93*990b4856Slling 	/* hidden properties */
94*990b4856Slling 	register_hidden(ZPOOL_PROP_NAME, "name", PROP_TYPE_STRING,
95*990b4856Slling 	    PROP_READONLY, ZFS_TYPE_POOL, "NAME");
96*990b4856Slling }
97*990b4856Slling 
98*990b4856Slling /*
99*990b4856Slling  * Given a property name and its type, returns the corresponding property ID.
100*990b4856Slling  */
101*990b4856Slling zpool_prop_t
102*990b4856Slling zpool_name_to_prop(const char *propname)
103*990b4856Slling {
104*990b4856Slling 	return (zprop_name_to_prop(propname, ZFS_TYPE_POOL));
105*990b4856Slling }
106*990b4856Slling 
107*990b4856Slling /*
108*990b4856Slling  * Given a pool property ID, returns the corresponding name.
109*990b4856Slling  * Assuming the pool propety ID is valid.
110*990b4856Slling  */
111*990b4856Slling const char *
112*990b4856Slling zpool_prop_to_name(zpool_prop_t prop)
113*990b4856Slling {
114*990b4856Slling 	return (zpool_prop_table[prop].pd_name);
115*990b4856Slling }
116*990b4856Slling 
117*990b4856Slling zprop_type_t
118*990b4856Slling zpool_prop_get_type(zpool_prop_t prop)
119*990b4856Slling {
120*990b4856Slling 	return (zpool_prop_table[prop].pd_proptype);
121*990b4856Slling }
122*990b4856Slling 
123*990b4856Slling boolean_t
124*990b4856Slling zpool_prop_readonly(zpool_prop_t prop)
125*990b4856Slling {
126*990b4856Slling 	return (zpool_prop_table[prop].pd_attr == PROP_READONLY);
127*990b4856Slling }
128*990b4856Slling 
129*990b4856Slling const char *
130*990b4856Slling zpool_prop_default_string(zpool_prop_t prop)
131*990b4856Slling {
132*990b4856Slling 	return (zpool_prop_table[prop].pd_strdefault);
133*990b4856Slling }
134*990b4856Slling 
135*990b4856Slling uint64_t
136*990b4856Slling zpool_prop_default_numeric(zpool_prop_t prop)
137*990b4856Slling {
138*990b4856Slling 	return (zpool_prop_table[prop].pd_numdefault);
139*990b4856Slling }
140*990b4856Slling 
141*990b4856Slling int
142*990b4856Slling zpool_prop_string_to_index(zpool_prop_t prop, const char *string,
143*990b4856Slling     uint64_t *index)
144*990b4856Slling {
145*990b4856Slling 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_POOL));
146*990b4856Slling }
147*990b4856Slling 
148*990b4856Slling int
149*990b4856Slling zpool_prop_index_to_string(zpool_prop_t prop, uint64_t index,
150*990b4856Slling     const char **string)
151*990b4856Slling {
152*990b4856Slling 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_POOL));
153*990b4856Slling }
154*990b4856Slling 
155*990b4856Slling #ifndef _KERNEL
156*990b4856Slling 
157*990b4856Slling const char *
158*990b4856Slling zpool_prop_values(zpool_prop_t prop)
159*990b4856Slling {
160*990b4856Slling 	return (zpool_prop_table[prop].pd_values);
161*990b4856Slling }
162*990b4856Slling 
163*990b4856Slling const char *
164*990b4856Slling zpool_prop_column_name(zpool_prop_t prop)
165*990b4856Slling {
166*990b4856Slling 	return (zpool_prop_table[prop].pd_colname);
167*990b4856Slling }
168*990b4856Slling 
169*990b4856Slling boolean_t
170*990b4856Slling zpool_prop_align_right(zpool_prop_t prop)
171*990b4856Slling {
172*990b4856Slling 	return (zpool_prop_table[prop].pd_rightalign);
173*990b4856Slling }
174*990b4856Slling #endif
175