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