mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 18:40:43 +03:00
Illumos #3996
3996 want a libzfs_core API to rollback to latest snapshot Reviewed by: Christopher Siden <christopher.siden@delphix.com> Reviewed by: Adam Leventhal <ahl@delphix.com> Reviewed by: George Wilson <george.wilson@delphix.com> Reviewed by: Andy Stormont <andyjstormont@gmail.com> Approved by: Richard Lowe <richlowe@richlowe.net> References: https://www.illumos.org/issues/3996 illumos/illumos-gate@a7027df17f Ported-by: Richard Yao <ryao@gentoo.org> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Issue #1775
This commit is contained in:
committed by
Brian Behlendorf
parent
5d1f7fb647
commit
46ba1e59d3
@@ -3732,7 +3732,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 = 0, new_volsize;
|
||||
zfs_prop_t resv_prop = { 0 };
|
||||
@@ -3766,22 +3765,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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user