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