annotate usr/src/uts/common/fs/zfs/dsl_destroy.c @ 14022:624fa8f61951

3642 dsl_scan_active() should not issue I/O to determine if async destroying is active 3643 txg_delay should not hold the tc_lock Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed by: Adam Leventhal <ahl@delphix.com> Approved by: Gordon Ross <gwr@nexenta.com>
author George Wilson <george.wilson@delphix.com>
date Tue, 23 Apr 2013 09:31:42 -0800
parents d7059eb1884c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
1 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
2 * CDDL HEADER START
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
3 *
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
4 * The contents of this file are subject to the terms of the
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
5 * Common Development and Distribution License (the "License").
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
6 * You may not use this file except in compliance with the License.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
7 *
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
9 * or http://www.opensolaris.org/os/licensing.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
10 * See the License for the specific language governing permissions
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
11 * and limitations under the License.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
12 *
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
13 * When distributing Covered Code, include this CDDL HEADER in each
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
15 * If applicable, add the following below this CDDL HEADER, with the
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
16 * fields enclosed by brackets "[]" replaced with your own identifying
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
17 * information: Portions Copyright [yyyy] [name of copyright owner]
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
18 *
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
19 * CDDL HEADER END
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
20 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
21 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
13983
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13976
diff changeset
23 * Copyright (c) 2013 by Delphix. All rights reserved.
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
24 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
25
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
26 #include <sys/zfs_context.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
27 #include <sys/dsl_userhold.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
28 #include <sys/dsl_dataset.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
29 #include <sys/dsl_synctask.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
30 #include <sys/dmu_tx.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
31 #include <sys/dsl_pool.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
32 #include <sys/dsl_dir.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
33 #include <sys/dmu_traverse.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
34 #include <sys/dsl_scan.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
35 #include <sys/dmu_objset.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
36 #include <sys/zap.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
37 #include <sys/zfeature.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
38 #include <sys/zfs_ioctl.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
39 #include <sys/dsl_deleg.h>
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
40
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
41 typedef struct dmu_snapshots_destroy_arg {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
42 nvlist_t *dsda_snaps;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
43 nvlist_t *dsda_successful_snaps;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
44 boolean_t dsda_defer;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
45 nvlist_t *dsda_errlist;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
46 } dmu_snapshots_destroy_arg_t;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
47
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
48 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
49 * ds must be owned.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
50 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
51 static int
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
52 dsl_destroy_snapshot_check_impl(dsl_dataset_t *ds, boolean_t defer)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
53 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
54 if (!dsl_dataset_is_snapshot(ds))
13983
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13976
diff changeset
55 return (SET_ERROR(EINVAL));
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
56
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
57 if (dsl_dataset_long_held(ds))
13983
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13976
diff changeset
58 return (SET_ERROR(EBUSY));
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
59
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
60 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
61 * Only allow deferred destroy on pools that support it.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
62 * NOTE: deferred destroy is only supported on snapshots.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
63 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
64 if (defer) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
65 if (spa_version(ds->ds_dir->dd_pool->dp_spa) <
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
66 SPA_VERSION_USERREFS)
13983
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13976
diff changeset
67 return (SET_ERROR(ENOTSUP));
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
68 return (0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
69 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
70
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
71 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
72 * If this snapshot has an elevated user reference count,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
73 * we can't destroy it yet.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
74 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
75 if (ds->ds_userrefs > 0)
13983
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13976
diff changeset
76 return (SET_ERROR(EBUSY));
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
77
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
78 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
79 * Can't delete a branch point.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
80 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
81 if (ds->ds_phys->ds_num_children > 1)
13983
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13976
diff changeset
82 return (SET_ERROR(EEXIST));
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
83
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
84 return (0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
85 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
86
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
87 static int
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
88 dsl_destroy_snapshot_check(void *arg, dmu_tx_t *tx)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
89 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
90 dmu_snapshots_destroy_arg_t *dsda = arg;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
91 dsl_pool_t *dp = dmu_tx_pool(tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
92 nvpair_t *pair;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
93 int error = 0;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
94
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
95 if (!dmu_tx_is_syncing(tx))
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
96 return (0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
97
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
98 for (pair = nvlist_next_nvpair(dsda->dsda_snaps, NULL);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
99 pair != NULL; pair = nvlist_next_nvpair(dsda->dsda_snaps, pair)) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
100 dsl_dataset_t *ds;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
101
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
102 error = dsl_dataset_hold(dp, nvpair_name(pair),
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
103 FTAG, &ds);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
104
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
105 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
106 * If the snapshot does not exist, silently ignore it
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
107 * (it's "already destroyed").
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
108 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
109 if (error == ENOENT)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
110 continue;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
111
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
112 if (error == 0) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
113 error = dsl_destroy_snapshot_check_impl(ds,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
114 dsda->dsda_defer);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
115 dsl_dataset_rele(ds, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
116 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
117
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
118 if (error == 0) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
119 fnvlist_add_boolean(dsda->dsda_successful_snaps,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
120 nvpair_name(pair));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
121 } else {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
122 fnvlist_add_int32(dsda->dsda_errlist,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
123 nvpair_name(pair), error);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
124 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
125 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
126
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
127 pair = nvlist_next_nvpair(dsda->dsda_errlist, NULL);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
128 if (pair != NULL)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
129 return (fnvpair_value_int32(pair));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
130 return (0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
131 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
132
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
133 struct process_old_arg {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
134 dsl_dataset_t *ds;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
135 dsl_dataset_t *ds_prev;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
136 boolean_t after_branch_point;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
137 zio_t *pio;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
138 uint64_t used, comp, uncomp;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
139 };
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
140
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
141 static int
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
142 process_old_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
143 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
144 struct process_old_arg *poa = arg;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
145 dsl_pool_t *dp = poa->ds->ds_dir->dd_pool;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
146
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
147 if (bp->blk_birth <= poa->ds->ds_phys->ds_prev_snap_txg) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
148 dsl_deadlist_insert(&poa->ds->ds_deadlist, bp, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
149 if (poa->ds_prev && !poa->after_branch_point &&
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
150 bp->blk_birth >
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
151 poa->ds_prev->ds_phys->ds_prev_snap_txg) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
152 poa->ds_prev->ds_phys->ds_unique_bytes +=
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
153 bp_get_dsize_sync(dp->dp_spa, bp);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
154 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
155 } else {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
156 poa->used += bp_get_dsize_sync(dp->dp_spa, bp);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
157 poa->comp += BP_GET_PSIZE(bp);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
158 poa->uncomp += BP_GET_UCSIZE(bp);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
159 dsl_free_sync(poa->pio, dp, tx->tx_txg, bp);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
160 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
161 return (0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
162 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
163
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
164 static void
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
165 process_old_deadlist(dsl_dataset_t *ds, dsl_dataset_t *ds_prev,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
166 dsl_dataset_t *ds_next, boolean_t after_branch_point, dmu_tx_t *tx)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
167 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
168 struct process_old_arg poa = { 0 };
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
169 dsl_pool_t *dp = ds->ds_dir->dd_pool;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
170 objset_t *mos = dp->dp_meta_objset;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
171 uint64_t deadlist_obj;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
172
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
173 ASSERT(ds->ds_deadlist.dl_oldfmt);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
174 ASSERT(ds_next->ds_deadlist.dl_oldfmt);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
175
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
176 poa.ds = ds;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
177 poa.ds_prev = ds_prev;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
178 poa.after_branch_point = after_branch_point;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
179 poa.pio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
180 VERIFY0(bpobj_iterate(&ds_next->ds_deadlist.dl_bpobj,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
181 process_old_cb, &poa, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
182 VERIFY0(zio_wait(poa.pio));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
183 ASSERT3U(poa.used, ==, ds->ds_phys->ds_unique_bytes);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
184
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
185 /* change snapused */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
186 dsl_dir_diduse_space(ds->ds_dir, DD_USED_SNAP,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
187 -poa.used, -poa.comp, -poa.uncomp, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
188
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
189 /* swap next's deadlist to our deadlist */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
190 dsl_deadlist_close(&ds->ds_deadlist);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
191 dsl_deadlist_close(&ds_next->ds_deadlist);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
192 deadlist_obj = ds->ds_phys->ds_deadlist_obj;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
193 ds->ds_phys->ds_deadlist_obj = ds_next->ds_phys->ds_deadlist_obj;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
194 ds_next->ds_phys->ds_deadlist_obj = deadlist_obj;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
195 dsl_deadlist_open(&ds->ds_deadlist, mos, ds->ds_phys->ds_deadlist_obj);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
196 dsl_deadlist_open(&ds_next->ds_deadlist, mos,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
197 ds_next->ds_phys->ds_deadlist_obj);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
198 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
199
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
200 static void
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
201 dsl_dataset_remove_clones_key(dsl_dataset_t *ds, uint64_t mintxg, dmu_tx_t *tx)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
202 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
203 objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
204 zap_cursor_t zc;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
205 zap_attribute_t za;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
206
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
207 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
208 * If it is the old version, dd_clones doesn't exist so we can't
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
209 * find the clones, but dsl_deadlist_remove_key() is a no-op so it
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
210 * doesn't matter.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
211 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
212 if (ds->ds_dir->dd_phys->dd_clones == 0)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
213 return;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
214
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
215 for (zap_cursor_init(&zc, mos, ds->ds_dir->dd_phys->dd_clones);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
216 zap_cursor_retrieve(&zc, &za) == 0;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
217 zap_cursor_advance(&zc)) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
218 dsl_dataset_t *clone;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
219
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
220 VERIFY0(dsl_dataset_hold_obj(ds->ds_dir->dd_pool,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
221 za.za_first_integer, FTAG, &clone));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
222 if (clone->ds_dir->dd_origin_txg > mintxg) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
223 dsl_deadlist_remove_key(&clone->ds_deadlist,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
224 mintxg, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
225 dsl_dataset_remove_clones_key(clone, mintxg, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
226 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
227 dsl_dataset_rele(clone, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
228 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
229 zap_cursor_fini(&zc);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
230 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
231
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
232 void
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
233 dsl_destroy_snapshot_sync_impl(dsl_dataset_t *ds, boolean_t defer, dmu_tx_t *tx)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
234 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
235 int err;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
236 int after_branch_point = FALSE;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
237 dsl_pool_t *dp = ds->ds_dir->dd_pool;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
238 objset_t *mos = dp->dp_meta_objset;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
239 dsl_dataset_t *ds_prev = NULL;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
240 uint64_t obj;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
241
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
242 ASSERT(RRW_WRITE_HELD(&dp->dp_config_rwlock));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
243 ASSERT3U(ds->ds_phys->ds_bp.blk_birth, <=, tx->tx_txg);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
244 ASSERT(refcount_is_zero(&ds->ds_longholds));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
245
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
246 if (defer &&
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
247 (ds->ds_userrefs > 0 || ds->ds_phys->ds_num_children > 1)) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
248 ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
249 dmu_buf_will_dirty(ds->ds_dbuf, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
250 ds->ds_phys->ds_flags |= DS_FLAG_DEFER_DESTROY;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
251 spa_history_log_internal_ds(ds, "defer_destroy", tx, "");
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
252 return;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
253 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
254
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
255 ASSERT3U(ds->ds_phys->ds_num_children, <=, 1);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
256
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
257 /* We need to log before removing it from the namespace. */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
258 spa_history_log_internal_ds(ds, "destroy", tx, "");
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
259
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
260 dsl_scan_ds_destroyed(ds, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
261
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
262 obj = ds->ds_object;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
263
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
264 if (ds->ds_phys->ds_prev_snap_obj != 0) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
265 ASSERT3P(ds->ds_prev, ==, NULL);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
266 VERIFY0(dsl_dataset_hold_obj(dp,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
267 ds->ds_phys->ds_prev_snap_obj, FTAG, &ds_prev));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
268 after_branch_point =
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
269 (ds_prev->ds_phys->ds_next_snap_obj != obj);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
270
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
271 dmu_buf_will_dirty(ds_prev->ds_dbuf, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
272 if (after_branch_point &&
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
273 ds_prev->ds_phys->ds_next_clones_obj != 0) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
274 dsl_dataset_remove_from_next_clones(ds_prev, obj, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
275 if (ds->ds_phys->ds_next_snap_obj != 0) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
276 VERIFY0(zap_add_int(mos,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
277 ds_prev->ds_phys->ds_next_clones_obj,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
278 ds->ds_phys->ds_next_snap_obj, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
279 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
280 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
281 if (!after_branch_point) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
282 ds_prev->ds_phys->ds_next_snap_obj =
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
283 ds->ds_phys->ds_next_snap_obj;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
284 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
285 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
286
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
287 dsl_dataset_t *ds_next;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
288 uint64_t old_unique;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
289 uint64_t used = 0, comp = 0, uncomp = 0;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
290
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
291 VERIFY0(dsl_dataset_hold_obj(dp,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
292 ds->ds_phys->ds_next_snap_obj, FTAG, &ds_next));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
293 ASSERT3U(ds_next->ds_phys->ds_prev_snap_obj, ==, obj);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
294
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
295 old_unique = ds_next->ds_phys->ds_unique_bytes;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
296
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
297 dmu_buf_will_dirty(ds_next->ds_dbuf, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
298 ds_next->ds_phys->ds_prev_snap_obj =
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
299 ds->ds_phys->ds_prev_snap_obj;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
300 ds_next->ds_phys->ds_prev_snap_txg =
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
301 ds->ds_phys->ds_prev_snap_txg;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
302 ASSERT3U(ds->ds_phys->ds_prev_snap_txg, ==,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
303 ds_prev ? ds_prev->ds_phys->ds_creation_txg : 0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
304
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
305 if (ds_next->ds_deadlist.dl_oldfmt) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
306 process_old_deadlist(ds, ds_prev, ds_next,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
307 after_branch_point, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
308 } else {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
309 /* Adjust prev's unique space. */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
310 if (ds_prev && !after_branch_point) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
311 dsl_deadlist_space_range(&ds_next->ds_deadlist,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
312 ds_prev->ds_phys->ds_prev_snap_txg,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
313 ds->ds_phys->ds_prev_snap_txg,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
314 &used, &comp, &uncomp);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
315 ds_prev->ds_phys->ds_unique_bytes += used;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
316 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
317
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
318 /* Adjust snapused. */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
319 dsl_deadlist_space_range(&ds_next->ds_deadlist,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
320 ds->ds_phys->ds_prev_snap_txg, UINT64_MAX,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
321 &used, &comp, &uncomp);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
322 dsl_dir_diduse_space(ds->ds_dir, DD_USED_SNAP,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
323 -used, -comp, -uncomp, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
324
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
325 /* Move blocks to be freed to pool's free list. */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
326 dsl_deadlist_move_bpobj(&ds_next->ds_deadlist,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
327 &dp->dp_free_bpobj, ds->ds_phys->ds_prev_snap_txg,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
328 tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
329 dsl_dir_diduse_space(tx->tx_pool->dp_free_dir,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
330 DD_USED_HEAD, used, comp, uncomp, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
331
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
332 /* Merge our deadlist into next's and free it. */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
333 dsl_deadlist_merge(&ds_next->ds_deadlist,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
334 ds->ds_phys->ds_deadlist_obj, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
335 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
336 dsl_deadlist_close(&ds->ds_deadlist);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
337 dsl_deadlist_free(mos, ds->ds_phys->ds_deadlist_obj, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
338 dmu_buf_will_dirty(ds->ds_dbuf, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
339 ds->ds_phys->ds_deadlist_obj = 0;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
340
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
341 /* Collapse range in clone heads */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
342 dsl_dataset_remove_clones_key(ds,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
343 ds->ds_phys->ds_creation_txg, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
344
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
345 if (dsl_dataset_is_snapshot(ds_next)) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
346 dsl_dataset_t *ds_nextnext;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
347
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
348 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
349 * Update next's unique to include blocks which
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
350 * were previously shared by only this snapshot
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
351 * and it. Those blocks will be born after the
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
352 * prev snap and before this snap, and will have
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
353 * died after the next snap and before the one
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
354 * after that (ie. be on the snap after next's
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
355 * deadlist).
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
356 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
357 VERIFY0(dsl_dataset_hold_obj(dp,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
358 ds_next->ds_phys->ds_next_snap_obj, FTAG, &ds_nextnext));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
359 dsl_deadlist_space_range(&ds_nextnext->ds_deadlist,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
360 ds->ds_phys->ds_prev_snap_txg,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
361 ds->ds_phys->ds_creation_txg,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
362 &used, &comp, &uncomp);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
363 ds_next->ds_phys->ds_unique_bytes += used;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
364 dsl_dataset_rele(ds_nextnext, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
365 ASSERT3P(ds_next->ds_prev, ==, NULL);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
366
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
367 /* Collapse range in this head. */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
368 dsl_dataset_t *hds;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
369 VERIFY0(dsl_dataset_hold_obj(dp,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
370 ds->ds_dir->dd_phys->dd_head_dataset_obj, FTAG, &hds));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
371 dsl_deadlist_remove_key(&hds->ds_deadlist,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
372 ds->ds_phys->ds_creation_txg, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
373 dsl_dataset_rele(hds, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
374
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
375 } else {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
376 ASSERT3P(ds_next->ds_prev, ==, ds);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
377 dsl_dataset_rele(ds_next->ds_prev, ds_next);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
378 ds_next->ds_prev = NULL;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
379 if (ds_prev) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
380 VERIFY0(dsl_dataset_hold_obj(dp,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
381 ds->ds_phys->ds_prev_snap_obj,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
382 ds_next, &ds_next->ds_prev));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
383 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
384
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
385 dsl_dataset_recalc_head_uniq(ds_next);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
386
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
387 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
388 * Reduce the amount of our unconsumed refreservation
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
389 * being charged to our parent by the amount of
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
390 * new unique data we have gained.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
391 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
392 if (old_unique < ds_next->ds_reserved) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
393 int64_t mrsdelta;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
394 uint64_t new_unique =
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
395 ds_next->ds_phys->ds_unique_bytes;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
396
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
397 ASSERT(old_unique <= new_unique);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
398 mrsdelta = MIN(new_unique - old_unique,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
399 ds_next->ds_reserved - old_unique);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
400 dsl_dir_diduse_space(ds->ds_dir,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
401 DD_USED_REFRSRV, -mrsdelta, 0, 0, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
402 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
403 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
404 dsl_dataset_rele(ds_next, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
405
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
406 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
407 * This must be done after the dsl_traverse(), because it will
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
408 * re-open the objset.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
409 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
410 if (ds->ds_objset) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
411 dmu_objset_evict(ds->ds_objset);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
412 ds->ds_objset = NULL;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
413 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
414
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
415 /* remove from snapshot namespace */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
416 dsl_dataset_t *ds_head;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
417 ASSERT(ds->ds_phys->ds_snapnames_zapobj == 0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
418 VERIFY0(dsl_dataset_hold_obj(dp,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
419 ds->ds_dir->dd_phys->dd_head_dataset_obj, FTAG, &ds_head));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
420 VERIFY0(dsl_dataset_get_snapname(ds));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
421 #ifdef ZFS_DEBUG
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
422 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
423 uint64_t val;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
424
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
425 err = dsl_dataset_snap_lookup(ds_head,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
426 ds->ds_snapname, &val);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
427 ASSERT0(err);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
428 ASSERT3U(val, ==, obj);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
429 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
430 #endif
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
431 VERIFY0(dsl_dataset_snap_remove(ds_head, ds->ds_snapname, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
432 dsl_dataset_rele(ds_head, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
433
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
434 if (ds_prev != NULL)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
435 dsl_dataset_rele(ds_prev, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
436
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
437 spa_prop_clear_bootfs(dp->dp_spa, ds->ds_object, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
438
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
439 if (ds->ds_phys->ds_next_clones_obj != 0) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
440 uint64_t count;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
441 ASSERT0(zap_count(mos,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
442 ds->ds_phys->ds_next_clones_obj, &count) && count == 0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
443 VERIFY0(dmu_object_free(mos,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
444 ds->ds_phys->ds_next_clones_obj, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
445 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
446 if (ds->ds_phys->ds_props_obj != 0)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
447 VERIFY0(zap_destroy(mos, ds->ds_phys->ds_props_obj, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
448 if (ds->ds_phys->ds_userrefs_obj != 0)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
449 VERIFY0(zap_destroy(mos, ds->ds_phys->ds_userrefs_obj, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
450 dsl_dir_rele(ds->ds_dir, ds);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
451 ds->ds_dir = NULL;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
452 VERIFY0(dmu_object_free(mos, obj, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
453 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
454
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
455 static void
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
456 dsl_destroy_snapshot_sync(void *arg, dmu_tx_t *tx)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
457 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
458 dmu_snapshots_destroy_arg_t *dsda = arg;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
459 dsl_pool_t *dp = dmu_tx_pool(tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
460 nvpair_t *pair;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
461
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
462 for (pair = nvlist_next_nvpair(dsda->dsda_successful_snaps, NULL);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
463 pair != NULL;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
464 pair = nvlist_next_nvpair(dsda->dsda_successful_snaps, pair)) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
465 dsl_dataset_t *ds;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
466
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
467 VERIFY0(dsl_dataset_hold(dp, nvpair_name(pair), FTAG, &ds));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
468
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
469 dsl_destroy_snapshot_sync_impl(ds, dsda->dsda_defer, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
470 dsl_dataset_rele(ds, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
471 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
472 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
473
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
474 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
475 * The semantics of this function are described in the comment above
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
476 * lzc_destroy_snaps(). To summarize:
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
477 *
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
478 * The snapshots must all be in the same pool.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
479 *
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
480 * Snapshots that don't exist will be silently ignored (considered to be
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
481 * "already deleted").
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
482 *
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
483 * On success, all snaps will be destroyed and this will return 0.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
484 * On failure, no snaps will be destroyed, the errlist will be filled in,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
485 * and this will return an errno.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
486 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
487 int
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
488 dsl_destroy_snapshots_nvl(nvlist_t *snaps, boolean_t defer,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
489 nvlist_t *errlist)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
490 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
491 dmu_snapshots_destroy_arg_t dsda;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
492 int error;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
493 nvpair_t *pair;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
494
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
495 pair = nvlist_next_nvpair(snaps, NULL);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
496 if (pair == NULL)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
497 return (0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
498
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
499 dsda.dsda_snaps = snaps;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
500 dsda.dsda_successful_snaps = fnvlist_alloc();
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
501 dsda.dsda_defer = defer;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
502 dsda.dsda_errlist = errlist;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
503
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
504 error = dsl_sync_task(nvpair_name(pair),
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
505 dsl_destroy_snapshot_check, dsl_destroy_snapshot_sync,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
506 &dsda, 0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
507 fnvlist_free(dsda.dsda_successful_snaps);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
508
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
509 return (error);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
510 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
511
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
512 int
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
513 dsl_destroy_snapshot(const char *name, boolean_t defer)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
514 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
515 int error;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
516 nvlist_t *nvl = fnvlist_alloc();
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
517 nvlist_t *errlist = fnvlist_alloc();
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
518
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
519 fnvlist_add_boolean(nvl, name);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
520 error = dsl_destroy_snapshots_nvl(nvl, defer, errlist);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
521 fnvlist_free(errlist);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
522 fnvlist_free(nvl);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
523 return (error);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
524 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
525
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
526 struct killarg {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
527 dsl_dataset_t *ds;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
528 dmu_tx_t *tx;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
529 };
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
530
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
531 /* ARGSUSED */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
532 static int
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
533 kill_blkptr(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
534 const zbookmark_t *zb, const dnode_phys_t *dnp, void *arg)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
535 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
536 struct killarg *ka = arg;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
537 dmu_tx_t *tx = ka->tx;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
538
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
539 if (bp == NULL)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
540 return (0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
541
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
542 if (zb->zb_level == ZB_ZIL_LEVEL) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
543 ASSERT(zilog != NULL);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
544 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
545 * It's a block in the intent log. It has no
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
546 * accounting, so just free it.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
547 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
548 dsl_free(ka->tx->tx_pool, ka->tx->tx_txg, bp);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
549 } else {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
550 ASSERT(zilog == NULL);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
551 ASSERT3U(bp->blk_birth, >, ka->ds->ds_phys->ds_prev_snap_txg);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
552 (void) dsl_dataset_block_kill(ka->ds, bp, tx, B_FALSE);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
553 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
554
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
555 return (0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
556 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
557
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
558 static void
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
559 old_synchronous_dataset_destroy(dsl_dataset_t *ds, dmu_tx_t *tx)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
560 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
561 struct killarg ka;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
562
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
563 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
564 * Free everything that we point to (that's born after
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
565 * the previous snapshot, if we are a clone)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
566 *
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
567 * NB: this should be very quick, because we already
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
568 * freed all the objects in open context.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
569 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
570 ka.ds = ds;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
571 ka.tx = tx;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
572 VERIFY0(traverse_dataset(ds,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
573 ds->ds_phys->ds_prev_snap_txg, TRAVERSE_POST,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
574 kill_blkptr, &ka));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
575 ASSERT(!DS_UNIQUE_IS_ACCURATE(ds) || ds->ds_phys->ds_unique_bytes == 0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
576 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
577
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
578 typedef struct dsl_destroy_head_arg {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
579 const char *ddha_name;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
580 } dsl_destroy_head_arg_t;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
581
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
582 int
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
583 dsl_destroy_head_check_impl(dsl_dataset_t *ds, int expected_holds)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
584 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
585 int error;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
586 uint64_t count;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
587 objset_t *mos;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
588
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
589 if (dsl_dataset_is_snapshot(ds))
13983
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13976
diff changeset
590 return (SET_ERROR(EINVAL));
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
591
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
592 if (refcount_count(&ds->ds_longholds) != expected_holds)
13983
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13976
diff changeset
593 return (SET_ERROR(EBUSY));
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
594
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
595 mos = ds->ds_dir->dd_pool->dp_meta_objset;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
596
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
597 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
598 * Can't delete a head dataset if there are snapshots of it.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
599 * (Except if the only snapshots are from the branch we cloned
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
600 * from.)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
601 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
602 if (ds->ds_prev != NULL &&
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
603 ds->ds_prev->ds_phys->ds_next_snap_obj == ds->ds_object)
13983
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13976
diff changeset
604 return (SET_ERROR(EBUSY));
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
605
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
606 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
607 * Can't delete if there are children of this fs.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
608 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
609 error = zap_count(mos,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
610 ds->ds_dir->dd_phys->dd_child_dir_zapobj, &count);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
611 if (error != 0)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
612 return (error);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
613 if (count != 0)
13983
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13976
diff changeset
614 return (SET_ERROR(EEXIST));
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
615
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
616 if (dsl_dir_is_clone(ds->ds_dir) && DS_IS_DEFER_DESTROY(ds->ds_prev) &&
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
617 ds->ds_prev->ds_phys->ds_num_children == 2 &&
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
618 ds->ds_prev->ds_userrefs == 0) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
619 /* We need to remove the origin snapshot as well. */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
620 if (!refcount_is_zero(&ds->ds_prev->ds_longholds))
13983
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13976
diff changeset
621 return (SET_ERROR(EBUSY));
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
622 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
623 return (0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
624 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
625
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
626 static int
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
627 dsl_destroy_head_check(void *arg, dmu_tx_t *tx)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
628 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
629 dsl_destroy_head_arg_t *ddha = arg;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
630 dsl_pool_t *dp = dmu_tx_pool(tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
631 dsl_dataset_t *ds;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
632 int error;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
633
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
634 error = dsl_dataset_hold(dp, ddha->ddha_name, FTAG, &ds);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
635 if (error != 0)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
636 return (error);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
637
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
638 error = dsl_destroy_head_check_impl(ds, 0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
639 dsl_dataset_rele(ds, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
640 return (error);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
641 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
642
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
643 static void
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
644 dsl_dir_destroy_sync(uint64_t ddobj, dmu_tx_t *tx)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
645 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
646 dsl_dir_t *dd;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
647 dsl_pool_t *dp = dmu_tx_pool(tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
648 objset_t *mos = dp->dp_meta_objset;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
649 dd_used_t t;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
650
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
651 ASSERT(RRW_WRITE_HELD(&dmu_tx_pool(tx)->dp_config_rwlock));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
652
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
653 VERIFY0(dsl_dir_hold_obj(dp, ddobj, NULL, FTAG, &dd));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
654
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
655 ASSERT0(dd->dd_phys->dd_head_dataset_obj);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
656
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
657 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
658 * Remove our reservation. The impl() routine avoids setting the
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
659 * actual property, which would require the (already destroyed) ds.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
660 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
661 dsl_dir_set_reservation_sync_impl(dd, 0, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
662
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
663 ASSERT0(dd->dd_phys->dd_used_bytes);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
664 ASSERT0(dd->dd_phys->dd_reserved);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
665 for (t = 0; t < DD_USED_NUM; t++)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
666 ASSERT0(dd->dd_phys->dd_used_breakdown[t]);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
667
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
668 VERIFY0(zap_destroy(mos, dd->dd_phys->dd_child_dir_zapobj, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
669 VERIFY0(zap_destroy(mos, dd->dd_phys->dd_props_zapobj, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
670 VERIFY0(dsl_deleg_destroy(mos, dd->dd_phys->dd_deleg_zapobj, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
671 VERIFY0(zap_remove(mos,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
672 dd->dd_parent->dd_phys->dd_child_dir_zapobj, dd->dd_myname, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
673
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
674 dsl_dir_rele(dd, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
675 VERIFY0(dmu_object_free(mos, ddobj, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
676 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
677
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
678 void
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
679 dsl_destroy_head_sync_impl(dsl_dataset_t *ds, dmu_tx_t *tx)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
680 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
681 dsl_pool_t *dp = dmu_tx_pool(tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
682 objset_t *mos = dp->dp_meta_objset;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
683 uint64_t obj, ddobj, prevobj = 0;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
684 boolean_t rmorigin;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
685
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
686 ASSERT3U(ds->ds_phys->ds_num_children, <=, 1);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
687 ASSERT(ds->ds_prev == NULL ||
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
688 ds->ds_prev->ds_phys->ds_next_snap_obj != ds->ds_object);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
689 ASSERT3U(ds->ds_phys->ds_bp.blk_birth, <=, tx->tx_txg);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
690 ASSERT(RRW_WRITE_HELD(&dp->dp_config_rwlock));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
691
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
692 /* We need to log before removing it from the namespace. */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
693 spa_history_log_internal_ds(ds, "destroy", tx, "");
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
694
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
695 rmorigin = (dsl_dir_is_clone(ds->ds_dir) &&
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
696 DS_IS_DEFER_DESTROY(ds->ds_prev) &&
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
697 ds->ds_prev->ds_phys->ds_num_children == 2 &&
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
698 ds->ds_prev->ds_userrefs == 0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
699
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
700 /* Remove our reservation */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
701 if (ds->ds_reserved != 0) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
702 dsl_dataset_set_refreservation_sync_impl(ds,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
703 (ZPROP_SRC_NONE | ZPROP_SRC_LOCAL | ZPROP_SRC_RECEIVED),
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
704 0, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
705 ASSERT0(ds->ds_reserved);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
706 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
707
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
708 dsl_scan_ds_destroyed(ds, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
709
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
710 obj = ds->ds_object;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
711
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
712 if (ds->ds_phys->ds_prev_snap_obj != 0) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
713 /* This is a clone */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
714 ASSERT(ds->ds_prev != NULL);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
715 ASSERT3U(ds->ds_prev->ds_phys->ds_next_snap_obj, !=, obj);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
716 ASSERT0(ds->ds_phys->ds_next_snap_obj);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
717
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
718 dmu_buf_will_dirty(ds->ds_prev->ds_dbuf, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
719 if (ds->ds_prev->ds_phys->ds_next_clones_obj != 0) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
720 dsl_dataset_remove_from_next_clones(ds->ds_prev,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
721 obj, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
722 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
723
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
724 ASSERT3U(ds->ds_prev->ds_phys->ds_num_children, >, 1);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
725 ds->ds_prev->ds_phys->ds_num_children--;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
726 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
727
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
728 zfeature_info_t *async_destroy =
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
729 &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY];
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
730 objset_t *os;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
731
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
732 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
733 * Destroy the deadlist. Unless it's a clone, the
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
734 * deadlist should be empty. (If it's a clone, it's
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
735 * safe to ignore the deadlist contents.)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
736 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
737 dsl_deadlist_close(&ds->ds_deadlist);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
738 dsl_deadlist_free(mos, ds->ds_phys->ds_deadlist_obj, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
739 dmu_buf_will_dirty(ds->ds_dbuf, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
740 ds->ds_phys->ds_deadlist_obj = 0;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
741
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
742 VERIFY0(dmu_objset_from_ds(ds, &os));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
743
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
744 if (!spa_feature_is_enabled(dp->dp_spa, async_destroy)) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
745 old_synchronous_dataset_destroy(ds, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
746 } else {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
747 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
748 * Move the bptree into the pool's list of trees to
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
749 * clean up and update space accounting information.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
750 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
751 uint64_t used, comp, uncomp;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
752
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
753 zil_destroy_sync(dmu_objset_zil(os), tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
754
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
755 if (!spa_feature_is_active(dp->dp_spa, async_destroy)) {
14022
624fa8f61951 3642 dsl_scan_active() should not issue I/O to determine if async destroying is active
George Wilson <george.wilson@delphix.com>
parents: 13983
diff changeset
756 dsl_scan_t *scn = dp->dp_scan;
624fa8f61951 3642 dsl_scan_active() should not issue I/O to determine if async destroying is active
George Wilson <george.wilson@delphix.com>
parents: 13983
diff changeset
757
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
758 spa_feature_incr(dp->dp_spa, async_destroy, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
759 dp->dp_bptree_obj = bptree_alloc(mos, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
760 VERIFY0(zap_add(mos,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
761 DMU_POOL_DIRECTORY_OBJECT,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
762 DMU_POOL_BPTREE_OBJ, sizeof (uint64_t), 1,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
763 &dp->dp_bptree_obj, tx));
14022
624fa8f61951 3642 dsl_scan_active() should not issue I/O to determine if async destroying is active
George Wilson <george.wilson@delphix.com>
parents: 13983
diff changeset
764 ASSERT(!scn->scn_async_destroying);
624fa8f61951 3642 dsl_scan_active() should not issue I/O to determine if async destroying is active
George Wilson <george.wilson@delphix.com>
parents: 13983
diff changeset
765 scn->scn_async_destroying = B_TRUE;
13976
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
766 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
767
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
768 used = ds->ds_dir->dd_phys->dd_used_bytes;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
769 comp = ds->ds_dir->dd_phys->dd_compressed_bytes;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
770 uncomp = ds->ds_dir->dd_phys->dd_uncompressed_bytes;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
771
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
772 ASSERT(!DS_UNIQUE_IS_ACCURATE(ds) ||
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
773 ds->ds_phys->ds_unique_bytes == used);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
774
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
775 bptree_add(mos, dp->dp_bptree_obj,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
776 &ds->ds_phys->ds_bp, ds->ds_phys->ds_prev_snap_txg,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
777 used, comp, uncomp, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
778 dsl_dir_diduse_space(ds->ds_dir, DD_USED_HEAD,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
779 -used, -comp, -uncomp, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
780 dsl_dir_diduse_space(dp->dp_free_dir, DD_USED_HEAD,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
781 used, comp, uncomp, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
782 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
783
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
784 if (ds->ds_prev != NULL) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
785 if (spa_version(dp->dp_spa) >= SPA_VERSION_DIR_CLONES) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
786 VERIFY0(zap_remove_int(mos,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
787 ds->ds_prev->ds_dir->dd_phys->dd_clones,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
788 ds->ds_object, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
789 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
790 prevobj = ds->ds_prev->ds_object;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
791 dsl_dataset_rele(ds->ds_prev, ds);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
792 ds->ds_prev = NULL;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
793 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
794
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
795 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
796 * This must be done after the dsl_traverse(), because it will
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
797 * re-open the objset.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
798 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
799 if (ds->ds_objset) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
800 dmu_objset_evict(ds->ds_objset);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
801 ds->ds_objset = NULL;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
802 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
803
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
804 /* Erase the link in the dir */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
805 dmu_buf_will_dirty(ds->ds_dir->dd_dbuf, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
806 ds->ds_dir->dd_phys->dd_head_dataset_obj = 0;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
807 ddobj = ds->ds_dir->dd_object;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
808 ASSERT(ds->ds_phys->ds_snapnames_zapobj != 0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
809 VERIFY0(zap_destroy(mos, ds->ds_phys->ds_snapnames_zapobj, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
810
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
811 spa_prop_clear_bootfs(dp->dp_spa, ds->ds_object, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
812
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
813 ASSERT0(ds->ds_phys->ds_next_clones_obj);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
814 ASSERT0(ds->ds_phys->ds_props_obj);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
815 ASSERT0(ds->ds_phys->ds_userrefs_obj);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
816 dsl_dir_rele(ds->ds_dir, ds);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
817 ds->ds_dir = NULL;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
818 VERIFY0(dmu_object_free(mos, obj, tx));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
819
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
820 dsl_dir_destroy_sync(ddobj, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
821
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
822 if (rmorigin) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
823 dsl_dataset_t *prev;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
824 VERIFY0(dsl_dataset_hold_obj(dp, prevobj, FTAG, &prev));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
825 dsl_destroy_snapshot_sync_impl(prev, B_FALSE, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
826 dsl_dataset_rele(prev, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
827 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
828 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
829
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
830 static void
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
831 dsl_destroy_head_sync(void *arg, dmu_tx_t *tx)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
832 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
833 dsl_destroy_head_arg_t *ddha = arg;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
834 dsl_pool_t *dp = dmu_tx_pool(tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
835 dsl_dataset_t *ds;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
836
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
837 VERIFY0(dsl_dataset_hold(dp, ddha->ddha_name, FTAG, &ds));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
838 dsl_destroy_head_sync_impl(ds, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
839 dsl_dataset_rele(ds, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
840 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
841
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
842 static void
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
843 dsl_destroy_head_begin_sync(void *arg, dmu_tx_t *tx)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
844 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
845 dsl_destroy_head_arg_t *ddha = arg;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
846 dsl_pool_t *dp = dmu_tx_pool(tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
847 dsl_dataset_t *ds;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
848
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
849 VERIFY0(dsl_dataset_hold(dp, ddha->ddha_name, FTAG, &ds));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
850
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
851 /* Mark it as inconsistent on-disk, in case we crash */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
852 dmu_buf_will_dirty(ds->ds_dbuf, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
853 ds->ds_phys->ds_flags |= DS_FLAG_INCONSISTENT;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
854
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
855 spa_history_log_internal_ds(ds, "destroy begin", tx, "");
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
856 dsl_dataset_rele(ds, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
857 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
858
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
859 int
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
860 dsl_destroy_head(const char *name)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
861 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
862 dsl_destroy_head_arg_t ddha;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
863 int error;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
864 spa_t *spa;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
865 boolean_t isenabled;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
866
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
867 #ifdef _KERNEL
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
868 zfs_destroy_unmount_origin(name);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
869 #endif
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
870
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
871 error = spa_open(name, &spa, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
872 if (error != 0)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
873 return (error);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
874 isenabled = spa_feature_is_enabled(spa,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
875 &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY]);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
876 spa_close(spa, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
877
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
878 ddha.ddha_name = name;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
879
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
880 if (!isenabled) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
881 objset_t *os;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
882
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
883 error = dsl_sync_task(name, dsl_destroy_head_check,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
884 dsl_destroy_head_begin_sync, &ddha, 0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
885 if (error != 0)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
886 return (error);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
887
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
888 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
889 * Head deletion is processed in one txg on old pools;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
890 * remove the objects from open context so that the txg sync
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
891 * is not too long.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
892 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
893 error = dmu_objset_own(name, DMU_OST_ANY, B_FALSE, FTAG, &os);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
894 if (error == 0) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
895 uint64_t prev_snap_txg =
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
896 dmu_objset_ds(os)->ds_phys->ds_prev_snap_txg;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
897 for (uint64_t obj = 0; error == 0;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
898 error = dmu_object_next(os, &obj, FALSE,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
899 prev_snap_txg))
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
900 (void) dmu_free_object(os, obj);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
901 /* sync out all frees */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
902 txg_wait_synced(dmu_objset_pool(os), 0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
903 dmu_objset_disown(os, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
904 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
905 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
906
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
907 return (dsl_sync_task(name, dsl_destroy_head_check,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
908 dsl_destroy_head_sync, &ddha, 0));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
909 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
910
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
911 /*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
912 * Note, this function is used as the callback for dmu_objset_find(). We
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
913 * always return 0 so that we will continue to find and process
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
914 * inconsistent datasets, even if we encounter an error trying to
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
915 * process one of them.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
916 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
917 /* ARGSUSED */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
918 int
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
919 dsl_destroy_inconsistent(const char *dsname, void *arg)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
920 {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
921 objset_t *os;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
922
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
923 if (dmu_objset_hold(dsname, FTAG, &os) == 0) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
924 boolean_t inconsistent = DS_IS_INCONSISTENT(dmu_objset_ds(os));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
925 dmu_objset_rele(os, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
926 if (inconsistent)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
927 (void) dsl_destroy_head(dsname);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
928 }
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
929 return (0);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents:
diff changeset
930 }