xref: /titanic_51/usr/src/uts/common/sys/fs/zfs.h (revision a4ac8bb3f5b2fff60581bee101792ac7a34bad8c)
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  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_FS_ZFS_H
27 #define	_SYS_FS_ZFS_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.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_t;
50 
51 #define	ZFS_TYPE_ANY	\
52 	(ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME | ZFS_TYPE_SNAPSHOT)
53 
54 /*
55  * Properties are identified by these constants.  They are arranged in order of
56  * how they should be displayed by 'zfs get'.  If you make any changes to this
57  * list, be sure to update the property table in usr/src/common/zfs/zfs_prop.c.
58  */
59 typedef enum {
60 	ZFS_PROP_INVAL = -1,
61 	ZFS_PROP_TYPE,
62 	ZFS_PROP_CREATION,
63 	ZFS_PROP_USED,
64 	ZFS_PROP_AVAILABLE,
65 	ZFS_PROP_REFERENCED,
66 	ZFS_PROP_COMPRESSRATIO,
67 	ZFS_PROP_MOUNTED,
68 	ZFS_PROP_ORIGIN,
69 	ZFS_PROP_QUOTA,
70 	ZFS_PROP_RESERVATION,
71 	ZFS_PROP_VOLSIZE,
72 	ZFS_PROP_VOLBLOCKSIZE,
73 	ZFS_PROP_RECORDSIZE,
74 	ZFS_PROP_MOUNTPOINT,
75 	ZFS_PROP_SHARENFS,
76 	ZFS_PROP_CHECKSUM,
77 	ZFS_PROP_COMPRESSION,
78 	ZFS_PROP_ATIME,
79 	ZFS_PROP_DEVICES,
80 	ZFS_PROP_EXEC,
81 	ZFS_PROP_SETUID,
82 	ZFS_PROP_READONLY,
83 	ZFS_PROP_ZONED,
84 	ZFS_PROP_SNAPDIR,
85 	ZFS_PROP_ACLMODE,
86 	ZFS_PROP_ACLINHERIT,
87 	/*
88 	 * The following properties are not exposed to the user, but are
89 	 * accessible by libzfs clients.
90 	 */
91 	ZFS_PROP_CREATETXG,
92 	ZFS_PROP_NAME,
93 	ZFS_NPROP_ALL
94 } zfs_prop_t;
95 
96 #define	ZFS_NPROP_VISIBLE	ZFS_PROP_CREATETXG
97 
98 #define	ZFS_PROP_VALUE		"value"
99 #define	ZFS_PROP_SOURCE		"source"
100 
101 /*
102  * The following functions are shared between libzfs and the kernel.
103  */
104 zfs_prop_t zfs_name_to_prop(const char *);
105 int zfs_prop_readonly(zfs_prop_t);
106 const char *zfs_prop_default_string(zfs_prop_t);
107 uint64_t zfs_prop_default_numeric(zfs_prop_t);
108 
109 /*
110  * On-disk format version.
111  */
112 #define	ZFS_VERSION_1			1ULL
113 #define	ZFS_VERSION_2			2ULL
114 #define	ZFS_VERSION			ZFS_VERSION_2
115 
116 /*
117  * Symbolic names for the changes that caused a ZFS_VERSION switch.
118  * Used in the code when checking for presence or absence of a feature.
119  * Feel free to define multiple symbolic names for each version if there
120  * were multiple changes to on-disk structures during that version.
121  *
122  * NOTE: When checking the current ZFS_VERSION in your code, be sure
123  *       to use spa_version() since it reports the version of the
124  *       last synced uberblock.  Checking the in-flight version can
125  *       be dangerous in some cases.
126  */
127 #define	ZFS_VERSION_INITIAL		ZFS_VERSION_1
128 #define	ZFS_VERSION_DITTO_BLOCKS	ZFS_VERSION_2
129 
130 /*
131  * The following are configuration names used in the nvlist describing a pool's
132  * configuration.
133  */
134 #define	ZPOOL_CONFIG_VERSION		"version"
135 #define	ZPOOL_CONFIG_POOL_NAME		"name"
136 #define	ZPOOL_CONFIG_POOL_STATE		"state"
137 #define	ZPOOL_CONFIG_POOL_TXG		"txg"
138 #define	ZPOOL_CONFIG_POOL_GUID		"pool_guid"
139 #define	ZPOOL_CONFIG_CREATE_TXG		"create_txg"
140 #define	ZPOOL_CONFIG_TOP_GUID		"top_guid"
141 #define	ZPOOL_CONFIG_POOL_HEALTH	"pool_health"
142 #define	ZPOOL_CONFIG_VDEV_TREE		"vdev_tree"
143 #define	ZPOOL_CONFIG_TYPE		"type"
144 #define	ZPOOL_CONFIG_CHILDREN		"children"
145 #define	ZPOOL_CONFIG_ID			"id"
146 #define	ZPOOL_CONFIG_GUID		"guid"
147 #define	ZPOOL_CONFIG_PATH		"path"
148 #define	ZPOOL_CONFIG_DEVID		"devid"
149 #define	ZPOOL_CONFIG_METASLAB_ARRAY	"metaslab_array"
150 #define	ZPOOL_CONFIG_METASLAB_SHIFT	"metaslab_shift"
151 #define	ZPOOL_CONFIG_ASHIFT		"ashift"
152 #define	ZPOOL_CONFIG_ASIZE		"asize"
153 #define	ZPOOL_CONFIG_DTL		"DTL"
154 #define	ZPOOL_CONFIG_STATS		"stats"
155 #define	ZPOOL_CONFIG_WHOLE_DISK		"whole_disk"
156 #define	ZPOOL_CONFIG_OFFLINE		"offline"
157 #define	ZPOOL_CONFIG_ERRCOUNT		"error_count"
158 #define	ZPOOL_CONFIG_NOT_PRESENT	"not_present"
159 
160 #define	VDEV_TYPE_ROOT			"root"
161 #define	VDEV_TYPE_MIRROR		"mirror"
162 #define	VDEV_TYPE_REPLACING		"replacing"
163 #define	VDEV_TYPE_RAIDZ			"raidz"
164 #define	VDEV_TYPE_DISK			"disk"
165 #define	VDEV_TYPE_FILE			"file"
166 #define	VDEV_TYPE_MISSING		"missing"
167 
168 /*
169  * This is needed in userland to report the minimum necessary device size.
170  */
171 #define	SPA_MINDEVSIZE		(64ULL << 20)
172 
173 /*
174  * The location of the pool configuration repository, shared between kernel and
175  * userland.
176  */
177 #define	ZPOOL_CACHE_DIR		"/etc/zfs"
178 #define	ZPOOL_CACHE_FILE	"zpool.cache"
179 #define	ZPOOL_CACHE_TMP		".zpool.cache"
180 
181 #define	ZPOOL_CACHE		ZPOOL_CACHE_DIR "/" ZPOOL_CACHE_FILE
182 
183 /*
184  * vdev states are ordered from least to most healthy.
185  * A vdev that's CANT_OPEN or below is considered unusable.
186  */
187 typedef enum vdev_state {
188 	VDEV_STATE_UNKNOWN = 0,	/* Uninitialized vdev			*/
189 	VDEV_STATE_CLOSED,	/* Not currently open			*/
190 	VDEV_STATE_OFFLINE,	/* Not allowed to open			*/
191 	VDEV_STATE_CANT_OPEN,	/* Tried to open, but failed		*/
192 	VDEV_STATE_DEGRADED,	/* Replicated vdev with unhealthy kids	*/
193 	VDEV_STATE_HEALTHY	/* Presumed good			*/
194 } vdev_state_t;
195 
196 /*
197  * vdev aux states.  When a vdev is in the CANT_OPEN state, the aux field
198  * of the vdev stats structure uses these constants to distinguish why.
199  */
200 typedef enum vdev_aux {
201 	VDEV_AUX_NONE,		/* no error				*/
202 	VDEV_AUX_OPEN_FAILED,	/* ldi_open_*() or vn_open() failed	*/
203 	VDEV_AUX_CORRUPT_DATA,	/* bad label or disk contents		*/
204 	VDEV_AUX_NO_REPLICAS,	/* insufficient number of replicas	*/
205 	VDEV_AUX_BAD_GUID_SUM,	/* vdev guid sum doesn't match		*/
206 	VDEV_AUX_TOO_SMALL,	/* vdev size is too small		*/
207 	VDEV_AUX_BAD_LABEL,	/* the label is OK but invalid		*/
208 	VDEV_AUX_VERSION_NEWER,	/* on-disk version is too new		*/
209 	VDEV_AUX_VERSION_OLDER	/* on-disk version is too old		*/
210 } vdev_aux_t;
211 
212 /*
213  * pool state.  The following states are written to disk as part of the normal
214  * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED.  The remaining states are
215  * software abstractions used at various levels to communicate pool state.
216  */
217 typedef enum pool_state {
218 	POOL_STATE_ACTIVE = 0,		/* In active use		*/
219 	POOL_STATE_EXPORTED,		/* Explicitly exported		*/
220 	POOL_STATE_DESTROYED,		/* Explicitly destroyed		*/
221 	POOL_STATE_UNINITIALIZED,	/* Internal spa_t state		*/
222 	POOL_STATE_UNAVAIL,		/* Internal libzfs state	*/
223 	POOL_STATE_POTENTIALLY_ACTIVE	/* Internal libzfs state	*/
224 } pool_state_t;
225 
226 /*
227  * Scrub types.
228  */
229 typedef enum pool_scrub_type {
230 	POOL_SCRUB_NONE,
231 	POOL_SCRUB_RESILVER,
232 	POOL_SCRUB_EVERYTHING,
233 	POOL_SCRUB_TYPES
234 } pool_scrub_type_t;
235 
236 /*
237  * ZIO types.  Needed to interpret vdev statistics below.
238  */
239 typedef enum zio_type {
240 	ZIO_TYPE_NULL = 0,
241 	ZIO_TYPE_READ,
242 	ZIO_TYPE_WRITE,
243 	ZIO_TYPE_FREE,
244 	ZIO_TYPE_CLAIM,
245 	ZIO_TYPE_IOCTL,
246 	ZIO_TYPES
247 } zio_type_t;
248 
249 /*
250  * Vdev statistics.  Note: all fields should be 64-bit because this
251  * is passed between kernel and userland as an nvlist uint64 array.
252  */
253 typedef struct vdev_stat {
254 	hrtime_t	vs_timestamp;		/* time since vdev load	*/
255 	uint64_t	vs_state;		/* vdev state		*/
256 	uint64_t	vs_aux;			/* see vdev_aux_t	*/
257 	uint64_t	vs_alloc;		/* space allocated	*/
258 	uint64_t	vs_space;		/* total capacity	*/
259 	uint64_t	vs_rsize;		/* replaceable dev size */
260 	uint64_t	vs_ops[ZIO_TYPES];	/* operation count	*/
261 	uint64_t	vs_bytes[ZIO_TYPES];	/* bytes read/written	*/
262 	uint64_t	vs_read_errors;		/* read errors		*/
263 	uint64_t	vs_write_errors;	/* write errors		*/
264 	uint64_t	vs_checksum_errors;	/* checksum errors	*/
265 	uint64_t	vs_self_healed;		/* self-healed bytes	*/
266 	uint64_t	vs_scrub_type;		/* pool_scrub_type_t	*/
267 	uint64_t	vs_scrub_complete;	/* completed?		*/
268 	uint64_t	vs_scrub_examined;	/* bytes examined; top	*/
269 	uint64_t	vs_scrub_repaired;	/* bytes repaired; leaf	*/
270 	uint64_t	vs_scrub_errors;	/* errors during scrub	*/
271 	uint64_t	vs_scrub_start;		/* UTC scrub start time	*/
272 	uint64_t	vs_scrub_end;		/* UTC scrub end time	*/
273 } vdev_stat_t;
274 
275 #define	ZFS_DRIVER	"zfs"
276 #define	ZFS_DEV		"/dev/zfs"
277 
278 /*
279  * zvol paths.  Irritatingly, the devfsadm interfaces want all these
280  * paths without the /dev prefix, but for some things, we want the
281  * /dev prefix.  Below are the names without /dev.
282  */
283 #define	ZVOL_DEV_DIR	"zvol/dsk"
284 #define	ZVOL_RDEV_DIR	"zvol/rdsk"
285 
286 /*
287  * And here are the things we need with /dev, etc. in front of them.
288  */
289 #define	ZVOL_PSEUDO_DEV		"/devices/pseudo/zvol@0:"
290 #define	ZVOL_FULL_DEV_DIR	"/dev/" ZVOL_DEV_DIR
291 
292 #define	ZVOL_PROP_NAME		"name"
293 
294 /*
295  * /dev/zfs ioctl numbers.
296  */
297 #define	ZFS_IOC		('Z' << 8)
298 
299 typedef enum zfs_ioc {
300 	ZFS_IOC_POOL_CREATE = ZFS_IOC,
301 	ZFS_IOC_POOL_DESTROY,
302 	ZFS_IOC_POOL_IMPORT,
303 	ZFS_IOC_POOL_EXPORT,
304 	ZFS_IOC_POOL_CONFIGS,
305 	ZFS_IOC_POOL_STATS,
306 	ZFS_IOC_POOL_TRYIMPORT,
307 	ZFS_IOC_POOL_SCRUB,
308 	ZFS_IOC_POOL_FREEZE,
309 	ZFS_IOC_POOL_UPGRADE,
310 	ZFS_IOC_VDEV_ADD,
311 	ZFS_IOC_VDEV_REMOVE,
312 	ZFS_IOC_VDEV_ONLINE,
313 	ZFS_IOC_VDEV_OFFLINE,
314 	ZFS_IOC_VDEV_ATTACH,
315 	ZFS_IOC_VDEV_DETACH,
316 	ZFS_IOC_VDEV_SETPATH,
317 	ZFS_IOC_OBJSET_STATS,
318 	ZFS_IOC_DATASET_LIST_NEXT,
319 	ZFS_IOC_SNAPSHOT_LIST_NEXT,
320 	ZFS_IOC_SET_PROP,
321 	ZFS_IOC_SET_QUOTA,
322 	ZFS_IOC_SET_RESERVATION,
323 	ZFS_IOC_SET_VOLSIZE,
324 	ZFS_IOC_SET_VOLBLOCKSIZE,
325 	ZFS_IOC_CREATE_MINOR,
326 	ZFS_IOC_REMOVE_MINOR,
327 	ZFS_IOC_CREATE,
328 	ZFS_IOC_DESTROY,
329 	ZFS_IOC_ROLLBACK,
330 	ZFS_IOC_RENAME,
331 	ZFS_IOC_RECVBACKUP,
332 	ZFS_IOC_SENDBACKUP,
333 	ZFS_IOC_INJECT_FAULT,
334 	ZFS_IOC_CLEAR_FAULT,
335 	ZFS_IOC_INJECT_LIST_NEXT,
336 	ZFS_IOC_ERROR_LOG,
337 	ZFS_IOC_CLEAR,
338 	ZFS_IOC_BOOKMARK_NAME
339 } zfs_ioc_t;
340 
341 /*
342  * Internal SPA load state.  Used by FMA diagnosis engine.
343  */
344 typedef enum {
345 	SPA_LOAD_NONE,		/* no load in progress */
346 	SPA_LOAD_OPEN,		/* normal open */
347 	SPA_LOAD_IMPORT,	/* import in progress */
348 	SPA_LOAD_TRYIMPORT	/* tryimport in progress */
349 } spa_load_state_t;
350 
351 #ifdef	__cplusplus
352 }
353 #endif
354 
355 #endif	/* _SYS_FS_ZFS_H */
356