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