aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAndriy Gapon <avg@FreeBSD.org>2017-08-08 10:49:56 +0000
committerAndriy Gapon <avg@FreeBSD.org>2017-08-08 10:49:56 +0000
commit59946bc86e82dcfef6355d4a1d4e238ff895be35 (patch)
treea87e9a99a97f421b9f516af2ee042bd52e9bd0cb /lib
parent9ff5c34a7e9c61c15a74f4a87a50cfd8ddb036eb (diff)
downloadsrc-59946bc86e82dcfef6355d4a1d4e238ff895be35.tar.gz
src-59946bc86e82dcfef6355d4a1d4e238ff895be35.zip
7600 zfs rollback should pass target snapshot to kernel
illumos/illumos-gate@77b171372ed21642e04c873ef1e87fe2365520df https://github.com/illumos/illumos-gate/commit/77b171372ed21642e04c873ef1e87fe2365520df https://www.illumos.org/issues/7600 At present, the kernel side code seems to blindly rollback to whatever happens to be the latest snapshot at the time when the rollback task is processed. The expected target's name should be passed to the kernel driver and the sync task should validate that the target exists and that it is the latest snapshot indeed. Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com> Approved by: Robert Mustacchi <rm@joyent.com> Author: Andriy Gapon <avg@FreeBSD.org>
Notes
Notes: svn path=/vendor-sys/illumos/dist/; revision=322229
Diffstat (limited to 'lib')
-rw-r--r--lib/libzfs/common/libzfs_dataset.c19
-rw-r--r--lib/libzfs_core/common/libzfs_core.c24
-rw-r--r--lib/libzfs_core/common/libzfs_core.h1
3 files changed, 37 insertions, 7 deletions
diff --git a/lib/libzfs/common/libzfs_dataset.c b/lib/libzfs/common/libzfs_dataset.c
index a45889e7cff6..68ee7a0eaf75 100644
--- a/lib/libzfs/common/libzfs_dataset.c
+++ b/lib/libzfs/common/libzfs_dataset.c
@@ -3912,14 +3912,19 @@ zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force)
}
/*
- * 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.
+ * Pass both the filesystem and the wanted snapshot names,
+ * we would get an error back if the snapshot is destroyed or
+ * a new snapshot is created before this request is processed.
*/
- err = lzc_rollback(zhp->zfs_name, NULL, 0);
- if (err != 0) {
+ err = lzc_rollback_to(zhp->zfs_name, snap->zfs_name);
+ if (err == EXDEV) {
+ zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN,
+ "'%s' is not the latest snapshot"), snap->zfs_name);
+ (void) zfs_error_fmt(zhp->zfs_hdl, EZFS_BUSY,
+ dgettext(TEXT_DOMAIN, "cannot rollback '%s'"),
+ zhp->zfs_name);
+ return (err);
+ } else if (err != 0) {
(void) zfs_standard_error_fmt(zhp->zfs_hdl, errno,
dgettext(TEXT_DOMAIN, "cannot rollback '%s'"),
zhp->zfs_name);
diff --git a/lib/libzfs_core/common/libzfs_core.c b/lib/libzfs_core/common/libzfs_core.c
index 87f7ea4f466a..8f6c8595d9e1 100644
--- a/lib/libzfs_core/common/libzfs_core.c
+++ b/lib/libzfs_core/common/libzfs_core.c
@@ -728,6 +728,9 @@ lzc_receive_with_header(const char *snapname, nvlist_t *props,
* 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.
+ * Note that the latest snapshot may change if a new one is concurrently
+ * created or the current one is destroyed. lzc_rollback_to can be used
+ * to roll back to a specific latest snapshot.
*
* Return 0 on success or an errno on failure.
*/
@@ -751,6 +754,27 @@ lzc_rollback(const char *fsname, char *snapnamebuf, int snapnamelen)
}
/*
+ * Roll back this filesystem or volume to the specified snapshot,
+ * if possible.
+ *
+ * Return 0 on success or an errno on failure.
+ */
+int
+lzc_rollback_to(const char *fsname, const char *snapname)
+{
+ nvlist_t *args;
+ nvlist_t *result;
+ int err;
+
+ args = fnvlist_alloc();
+ fnvlist_add_string(args, "target", snapname);
+ err = lzc_ioctl(ZFS_IOC_ROLLBACK, fsname, args, &result);
+ nvlist_free(args);
+ nvlist_free(result);
+ return (err);
+}
+
+/*
* Creates bookmarks.
*
* The bookmarks nvlist maps from name of the bookmark (e.g. "pool/fs#bmark") to
diff --git a/lib/libzfs_core/common/libzfs_core.h b/lib/libzfs_core/common/libzfs_core.h
index 3d9e14d3da54..fc07d538c9ba 100644
--- a/lib/libzfs_core/common/libzfs_core.h
+++ b/lib/libzfs_core/common/libzfs_core.h
@@ -84,6 +84,7 @@ int lzc_receive_with_header(const char *, nvlist_t *, const char *, boolean_t,
boolean_t lzc_exists(const char *);
int lzc_rollback(const char *, char *, int);
+int lzc_rollback_to(const char *, const char *);
#ifdef __cplusplus
}