dmu_send.c revision b515258426fed6c7311fd3f1dea697cfbd4085c6
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.
7802d7bf98dec568dadf72286893b1fe5abd8602Matthew Ahrens * Copyright (c) 2011, 2014 by Delphix. All rights reserved.
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * Copyright (c) 2014, Joyent, Inc. All rights reserved.
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens * Copyright 2014 HybridCluster. 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);
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrensdump_write(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));
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * There's no pre-computed checksum for partial-block
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * writes or embedded BP's, so (like
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * fletcher4-checkummed blocks) userland will have to
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * compute a dedup-capable checksum itself.
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens drrw->drr_checksumtype = BP_GET_CHECKSUM(bp);
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if (zio_checksum_table[drrw->drr_checksumtype].ci_dedup)
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens drrw->drr_checksumflags |= DRR_CHECKSUM_DEDUP;
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens DDK_SET_LSIZE(&drrw->drr_key, BP_GET_LSIZE(bp));
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens DDK_SET_PSIZE(&drrw->drr_key, BP_GET_PSIZE(bp));
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens 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);
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrensdump_write_embedded(dmu_sendarg_t *dsp, uint64_t object, uint64_t offset,
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens bzero(dsp->dsa_drr, sizeof (dmu_replay_record_t));
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if (dump_bytes(dsp, dsp->dsa_drr, sizeof (dmu_replay_record_t)) != 0)
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if (dump_bytes(dsp, buf, P2ROUNDUP(drrw->drr_psize, 8)) != 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;
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens if (!(dsp->dsa_featureflags & DMU_BACKUP_FEATURE_LARGE_BLOCKS) &&
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);
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrensbackup_do_embed(dmu_sendarg_t *dsp, const blkptr_t *bp)
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens * Compression function must be legacy, or explicitly enabled.
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if ((BP_GET_COMPRESS(bp) >= ZIO_COMPRESS_LEGACY_FUNCTIONS &&
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens !(dsp->dsa_featureflags & DMU_BACKUP_FEATURE_EMBED_DATA_LZ4)))
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens * Embed type must be explicitly enabled.
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if (dsp->dsa_featureflags & DMU_BACKUP_FEATURE_EMBED_DATA)
efb80947b01107dafbbf0157de0d7e1af6551259ahrens (((uint64_t)dnp->dn_datablkszsec) << (SPA_MINBLOCKSHIFT + \
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick/* ARGSUSED */
1b912ec7100c10e7243bf0879af0fe580e08c73dGeorge Wilsonbackup_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
7802d7bf98dec568dadf72286893b1fe5abd8602Matthew Ahrens const zbookmark_phys_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);
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens /* it's an embedded level-0 block of a regular object */
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens int blksz = dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT;
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens err = dump_write_embedded(dsp, zb->zb_object,
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens } else { /* it's a level-0 block of a regular object */
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens ASSERT3U(blksz, ==, dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
1b912ec7100c10e7243bf0879af0fe580e08c73dGeorge Wilson if (arc_read(NULL, spa, bp, arc_getbuf_func, &abuf,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens /* Send a block filled with 0x"zfs badd bloc" */
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * Releases dp using the specified tag.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_send_impl(void *tag, dsl_pool_t *dp, dsl_dataset_t *ds,
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens zfs_bookmark_phys_t *fromzb, boolean_t is_clone, boolean_t embedok,
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens boolean_t large_block_ok, int outfd, vnode_t *vp, offset_t *off)
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) {
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens featureflags |= DMU_BACKUP_FEATURE_LARGE_BLOCKS;
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens spa_feature_is_active(dp->dp_spa, SPA_FEATURE_EMBEDDED_DATA)) {
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens featureflags |= DMU_BACKUP_FEATURE_EMBED_DATA;
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if (spa_feature_is_active(dp->dp_spa, SPA_FEATURE_LZ4_COMPRESS))
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens featureflags |= DMU_BACKUP_FEATURE_EMBED_DATA_LZ4;
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens DMU_SET_FEATUREFLAGS(drr->drr_u.drr_begin.drr_versioninfo,
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;
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens err = dmu_send_impl(FTAG, dp, ds, &zb, is_clone,
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens err = dmu_send_impl(FTAG, dp, ds, NULL, B_FALSE,
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew 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);
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens err = dmu_send_impl(FTAG, dp, ds, &zb, is_clone,
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew 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;
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens uint64_t featureflags = DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo);
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 */
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if ((featureflags & DMU_BACKUP_FEATURE_SA_SPILL) &&
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens * The receiving code doesn't know how to translate a WRITE_EMBEDDED
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens * record to a plan WRITE record, so the pool must have the
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens * EMBEDDED_DATA feature enabled if the stream has WRITE_EMBEDDED
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens * records. Same with WRITE_EMBEDDED records that use LZ4 compression.
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if ((featureflags & DMU_BACKUP_FEATURE_EMBED_DATA) &&
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens !spa_feature_is_enabled(dp->dp_spa, SPA_FEATURE_EMBEDDED_DATA))
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if ((featureflags & DMU_BACKUP_FEATURE_EMBED_DATA_LZ4) &&
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens !spa_feature_is_enabled(dp->dp_spa, SPA_FEATURE_LZ4_COMPRESS))
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * The receiving code doesn't know how to translate large blocks
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * to smaller ones, so the pool must have the LARGE_BLOCKS
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens * feature enabled if the stream has LARGE_BLOCKS.
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens if ((featureflags & DMU_BACKUP_FEATURE_LARGE_BLOCKS) &&
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens !spa_feature_is_enabled(dp->dp_spa, SPA_FEATURE_LARGE_BLOCKS))
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));
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens if ((DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo) &
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens dsl_dataset_activate_large_blocks_sync_impl(dsobj, tx);
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 *
8a9047098ad8ce5afa38b6d012c8b509bb619f40Matthew Ahrensrestore_read(struct restorearg *ra, int len, char *buf)
efb80947b01107dafbbf0157de0d7e1af6551259ahrens /* some things will require 8-byte alignment, so everything must */
8a9047098ad8ce5afa38b6d012c8b509bb619f40Matthew Ahrens fletcher_4_incremental_byteswap(buf, len, &ra->cksum);
8a9047098ad8ce5afa38b6d012c8b509bb619f40Matthew Ahrens fletcher_4_incremental_native(buf, 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))
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]);
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrensdeduce_nblkptr(dmu_object_type_t bonus_type, uint64_t bonus_size)
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens ((DN_MAX_BONUSLEN - bonus_size) >> SPA_BLKPTRSHIFT));
efb80947b01107dafbbf0157de0d7e1af6551259ahrensrestore_object(struct restorearg *ra, objset_t *os, struct drr_object *drro)
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt drro->drr_checksumtype >= ZIO_CHECKSUM_FUNCTIONS ||
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens drro->drr_blksz > spa_maxblocksize(dmu_objset_spa(os)) ||
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens err = dmu_object_info(os, drro->drr_object, &doi);
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens object = err == 0 ? drro->drr_object : DMU_NEW_OBJECT;
8a9047098ad8ce5afa38b6d012c8b509bb619f40Matthew Ahrens data = restore_read(ra, P2ROUNDUP(drro->drr_bonuslen, 8), NULL);
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens * If we are losing blkptrs or changing the block size this must
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens * be a new file instance. We must clear out the previous file
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens * contents before we can change this type of metadata in the dnode.
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens nblkptr = deduce_nblkptr(drro->drr_bonustype,
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens if (drro->drr_blksz != doi.doi_data_block_size ||
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens err = dmu_free_long_range(os, drro->drr_object,
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens /* currently free, want to be allocated */
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens drro->drr_blksz != doi.doi_data_block_size ||
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens /* currently allocated, but with different properties */
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens drro->drr_bonustype, drro->drr_bonuslen, tx);
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)
8a9047098ad8ce5afa38b6d012c8b509bb619f40Matthew Ahrens if (dmu_bonus_hold(os, drrw->drr_object, FTAG, &bonus) != 0)
8a9047098ad8ce5afa38b6d012c8b509bb619f40Matthew Ahrens arc_buf_t *abuf = dmu_request_arcbuf(bonus, drrw->drr_length);
8a9047098ad8ce5afa38b6d012c8b509bb619f40Matthew Ahrens data = restore_read(ra, drrw->drr_length, abuf->b_data);
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden dmu_ot_byteswap[byteswap].ob_func(data, drrw->drr_length);
8a9047098ad8ce5afa38b6d012c8b509bb619f40Matthew Ahrens dmu_assign_arcbuf(bonus, drrw->drr_offset, abuf, tx);
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,
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens err = dmu_buf_hold(ref_os, drrwbr->drr_refobject,
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens drrwbr->drr_refoffset, FTAG, &dbp, DMU_READ_PREFETCH);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt drrwbr->drr_offset, drrwbr->drr_length, dbp->db_data, tx);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt return (0);
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrensrestore_write_embedded(struct restorearg *ra, objset_t *os,
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if (drrwnp->drr_offset + drrwnp->drr_length < drrwnp->drr_offset)
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if (drrwnp->drr_etype >= NUM_BP_EMBEDDED_TYPES)
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if (drrwnp->drr_compression >= ZIO_COMPRESS_FUNCTIONS)
8a9047098ad8ce5afa38b6d012c8b509bb619f40Matthew Ahrens data = restore_read(ra, P2ROUNDUP(drrwnp->drr_psize, 8), NULL);
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens drrwnp->drr_compression, drrwnp->drr_lsize, drrwnp->drr_psize,
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaumrestore_spill(struct restorearg *ra, objset_t *os, struct drr_spill *drrs)
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens drrs->drr_length > spa_maxblocksize(dmu_objset_spa(os)))
8a9047098ad8ce5afa38b6d012c8b509bb619f40Matthew Ahrens data = restore_read(ra, drrs->drr_length, NULL);
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.
8a9047098ad8ce5afa38b6d012c8b509bb619f40Matthew Ahrens NULL != (drr = restore_read(&ra, sizeof (*drr), NULL))) {
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.
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens ra.err = restore_write_embedded(&ra, os, &drrwe);
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
7d46dc6ca63a6f3f0d51aa655bfcf10cf2405a9eMatthew Ahrens dmu_recv_end_modified_blocks, ZFS_SPACE_CHECK_NORMAL);
7d46dc6ca63a6f3f0d51aa655bfcf10cf2405a9eMatthew Ahrens dmu_recv_end_modified_blocks, ZFS_SPACE_CHECK_NORMAL);
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.