dmu_send.c revision a2afb611b30628fb74ad9eade4ae465f9031e262
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * CDDL HEADER START
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * The contents of this file are subject to the terms of the
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * Common Development and Distribution License (the "License").
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * You may not use this file except in compliance with the License.
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * See the License for the specific language governing permissions
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * and limitations under the License.
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * When distributing Covered Code, include this CDDL HEADER in each
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * If applicable, add the following below this CDDL HEADER, with the
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * fields enclosed by brackets "[]" replaced with your own identifying
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * CDDL HEADER END
dc7cd546d81fce970935f08099931c2ad2d57731Mark Shellenbaum * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
ec5cf9d53a1d7280f3f1a6eadd7cdabdc99814ebAlexander Stetsenko * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens * Copyright (c) 2013 by Delphix. All rights reserved.
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * Copyright (c) 2014, Joyent, Inc. All rights reserved.
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens/* Set this tunable to TRUE to replace corrupt data with 0x2f5baddb10c */
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewskidump_bytes(dmu_sendarg_t *dsp, void *buf, int len)
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski dsl_dataset_t *ds = dsp->dsa_os->os_dsl_dataset;
efb80947b01107dafbbf0157de0d7e1af6551259ahrens ssize_t resid; /* have to get resid to get detailed errno */
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski fletcher_4_incremental_native(buf, len, &dsp->dsa_zc);
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski dsp->dsa_err = vn_rdwr(UIO_WRITE, dsp->dsa_vp,
efb80947b01107dafbbf0157de0d7e1af6551259ahrens 0, UIO_SYSSPACE, FAPPEND, RLIM64_INFINITY, CRED(), &resid);
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewskidump_free(dmu_sendarg_t *dsp, uint64_t object, uint64_t offset,
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski struct drr_free *drrf = &(dsp->dsa_drr->drr_u.drr_free);
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * When we receive a free record, dbuf_free_range() assumes
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * that the receiving system doesn't have any dbufs in the range
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * being freed. This is always true because there is a one-record
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * constraint: we only send one WRITE record for any given
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * object+offset. We know that the one-record constraint is
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * true because we always send data in increasing order by
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * object,offset.
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * If the increasing-order constraint ever changes, we should find
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * another way to assert that the one-record constraint is still
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * If we are doing a non-incremental send, then there can't
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * be any data in the dataset we're receiving into. Therefore
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * a free record would simply be a no-op. Save space by not
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * sending it to begin with.
534029e5aa7701f85c9a4e201014b5a5a1aaf488Simon Klinkert if (length != -1ULL && offset + length < offset)
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * If there is a pending op, but it's not PENDING_FREE, push it out,
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * since free block aggregation can only be done for blocks of the
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * same type (i.e., DRR_FREE records can only be aggregated with
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * other DRR_FREE records. DRR_FREEOBJECTS records can only be
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * aggregated with other DRR_FREEOBJECTS records.
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * There should never be a PENDING_FREE if length is -1
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * (because dump_dnode is the only place where this
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * function is called with a -1, and only after flushing
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * any pending record).
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * Check to see whether this free block can be aggregated
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * with pending one.
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt if (drrf->drr_object == object && drrf->drr_offset +
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt return (0);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt /* not a continuation. Push out pending record */
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt sizeof (dmu_replay_record_t)) != 0)
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt /* create a FREE record and make it pending */
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski bzero(dsp->dsa_drr, sizeof (dmu_replay_record_t));
efb80947b01107dafbbf0157de0d7e1af6551259ahrens return (0);
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewskidump_data(dmu_sendarg_t *dsp, dmu_object_type_t type,
8e7144747a94247ce9dbb4fb1f67bdcb666b30d8Lori Alt uint64_t object, uint64_t offset, int blksz, const blkptr_t *bp, void *data)
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski struct drr_write *drrw = &(dsp->dsa_drr->drr_u.drr_write);
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * We send data in increasing object, offset order.
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * See comment in dump_free() for details.
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens dsp->dsa_last_data_offset = offset + blksz - 1;
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * If there is any kind of pending aggregation (currently either
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * a grouping of free objects or free blocks), push it out to
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * the stream, since aggregation can't be done across operations
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * of different types.
efb80947b01107dafbbf0157de0d7e1af6551259ahrens /* write a DATA record */
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski bzero(dsp->dsa_drr, sizeof (dmu_replay_record_t));
8e7144747a94247ce9dbb4fb1f67bdcb666b30d8Lori Alt if (zio_checksum_table[drrw->drr_checksumtype].ci_dedup)
8e7144747a94247ce9dbb4fb1f67bdcb666b30d8Lori Alt DDK_SET_COMPRESS(&drrw->drr_key, BP_GET_COMPRESS(bp));
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski if (dump_bytes(dsp, dsp->dsa_drr, sizeof (dmu_replay_record_t)) != 0)
efb80947b01107dafbbf0157de0d7e1af6551259ahrens return (0);
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewskidump_spill(dmu_sendarg_t *dsp, uint64_t object, int blksz, void *data)
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski struct drr_spill *drrs = &(dsp->dsa_drr->drr_u.drr_spill);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum /* write a SPILL record */
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski bzero(dsp->dsa_drr, sizeof (dmu_replay_record_t));
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski if (dump_bytes(dsp, dsp->dsa_drr, sizeof (dmu_replay_record_t)))
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewskidump_freeobjects(dmu_sendarg_t *dsp, uint64_t firstobj, uint64_t numobjs)
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski struct drr_freeobjects *drrfo = &(dsp->dsa_drr->drr_u.drr_freeobjects);
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens /* See comment in dump_free(). */
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * If there is a pending op, but it's not PENDING_FREEOBJECTS,
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * push it out, since free block aggregation can only be done for
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * blocks of the same type (i.e., DRR_FREE records can only be
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * aggregated with other DRR_FREE records. DRR_FREEOBJECTS records
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * can only be aggregated with other DRR_FREEOBJECTS records.
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski if (dsp->dsa_pending_op == PENDING_FREEOBJECTS) {
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * See whether this free object array can be aggregated
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * with pending one
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt if (drrfo->drr_firstobj + drrfo->drr_numobjs == firstobj) {
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt return (0);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt /* can't be aggregated. Push out pending record */
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt sizeof (dmu_replay_record_t)) != 0)
efb80947b01107dafbbf0157de0d7e1af6551259ahrens /* write a FREEOBJECTS record */
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski bzero(dsp->dsa_drr, sizeof (dmu_replay_record_t));
efb80947b01107dafbbf0157de0d7e1af6551259ahrens return (0);
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewskidump_dnode(dmu_sendarg_t *dsp, uint64_t object, dnode_phys_t *dnp)
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski struct drr_object *drro = &(dsp->dsa_drr->drr_u.drr_object);
efb80947b01107dafbbf0157de0d7e1af6551259ahrens /* write an OBJECT record */
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski bzero(dsp->dsa_drr, sizeof (dmu_replay_record_t));
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt drro->drr_blksz = dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT;
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski if (dump_bytes(dsp, dsp->dsa_drr, sizeof (dmu_replay_record_t)) != 0)
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski if (dump_bytes(dsp, DN_BONUS(dnp), P2ROUNDUP(dnp->dn_bonuslen, 8)) != 0)
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens /* Free anything past the end of the file. */
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski if (dump_free(dsp, object, (dnp->dn_maxblkid + 1) *
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens (dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT), -1ULL) != 0)
efb80947b01107dafbbf0157de0d7e1af6551259ahrens return (0);
efb80947b01107dafbbf0157de0d7e1af6551259ahrens (((uint64_t)dnp->dn_datablkszsec) << (SPA_MINBLOCKSHIFT + \
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick/* ARGSUSED */
1b912ec7100c10e7243bf0879af0fe580e08c73dGeorge Wilsonbackup_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick const zbookmark_t *zb, const dnode_phys_t *dnp, void *arg)
efb80947b01107dafbbf0157de0d7e1af6551259ahrens dmu_object_type_t type = bp ? BP_GET_TYPE(bp) : DMU_OT_NONE;
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * If we are sending a non-snapshot (which is allowed on
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * read-only pools), it may have a ZIL, which must be ignored.
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens uint64_t dnobj = (zb->zb_blkid * span) >> DNODE_SHIFT;
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski err = dump_freeobjects(dsp, dnobj, span >> DNODE_SHIFT);
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski err = dump_free(dsp, zb->zb_object, zb->zb_blkid * span, span);
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens } else if (zb->zb_level > 0 || type == DMU_OT_OBJSET) {
1b912ec7100c10e7243bf0879af0fe580e08c73dGeorge Wilson if (arc_read(NULL, spa, bp, arc_getbuf_func, &abuf,
1b912ec7100c10e7243bf0879af0fe580e08c73dGeorge Wilson if (arc_read(NULL, spa, bp, arc_getbuf_func, &abuf,
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski err = dump_spill(dsp, zb->zb_object, blksz, abuf->b_data);
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens } else { /* it's a level-0 block of a regular object */
1b912ec7100c10e7243bf0879af0fe580e08c73dGeorge Wilson if (arc_read(NULL, spa, bp, arc_getbuf_func, &abuf,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens /* Send a block filled with 0x"zfs badd bloc" */
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski err = dump_data(dsp, type, zb->zb_object, zb->zb_blkid * blksz,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * Releases dp using the specified tag.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_send_impl(void *tag, dsl_pool_t *dp, dsl_dataset_t *ds,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens zfs_bookmark_phys_t *fromzb, boolean_t is_clone, int outfd,
efb80947b01107dafbbf0157de0d7e1af6551259ahrens drr = kmem_zalloc(sizeof (dmu_replay_record_t), KM_SLEEP);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt DMU_SET_STREAM_HDRTYPE(drr->drr_u.drr_begin.drr_versioninfo,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (zfs_get_zplprop(os, ZFS_PROP_VERSION, &version) != 0) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens drr->drr_u.drr_begin.drr_type = dmu_objset_type(os);
efb80947b01107dafbbf0157de0d7e1af6551259ahrens drr->drr_u.drr_begin.drr_toguid = ds->ds_phys->ds_guid;
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens drr->drr_u.drr_begin.drr_fromguid = fromzb->zbm_guid;
efb80947b01107dafbbf0157de0d7e1af6551259ahrens dsl_dataset_name(ds, drr->drr_u.drr_begin.drr_toname);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens (void) strlcat(drr->drr_u.drr_begin.drr_toname, "@--head--",
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski dsp = kmem_zalloc(sizeof (dmu_sendarg_t), KM_SLEEP);
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski if (dump_bytes(dsp, drr, sizeof (dmu_replay_record_t)) != 0) {
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens err = traverse_dataset(ds, fromtxg, TRAVERSE_PRE | TRAVERSE_PREFETCH,
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski if (dump_bytes(dsp, drr, sizeof (dmu_replay_record_t)) != 0)
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski drr->drr_u.drr_end.drr_checksum = dsp->dsa_zc;
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski drr->drr_u.drr_end.drr_toguid = dsp->dsa_toguid;
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski if (dump_bytes(dsp, drr, sizeof (dmu_replay_record_t)) != 0) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_send_obj(const char *pool, uint64_t tosnap, uint64_t fromsnap,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_dataset_hold_obj(dp, tosnap, FTAG, &ds);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_dataset_hold_obj(dp, fromsnap, FTAG, &fromds);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens zb.zbm_creation_time = fromds->ds_phys->ds_creation_time;
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens zb.zbm_creation_txg = fromds->ds_phys->ds_creation_txg;
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens err = dmu_send_impl(FTAG, dp, ds, &zb, is_clone,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens err = dmu_send_impl(FTAG, dp, ds, NULL, B_FALSE,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_send(const char *tosnap, const char *fromsnap,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens if (fromsnap != NULL && strpbrk(fromsnap, "@#") == NULL)
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens if (strchr(tosnap, '@') == NULL && spa_writeable(dp->dp_spa)) {
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * We are sending a filesystem or volume. Ensure
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * that it doesn't change by owning the dataset.
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens err = dsl_dataset_own(dp, tosnap, FTAG, &ds);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens err = dsl_dataset_hold(dp, tosnap, FTAG, &ds);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens int fsnamelen = strchr(tosnap, '@') - tosnap;
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * If the fromsnap is in a different filesystem, then
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * mark the send stream as a clone.
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens if (strncmp(tosnap, fromsnap, fsnamelen) != 0 ||
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens err = dsl_dataset_hold(dp, fromsnap, FTAG, &fromds);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens err = dsl_bookmark_lookup(dp, fromsnap, ds, &zb);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens err = dmu_send_impl(FTAG, dp, ds, &zb, is_clone,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens err = dmu_send_impl(FTAG, dp, ds, NULL, B_FALSE,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_send_estimate(dsl_dataset_t *ds, dsl_dataset_t *fromds, uint64_t *sizep)
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens /* tosnap must be a snapshot */
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * fromsnap must be an earlier snapshot from the same fs as tosnap,
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens * or the origin's fs.
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens if (fromds != NULL && !dsl_dataset_is_before(ds, fromds, 0))
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens /* Get uncompressed size estimate of changed data. */
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * Assume that space (both on-disk and in-stream) is dominated by
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * data. We will adjust for indirect blocks and the copies property,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * but ignore per-object space used (eg, dnodes and DRR_OBJECT records).
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * Subtract out approximate space used by indirect blocks.
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * Assume most space is used by data blocks (non-indirect, non-dnode).
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * Assume all blocks are recordsize. Assume ditto blocks and
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * internal fragmentation counter out compression.
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * Therefore, space used by indirect blocks is sizeof(blkptr_t) per
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens * block, which we observe in practice.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_prop_get_int_ds(ds, "recordsize", &recordsize);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens size -= size / recordsize * sizeof (blkptr_t);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens /* Add in the space for the record associated with each block. */
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens size += size / recordsize * sizeof (dmu_replay_record_t);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensrecv_begin_check_existing_impl(dmu_recv_begin_arg_t *drba, dsl_dataset_t *ds,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* temporary clone name must not exist */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ds->ds_dir->dd_phys->dd_child_dir_zapobj, recv_clone_name,
feaa74e41c407fe56e66a47e097c2842d4f65b9fMark Maybee /* new snapshot name must not exist */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ds->ds_phys->ds_snapnames_zapobj, drba->drba_cookie->drc_tosnap,
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * Check snapshot limit before receiving. We'll recheck again at the
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * end, but might as well abort before receiving if we're already over
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * Note that we do not check the file system limit with
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * dsl_dir_fscount_check because the temporary %clones don't count
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * against that limit.
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek error = dsl_fs_ss_limit_check(ds->ds_dir, 1, ZFS_PROP_SNAPSHOT_LIMIT,
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens uint64_t obj = ds->ds_phys->ds_prev_snap_obj;
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens /* Find snapshot in this dir that matches fromguid. */
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens while (obj != 0) {
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens * If we are not forcing, there must be no
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens * changes since fromsnap.
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens if (dsl_dataset_modified_since_snap(ds, snap)) {
ae46e4c775f2becc5343ff90b60a95acb79735f9Matthew Ahrens /* if full, most recent snapshot must be $ORIGIN */
ae46e4c775f2becc5343ff90b60a95acb79735f9Matthew Ahrens if (ds->ds_phys->ds_prev_snap_txg >= TXG_INITIAL)
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens drba->drba_snapobj = ds->ds_phys->ds_prev_snap_obj;
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens return (0);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens struct drr_begin *drrb = drba->drba_cookie->drc_drrb;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens const char *tofs = drba->drba_cookie->drc_tofs;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* already checked */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT3U(drrb->drr_magic, ==, DMU_BACKUP_MAGIC);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (DMU_GET_STREAM_HDRTYPE(drrb->drr_versioninfo) ==
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ((flags & DRR_FLAG_CLONE) && drba->drba_origin == NULL))
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Verify pool version supports SA if SA_SPILL feature set */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if ((DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo) &
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, tofs, FTAG, &ds);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* target fs already exists; recv into temp clone */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Can't recv a clone into an existing fs */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = recv_begin_check_existing_impl(drba, ds, fromguid);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* target fs does not exist; must be a full backup or clone */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * If it's a non-clone incremental, we are missing the
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * target fs, so fail the recv.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (fromguid != 0 && !(flags & DRR_FLAG_CLONE))
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Open the parent of tofs */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) strlcpy(buf, tofs, strrchr(tofs, '/') - tofs + 1);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, buf, FTAG, &ds);
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * Check filesystem and snapshot limits before receiving. We'll
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * recheck snapshot limits again at the end (we create the
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * filesystems and increment those counts during begin_sync).
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek ZFS_PROP_FILESYSTEM_LIMIT, NULL, drba->drba_cred);
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek ZFS_PROP_SNAPSHOT_LIMIT, NULL, drba->drba_cred);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, drba->drba_origin,
f18faf3f3e5def85fdfff681617d227703ace2adekstatic void
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens struct drr_begin *drrb = drba->drba_cookie->drc_drrb;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens const char *tofs = drba->drba_cookie->drc_tofs;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens crflags = (drrb->drr_flags & DRR_FLAG_CI_DATA) ?
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, tofs, FTAG, &ds);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* create temporary clone */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsobj = dsl_dataset_create_sync(ds->ds_dir, recv_clone_name,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dir_hold(dp, tofs, FTAG, &dd, &tail));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_hold(dp, drba->drba_origin,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Create new dataset. */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_own_obj(dp, dsobj, dmu_recv_tag, &newds));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens newds->ds_phys->ds_flags |= DS_FLAG_INCONSISTENT;
ae46e4c775f2becc5343ff90b60a95acb79735f9Matthew Ahrens * If we actually created a non-clone, we need to create the
ae46e4c775f2becc5343ff90b60a95acb79735f9Matthew Ahrens * objset in our new dataset.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (BP_IS_HOLE(dsl_dataset_get_blkptr(newds))) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens newds, dsl_dataset_get_blkptr(newds), drrb->drr_type, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens spa_history_log_internal_ds(newds, "receive", tx, "");
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * NB: callers *MUST* call dmu_recv_stream() if dmu_recv_begin()
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * succeeds; otherwise we will leak the holds on the datasets.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_recv_begin(char *tofs, char *tosnap, struct drr_begin *drrb,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens boolean_t force, char *origin, dmu_recv_cookie_t *drc)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC))
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens else if (drrb->drr_magic != DMU_BACKUP_MAGIC)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens drr = kmem_zalloc(sizeof (dmu_replay_record_t), KM_SLEEP);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens sizeof (dmu_replay_record_t), &drc->drc_cksum);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens sizeof (dmu_replay_record_t), &drc->drc_cksum);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens kmem_free(drr, sizeof (dmu_replay_record_t));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens drrb->drr_versioninfo = BSWAP_64(drrb->drr_versioninfo);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens drrb->drr_creation_time = BSWAP_64(drrb->drr_creation_time);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens drrb->drr_toguid = BSWAP_64(drrb->drr_toguid);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens drrb->drr_fromguid = BSWAP_64(drrb->drr_fromguid);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens return (dsl_sync_task(tofs, dmu_recv_begin_check, dmu_recv_begin_sync,
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens int bufsize; /* amount of memory allocated for buf */
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alttypedef struct guid_map_entry {
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt return (-1);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt return (1);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt return (0);
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby while ((gmep = avl_destroy_nodes(ca, &cookie)) != NULL) {
efb80947b01107dafbbf0157de0d7e1af6551259ahrensstatic void *
efb80947b01107dafbbf0157de0d7e1af6551259ahrens /* some things will require 8-byte alignment, so everything must */
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens fletcher_4_incremental_byteswap(rv, len, &ra->cksum);
efb80947b01107dafbbf0157de0d7e1af6551259ahrens#define DO64(X) (drr->drr_u.X = BSWAP_64(drr->drr_u.X))
efb80947b01107dafbbf0157de0d7e1af6551259ahrens#define DO32(X) (drr->drr_u.X = BSWAP_32(drr->drr_u.X))
efb80947b01107dafbbf0157de0d7e1af6551259ahrens /* DO64(drr_object.drr_allocation_txg); */
8e7144747a94247ce9dbb4fb1f67bdcb666b30d8Lori Alt DO64(drr_write_byref.drr_key.ddk_cksum.zc_word[0]);
8e7144747a94247ce9dbb4fb1f67bdcb666b30d8Lori Alt DO64(drr_write_byref.drr_key.ddk_cksum.zc_word[1]);
8e7144747a94247ce9dbb4fb1f67bdcb666b30d8Lori Alt DO64(drr_write_byref.drr_key.ddk_cksum.zc_word[2]);
8e7144747a94247ce9dbb4fb1f67bdcb666b30d8Lori Alt DO64(drr_write_byref.drr_key.ddk_cksum.zc_word[3]);
efb80947b01107dafbbf0157de0d7e1af6551259ahrensrestore_object(struct restorearg *ra, objset_t *os, struct drr_object *drro)
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt drro->drr_checksumtype >= ZIO_CHECKSUM_FUNCTIONS ||
2bf405a25eb25f79638fc951ff8d8857ad384417Mark Maybee err = dmu_object_info(os, drro->drr_object, NULL);
adee0b6f10e370500326bde344e66b6662e0b9dcTim Haley data = restore_read(ra, P2ROUNDUP(drro->drr_bonuslen, 8));
efb80947b01107dafbbf0157de0d7e1af6551259ahrens /* currently free, want to be allocated */
efb80947b01107dafbbf0157de0d7e1af6551259ahrens /* currently allocated, want to be allocated */
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt dmu_object_set_checksum(os, drro->drr_object, drro->drr_checksumtype,
efb80947b01107dafbbf0157de0d7e1af6551259ahrens dmu_object_set_compress(os, drro->drr_object, drro->drr_compress, tx);
efb80947b01107dafbbf0157de0d7e1af6551259ahrens VERIFY(0 == dmu_bonus_hold(os, drro->drr_object, FTAG, &db));
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden dmu_ot_byteswap[byteswap].ob_func(db->db_data,
efb80947b01107dafbbf0157de0d7e1af6551259ahrens return (0);
efb80947b01107dafbbf0157de0d7e1af6551259ahrens/* ARGSUSED */
efb80947b01107dafbbf0157de0d7e1af6551259ahrensrestore_freeobjects(struct restorearg *ra, objset_t *os,
efb80947b01107dafbbf0157de0d7e1af6551259ahrens if (drrfo->drr_firstobj + drrfo->drr_numobjs < drrfo->drr_firstobj)
efb80947b01107dafbbf0157de0d7e1af6551259ahrens return (0);
efb80947b01107dafbbf0157de0d7e1af6551259ahrens if (drrw->drr_offset + drrw->drr_length < drrw->drr_offset ||
efb80947b01107dafbbf0157de0d7e1af6551259ahrens if (dmu_object_info(os, drrw->drr_object, NULL) != 0)
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden dmu_ot_byteswap[byteswap].ob_func(data, drrw->drr_length);
efb80947b01107dafbbf0157de0d7e1af6551259ahrens return (0);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * Handle a DRR_WRITE_BYREF record. This record is used in dedup'ed
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * streams to refer to a copy of the data that is already on the
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * system because it came in earlier in the stream. This function
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * finds the earlier copy of the data, and uses that copy instead of
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * data from the stream to fulfill this write.
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Altrestore_write_byref(struct restorearg *ra, objset_t *os,
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt if (drrwbr->drr_offset + drrwbr->drr_length < drrwbr->drr_offset)
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * If the GUID of the referenced dataset is different from the
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt * GUID of the target dataset, find the referenced dataset.
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby if ((gmep = avl_find(ra->guid_to_ds_map, &gmesrch,
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt if (err = dmu_buf_hold(ref_os, drrwbr->drr_refobject,
47cb52daa729f19e298c85a84e8df069365c5232Jeff Bonwick drrwbr->drr_refoffset, FTAG, &dbp, DMU_READ_PREFETCH))
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt drrwbr->drr_offset, drrwbr->drr_length, dbp->db_data, tx);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt return (0);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaumrestore_spill(struct restorearg *ra, objset_t *os, struct drr_spill *drrs)
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum if (dmu_object_info(os, drrs->drr_object, NULL) != 0)
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum VERIFY(0 == dmu_bonus_hold(os, drrs->drr_object, FTAG, &db));
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum if ((err = dmu_spill_hold_by_bonus(db, FTAG, &db_spill)) != 0) {
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum bcopy(data, db_spill->db_data, drrs->drr_length);
efb80947b01107dafbbf0157de0d7e1af6551259ahrens/* ARGSUSED */
efb80947b01107dafbbf0157de0d7e1af6551259ahrens drrf->drr_offset + drrf->drr_length < drrf->drr_offset)
efb80947b01107dafbbf0157de0d7e1af6551259ahrens if (dmu_object_info(os, drrf->drr_object, NULL) != 0)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens/* used to destroy the drc_ds on error */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dataset_disown(drc->drc_ds, dmu_recv_tag);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens * NB: callers *must* call dmu_recv_end() if this succeeds.
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirbydmu_recv_stream(dmu_recv_cookie_t *drc, vnode_t *vp, offset_t *voffp,
3cb34c601f3ef3016f638574f5982e80c3735c71ahrens /* these were verified in dmu_recv_begin */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT3U(DMU_GET_STREAM_HDRTYPE(drc->drc_drrb->drr_versioninfo), ==,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT3U(drc->drc_drrb->drr_type, <, DMU_OST_NUMTYPES);
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * Open the objset we are modifying.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dmu_objset_from_ds(drc->drc_ds, &os));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT(drc->drc_ds->ds_phys->ds_flags & DS_FLAG_INCONSISTENT);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt featureflags = DMU_GET_FEATUREFLAGS(drc->drc_drrb->drr_versioninfo);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt /* if this stream is dedup'ed, set up the avl tree for guid mapping */
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby ra.err = zfs_onexit_fd_hold(cleanup_fd, &minor);
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby ra.err = zfs_onexit_cb_data(minor, *action_handlep,
ec5cf9d53a1d7280f3f1a6eadd7cdabdc99814ebAlexander Stetsenko drc->drc_guid_to_ds_map = ra.guid_to_ds_map;
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * Read records and process them.
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * We need to make a copy of the record header,
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * because restore_{object,write} may need to
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * restore_read(), which will invalidate drr.
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * We compare against the *previous* checksum
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * value, because the stored checksum is of
efb80947b01107dafbbf0157de0d7e1af6551259ahrens * everything before the DRR_END record.
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum struct drr_spill drrs = drr->drr_u.drr_spill;
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby if ((featureflags & DMU_BACKUP_FEATURE_DEDUP) && (cleanup_fd != -1))
f4b94bde302dc950da6b4ec29936dd9a7b9d61abMatthew Ahrens * destroy what we created, so we don't leave it in the
f4b94bde302dc950da6b4ec29936dd9a7b9d61abMatthew Ahrens * inconsistent restoring state.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT3P(drc->drc_ds->ds_owner, ==, dmu_recv_tag);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, drc->drc_tofs, FTAG, &origin_head);
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens * We will destroy any snapshots in tofs (i.e. before
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens * origin_head) that are after the origin (which is
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens * the snap before drc_ds, because drc_ds can not
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens * have any snaps of its own).
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens uint64_t obj = origin_head->ds_phys->ds_prev_snap_obj;
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens while (obj != drc->drc_ds->ds_phys->ds_prev_snap_obj) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_clone_swap_check_impl(drc->drc_ds,
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowski origin_head, drc->drc_force, drc->drc_owner, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_snapshot_check_impl(origin_head,
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek drc->drc_tosnap, tx, B_TRUE, 1, drc->drc_cred);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_destroy_head_check_impl(drc->drc_ds, 1);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_snapshot_check_impl(drc->drc_ds,
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek drc->drc_tosnap, tx, B_TRUE, 1, drc->drc_cred);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens spa_history_log_internal_ds(drc->drc_ds, "finish receiving",
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_hold(dp, drc->drc_tofs, FTAG,
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens * Destroy any snapshots of drc_tofs (origin_head)
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens * after the origin (the snap before drc_ds).
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens uint64_t obj = origin_head->ds_phys->ds_prev_snap_obj;
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens while (obj != drc->drc_ds->ds_phys->ds_prev_snap_obj) {
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens ASSERT3P(snap->ds_dir, ==, origin_head->ds_dir);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dataset_clone_swap_sync_impl(drc->drc_ds,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* set snapshot's creation time and guid */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dmu_buf_will_dirty(origin_head->ds_prev->ds_dbuf, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens origin_head->ds_prev->ds_phys->ds_creation_time =
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dmu_buf_will_dirty(origin_head->ds_dbuf, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens origin_head->ds_phys->ds_flags &= ~DS_FLAG_INCONSISTENT;
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowski VERIFY3P(origin_head->ds_owner, ==, drc->drc_owner);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dataset_snapshot_sync_impl(ds, drc->drc_tosnap, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* set snapshot's creation time and guid */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dmu_buf_will_dirty(ds->ds_prev->ds_dbuf, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ds->ds_prev->ds_phys->ds_guid = drc->drc_drrb->drr_toguid;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ds->ds_prev->ds_phys->ds_flags &= ~DS_FLAG_INCONSISTENT;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ds->ds_phys->ds_flags &= ~DS_FLAG_INCONSISTENT;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens drc->drc_newsnapobj = drc->drc_ds->ds_phys->ds_prev_snap_obj;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Release the hold from dmu_recv_begin. This must be done before
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * we return to open context, so that when we free the dataset's dnode,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * we can evict its bonus buffer.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dataset_disown(drc->drc_ds, dmu_recv_tag);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensadd_ds_to_guidmap(const char *name, avl_tree_t *guid_map, uint64_t snapobj)
de8d9cff565e928d0ace86f3ea0e2b15094d61dfMatthew Ahrens err = dsl_dataset_hold_obj(dp, snapobj, gmep, &snapds);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * We will be destroying the ds; make sure its origin is unmounted if
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens } else if (drc->drc_guid_to_ds_map != NULL) {
91948b51b8e978ddc88a36b2bc3ae83c20cdc9aaKeith M Wesolowskidmu_recv_end(dmu_recv_cookie_t *drc, void *owner)
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * Return TRUE if this objset is currently being received into.