aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGiuseppe Di Natale <[email protected]>2017-06-26 16:56:09 -0700
committerBrian Behlendorf <[email protected]>2017-06-26 16:56:09 -0700
commitd12f91fde3c6a7d1aa71967b3480faac6c853051 (patch)
treeeb04ad4ac4f5cbf2d7e45a20f1047da24a41b16a /lib
parent7517376f939d788a2622c84fe1f502799a74a0ae (diff)
OpenZFS 8264 - want support for promoting datasets in libzfs_core
Authored by: Andrew Stormont <[email protected]> Reviewed by: Andriy Gapon <[email protected]> Reviewed by: Matthew Ahrens <[email protected]> Reviewed by: Dan McDonald <[email protected]> Approved by: Dan McDonald <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Ported-by: Giuseppe Di Natale <[email protected]> OpenZFS-issue: https://www.illumos.org/issues/8264 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/a4b8c9a Closes #6254
Diffstat (limited to 'lib')
-rw-r--r--lib/libzfs/libzfs_dataset.c20
-rw-r--r--lib/libzfs_core/libzfs_core.c25
2 files changed, 31 insertions, 14 deletions
diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c
index f1346b69c..bc630919a 100644
--- a/lib/libzfs/libzfs_dataset.c
+++ b/lib/libzfs/libzfs_dataset.c
@@ -29,6 +29,7 @@
* Copyright (c) 2013 Steven Hartland. All rights reserved.
* Copyright 2016 Nexenta Systems, Inc.
* Copyright 2016 Igor Kozhukhov <[email protected]>
+ * Copyright 2017 RackTop Systems.
*/
#include <ctype.h>
@@ -3731,8 +3732,7 @@ int
zfs_promote(zfs_handle_t *zhp)
{
libzfs_handle_t *hdl = zhp->zfs_hdl;
- zfs_cmd_t zc = {"\0"};
- char parent[MAXPATHLEN];
+ char snapname[ZFS_MAX_DATASET_NAME_LEN];
int ret;
char errbuf[1024];
@@ -3745,31 +3745,25 @@ zfs_promote(zfs_handle_t *zhp)
return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
}
- (void) strlcpy(parent, zhp->zfs_dmustats.dds_origin, sizeof (parent));
- if (parent[0] == '\0') {
+ if (zhp->zfs_dmustats.dds_origin[0] == '\0') {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"not a cloned filesystem"));
return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
}
- (void) strlcpy(zc.zc_value, zhp->zfs_dmustats.dds_origin,
- sizeof (zc.zc_value));
- (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
- ret = zfs_ioctl(hdl, ZFS_IOC_PROMOTE, &zc);
+ ret = lzc_promote(zhp->zfs_name, snapname, sizeof (snapname));
if (ret != 0) {
- int save_errno = errno;
-
- switch (save_errno) {
+ switch (ret) {
case EEXIST:
/* There is a conflicting snapshot name. */
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"conflicting snapshot '%s' from parent '%s'"),
- zc.zc_string, parent);
+ snapname, zhp->zfs_dmustats.dds_origin);
return (zfs_error(hdl, EZFS_EXISTS, errbuf));
default:
- return (zfs_standard_error(hdl, save_errno, errbuf));
+ return (zfs_standard_error(hdl, ret, errbuf));
}
}
return (ret);
diff --git a/lib/libzfs_core/libzfs_core.c b/lib/libzfs_core/libzfs_core.c
index 8e36d8459..8142f2c63 100644
--- a/lib/libzfs_core/libzfs_core.c
+++ b/lib/libzfs_core/libzfs_core.c
@@ -23,6 +23,7 @@
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
* Copyright (c) 2013 Steven Hartland. All rights reserved.
* Copyright (c) 2017 Datto Inc.
+ * Copyright 2017 RackTop Systems.
*/
/*
@@ -206,6 +207,28 @@ lzc_clone(const char *fsname, const char *origin,
return (error);
}
+int
+lzc_promote(const char *fsname, char *snapnamebuf, int snapnamelen)
+{
+ /*
+ * The promote ioctl is still legacy, so we need to construct our
+ * own zfs_cmd_t rather than using lzc_ioctl().
+ */
+ zfs_cmd_t zc = { "\0" };
+
+ ASSERT3S(g_refcount, >, 0);
+ VERIFY3S(g_fd, !=, -1);
+
+ (void) strlcpy(zc.zc_name, fsname, sizeof (zc.zc_name));
+ if (ioctl(g_fd, ZFS_IOC_PROMOTE, &zc) != 0) {
+ int error = errno;
+ if (error == EEXIST && snapnamebuf != NULL)
+ (void) strlcpy(snapnamebuf, zc.zc_string, snapnamelen);
+ return (error);
+ }
+ return (0);
+}
+
/*
* Creates snapshots.
*
@@ -333,7 +356,7 @@ lzc_exists(const char *dataset)
{
/*
* The objset_stats ioctl is still legacy, so we need to construct our
- * own zfs_cmd_t rather than using zfsc_ioctl().
+ * own zfs_cmd_t rather than using lzc_ioctl().
*/
zfs_cmd_t zc = {"\0"};