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