Print this page
4374 dn_free_ranges should use range_tree_t
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Max Grossman <max.grossman@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Dan McDonald <danmcd@omniti.com>
Approved by: Dan McDonald <danmcd@omniti.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/zfs/dnode_sync.c
+++ new/usr/src/uts/common/fs/zfs/dnode_sync.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 /*
23 23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 - * Copyright (c) 2013 by Delphix. All rights reserved.
24 + * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
25 25 */
26 26
27 27 #include <sys/zfs_context.h>
28 28 #include <sys/dbuf.h>
29 29 #include <sys/dnode.h>
30 30 #include <sys/dmu.h>
31 31 #include <sys/dmu_tx.h>
32 32 #include <sys/dmu_objset.h>
33 33 #include <sys/dsl_dataset.h>
34 34 #include <sys/spa.h>
35 +#include <sys/range_tree.h>
35 36 #include <sys/zfeature.h>
36 37
37 38 static void
38 39 dnode_increase_indirection(dnode_t *dn, dmu_tx_t *tx)
39 40 {
40 41 dmu_buf_impl_t *db;
41 42 int txgoff = tx->tx_txg & TXG_MASK;
42 43 int nblkptr = dn->dn_phys->dn_nblkptr;
43 44 int old_toplvl = dn->dn_phys->dn_nlevels - 1;
44 45 int new_level = dn->dn_next_nlevels[txgoff];
45 46 int i;
46 47
47 48 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
48 49
49 50 /* this dnode can't be paged out because it's dirty */
50 51 ASSERT(dn->dn_phys->dn_type != DMU_OT_NONE);
51 52 ASSERT(RW_WRITE_HELD(&dn->dn_struct_rwlock));
52 53 ASSERT(new_level > 1 && dn->dn_phys->dn_nlevels > 0);
53 54
54 55 db = dbuf_hold_level(dn, dn->dn_phys->dn_nlevels, 0, FTAG);
55 56 ASSERT(db != NULL);
56 57
57 58 dn->dn_phys->dn_nlevels = new_level;
58 59 dprintf("os=%p obj=%llu, increase to %d\n", dn->dn_objset,
59 60 dn->dn_object, dn->dn_phys->dn_nlevels);
60 61
61 62 /* check for existing blkptrs in the dnode */
62 63 for (i = 0; i < nblkptr; i++)
63 64 if (!BP_IS_HOLE(&dn->dn_phys->dn_blkptr[i]))
64 65 break;
65 66 if (i != nblkptr) {
66 67 /* transfer dnode's block pointers to new indirect block */
67 68 (void) dbuf_read(db, NULL, DB_RF_MUST_SUCCEED|DB_RF_HAVESTRUCT);
68 69 ASSERT(db->db.db_data);
69 70 ASSERT(arc_released(db->db_buf));
70 71 ASSERT3U(sizeof (blkptr_t) * nblkptr, <=, db->db.db_size);
71 72 bcopy(dn->dn_phys->dn_blkptr, db->db.db_data,
72 73 sizeof (blkptr_t) * nblkptr);
73 74 arc_buf_freeze(db->db_buf);
74 75 }
75 76
76 77 /* set dbuf's parent pointers to new indirect buf */
77 78 for (i = 0; i < nblkptr; i++) {
78 79 dmu_buf_impl_t *child = dbuf_find(dn, old_toplvl, i);
79 80
80 81 if (child == NULL)
81 82 continue;
82 83 #ifdef DEBUG
83 84 DB_DNODE_ENTER(child);
84 85 ASSERT3P(DB_DNODE(child), ==, dn);
85 86 DB_DNODE_EXIT(child);
86 87 #endif /* DEBUG */
87 88 if (child->db_parent && child->db_parent != dn->dn_dbuf) {
88 89 ASSERT(child->db_parent->db_level == db->db_level);
89 90 ASSERT(child->db_blkptr !=
90 91 &dn->dn_phys->dn_blkptr[child->db_blkid]);
91 92 mutex_exit(&child->db_mtx);
92 93 continue;
93 94 }
94 95 ASSERT(child->db_parent == NULL ||
95 96 child->db_parent == dn->dn_dbuf);
96 97
97 98 child->db_parent = db;
98 99 dbuf_add_ref(db, child);
99 100 if (db->db.db_data)
100 101 child->db_blkptr = (blkptr_t *)db->db.db_data + i;
101 102 else
102 103 child->db_blkptr = NULL;
103 104 dprintf_dbuf_bp(child, child->db_blkptr,
104 105 "changed db_blkptr to new indirect %s", "");
105 106
106 107 mutex_exit(&child->db_mtx);
107 108 }
108 109
109 110 bzero(dn->dn_phys->dn_blkptr, sizeof (blkptr_t) * nblkptr);
110 111
111 112 dbuf_rele(db, FTAG);
112 113
113 114 rw_exit(&dn->dn_struct_rwlock);
114 115 }
115 116
116 117 static void
117 118 free_blocks(dnode_t *dn, blkptr_t *bp, int num, dmu_tx_t *tx)
118 119 {
119 120 dsl_dataset_t *ds = dn->dn_objset->os_dsl_dataset;
120 121 uint64_t bytesfreed = 0;
121 122
122 123 dprintf("ds=%p obj=%llx num=%d\n", ds, dn->dn_object, num);
123 124
124 125 for (int i = 0; i < num; i++, bp++) {
125 126 if (BP_IS_HOLE(bp))
126 127 continue;
127 128
128 129 bytesfreed += dsl_dataset_block_kill(ds, bp, tx, B_FALSE);
129 130 ASSERT3U(bytesfreed, <=, DN_USED_BYTES(dn->dn_phys));
130 131
131 132 /*
132 133 * Save some useful information on the holes being
133 134 * punched, including logical size, type, and indirection
134 135 * level. Retaining birth time enables detection of when
135 136 * holes are punched for reducing the number of free
136 137 * records transmitted during a zfs send.
137 138 */
138 139
139 140 uint64_t lsize = BP_GET_LSIZE(bp);
140 141 dmu_object_type_t type = BP_GET_TYPE(bp);
141 142 uint64_t lvl = BP_GET_LEVEL(bp);
142 143
143 144 bzero(bp, sizeof (blkptr_t));
144 145
145 146 if (spa_feature_is_active(dn->dn_objset->os_spa,
146 147 SPA_FEATURE_HOLE_BIRTH)) {
147 148 BP_SET_LSIZE(bp, lsize);
148 149 BP_SET_TYPE(bp, type);
149 150 BP_SET_LEVEL(bp, lvl);
150 151 BP_SET_BIRTH(bp, dmu_tx_get_txg(tx), 0);
151 152 }
152 153 }
153 154 dnode_diduse_space(dn, -bytesfreed);
154 155 }
155 156
156 157 #ifdef ZFS_DEBUG
157 158 static void
158 159 free_verify(dmu_buf_impl_t *db, uint64_t start, uint64_t end, dmu_tx_t *tx)
159 160 {
160 161 int off, num;
161 162 int i, err, epbs;
162 163 uint64_t txg = tx->tx_txg;
163 164 dnode_t *dn;
164 165
165 166 DB_DNODE_ENTER(db);
166 167 dn = DB_DNODE(db);
167 168 epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
168 169 off = start - (db->db_blkid * 1<<epbs);
169 170 num = end - start + 1;
170 171
171 172 ASSERT3U(off, >=, 0);
172 173 ASSERT3U(num, >=, 0);
173 174 ASSERT3U(db->db_level, >, 0);
174 175 ASSERT3U(db->db.db_size, ==, 1 << dn->dn_phys->dn_indblkshift);
175 176 ASSERT3U(off+num, <=, db->db.db_size >> SPA_BLKPTRSHIFT);
176 177 ASSERT(db->db_blkptr != NULL);
177 178
178 179 for (i = off; i < off+num; i++) {
179 180 uint64_t *buf;
180 181 dmu_buf_impl_t *child;
181 182 dbuf_dirty_record_t *dr;
182 183 int j;
183 184
184 185 ASSERT(db->db_level == 1);
185 186
186 187 rw_enter(&dn->dn_struct_rwlock, RW_READER);
187 188 err = dbuf_hold_impl(dn, db->db_level-1,
188 189 (db->db_blkid << epbs) + i, TRUE, FTAG, &child);
189 190 rw_exit(&dn->dn_struct_rwlock);
190 191 if (err == ENOENT)
191 192 continue;
192 193 ASSERT(err == 0);
193 194 ASSERT(child->db_level == 0);
194 195 dr = child->db_last_dirty;
195 196 while (dr && dr->dr_txg > txg)
196 197 dr = dr->dr_next;
197 198 ASSERT(dr == NULL || dr->dr_txg == txg);
198 199
199 200 /* data_old better be zeroed */
200 201 if (dr) {
201 202 buf = dr->dt.dl.dr_data->b_data;
202 203 for (j = 0; j < child->db.db_size >> 3; j++) {
203 204 if (buf[j] != 0) {
204 205 panic("freed data not zero: "
205 206 "child=%p i=%d off=%d num=%d\n",
206 207 (void *)child, i, off, num);
207 208 }
208 209 }
209 210 }
210 211
211 212 /*
212 213 * db_data better be zeroed unless it's dirty in a
213 214 * future txg.
214 215 */
215 216 mutex_enter(&child->db_mtx);
216 217 buf = child->db.db_data;
217 218 if (buf != NULL && child->db_state != DB_FILL &&
218 219 child->db_last_dirty == NULL) {
219 220 for (j = 0; j < child->db.db_size >> 3; j++) {
220 221 if (buf[j] != 0) {
221 222 panic("freed data not zero: "
222 223 "child=%p i=%d off=%d num=%d\n",
223 224 (void *)child, i, off, num);
224 225 }
225 226 }
226 227 }
227 228 mutex_exit(&child->db_mtx);
228 229
229 230 dbuf_rele(child, FTAG);
230 231 }
231 232 DB_DNODE_EXIT(db);
232 233 }
233 234 #endif
234 235
235 236 #define ALL -1
236 237
237 238 static void
238 239 free_children(dmu_buf_impl_t *db, uint64_t blkid, uint64_t nblks,
239 240 dmu_tx_t *tx)
240 241 {
241 242 dnode_t *dn;
242 243 blkptr_t *bp;
243 244 dmu_buf_impl_t *subdb;
244 245 uint64_t start, end, dbstart, dbend, i;
245 246 int epbs, shift;
246 247
247 248 /*
248 249 * There is a small possibility that this block will not be cached:
249 250 * 1 - if level > 1 and there are no children with level <= 1
250 251 * 2 - if this block was evicted since we read it from
251 252 * dmu_tx_hold_free().
252 253 */
253 254 if (db->db_state != DB_CACHED)
254 255 (void) dbuf_read(db, NULL, DB_RF_MUST_SUCCEED);
255 256
256 257 dbuf_release_bp(db);
257 258 bp = db->db.db_data;
258 259
259 260 DB_DNODE_ENTER(db);
260 261 dn = DB_DNODE(db);
261 262 epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
262 263 shift = (db->db_level - 1) * epbs;
263 264 dbstart = db->db_blkid << epbs;
264 265 start = blkid >> shift;
265 266 if (dbstart < start) {
266 267 bp += start - dbstart;
267 268 } else {
268 269 start = dbstart;
269 270 }
270 271 dbend = ((db->db_blkid + 1) << epbs) - 1;
271 272 end = (blkid + nblks - 1) >> shift;
272 273 if (dbend <= end)
273 274 end = dbend;
274 275
275 276 ASSERT3U(start, <=, end);
276 277
277 278 if (db->db_level == 1) {
278 279 FREE_VERIFY(db, start, end, tx);
279 280 free_blocks(dn, bp, end-start+1, tx);
280 281 } else {
281 282 for (i = start; i <= end; i++, bp++) {
282 283 if (BP_IS_HOLE(bp))
283 284 continue;
284 285 rw_enter(&dn->dn_struct_rwlock, RW_READER);
285 286 VERIFY0(dbuf_hold_impl(dn, db->db_level - 1,
286 287 i, B_TRUE, FTAG, &subdb));
287 288 rw_exit(&dn->dn_struct_rwlock);
288 289 ASSERT3P(bp, ==, subdb->db_blkptr);
289 290
290 291 free_children(subdb, blkid, nblks, tx);
291 292 dbuf_rele(subdb, FTAG);
292 293 }
293 294 }
294 295
295 296 /* If this whole block is free, free ourself too. */
296 297 for (i = 0, bp = db->db.db_data; i < 1 << epbs; i++, bp++) {
297 298 if (!BP_IS_HOLE(bp))
298 299 break;
299 300 }
300 301 if (i == 1 << epbs) {
301 302 /* didn't find any non-holes */
302 303 bzero(db->db.db_data, db->db.db_size);
303 304 free_blocks(dn, db->db_blkptr, 1, tx);
304 305 } else {
305 306 /*
306 307 * Partial block free; must be marked dirty so that it
307 308 * will be written out.
308 309 */
309 310 ASSERT(db->db_dirtycnt > 0);
310 311 }
|
↓ open down ↓ |
266 lines elided |
↑ open up ↑ |
311 312
312 313 DB_DNODE_EXIT(db);
313 314 arc_buf_freeze(db->db_buf);
314 315 }
315 316
316 317 /*
317 318 * Traverse the indicated range of the provided file
318 319 * and "free" all the blocks contained there.
319 320 */
320 321 static void
321 -dnode_sync_free_range(dnode_t *dn, uint64_t blkid, uint64_t nblks,
322 +dnode_sync_free_range_impl(dnode_t *dn, uint64_t blkid, uint64_t nblks,
322 323 dmu_tx_t *tx)
323 324 {
324 325 blkptr_t *bp = dn->dn_phys->dn_blkptr;
325 326 int dnlevel = dn->dn_phys->dn_nlevels;
326 327 boolean_t trunc = B_FALSE;
327 328
328 329 if (blkid > dn->dn_phys->dn_maxblkid)
329 330 return;
330 331
331 332 ASSERT(dn->dn_phys->dn_maxblkid < UINT64_MAX);
332 333 if (blkid + nblks > dn->dn_phys->dn_maxblkid) {
333 334 nblks = dn->dn_phys->dn_maxblkid - blkid + 1;
334 335 trunc = B_TRUE;
335 336 }
336 337
337 338 /* There are no indirect blocks in the object */
338 339 if (dnlevel == 1) {
339 340 if (blkid >= dn->dn_phys->dn_nblkptr) {
340 341 /* this range was never made persistent */
341 342 return;
342 343 }
343 344 ASSERT3U(blkid + nblks, <=, dn->dn_phys->dn_nblkptr);
344 345 free_blocks(dn, bp + blkid, nblks, tx);
345 346 } else {
346 347 int shift = (dnlevel - 1) *
347 348 (dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT);
348 349 int start = blkid >> shift;
349 350 int end = (blkid + nblks - 1) >> shift;
350 351 dmu_buf_impl_t *db;
351 352
352 353 ASSERT(start < dn->dn_phys->dn_nblkptr);
353 354 bp += start;
354 355 for (int i = start; i <= end; i++, bp++) {
355 356 if (BP_IS_HOLE(bp))
356 357 continue;
357 358 rw_enter(&dn->dn_struct_rwlock, RW_READER);
358 359 VERIFY0(dbuf_hold_impl(dn, dnlevel - 1, i,
359 360 TRUE, FTAG, &db));
360 361 rw_exit(&dn->dn_struct_rwlock);
361 362
362 363 free_children(db, blkid, nblks, tx);
363 364 dbuf_rele(db, FTAG);
364 365
365 366 }
366 367 }
367 368
368 369 if (trunc) {
|
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
369 370 dn->dn_phys->dn_maxblkid = blkid == 0 ? 0 : blkid - 1;
370 371
371 372 uint64_t off = (dn->dn_phys->dn_maxblkid + 1) *
372 373 (dn->dn_phys->dn_datablkszsec << SPA_MINBLOCKSHIFT);
373 374 ASSERT(off < dn->dn_phys->dn_maxblkid ||
374 375 dn->dn_phys->dn_maxblkid == 0 ||
375 376 dnode_next_offset(dn, 0, &off, 1, 1, 0) != 0);
376 377 }
377 378 }
378 379
380 +typedef struct dnode_sync_free_range_arg {
381 + dnode_t *dsfra_dnode;
382 + dmu_tx_t *dsfra_tx;
383 +} dnode_sync_free_range_arg_t;
384 +
385 +static void
386 +dnode_sync_free_range(void *arg, uint64_t blkid, uint64_t nblks)
387 +{
388 + dnode_sync_free_range_arg_t *dsfra = arg;
389 + dnode_t *dn = dsfra->dsfra_dnode;
390 +
391 + mutex_exit(&dn->dn_mtx);
392 + dnode_sync_free_range_impl(dn, blkid, nblks, dsfra->dsfra_tx);
393 + mutex_enter(&dn->dn_mtx);
394 +}
395 +
379 396 /*
380 397 * Try to kick all the dnode's dbufs out of the cache...
381 398 */
382 399 void
383 400 dnode_evict_dbufs(dnode_t *dn)
384 401 {
385 402 int progress;
386 403 int pass = 0;
387 404
388 405 do {
389 406 dmu_buf_impl_t *db, marker;
390 407 int evicting = FALSE;
391 408
392 409 progress = FALSE;
393 410 mutex_enter(&dn->dn_dbufs_mtx);
394 411 list_insert_tail(&dn->dn_dbufs, &marker);
395 412 db = list_head(&dn->dn_dbufs);
396 413 for (; db != ▮ db = list_head(&dn->dn_dbufs)) {
397 414 list_remove(&dn->dn_dbufs, db);
398 415 list_insert_tail(&dn->dn_dbufs, db);
399 416 #ifdef DEBUG
400 417 DB_DNODE_ENTER(db);
401 418 ASSERT3P(DB_DNODE(db), ==, dn);
402 419 DB_DNODE_EXIT(db);
403 420 #endif /* DEBUG */
404 421
405 422 mutex_enter(&db->db_mtx);
406 423 if (db->db_state == DB_EVICTING) {
407 424 progress = TRUE;
408 425 evicting = TRUE;
409 426 mutex_exit(&db->db_mtx);
410 427 } else if (refcount_is_zero(&db->db_holds)) {
411 428 progress = TRUE;
412 429 dbuf_clear(db); /* exits db_mtx for us */
413 430 } else {
414 431 mutex_exit(&db->db_mtx);
415 432 }
416 433
417 434 }
418 435 list_remove(&dn->dn_dbufs, &marker);
419 436 /*
420 437 * NB: we need to drop dn_dbufs_mtx between passes so
421 438 * that any DB_EVICTING dbufs can make progress.
422 439 * Ideally, we would have some cv we could wait on, but
423 440 * since we don't, just wait a bit to give the other
424 441 * thread a chance to run.
425 442 */
426 443 mutex_exit(&dn->dn_dbufs_mtx);
427 444 if (evicting)
428 445 delay(1);
429 446 pass++;
430 447 ASSERT(pass < 100); /* sanity check */
431 448 } while (progress);
432 449
433 450 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
434 451 if (dn->dn_bonus && refcount_is_zero(&dn->dn_bonus->db_holds)) {
435 452 mutex_enter(&dn->dn_bonus->db_mtx);
436 453 dbuf_evict(dn->dn_bonus);
437 454 dn->dn_bonus = NULL;
438 455 }
439 456 rw_exit(&dn->dn_struct_rwlock);
440 457 }
441 458
442 459 static void
443 460 dnode_undirty_dbufs(list_t *list)
444 461 {
445 462 dbuf_dirty_record_t *dr;
446 463
447 464 while (dr = list_head(list)) {
448 465 dmu_buf_impl_t *db = dr->dr_dbuf;
449 466 uint64_t txg = dr->dr_txg;
450 467
451 468 if (db->db_level != 0)
452 469 dnode_undirty_dbufs(&dr->dt.di.dr_children);
453 470
454 471 mutex_enter(&db->db_mtx);
455 472 /* XXX - use dbuf_undirty()? */
456 473 list_remove(list, dr);
457 474 ASSERT(db->db_last_dirty == dr);
458 475 db->db_last_dirty = NULL;
459 476 db->db_dirtycnt -= 1;
460 477 if (db->db_level == 0) {
461 478 ASSERT(db->db_blkid == DMU_BONUS_BLKID ||
462 479 dr->dt.dl.dr_data == db->db_buf);
463 480 dbuf_unoverride(dr);
464 481 }
465 482 kmem_free(dr, sizeof (dbuf_dirty_record_t));
466 483 dbuf_rele_and_unlock(db, (void *)(uintptr_t)txg);
467 484 }
468 485 }
469 486
470 487 static void
471 488 dnode_sync_free(dnode_t *dn, dmu_tx_t *tx)
472 489 {
473 490 int txgoff = tx->tx_txg & TXG_MASK;
474 491
475 492 ASSERT(dmu_tx_is_syncing(tx));
476 493
477 494 /*
478 495 * Our contents should have been freed in dnode_sync() by the
479 496 * free range record inserted by the caller of dnode_free().
480 497 */
481 498 ASSERT0(DN_USED_BYTES(dn->dn_phys));
482 499 ASSERT(BP_IS_HOLE(dn->dn_phys->dn_blkptr));
483 500
484 501 dnode_undirty_dbufs(&dn->dn_dirty_records[txgoff]);
485 502 dnode_evict_dbufs(dn);
486 503 ASSERT3P(list_head(&dn->dn_dbufs), ==, NULL);
487 504 ASSERT3P(dn->dn_bonus, ==, NULL);
488 505
489 506 /*
490 507 * XXX - It would be nice to assert this, but we may still
491 508 * have residual holds from async evictions from the arc...
492 509 *
493 510 * zfs_obj_to_path() also depends on this being
494 511 * commented out.
495 512 *
496 513 * ASSERT3U(refcount_count(&dn->dn_holds), ==, 1);
497 514 */
498 515
499 516 /* Undirty next bits */
500 517 dn->dn_next_nlevels[txgoff] = 0;
501 518 dn->dn_next_indblkshift[txgoff] = 0;
502 519 dn->dn_next_blksz[txgoff] = 0;
503 520
504 521 /* ASSERT(blkptrs are zero); */
505 522 ASSERT(dn->dn_phys->dn_type != DMU_OT_NONE);
506 523 ASSERT(dn->dn_type != DMU_OT_NONE);
507 524
508 525 ASSERT(dn->dn_free_txg > 0);
509 526 if (dn->dn_allocated_txg != dn->dn_free_txg)
510 527 dmu_buf_will_dirty(&dn->dn_dbuf->db, tx);
511 528 bzero(dn->dn_phys, sizeof (dnode_phys_t));
512 529
513 530 mutex_enter(&dn->dn_mtx);
514 531 dn->dn_type = DMU_OT_NONE;
515 532 dn->dn_maxblkid = 0;
516 533 dn->dn_allocated_txg = 0;
517 534 dn->dn_free_txg = 0;
518 535 dn->dn_have_spill = B_FALSE;
519 536 mutex_exit(&dn->dn_mtx);
520 537
521 538 ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT);
522 539
523 540 dnode_rele(dn, (void *)(uintptr_t)tx->tx_txg);
524 541 /*
525 542 * Now that we've released our hold, the dnode may
|
↓ open down ↓ |
137 lines elided |
↑ open up ↑ |
526 543 * be evicted, so we musn't access it.
527 544 */
528 545 }
529 546
530 547 /*
531 548 * Write out the dnode's dirty buffers.
532 549 */
533 550 void
534 551 dnode_sync(dnode_t *dn, dmu_tx_t *tx)
535 552 {
536 - free_range_t *rp;
537 553 dnode_phys_t *dnp = dn->dn_phys;
538 554 int txgoff = tx->tx_txg & TXG_MASK;
539 555 list_t *list = &dn->dn_dirty_records[txgoff];
540 556 static const dnode_phys_t zerodn = { 0 };
541 557 boolean_t kill_spill = B_FALSE;
542 558
543 559 ASSERT(dmu_tx_is_syncing(tx));
544 560 ASSERT(dnp->dn_type != DMU_OT_NONE || dn->dn_allocated_txg);
545 561 ASSERT(dnp->dn_type != DMU_OT_NONE ||
546 562 bcmp(dnp, &zerodn, DNODE_SIZE) == 0);
547 563 DNODE_VERIFY(dn);
548 564
549 565 ASSERT(dn->dn_dbuf == NULL || arc_released(dn->dn_dbuf->db_buf));
550 566
551 567 if (dmu_objset_userused_enabled(dn->dn_objset) &&
552 568 !DMU_OBJECT_IS_SPECIAL(dn->dn_object)) {
553 569 mutex_enter(&dn->dn_mtx);
554 570 dn->dn_oldused = DN_USED_BYTES(dn->dn_phys);
555 571 dn->dn_oldflags = dn->dn_phys->dn_flags;
556 572 dn->dn_phys->dn_flags |= DNODE_FLAG_USERUSED_ACCOUNTED;
557 573 mutex_exit(&dn->dn_mtx);
558 574 dmu_objset_userquota_get_ids(dn, B_FALSE, tx);
559 575 } else {
560 576 /* Once we account for it, we should always account for it. */
561 577 ASSERT(!(dn->dn_phys->dn_flags &
562 578 DNODE_FLAG_USERUSED_ACCOUNTED));
563 579 }
564 580
565 581 mutex_enter(&dn->dn_mtx);
566 582 if (dn->dn_allocated_txg == tx->tx_txg) {
567 583 /* The dnode is newly allocated or reallocated */
568 584 if (dnp->dn_type == DMU_OT_NONE) {
569 585 /* this is a first alloc, not a realloc */
570 586 dnp->dn_nlevels = 1;
571 587 dnp->dn_nblkptr = dn->dn_nblkptr;
572 588 }
573 589
574 590 dnp->dn_type = dn->dn_type;
575 591 dnp->dn_bonustype = dn->dn_bonustype;
576 592 dnp->dn_bonuslen = dn->dn_bonuslen;
577 593 }
578 594
579 595 ASSERT(dnp->dn_nlevels > 1 ||
580 596 BP_IS_HOLE(&dnp->dn_blkptr[0]) ||
581 597 BP_GET_LSIZE(&dnp->dn_blkptr[0]) ==
582 598 dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
583 599
|
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
584 600 if (dn->dn_next_type[txgoff] != 0) {
585 601 dnp->dn_type = dn->dn_type;
586 602 dn->dn_next_type[txgoff] = 0;
587 603 }
588 604
589 605 if (dn->dn_next_blksz[txgoff] != 0) {
590 606 ASSERT(P2PHASE(dn->dn_next_blksz[txgoff],
591 607 SPA_MINBLOCKSIZE) == 0);
592 608 ASSERT(BP_IS_HOLE(&dnp->dn_blkptr[0]) ||
593 609 dn->dn_maxblkid == 0 || list_head(list) != NULL ||
594 - avl_last(&dn->dn_ranges[txgoff]) ||
595 610 dn->dn_next_blksz[txgoff] >> SPA_MINBLOCKSHIFT ==
596 - dnp->dn_datablkszsec);
611 + dnp->dn_datablkszsec ||
612 + range_tree_space(dn->dn_free_ranges[txgoff]) != 0);
597 613 dnp->dn_datablkszsec =
598 614 dn->dn_next_blksz[txgoff] >> SPA_MINBLOCKSHIFT;
599 615 dn->dn_next_blksz[txgoff] = 0;
600 616 }
601 617
602 618 if (dn->dn_next_bonuslen[txgoff] != 0) {
603 619 if (dn->dn_next_bonuslen[txgoff] == DN_ZERO_BONUSLEN)
604 620 dnp->dn_bonuslen = 0;
605 621 else
606 622 dnp->dn_bonuslen = dn->dn_next_bonuslen[txgoff];
607 623 ASSERT(dnp->dn_bonuslen <= DN_MAX_BONUSLEN);
608 624 dn->dn_next_bonuslen[txgoff] = 0;
609 625 }
610 626
611 627 if (dn->dn_next_bonustype[txgoff] != 0) {
612 628 ASSERT(DMU_OT_IS_VALID(dn->dn_next_bonustype[txgoff]));
613 629 dnp->dn_bonustype = dn->dn_next_bonustype[txgoff];
614 630 dn->dn_next_bonustype[txgoff] = 0;
615 631 }
616 632
617 633 boolean_t freeing_dnode = dn->dn_free_txg > 0 &&
618 634 dn->dn_free_txg <= tx->tx_txg;
619 635
620 636 /*
621 637 * We will either remove a spill block when a file is being removed
622 638 * or we have been asked to remove it.
623 639 */
624 640 if (dn->dn_rm_spillblk[txgoff] ||
625 641 ((dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) && freeing_dnode)) {
626 642 if ((dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR))
627 643 kill_spill = B_TRUE;
628 644 dn->dn_rm_spillblk[txgoff] = 0;
629 645 }
630 646
631 647 if (dn->dn_next_indblkshift[txgoff] != 0) {
632 648 ASSERT(dnp->dn_nlevels == 1);
633 649 dnp->dn_indblkshift = dn->dn_next_indblkshift[txgoff];
634 650 dn->dn_next_indblkshift[txgoff] = 0;
635 651 }
636 652
637 653 /*
638 654 * Just take the live (open-context) values for checksum and compress.
639 655 * Strictly speaking it's a future leak, but nothing bad happens if we
640 656 * start using the new checksum or compress algorithm a little early.
641 657 */
642 658 dnp->dn_checksum = dn->dn_checksum;
643 659 dnp->dn_compress = dn->dn_compress;
644 660
|
↓ open down ↓ |
38 lines elided |
↑ open up ↑ |
645 661 mutex_exit(&dn->dn_mtx);
646 662
647 663 if (kill_spill) {
648 664 free_blocks(dn, &dn->dn_phys->dn_spill, 1, tx);
649 665 mutex_enter(&dn->dn_mtx);
650 666 dnp->dn_flags &= ~DNODE_FLAG_SPILL_BLKPTR;
651 667 mutex_exit(&dn->dn_mtx);
652 668 }
653 669
654 670 /* process all the "freed" ranges in the file */
655 - while (rp = avl_last(&dn->dn_ranges[txgoff])) {
656 - dnode_sync_free_range(dn, rp->fr_blkid, rp->fr_nblks, tx);
657 - /* grab the mutex so we don't race with dnode_block_freed() */
671 + if (dn->dn_free_ranges[txgoff] != NULL) {
672 + dnode_sync_free_range_arg_t dsfra;
673 + dsfra.dsfra_dnode = dn;
674 + dsfra.dsfra_tx = tx;
658 675 mutex_enter(&dn->dn_mtx);
659 - avl_remove(&dn->dn_ranges[txgoff], rp);
676 + range_tree_vacate(dn->dn_free_ranges[txgoff],
677 + dnode_sync_free_range, &dsfra);
678 + range_tree_destroy(dn->dn_free_ranges[txgoff]);
679 + dn->dn_free_ranges[txgoff] = NULL;
660 680 mutex_exit(&dn->dn_mtx);
661 - kmem_free(rp, sizeof (free_range_t));
662 681 }
663 682
664 683 if (freeing_dnode) {
665 684 dnode_sync_free(dn, tx);
666 685 return;
667 686 }
668 687
669 688 if (dn->dn_next_nblkptr[txgoff]) {
670 689 /* this should only happen on a realloc */
671 690 ASSERT(dn->dn_allocated_txg == tx->tx_txg);
672 691 if (dn->dn_next_nblkptr[txgoff] > dnp->dn_nblkptr) {
673 692 /* zero the new blkptrs we are gaining */
674 693 bzero(dnp->dn_blkptr + dnp->dn_nblkptr,
675 694 sizeof (blkptr_t) *
676 695 (dn->dn_next_nblkptr[txgoff] - dnp->dn_nblkptr));
677 696 #ifdef ZFS_DEBUG
678 697 } else {
679 698 int i;
680 699 ASSERT(dn->dn_next_nblkptr[txgoff] < dnp->dn_nblkptr);
681 700 /* the blkptrs we are losing better be unallocated */
682 701 for (i = dn->dn_next_nblkptr[txgoff];
683 702 i < dnp->dn_nblkptr; i++)
684 703 ASSERT(BP_IS_HOLE(&dnp->dn_blkptr[i]));
685 704 #endif
686 705 }
687 706 mutex_enter(&dn->dn_mtx);
688 707 dnp->dn_nblkptr = dn->dn_next_nblkptr[txgoff];
689 708 dn->dn_next_nblkptr[txgoff] = 0;
690 709 mutex_exit(&dn->dn_mtx);
691 710 }
692 711
693 712 if (dn->dn_next_nlevels[txgoff]) {
694 713 dnode_increase_indirection(dn, tx);
695 714 dn->dn_next_nlevels[txgoff] = 0;
696 715 }
697 716
698 717 dbuf_sync_list(list, tx);
699 718
700 719 if (!DMU_OBJECT_IS_SPECIAL(dn->dn_object)) {
701 720 ASSERT3P(list_head(list), ==, NULL);
702 721 dnode_rele(dn, (void *)(uintptr_t)tx->tx_txg);
703 722 }
704 723
705 724 /*
706 725 * Although we have dropped our reference to the dnode, it
707 726 * can't be evicted until its written, and we haven't yet
708 727 * initiated the IO for the dnode's dbuf.
709 728 */
710 729 }
|
↓ open down ↓ |
39 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX