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