Deleted Added
full compact
spa_misc.c (243503) spa_misc.c (247265)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 8 unchanged lines hidden (view full) ---

17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 8 unchanged lines hidden (view full) ---

17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 * Copyright 2013 Martin Matuska <mm@FreeBSD.org>. All rights reserved.
25 */
26
27#include <sys/zfs_context.h>
28#include <sys/spa_impl.h>
26 */
27
28#include <sys/zfs_context.h>
29#include <sys/spa_impl.h>
30#include <sys/spa_boot.h>
29#include <sys/zio.h>
30#include <sys/zio_checksum.h>
31#include <sys/zio_compress.h>
32#include <sys/dmu.h>
33#include <sys/dmu_tx.h>
34#include <sys/zap.h>
35#include <sys/zil.h>
36#include <sys/vdev_impl.h>

--- 211 unchanged lines hidden (view full) ---

248 * set, calls to zfs_panic_recover() will turn into warning messages.
249 */
250int zfs_recover = 0;
251SYSCTL_DECL(_vfs_zfs);
252TUNABLE_INT("vfs.zfs.recover", &zfs_recover);
253SYSCTL_INT(_vfs_zfs, OID_AUTO, recover, CTLFLAG_RDTUN, &zfs_recover, 0,
254 "Try to recover from otherwise-fatal errors.");
255
31#include <sys/zio.h>
32#include <sys/zio_checksum.h>
33#include <sys/zio_compress.h>
34#include <sys/dmu.h>
35#include <sys/dmu_tx.h>
36#include <sys/zap.h>
37#include <sys/zil.h>
38#include <sys/vdev_impl.h>

--- 211 unchanged lines hidden (view full) ---

250 * set, calls to zfs_panic_recover() will turn into warning messages.
251 */
252int zfs_recover = 0;
253SYSCTL_DECL(_vfs_zfs);
254TUNABLE_INT("vfs.zfs.recover", &zfs_recover);
255SYSCTL_INT(_vfs_zfs, OID_AUTO, recover, CTLFLAG_RDTUN, &zfs_recover, 0,
256 "Try to recover from otherwise-fatal errors.");
257
258extern int zfs_txg_synctime_ms;
256
257/*
259
260/*
261 * Expiration time in units of zfs_txg_synctime_ms. This value has two
262 * meanings. First it is used to determine when the spa_deadman logic
263 * should fire. By default the spa_deadman will fire if spa_sync has
264 * not completed in 1000 * zfs_txg_synctime_ms (i.e. 1000 seconds).
265 * Secondly, the value determines if an I/O is considered "hung".
266 * Any I/O that has not completed in zfs_deadman_synctime is considered
267 * "hung" resulting in a system panic.
268 * 1000 zfs_txg_synctime_ms (i.e. 1000 seconds).
269 */
270uint64_t zfs_deadman_synctime = 1000ULL;
271TUNABLE_QUAD("vfs.zfs.deadman_synctime", &zfs_deadman_synctime);
272SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, deadman_synctime, CTLFLAG_RDTUN,
273 &zfs_deadman_synctime, 0,
274 "Stalled ZFS I/O expiration time in units of vfs.zfs.txg_synctime_ms");
275
276/*
277 * Default value of -1 for zfs_deadman_enabled is resolved in
278 * zfs_deadman_init()
279 */
280int zfs_deadman_enabled = -1;
281TUNABLE_INT("vfs.zfs.deadman_enabled", &zfs_deadman_enabled);
282SYSCTL_INT(_vfs_zfs, OID_AUTO, deadman_enabled, CTLFLAG_RDTUN,
283 &zfs_deadman_enabled, 0, "Kernel panic on stalled ZFS I/O");
284
285#ifndef illumos
286#ifdef _KERNEL
287static void
288zfs_deadman_init()
289{
290 /*
291 * If we are not i386 or amd64 or in a virtual machine,
292 * disable ZFS deadman thread by default
293 */
294 if (zfs_deadman_enabled == -1) {
295#if defined(__amd64__) || defined(__i386__)
296 zfs_deadman_enabled = (vm_guest == VM_GUEST_NO) ? 1 : 0;
297#else
298 zfs_deadman_enabled = 0;
299#endif
300 }
301}
302#endif /* _KERNEL */
303#endif /* !illumos */
304
305/*
258 * ==========================================================================
259 * SPA config locking
260 * ==========================================================================
261 */
262static void
263spa_config_lock_init(spa_t *spa)
264{
265 for (int i = 0; i < SCL_LOCKS; i++) {

--- 151 unchanged lines hidden (view full) ---

417
418 if (cp)
419 *cp = c;
420
421 return (spa);
422}
423
424/*
306 * ==========================================================================
307 * SPA config locking
308 * ==========================================================================
309 */
310static void
311spa_config_lock_init(spa_t *spa)
312{
313 for (int i = 0; i < SCL_LOCKS; i++) {

--- 151 unchanged lines hidden (view full) ---

465
466 if (cp)
467 *cp = c;
468
469 return (spa);
470}
471
472/*
473 * Fires when spa_sync has not completed within zfs_deadman_synctime_ms.
474 * If the zfs_deadman_enabled flag is set then it inspects all vdev queues
475 * looking for potentially hung I/Os.
476 */
477void
478spa_deadman(void *arg)
479{
480 spa_t *spa = arg;
481
482 zfs_dbgmsg("slow spa_sync: started %llu seconds ago, calls %llu",
483 (gethrtime() - spa->spa_sync_starttime) / NANOSEC,
484 ++spa->spa_deadman_calls);
485 if (zfs_deadman_enabled)
486 vdev_deadman(spa->spa_root_vdev);
487}
488
489/*
425 * Create an uninitialized spa_t with the given name. Requires
426 * spa_namespace_lock. The caller must ensure that the spa_t doesn't already
427 * exist by calling spa_lookup() first.
428 */
429spa_t *
430spa_add(const char *name, nvlist_t *config, const char *altroot)
431{
432 spa_t *spa;
433 spa_config_dirent_t *dp;
490 * Create an uninitialized spa_t with the given name. Requires
491 * spa_namespace_lock. The caller must ensure that the spa_t doesn't already
492 * exist by calling spa_lookup() first.
493 */
494spa_t *
495spa_add(const char *name, nvlist_t *config, const char *altroot)
496{
497 spa_t *spa;
498 spa_config_dirent_t *dp;
499#ifdef illumos
500 cyc_handler_t hdlr;
501 cyc_time_t when;
502#endif
434
435 ASSERT(MUTEX_HELD(&spa_namespace_lock));
436
437 spa = kmem_zalloc(sizeof (spa_t), KM_SLEEP);
438
439 mutex_init(&spa->spa_async_lock, NULL, MUTEX_DEFAULT, NULL);
440 mutex_init(&spa->spa_errlist_lock, NULL, MUTEX_DEFAULT, NULL);
441 mutex_init(&spa->spa_errlog_lock, NULL, MUTEX_DEFAULT, NULL);

--- 15 unchanged lines hidden (view full) ---

457 (void) strlcpy(spa->spa_name, name, sizeof (spa->spa_name));
458 spa->spa_state = POOL_STATE_UNINITIALIZED;
459 spa->spa_freeze_txg = UINT64_MAX;
460 spa->spa_final_txg = UINT64_MAX;
461 spa->spa_load_max_txg = UINT64_MAX;
462 spa->spa_proc = &p0;
463 spa->spa_proc_state = SPA_PROC_NONE;
464
503
504 ASSERT(MUTEX_HELD(&spa_namespace_lock));
505
506 spa = kmem_zalloc(sizeof (spa_t), KM_SLEEP);
507
508 mutex_init(&spa->spa_async_lock, NULL, MUTEX_DEFAULT, NULL);
509 mutex_init(&spa->spa_errlist_lock, NULL, MUTEX_DEFAULT, NULL);
510 mutex_init(&spa->spa_errlog_lock, NULL, MUTEX_DEFAULT, NULL);

--- 15 unchanged lines hidden (view full) ---

526 (void) strlcpy(spa->spa_name, name, sizeof (spa->spa_name));
527 spa->spa_state = POOL_STATE_UNINITIALIZED;
528 spa->spa_freeze_txg = UINT64_MAX;
529 spa->spa_final_txg = UINT64_MAX;
530 spa->spa_load_max_txg = UINT64_MAX;
531 spa->spa_proc = &p0;
532 spa->spa_proc_state = SPA_PROC_NONE;
533
534#ifdef illumos
535 hdlr.cyh_func = spa_deadman;
536 hdlr.cyh_arg = spa;
537 hdlr.cyh_level = CY_LOW_LEVEL;
538#endif
539
540 spa->spa_deadman_synctime = zfs_deadman_synctime *
541 zfs_txg_synctime_ms * MICROSEC;
542
543#ifdef illumos
544 /*
545 * This determines how often we need to check for hung I/Os after
546 * the cyclic has already fired. Since checking for hung I/Os is
547 * an expensive operation we don't want to check too frequently.
548 * Instead wait for 5 synctimes before checking again.
549 */
550 when.cyt_interval = 5ULL * zfs_txg_synctime_ms * MICROSEC;
551 when.cyt_when = CY_INFINITY;
552 mutex_enter(&cpu_lock);
553 spa->spa_deadman_cycid = cyclic_add(&hdlr, &when);
554 mutex_exit(&cpu_lock);
555#else /* !illumos */
556#ifdef _KERNEL
557 callout_init(&spa->spa_deadman_cycid, CALLOUT_MPSAFE);
558#endif
559#endif
465 refcount_create(&spa->spa_refcount);
466 spa_config_lock_init(spa);
467
468 avl_add(&spa_namespace_avl, spa);
469
470 /*
471 * Set the alternate root, if there is one.
472 */

--- 66 unchanged lines hidden (view full) ---

539 }
540
541 list_destroy(&spa->spa_config_list);
542
543 nvlist_free(spa->spa_label_features);
544 nvlist_free(spa->spa_load_info);
545 spa_config_set(spa, NULL);
546
560 refcount_create(&spa->spa_refcount);
561 spa_config_lock_init(spa);
562
563 avl_add(&spa_namespace_avl, spa);
564
565 /*
566 * Set the alternate root, if there is one.
567 */

--- 66 unchanged lines hidden (view full) ---

634 }
635
636 list_destroy(&spa->spa_config_list);
637
638 nvlist_free(spa->spa_label_features);
639 nvlist_free(spa->spa_load_info);
640 spa_config_set(spa, NULL);
641
642#ifdef illumos
643 mutex_enter(&cpu_lock);
644 if (spa->spa_deadman_cycid != CYCLIC_NONE)
645 cyclic_remove(spa->spa_deadman_cycid);
646 mutex_exit(&cpu_lock);
647 spa->spa_deadman_cycid = CYCLIC_NONE;
648#else /* !illumos */
649#ifdef _KERNEL
650 callout_drain(&spa->spa_deadman_cycid);
651#endif
652#endif
653
547 refcount_destroy(&spa->spa_refcount);
548
549 spa_config_lock_destroy(spa);
550
551 for (int t = 0; t < TXG_SIZE; t++)
552 bplist_destroy(&spa->spa_free_bplist[t]);
553
554 cv_destroy(&spa->spa_async_cv);

--- 951 unchanged lines hidden (view full) ---

1506
1507int
1508spa_prev_software_version(spa_t *spa)
1509{
1510 return (spa->spa_prev_software_version);
1511}
1512
1513uint64_t
654 refcount_destroy(&spa->spa_refcount);
655
656 spa_config_lock_destroy(spa);
657
658 for (int t = 0; t < TXG_SIZE; t++)
659 bplist_destroy(&spa->spa_free_bplist[t]);
660
661 cv_destroy(&spa->spa_async_cv);

--- 951 unchanged lines hidden (view full) ---

1613
1614int
1615spa_prev_software_version(spa_t *spa)
1616{
1617 return (spa->spa_prev_software_version);
1618}
1619
1620uint64_t
1621spa_deadman_synctime(spa_t *spa)
1622{
1623 return (spa->spa_deadman_synctime);
1624}
1625
1626uint64_t
1514dva_get_dsize_sync(spa_t *spa, const dva_t *dva)
1515{
1516 uint64_t asize = DVA_GET_ASIZE(dva);
1517 uint64_t dsize = asize;
1518
1519 ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
1520
1521 if (asize != 0 && spa->spa_deflate) {

--- 78 unchanged lines hidden (view full) ---

1600 offsetof(spa_aux_t, aux_avl));
1601
1602 avl_create(&spa_l2cache_avl, spa_l2cache_compare, sizeof (spa_aux_t),
1603 offsetof(spa_aux_t, aux_avl));
1604
1605 spa_mode_global = mode;
1606
1607#ifdef illumos
1627dva_get_dsize_sync(spa_t *spa, const dva_t *dva)
1628{
1629 uint64_t asize = DVA_GET_ASIZE(dva);
1630 uint64_t dsize = asize;
1631
1632 ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
1633
1634 if (asize != 0 && spa->spa_deflate) {

--- 78 unchanged lines hidden (view full) ---

1713 offsetof(spa_aux_t, aux_avl));
1714
1715 avl_create(&spa_l2cache_avl, spa_l2cache_compare, sizeof (spa_aux_t),
1716 offsetof(spa_aux_t, aux_avl));
1717
1718 spa_mode_global = mode;
1719
1720#ifdef illumos
1608#ifndef _KERNEL
1721#ifdef _KERNEL
1722 spa_arch_init();
1723#else
1609 if (spa_mode_global != FREAD && dprintf_find_string("watch")) {
1610 arc_procfd = open("/proc/self/ctl", O_WRONLY);
1611 if (arc_procfd == -1) {
1612 perror("could not enable watchpoints: "
1613 "opening /proc/self/ctl failed: ");
1614 } else {
1615 arc_watch = B_TRUE;
1616 }

--- 7 unchanged lines hidden (view full) ---

1624 dmu_init();
1625 zil_init();
1626 vdev_cache_stat_init();
1627 zfs_prop_init();
1628 zpool_prop_init();
1629 zpool_feature_init();
1630 spa_config_load();
1631 l2arc_start();
1724 if (spa_mode_global != FREAD && dprintf_find_string("watch")) {
1725 arc_procfd = open("/proc/self/ctl", O_WRONLY);
1726 if (arc_procfd == -1) {
1727 perror("could not enable watchpoints: "
1728 "opening /proc/self/ctl failed: ");
1729 } else {
1730 arc_watch = B_TRUE;
1731 }

--- 7 unchanged lines hidden (view full) ---

1739 dmu_init();
1740 zil_init();
1741 vdev_cache_stat_init();
1742 zfs_prop_init();
1743 zpool_prop_init();
1744 zpool_feature_init();
1745 spa_config_load();
1746 l2arc_start();
1747#ifndef illumos
1748#ifdef _KERNEL
1749 zfs_deadman_init();
1750#endif
1751#endif /* !illumos */
1632}
1633
1634void
1635spa_fini(void)
1636{
1637 l2arc_stop();
1638
1639 spa_evict_all();

--- 131 unchanged lines hidden ---
1752}
1753
1754void
1755spa_fini(void)
1756{
1757 l2arc_stop();
1758
1759 spa_evict_all();

--- 131 unchanged lines hidden ---