]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/sys/fs/zfs.h
OpenZFS 6550 - cmd/zfs: cleanup gcc warnings
[FreeBSD/FreeBSD.git] / include / 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, 2014 by Delphix. All rights reserved.
25  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
26  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
27  */
28
29 /* Portions Copyright 2010 Robert Milkowski */
30
31 #ifndef _SYS_FS_ZFS_H
32 #define _SYS_FS_ZFS_H
33
34 #include <sys/time.h>
35 #include <sys/zio_priority.h>
36
37 #ifdef  __cplusplus
38 extern "C" {
39 #endif
40
41 /*
42  * Types and constants shared between userland and the kernel.
43  */
44
45 /*
46  * Each dataset can be one of the following types.  These constants can be
47  * combined into masks that can be passed to various functions.
48  */
49 typedef enum {
50         ZFS_TYPE_FILESYSTEM     = (1 << 0),
51         ZFS_TYPE_SNAPSHOT       = (1 << 1),
52         ZFS_TYPE_VOLUME         = (1 << 2),
53         ZFS_TYPE_POOL           = (1 << 3),
54         ZFS_TYPE_BOOKMARK       = (1 << 4)
55 } zfs_type_t;
56
57 typedef enum dmu_objset_type {
58         DMU_OST_NONE,
59         DMU_OST_META,
60         DMU_OST_ZFS,
61         DMU_OST_ZVOL,
62         DMU_OST_OTHER,                  /* For testing only! */
63         DMU_OST_ANY,                    /* Be careful! */
64         DMU_OST_NUMTYPES
65 } dmu_objset_type_t;
66
67 #define ZFS_TYPE_DATASET        \
68         (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME | ZFS_TYPE_SNAPSHOT)
69
70 /*
71  * All of these include the terminating NUL byte.
72  */
73 #define ZAP_MAXNAMELEN 256
74 #define ZAP_MAXVALUELEN (1024 * 8)
75 #define ZAP_OLDMAXVALUELEN 1024
76 #define ZFS_MAX_DATASET_NAME_LEN 256
77
78 /*
79  * Dataset properties are identified by these constants and must be added to
80  * the end of this list to ensure that external consumers are not affected
81  * by the change. If you make any changes to this list, be sure to update
82  * the property table in module/zcommon/zfs_prop.c.
83  */
84 typedef enum {
85         ZFS_PROP_BAD = -1,
86         ZFS_PROP_TYPE = 0,
87         ZFS_PROP_CREATION,
88         ZFS_PROP_USED,
89         ZFS_PROP_AVAILABLE,
90         ZFS_PROP_REFERENCED,
91         ZFS_PROP_COMPRESSRATIO,
92         ZFS_PROP_MOUNTED,
93         ZFS_PROP_ORIGIN,
94         ZFS_PROP_QUOTA,
95         ZFS_PROP_RESERVATION,
96         ZFS_PROP_VOLSIZE,
97         ZFS_PROP_VOLBLOCKSIZE,
98         ZFS_PROP_RECORDSIZE,
99         ZFS_PROP_MOUNTPOINT,
100         ZFS_PROP_SHARENFS,
101         ZFS_PROP_CHECKSUM,
102         ZFS_PROP_COMPRESSION,
103         ZFS_PROP_ATIME,
104         ZFS_PROP_DEVICES,
105         ZFS_PROP_EXEC,
106         ZFS_PROP_SETUID,
107         ZFS_PROP_READONLY,
108         ZFS_PROP_ZONED,
109         ZFS_PROP_SNAPDIR,
110         ZFS_PROP_PRIVATE,               /* not exposed to user, temporary */
111         ZFS_PROP_ACLINHERIT,
112         ZFS_PROP_CREATETXG,             /* not exposed to the user */
113         ZFS_PROP_NAME,                  /* not exposed to the user */
114         ZFS_PROP_CANMOUNT,
115         ZFS_PROP_ISCSIOPTIONS,          /* not exposed to the user */
116         ZFS_PROP_XATTR,
117         ZFS_PROP_NUMCLONES,             /* not exposed to the user */
118         ZFS_PROP_COPIES,
119         ZFS_PROP_VERSION,
120         ZFS_PROP_UTF8ONLY,
121         ZFS_PROP_NORMALIZE,
122         ZFS_PROP_CASE,
123         ZFS_PROP_VSCAN,
124         ZFS_PROP_NBMAND,
125         ZFS_PROP_SHARESMB,
126         ZFS_PROP_REFQUOTA,
127         ZFS_PROP_REFRESERVATION,
128         ZFS_PROP_GUID,
129         ZFS_PROP_PRIMARYCACHE,
130         ZFS_PROP_SECONDARYCACHE,
131         ZFS_PROP_USEDSNAP,
132         ZFS_PROP_USEDDS,
133         ZFS_PROP_USEDCHILD,
134         ZFS_PROP_USEDREFRESERV,
135         ZFS_PROP_USERACCOUNTING,        /* not exposed to the user */
136         ZFS_PROP_STMF_SHAREINFO,        /* not exposed to the user */
137         ZFS_PROP_DEFER_DESTROY,
138         ZFS_PROP_USERREFS,
139         ZFS_PROP_LOGBIAS,
140         ZFS_PROP_UNIQUE,                /* not exposed to the user */
141         ZFS_PROP_OBJSETID,              /* not exposed to the user */
142         ZFS_PROP_DEDUP,
143         ZFS_PROP_MLSLABEL,
144         ZFS_PROP_SYNC,
145         ZFS_PROP_DNODESIZE,
146         ZFS_PROP_REFRATIO,
147         ZFS_PROP_WRITTEN,
148         ZFS_PROP_CLONES,
149         ZFS_PROP_LOGICALUSED,
150         ZFS_PROP_LOGICALREFERENCED,
151         ZFS_PROP_INCONSISTENT,          /* not exposed to the user */
152         ZFS_PROP_FILESYSTEM_LIMIT,
153         ZFS_PROP_SNAPSHOT_LIMIT,
154         ZFS_PROP_FILESYSTEM_COUNT,
155         ZFS_PROP_SNAPSHOT_COUNT,
156         ZFS_PROP_SNAPDEV,
157         ZFS_PROP_ACLTYPE,
158         ZFS_PROP_SELINUX_CONTEXT,
159         ZFS_PROP_SELINUX_FSCONTEXT,
160         ZFS_PROP_SELINUX_DEFCONTEXT,
161         ZFS_PROP_SELINUX_ROOTCONTEXT,
162         ZFS_PROP_RELATIME,
163         ZFS_PROP_REDUNDANT_METADATA,
164         ZFS_PROP_OVERLAY,
165         ZFS_PROP_PREV_SNAP,
166         ZFS_PROP_RECEIVE_RESUME_TOKEN,
167         ZFS_NUM_PROPS
168 } zfs_prop_t;
169
170 typedef enum {
171         ZFS_PROP_USERUSED,
172         ZFS_PROP_USERQUOTA,
173         ZFS_PROP_GROUPUSED,
174         ZFS_PROP_GROUPQUOTA,
175         ZFS_PROP_USEROBJUSED,
176         ZFS_PROP_USEROBJQUOTA,
177         ZFS_PROP_GROUPOBJUSED,
178         ZFS_PROP_GROUPOBJQUOTA,
179         ZFS_NUM_USERQUOTA_PROPS
180 } zfs_userquota_prop_t;
181
182 extern const char *zfs_userquota_prop_prefixes[ZFS_NUM_USERQUOTA_PROPS];
183
184 /*
185  * Pool properties are identified by these constants and must be added to the
186  * end of this list to ensure that external consumers are not affected
187  * by the change. If you make any changes to this list, be sure to update
188  * the property table in module/zcommon/zpool_prop.c.
189  */
190 typedef enum {
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_ASHIFT,
211         ZPOOL_PROP_COMMENT,
212         ZPOOL_PROP_EXPANDSZ,
213         ZPOOL_PROP_FREEING,
214         ZPOOL_PROP_FRAGMENTATION,
215         ZPOOL_PROP_LEAKED,
216         ZPOOL_PROP_MAXBLOCKSIZE,
217         ZPOOL_PROP_TNAME,
218         ZPOOL_PROP_MAXDNODESIZE,
219         ZPOOL_NUM_PROPS
220 } zpool_prop_t;
221
222 /* Small enough to not hog a whole line of printout in zpool(1M). */
223 #define ZPROP_MAX_COMMENT       32
224
225 #define ZPROP_CONT              -2
226 #define ZPROP_INVAL             -1
227
228 #define ZPROP_VALUE             "value"
229 #define ZPROP_SOURCE            "source"
230
231 typedef enum {
232         ZPROP_SRC_NONE = 0x1,
233         ZPROP_SRC_DEFAULT = 0x2,
234         ZPROP_SRC_TEMPORARY = 0x4,
235         ZPROP_SRC_LOCAL = 0x8,
236         ZPROP_SRC_INHERITED = 0x10,
237         ZPROP_SRC_RECEIVED = 0x20
238 } zprop_source_t;
239
240 #define ZPROP_SRC_ALL   0x3f
241
242 #define ZPROP_SOURCE_VAL_RECVD  "$recvd"
243 #define ZPROP_N_MORE_ERRORS     "N_MORE_ERRORS"
244
245 /*
246  * Dataset flag implemented as a special entry in the props zap object
247  * indicating that the dataset has received properties on or after
248  * SPA_VERSION_RECVD_PROPS. The first such receive blows away local properties
249  * just as it did in earlier versions, and thereafter, local properties are
250  * preserved.
251  */
252 #define ZPROP_HAS_RECVD         "$hasrecvd"
253
254 typedef enum {
255         ZPROP_ERR_NOCLEAR = 0x1, /* failure to clear existing props */
256         ZPROP_ERR_NORESTORE = 0x2 /* failure to restore props on error */
257 } zprop_errflags_t;
258
259 typedef int (*zprop_func)(int, void *);
260
261 /*
262  * Properties to be set on the root file system of a new pool
263  * are stuffed into their own nvlist, which is then included in
264  * the properties nvlist with the pool properties.
265  */
266 #define ZPOOL_ROOTFS_PROPS      "root-props-nvl"
267
268 /*
269  * Dataset property functions shared between libzfs and kernel.
270  */
271 const char *zfs_prop_default_string(zfs_prop_t);
272 uint64_t zfs_prop_default_numeric(zfs_prop_t);
273 boolean_t zfs_prop_readonly(zfs_prop_t);
274 boolean_t zfs_prop_inheritable(zfs_prop_t);
275 boolean_t zfs_prop_setonce(zfs_prop_t);
276 const char *zfs_prop_to_name(zfs_prop_t);
277 zfs_prop_t zfs_name_to_prop(const char *);
278 boolean_t zfs_prop_user(const char *);
279 boolean_t zfs_prop_userquota(const char *);
280 boolean_t zfs_prop_written(const char *);
281 int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
282 int zfs_prop_string_to_index(zfs_prop_t, const char *, uint64_t *);
283 uint64_t zfs_prop_random_value(zfs_prop_t, uint64_t seed);
284 boolean_t zfs_prop_valid_for_type(int, zfs_type_t, boolean_t);
285
286 /*
287  * Pool property functions shared between libzfs and kernel.
288  */
289 zpool_prop_t zpool_name_to_prop(const char *);
290 const char *zpool_prop_to_name(zpool_prop_t);
291 const char *zpool_prop_default_string(zpool_prop_t);
292 uint64_t zpool_prop_default_numeric(zpool_prop_t);
293 boolean_t zpool_prop_readonly(zpool_prop_t);
294 boolean_t zpool_prop_feature(const char *);
295 boolean_t zpool_prop_unsupported(const char *);
296 int zpool_prop_index_to_string(zpool_prop_t, uint64_t, const char **);
297 int zpool_prop_string_to_index(zpool_prop_t, const char *, uint64_t *);
298 uint64_t zpool_prop_random_value(zpool_prop_t, uint64_t seed);
299
300 /*
301  * Definitions for the Delegation.
302  */
303 typedef enum {
304         ZFS_DELEG_WHO_UNKNOWN = 0,
305         ZFS_DELEG_USER = 'u',
306         ZFS_DELEG_USER_SETS = 'U',
307         ZFS_DELEG_GROUP = 'g',
308         ZFS_DELEG_GROUP_SETS = 'G',
309         ZFS_DELEG_EVERYONE = 'e',
310         ZFS_DELEG_EVERYONE_SETS = 'E',
311         ZFS_DELEG_CREATE = 'c',
312         ZFS_DELEG_CREATE_SETS = 'C',
313         ZFS_DELEG_NAMED_SET = 's',
314         ZFS_DELEG_NAMED_SET_SETS = 'S'
315 } zfs_deleg_who_type_t;
316
317 typedef enum {
318         ZFS_DELEG_NONE = 0,
319         ZFS_DELEG_PERM_LOCAL = 1,
320         ZFS_DELEG_PERM_DESCENDENT = 2,
321         ZFS_DELEG_PERM_LOCALDESCENDENT = 3,
322         ZFS_DELEG_PERM_CREATE = 4
323 } zfs_deleg_inherit_t;
324
325 #define ZFS_DELEG_PERM_UID      "uid"
326 #define ZFS_DELEG_PERM_GID      "gid"
327 #define ZFS_DELEG_PERM_GROUPS   "groups"
328
329 #define ZFS_MLSLABEL_DEFAULT    "none"
330
331 #define ZFS_SMB_ACL_SRC         "src"
332 #define ZFS_SMB_ACL_TARGET      "target"
333
334 typedef enum {
335         ZFS_CANMOUNT_OFF = 0,
336         ZFS_CANMOUNT_ON = 1,
337         ZFS_CANMOUNT_NOAUTO = 2
338 } zfs_canmount_type_t;
339
340 typedef enum {
341         ZFS_LOGBIAS_LATENCY = 0,
342         ZFS_LOGBIAS_THROUGHPUT = 1
343 } zfs_logbias_op_t;
344
345 typedef enum zfs_share_op {
346         ZFS_SHARE_NFS = 0,
347         ZFS_UNSHARE_NFS = 1,
348         ZFS_SHARE_SMB = 2,
349         ZFS_UNSHARE_SMB = 3
350 } zfs_share_op_t;
351
352 typedef enum zfs_smb_acl_op {
353         ZFS_SMB_ACL_ADD,
354         ZFS_SMB_ACL_REMOVE,
355         ZFS_SMB_ACL_RENAME,
356         ZFS_SMB_ACL_PURGE
357 } zfs_smb_acl_op_t;
358
359 typedef enum zfs_cache_type {
360         ZFS_CACHE_NONE = 0,
361         ZFS_CACHE_METADATA = 1,
362         ZFS_CACHE_ALL = 2
363 } zfs_cache_type_t;
364
365 typedef enum {
366         ZFS_SYNC_STANDARD = 0,
367         ZFS_SYNC_ALWAYS = 1,
368         ZFS_SYNC_DISABLED = 2
369 } zfs_sync_type_t;
370
371 typedef enum {
372         ZFS_XATTR_OFF = 0,
373         ZFS_XATTR_DIR = 1,
374         ZFS_XATTR_SA = 2
375 } zfs_xattr_type_t;
376
377 typedef enum {
378         ZFS_DNSIZE_LEGACY = 0,
379         ZFS_DNSIZE_AUTO = 1,
380         ZFS_DNSIZE_1K = 1024,
381         ZFS_DNSIZE_2K = 2048,
382         ZFS_DNSIZE_4K = 4096,
383         ZFS_DNSIZE_8K = 8192,
384         ZFS_DNSIZE_16K = 16384
385 } zfs_dnsize_type_t;
386
387 typedef enum {
388         ZFS_REDUNDANT_METADATA_ALL,
389         ZFS_REDUNDANT_METADATA_MOST
390 } zfs_redundant_metadata_type_t;
391
392 /*
393  * On-disk version number.
394  */
395 #define SPA_VERSION_1                   1ULL
396 #define SPA_VERSION_2                   2ULL
397 #define SPA_VERSION_3                   3ULL
398 #define SPA_VERSION_4                   4ULL
399 #define SPA_VERSION_5                   5ULL
400 #define SPA_VERSION_6                   6ULL
401 #define SPA_VERSION_7                   7ULL
402 #define SPA_VERSION_8                   8ULL
403 #define SPA_VERSION_9                   9ULL
404 #define SPA_VERSION_10                  10ULL
405 #define SPA_VERSION_11                  11ULL
406 #define SPA_VERSION_12                  12ULL
407 #define SPA_VERSION_13                  13ULL
408 #define SPA_VERSION_14                  14ULL
409 #define SPA_VERSION_15                  15ULL
410 #define SPA_VERSION_16                  16ULL
411 #define SPA_VERSION_17                  17ULL
412 #define SPA_VERSION_18                  18ULL
413 #define SPA_VERSION_19                  19ULL
414 #define SPA_VERSION_20                  20ULL
415 #define SPA_VERSION_21                  21ULL
416 #define SPA_VERSION_22                  22ULL
417 #define SPA_VERSION_23                  23ULL
418 #define SPA_VERSION_24                  24ULL
419 #define SPA_VERSION_25                  25ULL
420 #define SPA_VERSION_26                  26ULL
421 #define SPA_VERSION_27                  27ULL
422 #define SPA_VERSION_28                  28ULL
423 #define SPA_VERSION_5000                5000ULL
424
425 /*
426  * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk
427  * format change. Go to usr/src/grub/grub-0.97/stage2/{zfs-include/, fsys_zfs*},
428  * and do the appropriate changes.  Also bump the version number in
429  * usr/src/grub/capability.
430  */
431 #define SPA_VERSION                     SPA_VERSION_5000
432 #define SPA_VERSION_STRING              "5000"
433
434 /*
435  * Symbolic names for the changes that caused a SPA_VERSION switch.
436  * Used in the code when checking for presence or absence of a feature.
437  * Feel free to define multiple symbolic names for each version if there
438  * were multiple changes to on-disk structures during that version.
439  *
440  * NOTE: When checking the current SPA_VERSION in your code, be sure
441  *       to use spa_version() since it reports the version of the
442  *       last synced uberblock.  Checking the in-flight version can
443  *       be dangerous in some cases.
444  */
445 #define SPA_VERSION_INITIAL             SPA_VERSION_1
446 #define SPA_VERSION_DITTO_BLOCKS        SPA_VERSION_2
447 #define SPA_VERSION_SPARES              SPA_VERSION_3
448 #define SPA_VERSION_RAIDZ2              SPA_VERSION_3
449 #define SPA_VERSION_BPOBJ_ACCOUNT       SPA_VERSION_3
450 #define SPA_VERSION_RAIDZ_DEFLATE       SPA_VERSION_3
451 #define SPA_VERSION_DNODE_BYTES         SPA_VERSION_3
452 #define SPA_VERSION_ZPOOL_HISTORY       SPA_VERSION_4
453 #define SPA_VERSION_GZIP_COMPRESSION    SPA_VERSION_5
454 #define SPA_VERSION_BOOTFS              SPA_VERSION_6
455 #define SPA_VERSION_SLOGS               SPA_VERSION_7
456 #define SPA_VERSION_DELEGATED_PERMS     SPA_VERSION_8
457 #define SPA_VERSION_FUID                SPA_VERSION_9
458 #define SPA_VERSION_REFRESERVATION      SPA_VERSION_9
459 #define SPA_VERSION_REFQUOTA            SPA_VERSION_9
460 #define SPA_VERSION_UNIQUE_ACCURATE     SPA_VERSION_9
461 #define SPA_VERSION_L2CACHE             SPA_VERSION_10
462 #define SPA_VERSION_NEXT_CLONES         SPA_VERSION_11
463 #define SPA_VERSION_ORIGIN              SPA_VERSION_11
464 #define SPA_VERSION_DSL_SCRUB           SPA_VERSION_11
465 #define SPA_VERSION_SNAP_PROPS          SPA_VERSION_12
466 #define SPA_VERSION_USED_BREAKDOWN      SPA_VERSION_13
467 #define SPA_VERSION_PASSTHROUGH_X       SPA_VERSION_14
468 #define SPA_VERSION_USERSPACE           SPA_VERSION_15
469 #define SPA_VERSION_STMF_PROP           SPA_VERSION_16
470 #define SPA_VERSION_RAIDZ3              SPA_VERSION_17
471 #define SPA_VERSION_USERREFS            SPA_VERSION_18
472 #define SPA_VERSION_HOLES               SPA_VERSION_19
473 #define SPA_VERSION_ZLE_COMPRESSION     SPA_VERSION_20
474 #define SPA_VERSION_DEDUP               SPA_VERSION_21
475 #define SPA_VERSION_RECVD_PROPS         SPA_VERSION_22
476 #define SPA_VERSION_SLIM_ZIL            SPA_VERSION_23
477 #define SPA_VERSION_SA                  SPA_VERSION_24
478 #define SPA_VERSION_SCAN                SPA_VERSION_25
479 #define SPA_VERSION_DIR_CLONES          SPA_VERSION_26
480 #define SPA_VERSION_DEADLISTS           SPA_VERSION_26
481 #define SPA_VERSION_FAST_SNAP           SPA_VERSION_27
482 #define SPA_VERSION_MULTI_REPLACE       SPA_VERSION_28
483 #define SPA_VERSION_BEFORE_FEATURES     SPA_VERSION_28
484 #define SPA_VERSION_FEATURES            SPA_VERSION_5000
485
486 #define SPA_VERSION_IS_SUPPORTED(v) \
487         (((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \
488         ((v) >= SPA_VERSION_FEATURES && (v) <= SPA_VERSION))
489
490 /*
491  * ZPL version - rev'd whenever an incompatible on-disk format change
492  * occurs.  This is independent of SPA/DMU/ZAP versioning.  You must
493  * also update the version_table[] and help message in zfs_prop.c.
494  *
495  * When changing, be sure to teach GRUB how to read the new format!
496  * See usr/src/grub/grub-0.97/stage2/{zfs-include/,fsys_zfs*}
497  */
498 #define ZPL_VERSION_1                   1ULL
499 #define ZPL_VERSION_2                   2ULL
500 #define ZPL_VERSION_3                   3ULL
501 #define ZPL_VERSION_4                   4ULL
502 #define ZPL_VERSION_5                   5ULL
503 #define ZPL_VERSION                     ZPL_VERSION_5
504 #define ZPL_VERSION_STRING              "5"
505
506 #define ZPL_VERSION_INITIAL             ZPL_VERSION_1
507 #define ZPL_VERSION_DIRENT_TYPE         ZPL_VERSION_2
508 #define ZPL_VERSION_FUID                ZPL_VERSION_3
509 #define ZPL_VERSION_NORMALIZATION       ZPL_VERSION_3
510 #define ZPL_VERSION_SYSATTR             ZPL_VERSION_3
511 #define ZPL_VERSION_USERSPACE           ZPL_VERSION_4
512 #define ZPL_VERSION_SA                  ZPL_VERSION_5
513
514 /* Rewind request information */
515 #define ZPOOL_NO_REWIND         1  /* No policy - default behavior */
516 #define ZPOOL_NEVER_REWIND      2  /* Do not search for best txg or rewind */
517 #define ZPOOL_TRY_REWIND        4  /* Search for best txg, but do not rewind */
518 #define ZPOOL_DO_REWIND         8  /* Rewind to best txg w/in deferred frees */
519 #define ZPOOL_EXTREME_REWIND    16 /* Allow extreme measures to find best txg */
520 #define ZPOOL_REWIND_MASK       28 /* All the possible rewind bits */
521 #define ZPOOL_REWIND_POLICIES   31 /* All the possible policy bits */
522
523 typedef struct zpool_rewind_policy {
524         uint32_t        zrp_request;    /* rewind behavior requested */
525         uint64_t        zrp_maxmeta;    /* max acceptable meta-data errors */
526         uint64_t        zrp_maxdata;    /* max acceptable data errors */
527         uint64_t        zrp_txg;        /* specific txg to load */
528 } zpool_rewind_policy_t;
529
530 /*
531  * The following are configuration names used in the nvlist describing a pool's
532  * configuration.
533  */
534 #define ZPOOL_CONFIG_VERSION            "version"
535 #define ZPOOL_CONFIG_POOL_NAME          "name"
536 #define ZPOOL_CONFIG_POOL_STATE         "state"
537 #define ZPOOL_CONFIG_POOL_TXG           "txg"
538 #define ZPOOL_CONFIG_POOL_GUID          "pool_guid"
539 #define ZPOOL_CONFIG_CREATE_TXG         "create_txg"
540 #define ZPOOL_CONFIG_TOP_GUID           "top_guid"
541 #define ZPOOL_CONFIG_VDEV_TREE          "vdev_tree"
542 #define ZPOOL_CONFIG_TYPE               "type"
543 #define ZPOOL_CONFIG_CHILDREN           "children"
544 #define ZPOOL_CONFIG_ID                 "id"
545 #define ZPOOL_CONFIG_GUID               "guid"
546 #define ZPOOL_CONFIG_PATH               "path"
547 #define ZPOOL_CONFIG_DEVID              "devid"
548 #define ZPOOL_CONFIG_METASLAB_ARRAY     "metaslab_array"
549 #define ZPOOL_CONFIG_METASLAB_SHIFT     "metaslab_shift"
550 #define ZPOOL_CONFIG_ASHIFT             "ashift"
551 #define ZPOOL_CONFIG_ASIZE              "asize"
552 #define ZPOOL_CONFIG_DTL                "DTL"
553 #define ZPOOL_CONFIG_SCAN_STATS         "scan_stats"    /* not stored on disk */
554 #define ZPOOL_CONFIG_VDEV_STATS         "vdev_stats"    /* not stored on disk */
555
556 /* container nvlist of extended stats */
557 #define ZPOOL_CONFIG_VDEV_STATS_EX      "vdev_stats_ex"
558
559 /* Active queue read/write stats */
560 #define ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE   "vdev_sync_r_active_queue"
561 #define ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE   "vdev_sync_w_active_queue"
562 #define ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE  "vdev_async_r_active_queue"
563 #define ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE  "vdev_async_w_active_queue"
564 #define ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE    "vdev_async_scrub_active_queue"
565
566 /* Queue sizes */
567 #define ZPOOL_CONFIG_VDEV_SYNC_R_PEND_QUEUE     "vdev_sync_r_pend_queue"
568 #define ZPOOL_CONFIG_VDEV_SYNC_W_PEND_QUEUE     "vdev_sync_w_pend_queue"
569 #define ZPOOL_CONFIG_VDEV_ASYNC_R_PEND_QUEUE    "vdev_async_r_pend_queue"
570 #define ZPOOL_CONFIG_VDEV_ASYNC_W_PEND_QUEUE    "vdev_async_w_pend_queue"
571 #define ZPOOL_CONFIG_VDEV_SCRUB_PEND_QUEUE      "vdev_async_scrub_pend_queue"
572
573 /* Latency read/write histogram stats */
574 #define ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO       "vdev_tot_r_lat_histo"
575 #define ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO       "vdev_tot_w_lat_histo"
576 #define ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO      "vdev_disk_r_lat_histo"
577 #define ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO      "vdev_disk_w_lat_histo"
578 #define ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO      "vdev_sync_r_lat_histo"
579 #define ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO      "vdev_sync_w_lat_histo"
580 #define ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO     "vdev_async_r_lat_histo"
581 #define ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO     "vdev_async_w_lat_histo"
582 #define ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO       "vdev_scrub_histo"
583
584 /* Request size histograms */
585 #define ZPOOL_CONFIG_VDEV_SYNC_IND_R_HISTO      "vdev_sync_ind_r_histo"
586 #define ZPOOL_CONFIG_VDEV_SYNC_IND_W_HISTO      "vdev_sync_ind_w_histo"
587 #define ZPOOL_CONFIG_VDEV_ASYNC_IND_R_HISTO     "vdev_async_ind_r_histo"
588 #define ZPOOL_CONFIG_VDEV_ASYNC_IND_W_HISTO     "vdev_async_ind_w_histo"
589 #define ZPOOL_CONFIG_VDEV_IND_SCRUB_HISTO       "vdev_ind_scrub_histo"
590 #define ZPOOL_CONFIG_VDEV_SYNC_AGG_R_HISTO      "vdev_sync_agg_r_histo"
591 #define ZPOOL_CONFIG_VDEV_SYNC_AGG_W_HISTO      "vdev_sync_agg_w_histo"
592 #define ZPOOL_CONFIG_VDEV_ASYNC_AGG_R_HISTO     "vdev_async_agg_r_histo"
593 #define ZPOOL_CONFIG_VDEV_ASYNC_AGG_W_HISTO     "vdev_async_agg_w_histo"
594 #define ZPOOL_CONFIG_VDEV_AGG_SCRUB_HISTO       "vdev_agg_scrub_histo"
595
596 /* vdev enclosure sysfs path */
597 #define ZPOOL_CONFIG_VDEV_ENC_SYSFS_PATH        "vdev_enc_sysfs_path"
598
599 #define ZPOOL_CONFIG_WHOLE_DISK         "whole_disk"
600 #define ZPOOL_CONFIG_ERRCOUNT           "error_count"
601 #define ZPOOL_CONFIG_NOT_PRESENT        "not_present"
602 #define ZPOOL_CONFIG_SPARES             "spares"
603 #define ZPOOL_CONFIG_IS_SPARE           "is_spare"
604 #define ZPOOL_CONFIG_NPARITY            "nparity"
605 #define ZPOOL_CONFIG_HOSTID             "hostid"
606 #define ZPOOL_CONFIG_HOSTNAME           "hostname"
607 #define ZPOOL_CONFIG_LOADED_TIME        "initial_load_time"
608 #define ZPOOL_CONFIG_UNSPARE            "unspare"
609 #define ZPOOL_CONFIG_PHYS_PATH          "phys_path"
610 #define ZPOOL_CONFIG_IS_LOG             "is_log"
611 #define ZPOOL_CONFIG_L2CACHE            "l2cache"
612 #define ZPOOL_CONFIG_HOLE_ARRAY         "hole_array"
613 #define ZPOOL_CONFIG_VDEV_CHILDREN      "vdev_children"
614 #define ZPOOL_CONFIG_IS_HOLE            "is_hole"
615 #define ZPOOL_CONFIG_DDT_HISTOGRAM      "ddt_histogram"
616 #define ZPOOL_CONFIG_DDT_OBJ_STATS      "ddt_object_stats"
617 #define ZPOOL_CONFIG_DDT_STATS          "ddt_stats"
618 #define ZPOOL_CONFIG_SPLIT              "splitcfg"
619 #define ZPOOL_CONFIG_ORIG_GUID          "orig_guid"
620 #define ZPOOL_CONFIG_SPLIT_GUID         "split_guid"
621 #define ZPOOL_CONFIG_SPLIT_LIST         "guid_list"
622 #define ZPOOL_CONFIG_REMOVING           "removing"
623 #define ZPOOL_CONFIG_RESILVER_TXG       "resilver_txg"
624 #define ZPOOL_CONFIG_COMMENT            "comment"
625 #define ZPOOL_CONFIG_SUSPENDED          "suspended"     /* not stored on disk */
626 #define ZPOOL_CONFIG_TIMESTAMP          "timestamp"     /* not stored on disk */
627 #define ZPOOL_CONFIG_BOOTFS             "bootfs"        /* not stored on disk */
628 #define ZPOOL_CONFIG_MISSING_DEVICES    "missing_vdevs" /* not stored on disk */
629 #define ZPOOL_CONFIG_LOAD_INFO          "load_info"     /* not stored on disk */
630 #define ZPOOL_CONFIG_REWIND_INFO        "rewind_info"   /* not stored on disk */
631 #define ZPOOL_CONFIG_UNSUP_FEAT         "unsup_feat"    /* not stored on disk */
632 #define ZPOOL_CONFIG_ENABLED_FEAT       "enabled_feat"  /* not stored on disk */
633 #define ZPOOL_CONFIG_CAN_RDONLY         "can_rdonly"    /* not stored on disk */
634 #define ZPOOL_CONFIG_FEATURES_FOR_READ  "features_for_read"
635 #define ZPOOL_CONFIG_FEATURE_STATS      "feature_stats" /* not stored on disk */
636 #define ZPOOL_CONFIG_ERRATA             "errata"        /* not stored on disk */
637 #define ZPOOL_CONFIG_VDEV_TOP_ZAP       "com.delphix:vdev_zap_top"
638 #define ZPOOL_CONFIG_VDEV_LEAF_ZAP      "com.delphix:vdev_zap_leaf"
639 #define ZPOOL_CONFIG_HAS_PER_VDEV_ZAPS  "com.delphix:has_per_vdev_zaps"
640 /*
641  * The persistent vdev state is stored as separate values rather than a single
642  * 'vdev_state' entry.  This is because a device can be in multiple states, such
643  * as offline and degraded.
644  */
645 #define ZPOOL_CONFIG_OFFLINE            "offline"
646 #define ZPOOL_CONFIG_FAULTED            "faulted"
647 #define ZPOOL_CONFIG_DEGRADED           "degraded"
648 #define ZPOOL_CONFIG_REMOVED            "removed"
649 #define ZPOOL_CONFIG_FRU                "fru"
650 #define ZPOOL_CONFIG_AUX_STATE          "aux_state"
651
652 /* Rewind policy parameters */
653 #define ZPOOL_REWIND_POLICY             "rewind-policy"
654 #define ZPOOL_REWIND_REQUEST            "rewind-request"
655 #define ZPOOL_REWIND_REQUEST_TXG        "rewind-request-txg"
656 #define ZPOOL_REWIND_META_THRESH        "rewind-meta-thresh"
657 #define ZPOOL_REWIND_DATA_THRESH        "rewind-data-thresh"
658
659 /* Rewind data discovered */
660 #define ZPOOL_CONFIG_LOAD_TIME          "rewind_txg_ts"
661 #define ZPOOL_CONFIG_LOAD_DATA_ERRORS   "verify_data_errors"
662 #define ZPOOL_CONFIG_REWIND_TIME        "seconds_of_rewind"
663
664 #define VDEV_TYPE_ROOT                  "root"
665 #define VDEV_TYPE_MIRROR                "mirror"
666 #define VDEV_TYPE_REPLACING             "replacing"
667 #define VDEV_TYPE_RAIDZ                 "raidz"
668 #define VDEV_TYPE_DISK                  "disk"
669 #define VDEV_TYPE_FILE                  "file"
670 #define VDEV_TYPE_MISSING               "missing"
671 #define VDEV_TYPE_HOLE                  "hole"
672 #define VDEV_TYPE_SPARE                 "spare"
673 #define VDEV_TYPE_LOG                   "log"
674 #define VDEV_TYPE_L2CACHE               "l2cache"
675
676 /*
677  * This is needed in userland to report the minimum necessary device size.
678  */
679 #define SPA_MINDEVSIZE          (64ULL << 20)
680
681 /*
682  * Set if the fragmentation has not yet been calculated. This can happen
683  * because the space maps have not been upgraded or the histogram feature
684  * is not enabled.
685  */
686 #define ZFS_FRAG_INVALID        UINT64_MAX
687
688 /*
689  * The location of the pool configuration repository, shared between kernel and
690  * userland.
691  */
692 #define ZPOOL_CACHE             "/etc/zfs/zpool.cache"
693
694 /*
695  * vdev states are ordered from least to most healthy.
696  * A vdev that's CANT_OPEN or below is considered unusable.
697  */
698 typedef enum vdev_state {
699         VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev                   */
700         VDEV_STATE_CLOSED,      /* Not currently open                   */
701         VDEV_STATE_OFFLINE,     /* Not allowed to open                  */
702         VDEV_STATE_REMOVED,     /* Explicitly removed from system       */
703         VDEV_STATE_CANT_OPEN,   /* Tried to open, but failed            */
704         VDEV_STATE_FAULTED,     /* External request to fault device     */
705         VDEV_STATE_DEGRADED,    /* Replicated vdev with unhealthy kids  */
706         VDEV_STATE_HEALTHY      /* Presumed good                        */
707 } vdev_state_t;
708
709 #define VDEV_STATE_ONLINE       VDEV_STATE_HEALTHY
710
711 /*
712  * vdev aux states.  When a vdev is in the CANT_OPEN state, the aux field
713  * of the vdev stats structure uses these constants to distinguish why.
714  */
715 typedef enum vdev_aux {
716         VDEV_AUX_NONE,          /* no error                             */
717         VDEV_AUX_OPEN_FAILED,   /* ldi_open_*() or vn_open() failed     */
718         VDEV_AUX_CORRUPT_DATA,  /* bad label or disk contents           */
719         VDEV_AUX_NO_REPLICAS,   /* insufficient number of replicas      */
720         VDEV_AUX_BAD_GUID_SUM,  /* vdev guid sum doesn't match          */
721         VDEV_AUX_TOO_SMALL,     /* vdev size is too small               */
722         VDEV_AUX_BAD_LABEL,     /* the label is OK but invalid          */
723         VDEV_AUX_VERSION_NEWER, /* on-disk version is too new           */
724         VDEV_AUX_VERSION_OLDER, /* on-disk version is too old           */
725         VDEV_AUX_UNSUP_FEAT,    /* unsupported features                 */
726         VDEV_AUX_SPARED,        /* hot spare used in another pool       */
727         VDEV_AUX_ERR_EXCEEDED,  /* too many errors                      */
728         VDEV_AUX_IO_FAILURE,    /* experienced I/O failure              */
729         VDEV_AUX_BAD_LOG,       /* cannot read log chain(s)             */
730         VDEV_AUX_EXTERNAL,      /* external diagnosis                   */
731         VDEV_AUX_SPLIT_POOL     /* vdev was split off into another pool */
732 } vdev_aux_t;
733
734 /*
735  * pool state.  The following states are written to disk as part of the normal
736  * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE.  The remaining
737  * states are software abstractions used at various levels to communicate
738  * pool state.
739  */
740 typedef enum pool_state {
741         POOL_STATE_ACTIVE = 0,          /* In active use                */
742         POOL_STATE_EXPORTED,            /* Explicitly exported          */
743         POOL_STATE_DESTROYED,           /* Explicitly destroyed         */
744         POOL_STATE_SPARE,               /* Reserved for hot spare use   */
745         POOL_STATE_L2CACHE,             /* Level 2 ARC device           */
746         POOL_STATE_UNINITIALIZED,       /* Internal spa_t state         */
747         POOL_STATE_UNAVAIL,             /* Internal libzfs state        */
748         POOL_STATE_POTENTIALLY_ACTIVE   /* Internal libzfs state        */
749 } pool_state_t;
750
751 /*
752  * Scan Functions.
753  */
754 typedef enum pool_scan_func {
755         POOL_SCAN_NONE,
756         POOL_SCAN_SCRUB,
757         POOL_SCAN_RESILVER,
758         POOL_SCAN_FUNCS
759 } pool_scan_func_t;
760
761 /*
762  * ZIO types.  Needed to interpret vdev statistics below.
763  */
764 typedef enum zio_type {
765         ZIO_TYPE_NULL = 0,
766         ZIO_TYPE_READ,
767         ZIO_TYPE_WRITE,
768         ZIO_TYPE_FREE,
769         ZIO_TYPE_CLAIM,
770         ZIO_TYPE_IOCTL,
771         ZIO_TYPES
772 } zio_type_t;
773
774 /*
775  * Pool statistics.  Note: all fields should be 64-bit because this
776  * is passed between kernel and userland as an nvlist uint64 array.
777  */
778 typedef struct pool_scan_stat {
779         /* values stored on disk */
780         uint64_t        pss_func;       /* pool_scan_func_t */
781         uint64_t        pss_state;      /* dsl_scan_state_t */
782         uint64_t        pss_start_time; /* scan start time */
783         uint64_t        pss_end_time;   /* scan end time */
784         uint64_t        pss_to_examine; /* total bytes to scan */
785         uint64_t        pss_examined;   /* total examined bytes */
786         uint64_t        pss_to_process; /* total bytes to process */
787         uint64_t        pss_processed;  /* total processed bytes */
788         uint64_t        pss_errors;     /* scan errors  */
789
790         /* values not stored on disk */
791         uint64_t        pss_pass_exam;  /* examined bytes per scan pass */
792         uint64_t        pss_pass_start; /* start time of a scan pass */
793 } pool_scan_stat_t;
794
795 typedef enum dsl_scan_state {
796         DSS_NONE,
797         DSS_SCANNING,
798         DSS_FINISHED,
799         DSS_CANCELED,
800         DSS_NUM_STATES
801 } dsl_scan_state_t;
802
803 /*
804  * Errata described by http://zfsonlinux.org/msg/ZFS-8000-ER.  The ordering
805  * of this enum must be maintained to ensure the errata identifiers map to
806  * the correct documentation.  New errata may only be appended to the list
807  * and must contain corresponding documentation at the above link.
808  */
809 typedef enum zpool_errata {
810         ZPOOL_ERRATA_NONE,
811         ZPOOL_ERRATA_ZOL_2094_SCRUB,
812         ZPOOL_ERRATA_ZOL_2094_ASYNC_DESTROY,
813 } zpool_errata_t;
814
815 /*
816  * Vdev statistics.  Note: all fields should be 64-bit because this
817  * is passed between kernel and userland as an nvlist uint64 array.
818  */
819 typedef struct vdev_stat {
820         hrtime_t        vs_timestamp;           /* time since vdev load */
821         uint64_t        vs_state;               /* vdev state           */
822         uint64_t        vs_aux;                 /* see vdev_aux_t       */
823         uint64_t        vs_alloc;               /* space allocated      */
824         uint64_t        vs_space;               /* total capacity       */
825         uint64_t        vs_dspace;              /* deflated capacity    */
826         uint64_t        vs_rsize;               /* replaceable dev size */
827         uint64_t        vs_esize;               /* expandable dev size */
828         uint64_t        vs_ops[ZIO_TYPES];      /* operation count      */
829         uint64_t        vs_bytes[ZIO_TYPES];    /* bytes read/written   */
830         uint64_t        vs_read_errors;         /* read errors          */
831         uint64_t        vs_write_errors;        /* write errors         */
832         uint64_t        vs_checksum_errors;     /* checksum errors      */
833         uint64_t        vs_self_healed;         /* self-healed bytes    */
834         uint64_t        vs_scan_removing;       /* removing?    */
835         uint64_t        vs_scan_processed;      /* scan processed bytes */
836         uint64_t        vs_fragmentation;       /* device fragmentation */
837
838 } vdev_stat_t;
839
840 /*
841  * Extended stats
842  *
843  * These are stats which aren't included in the original iostat output.  For
844  * convenience, they are grouped together in vdev_stat_ex, although each stat
845  * is individually exported as an nvlist.
846  */
847 typedef struct vdev_stat_ex {
848         /* Number of ZIOs issued to disk and waiting to finish */
849         uint64_t vsx_active_queue[ZIO_PRIORITY_NUM_QUEUEABLE];
850
851         /* Number of ZIOs pending to be issued to disk */
852         uint64_t vsx_pend_queue[ZIO_PRIORITY_NUM_QUEUEABLE];
853
854         /*
855          * Below are the histograms for various latencies. Buckets are in
856          * units of nanoseconds.
857          */
858
859         /*
860          * 2^37 nanoseconds = 134s. Timeouts will probably start kicking in
861          * before this.
862          */
863 #define VDEV_L_HISTO_BUCKETS 37         /* Latency histo buckets */
864 #define VDEV_RQ_HISTO_BUCKETS 25        /* Request size histo buckets */
865
866
867         /* Amount of time in ZIO queue (ns) */
868         uint64_t vsx_queue_histo[ZIO_PRIORITY_NUM_QUEUEABLE]
869             [VDEV_L_HISTO_BUCKETS];
870
871         /* Total ZIO latency (ns).  Includes queuing and disk access time */
872         uint64_t vsx_total_histo[ZIO_TYPES][VDEV_L_HISTO_BUCKETS];
873
874         /* Amount of time to read/write the disk (ns) */
875         uint64_t vsx_disk_histo[ZIO_TYPES][VDEV_L_HISTO_BUCKETS];
876
877         /* "lookup the bucket for a value" histogram macros */
878 #define HISTO(val, buckets) (val != 0 ? MIN(highbit64(val) - 1, \
879             buckets - 1) : 0)
880 #define L_HISTO(a) HISTO(a, VDEV_L_HISTO_BUCKETS)
881 #define RQ_HISTO(a) HISTO(a, VDEV_RQ_HISTO_BUCKETS)
882
883         /* Physical IO histogram */
884         uint64_t vsx_ind_histo[ZIO_PRIORITY_NUM_QUEUEABLE]
885             [VDEV_RQ_HISTO_BUCKETS];
886
887         /* Delegated (aggregated) physical IO histogram */
888         uint64_t vsx_agg_histo[ZIO_PRIORITY_NUM_QUEUEABLE]
889             [VDEV_RQ_HISTO_BUCKETS];
890
891 } vdev_stat_ex_t;
892
893 /*
894  * DDT statistics.  Note: all fields should be 64-bit because this
895  * is passed between kernel and userland as an nvlist uint64 array.
896  */
897 typedef struct ddt_object {
898         uint64_t        ddo_count;      /* number of elements in ddt    */
899         uint64_t        ddo_dspace;     /* size of ddt on disk          */
900         uint64_t        ddo_mspace;     /* size of ddt in-core          */
901 } ddt_object_t;
902
903 typedef struct ddt_stat {
904         uint64_t        dds_blocks;     /* blocks                       */
905         uint64_t        dds_lsize;      /* logical size                 */
906         uint64_t        dds_psize;      /* physical size                */
907         uint64_t        dds_dsize;      /* deflated allocated size      */
908         uint64_t        dds_ref_blocks; /* referenced blocks            */
909         uint64_t        dds_ref_lsize;  /* referenced lsize * refcnt    */
910         uint64_t        dds_ref_psize;  /* referenced psize * refcnt    */
911         uint64_t        dds_ref_dsize;  /* referenced dsize * refcnt    */
912 } ddt_stat_t;
913
914 typedef struct ddt_histogram {
915         ddt_stat_t      ddh_stat[64];   /* power-of-two histogram buckets */
916 } ddt_histogram_t;
917
918 #define ZVOL_DRIVER     "zvol"
919 #define ZFS_DRIVER      "zfs"
920 #define ZFS_DEV         "/dev/zfs"
921 #define ZFS_SHARETAB    "/etc/dfs/sharetab"
922
923 /* general zvol path */
924 #define ZVOL_DIR        "/dev"
925
926 #define ZVOL_MAJOR              230
927 #define ZVOL_MINOR_BITS         4
928 #define ZVOL_MINOR_MASK         ((1U << ZVOL_MINOR_BITS) - 1)
929 #define ZVOL_MINORS             (1 << 4)
930 #define ZVOL_DEV_NAME           "zd"
931
932 #define ZVOL_PROP_NAME          "name"
933 #define ZVOL_DEFAULT_BLOCKSIZE  8192
934
935 /*
936  * /dev/zfs ioctl numbers.
937  */
938 typedef enum zfs_ioc {
939         /*
940          * Illumos - 71/128 numbers reserved.
941          */
942         ZFS_IOC_FIRST = ('Z' << 8),
943         ZFS_IOC = ZFS_IOC_FIRST,
944         ZFS_IOC_POOL_CREATE = ZFS_IOC_FIRST,
945         ZFS_IOC_POOL_DESTROY,
946         ZFS_IOC_POOL_IMPORT,
947         ZFS_IOC_POOL_EXPORT,
948         ZFS_IOC_POOL_CONFIGS,
949         ZFS_IOC_POOL_STATS,
950         ZFS_IOC_POOL_TRYIMPORT,
951         ZFS_IOC_POOL_SCAN,
952         ZFS_IOC_POOL_FREEZE,
953         ZFS_IOC_POOL_UPGRADE,
954         ZFS_IOC_POOL_GET_HISTORY,
955         ZFS_IOC_VDEV_ADD,
956         ZFS_IOC_VDEV_REMOVE,
957         ZFS_IOC_VDEV_SET_STATE,
958         ZFS_IOC_VDEV_ATTACH,
959         ZFS_IOC_VDEV_DETACH,
960         ZFS_IOC_VDEV_SETPATH,
961         ZFS_IOC_VDEV_SETFRU,
962         ZFS_IOC_OBJSET_STATS,
963         ZFS_IOC_OBJSET_ZPLPROPS,
964         ZFS_IOC_DATASET_LIST_NEXT,
965         ZFS_IOC_SNAPSHOT_LIST_NEXT,
966         ZFS_IOC_SET_PROP,
967         ZFS_IOC_CREATE,
968         ZFS_IOC_DESTROY,
969         ZFS_IOC_ROLLBACK,
970         ZFS_IOC_RENAME,
971         ZFS_IOC_RECV,
972         ZFS_IOC_SEND,
973         ZFS_IOC_INJECT_FAULT,
974         ZFS_IOC_CLEAR_FAULT,
975         ZFS_IOC_INJECT_LIST_NEXT,
976         ZFS_IOC_ERROR_LOG,
977         ZFS_IOC_CLEAR,
978         ZFS_IOC_PROMOTE,
979         ZFS_IOC_SNAPSHOT,
980         ZFS_IOC_DSOBJ_TO_DSNAME,
981         ZFS_IOC_OBJ_TO_PATH,
982         ZFS_IOC_POOL_SET_PROPS,
983         ZFS_IOC_POOL_GET_PROPS,
984         ZFS_IOC_SET_FSACL,
985         ZFS_IOC_GET_FSACL,
986         ZFS_IOC_SHARE,
987         ZFS_IOC_INHERIT_PROP,
988         ZFS_IOC_SMB_ACL,
989         ZFS_IOC_USERSPACE_ONE,
990         ZFS_IOC_USERSPACE_MANY,
991         ZFS_IOC_USERSPACE_UPGRADE,
992         ZFS_IOC_HOLD,
993         ZFS_IOC_RELEASE,
994         ZFS_IOC_GET_HOLDS,
995         ZFS_IOC_OBJSET_RECVD_PROPS,
996         ZFS_IOC_VDEV_SPLIT,
997         ZFS_IOC_NEXT_OBJ,
998         ZFS_IOC_DIFF,
999         ZFS_IOC_TMP_SNAPSHOT,
1000         ZFS_IOC_OBJ_TO_STATS,
1001         ZFS_IOC_SPACE_WRITTEN,
1002         ZFS_IOC_SPACE_SNAPS,
1003         ZFS_IOC_DESTROY_SNAPS,
1004         ZFS_IOC_POOL_REGUID,
1005         ZFS_IOC_POOL_REOPEN,
1006         ZFS_IOC_SEND_PROGRESS,
1007         ZFS_IOC_LOG_HISTORY,
1008         ZFS_IOC_SEND_NEW,
1009         ZFS_IOC_SEND_SPACE,
1010         ZFS_IOC_CLONE,
1011         ZFS_IOC_BOOKMARK,
1012         ZFS_IOC_GET_BOOKMARKS,
1013         ZFS_IOC_DESTROY_BOOKMARKS,
1014         ZFS_IOC_RECV_NEW,
1015
1016         /*
1017          * Linux - 3/64 numbers reserved.
1018          */
1019         ZFS_IOC_LINUX = ('Z' << 8) + 0x80,
1020         ZFS_IOC_EVENTS_NEXT,
1021         ZFS_IOC_EVENTS_CLEAR,
1022         ZFS_IOC_EVENTS_SEEK,
1023
1024         /*
1025          * FreeBSD - 1/64 numbers reserved.
1026          */
1027         ZFS_IOC_FREEBSD = ('Z' << 8) + 0xC0,
1028
1029         ZFS_IOC_LAST
1030 } zfs_ioc_t;
1031
1032 /*
1033  * zvol ioctl to get dataset name
1034  */
1035 #define BLKZNAME                _IOR(0x12, 125, char[ZFS_MAX_DATASET_NAME_LEN])
1036
1037 /*
1038  * Internal SPA load state.  Used by FMA diagnosis engine.
1039  */
1040 typedef enum {
1041         SPA_LOAD_NONE,          /* no load in progress  */
1042         SPA_LOAD_OPEN,          /* normal open          */
1043         SPA_LOAD_IMPORT,        /* import in progress   */
1044         SPA_LOAD_TRYIMPORT,     /* tryimport in progress */
1045         SPA_LOAD_RECOVER,       /* recovery requested   */
1046         SPA_LOAD_ERROR,         /* load failed          */
1047         SPA_LOAD_CREATE         /* creation in progress */
1048 } spa_load_state_t;
1049
1050 /*
1051  * Bookmark name values.
1052  */
1053 #define ZPOOL_ERR_LIST          "error list"
1054 #define ZPOOL_ERR_DATASET       "dataset"
1055 #define ZPOOL_ERR_OBJECT        "object"
1056
1057 #define HIS_MAX_RECORD_LEN      (MAXPATHLEN + MAXPATHLEN + 1)
1058
1059 /*
1060  * The following are names used in the nvlist describing
1061  * the pool's history log.
1062  */
1063 #define ZPOOL_HIST_RECORD       "history record"
1064 #define ZPOOL_HIST_TIME         "history time"
1065 #define ZPOOL_HIST_CMD          "history command"
1066 #define ZPOOL_HIST_WHO          "history who"
1067 #define ZPOOL_HIST_ZONE         "history zone"
1068 #define ZPOOL_HIST_HOST         "history hostname"
1069 #define ZPOOL_HIST_TXG          "history txg"
1070 #define ZPOOL_HIST_INT_EVENT    "history internal event"
1071 #define ZPOOL_HIST_INT_STR      "history internal str"
1072 #define ZPOOL_HIST_INT_NAME     "internal_name"
1073 #define ZPOOL_HIST_IOCTL        "ioctl"
1074 #define ZPOOL_HIST_INPUT_NVL    "in_nvl"
1075 #define ZPOOL_HIST_OUTPUT_NVL   "out_nvl"
1076 #define ZPOOL_HIST_DSNAME       "dsname"
1077 #define ZPOOL_HIST_DSID         "dsid"
1078
1079 /*
1080  * Flags for ZFS_IOC_VDEV_SET_STATE
1081  */
1082 #define ZFS_ONLINE_CHECKREMOVE  0x1
1083 #define ZFS_ONLINE_UNSPARE      0x2
1084 #define ZFS_ONLINE_FORCEFAULT   0x4
1085 #define ZFS_ONLINE_EXPAND       0x8
1086 #define ZFS_OFFLINE_TEMPORARY   0x1
1087
1088 /*
1089  * Flags for ZFS_IOC_POOL_IMPORT
1090  */
1091 #define ZFS_IMPORT_NORMAL       0x0
1092 #define ZFS_IMPORT_VERBATIM     0x1
1093 #define ZFS_IMPORT_ANY_HOST     0x2
1094 #define ZFS_IMPORT_MISSING_LOG  0x4
1095 #define ZFS_IMPORT_ONLY         0x8
1096 #define ZFS_IMPORT_TEMP_NAME    0x10
1097
1098 /*
1099  * Sysevent payload members.  ZFS will generate the following sysevents with the
1100  * given payloads:
1101  *
1102  *      ESC_ZFS_RESILVER_START
1103  *      ESC_ZFS_RESILVER_END
1104  *      ESC_ZFS_POOL_DESTROY
1105  *      ESC_ZFS_POOL_REGUID
1106  *
1107  *              ZFS_EV_POOL_NAME        DATA_TYPE_STRING
1108  *              ZFS_EV_POOL_GUID        DATA_TYPE_UINT64
1109  *
1110  *      ESC_ZFS_VDEV_REMOVE
1111  *      ESC_ZFS_VDEV_CLEAR
1112  *      ESC_ZFS_VDEV_CHECK
1113  *
1114  *              ZFS_EV_POOL_NAME        DATA_TYPE_STRING
1115  *              ZFS_EV_POOL_GUID        DATA_TYPE_UINT64
1116  *              ZFS_EV_VDEV_PATH        DATA_TYPE_STRING        (optional)
1117  *              ZFS_EV_VDEV_GUID        DATA_TYPE_UINT64
1118  */
1119 #define ZFS_EV_POOL_NAME        "pool_name"
1120 #define ZFS_EV_POOL_GUID        "pool_guid"
1121 #define ZFS_EV_VDEV_PATH        "vdev_path"
1122 #define ZFS_EV_VDEV_GUID        "vdev_guid"
1123
1124 #ifdef  __cplusplus
1125 }
1126 #endif
1127
1128 #endif  /* _SYS_FS_ZFS_H */