Print this page
2619 asynchronous destruction of ZFS file systems
2747 SPA versioning with zfs feature flags
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <gwilson@delphix.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Reviewed by: Dan Kruchinin <dan.kruchinin@gmail.com>
Approved by: Dan McDonald <danmcd@nexenta.com>
| 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 *
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 - * Copyright (c) 2011 by Delphix. All rights reserved.
23 + * Copyright (c) 2012 by Delphix. All rights reserved.
24 24 */
25 25
26 26 #include <sys/dsl_pool.h>
27 27 #include <sys/dsl_dataset.h>
28 28 #include <sys/dsl_prop.h>
29 29 #include <sys/dsl_dir.h>
30 30 #include <sys/dsl_synctask.h>
31 31 #include <sys/dsl_scan.h>
32 32 #include <sys/dnode.h>
33 33 #include <sys/dmu_tx.h>
34 34 #include <sys/dmu_objset.h>
35 35 #include <sys/arc.h>
36 36 #include <sys/zap.h>
37 37 #include <sys/zio.h>
38 38 #include <sys/zfs_context.h>
39 39 #include <sys/fs/zfs.h>
40 40 #include <sys/zfs_znode.h>
41 41 #include <sys/spa_impl.h>
42 42 #include <sys/dsl_deadlist.h>
43 +#include <sys/bptree.h>
44 +#include <sys/zfeature.h>
43 45
44 46 int zfs_no_write_throttle = 0;
45 47 int zfs_write_limit_shift = 3; /* 1/8th of physical memory */
46 48 int zfs_txg_synctime_ms = 1000; /* target millisecs to sync a txg */
47 49
48 50 uint64_t zfs_write_limit_min = 32 << 20; /* min write limit is 32MB */
49 51 uint64_t zfs_write_limit_max = 0; /* max data payload per txg */
50 52 uint64_t zfs_write_limit_inflated = 0;
51 53 uint64_t zfs_write_limit_override = 0;
52 54
53 55 kmutex_t zfs_write_limit_lock;
54 56
55 57 static pgcnt_t old_physmem = 0;
56 58
57 59 int
58 60 dsl_pool_open_special_dir(dsl_pool_t *dp, const char *name, dsl_dir_t **ddp)
59 61 {
60 62 uint64_t obj;
61 63 int err;
62 64
63 65 err = zap_lookup(dp->dp_meta_objset,
64 66 dp->dp_root_dir->dd_phys->dd_child_dir_zapobj,
65 67 name, sizeof (obj), 1, &obj);
66 68 if (err)
67 69 return (err);
68 70
69 71 return (dsl_dir_open_obj(dp, obj, name, dp, ddp));
70 72 }
71 73
72 74 static dsl_pool_t *
73 75 dsl_pool_open_impl(spa_t *spa, uint64_t txg)
74 76 {
75 77 dsl_pool_t *dp;
76 78 blkptr_t *bp = spa_get_rootblkptr(spa);
77 79
78 80 dp = kmem_zalloc(sizeof (dsl_pool_t), KM_SLEEP);
79 81 dp->dp_spa = spa;
80 82 dp->dp_meta_rootbp = *bp;
81 83 rw_init(&dp->dp_config_rwlock, NULL, RW_DEFAULT, NULL);
82 84 dp->dp_write_limit = zfs_write_limit_min;
83 85 txg_init(dp, txg);
84 86
85 87 txg_list_create(&dp->dp_dirty_datasets,
86 88 offsetof(dsl_dataset_t, ds_dirty_link));
87 89 txg_list_create(&dp->dp_dirty_dirs,
88 90 offsetof(dsl_dir_t, dd_dirty_link));
89 91 txg_list_create(&dp->dp_sync_tasks,
90 92 offsetof(dsl_sync_task_group_t, dstg_node));
91 93 list_create(&dp->dp_synced_datasets, sizeof (dsl_dataset_t),
92 94 offsetof(dsl_dataset_t, ds_synced_link));
|
↓ open down ↓ |
40 lines elided |
↑ open up ↑ |
93 95
94 96 mutex_init(&dp->dp_lock, NULL, MUTEX_DEFAULT, NULL);
95 97
96 98 dp->dp_vnrele_taskq = taskq_create("zfs_vn_rele_taskq", 1, minclsyspri,
97 99 1, 4, 0);
98 100
99 101 return (dp);
100 102 }
101 103
102 104 int
103 -dsl_pool_open(spa_t *spa, uint64_t txg, dsl_pool_t **dpp)
105 +dsl_pool_init(spa_t *spa, uint64_t txg, dsl_pool_t **dpp)
104 106 {
105 107 int err;
106 108 dsl_pool_t *dp = dsl_pool_open_impl(spa, txg);
109 +
110 + err = dmu_objset_open_impl(spa, NULL, &dp->dp_meta_rootbp,
111 + &dp->dp_meta_objset);
112 + if (err != 0)
113 + dsl_pool_close(dp);
114 + else
115 + *dpp = dp;
116 +
117 + return (err);
118 +}
119 +
120 +int
121 +dsl_pool_open(dsl_pool_t *dp)
122 +{
123 + int err;
107 124 dsl_dir_t *dd;
108 125 dsl_dataset_t *ds;
109 126 uint64_t obj;
110 127
111 - rw_enter(&dp->dp_config_rwlock, RW_WRITER);
112 - err = dmu_objset_open_impl(spa, NULL, &dp->dp_meta_rootbp,
113 - &dp->dp_meta_objset);
114 - if (err)
115 - goto out;
128 + ASSERT(!dmu_objset_is_dirty_anywhere(dp->dp_meta_objset));
116 129
130 + rw_enter(&dp->dp_config_rwlock, RW_WRITER);
117 131 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
118 132 DMU_POOL_ROOT_DATASET, sizeof (uint64_t), 1,
119 133 &dp->dp_root_dir_obj);
120 134 if (err)
121 135 goto out;
122 136
123 137 err = dsl_dir_open_obj(dp, dp->dp_root_dir_obj,
124 138 NULL, dp, &dp->dp_root_dir);
125 139 if (err)
126 140 goto out;
127 141
128 142 err = dsl_pool_open_special_dir(dp, MOS_DIR_NAME, &dp->dp_mos_dir);
129 143 if (err)
130 144 goto out;
131 145
132 - if (spa_version(spa) >= SPA_VERSION_ORIGIN) {
146 + if (spa_version(dp->dp_spa) >= SPA_VERSION_ORIGIN) {
133 147 err = dsl_pool_open_special_dir(dp, ORIGIN_DIR_NAME, &dd);
134 148 if (err)
135 149 goto out;
136 150 err = dsl_dataset_hold_obj(dp, dd->dd_phys->dd_head_dataset_obj,
137 151 FTAG, &ds);
138 152 if (err == 0) {
139 153 err = dsl_dataset_hold_obj(dp,
140 154 ds->ds_phys->ds_prev_snap_obj, dp,
141 155 &dp->dp_origin_snap);
142 156 dsl_dataset_rele(ds, FTAG);
143 157 }
144 158 dsl_dir_close(dd, dp);
145 159 if (err)
146 160 goto out;
147 161 }
148 162
149 - if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
163 + if (spa_version(dp->dp_spa) >= SPA_VERSION_DEADLISTS) {
150 164 err = dsl_pool_open_special_dir(dp, FREE_DIR_NAME,
151 165 &dp->dp_free_dir);
152 166 if (err)
153 167 goto out;
154 168
155 169 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
156 170 DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj);
157 171 if (err)
158 172 goto out;
159 173 VERIFY3U(0, ==, bpobj_open(&dp->dp_free_bpobj,
160 174 dp->dp_meta_objset, obj));
161 175 }
162 176
177 + if (spa_feature_is_active(dp->dp_spa,
178 + &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
179 + err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
180 + DMU_POOL_BPTREE_OBJ, sizeof (uint64_t), 1,
181 + &dp->dp_bptree_obj);
182 + if (err != 0)
183 + goto out;
184 + }
185 +
163 186 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
164 187 DMU_POOL_TMP_USERREFS, sizeof (uint64_t), 1,
165 188 &dp->dp_tmp_userrefs_obj);
166 189 if (err == ENOENT)
167 190 err = 0;
168 191 if (err)
169 192 goto out;
170 193
171 - err = dsl_scan_init(dp, txg);
194 + err = dsl_scan_init(dp, dp->dp_tx.tx_open_txg);
172 195
173 196 out:
174 197 rw_exit(&dp->dp_config_rwlock);
175 - if (err)
176 - dsl_pool_close(dp);
177 - else
178 - *dpp = dp;
179 -
180 198 return (err);
181 199 }
182 200
183 201 void
184 202 dsl_pool_close(dsl_pool_t *dp)
185 203 {
186 204 /* drop our references from dsl_pool_open() */
187 205
188 206 /*
189 207 * Since we held the origin_snap from "syncing" context (which
190 208 * includes pool-opening context), it actually only got a "ref"
191 209 * and not a hold, so just drop that here.
192 210 */
193 211 if (dp->dp_origin_snap)
194 212 dsl_dataset_drop_ref(dp->dp_origin_snap, dp);
195 213 if (dp->dp_mos_dir)
196 214 dsl_dir_close(dp->dp_mos_dir, dp);
197 215 if (dp->dp_free_dir)
198 216 dsl_dir_close(dp->dp_free_dir, dp);
199 217 if (dp->dp_root_dir)
200 218 dsl_dir_close(dp->dp_root_dir, dp);
201 219
202 220 bpobj_close(&dp->dp_free_bpobj);
203 221
204 222 /* undo the dmu_objset_open_impl(mos) from dsl_pool_open() */
205 223 if (dp->dp_meta_objset)
206 224 dmu_objset_evict(dp->dp_meta_objset);
207 225
208 226 txg_list_destroy(&dp->dp_dirty_datasets);
209 227 txg_list_destroy(&dp->dp_sync_tasks);
210 228 txg_list_destroy(&dp->dp_dirty_dirs);
211 229 list_destroy(&dp->dp_synced_datasets);
212 230
213 231 arc_flush(dp->dp_spa);
214 232 txg_fini(dp);
215 233 dsl_scan_fini(dp);
216 234 rw_destroy(&dp->dp_config_rwlock);
217 235 mutex_destroy(&dp->dp_lock);
218 236 taskq_destroy(dp->dp_vnrele_taskq);
219 237 if (dp->dp_blkstats)
220 238 kmem_free(dp->dp_blkstats, sizeof (zfs_all_blkstats_t));
221 239 kmem_free(dp, sizeof (dsl_pool_t));
222 240 }
223 241
224 242 dsl_pool_t *
225 243 dsl_pool_create(spa_t *spa, nvlist_t *zplprops, uint64_t txg)
226 244 {
227 245 int err;
228 246 dsl_pool_t *dp = dsl_pool_open_impl(spa, txg);
229 247 dmu_tx_t *tx = dmu_tx_create_assigned(dp, txg);
230 248 objset_t *os;
231 249 dsl_dataset_t *ds;
232 250 uint64_t obj;
233 251
234 252 /* create and open the MOS (meta-objset) */
235 253 dp->dp_meta_objset = dmu_objset_create_impl(spa,
236 254 NULL, &dp->dp_meta_rootbp, DMU_OST_META, tx);
237 255
238 256 /* create the pool directory */
239 257 err = zap_create_claim(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
240 258 DMU_OT_OBJECT_DIRECTORY, DMU_OT_NONE, 0, tx);
241 259 ASSERT3U(err, ==, 0);
242 260
243 261 /* Initialize scan structures */
244 262 VERIFY3U(0, ==, dsl_scan_init(dp, txg));
245 263
246 264 /* create and open the root dir */
247 265 dp->dp_root_dir_obj = dsl_dir_create_sync(dp, NULL, NULL, tx);
248 266 VERIFY(0 == dsl_dir_open_obj(dp, dp->dp_root_dir_obj,
249 267 NULL, dp, &dp->dp_root_dir));
250 268
251 269 /* create and open the meta-objset dir */
252 270 (void) dsl_dir_create_sync(dp, dp->dp_root_dir, MOS_DIR_NAME, tx);
253 271 VERIFY(0 == dsl_pool_open_special_dir(dp,
254 272 MOS_DIR_NAME, &dp->dp_mos_dir));
255 273
256 274 if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
257 275 /* create and open the free dir */
258 276 (void) dsl_dir_create_sync(dp, dp->dp_root_dir,
259 277 FREE_DIR_NAME, tx);
260 278 VERIFY(0 == dsl_pool_open_special_dir(dp,
261 279 FREE_DIR_NAME, &dp->dp_free_dir));
262 280
263 281 /* create and open the free_bplist */
264 282 obj = bpobj_alloc(dp->dp_meta_objset, SPA_MAXBLOCKSIZE, tx);
265 283 VERIFY(zap_add(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
266 284 DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj, tx) == 0);
267 285 VERIFY3U(0, ==, bpobj_open(&dp->dp_free_bpobj,
268 286 dp->dp_meta_objset, obj));
269 287 }
270 288
271 289 if (spa_version(spa) >= SPA_VERSION_DSL_SCRUB)
272 290 dsl_pool_create_origin(dp, tx);
273 291
274 292 /* create the root dataset */
275 293 obj = dsl_dataset_create_sync_dd(dp->dp_root_dir, NULL, 0, tx);
276 294
277 295 /* create the root objset */
278 296 VERIFY(0 == dsl_dataset_hold_obj(dp, obj, FTAG, &ds));
279 297 os = dmu_objset_create_impl(dp->dp_spa, ds,
280 298 dsl_dataset_get_blkptr(ds), DMU_OST_ZFS, tx);
281 299 #ifdef _KERNEL
282 300 zfs_create_fs(os, kcred, zplprops, tx);
283 301 #endif
284 302 dsl_dataset_rele(ds, FTAG);
285 303
286 304 dmu_tx_commit(tx);
287 305
288 306 return (dp);
289 307 }
290 308
291 309 static int
292 310 deadlist_enqueue_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
293 311 {
294 312 dsl_deadlist_t *dl = arg;
295 313 dsl_pool_t *dp = dmu_objset_pool(dl->dl_os);
296 314 rw_enter(&dp->dp_config_rwlock, RW_READER);
297 315 dsl_deadlist_insert(dl, bp, tx);
298 316 rw_exit(&dp->dp_config_rwlock);
299 317 return (0);
300 318 }
301 319
302 320 void
303 321 dsl_pool_sync(dsl_pool_t *dp, uint64_t txg)
304 322 {
305 323 zio_t *zio;
306 324 dmu_tx_t *tx;
307 325 dsl_dir_t *dd;
308 326 dsl_dataset_t *ds;
309 327 dsl_sync_task_group_t *dstg;
310 328 objset_t *mos = dp->dp_meta_objset;
311 329 hrtime_t start, write_time;
312 330 uint64_t data_written;
313 331 int err;
314 332
315 333 /*
316 334 * We need to copy dp_space_towrite() before doing
317 335 * dsl_sync_task_group_sync(), because
318 336 * dsl_dataset_snapshot_reserve_space() will increase
319 337 * dp_space_towrite but not actually write anything.
320 338 */
321 339 data_written = dp->dp_space_towrite[txg & TXG_MASK];
322 340
323 341 tx = dmu_tx_create_assigned(dp, txg);
324 342
325 343 dp->dp_read_overhead = 0;
326 344 start = gethrtime();
327 345
328 346 zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
329 347 while (ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) {
330 348 /*
331 349 * We must not sync any non-MOS datasets twice, because
332 350 * we may have taken a snapshot of them. However, we
333 351 * may sync newly-created datasets on pass 2.
334 352 */
335 353 ASSERT(!list_link_active(&ds->ds_synced_link));
336 354 list_insert_tail(&dp->dp_synced_datasets, ds);
337 355 dsl_dataset_sync(ds, zio, tx);
338 356 }
339 357 DTRACE_PROBE(pool_sync__1setup);
340 358 err = zio_wait(zio);
341 359
342 360 write_time = gethrtime() - start;
343 361 ASSERT(err == 0);
344 362 DTRACE_PROBE(pool_sync__2rootzio);
345 363
346 364 for (ds = list_head(&dp->dp_synced_datasets); ds;
347 365 ds = list_next(&dp->dp_synced_datasets, ds))
348 366 dmu_objset_do_userquota_updates(ds->ds_objset, tx);
349 367
350 368 /*
351 369 * Sync the datasets again to push out the changes due to
352 370 * userspace updates. This must be done before we process the
353 371 * sync tasks, because that could cause a snapshot of a dataset
354 372 * whose ds_bp will be rewritten when we do this 2nd sync.
355 373 */
356 374 zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
357 375 while (ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) {
358 376 ASSERT(list_link_active(&ds->ds_synced_link));
359 377 dmu_buf_rele(ds->ds_dbuf, ds);
360 378 dsl_dataset_sync(ds, zio, tx);
361 379 }
362 380 err = zio_wait(zio);
363 381
364 382 /*
365 383 * Move dead blocks from the pending deadlist to the on-disk
366 384 * deadlist.
367 385 */
368 386 for (ds = list_head(&dp->dp_synced_datasets); ds;
369 387 ds = list_next(&dp->dp_synced_datasets, ds)) {
370 388 bplist_iterate(&ds->ds_pending_deadlist,
371 389 deadlist_enqueue_cb, &ds->ds_deadlist, tx);
372 390 }
373 391
374 392 while (dstg = txg_list_remove(&dp->dp_sync_tasks, txg)) {
375 393 /*
376 394 * No more sync tasks should have been added while we
377 395 * were syncing.
378 396 */
379 397 ASSERT(spa_sync_pass(dp->dp_spa) == 1);
380 398 dsl_sync_task_group_sync(dstg, tx);
381 399 }
382 400 DTRACE_PROBE(pool_sync__3task);
383 401
384 402 start = gethrtime();
385 403 while (dd = txg_list_remove(&dp->dp_dirty_dirs, txg))
386 404 dsl_dir_sync(dd, tx);
387 405 write_time += gethrtime() - start;
388 406
389 407 start = gethrtime();
390 408 if (list_head(&mos->os_dirty_dnodes[txg & TXG_MASK]) != NULL ||
391 409 list_head(&mos->os_free_dnodes[txg & TXG_MASK]) != NULL) {
392 410 zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
393 411 dmu_objset_sync(mos, zio, tx);
394 412 err = zio_wait(zio);
395 413 ASSERT(err == 0);
396 414 dprintf_bp(&dp->dp_meta_rootbp, "meta objset rootbp is %s", "");
397 415 spa_set_rootblkptr(dp->dp_spa, &dp->dp_meta_rootbp);
398 416 }
399 417 write_time += gethrtime() - start;
400 418 DTRACE_PROBE2(pool_sync__4io, hrtime_t, write_time,
401 419 hrtime_t, dp->dp_read_overhead);
402 420 write_time -= dp->dp_read_overhead;
403 421
404 422 dmu_tx_commit(tx);
405 423
406 424 dp->dp_space_towrite[txg & TXG_MASK] = 0;
407 425 ASSERT(dp->dp_tempreserved[txg & TXG_MASK] == 0);
408 426
409 427 /*
410 428 * If the write limit max has not been explicitly set, set it
411 429 * to a fraction of available physical memory (default 1/8th).
412 430 * Note that we must inflate the limit because the spa
413 431 * inflates write sizes to account for data replication.
414 432 * Check this each sync phase to catch changing memory size.
415 433 */
416 434 if (physmem != old_physmem && zfs_write_limit_shift) {
417 435 mutex_enter(&zfs_write_limit_lock);
418 436 old_physmem = physmem;
419 437 zfs_write_limit_max = ptob(physmem) >> zfs_write_limit_shift;
420 438 zfs_write_limit_inflated = MAX(zfs_write_limit_min,
421 439 spa_get_asize(dp->dp_spa, zfs_write_limit_max));
422 440 mutex_exit(&zfs_write_limit_lock);
423 441 }
424 442
425 443 /*
426 444 * Attempt to keep the sync time consistent by adjusting the
427 445 * amount of write traffic allowed into each transaction group.
428 446 * Weight the throughput calculation towards the current value:
429 447 * thru = 3/4 old_thru + 1/4 new_thru
430 448 *
431 449 * Note: write_time is in nanosecs, so write_time/MICROSEC
432 450 * yields millisecs
433 451 */
434 452 ASSERT(zfs_write_limit_min > 0);
435 453 if (data_written > zfs_write_limit_min / 8 && write_time > MICROSEC) {
436 454 uint64_t throughput = data_written / (write_time / MICROSEC);
437 455
438 456 if (dp->dp_throughput)
439 457 dp->dp_throughput = throughput / 4 +
440 458 3 * dp->dp_throughput / 4;
441 459 else
442 460 dp->dp_throughput = throughput;
443 461 dp->dp_write_limit = MIN(zfs_write_limit_inflated,
444 462 MAX(zfs_write_limit_min,
445 463 dp->dp_throughput * zfs_txg_synctime_ms));
446 464 }
447 465 }
448 466
449 467 void
450 468 dsl_pool_sync_done(dsl_pool_t *dp, uint64_t txg)
451 469 {
452 470 dsl_dataset_t *ds;
453 471 objset_t *os;
454 472
455 473 while (ds = list_head(&dp->dp_synced_datasets)) {
456 474 list_remove(&dp->dp_synced_datasets, ds);
457 475 os = ds->ds_objset;
458 476 zil_clean(os->os_zil, txg);
459 477 ASSERT(!dmu_objset_is_dirty(os, txg));
460 478 dmu_buf_rele(ds->ds_dbuf, ds);
461 479 }
462 480 ASSERT(!dmu_objset_is_dirty(dp->dp_meta_objset, txg));
|
↓ open down ↓ |
273 lines elided |
↑ open up ↑ |
463 481 }
464 482
465 483 /*
466 484 * TRUE if the current thread is the tx_sync_thread or if we
467 485 * are being called from SPA context during pool initialization.
468 486 */
469 487 int
470 488 dsl_pool_sync_context(dsl_pool_t *dp)
471 489 {
472 490 return (curthread == dp->dp_tx.tx_sync_thread ||
473 - spa_get_dsl(dp->dp_spa) == NULL);
491 + spa_is_initializing(dp->dp_spa));
474 492 }
475 493
476 494 uint64_t
477 495 dsl_pool_adjustedsize(dsl_pool_t *dp, boolean_t netfree)
478 496 {
479 497 uint64_t space, resv;
480 498
481 499 /*
482 500 * Reserve about 1.6% (1/64), or at least 32MB, for allocation
483 501 * efficiency.
484 502 * XXX The intent log is not accounted for, so it must fit
485 503 * within this slop.
486 504 *
487 505 * If we're trying to assess whether it's OK to do a free,
488 506 * cut the reservation in half to allow forward progress
489 507 * (e.g. make it possible to rm(1) files from a full pool).
490 508 */
491 509 space = spa_get_dspace(dp->dp_spa);
492 510 resv = MAX(space >> 6, SPA_MINDEVSIZE >> 1);
493 511 if (netfree)
494 512 resv >>= 1;
495 513
496 514 return (space - resv);
497 515 }
498 516
499 517 int
500 518 dsl_pool_tempreserve_space(dsl_pool_t *dp, uint64_t space, dmu_tx_t *tx)
501 519 {
502 520 uint64_t reserved = 0;
503 521 uint64_t write_limit = (zfs_write_limit_override ?
504 522 zfs_write_limit_override : dp->dp_write_limit);
505 523
506 524 if (zfs_no_write_throttle) {
507 525 atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK],
508 526 space);
509 527 return (0);
510 528 }
511 529
512 530 /*
513 531 * Check to see if we have exceeded the maximum allowed IO for
514 532 * this transaction group. We can do this without locks since
515 533 * a little slop here is ok. Note that we do the reserved check
516 534 * with only half the requested reserve: this is because the
517 535 * reserve requests are worst-case, and we really don't want to
518 536 * throttle based off of worst-case estimates.
519 537 */
520 538 if (write_limit > 0) {
521 539 reserved = dp->dp_space_towrite[tx->tx_txg & TXG_MASK]
522 540 + dp->dp_tempreserved[tx->tx_txg & TXG_MASK] / 2;
523 541
524 542 if (reserved && reserved > write_limit)
525 543 return (ERESTART);
526 544 }
527 545
528 546 atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK], space);
529 547
530 548 /*
531 549 * If this transaction group is over 7/8ths capacity, delay
532 550 * the caller 1 clock tick. This will slow down the "fill"
533 551 * rate until the sync process can catch up with us.
534 552 */
535 553 if (reserved && reserved > (write_limit - (write_limit >> 3)))
536 554 txg_delay(dp, tx->tx_txg, 1);
537 555
538 556 return (0);
539 557 }
540 558
541 559 void
542 560 dsl_pool_tempreserve_clear(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx)
543 561 {
544 562 ASSERT(dp->dp_tempreserved[tx->tx_txg & TXG_MASK] >= space);
545 563 atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK], -space);
546 564 }
547 565
548 566 void
549 567 dsl_pool_memory_pressure(dsl_pool_t *dp)
550 568 {
551 569 uint64_t space_inuse = 0;
552 570 int i;
553 571
554 572 if (dp->dp_write_limit == zfs_write_limit_min)
555 573 return;
556 574
557 575 for (i = 0; i < TXG_SIZE; i++) {
558 576 space_inuse += dp->dp_space_towrite[i];
559 577 space_inuse += dp->dp_tempreserved[i];
560 578 }
561 579 dp->dp_write_limit = MAX(zfs_write_limit_min,
562 580 MIN(dp->dp_write_limit, space_inuse / 4));
563 581 }
564 582
565 583 void
566 584 dsl_pool_willuse_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx)
567 585 {
568 586 if (space > 0) {
569 587 mutex_enter(&dp->dp_lock);
570 588 dp->dp_space_towrite[tx->tx_txg & TXG_MASK] += space;
571 589 mutex_exit(&dp->dp_lock);
572 590 }
573 591 }
574 592
575 593 /* ARGSUSED */
576 594 static int
577 595 upgrade_clones_cb(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg)
578 596 {
579 597 dmu_tx_t *tx = arg;
580 598 dsl_dataset_t *ds, *prev = NULL;
581 599 int err;
582 600 dsl_pool_t *dp = spa_get_dsl(spa);
583 601
584 602 err = dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds);
585 603 if (err)
586 604 return (err);
587 605
588 606 while (ds->ds_phys->ds_prev_snap_obj != 0) {
589 607 err = dsl_dataset_hold_obj(dp, ds->ds_phys->ds_prev_snap_obj,
590 608 FTAG, &prev);
591 609 if (err) {
592 610 dsl_dataset_rele(ds, FTAG);
593 611 return (err);
594 612 }
595 613
596 614 if (prev->ds_phys->ds_next_snap_obj != ds->ds_object)
597 615 break;
598 616 dsl_dataset_rele(ds, FTAG);
599 617 ds = prev;
600 618 prev = NULL;
601 619 }
602 620
603 621 if (prev == NULL) {
604 622 prev = dp->dp_origin_snap;
605 623
606 624 /*
607 625 * The $ORIGIN can't have any data, or the accounting
608 626 * will be wrong.
609 627 */
610 628 ASSERT(prev->ds_phys->ds_bp.blk_birth == 0);
611 629
612 630 /* The origin doesn't get attached to itself */
613 631 if (ds->ds_object == prev->ds_object) {
614 632 dsl_dataset_rele(ds, FTAG);
615 633 return (0);
616 634 }
617 635
618 636 dmu_buf_will_dirty(ds->ds_dbuf, tx);
619 637 ds->ds_phys->ds_prev_snap_obj = prev->ds_object;
620 638 ds->ds_phys->ds_prev_snap_txg = prev->ds_phys->ds_creation_txg;
621 639
622 640 dmu_buf_will_dirty(ds->ds_dir->dd_dbuf, tx);
623 641 ds->ds_dir->dd_phys->dd_origin_obj = prev->ds_object;
624 642
625 643 dmu_buf_will_dirty(prev->ds_dbuf, tx);
626 644 prev->ds_phys->ds_num_children++;
627 645
628 646 if (ds->ds_phys->ds_next_snap_obj == 0) {
629 647 ASSERT(ds->ds_prev == NULL);
630 648 VERIFY(0 == dsl_dataset_hold_obj(dp,
631 649 ds->ds_phys->ds_prev_snap_obj, ds, &ds->ds_prev));
632 650 }
633 651 }
634 652
635 653 ASSERT(ds->ds_dir->dd_phys->dd_origin_obj == prev->ds_object);
636 654 ASSERT(ds->ds_phys->ds_prev_snap_obj == prev->ds_object);
637 655
638 656 if (prev->ds_phys->ds_next_clones_obj == 0) {
639 657 dmu_buf_will_dirty(prev->ds_dbuf, tx);
640 658 prev->ds_phys->ds_next_clones_obj =
641 659 zap_create(dp->dp_meta_objset,
642 660 DMU_OT_NEXT_CLONES, DMU_OT_NONE, 0, tx);
643 661 }
644 662 VERIFY(0 == zap_add_int(dp->dp_meta_objset,
645 663 prev->ds_phys->ds_next_clones_obj, ds->ds_object, tx));
646 664
647 665 dsl_dataset_rele(ds, FTAG);
648 666 if (prev != dp->dp_origin_snap)
649 667 dsl_dataset_rele(prev, FTAG);
650 668 return (0);
651 669 }
652 670
653 671 void
654 672 dsl_pool_upgrade_clones(dsl_pool_t *dp, dmu_tx_t *tx)
655 673 {
656 674 ASSERT(dmu_tx_is_syncing(tx));
657 675 ASSERT(dp->dp_origin_snap != NULL);
658 676
659 677 VERIFY3U(0, ==, dmu_objset_find_spa(dp->dp_spa, NULL, upgrade_clones_cb,
660 678 tx, DS_FIND_CHILDREN));
661 679 }
662 680
663 681 /* ARGSUSED */
664 682 static int
665 683 upgrade_dir_clones_cb(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg)
666 684 {
667 685 dmu_tx_t *tx = arg;
668 686 dsl_dataset_t *ds;
669 687 dsl_pool_t *dp = spa_get_dsl(spa);
670 688 objset_t *mos = dp->dp_meta_objset;
671 689
672 690 VERIFY3U(0, ==, dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds));
673 691
674 692 if (ds->ds_dir->dd_phys->dd_origin_obj) {
675 693 dsl_dataset_t *origin;
676 694
677 695 VERIFY3U(0, ==, dsl_dataset_hold_obj(dp,
678 696 ds->ds_dir->dd_phys->dd_origin_obj, FTAG, &origin));
679 697
680 698 if (origin->ds_dir->dd_phys->dd_clones == 0) {
681 699 dmu_buf_will_dirty(origin->ds_dir->dd_dbuf, tx);
682 700 origin->ds_dir->dd_phys->dd_clones = zap_create(mos,
683 701 DMU_OT_DSL_CLONES, DMU_OT_NONE, 0, tx);
684 702 }
685 703
686 704 VERIFY3U(0, ==, zap_add_int(dp->dp_meta_objset,
687 705 origin->ds_dir->dd_phys->dd_clones, dsobj, tx));
688 706
689 707 dsl_dataset_rele(origin, FTAG);
690 708 }
691 709
692 710 dsl_dataset_rele(ds, FTAG);
693 711 return (0);
694 712 }
695 713
696 714 void
697 715 dsl_pool_upgrade_dir_clones(dsl_pool_t *dp, dmu_tx_t *tx)
698 716 {
699 717 ASSERT(dmu_tx_is_syncing(tx));
700 718 uint64_t obj;
701 719
702 720 (void) dsl_dir_create_sync(dp, dp->dp_root_dir, FREE_DIR_NAME, tx);
703 721 VERIFY(0 == dsl_pool_open_special_dir(dp,
704 722 FREE_DIR_NAME, &dp->dp_free_dir));
705 723
706 724 /*
707 725 * We can't use bpobj_alloc(), because spa_version() still
708 726 * returns the old version, and we need a new-version bpobj with
709 727 * subobj support. So call dmu_object_alloc() directly.
710 728 */
711 729 obj = dmu_object_alloc(dp->dp_meta_objset, DMU_OT_BPOBJ,
712 730 SPA_MAXBLOCKSIZE, DMU_OT_BPOBJ_HDR, sizeof (bpobj_phys_t), tx);
713 731 VERIFY3U(0, ==, zap_add(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
714 732 DMU_POOL_FREE_BPOBJ, sizeof (uint64_t), 1, &obj, tx));
715 733 VERIFY3U(0, ==, bpobj_open(&dp->dp_free_bpobj,
716 734 dp->dp_meta_objset, obj));
717 735
718 736 VERIFY3U(0, ==, dmu_objset_find_spa(dp->dp_spa, NULL,
719 737 upgrade_dir_clones_cb, tx, DS_FIND_CHILDREN));
720 738 }
721 739
722 740 void
723 741 dsl_pool_create_origin(dsl_pool_t *dp, dmu_tx_t *tx)
724 742 {
725 743 uint64_t dsobj;
726 744 dsl_dataset_t *ds;
727 745
728 746 ASSERT(dmu_tx_is_syncing(tx));
729 747 ASSERT(dp->dp_origin_snap == NULL);
730 748
731 749 /* create the origin dir, ds, & snap-ds */
732 750 rw_enter(&dp->dp_config_rwlock, RW_WRITER);
733 751 dsobj = dsl_dataset_create_sync(dp->dp_root_dir, ORIGIN_DIR_NAME,
734 752 NULL, 0, kcred, tx);
735 753 VERIFY(0 == dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds));
736 754 dsl_dataset_snapshot_sync(ds, ORIGIN_DIR_NAME, tx);
737 755 VERIFY(0 == dsl_dataset_hold_obj(dp, ds->ds_phys->ds_prev_snap_obj,
738 756 dp, &dp->dp_origin_snap));
739 757 dsl_dataset_rele(ds, FTAG);
740 758 rw_exit(&dp->dp_config_rwlock);
741 759 }
742 760
743 761 taskq_t *
744 762 dsl_pool_vnrele_taskq(dsl_pool_t *dp)
745 763 {
746 764 return (dp->dp_vnrele_taskq);
747 765 }
748 766
749 767 /*
750 768 * Walk through the pool-wide zap object of temporary snapshot user holds
751 769 * and release them.
752 770 */
753 771 void
754 772 dsl_pool_clean_tmp_userrefs(dsl_pool_t *dp)
755 773 {
756 774 zap_attribute_t za;
757 775 zap_cursor_t zc;
758 776 objset_t *mos = dp->dp_meta_objset;
759 777 uint64_t zapobj = dp->dp_tmp_userrefs_obj;
760 778
761 779 if (zapobj == 0)
762 780 return;
763 781 ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS);
764 782
765 783 for (zap_cursor_init(&zc, mos, zapobj);
766 784 zap_cursor_retrieve(&zc, &za) == 0;
767 785 zap_cursor_advance(&zc)) {
768 786 char *htag;
769 787 uint64_t dsobj;
770 788
771 789 htag = strchr(za.za_name, '-');
772 790 *htag = '\0';
773 791 ++htag;
774 792 dsobj = strtonum(za.za_name, NULL);
775 793 (void) dsl_dataset_user_release_tmp(dp, dsobj, htag, B_FALSE);
776 794 }
777 795 zap_cursor_fini(&zc);
778 796 }
779 797
780 798 /*
|
↓ open down ↓ |
297 lines elided |
↑ open up ↑ |
781 799 * Create the pool-wide zap object for storing temporary snapshot holds.
782 800 */
783 801 void
784 802 dsl_pool_user_hold_create_obj(dsl_pool_t *dp, dmu_tx_t *tx)
785 803 {
786 804 objset_t *mos = dp->dp_meta_objset;
787 805
788 806 ASSERT(dp->dp_tmp_userrefs_obj == 0);
789 807 ASSERT(dmu_tx_is_syncing(tx));
790 808
791 - dp->dp_tmp_userrefs_obj = zap_create(mos, DMU_OT_USERREFS,
792 - DMU_OT_NONE, 0, tx);
793 -
794 - VERIFY(zap_add(mos, DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_TMP_USERREFS,
795 - sizeof (uint64_t), 1, &dp->dp_tmp_userrefs_obj, tx) == 0);
809 + dp->dp_tmp_userrefs_obj = zap_create_link(mos, DMU_OT_USERREFS,
810 + DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_TMP_USERREFS, tx);
796 811 }
797 812
798 813 static int
799 814 dsl_pool_user_hold_rele_impl(dsl_pool_t *dp, uint64_t dsobj,
800 815 const char *tag, uint64_t *now, dmu_tx_t *tx, boolean_t holding)
801 816 {
802 817 objset_t *mos = dp->dp_meta_objset;
803 818 uint64_t zapobj = dp->dp_tmp_userrefs_obj;
804 819 char *name;
805 820 int error;
806 821
807 822 ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS);
808 823 ASSERT(dmu_tx_is_syncing(tx));
809 824
810 825 /*
811 826 * If the pool was created prior to SPA_VERSION_USERREFS, the
812 827 * zap object for temporary holds might not exist yet.
813 828 */
814 829 if (zapobj == 0) {
815 830 if (holding) {
816 831 dsl_pool_user_hold_create_obj(dp, tx);
817 832 zapobj = dp->dp_tmp_userrefs_obj;
818 833 } else {
819 834 return (ENOENT);
820 835 }
821 836 }
822 837
823 838 name = kmem_asprintf("%llx-%s", (u_longlong_t)dsobj, tag);
824 839 if (holding)
825 840 error = zap_add(mos, zapobj, name, 8, 1, now, tx);
826 841 else
827 842 error = zap_remove(mos, zapobj, name, tx);
828 843 strfree(name);
829 844
830 845 return (error);
831 846 }
832 847
833 848 /*
834 849 * Add a temporary hold for the given dataset object and tag.
835 850 */
836 851 int
837 852 dsl_pool_user_hold(dsl_pool_t *dp, uint64_t dsobj, const char *tag,
838 853 uint64_t *now, dmu_tx_t *tx)
839 854 {
840 855 return (dsl_pool_user_hold_rele_impl(dp, dsobj, tag, now, tx, B_TRUE));
841 856 }
842 857
843 858 /*
844 859 * Release a temporary hold for the given dataset object and tag.
845 860 */
846 861 int
847 862 dsl_pool_user_release(dsl_pool_t *dp, uint64_t dsobj, const char *tag,
848 863 dmu_tx_t *tx)
849 864 {
850 865 return (dsl_pool_user_hold_rele_impl(dp, dsobj, tag, NULL,
851 866 tx, B_FALSE));
852 867 }
|
↓ open down ↓ |
47 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX