aboutsummaryrefslogtreecommitdiff
path: root/cddl/contrib/opensolaris/lib
diff options
context:
space:
mode:
authorAndriy Gapon <avg@FreeBSD.org>2016-11-03 09:24:27 +0000
committerAndriy Gapon <avg@FreeBSD.org>2016-11-03 09:24:27 +0000
commitd5315b02cd10ad8861a00b3224add94e23b39a84 (patch)
tree8032c2446b49e0bd374006563a6237e6a680bd69 /cddl/contrib/opensolaris/lib
parent19a8946bce1e8cb309aa152462fcb30bf49e457e (diff)
parentc01a79842c34ad06b62b2f069ed8a9d2e8a901b2 (diff)
MFV r308222: 6051 lzc_receive: allow the caller to read the begin record
illumos/illumos-gate@620f322510b2d6433f7f6af60fa52380c07756ad https://github.com/illumos/illumos-gate/commit/620f322510b2d6433f7f6af60fa52380c07756ad https://www.illumos.org/issues/6051 Currently lzc_receive() requires that its snapname argument is a snapshot name (contains '@'). zfs receive allows to specify just a dataset name and would try to deduce the snapshot name from the stream. I propose to allow lzc_receive() to do the same. That seems to be quite easy to implement, it requires only a small amount of logic, it does not require any additional system calls or any additional data from the stream. The benefit is that the new behavior would allow to keep the snapshot names the same between the sender and receiver at zero cost, without a need to pass the names out of band. Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed by: Paul Dagnelie <pcd@delphix.com> Approved by: Robert Mustacchi <rm@joyent.com> Author: Andriy Gapon <avg@icyb.net.ua> MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=308247
Diffstat (limited to 'cddl/contrib/opensolaris/lib')
-rw-r--r--cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c42
-rw-r--r--cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h7
2 files changed, 41 insertions, 8 deletions
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 c1ada8d6a10f..ee3158b4f811 100644
--- a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c
+++ b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c
@@ -596,8 +596,9 @@ recv_read(int fd, void *buf, int ilen)
}
static int
-lzc_receive_impl(const char *snapname, nvlist_t *props, const char *origin,
- boolean_t force, boolean_t resumable, int fd)
+recv_impl(const char *snapname, nvlist_t *props, const char *origin,
+ boolean_t force, boolean_t resumable, int fd,
+ const dmu_replay_record_t *begin_record)
{
/*
* The receive ioctl is still legacy, so we need to construct our own
@@ -642,9 +643,14 @@ lzc_receive_impl(const char *snapname, nvlist_t *props, const char *origin,
(void) strlcpy(zc.zc_string, origin, sizeof (zc.zc_string));
/* zc_begin_record is non-byteswapped BEGIN record */
- error = recv_read(fd, &zc.zc_begin_record, sizeof (zc.zc_begin_record));
- if (error != 0)
- goto out;
+ if (begin_record == NULL) {
+ error = recv_read(fd, &zc.zc_begin_record,
+ sizeof (zc.zc_begin_record));
+ if (error != 0)
+ goto out;
+ } else {
+ zc.zc_begin_record = *begin_record;
+ }
/* zc_cookie is fd to read from */
zc.zc_cookie = fd;
@@ -685,7 +691,7 @@ int
lzc_receive(const char *snapname, nvlist_t *props, const char *origin,
boolean_t force, int fd)
{
- return (lzc_receive_impl(snapname, props, origin, force, B_FALSE, fd));
+ return (recv_impl(snapname, props, origin, force, B_FALSE, fd, NULL));
}
/*
@@ -698,7 +704,29 @@ int
lzc_receive_resumable(const char *snapname, nvlist_t *props, const char *origin,
boolean_t force, int fd)
{
- return (lzc_receive_impl(snapname, props, origin, force, B_TRUE, fd));
+ return (recv_impl(snapname, props, origin, force, B_TRUE, fd, NULL));
+}
+
+/*
+ * Like lzc_receive, but allows the caller to read the begin record and then to
+ * pass it in. That could be useful if the caller wants to derive, for example,
+ * the snapname or the origin parameters based on the information contained in
+ * the begin record.
+ * The begin record must be in its original form as read from the stream,
+ * in other words, it should not be byteswapped.
+ *
+ * The 'resumable' parameter allows to obtain the same behavior as with
+ * lzc_receive_resumable.
+ */
+int
+lzc_receive_with_header(const char *snapname, nvlist_t *props,
+ const char *origin, boolean_t force, boolean_t resumable, int fd,
+ const dmu_replay_record_t *begin_record)
+{
+ if (begin_record == NULL)
+ return (EINVAL);
+ return (recv_impl(snapname, props, origin, force, resumable, fd,
+ begin_record));
}
/*
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 d922ab55f5ef..8ff00cc2ddf7 100644
--- a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h
+++ b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h
@@ -68,10 +68,15 @@ enum lzc_send_flags {
int lzc_send(const char *, const char *, int, enum lzc_send_flags);
int lzc_send_resume(const char *, const char *, int,
enum lzc_send_flags, uint64_t, uint64_t);
+int lzc_send_space(const char *, const char *, uint64_t *);
+
+struct dmu_replay_record;
+
int lzc_receive(const char *, nvlist_t *, const char *, boolean_t, int);
int lzc_receive_resumable(const char *, nvlist_t *, const char *,
boolean_t, int);
-int lzc_send_space(const char *, const char *, uint64_t *);
+int lzc_receive_with_header(const char *, nvlist_t *, const char *, boolean_t,
+ boolean_t, int, const struct dmu_replay_record *);
boolean_t lzc_exists(const char *);