usr/src/uts/common/fs/zfs/spa_misc.c
author brendan
Fri, 09 Nov 2007 21:33:30 -0800
changeset 5450 b25030891c44
parent 5363 36eeffc5336d
child 5530 4ed96167d864
permissions -rw-r--r--
PSARC 2007/618 ZFS L2ARC 6536054 second tier ("external") ARC
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#pragma ident	"%Z%%M%	%I%	%E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/spa_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/zio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/zio_checksum.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/zio_compress.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/dmu_tx.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/zap.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/zil.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/vdev_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <sys/metaslab.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
#include <sys/uberblock_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
#include <sys/txg.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#include <sys/avl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include <sys/unique.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#include <sys/dsl_pool.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
#include <sys/dsl_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
#include <sys/dsl_prop.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#include <sys/fs/zfs.h>
4620
4895df7f426f 6574298 slog still uses main pool for dmu_sync()
perrin
parents: 4603
diff changeset
    47
#include <sys/metaslab_impl.h>
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4620
diff changeset
    48
#include "zfs_prop.h"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
 * SPA locking
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
 * There are four basic locks for managing spa_t structures:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
 * spa_namespace_lock (global mutex)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    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
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
    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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
 * spa_refcount (per-spa refcount_t protected by mutex)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
 *
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4620
diff changeset
    80
 * spa_config_lock (per-spa read-priority rwlock)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
 *
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4620
diff changeset
    82
 *	This protects the spa_t from config changes, and must be held in
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4620
diff changeset
    83
 *	the following circumstances:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
 * spa_config_cache_lock (per-spa mutex)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
 *      other locks are required to obtain this lock, although implicitly you
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
 *      must have the namespace lock or non-zero refcount to have any kind
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
 *      of spa_t pointer at all.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
 * The locking order is fairly straightforward:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
 * The spa_namespace_lock and spa_config_cache_lock can be acquired directly and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
 * are globally visible.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
 * The namespace is manipulated using the following functions, all which require
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
 * the spa_namespace_lock to be held.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
 *
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   131
 *	spa_guid_exists()	Determine whether a pool/device guid exists.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
 * The spa_refcount is manipulated using the following functions:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
 * The spa_config_lock is manipulated using the following functions:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
 *
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   158
 * The vdev configuration is protected by spa_vdev_enter() / spa_vdev_exit().
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   161
 *				for writing.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   165
 *				cache, and release the namespace lock.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   167
 * The spa_name() function also requires either the spa_namespace_lock
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
 * or the spa_config_lock, as both are needed to do a rename.  spa_rename() is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
 * also implemented within this file since is requires manipulation of the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   170
 * namespace.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
static avl_tree_t spa_namespace_avl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
kmutex_t spa_namespace_lock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2926
diff changeset
   177
int spa_max_replication_override = SPA_DVAS_PER_BP;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   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
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   180
static avl_tree_t spa_spare_avl;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   181
static kmutex_t spa_l2cache_lock;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   182
static avl_tree_t spa_l2cache_avl;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   183
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
kmem_cache_t *spa_buffer_pool;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   185
int spa_mode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
#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
   188
/* 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
   189
int zfs_flags = ~ZFS_DEBUG_DPRINTF;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
#else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
int zfs_flags = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
3713
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   194
/*
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   195
 * zfs_recover can be set to nonzero to attempt to recover from
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   196
 * otherwise-fatal errors, typically caused by on-disk corruption.  When
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   197
 * set, calls to zfs_panic_recover() will turn into warning messages.
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   198
 */
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   199
int zfs_recover = 0;
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   200
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
#define	SPA_MINREF	5	/* spa_refcnt for an open-but-idle pool */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
 * SPA namespace functions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   210
 * Lookup the named spa_t in the AVL tree.  The spa_namespace_lock must be held.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
 * Returns NULL if no matching spa_t is found.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
spa_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
spa_lookup(const char *name)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
	spa_t search, *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
	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
   218
	char c;
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   219
	char *cp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
	ASSERT(MUTEX_HELD(&spa_namespace_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   223
	/*
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   224
	 * 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
   225
	 * just use that.
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   226
	 */
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   227
	cp = strpbrk(name, "/@");
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   228
	if (cp) {
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   229
		c = *cp;
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   230
		*cp = '\0';
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   231
	}
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   232
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
	search.spa_name = (char *)name;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
	spa = avl_find(&spa_namespace_avl, &search, &where);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   236
	if (cp)
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   237
		*cp = c;
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   238
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
	return (spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
 * Create an uninitialized spa_t with the given name.  Requires
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
 * spa_namespace_lock.  The caller must ensure that the spa_t doesn't already
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
 * exist by calling spa_lookup() first.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
spa_t *
1635
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   248
spa_add(const char *name, const char *altroot)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
	ASSERT(MUTEX_HELD(&spa_namespace_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
	spa = kmem_zalloc(sizeof (spa_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   256
	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
   257
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   258
	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
   259
	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
   260
	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
   261
	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
   262
	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
   263
	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
   264
	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
   265
	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
   266
	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
   267
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   268
	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
   269
	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
   270
	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
   271
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
	spa->spa_name = spa_strdup(name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
	spa->spa_state = POOL_STATE_UNINITIALIZED;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
	spa->spa_freeze_txg = UINT64_MAX;
1635
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   275
	spa->spa_final_txg = UINT64_MAX;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
	refcount_create(&spa->spa_refcount);
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4620
diff changeset
   278
	rprw_init(&spa->spa_config_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
	avl_add(&spa_namespace_avl, spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5094
diff changeset
   282
	mutex_init(&spa->spa_zio_lock, NULL, MUTEX_DEFAULT, NULL);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5094
diff changeset
   283
1635
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   284
	/*
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   285
	 * 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
   286
	 */
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   287
	if (altroot) {
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   288
		spa->spa_root = spa_strdup(altroot);
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   289
		spa_active_count++;
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   290
	}
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   291
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
	return (spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
 * Removes a spa_t from the namespace, freeing up any memory used.  Requires
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
 * spa_namespace_lock.  This is called only after the spa_t has been closed and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
 * deactivated.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
spa_remove(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
	ASSERT(MUTEX_HELD(&spa_namespace_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
	ASSERT(spa->spa_state == POOL_STATE_UNINITIALIZED);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
	ASSERT(spa->spa_scrub_thread == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
	avl_remove(&spa_namespace_avl, spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
	cv_broadcast(&spa_namespace_cv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
1635
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   310
	if (spa->spa_root) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
		spa_strfree(spa->spa_root);
1635
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   312
		spa_active_count--;
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   313
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
	if (spa->spa_name)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
		spa_strfree(spa->spa_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5329
diff changeset
   318
	if (spa->spa_config_dir)
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5329
diff changeset
   319
		spa_strfree(spa->spa_config_dir);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5329
diff changeset
   320
	if (spa->spa_config_file)
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5329
diff changeset
   321
		spa_strfree(spa->spa_config_file);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5329
diff changeset
   322
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
	spa_config_set(spa, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
	refcount_destroy(&spa->spa_refcount);
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4620
diff changeset
   326
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4620
diff changeset
   327
	rprw_destroy(&spa->spa_config_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   329
	rw_destroy(&spa->spa_traverse_lock);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   330
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   331
	cv_destroy(&spa->spa_async_cv);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   332
	cv_destroy(&spa->spa_scrub_cv);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   333
	cv_destroy(&spa->spa_scrub_io_cv);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   334
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   335
	mutex_destroy(&spa->spa_uberblock_lock);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   336
	mutex_destroy(&spa->spa_async_lock);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   337
	mutex_destroy(&spa->spa_config_cache_lock);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   338
	mutex_destroy(&spa->spa_scrub_lock);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2174
diff changeset
   339
	mutex_destroy(&spa->spa_errlog_lock);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   340
	mutex_destroy(&spa->spa_errlist_lock);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   341
	mutex_destroy(&spa->spa_sync_bplist.bpl_lock);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
   342
	mutex_destroy(&spa->spa_history_lock);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3713
diff changeset
   343
	mutex_destroy(&spa->spa_props_lock);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5094
diff changeset
   344
	mutex_destroy(&spa->spa_zio_lock);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2174
diff changeset
   345
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   346
	kmem_free(spa, sizeof (spa_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   347
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   348
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
 * Given a pool, return the next pool in the namespace, or NULL if there is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
 * none.  If 'prev' is NULL, return the first pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   352
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   353
spa_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   354
spa_next(spa_t *prev)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   355
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
	ASSERT(MUTEX_HELD(&spa_namespace_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   357
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   358
	if (prev)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   359
		return (AVL_NEXT(&spa_namespace_avl, prev));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   360
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   361
		return (avl_first(&spa_namespace_avl));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   362
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   363
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   364
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   365
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   366
 * SPA refcount functions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   367
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   368
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   369
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
 * Add a reference to the given spa_t.  Must have at least one reference, or
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
 * have the namespace lock held.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   374
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   375
spa_open_ref(spa_t *spa, void *tag)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   376
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
	ASSERT(refcount_count(&spa->spa_refcount) > SPA_MINREF ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
	    MUTEX_HELD(&spa_namespace_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
	(void) refcount_add(&spa->spa_refcount, tag);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   381
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   384
 * Remove a reference to the given spa_t.  Must have at least one reference, or
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   385
 * have the namespace lock held.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   386
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   387
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   388
spa_close(spa_t *spa, void *tag)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   389
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   390
	ASSERT(refcount_count(&spa->spa_refcount) > SPA_MINREF ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   391
	    MUTEX_HELD(&spa_namespace_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   392
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   393
	(void) refcount_remove(&spa->spa_refcount, tag);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   394
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   395
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   396
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   397
 * Check to see if the spa refcount is zero.  Must be called with
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   398
 * spa_namespace_lock held.  We really compare against SPA_MINREF, which is the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   399
 * number of references acquired when opening a pool
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   400
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   401
boolean_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   402
spa_refcount_zero(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   403
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   404
	ASSERT(MUTEX_HELD(&spa_namespace_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   405
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   406
	return (refcount_count(&spa->spa_refcount) == SPA_MINREF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   407
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   408
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   409
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   410
 * ==========================================================================
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   411
 * SPA spare and l2cache tracking
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   412
 * ==========================================================================
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   413
 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   414
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   415
/*
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   416
 * Hot spares and cache devices are tracked using the same code below,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   417
 * for 'auxiliary' devices.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   418
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   419
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   420
typedef struct spa_aux {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   421
	uint64_t	aux_guid;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   422
	uint64_t	aux_pool;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   423
	avl_node_t	aux_avl;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   424
	int		aux_count;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   425
} spa_aux_t;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   426
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   427
static int
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   428
spa_aux_compare(const void *a, const void *b)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   429
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   430
	const spa_aux_t *sa = a;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   431
	const spa_aux_t *sb = b;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   432
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   433
	if (sa->aux_guid < sb->aux_guid)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   434
		return (-1);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   435
	else if (sa->aux_guid > sb->aux_guid)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   436
		return (1);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   437
	else
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   438
		return (0);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   439
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   440
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   441
void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   442
spa_aux_add(vdev_t *vd, avl_tree_t *avl)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   443
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   444
	avl_index_t where;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   445
	spa_aux_t search;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   446
	spa_aux_t *aux;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   447
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   448
	search.aux_guid = vd->vdev_guid;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   449
	if ((aux = avl_find(avl, &search, &where)) != NULL) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   450
		aux->aux_count++;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   451
	} else {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   452
		aux = kmem_zalloc(sizeof (spa_aux_t), KM_SLEEP);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   453
		aux->aux_guid = vd->vdev_guid;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   454
		aux->aux_count = 1;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   455
		avl_insert(avl, aux, where);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   456
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   457
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   458
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   459
void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   460
spa_aux_remove(vdev_t *vd, avl_tree_t *avl)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   461
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   462
	spa_aux_t search;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   463
	spa_aux_t *aux;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   464
	avl_index_t where;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   465
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   466
	search.aux_guid = vd->vdev_guid;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   467
	aux = avl_find(avl, &search, &where);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   468
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   469
	ASSERT(aux != NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   470
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   471
	if (--aux->aux_count == 0) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   472
		avl_remove(avl, aux);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   473
		kmem_free(aux, sizeof (spa_aux_t));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   474
	} else if (aux->aux_pool == spa_guid(vd->vdev_spa)) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   475
		aux->aux_pool = 0ULL;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   476
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   477
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   478
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   479
boolean_t
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   480
spa_aux_exists(uint64_t guid, uint64_t *pool, avl_tree_t *avl)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   481
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   482
	spa_aux_t search, *found;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   483
	avl_index_t where;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   484
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   485
	search.aux_guid = guid;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   486
	found = avl_find(avl, &search, &where);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   487
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   488
	if (pool) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   489
		if (found)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   490
			*pool = found->aux_pool;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   491
		else
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   492
			*pool = 0ULL;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   493
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   494
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   495
	return (found != NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   496
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   497
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   498
void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   499
spa_aux_activate(vdev_t *vd, avl_tree_t *avl)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   500
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   501
	spa_aux_t search, *found;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   502
	avl_index_t where;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   503
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   504
	search.aux_guid = vd->vdev_guid;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   505
	found = avl_find(avl, &search, &where);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   506
	ASSERT(found != NULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   507
	ASSERT(found->aux_pool == 0ULL);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   508
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   509
	found->aux_pool = spa_guid(vd->vdev_spa);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   510
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   511
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   512
/*
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   513
 * 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
   514
 *
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   515
 * 	- 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
   516
 * 	- 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
   517
 *	  another pool.
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   518
 * 	- 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
   519
 *	  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
   520
 *
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   521
 * 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
   522
 * 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
   523
 * 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
   524
 * 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
   525
 * 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
   526
 * 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
   527
 *
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   528
 * 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
   529
 * 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
   530
 * 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
   531
 * be completely consistent with respect to other vdev configuration changes.
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   532
 */
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   533
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   534
static int
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   535
spa_spare_compare(const void *a, const void *b)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   536
{
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   537
	return (spa_aux_compare(a, b));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   538
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   539
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   540
void
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   541
spa_spare_add(vdev_t *vd)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   542
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   543
	mutex_enter(&spa_spare_lock);
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   544
	ASSERT(!vd->vdev_isspare);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   545
	spa_aux_add(vd, &spa_spare_avl);
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   546
	vd->vdev_isspare = B_TRUE;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   547
	mutex_exit(&spa_spare_lock);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   548
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   549
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   550
void
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   551
spa_spare_remove(vdev_t *vd)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   552
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   553
	mutex_enter(&spa_spare_lock);
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   554
	ASSERT(vd->vdev_isspare);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   555
	spa_aux_remove(vd, &spa_spare_avl);
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   556
	vd->vdev_isspare = B_FALSE;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   557
	mutex_exit(&spa_spare_lock);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   558
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   559
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   560
boolean_t
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   561
spa_spare_exists(uint64_t guid, uint64_t *pool)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   562
{
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   563
	boolean_t found;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   564
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   565
	mutex_enter(&spa_spare_lock);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   566
	found = spa_aux_exists(guid, pool, &spa_spare_avl);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   567
	mutex_exit(&spa_spare_lock);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   568
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   569
	return (found);
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   570
}
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   571
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   572
void
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   573
spa_spare_activate(vdev_t *vd)
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   574
{
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   575
	mutex_enter(&spa_spare_lock);
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   576
	ASSERT(vd->vdev_isspare);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   577
	spa_aux_activate(vd, &spa_spare_avl);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   578
	mutex_exit(&spa_spare_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   579
}
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   580
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   581
/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   582
 * Level 2 ARC devices are tracked globally for the same reasons as spares.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   583
 * Cache devices currently only support one pool per cache device, and so
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   584
 * for these devices the aux reference count is currently unused beyond 1.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   585
 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   586
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   587
static int
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   588
spa_l2cache_compare(const void *a, const void *b)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   589
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   590
	return (spa_aux_compare(a, b));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   591
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   592
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   593
void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   594
spa_l2cache_add(vdev_t *vd)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   595
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   596
	mutex_enter(&spa_l2cache_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   597
	ASSERT(!vd->vdev_isl2cache);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   598
	spa_aux_add(vd, &spa_l2cache_avl);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   599
	vd->vdev_isl2cache = B_TRUE;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   600
	mutex_exit(&spa_l2cache_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   601
}
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   602
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   603
void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   604
spa_l2cache_remove(vdev_t *vd)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   605
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   606
	mutex_enter(&spa_l2cache_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   607
	ASSERT(vd->vdev_isl2cache);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   608
	spa_aux_remove(vd, &spa_l2cache_avl);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   609
	vd->vdev_isl2cache = B_FALSE;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   610
	mutex_exit(&spa_l2cache_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   611
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   612
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   613
boolean_t
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   614
spa_l2cache_exists(uint64_t guid, uint64_t *pool)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   615
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   616
	boolean_t found;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   617
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   618
	mutex_enter(&spa_l2cache_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   619
	found = spa_aux_exists(guid, pool, &spa_l2cache_avl);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   620
	mutex_exit(&spa_l2cache_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   621
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   622
	return (found);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   623
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   624
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   625
void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   626
spa_l2cache_activate(vdev_t *vd)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   627
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   628
	mutex_enter(&spa_l2cache_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   629
	ASSERT(vd->vdev_isl2cache);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   630
	spa_aux_activate(vd, &spa_l2cache_avl);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   631
	mutex_exit(&spa_l2cache_lock);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   632
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   633
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   634
void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   635
spa_l2cache_space_update(vdev_t *vd, int64_t space, int64_t alloc)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   636
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   637
	vdev_space_update(vd, space, alloc, B_FALSE);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   638
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   639
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   640
/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
   641
 * ==========================================================================
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
 * SPA config locking
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   644
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
void
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   646
spa_config_enter(spa_t *spa, krw_t rw, void *tag)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
{
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4620
diff changeset
   648
	rprw_enter(&spa->spa_config_lock, rw, tag);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   649
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   651
void
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   652
spa_config_exit(spa_t *spa, void *tag)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   653
{
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4620
diff changeset
   654
	rprw_exit(&spa->spa_config_lock, tag);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   655
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   656
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   657
boolean_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   658
spa_config_held(spa_t *spa, krw_t rw)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   659
{
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4620
diff changeset
   660
	return (rprw_held(&spa->spa_config_lock, rw));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   661
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   662
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   663
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   664
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   665
 * SPA vdev locking
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   666
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   667
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   669
/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   670
 * Lock the given spa_t for the purpose of adding or removing a vdev.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   671
 * Grabs the global spa_namespace_lock plus the spa config lock for writing.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   672
 * It returns the next transaction group for the spa_t.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   673
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   674
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   675
spa_vdev_enter(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   676
{
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3912
diff changeset
   677
	mutex_enter(&spa_namespace_lock);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3912
diff changeset
   678
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   679
	/*
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3912
diff changeset
   680
	 * Suspend scrub activity while we mess with the config.  We must do
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3912
diff changeset
   681
	 * this after acquiring the namespace lock to avoid a 3-way deadlock
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3912
diff changeset
   682
	 * with spa_scrub_stop() and the scrub thread.
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   683
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   684
	spa_scrub_suspend(spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   685
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   686
	spa_config_enter(spa, RW_WRITER, spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
	return (spa_last_synced_txg(spa) + 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   689
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   690
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   691
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
 * Unlock the spa_t after adding or removing a vdev.  Besides undoing the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   693
 * locking of spa_vdev_enter(), we also want make sure the transactions have
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
 * synced to disk, and then update the global configuration cache with the new
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
 * information.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
{
1585
4ad213e858a9 6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents: 1544
diff changeset
   700
	int config_changed = B_FALSE;
4ad213e858a9 6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents: 1544
diff changeset
   701
1635
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   702
	ASSERT(txg > spa_last_synced_txg(spa));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   704
	/*
1585
4ad213e858a9 6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents: 1544
diff changeset
   705
	 * Reassess the DTLs.
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   706
	 */
1635
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   707
	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
   708
4ad213e858a9 6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents: 1544
diff changeset
   709
	/*
1635
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   710
	 * 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
   711
	 */
4ad213e858a9 6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents: 1544
diff changeset
   712
	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
   713
		config_changed = B_TRUE;
1635
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   714
		spa_scrub_restart(spa, txg);
1585
4ad213e858a9 6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents: 1544
diff changeset
   715
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   716
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   717
	spa_config_exit(spa, spa);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   718
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   719
	/*
1601
438b928f80c7 6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents: 1585
diff changeset
   720
	 * Allow scrubbing to resume.
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   721
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   722
	spa_scrub_resume(spa);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   723
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   724
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   725
	 * Note: this txg_wait_synced() is important because it ensures
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   726
	 * that there won't be more than one config change per txg.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   727
	 * This allows us to use the txg as the generation number.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   728
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   729
	if (error == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
		txg_wait_synced(spa->spa_dsl_pool, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   731
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
	if (vd != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   733
		ASSERT(!vd->vdev_detached || vd->vdev_dtl.smo_object == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   734
		vdev_free(vd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   735
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   736
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
	/*
1585
4ad213e858a9 6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents: 1544
diff changeset
   738
	 * If the config changed, update the config cache.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   739
	 */
1585
4ad213e858a9 6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents: 1544
diff changeset
   740
	if (config_changed)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   741
		spa_config_sync();
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   742
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   743
	mutex_exit(&spa_namespace_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   745
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   746
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   747
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   748
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   749
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
 * Miscellaneous functions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
 * Rename a spa_t.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
spa_rename(const char *name, const char *newname)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   762
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   763
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
	 * Lookup the spa_t and grab the config lock for writing.  We need to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
	 * actually open the pool so that we can sync out the necessary labels.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
	 * It's OK to call spa_open() with the namespace lock held because we
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   767
	 * allow recursive calls for other reasons.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   768
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   769
	mutex_enter(&spa_namespace_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   770
	if ((err = spa_open(name, &spa, FTAG)) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   771
		mutex_exit(&spa_namespace_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
		return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   775
	spa_config_enter(spa, RW_WRITER, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
	avl_remove(&spa_namespace_avl, spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
	spa_strfree(spa->spa_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
	spa->spa_name = spa_strdup(newname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
	avl_add(&spa_namespace_avl, spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
	 * Sync all labels to disk with the new names by marking the root vdev
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
	 * dirty and waiting for it to sync.  It will pick up the new pool name
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
	 * during the sync.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
	vdev_config_dirty(spa->spa_root_vdev);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   789
	spa_config_exit(spa, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   790
1635
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
   791
	txg_wait_synced(spa->spa_dsl_pool, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
	 * Sync the updated config cache.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   795
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   796
	spa_config_sync();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   797
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   798
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   799
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   800
	mutex_exit(&spa_namespace_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   801
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   802
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   803
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   804
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   806
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   807
 * Determine whether a pool with given pool_guid exists.  If device_guid is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   808
 * non-zero, determine whether the pool exists *and* contains a device with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
 * specified device_guid.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   810
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   811
boolean_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
spa_guid_exists(uint64_t pool_guid, uint64_t device_guid)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   814
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
	avl_tree_t *t = &spa_namespace_avl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   817
	ASSERT(MUTEX_HELD(&spa_namespace_lock));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
	for (spa = avl_first(t); spa != NULL; spa = AVL_NEXT(t, spa)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   820
		if (spa->spa_state == POOL_STATE_UNINITIALIZED)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
		if (spa->spa_root_vdev == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   823
			continue;
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   824
		if (spa_guid(spa) == pool_guid) {
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   825
			if (device_guid == 0)
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   826
				break;
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   827
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   828
			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
   829
			    device_guid) != NULL)
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   830
				break;
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   831
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   832
			/*
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   833
			 * 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
   834
			 */
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   835
			if (spa->spa_pending_vdev) {
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   836
				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
   837
				    device_guid) != NULL)
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   838
					break;
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   839
			}
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 2986
diff changeset
   840
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   841
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   842
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   843
	return (spa != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   845
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   846
char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
spa_strdup(const char *s)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   849
	size_t len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   850
	char *new;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   851
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   852
	len = strlen(s);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   853
	new = kmem_alloc(len + 1, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
	bcopy(s, new, len);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   855
	new[len] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   857
	return (new);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   858
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   859
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
spa_strfree(char *s)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   863
	kmem_free(s, strlen(s) + 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   864
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   865
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   866
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   867
spa_get_random(uint64_t range)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   868
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
	uint64_t r;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   871
	ASSERT(range != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   872
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   873
	(void) random_get_pseudo_bytes((void *)&r, sizeof (uint64_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   874
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   875
	return (r % range);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   877
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   878
void
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
   879
sprintf_blkptr(char *buf, int len, const blkptr_t *bp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   880
{
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
   881
	int d;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   882
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   883
	if (bp == NULL) {
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 789
diff changeset
   884
		(void) snprintf(buf, len, "<NULL>");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   885
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   887
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   888
	if (BP_IS_HOLE(bp)) {
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 789
diff changeset
   889
		(void) snprintf(buf, len, "<hole>");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   890
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   892
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
   893
	(void) snprintf(buf, len, "[L%llu %s] %llxL/%llxP ",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
	    (u_longlong_t)BP_GET_LEVEL(bp),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   895
	    dmu_ot[BP_GET_TYPE(bp)].ot_name,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   896
	    (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
   897
	    (u_longlong_t)BP_GET_PSIZE(bp));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
   898
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
   899
	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
   900
		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
   901
		(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
   902
		    "DVA[%d]=<%llu:%llx:%llx> ", d,
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
   903
		    (u_longlong_t)DVA_GET_VDEV(dva),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
   904
		    (u_longlong_t)DVA_GET_OFFSET(dva),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
   905
		    (u_longlong_t)DVA_GET_ASIZE(dva));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
   906
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
   907
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
   908
	(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
   909
	    "%s %s %s %s birth=%llu fill=%llu cksum=%llx:%llx:%llx:%llx",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   910
	    zio_checksum_table[BP_GET_CHECKSUM(bp)].ci_name,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   911
	    zio_compress_table[BP_GET_COMPRESS(bp)].ci_name,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   912
	    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
   913
	    BP_IS_GANG(bp) ? "gang" : "contiguous",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   914
	    (u_longlong_t)bp->blk_birth,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   915
	    (u_longlong_t)bp->blk_fill,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   916
	    (u_longlong_t)bp->blk_cksum.zc_word[0],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   917
	    (u_longlong_t)bp->blk_cksum.zc_word[1],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   918
	    (u_longlong_t)bp->blk_cksum.zc_word[2],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   919
	    (u_longlong_t)bp->blk_cksum.zc_word[3]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   920
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   921
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   922
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   923
spa_freeze(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   924
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   925
	uint64_t freeze_txg = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   926
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   927
	spa_config_enter(spa, RW_WRITER, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   928
	if (spa->spa_freeze_txg == UINT64_MAX) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   929
		freeze_txg = spa_last_synced_txg(spa) + TXG_SIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   930
		spa->spa_freeze_txg = freeze_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   931
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   932
	spa_config_exit(spa, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   933
	if (freeze_txg != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   934
		txg_wait_synced(spa_get_dsl(spa), freeze_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   935
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   936
3713
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   937
void
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   938
zfs_panic_recover(const char *fmt, ...)
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   939
{
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   940
	va_list adx;
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   941
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   942
	va_start(adx, fmt);
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   943
	vcmn_err(zfs_recover ? CE_WARN : CE_PANIC, fmt, adx);
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   944
	va_end(adx);
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   945
}
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3377
diff changeset
   946
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   947
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   948
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
 * Accessor functions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   950
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   951
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   952
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   953
krwlock_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   954
spa_traverse_rwlock(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   955
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   956
	return (&spa->spa_traverse_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   958
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   959
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
spa_traverse_wanted(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   961
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   962
	return (spa->spa_traverse_wanted);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   963
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   964
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   965
dsl_pool_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
spa_get_dsl(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   967
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   968
	return (spa->spa_dsl_pool);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   969
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   970
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   971
blkptr_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   972
spa_get_rootblkptr(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   973
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   974
	return (&spa->spa_ubsync.ub_rootbp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   975
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   976
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   978
spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   979
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
	spa->spa_uberblock.ub_rootbp = *bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   981
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
spa_altroot(spa_t *spa, char *buf, size_t buflen)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
	if (spa->spa_root == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
		buf[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   988
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   989
		(void) strncpy(buf, spa->spa_root, buflen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   990
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   991
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   992
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   993
spa_sync_pass(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   994
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   995
	return (spa->spa_sync_pass);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   997
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   998
char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   999
spa_name(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1000
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1001
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1002
	 * Accessing the name requires holding either the namespace lock or the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1003
	 * config lock, both of which are required to do a rename.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1004
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
	ASSERT(MUTEX_HELD(&spa_namespace_lock) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1006
	    spa_config_held(spa, RW_READER) || spa_config_held(spa, RW_WRITER));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1007
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1008
	return (spa->spa_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1009
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1011
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1012
spa_guid(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1013
{
2174
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2082
diff changeset
  1014
	/*
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2082
diff changeset
  1015
	 * 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
  1016
	 * 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
  1017
	 * 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
  1018
	 * this case.
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2082
diff changeset
  1019
	 */
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2082
diff changeset
  1020
	if (spa->spa_root_vdev != NULL)
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2082
diff changeset
  1021
		return (spa->spa_root_vdev->vdev_guid);
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2082
diff changeset
  1022
	else
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2082
diff changeset
  1023
		return (spa->spa_load_guid);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1024
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1025
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1026
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
spa_last_synced_txg(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1028
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1029
	return (spa->spa_ubsync.ub_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1030
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1031
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1032
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1033
spa_first_txg(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1034
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1035
	return (spa->spa_first_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1036
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1037
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1038
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1039
spa_state(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1041
	return (spa->spa_state);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1044
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1045
spa_freeze_txg(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1046
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1047
	return (spa->spa_freeze_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1048
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1049
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1050
/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1051
 * Return how much space is allocated in the pool (ie. sum of all asize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1052
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1053
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1054
spa_get_alloc(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1055
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1056
	return (spa->spa_root_vdev->vdev_stat.vs_alloc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1057
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1058
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1059
/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1060
 * Return how much (raid-z inflated) space there is in the pool.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1061
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1062
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1063
spa_get_space(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1064
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1065
	return (spa->spa_root_vdev->vdev_stat.vs_space);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1066
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1067
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1068
/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1069
 * Return the amount of raid-z-deflated space in the pool.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1070
 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1071
uint64_t
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1072
spa_get_dspace(spa_t *spa)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1073
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1074
	if (spa->spa_deflate)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1075
		return (spa->spa_root_vdev->vdev_stat.vs_dspace);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1076
	else
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1077
		return (spa->spa_root_vdev->vdev_stat.vs_space);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1078
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1079
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1081
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1082
spa_get_asize(spa_t *spa, uint64_t lsize)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1083
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1084
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1085
	 * For now, the worst case is 512-byte RAID-Z blocks, in which
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1086
	 * 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
  1087
	 * 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
  1088
	 * we have to multiply by a total of 6x.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
	 */
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1090
	return (lsize * 6);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1091
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1092
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5094
diff changeset
  1093
/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5094
diff changeset
  1094
 * Return the failure mode that has been set to this pool. The default
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5094
diff changeset
  1095
 * behavior will be to block all I/Os when a complete failure occurs.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5094
diff changeset
  1096
 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5094
diff changeset
  1097
uint8_t
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5094
diff changeset
  1098
spa_get_failmode(spa_t *spa)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5094
diff changeset
  1099
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5094
diff changeset
  1100
	return (spa->spa_failmode);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5094
diff changeset
  1101
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5094
diff changeset
  1102
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1103
uint64_t
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1104
spa_version(spa_t *spa)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1105
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1106
	return (spa->spa_ubsync.ub_version);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1107
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1108
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1109
int
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1110
spa_max_replication(spa_t *spa)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1111
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1112
	/*
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4527
diff changeset
  1113
	 * 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
  1114
	 * 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
  1115
	 * replication level accordingly.
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1116
	 */
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4527
diff changeset
  1117
	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
  1118
		return (1);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1635
diff changeset
  1119
	return (MIN(SPA_DVAS_PER_BP, spa_max_replication_override));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1120
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1121
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1122
uint64_t
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1123
bp_get_dasize(spa_t *spa, const blkptr_t *bp)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1124
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1125
	int sz = 0, i;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1126
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1127
	if (!spa->spa_deflate)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1128
		return (BP_GET_ASIZE(bp));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1129
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4831
diff changeset
  1130
	spa_config_enter(spa, RW_READER, FTAG);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1131
	for (i = 0; i < SPA_DVAS_PER_BP; i++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1132
		vdev_t *vd =
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1133
		    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
  1134
		if (vd)
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4831
diff changeset
  1135
			sz += (DVA_GET_ASIZE(&bp->blk_dva[i]) >>
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4831
diff changeset
  1136
			    SPA_MINBLOCKSHIFT) * vd->vdev_deflate_ratio;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1137
	}
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4831
diff changeset
  1138
	spa_config_exit(spa, FTAG);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1139
	return (sz);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1140
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1141
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1142
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1143
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1144
 * Initialization and Termination
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1145
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1146
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1147
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1148
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1149
spa_name_compare(const void *a1, const void *a2)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1150
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1151
	const spa_t *s1 = a1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1152
	const spa_t *s2 = a2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1153
	int s;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1154
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1155
	s = strcmp(s1->spa_name, s2->spa_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1156
	if (s > 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1157
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1158
	if (s < 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1160
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1161
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1162
1635
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
  1163
int
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
  1164
spa_busy(void)
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
  1165
{
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
  1166
	return (spa_active_count);
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
  1167
}
0ab1193d47cb 6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents: 1601
diff changeset
  1168
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1169
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
spa_init(int mode)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1171
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1172
	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
  1173
	mutex_init(&spa_spare_lock, NULL, MUTEX_DEFAULT, NULL);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1174
	mutex_init(&spa_l2cache_lock, NULL, MUTEX_DEFAULT, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1175
	cv_init(&spa_namespace_cv, NULL, CV_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1176
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1177
	avl_create(&spa_namespace_avl, spa_name_compare, sizeof (spa_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
	    offsetof(spa_t, spa_avl));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1179
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1180
	avl_create(&spa_spare_avl, spa_spare_compare, sizeof (spa_aux_t),
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1181
	    offsetof(spa_aux_t, aux_avl));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1182
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1183
	avl_create(&spa_l2cache_avl, spa_l2cache_compare, sizeof (spa_aux_t),
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1184
	    offsetof(spa_aux_t, aux_avl));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1185
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1186
	spa_mode = mode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
	refcount_init();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
	unique_init();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
	zio_init();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1191
	dmu_init();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1192
	zil_init();
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4620
diff changeset
  1193
	zfs_prop_init();
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4944
diff changeset
  1194
	zpool_prop_init();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1195
	spa_config_load();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1197
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1198
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1199
spa_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1200
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1201
	spa_evict_all();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
	zil_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1204
	dmu_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1205
	zio_fini();
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4620
diff changeset
  1206
	unique_fini();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
	refcount_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1208
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1209
	avl_destroy(&spa_namespace_avl);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1807
diff changeset
  1210
	avl_destroy(&spa_spare_avl);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1211
	avl_destroy(&spa_l2cache_avl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1212
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
	cv_destroy(&spa_namespace_cv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
	mutex_destroy(&spa_namespace_lock);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
  1215
	mutex_destroy(&spa_spare_lock);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1216
	mutex_destroy(&spa_l2cache_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1217
}
4620
4895df7f426f 6574298 slog still uses main pool for dmu_sync()
perrin
parents: 4603
diff changeset
  1218
4895df7f426f 6574298 slog still uses main pool for dmu_sync()
perrin
parents: 4603
diff changeset
  1219
/*
4895df7f426f 6574298 slog still uses main pool for dmu_sync()
perrin
parents: 4603
diff changeset
  1220
 * Return whether this pool has slogs. No locking needed.
4895df7f426f 6574298 slog still uses main pool for dmu_sync()
perrin
parents: 4603
diff changeset
  1221
 * It's not a problem if the wrong answer is returned as it's only for
4895df7f426f 6574298 slog still uses main pool for dmu_sync()
perrin
parents: 4603
diff changeset
  1222
 * performance and not correctness
4895df7f426f 6574298 slog still uses main pool for dmu_sync()
perrin
parents: 4603
diff changeset
  1223
 */
4895df7f426f 6574298 slog still uses main pool for dmu_sync()
perrin
parents: 4603
diff changeset
  1224
boolean_t
4895df7f426f 6574298 slog still uses main pool for dmu_sync()
perrin
parents: 4603
diff changeset
  1225
spa_has_slogs(spa_t *spa)
4895df7f426f 6574298 slog still uses main pool for dmu_sync()
perrin
parents: 4603
diff changeset
  1226
{
4895df7f426f 6574298 slog still uses main pool for dmu_sync()
perrin
parents: 4603
diff changeset
  1227
	return (spa->spa_log_class->mc_rotor != NULL);
4895df7f426f 6574298 slog still uses main pool for dmu_sync()
perrin
parents: 4603
diff changeset
  1228
}