author | ck153898 |
Mon, 29 Oct 2007 22:45:33 -0700 | |
changeset 5378 | 111aa1baa84a |
parent 5329 | 33cb98223b2d |
child 5765 | 86c482ef4a34 |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
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:
873
diff
changeset
|
5 |
* Common Development and Distribution License (the "License"). |
bdcb30e07e7d
6389368 fat zap should use 16k blocks (with backwards compatability)
ahrens
parents:
873
diff
changeset
|
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 |
/* |
|
5329 | 22 |
* Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
#pragma ident "%Z%%M% %I% %E% SMI" |
|
27 |
||
28 |
#include <sys/dmu.h> |
|
29 |
#include <sys/dmu_impl.h> |
|
30 |
#include <sys/dbuf.h> |
|
31 |
#include <sys/dmu_tx.h> |
|
32 |
#include <sys/dmu_objset.h> |
|
33 |
#include <sys/dsl_dataset.h> /* for dsl_dataset_block_freeable() */ |
|
34 |
#include <sys/dsl_dir.h> /* for dsl_dir_tempreserve_*() */ |
|
35 |
#include <sys/dsl_pool.h> |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
36 |
#include <sys/zap_impl.h> /* for fzap_default_block_shift */ |
789 | 37 |
#include <sys/spa.h> |
38 |
#include <sys/zfs_context.h> |
|
39 |
||
1544 | 40 |
typedef void (*dmu_tx_hold_func_t)(dmu_tx_t *tx, struct dnode *dn, |
41 |
uint64_t arg1, uint64_t arg2); |
|
42 |
||
789 | 43 |
|
44 |
dmu_tx_t * |
|
2199 | 45 |
dmu_tx_create_dd(dsl_dir_t *dd) |
789 | 46 |
{ |
47 |
dmu_tx_t *tx = kmem_zalloc(sizeof (dmu_tx_t), KM_SLEEP); |
|
48 |
tx->tx_dir = dd; |
|
49 |
if (dd) |
|
50 |
tx->tx_pool = dd->dd_pool; |
|
51 |
list_create(&tx->tx_holds, sizeof (dmu_tx_hold_t), |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
52 |
offsetof(dmu_tx_hold_t, txh_node)); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
53 |
#ifdef ZFS_DEBUG |
789 | 54 |
refcount_create(&tx->tx_space_written); |
55 |
refcount_create(&tx->tx_space_freed); |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
56 |
#endif |
789 | 57 |
return (tx); |
58 |
} |
|
59 |
||
60 |
dmu_tx_t * |
|
61 |
dmu_tx_create(objset_t *os) |
|
62 |
{ |
|
2199 | 63 |
dmu_tx_t *tx = dmu_tx_create_dd(os->os->os_dsl_dataset->ds_dir); |
789 | 64 |
tx->tx_objset = os; |
1544 | 65 |
tx->tx_lastsnap_txg = dsl_dataset_prev_snap_txg(os->os->os_dsl_dataset); |
789 | 66 |
return (tx); |
67 |
} |
|
68 |
||
69 |
dmu_tx_t * |
|
70 |
dmu_tx_create_assigned(struct dsl_pool *dp, uint64_t txg) |
|
71 |
{ |
|
2199 | 72 |
dmu_tx_t *tx = dmu_tx_create_dd(NULL); |
789 | 73 |
|
74 |
ASSERT3U(txg, <=, dp->dp_tx.tx_open_txg); |
|
75 |
tx->tx_pool = dp; |
|
76 |
tx->tx_txg = txg; |
|
77 |
tx->tx_anyobj = TRUE; |
|
78 |
||
79 |
return (tx); |
|
80 |
} |
|
81 |
||
82 |
int |
|
83 |
dmu_tx_is_syncing(dmu_tx_t *tx) |
|
84 |
{ |
|
85 |
return (tx->tx_anyobj); |
|
86 |
} |
|
87 |
||
88 |
int |
|
89 |
dmu_tx_private_ok(dmu_tx_t *tx) |
|
90 |
{ |
|
1544 | 91 |
return (tx->tx_anyobj); |
789 | 92 |
} |
93 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
94 |
static dmu_tx_hold_t * |
789 | 95 |
dmu_tx_hold_object_impl(dmu_tx_t *tx, objset_t *os, uint64_t object, |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
96 |
enum dmu_tx_hold_type type, uint64_t arg1, uint64_t arg2) |
789 | 97 |
{ |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
98 |
dmu_tx_hold_t *txh; |
789 | 99 |
dnode_t *dn = NULL; |
1544 | 100 |
int err; |
789 | 101 |
|
102 |
if (object != DMU_NEW_OBJECT) { |
|
1544 | 103 |
err = dnode_hold(os->os, object, tx, &dn); |
104 |
if (err) { |
|
105 |
tx->tx_err = err; |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
106 |
return (NULL); |
1544 | 107 |
} |
789 | 108 |
|
1544 | 109 |
if (err == 0 && tx->tx_txg != 0) { |
789 | 110 |
mutex_enter(&dn->dn_mtx); |
111 |
/* |
|
112 |
* dn->dn_assigned_txg == tx->tx_txg doesn't pose a |
|
113 |
* problem, but there's no way for it to happen (for |
|
114 |
* now, at least). |
|
115 |
*/ |
|
116 |
ASSERT(dn->dn_assigned_txg == 0); |
|
117 |
dn->dn_assigned_txg = tx->tx_txg; |
|
118 |
(void) refcount_add(&dn->dn_tx_holds, tx); |
|
119 |
mutex_exit(&dn->dn_mtx); |
|
120 |
} |
|
121 |
} |
|
122 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
123 |
txh = kmem_zalloc(sizeof (dmu_tx_hold_t), KM_SLEEP); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
124 |
txh->txh_tx = tx; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
125 |
txh->txh_dnode = dn; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
126 |
#ifdef ZFS_DEBUG |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
127 |
txh->txh_type = type; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
128 |
txh->txh_arg1 = arg1; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
129 |
txh->txh_arg2 = arg2; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
130 |
#endif |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
131 |
list_insert_tail(&tx->tx_holds, txh); |
1544 | 132 |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
133 |
return (txh); |
789 | 134 |
} |
135 |
||
136 |
void |
|
137 |
dmu_tx_add_new_object(dmu_tx_t *tx, objset_t *os, uint64_t object) |
|
138 |
{ |
|
139 |
/* |
|
140 |
* If we're syncing, they can manipulate any object anyhow, and |
|
141 |
* the hold on the dnode_t can cause problems. |
|
142 |
*/ |
|
143 |
if (!dmu_tx_is_syncing(tx)) { |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
144 |
(void) dmu_tx_hold_object_impl(tx, os, |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
145 |
object, THT_NEWOBJECT, 0, 0); |
789 | 146 |
} |
147 |
} |
|
148 |
||
1544 | 149 |
static int |
150 |
dmu_tx_check_ioerr(zio_t *zio, dnode_t *dn, int level, uint64_t blkid) |
|
151 |
{ |
|
152 |
int err; |
|
153 |
dmu_buf_impl_t *db; |
|
154 |
||
155 |
rw_enter(&dn->dn_struct_rwlock, RW_READER); |
|
156 |
db = dbuf_hold_level(dn, level, blkid, FTAG); |
|
157 |
rw_exit(&dn->dn_struct_rwlock); |
|
158 |
if (db == NULL) |
|
159 |
return (EIO); |
|
160 |
err = dbuf_read(db, zio, DB_RF_CANFAIL); |
|
161 |
dbuf_rele(db, FTAG); |
|
162 |
return (err); |
|
163 |
} |
|
164 |
||
789 | 165 |
/* ARGSUSED */ |
166 |
static void |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
167 |
dmu_tx_count_write(dmu_tx_hold_t *txh, uint64_t off, uint64_t len) |
789 | 168 |
{ |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
169 |
dnode_t *dn = txh->txh_dnode; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
170 |
uint64_t start, end, i; |
789 | 171 |
int min_bs, max_bs, min_ibs, max_ibs, epbs, bits; |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
172 |
int err = 0; |
789 | 173 |
|
174 |
if (len == 0) |
|
175 |
return; |
|
176 |
||
177 |
min_bs = SPA_MINBLOCKSHIFT; |
|
178 |
max_bs = SPA_MAXBLOCKSHIFT; |
|
179 |
min_ibs = DN_MIN_INDBLKSHIFT; |
|
180 |
max_ibs = DN_MAX_INDBLKSHIFT; |
|
181 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
182 |
|
789 | 183 |
/* |
1544 | 184 |
* For i/o error checking, read the first and last level-0 |
2082 | 185 |
* blocks (if they are not aligned), and all the level-1 blocks. |
1544 | 186 |
*/ |
187 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
188 |
if (dn) { |
1544 | 189 |
if (dn->dn_maxblkid == 0) { |
190 |
err = dmu_tx_check_ioerr(NULL, dn, 0, 0); |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
191 |
if (err) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
192 |
goto out; |
1544 | 193 |
} else { |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
194 |
zio_t *zio = zio_root(dn->dn_objset->os_spa, |
1544 | 195 |
NULL, NULL, ZIO_FLAG_CANFAIL); |
196 |
||
197 |
/* first level-0 block */ |
|
2082 | 198 |
start = off >> dn->dn_datablkshift; |
199 |
if (P2PHASE(off, dn->dn_datablksz) || |
|
200 |
len < dn->dn_datablksz) { |
|
201 |
err = dmu_tx_check_ioerr(zio, dn, 0, start); |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
202 |
if (err) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
203 |
goto out; |
1544 | 204 |
} |
205 |
||
206 |
/* last level-0 block */ |
|
2082 | 207 |
end = (off+len-1) >> dn->dn_datablkshift; |
208 |
if (end != start && |
|
209 |
P2PHASE(off+len, dn->dn_datablksz)) { |
|
1544 | 210 |
err = dmu_tx_check_ioerr(zio, dn, 0, end); |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
211 |
if (err) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
212 |
goto out; |
1544 | 213 |
} |
214 |
||
215 |
/* level-1 blocks */ |
|
216 |
if (dn->dn_nlevels > 1) { |
|
217 |
start >>= dn->dn_indblkshift - SPA_BLKPTRSHIFT; |
|
218 |
end >>= dn->dn_indblkshift - SPA_BLKPTRSHIFT; |
|
219 |
for (i = start+1; i < end; i++) { |
|
220 |
err = dmu_tx_check_ioerr(zio, dn, 1, i); |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
221 |
if (err) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
222 |
goto out; |
1544 | 223 |
} |
224 |
} |
|
225 |
||
226 |
err = zio_wait(zio); |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
227 |
if (err) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
228 |
goto out; |
1544 | 229 |
} |
230 |
} |
|
231 |
||
232 |
/* |
|
789 | 233 |
* If there's more than one block, the blocksize can't change, |
234 |
* so we can make a more precise estimate. Alternatively, |
|
235 |
* if the dnode's ibs is larger than max_ibs, always use that. |
|
236 |
* This ensures that if we reduce DN_MAX_INDBLKSHIFT, |
|
237 |
* the code will still work correctly on existing pools. |
|
238 |
*/ |
|
239 |
if (dn && (dn->dn_maxblkid != 0 || dn->dn_indblkshift > max_ibs)) { |
|
240 |
min_ibs = max_ibs = dn->dn_indblkshift; |
|
241 |
if (dn->dn_datablkshift != 0) |
|
242 |
min_bs = max_bs = dn->dn_datablkshift; |
|
243 |
} |
|
244 |
||
245 |
/* |
|
246 |
* 'end' is the last thing we will access, not one past. |
|
247 |
* This way we won't overflow when accessing the last byte. |
|
248 |
*/ |
|
249 |
start = P2ALIGN(off, 1ULL << max_bs); |
|
250 |
end = P2ROUNDUP(off + len, 1ULL << max_bs) - 1; |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
251 |
txh->txh_space_towrite += end - start + 1; |
789 | 252 |
|
253 |
start >>= min_bs; |
|
254 |
end >>= min_bs; |
|
255 |
||
256 |
epbs = min_ibs - SPA_BLKPTRSHIFT; |
|
257 |
||
258 |
/* |
|
259 |
* The object contains at most 2^(64 - min_bs) blocks, |
|
260 |
* and each indirect level maps 2^epbs. |
|
261 |
*/ |
|
262 |
for (bits = 64 - min_bs; bits >= 0; bits -= epbs) { |
|
263 |
start >>= epbs; |
|
264 |
end >>= epbs; |
|
265 |
/* |
|
266 |
* If we increase the number of levels of indirection, |
|
267 |
* we'll need new blkid=0 indirect blocks. If start == 0, |
|
268 |
* we're already accounting for that blocks; and if end == 0, |
|
269 |
* we can't increase the number of levels beyond that. |
|
270 |
*/ |
|
271 |
if (start != 0 && end != 0) |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
272 |
txh->txh_space_towrite += 1ULL << max_ibs; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
273 |
txh->txh_space_towrite += (end - start + 1) << max_ibs; |
789 | 274 |
} |
275 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
276 |
ASSERT(txh->txh_space_towrite < 2 * DMU_MAX_ACCESS); |
789 | 277 |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
278 |
out: |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
279 |
if (err) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
280 |
txh->txh_tx->tx_err = err; |
789 | 281 |
} |
282 |
||
283 |
static void |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
284 |
dmu_tx_count_dnode(dmu_tx_hold_t *txh) |
789 | 285 |
{ |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
286 |
dnode_t *dn = txh->txh_dnode; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
287 |
dnode_t *mdn = txh->txh_tx->tx_objset->os->os_meta_dnode; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
288 |
uint64_t space = mdn->dn_datablksz + |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
289 |
((mdn->dn_nlevels-1) << mdn->dn_indblkshift); |
789 | 290 |
|
291 |
if (dn && dn->dn_dbuf->db_blkptr && |
|
292 |
dsl_dataset_block_freeable(dn->dn_objset->os_dsl_dataset, |
|
1544 | 293 |
dn->dn_dbuf->db_blkptr->blk_birth)) { |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
294 |
txh->txh_space_tooverwrite += space; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
295 |
} else { |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
296 |
txh->txh_space_towrite += space; |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
297 |
if (dn && dn->dn_dbuf->db_blkptr) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
298 |
txh->txh_space_tounref += space; |
789 | 299 |
} |
300 |
} |
|
301 |
||
302 |
void |
|
303 |
dmu_tx_hold_write(dmu_tx_t *tx, uint64_t object, uint64_t off, int len) |
|
304 |
{ |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
305 |
dmu_tx_hold_t *txh; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
306 |
|
789 | 307 |
ASSERT(tx->tx_txg == 0); |
1544 | 308 |
ASSERT(len < DMU_MAX_ACCESS); |
1819 | 309 |
ASSERT(len == 0 || UINT64_MAX - off >= len - 1); |
789 | 310 |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
311 |
txh = dmu_tx_hold_object_impl(tx, tx->tx_objset, |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
312 |
object, THT_WRITE, off, len); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
313 |
if (txh == NULL) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
314 |
return; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
315 |
|
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
316 |
dmu_tx_count_write(txh, off, len); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
317 |
dmu_tx_count_dnode(txh); |
789 | 318 |
} |
319 |
||
320 |
static void |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
321 |
dmu_tx_count_free(dmu_tx_hold_t *txh, uint64_t off, uint64_t len) |
789 | 322 |
{ |
323 |
uint64_t blkid, nblks; |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
324 |
uint64_t space = 0, unref = 0; |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
325 |
dnode_t *dn = txh->txh_dnode; |
789 | 326 |
dsl_dataset_t *ds = dn->dn_objset->os_dsl_dataset; |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
327 |
spa_t *spa = txh->txh_tx->tx_pool->dp_spa; |
1600
d1ef3e135d5a
6397264 zfs-s10-0311:assertion failed:((&dnp->dn_blkptr[0])->blk_birth == 0)
ahrens
parents:
1596
diff
changeset
|
328 |
int dirty; |
789 | 329 |
|
330 |
/* |
|
1600
d1ef3e135d5a
6397264 zfs-s10-0311:assertion failed:((&dnp->dn_blkptr[0])->blk_birth == 0)
ahrens
parents:
1596
diff
changeset
|
331 |
* We don't need to use any locking to check for dirtyness |
d1ef3e135d5a
6397264 zfs-s10-0311:assertion failed:((&dnp->dn_blkptr[0])->blk_birth == 0)
ahrens
parents:
1596
diff
changeset
|
332 |
* because it's OK if we get stale data -- the dnode may become |
1758
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1686
diff
changeset
|
333 |
* dirty immediately after our check anyway. This is just a |
d0750a16db04
6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents:
1686
diff
changeset
|
334 |
* means to avoid the expensive count when we aren't sure we |
1600
d1ef3e135d5a
6397264 zfs-s10-0311:assertion failed:((&dnp->dn_blkptr[0])->blk_birth == 0)
ahrens
parents:
1596
diff
changeset
|
335 |
* need it. We need to be able to deal with a dirty dnode. |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
336 |
*/ |
1600
d1ef3e135d5a
6397264 zfs-s10-0311:assertion failed:((&dnp->dn_blkptr[0])->blk_birth == 0)
ahrens
parents:
1596
diff
changeset
|
337 |
dirty = list_link_active(&dn->dn_dirty_link[0]) | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
338 |
list_link_active(&dn->dn_dirty_link[1]) | |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
339 |
list_link_active(&dn->dn_dirty_link[2]) | |
1600
d1ef3e135d5a
6397264 zfs-s10-0311:assertion failed:((&dnp->dn_blkptr[0])->blk_birth == 0)
ahrens
parents:
1596
diff
changeset
|
340 |
list_link_active(&dn->dn_dirty_link[3]); |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
341 |
if (dirty || dn->dn_assigned_txg || dn->dn_phys->dn_nlevels == 0) |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
342 |
return; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
343 |
|
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
344 |
/* |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
345 |
* the struct_rwlock protects us against dn_phys->dn_nlevels |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
346 |
* changing, in case (against all odds) we manage to dirty & |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
347 |
* sync out the changes after we check for being dirty. |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
348 |
* also, dbuf_hold_impl() wants us to have the struct_rwlock. |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
349 |
* |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
350 |
* It's fine to use dn_datablkshift rather than the dn_phys |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
351 |
* equivalent because if it is changing, maxblkid==0 and we will |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
352 |
* bail. |
789 | 353 |
*/ |
354 |
rw_enter(&dn->dn_struct_rwlock, RW_READER); |
|
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
355 |
if (dn->dn_phys->dn_maxblkid == 0) { |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
356 |
if (off == 0 && len >= dn->dn_datablksz) { |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
357 |
blkid = 0; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
358 |
nblks = 1; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
359 |
} else { |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
360 |
rw_exit(&dn->dn_struct_rwlock); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
361 |
return; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
362 |
} |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
363 |
} else { |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
364 |
blkid = off >> dn->dn_datablkshift; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
365 |
nblks = (off + len) >> dn->dn_datablkshift; |
789 | 366 |
|
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
367 |
if (blkid >= dn->dn_phys->dn_maxblkid) { |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
368 |
rw_exit(&dn->dn_struct_rwlock); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
369 |
return; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
370 |
} |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
371 |
if (blkid + nblks > dn->dn_phys->dn_maxblkid) |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
372 |
nblks = dn->dn_phys->dn_maxblkid - blkid; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
373 |
|
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
374 |
/* don't bother after 128,000 blocks */ |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
375 |
nblks = MIN(nblks, 128*1024); |
1544 | 376 |
} |
789 | 377 |
|
378 |
if (dn->dn_phys->dn_nlevels == 1) { |
|
379 |
int i; |
|
380 |
for (i = 0; i < nblks; i++) { |
|
381 |
blkptr_t *bp = dn->dn_phys->dn_blkptr; |
|
382 |
ASSERT3U(blkid + i, <, dn->dn_phys->dn_nblkptr); |
|
383 |
bp += blkid + i; |
|
1544 | 384 |
if (dsl_dataset_block_freeable(ds, bp->blk_birth)) { |
789 | 385 |
dprintf_bp(bp, "can free old%s", ""); |
2082 | 386 |
space += bp_get_dasize(spa, bp); |
789 | 387 |
} |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
388 |
unref += BP_GET_ASIZE(bp); |
789 | 389 |
} |
1544 | 390 |
nblks = 0; |
789 | 391 |
} |
392 |
||
393 |
while (nblks) { |
|
394 |
dmu_buf_impl_t *dbuf; |
|
395 |
int err, epbs, blkoff, tochk; |
|
396 |
||
397 |
epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT; |
|
398 |
blkoff = P2PHASE(blkid, 1<<epbs); |
|
399 |
tochk = MIN((1<<epbs) - blkoff, nblks); |
|
400 |
||
401 |
err = dbuf_hold_impl(dn, 1, blkid >> epbs, TRUE, FTAG, &dbuf); |
|
402 |
if (err == 0) { |
|
403 |
int i; |
|
404 |
blkptr_t *bp; |
|
405 |
||
1544 | 406 |
err = dbuf_read(dbuf, NULL, |
407 |
DB_RF_HAVESTRUCT | DB_RF_CANFAIL); |
|
408 |
if (err != 0) { |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
409 |
txh->txh_tx->tx_err = err; |
1544 | 410 |
dbuf_rele(dbuf, FTAG); |
411 |
break; |
|
412 |
} |
|
789 | 413 |
|
414 |
bp = dbuf->db.db_data; |
|
415 |
bp += blkoff; |
|
416 |
||
417 |
for (i = 0; i < tochk; i++) { |
|
418 |
if (dsl_dataset_block_freeable(ds, |
|
1544 | 419 |
bp[i].blk_birth)) { |
789 | 420 |
dprintf_bp(&bp[i], |
421 |
"can free old%s", ""); |
|
2082 | 422 |
space += bp_get_dasize(spa, &bp[i]); |
789 | 423 |
} |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
424 |
unref += BP_GET_ASIZE(bp); |
789 | 425 |
} |
1544 | 426 |
dbuf_rele(dbuf, FTAG); |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
427 |
} |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
428 |
if (err && err != ENOENT) { |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
429 |
txh->txh_tx->tx_err = err; |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
430 |
break; |
789 | 431 |
} |
432 |
||
433 |
blkid += tochk; |
|
434 |
nblks -= tochk; |
|
435 |
} |
|
436 |
rw_exit(&dn->dn_struct_rwlock); |
|
437 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
438 |
txh->txh_space_tofree += space; |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
439 |
txh->txh_space_tounref += unref; |
789 | 440 |
} |
441 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
442 |
void |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
443 |
dmu_tx_hold_free(dmu_tx_t *tx, uint64_t object, uint64_t off, uint64_t len) |
789 | 444 |
{ |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
445 |
dmu_tx_hold_t *txh; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
446 |
dnode_t *dn; |
1544 | 447 |
uint64_t start, end, i; |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
448 |
int err, shift; |
1544 | 449 |
zio_t *zio; |
789 | 450 |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
451 |
ASSERT(tx->tx_txg == 0); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
452 |
|
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
453 |
txh = dmu_tx_hold_object_impl(tx, tx->tx_objset, |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
454 |
object, THT_FREE, off, len); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
455 |
if (txh == NULL) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
456 |
return; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
457 |
dn = txh->txh_dnode; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
458 |
|
789 | 459 |
/* first block */ |
1793
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
460 |
if (off != 0) |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
461 |
dmu_tx_count_write(txh, off, 1); |
789 | 462 |
/* last block */ |
463 |
if (len != DMU_OBJECT_END) |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
464 |
dmu_tx_count_write(txh, off+len, 1); |
789 | 465 |
|
466 |
if (off >= (dn->dn_maxblkid+1) * dn->dn_datablksz) |
|
467 |
return; |
|
468 |
if (len == DMU_OBJECT_END) |
|
469 |
len = (dn->dn_maxblkid+1) * dn->dn_datablksz - off; |
|
470 |
||
1544 | 471 |
/* |
472 |
* For i/o error checking, read the first and last level-0 |
|
473 |
* blocks, and all the level-1 blocks. The above count_write's |
|
474 |
* will take care of the level-0 blocks. |
|
475 |
*/ |
|
1793
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
476 |
if (dn->dn_nlevels > 1) { |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
477 |
shift = dn->dn_datablkshift + dn->dn_indblkshift - |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
478 |
SPA_BLKPTRSHIFT; |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
479 |
start = off >> shift; |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
480 |
end = dn->dn_datablkshift ? ((off+len) >> shift) : 0; |
1544 | 481 |
|
1793
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
482 |
zio = zio_root(tx->tx_pool->dp_spa, |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
483 |
NULL, NULL, ZIO_FLAG_CANFAIL); |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
484 |
for (i = start; i <= end; i++) { |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
485 |
uint64_t ibyte = i << shift; |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2199
diff
changeset
|
486 |
err = dnode_next_offset(dn, FALSE, &ibyte, 2, 1, 0); |
1793
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
487 |
i = ibyte >> shift; |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
488 |
if (err == ESRCH) |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
489 |
break; |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
490 |
if (err) { |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
491 |
tx->tx_err = err; |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
492 |
return; |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
493 |
} |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
494 |
|
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
495 |
err = dmu_tx_check_ioerr(zio, dn, 1, i); |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
496 |
if (err) { |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
497 |
tx->tx_err = err; |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
498 |
return; |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
499 |
} |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
500 |
} |
d371fba21a3e
6407444 unhandled i/o error from dnode_next_offset_level()
ahrens
parents:
1758
diff
changeset
|
501 |
err = zio_wait(zio); |
1544 | 502 |
if (err) { |
503 |
tx->tx_err = err; |
|
504 |
return; |
|
505 |
} |
|
506 |
} |
|
507 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
508 |
dmu_tx_count_dnode(txh); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
509 |
dmu_tx_count_free(txh, off, len); |
789 | 510 |
} |
511 |
||
512 |
void |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
513 |
dmu_tx_hold_zap(dmu_tx_t *tx, uint64_t object, int add, char *name) |
789 | 514 |
{ |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
515 |
dmu_tx_hold_t *txh; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
516 |
dnode_t *dn; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
517 |
uint64_t nblocks; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
518 |
int epbs, err; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
519 |
|
789 | 520 |
ASSERT(tx->tx_txg == 0); |
521 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
522 |
txh = dmu_tx_hold_object_impl(tx, tx->tx_objset, |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
523 |
object, THT_ZAP, add, (uintptr_t)name); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
524 |
if (txh == NULL) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
525 |
return; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
526 |
dn = txh->txh_dnode; |
789 | 527 |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
528 |
dmu_tx_count_dnode(txh); |
789 | 529 |
|
530 |
if (dn == NULL) { |
|
531 |
/* |
|
1544 | 532 |
* We will be able to fit a new object's entries into one leaf |
789 | 533 |
* block. So there will be at most 2 blocks total, |
534 |
* including the header block. |
|
535 |
*/ |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
536 |
dmu_tx_count_write(txh, 0, 2 << fzap_default_block_shift); |
789 | 537 |
return; |
538 |
} |
|
539 |
||
540 |
ASSERT3P(dmu_ot[dn->dn_type].ot_byteswap, ==, zap_byteswap); |
|
541 |
||
1544 | 542 |
if (dn->dn_maxblkid == 0 && !add) { |
789 | 543 |
/* |
544 |
* If there is only one block (i.e. this is a micro-zap) |
|
1544 | 545 |
* and we are not adding anything, the accounting is simple. |
789 | 546 |
*/ |
1544 | 547 |
err = dmu_tx_check_ioerr(NULL, dn, 0, 0); |
548 |
if (err) { |
|
549 |
tx->tx_err = err; |
|
550 |
return; |
|
551 |
} |
|
552 |
||
3245
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3025
diff
changeset
|
553 |
/* |
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3025
diff
changeset
|
554 |
* Use max block size here, since we don't know how much |
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3025
diff
changeset
|
555 |
* the size will change between now and the dbuf dirty call. |
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3025
diff
changeset
|
556 |
*/ |
789 | 557 |
if (dsl_dataset_block_freeable(dn->dn_objset->os_dsl_dataset, |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
558 |
dn->dn_phys->dn_blkptr[0].blk_birth)) { |
3245
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3025
diff
changeset
|
559 |
txh->txh_space_tooverwrite += SPA_MAXBLOCKSIZE; |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
560 |
} else { |
3245
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3025
diff
changeset
|
561 |
txh->txh_space_towrite += SPA_MAXBLOCKSIZE; |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
562 |
txh->txh_space_tounref += |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
563 |
BP_GET_ASIZE(dn->dn_phys->dn_blkptr); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
564 |
} |
789 | 565 |
return; |
566 |
} |
|
567 |
||
1544 | 568 |
if (dn->dn_maxblkid > 0 && name) { |
569 |
/* |
|
570 |
* access the name in this fat-zap so that we'll check |
|
571 |
* for i/o errors to the leaf blocks, etc. |
|
572 |
*/ |
|
573 |
err = zap_lookup(&dn->dn_objset->os, dn->dn_object, name, |
|
574 |
8, 0, NULL); |
|
575 |
if (err == EIO) { |
|
576 |
tx->tx_err = err; |
|
577 |
return; |
|
578 |
} |
|
579 |
} |
|
580 |
||
789 | 581 |
/* |
1544 | 582 |
* 3 blocks overwritten: target leaf, ptrtbl block, header block |
583 |
* 3 new blocks written if adding: new split leaf, 2 grown ptrtbl blocks |
|
789 | 584 |
*/ |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
585 |
dmu_tx_count_write(txh, dn->dn_maxblkid * dn->dn_datablksz, |
1544 | 586 |
(3 + add ? 3 : 0) << dn->dn_datablkshift); |
789 | 587 |
|
588 |
/* |
|
589 |
* If the modified blocks are scattered to the four winds, |
|
590 |
* we'll have to modify an indirect twig for each. |
|
591 |
*/ |
|
592 |
epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT; |
|
593 |
for (nblocks = dn->dn_maxblkid >> epbs; nblocks != 0; nblocks >>= epbs) |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
594 |
txh->txh_space_towrite += 3 << dn->dn_indblkshift; |
789 | 595 |
} |
596 |
||
597 |
void |
|
598 |
dmu_tx_hold_bonus(dmu_tx_t *tx, uint64_t object) |
|
599 |
{ |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
600 |
dmu_tx_hold_t *txh; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
601 |
|
789 | 602 |
ASSERT(tx->tx_txg == 0); |
603 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
604 |
txh = dmu_tx_hold_object_impl(tx, tx->tx_objset, |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
605 |
object, THT_BONUS, 0, 0); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
606 |
if (txh) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
607 |
dmu_tx_count_dnode(txh); |
789 | 608 |
} |
609 |
||
610 |
void |
|
611 |
dmu_tx_hold_space(dmu_tx_t *tx, uint64_t space) |
|
612 |
{ |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
613 |
dmu_tx_hold_t *txh; |
789 | 614 |
ASSERT(tx->tx_txg == 0); |
615 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
616 |
txh = dmu_tx_hold_object_impl(tx, tx->tx_objset, |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
617 |
DMU_NEW_OBJECT, THT_SPACE, space, 0); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
618 |
|
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
619 |
txh->txh_space_towrite += space; |
789 | 620 |
} |
621 |
||
622 |
int |
|
623 |
dmu_tx_holds(dmu_tx_t *tx, uint64_t object) |
|
624 |
{ |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
625 |
dmu_tx_hold_t *txh; |
789 | 626 |
int holds = 0; |
627 |
||
628 |
/* |
|
629 |
* By asserting that the tx is assigned, we're counting the |
|
630 |
* number of dn_tx_holds, which is the same as the number of |
|
631 |
* dn_holds. Otherwise, we'd be counting dn_holds, but |
|
632 |
* dn_tx_holds could be 0. |
|
633 |
*/ |
|
634 |
ASSERT(tx->tx_txg != 0); |
|
635 |
||
636 |
/* if (tx->tx_anyobj == TRUE) */ |
|
637 |
/* return (0); */ |
|
638 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
639 |
for (txh = list_head(&tx->tx_holds); txh; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
640 |
txh = list_next(&tx->tx_holds, txh)) { |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
641 |
if (txh->txh_dnode && txh->txh_dnode->dn_object == object) |
789 | 642 |
holds++; |
643 |
} |
|
644 |
||
645 |
return (holds); |
|
646 |
} |
|
647 |
||
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
648 |
#ifdef ZFS_DEBUG |
789 | 649 |
void |
650 |
dmu_tx_dirty_buf(dmu_tx_t *tx, dmu_buf_impl_t *db) |
|
651 |
{ |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
652 |
dmu_tx_hold_t *txh; |
789 | 653 |
int match_object = FALSE, match_offset = FALSE; |
654 |
dnode_t *dn = db->db_dnode; |
|
655 |
||
656 |
ASSERT(tx->tx_txg != 0); |
|
657 |
ASSERT(tx->tx_objset == NULL || dn->dn_objset == tx->tx_objset->os); |
|
658 |
ASSERT3U(dn->dn_object, ==, db->db.db_object); |
|
659 |
||
660 |
if (tx->tx_anyobj) |
|
661 |
return; |
|
662 |
||
663 |
/* XXX No checking on the meta dnode for now */ |
|
1544 | 664 |
if (db->db.db_object == DMU_META_DNODE_OBJECT) |
789 | 665 |
return; |
666 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
667 |
for (txh = list_head(&tx->tx_holds); txh; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
668 |
txh = list_next(&tx->tx_holds, txh)) { |
789 | 669 |
ASSERT(dn == NULL || dn->dn_assigned_txg == tx->tx_txg); |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
670 |
if (txh->txh_dnode == dn && txh->txh_type != THT_NEWOBJECT) |
789 | 671 |
match_object = TRUE; |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
672 |
if (txh->txh_dnode == NULL || txh->txh_dnode == dn) { |
789 | 673 |
int datablkshift = dn->dn_datablkshift ? |
674 |
dn->dn_datablkshift : SPA_MAXBLOCKSHIFT; |
|
675 |
int epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT; |
|
676 |
int shift = datablkshift + epbs * db->db_level; |
|
677 |
uint64_t beginblk = shift >= 64 ? 0 : |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
678 |
(txh->txh_arg1 >> shift); |
789 | 679 |
uint64_t endblk = shift >= 64 ? 0 : |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
680 |
((txh->txh_arg1 + txh->txh_arg2 - 1) >> shift); |
789 | 681 |
uint64_t blkid = db->db_blkid; |
682 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
683 |
/* XXX txh_arg2 better not be zero... */ |
789 | 684 |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
685 |
dprintf("found txh type %x beginblk=%llx endblk=%llx\n", |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
686 |
txh->txh_type, beginblk, endblk); |
789 | 687 |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
688 |
switch (txh->txh_type) { |
789 | 689 |
case THT_WRITE: |
690 |
if (blkid >= beginblk && blkid <= endblk) |
|
691 |
match_offset = TRUE; |
|
692 |
/* |
|
693 |
* We will let this hold work for the bonus |
|
694 |
* buffer so that we don't need to hold it |
|
695 |
* when creating a new object. |
|
696 |
*/ |
|
697 |
if (blkid == DB_BONUS_BLKID) |
|
698 |
match_offset = TRUE; |
|
699 |
/* |
|
700 |
* They might have to increase nlevels, |
|
701 |
* thus dirtying the new TLIBs. Or the |
|
702 |
* might have to change the block size, |
|
703 |
* thus dirying the new lvl=0 blk=0. |
|
704 |
*/ |
|
705 |
if (blkid == 0) |
|
706 |
match_offset = TRUE; |
|
707 |
break; |
|
708 |
case THT_FREE: |
|
709 |
if (blkid == beginblk && |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
710 |
(txh->txh_arg1 != 0 || |
789 | 711 |
dn->dn_maxblkid == 0)) |
712 |
match_offset = TRUE; |
|
713 |
if (blkid == endblk && |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
714 |
txh->txh_arg2 != DMU_OBJECT_END) |
789 | 715 |
match_offset = TRUE; |
716 |
break; |
|
717 |
case THT_BONUS: |
|
718 |
if (blkid == DB_BONUS_BLKID) |
|
719 |
match_offset = TRUE; |
|
720 |
break; |
|
721 |
case THT_ZAP: |
|
722 |
match_offset = TRUE; |
|
723 |
break; |
|
724 |
case THT_NEWOBJECT: |
|
725 |
match_object = TRUE; |
|
726 |
break; |
|
727 |
default: |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
728 |
ASSERT(!"bad txh_type"); |
789 | 729 |
} |
730 |
} |
|
731 |
if (match_object && match_offset) |
|
732 |
return; |
|
733 |
} |
|
734 |
panic("dirtying dbuf obj=%llx lvl=%u blkid=%llx but not tx_held\n", |
|
735 |
(u_longlong_t)db->db.db_object, db->db_level, |
|
736 |
(u_longlong_t)db->db_blkid); |
|
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
737 |
} |
789 | 738 |
#endif |
739 |
||
740 |
static int |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
741 |
dmu_tx_try_assign(dmu_tx_t *tx, uint64_t txg_how) |
789 | 742 |
{ |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
743 |
dmu_tx_hold_t *txh; |
5329 | 744 |
spa_t *spa = tx->tx_pool->dp_spa; |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
745 |
uint64_t lsize, asize, fsize, usize; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
746 |
uint64_t towrite, tofree, tooverwrite, tounref; |
789 | 747 |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
748 |
ASSERT3U(tx->tx_txg, ==, 0); |
5329 | 749 |
|
1544 | 750 |
if (tx->tx_err) |
751 |
return (tx->tx_err); |
|
789 | 752 |
|
5329 | 753 |
if (spa_state(spa) == POOL_STATE_IO_FAILURE) { |
754 |
/* |
|
755 |
* If the user has indicated a blocking failure mode |
|
756 |
* then return ERESTART which will block in dmu_tx_wait(). |
|
757 |
* Otherwise, return EIO so that an error can get |
|
758 |
* propagated back to the VOP calls. |
|
759 |
* |
|
760 |
* Note that we always honor the txg_how flag regardless |
|
761 |
* of the failuremode setting. |
|
762 |
*/ |
|
763 |
if (spa_get_failmode(spa) == ZIO_FAILURE_MODE_CONTINUE && |
|
764 |
txg_how != TXG_WAIT) |
|
765 |
return (EIO); |
|
766 |
||
767 |
return (ERESTART); |
|
768 |
} |
|
769 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
770 |
tx->tx_txg = txg_hold_open(tx->tx_pool, &tx->tx_txgh); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
771 |
tx->tx_needassign_txh = NULL; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
772 |
|
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
773 |
/* |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
774 |
* NB: No error returns are allowed after txg_hold_open, but |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
775 |
* before processing the dnode holds, due to the |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
776 |
* dmu_tx_unassign() logic. |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
777 |
*/ |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
778 |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
779 |
towrite = tofree = tooverwrite = tounref = 0; |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
780 |
for (txh = list_head(&tx->tx_holds); txh; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
781 |
txh = list_next(&tx->tx_holds, txh)) { |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
782 |
dnode_t *dn = txh->txh_dnode; |
789 | 783 |
if (dn != NULL) { |
784 |
mutex_enter(&dn->dn_mtx); |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
785 |
if (dn->dn_assigned_txg == tx->tx_txg - 1) { |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
786 |
mutex_exit(&dn->dn_mtx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
787 |
tx->tx_needassign_txh = txh; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
788 |
return (ERESTART); |
789 | 789 |
} |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
790 |
if (dn->dn_assigned_txg == 0) |
789 | 791 |
dn->dn_assigned_txg = tx->tx_txg; |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
792 |
ASSERT3U(dn->dn_assigned_txg, ==, tx->tx_txg); |
789 | 793 |
(void) refcount_add(&dn->dn_tx_holds, tx); |
794 |
mutex_exit(&dn->dn_mtx); |
|
795 |
} |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
796 |
towrite += txh->txh_space_towrite; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
797 |
tofree += txh->txh_space_tofree; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
798 |
tooverwrite += txh->txh_space_tooverwrite; |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
799 |
tounref += txh->txh_space_tounref; |
1544 | 800 |
} |
801 |
||
802 |
/* |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
803 |
* NB: This check must be after we've held the dnodes, so that |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
804 |
* the dmu_tx_unassign() logic will work properly |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
805 |
*/ |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
806 |
if (txg_how >= TXG_INITIAL && txg_how != tx->tx_txg) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
807 |
return (ERESTART); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
808 |
|
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
809 |
/* |
1544 | 810 |
* If a snapshot has been taken since we made our estimates, |
811 |
* assume that we won't be able to free or overwrite anything. |
|
812 |
*/ |
|
813 |
if (tx->tx_objset && |
|
814 |
dsl_dataset_prev_snap_txg(tx->tx_objset->os->os_dsl_dataset) > |
|
815 |
tx->tx_lastsnap_txg) { |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
816 |
towrite += tooverwrite; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
817 |
tooverwrite = tofree = 0; |
789 | 818 |
} |
819 |
||
820 |
/* |
|
821 |
* Convert logical size to worst-case allocated size. |
|
822 |
*/ |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
823 |
fsize = spa_get_asize(tx->tx_pool->dp_spa, tooverwrite) + tofree; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
824 |
lsize = towrite + tooverwrite; |
789 | 825 |
asize = spa_get_asize(tx->tx_pool->dp_spa, lsize); |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
826 |
usize = spa_get_asize(tx->tx_pool->dp_spa, tounref); |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
827 |
|
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
828 |
#ifdef ZFS_DEBUG |
789 | 829 |
tx->tx_space_towrite = asize; |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
830 |
tx->tx_space_tofree = tofree; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
831 |
tx->tx_space_tooverwrite = tooverwrite; |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
832 |
tx->tx_space_tounref = tounref; |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
833 |
#endif |
789 | 834 |
|
835 |
if (tx->tx_dir && asize != 0) { |
|
836 |
int err = dsl_dir_tempreserve_space(tx->tx_dir, |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5329
diff
changeset
|
837 |
lsize, asize, fsize, usize, &tx->tx_tempreserve_cookie, tx); |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
838 |
if (err) |
789 | 839 |
return (err); |
840 |
} |
|
841 |
||
842 |
return (0); |
|
843 |
} |
|
844 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
845 |
static void |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
846 |
dmu_tx_unassign(dmu_tx_t *tx) |
789 | 847 |
{ |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
848 |
dmu_tx_hold_t *txh; |
789 | 849 |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
850 |
if (tx->tx_txg == 0) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
851 |
return; |
789 | 852 |
|
853 |
txg_rele_to_quiesce(&tx->tx_txgh); |
|
854 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
855 |
for (txh = list_head(&tx->tx_holds); txh != tx->tx_needassign_txh; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
856 |
txh = list_next(&tx->tx_holds, txh)) { |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
857 |
dnode_t *dn = txh->txh_dnode; |
789 | 858 |
|
859 |
if (dn == NULL) |
|
860 |
continue; |
|
861 |
mutex_enter(&dn->dn_mtx); |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
862 |
ASSERT3U(dn->dn_assigned_txg, ==, tx->tx_txg); |
789 | 863 |
|
864 |
if (refcount_remove(&dn->dn_tx_holds, tx) == 0) { |
|
865 |
dn->dn_assigned_txg = 0; |
|
866 |
cv_broadcast(&dn->dn_notxholds); |
|
867 |
} |
|
868 |
mutex_exit(&dn->dn_mtx); |
|
869 |
} |
|
870 |
||
871 |
txg_rele_to_sync(&tx->tx_txgh); |
|
872 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
873 |
tx->tx_lasttried_txg = tx->tx_txg; |
789 | 874 |
tx->tx_txg = 0; |
875 |
} |
|
876 |
||
877 |
/* |
|
878 |
* Assign tx to a transaction group. txg_how can be one of: |
|
879 |
* |
|
880 |
* (1) TXG_WAIT. If the current open txg is full, waits until there's |
|
881 |
* a new one. This should be used when you're not holding locks. |
|
882 |
* If will only fail if we're truly out of space (or over quota). |
|
883 |
* |
|
884 |
* (2) TXG_NOWAIT. If we can't assign into the current open txg without |
|
885 |
* blocking, returns immediately with ERESTART. This should be used |
|
886 |
* whenever you're holding locks. On an ERESTART error, the caller |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
887 |
* should drop locks, do a dmu_tx_wait(tx), and try again. |
789 | 888 |
* |
889 |
* (3) A specific txg. Use this if you need to ensure that multiple |
|
890 |
* transactions all sync in the same txg. Like TXG_NOWAIT, it |
|
891 |
* returns ERESTART if it can't assign you into the requested txg. |
|
892 |
*/ |
|
893 |
int |
|
894 |
dmu_tx_assign(dmu_tx_t *tx, uint64_t txg_how) |
|
895 |
{ |
|
896 |
int err; |
|
897 |
||
898 |
ASSERT(tx->tx_txg == 0); |
|
899 |
ASSERT(txg_how != 0); |
|
900 |
ASSERT(!dsl_pool_sync_context(tx->tx_pool)); |
|
901 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
902 |
while ((err = dmu_tx_try_assign(tx, txg_how)) != 0) { |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
903 |
dmu_tx_unassign(tx); |
789 | 904 |
|
905 |
if (err != ERESTART || txg_how != TXG_WAIT) |
|
906 |
return (err); |
|
907 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
908 |
dmu_tx_wait(tx); |
789 | 909 |
} |
910 |
||
911 |
txg_rele_to_quiesce(&tx->tx_txgh); |
|
912 |
||
913 |
return (0); |
|
914 |
} |
|
915 |
||
916 |
void |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
917 |
dmu_tx_wait(dmu_tx_t *tx) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
918 |
{ |
5329 | 919 |
spa_t *spa = tx->tx_pool->dp_spa; |
920 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
921 |
ASSERT(tx->tx_txg == 0); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
922 |
|
5329 | 923 |
/* |
924 |
* It's possible that the pool has become active after this thread |
|
925 |
* has tried to obtain a tx. If that's the case then his |
|
926 |
* tx_lasttried_txg would not have been assigned. |
|
927 |
*/ |
|
928 |
if (spa_state(spa) == POOL_STATE_IO_FAILURE || |
|
929 |
tx->tx_lasttried_txg == 0) { |
|
930 |
txg_wait_synced(tx->tx_pool, spa_last_synced_txg(spa) + 1); |
|
931 |
} else if (tx->tx_needassign_txh) { |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
932 |
dnode_t *dn = tx->tx_needassign_txh->txh_dnode; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
933 |
|
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
934 |
mutex_enter(&dn->dn_mtx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
935 |
while (dn->dn_assigned_txg == tx->tx_lasttried_txg - 1) |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
936 |
cv_wait(&dn->dn_notxholds, &dn->dn_mtx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
937 |
mutex_exit(&dn->dn_mtx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
938 |
tx->tx_needassign_txh = NULL; |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
939 |
} else { |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
940 |
txg_wait_open(tx->tx_pool, tx->tx_lasttried_txg + 1); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
941 |
} |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
942 |
} |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
943 |
|
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
944 |
void |
789 | 945 |
dmu_tx_willuse_space(dmu_tx_t *tx, int64_t delta) |
946 |
{ |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
947 |
#ifdef ZFS_DEBUG |
789 | 948 |
if (tx->tx_dir == NULL || delta == 0) |
949 |
return; |
|
950 |
||
951 |
if (delta > 0) { |
|
952 |
ASSERT3U(refcount_count(&tx->tx_space_written) + delta, <=, |
|
953 |
tx->tx_space_towrite); |
|
954 |
(void) refcount_add_many(&tx->tx_space_written, delta, NULL); |
|
955 |
} else { |
|
956 |
(void) refcount_add_many(&tx->tx_space_freed, -delta, NULL); |
|
957 |
} |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
958 |
#endif |
789 | 959 |
} |
960 |
||
961 |
void |
|
962 |
dmu_tx_commit(dmu_tx_t *tx) |
|
963 |
{ |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
964 |
dmu_tx_hold_t *txh; |
789 | 965 |
|
966 |
ASSERT(tx->tx_txg != 0); |
|
967 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
968 |
while (txh = list_head(&tx->tx_holds)) { |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
969 |
dnode_t *dn = txh->txh_dnode; |
789 | 970 |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
971 |
list_remove(&tx->tx_holds, txh); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
972 |
kmem_free(txh, sizeof (dmu_tx_hold_t)); |
789 | 973 |
if (dn == NULL) |
974 |
continue; |
|
975 |
mutex_enter(&dn->dn_mtx); |
|
976 |
ASSERT3U(dn->dn_assigned_txg, ==, tx->tx_txg); |
|
977 |
||
978 |
if (refcount_remove(&dn->dn_tx_holds, tx) == 0) { |
|
979 |
dn->dn_assigned_txg = 0; |
|
980 |
cv_broadcast(&dn->dn_notxholds); |
|
981 |
} |
|
982 |
mutex_exit(&dn->dn_mtx); |
|
983 |
dnode_rele(dn, tx); |
|
984 |
} |
|
985 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
986 |
if (tx->tx_tempreserve_cookie) |
789 | 987 |
dsl_dir_tempreserve_clear(tx->tx_tempreserve_cookie, tx); |
988 |
||
989 |
if (tx->tx_anyobj == FALSE) |
|
990 |
txg_rele_to_sync(&tx->tx_txgh); |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
991 |
#ifdef ZFS_DEBUG |
789 | 992 |
dprintf("towrite=%llu written=%llu tofree=%llu freed=%llu\n", |
993 |
tx->tx_space_towrite, refcount_count(&tx->tx_space_written), |
|
994 |
tx->tx_space_tofree, refcount_count(&tx->tx_space_freed)); |
|
995 |
refcount_destroy_many(&tx->tx_space_written, |
|
996 |
refcount_count(&tx->tx_space_written)); |
|
997 |
refcount_destroy_many(&tx->tx_space_freed, |
|
998 |
refcount_count(&tx->tx_space_freed)); |
|
999 |
#endif |
|
1000 |
kmem_free(tx, sizeof (dmu_tx_t)); |
|
1001 |
} |
|
1002 |
||
1003 |
void |
|
1004 |
dmu_tx_abort(dmu_tx_t *tx) |
|
1005 |
{ |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
1006 |
dmu_tx_hold_t *txh; |
789 | 1007 |
|
1008 |
ASSERT(tx->tx_txg == 0); |
|
1009 |
||
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
1010 |
while (txh = list_head(&tx->tx_holds)) { |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
1011 |
dnode_t *dn = txh->txh_dnode; |
789 | 1012 |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
1013 |
list_remove(&tx->tx_holds, txh); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
1014 |
kmem_free(txh, sizeof (dmu_tx_hold_t)); |
789 | 1015 |
if (dn != NULL) |
1016 |
dnode_rele(dn, tx); |
|
1017 |
} |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
2082
diff
changeset
|
1018 |
#ifdef ZFS_DEBUG |
789 | 1019 |
refcount_destroy_many(&tx->tx_space_written, |
1020 |
refcount_count(&tx->tx_space_written)); |
|
1021 |
refcount_destroy_many(&tx->tx_space_freed, |
|
1022 |
refcount_count(&tx->tx_space_freed)); |
|
1023 |
#endif |
|
1024 |
kmem_free(tx, sizeof (dmu_tx_t)); |
|
1025 |
} |
|
1026 |
||
1027 |
uint64_t |
|
1028 |
dmu_tx_get_txg(dmu_tx_t *tx) |
|
1029 |
{ |
|
1030 |
ASSERT(tx->tx_txg != 0); |
|
1031 |
return (tx->tx_txg); |
|
1032 |
} |