Changeset View
Changeset View
Standalone View
Standalone View
sys/contrib/openzfs/lib/libzfs/libzfs_sendrecv.c
Show First 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | fsavl_create(nvlist_t *fss) | ||||
avl_create(fsavl, fsavl_compare, sizeof (fsavl_node_t), | avl_create(fsavl, fsavl_compare, sizeof (fsavl_node_t), | ||||
offsetof(fsavl_node_t, fn_node)); | offsetof(fsavl_node_t, fn_node)); | ||||
while ((fselem = nvlist_next_nvpair(fss, fselem)) != NULL) { | while ((fselem = nvlist_next_nvpair(fss, fselem)) != NULL) { | ||||
nvlist_t *nvfs, *snaps; | nvlist_t *nvfs, *snaps; | ||||
nvpair_t *snapelem = NULL; | nvpair_t *snapelem = NULL; | ||||
VERIFY(0 == nvpair_value_nvlist(fselem, &nvfs)); | nvfs = fnvpair_value_nvlist(fselem); | ||||
VERIFY(0 == nvlist_lookup_nvlist(nvfs, "snaps", &snaps)); | snaps = fnvlist_lookup_nvlist(nvfs, "snaps"); | ||||
while ((snapelem = | while ((snapelem = | ||||
nvlist_next_nvpair(snaps, snapelem)) != NULL) { | nvlist_next_nvpair(snaps, snapelem)) != NULL) { | ||||
fsavl_node_t *fn; | fsavl_node_t *fn; | ||||
uint64_t guid; | uint64_t guid; | ||||
VERIFY(0 == nvpair_value_uint64(snapelem, &guid)); | guid = fnvpair_value_uint64(snapelem); | ||||
if ((fn = malloc(sizeof (fsavl_node_t))) == NULL) { | if ((fn = malloc(sizeof (fsavl_node_t))) == NULL) { | ||||
fsavl_destroy(fsavl); | fsavl_destroy(fsavl); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
fn->fn_nvfs = nvfs; | fn->fn_nvfs = nvfs; | ||||
fn->fn_snapname = nvpair_name(snapelem); | fn->fn_snapname = nvpair_name(snapelem); | ||||
fn->fn_guid = guid; | fn->fn_guid = guid; | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | if (sd->verbose) { | ||||
"skipping snapshot %s because it was created " | "skipping snapshot %s because it was created " | ||||
"after the destination snapshot (%s)\n"), | "after the destination snapshot (%s)\n"), | ||||
zhp->zfs_name, sd->tosnap); | zhp->zfs_name, sd->tosnap); | ||||
} | } | ||||
zfs_close(zhp); | zfs_close(zhp); | ||||
return (0); | return (0); | ||||
} | } | ||||
VERIFY(0 == nvlist_add_uint64(sd->parent_snaps, snapname, guid)); | fnvlist_add_uint64(sd->parent_snaps, snapname, guid); | ||||
/* | /* | ||||
* NB: if there is no fromsnap here (it's a newly created fs in | * NB: if there is no fromsnap here (it's a newly created fs in | ||||
* an incremental replication), we will substitute the tosnap. | * an incremental replication), we will substitute the tosnap. | ||||
*/ | */ | ||||
if (isfromsnap || (sd->parent_fromsnap_guid == 0 && istosnap)) { | if (isfromsnap || (sd->parent_fromsnap_guid == 0 && istosnap)) { | ||||
sd->parent_fromsnap_guid = guid; | sd->parent_fromsnap_guid = guid; | ||||
} | } | ||||
if (!sd->recursive) { | if (!sd->recursive) { | ||||
if (!sd->seenfrom && isfromsnap) { | if (!sd->seenfrom && isfromsnap) { | ||||
sd->seenfrom = B_TRUE; | sd->seenfrom = B_TRUE; | ||||
zfs_close(zhp); | zfs_close(zhp); | ||||
return (0); | return (0); | ||||
} | } | ||||
if ((sd->seento || !sd->seenfrom) && !istosnapwithnofrom) { | if ((sd->seento || !sd->seenfrom) && !istosnapwithnofrom) { | ||||
zfs_close(zhp); | zfs_close(zhp); | ||||
return (0); | return (0); | ||||
} | } | ||||
if (istosnap) | if (istosnap) | ||||
sd->seento = B_TRUE; | sd->seento = B_TRUE; | ||||
} | } | ||||
VERIFY(0 == nvlist_alloc(&nv, NV_UNIQUE_NAME, 0)); | nv = fnvlist_alloc(); | ||||
send_iterate_prop(zhp, sd->backup, nv); | send_iterate_prop(zhp, sd->backup, nv); | ||||
VERIFY(0 == nvlist_add_nvlist(sd->snapprops, snapname, nv)); | fnvlist_add_nvlist(sd->snapprops, snapname, nv); | ||||
nvlist_free(nv); | fnvlist_free(nv); | ||||
if (sd->holds) { | if (sd->holds) { | ||||
nvlist_t *holds = fnvlist_alloc(); | nvlist_t *holds = fnvlist_alloc(); | ||||
int err = lzc_get_holds(zhp->zfs_name, &holds); | int err = lzc_get_holds(zhp->zfs_name, &holds); | ||||
if (err == 0) { | if (err == 0) { | ||||
VERIFY(0 == nvlist_add_nvlist(sd->snapholds, | fnvlist_add_nvlist(sd->snapholds, snapname, holds); | ||||
snapname, holds)); | |||||
} | } | ||||
fnvlist_free(holds); | fnvlist_free(holds); | ||||
} | } | ||||
zfs_close(zhp); | zfs_close(zhp); | ||||
return (0); | return (0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | if (prop == ZFS_PROP_QUOTA || prop == ZFS_PROP_RESERVATION || | ||||
if ((strcmp(source, zhp->zfs_name) != 0) && | if ((strcmp(source, zhp->zfs_name) != 0) && | ||||
(strcmp(source, ZPROP_SOURCE_VAL_RECVD) != 0)) | (strcmp(source, ZPROP_SOURCE_VAL_RECVD) != 0)) | ||||
continue; | continue; | ||||
} | } | ||||
if (zfs_prop_user(propname) || | if (zfs_prop_user(propname) || | ||||
zfs_prop_get_type(prop) == PROP_TYPE_STRING) { | zfs_prop_get_type(prop) == PROP_TYPE_STRING) { | ||||
char *value; | char *value; | ||||
verify(nvlist_lookup_string(propnv, | value = fnvlist_lookup_string(propnv, ZPROP_VALUE); | ||||
ZPROP_VALUE, &value) == 0); | fnvlist_add_string(nv, propname, value); | ||||
VERIFY(0 == nvlist_add_string(nv, propname, value)); | |||||
} else { | } else { | ||||
uint64_t value; | uint64_t value; | ||||
verify(nvlist_lookup_uint64(propnv, | value = fnvlist_lookup_uint64(propnv, ZPROP_VALUE); | ||||
ZPROP_VALUE, &value) == 0); | fnvlist_add_uint64(nv, propname, value); | ||||
VERIFY(0 == nvlist_add_uint64(nv, propname, value)); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* returns snapshot creation txg | * returns snapshot creation txg | ||||
* and returns 0 if the snapshot does not exist | * and returns 0 if the snapshot does not exist | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | send_iterate_fs(zfs_handle_t *zhp, void *arg) | ||||
if (nv != NULL) | if (nv != NULL) | ||||
fnvlist_add_nvlist(nvfs, "props", nv); | fnvlist_add_nvlist(nvfs, "props", nv); | ||||
/* iterate over snaps, and set sd->parent_fromsnap_guid */ | /* iterate over snaps, and set sd->parent_fromsnap_guid */ | ||||
sd->parent_fromsnap_guid = 0; | sd->parent_fromsnap_guid = 0; | ||||
sd->parent_snaps = fnvlist_alloc(); | sd->parent_snaps = fnvlist_alloc(); | ||||
sd->snapprops = fnvlist_alloc(); | sd->snapprops = fnvlist_alloc(); | ||||
if (sd->holds) | if (sd->holds) | ||||
VERIFY(0 == nvlist_alloc(&sd->snapholds, NV_UNIQUE_NAME, 0)); | sd->snapholds = fnvlist_alloc(); | ||||
/* | /* | ||||
* If this is a "doall" send, a replicate send or we're just trying | * If this is a "doall" send, a replicate send or we're just trying | ||||
* to gather a list of previous snapshots, iterate through all the | * to gather a list of previous snapshots, iterate through all the | ||||
* snaps in the txg range. Otherwise just look at the one we're | * snaps in the txg range. Otherwise just look at the one we're | ||||
* interested in. | * interested in. | ||||
*/ | */ | ||||
if (sd->doall || sd->replicate || sd->tosnap == NULL) { | if (sd->doall || sd->replicate || sd->tosnap == NULL) { | ||||
if (!sd->replicate && fromsnap_txg != 0) | if (!sd->replicate && fromsnap_txg != 0) | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | gather_nvlist(libzfs_handle_t *hdl, const char *fsname, const char *fromsnap, | ||||
zfs_handle_t *zhp; | zfs_handle_t *zhp; | ||||
send_data_t sd = { 0 }; | send_data_t sd = { 0 }; | ||||
int error; | int error; | ||||
zhp = zfs_open(hdl, fsname, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); | zhp = zfs_open(hdl, fsname, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); | ||||
if (zhp == NULL) | if (zhp == NULL) | ||||
return (EZFS_BADTYPE); | return (EZFS_BADTYPE); | ||||
VERIFY(0 == nvlist_alloc(&sd.fss, NV_UNIQUE_NAME, 0)); | sd.fss = fnvlist_alloc(); | ||||
sd.fsname = fsname; | sd.fsname = fsname; | ||||
sd.fromsnap = fromsnap; | sd.fromsnap = fromsnap; | ||||
sd.tosnap = tosnap; | sd.tosnap = tosnap; | ||||
sd.recursive = recursive; | sd.recursive = recursive; | ||||
sd.raw = raw; | sd.raw = raw; | ||||
sd.doall = doall; | sd.doall = doall; | ||||
sd.replicate = replicate; | sd.replicate = replicate; | ||||
sd.verbose = verbose; | sd.verbose = verbose; | ||||
sd.backup = backup; | sd.backup = backup; | ||||
sd.holds = holds; | sd.holds = holds; | ||||
sd.props = props; | sd.props = props; | ||||
if ((error = send_iterate_fs(zhp, &sd)) != 0) { | if ((error = send_iterate_fs(zhp, &sd)) != 0) { | ||||
nvlist_free(sd.fss); | fnvlist_free(sd.fss); | ||||
if (avlp != NULL) | if (avlp != NULL) | ||||
*avlp = NULL; | *avlp = NULL; | ||||
*nvlp = NULL; | *nvlp = NULL; | ||||
return (error); | return (error); | ||||
} | } | ||||
if (avlp != NULL && (*avlp = fsavl_create(sd.fss)) == NULL) { | if (avlp != NULL && (*avlp = fsavl_create(sd.fss)) == NULL) { | ||||
nvlist_free(sd.fss); | fnvlist_free(sd.fss); | ||||
*nvlp = NULL; | *nvlp = NULL; | ||||
return (EZFS_NOMEM); | return (EZFS_NOMEM); | ||||
} | } | ||||
*nvlp = sd.fss; | *nvlp = sd.fss; | ||||
return (0); | return (0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | dump_ioctl(zfs_handle_t *zhp, const char *fromsnap, uint64_t fromsnap_obj, | ||||
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); | (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); | ||||
zc.zc_cookie = outfd; | zc.zc_cookie = outfd; | ||||
zc.zc_obj = fromorigin; | zc.zc_obj = fromorigin; | ||||
zc.zc_sendobj = zfs_prop_get_int(zhp, ZFS_PROP_OBJSETID); | zc.zc_sendobj = zfs_prop_get_int(zhp, ZFS_PROP_OBJSETID); | ||||
zc.zc_fromobj = fromsnap_obj; | zc.zc_fromobj = fromsnap_obj; | ||||
zc.zc_flags = flags; | zc.zc_flags = flags; | ||||
VERIFY(0 == nvlist_alloc(&thisdbg, NV_UNIQUE_NAME, 0)); | thisdbg = fnvlist_alloc(); | ||||
if (fromsnap && fromsnap[0] != '\0') { | if (fromsnap && fromsnap[0] != '\0') { | ||||
VERIFY(0 == nvlist_add_string(thisdbg, | fnvlist_add_string(thisdbg, "fromsnap", fromsnap); | ||||
"fromsnap", fromsnap)); | |||||
} | } | ||||
if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SEND, &zc) != 0) { | if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SEND, &zc) != 0) { | ||||
char errbuf[1024]; | char errbuf[1024]; | ||||
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, | (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, | ||||
"warning: cannot send '%s'"), zhp->zfs_name); | "warning: cannot send '%s'"), zhp->zfs_name); | ||||
VERIFY(0 == nvlist_add_uint64(thisdbg, "error", errno)); | fnvlist_add_uint64(thisdbg, "error", errno); | ||||
if (debugnv) { | if (debugnv) { | ||||
VERIFY(0 == nvlist_add_nvlist(debugnv, | fnvlist_add_nvlist(debugnv, zhp->zfs_name, thisdbg); | ||||
zhp->zfs_name, thisdbg)); | |||||
} | } | ||||
nvlist_free(thisdbg); | fnvlist_free(thisdbg); | ||||
switch (errno) { | switch (errno) { | ||||
case EXDEV: | case EXDEV: | ||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | ||||
"not an earlier snapshot from the same fs")); | "not an earlier snapshot from the same fs")); | ||||
return (zfs_error(hdl, EZFS_CROSSTARGET, errbuf)); | return (zfs_error(hdl, EZFS_CROSSTARGET, errbuf)); | ||||
case EACCES: | case EACCES: | ||||
Show All 25 Lines | case EROFS: | ||||
return (zfs_error(hdl, EZFS_BADBACKUP, errbuf)); | return (zfs_error(hdl, EZFS_BADBACKUP, errbuf)); | ||||
default: | default: | ||||
return (zfs_standard_error(hdl, errno, errbuf)); | return (zfs_standard_error(hdl, errno, errbuf)); | ||||
} | } | ||||
} | } | ||||
if (debugnv) | if (debugnv) | ||||
VERIFY(0 == nvlist_add_nvlist(debugnv, zhp->zfs_name, thisdbg)); | fnvlist_add_nvlist(debugnv, zhp->zfs_name, thisdbg); | ||||
nvlist_free(thisdbg); | fnvlist_free(thisdbg); | ||||
return (0); | return (0); | ||||
} | } | ||||
static void | static void | ||||
gather_holds(zfs_handle_t *zhp, send_dump_data_t *sdd) | gather_holds(zfs_handle_t *zhp, send_dump_data_t *sdd) | ||||
{ | { | ||||
assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT); | assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT); | ||||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | if (sdd->replicate) { | ||||
nvlist_t *snapprops; | nvlist_t *snapprops; | ||||
/* | /* | ||||
* Filter out all intermediate snapshots except origin | * Filter out all intermediate snapshots except origin | ||||
* snapshots needed to replicate clones. | * snapshots needed to replicate clones. | ||||
*/ | */ | ||||
nvlist_t *nvfs = fsavl_find(sdd->fsavl, | nvlist_t *nvfs = fsavl_find(sdd->fsavl, | ||||
zhp->zfs_dmustats.dds_guid, &snapname); | zhp->zfs_dmustats.dds_guid, &snapname); | ||||
VERIFY(0 == nvlist_lookup_nvlist(nvfs, | snapprops = fnvlist_lookup_nvlist(nvfs, "snapprops"); | ||||
"snapprops", &snapprops)); | snapprops = fnvlist_lookup_nvlist(snapprops, thissnap); | ||||
VERIFY(0 == nvlist_lookup_nvlist(snapprops, | |||||
thissnap, &snapprops)); | |||||
exclude = !nvlist_exists(snapprops, "is_clone_origin"); | exclude = !nvlist_exists(snapprops, "is_clone_origin"); | ||||
} else { | } else { | ||||
exclude = B_TRUE; | exclude = B_TRUE; | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* If a filter function exists, call it to determine whether | * If a filter function exists, call it to determine whether | ||||
▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | if (!sdd->replicate) | ||||
return (dump_filesystem(rzhp, sdd)); | return (dump_filesystem(rzhp, sdd)); | ||||
/* Mark the clone origin snapshots. */ | /* Mark the clone origin snapshots. */ | ||||
for (fspair = nvlist_next_nvpair(sdd->fss, NULL); fspair; | for (fspair = nvlist_next_nvpair(sdd->fss, NULL); fspair; | ||||
fspair = nvlist_next_nvpair(sdd->fss, fspair)) { | fspair = nvlist_next_nvpair(sdd->fss, fspair)) { | ||||
nvlist_t *nvfs; | nvlist_t *nvfs; | ||||
uint64_t origin_guid = 0; | uint64_t origin_guid = 0; | ||||
VERIFY(0 == nvpair_value_nvlist(fspair, &nvfs)); | nvfs = fnvpair_value_nvlist(fspair); | ||||
(void) nvlist_lookup_uint64(nvfs, "origin", &origin_guid); | (void) nvlist_lookup_uint64(nvfs, "origin", &origin_guid); | ||||
if (origin_guid != 0) { | if (origin_guid != 0) { | ||||
char *snapname; | char *snapname; | ||||
nvlist_t *origin_nv = fsavl_find(sdd->fsavl, | nvlist_t *origin_nv = fsavl_find(sdd->fsavl, | ||||
origin_guid, &snapname); | origin_guid, &snapname); | ||||
if (origin_nv != NULL) { | if (origin_nv != NULL) { | ||||
nvlist_t *snapprops; | nvlist_t *snapprops; | ||||
VERIFY(0 == nvlist_lookup_nvlist(origin_nv, | snapprops = fnvlist_lookup_nvlist(origin_nv, | ||||
"snapprops", &snapprops)); | "snapprops"); | ||||
VERIFY(0 == nvlist_lookup_nvlist(snapprops, | snapprops = fnvlist_lookup_nvlist(snapprops, | ||||
snapname, &snapprops)); | snapname); | ||||
VERIFY(0 == nvlist_add_boolean( | fnvlist_add_boolean(snapprops, | ||||
snapprops, "is_clone_origin")); | "is_clone_origin"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
again: | again: | ||||
needagain = progress = B_FALSE; | needagain = progress = B_FALSE; | ||||
for (fspair = nvlist_next_nvpair(sdd->fss, NULL); fspair; | for (fspair = nvlist_next_nvpair(sdd->fss, NULL); fspair; | ||||
fspair = nvlist_next_nvpair(sdd->fss, fspair)) { | fspair = nvlist_next_nvpair(sdd->fss, fspair)) { | ||||
nvlist_t *fslist, *parent_nv; | nvlist_t *fslist, *parent_nv; | ||||
char *fsname; | char *fsname; | ||||
zfs_handle_t *zhp; | zfs_handle_t *zhp; | ||||
int err; | int err; | ||||
uint64_t origin_guid = 0; | uint64_t origin_guid = 0; | ||||
uint64_t parent_guid = 0; | uint64_t parent_guid = 0; | ||||
VERIFY(nvpair_value_nvlist(fspair, &fslist) == 0); | fslist = fnvpair_value_nvlist(fspair); | ||||
if (nvlist_lookup_boolean(fslist, "sent") == 0) | if (nvlist_lookup_boolean(fslist, "sent") == 0) | ||||
continue; | continue; | ||||
VERIFY(nvlist_lookup_string(fslist, "name", &fsname) == 0); | fsname = fnvlist_lookup_string(fslist, "name"); | ||||
(void) nvlist_lookup_uint64(fslist, "origin", &origin_guid); | (void) nvlist_lookup_uint64(fslist, "origin", &origin_guid); | ||||
(void) nvlist_lookup_uint64(fslist, "parentfromsnap", | (void) nvlist_lookup_uint64(fslist, "parentfromsnap", | ||||
&parent_guid); | &parent_guid); | ||||
if (parent_guid != 0) { | if (parent_guid != 0) { | ||||
parent_nv = fsavl_find(sdd->fsavl, parent_guid, NULL); | parent_nv = fsavl_find(sdd->fsavl, parent_guid, NULL); | ||||
if (!nvlist_exists(parent_nv, "sent")) { | if (!nvlist_exists(parent_nv, "sent")) { | ||||
/* parent has not been sent; skip this one */ | /* parent has not been sent; skip this one */ | ||||
Show All 15 Lines | if (origin_guid != 0) { | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
zhp = zfs_open(rzhp->zfs_hdl, fsname, ZFS_TYPE_DATASET); | zhp = zfs_open(rzhp->zfs_hdl, fsname, ZFS_TYPE_DATASET); | ||||
if (zhp == NULL) | if (zhp == NULL) | ||||
return (-1); | return (-1); | ||||
err = dump_filesystem(zhp, sdd); | err = dump_filesystem(zhp, sdd); | ||||
VERIFY(nvlist_add_boolean(fslist, "sent") == 0); | fnvlist_add_boolean(fslist, "sent"); | ||||
progress = B_TRUE; | progress = B_TRUE; | ||||
zfs_close(zhp); | zfs_close(zhp); | ||||
if (err) | if (err) | ||||
return (err); | return (err); | ||||
} | } | ||||
if (needagain) { | if (needagain) { | ||||
assert(progress); | assert(progress); | ||||
goto again; | goto again; | ||||
} | } | ||||
/* clean out the sent flags in case we reuse this fss */ | /* clean out the sent flags in case we reuse this fss */ | ||||
for (fspair = nvlist_next_nvpair(sdd->fss, NULL); fspair; | for (fspair = nvlist_next_nvpair(sdd->fss, NULL); fspair; | ||||
fspair = nvlist_next_nvpair(sdd->fss, fspair)) { | fspair = nvlist_next_nvpair(sdd->fss, fspair)) { | ||||
nvlist_t *fslist; | nvlist_t *fslist; | ||||
VERIFY(nvpair_value_nvlist(fspair, &fslist) == 0); | fslist = fnvpair_value_nvlist(fspair); | ||||
(void) nvlist_remove_all(fslist, "sent"); | (void) nvlist_remove_all(fslist, "sent"); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
nvlist_t * | nvlist_t * | ||||
zfs_send_resume_token_to_nvlist(libzfs_handle_t *hdl, const char *token) | zfs_send_resume_token_to_nvlist(libzfs_handle_t *hdl, const char *token) | ||||
▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | find_redact_book(libzfs_handle_t *hdl, const char *path, | ||||
nvlist_t *bmarks; | nvlist_t *bmarks; | ||||
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, | (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, | ||||
"cannot resume send")); | "cannot resume send")); | ||||
fnvlist_add_boolean(props, "redact_complete"); | fnvlist_add_boolean(props, "redact_complete"); | ||||
fnvlist_add_boolean(props, zfs_prop_to_name(ZFS_PROP_REDACT_SNAPS)); | fnvlist_add_boolean(props, zfs_prop_to_name(ZFS_PROP_REDACT_SNAPS)); | ||||
error = lzc_get_bookmarks(path, props, &bmarks); | error = lzc_get_bookmarks(path, props, &bmarks); | ||||
nvlist_free(props); | fnvlist_free(props); | ||||
if (error != 0) { | if (error != 0) { | ||||
if (error == ESRCH) { | if (error == ESRCH) { | ||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | ||||
"nonexistent redaction bookmark provided")); | "nonexistent redaction bookmark provided")); | ||||
} else if (error == ENOENT) { | } else if (error == ENOENT) { | ||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | ||||
"dataset to be sent no longer exists")); | "dataset to be sent no longer exists")); | ||||
} else { | } else { | ||||
▲ Show 20 Lines • Show All 273 Lines • ▼ Show 20 Lines | if (resume_nvl == NULL) { | ||||
/* | /* | ||||
* zfs_error_aux has already been set by | * zfs_error_aux has already been set by | ||||
* zfs_send_resume_token_to_nvlist() | * zfs_send_resume_token_to_nvlist() | ||||
*/ | */ | ||||
return (zfs_error(hdl, EZFS_FAULT, errbuf)); | return (zfs_error(hdl, EZFS_FAULT, errbuf)); | ||||
} | } | ||||
ret = zfs_send_resume_impl(hdl, flags, outfd, resume_nvl); | ret = zfs_send_resume_impl(hdl, flags, outfd, resume_nvl); | ||||
nvlist_free(resume_nvl); | fnvlist_free(resume_nvl); | ||||
return (ret); | return (ret); | ||||
} | } | ||||
int | int | ||||
zfs_send_saved(zfs_handle_t *zhp, sendflags_t *flags, int outfd, | zfs_send_saved(zfs_handle_t *zhp, sendflags_t *flags, int outfd, | ||||
const char *resume_token) | const char *resume_token) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | zfs_send_saved(zfs_handle_t *zhp, sendflags_t *flags, int outfd, | ||||
fnvlist_add_uint64(saved_nvl, "bytes", bytes); | fnvlist_add_uint64(saved_nvl, "bytes", bytes); | ||||
(void) nvlist_remove_all(saved_nvl, "toname"); | (void) nvlist_remove_all(saved_nvl, "toname"); | ||||
fnvlist_add_string(saved_nvl, "toname", zhp->zfs_name); | fnvlist_add_string(saved_nvl, "toname", zhp->zfs_name); | ||||
ret = zfs_send_resume_impl(hdl, flags, outfd, saved_nvl); | ret = zfs_send_resume_impl(hdl, flags, outfd, saved_nvl); | ||||
out: | out: | ||||
nvlist_free(saved_nvl); | fnvlist_free(saved_nvl); | ||||
nvlist_free(resume_nvl); | fnvlist_free(resume_nvl); | ||||
return (ret); | return (ret); | ||||
} | } | ||||
/* | /* | ||||
* This function informs the target system that the recursive send is complete. | * This function informs the target system that the recursive send is complete. | ||||
* The record is also expected in the case of a send -p. | * The record is also expected in the case of a send -p. | ||||
*/ | */ | ||||
static int | static int | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | if (gather_props) { | ||||
if (from != NULL) | if (from != NULL) | ||||
fnvlist_add_string(hdrnv, "fromsnap", from); | fnvlist_add_string(hdrnv, "fromsnap", from); | ||||
fnvlist_add_string(hdrnv, "tosnap", tosnap); | fnvlist_add_string(hdrnv, "tosnap", tosnap); | ||||
if (!recursive) | if (!recursive) | ||||
fnvlist_add_boolean(hdrnv, "not_recursive"); | fnvlist_add_boolean(hdrnv, "not_recursive"); | ||||
if (raw) { | if (raw) { | ||||
VERIFY0(nvlist_add_boolean(hdrnv, "raw")); | fnvlist_add_boolean(hdrnv, "raw"); | ||||
} | } | ||||
if ((err = gather_nvlist(zhp->zfs_hdl, tofs, | if ((err = gather_nvlist(zhp->zfs_hdl, tofs, | ||||
from, tosnap, recursive, raw, doall, replicate, verbose, | from, tosnap, recursive, raw, doall, replicate, verbose, | ||||
backup, holds, props, &fss, fsavlp)) != 0) { | backup, holds, props, &fss, fsavlp)) != 0) { | ||||
return (zfs_error(zhp->zfs_hdl, EZFS_BADBACKUP, | return (zfs_error(zhp->zfs_hdl, EZFS_BADBACKUP, | ||||
errbuf)); | errbuf)); | ||||
} | } | ||||
Show All 13 Lines | if ((fnvlist_size(fss) + fnvlist_size(hdrnv)) > | ||||
errbuf)); | errbuf)); | ||||
} | } | ||||
fnvlist_add_nvlist(hdrnv, "fss", fss); | fnvlist_add_nvlist(hdrnv, "fss", fss); | ||||
VERIFY0(nvlist_pack(hdrnv, &packbuf, &buflen, NV_ENCODE_XDR, | VERIFY0(nvlist_pack(hdrnv, &packbuf, &buflen, NV_ENCODE_XDR, | ||||
0)); | 0)); | ||||
if (fssp != NULL) { | if (fssp != NULL) { | ||||
*fssp = fss; | *fssp = fss; | ||||
} else { | } else { | ||||
nvlist_free(fss); | fnvlist_free(fss); | ||||
} | } | ||||
nvlist_free(hdrnv); | fnvlist_free(hdrnv); | ||||
} | } | ||||
if (!dryrun) { | if (!dryrun) { | ||||
dmu_replay_record_t drr = { 0 }; | dmu_replay_record_t drr = { 0 }; | ||||
/* write first begin record */ | /* write first begin record */ | ||||
drr.drr_type = DRR_BEGIN; | drr.drr_type = DRR_BEGIN; | ||||
drr.drr_u.drr_begin.drr_magic = DMU_BACKUP_MAGIC; | drr.drr_u.drr_begin.drr_magic = DMU_BACKUP_MAGIC; | ||||
DMU_SET_STREAM_HDRTYPE(drr.drr_u.drr_begin. | DMU_SET_STREAM_HDRTYPE(drr.drr_u.drr_begin. | ||||
▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | if (flags->verbosity != 0 || sdd.snapholds != NULL) { | ||||
} | } | ||||
sdd.dryrun = B_FALSE; | sdd.dryrun = B_FALSE; | ||||
sdd.verbosity = 0; | sdd.verbosity = 0; | ||||
} | } | ||||
err = dump_filesystems(zhp, &sdd); | err = dump_filesystems(zhp, &sdd); | ||||
fsavl_destroy(fsavl); | fsavl_destroy(fsavl); | ||||
nvlist_free(fss); | fnvlist_free(fss); | ||||
/* Ensure no snaps found is treated as an error. */ | /* Ensure no snaps found is treated as an error. */ | ||||
if (err == 0 && !sdd.seento) | if (err == 0 && !sdd.seento) | ||||
err = ENOENT; | err = ENOENT; | ||||
if (sdd.cleanup_fd != -1) { | if (sdd.cleanup_fd != -1) { | ||||
VERIFY(0 == close(sdd.cleanup_fd)); | VERIFY(0 == close(sdd.cleanup_fd)); | ||||
sdd.cleanup_fd = -1; | sdd.cleanup_fd = -1; | ||||
Show All 12 Lines | zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, | ||||
} | } | ||||
return (err || sdd.err); | return (err || sdd.err); | ||||
stderr_out: | stderr_out: | ||||
err = zfs_standard_error(zhp->zfs_hdl, err, errbuf); | err = zfs_standard_error(zhp->zfs_hdl, err, errbuf); | ||||
err_out: | err_out: | ||||
fsavl_destroy(fsavl); | fsavl_destroy(fsavl); | ||||
nvlist_free(fss); | fnvlist_free(fss); | ||||
fnvlist_free(sdd.snapholds); | fnvlist_free(sdd.snapholds); | ||||
if (sdd.cleanup_fd != -1) | if (sdd.cleanup_fd != -1) | ||||
VERIFY(0 == close(sdd.cleanup_fd)); | VERIFY(0 == close(sdd.cleanup_fd)); | ||||
return (err); | return (err); | ||||
} | } | ||||
static zfs_handle_t * | static zfs_handle_t * | ||||
▲ Show 20 Lines • Show All 728 Lines • ▼ Show 20 Lines | created_before(libzfs_handle_t *hdl, avl_tree_t *avl, | ||||
uint64_t create1, create2; | uint64_t create1, create2; | ||||
if (guid2 == 0) | if (guid2 == 0) | ||||
return (0); | return (0); | ||||
if (guid1 == 0) | if (guid1 == 0) | ||||
return (1); | return (1); | ||||
nvfs = fsavl_find(avl, guid1, &snapname); | nvfs = fsavl_find(avl, guid1, &snapname); | ||||
VERIFY(0 == nvlist_lookup_string(nvfs, "name", &fsname)); | fsname = fnvlist_lookup_string(nvfs, "name"); | ||||
(void) snprintf(buf, sizeof (buf), "%s@%s", fsname, snapname); | (void) snprintf(buf, sizeof (buf), "%s@%s", fsname, snapname); | ||||
guid1hdl = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT); | guid1hdl = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT); | ||||
if (guid1hdl == NULL) | if (guid1hdl == NULL) | ||||
return (-1); | return (-1); | ||||
nvfs = fsavl_find(avl, guid2, &snapname); | nvfs = fsavl_find(avl, guid2, &snapname); | ||||
VERIFY(0 == nvlist_lookup_string(nvfs, "name", &fsname)); | fsname = fnvlist_lookup_string(nvfs, "name"); | ||||
(void) snprintf(buf, sizeof (buf), "%s@%s", fsname, snapname); | (void) snprintf(buf, sizeof (buf), "%s@%s", fsname, snapname); | ||||
guid2hdl = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT); | guid2hdl = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT); | ||||
if (guid2hdl == NULL) { | if (guid2hdl == NULL) { | ||||
zfs_close(guid1hdl); | zfs_close(guid1hdl); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
create1 = zfs_prop_get_int(guid1hdl, ZFS_PROP_CREATETXG); | create1 = zfs_prop_get_int(guid1hdl, ZFS_PROP_CREATETXG); | ||||
Show All 21 Lines | |||||
static int | static int | ||||
recv_fix_encryption_hierarchy(libzfs_handle_t *hdl, const char *top_zfs, | recv_fix_encryption_hierarchy(libzfs_handle_t *hdl, const char *top_zfs, | ||||
nvlist_t *stream_nv, avl_tree_t *stream_avl) | nvlist_t *stream_nv, avl_tree_t *stream_avl) | ||||
{ | { | ||||
int err; | int err; | ||||
nvpair_t *fselem = NULL; | nvpair_t *fselem = NULL; | ||||
nvlist_t *stream_fss; | nvlist_t *stream_fss; | ||||
VERIFY(0 == nvlist_lookup_nvlist(stream_nv, "fss", &stream_fss)); | stream_fss = fnvlist_lookup_nvlist(stream_nv, "fss"); | ||||
while ((fselem = nvlist_next_nvpair(stream_fss, fselem)) != NULL) { | while ((fselem = nvlist_next_nvpair(stream_fss, fselem)) != NULL) { | ||||
zfs_handle_t *zhp = NULL; | zfs_handle_t *zhp = NULL; | ||||
uint64_t crypt; | uint64_t crypt; | ||||
nvlist_t *snaps, *props, *stream_nvfs = NULL; | nvlist_t *snaps, *props, *stream_nvfs = NULL; | ||||
nvpair_t *snapel = NULL; | nvpair_t *snapel = NULL; | ||||
boolean_t is_encroot, is_clone, stream_encroot; | boolean_t is_encroot, is_clone, stream_encroot; | ||||
char *cp; | char *cp; | ||||
char *stream_keylocation = NULL; | char *stream_keylocation = NULL; | ||||
char keylocation[MAXNAMELEN]; | char keylocation[MAXNAMELEN]; | ||||
char fsname[ZFS_MAX_DATASET_NAME_LEN]; | char fsname[ZFS_MAX_DATASET_NAME_LEN]; | ||||
keylocation[0] = '\0'; | keylocation[0] = '\0'; | ||||
VERIFY(0 == nvpair_value_nvlist(fselem, &stream_nvfs)); | stream_nvfs = fnvpair_value_nvlist(fselem); | ||||
VERIFY(0 == nvlist_lookup_nvlist(stream_nvfs, "snaps", &snaps)); | snaps = fnvlist_lookup_nvlist(stream_nvfs, "snaps"); | ||||
VERIFY(0 == nvlist_lookup_nvlist(stream_nvfs, "props", &props)); | props = fnvlist_lookup_nvlist(stream_nvfs, "props"); | ||||
stream_encroot = nvlist_exists(stream_nvfs, "is_encroot"); | stream_encroot = nvlist_exists(stream_nvfs, "is_encroot"); | ||||
/* find a snapshot from the stream that exists locally */ | /* find a snapshot from the stream that exists locally */ | ||||
err = ENOENT; | err = ENOENT; | ||||
while ((snapel = nvlist_next_nvpair(snaps, snapel)) != NULL) { | while ((snapel = nvlist_next_nvpair(snaps, snapel)) != NULL) { | ||||
uint64_t guid; | uint64_t guid; | ||||
VERIFY(0 == nvpair_value_uint64(snapel, &guid)); | guid = fnvpair_value_uint64(snapel); | ||||
err = guid_to_name(hdl, top_zfs, guid, B_FALSE, | err = guid_to_name(hdl, top_zfs, guid, B_FALSE, | ||||
fsname); | fsname); | ||||
if (err == 0) | if (err == 0) | ||||
break; | break; | ||||
} | } | ||||
if (err != 0) | if (err != 0) | ||||
continue; | continue; | ||||
Show All 28 Lines | if (stream_encroot) { | ||||
err = lzc_change_key(fsname, | err = lzc_change_key(fsname, | ||||
DCP_CMD_FORCE_NEW_KEY, NULL, NULL, 0); | DCP_CMD_FORCE_NEW_KEY, NULL, NULL, 0); | ||||
if (err != 0) { | if (err != 0) { | ||||
zfs_close(zhp); | zfs_close(zhp); | ||||
goto error; | goto error; | ||||
} | } | ||||
} | } | ||||
VERIFY(0 == nvlist_lookup_string(props, | stream_keylocation = fnvlist_lookup_string(props, | ||||
zfs_prop_to_name(ZFS_PROP_KEYLOCATION), | zfs_prop_to_name(ZFS_PROP_KEYLOCATION)); | ||||
&stream_keylocation)); | |||||
/* | /* | ||||
* Refresh the properties in case the call to | * Refresh the properties in case the call to | ||||
* lzc_change_key() changed the value. | * lzc_change_key() changed the value. | ||||
*/ | */ | ||||
zfs_refresh_properties(zhp); | zfs_refresh_properties(zhp); | ||||
err = zfs_prop_get(zhp, ZFS_PROP_KEYLOCATION, | err = zfs_prop_get(zhp, ZFS_PROP_KEYLOCATION, | ||||
keylocation, sizeof (keylocation), NULL, NULL, | keylocation, sizeof (keylocation), NULL, NULL, | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs, | ||||
nvpair_t *fselem, *nextfselem; | nvpair_t *fselem, *nextfselem; | ||||
char *fromsnap; | char *fromsnap; | ||||
char newname[ZFS_MAX_DATASET_NAME_LEN]; | char newname[ZFS_MAX_DATASET_NAME_LEN]; | ||||
char guidname[32]; | char guidname[32]; | ||||
int error; | int error; | ||||
boolean_t needagain, progress, recursive; | boolean_t needagain, progress, recursive; | ||||
char *s1, *s2; | char *s1, *s2; | ||||
VERIFY(0 == nvlist_lookup_string(stream_nv, "fromsnap", &fromsnap)); | fromsnap = fnvlist_lookup_string(stream_nv, "fromsnap"); | ||||
recursive = (nvlist_lookup_boolean(stream_nv, "not_recursive") == | recursive = (nvlist_lookup_boolean(stream_nv, "not_recursive") == | ||||
ENOENT); | ENOENT); | ||||
if (flags->dryrun) | if (flags->dryrun) | ||||
return (0); | return (0); | ||||
again: | again: | ||||
needagain = progress = B_FALSE; | needagain = progress = B_FALSE; | ||||
VERIFY(0 == nvlist_alloc(&deleted, NV_UNIQUE_NAME, 0)); | deleted = fnvlist_alloc(); | ||||
if ((error = gather_nvlist(hdl, tofs, fromsnap, NULL, | if ((error = gather_nvlist(hdl, tofs, fromsnap, NULL, | ||||
recursive, B_TRUE, B_FALSE, recursive, B_FALSE, B_FALSE, | recursive, B_TRUE, B_FALSE, recursive, B_FALSE, B_FALSE, | ||||
B_FALSE, B_TRUE, &local_nv, &local_avl)) != 0) | B_FALSE, B_TRUE, &local_nv, &local_avl)) != 0) | ||||
return (error); | return (error); | ||||
/* | /* | ||||
* Process deletes and renames | * Process deletes and renames | ||||
*/ | */ | ||||
for (fselem = nvlist_next_nvpair(local_nv, NULL); | for (fselem = nvlist_next_nvpair(local_nv, NULL); | ||||
fselem; fselem = nextfselem) { | fselem; fselem = nextfselem) { | ||||
nvlist_t *nvfs, *snaps; | nvlist_t *nvfs, *snaps; | ||||
nvlist_t *stream_nvfs = NULL; | nvlist_t *stream_nvfs = NULL; | ||||
nvpair_t *snapelem, *nextsnapelem; | nvpair_t *snapelem, *nextsnapelem; | ||||
uint64_t fromguid = 0; | uint64_t fromguid = 0; | ||||
uint64_t originguid = 0; | uint64_t originguid = 0; | ||||
uint64_t stream_originguid = 0; | uint64_t stream_originguid = 0; | ||||
uint64_t parent_fromsnap_guid, stream_parent_fromsnap_guid; | uint64_t parent_fromsnap_guid, stream_parent_fromsnap_guid; | ||||
char *fsname, *stream_fsname; | char *fsname, *stream_fsname; | ||||
nextfselem = nvlist_next_nvpair(local_nv, fselem); | nextfselem = nvlist_next_nvpair(local_nv, fselem); | ||||
VERIFY(0 == nvpair_value_nvlist(fselem, &nvfs)); | nvfs = fnvpair_value_nvlist(fselem); | ||||
VERIFY(0 == nvlist_lookup_nvlist(nvfs, "snaps", &snaps)); | snaps = fnvlist_lookup_nvlist(nvfs, "snaps"); | ||||
VERIFY(0 == nvlist_lookup_string(nvfs, "name", &fsname)); | fsname = fnvlist_lookup_string(nvfs, "name"); | ||||
VERIFY(0 == nvlist_lookup_uint64(nvfs, "parentfromsnap", | parent_fromsnap_guid = fnvlist_lookup_uint64(nvfs, | ||||
&parent_fromsnap_guid)); | "parentfromsnap"); | ||||
(void) nvlist_lookup_uint64(nvfs, "origin", &originguid); | (void) nvlist_lookup_uint64(nvfs, "origin", &originguid); | ||||
/* | /* | ||||
* First find the stream's fs, so we can check for | * First find the stream's fs, so we can check for | ||||
* a different origin (due to "zfs promote") | * a different origin (due to "zfs promote") | ||||
*/ | */ | ||||
for (snapelem = nvlist_next_nvpair(snaps, NULL); | for (snapelem = nvlist_next_nvpair(snaps, NULL); | ||||
snapelem; snapelem = nvlist_next_nvpair(snaps, snapelem)) { | snapelem; snapelem = nvlist_next_nvpair(snaps, snapelem)) { | ||||
uint64_t thisguid; | uint64_t thisguid; | ||||
VERIFY(0 == nvpair_value_uint64(snapelem, &thisguid)); | thisguid = fnvpair_value_uint64(snapelem); | ||||
stream_nvfs = fsavl_find(stream_avl, thisguid, NULL); | stream_nvfs = fsavl_find(stream_avl, thisguid, NULL); | ||||
if (stream_nvfs != NULL) | if (stream_nvfs != NULL) | ||||
break; | break; | ||||
} | } | ||||
/* check for promote */ | /* check for promote */ | ||||
(void) nvlist_lookup_uint64(stream_nvfs, "origin", | (void) nvlist_lookup_uint64(stream_nvfs, "origin", | ||||
&stream_originguid); | &stream_originguid); | ||||
if (stream_nvfs && originguid != stream_originguid) { | if (stream_nvfs && originguid != stream_originguid) { | ||||
switch (created_before(hdl, local_avl, | switch (created_before(hdl, local_avl, | ||||
stream_originguid, originguid)) { | stream_originguid, originguid)) { | ||||
case 1: { | case 1: { | ||||
/* promote it! */ | /* promote it! */ | ||||
nvlist_t *origin_nvfs; | nvlist_t *origin_nvfs; | ||||
char *origin_fsname; | char *origin_fsname; | ||||
origin_nvfs = fsavl_find(local_avl, originguid, | origin_nvfs = fsavl_find(local_avl, originguid, | ||||
NULL); | NULL); | ||||
VERIFY(0 == nvlist_lookup_string(origin_nvfs, | origin_fsname = fnvlist_lookup_string( | ||||
"name", &origin_fsname)); | origin_nvfs, "name"); | ||||
error = recv_promote(hdl, fsname, origin_fsname, | error = recv_promote(hdl, fsname, origin_fsname, | ||||
flags); | flags); | ||||
if (error == 0) | if (error == 0) | ||||
progress = B_TRUE; | progress = B_TRUE; | ||||
break; | break; | ||||
} | } | ||||
default: | default: | ||||
break; | break; | ||||
case -1: | case -1: | ||||
fsavl_destroy(local_avl); | fsavl_destroy(local_avl); | ||||
nvlist_free(local_nv); | fnvlist_free(local_nv); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
/* | /* | ||||
* We had/have the wrong origin, therefore our | * We had/have the wrong origin, therefore our | ||||
* list of snapshots is wrong. Need to handle | * list of snapshots is wrong. Need to handle | ||||
* them on the next pass. | * them on the next pass. | ||||
*/ | */ | ||||
needagain = B_TRUE; | needagain = B_TRUE; | ||||
continue; | continue; | ||||
} | } | ||||
for (snapelem = nvlist_next_nvpair(snaps, NULL); | for (snapelem = nvlist_next_nvpair(snaps, NULL); | ||||
snapelem; snapelem = nextsnapelem) { | snapelem; snapelem = nextsnapelem) { | ||||
uint64_t thisguid; | uint64_t thisguid; | ||||
char *stream_snapname; | char *stream_snapname; | ||||
nvlist_t *found, *props; | nvlist_t *found, *props; | ||||
nextsnapelem = nvlist_next_nvpair(snaps, snapelem); | nextsnapelem = nvlist_next_nvpair(snaps, snapelem); | ||||
VERIFY(0 == nvpair_value_uint64(snapelem, &thisguid)); | thisguid = fnvpair_value_uint64(snapelem); | ||||
found = fsavl_find(stream_avl, thisguid, | found = fsavl_find(stream_avl, thisguid, | ||||
&stream_snapname); | &stream_snapname); | ||||
/* check for delete */ | /* check for delete */ | ||||
if (found == NULL) { | if (found == NULL) { | ||||
char name[ZFS_MAX_DATASET_NAME_LEN]; | char name[ZFS_MAX_DATASET_NAME_LEN]; | ||||
if (!flags->force) | if (!flags->force) | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | if (fromguid == 0) { | ||||
(void) printf("local fs %s does not have " | (void) printf("local fs %s does not have " | ||||
"fromsnap (%s in stream); must have " | "fromsnap (%s in stream); must have " | ||||
"been deleted locally; ignoring\n", | "been deleted locally; ignoring\n", | ||||
fsname, fromsnap); | fsname, fromsnap); | ||||
} | } | ||||
continue; | continue; | ||||
} | } | ||||
VERIFY(0 == nvlist_lookup_string(stream_nvfs, | stream_fsname = fnvlist_lookup_string(stream_nvfs, "name"); | ||||
"name", &stream_fsname)); | stream_parent_fromsnap_guid = fnvlist_lookup_uint64( | ||||
VERIFY(0 == nvlist_lookup_uint64(stream_nvfs, | stream_nvfs, "parentfromsnap"); | ||||
"parentfromsnap", &stream_parent_fromsnap_guid)); | |||||
s1 = strrchr(fsname, '/'); | s1 = strrchr(fsname, '/'); | ||||
s2 = strrchr(stream_fsname, '/'); | s2 = strrchr(stream_fsname, '/'); | ||||
/* | /* | ||||
* Check if we're going to rename based on parent guid change | * Check if we're going to rename based on parent guid change | ||||
* and the current parent guid was also deleted. If it was then | * and the current parent guid was also deleted. If it was then | ||||
* rename will fail and is likely unneeded, so avoid this and | * rename will fail and is likely unneeded, so avoid this and | ||||
Show All 32 Lines | if ((stream_parent_fromsnap_guid != 0 && | ||||
* tosnap for stream_parent_fromsnap_guid, | * tosnap for stream_parent_fromsnap_guid, | ||||
* because the parent is a newly-created fs; | * because the parent is a newly-created fs; | ||||
* we'll be able to rename it after we recv the | * we'll be able to rename it after we recv the | ||||
* new fs. | * new fs. | ||||
*/ | */ | ||||
if (parent != NULL) { | if (parent != NULL) { | ||||
char *pname; | char *pname; | ||||
VERIFY(0 == nvlist_lookup_string(parent, "name", | pname = fnvlist_lookup_string(parent, "name"); | ||||
&pname)); | |||||
(void) snprintf(tryname, sizeof (tryname), | (void) snprintf(tryname, sizeof (tryname), | ||||
"%s%s", pname, strrchr(stream_fsname, '/')); | "%s%s", pname, strrchr(stream_fsname, '/')); | ||||
} else { | } else { | ||||
tryname[0] = '\0'; | tryname[0] = '\0'; | ||||
if (flags->verbose) { | if (flags->verbose) { | ||||
(void) printf("local fs %s new parent " | (void) printf("local fs %s new parent " | ||||
"not found\n", fsname); | "not found\n", fsname); | ||||
} | } | ||||
} | } | ||||
newname[0] = '\0'; | newname[0] = '\0'; | ||||
error = recv_rename(hdl, fsname, tryname, | error = recv_rename(hdl, fsname, tryname, | ||||
strlen(tofs)+1, newname, flags); | strlen(tofs)+1, newname, flags); | ||||
if (renamed != NULL && newname[0] != '\0') { | if (renamed != NULL && newname[0] != '\0') { | ||||
VERIFY(0 == nvlist_add_boolean(renamed, | fnvlist_add_boolean(renamed, newname); | ||||
newname)); | |||||
} | } | ||||
if (error) | if (error) | ||||
needagain = B_TRUE; | needagain = B_TRUE; | ||||
else | else | ||||
progress = B_TRUE; | progress = B_TRUE; | ||||
} | } | ||||
} | } | ||||
doagain: | doagain: | ||||
fsavl_destroy(local_avl); | fsavl_destroy(local_avl); | ||||
nvlist_free(local_nv); | fnvlist_free(local_nv); | ||||
nvlist_free(deleted); | fnvlist_free(deleted); | ||||
if (needagain && progress) { | if (needagain && progress) { | ||||
/* do another pass to fix up temporary names */ | /* do another pass to fix up temporary names */ | ||||
if (flags->verbose) | if (flags->verbose) | ||||
(void) printf("another pass:\n"); | (void) printf("another pass:\n"); | ||||
goto again; | goto again; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | if (!ZIO_CHECKSUM_EQUAL(drre.drr_u.drr_end.drr_checksum, *zc)) { | ||||
goto out; | goto out; | ||||
} | } | ||||
(void) nvlist_lookup_string(stream_nv, "fromsnap", &fromsnap); | (void) nvlist_lookup_string(stream_nv, "fromsnap", &fromsnap); | ||||
if (drr->drr_payloadlen != 0) { | if (drr->drr_payloadlen != 0) { | ||||
nvlist_t *stream_fss; | nvlist_t *stream_fss; | ||||
VERIFY(0 == nvlist_lookup_nvlist(stream_nv, "fss", | stream_fss = fnvlist_lookup_nvlist(stream_nv, "fss"); | ||||
&stream_fss)); | |||||
if ((stream_avl = fsavl_create(stream_fss)) == NULL) { | if ((stream_avl = fsavl_create(stream_fss)) == NULL) { | ||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | ||||
"couldn't allocate avl tree")); | "couldn't allocate avl tree")); | ||||
error = zfs_error(hdl, EZFS_NOMEM, errbuf); | error = zfs_error(hdl, EZFS_NOMEM, errbuf); | ||||
goto out; | goto out; | ||||
} | } | ||||
if (fromsnap != NULL && recursive) { | if (fromsnap != NULL && recursive) { | ||||
Show All 19 Lines | if (fromsnap != NULL && recursive) { | ||||
} | } | ||||
/* zfs_receive_one() will create_parents() */ | /* zfs_receive_one() will create_parents() */ | ||||
(void) strlcat(tofs, &drrb->drr_toname[i], | (void) strlcat(tofs, &drrb->drr_toname[i], | ||||
sizeof (tofs)); | sizeof (tofs)); | ||||
*strchr(tofs, '@') = '\0'; | *strchr(tofs, '@') = '\0'; | ||||
} | } | ||||
if (!flags->dryrun && !flags->nomount) { | if (!flags->dryrun && !flags->nomount) { | ||||
VERIFY(0 == nvlist_alloc(&renamed, | renamed = fnvlist_alloc(); | ||||
NV_UNIQUE_NAME, 0)); | |||||
} | } | ||||
softerr = recv_incremental_replication(hdl, tofs, flags, | softerr = recv_incremental_replication(hdl, tofs, flags, | ||||
stream_nv, stream_avl, renamed); | stream_nv, stream_avl, renamed); | ||||
/* Unmount renamed filesystems before receiving. */ | /* Unmount renamed filesystems before receiving. */ | ||||
while ((pair = nvlist_next_nvpair(renamed, | while ((pair = nvlist_next_nvpair(renamed, | ||||
pair)) != NULL) { | pair)) != NULL) { | ||||
Show All 10 Lines | if (fromsnap != NULL && recursive) { | ||||
if (clp != NULL) { | if (clp != NULL) { | ||||
softerr |= | softerr |= | ||||
changelist_prefix(clp); | changelist_prefix(clp); | ||||
changelist_free(clp); | changelist_free(clp); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
nvlist_free(renamed); | fnvlist_free(renamed); | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Get the fs specified by the first path in the stream (the top level | * Get the fs specified by the first path in the stream (the top level | ||||
* specified by 'zfs send') and pass it to each invocation of | * specified by 'zfs send') and pass it to each invocation of | ||||
* zfs_receive_one(). | * zfs_receive_one(). | ||||
*/ | */ | ||||
Show All 39 Lines | zfs_receive_package(libzfs_handle_t *hdl, int fd, const char *destname, | ||||
if (raw && softerr == 0 && *top_zfs != NULL) { | if (raw && softerr == 0 && *top_zfs != NULL) { | ||||
softerr = recv_fix_encryption_hierarchy(hdl, *top_zfs, | softerr = recv_fix_encryption_hierarchy(hdl, *top_zfs, | ||||
stream_nv, stream_avl); | stream_nv, stream_avl); | ||||
} | } | ||||
out: | out: | ||||
fsavl_destroy(stream_avl); | fsavl_destroy(stream_avl); | ||||
nvlist_free(stream_nv); | fnvlist_free(stream_nv); | ||||
if (softerr) | if (softerr) | ||||
error = -2; | error = -2; | ||||
if (anyerr) | if (anyerr) | ||||
error = -1; | error = -1; | ||||
return (error); | return (error); | ||||
} | } | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 406 Lines • ▼ Show 20 Lines | if (stream_avl != NULL) { | ||||
nvlist_t *lookup = NULL; | nvlist_t *lookup = NULL; | ||||
nvlist_t *fs = fsavl_find(stream_avl, drrb->drr_toguid, | nvlist_t *fs = fsavl_find(stream_avl, drrb->drr_toguid, | ||||
&snapname); | &snapname); | ||||
(void) nvlist_lookup_uint64(fs, "parentfromsnap", | (void) nvlist_lookup_uint64(fs, "parentfromsnap", | ||||
&parent_snapguid); | &parent_snapguid); | ||||
err = nvlist_lookup_nvlist(fs, "props", &rcvprops); | err = nvlist_lookup_nvlist(fs, "props", &rcvprops); | ||||
if (err) { | if (err) { | ||||
VERIFY(0 == nvlist_alloc(&rcvprops, NV_UNIQUE_NAME, 0)); | rcvprops = fnvlist_alloc(); | ||||
newprops = B_TRUE; | newprops = B_TRUE; | ||||
} | } | ||||
/* | /* | ||||
* The keylocation property may only be set on encryption roots, | * The keylocation property may only be set on encryption roots, | ||||
* but this dataset might not become an encryption root until | * but this dataset might not become an encryption root until | ||||
* recv_fix_encryption_hierarchy() is called. That function | * recv_fix_encryption_hierarchy() is called. That function | ||||
* will fixup the keylocation anyway, so we temporarily unset | * will fixup the keylocation anyway, so we temporarily unset | ||||
* the keylocation for now to avoid any errors from the receive | * the keylocation for now to avoid any errors from the receive | ||||
* ioctl. | * ioctl. | ||||
*/ | */ | ||||
err = nvlist_lookup_string(rcvprops, | err = nvlist_lookup_string(rcvprops, | ||||
zfs_prop_to_name(ZFS_PROP_KEYLOCATION), &keylocation); | zfs_prop_to_name(ZFS_PROP_KEYLOCATION), &keylocation); | ||||
if (err == 0) { | if (err == 0) { | ||||
strcpy(tmp_keylocation, keylocation); | strcpy(tmp_keylocation, keylocation); | ||||
(void) nvlist_remove_all(rcvprops, | (void) nvlist_remove_all(rcvprops, | ||||
zfs_prop_to_name(ZFS_PROP_KEYLOCATION)); | zfs_prop_to_name(ZFS_PROP_KEYLOCATION)); | ||||
} | } | ||||
if (flags->canmountoff) { | if (flags->canmountoff) { | ||||
VERIFY(0 == nvlist_add_uint64(rcvprops, | fnvlist_add_uint64(rcvprops, | ||||
zfs_prop_to_name(ZFS_PROP_CANMOUNT), 0)); | zfs_prop_to_name(ZFS_PROP_CANMOUNT), 0); | ||||
} else if (newprops) { /* nothing in rcvprops, eliminate it */ | } else if (newprops) { /* nothing in rcvprops, eliminate it */ | ||||
nvlist_free(rcvprops); | fnvlist_free(rcvprops); | ||||
rcvprops = NULL; | rcvprops = NULL; | ||||
newprops = B_FALSE; | newprops = B_FALSE; | ||||
} | } | ||||
if (0 == nvlist_lookup_nvlist(fs, "snapprops", &lookup)) { | if (0 == nvlist_lookup_nvlist(fs, "snapprops", &lookup)) { | ||||
VERIFY(0 == nvlist_lookup_nvlist(lookup, | snapprops_nvlist = fnvlist_lookup_nvlist(lookup, | ||||
snapname, &snapprops_nvlist)); | snapname); | ||||
} | } | ||||
if (holds) { | if (holds) { | ||||
if (0 == nvlist_lookup_nvlist(fs, "snapholds", | if (0 == nvlist_lookup_nvlist(fs, "snapholds", | ||||
&lookup)) { | &lookup)) { | ||||
VERIFY(0 == nvlist_lookup_nvlist(lookup, | snapholds_nvlist = fnvlist_lookup_nvlist( | ||||
snapname, &snapholds_nvlist)); | lookup, snapname); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
cp = NULL; | cp = NULL; | ||||
/* | /* | ||||
* Determine how much of the snapshot name stored in the stream | * Determine how much of the snapshot name stored in the stream | ||||
▲ Show 20 Lines • Show All 517 Lines • ▼ Show 20 Lines | if (err == 0 && snapholds_nvlist) { | ||||
nvpair_t *pair; | nvpair_t *pair; | ||||
nvlist_t *holds, *errors = NULL; | nvlist_t *holds, *errors = NULL; | ||||
int cleanup_fd = -1; | int cleanup_fd = -1; | ||||
VERIFY(0 == nvlist_alloc(&holds, 0, KM_SLEEP)); | VERIFY(0 == nvlist_alloc(&holds, 0, KM_SLEEP)); | ||||
for (pair = nvlist_next_nvpair(snapholds_nvlist, NULL); | for (pair = nvlist_next_nvpair(snapholds_nvlist, NULL); | ||||
pair != NULL; | pair != NULL; | ||||
pair = nvlist_next_nvpair(snapholds_nvlist, pair)) { | pair = nvlist_next_nvpair(snapholds_nvlist, pair)) { | ||||
VERIFY(0 == nvlist_add_string(holds, destsnap, | fnvlist_add_string(holds, destsnap, nvpair_name(pair)); | ||||
nvpair_name(pair))); | |||||
} | } | ||||
(void) lzc_hold(holds, cleanup_fd, &errors); | (void) lzc_hold(holds, cleanup_fd, &errors); | ||||
nvlist_free(snapholds_nvlist); | fnvlist_free(snapholds_nvlist); | ||||
nvlist_free(holds); | fnvlist_free(holds); | ||||
} | } | ||||
if (err && (ioctl_errno == ENOENT || ioctl_errno == EEXIST)) { | if (err && (ioctl_errno == ENOENT || ioctl_errno == EEXIST)) { | ||||
/* | /* | ||||
* It may be that this snapshot already exists, | * It may be that this snapshot already exists, | ||||
* in which case we want to consume & ignore it | * in which case we want to consume & ignore it | ||||
* rather than failing. | * rather than failing. | ||||
*/ | */ | ||||
avl_tree_t *local_avl; | avl_tree_t *local_avl; | ||||
nvlist_t *local_nv, *fs; | nvlist_t *local_nv, *fs; | ||||
cp = strchr(destsnap, '@'); | cp = strchr(destsnap, '@'); | ||||
/* | /* | ||||
* XXX Do this faster by just iterating over snaps in | * XXX Do this faster by just iterating over snaps in | ||||
* this fs. Also if zc_value does not exist, we will | * this fs. Also if zc_value does not exist, we will | ||||
* get a strange "does not exist" error message. | * get a strange "does not exist" error message. | ||||
*/ | */ | ||||
*cp = '\0'; | *cp = '\0'; | ||||
if (gather_nvlist(hdl, destsnap, NULL, NULL, B_FALSE, B_TRUE, | if (gather_nvlist(hdl, destsnap, NULL, NULL, B_FALSE, B_TRUE, | ||||
B_FALSE, B_FALSE, B_FALSE, B_FALSE, B_FALSE, B_TRUE, | B_FALSE, B_FALSE, B_FALSE, B_FALSE, B_FALSE, B_TRUE, | ||||
&local_nv, &local_avl) == 0) { | &local_nv, &local_avl) == 0) { | ||||
*cp = '@'; | *cp = '@'; | ||||
fs = fsavl_find(local_avl, drrb->drr_toguid, NULL); | fs = fsavl_find(local_avl, drrb->drr_toguid, NULL); | ||||
fsavl_destroy(local_avl); | fsavl_destroy(local_avl); | ||||
nvlist_free(local_nv); | fnvlist_free(local_nv); | ||||
if (fs != NULL) { | if (fs != NULL) { | ||||
if (flags->verbose) { | if (flags->verbose) { | ||||
(void) printf("snap %s already exists; " | (void) printf("snap %s already exists; " | ||||
"ignoring\n", destsnap); | "ignoring\n", destsnap); | ||||
} | } | ||||
err = ioctl_err = recv_skip(hdl, infd, | err = ioctl_err = recv_skip(hdl, infd, | ||||
flags->byteswap); | flags->byteswap); | ||||
▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | if (flags->verbose) { | ||||
(void) printf("received %s stream in %lld seconds (%s/sec)\n", | (void) printf("received %s stream in %lld seconds (%s/sec)\n", | ||||
buf1, (longlong_t)delta, buf2); | buf1, (longlong_t)delta, buf2); | ||||
} | } | ||||
err = 0; | err = 0; | ||||
out: | out: | ||||
if (prop_errors != NULL) | if (prop_errors != NULL) | ||||
nvlist_free(prop_errors); | fnvlist_free(prop_errors); | ||||
if (tmp_keylocation[0] != '\0') { | if (tmp_keylocation[0] != '\0') { | ||||
VERIFY(0 == nvlist_add_string(rcvprops, | fnvlist_add_string(rcvprops, | ||||
zfs_prop_to_name(ZFS_PROP_KEYLOCATION), tmp_keylocation)); | zfs_prop_to_name(ZFS_PROP_KEYLOCATION), tmp_keylocation); | ||||
} | } | ||||
if (newprops) | if (newprops) | ||||
nvlist_free(rcvprops); | fnvlist_free(rcvprops); | ||||
nvlist_free(oxprops); | fnvlist_free(oxprops); | ||||
nvlist_free(origprops); | fnvlist_free(origprops); | ||||
return (err); | return (err); | ||||
} | } | ||||
/* | /* | ||||
* Check properties we were asked to override (both -o|-x) | * Check properties we were asked to override (both -o|-x) | ||||
*/ | */ | ||||
static boolean_t | static boolean_t | ||||
▲ Show 20 Lines • Show All 249 Lines • Show Last 20 Lines |