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