xref: /freebsd/sys/contrib/openzfs/include/sys/fs/zfs.h (revision c03c5b1c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright (c) 2011, 2020 by Delphix. All rights reserved.
25  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
26  * Copyright (c) 2013, 2017 Joyent, Inc. All rights reserved.
27  * Copyright (c) 2014 Integros [integros.com]
28  * Copyright (c) 2017, Intel Corporation.
29  * Copyright (c) 2019 Datto Inc.
30  * Portions Copyright 2010 Robert Milkowski
31  * Copyright (c) 2021, Colm Buckley <colm@tuatha.org>
32  */
33 
34 #ifndef	_SYS_FS_ZFS_H
35 #define	_SYS_FS_ZFS_H extern __attribute__((visibility("default")))
36 
37 #include <sys/time.h>
38 #include <sys/zio_priority.h>
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * Types and constants shared between userland and the kernel.
46  */
47 
48 /*
49  * Each dataset can be one of the following types.  These constants can be
50  * combined into masks that can be passed to various functions.
51  */
52 typedef enum {
53 	ZFS_TYPE_INVALID	= 0,
54 	ZFS_TYPE_FILESYSTEM	= (1 << 0),
55 	ZFS_TYPE_SNAPSHOT	= (1 << 1),
56 	ZFS_TYPE_VOLUME		= (1 << 2),
57 	ZFS_TYPE_POOL		= (1 << 3),
58 	ZFS_TYPE_BOOKMARK	= (1 << 4),
59 	ZFS_TYPE_VDEV		= (1 << 5),
60 } zfs_type_t;
61 
62 /*
63  * NB: lzc_dataset_type should be updated whenever a new objset type is added,
64  * if it represents a real type of a dataset that can be created from userland.
65  */
66 typedef enum dmu_objset_type {
67 	DMU_OST_NONE,
68 	DMU_OST_META,
69 	DMU_OST_ZFS,
70 	DMU_OST_ZVOL,
71 	DMU_OST_OTHER,			/* For testing only! */
72 	DMU_OST_ANY,			/* Be careful! */
73 	DMU_OST_NUMTYPES
74 } dmu_objset_type_t;
75 
76 #define	ZFS_TYPE_DATASET	\
77 	(ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME | ZFS_TYPE_SNAPSHOT)
78 
79 /*
80  * All of these include the terminating NUL byte.
81  */
82 #define	ZAP_MAXNAMELEN 256
83 #define	ZAP_MAXVALUELEN (1024 * 8)
84 #define	ZAP_OLDMAXVALUELEN 1024
85 #define	ZFS_MAX_DATASET_NAME_LEN 256
86 
87 /*
88  * Dataset properties are identified by these constants and must be added to
89  * the end of this list to ensure that external consumers are not affected
90  * by the change. If you make any changes to this list, be sure to update
91  * the property table in module/zcommon/zfs_prop.c.
92  */
93 typedef enum {
94 	ZPROP_CONT = -2,
95 	ZPROP_INVAL = -1,
96 	ZFS_PROP_TYPE = 0,
97 	ZFS_PROP_CREATION,
98 	ZFS_PROP_USED,
99 	ZFS_PROP_AVAILABLE,
100 	ZFS_PROP_REFERENCED,
101 	ZFS_PROP_COMPRESSRATIO,
102 	ZFS_PROP_MOUNTED,
103 	ZFS_PROP_ORIGIN,
104 	ZFS_PROP_QUOTA,
105 	ZFS_PROP_RESERVATION,
106 	ZFS_PROP_VOLSIZE,
107 	ZFS_PROP_VOLBLOCKSIZE,
108 	ZFS_PROP_RECORDSIZE,
109 	ZFS_PROP_MOUNTPOINT,
110 	ZFS_PROP_SHARENFS,
111 	ZFS_PROP_CHECKSUM,
112 	ZFS_PROP_COMPRESSION,
113 	ZFS_PROP_ATIME,
114 	ZFS_PROP_DEVICES,
115 	ZFS_PROP_EXEC,
116 	ZFS_PROP_SETUID,
117 	ZFS_PROP_READONLY,
118 	ZFS_PROP_ZONED,
119 	ZFS_PROP_SNAPDIR,
120 	ZFS_PROP_ACLMODE,
121 	ZFS_PROP_ACLINHERIT,
122 	ZFS_PROP_CREATETXG,
123 	ZFS_PROP_NAME,			/* not exposed to the user */
124 	ZFS_PROP_CANMOUNT,
125 	ZFS_PROP_ISCSIOPTIONS,		/* not exposed to the user */
126 	ZFS_PROP_XATTR,
127 	ZFS_PROP_NUMCLONES,		/* not exposed to the user */
128 	ZFS_PROP_COPIES,
129 	ZFS_PROP_VERSION,
130 	ZFS_PROP_UTF8ONLY,
131 	ZFS_PROP_NORMALIZE,
132 	ZFS_PROP_CASE,
133 	ZFS_PROP_VSCAN,
134 	ZFS_PROP_NBMAND,
135 	ZFS_PROP_SHARESMB,
136 	ZFS_PROP_REFQUOTA,
137 	ZFS_PROP_REFRESERVATION,
138 	ZFS_PROP_GUID,
139 	ZFS_PROP_PRIMARYCACHE,
140 	ZFS_PROP_SECONDARYCACHE,
141 	ZFS_PROP_USEDSNAP,
142 	ZFS_PROP_USEDDS,
143 	ZFS_PROP_USEDCHILD,
144 	ZFS_PROP_USEDREFRESERV,
145 	ZFS_PROP_USERACCOUNTING,	/* not exposed to the user */
146 	ZFS_PROP_STMF_SHAREINFO,	/* not exposed to the user */
147 	ZFS_PROP_DEFER_DESTROY,
148 	ZFS_PROP_USERREFS,
149 	ZFS_PROP_LOGBIAS,
150 	ZFS_PROP_UNIQUE,		/* not exposed to the user */
151 	ZFS_PROP_OBJSETID,
152 	ZFS_PROP_DEDUP,
153 	ZFS_PROP_MLSLABEL,
154 	ZFS_PROP_SYNC,
155 	ZFS_PROP_DNODESIZE,
156 	ZFS_PROP_REFRATIO,
157 	ZFS_PROP_WRITTEN,
158 	ZFS_PROP_CLONES,
159 	ZFS_PROP_LOGICALUSED,
160 	ZFS_PROP_LOGICALREFERENCED,
161 	ZFS_PROP_INCONSISTENT,		/* not exposed to the user */
162 	ZFS_PROP_VOLMODE,
163 	ZFS_PROP_FILESYSTEM_LIMIT,
164 	ZFS_PROP_SNAPSHOT_LIMIT,
165 	ZFS_PROP_FILESYSTEM_COUNT,
166 	ZFS_PROP_SNAPSHOT_COUNT,
167 	ZFS_PROP_SNAPDEV,
168 	ZFS_PROP_ACLTYPE,
169 	ZFS_PROP_SELINUX_CONTEXT,
170 	ZFS_PROP_SELINUX_FSCONTEXT,
171 	ZFS_PROP_SELINUX_DEFCONTEXT,
172 	ZFS_PROP_SELINUX_ROOTCONTEXT,
173 	ZFS_PROP_RELATIME,
174 	ZFS_PROP_REDUNDANT_METADATA,
175 	ZFS_PROP_OVERLAY,
176 	ZFS_PROP_PREV_SNAP,
177 	ZFS_PROP_RECEIVE_RESUME_TOKEN,
178 	ZFS_PROP_ENCRYPTION,
179 	ZFS_PROP_KEYLOCATION,
180 	ZFS_PROP_KEYFORMAT,
181 	ZFS_PROP_PBKDF2_SALT,
182 	ZFS_PROP_PBKDF2_ITERS,
183 	ZFS_PROP_ENCRYPTION_ROOT,
184 	ZFS_PROP_KEY_GUID,
185 	ZFS_PROP_KEYSTATUS,
186 	ZFS_PROP_REMAPTXG,		/* obsolete - no longer used */
187 	ZFS_PROP_SPECIAL_SMALL_BLOCKS,
188 	ZFS_PROP_IVSET_GUID,		/* not exposed to the user */
189 	ZFS_PROP_REDACTED,
190 	ZFS_PROP_REDACT_SNAPS,
191 	ZFS_NUM_PROPS
192 } zfs_prop_t;
193 
194 typedef enum {
195 	ZFS_PROP_USERUSED,
196 	ZFS_PROP_USERQUOTA,
197 	ZFS_PROP_GROUPUSED,
198 	ZFS_PROP_GROUPQUOTA,
199 	ZFS_PROP_USEROBJUSED,
200 	ZFS_PROP_USEROBJQUOTA,
201 	ZFS_PROP_GROUPOBJUSED,
202 	ZFS_PROP_GROUPOBJQUOTA,
203 	ZFS_PROP_PROJECTUSED,
204 	ZFS_PROP_PROJECTQUOTA,
205 	ZFS_PROP_PROJECTOBJUSED,
206 	ZFS_PROP_PROJECTOBJQUOTA,
207 	ZFS_NUM_USERQUOTA_PROPS
208 } zfs_userquota_prop_t;
209 
210 _SYS_FS_ZFS_H const char *const zfs_userquota_prop_prefixes[
211     ZFS_NUM_USERQUOTA_PROPS];
212 
213 /*
214  * Pool properties are identified by these constants and must be added to the
215  * end of this list to ensure that external consumers are not affected
216  * by the change.  Properties must be registered in zfs_prop_init().
217  */
218 typedef enum {
219 	ZPOOL_PROP_INVAL = -1,
220 	ZPOOL_PROP_NAME,
221 	ZPOOL_PROP_SIZE,
222 	ZPOOL_PROP_CAPACITY,
223 	ZPOOL_PROP_ALTROOT,
224 	ZPOOL_PROP_HEALTH,
225 	ZPOOL_PROP_GUID,
226 	ZPOOL_PROP_VERSION,
227 	ZPOOL_PROP_BOOTFS,
228 	ZPOOL_PROP_DELEGATION,
229 	ZPOOL_PROP_AUTOREPLACE,
230 	ZPOOL_PROP_CACHEFILE,
231 	ZPOOL_PROP_FAILUREMODE,
232 	ZPOOL_PROP_LISTSNAPS,
233 	ZPOOL_PROP_AUTOEXPAND,
234 	ZPOOL_PROP_DEDUPDITTO,
235 	ZPOOL_PROP_DEDUPRATIO,
236 	ZPOOL_PROP_FREE,
237 	ZPOOL_PROP_ALLOCATED,
238 	ZPOOL_PROP_READONLY,
239 	ZPOOL_PROP_ASHIFT,
240 	ZPOOL_PROP_COMMENT,
241 	ZPOOL_PROP_EXPANDSZ,
242 	ZPOOL_PROP_FREEING,
243 	ZPOOL_PROP_FRAGMENTATION,
244 	ZPOOL_PROP_LEAKED,
245 	ZPOOL_PROP_MAXBLOCKSIZE,
246 	ZPOOL_PROP_TNAME,
247 	ZPOOL_PROP_MAXDNODESIZE,
248 	ZPOOL_PROP_MULTIHOST,
249 	ZPOOL_PROP_CHECKPOINT,
250 	ZPOOL_PROP_LOAD_GUID,
251 	ZPOOL_PROP_AUTOTRIM,
252 	ZPOOL_PROP_COMPATIBILITY,
253 	ZPOOL_NUM_PROPS
254 } zpool_prop_t;
255 
256 /* Small enough to not hog a whole line of printout in zpool(8). */
257 #define	ZPROP_MAX_COMMENT	32
258 #define	ZPROP_BOOLEAN_NA	2
259 
260 #define	ZPROP_VALUE		"value"
261 #define	ZPROP_SOURCE		"source"
262 
263 typedef enum {
264 	ZPROP_SRC_NONE = 0x1,
265 	ZPROP_SRC_DEFAULT = 0x2,
266 	ZPROP_SRC_TEMPORARY = 0x4,
267 	ZPROP_SRC_LOCAL = 0x8,
268 	ZPROP_SRC_INHERITED = 0x10,
269 	ZPROP_SRC_RECEIVED = 0x20
270 } zprop_source_t;
271 
272 #define	ZPROP_SRC_ALL	0x3f
273 
274 #define	ZPROP_SOURCE_VAL_RECVD	"$recvd"
275 #define	ZPROP_N_MORE_ERRORS	"N_MORE_ERRORS"
276 
277 /*
278  * Dataset flag implemented as a special entry in the props zap object
279  * indicating that the dataset has received properties on or after
280  * SPA_VERSION_RECVD_PROPS. The first such receive blows away local properties
281  * just as it did in earlier versions, and thereafter, local properties are
282  * preserved.
283  */
284 #define	ZPROP_HAS_RECVD		"$hasrecvd"
285 
286 typedef enum {
287 	ZPROP_ERR_NOCLEAR = 0x1, /* failure to clear existing props */
288 	ZPROP_ERR_NORESTORE = 0x2 /* failure to restore props on error */
289 } zprop_errflags_t;
290 
291 typedef int (*zprop_func)(int, void *);
292 
293 /*
294  * Properties to be set on the root file system of a new pool
295  * are stuffed into their own nvlist, which is then included in
296  * the properties nvlist with the pool properties.
297  */
298 #define	ZPOOL_ROOTFS_PROPS	"root-props-nvl"
299 
300 /*
301  * Length of 'written@' and 'written#'
302  */
303 #define	ZFS_WRITTEN_PROP_PREFIX_LEN	8
304 
305 /*
306  * VDEV properties are identified by these constants and must be added to the
307  * end of this list to ensure that external consumers are not affected
308  * by the change. If you make any changes to this list, be sure to update
309  * the property table in usr/src/common/zfs/zpool_prop.c.
310  */
311 typedef enum {
312 	VDEV_PROP_INVAL = -1,
313 #define	VDEV_PROP_USER	VDEV_PROP_INVAL
314 	VDEV_PROP_NAME,
315 	VDEV_PROP_CAPACITY,
316 	VDEV_PROP_STATE,
317 	VDEV_PROP_GUID,
318 	VDEV_PROP_ASIZE,
319 	VDEV_PROP_PSIZE,
320 	VDEV_PROP_ASHIFT,
321 	VDEV_PROP_SIZE,
322 	VDEV_PROP_FREE,
323 	VDEV_PROP_ALLOCATED,
324 	VDEV_PROP_COMMENT,
325 	VDEV_PROP_EXPANDSZ,
326 	VDEV_PROP_FRAGMENTATION,
327 	VDEV_PROP_BOOTSIZE,
328 	VDEV_PROP_PARITY,
329 	VDEV_PROP_PATH,
330 	VDEV_PROP_DEVID,
331 	VDEV_PROP_PHYS_PATH,
332 	VDEV_PROP_ENC_PATH,
333 	VDEV_PROP_FRU,
334 	VDEV_PROP_PARENT,
335 	VDEV_PROP_CHILDREN,
336 	VDEV_PROP_NUMCHILDREN,
337 	VDEV_PROP_READ_ERRORS,
338 	VDEV_PROP_WRITE_ERRORS,
339 	VDEV_PROP_CHECKSUM_ERRORS,
340 	VDEV_PROP_INITIALIZE_ERRORS,
341 	VDEV_PROP_OPS_NULL,
342 	VDEV_PROP_OPS_READ,
343 	VDEV_PROP_OPS_WRITE,
344 	VDEV_PROP_OPS_FREE,
345 	VDEV_PROP_OPS_CLAIM,
346 	VDEV_PROP_OPS_TRIM,
347 	VDEV_PROP_BYTES_NULL,
348 	VDEV_PROP_BYTES_READ,
349 	VDEV_PROP_BYTES_WRITE,
350 	VDEV_PROP_BYTES_FREE,
351 	VDEV_PROP_BYTES_CLAIM,
352 	VDEV_PROP_BYTES_TRIM,
353 	VDEV_PROP_REMOVING,
354 	VDEV_PROP_ALLOCATING,
355 	VDEV_NUM_PROPS
356 } vdev_prop_t;
357 
358 /*
359  * Dataset property functions shared between libzfs and kernel.
360  */
361 _SYS_FS_ZFS_H const char *zfs_prop_default_string(zfs_prop_t);
362 _SYS_FS_ZFS_H uint64_t zfs_prop_default_numeric(zfs_prop_t);
363 _SYS_FS_ZFS_H boolean_t zfs_prop_readonly(zfs_prop_t);
364 _SYS_FS_ZFS_H boolean_t zfs_prop_visible(zfs_prop_t prop);
365 _SYS_FS_ZFS_H boolean_t zfs_prop_inheritable(zfs_prop_t);
366 _SYS_FS_ZFS_H boolean_t zfs_prop_setonce(zfs_prop_t);
367 _SYS_FS_ZFS_H boolean_t zfs_prop_encryption_key_param(zfs_prop_t);
368 _SYS_FS_ZFS_H boolean_t zfs_prop_valid_keylocation(const char *, boolean_t);
369 _SYS_FS_ZFS_H const char *zfs_prop_to_name(zfs_prop_t);
370 _SYS_FS_ZFS_H zfs_prop_t zfs_name_to_prop(const char *);
371 _SYS_FS_ZFS_H boolean_t zfs_prop_user(const char *);
372 _SYS_FS_ZFS_H boolean_t zfs_prop_userquota(const char *);
373 _SYS_FS_ZFS_H boolean_t zfs_prop_written(const char *);
374 _SYS_FS_ZFS_H int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
375 _SYS_FS_ZFS_H int zfs_prop_string_to_index(zfs_prop_t, const char *,
376     uint64_t *);
377 _SYS_FS_ZFS_H uint64_t zfs_prop_random_value(zfs_prop_t, uint64_t seed);
378 _SYS_FS_ZFS_H boolean_t zfs_prop_valid_for_type(int, zfs_type_t, boolean_t);
379 
380 /*
381  * Pool property functions shared between libzfs and kernel.
382  */
383 _SYS_FS_ZFS_H zpool_prop_t zpool_name_to_prop(const char *);
384 _SYS_FS_ZFS_H const char *zpool_prop_to_name(zpool_prop_t);
385 _SYS_FS_ZFS_H const char *zpool_prop_default_string(zpool_prop_t);
386 _SYS_FS_ZFS_H uint64_t zpool_prop_default_numeric(zpool_prop_t);
387 _SYS_FS_ZFS_H boolean_t zpool_prop_readonly(zpool_prop_t);
388 _SYS_FS_ZFS_H boolean_t zpool_prop_setonce(zpool_prop_t);
389 _SYS_FS_ZFS_H boolean_t zpool_prop_feature(const char *);
390 _SYS_FS_ZFS_H boolean_t zpool_prop_unsupported(const char *);
391 _SYS_FS_ZFS_H int zpool_prop_index_to_string(zpool_prop_t, uint64_t,
392     const char **);
393 _SYS_FS_ZFS_H int zpool_prop_string_to_index(zpool_prop_t, const char *,
394     uint64_t *);
395 _SYS_FS_ZFS_H uint64_t zpool_prop_random_value(zpool_prop_t, uint64_t seed);
396 
397 /*
398  * VDEV property functions shared between libzfs and kernel.
399  */
400 _SYS_FS_ZFS_H vdev_prop_t vdev_name_to_prop(const char *);
401 _SYS_FS_ZFS_H boolean_t vdev_prop_user(const char *name);
402 _SYS_FS_ZFS_H const char *vdev_prop_to_name(vdev_prop_t);
403 _SYS_FS_ZFS_H const char *vdev_prop_default_string(vdev_prop_t);
404 _SYS_FS_ZFS_H uint64_t vdev_prop_default_numeric(vdev_prop_t);
405 _SYS_FS_ZFS_H boolean_t vdev_prop_readonly(vdev_prop_t prop);
406 _SYS_FS_ZFS_H int vdev_prop_index_to_string(vdev_prop_t, uint64_t,
407     const char **);
408 _SYS_FS_ZFS_H int vdev_prop_string_to_index(vdev_prop_t, const char *,
409     uint64_t *);
410 _SYS_FS_ZFS_H boolean_t zpool_prop_vdev(const char *name);
411 _SYS_FS_ZFS_H uint64_t vdev_prop_random_value(vdev_prop_t prop, uint64_t seed);
412 
413 /*
414  * Definitions for the Delegation.
415  */
416 typedef enum {
417 	ZFS_DELEG_WHO_UNKNOWN = 0,
418 	ZFS_DELEG_USER = 'u',
419 	ZFS_DELEG_USER_SETS = 'U',
420 	ZFS_DELEG_GROUP = 'g',
421 	ZFS_DELEG_GROUP_SETS = 'G',
422 	ZFS_DELEG_EVERYONE = 'e',
423 	ZFS_DELEG_EVERYONE_SETS = 'E',
424 	ZFS_DELEG_CREATE = 'c',
425 	ZFS_DELEG_CREATE_SETS = 'C',
426 	ZFS_DELEG_NAMED_SET = 's',
427 	ZFS_DELEG_NAMED_SET_SETS = 'S'
428 } zfs_deleg_who_type_t;
429 
430 typedef enum {
431 	ZFS_DELEG_NONE = 0,
432 	ZFS_DELEG_PERM_LOCAL = 1,
433 	ZFS_DELEG_PERM_DESCENDENT = 2,
434 	ZFS_DELEG_PERM_LOCALDESCENDENT = 3,
435 	ZFS_DELEG_PERM_CREATE = 4
436 } zfs_deleg_inherit_t;
437 
438 #define	ZFS_DELEG_PERM_UID	"uid"
439 #define	ZFS_DELEG_PERM_GID	"gid"
440 #define	ZFS_DELEG_PERM_GROUPS	"groups"
441 
442 #define	ZFS_MLSLABEL_DEFAULT	"none"
443 
444 #define	ZFS_SMB_ACL_SRC		"src"
445 #define	ZFS_SMB_ACL_TARGET	"target"
446 
447 typedef enum {
448 	ZFS_CANMOUNT_OFF = 0,
449 	ZFS_CANMOUNT_ON = 1,
450 	ZFS_CANMOUNT_NOAUTO = 2
451 } zfs_canmount_type_t;
452 
453 typedef enum {
454 	ZFS_LOGBIAS_LATENCY = 0,
455 	ZFS_LOGBIAS_THROUGHPUT = 1
456 } zfs_logbias_op_t;
457 
458 typedef enum zfs_share_op {
459 	ZFS_SHARE_NFS = 0,
460 	ZFS_UNSHARE_NFS = 1,
461 	ZFS_SHARE_SMB = 2,
462 	ZFS_UNSHARE_SMB = 3
463 } zfs_share_op_t;
464 
465 typedef enum zfs_smb_acl_op {
466 	ZFS_SMB_ACL_ADD,
467 	ZFS_SMB_ACL_REMOVE,
468 	ZFS_SMB_ACL_RENAME,
469 	ZFS_SMB_ACL_PURGE
470 } zfs_smb_acl_op_t;
471 
472 typedef enum zfs_cache_type {
473 	ZFS_CACHE_NONE = 0,
474 	ZFS_CACHE_METADATA = 1,
475 	ZFS_CACHE_ALL = 2
476 } zfs_cache_type_t;
477 
478 typedef enum {
479 	ZFS_SYNC_STANDARD = 0,
480 	ZFS_SYNC_ALWAYS = 1,
481 	ZFS_SYNC_DISABLED = 2
482 } zfs_sync_type_t;
483 
484 typedef enum {
485 	ZFS_XATTR_OFF = 0,
486 	ZFS_XATTR_DIR = 1,
487 	ZFS_XATTR_SA = 2
488 } zfs_xattr_type_t;
489 
490 typedef enum {
491 	ZFS_DNSIZE_LEGACY = 0,
492 	ZFS_DNSIZE_AUTO = 1,
493 	ZFS_DNSIZE_1K = 1024,
494 	ZFS_DNSIZE_2K = 2048,
495 	ZFS_DNSIZE_4K = 4096,
496 	ZFS_DNSIZE_8K = 8192,
497 	ZFS_DNSIZE_16K = 16384
498 } zfs_dnsize_type_t;
499 
500 typedef enum {
501 	ZFS_REDUNDANT_METADATA_ALL,
502 	ZFS_REDUNDANT_METADATA_MOST
503 } zfs_redundant_metadata_type_t;
504 
505 typedef enum {
506 	ZFS_VOLMODE_DEFAULT = 0,
507 	ZFS_VOLMODE_GEOM = 1,
508 	ZFS_VOLMODE_DEV = 2,
509 	ZFS_VOLMODE_NONE = 3
510 } zfs_volmode_t;
511 
512 typedef enum zfs_keystatus {
513 	ZFS_KEYSTATUS_NONE = 0,
514 	ZFS_KEYSTATUS_UNAVAILABLE,
515 	ZFS_KEYSTATUS_AVAILABLE,
516 } zfs_keystatus_t;
517 
518 typedef enum zfs_keyformat {
519 	ZFS_KEYFORMAT_NONE = 0,
520 	ZFS_KEYFORMAT_RAW,
521 	ZFS_KEYFORMAT_HEX,
522 	ZFS_KEYFORMAT_PASSPHRASE,
523 	ZFS_KEYFORMAT_FORMATS
524 } zfs_keyformat_t;
525 
526 typedef enum zfs_key_location {
527 	ZFS_KEYLOCATION_NONE = 0,
528 	ZFS_KEYLOCATION_PROMPT,
529 	ZFS_KEYLOCATION_URI,
530 	ZFS_KEYLOCATION_LOCATIONS
531 } zfs_keylocation_t;
532 
533 #define	DEFAULT_PBKDF2_ITERATIONS 350000
534 #define	MIN_PBKDF2_ITERATIONS 100000
535 
536 /*
537  * On-disk version number.
538  */
539 #define	SPA_VERSION_1			1ULL
540 #define	SPA_VERSION_2			2ULL
541 #define	SPA_VERSION_3			3ULL
542 #define	SPA_VERSION_4			4ULL
543 #define	SPA_VERSION_5			5ULL
544 #define	SPA_VERSION_6			6ULL
545 #define	SPA_VERSION_7			7ULL
546 #define	SPA_VERSION_8			8ULL
547 #define	SPA_VERSION_9			9ULL
548 #define	SPA_VERSION_10			10ULL
549 #define	SPA_VERSION_11			11ULL
550 #define	SPA_VERSION_12			12ULL
551 #define	SPA_VERSION_13			13ULL
552 #define	SPA_VERSION_14			14ULL
553 #define	SPA_VERSION_15			15ULL
554 #define	SPA_VERSION_16			16ULL
555 #define	SPA_VERSION_17			17ULL
556 #define	SPA_VERSION_18			18ULL
557 #define	SPA_VERSION_19			19ULL
558 #define	SPA_VERSION_20			20ULL
559 #define	SPA_VERSION_21			21ULL
560 #define	SPA_VERSION_22			22ULL
561 #define	SPA_VERSION_23			23ULL
562 #define	SPA_VERSION_24			24ULL
563 #define	SPA_VERSION_25			25ULL
564 #define	SPA_VERSION_26			26ULL
565 #define	SPA_VERSION_27			27ULL
566 #define	SPA_VERSION_28			28ULL
567 #define	SPA_VERSION_5000		5000ULL
568 
569 /*
570  * The incrementing pool version number has been replaced by pool feature
571  * flags.  For more details, see zfeature.c.
572  */
573 #define	SPA_VERSION			SPA_VERSION_5000
574 #define	SPA_VERSION_STRING		"5000"
575 
576 /*
577  * Symbolic names for the changes that caused a SPA_VERSION switch.
578  * Used in the code when checking for presence or absence of a feature.
579  * Feel free to define multiple symbolic names for each version if there
580  * were multiple changes to on-disk structures during that version.
581  *
582  * NOTE: When checking the current SPA_VERSION in your code, be sure
583  *       to use spa_version() since it reports the version of the
584  *       last synced uberblock.  Checking the in-flight version can
585  *       be dangerous in some cases.
586  */
587 #define	SPA_VERSION_INITIAL		SPA_VERSION_1
588 #define	SPA_VERSION_DITTO_BLOCKS	SPA_VERSION_2
589 #define	SPA_VERSION_SPARES		SPA_VERSION_3
590 #define	SPA_VERSION_RAIDZ2		SPA_VERSION_3
591 #define	SPA_VERSION_BPOBJ_ACCOUNT	SPA_VERSION_3
592 #define	SPA_VERSION_RAIDZ_DEFLATE	SPA_VERSION_3
593 #define	SPA_VERSION_DNODE_BYTES		SPA_VERSION_3
594 #define	SPA_VERSION_ZPOOL_HISTORY	SPA_VERSION_4
595 #define	SPA_VERSION_GZIP_COMPRESSION	SPA_VERSION_5
596 #define	SPA_VERSION_BOOTFS		SPA_VERSION_6
597 #define	SPA_VERSION_SLOGS		SPA_VERSION_7
598 #define	SPA_VERSION_DELEGATED_PERMS	SPA_VERSION_8
599 #define	SPA_VERSION_FUID		SPA_VERSION_9
600 #define	SPA_VERSION_REFRESERVATION	SPA_VERSION_9
601 #define	SPA_VERSION_REFQUOTA		SPA_VERSION_9
602 #define	SPA_VERSION_UNIQUE_ACCURATE	SPA_VERSION_9
603 #define	SPA_VERSION_L2CACHE		SPA_VERSION_10
604 #define	SPA_VERSION_NEXT_CLONES		SPA_VERSION_11
605 #define	SPA_VERSION_ORIGIN		SPA_VERSION_11
606 #define	SPA_VERSION_DSL_SCRUB		SPA_VERSION_11
607 #define	SPA_VERSION_SNAP_PROPS		SPA_VERSION_12
608 #define	SPA_VERSION_USED_BREAKDOWN	SPA_VERSION_13
609 #define	SPA_VERSION_PASSTHROUGH_X	SPA_VERSION_14
610 #define	SPA_VERSION_USERSPACE		SPA_VERSION_15
611 #define	SPA_VERSION_STMF_PROP		SPA_VERSION_16
612 #define	SPA_VERSION_RAIDZ3		SPA_VERSION_17
613 #define	SPA_VERSION_USERREFS		SPA_VERSION_18
614 #define	SPA_VERSION_HOLES		SPA_VERSION_19
615 #define	SPA_VERSION_ZLE_COMPRESSION	SPA_VERSION_20
616 #define	SPA_VERSION_DEDUP		SPA_VERSION_21
617 #define	SPA_VERSION_RECVD_PROPS		SPA_VERSION_22
618 #define	SPA_VERSION_SLIM_ZIL		SPA_VERSION_23
619 #define	SPA_VERSION_SA			SPA_VERSION_24
620 #define	SPA_VERSION_SCAN		SPA_VERSION_25
621 #define	SPA_VERSION_DIR_CLONES		SPA_VERSION_26
622 #define	SPA_VERSION_DEADLISTS		SPA_VERSION_26
623 #define	SPA_VERSION_FAST_SNAP		SPA_VERSION_27
624 #define	SPA_VERSION_MULTI_REPLACE	SPA_VERSION_28
625 #define	SPA_VERSION_BEFORE_FEATURES	SPA_VERSION_28
626 #define	SPA_VERSION_FEATURES		SPA_VERSION_5000
627 
628 #define	SPA_VERSION_IS_SUPPORTED(v) \
629 	(((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \
630 	((v) >= SPA_VERSION_FEATURES && (v) <= SPA_VERSION))
631 
632 /*
633  * ZPL version - rev'd whenever an incompatible on-disk format change
634  * occurs.  This is independent of SPA/DMU/ZAP versioning.  You must
635  * also update the version_table[] and help message in zfs_prop.c.
636  */
637 #define	ZPL_VERSION_1			1ULL
638 #define	ZPL_VERSION_2			2ULL
639 #define	ZPL_VERSION_3			3ULL
640 #define	ZPL_VERSION_4			4ULL
641 #define	ZPL_VERSION_5			5ULL
642 #define	ZPL_VERSION			ZPL_VERSION_5
643 #define	ZPL_VERSION_STRING		"5"
644 
645 #define	ZPL_VERSION_INITIAL		ZPL_VERSION_1
646 #define	ZPL_VERSION_DIRENT_TYPE		ZPL_VERSION_2
647 #define	ZPL_VERSION_FUID		ZPL_VERSION_3
648 #define	ZPL_VERSION_NORMALIZATION	ZPL_VERSION_3
649 #define	ZPL_VERSION_SYSATTR		ZPL_VERSION_3
650 #define	ZPL_VERSION_USERSPACE		ZPL_VERSION_4
651 #define	ZPL_VERSION_SA			ZPL_VERSION_5
652 
653 /* Persistent L2ARC version */
654 #define	L2ARC_PERSISTENT_VERSION_1	1ULL
655 #define	L2ARC_PERSISTENT_VERSION	L2ARC_PERSISTENT_VERSION_1
656 #define	L2ARC_PERSISTENT_VERSION_STRING	"1"
657 
658 /* Rewind policy information */
659 #define	ZPOOL_NO_REWIND		1  /* No policy - default behavior */
660 #define	ZPOOL_NEVER_REWIND	2  /* Do not search for best txg or rewind */
661 #define	ZPOOL_TRY_REWIND	4  /* Search for best txg, but do not rewind */
662 #define	ZPOOL_DO_REWIND		8  /* Rewind to best txg w/in deferred frees */
663 #define	ZPOOL_EXTREME_REWIND	16 /* Allow extreme measures to find best txg */
664 #define	ZPOOL_REWIND_MASK	28 /* All the possible rewind bits */
665 #define	ZPOOL_REWIND_POLICIES	31 /* All the possible policy bits */
666 
667 typedef struct zpool_load_policy {
668 	uint32_t	zlp_rewind;	/* rewind policy requested */
669 	uint64_t	zlp_maxmeta;	/* max acceptable meta-data errors */
670 	uint64_t	zlp_maxdata;	/* max acceptable data errors */
671 	uint64_t	zlp_txg;	/* specific txg to load */
672 } zpool_load_policy_t;
673 
674 /*
675  * The following are configuration names used in the nvlist describing a pool's
676  * configuration.  New on-disk names should be prefixed with "<reversed-DNS>:"
677  * (e.g. "org.openzfs:") to avoid conflicting names being developed
678  * independently.
679  */
680 #define	ZPOOL_CONFIG_VERSION		"version"
681 #define	ZPOOL_CONFIG_POOL_NAME		"name"
682 #define	ZPOOL_CONFIG_POOL_STATE		"state"
683 #define	ZPOOL_CONFIG_POOL_TXG		"txg"
684 #define	ZPOOL_CONFIG_POOL_GUID		"pool_guid"
685 #define	ZPOOL_CONFIG_CREATE_TXG		"create_txg"
686 #define	ZPOOL_CONFIG_TOP_GUID		"top_guid"
687 #define	ZPOOL_CONFIG_VDEV_TREE		"vdev_tree"
688 #define	ZPOOL_CONFIG_TYPE		"type"
689 #define	ZPOOL_CONFIG_CHILDREN		"children"
690 #define	ZPOOL_CONFIG_ID			"id"
691 #define	ZPOOL_CONFIG_GUID		"guid"
692 #define	ZPOOL_CONFIG_INDIRECT_OBJECT	"com.delphix:indirect_object"
693 #define	ZPOOL_CONFIG_INDIRECT_BIRTHS	"com.delphix:indirect_births"
694 #define	ZPOOL_CONFIG_PREV_INDIRECT_VDEV	"com.delphix:prev_indirect_vdev"
695 #define	ZPOOL_CONFIG_PATH		"path"
696 #define	ZPOOL_CONFIG_DEVID		"devid"
697 #define	ZPOOL_CONFIG_SPARE_ID		"spareid"
698 #define	ZPOOL_CONFIG_METASLAB_ARRAY	"metaslab_array"
699 #define	ZPOOL_CONFIG_METASLAB_SHIFT	"metaslab_shift"
700 #define	ZPOOL_CONFIG_ASHIFT		"ashift"
701 #define	ZPOOL_CONFIG_ASIZE		"asize"
702 #define	ZPOOL_CONFIG_DTL		"DTL"
703 #define	ZPOOL_CONFIG_SCAN_STATS		"scan_stats"	/* not stored on disk */
704 #define	ZPOOL_CONFIG_REMOVAL_STATS	"removal_stats"	/* not stored on disk */
705 #define	ZPOOL_CONFIG_CHECKPOINT_STATS	"checkpoint_stats" /* not on disk */
706 #define	ZPOOL_CONFIG_VDEV_STATS		"vdev_stats"	/* not stored on disk */
707 #define	ZPOOL_CONFIG_INDIRECT_SIZE	"indirect_size"	/* not stored on disk */
708 
709 /* container nvlist of extended stats */
710 #define	ZPOOL_CONFIG_VDEV_STATS_EX	"vdev_stats_ex"
711 
712 /* Active queue read/write stats */
713 #define	ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE	"vdev_sync_r_active_queue"
714 #define	ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE	"vdev_sync_w_active_queue"
715 #define	ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE	"vdev_async_r_active_queue"
716 #define	ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE	"vdev_async_w_active_queue"
717 #define	ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE	"vdev_async_scrub_active_queue"
718 #define	ZPOOL_CONFIG_VDEV_TRIM_ACTIVE_QUEUE	"vdev_async_trim_active_queue"
719 #define	ZPOOL_CONFIG_VDEV_REBUILD_ACTIVE_QUEUE	"vdev_rebuild_active_queue"
720 
721 /* Queue sizes */
722 #define	ZPOOL_CONFIG_VDEV_SYNC_R_PEND_QUEUE	"vdev_sync_r_pend_queue"
723 #define	ZPOOL_CONFIG_VDEV_SYNC_W_PEND_QUEUE	"vdev_sync_w_pend_queue"
724 #define	ZPOOL_CONFIG_VDEV_ASYNC_R_PEND_QUEUE	"vdev_async_r_pend_queue"
725 #define	ZPOOL_CONFIG_VDEV_ASYNC_W_PEND_QUEUE	"vdev_async_w_pend_queue"
726 #define	ZPOOL_CONFIG_VDEV_SCRUB_PEND_QUEUE	"vdev_async_scrub_pend_queue"
727 #define	ZPOOL_CONFIG_VDEV_TRIM_PEND_QUEUE	"vdev_async_trim_pend_queue"
728 #define	ZPOOL_CONFIG_VDEV_REBUILD_PEND_QUEUE	"vdev_rebuild_pend_queue"
729 
730 /* Latency read/write histogram stats */
731 #define	ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO	"vdev_tot_r_lat_histo"
732 #define	ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO	"vdev_tot_w_lat_histo"
733 #define	ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO	"vdev_disk_r_lat_histo"
734 #define	ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO	"vdev_disk_w_lat_histo"
735 #define	ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO	"vdev_sync_r_lat_histo"
736 #define	ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO	"vdev_sync_w_lat_histo"
737 #define	ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO	"vdev_async_r_lat_histo"
738 #define	ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO	"vdev_async_w_lat_histo"
739 #define	ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO	"vdev_scrub_histo"
740 #define	ZPOOL_CONFIG_VDEV_TRIM_LAT_HISTO	"vdev_trim_histo"
741 #define	ZPOOL_CONFIG_VDEV_REBUILD_LAT_HISTO	"vdev_rebuild_histo"
742 
743 /* Request size histograms */
744 #define	ZPOOL_CONFIG_VDEV_SYNC_IND_R_HISTO	"vdev_sync_ind_r_histo"
745 #define	ZPOOL_CONFIG_VDEV_SYNC_IND_W_HISTO	"vdev_sync_ind_w_histo"
746 #define	ZPOOL_CONFIG_VDEV_ASYNC_IND_R_HISTO	"vdev_async_ind_r_histo"
747 #define	ZPOOL_CONFIG_VDEV_ASYNC_IND_W_HISTO	"vdev_async_ind_w_histo"
748 #define	ZPOOL_CONFIG_VDEV_IND_SCRUB_HISTO	"vdev_ind_scrub_histo"
749 #define	ZPOOL_CONFIG_VDEV_IND_TRIM_HISTO	"vdev_ind_trim_histo"
750 #define	ZPOOL_CONFIG_VDEV_IND_REBUILD_HISTO	"vdev_ind_rebuild_histo"
751 #define	ZPOOL_CONFIG_VDEV_SYNC_AGG_R_HISTO	"vdev_sync_agg_r_histo"
752 #define	ZPOOL_CONFIG_VDEV_SYNC_AGG_W_HISTO	"vdev_sync_agg_w_histo"
753 #define	ZPOOL_CONFIG_VDEV_ASYNC_AGG_R_HISTO	"vdev_async_agg_r_histo"
754 #define	ZPOOL_CONFIG_VDEV_ASYNC_AGG_W_HISTO	"vdev_async_agg_w_histo"
755 #define	ZPOOL_CONFIG_VDEV_AGG_SCRUB_HISTO	"vdev_agg_scrub_histo"
756 #define	ZPOOL_CONFIG_VDEV_AGG_TRIM_HISTO	"vdev_agg_trim_histo"
757 #define	ZPOOL_CONFIG_VDEV_AGG_REBUILD_HISTO	"vdev_agg_rebuild_histo"
758 
759 /* Number of slow IOs */
760 #define	ZPOOL_CONFIG_VDEV_SLOW_IOS		"vdev_slow_ios"
761 
762 /* vdev enclosure sysfs path */
763 #define	ZPOOL_CONFIG_VDEV_ENC_SYSFS_PATH	"vdev_enc_sysfs_path"
764 
765 #define	ZPOOL_CONFIG_WHOLE_DISK		"whole_disk"
766 #define	ZPOOL_CONFIG_ERRCOUNT		"error_count"
767 #define	ZPOOL_CONFIG_NOT_PRESENT	"not_present"
768 #define	ZPOOL_CONFIG_SPARES		"spares"
769 #define	ZPOOL_CONFIG_IS_SPARE		"is_spare"
770 #define	ZPOOL_CONFIG_NPARITY		"nparity"
771 #define	ZPOOL_CONFIG_HOSTID		"hostid"
772 #define	ZPOOL_CONFIG_HOSTNAME		"hostname"
773 #define	ZPOOL_CONFIG_LOADED_TIME	"initial_load_time"
774 #define	ZPOOL_CONFIG_UNSPARE		"unspare"
775 #define	ZPOOL_CONFIG_PHYS_PATH		"phys_path"
776 #define	ZPOOL_CONFIG_IS_LOG		"is_log"
777 #define	ZPOOL_CONFIG_L2CACHE		"l2cache"
778 #define	ZPOOL_CONFIG_HOLE_ARRAY		"hole_array"
779 #define	ZPOOL_CONFIG_VDEV_CHILDREN	"vdev_children"
780 #define	ZPOOL_CONFIG_IS_HOLE		"is_hole"
781 #define	ZPOOL_CONFIG_DDT_HISTOGRAM	"ddt_histogram"
782 #define	ZPOOL_CONFIG_DDT_OBJ_STATS	"ddt_object_stats"
783 #define	ZPOOL_CONFIG_DDT_STATS		"ddt_stats"
784 #define	ZPOOL_CONFIG_SPLIT		"splitcfg"
785 #define	ZPOOL_CONFIG_ORIG_GUID		"orig_guid"
786 #define	ZPOOL_CONFIG_SPLIT_GUID		"split_guid"
787 #define	ZPOOL_CONFIG_SPLIT_LIST		"guid_list"
788 #define	ZPOOL_CONFIG_NONALLOCATING	"non_allocating"
789 #define	ZPOOL_CONFIG_REMOVING		"removing"
790 #define	ZPOOL_CONFIG_RESILVER_TXG	"resilver_txg"
791 #define	ZPOOL_CONFIG_REBUILD_TXG	"rebuild_txg"
792 #define	ZPOOL_CONFIG_COMMENT		"comment"
793 #define	ZPOOL_CONFIG_SUSPENDED		"suspended"	/* not stored on disk */
794 #define	ZPOOL_CONFIG_SUSPENDED_REASON	"suspended_reason"	/* not stored */
795 #define	ZPOOL_CONFIG_TIMESTAMP		"timestamp"	/* not stored on disk */
796 #define	ZPOOL_CONFIG_BOOTFS		"bootfs"	/* not stored on disk */
797 #define	ZPOOL_CONFIG_MISSING_DEVICES	"missing_vdevs"	/* not stored on disk */
798 #define	ZPOOL_CONFIG_LOAD_INFO		"load_info"	/* not stored on disk */
799 #define	ZPOOL_CONFIG_REWIND_INFO	"rewind_info"	/* not stored on disk */
800 #define	ZPOOL_CONFIG_UNSUP_FEAT		"unsup_feat"	/* not stored on disk */
801 #define	ZPOOL_CONFIG_ENABLED_FEAT	"enabled_feat"	/* not stored on disk */
802 #define	ZPOOL_CONFIG_CAN_RDONLY		"can_rdonly"	/* not stored on disk */
803 #define	ZPOOL_CONFIG_FEATURES_FOR_READ	"features_for_read"
804 #define	ZPOOL_CONFIG_FEATURE_STATS	"feature_stats"	/* not stored on disk */
805 #define	ZPOOL_CONFIG_ERRATA		"errata"	/* not stored on disk */
806 #define	ZPOOL_CONFIG_VDEV_TOP_ZAP	"com.delphix:vdev_zap_top"
807 #define	ZPOOL_CONFIG_VDEV_LEAF_ZAP	"com.delphix:vdev_zap_leaf"
808 #define	ZPOOL_CONFIG_HAS_PER_VDEV_ZAPS	"com.delphix:has_per_vdev_zaps"
809 #define	ZPOOL_CONFIG_RESILVER_DEFER	"com.datto:resilver_defer"
810 #define	ZPOOL_CONFIG_CACHEFILE		"cachefile"	/* not stored on disk */
811 #define	ZPOOL_CONFIG_MMP_STATE		"mmp_state"	/* not stored on disk */
812 #define	ZPOOL_CONFIG_MMP_TXG		"mmp_txg"	/* not stored on disk */
813 #define	ZPOOL_CONFIG_MMP_SEQ		"mmp_seq"	/* not stored on disk */
814 #define	ZPOOL_CONFIG_MMP_HOSTNAME	"mmp_hostname"	/* not stored on disk */
815 #define	ZPOOL_CONFIG_MMP_HOSTID		"mmp_hostid"	/* not stored on disk */
816 #define	ZPOOL_CONFIG_ALLOCATION_BIAS	"alloc_bias"	/* not stored on disk */
817 #define	ZPOOL_CONFIG_EXPANSION_TIME	"expansion_time"	/* not stored */
818 #define	ZPOOL_CONFIG_REBUILD_STATS	"org.openzfs:rebuild_stats"
819 #define	ZPOOL_CONFIG_COMPATIBILITY	"compatibility"
820 
821 /*
822  * The persistent vdev state is stored as separate values rather than a single
823  * 'vdev_state' entry.  This is because a device can be in multiple states, such
824  * as offline and degraded.
825  */
826 #define	ZPOOL_CONFIG_OFFLINE		"offline"
827 #define	ZPOOL_CONFIG_FAULTED		"faulted"
828 #define	ZPOOL_CONFIG_DEGRADED		"degraded"
829 #define	ZPOOL_CONFIG_REMOVED		"removed"
830 #define	ZPOOL_CONFIG_FRU		"fru"
831 #define	ZPOOL_CONFIG_AUX_STATE		"aux_state"
832 
833 /* Pool load policy parameters */
834 #define	ZPOOL_LOAD_POLICY		"load-policy"
835 #define	ZPOOL_LOAD_REWIND_POLICY	"load-rewind-policy"
836 #define	ZPOOL_LOAD_REQUEST_TXG		"load-request-txg"
837 #define	ZPOOL_LOAD_META_THRESH		"load-meta-thresh"
838 #define	ZPOOL_LOAD_DATA_THRESH		"load-data-thresh"
839 
840 /* Rewind data discovered */
841 #define	ZPOOL_CONFIG_LOAD_TIME		"rewind_txg_ts"
842 #define	ZPOOL_CONFIG_LOAD_META_ERRORS	"verify_meta_errors"
843 #define	ZPOOL_CONFIG_LOAD_DATA_ERRORS	"verify_data_errors"
844 #define	ZPOOL_CONFIG_REWIND_TIME	"seconds_of_rewind"
845 
846 /* dRAID configuration */
847 #define	ZPOOL_CONFIG_DRAID_NDATA	"draid_ndata"
848 #define	ZPOOL_CONFIG_DRAID_NSPARES	"draid_nspares"
849 #define	ZPOOL_CONFIG_DRAID_NGROUPS	"draid_ngroups"
850 
851 #define	VDEV_TYPE_ROOT			"root"
852 #define	VDEV_TYPE_MIRROR		"mirror"
853 #define	VDEV_TYPE_REPLACING		"replacing"
854 #define	VDEV_TYPE_RAIDZ			"raidz"
855 #define	VDEV_TYPE_DRAID			"draid"
856 #define	VDEV_TYPE_DRAID_SPARE		"dspare"
857 #define	VDEV_TYPE_DISK			"disk"
858 #define	VDEV_TYPE_FILE			"file"
859 #define	VDEV_TYPE_MISSING		"missing"
860 #define	VDEV_TYPE_HOLE			"hole"
861 #define	VDEV_TYPE_SPARE			"spare"
862 #define	VDEV_TYPE_LOG			"log"
863 #define	VDEV_TYPE_L2CACHE		"l2cache"
864 #define	VDEV_TYPE_INDIRECT		"indirect"
865 
866 #define	VDEV_RAIDZ_MAXPARITY		3
867 
868 #define	VDEV_DRAID_MAXPARITY		3
869 #define	VDEV_DRAID_MIN_CHILDREN		2
870 #define	VDEV_DRAID_MAX_CHILDREN		UINT8_MAX
871 
872 /* VDEV_TOP_ZAP_* are used in top-level vdev ZAP objects. */
873 #define	VDEV_TOP_ZAP_INDIRECT_OBSOLETE_SM \
874 	"com.delphix:indirect_obsolete_sm"
875 #define	VDEV_TOP_ZAP_OBSOLETE_COUNTS_ARE_PRECISE \
876 	"com.delphix:obsolete_counts_are_precise"
877 #define	VDEV_TOP_ZAP_POOL_CHECKPOINT_SM \
878 	"com.delphix:pool_checkpoint_sm"
879 #define	VDEV_TOP_ZAP_MS_UNFLUSHED_PHYS_TXGS \
880 	"com.delphix:ms_unflushed_phys_txgs"
881 
882 #define	VDEV_TOP_ZAP_VDEV_REBUILD_PHYS \
883 	"org.openzfs:vdev_rebuild"
884 
885 #define	VDEV_TOP_ZAP_ALLOCATION_BIAS \
886 	"org.zfsonlinux:allocation_bias"
887 
888 /* vdev metaslab allocation bias */
889 #define	VDEV_ALLOC_BIAS_LOG		"log"
890 #define	VDEV_ALLOC_BIAS_SPECIAL		"special"
891 #define	VDEV_ALLOC_BIAS_DEDUP		"dedup"
892 
893 /* vdev initialize state */
894 #define	VDEV_LEAF_ZAP_INITIALIZE_LAST_OFFSET	\
895 	"com.delphix:next_offset_to_initialize"
896 #define	VDEV_LEAF_ZAP_INITIALIZE_STATE	\
897 	"com.delphix:vdev_initialize_state"
898 #define	VDEV_LEAF_ZAP_INITIALIZE_ACTION_TIME	\
899 	"com.delphix:vdev_initialize_action_time"
900 
901 /* vdev TRIM state */
902 #define	VDEV_LEAF_ZAP_TRIM_LAST_OFFSET	\
903 	"org.zfsonlinux:next_offset_to_trim"
904 #define	VDEV_LEAF_ZAP_TRIM_STATE	\
905 	"org.zfsonlinux:vdev_trim_state"
906 #define	VDEV_LEAF_ZAP_TRIM_ACTION_TIME	\
907 	"org.zfsonlinux:vdev_trim_action_time"
908 #define	VDEV_LEAF_ZAP_TRIM_RATE		\
909 	"org.zfsonlinux:vdev_trim_rate"
910 #define	VDEV_LEAF_ZAP_TRIM_PARTIAL	\
911 	"org.zfsonlinux:vdev_trim_partial"
912 #define	VDEV_LEAF_ZAP_TRIM_SECURE	\
913 	"org.zfsonlinux:vdev_trim_secure"
914 
915 /*
916  * This is needed in userland to report the minimum necessary device size.
917  */
918 #define	SPA_MINDEVSIZE		(64ULL << 20)
919 
920 /*
921  * Set if the fragmentation has not yet been calculated. This can happen
922  * because the space maps have not been upgraded or the histogram feature
923  * is not enabled.
924  */
925 #define	ZFS_FRAG_INVALID	UINT64_MAX
926 
927 /*
928  * The location of the pool configuration repository, shared between kernel and
929  * userland.
930  */
931 #define	ZPOOL_CACHE_BOOT	"/boot/zfs/zpool.cache"
932 #define	ZPOOL_CACHE		"/etc/zfs/zpool.cache"
933 /*
934  * Settings for zpool compatibility features files
935  */
936 #define	ZPOOL_SYSCONF_COMPAT_D	SYSCONFDIR "/zfs/compatibility.d"
937 #define	ZPOOL_DATA_COMPAT_D	PKGDATADIR "/compatibility.d"
938 #define	ZPOOL_COMPAT_MAXSIZE	16384
939 
940 /*
941  * Hard-wired compatibility settings
942  */
943 #define	ZPOOL_COMPAT_LEGACY	"legacy"
944 #define	ZPOOL_COMPAT_OFF	"off"
945 
946 /*
947  * vdev states are ordered from least to most healthy.
948  * A vdev that's CANT_OPEN or below is considered unusable.
949  */
950 typedef enum vdev_state {
951 	VDEV_STATE_UNKNOWN = 0,	/* Uninitialized vdev			*/
952 	VDEV_STATE_CLOSED,	/* Not currently open			*/
953 	VDEV_STATE_OFFLINE,	/* Not allowed to open			*/
954 	VDEV_STATE_REMOVED,	/* Explicitly removed from system	*/
955 	VDEV_STATE_CANT_OPEN,	/* Tried to open, but failed		*/
956 	VDEV_STATE_FAULTED,	/* External request to fault device	*/
957 	VDEV_STATE_DEGRADED,	/* Replicated vdev with unhealthy kids	*/
958 	VDEV_STATE_HEALTHY	/* Presumed good			*/
959 } vdev_state_t;
960 
961 #define	VDEV_STATE_ONLINE	VDEV_STATE_HEALTHY
962 
963 /*
964  * vdev aux states.  When a vdev is in the CANT_OPEN state, the aux field
965  * of the vdev stats structure uses these constants to distinguish why.
966  */
967 typedef enum vdev_aux {
968 	VDEV_AUX_NONE,		/* no error				*/
969 	VDEV_AUX_OPEN_FAILED,	/* ldi_open_*() or vn_open() failed	*/
970 	VDEV_AUX_CORRUPT_DATA,	/* bad label or disk contents		*/
971 	VDEV_AUX_NO_REPLICAS,	/* insufficient number of replicas	*/
972 	VDEV_AUX_BAD_GUID_SUM,	/* vdev guid sum doesn't match		*/
973 	VDEV_AUX_TOO_SMALL,	/* vdev size is too small		*/
974 	VDEV_AUX_BAD_LABEL,	/* the label is OK but invalid		*/
975 	VDEV_AUX_VERSION_NEWER,	/* on-disk version is too new		*/
976 	VDEV_AUX_VERSION_OLDER,	/* on-disk version is too old		*/
977 	VDEV_AUX_UNSUP_FEAT,	/* unsupported features			*/
978 	VDEV_AUX_SPARED,	/* hot spare used in another pool	*/
979 	VDEV_AUX_ERR_EXCEEDED,	/* too many errors			*/
980 	VDEV_AUX_IO_FAILURE,	/* experienced I/O failure		*/
981 	VDEV_AUX_BAD_LOG,	/* cannot read log chain(s)		*/
982 	VDEV_AUX_EXTERNAL,	/* external diagnosis or forced fault	*/
983 	VDEV_AUX_SPLIT_POOL,	/* vdev was split off into another pool	*/
984 	VDEV_AUX_BAD_ASHIFT,	/* vdev ashift is invalid		*/
985 	VDEV_AUX_EXTERNAL_PERSIST,	/* persistent forced fault	*/
986 	VDEV_AUX_ACTIVE,	/* vdev active on a different host	*/
987 	VDEV_AUX_CHILDREN_OFFLINE, /* all children are offline		*/
988 	VDEV_AUX_ASHIFT_TOO_BIG, /* vdev's min block size is too large   */
989 } vdev_aux_t;
990 
991 /*
992  * pool state.  The following states are written to disk as part of the normal
993  * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE.  The remaining
994  * states are software abstractions used at various levels to communicate
995  * pool state.
996  */
997 typedef enum pool_state {
998 	POOL_STATE_ACTIVE = 0,		/* In active use		*/
999 	POOL_STATE_EXPORTED,		/* Explicitly exported		*/
1000 	POOL_STATE_DESTROYED,		/* Explicitly destroyed		*/
1001 	POOL_STATE_SPARE,		/* Reserved for hot spare use	*/
1002 	POOL_STATE_L2CACHE,		/* Level 2 ARC device		*/
1003 	POOL_STATE_UNINITIALIZED,	/* Internal spa_t state		*/
1004 	POOL_STATE_UNAVAIL,		/* Internal libzfs state	*/
1005 	POOL_STATE_POTENTIALLY_ACTIVE	/* Internal libzfs state	*/
1006 } pool_state_t;
1007 
1008 /*
1009  * mmp state. The following states provide additional detail describing
1010  * why a pool couldn't be safely imported.
1011  */
1012 typedef enum mmp_state {
1013 	MMP_STATE_ACTIVE = 0,		/* In active use		*/
1014 	MMP_STATE_INACTIVE,		/* Inactive and safe to import	*/
1015 	MMP_STATE_NO_HOSTID		/* System hostid is not set	*/
1016 } mmp_state_t;
1017 
1018 /*
1019  * Scan Functions.
1020  */
1021 typedef enum pool_scan_func {
1022 	POOL_SCAN_NONE,
1023 	POOL_SCAN_SCRUB,
1024 	POOL_SCAN_RESILVER,
1025 	POOL_SCAN_FUNCS
1026 } pool_scan_func_t;
1027 
1028 /*
1029  * Used to control scrub pause and resume.
1030  */
1031 typedef enum pool_scrub_cmd {
1032 	POOL_SCRUB_NORMAL = 0,
1033 	POOL_SCRUB_PAUSE,
1034 	POOL_SCRUB_FLAGS_END
1035 } pool_scrub_cmd_t;
1036 
1037 typedef enum {
1038 	CS_NONE,
1039 	CS_CHECKPOINT_EXISTS,
1040 	CS_CHECKPOINT_DISCARDING,
1041 	CS_NUM_STATES
1042 } checkpoint_state_t;
1043 
1044 typedef struct pool_checkpoint_stat {
1045 	uint64_t pcs_state;		/* checkpoint_state_t */
1046 	uint64_t pcs_start_time;	/* time checkpoint/discard started */
1047 	uint64_t pcs_space;		/* checkpointed space */
1048 } pool_checkpoint_stat_t;
1049 
1050 /*
1051  * ZIO types.  Needed to interpret vdev statistics below.
1052  */
1053 typedef enum zio_type {
1054 	ZIO_TYPE_NULL = 0,
1055 	ZIO_TYPE_READ,
1056 	ZIO_TYPE_WRITE,
1057 	ZIO_TYPE_FREE,
1058 	ZIO_TYPE_CLAIM,
1059 	ZIO_TYPE_IOCTL,
1060 	ZIO_TYPE_TRIM,
1061 	ZIO_TYPES
1062 } zio_type_t;
1063 
1064 /*
1065  * Pool statistics.  Note: all fields should be 64-bit because this
1066  * is passed between kernel and userland as an nvlist uint64 array.
1067  */
1068 typedef struct pool_scan_stat {
1069 	/* values stored on disk */
1070 	uint64_t	pss_func;	/* pool_scan_func_t */
1071 	uint64_t	pss_state;	/* dsl_scan_state_t */
1072 	uint64_t	pss_start_time;	/* scan start time */
1073 	uint64_t	pss_end_time;	/* scan end time */
1074 	uint64_t	pss_to_examine;	/* total bytes to scan */
1075 	uint64_t	pss_examined;	/* total bytes located by scanner */
1076 	uint64_t	pss_to_process; /* total bytes to process */
1077 	uint64_t	pss_processed;	/* total processed bytes */
1078 	uint64_t	pss_errors;	/* scan errors	*/
1079 
1080 	/* values not stored on disk */
1081 	uint64_t	pss_pass_exam; /* examined bytes per scan pass */
1082 	uint64_t	pss_pass_start;	/* start time of a scan pass */
1083 	uint64_t	pss_pass_scrub_pause; /* pause time of a scrub pass */
1084 	/* cumulative time scrub spent paused, needed for rate calculation */
1085 	uint64_t	pss_pass_scrub_spent_paused;
1086 	uint64_t	pss_pass_issued; /* issued bytes per scan pass */
1087 	uint64_t	pss_issued;	/* total bytes checked by scanner */
1088 } pool_scan_stat_t;
1089 
1090 typedef struct pool_removal_stat {
1091 	uint64_t prs_state; /* dsl_scan_state_t */
1092 	uint64_t prs_removing_vdev;
1093 	uint64_t prs_start_time;
1094 	uint64_t prs_end_time;
1095 	uint64_t prs_to_copy; /* bytes that need to be copied */
1096 	uint64_t prs_copied; /* bytes copied so far */
1097 	/*
1098 	 * bytes of memory used for indirect mappings.
1099 	 * This includes all removed vdevs.
1100 	 */
1101 	uint64_t prs_mapping_memory;
1102 } pool_removal_stat_t;
1103 
1104 typedef enum dsl_scan_state {
1105 	DSS_NONE,
1106 	DSS_SCANNING,
1107 	DSS_FINISHED,
1108 	DSS_CANCELED,
1109 	DSS_NUM_STATES
1110 } dsl_scan_state_t;
1111 
1112 typedef struct vdev_rebuild_stat {
1113 	uint64_t vrs_state;		/* vdev_rebuild_state_t */
1114 	uint64_t vrs_start_time;	/* time_t */
1115 	uint64_t vrs_end_time;		/* time_t */
1116 	uint64_t vrs_scan_time_ms;	/* total run time (millisecs) */
1117 	uint64_t vrs_bytes_scanned;	/* allocated bytes scanned */
1118 	uint64_t vrs_bytes_issued;	/* read bytes issued */
1119 	uint64_t vrs_bytes_rebuilt;	/* rebuilt bytes */
1120 	uint64_t vrs_bytes_est;		/* total bytes to scan */
1121 	uint64_t vrs_errors;		/* scanning errors */
1122 	uint64_t vrs_pass_time_ms;	/* pass run time (millisecs) */
1123 	uint64_t vrs_pass_bytes_scanned; /* bytes scanned since start/resume */
1124 	uint64_t vrs_pass_bytes_issued;	/* bytes rebuilt since start/resume */
1125 } vdev_rebuild_stat_t;
1126 
1127 /*
1128  * Errata described by https://openzfs.github.io/openzfs-docs/msg/ZFS-8000-ER.
1129  * The ordering of this enum must be maintained to ensure the errata identifiers
1130  * map to the correct documentation.  New errata may only be appended to the
1131  * list and must contain corresponding documentation at the above link.
1132  */
1133 typedef enum zpool_errata {
1134 	ZPOOL_ERRATA_NONE,
1135 	ZPOOL_ERRATA_ZOL_2094_SCRUB,
1136 	ZPOOL_ERRATA_ZOL_2094_ASYNC_DESTROY,
1137 	ZPOOL_ERRATA_ZOL_6845_ENCRYPTION,
1138 	ZPOOL_ERRATA_ZOL_8308_ENCRYPTION,
1139 } zpool_errata_t;
1140 
1141 /*
1142  * Vdev statistics.  Note: all fields should be 64-bit because this
1143  * is passed between kernel and user land as an nvlist uint64 array.
1144  *
1145  * The vs_ops[] and vs_bytes[] arrays must always be an array size of 6 in
1146  * order to keep subsequent members at their known fixed offsets.  When
1147  * adding a new field it must be added to the end the structure.
1148  */
1149 #define	VS_ZIO_TYPES	6
1150 
1151 typedef struct vdev_stat {
1152 	hrtime_t	vs_timestamp;		/* time since vdev load	*/
1153 	uint64_t	vs_state;		/* vdev state		*/
1154 	uint64_t	vs_aux;			/* see vdev_aux_t	*/
1155 	uint64_t	vs_alloc;		/* space allocated	*/
1156 	uint64_t	vs_space;		/* total capacity	*/
1157 	uint64_t	vs_dspace;		/* deflated capacity	*/
1158 	uint64_t	vs_rsize;		/* replaceable dev size */
1159 	uint64_t	vs_esize;		/* expandable dev size */
1160 	uint64_t	vs_ops[VS_ZIO_TYPES];	/* operation count	*/
1161 	uint64_t	vs_bytes[VS_ZIO_TYPES];	/* bytes read/written	*/
1162 	uint64_t	vs_read_errors;		/* read errors		*/
1163 	uint64_t	vs_write_errors;	/* write errors		*/
1164 	uint64_t	vs_checksum_errors;	/* checksum errors	*/
1165 	uint64_t	vs_initialize_errors;	/* initializing errors	*/
1166 	uint64_t	vs_self_healed;		/* self-healed bytes	*/
1167 	uint64_t	vs_scan_removing;	/* removing?	*/
1168 	uint64_t	vs_scan_processed;	/* scan processed bytes	*/
1169 	uint64_t	vs_fragmentation;	/* device fragmentation */
1170 	uint64_t	vs_initialize_bytes_done; /* bytes initialized */
1171 	uint64_t	vs_initialize_bytes_est; /* total bytes to initialize */
1172 	uint64_t	vs_initialize_state;	/* vdev_initializing_state_t */
1173 	uint64_t	vs_initialize_action_time; /* time_t */
1174 	uint64_t	vs_checkpoint_space;    /* checkpoint-consumed space */
1175 	uint64_t	vs_resilver_deferred;	/* resilver deferred	*/
1176 	uint64_t	vs_slow_ios;		/* slow IOs */
1177 	uint64_t	vs_trim_errors;		/* trimming errors	*/
1178 	uint64_t	vs_trim_notsup;		/* supported by device */
1179 	uint64_t	vs_trim_bytes_done;	/* bytes trimmed */
1180 	uint64_t	vs_trim_bytes_est;	/* total bytes to trim */
1181 	uint64_t	vs_trim_state;		/* vdev_trim_state_t */
1182 	uint64_t	vs_trim_action_time;	/* time_t */
1183 	uint64_t	vs_rebuild_processed;	/* bytes rebuilt */
1184 	uint64_t	vs_configured_ashift;   /* TLV vdev_ashift */
1185 	uint64_t	vs_logical_ashift;	/* vdev_logical_ashift  */
1186 	uint64_t	vs_physical_ashift;	/* vdev_physical_ashift */
1187 	uint64_t	vs_noalloc;		/* allocations halted?	*/
1188 } vdev_stat_t;
1189 
1190 #define	VDEV_STAT_VALID(field, uint64_t_field_count) \
1191 ((uint64_t_field_count * sizeof (uint64_t)) >=	 \
1192 	(offsetof(vdev_stat_t, field) + sizeof (((vdev_stat_t *)NULL)->field)))
1193 
1194 /*
1195  * Extended stats
1196  *
1197  * These are stats which aren't included in the original iostat output.  For
1198  * convenience, they are grouped together in vdev_stat_ex, although each stat
1199  * is individually exported as an nvlist.
1200  */
1201 typedef struct vdev_stat_ex {
1202 	/* Number of ZIOs issued to disk and waiting to finish */
1203 	uint64_t vsx_active_queue[ZIO_PRIORITY_NUM_QUEUEABLE];
1204 
1205 	/* Number of ZIOs pending to be issued to disk */
1206 	uint64_t vsx_pend_queue[ZIO_PRIORITY_NUM_QUEUEABLE];
1207 
1208 	/*
1209 	 * Below are the histograms for various latencies. Buckets are in
1210 	 * units of nanoseconds.
1211 	 */
1212 
1213 	/*
1214 	 * 2^37 nanoseconds = 134s. Timeouts will probably start kicking in
1215 	 * before this.
1216 	 */
1217 #define	VDEV_L_HISTO_BUCKETS 37		/* Latency histo buckets */
1218 #define	VDEV_RQ_HISTO_BUCKETS 25	/* Request size histo buckets */
1219 
1220 	/* Amount of time in ZIO queue (ns) */
1221 	uint64_t vsx_queue_histo[ZIO_PRIORITY_NUM_QUEUEABLE]
1222 	    [VDEV_L_HISTO_BUCKETS];
1223 
1224 	/* Total ZIO latency (ns).  Includes queuing and disk access time */
1225 	uint64_t vsx_total_histo[ZIO_TYPES][VDEV_L_HISTO_BUCKETS];
1226 
1227 	/* Amount of time to read/write the disk (ns) */
1228 	uint64_t vsx_disk_histo[ZIO_TYPES][VDEV_L_HISTO_BUCKETS];
1229 
1230 	/* "lookup the bucket for a value" histogram macros */
1231 #define	HISTO(val, buckets) (val != 0 ? MIN(highbit64(val) - 1, \
1232 	    buckets - 1) : 0)
1233 #define	L_HISTO(a) HISTO(a, VDEV_L_HISTO_BUCKETS)
1234 #define	RQ_HISTO(a) HISTO(a, VDEV_RQ_HISTO_BUCKETS)
1235 
1236 	/* Physical IO histogram */
1237 	uint64_t vsx_ind_histo[ZIO_PRIORITY_NUM_QUEUEABLE]
1238 	    [VDEV_RQ_HISTO_BUCKETS];
1239 
1240 	/* Delegated (aggregated) physical IO histogram */
1241 	uint64_t vsx_agg_histo[ZIO_PRIORITY_NUM_QUEUEABLE]
1242 	    [VDEV_RQ_HISTO_BUCKETS];
1243 
1244 } vdev_stat_ex_t;
1245 
1246 /*
1247  * Initialize functions.
1248  */
1249 typedef enum pool_initialize_func {
1250 	POOL_INITIALIZE_START,
1251 	POOL_INITIALIZE_CANCEL,
1252 	POOL_INITIALIZE_SUSPEND,
1253 	POOL_INITIALIZE_FUNCS
1254 } pool_initialize_func_t;
1255 
1256 /*
1257  * TRIM functions.
1258  */
1259 typedef enum pool_trim_func {
1260 	POOL_TRIM_START,
1261 	POOL_TRIM_CANCEL,
1262 	POOL_TRIM_SUSPEND,
1263 	POOL_TRIM_FUNCS
1264 } pool_trim_func_t;
1265 
1266 /*
1267  * DDT statistics.  Note: all fields should be 64-bit because this
1268  * is passed between kernel and userland as an nvlist uint64 array.
1269  */
1270 typedef struct ddt_object {
1271 	uint64_t	ddo_count;	/* number of elements in ddt	*/
1272 	uint64_t	ddo_dspace;	/* size of ddt on disk		*/
1273 	uint64_t	ddo_mspace;	/* size of ddt in-core		*/
1274 } ddt_object_t;
1275 
1276 typedef struct ddt_stat {
1277 	uint64_t	dds_blocks;	/* blocks			*/
1278 	uint64_t	dds_lsize;	/* logical size			*/
1279 	uint64_t	dds_psize;	/* physical size		*/
1280 	uint64_t	dds_dsize;	/* deflated allocated size	*/
1281 	uint64_t	dds_ref_blocks;	/* referenced blocks		*/
1282 	uint64_t	dds_ref_lsize;	/* referenced lsize * refcnt	*/
1283 	uint64_t	dds_ref_psize;	/* referenced psize * refcnt	*/
1284 	uint64_t	dds_ref_dsize;	/* referenced dsize * refcnt	*/
1285 } ddt_stat_t;
1286 
1287 typedef struct ddt_histogram {
1288 	ddt_stat_t	ddh_stat[64];	/* power-of-two histogram buckets */
1289 } ddt_histogram_t;
1290 
1291 #define	ZVOL_DRIVER	"zvol"
1292 #define	ZFS_DRIVER	"zfs"
1293 #define	ZFS_DEV		"/dev/zfs"
1294 
1295 #define	ZFS_SUPER_MAGIC	0x2fc12fc1
1296 
1297 /* general zvol path */
1298 #define	ZVOL_DIR		"/dev/zvol/"
1299 
1300 #define	ZVOL_MAJOR		230
1301 #define	ZVOL_MINOR_BITS		4
1302 #define	ZVOL_MINOR_MASK		((1U << ZVOL_MINOR_BITS) - 1)
1303 #define	ZVOL_MINORS		(1 << 4)
1304 #define	ZVOL_DEV_NAME		"zd"
1305 
1306 #define	ZVOL_PROP_NAME		"name"
1307 #define	ZVOL_DEFAULT_BLOCKSIZE	16384
1308 
1309 typedef enum {
1310 	VDEV_INITIALIZE_NONE,
1311 	VDEV_INITIALIZE_ACTIVE,
1312 	VDEV_INITIALIZE_CANCELED,
1313 	VDEV_INITIALIZE_SUSPENDED,
1314 	VDEV_INITIALIZE_COMPLETE
1315 } vdev_initializing_state_t;
1316 
1317 typedef enum {
1318 	VDEV_TRIM_NONE,
1319 	VDEV_TRIM_ACTIVE,
1320 	VDEV_TRIM_CANCELED,
1321 	VDEV_TRIM_SUSPENDED,
1322 	VDEV_TRIM_COMPLETE,
1323 } vdev_trim_state_t;
1324 
1325 typedef enum {
1326 	VDEV_REBUILD_NONE,
1327 	VDEV_REBUILD_ACTIVE,
1328 	VDEV_REBUILD_CANCELED,
1329 	VDEV_REBUILD_COMPLETE,
1330 } vdev_rebuild_state_t;
1331 
1332 /*
1333  * nvlist name constants. Facilitate restricting snapshot iteration range for
1334  * the "list next snapshot" ioctl
1335  */
1336 #define	SNAP_ITER_MIN_TXG	"snap_iter_min_txg"
1337 #define	SNAP_ITER_MAX_TXG	"snap_iter_max_txg"
1338 
1339 /*
1340  * /dev/zfs ioctl numbers.
1341  *
1342  * These numbers cannot change over time. New ioctl numbers must be appended.
1343  */
1344 typedef enum zfs_ioc {
1345 	/*
1346 	 * Core features - 81/128 numbers reserved.
1347 	 */
1348 #ifdef __FreeBSD__
1349 	ZFS_IOC_FIRST =	0,
1350 #else
1351 	ZFS_IOC_FIRST =	('Z' << 8),
1352 #endif
1353 	ZFS_IOC = ZFS_IOC_FIRST,
1354 	ZFS_IOC_POOL_CREATE = ZFS_IOC_FIRST,	/* 0x5a00 */
1355 	ZFS_IOC_POOL_DESTROY,			/* 0x5a01 */
1356 	ZFS_IOC_POOL_IMPORT,			/* 0x5a02 */
1357 	ZFS_IOC_POOL_EXPORT,			/* 0x5a03 */
1358 	ZFS_IOC_POOL_CONFIGS,			/* 0x5a04 */
1359 	ZFS_IOC_POOL_STATS,			/* 0x5a05 */
1360 	ZFS_IOC_POOL_TRYIMPORT,			/* 0x5a06 */
1361 	ZFS_IOC_POOL_SCAN,			/* 0x5a07 */
1362 	ZFS_IOC_POOL_FREEZE,			/* 0x5a08 */
1363 	ZFS_IOC_POOL_UPGRADE,			/* 0x5a09 */
1364 	ZFS_IOC_POOL_GET_HISTORY,		/* 0x5a0a */
1365 	ZFS_IOC_VDEV_ADD,			/* 0x5a0b */
1366 	ZFS_IOC_VDEV_REMOVE,			/* 0x5a0c */
1367 	ZFS_IOC_VDEV_SET_STATE,			/* 0x5a0d */
1368 	ZFS_IOC_VDEV_ATTACH,			/* 0x5a0e */
1369 	ZFS_IOC_VDEV_DETACH,			/* 0x5a0f */
1370 	ZFS_IOC_VDEV_SETPATH,			/* 0x5a10 */
1371 	ZFS_IOC_VDEV_SETFRU,			/* 0x5a11 */
1372 	ZFS_IOC_OBJSET_STATS,			/* 0x5a12 */
1373 	ZFS_IOC_OBJSET_ZPLPROPS,		/* 0x5a13 */
1374 	ZFS_IOC_DATASET_LIST_NEXT,		/* 0x5a14 */
1375 	ZFS_IOC_SNAPSHOT_LIST_NEXT,		/* 0x5a15 */
1376 	ZFS_IOC_SET_PROP,			/* 0x5a16 */
1377 	ZFS_IOC_CREATE,				/* 0x5a17 */
1378 	ZFS_IOC_DESTROY,			/* 0x5a18 */
1379 	ZFS_IOC_ROLLBACK,			/* 0x5a19 */
1380 	ZFS_IOC_RENAME,				/* 0x5a1a */
1381 	ZFS_IOC_RECV,				/* 0x5a1b */
1382 	ZFS_IOC_SEND,				/* 0x5a1c */
1383 	ZFS_IOC_INJECT_FAULT,			/* 0x5a1d */
1384 	ZFS_IOC_CLEAR_FAULT,			/* 0x5a1e */
1385 	ZFS_IOC_INJECT_LIST_NEXT,		/* 0x5a1f */
1386 	ZFS_IOC_ERROR_LOG,			/* 0x5a20 */
1387 	ZFS_IOC_CLEAR,				/* 0x5a21 */
1388 	ZFS_IOC_PROMOTE,			/* 0x5a22 */
1389 	ZFS_IOC_SNAPSHOT,			/* 0x5a23 */
1390 	ZFS_IOC_DSOBJ_TO_DSNAME,		/* 0x5a24 */
1391 	ZFS_IOC_OBJ_TO_PATH,			/* 0x5a25 */
1392 	ZFS_IOC_POOL_SET_PROPS,			/* 0x5a26 */
1393 	ZFS_IOC_POOL_GET_PROPS,			/* 0x5a27 */
1394 	ZFS_IOC_SET_FSACL,			/* 0x5a28 */
1395 	ZFS_IOC_GET_FSACL,			/* 0x5a29 */
1396 	ZFS_IOC_SHARE,				/* 0x5a2a */
1397 	ZFS_IOC_INHERIT_PROP,			/* 0x5a2b */
1398 	ZFS_IOC_SMB_ACL,			/* 0x5a2c */
1399 	ZFS_IOC_USERSPACE_ONE,			/* 0x5a2d */
1400 	ZFS_IOC_USERSPACE_MANY,			/* 0x5a2e */
1401 	ZFS_IOC_USERSPACE_UPGRADE,		/* 0x5a2f */
1402 	ZFS_IOC_HOLD,				/* 0x5a30 */
1403 	ZFS_IOC_RELEASE,			/* 0x5a31 */
1404 	ZFS_IOC_GET_HOLDS,			/* 0x5a32 */
1405 	ZFS_IOC_OBJSET_RECVD_PROPS,		/* 0x5a33 */
1406 	ZFS_IOC_VDEV_SPLIT,			/* 0x5a34 */
1407 	ZFS_IOC_NEXT_OBJ,			/* 0x5a35 */
1408 	ZFS_IOC_DIFF,				/* 0x5a36 */
1409 	ZFS_IOC_TMP_SNAPSHOT,			/* 0x5a37 */
1410 	ZFS_IOC_OBJ_TO_STATS,			/* 0x5a38 */
1411 	ZFS_IOC_SPACE_WRITTEN,			/* 0x5a39 */
1412 	ZFS_IOC_SPACE_SNAPS,			/* 0x5a3a */
1413 	ZFS_IOC_DESTROY_SNAPS,			/* 0x5a3b */
1414 	ZFS_IOC_POOL_REGUID,			/* 0x5a3c */
1415 	ZFS_IOC_POOL_REOPEN,			/* 0x5a3d */
1416 	ZFS_IOC_SEND_PROGRESS,			/* 0x5a3e */
1417 	ZFS_IOC_LOG_HISTORY,			/* 0x5a3f */
1418 	ZFS_IOC_SEND_NEW,			/* 0x5a40 */
1419 	ZFS_IOC_SEND_SPACE,			/* 0x5a41 */
1420 	ZFS_IOC_CLONE,				/* 0x5a42 */
1421 	ZFS_IOC_BOOKMARK,			/* 0x5a43 */
1422 	ZFS_IOC_GET_BOOKMARKS,			/* 0x5a44 */
1423 	ZFS_IOC_DESTROY_BOOKMARKS,		/* 0x5a45 */
1424 	ZFS_IOC_RECV_NEW,			/* 0x5a46 */
1425 	ZFS_IOC_POOL_SYNC,			/* 0x5a47 */
1426 	ZFS_IOC_CHANNEL_PROGRAM,		/* 0x5a48 */
1427 	ZFS_IOC_LOAD_KEY,			/* 0x5a49 */
1428 	ZFS_IOC_UNLOAD_KEY,			/* 0x5a4a */
1429 	ZFS_IOC_CHANGE_KEY,			/* 0x5a4b */
1430 	ZFS_IOC_REMAP,				/* 0x5a4c */
1431 	ZFS_IOC_POOL_CHECKPOINT,		/* 0x5a4d */
1432 	ZFS_IOC_POOL_DISCARD_CHECKPOINT,	/* 0x5a4e */
1433 	ZFS_IOC_POOL_INITIALIZE,		/* 0x5a4f */
1434 	ZFS_IOC_POOL_TRIM,			/* 0x5a50 */
1435 	ZFS_IOC_REDACT,				/* 0x5a51 */
1436 	ZFS_IOC_GET_BOOKMARK_PROPS,		/* 0x5a52 */
1437 	ZFS_IOC_WAIT,				/* 0x5a53 */
1438 	ZFS_IOC_WAIT_FS,			/* 0x5a54 */
1439 	ZFS_IOC_VDEV_GET_PROPS,			/* 0x5a55 */
1440 	ZFS_IOC_VDEV_SET_PROPS,			/* 0x5a56 */
1441 
1442 	/*
1443 	 * Per-platform (Optional) - 8/128 numbers reserved.
1444 	 */
1445 	ZFS_IOC_PLATFORM = ZFS_IOC_FIRST + 0x80,
1446 	ZFS_IOC_EVENTS_NEXT,			/* 0x81 (Linux) */
1447 	ZFS_IOC_EVENTS_CLEAR,			/* 0x82 (Linux) */
1448 	ZFS_IOC_EVENTS_SEEK,			/* 0x83 (Linux) */
1449 	ZFS_IOC_NEXTBOOT,			/* 0x84 (FreeBSD) */
1450 	ZFS_IOC_JAIL,				/* 0x85 (FreeBSD) */
1451 	ZFS_IOC_UNJAIL,				/* 0x86 (FreeBSD) */
1452 	ZFS_IOC_SET_BOOTENV,			/* 0x87 */
1453 	ZFS_IOC_GET_BOOTENV,			/* 0x88 */
1454 	ZFS_IOC_LAST
1455 } zfs_ioc_t;
1456 
1457 /*
1458  * zvol ioctl to get dataset name
1459  */
1460 #define	BLKZNAME		_IOR(0x12, 125, char[ZFS_MAX_DATASET_NAME_LEN])
1461 
1462 #ifdef __linux__
1463 
1464 /*
1465  * IOCTLs to update and retrieve additional file level attributes on
1466  * Linux.
1467  */
1468 #define	ZFS_IOC_GETDOSFLAGS	_IOR(0x83, 1, uint64_t)
1469 #define	ZFS_IOC_SETDOSFLAGS	_IOW(0x83, 2, uint64_t)
1470 
1471 /*
1472  * Additional file level attributes, that are stored
1473  * in the upper half of z_pflags
1474  */
1475 #define	ZFS_READONLY		0x0000000100000000ull
1476 #define	ZFS_HIDDEN		0x0000000200000000ull
1477 #define	ZFS_SYSTEM		0x0000000400000000ull
1478 #define	ZFS_ARCHIVE		0x0000000800000000ull
1479 #define	ZFS_IMMUTABLE		0x0000001000000000ull
1480 #define	ZFS_NOUNLINK		0x0000002000000000ull
1481 #define	ZFS_APPENDONLY		0x0000004000000000ull
1482 #define	ZFS_NODUMP		0x0000008000000000ull
1483 #define	ZFS_OPAQUE		0x0000010000000000ull
1484 #define	ZFS_AV_QUARANTINED	0x0000020000000000ull
1485 #define	ZFS_AV_MODIFIED		0x0000040000000000ull
1486 #define	ZFS_REPARSE		0x0000080000000000ull
1487 #define	ZFS_OFFLINE		0x0000100000000000ull
1488 #define	ZFS_SPARSE		0x0000200000000000ull
1489 
1490 #define	ZFS_DOS_FL_USER_VISIBLE	(ZFS_IMMUTABLE | ZFS_APPENDONLY | \
1491 	    ZFS_NOUNLINK | ZFS_ARCHIVE | ZFS_NODUMP | ZFS_SYSTEM | \
1492 	    ZFS_HIDDEN | ZFS_READONLY | ZFS_REPARSE | ZFS_OFFLINE | \
1493 	    ZFS_SPARSE)
1494 
1495 #endif
1496 
1497 /*
1498  * ZFS-specific error codes used for returning descriptive errors
1499  * to the userland through zfs ioctls.
1500  *
1501  * The enum implicitly includes all the error codes from errno.h.
1502  * New code should use and extend this enum for errors that are
1503  * not described precisely by generic errno codes.
1504  *
1505  * These numbers should not change over time. New entries should be appended.
1506  *
1507  * (Keep in sync with contrib/pyzfs/libzfs_core/_constants.py)
1508  */
1509 typedef enum {
1510 	ZFS_ERR_CHECKPOINT_EXISTS = 1024,
1511 	ZFS_ERR_DISCARDING_CHECKPOINT,
1512 	ZFS_ERR_NO_CHECKPOINT,
1513 	ZFS_ERR_DEVRM_IN_PROGRESS,
1514 	ZFS_ERR_VDEV_TOO_BIG,
1515 	ZFS_ERR_IOC_CMD_UNAVAIL,
1516 	ZFS_ERR_IOC_ARG_UNAVAIL,
1517 	ZFS_ERR_IOC_ARG_REQUIRED,
1518 	ZFS_ERR_IOC_ARG_BADTYPE,
1519 	ZFS_ERR_WRONG_PARENT,
1520 	ZFS_ERR_FROM_IVSET_GUID_MISSING,
1521 	ZFS_ERR_FROM_IVSET_GUID_MISMATCH,
1522 	ZFS_ERR_SPILL_BLOCK_FLAG_MISSING,
1523 	ZFS_ERR_UNKNOWN_SEND_STREAM_FEATURE,
1524 	ZFS_ERR_EXPORT_IN_PROGRESS,
1525 	ZFS_ERR_BOOKMARK_SOURCE_NOT_ANCESTOR,
1526 	ZFS_ERR_STREAM_TRUNCATED,
1527 	ZFS_ERR_STREAM_LARGE_BLOCK_MISMATCH,
1528 	ZFS_ERR_RESILVER_IN_PROGRESS,
1529 	ZFS_ERR_REBUILD_IN_PROGRESS,
1530 	ZFS_ERR_BADPROP,
1531 	ZFS_ERR_VDEV_NOTSUP,
1532 } zfs_errno_t;
1533 
1534 /*
1535  * Internal SPA load state.  Used by FMA diagnosis engine.
1536  */
1537 typedef enum {
1538 	SPA_LOAD_NONE,		/* no load in progress	*/
1539 	SPA_LOAD_OPEN,		/* normal open		*/
1540 	SPA_LOAD_IMPORT,	/* import in progress	*/
1541 	SPA_LOAD_TRYIMPORT,	/* tryimport in progress */
1542 	SPA_LOAD_RECOVER,	/* recovery requested	*/
1543 	SPA_LOAD_ERROR,		/* load failed		*/
1544 	SPA_LOAD_CREATE		/* creation in progress */
1545 } spa_load_state_t;
1546 
1547 typedef enum {
1548 	ZPOOL_WAIT_CKPT_DISCARD,
1549 	ZPOOL_WAIT_FREE,
1550 	ZPOOL_WAIT_INITIALIZE,
1551 	ZPOOL_WAIT_REPLACE,
1552 	ZPOOL_WAIT_REMOVE,
1553 	ZPOOL_WAIT_RESILVER,
1554 	ZPOOL_WAIT_SCRUB,
1555 	ZPOOL_WAIT_TRIM,
1556 	ZPOOL_WAIT_NUM_ACTIVITIES
1557 } zpool_wait_activity_t;
1558 
1559 typedef enum {
1560 	ZFS_WAIT_DELETEQ,
1561 	ZFS_WAIT_NUM_ACTIVITIES
1562 } zfs_wait_activity_t;
1563 
1564 /*
1565  * Bookmark name values.
1566  */
1567 #define	ZPOOL_ERR_LIST		"error list"
1568 #define	ZPOOL_ERR_DATASET	"dataset"
1569 #define	ZPOOL_ERR_OBJECT	"object"
1570 
1571 #define	HIS_MAX_RECORD_LEN	(MAXPATHLEN + MAXPATHLEN + 1)
1572 
1573 /*
1574  * The following are names used in the nvlist describing
1575  * the pool's history log.
1576  */
1577 #define	ZPOOL_HIST_RECORD	"history record"
1578 #define	ZPOOL_HIST_TIME		"history time"
1579 #define	ZPOOL_HIST_CMD		"history command"
1580 #define	ZPOOL_HIST_WHO		"history who"
1581 #define	ZPOOL_HIST_ZONE		"history zone"
1582 #define	ZPOOL_HIST_HOST		"history hostname"
1583 #define	ZPOOL_HIST_TXG		"history txg"
1584 #define	ZPOOL_HIST_INT_EVENT	"history internal event"
1585 #define	ZPOOL_HIST_INT_STR	"history internal str"
1586 #define	ZPOOL_HIST_INT_NAME	"internal_name"
1587 #define	ZPOOL_HIST_IOCTL	"ioctl"
1588 #define	ZPOOL_HIST_INPUT_NVL	"in_nvl"
1589 #define	ZPOOL_HIST_OUTPUT_NVL	"out_nvl"
1590 #define	ZPOOL_HIST_OUTPUT_SIZE	"out_size"
1591 #define	ZPOOL_HIST_DSNAME	"dsname"
1592 #define	ZPOOL_HIST_DSID		"dsid"
1593 #define	ZPOOL_HIST_ERRNO	"errno"
1594 #define	ZPOOL_HIST_ELAPSED_NS	"elapsed_ns"
1595 
1596 /*
1597  * Special nvlist name that will not have its args recorded in the pool's
1598  * history log.
1599  */
1600 #define	ZPOOL_HIDDEN_ARGS	"hidden_args"
1601 
1602 /*
1603  * The following are names used when invoking ZFS_IOC_POOL_INITIALIZE.
1604  */
1605 #define	ZPOOL_INITIALIZE_COMMAND	"initialize_command"
1606 #define	ZPOOL_INITIALIZE_VDEVS		"initialize_vdevs"
1607 
1608 /*
1609  * The following are names used when invoking ZFS_IOC_POOL_TRIM.
1610  */
1611 #define	ZPOOL_TRIM_COMMAND		"trim_command"
1612 #define	ZPOOL_TRIM_VDEVS		"trim_vdevs"
1613 #define	ZPOOL_TRIM_RATE			"trim_rate"
1614 #define	ZPOOL_TRIM_SECURE		"trim_secure"
1615 
1616 /*
1617  * The following are names used when invoking ZFS_IOC_POOL_WAIT.
1618  */
1619 #define	ZPOOL_WAIT_ACTIVITY		"wait_activity"
1620 #define	ZPOOL_WAIT_TAG			"wait_tag"
1621 #define	ZPOOL_WAIT_WAITED		"wait_waited"
1622 
1623 /*
1624  * The following are names used when invoking ZFS_IOC_VDEV_GET_PROP.
1625  */
1626 #define	ZPOOL_VDEV_PROPS_GET_VDEV	"vdevprops_get_vdev"
1627 #define	ZPOOL_VDEV_PROPS_GET_PROPS	"vdevprops_get_props"
1628 
1629 /*
1630  * The following are names used when invoking ZFS_IOC_VDEV_SET_PROP.
1631  */
1632 #define	ZPOOL_VDEV_PROPS_SET_VDEV	"vdevprops_set_vdev"
1633 #define	ZPOOL_VDEV_PROPS_SET_PROPS	"vdevprops_set_props"
1634 
1635 /*
1636  * The following are names used when invoking ZFS_IOC_WAIT_FS.
1637  */
1638 #define	ZFS_WAIT_ACTIVITY		"wait_activity"
1639 #define	ZFS_WAIT_WAITED			"wait_waited"
1640 
1641 /*
1642  * Flags for ZFS_IOC_VDEV_SET_STATE
1643  */
1644 #define	ZFS_ONLINE_CHECKREMOVE	0x1
1645 #define	ZFS_ONLINE_UNSPARE	0x2
1646 #define	ZFS_ONLINE_FORCEFAULT	0x4
1647 #define	ZFS_ONLINE_EXPAND	0x8
1648 #define	ZFS_OFFLINE_TEMPORARY	0x1
1649 
1650 /*
1651  * Flags for ZFS_IOC_POOL_IMPORT
1652  */
1653 #define	ZFS_IMPORT_NORMAL	0x0
1654 #define	ZFS_IMPORT_VERBATIM	0x1
1655 #define	ZFS_IMPORT_ANY_HOST	0x2
1656 #define	ZFS_IMPORT_MISSING_LOG	0x4
1657 #define	ZFS_IMPORT_ONLY		0x8
1658 #define	ZFS_IMPORT_TEMP_NAME	0x10
1659 #define	ZFS_IMPORT_SKIP_MMP	0x20
1660 #define	ZFS_IMPORT_LOAD_KEYS	0x40
1661 #define	ZFS_IMPORT_CHECKPOINT	0x80
1662 
1663 /*
1664  * Channel program argument/return nvlist keys and defaults.
1665  */
1666 #define	ZCP_ARG_PROGRAM		"program"
1667 #define	ZCP_ARG_ARGLIST		"arg"
1668 #define	ZCP_ARG_SYNC		"sync"
1669 #define	ZCP_ARG_INSTRLIMIT	"instrlimit"
1670 #define	ZCP_ARG_MEMLIMIT	"memlimit"
1671 
1672 #define	ZCP_ARG_CLIARGV		"argv"
1673 
1674 #define	ZCP_RET_ERROR		"error"
1675 #define	ZCP_RET_RETURN		"return"
1676 
1677 #define	ZCP_DEFAULT_INSTRLIMIT	(10 * 1000 * 1000)
1678 #define	ZCP_MAX_INSTRLIMIT	(10 * ZCP_DEFAULT_INSTRLIMIT)
1679 #define	ZCP_DEFAULT_MEMLIMIT	(10 * 1024 * 1024)
1680 #define	ZCP_MAX_MEMLIMIT	(10 * ZCP_DEFAULT_MEMLIMIT)
1681 
1682 /*
1683  * Sysevent payload members.  ZFS will generate the following sysevents with the
1684  * given payloads:
1685  *
1686  *	ESC_ZFS_RESILVER_START
1687  *	ESC_ZFS_RESILVER_FINISH
1688  *
1689  *		ZFS_EV_POOL_NAME	DATA_TYPE_STRING
1690  *		ZFS_EV_POOL_GUID	DATA_TYPE_UINT64
1691  *		ZFS_EV_RESILVER_TYPE	DATA_TYPE_STRING
1692  *
1693  *	ESC_ZFS_POOL_DESTROY
1694  *	ESC_ZFS_POOL_REGUID
1695  *
1696  *		ZFS_EV_POOL_NAME	DATA_TYPE_STRING
1697  *		ZFS_EV_POOL_GUID	DATA_TYPE_UINT64
1698  *
1699  *	ESC_ZFS_VDEV_REMOVE
1700  *	ESC_ZFS_VDEV_CLEAR
1701  *	ESC_ZFS_VDEV_CHECK
1702  *
1703  *		ZFS_EV_POOL_NAME	DATA_TYPE_STRING
1704  *		ZFS_EV_POOL_GUID	DATA_TYPE_UINT64
1705  *		ZFS_EV_VDEV_PATH	DATA_TYPE_STRING	(optional)
1706  *		ZFS_EV_VDEV_GUID	DATA_TYPE_UINT64
1707  *
1708  *	ESC_ZFS_HISTORY_EVENT
1709  *
1710  *		ZFS_EV_POOL_NAME	DATA_TYPE_STRING
1711  *		ZFS_EV_POOL_GUID	DATA_TYPE_UINT64
1712  *		ZFS_EV_HIST_TIME	DATA_TYPE_UINT64	(optional)
1713  *		ZFS_EV_HIST_CMD		DATA_TYPE_STRING	(optional)
1714  *		ZFS_EV_HIST_WHO		DATA_TYPE_UINT64	(optional)
1715  *		ZFS_EV_HIST_ZONE	DATA_TYPE_STRING	(optional)
1716  *		ZFS_EV_HIST_HOST	DATA_TYPE_STRING	(optional)
1717  *		ZFS_EV_HIST_TXG		DATA_TYPE_UINT64	(optional)
1718  *		ZFS_EV_HIST_INT_EVENT	DATA_TYPE_UINT64	(optional)
1719  *		ZFS_EV_HIST_INT_STR	DATA_TYPE_STRING	(optional)
1720  *		ZFS_EV_HIST_INT_NAME	DATA_TYPE_STRING	(optional)
1721  *		ZFS_EV_HIST_IOCTL	DATA_TYPE_STRING	(optional)
1722  *		ZFS_EV_HIST_DSNAME	DATA_TYPE_STRING	(optional)
1723  *		ZFS_EV_HIST_DSID	DATA_TYPE_UINT64	(optional)
1724  *
1725  * The ZFS_EV_HIST_* members will correspond to the ZPOOL_HIST_* members in the
1726  * history log nvlist.  The keynames will be free of any spaces or other
1727  * characters that could be potentially unexpected to consumers of the
1728  * sysevents.
1729  */
1730 #define	ZFS_EV_POOL_NAME	"pool_name"
1731 #define	ZFS_EV_POOL_GUID	"pool_guid"
1732 #define	ZFS_EV_VDEV_PATH	"vdev_path"
1733 #define	ZFS_EV_VDEV_GUID	"vdev_guid"
1734 #define	ZFS_EV_HIST_TIME	"history_time"
1735 #define	ZFS_EV_HIST_CMD		"history_command"
1736 #define	ZFS_EV_HIST_WHO		"history_who"
1737 #define	ZFS_EV_HIST_ZONE	"history_zone"
1738 #define	ZFS_EV_HIST_HOST	"history_hostname"
1739 #define	ZFS_EV_HIST_TXG		"history_txg"
1740 #define	ZFS_EV_HIST_INT_EVENT	"history_internal_event"
1741 #define	ZFS_EV_HIST_INT_STR	"history_internal_str"
1742 #define	ZFS_EV_HIST_INT_NAME	"history_internal_name"
1743 #define	ZFS_EV_HIST_IOCTL	"history_ioctl"
1744 #define	ZFS_EV_HIST_DSNAME	"history_dsname"
1745 #define	ZFS_EV_HIST_DSID	"history_dsid"
1746 #define	ZFS_EV_RESILVER_TYPE	"resilver_type"
1747 
1748 /*
1749  * We currently support block sizes from 512 bytes to 16MB.
1750  * The benefits of larger blocks, and thus larger IO, need to be weighed
1751  * against the cost of COWing a giant block to modify one byte, and the
1752  * large latency of reading or writing a large block.
1753  *
1754  * Note that although blocks up to 16MB are supported, the recordsize
1755  * property can not be set larger than zfs_max_recordsize (default 1MB).
1756  * See the comment near zfs_max_recordsize in dsl_dataset.c for details.
1757  *
1758  * Note that although the LSIZE field of the blkptr_t can store sizes up
1759  * to 32MB, the dnode's dn_datablkszsec can only store sizes up to
1760  * 32MB - 512 bytes.  Therefore, we limit SPA_MAXBLOCKSIZE to 16MB.
1761  */
1762 #define	SPA_MINBLOCKSHIFT	9
1763 #define	SPA_OLD_MAXBLOCKSHIFT	17
1764 #define	SPA_MAXBLOCKSHIFT	24
1765 #define	SPA_MINBLOCKSIZE	(1ULL << SPA_MINBLOCKSHIFT)
1766 #define	SPA_OLD_MAXBLOCKSIZE	(1ULL << SPA_OLD_MAXBLOCKSHIFT)
1767 #define	SPA_MAXBLOCKSIZE	(1ULL << SPA_MAXBLOCKSHIFT)
1768 
1769 /* supported encryption algorithms */
1770 enum zio_encrypt {
1771 	ZIO_CRYPT_INHERIT = 0,
1772 	ZIO_CRYPT_ON,
1773 	ZIO_CRYPT_OFF,
1774 	ZIO_CRYPT_AES_128_CCM,
1775 	ZIO_CRYPT_AES_192_CCM,
1776 	ZIO_CRYPT_AES_256_CCM,
1777 	ZIO_CRYPT_AES_128_GCM,
1778 	ZIO_CRYPT_AES_192_GCM,
1779 	ZIO_CRYPT_AES_256_GCM,
1780 	ZIO_CRYPT_FUNCTIONS
1781 };
1782 
1783 #define	ZIO_CRYPT_ON_VALUE	ZIO_CRYPT_AES_256_GCM
1784 #define	ZIO_CRYPT_DEFAULT	ZIO_CRYPT_OFF
1785 
1786 /*
1787  * xattr namespace prefixes.  These are forbidden in xattr names.
1788  *
1789  * For cross-platform compatibility, xattrs in the user namespace should not be
1790  * prefixed with the namespace name, but for backwards compatibility with older
1791  * ZFS on Linux versions we do prefix the namespace.
1792  */
1793 #define	ZFS_XA_NS_FREEBSD_PREFIX		"freebsd:"
1794 #define	ZFS_XA_NS_FREEBSD_PREFIX_LEN		strlen("freebsd:")
1795 #define	ZFS_XA_NS_LINUX_SECURITY_PREFIX		"security."
1796 #define	ZFS_XA_NS_LINUX_SECURITY_PREFIX_LEN	strlen("security.")
1797 #define	ZFS_XA_NS_LINUX_SYSTEM_PREFIX		"system."
1798 #define	ZFS_XA_NS_LINUX_SYSTEM_PREFIX_LEN	strlen("system.")
1799 #define	ZFS_XA_NS_LINUX_TRUSTED_PREFIX		"trusted."
1800 #define	ZFS_XA_NS_LINUX_TRUSTED_PREFIX_LEN	strlen("trusted.")
1801 #define	ZFS_XA_NS_LINUX_USER_PREFIX		"user."
1802 #define	ZFS_XA_NS_LINUX_USER_PREFIX_LEN		strlen("user.")
1803 
1804 #define	ZFS_XA_NS_PREFIX_MATCH(ns, name) \
1805 	(strncmp(name, ZFS_XA_NS_##ns##_PREFIX, \
1806 	ZFS_XA_NS_##ns##_PREFIX_LEN) == 0)
1807 
1808 #define	ZFS_XA_NS_PREFIX_FORBIDDEN(name) \
1809 	(ZFS_XA_NS_PREFIX_MATCH(FREEBSD, name) || \
1810 	    ZFS_XA_NS_PREFIX_MATCH(LINUX_SECURITY, name) || \
1811 	    ZFS_XA_NS_PREFIX_MATCH(LINUX_SYSTEM, name) || \
1812 	    ZFS_XA_NS_PREFIX_MATCH(LINUX_TRUSTED, name) || \
1813 	    ZFS_XA_NS_PREFIX_MATCH(LINUX_USER, name))
1814 
1815 #ifdef	__cplusplus
1816 }
1817 #endif
1818 
1819 #endif	/* _SYS_FS_ZFS_H */
1820