Skip to content

Commit

Permalink
Refactor parent dataset handling in libzfs zfs_rename()
Browse files Browse the repository at this point in the history
For recursive renaming, simplify the code by moving `zhrp` and
`parentname` to inner scope. `zhrp` is only used to test existence
of a parent dataset for recursive dataset dir scan since ba6a240.

Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Richard Laager <rlaager@wiktel.com>
Reviewed-by: Giuseppe Di Natale <guss80@gmail.com>
Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@osnexus.com>
Closes openzfs#8815
  • Loading branch information
kusumi authored and allanjude committed Jun 15, 2019
1 parent bba39c7 commit 781b666
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions lib/libzfs/libzfs_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -4486,8 +4486,6 @@ zfs_rename(zfs_handle_t *zhp, const char *target, renameflags_t flags)
zfs_cmd_t zc = {"\0"};
char *delim;
prop_changelist_t *cl = NULL;
zfs_handle_t *zhrp = NULL;
char *parentname = NULL;
char parent[ZFS_MAX_DATASET_NAME_LEN];
char property[ZFS_MAXPROPLEN];
libzfs_handle_t *hdl = zhp->zfs_hdl;
Expand Down Expand Up @@ -4582,7 +4580,7 @@ zfs_rename(zfs_handle_t *zhp, const char *target, renameflags_t flags)
return (zfs_error(hdl, EZFS_ZONED, errbuf));
}

/*
/*
* Avoid unmounting file systems with mountpoint property set to
* 'legacy' or 'none' even if -u option is not given.
*/
Expand All @@ -4595,18 +4593,21 @@ zfs_rename(zfs_handle_t *zhp, const char *target, renameflags_t flags)
flags.nounmount = B_TRUE;
}
if (flags.recursive) {
parentname = zfs_strdup(zhp->zfs_hdl, zhp->zfs_name);
zfs_handle_t *zhrp;
char *parentname = zfs_strdup(zhp->zfs_hdl, zhp->zfs_name);
if (parentname == NULL) {
ret = -1;
goto error;
}
delim = strchr(parentname, '@');
*delim = '\0';
zhrp = zfs_open(zhp->zfs_hdl, parentname, ZFS_TYPE_DATASET);
free(parentname);
if (zhrp == NULL) {
ret = -1;
goto error;
}
zfs_close(zhrp);
} else if (zhp->zfs_type != ZFS_TYPE_SNAPSHOT) {
if ((cl = changelist_gather(zhp, ZFS_PROP_NAME,
flags.nounmount ? CL_GATHER_DONT_UNMOUNT : CL_GATHER_ITER_MOUNTED,
Expand Down Expand Up @@ -4680,12 +4681,6 @@ zfs_rename(zfs_handle_t *zhp, const char *target, renameflags_t flags)
}

error:
if (parentname != NULL) {
free(parentname);
}
if (zhrp != NULL) {
zfs_close(zhrp);
}
if (cl != NULL) {
changelist_free(cl);
}
Expand Down

0 comments on commit 781b666

Please sign in to comment.