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