]>
Commit | Line | Data |
---|---|---|
34dc7c2f BB |
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 | /* | |
428870ff | 22 | * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
faf0f58c | 23 | * Copyright (c) 2011, 2014 by Delphix. All rights reserved. |
632a242e | 24 | * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. |
34dc7c2f BB |
25 | */ |
26 | ||
428870ff BB |
27 | /* Portions Copyright 2010 Robert Milkowski */ |
28 | ||
34dc7c2f BB |
29 | #include <sys/zio.h> |
30 | #include <sys/spa.h> | |
31 | #include <sys/u8_textprep.h> | |
32 | #include <sys/zfs_acl.h> | |
33 | #include <sys/zfs_ioctl.h> | |
34 | #include <sys/zfs_znode.h> | |
35 | ||
36 | #include "zfs_prop.h" | |
37 | #include "zfs_deleg.h" | |
1eeb4562 | 38 | #include "zfs_fletcher.h" |
34dc7c2f BB |
39 | |
40 | #if defined(_KERNEL) | |
41 | #include <sys/systm.h> | |
42 | #else | |
43 | #include <stdlib.h> | |
44 | #include <string.h> | |
45 | #include <ctype.h> | |
46 | #endif | |
47 | ||
48 | static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS]; | |
49 | ||
9babb374 BB |
50 | /* Note this is indexed by zfs_userquota_prop_t, keep the order the same */ |
51 | const char *zfs_userquota_prop_prefixes[] = { | |
52 | "userused@", | |
53 | "userquota@", | |
54 | "groupused@", | |
55 | "groupquota@" | |
56 | }; | |
57 | ||
34dc7c2f BB |
58 | zprop_desc_t * |
59 | zfs_prop_get_table(void) | |
60 | { | |
61 | return (zfs_prop_table); | |
62 | } | |
63 | ||
64 | void | |
65 | zfs_prop_init(void) | |
66 | { | |
67 | static zprop_index_t checksum_table[] = { | |
68 | { "on", ZIO_CHECKSUM_ON }, | |
69 | { "off", ZIO_CHECKSUM_OFF }, | |
70 | { "fletcher2", ZIO_CHECKSUM_FLETCHER_2 }, | |
71 | { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 }, | |
72 | { "sha256", ZIO_CHECKSUM_SHA256 }, | |
3c67d83a TH |
73 | { "noparity", ZIO_CHECKSUM_NOPARITY }, |
74 | { "sha512", ZIO_CHECKSUM_SHA512 }, | |
75 | { "skein", ZIO_CHECKSUM_SKEIN }, | |
76 | { "edonr", ZIO_CHECKSUM_EDONR }, | |
34dc7c2f BB |
77 | { NULL } |
78 | }; | |
79 | ||
428870ff BB |
80 | static zprop_index_t dedup_table[] = { |
81 | { "on", ZIO_CHECKSUM_ON }, | |
82 | { "off", ZIO_CHECKSUM_OFF }, | |
83 | { "verify", ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY }, | |
84 | { "sha256", ZIO_CHECKSUM_SHA256 }, | |
85 | { "sha256,verify", | |
86 | ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY }, | |
3c67d83a TH |
87 | { "sha512", ZIO_CHECKSUM_SHA512 }, |
88 | { "sha512,verify", | |
89 | ZIO_CHECKSUM_SHA512 | ZIO_CHECKSUM_VERIFY }, | |
90 | { "skein", ZIO_CHECKSUM_SKEIN }, | |
91 | { "skein,verify", | |
92 | ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY }, | |
93 | { "edonr,verify", | |
94 | ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY }, | |
428870ff BB |
95 | { NULL } |
96 | }; | |
97 | ||
34dc7c2f BB |
98 | static zprop_index_t compress_table[] = { |
99 | { "on", ZIO_COMPRESS_ON }, | |
100 | { "off", ZIO_COMPRESS_OFF }, | |
101 | { "lzjb", ZIO_COMPRESS_LZJB }, | |
102 | { "gzip", ZIO_COMPRESS_GZIP_6 }, /* gzip default */ | |
103 | { "gzip-1", ZIO_COMPRESS_GZIP_1 }, | |
104 | { "gzip-2", ZIO_COMPRESS_GZIP_2 }, | |
105 | { "gzip-3", ZIO_COMPRESS_GZIP_3 }, | |
106 | { "gzip-4", ZIO_COMPRESS_GZIP_4 }, | |
107 | { "gzip-5", ZIO_COMPRESS_GZIP_5 }, | |
108 | { "gzip-6", ZIO_COMPRESS_GZIP_6 }, | |
109 | { "gzip-7", ZIO_COMPRESS_GZIP_7 }, | |
110 | { "gzip-8", ZIO_COMPRESS_GZIP_8 }, | |
111 | { "gzip-9", ZIO_COMPRESS_GZIP_9 }, | |
428870ff | 112 | { "zle", ZIO_COMPRESS_ZLE }, |
9759c60f | 113 | { "lz4", ZIO_COMPRESS_LZ4 }, |
34dc7c2f BB |
114 | { NULL } |
115 | }; | |
116 | ||
117 | static zprop_index_t snapdir_table[] = { | |
118 | { "hidden", ZFS_SNAPDIR_HIDDEN }, | |
119 | { "visible", ZFS_SNAPDIR_VISIBLE }, | |
120 | { NULL } | |
121 | }; | |
122 | ||
0b4d1b58 ED |
123 | static zprop_index_t snapdev_table[] = { |
124 | { "hidden", ZFS_SNAPDEV_HIDDEN }, | |
125 | { "visible", ZFS_SNAPDEV_VISIBLE }, | |
126 | { NULL } | |
127 | }; | |
128 | ||
023699cd MM |
129 | static zprop_index_t acltype_table[] = { |
130 | { "off", ZFS_ACLTYPE_OFF }, | |
131 | { "disabled", ZFS_ACLTYPE_OFF }, | |
132 | { "noacl", ZFS_ACLTYPE_OFF }, | |
133 | { "posixacl", ZFS_ACLTYPE_POSIXACL }, | |
134 | { NULL } | |
135 | }; | |
136 | ||
34dc7c2f BB |
137 | static zprop_index_t acl_inherit_table[] = { |
138 | { "discard", ZFS_ACL_DISCARD }, | |
139 | { "noallow", ZFS_ACL_NOALLOW }, | |
140 | { "restricted", ZFS_ACL_RESTRICTED }, | |
141 | { "passthrough", ZFS_ACL_PASSTHROUGH }, | |
142 | { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatability */ | |
b128c09f | 143 | { "passthrough-x", ZFS_ACL_PASSTHROUGH_X }, |
34dc7c2f BB |
144 | { NULL } |
145 | }; | |
146 | ||
147 | static zprop_index_t case_table[] = { | |
148 | { "sensitive", ZFS_CASE_SENSITIVE }, | |
149 | { "insensitive", ZFS_CASE_INSENSITIVE }, | |
150 | { "mixed", ZFS_CASE_MIXED }, | |
151 | { NULL } | |
152 | }; | |
153 | ||
154 | static zprop_index_t copies_table[] = { | |
155 | { "1", 1 }, | |
156 | { "2", 2 }, | |
157 | { "3", 3 }, | |
158 | { NULL } | |
159 | }; | |
160 | ||
161 | /* | |
162 | * Use the unique flags we have to send to u8_strcmp() and/or | |
163 | * u8_textprep() to represent the various normalization property | |
164 | * values. | |
165 | */ | |
166 | static zprop_index_t normalize_table[] = { | |
167 | { "none", 0 }, | |
168 | { "formD", U8_TEXTPREP_NFD }, | |
169 | { "formKC", U8_TEXTPREP_NFKC }, | |
170 | { "formC", U8_TEXTPREP_NFC }, | |
171 | { "formKD", U8_TEXTPREP_NFKD }, | |
172 | { NULL } | |
173 | }; | |
174 | ||
175 | static zprop_index_t version_table[] = { | |
176 | { "1", 1 }, | |
177 | { "2", 2 }, | |
178 | { "3", 3 }, | |
9babb374 | 179 | { "4", 4 }, |
428870ff | 180 | { "5", 5 }, |
34dc7c2f BB |
181 | { "current", ZPL_VERSION }, |
182 | { NULL } | |
183 | }; | |
184 | ||
185 | static zprop_index_t boolean_table[] = { | |
186 | { "off", 0 }, | |
187 | { "on", 1 }, | |
188 | { NULL } | |
189 | }; | |
190 | ||
428870ff BB |
191 | static zprop_index_t logbias_table[] = { |
192 | { "latency", ZFS_LOGBIAS_LATENCY }, | |
193 | { "throughput", ZFS_LOGBIAS_THROUGHPUT }, | |
194 | { NULL } | |
195 | }; | |
196 | ||
34dc7c2f BB |
197 | static zprop_index_t canmount_table[] = { |
198 | { "off", ZFS_CANMOUNT_OFF }, | |
199 | { "on", ZFS_CANMOUNT_ON }, | |
200 | { "noauto", ZFS_CANMOUNT_NOAUTO }, | |
201 | { NULL } | |
202 | }; | |
203 | ||
b128c09f BB |
204 | static zprop_index_t cache_table[] = { |
205 | { "none", ZFS_CACHE_NONE }, | |
206 | { "metadata", ZFS_CACHE_METADATA }, | |
207 | { "all", ZFS_CACHE_ALL }, | |
208 | { NULL } | |
209 | }; | |
210 | ||
428870ff BB |
211 | static zprop_index_t sync_table[] = { |
212 | { "standard", ZFS_SYNC_STANDARD }, | |
213 | { "always", ZFS_SYNC_ALWAYS }, | |
214 | { "disabled", ZFS_SYNC_DISABLED }, | |
215 | { NULL } | |
216 | }; | |
217 | ||
82a37189 BB |
218 | static zprop_index_t xattr_table[] = { |
219 | { "off", ZFS_XATTR_OFF }, | |
220 | { "on", ZFS_XATTR_DIR }, | |
221 | { "sa", ZFS_XATTR_SA }, | |
222 | { "dir", ZFS_XATTR_DIR }, | |
223 | { NULL } | |
224 | }; | |
225 | ||
50c957f7 NB |
226 | static zprop_index_t dnsize_table[] = { |
227 | { "legacy", ZFS_DNSIZE_LEGACY }, | |
228 | { "auto", ZFS_DNSIZE_AUTO }, | |
229 | { "1k", ZFS_DNSIZE_1K }, | |
230 | { "2k", ZFS_DNSIZE_2K }, | |
231 | { "4k", ZFS_DNSIZE_4K }, | |
232 | { "8k", ZFS_DNSIZE_8K }, | |
233 | { "16k", ZFS_DNSIZE_16K }, | |
234 | { NULL } | |
235 | }; | |
236 | ||
faf0f58c MA |
237 | static zprop_index_t redundant_metadata_table[] = { |
238 | { "all", ZFS_REDUNDANT_METADATA_ALL }, | |
239 | { "most", ZFS_REDUNDANT_METADATA_MOST }, | |
240 | { NULL } | |
241 | }; | |
242 | ||
34dc7c2f | 243 | /* inherit index properties */ |
faf0f58c MA |
244 | zprop_register_index(ZFS_PROP_REDUNDANT_METADATA, "redundant_metadata", |
245 | ZFS_REDUNDANT_METADATA_ALL, | |
246 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
247 | "all | most", "REDUND_MD", | |
248 | redundant_metadata_table); | |
428870ff | 249 | zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD, |
34dc7c2f | 250 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, |
428870ff BB |
251 | "standard | always | disabled", "SYNC", |
252 | sync_table); | |
253 | zprop_register_index(ZFS_PROP_CHECKSUM, "checksum", | |
254 | ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM | | |
255 | ZFS_TYPE_VOLUME, | |
3c67d83a TH |
256 | "on | off | fletcher2 | fletcher4 | sha256 | sha512 | " |
257 | "skein | edonr", "CHECKSUM", checksum_table); | |
428870ff BB |
258 | zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF, |
259 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
3c67d83a TH |
260 | "on | off | verify | sha256[,verify], sha512[,verify], " |
261 | "skein[,verify], edonr,verify", "DEDUP", dedup_table); | |
428870ff | 262 | zprop_register_index(ZFS_PROP_COMPRESSION, "compression", |
34dc7c2f BB |
263 | ZIO_COMPRESS_DEFAULT, PROP_INHERIT, |
264 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
9759c60f | 265 | "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4", "COMPRESS", |
428870ff BB |
266 | compress_table); |
267 | zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN, | |
34dc7c2f BB |
268 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM, |
269 | "hidden | visible", "SNAPDIR", snapdir_table); | |
0b4d1b58 ED |
270 | zprop_register_index(ZFS_PROP_SNAPDEV, "snapdev", ZFS_SNAPDEV_HIDDEN, |
271 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
272 | "hidden | visible", "SNAPDEV", snapdev_table); | |
023699cd MM |
273 | zprop_register_index(ZFS_PROP_ACLTYPE, "acltype", ZFS_ACLTYPE_OFF, |
274 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, | |
275 | "noacl | posixacl", "ACLTYPE", acltype_table); | |
428870ff BB |
276 | zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit", |
277 | ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM, | |
b128c09f | 278 | "discard | noallow | restricted | passthrough | passthrough-x", |
34dc7c2f | 279 | "ACLINHERIT", acl_inherit_table); |
428870ff BB |
280 | zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT, |
281 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
34dc7c2f | 282 | "1 | 2 | 3", "COPIES", copies_table); |
428870ff | 283 | zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache", |
b128c09f BB |
284 | ZFS_CACHE_ALL, PROP_INHERIT, |
285 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, | |
286 | "all | none | metadata", "PRIMARYCACHE", cache_table); | |
428870ff | 287 | zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache", |
b128c09f BB |
288 | ZFS_CACHE_ALL, PROP_INHERIT, |
289 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, | |
290 | "all | none | metadata", "SECONDARYCACHE", cache_table); | |
428870ff BB |
291 | zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY, |
292 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
293 | "latency | throughput", "LOGBIAS", logbias_table); | |
82a37189 BB |
294 | zprop_register_index(ZFS_PROP_XATTR, "xattr", ZFS_XATTR_DIR, |
295 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, | |
296 | "on | off | dir | sa", "XATTR", xattr_table); | |
50c957f7 NB |
297 | zprop_register_index(ZFS_PROP_DNODESIZE, "dnodesize", |
298 | ZFS_DNSIZE_LEGACY, PROP_INHERIT, ZFS_TYPE_FILESYSTEM, | |
299 | "legacy | auto | 1k | 2k | 4k | 8k | 16k", "DNSIZE", dnsize_table); | |
34dc7c2f BB |
300 | |
301 | /* inherit index (boolean) properties */ | |
428870ff | 302 | zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT, |
34dc7c2f | 303 | ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table); |
6d111134 TC |
304 | zprop_register_index(ZFS_PROP_RELATIME, "relatime", 0, PROP_INHERIT, |
305 | ZFS_TYPE_FILESYSTEM, "on | off", "RELATIME", boolean_table); | |
428870ff | 306 | zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT, |
34dc7c2f BB |
307 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES", |
308 | boolean_table); | |
428870ff | 309 | zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT, |
34dc7c2f BB |
310 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC", |
311 | boolean_table); | |
428870ff | 312 | zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT, |
34dc7c2f BB |
313 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID", |
314 | boolean_table); | |
428870ff | 315 | zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT, |
34dc7c2f BB |
316 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY", |
317 | boolean_table); | |
428870ff | 318 | zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT, |
34dc7c2f | 319 | ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table); |
428870ff | 320 | zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT, |
82a37189 | 321 | ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", boolean_table); |
428870ff | 322 | zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT, |
34dc7c2f BB |
323 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND", |
324 | boolean_table); | |
f67d7090 TF |
325 | zprop_register_index(ZFS_PROP_OVERLAY, "overlay", 0, PROP_INHERIT, |
326 | ZFS_TYPE_FILESYSTEM, "on | off", "OVERLAY", boolean_table); | |
34dc7c2f BB |
327 | |
328 | /* default index properties */ | |
428870ff | 329 | zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT, |
34dc7c2f | 330 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, |
330d06f9 | 331 | "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table); |
428870ff | 332 | zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON, |
34dc7c2f BB |
333 | PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto", |
334 | "CANMOUNT", canmount_table); | |
335 | ||
336 | /* readonly index (boolean) properties */ | |
428870ff | 337 | zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY, |
34dc7c2f | 338 | ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table); |
428870ff | 339 | zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0, |
45d1cae3 BB |
340 | PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY", |
341 | boolean_table); | |
34dc7c2f BB |
342 | |
343 | /* set once index properties */ | |
428870ff | 344 | zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0, |
34dc7c2f BB |
345 | PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, |
346 | "none | formC | formD | formKC | formKD", "NORMALIZATION", | |
347 | normalize_table); | |
428870ff BB |
348 | zprop_register_index(ZFS_PROP_CASE, "casesensitivity", |
349 | ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM | | |
350 | ZFS_TYPE_SNAPSHOT, | |
34dc7c2f BB |
351 | "sensitive | insensitive | mixed", "CASE", case_table); |
352 | ||
353 | /* set once index (boolean) properties */ | |
428870ff | 354 | zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME, |
34dc7c2f BB |
355 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, |
356 | "on | off", "UTF8ONLY", boolean_table); | |
357 | ||
358 | /* string properties */ | |
428870ff | 359 | zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY, |
34dc7c2f | 360 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN"); |
330d06f9 MA |
361 | zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY, |
362 | ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES"); | |
428870ff BB |
363 | zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", |
364 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", | |
365 | "MOUNTPOINT"); | |
366 | zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", | |
367 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", | |
368 | "SHARENFS"); | |
369 | zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY, | |
da536844 MA |
370 | ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, |
371 | "filesystem | volume | snapshot | bookmark", "TYPE"); | |
428870ff BB |
372 | zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", |
373 | PROP_INHERIT, ZFS_TYPE_FILESYSTEM, | |
374 | "on | off | sharemgr(1M) options", "SHARESMB"); | |
375 | zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel", | |
376 | ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET, | |
377 | "<sensitivity label>", "MLSLABEL"); | |
11b9ec23 MT |
378 | zprop_register_string(ZFS_PROP_SELINUX_CONTEXT, "context", |
379 | "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux context>", | |
380 | "CONTEXT"); | |
381 | zprop_register_string(ZFS_PROP_SELINUX_FSCONTEXT, "fscontext", | |
382 | "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux fscontext>", | |
383 | "FSCONTEXT"); | |
384 | zprop_register_string(ZFS_PROP_SELINUX_DEFCONTEXT, "defcontext", | |
385 | "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux defcontext>", | |
386 | "DEFCONTEXT"); | |
387 | zprop_register_string(ZFS_PROP_SELINUX_ROOTCONTEXT, "rootcontext", | |
388 | "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux rootcontext>", | |
389 | "ROOTCONTEXT"); | |
47dfff3b MA |
390 | zprop_register_string(ZFS_PROP_RECEIVE_RESUME_TOKEN, |
391 | "receive_resume_token", | |
392 | NULL, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
393 | "<string token>", "RESUMETOK"); | |
34dc7c2f BB |
394 | |
395 | /* readonly number properties */ | |
428870ff | 396 | zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, |
34dc7c2f | 397 | ZFS_TYPE_DATASET, "<size>", "USED"); |
428870ff | 398 | zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, |
34dc7c2f | 399 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); |
428870ff BB |
400 | zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0, |
401 | PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER"); | |
402 | zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, | |
34dc7c2f BB |
403 | PROP_READONLY, ZFS_TYPE_DATASET, |
404 | "<1.00x or higher if compressed>", "RATIO"); | |
f5fc4aca MA |
405 | zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0, |
406 | PROP_READONLY, ZFS_TYPE_DATASET, | |
407 | "<1.00x or higher if compressed>", "REFRATIO"); | |
428870ff BB |
408 | zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", |
409 | ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME, | |
34dc7c2f | 410 | ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); |
428870ff BB |
411 | zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, |
412 | PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", | |
413 | "USEDSNAP"); | |
414 | zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, | |
415 | PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", | |
416 | "USEDDS"); | |
417 | zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, | |
418 | PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", | |
419 | "USEDCHILD"); | |
420 | zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0, | |
b128c09f BB |
421 | PROP_READONLY, |
422 | ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV"); | |
428870ff | 423 | zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY, |
45d1cae3 | 424 | ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS"); |
330d06f9 MA |
425 | zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY, |
426 | ZFS_TYPE_DATASET, "<size>", "WRITTEN"); | |
24a64651 MA |
427 | zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0, |
428 | PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LUSED"); | |
429 | zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced", | |
430 | 0, PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LREFER"); | |
34dc7c2f BB |
431 | |
432 | /* default number properties */ | |
428870ff | 433 | zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, |
34dc7c2f | 434 | ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); |
428870ff BB |
435 | zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0, |
436 | PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
437 | "<size> | none", "RESERV"); | |
438 | zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, | |
962d5242 | 439 | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); |
428870ff | 440 | zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, |
34dc7c2f | 441 | ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); |
428870ff | 442 | zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, |
34dc7c2f BB |
443 | PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, |
444 | "<size> | none", "REFRESERV"); | |
788eb90c JJ |
445 | zprop_register_number(ZFS_PROP_FILESYSTEM_LIMIT, "filesystem_limit", |
446 | UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, | |
447 | "<count> | none", "FSLIMIT"); | |
448 | zprop_register_number(ZFS_PROP_SNAPSHOT_LIMIT, "snapshot_limit", | |
449 | UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
450 | "<count> | none", "SSLIMIT"); | |
451 | zprop_register_number(ZFS_PROP_FILESYSTEM_COUNT, "filesystem_count", | |
452 | UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, | |
453 | "<count>", "FSCOUNT"); | |
454 | zprop_register_number(ZFS_PROP_SNAPSHOT_COUNT, "snapshot_count", | |
455 | UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, | |
456 | "<count>", "SSCOUNT"); | |
34dc7c2f BB |
457 | |
458 | /* inherit number properties */ | |
428870ff | 459 | zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize", |
f1512ee6 MA |
460 | SPA_OLD_MAXBLOCKSIZE, PROP_INHERIT, |
461 | ZFS_TYPE_FILESYSTEM, "512 to 1M, power of 2", "RECSIZE"); | |
34dc7c2f BB |
462 | |
463 | /* hidden properties */ | |
428870ff | 464 | zprop_register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER, |
da536844 | 465 | PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "CREATETXG"); |
428870ff BB |
466 | zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, |
467 | PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES"); | |
468 | zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, | |
da536844 | 469 | PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "NAME"); |
428870ff BB |
470 | zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", |
471 | PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); | |
472 | zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu", | |
9babb374 BB |
473 | PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, |
474 | "STMF_SBD_LU"); | |
428870ff | 475 | zprop_register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER, |
da536844 | 476 | PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "GUID"); |
428870ff BB |
477 | zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting", |
478 | PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, | |
479 | "USERACCOUNTING"); | |
480 | zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER, | |
481 | PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE"); | |
482 | zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER, | |
483 | PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID"); | |
96c2e961 KW |
484 | zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent", |
485 | PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT"); | |
1715493f MA |
486 | zprop_register_hidden(ZFS_PROP_PREV_SNAP, "prevsnap", PROP_TYPE_STRING, |
487 | PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PREVSNAP"); | |
428870ff BB |
488 | |
489 | /* | |
490 | * Property to be removed once libbe is integrated | |
491 | */ | |
492 | zprop_register_hidden(ZFS_PROP_PRIVATE, "priv_prop", | |
493 | PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_FILESYSTEM, | |
494 | "PRIV_PROP"); | |
34dc7c2f BB |
495 | |
496 | /* oddball properties */ | |
428870ff | 497 | zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, |
da536844 | 498 | NULL, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, |
34dc7c2f BB |
499 | "<date>", "CREATION", B_FALSE, B_TRUE, NULL); |
500 | } | |
501 | ||
502 | boolean_t | |
503 | zfs_prop_delegatable(zfs_prop_t prop) | |
504 | { | |
505 | zprop_desc_t *pd = &zfs_prop_table[prop]; | |
428870ff BB |
506 | |
507 | /* The mlslabel property is never delegatable. */ | |
508 | if (prop == ZFS_PROP_MLSLABEL) | |
509 | return (B_FALSE); | |
510 | ||
34dc7c2f BB |
511 | return (pd->pd_attr != PROP_READONLY); |
512 | } | |
513 | ||
514 | /* | |
515 | * Given a zfs dataset property name, returns the corresponding property ID. | |
516 | */ | |
517 | zfs_prop_t | |
518 | zfs_name_to_prop(const char *propname) | |
519 | { | |
520 | return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); | |
521 | } | |
522 | ||
34dc7c2f BB |
523 | /* |
524 | * For user property names, we allow all lowercase alphanumeric characters, plus | |
525 | * a few useful punctuation characters. | |
526 | */ | |
527 | static int | |
528 | valid_char(char c) | |
529 | { | |
530 | return ((c >= 'a' && c <= 'z') || | |
531 | (c >= '0' && c <= '9') || | |
532 | c == '-' || c == '_' || c == '.' || c == ':'); | |
533 | } | |
534 | ||
535 | /* | |
536 | * Returns true if this is a valid user-defined property (one with a ':'). | |
537 | */ | |
538 | boolean_t | |
539 | zfs_prop_user(const char *name) | |
540 | { | |
541 | int i; | |
542 | char c; | |
543 | boolean_t foundsep = B_FALSE; | |
544 | ||
545 | for (i = 0; i < strlen(name); i++) { | |
546 | c = name[i]; | |
547 | if (!valid_char(c)) | |
548 | return (B_FALSE); | |
549 | if (c == ':') | |
550 | foundsep = B_TRUE; | |
551 | } | |
552 | ||
553 | if (!foundsep) | |
554 | return (B_FALSE); | |
555 | ||
556 | return (B_TRUE); | |
557 | } | |
558 | ||
9babb374 BB |
559 | /* |
560 | * Returns true if this is a valid userspace-type property (one with a '@'). | |
561 | * Note that after the @, any character is valid (eg, another @, for SID | |
562 | * user@domain). | |
563 | */ | |
564 | boolean_t | |
565 | zfs_prop_userquota(const char *name) | |
566 | { | |
567 | zfs_userquota_prop_t prop; | |
568 | ||
569 | for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) { | |
570 | if (strncmp(name, zfs_userquota_prop_prefixes[prop], | |
571 | strlen(zfs_userquota_prop_prefixes[prop])) == 0) { | |
572 | return (B_TRUE); | |
573 | } | |
574 | } | |
575 | ||
576 | return (B_FALSE); | |
577 | } | |
578 | ||
330d06f9 MA |
579 | /* |
580 | * Returns true if this is a valid written@ property. | |
581 | * Note that after the @, any character is valid (eg, another @, for | |
582 | * written@pool/fs@origin). | |
583 | */ | |
584 | boolean_t | |
585 | zfs_prop_written(const char *name) | |
586 | { | |
587 | static const char *prefix = "written@"; | |
588 | return (strncmp(name, prefix, strlen(prefix)) == 0); | |
589 | } | |
590 | ||
34dc7c2f BB |
591 | /* |
592 | * Tables of index types, plus functions to convert between the user view | |
593 | * (strings) and internal representation (uint64_t). | |
594 | */ | |
595 | int | |
596 | zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) | |
597 | { | |
598 | return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); | |
599 | } | |
600 | ||
601 | int | |
602 | zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) | |
603 | { | |
604 | return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); | |
605 | } | |
606 | ||
428870ff BB |
607 | uint64_t |
608 | zfs_prop_random_value(zfs_prop_t prop, uint64_t seed) | |
609 | { | |
610 | return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET)); | |
611 | } | |
612 | ||
34dc7c2f BB |
613 | /* |
614 | * Returns TRUE if the property applies to any of the given dataset types. | |
615 | */ | |
b128c09f | 616 | boolean_t |
962d5242 | 617 | zfs_prop_valid_for_type(int prop, zfs_type_t types, boolean_t headcheck) |
34dc7c2f | 618 | { |
962d5242 | 619 | return (zprop_valid_for_type(prop, types, headcheck)); |
34dc7c2f BB |
620 | } |
621 | ||
622 | zprop_type_t | |
623 | zfs_prop_get_type(zfs_prop_t prop) | |
624 | { | |
625 | return (zfs_prop_table[prop].pd_proptype); | |
626 | } | |
627 | ||
628 | /* | |
629 | * Returns TRUE if the property is readonly. | |
630 | */ | |
631 | boolean_t | |
632 | zfs_prop_readonly(zfs_prop_t prop) | |
633 | { | |
634 | return (zfs_prop_table[prop].pd_attr == PROP_READONLY || | |
635 | zfs_prop_table[prop].pd_attr == PROP_ONETIME); | |
636 | } | |
637 | ||
638 | /* | |
639 | * Returns TRUE if the property is only allowed to be set once. | |
640 | */ | |
641 | boolean_t | |
642 | zfs_prop_setonce(zfs_prop_t prop) | |
643 | { | |
644 | return (zfs_prop_table[prop].pd_attr == PROP_ONETIME); | |
645 | } | |
646 | ||
647 | const char * | |
648 | zfs_prop_default_string(zfs_prop_t prop) | |
649 | { | |
650 | return (zfs_prop_table[prop].pd_strdefault); | |
651 | } | |
652 | ||
653 | uint64_t | |
654 | zfs_prop_default_numeric(zfs_prop_t prop) | |
655 | { | |
656 | return (zfs_prop_table[prop].pd_numdefault); | |
657 | } | |
658 | ||
659 | /* | |
660 | * Given a dataset property ID, returns the corresponding name. | |
661 | * Assuming the zfs dataset property ID is valid. | |
662 | */ | |
663 | const char * | |
664 | zfs_prop_to_name(zfs_prop_t prop) | |
665 | { | |
666 | return (zfs_prop_table[prop].pd_name); | |
667 | } | |
668 | ||
669 | /* | |
670 | * Returns TRUE if the property is inheritable. | |
671 | */ | |
672 | boolean_t | |
673 | zfs_prop_inheritable(zfs_prop_t prop) | |
674 | { | |
675 | return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || | |
676 | zfs_prop_table[prop].pd_attr == PROP_ONETIME); | |
677 | } | |
678 | ||
679 | #ifndef _KERNEL | |
680 | ||
681 | /* | |
682 | * Returns a string describing the set of acceptable values for the given | |
683 | * zfs property, or NULL if it cannot be set. | |
684 | */ | |
685 | const char * | |
686 | zfs_prop_values(zfs_prop_t prop) | |
687 | { | |
688 | return (zfs_prop_table[prop].pd_values); | |
689 | } | |
690 | ||
691 | /* | |
692 | * Returns TRUE if this property is a string type. Note that index types | |
693 | * (compression, checksum) are treated as strings in userland, even though they | |
694 | * are stored numerically on disk. | |
695 | */ | |
696 | int | |
697 | zfs_prop_is_string(zfs_prop_t prop) | |
698 | { | |
699 | return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || | |
700 | zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); | |
701 | } | |
702 | ||
703 | /* | |
704 | * Returns the column header for the given property. Used only in | |
705 | * 'zfs list -o', but centralized here with the other property information. | |
706 | */ | |
707 | const char * | |
708 | zfs_prop_column_name(zfs_prop_t prop) | |
709 | { | |
710 | return (zfs_prop_table[prop].pd_colname); | |
711 | } | |
712 | ||
713 | /* | |
714 | * Returns whether the given property should be displayed right-justified for | |
715 | * 'zfs list'. | |
716 | */ | |
717 | boolean_t | |
718 | zfs_prop_align_right(zfs_prop_t prop) | |
719 | { | |
720 | return (zfs_prop_table[prop].pd_rightalign); | |
721 | } | |
722 | ||
723 | #endif | |
c28b2279 BB |
724 | |
725 | #if defined(_KERNEL) && defined(HAVE_SPL) | |
b4f3666a BB |
726 | static int __init |
727 | zcommon_init(void) | |
728 | { | |
1eeb4562 | 729 | fletcher_4_init(); |
b4f3666a BB |
730 | return (0); |
731 | } | |
c28b2279 | 732 | |
b4f3666a BB |
733 | static void __exit |
734 | zcommon_fini(void) | |
735 | { | |
1eeb4562 | 736 | fletcher_4_fini(); |
b4f3666a | 737 | } |
c28b2279 | 738 | |
b4f3666a BB |
739 | module_init(zcommon_init); |
740 | module_exit(zcommon_fini); | |
c28b2279 BB |
741 | |
742 | MODULE_DESCRIPTION("Generic ZFS support"); | |
743 | MODULE_AUTHOR(ZFS_META_AUTHOR); | |
744 | MODULE_LICENSE(ZFS_META_LICENSE); | |
99e349db | 745 | MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE); |
c28b2279 BB |
746 | |
747 | /* zfs dataset property functions */ | |
748 | EXPORT_SYMBOL(zfs_userquota_prop_prefixes); | |
749 | EXPORT_SYMBOL(zfs_prop_init); | |
750 | EXPORT_SYMBOL(zfs_prop_get_type); | |
751 | EXPORT_SYMBOL(zfs_prop_get_table); | |
752 | EXPORT_SYMBOL(zfs_prop_delegatable); | |
753 | ||
754 | /* Dataset property functions shared between libzfs and kernel. */ | |
755 | EXPORT_SYMBOL(zfs_prop_default_string); | |
756 | EXPORT_SYMBOL(zfs_prop_default_numeric); | |
757 | EXPORT_SYMBOL(zfs_prop_readonly); | |
758 | EXPORT_SYMBOL(zfs_prop_inheritable); | |
759 | EXPORT_SYMBOL(zfs_prop_setonce); | |
760 | EXPORT_SYMBOL(zfs_prop_to_name); | |
761 | EXPORT_SYMBOL(zfs_name_to_prop); | |
762 | EXPORT_SYMBOL(zfs_prop_user); | |
763 | EXPORT_SYMBOL(zfs_prop_userquota); | |
764 | EXPORT_SYMBOL(zfs_prop_index_to_string); | |
765 | EXPORT_SYMBOL(zfs_prop_string_to_index); | |
766 | EXPORT_SYMBOL(zfs_prop_valid_for_type); | |
767 | ||
768 | #endif |