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