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.
34 * Types and constants shared between userland and the kernel.
38 * Each dataset can be one of the following types. These constants can be
39 * combined into masks that can be passed to various functions.
42 ZFS_TYPE_FILESYSTEM = 0x1,
43 ZFS_TYPE_SNAPSHOT = 0x2,
44 ZFS_TYPE_VOLUME = 0x4,
48 #define ZFS_TYPE_DATASET \
49 (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME | ZFS_TYPE_SNAPSHOT)
52 * Dataset properties are identified by these constants and must be added to
53 * the end of this list to ensure that external consumers are not affected
54 * by the change. If you make any changes to this list, be sure to update
55 * the property table in usr/src/common/zfs/zfs_prop.c.
63 ZFS_PROP_COMPRESSRATIO,
69 ZFS_PROP_VOLBLOCKSIZE,
84 ZFS_PROP_CREATETXG, /* not exposed to the user */
85 ZFS_PROP_NAME, /* not exposed to the user */
88 ZFS_PROP_ISCSIOPTIONS, /* not exposed to the user */
90 ZFS_PROP_NUMCLONES, /* not exposed to the user */
100 ZFS_PROP_REFRESERVATION,
102 ZFS_PROP_PRIMARYCACHE,
103 ZFS_PROP_SECONDARYCACHE,
107 ZFS_PROP_USEDREFRESERV,
112 * Pool properties are identified by these constants and must be added to the
113 * end of this list to ensure that external consumers are not affected
114 * by the change. If you make any changes to this list, be sure to update
115 * the property table in usr/src/common/zfs/zpool_prop.c.
121 ZPOOL_PROP_AVAILABLE,
128 ZPOOL_PROP_DELEGATION,
129 ZPOOL_PROP_AUTOREPLACE,
130 ZPOOL_PROP_CACHEFILE,
131 ZPOOL_PROP_FAILUREMODE,
132 ZPOOL_PROP_LISTSNAPS,
136 #define ZPROP_CONT -2
137 #define ZPROP_INVAL -1
139 #define ZPROP_VALUE "value"
140 #define ZPROP_SOURCE "source"
143 ZPROP_SRC_NONE = 0x1,
144 ZPROP_SRC_DEFAULT = 0x2,
145 ZPROP_SRC_TEMPORARY = 0x4,
146 ZPROP_SRC_LOCAL = 0x8,
147 ZPROP_SRC_INHERITED = 0x10
150 #define ZPROP_SRC_ALL 0x1f
152 typedef int (*zprop_func)(int, void *);
155 * Properties to be set on the root file system of a new pool
156 * are stuffed into their own nvlist, which is then included in
157 * the properties nvlist with the pool properties.
159 #define ZPOOL_ROOTFS_PROPS "root-props-nvl"
162 * Dataset property functions shared between libzfs and kernel.
164 const char *zfs_prop_default_string(zfs_prop_t);
165 uint64_t zfs_prop_default_numeric(zfs_prop_t);
166 boolean_t zfs_prop_readonly(zfs_prop_t);
167 boolean_t zfs_prop_inheritable(zfs_prop_t);
168 boolean_t zfs_prop_setonce(zfs_prop_t);
169 const char *zfs_prop_to_name(zfs_prop_t);
170 zfs_prop_t zfs_name_to_prop(const char *);
171 boolean_t zfs_prop_user(const char *);
172 int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
173 int zfs_prop_string_to_index(zfs_prop_t, const char *, uint64_t *);
174 boolean_t zfs_prop_valid_for_type(int, zfs_type_t);
177 * Pool property functions shared between libzfs and kernel.
179 zpool_prop_t zpool_name_to_prop(const char *);
180 const char *zpool_prop_to_name(zpool_prop_t);
181 const char *zpool_prop_default_string(zpool_prop_t);
182 uint64_t zpool_prop_default_numeric(zpool_prop_t);
183 boolean_t zpool_prop_readonly(zpool_prop_t);
184 int zpool_prop_index_to_string(zpool_prop_t, uint64_t, const char **);
185 int zpool_prop_string_to_index(zpool_prop_t, const char *, uint64_t *);
188 * Definitions for the Delegation.
191 ZFS_DELEG_WHO_UNKNOWN = 0,
192 ZFS_DELEG_USER = 'u',
193 ZFS_DELEG_USER_SETS = 'U',
194 ZFS_DELEG_GROUP = 'g',
195 ZFS_DELEG_GROUP_SETS = 'G',
196 ZFS_DELEG_EVERYONE = 'e',
197 ZFS_DELEG_EVERYONE_SETS = 'E',
198 ZFS_DELEG_CREATE = 'c',
199 ZFS_DELEG_CREATE_SETS = 'C',
200 ZFS_DELEG_NAMED_SET = 's',
201 ZFS_DELEG_NAMED_SET_SETS = 'S'
202 } zfs_deleg_who_type_t;
206 ZFS_DELEG_PERM_LOCAL = 1,
207 ZFS_DELEG_PERM_DESCENDENT = 2,
208 ZFS_DELEG_PERM_LOCALDESCENDENT = 3,
209 ZFS_DELEG_PERM_CREATE = 4
210 } zfs_deleg_inherit_t;
212 #define ZFS_DELEG_PERM_UID "uid"
213 #define ZFS_DELEG_PERM_GID "gid"
214 #define ZFS_DELEG_PERM_GROUPS "groups"
217 ZFS_CANMOUNT_OFF = 0,
219 ZFS_CANMOUNT_NOAUTO = 2
220 } zfs_canmount_type_t;
222 typedef enum zfs_share_op {
229 typedef enum zfs_cache_type {
231 ZFS_CACHE_METADATA = 1,
237 * On-disk version number.
239 #define SPA_VERSION_1 1ULL
240 #define SPA_VERSION_2 2ULL
241 #define SPA_VERSION_3 3ULL
242 #define SPA_VERSION_4 4ULL
243 #define SPA_VERSION_5 5ULL
244 #define SPA_VERSION_6 6ULL
245 #define SPA_VERSION_7 7ULL
246 #define SPA_VERSION_8 8ULL
247 #define SPA_VERSION_9 9ULL
248 #define SPA_VERSION_10 10ULL
249 #define SPA_VERSION_11 11ULL
250 #define SPA_VERSION_12 12ULL
251 #define SPA_VERSION_13 13ULL
252 #define SPA_VERSION_14 14ULL
254 * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk
255 * format change. Go to usr/src/grub/grub-0.95/stage2/{zfs-include/, fsys_zfs*},
256 * and do the appropriate changes.
258 #define SPA_VERSION SPA_VERSION_14
259 #define SPA_VERSION_STRING "14"
262 * Symbolic names for the changes that caused a SPA_VERSION switch.
263 * Used in the code when checking for presence or absence of a feature.
264 * Feel free to define multiple symbolic names for each version if there
265 * were multiple changes to on-disk structures during that version.
267 * NOTE: When checking the current SPA_VERSION in your code, be sure
268 * to use spa_version() since it reports the version of the
269 * last synced uberblock. Checking the in-flight version can
270 * be dangerous in some cases.
272 #define SPA_VERSION_INITIAL SPA_VERSION_1
273 #define SPA_VERSION_DITTO_BLOCKS SPA_VERSION_2
274 #define SPA_VERSION_SPARES SPA_VERSION_3
275 #define SPA_VERSION_RAID6 SPA_VERSION_3
276 #define SPA_VERSION_BPLIST_ACCOUNT SPA_VERSION_3
277 #define SPA_VERSION_RAIDZ_DEFLATE SPA_VERSION_3
278 #define SPA_VERSION_DNODE_BYTES SPA_VERSION_3
279 #define SPA_VERSION_ZPOOL_HISTORY SPA_VERSION_4
280 #define SPA_VERSION_GZIP_COMPRESSION SPA_VERSION_5
281 #define SPA_VERSION_BOOTFS SPA_VERSION_6
282 #define SPA_VERSION_SLOGS SPA_VERSION_7
283 #define SPA_VERSION_DELEGATED_PERMS SPA_VERSION_8
284 #define SPA_VERSION_FUID SPA_VERSION_9
285 #define SPA_VERSION_REFRESERVATION SPA_VERSION_9
286 #define SPA_VERSION_REFQUOTA SPA_VERSION_9
287 #define SPA_VERSION_UNIQUE_ACCURATE SPA_VERSION_9
288 #define SPA_VERSION_L2CACHE SPA_VERSION_10
289 #define SPA_VERSION_NEXT_CLONES SPA_VERSION_11
290 #define SPA_VERSION_ORIGIN SPA_VERSION_11
291 #define SPA_VERSION_DSL_SCRUB SPA_VERSION_11
292 #define SPA_VERSION_SNAP_PROPS SPA_VERSION_12
293 #define SPA_VERSION_USED_BREAKDOWN SPA_VERSION_13
294 #define SPA_VERSION_PASSTHROUGH_X SPA_VERSION_14
297 * ZPL version - rev'd whenever an incompatible on-disk format change
298 * occurs. This is independent of SPA/DMU/ZAP versioning. You must
299 * also update the version_table[] and help message in zfs_prop.c.
301 * When changing, be sure to teach GRUB how to read the new format!
302 * See usr/src/grub/grub-0.95/stage2/{zfs-include/,fsys_zfs*}
304 #define ZPL_VERSION_1 1ULL
305 #define ZPL_VERSION_2 2ULL
306 #define ZPL_VERSION_3 3ULL
307 #define ZPL_VERSION ZPL_VERSION_3
308 #define ZPL_VERSION_STRING "3"
310 #define ZPL_VERSION_INITIAL ZPL_VERSION_1
311 #define ZPL_VERSION_DIRENT_TYPE ZPL_VERSION_2
312 #define ZPL_VERSION_FUID ZPL_VERSION_3
313 #define ZPL_VERSION_NORMALIZATION ZPL_VERSION_3
314 #define ZPL_VERSION_SYSATTR ZPL_VERSION_3
317 * The following are configuration names used in the nvlist describing a pool's
320 #define ZPOOL_CONFIG_VERSION "version"
321 #define ZPOOL_CONFIG_POOL_NAME "name"
322 #define ZPOOL_CONFIG_POOL_STATE "state"
323 #define ZPOOL_CONFIG_POOL_TXG "txg"
324 #define ZPOOL_CONFIG_POOL_GUID "pool_guid"
325 #define ZPOOL_CONFIG_CREATE_TXG "create_txg"
326 #define ZPOOL_CONFIG_TOP_GUID "top_guid"
327 #define ZPOOL_CONFIG_VDEV_TREE "vdev_tree"
328 #define ZPOOL_CONFIG_TYPE "type"
329 #define ZPOOL_CONFIG_CHILDREN "children"
330 #define ZPOOL_CONFIG_ID "id"
331 #define ZPOOL_CONFIG_GUID "guid"
332 #define ZPOOL_CONFIG_PATH "path"
333 #define ZPOOL_CONFIG_DEVID "devid"
334 #define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array"
335 #define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift"
336 #define ZPOOL_CONFIG_ASHIFT "ashift"
337 #define ZPOOL_CONFIG_ASIZE "asize"
338 #define ZPOOL_CONFIG_DTL "DTL"
339 #define ZPOOL_CONFIG_STATS "stats"
340 #define ZPOOL_CONFIG_WHOLE_DISK "whole_disk"
341 #define ZPOOL_CONFIG_ERRCOUNT "error_count"
342 #define ZPOOL_CONFIG_NOT_PRESENT "not_present"
343 #define ZPOOL_CONFIG_SPARES "spares"
344 #define ZPOOL_CONFIG_IS_SPARE "is_spare"
345 #define ZPOOL_CONFIG_NPARITY "nparity"
346 #define ZPOOL_CONFIG_HOSTID "hostid"
347 #define ZPOOL_CONFIG_HOSTNAME "hostname"
348 #define ZPOOL_CONFIG_UNSPARE "unspare"
349 #define ZPOOL_CONFIG_PHYS_PATH "phys_path"
350 #define ZPOOL_CONFIG_IS_LOG "is_log"
351 #define ZPOOL_CONFIG_L2CACHE "l2cache"
352 #define ZPOOL_CONFIG_SUSPENDED "suspended" /* not stored on disk */
353 #define ZPOOL_CONFIG_TIMESTAMP "timestamp" /* not stored on disk */
354 #define ZPOOL_CONFIG_BOOTFS "bootfs" /* not stored on disk */
356 * The persistent vdev state is stored as separate values rather than a single
357 * 'vdev_state' entry. This is because a device can be in multiple states, such
358 * as offline and degraded.
360 #define ZPOOL_CONFIG_OFFLINE "offline"
361 #define ZPOOL_CONFIG_FAULTED "faulted"
362 #define ZPOOL_CONFIG_DEGRADED "degraded"
363 #define ZPOOL_CONFIG_REMOVED "removed"
365 #define VDEV_TYPE_ROOT "root"
366 #define VDEV_TYPE_MIRROR "mirror"
367 #define VDEV_TYPE_REPLACING "replacing"
368 #define VDEV_TYPE_RAIDZ "raidz"
369 #define VDEV_TYPE_DISK "disk"
370 #define VDEV_TYPE_FILE "file"
371 #define VDEV_TYPE_MISSING "missing"
372 #define VDEV_TYPE_SPARE "spare"
373 #define VDEV_TYPE_LOG "log"
374 #define VDEV_TYPE_L2CACHE "l2cache"
377 * This is needed in userland to report the minimum necessary device size.
379 #define SPA_MINDEVSIZE (64ULL << 20)
382 * The location of the pool configuration repository, shared between kernel and
385 #define ZPOOL_CACHE "/etc/zfs/zpool.cache"
388 * vdev states are ordered from least to most healthy.
389 * A vdev that's CANT_OPEN or below is considered unusable.
391 typedef enum vdev_state {
392 VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev */
393 VDEV_STATE_CLOSED, /* Not currently open */
394 VDEV_STATE_OFFLINE, /* Not allowed to open */
395 VDEV_STATE_REMOVED, /* Explicitly removed from system */
396 VDEV_STATE_CANT_OPEN, /* Tried to open, but failed */
397 VDEV_STATE_FAULTED, /* External request to fault device */
398 VDEV_STATE_DEGRADED, /* Replicated vdev with unhealthy kids */
399 VDEV_STATE_HEALTHY /* Presumed good */
402 #define VDEV_STATE_ONLINE VDEV_STATE_HEALTHY
405 * vdev aux states. When a vdev is in the CANT_OPEN state, the aux field
406 * of the vdev stats structure uses these constants to distinguish why.
408 typedef enum vdev_aux {
409 VDEV_AUX_NONE, /* no error */
410 VDEV_AUX_OPEN_FAILED, /* ldi_open_*() or vn_open() failed */
411 VDEV_AUX_CORRUPT_DATA, /* bad label or disk contents */
412 VDEV_AUX_NO_REPLICAS, /* insufficient number of replicas */
413 VDEV_AUX_BAD_GUID_SUM, /* vdev guid sum doesn't match */
414 VDEV_AUX_TOO_SMALL, /* vdev size is too small */
415 VDEV_AUX_BAD_LABEL, /* the label is OK but invalid */
416 VDEV_AUX_VERSION_NEWER, /* on-disk version is too new */
417 VDEV_AUX_VERSION_OLDER, /* on-disk version is too old */
418 VDEV_AUX_SPARED, /* hot spare used in another pool */
419 VDEV_AUX_ERR_EXCEEDED, /* too many errors */
420 VDEV_AUX_IO_FAILURE, /* experienced I/O failure */
421 VDEV_AUX_BAD_LOG /* cannot read log chain(s) */
425 * pool state. The following states are written to disk as part of the normal
426 * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE. The remaining
427 * states are software abstractions used at various levels to communicate
430 typedef enum pool_state {
431 POOL_STATE_ACTIVE = 0, /* In active use */
432 POOL_STATE_EXPORTED, /* Explicitly exported */
433 POOL_STATE_DESTROYED, /* Explicitly destroyed */
434 POOL_STATE_SPARE, /* Reserved for hot spare use */
435 POOL_STATE_L2CACHE, /* Level 2 ARC device */
436 POOL_STATE_UNINITIALIZED, /* Internal spa_t state */
437 POOL_STATE_UNAVAIL, /* Internal libzfs state */
438 POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */
444 typedef enum pool_scrub_type {
447 POOL_SCRUB_EVERYTHING,
452 * ZIO types. Needed to interpret vdev statistics below.
454 typedef enum zio_type {
465 * Vdev statistics. Note: all fields should be 64-bit because this
466 * is passed between kernel and userland as an nvlist uint64 array.
468 typedef struct vdev_stat {
469 hrtime_t vs_timestamp; /* time since vdev load */
470 uint64_t vs_state; /* vdev state */
471 uint64_t vs_aux; /* see vdev_aux_t */
472 uint64_t vs_alloc; /* space allocated */
473 uint64_t vs_space; /* total capacity */
474 uint64_t vs_dspace; /* deflated capacity */
475 uint64_t vs_rsize; /* replaceable dev size */
476 uint64_t vs_ops[ZIO_TYPES]; /* operation count */
477 uint64_t vs_bytes[ZIO_TYPES]; /* bytes read/written */
478 uint64_t vs_read_errors; /* read errors */
479 uint64_t vs_write_errors; /* write errors */
480 uint64_t vs_checksum_errors; /* checksum errors */
481 uint64_t vs_self_healed; /* self-healed bytes */
482 uint64_t vs_scrub_type; /* pool_scrub_type_t */
483 uint64_t vs_scrub_complete; /* completed? */
484 uint64_t vs_scrub_examined; /* bytes examined; top */
485 uint64_t vs_scrub_repaired; /* bytes repaired; leaf */
486 uint64_t vs_scrub_errors; /* errors during scrub */
487 uint64_t vs_scrub_start; /* UTC scrub start time */
488 uint64_t vs_scrub_end; /* UTC scrub end time */
491 #define ZVOL_DRIVER "zvol"
492 #define ZFS_DRIVER "zfs"
493 #define ZFS_DEV "/dev/zfs"
496 * zvol paths. Irritatingly, the devfsadm interfaces want all these
497 * paths without the /dev prefix, but for some things, we want the
498 * /dev prefix. Below are the names without /dev.
500 #define ZVOL_DEV_DIR "zvol/dsk"
501 #define ZVOL_RDEV_DIR "zvol/rdsk"
504 * And here are the things we need with /dev, etc. in front of them.
506 #define ZVOL_PSEUDO_DEV "/devices/pseudo/zvol@0:"
507 #define ZVOL_FULL_DEV_DIR "/dev/" ZVOL_DEV_DIR "/"
509 #define ZVOL_PROP_NAME "name"
512 * /dev/zfs ioctl numbers.
514 #define ZFS_IOC ('Z' << 8)
516 typedef enum zfs_ioc {
517 ZFS_IOC_POOL_CREATE = ZFS_IOC,
518 ZFS_IOC_POOL_DESTROY,
521 ZFS_IOC_POOL_CONFIGS,
523 ZFS_IOC_POOL_TRYIMPORT,
526 ZFS_IOC_POOL_UPGRADE,
527 ZFS_IOC_POOL_GET_HISTORY,
530 ZFS_IOC_VDEV_SET_STATE,
533 ZFS_IOC_VDEV_SETPATH,
534 ZFS_IOC_OBJSET_STATS,
535 ZFS_IOC_OBJSET_ZPLPROPS,
536 ZFS_IOC_DATASET_LIST_NEXT,
537 ZFS_IOC_SNAPSHOT_LIST_NEXT,
539 ZFS_IOC_CREATE_MINOR,
540 ZFS_IOC_REMOVE_MINOR,
547 ZFS_IOC_INJECT_FAULT,
549 ZFS_IOC_INJECT_LIST_NEXT,
553 ZFS_IOC_DESTROY_SNAPS,
555 ZFS_IOC_DSOBJ_TO_DSNAME,
557 ZFS_IOC_POOL_SET_PROPS,
558 ZFS_IOC_POOL_GET_PROPS,
561 ZFS_IOC_ISCSI_PERM_CHECK,
567 * Internal SPA load state. Used by FMA diagnosis engine.
570 SPA_LOAD_NONE, /* no load in progress */
571 SPA_LOAD_OPEN, /* normal open */
572 SPA_LOAD_IMPORT, /* import in progress */
573 SPA_LOAD_TRYIMPORT /* tryimport in progress */
577 * Bookmark name values.
579 #define ZPOOL_ERR_LIST "error list"
580 #define ZPOOL_ERR_DATASET "dataset"
581 #define ZPOOL_ERR_OBJECT "object"
583 #define HIS_MAX_RECORD_LEN (MAXPATHLEN + MAXPATHLEN + 1)
586 * The following are names used in the nvlist describing
587 * the pool's history log.
589 #define ZPOOL_HIST_RECORD "history record"
590 #define ZPOOL_HIST_TIME "history time"
591 #define ZPOOL_HIST_CMD "history command"
592 #define ZPOOL_HIST_WHO "history who"
593 #define ZPOOL_HIST_ZONE "history zone"
594 #define ZPOOL_HIST_HOST "history hostname"
595 #define ZPOOL_HIST_TXG "history txg"
596 #define ZPOOL_HIST_INT_EVENT "history internal event"
597 #define ZPOOL_HIST_INT_STR "history internal str"
600 * Flags for ZFS_IOC_VDEV_SET_STATE
602 #define ZFS_ONLINE_CHECKREMOVE 0x1
603 #define ZFS_ONLINE_UNSPARE 0x2
604 #define ZFS_ONLINE_FORCEFAULT 0x4
605 #define ZFS_OFFLINE_TEMPORARY 0x1
608 * Sysevent payload members. ZFS will generate the following sysevents with the
611 * ESC_ZFS_RESILVER_START
612 * ESC_ZFS_RESILVER_END
613 * ESC_ZFS_POOL_DESTROY
615 * ZFS_EV_POOL_NAME DATA_TYPE_STRING
616 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64
618 * ESC_ZFS_VDEV_REMOVE
622 * ZFS_EV_POOL_NAME DATA_TYPE_STRING
623 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64
624 * ZFS_EV_VDEV_PATH DATA_TYPE_STRING (optional)
625 * ZFS_EV_VDEV_GUID DATA_TYPE_UINT64
627 #define ZFS_EV_POOL_NAME "pool_name"
628 #define ZFS_EV_POOL_GUID "pool_guid"
629 #define ZFS_EV_VDEV_PATH "vdev_path"
630 #define ZFS_EV_VDEV_GUID "vdev_guid"
633 * Note: This is encoded on-disk, so new events must be added to the
634 * end, and unused events can not be removed. Be sure to edit
635 * zpool_main.c: hist_event_table[].
637 typedef enum history_internal_events {
645 LOG_POOL_VDEV_ATTACH,
646 LOG_POOL_VDEV_REPLACE,
647 LOG_POOL_VDEV_DETACH,
648 LOG_POOL_VDEV_ONLINE,
649 LOG_POOL_VDEV_OFFLINE,
657 LOG_DS_DESTROY_BEGIN,
663 LOG_DS_PERM_WHO_REMOVE,
668 LOG_DS_REPLAY_INC_SYNC,
669 LOG_DS_REPLAY_FULL_SYNC,
677 } history_internal_events_t;
683 #endif /* _SYS_FS_ZFS_H */