]>
Commit | Line | Data |
---|---|---|
34dc7c2f BB |
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 | /* | |
428870ff | 22 | * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
492f64e9 | 23 | * Copyright (c) 2011, 2018 by Delphix. All rights reserved. |
cc99f275 | 24 | * Copyright (c) 2017, Intel Corporation. |
34dc7c2f BB |
25 | */ |
26 | ||
27 | #ifndef _SYS_VDEV_IMPL_H | |
28 | #define _SYS_VDEV_IMPL_H | |
29 | ||
34dc7c2f | 30 | #include <sys/avl.h> |
a1d477c2 | 31 | #include <sys/bpobj.h> |
34dc7c2f BB |
32 | #include <sys/dmu.h> |
33 | #include <sys/metaslab.h> | |
34 | #include <sys/nvpair.h> | |
35 | #include <sys/space_map.h> | |
36 | #include <sys/vdev.h> | |
37 | #include <sys/dkio.h> | |
38 | #include <sys/uberblock_impl.h> | |
a1d477c2 MA |
39 | #include <sys/vdev_indirect_mapping.h> |
40 | #include <sys/vdev_indirect_births.h> | |
41 | #include <sys/vdev_removal.h> | |
6078881a | 42 | #include <sys/zfs_ratelimit.h> |
34dc7c2f BB |
43 | |
44 | #ifdef __cplusplus | |
45 | extern "C" { | |
46 | #endif | |
47 | ||
48 | /* | |
49 | * Virtual device descriptors. | |
50 | * | |
51 | * All storage pool operations go through the virtual device framework, | |
52 | * which provides data replication and I/O scheduling. | |
53 | */ | |
54 | ||
55 | /* | |
56 | * Forward declarations that lots of things need. | |
57 | */ | |
58 | typedef struct vdev_queue vdev_queue_t; | |
59 | typedef struct vdev_cache vdev_cache_t; | |
60 | typedef struct vdev_cache_entry vdev_cache_entry_t; | |
a6255b7f | 61 | struct abd; |
34dc7c2f | 62 | |
3dfb57a3 | 63 | extern int zfs_vdev_queue_depth_pct; |
492f64e9 | 64 | extern int zfs_vdev_def_queue_depth; |
3dfb57a3 DB |
65 | extern uint32_t zfs_vdev_async_write_max_active; |
66 | ||
34dc7c2f BB |
67 | /* |
68 | * Virtual device operations | |
69 | */ | |
1bd201e7 CS |
70 | typedef int vdev_open_func_t(vdev_t *vd, uint64_t *size, uint64_t *max_size, |
71 | uint64_t *ashift); | |
34dc7c2f | 72 | typedef void vdev_close_func_t(vdev_t *vd); |
34dc7c2f | 73 | typedef uint64_t vdev_asize_func_t(vdev_t *vd, uint64_t psize); |
98b25418 | 74 | typedef void vdev_io_start_func_t(zio_t *zio); |
b128c09f | 75 | typedef void vdev_io_done_func_t(zio_t *zio); |
34dc7c2f | 76 | typedef void vdev_state_change_func_t(vdev_t *vd, int, int); |
3d6da72d | 77 | typedef boolean_t vdev_need_resilver_func_t(vdev_t *vd, uint64_t, size_t); |
428870ff BB |
78 | typedef void vdev_hold_func_t(vdev_t *vd); |
79 | typedef void vdev_rele_func_t(vdev_t *vd); | |
34dc7c2f | 80 | |
a1d477c2 MA |
81 | typedef void vdev_remap_cb_t(uint64_t inner_offset, vdev_t *vd, |
82 | uint64_t offset, uint64_t size, void *arg); | |
83 | typedef void vdev_remap_func_t(vdev_t *vd, uint64_t offset, uint64_t size, | |
84 | vdev_remap_cb_t callback, void *arg); | |
619f0976 GW |
85 | /* |
86 | * Given a target vdev, translates the logical range "in" to the physical | |
87 | * range "res" | |
88 | */ | |
89 | typedef void vdev_xlation_func_t(vdev_t *cvd, const range_seg_t *in, | |
90 | range_seg_t *res); | |
a1d477c2 | 91 | |
b01615d5 | 92 | typedef const struct vdev_ops { |
34dc7c2f BB |
93 | vdev_open_func_t *vdev_op_open; |
94 | vdev_close_func_t *vdev_op_close; | |
34dc7c2f BB |
95 | vdev_asize_func_t *vdev_op_asize; |
96 | vdev_io_start_func_t *vdev_op_io_start; | |
97 | vdev_io_done_func_t *vdev_op_io_done; | |
98 | vdev_state_change_func_t *vdev_op_state_change; | |
3d6da72d | 99 | vdev_need_resilver_func_t *vdev_op_need_resilver; |
428870ff BB |
100 | vdev_hold_func_t *vdev_op_hold; |
101 | vdev_rele_func_t *vdev_op_rele; | |
a1d477c2 | 102 | vdev_remap_func_t *vdev_op_remap; |
619f0976 GW |
103 | /* |
104 | * For translating ranges from non-leaf vdevs (e.g. raidz) to leaves. | |
105 | * Used when initializing vdevs. Isn't used by leaf ops. | |
106 | */ | |
107 | vdev_xlation_func_t *vdev_op_xlate; | |
34dc7c2f BB |
108 | char vdev_op_type[16]; |
109 | boolean_t vdev_op_leaf; | |
110 | } vdev_ops_t; | |
111 | ||
112 | /* | |
113 | * Virtual device properties | |
114 | */ | |
115 | struct vdev_cache_entry { | |
a6255b7f | 116 | struct abd *ve_abd; |
34dc7c2f | 117 | uint64_t ve_offset; |
0b75bdb3 | 118 | clock_t ve_lastused; |
34dc7c2f BB |
119 | avl_node_t ve_offset_node; |
120 | avl_node_t ve_lastused_node; | |
121 | uint32_t ve_hits; | |
122 | uint16_t ve_missed_update; | |
123 | zio_t *ve_fill_io; | |
124 | }; | |
125 | ||
126 | struct vdev_cache { | |
127 | avl_tree_t vc_offset_tree; | |
128 | avl_tree_t vc_lastused_tree; | |
129 | kmutex_t vc_lock; | |
130 | }; | |
131 | ||
e8b96c60 MA |
132 | typedef struct vdev_queue_class { |
133 | uint32_t vqc_active; | |
134 | ||
135 | /* | |
136 | * Sorted by offset or timestamp, depending on if the queue is | |
137 | * LBA-ordered vs FIFO. | |
138 | */ | |
139 | avl_tree_t vqc_queued_tree; | |
140 | } vdev_queue_class_t; | |
141 | ||
34dc7c2f | 142 | struct vdev_queue { |
e8b96c60 MA |
143 | vdev_t *vq_vdev; |
144 | vdev_queue_class_t vq_class[ZIO_PRIORITY_NUM_QUEUEABLE]; | |
145 | avl_tree_t vq_active_tree; | |
ec8501ee JG |
146 | avl_tree_t vq_read_offset_tree; |
147 | avl_tree_t vq_write_offset_tree; | |
e8b96c60 MA |
148 | uint64_t vq_last_offset; |
149 | hrtime_t vq_io_complete_ts; /* time last i/o completed */ | |
cb682a17 | 150 | hrtime_t vq_io_delta_ts; |
50b25b21 | 151 | zio_t vq_io_search; /* used as local for stack reduction */ |
34dc7c2f BB |
152 | kmutex_t vq_lock; |
153 | }; | |
154 | ||
cc99f275 DB |
155 | typedef enum vdev_alloc_bias { |
156 | VDEV_BIAS_NONE, | |
157 | VDEV_BIAS_LOG, /* dedicated to ZIL data (SLOG) */ | |
158 | VDEV_BIAS_SPECIAL, /* dedicated to ddt, metadata, and small blks */ | |
159 | VDEV_BIAS_DEDUP /* dedicated to dedup metadata */ | |
160 | } vdev_alloc_bias_t; | |
161 | ||
162 | ||
a1d477c2 MA |
163 | /* |
164 | * On-disk indirect vdev state. | |
165 | * | |
166 | * An indirect vdev is described exclusively in the MOS config of a pool. | |
167 | * The config for an indirect vdev includes several fields, which are | |
168 | * accessed in memory by a vdev_indirect_config_t. | |
169 | */ | |
170 | typedef struct vdev_indirect_config { | |
171 | /* | |
172 | * Object (in MOS) which contains the indirect mapping. This object | |
173 | * contains an array of vdev_indirect_mapping_entry_phys_t ordered by | |
174 | * vimep_src. The bonus buffer for this object is a | |
175 | * vdev_indirect_mapping_phys_t. This object is allocated when a vdev | |
176 | * removal is initiated. | |
177 | * | |
178 | * Note that this object can be empty if none of the data on the vdev | |
179 | * has been copied yet. | |
180 | */ | |
181 | uint64_t vic_mapping_object; | |
182 | ||
183 | /* | |
184 | * Object (in MOS) which contains the birth times for the mapping | |
185 | * entries. This object contains an array of | |
186 | * vdev_indirect_birth_entry_phys_t sorted by vibe_offset. The bonus | |
187 | * buffer for this object is a vdev_indirect_birth_phys_t. This object | |
188 | * is allocated when a vdev removal is initiated. | |
189 | * | |
190 | * Note that this object can be empty if none of the vdev has yet been | |
191 | * copied. | |
192 | */ | |
193 | uint64_t vic_births_object; | |
194 | ||
195 | /* | |
196 | * This is the vdev ID which was removed previous to this vdev, or | |
197 | * UINT64_MAX if there are no previously removed vdevs. | |
198 | */ | |
199 | uint64_t vic_prev_indirect_vdev; | |
200 | } vdev_indirect_config_t; | |
201 | ||
34dc7c2f BB |
202 | /* |
203 | * Virtual device descriptor | |
204 | */ | |
205 | struct vdev { | |
206 | /* | |
207 | * Common to all vdev types. | |
208 | */ | |
209 | uint64_t vdev_id; /* child number in vdev parent */ | |
210 | uint64_t vdev_guid; /* unique ID for this vdev */ | |
211 | uint64_t vdev_guid_sum; /* self guid + all child guids */ | |
428870ff | 212 | uint64_t vdev_orig_guid; /* orig. guid prior to remove */ |
34dc7c2f | 213 | uint64_t vdev_asize; /* allocatable device capacity */ |
9babb374 | 214 | uint64_t vdev_min_asize; /* min acceptable asize */ |
1bd201e7 | 215 | uint64_t vdev_max_asize; /* max acceptable asize */ |
34dc7c2f BB |
216 | uint64_t vdev_ashift; /* block alignment shift */ |
217 | uint64_t vdev_state; /* see VDEV_STATE_* #defines */ | |
218 | uint64_t vdev_prevstate; /* used when reopening a vdev */ | |
219 | vdev_ops_t *vdev_ops; /* vdev operations */ | |
220 | spa_t *vdev_spa; /* spa for this vdev */ | |
221 | void *vdev_tsd; /* type-specific data */ | |
428870ff BB |
222 | vnode_t *vdev_name_vp; /* vnode for pathname */ |
223 | vnode_t *vdev_devid_vp; /* vnode for devid */ | |
34dc7c2f BB |
224 | vdev_t *vdev_top; /* top-level vdev */ |
225 | vdev_t *vdev_parent; /* parent vdev */ | |
226 | vdev_t **vdev_child; /* array of children */ | |
227 | uint64_t vdev_children; /* number of children */ | |
34dc7c2f | 228 | vdev_stat_t vdev_stat; /* virtual device statistics */ |
193a37cb | 229 | vdev_stat_ex_t vdev_stat_ex; /* extended statistics */ |
9babb374 | 230 | boolean_t vdev_expanding; /* expand the vdev? */ |
428870ff | 231 | boolean_t vdev_reopening; /* reopen in progress? */ |
fb40095f | 232 | boolean_t vdev_nonrot; /* true if solid state */ |
45d1cae3 BB |
233 | int vdev_open_error; /* error on last open */ |
234 | kthread_t *vdev_open_thread; /* thread opening children */ | |
428870ff | 235 | uint64_t vdev_crtxg; /* txg when top-level was added */ |
34dc7c2f BB |
236 | |
237 | /* | |
238 | * Top-level vdev state. | |
239 | */ | |
240 | uint64_t vdev_ms_array; /* metaslab array object */ | |
241 | uint64_t vdev_ms_shift; /* metaslab size shift */ | |
242 | uint64_t vdev_ms_count; /* number of metaslabs */ | |
243 | metaslab_group_t *vdev_mg; /* metaslab group */ | |
244 | metaslab_t **vdev_ms; /* metaslab array */ | |
920dd524 | 245 | uint64_t vdev_pending_fastwrite; /* allocated fastwrites */ |
34dc7c2f BB |
246 | txg_list_t vdev_ms_list; /* per-txg dirty metaslab lists */ |
247 | txg_list_t vdev_dtl_list; /* per-txg dirty DTL lists */ | |
248 | txg_node_t vdev_txg_node; /* per-txg dirty vdev linkage */ | |
249 | boolean_t vdev_remove_wanted; /* async remove wanted? */ | |
b128c09f BB |
250 | boolean_t vdev_probe_wanted; /* async probe wanted? */ |
251 | list_node_t vdev_config_dirty_node; /* config dirty list */ | |
252 | list_node_t vdev_state_dirty_node; /* state dirty list */ | |
34dc7c2f BB |
253 | uint64_t vdev_deflate_ratio; /* deflation ratio (x512) */ |
254 | uint64_t vdev_islog; /* is an intent log device */ | |
93cf2076 | 255 | uint64_t vdev_removing; /* device is being removed? */ |
3dfb57a3 DB |
256 | boolean_t vdev_ishole; /* is a hole in the namespace */ |
257 | kmutex_t vdev_queue_lock; /* protects vdev_queue_depth */ | |
e0ab3ab5 | 258 | uint64_t vdev_top_zap; |
cc99f275 | 259 | vdev_alloc_bias_t vdev_alloc_bias; /* metaslab allocation bias */ |
34dc7c2f | 260 | |
d2734cce SD |
261 | /* pool checkpoint related */ |
262 | space_map_t *vdev_checkpoint_sm; /* contains reserved blocks */ | |
263 | ||
619f0976 GW |
264 | boolean_t vdev_initialize_exit_wanted; |
265 | vdev_initializing_state_t vdev_initialize_state; | |
266 | kthread_t *vdev_initialize_thread; | |
267 | /* Protects vdev_initialize_thread and vdev_initialize_state. */ | |
268 | kmutex_t vdev_initialize_lock; | |
269 | kcondvar_t vdev_initialize_cv; | |
270 | uint64_t vdev_initialize_offset[TXG_SIZE]; | |
271 | uint64_t vdev_initialize_last_offset; | |
272 | range_tree_t *vdev_initialize_tree; /* valid while initializing */ | |
273 | uint64_t vdev_initialize_bytes_est; | |
274 | uint64_t vdev_initialize_bytes_done; | |
275 | time_t vdev_initialize_action_time; /* start and end time */ | |
276 | ||
277 | /* for limiting outstanding I/Os */ | |
278 | kmutex_t vdev_initialize_io_lock; | |
279 | kcondvar_t vdev_initialize_io_cv; | |
280 | uint64_t vdev_initialize_inflight; | |
281 | ||
a1d477c2 MA |
282 | /* |
283 | * Values stored in the config for an indirect or removing vdev. | |
284 | */ | |
285 | vdev_indirect_config_t vdev_indirect_config; | |
286 | ||
287 | /* | |
288 | * The vdev_indirect_rwlock protects the vdev_indirect_mapping | |
289 | * pointer from changing on indirect vdevs (when it is condensed). | |
290 | * Note that removing (not yet indirect) vdevs have different | |
291 | * access patterns (the mapping is not accessed from open context, | |
292 | * e.g. from zio_read) and locking strategy (e.g. svr_lock). | |
293 | */ | |
294 | krwlock_t vdev_indirect_rwlock; | |
295 | vdev_indirect_mapping_t *vdev_indirect_mapping; | |
296 | vdev_indirect_births_t *vdev_indirect_births; | |
297 | ||
298 | /* | |
299 | * In memory data structures used to manage the obsolete sm, for | |
300 | * indirect or removing vdevs. | |
301 | * | |
302 | * The vdev_obsolete_segments is the in-core record of the segments | |
303 | * that are no longer referenced anywhere in the pool (due to | |
304 | * being freed or remapped and not referenced by any snapshots). | |
305 | * During a sync, segments are added to vdev_obsolete_segments | |
306 | * via vdev_indirect_mark_obsolete(); at the end of each sync | |
307 | * pass, this is appended to vdev_obsolete_sm via | |
308 | * vdev_indirect_sync_obsolete(). The vdev_obsolete_lock | |
309 | * protects against concurrent modifications of vdev_obsolete_segments | |
310 | * from multiple zio threads. | |
311 | */ | |
312 | kmutex_t vdev_obsolete_lock; | |
313 | range_tree_t *vdev_obsolete_segments; | |
314 | space_map_t *vdev_obsolete_sm; | |
315 | ||
3dfb57a3 DB |
316 | /* |
317 | * The queue depth parameters determine how many async writes are | |
9f438c5f | 318 | * still pending (i.e. allocated but not yet issued to disk) per |
3dfb57a3 DB |
319 | * top-level (vdev_async_write_queue_depth) and the maximum allowed |
320 | * (vdev_max_async_write_queue_depth). These values only apply to | |
321 | * top-level vdevs. | |
322 | */ | |
323 | uint64_t vdev_async_write_queue_depth; | |
324 | uint64_t vdev_max_async_write_queue_depth; | |
325 | ||
d4a72f23 TC |
326 | /* |
327 | * Protects the vdev_scan_io_queue field itself as well as the | |
328 | * structure's contents (when present). | |
329 | */ | |
330 | kmutex_t vdev_scan_io_queue_lock; | |
331 | struct dsl_scan_io_queue *vdev_scan_io_queue; | |
332 | ||
34dc7c2f BB |
333 | /* |
334 | * Leaf vdev state. | |
335 | */ | |
93cf2076 GW |
336 | range_tree_t *vdev_dtl[DTL_TYPES]; /* dirty time logs */ |
337 | space_map_t *vdev_dtl_sm; /* dirty time log space map */ | |
34dc7c2f | 338 | txg_node_t vdev_dtl_node; /* per-txg dirty DTL linkage */ |
93cf2076 GW |
339 | uint64_t vdev_dtl_object; /* DTL object */ |
340 | uint64_t vdev_psize; /* physical device capacity */ | |
34dc7c2f BB |
341 | uint64_t vdev_wholedisk; /* true if this is a whole disk */ |
342 | uint64_t vdev_offline; /* persistent offline state */ | |
343 | uint64_t vdev_faulted; /* persistent faulted state */ | |
344 | uint64_t vdev_degraded; /* persistent degraded state */ | |
345 | uint64_t vdev_removed; /* persistent removed state */ | |
5d1f7fb6 | 346 | uint64_t vdev_resilver_txg; /* persistent resilvering state */ |
34dc7c2f BB |
347 | uint64_t vdev_nparity; /* number of parity devices for raidz */ |
348 | char *vdev_path; /* vdev path (if any) */ | |
349 | char *vdev_devid; /* vdev devid (if any) */ | |
350 | char *vdev_physpath; /* vdev device path (if any) */ | |
1bbd8770 | 351 | char *vdev_enc_sysfs_path; /* enclosure sysfs path */ |
9babb374 | 352 | char *vdev_fru; /* physical FRU location */ |
b128c09f BB |
353 | uint64_t vdev_not_present; /* not present during import */ |
354 | uint64_t vdev_unspare; /* unspare when resilvering done */ | |
b128c09f BB |
355 | boolean_t vdev_nowritecache; /* true if flushwritecache failed */ |
356 | boolean_t vdev_checkremove; /* temporary online test */ | |
357 | boolean_t vdev_forcefault; /* force online fault */ | |
428870ff BB |
358 | boolean_t vdev_splitting; /* split or repair in progress */ |
359 | boolean_t vdev_delayed_close; /* delayed device close? */ | |
93cf2076 GW |
360 | boolean_t vdev_tmpoffline; /* device taken offline temporarily? */ |
361 | boolean_t vdev_detached; /* device detached? */ | |
362 | boolean_t vdev_cant_read; /* vdev is failing all reads */ | |
363 | boolean_t vdev_cant_write; /* vdev is failing all writes */ | |
364 | boolean_t vdev_isspare; /* was a hot spare */ | |
365 | boolean_t vdev_isl2cache; /* was a l2cache device */ | |
9d3f7b87 | 366 | boolean_t vdev_copy_uberblocks; /* post expand copy uberblocks */ |
80a91e74 | 367 | boolean_t vdev_resilver_deferred; /* resilver deferred */ |
34dc7c2f BB |
368 | vdev_queue_t vdev_queue; /* I/O deadline schedule queue */ |
369 | vdev_cache_t vdev_cache; /* physical block cache */ | |
c3520e7f | 370 | spa_aux_vdev_t *vdev_aux; /* for l2cache and spares vdevs */ |
b128c09f | 371 | zio_t *vdev_probe_zio; /* root of current probe */ |
428870ff | 372 | vdev_aux_t vdev_label_aux; /* on-disk aux state */ |
e0ab3ab5 | 373 | uint64_t vdev_leaf_zap; |
379ca9cf | 374 | hrtime_t vdev_mmp_pending; /* 0 if write finished */ |
7088545d | 375 | uint64_t vdev_mmp_kstat_id; /* to find kstat entry */ |
d48091de | 376 | uint64_t vdev_expansion_time; /* vdev's last expansion time */ |
34dc7c2f BB |
377 | |
378 | /* | |
379 | * For DTrace to work in userland (libzpool) context, these fields must | |
380 | * remain at the end of the structure. DTrace will use the kernel's | |
381 | * CTF definition for 'struct vdev', and since the size of a kmutex_t is | |
9ae529ec | 382 | * larger in userland, the offsets for the rest of the fields would be |
34dc7c2f BB |
383 | * incorrect. |
384 | */ | |
385 | kmutex_t vdev_dtl_lock; /* vdev_dtl_{map,resilver} */ | |
386 | kmutex_t vdev_stat_lock; /* vdev_stat */ | |
b128c09f | 387 | kmutex_t vdev_probe_lock; /* protects vdev_probe_zio */ |
6078881a TH |
388 | |
389 | /* | |
390 | * We rate limit ZIO delay and ZIO checksum events, since they | |
391 | * can flood ZED with tons of events when a drive is acting up. | |
392 | */ | |
6078881a TH |
393 | zfs_ratelimit_t vdev_delay_rl; |
394 | zfs_ratelimit_t vdev_checksum_rl; | |
34dc7c2f BB |
395 | }; |
396 | ||
428870ff BB |
397 | #define VDEV_RAIDZ_MAXPARITY 3 |
398 | ||
9babb374 BB |
399 | #define VDEV_PAD_SIZE (8 << 10) |
400 | /* 2 padding areas (vl_pad1 and vl_pad2) to skip */ | |
401 | #define VDEV_SKIP_SIZE VDEV_PAD_SIZE * 2 | |
34dc7c2f BB |
402 | #define VDEV_PHYS_SIZE (112 << 10) |
403 | #define VDEV_UBERBLOCK_RING (128 << 10) | |
404 | ||
379ca9cf OF |
405 | /* |
406 | * MMP blocks occupy the last MMP_BLOCKS_PER_LABEL slots in the uberblock | |
407 | * ring when MMP is enabled. | |
408 | */ | |
409 | #define MMP_BLOCKS_PER_LABEL 1 | |
410 | ||
b02fe35d AR |
411 | /* The largest uberblock we support is 8k. */ |
412 | #define MAX_UBERBLOCK_SHIFT (13) | |
34dc7c2f | 413 | #define VDEV_UBERBLOCK_SHIFT(vd) \ |
b02fe35d AR |
414 | MIN(MAX((vd)->vdev_top->vdev_ashift, UBERBLOCK_SHIFT), \ |
415 | MAX_UBERBLOCK_SHIFT) | |
34dc7c2f BB |
416 | #define VDEV_UBERBLOCK_COUNT(vd) \ |
417 | (VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT(vd)) | |
418 | #define VDEV_UBERBLOCK_OFFSET(vd, n) \ | |
419 | offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT(vd)]) | |
420 | #define VDEV_UBERBLOCK_SIZE(vd) (1ULL << VDEV_UBERBLOCK_SHIFT(vd)) | |
421 | ||
34dc7c2f | 422 | typedef struct vdev_phys { |
428870ff BB |
423 | char vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)]; |
424 | zio_eck_t vp_zbt; | |
34dc7c2f BB |
425 | } vdev_phys_t; |
426 | ||
427 | typedef struct vdev_label { | |
9babb374 BB |
428 | char vl_pad1[VDEV_PAD_SIZE]; /* 8K */ |
429 | char vl_pad2[VDEV_PAD_SIZE]; /* 8K */ | |
34dc7c2f BB |
430 | vdev_phys_t vl_vdev_phys; /* 112K */ |
431 | char vl_uberblock[VDEV_UBERBLOCK_RING]; /* 128K */ | |
432 | } vdev_label_t; /* 256K total */ | |
433 | ||
434 | /* | |
435 | * vdev_dirty() flags | |
436 | */ | |
437 | #define VDD_METASLAB 0x01 | |
438 | #define VDD_DTL 0x02 | |
439 | ||
d3cc8b15 WA |
440 | /* Offset of embedded boot loader region on each label */ |
441 | #define VDEV_BOOT_OFFSET (2 * sizeof (vdev_label_t)) | |
34dc7c2f | 442 | /* |
d3cc8b15 | 443 | * Size of embedded boot loader region on each label. |
34dc7c2f BB |
444 | * The total size of the first two labels plus the boot area is 4MB. |
445 | */ | |
d3cc8b15 | 446 | #define VDEV_BOOT_SIZE (7ULL << 19) /* 3.5M */ |
34dc7c2f BB |
447 | |
448 | /* | |
449 | * Size of label regions at the start and end of each leaf device. | |
450 | */ | |
451 | #define VDEV_LABEL_START_SIZE (2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE) | |
452 | #define VDEV_LABEL_END_SIZE (2 * sizeof (vdev_label_t)) | |
453 | #define VDEV_LABELS 4 | |
9ae529ec | 454 | #define VDEV_BEST_LABEL VDEV_LABELS |
34dc7c2f BB |
455 | |
456 | #define VDEV_ALLOC_LOAD 0 | |
457 | #define VDEV_ALLOC_ADD 1 | |
458 | #define VDEV_ALLOC_SPARE 2 | |
459 | #define VDEV_ALLOC_L2CACHE 3 | |
9babb374 | 460 | #define VDEV_ALLOC_ROOTPOOL 4 |
428870ff | 461 | #define VDEV_ALLOC_SPLIT 5 |
5ffb9d1d | 462 | #define VDEV_ALLOC_ATTACH 6 |
34dc7c2f BB |
463 | |
464 | /* | |
465 | * Allocate or free a vdev | |
466 | */ | |
428870ff BB |
467 | extern vdev_t *vdev_alloc_common(spa_t *spa, uint_t id, uint64_t guid, |
468 | vdev_ops_t *ops); | |
34dc7c2f BB |
469 | extern int vdev_alloc(spa_t *spa, vdev_t **vdp, nvlist_t *config, |
470 | vdev_t *parent, uint_t id, int alloctype); | |
471 | extern void vdev_free(vdev_t *vd); | |
472 | ||
473 | /* | |
474 | * Add or remove children and parents | |
475 | */ | |
476 | extern void vdev_add_child(vdev_t *pvd, vdev_t *cvd); | |
477 | extern void vdev_remove_child(vdev_t *pvd, vdev_t *cvd); | |
478 | extern void vdev_compact_children(vdev_t *pvd); | |
479 | extern vdev_t *vdev_add_parent(vdev_t *cvd, vdev_ops_t *ops); | |
480 | extern void vdev_remove_parent(vdev_t *cvd); | |
481 | ||
482 | /* | |
483 | * vdev sync load and sync | |
484 | */ | |
572e2857 | 485 | extern boolean_t vdev_log_state_valid(vdev_t *vd); |
a1d477c2 | 486 | extern int vdev_load(vdev_t *vd); |
93cf2076 | 487 | extern int vdev_dtl_load(vdev_t *vd); |
34dc7c2f BB |
488 | extern void vdev_sync(vdev_t *vd, uint64_t txg); |
489 | extern void vdev_sync_done(vdev_t *vd, uint64_t txg); | |
490 | extern void vdev_dirty(vdev_t *vd, int flags, void *arg, uint64_t txg); | |
93cf2076 | 491 | extern void vdev_dirty_leaves(vdev_t *vd, int flags, uint64_t txg); |
34dc7c2f BB |
492 | |
493 | /* | |
494 | * Available vdev types. | |
495 | */ | |
496 | extern vdev_ops_t vdev_root_ops; | |
497 | extern vdev_ops_t vdev_mirror_ops; | |
498 | extern vdev_ops_t vdev_replacing_ops; | |
499 | extern vdev_ops_t vdev_raidz_ops; | |
500 | extern vdev_ops_t vdev_disk_ops; | |
501 | extern vdev_ops_t vdev_file_ops; | |
502 | extern vdev_ops_t vdev_missing_ops; | |
428870ff | 503 | extern vdev_ops_t vdev_hole_ops; |
34dc7c2f | 504 | extern vdev_ops_t vdev_spare_ops; |
a1d477c2 | 505 | extern vdev_ops_t vdev_indirect_ops; |
34dc7c2f BB |
506 | |
507 | /* | |
508 | * Common size functions | |
509 | */ | |
619f0976 GW |
510 | extern void vdev_default_xlate(vdev_t *vd, const range_seg_t *in, |
511 | range_seg_t *out); | |
34dc7c2f | 512 | extern uint64_t vdev_default_asize(vdev_t *vd, uint64_t psize); |
9babb374 BB |
513 | extern uint64_t vdev_get_min_asize(vdev_t *vd); |
514 | extern void vdev_set_min_asize(vdev_t *vd); | |
34dc7c2f BB |
515 | |
516 | /* | |
d3cc8b15 | 517 | * Global variables |
34dc7c2f | 518 | */ |
d2734cce | 519 | extern int vdev_standard_sm_blksz; |
d3cc8b15 | 520 | /* zdb uses this tunable, so it must be declared here to make lint happy. */ |
34dc7c2f BB |
521 | extern int zfs_vdev_cache_size; |
522 | ||
a1d477c2 MA |
523 | /* |
524 | * Functions from vdev_indirect.c | |
525 | */ | |
526 | extern void vdev_indirect_sync_obsolete(vdev_t *vd, dmu_tx_t *tx); | |
527 | extern boolean_t vdev_indirect_should_condense(vdev_t *vd); | |
528 | extern void spa_condense_indirect_start_sync(vdev_t *vd, dmu_tx_t *tx); | |
27f80e85 BB |
529 | extern int vdev_obsolete_sm_object(vdev_t *vd, uint64_t *sm_obj); |
530 | extern int vdev_obsolete_counts_are_precise(vdev_t *vd, boolean_t *are_precise); | |
a1d477c2 | 531 | |
d2734cce SD |
532 | /* |
533 | * Other miscellaneous functions | |
534 | */ | |
27f80e85 | 535 | int vdev_checkpoint_sm_object(vdev_t *vd, uint64_t *sm_obj); |
d2734cce | 536 | |
34dc7c2f BB |
537 | #ifdef __cplusplus |
538 | } | |
539 | #endif | |
540 | ||
541 | #endif /* _SYS_VDEV_IMPL_H */ |