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