]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/include/sys/vdev_impl.h
MFV 2.0-rc2
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / include / sys / vdev_impl.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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright (c) 2011, 2020 by Delphix. All rights reserved.
24  * Copyright (c) 2017, Intel Corporation.
25  */
26
27 #ifndef _SYS_VDEV_IMPL_H
28 #define _SYS_VDEV_IMPL_H
29
30 #include <sys/avl.h>
31 #include <sys/bpobj.h>
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>
39 #include <sys/vdev_indirect_mapping.h>
40 #include <sys/vdev_indirect_births.h>
41 #include <sys/vdev_rebuild.h>
42 #include <sys/vdev_removal.h>
43 #include <sys/zfs_ratelimit.h>
44
45 #ifdef  __cplusplus
46 extern "C" {
47 #endif
48
49 /*
50  * Virtual device descriptors.
51  *
52  * All storage pool operations go through the virtual device framework,
53  * which provides data replication and I/O scheduling.
54  */
55
56 /*
57  * Forward declarations that lots of things need.
58  */
59 typedef struct vdev_queue vdev_queue_t;
60 typedef struct vdev_cache vdev_cache_t;
61 typedef struct vdev_cache_entry vdev_cache_entry_t;
62 struct abd;
63
64 extern int zfs_vdev_queue_depth_pct;
65 extern int zfs_vdev_def_queue_depth;
66 extern uint32_t zfs_vdev_async_write_max_active;
67
68 /*
69  * Virtual device operations
70  */
71 typedef int     vdev_open_func_t(vdev_t *vd, uint64_t *size, uint64_t *max_size,
72     uint64_t *ashift, uint64_t *pshift);
73 typedef void    vdev_close_func_t(vdev_t *vd);
74 typedef uint64_t vdev_asize_func_t(vdev_t *vd, uint64_t psize);
75 typedef void    vdev_io_start_func_t(zio_t *zio);
76 typedef void    vdev_io_done_func_t(zio_t *zio);
77 typedef void    vdev_state_change_func_t(vdev_t *vd, int, int);
78 typedef boolean_t vdev_need_resilver_func_t(vdev_t *vd, uint64_t, size_t);
79 typedef void    vdev_hold_func_t(vdev_t *vd);
80 typedef void    vdev_rele_func_t(vdev_t *vd);
81
82 typedef void    vdev_remap_cb_t(uint64_t inner_offset, vdev_t *vd,
83     uint64_t offset, uint64_t size, void *arg);
84 typedef void    vdev_remap_func_t(vdev_t *vd, uint64_t offset, uint64_t size,
85     vdev_remap_cb_t callback, void *arg);
86 /*
87  * Given a target vdev, translates the logical range "in" to the physical
88  * range "res"
89  */
90 typedef void vdev_xlation_func_t(vdev_t *cvd, const range_seg64_t *in,
91     range_seg64_t *res);
92
93 typedef const struct vdev_ops {
94         vdev_open_func_t                *vdev_op_open;
95         vdev_close_func_t               *vdev_op_close;
96         vdev_asize_func_t               *vdev_op_asize;
97         vdev_io_start_func_t            *vdev_op_io_start;
98         vdev_io_done_func_t             *vdev_op_io_done;
99         vdev_state_change_func_t        *vdev_op_state_change;
100         vdev_need_resilver_func_t       *vdev_op_need_resilver;
101         vdev_hold_func_t                *vdev_op_hold;
102         vdev_rele_func_t                *vdev_op_rele;
103         vdev_remap_func_t               *vdev_op_remap;
104         /*
105          * For translating ranges from non-leaf vdevs (e.g. raidz) to leaves.
106          * Used when initializing vdevs. Isn't used by leaf ops.
107          */
108         vdev_xlation_func_t             *vdev_op_xlate;
109         char                            vdev_op_type[16];
110         boolean_t                       vdev_op_leaf;
111 } vdev_ops_t;
112
113 /*
114  * Virtual device properties
115  */
116 struct vdev_cache_entry {
117         struct abd      *ve_abd;
118         uint64_t        ve_offset;
119         clock_t         ve_lastused;
120         avl_node_t      ve_offset_node;
121         avl_node_t      ve_lastused_node;
122         uint32_t        ve_hits;
123         uint16_t        ve_missed_update;
124         zio_t           *ve_fill_io;
125 };
126
127 struct vdev_cache {
128         avl_tree_t      vc_offset_tree;
129         avl_tree_t      vc_lastused_tree;
130         kmutex_t        vc_lock;
131 };
132
133 typedef struct vdev_queue_class {
134         uint32_t        vqc_active;
135
136         /*
137          * Sorted by offset or timestamp, depending on if the queue is
138          * LBA-ordered vs FIFO.
139          */
140         avl_tree_t      vqc_queued_tree;
141 } vdev_queue_class_t;
142
143 struct vdev_queue {
144         vdev_t          *vq_vdev;
145         vdev_queue_class_t vq_class[ZIO_PRIORITY_NUM_QUEUEABLE];
146         avl_tree_t      vq_active_tree;
147         avl_tree_t      vq_read_offset_tree;
148         avl_tree_t      vq_write_offset_tree;
149         avl_tree_t      vq_trim_offset_tree;
150         uint64_t        vq_last_offset;
151         hrtime_t        vq_io_complete_ts; /* time last i/o completed */
152         hrtime_t        vq_io_delta_ts;
153         zio_t           vq_io_search; /* used as local for stack reduction */
154         kmutex_t        vq_lock;
155 };
156
157 typedef enum vdev_alloc_bias {
158         VDEV_BIAS_NONE,
159         VDEV_BIAS_LOG,          /* dedicated to ZIL data (SLOG) */
160         VDEV_BIAS_SPECIAL,      /* dedicated to ddt, metadata, and small blks */
161         VDEV_BIAS_DEDUP         /* dedicated to dedup metadata */
162 } vdev_alloc_bias_t;
163
164
165 /*
166  * On-disk indirect vdev state.
167  *
168  * An indirect vdev is described exclusively in the MOS config of a pool.
169  * The config for an indirect vdev includes several fields, which are
170  * accessed in memory by a vdev_indirect_config_t.
171  */
172 typedef struct vdev_indirect_config {
173         /*
174          * Object (in MOS) which contains the indirect mapping. This object
175          * contains an array of vdev_indirect_mapping_entry_phys_t ordered by
176          * vimep_src. The bonus buffer for this object is a
177          * vdev_indirect_mapping_phys_t. This object is allocated when a vdev
178          * removal is initiated.
179          *
180          * Note that this object can be empty if none of the data on the vdev
181          * has been copied yet.
182          */
183         uint64_t        vic_mapping_object;
184
185         /*
186          * Object (in MOS) which contains the birth times for the mapping
187          * entries. This object contains an array of
188          * vdev_indirect_birth_entry_phys_t sorted by vibe_offset. The bonus
189          * buffer for this object is a vdev_indirect_birth_phys_t. This object
190          * is allocated when a vdev removal is initiated.
191          *
192          * Note that this object can be empty if none of the vdev has yet been
193          * copied.
194          */
195         uint64_t        vic_births_object;
196
197         /*
198          * This is the vdev ID which was removed previous to this vdev, or
199          * UINT64_MAX if there are no previously removed vdevs.
200          */
201         uint64_t        vic_prev_indirect_vdev;
202 } vdev_indirect_config_t;
203
204 /*
205  * Virtual device descriptor
206  */
207 struct vdev {
208         /*
209          * Common to all vdev types.
210          */
211         uint64_t        vdev_id;        /* child number in vdev parent  */
212         uint64_t        vdev_guid;      /* unique ID for this vdev      */
213         uint64_t        vdev_guid_sum;  /* self guid + all child guids  */
214         uint64_t        vdev_orig_guid; /* orig. guid prior to remove   */
215         uint64_t        vdev_asize;     /* allocatable device capacity  */
216         uint64_t        vdev_min_asize; /* min acceptable asize         */
217         uint64_t        vdev_max_asize; /* max acceptable asize         */
218         uint64_t        vdev_ashift;    /* block alignment shift        */
219
220         /*
221          * Logical block alignment shift
222          *
223          * The smallest sized/aligned I/O supported by the device.
224          */
225         uint64_t        vdev_logical_ashift;
226         /*
227          * Physical block alignment shift
228          *
229          * The device supports logical I/Os with vdev_logical_ashift
230          * size/alignment, but optimum performance will be achieved by
231          * aligning/sizing requests to vdev_physical_ashift.  Smaller
232          * requests may be inflated or incur device level read-modify-write
233          * operations.
234          *
235          * May be 0 to indicate no preference (i.e. use vdev_logical_ashift).
236          */
237         uint64_t        vdev_physical_ashift;
238         uint64_t        vdev_state;     /* see VDEV_STATE_* #defines    */
239         uint64_t        vdev_prevstate; /* used when reopening a vdev   */
240         vdev_ops_t      *vdev_ops;      /* vdev operations              */
241         spa_t           *vdev_spa;      /* spa for this vdev            */
242         void            *vdev_tsd;      /* type-specific data           */
243         vdev_t          *vdev_top;      /* top-level vdev               */
244         vdev_t          *vdev_parent;   /* parent vdev                  */
245         vdev_t          **vdev_child;   /* array of children            */
246         uint64_t        vdev_children;  /* number of children           */
247         vdev_stat_t     vdev_stat;      /* virtual device statistics    */
248         vdev_stat_ex_t  vdev_stat_ex;   /* extended statistics          */
249         boolean_t       vdev_expanding; /* expand the vdev?             */
250         boolean_t       vdev_reopening; /* reopen in progress?          */
251         boolean_t       vdev_nonrot;    /* true if solid state          */
252         int             vdev_open_error; /* error on last open          */
253         kthread_t       *vdev_open_thread; /* thread opening children   */
254         uint64_t        vdev_crtxg;     /* txg when top-level was added */
255
256         /*
257          * Top-level vdev state.
258          */
259         uint64_t        vdev_ms_array;  /* metaslab array object        */
260         uint64_t        vdev_ms_shift;  /* metaslab size shift          */
261         uint64_t        vdev_ms_count;  /* number of metaslabs          */
262         metaslab_group_t *vdev_mg;      /* metaslab group               */
263         metaslab_t      **vdev_ms;      /* metaslab array               */
264         uint64_t        vdev_pending_fastwrite; /* allocated fastwrites */
265         txg_list_t      vdev_ms_list;   /* per-txg dirty metaslab lists */
266         txg_list_t      vdev_dtl_list;  /* per-txg dirty DTL lists      */
267         txg_node_t      vdev_txg_node;  /* per-txg dirty vdev linkage   */
268         boolean_t       vdev_remove_wanted; /* async remove wanted?     */
269         boolean_t       vdev_probe_wanted; /* async probe wanted?       */
270         list_node_t     vdev_config_dirty_node; /* config dirty list    */
271         list_node_t     vdev_state_dirty_node; /* state dirty list      */
272         uint64_t        vdev_deflate_ratio; /* deflation ratio (x512)   */
273         uint64_t        vdev_islog;     /* is an intent log device      */
274         uint64_t        vdev_removing;  /* device is being removed?     */
275         boolean_t       vdev_ishole;    /* is a hole in the namespace   */
276         uint64_t        vdev_top_zap;
277         vdev_alloc_bias_t vdev_alloc_bias; /* metaslab allocation bias  */
278
279         /* pool checkpoint related */
280         space_map_t     *vdev_checkpoint_sm;    /* contains reserved blocks */
281
282         /* Initialize related */
283         boolean_t       vdev_initialize_exit_wanted;
284         vdev_initializing_state_t       vdev_initialize_state;
285         list_node_t     vdev_initialize_node;
286         kthread_t       *vdev_initialize_thread;
287         /* Protects vdev_initialize_thread and vdev_initialize_state. */
288         kmutex_t        vdev_initialize_lock;
289         kcondvar_t      vdev_initialize_cv;
290         uint64_t        vdev_initialize_offset[TXG_SIZE];
291         uint64_t        vdev_initialize_last_offset;
292         range_tree_t    *vdev_initialize_tree;  /* valid while initializing */
293         uint64_t        vdev_initialize_bytes_est;
294         uint64_t        vdev_initialize_bytes_done;
295         uint64_t        vdev_initialize_action_time;    /* start and end time */
296
297         /* TRIM related */
298         boolean_t       vdev_trim_exit_wanted;
299         boolean_t       vdev_autotrim_exit_wanted;
300         vdev_trim_state_t       vdev_trim_state;
301         list_node_t     vdev_trim_node;
302         kmutex_t        vdev_autotrim_lock;
303         kcondvar_t      vdev_autotrim_cv;
304         kthread_t       *vdev_autotrim_thread;
305         /* Protects vdev_trim_thread and vdev_trim_state. */
306         kmutex_t        vdev_trim_lock;
307         kcondvar_t      vdev_trim_cv;
308         kthread_t       *vdev_trim_thread;
309         uint64_t        vdev_trim_offset[TXG_SIZE];
310         uint64_t        vdev_trim_last_offset;
311         uint64_t        vdev_trim_bytes_est;
312         uint64_t        vdev_trim_bytes_done;
313         uint64_t        vdev_trim_rate;         /* requested rate (bytes/sec) */
314         uint64_t        vdev_trim_partial;      /* requested partial TRIM */
315         uint64_t        vdev_trim_secure;       /* requested secure TRIM */
316         uint64_t        vdev_trim_action_time;  /* start and end time */
317
318         /* Rebuild related */
319         boolean_t       vdev_rebuilding;
320         boolean_t       vdev_rebuild_exit_wanted;
321         boolean_t       vdev_rebuild_cancel_wanted;
322         boolean_t       vdev_rebuild_reset_wanted;
323         kmutex_t        vdev_rebuild_lock;
324         kcondvar_t      vdev_rebuild_cv;
325         kthread_t       *vdev_rebuild_thread;
326         vdev_rebuild_t  vdev_rebuild_config;
327
328         /* For limiting outstanding I/Os (initialize, TRIM, rebuild) */
329         kmutex_t        vdev_initialize_io_lock;
330         kcondvar_t      vdev_initialize_io_cv;
331         uint64_t        vdev_initialize_inflight;
332         kmutex_t        vdev_trim_io_lock;
333         kcondvar_t      vdev_trim_io_cv;
334         uint64_t        vdev_trim_inflight[3];
335         kmutex_t        vdev_rebuild_io_lock;
336         kcondvar_t      vdev_rebuild_io_cv;
337         uint64_t        vdev_rebuild_inflight;
338
339         /*
340          * Values stored in the config for an indirect or removing vdev.
341          */
342         vdev_indirect_config_t  vdev_indirect_config;
343
344         /*
345          * The vdev_indirect_rwlock protects the vdev_indirect_mapping
346          * pointer from changing on indirect vdevs (when it is condensed).
347          * Note that removing (not yet indirect) vdevs have different
348          * access patterns (the mapping is not accessed from open context,
349          * e.g. from zio_read) and locking strategy (e.g. svr_lock).
350          */
351         krwlock_t vdev_indirect_rwlock;
352         vdev_indirect_mapping_t *vdev_indirect_mapping;
353         vdev_indirect_births_t *vdev_indirect_births;
354
355         /*
356          * In memory data structures used to manage the obsolete sm, for
357          * indirect or removing vdevs.
358          *
359          * The vdev_obsolete_segments is the in-core record of the segments
360          * that are no longer referenced anywhere in the pool (due to
361          * being freed or remapped and not referenced by any snapshots).
362          * During a sync, segments are added to vdev_obsolete_segments
363          * via vdev_indirect_mark_obsolete(); at the end of each sync
364          * pass, this is appended to vdev_obsolete_sm via
365          * vdev_indirect_sync_obsolete().  The vdev_obsolete_lock
366          * protects against concurrent modifications of vdev_obsolete_segments
367          * from multiple zio threads.
368          */
369         kmutex_t        vdev_obsolete_lock;
370         range_tree_t    *vdev_obsolete_segments;
371         space_map_t     *vdev_obsolete_sm;
372
373         /*
374          * Protects the vdev_scan_io_queue field itself as well as the
375          * structure's contents (when present).
376          */
377         kmutex_t                        vdev_scan_io_queue_lock;
378         struct dsl_scan_io_queue        *vdev_scan_io_queue;
379
380         /*
381          * Leaf vdev state.
382          */
383         range_tree_t    *vdev_dtl[DTL_TYPES]; /* dirty time logs        */
384         space_map_t     *vdev_dtl_sm;   /* dirty time log space map     */
385         txg_node_t      vdev_dtl_node;  /* per-txg dirty DTL linkage    */
386         uint64_t        vdev_dtl_object; /* DTL object                  */
387         uint64_t        vdev_psize;     /* physical device capacity     */
388         uint64_t        vdev_wholedisk; /* true if this is a whole disk */
389         uint64_t        vdev_offline;   /* persistent offline state     */
390         uint64_t        vdev_faulted;   /* persistent faulted state     */
391         uint64_t        vdev_degraded;  /* persistent degraded state    */
392         uint64_t        vdev_removed;   /* persistent removed state     */
393         uint64_t        vdev_resilver_txg; /* persistent resilvering state */
394         uint64_t        vdev_rebuild_txg; /* persistent rebuilding state */
395         uint64_t        vdev_nparity;   /* number of parity devices for raidz */
396         char            *vdev_path;     /* vdev path (if any)           */
397         char            *vdev_devid;    /* vdev devid (if any)          */
398         char            *vdev_physpath; /* vdev device path (if any)    */
399         char            *vdev_enc_sysfs_path;   /* enclosure sysfs path */
400         char            *vdev_fru;      /* physical FRU location        */
401         uint64_t        vdev_not_present; /* not present during import  */
402         uint64_t        vdev_unspare;   /* unspare when resilvering done */
403         boolean_t       vdev_nowritecache; /* true if flushwritecache failed */
404         boolean_t       vdev_has_trim;  /* TRIM is supported            */
405         boolean_t       vdev_has_securetrim; /* secure TRIM is supported */
406         boolean_t       vdev_checkremove; /* temporary online test      */
407         boolean_t       vdev_forcefault; /* force online fault          */
408         boolean_t       vdev_splitting; /* split or repair in progress  */
409         boolean_t       vdev_delayed_close; /* delayed device close?    */
410         boolean_t       vdev_tmpoffline; /* device taken offline temporarily? */
411         boolean_t       vdev_detached;  /* device detached?             */
412         boolean_t       vdev_cant_read; /* vdev is failing all reads    */
413         boolean_t       vdev_cant_write; /* vdev is failing all writes  */
414         boolean_t       vdev_isspare;   /* was a hot spare              */
415         boolean_t       vdev_isl2cache; /* was a l2cache device         */
416         boolean_t       vdev_copy_uberblocks;  /* post expand copy uberblocks */
417         boolean_t       vdev_resilver_deferred;  /* resilver deferred */
418         vdev_queue_t    vdev_queue;     /* I/O deadline schedule queue  */
419         vdev_cache_t    vdev_cache;     /* physical block cache         */
420         spa_aux_vdev_t  *vdev_aux;      /* for l2cache and spares vdevs */
421         zio_t           *vdev_probe_zio; /* root of current probe       */
422         vdev_aux_t      vdev_label_aux; /* on-disk aux state            */
423         uint64_t        vdev_leaf_zap;
424         hrtime_t        vdev_mmp_pending; /* 0 if write finished        */
425         uint64_t        vdev_mmp_kstat_id;      /* to find kstat entry */
426         uint64_t        vdev_expansion_time;    /* vdev's last expansion time */
427         list_node_t     vdev_leaf_node;         /* leaf vdev list */
428
429         /*
430          * For DTrace to work in userland (libzpool) context, these fields must
431          * remain at the end of the structure.  DTrace will use the kernel's
432          * CTF definition for 'struct vdev', and since the size of a kmutex_t is
433          * larger in userland, the offsets for the rest of the fields would be
434          * incorrect.
435          */
436         kmutex_t        vdev_dtl_lock;  /* vdev_dtl_{map,resilver}      */
437         kmutex_t        vdev_stat_lock; /* vdev_stat                    */
438         kmutex_t        vdev_probe_lock; /* protects vdev_probe_zio     */
439
440         /*
441          * We rate limit ZIO delay and ZIO checksum events, since they
442          * can flood ZED with tons of events when a drive is acting up.
443          */
444         zfs_ratelimit_t vdev_delay_rl;
445         zfs_ratelimit_t vdev_checksum_rl;
446 };
447
448 #define VDEV_RAIDZ_MAXPARITY    3
449
450 #define VDEV_PAD_SIZE           (8 << 10)
451 /* 2 padding areas (vl_pad1 and vl_be) to skip */
452 #define VDEV_SKIP_SIZE          VDEV_PAD_SIZE * 2
453 #define VDEV_PHYS_SIZE          (112 << 10)
454 #define VDEV_UBERBLOCK_RING     (128 << 10)
455
456 /*
457  * MMP blocks occupy the last MMP_BLOCKS_PER_LABEL slots in the uberblock
458  * ring when MMP is enabled.
459  */
460 #define MMP_BLOCKS_PER_LABEL    1
461
462 /* The largest uberblock we support is 8k. */
463 #define MAX_UBERBLOCK_SHIFT (13)
464 #define VDEV_UBERBLOCK_SHIFT(vd)        \
465         MIN(MAX((vd)->vdev_top->vdev_ashift, UBERBLOCK_SHIFT), \
466             MAX_UBERBLOCK_SHIFT)
467 #define VDEV_UBERBLOCK_COUNT(vd)        \
468         (VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT(vd))
469 #define VDEV_UBERBLOCK_OFFSET(vd, n)    \
470         offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT(vd)])
471 #define VDEV_UBERBLOCK_SIZE(vd)         (1ULL << VDEV_UBERBLOCK_SHIFT(vd))
472
473 typedef struct vdev_phys {
474         char            vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)];
475         zio_eck_t       vp_zbt;
476 } vdev_phys_t;
477
478 typedef enum vbe_vers {
479         /*
480          * The bootenv file is stored as ascii text in the envblock.
481          * It is used by the GRUB bootloader used on Linux to store the
482          * contents of the grubenv file. The file is stored as raw ASCII,
483          * and is protected by an embedded checksum. By default, GRUB will
484          * check if the boot filesystem supports storing the environment data
485          * in a special location, and if so, will invoke filesystem specific
486          * logic to retrieve it. This can be overriden by a variable, should
487          * the user so desire.
488          */
489         VB_RAW = 0,
490
491         /*
492          * The bootenv file is converted to an nvlist and then packed into the
493          * envblock.
494          */
495         VB_NVLIST = 1
496 } vbe_vers_t;
497
498 typedef struct vdev_boot_envblock {
499         uint64_t        vbe_version;
500         char            vbe_bootenv[VDEV_PAD_SIZE - sizeof (uint64_t) -
501                         sizeof (zio_eck_t)];
502         zio_eck_t       vbe_zbt;
503 } vdev_boot_envblock_t;
504
505 CTASSERT_GLOBAL(sizeof (vdev_boot_envblock_t) == VDEV_PAD_SIZE);
506
507 typedef struct vdev_label {
508         char            vl_pad1[VDEV_PAD_SIZE];                 /*  8K */
509         vdev_boot_envblock_t    vl_be;                          /*  8K */
510         vdev_phys_t     vl_vdev_phys;                           /* 112K */
511         char            vl_uberblock[VDEV_UBERBLOCK_RING];      /* 128K */
512 } vdev_label_t;                                         /* 256K total */
513
514 /*
515  * vdev_dirty() flags
516  */
517 #define VDD_METASLAB    0x01
518 #define VDD_DTL         0x02
519
520 /* Offset of embedded boot loader region on each label */
521 #define VDEV_BOOT_OFFSET        (2 * sizeof (vdev_label_t))
522 /*
523  * Size of embedded boot loader region on each label.
524  * The total size of the first two labels plus the boot area is 4MB.
525  */
526 #define VDEV_BOOT_SIZE          (7ULL << 19)                    /* 3.5M */
527
528 /*
529  * Size of label regions at the start and end of each leaf device.
530  */
531 #define VDEV_LABEL_START_SIZE   (2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE)
532 #define VDEV_LABEL_END_SIZE     (2 * sizeof (vdev_label_t))
533 #define VDEV_LABELS             4
534 #define VDEV_BEST_LABEL         VDEV_LABELS
535
536 #define VDEV_ALLOC_LOAD         0
537 #define VDEV_ALLOC_ADD          1
538 #define VDEV_ALLOC_SPARE        2
539 #define VDEV_ALLOC_L2CACHE      3
540 #define VDEV_ALLOC_ROOTPOOL     4
541 #define VDEV_ALLOC_SPLIT        5
542 #define VDEV_ALLOC_ATTACH       6
543
544 /*
545  * Allocate or free a vdev
546  */
547 extern vdev_t *vdev_alloc_common(spa_t *spa, uint_t id, uint64_t guid,
548     vdev_ops_t *ops);
549 extern int vdev_alloc(spa_t *spa, vdev_t **vdp, nvlist_t *config,
550     vdev_t *parent, uint_t id, int alloctype);
551 extern void vdev_free(vdev_t *vd);
552
553 /*
554  * Add or remove children and parents
555  */
556 extern void vdev_add_child(vdev_t *pvd, vdev_t *cvd);
557 extern void vdev_remove_child(vdev_t *pvd, vdev_t *cvd);
558 extern void vdev_compact_children(vdev_t *pvd);
559 extern vdev_t *vdev_add_parent(vdev_t *cvd, vdev_ops_t *ops);
560 extern void vdev_remove_parent(vdev_t *cvd);
561
562 /*
563  * vdev sync load and sync
564  */
565 extern boolean_t vdev_log_state_valid(vdev_t *vd);
566 extern int vdev_load(vdev_t *vd);
567 extern int vdev_dtl_load(vdev_t *vd);
568 extern void vdev_sync(vdev_t *vd, uint64_t txg);
569 extern void vdev_sync_done(vdev_t *vd, uint64_t txg);
570 extern void vdev_dirty(vdev_t *vd, int flags, void *arg, uint64_t txg);
571 extern void vdev_dirty_leaves(vdev_t *vd, int flags, uint64_t txg);
572
573 /*
574  * Available vdev types.
575  */
576 extern vdev_ops_t vdev_root_ops;
577 extern vdev_ops_t vdev_mirror_ops;
578 extern vdev_ops_t vdev_replacing_ops;
579 extern vdev_ops_t vdev_raidz_ops;
580 extern vdev_ops_t vdev_disk_ops;
581 extern vdev_ops_t vdev_file_ops;
582 extern vdev_ops_t vdev_missing_ops;
583 extern vdev_ops_t vdev_hole_ops;
584 extern vdev_ops_t vdev_spare_ops;
585 extern vdev_ops_t vdev_indirect_ops;
586
587 /*
588  * Common size functions
589  */
590 extern void vdev_default_xlate(vdev_t *vd, const range_seg64_t *in,
591     range_seg64_t *out);
592 extern uint64_t vdev_default_asize(vdev_t *vd, uint64_t psize);
593 extern uint64_t vdev_get_min_asize(vdev_t *vd);
594 extern void vdev_set_min_asize(vdev_t *vd);
595
596 /*
597  * Global variables
598  */
599 extern int zfs_vdev_standard_sm_blksz;
600 /* zdb uses this tunable, so it must be declared here to make lint happy. */
601 extern int zfs_vdev_cache_size;
602
603 /*
604  * Functions from vdev_indirect.c
605  */
606 extern void vdev_indirect_sync_obsolete(vdev_t *vd, dmu_tx_t *tx);
607 extern boolean_t vdev_indirect_should_condense(vdev_t *vd);
608 extern void spa_condense_indirect_start_sync(vdev_t *vd, dmu_tx_t *tx);
609 extern int vdev_obsolete_sm_object(vdev_t *vd, uint64_t *sm_obj);
610 extern int vdev_obsolete_counts_are_precise(vdev_t *vd, boolean_t *are_precise);
611
612 /*
613  * Other miscellaneous functions
614  */
615 int vdev_checkpoint_sm_object(vdev_t *vd, uint64_t *sm_obj);
616
617 /*
618  * Vdev ashift optimization tunables
619  */
620 extern uint64_t zfs_vdev_min_auto_ashift;
621 extern uint64_t zfs_vdev_max_auto_ashift;
622 int param_set_min_auto_ashift(ZFS_MODULE_PARAM_ARGS);
623 int param_set_max_auto_ashift(ZFS_MODULE_PARAM_ARGS);
624
625 #ifdef  __cplusplus
626 }
627 #endif
628
629 #endif  /* _SYS_VDEV_IMPL_H */