author | ahrens |
Thu, 02 Aug 2007 21:23:46 -0700 | |
changeset 4787 | 602d3f97842c |
parent 4634 | 39bfb9e90d34 |
child 4935 | c80bf0e6f4aa |
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 |
/* |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
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 |
||
4543 | 28 |
#include <sys/cred.h> |
789 | 29 |
#include <sys/zfs_context.h> |
30 |
#include <sys/dmu_objset.h> |
|
31 |
#include <sys/dsl_dir.h> |
|
32 |
#include <sys/dsl_dataset.h> |
|
33 |
#include <sys/dsl_prop.h> |
|
34 |
#include <sys/dsl_pool.h> |
|
2199 | 35 |
#include <sys/dsl_synctask.h> |
4543 | 36 |
#include <sys/dsl_deleg.h> |
789 | 37 |
#include <sys/dnode.h> |
38 |
#include <sys/dbuf.h> |
|
2885 | 39 |
#include <sys/zvol.h> |
789 | 40 |
#include <sys/dmu_tx.h> |
41 |
#include <sys/zio_checksum.h> |
|
42 |
#include <sys/zap.h> |
|
43 |
#include <sys/zil.h> |
|
44 |
#include <sys/dmu_impl.h> |
|
4543 | 45 |
#include <sys/zfs_ioctl.h> |
789 | 46 |
|
47 |
||
48 |
spa_t * |
|
49 |
dmu_objset_spa(objset_t *os) |
|
50 |
{ |
|
51 |
return (os->os->os_spa); |
|
52 |
} |
|
53 |
||
54 |
zilog_t * |
|
55 |
dmu_objset_zil(objset_t *os) |
|
56 |
{ |
|
57 |
return (os->os->os_zil); |
|
58 |
} |
|
59 |
||
60 |
dsl_pool_t * |
|
61 |
dmu_objset_pool(objset_t *os) |
|
62 |
{ |
|
63 |
dsl_dataset_t *ds; |
|
64 |
||
65 |
if ((ds = os->os->os_dsl_dataset) != NULL && ds->ds_dir) |
|
66 |
return (ds->ds_dir->dd_pool); |
|
67 |
else |
|
68 |
return (spa_get_dsl(os->os->os_spa)); |
|
69 |
} |
|
70 |
||
71 |
dsl_dataset_t * |
|
72 |
dmu_objset_ds(objset_t *os) |
|
73 |
{ |
|
74 |
return (os->os->os_dsl_dataset); |
|
75 |
} |
|
76 |
||
77 |
dmu_objset_type_t |
|
78 |
dmu_objset_type(objset_t *os) |
|
79 |
{ |
|
80 |
return (os->os->os_phys->os_type); |
|
81 |
} |
|
82 |
||
83 |
void |
|
84 |
dmu_objset_name(objset_t *os, char *buf) |
|
85 |
{ |
|
86 |
dsl_dataset_name(os->os->os_dsl_dataset, buf); |
|
87 |
} |
|
88 |
||
89 |
uint64_t |
|
90 |
dmu_objset_id(objset_t *os) |
|
91 |
{ |
|
92 |
dsl_dataset_t *ds = os->os->os_dsl_dataset; |
|
93 |
||
94 |
return (ds ? ds->ds_object : 0); |
|
95 |
} |
|
96 |
||
97 |
static void |
|
98 |
checksum_changed_cb(void *arg, uint64_t newval) |
|
99 |
{ |
|
100 |
objset_impl_t *osi = arg; |
|
101 |
||
102 |
/* |
|
103 |
* Inheritance should have been done by now. |
|
104 |
*/ |
|
105 |
ASSERT(newval != ZIO_CHECKSUM_INHERIT); |
|
106 |
||
107 |
osi->os_checksum = zio_checksum_select(newval, ZIO_CHECKSUM_ON_VALUE); |
|
108 |
} |
|
109 |
||
110 |
static void |
|
111 |
compression_changed_cb(void *arg, uint64_t newval) |
|
112 |
{ |
|
113 |
objset_impl_t *osi = arg; |
|
114 |
||
115 |
/* |
|
116 |
* Inheritance and range checking should have been done by now. |
|
117 |
*/ |
|
118 |
ASSERT(newval != ZIO_COMPRESS_INHERIT); |
|
119 |
||
120 |
osi->os_compress = zio_compress_select(newval, ZIO_COMPRESS_ON_VALUE); |
|
121 |
} |
|
122 |
||
3835 | 123 |
static void |
124 |
copies_changed_cb(void *arg, uint64_t newval) |
|
125 |
{ |
|
126 |
objset_impl_t *osi = arg; |
|
127 |
||
128 |
/* |
|
129 |
* Inheritance and range checking should have been done by now. |
|
130 |
*/ |
|
131 |
ASSERT(newval > 0); |
|
132 |
ASSERT(newval <= spa_max_replication(osi->os_spa)); |
|
133 |
||
134 |
osi->os_copies = newval; |
|
135 |
} |
|
136 |
||
789 | 137 |
void |
138 |
dmu_objset_byteswap(void *buf, size_t size) |
|
139 |
{ |
|
140 |
objset_phys_t *osp = buf; |
|
141 |
||
142 |
ASSERT(size == sizeof (objset_phys_t)); |
|
143 |
dnode_byteswap(&osp->os_meta_dnode); |
|
144 |
byteswap_uint64_array(&osp->os_zil_header, sizeof (zil_header_t)); |
|
145 |
osp->os_type = BSWAP_64(osp->os_type); |
|
146 |
} |
|
147 |
||
1544 | 148 |
int |
149 |
dmu_objset_open_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp, |
|
150 |
objset_impl_t **osip) |
|
789 | 151 |
{ |
4787 | 152 |
objset_impl_t *osi; |
789 | 153 |
int i, err, checksum; |
154 |
||
4787 | 155 |
ASSERT(ds == NULL || MUTEX_HELD(&ds->ds_opening_lock)); |
156 |
||
789 | 157 |
osi = kmem_zalloc(sizeof (objset_impl_t), KM_SLEEP); |
158 |
osi->os.os = osi; |
|
159 |
osi->os_dsl_dataset = ds; |
|
160 |
osi->os_spa = spa; |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
161 |
osi->os_rootbp = bp; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
162 |
if (!BP_IS_HOLE(osi->os_rootbp)) { |
2391 | 163 |
uint32_t aflags = ARC_WAIT; |
1544 | 164 |
zbookmark_t zb; |
165 |
zb.zb_objset = ds ? ds->ds_object : 0; |
|
166 |
zb.zb_object = 0; |
|
167 |
zb.zb_level = -1; |
|
168 |
zb.zb_blkid = 0; |
|
169 |
||
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
170 |
dprintf_bp(osi->os_rootbp, "reading %s", ""); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
171 |
err = arc_read(NULL, spa, osi->os_rootbp, |
789 | 172 |
dmu_ot[DMU_OT_OBJSET].ot_byteswap, |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
173 |
arc_getbuf_func, &osi->os_phys_buf, |
2391 | 174 |
ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &aflags, &zb); |
1544 | 175 |
if (err) { |
176 |
kmem_free(osi, sizeof (objset_impl_t)); |
|
177 |
return (err); |
|
178 |
} |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
179 |
osi->os_phys = osi->os_phys_buf->b_data; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
180 |
arc_release(osi->os_phys_buf, &osi->os_phys_buf); |
789 | 181 |
} else { |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
182 |
osi->os_phys_buf = arc_buf_alloc(spa, sizeof (objset_phys_t), |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
183 |
&osi->os_phys_buf, ARC_BUFC_METADATA); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
184 |
osi->os_phys = osi->os_phys_buf->b_data; |
789 | 185 |
bzero(osi->os_phys, sizeof (objset_phys_t)); |
186 |
} |
|
187 |
||
188 |
/* |
|
189 |
* Note: the changed_cb will be called once before the register |
|
190 |
* func returns, thus changing the checksum/compression from the |
|
2082 | 191 |
* default (fletcher2/off). Snapshots don't need to know, and |
192 |
* registering would complicate clone promotion. |
|
789 | 193 |
*/ |
2082 | 194 |
if (ds && ds->ds_phys->ds_num_children == 0) { |
789 | 195 |
err = dsl_prop_register(ds, "checksum", |
196 |
checksum_changed_cb, osi); |
|
1544 | 197 |
if (err == 0) |
198 |
err = dsl_prop_register(ds, "compression", |
|
199 |
compression_changed_cb, osi); |
|
3835 | 200 |
if (err == 0) |
201 |
err = dsl_prop_register(ds, "copies", |
|
202 |
copies_changed_cb, osi); |
|
1544 | 203 |
if (err) { |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
204 |
VERIFY(arc_buf_remove_ref(osi->os_phys_buf, |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
205 |
&osi->os_phys_buf) == 1); |
1544 | 206 |
kmem_free(osi, sizeof (objset_impl_t)); |
207 |
return (err); |
|
208 |
} |
|
2082 | 209 |
} else if (ds == NULL) { |
789 | 210 |
/* It's the meta-objset. */ |
211 |
osi->os_checksum = ZIO_CHECKSUM_FLETCHER_4; |
|
1544 | 212 |
osi->os_compress = ZIO_COMPRESS_LZJB; |
3835 | 213 |
osi->os_copies = spa_max_replication(spa); |
789 | 214 |
} |
215 |
||
1544 | 216 |
osi->os_zil = zil_alloc(&osi->os, &osi->os_phys->os_zil_header); |
217 |
||
789 | 218 |
/* |
219 |
* Metadata always gets compressed and checksummed. |
|
220 |
* If the data checksum is multi-bit correctable, and it's not |
|
221 |
* a ZBT-style checksum, then it's suitable for metadata as well. |
|
222 |
* Otherwise, the metadata checksum defaults to fletcher4. |
|
223 |
*/ |
|
224 |
checksum = osi->os_checksum; |
|
225 |
||
226 |
if (zio_checksum_table[checksum].ci_correctable && |
|
227 |
!zio_checksum_table[checksum].ci_zbt) |
|
228 |
osi->os_md_checksum = checksum; |
|
229 |
else |
|
230 |
osi->os_md_checksum = ZIO_CHECKSUM_FLETCHER_4; |
|
1544 | 231 |
osi->os_md_compress = ZIO_COMPRESS_LZJB; |
789 | 232 |
|
233 |
for (i = 0; i < TXG_SIZE; i++) { |
|
234 |
list_create(&osi->os_dirty_dnodes[i], sizeof (dnode_t), |
|
235 |
offsetof(dnode_t, dn_dirty_link[i])); |
|
236 |
list_create(&osi->os_free_dnodes[i], sizeof (dnode_t), |
|
237 |
offsetof(dnode_t, dn_dirty_link[i])); |
|
238 |
} |
|
239 |
list_create(&osi->os_dnodes, sizeof (dnode_t), |
|
240 |
offsetof(dnode_t, dn_link)); |
|
241 |
list_create(&osi->os_downgraded_dbufs, sizeof (dmu_buf_impl_t), |
|
242 |
offsetof(dmu_buf_impl_t, db_link)); |
|
243 |
||
2856 | 244 |
mutex_init(&osi->os_lock, NULL, MUTEX_DEFAULT, NULL); |
245 |
mutex_init(&osi->os_obj_lock, NULL, MUTEX_DEFAULT, NULL); |
|
246 |
||
789 | 247 |
osi->os_meta_dnode = dnode_special_open(osi, |
248 |
&osi->os_phys->os_meta_dnode, DMU_META_DNODE_OBJECT); |
|
249 |
||
4787 | 250 |
/* |
251 |
* We should be the only thread trying to do this because we |
|
252 |
* have ds_opening_lock |
|
253 |
*/ |
|
254 |
if (ds) { |
|
255 |
VERIFY(NULL == dsl_dataset_set_user_ptr(ds, osi, |
|
256 |
dmu_objset_evict)); |
|
789 | 257 |
} |
258 |
||
1544 | 259 |
*osip = osi; |
260 |
return (0); |
|
789 | 261 |
} |
262 |
||
263 |
/* called from zpl */ |
|
264 |
int |
|
265 |
dmu_objset_open(const char *name, dmu_objset_type_t type, int mode, |
|
266 |
objset_t **osp) |
|
267 |
{ |
|
268 |
dsl_dataset_t *ds; |
|
269 |
int err; |
|
270 |
objset_t *os; |
|
271 |
objset_impl_t *osi; |
|
272 |
||
273 |
os = kmem_alloc(sizeof (objset_t), KM_SLEEP); |
|
274 |
err = dsl_dataset_open(name, mode, os, &ds); |
|
275 |
if (err) { |
|
276 |
kmem_free(os, sizeof (objset_t)); |
|
277 |
return (err); |
|
278 |
} |
|
279 |
||
4787 | 280 |
mutex_enter(&ds->ds_opening_lock); |
789 | 281 |
osi = dsl_dataset_get_user_ptr(ds); |
282 |
if (osi == NULL) { |
|
1544 | 283 |
err = dmu_objset_open_impl(dsl_dataset_get_spa(ds), |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
284 |
ds, &ds->ds_phys->ds_bp, &osi); |
1544 | 285 |
if (err) { |
286 |
dsl_dataset_close(ds, mode, os); |
|
287 |
kmem_free(os, sizeof (objset_t)); |
|
288 |
return (err); |
|
289 |
} |
|
789 | 290 |
} |
4787 | 291 |
mutex_exit(&ds->ds_opening_lock); |
789 | 292 |
|
293 |
os->os = osi; |
|
294 |
os->os_mode = mode; |
|
295 |
||
296 |
if (type != DMU_OST_ANY && type != os->os->os_phys->os_type) { |
|
297 |
dmu_objset_close(os); |
|
298 |
return (EINVAL); |
|
299 |
} |
|
300 |
*osp = os; |
|
301 |
return (0); |
|
302 |
} |
|
303 |
||
304 |
void |
|
305 |
dmu_objset_close(objset_t *os) |
|
306 |
{ |
|
307 |
dsl_dataset_close(os->os->os_dsl_dataset, os->os_mode, os); |
|
308 |
kmem_free(os, sizeof (objset_t)); |
|
309 |
} |
|
310 |
||
1646
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1596
diff
changeset
|
311 |
int |
4787 | 312 |
dmu_objset_evict_dbufs(objset_t *os, boolean_t try) |
1544 | 313 |
{ |
314 |
objset_impl_t *osi = os->os; |
|
315 |
dnode_t *dn; |
|
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
316 |
|
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
317 |
mutex_enter(&osi->os_lock); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
318 |
|
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
319 |
/* process the mdn last, since the other dnodes have holds on it */ |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
320 |
list_remove(&osi->os_dnodes, osi->os_meta_dnode); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
321 |
list_insert_tail(&osi->os_dnodes, osi->os_meta_dnode); |
1544 | 322 |
|
323 |
/* |
|
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
324 |
* Find the first dnode with holds. We have to do this dance |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
325 |
* because dnode_add_ref() only works if you already have a |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
326 |
* hold. If there are no holds then it has no dbufs so OK to |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
327 |
* skip. |
1544 | 328 |
*/ |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
329 |
for (dn = list_head(&osi->os_dnodes); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
330 |
dn && refcount_is_zero(&dn->dn_holds); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
331 |
dn = list_next(&osi->os_dnodes, dn)) |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
332 |
continue; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
333 |
if (dn) |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
334 |
dnode_add_ref(dn, FTAG); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
335 |
|
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
336 |
while (dn) { |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
337 |
dnode_t *next_dn = dn; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
338 |
|
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
339 |
do { |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
340 |
next_dn = list_next(&osi->os_dnodes, next_dn); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
341 |
} while (next_dn && refcount_is_zero(&next_dn->dn_holds)); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
342 |
if (next_dn) |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
343 |
dnode_add_ref(next_dn, FTAG); |
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 |
mutex_exit(&osi->os_lock); |
1646
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1596
diff
changeset
|
346 |
if (dnode_evict_dbufs(dn, try)) { |
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1596
diff
changeset
|
347 |
dnode_rele(dn, FTAG); |
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1596
diff
changeset
|
348 |
if (next_dn) |
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1596
diff
changeset
|
349 |
dnode_rele(next_dn, FTAG); |
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1596
diff
changeset
|
350 |
return (1); |
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1596
diff
changeset
|
351 |
} |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
352 |
dnode_rele(dn, FTAG); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
353 |
mutex_enter(&osi->os_lock); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
354 |
dn = next_dn; |
1544 | 355 |
} |
356 |
mutex_exit(&osi->os_lock); |
|
1646
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1596
diff
changeset
|
357 |
return (0); |
1544 | 358 |
} |
359 |
||
360 |
void |
|
789 | 361 |
dmu_objset_evict(dsl_dataset_t *ds, void *arg) |
362 |
{ |
|
363 |
objset_impl_t *osi = arg; |
|
1544 | 364 |
objset_t os; |
2082 | 365 |
int i; |
789 | 366 |
|
367 |
for (i = 0; i < TXG_SIZE; i++) { |
|
368 |
ASSERT(list_head(&osi->os_dirty_dnodes[i]) == NULL); |
|
369 |
ASSERT(list_head(&osi->os_free_dnodes[i]) == NULL); |
|
370 |
} |
|
371 |
||
2082 | 372 |
if (ds && ds->ds_phys->ds_num_children == 0) { |
373 |
VERIFY(0 == dsl_prop_unregister(ds, "checksum", |
|
374 |
checksum_changed_cb, osi)); |
|
375 |
VERIFY(0 == dsl_prop_unregister(ds, "compression", |
|
376 |
compression_changed_cb, osi)); |
|
3835 | 377 |
VERIFY(0 == dsl_prop_unregister(ds, "copies", |
378 |
copies_changed_cb, osi)); |
|
789 | 379 |
} |
380 |
||
1544 | 381 |
/* |
382 |
* We should need only a single pass over the dnode list, since |
|
383 |
* nothing can be added to the list at this point. |
|
384 |
*/ |
|
385 |
os.os = osi; |
|
1646
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1596
diff
changeset
|
386 |
(void) dmu_objset_evict_dbufs(&os, 0); |
1544 | 387 |
|
789 | 388 |
ASSERT3P(list_head(&osi->os_dnodes), ==, osi->os_meta_dnode); |
389 |
ASSERT3P(list_tail(&osi->os_dnodes), ==, osi->os_meta_dnode); |
|
390 |
ASSERT3P(list_head(&osi->os_meta_dnode->dn_dbufs), ==, NULL); |
|
391 |
||
392 |
dnode_special_close(osi->os_meta_dnode); |
|
393 |
zil_free(osi->os_zil); |
|
394 |
||
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
395 |
VERIFY(arc_buf_remove_ref(osi->os_phys_buf, &osi->os_phys_buf) == 1); |
2856 | 396 |
mutex_destroy(&osi->os_lock); |
397 |
mutex_destroy(&osi->os_obj_lock); |
|
789 | 398 |
kmem_free(osi, sizeof (objset_impl_t)); |
399 |
} |
|
400 |
||
401 |
/* called from dsl for meta-objset */ |
|
402 |
objset_impl_t * |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
403 |
dmu_objset_create_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp, |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
404 |
dmu_objset_type_t type, dmu_tx_t *tx) |
789 | 405 |
{ |
406 |
objset_impl_t *osi; |
|
407 |
dnode_t *mdn; |
|
408 |
||
409 |
ASSERT(dmu_tx_is_syncing(tx)); |
|
4787 | 410 |
if (ds) |
411 |
mutex_enter(&ds->ds_opening_lock); |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
412 |
VERIFY(0 == dmu_objset_open_impl(spa, ds, bp, &osi)); |
4787 | 413 |
if (ds) |
414 |
mutex_exit(&ds->ds_opening_lock); |
|
789 | 415 |
mdn = osi->os_meta_dnode; |
416 |
||
417 |
dnode_allocate(mdn, DMU_OT_DNODE, 1 << DNODE_BLOCK_SHIFT, |
|
418 |
DN_MAX_INDBLKSHIFT, DMU_OT_NONE, 0, tx); |
|
419 |
||
420 |
/* |
|
421 |
* We don't want to have to increase the meta-dnode's nlevels |
|
422 |
* later, because then we could do it in quescing context while |
|
423 |
* we are also accessing it in open context. |
|
424 |
* |
|
425 |
* This precaution is not necessary for the MOS (ds == NULL), |
|
426 |
* because the MOS is only updated in syncing context. |
|
427 |
* This is most fortunate: the MOS is the only objset that |
|
428 |
* needs to be synced multiple times as spa_sync() iterates |
|
429 |
* to convergence, so minimizing its dn_nlevels matters. |
|
430 |
*/ |
|
1544 | 431 |
if (ds != NULL) { |
432 |
int levels = 1; |
|
433 |
||
434 |
/* |
|
435 |
* Determine the number of levels necessary for the meta-dnode |
|
436 |
* to contain DN_MAX_OBJECT dnodes. |
|
437 |
*/ |
|
438 |
while ((uint64_t)mdn->dn_nblkptr << (mdn->dn_datablkshift + |
|
439 |
(levels - 1) * (mdn->dn_indblkshift - SPA_BLKPTRSHIFT)) < |
|
440 |
DN_MAX_OBJECT * sizeof (dnode_phys_t)) |
|
441 |
levels++; |
|
442 |
||
789 | 443 |
mdn->dn_next_nlevels[tx->tx_txg & TXG_MASK] = |
1544 | 444 |
mdn->dn_nlevels = levels; |
445 |
} |
|
789 | 446 |
|
447 |
ASSERT(type != DMU_OST_NONE); |
|
448 |
ASSERT(type != DMU_OST_ANY); |
|
449 |
ASSERT(type < DMU_OST_NUMTYPES); |
|
450 |
osi->os_phys->os_type = type; |
|
451 |
||
452 |
dsl_dataset_dirty(ds, tx); |
|
453 |
||
454 |
return (osi); |
|
455 |
} |
|
456 |
||
457 |
struct oscarg { |
|
4543 | 458 |
void (*userfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx); |
789 | 459 |
void *userarg; |
460 |
dsl_dataset_t *clone_parent; |
|
461 |
const char *lastname; |
|
462 |
dmu_objset_type_t type; |
|
463 |
}; |
|
464 |
||
4543 | 465 |
/*ARGSUSED*/ |
789 | 466 |
static int |
2199 | 467 |
dmu_objset_create_check(void *arg1, void *arg2, dmu_tx_t *tx) |
789 | 468 |
{ |
2199 | 469 |
dsl_dir_t *dd = arg1; |
470 |
struct oscarg *oa = arg2; |
|
471 |
objset_t *mos = dd->dd_pool->dp_meta_objset; |
|
472 |
int err; |
|
473 |
uint64_t ddobj; |
|
474 |
||
475 |
err = zap_lookup(mos, dd->dd_phys->dd_child_dir_zapobj, |
|
476 |
oa->lastname, sizeof (uint64_t), 1, &ddobj); |
|
477 |
if (err != ENOENT) |
|
478 |
return (err ? err : EEXIST); |
|
479 |
||
480 |
if (oa->clone_parent != NULL) { |
|
481 |
/* |
|
482 |
* You can't clone across pools. |
|
483 |
*/ |
|
484 |
if (oa->clone_parent->ds_dir->dd_pool != dd->dd_pool) |
|
485 |
return (EXDEV); |
|
486 |
||
487 |
/* |
|
488 |
* You can only clone snapshots, not the head datasets. |
|
489 |
*/ |
|
490 |
if (oa->clone_parent->ds_phys->ds_num_children == 0) |
|
491 |
return (EINVAL); |
|
492 |
} |
|
4543 | 493 |
|
2199 | 494 |
return (0); |
495 |
} |
|
496 |
||
497 |
static void |
|
4543 | 498 |
dmu_objset_create_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
2199 | 499 |
{ |
500 |
dsl_dir_t *dd = arg1; |
|
501 |
struct oscarg *oa = arg2; |
|
789 | 502 |
dsl_dataset_t *ds; |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
503 |
blkptr_t *bp; |
2199 | 504 |
uint64_t dsobj; |
789 | 505 |
|
506 |
ASSERT(dmu_tx_is_syncing(tx)); |
|
507 |
||
2199 | 508 |
dsobj = dsl_dataset_create_sync(dd, oa->lastname, |
789 | 509 |
oa->clone_parent, tx); |
510 |
||
2199 | 511 |
VERIFY(0 == dsl_dataset_open_obj(dd->dd_pool, dsobj, NULL, |
1544 | 512 |
DS_MODE_STANDARD | DS_MODE_READONLY, FTAG, &ds)); |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
513 |
bp = dsl_dataset_get_blkptr(ds); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
514 |
if (BP_IS_HOLE(bp)) { |
789 | 515 |
objset_impl_t *osi; |
516 |
||
517 |
/* This is an empty dmu_objset; not a clone. */ |
|
518 |
osi = dmu_objset_create_impl(dsl_dataset_get_spa(ds), |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
519 |
ds, bp, oa->type, tx); |
789 | 520 |
|
521 |
if (oa->userfunc) |
|
4543 | 522 |
oa->userfunc(&osi->os, oa->userarg, cr, tx); |
789 | 523 |
} |
4543 | 524 |
|
525 |
/* |
|
526 |
* Create create time permission if any? |
|
527 |
*/ |
|
528 |
dsl_deleg_set_create_perms(ds->ds_dir, tx, cr); |
|
529 |
||
530 |
spa_history_internal_log(LOG_DS_CREATE, dd->dd_pool->dp_spa, |
|
531 |
tx, cr, "dataset = %llu", dsobj); |
|
532 |
||
789 | 533 |
dsl_dataset_close(ds, DS_MODE_STANDARD | DS_MODE_READONLY, FTAG); |
534 |
} |
|
535 |
||
536 |
int |
|
537 |
dmu_objset_create(const char *name, dmu_objset_type_t type, |
|
538 |
objset_t *clone_parent, |
|
4543 | 539 |
void (*func)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx), void *arg) |
789 | 540 |
{ |
2199 | 541 |
dsl_dir_t *pdd; |
789 | 542 |
const char *tail; |
543 |
int err = 0; |
|
2199 | 544 |
struct oscarg oa = { 0 }; |
789 | 545 |
|
2199 | 546 |
ASSERT(strchr(name, '@') == NULL); |
547 |
err = dsl_dir_open(name, FTAG, &pdd, &tail); |
|
1544 | 548 |
if (err) |
549 |
return (err); |
|
789 | 550 |
if (tail == NULL) { |
2199 | 551 |
dsl_dir_close(pdd, FTAG); |
789 | 552 |
return (EEXIST); |
553 |
} |
|
554 |
||
555 |
dprintf("name=%s\n", name); |
|
556 |
||
2199 | 557 |
oa.userfunc = func; |
558 |
oa.userarg = arg; |
|
559 |
oa.lastname = tail; |
|
560 |
oa.type = type; |
|
4543 | 561 |
|
2199 | 562 |
if (clone_parent != NULL) { |
789 | 563 |
/* |
2199 | 564 |
* You can't clone to a different type. |
789 | 565 |
*/ |
2199 | 566 |
if (clone_parent->os->os_phys->os_type != type) { |
567 |
dsl_dir_close(pdd, FTAG); |
|
568 |
return (EINVAL); |
|
789 | 569 |
} |
2199 | 570 |
oa.clone_parent = clone_parent->os->os_dsl_dataset; |
789 | 571 |
} |
2199 | 572 |
err = dsl_sync_task_do(pdd->dd_pool, dmu_objset_create_check, |
573 |
dmu_objset_create_sync, pdd, &oa, 5); |
|
574 |
dsl_dir_close(pdd, FTAG); |
|
789 | 575 |
return (err); |
576 |
} |
|
577 |
||
578 |
int |
|
579 |
dmu_objset_destroy(const char *name) |
|
580 |
{ |
|
581 |
objset_t *os; |
|
582 |
int error; |
|
583 |
||
584 |
/* |
|
585 |
* If it looks like we'll be able to destroy it, and there's |
|
586 |
* an unplayed replay log sitting around, destroy the log. |
|
587 |
* It would be nicer to do this in dsl_dataset_destroy_sync(), |
|
588 |
* but the replay log objset is modified in open context. |
|
589 |
*/ |
|
590 |
error = dmu_objset_open(name, DMU_OST_ANY, DS_MODE_EXCLUSIVE, &os); |
|
591 |
if (error == 0) { |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1775
diff
changeset
|
592 |
zil_destroy(dmu_objset_zil(os), B_FALSE); |
789 | 593 |
dmu_objset_close(os); |
594 |
} |
|
595 |
||
596 |
return (dsl_dataset_destroy(name)); |
|
597 |
} |
|
598 |
||
599 |
int |
|
600 |
dmu_objset_rollback(const char *name) |
|
601 |
{ |
|
602 |
int err; |
|
603 |
objset_t *os; |
|
604 |
||
2199 | 605 |
err = dmu_objset_open(name, DMU_OST_ANY, |
606 |
DS_MODE_EXCLUSIVE | DS_MODE_INCONSISTENT, &os); |
|
789 | 607 |
if (err == 0) { |
608 |
err = zil_suspend(dmu_objset_zil(os)); |
|
609 |
if (err == 0) |
|
610 |
zil_resume(dmu_objset_zil(os)); |
|
611 |
if (err == 0) { |
|
612 |
/* XXX uncache everything? */ |
|
2199 | 613 |
err = dsl_dataset_rollback(os->os->os_dsl_dataset); |
789 | 614 |
} |
2199 | 615 |
dmu_objset_close(os); |
789 | 616 |
} |
617 |
return (err); |
|
618 |
} |
|
619 |
||
2199 | 620 |
struct snaparg { |
621 |
dsl_sync_task_group_t *dstg; |
|
622 |
char *snapname; |
|
623 |
char failed[MAXPATHLEN]; |
|
4543 | 624 |
boolean_t checkperms; |
2199 | 625 |
}; |
626 |
||
627 |
static int |
|
628 |
dmu_objset_snapshot_one(char *name, void *arg) |
|
629 |
{ |
|
630 |
struct snaparg *sn = arg; |
|
631 |
objset_t *os; |
|
3637
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
632 |
dmu_objset_stats_t stat; |
2199 | 633 |
int err; |
634 |
||
635 |
(void) strcpy(sn->failed, name); |
|
636 |
||
4543 | 637 |
/* |
638 |
* Check permissions only when requested. This only applies when |
|
639 |
* doing a recursive snapshot. The permission checks for the starting |
|
640 |
* dataset have already been performed in zfs_secpolicy_snapshot() |
|
641 |
*/ |
|
642 |
if (sn->checkperms == B_TRUE && |
|
643 |
(err = zfs_secpolicy_snapshot_perms(name, CRED()))) |
|
644 |
return (err); |
|
645 |
||
2199 | 646 |
err = dmu_objset_open(name, DMU_OST_ANY, DS_MODE_STANDARD, &os); |
647 |
if (err != 0) |
|
648 |
return (err); |
|
649 |
||
650 |
/* |
|
3637
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
651 |
* If the objset is in an inconsistent state, return busy. |
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
652 |
*/ |
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
653 |
dmu_objset_fast_stat(os, &stat); |
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
654 |
if (stat.dds_inconsistent) { |
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
655 |
dmu_objset_close(os); |
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
656 |
return (EBUSY); |
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
657 |
} |
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
658 |
|
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
659 |
/* |
2199 | 660 |
* NB: we need to wait for all in-flight changes to get to disk, |
661 |
* so that we snapshot those changes. zil_suspend does this as |
|
662 |
* a side effect. |
|
663 |
*/ |
|
664 |
err = zil_suspend(dmu_objset_zil(os)); |
|
665 |
if (err == 0) { |
|
666 |
dsl_sync_task_create(sn->dstg, dsl_dataset_snapshot_check, |
|
667 |
dsl_dataset_snapshot_sync, os, sn->snapname, 3); |
|
3637
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
668 |
} else { |
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
669 |
dmu_objset_close(os); |
2199 | 670 |
} |
3637
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
671 |
|
2199 | 672 |
return (err); |
673 |
} |
|
674 |
||
675 |
int |
|
676 |
dmu_objset_snapshot(char *fsname, char *snapname, boolean_t recursive) |
|
677 |
{ |
|
678 |
dsl_sync_task_t *dst; |
|
679 |
struct snaparg sn = { 0 }; |
|
680 |
spa_t *spa; |
|
681 |
int err; |
|
682 |
||
683 |
(void) strcpy(sn.failed, fsname); |
|
684 |
||
4603
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4543
diff
changeset
|
685 |
err = spa_open(fsname, &spa, FTAG); |
2199 | 686 |
if (err) |
687 |
return (err); |
|
688 |
||
689 |
sn.dstg = dsl_sync_task_group_create(spa_get_dsl(spa)); |
|
690 |
sn.snapname = snapname; |
|
691 |
||
2417 | 692 |
if (recursive) { |
4543 | 693 |
sn.checkperms = B_TRUE; |
2417 | 694 |
err = dmu_objset_find(fsname, |
695 |
dmu_objset_snapshot_one, &sn, DS_FIND_CHILDREN); |
|
696 |
} else { |
|
4543 | 697 |
sn.checkperms = B_FALSE; |
2199 | 698 |
err = dmu_objset_snapshot_one(fsname, &sn); |
2417 | 699 |
} |
2199 | 700 |
|
701 |
if (err) |
|
702 |
goto out; |
|
703 |
||
704 |
err = dsl_sync_task_group_wait(sn.dstg); |
|
705 |
||
706 |
for (dst = list_head(&sn.dstg->dstg_tasks); dst; |
|
707 |
dst = list_next(&sn.dstg->dstg_tasks, dst)) { |
|
708 |
objset_t *os = dst->dst_arg1; |
|
709 |
if (dst->dst_err) |
|
710 |
dmu_objset_name(os, sn.failed); |
|
711 |
zil_resume(dmu_objset_zil(os)); |
|
712 |
dmu_objset_close(os); |
|
713 |
} |
|
714 |
out: |
|
715 |
if (err) |
|
716 |
(void) strcpy(fsname, sn.failed); |
|
717 |
dsl_sync_task_group_destroy(sn.dstg); |
|
718 |
spa_close(spa, FTAG); |
|
719 |
return (err); |
|
720 |
} |
|
721 |
||
789 | 722 |
static void |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
723 |
dmu_objset_sync_dnodes(list_t *list, dmu_tx_t *tx) |
789 | 724 |
{ |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
725 |
dnode_t *dn; |
789 | 726 |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
727 |
while (dn = list_head(list)) { |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
728 |
ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
729 |
ASSERT(dn->dn_dbuf->db_data_pending); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
730 |
/* |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
731 |
* Initialize dn_zio outside dnode_sync() |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
732 |
* to accomodate meta-dnode |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
733 |
*/ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
734 |
dn->dn_zio = dn->dn_dbuf->db_data_pending->dr_zio; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
735 |
ASSERT(dn->dn_zio); |
789 | 736 |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
737 |
ASSERT3U(dn->dn_nlevels, <=, DN_MAX_LEVELS); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
738 |
list_remove(list, dn); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
739 |
dnode_sync(dn, tx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
740 |
} |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
741 |
} |
2981 | 742 |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
743 |
/* ARGSUSED */ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
744 |
static void |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
745 |
ready(zio_t *zio, arc_buf_t *abuf, void *arg) |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
746 |
{ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
747 |
objset_impl_t *os = arg; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
748 |
blkptr_t *bp = os->os_rootbp; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
749 |
dnode_phys_t *dnp = &os->os_phys->os_meta_dnode; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
750 |
int i; |
2981 | 751 |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
752 |
/* |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
753 |
* Update rootbp fill count. |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
754 |
*/ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
755 |
bp->blk_fill = 1; /* count the meta-dnode */ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
756 |
for (i = 0; i < dnp->dn_nblkptr; i++) |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
757 |
bp->blk_fill += dnp->dn_blkptr[i].blk_fill; |
789 | 758 |
} |
759 |
||
760 |
/* ARGSUSED */ |
|
761 |
static void |
|
762 |
killer(zio_t *zio, arc_buf_t *abuf, void *arg) |
|
763 |
{ |
|
764 |
objset_impl_t *os = arg; |
|
765 |
||
766 |
ASSERT3U(zio->io_error, ==, 0); |
|
767 |
||
768 |
BP_SET_TYPE(zio->io_bp, DMU_OT_OBJSET); |
|
769 |
BP_SET_LEVEL(zio->io_bp, 0); |
|
770 |
||
771 |
if (!DVA_EQUAL(BP_IDENTITY(zio->io_bp), |
|
772 |
BP_IDENTITY(&zio->io_bp_orig))) { |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
773 |
if (zio->io_bp_orig.blk_birth == os->os_synctx->tx_txg) |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
774 |
dsl_dataset_block_kill(os->os_dsl_dataset, |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
775 |
&zio->io_bp_orig, NULL, os->os_synctx); |
789 | 776 |
dsl_dataset_block_born(os->os_dsl_dataset, zio->io_bp, |
777 |
os->os_synctx); |
|
778 |
} |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
779 |
arc_release(os->os_phys_buf, &os->os_phys_buf); |
789 | 780 |
} |
781 |
||
782 |
/* called from dsl */ |
|
783 |
void |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
784 |
dmu_objset_sync(objset_impl_t *os, zio_t *pio, dmu_tx_t *tx) |
789 | 785 |
{ |
786 |
int txgoff; |
|
1544 | 787 |
zbookmark_t zb; |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
788 |
zio_t *zio; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
789 |
list_t *list; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
790 |
dbuf_dirty_record_t *dr; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
791 |
|
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
792 |
dprintf_ds(os->os_dsl_dataset, "txg=%llu\n", tx->tx_txg); |
789 | 793 |
|
794 |
ASSERT(dmu_tx_is_syncing(tx)); |
|
795 |
/* XXX the write_done callback should really give us the tx... */ |
|
796 |
os->os_synctx = tx; |
|
797 |
||
3882 | 798 |
if (os->os_dsl_dataset == NULL) { |
799 |
/* |
|
800 |
* This is the MOS. If we have upgraded, |
|
801 |
* spa_max_replication() could change, so reset |
|
802 |
* os_copies here. |
|
803 |
*/ |
|
804 |
os->os_copies = spa_max_replication(os->os_spa); |
|
805 |
} |
|
806 |
||
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
807 |
/* |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
808 |
* Create the root block IO |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
809 |
*/ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
810 |
zb.zb_objset = os->os_dsl_dataset ? os->os_dsl_dataset->ds_object : 0; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
811 |
zb.zb_object = 0; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
812 |
zb.zb_level = -1; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
813 |
zb.zb_blkid = 0; |
4787 | 814 |
if (BP_IS_OLDER(os->os_rootbp, tx->tx_txg)) { |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
815 |
dsl_dataset_block_kill(os->os_dsl_dataset, |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
816 |
os->os_rootbp, pio, tx); |
4787 | 817 |
} |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
818 |
zio = arc_write(pio, os->os_spa, os->os_md_checksum, |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
819 |
os->os_md_compress, |
3835 | 820 |
dmu_get_replication_level(os, &zb, DMU_OT_OBJSET), |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
821 |
tx->tx_txg, os->os_rootbp, os->os_phys_buf, ready, killer, os, |
4634
39bfb9e90d34
6437054 vdev_cache wises up: increase DB performance by 16%
ek110237
parents:
4603
diff
changeset
|
822 |
ZIO_PRIORITY_ASYNC_WRITE, ZIO_FLAG_MUSTSUCCEED | ZIO_FLAG_METADATA, |
39bfb9e90d34
6437054 vdev_cache wises up: increase DB performance by 16%
ek110237
parents:
4603
diff
changeset
|
823 |
&zb); |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
824 |
|
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
825 |
/* |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
826 |
* Sync meta-dnode - the parent IO for the sync is the root block |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
827 |
*/ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
828 |
os->os_meta_dnode->dn_zio = zio; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
829 |
dnode_sync(os->os_meta_dnode, tx); |
789 | 830 |
|
831 |
txgoff = tx->tx_txg & TXG_MASK; |
|
832 |
||
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
833 |
dmu_objset_sync_dnodes(&os->os_free_dnodes[txgoff], tx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
834 |
dmu_objset_sync_dnodes(&os->os_dirty_dnodes[txgoff], tx); |
789 | 835 |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
836 |
list = &os->os_meta_dnode->dn_dirty_records[txgoff]; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
837 |
while (dr = list_head(list)) { |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
838 |
ASSERT(dr->dr_dbuf->db_level == 0); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
839 |
list_remove(list, dr); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
840 |
if (dr->dr_zio) |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
841 |
zio_nowait(dr->dr_zio); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
842 |
} |
789 | 843 |
/* |
844 |
* Free intent log blocks up to this tx. |
|
845 |
*/ |
|
846 |
zil_sync(os->os_zil, tx); |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
847 |
zio_nowait(zio); |
789 | 848 |
} |
849 |
||
850 |
void |
|
2885 | 851 |
dmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp, |
852 |
uint64_t *usedobjsp, uint64_t *availobjsp) |
|
853 |
{ |
|
854 |
dsl_dataset_space(os->os->os_dsl_dataset, refdbytesp, availbytesp, |
|
855 |
usedobjsp, availobjsp); |
|
856 |
} |
|
857 |
||
858 |
uint64_t |
|
859 |
dmu_objset_fsid_guid(objset_t *os) |
|
860 |
{ |
|
861 |
return (dsl_dataset_fsid_guid(os->os->os_dsl_dataset)); |
|
862 |
} |
|
863 |
||
864 |
void |
|
865 |
dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat) |
|
789 | 866 |
{ |
2885 | 867 |
stat->dds_type = os->os->os_phys->os_type; |
868 |
if (os->os->os_dsl_dataset) |
|
869 |
dsl_dataset_fast_stat(os->os->os_dsl_dataset, stat); |
|
870 |
} |
|
871 |
||
872 |
void |
|
873 |
dmu_objset_stats(objset_t *os, nvlist_t *nv) |
|
874 |
{ |
|
875 |
ASSERT(os->os->os_dsl_dataset || |
|
876 |
os->os->os_phys->os_type == DMU_OST_META); |
|
877 |
||
878 |
if (os->os->os_dsl_dataset != NULL) |
|
879 |
dsl_dataset_stats(os->os->os_dsl_dataset, nv); |
|
880 |
||
881 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_TYPE, |
|
882 |
os->os->os_phys->os_type); |
|
789 | 883 |
} |
884 |
||
885 |
int |
|
886 |
dmu_objset_is_snapshot(objset_t *os) |
|
887 |
{ |
|
888 |
if (os->os->os_dsl_dataset != NULL) |
|
889 |
return (dsl_dataset_is_snapshot(os->os->os_dsl_dataset)); |
|
890 |
else |
|
891 |
return (B_FALSE); |
|
892 |
} |
|
893 |
||
894 |
int |
|
895 |
dmu_snapshot_list_next(objset_t *os, int namelen, char *name, |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
896 |
uint64_t *idp, uint64_t *offp) |
789 | 897 |
{ |
898 |
dsl_dataset_t *ds = os->os->os_dsl_dataset; |
|
899 |
zap_cursor_t cursor; |
|
900 |
zap_attribute_t attr; |
|
901 |
||
902 |
if (ds->ds_phys->ds_snapnames_zapobj == 0) |
|
903 |
return (ENOENT); |
|
904 |
||
905 |
zap_cursor_init_serialized(&cursor, |
|
906 |
ds->ds_dir->dd_pool->dp_meta_objset, |
|
907 |
ds->ds_phys->ds_snapnames_zapobj, *offp); |
|
908 |
||
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
909 |
if (zap_cursor_retrieve(&cursor, &attr) != 0) { |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
910 |
zap_cursor_fini(&cursor); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
911 |
return (ENOENT); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
912 |
} |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
913 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
914 |
if (strlen(attr.za_name) + 1 > namelen) { |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
915 |
zap_cursor_fini(&cursor); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
916 |
return (ENAMETOOLONG); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
917 |
} |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
918 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
919 |
(void) strcpy(name, attr.za_name); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
920 |
if (idp) |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
921 |
*idp = attr.za_first_integer; |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
922 |
zap_cursor_advance(&cursor); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
923 |
*offp = zap_cursor_serialize(&cursor); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
924 |
zap_cursor_fini(&cursor); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
925 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
926 |
return (0); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
927 |
} |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
928 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
929 |
int |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
930 |
dmu_dir_list_next(objset_t *os, int namelen, char *name, |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
931 |
uint64_t *idp, uint64_t *offp) |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
932 |
{ |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
933 |
dsl_dir_t *dd = os->os->os_dsl_dataset->ds_dir; |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
934 |
zap_cursor_t cursor; |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
935 |
zap_attribute_t attr; |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
936 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
937 |
/* there is no next dir on a snapshot! */ |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
938 |
if (os->os->os_dsl_dataset->ds_object != |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
939 |
dd->dd_phys->dd_head_dataset_obj) |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
940 |
return (ENOENT); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
941 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
942 |
zap_cursor_init_serialized(&cursor, |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
943 |
dd->dd_pool->dp_meta_objset, |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
944 |
dd->dd_phys->dd_child_dir_zapobj, *offp); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
945 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
946 |
if (zap_cursor_retrieve(&cursor, &attr) != 0) { |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
947 |
zap_cursor_fini(&cursor); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
948 |
return (ENOENT); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
949 |
} |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
950 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
951 |
if (strlen(attr.za_name) + 1 > namelen) { |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
952 |
zap_cursor_fini(&cursor); |
789 | 953 |
return (ENAMETOOLONG); |
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
954 |
} |
789 | 955 |
|
956 |
(void) strcpy(name, attr.za_name); |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
957 |
if (idp) |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
958 |
*idp = attr.za_first_integer; |
789 | 959 |
zap_cursor_advance(&cursor); |
960 |
*offp = zap_cursor_serialize(&cursor); |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
961 |
zap_cursor_fini(&cursor); |
789 | 962 |
|
963 |
return (0); |
|
964 |
} |
|
965 |
||
966 |
/* |
|
967 |
* Find all objsets under name, and for each, call 'func(child_name, arg)'. |
|
968 |
*/ |
|
2199 | 969 |
int |
970 |
dmu_objset_find(char *name, int func(char *, void *), void *arg, int flags) |
|
789 | 971 |
{ |
972 |
dsl_dir_t *dd; |
|
973 |
objset_t *os; |
|
974 |
uint64_t snapobj; |
|
975 |
zap_cursor_t zc; |
|
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
976 |
zap_attribute_t *attr; |
789 | 977 |
char *child; |
1544 | 978 |
int do_self, err; |
789 | 979 |
|
1544 | 980 |
err = dsl_dir_open(name, FTAG, &dd, NULL); |
981 |
if (err) |
|
2199 | 982 |
return (err); |
789 | 983 |
|
2199 | 984 |
/* NB: the $MOS dir doesn't have a head dataset */ |
789 | 985 |
do_self = (dd->dd_phys->dd_head_dataset_obj != 0); |
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
986 |
attr = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP); |
789 | 987 |
|
988 |
/* |
|
989 |
* Iterate over all children. |
|
990 |
*/ |
|
2417 | 991 |
if (flags & DS_FIND_CHILDREN) { |
992 |
for (zap_cursor_init(&zc, dd->dd_pool->dp_meta_objset, |
|
993 |
dd->dd_phys->dd_child_dir_zapobj); |
|
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
994 |
zap_cursor_retrieve(&zc, attr) == 0; |
2417 | 995 |
(void) zap_cursor_advance(&zc)) { |
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
996 |
ASSERT(attr->za_integer_length == sizeof (uint64_t)); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
997 |
ASSERT(attr->za_num_integers == 1); |
789 | 998 |
|
2417 | 999 |
/* |
1000 |
* No separating '/' because parent's name ends in /. |
|
1001 |
*/ |
|
1002 |
child = kmem_alloc(MAXPATHLEN, KM_SLEEP); |
|
1003 |
/* XXX could probably just use name here */ |
|
1004 |
dsl_dir_name(dd, child); |
|
1005 |
(void) strcat(child, "/"); |
|
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1006 |
(void) strcat(child, attr->za_name); |
2417 | 1007 |
err = dmu_objset_find(child, func, arg, flags); |
1008 |
kmem_free(child, MAXPATHLEN); |
|
1009 |
if (err) |
|
1010 |
break; |
|
1011 |
} |
|
1012 |
zap_cursor_fini(&zc); |
|
2199 | 1013 |
|
2417 | 1014 |
if (err) { |
1015 |
dsl_dir_close(dd, FTAG); |
|
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1016 |
kmem_free(attr, sizeof (zap_attribute_t)); |
2417 | 1017 |
return (err); |
1018 |
} |
|
789 | 1019 |
} |
1020 |
||
1021 |
/* |
|
1022 |
* Iterate over all snapshots. |
|
1023 |
*/ |
|
1024 |
if ((flags & DS_FIND_SNAPSHOTS) && |
|
1025 |
dmu_objset_open(name, DMU_OST_ANY, |
|
1026 |
DS_MODE_STANDARD | DS_MODE_READONLY, &os) == 0) { |
|
1027 |
||
1028 |
snapobj = os->os->os_dsl_dataset->ds_phys->ds_snapnames_zapobj; |
|
1029 |
dmu_objset_close(os); |
|
1030 |
||
1031 |
for (zap_cursor_init(&zc, dd->dd_pool->dp_meta_objset, snapobj); |
|
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1032 |
zap_cursor_retrieve(&zc, attr) == 0; |
789 | 1033 |
(void) zap_cursor_advance(&zc)) { |
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1034 |
ASSERT(attr->za_integer_length == sizeof (uint64_t)); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1035 |
ASSERT(attr->za_num_integers == 1); |
789 | 1036 |
|
1037 |
child = kmem_alloc(MAXPATHLEN, KM_SLEEP); |
|
1038 |
/* XXX could probably just use name here */ |
|
1039 |
dsl_dir_name(dd, child); |
|
1040 |
(void) strcat(child, "@"); |
|
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1041 |
(void) strcat(child, attr->za_name); |
2199 | 1042 |
err = func(child, arg); |
789 | 1043 |
kmem_free(child, MAXPATHLEN); |
2199 | 1044 |
if (err) |
1045 |
break; |
|
789 | 1046 |
} |
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1047 |
zap_cursor_fini(&zc); |
789 | 1048 |
} |
1049 |
||
1050 |
dsl_dir_close(dd, FTAG); |
|
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1051 |
kmem_free(attr, sizeof (zap_attribute_t)); |
789 | 1052 |
|
2199 | 1053 |
if (err) |
1054 |
return (err); |
|
1055 |
||
789 | 1056 |
/* |
1057 |
* Apply to self if appropriate. |
|
1058 |
*/ |
|
1059 |
if (do_self) |
|
2199 | 1060 |
err = func(name, arg); |
1061 |
return (err); |
|
789 | 1062 |
} |