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) 2011, 2016 by Delphix. All rights reserved.
25 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
26 * Copyright (c) 2012, Martin Matuska <mm@FreeBSD.org>. All rights reserved.
27 * Copyright (c) 2014 Integros [integros.com]
28 * Copyright 2017 Joyent, Inc.
29 * Copyright (c) 2017 Datto Inc.
32 /* Portions Copyright 2010 Robert Milkowski */
37 #include <sys/types.h>
38 #include <sys/ioccom.h>
46 * Types and constants shared between userland and the kernel.
50 * Each dataset can be one of the following types. These constants can be
51 * combined into masks that can be passed to various functions.
54 ZFS_TYPE_FILESYSTEM = (1 << 0),
55 ZFS_TYPE_SNAPSHOT = (1 << 1),
56 ZFS_TYPE_VOLUME = (1 << 2),
57 ZFS_TYPE_POOL = (1 << 3),
58 ZFS_TYPE_BOOKMARK = (1 << 4)
62 * NB: lzc_dataset_type should be updated whenever a new objset type is added,
63 * if it represents a real type of a dataset that can be created from userland.
65 typedef enum dmu_objset_type {
70 DMU_OST_OTHER, /* For testing only! */
71 DMU_OST_ANY, /* Be careful! */
75 #define ZFS_TYPE_DATASET \
76 (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME | ZFS_TYPE_SNAPSHOT)
79 * All of these include the terminating NUL byte.
81 #define ZAP_MAXNAMELEN 256
82 #define ZAP_MAXVALUELEN (1024 * 8)
83 #define ZAP_OLDMAXVALUELEN 1024
84 #define ZFS_MAX_DATASET_NAME_LEN 256
87 * Dataset properties are identified by these constants and must be added to
88 * the end of this list to ensure that external consumers are not affected
89 * by the change. If you make any changes to this list, be sure to update
90 * the property table in usr/src/common/zfs/zfs_prop.c.
100 ZFS_PROP_COMPRESSRATIO,
104 ZFS_PROP_RESERVATION,
106 ZFS_PROP_VOLBLOCKSIZE,
111 ZFS_PROP_COMPRESSION,
121 ZFS_PROP_CREATETXG, /* not exposed to the user */
122 ZFS_PROP_NAME, /* not exposed to the user */
124 ZFS_PROP_ISCSIOPTIONS, /* not exposed to the user */
126 ZFS_PROP_NUMCLONES, /* not exposed to the user */
136 ZFS_PROP_REFRESERVATION,
138 ZFS_PROP_PRIMARYCACHE,
139 ZFS_PROP_SECONDARYCACHE,
143 ZFS_PROP_USEDREFRESERV,
144 ZFS_PROP_USERACCOUNTING, /* not exposed to the user */
145 ZFS_PROP_STMF_SHAREINFO, /* not exposed to the user */
146 ZFS_PROP_DEFER_DESTROY,
149 ZFS_PROP_UNIQUE, /* not exposed to the user */
150 ZFS_PROP_OBJSETID, /* not exposed to the user */
157 ZFS_PROP_LOGICALUSED,
158 ZFS_PROP_LOGICALREFERENCED,
159 ZFS_PROP_INCONSISTENT, /* not exposed to the user */
161 ZFS_PROP_FILESYSTEM_LIMIT,
162 ZFS_PROP_SNAPSHOT_LIMIT,
163 ZFS_PROP_FILESYSTEM_COUNT,
164 ZFS_PROP_SNAPSHOT_COUNT,
165 ZFS_PROP_REDUNDANT_METADATA,
167 ZFS_PROP_RECEIVE_RESUME_TOKEN,
168 ZFS_PROP_REMAPTXG, /* not exposed to the user */
177 ZFS_NUM_USERQUOTA_PROPS
178 } zfs_userquota_prop_t;
180 extern const char *zfs_userquota_prop_prefixes[ZFS_NUM_USERQUOTA_PROPS];
183 * Pool properties are identified by these constants and must be added to the
184 * end of this list to ensure that external consumers are not affected
185 * by the change. If you make any changes to this list, be sure to update
186 * the property table in usr/src/common/zfs/zpool_prop.c.
189 ZPOOL_PROP_INVAL = -1,
198 ZPOOL_PROP_DELEGATION,
199 ZPOOL_PROP_AUTOREPLACE,
200 ZPOOL_PROP_CACHEFILE,
201 ZPOOL_PROP_FAILUREMODE,
202 ZPOOL_PROP_LISTSNAPS,
203 ZPOOL_PROP_AUTOEXPAND,
204 ZPOOL_PROP_DEDUPDITTO,
205 ZPOOL_PROP_DEDUPRATIO,
207 ZPOOL_PROP_ALLOCATED,
212 ZPOOL_PROP_FRAGMENTATION,
214 ZPOOL_PROP_MAXBLOCKSIZE,
216 ZPOOL_PROP_CHECKPOINT,
221 /* Small enough to not hog a whole line of printout in zpool(1M). */
222 #define ZPROP_MAX_COMMENT 32
224 #define ZPROP_VALUE "value"
225 #define ZPROP_SOURCE "source"
228 ZPROP_SRC_NONE = 0x1,
229 ZPROP_SRC_DEFAULT = 0x2,
230 ZPROP_SRC_TEMPORARY = 0x4,
231 ZPROP_SRC_LOCAL = 0x8,
232 ZPROP_SRC_INHERITED = 0x10,
233 ZPROP_SRC_RECEIVED = 0x20
236 #define ZPROP_SRC_ALL 0x3f
238 #define ZPROP_SOURCE_VAL_RECVD "$recvd"
239 #define ZPROP_N_MORE_ERRORS "N_MORE_ERRORS"
241 * Dataset flag implemented as a special entry in the props zap object
242 * indicating that the dataset has received properties on or after
243 * SPA_VERSION_RECVD_PROPS. The first such receive blows away local properties
244 * just as it did in earlier versions, and thereafter, local properties are
247 #define ZPROP_HAS_RECVD "$hasrecvd"
250 ZPROP_ERR_NOCLEAR = 0x1, /* failure to clear existing props */
251 ZPROP_ERR_NORESTORE = 0x2 /* failure to restore props on error */
254 typedef int (*zprop_func)(int, void *);
257 * Properties to be set on the root file system of a new pool
258 * are stuffed into their own nvlist, which is then included in
259 * the properties nvlist with the pool properties.
261 #define ZPOOL_ROOTFS_PROPS "root-props-nvl"
264 * Length of 'written@' and 'written#'
266 #define ZFS_WRITTEN_PROP_PREFIX_LEN 8
269 * Dataset property functions shared between libzfs and kernel.
271 const char *zfs_prop_default_string(zfs_prop_t);
272 uint64_t zfs_prop_default_numeric(zfs_prop_t);
273 boolean_t zfs_prop_readonly(zfs_prop_t);
274 boolean_t zfs_prop_visible(zfs_prop_t prop);
275 boolean_t zfs_prop_inheritable(zfs_prop_t);
276 boolean_t zfs_prop_setonce(zfs_prop_t);
277 const char *zfs_prop_to_name(zfs_prop_t);
278 zfs_prop_t zfs_name_to_prop(const char *);
279 boolean_t zfs_prop_user(const char *);
280 boolean_t zfs_prop_userquota(const char *);
281 int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
282 int zfs_prop_string_to_index(zfs_prop_t, const char *, uint64_t *);
283 uint64_t zfs_prop_random_value(zfs_prop_t, uint64_t seed);
284 boolean_t zfs_prop_valid_for_type(int, zfs_type_t);
287 * Pool property functions shared between libzfs and kernel.
289 zpool_prop_t zpool_name_to_prop(const char *);
290 const char *zpool_prop_to_name(zpool_prop_t);
291 const char *zpool_prop_default_string(zpool_prop_t);
292 uint64_t zpool_prop_default_numeric(zpool_prop_t);
293 boolean_t zpool_prop_readonly(zpool_prop_t);
294 boolean_t zpool_prop_feature(const char *);
295 boolean_t zpool_prop_unsupported(const char *name);
296 int zpool_prop_index_to_string(zpool_prop_t, uint64_t, const char **);
297 int zpool_prop_string_to_index(zpool_prop_t, const char *, uint64_t *);
298 uint64_t zpool_prop_random_value(zpool_prop_t, uint64_t seed);
301 * Definitions for the Delegation.
304 ZFS_DELEG_WHO_UNKNOWN = 0,
305 ZFS_DELEG_USER = 'u',
306 ZFS_DELEG_USER_SETS = 'U',
307 ZFS_DELEG_GROUP = 'g',
308 ZFS_DELEG_GROUP_SETS = 'G',
309 ZFS_DELEG_EVERYONE = 'e',
310 ZFS_DELEG_EVERYONE_SETS = 'E',
311 ZFS_DELEG_CREATE = 'c',
312 ZFS_DELEG_CREATE_SETS = 'C',
313 ZFS_DELEG_NAMED_SET = 's',
314 ZFS_DELEG_NAMED_SET_SETS = 'S'
315 } zfs_deleg_who_type_t;
319 ZFS_DELEG_PERM_LOCAL = 1,
320 ZFS_DELEG_PERM_DESCENDENT = 2,
321 ZFS_DELEG_PERM_LOCALDESCENDENT = 3,
322 ZFS_DELEG_PERM_CREATE = 4
323 } zfs_deleg_inherit_t;
325 #define ZFS_DELEG_PERM_UID "uid"
326 #define ZFS_DELEG_PERM_GID "gid"
327 #define ZFS_DELEG_PERM_GROUPS "groups"
329 #define ZFS_MLSLABEL_DEFAULT "none"
331 #define ZFS_SMB_ACL_SRC "src"
332 #define ZFS_SMB_ACL_TARGET "target"
335 ZFS_CANMOUNT_OFF = 0,
337 ZFS_CANMOUNT_NOAUTO = 2
338 } zfs_canmount_type_t;
341 ZFS_LOGBIAS_LATENCY = 0,
342 ZFS_LOGBIAS_THROUGHPUT = 1
345 typedef enum zfs_share_op {
352 typedef enum zfs_smb_acl_op {
359 typedef enum zfs_cache_type {
361 ZFS_CACHE_METADATA = 1,
366 ZFS_SYNC_STANDARD = 0,
368 ZFS_SYNC_DISABLED = 2
372 ZFS_VOLMODE_DEFAULT = 0,
373 ZFS_VOLMODE_GEOM = 1,
379 ZFS_REDUNDANT_METADATA_ALL,
380 ZFS_REDUNDANT_METADATA_MOST
381 } zfs_redundant_metadata_type_t;
384 * On-disk version number.
386 #define SPA_VERSION_1 1ULL
387 #define SPA_VERSION_2 2ULL
388 #define SPA_VERSION_3 3ULL
389 #define SPA_VERSION_4 4ULL
390 #define SPA_VERSION_5 5ULL
391 #define SPA_VERSION_6 6ULL
392 #define SPA_VERSION_7 7ULL
393 #define SPA_VERSION_8 8ULL
394 #define SPA_VERSION_9 9ULL
395 #define SPA_VERSION_10 10ULL
396 #define SPA_VERSION_11 11ULL
397 #define SPA_VERSION_12 12ULL
398 #define SPA_VERSION_13 13ULL
399 #define SPA_VERSION_14 14ULL
400 #define SPA_VERSION_15 15ULL
401 #define SPA_VERSION_16 16ULL
402 #define SPA_VERSION_17 17ULL
403 #define SPA_VERSION_18 18ULL
404 #define SPA_VERSION_19 19ULL
405 #define SPA_VERSION_20 20ULL
406 #define SPA_VERSION_21 21ULL
407 #define SPA_VERSION_22 22ULL
408 #define SPA_VERSION_23 23ULL
409 #define SPA_VERSION_24 24ULL
410 #define SPA_VERSION_25 25ULL
411 #define SPA_VERSION_26 26ULL
412 #define SPA_VERSION_27 27ULL
413 #define SPA_VERSION_28 28ULL
414 #define SPA_VERSION_5000 5000ULL
417 * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk
418 * format change. Go to usr/src/grub/grub-0.97/stage2/{zfs-include/, fsys_zfs*},
419 * and do the appropriate changes. Also bump the version number in
420 * usr/src/grub/capability.
422 #define SPA_VERSION SPA_VERSION_5000
423 #define SPA_VERSION_STRING "5000"
426 * Symbolic names for the changes that caused a SPA_VERSION switch.
427 * Used in the code when checking for presence or absence of a feature.
428 * Feel free to define multiple symbolic names for each version if there
429 * were multiple changes to on-disk structures during that version.
431 * NOTE: When checking the current SPA_VERSION in your code, be sure
432 * to use spa_version() since it reports the version of the
433 * last synced uberblock. Checking the in-flight version can
434 * be dangerous in some cases.
436 #define SPA_VERSION_INITIAL SPA_VERSION_1
437 #define SPA_VERSION_DITTO_BLOCKS SPA_VERSION_2
438 #define SPA_VERSION_SPARES SPA_VERSION_3
439 #define SPA_VERSION_RAIDZ2 SPA_VERSION_3
440 #define SPA_VERSION_BPOBJ_ACCOUNT SPA_VERSION_3
441 #define SPA_VERSION_RAIDZ_DEFLATE SPA_VERSION_3
442 #define SPA_VERSION_DNODE_BYTES SPA_VERSION_3
443 #define SPA_VERSION_ZPOOL_HISTORY SPA_VERSION_4
444 #define SPA_VERSION_GZIP_COMPRESSION SPA_VERSION_5
445 #define SPA_VERSION_BOOTFS SPA_VERSION_6
446 #define SPA_VERSION_SLOGS SPA_VERSION_7
447 #define SPA_VERSION_DELEGATED_PERMS SPA_VERSION_8
448 #define SPA_VERSION_FUID SPA_VERSION_9
449 #define SPA_VERSION_REFRESERVATION SPA_VERSION_9
450 #define SPA_VERSION_REFQUOTA SPA_VERSION_9
451 #define SPA_VERSION_UNIQUE_ACCURATE SPA_VERSION_9
452 #define SPA_VERSION_L2CACHE SPA_VERSION_10
453 #define SPA_VERSION_NEXT_CLONES SPA_VERSION_11
454 #define SPA_VERSION_ORIGIN SPA_VERSION_11
455 #define SPA_VERSION_DSL_SCRUB SPA_VERSION_11
456 #define SPA_VERSION_SNAP_PROPS SPA_VERSION_12
457 #define SPA_VERSION_USED_BREAKDOWN SPA_VERSION_13
458 #define SPA_VERSION_PASSTHROUGH_X SPA_VERSION_14
459 #define SPA_VERSION_USERSPACE SPA_VERSION_15
460 #define SPA_VERSION_STMF_PROP SPA_VERSION_16
461 #define SPA_VERSION_RAIDZ3 SPA_VERSION_17
462 #define SPA_VERSION_USERREFS SPA_VERSION_18
463 #define SPA_VERSION_HOLES SPA_VERSION_19
464 #define SPA_VERSION_ZLE_COMPRESSION SPA_VERSION_20
465 #define SPA_VERSION_DEDUP SPA_VERSION_21
466 #define SPA_VERSION_RECVD_PROPS SPA_VERSION_22
467 #define SPA_VERSION_SLIM_ZIL SPA_VERSION_23
468 #define SPA_VERSION_SA SPA_VERSION_24
469 #define SPA_VERSION_SCAN SPA_VERSION_25
470 #define SPA_VERSION_DIR_CLONES SPA_VERSION_26
471 #define SPA_VERSION_DEADLISTS SPA_VERSION_26
472 #define SPA_VERSION_FAST_SNAP SPA_VERSION_27
473 #define SPA_VERSION_MULTI_REPLACE SPA_VERSION_28
474 #define SPA_VERSION_BEFORE_FEATURES SPA_VERSION_28
475 #define SPA_VERSION_FEATURES SPA_VERSION_5000
477 #define SPA_VERSION_IS_SUPPORTED(v) \
478 (((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \
479 ((v) >= SPA_VERSION_FEATURES && (v) <= SPA_VERSION))
482 * ZPL version - rev'd whenever an incompatible on-disk format change
483 * occurs. This is independent of SPA/DMU/ZAP versioning. You must
484 * also update the version_table[] and help message in zfs_prop.c.
486 * When changing, be sure to teach GRUB how to read the new format!
487 * See usr/src/grub/grub-0.97/stage2/{zfs-include/,fsys_zfs*}
489 #define ZPL_VERSION_1 1ULL
490 #define ZPL_VERSION_2 2ULL
491 #define ZPL_VERSION_3 3ULL
492 #define ZPL_VERSION_4 4ULL
493 #define ZPL_VERSION_5 5ULL
494 #define ZPL_VERSION ZPL_VERSION_5
495 #define ZPL_VERSION_STRING "5"
497 #define ZPL_VERSION_INITIAL ZPL_VERSION_1
498 #define ZPL_VERSION_DIRENT_TYPE ZPL_VERSION_2
499 #define ZPL_VERSION_FUID ZPL_VERSION_3
500 #define ZPL_VERSION_NORMALIZATION ZPL_VERSION_3
501 #define ZPL_VERSION_SYSATTR ZPL_VERSION_3
502 #define ZPL_VERSION_USERSPACE ZPL_VERSION_4
503 #define ZPL_VERSION_SA ZPL_VERSION_5
505 /* Rewind policy information */
506 #define ZPOOL_NO_REWIND 1 /* No policy - default behavior */
507 #define ZPOOL_NEVER_REWIND 2 /* Do not search for best txg or rewind */
508 #define ZPOOL_TRY_REWIND 4 /* Search for best txg, but do not rewind */
509 #define ZPOOL_DO_REWIND 8 /* Rewind to best txg w/in deferred frees */
510 #define ZPOOL_EXTREME_REWIND 16 /* Allow extreme measures to find best txg */
511 #define ZPOOL_REWIND_MASK 28 /* All the possible rewind bits */
512 #define ZPOOL_REWIND_POLICIES 31 /* All the possible policy bits */
514 typedef struct zpool_load_policy {
515 uint32_t zlp_rewind; /* rewind policy requested */
516 uint64_t zlp_maxmeta; /* max acceptable meta-data errors */
517 uint64_t zlp_maxdata; /* max acceptable data errors */
518 uint64_t zlp_txg; /* specific txg to load */
519 } zpool_load_policy_t;
522 * The following are configuration names used in the nvlist describing a pool's
523 * configuration. New on-disk names should be prefixed with "<reverse-DNS>:"
524 * (e.g. "org.open-zfs:") to avoid conflicting names being developed
527 #define ZPOOL_CONFIG_VERSION "version"
528 #define ZPOOL_CONFIG_POOL_NAME "name"
529 #define ZPOOL_CONFIG_POOL_STATE "state"
530 #define ZPOOL_CONFIG_POOL_TXG "txg"
531 #define ZPOOL_CONFIG_POOL_GUID "pool_guid"
532 #define ZPOOL_CONFIG_CREATE_TXG "create_txg"
533 #define ZPOOL_CONFIG_TOP_GUID "top_guid"
534 #define ZPOOL_CONFIG_VDEV_TREE "vdev_tree"
535 #define ZPOOL_CONFIG_TYPE "type"
536 #define ZPOOL_CONFIG_CHILDREN "children"
537 #define ZPOOL_CONFIG_ID "id"
538 #define ZPOOL_CONFIG_GUID "guid"
539 #define ZPOOL_CONFIG_INDIRECT_OBJECT "com.delphix:indirect_object"
540 #define ZPOOL_CONFIG_INDIRECT_BIRTHS "com.delphix:indirect_births"
541 #define ZPOOL_CONFIG_PREV_INDIRECT_VDEV "com.delphix:prev_indirect_vdev"
542 #define ZPOOL_CONFIG_PATH "path"
543 #define ZPOOL_CONFIG_DEVID "devid"
544 #define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array"
545 #define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift"
546 #define ZPOOL_CONFIG_ASHIFT "ashift"
547 #define ZPOOL_CONFIG_ASIZE "asize"
548 #define ZPOOL_CONFIG_DTL "DTL"
549 #define ZPOOL_CONFIG_SCAN_STATS "scan_stats" /* not stored on disk */
550 #define ZPOOL_CONFIG_REMOVAL_STATS "removal_stats" /* not stored on disk */
551 #define ZPOOL_CONFIG_CHECKPOINT_STATS "checkpoint_stats" /* not on disk */
552 #define ZPOOL_CONFIG_VDEV_STATS "vdev_stats" /* not stored on disk */
553 #define ZPOOL_CONFIG_INDIRECT_SIZE "indirect_size" /* not stored on disk */
554 #define ZPOOL_CONFIG_WHOLE_DISK "whole_disk"
555 #define ZPOOL_CONFIG_ERRCOUNT "error_count"
556 #define ZPOOL_CONFIG_NOT_PRESENT "not_present"
557 #define ZPOOL_CONFIG_SPARES "spares"
558 #define ZPOOL_CONFIG_IS_SPARE "is_spare"
559 #define ZPOOL_CONFIG_NPARITY "nparity"
560 #define ZPOOL_CONFIG_HOSTID "hostid"
561 #define ZPOOL_CONFIG_HOSTNAME "hostname"
562 #define ZPOOL_CONFIG_LOADED_TIME "initial_load_time"
563 #define ZPOOL_CONFIG_UNSPARE "unspare"
564 #define ZPOOL_CONFIG_PHYS_PATH "phys_path"
565 #define ZPOOL_CONFIG_IS_LOG "is_log"
566 #define ZPOOL_CONFIG_L2CACHE "l2cache"
567 #define ZPOOL_CONFIG_HOLE_ARRAY "hole_array"
568 #define ZPOOL_CONFIG_VDEV_CHILDREN "vdev_children"
569 #define ZPOOL_CONFIG_IS_HOLE "is_hole"
570 #define ZPOOL_CONFIG_DDT_HISTOGRAM "ddt_histogram"
571 #define ZPOOL_CONFIG_DDT_OBJ_STATS "ddt_object_stats"
572 #define ZPOOL_CONFIG_DDT_STATS "ddt_stats"
573 #define ZPOOL_CONFIG_SPLIT "splitcfg"
574 #define ZPOOL_CONFIG_ORIG_GUID "orig_guid"
575 #define ZPOOL_CONFIG_SPLIT_GUID "split_guid"
576 #define ZPOOL_CONFIG_SPLIT_LIST "guid_list"
577 #define ZPOOL_CONFIG_REMOVING "removing"
578 #define ZPOOL_CONFIG_RESILVER_TXG "resilver_txg"
579 #define ZPOOL_CONFIG_COMMENT "comment"
580 #define ZPOOL_CONFIG_SUSPENDED "suspended" /* not stored on disk */
581 #define ZPOOL_CONFIG_TIMESTAMP "timestamp" /* not stored on disk */
582 #define ZPOOL_CONFIG_BOOTFS "bootfs" /* not stored on disk */
583 #define ZPOOL_CONFIG_MISSING_DEVICES "missing_vdevs" /* not stored on disk */
584 #define ZPOOL_CONFIG_LOAD_INFO "load_info" /* not stored on disk */
585 #define ZPOOL_CONFIG_REWIND_INFO "rewind_info" /* not stored on disk */
586 #define ZPOOL_CONFIG_UNSUP_FEAT "unsup_feat" /* not stored on disk */
587 #define ZPOOL_CONFIG_ENABLED_FEAT "enabled_feat" /* not stored on disk */
588 #define ZPOOL_CONFIG_CAN_RDONLY "can_rdonly" /* not stored on disk */
589 #define ZPOOL_CONFIG_FEATURES_FOR_READ "features_for_read"
590 #define ZPOOL_CONFIG_FEATURE_STATS "feature_stats" /* not stored on disk */
591 #define ZPOOL_CONFIG_VDEV_TOP_ZAP "com.delphix:vdev_zap_top"
592 #define ZPOOL_CONFIG_VDEV_LEAF_ZAP "com.delphix:vdev_zap_leaf"
593 #define ZPOOL_CONFIG_HAS_PER_VDEV_ZAPS "com.delphix:has_per_vdev_zaps"
594 #define ZPOOL_CONFIG_CACHEFILE "cachefile" /* not stored on disk */
596 * The persistent vdev state is stored as separate values rather than a single
597 * 'vdev_state' entry. This is because a device can be in multiple states, such
598 * as offline and degraded.
600 #define ZPOOL_CONFIG_OFFLINE "offline"
601 #define ZPOOL_CONFIG_FAULTED "faulted"
602 #define ZPOOL_CONFIG_DEGRADED "degraded"
603 #define ZPOOL_CONFIG_REMOVED "removed"
604 #define ZPOOL_CONFIG_FRU "fru"
605 #define ZPOOL_CONFIG_AUX_STATE "aux_state"
607 /* Pool load policy parameters */
608 #define ZPOOL_LOAD_POLICY "load-policy"
609 #define ZPOOL_LOAD_REWIND_POLICY "load-rewind-policy"
610 #define ZPOOL_LOAD_REQUEST_TXG "load-request-txg"
611 #define ZPOOL_LOAD_META_THRESH "load-meta-thresh"
612 #define ZPOOL_LOAD_DATA_THRESH "load-data-thresh"
614 /* Rewind data discovered */
615 #define ZPOOL_CONFIG_LOAD_TIME "rewind_txg_ts"
616 #define ZPOOL_CONFIG_LOAD_DATA_ERRORS "verify_data_errors"
617 #define ZPOOL_CONFIG_REWIND_TIME "seconds_of_rewind"
619 #define VDEV_TYPE_ROOT "root"
620 #define VDEV_TYPE_MIRROR "mirror"
621 #define VDEV_TYPE_REPLACING "replacing"
622 #define VDEV_TYPE_RAIDZ "raidz"
623 #define VDEV_TYPE_DISK "disk"
624 #define VDEV_TYPE_FILE "file"
625 #define VDEV_TYPE_MISSING "missing"
626 #define VDEV_TYPE_HOLE "hole"
627 #define VDEV_TYPE_SPARE "spare"
628 #define VDEV_TYPE_LOG "log"
629 #define VDEV_TYPE_L2CACHE "l2cache"
630 #define VDEV_TYPE_INDIRECT "indirect"
632 /* VDEV_TOP_ZAP_* are used in top-level vdev ZAP objects. */
633 #define VDEV_TOP_ZAP_INDIRECT_OBSOLETE_SM \
634 "com.delphix:indirect_obsolete_sm"
635 #define VDEV_TOP_ZAP_OBSOLETE_COUNTS_ARE_PRECISE \
636 "com.delphix:obsolete_counts_are_precise"
637 #define VDEV_TOP_ZAP_POOL_CHECKPOINT_SM \
638 "com.delphix:pool_checkpoint_sm"
641 * This is needed in userland to report the minimum necessary device size.
643 * Note that the zfs test suite uses 64MB vdevs.
645 #define SPA_MINDEVSIZE (64ULL << 20)
648 * Set if the fragmentation has not yet been calculated. This can happen
649 * because the space maps have not been upgraded or the histogram feature
652 #define ZFS_FRAG_INVALID UINT64_MAX
655 * The location of the pool configuration repository, shared between kernel and
658 #define ZPOOL_CACHE "/boot/zfs/zpool.cache"
661 * vdev states are ordered from least to most healthy.
662 * A vdev that's CANT_OPEN or below is considered unusable.
664 typedef enum vdev_state {
665 VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev */
666 VDEV_STATE_CLOSED, /* Not currently open */
667 VDEV_STATE_OFFLINE, /* Not allowed to open */
668 VDEV_STATE_REMOVED, /* Explicitly removed from system */
669 VDEV_STATE_CANT_OPEN, /* Tried to open, but failed */
670 VDEV_STATE_FAULTED, /* External request to fault device */
671 VDEV_STATE_DEGRADED, /* Replicated vdev with unhealthy kids */
672 VDEV_STATE_HEALTHY /* Presumed good */
675 #define VDEV_STATE_ONLINE VDEV_STATE_HEALTHY
678 * vdev aux states. When a vdev is in the CANT_OPEN state, the aux field
679 * of the vdev stats structure uses these constants to distinguish why.
681 typedef enum vdev_aux {
682 VDEV_AUX_NONE, /* no error */
683 VDEV_AUX_OPEN_FAILED, /* ldi_open_*() or vn_open() failed */
684 VDEV_AUX_CORRUPT_DATA, /* bad label or disk contents */
685 VDEV_AUX_NO_REPLICAS, /* insufficient number of replicas */
686 VDEV_AUX_BAD_GUID_SUM, /* vdev guid sum doesn't match */
687 VDEV_AUX_TOO_SMALL, /* vdev size is too small */
688 VDEV_AUX_BAD_LABEL, /* the label is OK but invalid */
689 VDEV_AUX_VERSION_NEWER, /* on-disk version is too new */
690 VDEV_AUX_VERSION_OLDER, /* on-disk version is too old */
691 VDEV_AUX_UNSUP_FEAT, /* unsupported features */
692 VDEV_AUX_SPARED, /* hot spare used in another pool */
693 VDEV_AUX_ERR_EXCEEDED, /* too many errors */
694 VDEV_AUX_IO_FAILURE, /* experienced I/O failure */
695 VDEV_AUX_BAD_LOG, /* cannot read log chain(s) */
696 VDEV_AUX_EXTERNAL, /* external diagnosis */
697 VDEV_AUX_SPLIT_POOL, /* vdev was split off into another pool */
698 VDEV_AUX_ASHIFT_TOO_BIG, /* vdev's min block size is too large */
699 VDEV_AUX_CHILDREN_OFFLINE /* all children are offline */
703 * pool state. The following states are written to disk as part of the normal
704 * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE. The remaining
705 * states are software abstractions used at various levels to communicate
708 typedef enum pool_state {
709 POOL_STATE_ACTIVE = 0, /* In active use */
710 POOL_STATE_EXPORTED, /* Explicitly exported */
711 POOL_STATE_DESTROYED, /* Explicitly destroyed */
712 POOL_STATE_SPARE, /* Reserved for hot spare use */
713 POOL_STATE_L2CACHE, /* Level 2 ARC device */
714 POOL_STATE_UNINITIALIZED, /* Internal spa_t state */
715 POOL_STATE_UNAVAIL, /* Internal libzfs state */
716 POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */
722 typedef enum pool_scan_func {
730 * Used to control scrub pause and resume.
732 typedef enum pool_scrub_cmd {
733 POOL_SCRUB_NORMAL = 0,
740 * ZIO types. Needed to interpret vdev statistics below.
742 typedef enum zio_type {
753 * Pool statistics. Note: all fields should be 64-bit because this
754 * is passed between kernel and userland as an nvlist uint64 array.
756 typedef struct pool_scan_stat {
757 /* values stored on disk */
758 uint64_t pss_func; /* pool_scan_func_t */
759 uint64_t pss_state; /* dsl_scan_state_t */
760 uint64_t pss_start_time; /* scan start time */
761 uint64_t pss_end_time; /* scan end time */
762 uint64_t pss_to_examine; /* total bytes to scan */
763 uint64_t pss_examined; /* total examined bytes */
764 uint64_t pss_to_process; /* total bytes to process */
765 uint64_t pss_processed; /* total processed bytes */
766 uint64_t pss_errors; /* scan errors */
768 /* values not stored on disk */
769 uint64_t pss_pass_exam; /* examined bytes per scan pass */
770 uint64_t pss_pass_start; /* start time of a scan pass */
771 uint64_t pss_pass_scrub_pause; /* pause time of a scurb pass */
772 /* cumulative time scrub spent paused, needed for rate calculation */
773 uint64_t pss_pass_scrub_spent_paused;
776 typedef struct pool_removal_stat {
777 uint64_t prs_state; /* dsl_scan_state_t */
778 uint64_t prs_removing_vdev;
779 uint64_t prs_start_time;
780 uint64_t prs_end_time;
781 uint64_t prs_to_copy; /* bytes that need to be copied */
782 uint64_t prs_copied; /* bytes copied so far */
784 * bytes of memory used for indirect mappings.
785 * This includes all removed vdevs.
787 uint64_t prs_mapping_memory;
788 } pool_removal_stat_t;
790 typedef enum dsl_scan_state {
800 CS_CHECKPOINT_EXISTS,
801 CS_CHECKPOINT_DISCARDING,
803 } checkpoint_state_t;
805 typedef struct pool_checkpoint_stat {
806 uint64_t pcs_state; /* checkpoint_state_t */
807 uint64_t pcs_start_time; /* time checkpoint/discard started */
808 uint64_t pcs_space; /* checkpointed space */
809 } pool_checkpoint_stat_t;
812 * Vdev statistics. Note: all fields should be 64-bit because this
813 * is passed between kernel and userland as an nvlist uint64 array.
815 typedef struct vdev_stat {
816 hrtime_t vs_timestamp; /* time since vdev load */
817 uint64_t vs_state; /* vdev state */
818 uint64_t vs_aux; /* see vdev_aux_t */
819 uint64_t vs_alloc; /* space allocated */
820 uint64_t vs_space; /* total capacity */
821 uint64_t vs_dspace; /* deflated capacity */
822 uint64_t vs_rsize; /* replaceable dev size */
823 uint64_t vs_esize; /* expandable dev size */
824 uint64_t vs_ops[ZIO_TYPES]; /* operation count */
825 uint64_t vs_bytes[ZIO_TYPES]; /* bytes read/written */
826 uint64_t vs_read_errors; /* read errors */
827 uint64_t vs_write_errors; /* write errors */
828 uint64_t vs_checksum_errors; /* checksum errors */
829 uint64_t vs_self_healed; /* self-healed bytes */
830 uint64_t vs_scan_removing; /* removing? */
831 uint64_t vs_scan_processed; /* scan processed bytes */
832 uint64_t vs_configured_ashift; /* TLV vdev_ashift */
833 uint64_t vs_logical_ashift; /* vdev_logical_ashift */
834 uint64_t vs_physical_ashift; /* vdev_physical_ashift */
835 uint64_t vs_fragmentation; /* device fragmentation */
836 uint64_t vs_checkpoint_space; /* checkpoint-consumed space */
838 #define VDEV_STAT_VALID(field, uint64_t_field_count) \
839 ((uint64_t_field_count * sizeof(uint64_t)) >= \
840 (offsetof(vdev_stat_t, field) + sizeof(((vdev_stat_t *)NULL)->field)))
843 * DDT statistics. Note: all fields should be 64-bit because this
844 * is passed between kernel and userland as an nvlist uint64 array.
846 typedef struct ddt_object {
847 uint64_t ddo_count; /* number of elments in ddt */
848 uint64_t ddo_dspace; /* size of ddt on disk */
849 uint64_t ddo_mspace; /* size of ddt in-core */
852 typedef struct ddt_stat {
853 uint64_t dds_blocks; /* blocks */
854 uint64_t dds_lsize; /* logical size */
855 uint64_t dds_psize; /* physical size */
856 uint64_t dds_dsize; /* deflated allocated size */
857 uint64_t dds_ref_blocks; /* referenced blocks */
858 uint64_t dds_ref_lsize; /* referenced lsize * refcnt */
859 uint64_t dds_ref_psize; /* referenced psize * refcnt */
860 uint64_t dds_ref_dsize; /* referenced dsize * refcnt */
863 typedef struct ddt_histogram {
864 ddt_stat_t ddh_stat[64]; /* power-of-two histogram buckets */
867 #define ZVOL_DRIVER "zvol"
868 #define ZFS_DRIVER "zfs"
869 #define ZFS_DEV_NAME "zfs"
870 #define ZFS_DEV "/dev/" ZFS_DEV_NAME
871 #define ZFS_DISK_ROOT "/dev/dsk"
872 #define ZFS_DISK_ROOTD ZFS_DISK_ROOT "/"
873 #define ZFS_RDISK_ROOT "/dev/rdsk"
874 #define ZFS_RDISK_ROOTD ZFS_RDISK_ROOT "/"
876 /* general zvol path */
877 #define ZVOL_DIR "/dev/zvol"
879 #define ZVOL_PSEUDO_DEV "/devices/pseudo/zfs@0:"
880 /* for dump and swap */
881 #define ZVOL_FULL_DEV_DIR ZVOL_DIR "/dsk/"
882 #define ZVOL_FULL_RDEV_DIR ZVOL_DIR "/rdsk/"
884 #define ZVOL_PROP_NAME "name"
885 #define ZVOL_DEFAULT_BLOCKSIZE 8192
888 * /dev/zfs ioctl numbers.
890 typedef enum zfs_ioc {
892 ZFS_IOC_POOL_CREATE = ZFS_IOC_FIRST,
893 ZFS_IOC_POOL_DESTROY,
896 ZFS_IOC_POOL_CONFIGS,
898 ZFS_IOC_POOL_TRYIMPORT,
901 ZFS_IOC_POOL_UPGRADE,
902 ZFS_IOC_POOL_GET_HISTORY,
905 ZFS_IOC_VDEV_SET_STATE,
908 ZFS_IOC_VDEV_SETPATH,
910 ZFS_IOC_OBJSET_STATS,
911 ZFS_IOC_OBJSET_ZPLPROPS,
912 ZFS_IOC_DATASET_LIST_NEXT,
913 ZFS_IOC_SNAPSHOT_LIST_NEXT,
921 ZFS_IOC_INJECT_FAULT,
923 ZFS_IOC_INJECT_LIST_NEXT,
927 ZFS_IOC_DESTROY_SNAPS,
929 ZFS_IOC_DSOBJ_TO_DSNAME,
931 ZFS_IOC_POOL_SET_PROPS,
932 ZFS_IOC_POOL_GET_PROPS,
936 ZFS_IOC_INHERIT_PROP,
938 ZFS_IOC_USERSPACE_ONE,
939 ZFS_IOC_USERSPACE_MANY,
940 ZFS_IOC_USERSPACE_UPGRADE,
944 ZFS_IOC_OBJSET_RECVD_PROPS,
948 ZFS_IOC_TMP_SNAPSHOT,
949 ZFS_IOC_OBJ_TO_STATS,
953 ZFS_IOC_SPACE_WRITTEN,
955 ZFS_IOC_SEND_PROGRESS,
962 ZFS_IOC_GET_BOOKMARKS,
963 ZFS_IOC_DESTROY_BOOKMARKS,
967 ZFS_IOC_CHANNEL_PROGRAM,
969 ZFS_IOC_POOL_CHECKPOINT,
970 ZFS_IOC_POOL_DISCARD_CHECKPOINT,
975 * ZFS-specific error codes used for returning descriptive errors
976 * to the userland through zfs ioctls.
978 * The enum implicitly includes all the error codes from errno.h.
979 * New code should use and extend this enum for errors that are
980 * not described precisely by generic errno codes.
983 ZFS_ERR_CHECKPOINT_EXISTS = 1024,
984 ZFS_ERR_DISCARDING_CHECKPOINT,
985 ZFS_ERR_NO_CHECKPOINT,
986 ZFS_ERR_DEVRM_IN_PROGRESS,
991 * Internal SPA load state. Used by FMA diagnosis engine.
994 SPA_LOAD_NONE, /* no load in progress */
995 SPA_LOAD_OPEN, /* normal open */
996 SPA_LOAD_IMPORT, /* import in progress */
997 SPA_LOAD_TRYIMPORT, /* tryimport in progress */
998 SPA_LOAD_RECOVER, /* recovery requested */
999 SPA_LOAD_ERROR, /* load failed */
1000 SPA_LOAD_CREATE /* creation in progress */
1004 * Bookmark name values.
1006 #define ZPOOL_ERR_LIST "error list"
1007 #define ZPOOL_ERR_DATASET "dataset"
1008 #define ZPOOL_ERR_OBJECT "object"
1010 #define HIS_MAX_RECORD_LEN (MAXPATHLEN + MAXPATHLEN + 1)
1013 * The following are names used in the nvlist describing
1014 * the pool's history log.
1016 #define ZPOOL_HIST_RECORD "history record"
1017 #define ZPOOL_HIST_TIME "history time"
1018 #define ZPOOL_HIST_CMD "history command"
1019 #define ZPOOL_HIST_WHO "history who"
1020 #define ZPOOL_HIST_ZONE "history zone"
1021 #define ZPOOL_HIST_HOST "history hostname"
1022 #define ZPOOL_HIST_TXG "history txg"
1023 #define ZPOOL_HIST_INT_EVENT "history internal event"
1024 #define ZPOOL_HIST_INT_STR "history internal str"
1025 #define ZPOOL_HIST_INT_NAME "internal_name"
1026 #define ZPOOL_HIST_IOCTL "ioctl"
1027 #define ZPOOL_HIST_INPUT_NVL "in_nvl"
1028 #define ZPOOL_HIST_OUTPUT_NVL "out_nvl"
1029 #define ZPOOL_HIST_DSNAME "dsname"
1030 #define ZPOOL_HIST_DSID "dsid"
1031 #define ZPOOL_HIST_ERRNO "errno"
1034 * Flags for ZFS_IOC_VDEV_SET_STATE
1036 #define ZFS_ONLINE_CHECKREMOVE 0x1
1037 #define ZFS_ONLINE_UNSPARE 0x2
1038 #define ZFS_ONLINE_FORCEFAULT 0x4
1039 #define ZFS_ONLINE_EXPAND 0x8
1040 #define ZFS_OFFLINE_TEMPORARY 0x1
1043 * Flags for ZFS_IOC_POOL_IMPORT
1045 #define ZFS_IMPORT_NORMAL 0x0
1046 #define ZFS_IMPORT_VERBATIM 0x1
1047 #define ZFS_IMPORT_ANY_HOST 0x2
1048 #define ZFS_IMPORT_MISSING_LOG 0x4
1049 #define ZFS_IMPORT_ONLY 0x8
1050 #define ZFS_IMPORT_CHECKPOINT 0x10
1051 #define ZFS_IMPORT_TEMP_NAME 0x20
1054 * Channel program argument/return nvlist keys and defaults.
1056 #define ZCP_ARG_PROGRAM "program"
1057 #define ZCP_ARG_ARGLIST "arg"
1058 #define ZCP_ARG_SYNC "sync"
1059 #define ZCP_ARG_INSTRLIMIT "instrlimit"
1060 #define ZCP_ARG_MEMLIMIT "memlimit"
1062 #define ZCP_ARG_CLIARGV "argv"
1064 #define ZCP_RET_ERROR "error"
1065 #define ZCP_RET_RETURN "return"
1067 #define ZCP_DEFAULT_INSTRLIMIT (10 * 1000 * 1000)
1068 #define ZCP_MAX_INSTRLIMIT (10 * ZCP_DEFAULT_INSTRLIMIT)
1069 #define ZCP_DEFAULT_MEMLIMIT (10 * 1024 * 1024)
1070 #define ZCP_MAX_MEMLIMIT (10 * ZCP_DEFAULT_MEMLIMIT)
1073 * Sysevent payload members. ZFS will generate the following sysevents with the
1076 * ESC_ZFS_RESILVER_START
1077 * ESC_ZFS_RESILVER_END
1078 * ESC_ZFS_POOL_DESTROY
1079 * ESC_ZFS_POOL_REGUID
1081 * ZFS_EV_POOL_NAME DATA_TYPE_STRING
1082 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64
1084 * ESC_ZFS_VDEV_REMOVE
1085 * ESC_ZFS_VDEV_CLEAR
1086 * ESC_ZFS_VDEV_CHECK
1088 * ZFS_EV_POOL_NAME DATA_TYPE_STRING
1089 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64
1090 * ZFS_EV_VDEV_PATH DATA_TYPE_STRING (optional)
1091 * ZFS_EV_VDEV_GUID DATA_TYPE_UINT64
1093 * ESC_ZFS_HISTORY_EVENT
1095 * ZFS_EV_POOL_NAME DATA_TYPE_STRING
1096 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64
1097 * ZFS_EV_HIST_TIME DATA_TYPE_UINT64 (optional)
1098 * ZFS_EV_HIST_CMD DATA_TYPE_STRING (optional)
1099 * ZFS_EV_HIST_WHO DATA_TYPE_UINT64 (optional)
1100 * ZFS_EV_HIST_ZONE DATA_TYPE_STRING (optional)
1101 * ZFS_EV_HIST_HOST DATA_TYPE_STRING (optional)
1102 * ZFS_EV_HIST_TXG DATA_TYPE_UINT64 (optional)
1103 * ZFS_EV_HIST_INT_EVENT DATA_TYPE_UINT64 (optional)
1104 * ZFS_EV_HIST_INT_STR DATA_TYPE_STRING (optional)
1105 * ZFS_EV_HIST_INT_NAME DATA_TYPE_STRING (optional)
1106 * ZFS_EV_HIST_IOCTL DATA_TYPE_STRING (optional)
1107 * ZFS_EV_HIST_DSNAME DATA_TYPE_STRING (optional)
1108 * ZFS_EV_HIST_DSID DATA_TYPE_UINT64 (optional)
1110 * The ZFS_EV_HIST_* members will correspond to the ZPOOL_HIST_* members in the
1111 * history log nvlist. The keynames will be free of any spaces or other
1112 * characters that could be potentially unexpected to consumers of the
1115 #define ZFS_EV_POOL_NAME "pool_name"
1116 #define ZFS_EV_POOL_GUID "pool_guid"
1117 #define ZFS_EV_VDEV_PATH "vdev_path"
1118 #define ZFS_EV_VDEV_GUID "vdev_guid"
1119 #define ZFS_EV_HIST_TIME "history_time"
1120 #define ZFS_EV_HIST_CMD "history_command"
1121 #define ZFS_EV_HIST_WHO "history_who"
1122 #define ZFS_EV_HIST_ZONE "history_zone"
1123 #define ZFS_EV_HIST_HOST "history_hostname"
1124 #define ZFS_EV_HIST_TXG "history_txg"
1125 #define ZFS_EV_HIST_INT_EVENT "history_internal_event"
1126 #define ZFS_EV_HIST_INT_STR "history_internal_str"
1127 #define ZFS_EV_HIST_INT_NAME "history_internal_name"
1128 #define ZFS_EV_HIST_IOCTL "history_ioctl"
1129 #define ZFS_EV_HIST_DSNAME "history_dsname"
1130 #define ZFS_EV_HIST_DSID "history_dsid"
1136 #endif /* _SYS_FS_ZFS_H */