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