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.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
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]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2011, 2019 by Delphix. All rights reserved.
24 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
25 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
26 * Copyright 2013 Saso Kiselkov. All rights reserved.
27 * Copyright (c) 2017 Datto Inc.
28 * Copyright (c) 2017, Intel Corporation.
29 * Copyright (c) 2019, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
30 * Copyright (c) 2023, Klara Inc.
33 #include <sys/zfs_context.h>
34 #include <sys/zfs_chksum.h>
35 #include <sys/spa_impl.h>
37 #include <sys/zio_checksum.h>
38 #include <sys/zio_compress.h>
40 #include <sys/dmu_tx.h>
43 #include <sys/vdev_impl.h>
44 #include <sys/vdev_initialize.h>
45 #include <sys/vdev_trim.h>
46 #include <sys/vdev_file.h>
47 #include <sys/vdev_raidz.h>
48 #include <sys/metaslab.h>
49 #include <sys/uberblock_impl.h>
52 #include <sys/unique.h>
53 #include <sys/dsl_pool.h>
54 #include <sys/dsl_dir.h>
55 #include <sys/dsl_prop.h>
56 #include <sys/fm/util.h>
57 #include <sys/dsl_scan.h>
58 #include <sys/fs/zfs.h>
59 #include <sys/metaslab_impl.h>
63 #include <sys/kstat.h>
65 #include <sys/btree.h>
66 #include <sys/zfeature.h>
68 #include <sys/zstd/zstd.h>
73 * There are three basic locks for managing spa_t structures:
75 * spa_namespace_lock (global mutex)
77 * This lock must be acquired to do any of the following:
79 * - Lookup a spa_t by name
80 * - Add or remove a spa_t from the namespace
81 * - Increase spa_refcount from non-zero
82 * - Check if spa_refcount is zero
84 * - add/remove/attach/detach devices
85 * - Held for the duration of create/destroy/import/export
87 * It does not need to handle recursion. A create or destroy may
88 * reference objects (files or zvols) in other pools, but by
89 * definition they must have an existing reference, and will never need
90 * to lookup a spa_t by name.
92 * spa_refcount (per-spa zfs_refcount_t protected by mutex)
94 * This reference count keep track of any active users of the spa_t. The
95 * spa_t cannot be destroyed or freed while this is non-zero. Internally,
96 * the refcount is never really 'zero' - opening a pool implicitly keeps
97 * some references in the DMU. Internally we check against spa_minref, but
98 * present the image of a zero/non-zero value to consumers.
100 * spa_config_lock[] (per-spa array of rwlocks)
102 * This protects the spa_t from config changes, and must be held in
103 * the following circumstances:
105 * - RW_READER to perform I/O to the spa
106 * - RW_WRITER to change the vdev config
108 * The locking order is fairly straightforward:
110 * spa_namespace_lock -> spa_refcount
112 * The namespace lock must be acquired to increase the refcount from 0
113 * or to check if it is zero.
115 * spa_refcount -> spa_config_lock[]
117 * There must be at least one valid reference on the spa_t to acquire
120 * spa_namespace_lock -> spa_config_lock[]
122 * The namespace lock must always be taken before the config lock.
125 * The spa_namespace_lock can be acquired directly and is globally visible.
127 * The namespace is manipulated using the following functions, all of which
128 * require the spa_namespace_lock to be held.
130 * spa_lookup() Lookup a spa_t by name.
132 * spa_add() Create a new spa_t in the namespace.
134 * spa_remove() Remove a spa_t from the namespace. This also
135 * frees up any memory associated with the spa_t.
137 * spa_next() Returns the next spa_t in the system, or the
138 * first if NULL is passed.
140 * spa_evict_all() Shutdown and remove all spa_t structures in
143 * spa_guid_exists() Determine whether a pool/device guid exists.
145 * The spa_refcount is manipulated using the following functions:
147 * spa_open_ref() Adds a reference to the given spa_t. Must be
148 * called with spa_namespace_lock held if the
149 * refcount is currently zero.
151 * spa_close() Remove a reference from the spa_t. This will
152 * not free the spa_t or remove it from the
153 * namespace. No locking is required.
155 * spa_refcount_zero() Returns true if the refcount is currently
156 * zero. Must be called with spa_namespace_lock
159 * The spa_config_lock[] is an array of rwlocks, ordered as follows:
160 * SCL_CONFIG > SCL_STATE > SCL_ALLOC > SCL_ZIO > SCL_FREE > SCL_VDEV.
161 * spa_config_lock[] is manipulated with spa_config_{enter,exit,held}().
163 * To read the configuration, it suffices to hold one of these locks as reader.
164 * To modify the configuration, you must hold all locks as writer. To modify
165 * vdev state without altering the vdev tree's topology (e.g. online/offline),
166 * you must hold SCL_STATE and SCL_ZIO as writer.
168 * We use these distinct config locks to avoid recursive lock entry.
169 * For example, spa_sync() (which holds SCL_CONFIG as reader) induces
170 * block allocations (SCL_ALLOC), which may require reading space maps
171 * from disk (dmu_read() -> zio_read() -> SCL_ZIO).
173 * The spa config locks cannot be normal rwlocks because we need the
174 * ability to hand off ownership. For example, SCL_ZIO is acquired
175 * by the issuing thread and later released by an interrupt thread.
176 * They do, however, obey the usual write-wanted semantics to prevent
177 * writer (i.e. system administrator) starvation.
179 * The lock acquisition rules are as follows:
182 * Protects changes to the vdev tree topology, such as vdev
183 * add/remove/attach/detach. Protects the dirty config list
184 * (spa_config_dirty_list) and the set of spares and l2arc devices.
187 * Protects changes to pool state and vdev state, such as vdev
188 * online/offline/fault/degrade/clear. Protects the dirty state list
189 * (spa_state_dirty_list) and global pool state (spa_state).
192 * Protects changes to metaslab groups and classes.
193 * Held as reader by metaslab_alloc() and metaslab_claim().
196 * Held by bp-level zios (those which have no io_vd upon entry)
197 * to prevent changes to the vdev tree. The bp-level zio implicitly
198 * protects all of its vdev child zios, which do not hold SCL_ZIO.
201 * Protects changes to metaslab groups and classes.
202 * Held as reader by metaslab_free(). SCL_FREE is distinct from
203 * SCL_ALLOC, and lower than SCL_ZIO, so that we can safely free
204 * blocks in zio_done() while another i/o that holds either
205 * SCL_ALLOC or SCL_ZIO is waiting for this i/o to complete.
208 * Held as reader to prevent changes to the vdev tree during trivial
209 * inquiries such as bp_get_dsize(). SCL_VDEV is distinct from the
210 * other locks, and lower than all of them, to ensure that it's safe
211 * to acquire regardless of caller context.
213 * In addition, the following rules apply:
215 * (a) spa_props_lock protects pool properties, spa_config and spa_config_list.
216 * The lock ordering is SCL_CONFIG > spa_props_lock.
218 * (b) I/O operations on leaf vdevs. For any zio operation that takes
219 * an explicit vdev_t argument -- such as zio_ioctl(), zio_read_phys(),
220 * or zio_write_phys() -- the caller must ensure that the config cannot
221 * cannot change in the interim, and that the vdev cannot be reopened.
222 * SCL_STATE as reader suffices for both.
224 * The vdev configuration is protected by spa_vdev_enter() / spa_vdev_exit().
226 * spa_vdev_enter() Acquire the namespace lock and the config lock
229 * spa_vdev_exit() Release the config lock, wait for all I/O
230 * to complete, sync the updated configs to the
231 * cache, and release the namespace lock.
233 * vdev state is protected by spa_vdev_state_enter() / spa_vdev_state_exit().
234 * Like spa_vdev_enter/exit, these are convenience wrappers -- the actual
235 * locking is, always, based on spa_namespace_lock and spa_config_lock[].
238 static avl_tree_t spa_namespace_avl
;
239 kmutex_t spa_namespace_lock
;
240 static kcondvar_t spa_namespace_cv
;
241 static const int spa_max_replication_override
= SPA_DVAS_PER_BP
;
243 static kmutex_t spa_spare_lock
;
244 static avl_tree_t spa_spare_avl
;
245 static kmutex_t spa_l2cache_lock
;
246 static avl_tree_t spa_l2cache_avl
;
248 spa_mode_t spa_mode_global
= SPA_MODE_UNINIT
;
252 * Everything except dprintf, set_error, spa, and indirect_remap is on
253 * by default in debug builds.
255 int zfs_flags
= ~(ZFS_DEBUG_DPRINTF
| ZFS_DEBUG_SET_ERROR
|
256 ZFS_DEBUG_INDIRECT_REMAP
);
262 * zfs_recover can be set to nonzero to attempt to recover from
263 * otherwise-fatal errors, typically caused by on-disk corruption. When
264 * set, calls to zfs_panic_recover() will turn into warning messages.
265 * This should only be used as a last resort, as it typically results
266 * in leaked space, or worse.
268 int zfs_recover
= B_FALSE
;
271 * If destroy encounters an EIO while reading metadata (e.g. indirect
272 * blocks), space referenced by the missing metadata can not be freed.
273 * Normally this causes the background destroy to become "stalled", as
274 * it is unable to make forward progress. While in this stalled state,
275 * all remaining space to free from the error-encountering filesystem is
276 * "temporarily leaked". Set this flag to cause it to ignore the EIO,
277 * permanently leak the space from indirect blocks that can not be read,
278 * and continue to free everything else that it can.
280 * The default, "stalling" behavior is useful if the storage partially
281 * fails (i.e. some but not all i/os fail), and then later recovers. In
282 * this case, we will be able to continue pool operations while it is
283 * partially failed, and when it recovers, we can continue to free the
284 * space, with no leaks. However, note that this case is actually
287 * Typically pools either (a) fail completely (but perhaps temporarily,
288 * e.g. a top-level vdev going offline), or (b) have localized,
289 * permanent errors (e.g. disk returns the wrong data due to bit flip or
290 * firmware bug). In case (a), this setting does not matter because the
291 * pool will be suspended and the sync thread will not be able to make
292 * forward progress regardless. In case (b), because the error is
293 * permanent, the best we can do is leak the minimum amount of space,
294 * which is what setting this flag will do. Therefore, it is reasonable
295 * for this flag to normally be set, but we chose the more conservative
296 * approach of not setting it, so that there is no possibility of
297 * leaking space in the "partial temporary" failure case.
299 int zfs_free_leak_on_eio
= B_FALSE
;
302 * Expiration time in milliseconds. This value has two meanings. First it is
303 * used to determine when the spa_deadman() logic should fire. By default the
304 * spa_deadman() will fire if spa_sync() has not completed in 600 seconds.
305 * Secondly, the value determines if an I/O is considered "hung". Any I/O that
306 * has not completed in zfs_deadman_synctime_ms is considered "hung" resulting
307 * in one of three behaviors controlled by zfs_deadman_failmode.
309 uint64_t zfs_deadman_synctime_ms
= 600000UL; /* 10 min. */
312 * This value controls the maximum amount of time zio_wait() will block for an
313 * outstanding IO. By default this is 300 seconds at which point the "hung"
314 * behavior will be applied as described for zfs_deadman_synctime_ms.
316 uint64_t zfs_deadman_ziotime_ms
= 300000UL; /* 5 min. */
319 * Check time in milliseconds. This defines the frequency at which we check
322 uint64_t zfs_deadman_checktime_ms
= 60000UL; /* 1 min. */
325 * By default the deadman is enabled.
327 int zfs_deadman_enabled
= B_TRUE
;
330 * Controls the behavior of the deadman when it detects a "hung" I/O.
331 * Valid values are zfs_deadman_failmode=<wait|continue|panic>.
333 * wait - Wait for the "hung" I/O (default)
334 * continue - Attempt to recover from a "hung" I/O
335 * panic - Panic the system
337 const char *zfs_deadman_failmode
= "wait";
340 * The worst case is single-sector max-parity RAID-Z blocks, in which
341 * case the space requirement is exactly (VDEV_RAIDZ_MAXPARITY + 1)
342 * times the size; so just assume that. Add to this the fact that
343 * we can have up to 3 DVAs per bp, and one more factor of 2 because
344 * the block may be dittoed with up to 3 DVAs by ddt_sync(). All together,
346 * (VDEV_RAIDZ_MAXPARITY + 1) * SPA_DVAS_PER_BP * 2 == 24
348 uint_t spa_asize_inflation
= 24;
351 * Normally, we don't allow the last 3.2% (1/(2^spa_slop_shift)) of space in
352 * the pool to be consumed (bounded by spa_max_slop). This ensures that we
353 * don't run the pool completely out of space, due to unaccounted changes (e.g.
354 * to the MOS). It also limits the worst-case time to allocate space. If we
355 * have less than this amount of free space, most ZPL operations (e.g. write,
356 * create) will return ENOSPC. The ZIL metaslabs (spa_embedded_log_class) are
357 * also part of this 3.2% of space which can't be consumed by normal writes;
358 * the slop space "proper" (spa_get_slop_space()) is decreased by the embedded
361 * Certain operations (e.g. file removal, most administrative actions) can
362 * use half the slop space. They will only return ENOSPC if less than half
363 * the slop space is free. Typically, once the pool has less than the slop
364 * space free, the user will use these operations to free up space in the pool.
365 * These are the operations that call dsl_pool_adjustedsize() with the netfree
366 * argument set to TRUE.
368 * Operations that are almost guaranteed to free up space in the absence of
369 * a pool checkpoint can use up to three quarters of the slop space
372 * A very restricted set of operations are always permitted, regardless of
373 * the amount of free space. These are the operations that call
374 * dsl_sync_task(ZFS_SPACE_CHECK_NONE). If these operations result in a net
375 * increase in the amount of space used, it is possible to run the pool
376 * completely out of space, causing it to be permanently read-only.
378 * Note that on very small pools, the slop space will be larger than
379 * 3.2%, in an effort to have it be at least spa_min_slop (128MB),
380 * but we never allow it to be more than half the pool size.
382 * Further, on very large pools, the slop space will be smaller than
383 * 3.2%, to avoid reserving much more space than we actually need; bounded
384 * by spa_max_slop (128GB).
386 * See also the comments in zfs_space_check_t.
388 uint_t spa_slop_shift
= 5;
389 static const uint64_t spa_min_slop
= 128ULL * 1024 * 1024;
390 static const uint64_t spa_max_slop
= 128ULL * 1024 * 1024 * 1024;
393 * Number of allocators to use, per spa instance
395 static int spa_num_allocators
= 4;
398 * Spa active allocator.
399 * Valid values are zfs_active_allocator=<dynamic|cursor|new-dynamic>.
401 const char *zfs_active_allocator
= "dynamic";
404 spa_load_failed(spa_t
*spa
, const char *fmt
, ...)
410 (void) vsnprintf(buf
, sizeof (buf
), fmt
, adx
);
413 zfs_dbgmsg("spa_load(%s, config %s): FAILED: %s", spa
->spa_name
,
414 spa
->spa_trust_config
? "trusted" : "untrusted", buf
);
418 spa_load_note(spa_t
*spa
, const char *fmt
, ...)
424 (void) vsnprintf(buf
, sizeof (buf
), fmt
, adx
);
427 zfs_dbgmsg("spa_load(%s, config %s): %s", spa
->spa_name
,
428 spa
->spa_trust_config
? "trusted" : "untrusted", buf
);
430 spa_import_progress_set_notes_nolog(spa
, "%s", buf
);
434 * By default dedup and user data indirects land in the special class
436 static int zfs_ddt_data_is_special
= B_TRUE
;
437 static int zfs_user_indirect_is_special
= B_TRUE
;
440 * The percentage of special class final space reserved for metadata only.
441 * Once we allocate 100 - zfs_special_class_metadata_reserve_pct we only
442 * let metadata into the class.
444 static uint_t zfs_special_class_metadata_reserve_pct
= 25;
447 * ==========================================================================
449 * ==========================================================================
452 spa_config_lock_init(spa_t
*spa
)
454 for (int i
= 0; i
< SCL_LOCKS
; i
++) {
455 spa_config_lock_t
*scl
= &spa
->spa_config_lock
[i
];
456 mutex_init(&scl
->scl_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
457 cv_init(&scl
->scl_cv
, NULL
, CV_DEFAULT
, NULL
);
458 scl
->scl_writer
= NULL
;
459 scl
->scl_write_wanted
= 0;
465 spa_config_lock_destroy(spa_t
*spa
)
467 for (int i
= 0; i
< SCL_LOCKS
; i
++) {
468 spa_config_lock_t
*scl
= &spa
->spa_config_lock
[i
];
469 mutex_destroy(&scl
->scl_lock
);
470 cv_destroy(&scl
->scl_cv
);
471 ASSERT(scl
->scl_writer
== NULL
);
472 ASSERT(scl
->scl_write_wanted
== 0);
473 ASSERT(scl
->scl_count
== 0);
478 spa_config_tryenter(spa_t
*spa
, int locks
, const void *tag
, krw_t rw
)
480 for (int i
= 0; i
< SCL_LOCKS
; i
++) {
481 spa_config_lock_t
*scl
= &spa
->spa_config_lock
[i
];
482 if (!(locks
& (1 << i
)))
484 mutex_enter(&scl
->scl_lock
);
485 if (rw
== RW_READER
) {
486 if (scl
->scl_writer
|| scl
->scl_write_wanted
) {
487 mutex_exit(&scl
->scl_lock
);
488 spa_config_exit(spa
, locks
& ((1 << i
) - 1),
493 ASSERT(scl
->scl_writer
!= curthread
);
494 if (scl
->scl_count
!= 0) {
495 mutex_exit(&scl
->scl_lock
);
496 spa_config_exit(spa
, locks
& ((1 << i
) - 1),
500 scl
->scl_writer
= curthread
;
503 mutex_exit(&scl
->scl_lock
);
509 spa_config_enter_impl(spa_t
*spa
, int locks
, const void *tag
, krw_t rw
,
515 ASSERT3U(SCL_LOCKS
, <, sizeof (wlocks_held
) * NBBY
);
517 for (int i
= 0; i
< SCL_LOCKS
; i
++) {
518 spa_config_lock_t
*scl
= &spa
->spa_config_lock
[i
];
519 if (scl
->scl_writer
== curthread
)
520 wlocks_held
|= (1 << i
);
521 if (!(locks
& (1 << i
)))
523 mutex_enter(&scl
->scl_lock
);
524 if (rw
== RW_READER
) {
525 while (scl
->scl_writer
||
526 (!mmp_flag
&& scl
->scl_write_wanted
)) {
527 cv_wait(&scl
->scl_cv
, &scl
->scl_lock
);
530 ASSERT(scl
->scl_writer
!= curthread
);
531 while (scl
->scl_count
!= 0) {
532 scl
->scl_write_wanted
++;
533 cv_wait(&scl
->scl_cv
, &scl
->scl_lock
);
534 scl
->scl_write_wanted
--;
536 scl
->scl_writer
= curthread
;
539 mutex_exit(&scl
->scl_lock
);
541 ASSERT3U(wlocks_held
, <=, locks
);
545 spa_config_enter(spa_t
*spa
, int locks
, const void *tag
, krw_t rw
)
547 spa_config_enter_impl(spa
, locks
, tag
, rw
, 0);
551 * The spa_config_enter_mmp() allows the mmp thread to cut in front of
552 * outstanding write lock requests. This is needed since the mmp updates are
553 * time sensitive and failure to service them promptly will result in a
554 * suspended pool. This pool suspension has been seen in practice when there is
555 * a single disk in a pool that is responding slowly and presumably about to
560 spa_config_enter_mmp(spa_t
*spa
, int locks
, const void *tag
, krw_t rw
)
562 spa_config_enter_impl(spa
, locks
, tag
, rw
, 1);
566 spa_config_exit(spa_t
*spa
, int locks
, const void *tag
)
569 for (int i
= SCL_LOCKS
- 1; i
>= 0; i
--) {
570 spa_config_lock_t
*scl
= &spa
->spa_config_lock
[i
];
571 if (!(locks
& (1 << i
)))
573 mutex_enter(&scl
->scl_lock
);
574 ASSERT(scl
->scl_count
> 0);
575 if (--scl
->scl_count
== 0) {
576 ASSERT(scl
->scl_writer
== NULL
||
577 scl
->scl_writer
== curthread
);
578 scl
->scl_writer
= NULL
; /* OK in either case */
579 cv_broadcast(&scl
->scl_cv
);
581 mutex_exit(&scl
->scl_lock
);
586 spa_config_held(spa_t
*spa
, int locks
, krw_t rw
)
590 for (int i
= 0; i
< SCL_LOCKS
; i
++) {
591 spa_config_lock_t
*scl
= &spa
->spa_config_lock
[i
];
592 if (!(locks
& (1 << i
)))
594 if ((rw
== RW_READER
&& scl
->scl_count
!= 0) ||
595 (rw
== RW_WRITER
&& scl
->scl_writer
== curthread
))
596 locks_held
|= 1 << i
;
603 * ==========================================================================
604 * SPA namespace functions
605 * ==========================================================================
609 * Lookup the named spa_t in the AVL tree. The spa_namespace_lock must be held.
610 * Returns NULL if no matching spa_t is found.
613 spa_lookup(const char *name
)
615 static spa_t search
; /* spa_t is large; don't allocate on stack */
620 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
622 (void) strlcpy(search
.spa_name
, name
, sizeof (search
.spa_name
));
625 * If it's a full dataset name, figure out the pool name and
628 cp
= strpbrk(search
.spa_name
, "/@#");
632 spa
= avl_find(&spa_namespace_avl
, &search
, &where
);
638 * Fires when spa_sync has not completed within zfs_deadman_synctime_ms.
639 * If the zfs_deadman_enabled flag is set then it inspects all vdev queues
640 * looking for potentially hung I/Os.
643 spa_deadman(void *arg
)
647 /* Disable the deadman if the pool is suspended. */
648 if (spa_suspended(spa
))
651 zfs_dbgmsg("slow spa_sync: started %llu seconds ago, calls %llu",
652 (gethrtime() - spa
->spa_sync_starttime
) / NANOSEC
,
653 (u_longlong_t
)++spa
->spa_deadman_calls
);
654 if (zfs_deadman_enabled
)
655 vdev_deadman(spa
->spa_root_vdev
, FTAG
);
657 spa
->spa_deadman_tqid
= taskq_dispatch_delay(system_delay_taskq
,
658 spa_deadman
, spa
, TQ_SLEEP
, ddi_get_lbolt() +
659 MSEC_TO_TICK(zfs_deadman_checktime_ms
));
663 spa_log_sm_sort_by_txg(const void *va
, const void *vb
)
665 const spa_log_sm_t
*a
= va
;
666 const spa_log_sm_t
*b
= vb
;
668 return (TREE_CMP(a
->sls_txg
, b
->sls_txg
));
672 * Create an uninitialized spa_t with the given name. Requires
673 * spa_namespace_lock. The caller must ensure that the spa_t doesn't already
674 * exist by calling spa_lookup() first.
677 spa_add(const char *name
, nvlist_t
*config
, const char *altroot
)
680 spa_config_dirent_t
*dp
;
682 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
684 spa
= kmem_zalloc(sizeof (spa_t
), KM_SLEEP
);
686 mutex_init(&spa
->spa_async_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
687 mutex_init(&spa
->spa_errlist_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
688 mutex_init(&spa
->spa_errlog_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
689 mutex_init(&spa
->spa_evicting_os_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
690 mutex_init(&spa
->spa_history_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
691 mutex_init(&spa
->spa_proc_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
692 mutex_init(&spa
->spa_props_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
693 mutex_init(&spa
->spa_cksum_tmpls_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
694 mutex_init(&spa
->spa_scrub_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
695 mutex_init(&spa
->spa_suspend_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
696 mutex_init(&spa
->spa_vdev_top_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
697 mutex_init(&spa
->spa_feat_stats_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
698 mutex_init(&spa
->spa_flushed_ms_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
699 mutex_init(&spa
->spa_activities_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
701 cv_init(&spa
->spa_async_cv
, NULL
, CV_DEFAULT
, NULL
);
702 cv_init(&spa
->spa_evicting_os_cv
, NULL
, CV_DEFAULT
, NULL
);
703 cv_init(&spa
->spa_proc_cv
, NULL
, CV_DEFAULT
, NULL
);
704 cv_init(&spa
->spa_scrub_io_cv
, NULL
, CV_DEFAULT
, NULL
);
705 cv_init(&spa
->spa_suspend_cv
, NULL
, CV_DEFAULT
, NULL
);
706 cv_init(&spa
->spa_activities_cv
, NULL
, CV_DEFAULT
, NULL
);
707 cv_init(&spa
->spa_waiters_cv
, NULL
, CV_DEFAULT
, NULL
);
709 for (int t
= 0; t
< TXG_SIZE
; t
++)
710 bplist_create(&spa
->spa_free_bplist
[t
]);
712 (void) strlcpy(spa
->spa_name
, name
, sizeof (spa
->spa_name
));
713 spa
->spa_state
= POOL_STATE_UNINITIALIZED
;
714 spa
->spa_freeze_txg
= UINT64_MAX
;
715 spa
->spa_final_txg
= UINT64_MAX
;
716 spa
->spa_load_max_txg
= UINT64_MAX
;
718 spa
->spa_proc_state
= SPA_PROC_NONE
;
719 spa
->spa_trust_config
= B_TRUE
;
720 spa
->spa_hostid
= zone_get_hostid(NULL
);
722 spa
->spa_deadman_synctime
= MSEC2NSEC(zfs_deadman_synctime_ms
);
723 spa
->spa_deadman_ziotime
= MSEC2NSEC(zfs_deadman_ziotime_ms
);
724 spa_set_deadman_failmode(spa
, zfs_deadman_failmode
);
725 spa_set_allocator(spa
, zfs_active_allocator
);
727 zfs_refcount_create(&spa
->spa_refcount
);
728 spa_config_lock_init(spa
);
731 avl_add(&spa_namespace_avl
, spa
);
734 * Set the alternate root, if there is one.
737 spa
->spa_root
= spa_strdup(altroot
);
739 /* Do not allow more allocators than CPUs. */
740 spa
->spa_alloc_count
= MIN(MAX(spa_num_allocators
, 1), boot_ncpus
);
742 spa
->spa_allocs
= kmem_zalloc(spa
->spa_alloc_count
*
743 sizeof (spa_alloc_t
), KM_SLEEP
);
744 for (int i
= 0; i
< spa
->spa_alloc_count
; i
++) {
745 mutex_init(&spa
->spa_allocs
[i
].spaa_lock
, NULL
, MUTEX_DEFAULT
,
747 avl_create(&spa
->spa_allocs
[i
].spaa_tree
, zio_bookmark_compare
,
748 sizeof (zio_t
), offsetof(zio_t
, io_queue_node
.a
));
751 avl_create(&spa
->spa_metaslabs_by_flushed
, metaslab_sort_by_flushed
,
752 sizeof (metaslab_t
), offsetof(metaslab_t
, ms_spa_txg_node
));
753 avl_create(&spa
->spa_sm_logs_by_txg
, spa_log_sm_sort_by_txg
,
754 sizeof (spa_log_sm_t
), offsetof(spa_log_sm_t
, sls_node
));
755 list_create(&spa
->spa_log_summary
, sizeof (log_summary_entry_t
),
756 offsetof(log_summary_entry_t
, lse_node
));
759 * Every pool starts with the default cachefile
761 list_create(&spa
->spa_config_list
, sizeof (spa_config_dirent_t
),
762 offsetof(spa_config_dirent_t
, scd_link
));
764 dp
= kmem_zalloc(sizeof (spa_config_dirent_t
), KM_SLEEP
);
765 dp
->scd_path
= altroot
? NULL
: spa_strdup(spa_config_path
);
766 list_insert_head(&spa
->spa_config_list
, dp
);
768 VERIFY(nvlist_alloc(&spa
->spa_load_info
, NV_UNIQUE_NAME
,
771 if (config
!= NULL
) {
774 if (nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_FEATURES_FOR_READ
,
776 VERIFY(nvlist_dup(features
, &spa
->spa_label_features
,
780 VERIFY(nvlist_dup(config
, &spa
->spa_config
, 0) == 0);
783 if (spa
->spa_label_features
== NULL
) {
784 VERIFY(nvlist_alloc(&spa
->spa_label_features
, NV_UNIQUE_NAME
,
788 spa
->spa_min_ashift
= INT_MAX
;
789 spa
->spa_max_ashift
= 0;
790 spa
->spa_min_alloc
= INT_MAX
;
791 spa
->spa_gcd_alloc
= INT_MAX
;
793 /* Reset cached value */
794 spa
->spa_dedup_dspace
= ~0ULL;
797 * As a pool is being created, treat all features as disabled by
798 * setting SPA_FEATURE_DISABLED for all entries in the feature
801 for (int i
= 0; i
< SPA_FEATURES
; i
++) {
802 spa
->spa_feat_refcount_cache
[i
] = SPA_FEATURE_DISABLED
;
805 list_create(&spa
->spa_leaf_list
, sizeof (vdev_t
),
806 offsetof(vdev_t
, vdev_leaf_node
));
812 * Removes a spa_t from the namespace, freeing up any memory used. Requires
813 * spa_namespace_lock. This is called only after the spa_t has been closed and
817 spa_remove(spa_t
*spa
)
819 spa_config_dirent_t
*dp
;
821 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
822 ASSERT(spa_state(spa
) == POOL_STATE_UNINITIALIZED
);
823 ASSERT3U(zfs_refcount_count(&spa
->spa_refcount
), ==, 0);
824 ASSERT0(spa
->spa_waiters
);
826 nvlist_free(spa
->spa_config_splitting
);
828 avl_remove(&spa_namespace_avl
, spa
);
829 cv_broadcast(&spa_namespace_cv
);
832 spa_strfree(spa
->spa_root
);
834 while ((dp
= list_remove_head(&spa
->spa_config_list
)) != NULL
) {
835 if (dp
->scd_path
!= NULL
)
836 spa_strfree(dp
->scd_path
);
837 kmem_free(dp
, sizeof (spa_config_dirent_t
));
840 for (int i
= 0; i
< spa
->spa_alloc_count
; i
++) {
841 avl_destroy(&spa
->spa_allocs
[i
].spaa_tree
);
842 mutex_destroy(&spa
->spa_allocs
[i
].spaa_lock
);
844 kmem_free(spa
->spa_allocs
, spa
->spa_alloc_count
*
845 sizeof (spa_alloc_t
));
847 avl_destroy(&spa
->spa_metaslabs_by_flushed
);
848 avl_destroy(&spa
->spa_sm_logs_by_txg
);
849 list_destroy(&spa
->spa_log_summary
);
850 list_destroy(&spa
->spa_config_list
);
851 list_destroy(&spa
->spa_leaf_list
);
853 nvlist_free(spa
->spa_label_features
);
854 nvlist_free(spa
->spa_load_info
);
855 nvlist_free(spa
->spa_feat_stats
);
856 spa_config_set(spa
, NULL
);
858 zfs_refcount_destroy(&spa
->spa_refcount
);
860 spa_stats_destroy(spa
);
861 spa_config_lock_destroy(spa
);
863 for (int t
= 0; t
< TXG_SIZE
; t
++)
864 bplist_destroy(&spa
->spa_free_bplist
[t
]);
866 zio_checksum_templates_free(spa
);
868 cv_destroy(&spa
->spa_async_cv
);
869 cv_destroy(&spa
->spa_evicting_os_cv
);
870 cv_destroy(&spa
->spa_proc_cv
);
871 cv_destroy(&spa
->spa_scrub_io_cv
);
872 cv_destroy(&spa
->spa_suspend_cv
);
873 cv_destroy(&spa
->spa_activities_cv
);
874 cv_destroy(&spa
->spa_waiters_cv
);
876 mutex_destroy(&spa
->spa_flushed_ms_lock
);
877 mutex_destroy(&spa
->spa_async_lock
);
878 mutex_destroy(&spa
->spa_errlist_lock
);
879 mutex_destroy(&spa
->spa_errlog_lock
);
880 mutex_destroy(&spa
->spa_evicting_os_lock
);
881 mutex_destroy(&spa
->spa_history_lock
);
882 mutex_destroy(&spa
->spa_proc_lock
);
883 mutex_destroy(&spa
->spa_props_lock
);
884 mutex_destroy(&spa
->spa_cksum_tmpls_lock
);
885 mutex_destroy(&spa
->spa_scrub_lock
);
886 mutex_destroy(&spa
->spa_suspend_lock
);
887 mutex_destroy(&spa
->spa_vdev_top_lock
);
888 mutex_destroy(&spa
->spa_feat_stats_lock
);
889 mutex_destroy(&spa
->spa_activities_lock
);
891 kmem_free(spa
, sizeof (spa_t
));
895 * Given a pool, return the next pool in the namespace, or NULL if there is
896 * none. If 'prev' is NULL, return the first pool.
899 spa_next(spa_t
*prev
)
901 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
904 return (AVL_NEXT(&spa_namespace_avl
, prev
));
906 return (avl_first(&spa_namespace_avl
));
910 * ==========================================================================
911 * SPA refcount functions
912 * ==========================================================================
916 * Add a reference to the given spa_t. Must have at least one reference, or
917 * have the namespace lock held.
920 spa_open_ref(spa_t
*spa
, const void *tag
)
922 ASSERT(zfs_refcount_count(&spa
->spa_refcount
) >= spa
->spa_minref
||
923 MUTEX_HELD(&spa_namespace_lock
));
924 (void) zfs_refcount_add(&spa
->spa_refcount
, tag
);
928 * Remove a reference to the given spa_t. Must have at least one reference, or
929 * have the namespace lock held.
932 spa_close(spa_t
*spa
, const void *tag
)
934 ASSERT(zfs_refcount_count(&spa
->spa_refcount
) > spa
->spa_minref
||
935 MUTEX_HELD(&spa_namespace_lock
));
936 (void) zfs_refcount_remove(&spa
->spa_refcount
, tag
);
940 * Remove a reference to the given spa_t held by a dsl dir that is
941 * being asynchronously released. Async releases occur from a taskq
942 * performing eviction of dsl datasets and dirs. The namespace lock
943 * isn't held and the hold by the object being evicted may contribute to
944 * spa_minref (e.g. dataset or directory released during pool export),
945 * so the asserts in spa_close() do not apply.
948 spa_async_close(spa_t
*spa
, const void *tag
)
950 (void) zfs_refcount_remove(&spa
->spa_refcount
, tag
);
954 * Check to see if the spa refcount is zero. Must be called with
955 * spa_namespace_lock held. We really compare against spa_minref, which is the
956 * number of references acquired when opening a pool
959 spa_refcount_zero(spa_t
*spa
)
961 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
963 return (zfs_refcount_count(&spa
->spa_refcount
) == spa
->spa_minref
);
967 * ==========================================================================
968 * SPA spare and l2cache tracking
969 * ==========================================================================
973 * Hot spares and cache devices are tracked using the same code below,
974 * for 'auxiliary' devices.
977 typedef struct spa_aux
{
985 spa_aux_compare(const void *a
, const void *b
)
987 const spa_aux_t
*sa
= (const spa_aux_t
*)a
;
988 const spa_aux_t
*sb
= (const spa_aux_t
*)b
;
990 return (TREE_CMP(sa
->aux_guid
, sb
->aux_guid
));
994 spa_aux_add(vdev_t
*vd
, avl_tree_t
*avl
)
1000 search
.aux_guid
= vd
->vdev_guid
;
1001 if ((aux
= avl_find(avl
, &search
, &where
)) != NULL
) {
1004 aux
= kmem_zalloc(sizeof (spa_aux_t
), KM_SLEEP
);
1005 aux
->aux_guid
= vd
->vdev_guid
;
1007 avl_insert(avl
, aux
, where
);
1012 spa_aux_remove(vdev_t
*vd
, avl_tree_t
*avl
)
1018 search
.aux_guid
= vd
->vdev_guid
;
1019 aux
= avl_find(avl
, &search
, &where
);
1021 ASSERT(aux
!= NULL
);
1023 if (--aux
->aux_count
== 0) {
1024 avl_remove(avl
, aux
);
1025 kmem_free(aux
, sizeof (spa_aux_t
));
1026 } else if (aux
->aux_pool
== spa_guid(vd
->vdev_spa
)) {
1027 aux
->aux_pool
= 0ULL;
1032 spa_aux_exists(uint64_t guid
, uint64_t *pool
, int *refcnt
, avl_tree_t
*avl
)
1034 spa_aux_t search
, *found
;
1036 search
.aux_guid
= guid
;
1037 found
= avl_find(avl
, &search
, NULL
);
1041 *pool
= found
->aux_pool
;
1048 *refcnt
= found
->aux_count
;
1053 return (found
!= NULL
);
1057 spa_aux_activate(vdev_t
*vd
, avl_tree_t
*avl
)
1059 spa_aux_t search
, *found
;
1062 search
.aux_guid
= vd
->vdev_guid
;
1063 found
= avl_find(avl
, &search
, &where
);
1064 ASSERT(found
!= NULL
);
1065 ASSERT(found
->aux_pool
== 0ULL);
1067 found
->aux_pool
= spa_guid(vd
->vdev_spa
);
1071 * Spares are tracked globally due to the following constraints:
1073 * - A spare may be part of multiple pools.
1074 * - A spare may be added to a pool even if it's actively in use within
1076 * - A spare in use in any pool can only be the source of a replacement if
1077 * the target is a spare in the same pool.
1079 * We keep track of all spares on the system through the use of a reference
1080 * counted AVL tree. When a vdev is added as a spare, or used as a replacement
1081 * spare, then we bump the reference count in the AVL tree. In addition, we set
1082 * the 'vdev_isspare' member to indicate that the device is a spare (active or
1083 * inactive). When a spare is made active (used to replace a device in the
1084 * pool), we also keep track of which pool its been made a part of.
1086 * The 'spa_spare_lock' protects the AVL tree. These functions are normally
1087 * called under the spa_namespace lock as part of vdev reconfiguration. The
1088 * separate spare lock exists for the status query path, which does not need to
1089 * be completely consistent with respect to other vdev configuration changes.
1093 spa_spare_compare(const void *a
, const void *b
)
1095 return (spa_aux_compare(a
, b
));
1099 spa_spare_add(vdev_t
*vd
)
1101 mutex_enter(&spa_spare_lock
);
1102 ASSERT(!vd
->vdev_isspare
);
1103 spa_aux_add(vd
, &spa_spare_avl
);
1104 vd
->vdev_isspare
= B_TRUE
;
1105 mutex_exit(&spa_spare_lock
);
1109 spa_spare_remove(vdev_t
*vd
)
1111 mutex_enter(&spa_spare_lock
);
1112 ASSERT(vd
->vdev_isspare
);
1113 spa_aux_remove(vd
, &spa_spare_avl
);
1114 vd
->vdev_isspare
= B_FALSE
;
1115 mutex_exit(&spa_spare_lock
);
1119 spa_spare_exists(uint64_t guid
, uint64_t *pool
, int *refcnt
)
1123 mutex_enter(&spa_spare_lock
);
1124 found
= spa_aux_exists(guid
, pool
, refcnt
, &spa_spare_avl
);
1125 mutex_exit(&spa_spare_lock
);
1131 spa_spare_activate(vdev_t
*vd
)
1133 mutex_enter(&spa_spare_lock
);
1134 ASSERT(vd
->vdev_isspare
);
1135 spa_aux_activate(vd
, &spa_spare_avl
);
1136 mutex_exit(&spa_spare_lock
);
1140 * Level 2 ARC devices are tracked globally for the same reasons as spares.
1141 * Cache devices currently only support one pool per cache device, and so
1142 * for these devices the aux reference count is currently unused beyond 1.
1146 spa_l2cache_compare(const void *a
, const void *b
)
1148 return (spa_aux_compare(a
, b
));
1152 spa_l2cache_add(vdev_t
*vd
)
1154 mutex_enter(&spa_l2cache_lock
);
1155 ASSERT(!vd
->vdev_isl2cache
);
1156 spa_aux_add(vd
, &spa_l2cache_avl
);
1157 vd
->vdev_isl2cache
= B_TRUE
;
1158 mutex_exit(&spa_l2cache_lock
);
1162 spa_l2cache_remove(vdev_t
*vd
)
1164 mutex_enter(&spa_l2cache_lock
);
1165 ASSERT(vd
->vdev_isl2cache
);
1166 spa_aux_remove(vd
, &spa_l2cache_avl
);
1167 vd
->vdev_isl2cache
= B_FALSE
;
1168 mutex_exit(&spa_l2cache_lock
);
1172 spa_l2cache_exists(uint64_t guid
, uint64_t *pool
)
1176 mutex_enter(&spa_l2cache_lock
);
1177 found
= spa_aux_exists(guid
, pool
, NULL
, &spa_l2cache_avl
);
1178 mutex_exit(&spa_l2cache_lock
);
1184 spa_l2cache_activate(vdev_t
*vd
)
1186 mutex_enter(&spa_l2cache_lock
);
1187 ASSERT(vd
->vdev_isl2cache
);
1188 spa_aux_activate(vd
, &spa_l2cache_avl
);
1189 mutex_exit(&spa_l2cache_lock
);
1193 * ==========================================================================
1195 * ==========================================================================
1199 * Lock the given spa_t for the purpose of adding or removing a vdev.
1200 * Grabs the global spa_namespace_lock plus the spa config lock for writing.
1201 * It returns the next transaction group for the spa_t.
1204 spa_vdev_enter(spa_t
*spa
)
1206 mutex_enter(&spa
->spa_vdev_top_lock
);
1207 mutex_enter(&spa_namespace_lock
);
1209 vdev_autotrim_stop_all(spa
);
1211 return (spa_vdev_config_enter(spa
));
1215 * The same as spa_vdev_enter() above but additionally takes the guid of
1216 * the vdev being detached. When there is a rebuild in process it will be
1217 * suspended while the vdev tree is modified then resumed by spa_vdev_exit().
1218 * The rebuild is canceled if only a single child remains after the detach.
1221 spa_vdev_detach_enter(spa_t
*spa
, uint64_t guid
)
1223 mutex_enter(&spa
->spa_vdev_top_lock
);
1224 mutex_enter(&spa_namespace_lock
);
1226 vdev_autotrim_stop_all(spa
);
1229 vdev_t
*vd
= spa_lookup_by_guid(spa
, guid
, B_FALSE
);
1231 vdev_rebuild_stop_wait(vd
->vdev_top
);
1235 return (spa_vdev_config_enter(spa
));
1239 * Internal implementation for spa_vdev_enter(). Used when a vdev
1240 * operation requires multiple syncs (i.e. removing a device) while
1241 * keeping the spa_namespace_lock held.
1244 spa_vdev_config_enter(spa_t
*spa
)
1246 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
1248 spa_config_enter(spa
, SCL_ALL
, spa
, RW_WRITER
);
1250 return (spa_last_synced_txg(spa
) + 1);
1254 * Used in combination with spa_vdev_config_enter() to allow the syncing
1255 * of multiple transactions without releasing the spa_namespace_lock.
1258 spa_vdev_config_exit(spa_t
*spa
, vdev_t
*vd
, uint64_t txg
, int error
,
1261 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
1263 int config_changed
= B_FALSE
;
1265 ASSERT(txg
> spa_last_synced_txg(spa
));
1267 spa
->spa_pending_vdev
= NULL
;
1270 * Reassess the DTLs.
1272 vdev_dtl_reassess(spa
->spa_root_vdev
, 0, 0, B_FALSE
, B_FALSE
);
1274 if (error
== 0 && !list_is_empty(&spa
->spa_config_dirty_list
)) {
1275 config_changed
= B_TRUE
;
1276 spa
->spa_config_generation
++;
1280 * Verify the metaslab classes.
1282 ASSERT(metaslab_class_validate(spa_normal_class(spa
)) == 0);
1283 ASSERT(metaslab_class_validate(spa_log_class(spa
)) == 0);
1284 ASSERT(metaslab_class_validate(spa_embedded_log_class(spa
)) == 0);
1285 ASSERT(metaslab_class_validate(spa_special_class(spa
)) == 0);
1286 ASSERT(metaslab_class_validate(spa_dedup_class(spa
)) == 0);
1288 spa_config_exit(spa
, SCL_ALL
, spa
);
1291 * Panic the system if the specified tag requires it. This
1292 * is useful for ensuring that configurations are updated
1295 if (zio_injection_enabled
)
1296 zio_handle_panic_injection(spa
, tag
, 0);
1299 * Note: this txg_wait_synced() is important because it ensures
1300 * that there won't be more than one config change per txg.
1301 * This allows us to use the txg as the generation number.
1304 txg_wait_synced(spa
->spa_dsl_pool
, txg
);
1307 ASSERT(!vd
->vdev_detached
|| vd
->vdev_dtl_sm
== NULL
);
1308 if (vd
->vdev_ops
->vdev_op_leaf
) {
1309 mutex_enter(&vd
->vdev_initialize_lock
);
1310 vdev_initialize_stop(vd
, VDEV_INITIALIZE_CANCELED
,
1312 mutex_exit(&vd
->vdev_initialize_lock
);
1314 mutex_enter(&vd
->vdev_trim_lock
);
1315 vdev_trim_stop(vd
, VDEV_TRIM_CANCELED
, NULL
);
1316 mutex_exit(&vd
->vdev_trim_lock
);
1320 * The vdev may be both a leaf and top-level device.
1322 vdev_autotrim_stop_wait(vd
);
1324 spa_config_enter(spa
, SCL_STATE_ALL
, spa
, RW_WRITER
);
1326 spa_config_exit(spa
, SCL_STATE_ALL
, spa
);
1330 * If the config changed, update the config cache.
1333 spa_write_cachefile(spa
, B_FALSE
, B_TRUE
, B_TRUE
);
1337 * Unlock the spa_t after adding or removing a vdev. Besides undoing the
1338 * locking of spa_vdev_enter(), we also want make sure the transactions have
1339 * synced to disk, and then update the global configuration cache with the new
1343 spa_vdev_exit(spa_t
*spa
, vdev_t
*vd
, uint64_t txg
, int error
)
1345 vdev_autotrim_restart(spa
);
1346 vdev_rebuild_restart(spa
);
1348 spa_vdev_config_exit(spa
, vd
, txg
, error
, FTAG
);
1349 mutex_exit(&spa_namespace_lock
);
1350 mutex_exit(&spa
->spa_vdev_top_lock
);
1356 * Lock the given spa_t for the purpose of changing vdev state.
1359 spa_vdev_state_enter(spa_t
*spa
, int oplocks
)
1361 int locks
= SCL_STATE_ALL
| oplocks
;
1364 * Root pools may need to read of the underlying devfs filesystem
1365 * when opening up a vdev. Unfortunately if we're holding the
1366 * SCL_ZIO lock it will result in a deadlock when we try to issue
1367 * the read from the root filesystem. Instead we "prefetch"
1368 * the associated vnodes that we need prior to opening the
1369 * underlying devices and cache them so that we can prevent
1370 * any I/O when we are doing the actual open.
1372 if (spa_is_root(spa
)) {
1373 int low
= locks
& ~(SCL_ZIO
- 1);
1374 int high
= locks
& ~low
;
1376 spa_config_enter(spa
, high
, spa
, RW_WRITER
);
1377 vdev_hold(spa
->spa_root_vdev
);
1378 spa_config_enter(spa
, low
, spa
, RW_WRITER
);
1380 spa_config_enter(spa
, locks
, spa
, RW_WRITER
);
1382 spa
->spa_vdev_locks
= locks
;
1386 spa_vdev_state_exit(spa_t
*spa
, vdev_t
*vd
, int error
)
1388 boolean_t config_changed
= B_FALSE
;
1391 if (vd
== NULL
|| vd
== spa
->spa_root_vdev
) {
1392 vdev_top
= spa
->spa_root_vdev
;
1394 vdev_top
= vd
->vdev_top
;
1397 if (vd
!= NULL
|| error
== 0)
1398 vdev_dtl_reassess(vdev_top
, 0, 0, B_FALSE
, B_FALSE
);
1401 if (vd
!= spa
->spa_root_vdev
)
1402 vdev_state_dirty(vdev_top
);
1404 config_changed
= B_TRUE
;
1405 spa
->spa_config_generation
++;
1408 if (spa_is_root(spa
))
1409 vdev_rele(spa
->spa_root_vdev
);
1411 ASSERT3U(spa
->spa_vdev_locks
, >=, SCL_STATE_ALL
);
1412 spa_config_exit(spa
, spa
->spa_vdev_locks
, spa
);
1415 * If anything changed, wait for it to sync. This ensures that,
1416 * from the system administrator's perspective, zpool(8) commands
1417 * are synchronous. This is important for things like zpool offline:
1418 * when the command completes, you expect no further I/O from ZFS.
1421 txg_wait_synced(spa
->spa_dsl_pool
, 0);
1424 * If the config changed, update the config cache.
1426 if (config_changed
) {
1427 mutex_enter(&spa_namespace_lock
);
1428 spa_write_cachefile(spa
, B_FALSE
, B_TRUE
, B_FALSE
);
1429 mutex_exit(&spa_namespace_lock
);
1436 * ==========================================================================
1437 * Miscellaneous functions
1438 * ==========================================================================
1442 spa_activate_mos_feature(spa_t
*spa
, const char *feature
, dmu_tx_t
*tx
)
1444 if (!nvlist_exists(spa
->spa_label_features
, feature
)) {
1445 fnvlist_add_boolean(spa
->spa_label_features
, feature
);
1447 * When we are creating the pool (tx_txg==TXG_INITIAL), we can't
1448 * dirty the vdev config because lock SCL_CONFIG is not held.
1449 * Thankfully, in this case we don't need to dirty the config
1450 * because it will be written out anyway when we finish
1451 * creating the pool.
1453 if (tx
->tx_txg
!= TXG_INITIAL
)
1454 vdev_config_dirty(spa
->spa_root_vdev
);
1459 spa_deactivate_mos_feature(spa_t
*spa
, const char *feature
)
1461 if (nvlist_remove_all(spa
->spa_label_features
, feature
) == 0)
1462 vdev_config_dirty(spa
->spa_root_vdev
);
1466 * Return the spa_t associated with given pool_guid, if it exists. If
1467 * device_guid is non-zero, determine whether the pool exists *and* contains
1468 * a device with the specified device_guid.
1471 spa_by_guid(uint64_t pool_guid
, uint64_t device_guid
)
1474 avl_tree_t
*t
= &spa_namespace_avl
;
1476 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
1478 for (spa
= avl_first(t
); spa
!= NULL
; spa
= AVL_NEXT(t
, spa
)) {
1479 if (spa
->spa_state
== POOL_STATE_UNINITIALIZED
)
1481 if (spa
->spa_root_vdev
== NULL
)
1483 if (spa_guid(spa
) == pool_guid
) {
1484 if (device_guid
== 0)
1487 if (vdev_lookup_by_guid(spa
->spa_root_vdev
,
1488 device_guid
) != NULL
)
1492 * Check any devices we may be in the process of adding.
1494 if (spa
->spa_pending_vdev
) {
1495 if (vdev_lookup_by_guid(spa
->spa_pending_vdev
,
1496 device_guid
) != NULL
)
1506 * Determine whether a pool with the given pool_guid exists.
1509 spa_guid_exists(uint64_t pool_guid
, uint64_t device_guid
)
1511 return (spa_by_guid(pool_guid
, device_guid
) != NULL
);
1515 spa_strdup(const char *s
)
1521 new = kmem_alloc(len
+ 1, KM_SLEEP
);
1522 memcpy(new, s
, len
+ 1);
1528 spa_strfree(char *s
)
1530 kmem_free(s
, strlen(s
) + 1);
1534 spa_generate_guid(spa_t
*spa
)
1540 (void) random_get_pseudo_bytes((void *)&guid
,
1542 } while (guid
== 0 || spa_guid_exists(spa_guid(spa
), guid
));
1545 (void) random_get_pseudo_bytes((void *)&guid
,
1547 } while (guid
== 0 || spa_guid_exists(guid
, 0));
1554 snprintf_blkptr(char *buf
, size_t buflen
, const blkptr_t
*bp
)
1557 const char *checksum
= NULL
;
1558 const char *compress
= NULL
;
1561 if (BP_GET_TYPE(bp
) & DMU_OT_NEWTYPE
) {
1562 dmu_object_byteswap_t bswap
=
1563 DMU_OT_BYTESWAP(BP_GET_TYPE(bp
));
1564 (void) snprintf(type
, sizeof (type
), "bswap %s %s",
1565 DMU_OT_IS_METADATA(BP_GET_TYPE(bp
)) ?
1566 "metadata" : "data",
1567 dmu_ot_byteswap
[bswap
].ob_name
);
1569 (void) strlcpy(type
, dmu_ot
[BP_GET_TYPE(bp
)].ot_name
,
1572 if (!BP_IS_EMBEDDED(bp
)) {
1574 zio_checksum_table
[BP_GET_CHECKSUM(bp
)].ci_name
;
1576 compress
= zio_compress_table
[BP_GET_COMPRESS(bp
)].ci_name
;
1579 SNPRINTF_BLKPTR(kmem_scnprintf
, ' ', buf
, buflen
, bp
, type
, checksum
,
1584 spa_freeze(spa_t
*spa
)
1586 uint64_t freeze_txg
= 0;
1588 spa_config_enter(spa
, SCL_ALL
, FTAG
, RW_WRITER
);
1589 if (spa
->spa_freeze_txg
== UINT64_MAX
) {
1590 freeze_txg
= spa_last_synced_txg(spa
) + TXG_SIZE
;
1591 spa
->spa_freeze_txg
= freeze_txg
;
1593 spa_config_exit(spa
, SCL_ALL
, FTAG
);
1594 if (freeze_txg
!= 0)
1595 txg_wait_synced(spa_get_dsl(spa
), freeze_txg
);
1599 zfs_panic_recover(const char *fmt
, ...)
1604 vcmn_err(zfs_recover
? CE_WARN
: CE_PANIC
, fmt
, adx
);
1609 * This is a stripped-down version of strtoull, suitable only for converting
1610 * lowercase hexadecimal numbers that don't overflow.
1613 zfs_strtonum(const char *str
, char **nptr
)
1619 while ((c
= *str
) != '\0') {
1620 if (c
>= '0' && c
<= '9')
1622 else if (c
>= 'a' && c
<= 'f')
1623 digit
= 10 + c
- 'a';
1634 *nptr
= (char *)str
;
1640 spa_activate_allocation_classes(spa_t
*spa
, dmu_tx_t
*tx
)
1643 * We bump the feature refcount for each special vdev added to the pool
1645 ASSERT(spa_feature_is_enabled(spa
, SPA_FEATURE_ALLOCATION_CLASSES
));
1646 spa_feature_incr(spa
, SPA_FEATURE_ALLOCATION_CLASSES
, tx
);
1650 * ==========================================================================
1651 * Accessor functions
1652 * ==========================================================================
1656 spa_shutting_down(spa_t
*spa
)
1658 return (spa
->spa_async_suspended
);
1662 spa_get_dsl(spa_t
*spa
)
1664 return (spa
->spa_dsl_pool
);
1668 spa_is_initializing(spa_t
*spa
)
1670 return (spa
->spa_is_initializing
);
1674 spa_indirect_vdevs_loaded(spa_t
*spa
)
1676 return (spa
->spa_indirect_vdevs_loaded
);
1680 spa_get_rootblkptr(spa_t
*spa
)
1682 return (&spa
->spa_ubsync
.ub_rootbp
);
1686 spa_set_rootblkptr(spa_t
*spa
, const blkptr_t
*bp
)
1688 spa
->spa_uberblock
.ub_rootbp
= *bp
;
1692 spa_altroot(spa_t
*spa
, char *buf
, size_t buflen
)
1694 if (spa
->spa_root
== NULL
)
1697 (void) strlcpy(buf
, spa
->spa_root
, buflen
);
1701 spa_sync_pass(spa_t
*spa
)
1703 return (spa
->spa_sync_pass
);
1707 spa_name(spa_t
*spa
)
1709 return (spa
->spa_name
);
1713 spa_guid(spa_t
*spa
)
1715 dsl_pool_t
*dp
= spa_get_dsl(spa
);
1719 * If we fail to parse the config during spa_load(), we can go through
1720 * the error path (which posts an ereport) and end up here with no root
1721 * vdev. We stash the original pool guid in 'spa_config_guid' to handle
1724 if (spa
->spa_root_vdev
== NULL
)
1725 return (spa
->spa_config_guid
);
1727 guid
= spa
->spa_last_synced_guid
!= 0 ?
1728 spa
->spa_last_synced_guid
: spa
->spa_root_vdev
->vdev_guid
;
1731 * Return the most recently synced out guid unless we're
1732 * in syncing context.
1734 if (dp
&& dsl_pool_sync_context(dp
))
1735 return (spa
->spa_root_vdev
->vdev_guid
);
1741 spa_load_guid(spa_t
*spa
)
1744 * This is a GUID that exists solely as a reference for the
1745 * purposes of the arc. It is generated at load time, and
1746 * is never written to persistent storage.
1748 return (spa
->spa_load_guid
);
1752 spa_last_synced_txg(spa_t
*spa
)
1754 return (spa
->spa_ubsync
.ub_txg
);
1758 spa_first_txg(spa_t
*spa
)
1760 return (spa
->spa_first_txg
);
1764 spa_syncing_txg(spa_t
*spa
)
1766 return (spa
->spa_syncing_txg
);
1770 * Return the last txg where data can be dirtied. The final txgs
1771 * will be used to just clear out any deferred frees that remain.
1774 spa_final_dirty_txg(spa_t
*spa
)
1776 return (spa
->spa_final_txg
- TXG_DEFER_SIZE
);
1780 spa_state(spa_t
*spa
)
1782 return (spa
->spa_state
);
1786 spa_load_state(spa_t
*spa
)
1788 return (spa
->spa_load_state
);
1792 spa_freeze_txg(spa_t
*spa
)
1794 return (spa
->spa_freeze_txg
);
1798 * Return the inflated asize for a logical write in bytes. This is used by the
1799 * DMU to calculate the space a logical write will require on disk.
1800 * If lsize is smaller than the largest physical block size allocatable on this
1801 * pool we use its value instead, since the write will end up using the whole
1805 spa_get_worst_case_asize(spa_t
*spa
, uint64_t lsize
)
1808 return (0); /* No inflation needed */
1809 return (MAX(lsize
, 1 << spa
->spa_max_ashift
) * spa_asize_inflation
);
1813 * Return the amount of slop space in bytes. It is typically 1/32 of the pool
1814 * (3.2%), minus the embedded log space. On very small pools, it may be
1815 * slightly larger than this. On very large pools, it will be capped to
1816 * the value of spa_max_slop. The embedded log space is not included in
1817 * spa_dspace. By subtracting it, the usable space (per "zfs list") is a
1818 * constant 97% of the total space, regardless of metaslab size (assuming the
1819 * default spa_slop_shift=5 and a non-tiny pool).
1821 * See the comment above spa_slop_shift for more details.
1824 spa_get_slop_space(spa_t
*spa
)
1830 * Make sure spa_dedup_dspace has been set.
1832 if (spa
->spa_dedup_dspace
== ~0ULL)
1833 spa_update_dspace(spa
);
1836 * spa_get_dspace() includes the space only logically "used" by
1837 * deduplicated data, so since it's not useful to reserve more
1838 * space with more deduplicated data, we subtract that out here.
1840 space
= spa_get_dspace(spa
) - spa
->spa_dedup_dspace
;
1841 slop
= MIN(space
>> spa_slop_shift
, spa_max_slop
);
1844 * Subtract the embedded log space, but no more than half the (3.2%)
1845 * unusable space. Note, the "no more than half" is only relevant if
1846 * zfs_embedded_slog_min_ms >> spa_slop_shift < 2, which is not true by
1849 uint64_t embedded_log
=
1850 metaslab_class_get_dspace(spa_embedded_log_class(spa
));
1851 slop
-= MIN(embedded_log
, slop
>> 1);
1854 * Slop space should be at least spa_min_slop, but no more than half
1857 slop
= MAX(slop
, MIN(space
>> 1, spa_min_slop
));
1862 spa_get_dspace(spa_t
*spa
)
1864 return (spa
->spa_dspace
);
1868 spa_get_checkpoint_space(spa_t
*spa
)
1870 return (spa
->spa_checkpoint_info
.sci_dspace
);
1874 spa_update_dspace(spa_t
*spa
)
1876 spa
->spa_dspace
= metaslab_class_get_dspace(spa_normal_class(spa
)) +
1877 ddt_get_dedup_dspace(spa
) + brt_get_dspace(spa
);
1878 if (spa
->spa_nonallocating_dspace
> 0) {
1880 * Subtract the space provided by all non-allocating vdevs that
1881 * contribute to dspace. If a file is overwritten, its old
1882 * blocks are freed and new blocks are allocated. If there are
1883 * no snapshots of the file, the available space should remain
1884 * the same. The old blocks could be freed from the
1885 * non-allocating vdev, but the new blocks must be allocated on
1886 * other (allocating) vdevs. By reserving the entire size of
1887 * the non-allocating vdevs (including allocated space), we
1888 * ensure that there will be enough space on the allocating
1889 * vdevs for this file overwrite to succeed.
1891 * Note that the DMU/DSL doesn't actually know or care
1892 * how much space is allocated (it does its own tracking
1893 * of how much space has been logically used). So it
1894 * doesn't matter that the data we are moving may be
1895 * allocated twice (on the old device and the new device).
1897 ASSERT3U(spa
->spa_dspace
, >=, spa
->spa_nonallocating_dspace
);
1898 spa
->spa_dspace
-= spa
->spa_nonallocating_dspace
;
1903 * Return the failure mode that has been set to this pool. The default
1904 * behavior will be to block all I/Os when a complete failure occurs.
1907 spa_get_failmode(spa_t
*spa
)
1909 return (spa
->spa_failmode
);
1913 spa_suspended(spa_t
*spa
)
1915 return (spa
->spa_suspended
!= ZIO_SUSPEND_NONE
);
1919 spa_version(spa_t
*spa
)
1921 return (spa
->spa_ubsync
.ub_version
);
1925 spa_deflate(spa_t
*spa
)
1927 return (spa
->spa_deflate
);
1931 spa_normal_class(spa_t
*spa
)
1933 return (spa
->spa_normal_class
);
1937 spa_log_class(spa_t
*spa
)
1939 return (spa
->spa_log_class
);
1943 spa_embedded_log_class(spa_t
*spa
)
1945 return (spa
->spa_embedded_log_class
);
1949 spa_special_class(spa_t
*spa
)
1951 return (spa
->spa_special_class
);
1955 spa_dedup_class(spa_t
*spa
)
1957 return (spa
->spa_dedup_class
);
1961 * Locate an appropriate allocation class
1964 spa_preferred_class(spa_t
*spa
, uint64_t size
, dmu_object_type_t objtype
,
1965 uint_t level
, uint_t special_smallblk
)
1968 * ZIL allocations determine their class in zio_alloc_zil().
1970 ASSERT(objtype
!= DMU_OT_INTENT_LOG
);
1972 boolean_t has_special_class
= spa
->spa_special_class
->mc_groups
!= 0;
1974 if (DMU_OT_IS_DDT(objtype
)) {
1975 if (spa
->spa_dedup_class
->mc_groups
!= 0)
1976 return (spa_dedup_class(spa
));
1977 else if (has_special_class
&& zfs_ddt_data_is_special
)
1978 return (spa_special_class(spa
));
1980 return (spa_normal_class(spa
));
1983 /* Indirect blocks for user data can land in special if allowed */
1984 if (level
> 0 && (DMU_OT_IS_FILE(objtype
) || objtype
== DMU_OT_ZVOL
)) {
1985 if (has_special_class
&& zfs_user_indirect_is_special
)
1986 return (spa_special_class(spa
));
1988 return (spa_normal_class(spa
));
1991 if (DMU_OT_IS_METADATA(objtype
) || level
> 0) {
1992 if (has_special_class
)
1993 return (spa_special_class(spa
));
1995 return (spa_normal_class(spa
));
1999 * Allow small file blocks in special class in some cases (like
2000 * for the dRAID vdev feature). But always leave a reserve of
2001 * zfs_special_class_metadata_reserve_pct exclusively for metadata.
2003 if (DMU_OT_IS_FILE(objtype
) &&
2004 has_special_class
&& size
<= special_smallblk
) {
2005 metaslab_class_t
*special
= spa_special_class(spa
);
2006 uint64_t alloc
= metaslab_class_get_alloc(special
);
2007 uint64_t space
= metaslab_class_get_space(special
);
2009 (space
* (100 - zfs_special_class_metadata_reserve_pct
))
2016 return (spa_normal_class(spa
));
2020 spa_evicting_os_register(spa_t
*spa
, objset_t
*os
)
2022 mutex_enter(&spa
->spa_evicting_os_lock
);
2023 list_insert_head(&spa
->spa_evicting_os_list
, os
);
2024 mutex_exit(&spa
->spa_evicting_os_lock
);
2028 spa_evicting_os_deregister(spa_t
*spa
, objset_t
*os
)
2030 mutex_enter(&spa
->spa_evicting_os_lock
);
2031 list_remove(&spa
->spa_evicting_os_list
, os
);
2032 cv_broadcast(&spa
->spa_evicting_os_cv
);
2033 mutex_exit(&spa
->spa_evicting_os_lock
);
2037 spa_evicting_os_wait(spa_t
*spa
)
2039 mutex_enter(&spa
->spa_evicting_os_lock
);
2040 while (!list_is_empty(&spa
->spa_evicting_os_list
))
2041 cv_wait(&spa
->spa_evicting_os_cv
, &spa
->spa_evicting_os_lock
);
2042 mutex_exit(&spa
->spa_evicting_os_lock
);
2044 dmu_buf_user_evict_wait();
2048 spa_max_replication(spa_t
*spa
)
2051 * As of SPA_VERSION == SPA_VERSION_DITTO_BLOCKS, we are able to
2052 * handle BPs with more than one DVA allocated. Set our max
2053 * replication level accordingly.
2055 if (spa_version(spa
) < SPA_VERSION_DITTO_BLOCKS
)
2057 return (MIN(SPA_DVAS_PER_BP
, spa_max_replication_override
));
2061 spa_prev_software_version(spa_t
*spa
)
2063 return (spa
->spa_prev_software_version
);
2067 spa_deadman_synctime(spa_t
*spa
)
2069 return (spa
->spa_deadman_synctime
);
2073 spa_get_autotrim(spa_t
*spa
)
2075 return (spa
->spa_autotrim
);
2079 spa_deadman_ziotime(spa_t
*spa
)
2081 return (spa
->spa_deadman_ziotime
);
2085 spa_get_deadman_failmode(spa_t
*spa
)
2087 return (spa
->spa_deadman_failmode
);
2091 spa_set_deadman_failmode(spa_t
*spa
, const char *failmode
)
2093 if (strcmp(failmode
, "wait") == 0)
2094 spa
->spa_deadman_failmode
= ZIO_FAILURE_MODE_WAIT
;
2095 else if (strcmp(failmode
, "continue") == 0)
2096 spa
->spa_deadman_failmode
= ZIO_FAILURE_MODE_CONTINUE
;
2097 else if (strcmp(failmode
, "panic") == 0)
2098 spa
->spa_deadman_failmode
= ZIO_FAILURE_MODE_PANIC
;
2100 spa
->spa_deadman_failmode
= ZIO_FAILURE_MODE_WAIT
;
2104 spa_set_deadman_ziotime(hrtime_t ns
)
2108 if (spa_mode_global
!= SPA_MODE_UNINIT
) {
2109 mutex_enter(&spa_namespace_lock
);
2110 while ((spa
= spa_next(spa
)) != NULL
)
2111 spa
->spa_deadman_ziotime
= ns
;
2112 mutex_exit(&spa_namespace_lock
);
2117 spa_set_deadman_synctime(hrtime_t ns
)
2121 if (spa_mode_global
!= SPA_MODE_UNINIT
) {
2122 mutex_enter(&spa_namespace_lock
);
2123 while ((spa
= spa_next(spa
)) != NULL
)
2124 spa
->spa_deadman_synctime
= ns
;
2125 mutex_exit(&spa_namespace_lock
);
2130 dva_get_dsize_sync(spa_t
*spa
, const dva_t
*dva
)
2132 uint64_t asize
= DVA_GET_ASIZE(dva
);
2133 uint64_t dsize
= asize
;
2135 ASSERT(spa_config_held(spa
, SCL_ALL
, RW_READER
) != 0);
2137 if (asize
!= 0 && spa
->spa_deflate
) {
2138 vdev_t
*vd
= vdev_lookup_top(spa
, DVA_GET_VDEV(dva
));
2140 dsize
= (asize
>> SPA_MINBLOCKSHIFT
) *
2141 vd
->vdev_deflate_ratio
;
2148 bp_get_dsize_sync(spa_t
*spa
, const blkptr_t
*bp
)
2152 for (int d
= 0; d
< BP_GET_NDVAS(bp
); d
++)
2153 dsize
+= dva_get_dsize_sync(spa
, &bp
->blk_dva
[d
]);
2159 bp_get_dsize(spa_t
*spa
, const blkptr_t
*bp
)
2163 spa_config_enter(spa
, SCL_VDEV
, FTAG
, RW_READER
);
2165 for (int d
= 0; d
< BP_GET_NDVAS(bp
); d
++)
2166 dsize
+= dva_get_dsize_sync(spa
, &bp
->blk_dva
[d
]);
2168 spa_config_exit(spa
, SCL_VDEV
, FTAG
);
2174 spa_dirty_data(spa_t
*spa
)
2176 return (spa
->spa_dsl_pool
->dp_dirty_total
);
2180 * ==========================================================================
2181 * SPA Import Progress Routines
2182 * ==========================================================================
2185 typedef struct spa_import_progress
{
2186 uint64_t pool_guid
; /* unique id for updates */
2188 spa_load_state_t spa_load_state
;
2189 char *spa_load_notes
;
2190 uint64_t mmp_sec_remaining
; /* MMP activity check */
2191 uint64_t spa_load_max_txg
; /* rewind txg */
2192 procfs_list_node_t smh_node
;
2193 } spa_import_progress_t
;
2195 spa_history_list_t
*spa_import_progress_list
= NULL
;
2198 spa_import_progress_show_header(struct seq_file
*f
)
2200 seq_printf(f
, "%-20s %-14s %-14s %-12s %-16s %s\n", "pool_guid",
2201 "load_state", "multihost_secs", "max_txg",
2202 "pool_name", "notes");
2207 spa_import_progress_show(struct seq_file
*f
, void *data
)
2209 spa_import_progress_t
*sip
= (spa_import_progress_t
*)data
;
2211 seq_printf(f
, "%-20llu %-14llu %-14llu %-12llu %-16s %s\n",
2212 (u_longlong_t
)sip
->pool_guid
, (u_longlong_t
)sip
->spa_load_state
,
2213 (u_longlong_t
)sip
->mmp_sec_remaining
,
2214 (u_longlong_t
)sip
->spa_load_max_txg
,
2215 (sip
->pool_name
? sip
->pool_name
: "-"),
2216 (sip
->spa_load_notes
? sip
->spa_load_notes
: "-"));
2221 /* Remove oldest elements from list until there are no more than 'size' left */
2223 spa_import_progress_truncate(spa_history_list_t
*shl
, unsigned int size
)
2225 spa_import_progress_t
*sip
;
2226 while (shl
->size
> size
) {
2227 sip
= list_remove_head(&shl
->procfs_list
.pl_list
);
2229 spa_strfree(sip
->pool_name
);
2230 if (sip
->spa_load_notes
)
2231 kmem_strfree(sip
->spa_load_notes
);
2232 kmem_free(sip
, sizeof (spa_import_progress_t
));
2236 IMPLY(size
== 0, list_is_empty(&shl
->procfs_list
.pl_list
));
2240 spa_import_progress_init(void)
2242 spa_import_progress_list
= kmem_zalloc(sizeof (spa_history_list_t
),
2245 spa_import_progress_list
->size
= 0;
2247 spa_import_progress_list
->procfs_list
.pl_private
=
2248 spa_import_progress_list
;
2250 procfs_list_install("zfs",
2254 &spa_import_progress_list
->procfs_list
,
2255 spa_import_progress_show
,
2256 spa_import_progress_show_header
,
2258 offsetof(spa_import_progress_t
, smh_node
));
2262 spa_import_progress_destroy(void)
2264 spa_history_list_t
*shl
= spa_import_progress_list
;
2265 procfs_list_uninstall(&shl
->procfs_list
);
2266 spa_import_progress_truncate(shl
, 0);
2267 procfs_list_destroy(&shl
->procfs_list
);
2268 kmem_free(shl
, sizeof (spa_history_list_t
));
2272 spa_import_progress_set_state(uint64_t pool_guid
,
2273 spa_load_state_t load_state
)
2275 spa_history_list_t
*shl
= spa_import_progress_list
;
2276 spa_import_progress_t
*sip
;
2282 mutex_enter(&shl
->procfs_list
.pl_lock
);
2283 for (sip
= list_tail(&shl
->procfs_list
.pl_list
); sip
!= NULL
;
2284 sip
= list_prev(&shl
->procfs_list
.pl_list
, sip
)) {
2285 if (sip
->pool_guid
== pool_guid
) {
2286 sip
->spa_load_state
= load_state
;
2287 if (sip
->spa_load_notes
!= NULL
) {
2288 kmem_strfree(sip
->spa_load_notes
);
2289 sip
->spa_load_notes
= NULL
;
2295 mutex_exit(&shl
->procfs_list
.pl_lock
);
2301 spa_import_progress_set_notes_impl(spa_t
*spa
, boolean_t log_dbgmsg
,
2302 const char *fmt
, va_list adx
)
2304 spa_history_list_t
*shl
= spa_import_progress_list
;
2305 spa_import_progress_t
*sip
;
2306 uint64_t pool_guid
= spa_guid(spa
);
2311 char *notes
= kmem_vasprintf(fmt
, adx
);
2313 mutex_enter(&shl
->procfs_list
.pl_lock
);
2314 for (sip
= list_tail(&shl
->procfs_list
.pl_list
); sip
!= NULL
;
2315 sip
= list_prev(&shl
->procfs_list
.pl_list
, sip
)) {
2316 if (sip
->pool_guid
== pool_guid
) {
2317 if (sip
->spa_load_notes
!= NULL
) {
2318 kmem_strfree(sip
->spa_load_notes
);
2319 sip
->spa_load_notes
= NULL
;
2321 sip
->spa_load_notes
= notes
;
2323 zfs_dbgmsg("'%s' %s", sip
->pool_name
, notes
);
2328 mutex_exit(&shl
->procfs_list
.pl_lock
);
2330 kmem_strfree(notes
);
2334 spa_import_progress_set_notes(spa_t
*spa
, const char *fmt
, ...)
2339 spa_import_progress_set_notes_impl(spa
, B_TRUE
, fmt
, adx
);
2344 spa_import_progress_set_notes_nolog(spa_t
*spa
, const char *fmt
, ...)
2349 spa_import_progress_set_notes_impl(spa
, B_FALSE
, fmt
, adx
);
2354 spa_import_progress_set_max_txg(uint64_t pool_guid
, uint64_t load_max_txg
)
2356 spa_history_list_t
*shl
= spa_import_progress_list
;
2357 spa_import_progress_t
*sip
;
2363 mutex_enter(&shl
->procfs_list
.pl_lock
);
2364 for (sip
= list_tail(&shl
->procfs_list
.pl_list
); sip
!= NULL
;
2365 sip
= list_prev(&shl
->procfs_list
.pl_list
, sip
)) {
2366 if (sip
->pool_guid
== pool_guid
) {
2367 sip
->spa_load_max_txg
= load_max_txg
;
2372 mutex_exit(&shl
->procfs_list
.pl_lock
);
2378 spa_import_progress_set_mmp_check(uint64_t pool_guid
,
2379 uint64_t mmp_sec_remaining
)
2381 spa_history_list_t
*shl
= spa_import_progress_list
;
2382 spa_import_progress_t
*sip
;
2388 mutex_enter(&shl
->procfs_list
.pl_lock
);
2389 for (sip
= list_tail(&shl
->procfs_list
.pl_list
); sip
!= NULL
;
2390 sip
= list_prev(&shl
->procfs_list
.pl_list
, sip
)) {
2391 if (sip
->pool_guid
== pool_guid
) {
2392 sip
->mmp_sec_remaining
= mmp_sec_remaining
;
2397 mutex_exit(&shl
->procfs_list
.pl_lock
);
2403 * A new import is in progress, add an entry.
2406 spa_import_progress_add(spa_t
*spa
)
2408 spa_history_list_t
*shl
= spa_import_progress_list
;
2409 spa_import_progress_t
*sip
;
2410 const char *poolname
= NULL
;
2412 sip
= kmem_zalloc(sizeof (spa_import_progress_t
), KM_SLEEP
);
2413 sip
->pool_guid
= spa_guid(spa
);
2415 (void) nvlist_lookup_string(spa
->spa_config
, ZPOOL_CONFIG_POOL_NAME
,
2417 if (poolname
== NULL
)
2418 poolname
= spa_name(spa
);
2419 sip
->pool_name
= spa_strdup(poolname
);
2420 sip
->spa_load_state
= spa_load_state(spa
);
2421 sip
->spa_load_notes
= NULL
;
2423 mutex_enter(&shl
->procfs_list
.pl_lock
);
2424 procfs_list_add(&shl
->procfs_list
, sip
);
2426 mutex_exit(&shl
->procfs_list
.pl_lock
);
2430 spa_import_progress_remove(uint64_t pool_guid
)
2432 spa_history_list_t
*shl
= spa_import_progress_list
;
2433 spa_import_progress_t
*sip
;
2435 mutex_enter(&shl
->procfs_list
.pl_lock
);
2436 for (sip
= list_tail(&shl
->procfs_list
.pl_list
); sip
!= NULL
;
2437 sip
= list_prev(&shl
->procfs_list
.pl_list
, sip
)) {
2438 if (sip
->pool_guid
== pool_guid
) {
2440 spa_strfree(sip
->pool_name
);
2441 if (sip
->spa_load_notes
)
2442 spa_strfree(sip
->spa_load_notes
);
2443 list_remove(&shl
->procfs_list
.pl_list
, sip
);
2445 kmem_free(sip
, sizeof (spa_import_progress_t
));
2449 mutex_exit(&shl
->procfs_list
.pl_lock
);
2453 * ==========================================================================
2454 * Initialization and Termination
2455 * ==========================================================================
2459 spa_name_compare(const void *a1
, const void *a2
)
2461 const spa_t
*s1
= a1
;
2462 const spa_t
*s2
= a2
;
2465 s
= strcmp(s1
->spa_name
, s2
->spa_name
);
2467 return (TREE_ISIGN(s
));
2477 spa_init(spa_mode_t mode
)
2479 mutex_init(&spa_namespace_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
2480 mutex_init(&spa_spare_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
2481 mutex_init(&spa_l2cache_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
2482 cv_init(&spa_namespace_cv
, NULL
, CV_DEFAULT
, NULL
);
2484 avl_create(&spa_namespace_avl
, spa_name_compare
, sizeof (spa_t
),
2485 offsetof(spa_t
, spa_avl
));
2487 avl_create(&spa_spare_avl
, spa_spare_compare
, sizeof (spa_aux_t
),
2488 offsetof(spa_aux_t
, aux_avl
));
2490 avl_create(&spa_l2cache_avl
, spa_l2cache_compare
, sizeof (spa_aux_t
),
2491 offsetof(spa_aux_t
, aux_avl
));
2493 spa_mode_global
= mode
;
2496 if (spa_mode_global
!= SPA_MODE_READ
&& dprintf_find_string("watch")) {
2497 struct sigaction sa
;
2499 sa
.sa_flags
= SA_SIGINFO
;
2500 sigemptyset(&sa
.sa_mask
);
2501 sa
.sa_sigaction
= arc_buf_sigsegv
;
2503 if (sigaction(SIGSEGV
, &sa
, NULL
) == -1) {
2504 perror("could not enable watchpoints: "
2505 "sigaction(SIGSEGV, ...) = ");
2513 zfs_refcount_init();
2516 metaslab_stat_init();
2522 vdev_mirror_stat_init();
2523 vdev_raidz_math_init();
2528 zpool_feature_init();
2534 spa_import_progress_init();
2545 vdev_mirror_stat_fini();
2546 vdev_raidz_math_fini();
2553 metaslab_stat_fini();
2556 zfs_refcount_fini();
2560 spa_import_progress_destroy();
2562 avl_destroy(&spa_namespace_avl
);
2563 avl_destroy(&spa_spare_avl
);
2564 avl_destroy(&spa_l2cache_avl
);
2566 cv_destroy(&spa_namespace_cv
);
2567 mutex_destroy(&spa_namespace_lock
);
2568 mutex_destroy(&spa_spare_lock
);
2569 mutex_destroy(&spa_l2cache_lock
);
2573 * Return whether this pool has a dedicated slog device. No locking needed.
2574 * It's not a problem if the wrong answer is returned as it's only for
2575 * performance and not correctness.
2578 spa_has_slogs(spa_t
*spa
)
2580 return (spa
->spa_log_class
->mc_groups
!= 0);
2584 spa_get_log_state(spa_t
*spa
)
2586 return (spa
->spa_log_state
);
2590 spa_set_log_state(spa_t
*spa
, spa_log_state_t state
)
2592 spa
->spa_log_state
= state
;
2596 spa_is_root(spa_t
*spa
)
2598 return (spa
->spa_is_root
);
2602 spa_writeable(spa_t
*spa
)
2604 return (!!(spa
->spa_mode
& SPA_MODE_WRITE
) && spa
->spa_trust_config
);
2608 * Returns true if there is a pending sync task in any of the current
2609 * syncing txg, the current quiescing txg, or the current open txg.
2612 spa_has_pending_synctask(spa_t
*spa
)
2614 return (!txg_all_lists_empty(&spa
->spa_dsl_pool
->dp_sync_tasks
) ||
2615 !txg_all_lists_empty(&spa
->spa_dsl_pool
->dp_early_sync_tasks
));
2619 spa_mode(spa_t
*spa
)
2621 return (spa
->spa_mode
);
2625 spa_bootfs(spa_t
*spa
)
2627 return (spa
->spa_bootfs
);
2631 spa_delegation(spa_t
*spa
)
2633 return (spa
->spa_delegation
);
2637 spa_meta_objset(spa_t
*spa
)
2639 return (spa
->spa_meta_objset
);
2643 spa_dedup_checksum(spa_t
*spa
)
2645 return (spa
->spa_dedup_checksum
);
2649 * Reset pool scan stat per scan pass (or reboot).
2652 spa_scan_stat_init(spa_t
*spa
)
2654 /* data not stored on disk */
2655 spa
->spa_scan_pass_start
= gethrestime_sec();
2656 if (dsl_scan_is_paused_scrub(spa
->spa_dsl_pool
->dp_scan
))
2657 spa
->spa_scan_pass_scrub_pause
= spa
->spa_scan_pass_start
;
2659 spa
->spa_scan_pass_scrub_pause
= 0;
2661 if (dsl_errorscrub_is_paused(spa
->spa_dsl_pool
->dp_scan
))
2662 spa
->spa_scan_pass_errorscrub_pause
= spa
->spa_scan_pass_start
;
2664 spa
->spa_scan_pass_errorscrub_pause
= 0;
2666 spa
->spa_scan_pass_scrub_spent_paused
= 0;
2667 spa
->spa_scan_pass_exam
= 0;
2668 spa
->spa_scan_pass_issued
= 0;
2670 // error scrub stats
2671 spa
->spa_scan_pass_errorscrub_spent_paused
= 0;
2675 * Get scan stats for zpool status reports
2678 spa_scan_get_stats(spa_t
*spa
, pool_scan_stat_t
*ps
)
2680 dsl_scan_t
*scn
= spa
->spa_dsl_pool
? spa
->spa_dsl_pool
->dp_scan
: NULL
;
2682 if (scn
== NULL
|| (scn
->scn_phys
.scn_func
== POOL_SCAN_NONE
&&
2683 scn
->errorscrub_phys
.dep_func
== POOL_SCAN_NONE
))
2684 return (SET_ERROR(ENOENT
));
2686 memset(ps
, 0, sizeof (pool_scan_stat_t
));
2688 /* data stored on disk */
2689 ps
->pss_func
= scn
->scn_phys
.scn_func
;
2690 ps
->pss_state
= scn
->scn_phys
.scn_state
;
2691 ps
->pss_start_time
= scn
->scn_phys
.scn_start_time
;
2692 ps
->pss_end_time
= scn
->scn_phys
.scn_end_time
;
2693 ps
->pss_to_examine
= scn
->scn_phys
.scn_to_examine
;
2694 ps
->pss_examined
= scn
->scn_phys
.scn_examined
;
2695 ps
->pss_skipped
= scn
->scn_phys
.scn_skipped
;
2696 ps
->pss_processed
= scn
->scn_phys
.scn_processed
;
2697 ps
->pss_errors
= scn
->scn_phys
.scn_errors
;
2699 /* data not stored on disk */
2700 ps
->pss_pass_exam
= spa
->spa_scan_pass_exam
;
2701 ps
->pss_pass_start
= spa
->spa_scan_pass_start
;
2702 ps
->pss_pass_scrub_pause
= spa
->spa_scan_pass_scrub_pause
;
2703 ps
->pss_pass_scrub_spent_paused
= spa
->spa_scan_pass_scrub_spent_paused
;
2704 ps
->pss_pass_issued
= spa
->spa_scan_pass_issued
;
2706 scn
->scn_issued_before_pass
+ spa
->spa_scan_pass_issued
;
2708 /* error scrub data stored on disk */
2709 ps
->pss_error_scrub_func
= scn
->errorscrub_phys
.dep_func
;
2710 ps
->pss_error_scrub_state
= scn
->errorscrub_phys
.dep_state
;
2711 ps
->pss_error_scrub_start
= scn
->errorscrub_phys
.dep_start_time
;
2712 ps
->pss_error_scrub_end
= scn
->errorscrub_phys
.dep_end_time
;
2713 ps
->pss_error_scrub_examined
= scn
->errorscrub_phys
.dep_examined
;
2714 ps
->pss_error_scrub_to_be_examined
=
2715 scn
->errorscrub_phys
.dep_to_examine
;
2717 /* error scrub data not stored on disk */
2718 ps
->pss_pass_error_scrub_pause
= spa
->spa_scan_pass_errorscrub_pause
;
2724 spa_maxblocksize(spa_t
*spa
)
2726 if (spa_feature_is_enabled(spa
, SPA_FEATURE_LARGE_BLOCKS
))
2727 return (SPA_MAXBLOCKSIZE
);
2729 return (SPA_OLD_MAXBLOCKSIZE
);
2734 * Returns the txg that the last device removal completed. No indirect mappings
2735 * have been added since this txg.
2738 spa_get_last_removal_txg(spa_t
*spa
)
2741 uint64_t ret
= -1ULL;
2743 spa_config_enter(spa
, SCL_VDEV
, FTAG
, RW_READER
);
2745 * sr_prev_indirect_vdev is only modified while holding all the
2746 * config locks, so it is sufficient to hold SCL_VDEV as reader when
2749 vdevid
= spa
->spa_removing_phys
.sr_prev_indirect_vdev
;
2751 while (vdevid
!= -1ULL) {
2752 vdev_t
*vd
= vdev_lookup_top(spa
, vdevid
);
2753 vdev_indirect_births_t
*vib
= vd
->vdev_indirect_births
;
2755 ASSERT3P(vd
->vdev_ops
, ==, &vdev_indirect_ops
);
2758 * If the removal did not remap any data, we don't care.
2760 if (vdev_indirect_births_count(vib
) != 0) {
2761 ret
= vdev_indirect_births_last_entry_txg(vib
);
2765 vdevid
= vd
->vdev_indirect_config
.vic_prev_indirect_vdev
;
2767 spa_config_exit(spa
, SCL_VDEV
, FTAG
);
2770 spa_feature_is_active(spa
, SPA_FEATURE_DEVICE_REMOVAL
));
2776 spa_maxdnodesize(spa_t
*spa
)
2778 if (spa_feature_is_enabled(spa
, SPA_FEATURE_LARGE_DNODE
))
2779 return (DNODE_MAX_SIZE
);
2781 return (DNODE_MIN_SIZE
);
2785 spa_multihost(spa_t
*spa
)
2787 return (spa
->spa_multihost
? B_TRUE
: B_FALSE
);
2791 spa_get_hostid(spa_t
*spa
)
2793 return (spa
->spa_hostid
);
2797 spa_trust_config(spa_t
*spa
)
2799 return (spa
->spa_trust_config
);
2803 spa_missing_tvds_allowed(spa_t
*spa
)
2805 return (spa
->spa_missing_tvds_allowed
);
2809 spa_syncing_log_sm(spa_t
*spa
)
2811 return (spa
->spa_syncing_log_sm
);
2815 spa_set_missing_tvds(spa_t
*spa
, uint64_t missing
)
2817 spa
->spa_missing_tvds
= missing
;
2821 * Return the pool state string ("ONLINE", "DEGRADED", "SUSPENDED", etc).
2824 spa_state_to_name(spa_t
*spa
)
2826 ASSERT3P(spa
, !=, NULL
);
2829 * it is possible for the spa to exist, without root vdev
2830 * as the spa transitions during import/export
2832 vdev_t
*rvd
= spa
->spa_root_vdev
;
2834 return ("TRANSITIONING");
2836 vdev_state_t state
= rvd
->vdev_state
;
2837 vdev_aux_t aux
= rvd
->vdev_stat
.vs_aux
;
2839 if (spa_suspended(spa
))
2840 return ("SUSPENDED");
2843 case VDEV_STATE_CLOSED
:
2844 case VDEV_STATE_OFFLINE
:
2846 case VDEV_STATE_REMOVED
:
2848 case VDEV_STATE_CANT_OPEN
:
2849 if (aux
== VDEV_AUX_CORRUPT_DATA
|| aux
== VDEV_AUX_BAD_LOG
)
2851 else if (aux
== VDEV_AUX_SPLIT_POOL
)
2855 case VDEV_STATE_FAULTED
:
2857 case VDEV_STATE_DEGRADED
:
2858 return ("DEGRADED");
2859 case VDEV_STATE_HEALTHY
:
2869 spa_top_vdevs_spacemap_addressable(spa_t
*spa
)
2871 vdev_t
*rvd
= spa
->spa_root_vdev
;
2872 for (uint64_t c
= 0; c
< rvd
->vdev_children
; c
++) {
2873 if (!vdev_is_spacemap_addressable(rvd
->vdev_child
[c
]))
2880 spa_has_checkpoint(spa_t
*spa
)
2882 return (spa
->spa_checkpoint_txg
!= 0);
2886 spa_importing_readonly_checkpoint(spa_t
*spa
)
2888 return ((spa
->spa_import_flags
& ZFS_IMPORT_CHECKPOINT
) &&
2889 spa
->spa_mode
== SPA_MODE_READ
);
2893 spa_min_claim_txg(spa_t
*spa
)
2895 uint64_t checkpoint_txg
= spa
->spa_uberblock
.ub_checkpoint_txg
;
2897 if (checkpoint_txg
!= 0)
2898 return (checkpoint_txg
+ 1);
2900 return (spa
->spa_first_txg
);
2904 * If there is a checkpoint, async destroys may consume more space from
2905 * the pool instead of freeing it. In an attempt to save the pool from
2906 * getting suspended when it is about to run out of space, we stop
2907 * processing async destroys.
2910 spa_suspend_async_destroy(spa_t
*spa
)
2912 dsl_pool_t
*dp
= spa_get_dsl(spa
);
2914 uint64_t unreserved
= dsl_pool_unreserved_space(dp
,
2915 ZFS_SPACE_CHECK_EXTRA_RESERVED
);
2916 uint64_t used
= dsl_dir_phys(dp
->dp_root_dir
)->dd_used_bytes
;
2917 uint64_t avail
= (unreserved
> used
) ? (unreserved
- used
) : 0;
2919 if (spa_has_checkpoint(spa
) && avail
== 0)
2925 #if defined(_KERNEL)
2928 param_set_deadman_failmode_common(const char *val
)
2934 return (SET_ERROR(EINVAL
));
2936 if ((p
= strchr(val
, '\n')) != NULL
)
2939 if (strcmp(val
, "wait") != 0 && strcmp(val
, "continue") != 0 &&
2940 strcmp(val
, "panic"))
2941 return (SET_ERROR(EINVAL
));
2943 if (spa_mode_global
!= SPA_MODE_UNINIT
) {
2944 mutex_enter(&spa_namespace_lock
);
2945 while ((spa
= spa_next(spa
)) != NULL
)
2946 spa_set_deadman_failmode(spa
, val
);
2947 mutex_exit(&spa_namespace_lock
);
2954 /* Namespace manipulation */
2955 EXPORT_SYMBOL(spa_lookup
);
2956 EXPORT_SYMBOL(spa_add
);
2957 EXPORT_SYMBOL(spa_remove
);
2958 EXPORT_SYMBOL(spa_next
);
2960 /* Refcount functions */
2961 EXPORT_SYMBOL(spa_open_ref
);
2962 EXPORT_SYMBOL(spa_close
);
2963 EXPORT_SYMBOL(spa_refcount_zero
);
2965 /* Pool configuration lock */
2966 EXPORT_SYMBOL(spa_config_tryenter
);
2967 EXPORT_SYMBOL(spa_config_enter
);
2968 EXPORT_SYMBOL(spa_config_exit
);
2969 EXPORT_SYMBOL(spa_config_held
);
2971 /* Pool vdev add/remove lock */
2972 EXPORT_SYMBOL(spa_vdev_enter
);
2973 EXPORT_SYMBOL(spa_vdev_exit
);
2975 /* Pool vdev state change lock */
2976 EXPORT_SYMBOL(spa_vdev_state_enter
);
2977 EXPORT_SYMBOL(spa_vdev_state_exit
);
2979 /* Accessor functions */
2980 EXPORT_SYMBOL(spa_shutting_down
);
2981 EXPORT_SYMBOL(spa_get_dsl
);
2982 EXPORT_SYMBOL(spa_get_rootblkptr
);
2983 EXPORT_SYMBOL(spa_set_rootblkptr
);
2984 EXPORT_SYMBOL(spa_altroot
);
2985 EXPORT_SYMBOL(spa_sync_pass
);
2986 EXPORT_SYMBOL(spa_name
);
2987 EXPORT_SYMBOL(spa_guid
);
2988 EXPORT_SYMBOL(spa_last_synced_txg
);
2989 EXPORT_SYMBOL(spa_first_txg
);
2990 EXPORT_SYMBOL(spa_syncing_txg
);
2991 EXPORT_SYMBOL(spa_version
);
2992 EXPORT_SYMBOL(spa_state
);
2993 EXPORT_SYMBOL(spa_load_state
);
2994 EXPORT_SYMBOL(spa_freeze_txg
);
2995 EXPORT_SYMBOL(spa_get_dspace
);
2996 EXPORT_SYMBOL(spa_update_dspace
);
2997 EXPORT_SYMBOL(spa_deflate
);
2998 EXPORT_SYMBOL(spa_normal_class
);
2999 EXPORT_SYMBOL(spa_log_class
);
3000 EXPORT_SYMBOL(spa_special_class
);
3001 EXPORT_SYMBOL(spa_preferred_class
);
3002 EXPORT_SYMBOL(spa_max_replication
);
3003 EXPORT_SYMBOL(spa_prev_software_version
);
3004 EXPORT_SYMBOL(spa_get_failmode
);
3005 EXPORT_SYMBOL(spa_suspended
);
3006 EXPORT_SYMBOL(spa_bootfs
);
3007 EXPORT_SYMBOL(spa_delegation
);
3008 EXPORT_SYMBOL(spa_meta_objset
);
3009 EXPORT_SYMBOL(spa_maxblocksize
);
3010 EXPORT_SYMBOL(spa_maxdnodesize
);
3012 /* Miscellaneous support routines */
3013 EXPORT_SYMBOL(spa_guid_exists
);
3014 EXPORT_SYMBOL(spa_strdup
);
3015 EXPORT_SYMBOL(spa_strfree
);
3016 EXPORT_SYMBOL(spa_generate_guid
);
3017 EXPORT_SYMBOL(snprintf_blkptr
);
3018 EXPORT_SYMBOL(spa_freeze
);
3019 EXPORT_SYMBOL(spa_upgrade
);
3020 EXPORT_SYMBOL(spa_evict_all
);
3021 EXPORT_SYMBOL(spa_lookup_by_guid
);
3022 EXPORT_SYMBOL(spa_has_spare
);
3023 EXPORT_SYMBOL(dva_get_dsize_sync
);
3024 EXPORT_SYMBOL(bp_get_dsize_sync
);
3025 EXPORT_SYMBOL(bp_get_dsize
);
3026 EXPORT_SYMBOL(spa_has_slogs
);
3027 EXPORT_SYMBOL(spa_is_root
);
3028 EXPORT_SYMBOL(spa_writeable
);
3029 EXPORT_SYMBOL(spa_mode
);
3030 EXPORT_SYMBOL(spa_namespace_lock
);
3031 EXPORT_SYMBOL(spa_trust_config
);
3032 EXPORT_SYMBOL(spa_missing_tvds_allowed
);
3033 EXPORT_SYMBOL(spa_set_missing_tvds
);
3034 EXPORT_SYMBOL(spa_state_to_name
);
3035 EXPORT_SYMBOL(spa_importing_readonly_checkpoint
);
3036 EXPORT_SYMBOL(spa_min_claim_txg
);
3037 EXPORT_SYMBOL(spa_suspend_async_destroy
);
3038 EXPORT_SYMBOL(spa_has_checkpoint
);
3039 EXPORT_SYMBOL(spa_top_vdevs_spacemap_addressable
);
3041 ZFS_MODULE_PARAM(zfs
, zfs_
, flags
, UINT
, ZMOD_RW
,
3042 "Set additional debugging flags");
3044 ZFS_MODULE_PARAM(zfs
, zfs_
, recover
, INT
, ZMOD_RW
,
3045 "Set to attempt to recover from fatal errors");
3047 ZFS_MODULE_PARAM(zfs
, zfs_
, free_leak_on_eio
, INT
, ZMOD_RW
,
3048 "Set to ignore IO errors during free and permanently leak the space");
3050 ZFS_MODULE_PARAM(zfs_deadman
, zfs_deadman_
, checktime_ms
, U64
, ZMOD_RW
,
3051 "Dead I/O check interval in milliseconds");
3053 ZFS_MODULE_PARAM(zfs_deadman
, zfs_deadman_
, enabled
, INT
, ZMOD_RW
,
3054 "Enable deadman timer");
3056 ZFS_MODULE_PARAM(zfs_spa
, spa_
, asize_inflation
, UINT
, ZMOD_RW
,
3057 "SPA size estimate multiplication factor");
3059 ZFS_MODULE_PARAM(zfs
, zfs_
, ddt_data_is_special
, INT
, ZMOD_RW
,
3060 "Place DDT data into the special class");
3062 ZFS_MODULE_PARAM(zfs
, zfs_
, user_indirect_is_special
, INT
, ZMOD_RW
,
3063 "Place user data indirect blocks into the special class");
3066 ZFS_MODULE_PARAM_CALL(zfs_deadman
, zfs_deadman_
, failmode
,
3067 param_set_deadman_failmode
, param_get_charp
, ZMOD_RW
,
3068 "Failmode for deadman timer");
3070 ZFS_MODULE_PARAM_CALL(zfs_deadman
, zfs_deadman_
, synctime_ms
,
3071 param_set_deadman_synctime
, spl_param_get_u64
, ZMOD_RW
,
3072 "Pool sync expiration time in milliseconds");
3074 ZFS_MODULE_PARAM_CALL(zfs_deadman
, zfs_deadman_
, ziotime_ms
,
3075 param_set_deadman_ziotime
, spl_param_get_u64
, ZMOD_RW
,
3076 "IO expiration time in milliseconds");
3078 ZFS_MODULE_PARAM(zfs
, zfs_
, special_class_metadata_reserve_pct
, UINT
, ZMOD_RW
,
3079 "Small file blocks in special vdevs depends on this much "
3080 "free space available");
3083 ZFS_MODULE_PARAM_CALL(zfs_spa
, spa_
, slop_shift
, param_set_slop_shift
,
3084 param_get_uint
, ZMOD_RW
, "Reserved free space in pool");
3086 ZFS_MODULE_PARAM(zfs
, spa_
, num_allocators
, INT
, ZMOD_RW
,
3087 "Number of allocators per spa, capped by ncpus");