032a952afdf8db6c5857a2ee4c3632718eb900b4
[zfs.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 by Delphix. All rights reserved.
25  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
26  */
27
28 /* Portions Copyright 2010 Robert Milkowski */
29
30 #ifndef _SYS_FS_ZFS_H
31 #define _SYS_FS_ZFS_H
32
33 #include <sys/time.h>
34
35 #ifdef  __cplusplus
36 extern "C" {
37 #endif
38
39 /*
40  * Types and constants shared between userland and the kernel.
41  */
42
43 /*
44  * Each dataset can be one of the following types.  These constants can be
45  * combined into masks that can be passed to various functions.
46  */
47 typedef enum {
48         ZFS_TYPE_FILESYSTEM     = 0x1,
49         ZFS_TYPE_SNAPSHOT       = 0x2,
50         ZFS_TYPE_VOLUME         = 0x4,
51         ZFS_TYPE_POOL           = 0x8
52 } zfs_type_t;
53
54 #define ZFS_TYPE_DATASET        \
55         (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME | ZFS_TYPE_SNAPSHOT)
56
57 #define ZAP_MAXNAMELEN 256
58 #define ZAP_MAXVALUELEN (1024 * 8)
59 #define ZAP_OLDMAXVALUELEN 1024
60
61 /*
62  * Dataset properties are identified by these constants and must be added to
63  * the end of this list to ensure that external consumers are not affected
64  * by the change. If you make any changes to this list, be sure to update
65  * the property table in usr/src/common/zfs/zfs_prop.c.
66  */
67 typedef enum {
68         ZFS_PROP_TYPE,
69         ZFS_PROP_CREATION,
70         ZFS_PROP_USED,
71         ZFS_PROP_AVAILABLE,
72         ZFS_PROP_REFERENCED,
73         ZFS_PROP_COMPRESSRATIO,
74         ZFS_PROP_MOUNTED,
75         ZFS_PROP_ORIGIN,
76         ZFS_PROP_QUOTA,
77         ZFS_PROP_RESERVATION,
78         ZFS_PROP_VOLSIZE,
79         ZFS_PROP_VOLBLOCKSIZE,
80         ZFS_PROP_RECORDSIZE,
81         ZFS_PROP_MOUNTPOINT,
82         ZFS_PROP_SHARENFS,
83         ZFS_PROP_CHECKSUM,
84         ZFS_PROP_COMPRESSION,
85         ZFS_PROP_ATIME,
86         ZFS_PROP_DEVICES,
87         ZFS_PROP_EXEC,
88         ZFS_PROP_SETUID,
89         ZFS_PROP_READONLY,
90         ZFS_PROP_ZONED,
91         ZFS_PROP_SNAPDIR,
92         ZFS_PROP_PRIVATE,               /* not exposed to user, temporary */
93         ZFS_PROP_ACLINHERIT,
94         ZFS_PROP_CREATETXG,             /* not exposed to the user */
95         ZFS_PROP_NAME,                  /* not exposed to the user */
96         ZFS_PROP_CANMOUNT,
97         ZFS_PROP_ISCSIOPTIONS,          /* not exposed to the user */
98         ZFS_PROP_XATTR,
99         ZFS_PROP_NUMCLONES,             /* not exposed to the user */
100         ZFS_PROP_COPIES,
101         ZFS_PROP_VERSION,
102         ZFS_PROP_UTF8ONLY,
103         ZFS_PROP_NORMALIZE,
104         ZFS_PROP_CASE,
105         ZFS_PROP_VSCAN,
106         ZFS_PROP_NBMAND,
107         ZFS_PROP_SHARESMB,
108         ZFS_PROP_REFQUOTA,
109         ZFS_PROP_REFRESERVATION,
110         ZFS_PROP_GUID,
111         ZFS_PROP_PRIMARYCACHE,
112         ZFS_PROP_SECONDARYCACHE,
113         ZFS_PROP_USEDSNAP,
114         ZFS_PROP_USEDDS,
115         ZFS_PROP_USEDCHILD,
116         ZFS_PROP_USEDREFRESERV,
117         ZFS_PROP_USERACCOUNTING,        /* not exposed to the user */
118         ZFS_PROP_STMF_SHAREINFO,        /* not exposed to the user */
119         ZFS_PROP_DEFER_DESTROY,
120         ZFS_PROP_USERREFS,
121         ZFS_PROP_LOGBIAS,
122         ZFS_PROP_UNIQUE,                /* not exposed to the user */
123         ZFS_PROP_OBJSETID,              /* not exposed to the user */
124         ZFS_PROP_DEDUP,
125         ZFS_PROP_MLSLABEL,
126         ZFS_PROP_SYNC,
127         ZFS_PROP_REFRATIO,
128         ZFS_NUM_PROPS
129 } zfs_prop_t;
130
131 typedef enum {
132         ZFS_PROP_USERUSED,
133         ZFS_PROP_USERQUOTA,
134         ZFS_PROP_GROUPUSED,
135         ZFS_PROP_GROUPQUOTA,
136         ZFS_NUM_USERQUOTA_PROPS
137 } zfs_userquota_prop_t;
138
139 extern const char *zfs_userquota_prop_prefixes[ZFS_NUM_USERQUOTA_PROPS];
140
141 /*
142  * Pool properties are identified by these constants and must be added to the
143  * end of this list to ensure that external consumers are not affected
144  * by the change. If you make any changes to this list, be sure to update
145  * the property table in usr/src/common/zfs/zpool_prop.c.
146  */
147 typedef enum {
148         ZPOOL_PROP_NAME,
149         ZPOOL_PROP_SIZE,
150         ZPOOL_PROP_CAPACITY,
151         ZPOOL_PROP_ALTROOT,
152         ZPOOL_PROP_HEALTH,
153         ZPOOL_PROP_GUID,
154         ZPOOL_PROP_VERSION,
155         ZPOOL_PROP_BOOTFS,
156         ZPOOL_PROP_DELEGATION,
157         ZPOOL_PROP_AUTOREPLACE,
158         ZPOOL_PROP_CACHEFILE,
159         ZPOOL_PROP_FAILUREMODE,
160         ZPOOL_PROP_LISTSNAPS,
161         ZPOOL_PROP_AUTOEXPAND,
162         ZPOOL_PROP_DEDUPDITTO,
163         ZPOOL_PROP_DEDUPRATIO,
164         ZPOOL_PROP_FREE,
165         ZPOOL_PROP_ALLOCATED,
166         ZPOOL_PROP_READONLY,
167         ZPOOL_PROP_ASHIFT,
168         ZPOOL_NUM_PROPS
169 } zpool_prop_t;
170
171 #define ZPROP_CONT              -2
172 #define ZPROP_INVAL             -1
173
174 #define ZPROP_VALUE             "value"
175 #define ZPROP_SOURCE            "source"
176
177 typedef enum {
178         ZPROP_SRC_NONE = 0x1,
179         ZPROP_SRC_DEFAULT = 0x2,
180         ZPROP_SRC_TEMPORARY = 0x4,
181         ZPROP_SRC_LOCAL = 0x8,
182         ZPROP_SRC_INHERITED = 0x10,
183         ZPROP_SRC_RECEIVED = 0x20
184 } zprop_source_t;
185
186 #define ZPROP_SRC_ALL   0x3f
187
188 #define ZPROP_SOURCE_VAL_RECVD  "$recvd"
189 #define ZPROP_N_MORE_ERRORS     "N_MORE_ERRORS"
190 /*
191  * Dataset flag implemented as a special entry in the props zap object
192  * indicating that the dataset has received properties on or after
193  * SPA_VERSION_RECVD_PROPS. The first such receive blows away local properties
194  * just as it did in earlier versions, and thereafter, local properties are
195  * preserved.
196  */
197 #define ZPROP_HAS_RECVD         "$hasrecvd"
198
199 typedef enum {
200         ZPROP_ERR_NOCLEAR = 0x1, /* failure to clear existing props */
201         ZPROP_ERR_NORESTORE = 0x2 /* failure to restore props on error */
202 } zprop_errflags_t;
203
204 typedef int (*zprop_func)(int, void *);
205
206 /*
207  * Properties to be set on the root file system of a new pool
208  * are stuffed into their own nvlist, which is then included in
209  * the properties nvlist with the pool properties.
210  */
211 #define ZPOOL_ROOTFS_PROPS      "root-props-nvl"
212
213 /*
214  * Dataset property functions shared between libzfs and kernel.
215  */
216 const char *zfs_prop_default_string(zfs_prop_t);
217 uint64_t zfs_prop_default_numeric(zfs_prop_t);
218 boolean_t zfs_prop_readonly(zfs_prop_t);
219 boolean_t zfs_prop_inheritable(zfs_prop_t);
220 boolean_t zfs_prop_setonce(zfs_prop_t);
221 const char *zfs_prop_to_name(zfs_prop_t);
222 zfs_prop_t zfs_name_to_prop(const char *);
223 boolean_t zfs_prop_user(const char *);
224 boolean_t zfs_prop_userquota(const char *);
225 int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
226 int zfs_prop_string_to_index(zfs_prop_t, const char *, uint64_t *);
227 uint64_t zfs_prop_random_value(zfs_prop_t, uint64_t seed);
228 boolean_t zfs_prop_valid_for_type(int, zfs_type_t);
229
230 /*
231  * Pool property functions shared between libzfs and kernel.
232  */
233 zpool_prop_t zpool_name_to_prop(const char *);
234 const char *zpool_prop_to_name(zpool_prop_t);
235 const char *zpool_prop_default_string(zpool_prop_t);
236 uint64_t zpool_prop_default_numeric(zpool_prop_t);
237 boolean_t zpool_prop_readonly(zpool_prop_t);
238 int zpool_prop_index_to_string(zpool_prop_t, uint64_t, const char **);
239 int zpool_prop_string_to_index(zpool_prop_t, const char *, uint64_t *);
240 uint64_t zpool_prop_random_value(zpool_prop_t, uint64_t seed);
241
242 /*
243  * Definitions for the Delegation.
244  */
245 typedef enum {
246         ZFS_DELEG_WHO_UNKNOWN = 0,
247         ZFS_DELEG_USER = 'u',
248         ZFS_DELEG_USER_SETS = 'U',
249         ZFS_DELEG_GROUP = 'g',
250         ZFS_DELEG_GROUP_SETS = 'G',
251         ZFS_DELEG_EVERYONE = 'e',
252         ZFS_DELEG_EVERYONE_SETS = 'E',
253         ZFS_DELEG_CREATE = 'c',
254         ZFS_DELEG_CREATE_SETS = 'C',
255         ZFS_DELEG_NAMED_SET = 's',
256         ZFS_DELEG_NAMED_SET_SETS = 'S'
257 } zfs_deleg_who_type_t;
258
259 typedef enum {
260         ZFS_DELEG_NONE = 0,
261         ZFS_DELEG_PERM_LOCAL = 1,
262         ZFS_DELEG_PERM_DESCENDENT = 2,
263         ZFS_DELEG_PERM_LOCALDESCENDENT = 3,
264         ZFS_DELEG_PERM_CREATE = 4
265 } zfs_deleg_inherit_t;
266
267 #define ZFS_DELEG_PERM_UID      "uid"
268 #define ZFS_DELEG_PERM_GID      "gid"
269 #define ZFS_DELEG_PERM_GROUPS   "groups"
270
271 #define ZFS_MLSLABEL_DEFAULT    "none"
272
273 #define ZFS_SMB_ACL_SRC         "src"
274 #define ZFS_SMB_ACL_TARGET      "target"
275
276 typedef enum {
277         ZFS_CANMOUNT_OFF = 0,
278         ZFS_CANMOUNT_ON = 1,
279         ZFS_CANMOUNT_NOAUTO = 2
280 } zfs_canmount_type_t;
281
282 typedef enum {
283         ZFS_LOGBIAS_LATENCY = 0,
284         ZFS_LOGBIAS_THROUGHPUT = 1
285 } zfs_logbias_op_t;
286
287 typedef enum zfs_share_op {
288         ZFS_SHARE_NFS = 0,
289         ZFS_UNSHARE_NFS = 1,
290         ZFS_SHARE_SMB = 2,
291         ZFS_UNSHARE_SMB = 3
292 } zfs_share_op_t;
293
294 typedef enum zfs_smb_acl_op {
295         ZFS_SMB_ACL_ADD,
296         ZFS_SMB_ACL_REMOVE,
297         ZFS_SMB_ACL_RENAME,
298         ZFS_SMB_ACL_PURGE
299 } zfs_smb_acl_op_t;
300
301 typedef enum zfs_cache_type {
302         ZFS_CACHE_NONE = 0,
303         ZFS_CACHE_METADATA = 1,
304         ZFS_CACHE_ALL = 2
305 } zfs_cache_type_t;
306
307 typedef enum {
308         ZFS_SYNC_STANDARD = 0,
309         ZFS_SYNC_ALWAYS = 1,
310         ZFS_SYNC_DISABLED = 2
311 } zfs_sync_type_t;
312
313 typedef enum {
314         ZFS_XATTR_OFF = 0,
315         ZFS_XATTR_DIR = 1,
316         ZFS_XATTR_SA = 2
317 } zfs_xattr_type_t;
318
319 /*
320  * On-disk version number.
321  */
322 #define SPA_VERSION_1                   1ULL
323 #define SPA_VERSION_2                   2ULL
324 #define SPA_VERSION_3                   3ULL
325 #define SPA_VERSION_4                   4ULL
326 #define SPA_VERSION_5                   5ULL
327 #define SPA_VERSION_6                   6ULL
328 #define SPA_VERSION_7                   7ULL
329 #define SPA_VERSION_8                   8ULL
330 #define SPA_VERSION_9                   9ULL
331 #define SPA_VERSION_10                  10ULL
332 #define SPA_VERSION_11                  11ULL
333 #define SPA_VERSION_12                  12ULL
334 #define SPA_VERSION_13                  13ULL
335 #define SPA_VERSION_14                  14ULL
336 #define SPA_VERSION_15                  15ULL
337 #define SPA_VERSION_16                  16ULL
338 #define SPA_VERSION_17                  17ULL
339 #define SPA_VERSION_18                  18ULL
340 #define SPA_VERSION_19                  19ULL
341 #define SPA_VERSION_20                  20ULL
342 #define SPA_VERSION_21                  21ULL
343 #define SPA_VERSION_22                  22ULL
344 #define SPA_VERSION_23                  23ULL
345 #define SPA_VERSION_24                  24ULL
346 #define SPA_VERSION_25                  25ULL
347 #define SPA_VERSION_26                  26ULL
348 #define SPA_VERSION_27                  27ULL
349 #define SPA_VERSION_28                  28ULL
350
351 /*
352  * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk
353  * format change. Go to usr/src/grub/grub-0.97/stage2/{zfs-include/, fsys_zfs*},
354  * and do the appropriate changes.  Also bump the version number in
355  * usr/src/grub/capability.
356  */
357 #define SPA_VERSION                     SPA_VERSION_28
358 #define SPA_VERSION_STRING              "28"
359
360 /*
361  * Symbolic names for the changes that caused a SPA_VERSION switch.
362  * Used in the code when checking for presence or absence of a feature.
363  * Feel free to define multiple symbolic names for each version if there
364  * were multiple changes to on-disk structures during that version.
365  *
366  * NOTE: When checking the current SPA_VERSION in your code, be sure
367  *       to use spa_version() since it reports the version of the
368  *       last synced uberblock.  Checking the in-flight version can
369  *       be dangerous in some cases.
370  */
371 #define SPA_VERSION_INITIAL             SPA_VERSION_1
372 #define SPA_VERSION_DITTO_BLOCKS        SPA_VERSION_2
373 #define SPA_VERSION_SPARES              SPA_VERSION_3
374 #define SPA_VERSION_RAIDZ2              SPA_VERSION_3
375 #define SPA_VERSION_BPOBJ_ACCOUNT       SPA_VERSION_3
376 #define SPA_VERSION_RAIDZ_DEFLATE       SPA_VERSION_3
377 #define SPA_VERSION_DNODE_BYTES         SPA_VERSION_3
378 #define SPA_VERSION_ZPOOL_HISTORY       SPA_VERSION_4
379 #define SPA_VERSION_GZIP_COMPRESSION    SPA_VERSION_5
380 #define SPA_VERSION_BOOTFS              SPA_VERSION_6
381 #define SPA_VERSION_SLOGS               SPA_VERSION_7
382 #define SPA_VERSION_DELEGATED_PERMS     SPA_VERSION_8
383 #define SPA_VERSION_FUID                SPA_VERSION_9
384 #define SPA_VERSION_REFRESERVATION      SPA_VERSION_9
385 #define SPA_VERSION_REFQUOTA            SPA_VERSION_9
386 #define SPA_VERSION_UNIQUE_ACCURATE     SPA_VERSION_9
387 #define SPA_VERSION_L2CACHE             SPA_VERSION_10
388 #define SPA_VERSION_NEXT_CLONES         SPA_VERSION_11
389 #define SPA_VERSION_ORIGIN              SPA_VERSION_11
390 #define SPA_VERSION_DSL_SCRUB           SPA_VERSION_11
391 #define SPA_VERSION_SNAP_PROPS          SPA_VERSION_12
392 #define SPA_VERSION_USED_BREAKDOWN      SPA_VERSION_13
393 #define SPA_VERSION_PASSTHROUGH_X       SPA_VERSION_14
394 #define SPA_VERSION_USERSPACE           SPA_VERSION_15
395 #define SPA_VERSION_STMF_PROP           SPA_VERSION_16
396 #define SPA_VERSION_RAIDZ3              SPA_VERSION_17
397 #define SPA_VERSION_USERREFS            SPA_VERSION_18
398 #define SPA_VERSION_HOLES               SPA_VERSION_19
399 #define SPA_VERSION_ZLE_COMPRESSION     SPA_VERSION_20
400 #define SPA_VERSION_DEDUP               SPA_VERSION_21
401 #define SPA_VERSION_RECVD_PROPS         SPA_VERSION_22
402 #define SPA_VERSION_SLIM_ZIL            SPA_VERSION_23
403 #define SPA_VERSION_SA                  SPA_VERSION_24
404 #define SPA_VERSION_SCAN                SPA_VERSION_25
405 #define SPA_VERSION_DIR_CLONES          SPA_VERSION_26
406 #define SPA_VERSION_DEADLISTS           SPA_VERSION_26
407 #define SPA_VERSION_FAST_SNAP           SPA_VERSION_27
408 #define SPA_VERSION_MULTI_REPLACE       SPA_VERSION_28
409
410 /*
411  * ZPL version - rev'd whenever an incompatible on-disk format change
412  * occurs.  This is independent of SPA/DMU/ZAP versioning.  You must
413  * also update the version_table[] and help message in zfs_prop.c.
414  *
415  * When changing, be sure to teach GRUB how to read the new format!
416  * See usr/src/grub/grub-0.97/stage2/{zfs-include/,fsys_zfs*}
417  */
418 #define ZPL_VERSION_1                   1ULL
419 #define ZPL_VERSION_2                   2ULL
420 #define ZPL_VERSION_3                   3ULL
421 #define ZPL_VERSION_4                   4ULL
422 #define ZPL_VERSION_5                   5ULL
423 #define ZPL_VERSION                     ZPL_VERSION_5
424 #define ZPL_VERSION_STRING              "5"
425
426 #define ZPL_VERSION_INITIAL             ZPL_VERSION_1
427 #define ZPL_VERSION_DIRENT_TYPE         ZPL_VERSION_2
428 #define ZPL_VERSION_FUID                ZPL_VERSION_3
429 #define ZPL_VERSION_NORMALIZATION       ZPL_VERSION_3
430 #define ZPL_VERSION_SYSATTR             ZPL_VERSION_3
431 #define ZPL_VERSION_USERSPACE           ZPL_VERSION_4
432 #define ZPL_VERSION_SA                  ZPL_VERSION_5
433
434 /* Rewind request information */
435 #define ZPOOL_NO_REWIND         1  /* No policy - default behavior */
436 #define ZPOOL_NEVER_REWIND      2  /* Do not search for best txg or rewind */
437 #define ZPOOL_TRY_REWIND        4  /* Search for best txg, but do not rewind */
438 #define ZPOOL_DO_REWIND         8  /* Rewind to best txg w/in deferred frees */
439 #define ZPOOL_EXTREME_REWIND    16 /* Allow extreme measures to find best txg */
440 #define ZPOOL_REWIND_MASK       28 /* All the possible rewind bits */
441 #define ZPOOL_REWIND_POLICIES   31 /* All the possible policy bits */
442
443 typedef struct zpool_rewind_policy {
444         uint32_t        zrp_request;    /* rewind behavior requested */
445         uint64_t        zrp_maxmeta;    /* max acceptable meta-data errors */
446         uint64_t        zrp_maxdata;    /* max acceptable data errors */
447         uint64_t        zrp_txg;        /* specific txg to load */
448 } zpool_rewind_policy_t;
449
450 /*
451  * The following are configuration names used in the nvlist describing a pool's
452  * configuration.
453  */
454 #define ZPOOL_CONFIG_VERSION            "version"
455 #define ZPOOL_CONFIG_POOL_NAME          "name"
456 #define ZPOOL_CONFIG_POOL_STATE         "state"
457 #define ZPOOL_CONFIG_POOL_TXG           "txg"
458 #define ZPOOL_CONFIG_POOL_GUID          "pool_guid"
459 #define ZPOOL_CONFIG_CREATE_TXG         "create_txg"
460 #define ZPOOL_CONFIG_TOP_GUID           "top_guid"
461 #define ZPOOL_CONFIG_VDEV_TREE          "vdev_tree"
462 #define ZPOOL_CONFIG_TYPE               "type"
463 #define ZPOOL_CONFIG_CHILDREN           "children"
464 #define ZPOOL_CONFIG_ID                 "id"
465 #define ZPOOL_CONFIG_GUID               "guid"
466 #define ZPOOL_CONFIG_PATH               "path"
467 #define ZPOOL_CONFIG_DEVID              "devid"
468 #define ZPOOL_CONFIG_METASLAB_ARRAY     "metaslab_array"
469 #define ZPOOL_CONFIG_METASLAB_SHIFT     "metaslab_shift"
470 #define ZPOOL_CONFIG_ASHIFT             "ashift"
471 #define ZPOOL_CONFIG_ASIZE              "asize"
472 #define ZPOOL_CONFIG_DTL                "DTL"
473 #define ZPOOL_CONFIG_SCAN_STATS         "scan_stats"    /* not stored on disk */
474 #define ZPOOL_CONFIG_VDEV_STATS         "vdev_stats"    /* not stored on disk */
475 #define ZPOOL_CONFIG_WHOLE_DISK         "whole_disk"
476 #define ZPOOL_CONFIG_ERRCOUNT           "error_count"
477 #define ZPOOL_CONFIG_NOT_PRESENT        "not_present"
478 #define ZPOOL_CONFIG_SPARES             "spares"
479 #define ZPOOL_CONFIG_IS_SPARE           "is_spare"
480 #define ZPOOL_CONFIG_NPARITY            "nparity"
481 #define ZPOOL_CONFIG_HOSTID             "hostid"
482 #define ZPOOL_CONFIG_HOSTNAME           "hostname"
483 #define ZPOOL_CONFIG_LOADED_TIME        "initial_load_time"
484 #define ZPOOL_CONFIG_UNSPARE            "unspare"
485 #define ZPOOL_CONFIG_PHYS_PATH          "phys_path"
486 #define ZPOOL_CONFIG_IS_LOG             "is_log"
487 #define ZPOOL_CONFIG_L2CACHE            "l2cache"
488 #define ZPOOL_CONFIG_HOLE_ARRAY         "hole_array"
489 #define ZPOOL_CONFIG_VDEV_CHILDREN      "vdev_children"
490 #define ZPOOL_CONFIG_IS_HOLE            "is_hole"
491 #define ZPOOL_CONFIG_DDT_HISTOGRAM      "ddt_histogram"
492 #define ZPOOL_CONFIG_DDT_OBJ_STATS      "ddt_object_stats"
493 #define ZPOOL_CONFIG_DDT_STATS          "ddt_stats"
494 #define ZPOOL_CONFIG_SPLIT              "splitcfg"
495 #define ZPOOL_CONFIG_ORIG_GUID          "orig_guid"
496 #define ZPOOL_CONFIG_SPLIT_GUID         "split_guid"
497 #define ZPOOL_CONFIG_SPLIT_LIST         "guid_list"
498 #define ZPOOL_CONFIG_REMOVING           "removing"
499 #define ZPOOL_CONFIG_RESILVERING        "resilvering"
500 #define ZPOOL_CONFIG_SUSPENDED          "suspended"     /* not stored on disk */
501 #define ZPOOL_CONFIG_TIMESTAMP          "timestamp"     /* not stored on disk */
502 #define ZPOOL_CONFIG_BOOTFS             "bootfs"        /* not stored on disk */
503 #define ZPOOL_CONFIG_MISSING_DEVICES    "missing_vdevs" /* not stored on disk */
504 #define ZPOOL_CONFIG_LOAD_INFO          "load_info"     /* not stored on disk */
505 /*
506  * The persistent vdev state is stored as separate values rather than a single
507  * 'vdev_state' entry.  This is because a device can be in multiple states, such
508  * as offline and degraded.
509  */
510 #define ZPOOL_CONFIG_OFFLINE            "offline"
511 #define ZPOOL_CONFIG_FAULTED            "faulted"
512 #define ZPOOL_CONFIG_DEGRADED           "degraded"
513 #define ZPOOL_CONFIG_REMOVED            "removed"
514 #define ZPOOL_CONFIG_FRU                "fru"
515 #define ZPOOL_CONFIG_AUX_STATE          "aux_state"
516
517 /* Rewind policy parameters */
518 #define ZPOOL_REWIND_POLICY             "rewind-policy"
519 #define ZPOOL_REWIND_REQUEST            "rewind-request"
520 #define ZPOOL_REWIND_REQUEST_TXG        "rewind-request-txg"
521 #define ZPOOL_REWIND_META_THRESH        "rewind-meta-thresh"
522 #define ZPOOL_REWIND_DATA_THRESH        "rewind-data-thresh"
523
524 /* Rewind data discovered */
525 #define ZPOOL_CONFIG_LOAD_TIME          "rewind_txg_ts"
526 #define ZPOOL_CONFIG_LOAD_DATA_ERRORS   "verify_data_errors"
527 #define ZPOOL_CONFIG_REWIND_TIME        "seconds_of_rewind"
528
529 #define VDEV_TYPE_ROOT                  "root"
530 #define VDEV_TYPE_MIRROR                "mirror"
531 #define VDEV_TYPE_REPLACING             "replacing"
532 #define VDEV_TYPE_RAIDZ                 "raidz"
533 #define VDEV_TYPE_DISK                  "disk"
534 #define VDEV_TYPE_FILE                  "file"
535 #define VDEV_TYPE_MISSING               "missing"
536 #define VDEV_TYPE_HOLE                  "hole"
537 #define VDEV_TYPE_SPARE                 "spare"
538 #define VDEV_TYPE_LOG                   "log"
539 #define VDEV_TYPE_L2CACHE               "l2cache"
540
541 /*
542  * This is needed in userland to report the minimum necessary device size.
543  */
544 #define SPA_MINDEVSIZE          (64ULL << 20)
545
546 /*
547  * The location of the pool configuration repository, shared between kernel and
548  * userland.
549  */
550 #define ZPOOL_CACHE             "/etc/zfs/zpool.cache"
551
552 /*
553  * vdev states are ordered from least to most healthy.
554  * A vdev that's CANT_OPEN or below is considered unusable.
555  */
556 typedef enum vdev_state {
557         VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev                   */
558         VDEV_STATE_CLOSED,      /* Not currently open                   */
559         VDEV_STATE_OFFLINE,     /* Not allowed to open                  */
560         VDEV_STATE_REMOVED,     /* Explicitly removed from system       */
561         VDEV_STATE_CANT_OPEN,   /* Tried to open, but failed            */
562         VDEV_STATE_FAULTED,     /* External request to fault device     */
563         VDEV_STATE_DEGRADED,    /* Replicated vdev with unhealthy kids  */
564         VDEV_STATE_HEALTHY      /* Presumed good                        */
565 } vdev_state_t;
566
567 #define VDEV_STATE_ONLINE       VDEV_STATE_HEALTHY
568
569 /*
570  * vdev aux states.  When a vdev is in the CANT_OPEN state, the aux field
571  * of the vdev stats structure uses these constants to distinguish why.
572  */
573 typedef enum vdev_aux {
574         VDEV_AUX_NONE,          /* no error                             */
575         VDEV_AUX_OPEN_FAILED,   /* ldi_open_*() or vn_open() failed     */
576         VDEV_AUX_CORRUPT_DATA,  /* bad label or disk contents           */
577         VDEV_AUX_NO_REPLICAS,   /* insufficient number of replicas      */
578         VDEV_AUX_BAD_GUID_SUM,  /* vdev guid sum doesn't match          */
579         VDEV_AUX_TOO_SMALL,     /* vdev size is too small               */
580         VDEV_AUX_BAD_LABEL,     /* the label is OK but invalid          */
581         VDEV_AUX_VERSION_NEWER, /* on-disk version is too new           */
582         VDEV_AUX_VERSION_OLDER, /* on-disk version is too old           */
583         VDEV_AUX_SPARED,        /* hot spare used in another pool       */
584         VDEV_AUX_ERR_EXCEEDED,  /* too many errors                      */
585         VDEV_AUX_IO_FAILURE,    /* experienced I/O failure              */
586         VDEV_AUX_BAD_LOG,       /* cannot read log chain(s)             */
587         VDEV_AUX_EXTERNAL,      /* external diagnosis                   */
588         VDEV_AUX_SPLIT_POOL     /* vdev was split off into another pool */
589 } vdev_aux_t;
590
591 /*
592  * pool state.  The following states are written to disk as part of the normal
593  * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE.  The remaining
594  * states are software abstractions used at various levels to communicate
595  * pool state.
596  */
597 typedef enum pool_state {
598         POOL_STATE_ACTIVE = 0,          /* In active use                */
599         POOL_STATE_EXPORTED,            /* Explicitly exported          */
600         POOL_STATE_DESTROYED,           /* Explicitly destroyed         */
601         POOL_STATE_SPARE,               /* Reserved for hot spare use   */
602         POOL_STATE_L2CACHE,             /* Level 2 ARC device           */
603         POOL_STATE_UNINITIALIZED,       /* Internal spa_t state         */
604         POOL_STATE_UNAVAIL,             /* Internal libzfs state        */
605         POOL_STATE_POTENTIALLY_ACTIVE   /* Internal libzfs state        */
606 } pool_state_t;
607
608 /*
609  * Scan Functions.
610  */
611 typedef enum pool_scan_func {
612         POOL_SCAN_NONE,
613         POOL_SCAN_SCRUB,
614         POOL_SCAN_RESILVER,
615         POOL_SCAN_FUNCS
616 } pool_scan_func_t;
617
618 /*
619  * ZIO types.  Needed to interpret vdev statistics below.
620  */
621 typedef enum zio_type {
622         ZIO_TYPE_NULL = 0,
623         ZIO_TYPE_READ,
624         ZIO_TYPE_WRITE,
625         ZIO_TYPE_FREE,
626         ZIO_TYPE_CLAIM,
627         ZIO_TYPE_IOCTL,
628         ZIO_TYPES
629 } zio_type_t;
630
631 /*
632  * Pool statistics.  Note: all fields should be 64-bit because this
633  * is passed between kernel and userland as an nvlist uint64 array.
634  */
635 typedef struct pool_scan_stat {
636         /* values stored on disk */
637         uint64_t        pss_func;       /* pool_scan_func_t */
638         uint64_t        pss_state;      /* dsl_scan_state_t */
639         uint64_t        pss_start_time; /* scan start time */
640         uint64_t        pss_end_time;   /* scan end time */
641         uint64_t        pss_to_examine; /* total bytes to scan */
642         uint64_t        pss_examined;   /* total examined bytes */
643         uint64_t        pss_to_process; /* total bytes to process */
644         uint64_t        pss_processed;  /* total processed bytes */
645         uint64_t        pss_errors;     /* scan errors  */
646
647         /* values not stored on disk */
648         uint64_t        pss_pass_exam;  /* examined bytes per scan pass */
649         uint64_t        pss_pass_start; /* start time of a scan pass */
650 } pool_scan_stat_t;
651
652 typedef enum dsl_scan_state {
653         DSS_NONE,
654         DSS_SCANNING,
655         DSS_FINISHED,
656         DSS_CANCELED,
657         DSS_NUM_STATES
658 } dsl_scan_state_t;
659
660
661 /*
662  * Vdev statistics.  Note: all fields should be 64-bit because this
663  * is passed between kernel and userland as an nvlist uint64 array.
664  */
665 typedef struct vdev_stat {
666         hrtime_t        vs_timestamp;           /* time since vdev load */
667         uint64_t        vs_state;               /* vdev state           */
668         uint64_t        vs_aux;                 /* see vdev_aux_t       */
669         uint64_t        vs_alloc;               /* space allocated      */
670         uint64_t        vs_space;               /* total capacity       */
671         uint64_t        vs_dspace;              /* deflated capacity    */
672         uint64_t        vs_rsize;               /* replaceable dev size */
673         uint64_t        vs_ops[ZIO_TYPES];      /* operation count      */
674         uint64_t        vs_bytes[ZIO_TYPES];    /* bytes read/written   */
675         uint64_t        vs_read_errors;         /* read errors          */
676         uint64_t        vs_write_errors;        /* write errors         */
677         uint64_t        vs_checksum_errors;     /* checksum errors      */
678         uint64_t        vs_self_healed;         /* self-healed bytes    */
679         uint64_t        vs_scan_removing;       /* removing?    */
680         uint64_t        vs_scan_processed;      /* scan processed bytes */
681 } vdev_stat_t;
682
683 /*
684  * DDT statistics.  Note: all fields should be 64-bit because this
685  * is passed between kernel and userland as an nvlist uint64 array.
686  */
687 typedef struct ddt_object {
688         uint64_t        ddo_count;      /* number of elments in ddt     */
689         uint64_t        ddo_dspace;     /* size of ddt on disk          */
690         uint64_t        ddo_mspace;     /* size of ddt in-core          */
691 } ddt_object_t;
692
693 typedef struct ddt_stat {
694         uint64_t        dds_blocks;     /* blocks                       */
695         uint64_t        dds_lsize;      /* logical size                 */
696         uint64_t        dds_psize;      /* physical size                */
697         uint64_t        dds_dsize;      /* deflated allocated size      */
698         uint64_t        dds_ref_blocks; /* referenced blocks            */
699         uint64_t        dds_ref_lsize;  /* referenced lsize * refcnt    */
700         uint64_t        dds_ref_psize;  /* referenced psize * refcnt    */
701         uint64_t        dds_ref_dsize;  /* referenced dsize * refcnt    */
702 } ddt_stat_t;
703
704 typedef struct ddt_histogram {
705         ddt_stat_t      ddh_stat[64];   /* power-of-two histogram buckets */
706 } ddt_histogram_t;
707
708 #define ZVOL_DRIVER     "zvol"
709 #define ZFS_DRIVER      "zfs"
710 #define ZFS_DEV         "/dev/zfs"
711
712 /* general zvol path */
713 #define ZVOL_DIR        "/dev"
714
715 #define ZVOL_MAJOR              230
716 #define ZVOL_MINOR_BITS         4
717 #define ZVOL_MINOR_MASK         ((1U << ZVOL_MINOR_BITS) - 1)
718 #define ZVOL_MINORS             (1 << 4)
719 #define ZVOL_DEV_NAME           "zd"
720
721 #define ZVOL_PROP_NAME          "name"
722 #define ZVOL_DEFAULT_BLOCKSIZE  8192
723
724 /*
725  * /dev/zfs ioctl numbers.
726  */
727 #define ZFS_IOC         ('Z' << 8)
728
729 typedef enum zfs_ioc {
730         ZFS_IOC_POOL_CREATE = ZFS_IOC,
731         ZFS_IOC_POOL_DESTROY,
732         ZFS_IOC_POOL_IMPORT,
733         ZFS_IOC_POOL_EXPORT,
734         ZFS_IOC_POOL_CONFIGS,
735         ZFS_IOC_POOL_STATS,
736         ZFS_IOC_POOL_TRYIMPORT,
737         ZFS_IOC_POOL_SCAN,
738         ZFS_IOC_POOL_FREEZE,
739         ZFS_IOC_POOL_UPGRADE,
740         ZFS_IOC_POOL_GET_HISTORY,
741         ZFS_IOC_VDEV_ADD,
742         ZFS_IOC_VDEV_REMOVE,
743         ZFS_IOC_VDEV_SET_STATE,
744         ZFS_IOC_VDEV_ATTACH,
745         ZFS_IOC_VDEV_DETACH,
746         ZFS_IOC_VDEV_SETPATH,
747         ZFS_IOC_VDEV_SETFRU,
748         ZFS_IOC_OBJSET_STATS,
749         ZFS_IOC_OBJSET_ZPLPROPS,
750         ZFS_IOC_DATASET_LIST_NEXT,
751         ZFS_IOC_SNAPSHOT_LIST_NEXT,
752         ZFS_IOC_SET_PROP,
753         ZFS_IOC_CREATE_MINOR,
754         ZFS_IOC_REMOVE_MINOR,
755         ZFS_IOC_CREATE,
756         ZFS_IOC_DESTROY,
757         ZFS_IOC_ROLLBACK,
758         ZFS_IOC_RENAME,
759         ZFS_IOC_RECV,
760         ZFS_IOC_SEND,
761         ZFS_IOC_INJECT_FAULT,
762         ZFS_IOC_CLEAR_FAULT,
763         ZFS_IOC_INJECT_LIST_NEXT,
764         ZFS_IOC_ERROR_LOG,
765         ZFS_IOC_CLEAR,
766         ZFS_IOC_PROMOTE,
767         ZFS_IOC_DESTROY_SNAPS,
768         ZFS_IOC_SNAPSHOT,
769         ZFS_IOC_DSOBJ_TO_DSNAME,
770         ZFS_IOC_OBJ_TO_PATH,
771         ZFS_IOC_POOL_SET_PROPS,
772         ZFS_IOC_POOL_GET_PROPS,
773         ZFS_IOC_SET_FSACL,
774         ZFS_IOC_GET_FSACL,
775         ZFS_IOC_SHARE,
776         ZFS_IOC_INHERIT_PROP,
777         ZFS_IOC_SMB_ACL,
778         ZFS_IOC_USERSPACE_ONE,
779         ZFS_IOC_USERSPACE_MANY,
780         ZFS_IOC_USERSPACE_UPGRADE,
781         ZFS_IOC_HOLD,
782         ZFS_IOC_RELEASE,
783         ZFS_IOC_GET_HOLDS,
784         ZFS_IOC_OBJSET_RECVD_PROPS,
785         ZFS_IOC_VDEV_SPLIT,
786         ZFS_IOC_NEXT_OBJ,
787         ZFS_IOC_DIFF,
788         ZFS_IOC_TMP_SNAPSHOT,
789         ZFS_IOC_OBJ_TO_STATS,
790         ZFS_IOC_POOL_REGUID,
791         ZFS_IOC_EVENTS_NEXT,
792         ZFS_IOC_EVENTS_CLEAR,
793 } zfs_ioc_t;
794
795 /*
796  * zvol ioctl to get dataset name
797  */
798 #define BLKZNAME                _IOR(0x12,125,char[ZFS_MAXNAMELEN])
799
800 /*
801  * Internal SPA load state.  Used by FMA diagnosis engine.
802  */
803 typedef enum {
804         SPA_LOAD_NONE,          /* no load in progress  */
805         SPA_LOAD_OPEN,          /* normal open          */
806         SPA_LOAD_IMPORT,        /* import in progress   */
807         SPA_LOAD_TRYIMPORT,     /* tryimport in progress */
808         SPA_LOAD_RECOVER,       /* recovery requested   */
809         SPA_LOAD_ERROR          /* load failed          */
810 } spa_load_state_t;
811
812 /*
813  * Bookmark name values.
814  */
815 #define ZPOOL_ERR_LIST          "error list"
816 #define ZPOOL_ERR_DATASET       "dataset"
817 #define ZPOOL_ERR_OBJECT        "object"
818
819 #define HIS_MAX_RECORD_LEN      (MAXPATHLEN + MAXPATHLEN + 1)
820
821 /*
822  * The following are names used in the nvlist describing
823  * the pool's history log.
824  */
825 #define ZPOOL_HIST_RECORD       "history record"
826 #define ZPOOL_HIST_TIME         "history time"
827 #define ZPOOL_HIST_CMD          "history command"
828 #define ZPOOL_HIST_WHO          "history who"
829 #define ZPOOL_HIST_ZONE         "history zone"
830 #define ZPOOL_HIST_HOST         "history hostname"
831 #define ZPOOL_HIST_TXG          "history txg"
832 #define ZPOOL_HIST_INT_EVENT    "history internal event"
833 #define ZPOOL_HIST_INT_STR      "history internal str"
834
835 /*
836  * Flags for ZFS_IOC_VDEV_SET_STATE
837  */
838 #define ZFS_ONLINE_CHECKREMOVE  0x1
839 #define ZFS_ONLINE_UNSPARE      0x2
840 #define ZFS_ONLINE_FORCEFAULT   0x4
841 #define ZFS_ONLINE_EXPAND       0x8
842 #define ZFS_OFFLINE_TEMPORARY   0x1
843
844 /*
845  * Flags for ZFS_IOC_POOL_IMPORT
846  */
847 #define ZFS_IMPORT_NORMAL       0x0
848 #define ZFS_IMPORT_VERBATIM     0x1
849 #define ZFS_IMPORT_ANY_HOST     0x2
850 #define ZFS_IMPORT_MISSING_LOG  0x4
851 #define ZFS_IMPORT_ONLY         0x8
852
853 /*
854  * Sysevent payload members.  ZFS will generate the following sysevents with the
855  * given payloads:
856  *
857  *      ESC_ZFS_RESILVER_START
858  *      ESC_ZFS_RESILVER_END
859  *      ESC_ZFS_POOL_DESTROY
860  *      ESC_ZFS_POOL_REGUID
861  *
862  *              ZFS_EV_POOL_NAME        DATA_TYPE_STRING
863  *              ZFS_EV_POOL_GUID        DATA_TYPE_UINT64
864  *
865  *      ESC_ZFS_VDEV_REMOVE
866  *      ESC_ZFS_VDEV_CLEAR
867  *      ESC_ZFS_VDEV_CHECK
868  *
869  *              ZFS_EV_POOL_NAME        DATA_TYPE_STRING
870  *              ZFS_EV_POOL_GUID        DATA_TYPE_UINT64
871  *              ZFS_EV_VDEV_PATH        DATA_TYPE_STRING        (optional)
872  *              ZFS_EV_VDEV_GUID        DATA_TYPE_UINT64
873  */
874 #define ZFS_EV_POOL_NAME        "pool_name"
875 #define ZFS_EV_POOL_GUID        "pool_guid"
876 #define ZFS_EV_VDEV_PATH        "vdev_path"
877 #define ZFS_EV_VDEV_GUID        "vdev_guid"
878
879 /*
880  * Note: This is encoded on-disk, so new events must be added to the
881  * end, and unused events can not be removed.  Be sure to edit
882  * libzfs_pool.c: hist_event_table[].
883  */
884 typedef enum history_internal_events {
885         LOG_NO_EVENT = 0,
886         LOG_POOL_CREATE,
887         LOG_POOL_VDEV_ADD,
888         LOG_POOL_REMOVE,
889         LOG_POOL_DESTROY,
890         LOG_POOL_EXPORT,
891         LOG_POOL_IMPORT,
892         LOG_POOL_VDEV_ATTACH,
893         LOG_POOL_VDEV_REPLACE,
894         LOG_POOL_VDEV_DETACH,
895         LOG_POOL_VDEV_ONLINE,
896         LOG_POOL_VDEV_OFFLINE,
897         LOG_POOL_UPGRADE,
898         LOG_POOL_CLEAR,
899         LOG_POOL_SCAN,
900         LOG_POOL_PROPSET,
901         LOG_DS_CREATE,
902         LOG_DS_CLONE,
903         LOG_DS_DESTROY,
904         LOG_DS_DESTROY_BEGIN,
905         LOG_DS_INHERIT,
906         LOG_DS_PROPSET,
907         LOG_DS_QUOTA,
908         LOG_DS_PERM_UPDATE,
909         LOG_DS_PERM_REMOVE,
910         LOG_DS_PERM_WHO_REMOVE,
911         LOG_DS_PROMOTE,
912         LOG_DS_RECEIVE,
913         LOG_DS_RENAME,
914         LOG_DS_RESERVATION,
915         LOG_DS_REPLAY_INC_SYNC,
916         LOG_DS_REPLAY_FULL_SYNC,
917         LOG_DS_ROLLBACK,
918         LOG_DS_SNAPSHOT,
919         LOG_DS_UPGRADE,
920         LOG_DS_REFQUOTA,
921         LOG_DS_REFRESERV,
922         LOG_POOL_SCAN_DONE,
923         LOG_DS_USER_HOLD,
924         LOG_DS_USER_RELEASE,
925         LOG_POOL_SPLIT,
926         LOG_END
927 } history_internal_events_t;
928
929 #ifdef  __cplusplus
930 }
931 #endif
932
933 #endif  /* _SYS_FS_ZFS_H */