summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2020-07-08 11:35:01 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2020-07-08 11:35:01 +0000
commitb97f5b09ef2e4af27e3cc4addd8abe5fc7c4d817 (patch)
tree26a516b2251314578cd471a7293f6d36cdd798a8 /usr/src
parent500c01a56730addd2b2a8a00fef7ce205769f05a (diff)
parentf4f9009fc79529ef8f45e7a31acd2ce4ca86a276 (diff)
downloadillumos-joyent-b97f5b09ef2e4af27e3cc4addd8abe5fc7c4d817.tar.gz
[illumos-gate merge]
commit f4f9009fc79529ef8f45e7a31acd2ce4ca86a276 12912 epoll mishandles excessive timeout negativity commit be9c3adb90f4f745cf5c07f3c0dbdd6c9028cda0 12926 libstand: add missing iscntrl() isgraph() and ispunct() commit 7ac89354c798225fea6296348415955ccd95fb80 12877 Port OpenZFS #7780 - Add basic zfs ioc input nvpair validation 12895 zfs_onexit_fd_hold fails to release non-zfs fds commit 6f0673af8764c356a5bd511fc7ca8af579fe2000 12810 usr/src/tools/opensolaris contents are unused commit 086d96878f5f62a25a6d90e5b03a1ef9ba352231 12909 epoll should better detect fd reassignment Conflicts: usr/src/uts/common/sys/user.h
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/boot/lib/libstand/stand.h16
-rw-r--r--usr/src/cmd/zfs/zfs_main.c22
-rw-r--r--usr/src/lib/libzfs/common/libzfs.h3
-rw-r--r--usr/src/lib/libzfs/common/libzfs_util.c37
-rw-r--r--usr/src/lib/libzfs_core/common/libzfs_core.c50
-rw-r--r--usr/src/pkg/README.pkg5
-rw-r--r--usr/src/pkg/manifests/system-test-zfstest.mf4
-rw-r--r--usr/src/test/zfs-tests/cmd/libzfs_input_check/.gitignore1
-rw-r--r--usr/src/test/zfs-tests/cmd/libzfs_input_check/Makefile22
-rw-r--r--usr/src/test/zfs-tests/cmd/libzfs_input_check/libzfs_input_check.c973
-rw-r--r--usr/src/test/zfs-tests/include/commands.cfg1
-rw-r--r--usr/src/test/zfs-tests/runfiles/omnios.run4
-rw-r--r--usr/src/test/zfs-tests/runfiles/openindiana.run4
-rw-r--r--usr/src/test/zfs-tests/runfiles/smartos.run4
-rw-r--r--usr/src/test/zfs-tests/tests/functional/libzfs/Makefile5
-rwxr-xr-xusr/src/test/zfs-tests/tests/functional/libzfs/cleanup.ksh34
-rwxr-xr-xusr/src/test/zfs-tests/tests/functional/libzfs/libzfs_input.ksh30
-rwxr-xr-xusr/src/test/zfs-tests/tests/functional/libzfs/setup.ksh35
-rw-r--r--usr/src/tools/opensolaris/BINARYLICENSE.txt190
-rw-r--r--usr/src/tools/opensolaris/README.binaries.tmpl27
-rw-r--r--usr/src/tools/opensolaris/README.opensolaris.tmpl82
-rw-r--r--usr/src/tools/scripts/checkpaths.sh5
-rw-r--r--usr/src/uts/common/fs/proc/prvnops.c3
-rw-r--r--usr/src/uts/common/fs/zfs/zfs_ioctl.c453
-rw-r--r--usr/src/uts/common/fs/zfs/zfs_onexit.c7
-rw-r--r--usr/src/uts/common/sys/file.h5
-rw-r--r--usr/src/uts/common/sys/fs/zfs.h169
-rw-r--r--usr/src/uts/common/sys/user.h2
28 files changed, 1684 insertions, 509 deletions
diff --git a/usr/src/boot/lib/libstand/stand.h b/usr/src/boot/lib/libstand/stand.h
index 9406d4f296..5f94a7fa58 100644
--- a/usr/src/boot/lib/libstand/stand.h
+++ b/usr/src/boot/lib/libstand/stand.h
@@ -238,6 +238,22 @@ static __inline int isalnum(int c)
return (isalpha(c) || isdigit(c));
}
+static __inline int iscntrl(int c)
+{
+ return ((c >= 0 && c < ' ') || c == 127);
+}
+
+static __inline int isgraph(int c)
+{
+ return (c >= '!' && c <= '~');
+}
+
+static __inline int ispunct(int c)
+{
+ return ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') ||
+ (c >= '[' && c <= '`') || (c >= '{' && c <= '~'));
+}
+
static __inline int toupper(int c)
{
return (islower(c) ? c - 'a' + 'A' : c);
diff --git a/usr/src/cmd/zfs/zfs_main.c b/usr/src/cmd/zfs/zfs_main.c
index 6c53682364..c8c7c525ba 100644
--- a/usr/src/cmd/zfs/zfs_main.c
+++ b/usr/src/cmd/zfs/zfs_main.c
@@ -7494,7 +7494,7 @@ zfs_do_bookmark(int argc, char **argv)
fnvlist_free(nvl);
if (ret != 0) {
- const char *err_msg;
+ const char *err_msg = NULL;
char errbuf[1024];
(void) snprintf(errbuf, sizeof (errbuf),
@@ -7518,11 +7518,13 @@ zfs_do_bookmark(int argc, char **argv)
err_msg = "out of space";
break;
default:
- err_msg = "unknown error";
+ (void) zfs_standard_error(g_zfs, ret, errbuf);
break;
}
- (void) fprintf(stderr, "%s: %s\n", errbuf,
- dgettext(TEXT_DOMAIN, err_msg));
+ if (err_msg != NULL) {
+ (void) fprintf(stderr, "%s: %s\n", errbuf,
+ dgettext(TEXT_DOMAIN, err_msg));
+ }
}
return (ret != 0);
@@ -7539,7 +7541,7 @@ zfs_do_channel_program(int argc, char **argv)
char c;
char *progbuf, *filename, *poolname;
size_t progsize, progread;
- nvlist_t *outnvl;
+ nvlist_t *outnvl = NULL;
uint64_t instrlimit = ZCP_DEFAULT_INSTRLIMIT;
uint64_t memlimit = ZCP_DEFAULT_MEMLIMIT;
boolean_t sync_flag = B_TRUE, json_output = B_FALSE;
@@ -7679,7 +7681,8 @@ zfs_do_channel_program(int argc, char **argv)
* falling back on strerror() for an unexpected return code.
*/
char *errstring = NULL;
- if (nvlist_exists(outnvl, ZCP_RET_ERROR)) {
+ const char *msg = gettext("Channel program execution failed");
+ if (outnvl != NULL && nvlist_exists(outnvl, ZCP_RET_ERROR)) {
(void) nvlist_lookup_string(outnvl,
ZCP_RET_ERROR, &errstring);
if (errstring == NULL)
@@ -7704,12 +7707,11 @@ zfs_do_channel_program(int argc, char **argv)
"programs must be run as root.";
break;
default:
- errstring = strerror(ret);
+ (void) zfs_standard_error(g_zfs, ret, msg);
}
}
- (void) fprintf(stderr,
- gettext("Channel program execution failed:\n%s\n"),
- errstring);
+ if (errstring != NULL)
+ (void) fprintf(stderr, "%s:\n%s\n", msg, errstring);
} else {
if (json_output) {
(void) nvlist_print_json(stdout, outnvl);
diff --git a/usr/src/lib/libzfs/common/libzfs.h b/usr/src/lib/libzfs/common/libzfs.h
index 8d14d37866..bdc24ac6ef 100644
--- a/usr/src/lib/libzfs/common/libzfs.h
+++ b/usr/src/lib/libzfs/common/libzfs.h
@@ -22,7 +22,7 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011 Pawel Jakub Dawidek. All rights reserved.
- * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
+ * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
* Copyright 2020 Joyent, Inc.
* Copyright (c) 2013 Steven Hartland. All rights reserved.
* Copyright (c) 2014 Integros [integros.com]
@@ -147,6 +147,7 @@ typedef enum zfs_error {
EZFS_NO_TRIM, /* no active trim */
EZFS_TRIM_NOTSUP, /* device does not support trim */
EZFS_NO_RESILVER_DEFER, /* pool doesn't support resilver_defer */
+ EZFS_IOC_NOTSUPPORTED, /* operation not supported by zfs module */
EZFS_UNKNOWN
} zfs_error_t;
diff --git a/usr/src/lib/libzfs/common/libzfs_util.c b/usr/src/lib/libzfs/common/libzfs_util.c
index c3cf11a897..3ccefa5585 100644
--- a/usr/src/lib/libzfs/common/libzfs_util.c
+++ b/usr/src/lib/libzfs/common/libzfs_util.c
@@ -22,7 +22,7 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2020 Joyent, Inc.
- * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
+ * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
* Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
* Copyright (c) 2017 Datto Inc.
*/
@@ -205,6 +205,9 @@ libzfs_error_description(libzfs_handle_t *hdl)
case EZFS_NOTSUP:
return (dgettext(TEXT_DOMAIN, "operation not supported "
"on this dataset"));
+ case EZFS_IOC_NOTSUPPORTED:
+ return (dgettext(TEXT_DOMAIN, "operation not supported by "
+ "zfs kernel module"));
case EZFS_ACTIVE_SPARE:
return (dgettext(TEXT_DOMAIN, "pool has active shared spare "
"device"));
@@ -442,6 +445,22 @@ zfs_standard_error_fmt(libzfs_handle_t *hdl, int error, const char *fmt, ...)
case EREMOTEIO:
zfs_verror(hdl, EZFS_ACTIVE_POOL, fmt, ap);
break;
+ case ZFS_ERR_IOC_CMD_UNAVAIL:
+ zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "the loaded zfs "
+ "module does not support this operation. A reboot may "
+ "be required to enable this operation."));
+ zfs_verror(hdl, EZFS_IOC_NOTSUPPORTED, fmt, ap);
+ break;
+ case ZFS_ERR_IOC_ARG_UNAVAIL:
+ zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "the loaded zfs "
+ "module does not support an option for this operation. "
+ "A reboot may be required to enable this option."));
+ zfs_verror(hdl, EZFS_IOC_NOTSUPPORTED, fmt, ap);
+ break;
+ case ZFS_ERR_IOC_ARG_REQUIRED:
+ case ZFS_ERR_IOC_ARG_BADTYPE:
+ zfs_verror(hdl, EZFS_IOC_NOTSUPPORTED, fmt, ap);
+ break;
default:
zfs_error_aux(hdl, strerror(error));
zfs_verror(hdl, EZFS_UNKNOWN, fmt, ap);
@@ -547,6 +566,22 @@ zpool_standard_error_fmt(libzfs_handle_t *hdl, int error, const char *fmt, ...)
case ZFS_ERR_VDEV_TOO_BIG:
zfs_verror(hdl, EZFS_VDEV_TOO_BIG, fmt, ap);
break;
+ case ZFS_ERR_IOC_CMD_UNAVAIL:
+ zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "the loaded zfs "
+ "module does not support this operation. A reboot may "
+ "be required to enable this operation."));
+ zfs_verror(hdl, EZFS_IOC_NOTSUPPORTED, fmt, ap);
+ break;
+ case ZFS_ERR_IOC_ARG_UNAVAIL:
+ zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "the loaded zfs "
+ "module does not support an option for this operation. "
+ "A reboot may be required to enable this option."));
+ zfs_verror(hdl, EZFS_IOC_NOTSUPPORTED, fmt, ap);
+ break;
+ case ZFS_ERR_IOC_ARG_REQUIRED:
+ case ZFS_ERR_IOC_ARG_BADTYPE:
+ zfs_verror(hdl, EZFS_IOC_NOTSUPPORTED, fmt, ap);
+ break;
default:
zfs_error_aux(hdl, strerror(error));
zfs_verror(hdl, EZFS_UNKNOWN, fmt, ap);
diff --git a/usr/src/lib/libzfs_core/common/libzfs_core.c b/usr/src/lib/libzfs_core/common/libzfs_core.c
index 628b1cc8ff..31ffddd93f 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, 2017 by Delphix. All rights reserved.
+ * Copyright (c) 2012, 2018 by Delphix. All rights reserved.
* Copyright (c) 2013 Steven Hartland. All rights reserved.
* Copyright (c) 2014 Integros [integros.com]
* Copyright 2017 RackTop Systems.
@@ -79,6 +79,9 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#ifdef ZFS_DEBUG
+#include <stdio.h>
+#endif
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
@@ -92,6 +95,42 @@ static int g_fd = -1;
static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
static int g_refcount;
+#ifdef ZFS_DEBUG
+static zfs_ioc_t fail_ioc_cmd;
+static zfs_errno_t fail_ioc_err;
+
+static void
+libzfs_core_debug_ioc(void)
+{
+ /*
+ * To test running newer user space binaries with kernel's
+ * that don't yet support an ioctl or a new ioctl arg we
+ * provide an override to intentionally fail an ioctl.
+ *
+ * USAGE:
+ * The override variable, ZFS_IOC_TEST, is of the form "cmd:err"
+ *
+ * For example, to fail a ZFS_IOC_POOL_CHECKPOINT with a
+ * ZFS_ERR_IOC_CMD_UNAVAIL, the string would be "0x5a4d:1029"
+ *
+ * $ sudo sh -c "ZFS_IOC_TEST=0x5a4d:1029 zpool checkpoint tank"
+ * cannot checkpoint 'tank': the loaded zfs module does not support
+ * this operation. A reboot may be required to enable this operation.
+ */
+ if (fail_ioc_cmd == 0) {
+ char *ioc_test = getenv("ZFS_IOC_TEST");
+ unsigned int ioc_num = 0, ioc_err = 0;
+
+ if (ioc_test != NULL &&
+ sscanf(ioc_test, "%i:%i", &ioc_num, &ioc_err) == 2 &&
+ ioc_num < ZFS_IOC_LAST) {
+ fail_ioc_cmd = ioc_num;
+ fail_ioc_err = ioc_err;
+ }
+ }
+}
+#endif
+
int
libzfs_core_init(void)
{
@@ -104,6 +143,10 @@ libzfs_core_init(void)
}
}
g_refcount++;
+
+#ifdef ZFS_DEBUG
+ libzfs_core_debug_ioc();
+#endif
(void) pthread_mutex_unlock(&g_lock);
return (0);
}
@@ -136,6 +179,11 @@ lzc_ioctl(zfs_ioc_t ioc, const char *name,
ASSERT3S(g_refcount, >, 0);
VERIFY3S(g_fd, !=, -1);
+#ifdef ZFS_DEBUG
+ if (ioc == fail_ioc_cmd)
+ return (fail_ioc_err);
+#endif
+
if (name != NULL)
(void) strlcpy(zc.zc_name, name, sizeof (zc.zc_name));
diff --git a/usr/src/pkg/README.pkg b/usr/src/pkg/README.pkg
index 9c4d86ad3f..1910c3adeb 100644
--- a/usr/src/pkg/README.pkg
+++ b/usr/src/pkg/README.pkg
@@ -442,10 +442,7 @@ The following actions are required for all packages in ON.
in /usr/share/package-manager/data/opensolaris.org.sections.
license
- All packages must specify a set of license actions. If
- you're adding items here that are not already included in
- usr/src/pkg/license_files, then you will also need to modify
- usr/src/tools/opensolaris/license-list.
+ All packages must specify a set of license actions.
You don't need to set the following. They're taken care of for all OS/Net
packages in the transforms/common_actions file.
diff --git a/usr/src/pkg/manifests/system-test-zfstest.mf b/usr/src/pkg/manifests/system-test-zfstest.mf
index 9f78c29bb5..f4b2dca8d8 100644
--- a/usr/src/pkg/manifests/system-test-zfstest.mf
+++ b/usr/src/pkg/manifests/system-test-zfstest.mf
@@ -192,6 +192,7 @@ file path=opt/zfs-tests/bin/file_write mode=0555
file path=opt/zfs-tests/bin/getholes mode=0555
file path=opt/zfs-tests/bin/has_unmap mode=0555
file path=opt/zfs-tests/bin/largest_file mode=0555
+file path=opt/zfs-tests/bin/libzfs_input_check mode=0555
file path=opt/zfs-tests/bin/memory_balloon mode=0555
file path=opt/zfs-tests/bin/mkbusy mode=0555
file path=opt/zfs-tests/bin/mkfiles mode=0555
@@ -2604,7 +2605,10 @@ file path=opt/zfs-tests/tests/functional/largest_pool/largest_pool.cfg \
mode=0444
file path=opt/zfs-tests/tests/functional/largest_pool/largest_pool_001_pos \
mode=0555
+file path=opt/zfs-tests/tests/functional/libzfs/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/libzfs/libzfs_input mode=0555
file path=opt/zfs-tests/tests/functional/libzfs/many_fds mode=0555
+file path=opt/zfs-tests/tests/functional/libzfs/setup mode=0555
file path=opt/zfs-tests/tests/functional/link_count/cleanup mode=0555
file path=opt/zfs-tests/tests/functional/link_count/link_count_001 mode=0555
file path=opt/zfs-tests/tests/functional/link_count/setup mode=0555
diff --git a/usr/src/test/zfs-tests/cmd/libzfs_input_check/.gitignore b/usr/src/test/zfs-tests/cmd/libzfs_input_check/.gitignore
new file mode 100644
index 0000000000..c879600848
--- /dev/null
+++ b/usr/src/test/zfs-tests/cmd/libzfs_input_check/.gitignore
@@ -0,0 +1 @@
+/libzfs_input_check
diff --git a/usr/src/test/zfs-tests/cmd/libzfs_input_check/Makefile b/usr/src/test/zfs-tests/cmd/libzfs_input_check/Makefile
new file mode 100644
index 0000000000..c525e9e06c
--- /dev/null
+++ b/usr/src/test/zfs-tests/cmd/libzfs_input_check/Makefile
@@ -0,0 +1,22 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2020 Joyent, Inc.
+#
+
+PROG = libzfs_input_check
+
+include $(SRC)/cmd/Makefile.cmd
+include ../Makefile.subdirs
+
+CPPFLAGS += -I$(SRC)/uts/common/fs/zfs
+LDLIBS += -lnvpair -lzfs_core
diff --git a/usr/src/test/zfs-tests/cmd/libzfs_input_check/libzfs_input_check.c b/usr/src/test/zfs-tests/cmd/libzfs_input_check/libzfs_input_check.c
new file mode 100644
index 0000000000..b469a96982
--- /dev/null
+++ b/usr/src/test/zfs-tests/cmd/libzfs_input_check/libzfs_input_check.c
@@ -0,0 +1,973 @@
+/*
+ * CDDL HEADER START
+ *
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright (c) 2018 by Delphix. All rights reserved.
+ * Copyright 2020 Joyent, Inc.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <libzfs_core.h>
+#include <unistd.h>
+
+#include <sys/nvpair.h>
+#include <sys/zfs_ioctl.h>
+
+/*
+ * Test the nvpair inputs for the non-legacy zfs ioctl commands.
+ */
+
+boolean_t unexpected_failures;
+int zfs_fd;
+const char *active_test;
+
+/*
+ * Tracks which zfs_ioc_t commands were tested
+ */
+boolean_t ioc_tested[256];
+
+/*
+ * Legacy ioctls that are skipped (for now)
+ */
+static unsigned ioc_skip[] = {
+ ZFS_IOC_POOL_CREATE,
+ ZFS_IOC_POOL_DESTROY,
+ ZFS_IOC_POOL_IMPORT,
+ ZFS_IOC_POOL_EXPORT,
+ ZFS_IOC_POOL_CONFIGS,
+ ZFS_IOC_POOL_STATS,
+ ZFS_IOC_POOL_TRYIMPORT,
+ ZFS_IOC_POOL_SCAN,
+ ZFS_IOC_POOL_FREEZE,
+ ZFS_IOC_POOL_UPGRADE,
+ ZFS_IOC_POOL_GET_HISTORY,
+
+ ZFS_IOC_VDEV_ADD,
+ ZFS_IOC_VDEV_REMOVE,
+ ZFS_IOC_VDEV_SET_STATE,
+ ZFS_IOC_VDEV_ATTACH,
+ ZFS_IOC_VDEV_DETACH,
+ ZFS_IOC_VDEV_SETPATH,
+ ZFS_IOC_VDEV_SETFRU,
+
+ ZFS_IOC_OBJSET_STATS,
+ ZFS_IOC_OBJSET_ZPLPROPS,
+ ZFS_IOC_DATASET_LIST_NEXT,
+ ZFS_IOC_SNAPSHOT_LIST_NEXT,
+ ZFS_IOC_SET_PROP,
+ ZFS_IOC_DESTROY,
+ ZFS_IOC_RENAME,
+ ZFS_IOC_RECV,
+ ZFS_IOC_SEND,
+ ZFS_IOC_INJECT_FAULT,
+ ZFS_IOC_CLEAR_FAULT,
+ ZFS_IOC_INJECT_LIST_NEXT,
+ ZFS_IOC_ERROR_LOG,
+ ZFS_IOC_CLEAR,
+ ZFS_IOC_PROMOTE,
+ ZFS_IOC_DSOBJ_TO_DSNAME,
+ ZFS_IOC_OBJ_TO_PATH,
+ ZFS_IOC_POOL_SET_PROPS,
+ ZFS_IOC_POOL_GET_PROPS,
+ ZFS_IOC_SET_FSACL,
+ ZFS_IOC_GET_FSACL,
+ ZFS_IOC_SHARE,
+ ZFS_IOC_INHERIT_PROP,
+ ZFS_IOC_SMB_ACL,
+ ZFS_IOC_USERSPACE_ONE,
+ ZFS_IOC_USERSPACE_MANY,
+ ZFS_IOC_USERSPACE_UPGRADE,
+ ZFS_IOC_OBJSET_RECVD_PROPS,
+ ZFS_IOC_VDEV_SPLIT,
+ ZFS_IOC_NEXT_OBJ,
+ ZFS_IOC_DIFF,
+ ZFS_IOC_TMP_SNAPSHOT,
+ ZFS_IOC_OBJ_TO_STATS,
+ ZFS_IOC_SPACE_WRITTEN,
+ ZFS_IOC_POOL_REGUID,
+ ZFS_IOC_SEND_PROGRESS,
+
+#ifndef __sun
+ ZFS_IOC_EVENTS_NEXT,
+ ZFS_IOC_EVENTS_CLEAR,
+ ZFS_IOC_EVENTS_SEEK,
+#else
+ /* This is still a legacy ioctl in illumos */
+ ZFS_IOC_POOL_REOPEN,
+#endif
+};
+
+
+#define IOC_INPUT_TEST(ioc, name, req, opt, err) \
+ IOC_INPUT_TEST_IMPL(ioc, name, req, opt, err, B_FALSE)
+
+#define IOC_INPUT_TEST_WILD(ioc, name, req, opt, err) \
+ IOC_INPUT_TEST_IMPL(ioc, name, req, opt, err, B_TRUE)
+
+#define IOC_INPUT_TEST_IMPL(ioc, name, req, opt, err, wild) \
+ do { \
+ active_test = __func__ + 5; \
+ ioc_tested[ioc - ZFS_IOC_FIRST] = B_TRUE; \
+ (void) lzc_ioctl_test(ioc, name, req, opt, err, wild); \
+ } while (0)
+
+/*
+ * run a zfs ioctl command, verify expected results and log failures
+ */
+static void
+lzc_ioctl_run(zfs_ioc_t ioc, const char *name, nvlist_t *innvl, int expected)
+{
+ zfs_cmd_t zc = {"\0"};
+ char *packed = NULL;
+ const char *variant;
+ size_t size = 0;
+ int error = 0;
+
+ switch (expected) {
+ case ZFS_ERR_IOC_ARG_UNAVAIL:
+ variant = "unsupported input";
+ break;
+ case ZFS_ERR_IOC_ARG_REQUIRED:
+ variant = "missing input";
+ break;
+ case ZFS_ERR_IOC_ARG_BADTYPE:
+ variant = "invalid input type";
+ break;
+ default:
+ variant = "valid input";
+ break;
+ }
+
+ packed = fnvlist_pack(innvl, &size);
+ (void) strncpy(zc.zc_name, name, sizeof (zc.zc_name));
+ zc.zc_name[sizeof (zc.zc_name) - 1] = '\0';
+ zc.zc_nvlist_src = (uint64_t)(uintptr_t)packed;
+ zc.zc_nvlist_src_size = size;
+ zc.zc_nvlist_dst_size = MAX(size * 2, 128 * 1024);
+ zc.zc_nvlist_dst = (uint64_t)(uintptr_t)malloc(zc.zc_nvlist_dst_size);
+
+ if (ioctl(zfs_fd, ioc, &zc) != 0)
+ error = errno;
+
+ if (error != expected) {
+ unexpected_failures = B_TRUE;
+ (void) fprintf(stderr, "%s: Unexpected result with %s, "
+ "error %d (expecting %d)\n",
+ active_test, variant, error, expected);
+ }
+
+ fnvlist_pack_free(packed, size);
+ free((void *)(uintptr_t)zc.zc_nvlist_dst);
+}
+
+/*
+ * Test each ioc for the following ioctl input errors:
+ * ZFS_ERR_IOC_ARG_UNAVAIL an input argument is not supported by kernel
+ * ZFS_ERR_IOC_ARG_REQUIRED a required input argument is missing
+ * ZFS_ERR_IOC_ARG_BADTYPE an input argument has an invalid type
+ */
+static int
+lzc_ioctl_test(zfs_ioc_t ioc, const char *name, nvlist_t *required,
+ nvlist_t *optional, int expected_error, boolean_t wildcard)
+{
+ nvlist_t *input = fnvlist_alloc();
+ nvlist_t *future = fnvlist_alloc();
+ int error = 0;
+
+ if (required != NULL) {
+ for (nvpair_t *pair = nvlist_next_nvpair(required, NULL);
+ pair != NULL; pair = nvlist_next_nvpair(required, pair)) {
+ fnvlist_add_nvpair(input, pair);
+ }
+ }
+ if (optional != NULL) {
+ for (nvpair_t *pair = nvlist_next_nvpair(optional, NULL);
+ pair != NULL; pair = nvlist_next_nvpair(optional, pair)) {
+ fnvlist_add_nvpair(input, pair);
+ }
+ }
+
+ /*
+ * Generic input run with 'optional' nvlist pair
+ */
+ if (!wildcard)
+ fnvlist_add_nvlist(input, "optional", future);
+ lzc_ioctl_run(ioc, name, input, expected_error);
+ if (!wildcard)
+ fnvlist_remove(input, "optional");
+
+ /*
+ * Bogus input value
+ */
+ if (!wildcard) {
+ fnvlist_add_string(input, "bogus_input", "bogus");
+ lzc_ioctl_run(ioc, name, input, ZFS_ERR_IOC_ARG_UNAVAIL);
+ fnvlist_remove(input, "bogus_input");
+ }
+
+ /*
+ * Missing required inputs
+ */
+ if (required != NULL) {
+ nvlist_t *empty = fnvlist_alloc();
+ lzc_ioctl_run(ioc, name, empty, ZFS_ERR_IOC_ARG_REQUIRED);
+ nvlist_free(empty);
+ }
+
+ /*
+ * Wrong nvpair type
+ */
+ if (required != NULL || optional != NULL) {
+ /*
+ * switch the type of one of the input pairs
+ */
+ for (nvpair_t *pair = nvlist_next_nvpair(input, NULL);
+ pair != NULL; pair = nvlist_next_nvpair(input, pair)) {
+ char pname[MAXNAMELEN];
+ data_type_t ptype;
+
+ (void) strncpy(pname, nvpair_name(pair),
+ sizeof (pname));
+ pname[sizeof (pname) - 1] = '\0';
+ ptype = nvpair_type(pair);
+ fnvlist_remove_nvpair(input, pair);
+
+ switch (ptype) {
+ case DATA_TYPE_STRING:
+ fnvlist_add_uint64(input, pname, 42);
+ break;
+ default:
+ fnvlist_add_string(input, pname, "bogus");
+ break;
+ }
+ }
+ lzc_ioctl_run(ioc, name, input, ZFS_ERR_IOC_ARG_BADTYPE);
+ }
+
+ nvlist_free(future);
+ nvlist_free(input);
+
+ return (error);
+}
+
+static void
+test_pool_sync(const char *pool)
+{
+ nvlist_t *required = fnvlist_alloc();
+
+ fnvlist_add_boolean_value(required, "force", B_TRUE);
+
+ IOC_INPUT_TEST(ZFS_IOC_POOL_SYNC, pool, required, NULL, 0);
+
+ nvlist_free(required);
+}
+
+#ifndef sun
+static void
+test_pool_reopen(const char *pool)
+{
+ nvlist_t *required = fnvlist_alloc();
+
+ fnvlist_add_boolean_value(required, "scrub_restart", B_FALSE);
+
+ IOC_INPUT_TEST(ZFS_IOC_POOL_REOPEN, pool, required, NULL, 0);
+
+ nvlist_free(required);
+}
+#endif
+
+static void
+test_pool_checkpoint(const char *pool)
+{
+ IOC_INPUT_TEST(ZFS_IOC_POOL_CHECKPOINT, pool, NULL, NULL, 0);
+}
+
+static void
+test_pool_discard_checkpoint(const char *pool)
+{
+ int err = lzc_pool_checkpoint(pool);
+ if (err == 0 || err == ZFS_ERR_CHECKPOINT_EXISTS)
+ IOC_INPUT_TEST(ZFS_IOC_POOL_DISCARD_CHECKPOINT, pool, NULL,
+ NULL, 0);
+}
+
+static void
+test_log_history(const char *pool)
+{
+ nvlist_t *required = fnvlist_alloc();
+
+ fnvlist_add_string(required, "message", "input check");
+
+ IOC_INPUT_TEST(ZFS_IOC_LOG_HISTORY, pool, required, NULL, 0);
+
+ nvlist_free(required);
+}
+
+static void
+test_create(const char *pool)
+{
+ char dataset[MAXNAMELEN + 32];
+
+ (void) snprintf(dataset, sizeof (dataset), "%s/create-fs", pool);
+
+ nvlist_t *required = fnvlist_alloc();
+ nvlist_t *optional = fnvlist_alloc();
+ nvlist_t *props = fnvlist_alloc();
+
+ fnvlist_add_int32(required, "type", DMU_OST_ZFS);
+ fnvlist_add_uint64(props, "recordsize", 8192);
+ fnvlist_add_nvlist(optional, "props", props);
+
+ IOC_INPUT_TEST(ZFS_IOC_CREATE, dataset, required, optional, 0);
+
+ nvlist_free(required);
+ nvlist_free(optional);
+}
+
+static void
+test_snapshot(const char *pool, const char *snapshot)
+{
+ nvlist_t *required = fnvlist_alloc();
+ nvlist_t *optional = fnvlist_alloc();
+ nvlist_t *snaps = fnvlist_alloc();
+ nvlist_t *props = fnvlist_alloc();
+
+ fnvlist_add_boolean(snaps, snapshot);
+ fnvlist_add_nvlist(required, "snaps", snaps);
+
+ fnvlist_add_string(props, "org.openzfs:launch", "September 17th, 2013");
+ fnvlist_add_nvlist(optional, "props", props);
+
+ IOC_INPUT_TEST(ZFS_IOC_SNAPSHOT, pool, required, optional, 0);
+
+ nvlist_free(props);
+ nvlist_free(snaps);
+ nvlist_free(optional);
+ nvlist_free(required);
+}
+
+static void
+test_space_snaps(const char *snapshot)
+{
+ nvlist_t *required = fnvlist_alloc();
+ fnvlist_add_string(required, "firstsnap", snapshot);
+
+ IOC_INPUT_TEST(ZFS_IOC_SPACE_SNAPS, snapshot, required, NULL, 0);
+
+ nvlist_free(required);
+}
+
+static void
+test_destroy_snaps(const char *pool, const char *snapshot)
+{
+ nvlist_t *required = fnvlist_alloc();
+ nvlist_t *snaps = fnvlist_alloc();
+
+ fnvlist_add_boolean(snaps, snapshot);
+ fnvlist_add_nvlist(required, "snaps", snaps);
+
+ IOC_INPUT_TEST(ZFS_IOC_DESTROY_SNAPS, pool, required, NULL, 0);
+
+ nvlist_free(snaps);
+ nvlist_free(required);
+}
+
+
+static void
+test_bookmark(const char *pool, const char *snapshot, const char *bookmark)
+{
+ nvlist_t *required = fnvlist_alloc();
+
+ fnvlist_add_string(required, bookmark, snapshot);
+
+ IOC_INPUT_TEST_WILD(ZFS_IOC_BOOKMARK, pool, required, NULL, 0);
+
+ nvlist_free(required);
+}
+
+static void
+test_get_bookmarks(const char *dataset)
+{
+ nvlist_t *optional = fnvlist_alloc();
+
+ fnvlist_add_boolean(optional, "guid");
+ fnvlist_add_boolean(optional, "createtxg");
+ fnvlist_add_boolean(optional, "creation");
+
+ IOC_INPUT_TEST_WILD(ZFS_IOC_GET_BOOKMARKS, dataset, NULL, optional, 0);
+
+ nvlist_free(optional);
+}
+
+static void
+test_destroy_bookmarks(const char *pool, const char *bookmark)
+{
+ nvlist_t *required = fnvlist_alloc();
+
+ fnvlist_add_boolean(required, bookmark);
+
+ IOC_INPUT_TEST_WILD(ZFS_IOC_DESTROY_BOOKMARKS, pool, required, NULL, 0);
+
+ nvlist_free(required);
+}
+
+static void
+test_clone(const char *snapshot, const char *clone)
+{
+ nvlist_t *required = fnvlist_alloc();
+ nvlist_t *optional = fnvlist_alloc();
+ nvlist_t *props = fnvlist_alloc();
+
+ fnvlist_add_string(required, "origin", snapshot);
+
+ IOC_INPUT_TEST(ZFS_IOC_CLONE, clone, required, NULL, 0);
+
+ nvlist_free(props);
+ nvlist_free(optional);
+ nvlist_free(required);
+}
+
+static void
+test_rollback(const char *dataset, const char *snapshot)
+{
+ nvlist_t *optional = fnvlist_alloc();
+
+ fnvlist_add_string(optional, "target", snapshot);
+
+ IOC_INPUT_TEST(ZFS_IOC_ROLLBACK, dataset, NULL, optional, B_FALSE);
+
+ nvlist_free(optional);
+}
+
+static void
+test_hold(const char *pool, const char *snapshot)
+{
+ nvlist_t *required = fnvlist_alloc();
+ nvlist_t *optional = fnvlist_alloc();
+ nvlist_t *holds = fnvlist_alloc();
+
+ fnvlist_add_string(holds, snapshot, "libzfs_check_hold");
+ fnvlist_add_nvlist(required, "holds", holds);
+ fnvlist_add_int32(optional, "cleanup_fd", zfs_fd);
+
+ IOC_INPUT_TEST(ZFS_IOC_HOLD, pool, required, optional, 0);
+
+ nvlist_free(holds);
+ nvlist_free(optional);
+ nvlist_free(required);
+}
+
+static void
+test_get_holds(const char *snapshot)
+{
+ IOC_INPUT_TEST(ZFS_IOC_GET_HOLDS, snapshot, NULL, NULL, 0);
+}
+
+static void
+test_release(const char *pool, const char *snapshot)
+{
+ nvlist_t *required = fnvlist_alloc();
+ nvlist_t *release = fnvlist_alloc();
+
+ fnvlist_add_boolean(release, "libzfs_check_hold");
+ fnvlist_add_nvlist(required, snapshot, release);
+
+ IOC_INPUT_TEST_WILD(ZFS_IOC_RELEASE, pool, required, NULL, 0);
+
+ nvlist_free(release);
+ nvlist_free(required);
+}
+
+
+static void
+test_send_new(const char *snapshot, int fd)
+{
+ nvlist_t *required = fnvlist_alloc();
+ nvlist_t *optional = fnvlist_alloc();
+
+ fnvlist_add_int32(required, "fd", fd);
+
+ fnvlist_add_boolean(optional, "largeblockok");
+ fnvlist_add_boolean(optional, "embedok");
+ fnvlist_add_boolean(optional, "compressok");
+ fnvlist_add_boolean(optional, "rawok");
+
+ /*
+ * TODO - Resumable send is harder to set up. So we currently
+ * ignore testing for that variant.
+ */
+#if 0
+ fnvlist_add_string(optional, "fromsnap", from);
+ fnvlist_add_uint64(optional, "resume_object", resumeobj);
+ fnvlist_add_uint64(optional, "resume_offset", offset);
+#endif
+ IOC_INPUT_TEST(ZFS_IOC_SEND_NEW, snapshot, required, optional, 0);
+
+ nvlist_free(optional);
+ nvlist_free(required);
+}
+
+#ifndef __sun
+static void
+test_recv_new(const char *dataset, int fd)
+{
+ dmu_replay_record_t drr = { 0 };
+ nvlist_t *required = fnvlist_alloc();
+ nvlist_t *optional = fnvlist_alloc();
+ nvlist_t *props = fnvlist_alloc();
+ char snapshot[MAXNAMELEN + 32];
+ ssize_t count;
+
+ int cleanup_fd = open(ZFS_DEV, O_RDWR);
+
+ (void) snprintf(snapshot, sizeof (snapshot), "%s@replicant", dataset);
+
+ count = pread(fd, &drr, sizeof (drr), 0);
+ if (count != sizeof (drr)) {
+ (void) fprintf(stderr, "could not read stream: %s\n",
+ strerror(errno));
+ }
+
+ fnvlist_add_string(required, "snapname", snapshot);
+ fnvlist_add_byte_array(required, "begin_record", (uchar_t *)&drr,
+ sizeof (drr));
+ fnvlist_add_int32(required, "input_fd", fd);
+
+ fnvlist_add_string(props, "org.openzfs:launch", "September 17th, 2013");
+ fnvlist_add_nvlist(optional, "localprops", props);
+ fnvlist_add_boolean(optional, "force");
+ fnvlist_add_int32(optional, "cleanup_fd", cleanup_fd);
+
+ /*
+ * TODO - Resumable receive is harder to set up. So we currently
+ * ignore testing for one.
+ */
+#if 0
+ fnvlist_add_nvlist(optional, "props", recvdprops);
+ fnvlist_add_string(optional, "origin", origin);
+ fnvlist_add_boolean(optional, "resumable");
+ fnvlist_add_uint64(optional, "action_handle", *action_handle);
+#endif
+ IOC_INPUT_TEST(ZFS_IOC_RECV_NEW, dataset, required, optional, EBADE);
+
+ nvlist_free(props);
+ nvlist_free(optional);
+ nvlist_free(required);
+
+ (void) close(cleanup_fd);
+}
+#endif
+
+static void
+test_send_space(const char *snapshot1, const char *snapshot2)
+{
+ nvlist_t *optional = fnvlist_alloc();
+
+ fnvlist_add_string(optional, "from", snapshot1);
+ fnvlist_add_boolean(optional, "largeblockok");
+ fnvlist_add_boolean(optional, "embedok");
+ fnvlist_add_boolean(optional, "compressok");
+ fnvlist_add_boolean(optional, "rawok");
+
+ IOC_INPUT_TEST(ZFS_IOC_SEND_SPACE, snapshot2, NULL, optional, 0);
+
+ nvlist_free(optional);
+}
+
+static void
+test_remap(const char *dataset)
+{
+ IOC_INPUT_TEST(ZFS_IOC_REMAP, dataset, NULL, NULL, 0);
+}
+
+static void
+test_channel_program(const char *pool)
+{
+ const char *program =
+ "arg = ...\n"
+ "argv = arg[\"argv\"]\n"
+ "return argv[1]";
+ char *const argv[1] = { "Hello World!" };
+ nvlist_t *required = fnvlist_alloc();
+ nvlist_t *optional = fnvlist_alloc();
+ nvlist_t *args = fnvlist_alloc();
+
+ fnvlist_add_string(required, "program", program);
+ fnvlist_add_string_array(args, "argv", argv, 1);
+ fnvlist_add_nvlist(required, "arg", args);
+
+ fnvlist_add_boolean_value(optional, "sync", B_TRUE);
+ fnvlist_add_uint64(optional, "instrlimit", 1000 * 1000);
+ fnvlist_add_uint64(optional, "memlimit", 8192 * 1024);
+
+ IOC_INPUT_TEST(ZFS_IOC_CHANNEL_PROGRAM, pool, required, optional, 0);
+
+ nvlist_free(args);
+ nvlist_free(optional);
+ nvlist_free(required);
+}
+
+#define WRAPPING_KEY_LEN 32
+
+static void
+test_load_key(const char *dataset)
+{
+ nvlist_t *required = fnvlist_alloc();
+ nvlist_t *optional = fnvlist_alloc();
+ nvlist_t *hidden = fnvlist_alloc();
+ uint8_t keydata[WRAPPING_KEY_LEN] = {0};
+
+ fnvlist_add_uint8_array(hidden, "wkeydata", keydata, sizeof (keydata));
+ fnvlist_add_nvlist(required, "hidden_args", hidden);
+ fnvlist_add_boolean(optional, "noop");
+
+ IOC_INPUT_TEST(ZFS_IOC_LOAD_KEY, dataset, required, optional, EINVAL);
+ nvlist_free(hidden);
+ nvlist_free(optional);
+ nvlist_free(required);
+}
+
+static void
+test_change_key(const char *dataset)
+{
+ IOC_INPUT_TEST(ZFS_IOC_CHANGE_KEY, dataset, NULL, NULL, EINVAL);
+}
+
+static void
+test_unload_key(const char *dataset)
+{
+ IOC_INPUT_TEST(ZFS_IOC_UNLOAD_KEY, dataset, NULL, NULL, EACCES);
+}
+
+static void
+test_vdev_initialize(const char *pool)
+{
+ nvlist_t *required = fnvlist_alloc();
+ nvlist_t *vdev_guids = fnvlist_alloc();
+
+ fnvlist_add_uint64(vdev_guids, "path", 0xdeadbeefdeadbeef);
+ fnvlist_add_uint64(required, ZPOOL_INITIALIZE_COMMAND,
+ POOL_INITIALIZE_START);
+ fnvlist_add_nvlist(required, ZPOOL_INITIALIZE_VDEVS, vdev_guids);
+
+ IOC_INPUT_TEST(ZFS_IOC_POOL_INITIALIZE, pool, required, NULL, EINVAL);
+ nvlist_free(vdev_guids);
+ nvlist_free(required);
+}
+
+static void
+test_vdev_trim(const char *pool)
+{
+ nvlist_t *required = fnvlist_alloc();
+ nvlist_t *optional = fnvlist_alloc();
+ nvlist_t *vdev_guids = fnvlist_alloc();
+
+ fnvlist_add_uint64(vdev_guids, "path", 0xdeadbeefdeadbeef);
+ fnvlist_add_uint64(required, ZPOOL_TRIM_COMMAND, POOL_TRIM_START);
+ fnvlist_add_nvlist(required, ZPOOL_TRIM_VDEVS, vdev_guids);
+ fnvlist_add_uint64(optional, ZPOOL_TRIM_RATE, 1ULL << 30);
+ fnvlist_add_boolean_value(optional, ZPOOL_TRIM_SECURE, B_TRUE);
+
+ IOC_INPUT_TEST(ZFS_IOC_POOL_TRIM, pool, required, optional, EINVAL);
+ nvlist_free(vdev_guids);
+ nvlist_free(optional);
+ nvlist_free(required);
+}
+
+static int
+zfs_destroy(const char *dataset)
+{
+ zfs_cmd_t zc = {"\0"};
+ int err;
+
+ (void) strncpy(zc.zc_name, dataset, sizeof (zc.zc_name));
+ zc.zc_name[sizeof (zc.zc_name) - 1] = '\0';
+ zc.zc_objset_type = DMU_OST_ZFS;
+ err = ioctl(zfs_fd, ZFS_IOC_DESTROY, &zc);
+
+ return (err == 0 ? 0 : errno);
+}
+
+static void
+zfs_ioc_input_tests(const char *pool)
+{
+ char filepath[] = "/tmp/ioc_test_file_XXXXXX";
+ char dataset[ZFS_MAX_DATASET_NAME_LEN];
+ char snapbase[ZFS_MAX_DATASET_NAME_LEN + 32];
+ char snapshot[ZFS_MAX_DATASET_NAME_LEN + 32];
+ char bookmark[ZFS_MAX_DATASET_NAME_LEN + 32];
+ char backup[ZFS_MAX_DATASET_NAME_LEN];
+ char clone[ZFS_MAX_DATASET_NAME_LEN];
+ int tmpfd, err;
+
+ /*
+ * Setup names and create a working dataset
+ */
+ (void) snprintf(dataset, sizeof (dataset), "%s/test-fs", pool);
+ (void) snprintf(snapbase, sizeof (snapbase), "%s@snapbase", dataset);
+ (void) snprintf(snapshot, sizeof (snapshot), "%s@snapshot", dataset);
+ (void) snprintf(bookmark, sizeof (bookmark), "%s#bookmark", dataset);
+ (void) snprintf(clone, sizeof (clone), "%s/test-fs-clone", pool);
+ (void) snprintf(backup, sizeof (backup), "%s/backup", pool);
+
+ err = lzc_create(dataset, DMU_OST_ZFS, NULL, NULL, 0);
+ if (err) {
+ (void) fprintf(stderr, "could not create '%s': %s\n",
+ dataset, strerror(errno));
+ exit(2);
+ }
+
+ tmpfd = mkstemp(filepath);
+ if (tmpfd < 0) {
+ (void) fprintf(stderr, "could not create '%s': %s\n",
+ filepath, strerror(errno));
+ exit(2);
+ }
+
+ /*
+ * run a test for each ioctl
+ * Note that some test build on previous test operations
+ */
+ test_pool_sync(pool);
+#ifndef __sun
+ test_pool_reopen(pool);
+#endif
+ test_pool_checkpoint(pool);
+ test_pool_discard_checkpoint(pool);
+ test_log_history(pool);
+
+ test_create(dataset);
+ test_snapshot(pool, snapbase);
+ test_snapshot(pool, snapshot);
+
+ test_space_snaps(snapshot);
+ test_send_space(snapbase, snapshot);
+ test_send_new(snapshot, tmpfd);
+#ifndef __sun
+ test_recv_new(backup, tmpfd);
+#endif
+
+ test_bookmark(pool, snapshot, bookmark);
+ test_get_bookmarks(dataset);
+ test_destroy_bookmarks(pool, bookmark);
+
+ test_hold(pool, snapshot);
+ test_get_holds(snapshot);
+ test_release(pool, snapshot);
+
+ test_clone(snapshot, clone);
+ (void) zfs_destroy(clone);
+
+ test_rollback(dataset, snapshot);
+ test_destroy_snaps(pool, snapshot);
+ test_destroy_snaps(pool, snapbase);
+
+ test_remap(dataset);
+ test_channel_program(pool);
+
+ test_load_key(dataset);
+ test_change_key(dataset);
+ test_unload_key(dataset);
+
+ test_vdev_initialize(pool);
+ test_vdev_trim(pool);
+
+ /*
+ * cleanup
+ */
+ zfs_cmd_t zc = {"\0"};
+
+ nvlist_t *snaps = fnvlist_alloc();
+ fnvlist_add_boolean(snaps, snapshot);
+ (void) lzc_destroy_snaps(snaps, B_FALSE, NULL);
+ nvlist_free(snaps);
+
+ (void) zfs_destroy(dataset);
+ (void) zfs_destroy(backup);
+
+ (void) close(tmpfd);
+ (void) unlink(filepath);
+
+ /*
+ * All the unused slots should yield ZFS_ERR_IOC_CMD_UNAVAIL
+ */
+ for (int i = 0; i < ARRAY_SIZE(ioc_skip); i++) {
+ if (ioc_tested[ioc_skip[i] - ZFS_IOC_FIRST])
+ (void) fprintf(stderr, "cmd %d tested, not skipped!\n",
+ (int)(ioc_skip[i] - ZFS_IOC_FIRST));
+
+ ioc_tested[ioc_skip[i] - ZFS_IOC_FIRST] = B_TRUE;
+ }
+
+ (void) strncpy(zc.zc_name, pool, sizeof (zc.zc_name));
+ zc.zc_name[sizeof (zc.zc_name) - 1] = '\0';
+
+ for (unsigned ioc = ZFS_IOC_FIRST; ioc < ZFS_IOC_LAST; ioc++) {
+ unsigned cmd = ioc - ZFS_IOC_FIRST;
+
+ if (ioc_tested[cmd])
+ continue;
+
+ if (ioctl(zfs_fd, ioc, &zc) != 0 &&
+ errno != ZFS_ERR_IOC_CMD_UNAVAIL) {
+ (void) fprintf(stderr, "cmd %d is missing a test case "
+ "(%d)\n", cmd, errno);
+ }
+ }
+}
+
+enum zfs_ioc_ref {
+ ZFS_IOC_BASE = ('Z' << 8),
+ LINUX_IOC_BASE = ('Z' << 8) + 0x80,
+ FREEBSD_IOC_BASE = ('Z' << 8) + 0xC0,
+};
+
+/*
+ * Canonical reference check of /dev/zfs ioctl numbers.
+ * These cannot change and new ioctl numbers must be appended.
+ */
+boolean_t
+validate_ioc_values(void)
+{
+ return (
+ ZFS_IOC_BASE + 0 == ZFS_IOC_POOL_CREATE &&
+ ZFS_IOC_BASE + 1 == ZFS_IOC_POOL_DESTROY &&
+ ZFS_IOC_BASE + 2 == ZFS_IOC_POOL_IMPORT &&
+ ZFS_IOC_BASE + 3 == ZFS_IOC_POOL_EXPORT &&
+ ZFS_IOC_BASE + 4 == ZFS_IOC_POOL_CONFIGS &&
+ ZFS_IOC_BASE + 5 == ZFS_IOC_POOL_STATS &&
+ ZFS_IOC_BASE + 6 == ZFS_IOC_POOL_TRYIMPORT &&
+ ZFS_IOC_BASE + 7 == ZFS_IOC_POOL_SCAN &&
+ ZFS_IOC_BASE + 8 == ZFS_IOC_POOL_FREEZE &&
+ ZFS_IOC_BASE + 9 == ZFS_IOC_POOL_UPGRADE &&
+ ZFS_IOC_BASE + 10 == ZFS_IOC_POOL_GET_HISTORY &&
+ ZFS_IOC_BASE + 11 == ZFS_IOC_VDEV_ADD &&
+ ZFS_IOC_BASE + 12 == ZFS_IOC_VDEV_REMOVE &&
+ ZFS_IOC_BASE + 13 == ZFS_IOC_VDEV_SET_STATE &&
+ ZFS_IOC_BASE + 14 == ZFS_IOC_VDEV_ATTACH &&
+ ZFS_IOC_BASE + 15 == ZFS_IOC_VDEV_DETACH &&
+ ZFS_IOC_BASE + 16 == ZFS_IOC_VDEV_SETPATH &&
+ ZFS_IOC_BASE + 17 == ZFS_IOC_VDEV_SETFRU &&
+ ZFS_IOC_BASE + 18 == ZFS_IOC_OBJSET_STATS &&
+ ZFS_IOC_BASE + 19 == ZFS_IOC_OBJSET_ZPLPROPS &&
+ ZFS_IOC_BASE + 20 == ZFS_IOC_DATASET_LIST_NEXT &&
+ ZFS_IOC_BASE + 21 == ZFS_IOC_SNAPSHOT_LIST_NEXT &&
+ ZFS_IOC_BASE + 22 == ZFS_IOC_SET_PROP &&
+ ZFS_IOC_BASE + 23 == ZFS_IOC_CREATE &&
+ ZFS_IOC_BASE + 24 == ZFS_IOC_DESTROY &&
+ ZFS_IOC_BASE + 25 == ZFS_IOC_ROLLBACK &&
+ ZFS_IOC_BASE + 26 == ZFS_IOC_RENAME &&
+ ZFS_IOC_BASE + 27 == ZFS_IOC_RECV &&
+ ZFS_IOC_BASE + 28 == ZFS_IOC_SEND &&
+ ZFS_IOC_BASE + 29 == ZFS_IOC_INJECT_FAULT &&
+ ZFS_IOC_BASE + 30 == ZFS_IOC_CLEAR_FAULT &&
+ ZFS_IOC_BASE + 31 == ZFS_IOC_INJECT_LIST_NEXT &&
+ ZFS_IOC_BASE + 32 == ZFS_IOC_ERROR_LOG &&
+ ZFS_IOC_BASE + 33 == ZFS_IOC_CLEAR &&
+ ZFS_IOC_BASE + 34 == ZFS_IOC_PROMOTE &&
+ ZFS_IOC_BASE + 35 == ZFS_IOC_SNAPSHOT &&
+ ZFS_IOC_BASE + 36 == ZFS_IOC_DSOBJ_TO_DSNAME &&
+ ZFS_IOC_BASE + 37 == ZFS_IOC_OBJ_TO_PATH &&
+ ZFS_IOC_BASE + 38 == ZFS_IOC_POOL_SET_PROPS &&
+ ZFS_IOC_BASE + 39 == ZFS_IOC_POOL_GET_PROPS &&
+ ZFS_IOC_BASE + 40 == ZFS_IOC_SET_FSACL &&
+ ZFS_IOC_BASE + 41 == ZFS_IOC_GET_FSACL &&
+ ZFS_IOC_BASE + 42 == ZFS_IOC_SHARE &&
+ ZFS_IOC_BASE + 43 == ZFS_IOC_INHERIT_PROP &&
+ ZFS_IOC_BASE + 44 == ZFS_IOC_SMB_ACL &&
+ ZFS_IOC_BASE + 45 == ZFS_IOC_USERSPACE_ONE &&
+ ZFS_IOC_BASE + 46 == ZFS_IOC_USERSPACE_MANY &&
+ ZFS_IOC_BASE + 47 == ZFS_IOC_USERSPACE_UPGRADE &&
+ ZFS_IOC_BASE + 48 == ZFS_IOC_HOLD &&
+ ZFS_IOC_BASE + 49 == ZFS_IOC_RELEASE &&
+ ZFS_IOC_BASE + 50 == ZFS_IOC_GET_HOLDS &&
+ ZFS_IOC_BASE + 51 == ZFS_IOC_OBJSET_RECVD_PROPS &&
+ ZFS_IOC_BASE + 52 == ZFS_IOC_VDEV_SPLIT &&
+ ZFS_IOC_BASE + 53 == ZFS_IOC_NEXT_OBJ &&
+ ZFS_IOC_BASE + 54 == ZFS_IOC_DIFF &&
+ ZFS_IOC_BASE + 55 == ZFS_IOC_TMP_SNAPSHOT &&
+ ZFS_IOC_BASE + 56 == ZFS_IOC_OBJ_TO_STATS &&
+ ZFS_IOC_BASE + 57 == ZFS_IOC_SPACE_WRITTEN &&
+ ZFS_IOC_BASE + 58 == ZFS_IOC_SPACE_SNAPS &&
+ ZFS_IOC_BASE + 59 == ZFS_IOC_DESTROY_SNAPS &&
+ ZFS_IOC_BASE + 60 == ZFS_IOC_POOL_REGUID &&
+ ZFS_IOC_BASE + 61 == ZFS_IOC_POOL_REOPEN &&
+ ZFS_IOC_BASE + 62 == ZFS_IOC_SEND_PROGRESS &&
+ ZFS_IOC_BASE + 63 == ZFS_IOC_LOG_HISTORY &&
+ ZFS_IOC_BASE + 64 == ZFS_IOC_SEND_NEW &&
+ ZFS_IOC_BASE + 65 == ZFS_IOC_SEND_SPACE &&
+ ZFS_IOC_BASE + 66 == ZFS_IOC_CLONE &&
+ ZFS_IOC_BASE + 67 == ZFS_IOC_BOOKMARK &&
+ ZFS_IOC_BASE + 68 == ZFS_IOC_GET_BOOKMARKS &&
+ ZFS_IOC_BASE + 69 == ZFS_IOC_DESTROY_BOOKMARKS &&
+#ifndef __sun
+ ZFS_IOC_BASE + 71 == ZFS_IOC_RECV_NEW &&
+#endif
+ ZFS_IOC_BASE + 70 == ZFS_IOC_POOL_SYNC &&
+ ZFS_IOC_BASE + 71 == ZFS_IOC_CHANNEL_PROGRAM &&
+ ZFS_IOC_BASE + 72 == ZFS_IOC_LOAD_KEY &&
+ ZFS_IOC_BASE + 73 == ZFS_IOC_UNLOAD_KEY &&
+ ZFS_IOC_BASE + 74 == ZFS_IOC_CHANGE_KEY &&
+ ZFS_IOC_BASE + 75 == ZFS_IOC_REMAP &&
+ ZFS_IOC_BASE + 76 == ZFS_IOC_POOL_CHECKPOINT &&
+
+#ifndef __sun
+ ZFS_IOC_BASE + 78 == ZFS_IOC_POOL_DISCARD_CHECKPOINT &&
+ LINUX_IOC_BASE + 1 == ZFS_IOC_EVENTS_NEXT &&
+ LINUX_IOC_BASE + 2 == ZFS_IOC_EVENTS_CLEAR &&
+ LINUX_IOC_BASE + 3 == ZFS_IOC_EVENTS_SEEK);
+#else
+ ZFS_IOC_BASE + 77 == ZFS_IOC_POOL_DISCARD_CHECKPOINT &&
+ ZFS_IOC_BASE + 78 == ZFS_IOC_POOL_INITIALIZE &&
+ ZFS_IOC_BASE + 79 == ZFS_IOC_POOL_TRIM &&
+ ZFS_IOC_BASE + 80 == ZFS_IOC_REDACT &&
+ ZFS_IOC_BASE + 81 == ZFS_IOC_GET_BOOKMARK_PROPS);
+#endif
+}
+
+int
+main(int argc, const char *argv[])
+{
+ if (argc != 2) {
+ (void) fprintf(stderr, "usage: %s <pool>\n", argv[0]);
+ exit(2);
+ }
+
+ if (!validate_ioc_values()) {
+ (void) fprintf(stderr, "WARNING: zfs_ioc_t has binary "
+ "incompatible command values\n");
+ exit(3);
+ }
+
+ (void) libzfs_core_init();
+ zfs_fd = open(ZFS_DEV, O_RDWR|O_EXCL);
+ if (zfs_fd < 0) {
+ (void) fprintf(stderr, "open: %s\n", strerror(errno));
+ libzfs_core_fini();
+ exit(2);
+ }
+
+ zfs_ioc_input_tests(argv[1]);
+
+ (void) close(zfs_fd);
+ libzfs_core_fini();
+
+ return (unexpected_failures);
+}
diff --git a/usr/src/test/zfs-tests/include/commands.cfg b/usr/src/test/zfs-tests/include/commands.cfg
index 0ad892e2b2..8e9f67627d 100644
--- a/usr/src/test/zfs-tests/include/commands.cfg
+++ b/usr/src/test/zfs-tests/include/commands.cfg
@@ -187,6 +187,7 @@ export ZFSTEST_FILES='chg_usr_exec
getholes
has_unmap
largest_file
+ libzfs_input_check
mkbusy
mkfiles
mkholes
diff --git a/usr/src/test/zfs-tests/runfiles/omnios.run b/usr/src/test/zfs-tests/runfiles/omnios.run
index 54848ba403..bddaa871da 100644
--- a/usr/src/test/zfs-tests/runfiles/omnios.run
+++ b/usr/src/test/zfs-tests/runfiles/omnios.run
@@ -740,9 +740,7 @@ tests = ['zvol_swap_001_pos', 'zvol_swap_002_pos', 'zvol_swap_003_pos',
'zvol_swap_004_pos', 'zvol_swap_005_pos', 'zvol_swap_006_pos']
[/opt/zfs-tests/tests/functional/libzfs]
-tests = ['many_fds']
-pre =
-post =
+tests = ['many_fds', 'libzfs_input']
[/opt/zfs-tests/tests/functional/log_spacemap]
tests = ['log_spacemap_import_logs']
diff --git a/usr/src/test/zfs-tests/runfiles/openindiana.run b/usr/src/test/zfs-tests/runfiles/openindiana.run
index 6ae3857a0a..77c00af358 100644
--- a/usr/src/test/zfs-tests/runfiles/openindiana.run
+++ b/usr/src/test/zfs-tests/runfiles/openindiana.run
@@ -740,9 +740,7 @@ tests = ['zvol_swap_001_pos', 'zvol_swap_002_pos', 'zvol_swap_003_pos',
'zvol_swap_004_pos', 'zvol_swap_005_pos', 'zvol_swap_006_pos']
[/opt/zfs-tests/tests/functional/libzfs]
-tests = ['many_fds']
-pre =
-post =
+tests = ['many_fds', 'libzfs_input']
[/opt/zfs-tests/tests/functional/log_spacemap]
tests = ['log_spacemap_import_logs']
diff --git a/usr/src/test/zfs-tests/runfiles/smartos.run b/usr/src/test/zfs-tests/runfiles/smartos.run
index 18e819a301..68d14b5dae 100644
--- a/usr/src/test/zfs-tests/runfiles/smartos.run
+++ b/usr/src/test/zfs-tests/runfiles/smartos.run
@@ -639,9 +639,7 @@ tests = ['zvol_misc_001_neg', 'zvol_misc_002_pos', 'zvol_misc_003_neg',
'zvol_misc_004_pos', 'zvol_misc_005_neg', 'zvol_misc_006_pos']
[/opt/zfs-tests/tests/functional/libzfs]
-tests = ['many_fds']
-pre =
-post =
+tests = ['many_fds', 'libzfs_input']
[/opt/zfs-tests/tests/functional/log_spacemap]
tests = ['log_spacemap_import_logs']
diff --git a/usr/src/test/zfs-tests/tests/functional/libzfs/Makefile b/usr/src/test/zfs-tests/tests/functional/libzfs/Makefile
index b26af8631f..72bb398f20 100644
--- a/usr/src/test/zfs-tests/tests/functional/libzfs/Makefile
+++ b/usr/src/test/zfs-tests/tests/functional/libzfs/Makefile
@@ -10,6 +10,7 @@
#
#
# Copyright (C) 2015 STRATO AG. All rights reserved.
+# Copyright 2020 Joyent, Inc.
#
include $(SRC)/Makefile.master
@@ -17,7 +18,7 @@ include $(SRC)/Makefile.master
ROOTOPTPKG = $(ROOT)/opt/zfs-tests
TESTDIR = $(ROOTOPTPKG)/tests/functional/libzfs
PROG = many_fds
-SCRIPTS =
+SCRIPTS = setup libzfs_input cleanup
include $(SRC)/cmd/Makefile.cmd
include $(SRC)/test/Makefile.com
@@ -40,8 +41,6 @@ $(PROG): $(OBJS)
install: all $(CMDS)
-lint: lint_SRCS
-
clobber: clean
-$(RM) $(PROG)
diff --git a/usr/src/test/zfs-tests/tests/functional/libzfs/cleanup.ksh b/usr/src/test/zfs-tests/tests/functional/libzfs/cleanup.ksh
new file mode 100755
index 0000000000..3166bd6ec1
--- /dev/null
+++ b/usr/src/test/zfs-tests/tests/functional/libzfs/cleanup.ksh
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/usr/src/test/zfs-tests/tests/functional/libzfs/libzfs_input.ksh b/usr/src/test/zfs-tests/tests/functional/libzfs/libzfs_input.ksh
new file mode 100755
index 0000000000..bc39c0367b
--- /dev/null
+++ b/usr/src/test/zfs-tests/tests/functional/libzfs/libzfs_input.ksh
@@ -0,0 +1,30 @@
+#!/bin/ksh -p
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2018 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+#
+# DESCRIPTION:
+# run C program to test passing different input to libzfs ioctls
+#
+
+log_assert "libzfs ioctls handle invalid input arguments"
+
+log_must libzfs_input_check $TESTPOOL
+
+log_pass "libzfs ioctls handle invalid input arguments"
diff --git a/usr/src/test/zfs-tests/tests/functional/libzfs/setup.ksh b/usr/src/test/zfs-tests/tests/functional/libzfs/setup.ksh
new file mode 100755
index 0000000000..fc5cec3063
--- /dev/null
+++ b/usr/src/test/zfs-tests/tests/functional/libzfs/setup.ksh
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK
diff --git a/usr/src/tools/opensolaris/BINARYLICENSE.txt b/usr/src/tools/opensolaris/BINARYLICENSE.txt
deleted file mode 100644
index ec304cfdd0..0000000000
--- a/usr/src/tools/opensolaris/BINARYLICENSE.txt
+++ /dev/null
@@ -1,190 +0,0 @@
-Sun Microsystems, Inc. Binary Code License Agreement
-
-SUN MICROSYSTEMS, INC. ("SUN") IS WILLING TO LICENSE THE SOFTWARE TO YOU
-ONLY UPON THE CONDITION THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN
-THIS BINARY CODE LICENSE AGREEMENT ("AGREEMENT"). PLEASE READ THE
-AGREEMENT CAREFULLY. BY DOWNLOADING OR INSTALLING THIS SOFTWARE, YOU
-ACCEPT THE FULL TERMS OF THIS AGREEMENT.
-
-1. Definitions.
-
-"Software" means all software provided to You in binary code form by Sun
-under this License as indicated on the opensolaris.org website. Software
-includes any updates or error corrections or documentation relating to
-Software provided to You by Sun under this License as indicated on the
-opensolaris.org website.
-
-2. Permitted Uses.
-
-Subject to the terms and conditions of this Agreement and restrictions and
-exceptions set forth in the Software's documentation, Sun grants you a
-non-exclusive, non-transferable, limited license without fees to
-
-(a) reproduce and use internally the Software for the purposes of
-developing or running an Open Solaris distribution.
-
-(b) reproduce and distribute the Software (and also portions of Software
-identified as Redistributable in the documentation accompanying Software),
-provided that you (i) distribute the Software or Redistributables bundled
-as part of, and for the sole purpose of running, OpenSolaris code;
-(ii) do not remove or alter any proprietary legends or notices contained
-in or on the Software or Redistributables, (iii) only distribute the
-Software or Redistributables subject to a license agreement that protects
-Sun's interests consistent with the terms contained in this Agreement,
-and (iv) you agree to defend and indemnify Sun and its licensors from and
-against any damages, costs, liabilities, settlement amounts and/or
-expenses (including attorneys' fees) incurred in connection with any claim,
-lawsuit or action by any third party that arises or results from the use
-or distribution of any and all Programs, Software, or Redistributables.
-
-3. Restrictions.
-
-(a) The copies of Software provided to you under this Agreement is
-licensed, not sold, to you by Sun. Sun reserves all rights not expressly
-granted.
-
-(b) You may not modify Software. However if the documentation
-accompanying Software lists specific portions of Software, such as header
-files, class libraries, reference source code, and/or redistributable
-files, that may be handled differently, you may do so only as provided in
-the documentation.
-
-(c) You may not rent, lease, lend or encumber Software.
-
-(d) You do not remove or alter any proprietary legends or notices
-contained in the Software,
-
-(e) Unless enforcement is prohibited by applicable law, you may not
-decompile, or reverse engineer Software.
-
-(f) The terms and conditions of this Agreement will apply to any Software
-updates, provided to you at Sun's discretion, that replace and/or
-supplement the original Software, unless such update contains a separate
-license.
-
-(g) Software is copyrighted.
-
-(h) Software is not designed, licensed or intended for use in the design,
-construction, operation or maintenance of any nuclear facility and Sun
-and its licensors disclaim any express or implied warranty of fitness for
-such uses.
-
-(i) No right, title or interest in or to any trademark, service mark,
-logo or trade name of Sun or its licensors is granted under this
-Agreement.
-
-(j) If your Permitted Use in this Agreement permits the distribution
-Software or portions of the Software, you may only distribute the Software
-subject to a license agreement that protects Sun's interests consistent
-with the terms contained in this Agreement.
-
-4. Java Compatibility and Open Source.
-
-Software may contain Java technology. You may not create additional
-classes to, or modifications of, the Java technology, except under
-compatibility requirements available under a separate agreement available
-at www.java.net.
-
-Sun supports and benefits from the global community of open source
-developers, and thanks the community for its important contributions and
-open standards-based technology, which Sun has adopted into many of its
-products.
-
-Please note that portions of Software may be provided with notices and
-open source licenses from such communities and third parties that govern
-the use of those portions, and any licenses granted hereunder do not
-alter any rights and obligations you may have under such open source
-licenses, however, the disclaimer of warranty and limitation of
-liability provisions in this Agreement will apply to all Software in
-this distribution.
-
-5. Term and Termination.
-
-The Agreement is effective on the Date you recieve the Software and
-remains effective until terminated. Your rights under this Agreement
-will terminate immediately without notice from Sun if you materially
-breach it or take any action in derogation of Sun's and/or its
-licensors' rights to Software. Sun may terminate this Agreement should
-any Software become, or in Sun's reasonable opinion likely to become,
-the subject of a claim of intellectual property infringement or trade
-secret misappropriation. Upon termination, you will cease use of, and
-destroy, Software and confirm compliance in writing to Sun. Sections 1,
-3, 4, 5, and 7-13 will survive termination of the Agreement.
-
-6. Limited Warranty.
-
-Sun warrants to you that for a period of 90 days from the date of
-receipt, the media on which Software is furnished (if any) will be free
-of defects in materials and workmanship under normal use. Except for
-the foregoing, Software is provided "AS IS". Your exclusive remedy and
-Sun's entire liability under this limited warranty will be at Sun's
-option to replace Software media or refund the fee paid for Software.
-Some states do not allow limitations on certain implied warranties, so
-the above may not apply to you. This limited warranty gives you
-specific legal rights. You may have others, which vary from state to
-state.
-
-7. Disclaimer of Warranty.
-
-UNLESS SPECIFIED IN THIS AGREEMENT, ALL EXPRESS OR IMPLIED CONDITIONS,
-REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT
-ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT THESE DISCLAIMERS ARE HELD TO
-BE LEGALLY INVALID.
-
-8. Limitation of Liability.
-
-TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL SUN OR ITS
-LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR SPECIAL,
-INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED
-REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF OR RELATED TO THE
-USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES. In no event will Sun's liability to you,
-whether in contract, tort (including negligence), or otherwise, exceed
-the amount paid by you for Software under this Agreement. The foregoing
-limitations will apply even if the above stated warranty fails of its
-essential purpose. Some states do not allow the exclusion of incidental
-or consequential damages, so some of the terms above may not be
-applicable to you.
-
-9. Export Regulations.
-
-All Software, documents, technical data, and any other materials
-delivered under this Agreement are subject to U.S. export control laws
-and may be subject to export or import regulations in other countries.
-You agree to comply strictly with these laws and regulations and
-acknowledge that you have the responsibility to obtain any licenses to
-export, re-export, or import as may be required after delivery to you.
-
-10. U.S. Government Restricted Rights.
-
-If Software is being acquired by or on behalf of the U.S. Government or
-by a U.S. Government prime contractor or subcontractor (at any tier),
-then the Government's rights in Software and accompanying documentation
-will be only as set forth in this Agreement; this is in accordance with
-48 CFR 227.7201 through 227.7202-4 (for Department of Defense (DOD)
-acquisitions) and with 48 CFR 2.101 and 12.212 (for non-DOD acquisitions).
-
-11. Governing Law.
-
-Any action related to this Agreement will be governed by California law
-and controlling U.S. federal law. No choice of law rules of any
-jurisdiction will apply.
-
-12. Severability.
-
-If any provision of this Agreement is held to be unenforceable, this
-Agreement will remain in effect with the provision omitted, unless
-omission would frustrate the intent of the parties, in which case this
-Agreement will immediately terminate.
-
-13. Integration.
-
-This Agreement is the entire agreement between you and Sun relating to
-its subject matter. It supersedes all prior or contemporaneous oral or
-written communications, proposals, representations and warranties and
-prevails over any conflicting or additional terms of any quote, order,
-acknowledgment, or other communication between the parties relating to
-its subject matter during the term of this Agreement. No modification
-of this Agreement will be binding, unless in writing and signed by an
-authorized representative of each party.
diff --git a/usr/src/tools/opensolaris/README.binaries.tmpl b/usr/src/tools/opensolaris/README.binaries.tmpl
deleted file mode 100644
index 6aa95135be..0000000000
--- a/usr/src/tools/opensolaris/README.binaries.tmpl
+++ /dev/null
@@ -1,27 +0,0 @@
-@ISA@ @DELIVERY@ Distribution README
-#ident "%Z%%M% %I% %E% SMI"
-
-1. Subject to the terms and conditions of the Software License Agreement
- and the obligations, restrictions, and exceptions set forth below, You
- may reproduce and distribute the Software (and also portions of Software
- identified below as Redistributable), provided that:
-
- (i) You distribute the Software or Redistributables bundled as part of,
- and for the sole purpose of running, a version of OpenSolaris;
-
- (ii) You do not remove or alter any proprietary legends or notices contained
- in or on the Software or Redistributables,
-
-(iii) You only distribute the Software or Redistributables subject to a license
- agreement that protects Sun's interests consistent with the terms
- contained in this Agreement, and
-
- (iv) You agree to defend and indemnify Sun and its licensors from and
- against any damages, costs, liabilities, settlement amounts and/or
- expenses (including attorneys' fees) incurred in connection with
- any claim, lawsuit or action by any third party that arises or
- results from the use or distribution of any and all Programs,
- Software, or Redistributables.
-
-Redistributables:
-
diff --git a/usr/src/tools/opensolaris/README.opensolaris.tmpl b/usr/src/tools/opensolaris/README.opensolaris.tmpl
deleted file mode 100644
index 95c9b98f46..0000000000
--- a/usr/src/tools/opensolaris/README.opensolaris.tmpl
+++ /dev/null
@@ -1,82 +0,0 @@
- OS/Net (ON) binaries for Buildable Source
-
-This delivery of the binaries to enable the Buildable Source consists of 2
-pieces:
-
-1. encumbered binaries tarball (on-closed-bins-DATE.PLATFORM.tar.bz2)
-2. signed cryptographic binaries (on-crypto-DATE.PLATFORM.tar.bz2)
-
-BFU archives are no longer supported.
-
-If you want to build the entire source tree, you will need the source,
-the encumbered binaries, and the cryptographic binaries. The tools may
-be bootstrapped from your source tree.
-
-The encumbered binaries tarball contains complete binaries (libraries,
-kernel modules, commands) that are compatible with the source. These
-are binaries that cannot be built using only the source tarball for
-one reason or another.
-
-The cryptographic binaries have been signed with a certificate and key
-that enables their use. The cryptographic binaries that you build
-from source will not be usable unless you have obtained your own
-certificate and key. See elfsign(1) for more information related to
-signing binaries.
-
-To obtain source, ensure that you have Mercurial installed (if you do
-not, utter 'pkg install developer/versioning/mercurial'), and then
-checkout from the Mercurial repository; please see instructions at:
-http://hub.opensolaris.org/bin/view/Project+onnv/
-
-
-Build Environment
------------------
-
-To build from source, you will also need the proper compiler, and you
-must be running a recent build. The build schedule is available at
-http://hub.opensolaris.org/bin/view/Community+Group+on/schedule.
-
-The standard compiler for building OpenSolaris code is Sun Studio,
-which is free to download and use. You can also use gcc. See the
-section "Installing from Source" (below) for details.
-
-Build machines are expected to be running an OpenSolaris build that
-is no more than 2 builds behind the source that you're building. For
-example, if you're building snv_143, your build machine should be
-running snv_141 or later.
-
-
-Other Important Information
----------------------------
-
-The buildable source contains the source for our high key-strength
-crypto, known as the Encryption Kit (SUNWcry, SUNWcryr, SUNWcryptoint).
-Please note that certain countries restrict the redistribution of
-high key-strength crypto. If you live in one of these countries,
-it is your responsibility to ensure that you are complying with your
-country's laws in this area.
-
-For general questions on the buildable source, please ask on the
-OpenSolaris Help discussion list (opensolaris-help <at> opensolaris
-<dot> org). For detailed comments about the code, please use the
-on-discuss list. Please note that the mailing lists are configured to
-only allow posts from list subscribers. The Help list also has a web
-forum that is gatewayed with the mailing list. More information about
-OpenSolaris lists is available at
-http://hub.opensolaris.org/bin/view/Main/discussions.
-
-
-Currently Known Issues
-----------------------
- These were some of the major known issues at the time of this
-delivery. The most recent list is available on the OpenSolaris.org
-website in the ON community at:
-http://hub.opensolaris.org/bin/view/Community+Group+on/known_issues
-
-<!-- #include http://hub.opensolaris.org/bin/view/Community+Group+on/known_issues -->
-
-
-Installing from Source
-----------------------
-
-<!-- #include http://hub.opensolaris.org/bin/view/Community+Group+on/install_quickstart -->
diff --git a/usr/src/tools/scripts/checkpaths.sh b/usr/src/tools/scripts/checkpaths.sh
index e4a9b21b61..5b33188df6 100644
--- a/usr/src/tools/scripts/checkpaths.sh
+++ b/usr/src/tools/scripts/checkpaths.sh
@@ -90,11 +90,6 @@ if [ -r $SRC/tools/findunref/exception_list ]; then
validate_paths -k ISUSED -r -e '^\*' $SRC/tools/findunref/exception_list
fi
-if [ -f $SRC/tools/opensolaris/license-list ]; then
- sed -e 's/$/.descrip/' < $SRC/tools/opensolaris/license-list | \
- validate_paths -n SRC/tools/opensolaris/license-list
-fi
-
validate_flg -f
exit 0
diff --git a/usr/src/uts/common/fs/proc/prvnops.c b/usr/src/uts/common/fs/proc/prvnops.c
index d096168b48..993b42530a 100644
--- a/usr/src/uts/common/fs/proc/prvnops.c
+++ b/usr/src/uts/common/fs/proc/prvnops.c
@@ -954,8 +954,7 @@ pr_read_fdinfo(prnode_t *pnp, uio_t *uiop, cred_t *cr)
fdinfo = pr_iol_newbuf(&data, offsetof(prfdinfo_t, pr_misc));
fdinfo->pr_fd = fd;
fdinfo->pr_fdflags = ufp_flag;
- /* FEPOLLED on f_flag2 should never be user-visible */
- fdinfo->pr_fileflags = (fp->f_flag2 & ~FEPOLLED) << 16 | fp->f_flag;
+ fdinfo->pr_fileflags = fp->f_flag2 << 16 | fp->f_flag;
if ((fdinfo->pr_fileflags & (FSEARCH | FEXEC)) == 0)
fdinfo->pr_fileflags += FOPEN;
fdinfo->pr_offset = fp->f_offset;
diff --git a/usr/src/uts/common/fs/zfs/zfs_ioctl.c b/usr/src/uts/common/fs/zfs/zfs_ioctl.c
index 153dcf1502..18ad081465 100644
--- a/usr/src/uts/common/fs/zfs/zfs_ioctl.c
+++ b/usr/src/uts/common/fs/zfs/zfs_ioctl.c
@@ -63,8 +63,9 @@
*
* zfs_ioc_t ioc
* The ioctl request number, which userland will pass to ioctl(2).
- * The ioctl numbers can change from release to release, because
- * the caller (libzfs) must be matched to the kernel.
+ * We want newer versions of libzfs and libzfs_core to run against
+ * existing zfs kernel modules (i.e. a deferred reboot after an update).
+ * Therefore the ioctl numbers cannot change from release to release.
*
* zfs_secpolicy_func_t *secpolicy
* This function will be called before the zfs_ioc_func_t, to
@@ -90,6 +91,10 @@
* Multiple checks can be or-ed together (e.g. POOL_CHECK_SUSPENDED |
* POOL_CHECK_READONLY).
*
+ * zfs_ioc_key_t *nvl_keys
+ * The list of expected/allowable innvl input keys. This list is used
+ * to validate the nvlist input to the ioctl.
+ *
* boolean_t smush_outnvlist
* If smush_outnvlist is true, then the output is presumed to be a
* list of errors, and it will be "smushed" down to fit into the
@@ -138,6 +143,14 @@
* use the outnvl if they succeed, because the caller can not
* distinguish between the operation failing, and
* deserialization failing.
+ *
+ * IOCTL Interface Errors
+ *
+ * The following ioctl input errors can be returned:
+ * ZFS_ERR_IOC_CMD_UNAVAIL the ioctl number is not supported by kernel
+ * ZFS_ERR_IOC_ARG_UNAVAIL an input argument is not supported by kernel
+ * ZFS_ERR_IOC_ARG_REQUIRED a required input argument is missing
+ * ZFS_ERR_IOC_ARG_BADTYPE an input argument has an invalid type
*/
#include <sys/types.h>
@@ -223,6 +236,37 @@ typedef int zfs_ioc_legacy_func_t(zfs_cmd_t *);
typedef int zfs_ioc_func_t(const char *, nvlist_t *, nvlist_t *);
typedef int zfs_secpolicy_func_t(zfs_cmd_t *, nvlist_t *, cred_t *);
+/*
+ * IOC Keys are used to document and validate user->kernel interface inputs.
+ * See zfs_keys_recv_new for an example declaration. Any key name that is not
+ * listed will be rejected as input.
+ *
+ * The keyname 'optional' is always allowed, and must be an nvlist if present.
+ * Arguments which older kernels can safely ignore can be placed under the
+ * "optional" key.
+ *
+ * When adding new keys to an existing ioc for new functionality, consider:
+ * - adding an entry into zfs_sysfs.c zfs_features[] list
+ * - updating the libzfs_input_check.c test utility
+ *
+ * Note: in the ZK_WILDCARDLIST case, the name serves as documentation
+ * for the expected name (bookmark, snapshot, property, etc) but there
+ * is no validation in the preflight zfs_check_input_nvpairs() check.
+ */
+typedef enum {
+ ZK_OPTIONAL = 1 << 0, /* pair is optional */
+ ZK_WILDCARDLIST = 1 << 1, /* one or more unspecified key names */
+} ioc_key_flag_t;
+
+/* DATA_TYPE_ANY is used when zkey_type can vary. */
+#define DATA_TYPE_ANY DATA_TYPE_UNKNOWN
+
+typedef struct zfs_ioc_key {
+ const char *zkey_name;
+ data_type_t zkey_type;
+ ioc_key_flag_t zkey_flags;
+} zfs_ioc_key_t;
+
typedef enum {
NO_NAME,
POOL_NAME,
@@ -244,6 +288,8 @@ typedef struct zfs_ioc_vec {
zfs_ioc_poolcheck_t zvec_pool_check;
boolean_t zvec_smush_outnvlist;
const char *zvec_name;
+ const zfs_ioc_key_t *zvec_nvl_keys;
+ size_t zvec_nvl_key_count;
} zfs_ioc_vec_t;
/* This array is indexed by zfs_userquota_prop_t */
@@ -861,8 +907,8 @@ zfs_secpolicy_destroy_snaps(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
nvpair_t *pair, *nextpair;
int error = 0;
- if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
- return (SET_ERROR(EINVAL));
+ snaps = fnvlist_lookup_nvlist(innvl, "snaps");
+
for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
pair = nextpair) {
nextpair = nvlist_next_nvpair(snaps, pair);
@@ -1009,8 +1055,8 @@ zfs_secpolicy_snapshot(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
int error = 0;
nvpair_t *pair;
- if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
- return (SET_ERROR(EINVAL));
+ snaps = fnvlist_lookup_nvlist(innvl, "snaps");
+
for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
pair = nvlist_next_nvpair(snaps, pair)) {
char *name = nvpair_name(pair);
@@ -1030,7 +1076,7 @@ zfs_secpolicy_snapshot(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
}
/*
- * Check for permission to create each snapshot in the nvlist.
+ * Check for permission to create each bookmark in the nvlist.
*/
/* ARGSUSED */
static int
@@ -1265,9 +1311,7 @@ zfs_secpolicy_hold(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
nvlist_t *holds;
int error;
- error = nvlist_lookup_nvlist(innvl, "holds", &holds);
- if (error != 0)
- return (SET_ERROR(EINVAL));
+ holds = fnvlist_lookup_nvlist(innvl, "holds");
for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
pair = nvlist_next_nvpair(holds, pair)) {
@@ -1338,12 +1382,15 @@ zfs_secpolicy_tmp_snapshot(zfs_cmd_t *zc, nvlist_t *innvl, cred_t *cr)
return (0);
error = zfs_secpolicy_snapshot_perms(zc->zc_name, cr);
- if (error == 0)
- error = zfs_secpolicy_hold(zc, innvl, cr);
- if (error == 0)
- error = zfs_secpolicy_release(zc, innvl, cr);
- if (error == 0)
- error = zfs_secpolicy_destroy(zc, innvl, cr);
+
+ if (innvl != NULL) {
+ if (error == 0)
+ error = zfs_secpolicy_hold(zc, innvl, cr);
+ if (error == 0)
+ error = zfs_secpolicy_release(zc, innvl, cr);
+ if (error == 0)
+ error = zfs_secpolicy_destroy(zc, innvl, cr);
+ }
return (error);
}
@@ -3300,6 +3347,13 @@ zfs_fill_zplprops_root(uint64_t spa_vers, nvlist_t *createprops,
*
* outnvl: propname -> error code (int32)
*/
+
+static const zfs_ioc_key_t zfs_keys_create[] = {
+ {"type", DATA_TYPE_INT32, 0},
+ {"props", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+ {"hidden_args", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+};
+
static int
zfs_ioc_create(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
{
@@ -3308,14 +3362,11 @@ zfs_ioc_create(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
nvlist_t *nvprops = NULL;
nvlist_t *hidden_args = NULL;
void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
- int32_t type32;
dmu_objset_type_t type;
boolean_t is_insensitive = B_FALSE;
dsl_crypto_params_t *dcp = NULL;
- if (nvlist_lookup_int32(innvl, "type", &type32) != 0)
- return (SET_ERROR(EINVAL));
- type = type32;
+ type = (dmu_objset_type_t)fnvlist_lookup_int32(innvl, "type");
(void) nvlist_lookup_nvlist(innvl, "props", &nvprops);
(void) nvlist_lookup_nvlist(innvl, ZPOOL_HIDDEN_ARGS, &hidden_args);
@@ -3418,6 +3469,12 @@ zfs_ioc_create(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
*
* outnvl: propname -> error code (int32)
*/
+static const zfs_ioc_key_t zfs_keys_clone[] = {
+ {"origin", DATA_TYPE_STRING, 0},
+ {"props", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+ {"hidden_args", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+};
+
static int
zfs_ioc_clone(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
{
@@ -3450,6 +3507,10 @@ zfs_ioc_clone(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
return (error);
}
+static const zfs_ioc_key_t zfs_keys_remap[] = {
+ /* no nvl keys */
+};
+
/* ARGSUSED */
static int
zfs_ioc_remap(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
@@ -3469,6 +3530,11 @@ zfs_ioc_remap(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
*
* outnvl: snapshot -> error code (int32)
*/
+static const zfs_ioc_key_t zfs_keys_snapshot[] = {
+ {"snaps", DATA_TYPE_NVLIST, 0},
+ {"props", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+};
+
static int
zfs_ioc_snapshot(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
{
@@ -3485,8 +3551,7 @@ zfs_ioc_snapshot(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
zfs_earlier_version(poolname, SPA_VERSION_SNAP_PROPS))
return (SET_ERROR(ENOTSUP));
- if (nvlist_lookup_nvlist(innvl, "snaps", &snaps) != 0)
- return (SET_ERROR(EINVAL));
+ snaps = fnvlist_lookup_nvlist(innvl, "snaps");
poollen = strlen(poolname);
for (pair = nvlist_next_nvpair(snaps, NULL); pair != NULL;
pair = nvlist_next_nvpair(snaps, pair)) {
@@ -3525,6 +3590,10 @@ zfs_ioc_snapshot(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
/*
* innvl: "message" -> string
*/
+static const zfs_ioc_key_t zfs_keys_log_history[] = {
+ {"message", DATA_TYPE_STRING, 0},
+};
+
/* ARGSUSED */
static int
zfs_ioc_log_history(const char *unused, nvlist_t *innvl, nvlist_t *outnvl)
@@ -3548,10 +3617,7 @@ zfs_ioc_log_history(const char *unused, nvlist_t *innvl, nvlist_t *outnvl)
if (error != 0)
return (error);
- if (nvlist_lookup_string(innvl, "message", &message) != 0) {
- spa_close(spa, FTAG);
- return (SET_ERROR(EINVAL));
- }
+ message = fnvlist_lookup_string(innvl, "message");
if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
spa_close(spa, FTAG);
@@ -3645,6 +3711,11 @@ zfs_destroy_unmount_origin(const char *fsname)
* outnvl: snapshot -> error code (int32)
*
*/
+static const zfs_ioc_key_t zfs_keys_destroy_snaps[] = {
+ {"snaps", DATA_TYPE_NVLIST, 0},
+ {"defer", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+};
+
/* ARGSUSED */
static int
zfs_ioc_destroy_snaps(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
@@ -3676,6 +3747,10 @@ zfs_ioc_destroy_snaps(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
* outnvl: bookmark -> error code (int32)
*
*/
+static const zfs_ioc_key_t zfs_keys_bookmark[] = {
+ {"<bookmark>...", DATA_TYPE_STRING, ZK_WILDCARDLIST},
+};
+
/* ARGSUSED */
static int
zfs_ioc_bookmark(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
@@ -3713,6 +3788,10 @@ zfs_ioc_bookmark(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
* }
*
*/
+static const zfs_ioc_key_t zfs_keys_get_bookmarks[] = {
+ {"<property>...", DATA_TYPE_BOOLEAN, ZK_WILDCARDLIST | ZK_OPTIONAL},
+};
+
static int
zfs_ioc_get_bookmarks(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
{
@@ -3727,6 +3806,10 @@ zfs_ioc_get_bookmarks(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
* outnvl: bookmark -> error code (int32)
*
*/
+static const zfs_ioc_key_t zfs_keys_destroy_bookmarks[] = {
+ {"<bookmark>...", DATA_TYPE_BOOLEAN, ZK_WILDCARDLIST},
+};
+
static int
zfs_ioc_destroy_bookmarks(const char *poolname, nvlist_t *innvl,
nvlist_t *outnvl)
@@ -3759,6 +3842,14 @@ zfs_ioc_destroy_bookmarks(const char *poolname, nvlist_t *innvl,
return (error);
}
+static const zfs_ioc_key_t zfs_keys_channel_program[] = {
+ {"program", DATA_TYPE_STRING, 0},
+ {"arg", DATA_TYPE_ANY, 0},
+ {"sync", DATA_TYPE_BOOLEAN_VALUE, ZK_OPTIONAL},
+ {"instrlimit", DATA_TYPE_UINT64, ZK_OPTIONAL},
+ {"memlimit", DATA_TYPE_UINT64, ZK_OPTIONAL},
+};
+
static int
zfs_ioc_channel_program(const char *poolname, nvlist_t *innvl,
nvlist_t *outnvl)
@@ -3769,9 +3860,7 @@ zfs_ioc_channel_program(const char *poolname, nvlist_t *innvl,
nvpair_t *nvarg = NULL;
nvlist_t *hidden_args = NULL;
- if (0 != nvlist_lookup_string(innvl, ZCP_ARG_PROGRAM, &program)) {
- return (EINVAL);
- }
+ program = fnvlist_lookup_string(innvl, ZCP_ARG_PROGRAM);
if (0 != nvlist_lookup_boolean_value(innvl, ZCP_ARG_SYNC, &sync_flag)) {
sync_flag = B_TRUE;
}
@@ -3781,9 +3870,7 @@ zfs_ioc_channel_program(const char *poolname, nvlist_t *innvl,
if (0 != nvlist_lookup_uint64(innvl, ZCP_ARG_MEMLIMIT, &memlimit)) {
memlimit = ZCP_DEFAULT_MEMLIMIT;
}
- if (0 != nvlist_lookup_nvpair(innvl, ZCP_ARG_ARGLIST, &nvarg)) {
- return (EINVAL);
- }
+ nvarg = fnvlist_lookup_nvpair(innvl, ZCP_ARG_ARGLIST);
/* hidden args are optional */
if (nvlist_lookup_nvlist(innvl, ZPOOL_HIDDEN_ARGS, &hidden_args) == 0) {
@@ -3808,6 +3895,10 @@ zfs_ioc_channel_program(const char *poolname, nvlist_t *innvl,
* innvl: unused
* outnvl: empty
*/
+static const zfs_ioc_key_t zfs_keys_pool_checkpoint[] = {
+ /* no nvl keys */
+};
+
/* ARGSUSED */
static int
zfs_ioc_pool_checkpoint(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
@@ -3819,6 +3910,10 @@ zfs_ioc_pool_checkpoint(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
* innvl: unused
* outnvl: empty
*/
+static const zfs_ioc_key_t zfs_keys_pool_discard_checkpoint[] = {
+ /* no nvl keys */
+};
+
/* ARGSUSED */
static int
zfs_ioc_pool_discard_checkpoint(const char *poolname, nvlist_t *innvl,
@@ -3909,6 +4004,11 @@ zfs_ioc_destroy(zfs_cmd_t *zc)
* EINVAL is returned for an unknown command or if any of the provided vdev
* guids have be specified with a type other than uint64.
*/
+static const zfs_ioc_key_t zfs_keys_pool_initialize[] = {
+ {ZPOOL_INITIALIZE_COMMAND, DATA_TYPE_UINT64, 0},
+ {ZPOOL_INITIALIZE_VDEVS, DATA_TYPE_NVLIST, 0}
+};
+
static int
zfs_ioc_pool_initialize(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
{
@@ -3980,6 +4080,12 @@ zfs_ioc_pool_initialize(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
* EINVAL is returned for an unknown command or if any of the provided vdev
* guids have be specified with a type other than uint64.
*/
+static const zfs_ioc_key_t zfs_keys_pool_trim[] = {
+ {ZPOOL_TRIM_COMMAND, DATA_TYPE_UINT64, 0},
+ {ZPOOL_TRIM_VDEVS, DATA_TYPE_NVLIST, 0},
+ {ZPOOL_TRIM_RATE, DATA_TYPE_UINT64, ZK_OPTIONAL},
+ {ZPOOL_TRIM_SECURE, DATA_TYPE_BOOLEAN_VALUE, ZK_OPTIONAL},
+};
static int
zfs_ioc_pool_trim(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
@@ -4044,6 +4150,10 @@ zfs_ioc_pool_trim(const char *poolname, nvlist_t *innvl, nvlist_t *outnvl)
* outnvl: "target" -> name of most recent snapshot
* }
*/
+static const zfs_ioc_key_t zfs_keys_rollback[] = {
+ {"target", DATA_TYPE_STRING, ZK_OPTIONAL},
+};
+
/* ARGSUSED */
static int
zfs_ioc_rollback(const char *fsname, nvlist_t *innvl, nvlist_t *outnvl)
@@ -5952,6 +6062,11 @@ zfs_ioc_smb_acl(zfs_cmd_t *zc)
* ...
* }
*/
+static const zfs_ioc_key_t zfs_keys_hold[] = {
+ {"holds", DATA_TYPE_NVLIST, 0},
+ {"cleanup_fd", DATA_TYPE_INT32, ZK_OPTIONAL},
+};
+
/* ARGSUSED */
static int
zfs_ioc_hold(const char *pool, nvlist_t *args, nvlist_t *errlist)
@@ -5962,9 +6077,7 @@ zfs_ioc_hold(const char *pool, nvlist_t *args, nvlist_t *errlist)
int error;
minor_t minor = 0;
- error = nvlist_lookup_nvlist(args, "holds", &holds);
- if (error != 0)
- return (SET_ERROR(EINVAL));
+ holds = fnvlist_lookup_nvlist(args, "holds");
/* make sure the user didn't pass us any invalid (empty) tags */
for (pair = nvlist_next_nvpair(holds, NULL); pair != NULL;
@@ -5999,11 +6112,14 @@ zfs_ioc_hold(const char *pool, nvlist_t *args, nvlist_t *errlist)
* ...
* }
*/
+static const zfs_ioc_key_t zfs_keys_get_holds[] = {
+ /* no nvl keys */
+};
+
/* ARGSUSED */
static int
zfs_ioc_get_holds(const char *snapname, nvlist_t *args, nvlist_t *outnvl)
{
- ASSERT3P(args, ==, NULL);
return (dsl_dataset_get_holds(snapname, outnvl));
}
@@ -6018,6 +6134,10 @@ zfs_ioc_get_holds(const char *snapname, nvlist_t *args, nvlist_t *outnvl)
* ...
* }
*/
+static const zfs_ioc_key_t zfs_keys_release[] = {
+ {"<snapname>...", DATA_TYPE_NVLIST, ZK_WILDCARDLIST},
+};
+
/* ARGSUSED */
static int
zfs_ioc_release(const char *pool, nvlist_t *holds, nvlist_t *errlist)
@@ -6076,6 +6196,10 @@ zfs_ioc_space_written(zfs_cmd_t *zc)
* "uncompressed" -> uncompressed space in bytes
* }
*/
+static const zfs_ioc_key_t zfs_keys_space_snaps[] = {
+ {"firstsnap", DATA_TYPE_STRING, 0},
+};
+
static int
zfs_ioc_space_snaps(const char *lastsnap, nvlist_t *innvl, nvlist_t *outnvl)
{
@@ -6085,8 +6209,7 @@ zfs_ioc_space_snaps(const char *lastsnap, nvlist_t *innvl, nvlist_t *outnvl)
char *firstsnap;
uint64_t used, comp, uncomp;
- if (nvlist_lookup_string(innvl, "firstsnap", &firstsnap) != 0)
- return (SET_ERROR(EINVAL));
+ firstsnap = fnvlist_lookup_string(innvl, "firstsnap");
error = dsl_pool_hold(lastsnap, FTAG, &dp);
if (error != 0)
@@ -6140,6 +6263,17 @@ zfs_ioc_space_snaps(const char *lastsnap, nvlist_t *innvl, nvlist_t *outnvl)
*
* outnvl is unused
*/
+static const zfs_ioc_key_t zfs_keys_send_new[] = {
+ {"fd", DATA_TYPE_INT32, 0},
+ {"fromsnap", DATA_TYPE_STRING, ZK_OPTIONAL},
+ {"largeblockok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"embedok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"compressok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"rawok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"resume_object", DATA_TYPE_UINT64, ZK_OPTIONAL},
+ {"resume_offset", DATA_TYPE_UINT64, ZK_OPTIONAL},
+};
+
/* ARGSUSED */
static int
zfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
@@ -6155,9 +6289,7 @@ zfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
uint64_t resumeobj = 0;
uint64_t resumeoff = 0;
- error = nvlist_lookup_int32(innvl, "fd", &fd);
- if (error != 0)
- return (SET_ERROR(EINVAL));
+ fd = fnvlist_lookup_int32(innvl, "fd");
(void) nvlist_lookup_string(innvl, "fromsnap", &fromname);
@@ -6202,6 +6334,15 @@ zfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
* "space" -> bytes of space (uint64)
* }
*/
+static const zfs_ioc_key_t zfs_keys_send_space[] = {
+ {"from", DATA_TYPE_STRING, ZK_OPTIONAL},
+ {"fromsnap", DATA_TYPE_STRING, ZK_OPTIONAL},
+ {"largeblockok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"embedok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"compressok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+ {"rawok", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+};
+
static int
zfs_ioc_send_space(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl)
{
@@ -6294,18 +6435,24 @@ out:
*
* onvl is unused
*/
+static const zfs_ioc_key_t zfs_keys_pool_sync[] = {
+ {"force", DATA_TYPE_BOOLEAN_VALUE, 0},
+};
+
/* ARGSUSED */
static int
zfs_ioc_pool_sync(const char *pool, nvlist_t *innvl, nvlist_t *onvl)
{
int err;
- boolean_t force;
+ boolean_t force = B_FALSE;
spa_t *spa;
if ((err = spa_open(pool, &spa, FTAG)) != 0)
return (err);
- force = fnvlist_lookup_boolean_value(innvl, "force");
+ if (innvl)
+ force = fnvlist_lookup_boolean_value(innvl, "force");
+
if (force) {
spa_config_enter(spa, SCL_CONFIG, FTAG, RW_WRITER);
vdev_config_dirty(spa->spa_root_vdev);
@@ -6327,6 +6474,11 @@ zfs_ioc_pool_sync(const char *pool, nvlist_t *innvl, nvlist_t *onvl)
* presence indicated key should only be verified, not loaded
* }
*/
+static const zfs_ioc_key_t zfs_keys_load_key[] = {
+ {"hidden_args", DATA_TYPE_NVLIST, 0},
+ {"noop", DATA_TYPE_BOOLEAN, ZK_OPTIONAL},
+};
+
/* ARGSUSED */
static int
zfs_ioc_load_key(const char *dsname, nvlist_t *innvl, nvlist_t *outnvl)
@@ -6341,11 +6493,7 @@ zfs_ioc_load_key(const char *dsname, nvlist_t *innvl, nvlist_t *outnvl)
goto error;
}
- ret = nvlist_lookup_nvlist(innvl, ZPOOL_HIDDEN_ARGS, &hidden_args);
- if (ret != 0) {
- ret = SET_ERROR(EINVAL);
- goto error;
- }
+ hidden_args = fnvlist_lookup_nvlist(innvl, ZPOOL_HIDDEN_ARGS);
ret = dsl_crypto_params_create_nvlist(DCP_CMD_NONE, NULL,
hidden_args, &dcp);
@@ -6369,6 +6517,10 @@ error:
* Unload a user's wrapping key from the kernel.
* Both innvl and outnvl are unused.
*/
+static const zfs_ioc_key_t zfs_keys_unload_key[] = {
+ /* no nvl keys */
+};
+
/* ARGSUSED */
static int
zfs_ioc_unload_key(const char *dsname, nvlist_t *innvl, nvlist_t *outnvl)
@@ -6401,6 +6553,12 @@ out:
*
* outnvl is unused
*/
+static const zfs_ioc_key_t zfs_keys_change_key[] = {
+ {"crypt_cmd", DATA_TYPE_UINT64, ZK_OPTIONAL},
+ {"hidden_args", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+ {"props", DATA_TYPE_NVLIST, ZK_OPTIONAL},
+};
+
/* ARGSUSED */
static int
zfs_ioc_change_key(const char *dsname, nvlist_t *innvl, nvlist_t *outnvl)
@@ -6467,7 +6625,7 @@ static void
zfs_ioctl_register(const char *name, zfs_ioc_t ioc, zfs_ioc_func_t *func,
zfs_secpolicy_func_t *secpolicy, zfs_ioc_namecheck_t namecheck,
zfs_ioc_poolcheck_t pool_check, boolean_t smush_outnvlist,
- boolean_t allow_log)
+ boolean_t allow_log, const zfs_ioc_key_t *nvl_keys, size_t num_keys)
{
zfs_ioc_vec_t *vec = &zfs_ioc_vec[ioc - ZFS_IOC_FIRST];
@@ -6486,6 +6644,8 @@ zfs_ioctl_register(const char *name, zfs_ioc_t ioc, zfs_ioc_func_t *func,
vec->zvec_pool_check = pool_check;
vec->zvec_smush_outnvlist = smush_outnvlist;
vec->zvec_allow_log = allow_log;
+ vec->zvec_nvl_keys = nvl_keys;
+ vec->zvec_nvl_key_count = num_keys;
}
static void
@@ -6549,104 +6709,131 @@ zfs_ioctl_init(void)
{
zfs_ioctl_register("snapshot", ZFS_IOC_SNAPSHOT,
zfs_ioc_snapshot, zfs_secpolicy_snapshot, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_snapshot, ARRAY_SIZE(zfs_keys_snapshot));
zfs_ioctl_register("log_history", ZFS_IOC_LOG_HISTORY,
zfs_ioc_log_history, zfs_secpolicy_log_history, NO_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_FALSE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_FALSE,
+ zfs_keys_log_history, ARRAY_SIZE(zfs_keys_log_history));
zfs_ioctl_register("space_snaps", ZFS_IOC_SPACE_SNAPS,
zfs_ioc_space_snaps, zfs_secpolicy_read, DATASET_NAME,
- POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
+ POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE,
+ zfs_keys_space_snaps, ARRAY_SIZE(zfs_keys_space_snaps));
zfs_ioctl_register("send", ZFS_IOC_SEND_NEW,
zfs_ioc_send_new, zfs_secpolicy_send_new, DATASET_NAME,
- POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
+ POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE,
+ zfs_keys_send_new, ARRAY_SIZE(zfs_keys_send_new));
zfs_ioctl_register("send_space", ZFS_IOC_SEND_SPACE,
zfs_ioc_send_space, zfs_secpolicy_read, DATASET_NAME,
- POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
+ POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE,
+ zfs_keys_send_space, ARRAY_SIZE(zfs_keys_send_space));
zfs_ioctl_register("create", ZFS_IOC_CREATE,
zfs_ioc_create, zfs_secpolicy_create_clone, DATASET_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_create, ARRAY_SIZE(zfs_keys_create));
zfs_ioctl_register("clone", ZFS_IOC_CLONE,
zfs_ioc_clone, zfs_secpolicy_create_clone, DATASET_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_clone, ARRAY_SIZE(zfs_keys_clone));
zfs_ioctl_register("remap", ZFS_IOC_REMAP,
zfs_ioc_remap, zfs_secpolicy_remap, DATASET_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_TRUE,
+ zfs_keys_remap, ARRAY_SIZE(zfs_keys_remap));
zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS,
zfs_ioc_destroy_snaps, zfs_secpolicy_destroy_snaps, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_destroy_snaps, ARRAY_SIZE(zfs_keys_destroy_snaps));
zfs_ioctl_register("hold", ZFS_IOC_HOLD,
zfs_ioc_hold, zfs_secpolicy_hold, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_hold, ARRAY_SIZE(zfs_keys_hold));
zfs_ioctl_register("release", ZFS_IOC_RELEASE,
zfs_ioc_release, zfs_secpolicy_release, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_release, ARRAY_SIZE(zfs_keys_release));
zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS,
zfs_ioc_get_holds, zfs_secpolicy_read, DATASET_NAME,
- POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
+ POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE,
+ zfs_keys_get_holds, ARRAY_SIZE(zfs_keys_get_holds));
zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK,
zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_TRUE,
+ zfs_keys_rollback, ARRAY_SIZE(zfs_keys_rollback));
zfs_ioctl_register("bookmark", ZFS_IOC_BOOKMARK,
zfs_ioc_bookmark, zfs_secpolicy_bookmark, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_bookmark, ARRAY_SIZE(zfs_keys_bookmark));
zfs_ioctl_register("get_bookmarks", ZFS_IOC_GET_BOOKMARKS,
zfs_ioc_get_bookmarks, zfs_secpolicy_read, DATASET_NAME,
- POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
+ POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE,
+ zfs_keys_get_bookmarks, ARRAY_SIZE(zfs_keys_get_bookmarks));
zfs_ioctl_register("destroy_bookmarks", ZFS_IOC_DESTROY_BOOKMARKS,
zfs_ioc_destroy_bookmarks, zfs_secpolicy_destroy_bookmarks,
POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_destroy_bookmarks,
+ ARRAY_SIZE(zfs_keys_destroy_bookmarks));
+
+ zfs_ioctl_register("load-key", ZFS_IOC_LOAD_KEY,
+ zfs_ioc_load_key, zfs_secpolicy_load_key,
+ DATASET_NAME, POOL_CHECK_SUSPENDED, B_TRUE, B_TRUE,
+ zfs_keys_load_key, ARRAY_SIZE(zfs_keys_load_key));
+ zfs_ioctl_register("unload-key", ZFS_IOC_UNLOAD_KEY,
+ zfs_ioc_unload_key, zfs_secpolicy_load_key,
+ DATASET_NAME, POOL_CHECK_SUSPENDED, B_TRUE, B_TRUE,
+ zfs_keys_unload_key, ARRAY_SIZE(zfs_keys_unload_key));
+ zfs_ioctl_register("change-key", ZFS_IOC_CHANGE_KEY,
+ zfs_ioc_change_key, zfs_secpolicy_change_key,
+ DATASET_NAME, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY,
+ B_TRUE, B_TRUE, zfs_keys_change_key,
+ ARRAY_SIZE(zfs_keys_change_key));
+
+ zfs_ioctl_register("sync", ZFS_IOC_POOL_SYNC,
+ zfs_ioc_pool_sync, zfs_secpolicy_none, POOL_NAME,
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_FALSE,
+ zfs_keys_pool_sync, ARRAY_SIZE(zfs_keys_pool_sync));
zfs_ioctl_register("channel_program", ZFS_IOC_CHANNEL_PROGRAM,
zfs_ioc_channel_program, zfs_secpolicy_config,
POOL_NAME, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE,
- B_TRUE);
+ B_TRUE, zfs_keys_channel_program,
+ ARRAY_SIZE(zfs_keys_channel_program));
zfs_ioctl_register("zpool_checkpoint", ZFS_IOC_POOL_CHECKPOINT,
zfs_ioc_pool_checkpoint, zfs_secpolicy_config, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_pool_checkpoint, ARRAY_SIZE(zfs_keys_pool_checkpoint));
zfs_ioctl_register("zpool_discard_checkpoint",
ZFS_IOC_POOL_DISCARD_CHECKPOINT, zfs_ioc_pool_discard_checkpoint,
zfs_secpolicy_config, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_pool_discard_checkpoint,
+ ARRAY_SIZE(zfs_keys_pool_discard_checkpoint));
zfs_ioctl_register("initialize", ZFS_IOC_POOL_INITIALIZE,
zfs_ioc_pool_initialize, zfs_secpolicy_config, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_pool_initialize, ARRAY_SIZE(zfs_keys_pool_initialize));
zfs_ioctl_register("trim", ZFS_IOC_POOL_TRIM,
zfs_ioc_pool_trim, zfs_secpolicy_config, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
-
- zfs_ioctl_register("sync", ZFS_IOC_POOL_SYNC,
- zfs_ioc_pool_sync, zfs_secpolicy_none, POOL_NAME,
- POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_FALSE);
-
- zfs_ioctl_register("load-key", ZFS_IOC_LOAD_KEY,
- zfs_ioc_load_key, zfs_secpolicy_load_key,
- DATASET_NAME, POOL_CHECK_SUSPENDED, B_TRUE, B_TRUE);
- zfs_ioctl_register("unload-key", ZFS_IOC_UNLOAD_KEY,
- zfs_ioc_unload_key, zfs_secpolicy_load_key,
- DATASET_NAME, POOL_CHECK_SUSPENDED, B_TRUE, B_TRUE);
- zfs_ioctl_register("change-key", ZFS_IOC_CHANGE_KEY,
- zfs_ioc_change_key, zfs_secpolicy_change_key,
- DATASET_NAME, POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY,
- B_TRUE, B_TRUE);
+ POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE,
+ zfs_keys_pool_trim, ARRAY_SIZE(zfs_keys_pool_trim));
/* IOCTLS that use the legacy function signature */
@@ -6783,6 +6970,80 @@ zfs_ioctl_init(void)
POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
}
+/*
+ * Verify that for non-legacy ioctls the input nvlist
+ * pairs match against the expected input.
+ *
+ * Possible errors are:
+ * ZFS_ERR_IOC_ARG_UNAVAIL An unrecognized nvpair was encountered
+ * ZFS_ERR_IOC_ARG_REQUIRED A required nvpair is missing
+ * ZFS_ERR_IOC_ARG_BADTYPE Invalid type for nvpair
+ */
+static int
+zfs_check_input_nvpairs(nvlist_t *innvl, const zfs_ioc_vec_t *vec)
+{
+ const zfs_ioc_key_t *nvl_keys = vec->zvec_nvl_keys;
+ boolean_t required_keys_found = B_FALSE;
+
+ /*
+ * examine each input pair
+ */
+ for (nvpair_t *pair = nvlist_next_nvpair(innvl, NULL);
+ pair != NULL; pair = nvlist_next_nvpair(innvl, pair)) {
+ char *name = nvpair_name(pair);
+ data_type_t type = nvpair_type(pair);
+ boolean_t identified = B_FALSE;
+
+ /*
+ * check pair against the documented names and type
+ */
+ for (int k = 0; k < vec->zvec_nvl_key_count; k++) {
+ /* if not a wild card name, check for an exact match */
+ if ((nvl_keys[k].zkey_flags & ZK_WILDCARDLIST) == 0 &&
+ strcmp(nvl_keys[k].zkey_name, name) != 0)
+ continue;
+
+ identified = B_TRUE;
+
+ if (nvl_keys[k].zkey_type != DATA_TYPE_ANY &&
+ nvl_keys[k].zkey_type != type) {
+ return (SET_ERROR(ZFS_ERR_IOC_ARG_BADTYPE));
+ }
+
+ if (nvl_keys[k].zkey_flags & ZK_OPTIONAL)
+ continue;
+
+ required_keys_found = B_TRUE;
+ break;
+ }
+
+ /* allow an 'optional' key, everything else is invalid */
+ if (!identified &&
+ (strcmp(name, "optional") != 0 ||
+ type != DATA_TYPE_NVLIST)) {
+ return (SET_ERROR(ZFS_ERR_IOC_ARG_UNAVAIL));
+ }
+ }
+
+ /* verify that all required keys were found */
+ for (int k = 0; k < vec->zvec_nvl_key_count; k++) {
+ if (nvl_keys[k].zkey_flags & ZK_OPTIONAL)
+ continue;
+
+ if (nvl_keys[k].zkey_flags & ZK_WILDCARDLIST) {
+ /* at least one non-optionial key is expected here */
+ if (!required_keys_found)
+ return (SET_ERROR(ZFS_ERR_IOC_ARG_REQUIRED));
+ continue;
+ }
+
+ if (!nvlist_exists(innvl, nvl_keys[k].zkey_name))
+ return (SET_ERROR(ZFS_ERR_IOC_ARG_REQUIRED));
+ }
+
+ return (0);
+}
+
int
pool_status_check(const char *name, zfs_ioc_namecheck_t type,
zfs_ioc_poolcheck_t check)
@@ -6933,9 +7194,16 @@ zfsdev_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp)
ASSERT3U(getmajor(dev), ==, ddi_driver_major(zfs_dip));
if (vecnum >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
- return (SET_ERROR(EINVAL));
+ return (SET_ERROR(ZFS_ERR_IOC_CMD_UNAVAIL));
vec = &zfs_ioc_vec[vecnum];
+ /*
+ * The registered ioctl list may be sparse, verify that either
+ * a normal or legacy handler are registered.
+ */
+ if (vec->zvec_func == NULL && vec->zvec_legacy_func == NULL)
+ return (SET_ERROR(ZFS_ERR_IOC_CMD_UNAVAIL));
+
zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
error = ddi_copyin((void *)arg, zc, sizeof (zfs_cmd_t), flag);
@@ -6978,6 +7246,19 @@ zfsdev_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp)
break;
}
+ /*
+ * Ensure that all input pairs are valid before we pass them down
+ * to the lower layers.
+ *
+ * The vectored functions can use fnvlist_lookup_{type} for any
+ * required pairs since zfs_check_input_nvpairs() confirmed that
+ * they exist and are of the correct type.
+ */
+ if (error == 0 && vec->zvec_func != NULL) {
+ error = zfs_check_input_nvpairs(innvl, vec);
+ if (error != 0)
+ goto out;
+ }
if (error == 0)
error = vec->zvec_secpolicy(zc, innvl, cr);
diff --git a/usr/src/uts/common/fs/zfs/zfs_onexit.c b/usr/src/uts/common/fs/zfs/zfs_onexit.c
index 4ae8dc29a0..99e530ca3c 100644
--- a/usr/src/uts/common/fs/zfs/zfs_onexit.c
+++ b/usr/src/uts/common/fs/zfs/zfs_onexit.c
@@ -125,13 +125,18 @@ zfs_onexit_fd_hold(int fd, minor_t *minorp)
{
file_t *fp;
zfs_onexit_t *zo;
+ int ret;
fp = getf(fd);
if (fp == NULL)
return (SET_ERROR(EBADF));
*minorp = getminor(fp->f_vnode->v_rdev);
- return (zfs_onexit_minor_to_state(*minorp, &zo));
+ ret = zfs_onexit_minor_to_state(*minorp, &zo);
+ if (ret != 0)
+ releasef(fd);
+
+ return (ret);
}
void
diff --git a/usr/src/uts/common/sys/file.h b/usr/src/uts/common/sys/file.h
index 816f6a7d33..f544033d2f 100644
--- a/usr/src/uts/common/sys/file.h
+++ b/usr/src/uts/common/sys/file.h
@@ -123,11 +123,6 @@ typedef struct fpollinfo {
#if defined(_KERNEL) || defined(_FAKE_KERNEL)
/*
- * This is a flag that is set on f_flag2, but is never user-visible
- */
-#define FEPOLLED 0x8000
-
-/*
* Fake flags for driver ioctl calls to inform them of the originating
* process' model. See <sys/model.h>
*
diff --git a/usr/src/uts/common/sys/fs/zfs.h b/usr/src/uts/common/sys/fs/zfs.h
index 93a2b5887a..f870d6ce7c 100644
--- a/usr/src/uts/common/sys/fs/zfs.h
+++ b/usr/src/uts/common/sys/fs/zfs.h
@@ -21,7 +21,7 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
+ * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2014 Integros [integros.com]
* Copyright 2020 Joyent, Inc.
@@ -1170,86 +1170,88 @@ typedef struct ddt_histogram {
typedef enum zfs_ioc {
ZFS_IOC_FIRST = ('Z' << 8),
ZFS_IOC = ZFS_IOC_FIRST,
- ZFS_IOC_POOL_CREATE = ZFS_IOC_FIRST,
- ZFS_IOC_POOL_DESTROY,
- ZFS_IOC_POOL_IMPORT,
- ZFS_IOC_POOL_EXPORT,
- ZFS_IOC_POOL_CONFIGS,
- ZFS_IOC_POOL_STATS,
- ZFS_IOC_POOL_TRYIMPORT,
- ZFS_IOC_POOL_SCAN,
- ZFS_IOC_POOL_FREEZE,
- ZFS_IOC_POOL_UPGRADE,
- ZFS_IOC_POOL_GET_HISTORY,
- ZFS_IOC_VDEV_ADD,
- ZFS_IOC_VDEV_REMOVE,
- ZFS_IOC_VDEV_SET_STATE,
- ZFS_IOC_VDEV_ATTACH,
- ZFS_IOC_VDEV_DETACH,
- ZFS_IOC_VDEV_SETPATH,
- ZFS_IOC_VDEV_SETFRU,
- ZFS_IOC_OBJSET_STATS,
- ZFS_IOC_OBJSET_ZPLPROPS,
- ZFS_IOC_DATASET_LIST_NEXT,
- ZFS_IOC_SNAPSHOT_LIST_NEXT,
- ZFS_IOC_SET_PROP,
- ZFS_IOC_CREATE,
- ZFS_IOC_DESTROY,
- ZFS_IOC_ROLLBACK,
- ZFS_IOC_RENAME,
- ZFS_IOC_RECV,
- ZFS_IOC_SEND,
- ZFS_IOC_INJECT_FAULT,
- ZFS_IOC_CLEAR_FAULT,
- ZFS_IOC_INJECT_LIST_NEXT,
- ZFS_IOC_ERROR_LOG,
- ZFS_IOC_CLEAR,
- ZFS_IOC_PROMOTE,
- ZFS_IOC_SNAPSHOT,
- ZFS_IOC_DSOBJ_TO_DSNAME,
- ZFS_IOC_OBJ_TO_PATH,
- ZFS_IOC_POOL_SET_PROPS,
- ZFS_IOC_POOL_GET_PROPS,
- ZFS_IOC_SET_FSACL,
- ZFS_IOC_GET_FSACL,
- ZFS_IOC_SHARE,
- ZFS_IOC_INHERIT_PROP,
- ZFS_IOC_SMB_ACL,
- ZFS_IOC_USERSPACE_ONE,
- ZFS_IOC_USERSPACE_MANY,
- ZFS_IOC_USERSPACE_UPGRADE,
- ZFS_IOC_HOLD,
- ZFS_IOC_RELEASE,
- ZFS_IOC_GET_HOLDS,
- ZFS_IOC_OBJSET_RECVD_PROPS,
- ZFS_IOC_VDEV_SPLIT,
- ZFS_IOC_NEXT_OBJ,
- ZFS_IOC_DIFF,
- ZFS_IOC_TMP_SNAPSHOT,
- ZFS_IOC_OBJ_TO_STATS,
- ZFS_IOC_SPACE_WRITTEN,
- ZFS_IOC_SPACE_SNAPS,
- ZFS_IOC_DESTROY_SNAPS,
- ZFS_IOC_POOL_REGUID,
- ZFS_IOC_POOL_REOPEN,
- ZFS_IOC_SEND_PROGRESS,
- ZFS_IOC_LOG_HISTORY,
- ZFS_IOC_SEND_NEW,
- ZFS_IOC_SEND_SPACE,
- ZFS_IOC_CLONE,
- ZFS_IOC_BOOKMARK,
- ZFS_IOC_GET_BOOKMARKS,
- ZFS_IOC_DESTROY_BOOKMARKS,
- ZFS_IOC_CHANNEL_PROGRAM,
- ZFS_IOC_REMAP,
- ZFS_IOC_POOL_CHECKPOINT,
- ZFS_IOC_POOL_DISCARD_CHECKPOINT,
- ZFS_IOC_POOL_INITIALIZE,
- ZFS_IOC_POOL_SYNC,
- ZFS_IOC_LOAD_KEY,
- ZFS_IOC_UNLOAD_KEY,
- ZFS_IOC_CHANGE_KEY,
- ZFS_IOC_POOL_TRIM,
+ ZFS_IOC_POOL_CREATE = ZFS_IOC_FIRST, /* 0x5a00 */
+ ZFS_IOC_POOL_DESTROY, /* 0x5a01 */
+ ZFS_IOC_POOL_IMPORT, /* 0x5a02 */
+ ZFS_IOC_POOL_EXPORT, /* 0x5a03 */
+ ZFS_IOC_POOL_CONFIGS, /* 0x5a04 */
+ ZFS_IOC_POOL_STATS, /* 0x5a05 */
+ ZFS_IOC_POOL_TRYIMPORT, /* 0x5a06 */
+ ZFS_IOC_POOL_SCAN, /* 0x5a07 */
+ ZFS_IOC_POOL_FREEZE, /* 0x5a08 */
+ ZFS_IOC_POOL_UPGRADE, /* 0x5a09 */
+ ZFS_IOC_POOL_GET_HISTORY, /* 0x5a0a */
+ ZFS_IOC_VDEV_ADD, /* 0x5a0b */
+ ZFS_IOC_VDEV_REMOVE, /* 0x5a0c */
+ ZFS_IOC_VDEV_SET_STATE, /* 0x5a0d */
+ ZFS_IOC_VDEV_ATTACH, /* 0x5a0e */
+ ZFS_IOC_VDEV_DETACH, /* 0x5a0f */
+ ZFS_IOC_VDEV_SETPATH, /* 0x5a10 */
+ ZFS_IOC_VDEV_SETFRU, /* 0x5a11 */
+ ZFS_IOC_OBJSET_STATS, /* 0x5a12 */
+ ZFS_IOC_OBJSET_ZPLPROPS, /* 0x5a13 */
+ ZFS_IOC_DATASET_LIST_NEXT, /* 0x5a14 */
+ ZFS_IOC_SNAPSHOT_LIST_NEXT, /* 0x5a15 */
+ ZFS_IOC_SET_PROP, /* 0x5a16 */
+ ZFS_IOC_CREATE, /* 0x5a17 */
+ ZFS_IOC_DESTROY, /* 0x5a18 */
+ ZFS_IOC_ROLLBACK, /* 0x5a19 */
+ ZFS_IOC_RENAME, /* 0x5a1a */
+ ZFS_IOC_RECV, /* 0x5a1b */
+ ZFS_IOC_SEND, /* 0x5a1c */
+ ZFS_IOC_INJECT_FAULT, /* 0x5a1d */
+ ZFS_IOC_CLEAR_FAULT, /* 0x5a1e */
+ ZFS_IOC_INJECT_LIST_NEXT, /* 0x5a1f */
+ ZFS_IOC_ERROR_LOG, /* 0x5a20 */
+ ZFS_IOC_CLEAR, /* 0x5a21 */
+ ZFS_IOC_PROMOTE, /* 0x5a22 */
+ ZFS_IOC_SNAPSHOT, /* 0x5a23 */
+ ZFS_IOC_DSOBJ_TO_DSNAME, /* 0x5a24 */
+ ZFS_IOC_OBJ_TO_PATH, /* 0x5a25 */
+ ZFS_IOC_POOL_SET_PROPS, /* 0x5a26 */
+ ZFS_IOC_POOL_GET_PROPS, /* 0x5a27 */
+ ZFS_IOC_SET_FSACL, /* 0x5a28 */
+ ZFS_IOC_GET_FSACL, /* 0x5a29 */
+ ZFS_IOC_SHARE, /* 0x5a2a */
+ ZFS_IOC_INHERIT_PROP, /* 0x5a2b */
+ ZFS_IOC_SMB_ACL, /* 0x5a2c */
+ ZFS_IOC_USERSPACE_ONE, /* 0x5a2d */
+ ZFS_IOC_USERSPACE_MANY, /* 0x5a2e */
+ ZFS_IOC_USERSPACE_UPGRADE, /* 0x5a2f */
+ ZFS_IOC_HOLD, /* 0x5a30 */
+ ZFS_IOC_RELEASE, /* 0x5a31 */
+ ZFS_IOC_GET_HOLDS, /* 0x5a32 */
+ ZFS_IOC_OBJSET_RECVD_PROPS, /* 0x5a33 */
+ ZFS_IOC_VDEV_SPLIT, /* 0x5a34 */
+ ZFS_IOC_NEXT_OBJ, /* 0x5a35 */
+ ZFS_IOC_DIFF, /* 0x5a36 */
+ ZFS_IOC_TMP_SNAPSHOT, /* 0x5a37 */
+ ZFS_IOC_OBJ_TO_STATS, /* 0x5a38 */
+ ZFS_IOC_SPACE_WRITTEN, /* 0x5a39 */
+ ZFS_IOC_SPACE_SNAPS, /* 0x5a3a */
+ ZFS_IOC_DESTROY_SNAPS, /* 0x5a3b */
+ ZFS_IOC_POOL_REGUID, /* 0x5a3c */
+ ZFS_IOC_POOL_REOPEN, /* 0x5a3d */
+ ZFS_IOC_SEND_PROGRESS, /* 0x5a3e */
+ ZFS_IOC_LOG_HISTORY, /* 0x5a3f */
+ ZFS_IOC_SEND_NEW, /* 0x5a40 */
+ ZFS_IOC_SEND_SPACE, /* 0x5a41 */
+ ZFS_IOC_CLONE, /* 0x5a42 */
+ ZFS_IOC_BOOKMARK, /* 0x5a43 */
+ ZFS_IOC_GET_BOOKMARKS, /* 0x5a44 */
+ ZFS_IOC_DESTROY_BOOKMARKS, /* 0x5a45 */
+ ZFS_IOC_POOL_SYNC, /* 0x5a47 */
+ ZFS_IOC_CHANNEL_PROGRAM, /* 0x5a48 */
+ ZFS_IOC_LOAD_KEY, /* 0x5a49 */
+ ZFS_IOC_UNLOAD_KEY, /* 0x5a4a */
+ ZFS_IOC_CHANGE_KEY, /* 0x5a4b */
+ ZFS_IOC_REMAP, /* 0x5a4c */
+ ZFS_IOC_POOL_CHECKPOINT, /* 0x5a4d */
+ ZFS_IOC_POOL_DISCARD_CHECKPOINT, /* 0x5a4e */
+ ZFS_IOC_POOL_INITIALIZE, /* 0x5a4f */
+ ZFS_IOC_POOL_TRIM, /* 0x5a50 */
+ ZFS_IOC_REDACT, /* 0x5a51 */
+ ZFS_IOC_GET_BOOKMARK_PROPS, /* 0x5a52 */
ZFS_IOC_LAST
} zfs_ioc_t;
@@ -1270,6 +1272,11 @@ typedef enum {
ZFS_ERR_FROM_IVSET_GUID_MISSING,
ZFS_ERR_FROM_IVSET_GUID_MISMATCH,
ZFS_ERR_SPILL_BLOCK_FLAG_MISSING,
+ ZFS_ERR_UNKNOWN_SEND_STREAM_FEATURE,
+ ZFS_ERR_IOC_CMD_UNAVAIL,
+ ZFS_ERR_IOC_ARG_UNAVAIL,
+ ZFS_ERR_IOC_ARG_REQUIRED,
+ ZFS_ERR_IOC_ARG_BADTYPE,
} zfs_errno_t;
/*
diff --git a/usr/src/uts/common/sys/user.h b/usr/src/uts/common/sys/user.h
index 8c424e7bf3..e9739cf0fc 100644
--- a/usr/src/uts/common/sys/user.h
+++ b/usr/src/uts/common/sys/user.h
@@ -111,7 +111,7 @@ typedef struct uf_entry {
short uf_busy; /* file is allocated [grow, fork] */
kcondvar_t uf_wanted_cv; /* waiting for setf() [never copied] */
kcondvar_t uf_closing_cv; /* waiting for close() [never copied] */
- struct portfd *uf_portfd; /* associated with port [grow] */
+ struct portfd *uf_portfd; /* associated with port [grow] */
uf_entry_gen_t uf_gen; /* assigned fd generation [grow,fork] */
/* Avoid false sharing - pad to coherency granularity (64 bytes) */
char uf_pad[64 - sizeof (kmutex_t) - 2 * sizeof (void*) -