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 #define ZFS_VERSION_7 7ULL 156 /* 157 * When bumping up ZFS_VERSION, make sure GRUB ZFS understand the on-disk 158 * format change. Go to usr/src/grub/grub-0.95/stage2/{zfs-include/, fsys_zfs*}, 159 * and do the appropriate changes. 160 */ 161 #define ZFS_VERSION ZFS_VERSION_7 162 #define ZFS_VERSION_STRING "7" 163 164 /* 165 * Symbolic names for the changes that caused a ZFS_VERSION switch. 166 * Used in the code when checking for presence or absence of a feature. 167 * Feel free to define multiple symbolic names for each version if there 168 * were multiple changes to on-disk structures during that version. 169 * 170 * NOTE: When checking the current ZFS_VERSION in your code, be sure 171 * to use spa_version() since it reports the version of the 172 * last synced uberblock. Checking the in-flight version can 173 * be dangerous in some cases. 174 */ 175 #define ZFS_VERSION_INITIAL ZFS_VERSION_1 176 #define ZFS_VERSION_DITTO_BLOCKS ZFS_VERSION_2 177 #define ZFS_VERSION_SPARES ZFS_VERSION_3 178 #define ZFS_VERSION_RAID6 ZFS_VERSION_3 179 #define ZFS_VERSION_BPLIST_ACCOUNT ZFS_VERSION_3 180 #define ZFS_VERSION_RAIDZ_DEFLATE ZFS_VERSION_3 181 #define ZFS_VERSION_DNODE_BYTES ZFS_VERSION_3 182 #define ZFS_VERSION_ZPOOL_HISTORY ZFS_VERSION_4 183 #define ZFS_VERSION_GZIP_COMPRESSION ZFS_VERSION_5 184 #define ZFS_VERSION_BOOTFS ZFS_VERSION_6 185 #define ZFS_VERSION_SLOGS ZFS_VERSION_7 186 187 /* 188 * The following are configuration names used in the nvlist describing a pool's 189 * configuration. 190 */ 191 #define ZPOOL_CONFIG_VERSION "version" 192 #define ZPOOL_CONFIG_POOL_NAME "name" 193 #define ZPOOL_CONFIG_POOL_STATE "state" 194 #define ZPOOL_CONFIG_POOL_TXG "txg" 195 #define ZPOOL_CONFIG_POOL_GUID "pool_guid" 196 #define ZPOOL_CONFIG_CREATE_TXG "create_txg" 197 #define ZPOOL_CONFIG_TOP_GUID "top_guid" 198 #define ZPOOL_CONFIG_VDEV_TREE "vdev_tree" 199 #define ZPOOL_CONFIG_TYPE "type" 200 #define ZPOOL_CONFIG_CHILDREN "children" 201 #define ZPOOL_CONFIG_ID "id" 202 #define ZPOOL_CONFIG_GUID "guid" 203 #define ZPOOL_CONFIG_PATH "path" 204 #define ZPOOL_CONFIG_DEVID "devid" 205 #define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array" 206 #define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift" 207 #define ZPOOL_CONFIG_ASHIFT "ashift" 208 #define ZPOOL_CONFIG_ASIZE "asize" 209 #define ZPOOL_CONFIG_DTL "DTL" 210 #define ZPOOL_CONFIG_STATS "stats" 211 #define ZPOOL_CONFIG_WHOLE_DISK "whole_disk" 212 #define ZPOOL_CONFIG_ERRCOUNT "error_count" 213 #define ZPOOL_CONFIG_NOT_PRESENT "not_present" 214 #define ZPOOL_CONFIG_SPARES "spares" 215 #define ZPOOL_CONFIG_IS_SPARE "is_spare" 216 #define ZPOOL_CONFIG_NPARITY "nparity" 217 #define ZPOOL_CONFIG_HOSTID "hostid" 218 #define ZPOOL_CONFIG_HOSTNAME "hostname" 219 #define ZPOOL_CONFIG_TIMESTAMP "timestamp" /* not stored on disk */ 220 #define ZPOOL_CONFIG_UNSPARE "unspare" 221 #define ZPOOL_CONFIG_PHYS_PATH "phys_path" 222 #define ZPOOL_CONFIG_IS_LOG "is_log" 223 /* 224 * The persistent vdev state is stored as separate values rather than a single 225 * 'vdev_state' entry. This is because a device can be in multiple states, such 226 * as offline and degraded. 227 */ 228 #define ZPOOL_CONFIG_OFFLINE "offline" 229 #define ZPOOL_CONFIG_FAULTED "faulted" 230 #define ZPOOL_CONFIG_DEGRADED "degraded" 231 #define ZPOOL_CONFIG_REMOVED "removed" 232 233 #define VDEV_TYPE_ROOT "root" 234 #define VDEV_TYPE_MIRROR "mirror" 235 #define VDEV_TYPE_REPLACING "replacing" 236 #define VDEV_TYPE_RAIDZ "raidz" 237 #define VDEV_TYPE_DISK "disk" 238 #define VDEV_TYPE_FILE "file" 239 #define VDEV_TYPE_MISSING "missing" 240 #define VDEV_TYPE_SPARE "spare" 241 #define VDEV_TYPE_LOG "log" 242 243 /* 244 * This is needed in userland to report the minimum necessary device size. 245 */ 246 #define SPA_MINDEVSIZE (64ULL << 20) 247 248 /* 249 * The location of the pool configuration repository, shared between kernel and 250 * userland. 251 */ 252 #define ZPOOL_CACHE_DIR "/etc/zfs" 253 #define ZPOOL_CACHE_FILE "zpool.cache" 254 #define ZPOOL_CACHE_TMP ".zpool.cache" 255 256 #define ZPOOL_CACHE ZPOOL_CACHE_DIR "/" ZPOOL_CACHE_FILE 257 258 /* 259 * vdev states are ordered from least to most healthy. 260 * A vdev that's CANT_OPEN or below is considered unusable. 261 */ 262 typedef enum vdev_state { 263 VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev */ 264 VDEV_STATE_CLOSED, /* Not currently open */ 265 VDEV_STATE_OFFLINE, /* Not allowed to open */ 266 VDEV_STATE_REMOVED, /* Explicitly removed from system */ 267 VDEV_STATE_CANT_OPEN, /* Tried to open, but failed */ 268 VDEV_STATE_FAULTED, /* External request to fault device */ 269 VDEV_STATE_DEGRADED, /* Replicated vdev with unhealthy kids */ 270 VDEV_STATE_HEALTHY /* Presumed good */ 271 } vdev_state_t; 272 273 #define VDEV_STATE_ONLINE VDEV_STATE_HEALTHY 274 275 /* 276 * vdev aux states. When a vdev is in the CANT_OPEN state, the aux field 277 * of the vdev stats structure uses these constants to distinguish why. 278 */ 279 typedef enum vdev_aux { 280 VDEV_AUX_NONE, /* no error */ 281 VDEV_AUX_OPEN_FAILED, /* ldi_open_*() or vn_open() failed */ 282 VDEV_AUX_CORRUPT_DATA, /* bad label or disk contents */ 283 VDEV_AUX_NO_REPLICAS, /* insufficient number of replicas */ 284 VDEV_AUX_BAD_GUID_SUM, /* vdev guid sum doesn't match */ 285 VDEV_AUX_TOO_SMALL, /* vdev size is too small */ 286 VDEV_AUX_BAD_LABEL, /* the label is OK but invalid */ 287 VDEV_AUX_VERSION_NEWER, /* on-disk version is too new */ 288 VDEV_AUX_VERSION_OLDER, /* on-disk version is too old */ 289 VDEV_AUX_SPARED, /* hot spare used in another pool */ 290 VDEV_AUX_ERR_EXCEEDED /* too many errors */ 291 } vdev_aux_t; 292 293 /* 294 * pool state. The following states are written to disk as part of the normal 295 * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE. The remaining states are 296 * software abstractions used at various levels to communicate pool state. 297 */ 298 typedef enum pool_state { 299 POOL_STATE_ACTIVE = 0, /* In active use */ 300 POOL_STATE_EXPORTED, /* Explicitly exported */ 301 POOL_STATE_DESTROYED, /* Explicitly destroyed */ 302 POOL_STATE_SPARE, /* Reserved for hot spare use */ 303 POOL_STATE_UNINITIALIZED, /* Internal spa_t state */ 304 POOL_STATE_UNAVAIL, /* Internal libzfs state */ 305 POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */ 306 } pool_state_t; 307 308 /* 309 * Scrub types. 310 */ 311 typedef enum pool_scrub_type { 312 POOL_SCRUB_NONE, 313 POOL_SCRUB_RESILVER, 314 POOL_SCRUB_EVERYTHING, 315 POOL_SCRUB_TYPES 316 } pool_scrub_type_t; 317 318 /* 319 * ZIO types. Needed to interpret vdev statistics below. 320 */ 321 typedef enum zio_type { 322 ZIO_TYPE_NULL = 0, 323 ZIO_TYPE_READ, 324 ZIO_TYPE_WRITE, 325 ZIO_TYPE_FREE, 326 ZIO_TYPE_CLAIM, 327 ZIO_TYPE_IOCTL, 328 ZIO_TYPES 329 } zio_type_t; 330 331 /* 332 * Vdev statistics. Note: all fields should be 64-bit because this 333 * is passed between kernel and userland as an nvlist uint64 array. 334 */ 335 typedef struct vdev_stat { 336 hrtime_t vs_timestamp; /* time since vdev load */ 337 uint64_t vs_state; /* vdev state */ 338 uint64_t vs_aux; /* see vdev_aux_t */ 339 uint64_t vs_alloc; /* space allocated */ 340 uint64_t vs_space; /* total capacity */ 341 uint64_t vs_dspace; /* deflated capacity */ 342 uint64_t vs_rsize; /* replaceable dev size */ 343 uint64_t vs_ops[ZIO_TYPES]; /* operation count */ 344 uint64_t vs_bytes[ZIO_TYPES]; /* bytes read/written */ 345 uint64_t vs_read_errors; /* read errors */ 346 uint64_t vs_write_errors; /* write errors */ 347 uint64_t vs_checksum_errors; /* checksum errors */ 348 uint64_t vs_self_healed; /* self-healed bytes */ 349 uint64_t vs_scrub_type; /* pool_scrub_type_t */ 350 uint64_t vs_scrub_complete; /* completed? */ 351 uint64_t vs_scrub_examined; /* bytes examined; top */ 352 uint64_t vs_scrub_repaired; /* bytes repaired; leaf */ 353 uint64_t vs_scrub_errors; /* errors during scrub */ 354 uint64_t vs_scrub_start; /* UTC scrub start time */ 355 uint64_t vs_scrub_end; /* UTC scrub end time */ 356 } vdev_stat_t; 357 358 #define ZFS_DRIVER "zfs" 359 #define ZFS_DEV "/dev/zfs" 360 361 /* 362 * zvol paths. Irritatingly, the devfsadm interfaces want all these 363 * paths without the /dev prefix, but for some things, we want the 364 * /dev prefix. Below are the names without /dev. 365 */ 366 #define ZVOL_DEV_DIR "zvol/dsk" 367 #define ZVOL_RDEV_DIR "zvol/rdsk" 368 369 /* 370 * And here are the things we need with /dev, etc. in front of them. 371 */ 372 #define ZVOL_PSEUDO_DEV "/devices/pseudo/zvol@0:" 373 #define ZVOL_FULL_DEV_DIR "/dev/" ZVOL_DEV_DIR 374 375 #define ZVOL_PROP_NAME "name" 376 377 /* 378 * /dev/zfs ioctl numbers. 379 */ 380 #define ZFS_IOC ('Z' << 8) 381 382 typedef enum zfs_ioc { 383 ZFS_IOC_POOL_CREATE = ZFS_IOC, 384 ZFS_IOC_POOL_DESTROY, 385 ZFS_IOC_POOL_IMPORT, 386 ZFS_IOC_POOL_EXPORT, 387 ZFS_IOC_POOL_CONFIGS, 388 ZFS_IOC_POOL_STATS, 389 ZFS_IOC_POOL_TRYIMPORT, 390 ZFS_IOC_POOL_SCRUB, 391 ZFS_IOC_POOL_FREEZE, 392 ZFS_IOC_POOL_UPGRADE, 393 ZFS_IOC_POOL_GET_HISTORY, 394 ZFS_IOC_POOL_LOG_HISTORY, 395 ZFS_IOC_VDEV_ADD, 396 ZFS_IOC_VDEV_REMOVE, 397 ZFS_IOC_VDEV_SET_STATE, 398 ZFS_IOC_VDEV_ATTACH, 399 ZFS_IOC_VDEV_DETACH, 400 ZFS_IOC_VDEV_SETPATH, 401 ZFS_IOC_OBJSET_STATS, 402 ZFS_IOC_DATASET_LIST_NEXT, 403 ZFS_IOC_SNAPSHOT_LIST_NEXT, 404 ZFS_IOC_SET_PROP, 405 ZFS_IOC_CREATE_MINOR, 406 ZFS_IOC_REMOVE_MINOR, 407 ZFS_IOC_CREATE, 408 ZFS_IOC_DESTROY, 409 ZFS_IOC_ROLLBACK, 410 ZFS_IOC_RENAME, 411 ZFS_IOC_RECVBACKUP, 412 ZFS_IOC_SENDBACKUP, 413 ZFS_IOC_INJECT_FAULT, 414 ZFS_IOC_CLEAR_FAULT, 415 ZFS_IOC_INJECT_LIST_NEXT, 416 ZFS_IOC_ERROR_LOG, 417 ZFS_IOC_CLEAR, 418 ZFS_IOC_PROMOTE, 419 ZFS_IOC_DESTROY_SNAPS, 420 ZFS_IOC_SNAPSHOT, 421 ZFS_IOC_DSOBJ_TO_DSNAME, 422 ZFS_IOC_OBJ_TO_PATH, 423 ZFS_IOC_POOL_SET_PROPS, 424 ZFS_IOC_POOL_GET_PROPS 425 } zfs_ioc_t; 426 427 /* 428 * Internal SPA load state. Used by FMA diagnosis engine. 429 */ 430 typedef enum { 431 SPA_LOAD_NONE, /* no load in progress */ 432 SPA_LOAD_OPEN, /* normal open */ 433 SPA_LOAD_IMPORT, /* import in progress */ 434 SPA_LOAD_TRYIMPORT /* tryimport in progress */ 435 } spa_load_state_t; 436 437 /* 438 * Bookmark name values. 439 */ 440 #define ZPOOL_ERR_LIST "error list" 441 #define ZPOOL_ERR_DATASET "dataset" 442 #define ZPOOL_ERR_OBJECT "object" 443 444 #define HIS_MAX_RECORD_LEN (MAXPATHLEN + MAXPATHLEN + 1) 445 446 /* 447 * The following are names used in the nvlist describing 448 * the pool's history log. 449 */ 450 #define ZPOOL_HIST_RECORD "history record" 451 #define ZPOOL_HIST_TIME "history time" 452 #define ZPOOL_HIST_CMD "history command" 453 454 /* 455 * Flags for ZFS_IOC_VDEV_SET_STATE 456 */ 457 #define ZFS_ONLINE_CHECKREMOVE 0x1 458 #define ZFS_ONLINE_UNSPARE 0x2 459 #define ZFS_ONLINE_FORCEFAULT 0x4 460 #define ZFS_OFFLINE_TEMPORARY 0x1 461 462 /* 463 * Sysevent payload members. ZFS will generate the following sysevents with the 464 * given payloads: 465 * 466 * ESC_ZFS_RESILVER_START 467 * ESC_ZFS_RESILVER_END 468 * ESC_ZFS_POOL_DESTROY 469 * 470 * ZFS_EV_POOL_NAME DATA_TYPE_STRING 471 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64 472 * 473 * ESC_ZFS_VDEV_REMOVE 474 * ESC_ZFS_VDEV_CLEAR 475 * ESC_ZFS_VDEV_CHECK 476 * 477 * ZFS_EV_POOL_NAME DATA_TYPE_STRING 478 * ZFS_EV_POOL_GUID DATA_TYPE_UINT64 479 * ZFS_EV_VDEV_PATH DATA_TYPE_STRING (optional) 480 * ZFS_EV_VDEV_GUID DATA_TYPE_UINT64 481 */ 482 #define ZFS_EV_POOL_NAME "pool_name" 483 #define ZFS_EV_POOL_GUID "pool_guid" 484 #define ZFS_EV_VDEV_PATH "vdev_path" 485 #define ZFS_EV_VDEV_GUID "vdev_guid" 486 487 #ifdef __cplusplus 488 } 489 #endif 490 491 #endif /* _SYS_FS_ZFS_H */ 492