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,
220 /* Small enough to not hog a whole line of printout in zpool(1M). */
221 #define ZPROP_MAX_COMMENT 32
223 #define ZPROP_VALUE "value"
224 #define ZPROP_SOURCE "source"
227 ZPROP_SRC_NONE = 0x1,
228 ZPROP_SRC_DEFAULT = 0x2,
229 ZPROP_SRC_TEMPORARY = 0x4,
230 ZPROP_SRC_LOCAL = 0x8,
231 ZPROP_SRC_INHERITED = 0x10,
232 ZPROP_SRC_RECEIVED = 0x20
235 #define ZPROP_SRC_ALL 0x3f
237 #define ZPROP_SOURCE_VAL_RECVD "$recvd"
238 #define ZPROP_N_MORE_ERRORS "N_MORE_ERRORS"
240 * Dataset flag implemented as a special entry in the props zap object
241 * indicating that the dataset has received properties on or after
242 * SPA_VERSION_RECVD_PROPS. The first such receive blows away local properties
243 * just as it did in earlier versions, and thereafter, local properties are
246 #define ZPROP_HAS_RECVD "$hasrecvd"
249 ZPROP_ERR_NOCLEAR = 0x1, /* failure to clear existing props */
250 ZPROP_ERR_NORESTORE = 0x2 /* failure to restore props on error */
253 typedef int (*zprop_func)(int, void *);
256 * Properties to be set on the root file system of a new pool
257 * are stuffed into their own nvlist, which is then included in
258 * the properties nvlist with the pool properties.
260 #define ZPOOL_ROOTFS_PROPS "root-props-nvl"
263 * Length of 'written@' and 'written#'
265 #define ZFS_WRITTEN_PROP_PREFIX_LEN 8
268 * Dataset property functions shared between libzfs and kernel.
270 const char *zfs_prop_default_string(zfs_prop_t);
271 uint64_t zfs_prop_default_numeric(zfs_prop_t);
272 boolean_t zfs_prop_readonly(zfs_prop_t);
273 boolean_t zfs_prop_visible(zfs_prop_t prop);
274 boolean_t zfs_prop_inheritable(zfs_prop_t);
275 boolean_t zfs_prop_setonce(zfs_prop_t);
276 const char *zfs_prop_to_name(zfs_prop_t);
277 zfs_prop_t zfs_name_to_prop(const char *);
278 boolean_t zfs_prop_user(const char *);
279 boolean_t zfs_prop_userquota(const char *);
280 int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
281 int zfs_prop_string_to_index(zfs_prop_t, const char *, uint64_t *);
282 uint64_t zfs_prop_random_value(zfs_prop_t, uint64_t seed);
283 boolean_t zfs_prop_valid_for_type(int, zfs_type_t);
286 * Pool property functions shared between libzfs and kernel.
288 zpool_prop_t zpool_name_to_prop(const char *);
289 const char *zpool_prop_to_name(zpool_prop_t);
290 const char *zpool_prop_default_string(zpool_prop_t);
291 uint64_t zpool_prop_default_numeric(zpool_prop_t);
292 boolean_t zpool_prop_readonly(zpool_prop_t);
293 boolean_t zpool_prop_feature(const char *);
294 boolean_t zpool_prop_unsupported(const char *name);
295 int zpool_prop_index_to_string(zpool_prop_t, uint64_t, const char **);
296 int zpool_prop_string_to_index(zpool_prop_t, const char *, uint64_t *);
297 uint64_t zpool_prop_random_value(zpool_prop_t, uint64_t seed);
300 * Definitions for the Delegation.
303 ZFS_DELEG_WHO_UNKNOWN = 0,
304 ZFS_DELEG_USER = 'u',
305 ZFS_DELEG_USER_SETS = 'U',
306 ZFS_DELEG_GROUP = 'g',
307 ZFS_DELEG_GROUP_SETS = 'G',
308 ZFS_DELEG_EVERYONE = 'e',
309 ZFS_DELEG_EVERYONE_SETS = 'E',
310 ZFS_DELEG_CREATE = 'c',
311 ZFS_DELEG_CREATE_SETS = 'C',
312 ZFS_DELEG_NAMED_SET = 's',
313 ZFS_DELEG_NAMED_SET_SETS = 'S'
314 } zfs_deleg_who_type_t;
318 ZFS_DELEG_PERM_LOCAL = 1,
319 ZFS_DELEG_PERM_DESCENDENT = 2,
320 ZFS_DELEG_PERM_LOCALDESCENDENT = 3,
321 ZFS_DELEG_PERM_CREATE = 4
322 } zfs_deleg_inherit_t;
324 #define ZFS_DELEG_PERM_UID "uid"
325 #define ZFS_DELEG_PERM_GID "gid"
326 #define ZFS_DELEG_PERM_GROUPS "groups"
328 #define ZFS_MLSLABEL_DEFAULT "none"
330 #define ZFS_SMB_ACL_SRC "src"
331 #define ZFS_SMB_ACL_TARGET "target"
334 ZFS_CANMOUNT_OFF = 0,
336 ZFS_CANMOUNT_NOAUTO = 2
337 } zfs_canmount_type_t;
340 ZFS_LOGBIAS_LATENCY = 0,
341 ZFS_LOGBIAS_THROUGHPUT = 1
344 typedef enum zfs_share_op {
351 typedef enum zfs_smb_acl_op {
358 typedef enum zfs_cache_type {
360 ZFS_CACHE_METADATA = 1,
365 ZFS_SYNC_STANDARD = 0,
367 ZFS_SYNC_DISABLED = 2
371 ZFS_VOLMODE_DEFAULT = 0,
372 ZFS_VOLMODE_GEOM = 1,
378 ZFS_REDUNDANT_METADATA_ALL,
379 ZFS_REDUNDANT_METADATA_MOST
380 } zfs_redundant_metadata_type_t;
383 * On-disk version number.
385 #define SPA_VERSION_1 1ULL
386 #define SPA_VERSION_2 2ULL
387 #define SPA_VERSION_3 3ULL
388 #define SPA_VERSION_4 4ULL
389 #define SPA_VERSION_5 5ULL
390 #define SPA_VERSION_6 6ULL
391 #define SPA_VERSION_7 7ULL
392 #define SPA_VERSION_8 8ULL
393 #define SPA_VERSION_9 9ULL
394 #define SPA_VERSION_10 10ULL
395 #define SPA_VERSION_11 11ULL
396 #define SPA_VERSION_12 12ULL
397 #define SPA_VERSION_13 13ULL
398 #define SPA_VERSION_14 14ULL
399 #define SPA_VERSION_15 15ULL
400 #define SPA_VERSION_16 16ULL
401 #define SPA_VERSION_17 17ULL
402 #define SPA_VERSION_18 18ULL
403 #define SPA_VERSION_19 19ULL
404 #define SPA_VERSION_20 20ULL
405 #define SPA_VERSION_21 21ULL
406 #define SPA_VERSION_22 22ULL
407 #define SPA_VERSION_23 23ULL
408 #define SPA_VERSION_24 24ULL
409 #define SPA_VERSION_25 25ULL
410 #define SPA_VERSION_26 26ULL
411 #define SPA_VERSION_27 27ULL
412 #define SPA_VERSION_28 28ULL
413 #define SPA_VERSION_5000 5000ULL
416 * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk
417 * format change. Go to usr/src/grub/grub-0.97/stage2/{zfs-include/, fsys_zfs*},
418 * and do the appropriate changes. Also bump the version number in
419 * usr/src/grub/capability.
421 #define SPA_VERSION SPA_VERSION_5000
422 #define SPA_VERSION_STRING "5000"
425 * Symbolic names for the changes that caused a SPA_VERSION switch.
426 * Used in the code when checking for presence or absence of a feature.
427 * Feel free to define multiple symbolic names for each version if there
428 * were multiple changes to on-disk structures during that version.
430 * NOTE: When checking the current SPA_VERSION in your code, be sure
431 * to use spa_version() since it reports the version of the
432 * last synced uberblock. Checking the in-flight version can
433 * be dangerous in some cases.
435 #define SPA_VERSION_INITIAL SPA_VERSION_1
436 #define SPA_VERSION_DITTO_BLOCKS SPA_VERSION_2
437 #define SPA_VERSION_SPARES SPA_VERSION_3
438 #define SPA_VERSION_RAIDZ2 SPA_VERSION_3
439 #define SPA_VERSION_BPOBJ_ACCOUNT SPA_VERSION_3
440 #define SPA_VERSION_RAIDZ_DEFLATE SPA_VERSION_3
441 #define SPA_VERSION_DNODE_BYTES SPA_VERSION_3
442 #define SPA_VERSION_ZPOOL_HISTORY SPA_VERSION_4
443 #define SPA_VERSION_GZIP_COMPRESSION SPA_VERSION_5
444 #define SPA_VERSION_BOOTFS SPA_VERSION_6
445 #define SPA_VERSION_SLOGS SPA_VERSION_7
446 #define SPA_VERSION_DELEGATED_PERMS SPA_VERSION_8
447 #define SPA_VERSION_FUID SPA_VERSION_9
448 #define SPA_VERSION_REFRESERVATION SPA_VERSION_9
449 #define SPA_VERSION_REFQUOTA SPA_VERSION_9
450 #define SPA_VERSION_UNIQUE_ACCURATE SPA_VERSION_9
451 #define SPA_VERSION_L2CACHE SPA_VERSION_10
452 #define SPA_VERSION_NEXT_CLONES SPA_VERSION_11
453 #define SPA_VERSION_ORIGIN SPA_VERSION_11
454 #define SPA_VERSION_DSL_SCRUB SPA_VERSION_11
455 #define SPA_VERSION_SNAP_PROPS SPA_VERSION_12
456 #define SPA_VERSION_USED_BREAKDOWN SPA_VERSION_13
457 #define SPA_VERSION_PASSTHROUGH_X SPA_VERSION_14
458 #define SPA_VERSION_USERSPACE SPA_VERSION_15
459 #define SPA_VERSION_STMF_PROP SPA_VERSION_16
460 #define SPA_VERSION_RAIDZ3 SPA_VERSION_17
461 #define SPA_VERSION_USERREFS SPA_VERSION_18
462 #define SPA_VERSION_HOLES SPA_VERSION_19
463 #define SPA_VERSION_ZLE_COMPRESSION SPA_VERSION_20
464 #define SPA_VERSION_DEDUP SPA_VERSION_21
465 #define SPA_VERSION_RECVD_PROPS SPA_VERSION_22
466 #define SPA_VERSION_SLIM_ZIL SPA_VERSION_23
467 #define SPA_VERSION_SA SPA_VERSION_24
468 #define SPA_VERSION_SCAN SPA_VERSION_25
469 #define SPA_VERSION_DIR_CLONES SPA_VERSION_26
470 #define SPA_VERSION_DEADLISTS SPA_VERSION_26
471 #define SPA_VERSION_FAST_SNAP SPA_VERSION_27
472 #define SPA_VERSION_MULTI_REPLACE SPA_VERSION_28
473 #define SPA_VERSION_BEFORE_FEATURES SPA_VERSION_28
474 #define SPA_VERSION_FEATURES SPA_VERSION_5000
476 #define SPA_VERSION_IS_SUPPORTED(v) \
477 (((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \
478 ((v) >= SPA_VERSION_FEATURES && (v) <= SPA_VERSION))
481 * ZPL version - rev'd whenever an incompatible on-disk format change
482 * occurs. This is independent of SPA/DMU/ZAP versioning. You must
483 * also update the version_table[] and help message in zfs_prop.c.
485 * When changing, be sure to teach GRUB how to read the new format!
486 * See usr/src/grub/grub-0.97/stage2/{zfs-include/,fsys_zfs*}
488 #define ZPL_VERSION_1 1ULL
489 #define ZPL_VERSION_2 2ULL
490 #define ZPL_VERSION_3 3ULL
491 #define ZPL_VERSION_4 4ULL
492 #define ZPL_VERSION_5 5ULL
493 #define ZPL_VERSION ZPL_VERSION_5
494 #define ZPL_VERSION_STRING "5"
496 #define ZPL_VERSION_INITIAL ZPL_VERSION_1
497 #define ZPL_VERSION_DIRENT_TYPE ZPL_VERSION_2
498 #define ZPL_VERSION_FUID ZPL_VERSION_3
499 #define ZPL_VERSION_NORMALIZATION ZPL_VERSION_3
500 #define ZPL_VERSION_SYSATTR ZPL_VERSION_3
501 #define ZPL_VERSION_USERSPACE ZPL_VERSION_4
502 #define ZPL_VERSION_SA ZPL_VERSION_5
504 /* Rewind request information */
505 #define ZPOOL_NO_REWIND 1 /* No policy - default behavior */
506 #define ZPOOL_NEVER_REWIND 2 /* Do not search for best txg or rewind */
507 #define ZPOOL_TRY_REWIND 4 /* Search for best txg, but do not rewind */
508 #define ZPOOL_DO_REWIND 8 /* Rewind to best txg w/in deferred frees */
509 #define ZPOOL_EXTREME_REWIND 16 /* Allow extreme measures to find best txg */
510 #define ZPOOL_REWIND_MASK 28 /* All the possible rewind bits */
511 #define ZPOOL_REWIND_POLICIES 31 /* All the possible policy bits */
513 typedef struct zpool_rewind_policy {
514 uint32_t zrp_request; /* rewind behavior requested */
515 uint64_t zrp_maxmeta; /* max acceptable meta-data errors */
516 uint64_t zrp_maxdata; /* max acceptable data errors */
517 uint64_t zrp_txg; /* specific txg to load */
518 } zpool_rewind_policy_t;
521 * The following are configuration names used in the nvlist describing a pool's
522 * configuration. New on-disk names should be prefixed with "<reverse-DNS>:"
523 * (e.g. "org.open-zfs:") to avoid conflicting names being developed
526 #define ZPOOL_CONFIG_VERSION "version"
527 #define ZPOOL_CONFIG_POOL_NAME "name"
528 #define ZPOOL_CONFIG_POOL_STATE "state"
529 #define ZPOOL_CONFIG_POOL_TXG "txg"
530 #define ZPOOL_CONFIG_POOL_GUID "pool_guid"
531 #define ZPOOL_CONFIG_CREATE_TXG "create_txg"
532 #define ZPOOL_CONFIG_TOP_GUID "top_guid"
533 #define ZPOOL_CONFIG_VDEV_TREE "vdev_tree"
534 #define ZPOOL_CONFIG_TYPE "type"
535 #define ZPOOL_CONFIG_CHILDREN "children"
536 #define ZPOOL_CONFIG_ID "id"
537 #define ZPOOL_CONFIG_GUID "guid"
538 #define ZPOOL_CONFIG_INDIRECT_OBJECT "com.delphix:indirect_object"
539 #define ZPOOL_CONFIG_INDIRECT_BIRTHS "com.delphix:indirect_births"
540 #define ZPOOL_CONFIG_PREV_INDIRECT_VDEV "com.delphix:prev_indirect_vdev"
541 #define ZPOOL_CONFIG_PATH "path"
542 #define ZPOOL_CONFIG_DEVID "devid"
543 #define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array"
544 #define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift"
545 #define ZPOOL_CONFIG_ASHIFT "ashift"
546 #define ZPOOL_CONFIG_ASIZE "asize"
547 #define ZPOOL_CONFIG_DTL "DTL"
548 #define ZPOOL_CONFIG_SCAN_STATS "scan_stats" /* not stored on disk */
549 #define ZPOOL_CONFIG_REMOVAL_STATS "removal_stats" /* not stored on disk */
550 #define ZPOOL_CONFIG_CHECKPOINT_STATS "checkpoint_stats" /* not on disk */
551 #define ZPOOL_CONFIG_VDEV_STATS "vdev_stats" /* not stored on disk */
552 #define ZPOOL_CONFIG_INDIRECT_SIZE "indirect_size" /* not stored on disk */
553 #define ZPOOL_CONFIG_WHOLE_DISK "whole_disk"
554 #define ZPOOL_CONFIG_ERRCOUNT "error_count"
555 #define ZPOOL_CONFIG_NOT_PRESENT "not_present"
556 #define ZPOOL_CONFIG_SPARES "spares"
557 #define ZPOOL_CONFIG_IS_SPARE "is_spare"
558 #define ZPOOL_CONFIG_NPARITY "nparity"
559 #define ZPOOL_CONFIG_HOSTID "hostid"
560 #define ZPOOL_CONFIG_HOSTNAME "hostname"
561 #define ZPOOL_CONFIG_LOADED_TIME "initial_load_time"
562 #define ZPOOL_CONFIG_UNSPARE "unspare"
563 #define ZPOOL_CONFIG_PHYS_PATH "phys_path"
564 #define ZPOOL_CONFIG_IS_LOG "is_log"
565 #define ZPOOL_CONFIG_L2CACHE "l2cache"
566 #define ZPOOL_CONFIG_HOLE_ARRAY "hole_array"
567 #define ZPOOL_CONFIG_VDEV_CHILDREN "vdev_children"
568 #define ZPOOL_CONFIG_IS_HOLE "is_hole"
569 #define ZPOOL_CONFIG_DDT_HISTOGRAM "ddt_histogram"
570 #define ZPOOL_CONFIG_DDT_OBJ_STATS "ddt_object_stats"
571 #define ZPOOL_CONFIG_DDT_STATS "ddt_stats"
572 #define ZPOOL_CONFIG_SPLIT "splitcfg"
573 #define ZPOOL_CONFIG_ORIG_GUID "orig_guid"
574 #define ZPOOL_CONFIG_SPLIT_GUID "split_guid"
575 #define ZPOOL_CONFIG_SPLIT_LIST "guid_list"
576 #define ZPOOL_CONFIG_REMOVING "removing"
577 #define ZPOOL_CONFIG_RESILVER_TXG "resilver_txg"
578 #define ZPOOL_CONFIG_COMMENT "comment"
579 #define ZPOOL_CONFIG_SUSPENDED "suspended" /* not stored on disk */
580 #define ZPOOL_CONFIG_TIMESTAMP "timestamp" /* not stored on disk */
581 #define ZPOOL_CONFIG_BOOTFS "bootfs" /* not stored on disk */
582 #define ZPOOL_CONFIG_MISSING_DEVICES "missing_vdevs" /* not stored on disk */
583 #define ZPOOL_CONFIG_LOAD_INFO "load_info" /* not stored on disk */
584 #define ZPOOL_CONFIG_REWIND_INFO "rewind_info" /* not stored on disk */
585 #define ZPOOL_CONFIG_UNSUP_FEAT "unsup_feat" /* not stored on disk */
586 #define ZPOOL_CONFIG_ENABLED_FEAT "enabled_feat" /* not stored on disk */
587 #define ZPOOL_CONFIG_CAN_RDONLY "can_rdonly" /* not stored on disk */
588 #define ZPOOL_CONFIG_FEATURES_FOR_READ "features_for_read"
589 #define ZPOOL_CONFIG_FEATURE_STATS "feature_stats" /* not stored on disk */
590 #define ZPOOL_CONFIG_VDEV_TOP_ZAP "com.delphix:vdev_zap_top"
591 #define ZPOOL_CONFIG_VDEV_LEAF_ZAP "com.delphix:vdev_zap_leaf"
592 #define ZPOOL_CONFIG_HAS_PER_VDEV_ZAPS "com.delphix:has_per_vdev_zaps"
593 #define ZPOOL_CONFIG_CACHEFILE "cachefile" /* not stored on disk */
595 * The persistent vdev state is stored as separate values rather than a single
596 * 'vdev_state' entry. This is because a device can be in multiple states, such
597 * as offline and degraded.
599 #define ZPOOL_CONFIG_OFFLINE "offline"
600 #define ZPOOL_CONFIG_FAULTED "faulted"
601 #define ZPOOL_CONFIG_DEGRADED "degraded"
602 #define ZPOOL_CONFIG_REMOVED "removed"
603 #define ZPOOL_CONFIG_FRU "fru"
604 #define ZPOOL_CONFIG_AUX_STATE "aux_state"
606 /* Rewind policy parameters */
607 #define ZPOOL_REWIND_POLICY "rewind-policy"
608 #define ZPOOL_REWIND_REQUEST "rewind-request"
609 #define ZPOOL_REWIND_REQUEST_TXG "rewind-request-txg"
610 #define ZPOOL_REWIND_META_THRESH "rewind-meta-thresh"
611 #define ZPOOL_REWIND_DATA_THRESH "rewind-data-thresh"
613 /* Rewind data discovered */
614 #define ZPOOL_CONFIG_LOAD_TIME "rewind_txg_ts"
615 #define ZPOOL_CONFIG_LOAD_DATA_ERRORS "verify_data_errors"
616 #define ZPOOL_CONFIG_REWIND_TIME "seconds_of_rewind"
618 #define VDEV_TYPE_ROOT "root"
619 #define VDEV_TYPE_MIRROR "mirror"
620 #define VDEV_TYPE_REPLACING "replacing"
621 #define VDEV_TYPE_RAIDZ "raidz"
622 #define VDEV_TYPE_DISK "disk"
623 #define VDEV_TYPE_FILE "file"
624 #define VDEV_TYPE_MISSING "missing"
625 #define VDEV_TYPE_HOLE "hole"
626 #define VDEV_TYPE_SPARE "spare"
627 #define VDEV_TYPE_LOG "log"
628 #define VDEV_TYPE_L2CACHE "l2cache"
629 #define VDEV_TYPE_INDIRECT "indirect"
631 /* VDEV_TOP_ZAP_* are used in top-level vdev ZAP objects. */
632 #define VDEV_TOP_ZAP_INDIRECT_OBSOLETE_SM \
633 "com.delphix:indirect_obsolete_sm"
634 #define VDEV_TOP_ZAP_OBSOLETE_COUNTS_ARE_PRECISE \
635 "com.delphix:obsolete_counts_are_precise"
636 #define VDEV_TOP_ZAP_POOL_CHECKPOINT_SM \
637 "com.delphix:pool_checkpoint_sm"
640 * This is needed in userland to report the minimum necessary device size.
642 * Note that the zfs test suite uses 64MB vdevs.
644 #define SPA_MINDEVSIZE (64ULL << 20)
647 * Set if the fragmentation has not yet been calculated. This can happen
648 * because the space maps have not been upgraded or the histogram feature
651 #define ZFS_FRAG_INVALID UINT64_MAX
654 * The location of the pool configuration repository, shared between kernel and
657 #define ZPOOL_CACHE "/boot/zfs/zpool.cache"
660 * vdev states are ordered from least to most healthy.
661 * A vdev that's CANT_OPEN or below is considered unusable.
663 typedef enum vdev_state {
664 VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev */
665 VDEV_STATE_CLOSED, /* Not currently open */
666 VDEV_STATE_OFFLINE, /* Not allowed to open */
667 VDEV_STATE_REMOVED, /* Explicitly removed from system */
668 VDEV_STATE_CANT_OPEN, /* Tried to open, but failed */
669 VDEV_STATE_FAULTED, /* External request to fault device */
670 VDEV_STATE_DEGRADED, /* Replicated vdev with unhealthy kids */
671 VDEV_STATE_HEALTHY /* Presumed good */
674 #define VDEV_STATE_ONLINE VDEV_STATE_HEALTHY
677 * vdev aux states. When a vdev is in the CANT_OPEN state, the aux field
678 * of the vdev stats structure uses these constants to distinguish why.
680 typedef enum vdev_aux {
681 VDEV_AUX_NONE, /* no error */
682 VDEV_AUX_OPEN_FAILED, /* ldi_open_*() or vn_open() failed */
683 VDEV_AUX_CORRUPT_DATA, /* bad label or disk contents */
684 VDEV_AUX_NO_REPLICAS, /* insufficient number of replicas */
685 VDEV_AUX_BAD_GUID_SUM, /* vdev guid sum doesn't match */
686 VDEV_AUX_TOO_SMALL, /* vdev size is too small */
687 VDEV_AUX_BAD_LABEL, /* the label is OK but invalid */
688 VDEV_AUX_VERSION_NEWER, /* on-disk version is too new */
689 VDEV_AUX_VERSION_OLDER, /* on-disk version is too old */
690 VDEV_AUX_UNSUP_FEAT, /* unsupported features */
691 VDEV_AUX_SPARED, /* hot spare used in another pool */
692 VDEV_AUX_ERR_EXCEEDED, /* too many errors */
693 VDEV_AUX_IO_FAILURE, /* experienced I/O failure */
694 VDEV_AUX_BAD_LOG, /* cannot read log chain(s) */
695 VDEV_AUX_EXTERNAL, /* external diagnosis */
696 VDEV_AUX_SPLIT_POOL, /* vdev was split off into another pool */
697 VDEV_AUX_ASHIFT_TOO_BIG, /* vdev's min block size is too large */
698 VDEV_AUX_CHILDREN_OFFLINE /* all children are offline */
702 * pool state. The following states are written to disk as part of the normal
703 * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE. The remaining
704 * states are software abstractions used at various levels to communicate
707 typedef enum pool_state {
708 POOL_STATE_ACTIVE = 0, /* In active use */
709 POOL_STATE_EXPORTED, /* Explicitly exported */
710 POOL_STATE_DESTROYED, /* Explicitly destroyed */
711 POOL_STATE_SPARE, /* Reserved for hot spare use */
712 POOL_STATE_L2CACHE, /* Level 2 ARC device */
713 POOL_STATE_UNINITIALIZED, /* Internal spa_t state */
714 POOL_STATE_UNAVAIL, /* Internal libzfs state */
715 POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */
721 typedef enum pool_scan_func {
729 * Used to control scrub pause and resume.
731 typedef enum pool_scrub_cmd {
732 POOL_SCRUB_NORMAL = 0,
739 * ZIO types. Needed to interpret vdev statistics below.
741 typedef enum zio_type {
752 * Pool statistics. Note: all fields should be 64-bit because this
753 * is passed between kernel and userland as an nvlist uint64 array.
755 typedef struct pool_scan_stat {
756 /* values stored on disk */
757 uint64_t pss_func; /* pool_scan_func_t */
758 uint64_t pss_state; /* dsl_scan_state_t */
759 uint64_t pss_start_time; /* scan start time */
760 uint64_t pss_end_time; /* scan end time */
761 uint64_t pss_to_examine; /* total bytes to scan */
762 uint64_t pss_examined; /* total examined bytes */
763 uint64_t pss_to_process; /* total bytes to process */
764 uint64_t pss_processed; /* total processed bytes */
765 uint64_t pss_errors; /* scan errors */
767 /* values not stored on disk */
768 uint64_t pss_pass_exam; /* examined bytes per scan pass */
769 uint64_t pss_pass_start; /* start time of a scan pass */
770 uint64_t pss_pass_scrub_pause; /* pause time of a scurb pass */
771 /* cumulative time scrub spent paused, needed for rate calculation */
772 uint64_t pss_pass_scrub_spent_paused;
775 typedef struct pool_removal_stat {
776 uint64_t prs_state; /* dsl_scan_state_t */
777 uint64_t prs_removing_vdev;
778 uint64_t prs_start_time;
779 uint64_t prs_end_time;
780 uint64_t prs_to_copy; /* bytes that need to be copied */
781 uint64_t prs_copied; /* bytes copied so far */
783 * bytes of memory used for indirect mappings.
784 * This includes all removed vdevs.
786 uint64_t prs_mapping_memory;
787 } pool_removal_stat_t;
789 typedef enum dsl_scan_state {
799 CS_CHECKPOINT_EXISTS,
800 CS_CHECKPOINT_DISCARDING,
802 } checkpoint_state_t;
804 typedef struct pool_checkpoint_stat {
805 uint64_t pcs_state; /* checkpoint_state_t */
806 uint64_t pcs_start_time; /* time checkpoint/discard started */
807 uint64_t pcs_space; /* checkpointed space */
808 } pool_checkpoint_stat_t;
811 * Vdev statistics. Note: all fields should be 64-bit because this
812 * is passed between kernel and userland as an nvlist uint64 array.
814 typedef struct vdev_stat {
815 hrtime_t vs_timestamp; /* time since vdev load */
816 uint64_t vs_state; /* vdev state */
817 uint64_t vs_aux; /* see vdev_aux_t */
818 uint64_t vs_alloc; /* space allocated */
819 uint64_t vs_space; /* total capacity */
820 uint64_t vs_dspace; /* deflated capacity */
821 uint64_t vs_rsize; /* replaceable dev size */
822 uint64_t vs_esize; /* expandable dev size */
823 uint64_t vs_ops[ZIO_TYPES]; /* operation count */
824 uint64_t vs_bytes[ZIO_TYPES]; /* bytes read/written */
825 uint64_t vs_read_errors; /* read errors */
826 uint64_t vs_write_errors; /* write errors */
827 uint64_t vs_checksum_errors; /* checksum errors */
828 uint64_t vs_self_healed; /* self-healed bytes */
829 uint64_t vs_scan_removing; /* removing? */
830 uint64_t vs_scan_processed; /* scan processed bytes */
831 uint64_t vs_configured_ashift; /* TLV vdev_ashift */
832 uint64_t vs_logical_ashift; /* vdev_logical_ashift */
833 uint64_t vs_physical_ashift; /* vdev_physical_ashift */
834 uint64_t vs_fragmentation; /* device fragmentation */
835 uint64_t vs_checkpoint_space; /* checkpoint-consumed space */
837 #define VDEV_STAT_VALID(field, uint64_t_field_count) \
838 ((uint64_t_field_count * sizeof(uint64_t)) >= \
839 (offsetof(vdev_stat_t, field) + sizeof(((vdev_stat_t *)NULL)->field)))
842 * DDT statistics. Note: all fields should be 64-bit because this
843 * is passed between kernel and userland as an nvlist uint64 array.
845 typedef struct ddt_object {
846 uint64_t ddo_count; /* number of elments in ddt */
847 uint64_t ddo_dspace; /* size of ddt on disk */
848 uint64_t ddo_mspace; /* size of ddt in-core */
851 typedef struct ddt_stat {
852 uint64_t dds_blocks; /* blocks */
853 uint64_t dds_lsize; /* logical size */
854 uint64_t dds_psize; /* physical size */
855 uint64_t dds_dsize; /* deflated allocated size */
856 uint64_t dds_ref_blocks; /* referenced blocks */
857 uint64_t dds_ref_lsize; /* referenced lsize * refcnt */
858 uint64_t dds_ref_psize; /* referenced psize * refcnt */
859 uint64_t dds_ref_dsize; /* referenced dsize * refcnt */
862 typedef struct ddt_histogram {
863 ddt_stat_t ddh_stat[64]; /* power-of-two histogram buckets */
866 #define ZVOL_DRIVER "zvol"
867 #define ZFS_DRIVER "zfs"
868 #define ZFS_DEV_NAME "zfs"
869 #define ZFS_DEV "/dev/" ZFS_DEV_NAME
870 #define ZFS_DISK_ROOT "/dev/dsk"
871 #define ZFS_DISK_ROOTD ZFS_DISK_ROOT "/"
872 #define ZFS_RDISK_ROOT "/dev/rdsk"
873 #define ZFS_RDISK_ROOTD ZFS_RDISK_ROOT "/"
875 /* general zvol path */
876 #define ZVOL_DIR "/dev/zvol"
878 #define ZVOL_PSEUDO_DEV "/devices/pseudo/zfs@0:"
879 /* for dump and swap */
880 #define ZVOL_FULL_DEV_DIR ZVOL_DIR "/dsk/"
881 #define ZVOL_FULL_RDEV_DIR ZVOL_DIR "/rdsk/"
883 #define ZVOL_PROP_NAME "name"
884 #define ZVOL_DEFAULT_BLOCKSIZE 8192
887 * /dev/zfs ioctl numbers.
889 typedef enum zfs_ioc {
891 ZFS_IOC_POOL_CREATE = ZFS_IOC_FIRST,
892 ZFS_IOC_POOL_DESTROY,
895 ZFS_IOC_POOL_CONFIGS,
897 ZFS_IOC_POOL_TRYIMPORT,
900 ZFS_IOC_POOL_UPGRADE,
901 ZFS_IOC_POOL_GET_HISTORY,
904 ZFS_IOC_VDEV_SET_STATE,
907 ZFS_IOC_VDEV_SETPATH,
909 ZFS_IOC_OBJSET_STATS,
910 ZFS_IOC_OBJSET_ZPLPROPS,
911 ZFS_IOC_DATASET_LIST_NEXT,
912 ZFS_IOC_SNAPSHOT_LIST_NEXT,
920 ZFS_IOC_INJECT_FAULT,
922 ZFS_IOC_INJECT_LIST_NEXT,
926 ZFS_IOC_DESTROY_SNAPS,
928 ZFS_IOC_DSOBJ_TO_DSNAME,
930 ZFS_IOC_POOL_SET_PROPS,
931 ZFS_IOC_POOL_GET_PROPS,
935 ZFS_IOC_INHERIT_PROP,
937 ZFS_IOC_USERSPACE_ONE,
938 ZFS_IOC_USERSPACE_MANY,
939 ZFS_IOC_USERSPACE_UPGRADE,
943 ZFS_IOC_OBJSET_RECVD_PROPS,
947 ZFS_IOC_TMP_SNAPSHOT,
948 ZFS_IOC_OBJ_TO_STATS,
952 ZFS_IOC_SPACE_WRITTEN,
954 ZFS_IOC_SEND_PROGRESS,
961 ZFS_IOC_GET_BOOKMARKS,
962 ZFS_IOC_DESTROY_BOOKMARKS,
966 ZFS_IOC_CHANNEL_PROGRAM,
968 ZFS_IOC_POOL_CHECKPOINT,
969 ZFS_IOC_POOL_DISCARD_CHECKPOINT,
974 * ZFS-specific error codes used for returning descriptive errors
975 * to the userland through zfs ioctls.
977 * The enum implicitly includes all the error codes from errno.h.
978 * New code should use and extend this enum for errors that are
979 * not described precisely by generic errno codes.
982 ZFS_ERR_CHECKPOINT_EXISTS = 1024,
983 ZFS_ERR_DISCARDING_CHECKPOINT,
984 ZFS_ERR_NO_CHECKPOINT,
985 ZFS_ERR_DEVRM_IN_PROGRESS,
990 * Internal SPA load state. Used by FMA diagnosis engine.
993 SPA_LOAD_NONE, /* no load in progress */
994 SPA_LOAD_OPEN, /* normal open */
995 SPA_LOAD_IMPORT, /* import in progress */
996 SPA_LOAD_TRYIMPORT, /* tryimport in progress */
997 SPA_LOAD_RECOVER, /* recovery requested */
998 SPA_LOAD_ERROR, /* load failed */
999 SPA_LOAD_CREATE /* creation in progress */
1003 * Bookmark name values.
1005 #define ZPOOL_ERR_LIST "error list"
1006 #define ZPOOL_ERR_DATASET "dataset"
1007 #define ZPOOL_ERR_OBJECT "object"
1009 #define HIS_MAX_RECORD_LEN (MAXPATHLEN + MAXPATHLEN + 1)
1012 * The following are names used in the nvlist describing
1013 * the pool's history log.
1015 #define ZPOOL_HIST_RECORD "history record"
1016 #define ZPOOL_HIST_TIME "history time"
1017 #define ZPOOL_HIST_CMD "history command"
1018 #define ZPOOL_HIST_WHO "history who"
1019 #define ZPOOL_HIST_ZONE "history zone"
1020 #define ZPOOL_HIST_HOST "history hostname"
1021 #define ZPOOL_HIST_TXG "history txg"
1022 #define ZPOOL_HIST_INT_EVENT "history internal event"
1023 #define ZPOOL_HIST_INT_STR "history internal str"
1024 #define ZPOOL_HIST_INT_NAME "internal_name"
1025 #define ZPOOL_HIST_IOCTL "ioctl"
1026 #define ZPOOL_HIST_INPUT_NVL "in_nvl"
1027 #define ZPOOL_HIST_OUTPUT_NVL "out_nvl"
1028 #define ZPOOL_HIST_DSNAME "dsname"
1029 #define ZPOOL_HIST_DSID "dsid"
1030 #define ZPOOL_HIST_ERRNO "errno"
1033 * Flags for ZFS_IOC_VDEV_SET_STATE
1035 #define ZFS_ONLINE_CHECKREMOVE 0x1
1036 #define ZFS_ONLINE_UNSPARE 0x2
1037 #define ZFS_ONLINE_FORCEFAULT 0x4
1038 #define ZFS_ONLINE_EXPAND 0x8
1039 #define ZFS_OFFLINE_TEMPORARY 0x1
1042 * Flags for ZFS_IOC_POOL_IMPORT
1044 #define ZFS_IMPORT_NORMAL 0x0
1045 #define ZFS_IMPORT_VERBATIM 0x1
1046 #define ZFS_IMPORT_ANY_HOST 0x2
1047 #define ZFS_IMPORT_MISSING_LOG 0x4
1048 #define ZFS_IMPORT_ONLY 0x8
1049 #define ZFS_IMPORT_CHECKPOINT 0x10
1052 * Channel program argument/return nvlist keys and defaults.
1054 #define ZCP_ARG_PROGRAM "program"
1055 #define ZCP_ARG_ARGLIST "arg"
1056 #define ZCP_ARG_SYNC "sync"
1057 #define ZCP_ARG_INSTRLIMIT "instrlimit"
1058 #define ZCP_ARG_MEMLIMIT "memlimit"
1060 #define ZCP_ARG_CLIARGV "argv"
1062 #define ZCP_RET_ERROR "error"
1063 #define ZCP_RET_RETURN "return"
1065 #define ZCP_DEFAULT_INSTRLIMIT (10 * 1000 * 1000)
1066 #define ZCP_MAX_INSTRLIMIT (10 * ZCP_DEFAULT_INSTRLIMIT)
1067 #define ZCP_DEFAULT_MEMLIMIT (10 * 1024 * 1024)
1068 #define ZCP_MAX_MEMLIMIT (10 * ZCP_DEFAULT_MEMLIMIT)
1071 * Sysevent payload members. ZFS will generate the following sysevents with the
1074 * ESC_ZFS_RESILVER_START
1075 * ESC_ZFS_RESILVER_END
1076 * ESC_ZFS_POOL_DESTROY
1077 * ESC_ZFS_POOL_REGUID
1079 * ZFS_EV_POOL_NAME DATA_TYPE_STRING
1080 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64
1082 * ESC_ZFS_VDEV_REMOVE
1083 * ESC_ZFS_VDEV_CLEAR
1084 * ESC_ZFS_VDEV_CHECK
1086 * ZFS_EV_POOL_NAME DATA_TYPE_STRING
1087 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64
1088 * ZFS_EV_VDEV_PATH DATA_TYPE_STRING (optional)
1089 * ZFS_EV_VDEV_GUID DATA_TYPE_UINT64
1091 * ESC_ZFS_HISTORY_EVENT
1093 * ZFS_EV_POOL_NAME DATA_TYPE_STRING
1094 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64
1095 * ZFS_EV_HIST_TIME DATA_TYPE_UINT64 (optional)
1096 * ZFS_EV_HIST_CMD DATA_TYPE_STRING (optional)
1097 * ZFS_EV_HIST_WHO DATA_TYPE_UINT64 (optional)
1098 * ZFS_EV_HIST_ZONE DATA_TYPE_STRING (optional)
1099 * ZFS_EV_HIST_HOST DATA_TYPE_STRING (optional)
1100 * ZFS_EV_HIST_TXG DATA_TYPE_UINT64 (optional)
1101 * ZFS_EV_HIST_INT_EVENT DATA_TYPE_UINT64 (optional)
1102 * ZFS_EV_HIST_INT_STR DATA_TYPE_STRING (optional)
1103 * ZFS_EV_HIST_INT_NAME DATA_TYPE_STRING (optional)
1104 * ZFS_EV_HIST_IOCTL DATA_TYPE_STRING (optional)
1105 * ZFS_EV_HIST_DSNAME DATA_TYPE_STRING (optional)
1106 * ZFS_EV_HIST_DSID DATA_TYPE_UINT64 (optional)
1108 * The ZFS_EV_HIST_* members will correspond to the ZPOOL_HIST_* members in the
1109 * history log nvlist. The keynames will be free of any spaces or other
1110 * characters that could be potentially unexpected to consumers of the
1113 #define ZFS_EV_POOL_NAME "pool_name"
1114 #define ZFS_EV_POOL_GUID "pool_guid"
1115 #define ZFS_EV_VDEV_PATH "vdev_path"
1116 #define ZFS_EV_VDEV_GUID "vdev_guid"
1117 #define ZFS_EV_HIST_TIME "history_time"
1118 #define ZFS_EV_HIST_CMD "history_command"
1119 #define ZFS_EV_HIST_WHO "history_who"
1120 #define ZFS_EV_HIST_ZONE "history_zone"
1121 #define ZFS_EV_HIST_HOST "history_hostname"
1122 #define ZFS_EV_HIST_TXG "history_txg"
1123 #define ZFS_EV_HIST_INT_EVENT "history_internal_event"
1124 #define ZFS_EV_HIST_INT_STR "history_internal_str"
1125 #define ZFS_EV_HIST_INT_NAME "history_internal_name"
1126 #define ZFS_EV_HIST_IOCTL "history_ioctl"
1127 #define ZFS_EV_HIST_DSNAME "history_dsname"
1128 #define ZFS_EV_HIST_DSID "history_dsid"
1134 #endif /* _SYS_FS_ZFS_H */