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