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