1eda14cbcSMatt Macy /* 2eda14cbcSMatt Macy * CDDL HEADER START 3eda14cbcSMatt Macy * 4eda14cbcSMatt Macy * The contents of this file are subject to the terms of the 5eda14cbcSMatt Macy * Common Development and Distribution License (the "License"). 6eda14cbcSMatt Macy * You may not use this file except in compliance with the License. 7eda14cbcSMatt Macy * 8eda14cbcSMatt Macy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9eda14cbcSMatt Macy * or http://www.opensolaris.org/os/licensing. 10eda14cbcSMatt Macy * See the License for the specific language governing permissions 11eda14cbcSMatt Macy * and limitations under the License. 12eda14cbcSMatt Macy * 13eda14cbcSMatt Macy * When distributing Covered Code, include this CDDL HEADER in each 14eda14cbcSMatt Macy * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15eda14cbcSMatt Macy * If applicable, add the following below this CDDL HEADER, with the 16eda14cbcSMatt Macy * fields enclosed by brackets "[]" replaced with your own identifying 17eda14cbcSMatt Macy * information: Portions Copyright [yyyy] [name of copyright owner] 18eda14cbcSMatt Macy * 19eda14cbcSMatt Macy * CDDL HEADER END 20eda14cbcSMatt Macy */ 21eda14cbcSMatt Macy /* 22eda14cbcSMatt Macy * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23eda14cbcSMatt Macy * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 24eda14cbcSMatt Macy * Copyright (c) 2011, 2018 by Delphix. All rights reserved. 25eda14cbcSMatt Macy * Copyright (c) 2014, Joyent, Inc. All rights reserved. 26eda14cbcSMatt Macy * Copyright 2014 HybridCluster. All rights reserved. 27eda14cbcSMatt Macy * Copyright 2016 RackTop Systems. 28eda14cbcSMatt Macy * Copyright (c) 2016 Actifio, Inc. All rights reserved. 29eda14cbcSMatt Macy * Copyright (c) 2019, Klara Inc. 30eda14cbcSMatt Macy * Copyright (c) 2019, Allan Jude 31eda14cbcSMatt Macy */ 32eda14cbcSMatt Macy 33eda14cbcSMatt Macy #include <sys/dmu.h> 34eda14cbcSMatt Macy #include <sys/dmu_impl.h> 35eda14cbcSMatt Macy #include <sys/dmu_tx.h> 36eda14cbcSMatt Macy #include <sys/dbuf.h> 37eda14cbcSMatt Macy #include <sys/dnode.h> 38eda14cbcSMatt Macy #include <sys/zfs_context.h> 39eda14cbcSMatt Macy #include <sys/dmu_objset.h> 40eda14cbcSMatt Macy #include <sys/dmu_traverse.h> 41eda14cbcSMatt Macy #include <sys/dsl_dataset.h> 42eda14cbcSMatt Macy #include <sys/dsl_dir.h> 43eda14cbcSMatt Macy #include <sys/dsl_prop.h> 44eda14cbcSMatt Macy #include <sys/dsl_pool.h> 45eda14cbcSMatt Macy #include <sys/dsl_synctask.h> 46eda14cbcSMatt Macy #include <sys/spa_impl.h> 47eda14cbcSMatt Macy #include <sys/zfs_ioctl.h> 48eda14cbcSMatt Macy #include <sys/zap.h> 49eda14cbcSMatt Macy #include <sys/zio_checksum.h> 50eda14cbcSMatt Macy #include <sys/zfs_znode.h> 51eda14cbcSMatt Macy #include <zfs_fletcher.h> 52eda14cbcSMatt Macy #include <sys/avl.h> 53eda14cbcSMatt Macy #include <sys/ddt.h> 54eda14cbcSMatt Macy #include <sys/zfs_onexit.h> 55eda14cbcSMatt Macy #include <sys/dmu_send.h> 56eda14cbcSMatt Macy #include <sys/dmu_recv.h> 57eda14cbcSMatt Macy #include <sys/dsl_destroy.h> 58eda14cbcSMatt Macy #include <sys/blkptr.h> 59eda14cbcSMatt Macy #include <sys/dsl_bookmark.h> 60eda14cbcSMatt Macy #include <sys/zfeature.h> 61eda14cbcSMatt Macy #include <sys/bqueue.h> 62eda14cbcSMatt Macy #include <sys/zvol.h> 63eda14cbcSMatt Macy #include <sys/policy.h> 64eda14cbcSMatt Macy #include <sys/objlist.h> 65eda14cbcSMatt Macy #ifdef _KERNEL 66eda14cbcSMatt Macy #include <sys/zfs_vfsops.h> 67eda14cbcSMatt Macy #endif 68eda14cbcSMatt Macy 69eda14cbcSMatt Macy /* Set this tunable to TRUE to replace corrupt data with 0x2f5baddb10c */ 70eda14cbcSMatt Macy int zfs_send_corrupt_data = B_FALSE; 71eda14cbcSMatt Macy /* 72eda14cbcSMatt Macy * This tunable controls the amount of data (measured in bytes) that will be 73eda14cbcSMatt Macy * prefetched by zfs send. If the main thread is blocking on reads that haven't 74eda14cbcSMatt Macy * completed, this variable might need to be increased. If instead the main 75eda14cbcSMatt Macy * thread is issuing new reads because the prefetches have fallen out of the 76eda14cbcSMatt Macy * cache, this may need to be decreased. 77eda14cbcSMatt Macy */ 78eda14cbcSMatt Macy int zfs_send_queue_length = SPA_MAXBLOCKSIZE; 79eda14cbcSMatt Macy /* 80eda14cbcSMatt Macy * This tunable controls the length of the queues that zfs send worker threads 81eda14cbcSMatt Macy * use to communicate. If the send_main_thread is blocking on these queues, 82eda14cbcSMatt Macy * this variable may need to be increased. If there is a significant slowdown 83eda14cbcSMatt Macy * at the start of a send as these threads consume all the available IO 84eda14cbcSMatt Macy * resources, this variable may need to be decreased. 85eda14cbcSMatt Macy */ 86eda14cbcSMatt Macy int zfs_send_no_prefetch_queue_length = 1024 * 1024; 87eda14cbcSMatt Macy /* 88eda14cbcSMatt Macy * These tunables control the fill fraction of the queues by zfs send. The fill 89eda14cbcSMatt Macy * fraction controls the frequency with which threads have to be cv_signaled. 90eda14cbcSMatt Macy * If a lot of cpu time is being spent on cv_signal, then these should be tuned 91eda14cbcSMatt Macy * down. If the queues empty before the signalled thread can catch up, then 92eda14cbcSMatt Macy * these should be tuned up. 93eda14cbcSMatt Macy */ 94eda14cbcSMatt Macy int zfs_send_queue_ff = 20; 95eda14cbcSMatt Macy int zfs_send_no_prefetch_queue_ff = 20; 96eda14cbcSMatt Macy 97eda14cbcSMatt Macy /* 98eda14cbcSMatt Macy * Use this to override the recordsize calculation for fast zfs send estimates. 99eda14cbcSMatt Macy */ 100eda14cbcSMatt Macy int zfs_override_estimate_recordsize = 0; 101eda14cbcSMatt Macy 102eda14cbcSMatt Macy /* Set this tunable to FALSE to disable setting of DRR_FLAG_FREERECORDS */ 103eda14cbcSMatt Macy int zfs_send_set_freerecords_bit = B_TRUE; 104eda14cbcSMatt Macy 105eda14cbcSMatt Macy /* Set this tunable to FALSE is disable sending unmodified spill blocks. */ 106eda14cbcSMatt Macy int zfs_send_unmodified_spill_blocks = B_TRUE; 107eda14cbcSMatt Macy 108eda14cbcSMatt Macy static inline boolean_t 109eda14cbcSMatt Macy overflow_multiply(uint64_t a, uint64_t b, uint64_t *c) 110eda14cbcSMatt Macy { 111eda14cbcSMatt Macy uint64_t temp = a * b; 112eda14cbcSMatt Macy if (b != 0 && temp / b != a) 113eda14cbcSMatt Macy return (B_FALSE); 114eda14cbcSMatt Macy *c = temp; 115eda14cbcSMatt Macy return (B_TRUE); 116eda14cbcSMatt Macy } 117eda14cbcSMatt Macy 118eda14cbcSMatt Macy struct send_thread_arg { 119eda14cbcSMatt Macy bqueue_t q; 120eda14cbcSMatt Macy objset_t *os; /* Objset to traverse */ 121eda14cbcSMatt Macy uint64_t fromtxg; /* Traverse from this txg */ 122eda14cbcSMatt Macy int flags; /* flags to pass to traverse_dataset */ 123eda14cbcSMatt Macy int error_code; 124eda14cbcSMatt Macy boolean_t cancel; 125eda14cbcSMatt Macy zbookmark_phys_t resume; 126eda14cbcSMatt Macy uint64_t *num_blocks_visited; 127eda14cbcSMatt Macy }; 128eda14cbcSMatt Macy 129eda14cbcSMatt Macy struct redact_list_thread_arg { 130eda14cbcSMatt Macy boolean_t cancel; 131eda14cbcSMatt Macy bqueue_t q; 132eda14cbcSMatt Macy zbookmark_phys_t resume; 133eda14cbcSMatt Macy redaction_list_t *rl; 134eda14cbcSMatt Macy boolean_t mark_redact; 135eda14cbcSMatt Macy int error_code; 136eda14cbcSMatt Macy uint64_t *num_blocks_visited; 137eda14cbcSMatt Macy }; 138eda14cbcSMatt Macy 139eda14cbcSMatt Macy struct send_merge_thread_arg { 140eda14cbcSMatt Macy bqueue_t q; 141eda14cbcSMatt Macy objset_t *os; 142eda14cbcSMatt Macy struct redact_list_thread_arg *from_arg; 143eda14cbcSMatt Macy struct send_thread_arg *to_arg; 144eda14cbcSMatt Macy struct redact_list_thread_arg *redact_arg; 145eda14cbcSMatt Macy int error; 146eda14cbcSMatt Macy boolean_t cancel; 147eda14cbcSMatt Macy }; 148eda14cbcSMatt Macy 149eda14cbcSMatt Macy struct send_range { 150eda14cbcSMatt Macy boolean_t eos_marker; /* Marks the end of the stream */ 151eda14cbcSMatt Macy uint64_t object; 152eda14cbcSMatt Macy uint64_t start_blkid; 153eda14cbcSMatt Macy uint64_t end_blkid; 154eda14cbcSMatt Macy bqueue_node_t ln; 155eda14cbcSMatt Macy enum type {DATA, HOLE, OBJECT, OBJECT_RANGE, REDACT, 156eda14cbcSMatt Macy PREVIOUSLY_REDACTED} type; 157eda14cbcSMatt Macy union { 158eda14cbcSMatt Macy struct srd { 159eda14cbcSMatt Macy dmu_object_type_t obj_type; 160eda14cbcSMatt Macy uint32_t datablksz; // logical size 161eda14cbcSMatt Macy uint32_t datasz; // payload size 162eda14cbcSMatt Macy blkptr_t bp; 163eda14cbcSMatt Macy arc_buf_t *abuf; 164eda14cbcSMatt Macy abd_t *abd; 165eda14cbcSMatt Macy kmutex_t lock; 166eda14cbcSMatt Macy kcondvar_t cv; 167eda14cbcSMatt Macy boolean_t io_outstanding; 168*681ce946SMartin Matuska boolean_t io_compressed; 169eda14cbcSMatt Macy int io_err; 170eda14cbcSMatt Macy } data; 171eda14cbcSMatt Macy struct srh { 172eda14cbcSMatt Macy uint32_t datablksz; 173eda14cbcSMatt Macy } hole; 174eda14cbcSMatt Macy struct sro { 175eda14cbcSMatt Macy /* 176eda14cbcSMatt Macy * This is a pointer because embedding it in the 177eda14cbcSMatt Macy * struct causes these structures to be massively larger 178eda14cbcSMatt Macy * for all range types; this makes the code much less 179eda14cbcSMatt Macy * memory efficient. 180eda14cbcSMatt Macy */ 181eda14cbcSMatt Macy dnode_phys_t *dnp; 182eda14cbcSMatt Macy blkptr_t bp; 183eda14cbcSMatt Macy } object; 184eda14cbcSMatt Macy struct srr { 185eda14cbcSMatt Macy uint32_t datablksz; 186eda14cbcSMatt Macy } redact; 187eda14cbcSMatt Macy struct sror { 188eda14cbcSMatt Macy blkptr_t bp; 189eda14cbcSMatt Macy } object_range; 190eda14cbcSMatt Macy } sru; 191eda14cbcSMatt Macy }; 192eda14cbcSMatt Macy 193eda14cbcSMatt Macy /* 194eda14cbcSMatt Macy * The list of data whose inclusion in a send stream can be pending from 195eda14cbcSMatt Macy * one call to backup_cb to another. Multiple calls to dump_free(), 196eda14cbcSMatt Macy * dump_freeobjects(), and dump_redact() can be aggregated into a single 197eda14cbcSMatt Macy * DRR_FREE, DRR_FREEOBJECTS, or DRR_REDACT replay record. 198eda14cbcSMatt Macy */ 199eda14cbcSMatt Macy typedef enum { 200eda14cbcSMatt Macy PENDING_NONE, 201eda14cbcSMatt Macy PENDING_FREE, 202eda14cbcSMatt Macy PENDING_FREEOBJECTS, 203eda14cbcSMatt Macy PENDING_REDACT 204eda14cbcSMatt Macy } dmu_pendop_t; 205eda14cbcSMatt Macy 206eda14cbcSMatt Macy typedef struct dmu_send_cookie { 207eda14cbcSMatt Macy dmu_replay_record_t *dsc_drr; 208eda14cbcSMatt Macy dmu_send_outparams_t *dsc_dso; 209eda14cbcSMatt Macy offset_t *dsc_off; 210eda14cbcSMatt Macy objset_t *dsc_os; 211eda14cbcSMatt Macy zio_cksum_t dsc_zc; 212eda14cbcSMatt Macy uint64_t dsc_toguid; 213eda14cbcSMatt Macy uint64_t dsc_fromtxg; 214eda14cbcSMatt Macy int dsc_err; 215eda14cbcSMatt Macy dmu_pendop_t dsc_pending_op; 216eda14cbcSMatt Macy uint64_t dsc_featureflags; 217eda14cbcSMatt Macy uint64_t dsc_last_data_object; 218eda14cbcSMatt Macy uint64_t dsc_last_data_offset; 219eda14cbcSMatt Macy uint64_t dsc_resume_object; 220eda14cbcSMatt Macy uint64_t dsc_resume_offset; 221eda14cbcSMatt Macy boolean_t dsc_sent_begin; 222eda14cbcSMatt Macy boolean_t dsc_sent_end; 223eda14cbcSMatt Macy } dmu_send_cookie_t; 224eda14cbcSMatt Macy 225eda14cbcSMatt Macy static int do_dump(dmu_send_cookie_t *dscp, struct send_range *range); 226eda14cbcSMatt Macy 227eda14cbcSMatt Macy static void 228eda14cbcSMatt Macy range_free(struct send_range *range) 229eda14cbcSMatt Macy { 230eda14cbcSMatt Macy if (range->type == OBJECT) { 231eda14cbcSMatt Macy size_t size = sizeof (dnode_phys_t) * 232eda14cbcSMatt Macy (range->sru.object.dnp->dn_extra_slots + 1); 233eda14cbcSMatt Macy kmem_free(range->sru.object.dnp, size); 234eda14cbcSMatt Macy } else if (range->type == DATA) { 235eda14cbcSMatt Macy mutex_enter(&range->sru.data.lock); 236eda14cbcSMatt Macy while (range->sru.data.io_outstanding) 237eda14cbcSMatt Macy cv_wait(&range->sru.data.cv, &range->sru.data.lock); 238eda14cbcSMatt Macy if (range->sru.data.abd != NULL) 239eda14cbcSMatt Macy abd_free(range->sru.data.abd); 240eda14cbcSMatt Macy if (range->sru.data.abuf != NULL) { 241eda14cbcSMatt Macy arc_buf_destroy(range->sru.data.abuf, 242eda14cbcSMatt Macy &range->sru.data.abuf); 243eda14cbcSMatt Macy } 244eda14cbcSMatt Macy mutex_exit(&range->sru.data.lock); 245eda14cbcSMatt Macy 246eda14cbcSMatt Macy cv_destroy(&range->sru.data.cv); 247eda14cbcSMatt Macy mutex_destroy(&range->sru.data.lock); 248eda14cbcSMatt Macy } 249eda14cbcSMatt Macy kmem_free(range, sizeof (*range)); 250eda14cbcSMatt Macy } 251eda14cbcSMatt Macy 252eda14cbcSMatt Macy /* 253eda14cbcSMatt Macy * For all record types except BEGIN, fill in the checksum (overlaid in 254eda14cbcSMatt Macy * drr_u.drr_checksum.drr_checksum). The checksum verifies everything 255eda14cbcSMatt Macy * up to the start of the checksum itself. 256eda14cbcSMatt Macy */ 257eda14cbcSMatt Macy static int 258eda14cbcSMatt Macy dump_record(dmu_send_cookie_t *dscp, void *payload, int payload_len) 259eda14cbcSMatt Macy { 260eda14cbcSMatt Macy dmu_send_outparams_t *dso = dscp->dsc_dso; 261eda14cbcSMatt Macy ASSERT3U(offsetof(dmu_replay_record_t, drr_u.drr_checksum.drr_checksum), 262eda14cbcSMatt Macy ==, sizeof (dmu_replay_record_t) - sizeof (zio_cksum_t)); 263eda14cbcSMatt Macy (void) fletcher_4_incremental_native(dscp->dsc_drr, 264eda14cbcSMatt Macy offsetof(dmu_replay_record_t, drr_u.drr_checksum.drr_checksum), 265eda14cbcSMatt Macy &dscp->dsc_zc); 266eda14cbcSMatt Macy if (dscp->dsc_drr->drr_type == DRR_BEGIN) { 267eda14cbcSMatt Macy dscp->dsc_sent_begin = B_TRUE; 268eda14cbcSMatt Macy } else { 269eda14cbcSMatt Macy ASSERT(ZIO_CHECKSUM_IS_ZERO(&dscp->dsc_drr->drr_u. 270eda14cbcSMatt Macy drr_checksum.drr_checksum)); 271eda14cbcSMatt Macy dscp->dsc_drr->drr_u.drr_checksum.drr_checksum = dscp->dsc_zc; 272eda14cbcSMatt Macy } 273eda14cbcSMatt Macy if (dscp->dsc_drr->drr_type == DRR_END) { 274eda14cbcSMatt Macy dscp->dsc_sent_end = B_TRUE; 275eda14cbcSMatt Macy } 276eda14cbcSMatt Macy (void) fletcher_4_incremental_native(&dscp->dsc_drr-> 277eda14cbcSMatt Macy drr_u.drr_checksum.drr_checksum, 278eda14cbcSMatt Macy sizeof (zio_cksum_t), &dscp->dsc_zc); 279eda14cbcSMatt Macy *dscp->dsc_off += sizeof (dmu_replay_record_t); 280eda14cbcSMatt Macy dscp->dsc_err = dso->dso_outfunc(dscp->dsc_os, dscp->dsc_drr, 281eda14cbcSMatt Macy sizeof (dmu_replay_record_t), dso->dso_arg); 282eda14cbcSMatt Macy if (dscp->dsc_err != 0) 283eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 284eda14cbcSMatt Macy if (payload_len != 0) { 285eda14cbcSMatt Macy *dscp->dsc_off += payload_len; 286eda14cbcSMatt Macy /* 287eda14cbcSMatt Macy * payload is null when dso_dryrun == B_TRUE (i.e. when we're 288eda14cbcSMatt Macy * doing a send size calculation) 289eda14cbcSMatt Macy */ 290eda14cbcSMatt Macy if (payload != NULL) { 291eda14cbcSMatt Macy (void) fletcher_4_incremental_native( 292eda14cbcSMatt Macy payload, payload_len, &dscp->dsc_zc); 293eda14cbcSMatt Macy } 294eda14cbcSMatt Macy 295eda14cbcSMatt Macy /* 296eda14cbcSMatt Macy * The code does not rely on this (len being a multiple of 8). 297eda14cbcSMatt Macy * We keep this assertion because of the corresponding assertion 298eda14cbcSMatt Macy * in receive_read(). Keeping this assertion ensures that we do 299eda14cbcSMatt Macy * not inadvertently break backwards compatibility (causing the 300eda14cbcSMatt Macy * assertion in receive_read() to trigger on old software). 301eda14cbcSMatt Macy * 302eda14cbcSMatt Macy * Raw sends cannot be received on old software, and so can 303eda14cbcSMatt Macy * bypass this assertion. 304eda14cbcSMatt Macy */ 305eda14cbcSMatt Macy 306eda14cbcSMatt Macy ASSERT((payload_len % 8 == 0) || 307eda14cbcSMatt Macy (dscp->dsc_featureflags & DMU_BACKUP_FEATURE_RAW)); 308eda14cbcSMatt Macy 309eda14cbcSMatt Macy dscp->dsc_err = dso->dso_outfunc(dscp->dsc_os, payload, 310eda14cbcSMatt Macy payload_len, dso->dso_arg); 311eda14cbcSMatt Macy if (dscp->dsc_err != 0) 312eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 313eda14cbcSMatt Macy } 314eda14cbcSMatt Macy return (0); 315eda14cbcSMatt Macy } 316eda14cbcSMatt Macy 317eda14cbcSMatt Macy /* 318eda14cbcSMatt Macy * Fill in the drr_free struct, or perform aggregation if the previous record is 319eda14cbcSMatt Macy * also a free record, and the two are adjacent. 320eda14cbcSMatt Macy * 321eda14cbcSMatt Macy * Note that we send free records even for a full send, because we want to be 322eda14cbcSMatt Macy * able to receive a full send as a clone, which requires a list of all the free 323eda14cbcSMatt Macy * and freeobject records that were generated on the source. 324eda14cbcSMatt Macy */ 325eda14cbcSMatt Macy static int 326eda14cbcSMatt Macy dump_free(dmu_send_cookie_t *dscp, uint64_t object, uint64_t offset, 327eda14cbcSMatt Macy uint64_t length) 328eda14cbcSMatt Macy { 329eda14cbcSMatt Macy struct drr_free *drrf = &(dscp->dsc_drr->drr_u.drr_free); 330eda14cbcSMatt Macy 331eda14cbcSMatt Macy /* 332eda14cbcSMatt Macy * When we receive a free record, dbuf_free_range() assumes 333eda14cbcSMatt Macy * that the receiving system doesn't have any dbufs in the range 334eda14cbcSMatt Macy * being freed. This is always true because there is a one-record 335eda14cbcSMatt Macy * constraint: we only send one WRITE record for any given 336eda14cbcSMatt Macy * object,offset. We know that the one-record constraint is 337eda14cbcSMatt Macy * true because we always send data in increasing order by 338eda14cbcSMatt Macy * object,offset. 339eda14cbcSMatt Macy * 340eda14cbcSMatt Macy * If the increasing-order constraint ever changes, we should find 341eda14cbcSMatt Macy * another way to assert that the one-record constraint is still 342eda14cbcSMatt Macy * satisfied. 343eda14cbcSMatt Macy */ 344eda14cbcSMatt Macy ASSERT(object > dscp->dsc_last_data_object || 345eda14cbcSMatt Macy (object == dscp->dsc_last_data_object && 346eda14cbcSMatt Macy offset > dscp->dsc_last_data_offset)); 347eda14cbcSMatt Macy 348eda14cbcSMatt Macy /* 349eda14cbcSMatt Macy * If there is a pending op, but it's not PENDING_FREE, push it out, 350eda14cbcSMatt Macy * since free block aggregation can only be done for blocks of the 351eda14cbcSMatt Macy * same type (i.e., DRR_FREE records can only be aggregated with 352eda14cbcSMatt Macy * other DRR_FREE records. DRR_FREEOBJECTS records can only be 353eda14cbcSMatt Macy * aggregated with other DRR_FREEOBJECTS records). 354eda14cbcSMatt Macy */ 355eda14cbcSMatt Macy if (dscp->dsc_pending_op != PENDING_NONE && 356eda14cbcSMatt Macy dscp->dsc_pending_op != PENDING_FREE) { 357eda14cbcSMatt Macy if (dump_record(dscp, NULL, 0) != 0) 358eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 359eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_NONE; 360eda14cbcSMatt Macy } 361eda14cbcSMatt Macy 362eda14cbcSMatt Macy if (dscp->dsc_pending_op == PENDING_FREE) { 363eda14cbcSMatt Macy /* 364eda14cbcSMatt Macy * Check to see whether this free block can be aggregated 365eda14cbcSMatt Macy * with pending one. 366eda14cbcSMatt Macy */ 367eda14cbcSMatt Macy if (drrf->drr_object == object && drrf->drr_offset + 368eda14cbcSMatt Macy drrf->drr_length == offset) { 369eda14cbcSMatt Macy if (offset + length < offset || length == UINT64_MAX) 370eda14cbcSMatt Macy drrf->drr_length = UINT64_MAX; 371eda14cbcSMatt Macy else 372eda14cbcSMatt Macy drrf->drr_length += length; 373eda14cbcSMatt Macy return (0); 374eda14cbcSMatt Macy } else { 375eda14cbcSMatt Macy /* not a continuation. Push out pending record */ 376eda14cbcSMatt Macy if (dump_record(dscp, NULL, 0) != 0) 377eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 378eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_NONE; 379eda14cbcSMatt Macy } 380eda14cbcSMatt Macy } 381eda14cbcSMatt Macy /* create a FREE record and make it pending */ 382eda14cbcSMatt Macy bzero(dscp->dsc_drr, sizeof (dmu_replay_record_t)); 383eda14cbcSMatt Macy dscp->dsc_drr->drr_type = DRR_FREE; 384eda14cbcSMatt Macy drrf->drr_object = object; 385eda14cbcSMatt Macy drrf->drr_offset = offset; 386eda14cbcSMatt Macy if (offset + length < offset) 387eda14cbcSMatt Macy drrf->drr_length = DMU_OBJECT_END; 388eda14cbcSMatt Macy else 389eda14cbcSMatt Macy drrf->drr_length = length; 390eda14cbcSMatt Macy drrf->drr_toguid = dscp->dsc_toguid; 391eda14cbcSMatt Macy if (length == DMU_OBJECT_END) { 392eda14cbcSMatt Macy if (dump_record(dscp, NULL, 0) != 0) 393eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 394eda14cbcSMatt Macy } else { 395eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_FREE; 396eda14cbcSMatt Macy } 397eda14cbcSMatt Macy 398eda14cbcSMatt Macy return (0); 399eda14cbcSMatt Macy } 400eda14cbcSMatt Macy 401eda14cbcSMatt Macy /* 402eda14cbcSMatt Macy * Fill in the drr_redact struct, or perform aggregation if the previous record 403eda14cbcSMatt Macy * is also a redaction record, and the two are adjacent. 404eda14cbcSMatt Macy */ 405eda14cbcSMatt Macy static int 406eda14cbcSMatt Macy dump_redact(dmu_send_cookie_t *dscp, uint64_t object, uint64_t offset, 407eda14cbcSMatt Macy uint64_t length) 408eda14cbcSMatt Macy { 409eda14cbcSMatt Macy struct drr_redact *drrr = &dscp->dsc_drr->drr_u.drr_redact; 410eda14cbcSMatt Macy 411eda14cbcSMatt Macy /* 412eda14cbcSMatt Macy * If there is a pending op, but it's not PENDING_REDACT, push it out, 413eda14cbcSMatt Macy * since free block aggregation can only be done for blocks of the 414eda14cbcSMatt Macy * same type (i.e., DRR_REDACT records can only be aggregated with 415eda14cbcSMatt Macy * other DRR_REDACT records). 416eda14cbcSMatt Macy */ 417eda14cbcSMatt Macy if (dscp->dsc_pending_op != PENDING_NONE && 418eda14cbcSMatt Macy dscp->dsc_pending_op != PENDING_REDACT) { 419eda14cbcSMatt Macy if (dump_record(dscp, NULL, 0) != 0) 420eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 421eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_NONE; 422eda14cbcSMatt Macy } 423eda14cbcSMatt Macy 424eda14cbcSMatt Macy if (dscp->dsc_pending_op == PENDING_REDACT) { 425eda14cbcSMatt Macy /* 426eda14cbcSMatt Macy * Check to see whether this redacted block can be aggregated 427eda14cbcSMatt Macy * with pending one. 428eda14cbcSMatt Macy */ 429eda14cbcSMatt Macy if (drrr->drr_object == object && drrr->drr_offset + 430eda14cbcSMatt Macy drrr->drr_length == offset) { 431eda14cbcSMatt Macy drrr->drr_length += length; 432eda14cbcSMatt Macy return (0); 433eda14cbcSMatt Macy } else { 434eda14cbcSMatt Macy /* not a continuation. Push out pending record */ 435eda14cbcSMatt Macy if (dump_record(dscp, NULL, 0) != 0) 436eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 437eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_NONE; 438eda14cbcSMatt Macy } 439eda14cbcSMatt Macy } 440eda14cbcSMatt Macy /* create a REDACT record and make it pending */ 441eda14cbcSMatt Macy bzero(dscp->dsc_drr, sizeof (dmu_replay_record_t)); 442eda14cbcSMatt Macy dscp->dsc_drr->drr_type = DRR_REDACT; 443eda14cbcSMatt Macy drrr->drr_object = object; 444eda14cbcSMatt Macy drrr->drr_offset = offset; 445eda14cbcSMatt Macy drrr->drr_length = length; 446eda14cbcSMatt Macy drrr->drr_toguid = dscp->dsc_toguid; 447eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_REDACT; 448eda14cbcSMatt Macy 449eda14cbcSMatt Macy return (0); 450eda14cbcSMatt Macy } 451eda14cbcSMatt Macy 452eda14cbcSMatt Macy static int 453eda14cbcSMatt Macy dmu_dump_write(dmu_send_cookie_t *dscp, dmu_object_type_t type, uint64_t object, 454*681ce946SMartin Matuska uint64_t offset, int lsize, int psize, const blkptr_t *bp, 455*681ce946SMartin Matuska boolean_t io_compressed, void *data) 456eda14cbcSMatt Macy { 457eda14cbcSMatt Macy uint64_t payload_size; 458eda14cbcSMatt Macy boolean_t raw = (dscp->dsc_featureflags & DMU_BACKUP_FEATURE_RAW); 459eda14cbcSMatt Macy struct drr_write *drrw = &(dscp->dsc_drr->drr_u.drr_write); 460eda14cbcSMatt Macy 461eda14cbcSMatt Macy /* 462eda14cbcSMatt Macy * We send data in increasing object, offset order. 463eda14cbcSMatt Macy * See comment in dump_free() for details. 464eda14cbcSMatt Macy */ 465eda14cbcSMatt Macy ASSERT(object > dscp->dsc_last_data_object || 466eda14cbcSMatt Macy (object == dscp->dsc_last_data_object && 467eda14cbcSMatt Macy offset > dscp->dsc_last_data_offset)); 468eda14cbcSMatt Macy dscp->dsc_last_data_object = object; 469eda14cbcSMatt Macy dscp->dsc_last_data_offset = offset + lsize - 1; 470eda14cbcSMatt Macy 471eda14cbcSMatt Macy /* 472eda14cbcSMatt Macy * If there is any kind of pending aggregation (currently either 473eda14cbcSMatt Macy * a grouping of free objects or free blocks), push it out to 474eda14cbcSMatt Macy * the stream, since aggregation can't be done across operations 475eda14cbcSMatt Macy * of different types. 476eda14cbcSMatt Macy */ 477eda14cbcSMatt Macy if (dscp->dsc_pending_op != PENDING_NONE) { 478eda14cbcSMatt Macy if (dump_record(dscp, NULL, 0) != 0) 479eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 480eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_NONE; 481eda14cbcSMatt Macy } 482eda14cbcSMatt Macy /* write a WRITE record */ 483eda14cbcSMatt Macy bzero(dscp->dsc_drr, sizeof (dmu_replay_record_t)); 484eda14cbcSMatt Macy dscp->dsc_drr->drr_type = DRR_WRITE; 485eda14cbcSMatt Macy drrw->drr_object = object; 486eda14cbcSMatt Macy drrw->drr_type = type; 487eda14cbcSMatt Macy drrw->drr_offset = offset; 488eda14cbcSMatt Macy drrw->drr_toguid = dscp->dsc_toguid; 489eda14cbcSMatt Macy drrw->drr_logical_size = lsize; 490eda14cbcSMatt Macy 491eda14cbcSMatt Macy /* only set the compression fields if the buf is compressed or raw */ 492*681ce946SMartin Matuska boolean_t compressed = 493*681ce946SMartin Matuska (bp != NULL ? BP_GET_COMPRESS(bp) != ZIO_COMPRESS_OFF && 494*681ce946SMartin Matuska io_compressed : lsize != psize); 495*681ce946SMartin Matuska if (raw || compressed) { 496eda14cbcSMatt Macy ASSERT(raw || dscp->dsc_featureflags & 497eda14cbcSMatt Macy DMU_BACKUP_FEATURE_COMPRESSED); 498eda14cbcSMatt Macy ASSERT(!BP_IS_EMBEDDED(bp)); 499eda14cbcSMatt Macy ASSERT3S(psize, >, 0); 500eda14cbcSMatt Macy 501eda14cbcSMatt Macy if (raw) { 502eda14cbcSMatt Macy ASSERT(BP_IS_PROTECTED(bp)); 503eda14cbcSMatt Macy 504eda14cbcSMatt Macy /* 505eda14cbcSMatt Macy * This is a raw protected block so we need to pass 506eda14cbcSMatt Macy * along everything the receiving side will need to 507eda14cbcSMatt Macy * interpret this block, including the byteswap, salt, 508eda14cbcSMatt Macy * IV, and MAC. 509eda14cbcSMatt Macy */ 510eda14cbcSMatt Macy if (BP_SHOULD_BYTESWAP(bp)) 511eda14cbcSMatt Macy drrw->drr_flags |= DRR_RAW_BYTESWAP; 512eda14cbcSMatt Macy zio_crypt_decode_params_bp(bp, drrw->drr_salt, 513eda14cbcSMatt Macy drrw->drr_iv); 514eda14cbcSMatt Macy zio_crypt_decode_mac_bp(bp, drrw->drr_mac); 515eda14cbcSMatt Macy } else { 516eda14cbcSMatt Macy /* this is a compressed block */ 517eda14cbcSMatt Macy ASSERT(dscp->dsc_featureflags & 518eda14cbcSMatt Macy DMU_BACKUP_FEATURE_COMPRESSED); 519eda14cbcSMatt Macy ASSERT(!BP_SHOULD_BYTESWAP(bp)); 520eda14cbcSMatt Macy ASSERT(!DMU_OT_IS_METADATA(BP_GET_TYPE(bp))); 521eda14cbcSMatt Macy ASSERT3U(BP_GET_COMPRESS(bp), !=, ZIO_COMPRESS_OFF); 522eda14cbcSMatt Macy ASSERT3S(lsize, >=, psize); 523eda14cbcSMatt Macy } 524eda14cbcSMatt Macy 525eda14cbcSMatt Macy /* set fields common to compressed and raw sends */ 526eda14cbcSMatt Macy drrw->drr_compressiontype = BP_GET_COMPRESS(bp); 527eda14cbcSMatt Macy drrw->drr_compressed_size = psize; 528eda14cbcSMatt Macy payload_size = drrw->drr_compressed_size; 529eda14cbcSMatt Macy } else { 530eda14cbcSMatt Macy payload_size = drrw->drr_logical_size; 531eda14cbcSMatt Macy } 532eda14cbcSMatt Macy 533eda14cbcSMatt Macy if (bp == NULL || BP_IS_EMBEDDED(bp) || (BP_IS_PROTECTED(bp) && !raw)) { 534eda14cbcSMatt Macy /* 535eda14cbcSMatt Macy * There's no pre-computed checksum for partial-block writes, 536eda14cbcSMatt Macy * embedded BP's, or encrypted BP's that are being sent as 537eda14cbcSMatt Macy * plaintext, so (like fletcher4-checksummed blocks) userland 538eda14cbcSMatt Macy * will have to compute a dedup-capable checksum itself. 539eda14cbcSMatt Macy */ 540eda14cbcSMatt Macy drrw->drr_checksumtype = ZIO_CHECKSUM_OFF; 541eda14cbcSMatt Macy } else { 542eda14cbcSMatt Macy drrw->drr_checksumtype = BP_GET_CHECKSUM(bp); 543eda14cbcSMatt Macy if (zio_checksum_table[drrw->drr_checksumtype].ci_flags & 544eda14cbcSMatt Macy ZCHECKSUM_FLAG_DEDUP) 545eda14cbcSMatt Macy drrw->drr_flags |= DRR_CHECKSUM_DEDUP; 546eda14cbcSMatt Macy DDK_SET_LSIZE(&drrw->drr_key, BP_GET_LSIZE(bp)); 547eda14cbcSMatt Macy DDK_SET_PSIZE(&drrw->drr_key, BP_GET_PSIZE(bp)); 548eda14cbcSMatt Macy DDK_SET_COMPRESS(&drrw->drr_key, BP_GET_COMPRESS(bp)); 549eda14cbcSMatt Macy DDK_SET_CRYPT(&drrw->drr_key, BP_IS_PROTECTED(bp)); 550eda14cbcSMatt Macy drrw->drr_key.ddk_cksum = bp->blk_cksum; 551eda14cbcSMatt Macy } 552eda14cbcSMatt Macy 553eda14cbcSMatt Macy if (dump_record(dscp, data, payload_size) != 0) 554eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 555eda14cbcSMatt Macy return (0); 556eda14cbcSMatt Macy } 557eda14cbcSMatt Macy 558eda14cbcSMatt Macy static int 559eda14cbcSMatt Macy dump_write_embedded(dmu_send_cookie_t *dscp, uint64_t object, uint64_t offset, 560eda14cbcSMatt Macy int blksz, const blkptr_t *bp) 561eda14cbcSMatt Macy { 562eda14cbcSMatt Macy char buf[BPE_PAYLOAD_SIZE]; 563eda14cbcSMatt Macy struct drr_write_embedded *drrw = 564eda14cbcSMatt Macy &(dscp->dsc_drr->drr_u.drr_write_embedded); 565eda14cbcSMatt Macy 566eda14cbcSMatt Macy if (dscp->dsc_pending_op != PENDING_NONE) { 567eda14cbcSMatt Macy if (dump_record(dscp, NULL, 0) != 0) 568eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 569eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_NONE; 570eda14cbcSMatt Macy } 571eda14cbcSMatt Macy 572eda14cbcSMatt Macy ASSERT(BP_IS_EMBEDDED(bp)); 573eda14cbcSMatt Macy 574eda14cbcSMatt Macy bzero(dscp->dsc_drr, sizeof (dmu_replay_record_t)); 575eda14cbcSMatt Macy dscp->dsc_drr->drr_type = DRR_WRITE_EMBEDDED; 576eda14cbcSMatt Macy drrw->drr_object = object; 577eda14cbcSMatt Macy drrw->drr_offset = offset; 578eda14cbcSMatt Macy drrw->drr_length = blksz; 579eda14cbcSMatt Macy drrw->drr_toguid = dscp->dsc_toguid; 580eda14cbcSMatt Macy drrw->drr_compression = BP_GET_COMPRESS(bp); 581eda14cbcSMatt Macy drrw->drr_etype = BPE_GET_ETYPE(bp); 582eda14cbcSMatt Macy drrw->drr_lsize = BPE_GET_LSIZE(bp); 583eda14cbcSMatt Macy drrw->drr_psize = BPE_GET_PSIZE(bp); 584eda14cbcSMatt Macy 585eda14cbcSMatt Macy decode_embedded_bp_compressed(bp, buf); 586eda14cbcSMatt Macy 587eda14cbcSMatt Macy if (dump_record(dscp, buf, P2ROUNDUP(drrw->drr_psize, 8)) != 0) 588eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 589eda14cbcSMatt Macy return (0); 590eda14cbcSMatt Macy } 591eda14cbcSMatt Macy 592eda14cbcSMatt Macy static int 593eda14cbcSMatt Macy dump_spill(dmu_send_cookie_t *dscp, const blkptr_t *bp, uint64_t object, 594eda14cbcSMatt Macy void *data) 595eda14cbcSMatt Macy { 596eda14cbcSMatt Macy struct drr_spill *drrs = &(dscp->dsc_drr->drr_u.drr_spill); 597eda14cbcSMatt Macy uint64_t blksz = BP_GET_LSIZE(bp); 598eda14cbcSMatt Macy uint64_t payload_size = blksz; 599eda14cbcSMatt Macy 600eda14cbcSMatt Macy if (dscp->dsc_pending_op != PENDING_NONE) { 601eda14cbcSMatt Macy if (dump_record(dscp, NULL, 0) != 0) 602eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 603eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_NONE; 604eda14cbcSMatt Macy } 605eda14cbcSMatt Macy 606eda14cbcSMatt Macy /* write a SPILL record */ 607eda14cbcSMatt Macy bzero(dscp->dsc_drr, sizeof (dmu_replay_record_t)); 608eda14cbcSMatt Macy dscp->dsc_drr->drr_type = DRR_SPILL; 609eda14cbcSMatt Macy drrs->drr_object = object; 610eda14cbcSMatt Macy drrs->drr_length = blksz; 611eda14cbcSMatt Macy drrs->drr_toguid = dscp->dsc_toguid; 612eda14cbcSMatt Macy 613eda14cbcSMatt Macy /* See comment in dump_dnode() for full details */ 614eda14cbcSMatt Macy if (zfs_send_unmodified_spill_blocks && 615eda14cbcSMatt Macy (bp->blk_birth <= dscp->dsc_fromtxg)) { 616eda14cbcSMatt Macy drrs->drr_flags |= DRR_SPILL_UNMODIFIED; 617eda14cbcSMatt Macy } 618eda14cbcSMatt Macy 619eda14cbcSMatt Macy /* handle raw send fields */ 620eda14cbcSMatt Macy if (dscp->dsc_featureflags & DMU_BACKUP_FEATURE_RAW) { 621eda14cbcSMatt Macy ASSERT(BP_IS_PROTECTED(bp)); 622eda14cbcSMatt Macy 623eda14cbcSMatt Macy if (BP_SHOULD_BYTESWAP(bp)) 624eda14cbcSMatt Macy drrs->drr_flags |= DRR_RAW_BYTESWAP; 625eda14cbcSMatt Macy drrs->drr_compressiontype = BP_GET_COMPRESS(bp); 626eda14cbcSMatt Macy drrs->drr_compressed_size = BP_GET_PSIZE(bp); 627eda14cbcSMatt Macy zio_crypt_decode_params_bp(bp, drrs->drr_salt, drrs->drr_iv); 628eda14cbcSMatt Macy zio_crypt_decode_mac_bp(bp, drrs->drr_mac); 629eda14cbcSMatt Macy payload_size = drrs->drr_compressed_size; 630eda14cbcSMatt Macy } 631eda14cbcSMatt Macy 632eda14cbcSMatt Macy if (dump_record(dscp, data, payload_size) != 0) 633eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 634eda14cbcSMatt Macy return (0); 635eda14cbcSMatt Macy } 636eda14cbcSMatt Macy 637eda14cbcSMatt Macy static int 638eda14cbcSMatt Macy dump_freeobjects(dmu_send_cookie_t *dscp, uint64_t firstobj, uint64_t numobjs) 639eda14cbcSMatt Macy { 640eda14cbcSMatt Macy struct drr_freeobjects *drrfo = &(dscp->dsc_drr->drr_u.drr_freeobjects); 641eda14cbcSMatt Macy uint64_t maxobj = DNODES_PER_BLOCK * 642eda14cbcSMatt Macy (DMU_META_DNODE(dscp->dsc_os)->dn_maxblkid + 1); 643eda14cbcSMatt Macy 644eda14cbcSMatt Macy /* 645eda14cbcSMatt Macy * ZoL < 0.7 does not handle large FREEOBJECTS records correctly, 646eda14cbcSMatt Macy * leading to zfs recv never completing. to avoid this issue, don't 647eda14cbcSMatt Macy * send FREEOBJECTS records for object IDs which cannot exist on the 648eda14cbcSMatt Macy * receiving side. 649eda14cbcSMatt Macy */ 650eda14cbcSMatt Macy if (maxobj > 0) { 651c40487d4SMatt Macy if (maxobj <= firstobj) 652eda14cbcSMatt Macy return (0); 653eda14cbcSMatt Macy 654eda14cbcSMatt Macy if (maxobj < firstobj + numobjs) 655eda14cbcSMatt Macy numobjs = maxobj - firstobj; 656eda14cbcSMatt Macy } 657eda14cbcSMatt Macy 658eda14cbcSMatt Macy /* 659eda14cbcSMatt Macy * If there is a pending op, but it's not PENDING_FREEOBJECTS, 660eda14cbcSMatt Macy * push it out, since free block aggregation can only be done for 661eda14cbcSMatt Macy * blocks of the same type (i.e., DRR_FREE records can only be 662eda14cbcSMatt Macy * aggregated with other DRR_FREE records. DRR_FREEOBJECTS records 663eda14cbcSMatt Macy * can only be aggregated with other DRR_FREEOBJECTS records). 664eda14cbcSMatt Macy */ 665eda14cbcSMatt Macy if (dscp->dsc_pending_op != PENDING_NONE && 666eda14cbcSMatt Macy dscp->dsc_pending_op != PENDING_FREEOBJECTS) { 667eda14cbcSMatt Macy if (dump_record(dscp, NULL, 0) != 0) 668eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 669eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_NONE; 670eda14cbcSMatt Macy } 671eda14cbcSMatt Macy 672eda14cbcSMatt Macy if (dscp->dsc_pending_op == PENDING_FREEOBJECTS) { 673eda14cbcSMatt Macy /* 674eda14cbcSMatt Macy * See whether this free object array can be aggregated 675eda14cbcSMatt Macy * with pending one 676eda14cbcSMatt Macy */ 677eda14cbcSMatt Macy if (drrfo->drr_firstobj + drrfo->drr_numobjs == firstobj) { 678eda14cbcSMatt Macy drrfo->drr_numobjs += numobjs; 679eda14cbcSMatt Macy return (0); 680eda14cbcSMatt Macy } else { 681eda14cbcSMatt Macy /* can't be aggregated. Push out pending record */ 682eda14cbcSMatt Macy if (dump_record(dscp, NULL, 0) != 0) 683eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 684eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_NONE; 685eda14cbcSMatt Macy } 686eda14cbcSMatt Macy } 687eda14cbcSMatt Macy 688eda14cbcSMatt Macy /* write a FREEOBJECTS record */ 689eda14cbcSMatt Macy bzero(dscp->dsc_drr, sizeof (dmu_replay_record_t)); 690eda14cbcSMatt Macy dscp->dsc_drr->drr_type = DRR_FREEOBJECTS; 691eda14cbcSMatt Macy drrfo->drr_firstobj = firstobj; 692eda14cbcSMatt Macy drrfo->drr_numobjs = numobjs; 693eda14cbcSMatt Macy drrfo->drr_toguid = dscp->dsc_toguid; 694eda14cbcSMatt Macy 695eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_FREEOBJECTS; 696eda14cbcSMatt Macy 697eda14cbcSMatt Macy return (0); 698eda14cbcSMatt Macy } 699eda14cbcSMatt Macy 700eda14cbcSMatt Macy static int 701eda14cbcSMatt Macy dump_dnode(dmu_send_cookie_t *dscp, const blkptr_t *bp, uint64_t object, 702eda14cbcSMatt Macy dnode_phys_t *dnp) 703eda14cbcSMatt Macy { 704eda14cbcSMatt Macy struct drr_object *drro = &(dscp->dsc_drr->drr_u.drr_object); 705eda14cbcSMatt Macy int bonuslen; 706eda14cbcSMatt Macy 707eda14cbcSMatt Macy if (object < dscp->dsc_resume_object) { 708eda14cbcSMatt Macy /* 709eda14cbcSMatt Macy * Note: when resuming, we will visit all the dnodes in 710eda14cbcSMatt Macy * the block of dnodes that we are resuming from. In 711eda14cbcSMatt Macy * this case it's unnecessary to send the dnodes prior to 712eda14cbcSMatt Macy * the one we are resuming from. We should be at most one 713eda14cbcSMatt Macy * block's worth of dnodes behind the resume point. 714eda14cbcSMatt Macy */ 715eda14cbcSMatt Macy ASSERT3U(dscp->dsc_resume_object - object, <, 716eda14cbcSMatt Macy 1 << (DNODE_BLOCK_SHIFT - DNODE_SHIFT)); 717eda14cbcSMatt Macy return (0); 718eda14cbcSMatt Macy } 719eda14cbcSMatt Macy 720eda14cbcSMatt Macy if (dnp == NULL || dnp->dn_type == DMU_OT_NONE) 721eda14cbcSMatt Macy return (dump_freeobjects(dscp, object, 1)); 722eda14cbcSMatt Macy 723eda14cbcSMatt Macy if (dscp->dsc_pending_op != PENDING_NONE) { 724eda14cbcSMatt Macy if (dump_record(dscp, NULL, 0) != 0) 725eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 726eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_NONE; 727eda14cbcSMatt Macy } 728eda14cbcSMatt Macy 729eda14cbcSMatt Macy /* write an OBJECT record */ 730eda14cbcSMatt Macy bzero(dscp->dsc_drr, sizeof (dmu_replay_record_t)); 731eda14cbcSMatt Macy dscp->dsc_drr->drr_type = DRR_OBJECT; 732eda14cbcSMatt Macy drro->drr_object = object; 733eda14cbcSMatt Macy drro->drr_type = dnp->dn_type; 734eda14cbcSMatt Macy drro->drr_bonustype = dnp->dn_bonustype; 735eda14cbcSMatt Macy drro->drr_blksz = dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT; 736eda14cbcSMatt Macy drro->drr_bonuslen = dnp->dn_bonuslen; 737eda14cbcSMatt Macy drro->drr_dn_slots = dnp->dn_extra_slots + 1; 738eda14cbcSMatt Macy drro->drr_checksumtype = dnp->dn_checksum; 739eda14cbcSMatt Macy drro->drr_compress = dnp->dn_compress; 740eda14cbcSMatt Macy drro->drr_toguid = dscp->dsc_toguid; 741eda14cbcSMatt Macy 742eda14cbcSMatt Macy if (!(dscp->dsc_featureflags & DMU_BACKUP_FEATURE_LARGE_BLOCKS) && 743eda14cbcSMatt Macy drro->drr_blksz > SPA_OLD_MAXBLOCKSIZE) 744eda14cbcSMatt Macy drro->drr_blksz = SPA_OLD_MAXBLOCKSIZE; 745eda14cbcSMatt Macy 746eda14cbcSMatt Macy bonuslen = P2ROUNDUP(dnp->dn_bonuslen, 8); 747eda14cbcSMatt Macy 748eda14cbcSMatt Macy if ((dscp->dsc_featureflags & DMU_BACKUP_FEATURE_RAW)) { 749eda14cbcSMatt Macy ASSERT(BP_IS_ENCRYPTED(bp)); 750eda14cbcSMatt Macy 751eda14cbcSMatt Macy if (BP_SHOULD_BYTESWAP(bp)) 752eda14cbcSMatt Macy drro->drr_flags |= DRR_RAW_BYTESWAP; 753eda14cbcSMatt Macy 754eda14cbcSMatt Macy /* needed for reconstructing dnp on recv side */ 755eda14cbcSMatt Macy drro->drr_maxblkid = dnp->dn_maxblkid; 756eda14cbcSMatt Macy drro->drr_indblkshift = dnp->dn_indblkshift; 757eda14cbcSMatt Macy drro->drr_nlevels = dnp->dn_nlevels; 758eda14cbcSMatt Macy drro->drr_nblkptr = dnp->dn_nblkptr; 759eda14cbcSMatt Macy 760eda14cbcSMatt Macy /* 761eda14cbcSMatt Macy * Since we encrypt the entire bonus area, the (raw) part 762eda14cbcSMatt Macy * beyond the bonuslen is actually nonzero, so we need 763eda14cbcSMatt Macy * to send it. 764eda14cbcSMatt Macy */ 765eda14cbcSMatt Macy if (bonuslen != 0) { 766eda14cbcSMatt Macy drro->drr_raw_bonuslen = DN_MAX_BONUS_LEN(dnp); 767eda14cbcSMatt Macy bonuslen = drro->drr_raw_bonuslen; 768eda14cbcSMatt Macy } 769eda14cbcSMatt Macy } 770eda14cbcSMatt Macy 771eda14cbcSMatt Macy /* 772eda14cbcSMatt Macy * DRR_OBJECT_SPILL is set for every dnode which references a 773eda14cbcSMatt Macy * spill block. This allows the receiving pool to definitively 774eda14cbcSMatt Macy * determine when a spill block should be kept or freed. 775eda14cbcSMatt Macy */ 776eda14cbcSMatt Macy if (dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) 777eda14cbcSMatt Macy drro->drr_flags |= DRR_OBJECT_SPILL; 778eda14cbcSMatt Macy 779eda14cbcSMatt Macy if (dump_record(dscp, DN_BONUS(dnp), bonuslen) != 0) 780eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 781eda14cbcSMatt Macy 782eda14cbcSMatt Macy /* Free anything past the end of the file. */ 783eda14cbcSMatt Macy if (dump_free(dscp, object, (dnp->dn_maxblkid + 1) * 784eda14cbcSMatt Macy (dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT), DMU_OBJECT_END) != 0) 785eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 786eda14cbcSMatt Macy 787eda14cbcSMatt Macy /* 788eda14cbcSMatt Macy * Send DRR_SPILL records for unmodified spill blocks. This is useful 789eda14cbcSMatt Macy * because changing certain attributes of the object (e.g. blocksize) 790eda14cbcSMatt Macy * can cause old versions of ZFS to incorrectly remove a spill block. 791eda14cbcSMatt Macy * Including these records in the stream forces an up to date version 792eda14cbcSMatt Macy * to always be written ensuring they're never lost. Current versions 793eda14cbcSMatt Macy * of the code which understand the DRR_FLAG_SPILL_BLOCK feature can 794eda14cbcSMatt Macy * ignore these unmodified spill blocks. 795eda14cbcSMatt Macy */ 796eda14cbcSMatt Macy if (zfs_send_unmodified_spill_blocks && 797eda14cbcSMatt Macy (dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) && 798eda14cbcSMatt Macy (DN_SPILL_BLKPTR(dnp)->blk_birth <= dscp->dsc_fromtxg)) { 799eda14cbcSMatt Macy struct send_range record; 800eda14cbcSMatt Macy blkptr_t *bp = DN_SPILL_BLKPTR(dnp); 801eda14cbcSMatt Macy 802eda14cbcSMatt Macy bzero(&record, sizeof (struct send_range)); 803eda14cbcSMatt Macy record.type = DATA; 804eda14cbcSMatt Macy record.object = object; 805eda14cbcSMatt Macy record.eos_marker = B_FALSE; 806eda14cbcSMatt Macy record.start_blkid = DMU_SPILL_BLKID; 807eda14cbcSMatt Macy record.end_blkid = record.start_blkid + 1; 808eda14cbcSMatt Macy record.sru.data.bp = *bp; 809eda14cbcSMatt Macy record.sru.data.obj_type = dnp->dn_type; 810eda14cbcSMatt Macy record.sru.data.datablksz = BP_GET_LSIZE(bp); 811eda14cbcSMatt Macy 812eda14cbcSMatt Macy if (do_dump(dscp, &record) != 0) 813eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 814eda14cbcSMatt Macy } 815eda14cbcSMatt Macy 816eda14cbcSMatt Macy if (dscp->dsc_err != 0) 817eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 818eda14cbcSMatt Macy 819eda14cbcSMatt Macy return (0); 820eda14cbcSMatt Macy } 821eda14cbcSMatt Macy 822eda14cbcSMatt Macy static int 823eda14cbcSMatt Macy dump_object_range(dmu_send_cookie_t *dscp, const blkptr_t *bp, 824eda14cbcSMatt Macy uint64_t firstobj, uint64_t numslots) 825eda14cbcSMatt Macy { 826eda14cbcSMatt Macy struct drr_object_range *drror = 827eda14cbcSMatt Macy &(dscp->dsc_drr->drr_u.drr_object_range); 828eda14cbcSMatt Macy 829eda14cbcSMatt Macy /* we only use this record type for raw sends */ 830eda14cbcSMatt Macy ASSERT(BP_IS_PROTECTED(bp)); 831eda14cbcSMatt Macy ASSERT(dscp->dsc_featureflags & DMU_BACKUP_FEATURE_RAW); 832eda14cbcSMatt Macy ASSERT3U(BP_GET_COMPRESS(bp), ==, ZIO_COMPRESS_OFF); 833eda14cbcSMatt Macy ASSERT3U(BP_GET_TYPE(bp), ==, DMU_OT_DNODE); 834eda14cbcSMatt Macy ASSERT0(BP_GET_LEVEL(bp)); 835eda14cbcSMatt Macy 836eda14cbcSMatt Macy if (dscp->dsc_pending_op != PENDING_NONE) { 837eda14cbcSMatt Macy if (dump_record(dscp, NULL, 0) != 0) 838eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 839eda14cbcSMatt Macy dscp->dsc_pending_op = PENDING_NONE; 840eda14cbcSMatt Macy } 841eda14cbcSMatt Macy 842eda14cbcSMatt Macy bzero(dscp->dsc_drr, sizeof (dmu_replay_record_t)); 843eda14cbcSMatt Macy dscp->dsc_drr->drr_type = DRR_OBJECT_RANGE; 844eda14cbcSMatt Macy drror->drr_firstobj = firstobj; 845eda14cbcSMatt Macy drror->drr_numslots = numslots; 846eda14cbcSMatt Macy drror->drr_toguid = dscp->dsc_toguid; 847eda14cbcSMatt Macy if (BP_SHOULD_BYTESWAP(bp)) 848eda14cbcSMatt Macy drror->drr_flags |= DRR_RAW_BYTESWAP; 849eda14cbcSMatt Macy zio_crypt_decode_params_bp(bp, drror->drr_salt, drror->drr_iv); 850eda14cbcSMatt Macy zio_crypt_decode_mac_bp(bp, drror->drr_mac); 851eda14cbcSMatt Macy 852eda14cbcSMatt Macy if (dump_record(dscp, NULL, 0) != 0) 853eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 854eda14cbcSMatt Macy return (0); 855eda14cbcSMatt Macy } 856eda14cbcSMatt Macy 857eda14cbcSMatt Macy static boolean_t 858eda14cbcSMatt Macy send_do_embed(const blkptr_t *bp, uint64_t featureflags) 859eda14cbcSMatt Macy { 860eda14cbcSMatt Macy if (!BP_IS_EMBEDDED(bp)) 861eda14cbcSMatt Macy return (B_FALSE); 862eda14cbcSMatt Macy 863eda14cbcSMatt Macy /* 864eda14cbcSMatt Macy * Compression function must be legacy, or explicitly enabled. 865eda14cbcSMatt Macy */ 866eda14cbcSMatt Macy if ((BP_GET_COMPRESS(bp) >= ZIO_COMPRESS_LEGACY_FUNCTIONS && 867eda14cbcSMatt Macy !(featureflags & DMU_BACKUP_FEATURE_LZ4))) 868eda14cbcSMatt Macy return (B_FALSE); 869eda14cbcSMatt Macy 870eda14cbcSMatt Macy /* 871eda14cbcSMatt Macy * If we have not set the ZSTD feature flag, we can't send ZSTD 872eda14cbcSMatt Macy * compressed embedded blocks, as the receiver may not support them. 873eda14cbcSMatt Macy */ 874eda14cbcSMatt Macy if ((BP_GET_COMPRESS(bp) == ZIO_COMPRESS_ZSTD && 875eda14cbcSMatt Macy !(featureflags & DMU_BACKUP_FEATURE_ZSTD))) 876eda14cbcSMatt Macy return (B_FALSE); 877eda14cbcSMatt Macy 878eda14cbcSMatt Macy /* 879eda14cbcSMatt Macy * Embed type must be explicitly enabled. 880eda14cbcSMatt Macy */ 881eda14cbcSMatt Macy switch (BPE_GET_ETYPE(bp)) { 882eda14cbcSMatt Macy case BP_EMBEDDED_TYPE_DATA: 883eda14cbcSMatt Macy if (featureflags & DMU_BACKUP_FEATURE_EMBED_DATA) 884eda14cbcSMatt Macy return (B_TRUE); 885eda14cbcSMatt Macy break; 886eda14cbcSMatt Macy default: 887eda14cbcSMatt Macy return (B_FALSE); 888eda14cbcSMatt Macy } 889eda14cbcSMatt Macy return (B_FALSE); 890eda14cbcSMatt Macy } 891eda14cbcSMatt Macy 892eda14cbcSMatt Macy /* 893eda14cbcSMatt Macy * This function actually handles figuring out what kind of record needs to be 894eda14cbcSMatt Macy * dumped, and calling the appropriate helper function. In most cases, 895eda14cbcSMatt Macy * the data has already been read by send_reader_thread(). 896eda14cbcSMatt Macy */ 897eda14cbcSMatt Macy static int 898eda14cbcSMatt Macy do_dump(dmu_send_cookie_t *dscp, struct send_range *range) 899eda14cbcSMatt Macy { 900eda14cbcSMatt Macy int err = 0; 901eda14cbcSMatt Macy switch (range->type) { 902eda14cbcSMatt Macy case OBJECT: 903eda14cbcSMatt Macy err = dump_dnode(dscp, &range->sru.object.bp, range->object, 904eda14cbcSMatt Macy range->sru.object.dnp); 905eda14cbcSMatt Macy return (err); 906eda14cbcSMatt Macy case OBJECT_RANGE: { 907eda14cbcSMatt Macy ASSERT3U(range->start_blkid + 1, ==, range->end_blkid); 908eda14cbcSMatt Macy if (!(dscp->dsc_featureflags & DMU_BACKUP_FEATURE_RAW)) { 909eda14cbcSMatt Macy return (0); 910eda14cbcSMatt Macy } 911eda14cbcSMatt Macy uint64_t epb = BP_GET_LSIZE(&range->sru.object_range.bp) >> 912eda14cbcSMatt Macy DNODE_SHIFT; 913eda14cbcSMatt Macy uint64_t firstobj = range->start_blkid * epb; 914eda14cbcSMatt Macy err = dump_object_range(dscp, &range->sru.object_range.bp, 915eda14cbcSMatt Macy firstobj, epb); 916eda14cbcSMatt Macy break; 917eda14cbcSMatt Macy } 918eda14cbcSMatt Macy case REDACT: { 919eda14cbcSMatt Macy struct srr *srrp = &range->sru.redact; 920eda14cbcSMatt Macy err = dump_redact(dscp, range->object, range->start_blkid * 921eda14cbcSMatt Macy srrp->datablksz, (range->end_blkid - range->start_blkid) * 922eda14cbcSMatt Macy srrp->datablksz); 923eda14cbcSMatt Macy return (err); 924eda14cbcSMatt Macy } 925eda14cbcSMatt Macy case DATA: { 926eda14cbcSMatt Macy struct srd *srdp = &range->sru.data; 927eda14cbcSMatt Macy blkptr_t *bp = &srdp->bp; 928eda14cbcSMatt Macy spa_t *spa = 929eda14cbcSMatt Macy dmu_objset_spa(dscp->dsc_os); 930eda14cbcSMatt Macy 931eda14cbcSMatt Macy ASSERT3U(srdp->datablksz, ==, BP_GET_LSIZE(bp)); 932eda14cbcSMatt Macy ASSERT3U(range->start_blkid + 1, ==, range->end_blkid); 933eda14cbcSMatt Macy if (BP_GET_TYPE(bp) == DMU_OT_SA) { 934eda14cbcSMatt Macy arc_flags_t aflags = ARC_FLAG_WAIT; 935eda14cbcSMatt Macy enum zio_flag zioflags = ZIO_FLAG_CANFAIL; 936eda14cbcSMatt Macy 937eda14cbcSMatt Macy if (dscp->dsc_featureflags & DMU_BACKUP_FEATURE_RAW) { 938eda14cbcSMatt Macy ASSERT(BP_IS_PROTECTED(bp)); 939eda14cbcSMatt Macy zioflags |= ZIO_FLAG_RAW; 940eda14cbcSMatt Macy } 941eda14cbcSMatt Macy 942eda14cbcSMatt Macy zbookmark_phys_t zb; 943eda14cbcSMatt Macy ASSERT3U(range->start_blkid, ==, DMU_SPILL_BLKID); 944eda14cbcSMatt Macy zb.zb_objset = dmu_objset_id(dscp->dsc_os); 945eda14cbcSMatt Macy zb.zb_object = range->object; 946eda14cbcSMatt Macy zb.zb_level = 0; 947eda14cbcSMatt Macy zb.zb_blkid = range->start_blkid; 948eda14cbcSMatt Macy 949eda14cbcSMatt Macy arc_buf_t *abuf = NULL; 950eda14cbcSMatt Macy if (!dscp->dsc_dso->dso_dryrun && arc_read(NULL, spa, 951eda14cbcSMatt Macy bp, arc_getbuf_func, &abuf, ZIO_PRIORITY_ASYNC_READ, 952eda14cbcSMatt Macy zioflags, &aflags, &zb) != 0) 953eda14cbcSMatt Macy return (SET_ERROR(EIO)); 954eda14cbcSMatt Macy 955eda14cbcSMatt Macy err = dump_spill(dscp, bp, zb.zb_object, 956eda14cbcSMatt Macy (abuf == NULL ? NULL : abuf->b_data)); 957eda14cbcSMatt Macy if (abuf != NULL) 958eda14cbcSMatt Macy arc_buf_destroy(abuf, &abuf); 959eda14cbcSMatt Macy return (err); 960eda14cbcSMatt Macy } 961eda14cbcSMatt Macy if (send_do_embed(bp, dscp->dsc_featureflags)) { 962eda14cbcSMatt Macy err = dump_write_embedded(dscp, range->object, 963eda14cbcSMatt Macy range->start_blkid * srdp->datablksz, 964eda14cbcSMatt Macy srdp->datablksz, bp); 965eda14cbcSMatt Macy return (err); 966eda14cbcSMatt Macy } 967eda14cbcSMatt Macy ASSERT(range->object > dscp->dsc_resume_object || 968eda14cbcSMatt Macy (range->object == dscp->dsc_resume_object && 969eda14cbcSMatt Macy range->start_blkid * srdp->datablksz >= 970eda14cbcSMatt Macy dscp->dsc_resume_offset)); 971eda14cbcSMatt Macy /* it's a level-0 block of a regular object */ 972eda14cbcSMatt Macy 973eda14cbcSMatt Macy mutex_enter(&srdp->lock); 974eda14cbcSMatt Macy while (srdp->io_outstanding) 975eda14cbcSMatt Macy cv_wait(&srdp->cv, &srdp->lock); 976eda14cbcSMatt Macy err = srdp->io_err; 977eda14cbcSMatt Macy mutex_exit(&srdp->lock); 978eda14cbcSMatt Macy 979eda14cbcSMatt Macy if (err != 0) { 980eda14cbcSMatt Macy if (zfs_send_corrupt_data && 981eda14cbcSMatt Macy !dscp->dsc_dso->dso_dryrun) { 982eda14cbcSMatt Macy /* 983eda14cbcSMatt Macy * Send a block filled with 0x"zfs badd bloc" 984eda14cbcSMatt Macy */ 985eda14cbcSMatt Macy srdp->abuf = arc_alloc_buf(spa, &srdp->abuf, 986eda14cbcSMatt Macy ARC_BUFC_DATA, srdp->datablksz); 987eda14cbcSMatt Macy uint64_t *ptr; 988eda14cbcSMatt Macy for (ptr = srdp->abuf->b_data; 989eda14cbcSMatt Macy (char *)ptr < (char *)srdp->abuf->b_data + 990eda14cbcSMatt Macy srdp->datablksz; ptr++) 991eda14cbcSMatt Macy *ptr = 0x2f5baddb10cULL; 992eda14cbcSMatt Macy } else { 993eda14cbcSMatt Macy return (SET_ERROR(EIO)); 994eda14cbcSMatt Macy } 995eda14cbcSMatt Macy } 996eda14cbcSMatt Macy 997eda14cbcSMatt Macy ASSERT(dscp->dsc_dso->dso_dryrun || 998eda14cbcSMatt Macy srdp->abuf != NULL || srdp->abd != NULL); 999eda14cbcSMatt Macy 1000eda14cbcSMatt Macy uint64_t offset = range->start_blkid * srdp->datablksz; 1001eda14cbcSMatt Macy 1002eda14cbcSMatt Macy char *data = NULL; 1003eda14cbcSMatt Macy if (srdp->abd != NULL) { 1004eda14cbcSMatt Macy data = abd_to_buf(srdp->abd); 1005eda14cbcSMatt Macy ASSERT3P(srdp->abuf, ==, NULL); 1006eda14cbcSMatt Macy } else if (srdp->abuf != NULL) { 1007eda14cbcSMatt Macy data = srdp->abuf->b_data; 1008eda14cbcSMatt Macy } 1009eda14cbcSMatt Macy 1010eda14cbcSMatt Macy /* 1011eda14cbcSMatt Macy * If we have large blocks stored on disk but the send flags 1012eda14cbcSMatt Macy * don't allow us to send large blocks, we split the data from 1013eda14cbcSMatt Macy * the arc buf into chunks. 1014eda14cbcSMatt Macy */ 1015eda14cbcSMatt Macy if (srdp->datablksz > SPA_OLD_MAXBLOCKSIZE && 1016eda14cbcSMatt Macy !(dscp->dsc_featureflags & 1017eda14cbcSMatt Macy DMU_BACKUP_FEATURE_LARGE_BLOCKS)) { 1018eda14cbcSMatt Macy while (srdp->datablksz > 0 && err == 0) { 1019eda14cbcSMatt Macy int n = MIN(srdp->datablksz, 1020eda14cbcSMatt Macy SPA_OLD_MAXBLOCKSIZE); 1021eda14cbcSMatt Macy err = dmu_dump_write(dscp, srdp->obj_type, 1022*681ce946SMartin Matuska range->object, offset, n, n, NULL, B_FALSE, 1023*681ce946SMartin Matuska data); 1024eda14cbcSMatt Macy offset += n; 1025eda14cbcSMatt Macy /* 1026eda14cbcSMatt Macy * When doing dry run, data==NULL is used as a 1027eda14cbcSMatt Macy * sentinel value by 1028eda14cbcSMatt Macy * dmu_dump_write()->dump_record(). 1029eda14cbcSMatt Macy */ 1030eda14cbcSMatt Macy if (data != NULL) 1031eda14cbcSMatt Macy data += n; 1032eda14cbcSMatt Macy srdp->datablksz -= n; 1033eda14cbcSMatt Macy } 1034eda14cbcSMatt Macy } else { 1035eda14cbcSMatt Macy err = dmu_dump_write(dscp, srdp->obj_type, 1036eda14cbcSMatt Macy range->object, offset, 1037*681ce946SMartin Matuska srdp->datablksz, srdp->datasz, bp, 1038*681ce946SMartin Matuska srdp->io_compressed, data); 1039eda14cbcSMatt Macy } 1040eda14cbcSMatt Macy return (err); 1041eda14cbcSMatt Macy } 1042eda14cbcSMatt Macy case HOLE: { 1043eda14cbcSMatt Macy struct srh *srhp = &range->sru.hole; 1044eda14cbcSMatt Macy if (range->object == DMU_META_DNODE_OBJECT) { 1045eda14cbcSMatt Macy uint32_t span = srhp->datablksz >> DNODE_SHIFT; 1046eda14cbcSMatt Macy uint64_t first_obj = range->start_blkid * span; 1047eda14cbcSMatt Macy uint64_t numobj = range->end_blkid * span - first_obj; 1048eda14cbcSMatt Macy return (dump_freeobjects(dscp, first_obj, numobj)); 1049eda14cbcSMatt Macy } 1050eda14cbcSMatt Macy uint64_t offset = 0; 1051eda14cbcSMatt Macy 1052eda14cbcSMatt Macy /* 1053eda14cbcSMatt Macy * If this multiply overflows, we don't need to send this block. 1054eda14cbcSMatt Macy * Even if it has a birth time, it can never not be a hole, so 1055eda14cbcSMatt Macy * we don't need to send records for it. 1056eda14cbcSMatt Macy */ 1057eda14cbcSMatt Macy if (!overflow_multiply(range->start_blkid, srhp->datablksz, 1058eda14cbcSMatt Macy &offset)) { 1059eda14cbcSMatt Macy return (0); 1060eda14cbcSMatt Macy } 1061eda14cbcSMatt Macy uint64_t len = 0; 1062eda14cbcSMatt Macy 1063eda14cbcSMatt Macy if (!overflow_multiply(range->end_blkid, srhp->datablksz, &len)) 1064eda14cbcSMatt Macy len = UINT64_MAX; 1065eda14cbcSMatt Macy len = len - offset; 1066eda14cbcSMatt Macy return (dump_free(dscp, range->object, offset, len)); 1067eda14cbcSMatt Macy } 1068eda14cbcSMatt Macy default: 1069eda14cbcSMatt Macy panic("Invalid range type in do_dump: %d", range->type); 1070eda14cbcSMatt Macy } 1071eda14cbcSMatt Macy return (err); 1072eda14cbcSMatt Macy } 1073eda14cbcSMatt Macy 1074eda14cbcSMatt Macy static struct send_range * 1075eda14cbcSMatt Macy range_alloc(enum type type, uint64_t object, uint64_t start_blkid, 1076eda14cbcSMatt Macy uint64_t end_blkid, boolean_t eos) 1077eda14cbcSMatt Macy { 1078eda14cbcSMatt Macy struct send_range *range = kmem_alloc(sizeof (*range), KM_SLEEP); 1079eda14cbcSMatt Macy range->type = type; 1080eda14cbcSMatt Macy range->object = object; 1081eda14cbcSMatt Macy range->start_blkid = start_blkid; 1082eda14cbcSMatt Macy range->end_blkid = end_blkid; 1083eda14cbcSMatt Macy range->eos_marker = eos; 1084eda14cbcSMatt Macy if (type == DATA) { 1085eda14cbcSMatt Macy range->sru.data.abd = NULL; 1086eda14cbcSMatt Macy range->sru.data.abuf = NULL; 1087eda14cbcSMatt Macy mutex_init(&range->sru.data.lock, NULL, MUTEX_DEFAULT, NULL); 1088eda14cbcSMatt Macy cv_init(&range->sru.data.cv, NULL, CV_DEFAULT, NULL); 1089eda14cbcSMatt Macy range->sru.data.io_outstanding = 0; 1090eda14cbcSMatt Macy range->sru.data.io_err = 0; 1091*681ce946SMartin Matuska range->sru.data.io_compressed = B_FALSE; 1092eda14cbcSMatt Macy } 1093eda14cbcSMatt Macy return (range); 1094eda14cbcSMatt Macy } 1095eda14cbcSMatt Macy 1096eda14cbcSMatt Macy /* 1097eda14cbcSMatt Macy * This is the callback function to traverse_dataset that acts as a worker 1098eda14cbcSMatt Macy * thread for dmu_send_impl. 1099eda14cbcSMatt Macy */ 1100eda14cbcSMatt Macy /*ARGSUSED*/ 1101eda14cbcSMatt Macy static int 1102eda14cbcSMatt Macy send_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp, 1103eda14cbcSMatt Macy const zbookmark_phys_t *zb, const struct dnode_phys *dnp, void *arg) 1104eda14cbcSMatt Macy { 1105eda14cbcSMatt Macy struct send_thread_arg *sta = arg; 1106eda14cbcSMatt Macy struct send_range *record; 1107eda14cbcSMatt Macy 1108eda14cbcSMatt Macy ASSERT(zb->zb_object == DMU_META_DNODE_OBJECT || 1109eda14cbcSMatt Macy zb->zb_object >= sta->resume.zb_object); 1110eda14cbcSMatt Macy 1111eda14cbcSMatt Macy /* 1112eda14cbcSMatt Macy * All bps of an encrypted os should have the encryption bit set. 1113eda14cbcSMatt Macy * If this is not true it indicates tampering and we report an error. 1114eda14cbcSMatt Macy */ 1115eda14cbcSMatt Macy if (sta->os->os_encrypted && 1116eda14cbcSMatt Macy !BP_IS_HOLE(bp) && !BP_USES_CRYPT(bp)) { 1117eda14cbcSMatt Macy spa_log_error(spa, zb); 1118eda14cbcSMatt Macy zfs_panic_recover("unencrypted block in encrypted " 1119eda14cbcSMatt Macy "object set %llu", dmu_objset_id(sta->os)); 1120eda14cbcSMatt Macy return (SET_ERROR(EIO)); 1121eda14cbcSMatt Macy } 1122eda14cbcSMatt Macy 1123eda14cbcSMatt Macy if (sta->cancel) 1124eda14cbcSMatt Macy return (SET_ERROR(EINTR)); 1125eda14cbcSMatt Macy if (zb->zb_object != DMU_META_DNODE_OBJECT && 1126eda14cbcSMatt Macy DMU_OBJECT_IS_SPECIAL(zb->zb_object)) 1127eda14cbcSMatt Macy return (0); 1128eda14cbcSMatt Macy atomic_inc_64(sta->num_blocks_visited); 1129eda14cbcSMatt Macy 1130eda14cbcSMatt Macy if (zb->zb_level == ZB_DNODE_LEVEL) { 1131eda14cbcSMatt Macy if (zb->zb_object == DMU_META_DNODE_OBJECT) 1132eda14cbcSMatt Macy return (0); 1133eda14cbcSMatt Macy record = range_alloc(OBJECT, zb->zb_object, 0, 0, B_FALSE); 1134eda14cbcSMatt Macy record->sru.object.bp = *bp; 1135eda14cbcSMatt Macy size_t size = sizeof (*dnp) * (dnp->dn_extra_slots + 1); 1136eda14cbcSMatt Macy record->sru.object.dnp = kmem_alloc(size, KM_SLEEP); 1137eda14cbcSMatt Macy bcopy(dnp, record->sru.object.dnp, size); 1138eda14cbcSMatt Macy bqueue_enqueue(&sta->q, record, sizeof (*record)); 1139eda14cbcSMatt Macy return (0); 1140eda14cbcSMatt Macy } 1141eda14cbcSMatt Macy if (zb->zb_level == 0 && zb->zb_object == DMU_META_DNODE_OBJECT && 1142eda14cbcSMatt Macy !BP_IS_HOLE(bp)) { 1143eda14cbcSMatt Macy record = range_alloc(OBJECT_RANGE, 0, zb->zb_blkid, 1144eda14cbcSMatt Macy zb->zb_blkid + 1, B_FALSE); 1145eda14cbcSMatt Macy record->sru.object_range.bp = *bp; 1146eda14cbcSMatt Macy bqueue_enqueue(&sta->q, record, sizeof (*record)); 1147eda14cbcSMatt Macy return (0); 1148eda14cbcSMatt Macy } 1149eda14cbcSMatt Macy if (zb->zb_level < 0 || (zb->zb_level > 0 && !BP_IS_HOLE(bp))) 1150eda14cbcSMatt Macy return (0); 1151eda14cbcSMatt Macy if (zb->zb_object == DMU_META_DNODE_OBJECT && !BP_IS_HOLE(bp)) 1152eda14cbcSMatt Macy return (0); 1153eda14cbcSMatt Macy 1154eda14cbcSMatt Macy uint64_t span = bp_span_in_blocks(dnp->dn_indblkshift, zb->zb_level); 1155eda14cbcSMatt Macy uint64_t start; 1156eda14cbcSMatt Macy 1157eda14cbcSMatt Macy /* 1158eda14cbcSMatt Macy * If this multiply overflows, we don't need to send this block. 1159eda14cbcSMatt Macy * Even if it has a birth time, it can never not be a hole, so 1160eda14cbcSMatt Macy * we don't need to send records for it. 1161eda14cbcSMatt Macy */ 1162eda14cbcSMatt Macy if (!overflow_multiply(span, zb->zb_blkid, &start) || (!(zb->zb_blkid == 1163eda14cbcSMatt Macy DMU_SPILL_BLKID || DMU_OT_IS_METADATA(dnp->dn_type)) && 1164eda14cbcSMatt Macy span * zb->zb_blkid > dnp->dn_maxblkid)) { 1165eda14cbcSMatt Macy ASSERT(BP_IS_HOLE(bp)); 1166eda14cbcSMatt Macy return (0); 1167eda14cbcSMatt Macy } 1168eda14cbcSMatt Macy 1169eda14cbcSMatt Macy if (zb->zb_blkid == DMU_SPILL_BLKID) 1170eda14cbcSMatt Macy ASSERT3U(BP_GET_TYPE(bp), ==, DMU_OT_SA); 1171eda14cbcSMatt Macy 1172eda14cbcSMatt Macy enum type record_type = DATA; 1173eda14cbcSMatt Macy if (BP_IS_HOLE(bp)) 1174eda14cbcSMatt Macy record_type = HOLE; 1175eda14cbcSMatt Macy else if (BP_IS_REDACTED(bp)) 1176eda14cbcSMatt Macy record_type = REDACT; 1177eda14cbcSMatt Macy else 1178eda14cbcSMatt Macy record_type = DATA; 1179eda14cbcSMatt Macy 1180eda14cbcSMatt Macy record = range_alloc(record_type, zb->zb_object, start, 1181eda14cbcSMatt Macy (start + span < start ? 0 : start + span), B_FALSE); 1182eda14cbcSMatt Macy 1183eda14cbcSMatt Macy uint64_t datablksz = (zb->zb_blkid == DMU_SPILL_BLKID ? 1184eda14cbcSMatt Macy BP_GET_LSIZE(bp) : dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT); 1185eda14cbcSMatt Macy 1186eda14cbcSMatt Macy if (BP_IS_HOLE(bp)) { 1187eda14cbcSMatt Macy record->sru.hole.datablksz = datablksz; 1188eda14cbcSMatt Macy } else if (BP_IS_REDACTED(bp)) { 1189eda14cbcSMatt Macy record->sru.redact.datablksz = datablksz; 1190eda14cbcSMatt Macy } else { 1191eda14cbcSMatt Macy record->sru.data.datablksz = datablksz; 1192eda14cbcSMatt Macy record->sru.data.obj_type = dnp->dn_type; 1193eda14cbcSMatt Macy record->sru.data.bp = *bp; 1194eda14cbcSMatt Macy } 1195eda14cbcSMatt Macy 1196eda14cbcSMatt Macy bqueue_enqueue(&sta->q, record, sizeof (*record)); 1197eda14cbcSMatt Macy return (0); 1198eda14cbcSMatt Macy } 1199eda14cbcSMatt Macy 1200eda14cbcSMatt Macy struct redact_list_cb_arg { 1201eda14cbcSMatt Macy uint64_t *num_blocks_visited; 1202eda14cbcSMatt Macy bqueue_t *q; 1203eda14cbcSMatt Macy boolean_t *cancel; 1204eda14cbcSMatt Macy boolean_t mark_redact; 1205eda14cbcSMatt Macy }; 1206eda14cbcSMatt Macy 1207eda14cbcSMatt Macy static int 1208eda14cbcSMatt Macy redact_list_cb(redact_block_phys_t *rb, void *arg) 1209eda14cbcSMatt Macy { 1210eda14cbcSMatt Macy struct redact_list_cb_arg *rlcap = arg; 1211eda14cbcSMatt Macy 1212eda14cbcSMatt Macy atomic_inc_64(rlcap->num_blocks_visited); 1213eda14cbcSMatt Macy if (*rlcap->cancel) 1214eda14cbcSMatt Macy return (-1); 1215eda14cbcSMatt Macy 1216eda14cbcSMatt Macy struct send_range *data = range_alloc(REDACT, rb->rbp_object, 1217eda14cbcSMatt Macy rb->rbp_blkid, rb->rbp_blkid + redact_block_get_count(rb), B_FALSE); 1218eda14cbcSMatt Macy ASSERT3U(data->end_blkid, >, rb->rbp_blkid); 1219eda14cbcSMatt Macy if (rlcap->mark_redact) { 1220eda14cbcSMatt Macy data->type = REDACT; 1221eda14cbcSMatt Macy data->sru.redact.datablksz = redact_block_get_size(rb); 1222eda14cbcSMatt Macy } else { 1223eda14cbcSMatt Macy data->type = PREVIOUSLY_REDACTED; 1224eda14cbcSMatt Macy } 1225eda14cbcSMatt Macy bqueue_enqueue(rlcap->q, data, sizeof (*data)); 1226eda14cbcSMatt Macy 1227eda14cbcSMatt Macy return (0); 1228eda14cbcSMatt Macy } 1229eda14cbcSMatt Macy 1230eda14cbcSMatt Macy /* 1231eda14cbcSMatt Macy * This function kicks off the traverse_dataset. It also handles setting the 1232eda14cbcSMatt Macy * error code of the thread in case something goes wrong, and pushes the End of 1233eda14cbcSMatt Macy * Stream record when the traverse_dataset call has finished. 1234eda14cbcSMatt Macy */ 1235eda14cbcSMatt Macy static void 1236eda14cbcSMatt Macy send_traverse_thread(void *arg) 1237eda14cbcSMatt Macy { 1238eda14cbcSMatt Macy struct send_thread_arg *st_arg = arg; 1239eda14cbcSMatt Macy int err = 0; 1240eda14cbcSMatt Macy struct send_range *data; 1241eda14cbcSMatt Macy fstrans_cookie_t cookie = spl_fstrans_mark(); 1242eda14cbcSMatt Macy 1243eda14cbcSMatt Macy err = traverse_dataset_resume(st_arg->os->os_dsl_dataset, 1244eda14cbcSMatt Macy st_arg->fromtxg, &st_arg->resume, 1245eda14cbcSMatt Macy st_arg->flags, send_cb, st_arg); 1246eda14cbcSMatt Macy 1247eda14cbcSMatt Macy if (err != EINTR) 1248eda14cbcSMatt Macy st_arg->error_code = err; 1249eda14cbcSMatt Macy data = range_alloc(DATA, 0, 0, 0, B_TRUE); 1250eda14cbcSMatt Macy bqueue_enqueue_flush(&st_arg->q, data, sizeof (*data)); 1251eda14cbcSMatt Macy spl_fstrans_unmark(cookie); 1252eda14cbcSMatt Macy thread_exit(); 1253eda14cbcSMatt Macy } 1254eda14cbcSMatt Macy 1255eda14cbcSMatt Macy /* 1256eda14cbcSMatt Macy * Utility function that causes End of Stream records to compare after of all 1257eda14cbcSMatt Macy * others, so that other threads' comparison logic can stay simple. 1258eda14cbcSMatt Macy */ 1259eda14cbcSMatt Macy static int __attribute__((unused)) 1260eda14cbcSMatt Macy send_range_after(const struct send_range *from, const struct send_range *to) 1261eda14cbcSMatt Macy { 1262eda14cbcSMatt Macy if (from->eos_marker == B_TRUE) 1263eda14cbcSMatt Macy return (1); 1264eda14cbcSMatt Macy if (to->eos_marker == B_TRUE) 1265eda14cbcSMatt Macy return (-1); 1266eda14cbcSMatt Macy 1267eda14cbcSMatt Macy uint64_t from_obj = from->object; 1268eda14cbcSMatt Macy uint64_t from_end_obj = from->object + 1; 1269eda14cbcSMatt Macy uint64_t to_obj = to->object; 1270eda14cbcSMatt Macy uint64_t to_end_obj = to->object + 1; 1271eda14cbcSMatt Macy if (from_obj == 0) { 1272eda14cbcSMatt Macy ASSERT(from->type == HOLE || from->type == OBJECT_RANGE); 1273eda14cbcSMatt Macy from_obj = from->start_blkid << DNODES_PER_BLOCK_SHIFT; 1274eda14cbcSMatt Macy from_end_obj = from->end_blkid << DNODES_PER_BLOCK_SHIFT; 1275eda14cbcSMatt Macy } 1276eda14cbcSMatt Macy if (to_obj == 0) { 1277eda14cbcSMatt Macy ASSERT(to->type == HOLE || to->type == OBJECT_RANGE); 1278eda14cbcSMatt Macy to_obj = to->start_blkid << DNODES_PER_BLOCK_SHIFT; 1279eda14cbcSMatt Macy to_end_obj = to->end_blkid << DNODES_PER_BLOCK_SHIFT; 1280eda14cbcSMatt Macy } 1281eda14cbcSMatt Macy 1282eda14cbcSMatt Macy if (from_end_obj <= to_obj) 1283eda14cbcSMatt Macy return (-1); 1284eda14cbcSMatt Macy if (from_obj >= to_end_obj) 1285eda14cbcSMatt Macy return (1); 1286eda14cbcSMatt Macy int64_t cmp = TREE_CMP(to->type == OBJECT_RANGE, from->type == 1287eda14cbcSMatt Macy OBJECT_RANGE); 1288eda14cbcSMatt Macy if (unlikely(cmp)) 1289eda14cbcSMatt Macy return (cmp); 1290eda14cbcSMatt Macy cmp = TREE_CMP(to->type == OBJECT, from->type == OBJECT); 1291eda14cbcSMatt Macy if (unlikely(cmp)) 1292eda14cbcSMatt Macy return (cmp); 1293eda14cbcSMatt Macy if (from->end_blkid <= to->start_blkid) 1294eda14cbcSMatt Macy return (-1); 1295eda14cbcSMatt Macy if (from->start_blkid >= to->end_blkid) 1296eda14cbcSMatt Macy return (1); 1297eda14cbcSMatt Macy return (0); 1298eda14cbcSMatt Macy } 1299eda14cbcSMatt Macy 1300eda14cbcSMatt Macy /* 1301eda14cbcSMatt Macy * Pop the new data off the queue, check that the records we receive are in 1302eda14cbcSMatt Macy * the right order, but do not free the old data. This is used so that the 1303eda14cbcSMatt Macy * records can be sent on to the main thread without copying the data. 1304eda14cbcSMatt Macy */ 1305eda14cbcSMatt Macy static struct send_range * 1306eda14cbcSMatt Macy get_next_range_nofree(bqueue_t *bq, struct send_range *prev) 1307eda14cbcSMatt Macy { 1308eda14cbcSMatt Macy struct send_range *next = bqueue_dequeue(bq); 1309eda14cbcSMatt Macy ASSERT3S(send_range_after(prev, next), ==, -1); 1310eda14cbcSMatt Macy return (next); 1311eda14cbcSMatt Macy } 1312eda14cbcSMatt Macy 1313eda14cbcSMatt Macy /* 1314eda14cbcSMatt Macy * Pop the new data off the queue, check that the records we receive are in 1315eda14cbcSMatt Macy * the right order, and free the old data. 1316eda14cbcSMatt Macy */ 1317eda14cbcSMatt Macy static struct send_range * 1318eda14cbcSMatt Macy get_next_range(bqueue_t *bq, struct send_range *prev) 1319eda14cbcSMatt Macy { 1320eda14cbcSMatt Macy struct send_range *next = get_next_range_nofree(bq, prev); 1321eda14cbcSMatt Macy range_free(prev); 1322eda14cbcSMatt Macy return (next); 1323eda14cbcSMatt Macy } 1324eda14cbcSMatt Macy 1325eda14cbcSMatt Macy static void 1326eda14cbcSMatt Macy redact_list_thread(void *arg) 1327eda14cbcSMatt Macy { 1328eda14cbcSMatt Macy struct redact_list_thread_arg *rlt_arg = arg; 1329eda14cbcSMatt Macy struct send_range *record; 1330eda14cbcSMatt Macy fstrans_cookie_t cookie = spl_fstrans_mark(); 1331eda14cbcSMatt Macy if (rlt_arg->rl != NULL) { 1332eda14cbcSMatt Macy struct redact_list_cb_arg rlcba = {0}; 1333eda14cbcSMatt Macy rlcba.cancel = &rlt_arg->cancel; 1334eda14cbcSMatt Macy rlcba.q = &rlt_arg->q; 1335eda14cbcSMatt Macy rlcba.num_blocks_visited = rlt_arg->num_blocks_visited; 1336eda14cbcSMatt Macy rlcba.mark_redact = rlt_arg->mark_redact; 1337eda14cbcSMatt Macy int err = dsl_redaction_list_traverse(rlt_arg->rl, 1338eda14cbcSMatt Macy &rlt_arg->resume, redact_list_cb, &rlcba); 1339eda14cbcSMatt Macy if (err != EINTR) 1340eda14cbcSMatt Macy rlt_arg->error_code = err; 1341eda14cbcSMatt Macy } 1342eda14cbcSMatt Macy record = range_alloc(DATA, 0, 0, 0, B_TRUE); 1343eda14cbcSMatt Macy bqueue_enqueue_flush(&rlt_arg->q, record, sizeof (*record)); 1344eda14cbcSMatt Macy spl_fstrans_unmark(cookie); 1345eda14cbcSMatt Macy 1346eda14cbcSMatt Macy thread_exit(); 1347eda14cbcSMatt Macy } 1348eda14cbcSMatt Macy 1349eda14cbcSMatt Macy /* 1350eda14cbcSMatt Macy * Compare the start point of the two provided ranges. End of stream ranges 1351eda14cbcSMatt Macy * compare last, objects compare before any data or hole inside that object and 1352eda14cbcSMatt Macy * multi-object holes that start at the same object. 1353eda14cbcSMatt Macy */ 1354eda14cbcSMatt Macy static int 1355eda14cbcSMatt Macy send_range_start_compare(struct send_range *r1, struct send_range *r2) 1356eda14cbcSMatt Macy { 1357eda14cbcSMatt Macy uint64_t r1_objequiv = r1->object; 1358eda14cbcSMatt Macy uint64_t r1_l0equiv = r1->start_blkid; 1359eda14cbcSMatt Macy uint64_t r2_objequiv = r2->object; 1360eda14cbcSMatt Macy uint64_t r2_l0equiv = r2->start_blkid; 1361eda14cbcSMatt Macy int64_t cmp = TREE_CMP(r1->eos_marker, r2->eos_marker); 1362eda14cbcSMatt Macy if (unlikely(cmp)) 1363eda14cbcSMatt Macy return (cmp); 1364eda14cbcSMatt Macy if (r1->object == 0) { 1365eda14cbcSMatt Macy r1_objequiv = r1->start_blkid * DNODES_PER_BLOCK; 1366eda14cbcSMatt Macy r1_l0equiv = 0; 1367eda14cbcSMatt Macy } 1368eda14cbcSMatt Macy if (r2->object == 0) { 1369eda14cbcSMatt Macy r2_objequiv = r2->start_blkid * DNODES_PER_BLOCK; 1370eda14cbcSMatt Macy r2_l0equiv = 0; 1371eda14cbcSMatt Macy } 1372eda14cbcSMatt Macy 1373eda14cbcSMatt Macy cmp = TREE_CMP(r1_objequiv, r2_objequiv); 1374eda14cbcSMatt Macy if (likely(cmp)) 1375eda14cbcSMatt Macy return (cmp); 1376eda14cbcSMatt Macy cmp = TREE_CMP(r2->type == OBJECT_RANGE, r1->type == OBJECT_RANGE); 1377eda14cbcSMatt Macy if (unlikely(cmp)) 1378eda14cbcSMatt Macy return (cmp); 1379eda14cbcSMatt Macy cmp = TREE_CMP(r2->type == OBJECT, r1->type == OBJECT); 1380eda14cbcSMatt Macy if (unlikely(cmp)) 1381eda14cbcSMatt Macy return (cmp); 1382eda14cbcSMatt Macy 1383eda14cbcSMatt Macy return (TREE_CMP(r1_l0equiv, r2_l0equiv)); 1384eda14cbcSMatt Macy } 1385eda14cbcSMatt Macy 1386eda14cbcSMatt Macy enum q_idx { 1387eda14cbcSMatt Macy REDACT_IDX = 0, 1388eda14cbcSMatt Macy TO_IDX, 1389eda14cbcSMatt Macy FROM_IDX, 1390eda14cbcSMatt Macy NUM_THREADS 1391eda14cbcSMatt Macy }; 1392eda14cbcSMatt Macy 1393eda14cbcSMatt Macy /* 1394eda14cbcSMatt Macy * This function returns the next range the send_merge_thread should operate on. 1395eda14cbcSMatt Macy * The inputs are two arrays; the first one stores the range at the front of the 1396eda14cbcSMatt Macy * queues stored in the second one. The ranges are sorted in descending 1397eda14cbcSMatt Macy * priority order; the metadata from earlier ranges overrules metadata from 1398eda14cbcSMatt Macy * later ranges. out_mask is used to return which threads the ranges came from; 1399eda14cbcSMatt Macy * bit i is set if ranges[i] started at the same place as the returned range. 1400eda14cbcSMatt Macy * 1401eda14cbcSMatt Macy * This code is not hardcoded to compare a specific number of threads; it could 1402eda14cbcSMatt Macy * be used with any number, just by changing the q_idx enum. 1403eda14cbcSMatt Macy * 1404eda14cbcSMatt Macy * The "next range" is the one with the earliest start; if two starts are equal, 1405eda14cbcSMatt Macy * the highest-priority range is the next to operate on. If a higher-priority 1406eda14cbcSMatt Macy * range starts in the middle of the first range, then the first range will be 1407eda14cbcSMatt Macy * truncated to end where the higher-priority range starts, and we will operate 1408eda14cbcSMatt Macy * on that one next time. In this way, we make sure that each block covered by 1409eda14cbcSMatt Macy * some range gets covered by a returned range, and each block covered is 1410eda14cbcSMatt Macy * returned using the metadata of the highest-priority range it appears in. 1411eda14cbcSMatt Macy * 1412eda14cbcSMatt Macy * For example, if the three ranges at the front of the queues were [2,4), 1413eda14cbcSMatt Macy * [3,5), and [1,3), then the ranges returned would be [1,2) with the metadata 1414eda14cbcSMatt Macy * from the third range, [2,4) with the metadata from the first range, and then 1415eda14cbcSMatt Macy * [4,5) with the metadata from the second. 1416eda14cbcSMatt Macy */ 1417eda14cbcSMatt Macy static struct send_range * 1418eda14cbcSMatt Macy find_next_range(struct send_range **ranges, bqueue_t **qs, uint64_t *out_mask) 1419eda14cbcSMatt Macy { 1420eda14cbcSMatt Macy int idx = 0; // index of the range with the earliest start 1421eda14cbcSMatt Macy int i; 1422eda14cbcSMatt Macy uint64_t bmask = 0; 1423eda14cbcSMatt Macy for (i = 1; i < NUM_THREADS; i++) { 1424eda14cbcSMatt Macy if (send_range_start_compare(ranges[i], ranges[idx]) < 0) 1425eda14cbcSMatt Macy idx = i; 1426eda14cbcSMatt Macy } 1427eda14cbcSMatt Macy if (ranges[idx]->eos_marker) { 1428eda14cbcSMatt Macy struct send_range *ret = range_alloc(DATA, 0, 0, 0, B_TRUE); 1429eda14cbcSMatt Macy *out_mask = 0; 1430eda14cbcSMatt Macy return (ret); 1431eda14cbcSMatt Macy } 1432eda14cbcSMatt Macy /* 1433eda14cbcSMatt Macy * Find all the ranges that start at that same point. 1434eda14cbcSMatt Macy */ 1435eda14cbcSMatt Macy for (i = 0; i < NUM_THREADS; i++) { 1436eda14cbcSMatt Macy if (send_range_start_compare(ranges[i], ranges[idx]) == 0) 1437eda14cbcSMatt Macy bmask |= 1 << i; 1438eda14cbcSMatt Macy } 1439eda14cbcSMatt Macy *out_mask = bmask; 1440eda14cbcSMatt Macy /* 1441eda14cbcSMatt Macy * OBJECT_RANGE records only come from the TO thread, and should always 1442eda14cbcSMatt Macy * be treated as overlapping with nothing and sent on immediately. They 1443eda14cbcSMatt Macy * are only used in raw sends, and are never redacted. 1444eda14cbcSMatt Macy */ 1445eda14cbcSMatt Macy if (ranges[idx]->type == OBJECT_RANGE) { 1446eda14cbcSMatt Macy ASSERT3U(idx, ==, TO_IDX); 1447eda14cbcSMatt Macy ASSERT3U(*out_mask, ==, 1 << TO_IDX); 1448eda14cbcSMatt Macy struct send_range *ret = ranges[idx]; 1449eda14cbcSMatt Macy ranges[idx] = get_next_range_nofree(qs[idx], ranges[idx]); 1450eda14cbcSMatt Macy return (ret); 1451eda14cbcSMatt Macy } 1452eda14cbcSMatt Macy /* 1453eda14cbcSMatt Macy * Find the first start or end point after the start of the first range. 1454eda14cbcSMatt Macy */ 1455eda14cbcSMatt Macy uint64_t first_change = ranges[idx]->end_blkid; 1456eda14cbcSMatt Macy for (i = 0; i < NUM_THREADS; i++) { 1457eda14cbcSMatt Macy if (i == idx || ranges[i]->eos_marker || 1458eda14cbcSMatt Macy ranges[i]->object > ranges[idx]->object || 1459eda14cbcSMatt Macy ranges[i]->object == DMU_META_DNODE_OBJECT) 1460eda14cbcSMatt Macy continue; 1461eda14cbcSMatt Macy ASSERT3U(ranges[i]->object, ==, ranges[idx]->object); 1462eda14cbcSMatt Macy if (first_change > ranges[i]->start_blkid && 1463eda14cbcSMatt Macy (bmask & (1 << i)) == 0) 1464eda14cbcSMatt Macy first_change = ranges[i]->start_blkid; 1465eda14cbcSMatt Macy else if (first_change > ranges[i]->end_blkid) 1466eda14cbcSMatt Macy first_change = ranges[i]->end_blkid; 1467eda14cbcSMatt Macy } 1468eda14cbcSMatt Macy /* 1469eda14cbcSMatt Macy * Update all ranges to no longer overlap with the range we're 1470eda14cbcSMatt Macy * returning. All such ranges must start at the same place as the range 1471eda14cbcSMatt Macy * being returned, and end at or after first_change. Thus we update 1472eda14cbcSMatt Macy * their start to first_change. If that makes them size 0, then free 1473eda14cbcSMatt Macy * them and pull a new range from that thread. 1474eda14cbcSMatt Macy */ 1475eda14cbcSMatt Macy for (i = 0; i < NUM_THREADS; i++) { 1476eda14cbcSMatt Macy if (i == idx || (bmask & (1 << i)) == 0) 1477eda14cbcSMatt Macy continue; 1478eda14cbcSMatt Macy ASSERT3U(first_change, >, ranges[i]->start_blkid); 1479eda14cbcSMatt Macy ranges[i]->start_blkid = first_change; 1480eda14cbcSMatt Macy ASSERT3U(ranges[i]->start_blkid, <=, ranges[i]->end_blkid); 1481eda14cbcSMatt Macy if (ranges[i]->start_blkid == ranges[i]->end_blkid) 1482eda14cbcSMatt Macy ranges[i] = get_next_range(qs[i], ranges[i]); 1483eda14cbcSMatt Macy } 1484eda14cbcSMatt Macy /* 1485eda14cbcSMatt Macy * Short-circuit the simple case; if the range doesn't overlap with 1486eda14cbcSMatt Macy * anything else, or it only overlaps with things that start at the same 1487eda14cbcSMatt Macy * place and are longer, send it on. 1488eda14cbcSMatt Macy */ 1489eda14cbcSMatt Macy if (first_change == ranges[idx]->end_blkid) { 1490eda14cbcSMatt Macy struct send_range *ret = ranges[idx]; 1491eda14cbcSMatt Macy ranges[idx] = get_next_range_nofree(qs[idx], ranges[idx]); 1492eda14cbcSMatt Macy return (ret); 1493eda14cbcSMatt Macy } 1494eda14cbcSMatt Macy 1495eda14cbcSMatt Macy /* 1496eda14cbcSMatt Macy * Otherwise, return a truncated copy of ranges[idx] and move the start 1497eda14cbcSMatt Macy * of ranges[idx] back to first_change. 1498eda14cbcSMatt Macy */ 1499eda14cbcSMatt Macy struct send_range *ret = kmem_alloc(sizeof (*ret), KM_SLEEP); 1500eda14cbcSMatt Macy *ret = *ranges[idx]; 1501eda14cbcSMatt Macy ret->end_blkid = first_change; 1502eda14cbcSMatt Macy ranges[idx]->start_blkid = first_change; 1503eda14cbcSMatt Macy return (ret); 1504eda14cbcSMatt Macy } 1505eda14cbcSMatt Macy 1506eda14cbcSMatt Macy #define FROM_AND_REDACT_BITS ((1 << REDACT_IDX) | (1 << FROM_IDX)) 1507eda14cbcSMatt Macy 1508eda14cbcSMatt Macy /* 1509eda14cbcSMatt Macy * Merge the results from the from thread and the to thread, and then hand the 1510eda14cbcSMatt Macy * records off to send_prefetch_thread to prefetch them. If this is not a 1511eda14cbcSMatt Macy * send from a redaction bookmark, the from thread will push an end of stream 1512eda14cbcSMatt Macy * record and stop, and we'll just send everything that was changed in the 1513eda14cbcSMatt Macy * to_ds since the ancestor's creation txg. If it is, then since 1514eda14cbcSMatt Macy * traverse_dataset has a canonical order, we can compare each change as 1515eda14cbcSMatt Macy * they're pulled off the queues. That will give us a stream that is 1516eda14cbcSMatt Macy * appropriately sorted, and covers all records. In addition, we pull the 1517eda14cbcSMatt Macy * data from the redact_list_thread and use that to determine which blocks 1518eda14cbcSMatt Macy * should be redacted. 1519eda14cbcSMatt Macy */ 1520eda14cbcSMatt Macy static void 1521eda14cbcSMatt Macy send_merge_thread(void *arg) 1522eda14cbcSMatt Macy { 1523eda14cbcSMatt Macy struct send_merge_thread_arg *smt_arg = arg; 1524eda14cbcSMatt Macy struct send_range *front_ranges[NUM_THREADS]; 1525eda14cbcSMatt Macy bqueue_t *queues[NUM_THREADS]; 1526eda14cbcSMatt Macy int err = 0; 1527eda14cbcSMatt Macy fstrans_cookie_t cookie = spl_fstrans_mark(); 1528eda14cbcSMatt Macy 1529eda14cbcSMatt Macy if (smt_arg->redact_arg == NULL) { 1530eda14cbcSMatt Macy front_ranges[REDACT_IDX] = 1531eda14cbcSMatt Macy kmem_zalloc(sizeof (struct send_range), KM_SLEEP); 1532eda14cbcSMatt Macy front_ranges[REDACT_IDX]->eos_marker = B_TRUE; 1533eda14cbcSMatt Macy front_ranges[REDACT_IDX]->type = REDACT; 1534eda14cbcSMatt Macy queues[REDACT_IDX] = NULL; 1535eda14cbcSMatt Macy } else { 1536eda14cbcSMatt Macy front_ranges[REDACT_IDX] = 1537eda14cbcSMatt Macy bqueue_dequeue(&smt_arg->redact_arg->q); 1538eda14cbcSMatt Macy queues[REDACT_IDX] = &smt_arg->redact_arg->q; 1539eda14cbcSMatt Macy } 1540eda14cbcSMatt Macy front_ranges[TO_IDX] = bqueue_dequeue(&smt_arg->to_arg->q); 1541eda14cbcSMatt Macy queues[TO_IDX] = &smt_arg->to_arg->q; 1542eda14cbcSMatt Macy front_ranges[FROM_IDX] = bqueue_dequeue(&smt_arg->from_arg->q); 1543eda14cbcSMatt Macy queues[FROM_IDX] = &smt_arg->from_arg->q; 1544eda14cbcSMatt Macy uint64_t mask = 0; 1545eda14cbcSMatt Macy struct send_range *range; 1546eda14cbcSMatt Macy for (range = find_next_range(front_ranges, queues, &mask); 1547eda14cbcSMatt Macy !range->eos_marker && err == 0 && !smt_arg->cancel; 1548eda14cbcSMatt Macy range = find_next_range(front_ranges, queues, &mask)) { 1549eda14cbcSMatt Macy /* 1550eda14cbcSMatt Macy * If the range in question was in both the from redact bookmark 1551eda14cbcSMatt Macy * and the bookmark we're using to redact, then don't send it. 1552eda14cbcSMatt Macy * It's already redacted on the receiving system, so a redaction 1553eda14cbcSMatt Macy * record would be redundant. 1554eda14cbcSMatt Macy */ 1555eda14cbcSMatt Macy if ((mask & FROM_AND_REDACT_BITS) == FROM_AND_REDACT_BITS) { 1556eda14cbcSMatt Macy ASSERT3U(range->type, ==, REDACT); 1557eda14cbcSMatt Macy range_free(range); 1558eda14cbcSMatt Macy continue; 1559eda14cbcSMatt Macy } 1560eda14cbcSMatt Macy bqueue_enqueue(&smt_arg->q, range, sizeof (*range)); 1561eda14cbcSMatt Macy 1562eda14cbcSMatt Macy if (smt_arg->to_arg->error_code != 0) { 1563eda14cbcSMatt Macy err = smt_arg->to_arg->error_code; 1564eda14cbcSMatt Macy } else if (smt_arg->from_arg->error_code != 0) { 1565eda14cbcSMatt Macy err = smt_arg->from_arg->error_code; 1566eda14cbcSMatt Macy } else if (smt_arg->redact_arg != NULL && 1567eda14cbcSMatt Macy smt_arg->redact_arg->error_code != 0) { 1568eda14cbcSMatt Macy err = smt_arg->redact_arg->error_code; 1569eda14cbcSMatt Macy } 1570eda14cbcSMatt Macy } 1571eda14cbcSMatt Macy if (smt_arg->cancel && err == 0) 1572eda14cbcSMatt Macy err = SET_ERROR(EINTR); 1573eda14cbcSMatt Macy smt_arg->error = err; 1574eda14cbcSMatt Macy if (smt_arg->error != 0) { 1575eda14cbcSMatt Macy smt_arg->to_arg->cancel = B_TRUE; 1576eda14cbcSMatt Macy smt_arg->from_arg->cancel = B_TRUE; 1577eda14cbcSMatt Macy if (smt_arg->redact_arg != NULL) 1578eda14cbcSMatt Macy smt_arg->redact_arg->cancel = B_TRUE; 1579eda14cbcSMatt Macy } 1580eda14cbcSMatt Macy for (int i = 0; i < NUM_THREADS; i++) { 1581eda14cbcSMatt Macy while (!front_ranges[i]->eos_marker) { 1582eda14cbcSMatt Macy front_ranges[i] = get_next_range(queues[i], 1583eda14cbcSMatt Macy front_ranges[i]); 1584eda14cbcSMatt Macy } 1585eda14cbcSMatt Macy range_free(front_ranges[i]); 1586eda14cbcSMatt Macy } 1587eda14cbcSMatt Macy if (range == NULL) 1588eda14cbcSMatt Macy range = kmem_zalloc(sizeof (*range), KM_SLEEP); 1589eda14cbcSMatt Macy range->eos_marker = B_TRUE; 1590eda14cbcSMatt Macy bqueue_enqueue_flush(&smt_arg->q, range, 1); 1591eda14cbcSMatt Macy spl_fstrans_unmark(cookie); 1592eda14cbcSMatt Macy thread_exit(); 1593eda14cbcSMatt Macy } 1594eda14cbcSMatt Macy 1595eda14cbcSMatt Macy struct send_reader_thread_arg { 1596eda14cbcSMatt Macy struct send_merge_thread_arg *smta; 1597eda14cbcSMatt Macy bqueue_t q; 1598eda14cbcSMatt Macy boolean_t cancel; 1599eda14cbcSMatt Macy boolean_t issue_reads; 1600eda14cbcSMatt Macy uint64_t featureflags; 1601eda14cbcSMatt Macy int error; 1602eda14cbcSMatt Macy }; 1603eda14cbcSMatt Macy 1604eda14cbcSMatt Macy static void 1605eda14cbcSMatt Macy dmu_send_read_done(zio_t *zio) 1606eda14cbcSMatt Macy { 1607eda14cbcSMatt Macy struct send_range *range = zio->io_private; 1608eda14cbcSMatt Macy 1609eda14cbcSMatt Macy mutex_enter(&range->sru.data.lock); 1610eda14cbcSMatt Macy if (zio->io_error != 0) { 1611eda14cbcSMatt Macy abd_free(range->sru.data.abd); 1612eda14cbcSMatt Macy range->sru.data.abd = NULL; 1613eda14cbcSMatt Macy range->sru.data.io_err = zio->io_error; 1614eda14cbcSMatt Macy } 1615eda14cbcSMatt Macy 1616eda14cbcSMatt Macy ASSERT(range->sru.data.io_outstanding); 1617eda14cbcSMatt Macy range->sru.data.io_outstanding = B_FALSE; 1618eda14cbcSMatt Macy cv_broadcast(&range->sru.data.cv); 1619eda14cbcSMatt Macy mutex_exit(&range->sru.data.lock); 1620eda14cbcSMatt Macy } 1621eda14cbcSMatt Macy 1622eda14cbcSMatt Macy static void 1623eda14cbcSMatt Macy issue_data_read(struct send_reader_thread_arg *srta, struct send_range *range) 1624eda14cbcSMatt Macy { 1625eda14cbcSMatt Macy struct srd *srdp = &range->sru.data; 1626eda14cbcSMatt Macy blkptr_t *bp = &srdp->bp; 1627eda14cbcSMatt Macy objset_t *os = srta->smta->os; 1628eda14cbcSMatt Macy 1629eda14cbcSMatt Macy ASSERT3U(range->type, ==, DATA); 1630eda14cbcSMatt Macy ASSERT3U(range->start_blkid + 1, ==, range->end_blkid); 1631eda14cbcSMatt Macy /* 1632eda14cbcSMatt Macy * If we have large blocks stored on disk but 1633eda14cbcSMatt Macy * the send flags don't allow us to send large 1634eda14cbcSMatt Macy * blocks, we split the data from the arc buf 1635eda14cbcSMatt Macy * into chunks. 1636eda14cbcSMatt Macy */ 1637eda14cbcSMatt Macy boolean_t split_large_blocks = 1638eda14cbcSMatt Macy srdp->datablksz > SPA_OLD_MAXBLOCKSIZE && 1639eda14cbcSMatt Macy !(srta->featureflags & DMU_BACKUP_FEATURE_LARGE_BLOCKS); 1640eda14cbcSMatt Macy /* 1641eda14cbcSMatt Macy * We should only request compressed data from the ARC if all 1642eda14cbcSMatt Macy * the following are true: 1643eda14cbcSMatt Macy * - stream compression was requested 1644eda14cbcSMatt Macy * - we aren't splitting large blocks into smaller chunks 1645eda14cbcSMatt Macy * - the data won't need to be byteswapped before sending 1646eda14cbcSMatt Macy * - this isn't an embedded block 1647eda14cbcSMatt Macy * - this isn't metadata (if receiving on a different endian 1648eda14cbcSMatt Macy * system it can be byteswapped more easily) 1649eda14cbcSMatt Macy */ 1650eda14cbcSMatt Macy boolean_t request_compressed = 1651eda14cbcSMatt Macy (srta->featureflags & DMU_BACKUP_FEATURE_COMPRESSED) && 1652eda14cbcSMatt Macy !split_large_blocks && !BP_SHOULD_BYTESWAP(bp) && 1653eda14cbcSMatt Macy !BP_IS_EMBEDDED(bp) && !DMU_OT_IS_METADATA(BP_GET_TYPE(bp)); 1654eda14cbcSMatt Macy 1655eda14cbcSMatt Macy enum zio_flag zioflags = ZIO_FLAG_CANFAIL; 1656eda14cbcSMatt Macy 1657*681ce946SMartin Matuska if (srta->featureflags & DMU_BACKUP_FEATURE_RAW) { 1658eda14cbcSMatt Macy zioflags |= ZIO_FLAG_RAW; 1659*681ce946SMartin Matuska srdp->io_compressed = B_TRUE; 1660*681ce946SMartin Matuska } else if (request_compressed) { 1661eda14cbcSMatt Macy zioflags |= ZIO_FLAG_RAW_COMPRESS; 1662*681ce946SMartin Matuska srdp->io_compressed = B_TRUE; 1663*681ce946SMartin Matuska } 1664eda14cbcSMatt Macy 1665eda14cbcSMatt Macy srdp->datasz = (zioflags & ZIO_FLAG_RAW_COMPRESS) ? 1666eda14cbcSMatt Macy BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp); 1667eda14cbcSMatt Macy 1668eda14cbcSMatt Macy if (!srta->issue_reads) 1669eda14cbcSMatt Macy return; 1670eda14cbcSMatt Macy if (BP_IS_REDACTED(bp)) 1671eda14cbcSMatt Macy return; 1672eda14cbcSMatt Macy if (send_do_embed(bp, srta->featureflags)) 1673eda14cbcSMatt Macy return; 1674eda14cbcSMatt Macy 1675eda14cbcSMatt Macy zbookmark_phys_t zb = { 1676eda14cbcSMatt Macy .zb_objset = dmu_objset_id(os), 1677eda14cbcSMatt Macy .zb_object = range->object, 1678eda14cbcSMatt Macy .zb_level = 0, 1679eda14cbcSMatt Macy .zb_blkid = range->start_blkid, 1680eda14cbcSMatt Macy }; 1681eda14cbcSMatt Macy 1682eda14cbcSMatt Macy arc_flags_t aflags = ARC_FLAG_CACHED_ONLY; 1683eda14cbcSMatt Macy 1684eda14cbcSMatt Macy int arc_err = arc_read(NULL, os->os_spa, bp, 1685eda14cbcSMatt Macy arc_getbuf_func, &srdp->abuf, ZIO_PRIORITY_ASYNC_READ, 1686eda14cbcSMatt Macy zioflags, &aflags, &zb); 1687eda14cbcSMatt Macy /* 1688eda14cbcSMatt Macy * If the data is not already cached in the ARC, we read directly 1689eda14cbcSMatt Macy * from zio. This avoids the performance overhead of adding a new 1690eda14cbcSMatt Macy * entry to the ARC, and we also avoid polluting the ARC cache with 1691eda14cbcSMatt Macy * data that is not likely to be used in the future. 1692eda14cbcSMatt Macy */ 1693eda14cbcSMatt Macy if (arc_err != 0) { 1694eda14cbcSMatt Macy srdp->abd = abd_alloc_linear(srdp->datasz, B_FALSE); 1695eda14cbcSMatt Macy srdp->io_outstanding = B_TRUE; 1696eda14cbcSMatt Macy zio_nowait(zio_read(NULL, os->os_spa, bp, srdp->abd, 1697eda14cbcSMatt Macy srdp->datasz, dmu_send_read_done, range, 1698eda14cbcSMatt Macy ZIO_PRIORITY_ASYNC_READ, zioflags, &zb)); 1699eda14cbcSMatt Macy } 1700eda14cbcSMatt Macy } 1701eda14cbcSMatt Macy 1702eda14cbcSMatt Macy /* 1703eda14cbcSMatt Macy * Create a new record with the given values. 1704eda14cbcSMatt Macy */ 1705eda14cbcSMatt Macy static void 1706eda14cbcSMatt Macy enqueue_range(struct send_reader_thread_arg *srta, bqueue_t *q, dnode_t *dn, 1707eda14cbcSMatt Macy uint64_t blkid, uint64_t count, const blkptr_t *bp, uint32_t datablksz) 1708eda14cbcSMatt Macy { 1709eda14cbcSMatt Macy enum type range_type = (bp == NULL || BP_IS_HOLE(bp) ? HOLE : 1710eda14cbcSMatt Macy (BP_IS_REDACTED(bp) ? REDACT : DATA)); 1711eda14cbcSMatt Macy 1712eda14cbcSMatt Macy struct send_range *range = range_alloc(range_type, dn->dn_object, 1713eda14cbcSMatt Macy blkid, blkid + count, B_FALSE); 1714eda14cbcSMatt Macy 1715eda14cbcSMatt Macy if (blkid == DMU_SPILL_BLKID) 1716eda14cbcSMatt Macy ASSERT3U(BP_GET_TYPE(bp), ==, DMU_OT_SA); 1717eda14cbcSMatt Macy 1718eda14cbcSMatt Macy switch (range_type) { 1719eda14cbcSMatt Macy case HOLE: 1720eda14cbcSMatt Macy range->sru.hole.datablksz = datablksz; 1721eda14cbcSMatt Macy break; 1722eda14cbcSMatt Macy case DATA: 1723eda14cbcSMatt Macy ASSERT3U(count, ==, 1); 1724eda14cbcSMatt Macy range->sru.data.datablksz = datablksz; 1725eda14cbcSMatt Macy range->sru.data.obj_type = dn->dn_type; 1726eda14cbcSMatt Macy range->sru.data.bp = *bp; 1727eda14cbcSMatt Macy issue_data_read(srta, range); 1728eda14cbcSMatt Macy break; 1729eda14cbcSMatt Macy case REDACT: 1730eda14cbcSMatt Macy range->sru.redact.datablksz = datablksz; 1731eda14cbcSMatt Macy break; 1732eda14cbcSMatt Macy default: 1733eda14cbcSMatt Macy break; 1734eda14cbcSMatt Macy } 1735eda14cbcSMatt Macy bqueue_enqueue(q, range, datablksz); 1736eda14cbcSMatt Macy } 1737eda14cbcSMatt Macy 1738eda14cbcSMatt Macy /* 1739eda14cbcSMatt Macy * This thread is responsible for two things: First, it retrieves the correct 1740eda14cbcSMatt Macy * blkptr in the to ds if we need to send the data because of something from 1741eda14cbcSMatt Macy * the from thread. As a result of this, we're the first ones to discover that 1742eda14cbcSMatt Macy * some indirect blocks can be discarded because they're not holes. Second, 1743eda14cbcSMatt Macy * it issues prefetches for the data we need to send. 1744eda14cbcSMatt Macy */ 1745eda14cbcSMatt Macy static void 1746eda14cbcSMatt Macy send_reader_thread(void *arg) 1747eda14cbcSMatt Macy { 1748eda14cbcSMatt Macy struct send_reader_thread_arg *srta = arg; 1749eda14cbcSMatt Macy struct send_merge_thread_arg *smta = srta->smta; 1750eda14cbcSMatt Macy bqueue_t *inq = &smta->q; 1751eda14cbcSMatt Macy bqueue_t *outq = &srta->q; 1752eda14cbcSMatt Macy objset_t *os = smta->os; 1753eda14cbcSMatt Macy fstrans_cookie_t cookie = spl_fstrans_mark(); 1754eda14cbcSMatt Macy struct send_range *range = bqueue_dequeue(inq); 1755eda14cbcSMatt Macy int err = 0; 1756eda14cbcSMatt Macy 1757eda14cbcSMatt Macy /* 1758eda14cbcSMatt Macy * If the record we're analyzing is from a redaction bookmark from the 1759eda14cbcSMatt Macy * fromds, then we need to know whether or not it exists in the tods so 1760eda14cbcSMatt Macy * we know whether to create records for it or not. If it does, we need 1761eda14cbcSMatt Macy * the datablksz so we can generate an appropriate record for it. 1762eda14cbcSMatt Macy * Finally, if it isn't redacted, we need the blkptr so that we can send 1763eda14cbcSMatt Macy * a WRITE record containing the actual data. 1764eda14cbcSMatt Macy */ 1765eda14cbcSMatt Macy uint64_t last_obj = UINT64_MAX; 1766eda14cbcSMatt Macy uint64_t last_obj_exists = B_TRUE; 1767eda14cbcSMatt Macy while (!range->eos_marker && !srta->cancel && smta->error == 0 && 1768eda14cbcSMatt Macy err == 0) { 1769eda14cbcSMatt Macy switch (range->type) { 1770eda14cbcSMatt Macy case DATA: 1771eda14cbcSMatt Macy issue_data_read(srta, range); 1772eda14cbcSMatt Macy bqueue_enqueue(outq, range, range->sru.data.datablksz); 1773eda14cbcSMatt Macy range = get_next_range_nofree(inq, range); 1774eda14cbcSMatt Macy break; 1775eda14cbcSMatt Macy case HOLE: 1776eda14cbcSMatt Macy case OBJECT: 1777eda14cbcSMatt Macy case OBJECT_RANGE: 1778eda14cbcSMatt Macy case REDACT: // Redacted blocks must exist 1779eda14cbcSMatt Macy bqueue_enqueue(outq, range, sizeof (*range)); 1780eda14cbcSMatt Macy range = get_next_range_nofree(inq, range); 1781eda14cbcSMatt Macy break; 1782eda14cbcSMatt Macy case PREVIOUSLY_REDACTED: { 1783eda14cbcSMatt Macy /* 1784eda14cbcSMatt Macy * This entry came from the "from bookmark" when 1785eda14cbcSMatt Macy * sending from a bookmark that has a redaction 1786eda14cbcSMatt Macy * list. We need to check if this object/blkid 1787eda14cbcSMatt Macy * exists in the target ("to") dataset, and if 1788eda14cbcSMatt Macy * not then we drop this entry. We also need 1789eda14cbcSMatt Macy * to fill in the block pointer so that we know 1790eda14cbcSMatt Macy * what to prefetch. 1791eda14cbcSMatt Macy * 1792eda14cbcSMatt Macy * To accomplish the above, we first cache whether or 1793eda14cbcSMatt Macy * not the last object we examined exists. If it 1794eda14cbcSMatt Macy * doesn't, we can drop this record. If it does, we hold 1795eda14cbcSMatt Macy * the dnode and use it to call dbuf_dnode_findbp. We do 1796eda14cbcSMatt Macy * this instead of dbuf_bookmark_findbp because we will 1797eda14cbcSMatt Macy * often operate on large ranges, and holding the dnode 1798eda14cbcSMatt Macy * once is more efficient. 1799eda14cbcSMatt Macy */ 1800eda14cbcSMatt Macy boolean_t object_exists = B_TRUE; 1801eda14cbcSMatt Macy /* 1802eda14cbcSMatt Macy * If the data is redacted, we only care if it exists, 1803eda14cbcSMatt Macy * so that we don't send records for objects that have 1804eda14cbcSMatt Macy * been deleted. 1805eda14cbcSMatt Macy */ 1806eda14cbcSMatt Macy dnode_t *dn; 1807eda14cbcSMatt Macy if (range->object == last_obj && !last_obj_exists) { 1808eda14cbcSMatt Macy /* 1809eda14cbcSMatt Macy * If we're still examining the same object as 1810eda14cbcSMatt Macy * previously, and it doesn't exist, we don't 1811eda14cbcSMatt Macy * need to call dbuf_bookmark_findbp. 1812eda14cbcSMatt Macy */ 1813eda14cbcSMatt Macy object_exists = B_FALSE; 1814eda14cbcSMatt Macy } else { 1815eda14cbcSMatt Macy err = dnode_hold(os, range->object, FTAG, &dn); 1816eda14cbcSMatt Macy if (err == ENOENT) { 1817eda14cbcSMatt Macy object_exists = B_FALSE; 1818eda14cbcSMatt Macy err = 0; 1819eda14cbcSMatt Macy } 1820eda14cbcSMatt Macy last_obj = range->object; 1821eda14cbcSMatt Macy last_obj_exists = object_exists; 1822eda14cbcSMatt Macy } 1823eda14cbcSMatt Macy 1824eda14cbcSMatt Macy if (err != 0) { 1825eda14cbcSMatt Macy break; 1826eda14cbcSMatt Macy } else if (!object_exists) { 1827eda14cbcSMatt Macy /* 1828eda14cbcSMatt Macy * The block was modified, but doesn't 1829eda14cbcSMatt Macy * exist in the to dataset; if it was 1830eda14cbcSMatt Macy * deleted in the to dataset, then we'll 1831eda14cbcSMatt Macy * visit the hole bp for it at some point. 1832eda14cbcSMatt Macy */ 1833eda14cbcSMatt Macy range = get_next_range(inq, range); 1834eda14cbcSMatt Macy continue; 1835eda14cbcSMatt Macy } 1836eda14cbcSMatt Macy uint64_t file_max = 1837eda14cbcSMatt Macy (dn->dn_maxblkid < range->end_blkid ? 1838eda14cbcSMatt Macy dn->dn_maxblkid : range->end_blkid); 1839eda14cbcSMatt Macy /* 1840eda14cbcSMatt Macy * The object exists, so we need to try to find the 1841eda14cbcSMatt Macy * blkptr for each block in the range we're processing. 1842eda14cbcSMatt Macy */ 1843eda14cbcSMatt Macy rw_enter(&dn->dn_struct_rwlock, RW_READER); 1844eda14cbcSMatt Macy for (uint64_t blkid = range->start_blkid; 1845eda14cbcSMatt Macy blkid < file_max; blkid++) { 1846eda14cbcSMatt Macy blkptr_t bp; 1847eda14cbcSMatt Macy uint32_t datablksz = 1848eda14cbcSMatt Macy dn->dn_phys->dn_datablkszsec << 1849eda14cbcSMatt Macy SPA_MINBLOCKSHIFT; 1850eda14cbcSMatt Macy uint64_t offset = blkid * datablksz; 1851eda14cbcSMatt Macy /* 1852eda14cbcSMatt Macy * This call finds the next non-hole block in 1853eda14cbcSMatt Macy * the object. This is to prevent a 1854eda14cbcSMatt Macy * performance problem where we're unredacting 1855eda14cbcSMatt Macy * a large hole. Using dnode_next_offset to 1856eda14cbcSMatt Macy * skip over the large hole avoids iterating 1857eda14cbcSMatt Macy * over every block in it. 1858eda14cbcSMatt Macy */ 1859eda14cbcSMatt Macy err = dnode_next_offset(dn, DNODE_FIND_HAVELOCK, 1860eda14cbcSMatt Macy &offset, 1, 1, 0); 1861eda14cbcSMatt Macy if (err == ESRCH) { 1862eda14cbcSMatt Macy offset = UINT64_MAX; 1863eda14cbcSMatt Macy err = 0; 1864eda14cbcSMatt Macy } else if (err != 0) { 1865eda14cbcSMatt Macy break; 1866eda14cbcSMatt Macy } 1867eda14cbcSMatt Macy if (offset != blkid * datablksz) { 1868eda14cbcSMatt Macy /* 1869eda14cbcSMatt Macy * if there is a hole from here 1870eda14cbcSMatt Macy * (blkid) to offset 1871eda14cbcSMatt Macy */ 1872eda14cbcSMatt Macy offset = MIN(offset, file_max * 1873eda14cbcSMatt Macy datablksz); 1874eda14cbcSMatt Macy uint64_t nblks = (offset / datablksz) - 1875eda14cbcSMatt Macy blkid; 1876eda14cbcSMatt Macy enqueue_range(srta, outq, dn, blkid, 1877eda14cbcSMatt Macy nblks, NULL, datablksz); 1878eda14cbcSMatt Macy blkid += nblks; 1879eda14cbcSMatt Macy } 1880eda14cbcSMatt Macy if (blkid >= file_max) 1881eda14cbcSMatt Macy break; 1882eda14cbcSMatt Macy err = dbuf_dnode_findbp(dn, 0, blkid, &bp, 1883eda14cbcSMatt Macy NULL, NULL); 1884eda14cbcSMatt Macy if (err != 0) 1885eda14cbcSMatt Macy break; 1886eda14cbcSMatt Macy ASSERT(!BP_IS_HOLE(&bp)); 1887eda14cbcSMatt Macy enqueue_range(srta, outq, dn, blkid, 1, &bp, 1888eda14cbcSMatt Macy datablksz); 1889eda14cbcSMatt Macy } 1890eda14cbcSMatt Macy rw_exit(&dn->dn_struct_rwlock); 1891eda14cbcSMatt Macy dnode_rele(dn, FTAG); 1892eda14cbcSMatt Macy range = get_next_range(inq, range); 1893eda14cbcSMatt Macy } 1894eda14cbcSMatt Macy } 1895eda14cbcSMatt Macy } 1896eda14cbcSMatt Macy if (srta->cancel || err != 0) { 1897eda14cbcSMatt Macy smta->cancel = B_TRUE; 1898eda14cbcSMatt Macy srta->error = err; 1899eda14cbcSMatt Macy } else if (smta->error != 0) { 1900eda14cbcSMatt Macy srta->error = smta->error; 1901eda14cbcSMatt Macy } 1902eda14cbcSMatt Macy while (!range->eos_marker) 1903eda14cbcSMatt Macy range = get_next_range(inq, range); 1904eda14cbcSMatt Macy 1905eda14cbcSMatt Macy bqueue_enqueue_flush(outq, range, 1); 1906eda14cbcSMatt Macy spl_fstrans_unmark(cookie); 1907eda14cbcSMatt Macy thread_exit(); 1908eda14cbcSMatt Macy } 1909eda14cbcSMatt Macy 1910eda14cbcSMatt Macy #define NUM_SNAPS_NOT_REDACTED UINT64_MAX 1911eda14cbcSMatt Macy 1912eda14cbcSMatt Macy struct dmu_send_params { 1913eda14cbcSMatt Macy /* Pool args */ 1914eda14cbcSMatt Macy void *tag; // Tag that dp was held with, will be used to release dp. 1915eda14cbcSMatt Macy dsl_pool_t *dp; 1916eda14cbcSMatt Macy /* To snapshot args */ 1917eda14cbcSMatt Macy const char *tosnap; 1918eda14cbcSMatt Macy dsl_dataset_t *to_ds; 1919eda14cbcSMatt Macy /* From snapshot args */ 1920eda14cbcSMatt Macy zfs_bookmark_phys_t ancestor_zb; 1921eda14cbcSMatt Macy uint64_t *fromredactsnaps; 1922eda14cbcSMatt Macy /* NUM_SNAPS_NOT_REDACTED if not sending from redaction bookmark */ 1923eda14cbcSMatt Macy uint64_t numfromredactsnaps; 1924eda14cbcSMatt Macy /* Stream params */ 1925eda14cbcSMatt Macy boolean_t is_clone; 1926eda14cbcSMatt Macy boolean_t embedok; 1927eda14cbcSMatt Macy boolean_t large_block_ok; 1928eda14cbcSMatt Macy boolean_t compressok; 1929eda14cbcSMatt Macy boolean_t rawok; 1930eda14cbcSMatt Macy boolean_t savedok; 1931eda14cbcSMatt Macy uint64_t resumeobj; 1932eda14cbcSMatt Macy uint64_t resumeoff; 1933eda14cbcSMatt Macy uint64_t saved_guid; 1934eda14cbcSMatt Macy zfs_bookmark_phys_t *redactbook; 1935eda14cbcSMatt Macy /* Stream output params */ 1936eda14cbcSMatt Macy dmu_send_outparams_t *dso; 1937eda14cbcSMatt Macy 1938eda14cbcSMatt Macy /* Stream progress params */ 1939eda14cbcSMatt Macy offset_t *off; 1940eda14cbcSMatt Macy int outfd; 1941eda14cbcSMatt Macy char saved_toname[MAXNAMELEN]; 1942eda14cbcSMatt Macy }; 1943eda14cbcSMatt Macy 1944eda14cbcSMatt Macy static int 1945eda14cbcSMatt Macy setup_featureflags(struct dmu_send_params *dspp, objset_t *os, 1946eda14cbcSMatt Macy uint64_t *featureflags) 1947eda14cbcSMatt Macy { 1948eda14cbcSMatt Macy dsl_dataset_t *to_ds = dspp->to_ds; 1949eda14cbcSMatt Macy dsl_pool_t *dp = dspp->dp; 1950eda14cbcSMatt Macy #ifdef _KERNEL 1951eda14cbcSMatt Macy if (dmu_objset_type(os) == DMU_OST_ZFS) { 1952eda14cbcSMatt Macy uint64_t version; 1953eda14cbcSMatt Macy if (zfs_get_zplprop(os, ZFS_PROP_VERSION, &version) != 0) 1954eda14cbcSMatt Macy return (SET_ERROR(EINVAL)); 1955eda14cbcSMatt Macy 1956eda14cbcSMatt Macy if (version >= ZPL_VERSION_SA) 1957eda14cbcSMatt Macy *featureflags |= DMU_BACKUP_FEATURE_SA_SPILL; 1958eda14cbcSMatt Macy } 1959eda14cbcSMatt Macy #endif 1960eda14cbcSMatt Macy 1961eda14cbcSMatt Macy /* raw sends imply large_block_ok */ 1962eda14cbcSMatt Macy if ((dspp->rawok || dspp->large_block_ok) && 1963eda14cbcSMatt Macy dsl_dataset_feature_is_active(to_ds, SPA_FEATURE_LARGE_BLOCKS)) { 1964eda14cbcSMatt Macy *featureflags |= DMU_BACKUP_FEATURE_LARGE_BLOCKS; 1965eda14cbcSMatt Macy } 1966eda14cbcSMatt Macy 1967eda14cbcSMatt Macy /* encrypted datasets will not have embedded blocks */ 1968eda14cbcSMatt Macy if ((dspp->embedok || dspp->rawok) && !os->os_encrypted && 1969eda14cbcSMatt Macy spa_feature_is_active(dp->dp_spa, SPA_FEATURE_EMBEDDED_DATA)) { 1970eda14cbcSMatt Macy *featureflags |= DMU_BACKUP_FEATURE_EMBED_DATA; 1971eda14cbcSMatt Macy } 1972eda14cbcSMatt Macy 1973eda14cbcSMatt Macy /* raw send implies compressok */ 1974eda14cbcSMatt Macy if (dspp->compressok || dspp->rawok) 1975eda14cbcSMatt Macy *featureflags |= DMU_BACKUP_FEATURE_COMPRESSED; 1976eda14cbcSMatt Macy 1977eda14cbcSMatt Macy if (dspp->rawok && os->os_encrypted) 1978eda14cbcSMatt Macy *featureflags |= DMU_BACKUP_FEATURE_RAW; 1979eda14cbcSMatt Macy 1980eda14cbcSMatt Macy if ((*featureflags & 1981eda14cbcSMatt Macy (DMU_BACKUP_FEATURE_EMBED_DATA | DMU_BACKUP_FEATURE_COMPRESSED | 1982eda14cbcSMatt Macy DMU_BACKUP_FEATURE_RAW)) != 0 && 1983eda14cbcSMatt Macy spa_feature_is_active(dp->dp_spa, SPA_FEATURE_LZ4_COMPRESS)) { 1984eda14cbcSMatt Macy *featureflags |= DMU_BACKUP_FEATURE_LZ4; 1985eda14cbcSMatt Macy } 1986eda14cbcSMatt Macy 1987eda14cbcSMatt Macy /* 1988eda14cbcSMatt Macy * We specifically do not include DMU_BACKUP_FEATURE_EMBED_DATA here to 1989eda14cbcSMatt Macy * allow sending ZSTD compressed datasets to a receiver that does not 1990eda14cbcSMatt Macy * support ZSTD 1991eda14cbcSMatt Macy */ 1992eda14cbcSMatt Macy if ((*featureflags & 1993eda14cbcSMatt Macy (DMU_BACKUP_FEATURE_COMPRESSED | DMU_BACKUP_FEATURE_RAW)) != 0 && 1994eda14cbcSMatt Macy dsl_dataset_feature_is_active(to_ds, SPA_FEATURE_ZSTD_COMPRESS)) { 1995eda14cbcSMatt Macy *featureflags |= DMU_BACKUP_FEATURE_ZSTD; 1996eda14cbcSMatt Macy } 1997eda14cbcSMatt Macy 1998eda14cbcSMatt Macy if (dspp->resumeobj != 0 || dspp->resumeoff != 0) { 1999eda14cbcSMatt Macy *featureflags |= DMU_BACKUP_FEATURE_RESUMING; 2000eda14cbcSMatt Macy } 2001eda14cbcSMatt Macy 2002eda14cbcSMatt Macy if (dspp->redactbook != NULL) { 2003eda14cbcSMatt Macy *featureflags |= DMU_BACKUP_FEATURE_REDACTED; 2004eda14cbcSMatt Macy } 2005eda14cbcSMatt Macy 2006eda14cbcSMatt Macy if (dsl_dataset_feature_is_active(to_ds, SPA_FEATURE_LARGE_DNODE)) { 2007eda14cbcSMatt Macy *featureflags |= DMU_BACKUP_FEATURE_LARGE_DNODE; 2008eda14cbcSMatt Macy } 2009eda14cbcSMatt Macy return (0); 2010eda14cbcSMatt Macy } 2011eda14cbcSMatt Macy 2012eda14cbcSMatt Macy static dmu_replay_record_t * 2013eda14cbcSMatt Macy create_begin_record(struct dmu_send_params *dspp, objset_t *os, 2014eda14cbcSMatt Macy uint64_t featureflags) 2015eda14cbcSMatt Macy { 2016eda14cbcSMatt Macy dmu_replay_record_t *drr = kmem_zalloc(sizeof (dmu_replay_record_t), 2017eda14cbcSMatt Macy KM_SLEEP); 2018eda14cbcSMatt Macy drr->drr_type = DRR_BEGIN; 2019eda14cbcSMatt Macy 2020eda14cbcSMatt Macy struct drr_begin *drrb = &drr->drr_u.drr_begin; 2021eda14cbcSMatt Macy dsl_dataset_t *to_ds = dspp->to_ds; 2022eda14cbcSMatt Macy 2023eda14cbcSMatt Macy drrb->drr_magic = DMU_BACKUP_MAGIC; 2024eda14cbcSMatt Macy drrb->drr_creation_time = dsl_dataset_phys(to_ds)->ds_creation_time; 2025eda14cbcSMatt Macy drrb->drr_type = dmu_objset_type(os); 2026eda14cbcSMatt Macy drrb->drr_toguid = dsl_dataset_phys(to_ds)->ds_guid; 2027eda14cbcSMatt Macy drrb->drr_fromguid = dspp->ancestor_zb.zbm_guid; 2028eda14cbcSMatt Macy 2029eda14cbcSMatt Macy DMU_SET_STREAM_HDRTYPE(drrb->drr_versioninfo, DMU_SUBSTREAM); 2030eda14cbcSMatt Macy DMU_SET_FEATUREFLAGS(drrb->drr_versioninfo, featureflags); 2031eda14cbcSMatt Macy 2032eda14cbcSMatt Macy if (dspp->is_clone) 2033eda14cbcSMatt Macy drrb->drr_flags |= DRR_FLAG_CLONE; 2034eda14cbcSMatt Macy if (dsl_dataset_phys(dspp->to_ds)->ds_flags & DS_FLAG_CI_DATASET) 2035eda14cbcSMatt Macy drrb->drr_flags |= DRR_FLAG_CI_DATA; 2036eda14cbcSMatt Macy if (zfs_send_set_freerecords_bit) 2037eda14cbcSMatt Macy drrb->drr_flags |= DRR_FLAG_FREERECORDS; 2038eda14cbcSMatt Macy drr->drr_u.drr_begin.drr_flags |= DRR_FLAG_SPILL_BLOCK; 2039eda14cbcSMatt Macy 2040eda14cbcSMatt Macy if (dspp->savedok) { 2041eda14cbcSMatt Macy drrb->drr_toguid = dspp->saved_guid; 2042eda14cbcSMatt Macy strlcpy(drrb->drr_toname, dspp->saved_toname, 2043eda14cbcSMatt Macy sizeof (drrb->drr_toname)); 2044eda14cbcSMatt Macy } else { 2045eda14cbcSMatt Macy dsl_dataset_name(to_ds, drrb->drr_toname); 2046eda14cbcSMatt Macy if (!to_ds->ds_is_snapshot) { 2047eda14cbcSMatt Macy (void) strlcat(drrb->drr_toname, "@--head--", 2048eda14cbcSMatt Macy sizeof (drrb->drr_toname)); 2049eda14cbcSMatt Macy } 2050eda14cbcSMatt Macy } 2051eda14cbcSMatt Macy return (drr); 2052eda14cbcSMatt Macy } 2053eda14cbcSMatt Macy 2054eda14cbcSMatt Macy static void 2055eda14cbcSMatt Macy setup_to_thread(struct send_thread_arg *to_arg, objset_t *to_os, 2056eda14cbcSMatt Macy dmu_sendstatus_t *dssp, uint64_t fromtxg, boolean_t rawok) 2057eda14cbcSMatt Macy { 2058eda14cbcSMatt Macy VERIFY0(bqueue_init(&to_arg->q, zfs_send_no_prefetch_queue_ff, 2059eda14cbcSMatt Macy MAX(zfs_send_no_prefetch_queue_length, 2 * zfs_max_recordsize), 2060eda14cbcSMatt Macy offsetof(struct send_range, ln))); 2061eda14cbcSMatt Macy to_arg->error_code = 0; 2062eda14cbcSMatt Macy to_arg->cancel = B_FALSE; 2063eda14cbcSMatt Macy to_arg->os = to_os; 2064eda14cbcSMatt Macy to_arg->fromtxg = fromtxg; 2065eda14cbcSMatt Macy to_arg->flags = TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA; 2066eda14cbcSMatt Macy if (rawok) 2067eda14cbcSMatt Macy to_arg->flags |= TRAVERSE_NO_DECRYPT; 206853b70c86SMartin Matuska if (zfs_send_corrupt_data) 206953b70c86SMartin Matuska to_arg->flags |= TRAVERSE_HARD; 2070eda14cbcSMatt Macy to_arg->num_blocks_visited = &dssp->dss_blocks; 2071eda14cbcSMatt Macy (void) thread_create(NULL, 0, send_traverse_thread, to_arg, 0, 2072eda14cbcSMatt Macy curproc, TS_RUN, minclsyspri); 2073eda14cbcSMatt Macy } 2074eda14cbcSMatt Macy 2075eda14cbcSMatt Macy static void 2076eda14cbcSMatt Macy setup_from_thread(struct redact_list_thread_arg *from_arg, 2077eda14cbcSMatt Macy redaction_list_t *from_rl, dmu_sendstatus_t *dssp) 2078eda14cbcSMatt Macy { 2079eda14cbcSMatt Macy VERIFY0(bqueue_init(&from_arg->q, zfs_send_no_prefetch_queue_ff, 2080eda14cbcSMatt Macy MAX(zfs_send_no_prefetch_queue_length, 2 * zfs_max_recordsize), 2081eda14cbcSMatt Macy offsetof(struct send_range, ln))); 2082eda14cbcSMatt Macy from_arg->error_code = 0; 2083eda14cbcSMatt Macy from_arg->cancel = B_FALSE; 2084eda14cbcSMatt Macy from_arg->rl = from_rl; 2085eda14cbcSMatt Macy from_arg->mark_redact = B_FALSE; 2086eda14cbcSMatt Macy from_arg->num_blocks_visited = &dssp->dss_blocks; 2087eda14cbcSMatt Macy /* 2088eda14cbcSMatt Macy * If from_ds is null, send_traverse_thread just returns success and 2089eda14cbcSMatt Macy * enqueues an eos marker. 2090eda14cbcSMatt Macy */ 2091eda14cbcSMatt Macy (void) thread_create(NULL, 0, redact_list_thread, from_arg, 0, 2092eda14cbcSMatt Macy curproc, TS_RUN, minclsyspri); 2093eda14cbcSMatt Macy } 2094eda14cbcSMatt Macy 2095eda14cbcSMatt Macy static void 2096eda14cbcSMatt Macy setup_redact_list_thread(struct redact_list_thread_arg *rlt_arg, 2097eda14cbcSMatt Macy struct dmu_send_params *dspp, redaction_list_t *rl, dmu_sendstatus_t *dssp) 2098eda14cbcSMatt Macy { 2099eda14cbcSMatt Macy if (dspp->redactbook == NULL) 2100eda14cbcSMatt Macy return; 2101eda14cbcSMatt Macy 2102eda14cbcSMatt Macy rlt_arg->cancel = B_FALSE; 2103eda14cbcSMatt Macy VERIFY0(bqueue_init(&rlt_arg->q, zfs_send_no_prefetch_queue_ff, 2104eda14cbcSMatt Macy MAX(zfs_send_no_prefetch_queue_length, 2 * zfs_max_recordsize), 2105eda14cbcSMatt Macy offsetof(struct send_range, ln))); 2106eda14cbcSMatt Macy rlt_arg->error_code = 0; 2107eda14cbcSMatt Macy rlt_arg->mark_redact = B_TRUE; 2108eda14cbcSMatt Macy rlt_arg->rl = rl; 2109eda14cbcSMatt Macy rlt_arg->num_blocks_visited = &dssp->dss_blocks; 2110eda14cbcSMatt Macy 2111eda14cbcSMatt Macy (void) thread_create(NULL, 0, redact_list_thread, rlt_arg, 0, 2112eda14cbcSMatt Macy curproc, TS_RUN, minclsyspri); 2113eda14cbcSMatt Macy } 2114eda14cbcSMatt Macy 2115eda14cbcSMatt Macy static void 2116eda14cbcSMatt Macy setup_merge_thread(struct send_merge_thread_arg *smt_arg, 2117eda14cbcSMatt Macy struct dmu_send_params *dspp, struct redact_list_thread_arg *from_arg, 2118eda14cbcSMatt Macy struct send_thread_arg *to_arg, struct redact_list_thread_arg *rlt_arg, 2119eda14cbcSMatt Macy objset_t *os) 2120eda14cbcSMatt Macy { 2121eda14cbcSMatt Macy VERIFY0(bqueue_init(&smt_arg->q, zfs_send_no_prefetch_queue_ff, 2122eda14cbcSMatt Macy MAX(zfs_send_no_prefetch_queue_length, 2 * zfs_max_recordsize), 2123eda14cbcSMatt Macy offsetof(struct send_range, ln))); 2124eda14cbcSMatt Macy smt_arg->cancel = B_FALSE; 2125eda14cbcSMatt Macy smt_arg->error = 0; 2126eda14cbcSMatt Macy smt_arg->from_arg = from_arg; 2127eda14cbcSMatt Macy smt_arg->to_arg = to_arg; 2128eda14cbcSMatt Macy if (dspp->redactbook != NULL) 2129eda14cbcSMatt Macy smt_arg->redact_arg = rlt_arg; 2130eda14cbcSMatt Macy 2131eda14cbcSMatt Macy smt_arg->os = os; 2132eda14cbcSMatt Macy (void) thread_create(NULL, 0, send_merge_thread, smt_arg, 0, curproc, 2133eda14cbcSMatt Macy TS_RUN, minclsyspri); 2134eda14cbcSMatt Macy } 2135eda14cbcSMatt Macy 2136eda14cbcSMatt Macy static void 2137eda14cbcSMatt Macy setup_reader_thread(struct send_reader_thread_arg *srt_arg, 2138eda14cbcSMatt Macy struct dmu_send_params *dspp, struct send_merge_thread_arg *smt_arg, 2139eda14cbcSMatt Macy uint64_t featureflags) 2140eda14cbcSMatt Macy { 2141eda14cbcSMatt Macy VERIFY0(bqueue_init(&srt_arg->q, zfs_send_queue_ff, 2142eda14cbcSMatt Macy MAX(zfs_send_queue_length, 2 * zfs_max_recordsize), 2143eda14cbcSMatt Macy offsetof(struct send_range, ln))); 2144eda14cbcSMatt Macy srt_arg->smta = smt_arg; 2145eda14cbcSMatt Macy srt_arg->issue_reads = !dspp->dso->dso_dryrun; 2146eda14cbcSMatt Macy srt_arg->featureflags = featureflags; 2147eda14cbcSMatt Macy (void) thread_create(NULL, 0, send_reader_thread, srt_arg, 0, 2148eda14cbcSMatt Macy curproc, TS_RUN, minclsyspri); 2149eda14cbcSMatt Macy } 2150eda14cbcSMatt Macy 2151eda14cbcSMatt Macy static int 2152eda14cbcSMatt Macy setup_resume_points(struct dmu_send_params *dspp, 2153eda14cbcSMatt Macy struct send_thread_arg *to_arg, struct redact_list_thread_arg *from_arg, 2154eda14cbcSMatt Macy struct redact_list_thread_arg *rlt_arg, 2155eda14cbcSMatt Macy struct send_merge_thread_arg *smt_arg, boolean_t resuming, objset_t *os, 2156eda14cbcSMatt Macy redaction_list_t *redact_rl, nvlist_t *nvl) 2157eda14cbcSMatt Macy { 2158eda14cbcSMatt Macy dsl_dataset_t *to_ds = dspp->to_ds; 2159eda14cbcSMatt Macy int err = 0; 2160eda14cbcSMatt Macy 2161eda14cbcSMatt Macy uint64_t obj = 0; 2162eda14cbcSMatt Macy uint64_t blkid = 0; 2163eda14cbcSMatt Macy if (resuming) { 2164eda14cbcSMatt Macy obj = dspp->resumeobj; 2165eda14cbcSMatt Macy dmu_object_info_t to_doi; 2166eda14cbcSMatt Macy err = dmu_object_info(os, obj, &to_doi); 2167eda14cbcSMatt Macy if (err != 0) 2168eda14cbcSMatt Macy return (err); 2169eda14cbcSMatt Macy 2170eda14cbcSMatt Macy blkid = dspp->resumeoff / to_doi.doi_data_block_size; 2171eda14cbcSMatt Macy } 2172eda14cbcSMatt Macy /* 2173eda14cbcSMatt Macy * If we're resuming a redacted send, we can skip to the appropriate 2174eda14cbcSMatt Macy * point in the redaction bookmark by binary searching through it. 2175eda14cbcSMatt Macy */ 2176eda14cbcSMatt Macy if (redact_rl != NULL) { 2177eda14cbcSMatt Macy SET_BOOKMARK(&rlt_arg->resume, to_ds->ds_object, obj, 0, blkid); 2178eda14cbcSMatt Macy } 2179eda14cbcSMatt Macy 2180eda14cbcSMatt Macy SET_BOOKMARK(&to_arg->resume, to_ds->ds_object, obj, 0, blkid); 2181eda14cbcSMatt Macy if (nvlist_exists(nvl, BEGINNV_REDACT_FROM_SNAPS)) { 2182eda14cbcSMatt Macy uint64_t objset = dspp->ancestor_zb.zbm_redaction_obj; 2183eda14cbcSMatt Macy /* 2184eda14cbcSMatt Macy * Note: If the resume point is in an object whose 2185eda14cbcSMatt Macy * blocksize is different in the from vs to snapshots, 2186eda14cbcSMatt Macy * we will have divided by the "wrong" blocksize. 2187eda14cbcSMatt Macy * However, in this case fromsnap's send_cb() will 2188eda14cbcSMatt Macy * detect that the blocksize has changed and therefore 2189eda14cbcSMatt Macy * ignore this object. 2190eda14cbcSMatt Macy * 2191eda14cbcSMatt Macy * If we're resuming a send from a redaction bookmark, 2192eda14cbcSMatt Macy * we still cannot accidentally suggest blocks behind 2193eda14cbcSMatt Macy * the to_ds. In addition, we know that any blocks in 2194eda14cbcSMatt Macy * the object in the to_ds will have to be sent, since 2195eda14cbcSMatt Macy * the size changed. Therefore, we can't cause any harm 2196eda14cbcSMatt Macy * this way either. 2197eda14cbcSMatt Macy */ 2198eda14cbcSMatt Macy SET_BOOKMARK(&from_arg->resume, objset, obj, 0, blkid); 2199eda14cbcSMatt Macy } 2200eda14cbcSMatt Macy if (resuming) { 2201eda14cbcSMatt Macy fnvlist_add_uint64(nvl, BEGINNV_RESUME_OBJECT, dspp->resumeobj); 2202eda14cbcSMatt Macy fnvlist_add_uint64(nvl, BEGINNV_RESUME_OFFSET, dspp->resumeoff); 2203eda14cbcSMatt Macy } 2204eda14cbcSMatt Macy return (0); 2205eda14cbcSMatt Macy } 2206eda14cbcSMatt Macy 2207eda14cbcSMatt Macy static dmu_sendstatus_t * 2208eda14cbcSMatt Macy setup_send_progress(struct dmu_send_params *dspp) 2209eda14cbcSMatt Macy { 2210eda14cbcSMatt Macy dmu_sendstatus_t *dssp = kmem_zalloc(sizeof (*dssp), KM_SLEEP); 2211eda14cbcSMatt Macy dssp->dss_outfd = dspp->outfd; 2212eda14cbcSMatt Macy dssp->dss_off = dspp->off; 2213eda14cbcSMatt Macy dssp->dss_proc = curproc; 2214eda14cbcSMatt Macy mutex_enter(&dspp->to_ds->ds_sendstream_lock); 2215eda14cbcSMatt Macy list_insert_head(&dspp->to_ds->ds_sendstreams, dssp); 2216eda14cbcSMatt Macy mutex_exit(&dspp->to_ds->ds_sendstream_lock); 2217eda14cbcSMatt Macy return (dssp); 2218eda14cbcSMatt Macy } 2219eda14cbcSMatt Macy 2220eda14cbcSMatt Macy /* 2221eda14cbcSMatt Macy * Actually do the bulk of the work in a zfs send. 2222eda14cbcSMatt Macy * 2223eda14cbcSMatt Macy * The idea is that we want to do a send from ancestor_zb to to_ds. We also 2224eda14cbcSMatt Macy * want to not send any data that has been modified by all the datasets in 2225eda14cbcSMatt Macy * redactsnaparr, and store the list of blocks that are redacted in this way in 2226eda14cbcSMatt Macy * a bookmark named redactbook, created on the to_ds. We do this by creating 2227eda14cbcSMatt Macy * several worker threads, whose function is described below. 2228eda14cbcSMatt Macy * 2229eda14cbcSMatt Macy * There are three cases. 2230eda14cbcSMatt Macy * The first case is a redacted zfs send. In this case there are 5 threads. 2231eda14cbcSMatt Macy * The first thread is the to_ds traversal thread: it calls dataset_traverse on 2232eda14cbcSMatt Macy * the to_ds and finds all the blocks that have changed since ancestor_zb (if 2233eda14cbcSMatt Macy * it's a full send, that's all blocks in the dataset). It then sends those 2234eda14cbcSMatt Macy * blocks on to the send merge thread. The redact list thread takes the data 2235eda14cbcSMatt Macy * from the redaction bookmark and sends those blocks on to the send merge 2236eda14cbcSMatt Macy * thread. The send merge thread takes the data from the to_ds traversal 2237eda14cbcSMatt Macy * thread, and combines it with the redaction records from the redact list 2238eda14cbcSMatt Macy * thread. If a block appears in both the to_ds's data and the redaction data, 2239eda14cbcSMatt Macy * the send merge thread will mark it as redacted and send it on to the prefetch 2240eda14cbcSMatt Macy * thread. Otherwise, the send merge thread will send the block on to the 2241eda14cbcSMatt Macy * prefetch thread unchanged. The prefetch thread will issue prefetch reads for 2242eda14cbcSMatt Macy * any data that isn't redacted, and then send the data on to the main thread. 2243eda14cbcSMatt Macy * The main thread behaves the same as in a normal send case, issuing demand 2244eda14cbcSMatt Macy * reads for data blocks and sending out records over the network 2245eda14cbcSMatt Macy * 2246eda14cbcSMatt Macy * The graphic below diagrams the flow of data in the case of a redacted zfs 2247eda14cbcSMatt Macy * send. Each box represents a thread, and each line represents the flow of 2248eda14cbcSMatt Macy * data. 2249eda14cbcSMatt Macy * 2250eda14cbcSMatt Macy * Records from the | 2251eda14cbcSMatt Macy * redaction bookmark | 2252eda14cbcSMatt Macy * +--------------------+ | +---------------------------+ 2253eda14cbcSMatt Macy * | | v | Send Merge Thread | 2254eda14cbcSMatt Macy * | Redact List Thread +----------> Apply redaction marks to | 2255eda14cbcSMatt Macy * | | | records as specified by | 2256eda14cbcSMatt Macy * +--------------------+ | redaction ranges | 2257eda14cbcSMatt Macy * +----^---------------+------+ 2258eda14cbcSMatt Macy * | | Merged data 2259eda14cbcSMatt Macy * | | 2260eda14cbcSMatt Macy * | +------------v--------+ 2261eda14cbcSMatt Macy * | | Prefetch Thread | 2262eda14cbcSMatt Macy * +--------------------+ | | Issues prefetch | 2263eda14cbcSMatt Macy * | to_ds Traversal | | | reads of data blocks| 2264eda14cbcSMatt Macy * | Thread (finds +---------------+ +------------+--------+ 2265eda14cbcSMatt Macy * | candidate blocks) | Blocks modified | Prefetched data 2266eda14cbcSMatt Macy * +--------------------+ by to_ds since | 2267eda14cbcSMatt Macy * ancestor_zb +------------v----+ 2268eda14cbcSMatt Macy * | Main Thread | File Descriptor 2269eda14cbcSMatt Macy * | Sends data over +->(to zfs receive) 2270eda14cbcSMatt Macy * | wire | 2271eda14cbcSMatt Macy * +-----------------+ 2272eda14cbcSMatt Macy * 2273eda14cbcSMatt Macy * The second case is an incremental send from a redaction bookmark. The to_ds 2274eda14cbcSMatt Macy * traversal thread and the main thread behave the same as in the redacted 2275eda14cbcSMatt Macy * send case. The new thread is the from bookmark traversal thread. It 2276eda14cbcSMatt Macy * iterates over the redaction list in the redaction bookmark, and enqueues 2277eda14cbcSMatt Macy * records for each block that was redacted in the original send. The send 2278eda14cbcSMatt Macy * merge thread now has to merge the data from the two threads. For details 2279eda14cbcSMatt Macy * about that process, see the header comment of send_merge_thread(). Any data 2280eda14cbcSMatt Macy * it decides to send on will be prefetched by the prefetch thread. Note that 2281eda14cbcSMatt Macy * you can perform a redacted send from a redaction bookmark; in that case, 2282eda14cbcSMatt Macy * the data flow behaves very similarly to the flow in the redacted send case, 2283eda14cbcSMatt Macy * except with the addition of the bookmark traversal thread iterating over the 2284eda14cbcSMatt Macy * redaction bookmark. The send_merge_thread also has to take on the 2285eda14cbcSMatt Macy * responsibility of merging the redact list thread's records, the bookmark 2286eda14cbcSMatt Macy * traversal thread's records, and the to_ds records. 2287eda14cbcSMatt Macy * 2288eda14cbcSMatt Macy * +---------------------+ 2289eda14cbcSMatt Macy * | | 2290eda14cbcSMatt Macy * | Redact List Thread +--------------+ 2291eda14cbcSMatt Macy * | | | 2292eda14cbcSMatt Macy * +---------------------+ | 2293eda14cbcSMatt Macy * Blocks in redaction list | Ranges modified by every secure snap 2294eda14cbcSMatt Macy * of from bookmark | (or EOS if not readcted) 2295eda14cbcSMatt Macy * | 2296eda14cbcSMatt Macy * +---------------------+ | +----v----------------------+ 2297eda14cbcSMatt Macy * | bookmark Traversal | v | Send Merge Thread | 2298eda14cbcSMatt Macy * | Thread (finds +---------> Merges bookmark, rlt, and | 2299eda14cbcSMatt Macy * | candidate blocks) | | to_ds send records | 2300eda14cbcSMatt Macy * +---------------------+ +----^---------------+------+ 2301eda14cbcSMatt Macy * | | Merged data 2302eda14cbcSMatt Macy * | +------------v--------+ 2303eda14cbcSMatt Macy * | | Prefetch Thread | 2304eda14cbcSMatt Macy * +--------------------+ | | Issues prefetch | 2305eda14cbcSMatt Macy * | to_ds Traversal | | | reads of data blocks| 2306eda14cbcSMatt Macy * | Thread (finds +---------------+ +------------+--------+ 2307eda14cbcSMatt Macy * | candidate blocks) | Blocks modified | Prefetched data 2308eda14cbcSMatt Macy * +--------------------+ by to_ds since +------------v----+ 2309eda14cbcSMatt Macy * ancestor_zb | Main Thread | File Descriptor 2310eda14cbcSMatt Macy * | Sends data over +->(to zfs receive) 2311eda14cbcSMatt Macy * | wire | 2312eda14cbcSMatt Macy * +-----------------+ 2313eda14cbcSMatt Macy * 2314eda14cbcSMatt Macy * The final case is a simple zfs full or incremental send. The to_ds traversal 2315eda14cbcSMatt Macy * thread behaves the same as always. The redact list thread is never started. 2316eda14cbcSMatt Macy * The send merge thread takes all the blocks that the to_ds traversal thread 2317eda14cbcSMatt Macy * sends it, prefetches the data, and sends the blocks on to the main thread. 2318eda14cbcSMatt Macy * The main thread sends the data over the wire. 2319eda14cbcSMatt Macy * 2320eda14cbcSMatt Macy * To keep performance acceptable, we want to prefetch the data in the worker 2321eda14cbcSMatt Macy * threads. While the to_ds thread could simply use the TRAVERSE_PREFETCH 2322eda14cbcSMatt Macy * feature built into traverse_dataset, the combining and deletion of records 2323eda14cbcSMatt Macy * due to redaction and sends from redaction bookmarks mean that we could 2324eda14cbcSMatt Macy * issue many unnecessary prefetches. As a result, we only prefetch data 2325eda14cbcSMatt Macy * after we've determined that the record is not going to be redacted. To 2326eda14cbcSMatt Macy * prevent the prefetching from getting too far ahead of the main thread, the 2327eda14cbcSMatt Macy * blocking queues that are used for communication are capped not by the 2328eda14cbcSMatt Macy * number of entries in the queue, but by the sum of the size of the 2329eda14cbcSMatt Macy * prefetches associated with them. The limit on the amount of data that the 2330eda14cbcSMatt Macy * thread can prefetch beyond what the main thread has reached is controlled 2331eda14cbcSMatt Macy * by the global variable zfs_send_queue_length. In addition, to prevent poor 2332eda14cbcSMatt Macy * performance in the beginning of a send, we also limit the distance ahead 2333eda14cbcSMatt Macy * that the traversal threads can be. That distance is controlled by the 2334eda14cbcSMatt Macy * zfs_send_no_prefetch_queue_length tunable. 2335eda14cbcSMatt Macy * 2336eda14cbcSMatt Macy * Note: Releases dp using the specified tag. 2337eda14cbcSMatt Macy */ 2338eda14cbcSMatt Macy static int 2339eda14cbcSMatt Macy dmu_send_impl(struct dmu_send_params *dspp) 2340eda14cbcSMatt Macy { 2341eda14cbcSMatt Macy objset_t *os; 2342eda14cbcSMatt Macy dmu_replay_record_t *drr; 2343eda14cbcSMatt Macy dmu_sendstatus_t *dssp; 2344eda14cbcSMatt Macy dmu_send_cookie_t dsc = {0}; 2345eda14cbcSMatt Macy int err; 2346eda14cbcSMatt Macy uint64_t fromtxg = dspp->ancestor_zb.zbm_creation_txg; 2347eda14cbcSMatt Macy uint64_t featureflags = 0; 2348eda14cbcSMatt Macy struct redact_list_thread_arg *from_arg; 2349eda14cbcSMatt Macy struct send_thread_arg *to_arg; 2350eda14cbcSMatt Macy struct redact_list_thread_arg *rlt_arg; 2351eda14cbcSMatt Macy struct send_merge_thread_arg *smt_arg; 2352eda14cbcSMatt Macy struct send_reader_thread_arg *srt_arg; 2353eda14cbcSMatt Macy struct send_range *range; 2354eda14cbcSMatt Macy redaction_list_t *from_rl = NULL; 2355eda14cbcSMatt Macy redaction_list_t *redact_rl = NULL; 2356eda14cbcSMatt Macy boolean_t resuming = (dspp->resumeobj != 0 || dspp->resumeoff != 0); 2357eda14cbcSMatt Macy boolean_t book_resuming = resuming; 2358eda14cbcSMatt Macy 2359eda14cbcSMatt Macy dsl_dataset_t *to_ds = dspp->to_ds; 2360eda14cbcSMatt Macy zfs_bookmark_phys_t *ancestor_zb = &dspp->ancestor_zb; 2361eda14cbcSMatt Macy dsl_pool_t *dp = dspp->dp; 2362eda14cbcSMatt Macy void *tag = dspp->tag; 2363eda14cbcSMatt Macy 2364eda14cbcSMatt Macy err = dmu_objset_from_ds(to_ds, &os); 2365eda14cbcSMatt Macy if (err != 0) { 2366eda14cbcSMatt Macy dsl_pool_rele(dp, tag); 2367eda14cbcSMatt Macy return (err); 2368eda14cbcSMatt Macy } 2369eda14cbcSMatt Macy 2370eda14cbcSMatt Macy /* 2371eda14cbcSMatt Macy * If this is a non-raw send of an encrypted ds, we can ensure that 2372eda14cbcSMatt Macy * the objset_phys_t is authenticated. This is safe because this is 2373eda14cbcSMatt Macy * either a snapshot or we have owned the dataset, ensuring that 2374eda14cbcSMatt Macy * it can't be modified. 2375eda14cbcSMatt Macy */ 2376eda14cbcSMatt Macy if (!dspp->rawok && os->os_encrypted && 2377eda14cbcSMatt Macy arc_is_unauthenticated(os->os_phys_buf)) { 2378eda14cbcSMatt Macy zbookmark_phys_t zb; 2379eda14cbcSMatt Macy 2380eda14cbcSMatt Macy SET_BOOKMARK(&zb, to_ds->ds_object, ZB_ROOT_OBJECT, 2381eda14cbcSMatt Macy ZB_ROOT_LEVEL, ZB_ROOT_BLKID); 2382eda14cbcSMatt Macy err = arc_untransform(os->os_phys_buf, os->os_spa, 2383eda14cbcSMatt Macy &zb, B_FALSE); 2384eda14cbcSMatt Macy if (err != 0) { 2385eda14cbcSMatt Macy dsl_pool_rele(dp, tag); 2386eda14cbcSMatt Macy return (err); 2387eda14cbcSMatt Macy } 2388eda14cbcSMatt Macy 2389eda14cbcSMatt Macy ASSERT0(arc_is_unauthenticated(os->os_phys_buf)); 2390eda14cbcSMatt Macy } 2391eda14cbcSMatt Macy 2392eda14cbcSMatt Macy if ((err = setup_featureflags(dspp, os, &featureflags)) != 0) { 2393eda14cbcSMatt Macy dsl_pool_rele(dp, tag); 2394eda14cbcSMatt Macy return (err); 2395eda14cbcSMatt Macy } 2396eda14cbcSMatt Macy 2397eda14cbcSMatt Macy /* 2398eda14cbcSMatt Macy * If we're doing a redacted send, hold the bookmark's redaction list. 2399eda14cbcSMatt Macy */ 2400eda14cbcSMatt Macy if (dspp->redactbook != NULL) { 2401eda14cbcSMatt Macy err = dsl_redaction_list_hold_obj(dp, 2402eda14cbcSMatt Macy dspp->redactbook->zbm_redaction_obj, FTAG, 2403eda14cbcSMatt Macy &redact_rl); 2404eda14cbcSMatt Macy if (err != 0) { 2405eda14cbcSMatt Macy dsl_pool_rele(dp, tag); 2406eda14cbcSMatt Macy return (SET_ERROR(EINVAL)); 2407eda14cbcSMatt Macy } 2408eda14cbcSMatt Macy dsl_redaction_list_long_hold(dp, redact_rl, FTAG); 2409eda14cbcSMatt Macy } 2410eda14cbcSMatt Macy 2411eda14cbcSMatt Macy /* 2412eda14cbcSMatt Macy * If we're sending from a redaction bookmark, hold the redaction list 2413eda14cbcSMatt Macy * so that we can consider sending the redacted blocks. 2414eda14cbcSMatt Macy */ 2415eda14cbcSMatt Macy if (ancestor_zb->zbm_redaction_obj != 0) { 2416eda14cbcSMatt Macy err = dsl_redaction_list_hold_obj(dp, 2417eda14cbcSMatt Macy ancestor_zb->zbm_redaction_obj, FTAG, &from_rl); 2418eda14cbcSMatt Macy if (err != 0) { 2419eda14cbcSMatt Macy if (redact_rl != NULL) { 2420eda14cbcSMatt Macy dsl_redaction_list_long_rele(redact_rl, FTAG); 2421eda14cbcSMatt Macy dsl_redaction_list_rele(redact_rl, FTAG); 2422eda14cbcSMatt Macy } 2423eda14cbcSMatt Macy dsl_pool_rele(dp, tag); 2424eda14cbcSMatt Macy return (SET_ERROR(EINVAL)); 2425eda14cbcSMatt Macy } 2426eda14cbcSMatt Macy dsl_redaction_list_long_hold(dp, from_rl, FTAG); 2427eda14cbcSMatt Macy } 2428eda14cbcSMatt Macy 2429eda14cbcSMatt Macy dsl_dataset_long_hold(to_ds, FTAG); 2430eda14cbcSMatt Macy 2431eda14cbcSMatt Macy from_arg = kmem_zalloc(sizeof (*from_arg), KM_SLEEP); 2432eda14cbcSMatt Macy to_arg = kmem_zalloc(sizeof (*to_arg), KM_SLEEP); 2433eda14cbcSMatt Macy rlt_arg = kmem_zalloc(sizeof (*rlt_arg), KM_SLEEP); 2434eda14cbcSMatt Macy smt_arg = kmem_zalloc(sizeof (*smt_arg), KM_SLEEP); 2435eda14cbcSMatt Macy srt_arg = kmem_zalloc(sizeof (*srt_arg), KM_SLEEP); 2436eda14cbcSMatt Macy 2437eda14cbcSMatt Macy drr = create_begin_record(dspp, os, featureflags); 2438eda14cbcSMatt Macy dssp = setup_send_progress(dspp); 2439eda14cbcSMatt Macy 2440eda14cbcSMatt Macy dsc.dsc_drr = drr; 2441eda14cbcSMatt Macy dsc.dsc_dso = dspp->dso; 2442eda14cbcSMatt Macy dsc.dsc_os = os; 2443eda14cbcSMatt Macy dsc.dsc_off = dspp->off; 2444eda14cbcSMatt Macy dsc.dsc_toguid = dsl_dataset_phys(to_ds)->ds_guid; 2445eda14cbcSMatt Macy dsc.dsc_fromtxg = fromtxg; 2446eda14cbcSMatt Macy dsc.dsc_pending_op = PENDING_NONE; 2447eda14cbcSMatt Macy dsc.dsc_featureflags = featureflags; 2448eda14cbcSMatt Macy dsc.dsc_resume_object = dspp->resumeobj; 2449eda14cbcSMatt Macy dsc.dsc_resume_offset = dspp->resumeoff; 2450eda14cbcSMatt Macy 2451eda14cbcSMatt Macy dsl_pool_rele(dp, tag); 2452eda14cbcSMatt Macy 2453eda14cbcSMatt Macy void *payload = NULL; 2454eda14cbcSMatt Macy size_t payload_len = 0; 2455eda14cbcSMatt Macy nvlist_t *nvl = fnvlist_alloc(); 2456eda14cbcSMatt Macy 2457eda14cbcSMatt Macy /* 2458eda14cbcSMatt Macy * If we're doing a redacted send, we include the snapshots we're 2459eda14cbcSMatt Macy * redacted with respect to so that the target system knows what send 2460eda14cbcSMatt Macy * streams can be correctly received on top of this dataset. If we're 2461eda14cbcSMatt Macy * instead sending a redacted dataset, we include the snapshots that the 2462eda14cbcSMatt Macy * dataset was created with respect to. 2463eda14cbcSMatt Macy */ 2464eda14cbcSMatt Macy if (dspp->redactbook != NULL) { 2465eda14cbcSMatt Macy fnvlist_add_uint64_array(nvl, BEGINNV_REDACT_SNAPS, 2466eda14cbcSMatt Macy redact_rl->rl_phys->rlp_snaps, 2467eda14cbcSMatt Macy redact_rl->rl_phys->rlp_num_snaps); 2468eda14cbcSMatt Macy } else if (dsl_dataset_feature_is_active(to_ds, 2469eda14cbcSMatt Macy SPA_FEATURE_REDACTED_DATASETS)) { 2470eda14cbcSMatt Macy uint64_t *tods_guids; 2471eda14cbcSMatt Macy uint64_t length; 2472eda14cbcSMatt Macy VERIFY(dsl_dataset_get_uint64_array_feature(to_ds, 2473eda14cbcSMatt Macy SPA_FEATURE_REDACTED_DATASETS, &length, &tods_guids)); 2474eda14cbcSMatt Macy fnvlist_add_uint64_array(nvl, BEGINNV_REDACT_SNAPS, tods_guids, 2475eda14cbcSMatt Macy length); 2476eda14cbcSMatt Macy } 2477eda14cbcSMatt Macy 2478eda14cbcSMatt Macy /* 2479eda14cbcSMatt Macy * If we're sending from a redaction bookmark, then we should retrieve 2480eda14cbcSMatt Macy * the guids of that bookmark so we can send them over the wire. 2481eda14cbcSMatt Macy */ 2482eda14cbcSMatt Macy if (from_rl != NULL) { 2483eda14cbcSMatt Macy fnvlist_add_uint64_array(nvl, BEGINNV_REDACT_FROM_SNAPS, 2484eda14cbcSMatt Macy from_rl->rl_phys->rlp_snaps, 2485eda14cbcSMatt Macy from_rl->rl_phys->rlp_num_snaps); 2486eda14cbcSMatt Macy } 2487eda14cbcSMatt Macy 2488eda14cbcSMatt Macy /* 2489eda14cbcSMatt Macy * If the snapshot we're sending from is redacted, include the redaction 2490eda14cbcSMatt Macy * list in the stream. 2491eda14cbcSMatt Macy */ 2492eda14cbcSMatt Macy if (dspp->numfromredactsnaps != NUM_SNAPS_NOT_REDACTED) { 2493eda14cbcSMatt Macy ASSERT3P(from_rl, ==, NULL); 2494eda14cbcSMatt Macy fnvlist_add_uint64_array(nvl, BEGINNV_REDACT_FROM_SNAPS, 2495eda14cbcSMatt Macy dspp->fromredactsnaps, (uint_t)dspp->numfromredactsnaps); 2496eda14cbcSMatt Macy if (dspp->numfromredactsnaps > 0) { 2497eda14cbcSMatt Macy kmem_free(dspp->fromredactsnaps, 2498eda14cbcSMatt Macy dspp->numfromredactsnaps * sizeof (uint64_t)); 2499eda14cbcSMatt Macy dspp->fromredactsnaps = NULL; 2500eda14cbcSMatt Macy } 2501eda14cbcSMatt Macy } 2502eda14cbcSMatt Macy 2503eda14cbcSMatt Macy if (resuming || book_resuming) { 2504eda14cbcSMatt Macy err = setup_resume_points(dspp, to_arg, from_arg, 2505eda14cbcSMatt Macy rlt_arg, smt_arg, resuming, os, redact_rl, nvl); 2506eda14cbcSMatt Macy if (err != 0) 2507eda14cbcSMatt Macy goto out; 2508eda14cbcSMatt Macy } 2509eda14cbcSMatt Macy 2510eda14cbcSMatt Macy if (featureflags & DMU_BACKUP_FEATURE_RAW) { 2511eda14cbcSMatt Macy uint64_t ivset_guid = (ancestor_zb != NULL) ? 2512eda14cbcSMatt Macy ancestor_zb->zbm_ivset_guid : 0; 2513eda14cbcSMatt Macy nvlist_t *keynvl = NULL; 2514eda14cbcSMatt Macy ASSERT(os->os_encrypted); 2515eda14cbcSMatt Macy 2516eda14cbcSMatt Macy err = dsl_crypto_populate_key_nvlist(os, ivset_guid, 2517eda14cbcSMatt Macy &keynvl); 2518eda14cbcSMatt Macy if (err != 0) { 2519eda14cbcSMatt Macy fnvlist_free(nvl); 2520eda14cbcSMatt Macy goto out; 2521eda14cbcSMatt Macy } 2522eda14cbcSMatt Macy 2523eda14cbcSMatt Macy fnvlist_add_nvlist(nvl, "crypt_keydata", keynvl); 2524eda14cbcSMatt Macy fnvlist_free(keynvl); 2525eda14cbcSMatt Macy } 2526eda14cbcSMatt Macy 2527eda14cbcSMatt Macy if (!nvlist_empty(nvl)) { 2528eda14cbcSMatt Macy payload = fnvlist_pack(nvl, &payload_len); 2529eda14cbcSMatt Macy drr->drr_payloadlen = payload_len; 2530eda14cbcSMatt Macy } 2531eda14cbcSMatt Macy 2532eda14cbcSMatt Macy fnvlist_free(nvl); 2533eda14cbcSMatt Macy err = dump_record(&dsc, payload, payload_len); 2534eda14cbcSMatt Macy fnvlist_pack_free(payload, payload_len); 2535eda14cbcSMatt Macy if (err != 0) { 2536eda14cbcSMatt Macy err = dsc.dsc_err; 2537eda14cbcSMatt Macy goto out; 2538eda14cbcSMatt Macy } 2539eda14cbcSMatt Macy 2540eda14cbcSMatt Macy setup_to_thread(to_arg, os, dssp, fromtxg, dspp->rawok); 2541eda14cbcSMatt Macy setup_from_thread(from_arg, from_rl, dssp); 2542eda14cbcSMatt Macy setup_redact_list_thread(rlt_arg, dspp, redact_rl, dssp); 2543eda14cbcSMatt Macy setup_merge_thread(smt_arg, dspp, from_arg, to_arg, rlt_arg, os); 2544eda14cbcSMatt Macy setup_reader_thread(srt_arg, dspp, smt_arg, featureflags); 2545eda14cbcSMatt Macy 2546eda14cbcSMatt Macy range = bqueue_dequeue(&srt_arg->q); 2547eda14cbcSMatt Macy while (err == 0 && !range->eos_marker) { 2548eda14cbcSMatt Macy err = do_dump(&dsc, range); 2549eda14cbcSMatt Macy range = get_next_range(&srt_arg->q, range); 2550eda14cbcSMatt Macy if (issig(JUSTLOOKING) && issig(FORREAL)) 2551eda14cbcSMatt Macy err = SET_ERROR(EINTR); 2552eda14cbcSMatt Macy } 2553eda14cbcSMatt Macy 2554eda14cbcSMatt Macy /* 2555eda14cbcSMatt Macy * If we hit an error or are interrupted, cancel our worker threads and 2556eda14cbcSMatt Macy * clear the queue of any pending records. The threads will pass the 2557eda14cbcSMatt Macy * cancel up the tree of worker threads, and each one will clean up any 2558eda14cbcSMatt Macy * pending records before exiting. 2559eda14cbcSMatt Macy */ 2560eda14cbcSMatt Macy if (err != 0) { 2561eda14cbcSMatt Macy srt_arg->cancel = B_TRUE; 2562eda14cbcSMatt Macy while (!range->eos_marker) { 2563eda14cbcSMatt Macy range = get_next_range(&srt_arg->q, range); 2564eda14cbcSMatt Macy } 2565eda14cbcSMatt Macy } 2566eda14cbcSMatt Macy range_free(range); 2567eda14cbcSMatt Macy 2568eda14cbcSMatt Macy bqueue_destroy(&srt_arg->q); 2569eda14cbcSMatt Macy bqueue_destroy(&smt_arg->q); 2570eda14cbcSMatt Macy if (dspp->redactbook != NULL) 2571eda14cbcSMatt Macy bqueue_destroy(&rlt_arg->q); 2572eda14cbcSMatt Macy bqueue_destroy(&to_arg->q); 2573eda14cbcSMatt Macy bqueue_destroy(&from_arg->q); 2574eda14cbcSMatt Macy 2575eda14cbcSMatt Macy if (err == 0 && srt_arg->error != 0) 2576eda14cbcSMatt Macy err = srt_arg->error; 2577eda14cbcSMatt Macy 2578eda14cbcSMatt Macy if (err != 0) 2579eda14cbcSMatt Macy goto out; 2580eda14cbcSMatt Macy 2581eda14cbcSMatt Macy if (dsc.dsc_pending_op != PENDING_NONE) 2582eda14cbcSMatt Macy if (dump_record(&dsc, NULL, 0) != 0) 2583eda14cbcSMatt Macy err = SET_ERROR(EINTR); 2584eda14cbcSMatt Macy 2585eda14cbcSMatt Macy if (err != 0) { 2586eda14cbcSMatt Macy if (err == EINTR && dsc.dsc_err != 0) 2587eda14cbcSMatt Macy err = dsc.dsc_err; 2588eda14cbcSMatt Macy goto out; 2589eda14cbcSMatt Macy } 2590eda14cbcSMatt Macy 2591eda14cbcSMatt Macy /* 2592eda14cbcSMatt Macy * Send the DRR_END record if this is not a saved stream. 2593eda14cbcSMatt Macy * Otherwise, the omitted DRR_END record will signal to 2594eda14cbcSMatt Macy * the receive side that the stream is incomplete. 2595eda14cbcSMatt Macy */ 2596eda14cbcSMatt Macy if (!dspp->savedok) { 2597eda14cbcSMatt Macy bzero(drr, sizeof (dmu_replay_record_t)); 2598eda14cbcSMatt Macy drr->drr_type = DRR_END; 2599eda14cbcSMatt Macy drr->drr_u.drr_end.drr_checksum = dsc.dsc_zc; 2600eda14cbcSMatt Macy drr->drr_u.drr_end.drr_toguid = dsc.dsc_toguid; 2601eda14cbcSMatt Macy 2602eda14cbcSMatt Macy if (dump_record(&dsc, NULL, 0) != 0) 2603eda14cbcSMatt Macy err = dsc.dsc_err; 2604eda14cbcSMatt Macy } 2605eda14cbcSMatt Macy out: 2606eda14cbcSMatt Macy mutex_enter(&to_ds->ds_sendstream_lock); 2607eda14cbcSMatt Macy list_remove(&to_ds->ds_sendstreams, dssp); 2608eda14cbcSMatt Macy mutex_exit(&to_ds->ds_sendstream_lock); 2609eda14cbcSMatt Macy 2610eda14cbcSMatt Macy VERIFY(err != 0 || (dsc.dsc_sent_begin && 2611eda14cbcSMatt Macy (dsc.dsc_sent_end || dspp->savedok))); 2612eda14cbcSMatt Macy 2613eda14cbcSMatt Macy kmem_free(drr, sizeof (dmu_replay_record_t)); 2614eda14cbcSMatt Macy kmem_free(dssp, sizeof (dmu_sendstatus_t)); 2615eda14cbcSMatt Macy kmem_free(from_arg, sizeof (*from_arg)); 2616eda14cbcSMatt Macy kmem_free(to_arg, sizeof (*to_arg)); 2617eda14cbcSMatt Macy kmem_free(rlt_arg, sizeof (*rlt_arg)); 2618eda14cbcSMatt Macy kmem_free(smt_arg, sizeof (*smt_arg)); 2619eda14cbcSMatt Macy kmem_free(srt_arg, sizeof (*srt_arg)); 2620eda14cbcSMatt Macy 2621eda14cbcSMatt Macy dsl_dataset_long_rele(to_ds, FTAG); 2622eda14cbcSMatt Macy if (from_rl != NULL) { 2623eda14cbcSMatt Macy dsl_redaction_list_long_rele(from_rl, FTAG); 2624eda14cbcSMatt Macy dsl_redaction_list_rele(from_rl, FTAG); 2625eda14cbcSMatt Macy } 2626eda14cbcSMatt Macy if (redact_rl != NULL) { 2627eda14cbcSMatt Macy dsl_redaction_list_long_rele(redact_rl, FTAG); 2628eda14cbcSMatt Macy dsl_redaction_list_rele(redact_rl, FTAG); 2629eda14cbcSMatt Macy } 2630eda14cbcSMatt Macy 2631eda14cbcSMatt Macy return (err); 2632eda14cbcSMatt Macy } 2633eda14cbcSMatt Macy 2634eda14cbcSMatt Macy int 2635eda14cbcSMatt Macy dmu_send_obj(const char *pool, uint64_t tosnap, uint64_t fromsnap, 2636eda14cbcSMatt Macy boolean_t embedok, boolean_t large_block_ok, boolean_t compressok, 2637eda14cbcSMatt Macy boolean_t rawok, boolean_t savedok, int outfd, offset_t *off, 2638eda14cbcSMatt Macy dmu_send_outparams_t *dsop) 2639eda14cbcSMatt Macy { 2640eda14cbcSMatt Macy int err; 2641eda14cbcSMatt Macy dsl_dataset_t *fromds; 26427877fdebSMatt Macy ds_hold_flags_t dsflags; 2643eda14cbcSMatt Macy struct dmu_send_params dspp = {0}; 2644eda14cbcSMatt Macy dspp.embedok = embedok; 2645eda14cbcSMatt Macy dspp.large_block_ok = large_block_ok; 2646eda14cbcSMatt Macy dspp.compressok = compressok; 2647eda14cbcSMatt Macy dspp.outfd = outfd; 2648eda14cbcSMatt Macy dspp.off = off; 2649eda14cbcSMatt Macy dspp.dso = dsop; 2650eda14cbcSMatt Macy dspp.tag = FTAG; 2651eda14cbcSMatt Macy dspp.rawok = rawok; 2652eda14cbcSMatt Macy dspp.savedok = savedok; 2653eda14cbcSMatt Macy 26547877fdebSMatt Macy dsflags = (rawok) ? DS_HOLD_FLAG_NONE : DS_HOLD_FLAG_DECRYPT; 2655eda14cbcSMatt Macy err = dsl_pool_hold(pool, FTAG, &dspp.dp); 2656eda14cbcSMatt Macy if (err != 0) 2657eda14cbcSMatt Macy return (err); 2658eda14cbcSMatt Macy 2659eda14cbcSMatt Macy err = dsl_dataset_hold_obj_flags(dspp.dp, tosnap, dsflags, FTAG, 2660eda14cbcSMatt Macy &dspp.to_ds); 2661eda14cbcSMatt Macy if (err != 0) { 2662eda14cbcSMatt Macy dsl_pool_rele(dspp.dp, FTAG); 2663eda14cbcSMatt Macy return (err); 2664eda14cbcSMatt Macy } 2665eda14cbcSMatt Macy 2666eda14cbcSMatt Macy if (fromsnap != 0) { 2667eda14cbcSMatt Macy err = dsl_dataset_hold_obj_flags(dspp.dp, fromsnap, dsflags, 2668eda14cbcSMatt Macy FTAG, &fromds); 2669eda14cbcSMatt Macy if (err != 0) { 2670eda14cbcSMatt Macy dsl_dataset_rele_flags(dspp.to_ds, dsflags, FTAG); 2671eda14cbcSMatt Macy dsl_pool_rele(dspp.dp, FTAG); 2672eda14cbcSMatt Macy return (err); 2673eda14cbcSMatt Macy } 2674eda14cbcSMatt Macy dspp.ancestor_zb.zbm_guid = dsl_dataset_phys(fromds)->ds_guid; 2675eda14cbcSMatt Macy dspp.ancestor_zb.zbm_creation_txg = 2676eda14cbcSMatt Macy dsl_dataset_phys(fromds)->ds_creation_txg; 2677eda14cbcSMatt Macy dspp.ancestor_zb.zbm_creation_time = 2678eda14cbcSMatt Macy dsl_dataset_phys(fromds)->ds_creation_time; 2679eda14cbcSMatt Macy 2680eda14cbcSMatt Macy if (dsl_dataset_is_zapified(fromds)) { 2681eda14cbcSMatt Macy (void) zap_lookup(dspp.dp->dp_meta_objset, 2682eda14cbcSMatt Macy fromds->ds_object, DS_FIELD_IVSET_GUID, 8, 1, 2683eda14cbcSMatt Macy &dspp.ancestor_zb.zbm_ivset_guid); 2684eda14cbcSMatt Macy } 2685eda14cbcSMatt Macy 2686eda14cbcSMatt Macy /* See dmu_send for the reasons behind this. */ 2687eda14cbcSMatt Macy uint64_t *fromredact; 2688eda14cbcSMatt Macy 2689eda14cbcSMatt Macy if (!dsl_dataset_get_uint64_array_feature(fromds, 2690eda14cbcSMatt Macy SPA_FEATURE_REDACTED_DATASETS, 2691eda14cbcSMatt Macy &dspp.numfromredactsnaps, 2692eda14cbcSMatt Macy &fromredact)) { 2693eda14cbcSMatt Macy dspp.numfromredactsnaps = NUM_SNAPS_NOT_REDACTED; 2694eda14cbcSMatt Macy } else if (dspp.numfromredactsnaps > 0) { 2695eda14cbcSMatt Macy uint64_t size = dspp.numfromredactsnaps * 2696eda14cbcSMatt Macy sizeof (uint64_t); 2697eda14cbcSMatt Macy dspp.fromredactsnaps = kmem_zalloc(size, KM_SLEEP); 2698eda14cbcSMatt Macy bcopy(fromredact, dspp.fromredactsnaps, size); 2699eda14cbcSMatt Macy } 2700eda14cbcSMatt Macy 2701c40487d4SMatt Macy boolean_t is_before = 2702c40487d4SMatt Macy dsl_dataset_is_before(dspp.to_ds, fromds, 0); 2703eda14cbcSMatt Macy dspp.is_clone = (dspp.to_ds->ds_dir != 2704eda14cbcSMatt Macy fromds->ds_dir); 2705eda14cbcSMatt Macy dsl_dataset_rele(fromds, FTAG); 2706c40487d4SMatt Macy if (!is_before) { 2707c40487d4SMatt Macy dsl_pool_rele(dspp.dp, FTAG); 2708c40487d4SMatt Macy err = SET_ERROR(EXDEV); 2709c40487d4SMatt Macy } else { 2710eda14cbcSMatt Macy err = dmu_send_impl(&dspp); 2711eda14cbcSMatt Macy } 2712eda14cbcSMatt Macy } else { 2713eda14cbcSMatt Macy dspp.numfromredactsnaps = NUM_SNAPS_NOT_REDACTED; 2714eda14cbcSMatt Macy err = dmu_send_impl(&dspp); 2715eda14cbcSMatt Macy } 2716eda14cbcSMatt Macy dsl_dataset_rele(dspp.to_ds, FTAG); 2717eda14cbcSMatt Macy return (err); 2718eda14cbcSMatt Macy } 2719eda14cbcSMatt Macy 2720eda14cbcSMatt Macy int 2721eda14cbcSMatt Macy dmu_send(const char *tosnap, const char *fromsnap, boolean_t embedok, 2722eda14cbcSMatt Macy boolean_t large_block_ok, boolean_t compressok, boolean_t rawok, 2723eda14cbcSMatt Macy boolean_t savedok, uint64_t resumeobj, uint64_t resumeoff, 2724eda14cbcSMatt Macy const char *redactbook, int outfd, offset_t *off, 2725eda14cbcSMatt Macy dmu_send_outparams_t *dsop) 2726eda14cbcSMatt Macy { 2727eda14cbcSMatt Macy int err = 0; 27287877fdebSMatt Macy ds_hold_flags_t dsflags; 2729eda14cbcSMatt Macy boolean_t owned = B_FALSE; 2730eda14cbcSMatt Macy dsl_dataset_t *fromds = NULL; 2731eda14cbcSMatt Macy zfs_bookmark_phys_t book = {0}; 2732eda14cbcSMatt Macy struct dmu_send_params dspp = {0}; 2733eda14cbcSMatt Macy 27347877fdebSMatt Macy dsflags = (rawok) ? DS_HOLD_FLAG_NONE : DS_HOLD_FLAG_DECRYPT; 2735eda14cbcSMatt Macy dspp.tosnap = tosnap; 2736eda14cbcSMatt Macy dspp.embedok = embedok; 2737eda14cbcSMatt Macy dspp.large_block_ok = large_block_ok; 2738eda14cbcSMatt Macy dspp.compressok = compressok; 2739eda14cbcSMatt Macy dspp.outfd = outfd; 2740eda14cbcSMatt Macy dspp.off = off; 2741eda14cbcSMatt Macy dspp.dso = dsop; 2742eda14cbcSMatt Macy dspp.tag = FTAG; 2743eda14cbcSMatt Macy dspp.resumeobj = resumeobj; 2744eda14cbcSMatt Macy dspp.resumeoff = resumeoff; 2745eda14cbcSMatt Macy dspp.rawok = rawok; 2746eda14cbcSMatt Macy dspp.savedok = savedok; 2747eda14cbcSMatt Macy 2748eda14cbcSMatt Macy if (fromsnap != NULL && strpbrk(fromsnap, "@#") == NULL) 2749eda14cbcSMatt Macy return (SET_ERROR(EINVAL)); 2750eda14cbcSMatt Macy 2751eda14cbcSMatt Macy err = dsl_pool_hold(tosnap, FTAG, &dspp.dp); 2752eda14cbcSMatt Macy if (err != 0) 2753eda14cbcSMatt Macy return (err); 2754eda14cbcSMatt Macy 2755eda14cbcSMatt Macy if (strchr(tosnap, '@') == NULL && spa_writeable(dspp.dp->dp_spa)) { 2756eda14cbcSMatt Macy /* 2757eda14cbcSMatt Macy * We are sending a filesystem or volume. Ensure 2758eda14cbcSMatt Macy * that it doesn't change by owning the dataset. 2759eda14cbcSMatt Macy */ 2760eda14cbcSMatt Macy 2761eda14cbcSMatt Macy if (savedok) { 2762eda14cbcSMatt Macy /* 2763eda14cbcSMatt Macy * We are looking for the dataset that represents the 2764eda14cbcSMatt Macy * partially received send stream. If this stream was 2765eda14cbcSMatt Macy * received as a new snapshot of an existing dataset, 2766eda14cbcSMatt Macy * this will be saved in a hidden clone named 2767eda14cbcSMatt Macy * "<pool>/<dataset>/%recv". Otherwise, the stream 2768eda14cbcSMatt Macy * will be saved in the live dataset itself. In 2769eda14cbcSMatt Macy * either case we need to use dsl_dataset_own_force() 2770eda14cbcSMatt Macy * because the stream is marked as inconsistent, 2771eda14cbcSMatt Macy * which would normally make it unavailable to be 2772eda14cbcSMatt Macy * owned. 2773eda14cbcSMatt Macy */ 2774eda14cbcSMatt Macy char *name = kmem_asprintf("%s/%s", tosnap, 2775eda14cbcSMatt Macy recv_clone_name); 2776eda14cbcSMatt Macy err = dsl_dataset_own_force(dspp.dp, name, dsflags, 2777eda14cbcSMatt Macy FTAG, &dspp.to_ds); 2778eda14cbcSMatt Macy if (err == ENOENT) { 2779eda14cbcSMatt Macy err = dsl_dataset_own_force(dspp.dp, tosnap, 2780eda14cbcSMatt Macy dsflags, FTAG, &dspp.to_ds); 2781eda14cbcSMatt Macy } 2782eda14cbcSMatt Macy 2783eda14cbcSMatt Macy if (err == 0) { 2784eda14cbcSMatt Macy err = zap_lookup(dspp.dp->dp_meta_objset, 2785eda14cbcSMatt Macy dspp.to_ds->ds_object, 2786eda14cbcSMatt Macy DS_FIELD_RESUME_TOGUID, 8, 1, 2787eda14cbcSMatt Macy &dspp.saved_guid); 2788eda14cbcSMatt Macy } 2789eda14cbcSMatt Macy 2790eda14cbcSMatt Macy if (err == 0) { 2791eda14cbcSMatt Macy err = zap_lookup(dspp.dp->dp_meta_objset, 2792eda14cbcSMatt Macy dspp.to_ds->ds_object, 2793eda14cbcSMatt Macy DS_FIELD_RESUME_TONAME, 1, 2794eda14cbcSMatt Macy sizeof (dspp.saved_toname), 2795eda14cbcSMatt Macy dspp.saved_toname); 2796eda14cbcSMatt Macy } 2797eda14cbcSMatt Macy if (err != 0) 2798eda14cbcSMatt Macy dsl_dataset_disown(dspp.to_ds, dsflags, FTAG); 2799eda14cbcSMatt Macy 2800eda14cbcSMatt Macy kmem_strfree(name); 2801eda14cbcSMatt Macy } else { 2802eda14cbcSMatt Macy err = dsl_dataset_own(dspp.dp, tosnap, dsflags, 2803eda14cbcSMatt Macy FTAG, &dspp.to_ds); 2804eda14cbcSMatt Macy } 2805eda14cbcSMatt Macy owned = B_TRUE; 2806eda14cbcSMatt Macy } else { 2807eda14cbcSMatt Macy err = dsl_dataset_hold_flags(dspp.dp, tosnap, dsflags, FTAG, 2808eda14cbcSMatt Macy &dspp.to_ds); 2809eda14cbcSMatt Macy } 2810eda14cbcSMatt Macy 2811eda14cbcSMatt Macy if (err != 0) { 2812eda14cbcSMatt Macy dsl_pool_rele(dspp.dp, FTAG); 2813eda14cbcSMatt Macy return (err); 2814eda14cbcSMatt Macy } 2815eda14cbcSMatt Macy 2816eda14cbcSMatt Macy if (redactbook != NULL) { 2817eda14cbcSMatt Macy char path[ZFS_MAX_DATASET_NAME_LEN]; 2818eda14cbcSMatt Macy (void) strlcpy(path, tosnap, sizeof (path)); 2819eda14cbcSMatt Macy char *at = strchr(path, '@'); 2820eda14cbcSMatt Macy if (at == NULL) { 2821eda14cbcSMatt Macy err = EINVAL; 2822eda14cbcSMatt Macy } else { 2823eda14cbcSMatt Macy (void) snprintf(at, sizeof (path) - (at - path), "#%s", 2824eda14cbcSMatt Macy redactbook); 2825eda14cbcSMatt Macy err = dsl_bookmark_lookup(dspp.dp, path, 2826eda14cbcSMatt Macy NULL, &book); 2827eda14cbcSMatt Macy dspp.redactbook = &book; 2828eda14cbcSMatt Macy } 2829eda14cbcSMatt Macy } 2830eda14cbcSMatt Macy 2831eda14cbcSMatt Macy if (err != 0) { 2832eda14cbcSMatt Macy dsl_pool_rele(dspp.dp, FTAG); 2833eda14cbcSMatt Macy if (owned) 2834eda14cbcSMatt Macy dsl_dataset_disown(dspp.to_ds, dsflags, FTAG); 2835eda14cbcSMatt Macy else 2836eda14cbcSMatt Macy dsl_dataset_rele_flags(dspp.to_ds, dsflags, FTAG); 2837eda14cbcSMatt Macy return (err); 2838eda14cbcSMatt Macy } 2839eda14cbcSMatt Macy 2840eda14cbcSMatt Macy if (fromsnap != NULL) { 2841eda14cbcSMatt Macy zfs_bookmark_phys_t *zb = &dspp.ancestor_zb; 2842eda14cbcSMatt Macy int fsnamelen; 2843eda14cbcSMatt Macy if (strpbrk(tosnap, "@#") != NULL) 2844eda14cbcSMatt Macy fsnamelen = strpbrk(tosnap, "@#") - tosnap; 2845eda14cbcSMatt Macy else 2846eda14cbcSMatt Macy fsnamelen = strlen(tosnap); 2847eda14cbcSMatt Macy 2848eda14cbcSMatt Macy /* 2849eda14cbcSMatt Macy * If the fromsnap is in a different filesystem, then 2850eda14cbcSMatt Macy * mark the send stream as a clone. 2851eda14cbcSMatt Macy */ 2852eda14cbcSMatt Macy if (strncmp(tosnap, fromsnap, fsnamelen) != 0 || 2853eda14cbcSMatt Macy (fromsnap[fsnamelen] != '@' && 2854eda14cbcSMatt Macy fromsnap[fsnamelen] != '#')) { 2855eda14cbcSMatt Macy dspp.is_clone = B_TRUE; 2856eda14cbcSMatt Macy } 2857eda14cbcSMatt Macy 2858eda14cbcSMatt Macy if (strchr(fromsnap, '@') != NULL) { 2859eda14cbcSMatt Macy err = dsl_dataset_hold(dspp.dp, fromsnap, FTAG, 2860eda14cbcSMatt Macy &fromds); 2861eda14cbcSMatt Macy 2862eda14cbcSMatt Macy if (err != 0) { 2863eda14cbcSMatt Macy ASSERT3P(fromds, ==, NULL); 2864eda14cbcSMatt Macy } else { 2865eda14cbcSMatt Macy /* 2866eda14cbcSMatt Macy * We need to make a deep copy of the redact 2867eda14cbcSMatt Macy * snapshots of the from snapshot, because the 2868eda14cbcSMatt Macy * array will be freed when we evict from_ds. 2869eda14cbcSMatt Macy */ 2870eda14cbcSMatt Macy uint64_t *fromredact; 2871eda14cbcSMatt Macy if (!dsl_dataset_get_uint64_array_feature( 2872eda14cbcSMatt Macy fromds, SPA_FEATURE_REDACTED_DATASETS, 2873eda14cbcSMatt Macy &dspp.numfromredactsnaps, 2874eda14cbcSMatt Macy &fromredact)) { 2875eda14cbcSMatt Macy dspp.numfromredactsnaps = 2876eda14cbcSMatt Macy NUM_SNAPS_NOT_REDACTED; 2877eda14cbcSMatt Macy } else if (dspp.numfromredactsnaps > 0) { 2878eda14cbcSMatt Macy uint64_t size = 2879eda14cbcSMatt Macy dspp.numfromredactsnaps * 2880eda14cbcSMatt Macy sizeof (uint64_t); 2881eda14cbcSMatt Macy dspp.fromredactsnaps = kmem_zalloc(size, 2882eda14cbcSMatt Macy KM_SLEEP); 2883eda14cbcSMatt Macy bcopy(fromredact, dspp.fromredactsnaps, 2884eda14cbcSMatt Macy size); 2885eda14cbcSMatt Macy } 2886eda14cbcSMatt Macy if (!dsl_dataset_is_before(dspp.to_ds, fromds, 2887eda14cbcSMatt Macy 0)) { 2888eda14cbcSMatt Macy err = SET_ERROR(EXDEV); 2889eda14cbcSMatt Macy } else { 2890eda14cbcSMatt Macy zb->zbm_creation_txg = 2891eda14cbcSMatt Macy dsl_dataset_phys(fromds)-> 2892eda14cbcSMatt Macy ds_creation_txg; 2893eda14cbcSMatt Macy zb->zbm_creation_time = 2894eda14cbcSMatt Macy dsl_dataset_phys(fromds)-> 2895eda14cbcSMatt Macy ds_creation_time; 2896eda14cbcSMatt Macy zb->zbm_guid = 2897eda14cbcSMatt Macy dsl_dataset_phys(fromds)->ds_guid; 2898eda14cbcSMatt Macy zb->zbm_redaction_obj = 0; 2899eda14cbcSMatt Macy 2900eda14cbcSMatt Macy if (dsl_dataset_is_zapified(fromds)) { 2901eda14cbcSMatt Macy (void) zap_lookup( 2902eda14cbcSMatt Macy dspp.dp->dp_meta_objset, 2903eda14cbcSMatt Macy fromds->ds_object, 2904eda14cbcSMatt Macy DS_FIELD_IVSET_GUID, 8, 1, 2905eda14cbcSMatt Macy &zb->zbm_ivset_guid); 2906eda14cbcSMatt Macy } 2907eda14cbcSMatt Macy } 2908eda14cbcSMatt Macy dsl_dataset_rele(fromds, FTAG); 2909eda14cbcSMatt Macy } 2910eda14cbcSMatt Macy } else { 2911eda14cbcSMatt Macy dspp.numfromredactsnaps = NUM_SNAPS_NOT_REDACTED; 2912eda14cbcSMatt Macy err = dsl_bookmark_lookup(dspp.dp, fromsnap, dspp.to_ds, 2913eda14cbcSMatt Macy zb); 2914eda14cbcSMatt Macy if (err == EXDEV && zb->zbm_redaction_obj != 0 && 2915eda14cbcSMatt Macy zb->zbm_guid == 2916eda14cbcSMatt Macy dsl_dataset_phys(dspp.to_ds)->ds_guid) 2917eda14cbcSMatt Macy err = 0; 2918eda14cbcSMatt Macy } 2919eda14cbcSMatt Macy 2920eda14cbcSMatt Macy if (err == 0) { 2921eda14cbcSMatt Macy /* dmu_send_impl will call dsl_pool_rele for us. */ 2922eda14cbcSMatt Macy err = dmu_send_impl(&dspp); 2923eda14cbcSMatt Macy } else { 2924eda14cbcSMatt Macy dsl_pool_rele(dspp.dp, FTAG); 2925eda14cbcSMatt Macy } 2926eda14cbcSMatt Macy } else { 2927eda14cbcSMatt Macy dspp.numfromredactsnaps = NUM_SNAPS_NOT_REDACTED; 2928eda14cbcSMatt Macy err = dmu_send_impl(&dspp); 2929eda14cbcSMatt Macy } 2930eda14cbcSMatt Macy if (owned) 2931eda14cbcSMatt Macy dsl_dataset_disown(dspp.to_ds, dsflags, FTAG); 2932eda14cbcSMatt Macy else 2933eda14cbcSMatt Macy dsl_dataset_rele_flags(dspp.to_ds, dsflags, FTAG); 2934eda14cbcSMatt Macy return (err); 2935eda14cbcSMatt Macy } 2936eda14cbcSMatt Macy 2937eda14cbcSMatt Macy static int 2938eda14cbcSMatt Macy dmu_adjust_send_estimate_for_indirects(dsl_dataset_t *ds, uint64_t uncompressed, 2939eda14cbcSMatt Macy uint64_t compressed, boolean_t stream_compressed, uint64_t *sizep) 2940eda14cbcSMatt Macy { 2941eda14cbcSMatt Macy int err = 0; 2942eda14cbcSMatt Macy uint64_t size; 2943eda14cbcSMatt Macy /* 2944eda14cbcSMatt Macy * Assume that space (both on-disk and in-stream) is dominated by 2945eda14cbcSMatt Macy * data. We will adjust for indirect blocks and the copies property, 2946eda14cbcSMatt Macy * but ignore per-object space used (eg, dnodes and DRR_OBJECT records). 2947eda14cbcSMatt Macy */ 2948eda14cbcSMatt Macy 2949eda14cbcSMatt Macy uint64_t recordsize; 2950eda14cbcSMatt Macy uint64_t record_count; 2951eda14cbcSMatt Macy objset_t *os; 2952eda14cbcSMatt Macy VERIFY0(dmu_objset_from_ds(ds, &os)); 2953eda14cbcSMatt Macy 2954eda14cbcSMatt Macy /* Assume all (uncompressed) blocks are recordsize. */ 2955eda14cbcSMatt Macy if (zfs_override_estimate_recordsize != 0) { 2956eda14cbcSMatt Macy recordsize = zfs_override_estimate_recordsize; 2957eda14cbcSMatt Macy } else if (os->os_phys->os_type == DMU_OST_ZVOL) { 2958eda14cbcSMatt Macy err = dsl_prop_get_int_ds(ds, 2959eda14cbcSMatt Macy zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), &recordsize); 2960eda14cbcSMatt Macy } else { 2961eda14cbcSMatt Macy err = dsl_prop_get_int_ds(ds, 2962eda14cbcSMatt Macy zfs_prop_to_name(ZFS_PROP_RECORDSIZE), &recordsize); 2963eda14cbcSMatt Macy } 2964eda14cbcSMatt Macy if (err != 0) 2965eda14cbcSMatt Macy return (err); 2966eda14cbcSMatt Macy record_count = uncompressed / recordsize; 2967eda14cbcSMatt Macy 2968eda14cbcSMatt Macy /* 2969eda14cbcSMatt Macy * If we're estimating a send size for a compressed stream, use the 2970eda14cbcSMatt Macy * compressed data size to estimate the stream size. Otherwise, use the 2971eda14cbcSMatt Macy * uncompressed data size. 2972eda14cbcSMatt Macy */ 2973eda14cbcSMatt Macy size = stream_compressed ? compressed : uncompressed; 2974eda14cbcSMatt Macy 2975eda14cbcSMatt Macy /* 2976eda14cbcSMatt Macy * Subtract out approximate space used by indirect blocks. 2977eda14cbcSMatt Macy * Assume most space is used by data blocks (non-indirect, non-dnode). 2978eda14cbcSMatt Macy * Assume no ditto blocks or internal fragmentation. 2979eda14cbcSMatt Macy * 2980eda14cbcSMatt Macy * Therefore, space used by indirect blocks is sizeof(blkptr_t) per 2981eda14cbcSMatt Macy * block. 2982eda14cbcSMatt Macy */ 2983eda14cbcSMatt Macy size -= record_count * sizeof (blkptr_t); 2984eda14cbcSMatt Macy 2985eda14cbcSMatt Macy /* Add in the space for the record associated with each block. */ 2986eda14cbcSMatt Macy size += record_count * sizeof (dmu_replay_record_t); 2987eda14cbcSMatt Macy 2988eda14cbcSMatt Macy *sizep = size; 2989eda14cbcSMatt Macy 2990eda14cbcSMatt Macy return (0); 2991eda14cbcSMatt Macy } 2992eda14cbcSMatt Macy 2993eda14cbcSMatt Macy int 2994eda14cbcSMatt Macy dmu_send_estimate_fast(dsl_dataset_t *origds, dsl_dataset_t *fromds, 2995eda14cbcSMatt Macy zfs_bookmark_phys_t *frombook, boolean_t stream_compressed, 2996eda14cbcSMatt Macy boolean_t saved, uint64_t *sizep) 2997eda14cbcSMatt Macy { 2998eda14cbcSMatt Macy int err; 2999eda14cbcSMatt Macy dsl_dataset_t *ds = origds; 3000eda14cbcSMatt Macy uint64_t uncomp, comp; 3001eda14cbcSMatt Macy 3002eda14cbcSMatt Macy ASSERT(dsl_pool_config_held(origds->ds_dir->dd_pool)); 3003eda14cbcSMatt Macy ASSERT(fromds == NULL || frombook == NULL); 3004eda14cbcSMatt Macy 3005eda14cbcSMatt Macy /* 3006eda14cbcSMatt Macy * If this is a saved send we may actually be sending 3007eda14cbcSMatt Macy * from the %recv clone used for resuming. 3008eda14cbcSMatt Macy */ 3009eda14cbcSMatt Macy if (saved) { 3010eda14cbcSMatt Macy objset_t *mos = origds->ds_dir->dd_pool->dp_meta_objset; 3011eda14cbcSMatt Macy uint64_t guid; 3012eda14cbcSMatt Macy char dsname[ZFS_MAX_DATASET_NAME_LEN + 6]; 3013eda14cbcSMatt Macy 3014eda14cbcSMatt Macy dsl_dataset_name(origds, dsname); 3015eda14cbcSMatt Macy (void) strcat(dsname, "/"); 3016eda14cbcSMatt Macy (void) strcat(dsname, recv_clone_name); 3017eda14cbcSMatt Macy 3018eda14cbcSMatt Macy err = dsl_dataset_hold(origds->ds_dir->dd_pool, 3019eda14cbcSMatt Macy dsname, FTAG, &ds); 3020eda14cbcSMatt Macy if (err != ENOENT && err != 0) { 3021eda14cbcSMatt Macy return (err); 3022eda14cbcSMatt Macy } else if (err == ENOENT) { 3023eda14cbcSMatt Macy ds = origds; 3024eda14cbcSMatt Macy } 3025eda14cbcSMatt Macy 3026eda14cbcSMatt Macy /* check that this dataset has partially received data */ 3027eda14cbcSMatt Macy err = zap_lookup(mos, ds->ds_object, 3028eda14cbcSMatt Macy DS_FIELD_RESUME_TOGUID, 8, 1, &guid); 3029eda14cbcSMatt Macy if (err != 0) { 3030eda14cbcSMatt Macy err = SET_ERROR(err == ENOENT ? EINVAL : err); 3031eda14cbcSMatt Macy goto out; 3032eda14cbcSMatt Macy } 3033eda14cbcSMatt Macy 3034eda14cbcSMatt Macy err = zap_lookup(mos, ds->ds_object, 3035eda14cbcSMatt Macy DS_FIELD_RESUME_TONAME, 1, sizeof (dsname), dsname); 3036eda14cbcSMatt Macy if (err != 0) { 3037eda14cbcSMatt Macy err = SET_ERROR(err == ENOENT ? EINVAL : err); 3038eda14cbcSMatt Macy goto out; 3039eda14cbcSMatt Macy } 3040eda14cbcSMatt Macy } 3041eda14cbcSMatt Macy 3042eda14cbcSMatt Macy /* tosnap must be a snapshot or the target of a saved send */ 3043eda14cbcSMatt Macy if (!ds->ds_is_snapshot && ds == origds) 3044eda14cbcSMatt Macy return (SET_ERROR(EINVAL)); 3045eda14cbcSMatt Macy 3046eda14cbcSMatt Macy if (fromds != NULL) { 3047eda14cbcSMatt Macy uint64_t used; 3048eda14cbcSMatt Macy if (!fromds->ds_is_snapshot) { 3049eda14cbcSMatt Macy err = SET_ERROR(EINVAL); 3050eda14cbcSMatt Macy goto out; 3051eda14cbcSMatt Macy } 3052eda14cbcSMatt Macy 3053eda14cbcSMatt Macy if (!dsl_dataset_is_before(ds, fromds, 0)) { 3054eda14cbcSMatt Macy err = SET_ERROR(EXDEV); 3055eda14cbcSMatt Macy goto out; 3056eda14cbcSMatt Macy } 3057eda14cbcSMatt Macy 3058eda14cbcSMatt Macy err = dsl_dataset_space_written(fromds, ds, &used, &comp, 3059eda14cbcSMatt Macy &uncomp); 3060eda14cbcSMatt Macy if (err != 0) 3061eda14cbcSMatt Macy goto out; 3062eda14cbcSMatt Macy } else if (frombook != NULL) { 3063eda14cbcSMatt Macy uint64_t used; 3064eda14cbcSMatt Macy err = dsl_dataset_space_written_bookmark(frombook, ds, &used, 3065eda14cbcSMatt Macy &comp, &uncomp); 3066eda14cbcSMatt Macy if (err != 0) 3067eda14cbcSMatt Macy goto out; 3068eda14cbcSMatt Macy } else { 3069eda14cbcSMatt Macy uncomp = dsl_dataset_phys(ds)->ds_uncompressed_bytes; 3070eda14cbcSMatt Macy comp = dsl_dataset_phys(ds)->ds_compressed_bytes; 3071eda14cbcSMatt Macy } 3072eda14cbcSMatt Macy 3073eda14cbcSMatt Macy err = dmu_adjust_send_estimate_for_indirects(ds, uncomp, comp, 3074eda14cbcSMatt Macy stream_compressed, sizep); 3075eda14cbcSMatt Macy /* 3076eda14cbcSMatt Macy * Add the size of the BEGIN and END records to the estimate. 3077eda14cbcSMatt Macy */ 3078eda14cbcSMatt Macy *sizep += 2 * sizeof (dmu_replay_record_t); 3079eda14cbcSMatt Macy 3080eda14cbcSMatt Macy out: 3081eda14cbcSMatt Macy if (ds != origds) 3082eda14cbcSMatt Macy dsl_dataset_rele(ds, FTAG); 3083eda14cbcSMatt Macy return (err); 3084eda14cbcSMatt Macy } 3085eda14cbcSMatt Macy 3086eda14cbcSMatt Macy /* BEGIN CSTYLED */ 3087eda14cbcSMatt Macy ZFS_MODULE_PARAM(zfs_send, zfs_send_, corrupt_data, INT, ZMOD_RW, 3088eda14cbcSMatt Macy "Allow sending corrupt data"); 3089eda14cbcSMatt Macy 3090eda14cbcSMatt Macy ZFS_MODULE_PARAM(zfs_send, zfs_send_, queue_length, INT, ZMOD_RW, 3091eda14cbcSMatt Macy "Maximum send queue length"); 3092eda14cbcSMatt Macy 3093eda14cbcSMatt Macy ZFS_MODULE_PARAM(zfs_send, zfs_send_, unmodified_spill_blocks, INT, ZMOD_RW, 3094eda14cbcSMatt Macy "Send unmodified spill blocks"); 3095eda14cbcSMatt Macy 3096eda14cbcSMatt Macy ZFS_MODULE_PARAM(zfs_send, zfs_send_, no_prefetch_queue_length, INT, ZMOD_RW, 3097eda14cbcSMatt Macy "Maximum send queue length for non-prefetch queues"); 3098eda14cbcSMatt Macy 3099eda14cbcSMatt Macy ZFS_MODULE_PARAM(zfs_send, zfs_send_, queue_ff, INT, ZMOD_RW, 3100eda14cbcSMatt Macy "Send queue fill fraction"); 3101eda14cbcSMatt Macy 3102eda14cbcSMatt Macy ZFS_MODULE_PARAM(zfs_send, zfs_send_, no_prefetch_queue_ff, INT, ZMOD_RW, 3103eda14cbcSMatt Macy "Send queue fill fraction for non-prefetch queues"); 3104eda14cbcSMatt Macy 3105eda14cbcSMatt Macy ZFS_MODULE_PARAM(zfs_send, zfs_, override_estimate_recordsize, INT, ZMOD_RW, 3106eda14cbcSMatt Macy "Override block size estimate with fixed size"); 3107eda14cbcSMatt Macy /* END CSTYLED */ 3108