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