2025-01-04 03:04:27 +03:00
|
|
|
// SPDX-License-Identifier: CDDL-1.0
|
2010-08-27 01:24:34 +04:00
|
|
|
/*
|
|
|
|
|
* CDDL HEADER START
|
|
|
|
|
*
|
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
|
*
|
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
2022-07-12 00:16:13 +03:00
|
|
|
* or https://opensource.org/licenses/CDDL-1.0.
|
2010-08-27 01:24:34 +04:00
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
|
* and limitations under the License.
|
|
|
|
|
*
|
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
|
*
|
|
|
|
|
* CDDL HEADER END
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
Implement Redacted Send/Receive
Redacted send/receive allows users to send subsets of their data to
a target system. One possible use case for this feature is to not
transmit sensitive information to a data warehousing, test/dev, or
analytics environment. Another is to save space by not replicating
unimportant data within a given dataset, for example in backup tools
like zrepl.
Redacted send/receive is a three-stage process. First, a clone (or
clones) is made of the snapshot to be sent to the target. In this
clone (or clones), all unnecessary or unwanted data is removed or
modified. This clone is then snapshotted to create the "redaction
snapshot" (or snapshots). Second, the new zfs redact command is used
to create a redaction bookmark. The redaction bookmark stores the
list of blocks in a snapshot that were modified by the redaction
snapshot(s). Finally, the redaction bookmark is passed as a parameter
to zfs send. When sending to the snapshot that was redacted, the
redaction bookmark is used to filter out blocks that contain sensitive
or unwanted information, and those blocks are not included in the send
stream. When sending from the redaction bookmark, the blocks it
contains are considered as candidate blocks in addition to those
blocks in the destination snapshot that were modified since the
creation_txg of the redaction bookmark. This step is necessary to
allow the target to rehydrate data in the case where some blocks are
accidentally or unnecessarily modified in the redaction snapshot.
The changes to bookmarks to enable fast space estimation involve
adding deadlists to bookmarks. There is also logic to manage the
life cycles of these deadlists.
The new size estimation process operates in cases where previously
an accurate estimate could not be provided. In those cases, a send
is performed where no data blocks are read, reducing the runtime
significantly and providing a byte-accurate size estimate.
Reviewed-by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed-by: Matt Ahrens <mahrens@delphix.com>
Reviewed-by: Prashanth Sreenivasa <pks@delphix.com>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Chris Williamson <chris.williamson@delphix.com>
Reviewed-by: Pavel Zhakarov <pavel.zakharov@delphix.com>
Reviewed-by: Sebastien Roy <sebastien.roy@delphix.com>
Reviewed-by: Prakash Surya <prakash.surya@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #7958
2019-06-19 19:48:13 +03:00
|
|
|
* Copyright (c) 2012, 2018 by Delphix. All rights reserved.
|
2019-09-24 22:01:37 +03:00
|
|
|
* Copyright (c) 2019, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
|
2010-08-27 01:24:34 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <sys/dmu.h>
|
|
|
|
|
#include <sys/dmu_impl.h>
|
|
|
|
|
#include <sys/dmu_tx.h>
|
|
|
|
|
#include <sys/dbuf.h>
|
|
|
|
|
#include <sys/dnode.h>
|
|
|
|
|
#include <sys/zfs_context.h>
|
|
|
|
|
#include <sys/dmu_objset.h>
|
|
|
|
|
#include <sys/dmu_traverse.h>
|
|
|
|
|
#include <sys/dsl_dataset.h>
|
|
|
|
|
#include <sys/dsl_dir.h>
|
|
|
|
|
#include <sys/dsl_pool.h>
|
|
|
|
|
#include <sys/dsl_synctask.h>
|
|
|
|
|
#include <sys/zfs_ioctl.h>
|
|
|
|
|
#include <sys/zap.h>
|
|
|
|
|
#include <sys/zio_checksum.h>
|
|
|
|
|
#include <sys/zfs_znode.h>
|
2019-11-21 20:32:57 +03:00
|
|
|
#include <sys/zfs_file.h>
|
2010-08-27 01:24:34 +04:00
|
|
|
|
2019-11-21 20:32:57 +03:00
|
|
|
|
|
|
|
|
typedef struct dmu_diffarg {
|
|
|
|
|
zfs_file_t *da_fp; /* file to which we are reporting */
|
2010-08-27 01:24:34 +04:00
|
|
|
offset_t *da_offp;
|
|
|
|
|
int da_err; /* error that stopped diff search */
|
|
|
|
|
dmu_diff_record_t da_ddr;
|
2019-11-21 20:32:57 +03:00
|
|
|
} dmu_diffarg_t;
|
2010-08-27 01:24:34 +04:00
|
|
|
|
2019-12-03 20:51:44 +03:00
|
|
|
static int
|
2019-11-21 20:32:57 +03:00
|
|
|
write_record(dmu_diffarg_t *da)
|
2010-08-27 01:24:34 +04:00
|
|
|
{
|
2019-11-21 20:32:57 +03:00
|
|
|
zfs_file_t *fp;
|
|
|
|
|
ssize_t resid;
|
2010-08-27 01:24:34 +04:00
|
|
|
|
|
|
|
|
if (da->da_ddr.ddr_type == DDR_NONE) {
|
|
|
|
|
da->da_err = 0;
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-21 20:32:57 +03:00
|
|
|
fp = da->da_fp;
|
|
|
|
|
da->da_err = zfs_file_write(fp, (caddr_t)&da->da_ddr,
|
|
|
|
|
sizeof (da->da_ddr), &resid);
|
2010-08-27 01:24:34 +04:00
|
|
|
*da->da_offp += sizeof (da->da_ddr);
|
|
|
|
|
return (da->da_err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2019-11-21 20:32:57 +03:00
|
|
|
report_free_dnode_range(dmu_diffarg_t *da, uint64_t first, uint64_t last)
|
2010-08-27 01:24:34 +04:00
|
|
|
{
|
|
|
|
|
ASSERT(first <= last);
|
|
|
|
|
if (da->da_ddr.ddr_type != DDR_FREE ||
|
|
|
|
|
first != da->da_ddr.ddr_last + 1) {
|
|
|
|
|
if (write_record(da) != 0)
|
|
|
|
|
return (da->da_err);
|
|
|
|
|
da->da_ddr.ddr_type = DDR_FREE;
|
|
|
|
|
da->da_ddr.ddr_first = first;
|
|
|
|
|
da->da_ddr.ddr_last = last;
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
da->da_ddr.ddr_last = last;
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2019-11-21 20:32:57 +03:00
|
|
|
report_dnode(dmu_diffarg_t *da, uint64_t object, dnode_phys_t *dnp)
|
2010-08-27 01:24:34 +04:00
|
|
|
{
|
|
|
|
|
ASSERT(dnp != NULL);
|
|
|
|
|
if (dnp->dn_type == DMU_OT_NONE)
|
|
|
|
|
return (report_free_dnode_range(da, object, object));
|
|
|
|
|
|
|
|
|
|
if (da->da_ddr.ddr_type != DDR_INUSE ||
|
|
|
|
|
object != da->da_ddr.ddr_last + 1) {
|
|
|
|
|
if (write_record(da) != 0)
|
|
|
|
|
return (da->da_err);
|
|
|
|
|
da->da_ddr.ddr_type = DDR_INUSE;
|
|
|
|
|
da->da_ddr.ddr_first = da->da_ddr.ddr_last = object;
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
da->da_ddr.ddr_last = object;
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define DBP_SPAN(dnp, level) \
|
|
|
|
|
(((uint64_t)dnp->dn_datablkszsec) << (SPA_MINBLOCKSHIFT + \
|
|
|
|
|
(level) * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT)))
|
|
|
|
|
|
|
|
|
|
static int
|
2013-07-03 00:26:24 +04:00
|
|
|
diff_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
|
2014-06-25 22:37:59 +04:00
|
|
|
const zbookmark_phys_t *zb, const dnode_phys_t *dnp, void *arg)
|
2010-08-27 01:24:34 +04:00
|
|
|
{
|
2021-12-12 18:06:44 +03:00
|
|
|
(void) zilog;
|
2019-11-21 20:32:57 +03:00
|
|
|
dmu_diffarg_t *da = arg;
|
2010-08-27 01:24:34 +04:00
|
|
|
int err = 0;
|
|
|
|
|
|
2024-05-29 20:49:11 +03:00
|
|
|
if (issig())
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(EINTR));
|
2010-08-27 01:24:34 +04:00
|
|
|
|
Implement Redacted Send/Receive
Redacted send/receive allows users to send subsets of their data to
a target system. One possible use case for this feature is to not
transmit sensitive information to a data warehousing, test/dev, or
analytics environment. Another is to save space by not replicating
unimportant data within a given dataset, for example in backup tools
like zrepl.
Redacted send/receive is a three-stage process. First, a clone (or
clones) is made of the snapshot to be sent to the target. In this
clone (or clones), all unnecessary or unwanted data is removed or
modified. This clone is then snapshotted to create the "redaction
snapshot" (or snapshots). Second, the new zfs redact command is used
to create a redaction bookmark. The redaction bookmark stores the
list of blocks in a snapshot that were modified by the redaction
snapshot(s). Finally, the redaction bookmark is passed as a parameter
to zfs send. When sending to the snapshot that was redacted, the
redaction bookmark is used to filter out blocks that contain sensitive
or unwanted information, and those blocks are not included in the send
stream. When sending from the redaction bookmark, the blocks it
contains are considered as candidate blocks in addition to those
blocks in the destination snapshot that were modified since the
creation_txg of the redaction bookmark. This step is necessary to
allow the target to rehydrate data in the case where some blocks are
accidentally or unnecessarily modified in the redaction snapshot.
The changes to bookmarks to enable fast space estimation involve
adding deadlists to bookmarks. There is also logic to manage the
life cycles of these deadlists.
The new size estimation process operates in cases where previously
an accurate estimate could not be provided. In those cases, a send
is performed where no data blocks are read, reducing the runtime
significantly and providing a byte-accurate size estimate.
Reviewed-by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed-by: Matt Ahrens <mahrens@delphix.com>
Reviewed-by: Prashanth Sreenivasa <pks@delphix.com>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Chris Williamson <chris.williamson@delphix.com>
Reviewed-by: Pavel Zhakarov <pavel.zakharov@delphix.com>
Reviewed-by: Sebastien Roy <sebastien.roy@delphix.com>
Reviewed-by: Prakash Surya <prakash.surya@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #7958
2019-06-19 19:48:13 +03:00
|
|
|
if (zb->zb_level == ZB_DNODE_LEVEL ||
|
|
|
|
|
zb->zb_object != DMU_META_DNODE_OBJECT)
|
2010-08-27 01:24:34 +04:00
|
|
|
return (0);
|
|
|
|
|
|
2013-12-09 22:37:51 +04:00
|
|
|
if (BP_IS_HOLE(bp)) {
|
2010-08-27 01:24:34 +04:00
|
|
|
uint64_t span = DBP_SPAN(dnp, zb->zb_level);
|
|
|
|
|
uint64_t dnobj = (zb->zb_blkid * span) >> DNODE_SHIFT;
|
|
|
|
|
|
|
|
|
|
err = report_free_dnode_range(da, dnobj,
|
|
|
|
|
dnobj + (span >> DNODE_SHIFT) - 1);
|
|
|
|
|
if (err)
|
|
|
|
|
return (err);
|
|
|
|
|
} else if (zb->zb_level == 0) {
|
|
|
|
|
dnode_phys_t *blk;
|
|
|
|
|
arc_buf_t *abuf;
|
2014-12-06 20:24:32 +03:00
|
|
|
arc_flags_t aflags = ARC_FLAG_WAIT;
|
2019-09-24 22:01:37 +03:00
|
|
|
int epb = BP_GET_LSIZE(bp) >> DNODE_SHIFT;
|
2018-05-01 21:24:20 +03:00
|
|
|
int zio_flags = ZIO_FLAG_CANFAIL;
|
2010-08-27 01:24:34 +04:00
|
|
|
int i;
|
|
|
|
|
|
2018-05-01 21:24:20 +03:00
|
|
|
if (BP_IS_PROTECTED(bp))
|
|
|
|
|
zio_flags |= ZIO_FLAG_RAW;
|
|
|
|
|
|
2013-07-03 00:26:24 +04:00
|
|
|
if (arc_read(NULL, spa, bp, arc_getbuf_func, &abuf,
|
2018-05-01 21:24:20 +03:00
|
|
|
ZIO_PRIORITY_ASYNC_READ, zio_flags, &aflags, zb) != 0)
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(EIO));
|
2010-08-27 01:24:34 +04:00
|
|
|
|
|
|
|
|
blk = abuf->b_data;
|
2019-09-24 22:01:37 +03:00
|
|
|
for (i = 0; i < epb; i += blk[i].dn_extra_slots + 1) {
|
2010-08-27 01:24:34 +04:00
|
|
|
uint64_t dnobj = (zb->zb_blkid <<
|
|
|
|
|
(DNODE_BLOCK_SHIFT - DNODE_SHIFT)) + i;
|
|
|
|
|
err = report_dnode(da, dnobj, blk+i);
|
|
|
|
|
if (err)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-06-02 07:04:53 +03:00
|
|
|
arc_buf_destroy(abuf, &abuf);
|
2010-08-27 01:24:34 +04:00
|
|
|
if (err)
|
|
|
|
|
return (err);
|
|
|
|
|
/* Don't care about the data blocks */
|
|
|
|
|
return (TRAVERSE_VISIT_NO_CHILDREN);
|
|
|
|
|
}
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2013-09-04 16:00:57 +04:00
|
|
|
dmu_diff(const char *tosnap_name, const char *fromsnap_name,
|
2019-11-21 20:32:57 +03:00
|
|
|
zfs_file_t *fp, offset_t *offp)
|
2010-08-27 01:24:34 +04:00
|
|
|
{
|
2019-11-21 20:32:57 +03:00
|
|
|
dmu_diffarg_t da;
|
2013-09-04 16:00:57 +04:00
|
|
|
dsl_dataset_t *fromsnap;
|
|
|
|
|
dsl_dataset_t *tosnap;
|
|
|
|
|
dsl_pool_t *dp;
|
|
|
|
|
int error;
|
|
|
|
|
uint64_t fromtxg;
|
|
|
|
|
|
|
|
|
|
if (strchr(tosnap_name, '@') == NULL ||
|
|
|
|
|
strchr(fromsnap_name, '@') == NULL)
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(EINVAL));
|
2010-08-27 01:24:34 +04:00
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
error = dsl_pool_hold(tosnap_name, FTAG, &dp);
|
|
|
|
|
if (error != 0)
|
|
|
|
|
return (error);
|
2010-08-27 01:24:34 +04:00
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
error = dsl_dataset_hold(dp, tosnap_name, FTAG, &tosnap);
|
|
|
|
|
if (error != 0) {
|
|
|
|
|
dsl_pool_rele(dp, FTAG);
|
|
|
|
|
return (error);
|
|
|
|
|
}
|
2010-08-27 01:24:34 +04:00
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
error = dsl_dataset_hold(dp, fromsnap_name, FTAG, &fromsnap);
|
|
|
|
|
if (error != 0) {
|
|
|
|
|
dsl_dataset_rele(tosnap, FTAG);
|
|
|
|
|
dsl_pool_rele(dp, FTAG);
|
|
|
|
|
return (error);
|
|
|
|
|
}
|
2010-08-27 01:24:34 +04:00
|
|
|
|
2013-12-12 02:33:41 +04:00
|
|
|
if (!dsl_dataset_is_before(tosnap, fromsnap, 0)) {
|
2013-09-04 16:00:57 +04:00
|
|
|
dsl_dataset_rele(fromsnap, FTAG);
|
|
|
|
|
dsl_dataset_rele(tosnap, FTAG);
|
|
|
|
|
dsl_pool_rele(dp, FTAG);
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(EXDEV));
|
2010-08-27 01:24:34 +04:00
|
|
|
}
|
|
|
|
|
|
2015-04-01 18:14:34 +03:00
|
|
|
fromtxg = dsl_dataset_phys(fromsnap)->ds_creation_txg;
|
2013-09-04 16:00:57 +04:00
|
|
|
dsl_dataset_rele(fromsnap, FTAG);
|
|
|
|
|
|
|
|
|
|
dsl_dataset_long_hold(tosnap, FTAG);
|
|
|
|
|
dsl_pool_rele(dp, FTAG);
|
2010-08-27 01:24:34 +04:00
|
|
|
|
2019-11-21 20:32:57 +03:00
|
|
|
da.da_fp = fp;
|
2010-08-27 01:24:34 +04:00
|
|
|
da.da_offp = offp;
|
|
|
|
|
da.da_ddr.ddr_type = DDR_NONE;
|
|
|
|
|
da.da_ddr.ddr_first = da.da_ddr.ddr_last = 0;
|
|
|
|
|
da.da_err = 0;
|
|
|
|
|
|
2018-05-01 21:24:20 +03:00
|
|
|
/*
|
|
|
|
|
* Since zfs diff only looks at dnodes which are stored in plaintext
|
|
|
|
|
* (other than bonus buffers), we don't technically need to decrypt
|
|
|
|
|
* the dataset to perform this operation. However, the command line
|
|
|
|
|
* utility will still fail if the keys are not loaded because the
|
|
|
|
|
* dataset isn't mounted and because it will fail when it attempts to
|
|
|
|
|
* call the ZFS_IOC_OBJ_TO_STATS ioctl.
|
|
|
|
|
*/
|
2013-09-04 16:00:57 +04:00
|
|
|
error = traverse_dataset(tosnap, fromtxg,
|
Allow physical rewrite without logical
During regular block writes ZFS sets both logical and physical
birth times equal to the current TXG. During dedup and block
cloning logical birth time is still set to the current TXG, but
physical may be copied from the original block that was used.
This represents the fact that logically user data has changed,
but the physically it is the same old block.
But block rewrite introduces a new situation, when block is not
changed logically, but stored in a different place of the pool.
From ARC, scrub and some other perspectives this is a new block,
but for example for user applications or incremental replication
it is not. Somewhat similar thing happen during remap phase of
device removal, but in that case space blocks are still acounted
as allocated at their logical birth times.
This patch introduces a new "rewrite" flag in the block pointer
structure, allowing to differentiate physical rewrite (when the
block is actually reallocated at the physical birth time) from
the device reval case (when the logical birth time is used).
The new functionality is not used at this point, and the only
expected change is that error log is now kept in terms of physical
physical birth times, rather than logical, since if a block with
logged error was somehow rewritten, then the previous error does
not matter any more.
This change also introduces a new TRAVERSE_LOGICAL flag to the
traverse code, allowing zfs send, redact and diff to work in
context of logical birth times, ignoring physical-only rewrites.
It also changes nothing at this point due to lack of those writes,
but they will come in a following patch.
Reviewed-by: Rob Norris <robn@despairlabs.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alexander Motin <alexander.motin@TrueNAS.com>
Closes #17565
2025-07-17 19:50:54 +03:00
|
|
|
TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA | TRAVERSE_NO_DECRYPT |
|
|
|
|
|
TRAVERSE_LOGICAL, diff_cb, &da);
|
2010-08-27 01:24:34 +04:00
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
if (error != 0) {
|
|
|
|
|
da.da_err = error;
|
2010-08-27 01:24:34 +04:00
|
|
|
} else {
|
|
|
|
|
/* we set the da.da_err we return as side-effect */
|
|
|
|
|
(void) write_record(&da);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
dsl_dataset_long_rele(tosnap, FTAG);
|
|
|
|
|
dsl_dataset_rele(tosnap, FTAG);
|
|
|
|
|
|
2010-08-27 01:24:34 +04:00
|
|
|
return (da.da_err);
|
|
|
|
|
}
|