FreeBSD ZFS
The Zettabyte File System
|
00001 /* 00002 * CDDL HEADER START 00003 * 00004 * The contents of this file are subject to the terms of the 00005 * Common Development and Distribution License (the "License"). 00006 * You may not use this file except in compliance with the License. 00007 * 00008 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 00009 * or http://www.opensolaris.org/os/licensing. 00010 * See the License for the specific language governing permissions 00011 * and limitations under the License. 00012 * 00013 * When distributing Covered Code, include this CDDL HEADER in each 00014 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 00015 * If applicable, add the following below this CDDL HEADER, with the 00016 * fields enclosed by brackets "[]" replaced with your own identifying 00017 * information: Portions Copyright [yyyy] [name of copyright owner] 00018 * 00019 * CDDL HEADER END 00020 */ 00021 /* 00022 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 00023 * Copyright (c) 2012 by Delphix. All rights reserved. 00024 */ 00025 00026 #ifndef _SYS_VDEV_IMPL_H 00027 #define _SYS_VDEV_IMPL_H 00028 00029 #include <sys/avl.h> 00030 #include <sys/dmu.h> 00031 #include <sys/metaslab.h> 00032 #include <sys/nvpair.h> 00033 #include <sys/space_map.h> 00034 #include <sys/vdev.h> 00035 #include <sys/dkio.h> 00036 #include <sys/uberblock_impl.h> 00037 00038 #ifdef __cplusplus 00039 extern "C" { 00040 #endif 00041 00050 /* 00051 * Forward declarations that lots of things need. 00052 */ 00053 typedef struct vdev_queue vdev_queue_t; 00054 typedef struct vdev_cache vdev_cache_t; 00055 typedef struct vdev_cache_entry vdev_cache_entry_t; 00056 00062 typedef int vdev_open_func_t(vdev_t *vd, uint64_t *size, uint64_t *max_size, 00063 uint64_t *ashift); 00064 typedef void vdev_close_func_t(vdev_t *vd); 00065 typedef uint64_t vdev_asize_func_t(vdev_t *vd, uint64_t psize); 00066 typedef int vdev_io_start_func_t(zio_t *zio); 00067 typedef void vdev_io_done_func_t(zio_t *zio); 00068 typedef void vdev_state_change_func_t(vdev_t *vd, int, int); 00069 typedef void vdev_hold_func_t(vdev_t *vd); 00070 typedef void vdev_rele_func_t(vdev_t *vd); 00071 /* \} */ 00072 00073 typedef struct vdev_ops { 00074 vdev_open_func_t *vdev_op_open; 00075 vdev_close_func_t *vdev_op_close; 00076 vdev_asize_func_t *vdev_op_asize; 00077 vdev_io_start_func_t *vdev_op_io_start; 00078 vdev_io_done_func_t *vdev_op_io_done; 00079 vdev_state_change_func_t *vdev_op_state_change; 00080 vdev_hold_func_t *vdev_op_hold; 00081 vdev_rele_func_t *vdev_op_rele; 00082 char vdev_op_type[16]; 00083 boolean_t vdev_op_leaf; 00084 } vdev_ops_t; 00085 00086 struct vdev_cache_entry { 00087 char *ve_data; 00088 uint64_t ve_offset; 00089 uint64_t ve_lastused; 00090 avl_node_t ve_offset_node; 00091 avl_node_t ve_lastused_node; 00092 uint32_t ve_hits; 00093 uint16_t ve_missed_update; 00094 zio_t *ve_fill_io; 00095 }; 00096 00097 struct vdev_cache { 00098 avl_tree_t vc_offset_tree; 00099 avl_tree_t vc_lastused_tree; 00100 kmutex_t vc_lock; 00101 }; 00102 00106 struct vdev_queue { 00107 avl_tree_t vq_deadline_tree; 00108 avl_tree_t vq_read_tree; 00109 avl_tree_t vq_write_tree; 00110 avl_tree_t vq_pending_tree; 00111 kmutex_t vq_lock; 00112 }; 00113 00117 struct vdev { 00123 uint64_t vdev_id; 00124 uint64_t vdev_guid; 00125 uint64_t vdev_guid_sum; 00126 uint64_t vdev_orig_guid; 00127 uint64_t vdev_asize; 00128 uint64_t vdev_min_asize; 00129 uint64_t vdev_max_asize; 00136 uint64_t vdev_ashift; 00137 uint64_t vdev_state; 00138 uint64_t vdev_prevstate; 00139 vdev_ops_t *vdev_ops; 00140 spa_t *vdev_spa; 00141 void *vdev_tsd; 00142 vnode_t *vdev_name_vp; 00143 vnode_t *vdev_devid_vp; 00144 vdev_t *vdev_top; 00145 vdev_t *vdev_parent; 00146 vdev_t **vdev_child; 00147 uint64_t vdev_children; 00148 space_map_t vdev_dtl[DTL_TYPES]; 00149 vdev_stat_t vdev_stat; 00150 boolean_t vdev_expanding; 00151 boolean_t vdev_reopening; 00152 int vdev_open_error; 00153 kthread_t *vdev_open_thread; 00154 uint64_t vdev_crtxg; 00155 /* \} */ 00156 00162 uint64_t vdev_ms_array; 00163 uint64_t vdev_ms_shift; 00164 uint64_t vdev_ms_count; 00165 metaslab_group_t *vdev_mg; 00166 metaslab_t **vdev_ms; 00167 txg_list_t vdev_ms_list; 00168 txg_list_t vdev_dtl_list; 00169 txg_node_t vdev_txg_node; 00170 boolean_t vdev_remove_wanted; 00171 boolean_t vdev_probe_wanted; 00172 uint64_t vdev_removing; 00173 list_node_t vdev_config_dirty_node; 00174 list_node_t vdev_state_dirty_node; 00175 uint64_t vdev_deflate_ratio; 00176 uint64_t vdev_islog; 00177 uint64_t vdev_ishole; 00178 /* \} */ 00179 00185 uint64_t vdev_psize; 00186 space_map_obj_t vdev_dtl_smo; 00187 txg_node_t vdev_dtl_node; 00188 uint64_t vdev_wholedisk; 00189 uint64_t vdev_offline; 00190 uint64_t vdev_faulted; 00191 uint64_t vdev_degraded; 00192 uint64_t vdev_removed; 00193 uint64_t vdev_resilvering; 00194 uint64_t vdev_nparity; 00195 char *vdev_path; 00196 char *vdev_devid; 00197 char *vdev_physpath; 00198 char *vdev_fru; 00199 uint64_t vdev_not_present; 00200 uint64_t vdev_unspare; 00201 hrtime_t vdev_last_try; 00202 boolean_t vdev_nowritecache; 00203 boolean_t vdev_notrim; 00204 boolean_t vdev_checkremove; 00205 boolean_t vdev_forcefault; 00206 boolean_t vdev_splitting; 00207 boolean_t vdev_delayed_close; 00208 uint8_t vdev_tmpoffline; 00209 uint8_t vdev_detached; 00210 uint8_t vdev_cant_read; 00211 uint8_t vdev_cant_write; 00212 uint64_t vdev_isspare; 00213 uint64_t vdev_isl2cache; 00214 vdev_queue_t vdev_queue; 00215 vdev_cache_t vdev_cache; 00216 spa_aux_vdev_t *vdev_aux; 00217 zio_t *vdev_probe_zio; 00218 vdev_aux_t vdev_label_aux; 00219 struct trim_map *vdev_trimmap; 00220 /* \} */ 00221 00222 /* 00223 * For DTrace to work in userland (libzpool) context, these fields must 00224 * remain at the end of the structure. DTrace will use the kernel's 00225 * CTF definition for 'struct vdev', and since the size of a kmutex_t is 00226 * larger in userland, the offsets for the rest of the fields would be 00227 * incorrect. 00228 */ 00229 kmutex_t vdev_dtl_lock; 00230 kmutex_t vdev_stat_lock; 00231 kmutex_t vdev_probe_lock; 00232 }; 00233 00234 #define VDEV_RAIDZ_MAXPARITY 3 00235 00236 #define VDEV_PAD_SIZE (8 << 10) 00237 00238 #define VDEV_SKIP_SIZE VDEV_PAD_SIZE * 2 00239 #define VDEV_PHYS_SIZE (112 << 10) 00240 #define VDEV_UBERBLOCK_RING (128 << 10) 00241 00242 #define VDEV_UBERBLOCK_SHIFT(vd) \ 00243 MAX((vd)->vdev_top->vdev_ashift, UBERBLOCK_SHIFT) 00244 #define VDEV_UBERBLOCK_COUNT(vd) \ 00245 (VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT(vd)) 00246 #define VDEV_UBERBLOCK_OFFSET(vd, n) \ 00247 offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT(vd)]) 00248 #define VDEV_UBERBLOCK_SIZE(vd) (1ULL << VDEV_UBERBLOCK_SHIFT(vd)) 00249 00250 typedef struct vdev_phys { 00251 char vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)]; 00252 zio_eck_t vp_zbt; 00253 } vdev_phys_t; 00254 00256 typedef struct vdev_label { 00257 char vl_pad1[VDEV_PAD_SIZE]; 00258 char vl_pad2[VDEV_PAD_SIZE]; 00259 vdev_phys_t vl_vdev_phys; 00260 char vl_uberblock[VDEV_UBERBLOCK_RING]; 00261 } vdev_label_t; 00262 00266 #define VDD_METASLAB 0x01 00267 #define VDD_DTL 0x02 00268 00270 #define VDEV_BOOT_OFFSET (2 * sizeof (vdev_label_t)) 00271 00275 #define VDEV_BOOT_SIZE (7ULL << 19) /* 3.5M */ 00276 00277 /* 00278 * Size of label regions at the start and end of each leaf device. 00279 */ 00280 #define VDEV_LABEL_START_SIZE (2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE) 00281 #define VDEV_LABEL_END_SIZE (2 * sizeof (vdev_label_t)) 00282 #define VDEV_LABELS 4 00283 #define VDEV_BEST_LABEL VDEV_LABELS 00284 00285 #define VDEV_ALLOC_LOAD 0 00286 #define VDEV_ALLOC_ADD 1 00287 #define VDEV_ALLOC_SPARE 2 00288 #define VDEV_ALLOC_L2CACHE 3 00289 #define VDEV_ALLOC_ROOTPOOL 4 00290 #define VDEV_ALLOC_SPLIT 5 00291 #define VDEV_ALLOC_ATTACH 6 00292 00293 /* 00294 * Allocate or free a vdev 00295 */ 00296 extern vdev_t *vdev_alloc_common(spa_t *spa, uint_t id, uint64_t guid, 00297 vdev_ops_t *ops); 00298 extern int vdev_alloc(spa_t *spa, vdev_t **vdp, nvlist_t *config, 00299 vdev_t *parent, uint_t id, int alloctype); 00300 extern void vdev_free(vdev_t *vd); 00301 00302 /* 00303 * Add or remove children and parents 00304 */ 00305 extern void vdev_add_child(vdev_t *pvd, vdev_t *cvd); 00306 extern void vdev_remove_child(vdev_t *pvd, vdev_t *cvd); 00307 extern void vdev_compact_children(vdev_t *pvd); 00308 extern vdev_t *vdev_add_parent(vdev_t *cvd, vdev_ops_t *ops); 00309 extern void vdev_remove_parent(vdev_t *cvd); 00310 00311 /* 00312 * vdev sync load and sync 00313 */ 00314 extern void vdev_load_log_state(vdev_t *nvd, vdev_t *ovd); 00315 extern boolean_t vdev_log_state_valid(vdev_t *vd); 00316 extern void vdev_load(vdev_t *vd); 00317 extern void vdev_sync(vdev_t *vd, uint64_t txg); 00318 extern void vdev_sync_done(vdev_t *vd, uint64_t txg); 00319 extern void vdev_dirty(vdev_t *vd, int flags, void *arg, uint64_t txg); 00320 00321 /* 00322 * Available vdev types. 00323 */ 00324 extern vdev_ops_t vdev_root_ops; 00325 extern vdev_ops_t vdev_mirror_ops; 00326 extern vdev_ops_t vdev_replacing_ops; 00327 extern vdev_ops_t vdev_raidz_ops; 00328 #ifdef _KERNEL 00329 extern vdev_ops_t vdev_geom_ops; 00330 #else 00331 extern vdev_ops_t vdev_disk_ops; 00332 #endif 00333 extern vdev_ops_t vdev_file_ops; 00334 extern vdev_ops_t vdev_missing_ops; 00335 extern vdev_ops_t vdev_hole_ops; 00336 extern vdev_ops_t vdev_spare_ops; 00337 00338 /* 00339 * Common size functions 00340 */ 00341 extern uint64_t vdev_default_asize(vdev_t *vd, uint64_t psize); 00342 extern uint64_t vdev_get_min_asize(vdev_t *vd); 00343 extern void vdev_set_min_asize(vdev_t *vd); 00344 00345 /* 00346 * zdb uses this tunable, so it must be declared here to make lint happy. 00347 */ 00348 extern int zfs_vdev_cache_size; 00349 00350 #ifdef __cplusplus 00351 } 00352 #endif 00353 00354 #endif /* _SYS_VDEV_IMPL_H */