summaryrefslogtreecommitdiff
path: root/cddl/contrib/opensolaris
diff options
context:
space:
mode:
authorAndriy Gapon <avg@FreeBSD.org>2017-06-14 16:31:36 +0000
committerAndriy Gapon <avg@FreeBSD.org>2017-06-14 16:31:36 +0000
commitb8d341fe2695fdceb7df2e9cde8d49e91e030193 (patch)
tree976db691bfbe1ed7e8b7633ffba680d82f5c27b0 /cddl/contrib/opensolaris
parent7737de9515464df271f509e3ee5d34b766195d24 (diff)
parente460d6ff6b33db7a7df0cbaa7a0814b8dae34891 (diff)
Notes
Diffstat (limited to 'cddl/contrib/opensolaris')
-rw-r--r--cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c20
-rw-r--r--cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c25
-rw-r--r--cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h2
3 files changed, 33 insertions, 14 deletions
diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c
index 6df8cd02b8fb..9d9cbc3a9afd 100644
--- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c
+++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c
@@ -30,6 +30,7 @@
* Copyright (c) 2014 Integros [integros.com]
* Copyright 2016 Nexenta Systems, Inc.
* Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
+ * Copyright 2017 RackTop Systems.
*/
#include <ctype.h>
@@ -3675,8 +3676,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];
@@ -3689,31 +3689,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/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c
index 9e4e88296483..27a414459f95 100644
--- a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c
+++ b/cddl/contrib/opensolaris/lib/libzfs_core/common/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) 2014 Integros [integros.com]
+ * Copyright 2017 RackTop Systems.
*/
/*
@@ -244,6 +245,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.
*
@@ -371,7 +394,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 };
diff --git a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h
index 8f19294e3432..fd18d5fab4f5 100644
--- a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h
+++ b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h
@@ -22,6 +22,7 @@
/*
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
* Copyright (c) 2013 by Martin Matuska <mm@FreeBSD.org>. All rights reserved.
+ * Copyright 2017 RackTop Systems.
*/
#ifndef _LIBZFS_CORE_H
@@ -49,6 +50,7 @@ enum lzc_dataset_type {
int lzc_snapshot(nvlist_t *, nvlist_t *, nvlist_t **);
int lzc_create(const char *, enum lzc_dataset_type, nvlist_t *);
int lzc_clone(const char *, const char *, nvlist_t *);
+int lzc_promote(const char *, char *, int);
int lzc_destroy_snaps(nvlist_t *, boolean_t, nvlist_t **);
int lzc_bookmark(nvlist_t *, nvlist_t **);
int lzc_get_bookmarks(const char *, nvlist_t *, nvlist_t **);