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