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