author | Jeff Bonwick <Jeff.Bonwick@Sun.COM> |
Mon, 29 Sep 2008 18:13:58 -0700 | |
changeset 7754 | b80e4842ad54 |
parent 7294 | c9c31ef4c960 |
child 8080 | 4299ee7a727e |
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 |
/* |
|
6174
7f23c0953907
6665004 missing zil_resume() when snapshots fail with EBUSY causes synchronous writes to crawl.
ahrens
parents:
5663
diff
changeset
|
22 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
4543 | 26 |
#include <sys/cred.h> |
789 | 27 |
#include <sys/zfs_context.h> |
28 |
#include <sys/dmu_objset.h> |
|
29 |
#include <sys/dsl_dir.h> |
|
30 |
#include <sys/dsl_dataset.h> |
|
31 |
#include <sys/dsl_prop.h> |
|
32 |
#include <sys/dsl_pool.h> |
|
2199 | 33 |
#include <sys/dsl_synctask.h> |
4543 | 34 |
#include <sys/dsl_deleg.h> |
789 | 35 |
#include <sys/dnode.h> |
36 |
#include <sys/dbuf.h> |
|
2885 | 37 |
#include <sys/zvol.h> |
789 | 38 |
#include <sys/dmu_tx.h> |
39 |
#include <sys/zio_checksum.h> |
|
40 |
#include <sys/zap.h> |
|
41 |
#include <sys/zil.h> |
|
42 |
#include <sys/dmu_impl.h> |
|
4543 | 43 |
#include <sys/zfs_ioctl.h> |
789 | 44 |
|
45 |
spa_t * |
|
46 |
dmu_objset_spa(objset_t *os) |
|
47 |
{ |
|
48 |
return (os->os->os_spa); |
|
49 |
} |
|
50 |
||
51 |
zilog_t * |
|
52 |
dmu_objset_zil(objset_t *os) |
|
53 |
{ |
|
54 |
return (os->os->os_zil); |
|
55 |
} |
|
56 |
||
57 |
dsl_pool_t * |
|
58 |
dmu_objset_pool(objset_t *os) |
|
59 |
{ |
|
60 |
dsl_dataset_t *ds; |
|
61 |
||
62 |
if ((ds = os->os->os_dsl_dataset) != NULL && ds->ds_dir) |
|
63 |
return (ds->ds_dir->dd_pool); |
|
64 |
else |
|
65 |
return (spa_get_dsl(os->os->os_spa)); |
|
66 |
} |
|
67 |
||
68 |
dsl_dataset_t * |
|
69 |
dmu_objset_ds(objset_t *os) |
|
70 |
{ |
|
71 |
return (os->os->os_dsl_dataset); |
|
72 |
} |
|
73 |
||
74 |
dmu_objset_type_t |
|
75 |
dmu_objset_type(objset_t *os) |
|
76 |
{ |
|
77 |
return (os->os->os_phys->os_type); |
|
78 |
} |
|
79 |
||
80 |
void |
|
81 |
dmu_objset_name(objset_t *os, char *buf) |
|
82 |
{ |
|
83 |
dsl_dataset_name(os->os->os_dsl_dataset, buf); |
|
84 |
} |
|
85 |
||
86 |
uint64_t |
|
87 |
dmu_objset_id(objset_t *os) |
|
88 |
{ |
|
89 |
dsl_dataset_t *ds = os->os->os_dsl_dataset; |
|
90 |
||
91 |
return (ds ? ds->ds_object : 0); |
|
92 |
} |
|
93 |
||
94 |
static void |
|
95 |
checksum_changed_cb(void *arg, uint64_t newval) |
|
96 |
{ |
|
97 |
objset_impl_t *osi = arg; |
|
98 |
||
99 |
/* |
|
100 |
* Inheritance should have been done by now. |
|
101 |
*/ |
|
102 |
ASSERT(newval != ZIO_CHECKSUM_INHERIT); |
|
103 |
||
104 |
osi->os_checksum = zio_checksum_select(newval, ZIO_CHECKSUM_ON_VALUE); |
|
105 |
} |
|
106 |
||
107 |
static void |
|
108 |
compression_changed_cb(void *arg, uint64_t newval) |
|
109 |
{ |
|
110 |
objset_impl_t *osi = arg; |
|
111 |
||
112 |
/* |
|
113 |
* Inheritance and range checking should have been done by now. |
|
114 |
*/ |
|
115 |
ASSERT(newval != ZIO_COMPRESS_INHERIT); |
|
116 |
||
117 |
osi->os_compress = zio_compress_select(newval, ZIO_COMPRESS_ON_VALUE); |
|
118 |
} |
|
119 |
||
3835 | 120 |
static void |
121 |
copies_changed_cb(void *arg, uint64_t newval) |
|
122 |
{ |
|
123 |
objset_impl_t *osi = arg; |
|
124 |
||
125 |
/* |
|
126 |
* Inheritance and range checking should have been done by now. |
|
127 |
*/ |
|
128 |
ASSERT(newval > 0); |
|
129 |
ASSERT(newval <= spa_max_replication(osi->os_spa)); |
|
130 |
||
131 |
osi->os_copies = newval; |
|
132 |
} |
|
133 |
||
7237
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
134 |
static void |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
135 |
primary_cache_changed_cb(void *arg, uint64_t newval) |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
136 |
{ |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
137 |
objset_impl_t *osi = arg; |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
138 |
|
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
139 |
/* |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
140 |
* Inheritance and range checking should have been done by now. |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
141 |
*/ |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
142 |
ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE || |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
143 |
newval == ZFS_CACHE_METADATA); |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
144 |
|
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
145 |
osi->os_primary_cache = newval; |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
146 |
} |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
147 |
|
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
148 |
static void |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
149 |
secondary_cache_changed_cb(void *arg, uint64_t newval) |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
150 |
{ |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
151 |
objset_impl_t *osi = arg; |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
152 |
|
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
153 |
/* |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
154 |
* Inheritance and range checking should have been done by now. |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
155 |
*/ |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
156 |
ASSERT(newval == ZFS_CACHE_ALL || newval == ZFS_CACHE_NONE || |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
157 |
newval == ZFS_CACHE_METADATA); |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
158 |
|
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
159 |
osi->os_secondary_cache = newval; |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
160 |
} |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
161 |
|
789 | 162 |
void |
163 |
dmu_objset_byteswap(void *buf, size_t size) |
|
164 |
{ |
|
165 |
objset_phys_t *osp = buf; |
|
166 |
||
167 |
ASSERT(size == sizeof (objset_phys_t)); |
|
168 |
dnode_byteswap(&osp->os_meta_dnode); |
|
169 |
byteswap_uint64_array(&osp->os_zil_header, sizeof (zil_header_t)); |
|
170 |
osp->os_type = BSWAP_64(osp->os_type); |
|
171 |
} |
|
172 |
||
1544 | 173 |
int |
174 |
dmu_objset_open_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp, |
|
175 |
objset_impl_t **osip) |
|
789 | 176 |
{ |
4787 | 177 |
objset_impl_t *osi; |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
178 |
int i, err; |
789 | 179 |
|
4787 | 180 |
ASSERT(ds == NULL || MUTEX_HELD(&ds->ds_opening_lock)); |
181 |
||
789 | 182 |
osi = kmem_zalloc(sizeof (objset_impl_t), KM_SLEEP); |
183 |
osi->os.os = osi; |
|
184 |
osi->os_dsl_dataset = ds; |
|
185 |
osi->os_spa = spa; |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
186 |
osi->os_rootbp = bp; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
187 |
if (!BP_IS_HOLE(osi->os_rootbp)) { |
2391 | 188 |
uint32_t aflags = ARC_WAIT; |
1544 | 189 |
zbookmark_t zb; |
190 |
zb.zb_objset = ds ? ds->ds_object : 0; |
|
191 |
zb.zb_object = 0; |
|
192 |
zb.zb_level = -1; |
|
193 |
zb.zb_blkid = 0; |
|
7237
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
194 |
if (DMU_OS_IS_L2CACHEABLE(osi)) |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
195 |
aflags |= ARC_L2CACHE; |
1544 | 196 |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
197 |
dprintf_bp(osi->os_rootbp, "reading %s", ""); |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
198 |
/* |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
199 |
* NB: when bprewrite scrub can change the bp, |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
200 |
* and this is called from dmu_objset_open_ds_os, the bp |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
201 |
* could change, and we'll need a lock. |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
202 |
*/ |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
203 |
err = arc_read_nolock(NULL, spa, osi->os_rootbp, |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
204 |
arc_getbuf_func, &osi->os_phys_buf, |
2391 | 205 |
ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &aflags, &zb); |
1544 | 206 |
if (err) { |
207 |
kmem_free(osi, sizeof (objset_impl_t)); |
|
7294 | 208 |
/* convert checksum errors into IO errors */ |
209 |
if (err == ECKSUM) |
|
210 |
err = EIO; |
|
1544 | 211 |
return (err); |
212 |
} |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
213 |
osi->os_phys = osi->os_phys_buf->b_data; |
789 | 214 |
} else { |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
215 |
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
|
216 |
&osi->os_phys_buf, ARC_BUFC_METADATA); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
217 |
osi->os_phys = osi->os_phys_buf->b_data; |
789 | 218 |
bzero(osi->os_phys, sizeof (objset_phys_t)); |
219 |
} |
|
220 |
||
221 |
/* |
|
222 |
* Note: the changed_cb will be called once before the register |
|
223 |
* func returns, thus changing the checksum/compression from the |
|
7237
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
224 |
* default (fletcher2/off). Snapshots don't need to know about |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
225 |
* checksum/compression/copies. |
789 | 226 |
*/ |
7237
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
227 |
if (ds) { |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
228 |
err = dsl_prop_register(ds, "primarycache", |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
229 |
primary_cache_changed_cb, osi); |
1544 | 230 |
if (err == 0) |
7237
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
231 |
err = dsl_prop_register(ds, "secondarycache", |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
232 |
secondary_cache_changed_cb, osi); |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
233 |
if (!dsl_dataset_is_snapshot(ds)) { |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
234 |
if (err == 0) |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
235 |
err = dsl_prop_register(ds, "checksum", |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
236 |
checksum_changed_cb, osi); |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
237 |
if (err == 0) |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
238 |
err = dsl_prop_register(ds, "compression", |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
239 |
compression_changed_cb, osi); |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
240 |
if (err == 0) |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
241 |
err = dsl_prop_register(ds, "copies", |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
242 |
copies_changed_cb, osi); |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
243 |
} |
1544 | 244 |
if (err) { |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
245 |
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
|
246 |
&osi->os_phys_buf) == 1); |
1544 | 247 |
kmem_free(osi, sizeof (objset_impl_t)); |
248 |
return (err); |
|
249 |
} |
|
2082 | 250 |
} else if (ds == NULL) { |
789 | 251 |
/* It's the meta-objset. */ |
252 |
osi->os_checksum = ZIO_CHECKSUM_FLETCHER_4; |
|
1544 | 253 |
osi->os_compress = ZIO_COMPRESS_LZJB; |
3835 | 254 |
osi->os_copies = spa_max_replication(spa); |
7237
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
255 |
osi->os_primary_cache = ZFS_CACHE_ALL; |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
256 |
osi->os_secondary_cache = ZFS_CACHE_ALL; |
789 | 257 |
} |
258 |
||
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
259 |
osi->os_zil_header = osi->os_phys->os_zil_header; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
260 |
osi->os_zil = zil_alloc(&osi->os, &osi->os_zil_header); |
789 | 261 |
|
262 |
for (i = 0; i < TXG_SIZE; i++) { |
|
263 |
list_create(&osi->os_dirty_dnodes[i], sizeof (dnode_t), |
|
264 |
offsetof(dnode_t, dn_dirty_link[i])); |
|
265 |
list_create(&osi->os_free_dnodes[i], sizeof (dnode_t), |
|
266 |
offsetof(dnode_t, dn_dirty_link[i])); |
|
267 |
} |
|
268 |
list_create(&osi->os_dnodes, sizeof (dnode_t), |
|
269 |
offsetof(dnode_t, dn_link)); |
|
270 |
list_create(&osi->os_downgraded_dbufs, sizeof (dmu_buf_impl_t), |
|
271 |
offsetof(dmu_buf_impl_t, db_link)); |
|
272 |
||
2856 | 273 |
mutex_init(&osi->os_lock, NULL, MUTEX_DEFAULT, NULL); |
274 |
mutex_init(&osi->os_obj_lock, NULL, MUTEX_DEFAULT, NULL); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
275 |
mutex_init(&osi->os_user_ptr_lock, NULL, MUTEX_DEFAULT, NULL); |
2856 | 276 |
|
789 | 277 |
osi->os_meta_dnode = dnode_special_open(osi, |
278 |
&osi->os_phys->os_meta_dnode, DMU_META_DNODE_OBJECT); |
|
279 |
||
4787 | 280 |
/* |
281 |
* We should be the only thread trying to do this because we |
|
282 |
* have ds_opening_lock |
|
283 |
*/ |
|
284 |
if (ds) { |
|
285 |
VERIFY(NULL == dsl_dataset_set_user_ptr(ds, osi, |
|
286 |
dmu_objset_evict)); |
|
789 | 287 |
} |
288 |
||
1544 | 289 |
*osip = osi; |
290 |
return (0); |
|
789 | 291 |
} |
292 |
||
5367 | 293 |
static int |
294 |
dmu_objset_open_ds_os(dsl_dataset_t *ds, objset_t *os, dmu_objset_type_t type) |
|
295 |
{ |
|
296 |
objset_impl_t *osi; |
|
297 |
||
298 |
mutex_enter(&ds->ds_opening_lock); |
|
299 |
osi = dsl_dataset_get_user_ptr(ds); |
|
300 |
if (osi == NULL) { |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
301 |
int err; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
302 |
|
5367 | 303 |
err = dmu_objset_open_impl(dsl_dataset_get_spa(ds), |
304 |
ds, &ds->ds_phys->ds_bp, &osi); |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
305 |
if (err) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
306 |
mutex_exit(&ds->ds_opening_lock); |
5367 | 307 |
return (err); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
308 |
} |
5367 | 309 |
} |
310 |
mutex_exit(&ds->ds_opening_lock); |
|
311 |
||
312 |
os->os = osi; |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
313 |
os->os_mode = DS_MODE_NOHOLD; |
5367 | 314 |
|
315 |
if (type != DMU_OST_ANY && type != os->os->os_phys->os_type) |
|
316 |
return (EINVAL); |
|
317 |
return (0); |
|
318 |
} |
|
319 |
||
320 |
int |
|
321 |
dmu_objset_open_ds(dsl_dataset_t *ds, dmu_objset_type_t type, objset_t **osp) |
|
322 |
{ |
|
323 |
objset_t *os; |
|
324 |
int err; |
|
325 |
||
326 |
os = kmem_alloc(sizeof (objset_t), KM_SLEEP); |
|
327 |
err = dmu_objset_open_ds_os(ds, os, type); |
|
328 |
if (err) |
|
329 |
kmem_free(os, sizeof (objset_t)); |
|
330 |
else |
|
331 |
*osp = os; |
|
332 |
return (err); |
|
333 |
} |
|
334 |
||
789 | 335 |
/* called from zpl */ |
336 |
int |
|
337 |
dmu_objset_open(const char *name, dmu_objset_type_t type, int mode, |
|
338 |
objset_t **osp) |
|
339 |
{ |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
340 |
objset_t *os; |
789 | 341 |
dsl_dataset_t *ds; |
342 |
int err; |
|
343 |
||
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
344 |
ASSERT(DS_MODE_TYPE(mode) == DS_MODE_USER || |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
345 |
DS_MODE_TYPE(mode) == DS_MODE_OWNER); |
5367 | 346 |
|
789 | 347 |
os = kmem_alloc(sizeof (objset_t), KM_SLEEP); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
348 |
if (DS_MODE_TYPE(mode) == DS_MODE_USER) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
349 |
err = dsl_dataset_hold(name, os, &ds); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
350 |
else |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
351 |
err = dsl_dataset_own(name, mode, os, &ds); |
789 | 352 |
if (err) { |
353 |
kmem_free(os, sizeof (objset_t)); |
|
354 |
return (err); |
|
355 |
} |
|
356 |
||
5367 | 357 |
err = dmu_objset_open_ds_os(ds, os, type); |
358 |
if (err) { |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
359 |
if (DS_MODE_TYPE(mode) == DS_MODE_USER) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
360 |
dsl_dataset_rele(ds, os); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
361 |
else |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
362 |
dsl_dataset_disown(ds, os); |
5367 | 363 |
kmem_free(os, sizeof (objset_t)); |
364 |
} else { |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
365 |
os->os_mode = mode; |
5367 | 366 |
*osp = os; |
789 | 367 |
} |
5367 | 368 |
return (err); |
789 | 369 |
} |
370 |
||
371 |
void |
|
372 |
dmu_objset_close(objset_t *os) |
|
373 |
{ |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
374 |
ASSERT(DS_MODE_TYPE(os->os_mode) == DS_MODE_USER || |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
375 |
DS_MODE_TYPE(os->os_mode) == DS_MODE_OWNER || |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
376 |
DS_MODE_TYPE(os->os_mode) == DS_MODE_NOHOLD); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
377 |
|
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
378 |
if (DS_MODE_TYPE(os->os_mode) == DS_MODE_USER) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
379 |
dsl_dataset_rele(os->os->os_dsl_dataset, os); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
380 |
else if (DS_MODE_TYPE(os->os_mode) == DS_MODE_OWNER) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
381 |
dsl_dataset_disown(os->os->os_dsl_dataset, os); |
789 | 382 |
kmem_free(os, sizeof (objset_t)); |
383 |
} |
|
384 |
||
1646
b4e43ae19fff
6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents:
1596
diff
changeset
|
385 |
int |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4935
diff
changeset
|
386 |
dmu_objset_evict_dbufs(objset_t *os) |
1544 | 387 |
{ |
388 |
objset_impl_t *osi = os->os; |
|
389 |
dnode_t *dn; |
|
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
390 |
|
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
391 |
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
|
392 |
|
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
393 |
/* 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
|
394 |
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
|
395 |
list_insert_tail(&osi->os_dnodes, osi->os_meta_dnode); |
1544 | 396 |
|
397 |
/* |
|
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
398 |
* 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
|
399 |
* 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
|
400 |
* 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
|
401 |
* skip. |
1544 | 402 |
*/ |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
403 |
for (dn = list_head(&osi->os_dnodes); |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4935
diff
changeset
|
404 |
dn && !dnode_add_ref(dn, FTAG); |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
405 |
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
|
406 |
continue; |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
407 |
|
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
408 |
while (dn) { |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
409 |
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
|
410 |
|
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
411 |
do { |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
412 |
next_dn = list_next(&osi->os_dnodes, next_dn); |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4935
diff
changeset
|
413 |
} while (next_dn && !dnode_add_ref(next_dn, FTAG)); |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
414 |
|
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
415 |
mutex_exit(&osi->os_lock); |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4935
diff
changeset
|
416 |
dnode_evict_dbufs(dn); |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
417 |
dnode_rele(dn, FTAG); |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
418 |
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
|
419 |
dn = next_dn; |
1544 | 420 |
} |
421 |
mutex_exit(&osi->os_lock); |
|
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4935
diff
changeset
|
422 |
return (list_head(&osi->os_dnodes) != osi->os_meta_dnode); |
1544 | 423 |
} |
424 |
||
425 |
void |
|
789 | 426 |
dmu_objset_evict(dsl_dataset_t *ds, void *arg) |
427 |
{ |
|
428 |
objset_impl_t *osi = arg; |
|
1544 | 429 |
objset_t os; |
2082 | 430 |
int i; |
789 | 431 |
|
432 |
for (i = 0; i < TXG_SIZE; i++) { |
|
433 |
ASSERT(list_head(&osi->os_dirty_dnodes[i]) == NULL); |
|
434 |
ASSERT(list_head(&osi->os_free_dnodes[i]) == NULL); |
|
435 |
} |
|
436 |
||
7237
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
437 |
if (ds) { |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
438 |
if (!dsl_dataset_is_snapshot(ds)) { |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
439 |
VERIFY(0 == dsl_prop_unregister(ds, "checksum", |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
440 |
checksum_changed_cb, osi)); |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
441 |
VERIFY(0 == dsl_prop_unregister(ds, "compression", |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
442 |
compression_changed_cb, osi)); |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
443 |
VERIFY(0 == dsl_prop_unregister(ds, "copies", |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
444 |
copies_changed_cb, osi)); |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
445 |
} |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
446 |
VERIFY(0 == dsl_prop_unregister(ds, "primarycache", |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
447 |
primary_cache_changed_cb, osi)); |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
448 |
VERIFY(0 == dsl_prop_unregister(ds, "secondarycache", |
f47d41541b14
PSARC 2008/393 zfs primarycache and secondarycache properties
ek110237
parents:
7046
diff
changeset
|
449 |
secondary_cache_changed_cb, osi)); |
789 | 450 |
} |
451 |
||
1544 | 452 |
/* |
453 |
* We should need only a single pass over the dnode list, since |
|
454 |
* nothing can be added to the list at this point. |
|
455 |
*/ |
|
456 |
os.os = osi; |
|
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4935
diff
changeset
|
457 |
(void) dmu_objset_evict_dbufs(&os); |
1544 | 458 |
|
789 | 459 |
ASSERT3P(list_head(&osi->os_dnodes), ==, osi->os_meta_dnode); |
460 |
ASSERT3P(list_tail(&osi->os_dnodes), ==, osi->os_meta_dnode); |
|
461 |
ASSERT3P(list_head(&osi->os_meta_dnode->dn_dbufs), ==, NULL); |
|
462 |
||
463 |
dnode_special_close(osi->os_meta_dnode); |
|
464 |
zil_free(osi->os_zil); |
|
465 |
||
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
466 |
VERIFY(arc_buf_remove_ref(osi->os_phys_buf, &osi->os_phys_buf) == 1); |
2856 | 467 |
mutex_destroy(&osi->os_lock); |
468 |
mutex_destroy(&osi->os_obj_lock); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
469 |
mutex_destroy(&osi->os_user_ptr_lock); |
789 | 470 |
kmem_free(osi, sizeof (objset_impl_t)); |
471 |
} |
|
472 |
||
473 |
/* called from dsl for meta-objset */ |
|
474 |
objset_impl_t * |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
475 |
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
|
476 |
dmu_objset_type_t type, dmu_tx_t *tx) |
789 | 477 |
{ |
478 |
objset_impl_t *osi; |
|
479 |
dnode_t *mdn; |
|
480 |
||
481 |
ASSERT(dmu_tx_is_syncing(tx)); |
|
4787 | 482 |
if (ds) |
483 |
mutex_enter(&ds->ds_opening_lock); |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
484 |
VERIFY(0 == dmu_objset_open_impl(spa, ds, bp, &osi)); |
4787 | 485 |
if (ds) |
486 |
mutex_exit(&ds->ds_opening_lock); |
|
789 | 487 |
mdn = osi->os_meta_dnode; |
488 |
||
489 |
dnode_allocate(mdn, DMU_OT_DNODE, 1 << DNODE_BLOCK_SHIFT, |
|
490 |
DN_MAX_INDBLKSHIFT, DMU_OT_NONE, 0, tx); |
|
491 |
||
492 |
/* |
|
493 |
* We don't want to have to increase the meta-dnode's nlevels |
|
494 |
* later, because then we could do it in quescing context while |
|
495 |
* we are also accessing it in open context. |
|
496 |
* |
|
497 |
* This precaution is not necessary for the MOS (ds == NULL), |
|
498 |
* because the MOS is only updated in syncing context. |
|
499 |
* This is most fortunate: the MOS is the only objset that |
|
500 |
* needs to be synced multiple times as spa_sync() iterates |
|
501 |
* to convergence, so minimizing its dn_nlevels matters. |
|
502 |
*/ |
|
1544 | 503 |
if (ds != NULL) { |
504 |
int levels = 1; |
|
505 |
||
506 |
/* |
|
507 |
* Determine the number of levels necessary for the meta-dnode |
|
508 |
* to contain DN_MAX_OBJECT dnodes. |
|
509 |
*/ |
|
510 |
while ((uint64_t)mdn->dn_nblkptr << (mdn->dn_datablkshift + |
|
511 |
(levels - 1) * (mdn->dn_indblkshift - SPA_BLKPTRSHIFT)) < |
|
512 |
DN_MAX_OBJECT * sizeof (dnode_phys_t)) |
|
513 |
levels++; |
|
514 |
||
789 | 515 |
mdn->dn_next_nlevels[tx->tx_txg & TXG_MASK] = |
1544 | 516 |
mdn->dn_nlevels = levels; |
517 |
} |
|
789 | 518 |
|
519 |
ASSERT(type != DMU_OST_NONE); |
|
520 |
ASSERT(type != DMU_OST_ANY); |
|
521 |
ASSERT(type < DMU_OST_NUMTYPES); |
|
522 |
osi->os_phys->os_type = type; |
|
523 |
||
524 |
dsl_dataset_dirty(ds, tx); |
|
525 |
||
526 |
return (osi); |
|
527 |
} |
|
528 |
||
529 |
struct oscarg { |
|
4543 | 530 |
void (*userfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx); |
789 | 531 |
void *userarg; |
532 |
dsl_dataset_t *clone_parent; |
|
533 |
const char *lastname; |
|
534 |
dmu_objset_type_t type; |
|
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
535 |
uint64_t flags; |
789 | 536 |
}; |
537 |
||
4543 | 538 |
/*ARGSUSED*/ |
789 | 539 |
static int |
2199 | 540 |
dmu_objset_create_check(void *arg1, void *arg2, dmu_tx_t *tx) |
789 | 541 |
{ |
2199 | 542 |
dsl_dir_t *dd = arg1; |
543 |
struct oscarg *oa = arg2; |
|
544 |
objset_t *mos = dd->dd_pool->dp_meta_objset; |
|
545 |
int err; |
|
546 |
uint64_t ddobj; |
|
547 |
||
548 |
err = zap_lookup(mos, dd->dd_phys->dd_child_dir_zapobj, |
|
549 |
oa->lastname, sizeof (uint64_t), 1, &ddobj); |
|
550 |
if (err != ENOENT) |
|
551 |
return (err ? err : EEXIST); |
|
552 |
||
553 |
if (oa->clone_parent != NULL) { |
|
554 |
/* |
|
555 |
* You can't clone across pools. |
|
556 |
*/ |
|
557 |
if (oa->clone_parent->ds_dir->dd_pool != dd->dd_pool) |
|
558 |
return (EXDEV); |
|
559 |
||
560 |
/* |
|
561 |
* You can only clone snapshots, not the head datasets. |
|
562 |
*/ |
|
563 |
if (oa->clone_parent->ds_phys->ds_num_children == 0) |
|
564 |
return (EINVAL); |
|
565 |
} |
|
4543 | 566 |
|
2199 | 567 |
return (0); |
568 |
} |
|
569 |
||
570 |
static void |
|
4543 | 571 |
dmu_objset_create_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
2199 | 572 |
{ |
573 |
dsl_dir_t *dd = arg1; |
|
574 |
struct oscarg *oa = arg2; |
|
789 | 575 |
dsl_dataset_t *ds; |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
576 |
blkptr_t *bp; |
2199 | 577 |
uint64_t dsobj; |
789 | 578 |
|
579 |
ASSERT(dmu_tx_is_syncing(tx)); |
|
580 |
||
2199 | 581 |
dsobj = dsl_dataset_create_sync(dd, oa->lastname, |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
582 |
oa->clone_parent, oa->flags, cr, tx); |
789 | 583 |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
584 |
VERIFY(0 == dsl_dataset_hold_obj(dd->dd_pool, dsobj, FTAG, &ds)); |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
585 |
bp = dsl_dataset_get_blkptr(ds); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
586 |
if (BP_IS_HOLE(bp)) { |
789 | 587 |
objset_impl_t *osi; |
588 |
||
589 |
/* This is an empty dmu_objset; not a clone. */ |
|
590 |
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
|
591 |
ds, bp, oa->type, tx); |
789 | 592 |
|
593 |
if (oa->userfunc) |
|
4543 | 594 |
oa->userfunc(&osi->os, oa->userarg, cr, tx); |
789 | 595 |
} |
4543 | 596 |
|
597 |
spa_history_internal_log(LOG_DS_CREATE, dd->dd_pool->dp_spa, |
|
598 |
tx, cr, "dataset = %llu", dsobj); |
|
599 |
||
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
600 |
dsl_dataset_rele(ds, FTAG); |
789 | 601 |
} |
602 |
||
603 |
int |
|
604 |
dmu_objset_create(const char *name, dmu_objset_type_t type, |
|
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
605 |
objset_t *clone_parent, uint64_t flags, |
4543 | 606 |
void (*func)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx), void *arg) |
789 | 607 |
{ |
2199 | 608 |
dsl_dir_t *pdd; |
789 | 609 |
const char *tail; |
610 |
int err = 0; |
|
2199 | 611 |
struct oscarg oa = { 0 }; |
789 | 612 |
|
2199 | 613 |
ASSERT(strchr(name, '@') == NULL); |
614 |
err = dsl_dir_open(name, FTAG, &pdd, &tail); |
|
1544 | 615 |
if (err) |
616 |
return (err); |
|
789 | 617 |
if (tail == NULL) { |
2199 | 618 |
dsl_dir_close(pdd, FTAG); |
789 | 619 |
return (EEXIST); |
620 |
} |
|
621 |
||
622 |
dprintf("name=%s\n", name); |
|
623 |
||
2199 | 624 |
oa.userfunc = func; |
625 |
oa.userarg = arg; |
|
626 |
oa.lastname = tail; |
|
627 |
oa.type = type; |
|
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
628 |
oa.flags = flags; |
4543 | 629 |
|
2199 | 630 |
if (clone_parent != NULL) { |
789 | 631 |
/* |
2199 | 632 |
* You can't clone to a different type. |
789 | 633 |
*/ |
2199 | 634 |
if (clone_parent->os->os_phys->os_type != type) { |
635 |
dsl_dir_close(pdd, FTAG); |
|
636 |
return (EINVAL); |
|
789 | 637 |
} |
2199 | 638 |
oa.clone_parent = clone_parent->os->os_dsl_dataset; |
789 | 639 |
} |
2199 | 640 |
err = dsl_sync_task_do(pdd->dd_pool, dmu_objset_create_check, |
641 |
dmu_objset_create_sync, pdd, &oa, 5); |
|
642 |
dsl_dir_close(pdd, FTAG); |
|
789 | 643 |
return (err); |
644 |
} |
|
645 |
||
646 |
int |
|
647 |
dmu_objset_destroy(const char *name) |
|
648 |
{ |
|
649 |
objset_t *os; |
|
650 |
int error; |
|
651 |
||
652 |
/* |
|
653 |
* If it looks like we'll be able to destroy it, and there's |
|
654 |
* an unplayed replay log sitting around, destroy the log. |
|
655 |
* It would be nicer to do this in dsl_dataset_destroy_sync(), |
|
656 |
* but the replay log objset is modified in open context. |
|
657 |
*/ |
|
5367 | 658 |
error = dmu_objset_open(name, DMU_OST_ANY, |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
659 |
DS_MODE_OWNER|DS_MODE_READONLY|DS_MODE_INCONSISTENT, &os); |
789 | 660 |
if (error == 0) { |
5367 | 661 |
dsl_dataset_t *ds = os->os->os_dsl_dataset; |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1775
diff
changeset
|
662 |
zil_destroy(dmu_objset_zil(os), B_FALSE); |
5367 | 663 |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
664 |
error = dsl_dataset_destroy(ds, os); |
5367 | 665 |
/* |
666 |
* dsl_dataset_destroy() closes the ds. |
|
667 |
*/ |
|
668 |
kmem_free(os, sizeof (objset_t)); |
|
789 | 669 |
} |
670 |
||
5367 | 671 |
return (error); |
789 | 672 |
} |
673 |
||
5446 | 674 |
/* |
675 |
* This will close the objset. |
|
676 |
*/ |
|
789 | 677 |
int |
5446 | 678 |
dmu_objset_rollback(objset_t *os) |
789 | 679 |
{ |
680 |
int err; |
|
5367 | 681 |
dsl_dataset_t *ds; |
789 | 682 |
|
5446 | 683 |
ds = os->os->os_dsl_dataset; |
4935
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4787
diff
changeset
|
684 |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
685 |
if (!dsl_dataset_tryown(ds, TRUE, os)) { |
5446 | 686 |
dmu_objset_close(os); |
687 |
return (EBUSY); |
|
688 |
} |
|
689 |
||
5367 | 690 |
err = dsl_dataset_rollback(ds, os->os->os_phys->os_type); |
4935
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4787
diff
changeset
|
691 |
|
5367 | 692 |
/* |
693 |
* NB: we close the objset manually because the rollback |
|
694 |
* actually implicitly called dmu_objset_evict(), thus freeing |
|
695 |
* the objset_impl_t. |
|
696 |
*/ |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
697 |
dsl_dataset_disown(ds, os); |
5367 | 698 |
kmem_free(os, sizeof (objset_t)); |
789 | 699 |
return (err); |
700 |
} |
|
701 |
||
2199 | 702 |
struct snaparg { |
703 |
dsl_sync_task_group_t *dstg; |
|
704 |
char *snapname; |
|
705 |
char failed[MAXPATHLEN]; |
|
4543 | 706 |
boolean_t checkperms; |
5367 | 707 |
list_t objsets; |
708 |
}; |
|
709 |
||
710 |
struct osnode { |
|
711 |
list_node_t node; |
|
712 |
objset_t *os; |
|
2199 | 713 |
}; |
714 |
||
715 |
static int |
|
716 |
dmu_objset_snapshot_one(char *name, void *arg) |
|
717 |
{ |
|
718 |
struct snaparg *sn = arg; |
|
719 |
objset_t *os; |
|
720 |
int err; |
|
721 |
||
722 |
(void) strcpy(sn->failed, name); |
|
723 |
||
4543 | 724 |
/* |
725 |
* Check permissions only when requested. This only applies when |
|
726 |
* doing a recursive snapshot. The permission checks for the starting |
|
727 |
* dataset have already been performed in zfs_secpolicy_snapshot() |
|
728 |
*/ |
|
729 |
if (sn->checkperms == B_TRUE && |
|
730 |
(err = zfs_secpolicy_snapshot_perms(name, CRED()))) |
|
731 |
return (err); |
|
732 |
||
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
733 |
err = dmu_objset_open(name, DMU_OST_ANY, DS_MODE_USER, &os); |
2199 | 734 |
if (err != 0) |
735 |
return (err); |
|
736 |
||
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
737 |
/* If the objset is in an inconsistent state, return busy */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
738 |
if (os->os->os_dsl_dataset->ds_phys->ds_flags & DS_FLAG_INCONSISTENT) { |
3637
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
739 |
dmu_objset_close(os); |
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
740 |
return (EBUSY); |
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
741 |
} |
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
742 |
|
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
743 |
/* |
2199 | 744 |
* NB: we need to wait for all in-flight changes to get to disk, |
745 |
* so that we snapshot those changes. zil_suspend does this as |
|
746 |
* a side effect. |
|
747 |
*/ |
|
748 |
err = zil_suspend(dmu_objset_zil(os)); |
|
749 |
if (err == 0) { |
|
5367 | 750 |
struct osnode *osn; |
2199 | 751 |
dsl_sync_task_create(sn->dstg, dsl_dataset_snapshot_check, |
5367 | 752 |
dsl_dataset_snapshot_sync, os->os->os_dsl_dataset, |
753 |
sn->snapname, 3); |
|
754 |
osn = kmem_alloc(sizeof (struct osnode), KM_SLEEP); |
|
755 |
osn->os = os; |
|
756 |
list_insert_tail(&sn->objsets, osn); |
|
3637
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
757 |
} else { |
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
758 |
dmu_objset_close(os); |
2199 | 759 |
} |
3637
526d8412c163
6402600 administrative actions while doing 'zfs recv' or 'zfs destroy' can cause confusing situation
rm160521
parents:
3547
diff
changeset
|
760 |
|
2199 | 761 |
return (err); |
762 |
} |
|
763 |
||
764 |
int |
|
765 |
dmu_objset_snapshot(char *fsname, char *snapname, boolean_t recursive) |
|
766 |
{ |
|
767 |
dsl_sync_task_t *dst; |
|
5367 | 768 |
struct osnode *osn; |
2199 | 769 |
struct snaparg sn = { 0 }; |
770 |
spa_t *spa; |
|
771 |
int err; |
|
772 |
||
773 |
(void) strcpy(sn.failed, fsname); |
|
774 |
||
4603
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4543
diff
changeset
|
775 |
err = spa_open(fsname, &spa, FTAG); |
2199 | 776 |
if (err) |
777 |
return (err); |
|
778 |
||
779 |
sn.dstg = dsl_sync_task_group_create(spa_get_dsl(spa)); |
|
780 |
sn.snapname = snapname; |
|
5367 | 781 |
list_create(&sn.objsets, sizeof (struct osnode), |
782 |
offsetof(struct osnode, node)); |
|
2199 | 783 |
|
2417 | 784 |
if (recursive) { |
4543 | 785 |
sn.checkperms = B_TRUE; |
2417 | 786 |
err = dmu_objset_find(fsname, |
787 |
dmu_objset_snapshot_one, &sn, DS_FIND_CHILDREN); |
|
788 |
} else { |
|
4543 | 789 |
sn.checkperms = B_FALSE; |
2199 | 790 |
err = dmu_objset_snapshot_one(fsname, &sn); |
2417 | 791 |
} |
2199 | 792 |
|
793 |
if (err) |
|
794 |
goto out; |
|
795 |
||
796 |
err = dsl_sync_task_group_wait(sn.dstg); |
|
797 |
||
798 |
for (dst = list_head(&sn.dstg->dstg_tasks); dst; |
|
799 |
dst = list_next(&sn.dstg->dstg_tasks, dst)) { |
|
5367 | 800 |
dsl_dataset_t *ds = dst->dst_arg1; |
2199 | 801 |
if (dst->dst_err) |
5367 | 802 |
dsl_dataset_name(ds, sn.failed); |
2199 | 803 |
} |
5367 | 804 |
|
6174
7f23c0953907
6665004 missing zil_resume() when snapshots fail with EBUSY causes synchronous writes to crawl.
ahrens
parents:
5663
diff
changeset
|
805 |
out: |
5367 | 806 |
while (osn = list_head(&sn.objsets)) { |
807 |
list_remove(&sn.objsets, osn); |
|
808 |
zil_resume(dmu_objset_zil(osn->os)); |
|
809 |
dmu_objset_close(osn->os); |
|
810 |
kmem_free(osn, sizeof (struct osnode)); |
|
811 |
} |
|
812 |
list_destroy(&sn.objsets); |
|
6174
7f23c0953907
6665004 missing zil_resume() when snapshots fail with EBUSY causes synchronous writes to crawl.
ahrens
parents:
5663
diff
changeset
|
813 |
|
2199 | 814 |
if (err) |
815 |
(void) strcpy(fsname, sn.failed); |
|
816 |
dsl_sync_task_group_destroy(sn.dstg); |
|
817 |
spa_close(spa, FTAG); |
|
818 |
return (err); |
|
819 |
} |
|
820 |
||
789 | 821 |
static void |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
822 |
dmu_objset_sync_dnodes(list_t *list, dmu_tx_t *tx) |
789 | 823 |
{ |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
824 |
dnode_t *dn; |
789 | 825 |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
826 |
while (dn = list_head(list)) { |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
827 |
ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
828 |
ASSERT(dn->dn_dbuf->db_data_pending); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
829 |
/* |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
830 |
* Initialize dn_zio outside dnode_sync() |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
831 |
* to accomodate meta-dnode |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
832 |
*/ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
833 |
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
|
834 |
ASSERT(dn->dn_zio); |
789 | 835 |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
836 |
ASSERT3U(dn->dn_nlevels, <=, DN_MAX_LEVELS); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
837 |
list_remove(list, dn); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
838 |
dnode_sync(dn, tx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
839 |
} |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
840 |
} |
2981 | 841 |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
842 |
/* ARGSUSED */ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
843 |
static void |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
844 |
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
|
845 |
{ |
7754
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
846 |
blkptr_t *bp = zio->io_bp; |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
847 |
blkptr_t *bp_orig = &zio->io_bp_orig; |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
848 |
objset_impl_t *os = arg; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
849 |
dnode_phys_t *dnp = &os->os_phys->os_meta_dnode; |
2981 | 850 |
|
7754
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
851 |
ASSERT(bp == os->os_rootbp); |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
852 |
ASSERT(BP_GET_TYPE(bp) == DMU_OT_OBJSET); |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
853 |
ASSERT(BP_GET_LEVEL(bp) == 0); |
5329 | 854 |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
855 |
/* |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
856 |
* Update rootbp fill count. |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
857 |
*/ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
858 |
bp->blk_fill = 1; /* count the meta-dnode */ |
7754
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
859 |
for (int i = 0; i < dnp->dn_nblkptr; i++) |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
860 |
bp->blk_fill += dnp->dn_blkptr[i].blk_fill; |
5329 | 861 |
|
7754
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
862 |
if (zio->io_flags & ZIO_FLAG_IO_REWRITE) { |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
863 |
ASSERT(DVA_EQUAL(BP_IDENTITY(bp), BP_IDENTITY(bp_orig))); |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
864 |
} else { |
5329 | 865 |
if (zio->io_bp_orig.blk_birth == os->os_synctx->tx_txg) |
6992 | 866 |
(void) dsl_dataset_block_kill(os->os_dsl_dataset, |
7754
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
867 |
&zio->io_bp_orig, zio, os->os_synctx); |
5329 | 868 |
dsl_dataset_block_born(os->os_dsl_dataset, bp, os->os_synctx); |
869 |
} |
|
789 | 870 |
} |
871 |
||
872 |
/* called from dsl */ |
|
873 |
void |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
874 |
dmu_objset_sync(objset_impl_t *os, zio_t *pio, dmu_tx_t *tx) |
789 | 875 |
{ |
876 |
int txgoff; |
|
1544 | 877 |
zbookmark_t zb; |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
878 |
writeprops_t wp = { 0 }; |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
879 |
zio_t *zio; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
880 |
list_t *list; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
881 |
dbuf_dirty_record_t *dr; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
882 |
|
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
883 |
dprintf_ds(os->os_dsl_dataset, "txg=%llu\n", tx->tx_txg); |
789 | 884 |
|
885 |
ASSERT(dmu_tx_is_syncing(tx)); |
|
886 |
/* XXX the write_done callback should really give us the tx... */ |
|
887 |
os->os_synctx = tx; |
|
888 |
||
3882 | 889 |
if (os->os_dsl_dataset == NULL) { |
890 |
/* |
|
891 |
* This is the MOS. If we have upgraded, |
|
892 |
* spa_max_replication() could change, so reset |
|
893 |
* os_copies here. |
|
894 |
*/ |
|
895 |
os->os_copies = spa_max_replication(os->os_spa); |
|
896 |
} |
|
897 |
||
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
898 |
/* |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
899 |
* Create the root block IO |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
900 |
*/ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
901 |
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
|
902 |
zb.zb_object = 0; |
7754
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
903 |
zb.zb_level = -1; /* for block ordering; it's level 0 on disk */ |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
904 |
zb.zb_blkid = 0; |
7754
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
905 |
|
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
906 |
wp.wp_type = DMU_OT_OBJSET; |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
907 |
wp.wp_level = 0; /* on-disk BP level; see above */ |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
908 |
wp.wp_copies = os->os_copies; |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
909 |
wp.wp_oschecksum = os->os_checksum; |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
910 |
wp.wp_oscompress = os->os_compress; |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
911 |
|
4787 | 912 |
if (BP_IS_OLDER(os->os_rootbp, tx->tx_txg)) { |
6992 | 913 |
(void) dsl_dataset_block_kill(os->os_dsl_dataset, |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
914 |
os->os_rootbp, pio, tx); |
4787 | 915 |
} |
7754
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
916 |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
917 |
arc_release(os->os_phys_buf, &os->os_phys_buf); |
7754
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
918 |
zio = arc_write(pio, os->os_spa, &wp, DMU_OS_IS_L2CACHEABLE(os), |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
919 |
tx->tx_txg, os->os_rootbp, os->os_phys_buf, ready, NULL, os, |
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7294
diff
changeset
|
920 |
ZIO_PRIORITY_ASYNC_WRITE, ZIO_FLAG_MUSTSUCCEED, &zb); |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
921 |
|
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
922 |
/* |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
923 |
* 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
|
924 |
*/ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
925 |
os->os_meta_dnode->dn_zio = zio; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
926 |
dnode_sync(os->os_meta_dnode, tx); |
789 | 927 |
|
928 |
txgoff = tx->tx_txg & TXG_MASK; |
|
929 |
||
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
930 |
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
|
931 |
dmu_objset_sync_dnodes(&os->os_dirty_dnodes[txgoff], tx); |
789 | 932 |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
933 |
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
|
934 |
while (dr = list_head(list)) { |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
935 |
ASSERT(dr->dr_dbuf->db_level == 0); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
936 |
list_remove(list, dr); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
937 |
if (dr->dr_zio) |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
938 |
zio_nowait(dr->dr_zio); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
939 |
} |
789 | 940 |
/* |
941 |
* Free intent log blocks up to this tx. |
|
942 |
*/ |
|
943 |
zil_sync(os->os_zil, tx); |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
944 |
os->os_phys->os_zil_header = os->os_zil_header; |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3290
diff
changeset
|
945 |
zio_nowait(zio); |
789 | 946 |
} |
947 |
||
948 |
void |
|
2885 | 949 |
dmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp, |
950 |
uint64_t *usedobjsp, uint64_t *availobjsp) |
|
951 |
{ |
|
952 |
dsl_dataset_space(os->os->os_dsl_dataset, refdbytesp, availbytesp, |
|
953 |
usedobjsp, availobjsp); |
|
954 |
} |
|
955 |
||
956 |
uint64_t |
|
957 |
dmu_objset_fsid_guid(objset_t *os) |
|
958 |
{ |
|
959 |
return (dsl_dataset_fsid_guid(os->os->os_dsl_dataset)); |
|
960 |
} |
|
961 |
||
962 |
void |
|
963 |
dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat) |
|
789 | 964 |
{ |
2885 | 965 |
stat->dds_type = os->os->os_phys->os_type; |
966 |
if (os->os->os_dsl_dataset) |
|
967 |
dsl_dataset_fast_stat(os->os->os_dsl_dataset, stat); |
|
968 |
} |
|
969 |
||
970 |
void |
|
971 |
dmu_objset_stats(objset_t *os, nvlist_t *nv) |
|
972 |
{ |
|
973 |
ASSERT(os->os->os_dsl_dataset || |
|
974 |
os->os->os_phys->os_type == DMU_OST_META); |
|
975 |
||
976 |
if (os->os->os_dsl_dataset != NULL) |
|
977 |
dsl_dataset_stats(os->os->os_dsl_dataset, nv); |
|
978 |
||
979 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_TYPE, |
|
980 |
os->os->os_phys->os_type); |
|
789 | 981 |
} |
982 |
||
983 |
int |
|
984 |
dmu_objset_is_snapshot(objset_t *os) |
|
985 |
{ |
|
986 |
if (os->os->os_dsl_dataset != NULL) |
|
987 |
return (dsl_dataset_is_snapshot(os->os->os_dsl_dataset)); |
|
988 |
else |
|
989 |
return (B_FALSE); |
|
990 |
} |
|
991 |
||
992 |
int |
|
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
993 |
dmu_snapshot_realname(objset_t *os, char *name, char *real, int maxlen, |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
994 |
boolean_t *conflict) |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
995 |
{ |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
996 |
dsl_dataset_t *ds = os->os->os_dsl_dataset; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
997 |
uint64_t ignored; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
998 |
|
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
999 |
if (ds->ds_phys->ds_snapnames_zapobj == 0) |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
1000 |
return (ENOENT); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
1001 |
|
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
1002 |
return (zap_lookup_norm(ds->ds_dir->dd_pool->dp_meta_objset, |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
1003 |
ds->ds_phys->ds_snapnames_zapobj, name, 8, 1, &ignored, MT_FIRST, |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
1004 |
real, maxlen, conflict)); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
1005 |
} |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
1006 |
|
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6174
diff
changeset
|
1007 |
int |
789 | 1008 |
dmu_snapshot_list_next(objset_t *os, int namelen, char *name, |
5663
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5446
diff
changeset
|
1009 |
uint64_t *idp, uint64_t *offp, boolean_t *case_conflict) |
789 | 1010 |
{ |
1011 |
dsl_dataset_t *ds = os->os->os_dsl_dataset; |
|
1012 |
zap_cursor_t cursor; |
|
1013 |
zap_attribute_t attr; |
|
1014 |
||
1015 |
if (ds->ds_phys->ds_snapnames_zapobj == 0) |
|
1016 |
return (ENOENT); |
|
1017 |
||
1018 |
zap_cursor_init_serialized(&cursor, |
|
1019 |
ds->ds_dir->dd_pool->dp_meta_objset, |
|
1020 |
ds->ds_phys->ds_snapnames_zapobj, *offp); |
|
1021 |
||
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1022 |
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
|
1023 |
zap_cursor_fini(&cursor); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1024 |
return (ENOENT); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1025 |
} |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1026 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1027 |
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
|
1028 |
zap_cursor_fini(&cursor); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1029 |
return (ENAMETOOLONG); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1030 |
} |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1031 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1032 |
(void) strcpy(name, attr.za_name); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1033 |
if (idp) |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1034 |
*idp = attr.za_first_integer; |
5663
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5446
diff
changeset
|
1035 |
if (case_conflict) |
029cc4273b57
6627223 gfs needs to support extended dirent flags
ck153898
parents:
5446
diff
changeset
|
1036 |
*case_conflict = attr.za_normalization_conflict; |
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1037 |
zap_cursor_advance(&cursor); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1038 |
*offp = zap_cursor_serialize(&cursor); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1039 |
zap_cursor_fini(&cursor); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1040 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1041 |
return (0); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1042 |
} |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1043 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1044 |
int |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1045 |
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
|
1046 |
uint64_t *idp, uint64_t *offp) |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1047 |
{ |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1048 |
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
|
1049 |
zap_cursor_t cursor; |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1050 |
zap_attribute_t attr; |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1051 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1052 |
/* 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
|
1053 |
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
|
1054 |
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
|
1055 |
return (ENOENT); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1056 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1057 |
zap_cursor_init_serialized(&cursor, |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1058 |
dd->dd_pool->dp_meta_objset, |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1059 |
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
|
1060 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1061 |
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
|
1062 |
zap_cursor_fini(&cursor); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1063 |
return (ENOENT); |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1064 |
} |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1065 |
|
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1066 |
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
|
1067 |
zap_cursor_fini(&cursor); |
789 | 1068 |
return (ENAMETOOLONG); |
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1069 |
} |
789 | 1070 |
|
1071 |
(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
|
1072 |
if (idp) |
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1073 |
*idp = attr.za_first_integer; |
789 | 1074 |
zap_cursor_advance(&cursor); |
1075 |
*offp = zap_cursor_serialize(&cursor); |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
1076 |
zap_cursor_fini(&cursor); |
789 | 1077 |
|
1078 |
return (0); |
|
1079 |
} |
|
1080 |
||
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1081 |
struct findarg { |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1082 |
int (*func)(char *, void *); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1083 |
void *arg; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1084 |
}; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1085 |
|
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1086 |
/* ARGSUSED */ |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1087 |
static int |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1088 |
findfunc(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1089 |
{ |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1090 |
struct findarg *fa = arg; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1091 |
return (fa->func((char *)dsname, fa->arg)); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1092 |
} |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1093 |
|
789 | 1094 |
/* |
1095 |
* Find all objsets under name, and for each, call 'func(child_name, arg)'. |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1096 |
* Perhaps change all callers to use dmu_objset_find_spa()? |
789 | 1097 |
*/ |
2199 | 1098 |
int |
1099 |
dmu_objset_find(char *name, int func(char *, void *), void *arg, int flags) |
|
789 | 1100 |
{ |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1101 |
struct findarg fa; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1102 |
fa.func = func; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1103 |
fa.arg = arg; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1104 |
return (dmu_objset_find_spa(NULL, name, findfunc, &fa, flags)); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1105 |
} |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1106 |
|
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1107 |
/* |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1108 |
* Find all objsets under name, call func on each |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1109 |
*/ |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1110 |
int |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1111 |
dmu_objset_find_spa(spa_t *spa, const char *name, |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1112 |
int func(spa_t *, uint64_t, const char *, void *), void *arg, int flags) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1113 |
{ |
789 | 1114 |
dsl_dir_t *dd; |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1115 |
dsl_pool_t *dp; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1116 |
dsl_dataset_t *ds; |
789 | 1117 |
zap_cursor_t zc; |
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1118 |
zap_attribute_t *attr; |
789 | 1119 |
char *child; |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1120 |
uint64_t thisobj; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1121 |
int err; |
789 | 1122 |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1123 |
if (name == NULL) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1124 |
name = spa_name(spa); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1125 |
err = dsl_dir_open_spa(spa, name, FTAG, &dd, NULL); |
1544 | 1126 |
if (err) |
2199 | 1127 |
return (err); |
789 | 1128 |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1129 |
/* Don't visit hidden ($MOS & $ORIGIN) objsets. */ |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1130 |
if (dd->dd_myname[0] == '$') { |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1131 |
dsl_dir_close(dd, FTAG); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1132 |
return (0); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1133 |
} |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1134 |
|
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1135 |
thisobj = dd->dd_phys->dd_head_dataset_obj; |
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1136 |
attr = kmem_alloc(sizeof (zap_attribute_t), KM_SLEEP); |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1137 |
dp = dd->dd_pool; |
789 | 1138 |
|
1139 |
/* |
|
1140 |
* Iterate over all children. |
|
1141 |
*/ |
|
2417 | 1142 |
if (flags & DS_FIND_CHILDREN) { |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1143 |
for (zap_cursor_init(&zc, dp->dp_meta_objset, |
2417 | 1144 |
dd->dd_phys->dd_child_dir_zapobj); |
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1145 |
zap_cursor_retrieve(&zc, attr) == 0; |
2417 | 1146 |
(void) zap_cursor_advance(&zc)) { |
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1147 |
ASSERT(attr->za_integer_length == sizeof (uint64_t)); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1148 |
ASSERT(attr->za_num_integers == 1); |
789 | 1149 |
|
2417 | 1150 |
child = kmem_alloc(MAXPATHLEN, KM_SLEEP); |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1151 |
(void) strcpy(child, name); |
2417 | 1152 |
(void) strcat(child, "/"); |
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1153 |
(void) strcat(child, attr->za_name); |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1154 |
err = dmu_objset_find_spa(spa, child, func, arg, flags); |
2417 | 1155 |
kmem_free(child, MAXPATHLEN); |
1156 |
if (err) |
|
1157 |
break; |
|
1158 |
} |
|
1159 |
zap_cursor_fini(&zc); |
|
2199 | 1160 |
|
2417 | 1161 |
if (err) { |
1162 |
dsl_dir_close(dd, FTAG); |
|
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1163 |
kmem_free(attr, sizeof (zap_attribute_t)); |
2417 | 1164 |
return (err); |
1165 |
} |
|
789 | 1166 |
} |
1167 |
||
1168 |
/* |
|
1169 |
* Iterate over all snapshots. |
|
1170 |
*/ |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1171 |
if (flags & DS_FIND_SNAPSHOTS) { |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1172 |
if (!dsl_pool_sync_context(dp)) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1173 |
rw_enter(&dp->dp_config_rwlock, RW_READER); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1174 |
err = dsl_dataset_hold_obj(dp, thisobj, FTAG, &ds); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1175 |
if (!dsl_pool_sync_context(dp)) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1176 |
rw_exit(&dp->dp_config_rwlock); |
789 | 1177 |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1178 |
if (err == 0) { |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1179 |
uint64_t snapobj = ds->ds_phys->ds_snapnames_zapobj; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1180 |
dsl_dataset_rele(ds, FTAG); |
789 | 1181 |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1182 |
for (zap_cursor_init(&zc, dp->dp_meta_objset, snapobj); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1183 |
zap_cursor_retrieve(&zc, attr) == 0; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1184 |
(void) zap_cursor_advance(&zc)) { |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1185 |
ASSERT(attr->za_integer_length == |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1186 |
sizeof (uint64_t)); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1187 |
ASSERT(attr->za_num_integers == 1); |
789 | 1188 |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1189 |
child = kmem_alloc(MAXPATHLEN, KM_SLEEP); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1190 |
(void) strcpy(child, name); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1191 |
(void) strcat(child, "@"); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1192 |
(void) strcat(child, attr->za_name); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1193 |
err = func(spa, attr->za_first_integer, |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1194 |
child, arg); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1195 |
kmem_free(child, MAXPATHLEN); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1196 |
if (err) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1197 |
break; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1198 |
} |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1199 |
zap_cursor_fini(&zc); |
789 | 1200 |
} |
1201 |
} |
|
1202 |
||
1203 |
dsl_dir_close(dd, FTAG); |
|
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3897
diff
changeset
|
1204 |
kmem_free(attr, sizeof (zap_attribute_t)); |
789 | 1205 |
|
2199 | 1206 |
if (err) |
1207 |
return (err); |
|
1208 |
||
789 | 1209 |
/* |
1210 |
* Apply to self if appropriate. |
|
1211 |
*/ |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
1212 |
err = func(spa, thisobj, name, arg); |
2199 | 1213 |
return (err); |
789 | 1214 |
} |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1215 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1216 |
void |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1217 |
dmu_objset_set_user(objset_t *os, void *user_ptr) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1218 |
{ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1219 |
ASSERT(MUTEX_HELD(&os->os->os_user_ptr_lock)); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1220 |
os->os->os_user_ptr = user_ptr; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1221 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1222 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1223 |
void * |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1224 |
dmu_objset_get_user(objset_t *os) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1225 |
{ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1226 |
ASSERT(MUTEX_HELD(&os->os->os_user_ptr_lock)); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1227 |
return (os->os->os_user_ptr); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1228 |
} |