author | Matthew Ahrens <Matthew.Ahrens@Sun.COM> |
Tue, 14 Oct 2008 15:57:18 -0700 | |
changeset 7837 | 001de5627df3 |
parent 7046 | 361307ae060d |
child 7994 | 7a573dc88b73 |
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 |
/* |
|
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
|
22 |
* Copyright 2008 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 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
164 |
if (bp == NULL && zb->zb_object == 0) { |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
165 |
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
|
166 |
uint64_t dnobj = (zb->zb_blkid * span) >> DNODE_SHIFT; |
2743 | 167 |
err = dump_freeobjects(ba, dnobj, span >> DNODE_SHIFT); |
168 |
} 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
|
169 |
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
|
170 |
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
|
171 |
} 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
|
172 |
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
|
173 |
} 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
|
174 |
dnode_phys_t *blk; |
2743 | 175 |
int i; |
176 |
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
|
177 |
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
|
178 |
arc_buf_t *abuf; |
2743 | 179 |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
185 |
blk = abuf->b_data; |
2743 | 186 |
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
|
187 |
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
|
188 |
(DNODE_BLOCK_SHIFT - DNODE_SHIFT)) + i; |
2743 | 189 |
err = dump_dnode(ba, dnobj, blk+i); |
190 |
if (err) |
|
191 |
break; |
|
192 |
} |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
193 |
(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
|
194 |
} 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
|
195 |
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
|
196 |
arc_buf_t *abuf; |
2743 | 197 |
int blksz = BP_GET_LSIZE(bp); |
198 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
return (EIO); |
2743 | 203 |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
204 |
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
|
205 |
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
|
206 |
(void) arc_buf_remove_ref(abuf, &abuf); |
2743 | 207 |
} |
208 |
||
209 |
ASSERT(err == 0 || err == EINTR); |
|
210 |
return (err); |
|
211 |
} |
|
212 |
||
213 |
int |
|
5367 | 214 |
dmu_sendbackup(objset_t *tosnap, objset_t *fromsnap, boolean_t fromorigin, |
215 |
vnode_t *vp, offset_t *off) |
|
2743 | 216 |
{ |
217 |
dsl_dataset_t *ds = tosnap->os->os_dsl_dataset; |
|
218 |
dsl_dataset_t *fromds = fromsnap ? fromsnap->os->os_dsl_dataset : NULL; |
|
219 |
dmu_replay_record_t *drr; |
|
220 |
struct backuparg ba; |
|
221 |
int err; |
|
5367 | 222 |
uint64_t fromtxg = 0; |
2743 | 223 |
|
224 |
/* tosnap must be a snapshot */ |
|
225 |
if (ds->ds_phys->ds_next_snap_obj == 0) |
|
226 |
return (EINVAL); |
|
227 |
||
228 |
/* fromsnap must be an earlier snapshot from the same fs as tosnap */ |
|
229 |
if (fromds && (ds->ds_dir != fromds->ds_dir || |
|
5367 | 230 |
fromds->ds_phys->ds_creation_txg >= ds->ds_phys->ds_creation_txg)) |
2743 | 231 |
return (EXDEV); |
232 |
||
5367 | 233 |
if (fromorigin) { |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
234 |
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
|
235 |
|
5367 | 236 |
if (fromsnap) |
237 |
return (EINVAL); |
|
238 |
||
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
239 |
if (dsl_dir_is_clone(ds->ds_dir)) { |
5367 | 240 |
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
|
241 |
err = dsl_dataset_hold_obj(dp, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
242 |
ds->ds_dir->dd_phys->dd_origin_obj, FTAG, &fromds); |
5367 | 243 |
rw_exit(&dp->dp_config_rwlock); |
244 |
if (err) |
|
245 |
return (err); |
|
246 |
} else { |
|
247 |
fromorigin = B_FALSE; |
|
248 |
} |
|
249 |
} |
|
250 |
||
251 |
||
2743 | 252 |
drr = kmem_zalloc(sizeof (dmu_replay_record_t), KM_SLEEP); |
253 |
drr->drr_type = DRR_BEGIN; |
|
254 |
drr->drr_u.drr_begin.drr_magic = DMU_BACKUP_MAGIC; |
|
5367 | 255 |
drr->drr_u.drr_begin.drr_version = DMU_BACKUP_STREAM_VERSION; |
2743 | 256 |
drr->drr_u.drr_begin.drr_creation_time = |
257 |
ds->ds_phys->ds_creation_time; |
|
258 |
drr->drr_u.drr_begin.drr_type = tosnap->os->os_phys->os_type; |
|
5367 | 259 |
if (fromorigin) |
260 |
drr->drr_u.drr_begin.drr_flags |= DRR_FLAG_CLONE; |
|
2743 | 261 |
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
|
262 |
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
|
263 |
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
|
264 |
|
2743 | 265 |
if (fromds) |
266 |
drr->drr_u.drr_begin.drr_fromguid = fromds->ds_phys->ds_guid; |
|
267 |
dsl_dataset_name(ds, drr->drr_u.drr_begin.drr_toname); |
|
268 |
||
5367 | 269 |
if (fromds) |
270 |
fromtxg = fromds->ds_phys->ds_creation_txg; |
|
271 |
if (fromorigin) |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
272 |
dsl_dataset_rele(fromds, FTAG); |
5367 | 273 |
|
2743 | 274 |
ba.drr = drr; |
275 |
ba.vp = vp; |
|
276 |
ba.os = tosnap; |
|
5367 | 277 |
ba.off = off; |
2743 | 278 |
ZIO_SET_CHECKSUM(&ba.zc, 0, 0, 0, 0); |
279 |
||
280 |
if (dump_bytes(&ba, drr, sizeof (dmu_replay_record_t))) { |
|
281 |
kmem_free(drr, sizeof (dmu_replay_record_t)); |
|
282 |
return (ba.err); |
|
283 |
} |
|
284 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
285 |
err = traverse_dataset(ds, fromtxg, TRAVERSE_PRE | TRAVERSE_PREFETCH, |
2743 | 286 |
backup_cb, &ba); |
287 |
||
288 |
if (err) { |
|
289 |
if (err == EINTR && ba.err) |
|
290 |
err = ba.err; |
|
3655 | 291 |
kmem_free(drr, sizeof (dmu_replay_record_t)); |
2743 | 292 |
return (err); |
293 |
} |
|
294 |
||
295 |
bzero(drr, sizeof (dmu_replay_record_t)); |
|
296 |
drr->drr_type = DRR_END; |
|
297 |
drr->drr_u.drr_end.drr_checksum = ba.zc; |
|
298 |
||
3655 | 299 |
if (dump_bytes(&ba, drr, sizeof (dmu_replay_record_t))) { |
300 |
kmem_free(drr, sizeof (dmu_replay_record_t)); |
|
2743 | 301 |
return (ba.err); |
3655 | 302 |
} |
2743 | 303 |
|
304 |
kmem_free(drr, sizeof (dmu_replay_record_t)); |
|
305 |
||
306 |
return (0); |
|
307 |
} |
|
308 |
||
5367 | 309 |
struct recvbeginsyncarg { |
310 |
const char *tofs; |
|
311 |
const char *tosnap; |
|
312 |
dsl_dataset_t *origin; |
|
313 |
uint64_t fromguid; |
|
314 |
dmu_objset_type_t type; |
|
315 |
void *tag; |
|
316 |
boolean_t force; |
|
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6479
diff
changeset
|
317 |
uint64_t dsflags; |
5367 | 318 |
char clonelastname[MAXNAMELEN]; |
319 |
dsl_dataset_t *ds; /* the ds to recv into; returned from the syncfunc */ |
|
2743 | 320 |
}; |
321 |
||
5367 | 322 |
static dsl_dataset_t * |
323 |
recv_full_sync_impl(dsl_pool_t *dp, uint64_t dsobj, dmu_objset_type_t type, |
|
324 |
cred_t *cr, dmu_tx_t *tx) |
|
325 |
{ |
|
326 |
dsl_dataset_t *ds; |
|
327 |
||
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
328 |
/* This should always work, since we just created it */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
329 |
/* XXX - create should return an owned ds */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
330 |
VERIFY(0 == dsl_dataset_own_obj(dp, dsobj, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
331 |
DS_MODE_INCONSISTENT, dmu_recv_tag, &ds)); |
5367 | 332 |
|
333 |
if (type != DMU_OST_NONE) { |
|
334 |
(void) dmu_objset_create_impl(dp->dp_spa, |
|
335 |
ds, &ds->ds_phys->ds_bp, type, tx); |
|
336 |
} |
|
337 |
||
338 |
spa_history_internal_log(LOG_DS_REPLAY_FULL_SYNC, |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
339 |
dp->dp_spa, tx, cr, "dataset = %lld", dsobj); |
5367 | 340 |
|
341 |
return (ds); |
|
342 |
} |
|
343 |
||
344 |
/* ARGSUSED */ |
|
2743 | 345 |
static int |
5367 | 346 |
recv_full_check(void *arg1, void *arg2, dmu_tx_t *tx) |
347 |
{ |
|
348 |
dsl_dir_t *dd = arg1; |
|
349 |
struct recvbeginsyncarg *rbsa = arg2; |
|
350 |
objset_t *mos = dd->dd_pool->dp_meta_objset; |
|
351 |
uint64_t val; |
|
352 |
int err; |
|
353 |
||
354 |
err = zap_lookup(mos, dd->dd_phys->dd_child_dir_zapobj, |
|
355 |
strrchr(rbsa->tofs, '/') + 1, sizeof (uint64_t), 1, &val); |
|
356 |
||
357 |
if (err != ENOENT) |
|
358 |
return (err ? err : EEXIST); |
|
359 |
||
360 |
if (rbsa->origin) { |
|
361 |
/* make sure it's a snap in the same pool */ |
|
362 |
if (rbsa->origin->ds_dir->dd_pool != dd->dd_pool) |
|
363 |
return (EXDEV); |
|
364 |
if (rbsa->origin->ds_phys->ds_num_children == 0) |
|
365 |
return (EINVAL); |
|
366 |
if (rbsa->origin->ds_phys->ds_guid != rbsa->fromguid) |
|
367 |
return (ENODEV); |
|
368 |
} |
|
369 |
||
370 |
return (0); |
|
371 |
} |
|
372 |
||
373 |
static void |
|
374 |
recv_full_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
|
375 |
{ |
|
376 |
dsl_dir_t *dd = arg1; |
|
377 |
struct recvbeginsyncarg *rbsa = arg2; |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
378 |
uint64_t flags = DS_FLAG_INCONSISTENT | rbsa->dsflags; |
5367 | 379 |
uint64_t dsobj; |
380 |
||
381 |
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
|
382 |
rbsa->origin, flags, cr, tx); |
5367 | 383 |
|
384 |
rbsa->ds = recv_full_sync_impl(dd->dd_pool, dsobj, |
|
385 |
rbsa->origin ? DMU_OST_NONE : rbsa->type, cr, tx); |
|
386 |
} |
|
387 |
||
388 |
static int |
|
389 |
recv_full_existing_check(void *arg1, void *arg2, dmu_tx_t *tx) |
|
2743 | 390 |
{ |
5367 | 391 |
dsl_dataset_t *ds = arg1; |
392 |
struct recvbeginsyncarg *rbsa = arg2; |
|
393 |
int err; |
|
394 |
||
395 |
/* must be a head ds */ |
|
396 |
if (ds->ds_phys->ds_next_snap_obj != 0) |
|
397 |
return (EINVAL); |
|
398 |
||
399 |
/* must not be a clone ds */ |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
400 |
if (dsl_dir_is_clone(ds->ds_dir)) |
5367 | 401 |
return (EINVAL); |
402 |
||
403 |
err = dsl_dataset_destroy_check(ds, rbsa->tag, tx); |
|
404 |
if (err) |
|
405 |
return (err); |
|
406 |
||
407 |
if (rbsa->origin) { |
|
408 |
/* make sure it's a snap in the same pool */ |
|
409 |
if (rbsa->origin->ds_dir->dd_pool != ds->ds_dir->dd_pool) |
|
410 |
return (EXDEV); |
|
411 |
if (rbsa->origin->ds_phys->ds_num_children == 0) |
|
412 |
return (EINVAL); |
|
413 |
if (rbsa->origin->ds_phys->ds_guid != rbsa->fromguid) |
|
414 |
return (ENODEV); |
|
415 |
} |
|
416 |
||
417 |
return (0); |
|
418 |
} |
|
419 |
||
420 |
static void |
|
421 |
recv_full_existing_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
|
422 |
{ |
|
423 |
dsl_dataset_t *ds = arg1; |
|
424 |
struct recvbeginsyncarg *rbsa = arg2; |
|
425 |
dsl_dir_t *dd = ds->ds_dir; |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
426 |
uint64_t flags = DS_FLAG_INCONSISTENT | rbsa->dsflags; |
5367 | 427 |
uint64_t dsobj; |
428 |
||
429 |
/* |
|
430 |
* NB: caller must provide an extra hold on the dsl_dir_t, so it |
|
431 |
* won't go away when dsl_dataset_destroy_sync() closes the |
|
432 |
* dataset. |
|
433 |
*/ |
|
434 |
dsl_dataset_destroy_sync(ds, rbsa->tag, cr, tx); |
|
435 |
||
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6992
diff
changeset
|
436 |
dsobj = dsl_dataset_create_sync_dd(dd, rbsa->origin, flags, tx); |
5367 | 437 |
|
438 |
rbsa->ds = recv_full_sync_impl(dd->dd_pool, dsobj, |
|
439 |
rbsa->origin ? DMU_OST_NONE : rbsa->type, cr, tx); |
|
440 |
} |
|
441 |
||
442 |
/* ARGSUSED */ |
|
443 |
static int |
|
444 |
recv_incremental_check(void *arg1, void *arg2, dmu_tx_t *tx) |
|
445 |
{ |
|
446 |
dsl_dataset_t *ds = arg1; |
|
447 |
struct recvbeginsyncarg *rbsa = arg2; |
|
2743 | 448 |
int err; |
449 |
uint64_t val; |
|
450 |
||
5367 | 451 |
/* must not have any changes since most recent snapshot */ |
452 |
if (!rbsa->force && dsl_dataset_modified_since_lastsnap(ds)) |
|
453 |
return (ETXTBSY); |
|
454 |
||
2743 | 455 |
/* must already be a snapshot of this fs */ |
456 |
if (ds->ds_phys->ds_prev_snap_obj == 0) |
|
457 |
return (ENODEV); |
|
458 |
||
459 |
/* most recent snapshot must match fromguid */ |
|
5367 | 460 |
if (ds->ds_prev->ds_phys->ds_guid != rbsa->fromguid) |
2743 | 461 |
return (ENODEV); |
462 |
||
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
|
463 |
/* 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
|
464 |
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
|
465 |
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
|
466 |
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
|
467 |
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
|
468 |
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
|
469 |
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
|
470 |
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
|
471 |
|
2743 | 472 |
/* new snapshot name must not exist */ |
5367 | 473 |
err = zap_lookup(ds->ds_dir->dd_pool->dp_meta_objset, |
474 |
ds->ds_phys->ds_snapnames_zapobj, rbsa->tosnap, 8, 1, &val); |
|
475 |
if (err == 0) |
|
2743 | 476 |
return (EEXIST); |
477 |
if (err != ENOENT) |
|
5367 | 478 |
return (err); |
2743 | 479 |
return (0); |
480 |
} |
|
481 |
||
482 |
/* ARGSUSED */ |
|
5367 | 483 |
static void |
484 |
recv_online_incremental_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
|
485 |
{ |
5367 | 486 |
dsl_dataset_t *ohds = arg1; |
487 |
struct recvbeginsyncarg *rbsa = arg2; |
|
488 |
dsl_pool_t *dp = ohds->ds_dir->dd_pool; |
|
489 |
dsl_dataset_t *ods, *cds; |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
490 |
uint64_t flags = DS_FLAG_INCONSISTENT | rbsa->dsflags; |
5367 | 491 |
uint64_t dsobj; |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
492 |
|
5367 | 493 |
/* create the temporary clone */ |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
494 |
VERIFY(0 == dsl_dataset_hold_obj(dp, ohds->ds_phys->ds_prev_snap_obj, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
495 |
FTAG, &ods)); |
5367 | 496 |
dsobj = dsl_dataset_create_sync(ohds->ds_dir, |
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6479
diff
changeset
|
497 |
rbsa->clonelastname, ods, flags, cr, tx); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
498 |
dsl_dataset_rele(ods, FTAG); |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
499 |
|
5367 | 500 |
/* open the temporary clone */ |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
501 |
VERIFY(0 == dsl_dataset_own_obj(dp, dsobj, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
502 |
DS_MODE_INCONSISTENT, dmu_recv_tag, &cds)); |
5367 | 503 |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
504 |
/* 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
|
505 |
if (ohds->ds_quota > 0) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
506 |
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
|
507 |
|
5367 | 508 |
rbsa->ds = cds; |
509 |
||
510 |
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
|
511 |
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
|
512 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
513 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
514 |
/* ARGSUSED */ |
2743 | 515 |
static void |
5367 | 516 |
recv_offline_incremental_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
2743 | 517 |
{ |
518 |
dsl_dataset_t *ds = arg1; |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
519 |
|
2743 | 520 |
dmu_buf_will_dirty(ds->ds_dbuf, tx); |
521 |
ds->ds_phys->ds_flags |= DS_FLAG_INCONSISTENT; |
|
4543 | 522 |
|
523 |
spa_history_internal_log(LOG_DS_REPLAY_INC_SYNC, |
|
524 |
ds->ds_dir->dd_pool->dp_spa, tx, cr, "dataset = %lld", |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
525 |
ds->ds_object); |
2743 | 526 |
} |
527 |
||
5367 | 528 |
/* |
529 |
* NB: callers *MUST* call dmu_recv_stream() if dmu_recv_begin() |
|
530 |
* succeeds; otherwise we will leak the holds on the datasets. |
|
531 |
*/ |
|
532 |
int |
|
533 |
dmu_recv_begin(char *tofs, char *tosnap, struct drr_begin *drrb, |
|
534 |
boolean_t force, objset_t *origin, boolean_t online, dmu_recv_cookie_t *drc) |
|
2743 | 535 |
{ |
5367 | 536 |
int err = 0; |
537 |
boolean_t byteswap; |
|
538 |
struct recvbeginsyncarg rbsa; |
|
539 |
uint64_t version; |
|
540 |
int flags; |
|
541 |
dsl_dataset_t *ds; |
|
542 |
||
543 |
if (drrb->drr_magic == DMU_BACKUP_MAGIC) |
|
544 |
byteswap = FALSE; |
|
545 |
else if (drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) |
|
546 |
byteswap = TRUE; |
|
547 |
else |
|
548 |
return (EINVAL); |
|
549 |
||
550 |
rbsa.tofs = tofs; |
|
551 |
rbsa.tosnap = tosnap; |
|
552 |
rbsa.origin = origin ? origin->os->os_dsl_dataset : NULL; |
|
553 |
rbsa.fromguid = drrb->drr_fromguid; |
|
554 |
rbsa.type = drrb->drr_type; |
|
555 |
rbsa.tag = FTAG; |
|
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6479
diff
changeset
|
556 |
rbsa.dsflags = 0; |
5367 | 557 |
version = drrb->drr_version; |
558 |
flags = drrb->drr_flags; |
|
559 |
||
560 |
if (byteswap) { |
|
561 |
rbsa.type = BSWAP_32(rbsa.type); |
|
562 |
rbsa.fromguid = BSWAP_64(rbsa.fromguid); |
|
563 |
version = BSWAP_64(version); |
|
564 |
flags = BSWAP_32(flags); |
|
565 |
} |
|
566 |
||
567 |
if (version != DMU_BACKUP_STREAM_VERSION || |
|
568 |
rbsa.type >= DMU_OST_NUMTYPES || |
|
569 |
((flags & DRR_FLAG_CLONE) && origin == NULL)) |
|
570 |
return (EINVAL); |
|
571 |
||
6492
903545192033
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents:
6479
diff
changeset
|
572 |
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
|
573 |
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
|
574 |
|
5367 | 575 |
bzero(drc, sizeof (dmu_recv_cookie_t)); |
576 |
drc->drc_drrb = drrb; |
|
577 |
drc->drc_tosnap = tosnap; |
|
578 |
drc->drc_force = force; |
|
579 |
||
580 |
/* |
|
581 |
* Process the begin in syncing context. |
|
582 |
*/ |
|
583 |
if (rbsa.fromguid && !(flags & DRR_FLAG_CLONE) && !online) { |
|
584 |
/* offline incremental receive */ |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
585 |
err = dsl_dataset_own(tofs, 0, dmu_recv_tag, &ds); |
5367 | 586 |
if (err) |
587 |
return (err); |
|
2743 | 588 |
|
5367 | 589 |
/* |
590 |
* Only do the rollback if the most recent snapshot |
|
591 |
* matches the incremental source |
|
592 |
*/ |
|
593 |
if (force) { |
|
594 |
if (ds->ds_prev == NULL || |
|
595 |
ds->ds_prev->ds_phys->ds_guid != |
|
596 |
rbsa.fromguid) { |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
597 |
dsl_dataset_disown(ds, dmu_recv_tag); |
5367 | 598 |
return (ENODEV); |
599 |
} |
|
600 |
(void) dsl_dataset_rollback(ds, DMU_OST_NONE); |
|
601 |
} |
|
602 |
rbsa.force = B_FALSE; |
|
603 |
err = dsl_sync_task_do(ds->ds_dir->dd_pool, |
|
604 |
recv_incremental_check, |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
605 |
recv_offline_incremental_sync, ds, &rbsa, 1); |
5367 | 606 |
if (err) { |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
607 |
dsl_dataset_disown(ds, dmu_recv_tag); |
5367 | 608 |
return (err); |
609 |
} |
|
610 |
drc->drc_logical_ds = drc->drc_real_ds = ds; |
|
611 |
} else if (rbsa.fromguid && !(flags & DRR_FLAG_CLONE)) { |
|
612 |
/* online incremental receive */ |
|
613 |
||
614 |
/* tmp clone name is: tofs/%tosnap" */ |
|
615 |
(void) snprintf(rbsa.clonelastname, sizeof (rbsa.clonelastname), |
|
616 |
"%%%s", tosnap); |
|
617 |
||
618 |
/* open the dataset we are logically receiving into */ |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
619 |
err = dsl_dataset_hold(tofs, dmu_recv_tag, &ds); |
5367 | 620 |
if (err) |
621 |
return (err); |
|
2743 | 622 |
|
5367 | 623 |
rbsa.force = force; |
624 |
err = dsl_sync_task_do(ds->ds_dir->dd_pool, |
|
625 |
recv_incremental_check, |
|
626 |
recv_online_incremental_sync, ds, &rbsa, 5); |
|
627 |
if (err) { |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
628 |
dsl_dataset_rele(ds, dmu_recv_tag); |
5367 | 629 |
return (err); |
630 |
} |
|
631 |
drc->drc_logical_ds = ds; |
|
632 |
drc->drc_real_ds = rbsa.ds; |
|
633 |
} else { |
|
634 |
/* create new fs -- full backup or clone */ |
|
635 |
dsl_dir_t *dd = NULL; |
|
636 |
const char *tail; |
|
637 |
||
638 |
err = dsl_dir_open(tofs, FTAG, &dd, &tail); |
|
639 |
if (err) |
|
640 |
return (err); |
|
641 |
if (tail == NULL) { |
|
642 |
if (!force) { |
|
643 |
dsl_dir_close(dd, FTAG); |
|
644 |
return (EEXIST); |
|
645 |
} |
|
646 |
||
647 |
rw_enter(&dd->dd_pool->dp_config_rwlock, RW_READER); |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
648 |
err = dsl_dataset_own_obj(dd->dd_pool, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
649 |
dd->dd_phys->dd_head_dataset_obj, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
650 |
DS_MODE_INCONSISTENT, FTAG, &ds); |
5367 | 651 |
rw_exit(&dd->dd_pool->dp_config_rwlock); |
652 |
if (err) { |
|
653 |
dsl_dir_close(dd, FTAG); |
|
654 |
return (err); |
|
655 |
} |
|
656 |
||
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
657 |
dsl_dataset_make_exclusive(ds, FTAG); |
5367 | 658 |
err = dsl_sync_task_do(dd->dd_pool, |
659 |
recv_full_existing_check, |
|
660 |
recv_full_existing_sync, ds, &rbsa, 5); |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
661 |
dsl_dataset_disown(ds, FTAG); |
5367 | 662 |
} else { |
663 |
err = dsl_sync_task_do(dd->dd_pool, recv_full_check, |
|
664 |
recv_full_sync, dd, &rbsa, 5); |
|
665 |
} |
|
666 |
dsl_dir_close(dd, FTAG); |
|
667 |
if (err) |
|
668 |
return (err); |
|
669 |
drc->drc_logical_ds = drc->drc_real_ds = rbsa.ds; |
|
670 |
drc->drc_newfs = B_TRUE; |
|
671 |
} |
|
672 |
||
2743 | 673 |
return (0); |
674 |
} |
|
675 |
||
5367 | 676 |
struct restorearg { |
677 |
int err; |
|
678 |
int byteswap; |
|
679 |
vnode_t *vp; |
|
680 |
char *buf; |
|
681 |
uint64_t voff; |
|
682 |
int bufsize; /* amount of memory allocated for buf */ |
|
683 |
zio_cksum_t cksum; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
684 |
}; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
685 |
|
2743 | 686 |
static void * |
687 |
restore_read(struct restorearg *ra, int len) |
|
688 |
{ |
|
689 |
void *rv; |
|
5367 | 690 |
int done = 0; |
2743 | 691 |
|
692 |
/* some things will require 8-byte alignment, so everything must */ |
|
693 |
ASSERT3U(len % 8, ==, 0); |
|
694 |
||
5367 | 695 |
while (done < len) { |
2743 | 696 |
ssize_t resid; |
697 |
||
698 |
ra->err = vn_rdwr(UIO_READ, ra->vp, |
|
5367 | 699 |
(caddr_t)ra->buf + done, len - done, |
2743 | 700 |
ra->voff, UIO_SYSSPACE, FAPPEND, |
701 |
RLIM64_INFINITY, CRED(), &resid); |
|
702 |
||
5367 | 703 |
if (resid == len - done) |
2743 | 704 |
ra->err = EINVAL; |
5367 | 705 |
ra->voff += len - done - resid; |
706 |
done = len - resid; |
|
2743 | 707 |
if (ra->err) |
708 |
return (NULL); |
|
709 |
} |
|
710 |
||
5367 | 711 |
ASSERT3U(done, ==, len); |
712 |
rv = ra->buf; |
|
2743 | 713 |
if (ra->byteswap) |
5367 | 714 |
fletcher_4_incremental_byteswap(rv, len, &ra->cksum); |
2743 | 715 |
else |
5367 | 716 |
fletcher_4_incremental_native(rv, len, &ra->cksum); |
2743 | 717 |
return (rv); |
718 |
} |
|
719 |
||
720 |
static void |
|
721 |
backup_byteswap(dmu_replay_record_t *drr) |
|
722 |
{ |
|
723 |
#define DO64(X) (drr->drr_u.X = BSWAP_64(drr->drr_u.X)) |
|
724 |
#define DO32(X) (drr->drr_u.X = BSWAP_32(drr->drr_u.X)) |
|
725 |
drr->drr_type = BSWAP_32(drr->drr_type); |
|
5367 | 726 |
drr->drr_payloadlen = BSWAP_32(drr->drr_payloadlen); |
2743 | 727 |
switch (drr->drr_type) { |
728 |
case DRR_BEGIN: |
|
729 |
DO64(drr_begin.drr_magic); |
|
730 |
DO64(drr_begin.drr_version); |
|
731 |
DO64(drr_begin.drr_creation_time); |
|
732 |
DO32(drr_begin.drr_type); |
|
5367 | 733 |
DO32(drr_begin.drr_flags); |
2743 | 734 |
DO64(drr_begin.drr_toguid); |
735 |
DO64(drr_begin.drr_fromguid); |
|
736 |
break; |
|
737 |
case DRR_OBJECT: |
|
738 |
DO64(drr_object.drr_object); |
|
739 |
/* DO64(drr_object.drr_allocation_txg); */ |
|
740 |
DO32(drr_object.drr_type); |
|
741 |
DO32(drr_object.drr_bonustype); |
|
742 |
DO32(drr_object.drr_blksz); |
|
743 |
DO32(drr_object.drr_bonuslen); |
|
744 |
break; |
|
745 |
case DRR_FREEOBJECTS: |
|
746 |
DO64(drr_freeobjects.drr_firstobj); |
|
747 |
DO64(drr_freeobjects.drr_numobjs); |
|
748 |
break; |
|
749 |
case DRR_WRITE: |
|
750 |
DO64(drr_write.drr_object); |
|
751 |
DO32(drr_write.drr_type); |
|
752 |
DO64(drr_write.drr_offset); |
|
753 |
DO64(drr_write.drr_length); |
|
754 |
break; |
|
755 |
case DRR_FREE: |
|
756 |
DO64(drr_free.drr_object); |
|
757 |
DO64(drr_free.drr_offset); |
|
758 |
DO64(drr_free.drr_length); |
|
759 |
break; |
|
760 |
case DRR_END: |
|
761 |
DO64(drr_end.drr_checksum.zc_word[0]); |
|
762 |
DO64(drr_end.drr_checksum.zc_word[1]); |
|
763 |
DO64(drr_end.drr_checksum.zc_word[2]); |
|
764 |
DO64(drr_end.drr_checksum.zc_word[3]); |
|
765 |
break; |
|
766 |
} |
|
767 |
#undef DO64 |
|
768 |
#undef DO32 |
|
769 |
} |
|
770 |
||
771 |
static int |
|
772 |
restore_object(struct restorearg *ra, objset_t *os, struct drr_object *drro) |
|
773 |
{ |
|
774 |
int err; |
|
775 |
dmu_tx_t *tx; |
|
776 |
||
777 |
err = dmu_object_info(os, drro->drr_object, NULL); |
|
778 |
||
779 |
if (err != 0 && err != ENOENT) |
|
780 |
return (EINVAL); |
|
781 |
||
782 |
if (drro->drr_type == DMU_OT_NONE || |
|
783 |
drro->drr_type >= DMU_OT_NUMTYPES || |
|
784 |
drro->drr_bonustype >= DMU_OT_NUMTYPES || |
|
785 |
drro->drr_checksum >= ZIO_CHECKSUM_FUNCTIONS || |
|
786 |
drro->drr_compress >= ZIO_COMPRESS_FUNCTIONS || |
|
787 |
P2PHASE(drro->drr_blksz, SPA_MINBLOCKSIZE) || |
|
788 |
drro->drr_blksz < SPA_MINBLOCKSIZE || |
|
789 |
drro->drr_blksz > SPA_MAXBLOCKSIZE || |
|
790 |
drro->drr_bonuslen > DN_MAX_BONUSLEN) { |
|
791 |
return (EINVAL); |
|
792 |
} |
|
793 |
||
794 |
tx = dmu_tx_create(os); |
|
795 |
||
796 |
if (err == ENOENT) { |
|
797 |
/* currently free, want to be allocated */ |
|
798 |
dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT); |
|
799 |
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, 1); |
|
800 |
err = dmu_tx_assign(tx, TXG_WAIT); |
|
801 |
if (err) { |
|
802 |
dmu_tx_abort(tx); |
|
803 |
return (err); |
|
804 |
} |
|
805 |
err = dmu_object_claim(os, drro->drr_object, |
|
806 |
drro->drr_type, drro->drr_blksz, |
|
807 |
drro->drr_bonustype, drro->drr_bonuslen, tx); |
|
808 |
} else { |
|
809 |
/* currently allocated, want to be allocated */ |
|
810 |
dmu_tx_hold_bonus(tx, drro->drr_object); |
|
811 |
/* |
|
812 |
* We may change blocksize, so need to |
|
813 |
* hold_write |
|
814 |
*/ |
|
815 |
dmu_tx_hold_write(tx, drro->drr_object, 0, 1); |
|
816 |
err = dmu_tx_assign(tx, TXG_WAIT); |
|
817 |
if (err) { |
|
818 |
dmu_tx_abort(tx); |
|
819 |
return (err); |
|
820 |
} |
|
821 |
||
822 |
err = dmu_object_reclaim(os, drro->drr_object, |
|
823 |
drro->drr_type, drro->drr_blksz, |
|
824 |
drro->drr_bonustype, drro->drr_bonuslen, tx); |
|
825 |
} |
|
826 |
if (err) { |
|
827 |
dmu_tx_commit(tx); |
|
828 |
return (EINVAL); |
|
829 |
} |
|
830 |
||
831 |
dmu_object_set_checksum(os, drro->drr_object, drro->drr_checksum, tx); |
|
832 |
dmu_object_set_compress(os, drro->drr_object, drro->drr_compress, tx); |
|
833 |
||
834 |
if (drro->drr_bonuslen) { |
|
835 |
dmu_buf_t *db; |
|
836 |
void *data; |
|
837 |
VERIFY(0 == dmu_bonus_hold(os, drro->drr_object, FTAG, &db)); |
|
838 |
dmu_buf_will_dirty(db, tx); |
|
839 |
||
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4543
diff
changeset
|
840 |
ASSERT3U(db->db_size, >=, drro->drr_bonuslen); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4543
diff
changeset
|
841 |
data = restore_read(ra, P2ROUNDUP(drro->drr_bonuslen, 8)); |
2743 | 842 |
if (data == NULL) { |
843 |
dmu_tx_commit(tx); |
|
844 |
return (ra->err); |
|
845 |
} |
|
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4543
diff
changeset
|
846 |
bcopy(data, db->db_data, drro->drr_bonuslen); |
2743 | 847 |
if (ra->byteswap) { |
848 |
dmu_ot[drro->drr_bonustype].ot_byteswap(db->db_data, |
|
849 |
drro->drr_bonuslen); |
|
850 |
} |
|
851 |
dmu_buf_rele(db, FTAG); |
|
852 |
} |
|
853 |
dmu_tx_commit(tx); |
|
854 |
return (0); |
|
855 |
} |
|
856 |
||
857 |
/* ARGSUSED */ |
|
858 |
static int |
|
859 |
restore_freeobjects(struct restorearg *ra, objset_t *os, |
|
860 |
struct drr_freeobjects *drrfo) |
|
861 |
{ |
|
862 |
uint64_t obj; |
|
863 |
||
864 |
if (drrfo->drr_firstobj + drrfo->drr_numobjs < drrfo->drr_firstobj) |
|
865 |
return (EINVAL); |
|
866 |
||
867 |
for (obj = drrfo->drr_firstobj; |
|
3087 | 868 |
obj < drrfo->drr_firstobj + drrfo->drr_numobjs; |
869 |
(void) dmu_object_next(os, &obj, FALSE, 0)) { |
|
2743 | 870 |
int err; |
871 |
||
872 |
if (dmu_object_info(os, obj, NULL) != 0) |
|
873 |
continue; |
|
874 |
||
6992 | 875 |
err = dmu_free_object(os, obj); |
876 |
if (err) |
|
2743 | 877 |
return (err); |
878 |
} |
|
879 |
return (0); |
|
880 |
} |
|
881 |
||
882 |
static int |
|
883 |
restore_write(struct restorearg *ra, objset_t *os, |
|
884 |
struct drr_write *drrw) |
|
885 |
{ |
|
886 |
dmu_tx_t *tx; |
|
887 |
void *data; |
|
888 |
int err; |
|
889 |
||
890 |
if (drrw->drr_offset + drrw->drr_length < drrw->drr_offset || |
|
891 |
drrw->drr_type >= DMU_OT_NUMTYPES) |
|
892 |
return (EINVAL); |
|
893 |
||
894 |
data = restore_read(ra, drrw->drr_length); |
|
895 |
if (data == NULL) |
|
896 |
return (ra->err); |
|
897 |
||
898 |
if (dmu_object_info(os, drrw->drr_object, NULL) != 0) |
|
899 |
return (EINVAL); |
|
900 |
||
901 |
tx = dmu_tx_create(os); |
|
902 |
||
903 |
dmu_tx_hold_write(tx, drrw->drr_object, |
|
904 |
drrw->drr_offset, drrw->drr_length); |
|
905 |
err = dmu_tx_assign(tx, TXG_WAIT); |
|
906 |
if (err) { |
|
907 |
dmu_tx_abort(tx); |
|
908 |
return (err); |
|
909 |
} |
|
910 |
if (ra->byteswap) |
|
911 |
dmu_ot[drrw->drr_type].ot_byteswap(data, drrw->drr_length); |
|
912 |
dmu_write(os, drrw->drr_object, |
|
913 |
drrw->drr_offset, drrw->drr_length, data, tx); |
|
914 |
dmu_tx_commit(tx); |
|
915 |
return (0); |
|
916 |
} |
|
917 |
||
918 |
/* ARGSUSED */ |
|
919 |
static int |
|
920 |
restore_free(struct restorearg *ra, objset_t *os, |
|
921 |
struct drr_free *drrf) |
|
922 |
{ |
|
923 |
int err; |
|
924 |
||
925 |
if (drrf->drr_length != -1ULL && |
|
926 |
drrf->drr_offset + drrf->drr_length < drrf->drr_offset) |
|
927 |
return (EINVAL); |
|
928 |
||
929 |
if (dmu_object_info(os, drrf->drr_object, NULL) != 0) |
|
930 |
return (EINVAL); |
|
931 |
||
6992 | 932 |
err = dmu_free_long_range(os, drrf->drr_object, |
2743 | 933 |
drrf->drr_offset, drrf->drr_length); |
934 |
return (err); |
|
935 |
} |
|
936 |
||
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
|
937 |
void |
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
|
938 |
dmu_recv_abort_cleanup(dmu_recv_cookie_t *drc) |
2743 | 939 |
{ |
5367 | 940 |
if (drc->drc_newfs || drc->drc_real_ds != drc->drc_logical_ds) { |
941 |
/* |
|
942 |
* online incremental or new fs: destroy the fs (which |
|
943 |
* may be a clone) that we created |
|
944 |
*/ |
|
945 |
(void) dsl_dataset_destroy(drc->drc_real_ds, dmu_recv_tag); |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
946 |
if (drc->drc_real_ds != drc->drc_logical_ds) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
947 |
dsl_dataset_rele(drc->drc_logical_ds, dmu_recv_tag); |
5367 | 948 |
} else { |
949 |
/* |
|
950 |
* offline incremental: rollback to most recent snapshot. |
|
951 |
*/ |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
952 |
(void) dsl_dataset_rollback(drc->drc_real_ds, DMU_OST_NONE); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
953 |
dsl_dataset_disown(drc->drc_real_ds, dmu_recv_tag); |
5367 | 954 |
} |
955 |
} |
|
2743 | 956 |
|
5367 | 957 |
/* |
958 |
* NB: callers *must* call dmu_recv_end() if this succeeds. |
|
959 |
*/ |
|
960 |
int |
|
961 |
dmu_recv_stream(dmu_recv_cookie_t *drc, vnode_t *vp, offset_t *voffp) |
|
962 |
{ |
|
963 |
struct restorearg ra = { 0 }; |
|
964 |
dmu_replay_record_t *drr; |
|
965 |
objset_t *os; |
|
966 |
zio_cksum_t pcksum; |
|
967 |
||
968 |
if (drc->drc_drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) |
|
969 |
ra.byteswap = TRUE; |
|
2743 | 970 |
|
5367 | 971 |
{ |
972 |
/* compute checksum of drr_begin record */ |
|
973 |
dmu_replay_record_t *drr; |
|
974 |
drr = kmem_zalloc(sizeof (dmu_replay_record_t), KM_SLEEP); |
|
975 |
||
976 |
drr->drr_type = DRR_BEGIN; |
|
977 |
drr->drr_u.drr_begin = *drc->drc_drrb; |
|
978 |
if (ra.byteswap) { |
|
979 |
fletcher_4_incremental_byteswap(drr, |
|
980 |
sizeof (dmu_replay_record_t), &ra.cksum); |
|
981 |
} else { |
|
982 |
fletcher_4_incremental_native(drr, |
|
983 |
sizeof (dmu_replay_record_t), &ra.cksum); |
|
984 |
} |
|
985 |
kmem_free(drr, sizeof (dmu_replay_record_t)); |
|
2743 | 986 |
} |
987 |
||
988 |
if (ra.byteswap) { |
|
5367 | 989 |
struct drr_begin *drrb = drc->drc_drrb; |
2743 | 990 |
drrb->drr_magic = BSWAP_64(drrb->drr_magic); |
991 |
drrb->drr_version = BSWAP_64(drrb->drr_version); |
|
992 |
drrb->drr_creation_time = BSWAP_64(drrb->drr_creation_time); |
|
993 |
drrb->drr_type = BSWAP_32(drrb->drr_type); |
|
994 |
drrb->drr_toguid = BSWAP_64(drrb->drr_toguid); |
|
995 |
drrb->drr_fromguid = BSWAP_64(drrb->drr_fromguid); |
|
996 |
} |
|
997 |
||
5367 | 998 |
ra.vp = vp; |
999 |
ra.voff = *voffp; |
|
1000 |
ra.bufsize = 1<<20; |
|
1001 |
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
|
1002 |
|
5367 | 1003 |
/* these were verified in dmu_recv_begin */ |
1004 |
ASSERT(drc->drc_drrb->drr_version == DMU_BACKUP_STREAM_VERSION); |
|
1005 |
ASSERT(drc->drc_drrb->drr_type < DMU_OST_NUMTYPES); |
|
2743 | 1006 |
|
1007 |
/* |
|
1008 |
* Open the objset we are modifying. |
|
1009 |
*/ |
|
5367 | 1010 |
VERIFY(dmu_objset_open_ds(drc->drc_real_ds, DMU_OST_ANY, &os) == 0); |
2743 | 1011 |
|
5367 | 1012 |
ASSERT(drc->drc_real_ds->ds_phys->ds_flags & DS_FLAG_INCONSISTENT); |
2743 | 1013 |
|
1014 |
/* |
|
1015 |
* Read records and process them. |
|
1016 |
*/ |
|
5367 | 1017 |
pcksum = ra.cksum; |
2743 | 1018 |
while (ra.err == 0 && |
1019 |
NULL != (drr = restore_read(&ra, sizeof (*drr)))) { |
|
1020 |
if (issig(JUSTLOOKING) && issig(FORREAL)) { |
|
1021 |
ra.err = EINTR; |
|
1022 |
goto out; |
|
1023 |
} |
|
1024 |
||
1025 |
if (ra.byteswap) |
|
1026 |
backup_byteswap(drr); |
|
1027 |
||
1028 |
switch (drr->drr_type) { |
|
1029 |
case DRR_OBJECT: |
|
1030 |
{ |
|
1031 |
/* |
|
1032 |
* We need to make a copy of the record header, |
|
1033 |
* because restore_{object,write} may need to |
|
1034 |
* restore_read(), which will invalidate drr. |
|
1035 |
*/ |
|
1036 |
struct drr_object drro = drr->drr_u.drr_object; |
|
1037 |
ra.err = restore_object(&ra, os, &drro); |
|
1038 |
break; |
|
1039 |
} |
|
1040 |
case DRR_FREEOBJECTS: |
|
1041 |
{ |
|
1042 |
struct drr_freeobjects drrfo = |
|
1043 |
drr->drr_u.drr_freeobjects; |
|
1044 |
ra.err = restore_freeobjects(&ra, os, &drrfo); |
|
1045 |
break; |
|
1046 |
} |
|
1047 |
case DRR_WRITE: |
|
1048 |
{ |
|
1049 |
struct drr_write drrw = drr->drr_u.drr_write; |
|
1050 |
ra.err = restore_write(&ra, os, &drrw); |
|
1051 |
break; |
|
1052 |
} |
|
1053 |
case DRR_FREE: |
|
1054 |
{ |
|
1055 |
struct drr_free drrf = drr->drr_u.drr_free; |
|
1056 |
ra.err = restore_free(&ra, os, &drrf); |
|
1057 |
break; |
|
1058 |
} |
|
1059 |
case DRR_END: |
|
1060 |
{ |
|
1061 |
struct drr_end drre = drr->drr_u.drr_end; |
|
1062 |
/* |
|
1063 |
* We compare against the *previous* checksum |
|
1064 |
* value, because the stored checksum is of |
|
1065 |
* everything before the DRR_END record. |
|
1066 |
*/ |
|
6479 | 1067 |
if (!ZIO_CHECKSUM_EQUAL(drre.drr_checksum, pcksum)) |
2743 | 1068 |
ra.err = ECKSUM; |
1069 |
goto out; |
|
1070 |
} |
|
1071 |
default: |
|
1072 |
ra.err = EINVAL; |
|
1073 |
goto out; |
|
1074 |
} |
|
5367 | 1075 |
pcksum = ra.cksum; |
2743 | 1076 |
} |
6479 | 1077 |
ASSERT(ra.err != 0); |
2743 | 1078 |
|
1079 |
out: |
|
5367 | 1080 |
dmu_objset_close(os); |
2743 | 1081 |
|
5367 | 1082 |
if (ra.err != 0) { |
2743 | 1083 |
/* |
1084 |
* rollback or destroy what we created, so we don't |
|
1085 |
* leave it in the restoring state. |
|
1086 |
*/ |
|
5367 | 1087 |
txg_wait_synced(drc->drc_real_ds->ds_dir->dd_pool, 0); |
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
|
1088 |
dmu_recv_abort_cleanup(drc); |
2743 | 1089 |
} |
1090 |
||
1091 |
kmem_free(ra.buf, ra.bufsize); |
|
5367 | 1092 |
*voffp = ra.voff; |
2743 | 1093 |
return (ra.err); |
1094 |
} |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
1095 |
|
5367 | 1096 |
struct recvendsyncarg { |
1097 |
char *tosnap; |
|
1098 |
uint64_t creation_time; |
|
1099 |
uint64_t toguid; |
|
1100 |
}; |
|
1101 |
||
1102 |
static int |
|
1103 |
recv_end_check(void *arg1, void *arg2, dmu_tx_t *tx) |
|
1104 |
{ |
|
1105 |
dsl_dataset_t *ds = arg1; |
|
1106 |
struct recvendsyncarg *resa = arg2; |
|
1107 |
||
1108 |
return (dsl_dataset_snapshot_check(ds, resa->tosnap, tx)); |
|
1109 |
} |
|
1110 |
||
1111 |
static void |
|
1112 |
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
|
1113 |
{ |
5367 | 1114 |
dsl_dataset_t *ds = arg1; |
1115 |
struct recvendsyncarg *resa = arg2; |
|
1116 |
||
1117 |
dsl_dataset_snapshot_sync(ds, resa->tosnap, cr, tx); |
|
1118 |
||
1119 |
/* set snapshot's creation time and guid */ |
|
1120 |
dmu_buf_will_dirty(ds->ds_prev->ds_dbuf, tx); |
|
1121 |
ds->ds_prev->ds_phys->ds_creation_time = resa->creation_time; |
|
1122 |
ds->ds_prev->ds_phys->ds_guid = resa->toguid; |
|
1123 |
ds->ds_prev->ds_phys->ds_flags &= ~DS_FLAG_INCONSISTENT; |
|
1124 |
||
1125 |
dmu_buf_will_dirty(ds->ds_dbuf, tx); |
|
1126 |
ds->ds_phys->ds_flags &= ~DS_FLAG_INCONSISTENT; |
|
1127 |
} |
|
1128 |
||
1129 |
int |
|
1130 |
dmu_recv_end(dmu_recv_cookie_t *drc) |
|
1131 |
{ |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1132 |
struct recvendsyncarg resa; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1133 |
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
|
1134 |
int err; |
5367 | 1135 |
|
1136 |
/* |
|
1137 |
* XXX hack; seems the ds is still dirty and |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1138 |
* dsl_pool_zil_clean() expects it to have a ds_user_ptr |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1139 |
* (and zil), but clone_swap() can close it. |
5367 | 1140 |
*/ |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1141 |
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
|
1142 |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1143 |
if (ds != drc->drc_real_ds) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1144 |
/* we are doing an online recv */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1145 |
if (dsl_dataset_tryown(ds, FALSE, dmu_recv_tag)) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1146 |
err = dsl_dataset_clone_swap(drc->drc_real_ds, ds, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1147 |
drc->drc_force); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1148 |
if (err) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1149 |
dsl_dataset_disown(ds, dmu_recv_tag); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1150 |
} else { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1151 |
err = EBUSY; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1152 |
dsl_dataset_rele(ds, dmu_recv_tag); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1153 |
} |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1154 |
/* dsl_dataset_destroy() will disown the ds */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1155 |
(void) dsl_dataset_destroy(drc->drc_real_ds, dmu_recv_tag); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1156 |
if (err) |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1157 |
return (err); |
5367 | 1158 |
} |
1159 |
||
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1160 |
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
|
1161 |
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
|
1162 |
resa.tosnap = drc->drc_tosnap; |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1163 |
|
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1164 |
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
|
1165 |
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
|
1166 |
if (err) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1167 |
if (drc->drc_newfs) { |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1168 |
ASSERT(ds == drc->drc_real_ds); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1169 |
(void) dsl_dataset_destroy(ds, dmu_recv_tag); |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1170 |
return (err); |
5367 | 1171 |
} else { |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1172 |
(void) dsl_dataset_rollback(ds, DMU_OST_NONE); |
5367 | 1173 |
} |
1174 |
} |
|
1175 |
||
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1176 |
/* release the hold from dmu_recv_begin */ |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6492
diff
changeset
|
1177 |
dsl_dataset_disown(ds, dmu_recv_tag); |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
1178 |
return (err); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4944
diff
changeset
|
1179 |
} |