]>
Commit | Line | Data |
---|---|---|
34dc7c2f BB |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
5 | * Common Development and Distribution License (the "License"). | |
6 | * You may not use this file except in compliance with the License. | |
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 | /* | |
428870ff | 22 | * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
13fe0198 | 23 | * Copyright (c) 2013 by Delphix. All rights reserved. |
37abac6d | 24 | * Copyright (c) 2012, Joyent, Inc. All rights reserved. |
34dc7c2f BB |
25 | */ |
26 | ||
34dc7c2f BB |
27 | #include <sys/dmu_objset.h> |
28 | #include <sys/dsl_dataset.h> | |
29 | #include <sys/dsl_dir.h> | |
30 | #include <sys/dsl_prop.h> | |
31 | #include <sys/dsl_synctask.h> | |
32 | #include <sys/dmu_traverse.h> | |
37abac6d | 33 | #include <sys/dmu_impl.h> |
34dc7c2f BB |
34 | #include <sys/dmu_tx.h> |
35 | #include <sys/arc.h> | |
36 | #include <sys/zio.h> | |
37 | #include <sys/zap.h> | |
9ae529ec | 38 | #include <sys/zfeature.h> |
34dc7c2f BB |
39 | #include <sys/unique.h> |
40 | #include <sys/zfs_context.h> | |
41 | #include <sys/zfs_ioctl.h> | |
42 | #include <sys/spa.h> | |
b128c09f | 43 | #include <sys/zfs_znode.h> |
572e2857 | 44 | #include <sys/zfs_onexit.h> |
45d1cae3 | 45 | #include <sys/zvol.h> |
428870ff BB |
46 | #include <sys/dsl_scan.h> |
47 | #include <sys/dsl_deadlist.h> | |
13fe0198 MA |
48 | #include <sys/dsl_destroy.h> |
49 | #include <sys/dsl_userhold.h> | |
34dc7c2f | 50 | |
428870ff BB |
51 | #define SWITCH64(x, y) \ |
52 | { \ | |
53 | uint64_t __tmp = (x); \ | |
54 | (x) = (y); \ | |
55 | (y) = __tmp; \ | |
56 | } | |
57 | ||
34dc7c2f BB |
58 | #define DS_REF_MAX (1ULL << 62) |
59 | ||
60 | #define DSL_DEADLIST_BLOCKSIZE SPA_MAXBLOCKSIZE | |
61 | ||
34dc7c2f BB |
62 | /* |
63 | * Figure out how much of this delta should be propogated to the dsl_dir | |
64 | * layer. If there's a refreservation, that space has already been | |
65 | * partially accounted for in our ancestors. | |
66 | */ | |
67 | static int64_t | |
68 | parent_delta(dsl_dataset_t *ds, int64_t delta) | |
69 | { | |
70 | uint64_t old_bytes, new_bytes; | |
71 | ||
72 | if (ds->ds_reserved == 0) | |
73 | return (delta); | |
74 | ||
75 | old_bytes = MAX(ds->ds_phys->ds_unique_bytes, ds->ds_reserved); | |
76 | new_bytes = MAX(ds->ds_phys->ds_unique_bytes + delta, ds->ds_reserved); | |
77 | ||
78 | ASSERT3U(ABS((int64_t)(new_bytes - old_bytes)), <=, ABS(delta)); | |
79 | return (new_bytes - old_bytes); | |
80 | } | |
81 | ||
82 | void | |
428870ff | 83 | dsl_dataset_block_born(dsl_dataset_t *ds, const blkptr_t *bp, dmu_tx_t *tx) |
34dc7c2f | 84 | { |
d6320ddb | 85 | int used, compressed, uncompressed; |
34dc7c2f BB |
86 | int64_t delta; |
87 | ||
d6320ddb BB |
88 | used = bp_get_dsize_sync(tx->tx_pool->dp_spa, bp); |
89 | compressed = BP_GET_PSIZE(bp); | |
90 | uncompressed = BP_GET_UCSIZE(bp); | |
91 | ||
428870ff | 92 | dprintf_bp(bp, "ds=%p", ds); |
34dc7c2f BB |
93 | |
94 | ASSERT(dmu_tx_is_syncing(tx)); | |
95 | /* It could have been compressed away to nothing */ | |
96 | if (BP_IS_HOLE(bp)) | |
97 | return; | |
98 | ASSERT(BP_GET_TYPE(bp) != DMU_OT_NONE); | |
9ae529ec | 99 | ASSERT(DMU_OT_IS_VALID(BP_GET_TYPE(bp))); |
34dc7c2f | 100 | if (ds == NULL) { |
29809a6c MA |
101 | dsl_pool_mos_diduse_space(tx->tx_pool, |
102 | used, compressed, uncompressed); | |
34dc7c2f BB |
103 | return; |
104 | } | |
428870ff | 105 | |
a169a625 | 106 | dmu_buf_will_dirty(ds->ds_dbuf, tx); |
34dc7c2f BB |
107 | mutex_enter(&ds->ds_lock); |
108 | delta = parent_delta(ds, used); | |
9ae529ec | 109 | ds->ds_phys->ds_referenced_bytes += used; |
34dc7c2f BB |
110 | ds->ds_phys->ds_compressed_bytes += compressed; |
111 | ds->ds_phys->ds_uncompressed_bytes += uncompressed; | |
112 | ds->ds_phys->ds_unique_bytes += used; | |
113 | mutex_exit(&ds->ds_lock); | |
b128c09f BB |
114 | dsl_dir_diduse_space(ds->ds_dir, DD_USED_HEAD, delta, |
115 | compressed, uncompressed, tx); | |
116 | dsl_dir_transfer_space(ds->ds_dir, used - delta, | |
117 | DD_USED_REFRSRV, DD_USED_HEAD, tx); | |
34dc7c2f BB |
118 | } |
119 | ||
b128c09f | 120 | int |
428870ff BB |
121 | dsl_dataset_block_kill(dsl_dataset_t *ds, const blkptr_t *bp, dmu_tx_t *tx, |
122 | boolean_t async) | |
34dc7c2f | 123 | { |
d6320ddb BB |
124 | int used, compressed, uncompressed; |
125 | ||
34dc7c2f | 126 | if (BP_IS_HOLE(bp)) |
b128c09f | 127 | return (0); |
34dc7c2f | 128 | |
428870ff BB |
129 | ASSERT(dmu_tx_is_syncing(tx)); |
130 | ASSERT(bp->blk_birth <= tx->tx_txg); | |
131 | ||
d6320ddb BB |
132 | used = bp_get_dsize_sync(tx->tx_pool->dp_spa, bp); |
133 | compressed = BP_GET_PSIZE(bp); | |
134 | uncompressed = BP_GET_UCSIZE(bp); | |
428870ff | 135 | |
34dc7c2f BB |
136 | ASSERT(used > 0); |
137 | if (ds == NULL) { | |
428870ff | 138 | dsl_free(tx->tx_pool, tx->tx_txg, bp); |
29809a6c MA |
139 | dsl_pool_mos_diduse_space(tx->tx_pool, |
140 | -used, -compressed, -uncompressed); | |
b128c09f | 141 | return (used); |
34dc7c2f BB |
142 | } |
143 | ASSERT3P(tx->tx_pool, ==, ds->ds_dir->dd_pool); | |
144 | ||
b128c09f | 145 | ASSERT(!dsl_dataset_is_snapshot(ds)); |
34dc7c2f BB |
146 | dmu_buf_will_dirty(ds->ds_dbuf, tx); |
147 | ||
148 | if (bp->blk_birth > ds->ds_phys->ds_prev_snap_txg) { | |
34dc7c2f BB |
149 | int64_t delta; |
150 | ||
428870ff BB |
151 | dprintf_bp(bp, "freeing ds=%llu", ds->ds_object); |
152 | dsl_free(tx->tx_pool, tx->tx_txg, bp); | |
34dc7c2f BB |
153 | |
154 | mutex_enter(&ds->ds_lock); | |
155 | ASSERT(ds->ds_phys->ds_unique_bytes >= used || | |
156 | !DS_UNIQUE_IS_ACCURATE(ds)); | |
157 | delta = parent_delta(ds, -used); | |
158 | ds->ds_phys->ds_unique_bytes -= used; | |
159 | mutex_exit(&ds->ds_lock); | |
b128c09f | 160 | dsl_dir_diduse_space(ds->ds_dir, DD_USED_HEAD, |
34dc7c2f | 161 | delta, -compressed, -uncompressed, tx); |
b128c09f BB |
162 | dsl_dir_transfer_space(ds->ds_dir, -used - delta, |
163 | DD_USED_REFRSRV, DD_USED_HEAD, tx); | |
34dc7c2f BB |
164 | } else { |
165 | dprintf_bp(bp, "putting on dead list: %s", ""); | |
428870ff BB |
166 | if (async) { |
167 | /* | |
168 | * We are here as part of zio's write done callback, | |
169 | * which means we're a zio interrupt thread. We can't | |
170 | * call dsl_deadlist_insert() now because it may block | |
171 | * waiting for I/O. Instead, put bp on the deferred | |
172 | * queue and let dsl_pool_sync() finish the job. | |
173 | */ | |
174 | bplist_append(&ds->ds_pending_deadlist, bp); | |
175 | } else { | |
176 | dsl_deadlist_insert(&ds->ds_deadlist, bp, tx); | |
177 | } | |
34dc7c2f BB |
178 | ASSERT3U(ds->ds_prev->ds_object, ==, |
179 | ds->ds_phys->ds_prev_snap_obj); | |
180 | ASSERT(ds->ds_prev->ds_phys->ds_num_children > 0); | |
181 | /* if (bp->blk_birth > prev prev snap txg) prev unique += bs */ | |
182 | if (ds->ds_prev->ds_phys->ds_next_snap_obj == | |
183 | ds->ds_object && bp->blk_birth > | |
184 | ds->ds_prev->ds_phys->ds_prev_snap_txg) { | |
185 | dmu_buf_will_dirty(ds->ds_prev->ds_dbuf, tx); | |
186 | mutex_enter(&ds->ds_prev->ds_lock); | |
187 | ds->ds_prev->ds_phys->ds_unique_bytes += used; | |
188 | mutex_exit(&ds->ds_prev->ds_lock); | |
189 | } | |
428870ff | 190 | if (bp->blk_birth > ds->ds_dir->dd_origin_txg) { |
b128c09f BB |
191 | dsl_dir_transfer_space(ds->ds_dir, used, |
192 | DD_USED_HEAD, DD_USED_SNAP, tx); | |
193 | } | |
34dc7c2f BB |
194 | } |
195 | mutex_enter(&ds->ds_lock); | |
9ae529ec CS |
196 | ASSERT3U(ds->ds_phys->ds_referenced_bytes, >=, used); |
197 | ds->ds_phys->ds_referenced_bytes -= used; | |
34dc7c2f BB |
198 | ASSERT3U(ds->ds_phys->ds_compressed_bytes, >=, compressed); |
199 | ds->ds_phys->ds_compressed_bytes -= compressed; | |
200 | ASSERT3U(ds->ds_phys->ds_uncompressed_bytes, >=, uncompressed); | |
201 | ds->ds_phys->ds_uncompressed_bytes -= uncompressed; | |
202 | mutex_exit(&ds->ds_lock); | |
b128c09f BB |
203 | |
204 | return (used); | |
34dc7c2f BB |
205 | } |
206 | ||
207 | uint64_t | |
208 | dsl_dataset_prev_snap_txg(dsl_dataset_t *ds) | |
209 | { | |
210 | uint64_t trysnap = 0; | |
211 | ||
212 | if (ds == NULL) | |
213 | return (0); | |
214 | /* | |
215 | * The snapshot creation could fail, but that would cause an | |
216 | * incorrect FALSE return, which would only result in an | |
217 | * overestimation of the amount of space that an operation would | |
218 | * consume, which is OK. | |
219 | * | |
220 | * There's also a small window where we could miss a pending | |
221 | * snapshot, because we could set the sync task in the quiescing | |
222 | * phase. So this should only be used as a guess. | |
223 | */ | |
224 | if (ds->ds_trysnap_txg > | |
225 | spa_last_synced_txg(ds->ds_dir->dd_pool->dp_spa)) | |
226 | trysnap = ds->ds_trysnap_txg; | |
227 | return (MAX(ds->ds_phys->ds_prev_snap_txg, trysnap)); | |
228 | } | |
229 | ||
9babb374 | 230 | boolean_t |
428870ff BB |
231 | dsl_dataset_block_freeable(dsl_dataset_t *ds, const blkptr_t *bp, |
232 | uint64_t blk_birth) | |
34dc7c2f | 233 | { |
428870ff BB |
234 | if (blk_birth <= dsl_dataset_prev_snap_txg(ds)) |
235 | return (B_FALSE); | |
236 | ||
572e2857 | 237 | ddt_prefetch(dsl_dataset_get_spa(ds), bp); |
428870ff BB |
238 | |
239 | return (B_TRUE); | |
34dc7c2f BB |
240 | } |
241 | ||
242 | /* ARGSUSED */ | |
243 | static void | |
244 | dsl_dataset_evict(dmu_buf_t *db, void *dsv) | |
245 | { | |
246 | dsl_dataset_t *ds = dsv; | |
247 | ||
13fe0198 | 248 | ASSERT(ds->ds_owner == NULL); |
34dc7c2f | 249 | |
34dc7c2f BB |
250 | unique_remove(ds->ds_fsid_guid); |
251 | ||
428870ff BB |
252 | if (ds->ds_objset != NULL) |
253 | dmu_objset_evict(ds->ds_objset); | |
34dc7c2f BB |
254 | |
255 | if (ds->ds_prev) { | |
13fe0198 | 256 | dsl_dataset_rele(ds->ds_prev, ds); |
34dc7c2f BB |
257 | ds->ds_prev = NULL; |
258 | } | |
259 | ||
428870ff | 260 | bplist_destroy(&ds->ds_pending_deadlist); |
13fe0198 | 261 | if (ds->ds_phys->ds_deadlist_obj != 0) |
428870ff | 262 | dsl_deadlist_close(&ds->ds_deadlist); |
b128c09f | 263 | if (ds->ds_dir) |
13fe0198 | 264 | dsl_dir_rele(ds->ds_dir, ds); |
34dc7c2f BB |
265 | |
266 | ASSERT(!list_link_active(&ds->ds_synced_link)); | |
267 | ||
268 | mutex_destroy(&ds->ds_lock); | |
269 | mutex_destroy(&ds->ds_opening_lock); | |
13fe0198 | 270 | refcount_destroy(&ds->ds_longholds); |
34dc7c2f BB |
271 | |
272 | kmem_free(ds, sizeof (dsl_dataset_t)); | |
273 | } | |
274 | ||
13fe0198 | 275 | int |
34dc7c2f BB |
276 | dsl_dataset_get_snapname(dsl_dataset_t *ds) |
277 | { | |
278 | dsl_dataset_phys_t *headphys; | |
279 | int err; | |
280 | dmu_buf_t *headdbuf; | |
281 | dsl_pool_t *dp = ds->ds_dir->dd_pool; | |
282 | objset_t *mos = dp->dp_meta_objset; | |
283 | ||
284 | if (ds->ds_snapname[0]) | |
285 | return (0); | |
286 | if (ds->ds_phys->ds_next_snap_obj == 0) | |
287 | return (0); | |
288 | ||
289 | err = dmu_bonus_hold(mos, ds->ds_dir->dd_phys->dd_head_dataset_obj, | |
290 | FTAG, &headdbuf); | |
13fe0198 | 291 | if (err != 0) |
34dc7c2f BB |
292 | return (err); |
293 | headphys = headdbuf->db_data; | |
294 | err = zap_value_search(dp->dp_meta_objset, | |
295 | headphys->ds_snapnames_zapobj, ds->ds_object, 0, ds->ds_snapname); | |
296 | dmu_buf_rele(headdbuf, FTAG); | |
297 | return (err); | |
298 | } | |
299 | ||
6772fb67 | 300 | int |
b128c09f | 301 | dsl_dataset_snap_lookup(dsl_dataset_t *ds, const char *name, uint64_t *value) |
34dc7c2f | 302 | { |
b128c09f BB |
303 | objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset; |
304 | uint64_t snapobj = ds->ds_phys->ds_snapnames_zapobj; | |
34dc7c2f BB |
305 | matchtype_t mt; |
306 | int err; | |
307 | ||
b128c09f | 308 | if (ds->ds_phys->ds_flags & DS_FLAG_CI_DATASET) |
34dc7c2f BB |
309 | mt = MT_FIRST; |
310 | else | |
311 | mt = MT_EXACT; | |
312 | ||
b128c09f | 313 | err = zap_lookup_norm(mos, snapobj, name, 8, 1, |
34dc7c2f BB |
314 | value, mt, NULL, 0, NULL); |
315 | if (err == ENOTSUP && mt == MT_FIRST) | |
b128c09f | 316 | err = zap_lookup(mos, snapobj, name, 8, 1, value); |
34dc7c2f BB |
317 | return (err); |
318 | } | |
319 | ||
13fe0198 MA |
320 | int |
321 | dsl_dataset_snap_remove(dsl_dataset_t *ds, const char *name, dmu_tx_t *tx) | |
34dc7c2f | 322 | { |
b128c09f BB |
323 | objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset; |
324 | uint64_t snapobj = ds->ds_phys->ds_snapnames_zapobj; | |
34dc7c2f BB |
325 | matchtype_t mt; |
326 | int err; | |
327 | ||
428870ff BB |
328 | dsl_dir_snap_cmtime_update(ds->ds_dir); |
329 | ||
b128c09f | 330 | if (ds->ds_phys->ds_flags & DS_FLAG_CI_DATASET) |
34dc7c2f BB |
331 | mt = MT_FIRST; |
332 | else | |
333 | mt = MT_EXACT; | |
334 | ||
b128c09f | 335 | err = zap_remove_norm(mos, snapobj, name, mt, tx); |
34dc7c2f | 336 | if (err == ENOTSUP && mt == MT_FIRST) |
b128c09f | 337 | err = zap_remove(mos, snapobj, name, tx); |
34dc7c2f BB |
338 | return (err); |
339 | } | |
340 | ||
13fe0198 MA |
341 | int |
342 | dsl_dataset_hold_obj(dsl_pool_t *dp, uint64_t dsobj, void *tag, | |
b128c09f | 343 | dsl_dataset_t **dsp) |
34dc7c2f | 344 | { |
34dc7c2f BB |
345 | objset_t *mos = dp->dp_meta_objset; |
346 | dmu_buf_t *dbuf; | |
347 | dsl_dataset_t *ds; | |
348 | int err; | |
572e2857 | 349 | dmu_object_info_t doi; |
34dc7c2f | 350 | |
13fe0198 | 351 | ASSERT(dsl_pool_config_held(dp)); |
34dc7c2f BB |
352 | |
353 | err = dmu_bonus_hold(mos, dsobj, tag, &dbuf); | |
13fe0198 | 354 | if (err != 0) |
34dc7c2f | 355 | return (err); |
572e2857 BB |
356 | |
357 | /* Make sure dsobj has the correct object type. */ | |
358 | dmu_object_info_from_db(dbuf, &doi); | |
3a84951d WA |
359 | if (doi.doi_type != DMU_OT_DSL_DATASET) { |
360 | dmu_buf_rele(dbuf, tag); | |
2e528b49 | 361 | return (SET_ERROR(EINVAL)); |
3a84951d | 362 | } |
572e2857 | 363 | |
34dc7c2f BB |
364 | ds = dmu_buf_get_user(dbuf); |
365 | if (ds == NULL) { | |
d4ed6673 | 366 | dsl_dataset_t *winner = NULL; |
34dc7c2f | 367 | |
b8d06fca | 368 | ds = kmem_zalloc(sizeof (dsl_dataset_t), KM_PUSHPAGE); |
34dc7c2f BB |
369 | ds->ds_dbuf = dbuf; |
370 | ds->ds_object = dsobj; | |
371 | ds->ds_phys = dbuf->db_data; | |
98f72a53 | 372 | list_link_init(&ds->ds_synced_link); |
34dc7c2f BB |
373 | |
374 | mutex_init(&ds->ds_lock, NULL, MUTEX_DEFAULT, NULL); | |
375 | mutex_init(&ds->ds_opening_lock, NULL, MUTEX_DEFAULT, NULL); | |
37abac6d | 376 | mutex_init(&ds->ds_sendstream_lock, NULL, MUTEX_DEFAULT, NULL); |
13fe0198 | 377 | refcount_create(&ds->ds_longholds); |
34dc7c2f | 378 | |
428870ff BB |
379 | bplist_create(&ds->ds_pending_deadlist); |
380 | dsl_deadlist_open(&ds->ds_deadlist, | |
34dc7c2f | 381 | mos, ds->ds_phys->ds_deadlist_obj); |
428870ff | 382 | |
37abac6d BP |
383 | list_create(&ds->ds_sendstreams, sizeof (dmu_sendarg_t), |
384 | offsetof(dmu_sendarg_t, dsa_link)); | |
385 | ||
34dc7c2f | 386 | if (err == 0) { |
13fe0198 | 387 | err = dsl_dir_hold_obj(dp, |
34dc7c2f BB |
388 | ds->ds_phys->ds_dir_obj, NULL, ds, &ds->ds_dir); |
389 | } | |
13fe0198 | 390 | if (err != 0) { |
34dc7c2f BB |
391 | mutex_destroy(&ds->ds_lock); |
392 | mutex_destroy(&ds->ds_opening_lock); | |
13fe0198 | 393 | refcount_destroy(&ds->ds_longholds); |
428870ff BB |
394 | bplist_destroy(&ds->ds_pending_deadlist); |
395 | dsl_deadlist_close(&ds->ds_deadlist); | |
34dc7c2f BB |
396 | kmem_free(ds, sizeof (dsl_dataset_t)); |
397 | dmu_buf_rele(dbuf, tag); | |
398 | return (err); | |
399 | } | |
400 | ||
b128c09f | 401 | if (!dsl_dataset_is_snapshot(ds)) { |
34dc7c2f | 402 | ds->ds_snapname[0] = '\0'; |
13fe0198 MA |
403 | if (ds->ds_phys->ds_prev_snap_obj != 0) { |
404 | err = dsl_dataset_hold_obj(dp, | |
b128c09f BB |
405 | ds->ds_phys->ds_prev_snap_obj, |
406 | ds, &ds->ds_prev); | |
34dc7c2f | 407 | } |
45d1cae3 BB |
408 | } else { |
409 | if (zfs_flags & ZFS_DEBUG_SNAPNAMES) | |
410 | err = dsl_dataset_get_snapname(ds); | |
411 | if (err == 0 && ds->ds_phys->ds_userrefs_obj != 0) { | |
412 | err = zap_count( | |
413 | ds->ds_dir->dd_pool->dp_meta_objset, | |
414 | ds->ds_phys->ds_userrefs_obj, | |
415 | &ds->ds_userrefs); | |
416 | } | |
34dc7c2f BB |
417 | } |
418 | ||
b128c09f | 419 | if (err == 0 && !dsl_dataset_is_snapshot(ds)) { |
13fe0198 MA |
420 | err = dsl_prop_get_int_ds(ds, |
421 | zfs_prop_to_name(ZFS_PROP_REFRESERVATION), | |
422 | &ds->ds_reserved); | |
34dc7c2f | 423 | if (err == 0) { |
13fe0198 MA |
424 | err = dsl_prop_get_int_ds(ds, |
425 | zfs_prop_to_name(ZFS_PROP_REFQUOTA), | |
426 | &ds->ds_quota); | |
34dc7c2f | 427 | } |
34dc7c2f BB |
428 | } else { |
429 | ds->ds_reserved = ds->ds_quota = 0; | |
430 | } | |
431 | ||
a117a6d6 GW |
432 | if (err != 0 || (winner = dmu_buf_set_user_ie(dbuf, ds, |
433 | &ds->ds_phys, dsl_dataset_evict)) != NULL) { | |
428870ff BB |
434 | bplist_destroy(&ds->ds_pending_deadlist); |
435 | dsl_deadlist_close(&ds->ds_deadlist); | |
b128c09f | 436 | if (ds->ds_prev) |
13fe0198 MA |
437 | dsl_dataset_rele(ds->ds_prev, ds); |
438 | dsl_dir_rele(ds->ds_dir, ds); | |
34dc7c2f BB |
439 | mutex_destroy(&ds->ds_lock); |
440 | mutex_destroy(&ds->ds_opening_lock); | |
13fe0198 | 441 | refcount_destroy(&ds->ds_longholds); |
34dc7c2f | 442 | kmem_free(ds, sizeof (dsl_dataset_t)); |
13fe0198 | 443 | if (err != 0) { |
34dc7c2f BB |
444 | dmu_buf_rele(dbuf, tag); |
445 | return (err); | |
446 | } | |
447 | ds = winner; | |
448 | } else { | |
449 | ds->ds_fsid_guid = | |
450 | unique_insert(ds->ds_phys->ds_fsid_guid); | |
451 | } | |
452 | } | |
453 | ASSERT3P(ds->ds_dbuf, ==, dbuf); | |
454 | ASSERT3P(ds->ds_phys, ==, dbuf->db_data); | |
b128c09f BB |
455 | ASSERT(ds->ds_phys->ds_prev_snap_obj != 0 || |
456 | spa_version(dp->dp_spa) < SPA_VERSION_ORIGIN || | |
457 | dp->dp_origin_snap == NULL || ds == dp->dp_origin_snap); | |
34dc7c2f BB |
458 | *dsp = ds; |
459 | return (0); | |
460 | } | |
461 | ||
b128c09f | 462 | int |
13fe0198 | 463 | dsl_dataset_hold(dsl_pool_t *dp, const char *name, |
428870ff | 464 | void *tag, dsl_dataset_t **dsp) |
34dc7c2f BB |
465 | { |
466 | dsl_dir_t *dd; | |
b128c09f | 467 | const char *snapname; |
34dc7c2f | 468 | uint64_t obj; |
34dc7c2f BB |
469 | int err = 0; |
470 | ||
13fe0198 MA |
471 | err = dsl_dir_hold(dp, name, FTAG, &dd, &snapname); |
472 | if (err != 0) | |
34dc7c2f BB |
473 | return (err); |
474 | ||
13fe0198 | 475 | ASSERT(dsl_pool_config_held(dp)); |
34dc7c2f | 476 | obj = dd->dd_phys->dd_head_dataset_obj; |
13fe0198 MA |
477 | if (obj != 0) |
478 | err = dsl_dataset_hold_obj(dp, obj, tag, dsp); | |
b128c09f | 479 | else |
2e528b49 | 480 | err = SET_ERROR(ENOENT); |
34dc7c2f | 481 | |
b128c09f BB |
482 | /* we may be looking for a snapshot */ |
483 | if (err == 0 && snapname != NULL) { | |
13fe0198 | 484 | dsl_dataset_t *ds; |
34dc7c2f | 485 | |
b128c09f BB |
486 | if (*snapname++ != '@') { |
487 | dsl_dataset_rele(*dsp, tag); | |
13fe0198 | 488 | dsl_dir_rele(dd, FTAG); |
2e528b49 | 489 | return (SET_ERROR(ENOENT)); |
34dc7c2f | 490 | } |
34dc7c2f | 491 | |
b128c09f BB |
492 | dprintf("looking for snapshot '%s'\n", snapname); |
493 | err = dsl_dataset_snap_lookup(*dsp, snapname, &obj); | |
494 | if (err == 0) | |
13fe0198 | 495 | err = dsl_dataset_hold_obj(dp, obj, tag, &ds); |
b128c09f BB |
496 | dsl_dataset_rele(*dsp, tag); |
497 | ||
13fe0198 | 498 | if (err == 0) { |
b128c09f BB |
499 | mutex_enter(&ds->ds_lock); |
500 | if (ds->ds_snapname[0] == 0) | |
501 | (void) strlcpy(ds->ds_snapname, snapname, | |
502 | sizeof (ds->ds_snapname)); | |
503 | mutex_exit(&ds->ds_lock); | |
13fe0198 | 504 | *dsp = ds; |
34dc7c2f | 505 | } |
34dc7c2f | 506 | } |
13fe0198 MA |
507 | |
508 | dsl_dir_rele(dd, FTAG); | |
34dc7c2f BB |
509 | return (err); |
510 | } | |
511 | ||
512 | int | |
13fe0198 | 513 | dsl_dataset_own_obj(dsl_pool_t *dp, uint64_t dsobj, |
428870ff | 514 | void *tag, dsl_dataset_t **dsp) |
34dc7c2f | 515 | { |
13fe0198 MA |
516 | int err = dsl_dataset_hold_obj(dp, dsobj, tag, dsp); |
517 | if (err != 0) | |
518 | return (err); | |
519 | if (!dsl_dataset_tryown(*dsp, tag)) { | |
520 | dsl_dataset_rele(*dsp, tag); | |
521 | *dsp = NULL; | |
2e528b49 | 522 | return (SET_ERROR(EBUSY)); |
13fe0198 MA |
523 | } |
524 | return (0); | |
525 | } | |
526 | ||
527 | int | |
528 | dsl_dataset_own(dsl_pool_t *dp, const char *name, | |
529 | void *tag, dsl_dataset_t **dsp) | |
530 | { | |
531 | int err = dsl_dataset_hold(dp, name, tag, dsp); | |
532 | if (err != 0) | |
b128c09f | 533 | return (err); |
13fe0198 | 534 | if (!dsl_dataset_tryown(*dsp, tag)) { |
428870ff | 535 | dsl_dataset_rele(*dsp, tag); |
2e528b49 | 536 | return (SET_ERROR(EBUSY)); |
b128c09f BB |
537 | } |
538 | return (0); | |
34dc7c2f BB |
539 | } |
540 | ||
13fe0198 MA |
541 | /* |
542 | * See the comment above dsl_pool_hold() for details. In summary, a long | |
543 | * hold is used to prevent destruction of a dataset while the pool hold | |
544 | * is dropped, allowing other concurrent operations (e.g. spa_sync()). | |
545 | * | |
546 | * The dataset and pool must be held when this function is called. After it | |
547 | * is called, the pool hold may be released while the dataset is still held | |
548 | * and accessed. | |
549 | */ | |
550 | void | |
551 | dsl_dataset_long_hold(dsl_dataset_t *ds, void *tag) | |
552 | { | |
553 | ASSERT(dsl_pool_config_held(ds->ds_dir->dd_pool)); | |
554 | (void) refcount_add(&ds->ds_longholds, tag); | |
555 | } | |
556 | ||
557 | void | |
558 | dsl_dataset_long_rele(dsl_dataset_t *ds, void *tag) | |
559 | { | |
560 | (void) refcount_remove(&ds->ds_longholds, tag); | |
561 | } | |
562 | ||
563 | /* Return B_TRUE if there are any long holds on this dataset. */ | |
564 | boolean_t | |
565 | dsl_dataset_long_held(dsl_dataset_t *ds) | |
566 | { | |
567 | return (!refcount_is_zero(&ds->ds_longholds)); | |
568 | } | |
569 | ||
34dc7c2f BB |
570 | void |
571 | dsl_dataset_name(dsl_dataset_t *ds, char *name) | |
572 | { | |
573 | if (ds == NULL) { | |
574 | (void) strcpy(name, "mos"); | |
575 | } else { | |
576 | dsl_dir_name(ds->ds_dir, name); | |
13fe0198 | 577 | VERIFY0(dsl_dataset_get_snapname(ds)); |
34dc7c2f BB |
578 | if (ds->ds_snapname[0]) { |
579 | (void) strcat(name, "@"); | |
b128c09f BB |
580 | /* |
581 | * We use a "recursive" mutex so that we | |
582 | * can call dprintf_ds() with ds_lock held. | |
583 | */ | |
34dc7c2f | 584 | if (!MUTEX_HELD(&ds->ds_lock)) { |
34dc7c2f BB |
585 | mutex_enter(&ds->ds_lock); |
586 | (void) strcat(name, ds->ds_snapname); | |
587 | mutex_exit(&ds->ds_lock); | |
588 | } else { | |
589 | (void) strcat(name, ds->ds_snapname); | |
590 | } | |
591 | } | |
592 | } | |
593 | } | |
594 | ||
34dc7c2f | 595 | void |
b128c09f BB |
596 | dsl_dataset_rele(dsl_dataset_t *ds, void *tag) |
597 | { | |
13fe0198 | 598 | dmu_buf_rele(ds->ds_dbuf, tag); |
b128c09f BB |
599 | } |
600 | ||
601 | void | |
428870ff | 602 | dsl_dataset_disown(dsl_dataset_t *ds, void *tag) |
34dc7c2f | 603 | { |
13fe0198 | 604 | ASSERT(ds->ds_owner == tag && ds->ds_dbuf != NULL); |
b128c09f | 605 | |
34dc7c2f | 606 | mutex_enter(&ds->ds_lock); |
b128c09f | 607 | ds->ds_owner = NULL; |
34dc7c2f | 608 | mutex_exit(&ds->ds_lock); |
13fe0198 MA |
609 | dsl_dataset_long_rele(ds, tag); |
610 | if (ds->ds_dbuf != NULL) | |
611 | dsl_dataset_rele(ds, tag); | |
b128c09f | 612 | else |
428870ff | 613 | dsl_dataset_evict(NULL, ds); |
34dc7c2f BB |
614 | } |
615 | ||
616 | boolean_t | |
13fe0198 | 617 | dsl_dataset_tryown(dsl_dataset_t *ds, void *tag) |
34dc7c2f | 618 | { |
b128c09f BB |
619 | boolean_t gotit = FALSE; |
620 | ||
34dc7c2f | 621 | mutex_enter(&ds->ds_lock); |
13fe0198 | 622 | if (ds->ds_owner == NULL && !DS_IS_INCONSISTENT(ds)) { |
428870ff | 623 | ds->ds_owner = tag; |
13fe0198 | 624 | dsl_dataset_long_hold(ds, tag); |
b128c09f | 625 | gotit = TRUE; |
34dc7c2f BB |
626 | } |
627 | mutex_exit(&ds->ds_lock); | |
b128c09f | 628 | return (gotit); |
34dc7c2f BB |
629 | } |
630 | ||
34dc7c2f | 631 | uint64_t |
b128c09f | 632 | dsl_dataset_create_sync_dd(dsl_dir_t *dd, dsl_dataset_t *origin, |
34dc7c2f BB |
633 | uint64_t flags, dmu_tx_t *tx) |
634 | { | |
635 | dsl_pool_t *dp = dd->dd_pool; | |
636 | dmu_buf_t *dbuf; | |
637 | dsl_dataset_phys_t *dsphys; | |
638 | uint64_t dsobj; | |
639 | objset_t *mos = dp->dp_meta_objset; | |
640 | ||
b128c09f BB |
641 | if (origin == NULL) |
642 | origin = dp->dp_origin_snap; | |
643 | ||
34dc7c2f BB |
644 | ASSERT(origin == NULL || origin->ds_dir->dd_pool == dp); |
645 | ASSERT(origin == NULL || origin->ds_phys->ds_num_children > 0); | |
646 | ASSERT(dmu_tx_is_syncing(tx)); | |
647 | ASSERT(dd->dd_phys->dd_head_dataset_obj == 0); | |
648 | ||
649 | dsobj = dmu_object_alloc(mos, DMU_OT_DSL_DATASET, 0, | |
650 | DMU_OT_DSL_DATASET, sizeof (dsl_dataset_phys_t), tx); | |
13fe0198 | 651 | VERIFY0(dmu_bonus_hold(mos, dsobj, FTAG, &dbuf)); |
34dc7c2f BB |
652 | dmu_buf_will_dirty(dbuf, tx); |
653 | dsphys = dbuf->db_data; | |
b128c09f | 654 | bzero(dsphys, sizeof (dsl_dataset_phys_t)); |
34dc7c2f BB |
655 | dsphys->ds_dir_obj = dd->dd_object; |
656 | dsphys->ds_flags = flags; | |
657 | dsphys->ds_fsid_guid = unique_create(); | |
658 | (void) random_get_pseudo_bytes((void*)&dsphys->ds_guid, | |
659 | sizeof (dsphys->ds_guid)); | |
660 | dsphys->ds_snapnames_zapobj = | |
661 | zap_create_norm(mos, U8_TEXTPREP_TOUPPER, DMU_OT_DSL_DS_SNAP_MAP, | |
662 | DMU_OT_NONE, 0, tx); | |
663 | dsphys->ds_creation_time = gethrestime_sec(); | |
b128c09f | 664 | dsphys->ds_creation_txg = tx->tx_txg == TXG_INITIAL ? 1 : tx->tx_txg; |
34dc7c2f | 665 | |
428870ff BB |
666 | if (origin == NULL) { |
667 | dsphys->ds_deadlist_obj = dsl_deadlist_alloc(mos, tx); | |
668 | } else { | |
13fe0198 | 669 | dsl_dataset_t *ohds; /* head of the origin snapshot */ |
428870ff | 670 | |
34dc7c2f BB |
671 | dsphys->ds_prev_snap_obj = origin->ds_object; |
672 | dsphys->ds_prev_snap_txg = | |
673 | origin->ds_phys->ds_creation_txg; | |
9ae529ec CS |
674 | dsphys->ds_referenced_bytes = |
675 | origin->ds_phys->ds_referenced_bytes; | |
34dc7c2f BB |
676 | dsphys->ds_compressed_bytes = |
677 | origin->ds_phys->ds_compressed_bytes; | |
678 | dsphys->ds_uncompressed_bytes = | |
679 | origin->ds_phys->ds_uncompressed_bytes; | |
680 | dsphys->ds_bp = origin->ds_phys->ds_bp; | |
681 | dsphys->ds_flags |= origin->ds_phys->ds_flags; | |
682 | ||
683 | dmu_buf_will_dirty(origin->ds_dbuf, tx); | |
684 | origin->ds_phys->ds_num_children++; | |
685 | ||
13fe0198 | 686 | VERIFY0(dsl_dataset_hold_obj(dp, |
428870ff BB |
687 | origin->ds_dir->dd_phys->dd_head_dataset_obj, FTAG, &ohds)); |
688 | dsphys->ds_deadlist_obj = dsl_deadlist_clone(&ohds->ds_deadlist, | |
689 | dsphys->ds_prev_snap_txg, dsphys->ds_prev_snap_obj, tx); | |
690 | dsl_dataset_rele(ohds, FTAG); | |
691 | ||
b128c09f BB |
692 | if (spa_version(dp->dp_spa) >= SPA_VERSION_NEXT_CLONES) { |
693 | if (origin->ds_phys->ds_next_clones_obj == 0) { | |
694 | origin->ds_phys->ds_next_clones_obj = | |
695 | zap_create(mos, | |
696 | DMU_OT_NEXT_CLONES, DMU_OT_NONE, 0, tx); | |
697 | } | |
13fe0198 MA |
698 | VERIFY0(zap_add_int(mos, |
699 | origin->ds_phys->ds_next_clones_obj, dsobj, tx)); | |
b128c09f BB |
700 | } |
701 | ||
34dc7c2f BB |
702 | dmu_buf_will_dirty(dd->dd_dbuf, tx); |
703 | dd->dd_phys->dd_origin_obj = origin->ds_object; | |
428870ff BB |
704 | if (spa_version(dp->dp_spa) >= SPA_VERSION_DIR_CLONES) { |
705 | if (origin->ds_dir->dd_phys->dd_clones == 0) { | |
706 | dmu_buf_will_dirty(origin->ds_dir->dd_dbuf, tx); | |
707 | origin->ds_dir->dd_phys->dd_clones = | |
708 | zap_create(mos, | |
709 | DMU_OT_DSL_CLONES, DMU_OT_NONE, 0, tx); | |
710 | } | |
13fe0198 | 711 | VERIFY0(zap_add_int(mos, |
428870ff BB |
712 | origin->ds_dir->dd_phys->dd_clones, dsobj, tx)); |
713 | } | |
34dc7c2f BB |
714 | } |
715 | ||
716 | if (spa_version(dp->dp_spa) >= SPA_VERSION_UNIQUE_ACCURATE) | |
717 | dsphys->ds_flags |= DS_FLAG_UNIQUE_ACCURATE; | |
718 | ||
719 | dmu_buf_rele(dbuf, FTAG); | |
720 | ||
721 | dmu_buf_will_dirty(dd->dd_dbuf, tx); | |
722 | dd->dd_phys->dd_head_dataset_obj = dsobj; | |
723 | ||
724 | return (dsobj); | |
725 | } | |
726 | ||
13fe0198 MA |
727 | static void |
728 | dsl_dataset_zero_zil(dsl_dataset_t *ds, dmu_tx_t *tx) | |
729 | { | |
730 | objset_t *os; | |
731 | ||
732 | VERIFY0(dmu_objset_from_ds(ds, &os)); | |
733 | bzero(&os->os_zil_header, sizeof (os->os_zil_header)); | |
734 | dsl_dataset_dirty(ds, tx); | |
735 | } | |
736 | ||
34dc7c2f BB |
737 | uint64_t |
738 | dsl_dataset_create_sync(dsl_dir_t *pdd, const char *lastname, | |
739 | dsl_dataset_t *origin, uint64_t flags, cred_t *cr, dmu_tx_t *tx) | |
740 | { | |
741 | dsl_pool_t *dp = pdd->dd_pool; | |
742 | uint64_t dsobj, ddobj; | |
743 | dsl_dir_t *dd; | |
744 | ||
13fe0198 | 745 | ASSERT(dmu_tx_is_syncing(tx)); |
34dc7c2f BB |
746 | ASSERT(lastname[0] != '@'); |
747 | ||
b128c09f | 748 | ddobj = dsl_dir_create_sync(dp, pdd, lastname, tx); |
13fe0198 | 749 | VERIFY0(dsl_dir_hold_obj(dp, ddobj, lastname, FTAG, &dd)); |
34dc7c2f | 750 | |
13fe0198 MA |
751 | dsobj = dsl_dataset_create_sync_dd(dd, origin, |
752 | flags & ~DS_CREATE_FLAG_NODIRTY, tx); | |
34dc7c2f BB |
753 | |
754 | dsl_deleg_set_create_perms(dd, tx, cr); | |
755 | ||
13fe0198 | 756 | dsl_dir_rele(dd, FTAG); |
34dc7c2f | 757 | |
572e2857 BB |
758 | /* |
759 | * If we are creating a clone, make sure we zero out any stale | |
760 | * data from the origin snapshots zil header. | |
761 | */ | |
13fe0198 | 762 | if (origin != NULL && !(flags & DS_CREATE_FLAG_NODIRTY)) { |
572e2857 | 763 | dsl_dataset_t *ds; |
572e2857 | 764 | |
13fe0198 MA |
765 | VERIFY0(dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds)); |
766 | dsl_dataset_zero_zil(ds, tx); | |
572e2857 BB |
767 | dsl_dataset_rele(ds, FTAG); |
768 | } | |
769 | ||
34dc7c2f BB |
770 | return (dsobj); |
771 | } | |
772 | ||
34dc7c2f | 773 | /* |
13fe0198 MA |
774 | * The unique space in the head dataset can be calculated by subtracting |
775 | * the space used in the most recent snapshot, that is still being used | |
776 | * in this file system, from the space currently in use. To figure out | |
777 | * the space in the most recent snapshot still in use, we need to take | |
778 | * the total space used in the snapshot and subtract out the space that | |
779 | * has been freed up since the snapshot was taken. | |
34dc7c2f | 780 | */ |
13fe0198 MA |
781 | void |
782 | dsl_dataset_recalc_head_uniq(dsl_dataset_t *ds) | |
34dc7c2f | 783 | { |
13fe0198 MA |
784 | uint64_t mrs_used; |
785 | uint64_t dlused, dlcomp, dluncomp; | |
34dc7c2f | 786 | |
13fe0198 | 787 | ASSERT(!dsl_dataset_is_snapshot(ds)); |
34dc7c2f | 788 | |
13fe0198 MA |
789 | if (ds->ds_phys->ds_prev_snap_obj != 0) |
790 | mrs_used = ds->ds_prev->ds_phys->ds_referenced_bytes; | |
791 | else | |
792 | mrs_used = 0; | |
45d1cae3 | 793 | |
13fe0198 | 794 | dsl_deadlist_space(&ds->ds_deadlist, &dlused, &dlcomp, &dluncomp); |
34dc7c2f | 795 | |
13fe0198 MA |
796 | ASSERT3U(dlused, <=, mrs_used); |
797 | ds->ds_phys->ds_unique_bytes = | |
798 | ds->ds_phys->ds_referenced_bytes - (mrs_used - dlused); | |
330d06f9 | 799 | |
13fe0198 MA |
800 | if (spa_version(ds->ds_dir->dd_pool->dp_spa) >= |
801 | SPA_VERSION_UNIQUE_ACCURATE) | |
802 | ds->ds_phys->ds_flags |= DS_FLAG_UNIQUE_ACCURATE; | |
34dc7c2f BB |
803 | } |
804 | ||
13fe0198 MA |
805 | void |
806 | dsl_dataset_remove_from_next_clones(dsl_dataset_t *ds, uint64_t obj, | |
807 | dmu_tx_t *tx) | |
45d1cae3 | 808 | { |
13fe0198 MA |
809 | objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset; |
810 | int err; | |
811 | ASSERTV(uint64_t count); | |
812 | ||
813 | ASSERT(ds->ds_phys->ds_num_children >= 2); | |
814 | err = zap_remove_int(mos, ds->ds_phys->ds_next_clones_obj, obj, tx); | |
815 | /* | |
816 | * The err should not be ENOENT, but a bug in a previous version | |
817 | * of the code could cause upgrade_clones_cb() to not set | |
818 | * ds_next_snap_obj when it should, leading to a missing entry. | |
819 | * If we knew that the pool was created after | |
820 | * SPA_VERSION_NEXT_CLONES, we could assert that it isn't | |
821 | * ENOENT. However, at least we can check that we don't have | |
822 | * too many entries in the next_clones_obj even after failing to | |
823 | * remove this one. | |
824 | */ | |
825 | if (err != ENOENT) | |
826 | VERIFY0(err); | |
827 | ASSERT0(zap_count(mos, ds->ds_phys->ds_next_clones_obj, | |
828 | &count)); | |
829 | ASSERT3U(count, <=, ds->ds_phys->ds_num_children - 2); | |
830 | } | |
45d1cae3 | 831 | |
45d1cae3 | 832 | |
13fe0198 MA |
833 | blkptr_t * |
834 | dsl_dataset_get_blkptr(dsl_dataset_t *ds) | |
835 | { | |
836 | return (&ds->ds_phys->ds_bp); | |
45d1cae3 BB |
837 | } |
838 | ||
13fe0198 MA |
839 | void |
840 | dsl_dataset_set_blkptr(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx) | |
45d1cae3 | 841 | { |
13fe0198 MA |
842 | ASSERT(dmu_tx_is_syncing(tx)); |
843 | /* If it's the meta-objset, set dp_meta_rootbp */ | |
844 | if (ds == NULL) { | |
845 | tx->tx_pool->dp_meta_rootbp = *bp; | |
846 | } else { | |
847 | dmu_buf_will_dirty(ds->ds_dbuf, tx); | |
848 | ds->ds_phys->ds_bp = *bp; | |
45d1cae3 | 849 | } |
13fe0198 | 850 | } |
45d1cae3 | 851 | |
13fe0198 MA |
852 | spa_t * |
853 | dsl_dataset_get_spa(dsl_dataset_t *ds) | |
854 | { | |
855 | return (ds->ds_dir->dd_pool->dp_spa); | |
45d1cae3 BB |
856 | } |
857 | ||
13fe0198 MA |
858 | void |
859 | dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx) | |
34dc7c2f | 860 | { |
13fe0198 | 861 | dsl_pool_t *dp; |
45d1cae3 | 862 | |
13fe0198 MA |
863 | if (ds == NULL) /* this is the meta-objset */ |
864 | return; | |
34dc7c2f | 865 | |
428870ff | 866 | ASSERT(ds->ds_objset != NULL); |
34dc7c2f BB |
867 | |
868 | if (ds->ds_phys->ds_next_snap_obj != 0) | |
869 | panic("dirtying snapshot!"); | |
870 | ||
871 | dp = ds->ds_dir->dd_pool; | |
872 | ||
13fe0198 | 873 | if (txg_list_add(&dp->dp_dirty_datasets, ds, tx->tx_txg)) { |
34dc7c2f BB |
874 | /* up the hold count until we can be written out */ |
875 | dmu_buf_add_ref(ds->ds_dbuf, ds); | |
876 | } | |
877 | } | |
878 | ||
04434775 MA |
879 | boolean_t |
880 | dsl_dataset_is_dirty(dsl_dataset_t *ds) | |
881 | { | |
882 | int t; | |
883 | ||
884 | for (t = 0; t < TXG_SIZE; t++) { | |
885 | if (txg_list_member(&ds->ds_dir->dd_pool->dp_dirty_datasets, | |
886 | ds, t)) | |
887 | return (B_TRUE); | |
888 | } | |
889 | return (B_FALSE); | |
890 | } | |
891 | ||
34dc7c2f | 892 | static int |
13fe0198 | 893 | dsl_dataset_snapshot_reserve_space(dsl_dataset_t *ds, dmu_tx_t *tx) |
34dc7c2f | 894 | { |
13fe0198 | 895 | uint64_t asize; |
34dc7c2f | 896 | |
13fe0198 | 897 | if (!dmu_tx_is_syncing(tx)) |
b128c09f BB |
898 | return (0); |
899 | ||
34dc7c2f | 900 | /* |
13fe0198 MA |
901 | * If there's an fs-only reservation, any blocks that might become |
902 | * owned by the snapshot dataset must be accommodated by space | |
903 | * outside of the reservation. | |
34dc7c2f | 904 | */ |
13fe0198 MA |
905 | ASSERT(ds->ds_reserved == 0 || DS_UNIQUE_IS_ACCURATE(ds)); |
906 | asize = MIN(ds->ds_phys->ds_unique_bytes, ds->ds_reserved); | |
907 | if (asize > dsl_dir_space_available(ds->ds_dir, NULL, 0, TRUE)) | |
2e528b49 | 908 | return (SET_ERROR(ENOSPC)); |
34dc7c2f BB |
909 | |
910 | /* | |
13fe0198 MA |
911 | * Propagate any reserved space for this snapshot to other |
912 | * snapshot checks in this sync group. | |
34dc7c2f | 913 | */ |
13fe0198 MA |
914 | if (asize > 0) |
915 | dsl_dir_willuse_space(ds->ds_dir, asize, tx); | |
34dc7c2f BB |
916 | |
917 | return (0); | |
918 | } | |
919 | ||
13fe0198 MA |
920 | typedef struct dsl_dataset_snapshot_arg { |
921 | nvlist_t *ddsa_snaps; | |
922 | nvlist_t *ddsa_props; | |
923 | nvlist_t *ddsa_errors; | |
924 | } dsl_dataset_snapshot_arg_t; | |
45d1cae3 | 925 | |
34dc7c2f | 926 | int |
13fe0198 | 927 | dsl_dataset_snapshot_check_impl(dsl_dataset_t *ds, const char *snapname, |
96c2e961 | 928 | dmu_tx_t *tx, boolean_t recv) |
34dc7c2f | 929 | { |
13fe0198 MA |
930 | int error; |
931 | uint64_t value; | |
34dc7c2f | 932 | |
13fe0198 | 933 | ds->ds_trysnap_txg = tx->tx_txg; |
b128c09f | 934 | |
13fe0198 | 935 | if (!dmu_tx_is_syncing(tx)) |
45d1cae3 | 936 | return (0); |
34dc7c2f BB |
937 | |
938 | /* | |
13fe0198 MA |
939 | * We don't allow multiple snapshots of the same txg. If there |
940 | * is already one, try again. | |
34dc7c2f | 941 | */ |
13fe0198 | 942 | if (ds->ds_phys->ds_prev_snap_txg >= tx->tx_txg) |
2e528b49 | 943 | return (SET_ERROR(EAGAIN)); |
34dc7c2f BB |
944 | |
945 | /* | |
13fe0198 | 946 | * Check for conflicting snapshot name. |
34dc7c2f | 947 | */ |
13fe0198 MA |
948 | error = dsl_dataset_snap_lookup(ds, snapname, &value); |
949 | if (error == 0) | |
2e528b49 | 950 | return (SET_ERROR(EEXIST)); |
13fe0198 MA |
951 | if (error != ENOENT) |
952 | return (error); | |
45d1cae3 | 953 | |
96c2e961 KW |
954 | /* |
955 | * We don't allow taking snapshots of inconsistent datasets, such as | |
956 | * those into which we are currently receiving. However, if we are | |
957 | * creating this snapshot as part of a receive, this check will be | |
958 | * executed atomically with respect to the completion of the receive | |
959 | * itself but prior to the clearing of DS_FLAG_INCONSISTENT; in this | |
960 | * case we ignore this, knowing it will be fixed up for us shortly in | |
961 | * dmu_recv_end_sync(). | |
962 | */ | |
963 | if (!recv && DS_IS_INCONSISTENT(ds)) | |
964 | return (SET_ERROR(EBUSY)); | |
965 | ||
13fe0198 MA |
966 | error = dsl_dataset_snapshot_reserve_space(ds, tx); |
967 | if (error != 0) | |
968 | return (error); | |
45d1cae3 | 969 | |
34dc7c2f BB |
970 | return (0); |
971 | } | |
972 | ||
13fe0198 MA |
973 | static int |
974 | dsl_dataset_snapshot_check(void *arg, dmu_tx_t *tx) | |
b128c09f | 975 | { |
13fe0198 MA |
976 | dsl_dataset_snapshot_arg_t *ddsa = arg; |
977 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
978 | nvpair_t *pair; | |
979 | int rv = 0; | |
b128c09f | 980 | |
13fe0198 MA |
981 | for (pair = nvlist_next_nvpair(ddsa->ddsa_snaps, NULL); |
982 | pair != NULL; pair = nvlist_next_nvpair(ddsa->ddsa_snaps, pair)) { | |
983 | int error = 0; | |
984 | dsl_dataset_t *ds; | |
985 | char *name, *atp; | |
986 | char dsname[MAXNAMELEN]; | |
987 | ||
988 | name = nvpair_name(pair); | |
989 | if (strlen(name) >= MAXNAMELEN) | |
2e528b49 | 990 | error = SET_ERROR(ENAMETOOLONG); |
13fe0198 MA |
991 | if (error == 0) { |
992 | atp = strchr(name, '@'); | |
993 | if (atp == NULL) | |
2e528b49 | 994 | error = SET_ERROR(EINVAL); |
13fe0198 MA |
995 | if (error == 0) |
996 | (void) strlcpy(dsname, name, atp - name + 1); | |
997 | } | |
998 | if (error == 0) | |
999 | error = dsl_dataset_hold(dp, dsname, FTAG, &ds); | |
1000 | if (error == 0) { | |
1001 | error = dsl_dataset_snapshot_check_impl(ds, | |
96c2e961 | 1002 | atp + 1, tx, B_FALSE); |
13fe0198 MA |
1003 | dsl_dataset_rele(ds, FTAG); |
1004 | } | |
b128c09f | 1005 | |
13fe0198 MA |
1006 | if (error != 0) { |
1007 | if (ddsa->ddsa_errors != NULL) { | |
1008 | fnvlist_add_int32(ddsa->ddsa_errors, | |
1009 | name, error); | |
1010 | } | |
1011 | rv = error; | |
1012 | } | |
1013 | } | |
1014 | return (rv); | |
b128c09f BB |
1015 | } |
1016 | ||
13fe0198 MA |
1017 | void |
1018 | dsl_dataset_snapshot_sync_impl(dsl_dataset_t *ds, const char *snapname, | |
1019 | dmu_tx_t *tx) | |
428870ff | 1020 | { |
13fe0198 MA |
1021 | dsl_pool_t *dp = ds->ds_dir->dd_pool; |
1022 | dmu_buf_t *dbuf; | |
1023 | dsl_dataset_phys_t *dsphys; | |
1024 | uint64_t dsobj, crtxg; | |
1025 | objset_t *mos = dp->dp_meta_objset; | |
1026 | ASSERTV(static zil_header_t zero_zil); | |
1027 | ASSERTV(objset_t *os); | |
1028 | ||
1029 | ASSERT(RRW_WRITE_HELD(&dp->dp_config_rwlock)); | |
428870ff | 1030 | |
428870ff | 1031 | /* |
13fe0198 MA |
1032 | * If we are on an old pool, the zil must not be active, in which |
1033 | * case it will be zeroed. Usually zil_suspend() accomplishes this. | |
428870ff | 1034 | */ |
13fe0198 MA |
1035 | ASSERT(spa_version(dmu_tx_pool(tx)->dp_spa) >= SPA_VERSION_FAST_SNAP || |
1036 | dmu_objset_from_ds(ds, &os) != 0 || | |
1037 | bcmp(&os->os_phys->os_zil_header, &zero_zil, | |
1038 | sizeof (zero_zil)) == 0); | |
428870ff | 1039 | |
428870ff BB |
1040 | |
1041 | /* | |
13fe0198 | 1042 | * The origin's ds_creation_txg has to be < TXG_INITIAL |
b128c09f BB |
1043 | */ |
1044 | if (strcmp(snapname, ORIGIN_DIR_NAME) == 0) | |
1045 | crtxg = 1; | |
1046 | else | |
1047 | crtxg = tx->tx_txg; | |
1048 | ||
34dc7c2f BB |
1049 | dsobj = dmu_object_alloc(mos, DMU_OT_DSL_DATASET, 0, |
1050 | DMU_OT_DSL_DATASET, sizeof (dsl_dataset_phys_t), tx); | |
13fe0198 | 1051 | VERIFY0(dmu_bonus_hold(mos, dsobj, FTAG, &dbuf)); |
34dc7c2f BB |
1052 | dmu_buf_will_dirty(dbuf, tx); |
1053 | dsphys = dbuf->db_data; | |
b128c09f | 1054 | bzero(dsphys, sizeof (dsl_dataset_phys_t)); |
34dc7c2f BB |
1055 | dsphys->ds_dir_obj = ds->ds_dir->dd_object; |
1056 | dsphys->ds_fsid_guid = unique_create(); | |
1057 | (void) random_get_pseudo_bytes((void*)&dsphys->ds_guid, | |
1058 | sizeof (dsphys->ds_guid)); | |
1059 | dsphys->ds_prev_snap_obj = ds->ds_phys->ds_prev_snap_obj; | |
1060 | dsphys->ds_prev_snap_txg = ds->ds_phys->ds_prev_snap_txg; | |
1061 | dsphys->ds_next_snap_obj = ds->ds_object; | |
1062 | dsphys->ds_num_children = 1; | |
1063 | dsphys->ds_creation_time = gethrestime_sec(); | |
b128c09f | 1064 | dsphys->ds_creation_txg = crtxg; |
34dc7c2f | 1065 | dsphys->ds_deadlist_obj = ds->ds_phys->ds_deadlist_obj; |
9ae529ec | 1066 | dsphys->ds_referenced_bytes = ds->ds_phys->ds_referenced_bytes; |
34dc7c2f BB |
1067 | dsphys->ds_compressed_bytes = ds->ds_phys->ds_compressed_bytes; |
1068 | dsphys->ds_uncompressed_bytes = ds->ds_phys->ds_uncompressed_bytes; | |
1069 | dsphys->ds_flags = ds->ds_phys->ds_flags; | |
1070 | dsphys->ds_bp = ds->ds_phys->ds_bp; | |
1071 | dmu_buf_rele(dbuf, FTAG); | |
1072 | ||
1073 | ASSERT3U(ds->ds_prev != 0, ==, ds->ds_phys->ds_prev_snap_obj != 0); | |
1074 | if (ds->ds_prev) { | |
b128c09f BB |
1075 | uint64_t next_clones_obj = |
1076 | ds->ds_prev->ds_phys->ds_next_clones_obj; | |
34dc7c2f BB |
1077 | ASSERT(ds->ds_prev->ds_phys->ds_next_snap_obj == |
1078 | ds->ds_object || | |
1079 | ds->ds_prev->ds_phys->ds_num_children > 1); | |
1080 | if (ds->ds_prev->ds_phys->ds_next_snap_obj == ds->ds_object) { | |
1081 | dmu_buf_will_dirty(ds->ds_prev->ds_dbuf, tx); | |
1082 | ASSERT3U(ds->ds_phys->ds_prev_snap_txg, ==, | |
1083 | ds->ds_prev->ds_phys->ds_creation_txg); | |
1084 | ds->ds_prev->ds_phys->ds_next_snap_obj = dsobj; | |
b128c09f | 1085 | } else if (next_clones_obj != 0) { |
13fe0198 | 1086 | dsl_dataset_remove_from_next_clones(ds->ds_prev, |
428870ff | 1087 | dsphys->ds_next_snap_obj, tx); |
13fe0198 | 1088 | VERIFY0(zap_add_int(mos, |
b128c09f | 1089 | next_clones_obj, dsobj, tx)); |
34dc7c2f BB |
1090 | } |
1091 | } | |
1092 | ||
1093 | /* | |
1094 | * If we have a reference-reservation on this dataset, we will | |
1095 | * need to increase the amount of refreservation being charged | |
1096 | * since our unique space is going to zero. | |
1097 | */ | |
1098 | if (ds->ds_reserved) { | |
428870ff BB |
1099 | int64_t delta; |
1100 | ASSERT(DS_UNIQUE_IS_ACCURATE(ds)); | |
1101 | delta = MIN(ds->ds_phys->ds_unique_bytes, ds->ds_reserved); | |
b128c09f | 1102 | dsl_dir_diduse_space(ds->ds_dir, DD_USED_REFRSRV, |
428870ff | 1103 | delta, 0, 0, tx); |
34dc7c2f BB |
1104 | } |
1105 | ||
34dc7c2f | 1106 | dmu_buf_will_dirty(ds->ds_dbuf, tx); |
428870ff BB |
1107 | ds->ds_phys->ds_deadlist_obj = dsl_deadlist_clone(&ds->ds_deadlist, |
1108 | UINT64_MAX, ds->ds_phys->ds_prev_snap_obj, tx); | |
1109 | dsl_deadlist_close(&ds->ds_deadlist); | |
1110 | dsl_deadlist_open(&ds->ds_deadlist, mos, ds->ds_phys->ds_deadlist_obj); | |
1111 | dsl_deadlist_add_key(&ds->ds_deadlist, | |
1112 | ds->ds_phys->ds_prev_snap_txg, tx); | |
1113 | ||
34dc7c2f BB |
1114 | ASSERT3U(ds->ds_phys->ds_prev_snap_txg, <, tx->tx_txg); |
1115 | ds->ds_phys->ds_prev_snap_obj = dsobj; | |
b128c09f | 1116 | ds->ds_phys->ds_prev_snap_txg = crtxg; |
34dc7c2f BB |
1117 | ds->ds_phys->ds_unique_bytes = 0; |
1118 | if (spa_version(dp->dp_spa) >= SPA_VERSION_UNIQUE_ACCURATE) | |
1119 | ds->ds_phys->ds_flags |= DS_FLAG_UNIQUE_ACCURATE; | |
34dc7c2f | 1120 | |
13fe0198 MA |
1121 | VERIFY0(zap_add(mos, ds->ds_phys->ds_snapnames_zapobj, |
1122 | snapname, 8, 1, &dsobj, tx)); | |
34dc7c2f BB |
1123 | |
1124 | if (ds->ds_prev) | |
13fe0198 MA |
1125 | dsl_dataset_rele(ds->ds_prev, ds); |
1126 | VERIFY0(dsl_dataset_hold_obj(dp, | |
b128c09f BB |
1127 | ds->ds_phys->ds_prev_snap_obj, ds, &ds->ds_prev)); |
1128 | ||
428870ff BB |
1129 | dsl_scan_ds_snapshotted(ds, tx); |
1130 | ||
1131 | dsl_dir_snap_cmtime_update(ds->ds_dir); | |
34dc7c2f | 1132 | |
6f1ffb06 | 1133 | spa_history_log_internal_ds(ds->ds_prev, "snapshot", tx, ""); |
34dc7c2f BB |
1134 | } |
1135 | ||
13fe0198 MA |
1136 | static void |
1137 | dsl_dataset_snapshot_sync(void *arg, dmu_tx_t *tx) | |
34dc7c2f | 1138 | { |
13fe0198 MA |
1139 | dsl_dataset_snapshot_arg_t *ddsa = arg; |
1140 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
1141 | nvpair_t *pair; | |
34dc7c2f | 1142 | |
13fe0198 MA |
1143 | for (pair = nvlist_next_nvpair(ddsa->ddsa_snaps, NULL); |
1144 | pair != NULL; pair = nvlist_next_nvpair(ddsa->ddsa_snaps, pair)) { | |
1145 | dsl_dataset_t *ds; | |
1146 | char *name, *atp; | |
1147 | char dsname[MAXNAMELEN]; | |
1148 | ||
1149 | name = nvpair_name(pair); | |
1150 | atp = strchr(name, '@'); | |
1151 | (void) strlcpy(dsname, name, atp - name + 1); | |
1152 | VERIFY0(dsl_dataset_hold(dp, dsname, FTAG, &ds)); | |
1153 | ||
1154 | dsl_dataset_snapshot_sync_impl(ds, atp + 1, tx); | |
1155 | if (ddsa->ddsa_props != NULL) { | |
1156 | dsl_props_set_sync_impl(ds->ds_prev, | |
1157 | ZPROP_SRC_LOCAL, ddsa->ddsa_props, tx); | |
1158 | } | |
1159 | dsl_dataset_rele(ds, FTAG); | |
1160 | } | |
34dc7c2f BB |
1161 | } |
1162 | ||
13fe0198 MA |
1163 | /* |
1164 | * The snapshots must all be in the same pool. | |
1165 | * All-or-nothing: if there are any failures, nothing will be modified. | |
1166 | */ | |
1167 | int | |
1168 | dsl_dataset_snapshot(nvlist_t *snaps, nvlist_t *props, nvlist_t *errors) | |
330d06f9 | 1169 | { |
13fe0198 MA |
1170 | dsl_dataset_snapshot_arg_t ddsa; |
1171 | nvpair_t *pair; | |
1172 | boolean_t needsuspend; | |
1173 | int error; | |
1174 | spa_t *spa; | |
1175 | char *firstname; | |
1176 | nvlist_t *suspended = NULL; | |
330d06f9 | 1177 | |
13fe0198 MA |
1178 | pair = nvlist_next_nvpair(snaps, NULL); |
1179 | if (pair == NULL) | |
1180 | return (0); | |
1181 | firstname = nvpair_name(pair); | |
1182 | ||
1183 | error = spa_open(firstname, &spa, FTAG); | |
1184 | if (error != 0) | |
1185 | return (error); | |
1186 | needsuspend = (spa_version(spa) < SPA_VERSION_FAST_SNAP); | |
1187 | spa_close(spa, FTAG); | |
1188 | ||
1189 | if (needsuspend) { | |
1190 | suspended = fnvlist_alloc(); | |
1191 | for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL; | |
1192 | pair = nvlist_next_nvpair(snaps, pair)) { | |
1193 | char fsname[MAXNAMELEN]; | |
1194 | char *snapname = nvpair_name(pair); | |
1195 | char *atp; | |
1196 | void *cookie; | |
1197 | ||
1198 | atp = strchr(snapname, '@'); | |
1199 | if (atp == NULL) { | |
2e528b49 | 1200 | error = SET_ERROR(EINVAL); |
13fe0198 MA |
1201 | break; |
1202 | } | |
1203 | (void) strlcpy(fsname, snapname, atp - snapname + 1); | |
1204 | ||
1205 | error = zil_suspend(fsname, &cookie); | |
1206 | if (error != 0) | |
1207 | break; | |
1208 | fnvlist_add_uint64(suspended, fsname, | |
1209 | (uintptr_t)cookie); | |
1210 | } | |
1211 | } | |
1212 | ||
1213 | ddsa.ddsa_snaps = snaps; | |
1214 | ddsa.ddsa_props = props; | |
1215 | ddsa.ddsa_errors = errors; | |
1216 | ||
1217 | if (error == 0) { | |
1218 | error = dsl_sync_task(firstname, dsl_dataset_snapshot_check, | |
1219 | dsl_dataset_snapshot_sync, &ddsa, | |
1220 | fnvlist_num_pairs(snaps) * 3); | |
1221 | } | |
1222 | ||
1223 | if (suspended != NULL) { | |
1224 | for (pair = nvlist_next_nvpair(suspended, NULL); pair != NULL; | |
1225 | pair = nvlist_next_nvpair(suspended, pair)) { | |
1226 | zil_resume((void *)(uintptr_t) | |
1227 | fnvpair_value_uint64(pair)); | |
1228 | } | |
1229 | fnvlist_free(suspended); | |
1230 | } | |
1231 | ||
ba6a2402 BB |
1232 | #ifdef _KERNEL |
1233 | if (error == 0) { | |
1234 | for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL; | |
d1d7e268 | 1235 | pair = nvlist_next_nvpair(snaps, pair)) { |
ba6a2402 BB |
1236 | char *snapname = nvpair_name(pair); |
1237 | zvol_create_minors(snapname); | |
1238 | } | |
1239 | } | |
1240 | #endif | |
1241 | ||
13fe0198 MA |
1242 | return (error); |
1243 | } | |
1244 | ||
1245 | typedef struct dsl_dataset_snapshot_tmp_arg { | |
1246 | const char *ddsta_fsname; | |
1247 | const char *ddsta_snapname; | |
1248 | minor_t ddsta_cleanup_minor; | |
1249 | const char *ddsta_htag; | |
1250 | } dsl_dataset_snapshot_tmp_arg_t; | |
1251 | ||
1252 | static int | |
1253 | dsl_dataset_snapshot_tmp_check(void *arg, dmu_tx_t *tx) | |
1254 | { | |
1255 | dsl_dataset_snapshot_tmp_arg_t *ddsta = arg; | |
1256 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
1257 | dsl_dataset_t *ds; | |
1258 | int error; | |
1259 | ||
1260 | error = dsl_dataset_hold(dp, ddsta->ddsta_fsname, FTAG, &ds); | |
1261 | if (error != 0) | |
1262 | return (error); | |
1263 | ||
96c2e961 KW |
1264 | error = dsl_dataset_snapshot_check_impl(ds, ddsta->ddsta_snapname, |
1265 | tx, B_FALSE); | |
13fe0198 MA |
1266 | if (error != 0) { |
1267 | dsl_dataset_rele(ds, FTAG); | |
1268 | return (error); | |
1269 | } | |
1270 | ||
1271 | if (spa_version(dp->dp_spa) < SPA_VERSION_USERREFS) { | |
1272 | dsl_dataset_rele(ds, FTAG); | |
2e528b49 | 1273 | return (SET_ERROR(ENOTSUP)); |
13fe0198 MA |
1274 | } |
1275 | error = dsl_dataset_user_hold_check_one(NULL, ddsta->ddsta_htag, | |
1276 | B_TRUE, tx); | |
1277 | if (error != 0) { | |
1278 | dsl_dataset_rele(ds, FTAG); | |
1279 | return (error); | |
1280 | } | |
1281 | ||
1282 | dsl_dataset_rele(ds, FTAG); | |
1283 | return (0); | |
1284 | } | |
1285 | ||
1286 | static void | |
1287 | dsl_dataset_snapshot_tmp_sync(void *arg, dmu_tx_t *tx) | |
1288 | { | |
1289 | dsl_dataset_snapshot_tmp_arg_t *ddsta = arg; | |
1290 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
1291 | dsl_dataset_t *ds; | |
1292 | ||
1293 | VERIFY0(dsl_dataset_hold(dp, ddsta->ddsta_fsname, FTAG, &ds)); | |
1294 | ||
1295 | dsl_dataset_snapshot_sync_impl(ds, ddsta->ddsta_snapname, tx); | |
1296 | dsl_dataset_user_hold_sync_one(ds->ds_prev, ddsta->ddsta_htag, | |
1297 | ddsta->ddsta_cleanup_minor, gethrestime_sec(), tx); | |
1298 | dsl_destroy_snapshot_sync_impl(ds->ds_prev, B_TRUE, tx); | |
1299 | ||
1300 | dsl_dataset_rele(ds, FTAG); | |
1301 | } | |
1302 | ||
1303 | int | |
1304 | dsl_dataset_snapshot_tmp(const char *fsname, const char *snapname, | |
1305 | minor_t cleanup_minor, const char *htag) | |
1306 | { | |
1307 | dsl_dataset_snapshot_tmp_arg_t ddsta; | |
1308 | int error; | |
1309 | spa_t *spa; | |
1310 | boolean_t needsuspend; | |
1311 | void *cookie; | |
1312 | ||
1313 | ddsta.ddsta_fsname = fsname; | |
1314 | ddsta.ddsta_snapname = snapname; | |
1315 | ddsta.ddsta_cleanup_minor = cleanup_minor; | |
1316 | ddsta.ddsta_htag = htag; | |
1317 | ||
1318 | error = spa_open(fsname, &spa, FTAG); | |
1319 | if (error != 0) | |
1320 | return (error); | |
1321 | needsuspend = (spa_version(spa) < SPA_VERSION_FAST_SNAP); | |
1322 | spa_close(spa, FTAG); | |
1323 | ||
1324 | if (needsuspend) { | |
1325 | error = zil_suspend(fsname, &cookie); | |
1326 | if (error != 0) | |
1327 | return (error); | |
1328 | } | |
1329 | ||
1330 | error = dsl_sync_task(fsname, dsl_dataset_snapshot_tmp_check, | |
1331 | dsl_dataset_snapshot_tmp_sync, &ddsta, 3); | |
1332 | ||
1333 | if (needsuspend) | |
1334 | zil_resume(cookie); | |
1335 | return (error); | |
1336 | } | |
1337 | ||
1338 | ||
1339 | void | |
1340 | dsl_dataset_sync(dsl_dataset_t *ds, zio_t *zio, dmu_tx_t *tx) | |
1341 | { | |
1342 | ASSERT(dmu_tx_is_syncing(tx)); | |
1343 | ASSERT(ds->ds_objset != NULL); | |
1344 | ASSERT(ds->ds_phys->ds_next_snap_obj == 0); | |
1345 | ||
1346 | /* | |
1347 | * in case we had to change ds_fsid_guid when we opened it, | |
1348 | * sync it out now. | |
1349 | */ | |
1350 | dmu_buf_will_dirty(ds->ds_dbuf, tx); | |
1351 | ds->ds_phys->ds_fsid_guid = ds->ds_fsid_guid; | |
1352 | ||
1353 | dmu_objset_sync(ds->ds_objset, zio, tx); | |
1354 | } | |
1355 | ||
1356 | static void | |
1357 | get_clones_stat(dsl_dataset_t *ds, nvlist_t *nv) | |
1358 | { | |
1359 | uint64_t count = 0; | |
1360 | objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset; | |
1361 | zap_cursor_t zc; | |
1362 | zap_attribute_t za; | |
1363 | nvlist_t *propval = fnvlist_alloc(); | |
1364 | nvlist_t *val = fnvlist_alloc(); | |
1365 | ||
1366 | ASSERT(dsl_pool_config_held(ds->ds_dir->dd_pool)); | |
330d06f9 MA |
1367 | |
1368 | /* | |
13fe0198 | 1369 | * There may be missing entries in ds_next_clones_obj |
330d06f9 MA |
1370 | * due to a bug in a previous version of the code. |
1371 | * Only trust it if it has the right number of entries. | |
1372 | */ | |
1373 | if (ds->ds_phys->ds_next_clones_obj != 0) { | |
13fe0198 | 1374 | ASSERT0(zap_count(mos, ds->ds_phys->ds_next_clones_obj, |
330d06f9 MA |
1375 | &count)); |
1376 | } | |
13fe0198 | 1377 | if (count != ds->ds_phys->ds_num_children - 1) |
330d06f9 | 1378 | goto fail; |
330d06f9 MA |
1379 | for (zap_cursor_init(&zc, mos, ds->ds_phys->ds_next_clones_obj); |
1380 | zap_cursor_retrieve(&zc, &za) == 0; | |
1381 | zap_cursor_advance(&zc)) { | |
1382 | dsl_dataset_t *clone; | |
1383 | char buf[ZFS_MAXNAMELEN]; | |
13fe0198 MA |
1384 | VERIFY0(dsl_dataset_hold_obj(ds->ds_dir->dd_pool, |
1385 | za.za_first_integer, FTAG, &clone)); | |
330d06f9 | 1386 | dsl_dir_name(clone->ds_dir, buf); |
13fe0198 | 1387 | fnvlist_add_boolean(val, buf); |
330d06f9 MA |
1388 | dsl_dataset_rele(clone, FTAG); |
1389 | } | |
1390 | zap_cursor_fini(&zc); | |
13fe0198 MA |
1391 | fnvlist_add_nvlist(propval, ZPROP_VALUE, val); |
1392 | fnvlist_add_nvlist(nv, zfs_prop_to_name(ZFS_PROP_CLONES), propval); | |
330d06f9 MA |
1393 | fail: |
1394 | nvlist_free(val); | |
1395 | nvlist_free(propval); | |
330d06f9 MA |
1396 | } |
1397 | ||
34dc7c2f BB |
1398 | void |
1399 | dsl_dataset_stats(dsl_dataset_t *ds, nvlist_t *nv) | |
1400 | { | |
f5fc4aca | 1401 | uint64_t refd, avail, uobjs, aobjs, ratio; |
13fe0198 MA |
1402 | ASSERTV(dsl_pool_t *dp = ds->ds_dir->dd_pool); |
1403 | ||
1404 | ASSERT(dsl_pool_config_held(dp)); | |
34dc7c2f | 1405 | |
6f1ffb06 MA |
1406 | ratio = ds->ds_phys->ds_compressed_bytes == 0 ? 100 : |
1407 | (ds->ds_phys->ds_uncompressed_bytes * 100 / | |
1408 | ds->ds_phys->ds_compressed_bytes); | |
1409 | ||
1410 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFRATIO, ratio); | |
24a64651 MA |
1411 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_LOGICALREFERENCED, |
1412 | ds->ds_phys->ds_uncompressed_bytes); | |
6f1ffb06 MA |
1413 | |
1414 | if (dsl_dataset_is_snapshot(ds)) { | |
1415 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_COMPRESSRATIO, ratio); | |
1416 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USED, | |
1417 | ds->ds_phys->ds_unique_bytes); | |
1418 | get_clones_stat(ds, nv); | |
1419 | } else { | |
1420 | dsl_dir_stats(ds->ds_dir, nv); | |
1421 | } | |
34dc7c2f BB |
1422 | |
1423 | dsl_dataset_space(ds, &refd, &avail, &uobjs, &aobjs); | |
1424 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_AVAILABLE, avail); | |
1425 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFERENCED, refd); | |
1426 | ||
1427 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_CREATION, | |
1428 | ds->ds_phys->ds_creation_time); | |
1429 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_CREATETXG, | |
1430 | ds->ds_phys->ds_creation_txg); | |
1431 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFQUOTA, | |
1432 | ds->ds_quota); | |
1433 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFRESERVATION, | |
1434 | ds->ds_reserved); | |
b128c09f BB |
1435 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_GUID, |
1436 | ds->ds_phys->ds_guid); | |
428870ff BB |
1437 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_UNIQUE, |
1438 | ds->ds_phys->ds_unique_bytes); | |
1439 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_OBJSETID, | |
1440 | ds->ds_object); | |
1441 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USERREFS, | |
1442 | ds->ds_userrefs); | |
45d1cae3 BB |
1443 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_DEFER_DESTROY, |
1444 | DS_IS_DEFER_DESTROY(ds) ? 1 : 0); | |
34dc7c2f | 1445 | |
330d06f9 MA |
1446 | if (ds->ds_phys->ds_prev_snap_obj != 0) { |
1447 | uint64_t written, comp, uncomp; | |
1448 | dsl_pool_t *dp = ds->ds_dir->dd_pool; | |
1449 | dsl_dataset_t *prev; | |
1450 | int err; | |
1451 | ||
330d06f9 MA |
1452 | err = dsl_dataset_hold_obj(dp, |
1453 | ds->ds_phys->ds_prev_snap_obj, FTAG, &prev); | |
330d06f9 MA |
1454 | if (err == 0) { |
1455 | err = dsl_dataset_space_written(prev, ds, &written, | |
1456 | &comp, &uncomp); | |
1457 | dsl_dataset_rele(prev, FTAG); | |
1458 | if (err == 0) { | |
1459 | dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_WRITTEN, | |
1460 | written); | |
1461 | } | |
1462 | } | |
1463 | } | |
1464 | ||
34dc7c2f BB |
1465 | } |
1466 | ||
1467 | void | |
1468 | dsl_dataset_fast_stat(dsl_dataset_t *ds, dmu_objset_stats_t *stat) | |
1469 | { | |
13fe0198 MA |
1470 | dsl_pool_t *dp = ds->ds_dir->dd_pool; |
1471 | ASSERT(dsl_pool_config_held(dp)); | |
1472 | ||
34dc7c2f BB |
1473 | stat->dds_creation_txg = ds->ds_phys->ds_creation_txg; |
1474 | stat->dds_inconsistent = ds->ds_phys->ds_flags & DS_FLAG_INCONSISTENT; | |
1475 | stat->dds_guid = ds->ds_phys->ds_guid; | |
6f1ffb06 MA |
1476 | stat->dds_origin[0] = '\0'; |
1477 | if (dsl_dataset_is_snapshot(ds)) { | |
34dc7c2f BB |
1478 | stat->dds_is_snapshot = B_TRUE; |
1479 | stat->dds_num_clones = ds->ds_phys->ds_num_children - 1; | |
fb5f0bc8 BB |
1480 | } else { |
1481 | stat->dds_is_snapshot = B_FALSE; | |
1482 | stat->dds_num_clones = 0; | |
34dc7c2f | 1483 | |
6f1ffb06 MA |
1484 | if (dsl_dir_is_clone(ds->ds_dir)) { |
1485 | dsl_dataset_t *ods; | |
34dc7c2f | 1486 | |
13fe0198 | 1487 | VERIFY0(dsl_dataset_hold_obj(dp, |
6f1ffb06 MA |
1488 | ds->ds_dir->dd_phys->dd_origin_obj, FTAG, &ods)); |
1489 | dsl_dataset_name(ods, stat->dds_origin); | |
13fe0198 | 1490 | dsl_dataset_rele(ods, FTAG); |
6f1ffb06 | 1491 | } |
34dc7c2f | 1492 | } |
34dc7c2f BB |
1493 | } |
1494 | ||
1495 | uint64_t | |
1496 | dsl_dataset_fsid_guid(dsl_dataset_t *ds) | |
1497 | { | |
1498 | return (ds->ds_fsid_guid); | |
1499 | } | |
1500 | ||
1501 | void | |
1502 | dsl_dataset_space(dsl_dataset_t *ds, | |
1503 | uint64_t *refdbytesp, uint64_t *availbytesp, | |
1504 | uint64_t *usedobjsp, uint64_t *availobjsp) | |
1505 | { | |
9ae529ec | 1506 | *refdbytesp = ds->ds_phys->ds_referenced_bytes; |
34dc7c2f BB |
1507 | *availbytesp = dsl_dir_space_available(ds->ds_dir, NULL, 0, TRUE); |
1508 | if (ds->ds_reserved > ds->ds_phys->ds_unique_bytes) | |
1509 | *availbytesp += ds->ds_reserved - ds->ds_phys->ds_unique_bytes; | |
1510 | if (ds->ds_quota != 0) { | |
1511 | /* | |
1512 | * Adjust available bytes according to refquota | |
1513 | */ | |
1514 | if (*refdbytesp < ds->ds_quota) | |
1515 | *availbytesp = MIN(*availbytesp, | |
1516 | ds->ds_quota - *refdbytesp); | |
1517 | else | |
1518 | *availbytesp = 0; | |
1519 | } | |
1520 | *usedobjsp = ds->ds_phys->ds_bp.blk_fill; | |
1521 | *availobjsp = DN_MAX_OBJECT - *usedobjsp; | |
1522 | } | |
1523 | ||
1524 | boolean_t | |
19580676 | 1525 | dsl_dataset_modified_since_snap(dsl_dataset_t *ds, dsl_dataset_t *snap) |
34dc7c2f | 1526 | { |
19580676 MA |
1527 | ASSERT(dsl_pool_config_held(ds->ds_dir->dd_pool)); |
1528 | if (snap == NULL) | |
34dc7c2f BB |
1529 | return (B_FALSE); |
1530 | if (ds->ds_phys->ds_bp.blk_birth > | |
19580676 MA |
1531 | snap->ds_phys->ds_creation_txg) { |
1532 | objset_t *os, *os_snap; | |
572e2857 BB |
1533 | /* |
1534 | * It may be that only the ZIL differs, because it was | |
1535 | * reset in the head. Don't count that as being | |
1536 | * modified. | |
1537 | */ | |
1538 | if (dmu_objset_from_ds(ds, &os) != 0) | |
1539 | return (B_TRUE); | |
19580676 | 1540 | if (dmu_objset_from_ds(snap, &os_snap) != 0) |
572e2857 BB |
1541 | return (B_TRUE); |
1542 | return (bcmp(&os->os_phys->os_meta_dnode, | |
19580676 | 1543 | &os_snap->os_phys->os_meta_dnode, |
572e2857 BB |
1544 | sizeof (os->os_phys->os_meta_dnode)) != 0); |
1545 | } | |
34dc7c2f BB |
1546 | return (B_FALSE); |
1547 | } | |
1548 | ||
13fe0198 MA |
1549 | typedef struct dsl_dataset_rename_snapshot_arg { |
1550 | const char *ddrsa_fsname; | |
1551 | const char *ddrsa_oldsnapname; | |
1552 | const char *ddrsa_newsnapname; | |
1553 | boolean_t ddrsa_recursive; | |
1554 | dmu_tx_t *ddrsa_tx; | |
1555 | } dsl_dataset_rename_snapshot_arg_t; | |
1556 | ||
34dc7c2f BB |
1557 | /* ARGSUSED */ |
1558 | static int | |
13fe0198 MA |
1559 | dsl_dataset_rename_snapshot_check_impl(dsl_pool_t *dp, |
1560 | dsl_dataset_t *hds, void *arg) | |
34dc7c2f | 1561 | { |
13fe0198 MA |
1562 | dsl_dataset_rename_snapshot_arg_t *ddrsa = arg; |
1563 | int error; | |
34dc7c2f | 1564 | uint64_t val; |
34dc7c2f | 1565 | |
13fe0198 MA |
1566 | error = dsl_dataset_snap_lookup(hds, ddrsa->ddrsa_oldsnapname, &val); |
1567 | if (error != 0) { | |
1568 | /* ignore nonexistent snapshots */ | |
1569 | return (error == ENOENT ? 0 : error); | |
1570 | } | |
34dc7c2f | 1571 | |
13fe0198 MA |
1572 | /* new name should not exist */ |
1573 | error = dsl_dataset_snap_lookup(hds, ddrsa->ddrsa_newsnapname, &val); | |
1574 | if (error == 0) | |
2e528b49 | 1575 | error = SET_ERROR(EEXIST); |
13fe0198 MA |
1576 | else if (error == ENOENT) |
1577 | error = 0; | |
34dc7c2f BB |
1578 | |
1579 | /* dataset name + 1 for the "@" + the new snapshot name must fit */ | |
13fe0198 MA |
1580 | if (dsl_dir_namelen(hds->ds_dir) + 1 + |
1581 | strlen(ddrsa->ddrsa_newsnapname) >= MAXNAMELEN) | |
2e528b49 | 1582 | error = SET_ERROR(ENAMETOOLONG); |
34dc7c2f | 1583 | |
13fe0198 | 1584 | return (error); |
34dc7c2f BB |
1585 | } |
1586 | ||
13fe0198 MA |
1587 | static int |
1588 | dsl_dataset_rename_snapshot_check(void *arg, dmu_tx_t *tx) | |
34dc7c2f | 1589 | { |
13fe0198 MA |
1590 | dsl_dataset_rename_snapshot_arg_t *ddrsa = arg; |
1591 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
34dc7c2f | 1592 | dsl_dataset_t *hds; |
13fe0198 | 1593 | int error; |
34dc7c2f | 1594 | |
13fe0198 MA |
1595 | error = dsl_dataset_hold(dp, ddrsa->ddrsa_fsname, FTAG, &hds); |
1596 | if (error != 0) | |
1597 | return (error); | |
34dc7c2f | 1598 | |
13fe0198 MA |
1599 | if (ddrsa->ddrsa_recursive) { |
1600 | error = dmu_objset_find_dp(dp, hds->ds_dir->dd_object, | |
1601 | dsl_dataset_rename_snapshot_check_impl, ddrsa, | |
1602 | DS_FIND_CHILDREN); | |
1603 | } else { | |
1604 | error = dsl_dataset_rename_snapshot_check_impl(dp, hds, ddrsa); | |
1605 | } | |
b128c09f | 1606 | dsl_dataset_rele(hds, FTAG); |
13fe0198 | 1607 | return (error); |
34dc7c2f BB |
1608 | } |
1609 | ||
34dc7c2f | 1610 | static int |
13fe0198 MA |
1611 | dsl_dataset_rename_snapshot_sync_impl(dsl_pool_t *dp, |
1612 | dsl_dataset_t *hds, void *arg) | |
34dc7c2f | 1613 | { |
ba6a2402 BB |
1614 | #ifdef _KERNEL |
1615 | char *oldname, *newname; | |
1616 | #endif | |
13fe0198 MA |
1617 | dsl_dataset_rename_snapshot_arg_t *ddrsa = arg; |
1618 | dsl_dataset_t *ds; | |
1619 | uint64_t val; | |
1620 | dmu_tx_t *tx = ddrsa->ddrsa_tx; | |
1621 | int error; | |
34dc7c2f | 1622 | |
13fe0198 MA |
1623 | error = dsl_dataset_snap_lookup(hds, ddrsa->ddrsa_oldsnapname, &val); |
1624 | ASSERT(error == 0 || error == ENOENT); | |
1625 | if (error == ENOENT) { | |
1626 | /* ignore nonexistent snapshots */ | |
1627 | return (0); | |
34dc7c2f BB |
1628 | } |
1629 | ||
13fe0198 MA |
1630 | VERIFY0(dsl_dataset_hold_obj(dp, val, FTAG, &ds)); |
1631 | ||
1632 | /* log before we change the name */ | |
1633 | spa_history_log_internal_ds(ds, "rename", tx, | |
1634 | "-> @%s", ddrsa->ddrsa_newsnapname); | |
34dc7c2f | 1635 | |
13fe0198 MA |
1636 | VERIFY0(dsl_dataset_snap_remove(hds, ddrsa->ddrsa_oldsnapname, tx)); |
1637 | mutex_enter(&ds->ds_lock); | |
1638 | (void) strcpy(ds->ds_snapname, ddrsa->ddrsa_newsnapname); | |
1639 | mutex_exit(&ds->ds_lock); | |
1640 | VERIFY0(zap_add(dp->dp_meta_objset, hds->ds_phys->ds_snapnames_zapobj, | |
1641 | ds->ds_snapname, 8, 1, &ds->ds_object, tx)); | |
34dc7c2f | 1642 | |
ba6a2402 BB |
1643 | #ifdef _KERNEL |
1644 | oldname = kmem_alloc(MAXPATHLEN, KM_PUSHPAGE); | |
1645 | newname = kmem_alloc(MAXPATHLEN, KM_PUSHPAGE); | |
1646 | snprintf(oldname, MAXPATHLEN, "%s@%s", ddrsa->ddrsa_fsname, | |
1647 | ddrsa->ddrsa_oldsnapname); | |
1648 | snprintf(newname, MAXPATHLEN, "%s@%s", ddrsa->ddrsa_fsname, | |
1649 | ddrsa->ddrsa_newsnapname); | |
1650 | zvol_rename_minors(oldname, newname); | |
1651 | kmem_free(newname, MAXPATHLEN); | |
1652 | kmem_free(oldname, MAXPATHLEN); | |
1653 | #endif | |
1654 | ||
13fe0198 | 1655 | dsl_dataset_rele(ds, FTAG); |
34dc7c2f BB |
1656 | return (0); |
1657 | } | |
1658 | ||
13fe0198 MA |
1659 | static void |
1660 | dsl_dataset_rename_snapshot_sync(void *arg, dmu_tx_t *tx) | |
34dc7c2f | 1661 | { |
13fe0198 MA |
1662 | dsl_dataset_rename_snapshot_arg_t *ddrsa = arg; |
1663 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
1664 | dsl_dataset_t *hds; | |
34dc7c2f | 1665 | |
13fe0198 MA |
1666 | VERIFY0(dsl_dataset_hold(dp, ddrsa->ddrsa_fsname, FTAG, &hds)); |
1667 | ddrsa->ddrsa_tx = tx; | |
1668 | if (ddrsa->ddrsa_recursive) { | |
1669 | VERIFY0(dmu_objset_find_dp(dp, hds->ds_dir->dd_object, | |
1670 | dsl_dataset_rename_snapshot_sync_impl, ddrsa, | |
1671 | DS_FIND_CHILDREN)); | |
1672 | } else { | |
1673 | VERIFY0(dsl_dataset_rename_snapshot_sync_impl(dp, hds, ddrsa)); | |
34dc7c2f | 1674 | } |
13fe0198 | 1675 | dsl_dataset_rele(hds, FTAG); |
34dc7c2f BB |
1676 | } |
1677 | ||
13fe0198 MA |
1678 | int |
1679 | dsl_dataset_rename_snapshot(const char *fsname, | |
1680 | const char *oldsnapname, const char *newsnapname, boolean_t recursive) | |
34dc7c2f | 1681 | { |
13fe0198 | 1682 | dsl_dataset_rename_snapshot_arg_t ddrsa; |
34dc7c2f | 1683 | |
13fe0198 MA |
1684 | ddrsa.ddrsa_fsname = fsname; |
1685 | ddrsa.ddrsa_oldsnapname = oldsnapname; | |
1686 | ddrsa.ddrsa_newsnapname = newsnapname; | |
1687 | ddrsa.ddrsa_recursive = recursive; | |
34dc7c2f | 1688 | |
13fe0198 MA |
1689 | return (dsl_sync_task(fsname, dsl_dataset_rename_snapshot_check, |
1690 | dsl_dataset_rename_snapshot_sync, &ddrsa, 1)); | |
34dc7c2f BB |
1691 | } |
1692 | ||
831baf06 KW |
1693 | /* |
1694 | * If we're doing an ownership handoff, we need to make sure that there is | |
1695 | * only one long hold on the dataset. We're not allowed to change anything here | |
1696 | * so we don't permanently release the long hold or regular hold here. We want | |
1697 | * to do this only when syncing to avoid the dataset unexpectedly going away | |
1698 | * when we release the long hold. | |
1699 | */ | |
1700 | static int | |
1701 | dsl_dataset_handoff_check(dsl_dataset_t *ds, void *owner, dmu_tx_t *tx) | |
1702 | { | |
1703 | boolean_t held; | |
1704 | ||
1705 | if (!dmu_tx_is_syncing(tx)) | |
1706 | return (0); | |
1707 | ||
1708 | if (owner != NULL) { | |
1709 | VERIFY3P(ds->ds_owner, ==, owner); | |
1710 | dsl_dataset_long_rele(ds, owner); | |
1711 | } | |
1712 | ||
1713 | held = dsl_dataset_long_held(ds); | |
1714 | ||
1715 | if (owner != NULL) | |
1716 | dsl_dataset_long_hold(ds, owner); | |
1717 | ||
1718 | if (held) | |
1719 | return (SET_ERROR(EBUSY)); | |
1720 | ||
1721 | return (0); | |
1722 | } | |
1723 | ||
1724 | typedef struct dsl_dataset_rollback_arg { | |
1725 | const char *ddra_fsname; | |
1726 | void *ddra_owner; | |
46ba1e59 | 1727 | nvlist_t *ddra_result; |
831baf06 KW |
1728 | } dsl_dataset_rollback_arg_t; |
1729 | ||
13fe0198 MA |
1730 | static int |
1731 | dsl_dataset_rollback_check(void *arg, dmu_tx_t *tx) | |
34dc7c2f | 1732 | { |
831baf06 | 1733 | dsl_dataset_rollback_arg_t *ddra = arg; |
13fe0198 | 1734 | dsl_pool_t *dp = dmu_tx_pool(tx); |
34dc7c2f | 1735 | dsl_dataset_t *ds; |
13fe0198 MA |
1736 | int64_t unused_refres_delta; |
1737 | int error; | |
34dc7c2f | 1738 | |
831baf06 | 1739 | error = dsl_dataset_hold(dp, ddra->ddra_fsname, FTAG, &ds); |
13fe0198 MA |
1740 | if (error != 0) |
1741 | return (error); | |
428870ff | 1742 | |
13fe0198 MA |
1743 | /* must not be a snapshot */ |
1744 | if (dsl_dataset_is_snapshot(ds)) { | |
1745 | dsl_dataset_rele(ds, FTAG); | |
2e528b49 | 1746 | return (SET_ERROR(EINVAL)); |
13fe0198 | 1747 | } |
34dc7c2f | 1748 | |
13fe0198 MA |
1749 | /* must have a most recent snapshot */ |
1750 | if (ds->ds_phys->ds_prev_snap_txg < TXG_INITIAL) { | |
1751 | dsl_dataset_rele(ds, FTAG); | |
2e528b49 | 1752 | return (SET_ERROR(EINVAL)); |
13fe0198 | 1753 | } |
34dc7c2f | 1754 | |
831baf06 KW |
1755 | error = dsl_dataset_handoff_check(ds, ddra->ddra_owner, tx); |
1756 | if (error != 0) { | |
13fe0198 | 1757 | dsl_dataset_rele(ds, FTAG); |
831baf06 | 1758 | return (error); |
34dc7c2f | 1759 | } |
428870ff | 1760 | |
13fe0198 MA |
1761 | /* |
1762 | * Check if the snap we are rolling back to uses more than | |
1763 | * the refquota. | |
1764 | */ | |
1765 | if (ds->ds_quota != 0 && | |
1766 | ds->ds_prev->ds_phys->ds_referenced_bytes > ds->ds_quota) { | |
1767 | dsl_dataset_rele(ds, FTAG); | |
2e528b49 | 1768 | return (SET_ERROR(EDQUOT)); |
34dc7c2f BB |
1769 | } |
1770 | ||
13fe0198 MA |
1771 | /* |
1772 | * When we do the clone swap, we will temporarily use more space | |
1773 | * due to the refreservation (the head will no longer have any | |
1774 | * unique space, so the entire amount of the refreservation will need | |
1775 | * to be free). We will immediately destroy the clone, freeing | |
1776 | * this space, but the freeing happens over many txg's. | |
1777 | */ | |
1778 | unused_refres_delta = (int64_t)MIN(ds->ds_reserved, | |
1779 | ds->ds_phys->ds_unique_bytes); | |
34dc7c2f | 1780 | |
13fe0198 MA |
1781 | if (unused_refres_delta > 0 && |
1782 | unused_refres_delta > | |
1783 | dsl_dir_space_available(ds->ds_dir, NULL, 0, TRUE)) { | |
1784 | dsl_dataset_rele(ds, FTAG); | |
2e528b49 | 1785 | return (SET_ERROR(ENOSPC)); |
13fe0198 | 1786 | } |
34dc7c2f | 1787 | |
13fe0198 MA |
1788 | dsl_dataset_rele(ds, FTAG); |
1789 | return (0); | |
1790 | } | |
34dc7c2f | 1791 | |
13fe0198 MA |
1792 | static void |
1793 | dsl_dataset_rollback_sync(void *arg, dmu_tx_t *tx) | |
1794 | { | |
831baf06 | 1795 | dsl_dataset_rollback_arg_t *ddra = arg; |
13fe0198 MA |
1796 | dsl_pool_t *dp = dmu_tx_pool(tx); |
1797 | dsl_dataset_t *ds, *clone; | |
1798 | uint64_t cloneobj; | |
46ba1e59 | 1799 | char namebuf[ZFS_MAXNAMELEN]; |
34dc7c2f | 1800 | |
831baf06 | 1801 | VERIFY0(dsl_dataset_hold(dp, ddra->ddra_fsname, FTAG, &ds)); |
34dc7c2f | 1802 | |
46ba1e59 MA |
1803 | dsl_dataset_name(ds->ds_prev, namebuf); |
1804 | fnvlist_add_string(ddra->ddra_result, "target", namebuf); | |
1805 | ||
13fe0198 MA |
1806 | cloneobj = dsl_dataset_create_sync(ds->ds_dir, "%rollback", |
1807 | ds->ds_prev, DS_CREATE_FLAG_NODIRTY, kcred, tx); | |
1808 | ||
1809 | VERIFY0(dsl_dataset_hold_obj(dp, cloneobj, FTAG, &clone)); | |
1810 | ||
1811 | dsl_dataset_clone_swap_sync_impl(clone, ds, tx); | |
1812 | dsl_dataset_zero_zil(ds, tx); | |
1813 | ||
1814 | dsl_destroy_head_sync_impl(clone, tx); | |
1815 | ||
1816 | dsl_dataset_rele(clone, FTAG); | |
1817 | dsl_dataset_rele(ds, FTAG); | |
1818 | } | |
1819 | ||
831baf06 | 1820 | /* |
46ba1e59 MA |
1821 | * Rolls back the given filesystem or volume to the most recent snapshot. |
1822 | * The name of the most recent snapshot will be returned under key "target" | |
1823 | * in the result nvlist. | |
831baf06 | 1824 | * |
46ba1e59 | 1825 | * If owner != NULL: |
831baf06 KW |
1826 | * - The existing dataset MUST be owned by the specified owner at entry |
1827 | * - Upon return, dataset will still be held by the same owner, whether we | |
1828 | * succeed or not. | |
1829 | * | |
1830 | * This mode is required any time the existing filesystem is mounted. See | |
1831 | * notes above zfs_suspend_fs() for further details. | |
1832 | */ | |
13fe0198 | 1833 | int |
46ba1e59 | 1834 | dsl_dataset_rollback(const char *fsname, void *owner, nvlist_t *result) |
13fe0198 | 1835 | { |
831baf06 KW |
1836 | dsl_dataset_rollback_arg_t ddra; |
1837 | ||
1838 | ddra.ddra_fsname = fsname; | |
1839 | ddra.ddra_owner = owner; | |
46ba1e59 | 1840 | ddra.ddra_result = result; |
831baf06 | 1841 | |
13fe0198 | 1842 | return (dsl_sync_task(fsname, dsl_dataset_rollback_check, |
46ba1e59 | 1843 | dsl_dataset_rollback_sync, &ddra, 1)); |
34dc7c2f BB |
1844 | } |
1845 | ||
b128c09f BB |
1846 | struct promotenode { |
1847 | list_node_t link; | |
1848 | dsl_dataset_t *ds; | |
1849 | }; | |
1850 | ||
13fe0198 MA |
1851 | typedef struct dsl_dataset_promote_arg { |
1852 | const char *ddpa_clonename; | |
1853 | dsl_dataset_t *ddpa_clone; | |
b128c09f | 1854 | list_t shared_snaps, origin_snaps, clone_snaps; |
13fe0198 | 1855 | dsl_dataset_t *origin_origin; /* origin of the origin */ |
b128c09f | 1856 | uint64_t used, comp, uncomp, unique, cloneusedsnap, originusedsnap; |
428870ff | 1857 | char *err_ds; |
13fe0198 | 1858 | } dsl_dataset_promote_arg_t; |
34dc7c2f | 1859 | |
b128c09f | 1860 | static int snaplist_space(list_t *l, uint64_t mintxg, uint64_t *spacep); |
13fe0198 MA |
1861 | static int promote_hold(dsl_dataset_promote_arg_t *ddpa, dsl_pool_t *dp, |
1862 | void *tag); | |
1863 | static void promote_rele(dsl_dataset_promote_arg_t *ddpa, void *tag); | |
b128c09f | 1864 | |
34dc7c2f | 1865 | static int |
13fe0198 | 1866 | dsl_dataset_promote_check(void *arg, dmu_tx_t *tx) |
34dc7c2f | 1867 | { |
13fe0198 MA |
1868 | dsl_dataset_promote_arg_t *ddpa = arg; |
1869 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
1870 | dsl_dataset_t *hds; | |
1871 | struct promotenode *snap; | |
1872 | dsl_dataset_t *origin_ds; | |
34dc7c2f | 1873 | int err; |
428870ff | 1874 | uint64_t unused; |
34dc7c2f | 1875 | |
13fe0198 MA |
1876 | err = promote_hold(ddpa, dp, FTAG); |
1877 | if (err != 0) | |
1878 | return (err); | |
34dc7c2f | 1879 | |
13fe0198 | 1880 | hds = ddpa->ddpa_clone; |
34dc7c2f | 1881 | |
13fe0198 MA |
1882 | if (hds->ds_phys->ds_flags & DS_FLAG_NOPROMOTE) { |
1883 | promote_rele(ddpa, FTAG); | |
2e528b49 | 1884 | return (SET_ERROR(EXDEV)); |
13fe0198 MA |
1885 | } |
1886 | ||
1887 | /* | |
1888 | * Compute and check the amount of space to transfer. Since this is | |
1889 | * so expensive, don't do the preliminary check. | |
1890 | */ | |
1891 | if (!dmu_tx_is_syncing(tx)) { | |
1892 | promote_rele(ddpa, FTAG); | |
1893 | return (0); | |
1894 | } | |
1895 | ||
1896 | snap = list_head(&ddpa->shared_snaps); | |
1897 | origin_ds = snap->ds; | |
34dc7c2f BB |
1898 | |
1899 | /* compute origin's new unique space */ | |
13fe0198 | 1900 | snap = list_tail(&ddpa->clone_snaps); |
b128c09f | 1901 | ASSERT3U(snap->ds->ds_phys->ds_prev_snap_obj, ==, origin_ds->ds_object); |
428870ff BB |
1902 | dsl_deadlist_space_range(&snap->ds->ds_deadlist, |
1903 | origin_ds->ds_phys->ds_prev_snap_txg, UINT64_MAX, | |
13fe0198 | 1904 | &ddpa->unique, &unused, &unused); |
34dc7c2f | 1905 | |
b128c09f BB |
1906 | /* |
1907 | * Walk the snapshots that we are moving | |
1908 | * | |
1909 | * Compute space to transfer. Consider the incremental changes | |
13fe0198 | 1910 | * to used by each snapshot: |
b128c09f BB |
1911 | * (my used) = (prev's used) + (blocks born) - (blocks killed) |
1912 | * So each snapshot gave birth to: | |
1913 | * (blocks born) = (my used) - (prev's used) + (blocks killed) | |
1914 | * So a sequence would look like: | |
1915 | * (uN - u(N-1) + kN) + ... + (u1 - u0 + k1) + (u0 - 0 + k0) | |
1916 | * Which simplifies to: | |
1917 | * uN + kN + kN-1 + ... + k1 + k0 | |
1918 | * Note however, if we stop before we reach the ORIGIN we get: | |
1919 | * uN + kN + kN-1 + ... + kM - uM-1 | |
1920 | */ | |
13fe0198 MA |
1921 | ddpa->used = origin_ds->ds_phys->ds_referenced_bytes; |
1922 | ddpa->comp = origin_ds->ds_phys->ds_compressed_bytes; | |
1923 | ddpa->uncomp = origin_ds->ds_phys->ds_uncompressed_bytes; | |
1924 | for (snap = list_head(&ddpa->shared_snaps); snap; | |
1925 | snap = list_next(&ddpa->shared_snaps, snap)) { | |
34dc7c2f | 1926 | uint64_t val, dlused, dlcomp, dluncomp; |
b128c09f | 1927 | dsl_dataset_t *ds = snap->ds; |
34dc7c2f | 1928 | |
13fe0198 MA |
1929 | /* |
1930 | * If there are long holds, we won't be able to evict | |
1931 | * the objset. | |
1932 | */ | |
1933 | if (dsl_dataset_long_held(ds)) { | |
2e528b49 | 1934 | err = SET_ERROR(EBUSY); |
13fe0198 MA |
1935 | goto out; |
1936 | } | |
1937 | ||
34dc7c2f | 1938 | /* Check that the snapshot name does not conflict */ |
13fe0198 | 1939 | VERIFY0(dsl_dataset_get_snapname(ds)); |
b128c09f | 1940 | err = dsl_dataset_snap_lookup(hds, ds->ds_snapname, &val); |
428870ff | 1941 | if (err == 0) { |
13fe0198 | 1942 | (void) strcpy(ddpa->err_ds, snap->ds->ds_snapname); |
2e528b49 | 1943 | err = SET_ERROR(EEXIST); |
428870ff BB |
1944 | goto out; |
1945 | } | |
b128c09f | 1946 | if (err != ENOENT) |
428870ff | 1947 | goto out; |
34dc7c2f | 1948 | |
b128c09f | 1949 | /* The very first snapshot does not have a deadlist */ |
34dc7c2f | 1950 | if (ds->ds_phys->ds_prev_snap_obj == 0) |
b128c09f | 1951 | continue; |
34dc7c2f | 1952 | |
428870ff BB |
1953 | dsl_deadlist_space(&ds->ds_deadlist, |
1954 | &dlused, &dlcomp, &dluncomp); | |
13fe0198 MA |
1955 | ddpa->used += dlused; |
1956 | ddpa->comp += dlcomp; | |
1957 | ddpa->uncomp += dluncomp; | |
b128c09f | 1958 | } |
34dc7c2f | 1959 | |
b128c09f BB |
1960 | /* |
1961 | * If we are a clone of a clone then we never reached ORIGIN, | |
1962 | * so we need to subtract out the clone origin's used space. | |
1963 | */ | |
13fe0198 MA |
1964 | if (ddpa->origin_origin) { |
1965 | ddpa->used -= ddpa->origin_origin->ds_phys->ds_referenced_bytes; | |
1966 | ddpa->comp -= ddpa->origin_origin->ds_phys->ds_compressed_bytes; | |
1967 | ddpa->uncomp -= | |
1968 | ddpa->origin_origin->ds_phys->ds_uncompressed_bytes; | |
34dc7c2f BB |
1969 | } |
1970 | ||
1971 | /* Check that there is enough space here */ | |
b128c09f | 1972 | err = dsl_dir_transfer_possible(origin_ds->ds_dir, hds->ds_dir, |
13fe0198 MA |
1973 | ddpa->used); |
1974 | if (err != 0) | |
1975 | goto out; | |
34dc7c2f | 1976 | |
b128c09f BB |
1977 | /* |
1978 | * Compute the amounts of space that will be used by snapshots | |
1979 | * after the promotion (for both origin and clone). For each, | |
1980 | * it is the amount of space that will be on all of their | |
1981 | * deadlists (that was not born before their new origin). | |
1982 | */ | |
1983 | if (hds->ds_dir->dd_phys->dd_flags & DD_FLAG_USED_BREAKDOWN) { | |
1984 | uint64_t space; | |
1985 | ||
1986 | /* | |
1987 | * Note, typically this will not be a clone of a clone, | |
428870ff BB |
1988 | * so dd_origin_txg will be < TXG_INITIAL, so |
1989 | * these snaplist_space() -> dsl_deadlist_space_range() | |
b128c09f BB |
1990 | * calls will be fast because they do not have to |
1991 | * iterate over all bps. | |
1992 | */ | |
13fe0198 MA |
1993 | snap = list_head(&ddpa->origin_snaps); |
1994 | err = snaplist_space(&ddpa->shared_snaps, | |
1995 | snap->ds->ds_dir->dd_origin_txg, &ddpa->cloneusedsnap); | |
1996 | if (err != 0) | |
1997 | goto out; | |
b128c09f | 1998 | |
13fe0198 | 1999 | err = snaplist_space(&ddpa->clone_snaps, |
428870ff | 2000 | snap->ds->ds_dir->dd_origin_txg, &space); |
13fe0198 MA |
2001 | if (err != 0) |
2002 | goto out; | |
2003 | ddpa->cloneusedsnap += space; | |
b128c09f BB |
2004 | } |
2005 | if (origin_ds->ds_dir->dd_phys->dd_flags & DD_FLAG_USED_BREAKDOWN) { | |
13fe0198 MA |
2006 | err = snaplist_space(&ddpa->origin_snaps, |
2007 | origin_ds->ds_phys->ds_creation_txg, &ddpa->originusedsnap); | |
2008 | if (err != 0) | |
2009 | goto out; | |
b128c09f BB |
2010 | } |
2011 | ||
428870ff | 2012 | out: |
13fe0198 | 2013 | promote_rele(ddpa, FTAG); |
428870ff | 2014 | return (err); |
34dc7c2f BB |
2015 | } |
2016 | ||
2017 | static void | |
13fe0198 | 2018 | dsl_dataset_promote_sync(void *arg, dmu_tx_t *tx) |
34dc7c2f | 2019 | { |
13fe0198 MA |
2020 | dsl_dataset_promote_arg_t *ddpa = arg; |
2021 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
2022 | dsl_dataset_t *hds; | |
2023 | struct promotenode *snap; | |
2024 | dsl_dataset_t *origin_ds; | |
b128c09f | 2025 | dsl_dataset_t *origin_head; |
13fe0198 | 2026 | dsl_dir_t *dd; |
34dc7c2f | 2027 | dsl_dir_t *odd = NULL; |
b128c09f BB |
2028 | uint64_t oldnext_obj; |
2029 | int64_t delta; | |
34dc7c2f | 2030 | |
13fe0198 MA |
2031 | VERIFY0(promote_hold(ddpa, dp, FTAG)); |
2032 | hds = ddpa->ddpa_clone; | |
2033 | ||
2034 | ASSERT0(hds->ds_phys->ds_flags & DS_FLAG_NOPROMOTE); | |
2035 | ||
2036 | snap = list_head(&ddpa->shared_snaps); | |
2037 | origin_ds = snap->ds; | |
2038 | dd = hds->ds_dir; | |
34dc7c2f | 2039 | |
13fe0198 | 2040 | snap = list_head(&ddpa->origin_snaps); |
b128c09f BB |
2041 | origin_head = snap->ds; |
2042 | ||
34dc7c2f BB |
2043 | /* |
2044 | * We need to explicitly open odd, since origin_ds's dd will be | |
2045 | * changing. | |
2046 | */ | |
13fe0198 | 2047 | VERIFY0(dsl_dir_hold_obj(dp, origin_ds->ds_dir->dd_object, |
34dc7c2f BB |
2048 | NULL, FTAG, &odd)); |
2049 | ||
b128c09f BB |
2050 | /* change origin's next snap */ |
2051 | dmu_buf_will_dirty(origin_ds->ds_dbuf, tx); | |
2052 | oldnext_obj = origin_ds->ds_phys->ds_next_snap_obj; | |
13fe0198 | 2053 | snap = list_tail(&ddpa->clone_snaps); |
b128c09f BB |
2054 | ASSERT3U(snap->ds->ds_phys->ds_prev_snap_obj, ==, origin_ds->ds_object); |
2055 | origin_ds->ds_phys->ds_next_snap_obj = snap->ds->ds_object; | |
2056 | ||
2057 | /* change the origin's next clone */ | |
2058 | if (origin_ds->ds_phys->ds_next_clones_obj) { | |
13fe0198 MA |
2059 | dsl_dataset_remove_from_next_clones(origin_ds, |
2060 | snap->ds->ds_object, tx); | |
2061 | VERIFY0(zap_add_int(dp->dp_meta_objset, | |
b128c09f BB |
2062 | origin_ds->ds_phys->ds_next_clones_obj, |
2063 | oldnext_obj, tx)); | |
2064 | } | |
2065 | ||
2066 | /* change origin */ | |
2067 | dmu_buf_will_dirty(dd->dd_dbuf, tx); | |
2068 | ASSERT3U(dd->dd_phys->dd_origin_obj, ==, origin_ds->ds_object); | |
2069 | dd->dd_phys->dd_origin_obj = odd->dd_phys->dd_origin_obj; | |
428870ff | 2070 | dd->dd_origin_txg = origin_head->ds_dir->dd_origin_txg; |
b128c09f BB |
2071 | dmu_buf_will_dirty(odd->dd_dbuf, tx); |
2072 | odd->dd_phys->dd_origin_obj = origin_ds->ds_object; | |
428870ff BB |
2073 | origin_head->ds_dir->dd_origin_txg = |
2074 | origin_ds->ds_phys->ds_creation_txg; | |
2075 | ||
2076 | /* change dd_clone entries */ | |
2077 | if (spa_version(dp->dp_spa) >= SPA_VERSION_DIR_CLONES) { | |
13fe0198 | 2078 | VERIFY0(zap_remove_int(dp->dp_meta_objset, |
428870ff | 2079 | odd->dd_phys->dd_clones, hds->ds_object, tx)); |
13fe0198 MA |
2080 | VERIFY0(zap_add_int(dp->dp_meta_objset, |
2081 | ddpa->origin_origin->ds_dir->dd_phys->dd_clones, | |
428870ff BB |
2082 | hds->ds_object, tx)); |
2083 | ||
13fe0198 MA |
2084 | VERIFY0(zap_remove_int(dp->dp_meta_objset, |
2085 | ddpa->origin_origin->ds_dir->dd_phys->dd_clones, | |
428870ff BB |
2086 | origin_head->ds_object, tx)); |
2087 | if (dd->dd_phys->dd_clones == 0) { | |
2088 | dd->dd_phys->dd_clones = zap_create(dp->dp_meta_objset, | |
2089 | DMU_OT_DSL_CLONES, DMU_OT_NONE, 0, tx); | |
2090 | } | |
13fe0198 | 2091 | VERIFY0(zap_add_int(dp->dp_meta_objset, |
428870ff | 2092 | dd->dd_phys->dd_clones, origin_head->ds_object, tx)); |
428870ff | 2093 | } |
34dc7c2f | 2094 | |
b128c09f | 2095 | /* move snapshots to this dir */ |
13fe0198 MA |
2096 | for (snap = list_head(&ddpa->shared_snaps); snap; |
2097 | snap = list_next(&ddpa->shared_snaps, snap)) { | |
b128c09f BB |
2098 | dsl_dataset_t *ds = snap->ds; |
2099 | ||
13fe0198 MA |
2100 | /* |
2101 | * Property callbacks are registered to a particular | |
2102 | * dsl_dir. Since ours is changing, evict the objset | |
2103 | * so that they will be unregistered from the old dsl_dir. | |
2104 | */ | |
428870ff BB |
2105 | if (ds->ds_objset) { |
2106 | dmu_objset_evict(ds->ds_objset); | |
2107 | ds->ds_objset = NULL; | |
b128c09f | 2108 | } |
13fe0198 | 2109 | |
34dc7c2f | 2110 | /* move snap name entry */ |
13fe0198 MA |
2111 | VERIFY0(dsl_dataset_get_snapname(ds)); |
2112 | VERIFY0(dsl_dataset_snap_remove(origin_head, | |
b128c09f | 2113 | ds->ds_snapname, tx)); |
13fe0198 | 2114 | VERIFY0(zap_add(dp->dp_meta_objset, |
34dc7c2f BB |
2115 | hds->ds_phys->ds_snapnames_zapobj, ds->ds_snapname, |
2116 | 8, 1, &ds->ds_object, tx)); | |
428870ff | 2117 | |
34dc7c2f BB |
2118 | /* change containing dsl_dir */ |
2119 | dmu_buf_will_dirty(ds->ds_dbuf, tx); | |
2120 | ASSERT3U(ds->ds_phys->ds_dir_obj, ==, odd->dd_object); | |
2121 | ds->ds_phys->ds_dir_obj = dd->dd_object; | |
2122 | ASSERT3P(ds->ds_dir, ==, odd); | |
13fe0198 MA |
2123 | dsl_dir_rele(ds->ds_dir, ds); |
2124 | VERIFY0(dsl_dir_hold_obj(dp, dd->dd_object, | |
34dc7c2f BB |
2125 | NULL, ds, &ds->ds_dir)); |
2126 | ||
428870ff BB |
2127 | /* move any clone references */ |
2128 | if (ds->ds_phys->ds_next_clones_obj && | |
2129 | spa_version(dp->dp_spa) >= SPA_VERSION_DIR_CLONES) { | |
2130 | zap_cursor_t zc; | |
2131 | zap_attribute_t za; | |
2132 | ||
2133 | for (zap_cursor_init(&zc, dp->dp_meta_objset, | |
2134 | ds->ds_phys->ds_next_clones_obj); | |
2135 | zap_cursor_retrieve(&zc, &za) == 0; | |
13fe0198 MA |
2136 | zap_cursor_advance(&zc)) { |
2137 | dsl_dataset_t *cnds; | |
2138 | uint64_t o; | |
34dc7c2f | 2139 | |
13fe0198 MA |
2140 | if (za.za_first_integer == oldnext_obj) { |
2141 | /* | |
2142 | * We've already moved the | |
2143 | * origin's reference. | |
2144 | */ | |
2145 | continue; | |
2146 | } | |
34dc7c2f | 2147 | |
13fe0198 MA |
2148 | VERIFY0(dsl_dataset_hold_obj(dp, |
2149 | za.za_first_integer, FTAG, &cnds)); | |
2150 | o = cnds->ds_dir->dd_phys->dd_head_dataset_obj; | |
34dc7c2f | 2151 | |
13fe0198 MA |
2152 | VERIFY0(zap_remove_int(dp->dp_meta_objset, |
2153 | odd->dd_phys->dd_clones, o, tx)); | |
2154 | VERIFY0(zap_add_int(dp->dp_meta_objset, | |
2155 | dd->dd_phys->dd_clones, o, tx)); | |
2156 | dsl_dataset_rele(cnds, FTAG); | |
2157 | } | |
2158 | zap_cursor_fini(&zc); | |
2159 | } | |
34dc7c2f | 2160 | |
13fe0198 | 2161 | ASSERT(!dsl_prop_hascb(ds)); |
34dc7c2f BB |
2162 | } |
2163 | ||
34dc7c2f | 2164 | /* |
13fe0198 MA |
2165 | * Change space accounting. |
2166 | * Note, pa->*usedsnap and dd_used_breakdown[SNAP] will either | |
2167 | * both be valid, or both be 0 (resulting in delta == 0). This | |
2168 | * is true for each of {clone,origin} independently. | |
34dc7c2f | 2169 | */ |
570827e1 | 2170 | |
13fe0198 MA |
2171 | delta = ddpa->cloneusedsnap - |
2172 | dd->dd_phys->dd_used_breakdown[DD_USED_SNAP]; | |
2173 | ASSERT3S(delta, >=, 0); | |
2174 | ASSERT3U(ddpa->used, >=, delta); | |
2175 | dsl_dir_diduse_space(dd, DD_USED_SNAP, delta, 0, 0, tx); | |
2176 | dsl_dir_diduse_space(dd, DD_USED_HEAD, | |
2177 | ddpa->used - delta, ddpa->comp, ddpa->uncomp, tx); | |
34dc7c2f | 2178 | |
13fe0198 MA |
2179 | delta = ddpa->originusedsnap - |
2180 | odd->dd_phys->dd_used_breakdown[DD_USED_SNAP]; | |
2181 | ASSERT3S(delta, <=, 0); | |
2182 | ASSERT3U(ddpa->used, >=, -delta); | |
2183 | dsl_dir_diduse_space(odd, DD_USED_SNAP, delta, 0, 0, tx); | |
2184 | dsl_dir_diduse_space(odd, DD_USED_HEAD, | |
2185 | -ddpa->used - delta, -ddpa->comp, -ddpa->uncomp, tx); | |
2186 | ||
2187 | origin_ds->ds_phys->ds_unique_bytes = ddpa->unique; | |
2188 | ||
2189 | /* log history record */ | |
2190 | spa_history_log_internal_ds(hds, "promote", tx, ""); | |
2191 | ||
2192 | dsl_dir_rele(odd, FTAG); | |
2193 | promote_rele(ddpa, FTAG); | |
34dc7c2f BB |
2194 | } |
2195 | ||
13fe0198 MA |
2196 | /* |
2197 | * Make a list of dsl_dataset_t's for the snapshots between first_obj | |
2198 | * (exclusive) and last_obj (inclusive). The list will be in reverse | |
2199 | * order (last_obj will be the list_head()). If first_obj == 0, do all | |
2200 | * snapshots back to this dataset's origin. | |
2201 | */ | |
34dc7c2f | 2202 | static int |
13fe0198 MA |
2203 | snaplist_make(dsl_pool_t *dp, |
2204 | uint64_t first_obj, uint64_t last_obj, list_t *l, void *tag) | |
34dc7c2f | 2205 | { |
13fe0198 | 2206 | uint64_t obj = last_obj; |
34dc7c2f | 2207 | |
13fe0198 MA |
2208 | list_create(l, sizeof (struct promotenode), |
2209 | offsetof(struct promotenode, link)); | |
34dc7c2f | 2210 | |
13fe0198 MA |
2211 | while (obj != first_obj) { |
2212 | dsl_dataset_t *ds; | |
2213 | struct promotenode *snap; | |
2214 | int err; | |
428870ff | 2215 | |
13fe0198 MA |
2216 | err = dsl_dataset_hold_obj(dp, obj, tag, &ds); |
2217 | ASSERT(err != ENOENT); | |
2218 | if (err != 0) | |
2219 | return (err); | |
34dc7c2f | 2220 | |
13fe0198 MA |
2221 | if (first_obj == 0) |
2222 | first_obj = ds->ds_dir->dd_phys->dd_origin_obj; | |
2223 | ||
2517c8ee | 2224 | snap = kmem_alloc(sizeof (*snap), KM_PUSHPAGE); |
13fe0198 MA |
2225 | snap->ds = ds; |
2226 | list_insert_tail(l, snap); | |
2227 | obj = ds->ds_phys->ds_prev_snap_obj; | |
2228 | } | |
34dc7c2f BB |
2229 | |
2230 | return (0); | |
2231 | } | |
2232 | ||
13fe0198 MA |
2233 | static int |
2234 | snaplist_space(list_t *l, uint64_t mintxg, uint64_t *spacep) | |
34dc7c2f | 2235 | { |
13fe0198 | 2236 | struct promotenode *snap; |
6f1ffb06 | 2237 | |
13fe0198 MA |
2238 | *spacep = 0; |
2239 | for (snap = list_head(l); snap; snap = list_next(l, snap)) { | |
2240 | uint64_t used, comp, uncomp; | |
2241 | dsl_deadlist_space_range(&snap->ds->ds_deadlist, | |
2242 | mintxg, UINT64_MAX, &used, &comp, &uncomp); | |
2243 | *spacep += used; | |
428870ff | 2244 | } |
13fe0198 | 2245 | return (0); |
34dc7c2f BB |
2246 | } |
2247 | ||
13fe0198 MA |
2248 | static void |
2249 | snaplist_destroy(list_t *l, void *tag) | |
34dc7c2f | 2250 | { |
13fe0198 | 2251 | struct promotenode *snap; |
428870ff | 2252 | |
13fe0198 MA |
2253 | if (l == NULL || !list_link_active(&l->list_head)) |
2254 | return; | |
34dc7c2f | 2255 | |
13fe0198 MA |
2256 | while ((snap = list_tail(l)) != NULL) { |
2257 | list_remove(l, snap); | |
2258 | dsl_dataset_rele(snap->ds, tag); | |
2259 | kmem_free(snap, sizeof (*snap)); | |
2260 | } | |
2261 | list_destroy(l); | |
34dc7c2f BB |
2262 | } |
2263 | ||
2264 | static int | |
13fe0198 | 2265 | promote_hold(dsl_dataset_promote_arg_t *ddpa, dsl_pool_t *dp, void *tag) |
34dc7c2f | 2266 | { |
13fe0198 MA |
2267 | int error; |
2268 | dsl_dir_t *dd; | |
2269 | struct promotenode *snap; | |
34dc7c2f | 2270 | |
13fe0198 MA |
2271 | error = dsl_dataset_hold(dp, ddpa->ddpa_clonename, tag, |
2272 | &ddpa->ddpa_clone); | |
2273 | if (error != 0) | |
2274 | return (error); | |
2275 | dd = ddpa->ddpa_clone->ds_dir; | |
34dc7c2f | 2276 | |
13fe0198 MA |
2277 | if (dsl_dataset_is_snapshot(ddpa->ddpa_clone) || |
2278 | !dsl_dir_is_clone(dd)) { | |
2279 | dsl_dataset_rele(ddpa->ddpa_clone, tag); | |
2e528b49 | 2280 | return (SET_ERROR(EINVAL)); |
13fe0198 | 2281 | } |
34dc7c2f | 2282 | |
13fe0198 MA |
2283 | error = snaplist_make(dp, 0, dd->dd_phys->dd_origin_obj, |
2284 | &ddpa->shared_snaps, tag); | |
2285 | if (error != 0) | |
2286 | goto out; | |
34dc7c2f | 2287 | |
13fe0198 MA |
2288 | error = snaplist_make(dp, 0, ddpa->ddpa_clone->ds_object, |
2289 | &ddpa->clone_snaps, tag); | |
2290 | if (error != 0) | |
2291 | goto out; | |
34dc7c2f | 2292 | |
13fe0198 MA |
2293 | snap = list_head(&ddpa->shared_snaps); |
2294 | ASSERT3U(snap->ds->ds_object, ==, dd->dd_phys->dd_origin_obj); | |
2295 | error = snaplist_make(dp, dd->dd_phys->dd_origin_obj, | |
2296 | snap->ds->ds_dir->dd_phys->dd_head_dataset_obj, | |
2297 | &ddpa->origin_snaps, tag); | |
2298 | if (error != 0) | |
2299 | goto out; | |
d164b209 | 2300 | |
13fe0198 MA |
2301 | if (snap->ds->ds_dir->dd_phys->dd_origin_obj != 0) { |
2302 | error = dsl_dataset_hold_obj(dp, | |
2303 | snap->ds->ds_dir->dd_phys->dd_origin_obj, | |
2304 | tag, &ddpa->origin_origin); | |
2305 | if (error != 0) | |
2306 | goto out; | |
d164b209 | 2307 | } |
13fe0198 MA |
2308 | out: |
2309 | if (error != 0) | |
2310 | promote_rele(ddpa, tag); | |
2311 | return (error); | |
34dc7c2f BB |
2312 | } |
2313 | ||
34dc7c2f | 2314 | static void |
13fe0198 | 2315 | promote_rele(dsl_dataset_promote_arg_t *ddpa, void *tag) |
34dc7c2f | 2316 | { |
13fe0198 MA |
2317 | snaplist_destroy(&ddpa->shared_snaps, tag); |
2318 | snaplist_destroy(&ddpa->clone_snaps, tag); | |
2319 | snaplist_destroy(&ddpa->origin_snaps, tag); | |
2320 | if (ddpa->origin_origin != NULL) | |
2321 | dsl_dataset_rele(ddpa->origin_origin, tag); | |
2322 | dsl_dataset_rele(ddpa->ddpa_clone, tag); | |
2323 | } | |
428870ff | 2324 | |
13fe0198 MA |
2325 | /* |
2326 | * Promote a clone. | |
2327 | * | |
2328 | * If it fails due to a conflicting snapshot name, "conflsnap" will be filled | |
2329 | * in with the name. (It must be at least MAXNAMELEN bytes long.) | |
2330 | */ | |
2331 | int | |
2332 | dsl_dataset_promote(const char *name, char *conflsnap) | |
2333 | { | |
2334 | dsl_dataset_promote_arg_t ddpa = { 0 }; | |
2335 | uint64_t numsnaps; | |
2336 | int error; | |
2337 | objset_t *os; | |
34dc7c2f | 2338 | |
13fe0198 MA |
2339 | /* |
2340 | * We will modify space proportional to the number of | |
2341 | * snapshots. Compute numsnaps. | |
2342 | */ | |
2343 | error = dmu_objset_hold(name, FTAG, &os); | |
2344 | if (error != 0) | |
2345 | return (error); | |
2346 | error = zap_count(dmu_objset_pool(os)->dp_meta_objset, | |
2347 | dmu_objset_ds(os)->ds_phys->ds_snapnames_zapobj, &numsnaps); | |
2348 | dmu_objset_rele(os, FTAG); | |
2349 | if (error != 0) | |
2350 | return (error); | |
34dc7c2f | 2351 | |
13fe0198 MA |
2352 | ddpa.ddpa_clonename = name; |
2353 | ddpa.err_ds = conflsnap; | |
6f1ffb06 | 2354 | |
13fe0198 MA |
2355 | return (dsl_sync_task(name, dsl_dataset_promote_check, |
2356 | dsl_dataset_promote_sync, &ddpa, 2 + numsnaps)); | |
34dc7c2f BB |
2357 | } |
2358 | ||
2359 | int | |
13fe0198 | 2360 | dsl_dataset_clone_swap_check_impl(dsl_dataset_t *clone, |
831baf06 | 2361 | dsl_dataset_t *origin_head, boolean_t force, void *owner, dmu_tx_t *tx) |
34dc7c2f | 2362 | { |
13fe0198 | 2363 | int64_t unused_refres_delta; |
34dc7c2f | 2364 | |
13fe0198 MA |
2365 | /* they should both be heads */ |
2366 | if (dsl_dataset_is_snapshot(clone) || | |
2367 | dsl_dataset_is_snapshot(origin_head)) | |
2e528b49 | 2368 | return (SET_ERROR(EINVAL)); |
428870ff | 2369 | |
19580676 MA |
2370 | /* if we are not forcing, the branch point should be just before them */ |
2371 | if (!force && clone->ds_prev != origin_head->ds_prev) | |
2e528b49 | 2372 | return (SET_ERROR(EINVAL)); |
34dc7c2f | 2373 | |
13fe0198 MA |
2374 | /* clone should be the clone (unless they are unrelated) */ |
2375 | if (clone->ds_prev != NULL && | |
2376 | clone->ds_prev != clone->ds_dir->dd_pool->dp_origin_snap && | |
19580676 | 2377 | origin_head->ds_dir != clone->ds_prev->ds_dir) |
2e528b49 | 2378 | return (SET_ERROR(EINVAL)); |
428870ff | 2379 | |
13fe0198 MA |
2380 | /* the clone should be a child of the origin */ |
2381 | if (clone->ds_dir->dd_parent != origin_head->ds_dir) | |
2e528b49 | 2382 | return (SET_ERROR(EINVAL)); |
45d1cae3 | 2383 | |
13fe0198 | 2384 | /* origin_head shouldn't be modified unless 'force' */ |
19580676 MA |
2385 | if (!force && |
2386 | dsl_dataset_modified_since_snap(origin_head, origin_head->ds_prev)) | |
2e528b49 | 2387 | return (SET_ERROR(ETXTBSY)); |
572e2857 | 2388 | |
13fe0198 | 2389 | /* origin_head should have no long holds (e.g. is not mounted) */ |
831baf06 | 2390 | if (dsl_dataset_handoff_check(origin_head, owner, tx)) |
2e528b49 | 2391 | return (SET_ERROR(EBUSY)); |
13fe0198 MA |
2392 | |
2393 | /* check amount of any unconsumed refreservation */ | |
2394 | unused_refres_delta = | |
2395 | (int64_t)MIN(origin_head->ds_reserved, | |
2396 | origin_head->ds_phys->ds_unique_bytes) - | |
2397 | (int64_t)MIN(origin_head->ds_reserved, | |
2398 | clone->ds_phys->ds_unique_bytes); | |
2399 | ||
2400 | if (unused_refres_delta > 0 && | |
2401 | unused_refres_delta > | |
2402 | dsl_dir_space_available(origin_head->ds_dir, NULL, 0, TRUE)) | |
2e528b49 | 2403 | return (SET_ERROR(ENOSPC)); |
13fe0198 MA |
2404 | |
2405 | /* clone can't be over the head's refquota */ | |
2406 | if (origin_head->ds_quota != 0 && | |
2407 | clone->ds_phys->ds_referenced_bytes > origin_head->ds_quota) | |
2e528b49 | 2408 | return (SET_ERROR(EDQUOT)); |
572e2857 | 2409 | |
13fe0198 | 2410 | return (0); |
572e2857 BB |
2411 | } |
2412 | ||
2413 | void | |
13fe0198 MA |
2414 | dsl_dataset_clone_swap_sync_impl(dsl_dataset_t *clone, |
2415 | dsl_dataset_t *origin_head, dmu_tx_t *tx) | |
572e2857 | 2416 | { |
13fe0198 MA |
2417 | dsl_pool_t *dp = dmu_tx_pool(tx); |
2418 | int64_t unused_refres_delta; | |
428870ff | 2419 | |
13fe0198 MA |
2420 | ASSERT(clone->ds_reserved == 0); |
2421 | ASSERT(origin_head->ds_quota == 0 || | |
2422 | clone->ds_phys->ds_unique_bytes <= origin_head->ds_quota); | |
19580676 | 2423 | ASSERT3P(clone->ds_prev, ==, origin_head->ds_prev); |
45d1cae3 | 2424 | |
13fe0198 MA |
2425 | dmu_buf_will_dirty(clone->ds_dbuf, tx); |
2426 | dmu_buf_will_dirty(origin_head->ds_dbuf, tx); | |
45d1cae3 | 2427 | |
13fe0198 MA |
2428 | if (clone->ds_objset != NULL) { |
2429 | dmu_objset_evict(clone->ds_objset); | |
2430 | clone->ds_objset = NULL; | |
2431 | } | |
45d1cae3 | 2432 | |
13fe0198 MA |
2433 | if (origin_head->ds_objset != NULL) { |
2434 | dmu_objset_evict(origin_head->ds_objset); | |
2435 | origin_head->ds_objset = NULL; | |
45d1cae3 | 2436 | } |
45d1cae3 | 2437 | |
13fe0198 MA |
2438 | unused_refres_delta = |
2439 | (int64_t)MIN(origin_head->ds_reserved, | |
2440 | origin_head->ds_phys->ds_unique_bytes) - | |
2441 | (int64_t)MIN(origin_head->ds_reserved, | |
2442 | clone->ds_phys->ds_unique_bytes); | |
2443 | ||
2444 | /* | |
2445 | * Reset origin's unique bytes, if it exists. | |
2446 | */ | |
2447 | if (clone->ds_prev) { | |
2448 | dsl_dataset_t *origin = clone->ds_prev; | |
2449 | uint64_t comp, uncomp; | |
2450 | ||
2451 | dmu_buf_will_dirty(origin->ds_dbuf, tx); | |
2452 | dsl_deadlist_space_range(&clone->ds_deadlist, | |
2453 | origin->ds_phys->ds_prev_snap_txg, UINT64_MAX, | |
2454 | &origin->ds_phys->ds_unique_bytes, &comp, &uncomp); | |
2455 | } | |
2456 | ||
2457 | /* swap blkptrs */ | |
2458 | { | |
2459 | blkptr_t tmp; | |
2460 | tmp = origin_head->ds_phys->ds_bp; | |
2461 | origin_head->ds_phys->ds_bp = clone->ds_phys->ds_bp; | |
2462 | clone->ds_phys->ds_bp = tmp; | |
2463 | } | |
2464 | ||
2465 | /* set dd_*_bytes */ | |
2466 | { | |
2467 | int64_t dused, dcomp, duncomp; | |
2468 | uint64_t cdl_used, cdl_comp, cdl_uncomp; | |
2469 | uint64_t odl_used, odl_comp, odl_uncomp; | |
2470 | ||
2471 | ASSERT3U(clone->ds_dir->dd_phys-> | |
2472 | dd_used_breakdown[DD_USED_SNAP], ==, 0); | |
2473 | ||
2474 | dsl_deadlist_space(&clone->ds_deadlist, | |
2475 | &cdl_used, &cdl_comp, &cdl_uncomp); | |
2476 | dsl_deadlist_space(&origin_head->ds_deadlist, | |
2477 | &odl_used, &odl_comp, &odl_uncomp); | |
428870ff | 2478 | |
13fe0198 MA |
2479 | dused = clone->ds_phys->ds_referenced_bytes + cdl_used - |
2480 | (origin_head->ds_phys->ds_referenced_bytes + odl_used); | |
2481 | dcomp = clone->ds_phys->ds_compressed_bytes + cdl_comp - | |
2482 | (origin_head->ds_phys->ds_compressed_bytes + odl_comp); | |
2483 | duncomp = clone->ds_phys->ds_uncompressed_bytes + | |
2484 | cdl_uncomp - | |
2485 | (origin_head->ds_phys->ds_uncompressed_bytes + odl_uncomp); | |
45d1cae3 | 2486 | |
13fe0198 MA |
2487 | dsl_dir_diduse_space(origin_head->ds_dir, DD_USED_HEAD, |
2488 | dused, dcomp, duncomp, tx); | |
2489 | dsl_dir_diduse_space(clone->ds_dir, DD_USED_HEAD, | |
2490 | -dused, -dcomp, -duncomp, tx); | |
45d1cae3 | 2491 | |
45d1cae3 | 2492 | /* |
13fe0198 MA |
2493 | * The difference in the space used by snapshots is the |
2494 | * difference in snapshot space due to the head's | |
2495 | * deadlist (since that's the only thing that's | |
2496 | * changing that affects the snapused). | |
45d1cae3 | 2497 | */ |
13fe0198 MA |
2498 | dsl_deadlist_space_range(&clone->ds_deadlist, |
2499 | origin_head->ds_dir->dd_origin_txg, UINT64_MAX, | |
2500 | &cdl_used, &cdl_comp, &cdl_uncomp); | |
2501 | dsl_deadlist_space_range(&origin_head->ds_deadlist, | |
2502 | origin_head->ds_dir->dd_origin_txg, UINT64_MAX, | |
2503 | &odl_used, &odl_comp, &odl_uncomp); | |
2504 | dsl_dir_transfer_space(origin_head->ds_dir, cdl_used - odl_used, | |
2505 | DD_USED_HEAD, DD_USED_SNAP, tx); | |
45d1cae3 | 2506 | } |
45d1cae3 | 2507 | |
13fe0198 MA |
2508 | /* swap ds_*_bytes */ |
2509 | SWITCH64(origin_head->ds_phys->ds_referenced_bytes, | |
2510 | clone->ds_phys->ds_referenced_bytes); | |
2511 | SWITCH64(origin_head->ds_phys->ds_compressed_bytes, | |
2512 | clone->ds_phys->ds_compressed_bytes); | |
2513 | SWITCH64(origin_head->ds_phys->ds_uncompressed_bytes, | |
2514 | clone->ds_phys->ds_uncompressed_bytes); | |
2515 | SWITCH64(origin_head->ds_phys->ds_unique_bytes, | |
2516 | clone->ds_phys->ds_unique_bytes); | |
45d1cae3 | 2517 | |
13fe0198 MA |
2518 | /* apply any parent delta for change in unconsumed refreservation */ |
2519 | dsl_dir_diduse_space(origin_head->ds_dir, DD_USED_REFRSRV, | |
2520 | unused_refres_delta, 0, 0, tx); | |
45d1cae3 | 2521 | |
13fe0198 MA |
2522 | /* |
2523 | * Swap deadlists. | |
2524 | */ | |
2525 | dsl_deadlist_close(&clone->ds_deadlist); | |
2526 | dsl_deadlist_close(&origin_head->ds_deadlist); | |
2527 | SWITCH64(origin_head->ds_phys->ds_deadlist_obj, | |
2528 | clone->ds_phys->ds_deadlist_obj); | |
2529 | dsl_deadlist_open(&clone->ds_deadlist, dp->dp_meta_objset, | |
2530 | clone->ds_phys->ds_deadlist_obj); | |
2531 | dsl_deadlist_open(&origin_head->ds_deadlist, dp->dp_meta_objset, | |
2532 | origin_head->ds_phys->ds_deadlist_obj); | |
45d1cae3 | 2533 | |
13fe0198 | 2534 | dsl_scan_ds_clone_swapped(origin_head, clone, tx); |
45d1cae3 | 2535 | |
13fe0198 MA |
2536 | spa_history_log_internal_ds(clone, "clone swap", tx, |
2537 | "parent=%s", origin_head->ds_dir->dd_myname); | |
45d1cae3 BB |
2538 | } |
2539 | ||
13fe0198 MA |
2540 | /* |
2541 | * Given a pool name and a dataset object number in that pool, | |
2542 | * return the name of that dataset. | |
2543 | */ | |
572e2857 | 2544 | int |
13fe0198 | 2545 | dsl_dsobj_to_dsname(char *pname, uint64_t obj, char *buf) |
572e2857 | 2546 | { |
13fe0198 MA |
2547 | dsl_pool_t *dp; |
2548 | dsl_dataset_t *ds; | |
572e2857 BB |
2549 | int error; |
2550 | ||
13fe0198 MA |
2551 | error = dsl_pool_hold(pname, FTAG, &dp); |
2552 | if (error != 0) | |
2553 | return (error); | |
2554 | ||
2555 | error = dsl_dataset_hold_obj(dp, obj, FTAG, &ds); | |
2556 | if (error == 0) { | |
2557 | dsl_dataset_name(ds, buf); | |
2558 | dsl_dataset_rele(ds, FTAG); | |
2559 | } | |
2560 | dsl_pool_rele(dp, FTAG); | |
572e2857 BB |
2561 | |
2562 | return (error); | |
2563 | } | |
2564 | ||
45d1cae3 | 2565 | int |
13fe0198 MA |
2566 | dsl_dataset_check_quota(dsl_dataset_t *ds, boolean_t check_quota, |
2567 | uint64_t asize, uint64_t inflight, uint64_t *used, uint64_t *ref_rsrv) | |
45d1cae3 | 2568 | { |
13fe0198 | 2569 | int error = 0; |
45d1cae3 | 2570 | |
13fe0198 | 2571 | ASSERT3S(asize, >, 0); |
45d1cae3 | 2572 | |
13fe0198 MA |
2573 | /* |
2574 | * *ref_rsrv is the portion of asize that will come from any | |
2575 | * unconsumed refreservation space. | |
2576 | */ | |
2577 | *ref_rsrv = 0; | |
45d1cae3 | 2578 | |
13fe0198 MA |
2579 | mutex_enter(&ds->ds_lock); |
2580 | /* | |
2581 | * Make a space adjustment for reserved bytes. | |
2582 | */ | |
2583 | if (ds->ds_reserved > ds->ds_phys->ds_unique_bytes) { | |
2584 | ASSERT3U(*used, >=, | |
2585 | ds->ds_reserved - ds->ds_phys->ds_unique_bytes); | |
2586 | *used -= (ds->ds_reserved - ds->ds_phys->ds_unique_bytes); | |
2587 | *ref_rsrv = | |
2588 | asize - MIN(asize, parent_delta(ds, asize + inflight)); | |
45d1cae3 BB |
2589 | } |
2590 | ||
13fe0198 MA |
2591 | if (!check_quota || ds->ds_quota == 0) { |
2592 | mutex_exit(&ds->ds_lock); | |
2593 | return (0); | |
45d1cae3 | 2594 | } |
13fe0198 MA |
2595 | /* |
2596 | * If they are requesting more space, and our current estimate | |
2597 | * is over quota, they get to try again unless the actual | |
2598 | * on-disk is over quota and there are no pending changes (which | |
2599 | * may free up space for us). | |
2600 | */ | |
2601 | if (ds->ds_phys->ds_referenced_bytes + inflight >= ds->ds_quota) { | |
2602 | if (inflight > 0 || | |
2603 | ds->ds_phys->ds_referenced_bytes < ds->ds_quota) | |
2e528b49 | 2604 | error = SET_ERROR(ERESTART); |
13fe0198 | 2605 | else |
2e528b49 | 2606 | error = SET_ERROR(EDQUOT); |
45d1cae3 | 2607 | } |
13fe0198 | 2608 | mutex_exit(&ds->ds_lock); |
45d1cae3 | 2609 | |
45d1cae3 BB |
2610 | return (error); |
2611 | } | |
2612 | ||
13fe0198 MA |
2613 | typedef struct dsl_dataset_set_qr_arg { |
2614 | const char *ddsqra_name; | |
2615 | zprop_source_t ddsqra_source; | |
2616 | uint64_t ddsqra_value; | |
2617 | } dsl_dataset_set_qr_arg_t; | |
45d1cae3 | 2618 | |
13fe0198 MA |
2619 | |
2620 | /* ARGSUSED */ | |
45d1cae3 | 2621 | static int |
13fe0198 | 2622 | dsl_dataset_set_refquota_check(void *arg, dmu_tx_t *tx) |
45d1cae3 | 2623 | { |
13fe0198 MA |
2624 | dsl_dataset_set_qr_arg_t *ddsqra = arg; |
2625 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
2626 | dsl_dataset_t *ds; | |
45d1cae3 | 2627 | int error; |
13fe0198 | 2628 | uint64_t newval; |
45d1cae3 | 2629 | |
13fe0198 | 2630 | if (spa_version(dp->dp_spa) < SPA_VERSION_REFQUOTA) |
2e528b49 | 2631 | return (SET_ERROR(ENOTSUP)); |
45d1cae3 | 2632 | |
13fe0198 MA |
2633 | error = dsl_dataset_hold(dp, ddsqra->ddsqra_name, FTAG, &ds); |
2634 | if (error != 0) | |
2635 | return (error); | |
2636 | ||
2637 | if (dsl_dataset_is_snapshot(ds)) { | |
2638 | dsl_dataset_rele(ds, FTAG); | |
2e528b49 | 2639 | return (SET_ERROR(EINVAL)); |
45d1cae3 BB |
2640 | } |
2641 | ||
13fe0198 MA |
2642 | error = dsl_prop_predict(ds->ds_dir, |
2643 | zfs_prop_to_name(ZFS_PROP_REFQUOTA), | |
2644 | ddsqra->ddsqra_source, ddsqra->ddsqra_value, &newval); | |
2645 | if (error != 0) { | |
2646 | dsl_dataset_rele(ds, FTAG); | |
45d1cae3 BB |
2647 | return (error); |
2648 | } | |
2649 | ||
13fe0198 MA |
2650 | if (newval == 0) { |
2651 | dsl_dataset_rele(ds, FTAG); | |
2652 | return (0); | |
2653 | } | |
2654 | ||
2655 | if (newval < ds->ds_phys->ds_referenced_bytes || | |
2656 | newval < ds->ds_reserved) { | |
2657 | dsl_dataset_rele(ds, FTAG); | |
2e528b49 | 2658 | return (SET_ERROR(ENOSPC)); |
13fe0198 | 2659 | } |
45d1cae3 | 2660 | |
13fe0198 | 2661 | dsl_dataset_rele(ds, FTAG); |
45d1cae3 BB |
2662 | return (0); |
2663 | } | |
2664 | ||
13fe0198 MA |
2665 | static void |
2666 | dsl_dataset_set_refquota_sync(void *arg, dmu_tx_t *tx) | |
45d1cae3 | 2667 | { |
13fe0198 MA |
2668 | dsl_dataset_set_qr_arg_t *ddsqra = arg; |
2669 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
2670 | dsl_dataset_t *ds; | |
2671 | uint64_t newval; | |
45d1cae3 | 2672 | |
13fe0198 | 2673 | VERIFY0(dsl_dataset_hold(dp, ddsqra->ddsqra_name, FTAG, &ds)); |
45d1cae3 | 2674 | |
13fe0198 MA |
2675 | dsl_prop_set_sync_impl(ds, |
2676 | zfs_prop_to_name(ZFS_PROP_REFQUOTA), | |
2677 | ddsqra->ddsqra_source, sizeof (ddsqra->ddsqra_value), 1, | |
2678 | &ddsqra->ddsqra_value, tx); | |
45d1cae3 | 2679 | |
13fe0198 MA |
2680 | VERIFY0(dsl_prop_get_int_ds(ds, |
2681 | zfs_prop_to_name(ZFS_PROP_REFQUOTA), &newval)); | |
45d1cae3 | 2682 | |
13fe0198 MA |
2683 | if (ds->ds_quota != newval) { |
2684 | dmu_buf_will_dirty(ds->ds_dbuf, tx); | |
2685 | ds->ds_quota = newval; | |
45d1cae3 | 2686 | } |
13fe0198 | 2687 | dsl_dataset_rele(ds, FTAG); |
45d1cae3 BB |
2688 | } |
2689 | ||
13fe0198 MA |
2690 | int |
2691 | dsl_dataset_set_refquota(const char *dsname, zprop_source_t source, | |
2692 | uint64_t refquota) | |
45d1cae3 | 2693 | { |
13fe0198 | 2694 | dsl_dataset_set_qr_arg_t ddsqra; |
428870ff | 2695 | |
13fe0198 MA |
2696 | ddsqra.ddsqra_name = dsname; |
2697 | ddsqra.ddsqra_source = source; | |
2698 | ddsqra.ddsqra_value = refquota; | |
2699 | ||
2700 | return (dsl_sync_task(dsname, dsl_dataset_set_refquota_check, | |
2701 | dsl_dataset_set_refquota_sync, &ddsqra, 0)); | |
45d1cae3 BB |
2702 | } |
2703 | ||
2704 | static int | |
13fe0198 | 2705 | dsl_dataset_set_refreservation_check(void *arg, dmu_tx_t *tx) |
45d1cae3 | 2706 | { |
13fe0198 MA |
2707 | dsl_dataset_set_qr_arg_t *ddsqra = arg; |
2708 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
45d1cae3 BB |
2709 | dsl_dataset_t *ds; |
2710 | int error; | |
13fe0198 | 2711 | uint64_t newval, unique; |
428870ff | 2712 | |
13fe0198 | 2713 | if (spa_version(dp->dp_spa) < SPA_VERSION_REFRESERVATION) |
2e528b49 | 2714 | return (SET_ERROR(ENOTSUP)); |
45d1cae3 | 2715 | |
13fe0198 MA |
2716 | error = dsl_dataset_hold(dp, ddsqra->ddsqra_name, FTAG, &ds); |
2717 | if (error != 0) | |
45d1cae3 | 2718 | return (error); |
45d1cae3 | 2719 | |
13fe0198 MA |
2720 | if (dsl_dataset_is_snapshot(ds)) { |
2721 | dsl_dataset_rele(ds, FTAG); | |
2e528b49 | 2722 | return (SET_ERROR(EINVAL)); |
45d1cae3 BB |
2723 | } |
2724 | ||
13fe0198 MA |
2725 | error = dsl_prop_predict(ds->ds_dir, |
2726 | zfs_prop_to_name(ZFS_PROP_REFRESERVATION), | |
2727 | ddsqra->ddsqra_source, ddsqra->ddsqra_value, &newval); | |
2728 | if (error != 0) { | |
2729 | dsl_dataset_rele(ds, FTAG); | |
45d1cae3 BB |
2730 | return (error); |
2731 | } | |
2732 | ||
13fe0198 MA |
2733 | /* |
2734 | * If we are doing the preliminary check in open context, the | |
2735 | * space estimates may be inaccurate. | |
2736 | */ | |
2737 | if (!dmu_tx_is_syncing(tx)) { | |
2738 | dsl_dataset_rele(ds, FTAG); | |
2739 | return (0); | |
45d1cae3 | 2740 | } |
45d1cae3 | 2741 | |
13fe0198 MA |
2742 | mutex_enter(&ds->ds_lock); |
2743 | if (!DS_UNIQUE_IS_ACCURATE(ds)) | |
2744 | dsl_dataset_recalc_head_uniq(ds); | |
2745 | unique = ds->ds_phys->ds_unique_bytes; | |
2746 | mutex_exit(&ds->ds_lock); | |
45d1cae3 | 2747 | |
13fe0198 MA |
2748 | if (MAX(unique, newval) > MAX(unique, ds->ds_reserved)) { |
2749 | uint64_t delta = MAX(unique, newval) - | |
2750 | MAX(unique, ds->ds_reserved); | |
45d1cae3 | 2751 | |
13fe0198 MA |
2752 | if (delta > |
2753 | dsl_dir_space_available(ds->ds_dir, NULL, 0, B_TRUE) || | |
2754 | (ds->ds_quota > 0 && newval > ds->ds_quota)) { | |
2755 | dsl_dataset_rele(ds, FTAG); | |
2e528b49 | 2756 | return (SET_ERROR(ENOSPC)); |
13fe0198 | 2757 | } |
45d1cae3 BB |
2758 | } |
2759 | ||
13fe0198 MA |
2760 | dsl_dataset_rele(ds, FTAG); |
2761 | return (0); | |
45d1cae3 BB |
2762 | } |
2763 | ||
13fe0198 MA |
2764 | void |
2765 | dsl_dataset_set_refreservation_sync_impl(dsl_dataset_t *ds, | |
2766 | zprop_source_t source, uint64_t value, dmu_tx_t *tx) | |
428870ff | 2767 | { |
13fe0198 MA |
2768 | uint64_t newval; |
2769 | uint64_t unique; | |
2770 | int64_t delta; | |
428870ff | 2771 | |
13fe0198 MA |
2772 | dsl_prop_set_sync_impl(ds, zfs_prop_to_name(ZFS_PROP_REFRESERVATION), |
2773 | source, sizeof (value), 1, &value, tx); | |
428870ff | 2774 | |
13fe0198 MA |
2775 | VERIFY0(dsl_prop_get_int_ds(ds, |
2776 | zfs_prop_to_name(ZFS_PROP_REFRESERVATION), &newval)); | |
572e2857 | 2777 | |
13fe0198 MA |
2778 | dmu_buf_will_dirty(ds->ds_dbuf, tx); |
2779 | mutex_enter(&ds->ds_dir->dd_lock); | |
2780 | mutex_enter(&ds->ds_lock); | |
2781 | ASSERT(DS_UNIQUE_IS_ACCURATE(ds)); | |
2782 | unique = ds->ds_phys->ds_unique_bytes; | |
2783 | delta = MAX(0, (int64_t)(newval - unique)) - | |
2784 | MAX(0, (int64_t)(ds->ds_reserved - unique)); | |
2785 | ds->ds_reserved = newval; | |
2786 | mutex_exit(&ds->ds_lock); | |
572e2857 | 2787 | |
13fe0198 MA |
2788 | dsl_dir_diduse_space(ds->ds_dir, DD_USED_REFRSRV, delta, 0, 0, tx); |
2789 | mutex_exit(&ds->ds_dir->dd_lock); | |
428870ff BB |
2790 | } |
2791 | ||
13fe0198 MA |
2792 | static void |
2793 | dsl_dataset_set_refreservation_sync(void *arg, dmu_tx_t *tx) | |
45d1cae3 | 2794 | { |
13fe0198 MA |
2795 | dsl_dataset_set_qr_arg_t *ddsqra = arg; |
2796 | dsl_pool_t *dp = dmu_tx_pool(tx); | |
45d1cae3 | 2797 | dsl_dataset_t *ds; |
45d1cae3 | 2798 | |
13fe0198 MA |
2799 | VERIFY0(dsl_dataset_hold(dp, ddsqra->ddsqra_name, FTAG, &ds)); |
2800 | dsl_dataset_set_refreservation_sync_impl(ds, | |
2801 | ddsqra->ddsqra_source, ddsqra->ddsqra_value, tx); | |
45d1cae3 | 2802 | dsl_dataset_rele(ds, FTAG); |
45d1cae3 | 2803 | } |
428870ff | 2804 | |
428870ff | 2805 | int |
13fe0198 MA |
2806 | dsl_dataset_set_refreservation(const char *dsname, zprop_source_t source, |
2807 | uint64_t refreservation) | |
428870ff | 2808 | { |
13fe0198 | 2809 | dsl_dataset_set_qr_arg_t ddsqra; |
428870ff | 2810 | |
13fe0198 MA |
2811 | ddsqra.ddsqra_name = dsname; |
2812 | ddsqra.ddsqra_source = source; | |
2813 | ddsqra.ddsqra_value = refreservation; | |
c28b2279 | 2814 | |
13fe0198 MA |
2815 | return (dsl_sync_task(dsname, dsl_dataset_set_refreservation_check, |
2816 | dsl_dataset_set_refreservation_sync, &ddsqra, 0)); | |
2817 | } | |
330d06f9 MA |
2818 | |
2819 | /* | |
2820 | * Return (in *usedp) the amount of space written in new that is not | |
2821 | * present in oldsnap. New may be a snapshot or the head. Old must be | |
2822 | * a snapshot before new, in new's filesystem (or its origin). If not then | |
2823 | * fail and return EINVAL. | |
2824 | * | |
2825 | * The written space is calculated by considering two components: First, we | |
2826 | * ignore any freed space, and calculate the written as new's used space | |
2827 | * minus old's used space. Next, we add in the amount of space that was freed | |
2828 | * between the two snapshots, thus reducing new's used space relative to old's. | |
2829 | * Specifically, this is the space that was born before old->ds_creation_txg, | |
2830 | * and freed before new (ie. on new's deadlist or a previous deadlist). | |
2831 | * | |
2832 | * space freed [---------------------] | |
2833 | * snapshots ---O-------O--------O-------O------ | |
2834 | * oldsnap new | |
2835 | */ | |
2836 | int | |
2837 | dsl_dataset_space_written(dsl_dataset_t *oldsnap, dsl_dataset_t *new, | |
2838 | uint64_t *usedp, uint64_t *compp, uint64_t *uncompp) | |
2839 | { | |
2840 | int err = 0; | |
2841 | uint64_t snapobj; | |
2842 | dsl_pool_t *dp = new->ds_dir->dd_pool; | |
2843 | ||
13fe0198 MA |
2844 | ASSERT(dsl_pool_config_held(dp)); |
2845 | ||
330d06f9 | 2846 | *usedp = 0; |
9ae529ec CS |
2847 | *usedp += new->ds_phys->ds_referenced_bytes; |
2848 | *usedp -= oldsnap->ds_phys->ds_referenced_bytes; | |
330d06f9 MA |
2849 | |
2850 | *compp = 0; | |
2851 | *compp += new->ds_phys->ds_compressed_bytes; | |
2852 | *compp -= oldsnap->ds_phys->ds_compressed_bytes; | |
2853 | ||
2854 | *uncompp = 0; | |
2855 | *uncompp += new->ds_phys->ds_uncompressed_bytes; | |
2856 | *uncompp -= oldsnap->ds_phys->ds_uncompressed_bytes; | |
2857 | ||
330d06f9 MA |
2858 | snapobj = new->ds_object; |
2859 | while (snapobj != oldsnap->ds_object) { | |
2860 | dsl_dataset_t *snap; | |
2861 | uint64_t used, comp, uncomp; | |
2862 | ||
9ae529ec CS |
2863 | if (snapobj == new->ds_object) { |
2864 | snap = new; | |
2865 | } else { | |
2866 | err = dsl_dataset_hold_obj(dp, snapobj, FTAG, &snap); | |
2867 | if (err != 0) | |
2868 | break; | |
2869 | } | |
330d06f9 MA |
2870 | |
2871 | if (snap->ds_phys->ds_prev_snap_txg == | |
2872 | oldsnap->ds_phys->ds_creation_txg) { | |
2873 | /* | |
2874 | * The blocks in the deadlist can not be born after | |
2875 | * ds_prev_snap_txg, so get the whole deadlist space, | |
2876 | * which is more efficient (especially for old-format | |
2877 | * deadlists). Unfortunately the deadlist code | |
2878 | * doesn't have enough information to make this | |
2879 | * optimization itself. | |
2880 | */ | |
2881 | dsl_deadlist_space(&snap->ds_deadlist, | |
2882 | &used, &comp, &uncomp); | |
2883 | } else { | |
2884 | dsl_deadlist_space_range(&snap->ds_deadlist, | |
2885 | 0, oldsnap->ds_phys->ds_creation_txg, | |
2886 | &used, &comp, &uncomp); | |
2887 | } | |
2888 | *usedp += used; | |
2889 | *compp += comp; | |
2890 | *uncompp += uncomp; | |
2891 | ||
2892 | /* | |
2893 | * If we get to the beginning of the chain of snapshots | |
2894 | * (ds_prev_snap_obj == 0) before oldsnap, then oldsnap | |
2895 | * was not a snapshot of/before new. | |
2896 | */ | |
2897 | snapobj = snap->ds_phys->ds_prev_snap_obj; | |
9ae529ec CS |
2898 | if (snap != new) |
2899 | dsl_dataset_rele(snap, FTAG); | |
330d06f9 | 2900 | if (snapobj == 0) { |
2e528b49 | 2901 | err = SET_ERROR(EINVAL); |
330d06f9 MA |
2902 | break; |
2903 | } | |
2904 | ||
2905 | } | |
330d06f9 MA |
2906 | return (err); |
2907 | } | |
2908 | ||
2909 | /* | |
2910 | * Return (in *usedp) the amount of space that will be reclaimed if firstsnap, | |
2911 | * lastsnap, and all snapshots in between are deleted. | |
2912 | * | |
2913 | * blocks that would be freed [---------------------------] | |
2914 | * snapshots ---O-------O--------O-------O--------O | |
2915 | * firstsnap lastsnap | |
2916 | * | |
2917 | * This is the set of blocks that were born after the snap before firstsnap, | |
2918 | * (birth > firstsnap->prev_snap_txg) and died before the snap after the | |
2919 | * last snap (ie, is on lastsnap->ds_next->ds_deadlist or an earlier deadlist). | |
2920 | * We calculate this by iterating over the relevant deadlists (from the snap | |
2921 | * after lastsnap, backward to the snap after firstsnap), summing up the | |
2922 | * space on the deadlist that was born after the snap before firstsnap. | |
2923 | */ | |
2924 | int | |
2925 | dsl_dataset_space_wouldfree(dsl_dataset_t *firstsnap, | |
2926 | dsl_dataset_t *lastsnap, | |
2927 | uint64_t *usedp, uint64_t *compp, uint64_t *uncompp) | |
2928 | { | |
2929 | int err = 0; | |
2930 | uint64_t snapobj; | |
2931 | dsl_pool_t *dp = firstsnap->ds_dir->dd_pool; | |
2932 | ||
2933 | ASSERT(dsl_dataset_is_snapshot(firstsnap)); | |
2934 | ASSERT(dsl_dataset_is_snapshot(lastsnap)); | |
2935 | ||
2936 | /* | |
2937 | * Check that the snapshots are in the same dsl_dir, and firstsnap | |
2938 | * is before lastsnap. | |
2939 | */ | |
2940 | if (firstsnap->ds_dir != lastsnap->ds_dir || | |
2941 | firstsnap->ds_phys->ds_creation_txg > | |
2942 | lastsnap->ds_phys->ds_creation_txg) | |
2e528b49 | 2943 | return (SET_ERROR(EINVAL)); |
330d06f9 MA |
2944 | |
2945 | *usedp = *compp = *uncompp = 0; | |
2946 | ||
330d06f9 MA |
2947 | snapobj = lastsnap->ds_phys->ds_next_snap_obj; |
2948 | while (snapobj != firstsnap->ds_object) { | |
2949 | dsl_dataset_t *ds; | |
2950 | uint64_t used, comp, uncomp; | |
2951 | ||
2952 | err = dsl_dataset_hold_obj(dp, snapobj, FTAG, &ds); | |
2953 | if (err != 0) | |
2954 | break; | |
2955 | ||
2956 | dsl_deadlist_space_range(&ds->ds_deadlist, | |
2957 | firstsnap->ds_phys->ds_prev_snap_txg, UINT64_MAX, | |
2958 | &used, &comp, &uncomp); | |
2959 | *usedp += used; | |
2960 | *compp += comp; | |
2961 | *uncompp += uncomp; | |
2962 | ||
2963 | snapobj = ds->ds_phys->ds_prev_snap_obj; | |
2964 | ASSERT3U(snapobj, !=, 0); | |
2965 | dsl_dataset_rele(ds, FTAG); | |
2966 | } | |
330d06f9 MA |
2967 | return (err); |
2968 | } | |
2969 | ||
13fe0198 MA |
2970 | /* |
2971 | * Return TRUE if 'earlier' is an earlier snapshot in 'later's timeline. | |
2972 | * For example, they could both be snapshots of the same filesystem, and | |
2973 | * 'earlier' is before 'later'. Or 'earlier' could be the origin of | |
2974 | * 'later's filesystem. Or 'earlier' could be an older snapshot in the origin's | |
2975 | * filesystem. Or 'earlier' could be the origin's origin. | |
2976 | */ | |
2977 | boolean_t | |
2978 | dsl_dataset_is_before(dsl_dataset_t *later, dsl_dataset_t *earlier) | |
2979 | { | |
2980 | dsl_pool_t *dp = later->ds_dir->dd_pool; | |
2981 | int error; | |
2982 | boolean_t ret; | |
2983 | dsl_dataset_t *origin; | |
2984 | ||
2985 | ASSERT(dsl_pool_config_held(dp)); | |
2986 | ||
2987 | if (earlier->ds_phys->ds_creation_txg >= | |
2988 | later->ds_phys->ds_creation_txg) | |
2989 | return (B_FALSE); | |
2990 | ||
2991 | if (later->ds_dir == earlier->ds_dir) | |
2992 | return (B_TRUE); | |
2993 | if (!dsl_dir_is_clone(later->ds_dir)) | |
2994 | return (B_FALSE); | |
2995 | ||
2996 | if (later->ds_dir->dd_phys->dd_origin_obj == earlier->ds_object) | |
2997 | return (B_TRUE); | |
2998 | error = dsl_dataset_hold_obj(dp, | |
2999 | later->ds_dir->dd_phys->dd_origin_obj, FTAG, &origin); | |
3000 | if (error != 0) | |
3001 | return (B_FALSE); | |
3002 | ret = dsl_dataset_is_before(origin, earlier); | |
3003 | dsl_dataset_rele(origin, FTAG); | |
3004 | return (ret); | |
3005 | } | |
3006 | ||
c28b2279 BB |
3007 | #if defined(_KERNEL) && defined(HAVE_SPL) |
3008 | EXPORT_SYMBOL(dsl_dataset_hold); | |
3009 | EXPORT_SYMBOL(dsl_dataset_hold_obj); | |
3010 | EXPORT_SYMBOL(dsl_dataset_own); | |
3011 | EXPORT_SYMBOL(dsl_dataset_own_obj); | |
3012 | EXPORT_SYMBOL(dsl_dataset_name); | |
3013 | EXPORT_SYMBOL(dsl_dataset_rele); | |
3014 | EXPORT_SYMBOL(dsl_dataset_disown); | |
c28b2279 | 3015 | EXPORT_SYMBOL(dsl_dataset_tryown); |
c28b2279 BB |
3016 | EXPORT_SYMBOL(dsl_dataset_create_sync); |
3017 | EXPORT_SYMBOL(dsl_dataset_create_sync_dd); | |
c28b2279 BB |
3018 | EXPORT_SYMBOL(dsl_dataset_snapshot_check); |
3019 | EXPORT_SYMBOL(dsl_dataset_snapshot_sync); | |
c28b2279 | 3020 | EXPORT_SYMBOL(dsl_dataset_promote); |
c28b2279 BB |
3021 | EXPORT_SYMBOL(dsl_dataset_user_hold); |
3022 | EXPORT_SYMBOL(dsl_dataset_user_release); | |
c28b2279 BB |
3023 | EXPORT_SYMBOL(dsl_dataset_get_holds); |
3024 | EXPORT_SYMBOL(dsl_dataset_get_blkptr); | |
3025 | EXPORT_SYMBOL(dsl_dataset_set_blkptr); | |
3026 | EXPORT_SYMBOL(dsl_dataset_get_spa); | |
19580676 | 3027 | EXPORT_SYMBOL(dsl_dataset_modified_since_snap); |
330d06f9 MA |
3028 | EXPORT_SYMBOL(dsl_dataset_space_written); |
3029 | EXPORT_SYMBOL(dsl_dataset_space_wouldfree); | |
c28b2279 BB |
3030 | EXPORT_SYMBOL(dsl_dataset_sync); |
3031 | EXPORT_SYMBOL(dsl_dataset_block_born); | |
3032 | EXPORT_SYMBOL(dsl_dataset_block_kill); | |
3033 | EXPORT_SYMBOL(dsl_dataset_block_freeable); | |
3034 | EXPORT_SYMBOL(dsl_dataset_prev_snap_txg); | |
3035 | EXPORT_SYMBOL(dsl_dataset_dirty); | |
3036 | EXPORT_SYMBOL(dsl_dataset_stats); | |
3037 | EXPORT_SYMBOL(dsl_dataset_fast_stat); | |
3038 | EXPORT_SYMBOL(dsl_dataset_space); | |
3039 | EXPORT_SYMBOL(dsl_dataset_fsid_guid); | |
3040 | EXPORT_SYMBOL(dsl_dsobj_to_dsname); | |
3041 | EXPORT_SYMBOL(dsl_dataset_check_quota); | |
13fe0198 MA |
3042 | EXPORT_SYMBOL(dsl_dataset_clone_swap_check_impl); |
3043 | EXPORT_SYMBOL(dsl_dataset_clone_swap_sync_impl); | |
c28b2279 | 3044 | #endif |