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]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2012 by Delphix. All rights reserved.
25 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
26 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
27 * Copyright (c) 2012, Martin Matuska <mm@FreeBSD.org>. All rights reserved.
30 /* Portions Copyright 2010 Robert Milkowski */
35 #include <sys/types.h>
36 #include <sys/ioccom.h>
44 * Types and constants shared between userland and the kernel.
48 * Each dataset can be one of the following types. These constants can be
49 * combined into masks that can be passed to various functions.
52 ZFS_TYPE_FILESYSTEM = 0x1,
53 ZFS_TYPE_SNAPSHOT = 0x2,
54 ZFS_TYPE_VOLUME = 0x4,
58 #define ZFS_TYPE_DATASET \
59 (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME | ZFS_TYPE_SNAPSHOT)
61 #define ZAP_MAXNAMELEN 256
62 #define ZAP_MAXVALUELEN (1024 * 8)
63 #define ZAP_OLDMAXVALUELEN 1024
66 * Dataset properties are identified by these constants and must be added to
67 * the end of this list to ensure that external consumers are not affected
68 * by the change. If you make any changes to this list, be sure to update
69 * the property table in usr/src/common/zfs/zfs_prop.c.
77 ZFS_PROP_COMPRESSRATIO,
83 ZFS_PROP_VOLBLOCKSIZE,
98 ZFS_PROP_CREATETXG, /* not exposed to the user */
99 ZFS_PROP_NAME, /* not exposed to the user */
101 ZFS_PROP_ISCSIOPTIONS, /* not exposed to the user */
103 ZFS_PROP_NUMCLONES, /* not exposed to the user */
113 ZFS_PROP_REFRESERVATION,
115 ZFS_PROP_PRIMARYCACHE,
116 ZFS_PROP_SECONDARYCACHE,
120 ZFS_PROP_USEDREFRESERV,
121 ZFS_PROP_USERACCOUNTING, /* not exposed to the user */
122 ZFS_PROP_STMF_SHAREINFO, /* not exposed to the user */
123 ZFS_PROP_DEFER_DESTROY,
126 ZFS_PROP_UNIQUE, /* not exposed to the user */
127 ZFS_PROP_OBJSETID, /* not exposed to the user */
142 ZFS_NUM_USERQUOTA_PROPS
143 } zfs_userquota_prop_t;
145 extern const char *zfs_userquota_prop_prefixes[ZFS_NUM_USERQUOTA_PROPS];
148 * Pool properties are identified by these constants and must be added to the
149 * end of this list to ensure that external consumers are not affected
150 * by the change. If you make any changes to this list, be sure to update
151 * the property table in usr/src/common/zfs/zpool_prop.c.
162 ZPOOL_PROP_DELEGATION,
163 ZPOOL_PROP_AUTOREPLACE,
164 ZPOOL_PROP_CACHEFILE,
165 ZPOOL_PROP_FAILUREMODE,
166 ZPOOL_PROP_LISTSNAPS,
167 ZPOOL_PROP_AUTOEXPAND,
168 ZPOOL_PROP_DEDUPDITTO,
169 ZPOOL_PROP_DEDUPRATIO,
171 ZPOOL_PROP_ALLOCATED,
179 /* Small enough to not hog a whole line of printout in zpool(1M). */
180 #define ZPROP_MAX_COMMENT 32
182 #define ZPROP_CONT -2
183 #define ZPROP_INVAL -1
185 #define ZPROP_VALUE "value"
186 #define ZPROP_SOURCE "source"
189 ZPROP_SRC_NONE = 0x1,
190 ZPROP_SRC_DEFAULT = 0x2,
191 ZPROP_SRC_TEMPORARY = 0x4,
192 ZPROP_SRC_LOCAL = 0x8,
193 ZPROP_SRC_INHERITED = 0x10,
194 ZPROP_SRC_RECEIVED = 0x20
197 #define ZPROP_SRC_ALL 0x3f
199 #define ZPROP_SOURCE_VAL_RECVD "$recvd"
200 #define ZPROP_N_MORE_ERRORS "N_MORE_ERRORS"
202 * Dataset flag implemented as a special entry in the props zap object
203 * indicating that the dataset has received properties on or after
204 * SPA_VERSION_RECVD_PROPS. The first such receive blows away local properties
205 * just as it did in earlier versions, and thereafter, local properties are
208 #define ZPROP_HAS_RECVD "$hasrecvd"
211 ZPROP_ERR_NOCLEAR = 0x1, /* failure to clear existing props */
212 ZPROP_ERR_NORESTORE = 0x2 /* failure to restore props on error */
215 typedef int (*zprop_func)(int, void *);
218 * Properties to be set on the root file system of a new pool
219 * are stuffed into their own nvlist, which is then included in
220 * the properties nvlist with the pool properties.
222 #define ZPOOL_ROOTFS_PROPS "root-props-nvl"
225 * Dataset property functions shared between libzfs and kernel.
227 const char *zfs_prop_default_string(zfs_prop_t);
228 uint64_t zfs_prop_default_numeric(zfs_prop_t);
229 boolean_t zfs_prop_readonly(zfs_prop_t);
230 boolean_t zfs_prop_inheritable(zfs_prop_t);
231 boolean_t zfs_prop_setonce(zfs_prop_t);
232 const char *zfs_prop_to_name(zfs_prop_t);
233 zfs_prop_t zfs_name_to_prop(const char *);
234 boolean_t zfs_prop_user(const char *);
235 boolean_t zfs_prop_userquota(const char *);
236 int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
237 int zfs_prop_string_to_index(zfs_prop_t, const char *, uint64_t *);
238 uint64_t zfs_prop_random_value(zfs_prop_t, uint64_t seed);
239 boolean_t zfs_prop_valid_for_type(int, zfs_type_t);
242 * Pool property functions shared between libzfs and kernel.
244 zpool_prop_t zpool_name_to_prop(const char *);
245 const char *zpool_prop_to_name(zpool_prop_t);
246 const char *zpool_prop_default_string(zpool_prop_t);
247 uint64_t zpool_prop_default_numeric(zpool_prop_t);
248 boolean_t zpool_prop_readonly(zpool_prop_t);
249 boolean_t zpool_prop_feature(const char *);
250 boolean_t zpool_prop_unsupported(const char *name);
251 int zpool_prop_index_to_string(zpool_prop_t, uint64_t, const char **);
252 int zpool_prop_string_to_index(zpool_prop_t, const char *, uint64_t *);
253 uint64_t zpool_prop_random_value(zpool_prop_t, uint64_t seed);
256 * Definitions for the Delegation.
259 ZFS_DELEG_WHO_UNKNOWN = 0,
260 ZFS_DELEG_USER = 'u',
261 ZFS_DELEG_USER_SETS = 'U',
262 ZFS_DELEG_GROUP = 'g',
263 ZFS_DELEG_GROUP_SETS = 'G',
264 ZFS_DELEG_EVERYONE = 'e',
265 ZFS_DELEG_EVERYONE_SETS = 'E',
266 ZFS_DELEG_CREATE = 'c',
267 ZFS_DELEG_CREATE_SETS = 'C',
268 ZFS_DELEG_NAMED_SET = 's',
269 ZFS_DELEG_NAMED_SET_SETS = 'S'
270 } zfs_deleg_who_type_t;
274 ZFS_DELEG_PERM_LOCAL = 1,
275 ZFS_DELEG_PERM_DESCENDENT = 2,
276 ZFS_DELEG_PERM_LOCALDESCENDENT = 3,
277 ZFS_DELEG_PERM_CREATE = 4
278 } zfs_deleg_inherit_t;
280 #define ZFS_DELEG_PERM_UID "uid"
281 #define ZFS_DELEG_PERM_GID "gid"
282 #define ZFS_DELEG_PERM_GROUPS "groups"
284 #define ZFS_MLSLABEL_DEFAULT "none"
286 #define ZFS_SMB_ACL_SRC "src"
287 #define ZFS_SMB_ACL_TARGET "target"
290 ZFS_CANMOUNT_OFF = 0,
292 ZFS_CANMOUNT_NOAUTO = 2
293 } zfs_canmount_type_t;
296 ZFS_LOGBIAS_LATENCY = 0,
297 ZFS_LOGBIAS_THROUGHPUT = 1
300 typedef enum zfs_share_op {
307 typedef enum zfs_smb_acl_op {
314 typedef enum zfs_cache_type {
316 ZFS_CACHE_METADATA = 1,
321 ZFS_SYNC_STANDARD = 0,
323 ZFS_SYNC_DISABLED = 2
328 * On-disk version number.
330 #define SPA_VERSION_1 1ULL
331 #define SPA_VERSION_2 2ULL
332 #define SPA_VERSION_3 3ULL
333 #define SPA_VERSION_4 4ULL
334 #define SPA_VERSION_5 5ULL
335 #define SPA_VERSION_6 6ULL
336 #define SPA_VERSION_7 7ULL
337 #define SPA_VERSION_8 8ULL
338 #define SPA_VERSION_9 9ULL
339 #define SPA_VERSION_10 10ULL
340 #define SPA_VERSION_11 11ULL
341 #define SPA_VERSION_12 12ULL
342 #define SPA_VERSION_13 13ULL
343 #define SPA_VERSION_14 14ULL
344 #define SPA_VERSION_15 15ULL
345 #define SPA_VERSION_16 16ULL
346 #define SPA_VERSION_17 17ULL
347 #define SPA_VERSION_18 18ULL
348 #define SPA_VERSION_19 19ULL
349 #define SPA_VERSION_20 20ULL
350 #define SPA_VERSION_21 21ULL
351 #define SPA_VERSION_22 22ULL
352 #define SPA_VERSION_23 23ULL
353 #define SPA_VERSION_24 24ULL
354 #define SPA_VERSION_25 25ULL
355 #define SPA_VERSION_26 26ULL
356 #define SPA_VERSION_27 27ULL
357 #define SPA_VERSION_28 28ULL
358 #define SPA_VERSION_5000 5000ULL
361 * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk
362 * format change. Go to usr/src/grub/grub-0.97/stage2/{zfs-include/, fsys_zfs*},
363 * and do the appropriate changes. Also bump the version number in
364 * usr/src/grub/capability.
366 #define SPA_VERSION SPA_VERSION_5000
367 #define SPA_VERSION_STRING "5000"
370 * Symbolic names for the changes that caused a SPA_VERSION switch.
371 * Used in the code when checking for presence or absence of a feature.
372 * Feel free to define multiple symbolic names for each version if there
373 * were multiple changes to on-disk structures during that version.
375 * NOTE: When checking the current SPA_VERSION in your code, be sure
376 * to use spa_version() since it reports the version of the
377 * last synced uberblock. Checking the in-flight version can
378 * be dangerous in some cases.
380 #define SPA_VERSION_INITIAL SPA_VERSION_1
381 #define SPA_VERSION_DITTO_BLOCKS SPA_VERSION_2
382 #define SPA_VERSION_SPARES SPA_VERSION_3
383 #define SPA_VERSION_RAIDZ2 SPA_VERSION_3
384 #define SPA_VERSION_BPOBJ_ACCOUNT SPA_VERSION_3
385 #define SPA_VERSION_RAIDZ_DEFLATE SPA_VERSION_3
386 #define SPA_VERSION_DNODE_BYTES SPA_VERSION_3
387 #define SPA_VERSION_ZPOOL_HISTORY SPA_VERSION_4
388 #define SPA_VERSION_GZIP_COMPRESSION SPA_VERSION_5
389 #define SPA_VERSION_BOOTFS SPA_VERSION_6
390 #define SPA_VERSION_SLOGS SPA_VERSION_7
391 #define SPA_VERSION_DELEGATED_PERMS SPA_VERSION_8
392 #define SPA_VERSION_FUID SPA_VERSION_9
393 #define SPA_VERSION_REFRESERVATION SPA_VERSION_9
394 #define SPA_VERSION_REFQUOTA SPA_VERSION_9
395 #define SPA_VERSION_UNIQUE_ACCURATE SPA_VERSION_9
396 #define SPA_VERSION_L2CACHE SPA_VERSION_10
397 #define SPA_VERSION_NEXT_CLONES SPA_VERSION_11
398 #define SPA_VERSION_ORIGIN SPA_VERSION_11
399 #define SPA_VERSION_DSL_SCRUB SPA_VERSION_11
400 #define SPA_VERSION_SNAP_PROPS SPA_VERSION_12
401 #define SPA_VERSION_USED_BREAKDOWN SPA_VERSION_13
402 #define SPA_VERSION_PASSTHROUGH_X SPA_VERSION_14
403 #define SPA_VERSION_USERSPACE SPA_VERSION_15
404 #define SPA_VERSION_STMF_PROP SPA_VERSION_16
405 #define SPA_VERSION_RAIDZ3 SPA_VERSION_17
406 #define SPA_VERSION_USERREFS SPA_VERSION_18
407 #define SPA_VERSION_HOLES SPA_VERSION_19
408 #define SPA_VERSION_ZLE_COMPRESSION SPA_VERSION_20
409 #define SPA_VERSION_DEDUP SPA_VERSION_21
410 #define SPA_VERSION_RECVD_PROPS SPA_VERSION_22
411 #define SPA_VERSION_SLIM_ZIL SPA_VERSION_23
412 #define SPA_VERSION_SA SPA_VERSION_24
413 #define SPA_VERSION_SCAN SPA_VERSION_25
414 #define SPA_VERSION_DIR_CLONES SPA_VERSION_26
415 #define SPA_VERSION_DEADLISTS SPA_VERSION_26
416 #define SPA_VERSION_FAST_SNAP SPA_VERSION_27
417 #define SPA_VERSION_MULTI_REPLACE SPA_VERSION_28
418 #define SPA_VERSION_BEFORE_FEATURES SPA_VERSION_28
419 #define SPA_VERSION_FEATURES SPA_VERSION_5000
421 #define SPA_VERSION_IS_SUPPORTED(v) \
422 (((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \
423 ((v) >= SPA_VERSION_FEATURES && (v) <= SPA_VERSION))
426 * ZPL version - rev'd whenever an incompatible on-disk format change
427 * occurs. This is independent of SPA/DMU/ZAP versioning. You must
428 * also update the version_table[] and help message in zfs_prop.c.
430 * When changing, be sure to teach GRUB how to read the new format!
431 * See usr/src/grub/grub-0.97/stage2/{zfs-include/,fsys_zfs*}
433 #define ZPL_VERSION_1 1ULL
434 #define ZPL_VERSION_2 2ULL
435 #define ZPL_VERSION_3 3ULL
436 #define ZPL_VERSION_4 4ULL
437 #define ZPL_VERSION_5 5ULL
438 #define ZPL_VERSION ZPL_VERSION_5
439 #define ZPL_VERSION_STRING "5"
441 #define ZPL_VERSION_INITIAL ZPL_VERSION_1
442 #define ZPL_VERSION_DIRENT_TYPE ZPL_VERSION_2
443 #define ZPL_VERSION_FUID ZPL_VERSION_3
444 #define ZPL_VERSION_NORMALIZATION ZPL_VERSION_3
445 #define ZPL_VERSION_SYSATTR ZPL_VERSION_3
446 #define ZPL_VERSION_USERSPACE ZPL_VERSION_4
447 #define ZPL_VERSION_SA ZPL_VERSION_5
449 /* Rewind request information */
450 #define ZPOOL_NO_REWIND 1 /* No policy - default behavior */
451 #define ZPOOL_NEVER_REWIND 2 /* Do not search for best txg or rewind */
452 #define ZPOOL_TRY_REWIND 4 /* Search for best txg, but do not rewind */
453 #define ZPOOL_DO_REWIND 8 /* Rewind to best txg w/in deferred frees */
454 #define ZPOOL_EXTREME_REWIND 16 /* Allow extreme measures to find best txg */
455 #define ZPOOL_REWIND_MASK 28 /* All the possible rewind bits */
456 #define ZPOOL_REWIND_POLICIES 31 /* All the possible policy bits */
458 typedef struct zpool_rewind_policy {
459 uint32_t zrp_request; /* rewind behavior requested */
460 uint64_t zrp_maxmeta; /* max acceptable meta-data errors */
461 uint64_t zrp_maxdata; /* max acceptable data errors */
462 uint64_t zrp_txg; /* specific txg to load */
463 } zpool_rewind_policy_t;
466 * The following are configuration names used in the nvlist describing a pool's
469 #define ZPOOL_CONFIG_VERSION "version"
470 #define ZPOOL_CONFIG_POOL_NAME "name"
471 #define ZPOOL_CONFIG_POOL_STATE "state"
472 #define ZPOOL_CONFIG_POOL_TXG "txg"
473 #define ZPOOL_CONFIG_POOL_GUID "pool_guid"
474 #define ZPOOL_CONFIG_CREATE_TXG "create_txg"
475 #define ZPOOL_CONFIG_TOP_GUID "top_guid"
476 #define ZPOOL_CONFIG_VDEV_TREE "vdev_tree"
477 #define ZPOOL_CONFIG_TYPE "type"
478 #define ZPOOL_CONFIG_CHILDREN "children"
479 #define ZPOOL_CONFIG_ID "id"
480 #define ZPOOL_CONFIG_GUID "guid"
481 #define ZPOOL_CONFIG_PATH "path"
482 #define ZPOOL_CONFIG_DEVID "devid"
483 #define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array"
484 #define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift"
485 #define ZPOOL_CONFIG_ASHIFT "ashift"
486 #define ZPOOL_CONFIG_ASIZE "asize"
487 #define ZPOOL_CONFIG_DTL "DTL"
488 #define ZPOOL_CONFIG_SCAN_STATS "scan_stats" /* not stored on disk */
489 #define ZPOOL_CONFIG_VDEV_STATS "vdev_stats" /* not stored on disk */
490 #define ZPOOL_CONFIG_WHOLE_DISK "whole_disk"
491 #define ZPOOL_CONFIG_ERRCOUNT "error_count"
492 #define ZPOOL_CONFIG_NOT_PRESENT "not_present"
493 #define ZPOOL_CONFIG_SPARES "spares"
494 #define ZPOOL_CONFIG_IS_SPARE "is_spare"
495 #define ZPOOL_CONFIG_NPARITY "nparity"
496 #define ZPOOL_CONFIG_HOSTID "hostid"
497 #define ZPOOL_CONFIG_HOSTNAME "hostname"
498 #define ZPOOL_CONFIG_LOADED_TIME "initial_load_time"
499 #define ZPOOL_CONFIG_UNSPARE "unspare"
500 #define ZPOOL_CONFIG_PHYS_PATH "phys_path"
501 #define ZPOOL_CONFIG_IS_LOG "is_log"
502 #define ZPOOL_CONFIG_L2CACHE "l2cache"
503 #define ZPOOL_CONFIG_HOLE_ARRAY "hole_array"
504 #define ZPOOL_CONFIG_VDEV_CHILDREN "vdev_children"
505 #define ZPOOL_CONFIG_IS_HOLE "is_hole"
506 #define ZPOOL_CONFIG_DDT_HISTOGRAM "ddt_histogram"
507 #define ZPOOL_CONFIG_DDT_OBJ_STATS "ddt_object_stats"
508 #define ZPOOL_CONFIG_DDT_STATS "ddt_stats"
509 #define ZPOOL_CONFIG_SPLIT "splitcfg"
510 #define ZPOOL_CONFIG_ORIG_GUID "orig_guid"
511 #define ZPOOL_CONFIG_SPLIT_GUID "split_guid"
512 #define ZPOOL_CONFIG_SPLIT_LIST "guid_list"
513 #define ZPOOL_CONFIG_REMOVING "removing"
514 #define ZPOOL_CONFIG_RESILVERING "resilvering"
515 #define ZPOOL_CONFIG_COMMENT "comment"
516 #define ZPOOL_CONFIG_SUSPENDED "suspended" /* not stored on disk */
517 #define ZPOOL_CONFIG_TIMESTAMP "timestamp" /* not stored on disk */
518 #define ZPOOL_CONFIG_BOOTFS "bootfs" /* not stored on disk */
519 #define ZPOOL_CONFIG_MISSING_DEVICES "missing_vdevs" /* not stored on disk */
520 #define ZPOOL_CONFIG_LOAD_INFO "load_info" /* not stored on disk */
521 #define ZPOOL_CONFIG_REWIND_INFO "rewind_info" /* not stored on disk */
522 #define ZPOOL_CONFIG_UNSUP_FEAT "unsup_feat" /* not stored on disk */
523 #define ZPOOL_CONFIG_ENABLED_FEAT "enabled_feat" /* not stored on disk */
524 #define ZPOOL_CONFIG_CAN_RDONLY "can_rdonly" /* not stored on disk */
525 #define ZPOOL_CONFIG_FEATURES_FOR_READ "features_for_read"
526 #define ZPOOL_CONFIG_FEATURE_STATS "feature_stats" /* not stored on disk */
528 * The persistent vdev state is stored as separate values rather than a single
529 * 'vdev_state' entry. This is because a device can be in multiple states, such
530 * as offline and degraded.
532 #define ZPOOL_CONFIG_OFFLINE "offline"
533 #define ZPOOL_CONFIG_FAULTED "faulted"
534 #define ZPOOL_CONFIG_DEGRADED "degraded"
535 #define ZPOOL_CONFIG_REMOVED "removed"
536 #define ZPOOL_CONFIG_FRU "fru"
537 #define ZPOOL_CONFIG_AUX_STATE "aux_state"
539 /* Rewind policy parameters */
540 #define ZPOOL_REWIND_POLICY "rewind-policy"
541 #define ZPOOL_REWIND_REQUEST "rewind-request"
542 #define ZPOOL_REWIND_REQUEST_TXG "rewind-request-txg"
543 #define ZPOOL_REWIND_META_THRESH "rewind-meta-thresh"
544 #define ZPOOL_REWIND_DATA_THRESH "rewind-data-thresh"
546 /* Rewind data discovered */
547 #define ZPOOL_CONFIG_LOAD_TIME "rewind_txg_ts"
548 #define ZPOOL_CONFIG_LOAD_DATA_ERRORS "verify_data_errors"
549 #define ZPOOL_CONFIG_REWIND_TIME "seconds_of_rewind"
551 #define VDEV_TYPE_ROOT "root"
552 #define VDEV_TYPE_MIRROR "mirror"
553 #define VDEV_TYPE_REPLACING "replacing"
554 #define VDEV_TYPE_RAIDZ "raidz"
555 #define VDEV_TYPE_DISK "disk"
556 #define VDEV_TYPE_FILE "file"
557 #define VDEV_TYPE_MISSING "missing"
558 #define VDEV_TYPE_HOLE "hole"
559 #define VDEV_TYPE_SPARE "spare"
560 #define VDEV_TYPE_LOG "log"
561 #define VDEV_TYPE_L2CACHE "l2cache"
564 * This is needed in userland to report the minimum necessary device size.
566 #define SPA_MINDEVSIZE (64ULL << 20)
569 * The location of the pool configuration repository, shared between kernel and
572 #define ZPOOL_CACHE "/boot/zfs/zpool.cache"
575 * vdev states are ordered from least to most healthy.
576 * A vdev that's CANT_OPEN or below is considered unusable.
578 typedef enum vdev_state {
579 VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev */
580 VDEV_STATE_CLOSED, /* Not currently open */
581 VDEV_STATE_OFFLINE, /* Not allowed to open */
582 VDEV_STATE_REMOVED, /* Explicitly removed from system */
583 VDEV_STATE_CANT_OPEN, /* Tried to open, but failed */
584 VDEV_STATE_FAULTED, /* External request to fault device */
585 VDEV_STATE_DEGRADED, /* Replicated vdev with unhealthy kids */
586 VDEV_STATE_HEALTHY /* Presumed good */
589 #define VDEV_STATE_ONLINE VDEV_STATE_HEALTHY
592 * vdev aux states. When a vdev is in the CANT_OPEN state, the aux field
593 * of the vdev stats structure uses these constants to distinguish why.
595 typedef enum vdev_aux {
596 VDEV_AUX_NONE, /* no error */
597 VDEV_AUX_OPEN_FAILED, /* ldi_open_*() or vn_open() failed */
598 VDEV_AUX_CORRUPT_DATA, /* bad label or disk contents */
599 VDEV_AUX_NO_REPLICAS, /* insufficient number of replicas */
600 VDEV_AUX_BAD_GUID_SUM, /* vdev guid sum doesn't match */
601 VDEV_AUX_TOO_SMALL, /* vdev size is too small */
602 VDEV_AUX_BAD_LABEL, /* the label is OK but invalid */
603 VDEV_AUX_VERSION_NEWER, /* on-disk version is too new */
604 VDEV_AUX_VERSION_OLDER, /* on-disk version is too old */
605 VDEV_AUX_UNSUP_FEAT, /* unsupported features */
606 VDEV_AUX_SPARED, /* hot spare used in another pool */
607 VDEV_AUX_ERR_EXCEEDED, /* too many errors */
608 VDEV_AUX_IO_FAILURE, /* experienced I/O failure */
609 VDEV_AUX_BAD_LOG, /* cannot read log chain(s) */
610 VDEV_AUX_EXTERNAL, /* external diagnosis */
611 VDEV_AUX_SPLIT_POOL /* vdev was split off into another pool */
615 * pool state. The following states are written to disk as part of the normal
616 * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE. The remaining
617 * states are software abstractions used at various levels to communicate
620 typedef enum pool_state {
621 POOL_STATE_ACTIVE = 0, /* In active use */
622 POOL_STATE_EXPORTED, /* Explicitly exported */
623 POOL_STATE_DESTROYED, /* Explicitly destroyed */
624 POOL_STATE_SPARE, /* Reserved for hot spare use */
625 POOL_STATE_L2CACHE, /* Level 2 ARC device */
626 POOL_STATE_UNINITIALIZED, /* Internal spa_t state */
627 POOL_STATE_UNAVAIL, /* Internal libzfs state */
628 POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */
634 typedef enum pool_scan_func {
642 * ZIO types. Needed to interpret vdev statistics below.
644 typedef enum zio_type {
655 * Pool statistics. Note: all fields should be 64-bit because this
656 * is passed between kernel and userland as an nvlist uint64 array.
658 typedef struct pool_scan_stat {
659 /* values stored on disk */
660 uint64_t pss_func; /* pool_scan_func_t */
661 uint64_t pss_state; /* dsl_scan_state_t */
662 uint64_t pss_start_time; /* scan start time */
663 uint64_t pss_end_time; /* scan end time */
664 uint64_t pss_to_examine; /* total bytes to scan */
665 uint64_t pss_examined; /* total examined bytes */
666 uint64_t pss_to_process; /* total bytes to process */
667 uint64_t pss_processed; /* total processed bytes */
668 uint64_t pss_errors; /* scan errors */
670 /* values not stored on disk */
671 uint64_t pss_pass_exam; /* examined bytes per scan pass */
672 uint64_t pss_pass_start; /* start time of a scan pass */
675 typedef enum dsl_scan_state {
685 * Vdev statistics. Note: all fields should be 64-bit because this
686 * is passed between kernel and userland as an nvlist uint64 array.
688 typedef struct vdev_stat {
689 hrtime_t vs_timestamp; /* time since vdev load */
690 uint64_t vs_state; /* vdev state */
691 uint64_t vs_aux; /* see vdev_aux_t */
692 uint64_t vs_alloc; /* space allocated */
693 uint64_t vs_space; /* total capacity */
694 uint64_t vs_dspace; /* deflated capacity */
695 uint64_t vs_rsize; /* replaceable dev size */
696 uint64_t vs_esize; /* expandable dev size */
697 uint64_t vs_ops[ZIO_TYPES]; /* operation count */
698 uint64_t vs_bytes[ZIO_TYPES]; /* bytes read/written */
699 uint64_t vs_read_errors; /* read errors */
700 uint64_t vs_write_errors; /* write errors */
701 uint64_t vs_checksum_errors; /* checksum errors */
702 uint64_t vs_self_healed; /* self-healed bytes */
703 uint64_t vs_scan_removing; /* removing? */
704 uint64_t vs_scan_processed; /* scan processed bytes */
708 * DDT statistics. Note: all fields should be 64-bit because this
709 * is passed between kernel and userland as an nvlist uint64 array.
711 typedef struct ddt_object {
712 uint64_t ddo_count; /* number of elments in ddt */
713 uint64_t ddo_dspace; /* size of ddt on disk */
714 uint64_t ddo_mspace; /* size of ddt in-core */
717 typedef struct ddt_stat {
718 uint64_t dds_blocks; /* blocks */
719 uint64_t dds_lsize; /* logical size */
720 uint64_t dds_psize; /* physical size */
721 uint64_t dds_dsize; /* deflated allocated size */
722 uint64_t dds_ref_blocks; /* referenced blocks */
723 uint64_t dds_ref_lsize; /* referenced lsize * refcnt */
724 uint64_t dds_ref_psize; /* referenced psize * refcnt */
725 uint64_t dds_ref_dsize; /* referenced dsize * refcnt */
728 typedef struct ddt_histogram {
729 ddt_stat_t ddh_stat[64]; /* power-of-two histogram buckets */
732 #define ZVOL_DRIVER "zvol"
733 #define ZFS_DRIVER "zfs"
734 #define ZFS_DEV_NAME "zfs"
735 #define ZFS_DEV "/dev/" ZFS_DEV_NAME
737 /* general zvol path */
738 #define ZVOL_DIR "/dev/zvol"
740 #define ZVOL_PSEUDO_DEV "/devices/pseudo/zfs@0:"
741 /* for dump and swap */
742 #define ZVOL_FULL_DEV_DIR ZVOL_DIR "/dsk/"
743 #define ZVOL_FULL_RDEV_DIR ZVOL_DIR "/rdsk/"
745 #define ZVOL_PROP_NAME "name"
746 #define ZVOL_DEFAULT_BLOCKSIZE 8192
749 * /dev/zfs ioctl numbers.
751 typedef unsigned long zfs_ioc_t;
753 #define ZFS_IOC(ioreq) ((ioreq) & 0xff)
755 #define ZFS_IOC_POOL_CREATE _IOWR('Z', 0, struct zfs_cmd)
756 #define ZFS_IOC_POOL_DESTROY _IOWR('Z', 1, struct zfs_cmd)
757 #define ZFS_IOC_POOL_IMPORT _IOWR('Z', 2, struct zfs_cmd)
758 #define ZFS_IOC_POOL_EXPORT _IOWR('Z', 3, struct zfs_cmd)
759 #define ZFS_IOC_POOL_CONFIGS _IOWR('Z', 4, struct zfs_cmd)
760 #define ZFS_IOC_POOL_STATS _IOWR('Z', 5, struct zfs_cmd)
761 #define ZFS_IOC_POOL_TRYIMPORT _IOWR('Z', 6, struct zfs_cmd)
762 #define ZFS_IOC_POOL_SCAN _IOWR('Z', 7, struct zfs_cmd)
763 #define ZFS_IOC_POOL_FREEZE _IOWR('Z', 8, struct zfs_cmd)
764 #define ZFS_IOC_POOL_UPGRADE _IOWR('Z', 9, struct zfs_cmd)
765 #define ZFS_IOC_POOL_GET_HISTORY _IOWR('Z', 10, struct zfs_cmd)
766 #define ZFS_IOC_VDEV_ADD _IOWR('Z', 11, struct zfs_cmd)
767 #define ZFS_IOC_VDEV_REMOVE _IOWR('Z', 12, struct zfs_cmd)
768 #define ZFS_IOC_VDEV_SET_STATE _IOWR('Z', 13, struct zfs_cmd)
769 #define ZFS_IOC_VDEV_ATTACH _IOWR('Z', 14, struct zfs_cmd)
770 #define ZFS_IOC_VDEV_DETACH _IOWR('Z', 15, struct zfs_cmd)
771 #define ZFS_IOC_VDEV_SETPATH _IOWR('Z', 16, struct zfs_cmd)
772 #define ZFS_IOC_VDEV_SETFRU _IOWR('Z', 17, struct zfs_cmd)
773 #define ZFS_IOC_OBJSET_STATS _IOWR('Z', 18, struct zfs_cmd)
774 #define ZFS_IOC_OBJSET_ZPLPROPS _IOWR('Z', 19, struct zfs_cmd)
775 #define ZFS_IOC_DATASET_LIST_NEXT _IOWR('Z', 20, struct zfs_cmd)
776 #define ZFS_IOC_SNAPSHOT_LIST_NEXT _IOWR('Z', 21, struct zfs_cmd)
777 #define ZFS_IOC_SET_PROP _IOWR('Z', 22, struct zfs_cmd)
778 #define ZFS_IOC_CREATE _IOWR('Z', 23, struct zfs_cmd)
779 #define ZFS_IOC_DESTROY _IOWR('Z', 24, struct zfs_cmd)
780 #define ZFS_IOC_ROLLBACK _IOWR('Z', 25, struct zfs_cmd)
781 #define ZFS_IOC_RENAME _IOWR('Z', 26, struct zfs_cmd)
782 #define ZFS_IOC_RECV _IOWR('Z', 27, struct zfs_cmd)
783 #define ZFS_IOC_SEND _IOWR('Z', 28, struct zfs_cmd)
784 #define ZFS_IOC_INJECT_FAULT _IOWR('Z', 29, struct zfs_cmd)
785 #define ZFS_IOC_CLEAR_FAULT _IOWR('Z', 30, struct zfs_cmd)
786 #define ZFS_IOC_INJECT_LIST_NEXT _IOWR('Z', 31, struct zfs_cmd)
787 #define ZFS_IOC_ERROR_LOG _IOWR('Z', 32, struct zfs_cmd)
788 #define ZFS_IOC_CLEAR _IOWR('Z', 33, struct zfs_cmd)
789 #define ZFS_IOC_PROMOTE _IOWR('Z', 34, struct zfs_cmd)
790 #define ZFS_IOC_DESTROY_SNAPS_NVL _IOWR('Z', 35, struct zfs_cmd)
791 #define ZFS_IOC_SNAPSHOT _IOWR('Z', 36, struct zfs_cmd)
792 #define ZFS_IOC_DSOBJ_TO_DSNAME _IOWR('Z', 37, struct zfs_cmd)
793 #define ZFS_IOC_OBJ_TO_PATH _IOWR('Z', 38, struct zfs_cmd)
794 #define ZFS_IOC_POOL_SET_PROPS _IOWR('Z', 39, struct zfs_cmd)
795 #define ZFS_IOC_POOL_GET_PROPS _IOWR('Z', 40, struct zfs_cmd)
796 #define ZFS_IOC_SET_FSACL _IOWR('Z', 41, struct zfs_cmd)
797 #define ZFS_IOC_GET_FSACL _IOWR('Z', 42, struct zfs_cmd)
798 #define ZFS_IOC_SHARE _IOWR('Z', 43, struct zfs_cmd)
799 #define ZFS_IOC_INHERIT_PROP _IOWR('Z', 44, struct zfs_cmd)
800 #define ZFS_IOC_SMB_ACL _IOWR('Z', 45, struct zfs_cmd)
801 #define ZFS_IOC_USERSPACE_ONE _IOWR('Z', 46, struct zfs_cmd)
802 #define ZFS_IOC_USERSPACE_MANY _IOWR('Z', 47, struct zfs_cmd)
803 #define ZFS_IOC_USERSPACE_UPGRADE _IOWR('Z', 48, struct zfs_cmd)
804 #define ZFS_IOC_HOLD _IOWR('Z', 49, struct zfs_cmd)
805 #define ZFS_IOC_RELEASE _IOWR('Z', 50, struct zfs_cmd)
806 #define ZFS_IOC_GET_HOLDS _IOWR('Z', 51, struct zfs_cmd)
807 #define ZFS_IOC_OBJSET_RECVD_PROPS _IOWR('Z', 52, struct zfs_cmd)
808 #define ZFS_IOC_VDEV_SPLIT _IOWR('Z', 53, struct zfs_cmd)
809 #define ZFS_IOC_NEXT_OBJ _IOWR('Z', 54, struct zfs_cmd)
810 #define ZFS_IOC_DIFF _IOWR('Z', 55, struct zfs_cmd)
811 #define ZFS_IOC_TMP_SNAPSHOT _IOWR('Z', 56, struct zfs_cmd)
812 #define ZFS_IOC_OBJ_TO_STATS _IOWR('Z', 57, struct zfs_cmd)
813 #define ZFS_IOC_JAIL _IOWR('Z', 58, struct zfs_cmd)
814 #define ZFS_IOC_UNJAIL _IOWR('Z', 59, struct zfs_cmd)
815 #define ZFS_IOC_POOL_REGUID _IOWR('Z', 60, struct zfs_cmd)
816 #define ZFS_IOC_SPACE_WRITTEN _IOWR('Z', 61, struct zfs_cmd)
817 #define ZFS_IOC_SPACE_SNAPS _IOWR('Z', 62, struct zfs_cmd)
818 #define ZFS_IOC_SEND_PROGRESS _IOWR('Z', 63, struct zfs_cmd)
819 #define ZFS_IOC_POOL_REOPEN _IOWR('Z', 64, struct zfs_cmd)
822 * Internal SPA load state. Used by FMA diagnosis engine.
825 SPA_LOAD_NONE, /* no load in progress */
826 SPA_LOAD_OPEN, /* normal open */
827 SPA_LOAD_IMPORT, /* import in progress */
828 SPA_LOAD_TRYIMPORT, /* tryimport in progress */
829 SPA_LOAD_RECOVER, /* recovery requested */
830 SPA_LOAD_ERROR /* load failed */
834 * Bookmark name values.
836 #define ZPOOL_ERR_LIST "error list"
837 #define ZPOOL_ERR_DATASET "dataset"
838 #define ZPOOL_ERR_OBJECT "object"
840 #define HIS_MAX_RECORD_LEN (MAXPATHLEN + MAXPATHLEN + 1)
843 * The following are names used in the nvlist describing
844 * the pool's history log.
846 #define ZPOOL_HIST_RECORD "history record"
847 #define ZPOOL_HIST_TIME "history time"
848 #define ZPOOL_HIST_CMD "history command"
849 #define ZPOOL_HIST_WHO "history who"
850 #define ZPOOL_HIST_ZONE "history zone"
851 #define ZPOOL_HIST_HOST "history hostname"
852 #define ZPOOL_HIST_TXG "history txg"
853 #define ZPOOL_HIST_INT_EVENT "history internal event"
854 #define ZPOOL_HIST_INT_STR "history internal str"
857 * Flags for ZFS_IOC_VDEV_SET_STATE
859 #define ZFS_ONLINE_CHECKREMOVE 0x1
860 #define ZFS_ONLINE_UNSPARE 0x2
861 #define ZFS_ONLINE_FORCEFAULT 0x4
862 #define ZFS_ONLINE_EXPAND 0x8
863 #define ZFS_OFFLINE_TEMPORARY 0x1
866 * Flags for ZFS_IOC_POOL_IMPORT
868 #define ZFS_IMPORT_NORMAL 0x0
869 #define ZFS_IMPORT_VERBATIM 0x1
870 #define ZFS_IMPORT_ANY_HOST 0x2
871 #define ZFS_IMPORT_MISSING_LOG 0x4
872 #define ZFS_IMPORT_ONLY 0x8
875 * Sysevent payload members. ZFS will generate the following sysevents with the
878 * ESC_ZFS_RESILVER_START
879 * ESC_ZFS_RESILVER_END
880 * ESC_ZFS_POOL_DESTROY
881 * ESC_ZFS_POOL_REGUID
883 * ZFS_EV_POOL_NAME DATA_TYPE_STRING
884 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64
886 * ESC_ZFS_VDEV_REMOVE
890 * ZFS_EV_POOL_NAME DATA_TYPE_STRING
891 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64
892 * ZFS_EV_VDEV_PATH DATA_TYPE_STRING (optional)
893 * ZFS_EV_VDEV_GUID DATA_TYPE_UINT64
895 #define ZFS_EV_POOL_NAME "pool_name"
896 #define ZFS_EV_POOL_GUID "pool_guid"
897 #define ZFS_EV_VDEV_PATH "vdev_path"
898 #define ZFS_EV_VDEV_GUID "vdev_guid"
901 * Note: This is encoded on-disk, so new events must be added to the
902 * end, and unused events can not be removed. Be sure to edit
903 * libzfs_pool.c: hist_event_table[].
905 typedef enum history_internal_events {
913 LOG_POOL_VDEV_ATTACH,
914 LOG_POOL_VDEV_REPLACE,
915 LOG_POOL_VDEV_DETACH,
916 LOG_POOL_VDEV_ONLINE,
917 LOG_POOL_VDEV_OFFLINE,
925 LOG_DS_DESTROY_BEGIN,
931 LOG_DS_PERM_WHO_REMOVE,
936 LOG_DS_REPLAY_INC_SYNC,
937 LOG_DS_REPLAY_FULL_SYNC,
948 } history_internal_events_t;
954 #endif /* _SYS_FS_ZFS_H */