aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/lib/libspl
diff options
context:
space:
mode:
Diffstat (limited to 'sys/contrib/openzfs/lib/libspl')
-rw-r--r--sys/contrib/openzfs/lib/libspl/Makefile.am71
-rw-r--r--sys/contrib/openzfs/lib/libspl/assert.c78
-rw-r--r--sys/contrib/openzfs/lib/libspl/atomic.c149
-rw-r--r--sys/contrib/openzfs/lib/libspl/backtrace.c303
-rw-r--r--sys/contrib/openzfs/lib/libspl/getexecname.c3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/Makefile.am126
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/assert.h192
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/atomic.h10
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/ia32/Makefile.am1
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/ia32/sys/Makefile.am3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/libdevinfo.h30
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/libgen.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/libshare.h45
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/locale.h35
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/Makefile.am7
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/freebsd/Makefile.am5
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/freebsd/fcntl.h1
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/Makefile.am12
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/byteorder.h19
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/fcntl.h1
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/file.h11
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/ia32/asm_linkage.h185
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/mnttab.h7
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/mount.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/param.h5
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/stat.h9
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/vfs.h1
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/zfs_context_os.h2
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/linux/Makefile.am1
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/linux/sys/Makefile.am10
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/linux/sys/byteorder.h19
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/linux/sys/errno.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/linux/sys/ia32/asm_linkage.h (renamed from sys/contrib/openzfs/lib/libspl/include/ia32/sys/asm_linkage.h)200
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/linux/sys/mnttab.h5
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/linux/sys/mount.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/linux/sys/param.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/linux/sys/stat.h8
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/linux/sys/sysmacros.h6
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/os/linux/sys/zfs_context_os.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/rpc/Makefile.am3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/rpc/xdr.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/statcommon.h7
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/stdio.h34
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/stdlib.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/string.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/Makefile.am48
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/abd_impl_os.h (renamed from sys/contrib/openzfs/lib/libspl/include/sys/stropts.h)25
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/abd_os.h (renamed from sys/contrib/openzfs/lib/libspl/include/stropts.h)31
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/acl.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/acl_impl.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/asm_linkage.h (renamed from sys/contrib/openzfs/lib/libspl/include/limits.h)32
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/backtrace.h (renamed from sys/contrib/openzfs/lib/libspl/include/sys/va_list.h)13
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/callb.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/cmn_err.h37
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/cred.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/debug.h7
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/dkio.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/dklabel.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/dktp/Makefile.am4
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/dktp/fdisk.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/feature_tests.h10
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/int_limits.h30
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/int_types.h32
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/inttypes.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/isa_defs.h52
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/kmem.h7
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/kstat.h48
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/list.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/list_impl.h4
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/mhd.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/mkdev.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/mod.h56
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/policy.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/poll.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/priv.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/processor.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/sha2.h151
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/simd.h181
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/stack.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/stdtypes.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/string.h1
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/strings.h33
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/sunddi.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/systeminfo.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/time.h14
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/tunables.h60
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/types.h32
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/types32.h8
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/tzfile.h164
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/uio.h35
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/varargs.h30
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/vnode.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/vtoc.h350
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/wmsum.h1
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/sys/zone.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/thread.h30
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/tzfile.h32
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/ucred.h32
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/umem.h35
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/unistd.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/util/Makefile.am3
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/util/sscanf.h30
-rw-r--r--sys/contrib/openzfs/lib/libspl/include/zone.h15
-rw-r--r--sys/contrib/openzfs/lib/libspl/libspl_impl.h3
-rw-r--r--sys/contrib/openzfs/lib/libspl/list.c7
-rw-r--r--sys/contrib/openzfs/lib/libspl/mkdirp.c3
-rw-r--r--sys/contrib/openzfs/lib/libspl/os/freebsd/getexecname.c3
-rw-r--r--sys/contrib/openzfs/lib/libspl/os/freebsd/gethostid.c3
-rw-r--r--sys/contrib/openzfs/lib/libspl/os/freebsd/getmntany.c8
-rw-r--r--sys/contrib/openzfs/lib/libspl/os/freebsd/mnttab.c49
-rw-r--r--sys/contrib/openzfs/lib/libspl/os/freebsd/zone.c1
-rw-r--r--sys/contrib/openzfs/lib/libspl/os/linux/getexecname.c3
-rw-r--r--sys/contrib/openzfs/lib/libspl/os/linux/gethostid.c9
-rw-r--r--sys/contrib/openzfs/lib/libspl/os/linux/getmntany.c42
-rw-r--r--sys/contrib/openzfs/lib/libspl/os/linux/zone.c37
-rw-r--r--sys/contrib/openzfs/lib/libspl/page.c3
-rw-r--r--sys/contrib/openzfs/lib/libspl/strlcat.c3
-rw-r--r--sys/contrib/openzfs/lib/libspl/strlcpy.c3
-rw-r--r--sys/contrib/openzfs/lib/libspl/timestamp.c50
-rw-r--r--sys/contrib/openzfs/lib/libspl/tunables.c319
120 files changed, 2208 insertions, 1708 deletions
diff --git a/sys/contrib/openzfs/lib/libspl/Makefile.am b/sys/contrib/openzfs/lib/libspl/Makefile.am
index 8457df6dcdf4..0fd907d3011e 100644
--- a/sys/contrib/openzfs/lib/libspl/Makefile.am
+++ b/sys/contrib/openzfs/lib/libspl/Makefile.am
@@ -1,47 +1,56 @@
-include $(top_srcdir)/config/Rules.am
+include $(srcdir)/%D%/include/Makefile.am
-SUBDIRS = include
+libspl_assert_la_CFLAGS = $(AM_CFLAGS) $(LIBRARY_CFLAGS) $(LIBUNWIND_CFLAGS)
+libspl_la_CFLAGS = $(libspl_assert_la_CFLAGS)
+if TARGET_CPU_I386
+libspl_la_CFLAGS += $(NO_ATOMIC_ALIGNMENT)
+endif
-noinst_LTLIBRARIES = libspl_assert.la libspl.la
+noinst_LTLIBRARIES += libspl_assert.la libspl.la
+CPPCHECKTARGETS += libspl_assert.la libspl.la
libspl_assert_la_SOURCES = \
- assert.c
-
-USER_C = \
- libspl_impl.h \
- atomic.c \
- getexecname.c \
- list.c \
- mkdirp.c \
- page.c \
- strlcat.c \
- strlcpy.c \
- timestamp.c \
- include/sys/list.h \
- include/sys/list_impl.h
+ %D%/assert.c \
+ %D%/backtrace.c
+
+libspl_la_SOURCES = \
+ %D%/libspl_impl.h \
+ %D%/atomic.c \
+ %D%/getexecname.c \
+ %D%/list.c \
+ %D%/mkdirp.c \
+ %D%/page.c \
+ %D%/strlcat.c \
+ %D%/strlcpy.c \
+ %D%/timestamp.c \
+ %D%/tunables.c \
+ %D%/include/sys/list.h \
+ %D%/include/sys/list_impl.h
if BUILD_LINUX
-USER_C += \
- os/linux/getexecname.c \
- os/linux/gethostid.c \
- os/linux/getmntany.c \
- os/linux/zone.c
+libspl_la_SOURCES += \
+ %D%/os/linux/getexecname.c \
+ %D%/os/linux/gethostid.c \
+ %D%/os/linux/getmntany.c \
+ %D%/os/linux/zone.c
endif
if BUILD_FREEBSD
-USER_C += \
- os/freebsd/getexecname.c \
- os/freebsd/gethostid.c \
- os/freebsd/getmntany.c \
- os/freebsd/mnttab.c \
- os/freebsd/zone.c
+libspl_la_SOURCES += \
+ %D%/os/freebsd/getexecname.c \
+ %D%/os/freebsd/gethostid.c \
+ %D%/os/freebsd/getmntany.c \
+ %D%/os/freebsd/mnttab.c \
+ %D%/os/freebsd/zone.c
endif
-libspl_la_SOURCES = $(USER_C)
-
libspl_la_LIBADD = \
libspl_assert.la
libspl_la_LIBADD += $(LIBATOMIC_LIBS) $(LIBCLOCK_GETTIME)
-include $(top_srcdir)/config/CppCheck.am
+libspl_assert_la_LIBADD = $(BACKTRACE_LIBS) $(LIBUNWIND_LIBS)
+
+if BUILD_FREEBSD
+libspl_assert_la_LIBADD += -lpthread
+endif
diff --git a/sys/contrib/openzfs/lib/libspl/assert.c b/sys/contrib/openzfs/lib/libspl/assert.c
index 8e4333976f95..54d931104814 100644
--- a/sys/contrib/openzfs/lib/libspl/assert.c
+++ b/sys/contrib/openzfs/lib/libspl/assert.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -22,25 +23,94 @@
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+/*
+ * Copyright (c) 2024, Rob Norris <robn@despairlabs.com>
+ */
#include <assert.h>
+#include <pthread.h>
+#include <sys/backtrace.h>
+
+#if defined(__linux__)
+#include <errno.h>
+#include <sys/prctl.h>
+#ifdef HAVE_GETTID
+#define libspl_gettid() gettid()
+#else
+#include <sys/syscall.h>
+#define libspl_gettid() ((pid_t)syscall(__NR_gettid))
+#endif
+#define libspl_getprogname() (program_invocation_short_name)
+#define libspl_getthreadname(buf, len) \
+ prctl(PR_GET_NAME, (unsigned long)(buf), 0, 0, 0)
+#elif defined(__FreeBSD__) || defined(__APPLE__)
+#if !defined(__APPLE__)
+#include <pthread_np.h>
+#define libspl_gettid() pthread_getthreadid_np()
+#endif
+#define libspl_getprogname() getprogname()
+#define libspl_getthreadname(buf, len) \
+ pthread_getname_np(pthread_self(), buf, len);
+#endif
+
+#if defined(__APPLE__)
+static inline uint64_t
+libspl_gettid(void)
+{
+ uint64_t tid;
-int libspl_assert_ok = 0;
+ if (pthread_threadid_np(NULL, &tid) != 0)
+ tid = 0;
+
+ return (tid);
+}
+#endif
+
+static boolean_t libspl_assert_ok = B_FALSE;
+
+void
+libspl_set_assert_ok(boolean_t val)
+{
+ libspl_assert_ok = val;
+}
+
+static pthread_mutex_t assert_lock = PTHREAD_MUTEX_INITIALIZER;
/* printf version of libspl_assert */
void
libspl_assertf(const char *file, const char *func, int line,
const char *format, ...)
{
+ pthread_mutex_lock(&assert_lock);
+
va_list args;
+ char tname[64];
+
+ libspl_getthreadname(tname, sizeof (tname));
+
+ fprintf(stderr, "ASSERT at %s:%d:%s()\n", file, line, func);
va_start(args, format);
vfprintf(stderr, format, args);
- fprintf(stderr, "\n");
- fprintf(stderr, "ASSERT at %s:%d:%s()", file, line, func);
va_end(args);
+
+ fprintf(stderr, "\n"
+ " PID: %-8u COMM: %s\n"
+#if defined(__APPLE__)
+ " TID: %-8" PRIu64 " NAME: %s\n",
+#else
+ " TID: %-8u NAME: %s\n",
+#endif
+ getpid(), libspl_getprogname(),
+ libspl_gettid(), tname);
+
+ libspl_backtrace(STDERR_FILENO);
+
+#if !__has_feature(attribute_analyzer_noreturn) && !defined(__COVERITY__)
if (libspl_assert_ok) {
+ pthread_mutex_unlock(&assert_lock);
return;
}
+#endif
abort();
}
diff --git a/sys/contrib/openzfs/lib/libspl/atomic.c b/sys/contrib/openzfs/lib/libspl/atomic.c
index 4717d818ce5c..b5cc4ab2a55f 100644
--- a/sys/contrib/openzfs/lib/libspl/atomic.c
+++ b/sys/contrib/openzfs/lib/libspl/atomic.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -29,7 +30,6 @@
/*
* These are the void returning variants
*/
-/* BEGIN CSTYLED */
#define ATOMIC_INC(name, type) \
void atomic_inc_##name(volatile type *target) \
{ \
@@ -37,13 +37,13 @@
}
ATOMIC_INC(8, uint8_t)
-ATOMIC_INC(uchar, uchar_t)
ATOMIC_INC(16, uint16_t)
-ATOMIC_INC(ushort, ushort_t)
ATOMIC_INC(32, uint32_t)
+ATOMIC_INC(64, uint64_t)
+ATOMIC_INC(uchar, uchar_t)
+ATOMIC_INC(ushort, ushort_t)
ATOMIC_INC(uint, uint_t)
ATOMIC_INC(ulong, ulong_t)
-ATOMIC_INC(64, uint64_t)
#define ATOMIC_DEC(name, type) \
@@ -53,13 +53,13 @@ ATOMIC_INC(64, uint64_t)
}
ATOMIC_DEC(8, uint8_t)
-ATOMIC_DEC(uchar, uchar_t)
ATOMIC_DEC(16, uint16_t)
-ATOMIC_DEC(ushort, ushort_t)
ATOMIC_DEC(32, uint32_t)
+ATOMIC_DEC(64, uint64_t)
+ATOMIC_DEC(uchar, uchar_t)
+ATOMIC_DEC(ushort, ushort_t)
ATOMIC_DEC(uint, uint_t)
ATOMIC_DEC(ulong, ulong_t)
-ATOMIC_DEC(64, uint64_t)
#define ATOMIC_ADD(name, type1, type2) \
@@ -68,21 +68,21 @@ ATOMIC_DEC(64, uint64_t)
(void) __atomic_add_fetch(target, bits, __ATOMIC_SEQ_CST); \
}
-ATOMIC_ADD(8, uint8_t, int8_t)
-ATOMIC_ADD(char, uchar_t, signed char)
-ATOMIC_ADD(16, uint16_t, int16_t)
-ATOMIC_ADD(short, ushort_t, short)
-ATOMIC_ADD(32, uint32_t, int32_t)
-ATOMIC_ADD(int, uint_t, int)
-ATOMIC_ADD(long, ulong_t, long)
-ATOMIC_ADD(64, uint64_t, int64_t)
-
void
atomic_add_ptr(volatile void *target, ssize_t bits)
{
(void) __atomic_add_fetch((void **)target, bits, __ATOMIC_SEQ_CST);
}
+ATOMIC_ADD(8, uint8_t, int8_t)
+ATOMIC_ADD(16, uint16_t, int16_t)
+ATOMIC_ADD(32, uint32_t, int32_t)
+ATOMIC_ADD(64, uint64_t, int64_t)
+ATOMIC_ADD(char, uchar_t, signed char)
+ATOMIC_ADD(short, ushort_t, short)
+ATOMIC_ADD(int, uint_t, int)
+ATOMIC_ADD(long, ulong_t, long)
+
#define ATOMIC_SUB(name, type1, type2) \
void atomic_sub_##name(volatile type1 *target, type2 bits) \
@@ -90,21 +90,21 @@ atomic_add_ptr(volatile void *target, ssize_t bits)
(void) __atomic_sub_fetch(target, bits, __ATOMIC_SEQ_CST); \
}
-ATOMIC_SUB(8, uint8_t, int8_t)
-ATOMIC_SUB(char, uchar_t, signed char)
-ATOMIC_SUB(16, uint16_t, int16_t)
-ATOMIC_SUB(short, ushort_t, short)
-ATOMIC_SUB(32, uint32_t, int32_t)
-ATOMIC_SUB(int, uint_t, int)
-ATOMIC_SUB(long, ulong_t, long)
-ATOMIC_SUB(64, uint64_t, int64_t)
-
void
atomic_sub_ptr(volatile void *target, ssize_t bits)
{
(void) __atomic_sub_fetch((void **)target, bits, __ATOMIC_SEQ_CST);
}
+ATOMIC_SUB(8, uint8_t, int8_t)
+ATOMIC_SUB(16, uint16_t, int16_t)
+ATOMIC_SUB(32, uint32_t, int32_t)
+ATOMIC_SUB(64, uint64_t, int64_t)
+ATOMIC_SUB(char, uchar_t, signed char)
+ATOMIC_SUB(short, ushort_t, short)
+ATOMIC_SUB(int, uint_t, int)
+ATOMIC_SUB(long, ulong_t, long)
+
#define ATOMIC_OR(name, type) \
void atomic_or_##name(volatile type *target, type bits) \
@@ -113,13 +113,13 @@ atomic_sub_ptr(volatile void *target, ssize_t bits)
}
ATOMIC_OR(8, uint8_t)
-ATOMIC_OR(uchar, uchar_t)
ATOMIC_OR(16, uint16_t)
-ATOMIC_OR(ushort, ushort_t)
ATOMIC_OR(32, uint32_t)
+ATOMIC_OR(64, uint64_t)
+ATOMIC_OR(uchar, uchar_t)
+ATOMIC_OR(ushort, ushort_t)
ATOMIC_OR(uint, uint_t)
ATOMIC_OR(ulong, ulong_t)
-ATOMIC_OR(64, uint64_t)
#define ATOMIC_AND(name, type) \
@@ -129,13 +129,13 @@ ATOMIC_OR(64, uint64_t)
}
ATOMIC_AND(8, uint8_t)
-ATOMIC_AND(uchar, uchar_t)
ATOMIC_AND(16, uint16_t)
-ATOMIC_AND(ushort, ushort_t)
ATOMIC_AND(32, uint32_t)
+ATOMIC_AND(64, uint64_t)
+ATOMIC_AND(uchar, uchar_t)
+ATOMIC_AND(ushort, ushort_t)
ATOMIC_AND(uint, uint_t)
ATOMIC_AND(ulong, ulong_t)
-ATOMIC_AND(64, uint64_t)
/*
@@ -149,13 +149,13 @@ ATOMIC_AND(64, uint64_t)
}
ATOMIC_INC_NV(8, uint8_t)
-ATOMIC_INC_NV(uchar, uchar_t)
ATOMIC_INC_NV(16, uint16_t)
-ATOMIC_INC_NV(ushort, ushort_t)
ATOMIC_INC_NV(32, uint32_t)
+ATOMIC_INC_NV(64, uint64_t)
+ATOMIC_INC_NV(uchar, uchar_t)
+ATOMIC_INC_NV(ushort, ushort_t)
ATOMIC_INC_NV(uint, uint_t)
ATOMIC_INC_NV(ulong, ulong_t)
-ATOMIC_INC_NV(64, uint64_t)
#define ATOMIC_DEC_NV(name, type) \
@@ -165,13 +165,13 @@ ATOMIC_INC_NV(64, uint64_t)
}
ATOMIC_DEC_NV(8, uint8_t)
-ATOMIC_DEC_NV(uchar, uchar_t)
ATOMIC_DEC_NV(16, uint16_t)
-ATOMIC_DEC_NV(ushort, ushort_t)
ATOMIC_DEC_NV(32, uint32_t)
+ATOMIC_DEC_NV(64, uint64_t)
+ATOMIC_DEC_NV(uchar, uchar_t)
+ATOMIC_DEC_NV(ushort, ushort_t)
ATOMIC_DEC_NV(uint, uint_t)
ATOMIC_DEC_NV(ulong, ulong_t)
-ATOMIC_DEC_NV(64, uint64_t)
#define ATOMIC_ADD_NV(name, type1, type2) \
@@ -180,21 +180,21 @@ ATOMIC_DEC_NV(64, uint64_t)
return (__atomic_add_fetch(target, bits, __ATOMIC_SEQ_CST)); \
}
-ATOMIC_ADD_NV(8, uint8_t, int8_t)
-ATOMIC_ADD_NV(char, uchar_t, signed char)
-ATOMIC_ADD_NV(16, uint16_t, int16_t)
-ATOMIC_ADD_NV(short, ushort_t, short)
-ATOMIC_ADD_NV(32, uint32_t, int32_t)
-ATOMIC_ADD_NV(int, uint_t, int)
-ATOMIC_ADD_NV(long, ulong_t, long)
-ATOMIC_ADD_NV(64, uint64_t, int64_t)
-
void *
atomic_add_ptr_nv(volatile void *target, ssize_t bits)
{
return (__atomic_add_fetch((void **)target, bits, __ATOMIC_SEQ_CST));
}
+ATOMIC_ADD_NV(8, uint8_t, int8_t)
+ATOMIC_ADD_NV(16, uint16_t, int16_t)
+ATOMIC_ADD_NV(32, uint32_t, int32_t)
+ATOMIC_ADD_NV(64, uint64_t, int64_t)
+ATOMIC_ADD_NV(char, uchar_t, signed char)
+ATOMIC_ADD_NV(short, ushort_t, short)
+ATOMIC_ADD_NV(int, uint_t, int)
+ATOMIC_ADD_NV(long, ulong_t, long)
+
#define ATOMIC_SUB_NV(name, type1, type2) \
type1 atomic_sub_##name##_nv(volatile type1 *target, type2 bits) \
@@ -202,6 +202,12 @@ atomic_add_ptr_nv(volatile void *target, ssize_t bits)
return (__atomic_sub_fetch(target, bits, __ATOMIC_SEQ_CST)); \
}
+void *
+atomic_sub_ptr_nv(volatile void *target, ssize_t bits)
+{
+ return (__atomic_sub_fetch((void **)target, bits, __ATOMIC_SEQ_CST));
+}
+
ATOMIC_SUB_NV(8, uint8_t, int8_t)
ATOMIC_SUB_NV(char, uchar_t, signed char)
ATOMIC_SUB_NV(16, uint16_t, int16_t)
@@ -211,12 +217,6 @@ ATOMIC_SUB_NV(int, uint_t, int)
ATOMIC_SUB_NV(long, ulong_t, long)
ATOMIC_SUB_NV(64, uint64_t, int64_t)
-void *
-atomic_sub_ptr_nv(volatile void *target, ssize_t bits)
-{
- return (__atomic_sub_fetch((void **)target, bits, __ATOMIC_SEQ_CST));
-}
-
#define ATOMIC_OR_NV(name, type) \
type atomic_or_##name##_nv(volatile type *target, type bits) \
@@ -225,13 +225,13 @@ atomic_sub_ptr_nv(volatile void *target, ssize_t bits)
}
ATOMIC_OR_NV(8, uint8_t)
-ATOMIC_OR_NV(uchar, uchar_t)
ATOMIC_OR_NV(16, uint16_t)
-ATOMIC_OR_NV(ushort, ushort_t)
ATOMIC_OR_NV(32, uint32_t)
+ATOMIC_OR_NV(64, uint64_t)
+ATOMIC_OR_NV(uchar, uchar_t)
+ATOMIC_OR_NV(ushort, ushort_t)
ATOMIC_OR_NV(uint, uint_t)
ATOMIC_OR_NV(ulong, ulong_t)
-ATOMIC_OR_NV(64, uint64_t)
#define ATOMIC_AND_NV(name, type) \
@@ -241,13 +241,13 @@ ATOMIC_OR_NV(64, uint64_t)
}
ATOMIC_AND_NV(8, uint8_t)
-ATOMIC_AND_NV(uchar, uchar_t)
ATOMIC_AND_NV(16, uint16_t)
-ATOMIC_AND_NV(ushort, ushort_t)
ATOMIC_AND_NV(32, uint32_t)
+ATOMIC_AND_NV(64, uint64_t)
+ATOMIC_AND_NV(uchar, uchar_t)
+ATOMIC_AND_NV(ushort, ushort_t)
ATOMIC_AND_NV(uint, uint_t)
ATOMIC_AND_NV(ulong, ulong_t)
-ATOMIC_AND_NV(64, uint64_t)
/*
@@ -268,15 +268,6 @@ ATOMIC_AND_NV(64, uint64_t)
return (exp); \
}
-ATOMIC_CAS(8, uint8_t)
-ATOMIC_CAS(uchar, uchar_t)
-ATOMIC_CAS(16, uint16_t)
-ATOMIC_CAS(ushort, ushort_t)
-ATOMIC_CAS(32, uint32_t)
-ATOMIC_CAS(uint, uint_t)
-ATOMIC_CAS(ulong, ulong_t)
-ATOMIC_CAS(64, uint64_t)
-
void *
atomic_cas_ptr(volatile void *target, void *exp, void *des)
{
@@ -286,6 +277,15 @@ atomic_cas_ptr(volatile void *target, void *exp, void *des)
return (exp);
}
+ATOMIC_CAS(8, uint8_t)
+ATOMIC_CAS(16, uint16_t)
+ATOMIC_CAS(32, uint32_t)
+ATOMIC_CAS(64, uint64_t)
+ATOMIC_CAS(uchar, uchar_t)
+ATOMIC_CAS(ushort, ushort_t)
+ATOMIC_CAS(uint, uint_t)
+ATOMIC_CAS(ulong, ulong_t)
+
/*
* Swap target and return old value
@@ -298,14 +298,13 @@ atomic_cas_ptr(volatile void *target, void *exp, void *des)
}
ATOMIC_SWAP(8, uint8_t)
-ATOMIC_SWAP(uchar, uchar_t)
ATOMIC_SWAP(16, uint16_t)
-ATOMIC_SWAP(ushort, ushort_t)
ATOMIC_SWAP(32, uint32_t)
+ATOMIC_SWAP(64, uint64_t)
+ATOMIC_SWAP(uchar, uchar_t)
+ATOMIC_SWAP(ushort, ushort_t)
ATOMIC_SWAP(uint, uint_t)
ATOMIC_SWAP(ulong, ulong_t)
-ATOMIC_SWAP(64, uint64_t)
-/* END CSTYLED */
void *
atomic_swap_ptr(volatile void *target, void *bits)
@@ -356,6 +355,12 @@ membar_exit(void)
}
void
+membar_sync(void)
+{
+ __atomic_thread_fence(__ATOMIC_SEQ_CST);
+}
+
+void
membar_producer(void)
{
__atomic_thread_fence(__ATOMIC_RELEASE);
diff --git a/sys/contrib/openzfs/lib/libspl/backtrace.c b/sys/contrib/openzfs/lib/libspl/backtrace.c
new file mode 100644
index 000000000000..c4a7006a9692
--- /dev/null
+++ b/sys/contrib/openzfs/lib/libspl/backtrace.c
@@ -0,0 +1,303 @@
+// SPDX-License-Identifier: CDDL-1.0
+/*
+ * 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 https://opensource.org/licenses/CDDL-1.0.
+ * 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 (c) 2024, Rob Norris <robn@despairlabs.com>
+ * Copyright (c) 2024, Klara Inc.
+ */
+
+#include <sys/backtrace.h>
+#include <sys/types.h>
+#include <sys/debug.h>
+#include <unistd.h>
+
+/*
+ * Output helpers. libspl_backtrace() must not block, must be thread-safe and
+ * must be safe to call from a signal handler. At least, that means not having
+ * printf, so we end up having to call write() directly on the fd. That's
+ * awkward, as we always have to pass through a length, and some systems will
+ * complain if we don't consume the return. So we have some macros to make
+ * things a little more palatable.
+ */
+#define spl_bt_write_n(fd, s, n) \
+ do { ssize_t r __maybe_unused = write(fd, s, n); } while (0)
+#define spl_bt_write(fd, s) spl_bt_write_n(fd, s, sizeof (s)-1)
+
+#ifdef HAVE_LIBUNWIND
+/*
+ * libunwind-gcc and libunwind-llvm both list registers using an enum,
+ * unw_regnum_t, however they indicate the highest numbered register for
+ * a given architecture in different ways. We can check which one is defined
+ * and mark which libunwind is in use
+ */
+#ifdef IS_LIBUNWIND_LLVM
+#include <libunwind.h>
+#define LAST_REG_INDEX _LIBUNWIND_HIGHEST_DWARF_REGISTER
+#else
+/*
+ * Need to define UNW_LOCAL_ONLY before importing libunwind.h
+ * if using libgcc libunwind.
+ */
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+#define LAST_REG_INDEX UNW_TDEP_LAST_REG
+#endif
+
+
+/*
+ * Convert `v` to ASCII hex characters. The bottom `n` nybbles (4-bits ie one
+ * hex digit) will be written, up to `buflen`. The buffer will not be
+ * null-terminated. Returns the number of digits written.
+ */
+static size_t
+spl_bt_u64_to_hex_str(uint64_t v, size_t n, char *buf, size_t buflen)
+{
+ static const char hexdigits[] = {
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
+ };
+
+ size_t pos = 0;
+ boolean_t want = (n == 0);
+ for (int i = 15; i >= 0; i--) {
+ const uint64_t d = v >> (i * 4) & 0xf;
+ if (!want && (d != 0 || n > i))
+ want = B_TRUE;
+ if (want) {
+ buf[pos++] = hexdigits[d];
+ if (pos == buflen)
+ break;
+ }
+ }
+ return (pos);
+}
+
+void
+libspl_backtrace(int fd)
+{
+ unw_context_t uc;
+ unw_cursor_t cp;
+ unw_word_t v;
+ char buf[128];
+ size_t n;
+ int err;
+
+ /* Snapshot the current frame and state. */
+ unw_getcontext(&uc);
+
+ /*
+ * TODO: walk back to the frame that tripped the assertion / the place
+ * where the signal was recieved.
+ */
+
+ /*
+ * Register dump. We're going to loop over all the registers in the
+ * top frame, and show them, with names, in a nice three-column
+ * layout, which keeps us within 80 columns.
+ */
+ spl_bt_write(fd, "Registers:\n");
+
+ /* Initialise a frame cursor, starting at the current frame */
+ unw_init_local(&cp, &uc);
+
+ /*
+ * Iterate over all registers for the architecture. We've figured
+ * out the highest number above, however, not all register numbers in
+ * this range are defined by the architecture, and not all defined
+ * registers will be present on every implementation of that
+ * architecture. Moreover, libunwind provides nice names for most, but
+ * not all registers, but these are hardcoded; a name being available
+ * does not mean that register is available.
+ *
+ * So, we have to pull this all together here. We try to get the value
+ * of every possible register. If we get a value for it, then the
+ * register must exist, and so we get its name. If libunwind has no
+ * name for it, we synthesize something. These cases should be rare,
+ * and they're usually for uninteresting or niche registers, so it
+ * shouldn't really matter. We can see the value, and that's the main
+ * thing.
+ */
+ uint_t cols = 0;
+ for (uint_t regnum = 0; regnum <= LAST_REG_INDEX; regnum++) {
+ /*
+ * Get the value. Any error probably means the register
+ * doesn't exist, and we skip it. LLVM libunwind iterates over
+ * fp registers in the same list, however they have to be
+ * accessed using unw_get_fpreg instead. Here, we just ignore
+ * them.
+ */
+#ifdef IS_LIBUNWIND_LLVM
+ if (unw_is_fpreg(&cp, regnum) ||
+ unw_get_reg(&cp, regnum, &v) < 0)
+ continue;
+#else
+ if (unw_get_reg(&cp, regnum, &v) < 0)
+ continue;
+#endif
+
+ /*
+ * Register name. If GCC libunwind doesn't have a name for it,
+ * it will return "???". As a shortcut, we just treat '?'
+ * is an alternate end-of-string character. LLVM libunwind will
+ * return the string 'unknown register', which we detect by
+ * checking if the register name is longer than 5 characters.
+ */
+#ifdef IS_LIBUNWIND_LLVM
+ const char *name = unw_regname(&cp, regnum);
+#else
+ const char *name = unw_regname(regnum);
+#endif
+ for (n = 0; name[n] != '\0' && name[n] != '?'; n++) {}
+ if (n == 0 || n > 5) {
+ /*
+ * No valid name, or likely llvm_libunwind returned
+ * unknown_register, so make one of the form "?xx",
+ * where "xx" is the two-char hex of libunwind's
+ * register number.
+ */
+ buf[0] = '?';
+ n = spl_bt_u64_to_hex_str(regnum, 2,
+ &buf[1], sizeof (buf)-1) + 1;
+ name = buf;
+ }
+
+ /*
+ * Two spaces of padding before each column, plus extra
+ * spaces to align register names shorter than three chars.
+ */
+ spl_bt_write_n(fd, " ", 5-MIN(n, 3));
+
+ /* Register name and column punctuation */
+ spl_bt_write_n(fd, name, n);
+ spl_bt_write(fd, ": 0x");
+
+ /*
+ * Convert register value (from unw_get_reg()) to hex. We're
+ * assuming that all registers are 64-bits wide, which is
+ * probably fine for any general-purpose registers on any
+ * machine currently in use. A more generic way would be to
+ * look at the width of unw_word_t, but that would also
+ * complicate the column code a bit. This is fine.
+ */
+ n = spl_bt_u64_to_hex_str(v, 16, buf, sizeof (buf));
+ spl_bt_write_n(fd, buf, n);
+
+ /* Every third column, emit a newline */
+ if (!(++cols % 3))
+ spl_bt_write(fd, "\n");
+ }
+
+ /* If we finished before the third column, emit a newline. */
+ if (cols % 3)
+ spl_bt_write(fd, "\n");
+
+ /* Now the main event, the backtrace. */
+ spl_bt_write(fd, "Call trace:\n");
+
+ /* Reset the cursor to the top again. */
+ unw_init_local(&cp, &uc);
+
+ do {
+ /*
+ * Getting the IP should never fail; libunwind handles it
+ * specially, because its used a lot internally. Still, no
+ * point being silly about it, as the last thing we want is
+ * our crash handler to crash. So if it ever does fail, we'll
+ * show an error line, but keep going to the next frame.
+ */
+ if (unw_get_reg(&cp, UNW_REG_IP, &v) < 0) {
+ spl_bt_write(fd, " [couldn't get IP register; "
+ "corrupt frame?]");
+ continue;
+ }
+
+ /* IP & punctuation */
+ n = spl_bt_u64_to_hex_str(v, 16, buf, sizeof (buf));
+ spl_bt_write(fd, " [0x");
+ spl_bt_write_n(fd, buf, n);
+ spl_bt_write(fd, "] ");
+
+ /*
+ * Function ("procedure") name for the current frame. `v`
+ * receives the offset from the named function to the IP, which
+ * we show as a "+offset" suffix.
+ *
+ * If libunwind can't determine the name, we just show "???"
+ * instead. We've already displayed the IP above; that will
+ * have to do.
+ *
+ * unw_get_proc_name() will return ENOMEM if the buffer is too
+ * small, instead truncating the name. So we treat that as a
+ * success and use whatever is in the buffer.
+ */
+ err = unw_get_proc_name(&cp, buf, sizeof (buf), &v);
+ if (err == 0 || err == -UNW_ENOMEM) {
+ for (n = 0; n < sizeof (buf) && buf[n] != '\0'; n++) {}
+ spl_bt_write_n(fd, buf, n);
+
+ /* Offset from proc name */
+ spl_bt_write(fd, "+0x");
+ n = spl_bt_u64_to_hex_str(v, 2, buf, sizeof (buf));
+ spl_bt_write_n(fd, buf, n);
+ } else
+ spl_bt_write(fd, "???");
+
+#ifdef HAVE_LIBUNWIND_ELF
+ /*
+ * Newer libunwind has unw_get_elf_filename(), which gets
+ * the name of the ELF object that the frame was executing in.
+ * Like `unw_get_proc_name()`, `v` recieves the offset within
+ * the file, and UNW_ENOMEM indicates that a truncate filename
+ * was left in the buffer.
+ */
+ err = unw_get_elf_filename(&cp, buf, sizeof (buf), &v);
+ if (err == 0 || err == -UNW_ENOMEM) {
+ for (n = 0; n < sizeof (buf) && buf[n] != '\0'; n++) {}
+ spl_bt_write(fd, " (in ");
+ spl_bt_write_n(fd, buf, n);
+
+ /* Offset within file */
+ spl_bt_write(fd, " +0x");
+ n = spl_bt_u64_to_hex_str(v, 2, buf, sizeof (buf));
+ spl_bt_write_n(fd, buf, n);
+ spl_bt_write(fd, ")");
+ }
+#endif
+ spl_bt_write(fd, "\n");
+ } while (unw_step(&cp) > 0);
+}
+#elif defined(HAVE_BACKTRACE)
+#include <execinfo.h>
+
+void
+libspl_backtrace(int fd)
+{
+ void *btptrs[64];
+ size_t nptrs = backtrace(btptrs, 64);
+ spl_bt_write(fd, "Call trace:\n");
+ backtrace_symbols_fd(btptrs, nptrs, fd);
+}
+#else
+void
+libspl_backtrace(int fd __maybe_unused)
+{
+}
+#endif
diff --git a/sys/contrib/openzfs/lib/libspl/getexecname.c b/sys/contrib/openzfs/lib/libspl/getexecname.c
index dca7162034f7..56ba5aa86058 100644
--- a/sys/contrib/openzfs/lib/libspl/getexecname.c
+++ b/sys/contrib/openzfs/lib/libspl/getexecname.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/Makefile.am b/sys/contrib/openzfs/lib/libspl/include/Makefile.am
index 9ca08b2bc0f7..21f0c70db9e7 100644
--- a/sys/contrib/openzfs/lib/libspl/include/Makefile.am
+++ b/sys/contrib/openzfs/lib/libspl/include/Makefile.am
@@ -1,22 +1,108 @@
-SUBDIRS = ia32 rpc sys util os
-
libspldir = $(includedir)/libspl
libspl_HEADERS = \
- assert.h \
- atomic.h \
- libdevinfo.h \
- libgen.h \
- libshare.h \
- limits.h \
- locale.h \
- statcommon.h \
- stdio.h \
- stdlib.h \
- string.h \
- stropts.h \
- thread.h \
- tzfile.h \
- ucred.h \
- umem.h \
- unistd.h \
- zone.h
+ %D%/assert.h \
+ %D%/atomic.h \
+ %D%/libgen.h \
+ %D%/libshare.h \
+ %D%/statcommon.h \
+ %D%/stdlib.h \
+ %D%/string.h \
+ %D%/umem.h \
+ %D%/unistd.h \
+ %D%/zone.h
+
+if BUILD_FREEBSD
+libspl_HEADERS += \
+ %D%/os/freebsd/fcntl.h
+endif
+
+
+libspl_rpcdir = $(libspldir)/rpc
+libspl_rpc_HEADERS = \
+ %D%/rpc/xdr.h
+
+
+libspl_sysdir = $(libspldir)/sys
+libspl_sys_HEADERS = \
+ %D%/sys/abd_os.h \
+ %D%/sys/abd_impl_os.h \
+ %D%/sys/acl.h \
+ %D%/sys/acl_impl.h \
+ %D%/sys/asm_linkage.h \
+ %D%/sys/backtrace.h \
+ %D%/sys/callb.h \
+ %D%/sys/cmn_err.h \
+ %D%/sys/cred.h \
+ %D%/sys/debug.h \
+ %D%/sys/dkio.h \
+ %D%/sys/dklabel.h \
+ %D%/sys/feature_tests.h \
+ %D%/sys/inttypes.h \
+ %D%/sys/isa_defs.h \
+ %D%/sys/kmem.h \
+ %D%/sys/kstat.h \
+ %D%/sys/list.h \
+ %D%/sys/list_impl.h \
+ %D%/sys/mhd.h \
+ %D%/sys/mkdev.h \
+ %D%/sys/mod.h \
+ %D%/sys/policy.h \
+ %D%/sys/poll.h \
+ %D%/sys/priv.h \
+ %D%/sys/processor.h \
+ %D%/sys/simd.h \
+ %D%/sys/stack.h \
+ %D%/sys/stdtypes.h \
+ %D%/sys/string.h \
+ %D%/sys/sunddi.h \
+ %D%/sys/systeminfo.h \
+ %D%/sys/time.h \
+ %D%/sys/trace_spl.h \
+ %D%/sys/trace_zfs.h \
+ %D%/sys/tunables.h \
+ %D%/sys/types.h \
+ %D%/sys/types32.h \
+ %D%/sys/uio.h \
+ %D%/sys/vnode.h \
+ %D%/sys/wmsum.h \
+ %D%/sys/zone.h
+
+libspl_ia32dir = $(libspldir)/sys/ia32
+
+if BUILD_LINUX
+libspl_sys_HEADERS += \
+ %D%/os/linux/sys/byteorder.h \
+ %D%/os/linux/sys/errno.h \
+ %D%/os/linux/sys/mnttab.h \
+ %D%/os/linux/sys/mount.h \
+ %D%/os/linux/sys/param.h \
+ %D%/os/linux/sys/stat.h \
+ %D%/os/linux/sys/sysmacros.h \
+ %D%/os/linux/sys/zfs_context_os.h
+
+libspl_ia32_HEADERS = \
+ %D%/os/linux/sys/ia32/asm_linkage.h
+endif
+
+if BUILD_FREEBSD
+libspl_sys_HEADERS += \
+ %D%/os/freebsd/sys/byteorder.h \
+ %D%/os/freebsd/sys/fcntl.h \
+ %D%/os/freebsd/sys/file.h \
+ %D%/os/freebsd/sys/mnttab.h \
+ %D%/os/freebsd/sys/mount.h \
+ %D%/os/freebsd/sys/param.h \
+ %D%/os/freebsd/sys/stat.h \
+ %D%/os/freebsd/sys/sysmacros.h \
+ %D%/os/freebsd/sys/vfs.h \
+ %D%/os/freebsd/sys/zfs_context_os.h
+
+libspl_ia32_HEADERS = \
+ %D%/os/freebsd/sys/ia32/asm_linkage.h
+endif
+
+
+libspl_sys_dktpdir = $(libspl_sysdir)/dktp
+libspl_sys_dktp_HEADERS = \
+ %D%/sys/dktp/fdisk.h
+
diff --git a/sys/contrib/openzfs/lib/libspl/include/assert.h b/sys/contrib/openzfs/lib/libspl/include/assert.h
index 84dbccdc4a12..e704a899e748 100644
--- a/sys/contrib/openzfs/lib/libspl/include/assert.h
+++ b/sys/contrib/openzfs/lib/libspl/include/assert.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -32,13 +33,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <sys/types.h>
+
+/* Workaround for non-Clang compilers */
+#ifndef __has_feature
+#define __has_feature(x) 0
+#endif
+
+/* We need to workaround libspl_set_assert_ok() that we have for zdb */
+#if __has_feature(attribute_analyzer_noreturn) || defined(__COVERITY__)
+#define NORETURN __attribute__((__noreturn__))
+#else
+#define NORETURN
+#endif
/* Set to non-zero to avoid abort()ing on an assertion failure */
-extern int libspl_assert_ok;
+extern void libspl_set_assert_ok(boolean_t val);
/* printf version of libspl_assert */
extern void libspl_assertf(const char *file, const char *func, int line,
- const char *format, ...);
+ const char *format, ...) NORETURN __attribute__((format(printf, 4, 5)));
static inline int
libspl_assert(const char *buf, const char *file, const char *func, int line)
@@ -51,21 +65,34 @@ libspl_assert(const char *buf, const char *file, const char *func, int line)
#undef verify
#endif
+#define PANIC(fmt, a...) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, fmt, ## a)
+
#define VERIFY(cond) \
(void) ((!(cond)) && \
libspl_assert(#cond, __FILE__, __FUNCTION__, __LINE__))
+
+#define VERIFYF(cond, STR, ...) \
+do { \
+ if (!(cond)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "%s " STR, #cond, \
+ __VA_ARGS__); \
+} while (0)
+
#define verify(cond) \
(void) ((!(cond)) && \
libspl_assert(#cond, __FILE__, __FUNCTION__, __LINE__))
#define VERIFY3B(LEFT, OP, RIGHT) \
do { \
- const boolean_t __left = (boolean_t)(LEFT); \
- const boolean_t __right = (boolean_t)(RIGHT); \
+ const boolean_t __left = (boolean_t)!!(LEFT); \
+ const boolean_t __right = (boolean_t)!!(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
- "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
- (u_longlong_t)__left, #OP, (u_longlong_t)__right); \
+ "VERIFY3B(%s, %s, %s) failed " \
+ "(%d %s %d)", #LEFT, #OP, #RIGHT, \
+ __left, #OP, __right); \
} while (0)
#define VERIFY3S(LEFT, OP, RIGHT) \
@@ -74,8 +101,9 @@ do { \
const int64_t __right = (int64_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
- "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
- (u_longlong_t)__left, #OP, (u_longlong_t)__right); \
+ "VERIFY3S(%s, %s, %s) failed " \
+ "(%lld %s 0x%lld)", #LEFT, #OP, #RIGHT, \
+ (longlong_t)__left, #OP, (longlong_t)__right); \
} while (0)
#define VERIFY3U(LEFT, OP, RIGHT) \
@@ -84,7 +112,8 @@ do { \
const uint64_t __right = (uint64_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
- "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
+ "VERIFY3U(%s, %s, %s) failed " \
+ "(%llu %s %llu)", #LEFT, #OP, #RIGHT, \
(u_longlong_t)__left, #OP, (u_longlong_t)__right); \
} while (0)
@@ -94,8 +123,9 @@ do { \
const uintptr_t __right = (uintptr_t)(RIGHT); \
if (!(__left OP __right)) \
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
- "%s %s %s (0x%llx %s 0x%llx)", #LEFT, #OP, #RIGHT, \
- (u_longlong_t)__left, #OP, (u_longlong_t)__right); \
+ "VERIFY3P(%s, %s, %s) failed " \
+ "(%p %s %p)", #LEFT, #OP, #RIGHT, \
+ (void *)__left, #OP, (void *)__right); \
} while (0)
#define VERIFY0(LEFT) \
@@ -103,48 +133,142 @@ do { \
const uint64_t __left = (uint64_t)(LEFT); \
if (!(__left == 0)) \
libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
- "%s == 0 (0x%llx == 0)", #LEFT, \
+ "VERIFY0(%s) failed (%lld)", #LEFT, \
(u_longlong_t)__left); \
} while (0)
+#define VERIFY0P(LEFT) \
+do { \
+ const uintptr_t __left = (uintptr_t)(LEFT); \
+ if (!(__left == 0)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "VERIFY0P(%s) failed (%p)", #LEFT, \
+ (void *)__left); \
+} while (0)
+
+/*
+ * This is just here because cstyle gets upset about #LEFT
+ * on a newline.
+ */
+
+/* BEGIN CSTYLED */
+#define VERIFY3BF(LEFT, OP, RIGHT, STR, ...) \
+do { \
+ const boolean_t __left = (boolean_t)!!(LEFT); \
+ const boolean_t __right = (boolean_t)!!(RIGHT); \
+ if (!(__left OP __right)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "VERIFY3B(%s, %s, %s) failed " \
+ "(%d %s %d) " STR, #LEFT, #OP, #RIGHT, \
+ __left, #OP, __right, \
+ __VA_ARGS__); \
+} while (0)
+
+#define VERIFY3SF(LEFT, OP, RIGHT, STR, ...) \
+do { \
+ const int64_t __left = (int64_t)(LEFT); \
+ const int64_t __right = (int64_t)(RIGHT); \
+ if (!(__left OP __right)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "VERIFY3S(%s, %s, %s) failed " \
+ "(%lld %s %lld) " STR, #LEFT, #OP, #RIGHT, \
+ (longlong_t)__left, #OP, (longlong_t)__right, \
+ __VA_ARGS__); \
+} while (0)
+
+#define VERIFY3UF(LEFT, OP, RIGHT, STR, ...) \
+do { \
+ const uint64_t __left = (uint64_t)(LEFT); \
+ const uint64_t __right = (uint64_t)(RIGHT); \
+ if (!(__left OP __right)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "VERIFY3U(%s, %s, %s) failed " \
+ "(%llu %s %llu) " STR, #LEFT, #OP, #RIGHT, \
+ (u_longlong_t)__left, #OP, (u_longlong_t)__right, \
+ __VA_ARGS__); \
+} while (0)
+
+#define VERIFY3PF(LEFT, OP, RIGHT, STR, ...) \
+do { \
+ const uintptr_t __left = (uintptr_t)(LEFT); \
+ const uintptr_t __right = (uintptr_t)(RIGHT); \
+ if (!(__left OP __right)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "VERIFY3P(%s, %s, %s) failed " \
+ "(%p %s %p) " STR, #LEFT, #OP, #RIGHT, \
+ (void *)__left, #OP, (void *)__right, \
+ __VA_ARGS__); \
+} while (0)
+/* END CSTYLED */
+
+#define VERIFY0F(LEFT, STR, ...) \
+do { \
+ const int64_t __left = (int64_t)(LEFT); \
+ if (!(__left == 0)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "VERIFY0(%s) failed (%lld) " STR, #LEFT, \
+ (longlong_t)__left, __VA_ARGS__); \
+} while (0)
+
+#define VERIFY0PF(LEFT, STR, ...) \
+do { \
+ const uintptr_t __left = (uintptr_t)(LEFT); \
+ if (!(__left == 0)) \
+ libspl_assertf(__FILE__, __FUNCTION__, __LINE__, \
+ "VERIFY0P(%s) failed (%p) " STR, #LEFT, \
+ (void *)__left, __VA_ARGS__); \
+} while (0)
+
#ifdef assert
#undef assert
#endif
-/* Compile time assert */
-#define CTASSERT_GLOBAL(x) _CTASSERT(x, __LINE__)
-#define CTASSERT(x) { _CTASSERT(x, __LINE__); }
-#define _CTASSERT(x, y) __CTASSERT(x, y)
-#define __CTASSERT(x, y) \
- typedef char __attribute__((unused)) \
- __compile_time_assertion__ ## y[(x) ? 1 : -1]
-
#ifdef NDEBUG
-#define ASSERT3B(x, y, z) ((void)0)
-#define ASSERT3S(x, y, z) ((void)0)
-#define ASSERT3U(x, y, z) ((void)0)
-#define ASSERT3P(x, y, z) ((void)0)
-#define ASSERT0(x) ((void)0)
-#define ASSERT(x) ((void)0)
-#define assert(x) ((void)0)
-#define IMPLY(A, B) ((void)0)
-#define EQUIV(A, B) ((void)0)
+#define ASSERT3B(x, y, z) \
+ ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z)))
+#define ASSERT3S(x, y, z) \
+ ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z)))
+#define ASSERT3U(x, y, z) \
+ ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z)))
+#define ASSERT3P(x, y, z) \
+ ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z)))
+#define ASSERT0(x) ((void) sizeof ((uintptr_t)(x)))
+#define ASSERT0P(x) ((void) sizeof ((uintptr_t)(x)))
+#define ASSERT3BF(x, y, z, str, ...) ASSERT3B(x, y, z)
+#define ASSERT3SF(x, y, z, str, ...) ASSERT3S(x, y, z)
+#define ASSERT3UF(x, y, z, str, ...) ASSERT3U(x, y, z)
+#define ASSERT3PF(x, y, z, str, ...) ASSERT3P(x, y, z)
+#define ASSERT0P(x) ((void) sizeof ((uintptr_t)(x)))
+#define ASSERT0PF(x, str, ...) ASSERT0P(x)
+#define ASSERT0F(x, str, ...) ASSERT0(x)
+#define ASSERT(x) ((void) sizeof ((uintptr_t)(x)))
+#define ASSERTF(x, str, ...) ASSERT(x)
+#define assert(x) ((void) sizeof ((uintptr_t)(x)))
+#define IMPLY(A, B) \
+ ((void) sizeof ((uintptr_t)(A)), (void) sizeof ((uintptr_t)(B)))
+#define EQUIV(A, B) \
+ ((void) sizeof ((uintptr_t)(A)), (void) sizeof ((uintptr_t)(B)))
#else
#define ASSERT3B VERIFY3B
#define ASSERT3S VERIFY3S
#define ASSERT3U VERIFY3U
#define ASSERT3P VERIFY3P
#define ASSERT0 VERIFY0
+#define ASSERT0P VERIFY0P
+#define ASSERT3BF VERIFY3BF
+#define ASSERT3SF VERIFY3SF
+#define ASSERT3UF VERIFY3UF
+#define ASSERT3PF VERIFY3PF
+#define ASSERT0PF VERIFY0PF
+#define ASSERT0F VERIFY0F
#define ASSERT VERIFY
+#define ASSERTF VERIFYF
#define assert VERIFY
#define IMPLY(A, B) \
((void)(((!(A)) || (B)) || \
libspl_assert("(" #A ") implies (" #B ")", \
__FILE__, __FUNCTION__, __LINE__)))
-#define EQUIV(A, B) \
- ((void)((!!(A) == !!(B)) || \
- libspl_assert("(" #A ") is equivalent to (" #B ")", \
- __FILE__, __FUNCTION__, __LINE__)))
+#define EQUIV(A, B) VERIFY3B(A, ==, B)
#endif /* NDEBUG */
diff --git a/sys/contrib/openzfs/lib/libspl/include/atomic.h b/sys/contrib/openzfs/lib/libspl/include/atomic.h
index 8dd1d654a486..cc6f2e2ce988 100644
--- a/sys/contrib/openzfs/lib/libspl/include/atomic.h
+++ b/sys/contrib/openzfs/lib/libspl/include/atomic.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -314,6 +315,13 @@ extern void membar_enter(void);
extern void membar_exit(void);
/*
+ * Make all stores and loads emitted prior to the the barrier complete before
+ * crossing it, while also making sure stores and loads emitted after the
+ * barrier only start being executed after crossing it.
+ */
+extern void membar_sync(void);
+
+/*
* Arrange that all stores issued before this point in the code reach
* global visibility before any stores that follow; useful in producer
* modules that update a data item, then set a flag that it is available.
diff --git a/sys/contrib/openzfs/lib/libspl/include/ia32/Makefile.am b/sys/contrib/openzfs/lib/libspl/include/ia32/Makefile.am
deleted file mode 100644
index 081839c48c8f..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/ia32/Makefile.am
+++ /dev/null
@@ -1 +0,0 @@
-SUBDIRS = sys
diff --git a/sys/contrib/openzfs/lib/libspl/include/ia32/sys/Makefile.am b/sys/contrib/openzfs/lib/libspl/include/ia32/sys/Makefile.am
deleted file mode 100644
index 683288460cdf..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/ia32/sys/Makefile.am
+++ /dev/null
@@ -1,3 +0,0 @@
-libspldir = $(includedir)/libspl/ia32/sys
-libspl_HEADERS = \
- asm_linkage.h
diff --git a/sys/contrib/openzfs/lib/libspl/include/libdevinfo.h b/sys/contrib/openzfs/lib/libspl/include/libdevinfo.h
deleted file mode 100644
index be1d291f4051..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/libdevinfo.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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 2008 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _LIBSPL_LIBDEVINFO_H
-#define _LIBSPL_LIBDEVINFO_H
-
-#endif /* _LIBSPL_LIBDEVINFO_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/libgen.h b/sys/contrib/openzfs/lib/libspl/include/libgen.h
index c46d7454e49f..18d3e1d891b8 100644
--- a/sys/contrib/openzfs/lib/libspl/include/libgen.h
+++ b/sys/contrib/openzfs/lib/libspl/include/libgen.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/libshare.h b/sys/contrib/openzfs/lib/libspl/include/libshare.h
index 5d06b163a3ba..bfa78bffd461 100644
--- a/sys/contrib/openzfs/lib/libspl/include/libshare.h
+++ b/sys/contrib/openzfs/lib/libspl/include/libshare.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -22,33 +23,33 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
- * Copyright (c) 2019, 2020 by Delphix. All rights reserved.
+ * Copyright (c) 2019, 2022 by Delphix. All rights reserved.
*/
#ifndef _LIBSPL_LIBSHARE_H
#define _LIBSPL_LIBSHARE_H extern __attribute__((visibility("default")))
-/* API Initialization */
-#define SA_INIT_SHARE_API 0x0001 /* init share specific interface */
-#define SA_INIT_CONTROL_API 0x0002 /* init control specific interface */
+#include <sys/types.h>
/*
* defined error values
*/
-
#define SA_OK 0
-#define SA_NO_SUCH_PATH 1 /* provided path doesn't exist */
+#define SA_SYSTEM_ERR 7 /* system error, use errno */
+#define SA_SYNTAX_ERR 8 /* syntax error on command line */
#define SA_NO_MEMORY 2 /* no memory for data structures */
+#define SA_INVALID_PROTOCOL 13 /* specified protocol not valid */
+#define SA_NOT_SUPPORTED 21 /* operation not supported for proto */
+
+/* The following errors are never returned by libshare */
+#define SA_NO_SUCH_PATH 1 /* provided path doesn't exist */
#define SA_DUPLICATE_NAME 3 /* object name is already in use */
#define SA_BAD_PATH 4 /* not a full path */
#define SA_NO_SUCH_GROUP 5 /* group is not defined */
#define SA_CONFIG_ERR 6 /* system configuration error */
-#define SA_SYSTEM_ERR 7 /* system error, use errno */
-#define SA_SYNTAX_ERR 8 /* syntax error on command line */
#define SA_NO_PERMISSION 9 /* no permission for operation */
#define SA_BUSY 10 /* resource is busy */
#define SA_NO_SUCH_PROP 11 /* property doesn't exist */
#define SA_INVALID_NAME 12 /* name of object is invalid */
-#define SA_INVALID_PROTOCOL 13 /* specified protocol not valid */
#define SA_NOT_ALLOWED 14 /* operation not allowed */
#define SA_BAD_VALUE 15 /* bad value for property */
#define SA_INVALID_SECURITY 16 /* invalid security type */
@@ -56,7 +57,6 @@
#define SA_VALUE_CONFLICT 18 /* property value conflict */
#define SA_NOT_IMPLEMENTED 19 /* plugin interface not implemented */
#define SA_INVALID_PATH 20 /* path is sub-dir of existing share */
-#define SA_NOT_SUPPORTED 21 /* operation not supported for proto */
#define SA_PROP_SHARE_ONLY 22 /* property valid on share only */
#define SA_NOT_SHARED 23 /* path is not shared */
#define SA_NO_SUCH_RESOURCE 24 /* resource not found */
@@ -71,16 +71,27 @@
#define SA_SHARE_EXISTS 33 /* path or file is already shared */
/* initialization */
-_LIBSPL_LIBSHARE_H char *sa_errorstr(int);
+_LIBSPL_LIBSHARE_H const char *sa_errorstr(int);
+
+/* available protocols */
+enum sa_protocol {
+ SA_PROTOCOL_NFS,
+ SA_PROTOCOL_SMB, /* ABI: add before _COUNT */
+ SA_PROTOCOL_COUNT,
+};
+
+/* lower-case */
+_LIBSPL_LIBSHARE_H const char *const sa_protocol_names[SA_PROTOCOL_COUNT];
/* share control */
_LIBSPL_LIBSHARE_H int sa_enable_share(const char *, const char *, const char *,
- char *);
-_LIBSPL_LIBSHARE_H int sa_disable_share(const char *, char *);
-_LIBSPL_LIBSHARE_H boolean_t sa_is_shared(const char *, char *);
-_LIBSPL_LIBSHARE_H void sa_commit_shares(const char *);
+ enum sa_protocol);
+_LIBSPL_LIBSHARE_H int sa_disable_share(const char *, enum sa_protocol);
+_LIBSPL_LIBSHARE_H boolean_t sa_is_shared(const char *, enum sa_protocol);
+_LIBSPL_LIBSHARE_H void sa_commit_shares(enum sa_protocol);
+_LIBSPL_LIBSHARE_H void sa_truncate_shares(enum sa_protocol);
/* protocol specific interfaces */
-_LIBSPL_LIBSHARE_H int sa_validate_shareopts(char *, char *);
+_LIBSPL_LIBSHARE_H int sa_validate_shareopts(const char *, enum sa_protocol);
#endif /* _LIBSPL_LIBSHARE_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/locale.h b/sys/contrib/openzfs/lib/libspl/include/locale.h
deleted file mode 100644
index 6c74df72072e..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/locale.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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 2008 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#include_next <locale.h>
-
-#ifndef _LIBSPL_LOCALE_H
-#define _LIBSPL_LOCALE_H
-
-#include <time.h>
-#include <sys/time.h>
-
-#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/Makefile.am b/sys/contrib/openzfs/lib/libspl/include/os/Makefile.am
deleted file mode 100644
index 7b362e02ad59..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/os/Makefile.am
+++ /dev/null
@@ -1,7 +0,0 @@
-if BUILD_FREEBSD
-SUBDIRS = freebsd
-endif
-
-if BUILD_LINUX
-SUBDIRS = linux
-endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/Makefile.am b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/Makefile.am
deleted file mode 100644
index f06325ee3e4e..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/Makefile.am
+++ /dev/null
@@ -1,5 +0,0 @@
-SUBDIRS = sys
-
-libspldir = $(includedir)/libspl
-libspl_HEADERS = \
- fcntl.h
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/fcntl.h b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/fcntl.h
index 26d571ad8926..1222b3d7a6b5 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/fcntl.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/fcntl.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2021 iXsystems, Inc.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/Makefile.am b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/Makefile.am
deleted file mode 100644
index 7a854608079c..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/Makefile.am
+++ /dev/null
@@ -1,12 +0,0 @@
-libspldir = $(includedir)/libspl/sys
-libspl_HEADERS = \
- byteorder.h \
- fcntl.h \
- file.h \
- mnttab.h \
- mount.h \
- param.h \
- stat.h \
- sysmacros.h \
- vfs.h \
- zfs_context_os.h
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/byteorder.h b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/byteorder.h
index cd692d3616e0..116ce991b89b 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/byteorder.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/byteorder.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -43,7 +44,7 @@
#include <sys/endian.h>
#include <netinet/in.h>
#include <sys/isa_defs.h>
-#include <sys/int_types.h>
+#include <inttypes.h>
#if defined(__GNUC__) && defined(_ASM_INLINES) && \
(defined(__i386) || defined(__amd64))
@@ -59,6 +60,18 @@ extern "C" {
*/
#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
+#ifdef __COVERITY__
+/*
+ * Coverity's taint warnings from byteswapping are false positives for us.
+ * Suppress them by hiding byteswapping from Coverity.
+ */
+#define BSWAP_8(x) ((x) & 0xff)
+#define BSWAP_16(x) ((x) & 0xffff)
+#define BSWAP_32(x) ((x) & 0xffffffff)
+#define BSWAP_64(x) (x)
+
+#else /* __COVERITY__ */
+
/*
* Macros to reverse byte order
*/
@@ -67,6 +80,8 @@ extern "C" {
#define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16))
#define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))
+#endif /* __COVERITY__ */
+
#define BMASK_8(x) ((x) & 0xff)
#define BMASK_16(x) ((x) & 0xffff)
#define BMASK_32(x) ((x) & 0xffffffff)
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/fcntl.h b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/fcntl.h
index c8a37a193850..64dd4d7ebe45 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/fcntl.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/fcntl.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2021 iXsystems, Inc.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/file.h b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/file.h
index 27fd2888f326..75c3b23860bb 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/file.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/file.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -29,14 +30,6 @@
#include_next <sys/file.h>
-#define FCREAT O_CREAT
-#define FTRUNC O_TRUNC
-#define FSYNC O_SYNC
-#define FDSYNC O_DSYNC
-#define FEXCL O_EXCL
-
-#define FNODSYNC 0x10000 /* fsync pseudo flag */
-#define FNOFOLLOW 0x20000 /* don't follow symlinks */
#define FIGNORECASE 0x80000 /* request case-insensitive lookups */
#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/ia32/asm_linkage.h b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/ia32/asm_linkage.h
new file mode 100644
index 000000000000..f9c34d282d46
--- /dev/null
+++ b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/ia32/asm_linkage.h
@@ -0,0 +1,185 @@
+// SPDX-License-Identifier: CDDL-1.0
+/*
+ * 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 https://opensource.org/licenses/CDDL-1.0.
+ * 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 2008 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _IA32_SYS_ASM_LINKAGE_H
+#define _IA32_SYS_ASM_LINKAGE_H
+
+#if defined(__linux__) && defined(CONFIG_SLS)
+#define RET ret; int3
+#else
+#define RET ret
+#endif
+
+/* Tell compiler to call assembler like Unix */
+#undef ASMABI
+#define ASMABI __attribute__((sysv_abi))
+
+#define ENDBR
+
+#define SECTION_TEXT .text
+#define SECTION_STATIC .section .rodata
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef _ASM /* The remainder of this file is only for assembly files */
+
+/*
+ * make annoying differences in assembler syntax go away
+ */
+
+/*
+ * D16 and A16 are used to insert instructions prefixes; the
+ * macros help the assembler code be slightly more portable.
+ */
+#if !defined(__GNUC_AS__)
+/*
+ * /usr/ccs/bin/as prefixes are parsed as separate instructions
+ */
+#define D16 data16;
+#define A16 addr16;
+
+/*
+ * (There are some weird constructs in constant expressions)
+ */
+#define _CONST(const) [const]
+#define _BITNOT(const) -1!_CONST(const)
+#define _MUL(a, b) _CONST(a \* b)
+
+#else
+/*
+ * Why not use the 'data16' and 'addr16' prefixes .. well, the
+ * assembler doesn't quite believe in real mode, and thus argues with
+ * us about what we're trying to do.
+ */
+#define D16 .byte 0x66;
+#define A16 .byte 0x67;
+
+#define _CONST(const) (const)
+#define _BITNOT(const) ~_CONST(const)
+#define _MUL(a, b) _CONST(a * b)
+
+#endif
+
+/*
+ * C pointers are different sizes between i386 and amd64.
+ * These constants can be used to compute offsets into pointer arrays.
+ */
+#if defined(__amd64)
+#define CLONGSHIFT 3
+#define CLONGSIZE 8
+#define CLONGMASK 7
+#elif defined(__i386)
+#define CLONGSHIFT 2
+#define CLONGSIZE 4
+#define CLONGMASK 3
+#endif
+
+/*
+ * Since we know we're either ILP32 or LP64 ..
+ */
+#define CPTRSHIFT CLONGSHIFT
+#define CPTRSIZE CLONGSIZE
+#define CPTRMASK CLONGMASK
+
+#if CPTRSIZE != (1 << CPTRSHIFT) || CLONGSIZE != (1 << CLONGSHIFT)
+#error "inconsistent shift constants"
+#endif
+
+#if CPTRMASK != (CPTRSIZE - 1) || CLONGMASK != (CLONGSIZE - 1)
+#error "inconsistent mask constants"
+#endif
+
+#define ASM_ENTRY_ALIGN 16
+
+/*
+ * SSE register alignment and save areas
+ */
+
+#define XMM_SIZE 16
+#define XMM_ALIGN 16
+
+/*
+ * ENTRY provides the standard procedure entry code and an easy way to
+ * insert the calls to mcount for profiling. ENTRY_NP is identical, but
+ * never calls mcount.
+ */
+#define ENTRY(x) \
+ .text; \
+ .balign ASM_ENTRY_ALIGN; \
+ .globl x; \
+x: MCOUNT(x)
+
+#define ENTRY_NP(x) \
+ .text; \
+ .balign ASM_ENTRY_ALIGN; \
+ .globl x; \
+x:
+
+#define ENTRY_ALIGN(x, a) \
+ .text; \
+ .balign a; \
+ .globl x; \
+x:
+
+#define FUNCTION(x) \
+ .type x, @function; \
+x:
+
+/*
+ * ENTRY2 is identical to ENTRY but provides two labels for the entry point.
+ */
+#define ENTRY2(x, y) \
+ .text; \
+ .balign ASM_ENTRY_ALIGN; \
+ .globl x, y; \
+x:; \
+y: MCOUNT(x)
+
+#define ENTRY_NP2(x, y) \
+ .text; \
+ .balign ASM_ENTRY_ALIGN; \
+ .globl x, y; \
+x:; \
+y:
+
+
+/*
+ * SET_SIZE trails a function and set the size for the ELF symbol table.
+ */
+#define SET_SIZE(x)
+
+#define SET_OBJ(x)
+
+#endif /* _ASM */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _IA32_SYS_ASM_LINKAGE_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/mnttab.h b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/mnttab.h
index c08349bdf9bd..e520bf5ef3bb 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/mnttab.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/mnttab.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -79,7 +80,7 @@ extern int _sol_getmntent(FILE *fp, struct mnttab *mp);
extern int getextmntent(const char *path, struct extmnttab *entry,
struct stat64 *statbuf);
extern void statfs2mnttab(struct statfs *sfs, struct mnttab *mp);
-char *hasmntopt(struct mnttab *mnt, char *opt);
-int getmntent(FILE *fp, struct mnttab *mp);
+extern char *hasmntopt(struct mnttab *mnt, const char *opt);
+extern int getmntent(FILE *fp, struct mnttab *mp);
#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/mount.h b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/mount.h
index e99518571270..231c250d3410 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/mount.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/mount.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/param.h b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/param.h
index cb5260ea3d7e..55fa1de0e8ff 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/param.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/param.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -57,6 +58,8 @@
extern size_t spl_pagesize(void);
#define PAGESIZE (spl_pagesize())
+#ifndef HAVE_EXECVPE
extern int execvpe(const char *name, char * const argv[], char * const envp[]);
+#endif
#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/stat.h b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/stat.h
index 38c684d62a1b..666f2ec6d760 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/stat.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/stat.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -76,8 +77,12 @@ fstat64_blk(int fd, struct stat64 *st)
/*
* Only Intel-based Macs have a separate stat64; Arm-based Macs are like
* FreeBSD and have a full 64-bit stat from the start.
+ *
+ * On Linux, musl libc is full 64-bit too and has deprecated its own version
+ * of these defines since version 1.2.4.
*/
-#if defined(__APPLE__) && !(defined(__i386__) || defined(__x86_64__))
+#if (defined(__APPLE__) && !(defined(__i386__) || defined(__x86_64__))) || \
+ (defined(__linux__) && !defined(__GLIBC__))
#define stat64 stat
#define fstat64 fstat
#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/vfs.h b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/vfs.h
index 55eb3c23b22e..228ec5905240 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/vfs.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/vfs.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2020 iXsystems, Inc.
* All rights reserved.
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/zfs_context_os.h b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/zfs_context_os.h
index b9bf487c2aef..1dd036d02ac6 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/zfs_context_os.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/zfs_context_os.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2020 iXsystems, Inc.
* All rights reserved.
@@ -30,6 +31,5 @@
#define ZFS_CONTEXT_OS_H_
#define HAVE_LARGE_STACKS 1
-#define ZFS_EXPORTS_PATH "/etc/zfs/exports"
#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/linux/Makefile.am b/sys/contrib/openzfs/lib/libspl/include/os/linux/Makefile.am
deleted file mode 100644
index 081839c48c8f..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/os/linux/Makefile.am
+++ /dev/null
@@ -1 +0,0 @@
-SUBDIRS = sys
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/Makefile.am b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/Makefile.am
deleted file mode 100644
index 1ec07a76d354..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/Makefile.am
+++ /dev/null
@@ -1,10 +0,0 @@
-libspldir = $(includedir)/libspl/sys
-libspl_HEADERS = \
- byteorder.h \
- errno.h \
- mnttab.h \
- mount.h \
- param.h \
- stat.h \
- sysmacros.h \
- zfs_context_os.h
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/byteorder.h b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/byteorder.h
index d5ee3e26f5a5..4fba62addd3b 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/byteorder.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/byteorder.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -46,7 +47,7 @@
#endif
#include <sys/isa_defs.h>
-#include <sys/int_types.h>
+#include <inttypes.h>
#ifdef __cplusplus
extern "C" {
@@ -90,6 +91,18 @@ extern in_port_t ntohs(in_port_t);
#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
+#ifdef __COVERITY__
+/*
+ * Coverity's taint warnings from byteswapping are false positives for us.
+ * Suppress them by hiding byteswapping from Coverity.
+ */
+#define BSWAP_8(x) ((x) & 0xff)
+#define BSWAP_16(x) ((x) & 0xffff)
+#define BSWAP_32(x) ((x) & 0xffffffff)
+#define BSWAP_64(x) (x)
+
+#else /* __COVERITY__ */
+
/*
* Macros to reverse byte order
*/
@@ -98,6 +111,8 @@ extern in_port_t ntohs(in_port_t);
#define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16))
#define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))
+#endif /* __COVERITY__ */
+
#define BMASK_8(x) ((x) & 0xff)
#define BMASK_16(x) ((x) & 0xffff)
#define BMASK_32(x) ((x) & 0xffffffff)
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/errno.h b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/errno.h
index 30d20ab895c5..dd0120100a3d 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/errno.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/errno.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/ia32/sys/asm_linkage.h b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/ia32/asm_linkage.h
index 61c4d1a26977..e1d25346b13e 100644
--- a/sys/contrib/openzfs/lib/libspl/include/ia32/sys/asm_linkage.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/ia32/asm_linkage.h
@@ -1,13 +1,13 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -19,14 +19,48 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _IA32_SYS_ASM_LINKAGE_H
#define _IA32_SYS_ASM_LINKAGE_H
+#if defined(_KERNEL) && defined(__linux__)
+#include <linux/linkage.h>
+#endif
+
+#ifndef ENDBR
+#if defined(__ELF__) && defined(__CET__) && defined(__has_include)
+/* CSTYLED */
+#if __has_include(<cet.h>)
+
+#include <cet.h>
+
+#ifdef _CET_ENDBR
+#define ENDBR _CET_ENDBR
+#endif /* _CET_ENDBR */
+
+#endif /* <cet.h> */
+#endif /* __ELF__ && __CET__ && __has_include */
+#endif /* !ENDBR */
+
+#ifndef ENDBR
+#define ENDBR
+#endif
+#ifndef RET
+#define RET ret
+#endif
+
+/* You can set to nothing on Unix platforms */
+#undef ASMABI
+#define ASMABI __attribute__((sysv_abi))
+
+#define SECTION_TEXT .text
+#define SECTION_STATIC .section .rodata
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -108,190 +142,66 @@ extern "C" {
#define XMM_SIZE 16
#define XMM_ALIGN 16
-#if defined(__amd64)
-
-#define SAVE_XMM_PROLOG(sreg, nreg) \
- subq $_CONST(_MUL(XMM_SIZE, nreg)), %rsp; \
- movq %rsp, sreg
-
-#define RSTOR_XMM_EPILOG(sreg, nreg) \
- addq $_CONST(_MUL(XMM_SIZE, nreg)), %rsp
-
-#elif defined(__i386)
-
-#define SAVE_XMM_PROLOG(sreg, nreg) \
- subl $_CONST(_MUL(XMM_SIZE, nreg) + XMM_ALIGN), %esp; \
- movl %esp, sreg; \
- addl $XMM_ALIGN, sreg; \
- andl $_BITNOT(XMM_ALIGN-1), sreg
-
-#define RSTOR_XMM_EPILOG(sreg, nreg) \
- addl $_CONST(_MUL(XMM_SIZE, nreg) + XMM_ALIGN), %esp;
-
-#endif /* __i386 */
-
-/*
- * profiling causes definitions of the MCOUNT and RTMCOUNT
- * particular to the type
- */
-#ifdef GPROF
-
-#define MCOUNT(x) \
- pushl %ebp; \
- movl %esp, %ebp; \
- call _mcount; \
- popl %ebp
-
-#endif /* GPROF */
-
-#ifdef PROF
-
-#define MCOUNT(x) \
-/* CSTYLED */ \
- .lcomm .L_/**/x/**/1, 4, 4; \
- pushl %ebp; \
- movl %esp, %ebp; \
-/* CSTYLED */ \
- movl $.L_/**/x/**/1, %edx; \
- call _mcount; \
- popl %ebp
-
-#endif /* PROF */
-
-/*
- * if we are not profiling, MCOUNT should be defined to nothing
- */
-#if !defined(PROF) && !defined(GPROF)
-#define MCOUNT(x)
-#endif /* !defined(PROF) && !defined(GPROF) */
-
-#define RTMCOUNT(x) MCOUNT(x)
-
-/*
- * Macro to define weak symbol aliases. These are similar to the ANSI-C
- * #pragma weak name = _name
- * except a compiler can determine type. The assembler must be told. Hence,
- * the second parameter must be the type of the symbol (i.e.: function,...)
- */
-#define ANSI_PRAGMA_WEAK(sym, stype) \
- .weak sym; \
- .type sym, @stype; \
-/* CSTYLED */ \
-sym = _/**/sym
-
-/*
- * Like ANSI_PRAGMA_WEAK(), but for unrelated names, as in:
- * #pragma weak sym1 = sym2
- */
-#define ANSI_PRAGMA_WEAK2(sym1, sym2, stype) \
- .weak sym1; \
- .type sym1, @stype; \
-sym1 = sym2
-
/*
* ENTRY provides the standard procedure entry code and an easy way to
* insert the calls to mcount for profiling. ENTRY_NP is identical, but
* never calls mcount.
*/
+#undef ENTRY
#define ENTRY(x) \
.text; \
- .align ASM_ENTRY_ALIGN; \
+ .balign ASM_ENTRY_ALIGN; \
.globl x; \
.type x, @function; \
x: MCOUNT(x)
#define ENTRY_NP(x) \
.text; \
- .align ASM_ENTRY_ALIGN; \
+ .balign ASM_ENTRY_ALIGN; \
.globl x; \
.type x, @function; \
x:
-#define RTENTRY(x) \
+#define ENTRY_ALIGN(x, a) \
.text; \
- .align ASM_ENTRY_ALIGN; \
+ .balign a; \
.globl x; \
.type x, @function; \
-x: RTMCOUNT(x)
+x:
+
+#define FUNCTION(x) \
+ .type x, @function; \
+x:
/*
* ENTRY2 is identical to ENTRY but provides two labels for the entry point.
*/
#define ENTRY2(x, y) \
- .text; \
- .align ASM_ENTRY_ALIGN; \
+ .text; \
+ .balign ASM_ENTRY_ALIGN; \
.globl x, y; \
.type x, @function; \
.type y, @function; \
-/* CSTYLED */ \
-x: ; \
+x:; \
y: MCOUNT(x)
#define ENTRY_NP2(x, y) \
.text; \
- .align ASM_ENTRY_ALIGN; \
+ .balign ASM_ENTRY_ALIGN; \
.globl x, y; \
.type x, @function; \
.type y, @function; \
-/* CSTYLED */ \
-x: ; \
+x:; \
y:
/*
- * ALTENTRY provides for additional entry points.
- */
-#define ALTENTRY(x) \
- .globl x; \
- .type x, @function; \
-x:
-
-/*
- * DGDEF and DGDEF2 provide global data declarations.
- *
- * DGDEF provides a word aligned word of storage.
- *
- * DGDEF2 allocates "sz" bytes of storage with **NO** alignment. This
- * implies this macro is best used for byte arrays.
- *
- * DGDEF3 allocates "sz" bytes of storage with "algn" alignment.
- */
-#define DGDEF2(name, sz) \
- .data; \
- .globl name; \
- .type name, @object; \
- .size name, sz; \
-name:
-
-#define DGDEF3(name, sz, algn) \
- .data; \
- .align algn; \
- .globl name; \
- .type name, @object; \
- .size name, sz; \
-name:
-
-#define DGDEF(name) DGDEF3(name, 4, 4)
-
-/*
* SET_SIZE trails a function and set the size for the ELF symbol table.
*/
#define SET_SIZE(x) \
.size x, [.-x]
-/*
- * NWORD provides native word value.
- */
-#if defined(__amd64)
-
-/*CSTYLED*/
-#define NWORD quad
-
-#elif defined(__i386)
-
-#define NWORD long
-
-#endif /* __i386 */
+#define SET_OBJ(x) .type x, @object
#endif /* _ASM */
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/mnttab.h b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/mnttab.h
index 1957293d5c69..c1b7f3b389c0 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/mnttab.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/mnttab.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -74,7 +75,7 @@ extern int getmntany(FILE *fp, struct mnttab *mp, struct mnttab *mpref);
extern int _sol_getmntent(FILE *fp, struct mnttab *mp);
extern int getextmntent(const char *path, struct extmnttab *mp,
struct stat64 *statbuf);
-static inline char *_sol_hasmntopt(struct mnttab *mnt, char *opt)
+static inline char *_sol_hasmntopt(struct mnttab *mnt, const char *opt)
{
struct mntent mnt_new;
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/mount.h b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/mount.h
index d7c6f750e23d..c4a291f5c22d 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/mount.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/mount.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/param.h b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/param.h
index 26335187fdca..814f8feaf37f 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/param.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/param.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/stat.h b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/stat.h
index 3e8d27e4c19a..13cc0b46ac93 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/stat.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/stat.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -30,6 +31,11 @@
#include <sys/mount.h> /* for BLKGETSIZE64 */
+#ifdef HAVE_STATX
+#include <fcntl.h>
+#include <sys/stat.h>
+#endif
+
/*
* Emulate Solaris' behavior of returning the block device size in fstat64().
*/
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/sysmacros.h b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/sysmacros.h
index 31f347c6fd5a..66e0da6b5afe 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/sysmacros.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/sysmacros.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -52,7 +53,8 @@
/*
* Compatibility macros/typedefs needed for Solaris -> Linux port
*/
-#define P2ALIGN(x, align) ((x) & -(align))
+// Deprecated. Use P2ALIGN_TYPED instead.
+// #define P2ALIGN(x, align) ((x) & -(align))
#define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
#define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1)
#define P2BOUNDARY(off, len, align) \
diff --git a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/zfs_context_os.h b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/zfs_context_os.h
index 81ced5207749..bbfb4d17e06d 100644
--- a/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/zfs_context_os.h
+++ b/sys/contrib/openzfs/lib/libspl/include/os/linux/sys/zfs_context_os.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/rpc/Makefile.am b/sys/contrib/openzfs/lib/libspl/include/rpc/Makefile.am
deleted file mode 100644
index 7fe1d7fea4d7..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/rpc/Makefile.am
+++ /dev/null
@@ -1,3 +0,0 @@
-libspldir = $(includedir)/libspl/rpc
-libspl_HEADERS = \
- xdr.h
diff --git a/sys/contrib/openzfs/lib/libspl/include/rpc/xdr.h b/sys/contrib/openzfs/lib/libspl/include/rpc/xdr.h
index 51d71f693bbf..85f718c275a5 100644
--- a/sys/contrib/openzfs/lib/libspl/include/rpc/xdr.h
+++ b/sys/contrib/openzfs/lib/libspl/include/rpc/xdr.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/statcommon.h b/sys/contrib/openzfs/lib/libspl/include/statcommon.h
index 1f376f5c7c24..21c64ed4a9f8 100644
--- a/sys/contrib/openzfs/lib/libspl/include/statcommon.h
+++ b/sys/contrib/openzfs/lib/libspl/include/statcommon.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -37,5 +38,9 @@
/* Print a timestamp in either Unix or standard format. */
void print_timestamp(uint_t);
+/* Return timestamp in either Unix or standard format in provided buffer */
+void get_timestamp(uint_t, char *, int);
+/* convert time_t to standard format */
+void format_timestamp(time_t, char *, int);
#endif /* _STATCOMMON_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/stdio.h b/sys/contrib/openzfs/lib/libspl/include/stdio.h
deleted file mode 100644
index 6152b09f1a97..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/stdio.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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 2008 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#include_next <stdio.h>
-
-#ifndef _LIBSPL_STDIO_H
-#define _LIBSPL_STDIO_H
-
-#define enable_extended_FILE_stdio(fd, sig) ((void) 0)
-
-#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/stdlib.h b/sys/contrib/openzfs/lib/libspl/include/stdlib.h
index a4ce4f781fc5..f381f21345fa 100644
--- a/sys/contrib/openzfs/lib/libspl/include/stdlib.h
+++ b/sys/contrib/openzfs/lib/libspl/include/stdlib.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/string.h b/sys/contrib/openzfs/lib/libspl/include/string.h
index a7d40fa61943..52f268b1d931 100644
--- a/sys/contrib/openzfs/lib/libspl/include/string.h
+++ b/sys/contrib/openzfs/lib/libspl/include/string.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/Makefile.am b/sys/contrib/openzfs/lib/libspl/include/sys/Makefile.am
deleted file mode 100644
index 6816a012533f..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/sys/Makefile.am
+++ /dev/null
@@ -1,48 +0,0 @@
-SUBDIRS = dktp
-
-libspldir = $(includedir)/libspl/sys
-libspl_HEADERS = \
- acl.h \
- acl_impl.h \
- callb.h \
- cmn_err.h \
- cred.h \
- debug.h \
- dkio.h \
- dklabel.h \
- feature_tests.h \
- int_limits.h \
- int_types.h \
- inttypes.h \
- isa_defs.h \
- kmem.h \
- kstat.h \
- list.h \
- list_impl.h \
- mhd.h \
- mkdev.h \
- policy.h \
- poll.h \
- priv.h \
- processor.h \
- sha2.h \
- simd.h \
- stack.h \
- stdtypes.h \
- strings.h \
- stropts.h \
- sunddi.h \
- systeminfo.h \
- time.h \
- trace_spl.h \
- trace_zfs.h \
- types32.h \
- types.h \
- tzfile.h \
- uio.h \
- va_list.h \
- varargs.h \
- vnode.h \
- vtoc.h \
- wmsum.h \
- zone.h
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/stropts.h b/sys/contrib/openzfs/lib/libspl/include/sys/abd_impl_os.h
index 08c2e79bc53c..dee95652c71c 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/stropts.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/abd_impl_os.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -19,11 +20,23 @@
* CDDL HEADER END
*/
/*
- * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2014 by Chunwei Chen. All rights reserved.
+ * Copyright (c) 2016, 2019 by Delphix. All rights reserved.
+ * Copyright (c) 2023, 2024, Klara Inc.
*/
-#ifndef _LIBSPL_SYS_STROPTS_H
-#define _LIBSPL_SYS_STROPTS_H
+#ifndef _ABD_IMPL_OS_H
+#define _ABD_IMPL_OS_H
-#endif /* _LIBSPL_SYS_STROPTS_H */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define abd_enter_critical(flags) ((void)0)
+#define abd_exit_critical(flags) ((void)0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ABD_IMPL_OS_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/stropts.h b/sys/contrib/openzfs/lib/libspl/include/sys/abd_os.h
index 37acd4052b0b..80ce46e99a8e 100644
--- a/sys/contrib/openzfs/lib/libspl/include/stropts.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/abd_os.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -18,8 +19,30 @@
*
* CDDL HEADER END
*/
+/*
+ * Copyright (c) 2014 by Chunwei Chen. All rights reserved.
+ * Copyright (c) 2016, 2019 by Delphix. All rights reserved.
+ */
+
+#ifndef _ABD_OS_H
+#define _ABD_OS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct abd_scatter {
+ uint_t abd_offset;
+ uint_t abd_iovcnt;
+ struct iovec abd_iov[1]; /* actually variable-length */
+};
+
+struct abd_linear {
+ void *abd_buf;
+};
-#ifndef _LIBSPL_STROPTS_H
-#define _LIBSPL_STROPTS_H
+#ifdef __cplusplus
+}
+#endif
-#endif /* _LIBSPL_STROPTS_H */
+#endif /* _ABD_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/acl.h b/sys/contrib/openzfs/lib/libspl/include/sys/acl.h
index 31168421b088..602043bbb196 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/acl.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/acl.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/acl_impl.h b/sys/contrib/openzfs/lib/libspl/include/sys/acl_impl.h
index 717334906415..2850eacf61f4 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/acl_impl.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/acl_impl.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/limits.h b/sys/contrib/openzfs/lib/libspl/include/sys/asm_linkage.h
index 5d996eb846d1..1a0f2864a178 100644
--- a/sys/contrib/openzfs/lib/libspl/include/limits.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/asm_linkage.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -20,26 +21,27 @@
* CDDL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#include_next <limits.h>
-#include <float.h>
+#ifndef _SYS_ASM_LINKAGE_H
+#define _SYS_ASM_LINKAGE_H
-#ifndef _LIBSPL_LIMITS_H
-#define _LIBSPL_LIMITS_H
+#if defined(__i386) || defined(__amd64)
+
+#include <sys/ia32/asm_linkage.h> /* XX64 x86/sys/asm_linkage.h */
-#ifndef DBL_DIG
-#define DBL_DIG 15
-#define DBL_MAX 1.7976931348623157081452E+308
-#define DBL_MIN 2.2250738585072013830903E-308
#endif
-#ifndef FLT_DIG
-#define FLT_DIG 6
-#define FLT_MAX 3.4028234663852885981170E+38F
-#define FLT_MIN 1.1754943508222875079688E-38F
+#if defined(_KERNEL) && defined(HAVE_KERNEL_OBJTOOL)
+
+#include <asm/frame.h>
+
+#else /* userspace */
+#define FRAME_BEGIN
+#define FRAME_END
#endif
-#endif /* _LIBSPL_LIMITS_H */
+
+#endif /* _SYS_ASM_LINKAGE_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/va_list.h b/sys/contrib/openzfs/lib/libspl/include/sys/backtrace.h
index a36f5c77daa9..3a2077f32e6c 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/va_list.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/backtrace.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -20,13 +21,13 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2024, Rob Norris <robn@despairlabs.com>
+ * Copyright (c) 2024, Klara Inc.
*/
-#ifndef _SYS_VA_LIST_H
-#define _SYS_VA_LIST_H
+#ifndef _LIBSPL_SYS_BACKTRACE_H
+#define _LIBSPL_SYS_BACKTRACE_H
-#include <stdarg.h>
+void libspl_backtrace(int fd);
#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/callb.h b/sys/contrib/openzfs/lib/libspl/include/sys/callb.h
index 8ffd18788865..46ed166e52f8 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/callb.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/callb.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/cmn_err.h b/sys/contrib/openzfs/lib/libspl/include/sys/cmn_err.h
index 63ff4eb29bc8..32930adaeffa 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/cmn_err.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/cmn_err.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -27,4 +28,38 @@
#ifndef _LIBSPL_SYS_CMN_ERR_H
#define _LIBSPL_SYS_CMN_ERR_H
+#include <atomic.h>
+
+#define cmn_err_once(ce, ...) \
+do { \
+ static volatile uint32_t printed = 0; \
+ if (atomic_cas_32(&printed, 0, 1) == 0) { \
+ cmn_err(ce, __VA_ARGS__); \
+ } \
+} while (0)
+
+#define vcmn_err_once(ce, fmt, ap) \
+do { \
+ static volatile uint32_t printed = 0; \
+ if (atomic_cas_32(&printed, 0, 1) == 0) { \
+ vcmn_err(ce, fmt, ap); \
+ } \
+} while (0)
+
+#define zcmn_err_once(zone, ce, ...) \
+do { \
+ static volatile uint32_t printed = 0; \
+ if (atomic_cas_32(&printed, 0, 1) == 0) { \
+ zcmn_err(zone, ce, __VA_ARGS__); \
+ } \
+} while (0)
+
+#define vzcmn_err_once(zone, ce, fmt, ap) \
+do { \
+ static volatile uint32_t printed = 0; \
+ if (atomic_cas_32(&printed, 0, 1) == 0) { \
+ vzcmn_err(zone, ce, fmt, ap); \
+ } \
+} while (0)
+
#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/cred.h b/sys/contrib/openzfs/lib/libspl/include/sys/cred.h
index 463b3abfc977..4f6183762a0a 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/cred.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/cred.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/debug.h b/sys/contrib/openzfs/lib/libspl/include/sys/debug.h
index af18da94804c..02f33a68b75b 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/debug.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/debug.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -37,4 +38,8 @@
#define __maybe_unused __attribute__((unused))
#endif
+#ifndef __must_check
+#define __must_check __attribute__((warn_unused_result))
+#endif
+
#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/dkio.h b/sys/contrib/openzfs/lib/libspl/include/sys/dkio.h
index f3c641f669b7..4ae1026d4d5f 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/dkio.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/dkio.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/dklabel.h b/sys/contrib/openzfs/lib/libspl/include/sys/dklabel.h
index 8c2ca06c0cbc..409d337e9adf 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/dklabel.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/dklabel.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/dktp/Makefile.am b/sys/contrib/openzfs/lib/libspl/include/sys/dktp/Makefile.am
deleted file mode 100644
index 4ad3695d8abc..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/sys/dktp/Makefile.am
+++ /dev/null
@@ -1,4 +0,0 @@
-libspldir = $(includedir)/libspl/sys/dktp
-libspl_HEADERS = \
- fdisk.h
-
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/dktp/fdisk.h b/sys/contrib/openzfs/lib/libspl/include/sys/dktp/fdisk.h
index e90135f362e6..5e5db04cccfc 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/dktp/fdisk.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/dktp/fdisk.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/feature_tests.h b/sys/contrib/openzfs/lib/libspl/include/sys/feature_tests.h
index c9564b2c3269..be7d4ebf9210 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/feature_tests.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/feature_tests.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -28,13 +29,12 @@
#define _SYS_FEATURE_TESTS_H
#define ____cacheline_aligned
-#define __NORETURN __attribute__((__noreturn__))
-#if !defined(fallthrough) && !defined(_LIBCPP_VERSION)
+#if !defined(zfs_fallthrough) && !defined(_LIBCPP_VERSION)
#if defined(HAVE_IMPLICIT_FALLTHROUGH)
-#define fallthrough __attribute__((__fallthrough__))
+#define zfs_fallthrough __attribute__((__fallthrough__))
#else
-#define fallthrough ((void)0)
+#define zfs_fallthrough ((void)0)
#endif
#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/int_limits.h b/sys/contrib/openzfs/lib/libspl/include/sys/int_limits.h
deleted file mode 100644
index 7af68cdb2998..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/sys/int_limits.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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 2006 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _LIBSPL_SYS_INT_LIMITS_H
-#define _LIBSPL_SYS_INT_LIMITS_H
-
-#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/int_types.h b/sys/contrib/openzfs/lib/libspl/include/sys/int_types.h
deleted file mode 100644
index 51e9e0285490..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/sys/int_types.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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 2006 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _SOL_SYS_INT_TYPES_H
-#define _SOL_SYS_INT_TYPES_H
-
-#include <inttypes.h>
-
-#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/inttypes.h b/sys/contrib/openzfs/lib/libspl/include/sys/inttypes.h
index d7d063985316..66cf97ac8b5c 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/inttypes.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/inttypes.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/isa_defs.h b/sys/contrib/openzfs/lib/libspl/include/sys/isa_defs.h
index 8c0932f57654..99dbc70e4617 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/isa_defs.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/isa_defs.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -126,7 +127,7 @@ extern "C" {
#endif
/* arm arch specific defines */
-#elif defined(__arm) || defined(__arm__) || defined(__aarch64__)
+#elif defined(__arm) || defined(__arm__)
#if !defined(__arm)
#define __arm
@@ -136,17 +137,11 @@ extern "C" {
#define __arm__
#endif
-#if defined(__aarch64__)
-#if !defined(_LP64)
-#define _LP64
-#endif
-#else
#if !defined(_ILP32)
#define _ILP32
#endif
-#endif
-#if defined(__ARMEL__) || defined(__AARCH64EL__)
+#if defined(__ARMEL__)
#define _ZFS_LITTLE_ENDIAN
#else
#define _ZFS_BIG_ENDIAN
@@ -158,6 +153,21 @@ extern "C" {
#define HAVE_EFFICIENT_UNALIGNED_ACCESS
#endif
+/* aarch64 arch specific defines */
+#elif defined(__aarch64__)
+
+#if !defined(_LP64)
+#define _LP64
+#endif
+
+#if defined(__AARCH64EL__)
+#define _ZFS_LITTLE_ENDIAN
+#else
+#define _ZFS_BIG_ENDIAN
+#endif
+
+#define _SUNOS_VTOC_16
+
/* sparc arch specific defines */
#elif defined(__sparc) || defined(__sparc__)
@@ -218,9 +228,13 @@ extern "C" {
* RISC-V arch specific defines
* only RV64G (including atomic) LP64 is supported yet
*/
-#elif defined(__riscv) && defined(_LP64) && _LP64 && \
+#elif defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64 && \
defined(__riscv_atomic) && __riscv_atomic
+#if !defined(_LP64)
+#define _LP64 1
+#endif
+
#ifndef __riscv__
#define __riscv__
#endif
@@ -233,10 +247,26 @@ extern "C" {
#define _SUNOS_VTOC_16
+/*
+ * LoongArch arch specific defines
+ * only LoongArch64 is supported yet
+ */
+#elif defined(__loongarch__) && defined(__loongarch_lp64)
+
+#if !defined(_LP64)
+#define _LP64
+#endif
+
+#define _ZFS_LITTLE_ENDIAN
+#define _SUNOS_VTOC_16
+
+/* not all LoongArch cores support unaligned accesses in hardware */
+#define _ALIGNMENT_REQUIRED 1
+
#else
/*
* Currently supported:
- * x86_64, x32, i386, arm, powerpc, s390, sparc, mips, and RV64G
+ * x86_64, x32, i386, arm, powerpc, s390, sparc, mips, RV64G, and LoongArch64
*/
#error "Unsupported ISA type"
#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/kmem.h b/sys/contrib/openzfs/lib/libspl/include/sys/kmem.h
index 83d47565aeaf..279461f8d4c1 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/kmem.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/kmem.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -35,8 +36,8 @@ extern "C" {
#define KM_SLEEP 0x00000000 /* same as KM_SLEEP */
#define KM_NOSLEEP 0x00000001 /* same as KM_NOSLEEP */
-#define kmem_alloc(size, flags) malloc(size)
-#define kmem_free(ptr, size) free(ptr)
+#define kmem_alloc(size, flags) ((void) sizeof (flags), malloc(size))
+#define kmem_free(ptr, size) ((void) sizeof (size), free(ptr))
#ifdef __cplusplus
}
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/kstat.h b/sys/contrib/openzfs/lib/libspl/include/sys/kstat.h
index f73fb92eb797..7777888c31eb 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/kstat.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/kstat.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -92,39 +93,6 @@ typedef struct kstat {
void *ks_lock; /* protects this kstat's data */
} kstat_t;
-#ifdef _SYSCALL32
-
-typedef int32_t kid32_t;
-
-typedef struct kstat32 {
- /*
- * Fields relevant to both kernel and user
- */
- hrtime_t ks_crtime;
- caddr32_t ks_next; /* struct kstat pointer */
- kid32_t ks_kid;
- char ks_module[KSTAT_STRLEN];
- uint8_t ks_resv;
- int32_t ks_instance;
- char ks_name[KSTAT_STRLEN];
- uint8_t ks_type;
- char ks_class[KSTAT_STRLEN];
- uint8_t ks_flags;
- caddr32_t ks_data; /* type-specific data */
- uint32_t ks_ndata;
- size32_t ks_data_size;
- hrtime_t ks_snaptime;
- /*
- * Fields relevant to kernel only (only needed here for padding)
- */
- int32_t _ks_update;
- caddr32_t _ks_private;
- int32_t _ks_snapshot;
- caddr32_t _ks_lock;
-} kstat32_t;
-
-#endif /* _SYSCALL32 */
-
/*
* kstat structure and locking strategy
*
@@ -383,9 +351,9 @@ typedef struct kstat32 {
*
* ksp->ks_snaptime = gethrtime();
* if (rw == KSTAT_WRITE)
- * bcopy(buf, ksp->ks_data, ksp->ks_data_size);
+ * memcpy(ksp->ks_data, buf, ksp->ks_data_size);
* else
- * bcopy(ksp->ks_data, buf, ksp->ks_data_size);
+ * memcpy(buf, ksp->ks_data, ksp->ks_data_size);
* return (0);
*
* A more illuminating example is taking a snapshot of a linked list:
@@ -394,7 +362,7 @@ typedef struct kstat32 {
* if (rw == KSTAT_WRITE)
* return (EACCES); ... See below ...
* for (foo = first_foo; foo; foo = foo->next) {
- * bcopy((char *) foo, (char *) buf, sizeof (struct foo));
+ * memcpy(buf, foo, sizeof (struct foo));
* buf = ((struct foo *) buf) + 1;
* }
* return (0);
@@ -423,12 +391,12 @@ typedef struct kstat32 {
* uint_t i;
*
* ... Do the regular copy ...
- * bcopy(ksp->ks_data, buf, sizeof (kstat_named_t) * ksp->ks_ndata);
+ * memcpy(buf, ksp->ks_data, sizeof (kstat_named_t) * ksp->ks_ndata);
*
* for (i = 0; i < ksp->ks_ndata; i++, knp++) {
* if (knp[i].data_type == KSTAT_DATA_STRING &&
* KSTAT_NAMED_STR_PTR(knp) != NULL) {
- * bcopy(KSTAT_NAMED_STR_PTR(knp), end,
+ * memcpy(end, KSTAT_NAMED_STR_PTR(knp),
* KSTAT_NAMED_STR_BUFLEN(knp));
* KSTAT_NAMED_STR_PTR(knp) = end;
* end += KSTAT_NAMED_STR_BUFLEN(knp);
@@ -467,7 +435,7 @@ typedef struct kstat_named {
* 64-bit compilation environments or 32-bit non-maximally conformant
* C89 or C90 ANSI C compilation environments (cc -Xt and cc -Xa). In the
* C99 ANSI C compilation environment, the long long type is supported.
- * The _INT64_TYPE is defined by the implementation (see sys/int_types.h).
+ * The _INT64_TYPE is defined by the implementation (see sys/inttypes.h).
*/
#if defined(_INT64_TYPE)
int64_t i64;
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/list.h b/sys/contrib/openzfs/lib/libspl/include/sys/list.h
index 6db92ed42955..cbbda85dabb5 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/list.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/list.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/list_impl.h b/sys/contrib/openzfs/lib/libspl/include/sys/list_impl.h
index b5655b972c11..10683adab325 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/list_impl.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/list_impl.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -39,7 +40,6 @@ struct list_node {
};
struct list {
- size_t list_size;
size_t list_offset;
struct list_node list_head;
};
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/mhd.h b/sys/contrib/openzfs/lib/libspl/include/sys/mhd.h
index fcc062d51c84..82ec436750ef 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/mhd.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/mhd.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/mkdev.h b/sys/contrib/openzfs/lib/libspl/include/sys/mkdev.h
index 5978de65de50..f02823c68db0 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/mkdev.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/mkdev.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/mod.h b/sys/contrib/openzfs/lib/libspl/include/sys/mod.h
new file mode 100644
index 000000000000..ad19b6607a42
--- /dev/null
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/mod.h
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: CDDL-1.0
+/*
+ * 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 https://opensource.org/licenses/CDDL-1.0.
+ * 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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
+ * Copyright (c) 2012, 2018 by Delphix. All rights reserved.
+ * Copyright (c) 2012, Joyent, Inc. All rights reserved.
+ * Copyright (c) 2025, Rob Norris <robn@despairlabs.com>
+ */
+
+#ifndef _SYS_MOD_H
+#define _SYS_MOD_H
+
+#include <sys/tunables.h>
+
+#define ZFS_MODULE_PARAM(scope, prefix, name, type, perm, desc) \
+ static const zfs_tunable_t _zfs_tunable_##prefix##name = { \
+ .zt_name = #prefix#name, \
+ .zt_varp = &prefix##name, \
+ .zt_varsz = sizeof (prefix##name), \
+ .zt_type = ZFS_TUNABLE_TYPE_##type, \
+ .zt_perm = ZFS_TUNABLE_PERM_##perm, \
+ .zt_desc = desc \
+ }; \
+ static const zfs_tunable_t * \
+ __zfs_tunable_##prefix##name \
+ __attribute__((__section__("zfs_tunables"))) \
+ __attribute__((__used__)) \
+ = &_zfs_tunable_##prefix##name;
+
+#define ZFS_MODULE_PARAM_ARGS void
+#define ZFS_MODULE_PARAM_CALL(scope_prefix, name_prefix, name, setfunc, \
+ getfunc, perm, desc)
+
+#define EXPORT_SYMBOL(x)
+
+#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/policy.h b/sys/contrib/openzfs/lib/libspl/include/sys/policy.h
index 2f695b35cd0b..0d6016c1dd17 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/policy.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/policy.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/poll.h b/sys/contrib/openzfs/lib/libspl/include/sys/poll.h
index 6ab0bddc0be5..3e99db0bdbee 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/poll.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/poll.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/priv.h b/sys/contrib/openzfs/lib/libspl/include/sys/priv.h
index 76c76d1830c2..30b88a6c47fc 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/priv.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/priv.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/processor.h b/sys/contrib/openzfs/lib/libspl/include/sys/processor.h
index 78e95d01f1b5..9e1bd90992bd 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/processor.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/processor.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/sha2.h b/sys/contrib/openzfs/lib/libspl/include/sys/sha2.h
deleted file mode 100644
index e2f66d225e25..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/sys/sha2.h
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * 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 2009 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-/* Copyright 2013 Saso Kiselkov. All rights reserved. */
-
-#ifndef _SYS_SHA2_H
-#define _SYS_SHA2_H
-
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define SHA2_HMAC_MIN_KEY_LEN 1 /* SHA2-HMAC min key length in bytes */
-#define SHA2_HMAC_MAX_KEY_LEN INT_MAX /* SHA2-HMAC max key length in bytes */
-
-#define SHA256_DIGEST_LENGTH 32 /* SHA256 digest length in bytes */
-#define SHA384_DIGEST_LENGTH 48 /* SHA384 digest length in bytes */
-#define SHA512_DIGEST_LENGTH 64 /* SHA512 digest length in bytes */
-
-/* Truncated versions of SHA-512 according to FIPS-180-4, section 5.3.6 */
-#define SHA512_224_DIGEST_LENGTH 28 /* SHA512/224 digest length */
-#define SHA512_256_DIGEST_LENGTH 32 /* SHA512/256 digest length */
-
-#define SHA256_HMAC_BLOCK_SIZE 64 /* SHA256-HMAC block size */
-#define SHA512_HMAC_BLOCK_SIZE 128 /* SHA512-HMAC block size */
-
-#define SHA256 0
-#define SHA256_HMAC 1
-#define SHA256_HMAC_GEN 2
-#define SHA384 3
-#define SHA384_HMAC 4
-#define SHA384_HMAC_GEN 5
-#define SHA512 6
-#define SHA512_HMAC 7
-#define SHA512_HMAC_GEN 8
-#define SHA512_224 9
-#define SHA512_256 10
-
-/*
- * SHA2 context.
- * The contents of this structure are a private interface between the
- * Init/Update/Final calls of the functions defined below.
- * Callers must never attempt to read or write any of the fields
- * in this structure directly.
- */
-typedef struct {
- uint32_t algotype; /* Algorithm Type */
-
- /* state (ABCDEFGH) */
- union {
- uint32_t s32[8]; /* for SHA256 */
- uint64_t s64[8]; /* for SHA384/512 */
- } state;
- /* number of bits */
- union {
- uint32_t c32[2]; /* for SHA256 , modulo 2^64 */
- uint64_t c64[2]; /* for SHA384/512, modulo 2^128 */
- } count;
- union {
- uint8_t buf8[128]; /* undigested input */
- uint32_t buf32[32]; /* realigned input */
- uint64_t buf64[16]; /* realigned input */
- } buf_un;
-} SHA2_CTX;
-
-typedef SHA2_CTX SHA256_CTX;
-typedef SHA2_CTX SHA384_CTX;
-typedef SHA2_CTX SHA512_CTX;
-
-extern void SHA256Init(SHA256_CTX *);
-
-extern void SHA256Update(SHA256_CTX *, const void *, size_t);
-
-extern void SHA256Final(void *, SHA256_CTX *);
-
-extern void SHA384Init(SHA384_CTX *);
-
-extern void SHA384Update(SHA384_CTX *, const void *, size_t);
-
-extern void SHA384Final(void *, SHA384_CTX *);
-
-extern void SHA512Init(SHA512_CTX *);
-
-extern void SHA512Update(SHA512_CTX *, const void *, size_t);
-
-extern void SHA512Final(void *, SHA512_CTX *);
-
-extern void SHA2Init(uint64_t mech, SHA2_CTX *);
-
-extern void SHA2Update(SHA2_CTX *, const void *, size_t);
-
-extern void SHA2Final(void *, SHA2_CTX *);
-
-#ifdef _SHA2_IMPL
-/*
- * The following types/functions are all private to the implementation
- * of the SHA2 functions and must not be used by consumers of the interface
- */
-
-/*
- * List of support mechanisms in this module.
- *
- * It is important to note that in the module, division or modulus calculations
- * are used on the enumerated type to determine which mechanism is being used;
- * therefore, changing the order or additional mechanisms should be done
- * carefully
- */
-typedef enum sha2_mech_type {
- SHA256_MECH_INFO_TYPE, /* SUN_CKM_SHA256 */
- SHA256_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC */
- SHA256_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC_GENERAL */
- SHA384_MECH_INFO_TYPE, /* SUN_CKM_SHA384 */
- SHA384_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC */
- SHA384_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC_GENERAL */
- SHA512_MECH_INFO_TYPE, /* SUN_CKM_SHA512 */
- SHA512_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA512_HMAC */
- SHA512_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA512_HMAC_GENERAL */
- SHA512_224_MECH_INFO_TYPE, /* SUN_CKM_SHA512_224 */
- SHA512_256_MECH_INFO_TYPE /* SUN_CKM_SHA512_256 */
-} sha2_mech_type_t;
-
-#endif /* _SHA2_IMPL */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _SYS_SHA2_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/simd.h b/sys/contrib/openzfs/lib/libspl/include/sys/simd.h
index dceedb698fe0..4772a5416b2e 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/simd.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/simd.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -20,8 +21,8 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright (c) 2022 Tino Reichardt <milky-zfs@mcmilk.de>
*/
#ifndef _LIBSPL_SYS_SIMD_H
@@ -30,6 +31,28 @@
#include <sys/isa_defs.h>
#include <sys/types.h>
+/* including <sys/auxv.h> clashes with AT_UID and others */
+#if defined(__arm__) || defined(__aarch64__) || defined(__powerpc__)
+#if defined(__FreeBSD__)
+#define AT_HWCAP 25
+#define AT_HWCAP2 26
+extern int elf_aux_info(int aux, void *buf, int buflen);
+static inline unsigned long getauxval(unsigned long key)
+{
+ unsigned long val = 0UL;
+
+ if (elf_aux_info((int)key, &val, sizeof (val)) != 0)
+ return (0UL);
+
+ return (val);
+}
+#elif defined(__linux__)
+#define AT_HWCAP 16
+#define AT_HWCAP2 26
+extern unsigned long getauxval(unsigned long type);
+#endif /* __linux__ */
+#endif /* arm || aarch64 || powerpc */
+
#if defined(__x86)
#include <cpuid.h>
@@ -78,7 +101,10 @@ typedef enum cpuid_inst_sets {
AVX512VL,
AES,
PCLMULQDQ,
- MOVBE
+ MOVBE,
+ SHA_NI,
+ VAES,
+ VPCLMULQDQ
} cpuid_inst_sets_t;
/*
@@ -103,6 +129,9 @@ typedef struct cpuid_feature_desc {
#define _AES_BIT (1U << 25)
#define _PCLMULQDQ_BIT (1U << 1)
#define _MOVBE_BIT (1U << 22)
+#define _VAES_BIT (1U << 9)
+#define _VPCLMULQDQ_BIT (1U << 10)
+#define _SHA_NI_BIT (1U << 29)
/*
* Descriptions of supported instruction sets
@@ -131,6 +160,9 @@ static const cpuid_feature_desc_t cpuid_features[] = {
[AES] = {1U, 0U, _AES_BIT, ECX },
[PCLMULQDQ] = {1U, 0U, _PCLMULQDQ_BIT, ECX },
[MOVBE] = {1U, 0U, _MOVBE_BIT, ECX },
+ [SHA_NI] = {7U, 0U, _SHA_NI_BIT, EBX },
+ [VAES] = {7U, 0U, _VAES_BIT, ECX },
+ [VPCLMULQDQ] = {7U, 0U, _VPCLMULQDQ_BIT, ECX },
};
/*
@@ -204,6 +236,9 @@ CPUID_FEATURE_CHECK(avx512vl, AVX512VL);
CPUID_FEATURE_CHECK(aes, AES);
CPUID_FEATURE_CHECK(pclmulqdq, PCLMULQDQ);
CPUID_FEATURE_CHECK(movbe, MOVBE);
+CPUID_FEATURE_CHECK(shani, SHA_NI);
+CPUID_FEATURE_CHECK(vaes, VAES);
+CPUID_FEATURE_CHECK(vpclmulqdq, VPCLMULQDQ);
/*
* Detect register set support
@@ -346,6 +381,33 @@ zfs_movbe_available(void)
}
/*
+ * Check if SHA_NI instruction is available
+ */
+static inline boolean_t
+zfs_shani_available(void)
+{
+ return (__cpuid_has_shani());
+}
+
+/*
+ * Check if VAES instruction is available
+ */
+static inline boolean_t
+zfs_vaes_available(void)
+{
+ return (__cpuid_has_vaes());
+}
+
+/*
+ * Check if VPCLMULQDQ instruction is available
+ */
+static inline boolean_t
+zfs_vpclmulqdq_available(void)
+{
+ return (__cpuid_has_vpclmulqdq());
+}
+
+/*
* AVX-512 family of instruction sets:
*
* AVX512F Foundation
@@ -443,53 +505,111 @@ zfs_avx512vbmi_available(void)
__zmm_enabled());
}
-#elif defined(__aarch64__)
+#elif defined(__arm__)
#define kfpu_allowed() 1
#define kfpu_initialize(tsk) do {} while (0)
#define kfpu_begin() do {} while (0)
#define kfpu_end() do {} while (0)
-#elif defined(__powerpc__)
+#define HWCAP_NEON 0x00001000
+#define HWCAP2_SHA2 0x00000008
+
+/*
+ * Check if NEON is available
+ */
+static inline boolean_t
+zfs_neon_available(void)
+{
+ unsigned long hwcap = getauxval(AT_HWCAP);
+ return (hwcap & HWCAP_NEON);
+}
+
+/*
+ * Check if SHA2 is available
+ */
+static inline boolean_t
+zfs_sha256_available(void)
+{
+ unsigned long hwcap = getauxval(AT_HWCAP);
+ return (hwcap & HWCAP2_SHA2);
+}
+
+#elif defined(__aarch64__)
#define kfpu_allowed() 1
#define kfpu_initialize(tsk) do {} while (0)
#define kfpu_begin() do {} while (0)
#define kfpu_end() do {} while (0)
+#define HWCAP_FP 0x00000001
+#define HWCAP_SHA2 0x00000040
+#define HWCAP_SHA512 0x00200000
+
+/*
+ * Check if NEON is available
+ */
+static inline boolean_t
+zfs_neon_available(void)
+{
+ unsigned long hwcap = getauxval(AT_HWCAP);
+ return (hwcap & HWCAP_FP);
+}
+
/*
- * Check if AltiVec instruction set is available
- * No easy way beyond 'altivec works' :-(
+ * Check if SHA2 is available
*/
-#include <signal.h>
-#include <setjmp.h>
+static inline boolean_t
+zfs_sha256_available(void)
+{
+ unsigned long hwcap = getauxval(AT_HWCAP);
+ return (hwcap & HWCAP_SHA2);
+}
-#if defined(__ALTIVEC__) && !defined(__FreeBSD__)
-static jmp_buf env;
-static void sigillhandler(int x)
+/*
+ * Check if SHA512 is available
+ */
+static inline boolean_t
+zfs_sha512_available(void)
{
- longjmp(env, 1);
+ unsigned long hwcap = getauxval(AT_HWCAP);
+ return (hwcap & HWCAP_SHA512);
}
-#endif
+
+#elif defined(__powerpc__)
+
+#define kfpu_allowed() 0
+#define kfpu_initialize(tsk) do {} while (0)
+#define kfpu_begin() do {} while (0)
+#define kfpu_end() do {} while (0)
+
+#define PPC_FEATURE_HAS_ALTIVEC 0x10000000
+#define PPC_FEATURE_HAS_VSX 0x00000080
+#define PPC_FEATURE2_ARCH_2_07 0x80000000
static inline boolean_t
zfs_altivec_available(void)
{
- boolean_t has_altivec = B_FALSE;
-#if defined(__ALTIVEC__) && !defined(__FreeBSD__)
- sighandler_t savesig;
- savesig = signal(SIGILL, sigillhandler);
- if (setjmp(env)) {
- signal(SIGILL, savesig);
- has_altivec = B_FALSE;
- } else {
- __asm__ __volatile__("vor 0,0,0\n" : : : "v0");
- signal(SIGILL, savesig);
- has_altivec = B_TRUE;
- }
-#endif
- return (has_altivec);
+ unsigned long hwcap = getauxval(AT_HWCAP);
+ return (hwcap & PPC_FEATURE_HAS_ALTIVEC);
+}
+
+static inline boolean_t
+zfs_vsx_available(void)
+{
+ unsigned long hwcap = getauxval(AT_HWCAP);
+ return (hwcap & PPC_FEATURE_HAS_VSX);
}
+
+static inline boolean_t
+zfs_isa207_available(void)
+{
+ unsigned long hwcap = getauxval(AT_HWCAP);
+ unsigned long hwcap2 = getauxval(AT_HWCAP2);
+ return ((hwcap & PPC_FEATURE_HAS_VSX) &&
+ (hwcap2 & PPC_FEATURE2_ARCH_2_07));
+}
+
#else
#define kfpu_allowed() 0
@@ -499,4 +619,7 @@ zfs_altivec_available(void)
#endif
+extern void simd_stat_init(void);
+extern void simd_stat_fini(void);
+
#endif /* _LIBSPL_SYS_SIMD_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/stack.h b/sys/contrib/openzfs/lib/libspl/include/sys/stack.h
index 59807e97b6a0..80984086a145 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/stack.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/stack.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/stdtypes.h b/sys/contrib/openzfs/lib/libspl/include/sys/stdtypes.h
index c26e2dc96c4e..db5876e5bc2b 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/stdtypes.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/stdtypes.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/string.h b/sys/contrib/openzfs/lib/libspl/include/sys/string.h
new file mode 100644
index 000000000000..3b2f5900276f
--- /dev/null
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/string.h
@@ -0,0 +1 @@
+#include <string.h>
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/strings.h b/sys/contrib/openzfs/lib/libspl/include/sys/strings.h
deleted file mode 100644
index c142047dcdb8..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/sys/strings.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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 2006 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _LIBSPL_SYS_STRINGS_H
-#define _LIBSPL_SYS_STRINGS_H
-
-#include <string.h>
-#include <strings.h>
-
-#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/sunddi.h b/sys/contrib/openzfs/lib/libspl/include/sys/sunddi.h
index ccd2b29b9b09..8489c7139bad 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/sunddi.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/sunddi.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/systeminfo.h b/sys/contrib/openzfs/lib/libspl/include/sys/systeminfo.h
index cc6c1793c00e..3ca1fa884994 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/systeminfo.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/systeminfo.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/time.h b/sys/contrib/openzfs/lib/libspl/include/sys/time.h
index c9f6165047d2..062c6ec979fc 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/time.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/time.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -97,11 +98,20 @@ gethrestime_sec(void)
}
static inline hrtime_t
+getlrtime(void)
+{
+ struct timeval tv;
+ (void) gettimeofday(&tv, NULL);
+ return ((((uint64_t)tv.tv_sec) * NANOSEC) +
+ ((uint64_t)tv.tv_usec * NSEC_PER_USEC));
+}
+
+static inline hrtime_t
gethrtime(void)
{
struct timespec ts;
(void) clock_gettime(CLOCK_MONOTONIC, &ts);
- return ((((u_int64_t)ts.tv_sec) * NANOSEC) + ts.tv_nsec);
+ return ((((uint64_t)ts.tv_sec) * NANOSEC) + ts.tv_nsec);
}
#endif /* _LIBSPL_SYS_TIME_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/tunables.h b/sys/contrib/openzfs/lib/libspl/include/sys/tunables.h
new file mode 100644
index 000000000000..5d9bb3d71a4a
--- /dev/null
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/tunables.h
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: CDDL-1.0
+/*
+ * 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 https://opensource.org/licenses/CDDL-1.0.
+ * 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 (c) 2025, Rob Norris <robn@despairlabs.com>
+ */
+
+#ifndef _SYS_TUNABLES_H
+#define _SYS_TUNABLES_H
+
+typedef enum {
+ ZFS_TUNABLE_TYPE_INT,
+ ZFS_TUNABLE_TYPE_UINT,
+ ZFS_TUNABLE_TYPE_ULONG,
+ ZFS_TUNABLE_TYPE_U64,
+ ZFS_TUNABLE_TYPE_STRING,
+} zfs_tunable_type_t;
+
+typedef enum {
+ ZFS_TUNABLE_PERM_ZMOD_RW,
+ ZFS_TUNABLE_PERM_ZMOD_RD,
+} zfs_tunable_perm_t;
+
+typedef struct zfs_tunable {
+ const char *zt_name;
+ void *zt_varp;
+ size_t zt_varsz;
+ zfs_tunable_type_t zt_type;
+ zfs_tunable_perm_t zt_perm;
+ const char *zt_desc;
+} zfs_tunable_t;
+
+int zfs_tunable_set(const zfs_tunable_t *tunable, const char *val);
+int zfs_tunable_get(const zfs_tunable_t *tunable, char *val, size_t valsz);
+
+const zfs_tunable_t *zfs_tunable_lookup(const char *name);
+
+typedef int (*zfs_tunable_iter_t)(const zfs_tunable_t *tunable, void *arg);
+void zfs_tunable_iter(zfs_tunable_iter_t cb, void *arg);
+
+#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/types.h b/sys/contrib/openzfs/lib/libspl/include/sys/types.h
index ea02ffac93ac..f4bb85c7942e 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/types.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/types.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -37,41 +38,16 @@
#include <sys/feature_tests.h>
#include_next <sys/types.h>
#include <sys/types32.h>
-#include <sys/va_list.h>
+#include <stdarg.h>
#include <sys/stdtypes.h>
#ifndef HAVE_INTTYPES
#include <inttypes.h>
#endif /* HAVE_INTTYPES */
-typedef int zoneid_t;
+typedef uint_t zoneid_t;
typedef int projid_t;
-/*
- * Definitions remaining from previous partial support for 64-bit file
- * offsets. This partial support for devices greater than 2gb requires
- * compiler support for long long.
- */
-#ifdef _LONG_LONG_LTOH
-typedef union {
- offset_t _f; /* Full 64 bit offset value */
- struct {
- int32_t _l; /* lower 32 bits of offset value */
- int32_t _u; /* upper 32 bits of offset value */
- } _p;
-} lloff_t;
-#endif
-
-#ifdef _LONG_LONG_HTOL
-typedef union {
- offset_t _f; /* Full 64 bit offset value */
- struct {
- int32_t _u; /* upper 32 bits of offset value */
- int32_t _l; /* lower 32 bits of offset value */
- } _p;
-} lloff_t;
-#endif
-
#include <sys/param.h> /* for NBBY */
#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/types32.h b/sys/contrib/openzfs/lib/libspl/include/sys/types32.h
index bb41aa34bee0..1bcae20187ad 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/types32.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/types32.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -65,11 +66,6 @@ typedef int32_t ssize32_t;
typedef int32_t time32_t;
typedef int32_t clock32_t;
-struct timeval32 {
- time32_t tv_sec; /* seconds */
- int32_t tv_usec; /* and microseconds */
-};
-
typedef struct timespec32 {
time32_t tv_sec; /* seconds */
int32_t tv_nsec; /* and nanoseconds */
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/tzfile.h b/sys/contrib/openzfs/lib/libspl/include/sys/tzfile.h
deleted file mode 100644
index e30e7566366e..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/sys/tzfile.h
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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.
- */
-
-/*
- * from Arthur Olson's 6.1
- */
-
-#ifndef _LIBSPL_SYS_TZFILE_H
-#define _LIBSPL_SYS_TZFILE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Information about time zone files.
- */
-
-#define TZDIR "/usr/share/lib/zoneinfo" /* Time zone object file directory */
-
-#define TZDEFAULT (getenv("TZ"))
-
-#define TZDEFRULES "posixrules"
-
-/*
- * Each file begins with. . .
- */
-
-struct tzhead {
- char tzh_reserved[24]; /* reserved for future use */
- char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
- char tzh_leapcnt[4]; /* coded number of leap seconds */
- char tzh_timecnt[4]; /* coded number of transition times */
- char tzh_typecnt[4]; /* coded number of local time types */
- char tzh_charcnt[4]; /* coded number of abbr. chars */
-};
-
-/*
- * . . .followed by. . .
- *
- * tzh_timecnt (char [4])s coded transition times a la time(2)
- * tzh_timecnt (unsigned char)s types of local time starting at above
- * tzh_typecnt repetitions of
- * one (char [4]) coded GMT offset in seconds
- * one (unsigned char) used to set tm_isdst
- * one (unsigned char) that's an abbreviation list index
- * tzh_charcnt (char)s '\0'-terminated zone abbreviations
- * tzh_leapcnt repetitions of
- * one (char [4]) coded leap second transition times
- * one (char [4]) total correction after above
- * tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition
- * time is standard time, if FALSE,
- * transition time is wall clock time
- * if absent, transition times are
- * assumed to be wall clock time
- */
-
-/*
- * In the current implementation, "tzset()" refuses to deal with files that
- * exceed any of the limits below.
- */
-
-/*
- * The TZ_MAX_TIMES value below is enough to handle a bit more than a
- * year's worth of solar time (corrected daily to the nearest second) or
- * 138 years of Pacific Presidential Election time
- * (where there are three time zone transitions every fourth year).
- */
-#define TZ_MAX_TIMES 370
-
-#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
-
-#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
-
-#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
-
-#define SECSPERMIN 60
-#define MINSPERHOUR 60
-#define HOURSPERDAY 24
-#define DAYSPERWEEK 7
-#define DAYSPERNYEAR 365
-#define DAYSPERLYEAR 366
-#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
-#define SECSPERDAY ((long)SECSPERHOUR * HOURSPERDAY)
-#define MONSPERYEAR 12
-
-#define TM_SUNDAY 0
-#define TM_MONDAY 1
-#define TM_TUESDAY 2
-#define TM_WEDNESDAY 3
-#define TM_THURSDAY 4
-#define TM_FRIDAY 5
-#define TM_SATURDAY 6
-
-#define TM_JANUARY 0
-#define TM_FEBRUARY 1
-#define TM_MARCH 2
-#define TM_APRIL 3
-#define TM_MAY 4
-#define TM_JUNE 5
-#define TM_JULY 6
-#define TM_AUGUST 7
-#define TM_SEPTEMBER 8
-#define TM_OCTOBER 9
-#define TM_NOVEMBER 10
-#define TM_DECEMBER 11
-
-#define TM_YEAR_BASE 1900
-
-#define EPOCH_YEAR 1970
-#define EPOCH_WDAY TM_THURSDAY
-
-/*
- * Accurate only for the past couple of centuries;
- * that will probably do.
- */
-
-#define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
-
-/*
- * Use of the underscored variants may cause problems if you move your code to
- * certain System-V-based systems; for maximum portability, use the
- * underscore-free variants. The underscored variants are provided for
- * backward compatibility only; they may disappear from future versions of
- * this file.
- */
-
-#define SECS_PER_MIN SECSPERMIN
-#define MINS_PER_HOUR MINSPERHOUR
-#define HOURS_PER_DAY HOURSPERDAY
-#define DAYS_PER_WEEK DAYSPERWEEK
-#define DAYS_PER_NYEAR DAYSPERNYEAR
-#define DAYS_PER_LYEAR DAYSPERLYEAR
-#define SECS_PER_HOUR SECSPERHOUR
-#define SECS_PER_DAY SECSPERDAY
-#define MONS_PER_YEAR MONSPERYEAR
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _LIBSPL_SYS_TZFILE_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/uio.h b/sys/contrib/openzfs/lib/libspl/include/sys/uio.h
index 81ade54b5409..9ada482be000 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/uio.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/uio.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -40,6 +41,7 @@
#ifndef _LIBSPL_SYS_UIO_H
#define _LIBSPL_SYS_UIO_H
+#include <sys/sysmacros.h>
#include <sys/types.h>
#include_next <sys/uio.h>
@@ -57,8 +59,7 @@ typedef enum zfs_uio_rw {
} zfs_uio_rw_t;
typedef enum zfs_uio_seg {
- UIO_USERSPACE = 0,
- UIO_SYSSPACE = 1,
+ UIO_SYSSPACE = 0,
} zfs_uio_seg_t;
#elif defined(__FreeBSD__)
@@ -82,6 +83,32 @@ typedef struct zfs_uio {
#define zfs_uio_iovlen(uio, idx) (uio)->uio_iov[(idx)].iov_len
#define zfs_uio_iovbase(uio, idx) (uio)->uio_iov[(idx)].iov_base
+static inline boolean_t
+zfs_dio_page_aligned(void *buf)
+{
+ return ((((unsigned long)(buf) & (PAGESIZE - 1)) == 0) ?
+ B_TRUE : B_FALSE);
+}
+
+static inline boolean_t
+zfs_dio_offset_aligned(uint64_t offset, uint64_t blksz)
+{
+ return ((IS_P2ALIGNED(offset, blksz)) ? B_TRUE : B_FALSE);
+}
+
+static inline boolean_t
+zfs_dio_size_aligned(uint64_t size, uint64_t blksz)
+{
+ return (((size % blksz) == 0) ? B_TRUE : B_FALSE);
+}
+
+static inline boolean_t
+zfs_dio_aligned(uint64_t offset, uint64_t size, uint64_t blksz)
+{
+ return ((zfs_dio_offset_aligned(offset, blksz) &&
+ zfs_dio_size_aligned(size, blksz)) ? B_TRUE : B_FALSE);
+}
+
static inline void
zfs_uio_iov_at_index(zfs_uio_t *uio, uint_t idx, void **base, uint64_t *len)
{
@@ -90,7 +117,7 @@ zfs_uio_iov_at_index(zfs_uio_t *uio, uint_t idx, void **base, uint64_t *len)
}
static inline void
-zfs_uio_advance(zfs_uio_t *uio, size_t size)
+zfs_uio_advance(zfs_uio_t *uio, ssize_t size)
{
uio->uio_resid -= size;
uio->uio_loffset += size;
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/varargs.h b/sys/contrib/openzfs/lib/libspl/include/sys/varargs.h
deleted file mode 100644
index 3d00a3361d87..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/sys/varargs.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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 2006 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _LIBSPL_SYS_VARARGS_H
-#define _LIBSPL_SYS_VARARGS_H
-
-#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/vnode.h b/sys/contrib/openzfs/lib/libspl/include/sys/vnode.h
index efcdd2c5a5ae..49afe12c52b1 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/vnode.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/vnode.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/vtoc.h b/sys/contrib/openzfs/lib/libspl/include/sys/vtoc.h
deleted file mode 100644
index 5d8448b628dc..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/sys/vtoc.h
+++ /dev/null
@@ -1,350 +0,0 @@
-/*
- * 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 2009 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-
-/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
-/* All Rights Reserved */
-
-
-#ifndef _SYS_VTOC_H
-#define _SYS_VTOC_H
-
-#include <sys/dklabel.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Note: the VTOC is not implemented fully, nor in the manner
- * that AT&T implements it. AT&T puts the vtoc structure
- * into a sector, usually the second sector (pdsector is first).
- *
- * Sun incorporates the tag, flag, version, and volume vtoc fields into
- * its Disk Label, which already has some vtoc-equivalent fields.
- * Upon reading the vtoc with read_vtoc(), the following exceptions
- * occur:
- * v_bootinfo [all] returned as zero
- * v_sanity returned as VTOC_SANE
- * if Disk Label was sane
- * v_sectorsz returned as 512
- * v_reserved [all] returned as zero
- * timestamp [all] returned as zero
- *
- * See dklabel.h, read_vtoc(), and write_vtoc().
- */
-
-#define V_NUMPAR NDKMAP /* The number of partitions */
- /* (from dkio.h) */
-
-#define VTOC_SANE 0x600DDEEE /* Indicates a sane VTOC */
-#define V_VERSION 0x01 /* layout version number */
-#define V_EXTVERSION V_VERSION /* extvtoc layout version number */
-
-/*
- * Partition identification tags
- */
-#define V_UNASSIGNED 0x00 /* unassigned partition */
-#define V_BOOT 0x01 /* Boot partition */
-#define V_ROOT 0x02 /* Root filesystem */
-#define V_SWAP 0x03 /* Swap filesystem */
-#define V_USR 0x04 /* Usr filesystem */
-#define V_BACKUP 0x05 /* full disk */
-#define V_STAND 0x06 /* Stand partition */
-#define V_VAR 0x07 /* Var partition */
-#define V_HOME 0x08 /* Home partition */
-#define V_ALTSCTR 0x09 /* Alternate sector partition */
-#define V_CACHE 0x0a /* Cache (cachefs) partition */
-#define V_RESERVED 0x0b /* SMI reserved data */
-
-/*
- * Partition permission flags
- */
-#define V_UNMNT 0x01 /* Unmountable partition */
-#define V_RONLY 0x10 /* Read only */
-
-/*
- * error codes for reading & writing vtoc
- */
-#define VT_ERROR (-2) /* errno supplies specific error */
-#define VT_EIO (-3) /* I/O error accessing vtoc */
-#define VT_EINVAL (-4) /* illegal value in vtoc or request */
-#define VT_ENOTSUP (-5) /* VTOC op. not supported */
-#define VT_ENOSPC (-6) /* requested space not found */
-#define VT_EOVERFLOW (-7) /* VTOC op. data struct limited */
-
-struct partition {
- ushort_t p_tag; /* ID tag of partition */
- ushort_t p_flag; /* permission flags */
- uint64_t p_start; /* start sector no of partition */
- long p_size; /* # of blocks in partition */
-};
-
-struct vtoc {
- unsigned long v_bootinfo[3]; /* info needed by mboot (unsupported) */
- unsigned long v_sanity; /* to verify vtoc sanity */
- unsigned long v_version; /* layout version */
- char v_volume[LEN_DKL_VVOL]; /* volume name */
- ushort_t v_sectorsz; /* sector size in bytes */
- ushort_t v_nparts; /* number of partitions */
- unsigned long v_reserved[10]; /* free space */
- struct partition v_part[V_NUMPAR]; /* partition headers */
- time_t timestamp[V_NUMPAR]; /* partition timestamp (unsupported) */
- char v_asciilabel[LEN_DKL_ASCII]; /* for compatibility */
-};
-
-struct extpartition {
- ushort_t p_tag; /* ID tag of partition */
- ushort_t p_flag; /* permission flags */
- ushort_t p_pad[2];
- diskaddr_t p_start; /* start sector no of partition */
- diskaddr_t p_size; /* # of blocks in partition */
-};
-
-
-struct extvtoc {
- uint64_t v_bootinfo[3]; /* info needed by mboot (unsupported) */
- uint64_t v_sanity; /* to verify vtoc sanity */
- uint64_t v_version; /* layout version */
- char v_volume[LEN_DKL_VVOL]; /* volume name */
- ushort_t v_sectorsz; /* sector size in bytes */
- ushort_t v_nparts; /* number of partitions */
- ushort_t pad[2];
- uint64_t v_reserved[10];
- struct extpartition v_part[V_NUMPAR]; /* partition headers */
- uint64_t timestamp[V_NUMPAR]; /* partition timestamp (unsupported) */
- char v_asciilabel[LEN_DKL_ASCII]; /* for compatibility */
-};
-
-#ifdef _KERNEL
-#define extvtoctovtoc(extv, v) \
- { \
- int i; \
- v.v_bootinfo[0] = (unsigned long)extv.v_bootinfo[0]; \
- v.v_bootinfo[1] = (unsigned long)extv.v_bootinfo[1]; \
- v.v_bootinfo[2] = (unsigned long)extv.v_bootinfo[2]; \
- v.v_sanity = (unsigned long)extv.v_sanity; \
- v.v_version = (unsigned long)extv.v_version; \
- bcopy(extv.v_volume, v.v_volume, LEN_DKL_VVOL); \
- v.v_sectorsz = extv.v_sectorsz; \
- v.v_nparts = extv.v_nparts; \
- for (i = 0; i < 10; i++) \
- v.v_reserved[i] = (unsigned long)extv.v_reserved[i]; \
- for (i = 0; i < V_NUMPAR; i++) { \
- v.v_part[i].p_tag = extv.v_part[i].p_tag; \
- v.v_part[i].p_flag = extv.v_part[i].p_flag; \
- v.v_part[i].p_start = (uint64_t)extv.v_part[i].p_start; \
- v.v_part[i].p_size = (long)extv.v_part[i].p_size; \
- v.timestamp[i] = (time_t)extv.timestamp[i]; \
- } \
- bcopy(extv.v_asciilabel, v.v_asciilabel, LEN_DKL_ASCII); \
- }
-
-#define vtoctoextvtoc(v, extv) \
- { \
- int i; \
- extv.v_bootinfo[0] = (uint64_t)v.v_bootinfo[0]; \
- extv.v_bootinfo[1] = (uint64_t)v.v_bootinfo[1]; \
- extv.v_bootinfo[2] = (uint64_t)v.v_bootinfo[2]; \
- extv.v_sanity = (uint64_t)v.v_sanity; \
- extv.v_version = (uint64_t)v.v_version; \
- bcopy(v.v_volume, extv.v_volume, LEN_DKL_VVOL); \
- extv.v_sectorsz = v.v_sectorsz; \
- extv.v_nparts = v.v_nparts; \
- for (i = 0; i < 10; i++) \
- extv.v_reserved[i] = (uint64_t)v.v_reserved[i]; \
- for (i = 0; i < V_NUMPAR; i++) { \
- extv.v_part[i].p_tag = v.v_part[i].p_tag; \
- extv.v_part[i].p_flag = v.v_part[i].p_flag; \
- extv.v_part[i].p_start = \
- (diskaddr_t)(unsigned long)v.v_part[i].p_start; \
- extv.v_part[i].p_size = \
- (diskaddr_t)(unsigned long)v.v_part[i].p_size; \
- extv.timestamp[i] = (uint64_t)v.timestamp[i]; \
- } \
- bcopy(v.v_asciilabel, extv.v_asciilabel, LEN_DKL_ASCII); \
- }
-#endif /* _KERNEL */
-
-#if defined(_SYSCALL32)
-struct partition32 {
- uint16_t p_tag; /* ID tag of partition */
- uint16_t p_flag; /* permission flags */
- daddr32_t p_start; /* start sector no of partition */
- int32_t p_size; /* # of blocks in partition */
-};
-
-struct vtoc32 {
- uint32_t v_bootinfo[3]; /* info needed by mboot (unsupported) */
- uint32_t v_sanity; /* to verify vtoc sanity */
- uint32_t v_version; /* layout version */
- char v_volume[LEN_DKL_VVOL]; /* volume name */
- uint16_t v_sectorsz; /* sector size in bytes */
- uint16_t v_nparts; /* number of partitions */
- uint32_t v_reserved[10]; /* free space */
- struct partition32 v_part[V_NUMPAR]; /* partition headers */
- time32_t timestamp[V_NUMPAR]; /* partition timestamp (unsupported) */
- char v_asciilabel[LEN_DKL_ASCII]; /* for compatibility */
-};
-
-#define vtoc32tovtoc(v32, v) \
- { \
- int i; \
- v.v_bootinfo[0] = v32.v_bootinfo[0]; \
- v.v_bootinfo[1] = v32.v_bootinfo[1]; \
- v.v_bootinfo[2] = v32.v_bootinfo[2]; \
- v.v_sanity = v32.v_sanity; \
- v.v_version = v32.v_version; \
- bcopy(v32.v_volume, v.v_volume, LEN_DKL_VVOL); \
- v.v_sectorsz = v32.v_sectorsz; \
- v.v_nparts = v32.v_nparts; \
- v.v_version = v32.v_version; \
- for (i = 0; i < 10; i++) \
- v.v_reserved[i] = v32.v_reserved[i]; \
- for (i = 0; i < V_NUMPAR; i++) { \
- v.v_part[i].p_tag = (ushort_t)v32.v_part[i].p_tag; \
- v.v_part[i].p_flag = (ushort_t)v32.v_part[i].p_flag; \
- v.v_part[i].p_start = (unsigned)v32.v_part[i].p_start; \
- v.v_part[i].p_size = (unsigned)v32.v_part[i].p_size; \
- } \
- for (i = 0; i < V_NUMPAR; i++) \
- v.timestamp[i] = (time_t)v32.timestamp[i]; \
- bcopy(v32.v_asciilabel, v.v_asciilabel, LEN_DKL_ASCII); \
- }
-
-#define vtoc32toextvtoc(v32, extv) \
- { \
- int i; \
- extv.v_bootinfo[0] = v32.v_bootinfo[0]; \
- extv.v_bootinfo[1] = v32.v_bootinfo[1]; \
- extv.v_bootinfo[2] = v32.v_bootinfo[2]; \
- extv.v_sanity = v32.v_sanity; \
- extv.v_version = v32.v_version; \
- bcopy(v32.v_volume, extv.v_volume, LEN_DKL_VVOL); \
- extv.v_sectorsz = v32.v_sectorsz; \
- extv.v_nparts = v32.v_nparts; \
- extv.v_version = v32.v_version; \
- for (i = 0; i < 10; i++) \
- extv.v_reserved[i] = v32.v_reserved[i]; \
- for (i = 0; i < V_NUMPAR; i++) { \
- extv.v_part[i].p_tag = (ushort_t)v32.v_part[i].p_tag; \
- extv.v_part[i].p_flag = (ushort_t)v32.v_part[i].p_flag; \
- extv.v_part[i].p_start = (diskaddr_t)v32.v_part[i].p_start; \
- extv.v_part[i].p_size = (diskaddr_t)v32.v_part[i].p_size; \
- extv.timestamp[i] = (time_t)v32.timestamp[i]; \
- } \
- bcopy(v32.v_asciilabel, extv.v_asciilabel, LEN_DKL_ASCII); \
- }
-
-
-#define vtoctovtoc32(v, v32) \
- { \
- int i; \
- v32.v_bootinfo[0] = v.v_bootinfo[0]; \
- v32.v_bootinfo[1] = v.v_bootinfo[1]; \
- v32.v_bootinfo[2] = v.v_bootinfo[2]; \
- v32.v_sanity = v.v_sanity; \
- v32.v_version = v.v_version; \
- bcopy(v.v_volume, v32.v_volume, LEN_DKL_VVOL); \
- v32.v_sectorsz = v.v_sectorsz; \
- v32.v_nparts = v.v_nparts; \
- v32.v_version = v.v_version; \
- for (i = 0; i < 10; i++) \
- v32.v_reserved[i] = v.v_reserved[i]; \
- for (i = 0; i < V_NUMPAR; i++) { \
- v32.v_part[i].p_tag = (ushort_t)v.v_part[i].p_tag; \
- v32.v_part[i].p_flag = (ushort_t)v.v_part[i].p_flag; \
- v32.v_part[i].p_start = (unsigned)v.v_part[i].p_start; \
- v32.v_part[i].p_size = (unsigned)v.v_part[i].p_size; \
- } \
- for (i = 0; i < V_NUMPAR; i++) { \
- if (v.timestamp[i] > TIME32_MAX) \
- v32.timestamp[i] = TIME32_MAX; \
- else \
- v32.timestamp[i] = (time32_t)v.timestamp[i]; \
- } \
- bcopy(v.v_asciilabel, v32.v_asciilabel, LEN_DKL_ASCII); \
- }
-
-#define extvtoctovtoc32(extv, v32) \
- { \
- int i; \
- v32.v_bootinfo[0] = extv.v_bootinfo[0]; \
- v32.v_bootinfo[1] = extv.v_bootinfo[1]; \
- v32.v_bootinfo[2] = extv.v_bootinfo[2]; \
- v32.v_sanity = extv.v_sanity; \
- v32.v_version = extv.v_version; \
- bcopy(extv.v_volume, v32.v_volume, LEN_DKL_VVOL); \
- v32.v_sectorsz = extv.v_sectorsz; \
- v32.v_nparts = extv.v_nparts; \
- v32.v_version = extv.v_version; \
- for (i = 0; i < 10; i++) \
- v32.v_reserved[i] = extv.v_reserved[i]; \
- for (i = 0; i < V_NUMPAR; i++) { \
- v32.v_part[i].p_tag = (ushort_t)extv.v_part[i].p_tag; \
- v32.v_part[i].p_flag = (ushort_t)extv.v_part[i].p_flag; \
- v32.v_part[i].p_start = (unsigned)extv.v_part[i].p_start; \
- v32.v_part[i].p_size = (unsigned)extv.v_part[i].p_size; \
- } \
- for (i = 0; i < V_NUMPAR; i++) { \
- if (extv.timestamp[i] > TIME32_MAX) \
- v32.timestamp[i] = TIME32_MAX; \
- else \
- v32.timestamp[i] = (time32_t)extv.timestamp[i]; \
- } \
- bcopy(extv.v_asciilabel, v32.v_asciilabel, LEN_DKL_ASCII); \
- }
-
-
-#endif /* _SYSCALL32 */
-
-/*
- * These defines are the mode parameter for the checksum routines.
- */
-#define CK_CHECKSUM 0 /* check checksum */
-#define CK_MAKESUM 1 /* generate checksum */
-
-#if defined(__STDC__)
-
-extern int read_vtoc(int, struct vtoc *);
-extern int write_vtoc(int, struct vtoc *);
-extern int read_extvtoc(int, struct extvtoc *);
-extern int write_extvtoc(int, struct extvtoc *);
-
-#else
-
-extern int read_vtoc();
-extern int write_vtoc();
-extern int read_extvtoc();
-extern int write_extvtoc();
-
-#endif /* __STDC__ */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _SYS_VTOC_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/wmsum.h b/sys/contrib/openzfs/lib/libspl/include/sys/wmsum.h
index 0679af73ce91..36e37f9e17d4 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/wmsum.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/wmsum.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/sys/zone.h b/sys/contrib/openzfs/lib/libspl/include/sys/zone.h
index bbb964dcef22..f4037b4875a9 100644
--- a/sys/contrib/openzfs/lib/libspl/include/sys/zone.h
+++ b/sys/contrib/openzfs/lib/libspl/include/sys/zone.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/thread.h b/sys/contrib/openzfs/lib/libspl/include/thread.h
deleted file mode 100644
index 74694e23eed5..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/thread.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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 2009 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _LIBSPL_THREAD_H
-#define _LIBSPL_THREAD_H
-
-#endif /* _LIBSPL_THREAD_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/tzfile.h b/sys/contrib/openzfs/lib/libspl/include/tzfile.h
deleted file mode 100644
index 7bd4087cd5d1..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/tzfile.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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.
- */
-
-#ifndef _LIBSPL_TZFILE_H
-#define _LIBSPL_TZFILE_H
-
-#include <sys/tzfile.h>
-
-#endif /* _LIBSPL_TZFILE_H */
diff --git a/sys/contrib/openzfs/lib/libspl/include/ucred.h b/sys/contrib/openzfs/lib/libspl/include/ucred.h
deleted file mode 100644
index 8178fdec4c74..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/ucred.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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.
- */
-
-#ifndef _LIBSPL_UCRED_H
-#define _LIBSPL_UCRED_H
-
-typedef int ucred_t;
-
-#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/umem.h b/sys/contrib/openzfs/lib/libspl/include/umem.h
index 65f12595e64f..3e44610e4e21 100644
--- a/sys/contrib/openzfs/lib/libspl/include/umem.h
+++ b/sys/contrib/openzfs/lib/libspl/include/umem.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -83,6 +84,7 @@ const char *_umem_debug_init(void);
const char *_umem_options_init(void);
const char *_umem_logging_init(void);
+__attribute__((malloc, alloc_size(1)))
static inline void *
umem_alloc(size_t size, int flags)
{
@@ -95,11 +97,12 @@ umem_alloc(size_t size, int flags)
return (ptr);
}
+__attribute__((malloc, alloc_size(1)))
static inline void *
umem_alloc_aligned(size_t size, size_t align, int flags)
{
void *ptr = NULL;
- int rc = EINVAL;
+ int rc;
do {
rc = posix_memalign(&ptr, align, size);
@@ -116,6 +119,7 @@ umem_alloc_aligned(size_t size, size_t align, int flags)
return (ptr);
}
+__attribute__((malloc, alloc_size(1)))
static inline void *
umem_zalloc(size_t size, int flags)
{
@@ -129,9 +133,24 @@ umem_zalloc(size_t size, int flags)
}
static inline void
-umem_free(void *ptr, size_t size __maybe_unused)
+umem_free(const void *ptr, size_t size __maybe_unused)
{
- free(ptr);
+ free((void *)ptr);
+}
+
+/*
+ * umem_free_aligned was added for supporting portability
+ * with non-POSIX platforms that require a different free
+ * to be used with aligned allocations.
+ */
+static inline void
+umem_free_aligned(void *ptr, size_t size __maybe_unused)
+{
+#ifndef _WIN32
+ free((void *)ptr);
+#else
+ _aligned_free(ptr);
+#endif
}
static inline void
@@ -140,7 +159,7 @@ umem_nofail_callback(umem_nofail_callback_t *cb __maybe_unused)
static inline umem_cache_t *
umem_cache_create(
- char *name, size_t bufsize, size_t align,
+ const char *name, size_t bufsize, size_t align,
umem_constructor_t *constructor,
umem_destructor_t *destructor,
umem_reclaim_t *reclaim,
@@ -170,6 +189,7 @@ umem_cache_destroy(umem_cache_t *cp)
umem_free(cp, sizeof (umem_cache_t));
}
+__attribute__((malloc))
static inline void *
umem_cache_alloc(umem_cache_t *cp, int flags)
{
@@ -193,7 +213,10 @@ umem_cache_free(umem_cache_t *cp, void *ptr)
if (cp->cache_destructor)
cp->cache_destructor(ptr, cp->cache_private);
- umem_free(ptr, cp->cache_bufsize);
+ if (cp->cache_align != 0)
+ umem_free_aligned(ptr, cp->cache_bufsize);
+ else
+ umem_free(ptr, cp->cache_bufsize);
}
static inline void
diff --git a/sys/contrib/openzfs/lib/libspl/include/unistd.h b/sys/contrib/openzfs/lib/libspl/include/unistd.h
index 0246991b4b61..6d755eb8ad91 100644
--- a/sys/contrib/openzfs/lib/libspl/include/unistd.h
+++ b/sys/contrib/openzfs/lib/libspl/include/unistd.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/include/util/Makefile.am b/sys/contrib/openzfs/lib/libspl/include/util/Makefile.am
deleted file mode 100644
index ab553bc80313..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/util/Makefile.am
+++ /dev/null
@@ -1,3 +0,0 @@
-libspldir = $(includedir)/libspl
-libspl_HEADERS = \
- sscanf.h
diff --git a/sys/contrib/openzfs/lib/libspl/include/util/sscanf.h b/sys/contrib/openzfs/lib/libspl/include/util/sscanf.h
deleted file mode 100644
index ead36acaba3e..000000000000
--- a/sys/contrib/openzfs/lib/libspl/include/util/sscanf.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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 2010 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _LIBSPL_UTIL_SSCANF_H
-#define _LIBSPL_UTIL_SSCANF_H
-
-#endif
diff --git a/sys/contrib/openzfs/lib/libspl/include/zone.h b/sys/contrib/openzfs/lib/libspl/include/zone.h
index b0ac2d9bc610..f946c0f13f77 100644
--- a/sys/contrib/openzfs/lib/libspl/include/zone.h
+++ b/sys/contrib/openzfs/lib/libspl/include/zone.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -33,7 +34,17 @@
extern "C" {
#endif
-#define GLOBAL_ZONEID 0
+#ifdef __FreeBSD__
+#define GLOBAL_ZONEID 0
+#else
+/*
+ * Hardcoded in the kernel's root user namespace. A "better" way to get
+ * this would be by using ioctl_ns(2), but this would need to be performed
+ * recursively on NS_GET_PARENT and then NS_GET_USERNS. Also, that's only
+ * supported since Linux 4.9.
+ */
+#define GLOBAL_ZONEID 4026531837U
+#endif
extern zoneid_t getzoneid(void);
diff --git a/sys/contrib/openzfs/lib/libspl/libspl_impl.h b/sys/contrib/openzfs/lib/libspl/libspl_impl.h
index cda56e64c962..39392da09ef5 100644
--- a/sys/contrib/openzfs/lib/libspl/libspl_impl.h
+++ b/sys/contrib/openzfs/lib/libspl/libspl_impl.h
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/list.c b/sys/contrib/openzfs/lib/libspl/list.c
index 0f2f3731b235..f95b358153de 100644
--- a/sys/contrib/openzfs/lib/libspl/list.c
+++ b/sys/contrib/openzfs/lib/libspl/list.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -65,7 +66,8 @@ list_create(list_t *list, size_t size, size_t offset)
ASSERT(size > 0);
ASSERT(size >= offset + sizeof (list_node_t));
- list->list_size = size;
+ (void) size;
+
list->list_offset = offset;
list->list_head.next = list->list_head.prev = &list->list_head;
}
@@ -194,7 +196,6 @@ list_move_tail(list_t *dst, list_t *src)
list_node_t *dstnode = &dst->list_head;
list_node_t *srcnode = &src->list_head;
- ASSERT(dst->list_size == src->list_size);
ASSERT(dst->list_offset == src->list_offset);
if (list_empty(src))
diff --git a/sys/contrib/openzfs/lib/libspl/mkdirp.c b/sys/contrib/openzfs/lib/libspl/mkdirp.c
index fce2c1c82eb7..80198dfbecba 100644
--- a/sys/contrib/openzfs/lib/libspl/mkdirp.c
+++ b/sys/contrib/openzfs/lib/libspl/mkdirp.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/os/freebsd/getexecname.c b/sys/contrib/openzfs/lib/libspl/os/freebsd/getexecname.c
index 256b28c1b70e..49c0ce3a2432 100644
--- a/sys/contrib/openzfs/lib/libspl/os/freebsd/getexecname.c
+++ b/sys/contrib/openzfs/lib/libspl/os/freebsd/getexecname.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/os/freebsd/gethostid.c b/sys/contrib/openzfs/lib/libspl/os/freebsd/gethostid.c
index 7bd567fe61b5..bd0f3ee5a075 100644
--- a/sys/contrib/openzfs/lib/libspl/os/freebsd/gethostid.c
+++ b/sys/contrib/openzfs/lib/libspl/os/freebsd/gethostid.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/os/freebsd/getmntany.c b/sys/contrib/openzfs/lib/libspl/os/freebsd/getmntany.c
index 0ef24059e84f..baff124b4a40 100644
--- a/sys/contrib/openzfs/lib/libspl/os/freebsd/getmntany.c
+++ b/sys/contrib/openzfs/lib/libspl/os/freebsd/getmntany.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -36,6 +37,7 @@
#include <sys/sysmacros.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <libzutil.h>
int
getextmntent(const char *path, struct extmnttab *entry, struct stat64 *statbuf)
@@ -49,13 +51,13 @@ getextmntent(const char *path, struct extmnttab *entry, struct stat64 *statbuf)
if (stat64(path, statbuf) != 0) {
(void) fprintf(stderr, "cannot open '%s': %s\n",
- path, strerror(errno));
+ path, zfs_strerror(errno));
return (-1);
}
if (statfs(path, &sfs) != 0) {
(void) fprintf(stderr, "%s: %s\n", path,
- strerror(errno));
+ zfs_strerror(errno));
return (-1);
}
statfs2mnttab(&sfs, (struct mnttab *)entry);
diff --git a/sys/contrib/openzfs/lib/libspl/os/freebsd/mnttab.c b/sys/contrib/openzfs/lib/libspl/os/freebsd/mnttab.c
index bd3e3e4e3eef..5287da132966 100644
--- a/sys/contrib/openzfs/lib/libspl/os/freebsd/mnttab.c
+++ b/sys/contrib/openzfs/lib/libspl/os/freebsd/mnttab.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
* All rights reserved.
@@ -29,9 +30,6 @@
* functions.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/mntent.h>
@@ -39,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <ctype.h>
#include <errno.h>
+#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -66,14 +65,14 @@ mntopt(char **p)
}
char *
-hasmntopt(struct mnttab *mnt, char *opt)
+hasmntopt(struct mnttab *mnt, const char *opt)
{
char tmpopts[MNT_LINE_MAX];
char *f, *opts = tmpopts;
if (mnt->mnt_mntopts == NULL)
return (NULL);
- (void) strcpy(opts, mnt->mnt_mntopts);
+ (void) strlcpy(opts, mnt->mnt_mntopts, MNT_LINE_MAX);
f = mntopt(&opts);
for (; *f; f = mntopt(&opts)) {
if (strncmp(opt, f, strlen(opt)) == 0)
@@ -91,16 +90,28 @@ optadd(char *mntopts, size_t size, const char *opt)
strlcat(mntopts, opt, size);
}
+static __thread char gfstypename[MFSNAMELEN];
+static __thread char gmntfromname[MNAMELEN];
+static __thread char gmntonname[MNAMELEN];
+static __thread char gmntopts[MNTMAXSTR];
+
void
statfs2mnttab(struct statfs *sfs, struct mnttab *mp)
{
- static char mntopts[MNTMAXSTR];
long flags;
- mntopts[0] = '\0';
+ strlcpy(gfstypename, sfs->f_fstypename, sizeof (gfstypename));
+ mp->mnt_fstype = gfstypename;
+
+ strlcpy(gmntfromname, sfs->f_mntfromname, sizeof (gmntfromname));
+ mp->mnt_special = gmntfromname;
+
+ strlcpy(gmntonname, sfs->f_mntonname, sizeof (gmntonname));
+ mp->mnt_mountp = gmntonname;
flags = sfs->f_flags;
-#define OPTADD(opt) optadd(mntopts, sizeof (mntopts), (opt))
+ gmntopts[0] = '\0';
+#define OPTADD(opt) optadd(gmntopts, sizeof (gmntopts), (opt))
if (flags & MNT_RDONLY)
OPTADD(MNTOPT_RO);
else
@@ -121,12 +132,10 @@ statfs2mnttab(struct statfs *sfs, struct mnttab *mp)
else
OPTADD(MNTOPT_EXEC);
#undef OPTADD
- mp->mnt_special = strdup(sfs->f_mntfromname);
- mp->mnt_mountp = strdup(sfs->f_mntonname);
- mp->mnt_fstype = strdup(sfs->f_fstypename);
- mp->mnt_mntopts = strdup(mntopts);
+ mp->mnt_mntopts = gmntopts;
}
+static pthread_rwlock_t gsfs_lock = PTHREAD_RWLOCK_INITIALIZER;
static struct statfs *gsfs = NULL;
static int allfs = 0;
@@ -136,6 +145,8 @@ statfs_init(void)
struct statfs *sfs;
int error;
+ (void) pthread_rwlock_wrlock(&gsfs_lock);
+
if (gsfs != NULL) {
free(gsfs);
gsfs = NULL;
@@ -153,6 +164,7 @@ statfs_init(void)
sfs = realloc(gsfs, allfs * sizeof (gsfs[0]));
if (sfs != NULL)
gsfs = sfs;
+ (void) pthread_rwlock_unlock(&gsfs_lock);
return (0);
fail:
error = errno;
@@ -160,19 +172,21 @@ fail:
free(gsfs);
gsfs = NULL;
allfs = 0;
+ (void) pthread_rwlock_unlock(&gsfs_lock);
return (error);
}
int
getmntany(FILE *fd __unused, struct mnttab *mgetp, struct mnttab *mrefp)
{
- // struct statfs *sfs;
int i, error;
error = statfs_init();
if (error != 0)
return (error);
+ (void) pthread_rwlock_rdlock(&gsfs_lock);
+
for (i = 0; i < allfs; i++) {
if (mrefp->mnt_special != NULL &&
strcmp(mrefp->mnt_special, gsfs[i].f_mntfromname) != 0) {
@@ -187,15 +201,16 @@ getmntany(FILE *fd __unused, struct mnttab *mgetp, struct mnttab *mrefp)
continue;
}
statfs2mnttab(&gsfs[i], mgetp);
+ (void) pthread_rwlock_unlock(&gsfs_lock);
return (0);
}
+ (void) pthread_rwlock_unlock(&gsfs_lock);
return (-1);
}
int
getmntent(FILE *fp, struct mnttab *mp)
{
- // struct statfs *sfs;
int error, nfs;
nfs = (int)lseek(fileno(fp), 0, SEEK_CUR);
@@ -207,9 +222,13 @@ getmntent(FILE *fp, struct mnttab *mp)
if (error != 0)
return (error);
}
- if (nfs >= allfs)
+ (void) pthread_rwlock_rdlock(&gsfs_lock);
+ if (nfs >= allfs) {
+ (void) pthread_rwlock_unlock(&gsfs_lock);
return (-1);
+ }
statfs2mnttab(&gsfs[nfs], mp);
+ (void) pthread_rwlock_unlock(&gsfs_lock);
if (lseek(fileno(fp), 1, SEEK_CUR) == -1)
return (errno);
return (0);
diff --git a/sys/contrib/openzfs/lib/libspl/os/freebsd/zone.c b/sys/contrib/openzfs/lib/libspl/os/freebsd/zone.c
index c07cb0532e16..d6f698207cd1 100644
--- a/sys/contrib/openzfs/lib/libspl/os/freebsd/zone.c
+++ b/sys/contrib/openzfs/lib/libspl/os/freebsd/zone.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
* All rights reserved.
diff --git a/sys/contrib/openzfs/lib/libspl/os/linux/getexecname.c b/sys/contrib/openzfs/lib/libspl/os/linux/getexecname.c
index a640556bcbec..dc4fe26ca550 100644
--- a/sys/contrib/openzfs/lib/libspl/os/linux/getexecname.c
+++ b/sys/contrib/openzfs/lib/libspl/os/linux/getexecname.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/os/linux/gethostid.c b/sys/contrib/openzfs/lib/libspl/os/linux/gethostid.c
index c04b7fd3eef3..d39f3dda3b8d 100644
--- a/sys/contrib/openzfs/lib/libspl/os/linux/gethostid.c
+++ b/sys/contrib/openzfs/lib/libspl/os/linux/gethostid.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -59,6 +60,7 @@ unsigned long
get_system_hostid(void)
{
unsigned long hostid = get_spl_hostid();
+ uint32_t system_hostid;
/*
* We do not use gethostid(3) because it can return a bogus ID,
@@ -69,8 +71,11 @@ get_system_hostid(void)
if (hostid == 0) {
int fd = open("/etc/hostid", O_RDONLY | O_CLOEXEC);
if (fd >= 0) {
- if (read(fd, &hostid, 4) < 0)
+ if (read(fd, &system_hostid, sizeof (system_hostid))
+ != sizeof (system_hostid))
hostid = 0;
+ else
+ hostid = system_hostid;
(void) close(fd);
}
}
diff --git a/sys/contrib/openzfs/lib/libspl/os/linux/getmntany.c b/sys/contrib/openzfs/lib/libspl/os/linux/getmntany.c
index d458b28ad309..ee1cdf59b9e5 100644
--- a/sys/contrib/openzfs/lib/libspl/os/linux/getmntany.c
+++ b/sys/contrib/openzfs/lib/libspl/os/linux/getmntany.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -38,6 +39,7 @@
#include <sys/sysmacros.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <libzutil.h>
#define BUFSIZE (MNT_LINE_MAX + 2)
@@ -83,13 +85,21 @@ _sol_getmntent(FILE *fp, struct mnttab *mgetp)
}
static int
-getextmntent_impl(FILE *fp, struct extmnttab *mp, int len)
+getextmntent_impl(FILE *fp, struct extmnttab *mp, uint64_t *mnt_id)
{
int ret;
struct stat64 st;
+ *mnt_id = 0;
ret = _sol_getmntent(fp, (struct mnttab *)mp);
if (ret == 0) {
+#ifdef HAVE_STATX_MNT_ID
+ struct statx stx;
+ if (statx(AT_FDCWD, mp->mnt_mountp,
+ AT_STATX_SYNC_AS_STAT | AT_SYMLINK_NOFOLLOW,
+ STATX_MNT_ID, &stx) == 0 && (stx.stx_mask & STATX_MNT_ID))
+ *mnt_id = stx.stx_mnt_id;
+#endif
if (stat64(mp->mnt_mountp, &st) != 0) {
mp->mnt_major = 0;
mp->mnt_minor = 0;
@@ -108,6 +118,12 @@ getextmntent(const char *path, struct extmnttab *entry, struct stat64 *statbuf)
struct stat64 st;
FILE *fp;
int match;
+ boolean_t have_mnt_id = B_FALSE;
+ uint64_t target_mnt_id = 0;
+ uint64_t entry_mnt_id;
+#ifdef HAVE_STATX_MNT_ID
+ struct statx stx;
+#endif
if (strlen(path) >= MAXPATHLEN) {
(void) fprintf(stderr, "invalid object; pathname too long\n");
@@ -122,10 +138,17 @@ getextmntent(const char *path, struct extmnttab *entry, struct stat64 *statbuf)
*/
if (stat64(path, statbuf) != 0) {
(void) fprintf(stderr, "cannot open '%s': %s\n",
- path, strerror(errno));
+ path, zfs_strerror(errno));
return (-1);
}
+#ifdef HAVE_STATX_MNT_ID
+ if (statx(AT_FDCWD, path, AT_STATX_SYNC_AS_STAT | AT_SYMLINK_NOFOLLOW,
+ STATX_MNT_ID, &stx) == 0 && (stx.stx_mask & STATX_MNT_ID)) {
+ have_mnt_id = B_TRUE;
+ target_mnt_id = stx.stx_mnt_id;
+ }
+#endif
if ((fp = fopen(MNTTAB, "re")) == NULL) {
(void) fprintf(stderr, "cannot open %s\n", MNTTAB);
@@ -137,12 +160,15 @@ getextmntent(const char *path, struct extmnttab *entry, struct stat64 *statbuf)
*/
match = 0;
- while (getextmntent_impl(fp, entry, sizeof (*entry)) == 0) {
- if (makedev(entry->mnt_major, entry->mnt_minor) ==
- statbuf->st_dev) {
- match = 1;
- break;
+ while (getextmntent_impl(fp, entry, &entry_mnt_id) == 0) {
+ if (have_mnt_id) {
+ match = (entry_mnt_id == target_mnt_id);
+ } else {
+ match = makedev(entry->mnt_major, entry->mnt_minor) ==
+ statbuf->st_dev;
}
+ if (match)
+ break;
}
(void) fclose(fp);
diff --git a/sys/contrib/openzfs/lib/libspl/os/linux/zone.c b/sys/contrib/openzfs/lib/libspl/os/linux/zone.c
index a71c4e0b275b..f1520676753e 100644
--- a/sys/contrib/openzfs/lib/libspl/os/linux/zone.c
+++ b/sys/contrib/openzfs/lib/libspl/os/linux/zone.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -23,10 +24,40 @@
* Use is subject to license terms.
*/
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+
#include <zone.h>
zoneid_t
-getzoneid()
+getzoneid(void)
{
- return (GLOBAL_ZONEID);
+ char path[PATH_MAX];
+ char buf[128] = { '\0' };
+ char *cp;
+
+ int c = snprintf(path, sizeof (path), "/proc/self/ns/user");
+ /* This API doesn't have any error checking... */
+ if (c < 0 || c >= sizeof (path))
+ return (GLOBAL_ZONEID);
+
+ ssize_t r = readlink(path, buf, sizeof (buf) - 1);
+ if (r < 0)
+ return (GLOBAL_ZONEID);
+
+ cp = strchr(buf, '[');
+ if (cp == NULL)
+ return (GLOBAL_ZONEID);
+ cp++;
+
+ unsigned long n = strtoul(cp, NULL, 10);
+ if (n == ULONG_MAX && errno == ERANGE)
+ return (GLOBAL_ZONEID);
+ zoneid_t z = (zoneid_t)n;
+
+ return (z);
}
diff --git a/sys/contrib/openzfs/lib/libspl/page.c b/sys/contrib/openzfs/lib/libspl/page.c
index 5b0d3f2e5786..6160a1de10cd 100644
--- a/sys/contrib/openzfs/lib/libspl/page.c
+++ b/sys/contrib/openzfs/lib/libspl/page.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -7,7 +8,7 @@
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/strlcat.c b/sys/contrib/openzfs/lib/libspl/strlcat.c
index 4528d875ed5e..6e4c3280a83a 100644
--- a/sys/contrib/openzfs/lib/libspl/strlcat.c
+++ b/sys/contrib/openzfs/lib/libspl/strlcat.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/strlcpy.c b/sys/contrib/openzfs/lib/libspl/strlcpy.c
index d483b91f6121..49ffa2db67c5 100644
--- a/sys/contrib/openzfs/lib/libspl/strlcpy.c
+++ b/sys/contrib/openzfs/lib/libspl/strlcpy.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
diff --git a/sys/contrib/openzfs/lib/libspl/timestamp.c b/sys/contrib/openzfs/lib/libspl/timestamp.c
index 22ecb3940739..0b0838f4b442 100644
--- a/sys/contrib/openzfs/lib/libspl/timestamp.c
+++ b/sys/contrib/openzfs/lib/libspl/timestamp.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -44,7 +45,7 @@ void
print_timestamp(uint_t timestamp_fmt)
{
time_t t = time(NULL);
- static char *fmt = NULL;
+ static const char *fmt = NULL;
/* We only need to retrieve this once per invocation */
if (fmt == NULL)
@@ -54,10 +55,53 @@ print_timestamp(uint_t timestamp_fmt)
(void) printf("%lld\n", (longlong_t)t);
} else if (timestamp_fmt == DDATE) {
char dstr[64];
+ struct tm tm;
int len;
- len = strftime(dstr, sizeof (dstr), fmt, localtime(&t));
+ len = strftime(dstr, sizeof (dstr), fmt, localtime_r(&t, &tm));
if (len > 0)
(void) printf("%s\n", dstr);
}
}
+
+/*
+ * Return timestamp as decimal reprentation (in string) of time_t
+ * value (-T u was specified) or in date(1) format (-T d was specified).
+ */
+void
+get_timestamp(uint_t timestamp_fmt, char *buf, int len)
+{
+ time_t t = time(NULL);
+ static const char *fmt = NULL;
+
+ /* We only need to retrieve this once per invocation */
+ if (fmt == NULL)
+ fmt = nl_langinfo(_DATE_FMT);
+
+ if (timestamp_fmt == UDATE) {
+ (void) snprintf(buf, len, "%lld", (longlong_t)t);
+ } else if (timestamp_fmt == DDATE) {
+ struct tm tm;
+ strftime(buf, len, fmt, localtime_r(&t, &tm));
+ }
+}
+
+/*
+ * Format the provided time stamp to human readable format
+ */
+void
+format_timestamp(time_t t, char *buf, int len)
+{
+ struct tm tm;
+ static const char *fmt = NULL;
+
+ if (t == 0) {
+ snprintf(buf, len, "-");
+ return;
+ }
+
+ /* We only need to retrieve this once per invocation */
+ if (fmt == NULL)
+ fmt = nl_langinfo(_DATE_FMT);
+ strftime(buf, len, fmt, localtime_r(&t, &tm));
+}
diff --git a/sys/contrib/openzfs/lib/libspl/tunables.c b/sys/contrib/openzfs/lib/libspl/tunables.c
new file mode 100644
index 000000000000..67dc9710dee8
--- /dev/null
+++ b/sys/contrib/openzfs/lib/libspl/tunables.c
@@ -0,0 +1,319 @@
+// SPDX-License-Identifier: CDDL-1.0
+/*
+ * 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 https://opensource.org/licenses/CDDL-1.0.
+ * 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 (c) 2025, Rob Norris <robn@despairlabs.com>
+ */
+
+#include <stddef.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <limits.h>
+#include <inttypes.h>
+#include <sys/tunables.h>
+
+/*
+ * Userspace tunables.
+ *
+ * Tunables are external pointers to global variables that are wired up to the
+ * host environment in some way that allows the operator to directly change
+ * their values "under the hood".
+ *
+ * In userspace, the "host environment" is the program using libzpool.so. So
+ * that it can manipulate tunables if it wants, we provide an API to access
+ * them.
+ *
+ * Tunables are declared through the ZFS_MODULE_PARAM* macros, which associate
+ * a global variable with some metadata we can use to describe and access the
+ * tunable. This is done by creating a uniquely-named zfs_tunable_t.
+ *
+ * At runtime, we need a way to discover these zfs_tunable_t items. Since they
+ * are declared globally, all over the codebase, there's no central place to
+ * record or list them. So, we take advantage of the compiler's "linker set"
+ * feature.
+ *
+ * In the ZFS_MODULE_PARAM macro, after we create the zfs_tunable_t, we also
+ * create a zfs_tunable_t* pointing to it. That pointer is forced into the
+ * "zfs_tunables" ELF section in compiled object. At link time, the linker will
+ * collect all these pointers into one single big "zfs_tunable" section, and
+ * will generate two new symbols in the final object: __start_zfs_tunable and
+ * __stop_zfs_tunable. These point to the first and last item in that section,
+ * which allows us to access the pointers in that section like an array, and
+ * through those pointers access the tunable metadata, and from there the
+ * actual C variable that the tunable describes.
+ */
+
+extern const zfs_tunable_t *__start_zfs_tunables;
+extern const zfs_tunable_t *__stop_zfs_tunables;
+
+/*
+ * Because there are no tunables in libspl itself, the above symbols will not
+ * be generated, which will stop libspl being linked at all. To work around
+ * that, we force a symbol into that section, and then when iterating, skip
+ * any NULL pointers.
+ */
+static void *__zfs_tunable__placeholder
+ __attribute__((__section__("zfs_tunables")))
+ __attribute__((__used__)) = NULL;
+
+/*
+ * Find the name tunable by walking through the linker set and comparing names,
+ * as described above. This is not particularly efficient but it's a fairly
+ * rare task, so it shouldn't be a big deal.
+ */
+const zfs_tunable_t *
+zfs_tunable_lookup(const char *name)
+{
+ for (const zfs_tunable_t **ztp = &__start_zfs_tunables;
+ ztp != &__stop_zfs_tunables; ztp++) {
+ const zfs_tunable_t *zt = *ztp;
+ if (zt == NULL)
+ continue;
+ if (strcmp(name, zt->zt_name) == 0)
+ return (zt);
+ }
+
+ return (NULL);
+}
+
+/*
+ * Like zfs_tunable_lookup, but call the provided callback for each tunable.
+ */
+void
+zfs_tunable_iter(zfs_tunable_iter_t cb, void *arg)
+{
+ for (const zfs_tunable_t **ztp = &__start_zfs_tunables;
+ ztp != &__stop_zfs_tunables; ztp++) {
+ const zfs_tunable_t *zt = *ztp;
+ if (zt == NULL)
+ continue;
+ if (cb(zt, arg))
+ return;
+ }
+}
+
+/*
+ * Parse a string into an int or uint. It's easier to have a pair of "generic"
+ * functions that clamp to a given min and max rather than have multiple
+ * functions for each width of type.
+ */
+static int
+zfs_tunable_parse_int(const char *val, intmax_t *np,
+ intmax_t min, intmax_t max)
+{
+ intmax_t n;
+ char *end;
+ errno = 0;
+ n = strtoimax(val, &end, 0);
+ if (errno != 0)
+ return (errno);
+ if (*end != '\0')
+ return (EINVAL);
+ if (n < min || n > max)
+ return (ERANGE);
+ *np = n;
+ return (0);
+}
+
+static int
+zfs_tunable_parse_uint(const char *val, uintmax_t *np,
+ uintmax_t min, uintmax_t max)
+{
+ uintmax_t n;
+ char *end;
+ errno = 0;
+ n = strtoumax(val, &end, 0);
+ if (errno != 0)
+ return (errno);
+ if (*end != '\0')
+ return (EINVAL);
+ if (strchr(val, '-'))
+ return (ERANGE);
+ if (n < min || n > max)
+ return (ERANGE);
+ *np = n;
+ return (0);
+}
+
+/*
+ * Set helpers for each tunable type. Parses the string, and if produces a
+ * valid value for the tunable, sets it. No effort is made to make sure the
+ * tunable is of the right type; that's done in zfs_tunable_set() below.
+ */
+static int
+zfs_tunable_set_int(const zfs_tunable_t *zt, const char *val)
+{
+ intmax_t n;
+ int err = zfs_tunable_parse_int(val, &n, INT_MIN, INT_MAX);
+ if (err != 0)
+ return (err);
+ *(int *)zt->zt_varp = n;
+ return (0);
+}
+
+static int
+zfs_tunable_set_uint(const zfs_tunable_t *zt, const char *val)
+{
+ uintmax_t n;
+ int err = zfs_tunable_parse_uint(val, &n, 0, UINT_MAX);
+ if (err != 0)
+ return (err);
+ *(unsigned int *)zt->zt_varp = n;
+ return (0);
+}
+
+static int
+zfs_tunable_set_ulong(const zfs_tunable_t *zt, const char *val)
+{
+ uintmax_t n;
+ int err = zfs_tunable_parse_uint(val, &n, 0, ULONG_MAX);
+ if (err != 0)
+ return (err);
+ *(unsigned long *)zt->zt_varp = n;
+ return (0);
+}
+
+static int
+zfs_tunable_set_u64(const zfs_tunable_t *zt, const char *val)
+{
+ uintmax_t n;
+ int err = zfs_tunable_parse_uint(val, &n, 0, UINT64_MAX);
+ if (err != 0)
+ return (err);
+ *(uint64_t *)zt->zt_varp = n;
+ return (0);
+}
+
+static int
+zfs_tunable_set_string(const zfs_tunable_t *zt, const char *val)
+{
+ (void) zt, (void) val;
+ /*
+ * We can't currently handle strings. String tunables are pointers
+ * into read-only memory, so we can update the pointer, but not the
+ * contents. That would mean taking an allocation, but we don't have
+ * an obvious place to free it.
+ *
+ * For now, it's no big deal as there's only a couple of string
+ * tunables anyway.
+ */
+ return (ENOTSUP);
+}
+
+/*
+ * Get helpers for each tunable type. Converts the value to a string if
+ * necessary and writes it into the provided buffer. The type is assumed to
+ * be correct; zfs_tunable_get() below will call the correct function for the
+ * type.
+ */
+static int
+zfs_tunable_get_int(const zfs_tunable_t *zt, char *val, size_t valsz)
+{
+ snprintf(val, valsz, "%d", *(int *)zt->zt_varp);
+ return (0);
+}
+
+static int
+zfs_tunable_get_uint(const zfs_tunable_t *zt, char *val, size_t valsz)
+{
+ snprintf(val, valsz, "%u", *(unsigned int *)zt->zt_varp);
+ return (0);
+}
+
+static int
+zfs_tunable_get_ulong(const zfs_tunable_t *zt, char *val, size_t valsz)
+{
+ snprintf(val, valsz, "%lu", *(unsigned long *)zt->zt_varp);
+ return (0);
+}
+
+static int
+zfs_tunable_get_u64(const zfs_tunable_t *zt, char *val, size_t valsz)
+{
+ snprintf(val, valsz, "%"PRIu64, *(uint64_t *)zt->zt_varp);
+ return (0);
+}
+
+static int
+zfs_tunable_get_string(const zfs_tunable_t *zt, char *val, size_t valsz)
+{
+ strlcpy(val, *(char **)zt->zt_varp, valsz);
+ return (0);
+}
+
+/* The public set function. Delegates to the type-specific version. */
+int
+zfs_tunable_set(const zfs_tunable_t *zt, const char *val)
+{
+ int err;
+ switch (zt->zt_type) {
+ case ZFS_TUNABLE_TYPE_INT:
+ err = zfs_tunable_set_int(zt, val);
+ break;
+ case ZFS_TUNABLE_TYPE_UINT:
+ err = zfs_tunable_set_uint(zt, val);
+ break;
+ case ZFS_TUNABLE_TYPE_ULONG:
+ err = zfs_tunable_set_ulong(zt, val);
+ break;
+ case ZFS_TUNABLE_TYPE_U64:
+ err = zfs_tunable_set_u64(zt, val);
+ break;
+ case ZFS_TUNABLE_TYPE_STRING:
+ err = zfs_tunable_set_string(zt, val);
+ break;
+ default:
+ err = EOPNOTSUPP;
+ break;
+ }
+ return (err);
+}
+
+/* The public get function. Delegates to the type-specific version. */
+int
+zfs_tunable_get(const zfs_tunable_t *zt, char *val, size_t valsz)
+{
+ int err;
+ switch (zt->zt_type) {
+ case ZFS_TUNABLE_TYPE_INT:
+ err = zfs_tunable_get_int(zt, val, valsz);
+ break;
+ case ZFS_TUNABLE_TYPE_UINT:
+ err = zfs_tunable_get_uint(zt, val, valsz);
+ break;
+ case ZFS_TUNABLE_TYPE_ULONG:
+ err = zfs_tunable_get_ulong(zt, val, valsz);
+ break;
+ case ZFS_TUNABLE_TYPE_U64:
+ err = zfs_tunable_get_u64(zt, val, valsz);
+ break;
+ case ZFS_TUNABLE_TYPE_STRING:
+ err = zfs_tunable_get_string(zt, val, valsz);
+ break;
+ default:
+ err = EOPNOTSUPP;
+ break;
+ }
+ return (err);
+}