diff options
author | Keith M Wesolowski <wesolows@foobazco.org> | 2013-08-14 21:17:29 +0000 |
---|---|---|
committer | Keith M Wesolowski <wesolows@foobazco.org> | 2013-08-14 21:17:33 +0000 |
commit | b4f82251ff85152d232c89d5cb42459e9fae2ac8 (patch) | |
tree | 2b380f6ec8ff27b0baa0932cfb4dbc056799674f /usr/src/lib | |
parent | 87939c38178223413d6110e2dac4cb908f61d04f (diff) | |
parent | a7027df17fad220a20367b9d1eb251bc6300d203 (diff) | |
download | illumos-joyent-b4f82251ff85152d232c89d5cb42459e9fae2ac8.tar.gz |
[illumos-gate merge]
commit a7027df17fad220a20367b9d1eb251bc6300d203
3996 want a libzfs_core API to rollback to latest snapshot
Diffstat (limited to 'usr/src/lib')
-rw-r--r-- | usr/src/lib/libzfs/common/libzfs_dataset.c | 12 | ||||
-rw-r--r-- | usr/src/lib/libzfs_core/common/libzfs_core.c | 26 | ||||
-rw-r--r-- | usr/src/lib/libzfs_core/common/libzfs_core.h | 3 | ||||
-rw-r--r-- | usr/src/lib/libzfs_core/common/mapfile-vers | 3 |
4 files changed, 31 insertions, 13 deletions
diff --git a/usr/src/lib/libzfs/common/libzfs_dataset.c b/usr/src/lib/libzfs/common/libzfs_dataset.c index 4d3fee0e66..4abf87de90 100644 --- a/usr/src/lib/libzfs/common/libzfs_dataset.c +++ b/usr/src/lib/libzfs/common/libzfs_dataset.c @@ -3539,7 +3539,6 @@ zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force) { rollback_data_t cb = { 0 }; int err; - zfs_cmd_t zc = { 0 }; boolean_t restore_resv = 0; uint64_t old_volsize, new_volsize; zfs_prop_t resv_prop; @@ -3571,22 +3570,15 @@ zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force) (old_volsize == zfs_prop_get_int(zhp, resv_prop)); } - (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); - - if (ZFS_IS_VOLUME(zhp)) - zc.zc_objset_type = DMU_OST_ZVOL; - else - zc.zc_objset_type = DMU_OST_ZFS; - /* * We rely on zfs_iter_children() to verify that there are no * newer snapshots for the given dataset. Therefore, we can * simply pass the name on to the ioctl() call. There is still * an unlikely race condition where the user has taken a * snapshot since we verified that this was the most recent. - * */ - if ((err = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_ROLLBACK, &zc)) != 0) { + err = lzc_rollback(zhp->zfs_name, NULL, 0); + if (err != 0) { (void) zfs_standard_error_fmt(zhp->zfs_hdl, errno, dgettext(TEXT_DOMAIN, "cannot rollback '%s'"), zhp->zfs_name); diff --git a/usr/src/lib/libzfs_core/common/libzfs_core.c b/usr/src/lib/libzfs_core/common/libzfs_core.c index a4f51233f4..20d7329677 100644 --- a/usr/src/lib/libzfs_core/common/libzfs_core.c +++ b/usr/src/lib/libzfs_core/common/libzfs_core.c @@ -20,7 +20,7 @@ */ /* - * Copyright (c) 2012 by Delphix. All rights reserved. + * Copyright (c) 2013 by Delphix. All rights reserved. * Copyright (c) 2013 Steven Hartland. All rights reserved. */ @@ -581,3 +581,27 @@ out: free((void*)(uintptr_t)zc.zc_nvlist_dst); return (error); } + +/* + * Roll back this filesystem or volume to its most recent snapshot. + * If snapnamebuf is not NULL, it will be filled in with the name + * of the most recent snapshot. + * + * Return 0 on success or an errno on failure. + */ +int +lzc_rollback(const char *fsname, char *snapnamebuf, int snapnamelen) +{ + nvlist_t *args; + nvlist_t *result; + int err; + + args = fnvlist_alloc(); + err = lzc_ioctl(ZFS_IOC_ROLLBACK, fsname, args, &result); + nvlist_free(args); + if (err == 0 && snapnamebuf != NULL) { + const char *snapname = fnvlist_lookup_string(result, "target"); + (void) strlcpy(snapnamebuf, snapname, snapnamelen); + } + return (err); +} diff --git a/usr/src/lib/libzfs_core/common/libzfs_core.h b/usr/src/lib/libzfs_core/common/libzfs_core.h index f5fd6cda9f..3642dc7afd 100644 --- a/usr/src/lib/libzfs_core/common/libzfs_core.h +++ b/usr/src/lib/libzfs_core/common/libzfs_core.h @@ -20,7 +20,7 @@ */ /* - * Copyright (c) 2012 by Delphix. All rights reserved. + * Copyright (c) 2013 by Delphix. All rights reserved. */ #ifndef _LIBZFS_CORE_H @@ -58,6 +58,7 @@ int lzc_send_space(const char *snapname, const char *fromsnap, boolean_t lzc_exists(const char *dataset); +int lzc_rollback(const char *fsname, char *snapnamebuf, int snapnamelen); #ifdef __cplusplus } diff --git a/usr/src/lib/libzfs_core/common/mapfile-vers b/usr/src/lib/libzfs_core/common/mapfile-vers index 1c9930a9cd..a4a110f907 100644 --- a/usr/src/lib/libzfs_core/common/mapfile-vers +++ b/usr/src/lib/libzfs_core/common/mapfile-vers @@ -19,7 +19,7 @@ # CDDL HEADER END # # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. -# Copyright (c) 2012 by Delphix. All rights reserved. +# Copyright (c) 2013 by Delphix. All rights reserved. # # MAPFILE HEADER START # @@ -49,6 +49,7 @@ SYMBOL_VERSION ILLUMOS_0.1 { lzc_hold; lzc_receive; lzc_release; + lzc_rollback; lzc_send; lzc_send_space; lzc_snaprange_space; |