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