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 http://www.opensolaris.org/os/licensing.
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) 2012 by Delphix. All rights reserved.
24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
27 #include <sys/zfs_context.h>
28 #include <sys/spa_impl.h>
30 #include <sys/zio_checksum.h>
31 #include <sys/zio_compress.h>
33 #include <sys/dmu_tx.h>
36 #include <sys/vdev_impl.h>
37 #include <sys/metaslab.h>
38 #include <sys/uberblock_impl.h>
41 #include <sys/unique.h>
42 #include <sys/dsl_pool.h>
43 #include <sys/dsl_dir.h>
44 #include <sys/dsl_prop.h>
45 #include <sys/fm/util.h>
46 #include <sys/dsl_scan.h>
47 #include <sys/fs/zfs.h>
48 #include <sys/metaslab_impl.h>
52 #include "zfeature_common.h"
57 * There are four basic locks for managing spa_t structures:
59 * spa_namespace_lock (global mutex)
61 * This lock must be acquired to do any of the following:
63 * - Lookup a spa_t by name
64 * - Add or remove a spa_t from the namespace
65 * - Increase spa_refcount from non-zero
66 * - Check if spa_refcount is zero
68 * - add/remove/attach/detach devices
69 * - Held for the duration of create/destroy/import/export
71 * It does not need to handle recursion. A create or destroy may
72 * reference objects (files or zvols) in other pools, but by
73 * definition they must have an existing reference, and will never need
74 * to lookup a spa_t by name.
76 * spa_refcount (per-spa refcount_t protected by mutex)
78 * This reference count keep track of any active users of the spa_t. The
79 * spa_t cannot be destroyed or freed while this is non-zero. Internally,
80 * the refcount is never really 'zero' - opening a pool implicitly keeps
81 * some references in the DMU. Internally we check against spa_minref, but
82 * present the image of a zero/non-zero value to consumers.
84 * spa_config_lock[] (per-spa array of rwlocks)
86 * This protects the spa_t from config changes, and must be held in
87 * the following circumstances:
89 * - RW_READER to perform I/O to the spa
90 * - RW_WRITER to change the vdev config
92 * The locking order is fairly straightforward:
94 * spa_namespace_lock -> spa_refcount
96 * The namespace lock must be acquired to increase the refcount from 0
97 * or to check if it is zero.
99 * spa_refcount -> spa_config_lock[]
101 * There must be at least one valid reference on the spa_t to acquire
104 * spa_namespace_lock -> spa_config_lock[]
106 * The namespace lock must always be taken before the config lock.
109 * The spa_namespace_lock can be acquired directly and is globally visible.
111 * The namespace is manipulated using the following functions, all of which
112 * require the spa_namespace_lock to be held.
114 * spa_lookup() Lookup a spa_t by name.
116 * spa_add() Create a new spa_t in the namespace.
118 * spa_remove() Remove a spa_t from the namespace. This also
119 * frees up any memory associated with the spa_t.
121 * spa_next() Returns the next spa_t in the system, or the
122 * first if NULL is passed.
124 * spa_evict_all() Shutdown and remove all spa_t structures in
127 * spa_guid_exists() Determine whether a pool/device guid exists.
129 * The spa_refcount is manipulated using the following functions:
131 * spa_open_ref() Adds a reference to the given spa_t. Must be
132 * called with spa_namespace_lock held if the
133 * refcount is currently zero.
135 * spa_close() Remove a reference from the spa_t. This will
136 * not free the spa_t or remove it from the
137 * namespace. No locking is required.
139 * spa_refcount_zero() Returns true if the refcount is currently
140 * zero. Must be called with spa_namespace_lock
143 * The spa_config_lock[] is an array of rwlocks, ordered as follows:
144 * SCL_CONFIG > SCL_STATE > SCL_ALLOC > SCL_ZIO > SCL_FREE > SCL_VDEV.
145 * spa_config_lock[] is manipulated with spa_config_{enter,exit,held}().
147 * To read the configuration, it suffices to hold one of these locks as reader.
148 * To modify the configuration, you must hold all locks as writer. To modify
149 * vdev state without altering the vdev tree's topology (e.g. online/offline),
150 * you must hold SCL_STATE and SCL_ZIO as writer.
152 * We use these distinct config locks to avoid recursive lock entry.
153 * For example, spa_sync() (which holds SCL_CONFIG as reader) induces
154 * block allocations (SCL_ALLOC), which may require reading space maps
155 * from disk (dmu_read() -> zio_read() -> SCL_ZIO).
157 * The spa config locks cannot be normal rwlocks because we need the
158 * ability to hand off ownership. For example, SCL_ZIO is acquired
159 * by the issuing thread and later released by an interrupt thread.
160 * They do, however, obey the usual write-wanted semantics to prevent
161 * writer (i.e. system administrator) starvation.
163 * The lock acquisition rules are as follows:
166 * Protects changes to the vdev tree topology, such as vdev
167 * add/remove/attach/detach. Protects the dirty config list
168 * (spa_config_dirty_list) and the set of spares and l2arc devices.
171 * Protects changes to pool state and vdev state, such as vdev
172 * online/offline/fault/degrade/clear. Protects the dirty state list
173 * (spa_state_dirty_list) and global pool state (spa_state).
176 * Protects changes to metaslab groups and classes.
177 * Held as reader by metaslab_alloc() and metaslab_claim().
180 * Held by bp-level zios (those which have no io_vd upon entry)
181 * to prevent changes to the vdev tree. The bp-level zio implicitly
182 * protects all of its vdev child zios, which do not hold SCL_ZIO.
185 * Protects changes to metaslab groups and classes.
186 * Held as reader by metaslab_free(). SCL_FREE is distinct from
187 * SCL_ALLOC, and lower than SCL_ZIO, so that we can safely free
188 * blocks in zio_done() while another i/o that holds either
189 * SCL_ALLOC or SCL_ZIO is waiting for this i/o to complete.
192 * Held as reader to prevent changes to the vdev tree during trivial
193 * inquiries such as bp_get_dsize(). SCL_VDEV is distinct from the
194 * other locks, and lower than all of them, to ensure that it's safe
195 * to acquire regardless of caller context.
197 * In addition, the following rules apply:
199 * (a) spa_props_lock protects pool properties, spa_config and spa_config_list.
200 * The lock ordering is SCL_CONFIG > spa_props_lock.
202 * (b) I/O operations on leaf vdevs. For any zio operation that takes
203 * an explicit vdev_t argument -- such as zio_ioctl(), zio_read_phys(),
204 * or zio_write_phys() -- the caller must ensure that the config cannot
205 * cannot change in the interim, and that the vdev cannot be reopened.
206 * SCL_STATE as reader suffices for both.
208 * The vdev configuration is protected by spa_vdev_enter() / spa_vdev_exit().
210 * spa_vdev_enter() Acquire the namespace lock and the config lock
213 * spa_vdev_exit() Release the config lock, wait for all I/O
214 * to complete, sync the updated configs to the
215 * cache, and release the namespace lock.
217 * vdev state is protected by spa_vdev_state_enter() / spa_vdev_state_exit().
218 * Like spa_vdev_enter/exit, these are convenience wrappers -- the actual
219 * locking is, always, based on spa_namespace_lock and spa_config_lock[].
221 * spa_rename() is also implemented within this file since it requires
222 * manipulation of the namespace.
225 static avl_tree_t spa_namespace_avl;
226 kmutex_t spa_namespace_lock;
227 static kcondvar_t spa_namespace_cv;
228 static int spa_active_count;
229 int spa_max_replication_override = SPA_DVAS_PER_BP;
231 static kmutex_t spa_spare_lock;
232 static avl_tree_t spa_spare_avl;
233 static kmutex_t spa_l2cache_lock;
234 static avl_tree_t spa_l2cache_avl;
236 kmem_cache_t *spa_buffer_pool;
240 * Expiration time in units of zfs_txg_synctime_ms. This value has two
241 * meanings. First it is used to determine when the spa_deadman logic
242 * should fire. By default the spa_deadman will fire if spa_sync has
243 * not completed in 1000 * zfs_txg_synctime_ms (i.e. 1000 seconds).
244 * Secondly, the value determines if an I/O is considered "hung".
245 * Any I/O that has not completed in zfs_deadman_synctime is considered
246 * "hung" resulting in a zevent being posted.
247 * 1000 zfs_txg_synctime_ms (i.e. 1000 seconds).
249 unsigned long zfs_deadman_synctime = 1000ULL;
252 * By default the deadman is enabled.
254 int zfs_deadman_enabled = 1;
258 * ==========================================================================
260 * ==========================================================================
263 spa_config_lock_init(spa_t *spa)
267 for (i = 0; i < SCL_LOCKS; i++) {
268 spa_config_lock_t *scl = &spa->spa_config_lock[i];
269 mutex_init(&scl->scl_lock, NULL, MUTEX_DEFAULT, NULL);
270 cv_init(&scl->scl_cv, NULL, CV_DEFAULT, NULL);
271 refcount_create(&scl->scl_count);
272 scl->scl_writer = NULL;
273 scl->scl_write_wanted = 0;
278 spa_config_lock_destroy(spa_t *spa)
282 for (i = 0; i < SCL_LOCKS; i++) {
283 spa_config_lock_t *scl = &spa->spa_config_lock[i];
284 mutex_destroy(&scl->scl_lock);
285 cv_destroy(&scl->scl_cv);
286 refcount_destroy(&scl->scl_count);
287 ASSERT(scl->scl_writer == NULL);
288 ASSERT(scl->scl_write_wanted == 0);
293 spa_config_tryenter(spa_t *spa, int locks, void *tag, krw_t rw)
297 for (i = 0; i < SCL_LOCKS; i++) {
298 spa_config_lock_t *scl = &spa->spa_config_lock[i];
299 if (!(locks & (1 << i)))
301 mutex_enter(&scl->scl_lock);
302 if (rw == RW_READER) {
303 if (scl->scl_writer || scl->scl_write_wanted) {
304 mutex_exit(&scl->scl_lock);
305 spa_config_exit(spa, locks ^ (1 << i), tag);
309 ASSERT(scl->scl_writer != curthread);
310 if (!refcount_is_zero(&scl->scl_count)) {
311 mutex_exit(&scl->scl_lock);
312 spa_config_exit(spa, locks ^ (1 << i), tag);
315 scl->scl_writer = curthread;
317 (void) refcount_add(&scl->scl_count, tag);
318 mutex_exit(&scl->scl_lock);
324 spa_config_enter(spa_t *spa, int locks, void *tag, krw_t rw)
329 for (i = 0; i < SCL_LOCKS; i++) {
330 spa_config_lock_t *scl = &spa->spa_config_lock[i];
331 if (scl->scl_writer == curthread)
332 wlocks_held |= (1 << i);
333 if (!(locks & (1 << i)))
335 mutex_enter(&scl->scl_lock);
336 if (rw == RW_READER) {
337 while (scl->scl_writer || scl->scl_write_wanted) {
338 cv_wait(&scl->scl_cv, &scl->scl_lock);
341 ASSERT(scl->scl_writer != curthread);
342 while (!refcount_is_zero(&scl->scl_count)) {
343 scl->scl_write_wanted++;
344 cv_wait(&scl->scl_cv, &scl->scl_lock);
345 scl->scl_write_wanted--;
347 scl->scl_writer = curthread;
349 (void) refcount_add(&scl->scl_count, tag);
350 mutex_exit(&scl->scl_lock);
352 ASSERT(wlocks_held <= locks);
356 spa_config_exit(spa_t *spa, int locks, void *tag)
360 for (i = SCL_LOCKS - 1; i >= 0; i--) {
361 spa_config_lock_t *scl = &spa->spa_config_lock[i];
362 if (!(locks & (1 << i)))
364 mutex_enter(&scl->scl_lock);
365 ASSERT(!refcount_is_zero(&scl->scl_count));
366 if (refcount_remove(&scl->scl_count, tag) == 0) {
367 ASSERT(scl->scl_writer == NULL ||
368 scl->scl_writer == curthread);
369 scl->scl_writer = NULL; /* OK in either case */
370 cv_broadcast(&scl->scl_cv);
372 mutex_exit(&scl->scl_lock);
377 spa_config_held(spa_t *spa, int locks, krw_t rw)
379 int i, locks_held = 0;
381 for (i = 0; i < SCL_LOCKS; i++) {
382 spa_config_lock_t *scl = &spa->spa_config_lock[i];
383 if (!(locks & (1 << i)))
385 if ((rw == RW_READER && !refcount_is_zero(&scl->scl_count)) ||
386 (rw == RW_WRITER && scl->scl_writer == curthread))
387 locks_held |= 1 << i;
394 * ==========================================================================
395 * SPA namespace functions
396 * ==========================================================================
400 * Lookup the named spa_t in the AVL tree. The spa_namespace_lock must be held.
401 * Returns NULL if no matching spa_t is found.
404 spa_lookup(const char *name)
406 static spa_t search; /* spa_t is large; don't allocate on stack */
412 ASSERT(MUTEX_HELD(&spa_namespace_lock));
415 * If it's a full dataset name, figure out the pool name and
418 cp = strpbrk(name, "/@");
424 (void) strlcpy(search.spa_name, name, sizeof (search.spa_name));
425 spa = avl_find(&spa_namespace_avl, &search, &where);
434 * Fires when spa_sync has not completed within zfs_deadman_synctime_ms.
435 * If the zfs_deadman_enabled flag is set then it inspects all vdev queues
436 * looking for potentially hung I/Os.
439 spa_deadman(void *arg)
443 zfs_dbgmsg("slow spa_sync: started %llu seconds ago, calls %llu",
444 (gethrtime() - spa->spa_sync_starttime) / NANOSEC,
445 ++spa->spa_deadman_calls);
446 if (zfs_deadman_enabled)
447 vdev_deadman(spa->spa_root_vdev);
449 spa->spa_deadman_tqid = taskq_dispatch_delay(system_taskq,
450 spa_deadman, spa, TQ_SLEEP, ddi_get_lbolt() +
451 NSEC_TO_TICK(spa->spa_deadman_synctime));
455 * Create an uninitialized spa_t with the given name. Requires
456 * spa_namespace_lock. The caller must ensure that the spa_t doesn't already
457 * exist by calling spa_lookup() first.
460 spa_add(const char *name, nvlist_t *config, const char *altroot)
463 spa_config_dirent_t *dp;
466 ASSERT(MUTEX_HELD(&spa_namespace_lock));
468 spa = kmem_zalloc(sizeof (spa_t), KM_PUSHPAGE | KM_NODEBUG);
470 mutex_init(&spa->spa_async_lock, NULL, MUTEX_DEFAULT, NULL);
471 mutex_init(&spa->spa_errlist_lock, NULL, MUTEX_DEFAULT, NULL);
472 mutex_init(&spa->spa_errlog_lock, NULL, MUTEX_DEFAULT, NULL);
473 mutex_init(&spa->spa_history_lock, NULL, MUTEX_DEFAULT, NULL);
474 mutex_init(&spa->spa_proc_lock, NULL, MUTEX_DEFAULT, NULL);
475 mutex_init(&spa->spa_props_lock, NULL, MUTEX_DEFAULT, NULL);
476 mutex_init(&spa->spa_scrub_lock, NULL, MUTEX_DEFAULT, NULL);
477 mutex_init(&spa->spa_suspend_lock, NULL, MUTEX_DEFAULT, NULL);
478 mutex_init(&spa->spa_vdev_top_lock, NULL, MUTEX_DEFAULT, NULL);
480 cv_init(&spa->spa_async_cv, NULL, CV_DEFAULT, NULL);
481 cv_init(&spa->spa_proc_cv, NULL, CV_DEFAULT, NULL);
482 cv_init(&spa->spa_scrub_io_cv, NULL, CV_DEFAULT, NULL);
483 cv_init(&spa->spa_suspend_cv, NULL, CV_DEFAULT, NULL);
485 for (t = 0; t < TXG_SIZE; t++)
486 bplist_create(&spa->spa_free_bplist[t]);
488 (void) strlcpy(spa->spa_name, name, sizeof (spa->spa_name));
489 spa->spa_state = POOL_STATE_UNINITIALIZED;
490 spa->spa_freeze_txg = UINT64_MAX;
491 spa->spa_final_txg = UINT64_MAX;
492 spa->spa_load_max_txg = UINT64_MAX;
494 spa->spa_proc_state = SPA_PROC_NONE;
496 spa->spa_deadman_synctime = zfs_deadman_synctime *
497 zfs_txg_synctime_ms * MICROSEC;
499 refcount_create(&spa->spa_refcount);
500 spa_config_lock_init(spa);
502 avl_add(&spa_namespace_avl, spa);
505 * Set the alternate root, if there is one.
508 spa->spa_root = spa_strdup(altroot);
513 * Every pool starts with the default cachefile
515 list_create(&spa->spa_config_list, sizeof (spa_config_dirent_t),
516 offsetof(spa_config_dirent_t, scd_link));
518 dp = kmem_zalloc(sizeof (spa_config_dirent_t), KM_PUSHPAGE);
519 dp->scd_path = altroot ? NULL : spa_strdup(spa_config_path);
520 list_insert_head(&spa->spa_config_list, dp);
522 VERIFY(nvlist_alloc(&spa->spa_load_info, NV_UNIQUE_NAME,
525 if (config != NULL) {
528 if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_FEATURES_FOR_READ,
530 VERIFY(nvlist_dup(features, &spa->spa_label_features,
534 VERIFY(nvlist_dup(config, &spa->spa_config, 0) == 0);
537 if (spa->spa_label_features == NULL) {
538 VERIFY(nvlist_alloc(&spa->spa_label_features, NV_UNIQUE_NAME,
546 * Removes a spa_t from the namespace, freeing up any memory used. Requires
547 * spa_namespace_lock. This is called only after the spa_t has been closed and
551 spa_remove(spa_t *spa)
553 spa_config_dirent_t *dp;
556 ASSERT(MUTEX_HELD(&spa_namespace_lock));
557 ASSERT(spa->spa_state == POOL_STATE_UNINITIALIZED);
559 nvlist_free(spa->spa_config_splitting);
561 avl_remove(&spa_namespace_avl, spa);
562 cv_broadcast(&spa_namespace_cv);
565 spa_strfree(spa->spa_root);
569 while ((dp = list_head(&spa->spa_config_list)) != NULL) {
570 list_remove(&spa->spa_config_list, dp);
571 if (dp->scd_path != NULL)
572 spa_strfree(dp->scd_path);
573 kmem_free(dp, sizeof (spa_config_dirent_t));
576 list_destroy(&spa->spa_config_list);
578 nvlist_free(spa->spa_label_features);
579 nvlist_free(spa->spa_load_info);
580 spa_config_set(spa, NULL);
582 refcount_destroy(&spa->spa_refcount);
584 spa_config_lock_destroy(spa);
586 for (t = 0; t < TXG_SIZE; t++)
587 bplist_destroy(&spa->spa_free_bplist[t]);
589 cv_destroy(&spa->spa_async_cv);
590 cv_destroy(&spa->spa_proc_cv);
591 cv_destroy(&spa->spa_scrub_io_cv);
592 cv_destroy(&spa->spa_suspend_cv);
594 mutex_destroy(&spa->spa_async_lock);
595 mutex_destroy(&spa->spa_errlist_lock);
596 mutex_destroy(&spa->spa_errlog_lock);
597 mutex_destroy(&spa->spa_history_lock);
598 mutex_destroy(&spa->spa_proc_lock);
599 mutex_destroy(&spa->spa_props_lock);
600 mutex_destroy(&spa->spa_scrub_lock);
601 mutex_destroy(&spa->spa_suspend_lock);
602 mutex_destroy(&spa->spa_vdev_top_lock);
604 kmem_free(spa, sizeof (spa_t));
608 * Given a pool, return the next pool in the namespace, or NULL if there is
609 * none. If 'prev' is NULL, return the first pool.
612 spa_next(spa_t *prev)
614 ASSERT(MUTEX_HELD(&spa_namespace_lock));
617 return (AVL_NEXT(&spa_namespace_avl, prev));
619 return (avl_first(&spa_namespace_avl));
623 * ==========================================================================
624 * SPA refcount functions
625 * ==========================================================================
629 * Add a reference to the given spa_t. Must have at least one reference, or
630 * have the namespace lock held.
633 spa_open_ref(spa_t *spa, void *tag)
635 ASSERT(refcount_count(&spa->spa_refcount) >= spa->spa_minref ||
636 MUTEX_HELD(&spa_namespace_lock));
637 (void) refcount_add(&spa->spa_refcount, tag);
641 * Remove a reference to the given spa_t. Must have at least one reference, or
642 * have the namespace lock held.
645 spa_close(spa_t *spa, void *tag)
647 ASSERT(refcount_count(&spa->spa_refcount) > spa->spa_minref ||
648 MUTEX_HELD(&spa_namespace_lock));
649 (void) refcount_remove(&spa->spa_refcount, tag);
653 * Check to see if the spa refcount is zero. Must be called with
654 * spa_namespace_lock held. We really compare against spa_minref, which is the
655 * number of references acquired when opening a pool
658 spa_refcount_zero(spa_t *spa)
660 ASSERT(MUTEX_HELD(&spa_namespace_lock));
662 return (refcount_count(&spa->spa_refcount) == spa->spa_minref);
666 * ==========================================================================
667 * SPA spare and l2cache tracking
668 * ==========================================================================
672 * Hot spares and cache devices are tracked using the same code below,
673 * for 'auxiliary' devices.
676 typedef struct spa_aux {
684 spa_aux_compare(const void *a, const void *b)
686 const spa_aux_t *sa = a;
687 const spa_aux_t *sb = b;
689 if (sa->aux_guid < sb->aux_guid)
691 else if (sa->aux_guid > sb->aux_guid)
698 spa_aux_add(vdev_t *vd, avl_tree_t *avl)
704 search.aux_guid = vd->vdev_guid;
705 if ((aux = avl_find(avl, &search, &where)) != NULL) {
708 aux = kmem_zalloc(sizeof (spa_aux_t), KM_PUSHPAGE);
709 aux->aux_guid = vd->vdev_guid;
711 avl_insert(avl, aux, where);
716 spa_aux_remove(vdev_t *vd, avl_tree_t *avl)
722 search.aux_guid = vd->vdev_guid;
723 aux = avl_find(avl, &search, &where);
727 if (--aux->aux_count == 0) {
728 avl_remove(avl, aux);
729 kmem_free(aux, sizeof (spa_aux_t));
730 } else if (aux->aux_pool == spa_guid(vd->vdev_spa)) {
731 aux->aux_pool = 0ULL;
736 spa_aux_exists(uint64_t guid, uint64_t *pool, int *refcnt, avl_tree_t *avl)
738 spa_aux_t search, *found;
740 search.aux_guid = guid;
741 found = avl_find(avl, &search, NULL);
745 *pool = found->aux_pool;
752 *refcnt = found->aux_count;
757 return (found != NULL);
761 spa_aux_activate(vdev_t *vd, avl_tree_t *avl)
763 spa_aux_t search, *found;
766 search.aux_guid = vd->vdev_guid;
767 found = avl_find(avl, &search, &where);
768 ASSERT(found != NULL);
769 ASSERT(found->aux_pool == 0ULL);
771 found->aux_pool = spa_guid(vd->vdev_spa);
775 * Spares are tracked globally due to the following constraints:
777 * - A spare may be part of multiple pools.
778 * - A spare may be added to a pool even if it's actively in use within
780 * - A spare in use in any pool can only be the source of a replacement if
781 * the target is a spare in the same pool.
783 * We keep track of all spares on the system through the use of a reference
784 * counted AVL tree. When a vdev is added as a spare, or used as a replacement
785 * spare, then we bump the reference count in the AVL tree. In addition, we set
786 * the 'vdev_isspare' member to indicate that the device is a spare (active or
787 * inactive). When a spare is made active (used to replace a device in the
788 * pool), we also keep track of which pool its been made a part of.
790 * The 'spa_spare_lock' protects the AVL tree. These functions are normally
791 * called under the spa_namespace lock as part of vdev reconfiguration. The
792 * separate spare lock exists for the status query path, which does not need to
793 * be completely consistent with respect to other vdev configuration changes.
797 spa_spare_compare(const void *a, const void *b)
799 return (spa_aux_compare(a, b));
803 spa_spare_add(vdev_t *vd)
805 mutex_enter(&spa_spare_lock);
806 ASSERT(!vd->vdev_isspare);
807 spa_aux_add(vd, &spa_spare_avl);
808 vd->vdev_isspare = B_TRUE;
809 mutex_exit(&spa_spare_lock);
813 spa_spare_remove(vdev_t *vd)
815 mutex_enter(&spa_spare_lock);
816 ASSERT(vd->vdev_isspare);
817 spa_aux_remove(vd, &spa_spare_avl);
818 vd->vdev_isspare = B_FALSE;
819 mutex_exit(&spa_spare_lock);
823 spa_spare_exists(uint64_t guid, uint64_t *pool, int *refcnt)
827 mutex_enter(&spa_spare_lock);
828 found = spa_aux_exists(guid, pool, refcnt, &spa_spare_avl);
829 mutex_exit(&spa_spare_lock);
835 spa_spare_activate(vdev_t *vd)
837 mutex_enter(&spa_spare_lock);
838 ASSERT(vd->vdev_isspare);
839 spa_aux_activate(vd, &spa_spare_avl);
840 mutex_exit(&spa_spare_lock);
844 * Level 2 ARC devices are tracked globally for the same reasons as spares.
845 * Cache devices currently only support one pool per cache device, and so
846 * for these devices the aux reference count is currently unused beyond 1.
850 spa_l2cache_compare(const void *a, const void *b)
852 return (spa_aux_compare(a, b));
856 spa_l2cache_add(vdev_t *vd)
858 mutex_enter(&spa_l2cache_lock);
859 ASSERT(!vd->vdev_isl2cache);
860 spa_aux_add(vd, &spa_l2cache_avl);
861 vd->vdev_isl2cache = B_TRUE;
862 mutex_exit(&spa_l2cache_lock);
866 spa_l2cache_remove(vdev_t *vd)
868 mutex_enter(&spa_l2cache_lock);
869 ASSERT(vd->vdev_isl2cache);
870 spa_aux_remove(vd, &spa_l2cache_avl);
871 vd->vdev_isl2cache = B_FALSE;
872 mutex_exit(&spa_l2cache_lock);
876 spa_l2cache_exists(uint64_t guid, uint64_t *pool)
880 mutex_enter(&spa_l2cache_lock);
881 found = spa_aux_exists(guid, pool, NULL, &spa_l2cache_avl);
882 mutex_exit(&spa_l2cache_lock);
888 spa_l2cache_activate(vdev_t *vd)
890 mutex_enter(&spa_l2cache_lock);
891 ASSERT(vd->vdev_isl2cache);
892 spa_aux_activate(vd, &spa_l2cache_avl);
893 mutex_exit(&spa_l2cache_lock);
897 * ==========================================================================
899 * ==========================================================================
903 * Lock the given spa_t for the purpose of adding or removing a vdev.
904 * Grabs the global spa_namespace_lock plus the spa config lock for writing.
905 * It returns the next transaction group for the spa_t.
908 spa_vdev_enter(spa_t *spa)
910 mutex_enter(&spa->spa_vdev_top_lock);
911 mutex_enter(&spa_namespace_lock);
912 return (spa_vdev_config_enter(spa));
916 * Internal implementation for spa_vdev_enter(). Used when a vdev
917 * operation requires multiple syncs (i.e. removing a device) while
918 * keeping the spa_namespace_lock held.
921 spa_vdev_config_enter(spa_t *spa)
923 ASSERT(MUTEX_HELD(&spa_namespace_lock));
925 spa_config_enter(spa, SCL_ALL, spa, RW_WRITER);
927 return (spa_last_synced_txg(spa) + 1);
931 * Used in combination with spa_vdev_config_enter() to allow the syncing
932 * of multiple transactions without releasing the spa_namespace_lock.
935 spa_vdev_config_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error, char *tag)
937 int config_changed = B_FALSE;
939 ASSERT(MUTEX_HELD(&spa_namespace_lock));
940 ASSERT(txg > spa_last_synced_txg(spa));
942 spa->spa_pending_vdev = NULL;
947 vdev_dtl_reassess(spa->spa_root_vdev, 0, 0, B_FALSE);
949 if (error == 0 && !list_is_empty(&spa->spa_config_dirty_list)) {
950 config_changed = B_TRUE;
951 spa->spa_config_generation++;
955 * Verify the metaslab classes.
957 ASSERT(metaslab_class_validate(spa_normal_class(spa)) == 0);
958 ASSERT(metaslab_class_validate(spa_log_class(spa)) == 0);
960 spa_config_exit(spa, SCL_ALL, spa);
963 * Panic the system if the specified tag requires it. This
964 * is useful for ensuring that configurations are updated
967 if (zio_injection_enabled)
968 zio_handle_panic_injection(spa, tag, 0);
971 * Note: this txg_wait_synced() is important because it ensures
972 * that there won't be more than one config change per txg.
973 * This allows us to use the txg as the generation number.
976 txg_wait_synced(spa->spa_dsl_pool, txg);
979 ASSERT(!vd->vdev_detached || vd->vdev_dtl_smo.smo_object == 0);
980 spa_config_enter(spa, SCL_ALL, spa, RW_WRITER);
982 spa_config_exit(spa, SCL_ALL, spa);
986 * If the config changed, update the config cache.
989 spa_config_sync(spa, B_FALSE, B_TRUE);
993 * Unlock the spa_t after adding or removing a vdev. Besides undoing the
994 * locking of spa_vdev_enter(), we also want make sure the transactions have
995 * synced to disk, and then update the global configuration cache with the new
999 spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error)
1001 spa_vdev_config_exit(spa, vd, txg, error, FTAG);
1002 mutex_exit(&spa_namespace_lock);
1003 mutex_exit(&spa->spa_vdev_top_lock);
1009 * Lock the given spa_t for the purpose of changing vdev state.
1012 spa_vdev_state_enter(spa_t *spa, int oplocks)
1014 int locks = SCL_STATE_ALL | oplocks;
1017 * Root pools may need to read of the underlying devfs filesystem
1018 * when opening up a vdev. Unfortunately if we're holding the
1019 * SCL_ZIO lock it will result in a deadlock when we try to issue
1020 * the read from the root filesystem. Instead we "prefetch"
1021 * the associated vnodes that we need prior to opening the
1022 * underlying devices and cache them so that we can prevent
1023 * any I/O when we are doing the actual open.
1025 if (spa_is_root(spa)) {
1026 int low = locks & ~(SCL_ZIO - 1);
1027 int high = locks & ~low;
1029 spa_config_enter(spa, high, spa, RW_WRITER);
1030 vdev_hold(spa->spa_root_vdev);
1031 spa_config_enter(spa, low, spa, RW_WRITER);
1033 spa_config_enter(spa, locks, spa, RW_WRITER);
1035 spa->spa_vdev_locks = locks;
1039 spa_vdev_state_exit(spa_t *spa, vdev_t *vd, int error)
1041 boolean_t config_changed = B_FALSE;
1043 if (vd != NULL || error == 0)
1044 vdev_dtl_reassess(vd ? vd->vdev_top : spa->spa_root_vdev,
1048 vdev_state_dirty(vd->vdev_top);
1049 config_changed = B_TRUE;
1050 spa->spa_config_generation++;
1053 if (spa_is_root(spa))
1054 vdev_rele(spa->spa_root_vdev);
1056 ASSERT3U(spa->spa_vdev_locks, >=, SCL_STATE_ALL);
1057 spa_config_exit(spa, spa->spa_vdev_locks, spa);
1060 * If anything changed, wait for it to sync. This ensures that,
1061 * from the system administrator's perspective, zpool(1M) commands
1062 * are synchronous. This is important for things like zpool offline:
1063 * when the command completes, you expect no further I/O from ZFS.
1066 txg_wait_synced(spa->spa_dsl_pool, 0);
1069 * If the config changed, update the config cache.
1071 if (config_changed) {
1072 mutex_enter(&spa_namespace_lock);
1073 spa_config_sync(spa, B_FALSE, B_TRUE);
1074 mutex_exit(&spa_namespace_lock);
1081 * ==========================================================================
1082 * Miscellaneous functions
1083 * ==========================================================================
1087 spa_activate_mos_feature(spa_t *spa, const char *feature)
1089 (void) nvlist_add_boolean(spa->spa_label_features, feature);
1090 vdev_config_dirty(spa->spa_root_vdev);
1094 spa_deactivate_mos_feature(spa_t *spa, const char *feature)
1096 (void) nvlist_remove_all(spa->spa_label_features, feature);
1097 vdev_config_dirty(spa->spa_root_vdev);
1104 spa_rename(const char *name, const char *newname)
1110 * Lookup the spa_t and grab the config lock for writing. We need to
1111 * actually open the pool so that we can sync out the necessary labels.
1112 * It's OK to call spa_open() with the namespace lock held because we
1113 * allow recursive calls for other reasons.
1115 mutex_enter(&spa_namespace_lock);
1116 if ((err = spa_open(name, &spa, FTAG)) != 0) {
1117 mutex_exit(&spa_namespace_lock);
1121 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
1123 avl_remove(&spa_namespace_avl, spa);
1124 (void) strlcpy(spa->spa_name, newname, sizeof (spa->spa_name));
1125 avl_add(&spa_namespace_avl, spa);
1128 * Sync all labels to disk with the new names by marking the root vdev
1129 * dirty and waiting for it to sync. It will pick up the new pool name
1132 vdev_config_dirty(spa->spa_root_vdev);
1134 spa_config_exit(spa, SCL_ALL, FTAG);
1136 txg_wait_synced(spa->spa_dsl_pool, 0);
1139 * Sync the updated config cache.
1141 spa_config_sync(spa, B_FALSE, B_TRUE);
1143 spa_close(spa, FTAG);
1145 mutex_exit(&spa_namespace_lock);
1151 * Return the spa_t associated with given pool_guid, if it exists. If
1152 * device_guid is non-zero, determine whether the pool exists *and* contains
1153 * a device with the specified device_guid.
1156 spa_by_guid(uint64_t pool_guid, uint64_t device_guid)
1159 avl_tree_t *t = &spa_namespace_avl;
1161 ASSERT(MUTEX_HELD(&spa_namespace_lock));
1163 for (spa = avl_first(t); spa != NULL; spa = AVL_NEXT(t, spa)) {
1164 if (spa->spa_state == POOL_STATE_UNINITIALIZED)
1166 if (spa->spa_root_vdev == NULL)
1168 if (spa_guid(spa) == pool_guid) {
1169 if (device_guid == 0)
1172 if (vdev_lookup_by_guid(spa->spa_root_vdev,
1173 device_guid) != NULL)
1177 * Check any devices we may be in the process of adding.
1179 if (spa->spa_pending_vdev) {
1180 if (vdev_lookup_by_guid(spa->spa_pending_vdev,
1181 device_guid) != NULL)
1191 * Determine whether a pool with the given pool_guid exists.
1194 spa_guid_exists(uint64_t pool_guid, uint64_t device_guid)
1196 return (spa_by_guid(pool_guid, device_guid) != NULL);
1200 spa_strdup(const char *s)
1206 new = kmem_alloc(len + 1, KM_PUSHPAGE);
1214 spa_strfree(char *s)
1216 kmem_free(s, strlen(s) + 1);
1220 spa_get_random(uint64_t range)
1226 (void) random_get_pseudo_bytes((void *)&r, sizeof (uint64_t));
1232 spa_generate_guid(spa_t *spa)
1234 uint64_t guid = spa_get_random(-1ULL);
1237 while (guid == 0 || spa_guid_exists(spa_guid(spa), guid))
1238 guid = spa_get_random(-1ULL);
1240 while (guid == 0 || spa_guid_exists(guid, 0))
1241 guid = spa_get_random(-1ULL);
1248 sprintf_blkptr(char *buf, const blkptr_t *bp)
1251 char *checksum = NULL;
1252 char *compress = NULL;
1255 if (BP_GET_TYPE(bp) & DMU_OT_NEWTYPE) {
1256 dmu_object_byteswap_t bswap =
1257 DMU_OT_BYTESWAP(BP_GET_TYPE(bp));
1258 (void) snprintf(type, sizeof (type), "bswap %s %s",
1259 DMU_OT_IS_METADATA(BP_GET_TYPE(bp)) ?
1260 "metadata" : "data",
1261 dmu_ot_byteswap[bswap].ob_name);
1263 (void) strlcpy(type, dmu_ot[BP_GET_TYPE(bp)].ot_name,
1266 checksum = zio_checksum_table[BP_GET_CHECKSUM(bp)].ci_name;
1267 compress = zio_compress_table[BP_GET_COMPRESS(bp)].ci_name;
1270 SPRINTF_BLKPTR(snprintf, ' ', buf, bp, type, checksum, compress);
1274 spa_freeze(spa_t *spa)
1276 uint64_t freeze_txg = 0;
1278 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
1279 if (spa->spa_freeze_txg == UINT64_MAX) {
1280 freeze_txg = spa_last_synced_txg(spa) + TXG_SIZE;
1281 spa->spa_freeze_txg = freeze_txg;
1283 spa_config_exit(spa, SCL_ALL, FTAG);
1284 if (freeze_txg != 0)
1285 txg_wait_synced(spa_get_dsl(spa), freeze_txg);
1289 * This is a stripped-down version of strtoull, suitable only for converting
1290 * lowercase hexidecimal numbers that don't overflow.
1293 strtonum(const char *str, char **nptr)
1299 while ((c = *str) != '\0') {
1300 if (c >= '0' && c <= '9')
1302 else if (c >= 'a' && c <= 'f')
1303 digit = 10 + c - 'a';
1314 *nptr = (char *)str;
1320 * ==========================================================================
1321 * Accessor functions
1322 * ==========================================================================
1326 spa_shutting_down(spa_t *spa)
1328 return (spa->spa_async_suspended);
1332 spa_get_dsl(spa_t *spa)
1334 return (spa->spa_dsl_pool);
1338 spa_is_initializing(spa_t *spa)
1340 return (spa->spa_is_initializing);
1344 spa_get_rootblkptr(spa_t *spa)
1346 return (&spa->spa_ubsync.ub_rootbp);
1350 spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp)
1352 spa->spa_uberblock.ub_rootbp = *bp;
1356 spa_altroot(spa_t *spa, char *buf, size_t buflen)
1358 if (spa->spa_root == NULL)
1361 (void) strncpy(buf, spa->spa_root, buflen);
1365 spa_sync_pass(spa_t *spa)
1367 return (spa->spa_sync_pass);
1371 spa_name(spa_t *spa)
1373 return (spa->spa_name);
1377 spa_guid(spa_t *spa)
1379 dsl_pool_t *dp = spa_get_dsl(spa);
1383 * If we fail to parse the config during spa_load(), we can go through
1384 * the error path (which posts an ereport) and end up here with no root
1385 * vdev. We stash the original pool guid in 'spa_config_guid' to handle
1388 if (spa->spa_root_vdev == NULL)
1389 return (spa->spa_config_guid);
1391 guid = spa->spa_last_synced_guid != 0 ?
1392 spa->spa_last_synced_guid : spa->spa_root_vdev->vdev_guid;
1395 * Return the most recently synced out guid unless we're
1396 * in syncing context.
1398 if (dp && dsl_pool_sync_context(dp))
1399 return (spa->spa_root_vdev->vdev_guid);
1405 spa_load_guid(spa_t *spa)
1408 * This is a GUID that exists solely as a reference for the
1409 * purposes of the arc. It is generated at load time, and
1410 * is never written to persistent storage.
1412 return (spa->spa_load_guid);
1416 spa_last_synced_txg(spa_t *spa)
1418 return (spa->spa_ubsync.ub_txg);
1422 spa_first_txg(spa_t *spa)
1424 return (spa->spa_first_txg);
1428 spa_syncing_txg(spa_t *spa)
1430 return (spa->spa_syncing_txg);
1434 spa_state(spa_t *spa)
1436 return (spa->spa_state);
1440 spa_load_state(spa_t *spa)
1442 return (spa->spa_load_state);
1446 spa_freeze_txg(spa_t *spa)
1448 return (spa->spa_freeze_txg);
1453 spa_get_asize(spa_t *spa, uint64_t lsize)
1456 * The worst case is single-sector max-parity RAID-Z blocks, in which
1457 * case the space requirement is exactly (VDEV_RAIDZ_MAXPARITY + 1)
1458 * times the size; so just assume that. Add to this the fact that
1459 * we can have up to 3 DVAs per bp, and one more factor of 2 because
1460 * the block may be dittoed with up to 3 DVAs by ddt_sync().
1462 return (lsize * (VDEV_RAIDZ_MAXPARITY + 1) * SPA_DVAS_PER_BP * 2);
1466 spa_get_dspace(spa_t *spa)
1468 return (spa->spa_dspace);
1472 spa_update_dspace(spa_t *spa)
1474 spa->spa_dspace = metaslab_class_get_dspace(spa_normal_class(spa)) +
1475 ddt_get_dedup_dspace(spa);
1479 * Return the failure mode that has been set to this pool. The default
1480 * behavior will be to block all I/Os when a complete failure occurs.
1483 spa_get_failmode(spa_t *spa)
1485 return (spa->spa_failmode);
1489 spa_suspended(spa_t *spa)
1491 return (spa->spa_suspended);
1495 spa_version(spa_t *spa)
1497 return (spa->spa_ubsync.ub_version);
1501 spa_deflate(spa_t *spa)
1503 return (spa->spa_deflate);
1507 spa_normal_class(spa_t *spa)
1509 return (spa->spa_normal_class);
1513 spa_log_class(spa_t *spa)
1515 return (spa->spa_log_class);
1519 spa_max_replication(spa_t *spa)
1522 * As of SPA_VERSION == SPA_VERSION_DITTO_BLOCKS, we are able to
1523 * handle BPs with more than one DVA allocated. Set our max
1524 * replication level accordingly.
1526 if (spa_version(spa) < SPA_VERSION_DITTO_BLOCKS)
1528 return (MIN(SPA_DVAS_PER_BP, spa_max_replication_override));
1532 spa_prev_software_version(spa_t *spa)
1534 return (spa->spa_prev_software_version);
1538 spa_deadman_synctime(spa_t *spa)
1540 return (spa->spa_deadman_synctime);
1544 dva_get_dsize_sync(spa_t *spa, const dva_t *dva)
1546 uint64_t asize = DVA_GET_ASIZE(dva);
1547 uint64_t dsize = asize;
1549 ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
1551 if (asize != 0 && spa->spa_deflate) {
1552 vdev_t *vd = vdev_lookup_top(spa, DVA_GET_VDEV(dva));
1553 dsize = (asize >> SPA_MINBLOCKSHIFT) * vd->vdev_deflate_ratio;
1560 bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp)
1565 for (d = 0; d < SPA_DVAS_PER_BP; d++)
1566 dsize += dva_get_dsize_sync(spa, &bp->blk_dva[d]);
1572 bp_get_dsize(spa_t *spa, const blkptr_t *bp)
1577 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
1579 for (d = 0; d < SPA_DVAS_PER_BP; d++)
1580 dsize += dva_get_dsize_sync(spa, &bp->blk_dva[d]);
1582 spa_config_exit(spa, SCL_VDEV, FTAG);
1588 * ==========================================================================
1589 * Initialization and Termination
1590 * ==========================================================================
1594 spa_name_compare(const void *a1, const void *a2)
1596 const spa_t *s1 = a1;
1597 const spa_t *s2 = a2;
1600 s = strcmp(s1->spa_name, s2->spa_name);
1617 mutex_init(&spa_namespace_lock, NULL, MUTEX_DEFAULT, NULL);
1618 mutex_init(&spa_spare_lock, NULL, MUTEX_DEFAULT, NULL);
1619 mutex_init(&spa_l2cache_lock, NULL, MUTEX_DEFAULT, NULL);
1620 cv_init(&spa_namespace_cv, NULL, CV_DEFAULT, NULL);
1622 avl_create(&spa_namespace_avl, spa_name_compare, sizeof (spa_t),
1623 offsetof(spa_t, spa_avl));
1625 avl_create(&spa_spare_avl, spa_spare_compare, sizeof (spa_aux_t),
1626 offsetof(spa_aux_t, aux_avl));
1628 avl_create(&spa_l2cache_avl, spa_l2cache_compare, sizeof (spa_aux_t),
1629 offsetof(spa_aux_t, aux_avl));
1631 spa_mode_global = mode;
1639 vdev_cache_stat_init();
1642 zpool_feature_init();
1654 vdev_cache_stat_fini();
1662 avl_destroy(&spa_namespace_avl);
1663 avl_destroy(&spa_spare_avl);
1664 avl_destroy(&spa_l2cache_avl);
1666 cv_destroy(&spa_namespace_cv);
1667 mutex_destroy(&spa_namespace_lock);
1668 mutex_destroy(&spa_spare_lock);
1669 mutex_destroy(&spa_l2cache_lock);
1673 * Return whether this pool has slogs. No locking needed.
1674 * It's not a problem if the wrong answer is returned as it's only for
1675 * performance and not correctness
1678 spa_has_slogs(spa_t *spa)
1680 return (spa->spa_log_class->mc_rotor != NULL);
1684 spa_get_log_state(spa_t *spa)
1686 return (spa->spa_log_state);
1690 spa_set_log_state(spa_t *spa, spa_log_state_t state)
1692 spa->spa_log_state = state;
1696 spa_is_root(spa_t *spa)
1698 return (spa->spa_is_root);
1702 spa_writeable(spa_t *spa)
1704 return (!!(spa->spa_mode & FWRITE));
1708 spa_mode(spa_t *spa)
1710 return (spa->spa_mode);
1714 spa_bootfs(spa_t *spa)
1716 return (spa->spa_bootfs);
1720 spa_delegation(spa_t *spa)
1722 return (spa->spa_delegation);
1726 spa_meta_objset(spa_t *spa)
1728 return (spa->spa_meta_objset);
1732 spa_dedup_checksum(spa_t *spa)
1734 return (spa->spa_dedup_checksum);
1738 * Reset pool scan stat per scan pass (or reboot).
1741 spa_scan_stat_init(spa_t *spa)
1743 /* data not stored on disk */
1744 spa->spa_scan_pass_start = gethrestime_sec();
1745 spa->spa_scan_pass_exam = 0;
1746 vdev_scan_stat_init(spa->spa_root_vdev);
1750 * Get scan stats for zpool status reports
1753 spa_scan_get_stats(spa_t *spa, pool_scan_stat_t *ps)
1755 dsl_scan_t *scn = spa->spa_dsl_pool ? spa->spa_dsl_pool->dp_scan : NULL;
1757 if (scn == NULL || scn->scn_phys.scn_func == POOL_SCAN_NONE)
1759 bzero(ps, sizeof (pool_scan_stat_t));
1761 /* data stored on disk */
1762 ps->pss_func = scn->scn_phys.scn_func;
1763 ps->pss_start_time = scn->scn_phys.scn_start_time;
1764 ps->pss_end_time = scn->scn_phys.scn_end_time;
1765 ps->pss_to_examine = scn->scn_phys.scn_to_examine;
1766 ps->pss_examined = scn->scn_phys.scn_examined;
1767 ps->pss_to_process = scn->scn_phys.scn_to_process;
1768 ps->pss_processed = scn->scn_phys.scn_processed;
1769 ps->pss_errors = scn->scn_phys.scn_errors;
1770 ps->pss_state = scn->scn_phys.scn_state;
1772 /* data not stored on disk */
1773 ps->pss_pass_start = spa->spa_scan_pass_start;
1774 ps->pss_pass_exam = spa->spa_scan_pass_exam;
1780 spa_debug_enabled(spa_t *spa)
1782 return (spa->spa_debug);
1785 #if defined(_KERNEL) && defined(HAVE_SPL)
1786 /* Namespace manipulation */
1787 EXPORT_SYMBOL(spa_lookup);
1788 EXPORT_SYMBOL(spa_add);
1789 EXPORT_SYMBOL(spa_remove);
1790 EXPORT_SYMBOL(spa_next);
1792 /* Refcount functions */
1793 EXPORT_SYMBOL(spa_open_ref);
1794 EXPORT_SYMBOL(spa_close);
1795 EXPORT_SYMBOL(spa_refcount_zero);
1797 /* Pool configuration lock */
1798 EXPORT_SYMBOL(spa_config_tryenter);
1799 EXPORT_SYMBOL(spa_config_enter);
1800 EXPORT_SYMBOL(spa_config_exit);
1801 EXPORT_SYMBOL(spa_config_held);
1803 /* Pool vdev add/remove lock */
1804 EXPORT_SYMBOL(spa_vdev_enter);
1805 EXPORT_SYMBOL(spa_vdev_exit);
1807 /* Pool vdev state change lock */
1808 EXPORT_SYMBOL(spa_vdev_state_enter);
1809 EXPORT_SYMBOL(spa_vdev_state_exit);
1811 /* Accessor functions */
1812 EXPORT_SYMBOL(spa_shutting_down);
1813 EXPORT_SYMBOL(spa_get_dsl);
1814 EXPORT_SYMBOL(spa_get_rootblkptr);
1815 EXPORT_SYMBOL(spa_set_rootblkptr);
1816 EXPORT_SYMBOL(spa_altroot);
1817 EXPORT_SYMBOL(spa_sync_pass);
1818 EXPORT_SYMBOL(spa_name);
1819 EXPORT_SYMBOL(spa_guid);
1820 EXPORT_SYMBOL(spa_last_synced_txg);
1821 EXPORT_SYMBOL(spa_first_txg);
1822 EXPORT_SYMBOL(spa_syncing_txg);
1823 EXPORT_SYMBOL(spa_version);
1824 EXPORT_SYMBOL(spa_state);
1825 EXPORT_SYMBOL(spa_load_state);
1826 EXPORT_SYMBOL(spa_freeze_txg);
1827 EXPORT_SYMBOL(spa_get_asize);
1828 EXPORT_SYMBOL(spa_get_dspace);
1829 EXPORT_SYMBOL(spa_update_dspace);
1830 EXPORT_SYMBOL(spa_deflate);
1831 EXPORT_SYMBOL(spa_normal_class);
1832 EXPORT_SYMBOL(spa_log_class);
1833 EXPORT_SYMBOL(spa_max_replication);
1834 EXPORT_SYMBOL(spa_prev_software_version);
1835 EXPORT_SYMBOL(spa_get_failmode);
1836 EXPORT_SYMBOL(spa_suspended);
1837 EXPORT_SYMBOL(spa_bootfs);
1838 EXPORT_SYMBOL(spa_delegation);
1839 EXPORT_SYMBOL(spa_meta_objset);
1841 /* Miscellaneous support routines */
1842 EXPORT_SYMBOL(spa_rename);
1843 EXPORT_SYMBOL(spa_guid_exists);
1844 EXPORT_SYMBOL(spa_strdup);
1845 EXPORT_SYMBOL(spa_strfree);
1846 EXPORT_SYMBOL(spa_get_random);
1847 EXPORT_SYMBOL(spa_generate_guid);
1848 EXPORT_SYMBOL(sprintf_blkptr);
1849 EXPORT_SYMBOL(spa_freeze);
1850 EXPORT_SYMBOL(spa_upgrade);
1851 EXPORT_SYMBOL(spa_evict_all);
1852 EXPORT_SYMBOL(spa_lookup_by_guid);
1853 EXPORT_SYMBOL(spa_has_spare);
1854 EXPORT_SYMBOL(dva_get_dsize_sync);
1855 EXPORT_SYMBOL(bp_get_dsize_sync);
1856 EXPORT_SYMBOL(bp_get_dsize);
1857 EXPORT_SYMBOL(spa_has_slogs);
1858 EXPORT_SYMBOL(spa_is_root);
1859 EXPORT_SYMBOL(spa_writeable);
1860 EXPORT_SYMBOL(spa_mode);
1862 EXPORT_SYMBOL(spa_namespace_lock);
1864 module_param(zfs_deadman_synctime, ulong, 0644);
1865 MODULE_PARM_DESC(zfs_deadman_synctime,"Expire in units of zfs_txg_synctime_ms");
1867 module_param(zfs_deadman_enabled, int, 0644);
1868 MODULE_PARM_DESC(zfs_deadman_enabled, "Enable deadman timer");