Mercurial > illumos > illumos-gate
annotate usr/src/uts/common/fs/zfs/dsl_dataset.c @ 6689:47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
6695465 divide by zero in txg_sync_thread() under heavy load
author | maybee |
---|---|
date | Thu, 22 May 2008 11:13:47 -0700 |
parents | 3a34b0dbb107 |
children | c511f317869e |
rev | line source |
---|---|
789 | 1 /* |
2 * CDDL HEADER START | |
3 * | |
4 * The contents of this file are subject to the terms of the | |
1544 | 5 * Common Development and Distribution License (the "License"). |
6 * You may not use this file except in compliance with the License. | |
789 | 7 * |
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 * or http://www.opensolaris.org/os/licensing. | |
10 * See the License for the specific language governing permissions | |
11 * and limitations under the License. | |
12 * | |
13 * When distributing Covered Code, include this CDDL HEADER in each | |
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 * If applicable, add the following below this CDDL HEADER, with the | |
16 * fields enclosed by brackets "[]" replaced with your own identifying | |
17 * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 * | |
19 * CDDL HEADER END | |
20 */ | |
21 /* | |
5831
48655d6b290b
6630761 In sub-filesystem, available space is less than refreservation space
ck153898
parents:
5712
diff
changeset
|
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
789 | 23 * Use is subject to license terms. |
24 */ | |
25 | |
26 #pragma ident "%Z%%M% %I% %E% SMI" | |
27 | |
28 #include <sys/dmu_objset.h> | |
29 #include <sys/dsl_dataset.h> | |
30 #include <sys/dsl_dir.h> | |
2082 | 31 #include <sys/dsl_prop.h> |
2199 | 32 #include <sys/dsl_synctask.h> |
789 | 33 #include <sys/dmu_traverse.h> |
34 #include <sys/dmu_tx.h> | |
35 #include <sys/arc.h> | |
36 #include <sys/zio.h> | |
37 #include <sys/zap.h> | |
38 #include <sys/unique.h> | |
39 #include <sys/zfs_context.h> | |
4007 | 40 #include <sys/zfs_ioctl.h> |
4543 | 41 #include <sys/spa.h> |
42 #include <sys/sunddi.h> | |
789 | 43 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
44 static char *dsl_reaper = "the grim reaper"; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
45 |
2199 | 46 static dsl_checkfunc_t dsl_dataset_destroy_begin_check; |
47 static dsl_syncfunc_t dsl_dataset_destroy_begin_sync; | |
48 static dsl_checkfunc_t dsl_dataset_rollback_check; | |
49 static dsl_syncfunc_t dsl_dataset_rollback_sync; | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
50 static dsl_syncfunc_t dsl_dataset_set_reservation_sync; |
1731
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
51 |
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3025
diff
changeset
|
52 #define DS_REF_MAX (1ULL << 62) |
789 | 53 |
54 #define DSL_DEADLIST_BLOCKSIZE SPA_MAXBLOCKSIZE | |
55 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
56 #define DSL_DATASET_IS_DESTROYED(ds) ((ds)->ds_owner == dsl_reaper) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
57 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
58 static void dsl_dataset_drop_ref(dsl_dataset_t *ds, void *tag); |
789 | 59 |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
60 /* |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
61 * Figure out how much of this delta should be propogated to the dsl_dir |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
62 * layer. If there's a refreservation, that space has already been |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
63 * partially accounted for in our ancestors. |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
64 */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
65 static int64_t |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
66 parent_delta(dsl_dataset_t *ds, int64_t delta) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
67 { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
68 uint64_t old_bytes, new_bytes; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
69 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
70 if (ds->ds_reserved == 0) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
71 return (delta); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
72 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
73 old_bytes = MAX(ds->ds_phys->ds_unique_bytes, ds->ds_reserved); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
74 new_bytes = MAX(ds->ds_phys->ds_unique_bytes + delta, ds->ds_reserved); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
75 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
76 ASSERT3U(ABS((int64_t)(new_bytes - old_bytes)), <=, ABS(delta)); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
77 return (new_bytes - old_bytes); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
78 } |
789 | 79 |
80 void | |
81 dsl_dataset_block_born(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx) | |
82 { | |
2082 | 83 int used = bp_get_dasize(tx->tx_pool->dp_spa, bp); |
789 | 84 int compressed = BP_GET_PSIZE(bp); |
85 int uncompressed = BP_GET_UCSIZE(bp); | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
86 int64_t delta; |
789 | 87 |
88 dprintf_bp(bp, "born, ds=%p\n", ds); | |
89 | |
90 ASSERT(dmu_tx_is_syncing(tx)); | |
91 /* It could have been compressed away to nothing */ | |
92 if (BP_IS_HOLE(bp)) | |
93 return; | |
94 ASSERT(BP_GET_TYPE(bp) != DMU_OT_NONE); | |
95 ASSERT3U(BP_GET_TYPE(bp), <, DMU_OT_NUMTYPES); | |
96 if (ds == NULL) { | |
97 /* | |
98 * Account for the meta-objset space in its placeholder | |
99 * dsl_dir. | |
100 */ | |
101 ASSERT3U(compressed, ==, uncompressed); /* it's all metadata */ | |
102 dsl_dir_diduse_space(tx->tx_pool->dp_mos_dir, | |
103 used, compressed, uncompressed, tx); | |
104 dsl_dir_dirty(tx->tx_pool->dp_mos_dir, tx); | |
105 return; | |
106 } | |
107 dmu_buf_will_dirty(ds->ds_dbuf, tx); | |
108 mutex_enter(&ds->ds_lock); | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
109 delta = parent_delta(ds, used); |
789 | 110 ds->ds_phys->ds_used_bytes += used; |
111 ds->ds_phys->ds_compressed_bytes += compressed; | |
112 ds->ds_phys->ds_uncompressed_bytes += uncompressed; | |
113 ds->ds_phys->ds_unique_bytes += used; | |
114 mutex_exit(&ds->ds_lock); | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
115 dsl_dir_diduse_space(ds->ds_dir, delta, compressed, uncompressed, tx); |
789 | 116 } |
117 | |
118 void | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
119 dsl_dataset_block_kill(dsl_dataset_t *ds, blkptr_t *bp, zio_t *pio, |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
120 dmu_tx_t *tx) |
789 | 121 { |
2082 | 122 int used = bp_get_dasize(tx->tx_pool->dp_spa, bp); |
789 | 123 int compressed = BP_GET_PSIZE(bp); |
124 int uncompressed = BP_GET_UCSIZE(bp); | |
125 | |
126 ASSERT(dmu_tx_is_syncing(tx)); | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
127 /* No block pointer => nothing to free */ |
789 | 128 if (BP_IS_HOLE(bp)) |
129 return; | |
130 | |
131 ASSERT(used > 0); | |
132 if (ds == NULL) { | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
133 int err; |
789 | 134 /* |
135 * Account for the meta-objset space in its placeholder | |
136 * dataset. | |
137 */ | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
138 err = arc_free(pio, tx->tx_pool->dp_spa, |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
139 tx->tx_txg, bp, NULL, NULL, pio ? ARC_NOWAIT: ARC_WAIT); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
140 ASSERT(err == 0); |
789 | 141 |
142 dsl_dir_diduse_space(tx->tx_pool->dp_mos_dir, | |
143 -used, -compressed, -uncompressed, tx); | |
144 dsl_dir_dirty(tx->tx_pool->dp_mos_dir, tx); | |
145 return; | |
146 } | |
147 ASSERT3P(tx->tx_pool, ==, ds->ds_dir->dd_pool); | |
148 | |
149 dmu_buf_will_dirty(ds->ds_dbuf, tx); | |
150 | |
151 if (bp->blk_birth > ds->ds_phys->ds_prev_snap_txg) { | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
152 int err; |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
153 int64_t delta; |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
154 |
789 | 155 dprintf_bp(bp, "freeing: %s", ""); |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
156 err = arc_free(pio, tx->tx_pool->dp_spa, |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
157 tx->tx_txg, bp, NULL, NULL, pio ? ARC_NOWAIT: ARC_WAIT); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
158 ASSERT(err == 0); |
789 | 159 |
160 mutex_enter(&ds->ds_lock); | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
161 ASSERT(ds->ds_phys->ds_unique_bytes >= used || |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
162 !DS_UNIQUE_IS_ACCURATE(ds)); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
163 delta = parent_delta(ds, -used); |
789 | 164 ds->ds_phys->ds_unique_bytes -= used; |
165 mutex_exit(&ds->ds_lock); | |
166 dsl_dir_diduse_space(ds->ds_dir, | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
167 delta, -compressed, -uncompressed, tx); |
789 | 168 } else { |
169 dprintf_bp(bp, "putting on dead list: %s", ""); | |
1544 | 170 VERIFY(0 == bplist_enqueue(&ds->ds_deadlist, bp, tx)); |
5712
81f1af42bafc
6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents:
5569
diff
changeset
|
171 ASSERT3U(ds->ds_prev->ds_object, ==, |
81f1af42bafc
6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents:
5569
diff
changeset
|
172 ds->ds_phys->ds_prev_snap_obj); |
81f1af42bafc
6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents:
5569
diff
changeset
|
173 ASSERT(ds->ds_prev->ds_phys->ds_num_children > 0); |
789 | 174 /* if (bp->blk_birth > prev prev snap txg) prev unique += bs */ |
5712
81f1af42bafc
6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents:
5569
diff
changeset
|
175 if (ds->ds_prev->ds_phys->ds_next_snap_obj == |
81f1af42bafc
6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents:
5569
diff
changeset
|
176 ds->ds_object && bp->blk_birth > |
81f1af42bafc
6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents:
5569
diff
changeset
|
177 ds->ds_prev->ds_phys->ds_prev_snap_txg) { |
81f1af42bafc
6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents:
5569
diff
changeset
|
178 dmu_buf_will_dirty(ds->ds_prev->ds_dbuf, tx); |
81f1af42bafc
6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents:
5569
diff
changeset
|
179 mutex_enter(&ds->ds_prev->ds_lock); |
81f1af42bafc
6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents:
5569
diff
changeset
|
180 ds->ds_prev->ds_phys->ds_unique_bytes += used; |
81f1af42bafc
6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents:
5569
diff
changeset
|
181 mutex_exit(&ds->ds_prev->ds_lock); |
789 | 182 } |
183 } | |
184 mutex_enter(&ds->ds_lock); | |
185 ASSERT3U(ds->ds_phys->ds_used_bytes, >=, used); | |
186 ds->ds_phys->ds_used_bytes -= used; | |
187 ASSERT3U(ds->ds_phys->ds_compressed_bytes, >=, compressed); | |
188 ds->ds_phys->ds_compressed_bytes -= compressed; | |
189 ASSERT3U(ds->ds_phys->ds_uncompressed_bytes, >=, uncompressed); | |
190 ds->ds_phys->ds_uncompressed_bytes -= uncompressed; | |
191 mutex_exit(&ds->ds_lock); | |
192 } | |
193 | |
1544 | 194 uint64_t |
195 dsl_dataset_prev_snap_txg(dsl_dataset_t *ds) | |
789 | 196 { |
2885 | 197 uint64_t trysnap = 0; |
198 | |
789 | 199 if (ds == NULL) |
1544 | 200 return (0); |
789 | 201 /* |
202 * The snapshot creation could fail, but that would cause an | |
203 * incorrect FALSE return, which would only result in an | |
204 * overestimation of the amount of space that an operation would | |
205 * consume, which is OK. | |
206 * | |
207 * There's also a small window where we could miss a pending | |
208 * snapshot, because we could set the sync task in the quiescing | |
209 * phase. So this should only be used as a guess. | |
210 */ | |
2885 | 211 if (ds->ds_trysnap_txg > |
212 spa_last_synced_txg(ds->ds_dir->dd_pool->dp_spa)) | |
213 trysnap = ds->ds_trysnap_txg; | |
214 return (MAX(ds->ds_phys->ds_prev_snap_txg, trysnap)); | |
1544 | 215 } |
216 | |
217 int | |
218 dsl_dataset_block_freeable(dsl_dataset_t *ds, uint64_t blk_birth) | |
219 { | |
220 return (blk_birth > dsl_dataset_prev_snap_txg(ds)); | |
789 | 221 } |
222 | |
223 /* ARGSUSED */ | |
224 static void | |
225 dsl_dataset_evict(dmu_buf_t *db, void *dsv) | |
226 { | |
227 dsl_dataset_t *ds = dsv; | |
228 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
229 ASSERT(ds->ds_owner == NULL || DSL_DATASET_IS_DESTROYED(ds)); |
789 | 230 |
231 dprintf_ds(ds, "evicting %s\n", ""); | |
232 | |
4787 | 233 unique_remove(ds->ds_fsid_guid); |
789 | 234 |
235 if (ds->ds_user_ptr != NULL) | |
236 ds->ds_user_evict_func(ds, ds->ds_user_ptr); | |
237 | |
238 if (ds->ds_prev) { | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
239 dsl_dataset_drop_ref(ds->ds_prev, ds); |
789 | 240 ds->ds_prev = NULL; |
241 } | |
242 | |
243 bplist_close(&ds->ds_deadlist); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
244 if (ds->ds_dir) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
245 dsl_dir_close(ds->ds_dir, ds); |
789 | 246 |
4787 | 247 ASSERT(!list_link_active(&ds->ds_synced_link)); |
789 | 248 |
2856 | 249 mutex_destroy(&ds->ds_lock); |
4787 | 250 mutex_destroy(&ds->ds_opening_lock); |
2856 | 251 mutex_destroy(&ds->ds_deadlist.bpl_lock); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
252 rw_destroy(&ds->ds_rwlock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
253 cv_destroy(&ds->ds_exclusive_cv); |
2856 | 254 |
789 | 255 kmem_free(ds, sizeof (dsl_dataset_t)); |
256 } | |
257 | |
1544 | 258 static int |
789 | 259 dsl_dataset_get_snapname(dsl_dataset_t *ds) |
260 { | |
261 dsl_dataset_phys_t *headphys; | |
262 int err; | |
263 dmu_buf_t *headdbuf; | |
264 dsl_pool_t *dp = ds->ds_dir->dd_pool; | |
265 objset_t *mos = dp->dp_meta_objset; | |
266 | |
267 if (ds->ds_snapname[0]) | |
1544 | 268 return (0); |
789 | 269 if (ds->ds_phys->ds_next_snap_obj == 0) |
1544 | 270 return (0); |
789 | 271 |
1544 | 272 err = dmu_bonus_hold(mos, ds->ds_dir->dd_phys->dd_head_dataset_obj, |
273 FTAG, &headdbuf); | |
274 if (err) | |
275 return (err); | |
789 | 276 headphys = headdbuf->db_data; |
277 err = zap_value_search(dp->dp_meta_objset, | |
4577 | 278 headphys->ds_snapnames_zapobj, ds->ds_object, 0, ds->ds_snapname); |
1544 | 279 dmu_buf_rele(headdbuf, FTAG); |
280 return (err); | |
789 | 281 } |
282 | |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
283 static int |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
284 dsl_dataset_snap_lookup(dsl_dataset_t *ds, const char *name, uint64_t *value) |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
285 { |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
286 objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
287 uint64_t snapobj = ds->ds_phys->ds_snapnames_zapobj; |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
288 matchtype_t mt; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
289 int err; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
290 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
291 if (ds->ds_phys->ds_flags & DS_FLAG_CI_DATASET) |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
292 mt = MT_FIRST; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
293 else |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
294 mt = MT_EXACT; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
295 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
296 err = zap_lookup_norm(mos, snapobj, name, 8, 1, |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
297 value, mt, NULL, 0, NULL); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
298 if (err == ENOTSUP && mt == MT_FIRST) |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
299 err = zap_lookup(mos, snapobj, name, 8, 1, value); |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
300 return (err); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
301 } |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
302 |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
303 static int |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
304 dsl_dataset_snap_remove(dsl_dataset_t *ds, char *name, dmu_tx_t *tx) |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
305 { |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
306 objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
307 uint64_t snapobj = ds->ds_phys->ds_snapnames_zapobj; |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
308 matchtype_t mt; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
309 int err; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
310 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
311 if (ds->ds_phys->ds_flags & DS_FLAG_CI_DATASET) |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
312 mt = MT_FIRST; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
313 else |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
314 mt = MT_EXACT; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
315 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
316 err = zap_remove_norm(mos, snapobj, name, mt, tx); |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
317 if (err == ENOTSUP && mt == MT_FIRST) |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
318 err = zap_remove(mos, snapobj, name, tx); |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
319 return (err); |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
320 } |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
321 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
322 static int |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
323 dsl_dataset_get_ref(dsl_pool_t *dp, uint64_t dsobj, void *tag, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
324 dsl_dataset_t **dsp) |
789 | 325 { |
326 objset_t *mos = dp->dp_meta_objset; | |
327 dmu_buf_t *dbuf; | |
328 dsl_dataset_t *ds; | |
1544 | 329 int err; |
789 | 330 |
331 ASSERT(RW_LOCK_HELD(&dp->dp_config_rwlock) || | |
332 dsl_pool_sync_context(dp)); | |
333 | |
1544 | 334 err = dmu_bonus_hold(mos, dsobj, tag, &dbuf); |
335 if (err) | |
336 return (err); | |
789 | 337 ds = dmu_buf_get_user(dbuf); |
338 if (ds == NULL) { | |
339 dsl_dataset_t *winner; | |
340 | |
341 ds = kmem_zalloc(sizeof (dsl_dataset_t), KM_SLEEP); | |
342 ds->ds_dbuf = dbuf; | |
343 ds->ds_object = dsobj; | |
344 ds->ds_phys = dbuf->db_data; | |
345 | |
2856 | 346 mutex_init(&ds->ds_lock, NULL, MUTEX_DEFAULT, NULL); |
4787 | 347 mutex_init(&ds->ds_opening_lock, NULL, MUTEX_DEFAULT, NULL); |
2856 | 348 mutex_init(&ds->ds_deadlist.bpl_lock, NULL, MUTEX_DEFAULT, |
349 NULL); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
350 rw_init(&ds->ds_rwlock, 0, 0, 0); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
351 cv_init(&ds->ds_exclusive_cv, NULL, CV_DEFAULT, NULL); |
2856 | 352 |
1544 | 353 err = bplist_open(&ds->ds_deadlist, |
789 | 354 mos, ds->ds_phys->ds_deadlist_obj); |
1544 | 355 if (err == 0) { |
356 err = dsl_dir_open_obj(dp, | |
357 ds->ds_phys->ds_dir_obj, NULL, ds, &ds->ds_dir); | |
358 } | |
359 if (err) { | |
360 /* | |
361 * we don't really need to close the blist if we | |
362 * just opened it. | |
363 */ | |
2856 | 364 mutex_destroy(&ds->ds_lock); |
4787 | 365 mutex_destroy(&ds->ds_opening_lock); |
2856 | 366 mutex_destroy(&ds->ds_deadlist.bpl_lock); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
367 rw_destroy(&ds->ds_rwlock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
368 cv_destroy(&ds->ds_exclusive_cv); |
1544 | 369 kmem_free(ds, sizeof (dsl_dataset_t)); |
370 dmu_buf_rele(dbuf, tag); | |
371 return (err); | |
372 } | |
789 | 373 |
374 if (ds->ds_dir->dd_phys->dd_head_dataset_obj == dsobj) { | |
375 ds->ds_snapname[0] = '\0'; | |
376 if (ds->ds_phys->ds_prev_snap_obj) { | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
377 err = dsl_dataset_get_ref(dp, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
378 ds->ds_phys->ds_prev_snap_obj, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
379 ds, &ds->ds_prev); |
789 | 380 } |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
381 } else if (zfs_flags & ZFS_DEBUG_SNAPNAMES) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
382 err = dsl_dataset_get_snapname(ds); |
789 | 383 } |
384 | |
5475
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
385 if (!dsl_dataset_is_snapshot(ds)) { |
5569
d3caac36d311
6634062 dsl_dataset_open_obj misuses RW_LOCK_HELD
ck153898
parents:
5518
diff
changeset
|
386 /* |
d3caac36d311
6634062 dsl_dataset_open_obj misuses RW_LOCK_HELD
ck153898
parents:
5518
diff
changeset
|
387 * In sync context, we're called with either no lock |
d3caac36d311
6634062 dsl_dataset_open_obj misuses RW_LOCK_HELD
ck153898
parents:
5518
diff
changeset
|
388 * or with the write lock. If we're not syncing, |
d3caac36d311
6634062 dsl_dataset_open_obj misuses RW_LOCK_HELD
ck153898
parents:
5518
diff
changeset
|
389 * we're always called with the read lock held. |
d3caac36d311
6634062 dsl_dataset_open_obj misuses RW_LOCK_HELD
ck153898
parents:
5518
diff
changeset
|
390 */ |
5475
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
391 boolean_t need_lock = |
5569
d3caac36d311
6634062 dsl_dataset_open_obj misuses RW_LOCK_HELD
ck153898
parents:
5518
diff
changeset
|
392 !RW_WRITE_HELD(&dp->dp_config_rwlock) && |
d3caac36d311
6634062 dsl_dataset_open_obj misuses RW_LOCK_HELD
ck153898
parents:
5518
diff
changeset
|
393 dsl_pool_sync_context(dp); |
5475
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
394 |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
395 if (need_lock) |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
396 rw_enter(&dp->dp_config_rwlock, RW_READER); |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
397 |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
398 err = dsl_prop_get_ds_locked(ds->ds_dir, |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
399 "refreservation", sizeof (uint64_t), 1, |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
400 &ds->ds_reserved, NULL); |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
401 if (err == 0) { |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
402 err = dsl_prop_get_ds_locked(ds->ds_dir, |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
403 "refquota", sizeof (uint64_t), 1, |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
404 &ds->ds_quota, NULL); |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
405 } |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
406 |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
407 if (need_lock) |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
408 rw_exit(&dp->dp_config_rwlock); |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
409 } else { |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
410 ds->ds_reserved = ds->ds_quota = 0; |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
411 } |
e140313199cc
6626338 assertion failed: 0 == dsl_prop_get_ds_locked(ds->ds_dir, "refreservation", sizeof (uint64_t), 1, &d
ck153898
parents:
5446
diff
changeset
|
412 |
1544 | 413 if (err == 0) { |
414 winner = dmu_buf_set_user_ie(dbuf, ds, &ds->ds_phys, | |
415 dsl_dataset_evict); | |
416 } | |
417 if (err || winner) { | |
789 | 418 bplist_close(&ds->ds_deadlist); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
419 if (ds->ds_prev) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
420 dsl_dataset_drop_ref(ds->ds_prev, ds); |
789 | 421 dsl_dir_close(ds->ds_dir, ds); |
2856 | 422 mutex_destroy(&ds->ds_lock); |
4787 | 423 mutex_destroy(&ds->ds_opening_lock); |
2856 | 424 mutex_destroy(&ds->ds_deadlist.bpl_lock); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
425 rw_destroy(&ds->ds_rwlock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
426 cv_destroy(&ds->ds_exclusive_cv); |
789 | 427 kmem_free(ds, sizeof (dsl_dataset_t)); |
1544 | 428 if (err) { |
429 dmu_buf_rele(dbuf, tag); | |
430 return (err); | |
431 } | |
789 | 432 ds = winner; |
433 } else { | |
4787 | 434 ds->ds_fsid_guid = |
789 | 435 unique_insert(ds->ds_phys->ds_fsid_guid); |
436 } | |
437 } | |
438 ASSERT3P(ds->ds_dbuf, ==, dbuf); | |
439 ASSERT3P(ds->ds_phys, ==, dbuf->db_data); | |
440 mutex_enter(&ds->ds_lock); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
441 if (!dsl_pool_sync_context(dp) && DSL_DATASET_IS_DESTROYED(ds)) { |
789 | 442 mutex_exit(&ds->ds_lock); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
443 dmu_buf_rele(ds->ds_dbuf, tag); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
444 return (ENOENT); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
445 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
446 mutex_exit(&ds->ds_lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
447 *dsp = ds; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
448 return (0); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
449 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
450 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
451 static int |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
452 dsl_dataset_hold_ref(dsl_dataset_t *ds, void *tag) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
453 { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
454 dsl_pool_t *dp = ds->ds_dir->dd_pool; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
455 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
456 /* |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
457 * In syncing context we don't want the rwlock lock: there |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
458 * may be an existing writer waiting for sync phase to |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
459 * finish. We don't need to worry about such writers, since |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
460 * sync phase is single-threaded, so the writer can't be |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
461 * doing anything while we are active. |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
462 */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
463 if (dsl_pool_sync_context(dp)) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
464 ASSERT(!DSL_DATASET_IS_DESTROYED(ds)); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
465 return (0); |
789 | 466 } |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
467 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
468 /* |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
469 * Normal users will hold the ds_rwlock as a READER until they |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
470 * are finished (i.e., call dsl_dataset_rele()). "Owners" will |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
471 * drop their READER lock after they set the ds_owner field. |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
472 * |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
473 * If the dataset is being destroyed, the destroy thread will |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
474 * obtain a WRITER lock for exclusive access after it's done its |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
475 * open-context work and then change the ds_owner to |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
476 * dsl_reaper once destruction is assured. So threads |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
477 * may block here temporarily, until the "destructability" of |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
478 * the dataset is determined. |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
479 */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
480 ASSERT(!RW_WRITE_HELD(&dp->dp_config_rwlock)); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
481 mutex_enter(&ds->ds_lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
482 while (!rw_tryenter(&ds->ds_rwlock, RW_READER)) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
483 rw_exit(&dp->dp_config_rwlock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
484 cv_wait(&ds->ds_exclusive_cv, &ds->ds_lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
485 if (DSL_DATASET_IS_DESTROYED(ds)) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
486 mutex_exit(&ds->ds_lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
487 dsl_dataset_drop_ref(ds, tag); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
488 rw_enter(&dp->dp_config_rwlock, RW_READER); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
489 return (ENOENT); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
490 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
491 rw_enter(&dp->dp_config_rwlock, RW_READER); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
492 } |
789 | 493 mutex_exit(&ds->ds_lock); |
1544 | 494 return (0); |
789 | 495 } |
496 | |
497 int | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
498 dsl_dataset_hold_obj(dsl_pool_t *dp, uint64_t dsobj, void *tag, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
499 dsl_dataset_t **dsp) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
500 { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
501 int err = dsl_dataset_get_ref(dp, dsobj, tag, dsp); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
502 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
503 if (err) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
504 return (err); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
505 return (dsl_dataset_hold_ref(*dsp, tag)); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
506 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
507 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
508 int |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
509 dsl_dataset_own_obj(dsl_pool_t *dp, uint64_t dsobj, int flags, void *owner, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
510 dsl_dataset_t **dsp) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
511 { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
512 int err = dsl_dataset_hold_obj(dp, dsobj, owner, dsp); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
513 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
514 ASSERT(DS_MODE_TYPE(flags) != DS_MODE_USER); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
515 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
516 if (err) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
517 return (err); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
518 if (!dsl_dataset_tryown(*dsp, DS_MODE_IS_INCONSISTENT(flags), owner)) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
519 dsl_dataset_rele(*dsp, owner); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
520 return (EBUSY); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
521 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
522 return (0); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
523 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
524 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
525 int |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
526 dsl_dataset_hold(const char *name, void *tag, dsl_dataset_t **dsp) |
789 | 527 { |
528 dsl_dir_t *dd; | |
529 dsl_pool_t *dp; | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
530 const char *snapname; |
789 | 531 uint64_t obj; |
532 int err = 0; | |
533 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
534 err = dsl_dir_open_spa(NULL, name, FTAG, &dd, &snapname); |
1544 | 535 if (err) |
536 return (err); | |
789 | 537 |
538 dp = dd->dd_pool; | |
539 obj = dd->dd_phys->dd_head_dataset_obj; | |
540 rw_enter(&dp->dp_config_rwlock, RW_READER); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
541 if (obj) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
542 err = dsl_dataset_get_ref(dp, obj, tag, dsp); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
543 else |
789 | 544 err = ENOENT; |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
545 if (err) |
789 | 546 goto out; |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
547 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
548 err = dsl_dataset_hold_ref(*dsp, tag); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
549 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
550 /* we may be looking for a snapshot */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
551 if (err == 0 && snapname != NULL) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
552 dsl_dataset_t *ds = NULL; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
553 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
554 if (*snapname++ != '@') { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
555 dsl_dataset_rele(*dsp, tag); |
789 | 556 err = ENOENT; |
557 goto out; | |
558 } | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
559 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
560 dprintf("looking for snapshot '%s'\n", snapname); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
561 err = dsl_dataset_snap_lookup(*dsp, snapname, &obj); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
562 if (err == 0) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
563 err = dsl_dataset_get_ref(dp, obj, tag, &ds); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
564 dsl_dataset_rele(*dsp, tag); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
565 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
566 ASSERT3U((err == 0), ==, (ds != NULL)); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
567 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
568 if (ds) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
569 mutex_enter(&ds->ds_lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
570 if (ds->ds_snapname[0] == 0) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
571 (void) strlcpy(ds->ds_snapname, snapname, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
572 sizeof (ds->ds_snapname)); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
573 mutex_exit(&ds->ds_lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
574 err = dsl_dataset_hold_ref(ds, tag); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
575 *dsp = err ? NULL : ds; |
789 | 576 } |
577 } | |
578 out: | |
579 rw_exit(&dp->dp_config_rwlock); | |
580 dsl_dir_close(dd, FTAG); | |
581 return (err); | |
582 } | |
583 | |
584 int | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
585 dsl_dataset_own(const char *name, int flags, void *owner, dsl_dataset_t **dsp) |
789 | 586 { |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
587 int err = dsl_dataset_hold(name, owner, dsp); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
588 if (err) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
589 return (err); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
590 if ((*dsp)->ds_phys->ds_num_children > 0 && |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
591 !DS_MODE_IS_READONLY(flags)) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
592 dsl_dataset_rele(*dsp, owner); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
593 return (EROFS); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
594 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
595 if (!dsl_dataset_tryown(*dsp, DS_MODE_IS_INCONSISTENT(flags), owner)) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
596 dsl_dataset_rele(*dsp, owner); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
597 return (EBUSY); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
598 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
599 return (0); |
789 | 600 } |
601 | |
602 void | |
603 dsl_dataset_name(dsl_dataset_t *ds, char *name) | |
604 { | |
605 if (ds == NULL) { | |
606 (void) strcpy(name, "mos"); | |
607 } else { | |
608 dsl_dir_name(ds->ds_dir, name); | |
1544 | 609 VERIFY(0 == dsl_dataset_get_snapname(ds)); |
789 | 610 if (ds->ds_snapname[0]) { |
611 (void) strcat(name, "@"); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
612 /* |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
613 * We use a "recursive" mutex so that we |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
614 * can call dprintf_ds() with ds_lock held. |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
615 */ |
789 | 616 if (!MUTEX_HELD(&ds->ds_lock)) { |
617 mutex_enter(&ds->ds_lock); | |
618 (void) strcat(name, ds->ds_snapname); | |
619 mutex_exit(&ds->ds_lock); | |
620 } else { | |
621 (void) strcat(name, ds->ds_snapname); | |
622 } | |
623 } | |
624 } | |
625 } | |
626 | |
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
627 static int |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
628 dsl_dataset_namelen(dsl_dataset_t *ds) |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
629 { |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
630 int result; |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
631 |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
632 if (ds == NULL) { |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
633 result = 3; /* "mos" */ |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
634 } else { |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
635 result = dsl_dir_namelen(ds->ds_dir); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
636 VERIFY(0 == dsl_dataset_get_snapname(ds)); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
637 if (ds->ds_snapname[0]) { |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
638 ++result; /* adding one for the @-sign */ |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
639 if (!MUTEX_HELD(&ds->ds_lock)) { |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
640 mutex_enter(&ds->ds_lock); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
641 result += strlen(ds->ds_snapname); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
642 mutex_exit(&ds->ds_lock); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
643 } else { |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
644 result += strlen(ds->ds_snapname); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
645 } |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
646 } |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
647 } |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
648 |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
649 return (result); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
650 } |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
651 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
652 static void |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
653 dsl_dataset_drop_ref(dsl_dataset_t *ds, void *tag) |
789 | 654 { |
1544 | 655 dmu_buf_rele(ds->ds_dbuf, tag); |
789 | 656 } |
657 | |
658 void | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
659 dsl_dataset_rele(dsl_dataset_t *ds, void *tag) |
5367 | 660 { |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
661 ASSERT(ds->ds_owner != tag); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
662 if (!dsl_pool_sync_context(ds->ds_dir->dd_pool)) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
663 rw_exit(&ds->ds_rwlock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
664 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
665 dsl_dataset_drop_ref(ds, tag); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
666 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
667 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
668 void |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
669 dsl_dataset_disown(dsl_dataset_t *ds, void *owner) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
670 { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
671 ASSERT((ds->ds_owner == owner && ds->ds_dbuf) || |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
672 (DSL_DATASET_IS_DESTROYED(ds) && ds->ds_dbuf == NULL)); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
673 |
5367 | 674 mutex_enter(&ds->ds_lock); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
675 ds->ds_owner = NULL; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
676 if (RW_WRITE_HELD(&ds->ds_rwlock)) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
677 rw_exit(&ds->ds_rwlock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
678 cv_broadcast(&ds->ds_exclusive_cv); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
679 } |
5367 | 680 mutex_exit(&ds->ds_lock); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
681 if (ds->ds_dbuf) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
682 dsl_dataset_drop_ref(ds, owner); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
683 else |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
684 dsl_dataset_evict(ds->ds_dbuf, ds); |
5367 | 685 } |
686 | |
687 boolean_t | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
688 dsl_dataset_tryown(dsl_dataset_t *ds, boolean_t inconsistentok, void *owner) |
5367 | 689 { |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
690 boolean_t gotit = FALSE; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
691 |
5367 | 692 mutex_enter(&ds->ds_lock); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
693 if (ds->ds_owner == NULL && |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
694 (!DS_IS_INCONSISTENT(ds) || inconsistentok)) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
695 ds->ds_owner = owner; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
696 if (!dsl_pool_sync_context(ds->ds_dir->dd_pool)) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
697 rw_exit(&ds->ds_rwlock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
698 gotit = TRUE; |
5367 | 699 } |
700 mutex_exit(&ds->ds_lock); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
701 return (gotit); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
702 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
703 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
704 void |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
705 dsl_dataset_make_exclusive(dsl_dataset_t *ds, void *owner) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
706 { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
707 ASSERT3P(owner, ==, ds->ds_owner); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
708 if (!RW_WRITE_HELD(&ds->ds_rwlock)) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
709 rw_enter(&ds->ds_rwlock, RW_WRITER); |
5367 | 710 } |
711 | |
712 void | |
789 | 713 dsl_dataset_create_root(dsl_pool_t *dp, uint64_t *ddobjp, dmu_tx_t *tx) |
714 { | |
715 objset_t *mos = dp->dp_meta_objset; | |
716 dmu_buf_t *dbuf; | |
717 dsl_dataset_phys_t *dsphys; | |
718 dsl_dataset_t *ds; | |
719 uint64_t dsobj; | |
720 dsl_dir_t *dd; | |
721 | |
722 dsl_dir_create_root(mos, ddobjp, tx); | |
1544 | 723 VERIFY(0 == dsl_dir_open_obj(dp, *ddobjp, NULL, FTAG, &dd)); |
789 | 724 |
928
36d72fe4da29
6349314 dmu_object_type names incorrect for DSL Directories and DSL Datasets
tabriz
parents:
885
diff
changeset
|
725 dsobj = dmu_object_alloc(mos, DMU_OT_DSL_DATASET, 0, |
36d72fe4da29
6349314 dmu_object_type names incorrect for DSL Directories and DSL Datasets
tabriz
parents:
885
diff
changeset
|
726 DMU_OT_DSL_DATASET, sizeof (dsl_dataset_phys_t), tx); |
1544 | 727 VERIFY(0 == dmu_bonus_hold(mos, dsobj, FTAG, &dbuf)); |
789 | 728 dmu_buf_will_dirty(dbuf, tx); |
729 dsphys = dbuf->db_data; | |
730 dsphys->ds_dir_obj = dd->dd_object; | |
731 dsphys->ds_fsid_guid = unique_create(); | |
732 (void) random_get_pseudo_bytes((void*)&dsphys->ds_guid, | |
733 sizeof (dsphys->ds_guid)); | |
734 dsphys->ds_snapnames_zapobj = | |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
735 zap_create_norm(mos, U8_TEXTPREP_TOUPPER, DMU_OT_DSL_DS_SNAP_MAP, |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
736 DMU_OT_NONE, 0, tx); |
789 | 737 dsphys->ds_creation_time = gethrestime_sec(); |
738 dsphys->ds_creation_txg = tx->tx_txg; | |
739 dsphys->ds_deadlist_obj = | |
740 bplist_create(mos, DSL_DEADLIST_BLOCKSIZE, tx); | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
741 if (spa_version(dp->dp_spa) >= SPA_VERSION_UNIQUE_ACCURATE) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
742 dsphys->ds_flags |= DS_FLAG_UNIQUE_ACCURATE; |
1544 | 743 dmu_buf_rele(dbuf, FTAG); |
789 | 744 |
745 dmu_buf_will_dirty(dd->dd_dbuf, tx); | |
746 dd->dd_phys->dd_head_dataset_obj = dsobj; | |
747 dsl_dir_close(dd, FTAG); | |
748 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
749 VERIFY(0 == dsl_dataset_get_ref(dp, dsobj, FTAG, &ds)); |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
750 (void) dmu_objset_create_impl(dp->dp_spa, ds, |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
751 &ds->ds_phys->ds_bp, DMU_OST_ZFS, tx); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
752 dsl_dataset_drop_ref(ds, FTAG); |
789 | 753 } |
754 | |
2199 | 755 uint64_t |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
756 dsl_dataset_create_sync_impl(dsl_dir_t *dd, dsl_dataset_t *origin, |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
757 uint64_t flags, dmu_tx_t *tx) |
789 | 758 { |
5367 | 759 dsl_pool_t *dp = dd->dd_pool; |
789 | 760 dmu_buf_t *dbuf; |
761 dsl_dataset_phys_t *dsphys; | |
5367 | 762 uint64_t dsobj; |
789 | 763 objset_t *mos = dp->dp_meta_objset; |
764 | |
5367 | 765 ASSERT(origin == NULL || origin->ds_dir->dd_pool == dp); |
766 ASSERT(origin == NULL || origin->ds_phys->ds_num_children > 0); | |
789 | 767 ASSERT(dmu_tx_is_syncing(tx)); |
5367 | 768 ASSERT(dd->dd_phys->dd_head_dataset_obj == 0); |
789 | 769 |
928
36d72fe4da29
6349314 dmu_object_type names incorrect for DSL Directories and DSL Datasets
tabriz
parents:
885
diff
changeset
|
770 dsobj = dmu_object_alloc(mos, DMU_OT_DSL_DATASET, 0, |
36d72fe4da29
6349314 dmu_object_type names incorrect for DSL Directories and DSL Datasets
tabriz
parents:
885
diff
changeset
|
771 DMU_OT_DSL_DATASET, sizeof (dsl_dataset_phys_t), tx); |
1544 | 772 VERIFY(0 == dmu_bonus_hold(mos, dsobj, FTAG, &dbuf)); |
789 | 773 dmu_buf_will_dirty(dbuf, tx); |
774 dsphys = dbuf->db_data; | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
775 bzero(dsphys, sizeof (dsl_dataset_phys_t)); |
789 | 776 dsphys->ds_dir_obj = dd->dd_object; |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
777 dsphys->ds_flags = flags; |
789 | 778 dsphys->ds_fsid_guid = unique_create(); |
779 (void) random_get_pseudo_bytes((void*)&dsphys->ds_guid, | |
780 sizeof (dsphys->ds_guid)); | |
781 dsphys->ds_snapnames_zapobj = | |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
782 zap_create_norm(mos, U8_TEXTPREP_TOUPPER, DMU_OT_DSL_DS_SNAP_MAP, |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
783 DMU_OT_NONE, 0, tx); |
789 | 784 dsphys->ds_creation_time = gethrestime_sec(); |
785 dsphys->ds_creation_txg = tx->tx_txg; | |
786 dsphys->ds_deadlist_obj = | |
787 bplist_create(mos, DSL_DEADLIST_BLOCKSIZE, tx); | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
788 |
5367 | 789 if (origin) { |
790 dsphys->ds_prev_snap_obj = origin->ds_object; | |
789 | 791 dsphys->ds_prev_snap_txg = |
5367 | 792 origin->ds_phys->ds_creation_txg; |
789 | 793 dsphys->ds_used_bytes = |
5367 | 794 origin->ds_phys->ds_used_bytes; |
789 | 795 dsphys->ds_compressed_bytes = |
5367 | 796 origin->ds_phys->ds_compressed_bytes; |
789 | 797 dsphys->ds_uncompressed_bytes = |
5367 | 798 origin->ds_phys->ds_uncompressed_bytes; |
799 dsphys->ds_bp = origin->ds_phys->ds_bp; | |
6502
66aef5f20377
6694731 drc->drc_real_ds->ds_phys->ds_flags & (1ULL<<0), file: ../../common/fs/zfs/dmu_send.c, line: 1069
timh
parents:
6492
diff
changeset
|
800 dsphys->ds_flags |= origin->ds_phys->ds_flags; |
789 | 801 |
5367 | 802 dmu_buf_will_dirty(origin->ds_dbuf, tx); |
803 origin->ds_phys->ds_num_children++; | |
789 | 804 |
805 dmu_buf_will_dirty(dd->dd_dbuf, tx); | |
5367 | 806 dd->dd_phys->dd_origin_obj = origin->ds_object; |
789 | 807 } |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
808 |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
809 if (spa_version(dp->dp_spa) >= SPA_VERSION_UNIQUE_ACCURATE) |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
810 dsphys->ds_flags |= DS_FLAG_UNIQUE_ACCURATE; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
811 |
1544 | 812 dmu_buf_rele(dbuf, FTAG); |
789 | 813 |
814 dmu_buf_will_dirty(dd->dd_dbuf, tx); | |
815 dd->dd_phys->dd_head_dataset_obj = dsobj; | |
5367 | 816 |
817 return (dsobj); | |
818 } | |
819 | |
820 uint64_t | |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
821 dsl_dataset_create_sync(dsl_dir_t *pdd, const char *lastname, |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
822 dsl_dataset_t *origin, uint64_t flags, cred_t *cr, dmu_tx_t *tx) |
5367 | 823 { |
824 dsl_pool_t *dp = pdd->dd_pool; | |
825 uint64_t dsobj, ddobj; | |
826 dsl_dir_t *dd; | |
827 | |
828 ASSERT(lastname[0] != '@'); | |
829 | |
830 ddobj = dsl_dir_create_sync(pdd, lastname, tx); | |
831 VERIFY(0 == dsl_dir_open_obj(dp, ddobj, lastname, FTAG, &dd)); | |
832 | |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
833 dsobj = dsl_dataset_create_sync_impl(dd, origin, flags, tx); |
5367 | 834 |
835 dsl_deleg_set_create_perms(dd, tx, cr); | |
836 | |
789 | 837 dsl_dir_close(dd, FTAG); |
838 | |
2199 | 839 return (dsobj); |
840 } | |
841 | |
842 struct destroyarg { | |
843 dsl_sync_task_group_t *dstg; | |
844 char *snapname; | |
845 char *failed; | |
846 }; | |
847 | |
848 static int | |
849 dsl_snapshot_destroy_one(char *name, void *arg) | |
850 { | |
851 struct destroyarg *da = arg; | |
852 dsl_dataset_t *ds; | |
853 char *cp; | |
854 int err; | |
855 | |
856 (void) strcat(name, "@"); | |
857 (void) strcat(name, da->snapname); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
858 err = dsl_dataset_own(name, DS_MODE_READONLY | DS_MODE_INCONSISTENT, |
4007 | 859 da->dstg, &ds); |
2199 | 860 cp = strchr(name, '@'); |
861 *cp = '\0'; | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
862 if (err == 0) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
863 dsl_dataset_make_exclusive(ds, da->dstg); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
864 dsl_sync_task_create(da->dstg, dsl_dataset_destroy_check, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
865 dsl_dataset_destroy_sync, ds, da->dstg, 0); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
866 } else if (err == ENOENT) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
867 err = 0; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
868 } else { |
2199 | 869 (void) strcpy(da->failed, name); |
870 } | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
871 return (err); |
789 | 872 } |
873 | |
2199 | 874 /* |
875 * Destroy 'snapname' in all descendants of 'fsname'. | |
876 */ | |
877 #pragma weak dmu_snapshots_destroy = dsl_snapshots_destroy | |
878 int | |
879 dsl_snapshots_destroy(char *fsname, char *snapname) | |
880 { | |
881 int err; | |
882 struct destroyarg da; | |
883 dsl_sync_task_t *dst; | |
884 spa_t *spa; | |
885 | |
4603
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
886 err = spa_open(fsname, &spa, FTAG); |
2199 | 887 if (err) |
888 return (err); | |
889 da.dstg = dsl_sync_task_group_create(spa_get_dsl(spa)); | |
890 da.snapname = snapname; | |
891 da.failed = fsname; | |
892 | |
893 err = dmu_objset_find(fsname, | |
2417 | 894 dsl_snapshot_destroy_one, &da, DS_FIND_CHILDREN); |
2199 | 895 |
896 if (err == 0) | |
897 err = dsl_sync_task_group_wait(da.dstg); | |
898 | |
899 for (dst = list_head(&da.dstg->dstg_tasks); dst; | |
900 dst = list_next(&da.dstg->dstg_tasks, dst)) { | |
901 dsl_dataset_t *ds = dst->dst_arg1; | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
902 /* |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
903 * Return the file system name that triggered the error |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
904 */ |
2199 | 905 if (dst->dst_err) { |
906 dsl_dataset_name(ds, fsname); | |
4603
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
907 *strchr(fsname, '@') = '\0'; |
2199 | 908 } |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
909 dsl_dataset_disown(ds, da.dstg); |
2199 | 910 } |
911 | |
912 dsl_sync_task_group_destroy(da.dstg); | |
913 spa_close(spa, FTAG); | |
914 return (err); | |
915 } | |
916 | |
5367 | 917 /* |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
918 * ds must be opened as OWNER. On return (whether successful or not), |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
919 * ds will be closed and caller can no longer dereference it. |
5367 | 920 */ |
789 | 921 int |
5367 | 922 dsl_dataset_destroy(dsl_dataset_t *ds, void *tag) |
789 | 923 { |
924 int err; | |
2199 | 925 dsl_sync_task_group_t *dstg; |
926 objset_t *os; | |
789 | 927 dsl_dir_t *dd; |
2199 | 928 uint64_t obj; |
929 | |
5367 | 930 if (dsl_dataset_is_snapshot(ds)) { |
2199 | 931 /* Destroying a snapshot is simpler */ |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
932 dsl_dataset_make_exclusive(ds, tag); |
2199 | 933 err = dsl_sync_task_do(ds->ds_dir->dd_pool, |
934 dsl_dataset_destroy_check, dsl_dataset_destroy_sync, | |
5367 | 935 ds, tag, 0); |
936 goto out; | |
2199 | 937 } |
938 | |
939 dd = ds->ds_dir; | |
789 | 940 |
2199 | 941 /* |
942 * Check for errors and mark this ds as inconsistent, in | |
943 * case we crash while freeing the objects. | |
944 */ | |
945 err = dsl_sync_task_do(dd->dd_pool, dsl_dataset_destroy_begin_check, | |
946 dsl_dataset_destroy_begin_sync, ds, NULL, 0); | |
5367 | 947 if (err) |
948 goto out; | |
949 | |
950 err = dmu_objset_open_ds(ds, DMU_OST_ANY, &os); | |
951 if (err) | |
952 goto out; | |
2199 | 953 |
954 /* | |
955 * remove the objects in open context, so that we won't | |
956 * have too much to do in syncing context. | |
957 */ | |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
958 for (obj = 0; err == 0; err = dmu_object_next(os, &obj, FALSE, |
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2885
diff
changeset
|
959 ds->ds_phys->ds_prev_snap_txg)) { |
2199 | 960 dmu_tx_t *tx = dmu_tx_create(os); |
961 dmu_tx_hold_free(tx, obj, 0, DMU_OBJECT_END); | |
962 dmu_tx_hold_bonus(tx, obj); | |
963 err = dmu_tx_assign(tx, TXG_WAIT); | |
964 if (err) { | |
965 /* | |
966 * Perhaps there is not enough disk | |
967 * space. Just deal with it from | |
968 * dsl_dataset_destroy_sync(). | |
969 */ | |
970 dmu_tx_abort(tx); | |
971 continue; | |
972 } | |
973 VERIFY(0 == dmu_object_free(os, obj, tx)); | |
974 dmu_tx_commit(tx); | |
975 } | |
976 | |
977 dmu_objset_close(os); | |
978 if (err != ESRCH) | |
5367 | 979 goto out; |
2199 | 980 |
5367 | 981 if (ds->ds_user_ptr) { |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
982 /* |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
983 * We need to sync out all in-flight IO before we try |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
984 * to evict (the dataset evict func is trying to clear |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
985 * the cached entries for this dataset in the ARC). |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
986 */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
987 txg_wait_synced(dd->dd_pool, 0); |
5367 | 988 ds->ds_user_evict_func(ds, ds->ds_user_ptr); |
989 ds->ds_user_ptr = NULL; | |
990 } | |
991 | |
992 rw_enter(&dd->dd_pool->dp_config_rwlock, RW_READER); | |
993 err = dsl_dir_open_obj(dd->dd_pool, dd->dd_object, NULL, FTAG, &dd); | |
994 rw_exit(&dd->dd_pool->dp_config_rwlock); | |
995 | |
1544 | 996 if (err) |
5367 | 997 goto out; |
789 | 998 |
2199 | 999 /* |
1000 * Blow away the dsl_dir + head dataset. | |
1001 */ | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1002 dsl_dataset_make_exclusive(ds, tag); |
2199 | 1003 dstg = dsl_sync_task_group_create(ds->ds_dir->dd_pool); |
1004 dsl_sync_task_create(dstg, dsl_dataset_destroy_check, | |
5367 | 1005 dsl_dataset_destroy_sync, ds, tag, 0); |
2199 | 1006 dsl_sync_task_create(dstg, dsl_dir_destroy_check, |
1007 dsl_dir_destroy_sync, dd, FTAG, 0); | |
1008 err = dsl_sync_task_group_wait(dstg); | |
1009 dsl_sync_task_group_destroy(dstg); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1010 /* if it is successful, dsl_dir_destroy_sync will close the dd */ |
5367 | 1011 if (err) |
2199 | 1012 dsl_dir_close(dd, FTAG); |
5367 | 1013 out: |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1014 dsl_dataset_disown(ds, tag); |
789 | 1015 return (err); |
1016 } | |
1017 | |
1018 int | |
5367 | 1019 dsl_dataset_rollback(dsl_dataset_t *ds, dmu_objset_type_t ost) |
789 | 1020 { |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1021 ASSERT(ds->ds_owner); |
5367 | 1022 |
2199 | 1023 return (dsl_sync_task_do(ds->ds_dir->dd_pool, |
1024 dsl_dataset_rollback_check, dsl_dataset_rollback_sync, | |
5367 | 1025 ds, &ost, 0)); |
789 | 1026 } |
1027 | |
1028 void * | |
1029 dsl_dataset_set_user_ptr(dsl_dataset_t *ds, | |
1030 void *p, dsl_dataset_evict_func_t func) | |
1031 { | |
1032 void *old; | |
1033 | |
1034 mutex_enter(&ds->ds_lock); | |
1035 old = ds->ds_user_ptr; | |
1036 if (old == NULL) { | |
1037 ds->ds_user_ptr = p; | |
1038 ds->ds_user_evict_func = func; | |
1039 } | |
1040 mutex_exit(&ds->ds_lock); | |
1041 return (old); | |
1042 } | |
1043 | |
1044 void * | |
1045 dsl_dataset_get_user_ptr(dsl_dataset_t *ds) | |
1046 { | |
1047 return (ds->ds_user_ptr); | |
1048 } | |
1049 | |
1050 | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
1051 blkptr_t * |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
1052 dsl_dataset_get_blkptr(dsl_dataset_t *ds) |
789 | 1053 { |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
1054 return (&ds->ds_phys->ds_bp); |
789 | 1055 } |
1056 | |
1057 void | |
1058 dsl_dataset_set_blkptr(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx) | |
1059 { | |
1060 ASSERT(dmu_tx_is_syncing(tx)); | |
1061 /* If it's the meta-objset, set dp_meta_rootbp */ | |
1062 if (ds == NULL) { | |
1063 tx->tx_pool->dp_meta_rootbp = *bp; | |
1064 } else { | |
1065 dmu_buf_will_dirty(ds->ds_dbuf, tx); | |
1066 ds->ds_phys->ds_bp = *bp; | |
1067 } | |
1068 } | |
1069 | |
1070 spa_t * | |
1071 dsl_dataset_get_spa(dsl_dataset_t *ds) | |
1072 { | |
1073 return (ds->ds_dir->dd_pool->dp_spa); | |
1074 } | |
1075 | |
1076 void | |
1077 dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx) | |
1078 { | |
1079 dsl_pool_t *dp; | |
1080 | |
1081 if (ds == NULL) /* this is the meta-objset */ | |
1082 return; | |
1083 | |
1084 ASSERT(ds->ds_user_ptr != NULL); | |
2885 | 1085 |
1086 if (ds->ds_phys->ds_next_snap_obj != 0) | |
1087 panic("dirtying snapshot!"); | |
789 | 1088 |
1089 dp = ds->ds_dir->dd_pool; | |
1090 | |
1091 if (txg_list_add(&dp->dp_dirty_datasets, ds, tx->tx_txg) == 0) { | |
1092 /* up the hold count until we can be written out */ | |
1093 dmu_buf_add_ref(ds->ds_dbuf, ds); | |
1094 } | |
1095 } | |
1096 | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1097 /* |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1098 * The unique space in the head dataset can be calculated by subtracting |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1099 * the space used in the most recent snapshot, that is still being used |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1100 * in this file system, from the space currently in use. To figure out |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1101 * the space in the most recent snapshot still in use, we need to take |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1102 * the total space used in the snapshot and subtract out the space that |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1103 * has been freed up since the snapshot was taken. |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1104 */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1105 static void |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1106 dsl_dataset_recalc_head_uniq(dsl_dataset_t *ds) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1107 { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1108 uint64_t mrs_used; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1109 uint64_t dlused, dlcomp, dluncomp; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1110 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1111 ASSERT(ds->ds_object == ds->ds_dir->dd_phys->dd_head_dataset_obj); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1112 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1113 if (ds->ds_phys->ds_prev_snap_obj != 0) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1114 mrs_used = ds->ds_prev->ds_phys->ds_used_bytes; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1115 else |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1116 mrs_used = 0; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1117 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1118 VERIFY(0 == bplist_space(&ds->ds_deadlist, &dlused, &dlcomp, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1119 &dluncomp)); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1120 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1121 ASSERT3U(dlused, <=, mrs_used); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1122 ds->ds_phys->ds_unique_bytes = |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1123 ds->ds_phys->ds_used_bytes - (mrs_used - dlused); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1124 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1125 if (!DS_UNIQUE_IS_ACCURATE(ds) && |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1126 spa_version(ds->ds_dir->dd_pool->dp_spa) >= |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1127 SPA_VERSION_UNIQUE_ACCURATE) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1128 ds->ds_phys->ds_flags |= DS_FLAG_UNIQUE_ACCURATE; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1129 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1130 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1131 static uint64_t |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1132 dsl_dataset_unique(dsl_dataset_t *ds) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1133 { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1134 if (!DS_UNIQUE_IS_ACCURATE(ds) && !dsl_dataset_is_snapshot(ds)) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1135 dsl_dataset_recalc_head_uniq(ds); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1136 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1137 return (ds->ds_phys->ds_unique_bytes); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1138 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1139 |
789 | 1140 struct killarg { |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1141 int64_t *usedp; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1142 int64_t *compressedp; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1143 int64_t *uncompressedp; |
789 | 1144 zio_t *zio; |
1145 dmu_tx_t *tx; | |
1146 }; | |
1147 | |
1148 static int | |
1149 kill_blkptr(traverse_blk_cache_t *bc, spa_t *spa, void *arg) | |
1150 { | |
1151 struct killarg *ka = arg; | |
1152 blkptr_t *bp = &bc->bc_blkptr; | |
1153 | |
1154 ASSERT3U(bc->bc_errno, ==, 0); | |
1155 | |
1156 /* | |
1157 * Since this callback is not called concurrently, no lock is | |
1158 * needed on the accounting values. | |
1159 */ | |
2082 | 1160 *ka->usedp += bp_get_dasize(spa, bp); |
789 | 1161 *ka->compressedp += BP_GET_PSIZE(bp); |
1162 *ka->uncompressedp += BP_GET_UCSIZE(bp); | |
1163 /* XXX check for EIO? */ | |
1164 (void) arc_free(ka->zio, spa, ka->tx->tx_txg, bp, NULL, NULL, | |
1165 ARC_NOWAIT); | |
1166 return (0); | |
1167 } | |
1168 | |
1169 /* ARGSUSED */ | |
2199 | 1170 static int |
1171 dsl_dataset_rollback_check(void *arg1, void *arg2, dmu_tx_t *tx) | |
789 | 1172 { |
2199 | 1173 dsl_dataset_t *ds = arg1; |
5367 | 1174 dmu_objset_type_t *ost = arg2; |
789 | 1175 |
2199 | 1176 /* |
5367 | 1177 * We can only roll back to emptyness if it is a ZPL objset. |
2199 | 1178 */ |
5367 | 1179 if (*ost != DMU_OST_ZFS && ds->ds_phys->ds_prev_snap_txg == 0) |
789 | 1180 return (EINVAL); |
1181 | |
2199 | 1182 /* |
1183 * This must not be a snapshot. | |
1184 */ | |
1185 if (ds->ds_phys->ds_next_snap_obj != 0) | |
1186 return (EINVAL); | |
789 | 1187 |
1188 /* | |
1189 * If we made changes this txg, traverse_dsl_dataset won't find | |
1190 * them. Try again. | |
1191 */ | |
2199 | 1192 if (ds->ds_phys->ds_bp.blk_birth >= tx->tx_txg) |
789 | 1193 return (EAGAIN); |
2199 | 1194 |
1195 return (0); | |
1196 } | |
789 | 1197 |
2199 | 1198 /* ARGSUSED */ |
1199 static void | |
4543 | 1200 dsl_dataset_rollback_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
2199 | 1201 { |
1202 dsl_dataset_t *ds = arg1; | |
5367 | 1203 dmu_objset_type_t *ost = arg2; |
2199 | 1204 objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset; |
789 | 1205 |
1206 dmu_buf_will_dirty(ds->ds_dbuf, tx); | |
1207 | |
4967
8d0de61ff354
6597381 BAD TRAP: type=e (#pf Page fault) rp=ffffff00043a48f0 addr=28 occurred in module "<unknown>" due to
perrin
parents:
4935
diff
changeset
|
1208 /* |
8d0de61ff354
6597381 BAD TRAP: type=e (#pf Page fault) rp=ffffff00043a48f0 addr=28 occurred in module "<unknown>" due to
perrin
parents:
4935
diff
changeset
|
1209 * Before the roll back destroy the zil. |
8d0de61ff354
6597381 BAD TRAP: type=e (#pf Page fault) rp=ffffff00043a48f0 addr=28 occurred in module "<unknown>" due to
perrin
parents:
4935
diff
changeset
|
1210 */ |
8d0de61ff354
6597381 BAD TRAP: type=e (#pf Page fault) rp=ffffff00043a48f0 addr=28 occurred in module "<unknown>" due to
perrin
parents:
4935
diff
changeset
|
1211 if (ds->ds_user_ptr != NULL) { |
8d0de61ff354
6597381 BAD TRAP: type=e (#pf Page fault) rp=ffffff00043a48f0 addr=28 occurred in module "<unknown>" due to
perrin
parents:
4935
diff
changeset
|
1212 zil_rollback_destroy( |
8d0de61ff354
6597381 BAD TRAP: type=e (#pf Page fault) rp=ffffff00043a48f0 addr=28 occurred in module "<unknown>" due to
perrin
parents:
4935
diff
changeset
|
1213 ((objset_impl_t *)ds->ds_user_ptr)->os_zil, tx); |
5367 | 1214 |
1215 /* | |
1216 * We need to make sure that the objset_impl_t is reopened after | |
1217 * we do the rollback, otherwise it will have the wrong | |
1218 * objset_phys_t. Normally this would happen when this | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1219 * dataset-open is closed, thus causing the |
5367 | 1220 * dataset to be immediately evicted. But when doing "zfs recv |
1221 * -F", we reopen the objset before that, so that there is no | |
1222 * window where the dataset is closed and inconsistent. | |
1223 */ | |
1224 ds->ds_user_evict_func(ds, ds->ds_user_ptr); | |
1225 ds->ds_user_ptr = NULL; | |
4967
8d0de61ff354
6597381 BAD TRAP: type=e (#pf Page fault) rp=ffffff00043a48f0 addr=28 occurred in module "<unknown>" due to
perrin
parents:
4935
diff
changeset
|
1226 } |
4935
c80bf0e6f4aa
6534949 Stale need for range locking comment in zvol.c
perrin
parents:
4787
diff
changeset
|
1227 |
789 | 1228 /* Zero out the deadlist. */ |
1229 bplist_close(&ds->ds_deadlist); | |
1230 bplist_destroy(mos, ds->ds_phys->ds_deadlist_obj, tx); | |
1231 ds->ds_phys->ds_deadlist_obj = | |
1232 bplist_create(mos, DSL_DEADLIST_BLOCKSIZE, tx); | |
1544 | 1233 VERIFY(0 == bplist_open(&ds->ds_deadlist, mos, |
1234 ds->ds_phys->ds_deadlist_obj)); | |
789 | 1235 |
1236 { | |
1237 /* Free blkptrs that we gave birth to */ | |
1238 zio_t *zio; | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1239 int64_t used = 0, compressed = 0, uncompressed = 0; |
789 | 1240 struct killarg ka; |
5518
85721e07d1fa
6630707 assertion failed: used >= 0 || dd->dd_used_bytes >= -used, file: dsl_dir.c, line: 904
ck153898
parents:
5481
diff
changeset
|
1241 int64_t delta; |
789 | 1242 |
1243 zio = zio_root(tx->tx_pool->dp_spa, NULL, NULL, | |
1244 ZIO_FLAG_MUSTSUCCEED); | |
1245 ka.usedp = &used; | |
1246 ka.compressedp = &compressed; | |
1247 ka.uncompressedp = &uncompressed; | |
1248 ka.zio = zio; | |
1249 ka.tx = tx; | |
1250 (void) traverse_dsl_dataset(ds, ds->ds_phys->ds_prev_snap_txg, | |
1251 ADVANCE_POST, kill_blkptr, &ka); | |
1252 (void) zio_wait(zio); | |
1253 | |
5518
85721e07d1fa
6630707 assertion failed: used >= 0 || dd->dd_used_bytes >= -used, file: dsl_dir.c, line: 904
ck153898
parents:
5481
diff
changeset
|
1254 /* only deduct space beyond any refreservation */ |
85721e07d1fa
6630707 assertion failed: used >= 0 || dd->dd_used_bytes >= -used, file: dsl_dir.c, line: 904
ck153898
parents:
5481
diff
changeset
|
1255 delta = parent_delta(ds, -used); |
2199 | 1256 dsl_dir_diduse_space(ds->ds_dir, |
5518
85721e07d1fa
6630707 assertion failed: used >= 0 || dd->dd_used_bytes >= -used, file: dsl_dir.c, line: 904
ck153898
parents:
5481
diff
changeset
|
1257 delta, -compressed, -uncompressed, tx); |
789 | 1258 } |
1259 | |
5367 | 1260 if (ds->ds_prev) { |
1261 /* Change our contents to that of the prev snapshot */ | |
1262 ASSERT3U(ds->ds_prev->ds_object, ==, | |
1263 ds->ds_phys->ds_prev_snap_obj); | |
1264 ds->ds_phys->ds_bp = ds->ds_prev->ds_phys->ds_bp; | |
1265 ds->ds_phys->ds_used_bytes = | |
1266 ds->ds_prev->ds_phys->ds_used_bytes; | |
1267 ds->ds_phys->ds_compressed_bytes = | |
1268 ds->ds_prev->ds_phys->ds_compressed_bytes; | |
1269 ds->ds_phys->ds_uncompressed_bytes = | |
1270 ds->ds_prev->ds_phys->ds_uncompressed_bytes; | |
1271 ds->ds_phys->ds_flags = ds->ds_prev->ds_phys->ds_flags; | |
1272 ds->ds_phys->ds_unique_bytes = 0; | |
789 | 1273 |
5367 | 1274 if (ds->ds_prev->ds_phys->ds_next_snap_obj == ds->ds_object) { |
1275 dmu_buf_will_dirty(ds->ds_prev->ds_dbuf, tx); | |
1276 ds->ds_prev->ds_phys->ds_unique_bytes = 0; | |
1277 } | |
1278 } else { | |
1279 /* Zero out our contents, recreate objset */ | |
1280 bzero(&ds->ds_phys->ds_bp, sizeof (blkptr_t)); | |
1281 ds->ds_phys->ds_used_bytes = 0; | |
1282 ds->ds_phys->ds_compressed_bytes = 0; | |
1283 ds->ds_phys->ds_uncompressed_bytes = 0; | |
1284 ds->ds_phys->ds_flags = 0; | |
1285 ds->ds_phys->ds_unique_bytes = 0; | |
1286 (void) dmu_objset_create_impl(ds->ds_dir->dd_pool->dp_spa, ds, | |
1287 &ds->ds_phys->ds_bp, *ost, tx); | |
2532
752725c22841
6448999 panic: used == ds->ds_phys->ds_unique_bytes
ahrens
parents:
2417
diff
changeset
|
1288 } |
4543 | 1289 |
1290 spa_history_internal_log(LOG_DS_ROLLBACK, ds->ds_dir->dd_pool->dp_spa, | |
1291 tx, cr, "dataset = %llu", ds->ds_object); | |
789 | 1292 } |
1293 | |
1731
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1294 /* ARGSUSED */ |
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1295 static int |
2199 | 1296 dsl_dataset_destroy_begin_check(void *arg1, void *arg2, dmu_tx_t *tx) |
1731
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1297 { |
2199 | 1298 dsl_dataset_t *ds = arg1; |
5367 | 1299 objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset; |
1300 uint64_t count; | |
1301 int err; | |
1731
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1302 |
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1303 /* |
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1304 * Can't delete a head dataset if there are snapshots of it. |
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1305 * (Except if the only snapshots are from the branch we cloned |
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1306 * from.) |
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1307 */ |
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1308 if (ds->ds_prev != NULL && |
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1309 ds->ds_prev->ds_phys->ds_next_snap_obj == ds->ds_object) |
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1310 return (EINVAL); |
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1311 |
5367 | 1312 /* |
1313 * This is really a dsl_dir thing, but check it here so that | |
1314 * we'll be less likely to leave this dataset inconsistent & | |
1315 * nearly destroyed. | |
1316 */ | |
1317 err = zap_count(mos, ds->ds_dir->dd_phys->dd_child_dir_zapobj, &count); | |
1318 if (err) | |
1319 return (err); | |
1320 if (count != 0) | |
1321 return (EEXIST); | |
1322 | |
1731
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1323 return (0); |
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1324 } |
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1544
diff
changeset
|
1325 |
2199 | 1326 /* ARGSUSED */ |
1327 static void | |
4543 | 1328 dsl_dataset_destroy_begin_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
789 | 1329 { |
2199 | 1330 dsl_dataset_t *ds = arg1; |
4543 | 1331 dsl_pool_t *dp = ds->ds_dir->dd_pool; |
789 | 1332 |
2199 | 1333 /* Mark it as inconsistent on-disk, in case we crash */ |
1334 dmu_buf_will_dirty(ds->ds_dbuf, tx); | |
1335 ds->ds_phys->ds_flags |= DS_FLAG_INCONSISTENT; | |
4543 | 1336 |
1337 spa_history_internal_log(LOG_DS_DESTROY_BEGIN, dp->dp_spa, tx, | |
1338 cr, "dataset = %llu", ds->ds_object); | |
2199 | 1339 } |
789 | 1340 |
2199 | 1341 /* ARGSUSED */ |
5367 | 1342 int |
2199 | 1343 dsl_dataset_destroy_check(void *arg1, void *arg2, dmu_tx_t *tx) |
1344 { | |
1345 dsl_dataset_t *ds = arg1; | |
789 | 1346 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1347 /* we have an owner hold, so noone else can destroy us */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1348 ASSERT(!DSL_DATASET_IS_DESTROYED(ds)); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1349 |
789 | 1350 /* Can't delete a branch point. */ |
2199 | 1351 if (ds->ds_phys->ds_num_children > 1) |
1352 return (EEXIST); | |
789 | 1353 |
1354 /* | |
1355 * Can't delete a head dataset if there are snapshots of it. | |
1356 * (Except if the only snapshots are from the branch we cloned | |
1357 * from.) | |
1358 */ | |
1359 if (ds->ds_prev != NULL && | |
2199 | 1360 ds->ds_prev->ds_phys->ds_next_snap_obj == ds->ds_object) |
789 | 1361 return (EINVAL); |
1362 | |
1363 /* | |
1364 * If we made changes this txg, traverse_dsl_dataset won't find | |
1365 * them. Try again. | |
1366 */ | |
2199 | 1367 if (ds->ds_phys->ds_bp.blk_birth >= tx->tx_txg) |
789 | 1368 return (EAGAIN); |
2199 | 1369 |
1370 /* XXX we should do some i/o error checking... */ | |
1371 return (0); | |
1372 } | |
1373 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1374 struct refsarg { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1375 kmutex_t lock; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1376 boolean_t gone; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1377 kcondvar_t cv; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1378 }; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1379 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1380 /* ARGSUSED */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1381 static void |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1382 dsl_dataset_refs_gone(dmu_buf_t *db, void *argv) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1383 { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1384 struct refsarg *arg = argv; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1385 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1386 mutex_enter(&arg->lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1387 arg->gone = TRUE; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1388 cv_signal(&arg->cv); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1389 mutex_exit(&arg->lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1390 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1391 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1392 static void |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1393 dsl_dataset_drain_refs(dsl_dataset_t *ds, void *tag) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1394 { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1395 struct refsarg arg; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1396 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1397 mutex_init(&arg.lock, NULL, MUTEX_DEFAULT, NULL); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1398 cv_init(&arg.cv, NULL, CV_DEFAULT, NULL); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1399 arg.gone = FALSE; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1400 (void) dmu_buf_update_user(ds->ds_dbuf, ds, &arg, &ds->ds_phys, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1401 dsl_dataset_refs_gone); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1402 dmu_buf_rele(ds->ds_dbuf, tag); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1403 mutex_enter(&arg.lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1404 while (!arg.gone) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1405 cv_wait(&arg.cv, &arg.lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1406 ASSERT(arg.gone); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1407 mutex_exit(&arg.lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1408 ds->ds_dbuf = NULL; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1409 ds->ds_phys = NULL; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1410 mutex_destroy(&arg.lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1411 cv_destroy(&arg.cv); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1412 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1413 |
5367 | 1414 void |
4543 | 1415 dsl_dataset_destroy_sync(void *arg1, void *tag, cred_t *cr, dmu_tx_t *tx) |
2199 | 1416 { |
1417 dsl_dataset_t *ds = arg1; | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1418 int64_t used = 0, compressed = 0, uncompressed = 0; |
2199 | 1419 zio_t *zio; |
1420 int err; | |
1421 int after_branch_point = FALSE; | |
1422 dsl_pool_t *dp = ds->ds_dir->dd_pool; | |
1423 objset_t *mos = dp->dp_meta_objset; | |
1424 dsl_dataset_t *ds_prev = NULL; | |
1425 uint64_t obj; | |
1426 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1427 ASSERT(ds->ds_owner); |
2199 | 1428 ASSERT3U(ds->ds_phys->ds_num_children, <=, 1); |
1429 ASSERT(ds->ds_prev == NULL || | |
1430 ds->ds_prev->ds_phys->ds_next_snap_obj != ds->ds_object); | |
1431 ASSERT3U(ds->ds_phys->ds_bp.blk_birth, <=, tx->tx_txg); | |
1432 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1433 /* signal any waiters that this dataset is going away */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1434 mutex_enter(&ds->ds_lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1435 ds->ds_owner = dsl_reaper; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1436 cv_broadcast(&ds->ds_exclusive_cv); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1437 mutex_exit(&ds->ds_lock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1438 |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1439 /* Remove our reservation */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1440 if (ds->ds_reserved != 0) { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1441 uint64_t val = 0; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1442 dsl_dataset_set_reservation_sync(ds, &val, cr, tx); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1443 ASSERT3U(ds->ds_reserved, ==, 0); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1444 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1445 |
2199 | 1446 ASSERT(RW_WRITE_HELD(&dp->dp_config_rwlock)); |
1447 | |
1448 obj = ds->ds_object; | |
789 | 1449 |
1450 if (ds->ds_phys->ds_prev_snap_obj != 0) { | |
1451 if (ds->ds_prev) { | |
1452 ds_prev = ds->ds_prev; | |
1453 } else { | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1454 VERIFY(0 == dsl_dataset_hold_obj(dp, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1455 ds->ds_phys->ds_prev_snap_obj, FTAG, &ds_prev)); |
789 | 1456 } |
1457 after_branch_point = | |
1458 (ds_prev->ds_phys->ds_next_snap_obj != obj); | |
1459 | |
1460 dmu_buf_will_dirty(ds_prev->ds_dbuf, tx); | |
1461 if (after_branch_point && | |
1462 ds->ds_phys->ds_next_snap_obj == 0) { | |
1463 /* This clone is toast. */ | |
1464 ASSERT(ds_prev->ds_phys->ds_num_children > 1); | |
1465 ds_prev->ds_phys->ds_num_children--; | |
1466 } else if (!after_branch_point) { | |
1467 ds_prev->ds_phys->ds_next_snap_obj = | |
1468 ds->ds_phys->ds_next_snap_obj; | |
1469 } | |
1470 } | |
1471 | |
1472 zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED); | |
1473 | |
1474 if (ds->ds_phys->ds_next_snap_obj != 0) { | |
2199 | 1475 blkptr_t bp; |
789 | 1476 dsl_dataset_t *ds_next; |
1477 uint64_t itor = 0; | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1478 uint64_t old_unique; |
789 | 1479 |
1480 spa_scrub_restart(dp->dp_spa, tx->tx_txg); | |
1481 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1482 VERIFY(0 == dsl_dataset_hold_obj(dp, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1483 ds->ds_phys->ds_next_snap_obj, FTAG, &ds_next)); |
789 | 1484 ASSERT3U(ds_next->ds_phys->ds_prev_snap_obj, ==, obj); |
1485 | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1486 old_unique = dsl_dataset_unique(ds_next); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1487 |
789 | 1488 dmu_buf_will_dirty(ds_next->ds_dbuf, tx); |
1489 ds_next->ds_phys->ds_prev_snap_obj = | |
1490 ds->ds_phys->ds_prev_snap_obj; | |
1491 ds_next->ds_phys->ds_prev_snap_txg = | |
1492 ds->ds_phys->ds_prev_snap_txg; | |
1493 ASSERT3U(ds->ds_phys->ds_prev_snap_txg, ==, | |
1494 ds_prev ? ds_prev->ds_phys->ds_creation_txg : 0); | |
1495 | |
1496 /* | |
1497 * Transfer to our deadlist (which will become next's | |
1498 * new deadlist) any entries from next's current | |
1499 * deadlist which were born before prev, and free the | |
1500 * other entries. | |
1501 * | |
1502 * XXX we're doing this long task with the config lock held | |
1503 */ | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1504 while (bplist_iterate(&ds_next->ds_deadlist, &itor, &bp) == 0) { |
789 | 1505 if (bp.blk_birth <= ds->ds_phys->ds_prev_snap_txg) { |
1544 | 1506 VERIFY(0 == bplist_enqueue(&ds->ds_deadlist, |
1507 &bp, tx)); | |
789 | 1508 if (ds_prev && !after_branch_point && |
1509 bp.blk_birth > | |
1510 ds_prev->ds_phys->ds_prev_snap_txg) { | |
1511 ds_prev->ds_phys->ds_unique_bytes += | |
2082 | 1512 bp_get_dasize(dp->dp_spa, &bp); |
789 | 1513 } |
1514 } else { | |
2082 | 1515 used += bp_get_dasize(dp->dp_spa, &bp); |
789 | 1516 compressed += BP_GET_PSIZE(&bp); |
1517 uncompressed += BP_GET_UCSIZE(&bp); | |
1518 /* XXX check return value? */ | |
1519 (void) arc_free(zio, dp->dp_spa, tx->tx_txg, | |
1520 &bp, NULL, NULL, ARC_NOWAIT); | |
1521 } | |
1522 } | |
1523 | |
1524 /* free next's deadlist */ | |
1525 bplist_close(&ds_next->ds_deadlist); | |
1526 bplist_destroy(mos, ds_next->ds_phys->ds_deadlist_obj, tx); | |
1527 | |
1528 /* set next's deadlist to our deadlist */ | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1529 bplist_close(&ds->ds_deadlist); |
789 | 1530 ds_next->ds_phys->ds_deadlist_obj = |
1531 ds->ds_phys->ds_deadlist_obj; | |
1544 | 1532 VERIFY(0 == bplist_open(&ds_next->ds_deadlist, mos, |
1533 ds_next->ds_phys->ds_deadlist_obj)); | |
789 | 1534 ds->ds_phys->ds_deadlist_obj = 0; |
1535 | |
1536 if (ds_next->ds_phys->ds_next_snap_obj != 0) { | |
1537 /* | |
1538 * Update next's unique to include blocks which | |
1539 * were previously shared by only this snapshot | |
1540 * and it. Those blocks will be born after the | |
1541 * prev snap and before this snap, and will have | |
1542 * died after the next snap and before the one | |
1543 * after that (ie. be on the snap after next's | |
1544 * deadlist). | |
1545 * | |
1546 * XXX we're doing this long task with the | |
1547 * config lock held | |
1548 */ | |
1549 dsl_dataset_t *ds_after_next; | |
1550 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1551 VERIFY(0 == dsl_dataset_hold_obj(dp, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1552 ds_next->ds_phys->ds_next_snap_obj, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1553 FTAG, &ds_after_next)); |
789 | 1554 itor = 0; |
1555 while (bplist_iterate(&ds_after_next->ds_deadlist, | |
1556 &itor, &bp) == 0) { | |
1557 if (bp.blk_birth > | |
1558 ds->ds_phys->ds_prev_snap_txg && | |
1559 bp.blk_birth <= | |
1560 ds->ds_phys->ds_creation_txg) { | |
1561 ds_next->ds_phys->ds_unique_bytes += | |
2082 | 1562 bp_get_dasize(dp->dp_spa, &bp); |
789 | 1563 } |
1564 } | |
1565 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1566 dsl_dataset_rele(ds_after_next, FTAG); |
789 | 1567 ASSERT3P(ds_next->ds_prev, ==, NULL); |
1568 } else { | |
1569 ASSERT3P(ds_next->ds_prev, ==, ds); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1570 dsl_dataset_drop_ref(ds_next->ds_prev, ds_next); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1571 ds_next->ds_prev = NULL; |
789 | 1572 if (ds_prev) { |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1573 VERIFY(0 == dsl_dataset_get_ref(dp, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1574 ds->ds_phys->ds_prev_snap_obj, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1575 ds_next, &ds_next->ds_prev)); |
789 | 1576 } |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1577 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1578 dsl_dataset_recalc_head_uniq(ds_next); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1579 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1580 /* |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1581 * Reduce the amount of our unconsmed refreservation |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1582 * being charged to our parent by the amount of |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1583 * new unique data we have gained. |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1584 */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1585 if (old_unique < ds_next->ds_reserved) { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1586 int64_t mrsdelta; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1587 uint64_t new_unique = |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1588 ds_next->ds_phys->ds_unique_bytes; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1589 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1590 ASSERT(old_unique <= new_unique); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1591 mrsdelta = MIN(new_unique - old_unique, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1592 ds_next->ds_reserved - old_unique); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1593 dsl_dir_diduse_space(ds->ds_dir, -mrsdelta, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1594 0, 0, tx); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1595 } |
789 | 1596 } |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1597 dsl_dataset_rele(ds_next, FTAG); |
789 | 1598 |
1599 /* | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1600 * NB: unique_bytes might not be accurate for the head objset. |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1601 * Before SPA_VERSION 9, we didn't update its value when we |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1602 * deleted the most recent snapshot. |
789 | 1603 */ |
1604 ASSERT3U(used, ==, ds->ds_phys->ds_unique_bytes); | |
1605 } else { | |
1606 /* | |
1607 * There's no next snapshot, so this is a head dataset. | |
1608 * Destroy the deadlist. Unless it's a clone, the | |
1609 * deadlist should be empty. (If it's a clone, it's | |
1610 * safe to ignore the deadlist contents.) | |
1611 */ | |
1612 struct killarg ka; | |
1613 | |
1614 ASSERT(after_branch_point || bplist_empty(&ds->ds_deadlist)); | |
1615 bplist_close(&ds->ds_deadlist); | |
1616 bplist_destroy(mos, ds->ds_phys->ds_deadlist_obj, tx); | |
1617 ds->ds_phys->ds_deadlist_obj = 0; | |
1618 | |
1619 /* | |
1620 * Free everything that we point to (that's born after | |
1621 * the previous snapshot, if we are a clone) | |
1622 * | |
1623 * XXX we're doing this long task with the config lock held | |
1624 */ | |
1625 ka.usedp = &used; | |
1626 ka.compressedp = &compressed; | |
1627 ka.uncompressedp = &uncompressed; | |
1628 ka.zio = zio; | |
1629 ka.tx = tx; | |
1630 err = traverse_dsl_dataset(ds, ds->ds_phys->ds_prev_snap_txg, | |
1631 ADVANCE_POST, kill_blkptr, &ka); | |
1632 ASSERT3U(err, ==, 0); | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1633 ASSERT(spa_version(dp->dp_spa) < |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1634 SPA_VERSION_UNIQUE_ACCURATE || |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1635 used == ds->ds_phys->ds_unique_bytes); |
789 | 1636 } |
1637 | |
1638 err = zio_wait(zio); | |
1639 ASSERT3U(err, ==, 0); | |
1640 | |
2199 | 1641 dsl_dir_diduse_space(ds->ds_dir, -used, -compressed, -uncompressed, tx); |
789 | 1642 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1643 if (ds->ds_dir->dd_phys->dd_head_dataset_obj == ds->ds_object) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1644 /* Erase the link in the dir */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1645 dmu_buf_will_dirty(ds->ds_dir->dd_dbuf, tx); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1646 ds->ds_dir->dd_phys->dd_head_dataset_obj = 0; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1647 ASSERT(ds->ds_phys->ds_snapnames_zapobj != 0); |
789 | 1648 err = zap_destroy(mos, ds->ds_phys->ds_snapnames_zapobj, tx); |
1649 ASSERT(err == 0); | |
1650 } else { | |
1651 /* remove from snapshot namespace */ | |
1652 dsl_dataset_t *ds_head; | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1653 ASSERT(ds->ds_phys->ds_snapnames_zapobj == 0); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1654 VERIFY(0 == dsl_dataset_hold_obj(dp, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1655 ds->ds_dir->dd_phys->dd_head_dataset_obj, FTAG, &ds_head)); |
2207
47efcb3433a7
6439370 assertion failures possible in dsl_dataset_destroy_sync()
ahrens
parents:
2199
diff
changeset
|
1656 VERIFY(0 == dsl_dataset_get_snapname(ds)); |
789 | 1657 #ifdef ZFS_DEBUG |
1658 { | |
1659 uint64_t val; | |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
1660 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1661 err = dsl_dataset_snap_lookup(ds_head, |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6047
diff
changeset
|
1662 ds->ds_snapname, &val); |
789 | 1663 ASSERT3U(err, ==, 0); |
1664 ASSERT3U(val, ==, obj); | |
1665 } | |
1666 #endif | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1667 err = dsl_dataset_snap_remove(ds_head, ds->ds_snapname, tx); |
789 | 1668 ASSERT(err == 0); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1669 dsl_dataset_rele(ds_head, FTAG); |
789 | 1670 } |
1671 | |
1672 if (ds_prev && ds->ds_prev != ds_prev) | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1673 dsl_dataset_rele(ds_prev, FTAG); |
789 | 1674 |
5094 | 1675 spa_prop_clear_bootfs(dp->dp_spa, ds->ds_object, tx); |
4543 | 1676 spa_history_internal_log(LOG_DS_DESTROY, dp->dp_spa, tx, |
1677 cr, "dataset = %llu", ds->ds_object); | |
1678 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1679 dsl_dir_close(ds->ds_dir, ds); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1680 ds->ds_dir = NULL; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1681 dsl_dataset_drain_refs(ds, tag); |
2199 | 1682 VERIFY(0 == dmu_object_free(mos, obj, tx)); |
1683 } | |
1684 | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1685 static int |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1686 dsl_dataset_snapshot_reserve_space(dsl_dataset_t *ds, dmu_tx_t *tx) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1687 { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1688 uint64_t asize; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1689 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1690 if (!dmu_tx_is_syncing(tx)) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1691 return (0); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1692 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1693 /* |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1694 * If there's an fs-only reservation, any blocks that might become |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1695 * owned by the snapshot dataset must be accommodated by space |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1696 * outside of the reservation. |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1697 */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1698 asize = MIN(dsl_dataset_unique(ds), ds->ds_reserved); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1699 if (asize > dsl_dir_space_available(ds->ds_dir, NULL, 0, FALSE)) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1700 return (ENOSPC); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1701 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1702 /* |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1703 * Propogate any reserved space for this snapshot to other |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1704 * snapshot checks in this sync group. |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1705 */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1706 if (asize > 0) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1707 dsl_dir_willuse_space(ds->ds_dir, asize, tx); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1708 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1709 return (0); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1710 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1711 |
2199 | 1712 /* ARGSUSED */ |
1713 int | |
1714 dsl_dataset_snapshot_check(void *arg1, void *arg2, dmu_tx_t *tx) | |
1715 { | |
5367 | 1716 dsl_dataset_t *ds = arg1; |
2199 | 1717 const char *snapname = arg2; |
1718 int err; | |
1719 uint64_t value; | |
789 | 1720 |
1721 /* | |
2199 | 1722 * We don't allow multiple snapshots of the same txg. If there |
1723 * is already one, try again. | |
1724 */ | |
1725 if (ds->ds_phys->ds_prev_snap_txg >= tx->tx_txg) | |
1726 return (EAGAIN); | |
1727 | |
1728 /* | |
1729 * Check for conflicting name snapshot name. | |
789 | 1730 */ |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1731 err = dsl_dataset_snap_lookup(ds, snapname, &value); |
2199 | 1732 if (err == 0) |
1733 return (EEXIST); | |
1734 if (err != ENOENT) | |
1735 return (err); | |
789 | 1736 |
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
1737 /* |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
1738 * Check that the dataset's name is not too long. Name consists |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
1739 * of the dataset's length + 1 for the @-sign + snapshot name's length |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
1740 */ |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
1741 if (dsl_dataset_namelen(ds) + 1 + strlen(snapname) >= MAXNAMELEN) |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
1742 return (ENAMETOOLONG); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
3912
diff
changeset
|
1743 |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1744 err = dsl_dataset_snapshot_reserve_space(ds, tx); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1745 if (err) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1746 return (err); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1747 |
2199 | 1748 ds->ds_trysnap_txg = tx->tx_txg; |
789 | 1749 return (0); |
1750 } | |
1751 | |
2199 | 1752 void |
4543 | 1753 dsl_dataset_snapshot_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
789 | 1754 { |
5367 | 1755 dsl_dataset_t *ds = arg1; |
2199 | 1756 const char *snapname = arg2; |
1757 dsl_pool_t *dp = ds->ds_dir->dd_pool; | |
789 | 1758 dmu_buf_t *dbuf; |
1759 dsl_dataset_phys_t *dsphys; | |
2199 | 1760 uint64_t dsobj; |
789 | 1761 objset_t *mos = dp->dp_meta_objset; |
1762 int err; | |
1763 | |
1764 spa_scrub_restart(dp->dp_spa, tx->tx_txg); | |
2199 | 1765 ASSERT(RW_WRITE_HELD(&dp->dp_config_rwlock)); |
789 | 1766 |
928
36d72fe4da29
6349314 dmu_object_type names incorrect for DSL Directories and DSL Datasets
tabriz
parents:
885
diff
changeset
|
1767 dsobj = dmu_object_alloc(mos, DMU_OT_DSL_DATASET, 0, |
36d72fe4da29
6349314 dmu_object_type names incorrect for DSL Directories and DSL Datasets
tabriz
parents:
885
diff
changeset
|
1768 DMU_OT_DSL_DATASET, sizeof (dsl_dataset_phys_t), tx); |
1544 | 1769 VERIFY(0 == dmu_bonus_hold(mos, dsobj, FTAG, &dbuf)); |
789 | 1770 dmu_buf_will_dirty(dbuf, tx); |
1771 dsphys = dbuf->db_data; | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1772 bzero(dsphys, sizeof (dsl_dataset_phys_t)); |
2199 | 1773 dsphys->ds_dir_obj = ds->ds_dir->dd_object; |
789 | 1774 dsphys->ds_fsid_guid = unique_create(); |
1775 (void) random_get_pseudo_bytes((void*)&dsphys->ds_guid, | |
1776 sizeof (dsphys->ds_guid)); | |
1777 dsphys->ds_prev_snap_obj = ds->ds_phys->ds_prev_snap_obj; | |
1778 dsphys->ds_prev_snap_txg = ds->ds_phys->ds_prev_snap_txg; | |
1779 dsphys->ds_next_snap_obj = ds->ds_object; | |
1780 dsphys->ds_num_children = 1; | |
1781 dsphys->ds_creation_time = gethrestime_sec(); | |
1782 dsphys->ds_creation_txg = tx->tx_txg; | |
1783 dsphys->ds_deadlist_obj = ds->ds_phys->ds_deadlist_obj; | |
1784 dsphys->ds_used_bytes = ds->ds_phys->ds_used_bytes; | |
1785 dsphys->ds_compressed_bytes = ds->ds_phys->ds_compressed_bytes; | |
1786 dsphys->ds_uncompressed_bytes = ds->ds_phys->ds_uncompressed_bytes; | |
2082 | 1787 dsphys->ds_flags = ds->ds_phys->ds_flags; |
789 | 1788 dsphys->ds_bp = ds->ds_phys->ds_bp; |
1544 | 1789 dmu_buf_rele(dbuf, FTAG); |
789 | 1790 |
2199 | 1791 ASSERT3U(ds->ds_prev != 0, ==, ds->ds_phys->ds_prev_snap_obj != 0); |
1792 if (ds->ds_prev) { | |
1793 ASSERT(ds->ds_prev->ds_phys->ds_next_snap_obj == | |
789 | 1794 ds->ds_object || |
2199 | 1795 ds->ds_prev->ds_phys->ds_num_children > 1); |
1796 if (ds->ds_prev->ds_phys->ds_next_snap_obj == ds->ds_object) { | |
1797 dmu_buf_will_dirty(ds->ds_prev->ds_dbuf, tx); | |
789 | 1798 ASSERT3U(ds->ds_phys->ds_prev_snap_txg, ==, |
2199 | 1799 ds->ds_prev->ds_phys->ds_creation_txg); |
1800 ds->ds_prev->ds_phys->ds_next_snap_obj = dsobj; | |
789 | 1801 } |
1802 } | |
1803 | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1804 /* |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1805 * If we have a reference-reservation on this dataset, we will |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1806 * need to increase the amount of refreservation being charged |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1807 * since our unique space is going to zero. |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1808 */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1809 if (ds->ds_reserved) { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1810 int64_t add = MIN(dsl_dataset_unique(ds), ds->ds_reserved); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1811 dsl_dir_diduse_space(ds->ds_dir, add, 0, 0, tx); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1812 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1813 |
789 | 1814 bplist_close(&ds->ds_deadlist); |
1815 dmu_buf_will_dirty(ds->ds_dbuf, tx); | |
5712
81f1af42bafc
6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents:
5569
diff
changeset
|
1816 ASSERT3U(ds->ds_phys->ds_prev_snap_txg, <, tx->tx_txg); |
789 | 1817 ds->ds_phys->ds_prev_snap_obj = dsobj; |
5712
81f1af42bafc
6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents:
5569
diff
changeset
|
1818 ds->ds_phys->ds_prev_snap_txg = tx->tx_txg; |
789 | 1819 ds->ds_phys->ds_unique_bytes = 0; |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1820 if (spa_version(dp->dp_spa) >= SPA_VERSION_UNIQUE_ACCURATE) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1821 ds->ds_phys->ds_flags |= DS_FLAG_UNIQUE_ACCURATE; |
789 | 1822 ds->ds_phys->ds_deadlist_obj = |
1823 bplist_create(mos, DSL_DEADLIST_BLOCKSIZE, tx); | |
1544 | 1824 VERIFY(0 == bplist_open(&ds->ds_deadlist, mos, |
1825 ds->ds_phys->ds_deadlist_obj)); | |
789 | 1826 |
1827 dprintf("snap '%s' -> obj %llu\n", snapname, dsobj); | |
1828 err = zap_add(mos, ds->ds_phys->ds_snapnames_zapobj, | |
1829 snapname, 8, 1, &dsobj, tx); | |
1830 ASSERT(err == 0); | |
1831 | |
1832 if (ds->ds_prev) | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1833 dsl_dataset_drop_ref(ds->ds_prev, ds); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1834 VERIFY(0 == dsl_dataset_get_ref(dp, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1835 ds->ds_phys->ds_prev_snap_obj, ds, &ds->ds_prev)); |
4543 | 1836 |
1837 spa_history_internal_log(LOG_DS_SNAPSHOT, dp->dp_spa, tx, cr, | |
4603
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
1838 "dataset = %llu", dsobj); |
789 | 1839 } |
1840 | |
1841 void | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
1842 dsl_dataset_sync(dsl_dataset_t *ds, zio_t *zio, dmu_tx_t *tx) |
789 | 1843 { |
1844 ASSERT(dmu_tx_is_syncing(tx)); | |
1845 ASSERT(ds->ds_user_ptr != NULL); | |
1846 ASSERT(ds->ds_phys->ds_next_snap_obj == 0); | |
1847 | |
4787 | 1848 /* |
1849 * in case we had to change ds_fsid_guid when we opened it, | |
1850 * sync it out now. | |
1851 */ | |
1852 dmu_buf_will_dirty(ds->ds_dbuf, tx); | |
1853 ds->ds_phys->ds_fsid_guid = ds->ds_fsid_guid; | |
1854 | |
789 | 1855 dsl_dir_dirty(ds->ds_dir, tx); |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
1856 dmu_objset_sync(ds->ds_user_ptr, zio, tx); |
789 | 1857 } |
1858 | |
1859 void | |
2885 | 1860 dsl_dataset_stats(dsl_dataset_t *ds, nvlist_t *nv) |
789 | 1861 { |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1862 uint64_t refd, avail, uobjs, aobjs; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1863 |
2885 | 1864 dsl_dir_stats(ds->ds_dir, nv); |
789 | 1865 |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1866 dsl_dataset_space(ds, &refd, &avail, &uobjs, &aobjs); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1867 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_AVAILABLE, avail); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1868 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFERENCED, refd); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1869 |
2885 | 1870 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_CREATION, |
1871 ds->ds_phys->ds_creation_time); | |
1872 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_CREATETXG, | |
1873 ds->ds_phys->ds_creation_txg); | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1874 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFQUOTA, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1875 ds->ds_quota); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1876 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFRESERVATION, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1877 ds->ds_reserved); |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6502
diff
changeset
|
1878 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_GUID, |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6502
diff
changeset
|
1879 ds->ds_phys->ds_guid); |
789 | 1880 |
1881 if (ds->ds_phys->ds_next_snap_obj) { | |
1882 /* | |
1883 * This is a snapshot; override the dd's space used with | |
2885 | 1884 * our unique space and compression ratio. |
789 | 1885 */ |
2885 | 1886 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USED, |
1887 ds->ds_phys->ds_unique_bytes); | |
1888 dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_COMPRESSRATIO, | |
1889 ds->ds_phys->ds_compressed_bytes == 0 ? 100 : | |
1890 (ds->ds_phys->ds_uncompressed_bytes * 100 / | |
1891 ds->ds_phys->ds_compressed_bytes)); | |
789 | 1892 } |
1893 } | |
1894 | |
2885 | 1895 void |
1896 dsl_dataset_fast_stat(dsl_dataset_t *ds, dmu_objset_stats_t *stat) | |
789 | 1897 { |
2885 | 1898 stat->dds_creation_txg = ds->ds_phys->ds_creation_txg; |
1899 stat->dds_inconsistent = ds->ds_phys->ds_flags & DS_FLAG_INCONSISTENT; | |
5367 | 1900 stat->dds_guid = ds->ds_phys->ds_guid; |
2885 | 1901 if (ds->ds_phys->ds_next_snap_obj) { |
1902 stat->dds_is_snapshot = B_TRUE; | |
1903 stat->dds_num_clones = ds->ds_phys->ds_num_children - 1; | |
1904 } | |
1905 | |
1906 /* clone origin is really a dsl_dir thing... */ | |
5446 | 1907 rw_enter(&ds->ds_dir->dd_pool->dp_config_rwlock, RW_READER); |
5367 | 1908 if (ds->ds_dir->dd_phys->dd_origin_obj) { |
2885 | 1909 dsl_dataset_t *ods; |
1910 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1911 VERIFY(0 == dsl_dataset_get_ref(ds->ds_dir->dd_pool, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1912 ds->ds_dir->dd_phys->dd_origin_obj, FTAG, &ods)); |
5367 | 1913 dsl_dataset_name(ods, stat->dds_origin); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1914 dsl_dataset_drop_ref(ods, FTAG); |
2885 | 1915 } |
5446 | 1916 rw_exit(&ds->ds_dir->dd_pool->dp_config_rwlock); |
2885 | 1917 } |
1918 | |
1919 uint64_t | |
1920 dsl_dataset_fsid_guid(dsl_dataset_t *ds) | |
1921 { | |
4787 | 1922 return (ds->ds_fsid_guid); |
2885 | 1923 } |
1924 | |
1925 void | |
1926 dsl_dataset_space(dsl_dataset_t *ds, | |
1927 uint64_t *refdbytesp, uint64_t *availbytesp, | |
1928 uint64_t *usedobjsp, uint64_t *availobjsp) | |
1929 { | |
1930 *refdbytesp = ds->ds_phys->ds_used_bytes; | |
1931 *availbytesp = dsl_dir_space_available(ds->ds_dir, NULL, 0, TRUE); | |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1932 if (ds->ds_reserved > ds->ds_phys->ds_unique_bytes) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1933 *availbytesp += ds->ds_reserved - ds->ds_phys->ds_unique_bytes; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1934 if (ds->ds_quota != 0) { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1935 /* |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1936 * Adjust available bytes according to refquota |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1937 */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1938 if (*refdbytesp < ds->ds_quota) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1939 *availbytesp = MIN(*availbytesp, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1940 ds->ds_quota - *refdbytesp); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1941 else |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1942 *availbytesp = 0; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1943 } |
2885 | 1944 *usedobjsp = ds->ds_phys->ds_bp.blk_fill; |
1945 *availobjsp = DN_MAX_OBJECT - *usedobjsp; | |
789 | 1946 } |
1947 | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1948 boolean_t |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1949 dsl_dataset_modified_since_lastsnap(dsl_dataset_t *ds) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1950 { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1951 dsl_pool_t *dp = ds->ds_dir->dd_pool; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1952 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1953 ASSERT(RW_LOCK_HELD(&dp->dp_config_rwlock) || |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1954 dsl_pool_sync_context(dp)); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1955 if (ds->ds_prev == NULL) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1956 return (B_FALSE); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1957 if (ds->ds_phys->ds_bp.blk_birth > |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1958 ds->ds_prev->ds_phys->ds_creation_txg) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1959 return (B_TRUE); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1960 return (B_FALSE); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1961 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
1962 |
2199 | 1963 /* ARGSUSED */ |
789 | 1964 static int |
2199 | 1965 dsl_dataset_snapshot_rename_check(void *arg1, void *arg2, dmu_tx_t *tx) |
789 | 1966 { |
2199 | 1967 dsl_dataset_t *ds = arg1; |
1968 char *newsnapname = arg2; | |
1969 dsl_dir_t *dd = ds->ds_dir; | |
1970 dsl_dataset_t *hds; | |
1971 uint64_t val; | |
789 | 1972 int err; |
1973 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1974 err = dsl_dataset_hold_obj(dd->dd_pool, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1975 dd->dd_phys->dd_head_dataset_obj, FTAG, &hds); |
789 | 1976 if (err) |
1977 return (err); | |
1978 | |
2199 | 1979 /* new name better not be in use */ |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1980 err = dsl_dataset_snap_lookup(hds, newsnapname, &val); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
1981 dsl_dataset_rele(hds, FTAG); |
789 | 1982 |
2199 | 1983 if (err == 0) |
1984 err = EEXIST; | |
1985 else if (err == ENOENT) | |
1986 err = 0; | |
4007 | 1987 |
1988 /* dataset name + 1 for the "@" + the new snapshot name must fit */ | |
1989 if (dsl_dir_namelen(ds->ds_dir) + 1 + strlen(newsnapname) >= MAXNAMELEN) | |
1990 err = ENAMETOOLONG; | |
1991 | |
2199 | 1992 return (err); |
1993 } | |
789 | 1994 |
2199 | 1995 static void |
4543 | 1996 dsl_dataset_snapshot_rename_sync(void *arg1, void *arg2, |
1997 cred_t *cr, dmu_tx_t *tx) | |
2199 | 1998 { |
1999 dsl_dataset_t *ds = arg1; | |
4543 | 2000 const char *newsnapname = arg2; |
2199 | 2001 dsl_dir_t *dd = ds->ds_dir; |
2002 objset_t *mos = dd->dd_pool->dp_meta_objset; | |
2003 dsl_dataset_t *hds; | |
2004 int err; | |
789 | 2005 |
2199 | 2006 ASSERT(ds->ds_phys->ds_next_snap_obj != 0); |
789 | 2007 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2008 VERIFY(0 == dsl_dataset_hold_obj(dd->dd_pool, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2009 dd->dd_phys->dd_head_dataset_obj, FTAG, &hds)); |
789 | 2010 |
2199 | 2011 VERIFY(0 == dsl_dataset_get_snapname(ds)); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2012 err = dsl_dataset_snap_remove(hds, ds->ds_snapname, tx); |
789 | 2013 ASSERT3U(err, ==, 0); |
2199 | 2014 mutex_enter(&ds->ds_lock); |
2015 (void) strcpy(ds->ds_snapname, newsnapname); | |
2016 mutex_exit(&ds->ds_lock); | |
2017 err = zap_add(mos, hds->ds_phys->ds_snapnames_zapobj, | |
2018 ds->ds_snapname, 8, 1, &ds->ds_object, tx); | |
789 | 2019 ASSERT3U(err, ==, 0); |
2020 | |
4543 | 2021 spa_history_internal_log(LOG_DS_RENAME, dd->dd_pool->dp_spa, tx, |
2022 cr, "dataset = %llu", ds->ds_object); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2023 dsl_dataset_rele(hds, FTAG); |
789 | 2024 } |
2025 | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2026 struct renamesnaparg { |
4007 | 2027 dsl_sync_task_group_t *dstg; |
2028 char failed[MAXPATHLEN]; | |
2029 char *oldsnap; | |
2030 char *newsnap; | |
2031 }; | |
2032 | |
2033 static int | |
2034 dsl_snapshot_rename_one(char *name, void *arg) | |
2035 { | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2036 struct renamesnaparg *ra = arg; |
4007 | 2037 dsl_dataset_t *ds = NULL; |
2038 char *cp; | |
2039 int err; | |
2040 | |
2041 cp = name + strlen(name); | |
2042 *cp = '@'; | |
2043 (void) strcpy(cp + 1, ra->oldsnap); | |
4543 | 2044 |
2045 /* | |
2046 * For recursive snapshot renames the parent won't be changing | |
2047 * so we just pass name for both the to/from argument. | |
2048 */ | |
2049 if (err = zfs_secpolicy_rename_perms(name, name, CRED())) { | |
2050 (void) strcpy(ra->failed, name); | |
2051 return (err); | |
2052 } | |
2053 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2054 #ifdef _KERNEL |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2055 /* |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2056 * For all filesystems undergoing rename, we'll need to unmount it. |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2057 */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2058 (void) zfs_unmount_snap(name, NULL); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2059 #endif |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2060 err = dsl_dataset_hold(name, ra->dstg, &ds); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2061 *cp = '\0'; |
4007 | 2062 if (err == ENOENT) { |
2063 return (0); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2064 } else if (err) { |
4007 | 2065 (void) strcpy(ra->failed, name); |
2066 return (err); | |
2067 } | |
2068 | |
2069 dsl_sync_task_create(ra->dstg, dsl_dataset_snapshot_rename_check, | |
2070 dsl_dataset_snapshot_rename_sync, ds, ra->newsnap, 0); | |
2071 | |
2072 return (0); | |
2073 } | |
2074 | |
2075 static int | |
2076 dsl_recursive_rename(char *oldname, const char *newname) | |
2077 { | |
2078 int err; | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2079 struct renamesnaparg *ra; |
4007 | 2080 dsl_sync_task_t *dst; |
2081 spa_t *spa; | |
2082 char *cp, *fsname = spa_strdup(oldname); | |
2083 int len = strlen(oldname); | |
2084 | |
2085 /* truncate the snapshot name to get the fsname */ | |
2086 cp = strchr(fsname, '@'); | |
2087 *cp = '\0'; | |
2088 | |
4603
c7840c367d00
6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents:
4577
diff
changeset
|
2089 err = spa_open(fsname, &spa, FTAG); |
4007 | 2090 if (err) { |
2091 kmem_free(fsname, len + 1); | |
2092 return (err); | |
2093 } | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2094 ra = kmem_alloc(sizeof (struct renamesnaparg), KM_SLEEP); |
4007 | 2095 ra->dstg = dsl_sync_task_group_create(spa_get_dsl(spa)); |
2096 | |
2097 ra->oldsnap = strchr(oldname, '@') + 1; | |
2098 ra->newsnap = strchr(newname, '@') + 1; | |
2099 *ra->failed = '\0'; | |
2100 | |
2101 err = dmu_objset_find(fsname, dsl_snapshot_rename_one, ra, | |
2102 DS_FIND_CHILDREN); | |
2103 kmem_free(fsname, len + 1); | |
2104 | |
2105 if (err == 0) { | |
2106 err = dsl_sync_task_group_wait(ra->dstg); | |
2107 } | |
2108 | |
2109 for (dst = list_head(&ra->dstg->dstg_tasks); dst; | |
2110 dst = list_next(&ra->dstg->dstg_tasks, dst)) { | |
2111 dsl_dataset_t *ds = dst->dst_arg1; | |
2112 if (dst->dst_err) { | |
2113 dsl_dir_name(ds->ds_dir, ra->failed); | |
4009
1a9b4fbc0d2a
6479884 want 'zfs rename -r' to recursively rename snapshots (fix lint)
mmusante
parents:
4007
diff
changeset
|
2114 (void) strcat(ra->failed, "@"); |
1a9b4fbc0d2a
6479884 want 'zfs rename -r' to recursively rename snapshots (fix lint)
mmusante
parents:
4007
diff
changeset
|
2115 (void) strcat(ra->failed, ra->newsnap); |
4007 | 2116 } |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2117 dsl_dataset_rele(ds, ra->dstg); |
4007 | 2118 } |
2119 | |
4543 | 2120 if (err) |
2121 (void) strcpy(oldname, ra->failed); | |
4007 | 2122 |
2123 dsl_sync_task_group_destroy(ra->dstg); | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2124 kmem_free(ra, sizeof (struct renamesnaparg)); |
4007 | 2125 spa_close(spa, FTAG); |
2126 return (err); | |
2127 } | |
2128 | |
4569
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2129 static int |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2130 dsl_valid_rename(char *oldname, void *arg) |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2131 { |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2132 int delta = *(int *)arg; |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2133 |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2134 if (strlen(oldname) + delta >= MAXNAMELEN) |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2135 return (ENAMETOOLONG); |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2136 |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2137 return (0); |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2138 } |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2139 |
789 | 2140 #pragma weak dmu_objset_rename = dsl_dataset_rename |
2141 int | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2142 dsl_dataset_rename(char *oldname, const char *newname, boolean_t recursive) |
789 | 2143 { |
2144 dsl_dir_t *dd; | |
2199 | 2145 dsl_dataset_t *ds; |
789 | 2146 const char *tail; |
2147 int err; | |
2148 | |
2199 | 2149 err = dsl_dir_open(oldname, FTAG, &dd, &tail); |
1544 | 2150 if (err) |
2151 return (err); | |
789 | 2152 if (tail == NULL) { |
4569
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2153 int delta = strlen(newname) - strlen(oldname); |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2154 |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2155 /* if we're growing, validate child size lengths */ |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2156 if (delta > 0) |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2157 err = dmu_objset_find(oldname, dsl_valid_rename, |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2158 &delta, DS_FIND_CHILDREN | DS_FIND_SNAPSHOTS); |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2159 |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2160 if (!err) |
e80d40447f27
6355623 zfs rename to a valid dataset name, but its snapshot name becomes too long, panics the system
mmusante
parents:
4543
diff
changeset
|
2161 err = dsl_dir_rename(dd, newname); |
789 | 2162 dsl_dir_close(dd, FTAG); |
2163 return (err); | |
2164 } | |
2165 if (tail[0] != '@') { | |
2166 /* the name ended in a nonexistant component */ | |
2167 dsl_dir_close(dd, FTAG); | |
2168 return (ENOENT); | |
2169 } | |
2170 | |
2199 | 2171 dsl_dir_close(dd, FTAG); |
2172 | |
2173 /* new name must be snapshot in same filesystem */ | |
2174 tail = strchr(newname, '@'); | |
2175 if (tail == NULL) | |
2176 return (EINVAL); | |
2177 tail++; | |
2178 if (strncmp(oldname, newname, tail - newname) != 0) | |
2179 return (EXDEV); | |
789 | 2180 |
4007 | 2181 if (recursive) { |
2182 err = dsl_recursive_rename(oldname, newname); | |
2183 } else { | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2184 err = dsl_dataset_hold(oldname, FTAG, &ds); |
4007 | 2185 if (err) |
2186 return (err); | |
2199 | 2187 |
4007 | 2188 err = dsl_sync_task_do(ds->ds_dir->dd_pool, |
2189 dsl_dataset_snapshot_rename_check, | |
2190 dsl_dataset_snapshot_rename_sync, ds, (char *)tail, 1); | |
2199 | 2191 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2192 dsl_dataset_rele(ds, FTAG); |
4007 | 2193 } |
2199 | 2194 |
789 | 2195 return (err); |
2196 } | |
2082 | 2197 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2198 struct promotedsarg { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2199 list_node_t link; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2200 dsl_dataset_t *ds; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2201 }; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2202 |
2199 | 2203 struct promotearg { |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2204 list_t snap_list; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2205 dsl_dataset_t *clone_origin, *old_head; |
2199 | 2206 uint64_t used, comp, uncomp, unique; |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2207 uint64_t newnext_obj; |
2199 | 2208 }; |
2209 | |
4543 | 2210 /* ARGSUSED */ |
2082 | 2211 static int |
2199 | 2212 dsl_dataset_promote_check(void *arg1, void *arg2, dmu_tx_t *tx) |
2082 | 2213 { |
2199 | 2214 dsl_dataset_t *hds = arg1; |
2215 struct promotearg *pa = arg2; | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2216 struct promotedsarg *snap = list_head(&pa->snap_list); |
2199 | 2217 dsl_pool_t *dp = hds->ds_dir->dd_pool; |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2218 dsl_dataset_t *origin_ds = snap->ds; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2219 dsl_dataset_t *newnext_ds; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2220 char *name; |
2199 | 2221 uint64_t itor = 0; |
2082 | 2222 blkptr_t bp; |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2223 int err; |
2199 | 2224 |
2082 | 2225 /* Check that it is a clone */ |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2226 if (hds->ds_dir->dd_phys->dd_origin_obj == 0) |
2082 | 2227 return (EINVAL); |
2228 | |
2199 | 2229 /* Since this is so expensive, don't do the preliminary check */ |
2230 if (!dmu_tx_is_syncing(tx)) | |
2231 return (0); | |
2232 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2233 if (hds->ds_phys->ds_flags & DS_FLAG_NOPROMOTE) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2234 return (EXDEV); |
2082 | 2235 |
5367 | 2236 /* find origin's new next ds */ |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2237 newnext_ds = hds; |
5367 | 2238 while (newnext_ds->ds_phys->ds_prev_snap_obj != origin_ds->ds_object) { |
2082 | 2239 dsl_dataset_t *prev; |
2240 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2241 err = dsl_dataset_hold_obj(dp, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2242 newnext_ds->ds_phys->ds_prev_snap_obj, FTAG, &prev); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2243 if (newnext_ds != hds) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2244 dsl_dataset_rele(newnext_ds, FTAG); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2245 if (err) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2246 return (err); |
2082 | 2247 newnext_ds = prev; |
2248 } | |
2199 | 2249 pa->newnext_obj = newnext_ds->ds_object; |
2082 | 2250 |
5367 | 2251 /* compute origin's new unique space */ |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2252 pa->unique = 0; |
2082 | 2253 while ((err = bplist_iterate(&newnext_ds->ds_deadlist, |
2254 &itor, &bp)) == 0) { | |
5367 | 2255 if (bp.blk_birth > origin_ds->ds_phys->ds_prev_snap_txg) |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2256 pa->unique += bp_get_dasize(dp->dp_spa, &bp); |
2082 | 2257 } |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2258 if (newnext_ds != hds) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2259 dsl_dataset_rele(newnext_ds, FTAG); |
2082 | 2260 if (err != ENOENT) |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2261 return (err); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2262 |
2082 | 2263 name = kmem_alloc(MAXPATHLEN, KM_SLEEP); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2264 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2265 /* |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2266 * Walk the snapshots that we are moving |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2267 * |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2268 * Compute space to transfer. Each snapshot gave birth to: |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2269 * (my used) - (prev's used) + (deadlist's used) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2270 * So a sequence would look like: |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2271 * uN - u(N-1) + dN + ... + u1 - u0 + d1 + u0 - 0 + d0 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2272 * Which simplifies to: |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2273 * uN + dN + ... + d1 + d0 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2274 * Note however, if we stop before we reach the ORIGIN we get: |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2275 * uN + dN + ... + dM - uM-1 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2276 */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2277 pa->used = origin_ds->ds_phys->ds_used_bytes; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2278 pa->comp = origin_ds->ds_phys->ds_compressed_bytes; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2279 pa->uncomp = origin_ds->ds_phys->ds_uncompressed_bytes; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2280 do { |
2082 | 2281 uint64_t val, dlused, dlcomp, dluncomp; |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2282 dsl_dataset_t *ds = snap->ds; |
2082 | 2283 |
2284 /* Check that the snapshot name does not conflict */ | |
2285 dsl_dataset_name(ds, name); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2286 err = dsl_dataset_snap_lookup(hds, ds->ds_snapname, &val); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2287 if (err == 0) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2288 err = EEXIST; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2289 if (err != ENOENT) |
2082 | 2290 break; |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2291 err = 0; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2292 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2293 /* The very first snapshot does not have a deadlist */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2294 if (ds->ds_phys->ds_prev_snap_obj != 0) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2295 if (err = bplist_space(&ds->ds_deadlist, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2296 &dlused, &dlcomp, &dluncomp)) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2297 break; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2298 pa->used += dlused; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2299 pa->comp += dlcomp; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2300 pa->uncomp += dluncomp; |
2082 | 2301 } |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2302 } while (snap = list_next(&pa->snap_list, snap)); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2303 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2304 /* |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2305 * If we are a clone of a clone then we never reached ORIGIN, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2306 * so we need to subtract out the clone origin's used space. |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2307 */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2308 if (pa->clone_origin) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2309 pa->used -= pa->clone_origin->ds_phys->ds_used_bytes; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2310 pa->comp -= pa->clone_origin->ds_phys->ds_compressed_bytes; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2311 pa->uncomp -= pa->clone_origin->ds_phys->ds_uncompressed_bytes; |
2082 | 2312 } |
2313 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2314 kmem_free(name, MAXPATHLEN); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2315 |
2082 | 2316 /* Check that there is enough space here */ |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2317 if (err == 0) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2318 dsl_dir_t *odd = origin_ds->ds_dir; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2319 err = dsl_dir_transfer_possible(odd, hds->ds_dir, pa->used); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2320 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2321 |
2199 | 2322 return (err); |
2323 } | |
2082 | 2324 |
2199 | 2325 static void |
4543 | 2326 dsl_dataset_promote_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
2199 | 2327 { |
2328 dsl_dataset_t *hds = arg1; | |
2329 struct promotearg *pa = arg2; | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2330 struct promotedsarg *snap = list_head(&pa->snap_list); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2331 dsl_dataset_t *origin_ds = snap->ds; |
2199 | 2332 dsl_dir_t *dd = hds->ds_dir; |
2333 dsl_pool_t *dp = hds->ds_dir->dd_pool; | |
5367 | 2334 dsl_dir_t *odd = NULL; |
2199 | 2335 char *name; |
2336 | |
2337 ASSERT(0 == (hds->ds_phys->ds_flags & DS_FLAG_NOPROMOTE)); | |
2338 | |
2417 | 2339 /* |
5367 | 2340 * We need to explicitly open odd, since origin_ds's dd will be |
2417 | 2341 * changing. |
2342 */ | |
5367 | 2343 VERIFY(0 == dsl_dir_open_obj(dp, origin_ds->ds_dir->dd_object, |
2344 NULL, FTAG, &odd)); | |
2082 | 2345 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2346 /* change origin's next snap */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2347 dmu_buf_will_dirty(origin_ds->ds_dbuf, tx); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2348 origin_ds->ds_phys->ds_next_snap_obj = pa->newnext_obj; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2349 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2350 /* change origin */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2351 dmu_buf_will_dirty(dd->dd_dbuf, tx); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2352 ASSERT3U(dd->dd_phys->dd_origin_obj, ==, origin_ds->ds_object); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2353 dd->dd_phys->dd_origin_obj = odd->dd_phys->dd_origin_obj; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2354 dmu_buf_will_dirty(odd->dd_dbuf, tx); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2355 odd->dd_phys->dd_origin_obj = origin_ds->ds_object; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2356 |
2082 | 2357 /* move snapshots to this dir */ |
2199 | 2358 name = kmem_alloc(MAXPATHLEN, KM_SLEEP); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2359 do { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2360 dsl_dataset_t *ds = snap->ds; |
2082 | 2361 |
2362 /* move snap name entry */ | |
2363 dsl_dataset_name(ds, name); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2364 VERIFY(0 == dsl_dataset_snap_remove(pa->old_head, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2365 ds->ds_snapname, tx)); |
2199 | 2366 VERIFY(0 == zap_add(dp->dp_meta_objset, |
2082 | 2367 hds->ds_phys->ds_snapnames_zapobj, ds->ds_snapname, |
2368 8, 1, &ds->ds_object, tx)); | |
2369 | |
2370 /* change containing dsl_dir */ | |
2371 dmu_buf_will_dirty(ds->ds_dbuf, tx); | |
5367 | 2372 ASSERT3U(ds->ds_phys->ds_dir_obj, ==, odd->dd_object); |
2082 | 2373 ds->ds_phys->ds_dir_obj = dd->dd_object; |
5367 | 2374 ASSERT3P(ds->ds_dir, ==, odd); |
2082 | 2375 dsl_dir_close(ds->ds_dir, ds); |
2199 | 2376 VERIFY(0 == dsl_dir_open_obj(dp, dd->dd_object, |
2082 | 2377 NULL, ds, &ds->ds_dir)); |
2378 | |
2379 ASSERT3U(dsl_prop_numcb(ds), ==, 0); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2380 } while (snap = list_next(&pa->snap_list, snap)); |
2082 | 2381 |
2382 /* change space accounting */ | |
5367 | 2383 dsl_dir_diduse_space(odd, -pa->used, -pa->comp, -pa->uncomp, tx); |
2199 | 2384 dsl_dir_diduse_space(dd, pa->used, pa->comp, pa->uncomp, tx); |
5367 | 2385 origin_ds->ds_phys->ds_unique_bytes = pa->unique; |
2082 | 2386 |
4543 | 2387 /* log history record */ |
2388 spa_history_internal_log(LOG_DS_PROMOTE, dd->dd_pool->dp_spa, tx, | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2389 cr, "dataset = %llu", hds->ds_object); |
4543 | 2390 |
5367 | 2391 dsl_dir_close(odd, FTAG); |
2199 | 2392 kmem_free(name, MAXPATHLEN); |
2082 | 2393 } |
2394 | |
2395 int | |
2396 dsl_dataset_promote(const char *name) | |
2397 { | |
2398 dsl_dataset_t *ds; | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2399 dsl_dir_t *dd; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2400 dsl_pool_t *dp; |
2082 | 2401 dmu_object_info_t doi; |
2199 | 2402 struct promotearg pa; |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2403 struct promotedsarg *snap; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2404 uint64_t snap_obj; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2405 uint64_t last_snap = 0; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2406 int err; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2407 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2408 err = dsl_dataset_hold(name, FTAG, &ds); |
2082 | 2409 if (err) |
2410 return (err); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2411 dd = ds->ds_dir; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2412 dp = dd->dd_pool; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2413 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2414 err = dmu_object_info(dp->dp_meta_objset, |
2082 | 2415 ds->ds_phys->ds_snapnames_zapobj, &doi); |
2416 if (err) { | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2417 dsl_dataset_rele(ds, FTAG); |
2082 | 2418 return (err); |
2419 } | |
2420 | |
2421 /* | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2422 * We are going to inherit all the snapshots taken before our |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2423 * origin (i.e., our new origin will be our parent's origin). |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2424 * Take ownership of them so that we can rename them into our |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2425 * namespace. |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2426 */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2427 pa.clone_origin = NULL; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2428 list_create(&pa.snap_list, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2429 sizeof (struct promotedsarg), offsetof(struct promotedsarg, link)); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2430 rw_enter(&dp->dp_config_rwlock, RW_READER); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2431 ASSERT(dd->dd_phys->dd_origin_obj != 0); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2432 snap_obj = dd->dd_phys->dd_origin_obj; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2433 while (snap_obj) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2434 snap = kmem_alloc(sizeof (struct promotedsarg), KM_SLEEP); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2435 err = dsl_dataset_own_obj(dp, snap_obj, 0, FTAG, &snap->ds); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2436 if (err == ENOENT) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2437 /* lost race with snapshot destroy */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2438 struct promotedsarg *last = list_tail(&pa.snap_list); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2439 ASSERT(snap_obj != last->ds->ds_phys->ds_prev_snap_obj); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2440 snap_obj = last->ds->ds_phys->ds_prev_snap_obj; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2441 kmem_free(snap, sizeof (struct promotedsarg)); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2442 continue; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2443 } else if (err) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2444 kmem_free(snap, sizeof (struct promotedsarg)); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2445 rw_exit(&dp->dp_config_rwlock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2446 goto out; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2447 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2448 /* |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2449 * We could be a clone of a clone. If we reach our |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2450 * parent's branch point, we're done. |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2451 */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2452 if (last_snap && |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2453 snap->ds->ds_phys->ds_next_snap_obj != last_snap) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2454 pa.clone_origin = snap->ds; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2455 kmem_free(snap, sizeof (struct promotedsarg)); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2456 snap_obj = 0; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2457 } else { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2458 list_insert_tail(&pa.snap_list, snap); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2459 last_snap = snap_obj; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2460 snap_obj = snap->ds->ds_phys->ds_prev_snap_obj; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2461 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2462 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2463 snap = list_head(&pa.snap_list); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2464 ASSERT(snap != NULL); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2465 err = dsl_dataset_hold_obj(dp, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2466 snap->ds->ds_dir->dd_phys->dd_head_dataset_obj, FTAG, &pa.old_head); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2467 rw_exit(&dp->dp_config_rwlock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2468 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2469 if (err) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2470 goto out; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2471 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2472 /* |
2082 | 2473 * Add in 128x the snapnames zapobj size, since we will be moving |
2474 * a bunch of snapnames to the promoted ds, and dirtying their | |
2475 * bonus buffers. | |
2476 */ | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2477 err = dsl_sync_task_do(dp, dsl_dataset_promote_check, |
2199 | 2478 dsl_dataset_promote_sync, ds, &pa, 2 + 2 * doi.doi_physical_blks); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2479 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2480 dsl_dataset_rele(pa.old_head, FTAG); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2481 out: |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2482 while ((snap = list_tail(&pa.snap_list)) != NULL) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2483 list_remove(&pa.snap_list, snap); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2484 dsl_dataset_disown(snap->ds, FTAG); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2485 kmem_free(snap, sizeof (struct promotedsarg)); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2486 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2487 list_destroy(&pa.snap_list); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2488 if (pa.clone_origin) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2489 dsl_dataset_disown(pa.clone_origin, FTAG); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2490 dsl_dataset_rele(ds, FTAG); |
2082 | 2491 return (err); |
2492 } | |
3912 | 2493 |
5367 | 2494 struct cloneswaparg { |
2495 dsl_dataset_t *cds; /* clone dataset */ | |
2496 dsl_dataset_t *ohds; /* origin's head dataset */ | |
2497 boolean_t force; | |
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2498 int64_t unused_refres_delta; /* change in unconsumed refreservation */ |
5367 | 2499 }; |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2500 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2501 /* ARGSUSED */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2502 static int |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2503 dsl_dataset_clone_swap_check(void *arg1, void *arg2, dmu_tx_t *tx) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2504 { |
5367 | 2505 struct cloneswaparg *csa = arg1; |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2506 |
5367 | 2507 /* they should both be heads */ |
2508 if (dsl_dataset_is_snapshot(csa->cds) || | |
2509 dsl_dataset_is_snapshot(csa->ohds)) | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2510 return (EINVAL); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2511 |
5367 | 2512 /* the branch point should be just before them */ |
2513 if (csa->cds->ds_prev != csa->ohds->ds_prev) | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2514 return (EINVAL); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2515 |
5367 | 2516 /* cds should be the clone */ |
2517 if (csa->cds->ds_prev->ds_phys->ds_next_snap_obj != | |
2518 csa->ohds->ds_object) | |
2519 return (EINVAL); | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2520 |
5367 | 2521 /* the clone should be a child of the origin */ |
2522 if (csa->cds->ds_dir->dd_parent != csa->ohds->ds_dir) | |
2523 return (EINVAL); | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2524 |
5367 | 2525 /* ohds shouldn't be modified unless 'force' */ |
2526 if (!csa->force && dsl_dataset_modified_since_lastsnap(csa->ohds)) | |
2527 return (ETXTBSY); | |
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2528 |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2529 /* adjust amount of any unconsumed refreservation */ |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2530 csa->unused_refres_delta = |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2531 (int64_t)MIN(csa->ohds->ds_reserved, |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2532 csa->ohds->ds_phys->ds_unique_bytes) - |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2533 (int64_t)MIN(csa->ohds->ds_reserved, |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2534 csa->cds->ds_phys->ds_unique_bytes); |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2535 |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2536 if (csa->unused_refres_delta > 0 && |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2537 csa->unused_refres_delta > |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2538 dsl_dir_space_available(csa->ohds->ds_dir, NULL, 0, TRUE)) |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2539 return (ENOSPC); |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2540 |
5367 | 2541 return (0); |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2542 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2543 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2544 /* ARGSUSED */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2545 static void |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2546 dsl_dataset_clone_swap_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2547 { |
5367 | 2548 struct cloneswaparg *csa = arg1; |
2549 dsl_pool_t *dp = csa->cds->ds_dir->dd_pool; | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2550 uint64_t itor = 0; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2551 blkptr_t bp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2552 uint64_t unique = 0; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2553 int err; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2554 |
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2555 ASSERT(csa->cds->ds_reserved == 0); |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2556 ASSERT(csa->cds->ds_quota == csa->ohds->ds_quota); |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2557 |
5367 | 2558 dmu_buf_will_dirty(csa->cds->ds_dbuf, tx); |
2559 dmu_buf_will_dirty(csa->ohds->ds_dbuf, tx); | |
2560 dmu_buf_will_dirty(csa->cds->ds_prev->ds_dbuf, tx); | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2561 |
5367 | 2562 if (csa->cds->ds_user_ptr != NULL) { |
2563 csa->cds->ds_user_evict_func(csa->cds, csa->cds->ds_user_ptr); | |
2564 csa->cds->ds_user_ptr = NULL; | |
2565 } | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2566 |
5367 | 2567 if (csa->ohds->ds_user_ptr != NULL) { |
2568 csa->ohds->ds_user_evict_func(csa->ohds, | |
2569 csa->ohds->ds_user_ptr); | |
2570 csa->ohds->ds_user_ptr = NULL; | |
2571 } | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2572 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2573 /* compute unique space */ |
5367 | 2574 while ((err = bplist_iterate(&csa->cds->ds_deadlist, |
2575 &itor, &bp)) == 0) { | |
2576 if (bp.blk_birth > csa->cds->ds_prev->ds_phys->ds_prev_snap_txg) | |
2577 unique += bp_get_dasize(dp->dp_spa, &bp); | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2578 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2579 VERIFY(err == ENOENT); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2580 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2581 /* reset origin's unique bytes */ |
5367 | 2582 csa->cds->ds_prev->ds_phys->ds_unique_bytes = unique; |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2583 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2584 /* swap blkptrs */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2585 { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2586 blkptr_t tmp; |
5367 | 2587 tmp = csa->ohds->ds_phys->ds_bp; |
2588 csa->ohds->ds_phys->ds_bp = csa->cds->ds_phys->ds_bp; | |
2589 csa->cds->ds_phys->ds_bp = tmp; | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2590 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2591 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2592 /* set dd_*_bytes */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2593 { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2594 int64_t dused, dcomp, duncomp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2595 uint64_t cdl_used, cdl_comp, cdl_uncomp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2596 uint64_t odl_used, odl_comp, odl_uncomp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2597 |
5367 | 2598 VERIFY(0 == bplist_space(&csa->cds->ds_deadlist, &cdl_used, |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2599 &cdl_comp, &cdl_uncomp)); |
5367 | 2600 VERIFY(0 == bplist_space(&csa->ohds->ds_deadlist, &odl_used, |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2601 &odl_comp, &odl_uncomp)); |
5367 | 2602 dused = csa->cds->ds_phys->ds_used_bytes + cdl_used - |
2603 (csa->ohds->ds_phys->ds_used_bytes + odl_used); | |
2604 dcomp = csa->cds->ds_phys->ds_compressed_bytes + cdl_comp - | |
2605 (csa->ohds->ds_phys->ds_compressed_bytes + odl_comp); | |
2606 duncomp = csa->cds->ds_phys->ds_uncompressed_bytes + | |
2607 cdl_uncomp - | |
2608 (csa->ohds->ds_phys->ds_uncompressed_bytes + odl_uncomp); | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2609 |
5367 | 2610 dsl_dir_diduse_space(csa->ohds->ds_dir, |
2611 dused, dcomp, duncomp, tx); | |
2612 dsl_dir_diduse_space(csa->cds->ds_dir, | |
2613 -dused, -dcomp, -duncomp, tx); | |
2614 } | |
2615 | |
2616 #define SWITCH64(x, y) \ | |
2617 { \ | |
2618 uint64_t __tmp = (x); \ | |
2619 (x) = (y); \ | |
2620 (y) = __tmp; \ | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2621 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2622 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2623 /* swap ds_*_bytes */ |
5367 | 2624 SWITCH64(csa->ohds->ds_phys->ds_used_bytes, |
2625 csa->cds->ds_phys->ds_used_bytes); | |
2626 SWITCH64(csa->ohds->ds_phys->ds_compressed_bytes, | |
2627 csa->cds->ds_phys->ds_compressed_bytes); | |
2628 SWITCH64(csa->ohds->ds_phys->ds_uncompressed_bytes, | |
2629 csa->cds->ds_phys->ds_uncompressed_bytes); | |
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2630 SWITCH64(csa->ohds->ds_phys->ds_unique_bytes, |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2631 csa->cds->ds_phys->ds_unique_bytes); |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2632 |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2633 /* apply any parent delta for change in unconsumed refreservation */ |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2634 dsl_dir_diduse_space(csa->ohds->ds_dir, csa->unused_refres_delta, |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2635 0, 0, tx); |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2636 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2637 /* swap deadlists */ |
5367 | 2638 bplist_close(&csa->cds->ds_deadlist); |
2639 bplist_close(&csa->ohds->ds_deadlist); | |
2640 SWITCH64(csa->ohds->ds_phys->ds_deadlist_obj, | |
2641 csa->cds->ds_phys->ds_deadlist_obj); | |
2642 VERIFY(0 == bplist_open(&csa->cds->ds_deadlist, dp->dp_meta_objset, | |
2643 csa->cds->ds_phys->ds_deadlist_obj)); | |
2644 VERIFY(0 == bplist_open(&csa->ohds->ds_deadlist, dp->dp_meta_objset, | |
2645 csa->ohds->ds_phys->ds_deadlist_obj)); | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2646 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2647 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2648 /* |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2649 * Swap 'clone' with its origin head file system. Used at the end |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2650 * of "online recv" to swizzle the file system to the new version. |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2651 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2652 int |
5367 | 2653 dsl_dataset_clone_swap(dsl_dataset_t *clone, dsl_dataset_t *origin_head, |
2654 boolean_t force) | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2655 { |
5367 | 2656 struct cloneswaparg csa; |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2657 int error; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2658 |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2659 ASSERT(clone->ds_owner); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2660 ASSERT(origin_head->ds_owner); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2661 retry: |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2662 /* Need exclusive access for the swap */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2663 rw_enter(&clone->ds_rwlock, RW_WRITER); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2664 if (!rw_tryenter(&origin_head->ds_rwlock, RW_WRITER)) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2665 rw_exit(&clone->ds_rwlock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2666 rw_enter(&origin_head->ds_rwlock, RW_WRITER); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2667 if (!rw_tryenter(&clone->ds_rwlock, RW_WRITER)) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2668 rw_exit(&origin_head->ds_rwlock); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2669 goto retry; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2670 } |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2671 } |
5367 | 2672 csa.cds = clone; |
2673 csa.ohds = origin_head; | |
2674 csa.force = force; | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2675 error = dsl_sync_task_do(clone->ds_dir->dd_pool, |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2676 dsl_dataset_clone_swap_check, |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2677 dsl_dataset_clone_swap_sync, &csa, NULL, 9); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2678 return (error); |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2679 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5094
diff
changeset
|
2680 |
3912 | 2681 /* |
2682 * Given a pool name and a dataset object number in that pool, | |
2683 * return the name of that dataset. | |
2684 */ | |
2685 int | |
2686 dsl_dsobj_to_dsname(char *pname, uint64_t obj, char *buf) | |
2687 { | |
2688 spa_t *spa; | |
2689 dsl_pool_t *dp; | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2690 dsl_dataset_t *ds; |
3912 | 2691 int error; |
2692 | |
2693 if ((error = spa_open(pname, &spa, FTAG)) != 0) | |
2694 return (error); | |
2695 dp = spa_get_dsl(spa); | |
2696 rw_enter(&dp->dp_config_rwlock, RW_READER); | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2697 if ((error = dsl_dataset_hold_obj(dp, obj, FTAG, &ds)) == 0) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2698 dsl_dataset_name(ds, buf); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2699 dsl_dataset_rele(ds, FTAG); |
3912 | 2700 } |
2701 rw_exit(&dp->dp_config_rwlock); | |
2702 spa_close(spa, FTAG); | |
2703 | |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2704 return (error); |
3912 | 2705 } |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2706 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2707 int |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2708 dsl_dataset_check_quota(dsl_dataset_t *ds, boolean_t check_quota, |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2709 uint64_t asize, uint64_t inflight, uint64_t *used, uint64_t *ref_rsrv) |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2710 { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2711 int error = 0; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2712 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2713 ASSERT3S(asize, >, 0); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2714 |
5831
48655d6b290b
6630761 In sub-filesystem, available space is less than refreservation space
ck153898
parents:
5712
diff
changeset
|
2715 /* |
48655d6b290b
6630761 In sub-filesystem, available space is less than refreservation space
ck153898
parents:
5712
diff
changeset
|
2716 * *ref_rsrv is the portion of asize that will come from any |
48655d6b290b
6630761 In sub-filesystem, available space is less than refreservation space
ck153898
parents:
5712
diff
changeset
|
2717 * unconsumed refreservation space. |
48655d6b290b
6630761 In sub-filesystem, available space is less than refreservation space
ck153898
parents:
5712
diff
changeset
|
2718 */ |
48655d6b290b
6630761 In sub-filesystem, available space is less than refreservation space
ck153898
parents:
5712
diff
changeset
|
2719 *ref_rsrv = 0; |
48655d6b290b
6630761 In sub-filesystem, available space is less than refreservation space
ck153898
parents:
5712
diff
changeset
|
2720 |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2721 mutex_enter(&ds->ds_lock); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2722 /* |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2723 * Make a space adjustment for reserved bytes. |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2724 */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2725 if (ds->ds_reserved > ds->ds_phys->ds_unique_bytes) { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2726 ASSERT3U(*used, >=, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2727 ds->ds_reserved - ds->ds_phys->ds_unique_bytes); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2728 *used -= (ds->ds_reserved - ds->ds_phys->ds_unique_bytes); |
5831
48655d6b290b
6630761 In sub-filesystem, available space is less than refreservation space
ck153898
parents:
5712
diff
changeset
|
2729 *ref_rsrv = |
48655d6b290b
6630761 In sub-filesystem, available space is less than refreservation space
ck153898
parents:
5712
diff
changeset
|
2730 asize - MIN(asize, parent_delta(ds, asize + inflight)); |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2731 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2732 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2733 if (!check_quota || ds->ds_quota == 0) { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2734 mutex_exit(&ds->ds_lock); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2735 return (0); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2736 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2737 /* |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2738 * If they are requesting more space, and our current estimate |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2739 * is over quota, they get to try again unless the actual |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2740 * on-disk is over quota and there are no pending changes (which |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2741 * may free up space for us). |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2742 */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2743 if (ds->ds_phys->ds_used_bytes + inflight >= ds->ds_quota) { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2744 if (inflight > 0 || ds->ds_phys->ds_used_bytes < ds->ds_quota) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2745 error = ERESTART; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2746 else |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2747 error = EDQUOT; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2748 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2749 mutex_exit(&ds->ds_lock); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2750 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2751 return (error); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2752 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2753 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2754 /* ARGSUSED */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2755 static int |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2756 dsl_dataset_set_quota_check(void *arg1, void *arg2, dmu_tx_t *tx) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2757 { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2758 dsl_dataset_t *ds = arg1; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2759 uint64_t *quotap = arg2; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2760 uint64_t new_quota = *quotap; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2761 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2762 if (spa_version(ds->ds_dir->dd_pool->dp_spa) < SPA_VERSION_REFQUOTA) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2763 return (ENOTSUP); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2764 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2765 if (new_quota == 0) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2766 return (0); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2767 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2768 if (new_quota < ds->ds_phys->ds_used_bytes || |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2769 new_quota < ds->ds_reserved) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2770 return (ENOSPC); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2771 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2772 return (0); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2773 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2774 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2775 /* ARGSUSED */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2776 void |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2777 dsl_dataset_set_quota_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2778 { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2779 dsl_dataset_t *ds = arg1; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2780 uint64_t *quotap = arg2; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2781 uint64_t new_quota = *quotap; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2782 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2783 dmu_buf_will_dirty(ds->ds_dbuf, tx); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2784 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2785 ds->ds_quota = new_quota; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2786 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2787 dsl_prop_set_uint64_sync(ds->ds_dir, "refquota", new_quota, cr, tx); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2788 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2789 spa_history_internal_log(LOG_DS_REFQUOTA, ds->ds_dir->dd_pool->dp_spa, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2790 tx, cr, "%lld dataset = %llu ", |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2791 (longlong_t)new_quota, ds->ds_object); |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2792 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2793 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2794 int |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2795 dsl_dataset_set_quota(const char *dsname, uint64_t quota) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2796 { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2797 dsl_dataset_t *ds; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2798 int err; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2799 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2800 err = dsl_dataset_hold(dsname, FTAG, &ds); |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2801 if (err) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2802 return (err); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2803 |
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2804 if (quota != ds->ds_quota) { |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2805 /* |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2806 * If someone removes a file, then tries to set the quota, we |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2807 * want to make sure the file freeing takes effect. |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2808 */ |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2809 txg_wait_open(ds->ds_dir->dd_pool, 0); |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2810 |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2811 err = dsl_sync_task_do(ds->ds_dir->dd_pool, |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2812 dsl_dataset_set_quota_check, dsl_dataset_set_quota_sync, |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2813 ds, "a, 0); |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5475
diff
changeset
|
2814 } |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2815 dsl_dataset_rele(ds, FTAG); |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2816 return (err); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2817 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2818 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2819 static int |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2820 dsl_dataset_set_reservation_check(void *arg1, void *arg2, dmu_tx_t *tx) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2821 { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2822 dsl_dataset_t *ds = arg1; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2823 uint64_t *reservationp = arg2; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2824 uint64_t new_reservation = *reservationp; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2825 int64_t delta; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2826 uint64_t unique; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2827 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2828 if (new_reservation > INT64_MAX) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2829 return (EOVERFLOW); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2830 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2831 if (spa_version(ds->ds_dir->dd_pool->dp_spa) < |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2832 SPA_VERSION_REFRESERVATION) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2833 return (ENOTSUP); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2834 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2835 if (dsl_dataset_is_snapshot(ds)) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2836 return (EINVAL); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2837 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2838 /* |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2839 * If we are doing the preliminary check in open context, the |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2840 * space estimates may be inaccurate. |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2841 */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2842 if (!dmu_tx_is_syncing(tx)) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2843 return (0); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2844 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2845 mutex_enter(&ds->ds_lock); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2846 unique = dsl_dataset_unique(ds); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2847 delta = MAX(unique, new_reservation) - MAX(unique, ds->ds_reserved); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2848 mutex_exit(&ds->ds_lock); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2849 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2850 if (delta > 0 && |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2851 delta > dsl_dir_space_available(ds->ds_dir, NULL, 0, TRUE)) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2852 return (ENOSPC); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2853 if (delta > 0 && ds->ds_quota > 0 && |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2854 new_reservation > ds->ds_quota) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2855 return (ENOSPC); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2856 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2857 return (0); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2858 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2859 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2860 /* ARGSUSED */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2861 static void |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2862 dsl_dataset_set_reservation_sync(void *arg1, void *arg2, cred_t *cr, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2863 dmu_tx_t *tx) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2864 { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2865 dsl_dataset_t *ds = arg1; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2866 uint64_t *reservationp = arg2; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2867 uint64_t new_reservation = *reservationp; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2868 uint64_t unique; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2869 int64_t delta; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2870 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2871 dmu_buf_will_dirty(ds->ds_dbuf, tx); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2872 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2873 mutex_enter(&ds->ds_lock); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2874 unique = dsl_dataset_unique(ds); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2875 delta = MAX(0, (int64_t)(new_reservation - unique)) - |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2876 MAX(0, (int64_t)(ds->ds_reserved - unique)); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2877 ds->ds_reserved = new_reservation; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2878 mutex_exit(&ds->ds_lock); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2879 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2880 dsl_prop_set_uint64_sync(ds->ds_dir, "refreservation", |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2881 new_reservation, cr, tx); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2882 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2883 dsl_dir_diduse_space(ds->ds_dir, delta, 0, 0, tx); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2884 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2885 spa_history_internal_log(LOG_DS_REFRESERV, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2886 ds->ds_dir->dd_pool->dp_spa, tx, cr, "%lld dataset = %llu", |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2887 (longlong_t)new_reservation, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2888 ds->ds_dir->dd_phys->dd_head_dataset_obj); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2889 } |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2890 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2891 int |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2892 dsl_dataset_set_reservation(const char *dsname, uint64_t reservation) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2893 { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2894 dsl_dataset_t *ds; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2895 int err; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2896 |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2897 err = dsl_dataset_hold(dsname, FTAG, &ds); |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2898 if (err) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2899 return (err); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2900 |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2901 err = dsl_sync_task_do(ds->ds_dir->dd_pool, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2902 dsl_dataset_set_reservation_check, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2903 dsl_dataset_set_reservation_sync, ds, &reservation, 0); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6643
diff
changeset
|
2904 dsl_dataset_rele(ds, FTAG); |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2905 return (err); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
2906 } |