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 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_FS_ZFS_H
28 #define	_SYS_FS_ZFS_H
29 
30 #include <sys/time.h>
31 #include <sys/ioctl.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * Types and constants shared between userland and the kernel.
39  */
40 
41 /*
42  * Each dataset can be one of the following types.  These constants can be
43  * combined into masks that can be passed to various functions.
44  */
45 typedef enum {
46 	ZFS_TYPE_FILESYSTEM	= 0x1,
47 	ZFS_TYPE_SNAPSHOT	= 0x2,
48 	ZFS_TYPE_VOLUME		= 0x4,
49 	ZFS_TYPE_POOL		= 0x8
50 } zfs_type_t;
51 
52 #define	ZFS_TYPE_DATASET	\
53 	(ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME | ZFS_TYPE_SNAPSHOT)
54 
55 #define	ZAP_MAXNAMELEN 256
56 #define	ZAP_MAXVALUELEN (1024 * 8)
57 #define	ZAP_OLDMAXVALUELEN 1024
58 
59 /*
60  * Dataset properties are identified by these constants and must be added to
61  * the end of this list to ensure that external consumers are not affected
62  * by the change. If you make any changes to this list, be sure to update
63  * the property table in usr/src/common/zfs/zfs_prop.c.
64  */
65 typedef enum {
66 	ZFS_PROP_TYPE,
67 	ZFS_PROP_CREATION,
68 	ZFS_PROP_USED,
69 	ZFS_PROP_AVAILABLE,
70 	ZFS_PROP_REFERENCED,
71 	ZFS_PROP_COMPRESSRATIO,
72 	ZFS_PROP_MOUNTED,
73 	ZFS_PROP_ORIGIN,
74 	ZFS_PROP_QUOTA,
75 	ZFS_PROP_RESERVATION,
76 	ZFS_PROP_VOLSIZE,
77 	ZFS_PROP_VOLBLOCKSIZE,
78 	ZFS_PROP_RECORDSIZE,
79 	ZFS_PROP_MOUNTPOINT,
80 	ZFS_PROP_SHARENFS,
81 	ZFS_PROP_CHECKSUM,
82 	ZFS_PROP_COMPRESSION,
83 	ZFS_PROP_ATIME,
84 	ZFS_PROP_DEVICES,
85 	ZFS_PROP_EXEC,
86 	ZFS_PROP_SETUID,
87 	ZFS_PROP_READONLY,
88 	ZFS_PROP_ZONED,
89 	ZFS_PROP_SNAPDIR,
90 	ZFS_PROP_ACLMODE,
91 	ZFS_PROP_ACLINHERIT,
92 	ZFS_PROP_CREATETXG,		/* not exposed to the user */
93 	ZFS_PROP_NAME,			/* not exposed to the user */
94 	ZFS_PROP_CANMOUNT,
95 	ZFS_PROP_SHAREISCSI,
96 	ZFS_PROP_ISCSIOPTIONS,		/* not exposed to the user */
97 	ZFS_PROP_XATTR,
98 	ZFS_PROP_NUMCLONES,		/* not exposed to the user */
99 	ZFS_PROP_COPIES,
100 	ZFS_PROP_VERSION,
101 	ZFS_PROP_UTF8ONLY,
102 	ZFS_PROP_NORMALIZE,
103 	ZFS_PROP_CASE,
104 	ZFS_PROP_VSCAN,
105 	ZFS_PROP_NBMAND,
106 	ZFS_PROP_SHARESMB,
107 	ZFS_PROP_REFQUOTA,
108 	ZFS_PROP_REFRESERVATION,
109 	ZFS_PROP_GUID,
110 	ZFS_PROP_PRIMARYCACHE,
111 	ZFS_PROP_SECONDARYCACHE,
112 	ZFS_PROP_USEDSNAP,
113 	ZFS_PROP_USEDDS,
114 	ZFS_PROP_USEDCHILD,
115 	ZFS_PROP_USEDREFRESERV,
116 	ZFS_PROP_USERACCOUNTING,	/* not exposed to the user */
117 	ZFS_PROP_STMF_SHAREINFO,	/* not exposed to the user */
118 	ZFS_PROP_DEFER_DESTROY,
119 	ZFS_PROP_USERREFS,
120 	ZFS_PROP_LOGBIAS,
121 	ZFS_PROP_UNIQUE,		/* not exposed to the user */
122 	ZFS_PROP_OBJSETID,		/* not exposed to the user */
123 	ZFS_PROP_DEDUP,
124 	ZFS_PROP_MLSLABEL,
125 	ZFS_NUM_PROPS
126 } zfs_prop_t;
127 
128 typedef enum {
129 	ZFS_PROP_USERUSED,
130 	ZFS_PROP_USERQUOTA,
131 	ZFS_PROP_GROUPUSED,
132 	ZFS_PROP_GROUPQUOTA,
133 	ZFS_NUM_USERQUOTA_PROPS
134 } zfs_userquota_prop_t;
135 
136 extern const char *zfs_userquota_prop_prefixes[ZFS_NUM_USERQUOTA_PROPS];
137 
138 /*
139  * Pool properties are identified by these constants and must be added to the
140  * end of this list to ensure that external consumers are not affected
141  * by the change. If you make any changes to this list, be sure to update
142  * the property table in usr/src/common/zfs/zpool_prop.c.
143  */
144 typedef enum {
145 	ZPOOL_PROP_NAME,
146 	ZPOOL_PROP_SIZE,
147 	ZPOOL_PROP_CAPACITY,
148 	ZPOOL_PROP_ALTROOT,
149 	ZPOOL_PROP_HEALTH,
150 	ZPOOL_PROP_GUID,
151 	ZPOOL_PROP_VERSION,
152 	ZPOOL_PROP_BOOTFS,
153 	ZPOOL_PROP_DELEGATION,
154 	ZPOOL_PROP_AUTOREPLACE,
155 	ZPOOL_PROP_CACHEFILE,
156 	ZPOOL_PROP_FAILUREMODE,
157 	ZPOOL_PROP_LISTSNAPS,
158 	ZPOOL_PROP_AUTOEXPAND,
159 	ZPOOL_PROP_DEDUPDITTO,
160 	ZPOOL_PROP_DEDUPRATIO,
161 	ZPOOL_PROP_FREE,
162 	ZPOOL_PROP_ALLOCATED,
163 	ZPOOL_NUM_PROPS
164 } zpool_prop_t;
165 
166 #define	ZPROP_CONT		-2
167 #define	ZPROP_INVAL		-1
168 
169 #define	ZPROP_VALUE		"value"
170 #define	ZPROP_SOURCE		"source"
171 
172 typedef enum {
173 	ZPROP_SRC_NONE = 0x1,
174 	ZPROP_SRC_DEFAULT = 0x2,
175 	ZPROP_SRC_TEMPORARY = 0x4,
176 	ZPROP_SRC_LOCAL = 0x8,
177 	ZPROP_SRC_INHERITED = 0x10,
178 	ZPROP_SRC_RECEIVED = 0x20
179 } zprop_source_t;
180 
181 #define	ZPROP_SRC_ALL	0x3f
182 
183 #define	ZPROP_SOURCE_VAL_RECVD	"$recvd"
184 #define	ZPROP_N_MORE_ERRORS	"N_MORE_ERRORS"
185 /*
186  * Dataset flag implemented as a special entry in the props zap object
187  * indicating that the dataset has received properties on or after
188  * SPA_VERSION_RECVD_PROPS. The first such receive blows away local properties
189  * just as it did in earlier versions, and thereafter, local properties are
190  * preserved.
191  */
192 #define	ZPROP_HAS_RECVD		"$hasrecvd"
193 
194 typedef enum {
195 	ZPROP_ERR_NOCLEAR = 0x1, /* failure to clear existing props */
196 	ZPROP_ERR_NORESTORE = 0x2 /* failure to restore props on error */
197 } zprop_errflags_t;
198 
199 typedef int (*zprop_func)(int, void *);
200 
201 /*
202  * Properties to be set on the root file system of a new pool
203  * are stuffed into their own nvlist, which is then included in
204  * the properties nvlist with the pool properties.
205  */
206 #define	ZPOOL_ROOTFS_PROPS	"root-props-nvl"
207 
208 /*
209  * Dataset property functions shared between libzfs and kernel.
210  */
211 const char *zfs_prop_default_string(zfs_prop_t);
212 uint64_t zfs_prop_default_numeric(zfs_prop_t);
213 boolean_t zfs_prop_readonly(zfs_prop_t);
214 boolean_t zfs_prop_inheritable(zfs_prop_t);
215 boolean_t zfs_prop_setonce(zfs_prop_t);
216 const char *zfs_prop_to_name(zfs_prop_t);
217 zfs_prop_t zfs_name_to_prop(const char *);
218 boolean_t zfs_prop_user(const char *);
219 boolean_t zfs_prop_userquota(const char *);
220 int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
221 int zfs_prop_string_to_index(zfs_prop_t, const char *, uint64_t *);
222 uint64_t zfs_prop_random_value(zfs_prop_t, uint64_t seed);
223 boolean_t zfs_prop_valid_for_type(int, zfs_type_t);
224 
225 /*
226  * Pool property functions shared between libzfs and kernel.
227  */
228 zpool_prop_t zpool_name_to_prop(const char *);
229 const char *zpool_prop_to_name(zpool_prop_t);
230 const char *zpool_prop_default_string(zpool_prop_t);
231 uint64_t zpool_prop_default_numeric(zpool_prop_t);
232 boolean_t zpool_prop_readonly(zpool_prop_t);
233 int zpool_prop_index_to_string(zpool_prop_t, uint64_t, const char **);
234 int zpool_prop_string_to_index(zpool_prop_t, const char *, uint64_t *);
235 uint64_t zpool_prop_random_value(zpool_prop_t, uint64_t seed);
236 
237 /*
238  * Definitions for the Delegation.
239  */
240 typedef enum {
241 	ZFS_DELEG_WHO_UNKNOWN = 0,
242 	ZFS_DELEG_USER = 'u',
243 	ZFS_DELEG_USER_SETS = 'U',
244 	ZFS_DELEG_GROUP = 'g',
245 	ZFS_DELEG_GROUP_SETS = 'G',
246 	ZFS_DELEG_EVERYONE = 'e',
247 	ZFS_DELEG_EVERYONE_SETS = 'E',
248 	ZFS_DELEG_CREATE = 'c',
249 	ZFS_DELEG_CREATE_SETS = 'C',
250 	ZFS_DELEG_NAMED_SET = 's',
251 	ZFS_DELEG_NAMED_SET_SETS = 'S'
252 } zfs_deleg_who_type_t;
253 
254 typedef enum {
255 	ZFS_DELEG_NONE = 0,
256 	ZFS_DELEG_PERM_LOCAL = 1,
257 	ZFS_DELEG_PERM_DESCENDENT = 2,
258 	ZFS_DELEG_PERM_LOCALDESCENDENT = 3,
259 	ZFS_DELEG_PERM_CREATE = 4
260 } zfs_deleg_inherit_t;
261 
262 #define	ZFS_DELEG_PERM_UID	"uid"
263 #define	ZFS_DELEG_PERM_GID	"gid"
264 #define	ZFS_DELEG_PERM_GROUPS	"groups"
265 
266 #define	ZFS_MLSLABEL_DEFAULT	"none"
267 
268 #define	ZFS_SMB_ACL_SRC		"src"
269 #define	ZFS_SMB_ACL_TARGET	"target"
270 
271 typedef enum {
272 	ZFS_CANMOUNT_OFF = 0,
273 	ZFS_CANMOUNT_ON = 1,
274 	ZFS_CANMOUNT_NOAUTO = 2
275 } zfs_canmount_type_t;
276 
277 typedef enum {
278 	ZFS_LOGBIAS_LATENCY = 0,
279 	ZFS_LOGBIAS_THROUGHPUT = 1
280 } zfs_logbias_op_t;
281 
282 typedef enum zfs_share_op {
283 	ZFS_SHARE_NFS = 0,
284 	ZFS_UNSHARE_NFS = 1,
285 	ZFS_SHARE_SMB = 2,
286 	ZFS_UNSHARE_SMB = 3
287 } zfs_share_op_t;
288 
289 typedef enum zfs_smb_acl_op {
290 	ZFS_SMB_ACL_ADD,
291 	ZFS_SMB_ACL_REMOVE,
292 	ZFS_SMB_ACL_RENAME,
293 	ZFS_SMB_ACL_PURGE
294 } zfs_smb_acl_op_t;
295 
296 typedef enum zfs_cache_type {
297 	ZFS_CACHE_NONE = 0,
298 	ZFS_CACHE_METADATA = 1,
299 	ZFS_CACHE_ALL = 2
300 } zfs_cache_type_t;
301 
302 
303 /*
304  * On-disk version number.
305  */
306 #define	SPA_VERSION_1			1ULL
307 #define	SPA_VERSION_2			2ULL
308 #define	SPA_VERSION_3			3ULL
309 #define	SPA_VERSION_4			4ULL
310 #define	SPA_VERSION_5			5ULL
311 #define	SPA_VERSION_6			6ULL
312 #define	SPA_VERSION_7			7ULL
313 #define	SPA_VERSION_8			8ULL
314 #define	SPA_VERSION_9			9ULL
315 #define	SPA_VERSION_10			10ULL
316 #define	SPA_VERSION_11			11ULL
317 #define	SPA_VERSION_12			12ULL
318 #define	SPA_VERSION_13			13ULL
319 #define	SPA_VERSION_14			14ULL
320 #define	SPA_VERSION_15			15ULL
321 #define	SPA_VERSION_16			16ULL
322 #define	SPA_VERSION_17			17ULL
323 #define	SPA_VERSION_18			18ULL
324 #define	SPA_VERSION_19			19ULL
325 #define	SPA_VERSION_20			20ULL
326 #define	SPA_VERSION_21			21ULL
327 #define	SPA_VERSION_22			22ULL
328 #define	SPA_VERSION_23			23ULL
329 /*
330  * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk
331  * format change. Go to usr/src/grub/grub-0.97/stage2/{zfs-include/, fsys_zfs*},
332  * and do the appropriate changes.  Also bump the version number in
333  * usr/src/grub/capability.
334  */
335 #define	SPA_VERSION			SPA_VERSION_23
336 #define	SPA_VERSION_STRING		"23"
337 
338 /*
339  * Symbolic names for the changes that caused a SPA_VERSION switch.
340  * Used in the code when checking for presence or absence of a feature.
341  * Feel free to define multiple symbolic names for each version if there
342  * were multiple changes to on-disk structures during that version.
343  *
344  * NOTE: When checking the current SPA_VERSION in your code, be sure
345  *       to use spa_version() since it reports the version of the
346  *       last synced uberblock.  Checking the in-flight version can
347  *       be dangerous in some cases.
348  */
349 #define	SPA_VERSION_INITIAL		SPA_VERSION_1
350 #define	SPA_VERSION_DITTO_BLOCKS	SPA_VERSION_2
351 #define	SPA_VERSION_SPARES		SPA_VERSION_3
352 #define	SPA_VERSION_RAIDZ2		SPA_VERSION_3
353 #define	SPA_VERSION_BPLIST_ACCOUNT	SPA_VERSION_3
354 #define	SPA_VERSION_RAIDZ_DEFLATE	SPA_VERSION_3
355 #define	SPA_VERSION_DNODE_BYTES		SPA_VERSION_3
356 #define	SPA_VERSION_ZPOOL_HISTORY	SPA_VERSION_4
357 #define	SPA_VERSION_GZIP_COMPRESSION	SPA_VERSION_5
358 #define	SPA_VERSION_BOOTFS		SPA_VERSION_6
359 #define	SPA_VERSION_SLOGS		SPA_VERSION_7
360 #define	SPA_VERSION_DELEGATED_PERMS	SPA_VERSION_8
361 #define	SPA_VERSION_FUID		SPA_VERSION_9
362 #define	SPA_VERSION_REFRESERVATION	SPA_VERSION_9
363 #define	SPA_VERSION_REFQUOTA		SPA_VERSION_9
364 #define	SPA_VERSION_UNIQUE_ACCURATE	SPA_VERSION_9
365 #define	SPA_VERSION_L2CACHE		SPA_VERSION_10
366 #define	SPA_VERSION_NEXT_CLONES		SPA_VERSION_11
367 #define	SPA_VERSION_ORIGIN		SPA_VERSION_11
368 #define	SPA_VERSION_DSL_SCRUB		SPA_VERSION_11
369 #define	SPA_VERSION_SNAP_PROPS		SPA_VERSION_12
370 #define	SPA_VERSION_USED_BREAKDOWN	SPA_VERSION_13
371 #define	SPA_VERSION_PASSTHROUGH_X	SPA_VERSION_14
372 #define	SPA_VERSION_USERSPACE		SPA_VERSION_15
373 #define	SPA_VERSION_STMF_PROP		SPA_VERSION_16
374 #define	SPA_VERSION_RAIDZ3		SPA_VERSION_17
375 #define	SPA_VERSION_USERREFS		SPA_VERSION_18
376 #define	SPA_VERSION_HOLES		SPA_VERSION_19
377 #define	SPA_VERSION_ZLE_COMPRESSION	SPA_VERSION_20
378 #define	SPA_VERSION_DEDUP		SPA_VERSION_21
379 #define	SPA_VERSION_RECVD_PROPS		SPA_VERSION_22
380 #define	SPA_VERSION_SLIM_ZIL		SPA_VERSION_23
381 
382 /*
383  * ZPL version - rev'd whenever an incompatible on-disk format change
384  * occurs.  This is independent of SPA/DMU/ZAP versioning.  You must
385  * also update the version_table[] and help message in zfs_prop.c.
386  *
387  * When changing, be sure to teach GRUB how to read the new format!
388  * See usr/src/grub/grub-0.97/stage2/{zfs-include/,fsys_zfs*}
389  */
390 #define	ZPL_VERSION_1			1ULL
391 #define	ZPL_VERSION_2			2ULL
392 #define	ZPL_VERSION_3			3ULL
393 #define	ZPL_VERSION_4			4ULL
394 #define	ZPL_VERSION			ZPL_VERSION_4
395 #define	ZPL_VERSION_STRING		"4"
396 
397 #define	ZPL_VERSION_INITIAL		ZPL_VERSION_1
398 #define	ZPL_VERSION_DIRENT_TYPE		ZPL_VERSION_2
399 #define	ZPL_VERSION_FUID		ZPL_VERSION_3
400 #define	ZPL_VERSION_NORMALIZATION	ZPL_VERSION_3
401 #define	ZPL_VERSION_SYSATTR		ZPL_VERSION_3
402 #define	ZPL_VERSION_USERSPACE		ZPL_VERSION_4
403 
404 /* Rewind request information */
405 #define	ZPOOL_NO_REWIND		1  /* No policy - default behavior */
406 #define	ZPOOL_NEVER_REWIND	2  /* Do not search for best txg or rewind */
407 #define	ZPOOL_TRY_REWIND	4  /* Search for best txg, but do not rewind */
408 #define	ZPOOL_DO_REWIND		8  /* Rewind to best txg w/in deferred frees */
409 #define	ZPOOL_EXTREME_REWIND	16 /* Allow extreme measures to find best txg */
410 #define	ZPOOL_REWIND_MASK	28 /* All the possible rewind bits */
411 #define	ZPOOL_REWIND_POLICIES	31 /* All the possible policy bits */
412 
413 typedef struct zpool_rewind_policy {
414 	uint32_t	zrp_request;	/* rewind behavior requested */
415 	uint64_t	zrp_maxmeta;	/* max acceptable meta-data errors */
416 	uint64_t	zrp_maxdata;	/* max acceptable data errors */
417 	uint64_t	zrp_txg;	/* specific txg to load */
418 } zpool_rewind_policy_t;
419 
420 /*
421  * The following are configuration names used in the nvlist describing a pool's
422  * configuration.
423  */
424 #define	ZPOOL_CONFIG_VERSION		"version"
425 #define	ZPOOL_CONFIG_POOL_NAME		"name"
426 #define	ZPOOL_CONFIG_POOL_STATE		"state"
427 #define	ZPOOL_CONFIG_POOL_TXG		"txg"
428 #define	ZPOOL_CONFIG_POOL_GUID		"pool_guid"
429 #define	ZPOOL_CONFIG_CREATE_TXG		"create_txg"
430 #define	ZPOOL_CONFIG_TOP_GUID		"top_guid"
431 #define	ZPOOL_CONFIG_VDEV_TREE		"vdev_tree"
432 #define	ZPOOL_CONFIG_TYPE		"type"
433 #define	ZPOOL_CONFIG_CHILDREN		"children"
434 #define	ZPOOL_CONFIG_ID			"id"
435 #define	ZPOOL_CONFIG_GUID		"guid"
436 #define	ZPOOL_CONFIG_PATH		"path"
437 #define	ZPOOL_CONFIG_DEVID		"devid"
438 #define	ZPOOL_CONFIG_METASLAB_ARRAY	"metaslab_array"
439 #define	ZPOOL_CONFIG_METASLAB_SHIFT	"metaslab_shift"
440 #define	ZPOOL_CONFIG_ASHIFT		"ashift"
441 #define	ZPOOL_CONFIG_ASIZE		"asize"
442 #define	ZPOOL_CONFIG_DTL		"DTL"
443 #define	ZPOOL_CONFIG_STATS		"stats"
444 #define	ZPOOL_CONFIG_WHOLE_DISK		"whole_disk"
445 #define	ZPOOL_CONFIG_ERRCOUNT		"error_count"
446 #define	ZPOOL_CONFIG_NOT_PRESENT	"not_present"
447 #define	ZPOOL_CONFIG_SPARES		"spares"
448 #define	ZPOOL_CONFIG_IS_SPARE		"is_spare"
449 #define	ZPOOL_CONFIG_NPARITY		"nparity"
450 #define	ZPOOL_CONFIG_HOSTID		"hostid"
451 #define	ZPOOL_CONFIG_HOSTNAME		"hostname"
452 #define	ZPOOL_CONFIG_UNSPARE		"unspare"
453 #define	ZPOOL_CONFIG_PHYS_PATH		"phys_path"
454 #define	ZPOOL_CONFIG_IS_LOG		"is_log"
455 #define	ZPOOL_CONFIG_L2CACHE		"l2cache"
456 #define	ZPOOL_CONFIG_HOLE_ARRAY		"hole_array"
457 #define	ZPOOL_CONFIG_VDEV_CHILDREN	"vdev_children"
458 #define	ZPOOL_CONFIG_IS_HOLE		"is_hole"
459 #define	ZPOOL_CONFIG_DDT_HISTOGRAM	"ddt_histogram"
460 #define	ZPOOL_CONFIG_DDT_OBJ_STATS	"ddt_object_stats"
461 #define	ZPOOL_CONFIG_DDT_STATS		"ddt_stats"
462 #define	ZPOOL_CONFIG_SPLIT		"splitcfg"
463 #define	ZPOOL_CONFIG_ORIG_GUID		"orig_guid"
464 #define	ZPOOL_CONFIG_SPLIT_GUID		"split_guid"
465 #define	ZPOOL_CONFIG_SPLIT_LIST		"guid_list"
466 #define	ZPOOL_CONFIG_SUSPENDED		"suspended"	/* not stored on disk */
467 #define	ZPOOL_CONFIG_TIMESTAMP		"timestamp"	/* not stored on disk */
468 #define	ZPOOL_CONFIG_BOOTFS		"bootfs"	/* not stored on disk */
469 /*
470  * The persistent vdev state is stored as separate values rather than a single
471  * 'vdev_state' entry.  This is because a device can be in multiple states, such
472  * as offline and degraded.
473  */
474 #define	ZPOOL_CONFIG_OFFLINE		"offline"
475 #define	ZPOOL_CONFIG_FAULTED		"faulted"
476 #define	ZPOOL_CONFIG_DEGRADED		"degraded"
477 #define	ZPOOL_CONFIG_REMOVED		"removed"
478 #define	ZPOOL_CONFIG_FRU		"fru"
479 #define	ZPOOL_CONFIG_AUX_STATE		"aux_state"
480 
481 /* Rewind policy parameters */
482 #define	ZPOOL_REWIND_POLICY		"rewind-policy"
483 #define	ZPOOL_REWIND_REQUEST		"rewind-request"
484 #define	ZPOOL_REWIND_REQUEST_TXG	"rewind-request-txg"
485 #define	ZPOOL_REWIND_META_THRESH	"rewind-meta-thresh"
486 #define	ZPOOL_REWIND_DATA_THRESH	"rewind-data-thresh"
487 
488 /* Rewind data discovered */
489 #define	ZPOOL_CONFIG_LOAD_TIME		"rewind_txg_ts"
490 #define	ZPOOL_CONFIG_LOAD_DATA_ERRORS	"verify_data_errors"
491 #define	ZPOOL_CONFIG_REWIND_TIME	"seconds_of_rewind"
492 
493 #define	VDEV_TYPE_ROOT			"root"
494 #define	VDEV_TYPE_MIRROR		"mirror"
495 #define	VDEV_TYPE_REPLACING		"replacing"
496 #define	VDEV_TYPE_RAIDZ			"raidz"
497 #define	VDEV_TYPE_DISK			"disk"
498 #define	VDEV_TYPE_FILE			"file"
499 #define	VDEV_TYPE_MISSING		"missing"
500 #define	VDEV_TYPE_HOLE			"hole"
501 #define	VDEV_TYPE_SPARE			"spare"
502 #define	VDEV_TYPE_LOG			"log"
503 #define	VDEV_TYPE_L2CACHE		"l2cache"
504 
505 /*
506  * This is needed in userland to report the minimum necessary device size.
507  */
508 #define	SPA_MINDEVSIZE		(64ULL << 20)
509 
510 /*
511  * The location of the pool configuration repository, shared between kernel and
512  * userland.
513  */
514 #define	ZPOOL_CACHE		"/etc/zfs/zpool.cache"
515 
516 /*
517  * vdev states are ordered from least to most healthy.
518  * A vdev that's CANT_OPEN or below is considered unusable.
519  */
520 typedef enum vdev_state {
521 	VDEV_STATE_UNKNOWN = 0,	/* Uninitialized vdev			*/
522 	VDEV_STATE_CLOSED,	/* Not currently open			*/
523 	VDEV_STATE_OFFLINE,	/* Not allowed to open			*/
524 	VDEV_STATE_REMOVED,	/* Explicitly removed from system	*/
525 	VDEV_STATE_CANT_OPEN,	/* Tried to open, but failed		*/
526 	VDEV_STATE_FAULTED,	/* External request to fault device	*/
527 	VDEV_STATE_DEGRADED,	/* Replicated vdev with unhealthy kids	*/
528 	VDEV_STATE_HEALTHY	/* Presumed good			*/
529 } vdev_state_t;
530 
531 #define	VDEV_STATE_ONLINE	VDEV_STATE_HEALTHY
532 
533 /*
534  * vdev aux states.  When a vdev is in the CANT_OPEN state, the aux field
535  * of the vdev stats structure uses these constants to distinguish why.
536  */
537 typedef enum vdev_aux {
538 	VDEV_AUX_NONE,		/* no error				*/
539 	VDEV_AUX_OPEN_FAILED,	/* ldi_open_*() or vn_open() failed	*/
540 	VDEV_AUX_CORRUPT_DATA,	/* bad label or disk contents		*/
541 	VDEV_AUX_NO_REPLICAS,	/* insufficient number of replicas	*/
542 	VDEV_AUX_BAD_GUID_SUM,	/* vdev guid sum doesn't match		*/
543 	VDEV_AUX_TOO_SMALL,	/* vdev size is too small		*/
544 	VDEV_AUX_BAD_LABEL,	/* the label is OK but invalid		*/
545 	VDEV_AUX_VERSION_NEWER,	/* on-disk version is too new		*/
546 	VDEV_AUX_VERSION_OLDER,	/* on-disk version is too old		*/
547 	VDEV_AUX_SPARED,	/* hot spare used in another pool	*/
548 	VDEV_AUX_ERR_EXCEEDED,	/* too many errors			*/
549 	VDEV_AUX_IO_FAILURE,	/* experienced I/O failure		*/
550 	VDEV_AUX_BAD_LOG,	/* cannot read log chain(s)		*/
551 	VDEV_AUX_EXTERNAL,	/* external diagnosis			*/
552 	VDEV_AUX_SPLIT_POOL	/* vdev was split off into another pool	*/
553 } vdev_aux_t;
554 
555 /*
556  * pool state.  The following states are written to disk as part of the normal
557  * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE.  The remaining
558  * states are software abstractions used at various levels to communicate
559  * pool state.
560  */
561 typedef enum pool_state {
562 	POOL_STATE_ACTIVE = 0,		/* In active use		*/
563 	POOL_STATE_EXPORTED,		/* Explicitly exported		*/
564 	POOL_STATE_DESTROYED,		/* Explicitly destroyed		*/
565 	POOL_STATE_SPARE,		/* Reserved for hot spare use	*/
566 	POOL_STATE_L2CACHE,		/* Level 2 ARC device		*/
567 	POOL_STATE_UNINITIALIZED,	/* Internal spa_t state		*/
568 	POOL_STATE_UNAVAIL,		/* Internal libzfs state	*/
569 	POOL_STATE_POTENTIALLY_ACTIVE	/* Internal libzfs state	*/
570 } pool_state_t;
571 
572 /*
573  * Scrub types.
574  */
575 typedef enum pool_scrub_type {
576 	POOL_SCRUB_NONE,
577 	POOL_SCRUB_RESILVER,
578 	POOL_SCRUB_EVERYTHING,
579 	POOL_SCRUB_TYPES
580 } pool_scrub_type_t;
581 
582 /*
583  * ZIO types.  Needed to interpret vdev statistics below.
584  */
585 typedef enum zio_type {
586 	ZIO_TYPE_NULL = 0,
587 	ZIO_TYPE_READ,
588 	ZIO_TYPE_WRITE,
589 	ZIO_TYPE_FREE,
590 	ZIO_TYPE_CLAIM,
591 	ZIO_TYPE_IOCTL,
592 	ZIO_TYPES
593 } zio_type_t;
594 
595 /*
596  * Vdev statistics.  Note: all fields should be 64-bit because this
597  * is passed between kernel and userland as an nvlist uint64 array.
598  */
599 typedef struct vdev_stat {
600 	hrtime_t	vs_timestamp;		/* time since vdev load	*/
601 	uint64_t	vs_state;		/* vdev state		*/
602 	uint64_t	vs_aux;			/* see vdev_aux_t	*/
603 	uint64_t	vs_alloc;		/* space allocated	*/
604 	uint64_t	vs_space;		/* total capacity	*/
605 	uint64_t	vs_dspace;		/* deflated capacity	*/
606 	uint64_t	vs_rsize;		/* replaceable dev size */
607 	uint64_t	vs_ops[ZIO_TYPES];	/* operation count	*/
608 	uint64_t	vs_bytes[ZIO_TYPES];	/* bytes read/written	*/
609 	uint64_t	vs_read_errors;		/* read errors		*/
610 	uint64_t	vs_write_errors;	/* write errors		*/
611 	uint64_t	vs_checksum_errors;	/* checksum errors	*/
612 	uint64_t	vs_self_healed;		/* self-healed bytes	*/
613 	uint64_t	vs_scrub_type;		/* pool_scrub_type_t	*/
614 	uint64_t	vs_scrub_complete;	/* completed?		*/
615 	uint64_t	vs_scrub_examined;	/* bytes examined; top	*/
616 	uint64_t	vs_scrub_repaired;	/* bytes repaired; leaf	*/
617 	uint64_t	vs_scrub_errors;	/* errors during scrub	*/
618 	uint64_t	vs_scrub_start;		/* UTC scrub start time	*/
619 	uint64_t	vs_scrub_end;		/* UTC scrub end time	*/
620 } vdev_stat_t;
621 
622 /*
623  * DDT statistics.  Note: all fields should be 64-bit because this
624  * is passed between kernel and userland as an nvlist uint64 array.
625  */
626 typedef struct ddt_object {
627 	uint64_t	ddo_count;	/* number of elments in ddt 	*/
628 	uint64_t	ddo_dspace;	/* size of ddt on disk		*/
629 	uint64_t	ddo_mspace;	/* size of ddt in-core		*/
630 } ddt_object_t;
631 
632 typedef struct ddt_stat {
633 	uint64_t	dds_blocks;	/* blocks			*/
634 	uint64_t	dds_lsize;	/* logical size			*/
635 	uint64_t	dds_psize;	/* physical size		*/
636 	uint64_t	dds_dsize;	/* deflated allocated size	*/
637 	uint64_t	dds_ref_blocks;	/* referenced blocks		*/
638 	uint64_t	dds_ref_lsize;	/* referenced lsize * refcnt	*/
639 	uint64_t	dds_ref_psize;	/* referenced psize * refcnt	*/
640 	uint64_t	dds_ref_dsize;	/* referenced dsize * refcnt	*/
641 } ddt_stat_t;
642 
643 typedef struct ddt_histogram {
644 	ddt_stat_t	ddh_stat[64];	/* power-of-two histogram buckets */
645 } ddt_histogram_t;
646 
647 #define	ZVOL_DRIVER	"zvol"
648 #define	ZFS_DRIVER	"zfs"
649 #define	ZFS_DEV		"/dev/zfs"
650 
651 /* general zvol path */
652 #define	ZVOL_DIR		"/dev/zvol"
653 /* expansion */
654 #define	ZVOL_PSEUDO_DEV		"/devices/pseudo/zfs@0:"
655 /* for dump and swap */
656 #define	ZVOL_FULL_DEV_DIR	ZVOL_DIR "/dsk/"
657 #define	ZVOL_FULL_RDEV_DIR	ZVOL_DIR "/rdsk/"
658 
659 #define	ZVOL_PROP_NAME		"name"
660 #define	ZVOL_DEFAULT_BLOCKSIZE	8192
661 
662 /*
663  * /dev/zfs ioctl numbers.
664  */
665 #define	ZFS_IOC		('Z' << 8)
666 
667 typedef enum zfs_ioc {
668 	ZFS_IOC_POOL_CREATE = ZFS_IOC,
669 	ZFS_IOC_POOL_DESTROY,
670 	ZFS_IOC_POOL_IMPORT,
671 	ZFS_IOC_POOL_EXPORT,
672 	ZFS_IOC_POOL_CONFIGS,
673 	ZFS_IOC_POOL_STATS,
674 	ZFS_IOC_POOL_TRYIMPORT,
675 	ZFS_IOC_POOL_SCRUB,
676 	ZFS_IOC_POOL_FREEZE,
677 	ZFS_IOC_POOL_UPGRADE,
678 	ZFS_IOC_POOL_GET_HISTORY,
679 	ZFS_IOC_VDEV_ADD,
680 	ZFS_IOC_VDEV_REMOVE,
681 	ZFS_IOC_VDEV_SET_STATE,
682 	ZFS_IOC_VDEV_ATTACH,
683 	ZFS_IOC_VDEV_DETACH,
684 	ZFS_IOC_VDEV_SETPATH,
685 	ZFS_IOC_VDEV_SETFRU,
686 	ZFS_IOC_OBJSET_STATS,
687 	ZFS_IOC_OBJSET_ZPLPROPS,
688 	ZFS_IOC_DATASET_LIST_NEXT,
689 	ZFS_IOC_SNAPSHOT_LIST_NEXT,
690 	ZFS_IOC_SET_PROP,
691 	ZFS_IOC_CREATE,
692 	ZFS_IOC_DESTROY,
693 	ZFS_IOC_ROLLBACK,
694 	ZFS_IOC_RENAME,
695 	ZFS_IOC_RECV,
696 	ZFS_IOC_SEND,
697 	ZFS_IOC_INJECT_FAULT,
698 	ZFS_IOC_CLEAR_FAULT,
699 	ZFS_IOC_INJECT_LIST_NEXT,
700 	ZFS_IOC_ERROR_LOG,
701 	ZFS_IOC_CLEAR,
702 	ZFS_IOC_PROMOTE,
703 	ZFS_IOC_DESTROY_SNAPS,
704 	ZFS_IOC_SNAPSHOT,
705 	ZFS_IOC_DSOBJ_TO_DSNAME,
706 	ZFS_IOC_OBJ_TO_PATH,
707 	ZFS_IOC_POOL_SET_PROPS,
708 	ZFS_IOC_POOL_GET_PROPS,
709 	ZFS_IOC_SET_FSACL,
710 	ZFS_IOC_GET_FSACL,
711 	ZFS_IOC_ISCSI_PERM_CHECK,
712 	ZFS_IOC_SHARE,
713 	ZFS_IOC_INHERIT_PROP,
714 	ZFS_IOC_SMB_ACL,
715 	ZFS_IOC_USERSPACE_ONE,
716 	ZFS_IOC_USERSPACE_MANY,
717 	ZFS_IOC_USERSPACE_UPGRADE,
718 	ZFS_IOC_HOLD,
719 	ZFS_IOC_RELEASE,
720 	ZFS_IOC_GET_HOLDS,
721 	ZFS_IOC_OBJSET_RECVD_PROPS,
722 	ZFS_IOC_VDEV_SPLIT
723 } zfs_ioc_t;
724 
725 /*
726  * Internal SPA load state.  Used by FMA diagnosis engine.
727  */
728 typedef enum {
729 	SPA_LOAD_NONE,		/* no load in progress	*/
730 	SPA_LOAD_OPEN,		/* normal open		*/
731 	SPA_LOAD_IMPORT,	/* import in progress	*/
732 	SPA_LOAD_TRYIMPORT,	/* tryimport in progress */
733 	SPA_LOAD_RECOVER,	/* recovery requested	*/
734 	SPA_LOAD_ERROR		/* load failed		*/
735 } spa_load_state_t;
736 
737 /*
738  * Bookmark name values.
739  */
740 #define	ZPOOL_ERR_LIST		"error list"
741 #define	ZPOOL_ERR_DATASET	"dataset"
742 #define	ZPOOL_ERR_OBJECT	"object"
743 
744 #define	HIS_MAX_RECORD_LEN	(MAXPATHLEN + MAXPATHLEN + 1)
745 
746 /*
747  * The following are names used in the nvlist describing
748  * the pool's history log.
749  */
750 #define	ZPOOL_HIST_RECORD	"history record"
751 #define	ZPOOL_HIST_TIME		"history time"
752 #define	ZPOOL_HIST_CMD		"history command"
753 #define	ZPOOL_HIST_WHO		"history who"
754 #define	ZPOOL_HIST_ZONE		"history zone"
755 #define	ZPOOL_HIST_HOST		"history hostname"
756 #define	ZPOOL_HIST_TXG		"history txg"
757 #define	ZPOOL_HIST_INT_EVENT	"history internal event"
758 #define	ZPOOL_HIST_INT_STR	"history internal str"
759 
760 /*
761  * Flags for ZFS_IOC_VDEV_SET_STATE
762  */
763 #define	ZFS_ONLINE_CHECKREMOVE	0x1
764 #define	ZFS_ONLINE_UNSPARE	0x2
765 #define	ZFS_ONLINE_FORCEFAULT	0x4
766 #define	ZFS_ONLINE_EXPAND	0x8
767 #define	ZFS_OFFLINE_TEMPORARY	0x1
768 
769 /*
770  * Sysevent payload members.  ZFS will generate the following sysevents with the
771  * given payloads:
772  *
773  *	ESC_ZFS_RESILVER_START
774  *	ESC_ZFS_RESILVER_END
775  *	ESC_ZFS_POOL_DESTROY
776  *
777  *		ZFS_EV_POOL_NAME	DATA_TYPE_STRING
778  *		ZFS_EV_POOL_GUID	DATA_TYPE_UINT64
779  *
780  *	ESC_ZFS_VDEV_REMOVE
781  *	ESC_ZFS_VDEV_CLEAR
782  *	ESC_ZFS_VDEV_CHECK
783  *
784  *		ZFS_EV_POOL_NAME	DATA_TYPE_STRING
785  *		ZFS_EV_POOL_GUID	DATA_TYPE_UINT64
786  *		ZFS_EV_VDEV_PATH	DATA_TYPE_STRING	(optional)
787  *		ZFS_EV_VDEV_GUID	DATA_TYPE_UINT64
788  */
789 #define	ZFS_EV_POOL_NAME	"pool_name"
790 #define	ZFS_EV_POOL_GUID	"pool_guid"
791 #define	ZFS_EV_VDEV_PATH	"vdev_path"
792 #define	ZFS_EV_VDEV_GUID	"vdev_guid"
793 
794 /*
795  * Note: This is encoded on-disk, so new events must be added to the
796  * end, and unused events can not be removed.  Be sure to edit
797  * libzfs_pool.c: hist_event_table[].
798  */
799 typedef enum history_internal_events {
800 	LOG_NO_EVENT = 0,
801 	LOG_POOL_CREATE,
802 	LOG_POOL_VDEV_ADD,
803 	LOG_POOL_REMOVE,
804 	LOG_POOL_DESTROY,
805 	LOG_POOL_EXPORT,
806 	LOG_POOL_IMPORT,
807 	LOG_POOL_VDEV_ATTACH,
808 	LOG_POOL_VDEV_REPLACE,
809 	LOG_POOL_VDEV_DETACH,
810 	LOG_POOL_VDEV_ONLINE,
811 	LOG_POOL_VDEV_OFFLINE,
812 	LOG_POOL_UPGRADE,
813 	LOG_POOL_CLEAR,
814 	LOG_POOL_SCRUB,
815 	LOG_POOL_PROPSET,
816 	LOG_DS_CREATE,
817 	LOG_DS_CLONE,
818 	LOG_DS_DESTROY,
819 	LOG_DS_DESTROY_BEGIN,
820 	LOG_DS_INHERIT,
821 	LOG_DS_PROPSET,
822 	LOG_DS_QUOTA,
823 	LOG_DS_PERM_UPDATE,
824 	LOG_DS_PERM_REMOVE,
825 	LOG_DS_PERM_WHO_REMOVE,
826 	LOG_DS_PROMOTE,
827 	LOG_DS_RECEIVE,
828 	LOG_DS_RENAME,
829 	LOG_DS_RESERVATION,
830 	LOG_DS_REPLAY_INC_SYNC,
831 	LOG_DS_REPLAY_FULL_SYNC,
832 	LOG_DS_ROLLBACK,
833 	LOG_DS_SNAPSHOT,
834 	LOG_DS_UPGRADE,
835 	LOG_DS_REFQUOTA,
836 	LOG_DS_REFRESERV,
837 	LOG_POOL_SCRUB_DONE,
838 	LOG_DS_USER_HOLD,
839 	LOG_DS_USER_RELEASE,
840 	LOG_POOL_SPLIT,
841 	LOG_END
842 } history_internal_events_t;
843 
844 #ifdef	__cplusplus
845 }
846 #endif
847 
848 #endif	/* _SYS_FS_ZFS_H */
849