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.
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.
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]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
29 #pragma ident "@(#)zfs.h 1.44 08/04/09 SMI"
36 * Types and constants shared between userland and the kernel.
40 * Each dataset can be one of the following types. These constants can be
41 * combined into masks that can be passed to various functions.
44 ZFS_TYPE_FILESYSTEM = 0x1,
45 ZFS_TYPE_SNAPSHOT = 0x2,
46 ZFS_TYPE_VOLUME = 0x4,
50 #define ZFS_TYPE_DATASET \
51 (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME | ZFS_TYPE_SNAPSHOT)
54 * Dataset properties are identified by these constants and must be added to
55 * the end of this list to ensure that external consumers are not affected
56 * by the change. If you make any changes to this list, be sure to update
57 * the property table in usr/src/common/zfs/zfs_prop.c.
65 ZFS_PROP_COMPRESSRATIO,
71 ZFS_PROP_VOLBLOCKSIZE,
86 ZFS_PROP_CREATETXG, /* not exposed to the user */
87 ZFS_PROP_NAME, /* not exposed to the user */
90 ZFS_PROP_ISCSIOPTIONS, /* not exposed to the user */
92 ZFS_PROP_NUMCLONES, /* not exposed to the user */
102 ZFS_PROP_REFRESERVATION,
107 * Pool properties are identified by these constants and must be added to the
108 * end of this list to ensure that external conumsers are not affected
109 * by the change. If you make any changes to this list, be sure to update
110 * the property table in usr/src/common/zfs/zpool_prop.c.
116 ZPOOL_PROP_AVAILABLE,
123 ZPOOL_PROP_DELEGATION,
124 ZPOOL_PROP_AUTOREPLACE,
125 ZPOOL_PROP_CACHEFILE,
126 ZPOOL_PROP_FAILUREMODE,
130 #define ZPROP_CONT -2
131 #define ZPROP_INVAL -1
133 #define ZPROP_VALUE "value"
134 #define ZPROP_SOURCE "source"
137 ZPROP_SRC_NONE = 0x1,
138 ZPROP_SRC_DEFAULT = 0x2,
139 ZPROP_SRC_TEMPORARY = 0x4,
140 ZPROP_SRC_LOCAL = 0x8,
141 ZPROP_SRC_INHERITED = 0x10
144 #define ZPROP_SRC_ALL 0x1f
146 typedef int (*zprop_func)(int, void *);
149 * Dataset property functions shared between libzfs and kernel.
151 const char *zfs_prop_default_string(zfs_prop_t);
152 uint64_t zfs_prop_default_numeric(zfs_prop_t);
153 boolean_t zfs_prop_readonly(zfs_prop_t);
154 boolean_t zfs_prop_inheritable(zfs_prop_t);
155 boolean_t zfs_prop_setonce(zfs_prop_t);
156 const char *zfs_prop_to_name(zfs_prop_t);
157 zfs_prop_t zfs_name_to_prop(const char *);
158 boolean_t zfs_prop_user(const char *);
159 int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
160 int zfs_prop_string_to_index(zfs_prop_t, const char *, uint64_t *);
161 int zfs_prop_valid_for_type(int, zfs_type_t);
164 * Pool property functions shared between libzfs and kernel.
166 zpool_prop_t zpool_name_to_prop(const char *);
167 const char *zpool_prop_to_name(zpool_prop_t);
168 const char *zpool_prop_default_string(zpool_prop_t);
169 uint64_t zpool_prop_default_numeric(zpool_prop_t);
170 boolean_t zpool_prop_readonly(zpool_prop_t);
171 int zpool_prop_index_to_string(zpool_prop_t, uint64_t, const char **);
172 int zpool_prop_string_to_index(zpool_prop_t, const char *, uint64_t *);
175 * Definitions for the Delegation.
178 ZFS_DELEG_WHO_UNKNOWN = 0,
179 ZFS_DELEG_USER = 'u',
180 ZFS_DELEG_USER_SETS = 'U',
181 ZFS_DELEG_GROUP = 'g',
182 ZFS_DELEG_GROUP_SETS = 'G',
183 ZFS_DELEG_EVERYONE = 'e',
184 ZFS_DELEG_EVERYONE_SETS = 'E',
185 ZFS_DELEG_CREATE = 'c',
186 ZFS_DELEG_CREATE_SETS = 'C',
187 ZFS_DELEG_NAMED_SET = 's',
188 ZFS_DELEG_NAMED_SET_SETS = 'S'
189 } zfs_deleg_who_type_t;
193 ZFS_DELEG_PERM_LOCAL = 1,
194 ZFS_DELEG_PERM_DESCENDENT = 2,
195 ZFS_DELEG_PERM_LOCALDESCENDENT = 3,
196 ZFS_DELEG_PERM_CREATE = 4
197 } zfs_deleg_inherit_t;
199 #define ZFS_DELEG_PERM_UID "uid"
200 #define ZFS_DELEG_PERM_GID "gid"
201 #define ZFS_DELEG_PERM_GROUPS "groups"
204 ZFS_CANMOUNT_OFF = 0,
206 ZFS_CANMOUNT_NOAUTO = 2
207 } zfs_canmount_type_t;
209 typedef enum zfs_share_op {
217 * On-disk version number.
219 #define SPA_VERSION_1 1ULL
220 #define SPA_VERSION_2 2ULL
221 #define SPA_VERSION_3 3ULL
222 #define SPA_VERSION_4 4ULL
223 #define SPA_VERSION_5 5ULL
224 #define SPA_VERSION_6 6ULL
225 #define SPA_VERSION_7 7ULL
226 #define SPA_VERSION_8 8ULL
227 #define SPA_VERSION_9 9ULL
228 #define SPA_VERSION_10 10ULL
231 * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk
232 * format change. Go to usr/src/grub/grub-0.95/stage2/{zfs-include/, fsys_zfs*},
233 * and do the appropriate changes.
235 #define SPA_VERSION SPA_VERSION_10
236 #define SPA_VERSION_STRING "10"
239 * Symbolic names for the changes that caused a SPA_VERSION switch.
240 * Used in the code when checking for presence or absence of a feature.
241 * Feel free to define multiple symbolic names for each version if there
242 * were multiple changes to on-disk structures during that version.
244 * NOTE: When checking the current SPA_VERSION in your code, be sure
245 * to use spa_version() since it reports the version of the
246 * last synced uberblock. Checking the in-flight version can
247 * be dangerous in some cases.
249 #define SPA_VERSION_INITIAL SPA_VERSION_1
250 #define SPA_VERSION_DITTO_BLOCKS SPA_VERSION_2
251 #define SPA_VERSION_SPARES SPA_VERSION_3
252 #define SPA_VERSION_RAID6 SPA_VERSION_3
253 #define SPA_VERSION_BPLIST_ACCOUNT SPA_VERSION_3
254 #define SPA_VERSION_RAIDZ_DEFLATE SPA_VERSION_3
255 #define SPA_VERSION_DNODE_BYTES SPA_VERSION_3
256 #define SPA_VERSION_ZPOOL_HISTORY SPA_VERSION_4
257 #define SPA_VERSION_GZIP_COMPRESSION SPA_VERSION_5
258 #define SPA_VERSION_BOOTFS SPA_VERSION_6
259 #define SPA_VERSION_SLOGS SPA_VERSION_7
260 #define SPA_VERSION_DELEGATED_PERMS SPA_VERSION_8
261 #define SPA_VERSION_FUID SPA_VERSION_9
262 #define SPA_VERSION_REFRESERVATION SPA_VERSION_9
263 #define SPA_VERSION_REFQUOTA SPA_VERSION_9
264 #define SPA_VERSION_UNIQUE_ACCURATE SPA_VERSION_9
265 #define SPA_VERSION_L2CACHE SPA_VERSION_10
268 * ZPL version - rev'd whenever an incompatible on-disk format change
269 * occurs. This is independent of SPA/DMU/ZAP versioning. You must
270 * also update the version_table[] and help message in zfs_prop.c.
272 * When changing, be sure to teach GRUB how to read the new format!
273 * See usr/src/grub/grub-0.95/stage2/{zfs-include/,fsys_zfs*}
275 #define ZPL_VERSION_1 1ULL
276 #define ZPL_VERSION_2 2ULL
277 #define ZPL_VERSION_3 3ULL
278 #define ZPL_VERSION ZPL_VERSION_3
279 #define ZPL_VERSION_STRING "3"
281 #define ZPL_VERSION_INITIAL ZPL_VERSION_1
282 #define ZPL_VERSION_DIRENT_TYPE ZPL_VERSION_2
283 #define ZPL_VERSION_FUID ZPL_VERSION_3
284 #define ZPL_VERSION_NORMALIZATION ZPL_VERSION_3
285 #define ZPL_VERSION_SYSATTR ZPL_VERSION_3
288 * The following are configuration names used in the nvlist describing a pool's
291 #define ZPOOL_CONFIG_VERSION "version"
292 #define ZPOOL_CONFIG_POOL_NAME "name"
293 #define ZPOOL_CONFIG_POOL_STATE "state"
294 #define ZPOOL_CONFIG_POOL_TXG "txg"
295 #define ZPOOL_CONFIG_POOL_GUID "pool_guid"
296 #define ZPOOL_CONFIG_CREATE_TXG "create_txg"
297 #define ZPOOL_CONFIG_TOP_GUID "top_guid"
298 #define ZPOOL_CONFIG_VDEV_TREE "vdev_tree"
299 #define ZPOOL_CONFIG_TYPE "type"
300 #define ZPOOL_CONFIG_CHILDREN "children"
301 #define ZPOOL_CONFIG_ID "id"
302 #define ZPOOL_CONFIG_GUID "guid"
303 #define ZPOOL_CONFIG_PATH "path"
304 #define ZPOOL_CONFIG_DEVID "devid"
305 #define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array"
306 #define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift"
307 #define ZPOOL_CONFIG_ASHIFT "ashift"
308 #define ZPOOL_CONFIG_ASIZE "asize"
309 #define ZPOOL_CONFIG_DTL "DTL"
310 #define ZPOOL_CONFIG_STATS "stats"
311 #define ZPOOL_CONFIG_WHOLE_DISK "whole_disk"
312 #define ZPOOL_CONFIG_ERRCOUNT "error_count"
313 #define ZPOOL_CONFIG_NOT_PRESENT "not_present"
314 #define ZPOOL_CONFIG_SPARES "spares"
315 #define ZPOOL_CONFIG_IS_SPARE "is_spare"
316 #define ZPOOL_CONFIG_NPARITY "nparity"
317 #define ZPOOL_CONFIG_HOSTID "hostid"
318 #define ZPOOL_CONFIG_HOSTNAME "hostname"
319 #define ZPOOL_CONFIG_UNSPARE "unspare"
320 #define ZPOOL_CONFIG_PHYS_PATH "phys_path"
321 #define ZPOOL_CONFIG_IS_LOG "is_log"
322 #define ZPOOL_CONFIG_L2CACHE "l2cache"
323 #define ZPOOL_CONFIG_TIMESTAMP "timestamp" /* not stored on disk */
324 #define ZPOOL_CONFIG_BOOTFS "bootfs" /* not stored on disk */
326 * The persistent vdev state is stored as separate values rather than a single
327 * 'vdev_state' entry. This is because a device can be in multiple states, such
328 * as offline and degraded.
330 #define ZPOOL_CONFIG_OFFLINE "offline"
331 #define ZPOOL_CONFIG_FAULTED "faulted"
332 #define ZPOOL_CONFIG_DEGRADED "degraded"
333 #define ZPOOL_CONFIG_REMOVED "removed"
335 #define VDEV_TYPE_ROOT "root"
336 #define VDEV_TYPE_MIRROR "mirror"
337 #define VDEV_TYPE_REPLACING "replacing"
338 #define VDEV_TYPE_RAIDZ "raidz"
339 #define VDEV_TYPE_DISK "disk"
340 #define VDEV_TYPE_FILE "file"
341 #define VDEV_TYPE_MISSING "missing"
342 #define VDEV_TYPE_SPARE "spare"
343 #define VDEV_TYPE_LOG "log"
344 #define VDEV_TYPE_L2CACHE "l2cache"
347 * This is needed in userland to report the minimum necessary device size.
349 #define SPA_MINDEVSIZE (64ULL << 20)
352 * The location of the pool configuration repository, shared between kernel and
355 #define ZPOOL_CACHE_DIR "/etc/zfs"
356 #define ZPOOL_CACHE_FILE "zpool.cache"
357 #define ZPOOL_CACHE_TMP ".zpool.cache"
359 #define ZPOOL_CACHE ZPOOL_CACHE_DIR "/" ZPOOL_CACHE_FILE
362 * vdev states are ordered from least to most healthy.
363 * A vdev that's CANT_OPEN or below is considered unusable.
365 typedef enum vdev_state {
366 VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev */
367 VDEV_STATE_CLOSED, /* Not currently open */
368 VDEV_STATE_OFFLINE, /* Not allowed to open */
369 VDEV_STATE_REMOVED, /* Explicitly removed from system */
370 VDEV_STATE_CANT_OPEN, /* Tried to open, but failed */
371 VDEV_STATE_FAULTED, /* External request to fault device */
372 VDEV_STATE_DEGRADED, /* Replicated vdev with unhealthy kids */
373 VDEV_STATE_HEALTHY /* Presumed good */
376 #define VDEV_STATE_ONLINE VDEV_STATE_HEALTHY
379 * vdev aux states. When a vdev is in the CANT_OPEN state, the aux field
380 * of the vdev stats structure uses these constants to distinguish why.
382 typedef enum vdev_aux {
383 VDEV_AUX_NONE, /* no error */
384 VDEV_AUX_OPEN_FAILED, /* ldi_open_*() or vn_open() failed */
385 VDEV_AUX_CORRUPT_DATA, /* bad label or disk contents */
386 VDEV_AUX_NO_REPLICAS, /* insufficient number of replicas */
387 VDEV_AUX_BAD_GUID_SUM, /* vdev guid sum doesn't match */
388 VDEV_AUX_TOO_SMALL, /* vdev size is too small */
389 VDEV_AUX_BAD_LABEL, /* the label is OK but invalid */
390 VDEV_AUX_VERSION_NEWER, /* on-disk version is too new */
391 VDEV_AUX_VERSION_OLDER, /* on-disk version is too old */
392 VDEV_AUX_SPARED, /* hot spare used in another pool */
393 VDEV_AUX_ERR_EXCEEDED /* too many errors */
397 * pool state. The following states are written to disk as part of the normal
398 * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE. The remaining
399 * states are software abstractions used at various levels to communicate
402 typedef enum pool_state {
403 POOL_STATE_ACTIVE = 0, /* In active use */
404 POOL_STATE_EXPORTED, /* Explicitly exported */
405 POOL_STATE_DESTROYED, /* Explicitly destroyed */
406 POOL_STATE_SPARE, /* Reserved for hot spare use */
407 POOL_STATE_L2CACHE, /* Level 2 ARC device */
408 POOL_STATE_UNINITIALIZED, /* Internal spa_t state */
409 POOL_STATE_IO_FAILURE, /* Internal pool state */
410 POOL_STATE_UNAVAIL, /* Internal libzfs state */
411 POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */
417 typedef enum pool_scrub_type {
420 POOL_SCRUB_EVERYTHING,
425 * ZIO types. Needed to interpret vdev statistics below.
427 typedef enum zio_type {
438 * Vdev statistics. Note: all fields should be 64-bit because this
439 * is passed between kernel and userland as an nvlist uint64 array.
441 typedef struct vdev_stat {
442 hrtime_t vs_timestamp; /* time since vdev load */
443 uint64_t vs_state; /* vdev state */
444 uint64_t vs_aux; /* see vdev_aux_t */
445 uint64_t vs_alloc; /* space allocated */
446 uint64_t vs_space; /* total capacity */
447 uint64_t vs_dspace; /* deflated capacity */
448 uint64_t vs_rsize; /* replaceable dev size */
449 uint64_t vs_ops[ZIO_TYPES]; /* operation count */
450 uint64_t vs_bytes[ZIO_TYPES]; /* bytes read/written */
451 uint64_t vs_read_errors; /* read errors */
452 uint64_t vs_write_errors; /* write errors */
453 uint64_t vs_checksum_errors; /* checksum errors */
454 uint64_t vs_self_healed; /* self-healed bytes */
455 uint64_t vs_scrub_type; /* pool_scrub_type_t */
456 uint64_t vs_scrub_complete; /* completed? */
457 uint64_t vs_scrub_examined; /* bytes examined; top */
458 uint64_t vs_scrub_repaired; /* bytes repaired; leaf */
459 uint64_t vs_scrub_errors; /* errors during scrub */
460 uint64_t vs_scrub_start; /* UTC scrub start time */
461 uint64_t vs_scrub_end; /* UTC scrub end time */
464 #define ZVOL_DRIVER "zvol"
465 #define ZFS_DRIVER "zfs"
466 #define ZFS_DEV "/dev/zfs"
469 * zvol paths. Irritatingly, the devfsadm interfaces want all these
470 * paths without the /dev prefix, but for some things, we want the
471 * /dev prefix. Below are the names without /dev.
473 #define ZVOL_DEV_DIR "zvol/dsk"
474 #define ZVOL_RDEV_DIR "zvol/rdsk"
477 * And here are the things we need with /dev, etc. in front of them.
479 #define ZVOL_PSEUDO_DEV "/devices/pseudo/zvol@0:"
480 #define ZVOL_FULL_DEV_DIR "/dev/" ZVOL_DEV_DIR "/"
482 #define ZVOL_PROP_NAME "name"
485 * /dev/zfs ioctl numbers.
487 #define ZFS_IOC ('Z' << 8)
489 typedef enum zfs_ioc {
490 ZFS_IOC_POOL_CREATE = ZFS_IOC,
491 ZFS_IOC_POOL_DESTROY,
494 ZFS_IOC_POOL_CONFIGS,
496 ZFS_IOC_POOL_TRYIMPORT,
499 ZFS_IOC_POOL_UPGRADE,
500 ZFS_IOC_POOL_GET_HISTORY,
503 ZFS_IOC_VDEV_SET_STATE,
506 ZFS_IOC_VDEV_SETPATH,
507 ZFS_IOC_OBJSET_STATS,
508 ZFS_IOC_OBJSET_ZPLPROPS,
509 ZFS_IOC_DATASET_LIST_NEXT,
510 ZFS_IOC_SNAPSHOT_LIST_NEXT,
512 ZFS_IOC_CREATE_MINOR,
513 ZFS_IOC_REMOVE_MINOR,
520 ZFS_IOC_INJECT_FAULT,
522 ZFS_IOC_INJECT_LIST_NEXT,
526 ZFS_IOC_DESTROY_SNAPS,
528 ZFS_IOC_DSOBJ_TO_DSNAME,
530 ZFS_IOC_POOL_SET_PROPS,
531 ZFS_IOC_POOL_GET_PROPS,
534 ZFS_IOC_ISCSI_PERM_CHECK,
540 * Internal SPA load state. Used by FMA diagnosis engine.
543 SPA_LOAD_NONE, /* no load in progress */
544 SPA_LOAD_OPEN, /* normal open */
545 SPA_LOAD_IMPORT, /* import in progress */
546 SPA_LOAD_TRYIMPORT /* tryimport in progress */
550 * Bookmark name values.
552 #define ZPOOL_ERR_LIST "error list"
553 #define ZPOOL_ERR_DATASET "dataset"
554 #define ZPOOL_ERR_OBJECT "object"
556 #define HIS_MAX_RECORD_LEN (MAXPATHLEN + MAXPATHLEN + 1)
559 * The following are names used in the nvlist describing
560 * the pool's history log.
562 #define ZPOOL_HIST_RECORD "history record"
563 #define ZPOOL_HIST_TIME "history time"
564 #define ZPOOL_HIST_CMD "history command"
565 #define ZPOOL_HIST_WHO "history who"
566 #define ZPOOL_HIST_ZONE "history zone"
567 #define ZPOOL_HIST_HOST "history hostname"
568 #define ZPOOL_HIST_TXG "history txg"
569 #define ZPOOL_HIST_INT_EVENT "history internal event"
570 #define ZPOOL_HIST_INT_STR "history internal str"
573 * Flags for ZFS_IOC_VDEV_SET_STATE
575 #define ZFS_ONLINE_CHECKREMOVE 0x1
576 #define ZFS_ONLINE_UNSPARE 0x2
577 #define ZFS_ONLINE_FORCEFAULT 0x4
578 #define ZFS_OFFLINE_TEMPORARY 0x1
581 * Sysevent payload members. ZFS will generate the following sysevents with the
584 * ESC_ZFS_RESILVER_START
585 * ESC_ZFS_RESILVER_END
586 * ESC_ZFS_POOL_DESTROY
588 * ZFS_EV_POOL_NAME DATA_TYPE_STRING
589 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64
591 * ESC_ZFS_VDEV_REMOVE
595 * ZFS_EV_POOL_NAME DATA_TYPE_STRING
596 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64
597 * ZFS_EV_VDEV_PATH DATA_TYPE_STRING (optional)
598 * ZFS_EV_VDEV_GUID DATA_TYPE_UINT64
600 #define ZFS_EV_POOL_NAME "pool_name"
601 #define ZFS_EV_POOL_GUID "pool_guid"
602 #define ZFS_EV_VDEV_PATH "vdev_path"
603 #define ZFS_EV_VDEV_GUID "vdev_guid"
605 typedef enum history_internal_events {
613 LOG_POOL_VDEV_ATTACH,
614 LOG_POOL_VDEV_REPLACE,
615 LOG_POOL_VDEV_DETACH,
616 LOG_POOL_VDEV_ONLINE,
617 LOG_POOL_VDEV_OFFLINE,
625 LOG_DS_DESTROY_BEGIN,
631 LOG_DS_PERM_WHO_REMOVE,
636 LOG_DS_REPLAY_INC_SYNC,
637 LOG_DS_REPLAY_FULL_SYNC,
644 } history_internal_events_t;
650 #endif /* _SYS_FS_ZFS_H */