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
);
432 * By default dedup and user data indirects land in the special class
434 static int zfs_ddt_data_is_special
= B_TRUE
;
435 static int zfs_user_indirect_is_special
= B_TRUE
;
438 * The percentage of special class final space reserved for metadata only.
439 * Once we allocate 100 - zfs_special_class_metadata_reserve_pct we only
440 * let metadata into the class.
442 static uint_t zfs_special_class_metadata_reserve_pct
= 25;
445 * ==========================================================================
447 * ==========================================================================
450 spa_config_lock_init(spa_t
*spa
)
452 for (int i
= 0; i
< SCL_LOCKS
; i
++) {
453 spa_config_lock_t
*scl
= &spa
->spa_config_lock
[i
];
454 mutex_init(&scl
->scl_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
455 cv_init(&scl
->scl_cv
, NULL
, CV_DEFAULT
, NULL
);
456 scl
->scl_writer
= NULL
;
457 scl
->scl_write_wanted
= 0;
463 spa_config_lock_destroy(spa_t
*spa
)
465 for (int i
= 0; i
< SCL_LOCKS
; i
++) {
466 spa_config_lock_t
*scl
= &spa
->spa_config_lock
[i
];
467 mutex_destroy(&scl
->scl_lock
);
468 cv_destroy(&scl
->scl_cv
);
469 ASSERT(scl
->scl_writer
== NULL
);
470 ASSERT(scl
->scl_write_wanted
== 0);
471 ASSERT(scl
->scl_count
== 0);
476 spa_config_tryenter(spa_t
*spa
, int locks
, const void *tag
, krw_t rw
)
478 for (int i
= 0; i
< SCL_LOCKS
; i
++) {
479 spa_config_lock_t
*scl
= &spa
->spa_config_lock
[i
];
480 if (!(locks
& (1 << i
)))
482 mutex_enter(&scl
->scl_lock
);
483 if (rw
== RW_READER
) {
484 if (scl
->scl_writer
|| scl
->scl_write_wanted
) {
485 mutex_exit(&scl
->scl_lock
);
486 spa_config_exit(spa
, locks
& ((1 << i
) - 1),
491 ASSERT(scl
->scl_writer
!= curthread
);
492 if (scl
->scl_count
!= 0) {
493 mutex_exit(&scl
->scl_lock
);
494 spa_config_exit(spa
, locks
& ((1 << i
) - 1),
498 scl
->scl_writer
= curthread
;
501 mutex_exit(&scl
->scl_lock
);
507 spa_config_enter_impl(spa_t
*spa
, int locks
, const void *tag
, krw_t rw
,
513 ASSERT3U(SCL_LOCKS
, <, sizeof (wlocks_held
) * NBBY
);
515 for (int i
= 0; i
< SCL_LOCKS
; i
++) {
516 spa_config_lock_t
*scl
= &spa
->spa_config_lock
[i
];
517 if (scl
->scl_writer
== curthread
)
518 wlocks_held
|= (1 << i
);
519 if (!(locks
& (1 << i
)))
521 mutex_enter(&scl
->scl_lock
);
522 if (rw
== RW_READER
) {
523 while (scl
->scl_writer
||
524 (!mmp_flag
&& scl
->scl_write_wanted
)) {
525 cv_wait(&scl
->scl_cv
, &scl
->scl_lock
);
528 ASSERT(scl
->scl_writer
!= curthread
);
529 while (scl
->scl_count
!= 0) {
530 scl
->scl_write_wanted
++;
531 cv_wait(&scl
->scl_cv
, &scl
->scl_lock
);
532 scl
->scl_write_wanted
--;
534 scl
->scl_writer
= curthread
;
537 mutex_exit(&scl
->scl_lock
);
539 ASSERT3U(wlocks_held
, <=, locks
);
543 spa_config_enter(spa_t
*spa
, int locks
, const void *tag
, krw_t rw
)
545 spa_config_enter_impl(spa
, locks
, tag
, rw
, 0);
549 * The spa_config_enter_mmp() allows the mmp thread to cut in front of
550 * outstanding write lock requests. This is needed since the mmp updates are
551 * time sensitive and failure to service them promptly will result in a
552 * suspended pool. This pool suspension has been seen in practice when there is
553 * a single disk in a pool that is responding slowly and presumably about to
558 spa_config_enter_mmp(spa_t
*spa
, int locks
, const void *tag
, krw_t rw
)
560 spa_config_enter_impl(spa
, locks
, tag
, rw
, 1);
564 spa_config_exit(spa_t
*spa
, int locks
, const void *tag
)
567 for (int i
= SCL_LOCKS
- 1; i
>= 0; i
--) {
568 spa_config_lock_t
*scl
= &spa
->spa_config_lock
[i
];
569 if (!(locks
& (1 << i
)))
571 mutex_enter(&scl
->scl_lock
);
572 ASSERT(scl
->scl_count
> 0);
573 if (--scl
->scl_count
== 0) {
574 ASSERT(scl
->scl_writer
== NULL
||
575 scl
->scl_writer
== curthread
);
576 scl
->scl_writer
= NULL
; /* OK in either case */
577 cv_broadcast(&scl
->scl_cv
);
579 mutex_exit(&scl
->scl_lock
);
584 spa_config_held(spa_t
*spa
, int locks
, krw_t rw
)
588 for (int i
= 0; i
< SCL_LOCKS
; i
++) {
589 spa_config_lock_t
*scl
= &spa
->spa_config_lock
[i
];
590 if (!(locks
& (1 << i
)))
592 if ((rw
== RW_READER
&& scl
->scl_count
!= 0) ||
593 (rw
== RW_WRITER
&& scl
->scl_writer
== curthread
))
594 locks_held
|= 1 << i
;
601 * ==========================================================================
602 * SPA namespace functions
603 * ==========================================================================
607 * Lookup the named spa_t in the AVL tree. The spa_namespace_lock must be held.
608 * Returns NULL if no matching spa_t is found.
611 spa_lookup(const char *name
)
613 static spa_t search
; /* spa_t is large; don't allocate on stack */
618 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
620 (void) strlcpy(search
.spa_name
, name
, sizeof (search
.spa_name
));
623 * If it's a full dataset name, figure out the pool name and
626 cp
= strpbrk(search
.spa_name
, "/@#");
630 spa
= avl_find(&spa_namespace_avl
, &search
, &where
);
636 * Fires when spa_sync has not completed within zfs_deadman_synctime_ms.
637 * If the zfs_deadman_enabled flag is set then it inspects all vdev queues
638 * looking for potentially hung I/Os.
641 spa_deadman(void *arg
)
645 /* Disable the deadman if the pool is suspended. */
646 if (spa_suspended(spa
))
649 zfs_dbgmsg("slow spa_sync: started %llu seconds ago, calls %llu",
650 (gethrtime() - spa
->spa_sync_starttime
) / NANOSEC
,
651 (u_longlong_t
)++spa
->spa_deadman_calls
);
652 if (zfs_deadman_enabled
)
653 vdev_deadman(spa
->spa_root_vdev
, FTAG
);
655 spa
->spa_deadman_tqid
= taskq_dispatch_delay(system_delay_taskq
,
656 spa_deadman
, spa
, TQ_SLEEP
, ddi_get_lbolt() +
657 MSEC_TO_TICK(zfs_deadman_checktime_ms
));
661 spa_log_sm_sort_by_txg(const void *va
, const void *vb
)
663 const spa_log_sm_t
*a
= va
;
664 const spa_log_sm_t
*b
= vb
;
666 return (TREE_CMP(a
->sls_txg
, b
->sls_txg
));
670 * Create an uninitialized spa_t with the given name. Requires
671 * spa_namespace_lock. The caller must ensure that the spa_t doesn't already
672 * exist by calling spa_lookup() first.
675 spa_add(const char *name
, nvlist_t
*config
, const char *altroot
)
678 spa_config_dirent_t
*dp
;
680 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
682 spa
= kmem_zalloc(sizeof (spa_t
), KM_SLEEP
);
684 mutex_init(&spa
->spa_async_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
685 mutex_init(&spa
->spa_errlist_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
686 mutex_init(&spa
->spa_errlog_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
687 mutex_init(&spa
->spa_evicting_os_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
688 mutex_init(&spa
->spa_history_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
689 mutex_init(&spa
->spa_proc_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
690 mutex_init(&spa
->spa_props_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
691 mutex_init(&spa
->spa_cksum_tmpls_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
692 mutex_init(&spa
->spa_scrub_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
693 mutex_init(&spa
->spa_suspend_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
694 mutex_init(&spa
->spa_vdev_top_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
695 mutex_init(&spa
->spa_feat_stats_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
696 mutex_init(&spa
->spa_flushed_ms_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
697 mutex_init(&spa
->spa_activities_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
699 cv_init(&spa
->spa_async_cv
, NULL
, CV_DEFAULT
, NULL
);
700 cv_init(&spa
->spa_evicting_os_cv
, NULL
, CV_DEFAULT
, NULL
);
701 cv_init(&spa
->spa_proc_cv
, NULL
, CV_DEFAULT
, NULL
);
702 cv_init(&spa
->spa_scrub_io_cv
, NULL
, CV_DEFAULT
, NULL
);
703 cv_init(&spa
->spa_suspend_cv
, NULL
, CV_DEFAULT
, NULL
);
704 cv_init(&spa
->spa_activities_cv
, NULL
, CV_DEFAULT
, NULL
);
705 cv_init(&spa
->spa_waiters_cv
, NULL
, CV_DEFAULT
, NULL
);
707 for (int t
= 0; t
< TXG_SIZE
; t
++)
708 bplist_create(&spa
->spa_free_bplist
[t
]);
710 (void) strlcpy(spa
->spa_name
, name
, sizeof (spa
->spa_name
));
711 spa
->spa_state
= POOL_STATE_UNINITIALIZED
;
712 spa
->spa_freeze_txg
= UINT64_MAX
;
713 spa
->spa_final_txg
= UINT64_MAX
;
714 spa
->spa_load_max_txg
= UINT64_MAX
;
716 spa
->spa_proc_state
= SPA_PROC_NONE
;
717 spa
->spa_trust_config
= B_TRUE
;
718 spa
->spa_hostid
= zone_get_hostid(NULL
);
720 spa
->spa_deadman_synctime
= MSEC2NSEC(zfs_deadman_synctime_ms
);
721 spa
->spa_deadman_ziotime
= MSEC2NSEC(zfs_deadman_ziotime_ms
);
722 spa_set_deadman_failmode(spa
, zfs_deadman_failmode
);
723 spa_set_allocator(spa
, zfs_active_allocator
);
725 zfs_refcount_create(&spa
->spa_refcount
);
726 spa_config_lock_init(spa
);
729 avl_add(&spa_namespace_avl
, spa
);
732 * Set the alternate root, if there is one.
735 spa
->spa_root
= spa_strdup(altroot
);
737 /* Do not allow more allocators than CPUs. */
738 spa
->spa_alloc_count
= MIN(MAX(spa_num_allocators
, 1), boot_ncpus
);
740 spa
->spa_allocs
= kmem_zalloc(spa
->spa_alloc_count
*
741 sizeof (spa_alloc_t
), KM_SLEEP
);
742 for (int i
= 0; i
< spa
->spa_alloc_count
; i
++) {
743 mutex_init(&spa
->spa_allocs
[i
].spaa_lock
, NULL
, MUTEX_DEFAULT
,
745 avl_create(&spa
->spa_allocs
[i
].spaa_tree
, zio_bookmark_compare
,
746 sizeof (zio_t
), offsetof(zio_t
, io_queue_node
.a
));
749 avl_create(&spa
->spa_metaslabs_by_flushed
, metaslab_sort_by_flushed
,
750 sizeof (metaslab_t
), offsetof(metaslab_t
, ms_spa_txg_node
));
751 avl_create(&spa
->spa_sm_logs_by_txg
, spa_log_sm_sort_by_txg
,
752 sizeof (spa_log_sm_t
), offsetof(spa_log_sm_t
, sls_node
));
753 list_create(&spa
->spa_log_summary
, sizeof (log_summary_entry_t
),
754 offsetof(log_summary_entry_t
, lse_node
));
757 * Every pool starts with the default cachefile
759 list_create(&spa
->spa_config_list
, sizeof (spa_config_dirent_t
),
760 offsetof(spa_config_dirent_t
, scd_link
));
762 dp
= kmem_zalloc(sizeof (spa_config_dirent_t
), KM_SLEEP
);
763 dp
->scd_path
= altroot
? NULL
: spa_strdup(spa_config_path
);
764 list_insert_head(&spa
->spa_config_list
, dp
);
766 VERIFY(nvlist_alloc(&spa
->spa_load_info
, NV_UNIQUE_NAME
,
769 if (config
!= NULL
) {
772 if (nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_FEATURES_FOR_READ
,
774 VERIFY(nvlist_dup(features
, &spa
->spa_label_features
,
778 VERIFY(nvlist_dup(config
, &spa
->spa_config
, 0) == 0);
781 if (spa
->spa_label_features
== NULL
) {
782 VERIFY(nvlist_alloc(&spa
->spa_label_features
, NV_UNIQUE_NAME
,
786 spa
->spa_min_ashift
= INT_MAX
;
787 spa
->spa_max_ashift
= 0;
788 spa
->spa_min_alloc
= INT_MAX
;
789 spa
->spa_gcd_alloc
= INT_MAX
;
791 /* Reset cached value */
792 spa
->spa_dedup_dspace
= ~0ULL;
795 * As a pool is being created, treat all features as disabled by
796 * setting SPA_FEATURE_DISABLED for all entries in the feature
799 for (int i
= 0; i
< SPA_FEATURES
; i
++) {
800 spa
->spa_feat_refcount_cache
[i
] = SPA_FEATURE_DISABLED
;
803 list_create(&spa
->spa_leaf_list
, sizeof (vdev_t
),
804 offsetof(vdev_t
, vdev_leaf_node
));
810 * Removes a spa_t from the namespace, freeing up any memory used. Requires
811 * spa_namespace_lock. This is called only after the spa_t has been closed and
815 spa_remove(spa_t
*spa
)
817 spa_config_dirent_t
*dp
;
819 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
820 ASSERT(spa_state(spa
) == POOL_STATE_UNINITIALIZED
);
821 ASSERT3U(zfs_refcount_count(&spa
->spa_refcount
), ==, 0);
822 ASSERT0(spa
->spa_waiters
);
824 nvlist_free(spa
->spa_config_splitting
);
826 avl_remove(&spa_namespace_avl
, spa
);
827 cv_broadcast(&spa_namespace_cv
);
830 spa_strfree(spa
->spa_root
);
832 while ((dp
= list_remove_head(&spa
->spa_config_list
)) != NULL
) {
833 if (dp
->scd_path
!= NULL
)
834 spa_strfree(dp
->scd_path
);
835 kmem_free(dp
, sizeof (spa_config_dirent_t
));
838 for (int i
= 0; i
< spa
->spa_alloc_count
; i
++) {
839 avl_destroy(&spa
->spa_allocs
[i
].spaa_tree
);
840 mutex_destroy(&spa
->spa_allocs
[i
].spaa_lock
);
842 kmem_free(spa
->spa_allocs
, spa
->spa_alloc_count
*
843 sizeof (spa_alloc_t
));
845 avl_destroy(&spa
->spa_metaslabs_by_flushed
);
846 avl_destroy(&spa
->spa_sm_logs_by_txg
);
847 list_destroy(&spa
->spa_log_summary
);
848 list_destroy(&spa
->spa_config_list
);
849 list_destroy(&spa
->spa_leaf_list
);
851 nvlist_free(spa
->spa_label_features
);
852 nvlist_free(spa
->spa_load_info
);
853 nvlist_free(spa
->spa_feat_stats
);
854 spa_config_set(spa
, NULL
);
856 zfs_refcount_destroy(&spa
->spa_refcount
);
858 spa_stats_destroy(spa
);
859 spa_config_lock_destroy(spa
);
861 for (int t
= 0; t
< TXG_SIZE
; t
++)
862 bplist_destroy(&spa
->spa_free_bplist
[t
]);
864 zio_checksum_templates_free(spa
);
866 cv_destroy(&spa
->spa_async_cv
);
867 cv_destroy(&spa
->spa_evicting_os_cv
);
868 cv_destroy(&spa
->spa_proc_cv
);
869 cv_destroy(&spa
->spa_scrub_io_cv
);
870 cv_destroy(&spa
->spa_suspend_cv
);
871 cv_destroy(&spa
->spa_activities_cv
);
872 cv_destroy(&spa
->spa_waiters_cv
);
874 mutex_destroy(&spa
->spa_flushed_ms_lock
);
875 mutex_destroy(&spa
->spa_async_lock
);
876 mutex_destroy(&spa
->spa_errlist_lock
);
877 mutex_destroy(&spa
->spa_errlog_lock
);
878 mutex_destroy(&spa
->spa_evicting_os_lock
);
879 mutex_destroy(&spa
->spa_history_lock
);
880 mutex_destroy(&spa
->spa_proc_lock
);
881 mutex_destroy(&spa
->spa_props_lock
);
882 mutex_destroy(&spa
->spa_cksum_tmpls_lock
);
883 mutex_destroy(&spa
->spa_scrub_lock
);
884 mutex_destroy(&spa
->spa_suspend_lock
);
885 mutex_destroy(&spa
->spa_vdev_top_lock
);
886 mutex_destroy(&spa
->spa_feat_stats_lock
);
887 mutex_destroy(&spa
->spa_activities_lock
);
889 kmem_free(spa
, sizeof (spa_t
));
893 * Given a pool, return the next pool in the namespace, or NULL if there is
894 * none. If 'prev' is NULL, return the first pool.
897 spa_next(spa_t
*prev
)
899 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
902 return (AVL_NEXT(&spa_namespace_avl
, prev
));
904 return (avl_first(&spa_namespace_avl
));
908 * ==========================================================================
909 * SPA refcount functions
910 * ==========================================================================
914 * Add a reference to the given spa_t. Must have at least one reference, or
915 * have the namespace lock held.
918 spa_open_ref(spa_t
*spa
, const void *tag
)
920 ASSERT(zfs_refcount_count(&spa
->spa_refcount
) >= spa
->spa_minref
||
921 MUTEX_HELD(&spa_namespace_lock
));
922 (void) zfs_refcount_add(&spa
->spa_refcount
, tag
);
926 * Remove a reference to the given spa_t. Must have at least one reference, or
927 * have the namespace lock held.
930 spa_close(spa_t
*spa
, const void *tag
)
932 ASSERT(zfs_refcount_count(&spa
->spa_refcount
) > spa
->spa_minref
||
933 MUTEX_HELD(&spa_namespace_lock
));
934 (void) zfs_refcount_remove(&spa
->spa_refcount
, tag
);
938 * Remove a reference to the given spa_t held by a dsl dir that is
939 * being asynchronously released. Async releases occur from a taskq
940 * performing eviction of dsl datasets and dirs. The namespace lock
941 * isn't held and the hold by the object being evicted may contribute to
942 * spa_minref (e.g. dataset or directory released during pool export),
943 * so the asserts in spa_close() do not apply.
946 spa_async_close(spa_t
*spa
, const void *tag
)
948 (void) zfs_refcount_remove(&spa
->spa_refcount
, tag
);
952 * Check to see if the spa refcount is zero. Must be called with
953 * spa_namespace_lock held. We really compare against spa_minref, which is the
954 * number of references acquired when opening a pool
957 spa_refcount_zero(spa_t
*spa
)
959 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
961 return (zfs_refcount_count(&spa
->spa_refcount
) == spa
->spa_minref
);
965 * ==========================================================================
966 * SPA spare and l2cache tracking
967 * ==========================================================================
971 * Hot spares and cache devices are tracked using the same code below,
972 * for 'auxiliary' devices.
975 typedef struct spa_aux
{
983 spa_aux_compare(const void *a
, const void *b
)
985 const spa_aux_t
*sa
= (const spa_aux_t
*)a
;
986 const spa_aux_t
*sb
= (const spa_aux_t
*)b
;
988 return (TREE_CMP(sa
->aux_guid
, sb
->aux_guid
));
992 spa_aux_add(vdev_t
*vd
, avl_tree_t
*avl
)
998 search
.aux_guid
= vd
->vdev_guid
;
999 if ((aux
= avl_find(avl
, &search
, &where
)) != NULL
) {
1002 aux
= kmem_zalloc(sizeof (spa_aux_t
), KM_SLEEP
);
1003 aux
->aux_guid
= vd
->vdev_guid
;
1005 avl_insert(avl
, aux
, where
);
1010 spa_aux_remove(vdev_t
*vd
, avl_tree_t
*avl
)
1016 search
.aux_guid
= vd
->vdev_guid
;
1017 aux
= avl_find(avl
, &search
, &where
);
1019 ASSERT(aux
!= NULL
);
1021 if (--aux
->aux_count
== 0) {
1022 avl_remove(avl
, aux
);
1023 kmem_free(aux
, sizeof (spa_aux_t
));
1024 } else if (aux
->aux_pool
== spa_guid(vd
->vdev_spa
)) {
1025 aux
->aux_pool
= 0ULL;
1030 spa_aux_exists(uint64_t guid
, uint64_t *pool
, int *refcnt
, avl_tree_t
*avl
)
1032 spa_aux_t search
, *found
;
1034 search
.aux_guid
= guid
;
1035 found
= avl_find(avl
, &search
, NULL
);
1039 *pool
= found
->aux_pool
;
1046 *refcnt
= found
->aux_count
;
1051 return (found
!= NULL
);
1055 spa_aux_activate(vdev_t
*vd
, avl_tree_t
*avl
)
1057 spa_aux_t search
, *found
;
1060 search
.aux_guid
= vd
->vdev_guid
;
1061 found
= avl_find(avl
, &search
, &where
);
1062 ASSERT(found
!= NULL
);
1063 ASSERT(found
->aux_pool
== 0ULL);
1065 found
->aux_pool
= spa_guid(vd
->vdev_spa
);
1069 * Spares are tracked globally due to the following constraints:
1071 * - A spare may be part of multiple pools.
1072 * - A spare may be added to a pool even if it's actively in use within
1074 * - A spare in use in any pool can only be the source of a replacement if
1075 * the target is a spare in the same pool.
1077 * We keep track of all spares on the system through the use of a reference
1078 * counted AVL tree. When a vdev is added as a spare, or used as a replacement
1079 * spare, then we bump the reference count in the AVL tree. In addition, we set
1080 * the 'vdev_isspare' member to indicate that the device is a spare (active or
1081 * inactive). When a spare is made active (used to replace a device in the
1082 * pool), we also keep track of which pool its been made a part of.
1084 * The 'spa_spare_lock' protects the AVL tree. These functions are normally
1085 * called under the spa_namespace lock as part of vdev reconfiguration. The
1086 * separate spare lock exists for the status query path, which does not need to
1087 * be completely consistent with respect to other vdev configuration changes.
1091 spa_spare_compare(const void *a
, const void *b
)
1093 return (spa_aux_compare(a
, b
));
1097 spa_spare_add(vdev_t
*vd
)
1099 mutex_enter(&spa_spare_lock
);
1100 ASSERT(!vd
->vdev_isspare
);
1101 spa_aux_add(vd
, &spa_spare_avl
);
1102 vd
->vdev_isspare
= B_TRUE
;
1103 mutex_exit(&spa_spare_lock
);
1107 spa_spare_remove(vdev_t
*vd
)
1109 mutex_enter(&spa_spare_lock
);
1110 ASSERT(vd
->vdev_isspare
);
1111 spa_aux_remove(vd
, &spa_spare_avl
);
1112 vd
->vdev_isspare
= B_FALSE
;
1113 mutex_exit(&spa_spare_lock
);
1117 spa_spare_exists(uint64_t guid
, uint64_t *pool
, int *refcnt
)
1121 mutex_enter(&spa_spare_lock
);
1122 found
= spa_aux_exists(guid
, pool
, refcnt
, &spa_spare_avl
);
1123 mutex_exit(&spa_spare_lock
);
1129 spa_spare_activate(vdev_t
*vd
)
1131 mutex_enter(&spa_spare_lock
);
1132 ASSERT(vd
->vdev_isspare
);
1133 spa_aux_activate(vd
, &spa_spare_avl
);
1134 mutex_exit(&spa_spare_lock
);
1138 * Level 2 ARC devices are tracked globally for the same reasons as spares.
1139 * Cache devices currently only support one pool per cache device, and so
1140 * for these devices the aux reference count is currently unused beyond 1.
1144 spa_l2cache_compare(const void *a
, const void *b
)
1146 return (spa_aux_compare(a
, b
));
1150 spa_l2cache_add(vdev_t
*vd
)
1152 mutex_enter(&spa_l2cache_lock
);
1153 ASSERT(!vd
->vdev_isl2cache
);
1154 spa_aux_add(vd
, &spa_l2cache_avl
);
1155 vd
->vdev_isl2cache
= B_TRUE
;
1156 mutex_exit(&spa_l2cache_lock
);
1160 spa_l2cache_remove(vdev_t
*vd
)
1162 mutex_enter(&spa_l2cache_lock
);
1163 ASSERT(vd
->vdev_isl2cache
);
1164 spa_aux_remove(vd
, &spa_l2cache_avl
);
1165 vd
->vdev_isl2cache
= B_FALSE
;
1166 mutex_exit(&spa_l2cache_lock
);
1170 spa_l2cache_exists(uint64_t guid
, uint64_t *pool
)
1174 mutex_enter(&spa_l2cache_lock
);
1175 found
= spa_aux_exists(guid
, pool
, NULL
, &spa_l2cache_avl
);
1176 mutex_exit(&spa_l2cache_lock
);
1182 spa_l2cache_activate(vdev_t
*vd
)
1184 mutex_enter(&spa_l2cache_lock
);
1185 ASSERT(vd
->vdev_isl2cache
);
1186 spa_aux_activate(vd
, &spa_l2cache_avl
);
1187 mutex_exit(&spa_l2cache_lock
);
1191 * ==========================================================================
1193 * ==========================================================================
1197 * Lock the given spa_t for the purpose of adding or removing a vdev.
1198 * Grabs the global spa_namespace_lock plus the spa config lock for writing.
1199 * It returns the next transaction group for the spa_t.
1202 spa_vdev_enter(spa_t
*spa
)
1204 mutex_enter(&spa
->spa_vdev_top_lock
);
1205 mutex_enter(&spa_namespace_lock
);
1207 vdev_autotrim_stop_all(spa
);
1209 return (spa_vdev_config_enter(spa
));
1213 * The same as spa_vdev_enter() above but additionally takes the guid of
1214 * the vdev being detached. When there is a rebuild in process it will be
1215 * suspended while the vdev tree is modified then resumed by spa_vdev_exit().
1216 * The rebuild is canceled if only a single child remains after the detach.
1219 spa_vdev_detach_enter(spa_t
*spa
, uint64_t guid
)
1221 mutex_enter(&spa
->spa_vdev_top_lock
);
1222 mutex_enter(&spa_namespace_lock
);
1224 vdev_autotrim_stop_all(spa
);
1227 vdev_t
*vd
= spa_lookup_by_guid(spa
, guid
, B_FALSE
);
1229 vdev_rebuild_stop_wait(vd
->vdev_top
);
1233 return (spa_vdev_config_enter(spa
));
1237 * Internal implementation for spa_vdev_enter(). Used when a vdev
1238 * operation requires multiple syncs (i.e. removing a device) while
1239 * keeping the spa_namespace_lock held.
1242 spa_vdev_config_enter(spa_t
*spa
)
1244 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
1246 spa_config_enter(spa
, SCL_ALL
, spa
, RW_WRITER
);
1248 return (spa_last_synced_txg(spa
) + 1);
1252 * Used in combination with spa_vdev_config_enter() to allow the syncing
1253 * of multiple transactions without releasing the spa_namespace_lock.
1256 spa_vdev_config_exit(spa_t
*spa
, vdev_t
*vd
, uint64_t txg
, int error
,
1259 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
1261 int config_changed
= B_FALSE
;
1263 ASSERT(txg
> spa_last_synced_txg(spa
));
1265 spa
->spa_pending_vdev
= NULL
;
1268 * Reassess the DTLs.
1270 vdev_dtl_reassess(spa
->spa_root_vdev
, 0, 0, B_FALSE
, B_FALSE
);
1272 if (error
== 0 && !list_is_empty(&spa
->spa_config_dirty_list
)) {
1273 config_changed
= B_TRUE
;
1274 spa
->spa_config_generation
++;
1278 * Verify the metaslab classes.
1280 ASSERT(metaslab_class_validate(spa_normal_class(spa
)) == 0);
1281 ASSERT(metaslab_class_validate(spa_log_class(spa
)) == 0);
1282 ASSERT(metaslab_class_validate(spa_embedded_log_class(spa
)) == 0);
1283 ASSERT(metaslab_class_validate(spa_special_class(spa
)) == 0);
1284 ASSERT(metaslab_class_validate(spa_dedup_class(spa
)) == 0);
1286 spa_config_exit(spa
, SCL_ALL
, spa
);
1289 * Panic the system if the specified tag requires it. This
1290 * is useful for ensuring that configurations are updated
1293 if (zio_injection_enabled
)
1294 zio_handle_panic_injection(spa
, tag
, 0);
1297 * Note: this txg_wait_synced() is important because it ensures
1298 * that there won't be more than one config change per txg.
1299 * This allows us to use the txg as the generation number.
1302 txg_wait_synced(spa
->spa_dsl_pool
, txg
);
1305 ASSERT(!vd
->vdev_detached
|| vd
->vdev_dtl_sm
== NULL
);
1306 if (vd
->vdev_ops
->vdev_op_leaf
) {
1307 mutex_enter(&vd
->vdev_initialize_lock
);
1308 vdev_initialize_stop(vd
, VDEV_INITIALIZE_CANCELED
,
1310 mutex_exit(&vd
->vdev_initialize_lock
);
1312 mutex_enter(&vd
->vdev_trim_lock
);
1313 vdev_trim_stop(vd
, VDEV_TRIM_CANCELED
, NULL
);
1314 mutex_exit(&vd
->vdev_trim_lock
);
1318 * The vdev may be both a leaf and top-level device.
1320 vdev_autotrim_stop_wait(vd
);
1322 spa_config_enter(spa
, SCL_STATE_ALL
, spa
, RW_WRITER
);
1324 spa_config_exit(spa
, SCL_STATE_ALL
, spa
);
1328 * If the config changed, update the config cache.
1331 spa_write_cachefile(spa
, B_FALSE
, B_TRUE
, B_TRUE
);
1335 * Unlock the spa_t after adding or removing a vdev. Besides undoing the
1336 * locking of spa_vdev_enter(), we also want make sure the transactions have
1337 * synced to disk, and then update the global configuration cache with the new
1341 spa_vdev_exit(spa_t
*spa
, vdev_t
*vd
, uint64_t txg
, int error
)
1343 vdev_autotrim_restart(spa
);
1344 vdev_rebuild_restart(spa
);
1346 spa_vdev_config_exit(spa
, vd
, txg
, error
, FTAG
);
1347 mutex_exit(&spa_namespace_lock
);
1348 mutex_exit(&spa
->spa_vdev_top_lock
);
1354 * Lock the given spa_t for the purpose of changing vdev state.
1357 spa_vdev_state_enter(spa_t
*spa
, int oplocks
)
1359 int locks
= SCL_STATE_ALL
| oplocks
;
1362 * Root pools may need to read of the underlying devfs filesystem
1363 * when opening up a vdev. Unfortunately if we're holding the
1364 * SCL_ZIO lock it will result in a deadlock when we try to issue
1365 * the read from the root filesystem. Instead we "prefetch"
1366 * the associated vnodes that we need prior to opening the
1367 * underlying devices and cache them so that we can prevent
1368 * any I/O when we are doing the actual open.
1370 if (spa_is_root(spa
)) {
1371 int low
= locks
& ~(SCL_ZIO
- 1);
1372 int high
= locks
& ~low
;
1374 spa_config_enter(spa
, high
, spa
, RW_WRITER
);
1375 vdev_hold(spa
->spa_root_vdev
);
1376 spa_config_enter(spa
, low
, spa
, RW_WRITER
);
1378 spa_config_enter(spa
, locks
, spa
, RW_WRITER
);
1380 spa
->spa_vdev_locks
= locks
;
1384 spa_vdev_state_exit(spa_t
*spa
, vdev_t
*vd
, int error
)
1386 boolean_t config_changed
= B_FALSE
;
1389 if (vd
== NULL
|| vd
== spa
->spa_root_vdev
) {
1390 vdev_top
= spa
->spa_root_vdev
;
1392 vdev_top
= vd
->vdev_top
;
1395 if (vd
!= NULL
|| error
== 0)
1396 vdev_dtl_reassess(vdev_top
, 0, 0, B_FALSE
, B_FALSE
);
1399 if (vd
!= spa
->spa_root_vdev
)
1400 vdev_state_dirty(vdev_top
);
1402 config_changed
= B_TRUE
;
1403 spa
->spa_config_generation
++;
1406 if (spa_is_root(spa
))
1407 vdev_rele(spa
->spa_root_vdev
);
1409 ASSERT3U(spa
->spa_vdev_locks
, >=, SCL_STATE_ALL
);
1410 spa_config_exit(spa
, spa
->spa_vdev_locks
, spa
);
1413 * If anything changed, wait for it to sync. This ensures that,
1414 * from the system administrator's perspective, zpool(8) commands
1415 * are synchronous. This is important for things like zpool offline:
1416 * when the command completes, you expect no further I/O from ZFS.
1419 txg_wait_synced(spa
->spa_dsl_pool
, 0);
1422 * If the config changed, update the config cache.
1424 if (config_changed
) {
1425 mutex_enter(&spa_namespace_lock
);
1426 spa_write_cachefile(spa
, B_FALSE
, B_TRUE
, B_FALSE
);
1427 mutex_exit(&spa_namespace_lock
);
1434 * ==========================================================================
1435 * Miscellaneous functions
1436 * ==========================================================================
1440 spa_activate_mos_feature(spa_t
*spa
, const char *feature
, dmu_tx_t
*tx
)
1442 if (!nvlist_exists(spa
->spa_label_features
, feature
)) {
1443 fnvlist_add_boolean(spa
->spa_label_features
, feature
);
1445 * When we are creating the pool (tx_txg==TXG_INITIAL), we can't
1446 * dirty the vdev config because lock SCL_CONFIG is not held.
1447 * Thankfully, in this case we don't need to dirty the config
1448 * because it will be written out anyway when we finish
1449 * creating the pool.
1451 if (tx
->tx_txg
!= TXG_INITIAL
)
1452 vdev_config_dirty(spa
->spa_root_vdev
);
1457 spa_deactivate_mos_feature(spa_t
*spa
, const char *feature
)
1459 if (nvlist_remove_all(spa
->spa_label_features
, feature
) == 0)
1460 vdev_config_dirty(spa
->spa_root_vdev
);
1464 * Return the spa_t associated with given pool_guid, if it exists. If
1465 * device_guid is non-zero, determine whether the pool exists *and* contains
1466 * a device with the specified device_guid.
1469 spa_by_guid(uint64_t pool_guid
, uint64_t device_guid
)
1472 avl_tree_t
*t
= &spa_namespace_avl
;
1474 ASSERT(MUTEX_HELD(&spa_namespace_lock
));
1476 for (spa
= avl_first(t
); spa
!= NULL
; spa
= AVL_NEXT(t
, spa
)) {
1477 if (spa
->spa_state
== POOL_STATE_UNINITIALIZED
)
1479 if (spa
->spa_root_vdev
== NULL
)
1481 if (spa_guid(spa
) == pool_guid
) {
1482 if (device_guid
== 0)
1485 if (vdev_lookup_by_guid(spa
->spa_root_vdev
,
1486 device_guid
) != NULL
)
1490 * Check any devices we may be in the process of adding.
1492 if (spa
->spa_pending_vdev
) {
1493 if (vdev_lookup_by_guid(spa
->spa_pending_vdev
,
1494 device_guid
) != NULL
)
1504 * Determine whether a pool with the given pool_guid exists.
1507 spa_guid_exists(uint64_t pool_guid
, uint64_t device_guid
)
1509 return (spa_by_guid(pool_guid
, device_guid
) != NULL
);
1513 spa_strdup(const char *s
)
1519 new = kmem_alloc(len
+ 1, KM_SLEEP
);
1520 memcpy(new, s
, len
+ 1);
1526 spa_strfree(char *s
)
1528 kmem_free(s
, strlen(s
) + 1);
1532 spa_generate_guid(spa_t
*spa
)
1538 (void) random_get_pseudo_bytes((void *)&guid
,
1540 } while (guid
== 0 || spa_guid_exists(spa_guid(spa
), guid
));
1543 (void) random_get_pseudo_bytes((void *)&guid
,
1545 } while (guid
== 0 || spa_guid_exists(guid
, 0));
1552 snprintf_blkptr(char *buf
, size_t buflen
, const blkptr_t
*bp
)
1555 const char *checksum
= NULL
;
1556 const char *compress
= NULL
;
1559 if (BP_GET_TYPE(bp
) & DMU_OT_NEWTYPE
) {
1560 dmu_object_byteswap_t bswap
=
1561 DMU_OT_BYTESWAP(BP_GET_TYPE(bp
));
1562 (void) snprintf(type
, sizeof (type
), "bswap %s %s",
1563 DMU_OT_IS_METADATA(BP_GET_TYPE(bp
)) ?
1564 "metadata" : "data",
1565 dmu_ot_byteswap
[bswap
].ob_name
);
1567 (void) strlcpy(type
, dmu_ot
[BP_GET_TYPE(bp
)].ot_name
,
1570 if (!BP_IS_EMBEDDED(bp
)) {
1572 zio_checksum_table
[BP_GET_CHECKSUM(bp
)].ci_name
;
1574 compress
= zio_compress_table
[BP_GET_COMPRESS(bp
)].ci_name
;
1577 SNPRINTF_BLKPTR(kmem_scnprintf
, ' ', buf
, buflen
, bp
, type
, checksum
,
1582 spa_freeze(spa_t
*spa
)
1584 uint64_t freeze_txg
= 0;
1586 spa_config_enter(spa
, SCL_ALL
, FTAG
, RW_WRITER
);
1587 if (spa
->spa_freeze_txg
== UINT64_MAX
) {
1588 freeze_txg
= spa_last_synced_txg(spa
) + TXG_SIZE
;
1589 spa
->spa_freeze_txg
= freeze_txg
;
1591 spa_config_exit(spa
, SCL_ALL
, FTAG
);
1592 if (freeze_txg
!= 0)
1593 txg_wait_synced(spa_get_dsl(spa
), freeze_txg
);
1597 zfs_panic_recover(const char *fmt
, ...)
1602 vcmn_err(zfs_recover
? CE_WARN
: CE_PANIC
, fmt
, adx
);
1607 * This is a stripped-down version of strtoull, suitable only for converting
1608 * lowercase hexadecimal numbers that don't overflow.
1611 zfs_strtonum(const char *str
, char **nptr
)
1617 while ((c
= *str
) != '\0') {
1618 if (c
>= '0' && c
<= '9')
1620 else if (c
>= 'a' && c
<= 'f')
1621 digit
= 10 + c
- 'a';
1632 *nptr
= (char *)str
;
1638 spa_activate_allocation_classes(spa_t
*spa
, dmu_tx_t
*tx
)
1641 * We bump the feature refcount for each special vdev added to the pool
1643 ASSERT(spa_feature_is_enabled(spa
, SPA_FEATURE_ALLOCATION_CLASSES
));
1644 spa_feature_incr(spa
, SPA_FEATURE_ALLOCATION_CLASSES
, tx
);
1648 * ==========================================================================
1649 * Accessor functions
1650 * ==========================================================================
1654 spa_shutting_down(spa_t
*spa
)
1656 return (spa
->spa_async_suspended
);
1660 spa_get_dsl(spa_t
*spa
)
1662 return (spa
->spa_dsl_pool
);
1666 spa_is_initializing(spa_t
*spa
)
1668 return (spa
->spa_is_initializing
);
1672 spa_indirect_vdevs_loaded(spa_t
*spa
)
1674 return (spa
->spa_indirect_vdevs_loaded
);
1678 spa_get_rootblkptr(spa_t
*spa
)
1680 return (&spa
->spa_ubsync
.ub_rootbp
);
1684 spa_set_rootblkptr(spa_t
*spa
, const blkptr_t
*bp
)
1686 spa
->spa_uberblock
.ub_rootbp
= *bp
;
1690 spa_altroot(spa_t
*spa
, char *buf
, size_t buflen
)
1692 if (spa
->spa_root
== NULL
)
1695 (void) strlcpy(buf
, spa
->spa_root
, buflen
);
1699 spa_sync_pass(spa_t
*spa
)
1701 return (spa
->spa_sync_pass
);
1705 spa_name(spa_t
*spa
)
1707 return (spa
->spa_name
);
1711 spa_guid(spa_t
*spa
)
1713 dsl_pool_t
*dp
= spa_get_dsl(spa
);
1717 * If we fail to parse the config during spa_load(), we can go through
1718 * the error path (which posts an ereport) and end up here with no root
1719 * vdev. We stash the original pool guid in 'spa_config_guid' to handle
1722 if (spa
->spa_root_vdev
== NULL
)
1723 return (spa
->spa_config_guid
);
1725 guid
= spa
->spa_last_synced_guid
!= 0 ?
1726 spa
->spa_last_synced_guid
: spa
->spa_root_vdev
->vdev_guid
;
1729 * Return the most recently synced out guid unless we're
1730 * in syncing context.
1732 if (dp
&& dsl_pool_sync_context(dp
))
1733 return (spa
->spa_root_vdev
->vdev_guid
);
1739 spa_load_guid(spa_t
*spa
)
1742 * This is a GUID that exists solely as a reference for the
1743 * purposes of the arc. It is generated at load time, and
1744 * is never written to persistent storage.
1746 return (spa
->spa_load_guid
);
1750 spa_last_synced_txg(spa_t
*spa
)
1752 return (spa
->spa_ubsync
.ub_txg
);
1756 spa_first_txg(spa_t
*spa
)
1758 return (spa
->spa_first_txg
);
1762 spa_syncing_txg(spa_t
*spa
)
1764 return (spa
->spa_syncing_txg
);
1768 * Return the last txg where data can be dirtied. The final txgs
1769 * will be used to just clear out any deferred frees that remain.
1772 spa_final_dirty_txg(spa_t
*spa
)
1774 return (spa
->spa_final_txg
- TXG_DEFER_SIZE
);
1778 spa_state(spa_t
*spa
)
1780 return (spa
->spa_state
);
1784 spa_load_state(spa_t
*spa
)
1786 return (spa
->spa_load_state
);
1790 spa_freeze_txg(spa_t
*spa
)
1792 return (spa
->spa_freeze_txg
);
1796 * Return the inflated asize for a logical write in bytes. This is used by the
1797 * DMU to calculate the space a logical write will require on disk.
1798 * If lsize is smaller than the largest physical block size allocatable on this
1799 * pool we use its value instead, since the write will end up using the whole
1803 spa_get_worst_case_asize(spa_t
*spa
, uint64_t lsize
)
1806 return (0); /* No inflation needed */
1807 return (MAX(lsize
, 1 << spa
->spa_max_ashift
) * spa_asize_inflation
);
1811 * Return the amount of slop space in bytes. It is typically 1/32 of the pool
1812 * (3.2%), minus the embedded log space. On very small pools, it may be
1813 * slightly larger than this. On very large pools, it will be capped to
1814 * the value of spa_max_slop. The embedded log space is not included in
1815 * spa_dspace. By subtracting it, the usable space (per "zfs list") is a
1816 * constant 97% of the total space, regardless of metaslab size (assuming the
1817 * default spa_slop_shift=5 and a non-tiny pool).
1819 * See the comment above spa_slop_shift for more details.
1822 spa_get_slop_space(spa_t
*spa
)
1828 * Make sure spa_dedup_dspace has been set.
1830 if (spa
->spa_dedup_dspace
== ~0ULL)
1831 spa_update_dspace(spa
);
1834 * spa_get_dspace() includes the space only logically "used" by
1835 * deduplicated data, so since it's not useful to reserve more
1836 * space with more deduplicated data, we subtract that out here.
1838 space
= spa_get_dspace(spa
) - spa
->spa_dedup_dspace
;
1839 slop
= MIN(space
>> spa_slop_shift
, spa_max_slop
);
1842 * Subtract the embedded log space, but no more than half the (3.2%)
1843 * unusable space. Note, the "no more than half" is only relevant if
1844 * zfs_embedded_slog_min_ms >> spa_slop_shift < 2, which is not true by
1847 uint64_t embedded_log
=
1848 metaslab_class_get_dspace(spa_embedded_log_class(spa
));
1849 slop
-= MIN(embedded_log
, slop
>> 1);
1852 * Slop space should be at least spa_min_slop, but no more than half
1855 slop
= MAX(slop
, MIN(space
>> 1, spa_min_slop
));
1860 spa_get_dspace(spa_t
*spa
)
1862 return (spa
->spa_dspace
);
1866 spa_get_checkpoint_space(spa_t
*spa
)
1868 return (spa
->spa_checkpoint_info
.sci_dspace
);
1872 spa_update_dspace(spa_t
*spa
)
1874 spa
->spa_dspace
= metaslab_class_get_dspace(spa_normal_class(spa
)) +
1875 ddt_get_dedup_dspace(spa
) + brt_get_dspace(spa
);
1876 if (spa
->spa_nonallocating_dspace
> 0) {
1878 * Subtract the space provided by all non-allocating vdevs that
1879 * contribute to dspace. If a file is overwritten, its old
1880 * blocks are freed and new blocks are allocated. If there are
1881 * no snapshots of the file, the available space should remain
1882 * the same. The old blocks could be freed from the
1883 * non-allocating vdev, but the new blocks must be allocated on
1884 * other (allocating) vdevs. By reserving the entire size of
1885 * the non-allocating vdevs (including allocated space), we
1886 * ensure that there will be enough space on the allocating
1887 * vdevs for this file overwrite to succeed.
1889 * Note that the DMU/DSL doesn't actually know or care
1890 * how much space is allocated (it does its own tracking
1891 * of how much space has been logically used). So it
1892 * doesn't matter that the data we are moving may be
1893 * allocated twice (on the old device and the new device).
1895 ASSERT3U(spa
->spa_dspace
, >=, spa
->spa_nonallocating_dspace
);
1896 spa
->spa_dspace
-= spa
->spa_nonallocating_dspace
;
1901 * Return the failure mode that has been set to this pool. The default
1902 * behavior will be to block all I/Os when a complete failure occurs.
1905 spa_get_failmode(spa_t
*spa
)
1907 return (spa
->spa_failmode
);
1911 spa_suspended(spa_t
*spa
)
1913 return (spa
->spa_suspended
!= ZIO_SUSPEND_NONE
);
1917 spa_version(spa_t
*spa
)
1919 return (spa
->spa_ubsync
.ub_version
);
1923 spa_deflate(spa_t
*spa
)
1925 return (spa
->spa_deflate
);
1929 spa_normal_class(spa_t
*spa
)
1931 return (spa
->spa_normal_class
);
1935 spa_log_class(spa_t
*spa
)
1937 return (spa
->spa_log_class
);
1941 spa_embedded_log_class(spa_t
*spa
)
1943 return (spa
->spa_embedded_log_class
);
1947 spa_special_class(spa_t
*spa
)
1949 return (spa
->spa_special_class
);
1953 spa_dedup_class(spa_t
*spa
)
1955 return (spa
->spa_dedup_class
);
1959 * Locate an appropriate allocation class
1962 spa_preferred_class(spa_t
*spa
, uint64_t size
, dmu_object_type_t objtype
,
1963 uint_t level
, uint_t special_smallblk
)
1966 * ZIL allocations determine their class in zio_alloc_zil().
1968 ASSERT(objtype
!= DMU_OT_INTENT_LOG
);
1970 boolean_t has_special_class
= spa
->spa_special_class
->mc_groups
!= 0;
1972 if (DMU_OT_IS_DDT(objtype
)) {
1973 if (spa
->spa_dedup_class
->mc_groups
!= 0)
1974 return (spa_dedup_class(spa
));
1975 else if (has_special_class
&& zfs_ddt_data_is_special
)
1976 return (spa_special_class(spa
));
1978 return (spa_normal_class(spa
));
1981 /* Indirect blocks for user data can land in special if allowed */
1982 if (level
> 0 && (DMU_OT_IS_FILE(objtype
) || objtype
== DMU_OT_ZVOL
)) {
1983 if (has_special_class
&& zfs_user_indirect_is_special
)
1984 return (spa_special_class(spa
));
1986 return (spa_normal_class(spa
));
1989 if (DMU_OT_IS_METADATA(objtype
) || level
> 0) {
1990 if (has_special_class
)
1991 return (spa_special_class(spa
));
1993 return (spa_normal_class(spa
));
1997 * Allow small file blocks in special class in some cases (like
1998 * for the dRAID vdev feature). But always leave a reserve of
1999 * zfs_special_class_metadata_reserve_pct exclusively for metadata.
2001 if (DMU_OT_IS_FILE(objtype
) &&
2002 has_special_class
&& size
<= special_smallblk
) {
2003 metaslab_class_t
*special
= spa_special_class(spa
);
2004 uint64_t alloc
= metaslab_class_get_alloc(special
);
2005 uint64_t space
= metaslab_class_get_space(special
);
2007 (space
* (100 - zfs_special_class_metadata_reserve_pct
))
2014 return (spa_normal_class(spa
));
2018 spa_evicting_os_register(spa_t
*spa
, objset_t
*os
)
2020 mutex_enter(&spa
->spa_evicting_os_lock
);
2021 list_insert_head(&spa
->spa_evicting_os_list
, os
);
2022 mutex_exit(&spa
->spa_evicting_os_lock
);
2026 spa_evicting_os_deregister(spa_t
*spa
, objset_t
*os
)
2028 mutex_enter(&spa
->spa_evicting_os_lock
);
2029 list_remove(&spa
->spa_evicting_os_list
, os
);
2030 cv_broadcast(&spa
->spa_evicting_os_cv
);
2031 mutex_exit(&spa
->spa_evicting_os_lock
);
2035 spa_evicting_os_wait(spa_t
*spa
)
2037 mutex_enter(&spa
->spa_evicting_os_lock
);
2038 while (!list_is_empty(&spa
->spa_evicting_os_list
))
2039 cv_wait(&spa
->spa_evicting_os_cv
, &spa
->spa_evicting_os_lock
);
2040 mutex_exit(&spa
->spa_evicting_os_lock
);
2042 dmu_buf_user_evict_wait();
2046 spa_max_replication(spa_t
*spa
)
2049 * As of SPA_VERSION == SPA_VERSION_DITTO_BLOCKS, we are able to
2050 * handle BPs with more than one DVA allocated. Set our max
2051 * replication level accordingly.
2053 if (spa_version(spa
) < SPA_VERSION_DITTO_BLOCKS
)
2055 return (MIN(SPA_DVAS_PER_BP
, spa_max_replication_override
));
2059 spa_prev_software_version(spa_t
*spa
)
2061 return (spa
->spa_prev_software_version
);
2065 spa_deadman_synctime(spa_t
*spa
)
2067 return (spa
->spa_deadman_synctime
);
2071 spa_get_autotrim(spa_t
*spa
)
2073 return (spa
->spa_autotrim
);
2077 spa_deadman_ziotime(spa_t
*spa
)
2079 return (spa
->spa_deadman_ziotime
);
2083 spa_get_deadman_failmode(spa_t
*spa
)
2085 return (spa
->spa_deadman_failmode
);
2089 spa_set_deadman_failmode(spa_t
*spa
, const char *failmode
)
2091 if (strcmp(failmode
, "wait") == 0)
2092 spa
->spa_deadman_failmode
= ZIO_FAILURE_MODE_WAIT
;
2093 else if (strcmp(failmode
, "continue") == 0)
2094 spa
->spa_deadman_failmode
= ZIO_FAILURE_MODE_CONTINUE
;
2095 else if (strcmp(failmode
, "panic") == 0)
2096 spa
->spa_deadman_failmode
= ZIO_FAILURE_MODE_PANIC
;
2098 spa
->spa_deadman_failmode
= ZIO_FAILURE_MODE_WAIT
;
2102 spa_set_deadman_ziotime(hrtime_t ns
)
2106 if (spa_mode_global
!= SPA_MODE_UNINIT
) {
2107 mutex_enter(&spa_namespace_lock
);
2108 while ((spa
= spa_next(spa
)) != NULL
)
2109 spa
->spa_deadman_ziotime
= ns
;
2110 mutex_exit(&spa_namespace_lock
);
2115 spa_set_deadman_synctime(hrtime_t ns
)
2119 if (spa_mode_global
!= SPA_MODE_UNINIT
) {
2120 mutex_enter(&spa_namespace_lock
);
2121 while ((spa
= spa_next(spa
)) != NULL
)
2122 spa
->spa_deadman_synctime
= ns
;
2123 mutex_exit(&spa_namespace_lock
);
2128 dva_get_dsize_sync(spa_t
*spa
, const dva_t
*dva
)
2130 uint64_t asize
= DVA_GET_ASIZE(dva
);
2131 uint64_t dsize
= asize
;
2133 ASSERT(spa_config_held(spa
, SCL_ALL
, RW_READER
) != 0);
2135 if (asize
!= 0 && spa
->spa_deflate
) {
2136 vdev_t
*vd
= vdev_lookup_top(spa
, DVA_GET_VDEV(dva
));
2138 dsize
= (asize
>> SPA_MINBLOCKSHIFT
) *
2139 vd
->vdev_deflate_ratio
;
2146 bp_get_dsize_sync(spa_t
*spa
, const blkptr_t
*bp
)
2150 for (int d
= 0; d
< BP_GET_NDVAS(bp
); d
++)
2151 dsize
+= dva_get_dsize_sync(spa
, &bp
->blk_dva
[d
]);
2157 bp_get_dsize(spa_t
*spa
, const blkptr_t
*bp
)
2161 spa_config_enter(spa
, SCL_VDEV
, FTAG
, RW_READER
);
2163 for (int d
= 0; d
< BP_GET_NDVAS(bp
); d
++)
2164 dsize
+= dva_get_dsize_sync(spa
, &bp
->blk_dva
[d
]);
2166 spa_config_exit(spa
, SCL_VDEV
, FTAG
);
2172 spa_dirty_data(spa_t
*spa
)
2174 return (spa
->spa_dsl_pool
->dp_dirty_total
);
2178 * ==========================================================================
2179 * SPA Import Progress Routines
2180 * ==========================================================================
2183 typedef struct spa_import_progress
{
2184 uint64_t pool_guid
; /* unique id for updates */
2186 spa_load_state_t spa_load_state
;
2187 uint64_t mmp_sec_remaining
; /* MMP activity check */
2188 uint64_t spa_load_max_txg
; /* rewind txg */
2189 procfs_list_node_t smh_node
;
2190 } spa_import_progress_t
;
2192 spa_history_list_t
*spa_import_progress_list
= NULL
;
2195 spa_import_progress_show_header(struct seq_file
*f
)
2197 seq_printf(f
, "%-20s %-14s %-14s %-12s %s\n", "pool_guid",
2198 "load_state", "multihost_secs", "max_txg",
2204 spa_import_progress_show(struct seq_file
*f
, void *data
)
2206 spa_import_progress_t
*sip
= (spa_import_progress_t
*)data
;
2208 seq_printf(f
, "%-20llu %-14llu %-14llu %-12llu %s\n",
2209 (u_longlong_t
)sip
->pool_guid
, (u_longlong_t
)sip
->spa_load_state
,
2210 (u_longlong_t
)sip
->mmp_sec_remaining
,
2211 (u_longlong_t
)sip
->spa_load_max_txg
,
2212 (sip
->pool_name
? sip
->pool_name
: "-"));
2217 /* Remove oldest elements from list until there are no more than 'size' left */
2219 spa_import_progress_truncate(spa_history_list_t
*shl
, unsigned int size
)
2221 spa_import_progress_t
*sip
;
2222 while (shl
->size
> size
) {
2223 sip
= list_remove_head(&shl
->procfs_list
.pl_list
);
2225 spa_strfree(sip
->pool_name
);
2226 kmem_free(sip
, sizeof (spa_import_progress_t
));
2230 IMPLY(size
== 0, list_is_empty(&shl
->procfs_list
.pl_list
));
2234 spa_import_progress_init(void)
2236 spa_import_progress_list
= kmem_zalloc(sizeof (spa_history_list_t
),
2239 spa_import_progress_list
->size
= 0;
2241 spa_import_progress_list
->procfs_list
.pl_private
=
2242 spa_import_progress_list
;
2244 procfs_list_install("zfs",
2248 &spa_import_progress_list
->procfs_list
,
2249 spa_import_progress_show
,
2250 spa_import_progress_show_header
,
2252 offsetof(spa_import_progress_t
, smh_node
));
2256 spa_import_progress_destroy(void)
2258 spa_history_list_t
*shl
= spa_import_progress_list
;
2259 procfs_list_uninstall(&shl
->procfs_list
);
2260 spa_import_progress_truncate(shl
, 0);
2261 procfs_list_destroy(&shl
->procfs_list
);
2262 kmem_free(shl
, sizeof (spa_history_list_t
));
2266 spa_import_progress_set_state(uint64_t pool_guid
,
2267 spa_load_state_t load_state
)
2269 spa_history_list_t
*shl
= spa_import_progress_list
;
2270 spa_import_progress_t
*sip
;
2276 mutex_enter(&shl
->procfs_list
.pl_lock
);
2277 for (sip
= list_tail(&shl
->procfs_list
.pl_list
); sip
!= NULL
;
2278 sip
= list_prev(&shl
->procfs_list
.pl_list
, sip
)) {
2279 if (sip
->pool_guid
== pool_guid
) {
2280 sip
->spa_load_state
= load_state
;
2285 mutex_exit(&shl
->procfs_list
.pl_lock
);
2291 spa_import_progress_set_max_txg(uint64_t pool_guid
, uint64_t load_max_txg
)
2293 spa_history_list_t
*shl
= spa_import_progress_list
;
2294 spa_import_progress_t
*sip
;
2300 mutex_enter(&shl
->procfs_list
.pl_lock
);
2301 for (sip
= list_tail(&shl
->procfs_list
.pl_list
); sip
!= NULL
;
2302 sip
= list_prev(&shl
->procfs_list
.pl_list
, sip
)) {
2303 if (sip
->pool_guid
== pool_guid
) {
2304 sip
->spa_load_max_txg
= load_max_txg
;
2309 mutex_exit(&shl
->procfs_list
.pl_lock
);
2315 spa_import_progress_set_mmp_check(uint64_t pool_guid
,
2316 uint64_t mmp_sec_remaining
)
2318 spa_history_list_t
*shl
= spa_import_progress_list
;
2319 spa_import_progress_t
*sip
;
2325 mutex_enter(&shl
->procfs_list
.pl_lock
);
2326 for (sip
= list_tail(&shl
->procfs_list
.pl_list
); sip
!= NULL
;
2327 sip
= list_prev(&shl
->procfs_list
.pl_list
, sip
)) {
2328 if (sip
->pool_guid
== pool_guid
) {
2329 sip
->mmp_sec_remaining
= mmp_sec_remaining
;
2334 mutex_exit(&shl
->procfs_list
.pl_lock
);
2340 * A new import is in progress, add an entry.
2343 spa_import_progress_add(spa_t
*spa
)
2345 spa_history_list_t
*shl
= spa_import_progress_list
;
2346 spa_import_progress_t
*sip
;
2347 const char *poolname
= NULL
;
2349 sip
= kmem_zalloc(sizeof (spa_import_progress_t
), KM_SLEEP
);
2350 sip
->pool_guid
= spa_guid(spa
);
2352 (void) nvlist_lookup_string(spa
->spa_config
, ZPOOL_CONFIG_POOL_NAME
,
2354 if (poolname
== NULL
)
2355 poolname
= spa_name(spa
);
2356 sip
->pool_name
= spa_strdup(poolname
);
2357 sip
->spa_load_state
= spa_load_state(spa
);
2359 mutex_enter(&shl
->procfs_list
.pl_lock
);
2360 procfs_list_add(&shl
->procfs_list
, sip
);
2362 mutex_exit(&shl
->procfs_list
.pl_lock
);
2366 spa_import_progress_remove(uint64_t pool_guid
)
2368 spa_history_list_t
*shl
= spa_import_progress_list
;
2369 spa_import_progress_t
*sip
;
2371 mutex_enter(&shl
->procfs_list
.pl_lock
);
2372 for (sip
= list_tail(&shl
->procfs_list
.pl_list
); sip
!= NULL
;
2373 sip
= list_prev(&shl
->procfs_list
.pl_list
, sip
)) {
2374 if (sip
->pool_guid
== pool_guid
) {
2376 spa_strfree(sip
->pool_name
);
2377 list_remove(&shl
->procfs_list
.pl_list
, sip
);
2379 kmem_free(sip
, sizeof (spa_import_progress_t
));
2383 mutex_exit(&shl
->procfs_list
.pl_lock
);
2387 * ==========================================================================
2388 * Initialization and Termination
2389 * ==========================================================================
2393 spa_name_compare(const void *a1
, const void *a2
)
2395 const spa_t
*s1
= a1
;
2396 const spa_t
*s2
= a2
;
2399 s
= strcmp(s1
->spa_name
, s2
->spa_name
);
2401 return (TREE_ISIGN(s
));
2411 spa_init(spa_mode_t mode
)
2413 mutex_init(&spa_namespace_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
2414 mutex_init(&spa_spare_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
2415 mutex_init(&spa_l2cache_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
2416 cv_init(&spa_namespace_cv
, NULL
, CV_DEFAULT
, NULL
);
2418 avl_create(&spa_namespace_avl
, spa_name_compare
, sizeof (spa_t
),
2419 offsetof(spa_t
, spa_avl
));
2421 avl_create(&spa_spare_avl
, spa_spare_compare
, sizeof (spa_aux_t
),
2422 offsetof(spa_aux_t
, aux_avl
));
2424 avl_create(&spa_l2cache_avl
, spa_l2cache_compare
, sizeof (spa_aux_t
),
2425 offsetof(spa_aux_t
, aux_avl
));
2427 spa_mode_global
= mode
;
2430 if (spa_mode_global
!= SPA_MODE_READ
&& dprintf_find_string("watch")) {
2431 struct sigaction sa
;
2433 sa
.sa_flags
= SA_SIGINFO
;
2434 sigemptyset(&sa
.sa_mask
);
2435 sa
.sa_sigaction
= arc_buf_sigsegv
;
2437 if (sigaction(SIGSEGV
, &sa
, NULL
) == -1) {
2438 perror("could not enable watchpoints: "
2439 "sigaction(SIGSEGV, ...) = ");
2447 zfs_refcount_init();
2450 metaslab_stat_init();
2456 vdev_mirror_stat_init();
2457 vdev_raidz_math_init();
2462 zpool_feature_init();
2468 spa_import_progress_init();
2479 vdev_mirror_stat_fini();
2480 vdev_raidz_math_fini();
2487 metaslab_stat_fini();
2490 zfs_refcount_fini();
2494 spa_import_progress_destroy();
2496 avl_destroy(&spa_namespace_avl
);
2497 avl_destroy(&spa_spare_avl
);
2498 avl_destroy(&spa_l2cache_avl
);
2500 cv_destroy(&spa_namespace_cv
);
2501 mutex_destroy(&spa_namespace_lock
);
2502 mutex_destroy(&spa_spare_lock
);
2503 mutex_destroy(&spa_l2cache_lock
);
2507 * Return whether this pool has a dedicated slog device. No locking needed.
2508 * It's not a problem if the wrong answer is returned as it's only for
2509 * performance and not correctness.
2512 spa_has_slogs(spa_t
*spa
)
2514 return (spa
->spa_log_class
->mc_groups
!= 0);
2518 spa_get_log_state(spa_t
*spa
)
2520 return (spa
->spa_log_state
);
2524 spa_set_log_state(spa_t
*spa
, spa_log_state_t state
)
2526 spa
->spa_log_state
= state
;
2530 spa_is_root(spa_t
*spa
)
2532 return (spa
->spa_is_root
);
2536 spa_writeable(spa_t
*spa
)
2538 return (!!(spa
->spa_mode
& SPA_MODE_WRITE
) && spa
->spa_trust_config
);
2542 * Returns true if there is a pending sync task in any of the current
2543 * syncing txg, the current quiescing txg, or the current open txg.
2546 spa_has_pending_synctask(spa_t
*spa
)
2548 return (!txg_all_lists_empty(&spa
->spa_dsl_pool
->dp_sync_tasks
) ||
2549 !txg_all_lists_empty(&spa
->spa_dsl_pool
->dp_early_sync_tasks
));
2553 spa_mode(spa_t
*spa
)
2555 return (spa
->spa_mode
);
2559 spa_bootfs(spa_t
*spa
)
2561 return (spa
->spa_bootfs
);
2565 spa_delegation(spa_t
*spa
)
2567 return (spa
->spa_delegation
);
2571 spa_meta_objset(spa_t
*spa
)
2573 return (spa
->spa_meta_objset
);
2577 spa_dedup_checksum(spa_t
*spa
)
2579 return (spa
->spa_dedup_checksum
);
2583 * Reset pool scan stat per scan pass (or reboot).
2586 spa_scan_stat_init(spa_t
*spa
)
2588 /* data not stored on disk */
2589 spa
->spa_scan_pass_start
= gethrestime_sec();
2590 if (dsl_scan_is_paused_scrub(spa
->spa_dsl_pool
->dp_scan
))
2591 spa
->spa_scan_pass_scrub_pause
= spa
->spa_scan_pass_start
;
2593 spa
->spa_scan_pass_scrub_pause
= 0;
2595 if (dsl_errorscrub_is_paused(spa
->spa_dsl_pool
->dp_scan
))
2596 spa
->spa_scan_pass_errorscrub_pause
= spa
->spa_scan_pass_start
;
2598 spa
->spa_scan_pass_errorscrub_pause
= 0;
2600 spa
->spa_scan_pass_scrub_spent_paused
= 0;
2601 spa
->spa_scan_pass_exam
= 0;
2602 spa
->spa_scan_pass_issued
= 0;
2604 // error scrub stats
2605 spa
->spa_scan_pass_errorscrub_spent_paused
= 0;
2609 * Get scan stats for zpool status reports
2612 spa_scan_get_stats(spa_t
*spa
, pool_scan_stat_t
*ps
)
2614 dsl_scan_t
*scn
= spa
->spa_dsl_pool
? spa
->spa_dsl_pool
->dp_scan
: NULL
;
2616 if (scn
== NULL
|| (scn
->scn_phys
.scn_func
== POOL_SCAN_NONE
&&
2617 scn
->errorscrub_phys
.dep_func
== POOL_SCAN_NONE
))
2618 return (SET_ERROR(ENOENT
));
2620 memset(ps
, 0, sizeof (pool_scan_stat_t
));
2622 /* data stored on disk */
2623 ps
->pss_func
= scn
->scn_phys
.scn_func
;
2624 ps
->pss_state
= scn
->scn_phys
.scn_state
;
2625 ps
->pss_start_time
= scn
->scn_phys
.scn_start_time
;
2626 ps
->pss_end_time
= scn
->scn_phys
.scn_end_time
;
2627 ps
->pss_to_examine
= scn
->scn_phys
.scn_to_examine
;
2628 ps
->pss_examined
= scn
->scn_phys
.scn_examined
;
2629 ps
->pss_skipped
= scn
->scn_phys
.scn_skipped
;
2630 ps
->pss_processed
= scn
->scn_phys
.scn_processed
;
2631 ps
->pss_errors
= scn
->scn_phys
.scn_errors
;
2633 /* data not stored on disk */
2634 ps
->pss_pass_exam
= spa
->spa_scan_pass_exam
;
2635 ps
->pss_pass_start
= spa
->spa_scan_pass_start
;
2636 ps
->pss_pass_scrub_pause
= spa
->spa_scan_pass_scrub_pause
;
2637 ps
->pss_pass_scrub_spent_paused
= spa
->spa_scan_pass_scrub_spent_paused
;
2638 ps
->pss_pass_issued
= spa
->spa_scan_pass_issued
;
2640 scn
->scn_issued_before_pass
+ spa
->spa_scan_pass_issued
;
2642 /* error scrub data stored on disk */
2643 ps
->pss_error_scrub_func
= scn
->errorscrub_phys
.dep_func
;
2644 ps
->pss_error_scrub_state
= scn
->errorscrub_phys
.dep_state
;
2645 ps
->pss_error_scrub_start
= scn
->errorscrub_phys
.dep_start_time
;
2646 ps
->pss_error_scrub_end
= scn
->errorscrub_phys
.dep_end_time
;
2647 ps
->pss_error_scrub_examined
= scn
->errorscrub_phys
.dep_examined
;
2648 ps
->pss_error_scrub_to_be_examined
=
2649 scn
->errorscrub_phys
.dep_to_examine
;
2651 /* error scrub data not stored on disk */
2652 ps
->pss_pass_error_scrub_pause
= spa
->spa_scan_pass_errorscrub_pause
;
2658 spa_maxblocksize(spa_t
*spa
)
2660 if (spa_feature_is_enabled(spa
, SPA_FEATURE_LARGE_BLOCKS
))
2661 return (SPA_MAXBLOCKSIZE
);
2663 return (SPA_OLD_MAXBLOCKSIZE
);
2668 * Returns the txg that the last device removal completed. No indirect mappings
2669 * have been added since this txg.
2672 spa_get_last_removal_txg(spa_t
*spa
)
2675 uint64_t ret
= -1ULL;
2677 spa_config_enter(spa
, SCL_VDEV
, FTAG
, RW_READER
);
2679 * sr_prev_indirect_vdev is only modified while holding all the
2680 * config locks, so it is sufficient to hold SCL_VDEV as reader when
2683 vdevid
= spa
->spa_removing_phys
.sr_prev_indirect_vdev
;
2685 while (vdevid
!= -1ULL) {
2686 vdev_t
*vd
= vdev_lookup_top(spa
, vdevid
);
2687 vdev_indirect_births_t
*vib
= vd
->vdev_indirect_births
;
2689 ASSERT3P(vd
->vdev_ops
, ==, &vdev_indirect_ops
);
2692 * If the removal did not remap any data, we don't care.
2694 if (vdev_indirect_births_count(vib
) != 0) {
2695 ret
= vdev_indirect_births_last_entry_txg(vib
);
2699 vdevid
= vd
->vdev_indirect_config
.vic_prev_indirect_vdev
;
2701 spa_config_exit(spa
, SCL_VDEV
, FTAG
);
2704 spa_feature_is_active(spa
, SPA_FEATURE_DEVICE_REMOVAL
));
2710 spa_maxdnodesize(spa_t
*spa
)
2712 if (spa_feature_is_enabled(spa
, SPA_FEATURE_LARGE_DNODE
))
2713 return (DNODE_MAX_SIZE
);
2715 return (DNODE_MIN_SIZE
);
2719 spa_multihost(spa_t
*spa
)
2721 return (spa
->spa_multihost
? B_TRUE
: B_FALSE
);
2725 spa_get_hostid(spa_t
*spa
)
2727 return (spa
->spa_hostid
);
2731 spa_trust_config(spa_t
*spa
)
2733 return (spa
->spa_trust_config
);
2737 spa_missing_tvds_allowed(spa_t
*spa
)
2739 return (spa
->spa_missing_tvds_allowed
);
2743 spa_syncing_log_sm(spa_t
*spa
)
2745 return (spa
->spa_syncing_log_sm
);
2749 spa_set_missing_tvds(spa_t
*spa
, uint64_t missing
)
2751 spa
->spa_missing_tvds
= missing
;
2755 * Return the pool state string ("ONLINE", "DEGRADED", "SUSPENDED", etc).
2758 spa_state_to_name(spa_t
*spa
)
2760 ASSERT3P(spa
, !=, NULL
);
2763 * it is possible for the spa to exist, without root vdev
2764 * as the spa transitions during import/export
2766 vdev_t
*rvd
= spa
->spa_root_vdev
;
2768 return ("TRANSITIONING");
2770 vdev_state_t state
= rvd
->vdev_state
;
2771 vdev_aux_t aux
= rvd
->vdev_stat
.vs_aux
;
2773 if (spa_suspended(spa
))
2774 return ("SUSPENDED");
2777 case VDEV_STATE_CLOSED
:
2778 case VDEV_STATE_OFFLINE
:
2780 case VDEV_STATE_REMOVED
:
2782 case VDEV_STATE_CANT_OPEN
:
2783 if (aux
== VDEV_AUX_CORRUPT_DATA
|| aux
== VDEV_AUX_BAD_LOG
)
2785 else if (aux
== VDEV_AUX_SPLIT_POOL
)
2789 case VDEV_STATE_FAULTED
:
2791 case VDEV_STATE_DEGRADED
:
2792 return ("DEGRADED");
2793 case VDEV_STATE_HEALTHY
:
2803 spa_top_vdevs_spacemap_addressable(spa_t
*spa
)
2805 vdev_t
*rvd
= spa
->spa_root_vdev
;
2806 for (uint64_t c
= 0; c
< rvd
->vdev_children
; c
++) {
2807 if (!vdev_is_spacemap_addressable(rvd
->vdev_child
[c
]))
2814 spa_has_checkpoint(spa_t
*spa
)
2816 return (spa
->spa_checkpoint_txg
!= 0);
2820 spa_importing_readonly_checkpoint(spa_t
*spa
)
2822 return ((spa
->spa_import_flags
& ZFS_IMPORT_CHECKPOINT
) &&
2823 spa
->spa_mode
== SPA_MODE_READ
);
2827 spa_min_claim_txg(spa_t
*spa
)
2829 uint64_t checkpoint_txg
= spa
->spa_uberblock
.ub_checkpoint_txg
;
2831 if (checkpoint_txg
!= 0)
2832 return (checkpoint_txg
+ 1);
2834 return (spa
->spa_first_txg
);
2838 * If there is a checkpoint, async destroys may consume more space from
2839 * the pool instead of freeing it. In an attempt to save the pool from
2840 * getting suspended when it is about to run out of space, we stop
2841 * processing async destroys.
2844 spa_suspend_async_destroy(spa_t
*spa
)
2846 dsl_pool_t
*dp
= spa_get_dsl(spa
);
2848 uint64_t unreserved
= dsl_pool_unreserved_space(dp
,
2849 ZFS_SPACE_CHECK_EXTRA_RESERVED
);
2850 uint64_t used
= dsl_dir_phys(dp
->dp_root_dir
)->dd_used_bytes
;
2851 uint64_t avail
= (unreserved
> used
) ? (unreserved
- used
) : 0;
2853 if (spa_has_checkpoint(spa
) && avail
== 0)
2859 #if defined(_KERNEL)
2862 param_set_deadman_failmode_common(const char *val
)
2868 return (SET_ERROR(EINVAL
));
2870 if ((p
= strchr(val
, '\n')) != NULL
)
2873 if (strcmp(val
, "wait") != 0 && strcmp(val
, "continue") != 0 &&
2874 strcmp(val
, "panic"))
2875 return (SET_ERROR(EINVAL
));
2877 if (spa_mode_global
!= SPA_MODE_UNINIT
) {
2878 mutex_enter(&spa_namespace_lock
);
2879 while ((spa
= spa_next(spa
)) != NULL
)
2880 spa_set_deadman_failmode(spa
, val
);
2881 mutex_exit(&spa_namespace_lock
);
2888 /* Namespace manipulation */
2889 EXPORT_SYMBOL(spa_lookup
);
2890 EXPORT_SYMBOL(spa_add
);
2891 EXPORT_SYMBOL(spa_remove
);
2892 EXPORT_SYMBOL(spa_next
);
2894 /* Refcount functions */
2895 EXPORT_SYMBOL(spa_open_ref
);
2896 EXPORT_SYMBOL(spa_close
);
2897 EXPORT_SYMBOL(spa_refcount_zero
);
2899 /* Pool configuration lock */
2900 EXPORT_SYMBOL(spa_config_tryenter
);
2901 EXPORT_SYMBOL(spa_config_enter
);
2902 EXPORT_SYMBOL(spa_config_exit
);
2903 EXPORT_SYMBOL(spa_config_held
);
2905 /* Pool vdev add/remove lock */
2906 EXPORT_SYMBOL(spa_vdev_enter
);
2907 EXPORT_SYMBOL(spa_vdev_exit
);
2909 /* Pool vdev state change lock */
2910 EXPORT_SYMBOL(spa_vdev_state_enter
);
2911 EXPORT_SYMBOL(spa_vdev_state_exit
);
2913 /* Accessor functions */
2914 EXPORT_SYMBOL(spa_shutting_down
);
2915 EXPORT_SYMBOL(spa_get_dsl
);
2916 EXPORT_SYMBOL(spa_get_rootblkptr
);
2917 EXPORT_SYMBOL(spa_set_rootblkptr
);
2918 EXPORT_SYMBOL(spa_altroot
);
2919 EXPORT_SYMBOL(spa_sync_pass
);
2920 EXPORT_SYMBOL(spa_name
);
2921 EXPORT_SYMBOL(spa_guid
);
2922 EXPORT_SYMBOL(spa_last_synced_txg
);
2923 EXPORT_SYMBOL(spa_first_txg
);
2924 EXPORT_SYMBOL(spa_syncing_txg
);
2925 EXPORT_SYMBOL(spa_version
);
2926 EXPORT_SYMBOL(spa_state
);
2927 EXPORT_SYMBOL(spa_load_state
);
2928 EXPORT_SYMBOL(spa_freeze_txg
);
2929 EXPORT_SYMBOL(spa_get_dspace
);
2930 EXPORT_SYMBOL(spa_update_dspace
);
2931 EXPORT_SYMBOL(spa_deflate
);
2932 EXPORT_SYMBOL(spa_normal_class
);
2933 EXPORT_SYMBOL(spa_log_class
);
2934 EXPORT_SYMBOL(spa_special_class
);
2935 EXPORT_SYMBOL(spa_preferred_class
);
2936 EXPORT_SYMBOL(spa_max_replication
);
2937 EXPORT_SYMBOL(spa_prev_software_version
);
2938 EXPORT_SYMBOL(spa_get_failmode
);
2939 EXPORT_SYMBOL(spa_suspended
);
2940 EXPORT_SYMBOL(spa_bootfs
);
2941 EXPORT_SYMBOL(spa_delegation
);
2942 EXPORT_SYMBOL(spa_meta_objset
);
2943 EXPORT_SYMBOL(spa_maxblocksize
);
2944 EXPORT_SYMBOL(spa_maxdnodesize
);
2946 /* Miscellaneous support routines */
2947 EXPORT_SYMBOL(spa_guid_exists
);
2948 EXPORT_SYMBOL(spa_strdup
);
2949 EXPORT_SYMBOL(spa_strfree
);
2950 EXPORT_SYMBOL(spa_generate_guid
);
2951 EXPORT_SYMBOL(snprintf_blkptr
);
2952 EXPORT_SYMBOL(spa_freeze
);
2953 EXPORT_SYMBOL(spa_upgrade
);
2954 EXPORT_SYMBOL(spa_evict_all
);
2955 EXPORT_SYMBOL(spa_lookup_by_guid
);
2956 EXPORT_SYMBOL(spa_has_spare
);
2957 EXPORT_SYMBOL(dva_get_dsize_sync
);
2958 EXPORT_SYMBOL(bp_get_dsize_sync
);
2959 EXPORT_SYMBOL(bp_get_dsize
);
2960 EXPORT_SYMBOL(spa_has_slogs
);
2961 EXPORT_SYMBOL(spa_is_root
);
2962 EXPORT_SYMBOL(spa_writeable
);
2963 EXPORT_SYMBOL(spa_mode
);
2964 EXPORT_SYMBOL(spa_namespace_lock
);
2965 EXPORT_SYMBOL(spa_trust_config
);
2966 EXPORT_SYMBOL(spa_missing_tvds_allowed
);
2967 EXPORT_SYMBOL(spa_set_missing_tvds
);
2968 EXPORT_SYMBOL(spa_state_to_name
);
2969 EXPORT_SYMBOL(spa_importing_readonly_checkpoint
);
2970 EXPORT_SYMBOL(spa_min_claim_txg
);
2971 EXPORT_SYMBOL(spa_suspend_async_destroy
);
2972 EXPORT_SYMBOL(spa_has_checkpoint
);
2973 EXPORT_SYMBOL(spa_top_vdevs_spacemap_addressable
);
2975 ZFS_MODULE_PARAM(zfs
, zfs_
, flags
, UINT
, ZMOD_RW
,
2976 "Set additional debugging flags");
2978 ZFS_MODULE_PARAM(zfs
, zfs_
, recover
, INT
, ZMOD_RW
,
2979 "Set to attempt to recover from fatal errors");
2981 ZFS_MODULE_PARAM(zfs
, zfs_
, free_leak_on_eio
, INT
, ZMOD_RW
,
2982 "Set to ignore IO errors during free and permanently leak the space");
2984 ZFS_MODULE_PARAM(zfs_deadman
, zfs_deadman_
, checktime_ms
, U64
, ZMOD_RW
,
2985 "Dead I/O check interval in milliseconds");
2987 ZFS_MODULE_PARAM(zfs_deadman
, zfs_deadman_
, enabled
, INT
, ZMOD_RW
,
2988 "Enable deadman timer");
2990 ZFS_MODULE_PARAM(zfs_spa
, spa_
, asize_inflation
, UINT
, ZMOD_RW
,
2991 "SPA size estimate multiplication factor");
2993 ZFS_MODULE_PARAM(zfs
, zfs_
, ddt_data_is_special
, INT
, ZMOD_RW
,
2994 "Place DDT data into the special class");
2996 ZFS_MODULE_PARAM(zfs
, zfs_
, user_indirect_is_special
, INT
, ZMOD_RW
,
2997 "Place user data indirect blocks into the special class");
3000 ZFS_MODULE_PARAM_CALL(zfs_deadman
, zfs_deadman_
, failmode
,
3001 param_set_deadman_failmode
, param_get_charp
, ZMOD_RW
,
3002 "Failmode for deadman timer");
3004 ZFS_MODULE_PARAM_CALL(zfs_deadman
, zfs_deadman_
, synctime_ms
,
3005 param_set_deadman_synctime
, spl_param_get_u64
, ZMOD_RW
,
3006 "Pool sync expiration time in milliseconds");
3008 ZFS_MODULE_PARAM_CALL(zfs_deadman
, zfs_deadman_
, ziotime_ms
,
3009 param_set_deadman_ziotime
, spl_param_get_u64
, ZMOD_RW
,
3010 "IO expiration time in milliseconds");
3012 ZFS_MODULE_PARAM(zfs
, zfs_
, special_class_metadata_reserve_pct
, UINT
, ZMOD_RW
,
3013 "Small file blocks in special vdevs depends on this much "
3014 "free space available");
3017 ZFS_MODULE_PARAM_CALL(zfs_spa
, spa_
, slop_shift
, param_set_slop_shift
,
3018 param_get_uint
, ZMOD_RW
, "Reserved free space in pool");
3020 ZFS_MODULE_PARAM(zfs
, spa_
, num_allocators
, INT
, ZMOD_RW
,
3021 "Number of allocators per spa, capped by ncpus");