2011-11-17 18:14:36 +00: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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2005, 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 16:48:13 +00:00
|
|
|
* Copyright (c) 2013, 2019 by Delphix. All rights reserved.
|
2015-07-05 21:51:53 +00:00
|
|
|
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
|
2019-03-12 20:13:22 +00:00
|
|
|
* Copyright (c) 2019 Datto Inc.
|
2011-11-17 18:14:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <libintl.h>
|
|
|
|
#include <libzfs.h>
|
2018-11-05 19:22:33 +00:00
|
|
|
#include <libzutil.h>
|
2018-10-02 19:30:58 +00:00
|
|
|
#include <sys/mntent.h>
|
2011-11-17 18:14:36 +00:00
|
|
|
|
|
|
|
#include "libzfs_impl.h"
|
|
|
|
|
2020-06-15 18:30:37 +00:00
|
|
|
static int
|
2011-11-17 18:14:36 +00:00
|
|
|
zfs_iter_clones(zfs_handle_t *zhp, zfs_iter_f func, void *data)
|
|
|
|
{
|
|
|
|
nvlist_t *nvl = zfs_get_clones_nvl(zhp);
|
|
|
|
nvpair_t *pair;
|
|
|
|
|
|
|
|
if (nvl == NULL)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
for (pair = nvlist_next_nvpair(nvl, NULL); pair != NULL;
|
|
|
|
pair = nvlist_next_nvpair(nvl, pair)) {
|
|
|
|
zfs_handle_t *clone = zfs_open(zhp->zfs_hdl, nvpair_name(pair),
|
|
|
|
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME);
|
|
|
|
if (clone != NULL) {
|
|
|
|
int err = func(clone, data);
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_do_list_ioctl(zfs_handle_t *zhp, int arg, zfs_cmd_t *zc)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
uint64_t orig_cookie;
|
|
|
|
|
|
|
|
orig_cookie = zc->zc_cookie;
|
|
|
|
top:
|
|
|
|
(void) strlcpy(zc->zc_name, zhp->zfs_name, sizeof (zc->zc_name));
|
2019-10-24 00:29:43 +00:00
|
|
|
rc = zfs_ioctl(zhp->zfs_hdl, arg, zc);
|
2011-11-17 18:14:36 +00:00
|
|
|
|
|
|
|
if (rc == -1) {
|
|
|
|
switch (errno) {
|
|
|
|
case ENOMEM:
|
|
|
|
/* expand nvlist memory and try again */
|
|
|
|
if (zcmd_expand_dst_nvlist(zhp->zfs_hdl, zc) != 0) {
|
|
|
|
zcmd_free_nvlists(zc);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
zc->zc_cookie = orig_cookie;
|
|
|
|
goto top;
|
|
|
|
/*
|
|
|
|
* An errno value of ESRCH indicates normal completion.
|
|
|
|
* If ENOENT is returned, then the underlying dataset
|
|
|
|
* has been removed since we obtained the handle.
|
|
|
|
*/
|
|
|
|
case ESRCH:
|
|
|
|
case ENOENT:
|
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rc = zfs_standard_error(zhp->zfs_hdl, errno,
|
|
|
|
dgettext(TEXT_DOMAIN,
|
|
|
|
"cannot iterate filesystems"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over all child filesystems
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data)
|
|
|
|
{
|
2013-09-04 12:00:57 +00:00
|
|
|
zfs_cmd_t zc = {"\0"};
|
2011-11-17 18:14:36 +00:00
|
|
|
zfs_handle_t *nzhp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (zhp->zfs_type != ZFS_TYPE_FILESYSTEM)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_DATASET_LIST_NEXT,
|
|
|
|
&zc)) == 0) {
|
|
|
|
/*
|
|
|
|
* Silently ignore errors, as the only plausible explanation is
|
|
|
|
* that the pool has since been removed.
|
|
|
|
*/
|
|
|
|
if ((nzhp = make_dataset_handle_zc(zhp->zfs_hdl,
|
|
|
|
&zc)) == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret = func(nzhp, data)) != 0) {
|
|
|
|
zcmd_free_nvlists(&zc);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zcmd_free_nvlists(&zc);
|
|
|
|
return ((ret < 0) ? ret : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over all snapshots
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_iter_snapshots(zfs_handle_t *zhp, boolean_t simple, zfs_iter_f func,
|
2019-03-12 20:13:22 +00:00
|
|
|
void *data, uint64_t min_txg, uint64_t max_txg)
|
2011-11-17 18:14:36 +00:00
|
|
|
{
|
2013-09-04 12:00:57 +00:00
|
|
|
zfs_cmd_t zc = {"\0"};
|
2011-11-17 18:14:36 +00:00
|
|
|
zfs_handle_t *nzhp;
|
|
|
|
int ret;
|
2019-03-12 20:13:22 +00:00
|
|
|
nvlist_t *range_nvl = NULL;
|
2011-11-17 18:14:36 +00:00
|
|
|
|
2013-12-11 22:33:41 +00:00
|
|
|
if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT ||
|
|
|
|
zhp->zfs_type == ZFS_TYPE_BOOKMARK)
|
2011-11-17 18:14:36 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
zc.zc_simple = simple;
|
|
|
|
|
|
|
|
if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
|
|
|
|
return (-1);
|
2019-03-12 20:13:22 +00:00
|
|
|
|
|
|
|
if (min_txg != 0) {
|
|
|
|
range_nvl = fnvlist_alloc();
|
|
|
|
fnvlist_add_uint64(range_nvl, SNAP_ITER_MIN_TXG, min_txg);
|
|
|
|
}
|
|
|
|
if (max_txg != 0) {
|
|
|
|
if (range_nvl == NULL)
|
|
|
|
range_nvl = fnvlist_alloc();
|
|
|
|
fnvlist_add_uint64(range_nvl, SNAP_ITER_MAX_TXG, max_txg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (range_nvl != NULL &&
|
|
|
|
zcmd_write_src_nvlist(zhp->zfs_hdl, &zc, range_nvl) != 0) {
|
|
|
|
zcmd_free_nvlists(&zc);
|
|
|
|
fnvlist_free(range_nvl);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2011-11-17 18:14:36 +00:00
|
|
|
while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_SNAPSHOT_LIST_NEXT,
|
|
|
|
&zc)) == 0) {
|
|
|
|
|
|
|
|
if (simple)
|
|
|
|
nzhp = make_dataset_simple_handle_zc(zhp, &zc);
|
|
|
|
else
|
|
|
|
nzhp = make_dataset_handle_zc(zhp->zfs_hdl, &zc);
|
|
|
|
if (nzhp == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((ret = func(nzhp, data)) != 0) {
|
|
|
|
zcmd_free_nvlists(&zc);
|
2019-03-12 20:13:22 +00:00
|
|
|
fnvlist_free(range_nvl);
|
2011-11-17 18:14:36 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zcmd_free_nvlists(&zc);
|
2019-03-12 20:13:22 +00:00
|
|
|
fnvlist_free(range_nvl);
|
2011-11-17 18:14:36 +00:00
|
|
|
return ((ret < 0) ? ret : 0);
|
|
|
|
}
|
|
|
|
|
2013-12-11 22:33:41 +00:00
|
|
|
/*
|
|
|
|
* Iterate over all bookmarks
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_iter_bookmarks(zfs_handle_t *zhp, zfs_iter_f func, void *data)
|
|
|
|
{
|
|
|
|
zfs_handle_t *nzhp;
|
|
|
|
nvlist_t *props = NULL;
|
|
|
|
nvlist_t *bmarks = NULL;
|
|
|
|
int err;
|
|
|
|
nvpair_t *pair;
|
|
|
|
|
|
|
|
if ((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT | ZFS_TYPE_BOOKMARK)) != 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Setup the requested properties nvlist. */
|
|
|
|
props = fnvlist_alloc();
|
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 16:48:13 +00:00
|
|
|
for (zfs_prop_t p = 0; p < ZFS_NUM_PROPS; p++) {
|
|
|
|
if (zfs_prop_valid_for_type(p, ZFS_TYPE_BOOKMARK, B_FALSE)) {
|
|
|
|
fnvlist_add_boolean(props, zfs_prop_to_name(p));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fnvlist_add_boolean(props, "redact_complete");
|
2013-12-11 22:33:41 +00:00
|
|
|
|
|
|
|
if ((err = lzc_get_bookmarks(zhp->zfs_name, props, &bmarks)) != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (pair = nvlist_next_nvpair(bmarks, NULL);
|
|
|
|
pair != NULL; pair = nvlist_next_nvpair(bmarks, pair)) {
|
2016-06-15 21:28:36 +00:00
|
|
|
char name[ZFS_MAX_DATASET_NAME_LEN];
|
2013-12-11 22:33:41 +00:00
|
|
|
char *bmark_name;
|
|
|
|
nvlist_t *bmark_props;
|
|
|
|
|
|
|
|
bmark_name = nvpair_name(pair);
|
|
|
|
bmark_props = fnvpair_value_nvlist(pair);
|
|
|
|
|
2017-06-28 17:05:16 +00:00
|
|
|
if (snprintf(name, sizeof (name), "%s#%s", zhp->zfs_name,
|
|
|
|
bmark_name) >= sizeof (name)) {
|
|
|
|
err = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2013-12-11 22:33:41 +00:00
|
|
|
|
|
|
|
nzhp = make_bookmark_handle(zhp, name, bmark_props);
|
|
|
|
if (nzhp == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((err = func(nzhp, data)) != 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
fnvlist_free(props);
|
|
|
|
fnvlist_free(bmarks);
|
|
|
|
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2011-11-17 18:14:36 +00:00
|
|
|
/*
|
|
|
|
* Routines for dealing with the sorted snapshot functionality
|
|
|
|
*/
|
|
|
|
typedef struct zfs_node {
|
|
|
|
zfs_handle_t *zn_handle;
|
|
|
|
avl_node_t zn_avlnode;
|
|
|
|
} zfs_node_t;
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_sort_snaps(zfs_handle_t *zhp, void *data)
|
|
|
|
{
|
|
|
|
avl_tree_t *avl = data;
|
|
|
|
zfs_node_t *node;
|
|
|
|
zfs_node_t search;
|
|
|
|
|
|
|
|
search.zn_handle = zhp;
|
|
|
|
node = avl_find(avl, &search, NULL);
|
|
|
|
if (node) {
|
|
|
|
/*
|
|
|
|
* If this snapshot was renamed while we were creating the
|
|
|
|
* AVL tree, it's possible that we already inserted it under
|
|
|
|
* its old name. Remove the old handle before adding the new
|
|
|
|
* one.
|
|
|
|
*/
|
|
|
|
zfs_close(node->zn_handle);
|
|
|
|
avl_remove(avl, node);
|
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
node = zfs_alloc(zhp->zfs_hdl, sizeof (zfs_node_t));
|
|
|
|
node->zn_handle = zhp;
|
|
|
|
avl_add(avl, node);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_snapshot_compare(const void *larg, const void *rarg)
|
|
|
|
{
|
|
|
|
zfs_handle_t *l = ((zfs_node_t *)larg)->zn_handle;
|
|
|
|
zfs_handle_t *r = ((zfs_node_t *)rarg)->zn_handle;
|
|
|
|
uint64_t lcreate, rcreate;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sort them according to creation time. We use the hidden
|
|
|
|
* CREATETXG property to get an absolute ordering of snapshots.
|
|
|
|
*/
|
|
|
|
lcreate = zfs_prop_get_int(l, ZFS_PROP_CREATETXG);
|
|
|
|
rcreate = zfs_prop_get_int(r, ZFS_PROP_CREATETXG);
|
|
|
|
|
Reduce loaded range tree memory usage
This patch implements a new tree structure for ZFS, and uses it to
store range trees more efficiently.
The new structure is approximately a B-tree, though there are some
small differences from the usual characterizations. The tree has core
nodes and leaf nodes; each contain data elements, which the elements
in the core nodes acting as separators between its children. The
difference between core and leaf nodes is that the core nodes have an
array of children, while leaf nodes don't. Every node in the tree may
be only partially full; in most cases, they are all at least 50% full
(in terms of element count) except for the root node, which can be
less full. Underfull nodes will steal from their neighbors or merge to
remain full enough, while overfull nodes will split in two. The data
elements are contained in tree-controlled buffers; they are copied
into these on insertion, and overwritten on deletion. This means that
the elements are not independently allocated, which reduces overhead,
but also means they can't be shared between trees (and also that
pointers to them are only valid until a side-effectful tree operation
occurs). The overhead varies based on how dense the tree is, but is
usually on the order of about 50% of the element size; the per-node
overheads are very small, and so don't make a significant difference.
The trees can accept arbitrary records; they accept a size and a
comparator to allow them to be used for a variety of purposes.
The new trees replace the AVL trees used in the range trees today.
Currently, the range_seg_t structure contains three 8 byte integers
of payload and two 24 byte avl_tree_node_ts to handle its storage in
both an offset-sorted tree and a size-sorted tree (total size: 64
bytes). In the new model, the range seg structures are usually two 4
byte integers, but a separate one needs to exist for the size-sorted
and offset-sorted tree. Between the raw size, the 50% overhead, and
the double storage, the new btrees are expected to use 8*1.5*2 = 24
bytes per record, or 33.3% as much memory as the AVL trees (this is
for the purposes of storing metaslab range trees; for other purposes,
like scrubs, they use ~50% as much memory).
We reduced the size of the payload in the range segments by teaching
range trees about starting offsets and shifts; since metaslabs have a
fixed starting offset, and they all operate in terms of disk sectors,
we can store the ranges using 4-byte integers as long as the size of
the metaslab divided by the sector size is less than 2^32. For 512-byte
sectors, this is a 2^41 (or 2TB) metaslab, which with the default
settings corresponds to a 256PB disk. 4k sector disks can handle
metaslabs up to 2^46 bytes, or 2^63 byte disks. Since we do not
anticipate disks of this size in the near future, there should be
almost no cases where metaslabs need 64-byte integers to store their
ranges. We do still have the capability to store 64-byte integer ranges
to account for cases where we are storing per-vdev (or per-dnode) trees,
which could reasonably go above the limits discussed. We also do not
store fill information in the compact version of the node, since it
is only used for sorted scrub.
We also optimized the metaslab loading process in various other ways
to offset some inefficiencies in the btree model. While individual
operations (find, insert, remove_from) are faster for the btree than
they are for the avl tree, remove usually requires a find operation,
while in the AVL tree model the element itself suffices. Some clever
changes actually caused an overall speedup in metaslab loading; we use
approximately 40% less cpu to load metaslabs in our tests on Illumos.
Another memory and performance optimization was achieved by changing
what is stored in the size-sorted trees. When a disk is heavily
fragmented, the df algorithm used by default in ZFS will almost always
find a number of small regions in its initial cursor-based search; it
will usually only fall back to the size-sorted tree to find larger
regions. If we increase the size of the cursor-based search slightly,
and don't store segments that are smaller than a tunable size floor
in the size-sorted tree, we can further cut memory usage down to
below 20% of what the AVL trees store. This also results in further
reductions in CPU time spent loading metaslabs.
The 16KiB size floor was chosen because it results in substantial memory
usage reduction while not usually resulting in situations where we can't
find an appropriate chunk with the cursor and are forced to use an
oversized chunk from the size-sorted tree. In addition, even if we do
have to use an oversized chunk from the size-sorted tree, the chunk
would be too small to use for ZIL allocations, so it isn't as big of a
loss as it might otherwise be. And often, more small allocations will
follow the initial one, and the cursor search will now find the
remainder of the chunk we didn't use all of and use it for subsequent
allocations. Practical testing has shown little or no change in
fragmentation as a result of this change.
If the size-sorted tree becomes empty while the offset sorted one still
has entries, it will load all the entries from the offset sorted tree
and disregard the size floor until it is unloaded again. This operation
occurs rarely with the default setting, only on incredibly thoroughly
fragmented pools.
There are some other small changes to zdb to teach it to handle btrees,
but nothing major.
Reviewed-by: George Wilson <gwilson@delphix.com>
Reviewed-by: Matt Ahrens <matt@delphix.com>
Reviewed by: Sebastien Roy seb@delphix.com
Reviewed-by: Igor Kozhukhov <igor@dilos.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #9181
2019-10-09 17:36:03 +00:00
|
|
|
return (TREE_CMP(lcreate, rcreate));
|
2011-11-17 18:14:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-03-12 20:13:22 +00:00
|
|
|
zfs_iter_snapshots_sorted(zfs_handle_t *zhp, zfs_iter_f callback, void *data,
|
|
|
|
uint64_t min_txg, uint64_t max_txg)
|
2011-11-17 18:14:36 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
zfs_node_t *node;
|
|
|
|
avl_tree_t avl;
|
|
|
|
void *cookie = NULL;
|
|
|
|
|
|
|
|
avl_create(&avl, zfs_snapshot_compare,
|
|
|
|
sizeof (zfs_node_t), offsetof(zfs_node_t, zn_avlnode));
|
|
|
|
|
2019-03-12 20:13:22 +00:00
|
|
|
ret = zfs_iter_snapshots(zhp, B_FALSE, zfs_sort_snaps, &avl, min_txg,
|
|
|
|
max_txg);
|
2011-11-17 18:14:36 +00:00
|
|
|
|
|
|
|
for (node = avl_first(&avl); node != NULL; node = AVL_NEXT(&avl, node))
|
|
|
|
ret |= callback(node->zn_handle, data);
|
|
|
|
|
|
|
|
while ((node = avl_destroy_nodes(&avl, &cookie)) != NULL)
|
|
|
|
free(node);
|
|
|
|
|
|
|
|
avl_destroy(&avl);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char *ssa_first;
|
|
|
|
char *ssa_last;
|
|
|
|
boolean_t ssa_seenfirst;
|
|
|
|
boolean_t ssa_seenlast;
|
|
|
|
zfs_iter_f ssa_func;
|
|
|
|
void *ssa_arg;
|
|
|
|
} snapspec_arg_t;
|
|
|
|
|
|
|
|
static int
|
2017-01-12 17:42:11 +00:00
|
|
|
snapspec_cb(zfs_handle_t *zhp, void *arg)
|
|
|
|
{
|
2011-11-17 18:14:36 +00:00
|
|
|
snapspec_arg_t *ssa = arg;
|
2017-03-29 00:22:46 +00:00
|
|
|
const char *shortsnapname;
|
2011-11-17 18:14:36 +00:00
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (ssa->ssa_seenlast)
|
|
|
|
return (0);
|
|
|
|
|
2017-03-29 00:22:46 +00:00
|
|
|
shortsnapname = strchr(zfs_get_name(zhp), '@') + 1;
|
2011-11-17 18:14:36 +00:00
|
|
|
if (!ssa->ssa_seenfirst && strcmp(shortsnapname, ssa->ssa_first) == 0)
|
|
|
|
ssa->ssa_seenfirst = B_TRUE;
|
2017-03-29 00:22:46 +00:00
|
|
|
if (strcmp(shortsnapname, ssa->ssa_last) == 0)
|
|
|
|
ssa->ssa_seenlast = B_TRUE;
|
2011-11-17 18:14:36 +00:00
|
|
|
|
|
|
|
if (ssa->ssa_seenfirst) {
|
|
|
|
err = ssa->ssa_func(zhp, ssa->ssa_arg);
|
|
|
|
} else {
|
|
|
|
zfs_close(zhp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* spec is a string like "A,B%C,D"
|
|
|
|
*
|
|
|
|
* <snaps>, where <snaps> can be:
|
|
|
|
* <snap> (single snapshot)
|
|
|
|
* <snap>%<snap> (range of snapshots, inclusive)
|
|
|
|
* %<snap> (range of snapshots, starting with earliest)
|
|
|
|
* <snap>% (range of snapshots, ending with last)
|
|
|
|
* % (all snapshots)
|
|
|
|
* <snaps>[,...] (comma separated list of the above)
|
|
|
|
*
|
|
|
|
* If a snapshot can not be opened, continue trying to open the others, but
|
|
|
|
* return ENOENT at the end.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_iter_snapspec(zfs_handle_t *fs_zhp, const char *spec_orig,
|
|
|
|
zfs_iter_f func, void *arg)
|
|
|
|
{
|
2013-08-28 11:45:09 +00:00
|
|
|
char *buf, *comma_separated, *cp;
|
2011-11-17 18:14:36 +00:00
|
|
|
int err = 0;
|
|
|
|
int ret = 0;
|
|
|
|
|
2013-08-28 11:45:09 +00:00
|
|
|
buf = zfs_strdup(fs_zhp->zfs_hdl, spec_orig);
|
2011-11-17 18:14:36 +00:00
|
|
|
cp = buf;
|
|
|
|
|
|
|
|
while ((comma_separated = strsep(&cp, ",")) != NULL) {
|
|
|
|
char *pct = strchr(comma_separated, '%');
|
|
|
|
if (pct != NULL) {
|
|
|
|
snapspec_arg_t ssa = { 0 };
|
|
|
|
ssa.ssa_func = func;
|
|
|
|
ssa.ssa_arg = arg;
|
|
|
|
|
|
|
|
if (pct == comma_separated)
|
|
|
|
ssa.ssa_seenfirst = B_TRUE;
|
|
|
|
else
|
|
|
|
ssa.ssa_first = comma_separated;
|
|
|
|
*pct = '\0';
|
|
|
|
ssa.ssa_last = pct + 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is a lastname specified, make sure it
|
|
|
|
* exists.
|
|
|
|
*/
|
|
|
|
if (ssa.ssa_last[0] != '\0') {
|
2016-06-15 21:28:36 +00:00
|
|
|
char snapname[ZFS_MAX_DATASET_NAME_LEN];
|
2011-11-17 18:14:36 +00:00
|
|
|
(void) snprintf(snapname, sizeof (snapname),
|
|
|
|
"%s@%s", zfs_get_name(fs_zhp),
|
|
|
|
ssa.ssa_last);
|
|
|
|
if (!zfs_dataset_exists(fs_zhp->zfs_hdl,
|
|
|
|
snapname, ZFS_TYPE_SNAPSHOT)) {
|
|
|
|
ret = ENOENT;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = zfs_iter_snapshots_sorted(fs_zhp,
|
2019-03-12 20:13:22 +00:00
|
|
|
snapspec_cb, &ssa, 0, 0);
|
2011-11-17 18:14:36 +00:00
|
|
|
if (ret == 0)
|
|
|
|
ret = err;
|
|
|
|
if (ret == 0 && (!ssa.ssa_seenfirst ||
|
|
|
|
(ssa.ssa_last[0] != '\0' && !ssa.ssa_seenlast))) {
|
|
|
|
ret = ENOENT;
|
|
|
|
}
|
|
|
|
} else {
|
2016-06-15 21:28:36 +00:00
|
|
|
char snapname[ZFS_MAX_DATASET_NAME_LEN];
|
2011-11-17 18:14:36 +00:00
|
|
|
zfs_handle_t *snap_zhp;
|
|
|
|
(void) snprintf(snapname, sizeof (snapname), "%s@%s",
|
|
|
|
zfs_get_name(fs_zhp), comma_separated);
|
|
|
|
snap_zhp = make_dataset_handle(fs_zhp->zfs_hdl,
|
|
|
|
snapname);
|
|
|
|
if (snap_zhp == NULL) {
|
|
|
|
ret = ENOENT;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
err = func(snap_zhp, arg);
|
|
|
|
if (ret == 0)
|
|
|
|
ret = err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 11:45:09 +00:00
|
|
|
free(buf);
|
2011-11-17 18:14:36 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over all children, snapshots and filesystems
|
2017-12-30 23:25:56 +00:00
|
|
|
* Process snapshots before filesystems because they are nearer the input
|
|
|
|
* handle: this is extremely important when used with zfs_iter_f functions
|
|
|
|
* looking for data, following the logic that we would like to find it as soon
|
|
|
|
* and as close as possible.
|
2011-11-17 18:14:36 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_iter_children(zfs_handle_t *zhp, zfs_iter_f func, void *data)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2019-03-12 20:13:22 +00:00
|
|
|
if ((ret = zfs_iter_snapshots(zhp, B_FALSE, func, data, 0, 0)) != 0)
|
2011-11-17 18:14:36 +00:00
|
|
|
return (ret);
|
|
|
|
|
2017-10-10 22:22:05 +00:00
|
|
|
return (zfs_iter_filesystems(zhp, func, data));
|
2011-11-17 18:14:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct iter_stack_frame {
|
|
|
|
struct iter_stack_frame *next;
|
|
|
|
zfs_handle_t *zhp;
|
|
|
|
} iter_stack_frame_t;
|
|
|
|
|
|
|
|
typedef struct iter_dependents_arg {
|
|
|
|
boolean_t first;
|
|
|
|
boolean_t allowrecursion;
|
|
|
|
iter_stack_frame_t *stack;
|
|
|
|
zfs_iter_f func;
|
|
|
|
void *data;
|
|
|
|
} iter_dependents_arg_t;
|
|
|
|
|
|
|
|
static int
|
|
|
|
iter_dependents_cb(zfs_handle_t *zhp, void *arg)
|
|
|
|
{
|
|
|
|
iter_dependents_arg_t *ida = arg;
|
2013-12-11 22:33:41 +00:00
|
|
|
int err = 0;
|
2011-11-17 18:14:36 +00:00
|
|
|
boolean_t first = ida->first;
|
|
|
|
ida->first = B_FALSE;
|
|
|
|
|
|
|
|
if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) {
|
|
|
|
err = zfs_iter_clones(zhp, iter_dependents_cb, ida);
|
2013-12-11 22:33:41 +00:00
|
|
|
} else if (zhp->zfs_type != ZFS_TYPE_BOOKMARK) {
|
2011-11-17 18:14:36 +00:00
|
|
|
iter_stack_frame_t isf;
|
|
|
|
iter_stack_frame_t *f;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check if there is a cycle by seeing if this fs is already
|
|
|
|
* on the stack.
|
|
|
|
*/
|
|
|
|
for (f = ida->stack; f != NULL; f = f->next) {
|
|
|
|
if (f->zhp->zfs_dmustats.dds_guid ==
|
|
|
|
zhp->zfs_dmustats.dds_guid) {
|
|
|
|
if (ida->allowrecursion) {
|
|
|
|
zfs_close(zhp);
|
|
|
|
return (0);
|
|
|
|
} else {
|
|
|
|
zfs_error_aux(zhp->zfs_hdl,
|
|
|
|
dgettext(TEXT_DOMAIN,
|
|
|
|
"recursive dependency at '%s'"),
|
|
|
|
zfs_get_name(zhp));
|
|
|
|
err = zfs_error(zhp->zfs_hdl,
|
|
|
|
EZFS_RECURSIVE,
|
|
|
|
dgettext(TEXT_DOMAIN,
|
|
|
|
"cannot determine dependent "
|
|
|
|
"datasets"));
|
|
|
|
zfs_close(zhp);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isf.zhp = zhp;
|
|
|
|
isf.next = ida->stack;
|
|
|
|
ida->stack = &isf;
|
|
|
|
err = zfs_iter_filesystems(zhp, iter_dependents_cb, ida);
|
|
|
|
if (err == 0)
|
|
|
|
err = zfs_iter_snapshots(zhp, B_FALSE,
|
2019-03-12 20:13:22 +00:00
|
|
|
iter_dependents_cb, ida, 0, 0);
|
2011-11-17 18:14:36 +00:00
|
|
|
ida->stack = isf.next;
|
|
|
|
}
|
2013-08-16 02:33:42 +00:00
|
|
|
|
2011-11-17 18:14:36 +00:00
|
|
|
if (!first && err == 0)
|
|
|
|
err = ida->func(zhp, ida->data);
|
2013-08-16 02:33:42 +00:00
|
|
|
else
|
|
|
|
zfs_close(zhp);
|
|
|
|
|
2011-11-17 18:14:36 +00:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zfs_iter_dependents(zfs_handle_t *zhp, boolean_t allowrecursion,
|
|
|
|
zfs_iter_f func, void *data)
|
|
|
|
{
|
|
|
|
iter_dependents_arg_t ida;
|
|
|
|
ida.allowrecursion = allowrecursion;
|
|
|
|
ida.stack = NULL;
|
|
|
|
ida.func = func;
|
|
|
|
ida.data = data;
|
|
|
|
ida.first = B_TRUE;
|
|
|
|
return (iter_dependents_cb(zfs_handle_dup(zhp), &ida));
|
|
|
|
}
|
2018-10-02 19:30:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over mounted children of the specified dataset
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_iter_mounted(zfs_handle_t *zhp, zfs_iter_f func, void *data)
|
|
|
|
{
|
|
|
|
char mnt_prop[ZFS_MAXPROPLEN];
|
|
|
|
struct mnttab entry;
|
|
|
|
zfs_handle_t *mtab_zhp;
|
|
|
|
size_t namelen = strlen(zhp->zfs_name);
|
|
|
|
FILE *mnttab;
|
|
|
|
int err = 0;
|
|
|
|
|
2021-04-08 20:17:38 +00:00
|
|
|
if ((mnttab = fopen(MNTTAB, "re")) == NULL)
|
2018-10-02 19:30:58 +00:00
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
while (err == 0 && getmntent(mnttab, &entry) == 0) {
|
|
|
|
/* Ignore non-ZFS entries */
|
|
|
|
if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Ignore datasets not within the provided dataset */
|
|
|
|
if (strncmp(entry.mnt_special, zhp->zfs_name, namelen) != 0 ||
|
|
|
|
(entry.mnt_special[namelen] != '/' &&
|
|
|
|
entry.mnt_special[namelen] != '@'))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((mtab_zhp = zfs_open(zhp->zfs_hdl, entry.mnt_special,
|
|
|
|
ZFS_TYPE_FILESYSTEM)) == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Ignore legacy mounts as they are user managed */
|
|
|
|
verify(zfs_prop_get(mtab_zhp, ZFS_PROP_MOUNTPOINT, mnt_prop,
|
|
|
|
sizeof (mnt_prop), NULL, NULL, 0, B_FALSE) == 0);
|
|
|
|
if (strcmp(mnt_prop, "legacy") == 0) {
|
|
|
|
zfs_close(mtab_zhp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = func(mtab_zhp, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(mnttab);
|
|
|
|
|
|
|
|
return (err);
|
|
|
|
}
|