Print this page
OS-1566 dataset quota for ZFS datasets
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/common/zfs/zfs_prop.c
+++ new/usr/src/common/zfs/zfs_prop.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2011 by Delphix. All rights reserved.
24 24 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
25 25 */
26 26
27 27 /* Portions Copyright 2010 Robert Milkowski */
28 28
29 29 #include <sys/zio.h>
30 30 #include <sys/spa.h>
31 31 #include <sys/u8_textprep.h>
32 32 #include <sys/zfs_acl.h>
33 33 #include <sys/zfs_ioctl.h>
34 34 #include <sys/zfs_znode.h>
35 35
36 36 #include "zfs_prop.h"
37 37 #include "zfs_deleg.h"
38 38
39 39 #if defined(_KERNEL)
40 40 #include <sys/systm.h>
41 41 #else
42 42 #include <stdlib.h>
43 43 #include <string.h>
44 44 #include <ctype.h>
45 45 #endif
46 46
47 47 static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS];
48 48
49 49 /* Note this is indexed by zfs_userquota_prop_t, keep the order the same */
50 50 const char *zfs_userquota_prop_prefixes[] = {
51 51 "userused@",
52 52 "userquota@",
53 53 "groupused@",
54 54 "groupquota@"
55 55 };
56 56
57 57 zprop_desc_t *
58 58 zfs_prop_get_table(void)
59 59 {
60 60 return (zfs_prop_table);
61 61 }
62 62
63 63 void
64 64 zfs_prop_init(void)
65 65 {
66 66 static zprop_index_t checksum_table[] = {
67 67 { "on", ZIO_CHECKSUM_ON },
68 68 { "off", ZIO_CHECKSUM_OFF },
69 69 { "fletcher2", ZIO_CHECKSUM_FLETCHER_2 },
70 70 { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 },
71 71 { "sha256", ZIO_CHECKSUM_SHA256 },
72 72 { "noparity", ZIO_CHECKSUM_NOPARITY },
73 73 { NULL }
74 74 };
75 75
76 76 static zprop_index_t dedup_table[] = {
77 77 { "on", ZIO_CHECKSUM_ON },
78 78 { "off", ZIO_CHECKSUM_OFF },
79 79 { "verify", ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY },
80 80 { "sha256", ZIO_CHECKSUM_SHA256 },
81 81 { "sha256,verify",
82 82 ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY },
83 83 { NULL }
84 84 };
85 85
86 86 static zprop_index_t compress_table[] = {
87 87 { "on", ZIO_COMPRESS_ON },
88 88 { "off", ZIO_COMPRESS_OFF },
89 89 { "lzjb", ZIO_COMPRESS_LZJB },
90 90 { "gzip", ZIO_COMPRESS_GZIP_6 }, /* gzip default */
91 91 { "gzip-1", ZIO_COMPRESS_GZIP_1 },
92 92 { "gzip-2", ZIO_COMPRESS_GZIP_2 },
93 93 { "gzip-3", ZIO_COMPRESS_GZIP_3 },
94 94 { "gzip-4", ZIO_COMPRESS_GZIP_4 },
95 95 { "gzip-5", ZIO_COMPRESS_GZIP_5 },
96 96 { "gzip-6", ZIO_COMPRESS_GZIP_6 },
97 97 { "gzip-7", ZIO_COMPRESS_GZIP_7 },
98 98 { "gzip-8", ZIO_COMPRESS_GZIP_8 },
99 99 { "gzip-9", ZIO_COMPRESS_GZIP_9 },
100 100 { "zle", ZIO_COMPRESS_ZLE },
101 101 { NULL }
102 102 };
103 103
104 104 static zprop_index_t snapdir_table[] = {
105 105 { "hidden", ZFS_SNAPDIR_HIDDEN },
106 106 { "visible", ZFS_SNAPDIR_VISIBLE },
107 107 { NULL }
108 108 };
109 109
110 110 static zprop_index_t acl_mode_table[] = {
111 111 { "discard", ZFS_ACL_DISCARD },
112 112 { "groupmask", ZFS_ACL_GROUPMASK },
113 113 { "passthrough", ZFS_ACL_PASSTHROUGH },
114 114 { NULL }
115 115 };
116 116
117 117 static zprop_index_t acl_inherit_table[] = {
118 118 { "discard", ZFS_ACL_DISCARD },
119 119 { "noallow", ZFS_ACL_NOALLOW },
120 120 { "restricted", ZFS_ACL_RESTRICTED },
121 121 { "passthrough", ZFS_ACL_PASSTHROUGH },
122 122 { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatability */
123 123 { "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
124 124 { NULL }
125 125 };
126 126
127 127 static zprop_index_t case_table[] = {
128 128 { "sensitive", ZFS_CASE_SENSITIVE },
129 129 { "insensitive", ZFS_CASE_INSENSITIVE },
130 130 { "mixed", ZFS_CASE_MIXED },
131 131 { NULL }
132 132 };
133 133
134 134 static zprop_index_t copies_table[] = {
135 135 { "1", 1 },
136 136 { "2", 2 },
137 137 { "3", 3 },
138 138 { NULL }
139 139 };
140 140
141 141 /*
142 142 * Use the unique flags we have to send to u8_strcmp() and/or
143 143 * u8_textprep() to represent the various normalization property
144 144 * values.
145 145 */
146 146 static zprop_index_t normalize_table[] = {
147 147 { "none", 0 },
148 148 { "formD", U8_TEXTPREP_NFD },
149 149 { "formKC", U8_TEXTPREP_NFKC },
150 150 { "formC", U8_TEXTPREP_NFC },
151 151 { "formKD", U8_TEXTPREP_NFKD },
152 152 { NULL }
153 153 };
154 154
155 155 static zprop_index_t version_table[] = {
156 156 { "1", 1 },
157 157 { "2", 2 },
158 158 { "3", 3 },
159 159 { "4", 4 },
160 160 { "5", 5 },
161 161 { "current", ZPL_VERSION },
162 162 { NULL }
163 163 };
164 164
165 165 static zprop_index_t boolean_table[] = {
166 166 { "off", 0 },
167 167 { "on", 1 },
168 168 { NULL }
169 169 };
170 170
171 171 static zprop_index_t logbias_table[] = {
172 172 { "latency", ZFS_LOGBIAS_LATENCY },
173 173 { "throughput", ZFS_LOGBIAS_THROUGHPUT },
174 174 { NULL }
175 175 };
176 176
177 177 static zprop_index_t canmount_table[] = {
178 178 { "off", ZFS_CANMOUNT_OFF },
179 179 { "on", ZFS_CANMOUNT_ON },
180 180 { "noauto", ZFS_CANMOUNT_NOAUTO },
181 181 { NULL }
182 182 };
183 183
184 184 static zprop_index_t cache_table[] = {
185 185 { "none", ZFS_CACHE_NONE },
186 186 { "metadata", ZFS_CACHE_METADATA },
187 187 { "all", ZFS_CACHE_ALL },
188 188 { NULL }
189 189 };
190 190
191 191 static zprop_index_t sync_table[] = {
192 192 { "standard", ZFS_SYNC_STANDARD },
193 193 { "always", ZFS_SYNC_ALWAYS },
194 194 { "disabled", ZFS_SYNC_DISABLED },
195 195 { NULL }
196 196 };
197 197
198 198 /* inherit index properties */
199 199 zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD,
200 200 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
201 201 "standard | always | disabled", "SYNC",
202 202 sync_table);
203 203 zprop_register_index(ZFS_PROP_CHECKSUM, "checksum",
204 204 ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM |
205 205 ZFS_TYPE_VOLUME,
206 206 "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM",
207 207 checksum_table);
208 208 zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
209 209 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
210 210 "on | off | verify | sha256[,verify]", "DEDUP",
211 211 dedup_table);
212 212 zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
213 213 ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
214 214 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
215 215 "on | off | lzjb | gzip | gzip-[1-9] | zle", "COMPRESS",
216 216 compress_table);
217 217 zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
218 218 PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
219 219 "hidden | visible", "SNAPDIR", snapdir_table);
220 220 zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD,
221 221 PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
222 222 "discard | groupmask | passthrough", "ACLMODE", acl_mode_table);
223 223 zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
224 224 ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
225 225 "discard | noallow | restricted | passthrough | passthrough-x",
226 226 "ACLINHERIT", acl_inherit_table);
227 227 zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT,
228 228 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
229 229 "1 | 2 | 3", "COPIES", copies_table);
230 230 zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
231 231 ZFS_CACHE_ALL, PROP_INHERIT,
232 232 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
233 233 "all | none | metadata", "PRIMARYCACHE", cache_table);
234 234 zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
235 235 ZFS_CACHE_ALL, PROP_INHERIT,
236 236 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
237 237 "all | none | metadata", "SECONDARYCACHE", cache_table);
238 238 zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
239 239 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
240 240 "latency | throughput", "LOGBIAS", logbias_table);
241 241
242 242 /* inherit index (boolean) properties */
243 243 zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
244 244 ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
245 245 zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
246 246 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
247 247 boolean_table);
248 248 zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
249 249 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
250 250 boolean_table);
251 251 zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
252 252 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
253 253 boolean_table);
254 254 zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
255 255 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
256 256 boolean_table);
257 257 zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
258 258 ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table);
259 259 zprop_register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT,
260 260 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR",
261 261 boolean_table);
262 262 zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
263 263 ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
264 264 boolean_table);
265 265 zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
266 266 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
267 267 boolean_table);
268 268
269 269 /* default index properties */
270 270 zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
271 271 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
272 272 "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table);
273 273 zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
274 274 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
275 275 "CANMOUNT", canmount_table);
276 276
277 277 /* readonly index (boolean) properties */
278 278 zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
279 279 ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
280 280 zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0,
281 281 PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY",
282 282 boolean_table);
283 283
284 284 /* set once index properties */
285 285 zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
286 286 PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
287 287 "none | formC | formD | formKC | formKD", "NORMALIZATION",
288 288 normalize_table);
289 289 zprop_register_index(ZFS_PROP_CASE, "casesensitivity",
290 290 ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM |
291 291 ZFS_TYPE_SNAPSHOT,
292 292 "sensitive | insensitive | mixed", "CASE", case_table);
293 293
294 294 /* set once index (boolean) properties */
295 295 zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
296 296 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
297 297 "on | off", "UTF8ONLY", boolean_table);
298 298
299 299 /* string properties */
300 300 zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
301 301 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
302 302 zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY,
303 303 ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES");
304 304 zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/",
305 305 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none",
306 306 "MOUNTPOINT");
307 307 zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off",
308 308 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options",
309 309 "SHARENFS");
310 310 zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
311 311 ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE");
312 312 zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off",
313 313 PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
314 314 "on | off | sharemgr(1M) options", "SHARESMB");
315 315 zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel",
316 316 ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET,
317 317 "<sensitivity label>", "MLSLABEL");
318 318
319 319 /* readonly number properties */
320 320 zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
321 321 ZFS_TYPE_DATASET, "<size>", "USED");
322 322 zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
323 323 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
324 324 zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0,
325 325 PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER");
326 326 zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
327 327 PROP_READONLY, ZFS_TYPE_DATASET,
328 328 "<1.00x or higher if compressed>", "RATIO");
329 329 zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0,
330 330 PROP_READONLY, ZFS_TYPE_DATASET,
331 331 "<1.00x or higher if compressed>", "REFRATIO");
332 332 zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
333 333 ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
334 334 ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK");
335 335 zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0,
336 336 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
337 337 "USEDSNAP");
338 338 zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0,
339 339 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
340 340 "USEDDS");
341 341 zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0,
342 342 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
343 343 "USEDCHILD");
344 344 zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
345 345 PROP_READONLY,
346 346 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
347 347 zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
348 348 ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS");
349 349 zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY,
350 350 ZFS_TYPE_DATASET, "<size>", "WRITTEN");
351 351
352 352 /* default number properties */
353 353 zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
354 354 ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
↓ open down ↓ |
354 lines elided |
↑ open up ↑ |
355 355 zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0,
356 356 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
357 357 "<size> | none", "RESERV");
358 358 zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
359 359 ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
360 360 zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
361 361 ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
362 362 zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
363 363 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
364 364 "<size> | none", "REFRESERV");
365 + zprop_register_number(ZFS_PROP_DATASET_QUOTA, "dataset_quota", 0,
366 + PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
367 + "<count> | none", "DSQUOTA");
368 + zprop_register_number(ZFS_PROP_SNAPSHOT_QUOTA, "snapshot_quota", 0,
369 + PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
370 + "<count> | none", "SSQUOTA");
365 371
366 372 /* inherit number properties */
367 373 zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize",
368 374 SPA_MAXBLOCKSIZE, PROP_INHERIT,
369 375 ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE");
370 376
371 377 /* hidden properties */
372 378 zprop_register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER,
373 379 PROP_READONLY, ZFS_TYPE_DATASET, "CREATETXG");
374 380 zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
375 381 PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES");
376 382 zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
377 383 PROP_READONLY, ZFS_TYPE_DATASET, "NAME");
378 384 zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions",
379 385 PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
380 386 zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
381 387 PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
382 388 "STMF_SBD_LU");
383 389 zprop_register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER,
384 390 PROP_READONLY, ZFS_TYPE_DATASET, "GUID");
385 391 zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
386 392 PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
387 393 "USERACCOUNTING");
388 394 zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
389 395 PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE");
390 396 zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER,
391 397 PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID");
392 398
393 399 /* oddball properties */
394 400 zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0,
395 401 NULL, PROP_READONLY, ZFS_TYPE_DATASET,
396 402 "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
397 403 }
398 404
399 405 boolean_t
400 406 zfs_prop_delegatable(zfs_prop_t prop)
401 407 {
402 408 zprop_desc_t *pd = &zfs_prop_table[prop];
403 409
404 410 /* The mlslabel property is never delegatable. */
405 411 if (prop == ZFS_PROP_MLSLABEL)
406 412 return (B_FALSE);
407 413
408 414 return (pd->pd_attr != PROP_READONLY);
409 415 }
410 416
411 417 boolean_t
412 418 zfs_prop_cacheable(zfs_prop_t prop)
413 419 {
414 420 /*
415 421 * It'd be nice if each prop had a flags field which could have flag
416 422 * like PROP_CACHEABLE, but since zprop_attr_t is an enum and this
417 423 * setting is orthogonal to the concepts of PROP_READONLY, etc., we have
418 424 * this function.
419 425 */
420 426 return (prop == ZFS_PROP_VERSION ||
421 427 prop == ZFS_PROP_NORMALIZE ||
422 428 prop == ZFS_PROP_UTF8ONLY ||
423 429 prop == ZFS_PROP_CASE ||
424 430 prop == ZFS_PROP_VOLSIZE ||
425 431 prop == ZFS_PROP_VOLBLOCKSIZE);
426 432 }
427 433
428 434 /*
429 435 * Given a zfs dataset property name, returns the corresponding property ID.
430 436 */
431 437 zfs_prop_t
432 438 zfs_name_to_prop(const char *propname)
433 439 {
434 440 return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
435 441 }
436 442
437 443 /*
438 444 * For user property names, we allow all lowercase alphanumeric characters, plus
439 445 * a few useful punctuation characters.
440 446 */
441 447 static int
442 448 valid_char(char c)
443 449 {
444 450 return ((c >= 'a' && c <= 'z') ||
445 451 (c >= '0' && c <= '9') ||
446 452 c == '-' || c == '_' || c == '.' || c == ':');
447 453 }
448 454
449 455 /*
450 456 * Returns true if this is a valid user-defined property (one with a ':').
451 457 */
452 458 boolean_t
453 459 zfs_prop_user(const char *name)
454 460 {
455 461 int i;
456 462 char c;
457 463 boolean_t foundsep = B_FALSE;
458 464
459 465 for (i = 0; i < strlen(name); i++) {
460 466 c = name[i];
461 467 if (!valid_char(c))
462 468 return (B_FALSE);
463 469 if (c == ':')
464 470 foundsep = B_TRUE;
465 471 }
466 472
467 473 if (!foundsep)
468 474 return (B_FALSE);
469 475
470 476 return (B_TRUE);
471 477 }
472 478
473 479 /*
474 480 * Returns true if this is a valid userspace-type property (one with a '@').
475 481 * Note that after the @, any character is valid (eg, another @, for SID
476 482 * user@domain).
477 483 */
478 484 boolean_t
479 485 zfs_prop_userquota(const char *name)
480 486 {
481 487 zfs_userquota_prop_t prop;
482 488
483 489 for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
484 490 if (strncmp(name, zfs_userquota_prop_prefixes[prop],
485 491 strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
486 492 return (B_TRUE);
487 493 }
488 494 }
489 495
490 496 return (B_FALSE);
491 497 }
492 498
493 499 /*
494 500 * Returns true if this is a valid written@ property.
495 501 * Note that after the @, any character is valid (eg, another @, for
496 502 * written@pool/fs@origin).
497 503 */
498 504 boolean_t
499 505 zfs_prop_written(const char *name)
500 506 {
501 507 static const char *prefix = "written@";
502 508 return (strncmp(name, prefix, strlen(prefix)) == 0);
503 509 }
504 510
505 511 /*
506 512 * Tables of index types, plus functions to convert between the user view
507 513 * (strings) and internal representation (uint64_t).
508 514 */
509 515 int
510 516 zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
511 517 {
512 518 return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
513 519 }
514 520
515 521 int
516 522 zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
517 523 {
518 524 return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
519 525 }
520 526
521 527 uint64_t
522 528 zfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
523 529 {
524 530 return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
525 531 }
526 532
527 533 /*
528 534 * Returns TRUE if the property applies to any of the given dataset types.
529 535 */
530 536 boolean_t
531 537 zfs_prop_valid_for_type(int prop, zfs_type_t types)
532 538 {
533 539 return (zprop_valid_for_type(prop, types));
534 540 }
535 541
536 542 zprop_type_t
537 543 zfs_prop_get_type(zfs_prop_t prop)
538 544 {
539 545 return (zfs_prop_table[prop].pd_proptype);
540 546 }
541 547
542 548 /*
543 549 * Returns TRUE if the property is readonly.
544 550 */
545 551 boolean_t
546 552 zfs_prop_readonly(zfs_prop_t prop)
547 553 {
548 554 return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
549 555 zfs_prop_table[prop].pd_attr == PROP_ONETIME);
550 556 }
551 557
552 558 /*
553 559 * Returns TRUE if the property is only allowed to be set once.
554 560 */
555 561 boolean_t
556 562 zfs_prop_setonce(zfs_prop_t prop)
557 563 {
558 564 return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
559 565 }
560 566
561 567 const char *
562 568 zfs_prop_default_string(zfs_prop_t prop)
563 569 {
564 570 return (zfs_prop_table[prop].pd_strdefault);
565 571 }
566 572
567 573 uint64_t
568 574 zfs_prop_default_numeric(zfs_prop_t prop)
569 575 {
570 576 return (zfs_prop_table[prop].pd_numdefault);
571 577 }
572 578
573 579 /*
574 580 * Given a dataset property ID, returns the corresponding name.
575 581 * Assuming the zfs dataset property ID is valid.
576 582 */
577 583 const char *
578 584 zfs_prop_to_name(zfs_prop_t prop)
579 585 {
580 586 return (zfs_prop_table[prop].pd_name);
581 587 }
582 588
583 589 /*
584 590 * Returns TRUE if the property is inheritable.
585 591 */
586 592 boolean_t
587 593 zfs_prop_inheritable(zfs_prop_t prop)
588 594 {
589 595 return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
590 596 zfs_prop_table[prop].pd_attr == PROP_ONETIME);
591 597 }
592 598
593 599 #ifndef _KERNEL
594 600
595 601 /*
596 602 * Returns a string describing the set of acceptable values for the given
597 603 * zfs property, or NULL if it cannot be set.
598 604 */
599 605 const char *
600 606 zfs_prop_values(zfs_prop_t prop)
601 607 {
602 608 return (zfs_prop_table[prop].pd_values);
603 609 }
604 610
605 611 /*
606 612 * Returns TRUE if this property is a string type. Note that index types
607 613 * (compression, checksum) are treated as strings in userland, even though they
608 614 * are stored numerically on disk.
609 615 */
610 616 int
611 617 zfs_prop_is_string(zfs_prop_t prop)
612 618 {
613 619 return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
614 620 zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
615 621 }
616 622
617 623 /*
618 624 * Returns the column header for the given property. Used only in
619 625 * 'zfs list -o', but centralized here with the other property information.
620 626 */
621 627 const char *
622 628 zfs_prop_column_name(zfs_prop_t prop)
623 629 {
624 630 return (zfs_prop_table[prop].pd_colname);
625 631 }
626 632
627 633 /*
628 634 * Returns whether the given property should be displayed right-justified for
629 635 * 'zfs list'.
630 636 */
631 637 boolean_t
632 638 zfs_prop_align_right(zfs_prop_t prop)
633 639 {
634 640 return (zfs_prop_table[prop].pd_rightalign);
635 641 }
636 642
637 643 #endif
↓ open down ↓ |
263 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX