Refactor parent dataset handling in libzfs zfs_rename()
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 ba6a24026c
.
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 #8815
This commit is contained in:
parent
ab1a9705f8
commit
5691b86ce5
|
@ -4470,8 +4470,6 @@ zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive,
|
||||||
zfs_cmd_t zc = {"\0"};
|
zfs_cmd_t zc = {"\0"};
|
||||||
char *delim;
|
char *delim;
|
||||||
prop_changelist_t *cl = NULL;
|
prop_changelist_t *cl = NULL;
|
||||||
zfs_handle_t *zhrp = NULL;
|
|
||||||
char *parentname = NULL;
|
|
||||||
char parent[ZFS_MAX_DATASET_NAME_LEN];
|
char parent[ZFS_MAX_DATASET_NAME_LEN];
|
||||||
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
||||||
char errbuf[1024];
|
char errbuf[1024];
|
||||||
|
@ -4566,7 +4564,8 @@ zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recursive) {
|
if (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) {
|
if (parentname == NULL) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -4574,10 +4573,12 @@ zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive,
|
||||||
delim = strchr(parentname, '@');
|
delim = strchr(parentname, '@');
|
||||||
*delim = '\0';
|
*delim = '\0';
|
||||||
zhrp = zfs_open(zhp->zfs_hdl, parentname, ZFS_TYPE_DATASET);
|
zhrp = zfs_open(zhp->zfs_hdl, parentname, ZFS_TYPE_DATASET);
|
||||||
|
free(parentname);
|
||||||
if (zhrp == NULL) {
|
if (zhrp == NULL) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
zfs_close(zhrp);
|
||||||
} else if (zhp->zfs_type != ZFS_TYPE_SNAPSHOT) {
|
} else if (zhp->zfs_type != ZFS_TYPE_SNAPSHOT) {
|
||||||
if ((cl = changelist_gather(zhp, ZFS_PROP_NAME,
|
if ((cl = changelist_gather(zhp, ZFS_PROP_NAME,
|
||||||
CL_GATHER_ITER_MOUNTED,
|
CL_GATHER_ITER_MOUNTED,
|
||||||
|
@ -4650,12 +4651,6 @@ zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive,
|
||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
if (parentname != NULL) {
|
|
||||||
free(parentname);
|
|
||||||
}
|
|
||||||
if (zhrp != NULL) {
|
|
||||||
zfs_close(zhrp);
|
|
||||||
}
|
|
||||||
if (cl != NULL) {
|
if (cl != NULL) {
|
||||||
changelist_free(cl);
|
changelist_free(cl);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue