]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/cddl/contrib/opensolaris/uts/common/sys/fs/zfs.h
Merge once more from ^/vendor/llvm-project/release-10.x, to get the
[FreeBSD/FreeBSD.git] / sys / cddl / contrib / opensolaris / uts / common / sys / fs / zfs.h
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21
22 /*
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) 2019 Datto Inc.
30  * Copyright (c) 2017, Intel Corporation.
31  */
32
33 /* Portions Copyright 2010 Robert Milkowski */
34
35 #ifndef _SYS_FS_ZFS_H
36 #define _SYS_FS_ZFS_H
37
38 #include <sys/types.h>
39 #include <sys/ioccom.h>
40 #include <sys/time.h>
41
42 #ifdef  __cplusplus
43 extern "C" {
44 #endif
45
46 /*
47  * Types and constants shared between userland and the kernel.
48  */
49
50 /*
51  * Each dataset can be one of the following types.  These constants can be
52  * combined into masks that can be passed to various functions.
53  */
54 typedef enum {
55         ZFS_TYPE_FILESYSTEM     = (1 << 0),
56         ZFS_TYPE_SNAPSHOT       = (1 << 1),
57         ZFS_TYPE_VOLUME         = (1 << 2),
58         ZFS_TYPE_POOL           = (1 << 3),
59         ZFS_TYPE_BOOKMARK       = (1 << 4)
60 } zfs_type_t;
61
62 /*
63  * NB: lzc_dataset_type should be updated whenever a new objset type is added,
64  * if it represents a real type of a dataset that can be created from userland.
65  */
66 typedef enum dmu_objset_type {
67         DMU_OST_NONE,
68         DMU_OST_META,
69         DMU_OST_ZFS,
70         DMU_OST_ZVOL,
71         DMU_OST_OTHER,                  /* For testing only! */
72         DMU_OST_ANY,                    /* Be careful! */
73         DMU_OST_NUMTYPES
74 } dmu_objset_type_t;
75
76 #define ZFS_TYPE_DATASET        \
77         (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME | ZFS_TYPE_SNAPSHOT)
78
79 /*
80  * All of these include the terminating NUL byte.
81  */
82 #define ZAP_MAXNAMELEN 256
83 #define ZAP_MAXVALUELEN (1024 * 8)
84 #define ZAP_OLDMAXVALUELEN 1024
85 #define ZFS_MAX_DATASET_NAME_LEN 256
86
87 /*
88  * Dataset properties are identified by these constants and must be added to
89  * the end of this list to ensure that external consumers are not affected
90  * by the change. If you make any changes to this list, be sure to update
91  * the property table in usr/src/common/zfs/zfs_prop.c.
92  */
93 typedef enum {
94         ZPROP_CONT = -2,
95         ZPROP_INVAL = -1,
96         ZFS_PROP_TYPE = 0,
97         ZFS_PROP_CREATION,
98         ZFS_PROP_USED,
99         ZFS_PROP_AVAILABLE,
100         ZFS_PROP_REFERENCED,
101         ZFS_PROP_COMPRESSRATIO,
102         ZFS_PROP_MOUNTED,
103         ZFS_PROP_ORIGIN,
104         ZFS_PROP_QUOTA,
105         ZFS_PROP_RESERVATION,
106         ZFS_PROP_VOLSIZE,
107         ZFS_PROP_VOLBLOCKSIZE,
108         ZFS_PROP_RECORDSIZE,
109         ZFS_PROP_MOUNTPOINT,
110         ZFS_PROP_SHARENFS,
111         ZFS_PROP_CHECKSUM,
112         ZFS_PROP_COMPRESSION,
113         ZFS_PROP_ATIME,
114         ZFS_PROP_DEVICES,
115         ZFS_PROP_EXEC,
116         ZFS_PROP_SETUID,
117         ZFS_PROP_READONLY,
118         ZFS_PROP_ZONED,
119         ZFS_PROP_SNAPDIR,
120         ZFS_PROP_ACLMODE,
121         ZFS_PROP_ACLINHERIT,
122         ZFS_PROP_CREATETXG,
123         ZFS_PROP_NAME,                  /* not exposed to the user */
124         ZFS_PROP_CANMOUNT,
125         ZFS_PROP_ISCSIOPTIONS,          /* not exposed to the user */
126         ZFS_PROP_XATTR,
127         ZFS_PROP_NUMCLONES,             /* not exposed to the user */
128         ZFS_PROP_COPIES,
129         ZFS_PROP_VERSION,
130         ZFS_PROP_UTF8ONLY,
131         ZFS_PROP_NORMALIZE,
132         ZFS_PROP_CASE,
133         ZFS_PROP_VSCAN,
134         ZFS_PROP_NBMAND,
135         ZFS_PROP_SHARESMB,
136         ZFS_PROP_REFQUOTA,
137         ZFS_PROP_REFRESERVATION,
138         ZFS_PROP_GUID,
139         ZFS_PROP_PRIMARYCACHE,
140         ZFS_PROP_SECONDARYCACHE,
141         ZFS_PROP_USEDSNAP,
142         ZFS_PROP_USEDDS,
143         ZFS_PROP_USEDCHILD,
144         ZFS_PROP_USEDREFRESERV,
145         ZFS_PROP_USERACCOUNTING,        /* not exposed to the user */
146         ZFS_PROP_STMF_SHAREINFO,        /* not exposed to the user */
147         ZFS_PROP_DEFER_DESTROY,
148         ZFS_PROP_USERREFS,
149         ZFS_PROP_LOGBIAS,
150         ZFS_PROP_UNIQUE,                /* not exposed to the user */
151         ZFS_PROP_OBJSETID,              /* not exposed to the user */
152         ZFS_PROP_DEDUP,
153         ZFS_PROP_MLSLABEL,
154         ZFS_PROP_SYNC,
155         ZFS_PROP_DNODESIZE,
156         ZFS_PROP_REFRATIO,
157         ZFS_PROP_WRITTEN,
158         ZFS_PROP_CLONES,
159         ZFS_PROP_LOGICALUSED,
160         ZFS_PROP_LOGICALREFERENCED,
161         ZFS_PROP_INCONSISTENT,          /* not exposed to the user */
162         ZFS_PROP_VOLMODE,
163         ZFS_PROP_FILESYSTEM_LIMIT,
164         ZFS_PROP_SNAPSHOT_LIMIT,
165         ZFS_PROP_FILESYSTEM_COUNT,
166         ZFS_PROP_SNAPSHOT_COUNT,
167         ZFS_PROP_REDUNDANT_METADATA,
168         ZFS_PROP_PREV_SNAP,
169         ZFS_PROP_RECEIVE_RESUME_TOKEN,
170         ZFS_PROP_REMAPTXG,              /* not exposed to the user */
171         ZFS_PROP_SPECIAL_SMALL_BLOCKS,
172         ZFS_NUM_PROPS
173 } zfs_prop_t;
174
175 typedef enum {
176         ZFS_PROP_USERUSED,
177         ZFS_PROP_USERQUOTA,
178         ZFS_PROP_GROUPUSED,
179         ZFS_PROP_GROUPQUOTA,
180         ZFS_NUM_USERQUOTA_PROPS
181 } zfs_userquota_prop_t;
182
183 extern const char *zfs_userquota_prop_prefixes[ZFS_NUM_USERQUOTA_PROPS];
184
185 /*
186  * Pool properties are identified by these constants and must be added to the
187  * end of this list to ensure that external consumers are not affected
188  * by the change. If you make any changes to this list, be sure to update
189  * the property table in usr/src/common/zfs/zpool_prop.c.
190  */
191 typedef enum {
192         ZPOOL_PROP_INVAL = -1,
193         ZPOOL_PROP_NAME,
194         ZPOOL_PROP_SIZE,
195         ZPOOL_PROP_CAPACITY,
196         ZPOOL_PROP_ALTROOT,
197         ZPOOL_PROP_HEALTH,
198         ZPOOL_PROP_GUID,
199         ZPOOL_PROP_VERSION,
200         ZPOOL_PROP_BOOTFS,
201         ZPOOL_PROP_DELEGATION,
202         ZPOOL_PROP_AUTOREPLACE,
203         ZPOOL_PROP_CACHEFILE,
204         ZPOOL_PROP_FAILUREMODE,
205         ZPOOL_PROP_LISTSNAPS,
206         ZPOOL_PROP_AUTOEXPAND,
207         ZPOOL_PROP_DEDUPDITTO,
208         ZPOOL_PROP_DEDUPRATIO,
209         ZPOOL_PROP_FREE,
210         ZPOOL_PROP_ALLOCATED,
211         ZPOOL_PROP_READONLY,
212         ZPOOL_PROP_COMMENT,
213         ZPOOL_PROP_EXPANDSZ,
214         ZPOOL_PROP_FREEING,
215         ZPOOL_PROP_FRAGMENTATION,
216         ZPOOL_PROP_LEAKED,
217         ZPOOL_PROP_MAXBLOCKSIZE,
218         ZPOOL_PROP_BOOTSIZE,
219         ZPOOL_PROP_CHECKPOINT,
220         ZPOOL_PROP_TNAME,
221         ZPOOL_PROP_MAXDNODESIZE,
222         ZPOOL_PROP_MULTIHOST,
223         ZPOOL_NUM_PROPS
224 } zpool_prop_t;
225
226 /* Small enough to not hog a whole line of printout in zpool(1M). */
227 #define ZPROP_MAX_COMMENT       32
228
229 #define ZPROP_VALUE             "value"
230 #define ZPROP_SOURCE            "source"
231
232 typedef enum {
233         ZPROP_SRC_NONE = 0x1,
234         ZPROP_SRC_DEFAULT = 0x2,
235         ZPROP_SRC_TEMPORARY = 0x4,
236         ZPROP_SRC_LOCAL = 0x8,
237         ZPROP_SRC_INHERITED = 0x10,
238         ZPROP_SRC_RECEIVED = 0x20
239 } zprop_source_t;
240
241 #define ZPROP_SRC_ALL   0x3f
242
243 #define ZPROP_SOURCE_VAL_RECVD  "$recvd"
244 #define ZPROP_N_MORE_ERRORS     "N_MORE_ERRORS"
245 /*
246  * Dataset flag implemented as a special entry in the props zap object
247  * indicating that the dataset has received properties on or after
248  * SPA_VERSION_RECVD_PROPS. The first such receive blows away local properties
249  * just as it did in earlier versions, and thereafter, local properties are
250  * preserved.
251  */
252 #define ZPROP_HAS_RECVD         "$hasrecvd"
253
254 typedef enum {
255         ZPROP_ERR_NOCLEAR = 0x1, /* failure to clear existing props */
256         ZPROP_ERR_NORESTORE = 0x2 /* failure to restore props on error */
257 } zprop_errflags_t;
258
259 typedef int (*zprop_func)(int, void *);
260
261 /*
262  * Properties to be set on the root file system of a new pool
263  * are stuffed into their own nvlist, which is then included in
264  * the properties nvlist with the pool properties.
265  */
266 #define ZPOOL_ROOTFS_PROPS      "root-props-nvl"
267
268 /*
269  * Length of 'written@' and 'written#'
270  */
271 #define ZFS_WRITTEN_PROP_PREFIX_LEN     8
272
273 /*
274  * Dataset property functions shared between libzfs and kernel.
275  */
276 const char *zfs_prop_default_string(zfs_prop_t);
277 uint64_t zfs_prop_default_numeric(zfs_prop_t);
278 boolean_t zfs_prop_readonly(zfs_prop_t);
279 boolean_t zfs_prop_visible(zfs_prop_t prop);
280 boolean_t zfs_prop_inheritable(zfs_prop_t);
281 boolean_t zfs_prop_setonce(zfs_prop_t);
282 const char *zfs_prop_to_name(zfs_prop_t);
283 zfs_prop_t zfs_name_to_prop(const char *);
284 boolean_t zfs_prop_user(const char *);
285 boolean_t zfs_prop_userquota(const char *);
286 int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
287 int zfs_prop_string_to_index(zfs_prop_t, const char *, uint64_t *);
288 uint64_t zfs_prop_random_value(zfs_prop_t, uint64_t seed);
289 boolean_t zfs_prop_valid_for_type(int, zfs_type_t);
290
291 /*
292  * Pool property functions shared between libzfs and kernel.
293  */
294 zpool_prop_t zpool_name_to_prop(const char *);
295 const char *zpool_prop_to_name(zpool_prop_t);
296 const char *zpool_prop_default_string(zpool_prop_t);
297 uint64_t zpool_prop_default_numeric(zpool_prop_t);
298 boolean_t zpool_prop_readonly(zpool_prop_t);
299 boolean_t zpool_prop_feature(const char *);
300 boolean_t zpool_prop_unsupported(const char *name);
301 int zpool_prop_index_to_string(zpool_prop_t, uint64_t, const char **);
302 int zpool_prop_string_to_index(zpool_prop_t, const char *, uint64_t *);
303 uint64_t zpool_prop_random_value(zpool_prop_t, uint64_t seed);
304
305 /*
306  * Definitions for the Delegation.
307  */
308 typedef enum {
309         ZFS_DELEG_WHO_UNKNOWN = 0,
310         ZFS_DELEG_USER = 'u',
311         ZFS_DELEG_USER_SETS = 'U',
312         ZFS_DELEG_GROUP = 'g',
313         ZFS_DELEG_GROUP_SETS = 'G',
314         ZFS_DELEG_EVERYONE = 'e',
315         ZFS_DELEG_EVERYONE_SETS = 'E',
316         ZFS_DELEG_CREATE = 'c',
317         ZFS_DELEG_CREATE_SETS = 'C',
318         ZFS_DELEG_NAMED_SET = 's',
319         ZFS_DELEG_NAMED_SET_SETS = 'S'
320 } zfs_deleg_who_type_t;
321
322 typedef enum {
323         ZFS_DELEG_NONE = 0,
324         ZFS_DELEG_PERM_LOCAL = 1,
325         ZFS_DELEG_PERM_DESCENDENT = 2,
326         ZFS_DELEG_PERM_LOCALDESCENDENT = 3,
327         ZFS_DELEG_PERM_CREATE = 4
328 } zfs_deleg_inherit_t;
329
330 #define ZFS_DELEG_PERM_UID      "uid"
331 #define ZFS_DELEG_PERM_GID      "gid"
332 #define ZFS_DELEG_PERM_GROUPS   "groups"
333
334 #define ZFS_MLSLABEL_DEFAULT    "none"
335
336 #define ZFS_SMB_ACL_SRC         "src"
337 #define ZFS_SMB_ACL_TARGET      "target"
338
339 typedef enum {
340         ZFS_CANMOUNT_OFF = 0,
341         ZFS_CANMOUNT_ON = 1,
342         ZFS_CANMOUNT_NOAUTO = 2
343 } zfs_canmount_type_t;
344
345 typedef enum {
346         ZFS_LOGBIAS_LATENCY = 0,
347         ZFS_LOGBIAS_THROUGHPUT = 1
348 } zfs_logbias_op_t;
349
350 typedef enum zfs_share_op {
351         ZFS_SHARE_NFS = 0,
352         ZFS_UNSHARE_NFS = 1,
353         ZFS_SHARE_SMB = 2,
354         ZFS_UNSHARE_SMB = 3
355 } zfs_share_op_t;
356
357 typedef enum zfs_smb_acl_op {
358         ZFS_SMB_ACL_ADD,
359         ZFS_SMB_ACL_REMOVE,
360         ZFS_SMB_ACL_RENAME,
361         ZFS_SMB_ACL_PURGE
362 } zfs_smb_acl_op_t;
363
364 typedef enum zfs_cache_type {
365         ZFS_CACHE_NONE = 0,
366         ZFS_CACHE_METADATA = 1,
367         ZFS_CACHE_ALL = 2
368 } zfs_cache_type_t;
369
370 typedef enum {
371         ZFS_SYNC_STANDARD = 0,
372         ZFS_SYNC_ALWAYS = 1,
373         ZFS_SYNC_DISABLED = 2
374 } zfs_sync_type_t;
375
376 typedef enum {
377         ZFS_VOLMODE_DEFAULT = 0,
378         ZFS_VOLMODE_GEOM = 1,
379         ZFS_VOLMODE_DEV = 2,
380         ZFS_VOLMODE_NONE = 3
381 } zfs_volmode_t;
382
383 typedef enum {
384         ZFS_DNSIZE_LEGACY = 0,
385         ZFS_DNSIZE_AUTO = 1,
386         ZFS_DNSIZE_1K = 1024,
387         ZFS_DNSIZE_2K = 2048,
388         ZFS_DNSIZE_4K = 4096,
389         ZFS_DNSIZE_8K = 8192,
390         ZFS_DNSIZE_16K = 16384
391 } zfs_dnsize_type_t;
392
393 typedef enum {
394         ZFS_REDUNDANT_METADATA_ALL,
395         ZFS_REDUNDANT_METADATA_MOST
396 } zfs_redundant_metadata_type_t;
397
398 /*
399  * On-disk version number.
400  */
401 #define SPA_VERSION_1                   1ULL
402 #define SPA_VERSION_2                   2ULL
403 #define SPA_VERSION_3                   3ULL
404 #define SPA_VERSION_4                   4ULL
405 #define SPA_VERSION_5                   5ULL
406 #define SPA_VERSION_6                   6ULL
407 #define SPA_VERSION_7                   7ULL
408 #define SPA_VERSION_8                   8ULL
409 #define SPA_VERSION_9                   9ULL
410 #define SPA_VERSION_10                  10ULL
411 #define SPA_VERSION_11                  11ULL
412 #define SPA_VERSION_12                  12ULL
413 #define SPA_VERSION_13                  13ULL
414 #define SPA_VERSION_14                  14ULL
415 #define SPA_VERSION_15                  15ULL
416 #define SPA_VERSION_16                  16ULL
417 #define SPA_VERSION_17                  17ULL
418 #define SPA_VERSION_18                  18ULL
419 #define SPA_VERSION_19                  19ULL
420 #define SPA_VERSION_20                  20ULL
421 #define SPA_VERSION_21                  21ULL
422 #define SPA_VERSION_22                  22ULL
423 #define SPA_VERSION_23                  23ULL
424 #define SPA_VERSION_24                  24ULL
425 #define SPA_VERSION_25                  25ULL
426 #define SPA_VERSION_26                  26ULL
427 #define SPA_VERSION_27                  27ULL
428 #define SPA_VERSION_28                  28ULL
429 #define SPA_VERSION_5000                5000ULL
430
431 /*
432  * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk
433  * format change. Go to usr/src/grub/grub-0.97/stage2/{zfs-include/, fsys_zfs*},
434  * and do the appropriate changes.  Also bump the version number in
435  * usr/src/grub/capability.
436  */
437 #define SPA_VERSION                     SPA_VERSION_5000
438 #define SPA_VERSION_STRING              "5000"
439
440 /*
441  * Symbolic names for the changes that caused a SPA_VERSION switch.
442  * Used in the code when checking for presence or absence of a feature.
443  * Feel free to define multiple symbolic names for each version if there
444  * were multiple changes to on-disk structures during that version.
445  *
446  * NOTE: When checking the current SPA_VERSION in your code, be sure
447  *       to use spa_version() since it reports the version of the
448  *       last synced uberblock.  Checking the in-flight version can
449  *       be dangerous in some cases.
450  */
451 #define SPA_VERSION_INITIAL             SPA_VERSION_1
452 #define SPA_VERSION_DITTO_BLOCKS        SPA_VERSION_2
453 #define SPA_VERSION_SPARES              SPA_VERSION_3
454 #define SPA_VERSION_RAIDZ2              SPA_VERSION_3
455 #define SPA_VERSION_BPOBJ_ACCOUNT       SPA_VERSION_3
456 #define SPA_VERSION_RAIDZ_DEFLATE       SPA_VERSION_3
457 #define SPA_VERSION_DNODE_BYTES         SPA_VERSION_3
458 #define SPA_VERSION_ZPOOL_HISTORY       SPA_VERSION_4
459 #define SPA_VERSION_GZIP_COMPRESSION    SPA_VERSION_5
460 #define SPA_VERSION_BOOTFS              SPA_VERSION_6
461 #define SPA_VERSION_SLOGS               SPA_VERSION_7
462 #define SPA_VERSION_DELEGATED_PERMS     SPA_VERSION_8
463 #define SPA_VERSION_FUID                SPA_VERSION_9
464 #define SPA_VERSION_REFRESERVATION      SPA_VERSION_9
465 #define SPA_VERSION_REFQUOTA            SPA_VERSION_9
466 #define SPA_VERSION_UNIQUE_ACCURATE     SPA_VERSION_9
467 #define SPA_VERSION_L2CACHE             SPA_VERSION_10
468 #define SPA_VERSION_NEXT_CLONES         SPA_VERSION_11
469 #define SPA_VERSION_ORIGIN              SPA_VERSION_11
470 #define SPA_VERSION_DSL_SCRUB           SPA_VERSION_11
471 #define SPA_VERSION_SNAP_PROPS          SPA_VERSION_12
472 #define SPA_VERSION_USED_BREAKDOWN      SPA_VERSION_13
473 #define SPA_VERSION_PASSTHROUGH_X       SPA_VERSION_14
474 #define SPA_VERSION_USERSPACE           SPA_VERSION_15
475 #define SPA_VERSION_STMF_PROP           SPA_VERSION_16
476 #define SPA_VERSION_RAIDZ3              SPA_VERSION_17
477 #define SPA_VERSION_USERREFS            SPA_VERSION_18
478 #define SPA_VERSION_HOLES               SPA_VERSION_19
479 #define SPA_VERSION_ZLE_COMPRESSION     SPA_VERSION_20
480 #define SPA_VERSION_DEDUP               SPA_VERSION_21
481 #define SPA_VERSION_RECVD_PROPS         SPA_VERSION_22
482 #define SPA_VERSION_SLIM_ZIL            SPA_VERSION_23
483 #define SPA_VERSION_SA                  SPA_VERSION_24
484 #define SPA_VERSION_SCAN                SPA_VERSION_25
485 #define SPA_VERSION_DIR_CLONES          SPA_VERSION_26
486 #define SPA_VERSION_DEADLISTS           SPA_VERSION_26
487 #define SPA_VERSION_FAST_SNAP           SPA_VERSION_27
488 #define SPA_VERSION_MULTI_REPLACE       SPA_VERSION_28
489 #define SPA_VERSION_BEFORE_FEATURES     SPA_VERSION_28
490 #define SPA_VERSION_FEATURES            SPA_VERSION_5000
491
492 #define SPA_VERSION_IS_SUPPORTED(v) \
493         (((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \
494         ((v) >= SPA_VERSION_FEATURES && (v) <= SPA_VERSION))
495
496 /*
497  * ZPL version - rev'd whenever an incompatible on-disk format change
498  * occurs.  This is independent of SPA/DMU/ZAP versioning.  You must
499  * also update the version_table[] and help message in zfs_prop.c.
500  *
501  * When changing, be sure to teach GRUB how to read the new format!
502  * See usr/src/grub/grub-0.97/stage2/{zfs-include/,fsys_zfs*}
503  */
504 #define ZPL_VERSION_1                   1ULL
505 #define ZPL_VERSION_2                   2ULL
506 #define ZPL_VERSION_3                   3ULL
507 #define ZPL_VERSION_4                   4ULL
508 #define ZPL_VERSION_5                   5ULL
509 #define ZPL_VERSION                     ZPL_VERSION_5
510 #define ZPL_VERSION_STRING              "5"
511
512 #define ZPL_VERSION_INITIAL             ZPL_VERSION_1
513 #define ZPL_VERSION_DIRENT_TYPE         ZPL_VERSION_2
514 #define ZPL_VERSION_FUID                ZPL_VERSION_3
515 #define ZPL_VERSION_NORMALIZATION       ZPL_VERSION_3
516 #define ZPL_VERSION_SYSATTR             ZPL_VERSION_3
517 #define ZPL_VERSION_USERSPACE           ZPL_VERSION_4
518 #define ZPL_VERSION_SA                  ZPL_VERSION_5
519
520 /* Rewind policy information */
521 #define ZPOOL_NO_REWIND         1  /* No policy - default behavior */
522 #define ZPOOL_NEVER_REWIND      2  /* Do not search for best txg or rewind */
523 #define ZPOOL_TRY_REWIND        4  /* Search for best txg, but do not rewind */
524 #define ZPOOL_DO_REWIND         8  /* Rewind to best txg w/in deferred frees */
525 #define ZPOOL_EXTREME_REWIND    16 /* Allow extreme measures to find best txg */
526 #define ZPOOL_REWIND_MASK       28 /* All the possible rewind bits */
527 #define ZPOOL_REWIND_POLICIES   31 /* All the possible policy bits */
528
529 typedef struct zpool_load_policy {
530         uint32_t        zlp_rewind;     /* rewind policy requested */
531         uint64_t        zlp_maxmeta;    /* max acceptable meta-data errors */
532         uint64_t        zlp_maxdata;    /* max acceptable data errors */
533         uint64_t        zlp_txg;        /* specific txg to load */
534 } zpool_load_policy_t;
535
536 /*
537  * The following are configuration names used in the nvlist describing a pool's
538  * configuration.  New on-disk names should be prefixed with "<reverse-DNS>:"
539  * (e.g. "org.open-zfs:") to avoid conflicting names being developed
540  * independently.
541  */
542 #define ZPOOL_CONFIG_VERSION            "version"
543 #define ZPOOL_CONFIG_POOL_NAME          "name"
544 #define ZPOOL_CONFIG_POOL_STATE         "state"
545 #define ZPOOL_CONFIG_POOL_TXG           "txg"
546 #define ZPOOL_CONFIG_POOL_GUID          "pool_guid"
547 #define ZPOOL_CONFIG_CREATE_TXG         "create_txg"
548 #define ZPOOL_CONFIG_TOP_GUID           "top_guid"
549 #define ZPOOL_CONFIG_VDEV_TREE          "vdev_tree"
550 #define ZPOOL_CONFIG_TYPE               "type"
551 #define ZPOOL_CONFIG_CHILDREN           "children"
552 #define ZPOOL_CONFIG_ID                 "id"
553 #define ZPOOL_CONFIG_GUID               "guid"
554 #define ZPOOL_CONFIG_INDIRECT_OBJECT    "com.delphix:indirect_object"
555 #define ZPOOL_CONFIG_INDIRECT_BIRTHS    "com.delphix:indirect_births"
556 #define ZPOOL_CONFIG_PREV_INDIRECT_VDEV "com.delphix:prev_indirect_vdev"
557 #define ZPOOL_CONFIG_PATH               "path"
558 #define ZPOOL_CONFIG_DEVID              "devid"
559 #define ZPOOL_CONFIG_METASLAB_ARRAY     "metaslab_array"
560 #define ZPOOL_CONFIG_METASLAB_SHIFT     "metaslab_shift"
561 #define ZPOOL_CONFIG_ASHIFT             "ashift"
562 #define ZPOOL_CONFIG_ASIZE              "asize"
563 #define ZPOOL_CONFIG_DTL                "DTL"
564 #define ZPOOL_CONFIG_SCAN_STATS         "scan_stats"    /* not stored on disk */
565 #define ZPOOL_CONFIG_REMOVAL_STATS      "removal_stats" /* not stored on disk */
566 #define ZPOOL_CONFIG_CHECKPOINT_STATS   "checkpoint_stats" /* not on disk */
567 #define ZPOOL_CONFIG_VDEV_STATS         "vdev_stats"    /* not stored on disk */
568 #define ZPOOL_CONFIG_INDIRECT_SIZE      "indirect_size" /* not stored on disk */
569 #define ZPOOL_CONFIG_WHOLE_DISK         "whole_disk"
570 #define ZPOOL_CONFIG_ERRCOUNT           "error_count"
571 #define ZPOOL_CONFIG_NOT_PRESENT        "not_present"
572 #define ZPOOL_CONFIG_SPARES             "spares"
573 #define ZPOOL_CONFIG_IS_SPARE           "is_spare"
574 #define ZPOOL_CONFIG_NPARITY            "nparity"
575 #define ZPOOL_CONFIG_HOSTID             "hostid"
576 #define ZPOOL_CONFIG_HOSTNAME           "hostname"
577 #define ZPOOL_CONFIG_LOADED_TIME        "initial_load_time"
578 #define ZPOOL_CONFIG_UNSPARE            "unspare"
579 #define ZPOOL_CONFIG_PHYS_PATH          "phys_path"
580 #define ZPOOL_CONFIG_IS_LOG             "is_log"
581 #define ZPOOL_CONFIG_L2CACHE            "l2cache"
582 #define ZPOOL_CONFIG_HOLE_ARRAY         "hole_array"
583 #define ZPOOL_CONFIG_VDEV_CHILDREN      "vdev_children"
584 #define ZPOOL_CONFIG_IS_HOLE            "is_hole"
585 #define ZPOOL_CONFIG_DDT_HISTOGRAM      "ddt_histogram"
586 #define ZPOOL_CONFIG_DDT_OBJ_STATS      "ddt_object_stats"
587 #define ZPOOL_CONFIG_DDT_STATS          "ddt_stats"
588 #define ZPOOL_CONFIG_SPLIT              "splitcfg"
589 #define ZPOOL_CONFIG_ORIG_GUID          "orig_guid"
590 #define ZPOOL_CONFIG_SPLIT_GUID         "split_guid"
591 #define ZPOOL_CONFIG_SPLIT_LIST         "guid_list"
592 #define ZPOOL_CONFIG_REMOVING           "removing"
593 #define ZPOOL_CONFIG_RESILVER_TXG       "resilver_txg"
594 #define ZPOOL_CONFIG_COMMENT            "comment"
595 #define ZPOOL_CONFIG_SUSPENDED          "suspended"     /* not stored on disk */
596 #define ZPOOL_CONFIG_SUSPENDED_REASON   "suspended_reason"      /* not stored */
597 #define ZPOOL_CONFIG_TIMESTAMP          "timestamp"     /* not stored on disk */
598 #define ZPOOL_CONFIG_BOOTFS             "bootfs"        /* not stored on disk */
599 #define ZPOOL_CONFIG_MISSING_DEVICES    "missing_vdevs" /* not stored on disk */
600 #define ZPOOL_CONFIG_LOAD_INFO          "load_info"     /* not stored on disk */
601 #define ZPOOL_CONFIG_REWIND_INFO        "rewind_info"   /* not stored on disk */
602 #define ZPOOL_CONFIG_UNSUP_FEAT         "unsup_feat"    /* not stored on disk */
603 #define ZPOOL_CONFIG_ENABLED_FEAT       "enabled_feat"  /* not stored on disk */
604 #define ZPOOL_CONFIG_CAN_RDONLY         "can_rdonly"    /* not stored on disk */
605 #define ZPOOL_CONFIG_FEATURES_FOR_READ  "features_for_read"
606 #define ZPOOL_CONFIG_FEATURE_STATS      "feature_stats" /* not stored on disk */
607 #define ZPOOL_CONFIG_VDEV_TOP_ZAP       "com.delphix:vdev_zap_top"
608 #define ZPOOL_CONFIG_VDEV_LEAF_ZAP      "com.delphix:vdev_zap_leaf"
609 #define ZPOOL_CONFIG_HAS_PER_VDEV_ZAPS  "com.delphix:has_per_vdev_zaps"
610 #define ZPOOL_CONFIG_CACHEFILE          "cachefile"     /* not stored on disk */
611 #define ZPOOL_CONFIG_MMP_STATE          "mmp_state"     /* not stored on disk */
612 #define ZPOOL_CONFIG_MMP_TXG            "mmp_txg"       /* not stored on disk */
613 #define ZPOOL_CONFIG_MMP_SEQ            "mmp_seq"       /* not stored on disk */
614 #define ZPOOL_CONFIG_MMP_HOSTNAME       "mmp_hostname"  /* not stored on disk */
615 #define ZPOOL_CONFIG_MMP_HOSTID         "mmp_hostid"    /* not stored on disk */
616 #define ZPOOL_CONFIG_ALLOCATION_BIAS    "alloc_bias"    /* not stored on disk */
617
618 /*
619  * The persistent vdev state is stored as separate values rather than a single
620  * 'vdev_state' entry.  This is because a device can be in multiple states, such
621  * as offline and degraded.
622  */
623 #define ZPOOL_CONFIG_OFFLINE            "offline"
624 #define ZPOOL_CONFIG_FAULTED            "faulted"
625 #define ZPOOL_CONFIG_DEGRADED           "degraded"
626 #define ZPOOL_CONFIG_REMOVED            "removed"
627 #define ZPOOL_CONFIG_FRU                "fru"
628 #define ZPOOL_CONFIG_AUX_STATE          "aux_state"
629
630 /* Pool load policy parameters */
631 #define ZPOOL_LOAD_POLICY               "load-policy"
632 #define ZPOOL_LOAD_REWIND_POLICY        "load-rewind-policy"
633 #define ZPOOL_LOAD_REQUEST_TXG          "load-request-txg"
634 #define ZPOOL_LOAD_META_THRESH          "load-meta-thresh"
635 #define ZPOOL_LOAD_DATA_THRESH          "load-data-thresh"
636
637 /* Rewind data discovered */
638 #define ZPOOL_CONFIG_LOAD_TIME          "rewind_txg_ts"
639 #define ZPOOL_CONFIG_LOAD_DATA_ERRORS   "verify_data_errors"
640 #define ZPOOL_CONFIG_REWIND_TIME        "seconds_of_rewind"
641
642 #define VDEV_TYPE_ROOT                  "root"
643 #define VDEV_TYPE_MIRROR                "mirror"
644 #define VDEV_TYPE_REPLACING             "replacing"
645 #define VDEV_TYPE_RAIDZ                 "raidz"
646 #define VDEV_TYPE_DISK                  "disk"
647 #define VDEV_TYPE_FILE                  "file"
648 #define VDEV_TYPE_MISSING               "missing"
649 #define VDEV_TYPE_HOLE                  "hole"
650 #define VDEV_TYPE_SPARE                 "spare"
651 #define VDEV_TYPE_LOG                   "log"
652 #define VDEV_TYPE_L2CACHE               "l2cache"
653 #define VDEV_TYPE_INDIRECT              "indirect"
654
655 /* VDEV_TOP_ZAP_* are used in top-level vdev ZAP objects. */
656 #define VDEV_TOP_ZAP_INDIRECT_OBSOLETE_SM \
657         "com.delphix:indirect_obsolete_sm"
658 #define VDEV_TOP_ZAP_OBSOLETE_COUNTS_ARE_PRECISE \
659         "com.delphix:obsolete_counts_are_precise"
660 #define VDEV_TOP_ZAP_POOL_CHECKPOINT_SM \
661         "com.delphix:pool_checkpoint_sm"
662
663 #define VDEV_TOP_ZAP_ALLOCATION_BIAS \
664         "org.zfsonlinux:allocation_bias"
665
666 /* vdev metaslab allocation bias */
667 #define VDEV_ALLOC_BIAS_LOG             "log"
668 #define VDEV_ALLOC_BIAS_SPECIAL         "special"
669 #define VDEV_ALLOC_BIAS_DEDUP           "dedup"
670
671 #define VDEV_LEAF_ZAP_INITIALIZE_LAST_OFFSET    \
672         "com.delphix:next_offset_to_initialize"
673 #define VDEV_LEAF_ZAP_INITIALIZE_STATE  \
674         "com.delphix:vdev_initialize_state"
675 #define VDEV_LEAF_ZAP_INITIALIZE_ACTION_TIME    \
676         "com.delphix:vdev_initialize_action_time"
677
678 /*
679  * This is needed in userland to report the minimum necessary device size.
680  *
681  * Note that the zfs test suite uses 64MB vdevs.
682  */
683 #define SPA_MINDEVSIZE          (64ULL << 20)
684
685 /*
686  * Set if the fragmentation has not yet been calculated. This can happen
687  * because the space maps have not been upgraded or the histogram feature
688  * is not enabled.
689  */
690 #define ZFS_FRAG_INVALID        UINT64_MAX
691
692 /*
693  * The location of the pool configuration repository, shared between kernel and
694  * userland.
695  */
696 #define ZPOOL_CACHE             "/boot/zfs/zpool.cache"
697
698 /*
699  * vdev states are ordered from least to most healthy.
700  * A vdev that's CANT_OPEN or below is considered unusable.
701  */
702 typedef enum vdev_state {
703         VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev                   */
704         VDEV_STATE_CLOSED,      /* Not currently open                   */
705         VDEV_STATE_OFFLINE,     /* Not allowed to open                  */
706         VDEV_STATE_REMOVED,     /* Explicitly removed from system       */
707         VDEV_STATE_CANT_OPEN,   /* Tried to open, but failed            */
708         VDEV_STATE_FAULTED,     /* External request to fault device     */
709         VDEV_STATE_DEGRADED,    /* Replicated vdev with unhealthy kids  */
710         VDEV_STATE_HEALTHY      /* Presumed good                        */
711 } vdev_state_t;
712
713 #define VDEV_STATE_ONLINE       VDEV_STATE_HEALTHY
714
715 /*
716  * vdev aux states.  When a vdev is in the CANT_OPEN state, the aux field
717  * of the vdev stats structure uses these constants to distinguish why.
718  */
719 typedef enum vdev_aux {
720         VDEV_AUX_NONE,          /* no error                             */
721         VDEV_AUX_OPEN_FAILED,   /* ldi_open_*() or vn_open() failed     */
722         VDEV_AUX_CORRUPT_DATA,  /* bad label or disk contents           */
723         VDEV_AUX_NO_REPLICAS,   /* insufficient number of replicas      */
724         VDEV_AUX_BAD_GUID_SUM,  /* vdev guid sum doesn't match          */
725         VDEV_AUX_TOO_SMALL,     /* vdev size is too small               */
726         VDEV_AUX_BAD_LABEL,     /* the label is OK but invalid          */
727         VDEV_AUX_VERSION_NEWER, /* on-disk version is too new           */
728         VDEV_AUX_VERSION_OLDER, /* on-disk version is too old           */
729         VDEV_AUX_UNSUP_FEAT,    /* unsupported features                 */
730         VDEV_AUX_SPARED,        /* hot spare used in another pool       */
731         VDEV_AUX_ERR_EXCEEDED,  /* too many errors                      */
732         VDEV_AUX_IO_FAILURE,    /* experienced I/O failure              */
733         VDEV_AUX_BAD_LOG,       /* cannot read log chain(s)             */
734         VDEV_AUX_EXTERNAL,      /* external diagnosis                   */
735         VDEV_AUX_SPLIT_POOL,    /* vdev was split off into another pool */
736         VDEV_AUX_ASHIFT_TOO_BIG, /* vdev's min block size is too large   */
737         VDEV_AUX_CHILDREN_OFFLINE, /* all children are offline          */
738         VDEV_AUX_ACTIVE         /* vdev active on a different host      */
739 } vdev_aux_t;
740
741 /*
742  * pool state.  The following states are written to disk as part of the normal
743  * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE.  The remaining
744  * states are software abstractions used at various levels to communicate
745  * pool state.
746  */
747 typedef enum pool_state {
748         POOL_STATE_ACTIVE = 0,          /* In active use                */
749         POOL_STATE_EXPORTED,            /* Explicitly exported          */
750         POOL_STATE_DESTROYED,           /* Explicitly destroyed         */
751         POOL_STATE_SPARE,               /* Reserved for hot spare use   */
752         POOL_STATE_L2CACHE,             /* Level 2 ARC device           */
753         POOL_STATE_UNINITIALIZED,       /* Internal spa_t state         */
754         POOL_STATE_UNAVAIL,             /* Internal libzfs state        */
755         POOL_STATE_POTENTIALLY_ACTIVE   /* Internal libzfs state        */
756 } pool_state_t;
757
758 /*
759  * mmp state. The following states provide additional detail describing
760  * why a pool couldn't be safely imported.
761  */
762 typedef enum mmp_state {
763         MMP_STATE_ACTIVE = 0,           /* In active use                */
764         MMP_STATE_INACTIVE,             /* Inactive and safe to import  */
765         MMP_STATE_NO_HOSTID             /* System hostid is not set     */
766 } mmp_state_t;
767
768 /*
769  * Scan Functions.
770  */
771 typedef enum pool_scan_func {
772         POOL_SCAN_NONE,
773         POOL_SCAN_SCRUB,
774         POOL_SCAN_RESILVER,
775         POOL_SCAN_FUNCS
776 } pool_scan_func_t;
777
778 /*
779  * Used to control scrub pause and resume.
780  */
781 typedef enum pool_scrub_cmd {
782         POOL_SCRUB_NORMAL = 0,
783         POOL_SCRUB_PAUSE,
784         POOL_SCRUB_FLAGS_END
785 } pool_scrub_cmd_t;
786
787 /*
788  * Initialize functions.
789  */
790 typedef enum pool_initialize_func {
791         POOL_INITIALIZE_DO,
792         POOL_INITIALIZE_CANCEL,
793         POOL_INITIALIZE_SUSPEND,
794         POOL_INITIALIZE_FUNCS
795 } pool_initialize_func_t;
796
797 /*
798  * ZIO types.  Needed to interpret vdev statistics below.
799  */
800 typedef enum zio_type {
801         ZIO_TYPE_NULL = 0,
802         ZIO_TYPE_READ,
803         ZIO_TYPE_WRITE,
804         ZIO_TYPE_FREE,
805         ZIO_TYPE_CLAIM,
806         ZIO_TYPE_IOCTL,
807         ZIO_TYPES
808 } zio_type_t;
809
810 /*
811  * Pool statistics.  Note: all fields should be 64-bit because this
812  * is passed between kernel and userland as an nvlist uint64 array.
813  */
814 typedef struct pool_scan_stat {
815         /* values stored on disk */
816         uint64_t        pss_func;       /* pool_scan_func_t */
817         uint64_t        pss_state;      /* dsl_scan_state_t */
818         uint64_t        pss_start_time; /* scan start time */
819         uint64_t        pss_end_time;   /* scan end time */
820         uint64_t        pss_to_examine; /* total bytes to scan */
821         uint64_t        pss_examined;   /* total bytes located by scanner */
822         uint64_t        pss_to_process; /* total bytes to process */
823         uint64_t        pss_processed;  /* total processed bytes */
824         uint64_t        pss_errors;     /* scan errors  */
825
826         /* values not stored on disk */
827         uint64_t        pss_pass_exam;  /* examined bytes per scan pass */
828         uint64_t        pss_pass_start; /* start time of a scan pass */
829         uint64_t        pss_pass_scrub_pause; /* pause time of a scurb pass */
830         /* cumulative time scrub spent paused, needed for rate calculation */
831         uint64_t        pss_pass_scrub_spent_paused;
832
833         /* Sorted scrubbing new fields */
834         /* Stored on disk */
835         uint64_t        pss_issued;     /* total bytes checked by scanner */
836         /* Not stored on disk */
837         uint64_t        pss_pass_issued;        /* issued bytes per scan pass */
838 } pool_scan_stat_t;
839
840 typedef struct pool_removal_stat {
841         uint64_t prs_state; /* dsl_scan_state_t */
842         uint64_t prs_removing_vdev;
843         uint64_t prs_start_time;
844         uint64_t prs_end_time;
845         uint64_t prs_to_copy; /* bytes that need to be copied */
846         uint64_t prs_copied; /* bytes copied so far */
847         /*
848          * bytes of memory used for indirect mappings.
849          * This includes all removed vdevs.
850          */
851         uint64_t prs_mapping_memory;
852 } pool_removal_stat_t;
853
854 typedef enum dsl_scan_state {
855         DSS_NONE,
856         DSS_SCANNING,
857         DSS_FINISHED,
858         DSS_CANCELED,
859         DSS_NUM_STATES
860 } dsl_scan_state_t;
861
862 typedef enum {
863         CS_NONE,
864         CS_CHECKPOINT_EXISTS,
865         CS_CHECKPOINT_DISCARDING,
866         CS_NUM_STATES
867 } checkpoint_state_t;
868
869 typedef struct pool_checkpoint_stat {
870         uint64_t pcs_state;             /* checkpoint_state_t */
871         uint64_t pcs_start_time;        /* time checkpoint/discard started */
872         uint64_t pcs_space;             /* checkpointed space */
873 } pool_checkpoint_stat_t;
874
875 typedef enum {
876         VDEV_INITIALIZE_NONE,
877         VDEV_INITIALIZE_ACTIVE,
878         VDEV_INITIALIZE_CANCELED,
879         VDEV_INITIALIZE_SUSPENDED,
880         VDEV_INITIALIZE_COMPLETE
881 } vdev_initializing_state_t;
882
883 /*
884  * Vdev statistics.  Note: all fields should be 64-bit because this
885  * is passed between kernel and userland as an nvlist uint64 array.
886  */
887 typedef struct vdev_stat {
888         hrtime_t        vs_timestamp;           /* time since vdev load */
889         uint64_t        vs_state;               /* vdev state           */
890         uint64_t        vs_aux;                 /* see vdev_aux_t       */
891         uint64_t        vs_alloc;               /* space allocated      */
892         uint64_t        vs_space;               /* total capacity       */
893         uint64_t        vs_dspace;              /* deflated capacity    */
894         uint64_t        vs_rsize;               /* replaceable dev size */
895         uint64_t        vs_esize;               /* expandable dev size */
896         uint64_t        vs_ops[ZIO_TYPES];      /* operation count      */
897         uint64_t        vs_bytes[ZIO_TYPES];    /* bytes read/written   */
898         uint64_t        vs_read_errors;         /* read errors          */
899         uint64_t        vs_write_errors;        /* write errors         */
900         uint64_t        vs_checksum_errors;     /* checksum errors      */
901         uint64_t        vs_self_healed;         /* self-healed bytes    */
902         uint64_t        vs_scan_removing;       /* removing?    */
903         uint64_t        vs_scan_processed;      /* scan processed bytes */
904         uint64_t        vs_configured_ashift;   /* TLV vdev_ashift      */
905         uint64_t        vs_logical_ashift;      /* vdev_logical_ashift  */
906         uint64_t        vs_physical_ashift;     /* vdev_physical_ashift */
907         uint64_t        vs_fragmentation;       /* device fragmentation */
908         uint64_t        vs_checkpoint_space;    /* checkpoint-consumed space */
909         uint64_t        vs_initialize_errors;   /* initializing errors  */
910         uint64_t        vs_initialize_bytes_done; /* bytes initialized */
911         uint64_t        vs_initialize_bytes_est; /* total bytes to initialize */
912         uint64_t        vs_initialize_state;    /* vdev_initialzing_state_t */
913         uint64_t        vs_initialize_action_time; /* time_t */
914 } vdev_stat_t;
915 #define VDEV_STAT_VALID(field, uint64_t_field_count) \
916     ((uint64_t_field_count * sizeof(uint64_t)) >= \
917      (offsetof(vdev_stat_t, field) + sizeof(((vdev_stat_t *)NULL)->field)))
918
919 /*
920  * DDT statistics.  Note: all fields should be 64-bit because this
921  * is passed between kernel and userland as an nvlist uint64 array.
922  */
923 typedef struct ddt_object {
924         uint64_t        ddo_count;      /* number of elments in ddt     */
925         uint64_t        ddo_dspace;     /* size of ddt on disk          */
926         uint64_t        ddo_mspace;     /* size of ddt in-core          */
927 } ddt_object_t;
928
929 typedef struct ddt_stat {
930         uint64_t        dds_blocks;     /* blocks                       */
931         uint64_t        dds_lsize;      /* logical size                 */
932         uint64_t        dds_psize;      /* physical size                */
933         uint64_t        dds_dsize;      /* deflated allocated size      */
934         uint64_t        dds_ref_blocks; /* referenced blocks            */
935         uint64_t        dds_ref_lsize;  /* referenced lsize * refcnt    */
936         uint64_t        dds_ref_psize;  /* referenced psize * refcnt    */
937         uint64_t        dds_ref_dsize;  /* referenced dsize * refcnt    */
938 } ddt_stat_t;
939
940 typedef struct ddt_histogram {
941         ddt_stat_t      ddh_stat[64];   /* power-of-two histogram buckets */
942 } ddt_histogram_t;
943
944 #define ZVOL_DRIVER     "zvol"
945 #define ZFS_DRIVER      "zfs"
946 #define ZFS_DEV_NAME    "zfs"
947 #define ZFS_DEV         "/dev/" ZFS_DEV_NAME
948 #define ZFS_DISK_ROOT   "/dev/dsk"
949 #define ZFS_DISK_ROOTD  ZFS_DISK_ROOT "/"
950 #define ZFS_RDISK_ROOT  "/dev/rdsk"
951 #define ZFS_RDISK_ROOTD ZFS_RDISK_ROOT "/"
952
953 /* general zvol path */
954 #define ZVOL_DIR                "/dev/zvol"
955 /* expansion */
956 #define ZVOL_PSEUDO_DEV         "/devices/pseudo/zfs@0:"
957 /* for dump and swap */
958 #define ZVOL_FULL_DEV_DIR       ZVOL_DIR "/dsk/"
959 #define ZVOL_FULL_RDEV_DIR      ZVOL_DIR "/rdsk/"
960
961 #define ZVOL_PROP_NAME          "name"
962 #define ZVOL_DEFAULT_BLOCKSIZE  8192
963
964 /*
965  * /dev/zfs ioctl numbers.
966  */
967 typedef enum zfs_ioc {
968         ZFS_IOC_FIRST = 0,
969         ZFS_IOC_POOL_CREATE = ZFS_IOC_FIRST,
970         ZFS_IOC_POOL_DESTROY,
971         ZFS_IOC_POOL_IMPORT,
972         ZFS_IOC_POOL_EXPORT,
973         ZFS_IOC_POOL_CONFIGS,
974         ZFS_IOC_POOL_STATS,
975         ZFS_IOC_POOL_TRYIMPORT,
976         ZFS_IOC_POOL_SCAN,
977         ZFS_IOC_POOL_FREEZE,
978         ZFS_IOC_POOL_UPGRADE,
979         ZFS_IOC_POOL_GET_HISTORY,
980         ZFS_IOC_VDEV_ADD,
981         ZFS_IOC_VDEV_REMOVE,
982         ZFS_IOC_VDEV_SET_STATE,
983         ZFS_IOC_VDEV_ATTACH,
984         ZFS_IOC_VDEV_DETACH,
985         ZFS_IOC_VDEV_SETPATH,
986         ZFS_IOC_VDEV_SETFRU,
987         ZFS_IOC_OBJSET_STATS,
988         ZFS_IOC_OBJSET_ZPLPROPS,
989         ZFS_IOC_DATASET_LIST_NEXT,
990         ZFS_IOC_SNAPSHOT_LIST_NEXT,
991         ZFS_IOC_SET_PROP,
992         ZFS_IOC_CREATE,
993         ZFS_IOC_DESTROY,
994         ZFS_IOC_ROLLBACK,
995         ZFS_IOC_RENAME,
996         ZFS_IOC_RECV,
997         ZFS_IOC_SEND,
998         ZFS_IOC_INJECT_FAULT,
999         ZFS_IOC_CLEAR_FAULT,
1000         ZFS_IOC_INJECT_LIST_NEXT,
1001         ZFS_IOC_ERROR_LOG,
1002         ZFS_IOC_CLEAR,
1003         ZFS_IOC_PROMOTE,
1004         ZFS_IOC_DESTROY_SNAPS,
1005         ZFS_IOC_SNAPSHOT,
1006         ZFS_IOC_DSOBJ_TO_DSNAME,
1007         ZFS_IOC_OBJ_TO_PATH,
1008         ZFS_IOC_POOL_SET_PROPS,
1009         ZFS_IOC_POOL_GET_PROPS,
1010         ZFS_IOC_SET_FSACL,
1011         ZFS_IOC_GET_FSACL,
1012         ZFS_IOC_SHARE,
1013         ZFS_IOC_INHERIT_PROP,
1014         ZFS_IOC_SMB_ACL,
1015         ZFS_IOC_USERSPACE_ONE,
1016         ZFS_IOC_USERSPACE_MANY,
1017         ZFS_IOC_USERSPACE_UPGRADE,
1018         ZFS_IOC_HOLD,
1019         ZFS_IOC_RELEASE,
1020         ZFS_IOC_GET_HOLDS,
1021         ZFS_IOC_OBJSET_RECVD_PROPS,
1022         ZFS_IOC_VDEV_SPLIT,
1023         ZFS_IOC_NEXT_OBJ,
1024         ZFS_IOC_DIFF,
1025         ZFS_IOC_TMP_SNAPSHOT,
1026         ZFS_IOC_OBJ_TO_STATS,
1027         ZFS_IOC_JAIL,
1028         ZFS_IOC_UNJAIL,
1029         ZFS_IOC_POOL_REGUID,
1030         ZFS_IOC_SPACE_WRITTEN,
1031         ZFS_IOC_SPACE_SNAPS,
1032         ZFS_IOC_SEND_PROGRESS,
1033         ZFS_IOC_POOL_REOPEN,
1034         ZFS_IOC_LOG_HISTORY,
1035         ZFS_IOC_SEND_NEW,
1036         ZFS_IOC_SEND_SPACE,
1037         ZFS_IOC_CLONE,
1038         ZFS_IOC_BOOKMARK,
1039         ZFS_IOC_GET_BOOKMARKS,
1040         ZFS_IOC_DESTROY_BOOKMARKS,
1041 #ifdef __FreeBSD__
1042         ZFS_IOC_NEXTBOOT,
1043 #endif
1044         ZFS_IOC_CHANNEL_PROGRAM,
1045         ZFS_IOC_REMAP,
1046         ZFS_IOC_POOL_CHECKPOINT,
1047         ZFS_IOC_POOL_DISCARD_CHECKPOINT,
1048         ZFS_IOC_POOL_INITIALIZE,
1049         ZFS_IOC_POOL_SYNC,
1050         ZFS_IOC_LAST
1051 } zfs_ioc_t;
1052
1053 /*
1054  * ZFS-specific error codes used for returning descriptive errors
1055  * to the userland through zfs ioctls.
1056  *
1057  * The enum implicitly includes all the error codes from errno.h.
1058  * New code should use and extend this enum for errors that are
1059  * not described precisely by generic errno codes.
1060  */
1061 typedef enum {
1062         ZFS_ERR_CHECKPOINT_EXISTS = 1024,
1063         ZFS_ERR_DISCARDING_CHECKPOINT,
1064         ZFS_ERR_NO_CHECKPOINT,
1065         ZFS_ERR_DEVRM_IN_PROGRESS,
1066         ZFS_ERR_VDEV_TOO_BIG,
1067         ZFS_ERR_WRONG_PARENT,
1068 } zfs_errno_t;
1069
1070 /*
1071  * Internal SPA load state.  Used by FMA diagnosis engine.
1072  */
1073 typedef enum {
1074         SPA_LOAD_NONE,          /* no load in progress  */
1075         SPA_LOAD_OPEN,          /* normal open          */
1076         SPA_LOAD_IMPORT,        /* import in progress   */
1077         SPA_LOAD_TRYIMPORT,     /* tryimport in progress */
1078         SPA_LOAD_RECOVER,       /* recovery requested   */
1079         SPA_LOAD_ERROR,         /* load failed          */
1080         SPA_LOAD_CREATE         /* creation in progress */
1081 } spa_load_state_t;
1082
1083 /*
1084  * Bookmark name values.
1085  */
1086 #define ZPOOL_ERR_LIST          "error list"
1087 #define ZPOOL_ERR_DATASET       "dataset"
1088 #define ZPOOL_ERR_OBJECT        "object"
1089
1090 #define HIS_MAX_RECORD_LEN      (MAXPATHLEN + MAXPATHLEN + 1)
1091
1092 /*
1093  * The following are names used in the nvlist describing
1094  * the pool's history log.
1095  */
1096 #define ZPOOL_HIST_RECORD       "history record"
1097 #define ZPOOL_HIST_TIME         "history time"
1098 #define ZPOOL_HIST_CMD          "history command"
1099 #define ZPOOL_HIST_WHO          "history who"
1100 #define ZPOOL_HIST_ZONE         "history zone"
1101 #define ZPOOL_HIST_HOST         "history hostname"
1102 #define ZPOOL_HIST_TXG          "history txg"
1103 #define ZPOOL_HIST_INT_EVENT    "history internal event"
1104 #define ZPOOL_HIST_INT_STR      "history internal str"
1105 #define ZPOOL_HIST_INT_NAME     "internal_name"
1106 #define ZPOOL_HIST_IOCTL        "ioctl"
1107 #define ZPOOL_HIST_INPUT_NVL    "in_nvl"
1108 #define ZPOOL_HIST_OUTPUT_NVL   "out_nvl"
1109 #define ZPOOL_HIST_DSNAME       "dsname"
1110 #define ZPOOL_HIST_DSID         "dsid"
1111 #define ZPOOL_HIST_ERRNO        "errno"
1112
1113 /*
1114  * The following are names used when invoking ZFS_IOC_POOL_INITIALIZE.
1115  */
1116 #define ZPOOL_INITIALIZE_COMMAND        "initialize_command"
1117 #define ZPOOL_INITIALIZE_VDEVS          "initialize_vdevs"
1118
1119 /*
1120  * Flags for ZFS_IOC_VDEV_SET_STATE
1121  */
1122 #define ZFS_ONLINE_CHECKREMOVE  0x1
1123 #define ZFS_ONLINE_UNSPARE      0x2
1124 #define ZFS_ONLINE_FORCEFAULT   0x4
1125 #define ZFS_ONLINE_EXPAND       0x8
1126 #define ZFS_OFFLINE_TEMPORARY   0x1
1127
1128 /*
1129  * Flags for ZFS_IOC_POOL_IMPORT
1130  */
1131 #define ZFS_IMPORT_NORMAL       0x0
1132 #define ZFS_IMPORT_VERBATIM     0x1
1133 #define ZFS_IMPORT_ANY_HOST     0x2
1134 #define ZFS_IMPORT_MISSING_LOG  0x4
1135 #define ZFS_IMPORT_ONLY         0x8
1136 #define ZFS_IMPORT_CHECKPOINT   0x10
1137 #define ZFS_IMPORT_TEMP_NAME    0x20
1138 #define ZFS_IMPORT_SKIP_MMP     0x40
1139
1140 /*
1141  * Channel program argument/return nvlist keys and defaults.
1142  */
1143 #define ZCP_ARG_PROGRAM         "program"
1144 #define ZCP_ARG_ARGLIST         "arg"
1145 #define ZCP_ARG_SYNC            "sync"
1146 #define ZCP_ARG_INSTRLIMIT      "instrlimit"
1147 #define ZCP_ARG_MEMLIMIT        "memlimit"
1148
1149 #define ZCP_ARG_CLIARGV         "argv"
1150
1151 #define ZCP_RET_ERROR           "error"
1152 #define ZCP_RET_RETURN          "return"
1153
1154 #define ZCP_DEFAULT_INSTRLIMIT  (10 * 1000 * 1000)
1155 #define ZCP_MAX_INSTRLIMIT      (10 * ZCP_DEFAULT_INSTRLIMIT)
1156 #define ZCP_DEFAULT_MEMLIMIT    (10 * 1024 * 1024)
1157 #define ZCP_MAX_MEMLIMIT        (10 * ZCP_DEFAULT_MEMLIMIT)
1158
1159 /*
1160  * nvlist name constants. Facilitate restricting snapshot iteration range for
1161  * the "list next snapshot" ioctl
1162  */
1163 #define SNAP_ITER_MIN_TXG       "snap_iter_min_txg"
1164 #define SNAP_ITER_MAX_TXG       "snap_iter_max_txg"
1165
1166 /*
1167  * Sysevent payload members.  ZFS will generate the following sysevents with the
1168  * given payloads:
1169  *
1170  *      ESC_ZFS_RESILVER_START
1171  *      ESC_ZFS_RESILVER_END
1172  *      ESC_ZFS_POOL_DESTROY
1173  *      ESC_ZFS_POOL_REGUID
1174  *
1175  *              ZFS_EV_POOL_NAME        DATA_TYPE_STRING
1176  *              ZFS_EV_POOL_GUID        DATA_TYPE_UINT64
1177  *
1178  *      ESC_ZFS_VDEV_REMOVE
1179  *      ESC_ZFS_VDEV_CLEAR
1180  *      ESC_ZFS_VDEV_CHECK
1181  *
1182  *              ZFS_EV_POOL_NAME        DATA_TYPE_STRING
1183  *              ZFS_EV_POOL_GUID        DATA_TYPE_UINT64
1184  *              ZFS_EV_VDEV_PATH        DATA_TYPE_STRING        (optional)
1185  *              ZFS_EV_VDEV_GUID        DATA_TYPE_UINT64
1186  *
1187  *      ESC_ZFS_HISTORY_EVENT
1188  *
1189  *              ZFS_EV_POOL_NAME        DATA_TYPE_STRING
1190  *              ZFS_EV_POOL_GUID        DATA_TYPE_UINT64
1191  *              ZFS_EV_HIST_TIME        DATA_TYPE_UINT64        (optional)
1192  *              ZFS_EV_HIST_CMD         DATA_TYPE_STRING        (optional)
1193  *              ZFS_EV_HIST_WHO         DATA_TYPE_UINT64        (optional)
1194  *              ZFS_EV_HIST_ZONE        DATA_TYPE_STRING        (optional)
1195  *              ZFS_EV_HIST_HOST        DATA_TYPE_STRING        (optional)
1196  *              ZFS_EV_HIST_TXG         DATA_TYPE_UINT64        (optional)
1197  *              ZFS_EV_HIST_INT_EVENT   DATA_TYPE_UINT64        (optional)
1198  *              ZFS_EV_HIST_INT_STR     DATA_TYPE_STRING        (optional)
1199  *              ZFS_EV_HIST_INT_NAME    DATA_TYPE_STRING        (optional)
1200  *              ZFS_EV_HIST_IOCTL       DATA_TYPE_STRING        (optional)
1201  *              ZFS_EV_HIST_DSNAME      DATA_TYPE_STRING        (optional)
1202  *              ZFS_EV_HIST_DSID        DATA_TYPE_UINT64        (optional)
1203  *
1204  * The ZFS_EV_HIST_* members will correspond to the ZPOOL_HIST_* members in the
1205  * history log nvlist.  The keynames will be free of any spaces or other
1206  * characters that could be potentially unexpected to consumers of the
1207  * sysevents.
1208  */
1209 #define ZFS_EV_POOL_NAME        "pool_name"
1210 #define ZFS_EV_POOL_GUID        "pool_guid"
1211 #define ZFS_EV_VDEV_PATH        "vdev_path"
1212 #define ZFS_EV_VDEV_GUID        "vdev_guid"
1213 #define ZFS_EV_HIST_TIME        "history_time"
1214 #define ZFS_EV_HIST_CMD         "history_command"
1215 #define ZFS_EV_HIST_WHO         "history_who"
1216 #define ZFS_EV_HIST_ZONE        "history_zone"
1217 #define ZFS_EV_HIST_HOST        "history_hostname"
1218 #define ZFS_EV_HIST_TXG         "history_txg"
1219 #define ZFS_EV_HIST_INT_EVENT   "history_internal_event"
1220 #define ZFS_EV_HIST_INT_STR     "history_internal_str"
1221 #define ZFS_EV_HIST_INT_NAME    "history_internal_name"
1222 #define ZFS_EV_HIST_IOCTL       "history_ioctl"
1223 #define ZFS_EV_HIST_DSNAME      "history_dsname"
1224 #define ZFS_EV_HIST_DSID        "history_dsid"
1225
1226 #ifdef  __cplusplus
1227 }
1228 #endif
1229
1230 #endif  /* _SYS_FS_ZFS_H */