author | maybee |
Sun, 26 Aug 2007 11:19:04 -0700 | |
changeset 4944 | 96d96f8de974 |
parent 4831 | 41ec732c6d9f |
child 5094 | 71a3e95fb9e2 |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1544 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
789 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
/* |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
22 |
* Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
#pragma ident "%Z%%M% %I% %E% SMI" |
|
27 |
||
28 |
#include <sys/zfs_context.h> |
|
29 |
#include <sys/spa_impl.h> |
|
30 |
#include <sys/zio.h> |
|
31 |
#include <sys/zio_checksum.h> |
|
32 |
#include <sys/zio_compress.h> |
|
33 |
#include <sys/dmu.h> |
|
34 |
#include <sys/dmu_tx.h> |
|
35 |
#include <sys/zap.h> |
|
36 |
#include <sys/zil.h> |
|
37 |
#include <sys/vdev_impl.h> |
|
38 |
#include <sys/metaslab.h> |
|
39 |
#include <sys/uberblock_impl.h> |
|
40 |
#include <sys/txg.h> |
|
41 |
#include <sys/avl.h> |
|
42 |
#include <sys/unique.h> |
|
43 |
#include <sys/dsl_pool.h> |
|
44 |
#include <sys/dsl_dir.h> |
|
45 |
#include <sys/dsl_prop.h> |
|
46 |
#include <sys/fs/zfs.h> |
|
4620 | 47 |
#include <sys/metaslab_impl.h> |
4787 | 48 |
#include "zfs_prop.h" |
789 | 49 |
|
50 |
/* |
|
51 |
* SPA locking |
|
52 |
* |
|
53 |
* There are four basic locks for managing spa_t structures: |
|
54 |
* |
|
55 |
* spa_namespace_lock (global mutex) |
|
56 |
* |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
57 |
* This lock must be acquired to do any of the following: |
789 | 58 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
59 |
* - Lookup a spa_t by name |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
60 |
* - Add or remove a spa_t from the namespace |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
61 |
* - Increase spa_refcount from non-zero |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
62 |
* - Check if spa_refcount is zero |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
63 |
* - Rename a spa_t |
1544 | 64 |
* - add/remove/attach/detach devices |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
65 |
* - Held for the duration of create/destroy/import/export |
789 | 66 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
67 |
* It does not need to handle recursion. A create or destroy may |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
68 |
* reference objects (files or zvols) in other pools, but by |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
69 |
* definition they must have an existing reference, and will never need |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
70 |
* to lookup a spa_t by name. |
789 | 71 |
* |
72 |
* spa_refcount (per-spa refcount_t protected by mutex) |
|
73 |
* |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
74 |
* This reference count keep track of any active users of the spa_t. The |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
75 |
* spa_t cannot be destroyed or freed while this is non-zero. Internally, |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
76 |
* the refcount is never really 'zero' - opening a pool implicitly keeps |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
77 |
* some references in the DMU. Internally we check against SPA_MINREF, but |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
78 |
* present the image of a zero/non-zero value to consumers. |
789 | 79 |
* |
4787 | 80 |
* spa_config_lock (per-spa read-priority rwlock) |
789 | 81 |
* |
4787 | 82 |
* This protects the spa_t from config changes, and must be held in |
83 |
* the following circumstances: |
|
789 | 84 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
85 |
* - RW_READER to perform I/O to the spa |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
86 |
* - RW_WRITER to change the vdev config |
789 | 87 |
* |
88 |
* spa_config_cache_lock (per-spa mutex) |
|
89 |
* |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
90 |
* This mutex prevents the spa_config nvlist from being updated. No |
789 | 91 |
* other locks are required to obtain this lock, although implicitly you |
92 |
* must have the namespace lock or non-zero refcount to have any kind |
|
93 |
* of spa_t pointer at all. |
|
94 |
* |
|
95 |
* The locking order is fairly straightforward: |
|
96 |
* |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
97 |
* spa_namespace_lock -> spa_refcount |
789 | 98 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
99 |
* The namespace lock must be acquired to increase the refcount from 0 |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
100 |
* or to check if it is zero. |
789 | 101 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
102 |
* spa_refcount -> spa_config_lock |
789 | 103 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
104 |
* There must be at least one valid reference on the spa_t to acquire |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
105 |
* the config lock. |
789 | 106 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
107 |
* spa_namespace_lock -> spa_config_lock |
789 | 108 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
109 |
* The namespace lock must always be taken before the config lock. |
789 | 110 |
* |
111 |
* |
|
112 |
* The spa_namespace_lock and spa_config_cache_lock can be acquired directly and |
|
113 |
* are globally visible. |
|
114 |
* |
|
115 |
* The namespace is manipulated using the following functions, all which require |
|
116 |
* the spa_namespace_lock to be held. |
|
117 |
* |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
118 |
* spa_lookup() Lookup a spa_t by name. |
789 | 119 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
120 |
* spa_add() Create a new spa_t in the namespace. |
789 | 121 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
122 |
* spa_remove() Remove a spa_t from the namespace. This also |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
123 |
* frees up any memory associated with the spa_t. |
789 | 124 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
125 |
* spa_next() Returns the next spa_t in the system, or the |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
126 |
* first if NULL is passed. |
789 | 127 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
128 |
* spa_evict_all() Shutdown and remove all spa_t structures in |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
129 |
* the system. |
789 | 130 |
* |
1544 | 131 |
* spa_guid_exists() Determine whether a pool/device guid exists. |
789 | 132 |
* |
133 |
* The spa_refcount is manipulated using the following functions: |
|
134 |
* |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
135 |
* spa_open_ref() Adds a reference to the given spa_t. Must be |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
136 |
* called with spa_namespace_lock held if the |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
137 |
* refcount is currently zero. |
789 | 138 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
139 |
* spa_close() Remove a reference from the spa_t. This will |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
140 |
* not free the spa_t or remove it from the |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
141 |
* namespace. No locking is required. |
789 | 142 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
143 |
* spa_refcount_zero() Returns true if the refcount is currently |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
144 |
* zero. Must be called with spa_namespace_lock |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
145 |
* held. |
789 | 146 |
* |
147 |
* The spa_config_lock is manipulated using the following functions: |
|
148 |
* |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
149 |
* spa_config_enter() Acquire the config lock as RW_READER or |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
150 |
* RW_WRITER. At least one reference on the spa_t |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
151 |
* must exist. |
789 | 152 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
153 |
* spa_config_exit() Release the config lock. |
789 | 154 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
155 |
* spa_config_held() Returns true if the config lock is currently |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
156 |
* held in the given state. |
789 | 157 |
* |
1544 | 158 |
* The vdev configuration is protected by spa_vdev_enter() / spa_vdev_exit(). |
789 | 159 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
160 |
* spa_vdev_enter() Acquire the namespace lock and the config lock |
1544 | 161 |
* for writing. |
789 | 162 |
* |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
163 |
* spa_vdev_exit() Release the config lock, wait for all I/O |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
164 |
* to complete, sync the updated configs to the |
1544 | 165 |
* cache, and release the namespace lock. |
789 | 166 |
* |
167 |
* The spa_name() function also requires either the spa_namespace_lock |
|
168 |
* or the spa_config_lock, as both are needed to do a rename. spa_rename() is |
|
169 |
* also implemented within this file since is requires manipulation of the |
|
170 |
* namespace. |
|
171 |
*/ |
|
172 |
||
173 |
static avl_tree_t spa_namespace_avl; |
|
174 |
kmutex_t spa_namespace_lock; |
|
175 |
static kcondvar_t spa_namespace_cv; |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
176 |
static int spa_active_count; |
2986 | 177 |
int spa_max_replication_override = SPA_DVAS_PER_BP; |
789 | 178 |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
179 |
static kmutex_t spa_spare_lock; |
2082 | 180 |
static avl_tree_t spa_spare_avl; |
181 |
||
789 | 182 |
kmem_cache_t *spa_buffer_pool; |
183 |
int spa_mode; |
|
184 |
||
185 |
#ifdef ZFS_DEBUG |
|
4603
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
186 |
/* Everything except dprintf is on by default in debug builds */ |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
187 |
int zfs_flags = ~ZFS_DEBUG_DPRINTF; |
789 | 188 |
#else |
189 |
int zfs_flags = 0; |
|
190 |
#endif |
|
191 |
||
3713 | 192 |
/* |
193 |
* zfs_recover can be set to nonzero to attempt to recover from |
|
194 |
* otherwise-fatal errors, typically caused by on-disk corruption. When |
|
195 |
* set, calls to zfs_panic_recover() will turn into warning messages. |
|
196 |
*/ |
|
197 |
int zfs_recover = 0; |
|
198 |
||
789 | 199 |
#define SPA_MINREF 5 /* spa_refcnt for an open-but-idle pool */ |
200 |
||
201 |
/* |
|
202 |
* ========================================================================== |
|
203 |
* SPA namespace functions |
|
204 |
* ========================================================================== |
|
205 |
*/ |
|
206 |
||
207 |
/* |
|
208 |
* Lookup the named spa_t in the AVL tree. The spa_namespace_lock must be held. |
|
209 |
* Returns NULL if no matching spa_t is found. |
|
210 |
*/ |
|
211 |
spa_t * |
|
212 |
spa_lookup(const char *name) |
|
213 |
{ |
|
214 |
spa_t search, *spa; |
|
215 |
avl_index_t where; |
|
4603
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
216 |
char c; |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
217 |
char *cp; |
789 | 218 |
|
219 |
ASSERT(MUTEX_HELD(&spa_namespace_lock)); |
|
220 |
||
4603
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
221 |
/* |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
222 |
* If it's a full dataset name, figure out the pool name and |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
223 |
* just use that. |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
224 |
*/ |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
225 |
cp = strpbrk(name, "/@"); |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
226 |
if (cp) { |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
227 |
c = *cp; |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
228 |
*cp = '\0'; |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
229 |
} |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
230 |
|
789 | 231 |
search.spa_name = (char *)name; |
232 |
spa = avl_find(&spa_namespace_avl, &search, &where); |
|
233 |
||
4603
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
234 |
if (cp) |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
235 |
*cp = c; |
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
236 |
|
789 | 237 |
return (spa); |
238 |
} |
|
239 |
||
240 |
/* |
|
241 |
* Create an uninitialized spa_t with the given name. Requires |
|
242 |
* spa_namespace_lock. The caller must ensure that the spa_t doesn't already |
|
243 |
* exist by calling spa_lookup() first. |
|
244 |
*/ |
|
245 |
spa_t * |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
246 |
spa_add(const char *name, const char *altroot) |
789 | 247 |
{ |
248 |
spa_t *spa; |
|
249 |
||
250 |
ASSERT(MUTEX_HELD(&spa_namespace_lock)); |
|
251 |
||
252 |
spa = kmem_zalloc(sizeof (spa_t), KM_SLEEP); |
|
253 |
||
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
254 |
rw_init(&spa->spa_traverse_lock, NULL, RW_DEFAULT, NULL); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
255 |
|
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
256 |
mutex_init(&spa->spa_uberblock_lock, NULL, MUTEX_DEFAULT, NULL); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
257 |
mutex_init(&spa->spa_async_lock, NULL, MUTEX_DEFAULT, NULL); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
258 |
mutex_init(&spa->spa_config_cache_lock, NULL, MUTEX_DEFAULT, NULL); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
259 |
mutex_init(&spa->spa_scrub_lock, NULL, MUTEX_DEFAULT, NULL); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
260 |
mutex_init(&spa->spa_errlog_lock, NULL, MUTEX_DEFAULT, NULL); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
261 |
mutex_init(&spa->spa_errlist_lock, NULL, MUTEX_DEFAULT, NULL); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
262 |
mutex_init(&spa->spa_sync_bplist.bpl_lock, NULL, MUTEX_DEFAULT, NULL); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
263 |
mutex_init(&spa->spa_history_lock, NULL, MUTEX_DEFAULT, NULL); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
264 |
mutex_init(&spa->spa_props_lock, NULL, MUTEX_DEFAULT, NULL); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
265 |
|
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
266 |
cv_init(&spa->spa_async_cv, NULL, CV_DEFAULT, NULL); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
267 |
cv_init(&spa->spa_scrub_cv, NULL, CV_DEFAULT, NULL); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
268 |
cv_init(&spa->spa_scrub_io_cv, NULL, CV_DEFAULT, NULL); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
269 |
|
789 | 270 |
spa->spa_name = spa_strdup(name); |
271 |
spa->spa_state = POOL_STATE_UNINITIALIZED; |
|
272 |
spa->spa_freeze_txg = UINT64_MAX; |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
273 |
spa->spa_final_txg = UINT64_MAX; |
789 | 274 |
|
275 |
refcount_create(&spa->spa_refcount); |
|
4787 | 276 |
rprw_init(&spa->spa_config_lock); |
789 | 277 |
|
278 |
avl_add(&spa_namespace_avl, spa); |
|
279 |
||
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
280 |
/* |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
281 |
* Set the alternate root, if there is one. |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
282 |
*/ |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
283 |
if (altroot) { |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
284 |
spa->spa_root = spa_strdup(altroot); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
285 |
spa_active_count++; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
286 |
} |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
287 |
|
789 | 288 |
return (spa); |
289 |
} |
|
290 |
||
291 |
/* |
|
292 |
* Removes a spa_t from the namespace, freeing up any memory used. Requires |
|
293 |
* spa_namespace_lock. This is called only after the spa_t has been closed and |
|
294 |
* deactivated. |
|
295 |
*/ |
|
296 |
void |
|
297 |
spa_remove(spa_t *spa) |
|
298 |
{ |
|
299 |
ASSERT(MUTEX_HELD(&spa_namespace_lock)); |
|
300 |
ASSERT(spa->spa_state == POOL_STATE_UNINITIALIZED); |
|
301 |
ASSERT(spa->spa_scrub_thread == NULL); |
|
302 |
||
303 |
avl_remove(&spa_namespace_avl, spa); |
|
304 |
cv_broadcast(&spa_namespace_cv); |
|
305 |
||
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
306 |
if (spa->spa_root) { |
789 | 307 |
spa_strfree(spa->spa_root); |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
308 |
spa_active_count--; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
309 |
} |
789 | 310 |
|
311 |
if (spa->spa_name) |
|
312 |
spa_strfree(spa->spa_name); |
|
313 |
||
314 |
spa_config_set(spa, NULL); |
|
315 |
||
316 |
refcount_destroy(&spa->spa_refcount); |
|
4787 | 317 |
|
318 |
rprw_destroy(&spa->spa_config_lock); |
|
789 | 319 |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
320 |
rw_destroy(&spa->spa_traverse_lock); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
321 |
|
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
322 |
cv_destroy(&spa->spa_async_cv); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
323 |
cv_destroy(&spa->spa_scrub_cv); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
324 |
cv_destroy(&spa->spa_scrub_io_cv); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
325 |
|
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
326 |
mutex_destroy(&spa->spa_uberblock_lock); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
327 |
mutex_destroy(&spa->spa_async_lock); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
328 |
mutex_destroy(&spa->spa_config_cache_lock); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
329 |
mutex_destroy(&spa->spa_scrub_lock); |
2856 | 330 |
mutex_destroy(&spa->spa_errlog_lock); |
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
331 |
mutex_destroy(&spa->spa_errlist_lock); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
332 |
mutex_destroy(&spa->spa_sync_bplist.bpl_lock); |
2926 | 333 |
mutex_destroy(&spa->spa_history_lock); |
3912 | 334 |
mutex_destroy(&spa->spa_props_lock); |
2856 | 335 |
|
789 | 336 |
kmem_free(spa, sizeof (spa_t)); |
337 |
} |
|
338 |
||
339 |
/* |
|
340 |
* Given a pool, return the next pool in the namespace, or NULL if there is |
|
341 |
* none. If 'prev' is NULL, return the first pool. |
|
342 |
*/ |
|
343 |
spa_t * |
|
344 |
spa_next(spa_t *prev) |
|
345 |
{ |
|
346 |
ASSERT(MUTEX_HELD(&spa_namespace_lock)); |
|
347 |
||
348 |
if (prev) |
|
349 |
return (AVL_NEXT(&spa_namespace_avl, prev)); |
|
350 |
else |
|
351 |
return (avl_first(&spa_namespace_avl)); |
|
352 |
} |
|
353 |
||
354 |
/* |
|
355 |
* ========================================================================== |
|
356 |
* SPA refcount functions |
|
357 |
* ========================================================================== |
|
358 |
*/ |
|
359 |
||
360 |
/* |
|
361 |
* Add a reference to the given spa_t. Must have at least one reference, or |
|
362 |
* have the namespace lock held. |
|
363 |
*/ |
|
364 |
void |
|
365 |
spa_open_ref(spa_t *spa, void *tag) |
|
366 |
{ |
|
367 |
ASSERT(refcount_count(&spa->spa_refcount) > SPA_MINREF || |
|
368 |
MUTEX_HELD(&spa_namespace_lock)); |
|
369 |
||
370 |
(void) refcount_add(&spa->spa_refcount, tag); |
|
371 |
} |
|
372 |
||
373 |
/* |
|
374 |
* Remove a reference to the given spa_t. Must have at least one reference, or |
|
375 |
* have the namespace lock held. |
|
376 |
*/ |
|
377 |
void |
|
378 |
spa_close(spa_t *spa, void *tag) |
|
379 |
{ |
|
380 |
ASSERT(refcount_count(&spa->spa_refcount) > SPA_MINREF || |
|
381 |
MUTEX_HELD(&spa_namespace_lock)); |
|
382 |
||
383 |
(void) refcount_remove(&spa->spa_refcount, tag); |
|
384 |
} |
|
385 |
||
386 |
/* |
|
387 |
* Check to see if the spa refcount is zero. Must be called with |
|
388 |
* spa_namespace_lock held. We really compare against SPA_MINREF, which is the |
|
389 |
* number of references acquired when opening a pool |
|
390 |
*/ |
|
391 |
boolean_t |
|
392 |
spa_refcount_zero(spa_t *spa) |
|
393 |
{ |
|
394 |
ASSERT(MUTEX_HELD(&spa_namespace_lock)); |
|
395 |
||
396 |
return (refcount_count(&spa->spa_refcount) == SPA_MINREF); |
|
397 |
} |
|
398 |
||
399 |
/* |
|
400 |
* ========================================================================== |
|
2082 | 401 |
* SPA spare tracking |
402 |
* ========================================================================== |
|
403 |
*/ |
|
404 |
||
405 |
/* |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
406 |
* Spares are tracked globally due to the following constraints: |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
407 |
* |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
408 |
* - A spare may be part of multiple pools. |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
409 |
* - A spare may be added to a pool even if it's actively in use within |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
410 |
* another pool. |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
411 |
* - A spare in use in any pool can only be the source of a replacement if |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
412 |
* the target is a spare in the same pool. |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
413 |
* |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
414 |
* We keep track of all spares on the system through the use of a reference |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
415 |
* counted AVL tree. When a vdev is added as a spare, or used as a replacement |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
416 |
* spare, then we bump the reference count in the AVL tree. In addition, we set |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
417 |
* the 'vdev_isspare' member to indicate that the device is a spare (active or |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
418 |
* inactive). When a spare is made active (used to replace a device in the |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
419 |
* pool), we also keep track of which pool its been made a part of. |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
420 |
* |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
421 |
* The 'spa_spare_lock' protects the AVL tree. These functions are normally |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
422 |
* called under the spa_namespace lock as part of vdev reconfiguration. The |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
423 |
* separate spare lock exists for the status query path, which does not need to |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
424 |
* be completely consistent with respect to other vdev configuration changes. |
2082 | 425 |
*/ |
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
426 |
|
2082 | 427 |
typedef struct spa_spare { |
428 |
uint64_t spare_guid; |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
429 |
uint64_t spare_pool; |
2082 | 430 |
avl_node_t spare_avl; |
431 |
int spare_count; |
|
432 |
} spa_spare_t; |
|
433 |
||
434 |
static int |
|
435 |
spa_spare_compare(const void *a, const void *b) |
|
436 |
{ |
|
437 |
const spa_spare_t *sa = a; |
|
438 |
const spa_spare_t *sb = b; |
|
439 |
||
440 |
if (sa->spare_guid < sb->spare_guid) |
|
441 |
return (-1); |
|
442 |
else if (sa->spare_guid > sb->spare_guid) |
|
443 |
return (1); |
|
444 |
else |
|
445 |
return (0); |
|
446 |
} |
|
447 |
||
448 |
void |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
449 |
spa_spare_add(vdev_t *vd) |
2082 | 450 |
{ |
451 |
avl_index_t where; |
|
452 |
spa_spare_t search; |
|
453 |
spa_spare_t *spare; |
|
454 |
||
455 |
mutex_enter(&spa_spare_lock); |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
456 |
ASSERT(!vd->vdev_isspare); |
2082 | 457 |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
458 |
search.spare_guid = vd->vdev_guid; |
2082 | 459 |
if ((spare = avl_find(&spa_spare_avl, &search, &where)) != NULL) { |
460 |
spare->spare_count++; |
|
461 |
} else { |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
462 |
spare = kmem_zalloc(sizeof (spa_spare_t), KM_SLEEP); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
463 |
spare->spare_guid = vd->vdev_guid; |
2082 | 464 |
spare->spare_count = 1; |
465 |
avl_insert(&spa_spare_avl, spare, where); |
|
466 |
} |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
467 |
vd->vdev_isspare = B_TRUE; |
2082 | 468 |
|
469 |
mutex_exit(&spa_spare_lock); |
|
470 |
} |
|
471 |
||
472 |
void |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
473 |
spa_spare_remove(vdev_t *vd) |
2082 | 474 |
{ |
475 |
spa_spare_t search; |
|
476 |
spa_spare_t *spare; |
|
477 |
avl_index_t where; |
|
478 |
||
479 |
mutex_enter(&spa_spare_lock); |
|
480 |
||
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
481 |
search.spare_guid = vd->vdev_guid; |
2082 | 482 |
spare = avl_find(&spa_spare_avl, &search, &where); |
483 |
||
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
484 |
ASSERT(vd->vdev_isspare); |
2082 | 485 |
ASSERT(spare != NULL); |
486 |
||
487 |
if (--spare->spare_count == 0) { |
|
488 |
avl_remove(&spa_spare_avl, spare); |
|
489 |
kmem_free(spare, sizeof (spa_spare_t)); |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
490 |
} else if (spare->spare_pool == spa_guid(vd->vdev_spa)) { |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
491 |
spare->spare_pool = 0ULL; |
2082 | 492 |
} |
493 |
||
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
494 |
vd->vdev_isspare = B_FALSE; |
2082 | 495 |
mutex_exit(&spa_spare_lock); |
496 |
} |
|
497 |
||
498 |
boolean_t |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
499 |
spa_spare_exists(uint64_t guid, uint64_t *pool) |
2082 | 500 |
{ |
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
501 |
spa_spare_t search, *found; |
2082 | 502 |
avl_index_t where; |
503 |
||
504 |
mutex_enter(&spa_spare_lock); |
|
505 |
||
506 |
search.spare_guid = guid; |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
507 |
found = avl_find(&spa_spare_avl, &search, &where); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
508 |
|
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
509 |
if (pool) { |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
510 |
if (found) |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
511 |
*pool = found->spare_pool; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
512 |
else |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
513 |
*pool = 0ULL; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
514 |
} |
2082 | 515 |
|
516 |
mutex_exit(&spa_spare_lock); |
|
517 |
||
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
518 |
return (found != NULL); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
519 |
} |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
520 |
|
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
521 |
void |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
522 |
spa_spare_activate(vdev_t *vd) |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
523 |
{ |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
524 |
spa_spare_t search, *found; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
525 |
avl_index_t where; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
526 |
|
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
527 |
mutex_enter(&spa_spare_lock); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
528 |
ASSERT(vd->vdev_isspare); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
529 |
|
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
530 |
search.spare_guid = vd->vdev_guid; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
531 |
found = avl_find(&spa_spare_avl, &search, &where); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
532 |
ASSERT(found != NULL); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
533 |
ASSERT(found->spare_pool == 0ULL); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
534 |
|
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
535 |
found->spare_pool = spa_guid(vd->vdev_spa); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
536 |
mutex_exit(&spa_spare_lock); |
2082 | 537 |
} |
538 |
||
539 |
/* |
|
540 |
* ========================================================================== |
|
789 | 541 |
* SPA config locking |
542 |
* ========================================================================== |
|
543 |
*/ |
|
544 |
void |
|
1544 | 545 |
spa_config_enter(spa_t *spa, krw_t rw, void *tag) |
789 | 546 |
{ |
4787 | 547 |
rprw_enter(&spa->spa_config_lock, rw, tag); |
789 | 548 |
} |
549 |
||
550 |
void |
|
1544 | 551 |
spa_config_exit(spa_t *spa, void *tag) |
789 | 552 |
{ |
4787 | 553 |
rprw_exit(&spa->spa_config_lock, tag); |
789 | 554 |
} |
555 |
||
556 |
boolean_t |
|
557 |
spa_config_held(spa_t *spa, krw_t rw) |
|
558 |
{ |
|
4787 | 559 |
return (rprw_held(&spa->spa_config_lock, rw)); |
789 | 560 |
} |
561 |
||
562 |
/* |
|
563 |
* ========================================================================== |
|
564 |
* SPA vdev locking |
|
565 |
* ========================================================================== |
|
566 |
*/ |
|
567 |
||
568 |
/* |
|
1544 | 569 |
* Lock the given spa_t for the purpose of adding or removing a vdev. |
570 |
* Grabs the global spa_namespace_lock plus the spa config lock for writing. |
|
789 | 571 |
* It returns the next transaction group for the spa_t. |
572 |
*/ |
|
573 |
uint64_t |
|
574 |
spa_vdev_enter(spa_t *spa) |
|
575 |
{ |
|
4451 | 576 |
mutex_enter(&spa_namespace_lock); |
577 |
||
1544 | 578 |
/* |
4451 | 579 |
* Suspend scrub activity while we mess with the config. We must do |
580 |
* this after acquiring the namespace lock to avoid a 3-way deadlock |
|
581 |
* with spa_scrub_stop() and the scrub thread. |
|
1544 | 582 |
*/ |
583 |
spa_scrub_suspend(spa); |
|
789 | 584 |
|
1544 | 585 |
spa_config_enter(spa, RW_WRITER, spa); |
789 | 586 |
|
587 |
return (spa_last_synced_txg(spa) + 1); |
|
588 |
} |
|
589 |
||
590 |
/* |
|
591 |
* Unlock the spa_t after adding or removing a vdev. Besides undoing the |
|
592 |
* locking of spa_vdev_enter(), we also want make sure the transactions have |
|
593 |
* synced to disk, and then update the global configuration cache with the new |
|
594 |
* information. |
|
595 |
*/ |
|
596 |
int |
|
597 |
spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error) |
|
598 |
{ |
|
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
599 |
int config_changed = B_FALSE; |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
600 |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
601 |
ASSERT(txg > spa_last_synced_txg(spa)); |
789 | 602 |
|
1544 | 603 |
/* |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
604 |
* Reassess the DTLs. |
1544 | 605 |
*/ |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
606 |
vdev_dtl_reassess(spa->spa_root_vdev, 0, 0, B_FALSE); |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
607 |
|
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
608 |
/* |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
609 |
* If the config changed, notify the scrub thread that it must restart. |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
610 |
*/ |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
611 |
if (error == 0 && !list_is_empty(&spa->spa_dirty_list)) { |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
612 |
config_changed = B_TRUE; |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
613 |
spa_scrub_restart(spa, txg); |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
614 |
} |
789 | 615 |
|
1544 | 616 |
spa_config_exit(spa, spa); |
617 |
||
618 |
/* |
|
1601
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
619 |
* Allow scrubbing to resume. |
1544 | 620 |
*/ |
621 |
spa_scrub_resume(spa); |
|
622 |
||
789 | 623 |
/* |
624 |
* Note: this txg_wait_synced() is important because it ensures |
|
625 |
* that there won't be more than one config change per txg. |
|
626 |
* This allows us to use the txg as the generation number. |
|
627 |
*/ |
|
628 |
if (error == 0) |
|
629 |
txg_wait_synced(spa->spa_dsl_pool, txg); |
|
630 |
||
631 |
if (vd != NULL) { |
|
632 |
ASSERT(!vd->vdev_detached || vd->vdev_dtl.smo_object == 0); |
|
633 |
vdev_free(vd); |
|
634 |
} |
|
635 |
||
636 |
/* |
|
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
637 |
* If the config changed, update the config cache. |
789 | 638 |
*/ |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
639 |
if (config_changed) |
789 | 640 |
spa_config_sync(); |
1544 | 641 |
|
642 |
mutex_exit(&spa_namespace_lock); |
|
789 | 643 |
|
644 |
return (error); |
|
645 |
} |
|
646 |
||
647 |
/* |
|
648 |
* ========================================================================== |
|
649 |
* Miscellaneous functions |
|
650 |
* ========================================================================== |
|
651 |
*/ |
|
652 |
||
653 |
/* |
|
654 |
* Rename a spa_t. |
|
655 |
*/ |
|
656 |
int |
|
657 |
spa_rename(const char *name, const char *newname) |
|
658 |
{ |
|
659 |
spa_t *spa; |
|
660 |
int err; |
|
661 |
||
662 |
/* |
|
663 |
* Lookup the spa_t and grab the config lock for writing. We need to |
|
664 |
* actually open the pool so that we can sync out the necessary labels. |
|
665 |
* It's OK to call spa_open() with the namespace lock held because we |
|
1544 | 666 |
* allow recursive calls for other reasons. |
789 | 667 |
*/ |
668 |
mutex_enter(&spa_namespace_lock); |
|
669 |
if ((err = spa_open(name, &spa, FTAG)) != 0) { |
|
670 |
mutex_exit(&spa_namespace_lock); |
|
671 |
return (err); |
|
672 |
} |
|
673 |
||
1544 | 674 |
spa_config_enter(spa, RW_WRITER, FTAG); |
789 | 675 |
|
676 |
avl_remove(&spa_namespace_avl, spa); |
|
677 |
spa_strfree(spa->spa_name); |
|
678 |
spa->spa_name = spa_strdup(newname); |
|
679 |
avl_add(&spa_namespace_avl, spa); |
|
680 |
||
681 |
/* |
|
682 |
* Sync all labels to disk with the new names by marking the root vdev |
|
683 |
* dirty and waiting for it to sync. It will pick up the new pool name |
|
684 |
* during the sync. |
|
685 |
*/ |
|
686 |
vdev_config_dirty(spa->spa_root_vdev); |
|
687 |
||
1544 | 688 |
spa_config_exit(spa, FTAG); |
789 | 689 |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
690 |
txg_wait_synced(spa->spa_dsl_pool, 0); |
789 | 691 |
|
692 |
/* |
|
693 |
* Sync the updated config cache. |
|
694 |
*/ |
|
695 |
spa_config_sync(); |
|
696 |
||
697 |
spa_close(spa, FTAG); |
|
698 |
||
699 |
mutex_exit(&spa_namespace_lock); |
|
700 |
||
701 |
return (0); |
|
702 |
} |
|
703 |
||
704 |
||
705 |
/* |
|
706 |
* Determine whether a pool with given pool_guid exists. If device_guid is |
|
707 |
* non-zero, determine whether the pool exists *and* contains a device with the |
|
708 |
* specified device_guid. |
|
709 |
*/ |
|
710 |
boolean_t |
|
711 |
spa_guid_exists(uint64_t pool_guid, uint64_t device_guid) |
|
712 |
{ |
|
713 |
spa_t *spa; |
|
714 |
avl_tree_t *t = &spa_namespace_avl; |
|
715 |
||
1544 | 716 |
ASSERT(MUTEX_HELD(&spa_namespace_lock)); |
789 | 717 |
|
718 |
for (spa = avl_first(t); spa != NULL; spa = AVL_NEXT(t, spa)) { |
|
719 |
if (spa->spa_state == POOL_STATE_UNINITIALIZED) |
|
720 |
continue; |
|
721 |
if (spa->spa_root_vdev == NULL) |
|
722 |
continue; |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
723 |
if (spa_guid(spa) == pool_guid) { |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
724 |
if (device_guid == 0) |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
725 |
break; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
726 |
|
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
727 |
if (vdev_lookup_by_guid(spa->spa_root_vdev, |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
728 |
device_guid) != NULL) |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
729 |
break; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
730 |
|
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
731 |
/* |
4527 | 732 |
* Check any devices we may be in the process of adding. |
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
733 |
*/ |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
734 |
if (spa->spa_pending_vdev) { |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
735 |
if (vdev_lookup_by_guid(spa->spa_pending_vdev, |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
736 |
device_guid) != NULL) |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
737 |
break; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
738 |
} |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
2986
diff
changeset
|
739 |
} |
789 | 740 |
} |
741 |
||
742 |
return (spa != NULL); |
|
743 |
} |
|
744 |
||
745 |
char * |
|
746 |
spa_strdup(const char *s) |
|
747 |
{ |
|
748 |
size_t len; |
|
749 |
char *new; |
|
750 |
||
751 |
len = strlen(s); |
|
752 |
new = kmem_alloc(len + 1, KM_SLEEP); |
|
753 |
bcopy(s, new, len); |
|
754 |
new[len] = '\0'; |
|
755 |
||
756 |
return (new); |
|
757 |
} |
|
758 |
||
759 |
void |
|
760 |
spa_strfree(char *s) |
|
761 |
{ |
|
762 |
kmem_free(s, strlen(s) + 1); |
|
763 |
} |
|
764 |
||
765 |
uint64_t |
|
766 |
spa_get_random(uint64_t range) |
|
767 |
{ |
|
768 |
uint64_t r; |
|
769 |
||
770 |
ASSERT(range != 0); |
|
771 |
||
772 |
(void) random_get_pseudo_bytes((void *)&r, sizeof (uint64_t)); |
|
773 |
||
774 |
return (r % range); |
|
775 |
} |
|
776 |
||
777 |
void |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1775
diff
changeset
|
778 |
sprintf_blkptr(char *buf, int len, const blkptr_t *bp) |
789 | 779 |
{ |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
780 |
int d; |
789 | 781 |
|
782 |
if (bp == NULL) { |
|
896 | 783 |
(void) snprintf(buf, len, "<NULL>"); |
789 | 784 |
return; |
785 |
} |
|
786 |
||
787 |
if (BP_IS_HOLE(bp)) { |
|
896 | 788 |
(void) snprintf(buf, len, "<hole>"); |
789 | 789 |
return; |
790 |
} |
|
791 |
||
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
792 |
(void) snprintf(buf, len, "[L%llu %s] %llxL/%llxP ", |
789 | 793 |
(u_longlong_t)BP_GET_LEVEL(bp), |
794 |
dmu_ot[BP_GET_TYPE(bp)].ot_name, |
|
795 |
(u_longlong_t)BP_GET_LSIZE(bp), |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
796 |
(u_longlong_t)BP_GET_PSIZE(bp)); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
797 |
|
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
798 |
for (d = 0; d < BP_GET_NDVAS(bp); d++) { |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1775
diff
changeset
|
799 |
const dva_t *dva = &bp->blk_dva[d]; |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
800 |
(void) snprintf(buf + strlen(buf), len - strlen(buf), |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
801 |
"DVA[%d]=<%llu:%llx:%llx> ", d, |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
802 |
(u_longlong_t)DVA_GET_VDEV(dva), |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
803 |
(u_longlong_t)DVA_GET_OFFSET(dva), |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
804 |
(u_longlong_t)DVA_GET_ASIZE(dva)); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
805 |
} |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
806 |
|
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
807 |
(void) snprintf(buf + strlen(buf), len - strlen(buf), |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
808 |
"%s %s %s %s birth=%llu fill=%llu cksum=%llx:%llx:%llx:%llx", |
789 | 809 |
zio_checksum_table[BP_GET_CHECKSUM(bp)].ci_name, |
810 |
zio_compress_table[BP_GET_COMPRESS(bp)].ci_name, |
|
811 |
BP_GET_BYTEORDER(bp) == 0 ? "BE" : "LE", |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
812 |
BP_IS_GANG(bp) ? "gang" : "contiguous", |
789 | 813 |
(u_longlong_t)bp->blk_birth, |
814 |
(u_longlong_t)bp->blk_fill, |
|
815 |
(u_longlong_t)bp->blk_cksum.zc_word[0], |
|
816 |
(u_longlong_t)bp->blk_cksum.zc_word[1], |
|
817 |
(u_longlong_t)bp->blk_cksum.zc_word[2], |
|
818 |
(u_longlong_t)bp->blk_cksum.zc_word[3]); |
|
819 |
} |
|
820 |
||
821 |
void |
|
822 |
spa_freeze(spa_t *spa) |
|
823 |
{ |
|
824 |
uint64_t freeze_txg = 0; |
|
825 |
||
1544 | 826 |
spa_config_enter(spa, RW_WRITER, FTAG); |
789 | 827 |
if (spa->spa_freeze_txg == UINT64_MAX) { |
828 |
freeze_txg = spa_last_synced_txg(spa) + TXG_SIZE; |
|
829 |
spa->spa_freeze_txg = freeze_txg; |
|
830 |
} |
|
1544 | 831 |
spa_config_exit(spa, FTAG); |
789 | 832 |
if (freeze_txg != 0) |
833 |
txg_wait_synced(spa_get_dsl(spa), freeze_txg); |
|
834 |
} |
|
835 |
||
3713 | 836 |
void |
837 |
zfs_panic_recover(const char *fmt, ...) |
|
838 |
{ |
|
839 |
va_list adx; |
|
840 |
||
841 |
va_start(adx, fmt); |
|
842 |
vcmn_err(zfs_recover ? CE_WARN : CE_PANIC, fmt, adx); |
|
843 |
va_end(adx); |
|
844 |
} |
|
845 |
||
789 | 846 |
/* |
847 |
* ========================================================================== |
|
848 |
* Accessor functions |
|
849 |
* ========================================================================== |
|
850 |
*/ |
|
851 |
||
852 |
krwlock_t * |
|
853 |
spa_traverse_rwlock(spa_t *spa) |
|
854 |
{ |
|
855 |
return (&spa->spa_traverse_lock); |
|
856 |
} |
|
857 |
||
858 |
int |
|
859 |
spa_traverse_wanted(spa_t *spa) |
|
860 |
{ |
|
861 |
return (spa->spa_traverse_wanted); |
|
862 |
} |
|
863 |
||
864 |
dsl_pool_t * |
|
865 |
spa_get_dsl(spa_t *spa) |
|
866 |
{ |
|
867 |
return (spa->spa_dsl_pool); |
|
868 |
} |
|
869 |
||
870 |
blkptr_t * |
|
871 |
spa_get_rootblkptr(spa_t *spa) |
|
872 |
{ |
|
873 |
return (&spa->spa_ubsync.ub_rootbp); |
|
874 |
} |
|
875 |
||
876 |
void |
|
877 |
spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp) |
|
878 |
{ |
|
879 |
spa->spa_uberblock.ub_rootbp = *bp; |
|
880 |
} |
|
881 |
||
882 |
void |
|
883 |
spa_altroot(spa_t *spa, char *buf, size_t buflen) |
|
884 |
{ |
|
885 |
if (spa->spa_root == NULL) |
|
886 |
buf[0] = '\0'; |
|
887 |
else |
|
888 |
(void) strncpy(buf, spa->spa_root, buflen); |
|
889 |
} |
|
890 |
||
891 |
int |
|
892 |
spa_sync_pass(spa_t *spa) |
|
893 |
{ |
|
894 |
return (spa->spa_sync_pass); |
|
895 |
} |
|
896 |
||
897 |
char * |
|
898 |
spa_name(spa_t *spa) |
|
899 |
{ |
|
900 |
/* |
|
901 |
* Accessing the name requires holding either the namespace lock or the |
|
902 |
* config lock, both of which are required to do a rename. |
|
903 |
*/ |
|
904 |
ASSERT(MUTEX_HELD(&spa_namespace_lock) || |
|
905 |
spa_config_held(spa, RW_READER) || spa_config_held(spa, RW_WRITER)); |
|
906 |
||
907 |
return (spa->spa_name); |
|
908 |
} |
|
909 |
||
910 |
uint64_t |
|
911 |
spa_guid(spa_t *spa) |
|
912 |
{ |
|
2174
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
913 |
/* |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
914 |
* If we fail to parse the config during spa_load(), we can go through |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
915 |
* the error path (which posts an ereport) and end up here with no root |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
916 |
* vdev. We stash the original pool guid in 'spa_load_guid' to handle |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
917 |
* this case. |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
918 |
*/ |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
919 |
if (spa->spa_root_vdev != NULL) |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
920 |
return (spa->spa_root_vdev->vdev_guid); |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
921 |
else |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
922 |
return (spa->spa_load_guid); |
789 | 923 |
} |
924 |
||
925 |
uint64_t |
|
926 |
spa_last_synced_txg(spa_t *spa) |
|
927 |
{ |
|
928 |
return (spa->spa_ubsync.ub_txg); |
|
929 |
} |
|
930 |
||
931 |
uint64_t |
|
932 |
spa_first_txg(spa_t *spa) |
|
933 |
{ |
|
934 |
return (spa->spa_first_txg); |
|
935 |
} |
|
936 |
||
937 |
int |
|
938 |
spa_state(spa_t *spa) |
|
939 |
{ |
|
940 |
return (spa->spa_state); |
|
941 |
} |
|
942 |
||
943 |
uint64_t |
|
944 |
spa_freeze_txg(spa_t *spa) |
|
945 |
{ |
|
946 |
return (spa->spa_freeze_txg); |
|
947 |
} |
|
948 |
||
949 |
/* |
|
2082 | 950 |
* Return how much space is allocated in the pool (ie. sum of all asize) |
789 | 951 |
*/ |
952 |
uint64_t |
|
953 |
spa_get_alloc(spa_t *spa) |
|
954 |
{ |
|
955 |
return (spa->spa_root_vdev->vdev_stat.vs_alloc); |
|
956 |
} |
|
957 |
||
958 |
/* |
|
2082 | 959 |
* Return how much (raid-z inflated) space there is in the pool. |
789 | 960 |
*/ |
961 |
uint64_t |
|
962 |
spa_get_space(spa_t *spa) |
|
963 |
{ |
|
964 |
return (spa->spa_root_vdev->vdev_stat.vs_space); |
|
965 |
} |
|
966 |
||
2082 | 967 |
/* |
968 |
* Return the amount of raid-z-deflated space in the pool. |
|
969 |
*/ |
|
970 |
uint64_t |
|
971 |
spa_get_dspace(spa_t *spa) |
|
972 |
{ |
|
973 |
if (spa->spa_deflate) |
|
974 |
return (spa->spa_root_vdev->vdev_stat.vs_dspace); |
|
975 |
else |
|
976 |
return (spa->spa_root_vdev->vdev_stat.vs_space); |
|
977 |
} |
|
978 |
||
789 | 979 |
/* ARGSUSED */ |
980 |
uint64_t |
|
981 |
spa_get_asize(spa_t *spa, uint64_t lsize) |
|
982 |
{ |
|
983 |
/* |
|
984 |
* For now, the worst case is 512-byte RAID-Z blocks, in which |
|
985 |
* case the space requirement is exactly 2x; so just assume that. |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
986 |
* Add to this the fact that we can have up to 3 DVAs per bp, and |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
987 |
* we have to multiply by a total of 6x. |
789 | 988 |
*/ |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
989 |
return (lsize * 6); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
990 |
} |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
991 |
|
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
992 |
uint64_t |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
993 |
spa_version(spa_t *spa) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
994 |
{ |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
995 |
return (spa->spa_ubsync.ub_version); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
996 |
} |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
997 |
|
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
998 |
int |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
999 |
spa_max_replication(spa_t *spa) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
1000 |
{ |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
1001 |
/* |
4577 | 1002 |
* As of SPA_VERSION == SPA_VERSION_DITTO_BLOCKS, we are able to |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
1003 |
* handle BPs with more than one DVA allocated. Set our max |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
1004 |
* replication level accordingly. |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
1005 |
*/ |
4577 | 1006 |
if (spa_version(spa) < SPA_VERSION_DITTO_BLOCKS) |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
1007 |
return (1); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1635
diff
changeset
|
1008 |
return (MIN(SPA_DVAS_PER_BP, spa_max_replication_override)); |
789 | 1009 |
} |
1010 |
||
2082 | 1011 |
uint64_t |
1012 |
bp_get_dasize(spa_t *spa, const blkptr_t *bp) |
|
1013 |
{ |
|
1014 |
int sz = 0, i; |
|
1015 |
||
1016 |
if (!spa->spa_deflate) |
|
1017 |
return (BP_GET_ASIZE(bp)); |
|
1018 |
||
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4831
diff
changeset
|
1019 |
spa_config_enter(spa, RW_READER, FTAG); |
2082 | 1020 |
for (i = 0; i < SPA_DVAS_PER_BP; i++) { |
1021 |
vdev_t *vd = |
|
1022 |
vdev_lookup_top(spa, DVA_GET_VDEV(&bp->blk_dva[i])); |
|
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4831
diff
changeset
|
1023 |
if (vd) |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4831
diff
changeset
|
1024 |
sz += (DVA_GET_ASIZE(&bp->blk_dva[i]) >> |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4831
diff
changeset
|
1025 |
SPA_MINBLOCKSHIFT) * vd->vdev_deflate_ratio; |
2082 | 1026 |
} |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4831
diff
changeset
|
1027 |
spa_config_exit(spa, FTAG); |
2082 | 1028 |
return (sz); |
1029 |
} |
|
1030 |
||
789 | 1031 |
/* |
1032 |
* ========================================================================== |
|
1033 |
* Initialization and Termination |
|
1034 |
* ========================================================================== |
|
1035 |
*/ |
|
1036 |
||
1037 |
static int |
|
1038 |
spa_name_compare(const void *a1, const void *a2) |
|
1039 |
{ |
|
1040 |
const spa_t *s1 = a1; |
|
1041 |
const spa_t *s2 = a2; |
|
1042 |
int s; |
|
1043 |
||
1044 |
s = strcmp(s1->spa_name, s2->spa_name); |
|
1045 |
if (s > 0) |
|
1046 |
return (1); |
|
1047 |
if (s < 0) |
|
1048 |
return (-1); |
|
1049 |
return (0); |
|
1050 |
} |
|
1051 |
||
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1052 |
int |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1053 |
spa_busy(void) |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1054 |
{ |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1055 |
return (spa_active_count); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1056 |
} |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1057 |
|
789 | 1058 |
void |
1059 |
spa_init(int mode) |
|
1060 |
{ |
|
1061 |
mutex_init(&spa_namespace_lock, NULL, MUTEX_DEFAULT, NULL); |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
1062 |
mutex_init(&spa_spare_lock, NULL, MUTEX_DEFAULT, NULL); |
789 | 1063 |
cv_init(&spa_namespace_cv, NULL, CV_DEFAULT, NULL); |
1064 |
||
1065 |
avl_create(&spa_namespace_avl, spa_name_compare, sizeof (spa_t), |
|
1066 |
offsetof(spa_t, spa_avl)); |
|
1067 |
||
2082 | 1068 |
avl_create(&spa_spare_avl, spa_spare_compare, sizeof (spa_spare_t), |
1069 |
offsetof(spa_spare_t, spare_avl)); |
|
1070 |
||
789 | 1071 |
spa_mode = mode; |
1072 |
||
1073 |
refcount_init(); |
|
1074 |
unique_init(); |
|
1075 |
zio_init(); |
|
1076 |
dmu_init(); |
|
1077 |
zil_init(); |
|
4787 | 1078 |
zfs_prop_init(); |
789 | 1079 |
spa_config_load(); |
1080 |
} |
|
1081 |
||
1082 |
void |
|
1083 |
spa_fini(void) |
|
1084 |
{ |
|
1085 |
spa_evict_all(); |
|
1086 |
||
1087 |
zil_fini(); |
|
1088 |
dmu_fini(); |
|
1089 |
zio_fini(); |
|
4787 | 1090 |
unique_fini(); |
789 | 1091 |
refcount_fini(); |
1092 |
||
1093 |
avl_destroy(&spa_namespace_avl); |
|
2082 | 1094 |
avl_destroy(&spa_spare_avl); |
789 | 1095 |
|
1096 |
cv_destroy(&spa_namespace_cv); |
|
1097 |
mutex_destroy(&spa_namespace_lock); |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
1098 |
mutex_destroy(&spa_spare_lock); |
789 | 1099 |
} |
4620 | 1100 |
|
1101 |
/* |
|
1102 |
* Return whether this pool has slogs. No locking needed. |
|
1103 |
* It's not a problem if the wrong answer is returned as it's only for |
|
1104 |
* performance and not correctness |
|
1105 |
*/ |
|
1106 |
boolean_t |
|
1107 |
spa_has_slogs(spa_t *spa) |
|
1108 |
{ |
|
1109 |
return (spa->spa_log_class->mc_rotor != NULL); |
|
1110 |
} |