Print this page
NEX-19592 zfs_dbgmsg should not contain info calculated latency
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
NEX-17348 The ZFS deadman timer is currently set too high
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
Reviewed by: Joyce McIntosh<joyce.macintosh@nexenta.com>
NEX-9200 Improve the scalability of attribute locking in zfs_zget
Reviewed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-13140 DVA-throttle support for special-class
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-9989 Changing volume names can result in double imports and data corruption
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-10069 ZFS_READONLY is a little too strict (fix test lint)
NEX-9553 Move ss_fill gap logic from scan algorithm into range_tree.c
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-6088 ZFS scrub/resilver take excessively long due to issuing lots of random IO
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-5856 ddt_capped isn't reset when deduped dataset is destroyed
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
NEX-5553 ZFS auto-trim, manual-trim and scrub can race and deadlock
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-5795 Rename 'wrc' as 'wbc' in the source and in the tech docs
Reviewed by: Alex Aizman <alex.aizman@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
NEX-5064 On-demand trim should store operation start and stop time
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
NEX-5188 Removed special-vdev causes panic on read or on get size of special-bp
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-5186 smf-tests contains built files and it shouldn't
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Steve Peng <steve.peng@nexenta.com>
NEX-5168 cleanup and productize non-default latency based writecache load-balancer
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
NEX-3729 KRRP changes mess up iostat(1M)
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-4807 writecache load-balancing statistics: several distinct problems, must be revisited and revised
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
NEX-4876 On-demand TRIM shouldn't use system_taskq and should queue jobs
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
NEX-4683 WRC: Special block pointer must know that it is special
Reviewed by: Alex Aizman <alex.aizman@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
NEX-4677 Fix for NEX-4619 build breakage
NEX-4620 ZFS autotrim triggering is unreliable
NEX-4622 On-demand TRIM code illogically enumerates metaslabs via mg_ms_tree
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
NEX-4619 Want kstats to monitor TRIM and UNMAP operation
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
4185 add new cryptographic checksums to ZFS: SHA-512, Skein, Edon-R (fix studio build)
4185 add new cryptographic checksums to ZFS: SHA-512, Skein, Edon-R
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Approved by: Garrett D'Amore <garrett@damore.org>
5818 zfs {ref}compressratio is incorrect with 4k sector size
Reviewed by: Alex Reece <alex@delphix.com>
Reviewed by: George Wilson <george@delphix.com>
Reviewed by: Richard Elling <richard.elling@richardelling.com>
Reviewed by: Steven Hartland <killing@multiplay.co.uk>
Reviewed by: Don Brady <dev.fs.zfs@gmail.com>
Approved by: Albert Lee <trisk@omniti.com>
NEX-4476 WRC: Allow to use write back cache per tree of datasets
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Alex Aizman <alex.aizman@nexenta.com>
Revert "NEX-4476 WRC: Allow to use write back cache per tree of datasets"
This reverts commit fe97b74444278a6f36fec93179133641296312da.
NEX-4476 WRC: Allow to use write back cache per tree of datasets
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Alex Aizman <alex.aizman@nexenta.com>
NEX-4245 WRC: Code cleanup and refactoring to simplify merge with upstream
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Alex Aizman <alex.aizman@nexenta.com>
NEX-4203 spa_config_tryenter incorrectly handles the multiple-lock case
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
NEX-3965 System may panic on the importing of pool with WRC
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Revert "NEX-3965 System may panic on the importing of pool with WRC"
This reverts commit 45bc50222913cddafde94621d28b78d6efaea897.
NEX-3984 On-demand TRIM
Reviewed by: Alek Pinchuk <alek@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Conflicts:
usr/src/common/zfs/zpool_prop.c
usr/src/uts/common/sys/fs/zfs.h
NEX-3965 System may panic on the importing of pool with WRC
Reviewed by: Alex Aizman <alex.aizman@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
NEX-3558 KRRP Integration
NEX-3508 CLONE - Port NEX-2946 Add UNMAP/TRIM functionality to ZFS and illumos
Reviewed by: Josef Sipek <josef.sipek@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Conflicts:
usr/src/uts/common/io/scsi/targets/sd.c
usr/src/uts/common/sys/scsi/targets/sddef.h
NEX-3165 need some dedup improvements
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
4391 panic system rather than corrupting pool if we hit bug 4390
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Approved by: Gordon Ross <gwr@nexenta.com>
4370 avoid transmitting holes during zfs send
4371 DMU code clean up
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Approved by: Garrett D'Amore <garrett@damore.org>
OS-114 Heap leak when exporting/destroying pools with CoS
SUP-577 deadlock between zpool detach and syseventd
OS-80 support for vdev and CoS properties for the new I/O scheduler
OS-95 lint warning introduced by OS-61
Fixup merge results
re #13333 rb4362 - eliminated spa_update_iotime() to fix the stats
re #12643 rb4064 ZFS meta refactoring - vdev utilization tracking, auto-dedup
re #12585 rb4049 ZFS++ work port - refactoring to improve separation of open/closed code, bug fixes, performance improvements - open code
re #8346 rb2639 KT disk failures
Bug 11205: add missing libzfs_closed_stubs.c to fix opensource-only build.
ZFS plus work: special vdevs, cos, cos/vdev properties
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/zfs/spa_misc.c
+++ new/usr/src/uts/common/fs/zfs/spa_misc.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
|
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
24 - * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
25 24 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
25 + * Copyright 2019 Nexenta Systems, Inc. All rights reserved.
26 26 * Copyright 2013 Saso Kiselkov. All rights reserved.
27 27 * Copyright (c) 2014 Integros [integros.com]
28 28 * Copyright (c) 2017 Datto Inc.
29 29 */
30 30
31 31 #include <sys/zfs_context.h>
32 32 #include <sys/spa_impl.h>
33 33 #include <sys/spa_boot.h>
34 34 #include <sys/zio.h>
35 35 #include <sys/zio_checksum.h>
36 36 #include <sys/zio_compress.h>
37 37 #include <sys/dmu.h>
38 38 #include <sys/dmu_tx.h>
39 39 #include <sys/zap.h>
40 40 #include <sys/zil.h>
41 41 #include <sys/vdev_impl.h>
42 42 #include <sys/metaslab.h>
43 43 #include <sys/uberblock_impl.h>
44 44 #include <sys/txg.h>
|
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
45 45 #include <sys/avl.h>
46 46 #include <sys/unique.h>
47 47 #include <sys/dsl_pool.h>
48 48 #include <sys/dsl_dir.h>
49 49 #include <sys/dsl_prop.h>
50 50 #include <sys/dsl_scan.h>
51 51 #include <sys/fs/zfs.h>
52 52 #include <sys/metaslab_impl.h>
53 53 #include <sys/arc.h>
54 54 #include <sys/ddt.h>
55 +#include <sys/cos.h>
55 56 #include "zfs_prop.h"
56 57 #include <sys/zfeature.h>
57 58
58 59 /*
59 60 * SPA locking
60 61 *
61 62 * There are four basic locks for managing spa_t structures:
62 63 *
63 64 * spa_namespace_lock (global mutex)
64 65 *
65 66 * This lock must be acquired to do any of the following:
66 67 *
67 68 * - Lookup a spa_t by name
68 69 * - Add or remove a spa_t from the namespace
69 70 * - Increase spa_refcount from non-zero
70 71 * - Check if spa_refcount is zero
71 72 * - Rename a spa_t
72 73 * - add/remove/attach/detach devices
73 74 * - Held for the duration of create/destroy/import/export
74 75 *
75 76 * It does not need to handle recursion. A create or destroy may
76 77 * reference objects (files or zvols) in other pools, but by
77 78 * definition they must have an existing reference, and will never need
78 79 * to lookup a spa_t by name.
79 80 *
80 81 * spa_refcount (per-spa refcount_t protected by mutex)
81 82 *
82 83 * This reference count keep track of any active users of the spa_t. The
83 84 * spa_t cannot be destroyed or freed while this is non-zero. Internally,
84 85 * the refcount is never really 'zero' - opening a pool implicitly keeps
85 86 * some references in the DMU. Internally we check against spa_minref, but
86 87 * present the image of a zero/non-zero value to consumers.
87 88 *
88 89 * spa_config_lock[] (per-spa array of rwlocks)
89 90 *
90 91 * This protects the spa_t from config changes, and must be held in
91 92 * the following circumstances:
92 93 *
93 94 * - RW_READER to perform I/O to the spa
94 95 * - RW_WRITER to change the vdev config
95 96 *
96 97 * The locking order is fairly straightforward:
97 98 *
98 99 * spa_namespace_lock -> spa_refcount
99 100 *
100 101 * The namespace lock must be acquired to increase the refcount from 0
101 102 * or to check if it is zero.
102 103 *
103 104 * spa_refcount -> spa_config_lock[]
104 105 *
105 106 * There must be at least one valid reference on the spa_t to acquire
106 107 * the config lock.
107 108 *
108 109 * spa_namespace_lock -> spa_config_lock[]
109 110 *
110 111 * The namespace lock must always be taken before the config lock.
111 112 *
112 113 *
113 114 * The spa_namespace_lock can be acquired directly and is globally visible.
114 115 *
115 116 * The namespace is manipulated using the following functions, all of which
116 117 * require the spa_namespace_lock to be held.
117 118 *
118 119 * spa_lookup() Lookup a spa_t by name.
119 120 *
120 121 * spa_add() Create a new spa_t in the namespace.
121 122 *
122 123 * spa_remove() Remove a spa_t from the namespace. This also
123 124 * frees up any memory associated with the spa_t.
124 125 *
125 126 * spa_next() Returns the next spa_t in the system, or the
126 127 * first if NULL is passed.
127 128 *
128 129 * spa_evict_all() Shutdown and remove all spa_t structures in
129 130 * the system.
130 131 *
131 132 * spa_guid_exists() Determine whether a pool/device guid exists.
132 133 *
133 134 * The spa_refcount is manipulated using the following functions:
134 135 *
135 136 * spa_open_ref() Adds a reference to the given spa_t. Must be
136 137 * called with spa_namespace_lock held if the
137 138 * refcount is currently zero.
138 139 *
139 140 * spa_close() Remove a reference from the spa_t. This will
140 141 * not free the spa_t or remove it from the
141 142 * namespace. No locking is required.
142 143 *
143 144 * spa_refcount_zero() Returns true if the refcount is currently
144 145 * zero. Must be called with spa_namespace_lock
145 146 * held.
146 147 *
147 148 * The spa_config_lock[] is an array of rwlocks, ordered as follows:
148 149 * SCL_CONFIG > SCL_STATE > SCL_ALLOC > SCL_ZIO > SCL_FREE > SCL_VDEV.
149 150 * spa_config_lock[] is manipulated with spa_config_{enter,exit,held}().
150 151 *
151 152 * To read the configuration, it suffices to hold one of these locks as reader.
152 153 * To modify the configuration, you must hold all locks as writer. To modify
153 154 * vdev state without altering the vdev tree's topology (e.g. online/offline),
154 155 * you must hold SCL_STATE and SCL_ZIO as writer.
155 156 *
156 157 * We use these distinct config locks to avoid recursive lock entry.
157 158 * For example, spa_sync() (which holds SCL_CONFIG as reader) induces
158 159 * block allocations (SCL_ALLOC), which may require reading space maps
159 160 * from disk (dmu_read() -> zio_read() -> SCL_ZIO).
160 161 *
161 162 * The spa config locks cannot be normal rwlocks because we need the
162 163 * ability to hand off ownership. For example, SCL_ZIO is acquired
163 164 * by the issuing thread and later released by an interrupt thread.
164 165 * They do, however, obey the usual write-wanted semantics to prevent
165 166 * writer (i.e. system administrator) starvation.
166 167 *
167 168 * The lock acquisition rules are as follows:
168 169 *
169 170 * SCL_CONFIG
170 171 * Protects changes to the vdev tree topology, such as vdev
171 172 * add/remove/attach/detach. Protects the dirty config list
172 173 * (spa_config_dirty_list) and the set of spares and l2arc devices.
173 174 *
174 175 * SCL_STATE
175 176 * Protects changes to pool state and vdev state, such as vdev
176 177 * online/offline/fault/degrade/clear. Protects the dirty state list
177 178 * (spa_state_dirty_list) and global pool state (spa_state).
178 179 *
179 180 * SCL_ALLOC
180 181 * Protects changes to metaslab groups and classes.
181 182 * Held as reader by metaslab_alloc() and metaslab_claim().
182 183 *
183 184 * SCL_ZIO
184 185 * Held by bp-level zios (those which have no io_vd upon entry)
185 186 * to prevent changes to the vdev tree. The bp-level zio implicitly
186 187 * protects all of its vdev child zios, which do not hold SCL_ZIO.
187 188 *
188 189 * SCL_FREE
189 190 * Protects changes to metaslab groups and classes.
190 191 * Held as reader by metaslab_free(). SCL_FREE is distinct from
191 192 * SCL_ALLOC, and lower than SCL_ZIO, so that we can safely free
192 193 * blocks in zio_done() while another i/o that holds either
193 194 * SCL_ALLOC or SCL_ZIO is waiting for this i/o to complete.
194 195 *
195 196 * SCL_VDEV
196 197 * Held as reader to prevent changes to the vdev tree during trivial
197 198 * inquiries such as bp_get_dsize(). SCL_VDEV is distinct from the
198 199 * other locks, and lower than all of them, to ensure that it's safe
199 200 * to acquire regardless of caller context.
200 201 *
201 202 * In addition, the following rules apply:
202 203 *
203 204 * (a) spa_props_lock protects pool properties, spa_config and spa_config_list.
204 205 * The lock ordering is SCL_CONFIG > spa_props_lock.
205 206 *
206 207 * (b) I/O operations on leaf vdevs. For any zio operation that takes
207 208 * an explicit vdev_t argument -- such as zio_ioctl(), zio_read_phys(),
208 209 * or zio_write_phys() -- the caller must ensure that the config cannot
209 210 * cannot change in the interim, and that the vdev cannot be reopened.
210 211 * SCL_STATE as reader suffices for both.
211 212 *
212 213 * The vdev configuration is protected by spa_vdev_enter() / spa_vdev_exit().
213 214 *
214 215 * spa_vdev_enter() Acquire the namespace lock and the config lock
215 216 * for writing.
216 217 *
217 218 * spa_vdev_exit() Release the config lock, wait for all I/O
218 219 * to complete, sync the updated configs to the
|
↓ open down ↓ |
154 lines elided |
↑ open up ↑ |
219 220 * cache, and release the namespace lock.
220 221 *
221 222 * vdev state is protected by spa_vdev_state_enter() / spa_vdev_state_exit().
222 223 * Like spa_vdev_enter/exit, these are convenience wrappers -- the actual
223 224 * locking is, always, based on spa_namespace_lock and spa_config_lock[].
224 225 *
225 226 * spa_rename() is also implemented within this file since it requires
226 227 * manipulation of the namespace.
227 228 */
228 229
230 +struct spa_trimstats {
231 + kstat_named_t st_extents; /* # of extents issued to zio */
232 + kstat_named_t st_bytes; /* # of bytes issued to zio */
233 + kstat_named_t st_extents_skipped; /* # of extents too small */
234 + kstat_named_t st_bytes_skipped; /* bytes in extents_skipped */
235 + kstat_named_t st_auto_slow; /* trim slow, exts dropped */
236 +};
237 +
229 238 static avl_tree_t spa_namespace_avl;
230 239 kmutex_t spa_namespace_lock;
231 240 static kcondvar_t spa_namespace_cv;
232 241 static int spa_active_count;
233 242 int spa_max_replication_override = SPA_DVAS_PER_BP;
234 243
235 244 static kmutex_t spa_spare_lock;
236 245 static avl_tree_t spa_spare_avl;
237 246 static kmutex_t spa_l2cache_lock;
238 247 static avl_tree_t spa_l2cache_avl;
239 248
240 249 kmem_cache_t *spa_buffer_pool;
241 250 int spa_mode_global;
242 251
243 252 #ifdef ZFS_DEBUG
244 -/*
245 - * Everything except dprintf, spa, and indirect_remap is on by default
246 - * in debug builds.
247 - */
248 -int zfs_flags = ~(ZFS_DEBUG_DPRINTF | ZFS_DEBUG_SPA | ZFS_DEBUG_INDIRECT_REMAP);
253 +/* Everything except dprintf and spa is on by default in debug builds */
254 +int zfs_flags = ~(ZFS_DEBUG_DPRINTF | ZFS_DEBUG_SPA);
249 255 #else
250 256 int zfs_flags = 0;
251 257 #endif
252 258
259 +#define ZFS_OBJ_MTX_DEFAULT_SZ 64
260 +uint64_t spa_obj_mtx_sz = ZFS_OBJ_MTX_DEFAULT_SZ;
261 +
253 262 /*
254 263 * zfs_recover can be set to nonzero to attempt to recover from
255 264 * otherwise-fatal errors, typically caused by on-disk corruption. When
256 265 * set, calls to zfs_panic_recover() will turn into warning messages.
257 266 * This should only be used as a last resort, as it typically results
258 267 * in leaked space, or worse.
259 268 */
260 269 boolean_t zfs_recover = B_FALSE;
261 270
262 271 /*
263 272 * If destroy encounters an EIO while reading metadata (e.g. indirect
264 273 * blocks), space referenced by the missing metadata can not be freed.
265 274 * Normally this causes the background destroy to become "stalled", as
266 275 * it is unable to make forward progress. While in this stalled state,
267 276 * all remaining space to free from the error-encountering filesystem is
268 277 * "temporarily leaked". Set this flag to cause it to ignore the EIO,
269 278 * permanently leak the space from indirect blocks that can not be read,
270 279 * and continue to free everything else that it can.
271 280 *
272 281 * The default, "stalling" behavior is useful if the storage partially
273 282 * fails (i.e. some but not all i/os fail), and then later recovers. In
274 283 * this case, we will be able to continue pool operations while it is
275 284 * partially failed, and when it recovers, we can continue to free the
276 285 * space, with no leaks. However, note that this case is actually
277 286 * fairly rare.
278 287 *
279 288 * Typically pools either (a) fail completely (but perhaps temporarily,
280 289 * e.g. a top-level vdev going offline), or (b) have localized,
281 290 * permanent errors (e.g. disk returns the wrong data due to bit flip or
282 291 * firmware bug). In case (a), this setting does not matter because the
283 292 * pool will be suspended and the sync thread will not be able to make
|
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
284 293 * forward progress regardless. In case (b), because the error is
285 294 * permanent, the best we can do is leak the minimum amount of space,
286 295 * which is what setting this flag will do. Therefore, it is reasonable
287 296 * for this flag to normally be set, but we chose the more conservative
288 297 * approach of not setting it, so that there is no possibility of
289 298 * leaking space in the "partial temporary" failure case.
290 299 */
291 300 boolean_t zfs_free_leak_on_eio = B_FALSE;
292 301
293 302 /*
303 + * alpha for spa_update_latency() rolling average of pool latency, which
304 + * is updated on every txg commit.
305 + */
306 +int64_t zfs_root_latency_alpha = 10;
307 +
308 +/*
294 309 * Expiration time in milliseconds. This value has two meanings. First it is
295 310 * used to determine when the spa_deadman() logic should fire. By default the
296 - * spa_deadman() will fire if spa_sync() has not completed in 1000 seconds.
311 + * spa_deadman() will fire if spa_sync() has not completed in 250 seconds.
297 312 * Secondly, the value determines if an I/O is considered "hung". Any I/O that
298 313 * has not completed in zfs_deadman_synctime_ms is considered "hung" resulting
299 314 * in a system panic.
300 315 */
301 -uint64_t zfs_deadman_synctime_ms = 1000000ULL;
316 +uint64_t zfs_deadman_synctime_ms = 250000ULL;
302 317
303 318 /*
304 319 * Check time in milliseconds. This defines the frequency at which we check
305 320 * for hung I/O.
306 321 */
307 322 uint64_t zfs_deadman_checktime_ms = 5000ULL;
308 323
309 324 /*
310 325 * Override the zfs deadman behavior via /etc/system. By default the
311 326 * deadman is enabled except on VMware and sparc deployments.
312 327 */
313 328 int zfs_deadman_enabled = -1;
314 329
315 330 /*
316 331 * The worst case is single-sector max-parity RAID-Z blocks, in which
317 332 * case the space requirement is exactly (VDEV_RAIDZ_MAXPARITY + 1)
318 333 * times the size; so just assume that. Add to this the fact that
319 334 * we can have up to 3 DVAs per bp, and one more factor of 2 because
320 335 * the block may be dittoed with up to 3 DVAs by ddt_sync(). All together,
321 336 * the worst case is:
322 337 * (VDEV_RAIDZ_MAXPARITY + 1) * SPA_DVAS_PER_BP * 2 == 24
323 338 */
324 339 int spa_asize_inflation = 24;
325 340
326 341 /*
327 342 * Normally, we don't allow the last 3.2% (1/(2^spa_slop_shift)) of space in
328 343 * the pool to be consumed. This ensures that we don't run the pool
329 344 * completely out of space, due to unaccounted changes (e.g. to the MOS).
330 345 * It also limits the worst-case time to allocate space. If we have
331 346 * less than this amount of free space, most ZPL operations (e.g. write,
332 347 * create) will return ENOSPC.
333 348 *
334 349 * Certain operations (e.g. file removal, most administrative actions) can
335 350 * use half the slop space. They will only return ENOSPC if less than half
336 351 * the slop space is free. Typically, once the pool has less than the slop
337 352 * space free, the user will use these operations to free up space in the pool.
338 353 * These are the operations that call dsl_pool_adjustedsize() with the netfree
339 354 * argument set to TRUE.
340 355 *
341 356 * A very restricted set of operations are always permitted, regardless of
342 357 * the amount of free space. These are the operations that call
343 358 * dsl_sync_task(ZFS_SPACE_CHECK_NONE), e.g. "zfs destroy". If these
344 359 * operations result in a net increase in the amount of space used,
345 360 * it is possible to run the pool completely out of space, causing it to
346 361 * be permanently read-only.
|
↓ open down ↓ |
35 lines elided |
↑ open up ↑ |
347 362 *
348 363 * Note that on very small pools, the slop space will be larger than
349 364 * 3.2%, in an effort to have it be at least spa_min_slop (128MB),
350 365 * but we never allow it to be more than half the pool size.
351 366 *
352 367 * See also the comments in zfs_space_check_t.
353 368 */
354 369 int spa_slop_shift = 5;
355 370 uint64_t spa_min_slop = 128 * 1024 * 1024;
356 371
357 -/*PRINTFLIKE2*/
358 -void
359 -spa_load_failed(spa_t *spa, const char *fmt, ...)
360 -{
361 - va_list adx;
362 - char buf[256];
372 +static void spa_trimstats_create(spa_t *spa);
373 +static void spa_trimstats_destroy(spa_t *spa);
363 374
364 - va_start(adx, fmt);
365 - (void) vsnprintf(buf, sizeof (buf), fmt, adx);
366 - va_end(adx);
367 -
368 - zfs_dbgmsg("spa_load(%s, config %s): FAILED: %s", spa->spa_name,
369 - spa->spa_trust_config ? "trusted" : "untrusted", buf);
370 -}
371 -
372 -/*PRINTFLIKE2*/
373 -void
374 -spa_load_note(spa_t *spa, const char *fmt, ...)
375 -{
376 - va_list adx;
377 - char buf[256];
378 -
379 - va_start(adx, fmt);
380 - (void) vsnprintf(buf, sizeof (buf), fmt, adx);
381 - va_end(adx);
382 -
383 - zfs_dbgmsg("spa_load(%s, config %s): %s", spa->spa_name,
384 - spa->spa_trust_config ? "trusted" : "untrusted", buf);
385 -}
386 -
387 375 /*
388 376 * ==========================================================================
389 377 * SPA config locking
390 378 * ==========================================================================
391 379 */
392 380 static void
393 381 spa_config_lock_init(spa_t *spa)
394 382 {
395 383 for (int i = 0; i < SCL_LOCKS; i++) {
396 384 spa_config_lock_t *scl = &spa->spa_config_lock[i];
397 385 mutex_init(&scl->scl_lock, NULL, MUTEX_DEFAULT, NULL);
398 386 cv_init(&scl->scl_cv, NULL, CV_DEFAULT, NULL);
399 387 refcount_create_untracked(&scl->scl_count);
400 388 scl->scl_writer = NULL;
401 389 scl->scl_write_wanted = 0;
402 390 }
403 391 }
404 392
405 393 static void
406 394 spa_config_lock_destroy(spa_t *spa)
407 395 {
408 396 for (int i = 0; i < SCL_LOCKS; i++) {
409 397 spa_config_lock_t *scl = &spa->spa_config_lock[i];
410 398 mutex_destroy(&scl->scl_lock);
411 399 cv_destroy(&scl->scl_cv);
412 400 refcount_destroy(&scl->scl_count);
413 401 ASSERT(scl->scl_writer == NULL);
414 402 ASSERT(scl->scl_write_wanted == 0);
415 403 }
416 404 }
417 405
418 406 int
419 407 spa_config_tryenter(spa_t *spa, int locks, void *tag, krw_t rw)
420 408 {
421 409 for (int i = 0; i < SCL_LOCKS; i++) {
422 410 spa_config_lock_t *scl = &spa->spa_config_lock[i];
423 411 if (!(locks & (1 << i)))
424 412 continue;
425 413 mutex_enter(&scl->scl_lock);
426 414 if (rw == RW_READER) {
427 415 if (scl->scl_writer || scl->scl_write_wanted) {
428 416 mutex_exit(&scl->scl_lock);
429 417 spa_config_exit(spa, locks & ((1 << i) - 1),
430 418 tag);
431 419 return (0);
432 420 }
433 421 } else {
434 422 ASSERT(scl->scl_writer != curthread);
435 423 if (!refcount_is_zero(&scl->scl_count)) {
436 424 mutex_exit(&scl->scl_lock);
437 425 spa_config_exit(spa, locks & ((1 << i) - 1),
438 426 tag);
439 427 return (0);
440 428 }
441 429 scl->scl_writer = curthread;
442 430 }
443 431 (void) refcount_add(&scl->scl_count, tag);
444 432 mutex_exit(&scl->scl_lock);
445 433 }
446 434 return (1);
447 435 }
448 436
449 437 void
450 438 spa_config_enter(spa_t *spa, int locks, void *tag, krw_t rw)
451 439 {
452 440 int wlocks_held = 0;
453 441
454 442 ASSERT3U(SCL_LOCKS, <, sizeof (wlocks_held) * NBBY);
455 443
456 444 for (int i = 0; i < SCL_LOCKS; i++) {
457 445 spa_config_lock_t *scl = &spa->spa_config_lock[i];
458 446 if (scl->scl_writer == curthread)
459 447 wlocks_held |= (1 << i);
460 448 if (!(locks & (1 << i)))
461 449 continue;
462 450 mutex_enter(&scl->scl_lock);
463 451 if (rw == RW_READER) {
464 452 while (scl->scl_writer || scl->scl_write_wanted) {
465 453 cv_wait(&scl->scl_cv, &scl->scl_lock);
466 454 }
467 455 } else {
468 456 ASSERT(scl->scl_writer != curthread);
|
↓ open down ↓ |
72 lines elided |
↑ open up ↑ |
469 457 while (!refcount_is_zero(&scl->scl_count)) {
470 458 scl->scl_write_wanted++;
471 459 cv_wait(&scl->scl_cv, &scl->scl_lock);
472 460 scl->scl_write_wanted--;
473 461 }
474 462 scl->scl_writer = curthread;
475 463 }
476 464 (void) refcount_add(&scl->scl_count, tag);
477 465 mutex_exit(&scl->scl_lock);
478 466 }
479 - ASSERT3U(wlocks_held, <=, locks);
467 + ASSERT(wlocks_held <= locks);
480 468 }
481 469
482 470 void
483 471 spa_config_exit(spa_t *spa, int locks, void *tag)
484 472 {
485 473 for (int i = SCL_LOCKS - 1; i >= 0; i--) {
486 474 spa_config_lock_t *scl = &spa->spa_config_lock[i];
487 475 if (!(locks & (1 << i)))
488 476 continue;
489 477 mutex_enter(&scl->scl_lock);
490 478 ASSERT(!refcount_is_zero(&scl->scl_count));
491 479 if (refcount_remove(&scl->scl_count, tag) == 0) {
492 480 ASSERT(scl->scl_writer == NULL ||
493 481 scl->scl_writer == curthread);
494 482 scl->scl_writer = NULL; /* OK in either case */
495 483 cv_broadcast(&scl->scl_cv);
496 484 }
497 485 mutex_exit(&scl->scl_lock);
498 486 }
499 487 }
500 488
501 489 int
502 490 spa_config_held(spa_t *spa, int locks, krw_t rw)
503 491 {
504 492 int locks_held = 0;
505 493
506 494 for (int i = 0; i < SCL_LOCKS; i++) {
507 495 spa_config_lock_t *scl = &spa->spa_config_lock[i];
508 496 if (!(locks & (1 << i)))
509 497 continue;
510 498 if ((rw == RW_READER && !refcount_is_zero(&scl->scl_count)) ||
511 499 (rw == RW_WRITER && scl->scl_writer == curthread))
512 500 locks_held |= 1 << i;
513 501 }
514 502
515 503 return (locks_held);
516 504 }
517 505
518 506 /*
519 507 * ==========================================================================
520 508 * SPA namespace functions
521 509 * ==========================================================================
522 510 */
523 511
524 512 /*
525 513 * Lookup the named spa_t in the AVL tree. The spa_namespace_lock must be held.
526 514 * Returns NULL if no matching spa_t is found.
527 515 */
528 516 spa_t *
529 517 spa_lookup(const char *name)
530 518 {
531 519 static spa_t search; /* spa_t is large; don't allocate on stack */
532 520 spa_t *spa;
533 521 avl_index_t where;
534 522 char *cp;
535 523
536 524 ASSERT(MUTEX_HELD(&spa_namespace_lock));
537 525
538 526 (void) strlcpy(search.spa_name, name, sizeof (search.spa_name));
539 527
540 528 /*
541 529 * If it's a full dataset name, figure out the pool name and
542 530 * just use that.
543 531 */
544 532 cp = strpbrk(search.spa_name, "/@#");
545 533 if (cp != NULL)
546 534 *cp = '\0';
547 535
548 536 spa = avl_find(&spa_namespace_avl, &search, &where);
549 537
550 538 return (spa);
551 539 }
552 540
553 541 /*
554 542 * Fires when spa_sync has not completed within zfs_deadman_synctime_ms.
555 543 * If the zfs_deadman_enabled flag is set then it inspects all vdev queues
556 544 * looking for potentially hung I/Os.
557 545 */
558 546 void
559 547 spa_deadman(void *arg)
560 548 {
561 549 spa_t *spa = arg;
562 550
563 551 /*
564 552 * Disable the deadman timer if the pool is suspended.
565 553 */
566 554 if (spa_suspended(spa)) {
567 555 VERIFY(cyclic_reprogram(spa->spa_deadman_cycid, CY_INFINITY));
568 556 return;
569 557 }
570 558
571 559 zfs_dbgmsg("slow spa_sync: started %llu seconds ago, calls %llu",
572 560 (gethrtime() - spa->spa_sync_starttime) / NANOSEC,
573 561 ++spa->spa_deadman_calls);
574 562 if (zfs_deadman_enabled)
575 563 vdev_deadman(spa->spa_root_vdev);
576 564 }
577 565
578 566 /*
579 567 * Create an uninitialized spa_t with the given name. Requires
|
↓ open down ↓ |
90 lines elided |
↑ open up ↑ |
580 568 * spa_namespace_lock. The caller must ensure that the spa_t doesn't already
581 569 * exist by calling spa_lookup() first.
582 570 */
583 571 spa_t *
584 572 spa_add(const char *name, nvlist_t *config, const char *altroot)
585 573 {
586 574 spa_t *spa;
587 575 spa_config_dirent_t *dp;
588 576 cyc_handler_t hdlr;
589 577 cyc_time_t when;
578 + uint64_t guid;
590 579
591 580 ASSERT(MUTEX_HELD(&spa_namespace_lock));
592 581
593 582 spa = kmem_zalloc(sizeof (spa_t), KM_SLEEP);
594 583
595 584 mutex_init(&spa->spa_async_lock, NULL, MUTEX_DEFAULT, NULL);
596 585 mutex_init(&spa->spa_errlist_lock, NULL, MUTEX_DEFAULT, NULL);
597 586 mutex_init(&spa->spa_errlog_lock, NULL, MUTEX_DEFAULT, NULL);
598 587 mutex_init(&spa->spa_evicting_os_lock, NULL, MUTEX_DEFAULT, NULL);
599 588 mutex_init(&spa->spa_history_lock, NULL, MUTEX_DEFAULT, NULL);
600 589 mutex_init(&spa->spa_proc_lock, NULL, MUTEX_DEFAULT, NULL);
601 590 mutex_init(&spa->spa_props_lock, NULL, MUTEX_DEFAULT, NULL);
602 591 mutex_init(&spa->spa_cksum_tmpls_lock, NULL, MUTEX_DEFAULT, NULL);
603 592 mutex_init(&spa->spa_scrub_lock, NULL, MUTEX_DEFAULT, NULL);
604 593 mutex_init(&spa->spa_suspend_lock, NULL, MUTEX_DEFAULT, NULL);
605 594 mutex_init(&spa->spa_vdev_top_lock, NULL, MUTEX_DEFAULT, NULL);
606 595 mutex_init(&spa->spa_iokstat_lock, NULL, MUTEX_DEFAULT, NULL);
607 - mutex_init(&spa->spa_alloc_lock, NULL, MUTEX_DEFAULT, NULL);
596 + mutex_init(&spa->spa_cos_props_lock, NULL, MUTEX_DEFAULT, NULL);
597 + mutex_init(&spa->spa_vdev_props_lock, NULL, MUTEX_DEFAULT, NULL);
598 + mutex_init(&spa->spa_perfmon.perfmon_lock, NULL, MUTEX_DEFAULT, NULL);
608 599
600 + mutex_init(&spa->spa_auto_trim_lock, NULL, MUTEX_DEFAULT, NULL);
601 + mutex_init(&spa->spa_man_trim_lock, NULL, MUTEX_DEFAULT, NULL);
602 +
609 603 cv_init(&spa->spa_async_cv, NULL, CV_DEFAULT, NULL);
610 604 cv_init(&spa->spa_evicting_os_cv, NULL, CV_DEFAULT, NULL);
611 605 cv_init(&spa->spa_proc_cv, NULL, CV_DEFAULT, NULL);
612 606 cv_init(&spa->spa_scrub_io_cv, NULL, CV_DEFAULT, NULL);
613 607 cv_init(&spa->spa_suspend_cv, NULL, CV_DEFAULT, NULL);
608 + cv_init(&spa->spa_auto_trim_done_cv, NULL, CV_DEFAULT, NULL);
609 + cv_init(&spa->spa_man_trim_update_cv, NULL, CV_DEFAULT, NULL);
610 + cv_init(&spa->spa_man_trim_done_cv, NULL, CV_DEFAULT, NULL);
614 611
615 612 for (int t = 0; t < TXG_SIZE; t++)
616 613 bplist_create(&spa->spa_free_bplist[t]);
617 614
618 615 (void) strlcpy(spa->spa_name, name, sizeof (spa->spa_name));
619 616 spa->spa_state = POOL_STATE_UNINITIALIZED;
620 617 spa->spa_freeze_txg = UINT64_MAX;
621 618 spa->spa_final_txg = UINT64_MAX;
622 619 spa->spa_load_max_txg = UINT64_MAX;
623 620 spa->spa_proc = &p0;
624 621 spa->spa_proc_state = SPA_PROC_NONE;
625 - spa->spa_trust_config = B_TRUE;
622 + if (spa_obj_mtx_sz < 1 || spa_obj_mtx_sz > INT_MAX)
623 + spa->spa_obj_mtx_sz = ZFS_OBJ_MTX_DEFAULT_SZ;
624 + else
625 + spa->spa_obj_mtx_sz = spa_obj_mtx_sz;
626 626
627 + /*
628 + * Grabbing the guid here is just so that spa_config_guid_exists can
629 + * check early on to protect against doubled imports of the same pool
630 + * under different names. If the GUID isn't provided here, we will
631 + * let spa generate one later on during spa_load, although in that
632 + * case we might not be able to provide the double-import protection.
633 + */
634 + if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) == 0) {
635 + spa->spa_config_guid = guid;
636 + ASSERT(!spa_config_guid_exists(guid));
637 + }
638 +
627 639 hdlr.cyh_func = spa_deadman;
628 640 hdlr.cyh_arg = spa;
629 641 hdlr.cyh_level = CY_LOW_LEVEL;
630 642
631 643 spa->spa_deadman_synctime = MSEC2NSEC(zfs_deadman_synctime_ms);
632 644
633 645 /*
634 646 * This determines how often we need to check for hung I/Os after
635 647 * the cyclic has already fired. Since checking for hung I/Os is
636 648 * an expensive operation we don't want to check too frequently.
637 649 * Instead wait for 5 seconds before checking again.
638 650 */
639 651 when.cyt_interval = MSEC2NSEC(zfs_deadman_checktime_ms);
640 652 when.cyt_when = CY_INFINITY;
641 653 mutex_enter(&cpu_lock);
642 654 spa->spa_deadman_cycid = cyclic_add(&hdlr, &when);
643 655 mutex_exit(&cpu_lock);
644 656
645 657 refcount_create(&spa->spa_refcount);
646 658 spa_config_lock_init(spa);
647 659
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
648 660 avl_add(&spa_namespace_avl, spa);
649 661
650 662 /*
651 663 * Set the alternate root, if there is one.
652 664 */
653 665 if (altroot) {
654 666 spa->spa_root = spa_strdup(altroot);
655 667 spa_active_count++;
656 668 }
657 669
658 - avl_create(&spa->spa_alloc_tree, zio_bookmark_compare,
659 - sizeof (zio_t), offsetof(zio_t, io_alloc_node));
660 -
661 670 /*
662 671 * Every pool starts with the default cachefile
663 672 */
664 673 list_create(&spa->spa_config_list, sizeof (spa_config_dirent_t),
665 674 offsetof(spa_config_dirent_t, scd_link));
666 675
667 676 dp = kmem_zalloc(sizeof (spa_config_dirent_t), KM_SLEEP);
668 677 dp->scd_path = altroot ? NULL : spa_strdup(spa_config_path);
669 678 list_insert_head(&spa->spa_config_list, dp);
670 679
671 680 VERIFY(nvlist_alloc(&spa->spa_load_info, NV_UNIQUE_NAME,
672 681 KM_SLEEP) == 0);
673 682
674 683 if (config != NULL) {
675 684 nvlist_t *features;
676 685
677 686 if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_FEATURES_FOR_READ,
678 687 &features) == 0) {
679 688 VERIFY(nvlist_dup(features, &spa->spa_label_features,
680 689 0) == 0);
681 690 }
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
682 691
683 692 VERIFY(nvlist_dup(config, &spa->spa_config, 0) == 0);
684 693 }
685 694
686 695 if (spa->spa_label_features == NULL) {
687 696 VERIFY(nvlist_alloc(&spa->spa_label_features, NV_UNIQUE_NAME,
688 697 KM_SLEEP) == 0);
689 698 }
690 699
691 700 spa->spa_iokstat = kstat_create("zfs", 0, name,
692 - "disk", KSTAT_TYPE_IO, 1, 0);
701 + "zfs", KSTAT_TYPE_IO, 1, 0);
693 702 if (spa->spa_iokstat) {
694 703 spa->spa_iokstat->ks_lock = &spa->spa_iokstat_lock;
695 704 kstat_install(spa->spa_iokstat);
696 705 }
697 706
707 + spa_trimstats_create(spa);
708 +
698 709 spa->spa_debug = ((zfs_flags & ZFS_DEBUG_SPA) != 0);
699 710
711 + autosnap_init(spa);
712 +
713 + spa_cos_init(spa);
714 +
715 + spa_special_init(spa);
716 +
700 717 spa->spa_min_ashift = INT_MAX;
701 718 spa->spa_max_ashift = 0;
719 + wbc_init(&spa->spa_wbc, spa);
702 720
703 721 /*
704 722 * As a pool is being created, treat all features as disabled by
705 723 * setting SPA_FEATURE_DISABLED for all entries in the feature
706 724 * refcount cache.
707 725 */
708 726 for (int i = 0; i < SPA_FEATURES; i++) {
709 727 spa->spa_feat_refcount_cache[i] = SPA_FEATURE_DISABLED;
710 728 }
711 729
712 730 return (spa);
713 731 }
714 732
715 733 /*
716 734 * Removes a spa_t from the namespace, freeing up any memory used. Requires
717 735 * spa_namespace_lock. This is called only after the spa_t has been closed and
718 736 * deactivated.
719 737 */
720 738 void
721 739 spa_remove(spa_t *spa)
722 740 {
723 741 spa_config_dirent_t *dp;
724 742
725 743 ASSERT(MUTEX_HELD(&spa_namespace_lock));
726 744 ASSERT(spa->spa_state == POOL_STATE_UNINITIALIZED);
727 745 ASSERT3U(refcount_count(&spa->spa_refcount), ==, 0);
728 746
729 747 nvlist_free(spa->spa_config_splitting);
730 748
731 749 avl_remove(&spa_namespace_avl, spa);
732 750 cv_broadcast(&spa_namespace_cv);
733 751
734 752 if (spa->spa_root) {
735 753 spa_strfree(spa->spa_root);
|
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
736 754 spa_active_count--;
737 755 }
738 756
739 757 while ((dp = list_head(&spa->spa_config_list)) != NULL) {
740 758 list_remove(&spa->spa_config_list, dp);
741 759 if (dp->scd_path != NULL)
742 760 spa_strfree(dp->scd_path);
743 761 kmem_free(dp, sizeof (spa_config_dirent_t));
744 762 }
745 763
746 - avl_destroy(&spa->spa_alloc_tree);
747 764 list_destroy(&spa->spa_config_list);
748 765
766 + wbc_fini(&spa->spa_wbc);
767 +
768 + spa_special_fini(spa);
769 +
770 + spa_cos_fini(spa);
771 +
772 + autosnap_fini(spa);
773 +
749 774 nvlist_free(spa->spa_label_features);
750 775 nvlist_free(spa->spa_load_info);
751 776 spa_config_set(spa, NULL);
752 777
753 778 mutex_enter(&cpu_lock);
754 779 if (spa->spa_deadman_cycid != CYCLIC_NONE)
755 780 cyclic_remove(spa->spa_deadman_cycid);
756 781 mutex_exit(&cpu_lock);
757 782 spa->spa_deadman_cycid = CYCLIC_NONE;
758 783
759 784 refcount_destroy(&spa->spa_refcount);
760 785
761 786 spa_config_lock_destroy(spa);
762 787
788 + spa_trimstats_destroy(spa);
789 +
763 790 kstat_delete(spa->spa_iokstat);
764 791 spa->spa_iokstat = NULL;
765 792
766 793 for (int t = 0; t < TXG_SIZE; t++)
767 794 bplist_destroy(&spa->spa_free_bplist[t]);
768 795
769 796 zio_checksum_templates_free(spa);
770 797
771 798 cv_destroy(&spa->spa_async_cv);
772 799 cv_destroy(&spa->spa_evicting_os_cv);
773 800 cv_destroy(&spa->spa_proc_cv);
774 801 cv_destroy(&spa->spa_scrub_io_cv);
775 802 cv_destroy(&spa->spa_suspend_cv);
803 + cv_destroy(&spa->spa_auto_trim_done_cv);
804 + cv_destroy(&spa->spa_man_trim_update_cv);
805 + cv_destroy(&spa->spa_man_trim_done_cv);
776 806
777 - mutex_destroy(&spa->spa_alloc_lock);
778 807 mutex_destroy(&spa->spa_async_lock);
779 808 mutex_destroy(&spa->spa_errlist_lock);
780 809 mutex_destroy(&spa->spa_errlog_lock);
781 810 mutex_destroy(&spa->spa_evicting_os_lock);
782 811 mutex_destroy(&spa->spa_history_lock);
783 812 mutex_destroy(&spa->spa_proc_lock);
784 813 mutex_destroy(&spa->spa_props_lock);
785 814 mutex_destroy(&spa->spa_cksum_tmpls_lock);
786 815 mutex_destroy(&spa->spa_scrub_lock);
787 816 mutex_destroy(&spa->spa_suspend_lock);
788 817 mutex_destroy(&spa->spa_vdev_top_lock);
789 818 mutex_destroy(&spa->spa_iokstat_lock);
819 + mutex_destroy(&spa->spa_cos_props_lock);
820 + mutex_destroy(&spa->spa_vdev_props_lock);
821 + mutex_destroy(&spa->spa_auto_trim_lock);
822 + mutex_destroy(&spa->spa_man_trim_lock);
790 823
791 824 kmem_free(spa, sizeof (spa_t));
792 825 }
793 826
794 827 /*
795 828 * Given a pool, return the next pool in the namespace, or NULL if there is
796 829 * none. If 'prev' is NULL, return the first pool.
797 830 */
798 831 spa_t *
799 832 spa_next(spa_t *prev)
800 833 {
801 834 ASSERT(MUTEX_HELD(&spa_namespace_lock));
802 835
803 836 if (prev)
804 837 return (AVL_NEXT(&spa_namespace_avl, prev));
805 838 else
806 839 return (avl_first(&spa_namespace_avl));
807 840 }
808 841
809 842 /*
810 843 * ==========================================================================
811 844 * SPA refcount functions
812 845 * ==========================================================================
813 846 */
814 847
815 848 /*
816 849 * Add a reference to the given spa_t. Must have at least one reference, or
817 850 * have the namespace lock held.
818 851 */
819 852 void
820 853 spa_open_ref(spa_t *spa, void *tag)
821 854 {
822 855 ASSERT(refcount_count(&spa->spa_refcount) >= spa->spa_minref ||
823 856 MUTEX_HELD(&spa_namespace_lock));
824 857 (void) refcount_add(&spa->spa_refcount, tag);
825 858 }
826 859
827 860 /*
828 861 * Remove a reference to the given spa_t. Must have at least one reference, or
829 862 * have the namespace lock held.
830 863 */
831 864 void
832 865 spa_close(spa_t *spa, void *tag)
833 866 {
834 867 ASSERT(refcount_count(&spa->spa_refcount) > spa->spa_minref ||
835 868 MUTEX_HELD(&spa_namespace_lock));
836 869 (void) refcount_remove(&spa->spa_refcount, tag);
837 870 }
838 871
839 872 /*
840 873 * Remove a reference to the given spa_t held by a dsl dir that is
841 874 * being asynchronously released. Async releases occur from a taskq
842 875 * performing eviction of dsl datasets and dirs. The namespace lock
843 876 * isn't held and the hold by the object being evicted may contribute to
844 877 * spa_minref (e.g. dataset or directory released during pool export),
845 878 * so the asserts in spa_close() do not apply.
846 879 */
847 880 void
848 881 spa_async_close(spa_t *spa, void *tag)
849 882 {
850 883 (void) refcount_remove(&spa->spa_refcount, tag);
851 884 }
852 885
853 886 /*
854 887 * Check to see if the spa refcount is zero. Must be called with
855 888 * spa_namespace_lock held. We really compare against spa_minref, which is the
856 889 * number of references acquired when opening a pool
857 890 */
858 891 boolean_t
859 892 spa_refcount_zero(spa_t *spa)
860 893 {
861 894 ASSERT(MUTEX_HELD(&spa_namespace_lock));
862 895
863 896 return (refcount_count(&spa->spa_refcount) == spa->spa_minref);
864 897 }
865 898
866 899 /*
867 900 * ==========================================================================
868 901 * SPA spare and l2cache tracking
869 902 * ==========================================================================
870 903 */
871 904
872 905 /*
873 906 * Hot spares and cache devices are tracked using the same code below,
874 907 * for 'auxiliary' devices.
875 908 */
876 909
877 910 typedef struct spa_aux {
878 911 uint64_t aux_guid;
879 912 uint64_t aux_pool;
880 913 avl_node_t aux_avl;
881 914 int aux_count;
882 915 } spa_aux_t;
883 916
884 917 static int
885 918 spa_aux_compare(const void *a, const void *b)
886 919 {
887 920 const spa_aux_t *sa = a;
888 921 const spa_aux_t *sb = b;
889 922
890 923 if (sa->aux_guid < sb->aux_guid)
891 924 return (-1);
892 925 else if (sa->aux_guid > sb->aux_guid)
893 926 return (1);
894 927 else
895 928 return (0);
896 929 }
897 930
898 931 void
899 932 spa_aux_add(vdev_t *vd, avl_tree_t *avl)
900 933 {
901 934 avl_index_t where;
902 935 spa_aux_t search;
903 936 spa_aux_t *aux;
904 937
905 938 search.aux_guid = vd->vdev_guid;
906 939 if ((aux = avl_find(avl, &search, &where)) != NULL) {
907 940 aux->aux_count++;
908 941 } else {
909 942 aux = kmem_zalloc(sizeof (spa_aux_t), KM_SLEEP);
910 943 aux->aux_guid = vd->vdev_guid;
911 944 aux->aux_count = 1;
912 945 avl_insert(avl, aux, where);
913 946 }
914 947 }
915 948
916 949 void
917 950 spa_aux_remove(vdev_t *vd, avl_tree_t *avl)
918 951 {
919 952 spa_aux_t search;
920 953 spa_aux_t *aux;
921 954 avl_index_t where;
922 955
923 956 search.aux_guid = vd->vdev_guid;
924 957 aux = avl_find(avl, &search, &where);
925 958
926 959 ASSERT(aux != NULL);
927 960
928 961 if (--aux->aux_count == 0) {
929 962 avl_remove(avl, aux);
930 963 kmem_free(aux, sizeof (spa_aux_t));
931 964 } else if (aux->aux_pool == spa_guid(vd->vdev_spa)) {
932 965 aux->aux_pool = 0ULL;
933 966 }
934 967 }
935 968
936 969 boolean_t
937 970 spa_aux_exists(uint64_t guid, uint64_t *pool, int *refcnt, avl_tree_t *avl)
938 971 {
939 972 spa_aux_t search, *found;
940 973
941 974 search.aux_guid = guid;
942 975 found = avl_find(avl, &search, NULL);
943 976
944 977 if (pool) {
945 978 if (found)
946 979 *pool = found->aux_pool;
947 980 else
948 981 *pool = 0ULL;
949 982 }
950 983
951 984 if (refcnt) {
952 985 if (found)
953 986 *refcnt = found->aux_count;
954 987 else
955 988 *refcnt = 0;
956 989 }
957 990
958 991 return (found != NULL);
959 992 }
960 993
961 994 void
962 995 spa_aux_activate(vdev_t *vd, avl_tree_t *avl)
963 996 {
964 997 spa_aux_t search, *found;
965 998 avl_index_t where;
966 999
967 1000 search.aux_guid = vd->vdev_guid;
|
↓ open down ↓ |
168 lines elided |
↑ open up ↑ |
968 1001 found = avl_find(avl, &search, &where);
969 1002 ASSERT(found != NULL);
970 1003 ASSERT(found->aux_pool == 0ULL);
971 1004
972 1005 found->aux_pool = spa_guid(vd->vdev_spa);
973 1006 }
974 1007
975 1008 /*
976 1009 * Spares are tracked globally due to the following constraints:
977 1010 *
978 - * - A spare may be part of multiple pools.
979 - * - A spare may be added to a pool even if it's actively in use within
1011 + * - A spare may be part of multiple pools.
1012 + * - A spare may be added to a pool even if it's actively in use within
980 1013 * another pool.
981 - * - A spare in use in any pool can only be the source of a replacement if
1014 + * - A spare in use in any pool can only be the source of a replacement if
982 1015 * the target is a spare in the same pool.
983 1016 *
984 1017 * We keep track of all spares on the system through the use of a reference
985 1018 * counted AVL tree. When a vdev is added as a spare, or used as a replacement
986 1019 * spare, then we bump the reference count in the AVL tree. In addition, we set
987 1020 * the 'vdev_isspare' member to indicate that the device is a spare (active or
988 1021 * inactive). When a spare is made active (used to replace a device in the
989 1022 * pool), we also keep track of which pool its been made a part of.
990 1023 *
991 1024 * The 'spa_spare_lock' protects the AVL tree. These functions are normally
992 1025 * called under the spa_namespace lock as part of vdev reconfiguration. The
993 1026 * separate spare lock exists for the status query path, which does not need to
994 1027 * be completely consistent with respect to other vdev configuration changes.
995 1028 */
996 1029
997 1030 static int
998 1031 spa_spare_compare(const void *a, const void *b)
999 1032 {
1000 1033 return (spa_aux_compare(a, b));
1001 1034 }
1002 1035
1003 1036 void
1004 1037 spa_spare_add(vdev_t *vd)
1005 1038 {
1006 1039 mutex_enter(&spa_spare_lock);
1007 1040 ASSERT(!vd->vdev_isspare);
1008 1041 spa_aux_add(vd, &spa_spare_avl);
1009 1042 vd->vdev_isspare = B_TRUE;
1010 1043 mutex_exit(&spa_spare_lock);
1011 1044 }
1012 1045
1013 1046 void
1014 1047 spa_spare_remove(vdev_t *vd)
1015 1048 {
1016 1049 mutex_enter(&spa_spare_lock);
1017 1050 ASSERT(vd->vdev_isspare);
1018 1051 spa_aux_remove(vd, &spa_spare_avl);
1019 1052 vd->vdev_isspare = B_FALSE;
1020 1053 mutex_exit(&spa_spare_lock);
1021 1054 }
1022 1055
1023 1056 boolean_t
1024 1057 spa_spare_exists(uint64_t guid, uint64_t *pool, int *refcnt)
1025 1058 {
1026 1059 boolean_t found;
1027 1060
1028 1061 mutex_enter(&spa_spare_lock);
1029 1062 found = spa_aux_exists(guid, pool, refcnt, &spa_spare_avl);
1030 1063 mutex_exit(&spa_spare_lock);
1031 1064
1032 1065 return (found);
1033 1066 }
1034 1067
1035 1068 void
1036 1069 spa_spare_activate(vdev_t *vd)
1037 1070 {
1038 1071 mutex_enter(&spa_spare_lock);
1039 1072 ASSERT(vd->vdev_isspare);
1040 1073 spa_aux_activate(vd, &spa_spare_avl);
1041 1074 mutex_exit(&spa_spare_lock);
1042 1075 }
1043 1076
1044 1077 /*
1045 1078 * Level 2 ARC devices are tracked globally for the same reasons as spares.
1046 1079 * Cache devices currently only support one pool per cache device, and so
1047 1080 * for these devices the aux reference count is currently unused beyond 1.
1048 1081 */
1049 1082
1050 1083 static int
1051 1084 spa_l2cache_compare(const void *a, const void *b)
1052 1085 {
1053 1086 return (spa_aux_compare(a, b));
1054 1087 }
1055 1088
1056 1089 void
1057 1090 spa_l2cache_add(vdev_t *vd)
1058 1091 {
1059 1092 mutex_enter(&spa_l2cache_lock);
1060 1093 ASSERT(!vd->vdev_isl2cache);
1061 1094 spa_aux_add(vd, &spa_l2cache_avl);
1062 1095 vd->vdev_isl2cache = B_TRUE;
1063 1096 mutex_exit(&spa_l2cache_lock);
1064 1097 }
1065 1098
1066 1099 void
1067 1100 spa_l2cache_remove(vdev_t *vd)
1068 1101 {
1069 1102 mutex_enter(&spa_l2cache_lock);
1070 1103 ASSERT(vd->vdev_isl2cache);
1071 1104 spa_aux_remove(vd, &spa_l2cache_avl);
1072 1105 vd->vdev_isl2cache = B_FALSE;
1073 1106 mutex_exit(&spa_l2cache_lock);
1074 1107 }
1075 1108
1076 1109 boolean_t
1077 1110 spa_l2cache_exists(uint64_t guid, uint64_t *pool)
1078 1111 {
1079 1112 boolean_t found;
1080 1113
1081 1114 mutex_enter(&spa_l2cache_lock);
1082 1115 found = spa_aux_exists(guid, pool, NULL, &spa_l2cache_avl);
1083 1116 mutex_exit(&spa_l2cache_lock);
1084 1117
1085 1118 return (found);
1086 1119 }
1087 1120
1088 1121 void
1089 1122 spa_l2cache_activate(vdev_t *vd)
1090 1123 {
1091 1124 mutex_enter(&spa_l2cache_lock);
1092 1125 ASSERT(vd->vdev_isl2cache);
1093 1126 spa_aux_activate(vd, &spa_l2cache_avl);
1094 1127 mutex_exit(&spa_l2cache_lock);
1095 1128 }
1096 1129
1097 1130 /*
1098 1131 * ==========================================================================
1099 1132 * SPA vdev locking
1100 1133 * ==========================================================================
1101 1134 */
1102 1135
|
↓ open down ↓ |
111 lines elided |
↑ open up ↑ |
1103 1136 /*
1104 1137 * Lock the given spa_t for the purpose of adding or removing a vdev.
1105 1138 * Grabs the global spa_namespace_lock plus the spa config lock for writing.
1106 1139 * It returns the next transaction group for the spa_t.
1107 1140 */
1108 1141 uint64_t
1109 1142 spa_vdev_enter(spa_t *spa)
1110 1143 {
1111 1144 mutex_enter(&spa->spa_vdev_top_lock);
1112 1145 mutex_enter(&spa_namespace_lock);
1146 + mutex_enter(&spa->spa_auto_trim_lock);
1147 + mutex_enter(&spa->spa_man_trim_lock);
1148 + spa_trim_stop_wait(spa);
1113 1149 return (spa_vdev_config_enter(spa));
1114 1150 }
1115 1151
1116 1152 /*
1117 1153 * Internal implementation for spa_vdev_enter(). Used when a vdev
1118 1154 * operation requires multiple syncs (i.e. removing a device) while
1119 1155 * keeping the spa_namespace_lock held.
1120 1156 */
1121 1157 uint64_t
1122 1158 spa_vdev_config_enter(spa_t *spa)
1123 1159 {
1124 1160 ASSERT(MUTEX_HELD(&spa_namespace_lock));
1125 1161
1126 1162 spa_config_enter(spa, SCL_ALL, spa, RW_WRITER);
1127 1163
1128 1164 return (spa_last_synced_txg(spa) + 1);
1129 1165 }
1130 1166
1131 1167 /*
1132 1168 * Used in combination with spa_vdev_config_enter() to allow the syncing
1133 1169 * of multiple transactions without releasing the spa_namespace_lock.
1134 1170 */
1135 1171 void
1136 1172 spa_vdev_config_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error, char *tag)
1137 1173 {
1138 1174 ASSERT(MUTEX_HELD(&spa_namespace_lock));
1139 1175
1140 1176 int config_changed = B_FALSE;
1141 1177
1142 1178 ASSERT(txg > spa_last_synced_txg(spa));
1143 1179
1144 1180 spa->spa_pending_vdev = NULL;
1145 1181
1146 1182 /*
1147 1183 * Reassess the DTLs.
1148 1184 */
1149 1185 vdev_dtl_reassess(spa->spa_root_vdev, 0, 0, B_FALSE);
1150 1186
|
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
1151 1187 if (error == 0 && !list_is_empty(&spa->spa_config_dirty_list)) {
1152 1188 config_changed = B_TRUE;
1153 1189 spa->spa_config_generation++;
1154 1190 }
1155 1191
1156 1192 /*
1157 1193 * Verify the metaslab classes.
1158 1194 */
1159 1195 ASSERT(metaslab_class_validate(spa_normal_class(spa)) == 0);
1160 1196 ASSERT(metaslab_class_validate(spa_log_class(spa)) == 0);
1197 + ASSERT(metaslab_class_validate(spa_special_class(spa)) == 0);
1161 1198
1162 1199 spa_config_exit(spa, SCL_ALL, spa);
1163 1200
1164 1201 /*
1165 1202 * Panic the system if the specified tag requires it. This
1166 1203 * is useful for ensuring that configurations are updated
1167 1204 * transactionally.
1168 1205 */
1169 1206 if (zio_injection_enabled)
1170 1207 zio_handle_panic_injection(spa, tag, 0);
1171 1208
1172 1209 /*
1173 1210 * Note: this txg_wait_synced() is important because it ensures
1174 1211 * that there won't be more than one config change per txg.
1175 1212 * This allows us to use the txg as the generation number.
1176 1213 */
1177 1214 if (error == 0)
1178 1215 txg_wait_synced(spa->spa_dsl_pool, txg);
1179 1216
1180 1217 if (vd != NULL) {
|
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
1181 1218 ASSERT(!vd->vdev_detached || vd->vdev_dtl_sm == NULL);
1182 1219 spa_config_enter(spa, SCL_ALL, spa, RW_WRITER);
1183 1220 vdev_free(vd);
1184 1221 spa_config_exit(spa, SCL_ALL, spa);
1185 1222 }
1186 1223
1187 1224 /*
1188 1225 * If the config changed, update the config cache.
1189 1226 */
1190 1227 if (config_changed)
1191 - spa_write_cachefile(spa, B_FALSE, B_TRUE);
1228 + spa_config_sync(spa, B_FALSE, B_TRUE);
1192 1229 }
1193 1230
1194 1231 /*
1195 1232 * Unlock the spa_t after adding or removing a vdev. Besides undoing the
1196 1233 * locking of spa_vdev_enter(), we also want make sure the transactions have
1197 1234 * synced to disk, and then update the global configuration cache with the new
1198 1235 * information.
1199 1236 */
1200 1237 int
1201 1238 spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error)
1202 1239 {
1203 1240 spa_vdev_config_exit(spa, vd, txg, error, FTAG);
1241 + mutex_exit(&spa->spa_man_trim_lock);
1242 + mutex_exit(&spa->spa_auto_trim_lock);
1204 1243 mutex_exit(&spa_namespace_lock);
1205 1244 mutex_exit(&spa->spa_vdev_top_lock);
1206 1245
1207 1246 return (error);
1208 1247 }
1209 1248
1210 1249 /*
1211 1250 * Lock the given spa_t for the purpose of changing vdev state.
1212 1251 */
1213 1252 void
1214 1253 spa_vdev_state_enter(spa_t *spa, int oplocks)
1215 1254 {
1216 1255 int locks = SCL_STATE_ALL | oplocks;
1217 1256
1218 1257 /*
1219 1258 * Root pools may need to read of the underlying devfs filesystem
1220 1259 * when opening up a vdev. Unfortunately if we're holding the
1221 1260 * SCL_ZIO lock it will result in a deadlock when we try to issue
1222 1261 * the read from the root filesystem. Instead we "prefetch"
1223 1262 * the associated vnodes that we need prior to opening the
1224 1263 * underlying devices and cache them so that we can prevent
1225 1264 * any I/O when we are doing the actual open.
1226 1265 */
1227 1266 if (spa_is_root(spa)) {
1228 1267 int low = locks & ~(SCL_ZIO - 1);
1229 1268 int high = locks & ~low;
1230 1269
1231 1270 spa_config_enter(spa, high, spa, RW_WRITER);
1232 1271 vdev_hold(spa->spa_root_vdev);
1233 1272 spa_config_enter(spa, low, spa, RW_WRITER);
1234 1273 } else {
1235 1274 spa_config_enter(spa, locks, spa, RW_WRITER);
1236 1275 }
1237 1276 spa->spa_vdev_locks = locks;
1238 1277 }
1239 1278
1240 1279 int
1241 1280 spa_vdev_state_exit(spa_t *spa, vdev_t *vd, int error)
1242 1281 {
1243 1282 boolean_t config_changed = B_FALSE;
1244 1283
1245 1284 if (vd != NULL || error == 0)
1246 1285 vdev_dtl_reassess(vd ? vd->vdev_top : spa->spa_root_vdev,
1247 1286 0, 0, B_FALSE);
1248 1287
1249 1288 if (vd != NULL) {
1250 1289 vdev_state_dirty(vd->vdev_top);
1251 1290 config_changed = B_TRUE;
1252 1291 spa->spa_config_generation++;
1253 1292 }
1254 1293
1255 1294 if (spa_is_root(spa))
1256 1295 vdev_rele(spa->spa_root_vdev);
1257 1296
1258 1297 ASSERT3U(spa->spa_vdev_locks, >=, SCL_STATE_ALL);
1259 1298 spa_config_exit(spa, spa->spa_vdev_locks, spa);
1260 1299
1261 1300 /*
1262 1301 * If anything changed, wait for it to sync. This ensures that,
1263 1302 * from the system administrator's perspective, zpool(1M) commands
1264 1303 * are synchronous. This is important for things like zpool offline:
|
↓ open down ↓ |
51 lines elided |
↑ open up ↑ |
1265 1304 * when the command completes, you expect no further I/O from ZFS.
1266 1305 */
1267 1306 if (vd != NULL)
1268 1307 txg_wait_synced(spa->spa_dsl_pool, 0);
1269 1308
1270 1309 /*
1271 1310 * If the config changed, update the config cache.
1272 1311 */
1273 1312 if (config_changed) {
1274 1313 mutex_enter(&spa_namespace_lock);
1275 - spa_write_cachefile(spa, B_FALSE, B_TRUE);
1314 + spa_config_sync(spa, B_FALSE, B_TRUE);
1276 1315 mutex_exit(&spa_namespace_lock);
1277 1316 }
1278 1317
1279 1318 return (error);
1280 1319 }
1281 1320
1282 1321 /*
1283 1322 * ==========================================================================
1284 1323 * Miscellaneous functions
1285 1324 * ==========================================================================
1286 1325 */
1287 1326
1288 1327 void
1289 1328 spa_activate_mos_feature(spa_t *spa, const char *feature, dmu_tx_t *tx)
1290 1329 {
1291 1330 if (!nvlist_exists(spa->spa_label_features, feature)) {
1292 1331 fnvlist_add_boolean(spa->spa_label_features, feature);
1293 1332 /*
1294 1333 * When we are creating the pool (tx_txg==TXG_INITIAL), we can't
1295 1334 * dirty the vdev config because lock SCL_CONFIG is not held.
1296 1335 * Thankfully, in this case we don't need to dirty the config
1297 1336 * because it will be written out anyway when we finish
1298 1337 * creating the pool.
1299 1338 */
1300 1339 if (tx->tx_txg != TXG_INITIAL)
1301 1340 vdev_config_dirty(spa->spa_root_vdev);
1302 1341 }
1303 1342 }
1304 1343
1305 1344 void
1306 1345 spa_deactivate_mos_feature(spa_t *spa, const char *feature)
1307 1346 {
1308 1347 if (nvlist_remove_all(spa->spa_label_features, feature) == 0)
1309 1348 vdev_config_dirty(spa->spa_root_vdev);
1310 1349 }
1311 1350
1312 1351 /*
1313 1352 * Rename a spa_t.
1314 1353 */
1315 1354 int
1316 1355 spa_rename(const char *name, const char *newname)
1317 1356 {
1318 1357 spa_t *spa;
1319 1358 int err;
1320 1359
1321 1360 /*
1322 1361 * Lookup the spa_t and grab the config lock for writing. We need to
1323 1362 * actually open the pool so that we can sync out the necessary labels.
1324 1363 * It's OK to call spa_open() with the namespace lock held because we
1325 1364 * allow recursive calls for other reasons.
1326 1365 */
1327 1366 mutex_enter(&spa_namespace_lock);
1328 1367 if ((err = spa_open(name, &spa, FTAG)) != 0) {
1329 1368 mutex_exit(&spa_namespace_lock);
1330 1369 return (err);
1331 1370 }
1332 1371
1333 1372 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
1334 1373
1335 1374 avl_remove(&spa_namespace_avl, spa);
1336 1375 (void) strlcpy(spa->spa_name, newname, sizeof (spa->spa_name));
1337 1376 avl_add(&spa_namespace_avl, spa);
1338 1377
1339 1378 /*
1340 1379 * Sync all labels to disk with the new names by marking the root vdev
1341 1380 * dirty and waiting for it to sync. It will pick up the new pool name
1342 1381 * during the sync.
|
↓ open down ↓ |
57 lines elided |
↑ open up ↑ |
1343 1382 */
1344 1383 vdev_config_dirty(spa->spa_root_vdev);
1345 1384
1346 1385 spa_config_exit(spa, SCL_ALL, FTAG);
1347 1386
1348 1387 txg_wait_synced(spa->spa_dsl_pool, 0);
1349 1388
1350 1389 /*
1351 1390 * Sync the updated config cache.
1352 1391 */
1353 - spa_write_cachefile(spa, B_FALSE, B_TRUE);
1392 + spa_config_sync(spa, B_FALSE, B_TRUE);
1354 1393
1355 1394 spa_close(spa, FTAG);
1356 1395
1357 1396 mutex_exit(&spa_namespace_lock);
1358 1397
1359 1398 return (0);
1360 1399 }
1361 1400
1362 1401 /*
1363 1402 * Return the spa_t associated with given pool_guid, if it exists. If
1364 1403 * device_guid is non-zero, determine whether the pool exists *and* contains
1365 1404 * a device with the specified device_guid.
1366 1405 */
1367 1406 spa_t *
1368 1407 spa_by_guid(uint64_t pool_guid, uint64_t device_guid)
1369 1408 {
1370 1409 spa_t *spa;
1371 1410 avl_tree_t *t = &spa_namespace_avl;
1372 1411
1373 1412 ASSERT(MUTEX_HELD(&spa_namespace_lock));
1374 1413
1375 1414 for (spa = avl_first(t); spa != NULL; spa = AVL_NEXT(t, spa)) {
1376 1415 if (spa->spa_state == POOL_STATE_UNINITIALIZED)
1377 1416 continue;
1378 1417 if (spa->spa_root_vdev == NULL)
1379 1418 continue;
1380 1419 if (spa_guid(spa) == pool_guid) {
1381 1420 if (device_guid == 0)
1382 1421 break;
1383 1422
1384 1423 if (vdev_lookup_by_guid(spa->spa_root_vdev,
1385 1424 device_guid) != NULL)
1386 1425 break;
1387 1426
1388 1427 /*
1389 1428 * Check any devices we may be in the process of adding.
1390 1429 */
1391 1430 if (spa->spa_pending_vdev) {
1392 1431 if (vdev_lookup_by_guid(spa->spa_pending_vdev,
1393 1432 device_guid) != NULL)
1394 1433 break;
1395 1434 }
1396 1435 }
1397 1436 }
1398 1437
1399 1438 return (spa);
1400 1439 }
|
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
1401 1440
1402 1441 /*
1403 1442 * Determine whether a pool with the given pool_guid exists.
1404 1443 */
1405 1444 boolean_t
1406 1445 spa_guid_exists(uint64_t pool_guid, uint64_t device_guid)
1407 1446 {
1408 1447 return (spa_by_guid(pool_guid, device_guid) != NULL);
1409 1448 }
1410 1449
1450 +/*
1451 + * Similar to spa_guid_exists, but uses the spa_config_guid and doesn't
1452 + * filter the check by pool state (as spa_guid_exists does). This is
1453 + * used to protect against attempting to spa_add the same pool (with the
1454 + * same pool GUID) under different names. This situation can happen if
1455 + * the boot_archive contains an outdated zpool.cache file after a pool
1456 + * rename. That would make us import the pool twice, resulting in data
1457 + * corruption. Normally the boot_archive shouldn't contain a zpool.cache
1458 + * file, but if due to misconfiguration it does, this function serves as
1459 + * a failsafe to prevent the double import.
1460 + */
1461 +boolean_t
1462 +spa_config_guid_exists(uint64_t pool_guid)
1463 +{
1464 + spa_t *spa;
1465 +
1466 + ASSERT(MUTEX_HELD(&spa_namespace_lock));
1467 + if (pool_guid == 0)
1468 + return (B_FALSE);
1469 +
1470 + for (spa = avl_first(&spa_namespace_avl); spa != NULL;
1471 + spa = AVL_NEXT(&spa_namespace_avl, spa)) {
1472 + if (spa->spa_config_guid == pool_guid)
1473 + return (B_TRUE);
1474 + }
1475 +
1476 + return (B_FALSE);
1477 +}
1478 +
1411 1479 char *
1412 1480 spa_strdup(const char *s)
1413 1481 {
1414 1482 size_t len;
1415 1483 char *new;
1416 1484
1417 1485 len = strlen(s);
1418 1486 new = kmem_alloc(len + 1, KM_SLEEP);
1419 1487 bcopy(s, new, len);
1420 1488 new[len] = '\0';
1421 1489
1422 1490 return (new);
1423 1491 }
1424 1492
1425 1493 void
1426 1494 spa_strfree(char *s)
1427 1495 {
1428 1496 kmem_free(s, strlen(s) + 1);
1429 1497 }
1430 1498
1431 1499 uint64_t
1432 1500 spa_get_random(uint64_t range)
1433 1501 {
1434 1502 uint64_t r;
1435 1503
1436 1504 ASSERT(range != 0);
1437 1505
1438 1506 (void) random_get_pseudo_bytes((void *)&r, sizeof (uint64_t));
1439 1507
1440 1508 return (r % range);
1441 1509 }
1442 1510
1443 1511 uint64_t
1444 1512 spa_generate_guid(spa_t *spa)
1445 1513 {
1446 1514 uint64_t guid = spa_get_random(-1ULL);
1447 1515
1448 1516 if (spa != NULL) {
1449 1517 while (guid == 0 || spa_guid_exists(spa_guid(spa), guid))
1450 1518 guid = spa_get_random(-1ULL);
1451 1519 } else {
1452 1520 while (guid == 0 || spa_guid_exists(guid, 0))
1453 1521 guid = spa_get_random(-1ULL);
1454 1522 }
1455 1523
1456 1524 return (guid);
1457 1525 }
1458 1526
1459 1527 void
1460 1528 snprintf_blkptr(char *buf, size_t buflen, const blkptr_t *bp)
1461 1529 {
1462 1530 char type[256];
1463 1531 char *checksum = NULL;
1464 1532 char *compress = NULL;
1465 1533
1466 1534 if (bp != NULL) {
1467 1535 if (BP_GET_TYPE(bp) & DMU_OT_NEWTYPE) {
1468 1536 dmu_object_byteswap_t bswap =
1469 1537 DMU_OT_BYTESWAP(BP_GET_TYPE(bp));
1470 1538 (void) snprintf(type, sizeof (type), "bswap %s %s",
1471 1539 DMU_OT_IS_METADATA(BP_GET_TYPE(bp)) ?
1472 1540 "metadata" : "data",
1473 1541 dmu_ot_byteswap[bswap].ob_name);
1474 1542 } else {
1475 1543 (void) strlcpy(type, dmu_ot[BP_GET_TYPE(bp)].ot_name,
1476 1544 sizeof (type));
1477 1545 }
1478 1546 if (!BP_IS_EMBEDDED(bp)) {
1479 1547 checksum =
1480 1548 zio_checksum_table[BP_GET_CHECKSUM(bp)].ci_name;
1481 1549 }
1482 1550 compress = zio_compress_table[BP_GET_COMPRESS(bp)].ci_name;
1483 1551 }
1484 1552
1485 1553 SNPRINTF_BLKPTR(snprintf, ' ', buf, buflen, bp, type, checksum,
1486 1554 compress);
1487 1555 }
1488 1556
1489 1557 void
1490 1558 spa_freeze(spa_t *spa)
1491 1559 {
1492 1560 uint64_t freeze_txg = 0;
1493 1561
1494 1562 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
1495 1563 if (spa->spa_freeze_txg == UINT64_MAX) {
1496 1564 freeze_txg = spa_last_synced_txg(spa) + TXG_SIZE;
1497 1565 spa->spa_freeze_txg = freeze_txg;
1498 1566 }
1499 1567 spa_config_exit(spa, SCL_ALL, FTAG);
1500 1568 if (freeze_txg != 0)
1501 1569 txg_wait_synced(spa_get_dsl(spa), freeze_txg);
1502 1570 }
1503 1571
1504 1572 void
1505 1573 zfs_panic_recover(const char *fmt, ...)
1506 1574 {
1507 1575 va_list adx;
1508 1576
1509 1577 va_start(adx, fmt);
1510 1578 vcmn_err(zfs_recover ? CE_WARN : CE_PANIC, fmt, adx);
1511 1579 va_end(adx);
1512 1580 }
1513 1581
1514 1582 /*
1515 1583 * This is a stripped-down version of strtoull, suitable only for converting
1516 1584 * lowercase hexadecimal numbers that don't overflow.
1517 1585 */
1518 1586 uint64_t
1519 1587 zfs_strtonum(const char *str, char **nptr)
1520 1588 {
1521 1589 uint64_t val = 0;
1522 1590 char c;
1523 1591 int digit;
1524 1592
1525 1593 while ((c = *str) != '\0') {
1526 1594 if (c >= '0' && c <= '9')
1527 1595 digit = c - '0';
1528 1596 else if (c >= 'a' && c <= 'f')
1529 1597 digit = 10 + c - 'a';
1530 1598 else
1531 1599 break;
1532 1600
1533 1601 val *= 16;
1534 1602 val += digit;
1535 1603
1536 1604 str++;
1537 1605 }
1538 1606
1539 1607 if (nptr)
1540 1608 *nptr = (char *)str;
1541 1609
1542 1610 return (val);
1543 1611 }
1544 1612
1545 1613 /*
1546 1614 * ==========================================================================
1547 1615 * Accessor functions
1548 1616 * ==========================================================================
1549 1617 */
1550 1618
1551 1619 boolean_t
1552 1620 spa_shutting_down(spa_t *spa)
1553 1621 {
1554 1622 return (spa->spa_async_suspended);
1555 1623 }
1556 1624
1557 1625 dsl_pool_t *
1558 1626 spa_get_dsl(spa_t *spa)
|
↓ open down ↓ |
138 lines elided |
↑ open up ↑ |
1559 1627 {
1560 1628 return (spa->spa_dsl_pool);
1561 1629 }
1562 1630
1563 1631 boolean_t
1564 1632 spa_is_initializing(spa_t *spa)
1565 1633 {
1566 1634 return (spa->spa_is_initializing);
1567 1635 }
1568 1636
1569 -boolean_t
1570 -spa_indirect_vdevs_loaded(spa_t *spa)
1571 -{
1572 - return (spa->spa_indirect_vdevs_loaded);
1573 -}
1574 -
1575 1637 blkptr_t *
1576 1638 spa_get_rootblkptr(spa_t *spa)
1577 1639 {
1578 1640 return (&spa->spa_ubsync.ub_rootbp);
1579 1641 }
1580 1642
1581 1643 void
1582 1644 spa_set_rootblkptr(spa_t *spa, const blkptr_t *bp)
1583 1645 {
1584 1646 spa->spa_uberblock.ub_rootbp = *bp;
1585 1647 }
1586 1648
1587 1649 void
1588 1650 spa_altroot(spa_t *spa, char *buf, size_t buflen)
1589 1651 {
1590 1652 if (spa->spa_root == NULL)
1591 1653 buf[0] = '\0';
1592 1654 else
1593 1655 (void) strncpy(buf, spa->spa_root, buflen);
1594 1656 }
1595 1657
1596 1658 int
1597 1659 spa_sync_pass(spa_t *spa)
1598 1660 {
1599 1661 return (spa->spa_sync_pass);
1600 1662 }
1601 1663
1602 1664 char *
1603 1665 spa_name(spa_t *spa)
1604 1666 {
1605 1667 return (spa->spa_name);
1606 1668 }
1607 1669
1608 1670 uint64_t
1609 1671 spa_guid(spa_t *spa)
1610 1672 {
1611 1673 dsl_pool_t *dp = spa_get_dsl(spa);
1612 1674 uint64_t guid;
1613 1675
1614 1676 /*
1615 1677 * If we fail to parse the config during spa_load(), we can go through
1616 1678 * the error path (which posts an ereport) and end up here with no root
1617 1679 * vdev. We stash the original pool guid in 'spa_config_guid' to handle
1618 1680 * this case.
1619 1681 */
1620 1682 if (spa->spa_root_vdev == NULL)
1621 1683 return (spa->spa_config_guid);
1622 1684
1623 1685 guid = spa->spa_last_synced_guid != 0 ?
1624 1686 spa->spa_last_synced_guid : spa->spa_root_vdev->vdev_guid;
1625 1687
1626 1688 /*
1627 1689 * Return the most recently synced out guid unless we're
1628 1690 * in syncing context.
1629 1691 */
1630 1692 if (dp && dsl_pool_sync_context(dp))
1631 1693 return (spa->spa_root_vdev->vdev_guid);
1632 1694 else
1633 1695 return (guid);
1634 1696 }
1635 1697
1636 1698 uint64_t
1637 1699 spa_load_guid(spa_t *spa)
1638 1700 {
1639 1701 /*
1640 1702 * This is a GUID that exists solely as a reference for the
1641 1703 * purposes of the arc. It is generated at load time, and
1642 1704 * is never written to persistent storage.
1643 1705 */
1644 1706 return (spa->spa_load_guid);
1645 1707 }
1646 1708
1647 1709 uint64_t
1648 1710 spa_last_synced_txg(spa_t *spa)
1649 1711 {
1650 1712 return (spa->spa_ubsync.ub_txg);
1651 1713 }
1652 1714
1653 1715 uint64_t
1654 1716 spa_first_txg(spa_t *spa)
1655 1717 {
1656 1718 return (spa->spa_first_txg);
1657 1719 }
1658 1720
1659 1721 uint64_t
1660 1722 spa_syncing_txg(spa_t *spa)
1661 1723 {
1662 1724 return (spa->spa_syncing_txg);
1663 1725 }
1664 1726
1665 1727 /*
1666 1728 * Return the last txg where data can be dirtied. The final txgs
1667 1729 * will be used to just clear out any deferred frees that remain.
1668 1730 */
1669 1731 uint64_t
1670 1732 spa_final_dirty_txg(spa_t *spa)
1671 1733 {
1672 1734 return (spa->spa_final_txg - TXG_DEFER_SIZE);
1673 1735 }
1674 1736
1675 1737 pool_state_t
1676 1738 spa_state(spa_t *spa)
1677 1739 {
1678 1740 return (spa->spa_state);
1679 1741 }
1680 1742
1681 1743 spa_load_state_t
1682 1744 spa_load_state(spa_t *spa)
1683 1745 {
1684 1746 return (spa->spa_load_state);
1685 1747 }
1686 1748
1687 1749 uint64_t
1688 1750 spa_freeze_txg(spa_t *spa)
1689 1751 {
1690 1752 return (spa->spa_freeze_txg);
|
↓ open down ↓ |
106 lines elided |
↑ open up ↑ |
1691 1753 }
1692 1754
1693 1755 /* ARGSUSED */
1694 1756 uint64_t
1695 1757 spa_get_worst_case_asize(spa_t *spa, uint64_t lsize)
1696 1758 {
1697 1759 return (lsize * spa_asize_inflation);
1698 1760 }
1699 1761
1700 1762 /*
1763 + * Get either on disk (phys == B_TRUE) or possible in core DDT size
1764 + */
1765 +uint64_t
1766 +spa_get_ddts_size(spa_t *spa, boolean_t phys)
1767 +{
1768 + if (phys)
1769 + return (spa->spa_ddt_dsize);
1770 +
1771 + return (spa->spa_ddt_msize);
1772 +}
1773 +
1774 +/*
1775 + * Check to see if we need to stop DDT growth to stay within some limit
1776 + */
1777 +boolean_t
1778 +spa_enable_dedup_cap(spa_t *spa)
1779 +{
1780 + if (zfs_ddt_byte_ceiling != 0) {
1781 + if (zfs_ddts_msize > zfs_ddt_byte_ceiling) {
1782 + /* need to limit DDT to an in core bytecount */
1783 + return (B_TRUE);
1784 + }
1785 + } else if (zfs_ddt_limit_type == DDT_LIMIT_TO_ARC) {
1786 + if (zfs_ddts_msize > *arc_ddt_evict_threshold) {
1787 + /* need to limit DDT to fit into ARC */
1788 + return (B_TRUE);
1789 + }
1790 + } else if (zfs_ddt_limit_type == DDT_LIMIT_TO_L2ARC) {
1791 + if (spa->spa_l2arc_ddt_devs_size != 0) {
1792 + if (spa_get_ddts_size(spa, B_TRUE) >
1793 + spa->spa_l2arc_ddt_devs_size) {
1794 + /* limit DDT to fit into L2ARC DDT dev */
1795 + return (B_TRUE);
1796 + }
1797 + } else if (zfs_ddts_msize > *arc_ddt_evict_threshold) {
1798 + /* no L2ARC DDT dev - limit DDT to fit into ARC */
1799 + return (B_TRUE);
1800 + }
1801 + }
1802 +
1803 + return (B_FALSE);
1804 +}
1805 +
1806 +/*
1701 1807 * Return the amount of slop space in bytes. It is 1/32 of the pool (3.2%),
1702 1808 * or at least 128MB, unless that would cause it to be more than half the
1703 1809 * pool size.
1704 1810 *
1705 1811 * See the comment above spa_slop_shift for details.
1706 1812 */
1707 1813 uint64_t
1708 1814 spa_get_slop_space(spa_t *spa)
1709 1815 {
1710 1816 uint64_t space = spa_get_dspace(spa);
1711 1817 return (MAX(space >> spa_slop_shift, MIN(space >> 1, spa_min_slop)));
1712 1818 }
1713 1819
1714 1820 uint64_t
|
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
1715 1821 spa_get_dspace(spa_t *spa)
1716 1822 {
1717 1823 return (spa->spa_dspace);
1718 1824 }
1719 1825
1720 1826 void
1721 1827 spa_update_dspace(spa_t *spa)
1722 1828 {
1723 1829 spa->spa_dspace = metaslab_class_get_dspace(spa_normal_class(spa)) +
1724 1830 ddt_get_dedup_dspace(spa);
1725 - if (spa->spa_vdev_removal != NULL) {
1726 - /*
1727 - * We can't allocate from the removing device, so
1728 - * subtract its size. This prevents the DMU/DSL from
1729 - * filling up the (now smaller) pool while we are in the
1730 - * middle of removing the device.
1731 - *
1732 - * Note that the DMU/DSL doesn't actually know or care
1733 - * how much space is allocated (it does its own tracking
1734 - * of how much space has been logically used). So it
1735 - * doesn't matter that the data we are moving may be
1736 - * allocated twice (on the old device and the new
1737 - * device).
1738 - */
1739 - vdev_t *vd = spa->spa_vdev_removal->svr_vdev;
1740 - spa->spa_dspace -= spa_deflate(spa) ?
1741 - vd->vdev_stat.vs_dspace : vd->vdev_stat.vs_space;
1831 +}
1832 +
1833 +/*
1834 + * EXPERIMENTAL
1835 + * Use exponential moving average to track root vdev iotime, as well as top
1836 + * level vdev iotime.
1837 + * The principle: avg_new = avg_prev + (cur - avg_prev) * a / 100; a is
1838 + * tuneable. For example, if a = 10 (alpha = 0.1), it will take 20 iterations,
1839 + * or 100 seconds at 5 second txg commit intervals for the values from last 20
1840 + * iterations to account for 66% of the moving average.
1841 + * Currently, the challenge is that we keep track of iotime in cumulative
1842 + * nanoseconds since zpool import, both for leaf and top vdevs, so a way of
1843 + * getting delta pre/post txg commit is required.
1844 + */
1845 +
1846 +void
1847 +spa_update_latency(spa_t *spa)
1848 +{
1849 + vdev_t *rvd = spa->spa_root_vdev;
1850 + vdev_stat_t *rvs = &rvd->vdev_stat;
1851 + for (int c = 0; c < rvd->vdev_children; c++) {
1852 + vdev_t *cvd = rvd->vdev_child[c];
1853 + vdev_stat_t *cvs = &cvd->vdev_stat;
1854 + mutex_enter(&rvd->vdev_stat_lock);
1855 +
1856 + for (int t = 0; t < ZIO_TYPES; t++) {
1857 +
1858 + /*
1859 + * Non-trivial bit here. We update the moving latency
1860 + * average for each child vdev separately, but since we
1861 + * want the average to settle at the same rate
1862 + * regardless of top level vdev count, we effectively
1863 + * divide our alpha by number of children of the root
1864 + * vdev to account for that.
1865 + */
1866 + rvs->vs_latency[t] += ((((int64_t)cvs->vs_latency[t] -
1867 + (int64_t)rvs->vs_latency[t]) *
1868 + (int64_t)zfs_root_latency_alpha) / 100) /
1869 + (int64_t)(rvd->vdev_children);
1870 + }
1871 + mutex_exit(&rvd->vdev_stat_lock);
1742 1872 }
1743 1873 }
1744 1874
1875 +
1745 1876 /*
1746 1877 * Return the failure mode that has been set to this pool. The default
1747 1878 * behavior will be to block all I/Os when a complete failure occurs.
1748 1879 */
1749 1880 uint8_t
1750 1881 spa_get_failmode(spa_t *spa)
1751 1882 {
1752 1883 return (spa->spa_failmode);
1753 1884 }
1754 1885
1755 1886 boolean_t
1756 1887 spa_suspended(spa_t *spa)
|
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
1757 1888 {
1758 1889 return (spa->spa_suspended);
1759 1890 }
1760 1891
1761 1892 uint64_t
1762 1893 spa_version(spa_t *spa)
1763 1894 {
1764 1895 return (spa->spa_ubsync.ub_version);
1765 1896 }
1766 1897
1898 +int
1899 +spa_get_obj_mtx_sz(spa_t *spa)
1900 +{
1901 + return (spa->spa_obj_mtx_sz);
1902 +}
1903 +
1767 1904 boolean_t
1768 1905 spa_deflate(spa_t *spa)
1769 1906 {
1770 1907 return (spa->spa_deflate);
1771 1908 }
1772 1909
1773 1910 metaslab_class_t *
1774 1911 spa_normal_class(spa_t *spa)
1775 1912 {
1776 1913 return (spa->spa_normal_class);
1777 1914 }
1778 1915
1779 1916 metaslab_class_t *
1780 1917 spa_log_class(spa_t *spa)
1781 1918 {
1782 1919 return (spa->spa_log_class);
1783 1920 }
1784 1921
1922 +metaslab_class_t *
1923 +spa_special_class(spa_t *spa)
1924 +{
1925 + return (spa->spa_special_class);
1926 +}
1927 +
1785 1928 void
1786 1929 spa_evicting_os_register(spa_t *spa, objset_t *os)
1787 1930 {
1788 1931 mutex_enter(&spa->spa_evicting_os_lock);
1789 1932 list_insert_head(&spa->spa_evicting_os_list, os);
1790 1933 mutex_exit(&spa->spa_evicting_os_lock);
1791 1934 }
1792 1935
1793 1936 void
1794 1937 spa_evicting_os_deregister(spa_t *spa, objset_t *os)
1795 1938 {
1796 1939 mutex_enter(&spa->spa_evicting_os_lock);
1797 1940 list_remove(&spa->spa_evicting_os_list, os);
1798 1941 cv_broadcast(&spa->spa_evicting_os_cv);
1799 1942 mutex_exit(&spa->spa_evicting_os_lock);
1800 1943 }
1801 1944
1802 1945 void
|
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
1803 1946 spa_evicting_os_wait(spa_t *spa)
1804 1947 {
1805 1948 mutex_enter(&spa->spa_evicting_os_lock);
1806 1949 while (!list_is_empty(&spa->spa_evicting_os_list))
1807 1950 cv_wait(&spa->spa_evicting_os_cv, &spa->spa_evicting_os_lock);
1808 1951 mutex_exit(&spa->spa_evicting_os_lock);
1809 1952
1810 1953 dmu_buf_user_evict_wait();
1811 1954 }
1812 1955
1956 +uint64_t
1957 +spa_class_alloc_percentage(metaslab_class_t *mc)
1958 +{
1959 + uint64_t capacity = mc->mc_space;
1960 + uint64_t alloc = mc->mc_alloc;
1961 + uint64_t one_percent = capacity / 100;
1962 +
1963 + return (alloc / one_percent);
1964 +}
1965 +
1813 1966 int
1814 1967 spa_max_replication(spa_t *spa)
1815 1968 {
1816 1969 /*
1817 1970 * As of SPA_VERSION == SPA_VERSION_DITTO_BLOCKS, we are able to
1818 1971 * handle BPs with more than one DVA allocated. Set our max
1819 1972 * replication level accordingly.
1820 1973 */
1821 1974 if (spa_version(spa) < SPA_VERSION_DITTO_BLOCKS)
1822 1975 return (1);
1823 1976 return (MIN(SPA_DVAS_PER_BP, spa_max_replication_override));
1824 1977 }
1825 1978
1826 1979 int
1827 1980 spa_prev_software_version(spa_t *spa)
|
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
1828 1981 {
1829 1982 return (spa->spa_prev_software_version);
1830 1983 }
1831 1984
1832 1985 uint64_t
1833 1986 spa_deadman_synctime(spa_t *spa)
1834 1987 {
1835 1988 return (spa->spa_deadman_synctime);
1836 1989 }
1837 1990
1991 +spa_force_trim_t
1992 +spa_get_force_trim(spa_t *spa)
1993 +{
1994 + return (spa->spa_force_trim);
1995 +}
1996 +
1997 +spa_auto_trim_t
1998 +spa_get_auto_trim(spa_t *spa)
1999 +{
2000 + return (spa->spa_auto_trim);
2001 +}
2002 +
1838 2003 uint64_t
1839 2004 dva_get_dsize_sync(spa_t *spa, const dva_t *dva)
1840 2005 {
1841 2006 uint64_t asize = DVA_GET_ASIZE(dva);
1842 2007 uint64_t dsize = asize;
1843 2008
1844 2009 ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
1845 2010
1846 2011 if (asize != 0 && spa->spa_deflate) {
1847 2012 vdev_t *vd = vdev_lookup_top(spa, DVA_GET_VDEV(dva));
1848 2013 dsize = (asize >> SPA_MINBLOCKSHIFT) * vd->vdev_deflate_ratio;
1849 2014 }
1850 2015
1851 2016 return (dsize);
1852 2017 }
1853 2018
2019 +/*
2020 + * This function walks over the all DVAs of the given BP and
2021 + * adds up their sizes.
2022 + */
1854 2023 uint64_t
1855 2024 bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp)
1856 2025 {
2026 + /*
2027 + * SPECIAL-BP has two DVAs, but DVA[0] in this case is a
2028 + * temporary DVA, and after migration only the DVA[1]
2029 + * contains valid data. Therefore, we start walking for
2030 + * these BPs from DVA[1].
2031 + */
2032 + int start_dva = BP_IS_SPECIAL(bp) ? 1 : 0;
1857 2033 uint64_t dsize = 0;
1858 2034
1859 - for (int d = 0; d < BP_GET_NDVAS(bp); d++)
2035 + for (int d = start_dva; d < BP_GET_NDVAS(bp); d++) {
1860 2036 dsize += dva_get_dsize_sync(spa, &bp->blk_dva[d]);
2037 + }
1861 2038
1862 2039 return (dsize);
1863 2040 }
1864 2041
1865 2042 uint64_t
1866 2043 bp_get_dsize(spa_t *spa, const blkptr_t *bp)
1867 2044 {
1868 - uint64_t dsize = 0;
2045 + uint64_t dsize;
1869 2046
1870 2047 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
1871 2048
1872 - for (int d = 0; d < BP_GET_NDVAS(bp); d++)
1873 - dsize += dva_get_dsize_sync(spa, &bp->blk_dva[d]);
2049 + dsize = bp_get_dsize_sync(spa, bp);
1874 2050
1875 2051 spa_config_exit(spa, SCL_VDEV, FTAG);
1876 2052
1877 2053 return (dsize);
1878 2054 }
1879 2055
1880 2056 /*
1881 2057 * ==========================================================================
1882 2058 * Initialization and Termination
1883 2059 * ==========================================================================
1884 2060 */
1885 2061
1886 2062 static int
1887 2063 spa_name_compare(const void *a1, const void *a2)
1888 2064 {
1889 2065 const spa_t *s1 = a1;
1890 2066 const spa_t *s2 = a2;
1891 2067 int s;
1892 2068
1893 2069 s = strcmp(s1->spa_name, s2->spa_name);
1894 2070 if (s > 0)
1895 2071 return (1);
1896 2072 if (s < 0)
1897 2073 return (-1);
1898 2074 return (0);
1899 2075 }
1900 2076
1901 2077 int
1902 2078 spa_busy(void)
1903 2079 {
1904 2080 return (spa_active_count);
1905 2081 }
1906 2082
1907 2083 void
1908 2084 spa_boot_init()
1909 2085 {
1910 2086 spa_config_load();
1911 2087 }
1912 2088
1913 2089 void
1914 2090 spa_init(int mode)
1915 2091 {
1916 2092 mutex_init(&spa_namespace_lock, NULL, MUTEX_DEFAULT, NULL);
1917 2093 mutex_init(&spa_spare_lock, NULL, MUTEX_DEFAULT, NULL);
1918 2094 mutex_init(&spa_l2cache_lock, NULL, MUTEX_DEFAULT, NULL);
1919 2095 cv_init(&spa_namespace_cv, NULL, CV_DEFAULT, NULL);
1920 2096
1921 2097 avl_create(&spa_namespace_avl, spa_name_compare, sizeof (spa_t),
|
↓ open down ↓ |
38 lines elided |
↑ open up ↑ |
1922 2098 offsetof(spa_t, spa_avl));
1923 2099
1924 2100 avl_create(&spa_spare_avl, spa_spare_compare, sizeof (spa_aux_t),
1925 2101 offsetof(spa_aux_t, aux_avl));
1926 2102
1927 2103 avl_create(&spa_l2cache_avl, spa_l2cache_compare, sizeof (spa_aux_t),
1928 2104 offsetof(spa_aux_t, aux_avl));
1929 2105
1930 2106 spa_mode_global = mode;
1931 2107
2108 + /*
2109 + * logevent_max_q_sz from log_sysevent.c gives us upper bound on
2110 + * the number of taskq entries; queueing of sysevents is serialized,
2111 + * so there is no need for more than one worker thread
2112 + */
2113 + spa_sysevent_taskq = taskq_create("spa_sysevent_tq", 1,
2114 + minclsyspri, 1, 5000, TASKQ_DYNAMIC);
2115 +
1932 2116 #ifdef _KERNEL
1933 2117 spa_arch_init();
1934 2118 #else
1935 2119 if (spa_mode_global != FREAD && dprintf_find_string("watch")) {
1936 2120 arc_procfd = open("/proc/self/ctl", O_WRONLY);
1937 2121 if (arc_procfd == -1) {
1938 2122 perror("could not enable watchpoints: "
1939 2123 "opening /proc/self/ctl failed: ");
1940 2124 } else {
1941 2125 arc_watch = B_TRUE;
1942 2126 }
1943 2127 }
1944 2128 #endif
1945 2129
1946 2130 refcount_init();
|
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
1947 2131 unique_init();
1948 2132 range_tree_init();
1949 2133 metaslab_alloc_trace_init();
1950 2134 zio_init();
1951 2135 dmu_init();
1952 2136 zil_init();
1953 2137 vdev_cache_stat_init();
1954 2138 zfs_prop_init();
1955 2139 zpool_prop_init();
1956 2140 zpool_feature_init();
2141 + vdev_prop_init();
2142 + cos_prop_init();
1957 2143 spa_config_load();
1958 2144 l2arc_start();
2145 + ddt_init();
2146 + dsl_scan_global_init();
1959 2147 }
1960 2148
1961 2149 void
1962 2150 spa_fini(void)
1963 2151 {
2152 + ddt_fini();
2153 +
1964 2154 l2arc_stop();
1965 2155
1966 2156 spa_evict_all();
1967 2157
1968 2158 vdev_cache_stat_fini();
1969 2159 zil_fini();
1970 2160 dmu_fini();
1971 2161 zio_fini();
1972 2162 metaslab_alloc_trace_fini();
1973 2163 range_tree_fini();
1974 2164 unique_fini();
1975 2165 refcount_fini();
1976 2166
2167 + taskq_destroy(spa_sysevent_taskq);
2168 +
1977 2169 avl_destroy(&spa_namespace_avl);
1978 2170 avl_destroy(&spa_spare_avl);
1979 2171 avl_destroy(&spa_l2cache_avl);
1980 2172
1981 2173 cv_destroy(&spa_namespace_cv);
1982 2174 mutex_destroy(&spa_namespace_lock);
1983 2175 mutex_destroy(&spa_spare_lock);
1984 2176 mutex_destroy(&spa_l2cache_lock);
1985 2177 }
1986 2178
1987 2179 /*
1988 2180 * Return whether this pool has slogs. No locking needed.
1989 2181 * It's not a problem if the wrong answer is returned as it's only for
1990 2182 * performance and not correctness
1991 2183 */
1992 2184 boolean_t
1993 2185 spa_has_slogs(spa_t *spa)
1994 2186 {
1995 2187 return (spa->spa_log_class->mc_rotor != NULL);
1996 2188 }
1997 2189
1998 2190 spa_log_state_t
1999 2191 spa_get_log_state(spa_t *spa)
2000 2192 {
2001 2193 return (spa->spa_log_state);
2002 2194 }
2003 2195
2004 2196 void
2005 2197 spa_set_log_state(spa_t *spa, spa_log_state_t state)
2006 2198 {
2007 2199 spa->spa_log_state = state;
2008 2200 }
|
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
2009 2201
2010 2202 boolean_t
2011 2203 spa_is_root(spa_t *spa)
2012 2204 {
2013 2205 return (spa->spa_is_root);
2014 2206 }
2015 2207
2016 2208 boolean_t
2017 2209 spa_writeable(spa_t *spa)
2018 2210 {
2019 - return (!!(spa->spa_mode & FWRITE) && spa->spa_trust_config);
2211 + return (!!(spa->spa_mode & FWRITE));
2020 2212 }
2021 2213
2022 2214 /*
2023 2215 * Returns true if there is a pending sync task in any of the current
2024 2216 * syncing txg, the current quiescing txg, or the current open txg.
2025 2217 */
2026 2218 boolean_t
2027 2219 spa_has_pending_synctask(spa_t *spa)
2028 2220 {
2029 2221 return (!txg_all_lists_empty(&spa->spa_dsl_pool->dp_sync_tasks));
2030 2222 }
2031 2223
2224 +boolean_t
2225 +spa_has_special(spa_t *spa)
2226 +{
2227 + return (spa->spa_special_class->mc_rotor != NULL);
2228 +}
2229 +
2032 2230 int
2033 2231 spa_mode(spa_t *spa)
2034 2232 {
2035 2233 return (spa->spa_mode);
2036 2234 }
2037 2235
2038 2236 uint64_t
2039 2237 spa_bootfs(spa_t *spa)
2040 2238 {
2041 2239 return (spa->spa_bootfs);
2042 2240 }
2043 2241
2044 2242 uint64_t
2045 2243 spa_delegation(spa_t *spa)
2046 2244 {
2047 2245 return (spa->spa_delegation);
2048 2246 }
2049 2247
2050 2248 objset_t *
2051 2249 spa_meta_objset(spa_t *spa)
2052 2250 {
2053 2251 return (spa->spa_meta_objset);
2054 2252 }
2055 2253
2056 2254 enum zio_checksum
2057 2255 spa_dedup_checksum(spa_t *spa)
2058 2256 {
2059 2257 return (spa->spa_dedup_checksum);
2060 2258 }
2061 2259
2062 2260 /*
2063 2261 * Reset pool scan stat per scan pass (or reboot).
2064 2262 */
2065 2263 void
|
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
2066 2264 spa_scan_stat_init(spa_t *spa)
2067 2265 {
2068 2266 /* data not stored on disk */
2069 2267 spa->spa_scan_pass_start = gethrestime_sec();
2070 2268 if (dsl_scan_is_paused_scrub(spa->spa_dsl_pool->dp_scan))
2071 2269 spa->spa_scan_pass_scrub_pause = spa->spa_scan_pass_start;
2072 2270 else
2073 2271 spa->spa_scan_pass_scrub_pause = 0;
2074 2272 spa->spa_scan_pass_scrub_spent_paused = 0;
2075 2273 spa->spa_scan_pass_exam = 0;
2274 + spa->spa_scan_pass_work = 0;
2076 2275 vdev_scan_stat_init(spa->spa_root_vdev);
2077 2276 }
2078 2277
2079 2278 /*
2080 2279 * Get scan stats for zpool status reports
2081 2280 */
2082 2281 int
2083 2282 spa_scan_get_stats(spa_t *spa, pool_scan_stat_t *ps)
2084 2283 {
2085 2284 dsl_scan_t *scn = spa->spa_dsl_pool ? spa->spa_dsl_pool->dp_scan : NULL;
2086 2285
2087 2286 if (scn == NULL || scn->scn_phys.scn_func == POOL_SCAN_NONE)
2088 2287 return (SET_ERROR(ENOENT));
2089 2288 bzero(ps, sizeof (pool_scan_stat_t));
2090 2289
|
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
2091 2290 /* data stored on disk */
2092 2291 ps->pss_func = scn->scn_phys.scn_func;
2093 2292 ps->pss_start_time = scn->scn_phys.scn_start_time;
2094 2293 ps->pss_end_time = scn->scn_phys.scn_end_time;
2095 2294 ps->pss_to_examine = scn->scn_phys.scn_to_examine;
2096 2295 ps->pss_examined = scn->scn_phys.scn_examined;
2097 2296 ps->pss_to_process = scn->scn_phys.scn_to_process;
2098 2297 ps->pss_processed = scn->scn_phys.scn_processed;
2099 2298 ps->pss_errors = scn->scn_phys.scn_errors;
2100 2299 ps->pss_state = scn->scn_phys.scn_state;
2300 + mutex_enter(&scn->scn_status_lock);
2301 + ps->pss_issued = scn->scn_bytes_issued;
2302 + mutex_exit(&scn->scn_status_lock);
2101 2303
2102 2304 /* data not stored on disk */
2103 2305 ps->pss_pass_start = spa->spa_scan_pass_start;
2104 2306 ps->pss_pass_exam = spa->spa_scan_pass_exam;
2307 + ps->pss_pass_work = spa->spa_scan_pass_work;
2105 2308 ps->pss_pass_scrub_pause = spa->spa_scan_pass_scrub_pause;
2106 2309 ps->pss_pass_scrub_spent_paused = spa->spa_scan_pass_scrub_spent_paused;
2107 2310
2108 2311 return (0);
2109 2312 }
2110 2313
2111 2314 boolean_t
2112 2315 spa_debug_enabled(spa_t *spa)
2113 2316 {
2114 2317 return (spa->spa_debug);
2115 2318 }
|
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
2116 2319
2117 2320 int
2118 2321 spa_maxblocksize(spa_t *spa)
2119 2322 {
2120 2323 if (spa_feature_is_enabled(spa, SPA_FEATURE_LARGE_BLOCKS))
2121 2324 return (SPA_MAXBLOCKSIZE);
2122 2325 else
2123 2326 return (SPA_OLD_MAXBLOCKSIZE);
2124 2327 }
2125 2328
2329 +boolean_t
2330 +spa_wbc_present(spa_t *spa)
2331 +{
2332 + return (spa->spa_wbc_mode != WBC_MODE_OFF);
2333 +}
2334 +
2335 +boolean_t
2336 +spa_wbc_active(spa_t *spa)
2337 +{
2338 + return (spa->spa_wbc_mode == WBC_MODE_ACTIVE);
2339 +}
2340 +
2341 +int
2342 +spa_wbc_mode(const char *name)
2343 +{
2344 + int ret = 0;
2345 + spa_t *spa;
2346 +
2347 + mutex_enter(&spa_namespace_lock);
2348 + spa = spa_lookup(name);
2349 + if (!spa) {
2350 + mutex_exit(&spa_namespace_lock);
2351 + return (-1);
2352 + }
2353 +
2354 + ret = (int)spa->spa_wbc_mode;
2355 + mutex_exit(&spa_namespace_lock);
2356 + return (ret);
2357 +}
2358 +
2359 +struct zfs_autosnap *
2360 +spa_get_autosnap(spa_t *spa)
2361 +{
2362 + return (&spa->spa_autosnap);
2363 +}
2364 +
2365 +wbc_data_t *
2366 +spa_get_wbc_data(spa_t *spa)
2367 +{
2368 + return (&spa->spa_wbc);
2369 +}
2370 +
2126 2371 /*
2127 - * Returns the txg that the last device removal completed. No indirect mappings
2128 - * have been added since this txg.
2372 + * Creates the trim kstats structure for a spa.
2129 2373 */
2130 -uint64_t
2131 -spa_get_last_removal_txg(spa_t *spa)
2374 +static void
2375 +spa_trimstats_create(spa_t *spa)
2132 2376 {
2133 - uint64_t vdevid;
2134 - uint64_t ret = -1ULL;
2377 + /* truncate pool name to accomodate "_trimstats" suffix */
2378 + char short_spa_name[KSTAT_STRLEN - 10];
2379 + char name[KSTAT_STRLEN];
2135 2380
2136 - spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
2137 - /*
2138 - * sr_prev_indirect_vdev is only modified while holding all the
2139 - * config locks, so it is sufficient to hold SCL_VDEV as reader when
2140 - * examining it.
2141 - */
2142 - vdevid = spa->spa_removing_phys.sr_prev_indirect_vdev;
2381 + ASSERT3P(spa->spa_trimstats, ==, NULL);
2382 + ASSERT3P(spa->spa_trimstats_ks, ==, NULL);
2143 2383
2144 - while (vdevid != -1ULL) {
2145 - vdev_t *vd = vdev_lookup_top(spa, vdevid);
2146 - vdev_indirect_births_t *vib = vd->vdev_indirect_births;
2384 + (void) snprintf(short_spa_name, sizeof (short_spa_name), "%s",
2385 + spa->spa_name);
2386 + (void) snprintf(name, sizeof (name), "%s_trimstats", short_spa_name);
2147 2387
2148 - ASSERT3P(vd->vdev_ops, ==, &vdev_indirect_ops);
2388 + spa->spa_trimstats_ks = kstat_create("zfs", 0, name, "misc",
2389 + KSTAT_TYPE_NAMED, sizeof (*spa->spa_trimstats) /
2390 + sizeof (kstat_named_t), 0);
2391 + if (spa->spa_trimstats_ks) {
2392 + spa->spa_trimstats = spa->spa_trimstats_ks->ks_data;
2149 2393
2150 - /*
2151 - * If the removal did not remap any data, we don't care.
2152 - */
2153 - if (vdev_indirect_births_count(vib) != 0) {
2154 - ret = vdev_indirect_births_last_entry_txg(vib);
2155 - break;
2156 - }
2394 +#ifdef _KERNEL
2395 + kstat_named_init(&spa->spa_trimstats->st_extents,
2396 + "extents", KSTAT_DATA_UINT64);
2397 + kstat_named_init(&spa->spa_trimstats->st_bytes,
2398 + "bytes", KSTAT_DATA_UINT64);
2399 + kstat_named_init(&spa->spa_trimstats->st_extents_skipped,
2400 + "extents_skipped", KSTAT_DATA_UINT64);
2401 + kstat_named_init(&spa->spa_trimstats->st_bytes_skipped,
2402 + "bytes_skipped", KSTAT_DATA_UINT64);
2403 + kstat_named_init(&spa->spa_trimstats->st_auto_slow,
2404 + "auto_slow", KSTAT_DATA_UINT64);
2405 +#endif /* _KERNEL */
2157 2406
2158 - vdevid = vd->vdev_indirect_config.vic_prev_indirect_vdev;
2407 + kstat_install(spa->spa_trimstats_ks);
2408 + } else {
2409 + cmn_err(CE_NOTE, "!Cannot create trim kstats for pool %s",
2410 + spa->spa_name);
2159 2411 }
2160 - spa_config_exit(spa, SCL_VDEV, FTAG);
2412 +}
2161 2413
2162 - IMPLY(ret != -1ULL,
2163 - spa_feature_is_active(spa, SPA_FEATURE_DEVICE_REMOVAL));
2414 +/*
2415 + * Destroys the trim kstats for a spa.
2416 + */
2417 +static void
2418 +spa_trimstats_destroy(spa_t *spa)
2419 +{
2420 + if (spa->spa_trimstats_ks) {
2421 + kstat_delete(spa->spa_trimstats_ks);
2422 + spa->spa_trimstats = NULL;
2423 + spa->spa_trimstats_ks = NULL;
2424 + }
2425 +}
2164 2426
2165 - return (ret);
2427 +/*
2428 + * Updates the numerical trim kstats for a spa.
2429 + */
2430 +void
2431 +spa_trimstats_update(spa_t *spa, uint64_t extents, uint64_t bytes,
2432 + uint64_t extents_skipped, uint64_t bytes_skipped)
2433 +{
2434 + spa_trimstats_t *st = spa->spa_trimstats;
2435 + if (st) {
2436 + atomic_add_64(&st->st_extents.value.ui64, extents);
2437 + atomic_add_64(&st->st_bytes.value.ui64, bytes);
2438 + atomic_add_64(&st->st_extents_skipped.value.ui64,
2439 + extents_skipped);
2440 + atomic_add_64(&st->st_bytes_skipped.value.ui64,
2441 + bytes_skipped);
2442 + }
2166 2443 }
2167 2444
2168 -boolean_t
2169 -spa_trust_config(spa_t *spa)
2445 +/*
2446 + * Increments the slow-trim kstat for a spa.
2447 + */
2448 +void
2449 +spa_trimstats_auto_slow_incr(spa_t *spa)
2170 2450 {
2171 - return (spa->spa_trust_config);
2451 + spa_trimstats_t *st = spa->spa_trimstats;
2452 + if (st)
2453 + atomic_inc_64(&st->st_auto_slow.value.ui64);
2172 2454 }
2173 2455
2174 -uint64_t
2175 -spa_missing_tvds_allowed(spa_t *spa)
2456 +/*
2457 + * Creates the taskq used for dispatching auto-trim. This is called only when
2458 + * the property is set to `on' or when the pool is loaded (and the autotrim
2459 + * property is `on').
2460 + */
2461 +void
2462 +spa_auto_trim_taskq_create(spa_t *spa)
2176 2463 {
2177 - return (spa->spa_missing_tvds_allowed);
2464 + char name[MAXPATHLEN];
2465 + ASSERT(MUTEX_HELD(&spa->spa_auto_trim_lock));
2466 + ASSERT(spa->spa_auto_trim_taskq == NULL);
2467 + (void) snprintf(name, sizeof (name), "%s_auto_trim", spa->spa_name);
2468 + spa->spa_auto_trim_taskq = taskq_create(name, 1, minclsyspri, 1,
2469 + spa->spa_root_vdev->vdev_children, TASKQ_DYNAMIC);
2470 + VERIFY(spa->spa_auto_trim_taskq != NULL);
2178 2471 }
2179 2472
2473 +/*
2474 + * Creates the taskq for dispatching manual trim. This taskq is recreated
2475 + * each time `zpool trim <poolname>' is issued and destroyed after the run
2476 + * completes in an async spa request.
2477 + */
2180 2478 void
2181 -spa_set_missing_tvds(spa_t *spa, uint64_t missing)
2479 +spa_man_trim_taskq_create(spa_t *spa)
2182 2480 {
2183 - spa->spa_missing_tvds = missing;
2481 + char name[MAXPATHLEN];
2482 + ASSERT(MUTEX_HELD(&spa->spa_man_trim_lock));
2483 + spa_async_unrequest(spa, SPA_ASYNC_MAN_TRIM_TASKQ_DESTROY);
2484 + if (spa->spa_man_trim_taskq != NULL)
2485 + /*
2486 + * The async taskq destroy has been pre-empted, so just
2487 + * return, the taskq is still good to use.
2488 + */
2489 + return;
2490 + (void) snprintf(name, sizeof (name), "%s_man_trim", spa->spa_name);
2491 + spa->spa_man_trim_taskq = taskq_create(name, 1, minclsyspri, 1,
2492 + spa->spa_root_vdev->vdev_children, TASKQ_DYNAMIC);
2493 + VERIFY(spa->spa_man_trim_taskq != NULL);
2494 +}
2495 +
2496 +/*
2497 + * Destroys the taskq created in spa_auto_trim_taskq_create. The taskq
2498 + * is only destroyed when the autotrim property is set to `off'.
2499 + */
2500 +void
2501 +spa_auto_trim_taskq_destroy(spa_t *spa)
2502 +{
2503 + ASSERT(MUTEX_HELD(&spa->spa_auto_trim_lock));
2504 + ASSERT(spa->spa_auto_trim_taskq != NULL);
2505 + while (spa->spa_num_auto_trimming != 0)
2506 + cv_wait(&spa->spa_auto_trim_done_cv, &spa->spa_auto_trim_lock);
2507 + taskq_destroy(spa->spa_auto_trim_taskq);
2508 + spa->spa_auto_trim_taskq = NULL;
2509 +}
2510 +
2511 +/*
2512 + * Destroys the taskq created in spa_man_trim_taskq_create. The taskq is
2513 + * destroyed after a manual trim run completes from an async spa request.
2514 + * There is a bit of lag between an async request being issued at the
2515 + * completion of a trim run and it finally being acted on, hence why this
2516 + * function checks if new manual trimming threads haven't been re-spawned.
2517 + * If they have, we assume the async spa request been preempted by another
2518 + * manual trim request and we back off.
2519 + */
2520 +void
2521 +spa_man_trim_taskq_destroy(spa_t *spa)
2522 +{
2523 + ASSERT(MUTEX_HELD(&spa->spa_man_trim_lock));
2524 + ASSERT(spa->spa_man_trim_taskq != NULL);
2525 + if (spa->spa_num_man_trimming != 0)
2526 + /* another trim got started before we got here, back off */
2527 + return;
2528 + taskq_destroy(spa->spa_man_trim_taskq);
2529 + spa->spa_man_trim_taskq = NULL;
2184 2530 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX