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