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.
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.
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]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
25 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
26 * Copyright (c) 2014 RackTop Systems.
27 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
28 * Copyright (c) 2016 Actifio, Inc. All rights reserved.
29 * Copyright 2016, OmniTI Computer Consulting, Inc. All rights reserved.
30 * Copyright 2017 Nexenta Systems, Inc.
33 #include <sys/dmu_objset.h>
34 #include <sys/dsl_dataset.h>
35 #include <sys/dsl_dir.h>
36 #include <sys/dsl_prop.h>
37 #include <sys/dsl_synctask.h>
38 #include <sys/dmu_traverse.h>
39 #include <sys/dmu_impl.h>
40 #include <sys/dmu_tx.h>
44 #include <sys/zfeature.h>
45 #include <sys/unique.h>
46 #include <sys/zfs_context.h>
47 #include <sys/zfs_ioctl.h>
49 #include <sys/zfs_znode.h>
50 #include <sys/zfs_onexit.h>
52 #include <sys/dsl_scan.h>
53 #include <sys/dsl_deadlist.h>
54 #include <sys/dsl_destroy.h>
55 #include <sys/dsl_userhold.h>
56 #include <sys/dsl_bookmark.h>
57 #include <sys/policy.h>
58 #include <sys/dmu_send.h>
59 #include <sys/zio_compress.h>
60 #include <zfs_fletcher.h>
61 #include <sys/zio_checksum.h>
64 * The SPA supports block sizes up to 16MB. However, very large blocks
65 * can have an impact on i/o latency (e.g. tying up a spinning disk for
66 * ~300ms), and also potentially on the memory allocator. Therefore,
67 * we do not allow the recordsize to be set larger than zfs_max_recordsize
68 * (default 1MB). Larger blocks can be created by changing this tunable,
69 * and pools with larger blocks can always be imported and used, regardless
72 int zfs_max_recordsize
= 1 * 1024 * 1024;
74 #define SWITCH64(x, y) \
76 uint64_t __tmp = (x); \
81 #define DS_REF_MAX (1ULL << 62)
83 extern inline dsl_dataset_phys_t
*dsl_dataset_phys(dsl_dataset_t
*ds
);
85 extern int spa_asize_inflation
;
87 static zil_header_t zero_zil
;
90 * Figure out how much of this delta should be propagated to the dsl_dir
91 * layer. If there's a refreservation, that space has already been
92 * partially accounted for in our ancestors.
95 parent_delta(dsl_dataset_t
*ds
, int64_t delta
)
97 dsl_dataset_phys_t
*ds_phys
;
98 uint64_t old_bytes
, new_bytes
;
100 if (ds
->ds_reserved
== 0)
103 ds_phys
= dsl_dataset_phys(ds
);
104 old_bytes
= MAX(ds_phys
->ds_unique_bytes
, ds
->ds_reserved
);
105 new_bytes
= MAX(ds_phys
->ds_unique_bytes
+ delta
, ds
->ds_reserved
);
107 ASSERT3U(ABS((int64_t)(new_bytes
- old_bytes
)), <=, ABS(delta
));
108 return (new_bytes
- old_bytes
);
112 dsl_dataset_block_born(dsl_dataset_t
*ds
, const blkptr_t
*bp
, dmu_tx_t
*tx
)
114 int used
, compressed
, uncompressed
;
118 used
= bp_get_dsize_sync(tx
->tx_pool
->dp_spa
, bp
);
119 compressed
= BP_GET_PSIZE(bp
);
120 uncompressed
= BP_GET_UCSIZE(bp
);
122 dprintf_bp(bp
, "ds=%p", ds
);
124 ASSERT(dmu_tx_is_syncing(tx
));
125 /* It could have been compressed away to nothing */
128 ASSERT(BP_GET_TYPE(bp
) != DMU_OT_NONE
);
129 ASSERT(DMU_OT_IS_VALID(BP_GET_TYPE(bp
)));
131 dsl_pool_mos_diduse_space(tx
->tx_pool
,
132 used
, compressed
, uncompressed
);
136 ASSERT3U(bp
->blk_birth
, >, dsl_dataset_phys(ds
)->ds_prev_snap_txg
);
137 dmu_buf_will_dirty(ds
->ds_dbuf
, tx
);
138 mutex_enter(&ds
->ds_lock
);
139 delta
= parent_delta(ds
, used
);
140 dsl_dataset_phys(ds
)->ds_referenced_bytes
+= used
;
141 dsl_dataset_phys(ds
)->ds_compressed_bytes
+= compressed
;
142 dsl_dataset_phys(ds
)->ds_uncompressed_bytes
+= uncompressed
;
143 dsl_dataset_phys(ds
)->ds_unique_bytes
+= used
;
145 if (BP_GET_LSIZE(bp
) > SPA_OLD_MAXBLOCKSIZE
) {
146 ds
->ds_feature_activation_needed
[SPA_FEATURE_LARGE_BLOCKS
] =
150 f
= zio_checksum_to_feature(BP_GET_CHECKSUM(bp
));
151 if (f
!= SPA_FEATURE_NONE
)
152 ds
->ds_feature_activation_needed
[f
] = B_TRUE
;
154 mutex_exit(&ds
->ds_lock
);
155 dsl_dir_diduse_space(ds
->ds_dir
, DD_USED_HEAD
, delta
,
156 compressed
, uncompressed
, tx
);
157 dsl_dir_transfer_space(ds
->ds_dir
, used
- delta
,
158 DD_USED_REFRSRV
, DD_USED_HEAD
, tx
);
162 dsl_dataset_block_kill(dsl_dataset_t
*ds
, const blkptr_t
*bp
, dmu_tx_t
*tx
,
165 int used
= bp_get_dsize_sync(tx
->tx_pool
->dp_spa
, bp
);
166 int compressed
= BP_GET_PSIZE(bp
);
167 int uncompressed
= BP_GET_UCSIZE(bp
);
172 ASSERT(dmu_tx_is_syncing(tx
));
173 ASSERT(bp
->blk_birth
<= tx
->tx_txg
);
176 dsl_free(tx
->tx_pool
, tx
->tx_txg
, bp
);
177 dsl_pool_mos_diduse_space(tx
->tx_pool
,
178 -used
, -compressed
, -uncompressed
);
181 ASSERT3P(tx
->tx_pool
, ==, ds
->ds_dir
->dd_pool
);
183 ASSERT(!ds
->ds_is_snapshot
);
184 dmu_buf_will_dirty(ds
->ds_dbuf
, tx
);
186 if (bp
->blk_birth
> dsl_dataset_phys(ds
)->ds_prev_snap_txg
) {
189 dprintf_bp(bp
, "freeing ds=%llu", ds
->ds_object
);
190 dsl_free(tx
->tx_pool
, tx
->tx_txg
, bp
);
192 mutex_enter(&ds
->ds_lock
);
193 ASSERT(dsl_dataset_phys(ds
)->ds_unique_bytes
>= used
||
194 !DS_UNIQUE_IS_ACCURATE(ds
));
195 delta
= parent_delta(ds
, -used
);
196 dsl_dataset_phys(ds
)->ds_unique_bytes
-= used
;
197 mutex_exit(&ds
->ds_lock
);
198 dsl_dir_diduse_space(ds
->ds_dir
, DD_USED_HEAD
,
199 delta
, -compressed
, -uncompressed
, tx
);
200 dsl_dir_transfer_space(ds
->ds_dir
, -used
- delta
,
201 DD_USED_REFRSRV
, DD_USED_HEAD
, tx
);
203 dprintf_bp(bp
, "putting on dead list: %s", "");
206 * We are here as part of zio's write done callback,
207 * which means we're a zio interrupt thread. We can't
208 * call dsl_deadlist_insert() now because it may block
209 * waiting for I/O. Instead, put bp on the deferred
210 * queue and let dsl_pool_sync() finish the job.
212 bplist_append(&ds
->ds_pending_deadlist
, bp
);
214 dsl_deadlist_insert(&ds
->ds_deadlist
, bp
, tx
);
216 ASSERT3U(ds
->ds_prev
->ds_object
, ==,
217 dsl_dataset_phys(ds
)->ds_prev_snap_obj
);
218 ASSERT(dsl_dataset_phys(ds
->ds_prev
)->ds_num_children
> 0);
219 /* if (bp->blk_birth > prev prev snap txg) prev unique += bs */
220 if (dsl_dataset_phys(ds
->ds_prev
)->ds_next_snap_obj
==
221 ds
->ds_object
&& bp
->blk_birth
>
222 dsl_dataset_phys(ds
->ds_prev
)->ds_prev_snap_txg
) {
223 dmu_buf_will_dirty(ds
->ds_prev
->ds_dbuf
, tx
);
224 mutex_enter(&ds
->ds_prev
->ds_lock
);
225 dsl_dataset_phys(ds
->ds_prev
)->ds_unique_bytes
+= used
;
226 mutex_exit(&ds
->ds_prev
->ds_lock
);
228 if (bp
->blk_birth
> ds
->ds_dir
->dd_origin_txg
) {
229 dsl_dir_transfer_space(ds
->ds_dir
, used
,
230 DD_USED_HEAD
, DD_USED_SNAP
, tx
);
233 mutex_enter(&ds
->ds_lock
);
234 ASSERT3U(dsl_dataset_phys(ds
)->ds_referenced_bytes
, >=, used
);
235 dsl_dataset_phys(ds
)->ds_referenced_bytes
-= used
;
236 ASSERT3U(dsl_dataset_phys(ds
)->ds_compressed_bytes
, >=, compressed
);
237 dsl_dataset_phys(ds
)->ds_compressed_bytes
-= compressed
;
238 ASSERT3U(dsl_dataset_phys(ds
)->ds_uncompressed_bytes
, >=, uncompressed
);
239 dsl_dataset_phys(ds
)->ds_uncompressed_bytes
-= uncompressed
;
240 mutex_exit(&ds
->ds_lock
);
246 * We have to release the fsid syncronously or we risk that a subsequent
247 * mount of the same dataset will fail to unique_insert the fsid. This
248 * failure would manifest itself as the fsid of this dataset changing
249 * between mounts which makes NFS clients quite unhappy.
252 dsl_dataset_evict_sync(void *dbu
)
254 dsl_dataset_t
*ds
= dbu
;
256 ASSERT(ds
->ds_owner
== NULL
);
258 unique_remove(ds
->ds_fsid_guid
);
262 dsl_dataset_evict_async(void *dbu
)
264 dsl_dataset_t
*ds
= dbu
;
266 ASSERT(ds
->ds_owner
== NULL
);
270 if (ds
->ds_objset
!= NULL
)
271 dmu_objset_evict(ds
->ds_objset
);
274 dsl_dataset_rele(ds
->ds_prev
, ds
);
278 bplist_destroy(&ds
->ds_pending_deadlist
);
279 if (ds
->ds_deadlist
.dl_os
!= NULL
)
280 dsl_deadlist_close(&ds
->ds_deadlist
);
282 dsl_dir_async_rele(ds
->ds_dir
, ds
);
284 ASSERT(!list_link_active(&ds
->ds_synced_link
));
286 list_destroy(&ds
->ds_prop_cbs
);
287 mutex_destroy(&ds
->ds_lock
);
288 mutex_destroy(&ds
->ds_opening_lock
);
289 mutex_destroy(&ds
->ds_sendstream_lock
);
290 refcount_destroy(&ds
->ds_longholds
);
291 rrw_destroy(&ds
->ds_bp_rwlock
);
293 kmem_free(ds
, sizeof (dsl_dataset_t
));
297 dsl_dataset_get_snapname(dsl_dataset_t
*ds
)
299 dsl_dataset_phys_t
*headphys
;
302 dsl_pool_t
*dp
= ds
->ds_dir
->dd_pool
;
303 objset_t
*mos
= dp
->dp_meta_objset
;
305 if (ds
->ds_snapname
[0])
307 if (dsl_dataset_phys(ds
)->ds_next_snap_obj
== 0)
310 err
= dmu_bonus_hold(mos
, dsl_dir_phys(ds
->ds_dir
)->dd_head_dataset_obj
,
314 headphys
= headdbuf
->db_data
;
315 err
= zap_value_search(dp
->dp_meta_objset
,
316 headphys
->ds_snapnames_zapobj
, ds
->ds_object
, 0, ds
->ds_snapname
);
317 if (err
!= 0 && zfs_recover
== B_TRUE
) {
319 (void) snprintf(ds
->ds_snapname
, sizeof (ds
->ds_snapname
),
320 "SNAPOBJ=%llu-ERR=%d",
321 (unsigned long long)ds
->ds_object
, err
);
323 dmu_buf_rele(headdbuf
, FTAG
);
328 dsl_dataset_snap_lookup(dsl_dataset_t
*ds
, const char *name
, uint64_t *value
)
330 objset_t
*mos
= ds
->ds_dir
->dd_pool
->dp_meta_objset
;
331 uint64_t snapobj
= dsl_dataset_phys(ds
)->ds_snapnames_zapobj
;
335 if (dsl_dataset_phys(ds
)->ds_flags
& DS_FLAG_CI_DATASET
)
338 err
= zap_lookup_norm(mos
, snapobj
, name
, 8, 1,
339 value
, mt
, NULL
, 0, NULL
);
340 if (err
== ENOTSUP
&& (mt
& MT_NORMALIZE
))
341 err
= zap_lookup(mos
, snapobj
, name
, 8, 1, value
);
346 dsl_dataset_snap_remove(dsl_dataset_t
*ds
, const char *name
, dmu_tx_t
*tx
,
349 objset_t
*mos
= ds
->ds_dir
->dd_pool
->dp_meta_objset
;
350 uint64_t snapobj
= dsl_dataset_phys(ds
)->ds_snapnames_zapobj
;
354 dsl_dir_snap_cmtime_update(ds
->ds_dir
);
356 if (dsl_dataset_phys(ds
)->ds_flags
& DS_FLAG_CI_DATASET
)
359 err
= zap_remove_norm(mos
, snapobj
, name
, mt
, tx
);
360 if (err
== ENOTSUP
&& (mt
& MT_NORMALIZE
))
361 err
= zap_remove(mos
, snapobj
, name
, tx
);
363 if (err
== 0 && adj_cnt
)
364 dsl_fs_ss_count_adjust(ds
->ds_dir
, -1,
365 DD_FIELD_SNAPSHOT_COUNT
, tx
);
371 dsl_dataset_try_add_ref(dsl_pool_t
*dp
, dsl_dataset_t
*ds
, void *tag
)
373 dmu_buf_t
*dbuf
= ds
->ds_dbuf
;
374 boolean_t result
= B_FALSE
;
376 if (dbuf
!= NULL
&& dmu_buf_try_add_ref(dbuf
, dp
->dp_meta_objset
,
377 ds
->ds_object
, DMU_BONUS_BLKID
, tag
)) {
379 if (ds
== dmu_buf_get_user(dbuf
))
382 dmu_buf_rele(dbuf
, tag
);
389 dsl_dataset_hold_obj(dsl_pool_t
*dp
, uint64_t dsobj
, void *tag
,
392 objset_t
*mos
= dp
->dp_meta_objset
;
396 dmu_object_info_t doi
;
398 ASSERT(dsl_pool_config_held(dp
));
400 err
= dmu_bonus_hold(mos
, dsobj
, tag
, &dbuf
);
404 /* Make sure dsobj has the correct object type. */
405 dmu_object_info_from_db(dbuf
, &doi
);
406 if (doi
.doi_bonus_type
!= DMU_OT_DSL_DATASET
) {
407 dmu_buf_rele(dbuf
, tag
);
408 return (SET_ERROR(EINVAL
));
411 ds
= dmu_buf_get_user(dbuf
);
413 dsl_dataset_t
*winner
= NULL
;
415 ds
= kmem_zalloc(sizeof (dsl_dataset_t
), KM_SLEEP
);
417 ds
->ds_object
= dsobj
;
418 ds
->ds_is_snapshot
= dsl_dataset_phys(ds
)->ds_num_children
!= 0;
419 list_link_init(&ds
->ds_synced_link
);
421 mutex_init(&ds
->ds_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
422 mutex_init(&ds
->ds_opening_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
423 mutex_init(&ds
->ds_sendstream_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
424 rrw_init(&ds
->ds_bp_rwlock
, B_FALSE
);
425 refcount_create(&ds
->ds_longholds
);
427 bplist_create(&ds
->ds_pending_deadlist
);
428 dsl_deadlist_open(&ds
->ds_deadlist
,
429 mos
, dsl_dataset_phys(ds
)->ds_deadlist_obj
);
431 list_create(&ds
->ds_sendstreams
, sizeof (dmu_sendarg_t
),
432 offsetof(dmu_sendarg_t
, dsa_link
));
434 list_create(&ds
->ds_prop_cbs
, sizeof (dsl_prop_cb_record_t
),
435 offsetof(dsl_prop_cb_record_t
, cbr_ds_node
));
437 if (doi
.doi_type
== DMU_OTN_ZAP_METADATA
) {
440 for (f
= 0; f
< SPA_FEATURES
; f
++) {
441 if (!(spa_feature_table
[f
].fi_flags
&
442 ZFEATURE_FLAG_PER_DATASET
))
444 err
= zap_contains(mos
, dsobj
,
445 spa_feature_table
[f
].fi_guid
);
447 ds
->ds_feature_inuse
[f
] = B_TRUE
;
449 ASSERT3U(err
, ==, ENOENT
);
455 err
= dsl_dir_hold_obj(dp
,
456 dsl_dataset_phys(ds
)->ds_dir_obj
, NULL
, ds
, &ds
->ds_dir
);
458 mutex_destroy(&ds
->ds_lock
);
459 mutex_destroy(&ds
->ds_opening_lock
);
460 mutex_destroy(&ds
->ds_sendstream_lock
);
461 refcount_destroy(&ds
->ds_longholds
);
462 bplist_destroy(&ds
->ds_pending_deadlist
);
463 dsl_deadlist_close(&ds
->ds_deadlist
);
464 kmem_free(ds
, sizeof (dsl_dataset_t
));
465 dmu_buf_rele(dbuf
, tag
);
469 if (!ds
->ds_is_snapshot
) {
470 ds
->ds_snapname
[0] = '\0';
471 if (dsl_dataset_phys(ds
)->ds_prev_snap_obj
!= 0) {
472 err
= dsl_dataset_hold_obj(dp
,
473 dsl_dataset_phys(ds
)->ds_prev_snap_obj
,
476 if (doi
.doi_type
== DMU_OTN_ZAP_METADATA
) {
477 int zaperr
= zap_lookup(mos
, ds
->ds_object
,
478 DS_FIELD_BOOKMARK_NAMES
,
479 sizeof (ds
->ds_bookmarks
), 1,
481 if (zaperr
!= ENOENT
)
485 if (zfs_flags
& ZFS_DEBUG_SNAPNAMES
)
486 err
= dsl_dataset_get_snapname(ds
);
488 dsl_dataset_phys(ds
)->ds_userrefs_obj
!= 0) {
490 ds
->ds_dir
->dd_pool
->dp_meta_objset
,
491 dsl_dataset_phys(ds
)->ds_userrefs_obj
,
496 if (err
== 0 && !ds
->ds_is_snapshot
) {
497 err
= dsl_prop_get_int_ds(ds
,
498 zfs_prop_to_name(ZFS_PROP_REFRESERVATION
),
501 err
= dsl_prop_get_int_ds(ds
,
502 zfs_prop_to_name(ZFS_PROP_REFQUOTA
),
506 ds
->ds_reserved
= ds
->ds_quota
= 0;
509 dmu_buf_init_user(&ds
->ds_dbu
, dsl_dataset_evict_sync
,
510 dsl_dataset_evict_async
, &ds
->ds_dbuf
);
512 winner
= dmu_buf_set_user_ie(dbuf
, &ds
->ds_dbu
);
514 if (err
!= 0 || winner
!= NULL
) {
515 bplist_destroy(&ds
->ds_pending_deadlist
);
516 dsl_deadlist_close(&ds
->ds_deadlist
);
518 dsl_dataset_rele(ds
->ds_prev
, ds
);
519 dsl_dir_rele(ds
->ds_dir
, ds
);
520 mutex_destroy(&ds
->ds_lock
);
521 mutex_destroy(&ds
->ds_opening_lock
);
522 mutex_destroy(&ds
->ds_sendstream_lock
);
523 refcount_destroy(&ds
->ds_longholds
);
524 kmem_free(ds
, sizeof (dsl_dataset_t
));
526 dmu_buf_rele(dbuf
, tag
);
532 unique_insert(dsl_dataset_phys(ds
)->ds_fsid_guid
);
533 if (ds
->ds_fsid_guid
!=
534 dsl_dataset_phys(ds
)->ds_fsid_guid
) {
535 zfs_dbgmsg("ds_fsid_guid changed from "
536 "%llx to %llx for pool %s dataset id %llu",
538 dsl_dataset_phys(ds
)->ds_fsid_guid
,
539 (long long)ds
->ds_fsid_guid
,
540 spa_name(dp
->dp_spa
),
545 ASSERT3P(ds
->ds_dbuf
, ==, dbuf
);
546 ASSERT3P(dsl_dataset_phys(ds
), ==, dbuf
->db_data
);
547 ASSERT(dsl_dataset_phys(ds
)->ds_prev_snap_obj
!= 0 ||
548 spa_version(dp
->dp_spa
) < SPA_VERSION_ORIGIN
||
549 dp
->dp_origin_snap
== NULL
|| ds
== dp
->dp_origin_snap
);
555 dsl_dataset_hold(dsl_pool_t
*dp
, const char *name
,
556 void *tag
, dsl_dataset_t
**dsp
)
559 const char *snapname
;
564 err
= dsl_dir_hold(dp
, name
, FTAG
, &dd
, &snapname
);
568 ASSERT(dsl_pool_config_held(dp
));
569 obj
= dsl_dir_phys(dd
)->dd_head_dataset_obj
;
571 err
= dsl_dataset_hold_obj(dp
, obj
, tag
, &ds
);
573 err
= SET_ERROR(ENOENT
);
575 /* we may be looking for a snapshot */
576 if (err
== 0 && snapname
!= NULL
) {
577 dsl_dataset_t
*snap_ds
;
579 if (*snapname
++ != '@') {
580 dsl_dataset_rele(ds
, tag
);
581 dsl_dir_rele(dd
, FTAG
);
582 return (SET_ERROR(ENOENT
));
585 dprintf("looking for snapshot '%s'\n", snapname
);
586 err
= dsl_dataset_snap_lookup(ds
, snapname
, &obj
);
588 err
= dsl_dataset_hold_obj(dp
, obj
, tag
, &snap_ds
);
589 dsl_dataset_rele(ds
, tag
);
592 mutex_enter(&snap_ds
->ds_lock
);
593 if (snap_ds
->ds_snapname
[0] == 0)
594 (void) strlcpy(snap_ds
->ds_snapname
, snapname
,
595 sizeof (snap_ds
->ds_snapname
));
596 mutex_exit(&snap_ds
->ds_lock
);
602 dsl_dir_rele(dd
, FTAG
);
607 dsl_dataset_own_obj(dsl_pool_t
*dp
, uint64_t dsobj
,
608 void *tag
, dsl_dataset_t
**dsp
)
610 int err
= dsl_dataset_hold_obj(dp
, dsobj
, tag
, dsp
);
613 if (!dsl_dataset_tryown(*dsp
, tag
)) {
614 dsl_dataset_rele(*dsp
, tag
);
616 return (SET_ERROR(EBUSY
));
622 dsl_dataset_own(dsl_pool_t
*dp
, const char *name
,
623 void *tag
, dsl_dataset_t
**dsp
)
625 int err
= dsl_dataset_hold(dp
, name
, tag
, dsp
);
628 if (!dsl_dataset_tryown(*dsp
, tag
)) {
629 dsl_dataset_rele(*dsp
, tag
);
630 return (SET_ERROR(EBUSY
));
636 * See the comment above dsl_pool_hold() for details. In summary, a long
637 * hold is used to prevent destruction of a dataset while the pool hold
638 * is dropped, allowing other concurrent operations (e.g. spa_sync()).
640 * The dataset and pool must be held when this function is called. After it
641 * is called, the pool hold may be released while the dataset is still held
645 dsl_dataset_long_hold(dsl_dataset_t
*ds
, void *tag
)
647 ASSERT(dsl_pool_config_held(ds
->ds_dir
->dd_pool
));
648 (void) refcount_add(&ds
->ds_longholds
, tag
);
652 dsl_dataset_long_rele(dsl_dataset_t
*ds
, void *tag
)
654 (void) refcount_remove(&ds
->ds_longholds
, tag
);
657 /* Return B_TRUE if there are any long holds on this dataset. */
659 dsl_dataset_long_held(dsl_dataset_t
*ds
)
661 return (!refcount_is_zero(&ds
->ds_longholds
));
665 dsl_dataset_name(dsl_dataset_t
*ds
, char *name
)
668 (void) strcpy(name
, "mos");
670 dsl_dir_name(ds
->ds_dir
, name
);
671 VERIFY0(dsl_dataset_get_snapname(ds
));
672 if (ds
->ds_snapname
[0]) {
673 VERIFY3U(strlcat(name
, "@", ZFS_MAX_DATASET_NAME_LEN
),
674 <, ZFS_MAX_DATASET_NAME_LEN
);
676 * We use a "recursive" mutex so that we
677 * can call dprintf_ds() with ds_lock held.
679 if (!MUTEX_HELD(&ds
->ds_lock
)) {
680 mutex_enter(&ds
->ds_lock
);
681 VERIFY3U(strlcat(name
, ds
->ds_snapname
,
682 ZFS_MAX_DATASET_NAME_LEN
), <,
683 ZFS_MAX_DATASET_NAME_LEN
);
684 mutex_exit(&ds
->ds_lock
);
686 VERIFY3U(strlcat(name
, ds
->ds_snapname
,
687 ZFS_MAX_DATASET_NAME_LEN
), <,
688 ZFS_MAX_DATASET_NAME_LEN
);
695 dsl_dataset_namelen(dsl_dataset_t
*ds
)
698 VERIFY0(dsl_dataset_get_snapname(ds
));
699 mutex_enter(&ds
->ds_lock
);
700 len
= strlen(ds
->ds_snapname
);
701 /* add '@' if ds is a snap */
704 len
+= dsl_dir_namelen(ds
->ds_dir
);
705 mutex_exit(&ds
->ds_lock
);
710 dsl_dataset_rele(dsl_dataset_t
*ds
, void *tag
)
712 dmu_buf_rele(ds
->ds_dbuf
, tag
);
716 dsl_dataset_disown(dsl_dataset_t
*ds
, void *tag
)
718 ASSERT3P(ds
->ds_owner
, ==, tag
);
719 ASSERT(ds
->ds_dbuf
!= NULL
);
721 mutex_enter(&ds
->ds_lock
);
723 mutex_exit(&ds
->ds_lock
);
724 dsl_dataset_long_rele(ds
, tag
);
725 dsl_dataset_rele(ds
, tag
);
729 dsl_dataset_tryown(dsl_dataset_t
*ds
, void *tag
)
731 boolean_t gotit
= FALSE
;
733 ASSERT(dsl_pool_config_held(ds
->ds_dir
->dd_pool
));
734 mutex_enter(&ds
->ds_lock
);
735 if (ds
->ds_owner
== NULL
&& !DS_IS_INCONSISTENT(ds
)) {
737 dsl_dataset_long_hold(ds
, tag
);
740 mutex_exit(&ds
->ds_lock
);
745 dsl_dataset_has_owner(dsl_dataset_t
*ds
)
748 mutex_enter(&ds
->ds_lock
);
749 rv
= (ds
->ds_owner
!= NULL
);
750 mutex_exit(&ds
->ds_lock
);
755 dsl_dataset_activate_feature(uint64_t dsobj
, spa_feature_t f
, dmu_tx_t
*tx
)
757 spa_t
*spa
= dmu_tx_pool(tx
)->dp_spa
;
758 objset_t
*mos
= dmu_tx_pool(tx
)->dp_meta_objset
;
761 VERIFY(spa_feature_table
[f
].fi_flags
& ZFEATURE_FLAG_PER_DATASET
);
763 spa_feature_incr(spa
, f
, tx
);
764 dmu_object_zapify(mos
, dsobj
, DMU_OT_DSL_DATASET
, tx
);
766 VERIFY0(zap_add(mos
, dsobj
, spa_feature_table
[f
].fi_guid
,
767 sizeof (zero
), 1, &zero
, tx
));
771 dsl_dataset_deactivate_feature(uint64_t dsobj
, spa_feature_t f
, dmu_tx_t
*tx
)
773 spa_t
*spa
= dmu_tx_pool(tx
)->dp_spa
;
774 objset_t
*mos
= dmu_tx_pool(tx
)->dp_meta_objset
;
776 VERIFY(spa_feature_table
[f
].fi_flags
& ZFEATURE_FLAG_PER_DATASET
);
778 VERIFY0(zap_remove(mos
, dsobj
, spa_feature_table
[f
].fi_guid
, tx
));
779 spa_feature_decr(spa
, f
, tx
);
783 dsl_dataset_create_sync_dd(dsl_dir_t
*dd
, dsl_dataset_t
*origin
,
784 uint64_t flags
, dmu_tx_t
*tx
)
786 dsl_pool_t
*dp
= dd
->dd_pool
;
788 dsl_dataset_phys_t
*dsphys
;
790 objset_t
*mos
= dp
->dp_meta_objset
;
793 origin
= dp
->dp_origin_snap
;
795 ASSERT(origin
== NULL
|| origin
->ds_dir
->dd_pool
== dp
);
796 ASSERT(origin
== NULL
|| dsl_dataset_phys(origin
)->ds_num_children
> 0);
797 ASSERT(dmu_tx_is_syncing(tx
));
798 ASSERT(dsl_dir_phys(dd
)->dd_head_dataset_obj
== 0);
800 dsobj
= dmu_object_alloc(mos
, DMU_OT_DSL_DATASET
, 0,
801 DMU_OT_DSL_DATASET
, sizeof (dsl_dataset_phys_t
), tx
);
802 VERIFY0(dmu_bonus_hold(mos
, dsobj
, FTAG
, &dbuf
));
803 dmu_buf_will_dirty(dbuf
, tx
);
804 dsphys
= dbuf
->db_data
;
805 bzero(dsphys
, sizeof (dsl_dataset_phys_t
));
806 dsphys
->ds_dir_obj
= dd
->dd_object
;
807 dsphys
->ds_flags
= flags
;
808 dsphys
->ds_fsid_guid
= unique_create();
809 (void) random_get_pseudo_bytes((void*)&dsphys
->ds_guid
,
810 sizeof (dsphys
->ds_guid
));
811 dsphys
->ds_snapnames_zapobj
=
812 zap_create_norm(mos
, U8_TEXTPREP_TOUPPER
, DMU_OT_DSL_DS_SNAP_MAP
,
814 dsphys
->ds_creation_time
= gethrestime_sec();
815 dsphys
->ds_creation_txg
= tx
->tx_txg
== TXG_INITIAL
? 1 : tx
->tx_txg
;
817 if (origin
== NULL
) {
818 dsphys
->ds_deadlist_obj
= dsl_deadlist_alloc(mos
, tx
);
821 dsl_dataset_t
*ohds
; /* head of the origin snapshot */
823 dsphys
->ds_prev_snap_obj
= origin
->ds_object
;
824 dsphys
->ds_prev_snap_txg
=
825 dsl_dataset_phys(origin
)->ds_creation_txg
;
826 dsphys
->ds_referenced_bytes
=
827 dsl_dataset_phys(origin
)->ds_referenced_bytes
;
828 dsphys
->ds_compressed_bytes
=
829 dsl_dataset_phys(origin
)->ds_compressed_bytes
;
830 dsphys
->ds_uncompressed_bytes
=
831 dsl_dataset_phys(origin
)->ds_uncompressed_bytes
;
832 rrw_enter(&origin
->ds_bp_rwlock
, RW_READER
, FTAG
);
833 dsphys
->ds_bp
= dsl_dataset_phys(origin
)->ds_bp
;
834 rrw_exit(&origin
->ds_bp_rwlock
, FTAG
);
837 * Inherit flags that describe the dataset's contents
838 * (INCONSISTENT) or properties (Case Insensitive).
840 dsphys
->ds_flags
|= dsl_dataset_phys(origin
)->ds_flags
&
841 (DS_FLAG_INCONSISTENT
| DS_FLAG_CI_DATASET
);
843 for (f
= 0; f
< SPA_FEATURES
; f
++) {
844 if (origin
->ds_feature_inuse
[f
])
845 dsl_dataset_activate_feature(dsobj
, f
, tx
);
848 dmu_buf_will_dirty(origin
->ds_dbuf
, tx
);
849 dsl_dataset_phys(origin
)->ds_num_children
++;
851 VERIFY0(dsl_dataset_hold_obj(dp
,
852 dsl_dir_phys(origin
->ds_dir
)->dd_head_dataset_obj
,
854 dsphys
->ds_deadlist_obj
= dsl_deadlist_clone(&ohds
->ds_deadlist
,
855 dsphys
->ds_prev_snap_txg
, dsphys
->ds_prev_snap_obj
, tx
);
856 dsl_dataset_rele(ohds
, FTAG
);
858 if (spa_version(dp
->dp_spa
) >= SPA_VERSION_NEXT_CLONES
) {
859 if (dsl_dataset_phys(origin
)->ds_next_clones_obj
== 0) {
860 dsl_dataset_phys(origin
)->ds_next_clones_obj
=
862 DMU_OT_NEXT_CLONES
, DMU_OT_NONE
, 0, tx
);
864 VERIFY0(zap_add_int(mos
,
865 dsl_dataset_phys(origin
)->ds_next_clones_obj
,
869 dmu_buf_will_dirty(dd
->dd_dbuf
, tx
);
870 dsl_dir_phys(dd
)->dd_origin_obj
= origin
->ds_object
;
871 if (spa_version(dp
->dp_spa
) >= SPA_VERSION_DIR_CLONES
) {
872 if (dsl_dir_phys(origin
->ds_dir
)->dd_clones
== 0) {
873 dmu_buf_will_dirty(origin
->ds_dir
->dd_dbuf
, tx
);
874 dsl_dir_phys(origin
->ds_dir
)->dd_clones
=
876 DMU_OT_DSL_CLONES
, DMU_OT_NONE
, 0, tx
);
878 VERIFY0(zap_add_int(mos
,
879 dsl_dir_phys(origin
->ds_dir
)->dd_clones
,
884 if (spa_version(dp
->dp_spa
) >= SPA_VERSION_UNIQUE_ACCURATE
)
885 dsphys
->ds_flags
|= DS_FLAG_UNIQUE_ACCURATE
;
887 dmu_buf_rele(dbuf
, FTAG
);
889 dmu_buf_will_dirty(dd
->dd_dbuf
, tx
);
890 dsl_dir_phys(dd
)->dd_head_dataset_obj
= dsobj
;
896 dsl_dataset_zero_zil(dsl_dataset_t
*ds
, dmu_tx_t
*tx
)
900 VERIFY0(dmu_objset_from_ds(ds
, &os
));
901 if (bcmp(&os
->os_zil_header
, &zero_zil
, sizeof (zero_zil
)) != 0) {
902 dsl_pool_t
*dp
= ds
->ds_dir
->dd_pool
;
905 bzero(&os
->os_zil_header
, sizeof (os
->os_zil_header
));
907 zio
= zio_root(dp
->dp_spa
, NULL
, NULL
, ZIO_FLAG_MUSTSUCCEED
);
908 dsl_dataset_sync(ds
, zio
, tx
);
909 VERIFY0(zio_wait(zio
));
911 /* dsl_dataset_sync_done will drop this reference. */
912 dmu_buf_add_ref(ds
->ds_dbuf
, ds
);
913 dsl_dataset_sync_done(ds
, tx
);
918 dsl_dataset_create_sync(dsl_dir_t
*pdd
, const char *lastname
,
919 dsl_dataset_t
*origin
, uint64_t flags
, cred_t
*cr
, dmu_tx_t
*tx
)
921 dsl_pool_t
*dp
= pdd
->dd_pool
;
922 uint64_t dsobj
, ddobj
;
925 ASSERT(dmu_tx_is_syncing(tx
));
926 ASSERT(lastname
[0] != '@');
928 ddobj
= dsl_dir_create_sync(dp
, pdd
, lastname
, tx
);
929 VERIFY0(dsl_dir_hold_obj(dp
, ddobj
, lastname
, FTAG
, &dd
));
931 dsobj
= dsl_dataset_create_sync_dd(dd
, origin
,
932 flags
& ~DS_CREATE_FLAG_NODIRTY
, tx
);
934 dsl_deleg_set_create_perms(dd
, tx
, cr
);
937 * Since we're creating a new node we know it's a leaf, so we can
938 * initialize the counts if the limit feature is active.
940 if (spa_feature_is_active(dp
->dp_spa
, SPA_FEATURE_FS_SS_LIMIT
)) {
942 objset_t
*os
= dd
->dd_pool
->dp_meta_objset
;
944 dsl_dir_zapify(dd
, tx
);
945 VERIFY0(zap_add(os
, dd
->dd_object
, DD_FIELD_FILESYSTEM_COUNT
,
946 sizeof (cnt
), 1, &cnt
, tx
));
947 VERIFY0(zap_add(os
, dd
->dd_object
, DD_FIELD_SNAPSHOT_COUNT
,
948 sizeof (cnt
), 1, &cnt
, tx
));
951 dsl_dir_rele(dd
, FTAG
);
954 * If we are creating a clone, make sure we zero out any stale
955 * data from the origin snapshots zil header.
957 if (origin
!= NULL
&& !(flags
& DS_CREATE_FLAG_NODIRTY
)) {
960 VERIFY0(dsl_dataset_hold_obj(dp
, dsobj
, FTAG
, &ds
));
961 dsl_dataset_zero_zil(ds
, tx
);
962 dsl_dataset_rele(ds
, FTAG
);
969 * The unique space in the head dataset can be calculated by subtracting
970 * the space used in the most recent snapshot, that is still being used
971 * in this file system, from the space currently in use. To figure out
972 * the space in the most recent snapshot still in use, we need to take
973 * the total space used in the snapshot and subtract out the space that
974 * has been freed up since the snapshot was taken.
977 dsl_dataset_recalc_head_uniq(dsl_dataset_t
*ds
)
980 uint64_t dlused
, dlcomp
, dluncomp
;
982 ASSERT(!ds
->ds_is_snapshot
);
984 if (dsl_dataset_phys(ds
)->ds_prev_snap_obj
!= 0)
985 mrs_used
= dsl_dataset_phys(ds
->ds_prev
)->ds_referenced_bytes
;
989 dsl_deadlist_space(&ds
->ds_deadlist
, &dlused
, &dlcomp
, &dluncomp
);
991 ASSERT3U(dlused
, <=, mrs_used
);
992 dsl_dataset_phys(ds
)->ds_unique_bytes
=
993 dsl_dataset_phys(ds
)->ds_referenced_bytes
- (mrs_used
- dlused
);
995 if (spa_version(ds
->ds_dir
->dd_pool
->dp_spa
) >=
996 SPA_VERSION_UNIQUE_ACCURATE
)
997 dsl_dataset_phys(ds
)->ds_flags
|= DS_FLAG_UNIQUE_ACCURATE
;
1001 dsl_dataset_remove_from_next_clones(dsl_dataset_t
*ds
, uint64_t obj
,
1004 objset_t
*mos
= ds
->ds_dir
->dd_pool
->dp_meta_objset
;
1006 ASSERTV(uint64_t count
);
1008 ASSERT(dsl_dataset_phys(ds
)->ds_num_children
>= 2);
1009 err
= zap_remove_int(mos
, dsl_dataset_phys(ds
)->ds_next_clones_obj
,
1012 * The err should not be ENOENT, but a bug in a previous version
1013 * of the code could cause upgrade_clones_cb() to not set
1014 * ds_next_snap_obj when it should, leading to a missing entry.
1015 * If we knew that the pool was created after
1016 * SPA_VERSION_NEXT_CLONES, we could assert that it isn't
1017 * ENOENT. However, at least we can check that we don't have
1018 * too many entries in the next_clones_obj even after failing to
1023 ASSERT0(zap_count(mos
, dsl_dataset_phys(ds
)->ds_next_clones_obj
,
1025 ASSERT3U(count
, <=, dsl_dataset_phys(ds
)->ds_num_children
- 2);
1030 dsl_dataset_get_blkptr(dsl_dataset_t
*ds
)
1032 return (&dsl_dataset_phys(ds
)->ds_bp
);
1036 dsl_dataset_get_spa(dsl_dataset_t
*ds
)
1038 return (ds
->ds_dir
->dd_pool
->dp_spa
);
1042 dsl_dataset_dirty(dsl_dataset_t
*ds
, dmu_tx_t
*tx
)
1046 if (ds
== NULL
) /* this is the meta-objset */
1049 ASSERT(ds
->ds_objset
!= NULL
);
1051 if (dsl_dataset_phys(ds
)->ds_next_snap_obj
!= 0)
1052 panic("dirtying snapshot!");
1054 /* Must not dirty a dataset in the same txg where it got snapshotted. */
1055 ASSERT3U(tx
->tx_txg
, >, dsl_dataset_phys(ds
)->ds_prev_snap_txg
);
1057 dp
= ds
->ds_dir
->dd_pool
;
1058 if (txg_list_add(&dp
->dp_dirty_datasets
, ds
, tx
->tx_txg
)) {
1059 /* up the hold count until we can be written out */
1060 dmu_buf_add_ref(ds
->ds_dbuf
, ds
);
1065 dsl_dataset_is_dirty(dsl_dataset_t
*ds
)
1069 for (t
= 0; t
< TXG_SIZE
; t
++) {
1070 if (txg_list_member(&ds
->ds_dir
->dd_pool
->dp_dirty_datasets
,
1078 dsl_dataset_snapshot_reserve_space(dsl_dataset_t
*ds
, dmu_tx_t
*tx
)
1082 if (!dmu_tx_is_syncing(tx
))
1086 * If there's an fs-only reservation, any blocks that might become
1087 * owned by the snapshot dataset must be accommodated by space
1088 * outside of the reservation.
1090 ASSERT(ds
->ds_reserved
== 0 || DS_UNIQUE_IS_ACCURATE(ds
));
1091 asize
= MIN(dsl_dataset_phys(ds
)->ds_unique_bytes
, ds
->ds_reserved
);
1092 if (asize
> dsl_dir_space_available(ds
->ds_dir
, NULL
, 0, TRUE
))
1093 return (SET_ERROR(ENOSPC
));
1096 * Propagate any reserved space for this snapshot to other
1097 * snapshot checks in this sync group.
1100 dsl_dir_willuse_space(ds
->ds_dir
, asize
, tx
);
1105 typedef struct dsl_dataset_snapshot_arg
{
1106 nvlist_t
*ddsa_snaps
;
1107 nvlist_t
*ddsa_props
;
1108 nvlist_t
*ddsa_errors
;
1110 } dsl_dataset_snapshot_arg_t
;
1113 dsl_dataset_snapshot_check_impl(dsl_dataset_t
*ds
, const char *snapname
,
1114 dmu_tx_t
*tx
, boolean_t recv
, uint64_t cnt
, cred_t
*cr
)
1119 ds
->ds_trysnap_txg
= tx
->tx_txg
;
1121 if (!dmu_tx_is_syncing(tx
))
1125 * We don't allow multiple snapshots of the same txg. If there
1126 * is already one, try again.
1128 if (dsl_dataset_phys(ds
)->ds_prev_snap_txg
>= tx
->tx_txg
)
1129 return (SET_ERROR(EAGAIN
));
1132 * Check for conflicting snapshot name.
1134 error
= dsl_dataset_snap_lookup(ds
, snapname
, &value
);
1136 return (SET_ERROR(EEXIST
));
1137 if (error
!= ENOENT
)
1141 * We don't allow taking snapshots of inconsistent datasets, such as
1142 * those into which we are currently receiving. However, if we are
1143 * creating this snapshot as part of a receive, this check will be
1144 * executed atomically with respect to the completion of the receive
1145 * itself but prior to the clearing of DS_FLAG_INCONSISTENT; in this
1146 * case we ignore this, knowing it will be fixed up for us shortly in
1147 * dmu_recv_end_sync().
1149 if (!recv
&& DS_IS_INCONSISTENT(ds
))
1150 return (SET_ERROR(EBUSY
));
1153 * Skip the check for temporary snapshots or if we have already checked
1154 * the counts in dsl_dataset_snapshot_check. This means we really only
1155 * check the count here when we're receiving a stream.
1157 if (cnt
!= 0 && cr
!= NULL
) {
1158 error
= dsl_fs_ss_limit_check(ds
->ds_dir
, cnt
,
1159 ZFS_PROP_SNAPSHOT_LIMIT
, NULL
, cr
);
1164 error
= dsl_dataset_snapshot_reserve_space(ds
, tx
);
1172 dsl_dataset_snapshot_check(void *arg
, dmu_tx_t
*tx
)
1174 dsl_dataset_snapshot_arg_t
*ddsa
= arg
;
1175 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
1180 * Pre-compute how many total new snapshots will be created for each
1181 * level in the tree and below. This is needed for validating the
1182 * snapshot limit when either taking a recursive snapshot or when
1183 * taking multiple snapshots.
1185 * The problem is that the counts are not actually adjusted when
1186 * we are checking, only when we finally sync. For a single snapshot,
1187 * this is easy, the count will increase by 1 at each node up the tree,
1188 * but its more complicated for the recursive/multiple snapshot case.
1190 * The dsl_fs_ss_limit_check function does recursively check the count
1191 * at each level up the tree but since it is validating each snapshot
1192 * independently we need to be sure that we are validating the complete
1193 * count for the entire set of snapshots. We do this by rolling up the
1194 * counts for each component of the name into an nvlist and then
1195 * checking each of those cases with the aggregated count.
1197 * This approach properly handles not only the recursive snapshot
1198 * case (where we get all of those on the ddsa_snaps list) but also
1199 * the sibling case (e.g. snapshot a/b and a/c so that we will also
1200 * validate the limit on 'a' using a count of 2).
1202 * We validate the snapshot names in the third loop and only report
1205 if (dmu_tx_is_syncing(tx
)) {
1207 nvlist_t
*cnt_track
= NULL
;
1208 cnt_track
= fnvlist_alloc();
1210 nm
= kmem_alloc(MAXPATHLEN
, KM_SLEEP
);
1212 /* Rollup aggregated counts into the cnt_track list */
1213 for (pair
= nvlist_next_nvpair(ddsa
->ddsa_snaps
, NULL
);
1215 pair
= nvlist_next_nvpair(ddsa
->ddsa_snaps
, pair
)) {
1219 (void) strlcpy(nm
, nvpair_name(pair
), MAXPATHLEN
);
1220 pdelim
= strchr(nm
, '@');
1226 if (nvlist_lookup_uint64(cnt_track
, nm
,
1228 /* update existing entry */
1229 fnvlist_add_uint64(cnt_track
, nm
,
1233 fnvlist_add_uint64(cnt_track
, nm
, 1);
1236 pdelim
= strrchr(nm
, '/');
1239 } while (pdelim
!= NULL
);
1242 kmem_free(nm
, MAXPATHLEN
);
1244 /* Check aggregated counts at each level */
1245 for (pair
= nvlist_next_nvpair(cnt_track
, NULL
);
1246 pair
!= NULL
; pair
= nvlist_next_nvpair(cnt_track
, pair
)) {
1252 name
= nvpair_name(pair
);
1253 cnt
= fnvpair_value_uint64(pair
);
1256 error
= dsl_dataset_hold(dp
, name
, FTAG
, &ds
);
1258 error
= dsl_fs_ss_limit_check(ds
->ds_dir
, cnt
,
1259 ZFS_PROP_SNAPSHOT_LIMIT
, NULL
,
1261 dsl_dataset_rele(ds
, FTAG
);
1265 if (ddsa
->ddsa_errors
!= NULL
)
1266 fnvlist_add_int32(ddsa
->ddsa_errors
,
1269 /* only report one error for this check */
1273 nvlist_free(cnt_track
);
1276 for (pair
= nvlist_next_nvpair(ddsa
->ddsa_snaps
, NULL
);
1277 pair
!= NULL
; pair
= nvlist_next_nvpair(ddsa
->ddsa_snaps
, pair
)) {
1280 char *name
, *atp
= NULL
;
1281 char dsname
[ZFS_MAX_DATASET_NAME_LEN
];
1283 name
= nvpair_name(pair
);
1284 if (strlen(name
) >= ZFS_MAX_DATASET_NAME_LEN
)
1285 error
= SET_ERROR(ENAMETOOLONG
);
1287 atp
= strchr(name
, '@');
1289 error
= SET_ERROR(EINVAL
);
1291 (void) strlcpy(dsname
, name
, atp
- name
+ 1);
1294 error
= dsl_dataset_hold(dp
, dsname
, FTAG
, &ds
);
1296 /* passing 0/NULL skips dsl_fs_ss_limit_check */
1297 error
= dsl_dataset_snapshot_check_impl(ds
,
1298 atp
+ 1, tx
, B_FALSE
, 0, NULL
);
1299 dsl_dataset_rele(ds
, FTAG
);
1303 if (ddsa
->ddsa_errors
!= NULL
) {
1304 fnvlist_add_int32(ddsa
->ddsa_errors
,
1315 dsl_dataset_snapshot_sync_impl(dsl_dataset_t
*ds
, const char *snapname
,
1318 dsl_pool_t
*dp
= ds
->ds_dir
->dd_pool
;
1320 dsl_dataset_phys_t
*dsphys
;
1321 uint64_t dsobj
, crtxg
;
1322 objset_t
*mos
= dp
->dp_meta_objset
;
1324 ASSERTV(static zil_header_t zero_zil
);
1325 ASSERTV(objset_t
*os
);
1327 ASSERT(RRW_WRITE_HELD(&dp
->dp_config_rwlock
));
1330 * If we are on an old pool, the zil must not be active, in which
1331 * case it will be zeroed. Usually zil_suspend() accomplishes this.
1333 ASSERT(spa_version(dmu_tx_pool(tx
)->dp_spa
) >= SPA_VERSION_FAST_SNAP
||
1334 dmu_objset_from_ds(ds
, &os
) != 0 ||
1335 bcmp(&os
->os_phys
->os_zil_header
, &zero_zil
,
1336 sizeof (zero_zil
)) == 0);
1338 /* Should not snapshot a dirty dataset. */
1339 ASSERT(!txg_list_member(&ds
->ds_dir
->dd_pool
->dp_dirty_datasets
,
1342 dsl_fs_ss_count_adjust(ds
->ds_dir
, 1, DD_FIELD_SNAPSHOT_COUNT
, tx
);
1345 * The origin's ds_creation_txg has to be < TXG_INITIAL
1347 if (strcmp(snapname
, ORIGIN_DIR_NAME
) == 0)
1352 dsobj
= dmu_object_alloc(mos
, DMU_OT_DSL_DATASET
, 0,
1353 DMU_OT_DSL_DATASET
, sizeof (dsl_dataset_phys_t
), tx
);
1354 VERIFY0(dmu_bonus_hold(mos
, dsobj
, FTAG
, &dbuf
));
1355 dmu_buf_will_dirty(dbuf
, tx
);
1356 dsphys
= dbuf
->db_data
;
1357 bzero(dsphys
, sizeof (dsl_dataset_phys_t
));
1358 dsphys
->ds_dir_obj
= ds
->ds_dir
->dd_object
;
1359 dsphys
->ds_fsid_guid
= unique_create();
1360 (void) random_get_pseudo_bytes((void*)&dsphys
->ds_guid
,
1361 sizeof (dsphys
->ds_guid
));
1362 dsphys
->ds_prev_snap_obj
= dsl_dataset_phys(ds
)->ds_prev_snap_obj
;
1363 dsphys
->ds_prev_snap_txg
= dsl_dataset_phys(ds
)->ds_prev_snap_txg
;
1364 dsphys
->ds_next_snap_obj
= ds
->ds_object
;
1365 dsphys
->ds_num_children
= 1;
1366 dsphys
->ds_creation_time
= gethrestime_sec();
1367 dsphys
->ds_creation_txg
= crtxg
;
1368 dsphys
->ds_deadlist_obj
= dsl_dataset_phys(ds
)->ds_deadlist_obj
;
1369 dsphys
->ds_referenced_bytes
= dsl_dataset_phys(ds
)->ds_referenced_bytes
;
1370 dsphys
->ds_compressed_bytes
= dsl_dataset_phys(ds
)->ds_compressed_bytes
;
1371 dsphys
->ds_uncompressed_bytes
=
1372 dsl_dataset_phys(ds
)->ds_uncompressed_bytes
;
1373 dsphys
->ds_flags
= dsl_dataset_phys(ds
)->ds_flags
;
1374 rrw_enter(&ds
->ds_bp_rwlock
, RW_READER
, FTAG
);
1375 dsphys
->ds_bp
= dsl_dataset_phys(ds
)->ds_bp
;
1376 rrw_exit(&ds
->ds_bp_rwlock
, FTAG
);
1377 dmu_buf_rele(dbuf
, FTAG
);
1379 for (f
= 0; f
< SPA_FEATURES
; f
++) {
1380 if (ds
->ds_feature_inuse
[f
])
1381 dsl_dataset_activate_feature(dsobj
, f
, tx
);
1384 ASSERT3U(ds
->ds_prev
!= 0, ==,
1385 dsl_dataset_phys(ds
)->ds_prev_snap_obj
!= 0);
1387 uint64_t next_clones_obj
=
1388 dsl_dataset_phys(ds
->ds_prev
)->ds_next_clones_obj
;
1389 ASSERT(dsl_dataset_phys(ds
->ds_prev
)->ds_next_snap_obj
==
1391 dsl_dataset_phys(ds
->ds_prev
)->ds_num_children
> 1);
1392 if (dsl_dataset_phys(ds
->ds_prev
)->ds_next_snap_obj
==
1394 dmu_buf_will_dirty(ds
->ds_prev
->ds_dbuf
, tx
);
1395 ASSERT3U(dsl_dataset_phys(ds
)->ds_prev_snap_txg
, ==,
1396 dsl_dataset_phys(ds
->ds_prev
)->ds_creation_txg
);
1397 dsl_dataset_phys(ds
->ds_prev
)->ds_next_snap_obj
= dsobj
;
1398 } else if (next_clones_obj
!= 0) {
1399 dsl_dataset_remove_from_next_clones(ds
->ds_prev
,
1400 dsphys
->ds_next_snap_obj
, tx
);
1401 VERIFY0(zap_add_int(mos
,
1402 next_clones_obj
, dsobj
, tx
));
1407 * If we have a reference-reservation on this dataset, we will
1408 * need to increase the amount of refreservation being charged
1409 * since our unique space is going to zero.
1411 if (ds
->ds_reserved
) {
1413 ASSERT(DS_UNIQUE_IS_ACCURATE(ds
));
1414 delta
= MIN(dsl_dataset_phys(ds
)->ds_unique_bytes
,
1416 dsl_dir_diduse_space(ds
->ds_dir
, DD_USED_REFRSRV
,
1420 dmu_buf_will_dirty(ds
->ds_dbuf
, tx
);
1421 dsl_dataset_phys(ds
)->ds_deadlist_obj
=
1422 dsl_deadlist_clone(&ds
->ds_deadlist
, UINT64_MAX
,
1423 dsl_dataset_phys(ds
)->ds_prev_snap_obj
, tx
);
1424 dsl_deadlist_close(&ds
->ds_deadlist
);
1425 dsl_deadlist_open(&ds
->ds_deadlist
, mos
,
1426 dsl_dataset_phys(ds
)->ds_deadlist_obj
);
1427 dsl_deadlist_add_key(&ds
->ds_deadlist
,
1428 dsl_dataset_phys(ds
)->ds_prev_snap_txg
, tx
);
1430 ASSERT3U(dsl_dataset_phys(ds
)->ds_prev_snap_txg
, <, tx
->tx_txg
);
1431 dsl_dataset_phys(ds
)->ds_prev_snap_obj
= dsobj
;
1432 dsl_dataset_phys(ds
)->ds_prev_snap_txg
= crtxg
;
1433 dsl_dataset_phys(ds
)->ds_unique_bytes
= 0;
1434 if (spa_version(dp
->dp_spa
) >= SPA_VERSION_UNIQUE_ACCURATE
)
1435 dsl_dataset_phys(ds
)->ds_flags
|= DS_FLAG_UNIQUE_ACCURATE
;
1437 VERIFY0(zap_add(mos
, dsl_dataset_phys(ds
)->ds_snapnames_zapobj
,
1438 snapname
, 8, 1, &dsobj
, tx
));
1441 dsl_dataset_rele(ds
->ds_prev
, ds
);
1442 VERIFY0(dsl_dataset_hold_obj(dp
,
1443 dsl_dataset_phys(ds
)->ds_prev_snap_obj
, ds
, &ds
->ds_prev
));
1445 dsl_scan_ds_snapshotted(ds
, tx
);
1447 dsl_dir_snap_cmtime_update(ds
->ds_dir
);
1449 spa_history_log_internal_ds(ds
->ds_prev
, "snapshot", tx
, "");
1453 dsl_dataset_snapshot_sync(void *arg
, dmu_tx_t
*tx
)
1455 dsl_dataset_snapshot_arg_t
*ddsa
= arg
;
1456 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
1459 for (pair
= nvlist_next_nvpair(ddsa
->ddsa_snaps
, NULL
);
1460 pair
!= NULL
; pair
= nvlist_next_nvpair(ddsa
->ddsa_snaps
, pair
)) {
1463 char dsname
[ZFS_MAX_DATASET_NAME_LEN
];
1465 name
= nvpair_name(pair
);
1466 atp
= strchr(name
, '@');
1467 (void) strlcpy(dsname
, name
, atp
- name
+ 1);
1468 VERIFY0(dsl_dataset_hold(dp
, dsname
, FTAG
, &ds
));
1470 dsl_dataset_snapshot_sync_impl(ds
, atp
+ 1, tx
);
1471 if (ddsa
->ddsa_props
!= NULL
) {
1472 dsl_props_set_sync_impl(ds
->ds_prev
,
1473 ZPROP_SRC_LOCAL
, ddsa
->ddsa_props
, tx
);
1475 zvol_create_minors(dp
->dp_spa
, nvpair_name(pair
), B_TRUE
);
1476 dsl_dataset_rele(ds
, FTAG
);
1481 * The snapshots must all be in the same pool.
1482 * All-or-nothing: if there are any failures, nothing will be modified.
1485 dsl_dataset_snapshot(nvlist_t
*snaps
, nvlist_t
*props
, nvlist_t
*errors
)
1487 dsl_dataset_snapshot_arg_t ddsa
;
1489 boolean_t needsuspend
;
1493 nvlist_t
*suspended
= NULL
;
1495 pair
= nvlist_next_nvpair(snaps
, NULL
);
1498 firstname
= nvpair_name(pair
);
1500 error
= spa_open(firstname
, &spa
, FTAG
);
1503 needsuspend
= (spa_version(spa
) < SPA_VERSION_FAST_SNAP
);
1504 spa_close(spa
, FTAG
);
1507 suspended
= fnvlist_alloc();
1508 for (pair
= nvlist_next_nvpair(snaps
, NULL
); pair
!= NULL
;
1509 pair
= nvlist_next_nvpair(snaps
, pair
)) {
1510 char fsname
[ZFS_MAX_DATASET_NAME_LEN
];
1511 char *snapname
= nvpair_name(pair
);
1515 atp
= strchr(snapname
, '@');
1517 error
= SET_ERROR(EINVAL
);
1520 (void) strlcpy(fsname
, snapname
, atp
- snapname
+ 1);
1522 error
= zil_suspend(fsname
, &cookie
);
1525 fnvlist_add_uint64(suspended
, fsname
,
1530 ddsa
.ddsa_snaps
= snaps
;
1531 ddsa
.ddsa_props
= props
;
1532 ddsa
.ddsa_errors
= errors
;
1533 ddsa
.ddsa_cr
= CRED();
1536 error
= dsl_sync_task(firstname
, dsl_dataset_snapshot_check
,
1537 dsl_dataset_snapshot_sync
, &ddsa
,
1538 fnvlist_num_pairs(snaps
) * 3, ZFS_SPACE_CHECK_NORMAL
);
1541 if (suspended
!= NULL
) {
1542 for (pair
= nvlist_next_nvpair(suspended
, NULL
); pair
!= NULL
;
1543 pair
= nvlist_next_nvpair(suspended
, pair
)) {
1544 zil_resume((void *)(uintptr_t)
1545 fnvpair_value_uint64(pair
));
1547 fnvlist_free(suspended
);
1553 typedef struct dsl_dataset_snapshot_tmp_arg
{
1554 const char *ddsta_fsname
;
1555 const char *ddsta_snapname
;
1556 minor_t ddsta_cleanup_minor
;
1557 const char *ddsta_htag
;
1558 } dsl_dataset_snapshot_tmp_arg_t
;
1561 dsl_dataset_snapshot_tmp_check(void *arg
, dmu_tx_t
*tx
)
1563 dsl_dataset_snapshot_tmp_arg_t
*ddsta
= arg
;
1564 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
1568 error
= dsl_dataset_hold(dp
, ddsta
->ddsta_fsname
, FTAG
, &ds
);
1572 /* NULL cred means no limit check for tmp snapshot */
1573 error
= dsl_dataset_snapshot_check_impl(ds
, ddsta
->ddsta_snapname
,
1574 tx
, B_FALSE
, 0, NULL
);
1576 dsl_dataset_rele(ds
, FTAG
);
1580 if (spa_version(dp
->dp_spa
) < SPA_VERSION_USERREFS
) {
1581 dsl_dataset_rele(ds
, FTAG
);
1582 return (SET_ERROR(ENOTSUP
));
1584 error
= dsl_dataset_user_hold_check_one(NULL
, ddsta
->ddsta_htag
,
1587 dsl_dataset_rele(ds
, FTAG
);
1591 dsl_dataset_rele(ds
, FTAG
);
1596 dsl_dataset_snapshot_tmp_sync(void *arg
, dmu_tx_t
*tx
)
1598 dsl_dataset_snapshot_tmp_arg_t
*ddsta
= arg
;
1599 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
1600 dsl_dataset_t
*ds
= NULL
;
1602 VERIFY0(dsl_dataset_hold(dp
, ddsta
->ddsta_fsname
, FTAG
, &ds
));
1604 dsl_dataset_snapshot_sync_impl(ds
, ddsta
->ddsta_snapname
, tx
);
1605 dsl_dataset_user_hold_sync_one(ds
->ds_prev
, ddsta
->ddsta_htag
,
1606 ddsta
->ddsta_cleanup_minor
, gethrestime_sec(), tx
);
1607 dsl_destroy_snapshot_sync_impl(ds
->ds_prev
, B_TRUE
, tx
);
1609 dsl_dataset_rele(ds
, FTAG
);
1613 dsl_dataset_snapshot_tmp(const char *fsname
, const char *snapname
,
1614 minor_t cleanup_minor
, const char *htag
)
1616 dsl_dataset_snapshot_tmp_arg_t ddsta
;
1619 boolean_t needsuspend
;
1622 ddsta
.ddsta_fsname
= fsname
;
1623 ddsta
.ddsta_snapname
= snapname
;
1624 ddsta
.ddsta_cleanup_minor
= cleanup_minor
;
1625 ddsta
.ddsta_htag
= htag
;
1627 error
= spa_open(fsname
, &spa
, FTAG
);
1630 needsuspend
= (spa_version(spa
) < SPA_VERSION_FAST_SNAP
);
1631 spa_close(spa
, FTAG
);
1634 error
= zil_suspend(fsname
, &cookie
);
1639 error
= dsl_sync_task(fsname
, dsl_dataset_snapshot_tmp_check
,
1640 dsl_dataset_snapshot_tmp_sync
, &ddsta
, 3, ZFS_SPACE_CHECK_RESERVED
);
1649 dsl_dataset_sync(dsl_dataset_t
*ds
, zio_t
*zio
, dmu_tx_t
*tx
)
1653 ASSERT(dmu_tx_is_syncing(tx
));
1654 ASSERT(ds
->ds_objset
!= NULL
);
1655 ASSERT(dsl_dataset_phys(ds
)->ds_next_snap_obj
== 0);
1658 * in case we had to change ds_fsid_guid when we opened it,
1661 dmu_buf_will_dirty(ds
->ds_dbuf
, tx
);
1662 dsl_dataset_phys(ds
)->ds_fsid_guid
= ds
->ds_fsid_guid
;
1664 if (ds
->ds_resume_bytes
[tx
->tx_txg
& TXG_MASK
] != 0) {
1665 VERIFY0(zap_update(tx
->tx_pool
->dp_meta_objset
,
1666 ds
->ds_object
, DS_FIELD_RESUME_OBJECT
, 8, 1,
1667 &ds
->ds_resume_object
[tx
->tx_txg
& TXG_MASK
], tx
));
1668 VERIFY0(zap_update(tx
->tx_pool
->dp_meta_objset
,
1669 ds
->ds_object
, DS_FIELD_RESUME_OFFSET
, 8, 1,
1670 &ds
->ds_resume_offset
[tx
->tx_txg
& TXG_MASK
], tx
));
1671 VERIFY0(zap_update(tx
->tx_pool
->dp_meta_objset
,
1672 ds
->ds_object
, DS_FIELD_RESUME_BYTES
, 8, 1,
1673 &ds
->ds_resume_bytes
[tx
->tx_txg
& TXG_MASK
], tx
));
1674 ds
->ds_resume_object
[tx
->tx_txg
& TXG_MASK
] = 0;
1675 ds
->ds_resume_offset
[tx
->tx_txg
& TXG_MASK
] = 0;
1676 ds
->ds_resume_bytes
[tx
->tx_txg
& TXG_MASK
] = 0;
1679 dmu_objset_sync(ds
->ds_objset
, zio
, tx
);
1681 for (f
= 0; f
< SPA_FEATURES
; f
++) {
1682 if (ds
->ds_feature_activation_needed
[f
]) {
1683 if (ds
->ds_feature_inuse
[f
])
1685 dsl_dataset_activate_feature(ds
->ds_object
, f
, tx
);
1686 ds
->ds_feature_inuse
[f
] = B_TRUE
;
1692 deadlist_enqueue_cb(void *arg
, const blkptr_t
*bp
, dmu_tx_t
*tx
)
1694 dsl_deadlist_t
*dl
= arg
;
1695 dsl_deadlist_insert(dl
, bp
, tx
);
1700 dsl_dataset_sync_done(dsl_dataset_t
*ds
, dmu_tx_t
*tx
)
1702 objset_t
*os
= ds
->ds_objset
;
1704 bplist_iterate(&ds
->ds_pending_deadlist
,
1705 deadlist_enqueue_cb
, &ds
->ds_deadlist
, tx
);
1707 if (os
->os_synced_dnodes
!= NULL
) {
1708 multilist_destroy(os
->os_synced_dnodes
);
1709 os
->os_synced_dnodes
= NULL
;
1712 ASSERT(!dmu_objset_is_dirty(os
, dmu_tx_get_txg(tx
)));
1714 dmu_buf_rele(ds
->ds_dbuf
, ds
);
1718 get_clones_stat(dsl_dataset_t
*ds
, nvlist_t
*nv
)
1721 objset_t
*mos
= ds
->ds_dir
->dd_pool
->dp_meta_objset
;
1724 nvlist_t
*propval
= fnvlist_alloc();
1727 ASSERT(dsl_pool_config_held(ds
->ds_dir
->dd_pool
));
1730 * We use nvlist_alloc() instead of fnvlist_alloc() because the
1731 * latter would allocate the list with NV_UNIQUE_NAME flag.
1732 * As a result, every time a clone name is appended to the list
1733 * it would be (linearly) searched for for a duplicate name.
1734 * We already know that all clone names must be unique and we
1735 * want avoid the quadratic complexity of double-checking that
1736 * because we can have a large number of clones.
1738 VERIFY0(nvlist_alloc(&val
, 0, KM_SLEEP
));
1741 * There may be missing entries in ds_next_clones_obj
1742 * due to a bug in a previous version of the code.
1743 * Only trust it if it has the right number of entries.
1745 if (dsl_dataset_phys(ds
)->ds_next_clones_obj
!= 0) {
1746 VERIFY0(zap_count(mos
, dsl_dataset_phys(ds
)->ds_next_clones_obj
,
1749 if (count
!= dsl_dataset_phys(ds
)->ds_num_children
- 1)
1751 for (zap_cursor_init(&zc
, mos
,
1752 dsl_dataset_phys(ds
)->ds_next_clones_obj
);
1753 zap_cursor_retrieve(&zc
, &za
) == 0;
1754 zap_cursor_advance(&zc
)) {
1755 dsl_dataset_t
*clone
;
1756 char buf
[ZFS_MAX_DATASET_NAME_LEN
];
1757 VERIFY0(dsl_dataset_hold_obj(ds
->ds_dir
->dd_pool
,
1758 za
.za_first_integer
, FTAG
, &clone
));
1759 dsl_dir_name(clone
->ds_dir
, buf
);
1760 fnvlist_add_boolean(val
, buf
);
1761 dsl_dataset_rele(clone
, FTAG
);
1763 zap_cursor_fini(&zc
);
1764 fnvlist_add_nvlist(propval
, ZPROP_VALUE
, val
);
1765 fnvlist_add_nvlist(nv
, zfs_prop_to_name(ZFS_PROP_CLONES
), propval
);
1768 nvlist_free(propval
);
1772 get_receive_resume_stats(dsl_dataset_t
*ds
, nvlist_t
*nv
)
1774 dsl_pool_t
*dp
= ds
->ds_dir
->dd_pool
;
1776 if (dsl_dataset_has_resume_receive_state(ds
)) {
1779 uint8_t *compressed
;
1781 nvlist_t
*token_nv
= fnvlist_alloc();
1782 size_t packed_size
, compressed_size
;
1785 char buf
[MAXNAMELEN
];
1788 if (zap_lookup(dp
->dp_meta_objset
, ds
->ds_object
,
1789 DS_FIELD_RESUME_FROMGUID
, sizeof (val
), 1, &val
) == 0) {
1790 fnvlist_add_uint64(token_nv
, "fromguid", val
);
1792 if (zap_lookup(dp
->dp_meta_objset
, ds
->ds_object
,
1793 DS_FIELD_RESUME_OBJECT
, sizeof (val
), 1, &val
) == 0) {
1794 fnvlist_add_uint64(token_nv
, "object", val
);
1796 if (zap_lookup(dp
->dp_meta_objset
, ds
->ds_object
,
1797 DS_FIELD_RESUME_OFFSET
, sizeof (val
), 1, &val
) == 0) {
1798 fnvlist_add_uint64(token_nv
, "offset", val
);
1800 if (zap_lookup(dp
->dp_meta_objset
, ds
->ds_object
,
1801 DS_FIELD_RESUME_BYTES
, sizeof (val
), 1, &val
) == 0) {
1802 fnvlist_add_uint64(token_nv
, "bytes", val
);
1804 if (zap_lookup(dp
->dp_meta_objset
, ds
->ds_object
,
1805 DS_FIELD_RESUME_TOGUID
, sizeof (val
), 1, &val
) == 0) {
1806 fnvlist_add_uint64(token_nv
, "toguid", val
);
1808 if (zap_lookup(dp
->dp_meta_objset
, ds
->ds_object
,
1809 DS_FIELD_RESUME_TONAME
, 1, sizeof (buf
), buf
) == 0) {
1810 fnvlist_add_string(token_nv
, "toname", buf
);
1812 if (zap_contains(dp
->dp_meta_objset
, ds
->ds_object
,
1813 DS_FIELD_RESUME_LARGEBLOCK
) == 0) {
1814 fnvlist_add_boolean(token_nv
, "largeblockok");
1816 if (zap_contains(dp
->dp_meta_objset
, ds
->ds_object
,
1817 DS_FIELD_RESUME_EMBEDOK
) == 0) {
1818 fnvlist_add_boolean(token_nv
, "embedok");
1820 if (zap_contains(dp
->dp_meta_objset
, ds
->ds_object
,
1821 DS_FIELD_RESUME_COMPRESSOK
) == 0) {
1822 fnvlist_add_boolean(token_nv
, "compressok");
1824 packed
= fnvlist_pack(token_nv
, &packed_size
);
1825 fnvlist_free(token_nv
);
1826 compressed
= kmem_alloc(packed_size
, KM_SLEEP
);
1828 compressed_size
= gzip_compress(packed
, compressed
,
1829 packed_size
, packed_size
, 6);
1831 fletcher_4_native_varsize(compressed
, compressed_size
, &cksum
);
1833 str
= kmem_alloc(compressed_size
* 2 + 1, KM_SLEEP
);
1834 for (i
= 0; i
< compressed_size
; i
++) {
1835 (void) sprintf(str
+ i
* 2, "%02x", compressed
[i
]);
1837 str
[compressed_size
* 2] = '\0';
1838 propval
= kmem_asprintf("%u-%llx-%llx-%s",
1839 ZFS_SEND_RESUME_TOKEN_VERSION
,
1840 (longlong_t
)cksum
.zc_word
[0],
1841 (longlong_t
)packed_size
, str
);
1842 dsl_prop_nvlist_add_string(nv
,
1843 ZFS_PROP_RECEIVE_RESUME_TOKEN
, propval
);
1844 kmem_free(packed
, packed_size
);
1845 kmem_free(str
, compressed_size
* 2 + 1);
1846 kmem_free(compressed
, packed_size
);
1852 dsl_dataset_stats(dsl_dataset_t
*ds
, nvlist_t
*nv
)
1854 dsl_pool_t
*dp
= ds
->ds_dir
->dd_pool
;
1855 uint64_t refd
, avail
, uobjs
, aobjs
, ratio
;
1857 ASSERT(dsl_pool_config_held(dp
));
1859 ratio
= dsl_dataset_phys(ds
)->ds_compressed_bytes
== 0 ? 100 :
1860 (dsl_dataset_phys(ds
)->ds_uncompressed_bytes
* 100 /
1861 dsl_dataset_phys(ds
)->ds_compressed_bytes
);
1863 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_REFRATIO
, ratio
);
1864 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_LOGICALREFERENCED
,
1865 dsl_dataset_phys(ds
)->ds_uncompressed_bytes
);
1867 if (ds
->ds_is_snapshot
) {
1868 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_COMPRESSRATIO
, ratio
);
1869 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_USED
,
1870 dsl_dataset_phys(ds
)->ds_unique_bytes
);
1871 get_clones_stat(ds
, nv
);
1873 if (ds
->ds_prev
!= NULL
&& ds
->ds_prev
!= dp
->dp_origin_snap
) {
1874 char buf
[ZFS_MAX_DATASET_NAME_LEN
];
1875 dsl_dataset_name(ds
->ds_prev
, buf
);
1876 dsl_prop_nvlist_add_string(nv
, ZFS_PROP_PREV_SNAP
, buf
);
1879 dsl_dir_stats(ds
->ds_dir
, nv
);
1882 dsl_dataset_space(ds
, &refd
, &avail
, &uobjs
, &aobjs
);
1883 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_AVAILABLE
, avail
);
1884 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_REFERENCED
, refd
);
1886 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_CREATION
,
1887 dsl_dataset_phys(ds
)->ds_creation_time
);
1888 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_CREATETXG
,
1889 dsl_dataset_phys(ds
)->ds_creation_txg
);
1890 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_REFQUOTA
,
1892 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_REFRESERVATION
,
1894 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_GUID
,
1895 dsl_dataset_phys(ds
)->ds_guid
);
1896 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_UNIQUE
,
1897 dsl_dataset_phys(ds
)->ds_unique_bytes
);
1898 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_OBJSETID
,
1900 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_USERREFS
,
1902 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_DEFER_DESTROY
,
1903 DS_IS_DEFER_DESTROY(ds
) ? 1 : 0);
1905 if (dsl_dataset_phys(ds
)->ds_prev_snap_obj
!= 0) {
1906 uint64_t written
, comp
, uncomp
;
1907 dsl_pool_t
*dp
= ds
->ds_dir
->dd_pool
;
1908 dsl_dataset_t
*prev
;
1911 err
= dsl_dataset_hold_obj(dp
,
1912 dsl_dataset_phys(ds
)->ds_prev_snap_obj
, FTAG
, &prev
);
1914 err
= dsl_dataset_space_written(prev
, ds
, &written
,
1916 dsl_dataset_rele(prev
, FTAG
);
1918 dsl_prop_nvlist_add_uint64(nv
, ZFS_PROP_WRITTEN
,
1924 if (!dsl_dataset_is_snapshot(ds
)) {
1925 /* 6 extra bytes for /%recv */
1926 char recvname
[ZFS_MAX_DATASET_NAME_LEN
+ 6];
1927 dsl_dataset_t
*recv_ds
;
1930 * A failed "newfs" (e.g. full) resumable receive leaves
1931 * the stats set on this dataset. Check here for the prop.
1933 get_receive_resume_stats(ds
, nv
);
1936 * A failed incremental resumable receive leaves the
1937 * stats set on our child named "%recv". Check the child
1940 dsl_dataset_name(ds
, recvname
);
1941 if (strlcat(recvname
, "/", sizeof (recvname
)) <
1942 sizeof (recvname
) &&
1943 strlcat(recvname
, recv_clone_name
, sizeof (recvname
)) <
1944 sizeof (recvname
) &&
1945 dsl_dataset_hold(dp
, recvname
, FTAG
, &recv_ds
) == 0) {
1946 get_receive_resume_stats(recv_ds
, nv
);
1947 dsl_dataset_rele(recv_ds
, FTAG
);
1953 dsl_dataset_fast_stat(dsl_dataset_t
*ds
, dmu_objset_stats_t
*stat
)
1955 dsl_pool_t
*dp
= ds
->ds_dir
->dd_pool
;
1956 ASSERT(dsl_pool_config_held(dp
));
1958 stat
->dds_creation_txg
= dsl_dataset_phys(ds
)->ds_creation_txg
;
1959 stat
->dds_inconsistent
=
1960 dsl_dataset_phys(ds
)->ds_flags
& DS_FLAG_INCONSISTENT
;
1961 stat
->dds_guid
= dsl_dataset_phys(ds
)->ds_guid
;
1962 stat
->dds_origin
[0] = '\0';
1963 if (ds
->ds_is_snapshot
) {
1964 stat
->dds_is_snapshot
= B_TRUE
;
1965 stat
->dds_num_clones
=
1966 dsl_dataset_phys(ds
)->ds_num_children
- 1;
1968 stat
->dds_is_snapshot
= B_FALSE
;
1969 stat
->dds_num_clones
= 0;
1971 if (dsl_dir_is_clone(ds
->ds_dir
)) {
1974 VERIFY0(dsl_dataset_hold_obj(dp
,
1975 dsl_dir_phys(ds
->ds_dir
)->dd_origin_obj
,
1977 dsl_dataset_name(ods
, stat
->dds_origin
);
1978 dsl_dataset_rele(ods
, FTAG
);
1984 dsl_dataset_fsid_guid(dsl_dataset_t
*ds
)
1986 return (ds
->ds_fsid_guid
);
1990 dsl_dataset_space(dsl_dataset_t
*ds
,
1991 uint64_t *refdbytesp
, uint64_t *availbytesp
,
1992 uint64_t *usedobjsp
, uint64_t *availobjsp
)
1994 *refdbytesp
= dsl_dataset_phys(ds
)->ds_referenced_bytes
;
1995 *availbytesp
= dsl_dir_space_available(ds
->ds_dir
, NULL
, 0, TRUE
);
1996 if (ds
->ds_reserved
> dsl_dataset_phys(ds
)->ds_unique_bytes
)
1998 ds
->ds_reserved
- dsl_dataset_phys(ds
)->ds_unique_bytes
;
1999 if (ds
->ds_quota
!= 0) {
2001 * Adjust available bytes according to refquota
2003 if (*refdbytesp
< ds
->ds_quota
)
2004 *availbytesp
= MIN(*availbytesp
,
2005 ds
->ds_quota
- *refdbytesp
);
2009 rrw_enter(&ds
->ds_bp_rwlock
, RW_READER
, FTAG
);
2010 *usedobjsp
= BP_GET_FILL(&dsl_dataset_phys(ds
)->ds_bp
);
2011 rrw_exit(&ds
->ds_bp_rwlock
, FTAG
);
2012 *availobjsp
= DN_MAX_OBJECT
- *usedobjsp
;
2016 dsl_dataset_modified_since_snap(dsl_dataset_t
*ds
, dsl_dataset_t
*snap
)
2018 ASSERTV(dsl_pool_t
*dp
= ds
->ds_dir
->dd_pool
);
2021 ASSERT(dsl_pool_config_held(dp
));
2024 rrw_enter(&ds
->ds_bp_rwlock
, RW_READER
, FTAG
);
2025 birth
= dsl_dataset_get_blkptr(ds
)->blk_birth
;
2026 rrw_exit(&ds
->ds_bp_rwlock
, FTAG
);
2027 if (birth
> dsl_dataset_phys(snap
)->ds_creation_txg
) {
2028 objset_t
*os
, *os_snap
;
2030 * It may be that only the ZIL differs, because it was
2031 * reset in the head. Don't count that as being
2034 if (dmu_objset_from_ds(ds
, &os
) != 0)
2036 if (dmu_objset_from_ds(snap
, &os_snap
) != 0)
2038 return (bcmp(&os
->os_phys
->os_meta_dnode
,
2039 &os_snap
->os_phys
->os_meta_dnode
,
2040 sizeof (os
->os_phys
->os_meta_dnode
)) != 0);
2045 typedef struct dsl_dataset_rename_snapshot_arg
{
2046 const char *ddrsa_fsname
;
2047 const char *ddrsa_oldsnapname
;
2048 const char *ddrsa_newsnapname
;
2049 boolean_t ddrsa_recursive
;
2051 } dsl_dataset_rename_snapshot_arg_t
;
2055 dsl_dataset_rename_snapshot_check_impl(dsl_pool_t
*dp
,
2056 dsl_dataset_t
*hds
, void *arg
)
2058 dsl_dataset_rename_snapshot_arg_t
*ddrsa
= arg
;
2062 error
= dsl_dataset_snap_lookup(hds
, ddrsa
->ddrsa_oldsnapname
, &val
);
2064 /* ignore nonexistent snapshots */
2065 return (error
== ENOENT
? 0 : error
);
2068 /* new name should not exist */
2069 error
= dsl_dataset_snap_lookup(hds
, ddrsa
->ddrsa_newsnapname
, &val
);
2071 error
= SET_ERROR(EEXIST
);
2072 else if (error
== ENOENT
)
2075 /* dataset name + 1 for the "@" + the new snapshot name must fit */
2076 if (dsl_dir_namelen(hds
->ds_dir
) + 1 +
2077 strlen(ddrsa
->ddrsa_newsnapname
) >= ZFS_MAX_DATASET_NAME_LEN
)
2078 error
= SET_ERROR(ENAMETOOLONG
);
2084 dsl_dataset_rename_snapshot_check(void *arg
, dmu_tx_t
*tx
)
2086 dsl_dataset_rename_snapshot_arg_t
*ddrsa
= arg
;
2087 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
2091 error
= dsl_dataset_hold(dp
, ddrsa
->ddrsa_fsname
, FTAG
, &hds
);
2095 if (ddrsa
->ddrsa_recursive
) {
2096 error
= dmu_objset_find_dp(dp
, hds
->ds_dir
->dd_object
,
2097 dsl_dataset_rename_snapshot_check_impl
, ddrsa
,
2100 error
= dsl_dataset_rename_snapshot_check_impl(dp
, hds
, ddrsa
);
2102 dsl_dataset_rele(hds
, FTAG
);
2107 dsl_dataset_rename_snapshot_sync_impl(dsl_pool_t
*dp
,
2108 dsl_dataset_t
*hds
, void *arg
)
2110 dsl_dataset_rename_snapshot_arg_t
*ddrsa
= arg
;
2113 dmu_tx_t
*tx
= ddrsa
->ddrsa_tx
;
2116 error
= dsl_dataset_snap_lookup(hds
, ddrsa
->ddrsa_oldsnapname
, &val
);
2117 ASSERT(error
== 0 || error
== ENOENT
);
2118 if (error
== ENOENT
) {
2119 /* ignore nonexistent snapshots */
2123 VERIFY0(dsl_dataset_hold_obj(dp
, val
, FTAG
, &ds
));
2125 /* log before we change the name */
2126 spa_history_log_internal_ds(ds
, "rename", tx
,
2127 "-> @%s", ddrsa
->ddrsa_newsnapname
);
2129 VERIFY0(dsl_dataset_snap_remove(hds
, ddrsa
->ddrsa_oldsnapname
, tx
,
2131 mutex_enter(&ds
->ds_lock
);
2132 (void) strlcpy(ds
->ds_snapname
, ddrsa
->ddrsa_newsnapname
,
2133 sizeof (ds
->ds_snapname
));
2134 mutex_exit(&ds
->ds_lock
);
2135 VERIFY0(zap_add(dp
->dp_meta_objset
,
2136 dsl_dataset_phys(hds
)->ds_snapnames_zapobj
,
2137 ds
->ds_snapname
, 8, 1, &ds
->ds_object
, tx
));
2138 zvol_rename_minors(dp
->dp_spa
, ddrsa
->ddrsa_oldsnapname
,
2139 ddrsa
->ddrsa_newsnapname
, B_TRUE
);
2141 dsl_dataset_rele(ds
, FTAG
);
2146 dsl_dataset_rename_snapshot_sync(void *arg
, dmu_tx_t
*tx
)
2148 dsl_dataset_rename_snapshot_arg_t
*ddrsa
= arg
;
2149 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
2150 dsl_dataset_t
*hds
= NULL
;
2152 VERIFY0(dsl_dataset_hold(dp
, ddrsa
->ddrsa_fsname
, FTAG
, &hds
));
2153 ddrsa
->ddrsa_tx
= tx
;
2154 if (ddrsa
->ddrsa_recursive
) {
2155 VERIFY0(dmu_objset_find_dp(dp
, hds
->ds_dir
->dd_object
,
2156 dsl_dataset_rename_snapshot_sync_impl
, ddrsa
,
2159 VERIFY0(dsl_dataset_rename_snapshot_sync_impl(dp
, hds
, ddrsa
));
2161 dsl_dataset_rele(hds
, FTAG
);
2165 dsl_dataset_rename_snapshot(const char *fsname
,
2166 const char *oldsnapname
, const char *newsnapname
, boolean_t recursive
)
2168 dsl_dataset_rename_snapshot_arg_t ddrsa
;
2170 ddrsa
.ddrsa_fsname
= fsname
;
2171 ddrsa
.ddrsa_oldsnapname
= oldsnapname
;
2172 ddrsa
.ddrsa_newsnapname
= newsnapname
;
2173 ddrsa
.ddrsa_recursive
= recursive
;
2175 return (dsl_sync_task(fsname
, dsl_dataset_rename_snapshot_check
,
2176 dsl_dataset_rename_snapshot_sync
, &ddrsa
,
2177 1, ZFS_SPACE_CHECK_RESERVED
));
2181 * If we're doing an ownership handoff, we need to make sure that there is
2182 * only one long hold on the dataset. We're not allowed to change anything here
2183 * so we don't permanently release the long hold or regular hold here. We want
2184 * to do this only when syncing to avoid the dataset unexpectedly going away
2185 * when we release the long hold.
2188 dsl_dataset_handoff_check(dsl_dataset_t
*ds
, void *owner
, dmu_tx_t
*tx
)
2192 if (!dmu_tx_is_syncing(tx
))
2195 if (owner
!= NULL
) {
2196 VERIFY3P(ds
->ds_owner
, ==, owner
);
2197 dsl_dataset_long_rele(ds
, owner
);
2200 held
= dsl_dataset_long_held(ds
);
2203 dsl_dataset_long_hold(ds
, owner
);
2206 return (SET_ERROR(EBUSY
));
2211 typedef struct dsl_dataset_rollback_arg
{
2212 const char *ddra_fsname
;
2213 const char *ddra_tosnap
;
2215 nvlist_t
*ddra_result
;
2216 } dsl_dataset_rollback_arg_t
;
2219 dsl_dataset_rollback_check(void *arg
, dmu_tx_t
*tx
)
2221 dsl_dataset_rollback_arg_t
*ddra
= arg
;
2222 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
2224 int64_t unused_refres_delta
;
2227 nvlist_t
*proprequest
, *bookmarks
;
2229 error
= dsl_dataset_hold(dp
, ddra
->ddra_fsname
, FTAG
, &ds
);
2233 /* must not be a snapshot */
2234 if (ds
->ds_is_snapshot
) {
2235 dsl_dataset_rele(ds
, FTAG
);
2236 return (SET_ERROR(EINVAL
));
2239 /* must have a most recent snapshot */
2240 if (dsl_dataset_phys(ds
)->ds_prev_snap_txg
< TXG_INITIAL
) {
2241 dsl_dataset_rele(ds
, FTAG
);
2242 return (SET_ERROR(EINVAL
));
2246 * No rollback to a snapshot created in the current txg, because
2247 * the rollback may dirty the dataset and create blocks that are
2248 * not reachable from the rootbp while having a birth txg that
2249 * falls into the snapshot's range.
2251 if (dmu_tx_is_syncing(tx
) &&
2252 dsl_dataset_phys(ds
)->ds_prev_snap_txg
>= tx
->tx_txg
) {
2253 dsl_dataset_rele(ds
, FTAG
);
2254 return (SET_ERROR(EAGAIN
));
2258 * If the expected target snapshot is specified, then check that
2259 * the latest snapshot is it.
2261 if (ddra
->ddra_tosnap
!= NULL
) {
2262 char namebuf
[ZFS_MAX_DATASET_NAME_LEN
];
2264 dsl_dataset_name(ds
->ds_prev
, namebuf
);
2265 if (strcmp(namebuf
, ddra
->ddra_tosnap
) != 0)
2266 return (SET_ERROR(EXDEV
));
2269 /* must not have any bookmarks after the most recent snapshot */
2270 proprequest
= fnvlist_alloc();
2271 fnvlist_add_boolean(proprequest
, zfs_prop_to_name(ZFS_PROP_CREATETXG
));
2272 bookmarks
= fnvlist_alloc();
2273 error
= dsl_get_bookmarks_impl(ds
, proprequest
, bookmarks
);
2274 fnvlist_free(proprequest
);
2277 for (pair
= nvlist_next_nvpair(bookmarks
, NULL
);
2278 pair
!= NULL
; pair
= nvlist_next_nvpair(bookmarks
, pair
)) {
2280 fnvlist_lookup_nvlist(fnvpair_value_nvlist(pair
),
2281 zfs_prop_to_name(ZFS_PROP_CREATETXG
));
2282 uint64_t createtxg
= fnvlist_lookup_uint64(valuenv
, "value");
2283 if (createtxg
> dsl_dataset_phys(ds
)->ds_prev_snap_txg
) {
2284 fnvlist_free(bookmarks
);
2285 dsl_dataset_rele(ds
, FTAG
);
2286 return (SET_ERROR(EEXIST
));
2289 fnvlist_free(bookmarks
);
2291 error
= dsl_dataset_handoff_check(ds
, ddra
->ddra_owner
, tx
);
2293 dsl_dataset_rele(ds
, FTAG
);
2298 * Check if the snap we are rolling back to uses more than
2301 if (ds
->ds_quota
!= 0 &&
2302 dsl_dataset_phys(ds
->ds_prev
)->ds_referenced_bytes
> ds
->ds_quota
) {
2303 dsl_dataset_rele(ds
, FTAG
);
2304 return (SET_ERROR(EDQUOT
));
2308 * When we do the clone swap, we will temporarily use more space
2309 * due to the refreservation (the head will no longer have any
2310 * unique space, so the entire amount of the refreservation will need
2311 * to be free). We will immediately destroy the clone, freeing
2312 * this space, but the freeing happens over many txg's.
2314 unused_refres_delta
= (int64_t)MIN(ds
->ds_reserved
,
2315 dsl_dataset_phys(ds
)->ds_unique_bytes
);
2317 if (unused_refres_delta
> 0 &&
2318 unused_refres_delta
>
2319 dsl_dir_space_available(ds
->ds_dir
, NULL
, 0, TRUE
)) {
2320 dsl_dataset_rele(ds
, FTAG
);
2321 return (SET_ERROR(ENOSPC
));
2324 dsl_dataset_rele(ds
, FTAG
);
2329 dsl_dataset_rollback_sync(void *arg
, dmu_tx_t
*tx
)
2331 dsl_dataset_rollback_arg_t
*ddra
= arg
;
2332 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
2333 dsl_dataset_t
*ds
, *clone
;
2335 char namebuf
[ZFS_MAX_DATASET_NAME_LEN
];
2337 VERIFY0(dsl_dataset_hold(dp
, ddra
->ddra_fsname
, FTAG
, &ds
));
2339 dsl_dataset_name(ds
->ds_prev
, namebuf
);
2340 fnvlist_add_string(ddra
->ddra_result
, "target", namebuf
);
2342 cloneobj
= dsl_dataset_create_sync(ds
->ds_dir
, "%rollback",
2343 ds
->ds_prev
, DS_CREATE_FLAG_NODIRTY
, kcred
, tx
);
2345 VERIFY0(dsl_dataset_hold_obj(dp
, cloneobj
, FTAG
, &clone
));
2347 dsl_dataset_clone_swap_sync_impl(clone
, ds
, tx
);
2348 dsl_dataset_zero_zil(ds
, tx
);
2350 dsl_destroy_head_sync_impl(clone
, tx
);
2352 dsl_dataset_rele(clone
, FTAG
);
2353 dsl_dataset_rele(ds
, FTAG
);
2357 * Rolls back the given filesystem or volume to the most recent snapshot.
2358 * The name of the most recent snapshot will be returned under key "target"
2359 * in the result nvlist.
2362 * - The existing dataset MUST be owned by the specified owner at entry
2363 * - Upon return, dataset will still be held by the same owner, whether we
2366 * This mode is required any time the existing filesystem is mounted. See
2367 * notes above zfs_suspend_fs() for further details.
2370 dsl_dataset_rollback(const char *fsname
, const char *tosnap
, void *owner
,
2373 dsl_dataset_rollback_arg_t ddra
;
2375 ddra
.ddra_fsname
= fsname
;
2376 ddra
.ddra_tosnap
= tosnap
;
2377 ddra
.ddra_owner
= owner
;
2378 ddra
.ddra_result
= result
;
2380 return (dsl_sync_task(fsname
, dsl_dataset_rollback_check
,
2381 dsl_dataset_rollback_sync
, &ddra
,
2382 1, ZFS_SPACE_CHECK_RESERVED
));
2385 struct promotenode
{
2390 typedef struct dsl_dataset_promote_arg
{
2391 const char *ddpa_clonename
;
2392 dsl_dataset_t
*ddpa_clone
;
2393 list_t shared_snaps
, origin_snaps
, clone_snaps
;
2394 dsl_dataset_t
*origin_origin
; /* origin of the origin */
2395 uint64_t used
, comp
, uncomp
, unique
, cloneusedsnap
, originusedsnap
;
2398 } dsl_dataset_promote_arg_t
;
2400 static int snaplist_space(list_t
*l
, uint64_t mintxg
, uint64_t *spacep
);
2401 static int promote_hold(dsl_dataset_promote_arg_t
*ddpa
, dsl_pool_t
*dp
,
2403 static void promote_rele(dsl_dataset_promote_arg_t
*ddpa
, void *tag
);
2406 dsl_dataset_promote_check(void *arg
, dmu_tx_t
*tx
)
2408 dsl_dataset_promote_arg_t
*ddpa
= arg
;
2409 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
2411 struct promotenode
*snap
;
2412 dsl_dataset_t
*origin_ds
;
2416 size_t max_snap_len
;
2418 err
= promote_hold(ddpa
, dp
, FTAG
);
2422 hds
= ddpa
->ddpa_clone
;
2423 max_snap_len
= MAXNAMELEN
- strlen(ddpa
->ddpa_clonename
) - 1;
2425 if (dsl_dataset_phys(hds
)->ds_flags
& DS_FLAG_NOPROMOTE
) {
2426 promote_rele(ddpa
, FTAG
);
2427 return (SET_ERROR(EXDEV
));
2431 * Compute and check the amount of space to transfer. Since this is
2432 * so expensive, don't do the preliminary check.
2434 if (!dmu_tx_is_syncing(tx
)) {
2435 promote_rele(ddpa
, FTAG
);
2439 snap
= list_head(&ddpa
->shared_snaps
);
2441 err
= SET_ERROR(ENOENT
);
2444 origin_ds
= snap
->ds
;
2446 /* compute origin's new unique space */
2447 snap
= list_tail(&ddpa
->clone_snaps
);
2448 ASSERT3U(dsl_dataset_phys(snap
->ds
)->ds_prev_snap_obj
, ==,
2449 origin_ds
->ds_object
);
2450 dsl_deadlist_space_range(&snap
->ds
->ds_deadlist
,
2451 dsl_dataset_phys(origin_ds
)->ds_prev_snap_txg
, UINT64_MAX
,
2452 &ddpa
->unique
, &unused
, &unused
);
2455 * Walk the snapshots that we are moving
2457 * Compute space to transfer. Consider the incremental changes
2458 * to used by each snapshot:
2459 * (my used) = (prev's used) + (blocks born) - (blocks killed)
2460 * So each snapshot gave birth to:
2461 * (blocks born) = (my used) - (prev's used) + (blocks killed)
2462 * So a sequence would look like:
2463 * (uN - u(N-1) + kN) + ... + (u1 - u0 + k1) + (u0 - 0 + k0)
2464 * Which simplifies to:
2465 * uN + kN + kN-1 + ... + k1 + k0
2466 * Note however, if we stop before we reach the ORIGIN we get:
2467 * uN + kN + kN-1 + ... + kM - uM-1
2470 ddpa
->used
= dsl_dataset_phys(origin_ds
)->ds_referenced_bytes
;
2471 ddpa
->comp
= dsl_dataset_phys(origin_ds
)->ds_compressed_bytes
;
2472 ddpa
->uncomp
= dsl_dataset_phys(origin_ds
)->ds_uncompressed_bytes
;
2473 for (snap
= list_head(&ddpa
->shared_snaps
); snap
;
2474 snap
= list_next(&ddpa
->shared_snaps
, snap
)) {
2475 uint64_t val
, dlused
, dlcomp
, dluncomp
;
2476 dsl_dataset_t
*ds
= snap
->ds
;
2481 * If there are long holds, we won't be able to evict
2484 if (dsl_dataset_long_held(ds
)) {
2485 err
= SET_ERROR(EBUSY
);
2489 /* Check that the snapshot name does not conflict */
2490 VERIFY0(dsl_dataset_get_snapname(ds
));
2491 if (strlen(ds
->ds_snapname
) >= max_snap_len
) {
2492 err
= SET_ERROR(ENAMETOOLONG
);
2495 err
= dsl_dataset_snap_lookup(hds
, ds
->ds_snapname
, &val
);
2497 (void) strcpy(ddpa
->err_ds
, snap
->ds
->ds_snapname
);
2498 err
= SET_ERROR(EEXIST
);
2504 /* The very first snapshot does not have a deadlist */
2505 if (dsl_dataset_phys(ds
)->ds_prev_snap_obj
== 0)
2508 dsl_deadlist_space(&ds
->ds_deadlist
,
2509 &dlused
, &dlcomp
, &dluncomp
);
2510 ddpa
->used
+= dlused
;
2511 ddpa
->comp
+= dlcomp
;
2512 ddpa
->uncomp
+= dluncomp
;
2516 * If we are a clone of a clone then we never reached ORIGIN,
2517 * so we need to subtract out the clone origin's used space.
2519 if (ddpa
->origin_origin
) {
2521 dsl_dataset_phys(ddpa
->origin_origin
)->ds_referenced_bytes
;
2523 dsl_dataset_phys(ddpa
->origin_origin
)->ds_compressed_bytes
;
2525 dsl_dataset_phys(ddpa
->origin_origin
)->
2526 ds_uncompressed_bytes
;
2529 /* Check that there is enough space and limit headroom here */
2530 err
= dsl_dir_transfer_possible(origin_ds
->ds_dir
, hds
->ds_dir
,
2531 0, ss_mv_cnt
, ddpa
->used
, ddpa
->cr
);
2536 * Compute the amounts of space that will be used by snapshots
2537 * after the promotion (for both origin and clone). For each,
2538 * it is the amount of space that will be on all of their
2539 * deadlists (that was not born before their new origin).
2541 if (dsl_dir_phys(hds
->ds_dir
)->dd_flags
& DD_FLAG_USED_BREAKDOWN
) {
2545 * Note, typically this will not be a clone of a clone,
2546 * so dd_origin_txg will be < TXG_INITIAL, so
2547 * these snaplist_space() -> dsl_deadlist_space_range()
2548 * calls will be fast because they do not have to
2549 * iterate over all bps.
2551 snap
= list_head(&ddpa
->origin_snaps
);
2553 err
= SET_ERROR(ENOENT
);
2556 err
= snaplist_space(&ddpa
->shared_snaps
,
2557 snap
->ds
->ds_dir
->dd_origin_txg
, &ddpa
->cloneusedsnap
);
2561 err
= snaplist_space(&ddpa
->clone_snaps
,
2562 snap
->ds
->ds_dir
->dd_origin_txg
, &space
);
2565 ddpa
->cloneusedsnap
+= space
;
2567 if (dsl_dir_phys(origin_ds
->ds_dir
)->dd_flags
&
2568 DD_FLAG_USED_BREAKDOWN
) {
2569 err
= snaplist_space(&ddpa
->origin_snaps
,
2570 dsl_dataset_phys(origin_ds
)->ds_creation_txg
,
2571 &ddpa
->originusedsnap
);
2577 promote_rele(ddpa
, FTAG
);
2582 dsl_dataset_promote_sync(void *arg
, dmu_tx_t
*tx
)
2584 dsl_dataset_promote_arg_t
*ddpa
= arg
;
2585 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
2587 struct promotenode
*snap
;
2588 dsl_dataset_t
*origin_ds
;
2589 dsl_dataset_t
*origin_head
;
2591 dsl_dir_t
*odd
= NULL
;
2592 uint64_t oldnext_obj
;
2595 VERIFY0(promote_hold(ddpa
, dp
, FTAG
));
2596 hds
= ddpa
->ddpa_clone
;
2598 ASSERT0(dsl_dataset_phys(hds
)->ds_flags
& DS_FLAG_NOPROMOTE
);
2600 snap
= list_head(&ddpa
->shared_snaps
);
2601 origin_ds
= snap
->ds
;
2604 snap
= list_head(&ddpa
->origin_snaps
);
2605 origin_head
= snap
->ds
;
2608 * We need to explicitly open odd, since origin_ds's dd will be
2611 VERIFY0(dsl_dir_hold_obj(dp
, origin_ds
->ds_dir
->dd_object
,
2614 /* change origin's next snap */
2615 dmu_buf_will_dirty(origin_ds
->ds_dbuf
, tx
);
2616 oldnext_obj
= dsl_dataset_phys(origin_ds
)->ds_next_snap_obj
;
2617 snap
= list_tail(&ddpa
->clone_snaps
);
2618 ASSERT3U(dsl_dataset_phys(snap
->ds
)->ds_prev_snap_obj
, ==,
2619 origin_ds
->ds_object
);
2620 dsl_dataset_phys(origin_ds
)->ds_next_snap_obj
= snap
->ds
->ds_object
;
2622 /* change the origin's next clone */
2623 if (dsl_dataset_phys(origin_ds
)->ds_next_clones_obj
) {
2624 dsl_dataset_remove_from_next_clones(origin_ds
,
2625 snap
->ds
->ds_object
, tx
);
2626 VERIFY0(zap_add_int(dp
->dp_meta_objset
,
2627 dsl_dataset_phys(origin_ds
)->ds_next_clones_obj
,
2632 dmu_buf_will_dirty(dd
->dd_dbuf
, tx
);
2633 ASSERT3U(dsl_dir_phys(dd
)->dd_origin_obj
, ==, origin_ds
->ds_object
);
2634 dsl_dir_phys(dd
)->dd_origin_obj
= dsl_dir_phys(odd
)->dd_origin_obj
;
2635 dd
->dd_origin_txg
= origin_head
->ds_dir
->dd_origin_txg
;
2636 dmu_buf_will_dirty(odd
->dd_dbuf
, tx
);
2637 dsl_dir_phys(odd
)->dd_origin_obj
= origin_ds
->ds_object
;
2638 origin_head
->ds_dir
->dd_origin_txg
=
2639 dsl_dataset_phys(origin_ds
)->ds_creation_txg
;
2641 /* change dd_clone entries */
2642 if (spa_version(dp
->dp_spa
) >= SPA_VERSION_DIR_CLONES
) {
2643 VERIFY0(zap_remove_int(dp
->dp_meta_objset
,
2644 dsl_dir_phys(odd
)->dd_clones
, hds
->ds_object
, tx
));
2645 VERIFY0(zap_add_int(dp
->dp_meta_objset
,
2646 dsl_dir_phys(ddpa
->origin_origin
->ds_dir
)->dd_clones
,
2647 hds
->ds_object
, tx
));
2649 VERIFY0(zap_remove_int(dp
->dp_meta_objset
,
2650 dsl_dir_phys(ddpa
->origin_origin
->ds_dir
)->dd_clones
,
2651 origin_head
->ds_object
, tx
));
2652 if (dsl_dir_phys(dd
)->dd_clones
== 0) {
2653 dsl_dir_phys(dd
)->dd_clones
=
2654 zap_create(dp
->dp_meta_objset
, DMU_OT_DSL_CLONES
,
2655 DMU_OT_NONE
, 0, tx
);
2657 VERIFY0(zap_add_int(dp
->dp_meta_objset
,
2658 dsl_dir_phys(dd
)->dd_clones
, origin_head
->ds_object
, tx
));
2661 /* move snapshots to this dir */
2662 for (snap
= list_head(&ddpa
->shared_snaps
); snap
;
2663 snap
= list_next(&ddpa
->shared_snaps
, snap
)) {
2664 dsl_dataset_t
*ds
= snap
->ds
;
2667 * Property callbacks are registered to a particular
2668 * dsl_dir. Since ours is changing, evict the objset
2669 * so that they will be unregistered from the old dsl_dir.
2671 if (ds
->ds_objset
) {
2672 dmu_objset_evict(ds
->ds_objset
);
2673 ds
->ds_objset
= NULL
;
2676 /* move snap name entry */
2677 VERIFY0(dsl_dataset_get_snapname(ds
));
2678 VERIFY0(dsl_dataset_snap_remove(origin_head
,
2679 ds
->ds_snapname
, tx
, B_TRUE
));
2680 VERIFY0(zap_add(dp
->dp_meta_objset
,
2681 dsl_dataset_phys(hds
)->ds_snapnames_zapobj
, ds
->ds_snapname
,
2682 8, 1, &ds
->ds_object
, tx
));
2683 dsl_fs_ss_count_adjust(hds
->ds_dir
, 1,
2684 DD_FIELD_SNAPSHOT_COUNT
, tx
);
2686 /* change containing dsl_dir */
2687 dmu_buf_will_dirty(ds
->ds_dbuf
, tx
);
2688 ASSERT3U(dsl_dataset_phys(ds
)->ds_dir_obj
, ==, odd
->dd_object
);
2689 dsl_dataset_phys(ds
)->ds_dir_obj
= dd
->dd_object
;
2690 ASSERT3P(ds
->ds_dir
, ==, odd
);
2691 dsl_dir_rele(ds
->ds_dir
, ds
);
2692 VERIFY0(dsl_dir_hold_obj(dp
, dd
->dd_object
,
2693 NULL
, ds
, &ds
->ds_dir
));
2695 /* move any clone references */
2696 if (dsl_dataset_phys(ds
)->ds_next_clones_obj
&&
2697 spa_version(dp
->dp_spa
) >= SPA_VERSION_DIR_CLONES
) {
2701 for (zap_cursor_init(&zc
, dp
->dp_meta_objset
,
2702 dsl_dataset_phys(ds
)->ds_next_clones_obj
);
2703 zap_cursor_retrieve(&zc
, &za
) == 0;
2704 zap_cursor_advance(&zc
)) {
2705 dsl_dataset_t
*cnds
;
2708 if (za
.za_first_integer
== oldnext_obj
) {
2710 * We've already moved the
2711 * origin's reference.
2716 VERIFY0(dsl_dataset_hold_obj(dp
,
2717 za
.za_first_integer
, FTAG
, &cnds
));
2718 o
= dsl_dir_phys(cnds
->ds_dir
)->
2719 dd_head_dataset_obj
;
2721 VERIFY0(zap_remove_int(dp
->dp_meta_objset
,
2722 dsl_dir_phys(odd
)->dd_clones
, o
, tx
));
2723 VERIFY0(zap_add_int(dp
->dp_meta_objset
,
2724 dsl_dir_phys(dd
)->dd_clones
, o
, tx
));
2725 dsl_dataset_rele(cnds
, FTAG
);
2727 zap_cursor_fini(&zc
);
2730 ASSERT(!dsl_prop_hascb(ds
));
2734 * Change space accounting.
2735 * Note, pa->*usedsnap and dd_used_breakdown[SNAP] will either
2736 * both be valid, or both be 0 (resulting in delta == 0). This
2737 * is true for each of {clone,origin} independently.
2740 delta
= ddpa
->cloneusedsnap
-
2741 dsl_dir_phys(dd
)->dd_used_breakdown
[DD_USED_SNAP
];
2742 ASSERT3S(delta
, >=, 0);
2743 ASSERT3U(ddpa
->used
, >=, delta
);
2744 dsl_dir_diduse_space(dd
, DD_USED_SNAP
, delta
, 0, 0, tx
);
2745 dsl_dir_diduse_space(dd
, DD_USED_HEAD
,
2746 ddpa
->used
- delta
, ddpa
->comp
, ddpa
->uncomp
, tx
);
2748 delta
= ddpa
->originusedsnap
-
2749 dsl_dir_phys(odd
)->dd_used_breakdown
[DD_USED_SNAP
];
2750 ASSERT3S(delta
, <=, 0);
2751 ASSERT3U(ddpa
->used
, >=, -delta
);
2752 dsl_dir_diduse_space(odd
, DD_USED_SNAP
, delta
, 0, 0, tx
);
2753 dsl_dir_diduse_space(odd
, DD_USED_HEAD
,
2754 -ddpa
->used
- delta
, -ddpa
->comp
, -ddpa
->uncomp
, tx
);
2756 dsl_dataset_phys(origin_ds
)->ds_unique_bytes
= ddpa
->unique
;
2758 /* log history record */
2759 spa_history_log_internal_ds(hds
, "promote", tx
, "");
2761 dsl_dir_rele(odd
, FTAG
);
2762 promote_rele(ddpa
, FTAG
);
2766 * Make a list of dsl_dataset_t's for the snapshots between first_obj
2767 * (exclusive) and last_obj (inclusive). The list will be in reverse
2768 * order (last_obj will be the list_head()). If first_obj == 0, do all
2769 * snapshots back to this dataset's origin.
2772 snaplist_make(dsl_pool_t
*dp
,
2773 uint64_t first_obj
, uint64_t last_obj
, list_t
*l
, void *tag
)
2775 uint64_t obj
= last_obj
;
2777 list_create(l
, sizeof (struct promotenode
),
2778 offsetof(struct promotenode
, link
));
2780 while (obj
!= first_obj
) {
2782 struct promotenode
*snap
;
2785 err
= dsl_dataset_hold_obj(dp
, obj
, tag
, &ds
);
2786 ASSERT(err
!= ENOENT
);
2791 first_obj
= dsl_dir_phys(ds
->ds_dir
)->dd_origin_obj
;
2793 snap
= kmem_alloc(sizeof (*snap
), KM_SLEEP
);
2795 list_insert_tail(l
, snap
);
2796 obj
= dsl_dataset_phys(ds
)->ds_prev_snap_obj
;
2803 snaplist_space(list_t
*l
, uint64_t mintxg
, uint64_t *spacep
)
2805 struct promotenode
*snap
;
2808 for (snap
= list_head(l
); snap
; snap
= list_next(l
, snap
)) {
2809 uint64_t used
, comp
, uncomp
;
2810 dsl_deadlist_space_range(&snap
->ds
->ds_deadlist
,
2811 mintxg
, UINT64_MAX
, &used
, &comp
, &uncomp
);
2818 snaplist_destroy(list_t
*l
, void *tag
)
2820 struct promotenode
*snap
;
2822 if (l
== NULL
|| !list_link_active(&l
->list_head
))
2825 while ((snap
= list_tail(l
)) != NULL
) {
2826 list_remove(l
, snap
);
2827 dsl_dataset_rele(snap
->ds
, tag
);
2828 kmem_free(snap
, sizeof (*snap
));
2834 promote_hold(dsl_dataset_promote_arg_t
*ddpa
, dsl_pool_t
*dp
, void *tag
)
2838 struct promotenode
*snap
;
2840 error
= dsl_dataset_hold(dp
, ddpa
->ddpa_clonename
, tag
,
2844 dd
= ddpa
->ddpa_clone
->ds_dir
;
2846 if (ddpa
->ddpa_clone
->ds_is_snapshot
||
2847 !dsl_dir_is_clone(dd
)) {
2848 dsl_dataset_rele(ddpa
->ddpa_clone
, tag
);
2849 return (SET_ERROR(EINVAL
));
2852 error
= snaplist_make(dp
, 0, dsl_dir_phys(dd
)->dd_origin_obj
,
2853 &ddpa
->shared_snaps
, tag
);
2857 error
= snaplist_make(dp
, 0, ddpa
->ddpa_clone
->ds_object
,
2858 &ddpa
->clone_snaps
, tag
);
2862 snap
= list_head(&ddpa
->shared_snaps
);
2863 ASSERT3U(snap
->ds
->ds_object
, ==, dsl_dir_phys(dd
)->dd_origin_obj
);
2864 error
= snaplist_make(dp
, dsl_dir_phys(dd
)->dd_origin_obj
,
2865 dsl_dir_phys(snap
->ds
->ds_dir
)->dd_head_dataset_obj
,
2866 &ddpa
->origin_snaps
, tag
);
2870 if (dsl_dir_phys(snap
->ds
->ds_dir
)->dd_origin_obj
!= 0) {
2871 error
= dsl_dataset_hold_obj(dp
,
2872 dsl_dir_phys(snap
->ds
->ds_dir
)->dd_origin_obj
,
2873 tag
, &ddpa
->origin_origin
);
2879 promote_rele(ddpa
, tag
);
2884 promote_rele(dsl_dataset_promote_arg_t
*ddpa
, void *tag
)
2886 snaplist_destroy(&ddpa
->shared_snaps
, tag
);
2887 snaplist_destroy(&ddpa
->clone_snaps
, tag
);
2888 snaplist_destroy(&ddpa
->origin_snaps
, tag
);
2889 if (ddpa
->origin_origin
!= NULL
)
2890 dsl_dataset_rele(ddpa
->origin_origin
, tag
);
2891 dsl_dataset_rele(ddpa
->ddpa_clone
, tag
);
2897 * If it fails due to a conflicting snapshot name, "conflsnap" will be filled
2898 * in with the name. (It must be at least ZFS_MAX_DATASET_NAME_LEN bytes long.)
2901 dsl_dataset_promote(const char *name
, char *conflsnap
)
2903 dsl_dataset_promote_arg_t ddpa
= { 0 };
2909 * We will modify space proportional to the number of
2910 * snapshots. Compute numsnaps.
2912 error
= dmu_objset_hold(name
, FTAG
, &os
);
2915 error
= zap_count(dmu_objset_pool(os
)->dp_meta_objset
,
2916 dsl_dataset_phys(dmu_objset_ds(os
))->ds_snapnames_zapobj
,
2918 dmu_objset_rele(os
, FTAG
);
2922 ddpa
.ddpa_clonename
= name
;
2923 ddpa
.err_ds
= conflsnap
;
2926 return (dsl_sync_task(name
, dsl_dataset_promote_check
,
2927 dsl_dataset_promote_sync
, &ddpa
,
2928 2 + numsnaps
, ZFS_SPACE_CHECK_RESERVED
));
2932 dsl_dataset_clone_swap_check_impl(dsl_dataset_t
*clone
,
2933 dsl_dataset_t
*origin_head
, boolean_t force
, void *owner
, dmu_tx_t
*tx
)
2936 * "slack" factor for received datasets with refquota set on them.
2937 * See the bottom of this function for details on its use.
2939 uint64_t refquota_slack
= (uint64_t)DMU_MAX_ACCESS
*
2940 spa_asize_inflation
;
2941 int64_t unused_refres_delta
;
2943 /* they should both be heads */
2944 if (clone
->ds_is_snapshot
||
2945 origin_head
->ds_is_snapshot
)
2946 return (SET_ERROR(EINVAL
));
2948 /* if we are not forcing, the branch point should be just before them */
2949 if (!force
&& clone
->ds_prev
!= origin_head
->ds_prev
)
2950 return (SET_ERROR(EINVAL
));
2952 /* clone should be the clone (unless they are unrelated) */
2953 if (clone
->ds_prev
!= NULL
&&
2954 clone
->ds_prev
!= clone
->ds_dir
->dd_pool
->dp_origin_snap
&&
2955 origin_head
->ds_dir
!= clone
->ds_prev
->ds_dir
)
2956 return (SET_ERROR(EINVAL
));
2958 /* the clone should be a child of the origin */
2959 if (clone
->ds_dir
->dd_parent
!= origin_head
->ds_dir
)
2960 return (SET_ERROR(EINVAL
));
2962 /* origin_head shouldn't be modified unless 'force' */
2964 dsl_dataset_modified_since_snap(origin_head
, origin_head
->ds_prev
))
2965 return (SET_ERROR(ETXTBSY
));
2967 /* origin_head should have no long holds (e.g. is not mounted) */
2968 if (dsl_dataset_handoff_check(origin_head
, owner
, tx
))
2969 return (SET_ERROR(EBUSY
));
2971 /* check amount of any unconsumed refreservation */
2972 unused_refres_delta
=
2973 (int64_t)MIN(origin_head
->ds_reserved
,
2974 dsl_dataset_phys(origin_head
)->ds_unique_bytes
) -
2975 (int64_t)MIN(origin_head
->ds_reserved
,
2976 dsl_dataset_phys(clone
)->ds_unique_bytes
);
2978 if (unused_refres_delta
> 0 &&
2979 unused_refres_delta
>
2980 dsl_dir_space_available(origin_head
->ds_dir
, NULL
, 0, TRUE
))
2981 return (SET_ERROR(ENOSPC
));
2984 * The clone can't be too much over the head's refquota.
2986 * To ensure that the entire refquota can be used, we allow one
2987 * transaction to exceed the the refquota. Therefore, this check
2988 * needs to also allow for the space referenced to be more than the
2989 * refquota. The maximum amount of space that one transaction can use
2990 * on disk is DMU_MAX_ACCESS * spa_asize_inflation. Allowing this
2991 * overage ensures that we are able to receive a filesystem that
2992 * exceeds the refquota on the source system.
2994 * So that overage is the refquota_slack we use below.
2996 if (origin_head
->ds_quota
!= 0 &&
2997 dsl_dataset_phys(clone
)->ds_referenced_bytes
>
2998 origin_head
->ds_quota
+ refquota_slack
)
2999 return (SET_ERROR(EDQUOT
));
3005 dsl_dataset_clone_swap_sync_impl(dsl_dataset_t
*clone
,
3006 dsl_dataset_t
*origin_head
, dmu_tx_t
*tx
)
3008 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
3009 int64_t unused_refres_delta
;
3012 ASSERT(clone
->ds_reserved
== 0);
3014 * NOTE: On DEBUG kernels there could be a race between this and
3015 * the check function if spa_asize_inflation is adjusted...
3017 ASSERT(origin_head
->ds_quota
== 0 ||
3018 dsl_dataset_phys(clone
)->ds_unique_bytes
<= origin_head
->ds_quota
+
3019 DMU_MAX_ACCESS
* spa_asize_inflation
);
3020 ASSERT3P(clone
->ds_prev
, ==, origin_head
->ds_prev
);
3023 * Swap per-dataset feature flags.
3025 for (spa_feature_t f
= 0; f
< SPA_FEATURES
; f
++) {
3026 boolean_t clone_inuse
;
3027 boolean_t origin_head_inuse
;
3029 if (!(spa_feature_table
[f
].fi_flags
&
3030 ZFEATURE_FLAG_PER_DATASET
)) {
3031 ASSERT(!clone
->ds_feature_inuse
[f
]);
3032 ASSERT(!origin_head
->ds_feature_inuse
[f
]);
3036 clone_inuse
= clone
->ds_feature_inuse
[f
];
3037 origin_head_inuse
= origin_head
->ds_feature_inuse
[f
];
3040 dsl_dataset_deactivate_feature(clone
->ds_object
, f
, tx
);
3041 clone
->ds_feature_inuse
[f
] = B_FALSE
;
3043 if (origin_head_inuse
) {
3044 dsl_dataset_deactivate_feature(origin_head
->ds_object
,
3046 origin_head
->ds_feature_inuse
[f
] = B_FALSE
;
3049 dsl_dataset_activate_feature(origin_head
->ds_object
,
3051 origin_head
->ds_feature_inuse
[f
] = B_TRUE
;
3053 if (origin_head_inuse
) {
3054 dsl_dataset_activate_feature(clone
->ds_object
, f
, tx
);
3055 clone
->ds_feature_inuse
[f
] = B_TRUE
;
3059 dmu_buf_will_dirty(clone
->ds_dbuf
, tx
);
3060 dmu_buf_will_dirty(origin_head
->ds_dbuf
, tx
);
3062 if (clone
->ds_objset
!= NULL
) {
3063 dmu_objset_evict(clone
->ds_objset
);
3064 clone
->ds_objset
= NULL
;
3067 if (origin_head
->ds_objset
!= NULL
) {
3068 dmu_objset_evict(origin_head
->ds_objset
);
3069 origin_head
->ds_objset
= NULL
;
3072 unused_refres_delta
=
3073 (int64_t)MIN(origin_head
->ds_reserved
,
3074 dsl_dataset_phys(origin_head
)->ds_unique_bytes
) -
3075 (int64_t)MIN(origin_head
->ds_reserved
,
3076 dsl_dataset_phys(clone
)->ds_unique_bytes
);
3079 * Reset origin's unique bytes, if it exists.
3081 if (clone
->ds_prev
) {
3082 dsl_dataset_t
*origin
= clone
->ds_prev
;
3083 uint64_t comp
, uncomp
;
3085 dmu_buf_will_dirty(origin
->ds_dbuf
, tx
);
3086 dsl_deadlist_space_range(&clone
->ds_deadlist
,
3087 dsl_dataset_phys(origin
)->ds_prev_snap_txg
, UINT64_MAX
,
3088 &dsl_dataset_phys(origin
)->ds_unique_bytes
, &comp
, &uncomp
);
3093 rrw_enter(&clone
->ds_bp_rwlock
, RW_WRITER
, FTAG
);
3094 rrw_enter(&origin_head
->ds_bp_rwlock
, RW_WRITER
, FTAG
);
3095 tmp
= dsl_dataset_phys(origin_head
)->ds_bp
;
3096 dsl_dataset_phys(origin_head
)->ds_bp
=
3097 dsl_dataset_phys(clone
)->ds_bp
;
3098 dsl_dataset_phys(clone
)->ds_bp
= tmp
;
3099 rrw_exit(&origin_head
->ds_bp_rwlock
, FTAG
);
3100 rrw_exit(&clone
->ds_bp_rwlock
, FTAG
);
3103 /* set dd_*_bytes */
3105 int64_t dused
, dcomp
, duncomp
;
3106 uint64_t cdl_used
, cdl_comp
, cdl_uncomp
;
3107 uint64_t odl_used
, odl_comp
, odl_uncomp
;
3109 ASSERT3U(dsl_dir_phys(clone
->ds_dir
)->
3110 dd_used_breakdown
[DD_USED_SNAP
], ==, 0);
3112 dsl_deadlist_space(&clone
->ds_deadlist
,
3113 &cdl_used
, &cdl_comp
, &cdl_uncomp
);
3114 dsl_deadlist_space(&origin_head
->ds_deadlist
,
3115 &odl_used
, &odl_comp
, &odl_uncomp
);
3117 dused
= dsl_dataset_phys(clone
)->ds_referenced_bytes
+
3119 (dsl_dataset_phys(origin_head
)->ds_referenced_bytes
+
3121 dcomp
= dsl_dataset_phys(clone
)->ds_compressed_bytes
+
3123 (dsl_dataset_phys(origin_head
)->ds_compressed_bytes
+
3125 duncomp
= dsl_dataset_phys(clone
)->ds_uncompressed_bytes
+
3127 (dsl_dataset_phys(origin_head
)->ds_uncompressed_bytes
+
3130 dsl_dir_diduse_space(origin_head
->ds_dir
, DD_USED_HEAD
,
3131 dused
, dcomp
, duncomp
, tx
);
3132 dsl_dir_diduse_space(clone
->ds_dir
, DD_USED_HEAD
,
3133 -dused
, -dcomp
, -duncomp
, tx
);
3136 * The difference in the space used by snapshots is the
3137 * difference in snapshot space due to the head's
3138 * deadlist (since that's the only thing that's
3139 * changing that affects the snapused).
3141 dsl_deadlist_space_range(&clone
->ds_deadlist
,
3142 origin_head
->ds_dir
->dd_origin_txg
, UINT64_MAX
,
3143 &cdl_used
, &cdl_comp
, &cdl_uncomp
);
3144 dsl_deadlist_space_range(&origin_head
->ds_deadlist
,
3145 origin_head
->ds_dir
->dd_origin_txg
, UINT64_MAX
,
3146 &odl_used
, &odl_comp
, &odl_uncomp
);
3147 dsl_dir_transfer_space(origin_head
->ds_dir
, cdl_used
- odl_used
,
3148 DD_USED_HEAD
, DD_USED_SNAP
, tx
);
3151 /* swap ds_*_bytes */
3152 SWITCH64(dsl_dataset_phys(origin_head
)->ds_referenced_bytes
,
3153 dsl_dataset_phys(clone
)->ds_referenced_bytes
);
3154 SWITCH64(dsl_dataset_phys(origin_head
)->ds_compressed_bytes
,
3155 dsl_dataset_phys(clone
)->ds_compressed_bytes
);
3156 SWITCH64(dsl_dataset_phys(origin_head
)->ds_uncompressed_bytes
,
3157 dsl_dataset_phys(clone
)->ds_uncompressed_bytes
);
3158 SWITCH64(dsl_dataset_phys(origin_head
)->ds_unique_bytes
,
3159 dsl_dataset_phys(clone
)->ds_unique_bytes
);
3161 /* apply any parent delta for change in unconsumed refreservation */
3162 dsl_dir_diduse_space(origin_head
->ds_dir
, DD_USED_REFRSRV
,
3163 unused_refres_delta
, 0, 0, tx
);
3168 dsl_deadlist_close(&clone
->ds_deadlist
);
3169 dsl_deadlist_close(&origin_head
->ds_deadlist
);
3170 SWITCH64(dsl_dataset_phys(origin_head
)->ds_deadlist_obj
,
3171 dsl_dataset_phys(clone
)->ds_deadlist_obj
);
3172 dsl_deadlist_open(&clone
->ds_deadlist
, dp
->dp_meta_objset
,
3173 dsl_dataset_phys(clone
)->ds_deadlist_obj
);
3174 dsl_deadlist_open(&origin_head
->ds_deadlist
, dp
->dp_meta_objset
,
3175 dsl_dataset_phys(origin_head
)->ds_deadlist_obj
);
3177 dsl_scan_ds_clone_swapped(origin_head
, clone
, tx
);
3179 spa_history_log_internal_ds(clone
, "clone swap", tx
,
3180 "parent=%s", origin_head
->ds_dir
->dd_myname
);
3184 * Given a pool name and a dataset object number in that pool,
3185 * return the name of that dataset.
3188 dsl_dsobj_to_dsname(char *pname
, uint64_t obj
, char *buf
)
3194 error
= dsl_pool_hold(pname
, FTAG
, &dp
);
3198 error
= dsl_dataset_hold_obj(dp
, obj
, FTAG
, &ds
);
3200 dsl_dataset_name(ds
, buf
);
3201 dsl_dataset_rele(ds
, FTAG
);
3203 dsl_pool_rele(dp
, FTAG
);
3209 dsl_dataset_check_quota(dsl_dataset_t
*ds
, boolean_t check_quota
,
3210 uint64_t asize
, uint64_t inflight
, uint64_t *used
, uint64_t *ref_rsrv
)
3214 ASSERT3S(asize
, >, 0);
3217 * *ref_rsrv is the portion of asize that will come from any
3218 * unconsumed refreservation space.
3222 mutex_enter(&ds
->ds_lock
);
3224 * Make a space adjustment for reserved bytes.
3226 if (ds
->ds_reserved
> dsl_dataset_phys(ds
)->ds_unique_bytes
) {
3228 ds
->ds_reserved
- dsl_dataset_phys(ds
)->ds_unique_bytes
);
3230 (ds
->ds_reserved
- dsl_dataset_phys(ds
)->ds_unique_bytes
);
3232 asize
- MIN(asize
, parent_delta(ds
, asize
+ inflight
));
3235 if (!check_quota
|| ds
->ds_quota
== 0) {
3236 mutex_exit(&ds
->ds_lock
);
3240 * If they are requesting more space, and our current estimate
3241 * is over quota, they get to try again unless the actual
3242 * on-disk is over quota and there are no pending changes (which
3243 * may free up space for us).
3245 if (dsl_dataset_phys(ds
)->ds_referenced_bytes
+ inflight
>=
3248 dsl_dataset_phys(ds
)->ds_referenced_bytes
< ds
->ds_quota
)
3249 error
= SET_ERROR(ERESTART
);
3251 error
= SET_ERROR(EDQUOT
);
3253 mutex_exit(&ds
->ds_lock
);
3258 typedef struct dsl_dataset_set_qr_arg
{
3259 const char *ddsqra_name
;
3260 zprop_source_t ddsqra_source
;
3261 uint64_t ddsqra_value
;
3262 } dsl_dataset_set_qr_arg_t
;
3267 dsl_dataset_set_refquota_check(void *arg
, dmu_tx_t
*tx
)
3269 dsl_dataset_set_qr_arg_t
*ddsqra
= arg
;
3270 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
3275 if (spa_version(dp
->dp_spa
) < SPA_VERSION_REFQUOTA
)
3276 return (SET_ERROR(ENOTSUP
));
3278 error
= dsl_dataset_hold(dp
, ddsqra
->ddsqra_name
, FTAG
, &ds
);
3282 if (ds
->ds_is_snapshot
) {
3283 dsl_dataset_rele(ds
, FTAG
);
3284 return (SET_ERROR(EINVAL
));
3287 error
= dsl_prop_predict(ds
->ds_dir
,
3288 zfs_prop_to_name(ZFS_PROP_REFQUOTA
),
3289 ddsqra
->ddsqra_source
, ddsqra
->ddsqra_value
, &newval
);
3291 dsl_dataset_rele(ds
, FTAG
);
3296 dsl_dataset_rele(ds
, FTAG
);
3300 if (newval
< dsl_dataset_phys(ds
)->ds_referenced_bytes
||
3301 newval
< ds
->ds_reserved
) {
3302 dsl_dataset_rele(ds
, FTAG
);
3303 return (SET_ERROR(ENOSPC
));
3306 dsl_dataset_rele(ds
, FTAG
);
3311 dsl_dataset_set_refquota_sync(void *arg
, dmu_tx_t
*tx
)
3313 dsl_dataset_set_qr_arg_t
*ddsqra
= arg
;
3314 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
3315 dsl_dataset_t
*ds
= NULL
;
3318 VERIFY0(dsl_dataset_hold(dp
, ddsqra
->ddsqra_name
, FTAG
, &ds
));
3320 dsl_prop_set_sync_impl(ds
,
3321 zfs_prop_to_name(ZFS_PROP_REFQUOTA
),
3322 ddsqra
->ddsqra_source
, sizeof (ddsqra
->ddsqra_value
), 1,
3323 &ddsqra
->ddsqra_value
, tx
);
3325 VERIFY0(dsl_prop_get_int_ds(ds
,
3326 zfs_prop_to_name(ZFS_PROP_REFQUOTA
), &newval
));
3328 if (ds
->ds_quota
!= newval
) {
3329 dmu_buf_will_dirty(ds
->ds_dbuf
, tx
);
3330 ds
->ds_quota
= newval
;
3332 dsl_dataset_rele(ds
, FTAG
);
3336 dsl_dataset_set_refquota(const char *dsname
, zprop_source_t source
,
3339 dsl_dataset_set_qr_arg_t ddsqra
;
3341 ddsqra
.ddsqra_name
= dsname
;
3342 ddsqra
.ddsqra_source
= source
;
3343 ddsqra
.ddsqra_value
= refquota
;
3345 return (dsl_sync_task(dsname
, dsl_dataset_set_refquota_check
,
3346 dsl_dataset_set_refquota_sync
, &ddsqra
, 0, ZFS_SPACE_CHECK_NONE
));
3350 dsl_dataset_set_refreservation_check(void *arg
, dmu_tx_t
*tx
)
3352 dsl_dataset_set_qr_arg_t
*ddsqra
= arg
;
3353 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
3356 uint64_t newval
, unique
;
3358 if (spa_version(dp
->dp_spa
) < SPA_VERSION_REFRESERVATION
)
3359 return (SET_ERROR(ENOTSUP
));
3361 error
= dsl_dataset_hold(dp
, ddsqra
->ddsqra_name
, FTAG
, &ds
);
3365 if (ds
->ds_is_snapshot
) {
3366 dsl_dataset_rele(ds
, FTAG
);
3367 return (SET_ERROR(EINVAL
));
3370 error
= dsl_prop_predict(ds
->ds_dir
,
3371 zfs_prop_to_name(ZFS_PROP_REFRESERVATION
),
3372 ddsqra
->ddsqra_source
, ddsqra
->ddsqra_value
, &newval
);
3374 dsl_dataset_rele(ds
, FTAG
);
3379 * If we are doing the preliminary check in open context, the
3380 * space estimates may be inaccurate.
3382 if (!dmu_tx_is_syncing(tx
)) {
3383 dsl_dataset_rele(ds
, FTAG
);
3387 mutex_enter(&ds
->ds_lock
);
3388 if (!DS_UNIQUE_IS_ACCURATE(ds
))
3389 dsl_dataset_recalc_head_uniq(ds
);
3390 unique
= dsl_dataset_phys(ds
)->ds_unique_bytes
;
3391 mutex_exit(&ds
->ds_lock
);
3393 if (MAX(unique
, newval
) > MAX(unique
, ds
->ds_reserved
)) {
3394 uint64_t delta
= MAX(unique
, newval
) -
3395 MAX(unique
, ds
->ds_reserved
);
3398 dsl_dir_space_available(ds
->ds_dir
, NULL
, 0, B_TRUE
) ||
3399 (ds
->ds_quota
> 0 && newval
> ds
->ds_quota
)) {
3400 dsl_dataset_rele(ds
, FTAG
);
3401 return (SET_ERROR(ENOSPC
));
3405 dsl_dataset_rele(ds
, FTAG
);
3410 dsl_dataset_set_refreservation_sync_impl(dsl_dataset_t
*ds
,
3411 zprop_source_t source
, uint64_t value
, dmu_tx_t
*tx
)
3417 dsl_prop_set_sync_impl(ds
, zfs_prop_to_name(ZFS_PROP_REFRESERVATION
),
3418 source
, sizeof (value
), 1, &value
, tx
);
3420 VERIFY0(dsl_prop_get_int_ds(ds
,
3421 zfs_prop_to_name(ZFS_PROP_REFRESERVATION
), &newval
));
3423 dmu_buf_will_dirty(ds
->ds_dbuf
, tx
);
3424 mutex_enter(&ds
->ds_dir
->dd_lock
);
3425 mutex_enter(&ds
->ds_lock
);
3426 ASSERT(DS_UNIQUE_IS_ACCURATE(ds
));
3427 unique
= dsl_dataset_phys(ds
)->ds_unique_bytes
;
3428 delta
= MAX(0, (int64_t)(newval
- unique
)) -
3429 MAX(0, (int64_t)(ds
->ds_reserved
- unique
));
3430 ds
->ds_reserved
= newval
;
3431 mutex_exit(&ds
->ds_lock
);
3433 dsl_dir_diduse_space(ds
->ds_dir
, DD_USED_REFRSRV
, delta
, 0, 0, tx
);
3434 mutex_exit(&ds
->ds_dir
->dd_lock
);
3438 dsl_dataset_set_refreservation_sync(void *arg
, dmu_tx_t
*tx
)
3440 dsl_dataset_set_qr_arg_t
*ddsqra
= arg
;
3441 dsl_pool_t
*dp
= dmu_tx_pool(tx
);
3442 dsl_dataset_t
*ds
= NULL
;
3444 VERIFY0(dsl_dataset_hold(dp
, ddsqra
->ddsqra_name
, FTAG
, &ds
));
3445 dsl_dataset_set_refreservation_sync_impl(ds
,
3446 ddsqra
->ddsqra_source
, ddsqra
->ddsqra_value
, tx
);
3447 dsl_dataset_rele(ds
, FTAG
);
3451 dsl_dataset_set_refreservation(const char *dsname
, zprop_source_t source
,
3452 uint64_t refreservation
)
3454 dsl_dataset_set_qr_arg_t ddsqra
;
3456 ddsqra
.ddsqra_name
= dsname
;
3457 ddsqra
.ddsqra_source
= source
;
3458 ddsqra
.ddsqra_value
= refreservation
;
3460 return (dsl_sync_task(dsname
, dsl_dataset_set_refreservation_check
,
3461 dsl_dataset_set_refreservation_sync
, &ddsqra
,
3462 0, ZFS_SPACE_CHECK_NONE
));
3466 * Return (in *usedp) the amount of space written in new that is not
3467 * present in oldsnap. New may be a snapshot or the head. Old must be
3468 * a snapshot before new, in new's filesystem (or its origin). If not then
3469 * fail and return EINVAL.
3471 * The written space is calculated by considering two components: First, we
3472 * ignore any freed space, and calculate the written as new's used space
3473 * minus old's used space. Next, we add in the amount of space that was freed
3474 * between the two snapshots, thus reducing new's used space relative to old's.
3475 * Specifically, this is the space that was born before old->ds_creation_txg,
3476 * and freed before new (ie. on new's deadlist or a previous deadlist).
3478 * space freed [---------------------]
3479 * snapshots ---O-------O--------O-------O------
3483 dsl_dataset_space_written(dsl_dataset_t
*oldsnap
, dsl_dataset_t
*new,
3484 uint64_t *usedp
, uint64_t *compp
, uint64_t *uncompp
)
3488 dsl_pool_t
*dp
= new->ds_dir
->dd_pool
;
3490 ASSERT(dsl_pool_config_held(dp
));
3493 *usedp
+= dsl_dataset_phys(new)->ds_referenced_bytes
;
3494 *usedp
-= dsl_dataset_phys(oldsnap
)->ds_referenced_bytes
;
3497 *compp
+= dsl_dataset_phys(new)->ds_compressed_bytes
;
3498 *compp
-= dsl_dataset_phys(oldsnap
)->ds_compressed_bytes
;
3501 *uncompp
+= dsl_dataset_phys(new)->ds_uncompressed_bytes
;
3502 *uncompp
-= dsl_dataset_phys(oldsnap
)->ds_uncompressed_bytes
;
3504 snapobj
= new->ds_object
;
3505 while (snapobj
!= oldsnap
->ds_object
) {
3506 dsl_dataset_t
*snap
;
3507 uint64_t used
, comp
, uncomp
;
3509 if (snapobj
== new->ds_object
) {
3512 err
= dsl_dataset_hold_obj(dp
, snapobj
, FTAG
, &snap
);
3517 if (dsl_dataset_phys(snap
)->ds_prev_snap_txg
==
3518 dsl_dataset_phys(oldsnap
)->ds_creation_txg
) {
3520 * The blocks in the deadlist can not be born after
3521 * ds_prev_snap_txg, so get the whole deadlist space,
3522 * which is more efficient (especially for old-format
3523 * deadlists). Unfortunately the deadlist code
3524 * doesn't have enough information to make this
3525 * optimization itself.
3527 dsl_deadlist_space(&snap
->ds_deadlist
,
3528 &used
, &comp
, &uncomp
);
3530 dsl_deadlist_space_range(&snap
->ds_deadlist
,
3531 0, dsl_dataset_phys(oldsnap
)->ds_creation_txg
,
3532 &used
, &comp
, &uncomp
);
3539 * If we get to the beginning of the chain of snapshots
3540 * (ds_prev_snap_obj == 0) before oldsnap, then oldsnap
3541 * was not a snapshot of/before new.
3543 snapobj
= dsl_dataset_phys(snap
)->ds_prev_snap_obj
;
3545 dsl_dataset_rele(snap
, FTAG
);
3547 err
= SET_ERROR(EINVAL
);
3556 * Return (in *usedp) the amount of space that will be reclaimed if firstsnap,
3557 * lastsnap, and all snapshots in between are deleted.
3559 * blocks that would be freed [---------------------------]
3560 * snapshots ---O-------O--------O-------O--------O
3561 * firstsnap lastsnap
3563 * This is the set of blocks that were born after the snap before firstsnap,
3564 * (birth > firstsnap->prev_snap_txg) and died before the snap after the
3565 * last snap (ie, is on lastsnap->ds_next->ds_deadlist or an earlier deadlist).
3566 * We calculate this by iterating over the relevant deadlists (from the snap
3567 * after lastsnap, backward to the snap after firstsnap), summing up the
3568 * space on the deadlist that was born after the snap before firstsnap.
3571 dsl_dataset_space_wouldfree(dsl_dataset_t
*firstsnap
,
3572 dsl_dataset_t
*lastsnap
,
3573 uint64_t *usedp
, uint64_t *compp
, uint64_t *uncompp
)
3577 dsl_pool_t
*dp
= firstsnap
->ds_dir
->dd_pool
;
3579 ASSERT(firstsnap
->ds_is_snapshot
);
3580 ASSERT(lastsnap
->ds_is_snapshot
);
3583 * Check that the snapshots are in the same dsl_dir, and firstsnap
3584 * is before lastsnap.
3586 if (firstsnap
->ds_dir
!= lastsnap
->ds_dir
||
3587 dsl_dataset_phys(firstsnap
)->ds_creation_txg
>
3588 dsl_dataset_phys(lastsnap
)->ds_creation_txg
)
3589 return (SET_ERROR(EINVAL
));
3591 *usedp
= *compp
= *uncompp
= 0;
3593 snapobj
= dsl_dataset_phys(lastsnap
)->ds_next_snap_obj
;
3594 while (snapobj
!= firstsnap
->ds_object
) {
3596 uint64_t used
, comp
, uncomp
;
3598 err
= dsl_dataset_hold_obj(dp
, snapobj
, FTAG
, &ds
);
3602 dsl_deadlist_space_range(&ds
->ds_deadlist
,
3603 dsl_dataset_phys(firstsnap
)->ds_prev_snap_txg
, UINT64_MAX
,
3604 &used
, &comp
, &uncomp
);
3609 snapobj
= dsl_dataset_phys(ds
)->ds_prev_snap_obj
;
3610 ASSERT3U(snapobj
, !=, 0);
3611 dsl_dataset_rele(ds
, FTAG
);
3617 * Return TRUE if 'earlier' is an earlier snapshot in 'later's timeline.
3618 * For example, they could both be snapshots of the same filesystem, and
3619 * 'earlier' is before 'later'. Or 'earlier' could be the origin of
3620 * 'later's filesystem. Or 'earlier' could be an older snapshot in the origin's
3621 * filesystem. Or 'earlier' could be the origin's origin.
3623 * If non-zero, earlier_txg is used instead of earlier's ds_creation_txg.
3626 dsl_dataset_is_before(dsl_dataset_t
*later
, dsl_dataset_t
*earlier
,
3627 uint64_t earlier_txg
)
3629 dsl_pool_t
*dp
= later
->ds_dir
->dd_pool
;
3632 dsl_dataset_t
*origin
;
3634 ASSERT(dsl_pool_config_held(dp
));
3635 ASSERT(earlier
->ds_is_snapshot
|| earlier_txg
!= 0);
3637 if (earlier_txg
== 0)
3638 earlier_txg
= dsl_dataset_phys(earlier
)->ds_creation_txg
;
3640 if (later
->ds_is_snapshot
&&
3641 earlier_txg
>= dsl_dataset_phys(later
)->ds_creation_txg
)
3644 if (later
->ds_dir
== earlier
->ds_dir
)
3646 if (!dsl_dir_is_clone(later
->ds_dir
))
3649 if (dsl_dir_phys(later
->ds_dir
)->dd_origin_obj
== earlier
->ds_object
)
3651 error
= dsl_dataset_hold_obj(dp
,
3652 dsl_dir_phys(later
->ds_dir
)->dd_origin_obj
, FTAG
, &origin
);
3655 ret
= dsl_dataset_is_before(origin
, earlier
, earlier_txg
);
3656 dsl_dataset_rele(origin
, FTAG
);
3661 dsl_dataset_zapify(dsl_dataset_t
*ds
, dmu_tx_t
*tx
)
3663 objset_t
*mos
= ds
->ds_dir
->dd_pool
->dp_meta_objset
;
3664 dmu_object_zapify(mos
, ds
->ds_object
, DMU_OT_DSL_DATASET
, tx
);
3668 dsl_dataset_is_zapified(dsl_dataset_t
*ds
)
3670 dmu_object_info_t doi
;
3672 dmu_object_info_from_db(ds
->ds_dbuf
, &doi
);
3673 return (doi
.doi_type
== DMU_OTN_ZAP_METADATA
);
3677 dsl_dataset_has_resume_receive_state(dsl_dataset_t
*ds
)
3679 return (dsl_dataset_is_zapified(ds
) &&
3680 zap_contains(ds
->ds_dir
->dd_pool
->dp_meta_objset
,
3681 ds
->ds_object
, DS_FIELD_RESUME_TOGUID
) == 0);
3684 #if defined(_KERNEL) && defined(HAVE_SPL)
3686 module_param(zfs_max_recordsize
, int, 0644);
3687 MODULE_PARM_DESC(zfs_max_recordsize
, "Max allowed record size");
3689 /* Limited to 1M on 32-bit platforms due to lack of virtual address space */
3690 module_param(zfs_max_recordsize
, int, 0444);
3691 MODULE_PARM_DESC(zfs_max_recordsize
, "Max allowed record size");
3694 EXPORT_SYMBOL(dsl_dataset_hold
);
3695 EXPORT_SYMBOL(dsl_dataset_hold_obj
);
3696 EXPORT_SYMBOL(dsl_dataset_own
);
3697 EXPORT_SYMBOL(dsl_dataset_own_obj
);
3698 EXPORT_SYMBOL(dsl_dataset_name
);
3699 EXPORT_SYMBOL(dsl_dataset_rele
);
3700 EXPORT_SYMBOL(dsl_dataset_disown
);
3701 EXPORT_SYMBOL(dsl_dataset_tryown
);
3702 EXPORT_SYMBOL(dsl_dataset_create_sync
);
3703 EXPORT_SYMBOL(dsl_dataset_create_sync_dd
);
3704 EXPORT_SYMBOL(dsl_dataset_snapshot_check
);
3705 EXPORT_SYMBOL(dsl_dataset_snapshot_sync
);
3706 EXPORT_SYMBOL(dsl_dataset_promote
);
3707 EXPORT_SYMBOL(dsl_dataset_user_hold
);
3708 EXPORT_SYMBOL(dsl_dataset_user_release
);
3709 EXPORT_SYMBOL(dsl_dataset_get_holds
);
3710 EXPORT_SYMBOL(dsl_dataset_get_blkptr
);
3711 EXPORT_SYMBOL(dsl_dataset_get_spa
);
3712 EXPORT_SYMBOL(dsl_dataset_modified_since_snap
);
3713 EXPORT_SYMBOL(dsl_dataset_space_written
);
3714 EXPORT_SYMBOL(dsl_dataset_space_wouldfree
);
3715 EXPORT_SYMBOL(dsl_dataset_sync
);
3716 EXPORT_SYMBOL(dsl_dataset_block_born
);
3717 EXPORT_SYMBOL(dsl_dataset_block_kill
);
3718 EXPORT_SYMBOL(dsl_dataset_dirty
);
3719 EXPORT_SYMBOL(dsl_dataset_stats
);
3720 EXPORT_SYMBOL(dsl_dataset_fast_stat
);
3721 EXPORT_SYMBOL(dsl_dataset_space
);
3722 EXPORT_SYMBOL(dsl_dataset_fsid_guid
);
3723 EXPORT_SYMBOL(dsl_dsobj_to_dsname
);
3724 EXPORT_SYMBOL(dsl_dataset_check_quota
);
3725 EXPORT_SYMBOL(dsl_dataset_clone_swap_check_impl
);
3726 EXPORT_SYMBOL(dsl_dataset_clone_swap_sync_impl
);