Skip to content

Commit

Permalink
This is a combination of 3 commits.
Browse files Browse the repository at this point in the history
speed up recv_fix_encryption_hierarchy()

Signed-off-by: George Amanakis <[email protected]>
  • Loading branch information
gamanakis committed Jan 5, 2025
1 parent dc0324b commit a3ce640
Showing 1 changed file with 43 additions and 31 deletions.
74 changes: 43 additions & 31 deletions lib/libzfs/libzfs_sendrecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3376,49 +3376,61 @@ created_before(libzfs_handle_t *hdl, avl_tree_t *avl,
*/
static int
recv_fix_encryption_hierarchy(libzfs_handle_t *hdl, const char *top_zfs,
nvlist_t *stream_nv)
nvlist_t *stream_nv, avl_tree_t *stream_avl)
{
int err;
nvpair_t *fselem = NULL;
nvlist_t *stream_fss;
nvlist_t *stream_fss, *local_nv;
avl_tree_t *local_avl;
const char *fromsnap;
boolean_t recursive;
int error;

recursive = (nvlist_lookup_boolean(stream_nv, "not_recursive") ==
ENOENT);

Check failure on line 3390 in lib/libzfs/libzfs_sendrecv.c

View workflow job for this annotation

GitHub Actions / checkstyle

spaces instead of tabs
fromsnap = fnvlist_lookup_string(stream_nv, fromsnap);

if ((error = gather_nvlist(hdl, top_zfs, fromsnap, NULL,
recursive, B_TRUE, B_FALSE, recursive, B_FALSE, B_FALSE, B_FALSE,
B_FALSE, B_TRUE, &local_nv, &local_avl)) != 0)
return (error);

stream_fss = fnvlist_lookup_nvlist(stream_nv, "fss");

while ((fselem = nvlist_next_nvpair(stream_fss, fselem)) != NULL) {
while ((fselem = nvlist_next_nvpair(local_nv, fselem)) != NULL) {
zfs_handle_t *zhp = NULL;
uint64_t crypt;
nvlist_t *snaps, *props, *stream_nvfs = NULL;
nvpair_t *snapel = NULL;
nvlist_t *stream_props, *snaps, *stream_nvfs = NULL, *nvfs = NULL;

Check failure on line 3403 in lib/libzfs/libzfs_sendrecv.c

View workflow job for this annotation

GitHub Actions / checkstyle

line > 80 characters
boolean_t is_encroot, is_clone, stream_encroot;
char *cp;
const char *stream_keylocation = NULL;
char keylocation[MAXNAMELEN];
char fsname[ZFS_MAX_DATASET_NAME_LEN];
const char *fsname, *stream_fsname;
nvpair_t *snapelem, *nextsnapelem;

nvfs = fnvpair_value_nvlist(fselem);
snaps = fnvlist_lookup_nvlist(nvfs, "snaps");
fsname = fnvlist_lookup_string(nvfs, "name");

keylocation[0] = '\0';
stream_nvfs = fnvpair_value_nvlist(fselem);
snaps = fnvlist_lookup_nvlist(stream_nvfs, "snaps");
props = fnvlist_lookup_nvlist(stream_nvfs, "props");
stream_encroot = nvlist_exists(stream_nvfs, "is_encroot");

/* find a snapshot from the stream that exists locally */
err = ENOENT;
while ((snapel = nvlist_next_nvpair(snaps, snapel)) != NULL) {
uint64_t guid;
/*
* First find the stream's fs
*/
for (snapelem = nvlist_next_nvpair(snaps, NULL);
snapelem; snapelem = nvlist_next_nvpair(snaps, snapelem)) {
uint64_t thisguid;

thisguid = fnvpair_value_uint64(snapelem);
stream_nvfs = fsavl_find(stream_avl, thisguid, NULL);

guid = fnvpair_value_uint64(snapel);
err = guid_to_name(hdl, top_zfs, guid, B_FALSE,
fsname);
if (err == 0)
if (stream_nvfs != NULL)
break;
}

if (err != 0)
continue;

cp = strchr(fsname, '@');
if (cp != NULL)
*cp = '\0';
stream_nvfs = fnvpair_value_nvlist(snapelem);
stream_props = fnvlist_lookup_nvlist(stream_nvfs, "props");
stream_fsname = fnvlist_lookup_string(stream_nvfs, "name");
stream_encroot = nvlist_exists(stream_nvfs, "is_encroot");

zhp = zfs_open(hdl, fsname, ZFS_TYPE_DATASET);
if (zhp == NULL) {
Expand Down Expand Up @@ -3451,7 +3463,7 @@ recv_fix_encryption_hierarchy(libzfs_handle_t *hdl, const char *top_zfs,
}
}

stream_keylocation = fnvlist_lookup_string(props,
stream_keylocation = fnvlist_lookup_string(stream_props,
zfs_prop_to_name(ZFS_PROP_KEYLOCATION));

/*
Expand Down Expand Up @@ -3518,14 +3530,14 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs,
boolean_t needagain, progress, recursive;
const char *s1, *s2;

if (flags->dryrun)
return (0);

fromsnap = fnvlist_lookup_string(stream_nv, "fromsnap");

recursive = (nvlist_lookup_boolean(stream_nv, "not_recursive") ==
ENOENT);

if (flags->dryrun)
return (0);

again:
needagain = progress = B_FALSE;

Expand Down Expand Up @@ -3999,9 +4011,9 @@ zfs_receive_package(libzfs_handle_t *hdl, int fd, const char *destname,
stream_nv, stream_avl, NULL);
}

if (raw && softerr == 0 && *top_zfs != NULL) {
if (raw && softerr == 0 && *top_zfs != NULL && !flags->dryrun) {
softerr = recv_fix_encryption_hierarchy(hdl, *top_zfs,
stream_nv);
stream_nv, stream_avl);
}

out:
Expand Down

0 comments on commit a3ce640

Please sign in to comment.