Print this page
4101 metaslab_debug should allow for fine-grained control
4102 space_maps should store more information about themselves
4103 space map object blocksize should be increased
4104 ::spa_space no longer works
4105 removing a mirrored log device results in a leaked object
4106 asynchronously load metaslab
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Sebastien Roy <seb@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/spa_misc.c
+++ new/usr/src/uts/common/fs/zfs/spa_misc.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2013 by Delphix. All rights reserved.
24 24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 25 */
26 26
27 27 #include <sys/zfs_context.h>
28 28 #include <sys/spa_impl.h>
29 29 #include <sys/spa_boot.h>
30 30 #include <sys/zio.h>
31 31 #include <sys/zio_checksum.h>
32 32 #include <sys/zio_compress.h>
33 33 #include <sys/dmu.h>
34 34 #include <sys/dmu_tx.h>
35 35 #include <sys/zap.h>
36 36 #include <sys/zil.h>
37 37 #include <sys/vdev_impl.h>
38 38 #include <sys/metaslab.h>
39 39 #include <sys/uberblock_impl.h>
40 40 #include <sys/txg.h>
41 41 #include <sys/avl.h>
42 42 #include <sys/unique.h>
43 43 #include <sys/dsl_pool.h>
44 44 #include <sys/dsl_dir.h>
45 45 #include <sys/dsl_prop.h>
46 46 #include <sys/dsl_scan.h>
47 47 #include <sys/fs/zfs.h>
48 48 #include <sys/metaslab_impl.h>
49 49 #include <sys/arc.h>
50 50 #include <sys/ddt.h>
51 51 #include "zfs_prop.h"
52 52 #include "zfeature_common.h"
53 53
54 54 /*
55 55 * SPA locking
56 56 *
57 57 * There are four basic locks for managing spa_t structures:
58 58 *
59 59 * spa_namespace_lock (global mutex)
60 60 *
61 61 * This lock must be acquired to do any of the following:
62 62 *
63 63 * - Lookup a spa_t by name
64 64 * - Add or remove a spa_t from the namespace
65 65 * - Increase spa_refcount from non-zero
66 66 * - Check if spa_refcount is zero
67 67 * - Rename a spa_t
68 68 * - add/remove/attach/detach devices
69 69 * - Held for the duration of create/destroy/import/export
70 70 *
71 71 * It does not need to handle recursion. A create or destroy may
72 72 * reference objects (files or zvols) in other pools, but by
73 73 * definition they must have an existing reference, and will never need
74 74 * to lookup a spa_t by name.
75 75 *
76 76 * spa_refcount (per-spa refcount_t protected by mutex)
77 77 *
78 78 * This reference count keep track of any active users of the spa_t. The
79 79 * spa_t cannot be destroyed or freed while this is non-zero. Internally,
80 80 * the refcount is never really 'zero' - opening a pool implicitly keeps
81 81 * some references in the DMU. Internally we check against spa_minref, but
82 82 * present the image of a zero/non-zero value to consumers.
83 83 *
84 84 * spa_config_lock[] (per-spa array of rwlocks)
85 85 *
86 86 * This protects the spa_t from config changes, and must be held in
87 87 * the following circumstances:
88 88 *
89 89 * - RW_READER to perform I/O to the spa
90 90 * - RW_WRITER to change the vdev config
91 91 *
92 92 * The locking order is fairly straightforward:
93 93 *
94 94 * spa_namespace_lock -> spa_refcount
95 95 *
96 96 * The namespace lock must be acquired to increase the refcount from 0
97 97 * or to check if it is zero.
98 98 *
99 99 * spa_refcount -> spa_config_lock[]
100 100 *
101 101 * There must be at least one valid reference on the spa_t to acquire
102 102 * the config lock.
103 103 *
104 104 * spa_namespace_lock -> spa_config_lock[]
105 105 *
106 106 * The namespace lock must always be taken before the config lock.
107 107 *
108 108 *
109 109 * The spa_namespace_lock can be acquired directly and is globally visible.
110 110 *
111 111 * The namespace is manipulated using the following functions, all of which
112 112 * require the spa_namespace_lock to be held.
113 113 *
114 114 * spa_lookup() Lookup a spa_t by name.
115 115 *
116 116 * spa_add() Create a new spa_t in the namespace.
117 117 *
118 118 * spa_remove() Remove a spa_t from the namespace. This also
119 119 * frees up any memory associated with the spa_t.
120 120 *
121 121 * spa_next() Returns the next spa_t in the system, or the
122 122 * first if NULL is passed.
123 123 *
124 124 * spa_evict_all() Shutdown and remove all spa_t structures in
125 125 * the system.
126 126 *
127 127 * spa_guid_exists() Determine whether a pool/device guid exists.
128 128 *
129 129 * The spa_refcount is manipulated using the following functions:
130 130 *
131 131 * spa_open_ref() Adds a reference to the given spa_t. Must be
132 132 * called with spa_namespace_lock held if the
133 133 * refcount is currently zero.
134 134 *
135 135 * spa_close() Remove a reference from the spa_t. This will
136 136 * not free the spa_t or remove it from the
137 137 * namespace. No locking is required.
138 138 *
139 139 * spa_refcount_zero() Returns true if the refcount is currently
140 140 * zero. Must be called with spa_namespace_lock
141 141 * held.
142 142 *
143 143 * The spa_config_lock[] is an array of rwlocks, ordered as follows:
144 144 * SCL_CONFIG > SCL_STATE > SCL_ALLOC > SCL_ZIO > SCL_FREE > SCL_VDEV.
145 145 * spa_config_lock[] is manipulated with spa_config_{enter,exit,held}().
146 146 *
147 147 * To read the configuration, it suffices to hold one of these locks as reader.
148 148 * To modify the configuration, you must hold all locks as writer. To modify
149 149 * vdev state without altering the vdev tree's topology (e.g. online/offline),
150 150 * you must hold SCL_STATE and SCL_ZIO as writer.
151 151 *
152 152 * We use these distinct config locks to avoid recursive lock entry.
153 153 * For example, spa_sync() (which holds SCL_CONFIG as reader) induces
154 154 * block allocations (SCL_ALLOC), which may require reading space maps
155 155 * from disk (dmu_read() -> zio_read() -> SCL_ZIO).
156 156 *
157 157 * The spa config locks cannot be normal rwlocks because we need the
158 158 * ability to hand off ownership. For example, SCL_ZIO is acquired
159 159 * by the issuing thread and later released by an interrupt thread.
160 160 * They do, however, obey the usual write-wanted semantics to prevent
161 161 * writer (i.e. system administrator) starvation.
162 162 *
163 163 * The lock acquisition rules are as follows:
164 164 *
165 165 * SCL_CONFIG
166 166 * Protects changes to the vdev tree topology, such as vdev
167 167 * add/remove/attach/detach. Protects the dirty config list
168 168 * (spa_config_dirty_list) and the set of spares and l2arc devices.
169 169 *
170 170 * SCL_STATE
171 171 * Protects changes to pool state and vdev state, such as vdev
172 172 * online/offline/fault/degrade/clear. Protects the dirty state list
173 173 * (spa_state_dirty_list) and global pool state (spa_state).
174 174 *
175 175 * SCL_ALLOC
176 176 * Protects changes to metaslab groups and classes.
177 177 * Held as reader by metaslab_alloc() and metaslab_claim().
178 178 *
179 179 * SCL_ZIO
180 180 * Held by bp-level zios (those which have no io_vd upon entry)
181 181 * to prevent changes to the vdev tree. The bp-level zio implicitly
182 182 * protects all of its vdev child zios, which do not hold SCL_ZIO.
183 183 *
184 184 * SCL_FREE
185 185 * Protects changes to metaslab groups and classes.
186 186 * Held as reader by metaslab_free(). SCL_FREE is distinct from
187 187 * SCL_ALLOC, and lower than SCL_ZIO, so that we can safely free
188 188 * blocks in zio_done() while another i/o that holds either
189 189 * SCL_ALLOC or SCL_ZIO is waiting for this i/o to complete.
190 190 *
191 191 * SCL_VDEV
192 192 * Held as reader to prevent changes to the vdev tree during trivial
193 193 * inquiries such as bp_get_dsize(). SCL_VDEV is distinct from the
194 194 * other locks, and lower than all of them, to ensure that it's safe
195 195 * to acquire regardless of caller context.
196 196 *
197 197 * In addition, the following rules apply:
198 198 *
199 199 * (a) spa_props_lock protects pool properties, spa_config and spa_config_list.
200 200 * The lock ordering is SCL_CONFIG > spa_props_lock.
201 201 *
202 202 * (b) I/O operations on leaf vdevs. For any zio operation that takes
203 203 * an explicit vdev_t argument -- such as zio_ioctl(), zio_read_phys(),
204 204 * or zio_write_phys() -- the caller must ensure that the config cannot
205 205 * cannot change in the interim, and that the vdev cannot be reopened.
206 206 * SCL_STATE as reader suffices for both.
207 207 *
208 208 * The vdev configuration is protected by spa_vdev_enter() / spa_vdev_exit().
209 209 *
210 210 * spa_vdev_enter() Acquire the namespace lock and the config lock
211 211 * for writing.
212 212 *
213 213 * spa_vdev_exit() Release the config lock, wait for all I/O
214 214 * to complete, sync the updated configs to the
215 215 * cache, and release the namespace lock.
216 216 *
217 217 * vdev state is protected by spa_vdev_state_enter() / spa_vdev_state_exit().
218 218 * Like spa_vdev_enter/exit, these are convenience wrappers -- the actual
219 219 * locking is, always, based on spa_namespace_lock and spa_config_lock[].
220 220 *
221 221 * spa_rename() is also implemented within this file since it requires
222 222 * manipulation of the namespace.
223 223 */
224 224
225 225 static avl_tree_t spa_namespace_avl;
226 226 kmutex_t spa_namespace_lock;
227 227 static kcondvar_t spa_namespace_cv;
228 228 static int spa_active_count;
229 229 int spa_max_replication_override = SPA_DVAS_PER_BP;
230 230
231 231 static kmutex_t spa_spare_lock;
232 232 static avl_tree_t spa_spare_avl;
233 233 static kmutex_t spa_l2cache_lock;
234 234 static avl_tree_t spa_l2cache_avl;
235 235
236 236 kmem_cache_t *spa_buffer_pool;
237 237 int spa_mode_global;
238 238
239 239 #ifdef ZFS_DEBUG
240 240 /* Everything except dprintf and spa is on by default in debug builds */
241 241 int zfs_flags = ~(ZFS_DEBUG_DPRINTF | ZFS_DEBUG_SPA);
242 242 #else
243 243 int zfs_flags = 0;
244 244 #endif
245 245
246 246 /*
247 247 * zfs_recover can be set to nonzero to attempt to recover from
248 248 * otherwise-fatal errors, typically caused by on-disk corruption. When
249 249 * set, calls to zfs_panic_recover() will turn into warning messages.
250 250 */
251 251 int zfs_recover = 0;
252 252
253 253 /*
254 254 * Expiration time in milliseconds. This value has two meanings. First it is
255 255 * used to determine when the spa_deadman() logic should fire. By default the
256 256 * spa_deadman() will fire if spa_sync() has not completed in 1000 seconds.
257 257 * Secondly, the value determines if an I/O is considered "hung". Any I/O that
258 258 * has not completed in zfs_deadman_synctime_ms is considered "hung" resulting
259 259 * in a system panic.
260 260 */
261 261 uint64_t zfs_deadman_synctime_ms = 1000000ULL;
262 262
263 263 /*
264 264 * Check time in milliseconds. This defines the frequency at which we check
265 265 * for hung I/O.
266 266 */
267 267 uint64_t zfs_deadman_checktime_ms = 5000ULL;
268 268
269 269 /*
270 270 * Override the zfs deadman behavior via /etc/system. By default the
271 271 * deadman is enabled except on VMware and sparc deployments.
272 272 */
273 273 int zfs_deadman_enabled = -1;
274 274
275 275 /*
276 276 * The worst case is single-sector max-parity RAID-Z blocks, in which
277 277 * case the space requirement is exactly (VDEV_RAIDZ_MAXPARITY + 1)
278 278 * times the size; so just assume that. Add to this the fact that
279 279 * we can have up to 3 DVAs per bp, and one more factor of 2 because
280 280 * the block may be dittoed with up to 3 DVAs by ddt_sync(). All together,
281 281 * the worst case is:
282 282 * (VDEV_RAIDZ_MAXPARITY + 1) * SPA_DVAS_PER_BP * 2 == 24
283 283 */
284 284 int spa_asize_inflation = 24;
285 285
286 286 /*
287 287 * ==========================================================================
288 288 * SPA config locking
289 289 * ==========================================================================
290 290 */
291 291 static void
292 292 spa_config_lock_init(spa_t *spa)
293 293 {
294 294 for (int i = 0; i < SCL_LOCKS; i++) {
295 295 spa_config_lock_t *scl = &spa->spa_config_lock[i];
296 296 mutex_init(&scl->scl_lock, NULL, MUTEX_DEFAULT, NULL);
297 297 cv_init(&scl->scl_cv, NULL, CV_DEFAULT, NULL);
298 298 refcount_create_untracked(&scl->scl_count);
299 299 scl->scl_writer = NULL;
300 300 scl->scl_write_wanted = 0;
301 301 }
302 302 }
303 303
304 304 static void
305 305 spa_config_lock_destroy(spa_t *spa)
306 306 {
307 307 for (int i = 0; i < SCL_LOCKS; i++) {
308 308 spa_config_lock_t *scl = &spa->spa_config_lock[i];
309 309 mutex_destroy(&scl->scl_lock);
310 310 cv_destroy(&scl->scl_cv);
311 311 refcount_destroy(&scl->scl_count);
312 312 ASSERT(scl->scl_writer == NULL);
313 313 ASSERT(scl->scl_write_wanted == 0);
314 314 }
315 315 }
316 316
317 317 int
318 318 spa_config_tryenter(spa_t *spa, int locks, void *tag, krw_t rw)
319 319 {
320 320 for (int i = 0; i < SCL_LOCKS; i++) {
321 321 spa_config_lock_t *scl = &spa->spa_config_lock[i];
322 322 if (!(locks & (1 << i)))
323 323 continue;
324 324 mutex_enter(&scl->scl_lock);
325 325 if (rw == RW_READER) {
326 326 if (scl->scl_writer || scl->scl_write_wanted) {
327 327 mutex_exit(&scl->scl_lock);
328 328 spa_config_exit(spa, locks ^ (1 << i), tag);
329 329 return (0);
330 330 }
331 331 } else {
332 332 ASSERT(scl->scl_writer != curthread);
333 333 if (!refcount_is_zero(&scl->scl_count)) {
334 334 mutex_exit(&scl->scl_lock);
335 335 spa_config_exit(spa, locks ^ (1 << i), tag);
336 336 return (0);
337 337 }
338 338 scl->scl_writer = curthread;
339 339 }
340 340 (void) refcount_add(&scl->scl_count, tag);
341 341 mutex_exit(&scl->scl_lock);
342 342 }
343 343 return (1);
344 344 }
345 345
346 346 void
347 347 spa_config_enter(spa_t *spa, int locks, void *tag, krw_t rw)
348 348 {
349 349 int wlocks_held = 0;
350 350
351 351 ASSERT3U(SCL_LOCKS, <, sizeof (wlocks_held) * NBBY);
352 352
353 353 for (int i = 0; i < SCL_LOCKS; i++) {
354 354 spa_config_lock_t *scl = &spa->spa_config_lock[i];
355 355 if (scl->scl_writer == curthread)
356 356 wlocks_held |= (1 << i);
357 357 if (!(locks & (1 << i)))
358 358 continue;
359 359 mutex_enter(&scl->scl_lock);
360 360 if (rw == RW_READER) {
361 361 while (scl->scl_writer || scl->scl_write_wanted) {
362 362 cv_wait(&scl->scl_cv, &scl->scl_lock);
363 363 }
364 364 } else {
365 365 ASSERT(scl->scl_writer != curthread);
366 366 while (!refcount_is_zero(&scl->scl_count)) {
367 367 scl->scl_write_wanted++;
368 368 cv_wait(&scl->scl_cv, &scl->scl_lock);
369 369 scl->scl_write_wanted--;
370 370 }
371 371 scl->scl_writer = curthread;
372 372 }
373 373 (void) refcount_add(&scl->scl_count, tag);
374 374 mutex_exit(&scl->scl_lock);
375 375 }
376 376 ASSERT(wlocks_held <= locks);
377 377 }
378 378
379 379 void
380 380 spa_config_exit(spa_t *spa, int locks, void *tag)
381 381 {
382 382 for (int i = SCL_LOCKS - 1; i >= 0; i--) {
383 383 spa_config_lock_t *scl = &spa->spa_config_lock[i];
384 384 if (!(locks & (1 << i)))
385 385 continue;
386 386 mutex_enter(&scl->scl_lock);
387 387 ASSERT(!refcount_is_zero(&scl->scl_count));
388 388 if (refcount_remove(&scl->scl_count, tag) == 0) {
389 389 ASSERT(scl->scl_writer == NULL ||
390 390 scl->scl_writer == curthread);
391 391 scl->scl_writer = NULL; /* OK in either case */
392 392 cv_broadcast(&scl->scl_cv);
393 393 }
394 394 mutex_exit(&scl->scl_lock);
395 395 }
396 396 }
397 397
398 398 int
399 399 spa_config_held(spa_t *spa, int locks, krw_t rw)
400 400 {
401 401 int locks_held = 0;
402 402
403 403 for (int i = 0; i < SCL_LOCKS; i++) {
404 404 spa_config_lock_t *scl = &spa->spa_config_lock[i];
405 405 if (!(locks & (1 << i)))
406 406 continue;
407 407 if ((rw == RW_READER && !refcount_is_zero(&scl->scl_count)) ||
408 408 (rw == RW_WRITER && scl->scl_writer == curthread))
409 409 locks_held |= 1 << i;
410 410 }
411 411
412 412 return (locks_held);
413 413 }
414 414
415 415 /*
416 416 * ==========================================================================
417 417 * SPA namespace functions
418 418 * ==========================================================================
419 419 */
420 420
421 421 /*
422 422 * Lookup the named spa_t in the AVL tree. The spa_namespace_lock must be held.
423 423 * Returns NULL if no matching spa_t is found.
424 424 */
425 425 spa_t *
426 426 spa_lookup(const char *name)
427 427 {
428 428 static spa_t search; /* spa_t is large; don't allocate on stack */
429 429 spa_t *spa;
430 430 avl_index_t where;
431 431 char *cp;
432 432
433 433 ASSERT(MUTEX_HELD(&spa_namespace_lock));
434 434
435 435 (void) strlcpy(search.spa_name, name, sizeof (search.spa_name));
436 436
437 437 /*
438 438 * If it's a full dataset name, figure out the pool name and
439 439 * just use that.
440 440 */
441 441 cp = strpbrk(search.spa_name, "/@");
442 442 if (cp != NULL)
443 443 *cp = '\0';
444 444
445 445 spa = avl_find(&spa_namespace_avl, &search, &where);
446 446
447 447 return (spa);
448 448 }
449 449
↓ open down ↓ |
449 lines elided |
↑ open up ↑ |
450 450 /*
451 451 * Fires when spa_sync has not completed within zfs_deadman_synctime_ms.
452 452 * If the zfs_deadman_enabled flag is set then it inspects all vdev queues
453 453 * looking for potentially hung I/Os.
454 454 */
455 455 void
456 456 spa_deadman(void *arg)
457 457 {
458 458 spa_t *spa = arg;
459 459
460 + /*
461 + * Disable the deadman timer if the pool is suspended.
462 + */
463 + if (spa_suspended(spa)) {
464 + VERIFY(cyclic_reprogram(spa->spa_deadman_cycid, CY_INFINITY));
465 + return;
466 + }
467 +
460 468 zfs_dbgmsg("slow spa_sync: started %llu seconds ago, calls %llu",
461 469 (gethrtime() - spa->spa_sync_starttime) / NANOSEC,
462 470 ++spa->spa_deadman_calls);
463 471 if (zfs_deadman_enabled)
464 472 vdev_deadman(spa->spa_root_vdev);
465 473 }
466 474
467 475 /*
468 476 * Create an uninitialized spa_t with the given name. Requires
469 477 * spa_namespace_lock. The caller must ensure that the spa_t doesn't already
470 478 * exist by calling spa_lookup() first.
471 479 */
472 480 spa_t *
473 481 spa_add(const char *name, nvlist_t *config, const char *altroot)
474 482 {
475 483 spa_t *spa;
476 484 spa_config_dirent_t *dp;
477 485 cyc_handler_t hdlr;
478 486 cyc_time_t when;
479 487
480 488 ASSERT(MUTEX_HELD(&spa_namespace_lock));
481 489
482 490 spa = kmem_zalloc(sizeof (spa_t), KM_SLEEP);
483 491
484 492 mutex_init(&spa->spa_async_lock, NULL, MUTEX_DEFAULT, NULL);
485 493 mutex_init(&spa->spa_errlist_lock, NULL, MUTEX_DEFAULT, NULL);
486 494 mutex_init(&spa->spa_errlog_lock, NULL, MUTEX_DEFAULT, NULL);
487 495 mutex_init(&spa->spa_history_lock, NULL, MUTEX_DEFAULT, NULL);
488 496 mutex_init(&spa->spa_proc_lock, NULL, MUTEX_DEFAULT, NULL);
489 497 mutex_init(&spa->spa_props_lock, NULL, MUTEX_DEFAULT, NULL);
490 498 mutex_init(&spa->spa_scrub_lock, NULL, MUTEX_DEFAULT, NULL);
491 499 mutex_init(&spa->spa_suspend_lock, NULL, MUTEX_DEFAULT, NULL);
492 500 mutex_init(&spa->spa_vdev_top_lock, NULL, MUTEX_DEFAULT, NULL);
493 501 mutex_init(&spa->spa_iokstat_lock, NULL, MUTEX_DEFAULT, NULL);
494 502
495 503 cv_init(&spa->spa_async_cv, NULL, CV_DEFAULT, NULL);
496 504 cv_init(&spa->spa_proc_cv, NULL, CV_DEFAULT, NULL);
497 505 cv_init(&spa->spa_scrub_io_cv, NULL, CV_DEFAULT, NULL);
498 506 cv_init(&spa->spa_suspend_cv, NULL, CV_DEFAULT, NULL);
499 507
500 508 for (int t = 0; t < TXG_SIZE; t++)
501 509 bplist_create(&spa->spa_free_bplist[t]);
502 510
503 511 (void) strlcpy(spa->spa_name, name, sizeof (spa->spa_name));
504 512 spa->spa_state = POOL_STATE_UNINITIALIZED;
505 513 spa->spa_freeze_txg = UINT64_MAX;
506 514 spa->spa_final_txg = UINT64_MAX;
507 515 spa->spa_load_max_txg = UINT64_MAX;
508 516 spa->spa_proc = &p0;
509 517 spa->spa_proc_state = SPA_PROC_NONE;
510 518
511 519 hdlr.cyh_func = spa_deadman;
512 520 hdlr.cyh_arg = spa;
513 521 hdlr.cyh_level = CY_LOW_LEVEL;
514 522
515 523 spa->spa_deadman_synctime = MSEC2NSEC(zfs_deadman_synctime_ms);
516 524
517 525 /*
518 526 * This determines how often we need to check for hung I/Os after
519 527 * the cyclic has already fired. Since checking for hung I/Os is
520 528 * an expensive operation we don't want to check too frequently.
521 529 * Instead wait for 5 seconds before checking again.
522 530 */
523 531 when.cyt_interval = MSEC2NSEC(zfs_deadman_checktime_ms);
524 532 when.cyt_when = CY_INFINITY;
525 533 mutex_enter(&cpu_lock);
526 534 spa->spa_deadman_cycid = cyclic_add(&hdlr, &when);
527 535 mutex_exit(&cpu_lock);
528 536
529 537 refcount_create(&spa->spa_refcount);
530 538 spa_config_lock_init(spa);
531 539
532 540 avl_add(&spa_namespace_avl, spa);
533 541
534 542 /*
535 543 * Set the alternate root, if there is one.
536 544 */
537 545 if (altroot) {
538 546 spa->spa_root = spa_strdup(altroot);
539 547 spa_active_count++;
540 548 }
541 549
542 550 /*
543 551 * Every pool starts with the default cachefile
544 552 */
545 553 list_create(&spa->spa_config_list, sizeof (spa_config_dirent_t),
546 554 offsetof(spa_config_dirent_t, scd_link));
547 555
548 556 dp = kmem_zalloc(sizeof (spa_config_dirent_t), KM_SLEEP);
549 557 dp->scd_path = altroot ? NULL : spa_strdup(spa_config_path);
550 558 list_insert_head(&spa->spa_config_list, dp);
551 559
552 560 VERIFY(nvlist_alloc(&spa->spa_load_info, NV_UNIQUE_NAME,
553 561 KM_SLEEP) == 0);
554 562
555 563 if (config != NULL) {
556 564 nvlist_t *features;
557 565
558 566 if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_FEATURES_FOR_READ,
559 567 &features) == 0) {
560 568 VERIFY(nvlist_dup(features, &spa->spa_label_features,
561 569 0) == 0);
562 570 }
563 571
564 572 VERIFY(nvlist_dup(config, &spa->spa_config, 0) == 0);
565 573 }
566 574
567 575 if (spa->spa_label_features == NULL) {
568 576 VERIFY(nvlist_alloc(&spa->spa_label_features, NV_UNIQUE_NAME,
569 577 KM_SLEEP) == 0);
570 578 }
571 579
572 580 spa->spa_iokstat = kstat_create("zfs", 0, name,
573 581 "disk", KSTAT_TYPE_IO, 1, 0);
574 582 if (spa->spa_iokstat) {
575 583 spa->spa_iokstat->ks_lock = &spa->spa_iokstat_lock;
576 584 kstat_install(spa->spa_iokstat);
577 585 }
578 586
579 587 spa->spa_debug = ((zfs_flags & ZFS_DEBUG_SPA) != 0);
580 588
581 589 return (spa);
582 590 }
583 591
584 592 /*
585 593 * Removes a spa_t from the namespace, freeing up any memory used. Requires
586 594 * spa_namespace_lock. This is called only after the spa_t has been closed and
587 595 * deactivated.
588 596 */
589 597 void
590 598 spa_remove(spa_t *spa)
591 599 {
592 600 spa_config_dirent_t *dp;
593 601
594 602 ASSERT(MUTEX_HELD(&spa_namespace_lock));
595 603 ASSERT(spa->spa_state == POOL_STATE_UNINITIALIZED);
596 604
597 605 nvlist_free(spa->spa_config_splitting);
598 606
599 607 avl_remove(&spa_namespace_avl, spa);
600 608 cv_broadcast(&spa_namespace_cv);
601 609
602 610 if (spa->spa_root) {
603 611 spa_strfree(spa->spa_root);
604 612 spa_active_count--;
605 613 }
606 614
607 615 while ((dp = list_head(&spa->spa_config_list)) != NULL) {
608 616 list_remove(&spa->spa_config_list, dp);
609 617 if (dp->scd_path != NULL)
610 618 spa_strfree(dp->scd_path);
611 619 kmem_free(dp, sizeof (spa_config_dirent_t));
612 620 }
613 621
614 622 list_destroy(&spa->spa_config_list);
615 623
616 624 nvlist_free(spa->spa_label_features);
617 625 nvlist_free(spa->spa_load_info);
618 626 spa_config_set(spa, NULL);
619 627
620 628 mutex_enter(&cpu_lock);
621 629 if (spa->spa_deadman_cycid != CYCLIC_NONE)
622 630 cyclic_remove(spa->spa_deadman_cycid);
623 631 mutex_exit(&cpu_lock);
624 632 spa->spa_deadman_cycid = CYCLIC_NONE;
625 633
626 634 refcount_destroy(&spa->spa_refcount);
627 635
628 636 spa_config_lock_destroy(spa);
629 637
630 638 kstat_delete(spa->spa_iokstat);
631 639 spa->spa_iokstat = NULL;
632 640
633 641 for (int t = 0; t < TXG_SIZE; t++)
634 642 bplist_destroy(&spa->spa_free_bplist[t]);
635 643
636 644 cv_destroy(&spa->spa_async_cv);
637 645 cv_destroy(&spa->spa_proc_cv);
638 646 cv_destroy(&spa->spa_scrub_io_cv);
639 647 cv_destroy(&spa->spa_suspend_cv);
640 648
641 649 mutex_destroy(&spa->spa_async_lock);
642 650 mutex_destroy(&spa->spa_errlist_lock);
643 651 mutex_destroy(&spa->spa_errlog_lock);
644 652 mutex_destroy(&spa->spa_history_lock);
645 653 mutex_destroy(&spa->spa_proc_lock);
646 654 mutex_destroy(&spa->spa_props_lock);
647 655 mutex_destroy(&spa->spa_scrub_lock);
648 656 mutex_destroy(&spa->spa_suspend_lock);
649 657 mutex_destroy(&spa->spa_vdev_top_lock);
650 658 mutex_destroy(&spa->spa_iokstat_lock);
651 659
652 660 kmem_free(spa, sizeof (spa_t));
653 661 }
654 662
655 663 /*
656 664 * Given a pool, return the next pool in the namespace, or NULL if there is
657 665 * none. If 'prev' is NULL, return the first pool.
658 666 */
659 667 spa_t *
660 668 spa_next(spa_t *prev)
661 669 {
662 670 ASSERT(MUTEX_HELD(&spa_namespace_lock));
663 671
664 672 if (prev)
665 673 return (AVL_NEXT(&spa_namespace_avl, prev));
666 674 else
667 675 return (avl_first(&spa_namespace_avl));
668 676 }
669 677
670 678 /*
671 679 * ==========================================================================
672 680 * SPA refcount functions
673 681 * ==========================================================================
674 682 */
675 683
676 684 /*
677 685 * Add a reference to the given spa_t. Must have at least one reference, or
678 686 * have the namespace lock held.
679 687 */
680 688 void
681 689 spa_open_ref(spa_t *spa, void *tag)
682 690 {
683 691 ASSERT(refcount_count(&spa->spa_refcount) >= spa->spa_minref ||
684 692 MUTEX_HELD(&spa_namespace_lock));
685 693 (void) refcount_add(&spa->spa_refcount, tag);
686 694 }
687 695
688 696 /*
689 697 * Remove a reference to the given spa_t. Must have at least one reference, or
690 698 * have the namespace lock held.
691 699 */
692 700 void
693 701 spa_close(spa_t *spa, void *tag)
694 702 {
695 703 ASSERT(refcount_count(&spa->spa_refcount) > spa->spa_minref ||
696 704 MUTEX_HELD(&spa_namespace_lock));
697 705 (void) refcount_remove(&spa->spa_refcount, tag);
698 706 }
699 707
700 708 /*
701 709 * Check to see if the spa refcount is zero. Must be called with
702 710 * spa_namespace_lock held. We really compare against spa_minref, which is the
703 711 * number of references acquired when opening a pool
704 712 */
705 713 boolean_t
706 714 spa_refcount_zero(spa_t *spa)
707 715 {
708 716 ASSERT(MUTEX_HELD(&spa_namespace_lock));
709 717
710 718 return (refcount_count(&spa->spa_refcount) == spa->spa_minref);
711 719 }
712 720
713 721 /*
714 722 * ==========================================================================
715 723 * SPA spare and l2cache tracking
716 724 * ==========================================================================
717 725 */
718 726
719 727 /*
720 728 * Hot spares and cache devices are tracked using the same code below,
721 729 * for 'auxiliary' devices.
722 730 */
723 731
724 732 typedef struct spa_aux {
725 733 uint64_t aux_guid;
726 734 uint64_t aux_pool;
727 735 avl_node_t aux_avl;
728 736 int aux_count;
729 737 } spa_aux_t;
730 738
731 739 static int
732 740 spa_aux_compare(const void *a, const void *b)
733 741 {
734 742 const spa_aux_t *sa = a;
735 743 const spa_aux_t *sb = b;
736 744
737 745 if (sa->aux_guid < sb->aux_guid)
738 746 return (-1);
739 747 else if (sa->aux_guid > sb->aux_guid)
740 748 return (1);
741 749 else
742 750 return (0);
743 751 }
744 752
745 753 void
746 754 spa_aux_add(vdev_t *vd, avl_tree_t *avl)
747 755 {
748 756 avl_index_t where;
749 757 spa_aux_t search;
750 758 spa_aux_t *aux;
751 759
752 760 search.aux_guid = vd->vdev_guid;
753 761 if ((aux = avl_find(avl, &search, &where)) != NULL) {
754 762 aux->aux_count++;
755 763 } else {
756 764 aux = kmem_zalloc(sizeof (spa_aux_t), KM_SLEEP);
757 765 aux->aux_guid = vd->vdev_guid;
758 766 aux->aux_count = 1;
759 767 avl_insert(avl, aux, where);
760 768 }
761 769 }
762 770
763 771 void
764 772 spa_aux_remove(vdev_t *vd, avl_tree_t *avl)
765 773 {
766 774 spa_aux_t search;
767 775 spa_aux_t *aux;
768 776 avl_index_t where;
769 777
770 778 search.aux_guid = vd->vdev_guid;
771 779 aux = avl_find(avl, &search, &where);
772 780
773 781 ASSERT(aux != NULL);
774 782
775 783 if (--aux->aux_count == 0) {
776 784 avl_remove(avl, aux);
777 785 kmem_free(aux, sizeof (spa_aux_t));
778 786 } else if (aux->aux_pool == spa_guid(vd->vdev_spa)) {
779 787 aux->aux_pool = 0ULL;
780 788 }
781 789 }
782 790
783 791 boolean_t
784 792 spa_aux_exists(uint64_t guid, uint64_t *pool, int *refcnt, avl_tree_t *avl)
785 793 {
786 794 spa_aux_t search, *found;
787 795
788 796 search.aux_guid = guid;
789 797 found = avl_find(avl, &search, NULL);
790 798
791 799 if (pool) {
792 800 if (found)
793 801 *pool = found->aux_pool;
794 802 else
795 803 *pool = 0ULL;
796 804 }
797 805
798 806 if (refcnt) {
799 807 if (found)
800 808 *refcnt = found->aux_count;
801 809 else
802 810 *refcnt = 0;
803 811 }
804 812
805 813 return (found != NULL);
806 814 }
807 815
808 816 void
809 817 spa_aux_activate(vdev_t *vd, avl_tree_t *avl)
810 818 {
811 819 spa_aux_t search, *found;
812 820 avl_index_t where;
813 821
814 822 search.aux_guid = vd->vdev_guid;
815 823 found = avl_find(avl, &search, &where);
816 824 ASSERT(found != NULL);
817 825 ASSERT(found->aux_pool == 0ULL);
818 826
819 827 found->aux_pool = spa_guid(vd->vdev_spa);
820 828 }
821 829
822 830 /*
823 831 * Spares are tracked globally due to the following constraints:
824 832 *
825 833 * - A spare may be part of multiple pools.
826 834 * - A spare may be added to a pool even if it's actively in use within
827 835 * another pool.
828 836 * - A spare in use in any pool can only be the source of a replacement if
829 837 * the target is a spare in the same pool.
830 838 *
831 839 * We keep track of all spares on the system through the use of a reference
832 840 * counted AVL tree. When a vdev is added as a spare, or used as a replacement
833 841 * spare, then we bump the reference count in the AVL tree. In addition, we set
834 842 * the 'vdev_isspare' member to indicate that the device is a spare (active or
835 843 * inactive). When a spare is made active (used to replace a device in the
836 844 * pool), we also keep track of which pool its been made a part of.
837 845 *
838 846 * The 'spa_spare_lock' protects the AVL tree. These functions are normally
839 847 * called under the spa_namespace lock as part of vdev reconfiguration. The
840 848 * separate spare lock exists for the status query path, which does not need to
841 849 * be completely consistent with respect to other vdev configuration changes.
842 850 */
843 851
844 852 static int
845 853 spa_spare_compare(const void *a, const void *b)
846 854 {
847 855 return (spa_aux_compare(a, b));
848 856 }
849 857
850 858 void
851 859 spa_spare_add(vdev_t *vd)
852 860 {
853 861 mutex_enter(&spa_spare_lock);
854 862 ASSERT(!vd->vdev_isspare);
855 863 spa_aux_add(vd, &spa_spare_avl);
856 864 vd->vdev_isspare = B_TRUE;
857 865 mutex_exit(&spa_spare_lock);
858 866 }
859 867
860 868 void
861 869 spa_spare_remove(vdev_t *vd)
862 870 {
863 871 mutex_enter(&spa_spare_lock);
864 872 ASSERT(vd->vdev_isspare);
865 873 spa_aux_remove(vd, &spa_spare_avl);
866 874 vd->vdev_isspare = B_FALSE;
867 875 mutex_exit(&spa_spare_lock);
868 876 }
869 877
870 878 boolean_t
871 879 spa_spare_exists(uint64_t guid, uint64_t *pool, int *refcnt)
872 880 {
873 881 boolean_t found;
874 882
875 883 mutex_enter(&spa_spare_lock);
876 884 found = spa_aux_exists(guid, pool, refcnt, &spa_spare_avl);
877 885 mutex_exit(&spa_spare_lock);
878 886
879 887 return (found);
880 888 }
881 889
882 890 void
883 891 spa_spare_activate(vdev_t *vd)
884 892 {
885 893 mutex_enter(&spa_spare_lock);
886 894 ASSERT(vd->vdev_isspare);
887 895 spa_aux_activate(vd, &spa_spare_avl);
888 896 mutex_exit(&spa_spare_lock);
889 897 }
890 898
891 899 /*
892 900 * Level 2 ARC devices are tracked globally for the same reasons as spares.
893 901 * Cache devices currently only support one pool per cache device, and so
894 902 * for these devices the aux reference count is currently unused beyond 1.
895 903 */
896 904
897 905 static int
898 906 spa_l2cache_compare(const void *a, const void *b)
899 907 {
900 908 return (spa_aux_compare(a, b));
901 909 }
902 910
903 911 void
904 912 spa_l2cache_add(vdev_t *vd)
905 913 {
906 914 mutex_enter(&spa_l2cache_lock);
907 915 ASSERT(!vd->vdev_isl2cache);
908 916 spa_aux_add(vd, &spa_l2cache_avl);
909 917 vd->vdev_isl2cache = B_TRUE;
910 918 mutex_exit(&spa_l2cache_lock);
911 919 }
912 920
913 921 void
914 922 spa_l2cache_remove(vdev_t *vd)
915 923 {
916 924 mutex_enter(&spa_l2cache_lock);
917 925 ASSERT(vd->vdev_isl2cache);
918 926 spa_aux_remove(vd, &spa_l2cache_avl);
919 927 vd->vdev_isl2cache = B_FALSE;
920 928 mutex_exit(&spa_l2cache_lock);
921 929 }
922 930
923 931 boolean_t
924 932 spa_l2cache_exists(uint64_t guid, uint64_t *pool)
925 933 {
926 934 boolean_t found;
927 935
928 936 mutex_enter(&spa_l2cache_lock);
929 937 found = spa_aux_exists(guid, pool, NULL, &spa_l2cache_avl);
930 938 mutex_exit(&spa_l2cache_lock);
931 939
932 940 return (found);
933 941 }
934 942
935 943 void
936 944 spa_l2cache_activate(vdev_t *vd)
937 945 {
938 946 mutex_enter(&spa_l2cache_lock);
939 947 ASSERT(vd->vdev_isl2cache);
940 948 spa_aux_activate(vd, &spa_l2cache_avl);
941 949 mutex_exit(&spa_l2cache_lock);
942 950 }
943 951
944 952 /*
945 953 * ==========================================================================
946 954 * SPA vdev locking
947 955 * ==========================================================================
948 956 */
949 957
950 958 /*
951 959 * Lock the given spa_t for the purpose of adding or removing a vdev.
952 960 * Grabs the global spa_namespace_lock plus the spa config lock for writing.
953 961 * It returns the next transaction group for the spa_t.
954 962 */
955 963 uint64_t
956 964 spa_vdev_enter(spa_t *spa)
957 965 {
958 966 mutex_enter(&spa->spa_vdev_top_lock);
959 967 mutex_enter(&spa_namespace_lock);
960 968 return (spa_vdev_config_enter(spa));
961 969 }
962 970
963 971 /*
964 972 * Internal implementation for spa_vdev_enter(). Used when a vdev
965 973 * operation requires multiple syncs (i.e. removing a device) while
966 974 * keeping the spa_namespace_lock held.
967 975 */
968 976 uint64_t
969 977 spa_vdev_config_enter(spa_t *spa)
970 978 {
971 979 ASSERT(MUTEX_HELD(&spa_namespace_lock));
972 980
973 981 spa_config_enter(spa, SCL_ALL, spa, RW_WRITER);
974 982
975 983 return (spa_last_synced_txg(spa) + 1);
976 984 }
977 985
978 986 /*
979 987 * Used in combination with spa_vdev_config_enter() to allow the syncing
980 988 * of multiple transactions without releasing the spa_namespace_lock.
981 989 */
982 990 void
983 991 spa_vdev_config_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error, char *tag)
984 992 {
985 993 ASSERT(MUTEX_HELD(&spa_namespace_lock));
986 994
987 995 int config_changed = B_FALSE;
988 996
989 997 ASSERT(txg > spa_last_synced_txg(spa));
990 998
991 999 spa->spa_pending_vdev = NULL;
992 1000
993 1001 /*
994 1002 * Reassess the DTLs.
995 1003 */
996 1004 vdev_dtl_reassess(spa->spa_root_vdev, 0, 0, B_FALSE);
997 1005
998 1006 if (error == 0 && !list_is_empty(&spa->spa_config_dirty_list)) {
999 1007 config_changed = B_TRUE;
1000 1008 spa->spa_config_generation++;
1001 1009 }
1002 1010
1003 1011 /*
1004 1012 * Verify the metaslab classes.
1005 1013 */
1006 1014 ASSERT(metaslab_class_validate(spa_normal_class(spa)) == 0);
1007 1015 ASSERT(metaslab_class_validate(spa_log_class(spa)) == 0);
1008 1016
1009 1017 spa_config_exit(spa, SCL_ALL, spa);
1010 1018
1011 1019 /*
1012 1020 * Panic the system if the specified tag requires it. This
1013 1021 * is useful for ensuring that configurations are updated
1014 1022 * transactionally.
1015 1023 */
1016 1024 if (zio_injection_enabled)
1017 1025 zio_handle_panic_injection(spa, tag, 0);
↓ open down ↓ |
548 lines elided |
↑ open up ↑ |
1018 1026
1019 1027 /*
1020 1028 * Note: this txg_wait_synced() is important because it ensures
1021 1029 * that there won't be more than one config change per txg.
1022 1030 * This allows us to use the txg as the generation number.
1023 1031 */
1024 1032 if (error == 0)
1025 1033 txg_wait_synced(spa->spa_dsl_pool, txg);
1026 1034
1027 1035 if (vd != NULL) {
1028 - ASSERT(!vd->vdev_detached || vd->vdev_dtl_smo.smo_object == 0);
1036 + ASSERT(!vd->vdev_detached || vd->vdev_dtl_sm == NULL);
1029 1037 spa_config_enter(spa, SCL_ALL, spa, RW_WRITER);
1030 1038 vdev_free(vd);
1031 1039 spa_config_exit(spa, SCL_ALL, spa);
1032 1040 }
1033 1041
1034 1042 /*
1035 1043 * If the config changed, update the config cache.
1036 1044 */
1037 1045 if (config_changed)
1038 1046 spa_config_sync(spa, B_FALSE, B_TRUE);
1039 1047 }
1040 1048
1041 1049 /*
1042 1050 * Unlock the spa_t after adding or removing a vdev. Besides undoing the
1043 1051 * locking of spa_vdev_enter(), we also want make sure the transactions have
1044 1052 * synced to disk, and then update the global configuration cache with the new
1045 1053 * information.
1046 1054 */
1047 1055 int
1048 1056 spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error)
1049 1057 {
1050 1058 spa_vdev_config_exit(spa, vd, txg, error, FTAG);
1051 1059 mutex_exit(&spa_namespace_lock);
1052 1060 mutex_exit(&spa->spa_vdev_top_lock);
1053 1061
1054 1062 return (error);
1055 1063 }
1056 1064
1057 1065 /*
1058 1066 * Lock the given spa_t for the purpose of changing vdev state.
1059 1067 */
1060 1068 void
1061 1069 spa_vdev_state_enter(spa_t *spa, int oplocks)
1062 1070 {
1063 1071 int locks = SCL_STATE_ALL | oplocks;
1064 1072
1065 1073 /*
1066 1074 * Root pools may need to read of the underlying devfs filesystem
1067 1075 * when opening up a vdev. Unfortunately if we're holding the
1068 1076 * SCL_ZIO lock it will result in a deadlock when we try to issue
1069 1077 * the read from the root filesystem. Instead we "prefetch"
1070 1078 * the associated vnodes that we need prior to opening the
1071 1079 * underlying devices and cache them so that we can prevent
1072 1080 * any I/O when we are doing the actual open.
1073 1081 */
1074 1082 if (spa_is_root(spa)) {
1075 1083 int low = locks & ~(SCL_ZIO - 1);
1076 1084 int high = locks & ~low;
1077 1085
1078 1086 spa_config_enter(spa, high, spa, RW_WRITER);
1079 1087 vdev_hold(spa->spa_root_vdev);
1080 1088 spa_config_enter(spa, low, spa, RW_WRITER);
1081 1089 } else {
1082 1090 spa_config_enter(spa, locks, spa, RW_WRITER);
1083 1091 }
1084 1092 spa->spa_vdev_locks = locks;
1085 1093 }
1086 1094
1087 1095 int
1088 1096 spa_vdev_state_exit(spa_t *spa, vdev_t *vd, int error)
1089 1097 {
1090 1098 boolean_t config_changed = B_FALSE;
1091 1099
1092 1100 if (vd != NULL || error == 0)
1093 1101 vdev_dtl_reassess(vd ? vd->vdev_top : spa->spa_root_vdev,
1094 1102 0, 0, B_FALSE);
1095 1103
1096 1104 if (vd != NULL) {
1097 1105 vdev_state_dirty(vd->vdev_top);
1098 1106 config_changed = B_TRUE;
1099 1107 spa->spa_config_generation++;
1100 1108 }
1101 1109
1102 1110 if (spa_is_root(spa))
1103 1111 vdev_rele(spa->spa_root_vdev);
1104 1112
1105 1113 ASSERT3U(spa->spa_vdev_locks, >=, SCL_STATE_ALL);
1106 1114 spa_config_exit(spa, spa->spa_vdev_locks, spa);
1107 1115
1108 1116 /*
1109 1117 * If anything changed, wait for it to sync. This ensures that,
1110 1118 * from the system administrator's perspective, zpool(1M) commands
1111 1119 * are synchronous. This is important for things like zpool offline:
1112 1120 * when the command completes, you expect no further I/O from ZFS.
1113 1121 */
1114 1122 if (vd != NULL)
1115 1123 txg_wait_synced(spa->spa_dsl_pool, 0);
1116 1124
1117 1125 /*
1118 1126 * If the config changed, update the config cache.
1119 1127 */
1120 1128 if (config_changed) {
1121 1129 mutex_enter(&spa_namespace_lock);
1122 1130 spa_config_sync(spa, B_FALSE, B_TRUE);
1123 1131 mutex_exit(&spa_namespace_lock);
1124 1132 }
1125 1133
1126 1134 return (error);
1127 1135 }
1128 1136
1129 1137 /*
1130 1138 * ==========================================================================
1131 1139 * Miscellaneous functions
1132 1140 * ==========================================================================
1133 1141 */
1134 1142
1135 1143 void
1136 1144 spa_activate_mos_feature(spa_t *spa, const char *feature)
1137 1145 {
1138 1146 (void) nvlist_add_boolean(spa->spa_label_features, feature);
1139 1147 vdev_config_dirty(spa->spa_root_vdev);
1140 1148 }
1141 1149
1142 1150 void
1143 1151 spa_deactivate_mos_feature(spa_t *spa, const char *feature)
1144 1152 {
1145 1153 (void) nvlist_remove_all(spa->spa_label_features, feature);
1146 1154 vdev_config_dirty(spa->spa_root_vdev);
1147 1155 }
1148 1156
1149 1157 /*
1150 1158 * Rename a spa_t.
1151 1159 */
1152 1160 int
1153 1161 spa_rename(const char *name, const char *newname)
1154 1162 {
1155 1163 spa_t *spa;
1156 1164 int err;
1157 1165
1158 1166 /*
1159 1167 * Lookup the spa_t and grab the config lock for writing. We need to
1160 1168 * actually open the pool so that we can sync out the necessary labels.
1161 1169 * It's OK to call spa_open() with the namespace lock held because we
1162 1170 * allow recursive calls for other reasons.
1163 1171 */
1164 1172 mutex_enter(&spa_namespace_lock);
1165 1173 if ((err = spa_open(name, &spa, FTAG)) != 0) {
1166 1174 mutex_exit(&spa_namespace_lock);
1167 1175 return (err);
1168 1176 }
1169 1177
1170 1178 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
1171 1179
1172 1180 avl_remove(&spa_namespace_avl, spa);
1173 1181 (void) strlcpy(spa->spa_name, newname, sizeof (spa->spa_name));
1174 1182 avl_add(&spa_namespace_avl, spa);
1175 1183
1176 1184 /*
1177 1185 * Sync all labels to disk with the new names by marking the root vdev
1178 1186 * dirty and waiting for it to sync. It will pick up the new pool name
1179 1187 * during the sync.
1180 1188 */
1181 1189 vdev_config_dirty(spa->spa_root_vdev);
1182 1190
1183 1191 spa_config_exit(spa, SCL_ALL, FTAG);
1184 1192
1185 1193 txg_wait_synced(spa->spa_dsl_pool, 0);
1186 1194
1187 1195 /*
1188 1196 * Sync the updated config cache.
1189 1197 */
1190 1198 spa_config_sync(spa, B_FALSE, B_TRUE);
1191 1199
1192 1200 spa_close(spa, FTAG);
1193 1201
1194 1202 mutex_exit(&spa_namespace_lock);
1195 1203
1196 1204 return (0);
1197 1205 }
1198 1206
1199 1207 /*
1200 1208 * Return the spa_t associated with given pool_guid, if it exists. If
1201 1209 * device_guid is non-zero, determine whether the pool exists *and* contains
1202 1210 * a device with the specified device_guid.
1203 1211 */
1204 1212 spa_t *
1205 1213 spa_by_guid(uint64_t pool_guid, uint64_t device_guid)
1206 1214 {
1207 1215 spa_t *spa;
1208 1216 avl_tree_t *t = &spa_namespace_avl;
1209 1217
1210 1218 ASSERT(MUTEX_HELD(&spa_namespace_lock));
1211 1219
1212 1220 for (spa = avl_first(t); spa != NULL; spa = AVL_NEXT(t, spa)) {
1213 1221 if (spa->spa_state == POOL_STATE_UNINITIALIZED)
1214 1222 continue;
1215 1223 if (spa->spa_root_vdev == NULL)
1216 1224 continue;
1217 1225 if (spa_guid(spa) == pool_guid) {
1218 1226 if (device_guid == 0)
1219 1227 break;
1220 1228
1221 1229 if (vdev_lookup_by_guid(spa->spa_root_vdev,
1222 1230 device_guid) != NULL)
1223 1231 break;
1224 1232
1225 1233 /*
1226 1234 * Check any devices we may be in the process of adding.
1227 1235 */
1228 1236 if (spa->spa_pending_vdev) {
1229 1237 if (vdev_lookup_by_guid(spa->spa_pending_vdev,
1230 1238 device_guid) != NULL)
1231 1239 break;
1232 1240 }
1233 1241 }
1234 1242 }
1235 1243
1236 1244 return (spa);
1237 1245 }
1238 1246
1239 1247 /*
1240 1248 * Determine whether a pool with the given pool_guid exists.
1241 1249 */
1242 1250 boolean_t
1243 1251 spa_guid_exists(uint64_t pool_guid, uint64_t device_guid)
1244 1252 {
1245 1253 return (spa_by_guid(pool_guid, device_guid) != NULL);
1246 1254 }
1247 1255
1248 1256 char *
1249 1257 spa_strdup(const char *s)
1250 1258 {
1251 1259 size_t len;
1252 1260 char *new;
1253 1261
1254 1262 len = strlen(s);
1255 1263 new = kmem_alloc(len + 1, KM_SLEEP);
1256 1264 bcopy(s, new, len);
1257 1265 new[len] = '\0';
1258 1266
1259 1267 return (new);
1260 1268 }
1261 1269
1262 1270 void
1263 1271 spa_strfree(char *s)
1264 1272 {
1265 1273 kmem_free(s, strlen(s) + 1);
1266 1274 }
1267 1275
1268 1276 uint64_t
1269 1277 spa_get_random(uint64_t range)
1270 1278 {
1271 1279 uint64_t r;
1272 1280
1273 1281 ASSERT(range != 0);
1274 1282
1275 1283 (void) random_get_pseudo_bytes((void *)&r, sizeof (uint64_t));
1276 1284
1277 1285 return (r % range);
1278 1286 }
1279 1287
1280 1288 uint64_t
1281 1289 spa_generate_guid(spa_t *spa)
1282 1290 {
1283 1291 uint64_t guid = spa_get_random(-1ULL);
1284 1292
1285 1293 if (spa != NULL) {
1286 1294 while (guid == 0 || spa_guid_exists(spa_guid(spa), guid))
1287 1295 guid = spa_get_random(-1ULL);
1288 1296 } else {
1289 1297 while (guid == 0 || spa_guid_exists(guid, 0))
1290 1298 guid = spa_get_random(-1ULL);
1291 1299 }
1292 1300
1293 1301 return (guid);
1294 1302 }
1295 1303
1296 1304 void
1297 1305 sprintf_blkptr(char *buf, const blkptr_t *bp)
1298 1306 {
1299 1307 char type[256];
1300 1308 char *checksum = NULL;
1301 1309 char *compress = NULL;
1302 1310
1303 1311 if (bp != NULL) {
1304 1312 if (BP_GET_TYPE(bp) & DMU_OT_NEWTYPE) {
1305 1313 dmu_object_byteswap_t bswap =
1306 1314 DMU_OT_BYTESWAP(BP_GET_TYPE(bp));
1307 1315 (void) snprintf(type, sizeof (type), "bswap %s %s",
1308 1316 DMU_OT_IS_METADATA(BP_GET_TYPE(bp)) ?
1309 1317 "metadata" : "data",
1310 1318 dmu_ot_byteswap[bswap].ob_name);
1311 1319 } else {
1312 1320 (void) strlcpy(type, dmu_ot[BP_GET_TYPE(bp)].ot_name,
1313 1321 sizeof (type));
1314 1322 }
1315 1323 checksum = zio_checksum_table[BP_GET_CHECKSUM(bp)].ci_name;
1316 1324 compress = zio_compress_table[BP_GET_COMPRESS(bp)].ci_name;
1317 1325 }
1318 1326
1319 1327 SPRINTF_BLKPTR(snprintf, ' ', buf, bp, type, checksum, compress);
1320 1328 }
1321 1329
1322 1330 void
1323 1331 spa_freeze(spa_t *spa)
1324 1332 {
1325 1333 uint64_t freeze_txg = 0;
1326 1334
1327 1335 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
1328 1336 if (spa->spa_freeze_txg == UINT64_MAX) {
1329 1337 freeze_txg = spa_last_synced_txg(spa) + TXG_SIZE;
1330 1338 spa->spa_freeze_txg = freeze_txg;
1331 1339 }
1332 1340 spa_config_exit(spa, SCL_ALL, FTAG);
1333 1341 if (freeze_txg != 0)
1334 1342 txg_wait_synced(spa_get_dsl(spa), freeze_txg);
1335 1343 }
1336 1344
1337 1345 void
1338 1346 zfs_panic_recover(const char *fmt, ...)
1339 1347 {
1340 1348 va_list adx;
1341 1349
1342 1350 va_start(adx, fmt);
1343 1351 vcmn_err(zfs_recover ? CE_WARN : CE_PANIC, fmt, adx);
1344 1352 va_end(adx);
1345 1353 }
1346 1354
1347 1355 /*
1348 1356 * This is a stripped-down version of strtoull, suitable only for converting
1349 1357 * lowercase hexadecimal numbers that don't overflow.
1350 1358 */
1351 1359 uint64_t
1352 1360 strtonum(const char *str, char **nptr)
1353 1361 {
1354 1362 uint64_t val = 0;
1355 1363 char c;
1356 1364 int digit;
1357 1365
1358 1366 while ((c = *str) != '\0') {
1359 1367 if (c >= '0' && c <= '9')
1360 1368 digit = c - '0';
1361 1369 else if (c >= 'a' && c <= 'f')
1362 1370 digit = 10 + c - 'a';
1363 1371 else
1364 1372 break;
1365 1373
1366 1374 val *= 16;
1367 1375 val += digit;
1368 1376
1369 1377 str++;
1370 1378 }
1371 1379
1372 1380 if (nptr)
1373 1381 *nptr = (char *)str;
1374 1382
1375 1383 return (val);
1376 1384 }
1377 1385
1378 1386 /*
1379 1387 * ==========================================================================
1380 1388 * Accessor functions
1381 1389 * ==========================================================================
1382 1390 */
1383 1391
1384 1392 boolean_t
1385 1393 spa_shutting_down(spa_t *spa)
1386 1394 {
1387 1395 return (spa->spa_async_suspended);
1388 1396 }
1389 1397
1390 1398 dsl_pool_t *
1391 1399 spa_get_dsl(spa_t *spa)
1392 1400 {
1393 1401 return (spa->spa_dsl_pool);
1394 1402 }
1395 1403
1396 1404 boolean_t
1397 1405 spa_is_initializing(spa_t *spa)
1398 1406 {
1399 1407 return (spa->spa_is_initializing);
1400 1408 }
1401 1409
1402 1410 blkptr_t *
1403 1411 spa_get_rootblkptr(spa_t *spa)
1404 1412 {
1405 1413 return (&spa->spa_ubsync.ub_rootbp);
1406 1414 }
1407 1415
1408 1416 void
1409 1417 spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp)
1410 1418 {
1411 1419 spa->spa_uberblock.ub_rootbp = *bp;
1412 1420 }
1413 1421
1414 1422 void
1415 1423 spa_altroot(spa_t *spa, char *buf, size_t buflen)
1416 1424 {
1417 1425 if (spa->spa_root == NULL)
1418 1426 buf[0] = '\0';
1419 1427 else
1420 1428 (void) strncpy(buf, spa->spa_root, buflen);
1421 1429 }
1422 1430
1423 1431 int
1424 1432 spa_sync_pass(spa_t *spa)
1425 1433 {
1426 1434 return (spa->spa_sync_pass);
1427 1435 }
1428 1436
1429 1437 char *
1430 1438 spa_name(spa_t *spa)
1431 1439 {
1432 1440 return (spa->spa_name);
1433 1441 }
1434 1442
1435 1443 uint64_t
1436 1444 spa_guid(spa_t *spa)
1437 1445 {
1438 1446 dsl_pool_t *dp = spa_get_dsl(spa);
1439 1447 uint64_t guid;
1440 1448
1441 1449 /*
1442 1450 * If we fail to parse the config during spa_load(), we can go through
1443 1451 * the error path (which posts an ereport) and end up here with no root
1444 1452 * vdev. We stash the original pool guid in 'spa_config_guid' to handle
1445 1453 * this case.
1446 1454 */
1447 1455 if (spa->spa_root_vdev == NULL)
1448 1456 return (spa->spa_config_guid);
1449 1457
1450 1458 guid = spa->spa_last_synced_guid != 0 ?
1451 1459 spa->spa_last_synced_guid : spa->spa_root_vdev->vdev_guid;
1452 1460
1453 1461 /*
1454 1462 * Return the most recently synced out guid unless we're
1455 1463 * in syncing context.
1456 1464 */
1457 1465 if (dp && dsl_pool_sync_context(dp))
1458 1466 return (spa->spa_root_vdev->vdev_guid);
1459 1467 else
1460 1468 return (guid);
1461 1469 }
1462 1470
1463 1471 uint64_t
1464 1472 spa_load_guid(spa_t *spa)
1465 1473 {
1466 1474 /*
1467 1475 * This is a GUID that exists solely as a reference for the
1468 1476 * purposes of the arc. It is generated at load time, and
1469 1477 * is never written to persistent storage.
1470 1478 */
1471 1479 return (spa->spa_load_guid);
1472 1480 }
1473 1481
1474 1482 uint64_t
1475 1483 spa_last_synced_txg(spa_t *spa)
1476 1484 {
1477 1485 return (spa->spa_ubsync.ub_txg);
1478 1486 }
1479 1487
1480 1488 uint64_t
1481 1489 spa_first_txg(spa_t *spa)
1482 1490 {
1483 1491 return (spa->spa_first_txg);
1484 1492 }
1485 1493
1486 1494 uint64_t
1487 1495 spa_syncing_txg(spa_t *spa)
1488 1496 {
1489 1497 return (spa->spa_syncing_txg);
1490 1498 }
1491 1499
1492 1500 pool_state_t
1493 1501 spa_state(spa_t *spa)
1494 1502 {
1495 1503 return (spa->spa_state);
1496 1504 }
1497 1505
1498 1506 spa_load_state_t
1499 1507 spa_load_state(spa_t *spa)
1500 1508 {
1501 1509 return (spa->spa_load_state);
1502 1510 }
1503 1511
1504 1512 uint64_t
1505 1513 spa_freeze_txg(spa_t *spa)
1506 1514 {
1507 1515 return (spa->spa_freeze_txg);
1508 1516 }
1509 1517
1510 1518 /* ARGSUSED */
1511 1519 uint64_t
1512 1520 spa_get_asize(spa_t *spa, uint64_t lsize)
1513 1521 {
1514 1522 return (lsize * spa_asize_inflation);
1515 1523 }
1516 1524
1517 1525 uint64_t
1518 1526 spa_get_dspace(spa_t *spa)
1519 1527 {
1520 1528 return (spa->spa_dspace);
1521 1529 }
1522 1530
1523 1531 void
1524 1532 spa_update_dspace(spa_t *spa)
1525 1533 {
1526 1534 spa->spa_dspace = metaslab_class_get_dspace(spa_normal_class(spa)) +
1527 1535 ddt_get_dedup_dspace(spa);
1528 1536 }
1529 1537
1530 1538 /*
1531 1539 * Return the failure mode that has been set to this pool. The default
1532 1540 * behavior will be to block all I/Os when a complete failure occurs.
1533 1541 */
1534 1542 uint8_t
1535 1543 spa_get_failmode(spa_t *spa)
1536 1544 {
1537 1545 return (spa->spa_failmode);
1538 1546 }
1539 1547
1540 1548 boolean_t
1541 1549 spa_suspended(spa_t *spa)
1542 1550 {
1543 1551 return (spa->spa_suspended);
1544 1552 }
1545 1553
1546 1554 uint64_t
1547 1555 spa_version(spa_t *spa)
1548 1556 {
1549 1557 return (spa->spa_ubsync.ub_version);
1550 1558 }
1551 1559
1552 1560 boolean_t
1553 1561 spa_deflate(spa_t *spa)
1554 1562 {
1555 1563 return (spa->spa_deflate);
1556 1564 }
1557 1565
1558 1566 metaslab_class_t *
1559 1567 spa_normal_class(spa_t *spa)
1560 1568 {
1561 1569 return (spa->spa_normal_class);
1562 1570 }
1563 1571
1564 1572 metaslab_class_t *
1565 1573 spa_log_class(spa_t *spa)
1566 1574 {
1567 1575 return (spa->spa_log_class);
1568 1576 }
1569 1577
1570 1578 int
1571 1579 spa_max_replication(spa_t *spa)
1572 1580 {
1573 1581 /*
1574 1582 * As of SPA_VERSION == SPA_VERSION_DITTO_BLOCKS, we are able to
1575 1583 * handle BPs with more than one DVA allocated. Set our max
1576 1584 * replication level accordingly.
1577 1585 */
1578 1586 if (spa_version(spa) < SPA_VERSION_DITTO_BLOCKS)
1579 1587 return (1);
1580 1588 return (MIN(SPA_DVAS_PER_BP, spa_max_replication_override));
1581 1589 }
1582 1590
1583 1591 int
1584 1592 spa_prev_software_version(spa_t *spa)
1585 1593 {
1586 1594 return (spa->spa_prev_software_version);
1587 1595 }
1588 1596
1589 1597 uint64_t
1590 1598 spa_deadman_synctime(spa_t *spa)
1591 1599 {
1592 1600 return (spa->spa_deadman_synctime);
1593 1601 }
1594 1602
1595 1603 uint64_t
1596 1604 dva_get_dsize_sync(spa_t *spa, const dva_t *dva)
1597 1605 {
1598 1606 uint64_t asize = DVA_GET_ASIZE(dva);
1599 1607 uint64_t dsize = asize;
1600 1608
1601 1609 ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
1602 1610
1603 1611 if (asize != 0 && spa->spa_deflate) {
1604 1612 vdev_t *vd = vdev_lookup_top(spa, DVA_GET_VDEV(dva));
1605 1613 dsize = (asize >> SPA_MINBLOCKSHIFT) * vd->vdev_deflate_ratio;
1606 1614 }
1607 1615
1608 1616 return (dsize);
1609 1617 }
1610 1618
1611 1619 uint64_t
1612 1620 bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp)
1613 1621 {
1614 1622 uint64_t dsize = 0;
1615 1623
1616 1624 for (int d = 0; d < SPA_DVAS_PER_BP; d++)
1617 1625 dsize += dva_get_dsize_sync(spa, &bp->blk_dva[d]);
1618 1626
1619 1627 return (dsize);
1620 1628 }
1621 1629
1622 1630 uint64_t
1623 1631 bp_get_dsize(spa_t *spa, const blkptr_t *bp)
1624 1632 {
1625 1633 uint64_t dsize = 0;
1626 1634
1627 1635 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
1628 1636
1629 1637 for (int d = 0; d < SPA_DVAS_PER_BP; d++)
1630 1638 dsize += dva_get_dsize_sync(spa, &bp->blk_dva[d]);
1631 1639
1632 1640 spa_config_exit(spa, SCL_VDEV, FTAG);
1633 1641
1634 1642 return (dsize);
1635 1643 }
1636 1644
1637 1645 /*
1638 1646 * ==========================================================================
1639 1647 * Initialization and Termination
1640 1648 * ==========================================================================
1641 1649 */
1642 1650
1643 1651 static int
1644 1652 spa_name_compare(const void *a1, const void *a2)
1645 1653 {
1646 1654 const spa_t *s1 = a1;
1647 1655 const spa_t *s2 = a2;
1648 1656 int s;
1649 1657
1650 1658 s = strcmp(s1->spa_name, s2->spa_name);
1651 1659 if (s > 0)
1652 1660 return (1);
1653 1661 if (s < 0)
1654 1662 return (-1);
1655 1663 return (0);
1656 1664 }
1657 1665
1658 1666 int
1659 1667 spa_busy(void)
1660 1668 {
1661 1669 return (spa_active_count);
1662 1670 }
1663 1671
1664 1672 void
1665 1673 spa_boot_init()
1666 1674 {
1667 1675 spa_config_load();
1668 1676 }
1669 1677
1670 1678 void
1671 1679 spa_init(int mode)
1672 1680 {
1673 1681 mutex_init(&spa_namespace_lock, NULL, MUTEX_DEFAULT, NULL);
1674 1682 mutex_init(&spa_spare_lock, NULL, MUTEX_DEFAULT, NULL);
1675 1683 mutex_init(&spa_l2cache_lock, NULL, MUTEX_DEFAULT, NULL);
1676 1684 cv_init(&spa_namespace_cv, NULL, CV_DEFAULT, NULL);
1677 1685
1678 1686 avl_create(&spa_namespace_avl, spa_name_compare, sizeof (spa_t),
1679 1687 offsetof(spa_t, spa_avl));
1680 1688
1681 1689 avl_create(&spa_spare_avl, spa_spare_compare, sizeof (spa_aux_t),
1682 1690 offsetof(spa_aux_t, aux_avl));
1683 1691
1684 1692 avl_create(&spa_l2cache_avl, spa_l2cache_compare, sizeof (spa_aux_t),
1685 1693 offsetof(spa_aux_t, aux_avl));
1686 1694
1687 1695 spa_mode_global = mode;
1688 1696
1689 1697 #ifdef _KERNEL
1690 1698 spa_arch_init();
1691 1699 #else
1692 1700 if (spa_mode_global != FREAD && dprintf_find_string("watch")) {
1693 1701 arc_procfd = open("/proc/self/ctl", O_WRONLY);
1694 1702 if (arc_procfd == -1) {
↓ open down ↓ |
656 lines elided |
↑ open up ↑ |
1695 1703 perror("could not enable watchpoints: "
1696 1704 "opening /proc/self/ctl failed: ");
1697 1705 } else {
1698 1706 arc_watch = B_TRUE;
1699 1707 }
1700 1708 }
1701 1709 #endif
1702 1710
1703 1711 refcount_init();
1704 1712 unique_init();
1705 - space_map_init();
1713 + range_tree_init();
1706 1714 zio_init();
1707 1715 dmu_init();
1708 1716 zil_init();
1709 1717 vdev_cache_stat_init();
1710 1718 zfs_prop_init();
1711 1719 zpool_prop_init();
1712 1720 zpool_feature_init();
1713 1721 spa_config_load();
1714 1722 l2arc_start();
1715 1723 }
1716 1724
1717 1725 void
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
1718 1726 spa_fini(void)
1719 1727 {
1720 1728 l2arc_stop();
1721 1729
1722 1730 spa_evict_all();
1723 1731
1724 1732 vdev_cache_stat_fini();
1725 1733 zil_fini();
1726 1734 dmu_fini();
1727 1735 zio_fini();
1728 - space_map_fini();
1736 + range_tree_fini();
1729 1737 unique_fini();
1730 1738 refcount_fini();
1731 1739
1732 1740 avl_destroy(&spa_namespace_avl);
1733 1741 avl_destroy(&spa_spare_avl);
1734 1742 avl_destroy(&spa_l2cache_avl);
1735 1743
1736 1744 cv_destroy(&spa_namespace_cv);
1737 1745 mutex_destroy(&spa_namespace_lock);
1738 1746 mutex_destroy(&spa_spare_lock);
1739 1747 mutex_destroy(&spa_l2cache_lock);
1740 1748 }
1741 1749
1742 1750 /*
1743 1751 * Return whether this pool has slogs. No locking needed.
1744 1752 * It's not a problem if the wrong answer is returned as it's only for
1745 1753 * performance and not correctness
1746 1754 */
1747 1755 boolean_t
1748 1756 spa_has_slogs(spa_t *spa)
1749 1757 {
1750 1758 return (spa->spa_log_class->mc_rotor != NULL);
1751 1759 }
1752 1760
1753 1761 spa_log_state_t
1754 1762 spa_get_log_state(spa_t *spa)
1755 1763 {
1756 1764 return (spa->spa_log_state);
1757 1765 }
1758 1766
1759 1767 void
1760 1768 spa_set_log_state(spa_t *spa, spa_log_state_t state)
1761 1769 {
1762 1770 spa->spa_log_state = state;
1763 1771 }
1764 1772
1765 1773 boolean_t
1766 1774 spa_is_root(spa_t *spa)
1767 1775 {
1768 1776 return (spa->spa_is_root);
1769 1777 }
1770 1778
1771 1779 boolean_t
1772 1780 spa_writeable(spa_t *spa)
1773 1781 {
1774 1782 return (!!(spa->spa_mode & FWRITE));
1775 1783 }
1776 1784
1777 1785 int
1778 1786 spa_mode(spa_t *spa)
1779 1787 {
1780 1788 return (spa->spa_mode);
1781 1789 }
1782 1790
1783 1791 uint64_t
1784 1792 spa_bootfs(spa_t *spa)
1785 1793 {
1786 1794 return (spa->spa_bootfs);
1787 1795 }
1788 1796
1789 1797 uint64_t
1790 1798 spa_delegation(spa_t *spa)
1791 1799 {
1792 1800 return (spa->spa_delegation);
1793 1801 }
1794 1802
1795 1803 objset_t *
1796 1804 spa_meta_objset(spa_t *spa)
1797 1805 {
1798 1806 return (spa->spa_meta_objset);
1799 1807 }
1800 1808
1801 1809 enum zio_checksum
1802 1810 spa_dedup_checksum(spa_t *spa)
1803 1811 {
1804 1812 return (spa->spa_dedup_checksum);
1805 1813 }
1806 1814
1807 1815 /*
1808 1816 * Reset pool scan stat per scan pass (or reboot).
1809 1817 */
1810 1818 void
1811 1819 spa_scan_stat_init(spa_t *spa)
1812 1820 {
1813 1821 /* data not stored on disk */
1814 1822 spa->spa_scan_pass_start = gethrestime_sec();
1815 1823 spa->spa_scan_pass_exam = 0;
1816 1824 vdev_scan_stat_init(spa->spa_root_vdev);
1817 1825 }
1818 1826
1819 1827 /*
1820 1828 * Get scan stats for zpool status reports
1821 1829 */
1822 1830 int
1823 1831 spa_scan_get_stats(spa_t *spa, pool_scan_stat_t *ps)
1824 1832 {
1825 1833 dsl_scan_t *scn = spa->spa_dsl_pool ? spa->spa_dsl_pool->dp_scan : NULL;
1826 1834
1827 1835 if (scn == NULL || scn->scn_phys.scn_func == POOL_SCAN_NONE)
1828 1836 return (SET_ERROR(ENOENT));
1829 1837 bzero(ps, sizeof (pool_scan_stat_t));
1830 1838
1831 1839 /* data stored on disk */
1832 1840 ps->pss_func = scn->scn_phys.scn_func;
1833 1841 ps->pss_start_time = scn->scn_phys.scn_start_time;
1834 1842 ps->pss_end_time = scn->scn_phys.scn_end_time;
1835 1843 ps->pss_to_examine = scn->scn_phys.scn_to_examine;
1836 1844 ps->pss_examined = scn->scn_phys.scn_examined;
1837 1845 ps->pss_to_process = scn->scn_phys.scn_to_process;
1838 1846 ps->pss_processed = scn->scn_phys.scn_processed;
1839 1847 ps->pss_errors = scn->scn_phys.scn_errors;
1840 1848 ps->pss_state = scn->scn_phys.scn_state;
1841 1849
1842 1850 /* data not stored on disk */
1843 1851 ps->pss_pass_start = spa->spa_scan_pass_start;
1844 1852 ps->pss_pass_exam = spa->spa_scan_pass_exam;
1845 1853
1846 1854 return (0);
1847 1855 }
1848 1856
1849 1857 boolean_t
1850 1858 spa_debug_enabled(spa_t *spa)
1851 1859 {
1852 1860 return (spa->spa_debug);
1853 1861 }
↓ open down ↓ |
115 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX