Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send/Receive Fixes #2729

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions lib/libzfs/libzfs_sendrecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ typedef struct send_data {
const char *fromsnap;
const char *tosnap;
boolean_t recursive;
boolean_t seenfrom;
boolean_t seento;

/*
* The header nvlist is of the following format:
Expand Down Expand Up @@ -611,20 +613,39 @@ send_iterate_snap(zfs_handle_t *zhp, void *arg)
uint64_t guid = zhp->zfs_dmustats.dds_guid;
char *snapname;
nvlist_t *nv;
boolean_t isfromsnap, istosnap;

snapname = strrchr(zhp->zfs_name, '@')+1;
isfromsnap = (sd->fromsnap != NULL &&
strcmp(sd->fromsnap, snapname) == 0);
istosnap = (sd->tosnap != NULL && (strcmp(sd->tosnap, snapname) == 0));

VERIFY(0 == nvlist_add_uint64(sd->parent_snaps, snapname, guid));
/*
* NB: if there is no fromsnap here (it's a newly created fs in
* an incremental replication), we will substitute the tosnap.
*/
if ((sd->fromsnap && strcmp(snapname, sd->fromsnap) == 0) ||
(sd->parent_fromsnap_guid == 0 && sd->tosnap &&
strcmp(snapname, sd->tosnap) == 0)) {
if (isfromsnap || (sd->parent_fromsnap_guid == 0 && istosnap)) {
sd->parent_fromsnap_guid = guid;
}

if (!sd->recursive) {
if (!sd->seenfrom && isfromsnap) {
sd->seenfrom = B_TRUE;
zfs_close(zhp);
return (0);
}

if (sd->seento || !sd->seenfrom) {
zfs_close(zhp);
return (0);
}

if (istosnap)
sd->seento = B_TRUE;
}

VERIFY(0 == nvlist_add_uint64(sd->parent_snaps, snapname, guid));

VERIFY(0 == nvlist_alloc(&nv, NV_UNIQUE_NAME, 0));
send_iterate_prop(zhp, nv);
VERIFY(0 == nvlist_add_nvlist(sd->snapprops, snapname, nv));
Expand Down Expand Up @@ -745,7 +766,7 @@ send_iterate_fs(zfs_handle_t *zhp, void *arg)
sd->parent_fromsnap_guid = 0;
VERIFY(0 == nvlist_alloc(&sd->parent_snaps, NV_UNIQUE_NAME, 0));
VERIFY(0 == nvlist_alloc(&sd->snapprops, NV_UNIQUE_NAME, 0));
(void) zfs_iter_snapshots(zhp, B_FALSE, send_iterate_snap, sd);
(void) zfs_iter_snapshots_sorted(zhp, send_iterate_snap, sd);
VERIFY(0 == nvlist_add_nvlist(nvfs, "snaps", sd->parent_snaps));
VERIFY(0 == nvlist_add_nvlist(nvfs, "snapprops", sd->snapprops));
nvlist_free(sd->parent_snaps);
Expand Down Expand Up @@ -2020,11 +2041,12 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs,
recvflags_t *flags, nvlist_t *stream_nv, avl_tree_t *stream_avl,
nvlist_t *renamed)
{
nvlist_t *local_nv;
nvlist_t *local_nv, *deleted = NULL;
avl_tree_t *local_avl;
nvpair_t *fselem, *nextfselem;
char *fromsnap;
char newname[ZFS_MAXNAMELEN];
char guidname[32];
int error;
boolean_t needagain, progress, recursive;
char *s1, *s2;
Expand All @@ -2040,6 +2062,8 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs,
again:
needagain = progress = B_FALSE;

VERIFY(0 == nvlist_alloc(&deleted, NV_UNIQUE_NAME, 0));

if ((error = gather_nvlist(hdl, tofs, fromsnap, NULL,
recursive, &local_nv, &local_avl)) != 0)
return (error);
Expand Down Expand Up @@ -2154,6 +2178,8 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs,
needagain = B_TRUE;
else
progress = B_TRUE;
sprintf(guidname, "%lu", thisguid);
nvlist_add_boolean(deleted, guidname);
continue;
}

Expand Down Expand Up @@ -2209,6 +2235,8 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs,
needagain = B_TRUE;
else
progress = B_TRUE;
sprintf(guidname, "%lu", parent_fromsnap_guid);
nvlist_add_boolean(deleted, guidname);
continue;
}

Expand All @@ -2230,6 +2258,24 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs,
s1 = strrchr(fsname, '/');
s2 = strrchr(stream_fsname, '/');

/*
* Check if we're going to rename based on parent guid change
* and the current parent guid was also deleted. If it was then
* rename will fail and is likely unneeded, so avoid this and
* force an early retry to determine the new
* parent_fromsnap_guid.
*/
if (stream_parent_fromsnap_guid != 0 &&
parent_fromsnap_guid != 0 &&
stream_parent_fromsnap_guid != parent_fromsnap_guid) {
sprintf(guidname, "%lu", parent_fromsnap_guid);
if (nvlist_exists(deleted, guidname)) {
progress = B_TRUE;
needagain = B_TRUE;
goto doagain;
}
}

/*
* Check for rename. If the exact receive path is specified, it
* does not count as a rename, but we still need to check the
Expand Down Expand Up @@ -2284,8 +2330,10 @@ recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs,
}
}

doagain:
fsavl_destroy(local_avl);
nvlist_free(local_nv);
nvlist_free(deleted);

if (needagain && progress) {
/* do another pass to fix up temporary names */
Expand Down