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.
ca0cc3918a1789fa839194af2a9245f801a06b1aMatthew Ahrens * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * Copyright (c) 2014, Joyent, Inc. All rights reserved.
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens * Copyright 2014 HybridCluster. All rights reserved.
880094b6062aebeec8eda6a8651757611c83b13eAndrew Stormont * Copyright 2016 RackTop Systems.
c3d26abc9ee97b4f60233556aadeb57e0bd30bb9Matthew Ahrens * Copyright (c) 2014 Integros [integros.com]
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens/* Set this tunable to TRUE to replace corrupt data with 0x2f5baddb10c */
880094b6062aebeec8eda6a8651757611c83b13eAndrew Stormont/* Set this tunable to FALSE to disable setting of DRR_FLAG_FREERECORDS */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie#define BP_SPAN(datablkszsec, indblkshift, level) \
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie (((uint64_t)datablkszsec) << (SPA_MINBLOCKSHIFT + \
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrensstatic void byteswap_record(dmu_replay_record_t *drr);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie uint64_t fromtxg; /* Traverse from this txg */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie int flags; /* flags to pass to traverse_dataset */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie boolean_t eos_marker; /* Marks the end of the stream */
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewskidump_bytes(dmu_sendarg_t *dsp, void *buf, int len)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens dsl_dataset_t *ds = dmu_objset_ds(dsp->dsa_os);
efb80947b01107dafbbf0157de0d7e1af6551259ahrens ssize_t resid; /* have to get resid to get detailed errno */
c20404ff77119516354b0d112d28b7ea0dadd303Eli Rosenthal * The code does not rely on this (len being a multiple of 8). We keep
c20404ff77119516354b0d112d28b7ea0dadd303Eli Rosenthal * this assertion because of the corresponding assertion in
c20404ff77119516354b0d112d28b7ea0dadd303Eli Rosenthal * receive_read(). Keeping this assertion ensures that we do not
c20404ff77119516354b0d112d28b7ea0dadd303Eli Rosenthal * inadvertently break backwards compatibility (causing the assertion
c20404ff77119516354b0d112d28b7ea0dadd303Eli Rosenthal * in receive_read() to trigger on old software).
c20404ff77119516354b0d112d28b7ea0dadd303Eli Rosenthal * Removing the assertions could be rolled into a new feature that uses
c20404ff77119516354b0d112d28b7ea0dadd303Eli Rosenthal * data that isn't 8-byte aligned; if the assertions were removed, a
c20404ff77119516354b0d112d28b7ea0dadd303Eli Rosenthal * feature flag would have to be added.
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski dsp->dsa_err = vn_rdwr(UIO_WRITE, dsp->dsa_vp,
efb80947b01107dafbbf0157de0d7e1af6551259ahrens 0, UIO_SYSSPACE, FAPPEND, RLIM64_INFINITY, CRED(), &resid);
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens * For all record types except BEGIN, fill in the checksum (overlaid in
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens * drr_u.drr_checksum.drr_checksum). The checksum verifies everything
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens * up to the start of the checksum itself.
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrensdump_record(dmu_sendarg_t *dsp, void *payload, int payload_len)
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens ASSERT3U(offsetof(dmu_replay_record_t, drr_u.drr_checksum.drr_checksum),
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens ==, sizeof (dmu_replay_record_t) - sizeof (zio_cksum_t));
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens offsetof(dmu_replay_record_t, drr_u.drr_checksum.drr_checksum),
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens ASSERT(ZIO_CHECKSUM_IS_ZERO(&dsp->dsa_drr->drr_u.
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens dsp->dsa_drr->drr_u.drr_checksum.drr_checksum = dsp->dsa_zc;
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens fletcher_4_incremental_native(&dsp->dsa_drr->
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens if (dump_bytes(dsp, dsp->dsa_drr, sizeof (dmu_replay_record_t)) != 0)
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens fletcher_4_incremental_native(payload, payload_len,
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens if (dump_bytes(dsp, payload, payload_len) != 0)
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * Fill in the drr_free struct, or perform aggregation if the previous record is
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * also a free record, and the two are adjacent.
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * Note that we send free records even for a full send, because we want to be
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * able to receive a full send as a clone, which requires a list of all the free
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * and freeobject records that were generated on the source.
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
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew 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
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 /* 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,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel uint64_t object, uint64_t offset, int lsize, int psize, const blkptr_t *bp,
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.
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.
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens /* write a WRITE record */
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski bzero(dsp->dsa_drr, sizeof (dmu_replay_record_t));
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel /* only set the compression fields if the buf is compressed */
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel ASSERT(dsp->dsa_featureflags & DMU_BACKUP_FEATURE_COMPRESSED);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel ASSERT3U(BP_GET_COMPRESS(bp), !=, ZIO_COMPRESS_OFF);
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);
45818ee124adeaaf947698996b4f4c722afc6d1fMatthew Ahrens if (zio_checksum_table[drrw->drr_checksumtype].ci_flags &
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));
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));
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens if (dump_record(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 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);
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 */
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);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * Note: when resuming, we will visit all the dnodes in
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * the block of dnodes that we are resuming from. In
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * this case it's unnecessary to send the dnodes prior to
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * the one we are resuming from. We should be at most one
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * block's worth of dnodes behind the resume point.
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) &&
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 &&
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel !(dsp->dsa_featureflags & DMU_BACKUP_FEATURE_LZ4)))
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens * Embed type must be explicitly enabled.
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens if (dsp->dsa_featureflags & DMU_BACKUP_FEATURE_EMBED_DATA)
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * This is the callback function to traverse_dataset that acts as the worker
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * thread for dmu_send_impl.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliesend_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie const zbookmark_phys_t *zb, const struct dnode_phys *dnp, void *arg)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens ASSERT(zb->zb_object == DMU_META_DNODE_OBJECT ||
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie record = kmem_zalloc(sizeof (struct send_block_record), KM_SLEEP);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie record_size = dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * This function kicks off the traverse_dataset. It also handles setting the
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * error code of the thread in case something goes wrong, and pushes the End of
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Stream record when the traverse_dataset call has finished. If there is no
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * dataset to traverse, the thread immediately pushes End of Stream marker.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * This function actually handles figuring out what kind of record needs to be
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * dumped, reading the data (which has hopefully been prefetched), and calling
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * the appropriate helper function.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliedo_dump(dmu_sendarg_t *dsa, struct send_block_record *data)
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie dsl_dataset_t *ds = dmu_objset_ds(dsa->dsa_os);
efb80947b01107dafbbf0157de0d7e1af6551259ahrens dmu_object_type_t type = bp ? BP_GET_TYPE(bp) : DMU_OT_NONE;
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens ASSERT(zb->zb_object == DMU_META_DNODE_OBJECT ||
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie uint64_t span = BP_SPAN(dblkszsec, indblkshift, zb->zb_level);
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens uint64_t dnobj = (zb->zb_blkid * span) >> DNODE_SHIFT;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = dump_freeobjects(dsa, dnobj, span >> DNODE_SHIFT);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie uint64_t span = BP_SPAN(dblkszsec, indblkshift, zb->zb_level);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = dump_free(dsa, zb->zb_object, offset, 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,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie uint64_t dnobj = zb->zb_blkid * (blksz >> DNODE_SHIFT);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie for (int i = 0; i < blksz >> DNODE_SHIFT; i++) {
1b912ec7100c10e7243bf0879af0fe580e08c73dGeorge Wilson if (arc_read(NULL, spa, bp, arc_getbuf_func, &abuf,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = dump_spill(dsa, zb->zb_object, blksz, abuf->b_data);
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens /* it's an embedded level-0 block of a regular object */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie /* it's a level-0 block of a regular object */
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * If we have large blocks stored on disk but the send flags
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * don't allow us to send large blocks, we split the data from
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * the arc buf into chunks.
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel boolean_t split_large_blocks = blksz > SPA_OLD_MAXBLOCKSIZE &&
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel !(dsa->dsa_featureflags & DMU_BACKUP_FEATURE_LARGE_BLOCKS);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * We should only request compressed data from the ARC if all
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * the following are true:
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * - stream compression was requested
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * - we aren't splitting large blocks into smaller chunks
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * - the data won't need to be byteswapped before sending
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * - this isn't an embedded block
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * - this isn't metadata (if receiving on a different endian
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * system it can be byteswapped more easily)
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel (dsa->dsa_featureflags & DMU_BACKUP_FEATURE_COMPRESSED) &&
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel !split_large_blocks && !BP_SHOULD_BYTESWAP(bp) &&
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel !BP_IS_EMBEDDED(bp) && !DMU_OT_IS_METADATA(BP_GET_TYPE(bp));
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel zb->zb_blkid * blksz >= dsa->dsa_resume_offset));
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens ASSERT(zb->zb_object > dsa->dsa_resume_object ||
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens zb->zb_blkid * blksz >= dsa->dsa_resume_offset));
1b912ec7100c10e7243bf0879af0fe580e08c73dGeorge Wilson if (arc_read(NULL, spa, bp, arc_getbuf_func, &abuf,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel ZIO_PRIORITY_ASYNC_READ, zioflags, &aflags, zb) != 0) {
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens /* Send a block filled with 0x"zfs badd bloc" */
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel err = dump_write(dsa, type, zb->zb_object, offset,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Pop the new data off the queue, and free the old data.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelieget_next_record(bqueue_t *bq, struct send_block_record *data)
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie struct send_block_record *tmp = bqueue_dequeue(bq);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Actually do the bulk of the work in a zfs send.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Note: Releases dp using the specified tag.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliedmu_send_impl(void *tag, dsl_pool_t *dp, dsl_dataset_t *to_ds,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel zfs_bookmark_phys_t *ancestor_zb, boolean_t is_clone,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel boolean_t embedok, boolean_t large_block_ok, boolean_t compressok,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel int outfd, uint64_t resumeobj, uint64_t resumeoff,
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) {
ca0cc3918a1789fa839194af2a9245f801a06b1aMatthew Ahrens if (large_block_ok && to_ds->ds_feature_inuse[SPA_FEATURE_LARGE_BLOCKS])
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))
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel (DMU_BACKUP_FEATURE_EMBED_DATA | DMU_BACKUP_FEATURE_COMPRESSED)) !=
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel 0 && spa_feature_is_active(dp->dp_spa, SPA_FEATURE_LZ4_COMPRESS)) {
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);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie drr->drr_u.drr_begin.drr_toguid = dsl_dataset_phys(to_ds)->ds_guid;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (dsl_dataset_phys(to_ds)->ds_flags & DS_FLAG_CI_DATASET)
880094b6062aebeec8eda6a8651757611c83b13eAndrew Stormont drr->drr_u.drr_begin.drr_flags |= DRR_FLAG_FREERECORDS;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie dsl_dataset_name(to_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);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie dsp->dsa_toguid = dsl_dataset_phys(to_ds)->ds_guid;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie list_insert_head(&to_ds->ds_sendstreams, dsp);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens err = dmu_object_info(os, resumeobj, &to_doi);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens SET_BOOKMARK(&to_arg.resume, to_ds->ds_object, resumeobj, 0,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens fnvlist_add_uint64(nvl, "resume_object", resumeobj);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens fnvlist_add_uint64(nvl, "resume_offset", resumeoff);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens err = dump_record(dsp, payload, payload_len);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = bqueue_init(&to_arg.q, zfs_send_queue_length,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie to_arg.flags = TRAVERSE_PRE | TRAVERSE_PREFETCH;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie (void) thread_create(NULL, 0, send_traverse_thread, &to_arg, 0, curproc,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie to_data = get_next_record(&to_arg.q, to_data);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie to_data = get_next_record(&to_arg.q, to_data);
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski drr->drr_u.drr_end.drr_checksum = dsp->dsa_zc;
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski drr->drr_u.drr_end.drr_toguid = dsp->dsa_toguid;
12b90ee2d3b10689fc45f4930d2392f5fe1d9cfaMatt Krantz VERIFY(err != 0 || (dsp->dsa_sent_begin && dsp->dsa_sent_end));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdmu_send_obj(const char *pool, uint64_t tosnap, uint64_t fromsnap,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel boolean_t embedok, boolean_t large_block_ok, boolean_t compressok,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_dataset_hold_obj(dp, tosnap, FTAG, &ds);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens err = dsl_dataset_hold_obj(dp, fromsnap, FTAG, &fromds);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs zb.zbm_creation_txg = dsl_dataset_phys(fromds)->ds_creation_txg;
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs zb.zbm_guid = dsl_dataset_phys(fromds)->ds_guid;
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens err = dmu_send_impl(FTAG, dp, ds, &zb, is_clone,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel embedok, large_block_ok, compressok, outfd, 0, 0, vp, off);
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens err = dmu_send_impl(FTAG, dp, ds, NULL, B_FALSE,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel embedok, large_block_ok, compressok, outfd, 0, 0, vp, off);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrensdmu_send(const char *tosnap, const char *fromsnap, boolean_t embedok,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel boolean_t large_block_ok, boolean_t compressok, int outfd,
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);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs zb.zbm_guid = dsl_dataset_phys(fromds)->ds_guid;
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,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmeldmu_adjust_send_estimate_for_indirects(dsl_dataset_t *ds, uint64_t uncompressed,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel uint64_t compressed, boolean_t stream_compressed, uint64_t *sizep)
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * Assume that space (both on-disk and in-stream) is dominated by
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * data. We will adjust for indirect blocks and the copies property,
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * but ignore per-object space used (eg, dnodes and DRR_OBJECT records).
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel /* Assume all (uncompressed) blocks are recordsize. */
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel err = dsl_prop_get_int_ds(ds, zfs_prop_to_name(ZFS_PROP_RECORDSIZE),
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * If we're estimating a send size for a compressed stream, use the
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * compressed data size to estimate the stream size. Otherwise, use the
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * uncompressed data size.
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel size = stream_compressed ? compressed : uncompressed;
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * Subtract out approximate space used by indirect blocks.
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * Assume most space is used by data blocks (non-indirect, non-dnode).
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * Assume no ditto blocks or internal fragmentation.
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * Therefore, space used by indirect blocks is sizeof(blkptr_t) per
643da460c8ca583e39ce053081754e24087f84c8Max Grossman /* Add in the space for the record associated with each block. */
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel size += record_count * sizeof (dmu_replay_record_t);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmeldmu_send_estimate(dsl_dataset_t *ds, dsl_dataset_t *fromds,
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrens /* tosnap must be a snapshot */
24218bebb460e4015fac2c9f2cec1902eddbcd7bAndriy Gapon /* fromsnap, if provided, 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))
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel /* Get compressed and uncompressed size estimates of changed data. */
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel uncomp = dsl_dataset_phys(ds)->ds_uncompressed_bytes;
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel comp = dsl_dataset_phys(ds)->ds_compressed_bytes;
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel err = dmu_adjust_send_estimate_for_indirects(ds, uncomp, comp,
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * Simple callback used to traverse the blocks of a snapshot and sum their
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * uncompressed and compressed sizes.
643da460c8ca583e39ce053081754e24087f84c8Max Grossman/* ARGSUSED */
643da460c8ca583e39ce053081754e24087f84c8Max Grossmandmu_calculate_send_traversal(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
643da460c8ca583e39ce053081754e24087f84c8Max Grossman const zbookmark_phys_t *zb, const dnode_phys_t *dnp, void *arg)
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * Given a desination snapshot and a TXG, calculate the approximate size of a
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * send stream sent from that TXG. from_txg may be zero, indicating that the
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * whole snapshot will be sent.
643da460c8ca583e39ce053081754e24087f84c8Max Grossmandmu_send_estimate_from_txg(dsl_dataset_t *ds, uint64_t from_txg,
643da460c8ca583e39ce053081754e24087f84c8Max Grossman /* tosnap must be a snapshot */
643da460c8ca583e39ce053081754e24087f84c8Max Grossman /* verify that from_txg is before the provided snapshot was taken */
643da460c8ca583e39ce053081754e24087f84c8Max Grossman if (from_txg >= dsl_dataset_phys(ds)->ds_creation_txg) {
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * traverse the blocks of the snapshot with birth times after
643da460c8ca583e39ce053081754e24087f84c8Max Grossman * from_txg, summing their uncompressed size
643da460c8ca583e39ce053081754e24087f84c8Max Grossman err = traverse_dataset(ds, from_txg, TRAVERSE_POST,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel err = dmu_adjust_send_estimate_for_indirects(ds, size.uncompressed,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensrecv_begin_check_existing_impl(dmu_recv_begin_arg_t *drba, dsl_dataset_t *ds,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* temporary clone name must not exist */
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dir_phys(ds->ds_dir)->dd_child_dir_zapobj, recv_clone_name,
feaa74e41c407fe56e66a47e097c2842d4f65b9fMark Maybee /* new snapshot name must not exist */
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,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs uint64_t obj = dsl_dataset_phys(ds)->ds_prev_snap_obj;
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens /* Find snapshot in this dir that matches fromguid. */
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens while (obj != 0) {
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs if (dsl_dataset_phys(snap)->ds_guid == fromguid)
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs obj = dsl_dataset_phys(snap)->ds_prev_snap_obj;
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)) {
5bae108fe2364722de3aa86e04966a0d33fd027aAndriy Gapon /* if full, then must be forced */
5bae108fe2364722de3aa86e04966a0d33fd027aAndriy Gapon /* start from $ORIGIN@$ORIGIN, if supported */
5bae108fe2364722de3aa86e04966a0d33fd027aAndriy Gapon drba->drba_snapobj = dp->dp_origin_snap != NULL ?
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);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens ASSERT(!(featureflags & DMU_BACKUP_FEATURE_RESUMING));
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) &&
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens !spa_feature_is_enabled(dp->dp_spa, SPA_FEATURE_EXTENSIBLE_DATASET))
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens * The receiving code doesn't know how to translate a WRITE_EMBEDDED
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * record to a plain 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 !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 */
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie if (flags & DRR_FLAG_CLONE || drba->drba_origin) {
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.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (fromguid != 0 && !(flags & DRR_FLAG_CLONE ||
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * If we're receiving a full send as a clone, and it doesn't
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * contain all the necessary free records and freeobject
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * records, reject it.
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,
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie if (dsl_dataset_phys(origin)->ds_guid != fromguid &&
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 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));
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens VERIFY0(zap_add(mos, dsobj, DS_FIELD_RESUME_FROMGUID,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens VERIFY0(zap_add(mos, dsobj, DS_FIELD_RESUME_TOGUID,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens VERIFY0(zap_add(mos, dsobj, DS_FIELD_RESUME_TONAME,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens 1, strlen(drrb->drr_toname) + 1, drrb->drr_toname, tx));
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens VERIFY0(zap_add(mos, dsobj, DS_FIELD_RESUME_OBJECT,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens VERIFY0(zap_add(mos, dsobj, DS_FIELD_RESUME_OFFSET,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens VERIFY0(zap_add(mos, dsobj, DS_FIELD_RESUME_BYTES,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel if (DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo) &
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel VERIFY0(zap_add(mos, dsobj, DS_FIELD_RESUME_LARGEBLOCK,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if (DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo) &
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens VERIFY0(zap_add(mos, dsobj, DS_FIELD_RESUME_EMBEDOK,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel if (DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo) &
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel VERIFY0(zap_add(mos, dsobj, DS_FIELD_RESUME_COMPRESSOK,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(newds)->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.
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_enter(&newds->ds_bp_rwlock, RW_READER, FTAG);
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, "");
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrensdmu_recv_resume_begin_check(void *arg, dmu_tx_t *tx)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens struct drr_begin *drrb = drba->drba_cookie->drc_drrb;
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens uint64_t featureflags = DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens const char *tofs = drba->drba_cookie->drc_tofs;
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* already checked */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens ASSERT3U(drrb->drr_magic, ==, DMU_BACKUP_MAGIC);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens ASSERT(featureflags & DMU_BACKUP_FEATURE_RESUMING);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if (DMU_GET_STREAM_HDRTYPE(drrb->drr_versioninfo) ==
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* Verify pool version supports SA if SA_SPILL feature set */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if ((featureflags & DMU_BACKUP_FEATURE_SA_SPILL) &&
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * The receiving code doesn't know how to translate a WRITE_EMBEDDED
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * record to a plain WRITE record, so the pool must have the
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * EMBEDDED_DATA feature enabled if the stream has WRITE_EMBEDDED
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * records. Same with WRITE_EMBEDDED records that use LZ4 compression.
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if ((featureflags & DMU_BACKUP_FEATURE_EMBED_DATA) &&
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens !spa_feature_is_enabled(dp->dp_spa, SPA_FEATURE_EMBEDDED_DATA))
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens !spa_feature_is_enabled(dp->dp_spa, SPA_FEATURE_LZ4_COMPRESS))
9adfa60d484ce2435f5af77cc99dcd4e692b6660Matthew Ahrens /* 6 extra bytes for /%recv */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens (void) snprintf(recvname, sizeof (recvname), "%s/%s",
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if (dsl_dataset_hold(dp, recvname, FTAG, &ds) != 0) {
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* %recv does not exist; continue in tofs */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens error = dsl_dataset_hold(dp, tofs, FTAG, &ds);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* check that ds is marked inconsistent */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* check that there is resuming data, and that the toguid matches */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens error = zap_lookup(dp->dp_meta_objset, ds->ds_object,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens DS_FIELD_RESUME_TOGUID, sizeof (val), 1, &val);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * Check if the receive is still running. If so, it will be owned.
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * Note that nothing else can own the dataset (e.g. after the receive
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * fails) because it will be marked inconsistent.
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* There should not be any snapshots of this fs yet. */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if (ds->ds_prev != NULL && ds->ds_prev->ds_dir == ds->ds_dir) {
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * Note: resume point will be checked when we process the first WRITE
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* check that the origin matches */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens (void) zap_lookup(dp->dp_meta_objset, ds->ds_object,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens DS_FIELD_RESUME_FROMGUID, sizeof (val), 1, &val);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrensdmu_recv_resume_begin_sync(void *arg, dmu_tx_t *tx)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens const char *tofs = drba->drba_cookie->drc_tofs;
9adfa60d484ce2435f5af77cc99dcd4e692b6660Matthew Ahrens /* 6 extra bytes for /%recv */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens (void) snprintf(recvname, sizeof (recvname), "%s/%s",
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if (dsl_dataset_hold(dp, recvname, FTAG, &ds) != 0) {
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* %recv does not exist; continue in tofs */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens VERIFY0(dsl_dataset_hold(dp, tofs, FTAG, &ds));
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* clear the inconsistent flag so that we can own it */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens dsl_dataset_phys(ds)->ds_flags &= ~DS_FLAG_INCONSISTENT;
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens VERIFY0(dsl_dataset_own_obj(dp, dsobj, dmu_recv_tag, &ds));
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens dsl_dataset_phys(ds)->ds_flags |= DS_FLAG_INCONSISTENT;
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_enter(&ds->ds_bp_rwlock, RW_READER, FTAG);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens ASSERT(!BP_IS_HOLE(dsl_dataset_get_blkptr(ds)));
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens spa_history_log_internal_ds(ds, "resume 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.
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrensdmu_recv_begin(char *tofs, char *tosnap, dmu_replay_record_t *drr_begin,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens boolean_t force, boolean_t resumable, char *origin, dmu_recv_cookie_t *drc)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if (drc->drc_drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens sizeof (dmu_replay_record_t), &drc->drc_cksum);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens } else if (drc->drc_drrb->drr_magic == DMU_BACKUP_MAGIC) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens sizeof (dmu_replay_record_t), &drc->drc_cksum);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if (DMU_GET_FEATUREFLAGS(drc->drc_drrb->drr_versioninfo) &
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens dmu_recv_resume_begin_check, dmu_recv_resume_begin_sync,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie void *payload; /* Pointer to a buffer containing the payload */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * If the record is a write, pointer to the arc_buf_t containing the
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens uint64_t bytes_read; /* bytes read from stream when record created */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie boolean_t eos_marker; /* Marks the end of the stream */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * These three args are used to signal to the main thread that we're
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie /* A map from guid to dataset to help handle dedup'd streams. */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens uint64_t bytes_read; /* bytes read when current record created */
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie list_t list; /* List of struct receive_objnode. */
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * Last object looked up. Used to assert that objects are being looked
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * up in ascending order.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie vnode_t *vp; /* The vnode to read the stream from */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie uint64_t voff; /* The current offset in the stream */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * A record that has had its payload read in, but hasn't yet been handed
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * off to the worker thread.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie /* A record that has had its header read in, but not its payload. */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie /* Sorted list of objects not to issue prefetches for. */
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt return (-1);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt return (1);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt return (0);
c99e4bdccfb4ac4da569c64a43baaf908d726329Chris Kirby while ((gmep = avl_destroy_nodes(ca, &cookie)) != NULL) {
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliereceive_read(struct receive_arg *ra, int len, void *buf)
c20404ff77119516354b0d112d28b7ea0dadd303Eli Rosenthal * The code doesn't rely on this (lengths being multiples of 8). See
c20404ff77119516354b0d112d28b7ea0dadd303Eli Rosenthal * comment in dump_bytes.
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * Note: ECKSUM indicates that the receive
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * was interrupted and can potentially be resumed.
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))
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens ZIO_CHECKSUM_BSWAP(&drr->drr_u.drr_write.drr_key.ddk_cksum);
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens ZIO_CHECKSUM_BSWAP(&drr->drr_u.drr_write_byref.
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens ZIO_CHECKSUM_BSWAP(&drr->drr_u.drr_end.drr_checksum);
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens ZIO_CHECKSUM_BSWAP(&drr->drr_u.drr_checksum.drr_checksum);
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrensdeduce_nblkptr(dmu_object_type_t bonus_type, uint64_t bonus_size)
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens ((DN_MAX_BONUSLEN - bonus_size) >> SPA_BLKPTRSHIFT));
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrenssave_resume_state(struct receive_writer_arg *rwa,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens uint64_t object, uint64_t offset, dmu_tx_t *tx)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * We use ds_resume_bytes[] != 0 to indicate that we need to
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * update this on disk, so it must not be 0.
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * We only resume from write records, which have a valid
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * (non-meta-dnode) object number.
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * For resuming to work correctly, we must receive records in order,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * sorted by object,offset. This is checked by the callers, but
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * assert it here for good measure.
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens ASSERT3U(object, >=, rwa->os->os_dsl_dataset->ds_resume_object[txgoff]);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens ASSERT(object != rwa->os->os_dsl_dataset->ds_resume_object[txgoff] ||
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens offset >= rwa->os->os_dsl_dataset->ds_resume_offset[txgoff]);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens rwa->os->os_dsl_dataset->ds_resume_bytes[txgoff]);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens rwa->os->os_dsl_dataset->ds_resume_object[txgoff] = object;
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens rwa->os->os_dsl_dataset->ds_resume_offset[txgoff] = offset;
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens rwa->os->os_dsl_dataset->ds_resume_bytes[txgoff] = rwa->bytes_read;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliereceive_object(struct receive_writer_arg *rwa, struct drr_object *drro,
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt drro->drr_checksumtype >= ZIO_CHECKSUM_FUNCTIONS ||
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie drro->drr_blksz > spa_maxblocksize(dmu_objset_spa(rwa->os)) ||
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = dmu_object_info(rwa->os, drro->drr_object, &doi);
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens object = err == 0 ? drro->drr_object : DMU_NEW_OBJECT;
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 ||
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = dmu_free_long_range(rwa->os, drro->drr_object,
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens /* currently free, want to be allocated */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = dmu_object_claim(rwa->os, drro->drr_object,
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens drro->drr_blksz != doi.doi_data_block_size ||
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens /* currently allocated, but with different properties */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = dmu_object_reclaim(rwa->os, drro->drr_object,
e77d42eaa49fe55bfae1e0e0065c6e99affc001bMatthew Ahrens drro->drr_bonustype, drro->drr_bonuslen, tx);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie dmu_object_set_checksum(rwa->os, drro->drr_object,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie dmu_object_set_compress(rwa->os, drro->drr_object,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie VERIFY0(dmu_bonus_hold(rwa->os, drro->drr_object, FTAG, &db));
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden dmu_ot_byteswap[byteswap].ob_func(db->db_data,
efb80947b01107dafbbf0157de0d7e1af6551259ahrens return (0);
efb80947b01107dafbbf0157de0d7e1af6551259ahrens/* ARGSUSED */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliereceive_freeobjects(struct receive_writer_arg *rwa,
efb80947b01107dafbbf0157de0d7e1af6551259ahrens if (drrfo->drr_firstobj + drrfo->drr_numobjs < drrfo->drr_firstobj)
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie obj < drrfo->drr_firstobj + drrfo->drr_numobjs && next_err == 0;
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie next_err = dmu_object_next(rwa->os, &obj, FALSE, 0)) {
efb80947b01107dafbbf0157de0d7e1af6551259ahrens return (0);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliereceive_write(struct receive_writer_arg *rwa, struct drr_write *drrw,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel if (drrw->drr_offset + drrw->drr_logical_size < drrw->drr_offset ||
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * For resuming to work, records must be in increasing order
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * by (object, offset).
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (dmu_object_info(rwa->os, drrw->drr_object, NULL) != 0)
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens dmu_ot_byteswap[byteswap].ob_func(abuf->b_data,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel /* use the bonus buf to look up the dnode in dmu_assign_arcbuf */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (dmu_bonus_hold(rwa->os, drrw->drr_object, FTAG, &bonus) != 0)
8a9047098ad8ce5afa38b6d012c8b509bb619f40Matthew Ahrens dmu_assign_arcbuf(bonus, drrw->drr_offset, abuf, tx);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * Note: If the receive fails, we want the resume stream to start
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * with the same record that we last successfully received (as opposed
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * to the next record), so that we can verify that we are
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * resuming from the correct location.
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens save_resume_state(rwa, drrw->drr_object, drrw->drr_offset, 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.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliereceive_write_byref(struct receive_writer_arg *rwa,
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.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if ((gmep = avl_find(rwa->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);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* See comment in restore_write. */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens save_resume_state(rwa, drrwbr->drr_object, drrwbr->drr_offset, tx);
9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22Lori Alt return (0);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliereceive_write_embedded(struct receive_writer_arg *rwa,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens struct drr_write_embedded *drrwe, void *data)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if (drrwe->drr_offset + drrwe->drr_length < drrwe->drr_offset)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if (drrwe->drr_etype >= NUM_BP_EMBEDDED_TYPES)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if (drrwe->drr_compression >= ZIO_COMPRESS_FUNCTIONS)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens dmu_write_embedded(rwa->os, drrwe->drr_object,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens drrwe->drr_compression, drrwe->drr_lsize, drrwe->drr_psize,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* See comment in restore_write. */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens save_resume_state(rwa, drrwe->drr_object, drrwe->drr_offset, tx);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliereceive_spill(struct receive_writer_arg *rwa, struct drr_spill *drrs,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie drrs->drr_length > spa_maxblocksize(dmu_objset_spa(rwa->os)))
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (dmu_object_info(rwa->os, drrs->drr_object, NULL) != 0)
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie VERIFY0(dmu_bonus_hold(rwa->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 */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliereceive_free(struct receive_writer_arg *rwa, struct drr_free *drrf)
efb80947b01107dafbbf0157de0d7e1af6551259ahrens drrf->drr_offset + drrf->drr_length < drrf->drr_offset)
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (dmu_object_info(rwa->os, drrf->drr_object, NULL) != 0)
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = dmu_free_long_range(rwa->os, drrf->drr_object,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens/* used to destroy the drc_ds on error */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* wait for our resume state to be written to disk */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens txg_wait_synced(drc->drc_ds->ds_dir->dd_pool, 0);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens dsl_dataset_disown(drc->drc_ds, dmu_recv_tag);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens dsl_dataset_disown(drc->drc_ds, dmu_recv_tag);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliereceive_cksum(struct receive_arg *ra, int len, void *buf)
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens fletcher_4_incremental_byteswap(buf, len, &ra->cksum);
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens fletcher_4_incremental_native(buf, len, &ra->cksum);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Read the payload into a buffer of size len, and update the current record's
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * payload field.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Allocate ra->next_rrd and read the next record's header into
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * ra->next_rrd->header.
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens * Verify checksum of payload and next record.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliereceive_read_payload_and_next_header(struct receive_arg *ra, int len, void *buf)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* note: rrd is NULL when reading the begin record's payload */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie ra->next_rrd = kmem_zalloc(sizeof (*ra->next_rrd), KM_SLEEP);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = receive_read(ra, sizeof (ra->next_rrd->header),
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie kmem_free(ra->next_rrd, sizeof (*ra->next_rrd));
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (ra->next_rrd->header.drr_type == DRR_BEGIN) {
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie kmem_free(ra->next_rrd, sizeof (*ra->next_rrd));
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens * Note: checksum is of everything up to but not including the
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens * checksum itself.
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens ASSERT3U(offsetof(dmu_replay_record_t, drr_u.drr_checksum.drr_checksum),
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens ==, sizeof (dmu_replay_record_t) - sizeof (zio_cksum_t));
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens offsetof(dmu_replay_record_t, drr_u.drr_checksum.drr_checksum),
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie ra->next_rrd->header.drr_u.drr_checksum.drr_checksum;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie &ra->next_rrd->header.drr_u.drr_checksum.drr_checksum;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie kmem_free(ra->next_rrd, sizeof (*ra->next_rrd));
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie receive_cksum(ra, sizeof (cksum_orig), &cksum_orig);
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie list_create(&list->list, sizeof (struct receive_objnode),
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie for (struct receive_objnode *n = list_remove_head(&list->list);
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie n != NULL; n = list_remove_head(&list->list)) {
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie kmem_free(n, sizeof (*n));
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * This function looks through the objlist to see if the specified object number
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * is contained in the objlist. In the process, it will remove all object
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * numbers in the list that are smaller than the specified object number. Thus,
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * any lookup of an object number smaller than a previously looked up object
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * number will always return false; therefore, all lookups should be done in
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * ascending order.
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelieobjlist_exists(struct objlist *list, uint64_t object)
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie struct receive_objnode *node = list_head(&list->list);
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie while (node != NULL && node->object < object) {
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie VERIFY3P(node, ==, list_remove_head(&list->list));
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie return (node != NULL && node->object == object);
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * The objlist is a list of object numbers stored in ascending order. However,
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * the insertion of new object numbers does not seek out the correct location to
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * store a new object number; instead, it appends it to the list for simplicity.
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie * Thus, any users must take care to only insert new object numbers in ascending
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelieobjlist_insert(struct objlist *list, uint64_t object)
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie struct receive_objnode *node = kmem_zalloc(sizeof (*node), KM_SLEEP);
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie struct receive_objnode *last_object = list_tail(&list->list);
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie uint64_t last_objnum = (last_object != NULL ? last_object->object : 0);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Issue the prefetch reads for any necessary indirect blocks.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * We use the object ignore list to tell us whether or not to issue prefetches
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * for a given object. We do this for both correctness (in case the blocksize
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * of an object has changed) and performance (if the object doesn't exist, don't
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * needlessly try to issue prefetches). We also trim the list as we go through
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * the stream to prevent it from growing to an unbounded size.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * The object numbers within will always be in sorted order, and any write
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * records we see will also be in sorted order, but they're not sorted with
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * respect to each other (i.e. we can get several object records before
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * receiving each object's write records). As a result, once we've reached a
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * given object number, we can safely remove any reference to lower object
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * numbers in the ignore list. In practice, we receive up to 32 object records
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * before receiving write records, so the list can have up to 32 nodes in it.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie/* ARGSUSED */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie uint64_t object, uint64_t offset, uint64_t length)
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie if (!objlist_exists(&ra->ignore_objlist, object)) {
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie dmu_prefetch(ra->os, object, 1, offset, length,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Read records off the stream, issuing any necessary prefetches.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie struct drr_object *drro = &ra->rrd->header.drr_u.drr_object;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie uint32_t size = P2ROUNDUP(drro->drr_bonuslen, 8);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = receive_read_payload_and_next_header(ra, size, buf);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = dmu_object_info(ra->os, drro->drr_object, &doi);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * See receive_read_prefetch for an explanation why we're
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * storing this object in the ignore_obj_list.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie (err == 0 && doi.doi_data_block_size != drro->drr_blksz)) {
68ecb2ec930c4b0f00acaf8e0abb2b19c4b8b76fPaul Dagnelie objlist_insert(&ra->ignore_objlist, drro->drr_object);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = receive_read_payload_and_next_header(ra, 0, NULL);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie struct drr_write *drrw = &ra->rrd->header.drr_u.drr_write;
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel boolean_t is_meta = DMU_OT_IS_METADATA(drrw->drr_type);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel drrw->drr_compressed_size, drrw->drr_logical_size,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = receive_read_payload_and_next_header(ra,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie receive_read_prefetch(ra, drrw->drr_object, drrw->drr_offset,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = receive_read_payload_and_next_header(ra, 0, NULL);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie receive_read_prefetch(ra, drrwb->drr_object, drrwb->drr_offset,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie uint32_t size = P2ROUNDUP(drrwe->drr_psize, 8);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = receive_read_payload_and_next_header(ra, size, buf);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie receive_read_prefetch(ra, drrwe->drr_object, drrwe->drr_offset,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * It might be beneficial to prefetch indirect blocks here, but
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * we don't really have the data to decide for sure.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = receive_read_payload_and_next_header(ra, 0, NULL);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie struct drr_end *drre = &ra->rrd->header.drr_u.drr_end;
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens if (!ZIO_CHECKSUM_EQUAL(ra->prev_cksum, drre->drr_checksum))
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie struct drr_spill *drrs = &ra->rrd->header.drr_u.drr_spill;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie void *buf = kmem_zalloc(drrs->drr_length, KM_SLEEP);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = receive_read_payload_and_next_header(ra, drrs->drr_length,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Commit the records to the pool.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliereceive_process_record(struct receive_writer_arg *rwa,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens /* Processing in order, therefore bytes_read should be increasing. */
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens ASSERT3U(rrd->bytes_read, >=, rwa->bytes_read);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie struct drr_object *drro = &rrd->header.drr_u.drr_object;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = receive_object(rwa, drro, rrd->payload);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie struct drr_write *drrw = &rrd->header.drr_u.drr_write;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = receive_write(rwa, drrw, rrd->write_buf);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie /* if receive_write() is successful, it consumes the arc_buf */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie err = receive_write_embedded(rwa, drrwe, rrd->payload);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie struct drr_free *drrf = &rrd->header.drr_u.drr_free;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie struct drr_spill *drrs = &rrd->header.drr_u.drr_spill;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * dmu_recv_stream's worker thread; pull records off the queue, and then call
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * receive_process_record When we're done, signal the main thread and exit.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie for (rrd = bqueue_dequeue(&rwa->q); !rrd->eos_marker;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * If there's an error, the main thread will stop putting things
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * on the queue, but we need to clear everything in it before we
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrensresume_check(struct receive_arg *ra, nvlist_t *begin_nvl)
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens objset_t *mos = dmu_objset_pool(ra->os)->dp_meta_objset;
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens DS_FIELD_RESUME_OBJECT, sizeof (val), 1, &val));
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens DS_FIELD_RESUME_OFFSET, sizeof (val), 1, &val));
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Read in the stream's records, one by one, and apply them to the pool. There
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * are two threads involved; the thread that calls this function will spin up a
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * worker thread, read the records off the stream one by one, and issue
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * prefetches for any necessary indirect blocks. It will then push the records
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * onto an internal blocking queue. The worker thread will pull the records off
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * the queue, and actually write the data into the DMU. This way, the worker
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * thread doesn't have to wait for reads to complete, since everything it needs
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * (the indirect blocks) will be prefetched.
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,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens (void) zap_lookup(drc->drc_ds->ds_dir->dd_pool->dp_meta_objset,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens drc->drc_ds->ds_object, DS_FIELD_RESUME_BYTES,
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.
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens VERIFY0(dmu_objset_from_ds(drc->drc_ds, &ra.os));
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT(dsl_dataset_phys(drc->drc_ds)->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);
98110f08fa182032082d98be2ddb9391fcd62bf1Matthew Ahrens err = zfs_onexit_cb_data(minor, *action_handlep,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens uint32_t payloadlen = drc->drc_drr_begin->drr_payloadlen;
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens err = receive_read_payload_and_next_header(&ra, payloadlen, payload);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens err = nvlist_unpack(payload, payloadlen, &begin_nvl, KM_SLEEP);
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if (featureflags & DMU_BACKUP_FEATURE_RESUMING) {
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie (void) bqueue_init(&rwa.q, zfs_recv_queue_length,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie mutex_init(&rwa.mutex, NULL, MUTEX_DEFAULT, NULL);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie (void) thread_create(NULL, 0, receive_writer_thread, &rwa, 0, curproc,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * We're reading rwa.err without locks, which is safe since we are the
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * only reader, and the worker thread is the only writer. It's ok if we
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * miss a write for an iteration or two of the loop, since the writer
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * thread will keep freeing records we send it until we send it an eos
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * We can leave this loop in 3 ways: First, if rwa.err is
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * non-zero. In that case, the writer thread will free the rrd we just
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * pushed. Second, if we're interrupted; in that case, either it's the
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * first loop and ra.rrd was never allocated, or it's later, and ra.rrd
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * has been handed off to the writer thread who will free it. Finally,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * if receive_read_record fails or we're at the end of the stream, then
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * we free ra.rrd and exit.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie /* Allocates and loads header into ra.next_rrd */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (ra.rrd->header.drr_type == DRR_END || err != 0) {
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie sizeof (struct receive_record_arg) + ra.rrd->payload_size);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie ra.next_rrd = kmem_zalloc(sizeof (*ra.next_rrd), KM_SLEEP);
a7f53a5629374ca27c5696ace9a1946c2ca050f4Chris Kirby if ((featureflags & DMU_BACKUP_FEATURE_DEDUP) && (cleanup_fd != -1))
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * Clean up references. If receive is not resumable,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * destroy what we created, so we don't leave it in
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * the inconsistent 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).
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs obj = dsl_dataset_phys(origin_head)->ds_prev_snap_obj;
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(drc->drc_ds)->ds_prev_snap_obj) {
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs obj = dsl_dataset_phys(snap)->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).
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs obj = dsl_dataset_phys(origin_head)->ds_prev_snap_obj;
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(drc->drc_ds)->ds_prev_snap_obj) {
34f2f8cf94052481c81be2e134b94a00b501bf21Matthew Ahrens ASSERT3P(snap->ds_dir, ==, origin_head->ds_dir);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs obj = dsl_dataset_phys(snap)->ds_prev_snap_obj;
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);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(origin_head->ds_prev)->ds_creation_time =
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(origin_head->ds_prev)->ds_guid =
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(origin_head->ds_prev)->ds_flags &=
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dmu_buf_will_dirty(origin_head->ds_dbuf, tx);
2ad25b4055c18f39b3fb20bd5c8c61057e34f377Chris Williamson dsl_dataset_phys(origin_head)->ds_prev_snap_obj;
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);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds->ds_prev)->ds_creation_time =
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_flags &= ~DS_FLAG_INCONSISTENT;
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens if (dsl_dataset_has_resume_receive_state(ds)) {
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens (void) zap_remove(dp->dp_meta_objset, ds->ds_object,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens (void) zap_remove(dp->dp_meta_objset, ds->ds_object,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens (void) zap_remove(dp->dp_meta_objset, ds->ds_object,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens (void) zap_remove(dp->dp_meta_objset, ds->ds_object,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens (void) zap_remove(dp->dp_meta_objset, ds->ds_object,
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens (void) zap_remove(dp->dp_meta_objset, ds->ds_object,
2ad25b4055c18f39b3fb20bd5c8c61057e34f377Chris Williamson dsl_dataset_phys(drc->drc_ds)->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);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs gmep->guid = dsl_dataset_phys(snapds)->ds_guid;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * We will be destroying the ds; make sure its origin is unmounted if
2ad25b4055c18f39b3fb20bd5c8c61057e34f377Chris Williamson dmu_recv_end_modified_blocks, ZFS_SPACE_CHECK_NORMAL));
2ad25b4055c18f39b3fb20bd5c8c61057e34f377Chris Williamson dmu_recv_end_check, dmu_recv_end_sync, drc,
2ad25b4055c18f39b3fb20bd5c8c61057e34f377Chris Williamson dmu_recv_end_modified_blocks, ZFS_SPACE_CHECK_NORMAL));
2ad25b4055c18f39b3fb20bd5c8c61057e34f377Chris Williamsondmu_recv_end(dmu_recv_cookie_t *drc, void *owner)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens } else if (drc->drc_guid_to_ds_map != NULL) {
2f3d878000c3b33cde13e16c4f0a1ab15d883a18Matthew Ahrens * Return TRUE if this objset is currently being received into.