author | Matthew Ahrens <Matthew.Ahrens@Sun.COM> |
Wed, 12 Aug 2009 22:11:31 -0700 | |
changeset 10298 | a0d52501437c |
parent 10272 | a0669934e974 |
child 10819 | d41e0e73a69e |
permissions | -rw-r--r-- |
2743 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
5 |
* Common Development and Distribution License (the "License"). |
|
6 |
* You may not use this file except in compliance with the License. |
|
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 |
/* |
|
8644
10534c530688
6793373 assertion failed in dnode_reallocate: dn_nblkptr >= old_nblkptr
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7994
diff
changeset
|
22 |
* Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
2743 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
#include <sys/dmu.h> |
|
27 |
#include <sys/dmu_impl.h> |
|
28 |
#include <sys/dmu_tx.h> |
|
29 |
#include <sys/dbuf.h> |
|
30 |
#include <sys/dnode.h> |
|
31 |
#include <sys/zfs_context.h> |
|
32 |
#include <sys/dmu_objset.h> |
|
33 |
#include <sys/dmu_traverse.h> |
|
34 |
#include <sys/dsl_dataset.h> |
|
35 |
#include <sys/dsl_dir.h> |
|
36 |
#include <sys/dsl_pool.h> |
|
37 |
#include <sys/dsl_synctask.h> |
|
38 |
#include <sys/zfs_ioctl.h> |
|
39 |
#include <sys/zap.h> |
|
40 |
#include <sys/zio_checksum.h> |
|
41 |
||
5367 | 42 |
static char *dmu_recv_tag = "dmu_recv_tag"; |
43 |
||
2743 | 44 |
struct backuparg { |
45 |
dmu_replay_record_t *drr; |
|
46 |
vnode_t *vp; |
|
5367 | 47 |
offset_t *off; |
2743 | 48 |
objset_t *os; |
49 |
zio_cksum_t zc; |
|
50 |
int err; |
|
51 |
}; |
|
52 |
||
53 |
static int |
|
54 |
dump_bytes(struct backuparg *ba, void *buf, int len) |
|
55 |
{ |
|
56 |
ssize_t resid; /* have to get resid to get detailed errno */ |
|
57 |
ASSERT3U(len % 8, ==, 0); |
|
58 |
||
59 |
fletcher_4_incremental_native(buf, len, &ba->zc); |
|
60 |
ba->err = vn_rdwr(UIO_WRITE, ba->vp, |
|
61 |
(caddr_t)buf, len, |
|
62 |
0, UIO_SYSSPACE, FAPPEND, RLIM64_INFINITY, CRED(), &resid); |
|
5367 | 63 |
*ba->off += len; |
2743 | 64 |
return (ba->err); |
65 |
} |
|
66 |
||
67 |
static int |
|
68 |
dump_free(struct backuparg *ba, uint64_t object, uint64_t offset, |
|
69 |
uint64_t length) |
|
70 |
{ |
|
71 |
/* write a FREE record */ |
|
72 |
bzero(ba->drr, sizeof (dmu_replay_record_t)); |
|
73 |
ba->drr->drr_type = DRR_FREE; |
|
74 |
ba->drr->drr_u.drr_free.drr_object = object; |
|
75 |
ba->drr->drr_u.drr_free.drr_offset = offset; |
|
76 |
ba->drr->drr_u.drr_free.drr_length = length; |
|
77 |
||
78 |
if (dump_bytes(ba, ba->drr, sizeof (dmu_replay_record_t))) |
|
79 |
return (EINTR); |
|
80 |
return (0); |
|
81 |
} |
|
82 |
||
83 |
static int |
|
84 |
dump_data(struct backuparg *ba, dmu_object_type_t type, |
|
85 |
uint64_t object, uint64_t offset, int blksz, void *data) |
|
86 |
{ |
|
87 |
/* write a DATA record */ |
|
88 |
bzero(ba->drr, sizeof (dmu_replay_record_t)); |
|
89 |
ba->drr->drr_type = DRR_WRITE; |
|
90 |
ba->drr->drr_u.drr_write.drr_object = object; |
|
91 |
ba->drr->drr_u.drr_write.drr_type = type; |
|
92 |
ba->drr->drr_u.drr_write.drr_offset = offset; |
|
93 |
ba->drr->drr_u.drr_write.drr_length = blksz; |
|
94 |
||
95 |
if (dump_bytes(ba, ba->drr, sizeof (dmu_replay_record_t))) |
|
96 |
return (EINTR); |
|
97 |
if (dump_bytes(ba, data, blksz)) |
|
98 |
return (EINTR); |
|
99 |
return (0); |
|
100 |
} |
|
101 |
||
102 |
static int |
|
103 |
dump_freeobjects(struct backuparg *ba, uint64_t firstobj, uint64_t numobjs) |
|
104 |
{ |
|
105 |
/* write a FREEOBJECTS record */ |
|
106 |
bzero(ba->drr, sizeof (dmu_replay_record_t)); |
|
107 |
ba->drr->drr_type = DRR_FREEOBJECTS; |
|
108 |
ba->drr->drr_u.drr_freeobjects.drr_firstobj = firstobj; |
|
109 |
ba->drr->drr_u.drr_freeobjects.drr_numobjs = numobjs; |
|
110 |
||
111 |
if (dump_bytes(ba, ba->drr, sizeof (dmu_replay_record_t))) |
|
112 |
return (EINTR); |
|
113 |
return (0); |
|
114 |
} |
|
115 |
||
116 |
static int |
|
117 |
dump_dnode(struct backuparg *ba, uint64_t object, dnode_phys_t *dnp) |
|
118 |
{ |
|
119 |
if (dnp == NULL || dnp->dn_type == DMU_OT_NONE) |
|
120 |
return (dump_freeobjects(ba, object, 1)); |
|
121 |
||
122 |
/* write an OBJECT record */ |
|
123 |
bzero(ba->drr, sizeof (dmu_replay_record_t)); |
|
124 |
ba->drr->drr_type = DRR_OBJECT; |
|
125 |
ba->drr->drr_u.drr_object.drr_object = object; |
|
126 |
ba->drr->drr_u.drr_object.drr_type = dnp->dn_type; |
|
127 |
ba->drr->drr_u.drr_object.drr_bonustype = dnp->dn_bonustype; |
|
128 |
ba->drr->drr_u.drr_object.drr_blksz = |
|
129 |
dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT; |
|
130 |
ba->drr->drr_u.drr_object.drr_bonuslen = dnp->dn_bonuslen; |
|
131 |
ba->drr->drr_u.drr_object.drr_checksum = dnp->dn_checksum; |
|
132 |
ba->drr->drr_u.drr_object.drr_compress = dnp->dn_compress; |
|
133 |
||
134 |
if (dump_bytes(ba, ba->drr, sizeof (dmu_replay_record_t))) |
|
135 |
return (EINTR); |
|
136 |
||
137 |
if (dump_bytes(ba, DN_BONUS(dnp), P2ROUNDUP(dnp->dn_bonuslen, 8))) |
|
138 |
return (EINTR); |
|
139 |
||
140 |
/* free anything past the end of the file */ |
|
141 |
if (dump_free(ba, object, (dnp->dn_maxblkid + 1) * |
|
142 |
(dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT), -1ULL)) |
|
143 |
return (EINTR); |
|
144 |
if (ba->err) |
|
145 |
return (EINTR); |
|
146 |
return (0); |
|
147 |
} |
|
148 |
||
149 |
#define BP_SPAN(dnp, level) \ |
|
150 |
(((uint64_t)dnp->dn_datablkszsec) << (SPA_MINBLOCKSHIFT + \ |
|
151 |
(level) * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT))) |
|
152 |
||
153 |
static int |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
154 |
backup_cb(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:
7046
diff
changeset
|
155 |
const dnode_phys_t *dnp, void *arg) |
2743 | 156 |
{ |
157 |
struct backuparg *ba = arg; |
|
158 |
dmu_object_type_t type = bp ? BP_GET_TYPE(bp) : DMU_OT_NONE; |
|
159 |
int err = 0; |
|
160 |
||
161 |
if (issig(JUSTLOOKING) && issig(FORREAL)) |
|
162 |
return (EINTR); |
|
163 |
||
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
164 |
if (zb->zb_object != 0 && DMU_OBJECT_IS_SPECIAL(zb->zb_object)) { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
165 |
return (0); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8986
diff
changeset
|
166 |
} else if (bp == NULL && zb->zb_object == 0) { |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
167 |
uint64_t span = BP_SPAN(dnp, zb->zb_level); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
168 |
uint64_t dnobj = (zb->zb_blkid * span) >> DNODE_SHIFT; |
2743 | 169 |
err = dump_freeobjects(ba, dnobj, span >> DNODE_SHIFT); |
170 |
} else if (bp == NULL) { |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
171 |
uint64_t span = BP_SPAN(dnp, zb->zb_level); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
172 |
err = dump_free(ba, zb->zb_object, zb->zb_blkid * span, span); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
173 |
} else if (zb->zb_level > 0 || type == DMU_OT_OBJSET) { |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
174 |
return (0); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
175 |
} else if (type == DMU_OT_DNODE) { |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
176 |
dnode_phys_t *blk; |
2743 | 177 |
int i; |
178 |
int blksz = BP_GET_LSIZE(bp); |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
179 |
uint32_t aflags = ARC_WAIT; |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
180 |
arc_buf_t *abuf; |
2743 | 181 |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
182 |
if (arc_read_nolock(NULL, spa, bp, |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
183 |
arc_getbuf_func, &abuf, ZIO_PRIORITY_ASYNC_READ, |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
184 |
ZIO_FLAG_CANFAIL, &aflags, zb) != 0) |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
185 |
return (EIO); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
186 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
187 |
blk = abuf->b_data; |
2743 | 188 |
for (i = 0; i < blksz >> DNODE_SHIFT; i++) { |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
189 |
uint64_t dnobj = (zb->zb_blkid << |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
190 |
(DNODE_BLOCK_SHIFT - DNODE_SHIFT)) + i; |
2743 | 191 |
err = dump_dnode(ba, dnobj, blk+i); |
192 |
if (err) |
|
193 |
break; |
|
194 |
} |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
195 |
(void) arc_buf_remove_ref(abuf, &abuf); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
196 |
} else { /* it's a level-0 block of a regular object */ |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
197 |
uint32_t aflags = ARC_WAIT; |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
198 |
arc_buf_t *abuf; |
2743 | 199 |
int blksz = BP_GET_LSIZE(bp); |
200 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
201 |
if (arc_read_nolock(NULL, spa, bp, |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
202 |
arc_getbuf_func, &abuf, ZIO_PRIORITY_ASYNC_READ, |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
203 |
ZIO_FLAG_CANFAIL, &aflags, zb) != 0) |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
204 |
return (EIO); |
2743 | 205 |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
206 |
err = dump_data(ba, type, zb->zb_object, zb->zb_blkid * blksz, |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
207 |
blksz, abuf->b_data); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
208 |
(void) arc_buf_remove_ref(abuf, &abuf); |
2743 | 209 |
} |
210 |
||
211 |
ASSERT(err == 0 || err == EINTR); |
|
212 |
return (err); |
|
213 |
} |
|
214 |
||
215 |
int |
|
5367 | 216 |
dmu_sendbackup(objset_t *tosnap, objset_t *fromsnap, boolean_t fromorigin, |
217 |
vnode_t *vp, offset_t *off) |
|
2743 | 218 |
{ |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
219 |
dsl_dataset_t *ds = tosnap->os_dsl_dataset; |
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
220 |
dsl_dataset_t *fromds = fromsnap ? fromsnap->os_dsl_dataset : NULL; |
2743 | 221 |
dmu_replay_record_t *drr; |
222 |
struct backuparg ba; |
|
223 |
int err; |
|
5367 | 224 |
uint64_t fromtxg = 0; |
2743 | 225 |
|
226 |
/* tosnap must be a snapshot */ |
|
227 |
if (ds->ds_phys->ds_next_snap_obj == 0) |
|
228 |
return (EINVAL); |
|
229 |
||
230 |
/* fromsnap must be an earlier snapshot from the same fs as tosnap */ |
|
231 |
if (fromds && (ds->ds_dir != fromds->ds_dir || |
|
5367 | 232 |
fromds->ds_phys->ds_creation_txg >= ds->ds_phys->ds_creation_txg)) |
2743 | 233 |
return (EXDEV); |
234 |
||
5367 | 235 |
if (fromorigin) { |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
236 |
dsl_pool_t *dp = ds->ds_dir->dd_pool; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
237 |
|
5367 | 238 |
if (fromsnap) |
239 |
return (EINVAL); |
|
240 |
||
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
241 |
if (dsl_dir_is_clone(ds->ds_dir)) { |
5367 | 242 |
rw_enter(&dp->dp_config_rwlock, RW_READER); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
243 |
err = dsl_dataset_hold_obj(dp, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
244 |
ds->ds_dir->dd_phys->dd_origin_obj, FTAG, &fromds); |
5367 | 245 |
rw_exit(&dp->dp_config_rwlock); |
246 |
if (err) |
|
247 |
return (err); |
|
248 |
} else { |
|
249 |
fromorigin = B_FALSE; |
|
250 |
} |
|
251 |
} |
|
252 |
||
253 |
||
2743 | 254 |
drr = kmem_zalloc(sizeof (dmu_replay_record_t), KM_SLEEP); |
255 |
drr->drr_type = DRR_BEGIN; |
|
256 |
drr->drr_u.drr_begin.drr_magic = DMU_BACKUP_MAGIC; |
|
5367 | 257 |
drr->drr_u.drr_begin.drr_version = DMU_BACKUP_STREAM_VERSION; |
2743 | 258 |
drr->drr_u.drr_begin.drr_creation_time = |
259 |
ds->ds_phys->ds_creation_time; |
|
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
260 |
drr->drr_u.drr_begin.drr_type = tosnap->os_phys->os_type; |
5367 | 261 |
if (fromorigin) |
262 |
drr->drr_u.drr_begin.drr_flags |= DRR_FLAG_CLONE; |
|
2743 | 263 |
drr->drr_u.drr_begin.drr_toguid = ds->ds_phys->ds_guid; |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6479
diff
changeset
|
264 |
if (ds->ds_phys->ds_flags & DS_FLAG_CI_DATASET) |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6479
diff
changeset
|
265 |
drr->drr_u.drr_begin.drr_flags |= DRR_FLAG_CI_DATA; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6479
diff
changeset
|
266 |
|
2743 | 267 |
if (fromds) |
268 |
drr->drr_u.drr_begin.drr_fromguid = fromds->ds_phys->ds_guid; |
|
269 |
dsl_dataset_name(ds, drr->drr_u.drr_begin.drr_toname); |
|
270 |
||
5367 | 271 |
if (fromds) |
272 |
fromtxg = fromds->ds_phys->ds_creation_txg; |
|
273 |
if (fromorigin) |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
274 |
dsl_dataset_rele(fromds, FTAG); |
5367 | 275 |
|
2743 | 276 |
ba.drr = drr; |
277 |
ba.vp = vp; |
|
278 |
ba.os = tosnap; |
|
5367 | 279 |
ba.off = off; |
2743 | 280 |
ZIO_SET_CHECKSUM(&ba.zc, 0, 0, 0, 0); |
281 |
||
282 |
if (dump_bytes(&ba, drr, sizeof (dmu_replay_record_t))) { |
|
283 |
kmem_free(drr, sizeof (dmu_replay_record_t)); |
|
284 |
return (ba.err); |
|
285 |
} |
|
286 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
287 |
err = traverse_dataset(ds, fromtxg, TRAVERSE_PRE | TRAVERSE_PREFETCH, |
2743 | 288 |
backup_cb, &ba); |
289 |
||
290 |
if (err) { |
|
291 |
if (err == EINTR && ba.err) |
|
292 |
err = ba.err; |
|
3655 | 293 |
kmem_free(drr, sizeof (dmu_replay_record_t)); |
2743 | 294 |
return (err); |
295 |
} |
|
296 |
||
297 |
bzero(drr, sizeof (dmu_replay_record_t)); |
|
298 |
drr->drr_type = DRR_END; |
|
299 |
drr->drr_u.drr_end.drr_checksum = ba.zc; |
|
300 |
||
3655 | 301 |
if (dump_bytes(&ba, drr, sizeof (dmu_replay_record_t))) { |
302 |
kmem_free(drr, sizeof (dmu_replay_record_t)); |
|
2743 | 303 |
return (ba.err); |
3655 | 304 |
} |
2743 | 305 |
|
306 |
kmem_free(drr, sizeof (dmu_replay_record_t)); |
|
307 |
||
308 |
return (0); |
|
309 |
} |
|
310 |
||
5367 | 311 |
struct recvbeginsyncarg { |
312 |
const char *tofs; |
|
313 |
const char *tosnap; |
|
314 |
dsl_dataset_t *origin; |
|
315 |
uint64_t fromguid; |
|
316 |
dmu_objset_type_t type; |
|
317 |
void *tag; |
|
318 |
boolean_t force; |
|
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6479
diff
changeset
|
319 |
uint64_t dsflags; |
5367 | 320 |
char clonelastname[MAXNAMELEN]; |
321 |
dsl_dataset_t *ds; /* the ds to recv into; returned from the syncfunc */ |
|
2743 | 322 |
}; |
323 |
||
5367 | 324 |
/* ARGSUSED */ |
2743 | 325 |
static int |
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
326 |
recv_new_check(void *arg1, void *arg2, dmu_tx_t *tx) |
5367 | 327 |
{ |
328 |
dsl_dir_t *dd = arg1; |
|
329 |
struct recvbeginsyncarg *rbsa = arg2; |
|
330 |
objset_t *mos = dd->dd_pool->dp_meta_objset; |
|
331 |
uint64_t val; |
|
332 |
int err; |
|
333 |
||
334 |
err = zap_lookup(mos, dd->dd_phys->dd_child_dir_zapobj, |
|
335 |
strrchr(rbsa->tofs, '/') + 1, sizeof (uint64_t), 1, &val); |
|
336 |
||
337 |
if (err != ENOENT) |
|
338 |
return (err ? err : EEXIST); |
|
339 |
||
340 |
if (rbsa->origin) { |
|
341 |
/* make sure it's a snap in the same pool */ |
|
342 |
if (rbsa->origin->ds_dir->dd_pool != dd->dd_pool) |
|
343 |
return (EXDEV); |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
344 |
if (!dsl_dataset_is_snapshot(rbsa->origin)) |
5367 | 345 |
return (EINVAL); |
346 |
if (rbsa->origin->ds_phys->ds_guid != rbsa->fromguid) |
|
347 |
return (ENODEV); |
|
348 |
} |
|
349 |
||
350 |
return (0); |
|
351 |
} |
|
352 |
||
353 |
static void |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
354 |
recv_new_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
5367 | 355 |
{ |
356 |
dsl_dir_t *dd = arg1; |
|
357 |
struct recvbeginsyncarg *rbsa = arg2; |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
358 |
uint64_t flags = DS_FLAG_INCONSISTENT | rbsa->dsflags; |
5367 | 359 |
uint64_t dsobj; |
360 |
||
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
361 |
/* Create and open new dataset. */ |
5367 | 362 |
dsobj = dsl_dataset_create_sync(dd, strrchr(rbsa->tofs, '/') + 1, |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6479
diff
changeset
|
363 |
rbsa->origin, flags, cr, tx); |
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
364 |
VERIFY(0 == dsl_dataset_own_obj(dd->dd_pool, dsobj, |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
365 |
B_TRUE, dmu_recv_tag, &rbsa->ds)); |
5367 | 366 |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
367 |
if (rbsa->origin == NULL) { |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
368 |
(void) dmu_objset_create_impl(dd->dd_pool->dp_spa, |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
369 |
rbsa->ds, &rbsa->ds->ds_phys->ds_bp, rbsa->type, tx); |
5367 | 370 |
} |
371 |
||
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
372 |
spa_history_internal_log(LOG_DS_REPLAY_FULL_SYNC, |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
373 |
dd->dd_pool->dp_spa, tx, cr, "dataset = %lld", dsobj); |
5367 | 374 |
} |
375 |
||
376 |
/* ARGSUSED */ |
|
377 |
static int |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
378 |
recv_existing_check(void *arg1, void *arg2, dmu_tx_t *tx) |
5367 | 379 |
{ |
380 |
dsl_dataset_t *ds = arg1; |
|
381 |
struct recvbeginsyncarg *rbsa = arg2; |
|
2743 | 382 |
int err; |
383 |
uint64_t val; |
|
384 |
||
5367 | 385 |
/* must not have any changes since most recent snapshot */ |
386 |
if (!rbsa->force && dsl_dataset_modified_since_lastsnap(ds)) |
|
387 |
return (ETXTBSY); |
|
388 |
||
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
389 |
if (rbsa->fromguid) { |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
390 |
/* if incremental, most recent snapshot must match fromguid */ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
391 |
if (ds->ds_prev == NULL) |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
392 |
return (ENODEV); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
393 |
if (ds->ds_prev->ds_phys->ds_guid != rbsa->fromguid) |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
394 |
return (ENODEV); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
395 |
} else { |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
396 |
/* if full, most recent snapshot must be $ORIGIN */ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
397 |
if (ds->ds_phys->ds_prev_snap_txg >= TXG_INITIAL) |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
398 |
return (ENODEV); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
399 |
} |
2743 | 400 |
|
6083
23e77aa611b1
6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents:
5378
diff
changeset
|
401 |
/* temporary clone name must not exist */ |
23e77aa611b1
6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents:
5378
diff
changeset
|
402 |
err = zap_lookup(ds->ds_dir->dd_pool->dp_meta_objset, |
23e77aa611b1
6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents:
5378
diff
changeset
|
403 |
ds->ds_dir->dd_phys->dd_child_dir_zapobj, |
23e77aa611b1
6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents:
5378
diff
changeset
|
404 |
rbsa->clonelastname, 8, 1, &val); |
23e77aa611b1
6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents:
5378
diff
changeset
|
405 |
if (err == 0) |
23e77aa611b1
6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents:
5378
diff
changeset
|
406 |
return (EEXIST); |
23e77aa611b1
6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents:
5378
diff
changeset
|
407 |
if (err != ENOENT) |
23e77aa611b1
6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents:
5378
diff
changeset
|
408 |
return (err); |
23e77aa611b1
6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents:
5378
diff
changeset
|
409 |
|
2743 | 410 |
/* new snapshot name must not exist */ |
5367 | 411 |
err = zap_lookup(ds->ds_dir->dd_pool->dp_meta_objset, |
412 |
ds->ds_phys->ds_snapnames_zapobj, rbsa->tosnap, 8, 1, &val); |
|
413 |
if (err == 0) |
|
2743 | 414 |
return (EEXIST); |
415 |
if (err != ENOENT) |
|
5367 | 416 |
return (err); |
2743 | 417 |
return (0); |
418 |
} |
|
419 |
||
420 |
/* ARGSUSED */ |
|
5367 | 421 |
static void |
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
422 |
recv_existing_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
423 |
{ |
5367 | 424 |
dsl_dataset_t *ohds = arg1; |
425 |
struct recvbeginsyncarg *rbsa = arg2; |
|
426 |
dsl_pool_t *dp = ohds->ds_dir->dd_pool; |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
427 |
dsl_dataset_t *cds; |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
428 |
uint64_t flags = DS_FLAG_INCONSISTENT | rbsa->dsflags; |
5367 | 429 |
uint64_t dsobj; |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
430 |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
431 |
/* create and open the temporary clone */ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
432 |
dsobj = dsl_dataset_create_sync(ohds->ds_dir, rbsa->clonelastname, |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
433 |
ohds->ds_prev, flags, cr, tx); |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
434 |
VERIFY(0 == dsl_dataset_own_obj(dp, dsobj, B_TRUE, dmu_recv_tag, &cds)); |
5367 | 435 |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
436 |
/* |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
437 |
* If we actually created a non-clone, we need to create the |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
438 |
* objset in our new dataset. |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
439 |
*/ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
440 |
if (BP_IS_HOLE(dsl_dataset_get_blkptr(cds))) { |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
441 |
(void) dmu_objset_create_impl(dp->dp_spa, |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
442 |
cds, dsl_dataset_get_blkptr(cds), rbsa->type, tx); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
443 |
} |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
444 |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
445 |
/* copy the refquota from the target fs to the clone */ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
446 |
if (ohds->ds_quota > 0) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
447 |
dsl_dataset_set_quota_sync(cds, &ohds->ds_quota, cr, tx); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
448 |
|
5367 | 449 |
rbsa->ds = cds; |
450 |
||
451 |
spa_history_internal_log(LOG_DS_REPLAY_INC_SYNC, |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
452 |
dp->dp_spa, tx, cr, "dataset = %lld", dsobj); |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
453 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
454 |
|
5367 | 455 |
/* |
456 |
* NB: callers *MUST* call dmu_recv_stream() if dmu_recv_begin() |
|
457 |
* succeeds; otherwise we will leak the holds on the datasets. |
|
458 |
*/ |
|
459 |
int |
|
460 |
dmu_recv_begin(char *tofs, char *tosnap, struct drr_begin *drrb, |
|
10204
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
461 |
boolean_t force, objset_t *origin, dmu_recv_cookie_t *drc) |
2743 | 462 |
{ |
5367 | 463 |
int err = 0; |
464 |
boolean_t byteswap; |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
465 |
struct recvbeginsyncarg rbsa = { 0 }; |
5367 | 466 |
uint64_t version; |
467 |
int flags; |
|
468 |
dsl_dataset_t *ds; |
|
469 |
||
470 |
if (drrb->drr_magic == DMU_BACKUP_MAGIC) |
|
471 |
byteswap = FALSE; |
|
472 |
else if (drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) |
|
473 |
byteswap = TRUE; |
|
474 |
else |
|
475 |
return (EINVAL); |
|
476 |
||
477 |
rbsa.tofs = tofs; |
|
478 |
rbsa.tosnap = tosnap; |
|
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
479 |
rbsa.origin = origin ? origin->os_dsl_dataset : NULL; |
5367 | 480 |
rbsa.fromguid = drrb->drr_fromguid; |
481 |
rbsa.type = drrb->drr_type; |
|
482 |
rbsa.tag = FTAG; |
|
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6479
diff
changeset
|
483 |
rbsa.dsflags = 0; |
5367 | 484 |
version = drrb->drr_version; |
485 |
flags = drrb->drr_flags; |
|
486 |
||
487 |
if (byteswap) { |
|
488 |
rbsa.type = BSWAP_32(rbsa.type); |
|
489 |
rbsa.fromguid = BSWAP_64(rbsa.fromguid); |
|
490 |
version = BSWAP_64(version); |
|
491 |
flags = BSWAP_32(flags); |
|
492 |
} |
|
493 |
||
494 |
if (version != DMU_BACKUP_STREAM_VERSION || |
|
495 |
rbsa.type >= DMU_OST_NUMTYPES || |
|
496 |
((flags & DRR_FLAG_CLONE) && origin == NULL)) |
|
497 |
return (EINVAL); |
|
498 |
||
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6479
diff
changeset
|
499 |
if (flags & DRR_FLAG_CI_DATA) |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6479
diff
changeset
|
500 |
rbsa.dsflags = DS_FLAG_CI_DATASET; |
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6479
diff
changeset
|
501 |
|
5367 | 502 |
bzero(drc, sizeof (dmu_recv_cookie_t)); |
503 |
drc->drc_drrb = drrb; |
|
504 |
drc->drc_tosnap = tosnap; |
|
505 |
drc->drc_force = force; |
|
506 |
||
507 |
/* |
|
508 |
* Process the begin in syncing context. |
|
509 |
*/ |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
510 |
|
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
511 |
/* open the dataset we are logically receiving into */ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
512 |
err = dsl_dataset_hold(tofs, dmu_recv_tag, &ds); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
513 |
if (err == 0) { |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
514 |
/* target fs already exists; recv into temp clone */ |
5367 | 515 |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
516 |
/* Can't recv a clone into an existing fs */ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
517 |
if (flags & DRR_FLAG_CLONE) { |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
518 |
dsl_dataset_rele(ds, dmu_recv_tag); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
519 |
return (EINVAL); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
520 |
} |
2743 | 521 |
|
10204
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
522 |
/* must not have an incremental recv already in progress */ |
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
523 |
if (!mutex_tryenter(&ds->ds_recvlock)) { |
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
524 |
dsl_dataset_rele(ds, dmu_recv_tag); |
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
525 |
return (EBUSY); |
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
526 |
} |
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
527 |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
528 |
/* tmp clone name is: tofs/%tosnap" */ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
529 |
(void) snprintf(rbsa.clonelastname, sizeof (rbsa.clonelastname), |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
530 |
"%%%s", tosnap); |
5367 | 531 |
rbsa.force = force; |
532 |
err = dsl_sync_task_do(ds->ds_dir->dd_pool, |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
533 |
recv_existing_check, recv_existing_sync, ds, &rbsa, 5); |
5367 | 534 |
if (err) { |
10204
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
535 |
mutex_exit(&ds->ds_recvlock); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
536 |
dsl_dataset_rele(ds, dmu_recv_tag); |
5367 | 537 |
return (err); |
538 |
} |
|
539 |
drc->drc_logical_ds = ds; |
|
540 |
drc->drc_real_ds = rbsa.ds; |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
541 |
} else if (err == ENOENT) { |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
542 |
/* target fs does not exist; must be a full backup or clone */ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
543 |
dsl_dataset_t *parent; |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
544 |
char *cp; |
5367 | 545 |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
546 |
/* |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
547 |
* If it's a non-clone incremental, we are missing the |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
548 |
* target fs, so fail the recv. |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
549 |
*/ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
550 |
if (rbsa.fromguid && !(flags & DRR_FLAG_CLONE)) |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
551 |
return (ENOENT); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
552 |
|
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
553 |
/* Open the parent of tofs */ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
554 |
cp = strrchr(tofs, '/'); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
555 |
*cp = '\0'; |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
556 |
err = dsl_dataset_hold(tofs, FTAG, &parent); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
557 |
*cp = '/'; |
5367 | 558 |
if (err) |
559 |
return (err); |
|
560 |
||
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
561 |
err = dsl_sync_task_do(ds->ds_dir->dd_pool, |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
562 |
recv_new_check, recv_new_sync, ds->ds_dir, &rbsa, 5); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
563 |
dsl_dataset_rele(parent, FTAG); |
5367 | 564 |
if (err) |
565 |
return (err); |
|
566 |
drc->drc_logical_ds = drc->drc_real_ds = rbsa.ds; |
|
567 |
drc->drc_newfs = B_TRUE; |
|
568 |
} |
|
569 |
||
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
570 |
return (err); |
2743 | 571 |
} |
572 |
||
5367 | 573 |
struct restorearg { |
574 |
int err; |
|
575 |
int byteswap; |
|
576 |
vnode_t *vp; |
|
577 |
char *buf; |
|
578 |
uint64_t voff; |
|
579 |
int bufsize; /* amount of memory allocated for buf */ |
|
580 |
zio_cksum_t cksum; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
581 |
}; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
582 |
|
2743 | 583 |
static void * |
584 |
restore_read(struct restorearg *ra, int len) |
|
585 |
{ |
|
586 |
void *rv; |
|
5367 | 587 |
int done = 0; |
2743 | 588 |
|
589 |
/* some things will require 8-byte alignment, so everything must */ |
|
590 |
ASSERT3U(len % 8, ==, 0); |
|
591 |
||
5367 | 592 |
while (done < len) { |
2743 | 593 |
ssize_t resid; |
594 |
||
595 |
ra->err = vn_rdwr(UIO_READ, ra->vp, |
|
5367 | 596 |
(caddr_t)ra->buf + done, len - done, |
2743 | 597 |
ra->voff, UIO_SYSSPACE, FAPPEND, |
598 |
RLIM64_INFINITY, CRED(), &resid); |
|
599 |
||
5367 | 600 |
if (resid == len - done) |
2743 | 601 |
ra->err = EINVAL; |
5367 | 602 |
ra->voff += len - done - resid; |
603 |
done = len - resid; |
|
2743 | 604 |
if (ra->err) |
605 |
return (NULL); |
|
606 |
} |
|
607 |
||
5367 | 608 |
ASSERT3U(done, ==, len); |
609 |
rv = ra->buf; |
|
2743 | 610 |
if (ra->byteswap) |
5367 | 611 |
fletcher_4_incremental_byteswap(rv, len, &ra->cksum); |
2743 | 612 |
else |
5367 | 613 |
fletcher_4_incremental_native(rv, len, &ra->cksum); |
2743 | 614 |
return (rv); |
615 |
} |
|
616 |
||
617 |
static void |
|
618 |
backup_byteswap(dmu_replay_record_t *drr) |
|
619 |
{ |
|
620 |
#define DO64(X) (drr->drr_u.X = BSWAP_64(drr->drr_u.X)) |
|
621 |
#define DO32(X) (drr->drr_u.X = BSWAP_32(drr->drr_u.X)) |
|
622 |
drr->drr_type = BSWAP_32(drr->drr_type); |
|
5367 | 623 |
drr->drr_payloadlen = BSWAP_32(drr->drr_payloadlen); |
2743 | 624 |
switch (drr->drr_type) { |
625 |
case DRR_BEGIN: |
|
626 |
DO64(drr_begin.drr_magic); |
|
627 |
DO64(drr_begin.drr_version); |
|
628 |
DO64(drr_begin.drr_creation_time); |
|
629 |
DO32(drr_begin.drr_type); |
|
5367 | 630 |
DO32(drr_begin.drr_flags); |
2743 | 631 |
DO64(drr_begin.drr_toguid); |
632 |
DO64(drr_begin.drr_fromguid); |
|
633 |
break; |
|
634 |
case DRR_OBJECT: |
|
635 |
DO64(drr_object.drr_object); |
|
636 |
/* DO64(drr_object.drr_allocation_txg); */ |
|
637 |
DO32(drr_object.drr_type); |
|
638 |
DO32(drr_object.drr_bonustype); |
|
639 |
DO32(drr_object.drr_blksz); |
|
640 |
DO32(drr_object.drr_bonuslen); |
|
641 |
break; |
|
642 |
case DRR_FREEOBJECTS: |
|
643 |
DO64(drr_freeobjects.drr_firstobj); |
|
644 |
DO64(drr_freeobjects.drr_numobjs); |
|
645 |
break; |
|
646 |
case DRR_WRITE: |
|
647 |
DO64(drr_write.drr_object); |
|
648 |
DO32(drr_write.drr_type); |
|
649 |
DO64(drr_write.drr_offset); |
|
650 |
DO64(drr_write.drr_length); |
|
651 |
break; |
|
652 |
case DRR_FREE: |
|
653 |
DO64(drr_free.drr_object); |
|
654 |
DO64(drr_free.drr_offset); |
|
655 |
DO64(drr_free.drr_length); |
|
656 |
break; |
|
657 |
case DRR_END: |
|
658 |
DO64(drr_end.drr_checksum.zc_word[0]); |
|
659 |
DO64(drr_end.drr_checksum.zc_word[1]); |
|
660 |
DO64(drr_end.drr_checksum.zc_word[2]); |
|
661 |
DO64(drr_end.drr_checksum.zc_word[3]); |
|
662 |
break; |
|
663 |
} |
|
664 |
#undef DO64 |
|
665 |
#undef DO32 |
|
666 |
} |
|
667 |
||
668 |
static int |
|
669 |
restore_object(struct restorearg *ra, objset_t *os, struct drr_object *drro) |
|
670 |
{ |
|
671 |
int err; |
|
672 |
dmu_tx_t *tx; |
|
7994
7a573dc88b73
6764159 restore_object() makes a call that can block while having a tx open but not yet committed
Tim Haley <Tim.Haley@Sun.COM>
parents:
7837
diff
changeset
|
673 |
void *data = NULL; |
2743 | 674 |
|
675 |
if (drro->drr_type == DMU_OT_NONE || |
|
676 |
drro->drr_type >= DMU_OT_NUMTYPES || |
|
677 |
drro->drr_bonustype >= DMU_OT_NUMTYPES || |
|
678 |
drro->drr_checksum >= ZIO_CHECKSUM_FUNCTIONS || |
|
679 |
drro->drr_compress >= ZIO_COMPRESS_FUNCTIONS || |
|
680 |
P2PHASE(drro->drr_blksz, SPA_MINBLOCKSIZE) || |
|
681 |
drro->drr_blksz < SPA_MINBLOCKSIZE || |
|
682 |
drro->drr_blksz > SPA_MAXBLOCKSIZE || |
|
683 |
drro->drr_bonuslen > DN_MAX_BONUSLEN) { |
|
684 |
return (EINVAL); |
|
685 |
} |
|
686 |
||
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
687 |
err = dmu_object_info(os, drro->drr_object, NULL); |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
688 |
|
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
689 |
if (err != 0 && err != ENOENT) |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
690 |
return (EINVAL); |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
691 |
|
7994
7a573dc88b73
6764159 restore_object() makes a call that can block while having a tx open but not yet committed
Tim Haley <Tim.Haley@Sun.COM>
parents:
7837
diff
changeset
|
692 |
if (drro->drr_bonuslen) { |
7a573dc88b73
6764159 restore_object() makes a call that can block while having a tx open but not yet committed
Tim Haley <Tim.Haley@Sun.COM>
parents:
7837
diff
changeset
|
693 |
data = restore_read(ra, P2ROUNDUP(drro->drr_bonuslen, 8)); |
7a573dc88b73
6764159 restore_object() makes a call that can block while having a tx open but not yet committed
Tim Haley <Tim.Haley@Sun.COM>
parents:
7837
diff
changeset
|
694 |
if (ra->err) |
7a573dc88b73
6764159 restore_object() makes a call that can block while having a tx open but not yet committed
Tim Haley <Tim.Haley@Sun.COM>
parents:
7837
diff
changeset
|
695 |
return (ra->err); |
7a573dc88b73
6764159 restore_object() makes a call that can block while having a tx open but not yet committed
Tim Haley <Tim.Haley@Sun.COM>
parents:
7837
diff
changeset
|
696 |
} |
7a573dc88b73
6764159 restore_object() makes a call that can block while having a tx open but not yet committed
Tim Haley <Tim.Haley@Sun.COM>
parents:
7837
diff
changeset
|
697 |
|
2743 | 698 |
if (err == ENOENT) { |
699 |
/* currently free, want to be allocated */ |
|
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
700 |
tx = dmu_tx_create(os); |
2743 | 701 |
dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT); |
702 |
err = dmu_tx_assign(tx, TXG_WAIT); |
|
703 |
if (err) { |
|
704 |
dmu_tx_abort(tx); |
|
705 |
return (err); |
|
706 |
} |
|
707 |
err = dmu_object_claim(os, drro->drr_object, |
|
708 |
drro->drr_type, drro->drr_blksz, |
|
709 |
drro->drr_bonustype, drro->drr_bonuslen, tx); |
|
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
710 |
dmu_tx_commit(tx); |
2743 | 711 |
} else { |
712 |
/* currently allocated, want to be allocated */ |
|
713 |
err = dmu_object_reclaim(os, drro->drr_object, |
|
714 |
drro->drr_type, drro->drr_blksz, |
|
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
715 |
drro->drr_bonustype, drro->drr_bonuslen); |
2743 | 716 |
} |
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
717 |
if (err) |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
718 |
return (EINVAL); |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
719 |
|
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
720 |
tx = dmu_tx_create(os); |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
721 |
dmu_tx_hold_bonus(tx, drro->drr_object); |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
722 |
err = dmu_tx_assign(tx, TXG_WAIT); |
2743 | 723 |
if (err) { |
8986
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
724 |
dmu_tx_abort(tx); |
45c289aff7c9
6801979 zfs recv can fail with E2BIG
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
8644
diff
changeset
|
725 |
return (err); |
2743 | 726 |
} |
727 |
||
728 |
dmu_object_set_checksum(os, drro->drr_object, drro->drr_checksum, tx); |
|
729 |
dmu_object_set_compress(os, drro->drr_object, drro->drr_compress, tx); |
|
730 |
||
7994
7a573dc88b73
6764159 restore_object() makes a call that can block while having a tx open but not yet committed
Tim Haley <Tim.Haley@Sun.COM>
parents:
7837
diff
changeset
|
731 |
if (data != NULL) { |
2743 | 732 |
dmu_buf_t *db; |
7994
7a573dc88b73
6764159 restore_object() makes a call that can block while having a tx open but not yet committed
Tim Haley <Tim.Haley@Sun.COM>
parents:
7837
diff
changeset
|
733 |
|
2743 | 734 |
VERIFY(0 == dmu_bonus_hold(os, drro->drr_object, FTAG, &db)); |
735 |
dmu_buf_will_dirty(db, tx); |
|
736 |
||
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4543
diff
changeset
|
737 |
ASSERT3U(db->db_size, >=, drro->drr_bonuslen); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4543
diff
changeset
|
738 |
bcopy(data, db->db_data, drro->drr_bonuslen); |
2743 | 739 |
if (ra->byteswap) { |
740 |
dmu_ot[drro->drr_bonustype].ot_byteswap(db->db_data, |
|
741 |
drro->drr_bonuslen); |
|
742 |
} |
|
743 |
dmu_buf_rele(db, FTAG); |
|
744 |
} |
|
745 |
dmu_tx_commit(tx); |
|
746 |
return (0); |
|
747 |
} |
|
748 |
||
749 |
/* ARGSUSED */ |
|
750 |
static int |
|
751 |
restore_freeobjects(struct restorearg *ra, objset_t *os, |
|
752 |
struct drr_freeobjects *drrfo) |
|
753 |
{ |
|
754 |
uint64_t obj; |
|
755 |
||
756 |
if (drrfo->drr_firstobj + drrfo->drr_numobjs < drrfo->drr_firstobj) |
|
757 |
return (EINVAL); |
|
758 |
||
759 |
for (obj = drrfo->drr_firstobj; |
|
3087 | 760 |
obj < drrfo->drr_firstobj + drrfo->drr_numobjs; |
761 |
(void) dmu_object_next(os, &obj, FALSE, 0)) { |
|
2743 | 762 |
int err; |
763 |
||
764 |
if (dmu_object_info(os, obj, NULL) != 0) |
|
765 |
continue; |
|
766 |
||
6992 | 767 |
err = dmu_free_object(os, obj); |
768 |
if (err) |
|
2743 | 769 |
return (err); |
770 |
} |
|
771 |
return (0); |
|
772 |
} |
|
773 |
||
774 |
static int |
|
775 |
restore_write(struct restorearg *ra, objset_t *os, |
|
776 |
struct drr_write *drrw) |
|
777 |
{ |
|
778 |
dmu_tx_t *tx; |
|
779 |
void *data; |
|
780 |
int err; |
|
781 |
||
782 |
if (drrw->drr_offset + drrw->drr_length < drrw->drr_offset || |
|
783 |
drrw->drr_type >= DMU_OT_NUMTYPES) |
|
784 |
return (EINVAL); |
|
785 |
||
786 |
data = restore_read(ra, drrw->drr_length); |
|
787 |
if (data == NULL) |
|
788 |
return (ra->err); |
|
789 |
||
790 |
if (dmu_object_info(os, drrw->drr_object, NULL) != 0) |
|
791 |
return (EINVAL); |
|
792 |
||
793 |
tx = dmu_tx_create(os); |
|
794 |
||
795 |
dmu_tx_hold_write(tx, drrw->drr_object, |
|
796 |
drrw->drr_offset, drrw->drr_length); |
|
797 |
err = dmu_tx_assign(tx, TXG_WAIT); |
|
798 |
if (err) { |
|
799 |
dmu_tx_abort(tx); |
|
800 |
return (err); |
|
801 |
} |
|
802 |
if (ra->byteswap) |
|
803 |
dmu_ot[drrw->drr_type].ot_byteswap(data, drrw->drr_length); |
|
804 |
dmu_write(os, drrw->drr_object, |
|
805 |
drrw->drr_offset, drrw->drr_length, data, tx); |
|
806 |
dmu_tx_commit(tx); |
|
807 |
return (0); |
|
808 |
} |
|
809 |
||
810 |
/* ARGSUSED */ |
|
811 |
static int |
|
812 |
restore_free(struct restorearg *ra, objset_t *os, |
|
813 |
struct drr_free *drrf) |
|
814 |
{ |
|
815 |
int err; |
|
816 |
||
817 |
if (drrf->drr_length != -1ULL && |
|
818 |
drrf->drr_offset + drrf->drr_length < drrf->drr_offset) |
|
819 |
return (EINVAL); |
|
820 |
||
821 |
if (dmu_object_info(os, drrf->drr_object, NULL) != 0) |
|
822 |
return (EINVAL); |
|
823 |
||
6992 | 824 |
err = dmu_free_long_range(os, drrf->drr_object, |
2743 | 825 |
drrf->drr_offset, drrf->drr_length); |
826 |
return (err); |
|
827 |
} |
|
828 |
||
5367 | 829 |
/* |
830 |
* NB: callers *must* call dmu_recv_end() if this succeeds. |
|
831 |
*/ |
|
832 |
int |
|
833 |
dmu_recv_stream(dmu_recv_cookie_t *drc, vnode_t *vp, offset_t *voffp) |
|
834 |
{ |
|
835 |
struct restorearg ra = { 0 }; |
|
836 |
dmu_replay_record_t *drr; |
|
837 |
objset_t *os; |
|
838 |
zio_cksum_t pcksum; |
|
839 |
||
840 |
if (drc->drc_drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) |
|
841 |
ra.byteswap = TRUE; |
|
2743 | 842 |
|
5367 | 843 |
{ |
844 |
/* compute checksum of drr_begin record */ |
|
845 |
dmu_replay_record_t *drr; |
|
846 |
drr = kmem_zalloc(sizeof (dmu_replay_record_t), KM_SLEEP); |
|
847 |
||
848 |
drr->drr_type = DRR_BEGIN; |
|
849 |
drr->drr_u.drr_begin = *drc->drc_drrb; |
|
850 |
if (ra.byteswap) { |
|
851 |
fletcher_4_incremental_byteswap(drr, |
|
852 |
sizeof (dmu_replay_record_t), &ra.cksum); |
|
853 |
} else { |
|
854 |
fletcher_4_incremental_native(drr, |
|
855 |
sizeof (dmu_replay_record_t), &ra.cksum); |
|
856 |
} |
|
857 |
kmem_free(drr, sizeof (dmu_replay_record_t)); |
|
2743 | 858 |
} |
859 |
||
860 |
if (ra.byteswap) { |
|
5367 | 861 |
struct drr_begin *drrb = drc->drc_drrb; |
2743 | 862 |
drrb->drr_magic = BSWAP_64(drrb->drr_magic); |
863 |
drrb->drr_version = BSWAP_64(drrb->drr_version); |
|
864 |
drrb->drr_creation_time = BSWAP_64(drrb->drr_creation_time); |
|
865 |
drrb->drr_type = BSWAP_32(drrb->drr_type); |
|
866 |
drrb->drr_toguid = BSWAP_64(drrb->drr_toguid); |
|
867 |
drrb->drr_fromguid = BSWAP_64(drrb->drr_fromguid); |
|
868 |
} |
|
869 |
||
5367 | 870 |
ra.vp = vp; |
871 |
ra.voff = *voffp; |
|
872 |
ra.bufsize = 1<<20; |
|
873 |
ra.buf = kmem_alloc(ra.bufsize, KM_SLEEP); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
874 |
|
5367 | 875 |
/* these were verified in dmu_recv_begin */ |
876 |
ASSERT(drc->drc_drrb->drr_version == DMU_BACKUP_STREAM_VERSION); |
|
877 |
ASSERT(drc->drc_drrb->drr_type < DMU_OST_NUMTYPES); |
|
2743 | 878 |
|
879 |
/* |
|
880 |
* Open the objset we are modifying. |
|
881 |
*/ |
|
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
882 |
VERIFY(dmu_objset_from_ds(drc->drc_real_ds, &os) == 0); |
2743 | 883 |
|
5367 | 884 |
ASSERT(drc->drc_real_ds->ds_phys->ds_flags & DS_FLAG_INCONSISTENT); |
2743 | 885 |
|
886 |
/* |
|
887 |
* Read records and process them. |
|
888 |
*/ |
|
5367 | 889 |
pcksum = ra.cksum; |
2743 | 890 |
while (ra.err == 0 && |
891 |
NULL != (drr = restore_read(&ra, sizeof (*drr)))) { |
|
892 |
if (issig(JUSTLOOKING) && issig(FORREAL)) { |
|
893 |
ra.err = EINTR; |
|
894 |
goto out; |
|
895 |
} |
|
896 |
||
897 |
if (ra.byteswap) |
|
898 |
backup_byteswap(drr); |
|
899 |
||
900 |
switch (drr->drr_type) { |
|
901 |
case DRR_OBJECT: |
|
902 |
{ |
|
903 |
/* |
|
904 |
* We need to make a copy of the record header, |
|
905 |
* because restore_{object,write} may need to |
|
906 |
* restore_read(), which will invalidate drr. |
|
907 |
*/ |
|
908 |
struct drr_object drro = drr->drr_u.drr_object; |
|
909 |
ra.err = restore_object(&ra, os, &drro); |
|
910 |
break; |
|
911 |
} |
|
912 |
case DRR_FREEOBJECTS: |
|
913 |
{ |
|
914 |
struct drr_freeobjects drrfo = |
|
915 |
drr->drr_u.drr_freeobjects; |
|
916 |
ra.err = restore_freeobjects(&ra, os, &drrfo); |
|
917 |
break; |
|
918 |
} |
|
919 |
case DRR_WRITE: |
|
920 |
{ |
|
921 |
struct drr_write drrw = drr->drr_u.drr_write; |
|
922 |
ra.err = restore_write(&ra, os, &drrw); |
|
923 |
break; |
|
924 |
} |
|
925 |
case DRR_FREE: |
|
926 |
{ |
|
927 |
struct drr_free drrf = drr->drr_u.drr_free; |
|
928 |
ra.err = restore_free(&ra, os, &drrf); |
|
929 |
break; |
|
930 |
} |
|
931 |
case DRR_END: |
|
932 |
{ |
|
933 |
struct drr_end drre = drr->drr_u.drr_end; |
|
934 |
/* |
|
935 |
* We compare against the *previous* checksum |
|
936 |
* value, because the stored checksum is of |
|
937 |
* everything before the DRR_END record. |
|
938 |
*/ |
|
6479 | 939 |
if (!ZIO_CHECKSUM_EQUAL(drre.drr_checksum, pcksum)) |
2743 | 940 |
ra.err = ECKSUM; |
941 |
goto out; |
|
942 |
} |
|
943 |
default: |
|
944 |
ra.err = EINVAL; |
|
945 |
goto out; |
|
946 |
} |
|
5367 | 947 |
pcksum = ra.cksum; |
2743 | 948 |
} |
6479 | 949 |
ASSERT(ra.err != 0); |
2743 | 950 |
|
951 |
out: |
|
5367 | 952 |
if (ra.err != 0) { |
2743 | 953 |
/* |
10204
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
954 |
* destroy what we created, so we don't leave it in the |
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
955 |
* inconsistent restoring state. |
2743 | 956 |
*/ |
5367 | 957 |
txg_wait_synced(drc->drc_real_ds->ds_dir->dd_pool, 0); |
10204
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
958 |
|
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10204
diff
changeset
|
959 |
(void) dsl_dataset_destroy(drc->drc_real_ds, dmu_recv_tag, |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10204
diff
changeset
|
960 |
B_FALSE); |
10204
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
961 |
if (drc->drc_real_ds != drc->drc_logical_ds) { |
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
962 |
mutex_exit(&drc->drc_logical_ds->ds_recvlock); |
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
963 |
dsl_dataset_rele(drc->drc_logical_ds, dmu_recv_tag); |
83c3a84aecef
6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
964 |
} |
2743 | 965 |
} |
966 |
||
967 |
kmem_free(ra.buf, ra.bufsize); |
|
5367 | 968 |
*voffp = ra.voff; |
2743 | 969 |
return (ra.err); |
970 |
} |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
971 |
|
5367 | 972 |
struct recvendsyncarg { |
973 |
char *tosnap; |
|
974 |
uint64_t creation_time; |
|
975 |
uint64_t toguid; |
|
976 |
}; |
|
977 |
||
978 |
static int |
|
979 |
recv_end_check(void *arg1, void *arg2, dmu_tx_t *tx) |
|
980 |
{ |
|
981 |
dsl_dataset_t *ds = arg1; |
|
982 |
struct recvendsyncarg *resa = arg2; |
|
983 |
||
984 |
return (dsl_dataset_snapshot_check(ds, resa->tosnap, tx)); |
|
985 |
} |
|
986 |
||
987 |
static void |
|
988 |
recv_end_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
989 |
{ |
5367 | 990 |
dsl_dataset_t *ds = arg1; |
991 |
struct recvendsyncarg *resa = arg2; |
|
992 |
||
993 |
dsl_dataset_snapshot_sync(ds, resa->tosnap, cr, tx); |
|
994 |
||
995 |
/* set snapshot's creation time and guid */ |
|
996 |
dmu_buf_will_dirty(ds->ds_prev->ds_dbuf, tx); |
|
997 |
ds->ds_prev->ds_phys->ds_creation_time = resa->creation_time; |
|
998 |
ds->ds_prev->ds_phys->ds_guid = resa->toguid; |
|
999 |
ds->ds_prev->ds_phys->ds_flags &= ~DS_FLAG_INCONSISTENT; |
|
1000 |
||
1001 |
dmu_buf_will_dirty(ds->ds_dbuf, tx); |
|
1002 |
ds->ds_phys->ds_flags &= ~DS_FLAG_INCONSISTENT; |
|
1003 |
} |
|
1004 |
||
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1005 |
static int |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1006 |
dmu_recv_existing_end(dmu_recv_cookie_t *drc) |
5367 | 1007 |
{ |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1008 |
struct recvendsyncarg resa; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1009 |
dsl_dataset_t *ds = drc->drc_logical_ds; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1010 |
int err; |
5367 | 1011 |
|
1012 |
/* |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1013 |
* XXX hack; seems the ds is still dirty and dsl_pool_zil_clean() |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1014 |
* expects it to have a ds_user_ptr (and zil), but clone_swap() |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1015 |
* can close it. |
5367 | 1016 |
*/ |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1017 |
txg_wait_synced(ds->ds_dir->dd_pool, 0); |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
1018 |
|
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1019 |
if (dsl_dataset_tryown(ds, FALSE, dmu_recv_tag)) { |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1020 |
err = dsl_dataset_clone_swap(drc->drc_real_ds, ds, |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1021 |
drc->drc_force); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1022 |
if (err) |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1023 |
goto out; |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1024 |
} else { |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1025 |
mutex_exit(&ds->ds_recvlock); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1026 |
dsl_dataset_rele(ds, dmu_recv_tag); |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10204
diff
changeset
|
1027 |
(void) dsl_dataset_destroy(drc->drc_real_ds, dmu_recv_tag, |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10204
diff
changeset
|
1028 |
B_FALSE); |
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1029 |
return (EBUSY); |
5367 | 1030 |
} |
1031 |
||
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1032 |
resa.creation_time = drc->drc_drrb->drr_creation_time; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1033 |
resa.toguid = drc->drc_drrb->drr_toguid; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1034 |
resa.tosnap = drc->drc_tosnap; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1035 |
|
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1036 |
err = dsl_sync_task_do(ds->ds_dir->dd_pool, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1037 |
recv_end_check, recv_end_sync, ds, &resa, 3); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1038 |
if (err) { |
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1039 |
/* swap back */ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1040 |
(void) dsl_dataset_clone_swap(drc->drc_real_ds, ds, B_TRUE); |
5367 | 1041 |
} |
1042 |
||
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1043 |
out: |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1044 |
mutex_exit(&ds->ds_recvlock); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1045 |
dsl_dataset_disown(ds, dmu_recv_tag); |
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1046 |
(void) dsl_dataset_destroy(drc->drc_real_ds, dmu_recv_tag, B_FALSE); |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
1047 |
return (err); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
1048 |
} |
10272
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1049 |
|
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1050 |
static int |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1051 |
dmu_recv_new_end(dmu_recv_cookie_t *drc) |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1052 |
{ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1053 |
struct recvendsyncarg resa; |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1054 |
dsl_dataset_t *ds = drc->drc_logical_ds; |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1055 |
int err; |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1056 |
|
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1057 |
/* |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1058 |
* XXX hack; seems the ds is still dirty and dsl_pool_zil_clean() |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1059 |
* expects it to have a ds_user_ptr (and zil), but clone_swap() |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1060 |
* can close it. |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1061 |
*/ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1062 |
txg_wait_synced(ds->ds_dir->dd_pool, 0); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1063 |
|
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1064 |
resa.creation_time = drc->drc_drrb->drr_creation_time; |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1065 |
resa.toguid = drc->drc_drrb->drr_toguid; |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1066 |
resa.tosnap = drc->drc_tosnap; |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1067 |
|
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1068 |
err = dsl_sync_task_do(ds->ds_dir->dd_pool, |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1069 |
recv_end_check, recv_end_sync, ds, &resa, 3); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1070 |
if (err) { |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1071 |
/* clean up the fs we just recv'd into */ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1072 |
(void) dsl_dataset_destroy(ds, dmu_recv_tag, B_FALSE); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1073 |
} else { |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1074 |
/* release the hold from dmu_recv_begin */ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1075 |
dsl_dataset_disown(ds, dmu_recv_tag); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1076 |
} |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1077 |
return (err); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1078 |
} |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1079 |
|
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1080 |
int |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1081 |
dmu_recv_end(dmu_recv_cookie_t *drc) |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1082 |
{ |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1083 |
if (drc->drc_logical_ds != drc->drc_real_ds) |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1084 |
return (dmu_recv_existing_end(drc)); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1085 |
else |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1086 |
return (dmu_recv_new_end(drc)); |
a0669934e974
6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10242
diff
changeset
|
1087 |
} |