Print this page
NEX-9673 Add capability to replicate cloned datasets relative to origin
Reviewed by: Alex Deiter <alex.deiter@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-5085 implement async delete for large files
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Revert "NEX-5085 implement async delete for large files"
This reverts commit 65aa8f42d93fcbd6e0efb3d4883170a20d760611.
Fails regression testing of the zfs test mirror_stress_004.
NEX-5085 implement async delete for large files
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Kirill Davydychev <kirill.davydychev@nexenta.com>
NEX-7479 Autosnap may dispatch duplicated sync-tasks
Reviewed by: Alex Deiter <alex.deiter@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexent.com>
NEX-7543 backout async delete (NEX-5085 and NEX-6151)
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@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-5078 Want ability to see progress of freeing data and how much is left to free after large file delete patch
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-5085 implement async delete for large files
Reviewed by: Marcel Telka <marcel.telka@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
NEX-5024 Slow performance with a single large file delete
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-4830 writecache=off leaks data on special vdev (the data will never migrate)
Reviewed by: Alex Aizman <alex.aizman@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
5981 Deadlock in dmu_objset_find_dp
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Dan McDonald <danmcd@omniti.com>
Approved by: Robert Mustacchi <rm@joyent.com>
5269 zpool import slow
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george@delphix.com>
Reviewed by: Dan McDonald <danmcd@omniti.com>
Approved by: Dan McDonald <danmcd@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-3964 It should not be allowed to rename a snapshot that its new name is matched to the prefix of in-kernel autosnapshots
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
NEX-3485 Deferred deletes causing loss of service for NFS clients on cluster failover
Reviewed by: Marcel Telka <marcel.telka@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
NEX-3558 KRRP Integration
NEX-3079 port illumos ARC improvements
Fixup merge results
re #13253 rb4328 ssh: openssl version checking needs updating
re #11441 rb4292 panic in apic_record_rdt_entry on VMware hardware version 9
re #12619, rb4287 Deadlocked zfs txg processing in dsl_sync_task_group_sync()
re #12585 rb4049 ZFS++ work port - refactoring to improve separation of open/closed code, bug fixes, performance improvements - open code
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/dsl_pool.c
+++ new/usr/src/uts/common/fs/zfs/dsl_pool.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
|
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
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 24 * Copyright (c) 2013 Steven Hartland. All rights reserved.
25 25 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
26 26 * Copyright (c) 2014 Integros [integros.com]
27 - * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
27 + * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
28 28 */
29 29
30 +#include <sys/autosnap.h>
30 31 #include <sys/dsl_pool.h>
31 32 #include <sys/dsl_dataset.h>
32 33 #include <sys/dsl_prop.h>
33 34 #include <sys/dsl_dir.h>
34 35 #include <sys/dsl_synctask.h>
36 +#include <sys/dsl_dataset.h>
35 37 #include <sys/dsl_scan.h>
36 38 #include <sys/dnode.h>
37 39 #include <sys/dmu_tx.h>
38 40 #include <sys/dmu_objset.h>
41 +#include <sys/dmu_traverse.h>
39 42 #include <sys/arc.h>
40 43 #include <sys/zap.h>
41 44 #include <sys/zio.h>
42 45 #include <sys/zfs_context.h>
43 46 #include <sys/fs/zfs.h>
44 47 #include <sys/zfs_znode.h>
45 48 #include <sys/spa_impl.h>
46 49 #include <sys/dsl_deadlist.h>
47 50 #include <sys/bptree.h>
48 51 #include <sys/zfeature.h>
49 52 #include <sys/zil_impl.h>
50 53 #include <sys/dsl_userhold.h>
51 54
55 +#include <sys/wbc.h>
56 +#include <sys/time.h>
57 +
52 58 /*
53 59 * ZFS Write Throttle
54 60 * ------------------
55 61 *
56 62 * ZFS must limit the rate of incoming writes to the rate at which it is able
57 63 * to sync data modifications to the backend storage. Throttling by too much
58 64 * creates an artificial limit; throttling by too little can only be sustained
59 65 * for short periods and would lead to highly lumpy performance. On a per-pool
60 66 * basis, ZFS tracks the amount of modified (dirty) data. As operations change
61 67 * data, the amount of dirty data increases; as ZFS syncs out data, the amount
62 68 * of dirty data decreases. When the amount of dirty data exceeds a
63 69 * predetermined threshold further modifications are blocked until the amount
64 70 * of dirty data decreases (as data is synced out).
65 71 *
66 72 * The limit on dirty data is tunable, and should be adjusted according to
67 73 * both the IO capacity and available memory of the system. The larger the
68 74 * window, the more ZFS is able to aggregate and amortize metadata (and data)
69 75 * changes. However, memory is a limited resource, and allowing for more dirty
70 76 * data comes at the cost of keeping other useful data in memory (for example
71 77 * ZFS data cached by the ARC).
72 78 *
73 79 * Implementation
74 80 *
75 81 * As buffers are modified dsl_pool_willuse_space() increments both the per-
76 82 * txg (dp_dirty_pertxg[]) and poolwide (dp_dirty_total) accounting of
77 83 * dirty space used; dsl_pool_dirty_space() decrements those values as data
78 84 * is synced out from dsl_pool_sync(). While only the poolwide value is
79 85 * relevant, the per-txg value is useful for debugging. The tunable
80 86 * zfs_dirty_data_max determines the dirty space limit. Once that value is
81 87 * exceeded, new writes are halted until space frees up.
82 88 *
83 89 * The zfs_dirty_data_sync tunable dictates the threshold at which we
84 90 * ensure that there is a txg syncing (see the comment in txg.c for a full
85 91 * description of transaction group stages).
86 92 *
87 93 * The IO scheduler uses both the dirty space limit and current amount of
88 94 * dirty data as inputs. Those values affect the number of concurrent IOs ZFS
89 95 * issues. See the comment in vdev_queue.c for details of the IO scheduler.
90 96 *
91 97 * The delay is also calculated based on the amount of dirty data. See the
92 98 * comment above dmu_tx_delay() for details.
93 99 */
94 100
95 101 /*
96 102 * zfs_dirty_data_max will be set to zfs_dirty_data_max_percent% of all memory,
97 103 * capped at zfs_dirty_data_max_max. It can also be overridden in /etc/system.
98 104 */
99 105 uint64_t zfs_dirty_data_max;
100 106 uint64_t zfs_dirty_data_max_max = 4ULL * 1024 * 1024 * 1024;
101 107 int zfs_dirty_data_max_percent = 10;
102 108
103 109 /*
104 110 * If there is at least this much dirty data, push out a txg.
105 111 */
106 112 uint64_t zfs_dirty_data_sync = 64 * 1024 * 1024;
107 113
108 114 /*
109 115 * Once there is this amount of dirty data, the dmu_tx_delay() will kick in
110 116 * and delay each transaction.
111 117 * This value should be >= zfs_vdev_async_write_active_max_dirty_percent.
112 118 */
113 119 int zfs_delay_min_dirty_percent = 60;
114 120
115 121 /*
116 122 * This controls how quickly the delay approaches infinity.
117 123 * Larger values cause it to delay more for a given amount of dirty data.
118 124 * Therefore larger values will cause there to be less dirty data for a
119 125 * given throughput.
120 126 *
121 127 * For the smoothest delay, this value should be about 1 billion divided
122 128 * by the maximum number of operations per second. This will smoothly
123 129 * handle between 10x and 1/10th this number.
124 130 *
125 131 * Note: zfs_delay_scale * zfs_dirty_data_max must be < 2^64, due to the
126 132 * multiply in dmu_tx_delay().
127 133 */
128 134 uint64_t zfs_delay_scale = 1000 * 1000 * 1000 / 2000;
129 135
130 136 /*
131 137 * This determines the number of threads used by the dp_sync_taskq.
132 138 */
133 139 int zfs_sync_taskq_batch_pct = 75;
134 140
135 141 /*
136 142 * These tunables determine the behavior of how zil_itxg_clean() is
137 143 * called via zil_clean() in the context of spa_sync(). When an itxg
138 144 * list needs to be cleaned, TQ_NOSLEEP will be used when dispatching.
139 145 * If the dispatch fails, the call to zil_itxg_clean() will occur
140 146 * synchronously in the context of spa_sync(), which can negatively
141 147 * impact the performance of spa_sync() (e.g. in the case of the itxg
142 148 * list having a large number of itxs that needs to be cleaned).
143 149 *
144 150 * Thus, these tunables can be used to manipulate the behavior of the
145 151 * taskq used by zil_clean(); they determine the number of taskq entries
146 152 * that are pre-populated when the taskq is first created (via the
147 153 * "zfs_zil_clean_taskq_minalloc" tunable) and the maximum number of
148 154 * taskq entries that are cached after an on-demand allocation (via the
149 155 * "zfs_zil_clean_taskq_maxalloc").
150 156 *
151 157 * The idea being, we want to try reasonably hard to ensure there will
152 158 * already be a taskq entry pre-allocated by the time that it is needed
153 159 * by zil_clean(). This way, we can avoid the possibility of an
154 160 * on-demand allocation of a new taskq entry from failing, which would
|
↓ open down ↓ |
93 lines elided |
↑ open up ↑ |
155 161 * result in zil_itxg_clean() being called synchronously from zil_clean()
156 162 * (which can adversely affect performance of spa_sync()).
157 163 *
158 164 * Additionally, the number of threads used by the taskq can be
159 165 * configured via the "zfs_zil_clean_taskq_nthr_pct" tunable.
160 166 */
161 167 int zfs_zil_clean_taskq_nthr_pct = 100;
162 168 int zfs_zil_clean_taskq_minalloc = 1024;
163 169 int zfs_zil_clean_taskq_maxalloc = 1024 * 1024;
164 170
171 +/*
172 + * Tunable to control max number of tasks available for processing of
173 + * deferred deletes.
174 + */
175 +int zfs_vn_rele_max_tasks = 256;
176 +
165 177 int
166 178 dsl_pool_open_special_dir(dsl_pool_t *dp, const char *name, dsl_dir_t **ddp)
167 179 {
168 180 uint64_t obj;
169 181 int err;
170 182
171 183 err = zap_lookup(dp->dp_meta_objset,
172 184 dsl_dir_phys(dp->dp_root_dir)->dd_child_dir_zapobj,
173 185 name, sizeof (obj), 1, &obj);
174 186 if (err)
175 187 return (err);
176 188
177 189 return (dsl_dir_hold_obj(dp, obj, name, dp, ddp));
178 190 }
179 191
|
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
180 192 static dsl_pool_t *
181 193 dsl_pool_open_impl(spa_t *spa, uint64_t txg)
182 194 {
183 195 dsl_pool_t *dp;
184 196 blkptr_t *bp = spa_get_rootblkptr(spa);
185 197
186 198 dp = kmem_zalloc(sizeof (dsl_pool_t), KM_SLEEP);
187 199 dp->dp_spa = spa;
188 200 dp->dp_meta_rootbp = *bp;
189 201 rrw_init(&dp->dp_config_rwlock, B_TRUE);
202 +
203 + dp->dp_sync_history[0] = dp->dp_sync_history[1] = 0;
204 +
190 205 txg_init(dp, txg);
191 206
192 207 txg_list_create(&dp->dp_dirty_datasets, spa,
193 208 offsetof(dsl_dataset_t, ds_dirty_link));
194 209 txg_list_create(&dp->dp_dirty_zilogs, spa,
195 210 offsetof(zilog_t, zl_dirty_link));
196 211 txg_list_create(&dp->dp_dirty_dirs, spa,
197 212 offsetof(dsl_dir_t, dd_dirty_link));
198 213 txg_list_create(&dp->dp_sync_tasks, spa,
199 214 offsetof(dsl_sync_task_t, dst_node));
200 215
201 216 dp->dp_sync_taskq = taskq_create("dp_sync_taskq",
202 217 zfs_sync_taskq_batch_pct, minclsyspri, 1, INT_MAX,
203 218 TASKQ_THREADS_CPU_PCT);
|
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
204 219
205 220 dp->dp_zil_clean_taskq = taskq_create("dp_zil_clean_taskq",
206 221 zfs_zil_clean_taskq_nthr_pct, minclsyspri,
207 222 zfs_zil_clean_taskq_minalloc,
208 223 zfs_zil_clean_taskq_maxalloc,
209 224 TASKQ_PREPOPULATE | TASKQ_THREADS_CPU_PCT);
210 225
211 226 mutex_init(&dp->dp_lock, NULL, MUTEX_DEFAULT, NULL);
212 227 cv_init(&dp->dp_spaceavail_cv, NULL, CV_DEFAULT, NULL);
213 228
214 - dp->dp_vnrele_taskq = taskq_create("zfs_vn_rele_taskq", 1, minclsyspri,
215 - 1, 4, 0);
229 + dp->dp_vnrele_taskq = taskq_create("zfs_vn_rele_taskq",
230 + zfs_vn_rele_max_tasks, minclsyspri,
231 + 1, zfs_vn_rele_max_tasks, TASKQ_DYNAMIC);
216 232
217 233 return (dp);
218 234 }
219 235
220 236 int
221 237 dsl_pool_init(spa_t *spa, uint64_t txg, dsl_pool_t **dpp)
222 238 {
223 239 int err;
224 240 dsl_pool_t *dp = dsl_pool_open_impl(spa, txg);
225 241
226 242 err = dmu_objset_open_impl(spa, NULL, &dp->dp_meta_rootbp,
227 243 &dp->dp_meta_objset);
228 244 if (err != 0)
229 245 dsl_pool_close(dp);
230 246 else
231 247 *dpp = dp;
232 248
233 249 return (err);
234 250 }
235 251
236 252 int
237 253 dsl_pool_open(dsl_pool_t *dp)
238 254 {
239 255 int err;
240 256 dsl_dir_t *dd;
241 257 dsl_dataset_t *ds;
242 258 uint64_t obj;
243 259
244 260 rrw_enter(&dp->dp_config_rwlock, RW_WRITER, FTAG);
245 261 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
246 262 DMU_POOL_ROOT_DATASET, sizeof (uint64_t), 1,
247 263 &dp->dp_root_dir_obj);
248 264 if (err)
249 265 goto out;
250 266
251 267 err = dsl_dir_hold_obj(dp, dp->dp_root_dir_obj,
252 268 NULL, dp, &dp->dp_root_dir);
253 269 if (err)
254 270 goto out;
255 271
256 272 err = dsl_pool_open_special_dir(dp, MOS_DIR_NAME, &dp->dp_mos_dir);
257 273 if (err)
258 274 goto out;
259 275
260 276 if (spa_version(dp->dp_spa) >= SPA_VERSION_ORIGIN) {
261 277 err = dsl_pool_open_special_dir(dp, ORIGIN_DIR_NAME, &dd);
262 278 if (err)
263 279 goto out;
264 280 err = dsl_dataset_hold_obj(dp,
265 281 dsl_dir_phys(dd)->dd_head_dataset_obj, FTAG, &ds);
266 282 if (err == 0) {
267 283 err = dsl_dataset_hold_obj(dp,
268 284 dsl_dataset_phys(ds)->ds_prev_snap_obj, dp,
269 285 &dp->dp_origin_snap);
270 286 dsl_dataset_rele(ds, FTAG);
271 287 }
272 288 dsl_dir_rele(dd, dp);
273 289 if (err)
274 290 goto out;
275 291 }
276 292
277 293 if (spa_version(dp->dp_spa) >= SPA_VERSION_DEADLISTS) {
278 294 err = dsl_pool_open_special_dir(dp, FREE_DIR_NAME,
279 295 &dp->dp_free_dir);
280 296 if (err)
|
↓ open down ↓ |
55 lines elided |
↑ open up ↑ |
281 297 goto out;
282 298
283 299 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
284 300 DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj);
285 301 if (err)
286 302 goto out;
287 303 VERIFY0(bpobj_open(&dp->dp_free_bpobj,
288 304 dp->dp_meta_objset, obj));
289 305 }
290 306
291 - if (spa_feature_is_active(dp->dp_spa, SPA_FEATURE_OBSOLETE_COUNTS)) {
292 - err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
293 - DMU_POOL_OBSOLETE_BPOBJ, sizeof (uint64_t), 1, &obj);
294 - if (err == 0) {
295 - VERIFY0(bpobj_open(&dp->dp_obsolete_bpobj,
296 - dp->dp_meta_objset, obj));
297 - } else if (err == ENOENT) {
298 - /*
299 - * We might not have created the remap bpobj yet.
300 - */
301 - err = 0;
302 - } else {
303 - goto out;
304 - }
305 - }
306 -
307 307 /*
308 - * Note: errors ignored, because the these special dirs, used for
309 - * space accounting, are only created on demand.
308 + * Note: errors ignored, because the leak dir will not exist if we
309 + * have not encountered a leak yet.
310 310 */
311 311 (void) dsl_pool_open_special_dir(dp, LEAK_DIR_NAME,
312 312 &dp->dp_leak_dir);
313 313
314 314 if (spa_feature_is_active(dp->dp_spa, SPA_FEATURE_ASYNC_DESTROY)) {
315 315 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
316 316 DMU_POOL_BPTREE_OBJ, sizeof (uint64_t), 1,
317 317 &dp->dp_bptree_obj);
318 318 if (err != 0)
319 319 goto out;
320 320 }
321 321
322 322 if (spa_feature_is_active(dp->dp_spa, SPA_FEATURE_EMPTY_BPOBJ)) {
323 323 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
324 324 DMU_POOL_EMPTY_BPOBJ, sizeof (uint64_t), 1,
325 325 &dp->dp_empty_bpobj);
326 326 if (err != 0)
327 327 goto out;
328 328 }
329 329
330 330 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
331 331 DMU_POOL_TMP_USERREFS, sizeof (uint64_t), 1,
332 332 &dp->dp_tmp_userrefs_obj);
333 333 if (err == ENOENT)
334 334 err = 0;
335 335 if (err)
336 336 goto out;
337 337
338 338 err = dsl_scan_init(dp, dp->dp_tx.tx_open_txg);
339 339
340 340 out:
341 341 rrw_exit(&dp->dp_config_rwlock, FTAG);
342 342 return (err);
343 343 }
344 344
|
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
345 345 void
346 346 dsl_pool_close(dsl_pool_t *dp)
347 347 {
348 348 /*
349 349 * Drop our references from dsl_pool_open().
350 350 *
351 351 * Since we held the origin_snap from "syncing" context (which
352 352 * includes pool-opening context), it actually only got a "ref"
353 353 * and not a hold, so just drop that here.
354 354 */
355 - if (dp->dp_origin_snap != NULL)
355 + if (dp->dp_origin_snap)
356 356 dsl_dataset_rele(dp->dp_origin_snap, dp);
357 - if (dp->dp_mos_dir != NULL)
357 + if (dp->dp_mos_dir)
358 358 dsl_dir_rele(dp->dp_mos_dir, dp);
359 - if (dp->dp_free_dir != NULL)
359 + if (dp->dp_free_dir)
360 360 dsl_dir_rele(dp->dp_free_dir, dp);
361 - if (dp->dp_leak_dir != NULL)
361 + if (dp->dp_leak_dir)
362 362 dsl_dir_rele(dp->dp_leak_dir, dp);
363 - if (dp->dp_root_dir != NULL)
363 + if (dp->dp_root_dir)
364 364 dsl_dir_rele(dp->dp_root_dir, dp);
365 365
366 366 bpobj_close(&dp->dp_free_bpobj);
367 - bpobj_close(&dp->dp_obsolete_bpobj);
368 367
369 368 /* undo the dmu_objset_open_impl(mos) from dsl_pool_open() */
370 - if (dp->dp_meta_objset != NULL)
369 + if (dp->dp_meta_objset)
371 370 dmu_objset_evict(dp->dp_meta_objset);
372 371
373 372 txg_list_destroy(&dp->dp_dirty_datasets);
374 373 txg_list_destroy(&dp->dp_dirty_zilogs);
375 374 txg_list_destroy(&dp->dp_sync_tasks);
376 375 txg_list_destroy(&dp->dp_dirty_dirs);
377 376
378 377 taskq_destroy(dp->dp_zil_clean_taskq);
379 378 taskq_destroy(dp->dp_sync_taskq);
380 379
381 380 /*
382 381 * We can't set retry to TRUE since we're explicitly specifying
383 382 * a spa to flush. This is good enough; any missed buffers for
384 383 * this spa won't cause trouble, and they'll eventually fall
385 384 * out of the ARC just like any other unused buffer.
386 385 */
387 - arc_flush(dp->dp_spa, FALSE);
388 -
386 + arc_flush(dp->dp_spa, B_FALSE);
389 387 txg_fini(dp);
390 388 dsl_scan_fini(dp);
391 389 dmu_buf_user_evict_wait();
392 390
393 391 rrw_destroy(&dp->dp_config_rwlock);
394 392 mutex_destroy(&dp->dp_lock);
395 393 taskq_destroy(dp->dp_vnrele_taskq);
396 - if (dp->dp_blkstats != NULL)
394 + if (dp->dp_blkstats)
397 395 kmem_free(dp->dp_blkstats, sizeof (zfs_all_blkstats_t));
398 396 kmem_free(dp, sizeof (dsl_pool_t));
399 397 }
400 398
401 -void
402 -dsl_pool_create_obsolete_bpobj(dsl_pool_t *dp, dmu_tx_t *tx)
403 -{
404 - uint64_t obj;
405 - /*
406 - * Currently, we only create the obsolete_bpobj where there are
407 - * indirect vdevs with referenced mappings.
408 - */
409 - ASSERT(spa_feature_is_active(dp->dp_spa, SPA_FEATURE_DEVICE_REMOVAL));
410 - /* create and open the obsolete_bpobj */
411 - obj = bpobj_alloc(dp->dp_meta_objset, SPA_OLD_MAXBLOCKSIZE, tx);
412 - VERIFY0(bpobj_open(&dp->dp_obsolete_bpobj, dp->dp_meta_objset, obj));
413 - VERIFY0(zap_add(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
414 - DMU_POOL_OBSOLETE_BPOBJ, sizeof (uint64_t), 1, &obj, tx));
415 - spa_feature_incr(dp->dp_spa, SPA_FEATURE_OBSOLETE_COUNTS, tx);
416 -}
417 -
418 -void
419 -dsl_pool_destroy_obsolete_bpobj(dsl_pool_t *dp, dmu_tx_t *tx)
420 -{
421 - spa_feature_decr(dp->dp_spa, SPA_FEATURE_OBSOLETE_COUNTS, tx);
422 - VERIFY0(zap_remove(dp->dp_meta_objset,
423 - DMU_POOL_DIRECTORY_OBJECT,
424 - DMU_POOL_OBSOLETE_BPOBJ, tx));
425 - bpobj_free(dp->dp_meta_objset,
426 - dp->dp_obsolete_bpobj.bpo_object, tx);
427 - bpobj_close(&dp->dp_obsolete_bpobj);
428 -}
429 -
430 399 dsl_pool_t *
431 400 dsl_pool_create(spa_t *spa, nvlist_t *zplprops, uint64_t txg)
432 401 {
433 402 int err;
434 403 dsl_pool_t *dp = dsl_pool_open_impl(spa, txg);
435 404 dmu_tx_t *tx = dmu_tx_create_assigned(dp, txg);
436 405 dsl_dataset_t *ds;
437 406 uint64_t obj;
438 407
439 408 rrw_enter(&dp->dp_config_rwlock, RW_WRITER, FTAG);
440 409
441 410 /* create and open the MOS (meta-objset) */
442 411 dp->dp_meta_objset = dmu_objset_create_impl(spa,
443 412 NULL, &dp->dp_meta_rootbp, DMU_OST_META, tx);
444 413
445 414 /* create the pool directory */
446 415 err = zap_create_claim(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
447 416 DMU_OT_OBJECT_DIRECTORY, DMU_OT_NONE, 0, tx);
448 417 ASSERT0(err);
449 418
450 419 /* Initialize scan structures */
451 420 VERIFY0(dsl_scan_init(dp, txg));
452 421
453 422 /* create and open the root dir */
454 423 dp->dp_root_dir_obj = dsl_dir_create_sync(dp, NULL, NULL, tx);
455 424 VERIFY0(dsl_dir_hold_obj(dp, dp->dp_root_dir_obj,
456 425 NULL, dp, &dp->dp_root_dir));
457 426
458 427 /* create and open the meta-objset dir */
459 428 (void) dsl_dir_create_sync(dp, dp->dp_root_dir, MOS_DIR_NAME, tx);
460 429 VERIFY0(dsl_pool_open_special_dir(dp,
461 430 MOS_DIR_NAME, &dp->dp_mos_dir));
462 431
463 432 if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
464 433 /* create and open the free dir */
465 434 (void) dsl_dir_create_sync(dp, dp->dp_root_dir,
466 435 FREE_DIR_NAME, tx);
467 436 VERIFY0(dsl_pool_open_special_dir(dp,
468 437 FREE_DIR_NAME, &dp->dp_free_dir));
469 438
470 439 /* create and open the free_bplist */
471 440 obj = bpobj_alloc(dp->dp_meta_objset, SPA_OLD_MAXBLOCKSIZE, tx);
472 441 VERIFY(zap_add(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
473 442 DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj, tx) == 0);
474 443 VERIFY0(bpobj_open(&dp->dp_free_bpobj,
475 444 dp->dp_meta_objset, obj));
476 445 }
477 446
478 447 if (spa_version(spa) >= SPA_VERSION_DSL_SCRUB)
479 448 dsl_pool_create_origin(dp, tx);
480 449
481 450 /* create the root dataset */
482 451 obj = dsl_dataset_create_sync_dd(dp->dp_root_dir, NULL, 0, tx);
483 452
484 453 /* create the root objset */
485 454 VERIFY0(dsl_dataset_hold_obj(dp, obj, FTAG, &ds));
486 455 #ifdef _KERNEL
487 456 {
488 457 objset_t *os;
489 458 rrw_enter(&ds->ds_bp_rwlock, RW_READER, FTAG);
490 459 os = dmu_objset_create_impl(dp->dp_spa, ds,
491 460 dsl_dataset_get_blkptr(ds), DMU_OST_ZFS, tx);
492 461 rrw_exit(&ds->ds_bp_rwlock, FTAG);
493 462 zfs_create_fs(os, kcred, zplprops, tx);
494 463 }
495 464 #endif
496 465 dsl_dataset_rele(ds, FTAG);
497 466
498 467 dmu_tx_commit(tx);
499 468
500 469 rrw_exit(&dp->dp_config_rwlock, FTAG);
501 470
502 471 return (dp);
503 472 }
504 473
505 474 /*
506 475 * Account for the meta-objset space in its placeholder dsl_dir.
507 476 */
508 477 void
509 478 dsl_pool_mos_diduse_space(dsl_pool_t *dp,
510 479 int64_t used, int64_t comp, int64_t uncomp)
511 480 {
512 481 ASSERT3U(comp, ==, uncomp); /* it's all metadata */
513 482 mutex_enter(&dp->dp_lock);
514 483 dp->dp_mos_used_delta += used;
515 484 dp->dp_mos_compressed_delta += comp;
516 485 dp->dp_mos_uncompressed_delta += uncomp;
517 486 mutex_exit(&dp->dp_lock);
518 487 }
519 488
520 489 static void
521 490 dsl_pool_sync_mos(dsl_pool_t *dp, dmu_tx_t *tx)
522 491 {
523 492 zio_t *zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
524 493 dmu_objset_sync(dp->dp_meta_objset, zio, tx);
525 494 VERIFY0(zio_wait(zio));
526 495 dprintf_bp(&dp->dp_meta_rootbp, "meta objset rootbp is %s", "");
527 496 spa_set_rootblkptr(dp->dp_spa, &dp->dp_meta_rootbp);
528 497 }
529 498
530 499 static void
531 500 dsl_pool_dirty_delta(dsl_pool_t *dp, int64_t delta)
532 501 {
533 502 ASSERT(MUTEX_HELD(&dp->dp_lock));
534 503
535 504 if (delta < 0)
536 505 ASSERT3U(-delta, <=, dp->dp_dirty_total);
537 506
538 507 dp->dp_dirty_total += delta;
539 508
540 509 /*
541 510 * Note: we signal even when increasing dp_dirty_total.
542 511 * This ensures forward progress -- each thread wakes the next waiter.
543 512 */
544 513 if (dp->dp_dirty_total < zfs_dirty_data_max)
545 514 cv_signal(&dp->dp_spaceavail_cv);
|
↓ open down ↓ |
106 lines elided |
↑ open up ↑ |
546 515 }
547 516
548 517 void
549 518 dsl_pool_sync(dsl_pool_t *dp, uint64_t txg)
550 519 {
551 520 zio_t *zio;
552 521 dmu_tx_t *tx;
553 522 dsl_dir_t *dd;
554 523 dsl_dataset_t *ds;
555 524 objset_t *mos = dp->dp_meta_objset;
525 + spa_t *spa = dp->dp_spa;
556 526 list_t synced_datasets;
527 + dsl_sync_task_t *iter;
528 + boolean_t wbc_skip_txg = B_FALSE;
529 + boolean_t sync_ops = B_FALSE;
530 + boolean_t user_snap = B_FALSE;
531 + zfs_autosnap_t *autosnap = spa_get_autosnap(spa);
532 + boolean_t autosnap_initialized = autosnap->initialized;
533 + char snap[ZFS_MAX_DATASET_NAME_LEN];
557 534
535 + /* check if there are ny sync ops in the txg */
536 + if (txg_list_head(&dp->dp_sync_tasks, txg) != NULL)
537 + sync_ops = B_TRUE;
538 +
539 + /* check if there are user snaps in the txg */
540 + for (iter = txg_list_head(&dp->dp_sync_tasks, txg);
541 + iter != NULL;
542 + iter = txg_list_next(&dp->dp_sync_tasks, iter, txg)) {
543 + if (iter->dst_syncfunc == dsl_dataset_snapshot_sync) {
544 + user_snap = B_TRUE;
545 + break;
546 + }
547 + }
548 +
549 +
558 550 list_create(&synced_datasets, sizeof (dsl_dataset_t),
559 551 offsetof(dsl_dataset_t, ds_synced_link));
560 552
561 553 tx = dmu_tx_create_assigned(dp, txg);
562 554
555 + (void) sprintf(snap, "%s%llu", AUTOSNAP_PREFIX,
556 + (unsigned long long int) txg);
557 +
558 + if (autosnap_initialized && spa->spa_sync_pass == 1) {
559 + autosnap_zone_t *azone;
560 +
561 + rrw_enter(&dp->dp_config_rwlock, RW_READER, FTAG);
562 + mutex_enter(&autosnap->autosnap_lock);
563 +
564 + /*
565 + * WBC: the mechanism to ensure all WBC-ed dirty datasets
566 + * are synchronously auto-snapshotted
567 + * within (or by) the same TXG sync
568 + * The "synchronicity" of the rightmost boundary of the WBC
569 + * window is important to avoid used-space leakages
570 + * on special vdev.
571 + * Note that we skip here the WBC-ed datasets that are
572 + * already fully migrated and don't have data on special
573 + */
574 +
575 + for (ds = txg_list_head(&dp->dp_dirty_datasets, txg);
576 + ds != NULL;
577 + ds = txg_list_next(&dp->dp_dirty_datasets, ds, txg)) {
578 + char ds_name[ZFS_MAX_DATASET_NAME_LEN];
579 + boolean_t wbc_azone;
580 +
581 + dsl_dataset_name(ds, ds_name);
582 +
583 + azone = autosnap_find_zone(autosnap, ds_name, B_TRUE);
584 + if (azone == NULL)
585 + continue;
586 +
587 + if ((azone->flags & AUTOSNAP_CREATOR) == 0)
588 + continue;
589 +
590 + if (azone->created)
591 + continue;
592 +
593 + azone->delayed = B_TRUE;
594 + azone->dirty = B_TRUE;
595 + wbc_azone = (azone->flags & AUTOSNAP_WBC) != 0;
596 +
597 + if (autosnap_confirm_snap(azone, txg)) {
598 + if (!wbc_azone && !user_snap && !sync_ops) {
599 + autosnap_create_snapshot(azone,
600 + snap, dp, txg, tx);
601 + }
602 + } else if (wbc_azone) {
603 + wbc_skip_txg = B_TRUE;
604 + }
605 + }
606 +
607 + azone = list_head(&autosnap->autosnap_zones);
608 + while (azone != NULL) {
609 + boolean_t wbc_azone =
610 + ((azone->flags & AUTOSNAP_WBC) != 0);
611 +
612 + if (user_snap) {
613 + azone->delayed = B_TRUE;
614 + } else if (!azone->dirty && azone->delayed) {
615 + if (autosnap_confirm_snap(azone, txg)) {
616 + if (!wbc_azone && !user_snap &&
617 + !sync_ops) {
618 + autosnap_create_snapshot(azone,
619 + snap, dp, txg, tx);
620 + }
621 + } else if (wbc_azone) {
622 + wbc_skip_txg = B_TRUE;
623 + }
624 + }
625 +
626 + azone = list_next(&autosnap->autosnap_zones, azone);
627 + }
628 +
629 + mutex_exit(&autosnap->autosnap_lock);
630 + rrw_exit(&dp->dp_config_rwlock, FTAG);
631 + }
632 +
633 +
563 634 /*
564 635 * Write out all dirty blocks of dirty datasets.
565 636 */
566 637 zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
567 638 while ((ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) != NULL) {
639 +
568 640 /*
569 641 * We must not sync any non-MOS datasets twice, because
570 642 * we may have taken a snapshot of them. However, we
571 643 * may sync newly-created datasets on pass 2.
572 644 */
573 645 ASSERT(!list_link_active(&ds->ds_synced_link));
574 646 list_insert_tail(&synced_datasets, ds);
575 647 dsl_dataset_sync(ds, zio, tx);
576 648 }
649 +
577 650 VERIFY0(zio_wait(zio));
578 651
652 + if (autosnap_initialized && spa->spa_sync_pass == 1 &&
653 + !user_snap) {
654 + autosnap_zone_t *azone;
655 +
656 + rrw_enter(&dp->dp_config_rwlock, RW_READER, FTAG);
657 + mutex_enter(&autosnap->autosnap_lock);
658 +
659 + /*
660 + * At this stage we are walking over all delayed zones
661 + * to create autosnaps
662 + */
663 +
664 + azone = list_head(&autosnap->autosnap_zones);
665 + while (azone != NULL) {
666 + boolean_t skip_zone =
667 + ((azone->flags & AUTOSNAP_CREATOR) == 0);
668 +
669 + if (azone->delayed && !skip_zone) {
670 + boolean_t wbc_azone =
671 + ((azone->flags & AUTOSNAP_WBC) != 0);
672 +
673 + if ((!wbc_azone || !wbc_skip_txg) &&
674 + autosnap_confirm_snap(azone, txg)) {
675 + autosnap_create_snapshot(azone,
676 + snap, dp, txg, tx);
677 + }
678 + }
679 +
680 + if (skip_zone)
681 + azone->delayed = B_FALSE;
682 +
683 + azone = list_next(&autosnap->autosnap_zones, azone);
684 + }
685 +
686 + mutex_exit(&autosnap->autosnap_lock);
687 + rrw_exit(&dp->dp_config_rwlock, FTAG);
688 + }
689 +
579 690 /*
580 691 * We have written all of the accounted dirty data, so our
581 692 * dp_space_towrite should now be zero. However, some seldom-used
582 693 * code paths do not adhere to this (e.g. dbuf_undirty(), also
583 694 * rounding error in dbuf_write_physdone).
584 695 * Shore up the accounting of any dirtied space now.
585 696 */
586 697 dsl_pool_undirty_space(dp, dp->dp_dirty_pertxg[txg & TXG_MASK], txg);
587 698
588 699 /*
589 700 * Update the long range free counter after
590 701 * we're done syncing user data
591 702 */
592 703 mutex_enter(&dp->dp_lock);
593 704 ASSERT(spa_sync_pass(dp->dp_spa) == 1 ||
594 705 dp->dp_long_free_dirty_pertxg[txg & TXG_MASK] == 0);
706 + dp->dp_long_freeing_total -=
707 + dp->dp_long_free_dirty_pertxg[txg & TXG_MASK];
595 708 dp->dp_long_free_dirty_pertxg[txg & TXG_MASK] = 0;
596 709 mutex_exit(&dp->dp_lock);
597 710
598 711 /*
599 712 * After the data blocks have been written (ensured by the zio_wait()
600 713 * above), update the user/group space accounting. This happens
601 714 * in tasks dispatched to dp_sync_taskq, so wait for them before
602 715 * continuing.
603 716 */
604 717 for (ds = list_head(&synced_datasets); ds != NULL;
605 718 ds = list_next(&synced_datasets, ds)) {
606 719 dmu_objset_do_userquota_updates(ds->ds_objset, tx);
|
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
607 720 }
608 721 taskq_wait(dp->dp_sync_taskq);
609 722
610 723 /*
611 724 * Sync the datasets again to push out the changes due to
612 725 * userspace updates. This must be done before we process the
613 726 * sync tasks, so that any snapshots will have the correct
614 727 * user accounting information (and we won't get confused
615 728 * about which blocks are part of the snapshot).
616 729 */
730 +
617 731 zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
618 732 while ((ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) != NULL) {
619 733 ASSERT(list_link_active(&ds->ds_synced_link));
620 734 dmu_buf_rele(ds->ds_dbuf, ds);
621 735 dsl_dataset_sync(ds, zio, tx);
622 736 }
623 737 VERIFY0(zio_wait(zio));
624 738
625 739 /*
626 740 * Now that the datasets have been completely synced, we can
627 741 * clean up our in-memory structures accumulated while syncing:
628 742 *
629 743 * - move dead blocks from the pending deadlist to the on-disk deadlist
630 744 * - release hold from dsl_dataset_dirty()
631 745 */
632 746 while ((ds = list_remove_head(&synced_datasets)) != NULL) {
633 747 dsl_dataset_sync_done(ds, tx);
634 748 }
635 749 while ((dd = txg_list_remove(&dp->dp_dirty_dirs, txg)) != NULL) {
636 750 dsl_dir_sync(dd, tx);
637 751 }
638 752
639 753 /*
640 754 * The MOS's space is accounted for in the pool/$MOS
641 755 * (dp_mos_dir). We can't modify the mos while we're syncing
642 756 * it, so we remember the deltas and apply them here.
643 757 */
644 758 if (dp->dp_mos_used_delta != 0 || dp->dp_mos_compressed_delta != 0 ||
645 759 dp->dp_mos_uncompressed_delta != 0) {
646 760 dsl_dir_diduse_space(dp->dp_mos_dir, DD_USED_HEAD,
647 761 dp->dp_mos_used_delta,
648 762 dp->dp_mos_compressed_delta,
649 763 dp->dp_mos_uncompressed_delta, tx);
650 764 dp->dp_mos_used_delta = 0;
651 765 dp->dp_mos_compressed_delta = 0;
652 766 dp->dp_mos_uncompressed_delta = 0;
653 767 }
654 768
655 769 if (!multilist_is_empty(mos->os_dirty_dnodes[txg & TXG_MASK])) {
656 770 dsl_pool_sync_mos(dp, tx);
657 771 }
|
↓ open down ↓ |
31 lines elided |
↑ open up ↑ |
658 772
659 773 /*
660 774 * If we modify a dataset in the same txg that we want to destroy it,
661 775 * its dsl_dir's dd_dbuf will be dirty, and thus have a hold on it.
662 776 * dsl_dir_destroy_check() will fail if there are unexpected holds.
663 777 * Therefore, we want to sync the MOS (thus syncing the dd_dbuf
664 778 * and clearing the hold on it) before we process the sync_tasks.
665 779 * The MOS data dirtied by the sync_tasks will be synced on the next
666 780 * pass.
667 781 */
782 +
668 783 if (!txg_list_empty(&dp->dp_sync_tasks, txg)) {
669 784 dsl_sync_task_t *dst;
670 785 /*
671 786 * No more sync tasks should have been added while we
672 787 * were syncing.
673 788 */
674 789 ASSERT3U(spa_sync_pass(dp->dp_spa), ==, 1);
675 790 while ((dst = txg_list_remove(&dp->dp_sync_tasks, txg)) != NULL)
676 791 dsl_sync_task_sync(dst, tx);
677 792 }
678 793
794 + if (spa_feature_is_active(spa, SPA_FEATURE_WBC)) {
795 + wbc_trigger_wbcthread(dp->dp_spa,
796 + ((dp->dp_sync_history[0] + dp->dp_sync_history[1]) / 2));
797 + }
798 +
679 799 dmu_tx_commit(tx);
680 800
681 801 DTRACE_PROBE2(dsl_pool_sync__done, dsl_pool_t *dp, dp, uint64_t, txg);
682 802 }
683 803
684 804 void
685 805 dsl_pool_sync_done(dsl_pool_t *dp, uint64_t txg)
686 806 {
687 807 zilog_t *zilog;
688 808
689 809 while (zilog = txg_list_head(&dp->dp_dirty_zilogs, txg)) {
690 810 dsl_dataset_t *ds = dmu_objset_ds(zilog->zl_os);
691 811 /*
692 812 * We don't remove the zilog from the dp_dirty_zilogs
693 813 * list until after we've cleaned it. This ensures that
694 814 * callers of zilog_is_dirty() receive an accurate
695 815 * answer when they are racing with the spa sync thread.
696 816 */
697 817 zil_clean(zilog, txg);
698 818 (void) txg_list_remove_this(&dp->dp_dirty_zilogs, zilog, txg);
699 819 ASSERT(!dmu_objset_is_dirty(zilog->zl_os, txg));
700 820 dmu_buf_rele(ds->ds_dbuf, zilog);
701 821 }
702 822 ASSERT(!dmu_objset_is_dirty(dp->dp_meta_objset, txg));
703 823 }
704 824
705 825 /*
706 826 * TRUE if the current thread is the tx_sync_thread or if we
707 827 * are being called from SPA context during pool initialization.
708 828 */
709 829 int
710 830 dsl_pool_sync_context(dsl_pool_t *dp)
711 831 {
712 832 return (curthread == dp->dp_tx.tx_sync_thread ||
713 833 spa_is_initializing(dp->dp_spa) ||
714 834 taskq_member(dp->dp_sync_taskq, curthread));
715 835 }
716 836
717 837 uint64_t
718 838 dsl_pool_adjustedsize(dsl_pool_t *dp, boolean_t netfree)
719 839 {
720 840 uint64_t space, resv;
721 841
722 842 /*
723 843 * If we're trying to assess whether it's OK to do a free,
724 844 * cut the reservation in half to allow forward progress
725 845 * (e.g. make it possible to rm(1) files from a full pool).
726 846 */
727 847 space = spa_get_dspace(dp->dp_spa);
728 848 resv = spa_get_slop_space(dp->dp_spa);
729 849 if (netfree)
730 850 resv >>= 1;
731 851
|
↓ open down ↓ |
43 lines elided |
↑ open up ↑ |
732 852 return (space - resv);
733 853 }
734 854
735 855 boolean_t
736 856 dsl_pool_need_dirty_delay(dsl_pool_t *dp)
737 857 {
738 858 uint64_t delay_min_bytes =
739 859 zfs_dirty_data_max * zfs_delay_min_dirty_percent / 100;
740 860 boolean_t rv;
741 861
742 - mutex_enter(&dp->dp_lock);
743 862 if (dp->dp_dirty_total > zfs_dirty_data_sync)
744 863 txg_kick(dp);
745 864 rv = (dp->dp_dirty_total > delay_min_bytes);
746 - mutex_exit(&dp->dp_lock);
865 +
747 866 return (rv);
748 867 }
749 868
750 869 void
751 870 dsl_pool_dirty_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx)
752 871 {
753 872 if (space > 0) {
754 873 mutex_enter(&dp->dp_lock);
755 874 dp->dp_dirty_pertxg[tx->tx_txg & TXG_MASK] += space;
756 875 dsl_pool_dirty_delta(dp, space);
757 876 mutex_exit(&dp->dp_lock);
758 877 }
759 878 }
760 879
761 880 void
762 881 dsl_pool_undirty_space(dsl_pool_t *dp, int64_t space, uint64_t txg)
763 882 {
764 883 ASSERT3S(space, >=, 0);
765 884 if (space == 0)
766 885 return;
767 886 mutex_enter(&dp->dp_lock);
768 887 if (dp->dp_dirty_pertxg[txg & TXG_MASK] < space) {
769 888 /* XXX writing something we didn't dirty? */
770 889 space = dp->dp_dirty_pertxg[txg & TXG_MASK];
771 890 }
772 891 ASSERT3U(dp->dp_dirty_pertxg[txg & TXG_MASK], >=, space);
773 892 dp->dp_dirty_pertxg[txg & TXG_MASK] -= space;
774 893 ASSERT3U(dp->dp_dirty_total, >=, space);
775 894 dsl_pool_dirty_delta(dp, -space);
776 895 mutex_exit(&dp->dp_lock);
777 896 }
778 897
779 898 /* ARGSUSED */
780 899 static int
781 900 upgrade_clones_cb(dsl_pool_t *dp, dsl_dataset_t *hds, void *arg)
782 901 {
783 902 dmu_tx_t *tx = arg;
784 903 dsl_dataset_t *ds, *prev = NULL;
785 904 int err;
786 905
787 906 err = dsl_dataset_hold_obj(dp, hds->ds_object, FTAG, &ds);
788 907 if (err)
789 908 return (err);
790 909
791 910 while (dsl_dataset_phys(ds)->ds_prev_snap_obj != 0) {
792 911 err = dsl_dataset_hold_obj(dp,
793 912 dsl_dataset_phys(ds)->ds_prev_snap_obj, FTAG, &prev);
794 913 if (err) {
795 914 dsl_dataset_rele(ds, FTAG);
796 915 return (err);
797 916 }
798 917
799 918 if (dsl_dataset_phys(prev)->ds_next_snap_obj != ds->ds_object)
800 919 break;
801 920 dsl_dataset_rele(ds, FTAG);
802 921 ds = prev;
803 922 prev = NULL;
804 923 }
805 924
806 925 if (prev == NULL) {
807 926 prev = dp->dp_origin_snap;
808 927
809 928 /*
810 929 * The $ORIGIN can't have any data, or the accounting
811 930 * will be wrong.
812 931 */
813 932 rrw_enter(&ds->ds_bp_rwlock, RW_READER, FTAG);
814 933 ASSERT0(dsl_dataset_phys(prev)->ds_bp.blk_birth);
815 934 rrw_exit(&ds->ds_bp_rwlock, FTAG);
816 935
817 936 /* The origin doesn't get attached to itself */
818 937 if (ds->ds_object == prev->ds_object) {
819 938 dsl_dataset_rele(ds, FTAG);
820 939 return (0);
821 940 }
822 941
823 942 dmu_buf_will_dirty(ds->ds_dbuf, tx);
824 943 dsl_dataset_phys(ds)->ds_prev_snap_obj = prev->ds_object;
825 944 dsl_dataset_phys(ds)->ds_prev_snap_txg =
826 945 dsl_dataset_phys(prev)->ds_creation_txg;
827 946
828 947 dmu_buf_will_dirty(ds->ds_dir->dd_dbuf, tx);
829 948 dsl_dir_phys(ds->ds_dir)->dd_origin_obj = prev->ds_object;
830 949
831 950 dmu_buf_will_dirty(prev->ds_dbuf, tx);
832 951 dsl_dataset_phys(prev)->ds_num_children++;
833 952
834 953 if (dsl_dataset_phys(ds)->ds_next_snap_obj == 0) {
835 954 ASSERT(ds->ds_prev == NULL);
836 955 VERIFY0(dsl_dataset_hold_obj(dp,
837 956 dsl_dataset_phys(ds)->ds_prev_snap_obj,
838 957 ds, &ds->ds_prev));
839 958 }
840 959 }
841 960
842 961 ASSERT3U(dsl_dir_phys(ds->ds_dir)->dd_origin_obj, ==, prev->ds_object);
843 962 ASSERT3U(dsl_dataset_phys(ds)->ds_prev_snap_obj, ==, prev->ds_object);
844 963
845 964 if (dsl_dataset_phys(prev)->ds_next_clones_obj == 0) {
846 965 dmu_buf_will_dirty(prev->ds_dbuf, tx);
847 966 dsl_dataset_phys(prev)->ds_next_clones_obj =
848 967 zap_create(dp->dp_meta_objset,
849 968 DMU_OT_NEXT_CLONES, DMU_OT_NONE, 0, tx);
850 969 }
851 970 VERIFY0(zap_add_int(dp->dp_meta_objset,
852 971 dsl_dataset_phys(prev)->ds_next_clones_obj, ds->ds_object, tx));
853 972
854 973 dsl_dataset_rele(ds, FTAG);
855 974 if (prev != dp->dp_origin_snap)
856 975 dsl_dataset_rele(prev, FTAG);
857 976 return (0);
858 977 }
859 978
860 979 void
861 980 dsl_pool_upgrade_clones(dsl_pool_t *dp, dmu_tx_t *tx)
862 981 {
863 982 ASSERT(dmu_tx_is_syncing(tx));
864 983 ASSERT(dp->dp_origin_snap != NULL);
865 984
866 985 VERIFY0(dmu_objset_find_dp(dp, dp->dp_root_dir_obj, upgrade_clones_cb,
867 986 tx, DS_FIND_CHILDREN | DS_FIND_SERIALIZE));
868 987 }
869 988
870 989 /* ARGSUSED */
871 990 static int
872 991 upgrade_dir_clones_cb(dsl_pool_t *dp, dsl_dataset_t *ds, void *arg)
873 992 {
874 993 dmu_tx_t *tx = arg;
875 994 objset_t *mos = dp->dp_meta_objset;
876 995
877 996 if (dsl_dir_phys(ds->ds_dir)->dd_origin_obj != 0) {
878 997 dsl_dataset_t *origin;
879 998
880 999 VERIFY0(dsl_dataset_hold_obj(dp,
881 1000 dsl_dir_phys(ds->ds_dir)->dd_origin_obj, FTAG, &origin));
882 1001
883 1002 if (dsl_dir_phys(origin->ds_dir)->dd_clones == 0) {
884 1003 dmu_buf_will_dirty(origin->ds_dir->dd_dbuf, tx);
885 1004 dsl_dir_phys(origin->ds_dir)->dd_clones =
886 1005 zap_create(mos, DMU_OT_DSL_CLONES, DMU_OT_NONE,
887 1006 0, tx);
888 1007 }
889 1008
890 1009 VERIFY0(zap_add_int(dp->dp_meta_objset,
891 1010 dsl_dir_phys(origin->ds_dir)->dd_clones,
892 1011 ds->ds_object, tx));
893 1012
894 1013 dsl_dataset_rele(origin, FTAG);
895 1014 }
896 1015 return (0);
897 1016 }
898 1017
899 1018 void
900 1019 dsl_pool_upgrade_dir_clones(dsl_pool_t *dp, dmu_tx_t *tx)
901 1020 {
902 1021 ASSERT(dmu_tx_is_syncing(tx));
903 1022 uint64_t obj;
904 1023
905 1024 (void) dsl_dir_create_sync(dp, dp->dp_root_dir, FREE_DIR_NAME, tx);
906 1025 VERIFY0(dsl_pool_open_special_dir(dp,
907 1026 FREE_DIR_NAME, &dp->dp_free_dir));
908 1027
909 1028 /*
910 1029 * We can't use bpobj_alloc(), because spa_version() still
911 1030 * returns the old version, and we need a new-version bpobj with
912 1031 * subobj support. So call dmu_object_alloc() directly.
913 1032 */
914 1033 obj = dmu_object_alloc(dp->dp_meta_objset, DMU_OT_BPOBJ,
915 1034 SPA_OLD_MAXBLOCKSIZE, DMU_OT_BPOBJ_HDR, sizeof (bpobj_phys_t), tx);
916 1035 VERIFY0(zap_add(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
917 1036 DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj, tx));
918 1037 VERIFY0(bpobj_open(&dp->dp_free_bpobj, dp->dp_meta_objset, obj));
919 1038
920 1039 VERIFY0(dmu_objset_find_dp(dp, dp->dp_root_dir_obj,
921 1040 upgrade_dir_clones_cb, tx, DS_FIND_CHILDREN | DS_FIND_SERIALIZE));
922 1041 }
923 1042
924 1043 void
925 1044 dsl_pool_create_origin(dsl_pool_t *dp, dmu_tx_t *tx)
926 1045 {
927 1046 uint64_t dsobj;
928 1047 dsl_dataset_t *ds;
929 1048
930 1049 ASSERT(dmu_tx_is_syncing(tx));
931 1050 ASSERT(dp->dp_origin_snap == NULL);
932 1051 ASSERT(rrw_held(&dp->dp_config_rwlock, RW_WRITER));
933 1052
934 1053 /* create the origin dir, ds, & snap-ds */
935 1054 dsobj = dsl_dataset_create_sync(dp->dp_root_dir, ORIGIN_DIR_NAME,
936 1055 NULL, 0, kcred, tx);
937 1056 VERIFY0(dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds));
938 1057 dsl_dataset_snapshot_sync_impl(ds, ORIGIN_DIR_NAME, tx);
939 1058 VERIFY0(dsl_dataset_hold_obj(dp, dsl_dataset_phys(ds)->ds_prev_snap_obj,
940 1059 dp, &dp->dp_origin_snap));
941 1060 dsl_dataset_rele(ds, FTAG);
942 1061 }
943 1062
944 1063 taskq_t *
945 1064 dsl_pool_vnrele_taskq(dsl_pool_t *dp)
946 1065 {
947 1066 return (dp->dp_vnrele_taskq);
948 1067 }
949 1068
950 1069 /*
951 1070 * Walk through the pool-wide zap object of temporary snapshot user holds
952 1071 * and release them.
953 1072 */
954 1073 void
955 1074 dsl_pool_clean_tmp_userrefs(dsl_pool_t *dp)
956 1075 {
957 1076 zap_attribute_t za;
958 1077 zap_cursor_t zc;
959 1078 objset_t *mos = dp->dp_meta_objset;
960 1079 uint64_t zapobj = dp->dp_tmp_userrefs_obj;
961 1080 nvlist_t *holds;
962 1081
963 1082 if (zapobj == 0)
964 1083 return;
965 1084 ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS);
966 1085
967 1086 holds = fnvlist_alloc();
968 1087
969 1088 for (zap_cursor_init(&zc, mos, zapobj);
970 1089 zap_cursor_retrieve(&zc, &za) == 0;
971 1090 zap_cursor_advance(&zc)) {
972 1091 char *htag;
973 1092 nvlist_t *tags;
974 1093
975 1094 htag = strchr(za.za_name, '-');
976 1095 *htag = '\0';
977 1096 ++htag;
978 1097 if (nvlist_lookup_nvlist(holds, za.za_name, &tags) != 0) {
979 1098 tags = fnvlist_alloc();
980 1099 fnvlist_add_boolean(tags, htag);
981 1100 fnvlist_add_nvlist(holds, za.za_name, tags);
982 1101 fnvlist_free(tags);
983 1102 } else {
984 1103 fnvlist_add_boolean(tags, htag);
985 1104 }
986 1105 }
987 1106 dsl_dataset_user_release_tmp(dp, holds);
988 1107 fnvlist_free(holds);
989 1108 zap_cursor_fini(&zc);
990 1109 }
991 1110
992 1111 /*
993 1112 * Create the pool-wide zap object for storing temporary snapshot holds.
994 1113 */
995 1114 void
996 1115 dsl_pool_user_hold_create_obj(dsl_pool_t *dp, dmu_tx_t *tx)
997 1116 {
998 1117 objset_t *mos = dp->dp_meta_objset;
999 1118
1000 1119 ASSERT(dp->dp_tmp_userrefs_obj == 0);
1001 1120 ASSERT(dmu_tx_is_syncing(tx));
1002 1121
1003 1122 dp->dp_tmp_userrefs_obj = zap_create_link(mos, DMU_OT_USERREFS,
1004 1123 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_TMP_USERREFS, tx);
1005 1124 }
1006 1125
1007 1126 static int
1008 1127 dsl_pool_user_hold_rele_impl(dsl_pool_t *dp, uint64_t dsobj,
1009 1128 const char *tag, uint64_t now, dmu_tx_t *tx, boolean_t holding)
1010 1129 {
1011 1130 objset_t *mos = dp->dp_meta_objset;
1012 1131 uint64_t zapobj = dp->dp_tmp_userrefs_obj;
1013 1132 char *name;
1014 1133 int error;
1015 1134
1016 1135 ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS);
1017 1136 ASSERT(dmu_tx_is_syncing(tx));
1018 1137
1019 1138 /*
1020 1139 * If the pool was created prior to SPA_VERSION_USERREFS, the
1021 1140 * zap object for temporary holds might not exist yet.
1022 1141 */
1023 1142 if (zapobj == 0) {
1024 1143 if (holding) {
1025 1144 dsl_pool_user_hold_create_obj(dp, tx);
1026 1145 zapobj = dp->dp_tmp_userrefs_obj;
1027 1146 } else {
1028 1147 return (SET_ERROR(ENOENT));
1029 1148 }
1030 1149 }
1031 1150
1032 1151 name = kmem_asprintf("%llx-%s", (u_longlong_t)dsobj, tag);
1033 1152 if (holding)
1034 1153 error = zap_add(mos, zapobj, name, 8, 1, &now, tx);
1035 1154 else
1036 1155 error = zap_remove(mos, zapobj, name, tx);
1037 1156 strfree(name);
1038 1157
1039 1158 return (error);
1040 1159 }
1041 1160
1042 1161 /*
1043 1162 * Add a temporary hold for the given dataset object and tag.
1044 1163 */
1045 1164 int
1046 1165 dsl_pool_user_hold(dsl_pool_t *dp, uint64_t dsobj, const char *tag,
1047 1166 uint64_t now, dmu_tx_t *tx)
1048 1167 {
1049 1168 return (dsl_pool_user_hold_rele_impl(dp, dsobj, tag, now, tx, B_TRUE));
1050 1169 }
1051 1170
1052 1171 /*
1053 1172 * Release a temporary hold for the given dataset object and tag.
1054 1173 */
1055 1174 int
1056 1175 dsl_pool_user_release(dsl_pool_t *dp, uint64_t dsobj, const char *tag,
1057 1176 dmu_tx_t *tx)
1058 1177 {
1059 1178 return (dsl_pool_user_hold_rele_impl(dp, dsobj, tag, NULL,
1060 1179 tx, B_FALSE));
1061 1180 }
1062 1181
1063 1182 /*
1064 1183 * DSL Pool Configuration Lock
1065 1184 *
1066 1185 * The dp_config_rwlock protects against changes to DSL state (e.g. dataset
1067 1186 * creation / destruction / rename / property setting). It must be held for
1068 1187 * read to hold a dataset or dsl_dir. I.e. you must call
1069 1188 * dsl_pool_config_enter() or dsl_pool_hold() before calling
1070 1189 * dsl_{dataset,dir}_hold{_obj}. In most circumstances, the dp_config_rwlock
1071 1190 * must be held continuously until all datasets and dsl_dirs are released.
1072 1191 *
1073 1192 * The only exception to this rule is that if a "long hold" is placed on
1074 1193 * a dataset, then the dp_config_rwlock may be dropped while the dataset
1075 1194 * is still held. The long hold will prevent the dataset from being
1076 1195 * destroyed -- the destroy will fail with EBUSY. A long hold can be
1077 1196 * obtained by calling dsl_dataset_long_hold(), or by "owning" a dataset
1078 1197 * (by calling dsl_{dataset,objset}_{try}own{_obj}).
1079 1198 *
1080 1199 * Legitimate long-holders (including owners) should be long-running, cancelable
1081 1200 * tasks that should cause "zfs destroy" to fail. This includes DMU
1082 1201 * consumers (i.e. a ZPL filesystem being mounted or ZVOL being open),
1083 1202 * "zfs send", and "zfs diff". There are several other long-holders whose
1084 1203 * uses are suboptimal (e.g. "zfs promote", and zil_suspend()).
1085 1204 *
1086 1205 * The usual formula for long-holding would be:
1087 1206 * dsl_pool_hold()
1088 1207 * dsl_dataset_hold()
1089 1208 * ... perform checks ...
1090 1209 * dsl_dataset_long_hold()
1091 1210 * dsl_pool_rele()
1092 1211 * ... perform long-running task ...
1093 1212 * dsl_dataset_long_rele()
1094 1213 * dsl_dataset_rele()
1095 1214 *
1096 1215 * Note that when the long hold is released, the dataset is still held but
1097 1216 * the pool is not held. The dataset may change arbitrarily during this time
1098 1217 * (e.g. it could be destroyed). Therefore you shouldn't do anything to the
1099 1218 * dataset except release it.
1100 1219 *
1101 1220 * User-initiated operations (e.g. ioctls, zfs_ioc_*()) are either read-only
1102 1221 * or modifying operations.
1103 1222 *
1104 1223 * Modifying operations should generally use dsl_sync_task(). The synctask
1105 1224 * infrastructure enforces proper locking strategy with respect to the
1106 1225 * dp_config_rwlock. See the comment above dsl_sync_task() for details.
1107 1226 *
1108 1227 * Read-only operations will manually hold the pool, then the dataset, obtain
1109 1228 * information from the dataset, then release the pool and dataset.
1110 1229 * dmu_objset_{hold,rele}() are convenience routines that also do the pool
1111 1230 * hold/rele.
1112 1231 */
1113 1232
1114 1233 int
1115 1234 dsl_pool_hold(const char *name, void *tag, dsl_pool_t **dp)
1116 1235 {
1117 1236 spa_t *spa;
1118 1237 int error;
1119 1238
1120 1239 error = spa_open(name, &spa, tag);
1121 1240 if (error == 0) {
1122 1241 *dp = spa_get_dsl(spa);
1123 1242 dsl_pool_config_enter(*dp, tag);
1124 1243 }
1125 1244 return (error);
1126 1245 }
1127 1246
1128 1247 void
1129 1248 dsl_pool_rele(dsl_pool_t *dp, void *tag)
1130 1249 {
1131 1250 dsl_pool_config_exit(dp, tag);
1132 1251 spa_close(dp->dp_spa, tag);
1133 1252 }
1134 1253
1135 1254 void
1136 1255 dsl_pool_config_enter(dsl_pool_t *dp, void *tag)
1137 1256 {
1138 1257 /*
1139 1258 * We use a "reentrant" reader-writer lock, but not reentrantly.
1140 1259 *
1141 1260 * The rrwlock can (with the track_all flag) track all reading threads,
1142 1261 * which is very useful for debugging which code path failed to release
1143 1262 * the lock, and for verifying that the *current* thread does hold
1144 1263 * the lock.
1145 1264 *
1146 1265 * (Unlike a rwlock, which knows that N threads hold it for
1147 1266 * read, but not *which* threads, so rw_held(RW_READER) returns TRUE
1148 1267 * if any thread holds it for read, even if this thread doesn't).
1149 1268 */
1150 1269 ASSERT(!rrw_held(&dp->dp_config_rwlock, RW_READER));
1151 1270 rrw_enter(&dp->dp_config_rwlock, RW_READER, tag);
1152 1271 }
1153 1272
1154 1273 void
1155 1274 dsl_pool_config_enter_prio(dsl_pool_t *dp, void *tag)
1156 1275 {
1157 1276 ASSERT(!rrw_held(&dp->dp_config_rwlock, RW_READER));
1158 1277 rrw_enter_read_prio(&dp->dp_config_rwlock, tag);
1159 1278 }
1160 1279
1161 1280 void
1162 1281 dsl_pool_config_exit(dsl_pool_t *dp, void *tag)
1163 1282 {
1164 1283 rrw_exit(&dp->dp_config_rwlock, tag);
1165 1284 }
1166 1285
1167 1286 boolean_t
1168 1287 dsl_pool_config_held(dsl_pool_t *dp)
1169 1288 {
1170 1289 return (RRW_LOCK_HELD(&dp->dp_config_rwlock));
1171 1290 }
1172 1291
1173 1292 boolean_t
1174 1293 dsl_pool_config_held_writer(dsl_pool_t *dp)
1175 1294 {
1176 1295 return (RRW_WRITE_HELD(&dp->dp_config_rwlock));
1177 1296 }
|
↓ open down ↓ |
421 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX