2012-12-14 03:24:15 +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
|
|
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
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) 2011, 2018 by Delphix. All rights reserved.
|
2012-12-14 03:24:15 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/arc.h>
|
|
|
|
#include <sys/bptree.h>
|
|
|
|
#include <sys/dmu.h>
|
|
|
|
#include <sys/dmu_objset.h>
|
|
|
|
#include <sys/dmu_tx.h>
|
|
|
|
#include <sys/dmu_traverse.h>
|
|
|
|
#include <sys/dsl_dataset.h>
|
|
|
|
#include <sys/dsl_dir.h>
|
|
|
|
#include <sys/dsl_pool.h>
|
|
|
|
#include <sys/dnode.h>
|
|
|
|
#include <sys/spa.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A bptree is a queue of root block pointers from destroyed datasets. When a
|
|
|
|
* dataset is destroyed its root block pointer is put on the end of the pool's
|
|
|
|
* bptree queue so the dataset's blocks can be freed asynchronously by
|
|
|
|
* dsl_scan_sync. This allows the delete operation to finish without traversing
|
|
|
|
* all the dataset's blocks.
|
|
|
|
*
|
2013-06-11 21:12:34 +04:00
|
|
|
* Note that while bt_begin and bt_end are only ever incremented in this code,
|
2012-12-14 03:24:15 +04:00
|
|
|
* they are effectively reset to 0 every time the entire bptree is freed because
|
|
|
|
* the bptree's object is destroyed and re-created.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct bptree_args {
|
|
|
|
bptree_phys_t *ba_phys; /* data in bonus buffer, dirtied if freeing */
|
|
|
|
boolean_t ba_free; /* true if freeing during traversal */
|
|
|
|
|
|
|
|
bptree_itor_t *ba_func; /* function to call for each blockpointer */
|
|
|
|
void *ba_arg; /* caller supplied argument to ba_func */
|
|
|
|
dmu_tx_t *ba_tx; /* caller supplied tx, NULL if not freeing */
|
|
|
|
} bptree_args_t;
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
bptree_alloc(objset_t *os, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
uint64_t obj;
|
|
|
|
dmu_buf_t *db;
|
|
|
|
bptree_phys_t *bt;
|
|
|
|
|
|
|
|
obj = dmu_object_alloc(os, DMU_OTN_UINT64_METADATA,
|
2014-11-03 23:15:08 +03:00
|
|
|
SPA_OLD_MAXBLOCKSIZE, DMU_OTN_UINT64_METADATA,
|
2012-12-14 03:24:15 +04:00
|
|
|
sizeof (bptree_phys_t), tx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bonus buffer contents are already initialized to 0, but for
|
|
|
|
* readability we make it explicit.
|
|
|
|
*/
|
|
|
|
VERIFY3U(0, ==, dmu_bonus_hold(os, obj, FTAG, &db));
|
|
|
|
dmu_buf_will_dirty(db, tx);
|
|
|
|
bt = db->db_data;
|
|
|
|
bt->bt_begin = 0;
|
|
|
|
bt->bt_end = 0;
|
|
|
|
bt->bt_bytes = 0;
|
|
|
|
bt->bt_comp = 0;
|
|
|
|
bt->bt_uncomp = 0;
|
|
|
|
dmu_buf_rele(db, FTAG);
|
|
|
|
|
|
|
|
return (obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
bptree_free(objset_t *os, uint64_t obj, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
dmu_buf_t *db;
|
|
|
|
bptree_phys_t *bt;
|
|
|
|
|
|
|
|
VERIFY3U(0, ==, dmu_bonus_hold(os, obj, FTAG, &db));
|
|
|
|
bt = db->db_data;
|
|
|
|
ASSERT3U(bt->bt_begin, ==, bt->bt_end);
|
2013-05-11 01:17:03 +04:00
|
|
|
ASSERT0(bt->bt_bytes);
|
|
|
|
ASSERT0(bt->bt_comp);
|
|
|
|
ASSERT0(bt->bt_uncomp);
|
2012-12-14 03:24:15 +04:00
|
|
|
dmu_buf_rele(db, FTAG);
|
|
|
|
|
|
|
|
return (dmu_object_free(os, obj, tx));
|
|
|
|
}
|
|
|
|
|
2014-06-06 01:20:08 +04:00
|
|
|
boolean_t
|
|
|
|
bptree_is_empty(objset_t *os, uint64_t obj)
|
|
|
|
{
|
|
|
|
dmu_buf_t *db;
|
|
|
|
bptree_phys_t *bt;
|
|
|
|
boolean_t rv;
|
|
|
|
|
|
|
|
VERIFY0(dmu_bonus_hold(os, obj, FTAG, &db));
|
|
|
|
bt = db->db_data;
|
|
|
|
rv = (bt->bt_begin == bt->bt_end);
|
|
|
|
dmu_buf_rele(db, FTAG);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2012-12-14 03:24:15 +04:00
|
|
|
void
|
|
|
|
bptree_add(objset_t *os, uint64_t obj, blkptr_t *bp, uint64_t birth_txg,
|
|
|
|
uint64_t bytes, uint64_t comp, uint64_t uncomp, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
dmu_buf_t *db;
|
|
|
|
bptree_phys_t *bt;
|
2014-06-06 01:20:08 +04:00
|
|
|
bptree_entry_phys_t *bte;
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* bptree objects are in the pool mos, therefore they can only be
|
|
|
|
* modified in syncing context. Furthermore, this is only modified
|
|
|
|
* by the sync thread, so no locking is necessary.
|
|
|
|
*/
|
|
|
|
ASSERT(dmu_tx_is_syncing(tx));
|
|
|
|
|
|
|
|
VERIFY3U(0, ==, dmu_bonus_hold(os, obj, FTAG, &db));
|
|
|
|
bt = db->db_data;
|
|
|
|
|
2014-11-21 03:09:39 +03:00
|
|
|
bte = kmem_zalloc(sizeof (*bte), KM_SLEEP);
|
2014-06-06 01:20:08 +04:00
|
|
|
bte->be_birth_txg = birth_txg;
|
|
|
|
bte->be_bp = *bp;
|
|
|
|
dmu_write(os, obj, bt->bt_end * sizeof (*bte), sizeof (*bte), bte, tx);
|
|
|
|
kmem_free(bte, sizeof (*bte));
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
dmu_buf_will_dirty(db, tx);
|
|
|
|
bt->bt_end++;
|
|
|
|
bt->bt_bytes += bytes;
|
|
|
|
bt->bt_comp += comp;
|
|
|
|
bt->bt_uncomp += uncomp;
|
|
|
|
dmu_buf_rele(db, FTAG);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
2013-07-03 00:26:24 +04:00
|
|
|
bptree_visit_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)
|
2012-12-14 03:24:15 +04:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct bptree_args *ba = arg;
|
|
|
|
|
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 || BP_IS_HOLE(bp) ||
|
|
|
|
BP_IS_REDACTED(bp))
|
2012-12-14 03:24:15 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
err = ba->ba_func(ba->ba_arg, bp, ba->ba_tx);
|
|
|
|
if (err == 0 && ba->ba_free) {
|
|
|
|
ba->ba_phys->bt_bytes -= bp_get_dsize_sync(spa, bp);
|
|
|
|
ba->ba_phys->bt_comp -= BP_GET_PSIZE(bp);
|
|
|
|
ba->ba_phys->bt_uncomp -= BP_GET_UCSIZE(bp);
|
|
|
|
}
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2014-06-06 01:20:08 +04:00
|
|
|
/*
|
|
|
|
* If "free" is set:
|
|
|
|
* - It is assumed that "func" will be freeing the block pointers.
|
|
|
|
* - If "func" returns nonzero, the bookmark will be remembered and
|
|
|
|
* iteration will be restarted from this point on next invocation.
|
|
|
|
* - If an i/o error is encountered (e.g. "func" returns EIO or ECKSUM),
|
|
|
|
* bptree_iterate will remember the bookmark, continue traversing
|
|
|
|
* any additional entries, and return 0.
|
|
|
|
*
|
|
|
|
* If "free" is not set, traversal will stop and return an error if
|
|
|
|
* an i/o error is encountered.
|
|
|
|
*
|
|
|
|
* In either case, if zfs_free_leak_on_eio is set, i/o errors will be
|
|
|
|
* ignored and traversal will continue (i.e. TRAVERSE_HARD will be passed to
|
|
|
|
* traverse_dataset_destroyed()).
|
|
|
|
*/
|
2012-12-14 03:24:15 +04:00
|
|
|
int
|
|
|
|
bptree_iterate(objset_t *os, uint64_t obj, boolean_t free, bptree_itor_t func,
|
|
|
|
void *arg, dmu_tx_t *tx)
|
|
|
|
{
|
2014-06-06 01:20:08 +04:00
|
|
|
boolean_t ioerr = B_FALSE;
|
2012-12-14 03:24:15 +04:00
|
|
|
int err;
|
|
|
|
uint64_t i;
|
|
|
|
dmu_buf_t *db;
|
|
|
|
struct bptree_args ba;
|
|
|
|
|
|
|
|
ASSERT(!free || dmu_tx_is_syncing(tx));
|
|
|
|
|
|
|
|
err = dmu_bonus_hold(os, obj, FTAG, &db);
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
|
|
|
|
if (free)
|
|
|
|
dmu_buf_will_dirty(db, tx);
|
|
|
|
|
|
|
|
ba.ba_phys = db->db_data;
|
|
|
|
ba.ba_free = free;
|
|
|
|
ba.ba_func = func;
|
|
|
|
ba.ba_arg = arg;
|
|
|
|
ba.ba_tx = tx;
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
for (i = ba.ba_phys->bt_begin; i < ba.ba_phys->bt_end; i++) {
|
|
|
|
bptree_entry_phys_t bte;
|
Native Encryption for ZFS on Linux
This change incorporates three major pieces:
The first change is a keystore that manages wrapping
and encryption keys for encrypted datasets. These
commands mostly involve manipulating the new
DSL Crypto Key ZAP Objects that live in the MOS. Each
encrypted dataset has its own DSL Crypto Key that is
protected with a user's key. This level of indirection
allows users to change their keys without re-encrypting
their entire datasets. The change implements the new
subcommands "zfs load-key", "zfs unload-key" and
"zfs change-key" which allow the user to manage their
encryption keys and settings. In addition, several new
flags and properties have been added to allow dataset
creation and to make mounting and unmounting more
convenient.
The second piece of this patch provides the ability to
encrypt, decyrpt, and authenticate protected datasets.
Each object set maintains a Merkel tree of Message
Authentication Codes that protect the lower layers,
similarly to how checksums are maintained. This part
impacts the zio layer, which handles the actual
encryption and generation of MACs, as well as the ARC
and DMU, which need to be able to handle encrypted
buffers and protected data.
The last addition is the ability to do raw, encrypted
sends and receives. The idea here is to send raw
encrypted and compressed data and receive it exactly
as is on a backup system. This means that the dataset
on the receiving system is protected using the same
user key that is in use on the sending side. By doing
so, datasets can be efficiently backed up to an
untrusted system without fear of data being
compromised.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #494
Closes #5769
2017-08-14 20:36:48 +03:00
|
|
|
int flags = TRAVERSE_PREFETCH_METADATA | TRAVERSE_POST |
|
|
|
|
TRAVERSE_NO_DECRYPT;
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
err = dmu_read(os, obj, i * sizeof (bte), sizeof (bte),
|
|
|
|
&bte, DMU_READ_NO_PREFETCH);
|
|
|
|
if (err != 0)
|
|
|
|
break;
|
|
|
|
|
2014-06-06 01:20:08 +04:00
|
|
|
if (zfs_free_leak_on_eio)
|
2013-08-12 20:53:33 +04:00
|
|
|
flags |= TRAVERSE_HARD;
|
2014-10-24 03:59:27 +04:00
|
|
|
zfs_dbgmsg("bptree index %lld: traversing from min_txg=%lld "
|
2014-06-06 01:20:08 +04:00
|
|
|
"bookmark %lld/%lld/%lld/%lld",
|
2017-01-18 01:49:24 +03:00
|
|
|
(longlong_t)i,
|
|
|
|
(longlong_t)bte.be_birth_txg,
|
2014-06-06 01:20:08 +04:00
|
|
|
(longlong_t)bte.be_zb.zb_objset,
|
|
|
|
(longlong_t)bte.be_zb.zb_object,
|
|
|
|
(longlong_t)bte.be_zb.zb_level,
|
|
|
|
(longlong_t)bte.be_zb.zb_blkid);
|
2012-12-14 03:24:15 +04:00
|
|
|
err = traverse_dataset_destroyed(os->os_spa, &bte.be_bp,
|
2013-08-12 20:53:33 +04:00
|
|
|
bte.be_birth_txg, &bte.be_zb, flags,
|
2012-12-14 03:24:15 +04:00
|
|
|
bptree_visit_cb, &ba);
|
|
|
|
if (free) {
|
2014-06-06 01:20:08 +04:00
|
|
|
/*
|
|
|
|
* The callback has freed the visited block pointers.
|
|
|
|
* Record our traversal progress on disk, either by
|
|
|
|
* updating this record's bookmark, or by logically
|
|
|
|
* removing this record by advancing bt_begin.
|
|
|
|
*/
|
|
|
|
if (err != 0) {
|
2012-12-14 03:24:15 +04:00
|
|
|
/* save bookmark for future resume */
|
|
|
|
ASSERT3U(bte.be_zb.zb_objset, ==,
|
|
|
|
ZB_DESTROYED_OBJSET);
|
2013-05-11 01:17:03 +04:00
|
|
|
ASSERT0(bte.be_zb.zb_level);
|
2012-12-14 03:24:15 +04:00
|
|
|
dmu_write(os, obj, i * sizeof (bte),
|
|
|
|
sizeof (bte), &bte, tx);
|
2014-06-06 01:20:08 +04:00
|
|
|
if (err == EIO || err == ECKSUM ||
|
|
|
|
err == ENXIO) {
|
|
|
|
/*
|
|
|
|
* Skip the rest of this tree and
|
|
|
|
* continue on to the next entry.
|
|
|
|
*/
|
|
|
|
err = 0;
|
|
|
|
ioerr = B_TRUE;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (ioerr) {
|
2013-08-12 20:53:33 +04:00
|
|
|
/*
|
2014-06-06 01:20:08 +04:00
|
|
|
* This entry is finished, but there were
|
|
|
|
* i/o errors on previous entries, so we
|
|
|
|
* can't adjust bt_begin. Set this entry's
|
|
|
|
* be_birth_txg such that it will be
|
|
|
|
* treated as a no-op in future traversals.
|
2013-08-12 20:53:33 +04:00
|
|
|
*/
|
2014-06-06 01:20:08 +04:00
|
|
|
bte.be_birth_txg = UINT64_MAX;
|
|
|
|
dmu_write(os, obj, i * sizeof (bte),
|
|
|
|
sizeof (bte), &bte, tx);
|
2013-08-12 20:53:33 +04:00
|
|
|
}
|
|
|
|
|
2014-06-06 01:20:08 +04:00
|
|
|
if (!ioerr) {
|
|
|
|
ba.ba_phys->bt_begin++;
|
|
|
|
(void) dmu_free_range(os, obj,
|
|
|
|
i * sizeof (bte), sizeof (bte), tx);
|
|
|
|
}
|
|
|
|
} else if (err != 0) {
|
|
|
|
break;
|
2012-12-14 03:24:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-06 01:20:08 +04:00
|
|
|
ASSERT(!free || err != 0 || ioerr ||
|
|
|
|
ba.ba_phys->bt_begin == ba.ba_phys->bt_end);
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
/* if all blocks are free there should be no used space */
|
|
|
|
if (ba.ba_phys->bt_begin == ba.ba_phys->bt_end) {
|
2014-06-06 01:20:08 +04:00
|
|
|
if (zfs_free_leak_on_eio) {
|
|
|
|
ba.ba_phys->bt_bytes = 0;
|
|
|
|
ba.ba_phys->bt_comp = 0;
|
|
|
|
ba.ba_phys->bt_uncomp = 0;
|
|
|
|
}
|
|
|
|
|
2013-05-11 01:17:03 +04:00
|
|
|
ASSERT0(ba.ba_phys->bt_bytes);
|
|
|
|
ASSERT0(ba.ba_phys->bt_comp);
|
|
|
|
ASSERT0(ba.ba_phys->bt_uncomp);
|
2012-12-14 03:24:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
dmu_buf_rele(db, FTAG);
|
|
|
|
|
|
|
|
return (err);
|
|
|
|
}
|