xref: /titanic_51/usr/src/uts/common/sys/fs/zfs.h (revision fb9f9b975cb9214fec5dab37d461199adab9b964)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_FS_ZFS_H
28 #define	_SYS_FS_ZFS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Types and constants shared between userland and the kernel.
40  */
41 
42 /*
43  * Each dataset can be one of the following types.  These constants can be
44  * combined into masks that can be passed to various functions.
45  */
46 typedef enum {
47 	ZFS_TYPE_FILESYSTEM	= 0x1,
48 	ZFS_TYPE_SNAPSHOT	= 0x2,
49 	ZFS_TYPE_VOLUME		= 0x4
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.  They are arranged in order of
57  * how they should be displayed by 'zfs get'.  If you make any changes to this
58  * list, be sure to update the property table in usr/src/common/zfs/zfs_prop.c.
59  */
60 typedef enum {
61 	ZFS_PROP_INVAL = -1,
62 	ZFS_PROP_TYPE,
63 	ZFS_PROP_CREATION,
64 	ZFS_PROP_USED,
65 	ZFS_PROP_AVAILABLE,
66 	ZFS_PROP_REFERENCED,
67 	ZFS_PROP_COMPRESSRATIO,
68 	ZFS_PROP_MOUNTED,
69 	ZFS_PROP_ORIGIN,
70 	ZFS_PROP_QUOTA,
71 	ZFS_PROP_RESERVATION,
72 	ZFS_PROP_VOLSIZE,
73 	ZFS_PROP_VOLBLOCKSIZE,
74 	ZFS_PROP_RECORDSIZE,
75 	ZFS_PROP_MOUNTPOINT,
76 	ZFS_PROP_SHARENFS,
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 	/*
89 	 * The following properties are not exposed to the user, but are
90 	 * accessible by libzfs clients.
91 	 */
92 	ZFS_PROP_CREATETXG,
93 	ZFS_PROP_NAME,
94 	ZFS_NPROP_ALL
95 } zfs_prop_t;
96 
97 #define	ZFS_NPROP_VISIBLE	ZFS_PROP_CREATETXG
98 
99 /*
100  * The following functions are shared between libzfs and the kernel.
101  */
102 zfs_prop_t zfs_name_to_prop(const char *);
103 int zfs_prop_readonly(zfs_prop_t);
104 void zfs_prop_default_string(zfs_prop_t, char *, size_t);
105 uint64_t zfs_prop_default_numeric(zfs_prop_t);
106 
107 /*
108  * The following are configuration names used in the nvlist describing a pool's
109  * configuration.
110  */
111 #define	ZPOOL_CONFIG_VERSION		"version"
112 #define	ZPOOL_CONFIG_POOL_NAME		"name"
113 #define	ZPOOL_CONFIG_POOL_STATE		"state"
114 #define	ZPOOL_CONFIG_POOL_TXG		"txg"
115 #define	ZPOOL_CONFIG_POOL_GUID		"pool_guid"
116 #define	ZPOOL_CONFIG_CREATE_TXG		"create_txg"
117 #define	ZPOOL_CONFIG_TOP_GUID		"top_guid"
118 #define	ZPOOL_CONFIG_POOL_HEALTH	"pool_health"
119 #define	ZPOOL_CONFIG_VDEV_TREE		"vdev_tree"
120 #define	ZPOOL_CONFIG_TYPE		"type"
121 #define	ZPOOL_CONFIG_CHILDREN		"children"
122 #define	ZPOOL_CONFIG_ID			"id"
123 #define	ZPOOL_CONFIG_GUID		"guid"
124 #define	ZPOOL_CONFIG_PATH		"path"
125 #define	ZPOOL_CONFIG_DEVID		"devid"
126 #define	ZPOOL_CONFIG_METASLAB_ARRAY	"metaslab_array"
127 #define	ZPOOL_CONFIG_METASLAB_SHIFT	"metaslab_shift"
128 #define	ZPOOL_CONFIG_ASHIFT		"ashift"
129 #define	ZPOOL_CONFIG_ASIZE		"asize"
130 #define	ZPOOL_CONFIG_DTL		"DTL"
131 #define	ZPOOL_CONFIG_STATS		"stats"
132 
133 #define	VDEV_TYPE_ROOT			"root"
134 #define	VDEV_TYPE_MIRROR		"mirror"
135 #define	VDEV_TYPE_REPLACING		"replacing"
136 #define	VDEV_TYPE_RAIDZ			"raidz"
137 #define	VDEV_TYPE_DISK			"disk"
138 #define	VDEV_TYPE_FILE			"file"
139 #define	VDEV_TYPE_MISSING		"missing"
140 
141 /*
142  * This is needed in userland to report the minimum necessary device size.
143  */
144 #define	SPA_MINDEVSIZE		(64ULL << 20)
145 
146 /*
147  * The location of the pool configuration repository, shared between kernel and
148  * userland.
149  */
150 #define	ZPOOL_CACHE_DIR		"/etc/zfs"
151 #define	ZPOOL_CACHE_FILE	"zpool.cache"
152 #define	ZPOOL_CACHE_TMP		".zpool.cache"
153 
154 #define	ZPOOL_CACHE		ZPOOL_CACHE_DIR "/" ZPOOL_CACHE_FILE
155 
156 /*
157  * vdev states are ordered from least to most healthy.
158  * A vdev that's CANT_OPEN or below is considered unusable.
159  */
160 typedef enum vdev_state {
161 	VDEV_STATE_UNKNOWN = 0,	/* Uninitialized vdev			*/
162 	VDEV_STATE_CLOSED,	/* Not currently open			*/
163 	VDEV_STATE_OFFLINE,	/* Not allowed to open			*/
164 	VDEV_STATE_CANT_OPEN,	/* Tried to open, but failed		*/
165 	VDEV_STATE_DEGRADED,	/* Replicated vdev with unhealthy kids	*/
166 	VDEV_STATE_HEALTHY	/* Presumed good			*/
167 } vdev_state_t;
168 
169 /*
170  * vdev aux states.  When a vdev is in the CANT_OPEN state, the aux field
171  * of the vdev stats structure uses these constants to distinguish why.
172  */
173 typedef enum vdev_aux {
174 	VDEV_AUX_NONE,		/* no error				*/
175 	VDEV_AUX_OPEN_FAILED,	/* ldi_open_*() or vn_open() failed	*/
176 	VDEV_AUX_CORRUPT_DATA,	/* bad label or disk contents		*/
177 	VDEV_AUX_NO_REPLICAS,	/* insufficient number of replicas	*/
178 	VDEV_AUX_BAD_GUID_SUM,	/* vdev guid sum doesn't match		*/
179 	VDEV_AUX_TOO_SMALL,	/* vdev size is too small		*/
180 	VDEV_AUX_BAD_LABEL	/* the label is OK but invalid		*/
181 } vdev_aux_t;
182 
183 /*
184  * pool state.  The following states are actually written to disk as part of the
185  * normal SPA lifecycle: ACTIVE, EXPORTED, DESTROYED.  The remaining states
186  * (UNITIALIZED, UNAVAIL) are software abstractions used at various levels to
187  * communicate pool state.
188  */
189 typedef enum pool_state {
190 	POOL_STATE_ACTIVE = 0,		/* In active use		*/
191 	POOL_STATE_EXPORTED,		/* Explicitly exported		*/
192 	POOL_STATE_DESTROYED,		/* Explicitly destroyed		*/
193 	POOL_STATE_UNINITIALIZED,	/* Internal spa_t state		*/
194 	POOL_STATE_UNAVAIL		/* Internal libzfs state	*/
195 } pool_state_t;
196 
197 /*
198  * Scrub types.
199  */
200 typedef enum pool_scrub_type {
201 	POOL_SCRUB_NONE,
202 	POOL_SCRUB_RESILVER,
203 	POOL_SCRUB_EVERYTHING,
204 	POOL_SCRUB_TYPES
205 } pool_scrub_type_t;
206 
207 /*
208  * ZIO types.  Needed to interpret vdev statistics below.
209  */
210 typedef enum zio_type {
211 	ZIO_TYPE_NULL = 0,
212 	ZIO_TYPE_READ,
213 	ZIO_TYPE_WRITE,
214 	ZIO_TYPE_FREE,
215 	ZIO_TYPE_CLAIM,
216 	ZIO_TYPE_IOCTL,
217 	ZIO_TYPES
218 } zio_type_t;
219 
220 /*
221  * Vdev statistics.  Note: all fields should be 64-bit because this
222  * is passed between kernel and userland as an nvlist uint64 array.
223  */
224 typedef struct vdev_stat {
225 	hrtime_t	vs_timestamp;		/* time since vdev load	*/
226 	uint64_t	vs_state;		/* vdev state		*/
227 	uint64_t	vs_aux;			/* see vdev_aux_t	*/
228 	uint64_t	vs_alloc;		/* space allocated	*/
229 	uint64_t	vs_space;		/* total capacity	*/
230 	uint64_t	vs_ops[ZIO_TYPES];	/* operation count	*/
231 	uint64_t	vs_bytes[ZIO_TYPES];	/* bytes read/written	*/
232 	uint64_t	vs_read_errors;		/* read errors		*/
233 	uint64_t	vs_write_errors;	/* write errors		*/
234 	uint64_t	vs_checksum_errors;	/* checksum errors	*/
235 	uint64_t	vs_self_healed;		/* self-healed bytes	*/
236 	uint64_t	vs_scrub_type;		/* pool_scrub_type_t	*/
237 	uint64_t	vs_scrub_complete;	/* completed?		*/
238 	uint64_t	vs_scrub_examined;	/* bytes examined; top	*/
239 	uint64_t	vs_scrub_repaired;	/* bytes repaired; leaf	*/
240 	uint64_t	vs_scrub_errors;	/* errors during scrub	*/
241 	uint64_t	vs_scrub_start;		/* UTC scrub start time	*/
242 	uint64_t	vs_scrub_end;		/* UTC scrub end time	*/
243 } vdev_stat_t;
244 
245 #define	ZFS_DRIVER	"zfs"
246 #define	ZFS_DEV		"/dev/zfs"
247 
248 /*
249  * zvol paths.  Irritatingly, the devfsadm interfaces want all these
250  * paths without the /dev prefix, but for some things, we want the
251  * /dev prefix.  Below are the names without /dev.
252  */
253 #define	ZVOL_DEV_DIR	"zvol/dsk"
254 #define	ZVOL_RDEV_DIR	"zvol/rdsk"
255 
256 /*
257  * And here are the things we need with /dev, etc. in front of them.
258  */
259 #define	ZVOL_PSEUDO_DEV		"/devices/pseudo/zvol@0:"
260 #define	ZVOL_FULL_DEV_DIR	"/dev/" ZVOL_DEV_DIR
261 
262 #define	ZVOL_PROP_NAME		"name"
263 
264 /*
265  * /dev/zfs ioctl numbers.
266  */
267 #define	ZFS_IOC		('Z' << 8)
268 
269 typedef enum zfs_ioc {
270 	ZFS_IOC_POOL_CREATE = ZFS_IOC,
271 	ZFS_IOC_POOL_DESTROY,
272 	ZFS_IOC_POOL_IMPORT,
273 	ZFS_IOC_POOL_EXPORT,
274 	ZFS_IOC_POOL_CONFIGS,
275 	ZFS_IOC_POOL_GUID,
276 	ZFS_IOC_POOL_STATS,
277 	ZFS_IOC_POOL_TRYIMPORT,
278 	ZFS_IOC_POOL_SCRUB,
279 	ZFS_IOC_POOL_FREEZE,
280 	ZFS_IOC_VDEV_ADD,
281 	ZFS_IOC_VDEV_REMOVE,
282 	ZFS_IOC_VDEV_ONLINE,
283 	ZFS_IOC_VDEV_OFFLINE,
284 	ZFS_IOC_VDEV_ATTACH,
285 	ZFS_IOC_VDEV_DETACH,
286 	ZFS_IOC_OBJSET_STATS,
287 	ZFS_IOC_DATASET_LIST_NEXT,
288 	ZFS_IOC_SNAPSHOT_LIST_NEXT,
289 	ZFS_IOC_SET_PROP,
290 	ZFS_IOC_SET_QUOTA,
291 	ZFS_IOC_SET_RESERVATION,
292 	ZFS_IOC_SET_VOLSIZE,
293 	ZFS_IOC_SET_VOLBLOCKSIZE,
294 	ZFS_IOC_CREATE_MINOR,
295 	ZFS_IOC_REMOVE_MINOR,
296 	ZFS_IOC_CREATE,
297 	ZFS_IOC_DESTROY,
298 	ZFS_IOC_ROLLBACK,
299 	ZFS_IOC_RENAME,
300 	ZFS_IOC_RECVBACKUP,
301 	ZFS_IOC_SENDBACKUP
302 } zfs_ioc_t;
303 
304 #ifdef	__cplusplus
305 }
306 #endif
307 
308 #endif	/* _SYS_FS_ZFS_H */
309