author | Mark Maybee <Mark.Maybee@Sun.COM> |
Tue, 07 Apr 2009 11:51:00 -0600 | |
changeset 9299 | 8809e849f63e |
parent 8986 | 45c289aff7c9 |
child 10298 | a0d52501437c |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1544 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
789 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
/* |
|
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
22 |
* Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
#include <sys/dmu.h> |
|
27 |
#include <sys/dmu_objset.h> |
|
28 |
#include <sys/dmu_tx.h> |
|
29 |
#include <sys/dnode.h> |
|
30 |
||
31 |
uint64_t |
|
32 |
dmu_object_alloc(objset_t *os, dmu_object_type_t ot, int blocksize, |
|
33 |
dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx) |
|
34 |
{ |
|
35 |
objset_impl_t *osi = os->os; |
|
36 |
uint64_t object; |
|
37 |
uint64_t L2_dnode_count = DNODES_PER_BLOCK << |
|
38 |
(osi->os_meta_dnode->dn_indblkshift - SPA_BLKPTRSHIFT); |
|
1544 | 39 |
dnode_t *dn = NULL; |
789 | 40 |
int restarted = B_FALSE; |
41 |
||
42 |
mutex_enter(&osi->os_obj_lock); |
|
43 |
for (;;) { |
|
44 |
object = osi->os_obj_next; |
|
45 |
/* |
|
46 |
* Each time we polish off an L2 bp worth of dnodes |
|
47 |
* (2^13 objects), move to another L2 bp that's still |
|
48 |
* reasonably sparse (at most 1/4 full). Look from the |
|
49 |
* beginning once, but after that keep looking from here. |
|
50 |
* If we can't find one, just keep going from here. |
|
51 |
*/ |
|
52 |
if (P2PHASE(object, L2_dnode_count) == 0) { |
|
53 |
uint64_t offset = restarted ? object << DNODE_SHIFT : 0; |
|
54 |
int error = dnode_next_offset(osi->os_meta_dnode, |
|
6992 | 55 |
DNODE_FIND_HOLE, |
56 |
&offset, 2, DNODES_PER_BLOCK >> 2, 0); |
|
789 | 57 |
restarted = B_TRUE; |
58 |
if (error == 0) |
|
59 |
object = offset >> DNODE_SHIFT; |
|
60 |
} |
|
61 |
osi->os_obj_next = ++object; |
|
62 |
||
1544 | 63 |
/* |
64 |
* XXX We should check for an i/o error here and return |
|
65 |
* up to our caller. Actually we should pre-read it in |
|
66 |
* dmu_tx_assign(), but there is currently no mechanism |
|
67 |
* to do so. |
|
68 |
*/ |
|
69 |
(void) dnode_hold_impl(os->os, object, DNODE_MUST_BE_FREE, |
|
70 |
FTAG, &dn); |
|
789 | 71 |
if (dn) |
72 |
break; |
|
73 |
||
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
1544
diff
changeset
|
74 |
if (dmu_object_next(os, &object, B_TRUE, 0) == 0) |
789 | 75 |
osi->os_obj_next = object - 1; |
76 |
} |
|
77 |
||
78 |
dnode_allocate(dn, ot, blocksize, 0, bonustype, bonuslen, tx); |
|
79 |
dnode_rele(dn, FTAG); |
|
80 |
||
81 |
mutex_exit(&osi->os_obj_lock); |
|
82 |
||
83 |
dmu_tx_add_new_object(tx, os, object); |
|
84 |
return (object); |
|
85 |
} |
|
86 |
||
87 |
int |
|
88 |
dmu_object_claim(objset_t *os, uint64_t object, dmu_object_type_t ot, |
|
89 |
int blocksize, dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx) |
|
90 |
{ |
|
91 |
dnode_t *dn; |
|
1544 | 92 |
int err; |
789 | 93 |
|
1544 | 94 |
if (object == DMU_META_DNODE_OBJECT && !dmu_tx_private_ok(tx)) |
789 | 95 |
return (EBADF); |
96 |
||
1544 | 97 |
err = dnode_hold_impl(os->os, object, DNODE_MUST_BE_FREE, FTAG, &dn); |
98 |
if (err) |
|
99 |
return (err); |
|
789 | 100 |
dnode_allocate(dn, ot, blocksize, 0, bonustype, bonuslen, tx); |
101 |
dnode_rele(dn, FTAG); |
|
102 |
||
103 |
dmu_tx_add_new_object(tx, os, object); |
|
104 |
return (0); |
|
105 |
} |
|
106 |
||
107 |
int |
|
108 |
dmu_object_reclaim(objset_t *os, uint64_t object, dmu_object_type_t ot, |
|
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
109 |
int blocksize, dmu_object_type_t bonustype, int bonuslen) |
789 | 110 |
{ |
111 |
dnode_t *dn; |
|
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
112 |
dmu_tx_t *tx; |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
113 |
int nblkptr; |
1544 | 114 |
int err; |
789 | 115 |
|
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
116 |
if (object == DMU_META_DNODE_OBJECT) |
789 | 117 |
return (EBADF); |
118 |
||
1544 | 119 |
err = dnode_hold_impl(os->os, object, DNODE_MUST_BE_ALLOCATED, |
120 |
FTAG, &dn); |
|
121 |
if (err) |
|
122 |
return (err); |
|
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
123 |
|
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
124 |
if (dn->dn_type == ot && dn->dn_datablksz == blocksize && |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
125 |
dn->dn_bonustype == bonustype && dn->dn_bonuslen == bonuslen) { |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
126 |
/* nothing is changing, this is a noop */ |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
127 |
dnode_rele(dn, FTAG); |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
128 |
return (0); |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
129 |
} |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
130 |
|
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
131 |
nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT); |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
132 |
|
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
133 |
/* |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
134 |
* If we are losing blkptrs or changing the block size this must |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
135 |
* be a new file instance. We must clear out the previous file |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
136 |
* contents before we can change this type of metadata in the dnode. |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
137 |
*/ |
9299
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
138 |
if (dn->dn_nblkptr > nblkptr || dn->dn_datablksz != blocksize) { |
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
139 |
err = dmu_free_long_range(os, object, 0, DMU_OBJECT_END); |
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
140 |
if (err) |
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
141 |
goto out; |
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
142 |
} |
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
143 |
|
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
144 |
tx = dmu_tx_create(os); |
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
145 |
dmu_tx_hold_bonus(tx, object); |
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
146 |
err = dmu_tx_assign(tx, TXG_WAIT); |
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
147 |
if (err) { |
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
148 |
dmu_tx_abort(tx); |
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
149 |
goto out; |
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
150 |
} |
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
151 |
|
789 | 152 |
dnode_reallocate(dn, ot, blocksize, bonustype, bonuslen, tx); |
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
153 |
|
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
6992
diff
changeset
|
154 |
dmu_tx_commit(tx); |
9299
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
155 |
out: |
789 | 156 |
dnode_rele(dn, FTAG); |
157 |
||
9299
8809e849f63e
6783818 Incremental stream receive panics system
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8986
diff
changeset
|
158 |
return (err); |
789 | 159 |
} |
160 |
||
161 |
int |
|
162 |
dmu_object_free(objset_t *os, uint64_t object, dmu_tx_t *tx) |
|
163 |
{ |
|
164 |
dnode_t *dn; |
|
1544 | 165 |
int err; |
789 | 166 |
|
1544 | 167 |
ASSERT(object != DMU_META_DNODE_OBJECT || dmu_tx_private_ok(tx)); |
789 | 168 |
|
1544 | 169 |
err = dnode_hold_impl(os->os, object, DNODE_MUST_BE_ALLOCATED, |
170 |
FTAG, &dn); |
|
171 |
if (err) |
|
172 |
return (err); |
|
789 | 173 |
|
174 |
ASSERT(dn->dn_type != DMU_OT_NONE); |
|
6992 | 175 |
dnode_free_range(dn, 0, DMU_OBJECT_END, tx); |
789 | 176 |
dnode_free(dn, tx); |
177 |
dnode_rele(dn, FTAG); |
|
178 |
||
179 |
return (0); |
|
180 |
} |
|
181 |
||
182 |
int |
|
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
1544
diff
changeset
|
183 |
dmu_object_next(objset_t *os, uint64_t *objectp, boolean_t hole, uint64_t txg) |
789 | 184 |
{ |
185 |
uint64_t offset = (*objectp + 1) << DNODE_SHIFT; |
|
186 |
int error; |
|
187 |
||
188 |
error = dnode_next_offset(os->os->os_meta_dnode, |
|
6992 | 189 |
(hole ? DNODE_FIND_HOLE : 0), &offset, 0, DNODES_PER_BLOCK, txg); |
789 | 190 |
|
191 |
*objectp = offset >> DNODE_SHIFT; |
|
192 |
||
193 |
return (error); |
|
194 |
} |