annotate usr/src/uts/common/fs/zfs/dnode.c @ 13805:e3a9ae14a119

3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero Reviewed by Matt Ahrens <matthew.ahrens@delphix.com> Reviewed by George Wilson <george.wilson@delphix.com> Approved by Eric Schrock <eric.schrock@delphix.com>
author Madhav Suresh <madhav.suresh@delphix.com>
date Fri, 07 Sep 2012 07:19:55 -0700
parents 9410cf539b11
children 4972ab336f54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
2 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
3 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
4 * The contents of this file are subject to the terms of the
1491
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 1402
diff changeset
5 * Common Development and Distribution License (the "License").
bdcb30e07e7d 6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents: 1402
diff changeset
6 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
7 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
9 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
10 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
11 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
12 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
13 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
15 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
16 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
17 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
18 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
19 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
20 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
21 /*
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11958
diff changeset
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12684
diff changeset
23 * Copyright (c) 2012 by Delphix. All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
24 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
26 #include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
27 #include <sys/dbuf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
28 #include <sys/dnode.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
29 #include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
30 #include <sys/dmu_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
31 #include <sys/dmu_tx.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
32 #include <sys/dmu_objset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
33 #include <sys/dsl_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
34 #include <sys/dsl_dataset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
35 #include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
36 #include <sys/zio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
37 #include <sys/dmu_zfetch.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
38
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
39 static int free_range_compar(const void *node1, const void *node2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
40
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
41 static kmem_cache_t *dnode_cache;
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
42 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
43 * Define DNODE_STATS to turn on statistic gathering. By default, it is only
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
44 * turned on when DEBUG is also defined.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
45 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
46 #ifdef DEBUG
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
47 #define DNODE_STATS
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
48 #endif /* DEBUG */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
49
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
50 #ifdef DNODE_STATS
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
51 #define DNODE_STAT_ADD(stat) ((stat)++)
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
52 #else
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
53 #define DNODE_STAT_ADD(stat) /* nothing */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
54 #endif /* DNODE_STATS */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
55
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
56 static dnode_phys_t dnode_phys_zero;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
57
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
58 int zfs_default_bs = SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
59 int zfs_default_ibs = DN_MAX_INDBLKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
60
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
61 static kmem_cbrc_t dnode_move(void *, void *, size_t, void *);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
62
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
63 /* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
64 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
65 dnode_cons(void *arg, void *unused, int kmflag)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
66 {
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
67 dnode_t *dn = arg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
68 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
69
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
70 rw_init(&dn->dn_struct_rwlock, NULL, RW_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
71 mutex_init(&dn->dn_mtx, NULL, MUTEX_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
72 mutex_init(&dn->dn_dbufs_mtx, NULL, MUTEX_DEFAULT, NULL);
8214
d7abf7c1f1c1 6747934 Some locking variables are not properly initialized or destroyed
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 7754
diff changeset
73 cv_init(&dn->dn_notxholds, NULL, CV_DEFAULT, NULL);
d7abf7c1f1c1 6747934 Some locking variables are not properly initialized or destroyed
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 7754
diff changeset
74
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
75 refcount_create(&dn->dn_holds);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
76 refcount_create(&dn->dn_tx_holds);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
77 list_link_init(&dn->dn_link);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
78
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
79 bzero(&dn->dn_next_nblkptr[0], sizeof (dn->dn_next_nblkptr));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
80 bzero(&dn->dn_next_nlevels[0], sizeof (dn->dn_next_nlevels));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
81 bzero(&dn->dn_next_indblkshift[0], sizeof (dn->dn_next_indblkshift));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
82 bzero(&dn->dn_next_bonustype[0], sizeof (dn->dn_next_bonustype));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
83 bzero(&dn->dn_rm_spillblk[0], sizeof (dn->dn_rm_spillblk));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
84 bzero(&dn->dn_next_bonuslen[0], sizeof (dn->dn_next_bonuslen));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
85 bzero(&dn->dn_next_blksz[0], sizeof (dn->dn_next_blksz));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
86
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
87 for (i = 0; i < TXG_SIZE; i++) {
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
88 list_link_init(&dn->dn_dirty_link[i]);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
89 avl_create(&dn->dn_ranges[i], free_range_compar,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
90 sizeof (free_range_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
91 offsetof(struct free_range, fr_node));
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
92 list_create(&dn->dn_dirty_records[i],
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
93 sizeof (dbuf_dirty_record_t),
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
94 offsetof(dbuf_dirty_record_t, dr_dirty_node));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
95 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
96
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
97 dn->dn_allocated_txg = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
98 dn->dn_free_txg = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
99 dn->dn_assigned_txg = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
100 dn->dn_dirtyctx = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
101 dn->dn_dirtyctx_firstset = NULL;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
102 dn->dn_bonus = NULL;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
103 dn->dn_have_spill = B_FALSE;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
104 dn->dn_zio = NULL;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
105 dn->dn_oldused = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
106 dn->dn_oldflags = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
107 dn->dn_olduid = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
108 dn->dn_oldgid = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
109 dn->dn_newuid = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
110 dn->dn_newgid = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
111 dn->dn_id_flags = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
112
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
113 dn->dn_dbufs_count = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
114 list_create(&dn->dn_dbufs, sizeof (dmu_buf_impl_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
115 offsetof(dmu_buf_impl_t, db_link));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
116
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
117 dn->dn_moved = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
118 return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
119 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
120
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
121 /* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
122 static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
123 dnode_dest(void *arg, void *unused)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
124 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
125 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
126 dnode_t *dn = arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
127
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
128 rw_destroy(&dn->dn_struct_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
129 mutex_destroy(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
130 mutex_destroy(&dn->dn_dbufs_mtx);
8214
d7abf7c1f1c1 6747934 Some locking variables are not properly initialized or destroyed
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 7754
diff changeset
131 cv_destroy(&dn->dn_notxholds);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
132 refcount_destroy(&dn->dn_holds);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
133 refcount_destroy(&dn->dn_tx_holds);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
134 ASSERT(!list_link_active(&dn->dn_link));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
135
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
136 for (i = 0; i < TXG_SIZE; i++) {
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
137 ASSERT(!list_link_active(&dn->dn_dirty_link[i]));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
138 avl_destroy(&dn->dn_ranges[i]);
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
139 list_destroy(&dn->dn_dirty_records[i]);
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
140 ASSERT0(dn->dn_next_nblkptr[i]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
141 ASSERT0(dn->dn_next_nlevels[i]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
142 ASSERT0(dn->dn_next_indblkshift[i]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
143 ASSERT0(dn->dn_next_bonustype[i]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
144 ASSERT0(dn->dn_rm_spillblk[i]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
145 ASSERT0(dn->dn_next_bonuslen[i]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
146 ASSERT0(dn->dn_next_blksz[i]);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
147 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
148
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
149 ASSERT0(dn->dn_allocated_txg);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
150 ASSERT0(dn->dn_free_txg);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
151 ASSERT0(dn->dn_assigned_txg);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
152 ASSERT0(dn->dn_dirtyctx);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
153 ASSERT3P(dn->dn_dirtyctx_firstset, ==, NULL);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
154 ASSERT3P(dn->dn_bonus, ==, NULL);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
155 ASSERT(!dn->dn_have_spill);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
156 ASSERT3P(dn->dn_zio, ==, NULL);
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
157 ASSERT0(dn->dn_oldused);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
158 ASSERT0(dn->dn_oldflags);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
159 ASSERT0(dn->dn_olduid);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
160 ASSERT0(dn->dn_oldgid);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
161 ASSERT0(dn->dn_newuid);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
162 ASSERT0(dn->dn_newgid);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
163 ASSERT0(dn->dn_id_flags);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
164
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
165 ASSERT0(dn->dn_dbufs_count);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
166 list_destroy(&dn->dn_dbufs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
167 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
168
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
169 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
170 dnode_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
171 {
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
172 ASSERT(dnode_cache == NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
173 dnode_cache = kmem_cache_create("dnode_t",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
174 sizeof (dnode_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
175 0, dnode_cons, dnode_dest, NULL, NULL, NULL, 0);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
176 kmem_cache_set_move(dnode_cache, dnode_move);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
177 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
178
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
179 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
180 dnode_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
181 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
182 kmem_cache_destroy(dnode_cache);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
183 dnode_cache = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
184 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
185
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
186
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
187 #ifdef ZFS_DEBUG
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
188 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
189 dnode_verify(dnode_t *dn)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
190 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
191 int drop_struct_lock = FALSE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
192
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
193 ASSERT(dn->dn_phys);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
194 ASSERT(dn->dn_objset);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
195 ASSERT(dn->dn_handle->dnh_dnode == dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
196
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12684
diff changeset
197 ASSERT(DMU_OT_IS_VALID(dn->dn_phys->dn_type));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
198
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
199 if (!(zfs_flags & ZFS_DEBUG_DNODE_VERIFY))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
200 return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
201
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
202 if (!RW_WRITE_HELD(&dn->dn_struct_rwlock)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
203 rw_enter(&dn->dn_struct_rwlock, RW_READER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
204 drop_struct_lock = TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
205 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
206 if (dn->dn_phys->dn_type != DMU_OT_NONE || dn->dn_allocated_txg != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
207 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
208 ASSERT3U(dn->dn_indblkshift, >=, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
209 ASSERT3U(dn->dn_indblkshift, <=, SPA_MAXBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
210 if (dn->dn_datablkshift) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
211 ASSERT3U(dn->dn_datablkshift, >=, SPA_MINBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
212 ASSERT3U(dn->dn_datablkshift, <=, SPA_MAXBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
213 ASSERT3U(1<<dn->dn_datablkshift, ==, dn->dn_datablksz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
214 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
215 ASSERT3U(dn->dn_nlevels, <=, 30);
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12684
diff changeset
216 ASSERT(DMU_OT_IS_VALID(dn->dn_type));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
217 ASSERT3U(dn->dn_nblkptr, >=, 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
218 ASSERT3U(dn->dn_nblkptr, <=, DN_MAX_NBLKPTR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
219 ASSERT3U(dn->dn_bonuslen, <=, DN_MAX_BONUSLEN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
220 ASSERT3U(dn->dn_datablksz, ==,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
221 dn->dn_datablkszsec << SPA_MINBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
222 ASSERT3U(ISP2(dn->dn_datablksz), ==, dn->dn_datablkshift != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
223 ASSERT3U((dn->dn_nblkptr - 1) * sizeof (blkptr_t) +
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
224 dn->dn_bonuslen, <=, DN_MAX_BONUSLEN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
225 for (i = 0; i < TXG_SIZE; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
226 ASSERT3U(dn->dn_next_nlevels[i], <=, dn->dn_nlevels);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
227 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
228 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
229 if (dn->dn_phys->dn_type != DMU_OT_NONE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
230 ASSERT3U(dn->dn_phys->dn_nlevels, <=, dn->dn_nlevels);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
231 ASSERT(DMU_OBJECT_IS_SPECIAL(dn->dn_object) || dn->dn_dbuf != NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
232 if (dn->dn_dbuf != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
233 ASSERT3P(dn->dn_phys, ==,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
234 (dnode_phys_t *)dn->dn_dbuf->db.db_data +
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
235 (dn->dn_object % (dn->dn_dbuf->db.db_size >> DNODE_SHIFT)));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
236 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
237 if (drop_struct_lock)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
238 rw_exit(&dn->dn_struct_rwlock);
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
239 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
240 #endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
241
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
242 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
243 dnode_byteswap(dnode_phys_t *dnp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
244 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
245 uint64_t *buf64 = (void*)&dnp->dn_blkptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
246 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
247
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
248 if (dnp->dn_type == DMU_OT_NONE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
249 bzero(dnp, sizeof (dnode_phys_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
250 return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
251 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
252
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
253 dnp->dn_datablkszsec = BSWAP_16(dnp->dn_datablkszsec);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
254 dnp->dn_bonuslen = BSWAP_16(dnp->dn_bonuslen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
255 dnp->dn_maxblkid = BSWAP_64(dnp->dn_maxblkid);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
256 dnp->dn_used = BSWAP_64(dnp->dn_used);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
257
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
258 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
259 * dn_nblkptr is only one byte, so it's OK to read it in either
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
260 * byte order. We can't read dn_bouslen.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
261 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
262 ASSERT(dnp->dn_indblkshift <= SPA_MAXBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
263 ASSERT(dnp->dn_nblkptr <= DN_MAX_NBLKPTR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
264 for (i = 0; i < dnp->dn_nblkptr * sizeof (blkptr_t)/8; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
265 buf64[i] = BSWAP_64(buf64[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
266
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
267 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
268 * OK to check dn_bonuslen for zero, because it won't matter if
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
269 * we have the wrong byte order. This is necessary because the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
270 * dnode dnode is smaller than a regular dnode.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
271 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
272 if (dnp->dn_bonuslen != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
273 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
274 * Note that the bonus length calculated here may be
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
275 * longer than the actual bonus buffer. This is because
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
276 * we always put the bonus buffer after the last block
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
277 * pointer (instead of packing it against the end of the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
278 * dnode buffer).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
279 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
280 int off = (dnp->dn_nblkptr-1) * sizeof (blkptr_t);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
281 size_t len = DN_MAX_BONUSLEN - off;
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12684
diff changeset
282 ASSERT(DMU_OT_IS_VALID(dnp->dn_bonustype));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12684
diff changeset
283 dmu_object_byteswap_t byteswap =
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12684
diff changeset
284 DMU_OT_BYTESWAP(dnp->dn_bonustype);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12684
diff changeset
285 dmu_ot_byteswap[byteswap].ob_func(dnp->dn_bonus + off, len);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
286 }
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
287
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
288 /* Swap SPILL block if we have one */
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
289 if (dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
290 byteswap_uint64_array(&dnp->dn_spill, sizeof (blkptr_t));
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
291
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
292 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
293
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
294 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
295 dnode_buf_byteswap(void *vbuf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
296 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
297 dnode_phys_t *buf = vbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
298 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
299
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
300 ASSERT3U(sizeof (dnode_phys_t), ==, (1<<DNODE_SHIFT));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
301 ASSERT((size & (sizeof (dnode_phys_t)-1)) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
302
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
303 size >>= DNODE_SHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
304 for (i = 0; i < size; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
305 dnode_byteswap(buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
306 buf++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
307 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
308 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
309
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
310 static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
311 free_range_compar(const void *node1, const void *node2)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
312 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
313 const free_range_t *rp1 = node1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
314 const free_range_t *rp2 = node2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
315
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
316 if (rp1->fr_blkid < rp2->fr_blkid)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
317 return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
318 else if (rp1->fr_blkid > rp2->fr_blkid)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
319 return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
320 else return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
321 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
322
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
323 void
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
324 dnode_setbonuslen(dnode_t *dn, int newsize, dmu_tx_t *tx)
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
325 {
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
326 ASSERT3U(refcount_count(&dn->dn_holds), >=, 1);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
327
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
328 dnode_setdirty(dn, tx);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
329 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
330 ASSERT3U(newsize, <=, DN_MAX_BONUSLEN -
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
331 (dn->dn_nblkptr-1) * sizeof (blkptr_t));
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
332 dn->dn_bonuslen = newsize;
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
333 if (newsize == 0)
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
334 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = DN_ZERO_BONUSLEN;
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
335 else
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
336 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = dn->dn_bonuslen;
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
337 rw_exit(&dn->dn_struct_rwlock);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
338 }
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
339
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
340 void
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
341 dnode_setbonus_type(dnode_t *dn, dmu_object_type_t newtype, dmu_tx_t *tx)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
342 {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
343 ASSERT3U(refcount_count(&dn->dn_holds), >=, 1);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
344 dnode_setdirty(dn, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
345 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
346 dn->dn_bonustype = newtype;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
347 dn->dn_next_bonustype[tx->tx_txg & TXG_MASK] = dn->dn_bonustype;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
348 rw_exit(&dn->dn_struct_rwlock);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
349 }
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
350
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
351 void
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
352 dnode_rm_spill(dnode_t *dn, dmu_tx_t *tx)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
353 {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
354 ASSERT3U(refcount_count(&dn->dn_holds), >=, 1);
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11958
diff changeset
355 ASSERT(RW_WRITE_HELD(&dn->dn_struct_rwlock));
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
356 dnode_setdirty(dn, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
357 dn->dn_rm_spillblk[tx->tx_txg&TXG_MASK] = DN_KILL_SPILLBLK;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
358 dn->dn_have_spill = B_FALSE;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
359 }
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
360
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
361 static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
362 dnode_setdblksz(dnode_t *dn, int size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
363 {
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
364 ASSERT0(P2PHASE(size, SPA_MINBLOCKSIZE));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
365 ASSERT3U(size, <=, SPA_MAXBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
366 ASSERT3U(size, >=, SPA_MINBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
367 ASSERT3U(size >> SPA_MINBLOCKSHIFT, <,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
368 1<<(sizeof (dn->dn_phys->dn_datablkszsec) * 8));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
369 dn->dn_datablksz = size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
370 dn->dn_datablkszsec = size >> SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
371 dn->dn_datablkshift = ISP2(size) ? highbit(size - 1) : 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
372 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
373
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
374 static dnode_t *
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9950
diff changeset
375 dnode_create(objset_t *os, dnode_phys_t *dnp, dmu_buf_impl_t *db,
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
376 uint64_t object, dnode_handle_t *dnh)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
377 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
378 dnode_t *dn = kmem_cache_alloc(dnode_cache, KM_SLEEP);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
379
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
380 ASSERT(!POINTER_IS_VALID(dn->dn_objset));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
381 dn->dn_moved = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
382
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
383 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
384 * Defer setting dn_objset until the dnode is ready to be a candidate
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
385 * for the dnode_move() callback.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
386 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
387 dn->dn_object = object;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
388 dn->dn_dbuf = db;
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
389 dn->dn_handle = dnh;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
390 dn->dn_phys = dnp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
391
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
392 if (dnp->dn_datablkszsec) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
393 dnode_setdblksz(dn, dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
394 } else {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
395 dn->dn_datablksz = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
396 dn->dn_datablkszsec = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
397 dn->dn_datablkshift = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
398 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
399 dn->dn_indblkshift = dnp->dn_indblkshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
400 dn->dn_nlevels = dnp->dn_nlevels;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
401 dn->dn_type = dnp->dn_type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
402 dn->dn_nblkptr = dnp->dn_nblkptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
403 dn->dn_checksum = dnp->dn_checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
404 dn->dn_compress = dnp->dn_compress;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
405 dn->dn_bonustype = dnp->dn_bonustype;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
406 dn->dn_bonuslen = dnp->dn_bonuslen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
407 dn->dn_maxblkid = dnp->dn_maxblkid;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
408 dn->dn_have_spill = ((dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) != 0);
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11958
diff changeset
409 dn->dn_id_flags = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
410
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
411 dmu_zfetch_init(&dn->dn_zfetch, dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
412
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12684
diff changeset
413 ASSERT(DMU_OT_IS_VALID(dn->dn_phys->dn_type));
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
414
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
415 mutex_enter(&os->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
416 list_insert_head(&os->os_dnodes, dn);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
417 membar_producer();
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
418 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
419 * Everything else must be valid before assigning dn_objset makes the
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
420 * dnode eligible for dnode_move().
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
421 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
422 dn->dn_objset = os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
423 mutex_exit(&os->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
424
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8214
diff changeset
425 arc_space_consume(sizeof (dnode_t), ARC_SPACE_OTHER);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
426 return (dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
427 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
428
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
429 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
430 * Caller must be holding the dnode handle, which is released upon return.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
431 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
432 static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
433 dnode_destroy(dnode_t *dn)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
434 {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9950
diff changeset
435 objset_t *os = dn->dn_objset;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
436
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
437 ASSERT((dn->dn_id_flags & DN_ID_NEW_EXIST) == 0);
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2445
diff changeset
438
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
439 mutex_enter(&os->os_lock);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
440 POINTER_INVALIDATE(&dn->dn_objset);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
441 list_remove(&os->os_dnodes, dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
442 mutex_exit(&os->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
443
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
444 /* the dnode can no longer move, so we can release the handle */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
445 zrl_remove(&dn->dn_handle->dnh_zrlock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
446
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
447 dn->dn_allocated_txg = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
448 dn->dn_free_txg = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
449 dn->dn_assigned_txg = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
450
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
451 dn->dn_dirtyctx = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
452 if (dn->dn_dirtyctx_firstset != NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
453 kmem_free(dn->dn_dirtyctx_firstset, 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
454 dn->dn_dirtyctx_firstset = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
455 }
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
456 if (dn->dn_bonus != NULL) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
457 mutex_enter(&dn->dn_bonus->db_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
458 dbuf_evict(dn->dn_bonus);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
459 dn->dn_bonus = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
460 }
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
461 dn->dn_zio = NULL;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
462
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
463 dn->dn_have_spill = B_FALSE;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
464 dn->dn_oldused = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
465 dn->dn_oldflags = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
466 dn->dn_olduid = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
467 dn->dn_oldgid = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
468 dn->dn_newuid = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
469 dn->dn_newgid = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
470 dn->dn_id_flags = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
471
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
472 dmu_zfetch_rele(&dn->dn_zfetch);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
473 kmem_cache_free(dnode_cache, dn);
8582
df9361868dbe 6748019 ARC/L2ARC metadata accounting for arc_size
Brendan Gregg - Sun Microsystems <Brendan.Gregg@Sun.COM>
parents: 8214
diff changeset
474 arc_space_return(sizeof (dnode_t), ARC_SPACE_OTHER);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
475 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
476
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
477 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
478 dnode_allocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, int ibs,
1599
b2940ec637b4 6397222 corrupt microzap object
ahrens
parents: 1596
diff changeset
479 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
480 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
481 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
482
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
483 if (blocksize == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
484 blocksize = 1 << zfs_default_bs;
1402
bfaffef2800c 6382360 dnode_setblksz assertion failed
ahrens
parents: 873
diff changeset
485 else if (blocksize > SPA_MAXBLOCKSIZE)
bfaffef2800c 6382360 dnode_setblksz assertion failed
ahrens
parents: 873
diff changeset
486 blocksize = SPA_MAXBLOCKSIZE;
bfaffef2800c 6382360 dnode_setblksz assertion failed
ahrens
parents: 873
diff changeset
487 else
bfaffef2800c 6382360 dnode_setblksz assertion failed
ahrens
parents: 873
diff changeset
488 blocksize = P2ROUNDUP(blocksize, SPA_MINBLOCKSIZE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
489
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
490 if (ibs == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
491 ibs = zfs_default_ibs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
492
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
493 ibs = MIN(MAX(ibs, DN_MIN_INDBLKSHIFT), DN_MAX_INDBLKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
494
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
495 dprintf("os=%p obj=%llu txg=%llu blocksize=%d ibs=%d\n", dn->dn_objset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
496 dn->dn_object, tx->tx_txg, blocksize, ibs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
497
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
498 ASSERT(dn->dn_type == DMU_OT_NONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
499 ASSERT(bcmp(dn->dn_phys, &dnode_phys_zero, sizeof (dnode_phys_t)) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
500 ASSERT(dn->dn_phys->dn_type == DMU_OT_NONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
501 ASSERT(ot != DMU_OT_NONE);
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12684
diff changeset
502 ASSERT(DMU_OT_IS_VALID(ot));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
503 ASSERT((bonustype == DMU_OT_NONE && bonuslen == 0) ||
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
504 (bonustype == DMU_OT_SA && bonuslen == 0) ||
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
505 (bonustype != DMU_OT_NONE && bonuslen != 0));
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12684
diff changeset
506 ASSERT(DMU_OT_IS_VALID(bonustype));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
507 ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
508 ASSERT(dn->dn_type == DMU_OT_NONE);
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
509 ASSERT0(dn->dn_maxblkid);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
510 ASSERT0(dn->dn_allocated_txg);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
511 ASSERT0(dn->dn_assigned_txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
512 ASSERT(refcount_is_zero(&dn->dn_tx_holds));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
513 ASSERT3U(refcount_count(&dn->dn_holds), <=, 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
514 ASSERT3P(list_head(&dn->dn_dbufs), ==, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
515
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
516 for (i = 0; i < TXG_SIZE; i++) {
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
517 ASSERT0(dn->dn_next_nblkptr[i]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
518 ASSERT0(dn->dn_next_nlevels[i]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
519 ASSERT0(dn->dn_next_indblkshift[i]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
520 ASSERT0(dn->dn_next_bonuslen[i]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
521 ASSERT0(dn->dn_next_bonustype[i]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
522 ASSERT0(dn->dn_rm_spillblk[i]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
523 ASSERT0(dn->dn_next_blksz[i]);
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
524 ASSERT(!list_link_active(&dn->dn_dirty_link[i]));
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
525 ASSERT3P(list_head(&dn->dn_dirty_records[i]), ==, NULL);
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
526 ASSERT0(avl_numnodes(&dn->dn_ranges[i]));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
527 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
528
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
529 dn->dn_type = ot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
530 dnode_setdblksz(dn, blocksize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
531 dn->dn_indblkshift = ibs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
532 dn->dn_nlevels = 1;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
533 if (bonustype == DMU_OT_SA) /* Maximize bonus space for SA */
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
534 dn->dn_nblkptr = 1;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
535 else
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
536 dn->dn_nblkptr = 1 +
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
537 ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
538 dn->dn_bonustype = bonustype;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
539 dn->dn_bonuslen = bonuslen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
540 dn->dn_checksum = ZIO_CHECKSUM_INHERIT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
541 dn->dn_compress = ZIO_COMPRESS_INHERIT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
542 dn->dn_dirtyctx = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
543
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
544 dn->dn_free_txg = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
545 if (dn->dn_dirtyctx_firstset) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
546 kmem_free(dn->dn_dirtyctx_firstset, 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
547 dn->dn_dirtyctx_firstset = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
548 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
549
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
550 dn->dn_allocated_txg = tx->tx_txg;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
551 dn->dn_id_flags = 0;
1599
b2940ec637b4 6397222 corrupt microzap object
ahrens
parents: 1596
diff changeset
552
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
553 dnode_setdirty(dn, tx);
1599
b2940ec637b4 6397222 corrupt microzap object
ahrens
parents: 1596
diff changeset
554 dn->dn_next_indblkshift[tx->tx_txg & TXG_MASK] = ibs;
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
555 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = dn->dn_bonuslen;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
556 dn->dn_next_bonustype[tx->tx_txg & TXG_MASK] = dn->dn_bonustype;
1599
b2940ec637b4 6397222 corrupt microzap object
ahrens
parents: 1596
diff changeset
557 dn->dn_next_blksz[tx->tx_txg & TXG_MASK] = dn->dn_datablksz;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
558 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
559
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
560 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
561 dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
562 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
563 {
8986
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8644
diff changeset
564 int nblkptr;
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
565
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
566 ASSERT3U(blocksize, >=, SPA_MINBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
567 ASSERT3U(blocksize, <=, SPA_MAXBLOCKSIZE);
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
568 ASSERT0(blocksize % SPA_MINBLOCKSIZE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
569 ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT || dmu_tx_private_ok(tx));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
570 ASSERT(tx->tx_txg != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
571 ASSERT((bonustype == DMU_OT_NONE && bonuslen == 0) ||
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11958
diff changeset
572 (bonustype != DMU_OT_NONE && bonuslen != 0) ||
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11958
diff changeset
573 (bonustype == DMU_OT_SA && bonuslen == 0));
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12684
diff changeset
574 ASSERT(DMU_OT_IS_VALID(bonustype));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
575 ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN);
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
576
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
577 /* clean up any unreferenced dbufs */
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
578 dnode_evict_dbufs(dn);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
579
12432
222dd376dd6c 6952522 elpaso panics: assertion failed: refcount_is_zero(&dn->dn_holds), file: ../../common/fs/zfs/dnode.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12411
diff changeset
580 dn->dn_id_flags = 0;
222dd376dd6c 6952522 elpaso panics: assertion failed: refcount_is_zero(&dn->dn_holds), file: ../../common/fs/zfs/dnode.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12411
diff changeset
581
8986
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8644
diff changeset
582 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8644
diff changeset
583 dnode_setdirty(dn, tx);
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8644
diff changeset
584 if (dn->dn_datablksz != blocksize) {
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8644
diff changeset
585 /* change blocksize */
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8644
diff changeset
586 ASSERT(dn->dn_maxblkid == 0 &&
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8644
diff changeset
587 (BP_IS_HOLE(&dn->dn_phys->dn_blkptr[0]) ||
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8644
diff changeset
588 dnode_block_freed(dn, 0)));
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8644
diff changeset
589 dnode_setdblksz(dn, blocksize);
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8644
diff changeset
590 dn->dn_next_blksz[tx->tx_txg&TXG_MASK] = blocksize;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
591 }
8986
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8644
diff changeset
592 if (dn->dn_bonuslen != bonuslen)
45c289aff7c9 6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8644
diff changeset
593 dn->dn_next_bonuslen[tx->tx_txg&TXG_MASK] = bonuslen;
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11958
diff changeset
594
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11958
diff changeset
595 if (bonustype == DMU_OT_SA) /* Maximize bonus space for SA */
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11958
diff changeset
596 nblkptr = 1;
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11958
diff changeset
597 else
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11958
diff changeset
598 nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
599 if (dn->dn_bonustype != bonustype)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
600 dn->dn_next_bonustype[tx->tx_txg&TXG_MASK] = bonustype;
8644
10534c530688 6793373 assertion failed in dnode_reallocate: dn_nblkptr >= old_nblkptr
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8582
diff changeset
601 if (dn->dn_nblkptr != nblkptr)
10534c530688 6793373 assertion failed in dnode_reallocate: dn_nblkptr >= old_nblkptr
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8582
diff changeset
602 dn->dn_next_nblkptr[tx->tx_txg&TXG_MASK] = nblkptr;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
603 if (dn->dn_phys->dn_flags & DNODE_FLAG_SPILL_BLKPTR) {
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11958
diff changeset
604 dbuf_rm_spill(dn, tx);
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11958
diff changeset
605 dnode_rm_spill(dn, tx);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
606 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
607 rw_exit(&dn->dn_struct_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
608
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
609 /* change type */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
610 dn->dn_type = ot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
611
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
612 /* change bonus size and type */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
613 mutex_enter(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
614 dn->dn_bonustype = bonustype;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
615 dn->dn_bonuslen = bonuslen;
8644
10534c530688 6793373 assertion failed in dnode_reallocate: dn_nblkptr >= old_nblkptr
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8582
diff changeset
616 dn->dn_nblkptr = nblkptr;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
617 dn->dn_checksum = ZIO_CHECKSUM_INHERIT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
618 dn->dn_compress = ZIO_COMPRESS_INHERIT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
619 ASSERT3U(dn->dn_nblkptr, <=, DN_MAX_NBLKPTR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
620
8644
10534c530688 6793373 assertion failed in dnode_reallocate: dn_nblkptr >= old_nblkptr
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8582
diff changeset
621 /* fix up the bonus db_size */
10534c530688 6793373 assertion failed in dnode_reallocate: dn_nblkptr >= old_nblkptr
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8582
diff changeset
622 if (dn->dn_bonus) {
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
623 dn->dn_bonus->db.db_size =
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
624 DN_MAX_BONUSLEN - (dn->dn_nblkptr-1) * sizeof (blkptr_t);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
625 ASSERT(dn->dn_bonuslen <= dn->dn_bonus->db.db_size);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
626 }
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 3025
diff changeset
627
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
628 dn->dn_allocated_txg = tx->tx_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
629 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
630 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
631
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
632 #ifdef DNODE_STATS
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
633 static struct {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
634 uint64_t dms_dnode_invalid;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
635 uint64_t dms_dnode_recheck1;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
636 uint64_t dms_dnode_recheck2;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
637 uint64_t dms_dnode_special;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
638 uint64_t dms_dnode_handle;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
639 uint64_t dms_dnode_rwlock;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
640 uint64_t dms_dnode_active;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
641 } dnode_move_stats;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
642 #endif /* DNODE_STATS */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
643
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
644 static void
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
645 dnode_move_impl(dnode_t *odn, dnode_t *ndn)
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
646 {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
647 int i;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
648
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
649 ASSERT(!RW_LOCK_HELD(&odn->dn_struct_rwlock));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
650 ASSERT(MUTEX_NOT_HELD(&odn->dn_mtx));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
651 ASSERT(MUTEX_NOT_HELD(&odn->dn_dbufs_mtx));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
652 ASSERT(!RW_LOCK_HELD(&odn->dn_zfetch.zf_rwlock));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
653
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
654 /* Copy fields. */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
655 ndn->dn_objset = odn->dn_objset;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
656 ndn->dn_object = odn->dn_object;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
657 ndn->dn_dbuf = odn->dn_dbuf;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
658 ndn->dn_handle = odn->dn_handle;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
659 ndn->dn_phys = odn->dn_phys;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
660 ndn->dn_type = odn->dn_type;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
661 ndn->dn_bonuslen = odn->dn_bonuslen;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
662 ndn->dn_bonustype = odn->dn_bonustype;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
663 ndn->dn_nblkptr = odn->dn_nblkptr;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
664 ndn->dn_checksum = odn->dn_checksum;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
665 ndn->dn_compress = odn->dn_compress;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
666 ndn->dn_nlevels = odn->dn_nlevels;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
667 ndn->dn_indblkshift = odn->dn_indblkshift;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
668 ndn->dn_datablkshift = odn->dn_datablkshift;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
669 ndn->dn_datablkszsec = odn->dn_datablkszsec;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
670 ndn->dn_datablksz = odn->dn_datablksz;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
671 ndn->dn_maxblkid = odn->dn_maxblkid;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
672 bcopy(&odn->dn_next_nblkptr[0], &ndn->dn_next_nblkptr[0],
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
673 sizeof (odn->dn_next_nblkptr));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
674 bcopy(&odn->dn_next_nlevels[0], &ndn->dn_next_nlevels[0],
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
675 sizeof (odn->dn_next_nlevels));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
676 bcopy(&odn->dn_next_indblkshift[0], &ndn->dn_next_indblkshift[0],
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
677 sizeof (odn->dn_next_indblkshift));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
678 bcopy(&odn->dn_next_bonustype[0], &ndn->dn_next_bonustype[0],
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
679 sizeof (odn->dn_next_bonustype));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
680 bcopy(&odn->dn_rm_spillblk[0], &ndn->dn_rm_spillblk[0],
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
681 sizeof (odn->dn_rm_spillblk));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
682 bcopy(&odn->dn_next_bonuslen[0], &ndn->dn_next_bonuslen[0],
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
683 sizeof (odn->dn_next_bonuslen));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
684 bcopy(&odn->dn_next_blksz[0], &ndn->dn_next_blksz[0],
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
685 sizeof (odn->dn_next_blksz));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
686 for (i = 0; i < TXG_SIZE; i++) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
687 list_move_tail(&ndn->dn_dirty_records[i],
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
688 &odn->dn_dirty_records[i]);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
689 }
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
690 bcopy(&odn->dn_ranges[0], &ndn->dn_ranges[0], sizeof (odn->dn_ranges));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
691 ndn->dn_allocated_txg = odn->dn_allocated_txg;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
692 ndn->dn_free_txg = odn->dn_free_txg;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
693 ndn->dn_assigned_txg = odn->dn_assigned_txg;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
694 ndn->dn_dirtyctx = odn->dn_dirtyctx;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
695 ndn->dn_dirtyctx_firstset = odn->dn_dirtyctx_firstset;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
696 ASSERT(refcount_count(&odn->dn_tx_holds) == 0);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
697 refcount_transfer(&ndn->dn_holds, &odn->dn_holds);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
698 ASSERT(list_is_empty(&ndn->dn_dbufs));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
699 list_move_tail(&ndn->dn_dbufs, &odn->dn_dbufs);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
700 ndn->dn_dbufs_count = odn->dn_dbufs_count;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
701 ndn->dn_bonus = odn->dn_bonus;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
702 ndn->dn_have_spill = odn->dn_have_spill;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
703 ndn->dn_zio = odn->dn_zio;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
704 ndn->dn_oldused = odn->dn_oldused;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
705 ndn->dn_oldflags = odn->dn_oldflags;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
706 ndn->dn_olduid = odn->dn_olduid;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
707 ndn->dn_oldgid = odn->dn_oldgid;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
708 ndn->dn_newuid = odn->dn_newuid;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
709 ndn->dn_newgid = odn->dn_newgid;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
710 ndn->dn_id_flags = odn->dn_id_flags;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
711 dmu_zfetch_init(&ndn->dn_zfetch, NULL);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
712 list_move_tail(&ndn->dn_zfetch.zf_stream, &odn->dn_zfetch.zf_stream);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
713 ndn->dn_zfetch.zf_dnode = odn->dn_zfetch.zf_dnode;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
714 ndn->dn_zfetch.zf_stream_cnt = odn->dn_zfetch.zf_stream_cnt;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
715 ndn->dn_zfetch.zf_alloc_fail = odn->dn_zfetch.zf_alloc_fail;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
716
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
717 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
718 * Update back pointers. Updating the handle fixes the back pointer of
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
719 * every descendant dbuf as well as the bonus dbuf.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
720 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
721 ASSERT(ndn->dn_handle->dnh_dnode == odn);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
722 ndn->dn_handle->dnh_dnode = ndn;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
723 if (ndn->dn_zfetch.zf_dnode == odn) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
724 ndn->dn_zfetch.zf_dnode = ndn;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
725 }
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
726
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
727 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
728 * Invalidate the original dnode by clearing all of its back pointers.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
729 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
730 odn->dn_dbuf = NULL;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
731 odn->dn_handle = NULL;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
732 list_create(&odn->dn_dbufs, sizeof (dmu_buf_impl_t),
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
733 offsetof(dmu_buf_impl_t, db_link));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
734 odn->dn_dbufs_count = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
735 odn->dn_bonus = NULL;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
736 odn->dn_zfetch.zf_dnode = NULL;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
737
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
738 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
739 * Set the low bit of the objset pointer to ensure that dnode_move()
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
740 * recognizes the dnode as invalid in any subsequent callback.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
741 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
742 POINTER_INVALIDATE(&odn->dn_objset);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
743
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
744 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
745 * Satisfy the destructor.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
746 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
747 for (i = 0; i < TXG_SIZE; i++) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
748 list_create(&odn->dn_dirty_records[i],
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
749 sizeof (dbuf_dirty_record_t),
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
750 offsetof(dbuf_dirty_record_t, dr_dirty_node));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
751 odn->dn_ranges[i].avl_root = NULL;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
752 odn->dn_ranges[i].avl_numnodes = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
753 odn->dn_next_nlevels[i] = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
754 odn->dn_next_indblkshift[i] = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
755 odn->dn_next_bonustype[i] = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
756 odn->dn_rm_spillblk[i] = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
757 odn->dn_next_bonuslen[i] = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
758 odn->dn_next_blksz[i] = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
759 }
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
760 odn->dn_allocated_txg = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
761 odn->dn_free_txg = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
762 odn->dn_assigned_txg = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
763 odn->dn_dirtyctx = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
764 odn->dn_dirtyctx_firstset = NULL;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
765 odn->dn_have_spill = B_FALSE;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
766 odn->dn_zio = NULL;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
767 odn->dn_oldused = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
768 odn->dn_oldflags = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
769 odn->dn_olduid = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
770 odn->dn_oldgid = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
771 odn->dn_newuid = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
772 odn->dn_newgid = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
773 odn->dn_id_flags = 0;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
774
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
775 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
776 * Mark the dnode.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
777 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
778 ndn->dn_moved = 1;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
779 odn->dn_moved = (uint8_t)-1;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
780 }
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
781
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
782 #ifdef _KERNEL
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
783 /*ARGSUSED*/
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
784 static kmem_cbrc_t
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
785 dnode_move(void *buf, void *newbuf, size_t size, void *arg)
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
786 {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
787 dnode_t *odn = buf, *ndn = newbuf;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
788 objset_t *os;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
789 int64_t refcount;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
790 uint32_t dbufs;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
791
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
792 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
793 * The dnode is on the objset's list of known dnodes if the objset
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
794 * pointer is valid. We set the low bit of the objset pointer when
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
795 * freeing the dnode to invalidate it, and the memory patterns written
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
796 * by kmem (baddcafe and deadbeef) set at least one of the two low bits.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
797 * A newly created dnode sets the objset pointer last of all to indicate
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
798 * that the dnode is known and in a valid state to be moved by this
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
799 * function.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
800 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
801 os = odn->dn_objset;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
802 if (!POINTER_IS_VALID(os)) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
803 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_invalid);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
804 return (KMEM_CBRC_DONT_KNOW);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
805 }
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
806
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
807 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
808 * Ensure that the objset does not go away during the move.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
809 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
810 rw_enter(&os_lock, RW_WRITER);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
811 if (os != odn->dn_objset) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
812 rw_exit(&os_lock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
813 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_recheck1);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
814 return (KMEM_CBRC_DONT_KNOW);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
815 }
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
816
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
817 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
818 * If the dnode is still valid, then so is the objset. We know that no
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
819 * valid objset can be freed while we hold os_lock, so we can safely
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
820 * ensure that the objset remains in use.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
821 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
822 mutex_enter(&os->os_lock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
823
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
824 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
825 * Recheck the objset pointer in case the dnode was removed just before
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
826 * acquiring the lock.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
827 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
828 if (os != odn->dn_objset) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
829 mutex_exit(&os->os_lock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
830 rw_exit(&os_lock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
831 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_recheck2);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
832 return (KMEM_CBRC_DONT_KNOW);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
833 }
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
834
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
835 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
836 * At this point we know that as long as we hold os->os_lock, the dnode
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
837 * cannot be freed and fields within the dnode can be safely accessed.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
838 * The objset listing this dnode cannot go away as long as this dnode is
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
839 * on its list.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
840 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
841 rw_exit(&os_lock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
842 if (DMU_OBJECT_IS_SPECIAL(odn->dn_object)) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
843 mutex_exit(&os->os_lock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
844 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_special);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
845 return (KMEM_CBRC_NO);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
846 }
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
847 ASSERT(odn->dn_dbuf != NULL); /* only "special" dnodes have no parent */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
848
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
849 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
850 * Lock the dnode handle to prevent the dnode from obtaining any new
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
851 * holds. This also prevents the descendant dbufs and the bonus dbuf
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
852 * from accessing the dnode, so that we can discount their holds. The
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
853 * handle is safe to access because we know that while the dnode cannot
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
854 * go away, neither can its handle. Once we hold dnh_zrlock, we can
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
855 * safely move any dnode referenced only by dbufs.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
856 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
857 if (!zrl_tryenter(&odn->dn_handle->dnh_zrlock)) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
858 mutex_exit(&os->os_lock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
859 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_handle);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
860 return (KMEM_CBRC_LATER);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
861 }
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
862
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
863 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
864 * Ensure a consistent view of the dnode's holds and the dnode's dbufs.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
865 * We need to guarantee that there is a hold for every dbuf in order to
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
866 * determine whether the dnode is actively referenced. Falsely matching
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
867 * a dbuf to an active hold would lead to an unsafe move. It's possible
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
868 * that a thread already having an active dnode hold is about to add a
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
869 * dbuf, and we can't compare hold and dbuf counts while the add is in
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
870 * progress.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
871 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
872 if (!rw_tryenter(&odn->dn_struct_rwlock, RW_WRITER)) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
873 zrl_exit(&odn->dn_handle->dnh_zrlock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
874 mutex_exit(&os->os_lock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
875 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_rwlock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
876 return (KMEM_CBRC_LATER);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
877 }
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
878
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
879 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
880 * A dbuf may be removed (evicted) without an active dnode hold. In that
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
881 * case, the dbuf count is decremented under the handle lock before the
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
882 * dbuf's hold is released. This order ensures that if we count the hold
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
883 * after the dbuf is removed but before its hold is released, we will
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
884 * treat the unmatched hold as active and exit safely. If we count the
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
885 * hold before the dbuf is removed, the hold is discounted, and the
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
886 * removal is blocked until the move completes.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
887 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
888 refcount = refcount_count(&odn->dn_holds);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
889 ASSERT(refcount >= 0);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
890 dbufs = odn->dn_dbufs_count;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
891
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
892 /* We can't have more dbufs than dnode holds. */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
893 ASSERT3U(dbufs, <=, refcount);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
894 DTRACE_PROBE3(dnode__move, dnode_t *, odn, int64_t, refcount,
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
895 uint32_t, dbufs);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
896
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
897 if (refcount > dbufs) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
898 rw_exit(&odn->dn_struct_rwlock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
899 zrl_exit(&odn->dn_handle->dnh_zrlock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
900 mutex_exit(&os->os_lock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
901 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_active);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
902 return (KMEM_CBRC_LATER);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
903 }
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
904
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
905 rw_exit(&odn->dn_struct_rwlock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
906
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
907 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
908 * At this point we know that anyone with a hold on the dnode is not
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
909 * actively referencing it. The dnode is known and in a valid state to
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
910 * move. We're holding the locks needed to execute the critical section.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
911 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
912 dnode_move_impl(odn, ndn);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
913
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
914 list_link_replace(&odn->dn_link, &ndn->dn_link);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
915 /* If the dnode was safe to move, the refcount cannot have changed. */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
916 ASSERT(refcount == refcount_count(&ndn->dn_holds));
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
917 ASSERT(dbufs == ndn->dn_dbufs_count);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
918 zrl_exit(&ndn->dn_handle->dnh_zrlock); /* handle has moved */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
919 mutex_exit(&os->os_lock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
920
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
921 return (KMEM_CBRC_YES);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
922 }
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
923 #endif /* _KERNEL */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
924
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
925 void
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
926 dnode_special_close(dnode_handle_t *dnh)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
927 {
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
928 dnode_t *dn = dnh->dnh_dnode;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
929
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
930 /*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
931 * Wait for final references to the dnode to clear. This can
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
932 * only happen if the arc is asyncronously evicting state that
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
933 * has a hold on this dnode while we are trying to evict this
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
934 * dnode.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
935 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
936 while (refcount_count(&dn->dn_holds) > 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
937 delay(1);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
938 zrl_add(&dnh->dnh_zrlock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
939 dnode_destroy(dn); /* implicit zrl_remove() */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
940 zrl_destroy(&dnh->dnh_zrlock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
941 dnh->dnh_dnode = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
942 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
943
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
944 dnode_t *
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
945 dnode_special_open(objset_t *os, dnode_phys_t *dnp, uint64_t object,
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
946 dnode_handle_t *dnh)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
947 {
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
948 dnode_t *dn = dnode_create(os, dnp, NULL, object, dnh);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
949 dnh->dnh_dnode = dn;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
950 zrl_init(&dnh->dnh_zrlock);
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
951 DNODE_VERIFY(dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
952 return (dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
953 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
954
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
955 static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
956 dnode_buf_pageout(dmu_buf_t *db, void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
957 {
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
958 dnode_children_t *children_dnodes = arg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
959 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
960 int epb = db->db_size >> DNODE_SHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
961
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
962 ASSERT(epb == children_dnodes->dnc_count);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
963
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
964 for (i = 0; i < epb; i++) {
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
965 dnode_handle_t *dnh = &children_dnodes->dnc_children[i];
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
966 dnode_t *dn;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
967
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
968 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
969 * The dnode handle lock guards against the dnode moving to
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
970 * another valid address, so there is no need here to guard
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
971 * against changes to or from NULL.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
972 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
973 if (dnh->dnh_dnode == NULL) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
974 zrl_destroy(&dnh->dnh_zrlock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
975 continue;
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
976 }
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
977
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
978 zrl_add(&dnh->dnh_zrlock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
979 dn = dnh->dnh_dnode;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
980 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
981 * If there are holds on this dnode, then there should
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
982 * be holds on the dnode's containing dbuf as well; thus
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
983 * it wouldn't be eligible for eviction and this function
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
984 * would not have been called.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
985 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
986 ASSERT(refcount_is_zero(&dn->dn_holds));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
987 ASSERT(refcount_is_zero(&dn->dn_tx_holds));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
988
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
989 dnode_destroy(dn); /* implicit zrl_remove() */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
990 zrl_destroy(&dnh->dnh_zrlock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
991 dnh->dnh_dnode = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
992 }
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
993 kmem_free(children_dnodes, sizeof (dnode_children_t) +
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
994 (epb - 1) * sizeof (dnode_handle_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
995 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
996
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
997 /*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
998 * errors:
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
999 * EINVAL - invalid object number.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1000 * EIO - i/o error.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1001 * succeeds even for free dnodes.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1002 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1003 int
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9950
diff changeset
1004 dnode_hold_impl(objset_t *os, uint64_t object, int flag,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1005 void *tag, dnode_t **dnp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1006 {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1007 int epb, idx, err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1008 int drop_struct_lock = FALSE;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1009 int type;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1010 uint64_t blk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1011 dnode_t *mdn, *dn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1012 dmu_buf_impl_t *db;
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1013 dnode_children_t *children_dnodes;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1014 dnode_handle_t *dnh;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1015
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7385
diff changeset
1016 /*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7385
diff changeset
1017 * If you are holding the spa config lock as writer, you shouldn't
11958
575ffe1e978d 6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents: 11935
diff changeset
1018 * be asking the DMU to do *anything* unless it's the root pool
575ffe1e978d 6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents: 11935
diff changeset
1019 * which may require us to read from the root filesystem while
575ffe1e978d 6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents: 11935
diff changeset
1020 * holding some (not all) of the locks as writer.
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7385
diff changeset
1021 */
11958
575ffe1e978d 6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents: 11935
diff changeset
1022 ASSERT(spa_config_held(os->os_spa, SCL_ALL, RW_WRITER) == 0 ||
575ffe1e978d 6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents: 11935
diff changeset
1023 (spa_is_root(os->os_spa) &&
12586
b118bbd65be9 6494473 ZFS needs a way to slow down resilvering
George Wilson <George.Wilson@Sun.COM>
parents: 12432
diff changeset
1024 spa_config_held(os->os_spa, SCL_STATE, RW_WRITER)));
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7385
diff changeset
1025
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1026 if (object == DMU_USERUSED_OBJECT || object == DMU_GROUPUSED_OBJECT) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1027 dn = (object == DMU_USERUSED_OBJECT) ?
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1028 DMU_USERUSED_DNODE(os) : DMU_GROUPUSED_DNODE(os);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1029 if (dn == NULL)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1030 return (ENOENT);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1031 type = dn->dn_type;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1032 if ((flag & DNODE_MUST_BE_ALLOCATED) && type == DMU_OT_NONE)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1033 return (ENOENT);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1034 if ((flag & DNODE_MUST_BE_FREE) && type != DMU_OT_NONE)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1035 return (EEXIST);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1036 DNODE_VERIFY(dn);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1037 (void) refcount_add(&dn->dn_holds, tag);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1038 *dnp = dn;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1039 return (0);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1040 }
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1041
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1042 if (object == 0 || object >= DN_MAX_OBJECT)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1043 return (EINVAL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1044
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1045 mdn = DMU_META_DNODE(os);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1046 ASSERT(mdn->dn_object == DMU_META_DNODE_OBJECT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1047
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
1048 DNODE_VERIFY(mdn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1049
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1050 if (!RW_WRITE_HELD(&mdn->dn_struct_rwlock)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1051 rw_enter(&mdn->dn_struct_rwlock, RW_READER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1052 drop_struct_lock = TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1053 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1054
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1055 blk = dbuf_whichblock(mdn, object * sizeof (dnode_phys_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1056
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1057 db = dbuf_hold(mdn, blk, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1058 if (drop_struct_lock)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1059 rw_exit(&mdn->dn_struct_rwlock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1060 if (db == NULL)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1061 return (EIO);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1062 err = dbuf_read(db, NULL, DB_RF_CANFAIL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1063 if (err) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1064 dbuf_rele(db, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1065 return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1066 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1067
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1068 ASSERT3U(db->db.db_size, >=, 1<<DNODE_SHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1069 epb = db->db.db_size >> DNODE_SHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1070
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1071 idx = object & (epb-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1072
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1073 ASSERT(DB_DNODE(db)->dn_type == DMU_OT_DNODE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1074 children_dnodes = dmu_buf_get_user(&db->db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1075 if (children_dnodes == NULL) {
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1076 int i;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1077 dnode_children_t *winner;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1078 children_dnodes = kmem_alloc(sizeof (dnode_children_t) +
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1079 (epb - 1) * sizeof (dnode_handle_t), KM_SLEEP);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1080 children_dnodes->dnc_count = epb;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1081 dnh = &children_dnodes->dnc_children[0];
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1082 for (i = 0; i < epb; i++) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1083 zrl_init(&dnh[i].dnh_zrlock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1084 dnh[i].dnh_dnode = NULL;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1085 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1086 if (winner = dmu_buf_set_user(&db->db, children_dnodes, NULL,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1087 dnode_buf_pageout)) {
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1088 kmem_free(children_dnodes, sizeof (dnode_children_t) +
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1089 (epb - 1) * sizeof (dnode_handle_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1090 children_dnodes = winner;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1091 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1092 }
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1093 ASSERT(children_dnodes->dnc_count == epb);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1094
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1095 dnh = &children_dnodes->dnc_children[idx];
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1096 zrl_add(&dnh->dnh_zrlock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1097 if ((dn = dnh->dnh_dnode) == NULL) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1098 dnode_phys_t *phys = (dnode_phys_t *)db->db.db_data+idx;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1099 dnode_t *winner;
4309
3dfde0f4662d 6542676 ARC needs to track meta-data memory overhead
maybee
parents: 3882
diff changeset
1100
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1101 dn = dnode_create(os, phys, db, object, dnh);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1102 winner = atomic_cas_ptr(&dnh->dnh_dnode, NULL, dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1103 if (winner != NULL) {
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1104 zrl_add(&dnh->dnh_zrlock);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1105 dnode_destroy(dn); /* implicit zrl_remove() */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1106 dn = winner;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1107 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1108 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1109
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1110 mutex_enter(&dn->dn_mtx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1111 type = dn->dn_type;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1112 if (dn->dn_free_txg ||
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1113 ((flag & DNODE_MUST_BE_ALLOCATED) && type == DMU_OT_NONE) ||
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1114 ((flag & DNODE_MUST_BE_FREE) &&
12432
222dd376dd6c 6952522 elpaso panics: assertion failed: refcount_is_zero(&dn->dn_holds), file: ../../common/fs/zfs/dnode.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12411
diff changeset
1115 (type != DMU_OT_NONE || !refcount_is_zero(&dn->dn_holds)))) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1116 mutex_exit(&dn->dn_mtx);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1117 zrl_remove(&dnh->dnh_zrlock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1118 dbuf_rele(db, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1119 return (type == DMU_OT_NONE ? ENOENT : EEXIST);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1120 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1121 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1122
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1123 if (refcount_add(&dn->dn_holds, tag) == 1)
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1124 dbuf_add_ref(db, dnh);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1125 /* Now we can rely on the hold to prevent the dnode from moving. */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1126 zrl_remove(&dnh->dnh_zrlock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1127
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
1128 DNODE_VERIFY(dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1129 ASSERT3P(dn->dn_dbuf, ==, db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1130 ASSERT3U(dn->dn_object, ==, object);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1131 dbuf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1132
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1133 *dnp = dn;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1134 return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1135 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1136
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1137 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1138 * Return held dnode if the object is allocated, NULL if not.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1139 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1140 int
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9950
diff changeset
1141 dnode_hold(objset_t *os, uint64_t object, void *tag, dnode_t **dnp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1142 {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1143 return (dnode_hold_impl(os, object, DNODE_MUST_BE_ALLOCATED, tag, dnp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1144 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1145
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1146 /*
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1147 * Can only add a reference if there is already at least one
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1148 * reference on the dnode. Returns FALSE if unable to add a
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1149 * new reference.
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1150 */
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1151 boolean_t
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1152 dnode_add_ref(dnode_t *dn, void *tag)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1153 {
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1154 mutex_enter(&dn->dn_mtx);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1155 if (refcount_is_zero(&dn->dn_holds)) {
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1156 mutex_exit(&dn->dn_mtx);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1157 return (FALSE);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1158 }
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1159 VERIFY(1 < refcount_add(&dn->dn_holds, tag));
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1160 mutex_exit(&dn->dn_mtx);
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1161 return (TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1162 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1163
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1164 void
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1165 dnode_rele(dnode_t *dn, void *tag)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1166 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1167 uint64_t refs;
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1168 /* Get while the hold prevents the dnode from moving. */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1169 dmu_buf_impl_t *db = dn->dn_dbuf;
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1170 dnode_handle_t *dnh = dn->dn_handle;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1171
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1172 mutex_enter(&dn->dn_mtx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1173 refs = refcount_remove(&dn->dn_holds, tag);
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1174 mutex_exit(&dn->dn_mtx);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1175
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1176 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1177 * It's unsafe to release the last hold on a dnode by dnode_rele() or
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1178 * indirectly by dbuf_rele() while relying on the dnode handle to
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1179 * prevent the dnode from moving, since releasing the last hold could
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1180 * result in the dnode's parent dbuf evicting its dnode handles. For
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1181 * that reason anyone calling dnode_rele() or dbuf_rele() without some
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1182 * other direct or indirect hold on the dnode must first drop the dnode
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1183 * handle.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1184 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1185 ASSERT(refs > 0 || dnh->dnh_zrlock.zr_owner != curthread);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1186
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1187 /* NOTE: the DNODE_DNODE does not have a dn_dbuf */
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1188 if (refs == 0 && db != NULL) {
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1189 /*
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1190 * Another thread could add a hold to the dnode handle in
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1191 * dnode_hold_impl() while holding the parent dbuf. Since the
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1192 * hold on the parent dbuf prevents the handle from being
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1193 * destroyed, the hold on the handle is OK. We can't yet assert
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1194 * that the handle has zero references, but that will be
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1195 * asserted anyway when the handle gets destroyed.
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1196 */
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1197 dbuf_rele(db, dnh);
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1198 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1199 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1200
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1201 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1202 dnode_setdirty(dnode_t *dn, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1203 {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9950
diff changeset
1204 objset_t *os = dn->dn_objset;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1205 uint64_t txg = tx->tx_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1206
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1207 if (DMU_OBJECT_IS_SPECIAL(dn->dn_object)) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1208 dsl_dataset_dirty(os->os_dsl_dataset, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1209 return;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1210 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1211
873
adefbfa5f42d 6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents: 789
diff changeset
1212 DNODE_VERIFY(dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1213
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1214 #ifdef ZFS_DEBUG
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1215 mutex_enter(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1216 ASSERT(dn->dn_phys->dn_type || dn->dn_allocated_txg);
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1217 ASSERT(dn->dn_free_txg == 0 || dn->dn_free_txg >= txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1218 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1219 #endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1220
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1221 /*
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1222 * Determine old uid/gid when necessary
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1223 */
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11958
diff changeset
1224 dmu_objset_userquota_get_ids(dn, B_TRUE, tx);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1225
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1226 mutex_enter(&os->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1227
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1228 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1229 * If we are already marked dirty, we're done.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1230 */
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1231 if (list_link_active(&dn->dn_dirty_link[txg & TXG_MASK])) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1232 mutex_exit(&os->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1233 return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1234 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1235
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1236 ASSERT(!refcount_is_zero(&dn->dn_holds) || list_head(&dn->dn_dbufs));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1237 ASSERT(dn->dn_datablksz != 0);
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
1238 ASSERT0(dn->dn_next_bonuslen[txg&TXG_MASK]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
1239 ASSERT0(dn->dn_next_blksz[txg&TXG_MASK]);
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
1240 ASSERT0(dn->dn_next_bonustype[txg&TXG_MASK]);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1241
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1242 dprintf_ds(os->os_dsl_dataset, "obj=%llu txg=%llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1243 dn->dn_object, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1244
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1245 if (dn->dn_free_txg > 0 && dn->dn_free_txg <= txg) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1246 list_insert_tail(&os->os_free_dnodes[txg&TXG_MASK], dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1247 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1248 list_insert_tail(&os->os_dirty_dnodes[txg&TXG_MASK], dn);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1249 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1250
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1251 mutex_exit(&os->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1252
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1253 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1254 * The dnode maintains a hold on its containing dbuf as
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1255 * long as there are holds on it. Each instantiated child
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12586
diff changeset
1256 * dbuf maintains a hold on the dnode. When the last child
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1257 * drops its hold, the dnode will drop its hold on the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1258 * containing dbuf. We add a "dirty hold" here so that the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1259 * dnode will hang around after we finish processing its
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1260 * children.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1261 */
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4577
diff changeset
1262 VERIFY(dnode_add_ref(dn, (void *)(uintptr_t)tx->tx_txg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1263
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1264 (void) dbuf_dirty(dn->dn_dbuf, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1265
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1266 dsl_dataset_dirty(os->os_dsl_dataset, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1267 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1268
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1269 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1270 dnode_free(dnode_t *dn, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1271 {
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1272 int txgoff = tx->tx_txg & TXG_MASK;
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1273
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1274 dprintf("dn=%p txg=%llu\n", dn, tx->tx_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1275
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1276 /* we should be the only holder... hopefully */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1277 /* ASSERT3U(refcount_count(&dn->dn_holds), ==, 1); */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1278
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1279 mutex_enter(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1280 if (dn->dn_type == DMU_OT_NONE || dn->dn_free_txg) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1281 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1282 return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1283 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1284 dn->dn_free_txg = tx->tx_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1285 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1286
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1287 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1288 * If the dnode is already dirty, it needs to be moved from
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1289 * the dirty list to the free list.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1290 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1291 mutex_enter(&dn->dn_objset->os_lock);
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1292 if (list_link_active(&dn->dn_dirty_link[txgoff])) {
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1293 list_remove(&dn->dn_objset->os_dirty_dnodes[txgoff], dn);
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1294 list_insert_tail(&dn->dn_objset->os_free_dnodes[txgoff], dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1295 mutex_exit(&dn->dn_objset->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1296 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1297 mutex_exit(&dn->dn_objset->os_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1298 dnode_setdirty(dn, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1299 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1300 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1301
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1302 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1303 * Try to change the block size for the indicated dnode. This can only
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1304 * succeed if there are no blocks allocated or dirty beyond first block
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1305 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1306 int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1307 dnode_set_blksz(dnode_t *dn, uint64_t size, int ibs, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1308 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1309 dmu_buf_impl_t *db, *db_next;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1310 int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1311
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1312 if (size == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1313 size = SPA_MINBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1314 if (size > SPA_MAXBLOCKSIZE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1315 size = SPA_MAXBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1316 else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1317 size = P2ROUNDUP(size, SPA_MINBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1318
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1319 if (ibs == dn->dn_indblkshift)
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1320 ibs = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1321
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1322 if (size >> SPA_MINBLOCKSHIFT == dn->dn_datablkszsec && ibs == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1323 return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1324
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1325 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1326
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1327 /* Check for any allocated blocks beyond the first */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1328 if (dn->dn_phys->dn_maxblkid != 0)
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1329 goto fail;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1330
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1331 mutex_enter(&dn->dn_dbufs_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1332 for (db = list_head(&dn->dn_dbufs); db; db = db_next) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1333 db_next = list_next(&dn->dn_dbufs, db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1334
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1335 if (db->db_blkid != 0 && db->db_blkid != DMU_BONUS_BLKID &&
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1336 db->db_blkid != DMU_SPILL_BLKID) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1337 mutex_exit(&dn->dn_dbufs_mtx);
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1338 goto fail;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1339 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1340 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1341 mutex_exit(&dn->dn_dbufs_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1342
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1343 if (ibs && dn->dn_nlevels != 1)
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1344 goto fail;
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1345
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1346 /* resize the old block */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1347 err = dbuf_hold_impl(dn, 0, 0, TRUE, FTAG, &db);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1348 if (err == 0)
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1349 dbuf_new_size(db, size, tx);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1350 else if (err != ENOENT)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1351 goto fail;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1352
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1353 dnode_setdblksz(dn, size);
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1354 dnode_setdirty(dn, tx);
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1355 dn->dn_next_blksz[tx->tx_txg&TXG_MASK] = size;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1356 if (ibs) {
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1357 dn->dn_indblkshift = ibs;
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1358 dn->dn_next_indblkshift[tx->tx_txg&TXG_MASK] = ibs;
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1359 }
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1360 /* rele after we have fixed the blocksize in the dnode */
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1361 if (db)
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1362 dbuf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1363
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1364 rw_exit(&dn->dn_struct_rwlock);
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1365 return (0);
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1366
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1367 fail:
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1368 rw_exit(&dn->dn_struct_rwlock);
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1369 return (ENOTSUP);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1370 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1371
7332
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1372 /* read-holding callers must not rely on the lock being continuously held */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1373 void
7332
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1374 dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t have_read)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1375 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1376 uint64_t txgoff = tx->tx_txg & TXG_MASK;
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1377 int epbs, new_nlevels;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1378 uint64_t sz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1379
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1380 ASSERT(blkid != DMU_BONUS_BLKID);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1381
7332
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1382 ASSERT(have_read ?
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1383 RW_READ_HELD(&dn->dn_struct_rwlock) :
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1384 RW_WRITE_HELD(&dn->dn_struct_rwlock));
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1385
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1386 /*
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1387 * if we have a read-lock, check to see if we need to do any work
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1388 * before upgrading to a write-lock.
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1389 */
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1390 if (have_read) {
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1391 if (blkid <= dn->dn_maxblkid)
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1392 return;
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1393
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1394 if (!rw_tryupgrade(&dn->dn_struct_rwlock)) {
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1395 rw_exit(&dn->dn_struct_rwlock);
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1396 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1397 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1398 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1399
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1400 if (blkid <= dn->dn_maxblkid)
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1401 goto out;
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1402
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1403 dn->dn_maxblkid = blkid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1404
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1405 /*
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1406 * Compute the number of levels necessary to support the new maxblkid.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1407 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1408 new_nlevels = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1409 epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT;
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1410 for (sz = dn->dn_nblkptr;
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1411 sz <= blkid && sz >= dn->dn_nblkptr; sz <<= epbs)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1412 new_nlevels++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1413
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1414 if (new_nlevels > dn->dn_nlevels) {
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1415 int old_nlevels = dn->dn_nlevels;
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1416 dmu_buf_impl_t *db;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1417 list_t *list;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1418 dbuf_dirty_record_t *new, *dr, *dr_next;
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1419
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1420 dn->dn_nlevels = new_nlevels;
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1421
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1422 ASSERT3U(new_nlevels, >, dn->dn_next_nlevels[txgoff]);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1423 dn->dn_next_nlevels[txgoff] = new_nlevels;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1424
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1425 /* dirty the left indirects */
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1426 db = dbuf_hold_level(dn, old_nlevels, 0, FTAG);
12411
3e9af067a727 6911391 panic in dmu_tx_count_write()
John Harres <John.Harres@Sun.COM>
parents: 12178
diff changeset
1427 ASSERT(db != NULL);
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1428 new = dbuf_dirty(db, tx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1429 dbuf_rele(db, FTAG);
1596
2e2377ccbf85 6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents: 1544
diff changeset
1430
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1431 /* transfer the dirty records to the new indirect */
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1432 mutex_enter(&dn->dn_mtx);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1433 mutex_enter(&new->dt.di.dr_mtx);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1434 list = &dn->dn_dirty_records[txgoff];
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1435 for (dr = list_head(list); dr; dr = dr_next) {
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1436 dr_next = list_next(&dn->dn_dirty_records[txgoff], dr);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1437 if (dr->dr_dbuf->db_level != new_nlevels-1 &&
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1438 dr->dr_dbuf->db_blkid != DMU_BONUS_BLKID &&
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1439 dr->dr_dbuf->db_blkid != DMU_SPILL_BLKID) {
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1440 ASSERT(dr->dr_dbuf->db_level == old_nlevels-1);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1441 list_remove(&dn->dn_dirty_records[txgoff], dr);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1442 list_insert_tail(&new->dt.di.dr_children, dr);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1443 dr->dr_parent = new;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1444 }
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1445 }
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1446 mutex_exit(&new->dt.di.dr_mtx);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1447 mutex_exit(&dn->dn_mtx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1448 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1449
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1450 out:
7332
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1451 if (have_read)
396f25bd1f34 6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7049
diff changeset
1452 rw_downgrade(&dn->dn_struct_rwlock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1453 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1454
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1455 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1456 dnode_clear_range(dnode_t *dn, uint64_t blkid, uint64_t nblks, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1457 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1458 avl_tree_t *tree = &dn->dn_ranges[tx->tx_txg&TXG_MASK];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1459 avl_index_t where;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1460 free_range_t *rp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1461 free_range_t rp_tofind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1462 uint64_t endblk = blkid + nblks;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1463
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1464 ASSERT(MUTEX_HELD(&dn->dn_mtx));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1465 ASSERT(nblks <= UINT64_MAX - blkid); /* no overflow */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1466
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1467 dprintf_dnode(dn, "blkid=%llu nblks=%llu txg=%llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1468 blkid, nblks, tx->tx_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1469 rp_tofind.fr_blkid = blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1470 rp = avl_find(tree, &rp_tofind, &where);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1471 if (rp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1472 rp = avl_nearest(tree, where, AVL_BEFORE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1473 if (rp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1474 rp = avl_nearest(tree, where, AVL_AFTER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1475
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1476 while (rp && (rp->fr_blkid <= blkid + nblks)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1477 uint64_t fr_endblk = rp->fr_blkid + rp->fr_nblks;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1478 free_range_t *nrp = AVL_NEXT(tree, rp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1479
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1480 if (blkid <= rp->fr_blkid && endblk >= fr_endblk) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1481 /* clear this entire range */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1482 avl_remove(tree, rp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1483 kmem_free(rp, sizeof (free_range_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1484 } else if (blkid <= rp->fr_blkid &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1485 endblk > rp->fr_blkid && endblk < fr_endblk) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1486 /* clear the beginning of this range */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1487 rp->fr_blkid = endblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1488 rp->fr_nblks = fr_endblk - endblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1489 } else if (blkid > rp->fr_blkid && blkid < fr_endblk &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1490 endblk >= fr_endblk) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1491 /* clear the end of this range */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1492 rp->fr_nblks = blkid - rp->fr_blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1493 } else if (blkid > rp->fr_blkid && endblk < fr_endblk) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1494 /* clear a chunk out of this range */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1495 free_range_t *new_rp =
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1496 kmem_alloc(sizeof (free_range_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1497
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1498 new_rp->fr_blkid = endblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1499 new_rp->fr_nblks = fr_endblk - endblk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1500 avl_insert_here(tree, new_rp, rp, AVL_AFTER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1501 rp->fr_nblks = blkid - rp->fr_blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1502 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1503 /* there may be no overlap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1504 rp = nrp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1505 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1506 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1507
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1508 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1509 dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1510 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1511 dmu_buf_impl_t *db;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1512 uint64_t blkoff, blkid, nblks;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1513 int blksz, blkshift, head, tail;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1514 int trunc = FALSE;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1515 int epbs;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1516
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1517 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1518 blksz = dn->dn_datablksz;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1519 blkshift = dn->dn_datablkshift;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1520 epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1521
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1522 if (len == -1ULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1523 len = UINT64_MAX - off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1524 trunc = TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1525 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1526
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1527 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1528 * First, block align the region to free:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1529 */
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1530 if (ISP2(blksz)) {
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1531 head = P2NPHASE(off, blksz);
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1532 blkoff = P2PHASE(off, blksz);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1533 if ((off >> blkshift) > dn->dn_maxblkid)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1534 goto out;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1535 } else {
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1536 ASSERT(dn->dn_maxblkid == 0);
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1537 if (off == 0 && len >= blksz) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1538 /* Freeing the whole block; fast-track this request */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1539 blkid = 0;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1540 nblks = 1;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1541 goto done;
7385
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1542 } else if (off >= blksz) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1543 /* Freeing past end-of-data */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1544 goto out;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1545 } else {
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1546 /* Freeing part of the block. */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1547 head = blksz - off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1548 ASSERT3U(head, >, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1549 }
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1550 blkoff = off;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1551 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1552 /* zero out any partial block data at the start of the range */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1553 if (head) {
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1554 ASSERT3U(blkoff + head, ==, blksz);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1555 if (len < head)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1556 head = len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1557 if (dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, off), TRUE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1558 FTAG, &db) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1559 caddr_t data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1560
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1561 /* don't dirty if it isn't on disk and isn't dirty */
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3087
diff changeset
1562 if (db->db_last_dirty ||
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1563 (db->db_blkptr && !BP_IS_HOLE(db->db_blkptr))) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1564 rw_exit(&dn->dn_struct_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1565 dbuf_will_dirty(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1566 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1567 data = db->db.db_data;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1568 bzero(data + blkoff, head);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1569 }
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1570 dbuf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1571 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1572 off += head;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1573 len -= head;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1574 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1575
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1576 /* If the range was less than one block, we're done */
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1577 if (len == 0)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1578 goto out;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1579
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1580 /* If the remaining range is past end of file, we're done */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1581 if ((off >> blkshift) > dn->dn_maxblkid)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1582 goto out;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1583
7385
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1584 ASSERT(ISP2(blksz));
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1585 if (trunc)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1586 tail = 0;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1587 else
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1588 tail = P2PHASE(len, blksz);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1589
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
1590 ASSERT0(P2PHASE(off, blksz));
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1591 /* zero out any partial block data at the end of the range */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1592 if (tail) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1593 if (len < tail)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1594 tail = len;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1595 if (dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, off+len),
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1596 TRUE, FTAG, &db) == 0) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1597 /* don't dirty if not on disk and not dirty */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1598 if (db->db_last_dirty ||
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1599 (db->db_blkptr && !BP_IS_HOLE(db->db_blkptr))) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1600 rw_exit(&dn->dn_struct_rwlock);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1601 dbuf_will_dirty(db, tx);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1602 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1603 bzero(db->db.db_data, tail);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1604 }
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1605 dbuf_rele(db, FTAG);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1606 }
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1607 len -= tail;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1608 }
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1609
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1610 /* If the range did not include a full block, we are done */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1611 if (len == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1612 goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1613
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1614 ASSERT(IS_P2ALIGNED(off, blksz));
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1615 ASSERT(trunc || IS_P2ALIGNED(len, blksz));
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1616 blkid = off >> blkshift;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1617 nblks = len >> blkshift;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1618 if (trunc)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1619 nblks += 1;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1620
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1621 /*
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1622 * Read in and mark all the level-1 indirects dirty,
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1623 * so that they will stay in memory until syncing phase.
7049
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1624 * Always dirty the first and last indirect to make sure
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1625 * we dirty all the partial indirects.
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1626 */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1627 if (dn->dn_nlevels > 1) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1628 uint64_t i, first, last;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1629 int shift = epbs + dn->dn_datablkshift;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1630
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1631 first = blkid >> epbs;
7049
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1632 if (db = dbuf_hold_level(dn, 1, first, FTAG)) {
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1633 dbuf_will_dirty(db, tx);
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1634 dbuf_rele(db, FTAG);
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1635 }
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1636 if (trunc)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1637 last = dn->dn_maxblkid >> epbs;
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1638 else
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1639 last = (blkid + nblks - 1) >> epbs;
7049
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1640 if (last > first && (db = dbuf_hold_level(dn, 1, last, FTAG))) {
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1641 dbuf_will_dirty(db, tx);
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1642 dbuf_rele(db, FTAG);
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1643 }
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1644 for (i = first + 1; i < last; i++) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1645 uint64_t ibyte = i << shift;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1646 int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1647
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1648 err = dnode_next_offset(dn,
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1649 DNODE_FIND_HAVELOCK, &ibyte, 1, 1, 0);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1650 i = ibyte >> shift;
7049
d0b1e2eb4ab5 6723124 Assertion failed: all || blocks_freed == 0 || db->db_last_dirty
maybee
parents: 6992
diff changeset
1651 if (err == ESRCH || i >= last)
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1652 break;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1653 ASSERT(err == 0);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1654 db = dbuf_hold_level(dn, 1, i, FTAG);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1655 if (db) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1656 dbuf_will_dirty(db, tx);
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1657 dbuf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1658 }
2445
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1659 }
45c1310316ff 6447381 dnode_free_range() does not handle non-power-of-two blocksizes correctly
ahrens
parents: 2082
diff changeset
1660 }
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1661 done:
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1662 /*
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1663 * Add this range to the dnode range list.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1664 * We will finish up this free operation in the syncing phase.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1665 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1666 mutex_enter(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1667 dnode_clear_range(dn, blkid, nblks, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1668 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1669 free_range_t *rp, *found;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1670 avl_index_t where;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1671 avl_tree_t *tree = &dn->dn_ranges[tx->tx_txg&TXG_MASK];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1672
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1673 /* Add new range to dn_ranges */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1674 rp = kmem_alloc(sizeof (free_range_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1675 rp->fr_blkid = blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1676 rp->fr_nblks = nblks;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1677 found = avl_find(tree, rp, &where);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1678 ASSERT(found == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1679 avl_insert(tree, rp, where);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1680 dprintf_dnode(dn, "blkid=%llu nblks=%llu txg=%llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1681 blkid, nblks, tx->tx_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1682 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1683 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1684
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1685 dbuf_free_range(dn, blkid, blkid + nblks - 1, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1686 dnode_setdirty(dn, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1687 out:
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1688 if (trunc && dn->dn_maxblkid >= (off >> blkshift))
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1689 dn->dn_maxblkid = (off >> blkshift ? (off >> blkshift) - 1 : 0);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1690
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1691 rw_exit(&dn->dn_struct_rwlock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1692 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1693
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1694 static boolean_t
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1695 dnode_spill_freed(dnode_t *dn)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1696 {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1697 int i;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1698
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1699 mutex_enter(&dn->dn_mtx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1700 for (i = 0; i < TXG_SIZE; i++) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1701 if (dn->dn_rm_spillblk[i] == DN_KILL_SPILLBLK)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1702 break;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1703 }
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1704 mutex_exit(&dn->dn_mtx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1705 return (i < TXG_SIZE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1706 }
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1707
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1708 /* return TRUE if this blkid was freed in a recent txg, or FALSE if it wasn't */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1709 uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1710 dnode_block_freed(dnode_t *dn, uint64_t blkid)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1711 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1712 free_range_t range_tofind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1713 void *dp = spa_get_dsl(dn->dn_objset->os_spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1714 int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1715
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1716 if (blkid == DMU_BONUS_BLKID)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1717 return (FALSE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1718
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1719 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1720 * If we're in the process of opening the pool, dp will not be
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1721 * set yet, but there shouldn't be anything dirty.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1722 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1723 if (dp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1724 return (FALSE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1725
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1726 if (dn->dn_free_txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1727 return (TRUE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1728
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1729 if (blkid == DMU_SPILL_BLKID)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1730 return (dnode_spill_freed(dn));
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10298
diff changeset
1731
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1732 range_tofind.fr_blkid = blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1733 mutex_enter(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1734 for (i = 0; i < TXG_SIZE; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1735 free_range_t *range_found;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1736 avl_index_t idx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1737
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1738 range_found = avl_find(&dn->dn_ranges[i], &range_tofind, &idx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1739 if (range_found) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1740 ASSERT(range_found->fr_nblks > 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1741 break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1742 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1743 range_found = avl_nearest(&dn->dn_ranges[i], idx, AVL_BEFORE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1744 if (range_found &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1745 range_found->fr_blkid + range_found->fr_nblks > blkid)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1746 break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1747 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1748 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1749 return (i < TXG_SIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1750 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1751
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1752 /* call from syncing context when we actually write/free space for this dnode */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1753 void
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1754 dnode_diduse_space(dnode_t *dn, int64_t delta)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1755 {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1756 uint64_t space;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1757 dprintf_dnode(dn, "dn=%p dnp=%p used=%llu delta=%lld\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1758 dn, dn->dn_phys,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1759 (u_longlong_t)dn->dn_phys->dn_used,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1760 (longlong_t)delta);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1761
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1762 mutex_enter(&dn->dn_mtx);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1763 space = DN_USED_BYTES(dn->dn_phys);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1764 if (delta > 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1765 ASSERT3U(space + delta, >=, space); /* no overflow */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1766 } else {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1767 ASSERT3U(space, >=, -delta); /* no underflow */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1768 }
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1769 space += delta;
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4309
diff changeset
1770 if (spa_version(dn->dn_objset->os_spa) < SPA_VERSION_DNODE_BYTES) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1771 ASSERT((dn->dn_phys->dn_flags & DNODE_FLAG_USED_BYTES) == 0);
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
1772 ASSERT0(P2PHASE(space, 1<<DEV_BSHIFT));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1773 dn->dn_phys->dn_used = space >> DEV_BSHIFT;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1774 } else {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1775 dn->dn_phys->dn_used = space;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1990
diff changeset
1776 dn->dn_phys->dn_flags |= DNODE_FLAG_USED_BYTES;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1777 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1778 mutex_exit(&dn->dn_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1779 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1780
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1781 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1782 * Call when we think we're going to write/free space in open context.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1783 * Be conservative (ie. OK to write less than this or free more than
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1784 * this, but don't write more or free less).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1785 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1786 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1787 dnode_willuse_space(dnode_t *dn, int64_t space, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1788 {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9950
diff changeset
1789 objset_t *os = dn->dn_objset;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1790 dsl_dataset_t *ds = os->os_dsl_dataset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1791
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1792 if (space > 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1793 space = spa_get_asize(os->os_spa, space);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1794
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1795 if (ds)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1796 dsl_dir_willuse_space(ds->ds_dir, space, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1797
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1798 dmu_tx_willuse_space(tx, space);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1799 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1800
9950
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1801 /*
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1802 * This function scans a block at the indicated "level" looking for
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1803 * a hole or data (depending on 'flags'). If level > 0, then we are
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1804 * scanning an indirect block looking at its pointers. If level == 0,
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1805 * then we are looking at a block of dnodes. If we don't find what we
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1806 * are looking for in the block, we return ESRCH. Otherwise, return
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1807 * with *offset pointing to the beginning (if searching forwards) or
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1808 * end (if searching backwards) of the range covered by the block
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1809 * pointer we matched on (or dnode).
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1810 *
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1811 * The basic search algorithm used below by dnode_next_offset() is to
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1812 * use this function to search up the block tree (widen the search) until
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1813 * we find something (i.e., we don't return ESRCH) and then search back
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1814 * down the tree (narrow the search) until we reach our original search
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1815 * level.
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1816 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1817 static int
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1818 dnode_next_offset_level(dnode_t *dn, int flags, uint64_t *offset,
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1819 int lvl, uint64_t blkfill, uint64_t txg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1820 {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1821 dmu_buf_impl_t *db = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1822 void *data = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1823 uint64_t epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1824 uint64_t epb = 1ULL << epbs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1825 uint64_t minfill, maxfill;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1826 boolean_t hole;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1827 int i, inc, error, span;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1828
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1829 dprintf("probing object %llu offset %llx level %d of %u\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1830 dn->dn_object, *offset, lvl, dn->dn_phys->dn_nlevels);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1831
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8986
diff changeset
1832 hole = ((flags & DNODE_FIND_HOLE) != 0);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1833 inc = (flags & DNODE_FIND_BACKWARDS) ? -1 : 1;
7385
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1834 ASSERT(txg == 0 || !hole);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1835
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1836 if (lvl == dn->dn_phys->dn_nlevels) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1837 error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1838 epb = dn->dn_phys->dn_nblkptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1839 data = dn->dn_phys->dn_blkptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1840 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1841 uint64_t blkid = dbuf_whichblock(dn, *offset) >> (epbs * lvl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1842 error = dbuf_hold_impl(dn, lvl, blkid, TRUE, FTAG, &db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1843 if (error) {
7385
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1844 if (error != ENOENT)
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1845 return (error);
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1846 if (hole)
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1847 return (0);
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1848 /*
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1849 * This can only happen when we are searching up
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1850 * the block tree for data. We don't really need to
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1851 * adjust the offset, as we will just end up looking
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1852 * at the pointer to this block in its parent, and its
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1853 * going to be unallocated, so we will skip over it.
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1854 */
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1855 return (ESRCH);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1856 }
1793
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1857 error = dbuf_read(db, NULL, DB_RF_CANFAIL | DB_RF_HAVESTRUCT);
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1858 if (error) {
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1859 dbuf_rele(db, FTAG);
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1860 return (error);
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1861 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1862 data = db->db.db_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1863 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1864
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1865 if (db && txg &&
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1866 (db->db_blkptr == NULL || db->db_blkptr->blk_birth <= txg)) {
7385
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1867 /*
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1868 * This can only happen when we are searching up the tree
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1869 * and these conditions mean that we need to keep climbing.
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1870 */
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1871 error = ESRCH;
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1872 } else if (lvl == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1873 dnode_phys_t *dnp = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1874 span = DNODE_SHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1875 ASSERT(dn->dn_type == DMU_OT_DNODE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1876
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1877 for (i = (*offset >> span) & (blkfill - 1);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1878 i >= 0 && i < blkfill; i += inc) {
9409
9dc3f17354ed 6809683 zfs destroy fails to free object in open context, stops up txg train
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 9396
diff changeset
1879 if ((dnp[i].dn_type == DMU_OT_NONE) == hole)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1880 break;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1881 *offset += (1ULL << span) * inc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1882 }
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1883 if (i < 0 || i == blkfill)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1884 error = ESRCH;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1885 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1886 blkptr_t *bp = data;
9950
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1887 uint64_t start = *offset;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1888 span = (lvl - 1) * epbs + dn->dn_datablkshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1889 minfill = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1890 maxfill = blkfill << ((lvl - 1) * epbs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1891
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1892 if (hole)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1893 maxfill--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1894 else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1895 minfill++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1896
9950
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1897 *offset = *offset >> span;
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1898 for (i = BF64_GET(*offset, 0, epbs);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1899 i >= 0 && i < epb; i += inc) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1900 if (bp[i].blk_fill >= minfill &&
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1901 bp[i].blk_fill <= maxfill &&
7385
f69ff8507427 6727817 ZFS assertion failure (zero length arc_buf_alloc) during NFS I/O
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 7332
diff changeset
1902 (hole || bp[i].blk_birth > txg))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1903 break;
9950
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1904 if (inc > 0 || *offset > 0)
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1905 *offset += inc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1906 }
9950
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1907 *offset = *offset << span;
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1908 if (inc < 0) {
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1909 /* traversing backwards; position offset at the end */
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1910 ASSERT3U(*offset, <=, start);
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1911 *offset = MIN(*offset + (1ULL << span) - 1, start);
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1912 } else if (*offset < start) {
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1913 *offset = start;
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1914 }
78fc41aa9bc5 6792701 Removing large holey file does not free space
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9409
diff changeset
1915 if (i < 0 || i >= epb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1916 error = ESRCH;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1917 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1918
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1919 if (db)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1491
diff changeset
1920 dbuf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1921
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1922 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1923 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1924
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1925 /*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1926 * Find the next hole, data, or sparse region at or after *offset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1927 * The value 'blkfill' tells us how many items we expect to find
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1928 * in an L0 data block; this value is 1 for normal objects,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1929 * DNODES_PER_BLOCK for the meta dnode, and some fraction of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1930 * DNODES_PER_BLOCK when searching for sparse regions thereof.
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1931 *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1932 * Examples:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1933 *
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1934 * dnode_next_offset(dn, flags, offset, 1, 1, 0);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1935 * Finds the next/previous hole/data in a file.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1936 * Used in dmu_offset_next().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1937 *
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1938 * dnode_next_offset(mdn, flags, offset, 0, DNODES_PER_BLOCK, txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1939 * Finds the next free/allocated dnode an objset's meta-dnode.
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1940 * Only finds objects that have new contents since txg (ie.
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1941 * bonus buffer changes and content removal are ignored).
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1942 * Used in dmu_object_next().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1943 *
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1944 * dnode_next_offset(mdn, DNODE_FIND_HOLE, offset, 2, DNODES_PER_BLOCK >> 2, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1945 * Finds the next L2 meta-dnode bp that's at most 1/4 full.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1946 * Used in dmu_object_alloc().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1947 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1948 int
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1949 dnode_next_offset(dnode_t *dn, int flags, uint64_t *offset,
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1950 int minlvl, uint64_t blkfill, uint64_t txg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1951 {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1952 uint64_t initial_offset = *offset;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1953 int lvl, maxlvl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1954 int error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1955
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1956 if (!(flags & DNODE_FIND_HAVELOCK))
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1957 rw_enter(&dn->dn_struct_rwlock, RW_READER);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1958
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1959 if (dn->dn_phys->dn_nlevels == 0) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1960 error = ESRCH;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1961 goto out;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1962 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1963
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1964 if (dn->dn_datablkshift == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1965 if (*offset < dn->dn_datablksz) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1966 if (flags & DNODE_FIND_HOLE)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1967 *offset = dn->dn_datablksz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1968 } else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1969 error = ESRCH;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1970 }
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1971 goto out;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1972 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1973
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1974 maxlvl = dn->dn_phys->dn_nlevels;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1975
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1976 for (lvl = minlvl; lvl <= maxlvl; lvl++) {
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1977 error = dnode_next_offset_level(dn,
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1978 flags, offset, lvl, blkfill, txg);
1793
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1979 if (error != ESRCH)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1980 break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1981 }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1982
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1983 while (error == 0 && --lvl >= minlvl) {
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1984 error = dnode_next_offset_level(dn,
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1985 flags, offset, lvl, blkfill, txg);
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2885
diff changeset
1986 }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1987
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1988 if (error == 0 && (flags & DNODE_FIND_BACKWARDS ?
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1989 initial_offset < *offset : initial_offset > *offset))
1793
d371fba21a3e 6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents: 1646
diff changeset
1990 error = ESRCH;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1991 out:
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1992 if (!(flags & DNODE_FIND_HAVELOCK))
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 4944
diff changeset
1993 rw_exit(&dn->dn_struct_rwlock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1994
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1995 return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
1996 }