xref: /illumos-gate/usr/src/uts/common/sys/fs/zfs.h (revision 5711d3938643272e5ca2aaf5d868e612e7bc97b6)
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, 2016 by Delphix. All rights reserved.
25  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
26  * Copyright (c) 2014 Integros [integros.com]
27  * Copyright 2017 Joyent, Inc.
28  * Copyright (c) 2017 Datto Inc.
29  * Copyright (c) 2017, Intel Corporation.
30  */
31 
32 /* Portions Copyright 2010 Robert Milkowski */
33 
34 #ifndef	_SYS_FS_ZFS_H
35 #define	_SYS_FS_ZFS_H
36 
37 #include <sys/time.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  * Types and constants shared between userland and the kernel.
45  */
46 
47 /*
48  * Each dataset can be one of the following types.  These constants can be
49  * combined into masks that can be passed to various functions.
50  */
51 typedef enum {
52 	ZFS_TYPE_FILESYSTEM	= (1 << 0),
53 	ZFS_TYPE_SNAPSHOT	= (1 << 1),
54 	ZFS_TYPE_VOLUME		= (1 << 2),
55 	ZFS_TYPE_POOL		= (1 << 3),
56 	ZFS_TYPE_BOOKMARK	= (1 << 4)
57 } zfs_type_t;
58 
59 /*
60  * NB: lzc_dataset_type should be updated whenever a new objset type is added,
61  * if it represents a real type of a dataset that can be created from userland.
62  */
63 typedef enum dmu_objset_type {
64 	DMU_OST_NONE,
65 	DMU_OST_META,
66 	DMU_OST_ZFS,
67 	DMU_OST_ZVOL,
68 	DMU_OST_OTHER,			/* For testing only! */
69 	DMU_OST_ANY,			/* Be careful! */
70 	DMU_OST_NUMTYPES
71 } dmu_objset_type_t;
72 
73 #define	ZFS_TYPE_DATASET	\
74 	(ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME | ZFS_TYPE_SNAPSHOT)
75 
76 /*
77  * All of these include the terminating NUL byte.
78  */
79 #define	ZAP_MAXNAMELEN 256
80 #define	ZAP_MAXVALUELEN (1024 * 8)
81 #define	ZAP_OLDMAXVALUELEN 1024
82 #define	ZFS_MAX_DATASET_NAME_LEN 256
83 
84 /*
85  * Dataset properties are identified by these constants and must be added to
86  * the end of this list to ensure that external consumers are not affected
87  * by the change. If you make any changes to this list, be sure to update
88  * the property table in usr/src/common/zfs/zfs_prop.c.
89  */
90 typedef enum {
91 	ZPROP_CONT = -2,
92 	ZPROP_INVAL = -1,
93 	ZFS_PROP_TYPE = 0,
94 	ZFS_PROP_CREATION,
95 	ZFS_PROP_USED,
96 	ZFS_PROP_AVAILABLE,
97 	ZFS_PROP_REFERENCED,
98 	ZFS_PROP_COMPRESSRATIO,
99 	ZFS_PROP_MOUNTED,
100 	ZFS_PROP_ORIGIN,
101 	ZFS_PROP_QUOTA,
102 	ZFS_PROP_RESERVATION,
103 	ZFS_PROP_VOLSIZE,
104 	ZFS_PROP_VOLBLOCKSIZE,
105 	ZFS_PROP_RECORDSIZE,
106 	ZFS_PROP_MOUNTPOINT,
107 	ZFS_PROP_SHARENFS,
108 	ZFS_PROP_CHECKSUM,
109 	ZFS_PROP_COMPRESSION,
110 	ZFS_PROP_ATIME,
111 	ZFS_PROP_DEVICES,
112 	ZFS_PROP_EXEC,
113 	ZFS_PROP_SETUID,
114 	ZFS_PROP_READONLY,
115 	ZFS_PROP_ZONED,
116 	ZFS_PROP_SNAPDIR,
117 	ZFS_PROP_ACLMODE,
118 	ZFS_PROP_ACLINHERIT,
119 	ZFS_PROP_CREATETXG,
120 	ZFS_PROP_NAME,			/* not exposed to the user */
121 	ZFS_PROP_CANMOUNT,
122 	ZFS_PROP_ISCSIOPTIONS,		/* not exposed to the user */
123 	ZFS_PROP_XATTR,
124 	ZFS_PROP_NUMCLONES,		/* not exposed to the user */
125 	ZFS_PROP_COPIES,
126 	ZFS_PROP_VERSION,
127 	ZFS_PROP_UTF8ONLY,
128 	ZFS_PROP_NORMALIZE,
129 	ZFS_PROP_CASE,
130 	ZFS_PROP_VSCAN,
131 	ZFS_PROP_NBMAND,
132 	ZFS_PROP_SHARESMB,
133 	ZFS_PROP_REFQUOTA,
134 	ZFS_PROP_REFRESERVATION,
135 	ZFS_PROP_GUID,
136 	ZFS_PROP_PRIMARYCACHE,
137 	ZFS_PROP_SECONDARYCACHE,
138 	ZFS_PROP_USEDSNAP,
139 	ZFS_PROP_USEDDS,
140 	ZFS_PROP_USEDCHILD,
141 	ZFS_PROP_USEDREFRESERV,
142 	ZFS_PROP_USERACCOUNTING,	/* not exposed to the user */
143 	ZFS_PROP_STMF_SHAREINFO,	/* not exposed to the user */
144 	ZFS_PROP_DEFER_DESTROY,
145 	ZFS_PROP_USERREFS,
146 	ZFS_PROP_LOGBIAS,
147 	ZFS_PROP_UNIQUE,		/* not exposed to the user */
148 	ZFS_PROP_OBJSETID,		/* not exposed to the user */
149 	ZFS_PROP_DEDUP,
150 	ZFS_PROP_MLSLABEL,
151 	ZFS_PROP_SYNC,
152 	ZFS_PROP_DNODESIZE,
153 	ZFS_PROP_REFRATIO,
154 	ZFS_PROP_WRITTEN,
155 	ZFS_PROP_CLONES,
156 	ZFS_PROP_LOGICALUSED,
157 	ZFS_PROP_LOGICALREFERENCED,
158 	ZFS_PROP_INCONSISTENT,		/* not exposed to the user */
159 	ZFS_PROP_FILESYSTEM_LIMIT,
160 	ZFS_PROP_SNAPSHOT_LIMIT,
161 	ZFS_PROP_FILESYSTEM_COUNT,
162 	ZFS_PROP_SNAPSHOT_COUNT,
163 	ZFS_PROP_REDUNDANT_METADATA,
164 	ZFS_PROP_PREV_SNAP,
165 	ZFS_PROP_RECEIVE_RESUME_TOKEN,
166 	ZFS_PROP_REMAPTXG,		/* not exposed to the user */
167 	ZFS_PROP_SPECIAL_SMALL_BLOCKS,
168 	ZFS_PROP_ENCRYPTION,
169 	ZFS_PROP_KEYLOCATION,
170 	ZFS_PROP_KEYFORMAT,
171 	ZFS_PROP_PBKDF2_SALT,
172 	ZFS_PROP_PBKDF2_ITERS,
173 	ZFS_PROP_ENCRYPTION_ROOT,
174 	ZFS_PROP_KEY_GUID,
175 	ZFS_PROP_KEYSTATUS,
176 	ZFS_PROP_IVSET_GUID,		/* not exposed to the user */
177 	ZFS_NUM_PROPS
178 } zfs_prop_t;
179 
180 typedef enum {
181 	ZFS_PROP_USERUSED,
182 	ZFS_PROP_USERQUOTA,
183 	ZFS_PROP_GROUPUSED,
184 	ZFS_PROP_GROUPQUOTA,
185 	ZFS_PROP_USEROBJUSED,
186 	ZFS_PROP_USEROBJQUOTA,
187 	ZFS_PROP_GROUPOBJUSED,
188 	ZFS_PROP_GROUPOBJQUOTA,
189 	ZFS_PROP_PROJECTUSED,
190 	ZFS_PROP_PROJECTQUOTA,
191 	ZFS_PROP_PROJECTOBJUSED,
192 	ZFS_PROP_PROJECTOBJQUOTA,
193 	ZFS_NUM_USERQUOTA_PROPS
194 } zfs_userquota_prop_t;
195 
196 extern const char *zfs_userquota_prop_prefixes[ZFS_NUM_USERQUOTA_PROPS];
197 
198 /*
199  * Pool properties are identified by these constants and must be added to the
200  * end of this list to ensure that external consumers are not affected
201  * by the change. If you make any changes to this list, be sure to update
202  * the property table in usr/src/common/zfs/zpool_prop.c.
203  */
204 typedef enum {
205 	ZPOOL_PROP_INVAL = -1,
206 	ZPOOL_PROP_NAME,
207 	ZPOOL_PROP_SIZE,
208 	ZPOOL_PROP_CAPACITY,
209 	ZPOOL_PROP_ALTROOT,
210 	ZPOOL_PROP_HEALTH,
211 	ZPOOL_PROP_GUID,
212 	ZPOOL_PROP_VERSION,
213 	ZPOOL_PROP_BOOTFS,
214 	ZPOOL_PROP_DELEGATION,
215 	ZPOOL_PROP_AUTOREPLACE,
216 	ZPOOL_PROP_CACHEFILE,
217 	ZPOOL_PROP_FAILUREMODE,
218 	ZPOOL_PROP_LISTSNAPS,
219 	ZPOOL_PROP_AUTOEXPAND,
220 	ZPOOL_PROP_DEDUPDITTO,
221 	ZPOOL_PROP_DEDUPRATIO,
222 	ZPOOL_PROP_FREE,
223 	ZPOOL_PROP_ALLOCATED,
224 	ZPOOL_PROP_READONLY,
225 	ZPOOL_PROP_COMMENT,
226 	ZPOOL_PROP_EXPANDSZ,
227 	ZPOOL_PROP_FREEING,
228 	ZPOOL_PROP_FRAGMENTATION,
229 	ZPOOL_PROP_LEAKED,
230 	ZPOOL_PROP_MAXBLOCKSIZE,
231 	ZPOOL_PROP_BOOTSIZE,
232 	ZPOOL_PROP_CHECKPOINT,
233 	ZPOOL_PROP_TNAME,
234 	ZPOOL_PROP_MAXDNODESIZE,
235 	ZPOOL_PROP_MULTIHOST,
236 	ZPOOL_PROP_ASHIFT,
237 	ZPOOL_NUM_PROPS
238 } zpool_prop_t;
239 
240 /* Small enough to not hog a whole line of printout in zpool(1M). */
241 #define	ZPROP_MAX_COMMENT	32
242 
243 #define	ZPROP_VALUE		"value"
244 #define	ZPROP_SOURCE		"source"
245 
246 typedef enum {
247 	ZPROP_SRC_NONE = 0x1,
248 	ZPROP_SRC_DEFAULT = 0x2,
249 	ZPROP_SRC_TEMPORARY = 0x4,
250 	ZPROP_SRC_LOCAL = 0x8,
251 	ZPROP_SRC_INHERITED = 0x10,
252 	ZPROP_SRC_RECEIVED = 0x20
253 } zprop_source_t;
254 
255 #define	ZPROP_SRC_ALL	0x3f
256 
257 #define	ZPROP_SOURCE_VAL_RECVD	"$recvd"
258 #define	ZPROP_N_MORE_ERRORS	"N_MORE_ERRORS"
259 /*
260  * Dataset flag implemented as a special entry in the props zap object
261  * indicating that the dataset has received properties on or after
262  * SPA_VERSION_RECVD_PROPS. The first such receive blows away local properties
263  * just as it did in earlier versions, and thereafter, local properties are
264  * preserved.
265  */
266 #define	ZPROP_HAS_RECVD		"$hasrecvd"
267 
268 typedef enum {
269 	ZPROP_ERR_NOCLEAR = 0x1, /* failure to clear existing props */
270 	ZPROP_ERR_NORESTORE = 0x2 /* failure to restore props on error */
271 } zprop_errflags_t;
272 
273 typedef int (*zprop_func)(int, void *);
274 
275 /*
276  * Properties to be set on the root file system of a new pool
277  * are stuffed into their own nvlist, which is then included in
278  * the properties nvlist with the pool properties.
279  */
280 #define	ZPOOL_ROOTFS_PROPS	"root-props-nvl"
281 
282 /*
283  * Length of 'written@' and 'written#'
284  */
285 #define	ZFS_WRITTEN_PROP_PREFIX_LEN	8
286 
287 /*
288  * Dataset property functions shared between libzfs and kernel.
289  */
290 const char *zfs_prop_default_string(zfs_prop_t);
291 uint64_t zfs_prop_default_numeric(zfs_prop_t);
292 boolean_t zfs_prop_readonly(zfs_prop_t);
293 boolean_t zfs_prop_visible(zfs_prop_t prop);
294 boolean_t zfs_prop_inheritable(zfs_prop_t);
295 boolean_t zfs_prop_setonce(zfs_prop_t);
296 boolean_t zfs_prop_encryption_key_param(zfs_prop_t);
297 boolean_t zfs_prop_valid_keylocation(const char *, boolean_t);
298 const char *zfs_prop_to_name(zfs_prop_t);
299 zfs_prop_t zfs_name_to_prop(const char *);
300 boolean_t zfs_prop_user(const char *);
301 boolean_t zfs_prop_userquota(const char *);
302 boolean_t zfs_prop_written(const char *);
303 int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
304 int zfs_prop_string_to_index(zfs_prop_t, const char *, uint64_t *);
305 uint64_t zfs_prop_random_value(zfs_prop_t, uint64_t seed);
306 boolean_t zfs_prop_valid_for_type(int, zfs_type_t);
307 
308 /*
309  * Pool property functions shared between libzfs and kernel.
310  */
311 zpool_prop_t zpool_name_to_prop(const char *);
312 const char *zpool_prop_to_name(zpool_prop_t);
313 const char *zpool_prop_default_string(zpool_prop_t);
314 uint64_t zpool_prop_default_numeric(zpool_prop_t);
315 boolean_t zpool_prop_readonly(zpool_prop_t);
316 boolean_t zpool_prop_feature(const char *);
317 boolean_t zpool_prop_unsupported(const char *name);
318 int zpool_prop_index_to_string(zpool_prop_t, uint64_t, const char **);
319 int zpool_prop_string_to_index(zpool_prop_t, const char *, uint64_t *);
320 uint64_t zpool_prop_random_value(zpool_prop_t, uint64_t seed);
321 
322 /*
323  * Definitions for the Delegation.
324  */
325 typedef enum {
326 	ZFS_DELEG_WHO_UNKNOWN = 0,
327 	ZFS_DELEG_USER = 'u',
328 	ZFS_DELEG_USER_SETS = 'U',
329 	ZFS_DELEG_GROUP = 'g',
330 	ZFS_DELEG_GROUP_SETS = 'G',
331 	ZFS_DELEG_EVERYONE = 'e',
332 	ZFS_DELEG_EVERYONE_SETS = 'E',
333 	ZFS_DELEG_CREATE = 'c',
334 	ZFS_DELEG_CREATE_SETS = 'C',
335 	ZFS_DELEG_NAMED_SET = 's',
336 	ZFS_DELEG_NAMED_SET_SETS = 'S'
337 } zfs_deleg_who_type_t;
338 
339 typedef enum {
340 	ZFS_DELEG_NONE = 0,
341 	ZFS_DELEG_PERM_LOCAL = 1,
342 	ZFS_DELEG_PERM_DESCENDENT = 2,
343 	ZFS_DELEG_PERM_LOCALDESCENDENT = 3,
344 	ZFS_DELEG_PERM_CREATE = 4
345 } zfs_deleg_inherit_t;
346 
347 #define	ZFS_DELEG_PERM_UID	"uid"
348 #define	ZFS_DELEG_PERM_GID	"gid"
349 #define	ZFS_DELEG_PERM_GROUPS	"groups"
350 
351 #define	ZFS_MLSLABEL_DEFAULT	"none"
352 
353 #define	ZFS_SMB_ACL_SRC		"src"
354 #define	ZFS_SMB_ACL_TARGET	"target"
355 
356 typedef enum {
357 	ZFS_CANMOUNT_OFF = 0,
358 	ZFS_CANMOUNT_ON = 1,
359 	ZFS_CANMOUNT_NOAUTO = 2
360 } zfs_canmount_type_t;
361 
362 typedef enum {
363 	ZFS_LOGBIAS_LATENCY = 0,
364 	ZFS_LOGBIAS_THROUGHPUT = 1
365 } zfs_logbias_op_t;
366 
367 typedef enum zfs_share_op {
368 	ZFS_SHARE_NFS = 0,
369 	ZFS_UNSHARE_NFS = 1,
370 	ZFS_SHARE_SMB = 2,
371 	ZFS_UNSHARE_SMB = 3
372 } zfs_share_op_t;
373 
374 typedef enum zfs_smb_acl_op {
375 	ZFS_SMB_ACL_ADD,
376 	ZFS_SMB_ACL_REMOVE,
377 	ZFS_SMB_ACL_RENAME,
378 	ZFS_SMB_ACL_PURGE
379 } zfs_smb_acl_op_t;
380 
381 typedef enum zfs_cache_type {
382 	ZFS_CACHE_NONE = 0,
383 	ZFS_CACHE_METADATA = 1,
384 	ZFS_CACHE_ALL = 2
385 } zfs_cache_type_t;
386 
387 typedef enum {
388 	ZFS_SYNC_STANDARD = 0,
389 	ZFS_SYNC_ALWAYS = 1,
390 	ZFS_SYNC_DISABLED = 2
391 } zfs_sync_type_t;
392 
393 typedef enum {
394 	ZFS_DNSIZE_LEGACY = 0,
395 	ZFS_DNSIZE_AUTO = 1,
396 	ZFS_DNSIZE_1K = 1024,
397 	ZFS_DNSIZE_2K = 2048,
398 	ZFS_DNSIZE_4K = 4096,
399 	ZFS_DNSIZE_8K = 8192,
400 	ZFS_DNSIZE_16K = 16384
401 } zfs_dnsize_type_t;
402 
403 typedef enum {
404 	ZFS_REDUNDANT_METADATA_ALL,
405 	ZFS_REDUNDANT_METADATA_MOST
406 } zfs_redundant_metadata_type_t;
407 
408 typedef enum zfs_keystatus {
409 	ZFS_KEYSTATUS_NONE = 0,
410 	ZFS_KEYSTATUS_UNAVAILABLE,
411 	ZFS_KEYSTATUS_AVAILABLE
412 } zfs_keystatus_t;
413 
414 typedef enum zfs_keyformat {
415 	ZFS_KEYFORMAT_NONE = 0,
416 	ZFS_KEYFORMAT_RAW,
417 	ZFS_KEYFORMAT_HEX,
418 	ZFS_KEYFORMAT_PASSPHRASE,
419 	ZFS_KEYFORMAT_FORMATS
420 } zfs_keyformat_t;
421 
422 typedef enum zfs_key_location {
423 	ZFS_KEYLOCATION_NONE = 0,
424 	ZFS_KEYLOCATION_PROMPT,
425 	ZFS_KEYLOCATION_URI,
426 	ZFS_KEYLOCATION_LOCATIONS
427 } zfs_keylocation_t;
428 
429 #define	DEFAULT_PBKDF2_ITERATIONS 350000
430 #define	MIN_PBKDF2_ITERATIONS 100000
431 
432 /*
433  * On-disk version number.
434  */
435 #define	SPA_VERSION_1			1ULL
436 #define	SPA_VERSION_2			2ULL
437 #define	SPA_VERSION_3			3ULL
438 #define	SPA_VERSION_4			4ULL
439 #define	SPA_VERSION_5			5ULL
440 #define	SPA_VERSION_6			6ULL
441 #define	SPA_VERSION_7			7ULL
442 #define	SPA_VERSION_8			8ULL
443 #define	SPA_VERSION_9			9ULL
444 #define	SPA_VERSION_10			10ULL
445 #define	SPA_VERSION_11			11ULL
446 #define	SPA_VERSION_12			12ULL
447 #define	SPA_VERSION_13			13ULL
448 #define	SPA_VERSION_14			14ULL
449 #define	SPA_VERSION_15			15ULL
450 #define	SPA_VERSION_16			16ULL
451 #define	SPA_VERSION_17			17ULL
452 #define	SPA_VERSION_18			18ULL
453 #define	SPA_VERSION_19			19ULL
454 #define	SPA_VERSION_20			20ULL
455 #define	SPA_VERSION_21			21ULL
456 #define	SPA_VERSION_22			22ULL
457 #define	SPA_VERSION_23			23ULL
458 #define	SPA_VERSION_24			24ULL
459 #define	SPA_VERSION_25			25ULL
460 #define	SPA_VERSION_26			26ULL
461 #define	SPA_VERSION_27			27ULL
462 #define	SPA_VERSION_28			28ULL
463 #define	SPA_VERSION_5000		5000ULL
464 
465 /*
466  * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk
467  * format change. Go to usr/src/grub/grub-0.97/stage2/{zfs-include/, fsys_zfs*},
468  * and do the appropriate changes.  Also bump the version number in
469  * usr/src/grub/capability.
470  */
471 #define	SPA_VERSION			SPA_VERSION_5000
472 #define	SPA_VERSION_STRING		"5000"
473 
474 /*
475  * Symbolic names for the changes that caused a SPA_VERSION switch.
476  * Used in the code when checking for presence or absence of a feature.
477  * Feel free to define multiple symbolic names for each version if there
478  * were multiple changes to on-disk structures during that version.
479  *
480  * NOTE: When checking the current SPA_VERSION in your code, be sure
481  *       to use spa_version() since it reports the version of the
482  *       last synced uberblock.  Checking the in-flight version can
483  *       be dangerous in some cases.
484  */
485 #define	SPA_VERSION_INITIAL		SPA_VERSION_1
486 #define	SPA_VERSION_DITTO_BLOCKS	SPA_VERSION_2
487 #define	SPA_VERSION_SPARES		SPA_VERSION_3
488 #define	SPA_VERSION_RAIDZ2		SPA_VERSION_3
489 #define	SPA_VERSION_BPOBJ_ACCOUNT	SPA_VERSION_3
490 #define	SPA_VERSION_RAIDZ_DEFLATE	SPA_VERSION_3
491 #define	SPA_VERSION_DNODE_BYTES		SPA_VERSION_3
492 #define	SPA_VERSION_ZPOOL_HISTORY	SPA_VERSION_4
493 #define	SPA_VERSION_GZIP_COMPRESSION	SPA_VERSION_5
494 #define	SPA_VERSION_BOOTFS		SPA_VERSION_6
495 #define	SPA_VERSION_SLOGS		SPA_VERSION_7
496 #define	SPA_VERSION_DELEGATED_PERMS	SPA_VERSION_8
497 #define	SPA_VERSION_FUID		SPA_VERSION_9
498 #define	SPA_VERSION_REFRESERVATION	SPA_VERSION_9
499 #define	SPA_VERSION_REFQUOTA		SPA_VERSION_9
500 #define	SPA_VERSION_UNIQUE_ACCURATE	SPA_VERSION_9
501 #define	SPA_VERSION_L2CACHE		SPA_VERSION_10
502 #define	SPA_VERSION_NEXT_CLONES		SPA_VERSION_11
503 #define	SPA_VERSION_ORIGIN		SPA_VERSION_11
504 #define	SPA_VERSION_DSL_SCRUB		SPA_VERSION_11
505 #define	SPA_VERSION_SNAP_PROPS		SPA_VERSION_12
506 #define	SPA_VERSION_USED_BREAKDOWN	SPA_VERSION_13
507 #define	SPA_VERSION_PASSTHROUGH_X	SPA_VERSION_14
508 #define	SPA_VERSION_USERSPACE		SPA_VERSION_15
509 #define	SPA_VERSION_STMF_PROP		SPA_VERSION_16
510 #define	SPA_VERSION_RAIDZ3		SPA_VERSION_17
511 #define	SPA_VERSION_USERREFS		SPA_VERSION_18
512 #define	SPA_VERSION_HOLES		SPA_VERSION_19
513 #define	SPA_VERSION_ZLE_COMPRESSION	SPA_VERSION_20
514 #define	SPA_VERSION_DEDUP		SPA_VERSION_21
515 #define	SPA_VERSION_RECVD_PROPS		SPA_VERSION_22
516 #define	SPA_VERSION_SLIM_ZIL		SPA_VERSION_23
517 #define	SPA_VERSION_SA			SPA_VERSION_24
518 #define	SPA_VERSION_SCAN		SPA_VERSION_25
519 #define	SPA_VERSION_DIR_CLONES		SPA_VERSION_26
520 #define	SPA_VERSION_DEADLISTS		SPA_VERSION_26
521 #define	SPA_VERSION_FAST_SNAP		SPA_VERSION_27
522 #define	SPA_VERSION_MULTI_REPLACE	SPA_VERSION_28
523 #define	SPA_VERSION_BEFORE_FEATURES	SPA_VERSION_28
524 #define	SPA_VERSION_FEATURES		SPA_VERSION_5000
525 
526 #define	SPA_VERSION_IS_SUPPORTED(v) \
527 	(((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \
528 	((v) >= SPA_VERSION_FEATURES && (v) <= SPA_VERSION))
529 
530 /*
531  * ZPL version - rev'd whenever an incompatible on-disk format change
532  * occurs.  This is independent of SPA/DMU/ZAP versioning.  You must
533  * also update the version_table[] and help message in zfs_prop.c.
534  *
535  * When changing, be sure to teach GRUB how to read the new format!
536  * See usr/src/grub/grub-0.97/stage2/{zfs-include/,fsys_zfs*}
537  */
538 #define	ZPL_VERSION_1			1ULL
539 #define	ZPL_VERSION_2			2ULL
540 #define	ZPL_VERSION_3			3ULL
541 #define	ZPL_VERSION_4			4ULL
542 #define	ZPL_VERSION_5			5ULL
543 #define	ZPL_VERSION			ZPL_VERSION_5
544 #define	ZPL_VERSION_STRING		"5"
545 
546 #define	ZPL_VERSION_INITIAL		ZPL_VERSION_1
547 #define	ZPL_VERSION_DIRENT_TYPE		ZPL_VERSION_2
548 #define	ZPL_VERSION_FUID		ZPL_VERSION_3
549 #define	ZPL_VERSION_NORMALIZATION	ZPL_VERSION_3
550 #define	ZPL_VERSION_SYSATTR		ZPL_VERSION_3
551 #define	ZPL_VERSION_USERSPACE		ZPL_VERSION_4
552 #define	ZPL_VERSION_SA			ZPL_VERSION_5
553 
554 /* Rewind policy information */
555 #define	ZPOOL_NO_REWIND		1  /* No policy - default behavior */
556 #define	ZPOOL_NEVER_REWIND	2  /* Do not search for best txg or rewind */
557 #define	ZPOOL_TRY_REWIND	4  /* Search for best txg, but do not rewind */
558 #define	ZPOOL_DO_REWIND		8  /* Rewind to best txg w/in deferred frees */
559 #define	ZPOOL_EXTREME_REWIND	16 /* Allow extreme measures to find best txg */
560 #define	ZPOOL_REWIND_MASK	28 /* All the possible rewind bits */
561 #define	ZPOOL_REWIND_POLICIES	31 /* All the possible policy bits */
562 
563 typedef struct zpool_load_policy {
564 	uint32_t	zlp_rewind;	/* rewind policy requested */
565 	uint64_t	zlp_maxmeta;	/* max acceptable meta-data errors */
566 	uint64_t	zlp_maxdata;	/* max acceptable data errors */
567 	uint64_t	zlp_txg;	/* specific txg to load */
568 } zpool_load_policy_t;
569 
570 /*
571  * The following are configuration names used in the nvlist describing a pool's
572  * configuration.  New on-disk names should be prefixed with "<reverse-DNS>:"
573  * (e.g. "org.open-zfs:") to avoid conflicting names being developed
574  * independently.
575  */
576 #define	ZPOOL_CONFIG_VERSION		"version"
577 #define	ZPOOL_CONFIG_POOL_NAME		"name"
578 #define	ZPOOL_CONFIG_POOL_STATE		"state"
579 #define	ZPOOL_CONFIG_POOL_TXG		"txg"
580 #define	ZPOOL_CONFIG_POOL_GUID		"pool_guid"
581 #define	ZPOOL_CONFIG_CREATE_TXG		"create_txg"
582 #define	ZPOOL_CONFIG_TOP_GUID		"top_guid"
583 #define	ZPOOL_CONFIG_VDEV_TREE		"vdev_tree"
584 #define	ZPOOL_CONFIG_TYPE		"type"
585 #define	ZPOOL_CONFIG_CHILDREN		"children"
586 #define	ZPOOL_CONFIG_ID			"id"
587 #define	ZPOOL_CONFIG_GUID		"guid"
588 #define	ZPOOL_CONFIG_INDIRECT_OBJECT	"com.delphix:indirect_object"
589 #define	ZPOOL_CONFIG_INDIRECT_BIRTHS	"com.delphix:indirect_births"
590 #define	ZPOOL_CONFIG_PREV_INDIRECT_VDEV	"com.delphix:prev_indirect_vdev"
591 #define	ZPOOL_CONFIG_PATH		"path"
592 #define	ZPOOL_CONFIG_DEVID		"devid"
593 #define	ZPOOL_CONFIG_METASLAB_ARRAY	"metaslab_array"
594 #define	ZPOOL_CONFIG_METASLAB_SHIFT	"metaslab_shift"
595 #define	ZPOOL_CONFIG_ASHIFT		"ashift"
596 #define	ZPOOL_CONFIG_ASIZE		"asize"
597 #define	ZPOOL_CONFIG_DTL		"DTL"
598 #define	ZPOOL_CONFIG_SCAN_STATS		"scan_stats"	/* not stored on disk */
599 #define	ZPOOL_CONFIG_REMOVAL_STATS	"removal_stats"	/* not stored on disk */
600 #define	ZPOOL_CONFIG_CHECKPOINT_STATS	"checkpoint_stats" /* not on disk */
601 #define	ZPOOL_CONFIG_VDEV_STATS		"vdev_stats"	/* not stored on disk */
602 #define	ZPOOL_CONFIG_INDIRECT_SIZE	"indirect_size"	/* not stored on disk */
603 #define	ZPOOL_CONFIG_WHOLE_DISK		"whole_disk"
604 #define	ZPOOL_CONFIG_ERRCOUNT		"error_count"
605 #define	ZPOOL_CONFIG_NOT_PRESENT	"not_present"
606 #define	ZPOOL_CONFIG_SPARES		"spares"
607 #define	ZPOOL_CONFIG_IS_SPARE		"is_spare"
608 #define	ZPOOL_CONFIG_NPARITY		"nparity"
609 #define	ZPOOL_CONFIG_HOSTID		"hostid"
610 #define	ZPOOL_CONFIG_HOSTNAME		"hostname"
611 #define	ZPOOL_CONFIG_LOADED_TIME	"initial_load_time"
612 #define	ZPOOL_CONFIG_UNSPARE		"unspare"
613 #define	ZPOOL_CONFIG_PHYS_PATH		"phys_path"
614 #define	ZPOOL_CONFIG_IS_LOG		"is_log"
615 #define	ZPOOL_CONFIG_L2CACHE		"l2cache"
616 #define	ZPOOL_CONFIG_HOLE_ARRAY		"hole_array"
617 #define	ZPOOL_CONFIG_VDEV_CHILDREN	"vdev_children"
618 #define	ZPOOL_CONFIG_IS_HOLE		"is_hole"
619 #define	ZPOOL_CONFIG_DDT_HISTOGRAM	"ddt_histogram"
620 #define	ZPOOL_CONFIG_DDT_OBJ_STATS	"ddt_object_stats"
621 #define	ZPOOL_CONFIG_DDT_STATS		"ddt_stats"
622 #define	ZPOOL_CONFIG_SPLIT		"splitcfg"
623 #define	ZPOOL_CONFIG_ORIG_GUID		"orig_guid"
624 #define	ZPOOL_CONFIG_SPLIT_GUID		"split_guid"
625 #define	ZPOOL_CONFIG_SPLIT_LIST		"guid_list"
626 #define	ZPOOL_CONFIG_REMOVING		"removing"
627 #define	ZPOOL_CONFIG_RESILVER_TXG	"resilver_txg"
628 #define	ZPOOL_CONFIG_COMMENT		"comment"
629 #define	ZPOOL_CONFIG_SUSPENDED		"suspended"	/* not stored on disk */
630 #define	ZPOOL_CONFIG_SUSPENDED_REASON	"suspended_reason"	/* not stored */
631 #define	ZPOOL_CONFIG_TIMESTAMP		"timestamp"	/* not stored on disk */
632 #define	ZPOOL_CONFIG_BOOTFS		"bootfs"	/* not stored on disk */
633 #define	ZPOOL_CONFIG_MISSING_DEVICES	"missing_vdevs"	/* not stored on disk */
634 #define	ZPOOL_CONFIG_LOAD_INFO		"load_info"	/* not stored on disk */
635 #define	ZPOOL_CONFIG_REWIND_INFO	"rewind_info"	/* not stored on disk */
636 #define	ZPOOL_CONFIG_UNSUP_FEAT		"unsup_feat"	/* not stored on disk */
637 #define	ZPOOL_CONFIG_ENABLED_FEAT	"enabled_feat"	/* not stored on disk */
638 #define	ZPOOL_CONFIG_CAN_RDONLY		"can_rdonly"	/* not stored on disk */
639 #define	ZPOOL_CONFIG_FEATURES_FOR_READ	"features_for_read"
640 #define	ZPOOL_CONFIG_FEATURE_STATS	"feature_stats"	/* not stored on disk */
641 #define	ZPOOL_CONFIG_ERRATA		"errata"	/* not stored on disk */
642 #define	ZPOOL_CONFIG_VDEV_TOP_ZAP	"com.delphix:vdev_zap_top"
643 #define	ZPOOL_CONFIG_VDEV_LEAF_ZAP	"com.delphix:vdev_zap_leaf"
644 #define	ZPOOL_CONFIG_HAS_PER_VDEV_ZAPS	"com.delphix:has_per_vdev_zaps"
645 #define	ZPOOL_CONFIG_RESILVER_DEFER	"com.datto:resilver_defer"
646 #define	ZPOOL_CONFIG_CACHEFILE		"cachefile"	/* not stored on disk */
647 #define	ZPOOL_CONFIG_MMP_STATE		"mmp_state"	/* not stored on disk */
648 #define	ZPOOL_CONFIG_MMP_TXG		"mmp_txg"	/* not stored on disk */
649 #define	ZPOOL_CONFIG_MMP_HOSTNAME	"mmp_hostname"	/* not stored on disk */
650 #define	ZPOOL_CONFIG_MMP_HOSTID		"mmp_hostid"	/* not stored on disk */
651 #define	ZPOOL_CONFIG_ALLOCATION_BIAS	"alloc_bias"	/* not stored on disk */
652 
653 /*
654  * The persistent vdev state is stored as separate values rather than a single
655  * 'vdev_state' entry.  This is because a device can be in multiple states, such
656  * as offline and degraded.
657  */
658 #define	ZPOOL_CONFIG_OFFLINE		"offline"
659 #define	ZPOOL_CONFIG_FAULTED		"faulted"
660 #define	ZPOOL_CONFIG_DEGRADED		"degraded"
661 #define	ZPOOL_CONFIG_REMOVED		"removed"
662 #define	ZPOOL_CONFIG_FRU		"fru"
663 #define	ZPOOL_CONFIG_AUX_STATE		"aux_state"
664 
665 /* Pool load policy parameters */
666 #define	ZPOOL_LOAD_POLICY		"load-policy"
667 #define	ZPOOL_LOAD_REWIND_POLICY	"load-rewind-policy"
668 #define	ZPOOL_LOAD_REQUEST_TXG		"load-request-txg"
669 #define	ZPOOL_LOAD_META_THRESH		"load-meta-thresh"
670 #define	ZPOOL_LOAD_DATA_THRESH		"load-data-thresh"
671 
672 /* Rewind data discovered */
673 #define	ZPOOL_CONFIG_LOAD_TIME		"rewind_txg_ts"
674 #define	ZPOOL_CONFIG_LOAD_DATA_ERRORS	"verify_data_errors"
675 #define	ZPOOL_CONFIG_REWIND_TIME	"seconds_of_rewind"
676 
677 #define	VDEV_TYPE_ROOT			"root"
678 #define	VDEV_TYPE_MIRROR		"mirror"
679 #define	VDEV_TYPE_REPLACING		"replacing"
680 #define	VDEV_TYPE_RAIDZ			"raidz"
681 #define	VDEV_TYPE_DISK			"disk"
682 #define	VDEV_TYPE_FILE			"file"
683 #define	VDEV_TYPE_MISSING		"missing"
684 #define	VDEV_TYPE_HOLE			"hole"
685 #define	VDEV_TYPE_SPARE			"spare"
686 #define	VDEV_TYPE_LOG			"log"
687 #define	VDEV_TYPE_L2CACHE		"l2cache"
688 #define	VDEV_TYPE_INDIRECT		"indirect"
689 
690 /* VDEV_TOP_ZAP_* are used in top-level vdev ZAP objects. */
691 #define	VDEV_TOP_ZAP_INDIRECT_OBSOLETE_SM \
692 	"com.delphix:indirect_obsolete_sm"
693 #define	VDEV_TOP_ZAP_OBSOLETE_COUNTS_ARE_PRECISE \
694 	"com.delphix:obsolete_counts_are_precise"
695 #define	VDEV_TOP_ZAP_POOL_CHECKPOINT_SM \
696 	"com.delphix:pool_checkpoint_sm"
697 
698 #define	VDEV_TOP_ZAP_ALLOCATION_BIAS \
699 	"org.zfsonlinux:allocation_bias"
700 
701 /* vdev metaslab allocation bias */
702 #define	VDEV_ALLOC_BIAS_LOG		"log"
703 #define	VDEV_ALLOC_BIAS_SPECIAL		"special"
704 #define	VDEV_ALLOC_BIAS_DEDUP		"dedup"
705 
706 #define	VDEV_LEAF_ZAP_INITIALIZE_LAST_OFFSET	\
707 	"com.delphix:next_offset_to_initialize"
708 #define	VDEV_LEAF_ZAP_INITIALIZE_STATE	\
709 	"com.delphix:vdev_initialize_state"
710 #define	VDEV_LEAF_ZAP_INITIALIZE_ACTION_TIME	\
711 	"com.delphix:vdev_initialize_action_time"
712 
713 /*
714  * This is needed in userland to report the minimum necessary device size.
715  *
716  * Note that the zfs test suite uses 64MB vdevs.
717  */
718 #define	SPA_MINDEVSIZE		(64ULL << 20)
719 
720 /*
721  * Set if the fragmentation has not yet been calculated. This can happen
722  * because the space maps have not been upgraded or the histogram feature
723  * is not enabled.
724  */
725 #define	ZFS_FRAG_INVALID	UINT64_MAX
726 
727 /*
728  * The location of the pool configuration repository, shared between kernel and
729  * userland.
730  */
731 #define	ZPOOL_CACHE		"/etc/zfs/zpool.cache"
732 
733 /*
734  * vdev states are ordered from least to most healthy.
735  * A vdev that's CANT_OPEN or below is considered unusable.
736  */
737 typedef enum vdev_state {
738 	VDEV_STATE_UNKNOWN = 0,	/* Uninitialized vdev			*/
739 	VDEV_STATE_CLOSED,	/* Not currently open			*/
740 	VDEV_STATE_OFFLINE,	/* Not allowed to open			*/
741 	VDEV_STATE_REMOVED,	/* Explicitly removed from system	*/
742 	VDEV_STATE_CANT_OPEN,	/* Tried to open, but failed		*/
743 	VDEV_STATE_FAULTED,	/* External request to fault device	*/
744 	VDEV_STATE_DEGRADED,	/* Replicated vdev with unhealthy kids	*/
745 	VDEV_STATE_HEALTHY	/* Presumed good			*/
746 } vdev_state_t;
747 
748 #define	VDEV_STATE_ONLINE	VDEV_STATE_HEALTHY
749 
750 /*
751  * vdev aux states.  When a vdev is in the CANT_OPEN state, the aux field
752  * of the vdev stats structure uses these constants to distinguish why.
753  */
754 typedef enum vdev_aux {
755 	VDEV_AUX_NONE,		/* no error				*/
756 	VDEV_AUX_OPEN_FAILED,	/* ldi_open_*() or vn_open() failed	*/
757 	VDEV_AUX_CORRUPT_DATA,	/* bad label or disk contents		*/
758 	VDEV_AUX_NO_REPLICAS,	/* insufficient number of replicas	*/
759 	VDEV_AUX_BAD_GUID_SUM,	/* vdev guid sum doesn't match		*/
760 	VDEV_AUX_TOO_SMALL,	/* vdev size is too small		*/
761 	VDEV_AUX_BAD_LABEL,	/* the label is OK but invalid		*/
762 	VDEV_AUX_VERSION_NEWER,	/* on-disk version is too new		*/
763 	VDEV_AUX_VERSION_OLDER,	/* on-disk version is too old		*/
764 	VDEV_AUX_UNSUP_FEAT,	/* unsupported features			*/
765 	VDEV_AUX_SPARED,	/* hot spare used in another pool	*/
766 	VDEV_AUX_ERR_EXCEEDED,	/* too many errors			*/
767 	VDEV_AUX_IO_FAILURE,	/* experienced I/O failure		*/
768 	VDEV_AUX_BAD_LOG,	/* cannot read log chain(s)		*/
769 	VDEV_AUX_EXTERNAL,	/* external diagnosis			*/
770 	VDEV_AUX_SPLIT_POOL,	/* vdev was split off into another pool	*/
771 	VDEV_AUX_ACTIVE,	/* vdev active on a different host	*/
772 	VDEV_AUX_CHILDREN_OFFLINE, /* all children are offline		*/
773 	VDEV_AUX_BAD_ASHIFT	/* vdev ashift is invalid		*/
774 } vdev_aux_t;
775 
776 /*
777  * pool state.  The following states are written to disk as part of the normal
778  * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE.  The remaining
779  * states are software abstractions used at various levels to communicate
780  * pool state.
781  */
782 typedef enum pool_state {
783 	POOL_STATE_ACTIVE = 0,		/* In active use		*/
784 	POOL_STATE_EXPORTED,		/* Explicitly exported		*/
785 	POOL_STATE_DESTROYED,		/* Explicitly destroyed		*/
786 	POOL_STATE_SPARE,		/* Reserved for hot spare use	*/
787 	POOL_STATE_L2CACHE,		/* Level 2 ARC device		*/
788 	POOL_STATE_UNINITIALIZED,	/* Internal spa_t state		*/
789 	POOL_STATE_UNAVAIL,		/* Internal libzfs state	*/
790 	POOL_STATE_POTENTIALLY_ACTIVE	/* Internal libzfs state	*/
791 } pool_state_t;
792 
793 /*
794  * mmp state. The following states provide additional detail describing
795  * why a pool couldn't be safely imported.
796  */
797 typedef enum mmp_state {
798 	MMP_STATE_ACTIVE = 0,		/* In active use		*/
799 	MMP_STATE_INACTIVE,		/* Inactive and safe to import	*/
800 	MMP_STATE_NO_HOSTID		/* System hostid is not set	*/
801 } mmp_state_t;
802 
803 /*
804  * Scan Functions.
805  */
806 typedef enum pool_scan_func {
807 	POOL_SCAN_NONE,
808 	POOL_SCAN_SCRUB,
809 	POOL_SCAN_RESILVER,
810 	POOL_SCAN_FUNCS
811 } pool_scan_func_t;
812 
813 /*
814  * Used to control scrub pause and resume.
815  */
816 typedef enum pool_scrub_cmd {
817 	POOL_SCRUB_NORMAL = 0,
818 	POOL_SCRUB_PAUSE,
819 	POOL_SCRUB_FLAGS_END
820 } pool_scrub_cmd_t;
821 
822 /*
823  * Initialize functions.
824  */
825 typedef enum pool_initialize_func {
826 	POOL_INITIALIZE_DO,
827 	POOL_INITIALIZE_CANCEL,
828 	POOL_INITIALIZE_SUSPEND,
829 	POOL_INITIALIZE_FUNCS
830 } pool_initialize_func_t;
831 
832 /*
833  * ZIO types.  Needed to interpret vdev statistics below.
834  */
835 typedef enum zio_type {
836 	ZIO_TYPE_NULL = 0,
837 	ZIO_TYPE_READ,
838 	ZIO_TYPE_WRITE,
839 	ZIO_TYPE_FREE,
840 	ZIO_TYPE_CLAIM,
841 	ZIO_TYPE_IOCTL,
842 	ZIO_TYPES
843 } zio_type_t;
844 
845 /*
846  * Pool statistics.  Note: all fields should be 64-bit because this
847  * is passed between kernel and userland as an nvlist uint64 array.
848  */
849 typedef struct pool_scan_stat {
850 	/* values stored on disk */
851 	uint64_t	pss_func;	/* pool_scan_func_t */
852 	uint64_t	pss_state;	/* dsl_scan_state_t */
853 	uint64_t	pss_start_time;	/* scan start time */
854 	uint64_t	pss_end_time;	/* scan end time */
855 	uint64_t	pss_to_examine;	/* total bytes to scan */
856 	uint64_t	pss_examined;	/* total bytes located by scanner */
857 	uint64_t	pss_to_process; /* total bytes to process */
858 	uint64_t	pss_processed;	/* total processed bytes */
859 	uint64_t	pss_errors;	/* scan errors	*/
860 
861 	/* values not stored on disk */
862 	uint64_t	pss_pass_exam;	/* examined bytes per scan pass */
863 	uint64_t	pss_pass_issued; /* issued bytes per scan pass */
864 	uint64_t	pss_pass_start;	/* start time of a scan pass */
865 	uint64_t	pss_pass_scrub_pause; /* pause time of a scurb pass */
866 	/* cumulative time scrub spent paused, needed for rate calculation */
867 	uint64_t	pss_pass_scrub_spent_paused;
868 
869 	/* Sorted scrubbing new fields */
870 	/* Stored on disk */
871 	uint64_t	pss_issued;	/* total bytes checked by scanner */
872 } pool_scan_stat_t;
873 
874 /*
875  * Errata described by http://zfsonlinux.org/msg/ZFS-8000-ER.  The ordering
876  * of this enum must be maintained to ensure the errata identifiers map to
877  * the correct documentation.  New errata may only be appended to the list
878  * and must contain corresponding documentation at the above link.
879  */
880 typedef enum zpool_errata {
881 	ZPOOL_ERRATA_NONE,
882 	ZPOOL_ERRATA_ZOL_2094_SCRUB,
883 	ZPOOL_ERRATA_ZOL_2094_ASYNC_DESTROY,
884 	ZPOOL_ERRATA_ZOL_6845_ENCRYPTION,
885 	ZPOOL_ERRATA_ZOL_8308_ENCRYPTION,
886 } zpool_errata_t;
887 
888 typedef struct pool_removal_stat {
889 	uint64_t prs_state; /* dsl_scan_state_t */
890 	uint64_t prs_removing_vdev;
891 	uint64_t prs_start_time;
892 	uint64_t prs_end_time;
893 	uint64_t prs_to_copy; /* bytes that need to be copied */
894 	uint64_t prs_copied; /* bytes copied so far */
895 	/*
896 	 * bytes of memory used for indirect mappings.
897 	 * This includes all removed vdevs.
898 	 */
899 	uint64_t prs_mapping_memory;
900 } pool_removal_stat_t;
901 
902 typedef enum dsl_scan_state {
903 	DSS_NONE,
904 	DSS_SCANNING,
905 	DSS_FINISHED,
906 	DSS_CANCELED,
907 	DSS_NUM_STATES
908 } dsl_scan_state_t;
909 
910 typedef enum {
911 	CS_NONE,
912 	CS_CHECKPOINT_EXISTS,
913 	CS_CHECKPOINT_DISCARDING,
914 	CS_NUM_STATES
915 } checkpoint_state_t;
916 
917 typedef struct pool_checkpoint_stat {
918 	uint64_t pcs_state;		/* checkpoint_state_t */
919 	uint64_t pcs_start_time;	/* time checkpoint/discard started */
920 	uint64_t pcs_space;		/* checkpointed space */
921 } pool_checkpoint_stat_t;
922 
923 typedef enum {
924 	VDEV_INITIALIZE_NONE,
925 	VDEV_INITIALIZE_ACTIVE,
926 	VDEV_INITIALIZE_CANCELED,
927 	VDEV_INITIALIZE_SUSPENDED,
928 	VDEV_INITIALIZE_COMPLETE
929 } vdev_initializing_state_t;
930 
931 /*
932  * Vdev statistics.  Note: all fields should be 64-bit because this
933  * is passed between kernel and userland as an nvlist uint64 array.
934  */
935 typedef struct vdev_stat {
936 	hrtime_t	vs_timestamp;		/* time since vdev load	*/
937 	uint64_t	vs_state;		/* vdev state		*/
938 	uint64_t	vs_aux;			/* see vdev_aux_t	*/
939 	uint64_t	vs_alloc;		/* space allocated	*/
940 	uint64_t	vs_space;		/* total capacity	*/
941 	uint64_t	vs_dspace;		/* deflated capacity	*/
942 	uint64_t	vs_rsize;		/* replaceable dev size */
943 	uint64_t	vs_esize;		/* expandable dev size */
944 	uint64_t	vs_ops[ZIO_TYPES];	/* operation count	*/
945 	uint64_t	vs_bytes[ZIO_TYPES];	/* bytes read/written	*/
946 	uint64_t	vs_read_errors;		/* read errors		*/
947 	uint64_t	vs_write_errors;	/* write errors		*/
948 	uint64_t	vs_checksum_errors;	/* checksum errors	*/
949 	uint64_t	vs_initialize_errors;	/* initializing errors	*/
950 	uint64_t	vs_self_healed;		/* self-healed bytes	*/
951 	uint64_t	vs_scan_removing;	/* removing?	*/
952 	uint64_t	vs_scan_processed;	/* scan processed bytes	*/
953 	uint64_t	vs_fragmentation;	/* device fragmentation */
954 	uint64_t	vs_initialize_bytes_done; /* bytes initialized */
955 	uint64_t	vs_initialize_bytes_est; /* total bytes to initialize */
956 	uint64_t	vs_initialize_state;	/* vdev_initialzing_state_t */
957 	uint64_t	vs_initialize_action_time; /* time_t */
958 	uint64_t	vs_checkpoint_space;    /* checkpoint-consumed space */
959 	uint64_t	vs_resilver_deferred;	/* resilver deferred	*/
960 } vdev_stat_t;
961 
962 /*
963  * DDT statistics.  Note: all fields should be 64-bit because this
964  * is passed between kernel and userland as an nvlist uint64 array.
965  */
966 typedef struct ddt_object {
967 	uint64_t	ddo_count;	/* number of elments in ddt	*/
968 	uint64_t	ddo_dspace;	/* size of ddt on disk		*/
969 	uint64_t	ddo_mspace;	/* size of ddt in-core		*/
970 } ddt_object_t;
971 
972 typedef struct ddt_stat {
973 	uint64_t	dds_blocks;	/* blocks			*/
974 	uint64_t	dds_lsize;	/* logical size			*/
975 	uint64_t	dds_psize;	/* physical size		*/
976 	uint64_t	dds_dsize;	/* deflated allocated size	*/
977 	uint64_t	dds_ref_blocks;	/* referenced blocks		*/
978 	uint64_t	dds_ref_lsize;	/* referenced lsize * refcnt	*/
979 	uint64_t	dds_ref_psize;	/* referenced psize * refcnt	*/
980 	uint64_t	dds_ref_dsize;	/* referenced dsize * refcnt	*/
981 } ddt_stat_t;
982 
983 typedef struct ddt_histogram {
984 	ddt_stat_t	ddh_stat[64];	/* power-of-two histogram buckets */
985 } ddt_histogram_t;
986 
987 #define	ZVOL_DRIVER	"zvol"
988 #define	ZFS_DRIVER	"zfs"
989 #define	ZFS_DEV		"/dev/zfs"
990 #define	ZFS_DISK_ROOT	"/dev/dsk"
991 #define	ZFS_DISK_ROOTD	ZFS_DISK_ROOT "/"
992 #define	ZFS_RDISK_ROOT	"/dev/rdsk"
993 #define	ZFS_RDISK_ROOTD	ZFS_RDISK_ROOT "/"
994 
995 /* general zvol path */
996 #define	ZVOL_DIR		"/dev/zvol"
997 /* expansion */
998 #define	ZVOL_PSEUDO_DEV		"/devices/pseudo/zfs@0:"
999 /* for dump and swap */
1000 #define	ZVOL_FULL_DEV_DIR	ZVOL_DIR "/dsk/"
1001 #define	ZVOL_FULL_RDEV_DIR	ZVOL_DIR "/rdsk/"
1002 
1003 #define	ZVOL_PROP_NAME		"name"
1004 #define	ZVOL_DEFAULT_BLOCKSIZE	8192
1005 
1006 /*
1007  * /dev/zfs ioctl numbers.
1008  */
1009 typedef enum zfs_ioc {
1010 	ZFS_IOC_FIRST =	('Z' << 8),
1011 	ZFS_IOC = ZFS_IOC_FIRST,
1012 	ZFS_IOC_POOL_CREATE = ZFS_IOC_FIRST,
1013 	ZFS_IOC_POOL_DESTROY,
1014 	ZFS_IOC_POOL_IMPORT,
1015 	ZFS_IOC_POOL_EXPORT,
1016 	ZFS_IOC_POOL_CONFIGS,
1017 	ZFS_IOC_POOL_STATS,
1018 	ZFS_IOC_POOL_TRYIMPORT,
1019 	ZFS_IOC_POOL_SCAN,
1020 	ZFS_IOC_POOL_FREEZE,
1021 	ZFS_IOC_POOL_UPGRADE,
1022 	ZFS_IOC_POOL_GET_HISTORY,
1023 	ZFS_IOC_VDEV_ADD,
1024 	ZFS_IOC_VDEV_REMOVE,
1025 	ZFS_IOC_VDEV_SET_STATE,
1026 	ZFS_IOC_VDEV_ATTACH,
1027 	ZFS_IOC_VDEV_DETACH,
1028 	ZFS_IOC_VDEV_SETPATH,
1029 	ZFS_IOC_VDEV_SETFRU,
1030 	ZFS_IOC_OBJSET_STATS,
1031 	ZFS_IOC_OBJSET_ZPLPROPS,
1032 	ZFS_IOC_DATASET_LIST_NEXT,
1033 	ZFS_IOC_SNAPSHOT_LIST_NEXT,
1034 	ZFS_IOC_SET_PROP,
1035 	ZFS_IOC_CREATE,
1036 	ZFS_IOC_DESTROY,
1037 	ZFS_IOC_ROLLBACK,
1038 	ZFS_IOC_RENAME,
1039 	ZFS_IOC_RECV,
1040 	ZFS_IOC_SEND,
1041 	ZFS_IOC_INJECT_FAULT,
1042 	ZFS_IOC_CLEAR_FAULT,
1043 	ZFS_IOC_INJECT_LIST_NEXT,
1044 	ZFS_IOC_ERROR_LOG,
1045 	ZFS_IOC_CLEAR,
1046 	ZFS_IOC_PROMOTE,
1047 	ZFS_IOC_SNAPSHOT,
1048 	ZFS_IOC_DSOBJ_TO_DSNAME,
1049 	ZFS_IOC_OBJ_TO_PATH,
1050 	ZFS_IOC_POOL_SET_PROPS,
1051 	ZFS_IOC_POOL_GET_PROPS,
1052 	ZFS_IOC_SET_FSACL,
1053 	ZFS_IOC_GET_FSACL,
1054 	ZFS_IOC_SHARE,
1055 	ZFS_IOC_INHERIT_PROP,
1056 	ZFS_IOC_SMB_ACL,
1057 	ZFS_IOC_USERSPACE_ONE,
1058 	ZFS_IOC_USERSPACE_MANY,
1059 	ZFS_IOC_USERSPACE_UPGRADE,
1060 	ZFS_IOC_HOLD,
1061 	ZFS_IOC_RELEASE,
1062 	ZFS_IOC_GET_HOLDS,
1063 	ZFS_IOC_OBJSET_RECVD_PROPS,
1064 	ZFS_IOC_VDEV_SPLIT,
1065 	ZFS_IOC_NEXT_OBJ,
1066 	ZFS_IOC_DIFF,
1067 	ZFS_IOC_TMP_SNAPSHOT,
1068 	ZFS_IOC_OBJ_TO_STATS,
1069 	ZFS_IOC_SPACE_WRITTEN,
1070 	ZFS_IOC_SPACE_SNAPS,
1071 	ZFS_IOC_DESTROY_SNAPS,
1072 	ZFS_IOC_POOL_REGUID,
1073 	ZFS_IOC_POOL_REOPEN,
1074 	ZFS_IOC_SEND_PROGRESS,
1075 	ZFS_IOC_LOG_HISTORY,
1076 	ZFS_IOC_SEND_NEW,
1077 	ZFS_IOC_SEND_SPACE,
1078 	ZFS_IOC_CLONE,
1079 	ZFS_IOC_BOOKMARK,
1080 	ZFS_IOC_GET_BOOKMARKS,
1081 	ZFS_IOC_DESTROY_BOOKMARKS,
1082 	ZFS_IOC_CHANNEL_PROGRAM,
1083 	ZFS_IOC_REMAP,
1084 	ZFS_IOC_POOL_CHECKPOINT,
1085 	ZFS_IOC_POOL_DISCARD_CHECKPOINT,
1086 	ZFS_IOC_POOL_INITIALIZE,
1087 	ZFS_IOC_POOL_SYNC,
1088 	ZFS_IOC_LOAD_KEY,
1089 	ZFS_IOC_UNLOAD_KEY,
1090 	ZFS_IOC_CHANGE_KEY,
1091 	ZFS_IOC_LAST
1092 } zfs_ioc_t;
1093 
1094 /*
1095  * ZFS-specific error codes used for returning descriptive errors
1096  * to the userland through zfs ioctls.
1097  *
1098  * The enum implicitly includes all the error codes from errno.h.
1099  * New code should use and extend this enum for errors that are
1100  * not described precisely by generic errno codes.
1101  */
1102 typedef enum {
1103 	ZFS_ERR_CHECKPOINT_EXISTS = 1024,
1104 	ZFS_ERR_DISCARDING_CHECKPOINT,
1105 	ZFS_ERR_NO_CHECKPOINT,
1106 	ZFS_ERR_DEVRM_IN_PROGRESS,
1107 	ZFS_ERR_VDEV_TOO_BIG,
1108 	ZFS_ERR_FROM_IVSET_GUID_MISSING,
1109 	ZFS_ERR_FROM_IVSET_GUID_MISMATCH,
1110 	ZFS_ERR_SPILL_BLOCK_FLAG_MISSING,
1111 } zfs_errno_t;
1112 
1113 /*
1114  * Internal SPA load state.  Used by FMA diagnosis engine.
1115  */
1116 typedef enum {
1117 	SPA_LOAD_NONE,		/* no load in progress	*/
1118 	SPA_LOAD_OPEN,		/* normal open		*/
1119 	SPA_LOAD_IMPORT,	/* import in progress	*/
1120 	SPA_LOAD_TRYIMPORT,	/* tryimport in progress */
1121 	SPA_LOAD_RECOVER,	/* recovery requested	*/
1122 	SPA_LOAD_ERROR,		/* load failed		*/
1123 	SPA_LOAD_CREATE		/* creation in progress */
1124 } spa_load_state_t;
1125 
1126 /* supported encryption algorithms */
1127 enum zio_encrypt {
1128 	ZIO_CRYPT_INHERIT = 0,
1129 	ZIO_CRYPT_ON,
1130 	ZIO_CRYPT_OFF,
1131 	ZIO_CRYPT_AES_128_CCM,
1132 	ZIO_CRYPT_AES_192_CCM,
1133 	ZIO_CRYPT_AES_256_CCM,
1134 	ZIO_CRYPT_AES_128_GCM,
1135 	ZIO_CRYPT_AES_192_GCM,
1136 	ZIO_CRYPT_AES_256_GCM,
1137 	ZIO_CRYPT_FUNCTIONS
1138 };
1139 
1140 /*
1141  * Bookmark name values.
1142  */
1143 #define	ZPOOL_ERR_LIST		"error list"
1144 #define	ZPOOL_ERR_DATASET	"dataset"
1145 #define	ZPOOL_ERR_OBJECT	"object"
1146 
1147 #define	HIS_MAX_RECORD_LEN	(MAXPATHLEN + MAXPATHLEN + 1)
1148 
1149 /*
1150  * The following are names used in the nvlist describing
1151  * the pool's history log.
1152  */
1153 #define	ZPOOL_HIST_RECORD	"history record"
1154 #define	ZPOOL_HIST_TIME		"history time"
1155 #define	ZPOOL_HIST_CMD		"history command"
1156 #define	ZPOOL_HIST_WHO		"history who"
1157 #define	ZPOOL_HIST_ZONE		"history zone"
1158 #define	ZPOOL_HIST_HOST		"history hostname"
1159 #define	ZPOOL_HIST_TXG		"history txg"
1160 #define	ZPOOL_HIST_INT_EVENT	"history internal event"
1161 #define	ZPOOL_HIST_INT_STR	"history internal str"
1162 #define	ZPOOL_HIST_INT_NAME	"internal_name"
1163 #define	ZPOOL_HIST_IOCTL	"ioctl"
1164 #define	ZPOOL_HIST_INPUT_NVL	"in_nvl"
1165 #define	ZPOOL_HIST_OUTPUT_NVL	"out_nvl"
1166 #define	ZPOOL_HIST_DSNAME	"dsname"
1167 #define	ZPOOL_HIST_DSID		"dsid"
1168 #define	ZPOOL_HIST_ERRNO	"errno"
1169 
1170 /*
1171  * The following are names used when invoking ZFS_IOC_POOL_INITIALIZE.
1172  */
1173 #define	ZPOOL_INITIALIZE_COMMAND	"initialize_command"
1174 #define	ZPOOL_INITIALIZE_VDEVS		"initialize_vdevs"
1175 
1176 /*
1177  * Special nvlist name that will not have its args recorded in the pool's
1178  * history log.
1179  */
1180 #define	ZPOOL_HIDDEN_ARGS	"hidden_args"
1181 
1182 /*
1183  * Flags for ZFS_IOC_VDEV_SET_STATE
1184  */
1185 #define	ZFS_ONLINE_CHECKREMOVE	0x1
1186 #define	ZFS_ONLINE_UNSPARE	0x2
1187 #define	ZFS_ONLINE_FORCEFAULT	0x4
1188 #define	ZFS_ONLINE_EXPAND	0x8
1189 #define	ZFS_OFFLINE_TEMPORARY	0x1
1190 
1191 /*
1192  * Flags for ZFS_IOC_POOL_IMPORT
1193  */
1194 #define	ZFS_IMPORT_NORMAL	0x0
1195 #define	ZFS_IMPORT_VERBATIM	0x1
1196 #define	ZFS_IMPORT_ANY_HOST	0x2
1197 #define	ZFS_IMPORT_MISSING_LOG	0x4
1198 #define	ZFS_IMPORT_ONLY		0x8
1199 #define	ZFS_IMPORT_CHECKPOINT	0x10
1200 #define	ZFS_IMPORT_TEMP_NAME	0x20
1201 #define	ZFS_IMPORT_SKIP_MMP	0x40
1202 #define	ZFS_IMPORT_LOAD_KEYS	0x80
1203 
1204 /*
1205  * Channel program argument/return nvlist keys and defaults.
1206  */
1207 #define	ZCP_ARG_PROGRAM		"program"
1208 #define	ZCP_ARG_ARGLIST		"arg"
1209 #define	ZCP_ARG_SYNC		"sync"
1210 #define	ZCP_ARG_INSTRLIMIT	"instrlimit"
1211 #define	ZCP_ARG_MEMLIMIT	"memlimit"
1212 
1213 #define	ZCP_ARG_CLIARGV		"argv"
1214 
1215 #define	ZCP_RET_ERROR		"error"
1216 #define	ZCP_RET_RETURN		"return"
1217 
1218 #define	ZCP_DEFAULT_INSTRLIMIT	(10 * 1000 * 1000)
1219 #define	ZCP_MAX_INSTRLIMIT	(10 * ZCP_DEFAULT_INSTRLIMIT)
1220 #define	ZCP_DEFAULT_MEMLIMIT	(10 * 1024 * 1024)
1221 #define	ZCP_MAX_MEMLIMIT	(10 * ZCP_DEFAULT_MEMLIMIT)
1222 
1223 /*
1224  * Sysevent payload members.  ZFS will generate the following sysevents with the
1225  * given payloads:
1226  *
1227  *	ESC_ZFS_RESILVER_START
1228  *	ESC_ZFS_RESILVER_END
1229  *	ESC_ZFS_POOL_DESTROY
1230  *	ESC_ZFS_POOL_REGUID
1231  *
1232  *		ZFS_EV_POOL_NAME	DATA_TYPE_STRING
1233  *		ZFS_EV_POOL_GUID	DATA_TYPE_UINT64
1234  *
1235  *	ESC_ZFS_VDEV_REMOVE
1236  *	ESC_ZFS_VDEV_CLEAR
1237  *	ESC_ZFS_VDEV_CHECK
1238  *
1239  *		ZFS_EV_POOL_NAME	DATA_TYPE_STRING
1240  *		ZFS_EV_POOL_GUID	DATA_TYPE_UINT64
1241  *		ZFS_EV_VDEV_PATH	DATA_TYPE_STRING	(optional)
1242  *		ZFS_EV_VDEV_GUID	DATA_TYPE_UINT64
1243  *
1244  *	ESC_ZFS_HISTORY_EVENT
1245  *
1246  *		ZFS_EV_POOL_NAME	DATA_TYPE_STRING
1247  *		ZFS_EV_POOL_GUID	DATA_TYPE_UINT64
1248  *		ZFS_EV_HIST_TIME	DATA_TYPE_UINT64	(optional)
1249  *		ZFS_EV_HIST_CMD		DATA_TYPE_STRING	(optional)
1250  *		ZFS_EV_HIST_WHO		DATA_TYPE_UINT64	(optional)
1251  *		ZFS_EV_HIST_ZONE	DATA_TYPE_STRING	(optional)
1252  *		ZFS_EV_HIST_HOST	DATA_TYPE_STRING	(optional)
1253  *		ZFS_EV_HIST_TXG		DATA_TYPE_UINT64	(optional)
1254  *		ZFS_EV_HIST_INT_EVENT	DATA_TYPE_UINT64	(optional)
1255  *		ZFS_EV_HIST_INT_STR	DATA_TYPE_STRING	(optional)
1256  *		ZFS_EV_HIST_INT_NAME	DATA_TYPE_STRING	(optional)
1257  *		ZFS_EV_HIST_IOCTL	DATA_TYPE_STRING	(optional)
1258  *		ZFS_EV_HIST_DSNAME	DATA_TYPE_STRING	(optional)
1259  *		ZFS_EV_HIST_DSID	DATA_TYPE_UINT64	(optional)
1260  *
1261  * The ZFS_EV_HIST_* members will correspond to the ZPOOL_HIST_* members in the
1262  * history log nvlist.  The keynames will be free of any spaces or other
1263  * characters that could be potentially unexpected to consumers of the
1264  * sysevents.
1265  */
1266 #define	ZFS_EV_POOL_NAME	"pool_name"
1267 #define	ZFS_EV_POOL_GUID	"pool_guid"
1268 #define	ZFS_EV_VDEV_PATH	"vdev_path"
1269 #define	ZFS_EV_VDEV_GUID	"vdev_guid"
1270 #define	ZFS_EV_HIST_TIME	"history_time"
1271 #define	ZFS_EV_HIST_CMD		"history_command"
1272 #define	ZFS_EV_HIST_WHO		"history_who"
1273 #define	ZFS_EV_HIST_ZONE	"history_zone"
1274 #define	ZFS_EV_HIST_HOST	"history_hostname"
1275 #define	ZFS_EV_HIST_TXG		"history_txg"
1276 #define	ZFS_EV_HIST_INT_EVENT	"history_internal_event"
1277 #define	ZFS_EV_HIST_INT_STR	"history_internal_str"
1278 #define	ZFS_EV_HIST_INT_NAME	"history_internal_name"
1279 #define	ZFS_EV_HIST_IOCTL	"history_ioctl"
1280 #define	ZFS_EV_HIST_DSNAME	"history_dsname"
1281 #define	ZFS_EV_HIST_DSID	"history_dsid"
1282 
1283 #ifdef	__cplusplus
1284 }
1285 #endif
1286 
1287 #endif	/* _SYS_FS_ZFS_H */
1288