Changeset View
Changeset View
Standalone View
Standalone View
head/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c
Show First 20 Lines • Show All 4,285 Lines • ▼ Show 20 Lines | zfs_rename(zfs_handle_t *zhp, const char *source, const char *target, | ||||
/* make sure source name is valid */ | /* make sure source name is valid */ | ||||
if (!zfs_validate_name(hdl, zhp->zfs_name, zhp->zfs_type, B_TRUE)) | if (!zfs_validate_name(hdl, zhp->zfs_name, zhp->zfs_type, B_TRUE)) | ||||
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); | return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); | ||||
/* | /* | ||||
* Make sure the target name is valid | * Make sure the target name is valid | ||||
*/ | */ | ||||
if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) { | if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT || | ||||
if ((strchr(target, '@') == NULL) || | zhp->zfs_type == ZFS_TYPE_BOOKMARK) { | ||||
*target == '@') { | const char sep = zhp->zfs_type == ZFS_TYPE_SNAPSHOT ? '@' : '#'; | ||||
if ((strchr(target, sep) == NULL) || *target == sep) { | |||||
/* | /* | ||||
* Snapshot target name is abbreviated, | * Snapshot target name is abbreviated, | ||||
* reconstruct full dataset name | * reconstruct full dataset name | ||||
*/ | */ | ||||
(void) strlcpy(parent, zhp->zfs_name, | (void) strlcpy(parent, zhp->zfs_name, sizeof (parent)); | ||||
sizeof (parent)); | delim = strchr(parent, sep); | ||||
delim = strchr(parent, '@'); | if (strchr(target, sep) == NULL) | ||||
if (strchr(target, '@') == NULL) | |||||
*(++delim) = '\0'; | *(++delim) = '\0'; | ||||
else | else | ||||
*delim = '\0'; | *delim = '\0'; | ||||
(void) strlcat(parent, target, sizeof (parent)); | (void) strlcat(parent, target, sizeof (parent)); | ||||
target = parent; | target = parent; | ||||
} else { | } else { | ||||
/* | /* | ||||
* Make sure we're renaming within the same dataset. | * Make sure we're renaming within the same dataset. | ||||
*/ | */ | ||||
delim = strchr(target, '@'); | delim = strchr(target, sep); | ||||
if (strncmp(zhp->zfs_name, target, delim - target) | if (strncmp(zhp->zfs_name, target, delim - target) | ||||
!= 0 || zhp->zfs_name[delim - target] != '@') { | != 0 || zhp->zfs_name[delim - target] != sep) { | ||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | ||||
"snapshots must be part of same " | "%s must be part of same dataset"), | ||||
"dataset")); | zhp->zfs_type == ZFS_TYPE_SNAPSHOT ? | ||||
"snapshots" : "bookmarks"); | |||||
return (zfs_error(hdl, EZFS_CROSSTARGET, | return (zfs_error(hdl, EZFS_CROSSTARGET, | ||||
errbuf)); | errbuf)); | ||||
} | } | ||||
} | } | ||||
if (!zfs_validate_name(hdl, target, zhp->zfs_type, B_TRUE)) | if (!zfs_validate_name(hdl, target, zhp->zfs_type, B_TRUE)) | ||||
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); | return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); | ||||
} else { | } else { | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | if (zhp->zfs_type == ZFS_TYPE_FILESYSTEM && | ||||
!flags.recurse && !flags.nounmount && | !flags.recurse && !flags.nounmount && | ||||
zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, property, | zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, property, | ||||
sizeof (property), NULL, NULL, 0, B_FALSE) == 0 && | sizeof (property), NULL, NULL, 0, B_FALSE) == 0 && | ||||
(strcmp(property, "legacy") == 0 || | (strcmp(property, "legacy") == 0 || | ||||
strcmp(property, "none") == 0)) { | strcmp(property, "none") == 0)) { | ||||
flags.nounmount = B_TRUE; | flags.nounmount = B_TRUE; | ||||
} | } | ||||
if (flags.recurse) { | if (flags.recurse) { | ||||
parentname = zfs_strdup(zhp->zfs_hdl, zhp->zfs_name); | parentname = zfs_strdup(zhp->zfs_hdl, zhp->zfs_name); | ||||
if (parentname == NULL) { | if (parentname == NULL) { | ||||
ret = -1; | ret = -1; | ||||
goto error; | goto error; | ||||
} | } | ||||
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); | ||||
if (zhrp == NULL) { | if (zhrp == NULL) { | ||||
ret = -1; | ret = -1; | ||||
goto error; | goto error; | ||||
} | } | ||||
} else if (zhp->zfs_type != ZFS_TYPE_SNAPSHOT) { | } else if (zhp->zfs_type != ZFS_TYPE_SNAPSHOT && | ||||
zhp->zfs_type != ZFS_TYPE_BOOKMARK) { | |||||
if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, | if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, | ||||
flags.nounmount ? CL_GATHER_DONT_UNMOUNT : 0, | flags.nounmount ? CL_GATHER_DONT_UNMOUNT : 0, | ||||
flags.forceunmount ? MS_FORCE : 0)) == NULL) { | flags.forceunmount ? MS_FORCE : 0)) == NULL) { | ||||
return (-1); | return (-1); | ||||
} | } | ||||
if (changelist_haszonedchild(cl)) { | if (changelist_haszonedchild(cl)) { | ||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | ||||
Show All 28 Lines | if ((ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_RENAME, &zc)) != 0) { | ||||
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, | (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, | ||||
"cannot rename '%s'"), zc.zc_name); | "cannot rename '%s'"), zc.zc_name); | ||||
if (flags.recurse && errno == EEXIST) { | if (flags.recurse && errno == EEXIST) { | ||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, | ||||
"a child dataset already has a snapshot " | "a child dataset already has a snapshot " | ||||
"with the new name")); | "with the new name")); | ||||
(void) zfs_error(hdl, EZFS_EXISTS, errbuf); | (void) zfs_error(hdl, EZFS_EXISTS, errbuf); | ||||
} else if (errno == EINVAL) { | |||||
(void) zfs_error(hdl, EZFS_INVALIDNAME, errbuf); | |||||
} else { | } else { | ||||
(void) zfs_standard_error(zhp->zfs_hdl, errno, errbuf); | (void) zfs_standard_error(zhp->zfs_hdl, errno, errbuf); | ||||
} | } | ||||
/* | /* | ||||
* On failure, we still want to remount any filesystems that | * On failure, we still want to remount any filesystems that | ||||
* were previously mounted, so we don't alter the system state. | * were previously mounted, so we don't alter the system state. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 799 Lines • Show Last 20 Lines |