]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/cddl/contrib/opensolaris/uts/common/sys/fs/zfs.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25
26 #ifndef _SYS_FS_ZFS_H
27 #define _SYS_FS_ZFS_H
28
29 #pragma ident   "%Z%%M% %I%     %E% SMI"
30
31 #include <sys/types.h>
32 #include <sys/ioccom.h>
33
34 #ifdef  __cplusplus
35 extern "C" {
36 #endif
37
38 /*
39  * Types and constants shared between userland and the kernel.
40  */
41
42 /*
43  * Each dataset can be one of the following types.  These constants can be
44  * combined into masks that can be passed to various functions.
45  */
46 typedef enum {
47         ZFS_TYPE_FILESYSTEM     = 0x1,
48         ZFS_TYPE_SNAPSHOT       = 0x2,
49         ZFS_TYPE_VOLUME         = 0x4,
50         ZFS_TYPE_POOL           = 0x8
51 } zfs_type_t;
52
53 #define ZFS_TYPE_ANY    \
54         (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME | ZFS_TYPE_SNAPSHOT)
55
56 /*
57  * Properties are identified by these constants and must be added to the
58  * end of this list to ensure that external conumsers are not affected
59  * by the change. The property list also determines how 'zfs get' will
60  * display them.  If you make any changes to this list, be sure to update
61  * the property table in usr/src/common/zfs/zfs_prop.c.
62  */
63 typedef enum {
64         ZFS_PROP_CONT = -2,
65         ZFS_PROP_INVAL = -1,
66         ZFS_PROP_TYPE,
67         ZFS_PROP_CREATION,
68         ZFS_PROP_USED,
69         ZFS_PROP_AVAILABLE,
70         ZFS_PROP_REFERENCED,
71         ZFS_PROP_COMPRESSRATIO,
72         ZFS_PROP_MOUNTED,
73         ZFS_PROP_ORIGIN,
74         ZFS_PROP_QUOTA,
75         ZFS_PROP_RESERVATION,
76         ZFS_PROP_VOLSIZE,
77         ZFS_PROP_VOLBLOCKSIZE,
78         ZFS_PROP_RECORDSIZE,
79         ZFS_PROP_MOUNTPOINT,
80         ZFS_PROP_SHARENFS,
81         ZFS_PROP_CHECKSUM,
82         ZFS_PROP_COMPRESSION,
83         ZFS_PROP_ATIME,
84         ZFS_PROP_DEVICES,
85         ZFS_PROP_EXEC,
86         ZFS_PROP_SETUID,
87         ZFS_PROP_READONLY,
88         ZFS_PROP_ZONED,
89         ZFS_PROP_SNAPDIR,
90         ZFS_PROP_ACLMODE,
91         ZFS_PROP_ACLINHERIT,
92         ZFS_PROP_CREATETXG,             /* not exposed to the user */
93         ZFS_PROP_NAME,                  /* not exposed to the user */
94         ZFS_PROP_CANMOUNT,
95         ZFS_PROP_SHAREISCSI,
96         ZFS_PROP_ISCSIOPTIONS,          /* not exposed to the user */
97         ZFS_PROP_XATTR,
98         ZFS_PROP_NUMCLONES,             /* not exposed to the user */
99         ZFS_PROP_COPIES,
100         ZFS_PROP_BOOTFS
101 } zfs_prop_t;
102
103 typedef zfs_prop_t zpool_prop_t;
104
105 #define ZFS_PROP_VALUE          "value"
106 #define ZFS_PROP_SOURCE         "source"
107
108 typedef enum {
109         ZFS_SRC_NONE = 0x1,
110         ZFS_SRC_DEFAULT = 0x2,
111         ZFS_SRC_TEMPORARY = 0x4,
112         ZFS_SRC_LOCAL = 0x8,
113         ZFS_SRC_INHERITED = 0x10
114 } zfs_source_t;
115
116 #define ZFS_SRC_ALL     0x1f
117
118 /*
119  * The following functions are shared between libzfs and the kernel.
120  */
121 zfs_prop_t zfs_name_to_prop(const char *);
122 zpool_prop_t zpool_name_to_prop(const char *);
123 boolean_t zfs_prop_user(const char *);
124 int zfs_prop_readonly(zfs_prop_t);
125 const char *zfs_prop_default_string(zfs_prop_t);
126 const char *zfs_prop_to_name(zfs_prop_t);
127 const char *zpool_prop_to_name(zfs_prop_t);
128 uint64_t zfs_prop_default_numeric(zfs_prop_t);
129 int zfs_prop_inheritable(zfs_prop_t);
130 int zfs_prop_string_to_index(zfs_prop_t, const char *, uint64_t *);
131 int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
132
133 /*
134  * Property Iterator
135  */
136 typedef zfs_prop_t (*zfs_prop_f)(zfs_prop_t, void *);
137 typedef zfs_prop_f zpool_prop_f;
138 extern zfs_prop_t zfs_prop_iter(zfs_prop_f, void *, boolean_t);
139 extern zpool_prop_t zpool_prop_iter(zpool_prop_f, void *, boolean_t);
140
141 /*
142  * On-disk version number.
143  */
144 #define ZFS_VERSION_1                   1ULL
145 #define ZFS_VERSION_2                   2ULL
146 #define ZFS_VERSION_3                   3ULL
147 #define ZFS_VERSION_4                   4ULL
148 #define ZFS_VERSION_5                   5ULL
149 #define ZFS_VERSION_6                   6ULL
150 /*
151  * When bumping up ZFS_VERSION, make sure GRUB ZFS understand the on-disk
152  * format change. Go to usr/src/grub/grub-0.95/stage2/{zfs-include/, fsys_zfs*},
153  * and do the appropriate changes.
154  */
155 #define ZFS_VERSION                     ZFS_VERSION_6
156 #define ZFS_VERSION_STRING              "6"
157
158 /*
159  * Symbolic names for the changes that caused a ZFS_VERSION switch.
160  * Used in the code when checking for presence or absence of a feature.
161  * Feel free to define multiple symbolic names for each version if there
162  * were multiple changes to on-disk structures during that version.
163  *
164  * NOTE: When checking the current ZFS_VERSION in your code, be sure
165  *       to use spa_version() since it reports the version of the
166  *       last synced uberblock.  Checking the in-flight version can
167  *       be dangerous in some cases.
168  */
169 #define ZFS_VERSION_INITIAL             ZFS_VERSION_1
170 #define ZFS_VERSION_DITTO_BLOCKS        ZFS_VERSION_2
171 #define ZFS_VERSION_SPARES              ZFS_VERSION_3
172 #define ZFS_VERSION_RAID6               ZFS_VERSION_3
173 #define ZFS_VERSION_BPLIST_ACCOUNT      ZFS_VERSION_3
174 #define ZFS_VERSION_RAIDZ_DEFLATE       ZFS_VERSION_3
175 #define ZFS_VERSION_DNODE_BYTES         ZFS_VERSION_3
176 #define ZFS_VERSION_ZPOOL_HISTORY       ZFS_VERSION_4
177 #define ZFS_VERSION_GZIP_COMPRESSION    ZFS_VERSION_5
178 #define ZFS_VERSION_BOOTFS              ZFS_VERSION_6
179
180 /*
181  * The following are configuration names used in the nvlist describing a pool's
182  * configuration.
183  */
184 #define ZPOOL_CONFIG_VERSION            "version"
185 #define ZPOOL_CONFIG_POOL_NAME          "name"
186 #define ZPOOL_CONFIG_POOL_STATE         "state"
187 #define ZPOOL_CONFIG_POOL_TXG           "txg"
188 #define ZPOOL_CONFIG_POOL_GUID          "pool_guid"
189 #define ZPOOL_CONFIG_CREATE_TXG         "create_txg"
190 #define ZPOOL_CONFIG_TOP_GUID           "top_guid"
191 #define ZPOOL_CONFIG_VDEV_TREE          "vdev_tree"
192 #define ZPOOL_CONFIG_TYPE               "type"
193 #define ZPOOL_CONFIG_CHILDREN           "children"
194 #define ZPOOL_CONFIG_ID                 "id"
195 #define ZPOOL_CONFIG_GUID               "guid"
196 #define ZPOOL_CONFIG_PATH               "path"
197 #define ZPOOL_CONFIG_DEVID              "devid"
198 #define ZPOOL_CONFIG_METASLAB_ARRAY     "metaslab_array"
199 #define ZPOOL_CONFIG_METASLAB_SHIFT     "metaslab_shift"
200 #define ZPOOL_CONFIG_ASHIFT             "ashift"
201 #define ZPOOL_CONFIG_ASIZE              "asize"
202 #define ZPOOL_CONFIG_DTL                "DTL"
203 #define ZPOOL_CONFIG_STATS              "stats"
204 #define ZPOOL_CONFIG_WHOLE_DISK         "whole_disk"
205 #define ZPOOL_CONFIG_OFFLINE            "offline"
206 #define ZPOOL_CONFIG_ERRCOUNT           "error_count"
207 #define ZPOOL_CONFIG_NOT_PRESENT        "not_present"
208 #define ZPOOL_CONFIG_SPARES             "spares"
209 #define ZPOOL_CONFIG_IS_SPARE           "is_spare"
210 #define ZPOOL_CONFIG_NPARITY            "nparity"
211 #define ZPOOL_CONFIG_HOSTID             "hostid"
212 #define ZPOOL_CONFIG_HOSTNAME           "hostname"
213 #define ZPOOL_CONFIG_TIMESTAMP          "timestamp" /* not stored on disk */
214
215 #define VDEV_TYPE_ROOT                  "root"
216 #define VDEV_TYPE_MIRROR                "mirror"
217 #define VDEV_TYPE_REPLACING             "replacing"
218 #define VDEV_TYPE_RAIDZ                 "raidz"
219 #define VDEV_TYPE_DISK                  "disk"
220 #define VDEV_TYPE_FILE                  "file"
221 #define VDEV_TYPE_MISSING               "missing"
222 #define VDEV_TYPE_SPARE                 "spare"
223
224 /*
225  * This is needed in userland to report the minimum necessary device size.
226  */
227 #define SPA_MINDEVSIZE          (64ULL << 20)
228
229 /*
230  * The location of the pool configuration repository, shared between kernel and
231  * userland.
232  */
233 #define ZPOOL_CACHE_DIR         "/boot/zfs"
234 #define ZPOOL_CACHE_FILE        "zpool.cache"
235 #define ZPOOL_CACHE_TMP         ".zpool.cache"
236
237 #define ZPOOL_CACHE             ZPOOL_CACHE_DIR "/" ZPOOL_CACHE_FILE
238
239 /*
240  * vdev states are ordered from least to most healthy.
241  * A vdev that's CANT_OPEN or below is considered unusable.
242  */
243 typedef enum vdev_state {
244         VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev                   */
245         VDEV_STATE_CLOSED,      /* Not currently open                   */
246         VDEV_STATE_OFFLINE,     /* Not allowed to open                  */
247         VDEV_STATE_CANT_OPEN,   /* Tried to open, but failed            */
248         VDEV_STATE_DEGRADED,    /* Replicated vdev with unhealthy kids  */
249         VDEV_STATE_HEALTHY      /* Presumed good                        */
250 } vdev_state_t;
251
252 /*
253  * vdev aux states.  When a vdev is in the CANT_OPEN state, the aux field
254  * of the vdev stats structure uses these constants to distinguish why.
255  */
256 typedef enum vdev_aux {
257         VDEV_AUX_NONE,          /* no error                             */
258         VDEV_AUX_OPEN_FAILED,   /* ldi_open_*() or vn_open() failed     */
259         VDEV_AUX_CORRUPT_DATA,  /* bad label or disk contents           */
260         VDEV_AUX_NO_REPLICAS,   /* insufficient number of replicas      */
261         VDEV_AUX_BAD_GUID_SUM,  /* vdev guid sum doesn't match          */
262         VDEV_AUX_TOO_SMALL,     /* vdev size is too small               */
263         VDEV_AUX_BAD_LABEL,     /* the label is OK but invalid          */
264         VDEV_AUX_VERSION_NEWER, /* on-disk version is too new           */
265         VDEV_AUX_VERSION_OLDER, /* on-disk version is too old           */
266         VDEV_AUX_SPARED         /* hot spare used in another pool       */
267 } vdev_aux_t;
268
269 /*
270  * pool state.  The following states are written to disk as part of the normal
271  * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE.  The remaining states are
272  * software abstractions used at various levels to communicate pool state.
273  */
274 typedef enum pool_state {
275         POOL_STATE_ACTIVE = 0,          /* In active use                */
276         POOL_STATE_EXPORTED,            /* Explicitly exported          */
277         POOL_STATE_DESTROYED,           /* Explicitly destroyed         */
278         POOL_STATE_SPARE,               /* Reserved for hot spare use   */
279         POOL_STATE_UNINITIALIZED,       /* Internal spa_t state         */
280         POOL_STATE_UNAVAIL,             /* Internal libzfs state        */
281         POOL_STATE_POTENTIALLY_ACTIVE   /* Internal libzfs state        */
282 } pool_state_t;
283
284 /*
285  * Scrub types.
286  */
287 typedef enum pool_scrub_type {
288         POOL_SCRUB_NONE,
289         POOL_SCRUB_RESILVER,
290         POOL_SCRUB_EVERYTHING,
291         POOL_SCRUB_TYPES
292 } pool_scrub_type_t;
293
294 /*
295  * ZIO types.  Needed to interpret vdev statistics below.
296  */
297 typedef enum zio_type {
298         ZIO_TYPE_NULL = 0,
299         ZIO_TYPE_READ,
300         ZIO_TYPE_WRITE,
301         ZIO_TYPE_FREE,
302         ZIO_TYPE_CLAIM,
303         ZIO_TYPE_IOCTL,
304         ZIO_TYPES
305 } zio_type_t;
306
307 /*
308  * Vdev statistics.  Note: all fields should be 64-bit because this
309  * is passed between kernel and userland as an nvlist uint64 array.
310  */
311 typedef struct vdev_stat {
312         hrtime_t        vs_timestamp;           /* time since vdev load */
313         uint64_t        vs_state;               /* vdev state           */
314         uint64_t        vs_aux;                 /* see vdev_aux_t       */
315         uint64_t        vs_alloc;               /* space allocated      */
316         uint64_t        vs_space;               /* total capacity       */
317         uint64_t        vs_dspace;              /* deflated capacity    */
318         uint64_t        vs_rsize;               /* replaceable dev size */
319         uint64_t        vs_ops[ZIO_TYPES];      /* operation count      */
320         uint64_t        vs_bytes[ZIO_TYPES];    /* bytes read/written   */
321         uint64_t        vs_read_errors;         /* read errors          */
322         uint64_t        vs_write_errors;        /* write errors         */
323         uint64_t        vs_checksum_errors;     /* checksum errors      */
324         uint64_t        vs_self_healed;         /* self-healed bytes    */
325         uint64_t        vs_scrub_type;          /* pool_scrub_type_t    */
326         uint64_t        vs_scrub_complete;      /* completed?           */
327         uint64_t        vs_scrub_examined;      /* bytes examined; top  */
328         uint64_t        vs_scrub_repaired;      /* bytes repaired; leaf */
329         uint64_t        vs_scrub_errors;        /* errors during scrub  */
330         uint64_t        vs_scrub_start;         /* UTC scrub start time */
331         uint64_t        vs_scrub_end;           /* UTC scrub end time   */
332 } vdev_stat_t;
333
334 #define ZFS_DRIVER      "zfs"
335 #define ZFS_DEV_NAME    "zfs"
336 #define ZFS_DEV         "/dev/" ZFS_DEV_NAME
337
338 /*
339  * zvol paths.  Irritatingly, the devfsadm interfaces want all these
340  * paths without the /dev prefix, but for some things, we want the
341  * /dev prefix.  Below are the names without /dev.
342  */
343 #define ZVOL_DEV_DIR    "zvol"
344
345 /*
346  * And here are the things we need with /dev, etc. in front of them.
347  */
348 #define ZVOL_PSEUDO_DEV         "/devices/pseudo/zvol@0:"
349 #define ZVOL_FULL_DEV_DIR       "/dev/" ZVOL_DEV_DIR
350
351 #define ZVOL_PROP_NAME          "name"
352
353 /*
354  * /dev/zfs ioctl numbers.
355  */
356 typedef unsigned long   zfs_ioc_t;
357
358 #define ZFS_IOC(ioreq)  ((ioreq) & 0xff)
359
360 #define ZFS_IOC_POOL_CREATE             _IOWR('Z', 0, struct zfs_cmd)
361 #define ZFS_IOC_POOL_DESTROY            _IOWR('Z', 1, struct zfs_cmd)
362 #define ZFS_IOC_POOL_IMPORT             _IOWR('Z', 2, struct zfs_cmd)
363 #define ZFS_IOC_POOL_EXPORT             _IOWR('Z', 3, struct zfs_cmd)
364 #define ZFS_IOC_POOL_CONFIGS            _IOWR('Z', 4, struct zfs_cmd)
365 #define ZFS_IOC_POOL_STATS              _IOWR('Z', 5, struct zfs_cmd)
366 #define ZFS_IOC_POOL_TRYIMPORT          _IOWR('Z', 6, struct zfs_cmd)
367 #define ZFS_IOC_POOL_SCRUB              _IOWR('Z', 7, struct zfs_cmd)
368 #define ZFS_IOC_POOL_FREEZE             _IOWR('Z', 8, struct zfs_cmd)
369 #define ZFS_IOC_POOL_UPGRADE            _IOWR('Z', 9, struct zfs_cmd)
370 #define ZFS_IOC_POOL_GET_HISTORY        _IOWR('Z', 10, struct zfs_cmd)
371 #define ZFS_IOC_POOL_LOG_HISTORY        _IOWR('Z', 11, struct zfs_cmd)
372 #define ZFS_IOC_VDEV_ADD                _IOWR('Z', 12, struct zfs_cmd)
373 #define ZFS_IOC_VDEV_REMOVE             _IOWR('Z', 13, struct zfs_cmd)
374 #define ZFS_IOC_VDEV_ONLINE             _IOWR('Z', 14, struct zfs_cmd)
375 #define ZFS_IOC_VDEV_OFFLINE            _IOWR('Z', 15, struct zfs_cmd)
376 #define ZFS_IOC_VDEV_ATTACH             _IOWR('Z', 16, struct zfs_cmd)
377 #define ZFS_IOC_VDEV_DETACH             _IOWR('Z', 17, struct zfs_cmd)
378 #define ZFS_IOC_VDEV_SETPATH            _IOWR('Z', 18, struct zfs_cmd)
379 #define ZFS_IOC_OBJSET_STATS            _IOWR('Z', 19, struct zfs_cmd)
380 #define ZFS_IOC_DATASET_LIST_NEXT       _IOWR('Z', 20, struct zfs_cmd)
381 #define ZFS_IOC_SNAPSHOT_LIST_NEXT      _IOWR('Z', 21, struct zfs_cmd)
382 #define ZFS_IOC_SET_PROP                _IOWR('Z', 22, struct zfs_cmd)
383 #define ZFS_IOC_CREATE_MINOR            _IOWR('Z', 23, struct zfs_cmd)
384 #define ZFS_IOC_REMOVE_MINOR            _IOWR('Z', 24, struct zfs_cmd)
385 #define ZFS_IOC_CREATE                  _IOWR('Z', 25, struct zfs_cmd)
386 #define ZFS_IOC_DESTROY                 _IOWR('Z', 26, struct zfs_cmd)
387 #define ZFS_IOC_ROLLBACK                _IOWR('Z', 27, struct zfs_cmd)
388 #define ZFS_IOC_RENAME                  _IOWR('Z', 28, struct zfs_cmd)
389 #define ZFS_IOC_RECVBACKUP              _IOWR('Z', 29, struct zfs_cmd)
390 #define ZFS_IOC_SENDBACKUP              _IOWR('Z', 30, struct zfs_cmd)
391 #define ZFS_IOC_INJECT_FAULT            _IOWR('Z', 31, struct zfs_cmd)
392 #define ZFS_IOC_CLEAR_FAULT             _IOWR('Z', 32, struct zfs_cmd)
393 #define ZFS_IOC_INJECT_LIST_NEXT        _IOWR('Z', 33, struct zfs_cmd)
394 #define ZFS_IOC_ERROR_LOG               _IOWR('Z', 34, struct zfs_cmd)
395 #define ZFS_IOC_CLEAR                   _IOWR('Z', 35, struct zfs_cmd)
396 #define ZFS_IOC_PROMOTE                 _IOWR('Z', 36, struct zfs_cmd)
397 #define ZFS_IOC_DESTROY_SNAPS           _IOWR('Z', 37, struct zfs_cmd)
398 #define ZFS_IOC_SNAPSHOT                _IOWR('Z', 38, struct zfs_cmd)
399 #define ZFS_IOC_DSOBJ_TO_DSNAME         _IOWR('Z', 39, struct zfs_cmd)
400 #define ZFS_IOC_OBJ_TO_PATH             _IOWR('Z', 40, struct zfs_cmd)
401 #define ZFS_IOC_POOL_SET_PROPS          _IOWR('Z', 41, struct zfs_cmd)
402 #define ZFS_IOC_POOL_GET_PROPS          _IOWR('Z', 42, struct zfs_cmd)
403 #define ZFS_IOC_JAIL                    _IOWR('Z', 43, struct zfs_cmd)
404 #define ZFS_IOC_UNJAIL                  _IOWR('Z', 44, struct zfs_cmd)
405
406 /*
407  * Internal SPA load state.  Used by FMA diagnosis engine.
408  */
409 typedef enum {
410         SPA_LOAD_NONE,          /* no load in progress */
411         SPA_LOAD_OPEN,          /* normal open */
412         SPA_LOAD_IMPORT,        /* import in progress */
413         SPA_LOAD_TRYIMPORT      /* tryimport in progress */
414 } spa_load_state_t;
415
416 /*
417  * Bookmark name values.
418  */
419 #define ZPOOL_ERR_LIST          "error list"
420 #define ZPOOL_ERR_DATASET       "dataset"
421 #define ZPOOL_ERR_OBJECT        "object"
422
423 #define HIS_MAX_RECORD_LEN      (MAXPATHLEN + MAXPATHLEN + 1)
424
425 /*
426  * The following are names used in the nvlist describing
427  * the pool's history log.
428  */
429 #define ZPOOL_HIST_RECORD       "history record"
430 #define ZPOOL_HIST_TIME         "history time"
431 #define ZPOOL_HIST_CMD          "history command"
432
433 #ifdef  __cplusplus
434 }
435 #endif
436
437 #endif  /* _SYS_FS_ZFS_H */