xref: /freebsd/sys/contrib/openzfs/include/sys/spa_impl.h (revision 34f9f5680c9d5d5138e427ba3aeab0138cec3882)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * https://opensource.org/license/CDDL-1.0.
11  */
12 /*
13  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
14  * Copyright (c) 2011, 2024 by Delphix. All rights reserved.
15  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
16  * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
17  * Copyright 2013 Saso Kiselkov. All rights reserved.
18  * Copyright (c) 2016 Actifio, Inc. All rights reserved.
19  * Copyright (c) 2017, Intel Corporation.
20  * Copyright (c) 2019 Datto Inc.
21  * Copyright (c) 2024-2026, Klara, Inc.
22  * Copyright (c) 2026, TrueNAS.
23  */
24 
25 #ifndef _SYS_SPA_IMPL_H
26 #define	_SYS_SPA_IMPL_H
27 
28 #include <sys/spa.h>
29 #include <sys/spa_checkpoint.h>
30 #include <sys/spa_log_spacemap.h>
31 #include <sys/vdev.h>
32 #include <sys/vdev_rebuild.h>
33 #include <sys/vdev_removal.h>
34 #include <sys/vdev_raidz.h>
35 #include <sys/metaslab.h>
36 #include <sys/dmu.h>
37 #include <sys/dsl_pool.h>
38 #include <sys/uberblock_impl.h>
39 #include <sys/zfs_context.h>
40 #include <sys/avl.h>
41 #include <sys/zfs_refcount.h>
42 #include <sys/bplist.h>
43 #include <sys/bpobj.h>
44 #include <sys/dsl_crypt.h>
45 #include <sys/zfeature.h>
46 #include <sys/zthr.h>
47 #include <sys/arc_impl.h>
48 #include <sys/dsl_deadlist.h>
49 #include <zfeature_common.h>
50 
51 #include "zfs_crrd.h"
52 
53 #ifdef	__cplusplus
54 extern "C" {
55 #endif
56 
57 typedef struct spa_allocs_use {
58 	kmutex_t	sau_lock;
59 	uint_t		sau_rotor;
60 	boolean_t	sau_inuse[];
61 } spa_allocs_use_t;
62 
63 typedef struct spa_error_entry {
64 	zbookmark_phys_t	se_bookmark;
65 	char			*se_name;
66 	avl_node_t		se_avl;
67 	zbookmark_err_phys_t	se_zep;		/* not accounted in avl_find */
68 } spa_error_entry_t;
69 
70 typedef struct spa_history_phys {
71 	uint64_t sh_pool_create_len;	/* ending offset of zpool create */
72 	uint64_t sh_phys_max_off;	/* physical EOF */
73 	uint64_t sh_bof;		/* logical BOF */
74 	uint64_t sh_eof;		/* logical EOF */
75 	uint64_t sh_records_lost;	/* num of records overwritten */
76 } spa_history_phys_t;
77 
78 /*
79  * All members must be uint64_t, for byteswap purposes.
80  */
81 typedef struct spa_removing_phys {
82 	uint64_t sr_state; /* dsl_scan_state_t */
83 
84 	/*
85 	 * The vdev ID that we most recently attempted to remove,
86 	 * or -1 if no removal has been attempted.
87 	 */
88 	uint64_t sr_removing_vdev;
89 
90 	/*
91 	 * The vdev ID that we most recently successfully removed,
92 	 * or -1 if no devices have been removed.
93 	 */
94 	uint64_t sr_prev_indirect_vdev;
95 
96 	uint64_t sr_start_time;
97 	uint64_t sr_end_time;
98 
99 	/*
100 	 * Note that we can not use the space map's or indirect mapping's
101 	 * accounting as a substitute for these values, because we need to
102 	 * count frees of not-yet-copied data as though it did the copy.
103 	 * Otherwise, we could get into a situation where copied > to_copy,
104 	 * or we complete before copied == to_copy.
105 	 */
106 	uint64_t sr_to_copy; /* bytes that need to be copied */
107 	uint64_t sr_copied; /* bytes that have been copied or freed */
108 } spa_removing_phys_t;
109 
110 /*
111  * This struct is stored as an entry in the DMU_POOL_DIRECTORY_OBJECT
112  * (with key DMU_POOL_CONDENSING_INDIRECT).  It is present if a condense
113  * of an indirect vdev's mapping object is in progress.
114  */
115 typedef struct spa_condensing_indirect_phys {
116 	/*
117 	 * The vdev ID of the indirect vdev whose indirect mapping is
118 	 * being condensed.
119 	 */
120 	uint64_t	scip_vdev;
121 
122 	/*
123 	 * The vdev's old obsolete spacemap.  This spacemap's contents are
124 	 * being integrated into the new mapping.
125 	 */
126 	uint64_t	scip_prev_obsolete_sm_object;
127 
128 	/*
129 	 * The new mapping object that is being created.
130 	 */
131 	uint64_t	scip_next_mapping_object;
132 } spa_condensing_indirect_phys_t;
133 
134 struct spa_aux_vdev {
135 	uint64_t	sav_object;		/* MOS object for device list */
136 	nvlist_t	*sav_config;		/* cached device config */
137 	vdev_t		**sav_vdevs;		/* devices */
138 	int		sav_count;		/* number devices */
139 	boolean_t	sav_sync;		/* sync the device list */
140 	boolean_t	sav_label_sync;		/* sync aux labels */
141 	nvlist_t	**sav_pending;		/* pending device additions */
142 	uint_t		sav_npending;		/* # pending devices */
143 };
144 
145 /*
146  * scl_count holds the reference count plus SCL_COUNT_WRITER, so that a reader
147  * can take a reference and check for a writer in one atomic operation.
148  */
149 typedef struct spa_config_lock {
150 	kmutex_t	scl_lock;
151 	kthread_t	*scl_writer;
152 	int		scl_write_wanted;
153 	uint32_t	scl_count;
154 	kcondvar_t	scl_cv;
155 } ____cacheline_aligned spa_config_lock_t;
156 
157 typedef struct spa_config_dirent {
158 	list_node_t	scd_link;
159 	char		*scd_path;
160 } spa_config_dirent_t;
161 
162 typedef enum zio_taskq_type {
163 	ZIO_TASKQ_ISSUE = 0,
164 	ZIO_TASKQ_ISSUE_HIGH,
165 	ZIO_TASKQ_INTERRUPT,
166 	ZIO_TASKQ_INTERRUPT_HIGH,
167 	ZIO_TASKQ_TYPES
168 } zio_taskq_type_t;
169 
170 /*
171  * State machine for the zpool-poolname process.  The states transitions
172  * are done as follows:
173  *
174  *	From		   To			Routine
175  *	PROC_NONE	-> PROC_CREATED		spa_activate()
176  *	PROC_CREATED	-> PROC_ACTIVE		spa_thread()
177  *	PROC_ACTIVE	-> PROC_DEACTIVATE	spa_deactivate()
178  *	PROC_DEACTIVATE	-> PROC_GONE		spa_thread()
179  *	PROC_GONE	-> PROC_NONE		spa_deactivate()
180  */
181 typedef enum spa_proc_state {
182 	SPA_PROC_NONE,		/* spa_proc = &p0, no process created */
183 	SPA_PROC_CREATED,	/* spa_activate() has proc, is waiting */
184 	SPA_PROC_ACTIVE,	/* taskqs created, spa_proc set */
185 	SPA_PROC_DEACTIVATE,	/* spa_deactivate() requests process exit */
186 	SPA_PROC_GONE		/* spa_thread() is exiting, spa_proc = &p0 */
187 } spa_proc_state_t;
188 
189 typedef struct spa_taskqs {
190 	uint_t stqs_count;
191 	taskq_t **stqs_taskq;
192 } spa_taskqs_t;
193 
194 /* one for each thread in the spa sync taskq */
195 typedef struct spa_syncthread_info {
196 	kthread_t	*sti_thread;
197 	uint_t		sti_allocator;
198 } spa_syncthread_info_t;
199 
200 typedef enum spa_all_vdev_zap_action {
201 	AVZ_ACTION_NONE = 0,
202 	AVZ_ACTION_DESTROY,	/* Destroy all per-vdev ZAPs and the AVZ. */
203 	AVZ_ACTION_REBUILD,	/* Populate the new AVZ, see spa_avz_rebuild */
204 	AVZ_ACTION_INITIALIZE
205 } spa_avz_action_t;
206 
207 typedef enum spa_config_source {
208 	SPA_CONFIG_SRC_NONE = 0,
209 	SPA_CONFIG_SRC_SCAN,		/* scan of path (default: /dev/dsk) */
210 	SPA_CONFIG_SRC_CACHEFILE,	/* any cachefile */
211 	SPA_CONFIG_SRC_TRYIMPORT,	/* returned from call to tryimport */
212 	SPA_CONFIG_SRC_SPLIT,		/* new pool in a pool split */
213 	SPA_CONFIG_SRC_MOS		/* MOS, but not always from right txg */
214 } spa_config_source_t;
215 
216 typedef enum spa_condense_type {
217 	SPA_CONDENSE_LOG_SPACEMAP = 0,
218 #ifdef ZFS_DEBUG
219 	SPA_CONDENSE_DEBUG,
220 #endif
221 	SPA_CONDENSE_TYPES
222 } spa_condense_type_t;
223 
224 typedef struct spa_condense_stat {
225 	uint64_t scns_start_time;	/* time_t */
226 	uint64_t scns_end_time;		/* time_t */
227 	uint64_t scns_processed;	/* items processed */
228 	uint64_t scns_total;		/* total items to process */
229 } spa_condense_stat_t;
230 
231 
232 struct spa {
233 	/*
234 	 * Fields protected by spa_namespace_lock.
235 	 */
236 	char		spa_name[ZFS_MAX_DATASET_NAME_LEN];	/* pool name */
237 	char		*spa_load_name;		/* unmodified pool name */
238 	char		*spa_comment;		/* comment */
239 	avl_node_t	spa_avl;		/* node in spa_namespace_avl */
240 	nvlist_t	*spa_config;		/* last synced config */
241 	nvlist_t	*spa_config_syncing;	/* currently syncing config */
242 	nvlist_t	*spa_config_splitting;	/* config for splitting */
243 	nvlist_t	*spa_load_info;		/* info and errors from load */
244 	nvlist_t	*spa_create_info;	/* info from create */
245 	uint64_t	spa_config_txg;		/* txg of last config change */
246 	uint32_t	spa_sync_pass;		/* iterate-to-convergence */
247 	pool_state_t	spa_state;		/* pool state */
248 	int		spa_inject_ref;		/* injection references */
249 	uint8_t		spa_sync_on;		/* sync threads are running */
250 	spa_load_state_t spa_load_state;	/* current load operation */
251 	boolean_t	spa_indirect_vdevs_loaded; /* mappings loaded? */
252 	boolean_t	spa_trust_config;	/* do we trust vdev tree? */
253 	boolean_t	spa_is_splitting;	/* in the middle of a split? */
254 	spa_config_source_t spa_config_source;	/* where config comes from? */
255 	uint64_t	spa_import_flags;	/* import specific flags */
256 	spa_taskqs_t	spa_zio_taskq[ZIO_TYPES][ZIO_TASKQ_TYPES];
257 	dsl_pool_t	*spa_dsl_pool;
258 	boolean_t	spa_is_initializing;	/* true while opening pool */
259 	boolean_t	spa_is_exporting;	/* true while exporting pool */
260 	kthread_t	*spa_export_thread;	/* valid during pool export */
261 	kthread_t	*spa_load_thread;	/* loading, no namespace lock */
262 	metaslab_class_t *spa_normal_class;	/* normal data class */
263 	metaslab_class_t *spa_log_class;	/* intent log data class */
264 	metaslab_class_t *spa_embedded_log_class; /* log on normal vdevs */
265 	metaslab_class_t *spa_special_class;	/* special allocation class */
266 	metaslab_class_t *spa_special_embedded_log_class; /* log on special */
267 	metaslab_class_t *spa_dedup_class;	/* dedup allocation class */
268 	uint64_t	spa_first_txg;		/* first txg after spa_open() */
269 	uint64_t	spa_final_txg;		/* txg of export/destroy */
270 	uint64_t	spa_freeze_txg;		/* freeze pool at this txg */
271 	uint64_t	spa_load_max_txg;	/* best initial ub_txg */
272 	uint64_t	spa_claim_max_txg;	/* highest claimed birth txg */
273 	inode_timespec_t spa_loaded_ts;		/* 1st successful open time */
274 	objset_t	*spa_meta_objset;	/* copy of dp->dp_meta_objset */
275 	kmutex_t	spa_evicting_os_lock;	/* Evicting objset list lock */
276 	list_t		spa_evicting_os_list;	/* Objsets being evicted. */
277 	kcondvar_t	spa_evicting_os_cv;	/* Objset Eviction Completion */
278 	txg_list_t	spa_vdev_txg_list;	/* per-txg dirty vdev list */
279 	vdev_t		*spa_root_vdev;		/* top-level vdev container */
280 	uint64_t	spa_min_ashift;		/* of vdevs in normal class */
281 	uint64_t	spa_max_ashift;		/* of vdevs in normal class */
282 	uint64_t	spa_min_alloc;		/* of vdevs in normal class */
283 	uint64_t	spa_max_alloc;		/* of vdevs in normal class */
284 	uint64_t	spa_gcd_alloc;		/* of vdevs in normal class */
285 	uint64_t	spa_config_guid;	/* config pool guid */
286 	uint64_t	spa_load_guid;		/* spa_load initialized guid */
287 	uint64_t	spa_last_synced_guid;	/* last synced guid */
288 	list_t		spa_config_dirty_list;	/* vdevs with dirty config */
289 	list_t		spa_state_dirty_list;	/* vdevs with dirty state */
290 	spa_allocs_use_t *spa_allocs_use;
291 	int		spa_alloc_count;
292 	int		spa_active_allocator;	/* selectable allocator */
293 
294 	/* per-allocator sync thread taskqs */
295 	taskq_t		*spa_sync_tq;
296 	spa_syncthread_info_t *spa_syncthreads;
297 
298 	spa_aux_vdev_t	spa_spares;		/* hot spares */
299 	spa_aux_vdev_t	spa_l2cache;		/* L2ARC cache devices */
300 	boolean_t	spa_aux_sync_uber;	/* need to sync aux uber */
301 	l2arc_info_t	spa_l2arc_info;		/* L2ARC state and stats */
302 	nvlist_t	*spa_label_features;	/* Features for reading MOS */
303 	uint64_t	spa_config_object;	/* MOS object for pool config */
304 	uint64_t	spa_config_generation;	/* config generation number */
305 	uint64_t	spa_syncing_txg;	/* txg currently syncing */
306 	bpobj_t		spa_deferred_bpobj;	/* deferred-free bplist */
307 	bplist_t	spa_free_bplist[TXG_SIZE]; /* bplist of stuff to free */
308 	zio_cksum_salt_t spa_cksum_salt;	/* secret salt for cksum */
309 	/* checksum context templates */
310 	kmutex_t	spa_cksum_tmpls_lock;
311 	void		*spa_cksum_tmpls[ZIO_CHECKSUM_FUNCTIONS];
312 	uberblock_t	spa_ubsync;		/* last synced uberblock */
313 	uberblock_t	spa_uberblock;		/* current uberblock */
314 	boolean_t	spa_activity_check; 	/* activity check required */
315 	boolean_t	spa_extreme_rewind;	/* rewind past deferred frees */
316 	kmutex_t	spa_scrub_lock;		/* resilver/scrub lock */
317 	uint64_t	spa_scrub_inflight;	/* in-flight scrub bytes */
318 
319 	/* in-flight verification bytes */
320 	uint64_t	spa_load_verify_bytes;
321 	kcondvar_t	spa_scrub_io_cv;	/* scrub I/O completion */
322 	uint8_t		spa_scrub_active;	/* active or suspended? */
323 	uint8_t		spa_scrub_type;		/* type of scrub we're doing */
324 	uint8_t		spa_scrub_finished;	/* indicator to rotate logs */
325 	uint8_t		spa_scrub_started;	/* started since last boot */
326 	uint8_t		spa_scrub_reopen;	/* scrub doing vdev_reopen */
327 	uint64_t	spa_scan_pass_start;	/* start time per pass/reboot */
328 	uint64_t	spa_scan_pass_scrub_pause; /* scrub pause time */
329 	uint64_t	spa_scan_pass_scrub_spent_paused; /* total paused */
330 	uint64_t	spa_scan_pass_exam;	/* examined bytes per pass */
331 	uint64_t	spa_scan_pass_issued;	/* issued bytes per pass */
332 	uint64_t	spa_scrubbed_last_txg;	/* last txg scrubbed */
333 
334 	/* error scrub pause time in milliseconds */
335 	uint64_t	spa_scan_pass_errorscrub_pause;
336 	/* total error scrub paused time in milliseconds */
337 	uint64_t	spa_scan_pass_errorscrub_spent_paused;
338 	/*
339 	 * We are in the middle of a resilver, and another resilver
340 	 * is needed once this one completes. This is set iff any
341 	 * vdev_resilver_deferred is set.
342 	 */
343 	boolean_t	spa_resilver_deferred;
344 	kmutex_t	spa_async_lock;		/* protect async state */
345 	kthread_t	*spa_async_thread;	/* thread doing async task */
346 	int		spa_async_suspended;	/* async tasks suspended */
347 	kcondvar_t	spa_async_cv;		/* wait for thread_exit() */
348 	uint32_t	spa_async_tasks;	/* async task mask */
349 	uint64_t	spa_missing_tvds;	/* unopenable tvds on load */
350 	uint64_t	spa_missing_tvds_allowed; /* allow loading spa? */
351 
352 	uint64_t	spa_nonallocating_dspace;
353 	spa_removing_phys_t spa_removing_phys;
354 	spa_vdev_removal_t *spa_vdev_removal;
355 
356 	spa_condensing_indirect_phys_t	spa_condensing_indirect_phys;
357 	spa_condensing_indirect_t	*spa_condensing_indirect;
358 	zthr_t		*spa_condense_zthr;	/* zthr doing condense. */
359 
360 	vdev_raidz_expand_t	*spa_raidz_expand;
361 	zthr_t		*spa_raidz_expand_zthr;
362 
363 	uint64_t	spa_checkpoint_txg;	/* the txg of the checkpoint */
364 	spa_checkpoint_info_t spa_checkpoint_info; /* checkpoint accounting */
365 	zthr_t		*spa_checkpoint_discard_zthr;
366 
367 	kmutex_t	spa_txg_log_time_lock;	/* for spa_txg_log_time */
368 	dbrrd_t		spa_txg_log_time;
369 	uint64_t	spa_last_noted_txg;
370 	uint64_t	spa_last_noted_txg_time;
371 	uint64_t	spa_last_flush_txg_time;
372 
373 	space_map_t	*spa_syncing_log_sm;	/* current log space map */
374 	avl_tree_t	spa_sm_logs_by_txg;
375 	kmutex_t	spa_flushed_ms_lock;	/* for metaslabs_by_flushed */
376 	avl_tree_t	spa_metaslabs_by_flushed;
377 	spa_unflushed_stats_t	spa_unflushed_stats;
378 	list_t		spa_log_summary;
379 	spa_log_flushall_mode_t	spa_log_flushall_mode;
380 	uint64_t	spa_log_flushall_txg;
381 
382 	zthr_t		*spa_livelist_delete_zthr; /* deleting livelists */
383 	zthr_t		*spa_livelist_condense_zthr; /* condensing livelists */
384 	uint64_t	spa_livelists_to_delete; /* set of livelists to free */
385 	livelist_condense_entry_t	spa_to_condense; /* next to condense */
386 
387 	char		*spa_root;		/* alternate root directory */
388 	uint64_t	spa_ena;		/* spa-wide ereport ENA */
389 	int		spa_last_open_failed;	/* error if last open failed */
390 	uint64_t	spa_last_ubsync_txg;	/* "best" uberblock txg */
391 	uint64_t	spa_last_ubsync_txg_ts;	/* timestamp from that ub */
392 	uint64_t	spa_load_txg;		/* ub txg that loaded */
393 	uint64_t	spa_load_txg_ts;	/* timestamp from that ub */
394 	uint64_t	spa_load_meta_errors;	/* verify metadata err count */
395 	uint64_t	spa_load_data_errors;	/* verify data err count */
396 	uint64_t	spa_verify_min_txg;	/* start txg of verify scrub */
397 	kmutex_t	spa_errlog_lock;	/* error log lock */
398 	uint64_t	spa_errlog_last;	/* last error log object */
399 	uint64_t	spa_errlog_scrub;	/* scrub error log object */
400 	kmutex_t	spa_errlist_lock;	/* error list/ereport lock */
401 	avl_tree_t	spa_errlist_last;	/* last error list */
402 	avl_tree_t	spa_errlist_scrub;	/* scrub error list */
403 	avl_tree_t	spa_errlist_healed;	/* list of healed blocks */
404 	uint64_t	spa_deflate;		/* should we deflate? */
405 	uint64_t	spa_history;		/* history object */
406 	kmutex_t	spa_history_lock;	/* history lock */
407 	vdev_t		*spa_pending_vdev;	/* pending vdev additions */
408 	kmutex_t	spa_props_lock;		/* property lock */
409 	uint64_t	spa_pool_props_object;	/* object for properties */
410 	uint64_t	spa_bootfs;		/* default boot filesystem */
411 	uint64_t	spa_failmode;		/* failure mode for the pool */
412 	uint64_t	spa_deadman_failmode;	/* failure mode for deadman */
413 	uint64_t	spa_delegation;		/* delegation on/off */
414 	list_t		spa_config_list;	/* previous cache file(s) */
415 	/* per-CPU array of root of async I/O: */
416 	zio_t		**spa_async_zio_root;
417 	zio_t		*spa_suspend_zio_root;	/* root of all suspended I/O */
418 	zio_t		*spa_txg_zio[TXG_SIZE]; /* spa_sync() waits for this */
419 	kmutex_t	spa_suspend_lock;	/* protects suspend_zio_root */
420 	kcondvar_t	spa_suspend_cv;		/* notification of resume */
421 	zio_suspend_reason_t	spa_suspended;	/* pool is suspended */
422 	uint8_t		spa_claiming;		/* pool is doing zil_claim() */
423 	boolean_t	spa_is_root;		/* pool is root */
424 	int		spa_minref;		/* num refs when first opened */
425 	spa_mode_t	spa_mode;		/* SPA_MODE_{READ|WRITE} */
426 	boolean_t	spa_read_spacemaps;	/* spacemaps available if ro */
427 	spa_log_state_t spa_log_state;		/* log state */
428 	uint64_t	spa_autoexpand;		/* lun expansion on/off */
429 	ddt_t		*spa_ddt[ZIO_CHECKSUM_FUNCTIONS]; /* in-core DDTs */
430 	uint64_t	spa_ddt_stat_object;	/* DDT statistics */
431 	uint64_t	spa_dedup_dspace;	/* Cache get_dedup_dspace() */
432 	uint64_t	spa_dedup_checksum;	/* default dedup checksum */
433 	uint64_t	spa_dspace;		/* dspace in normal class */
434 	uint64_t	spa_rdspace;		/* raw (non-dedup) --//-- */
435 	boolean_t	spa_active_ddt_prune;	/* ddt prune process active */
436 	brt_vdev_t	**spa_brt_vdevs;	/* array of per-vdev BRTs */
437 	uint64_t	spa_brt_nvdevs;		/* number of vdevs in BRT */
438 	brt_dedup_shard_t *spa_brt_dedup;	/* pending dedup'd clones */
439 	uint64_t	spa_brt_rangesize;	/* pool's BRT range size */
440 	krwlock_t	spa_brt_lock;		/* Protects brt_vdevs/nvdevs */
441 	kmutex_t	spa_vdev_top_lock;	/* dueling offline/remove */
442 	kmutex_t	spa_proc_lock;		/* protects spa_proc* */
443 	kcondvar_t	spa_proc_cv;		/* spa_proc_state transitions */
444 	spa_proc_state_t spa_proc_state;	/* see definition */
445 	proc_t		*spa_proc;		/* "zpool-poolname" process */
446 	uintptr_t	spa_did;		/* if procp != p0, did of t1 */
447 	boolean_t	spa_autoreplace;	/* autoreplace set in open */
448 	int		spa_vdev_locks;		/* locks grabbed */
449 	uint64_t	spa_creation_version;	/* version at pool creation */
450 	uint64_t	spa_prev_software_version; /* See ub_software_version */
451 	uint64_t	spa_feat_for_write_obj;	/* required to write to pool */
452 	uint64_t	spa_feat_for_read_obj;	/* required to read from pool */
453 	uint64_t	spa_feat_desc_obj;	/* Feature descriptions */
454 	uint64_t	spa_feat_enabled_txg_obj; /* Feature enabled txg */
455 	kmutex_t	spa_feat_stats_lock;	/* protects spa_feat_stats */
456 	nvlist_t	*spa_feat_stats;	/* Cache of enabled features */
457 	/* cache feature refcounts */
458 	uint64_t	spa_feat_refcount_cache[SPA_FEATURES];
459 	taskqid_t	spa_deadman_tqid;	/* Task id */
460 	uint64_t	spa_deadman_calls;	/* number of deadman calls */
461 	hrtime_t	spa_sync_starttime;	/* starting time of spa_sync */
462 	uint64_t	spa_deadman_synctime;	/* deadman sync expiration */
463 	uint64_t	spa_deadman_ziotime;	/* deadman zio expiration */
464 	uint64_t	spa_all_vdev_zaps;	/* ZAP of per-vd ZAP obj #s */
465 	spa_avz_action_t	spa_avz_action;	/* destroy/rebuild AVZ? */
466 	uint64_t	spa_autotrim;		/* automatic background trim? */
467 	uint64_t	spa_errata;		/* errata issues detected */
468 	spa_stats_t	spa_stats;		/* assorted spa statistics */
469 	spa_keystore_t	spa_keystore;		/* loaded crypto keys */
470 
471 	/* arc_memory_throttle() parameters during low memory condition */
472 	uint64_t	spa_lowmem_page_load;	/* memory load during txg */
473 	uint64_t	spa_lowmem_last_txg;	/* txg window start */
474 
475 	hrtime_t	spa_ccw_fail_time;	/* Conf cache write fail time */
476 	taskq_t		*spa_zvol_taskq;	/* Taskq for minor management */
477 	taskq_t		*spa_metaslab_taskq;	/* Taskq for metaslab preload */
478 	taskq_t		*spa_prefetch_taskq;	/* Taskq for prefetch threads */
479 	taskq_t		*spa_upgrade_taskq;	/* Taskq for upgrade jobs */
480 	uint64_t	spa_multihost;		/* multihost aware (mmp) */
481 	mmp_thread_t	spa_mmp;		/* multihost mmp thread */
482 	list_t		spa_leaf_list;		/* list of leaf vdevs */
483 	uint64_t	spa_leaf_list_gen;	/* track leaf_list changes */
484 	uint32_t	spa_hostid;		/* cached system hostid */
485 
486 	/* synchronization for threads in spa_wait */
487 	kmutex_t	spa_activities_lock;
488 	kcondvar_t	spa_activities_cv;
489 	kcondvar_t	spa_waiters_cv;
490 	int		spa_waiters;		/* number of waiting threads */
491 	boolean_t	spa_waiters_cancel;	/* waiters should return */
492 
493 	char		*spa_compatibility;	/* compatibility file(s) */
494 	uint64_t	spa_dedup_table_quota;	/* property DDT maximum size */
495 	uint64_t	spa_dedup_dsize;	/* cached on-disk size of DDT */
496 	uint64_t	spa_dedup_class_full_txg; /* txg dedup class was full */
497 
498 	/* stats for user-initiated condense operations */
499 	spa_condense_stat_t	spa_condense_stats[SPA_CONDENSE_TYPES];
500 	kmutex_t		spa_condense_stats_lock;
501 
502 #ifdef ZFS_DEBUG
503 	/* see spa_condense_debug_task() */
504 	taskqid_t	spa_condense_debug_tqid;
505 #endif
506 
507 	/*
508 	 * spa_refcount & spa_config_lock must be the last elements
509 	 * because zfs_refcount_t changes size based on compilation options.
510 	 * In order for the MDB module to function correctly, the other
511 	 * fields must remain in the same location.
512 	 */
513 	spa_config_lock_t spa_config_lock[SCL_LOCKS]; /* config changes */
514 	zfs_refcount_t	spa_refcount;		/* number of opens */
515 };
516 
517 extern char *spa_config_path;
518 extern const char *zfs_deadman_failmode;
519 extern uint_t spa_slop_shift;
520 extern void spa_taskq_dispatch(spa_t *spa, zio_type_t t, zio_taskq_type_t q,
521     task_func_t *func, zio_t *zio, boolean_t cutinline);
522 extern void spa_load_spares(spa_t *spa);
523 extern void spa_load_l2cache(spa_t *spa);
524 extern sysevent_t *spa_event_create(spa_t *spa, vdev_t *vd, nvlist_t *hist_nvl,
525     const char *name);
526 extern void spa_event_post(sysevent_t *ev);
527 extern int param_set_deadman_failmode_common(const char *val);
528 extern void spa_set_deadman_synctime(hrtime_t ns);
529 extern void spa_set_deadman_ziotime(hrtime_t ns);
530 extern const char *spa_history_zone(void);
531 extern const char *zfs_active_allocator;
532 extern int param_set_active_allocator_common(const char *val);
533 
534 #ifdef	__cplusplus
535 }
536 #endif
537 
538 #endif	/* _SYS_SPA_IMPL_H */
539