1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
23 */
24
25 #include <sys/zio.h>
26 #include <sys/spa.h>
27 #include <sys/zfs_ioctl.h>
28 #include <sys/fs/zfs.h>
29
30 #include "zfs_prop.h"
31
32 #if defined(_KERNEL)
33 #include <sys/systm.h>
34 #else
35 #include <stdlib.h>
36 #include <string.h>
37 #include <ctype.h>
38 #endif
39
40 static zprop_desc_t cos_prop_table[COS_NUM_PROPS];
41
42 zprop_desc_t *
43 cos_prop_get_table(void)
44 {
45 return (cos_prop_table);
46 }
47
48 void
49 cos_prop_init(void)
50 {
51 zprop_register_number(COS_PROP_GUID, "cosguid", 0, PROP_READONLY,
52 ZFS_TYPE_COS, "<cos guid>", "COSGUID");
53
54 /* string properties */
55 zprop_register_string(COS_PROP_NAME, "cosname", NULL, PROP_DEFAULT,
56 ZFS_TYPE_COS, "<cos user defined name>", "COSNAME");
57
58 /* default number properties */
59 zprop_register_number(COS_PROP_PREFERRED_READ, "prefread", 0,
60 PROP_DEFAULT, ZFS_TYPE_COS, "<preferred read (0..100)>",
61 "PREFREAD");
62 zprop_register_number(COS_PROP_READ_MINACTIVE, "read_minactive", 0,
63 PROP_DEFAULT, ZFS_TYPE_COS, "<read min active (0..1000)>",
64 "READ_MINACTIVE");
65 zprop_register_number(COS_PROP_READ_MAXACTIVE, "read_maxactive", 0,
66 PROP_DEFAULT, ZFS_TYPE_COS, "<read max active (0..1000)>",
67 "READ_MAXACTIVE");
68 zprop_register_number(COS_PROP_AREAD_MINACTIVE, "aread_minactive", 0,
69 PROP_DEFAULT, ZFS_TYPE_COS, "<async read min active (0..1000)>",
70 "AREAD_MINACTIVE");
71 zprop_register_number(COS_PROP_AREAD_MAXACTIVE, "aread_maxactive", 0,
72 PROP_DEFAULT, ZFS_TYPE_COS, "<async read max active (0..1000)>",
73 "AREAD_MAXACTIVE");
74 zprop_register_number(COS_PROP_WRITE_MINACTIVE, "write_minactive", 0,
75 PROP_DEFAULT, ZFS_TYPE_COS, "<write min active (0..1000)>",
76 "WRITE_MINACTIVE");
77 zprop_register_number(COS_PROP_WRITE_MAXACTIVE, "write_maxactive", 0,
78 PROP_DEFAULT, ZFS_TYPE_COS, "<write max active (0..1000)>",
79 "WRITE_MAXACTIVE");
80 zprop_register_number(COS_PROP_AWRITE_MINACTIVE, "awrite_minactive", 0,
81 PROP_DEFAULT, ZFS_TYPE_COS, "<async write min active (0..1000)>",
82 "AWRITE_MINACTIVE");
83 zprop_register_number(COS_PROP_AWRITE_MAXACTIVE, "awrite_maxactive", 0,
84 PROP_DEFAULT, ZFS_TYPE_COS, "<async write max active (0..1000)>",
85 "AWRITE_MAXACTIVE");
86 zprop_register_number(COS_PROP_SCRUB_MINACTIVE, "scrub_minactive", 0,
87 PROP_DEFAULT, ZFS_TYPE_COS, "<scrub min active (0..1000)>",
88 "SCRUB_MINACTIVE");
89 zprop_register_number(COS_PROP_SCRUB_MAXACTIVE, "scrub_maxactive", 0,
90 PROP_DEFAULT, ZFS_TYPE_COS, "<scrub max active (0..1000)>",
91 "SCRUB_MAXACTIVE");
92 zprop_register_number(COS_PROP_RESILVER_MINACTIVE, "resilver_minactive", 0,
93 PROP_DEFAULT, ZFS_TYPE_COS, "<resilver min active (0..1000)>",
94 "RESILVER_MINACTIVE");
95 zprop_register_number(COS_PROP_RESILVER_MAXACTIVE, "resilver_maxactive", 0,
96 PROP_DEFAULT, ZFS_TYPE_COS, "<resilver max active (0..1000)>",
97 "RESILVER_MAXACTIVE");
98 }
99
100 /*
101 * Given a property name and its type, returns the corresponding property ID.
102 */
103 cos_prop_t
104 cos_name_to_prop(const char *propname)
105 {
106 return (zprop_name_to_prop(propname, ZFS_TYPE_COS));
107 }
108
109 /*
110 * Given a cos property ID, returns the corresponding name.
111 * Assuming the cos propety ID is valid.
112 */
113 const char *
114 cos_prop_to_name(cos_prop_t prop)
115 {
116 return (cos_prop_table[prop].pd_name);
117 }
118
119 zprop_type_t
120 cos_prop_get_type(cos_prop_t prop)
121 {
122 return (cos_prop_table[prop].pd_proptype);
123 }
124
125 boolean_t
126 cos_prop_readonly(cos_prop_t prop)
127 {
128 return (cos_prop_table[prop].pd_attr == PROP_READONLY);
129 }
130
131 const char *
132 cos_prop_default_string(cos_prop_t prop)
133 {
134 return (cos_prop_table[prop].pd_strdefault);
135 }
136
137 uint64_t
138 cos_prop_default_numeric(cos_prop_t prop)
139 {
140 return (cos_prop_table[prop].pd_numdefault);
141 }
142
143 int
144 cos_prop_string_to_index(cos_prop_t prop, const char *string,
145 uint64_t *index)
146 {
147 return (zprop_string_to_index(prop, string, index, ZFS_TYPE_COS));
148 }
149
150 int
151 cos_prop_index_to_string(cos_prop_t prop, uint64_t index,
152 const char **string)
153 {
154 return (zprop_index_to_string(prop, index, string, ZFS_TYPE_COS));
155 }
156
157 uint64_t
158 cos_prop_random_value(cos_prop_t prop, uint64_t seed)
159 {
160 return (zprop_random_value(prop, seed, ZFS_TYPE_COS));
161 }
162
163 #ifndef _KERNEL
164
165 const char *
166 cos_prop_values(cos_prop_t prop)
167 {
168 return (cos_prop_table[prop].pd_values);
169 }
170
171 const char *
172 cos_prop_column_name(cos_prop_t prop)
173 {
174 return (cos_prop_table[prop].pd_colname);
175 }
176
177 boolean_t
178 cos_prop_align_right(cos_prop_t prop)
179 {
180 return (cos_prop_table[prop].pd_rightalign);
181 }
182 #endif