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