OpenZFS/src efbef9emodule/os/freebsd/zfs zfs_vnops_os.c zfs_znode.c, tests/test-runner/bin zts-report.py.in

FreeBSD: Add zfs_link_create() error handling

Originally Solaris didn't expect errors there, but they may happen
if we fail to add entry into ZAP.  Linux fixed it in #7421, but it
was never fully ported to FreeBSD.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Alexander Motin <mav at FreeBSD.org>
Sponsored-By: iXsystems, Inc.
Closes #13215
Closes #16138 
DeltaFile
+42-12module/os/freebsd/zfs/zfs_vnops_os.c
+0-1module/os/freebsd/zfs/zfs_znode.c
+1-0module/os/freebsd/zfs/zfs_dir.c
+0-1tests/test-runner/bin/zts-report.py.in
+43-144 files

OpenZFS/src fec16b9config zfs-build.m4

config/zfs-build.m4: add Alpine Linux bash-completion path

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: omni <omni+vagant at hack.org>
Closes #16164
DeltaFile
+1-1config/zfs-build.m4
+1-11 files

OpenZFS/src d0d7c0dconfig zfs-build.m4

config/zfs-build.m4: sort vendors

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: omni <omni+vagant at hack.org>
Closes #16164
DeltaFile
+49-47config/zfs-build.m4
+49-471 files

OpenZFS/src a043b60cmd/zstream zstream_recompress.c

Correct level handling in zstream recompress.

sscanf returns number of items parsed on success and EOF on failure.

Reviewed-by: Adam Moss <c at yotes.com>
Reviewed-by: Paul Dagnelie <pcd at delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: Rob Norris <robn at despairlabs.com>
Signed-off-by: Rich Ercolani <rincebrain at gmail.com>
Closes #16198 
DeltaFile
+1-1cmd/zstream/zstream_recompress.c
+1-11 files

OpenZFS/src e675852module/zfs dbuf.c

dbuf: separate refcount calls for dbuf and dbuf_user

In 92dc4ad83 I updated the dbuf_cache accounting to track the size of
userdata associated with dbufs. This adds the size of the dbuf+userdata
together in a single call to zfs_refcount_add_many(), but sometime
removes them in separate calls to zfs_refcount_remove_many(), if dbuf
and userdata are evicted separately.

What I didn't realise is that when refcount tracking is on,
zfs_refcount_add_many() and zfs_refcount_remove_many() are expected to
be paired, with their second & third args (count & holder) the same on
both sides. Splitting the remove part into two calls means the counts
don't match up, tripping a panic.

This commit fixes that, by always adding and removing the dbuf and
userdata counts separately.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.

    [4 lines not shown]
DeltaFile
+19-9module/zfs/dbuf.c
+19-91 files

OpenZFS/src 3c941d1cmd ztest.c, cmd/zdb zdb.c

zdb/ztest: send dbgmsg output to stderr

And, make the output fd an arg to zfs_dbgmsg_print(). This is a change
in behaviour, but keeps it consistent with where crash traces go, and
it's easy to argue this is what we want anyway; this is information
about the task, not the actual output of the task.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Rob Norris <rob.norris at klarasystems.com>
Closes #16181
DeltaFile
+12-13module/os/freebsd/zfs/zfs_debug.c
+9-10module/os/linux/zfs/zfs_debug.c
+2-2cmd/zdb/zdb.c
+2-2cmd/ztest.c
+1-1include/sys/zfs_debug.h
+26-285 files

OpenZFS/src fa99d9cmodule/os/freebsd/zfs zfs_debug.c, module/os/linux/zfs zfs_debug.c

zfs_dbgmsg_print: make FreeBSD and Linux consistent

FreeBSD was using fprintf(), which might not be signal-safe. Meanwhile,
Linux's locking did not cover the header output. This two quirks are
unrelated, but both have the same response: be like the other one. So
with this commit, both functions are the same except for the names of
their lock and list variables.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Rob Norris <rob.norris at klarasystems.com>
Closes #16181
DeltaFile
+20-4module/os/freebsd/zfs/zfs_debug.c
+2-1module/os/linux/zfs/zfs_debug.c
+22-52 files

OpenZFS/src 1ea8c59cmd ztest.c, cmd/zdb zdb.c

backtrace: rework for signal safety

Mostly, try a lot harder to not allocate anything.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Rob Norris <rob.norris at klarasystems.com>
Closes #16181
DeltaFile
+64-27lib/libspl/backtrace.c
+1-1cmd/ztest.c
+1-1lib/libspl/assert.c
+1-1lib/libspl/include/sys/backtrace.h
+1-1cmd/zdb/zdb.c
+68-315 files

OpenZFS/src 3974ef0lib/libnvpair libnvpair.abi, lib/libspl backtrace.c assert.c

libspl: lift backtrace into a separate file

If it's going to be used directly by zdb/ztest, then it sort of doesn't
make sense to carry it with the assert code.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Rob Norris <rob.norris at klarasystems.com>
Closes #16181
DeltaFile
+106-5lib/libnvpair/libnvpair.abi
+81-8lib/libzfs_core/libzfs_core.abi
+79-6lib/libuutil/libuutil.abi
+80-0lib/libspl/backtrace.c
+2-53lib/libspl/assert.c
+39-2lib/libzfs/libzfs.abi
+387-746 files not shown
+426-7912 files

OpenZFS/src e7b4519cmd ztest.c, cmd/zdb zdb.c

zdb/ztest: use libspl backtrace for crashes

We can show much nicer backtraces these days, lets use them.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Rob Norris <rob.norris at klarasystems.com>
Closes #16181
DeltaFile
+1-11cmd/ztest.c
+1-11cmd/zdb/zdb.c
+6-3lib/libspl/assert.c
+2-0lib/libspl/include/assert.h
+10-254 files

OpenZFS/src 91c46d4cmd/zdb zdb.c

zdb: bring crash handling over from ztest

ztest has a very nice ability to show a backtrace when there's an
unexpected crash. zdb is used often enough on corrupted data and can
blow up too, so nice output is useful there too.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Rob Norris <rob.norris at klarasystems.com>
Closes #16181
DeltaFile
+56-5cmd/zdb/zdb.c
+56-51 files

OpenZFS/src 0a543dbinclude/sys spa_impl.h, module/zfs spa.c zio.c

spa_taskq_dispatch_ent: simplify arguments

This renames it to spa_taskq_dispatch(), and reduces and simplifies its
arguments based on these observations from its two call sites:

- arg is always the zio, so it can be typed that way, and we don't need
  to provide it twice;
- ent is always &zio->io_tqent, and zio is always provided, so we can
  use it directly;
- the only flag used is TQ_FRONT, which can just be a bool;
- zio != NULL was part of the "use allocator" test, but it never would
  have got that far, because that arg was only set to NULL in the
  reexecute path, which is forced to type CLAIM, so the condition would
  fail at t == WRITE anyway.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: Alexander Motin <mav at FreeBSD.org>

    [2 lines not shown]
DeltaFile
+13-5module/zfs/spa.c
+4-13module/zfs/zio.c
+2-2include/sys/spa_impl.h
+19-203 files

OpenZFS/src 515c4ddmodule/zfs spa.c

spa: flatten spa_taskq_dispatch_ent()

It is the only user of spa_taskq_dispatch_select(), so might as well
just carry it directly.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: Alexander Motin <mav at FreeBSD.org>
Signed-off-by: Rob Norris <rob.norris at klarasystems.com>
Closes #16151
DeltaFile
+3-10module/zfs/spa.c
+3-101 files

OpenZFS/src adda768include/sys spa_impl.h, module/zfs spa.c

spa: remove spa_taskq_dispatch_sync()

It has no callers anymore.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: Alexander Motin <mav at FreeBSD.org>
Signed-off-by: Rob Norris <rob.norris at klarasystems.com>
Closes #16151
DeltaFile
+0-13module/zfs/spa.c
+0-2include/sys/spa_impl.h
+0-152 files

OpenZFS/src cc38691module/zfs zfs_ioctl.c

zfs_ioc_send: use a dedicated taskq thread for send

When stack space is tight, the stream is written to its target on a
separate taskq thread to make sure there's enough stack space to
complete it.

This has always used an IO taskq, but that doesn't really make sense for
it, and moving it onto a regular taskq lets us get rid of
spa_taskq_dispatch_sync(), which is not used anywhere else.

Stream writes may block for a long time depending on what the target is,
and we have no way of discovering this, so we can't risk using the
system taskq, as there may be many tens of sends in progress. Instead,
we create a dedicated taskq thread for each send writer to run on, and
clean it up when it's done.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>

    [3 lines not shown]
DeltaFile
+70-33module/zfs/zfs_ioctl.c
+70-331 files

OpenZFS/src b64afa4cmd/zed/agents zfs_mod.c, cmd/zfs zfs_main.c

Better control the thread pool size when mounting datasets

Ever since a10d50f999, ZFS has mounted file systems in parallel when
importing a pool.  It uses a fixed size of 512 for the thread pool.  But
since c183d164aa1, it has also imported pools in parallel.  So the total
number of threads at one time is 513 * npools + 1.  That can easily
exceed the system's limit on the number of threads per process, which
will cause one or more pools to be unable to allocate any worker
threads, forcing them to fallback to slow serial mounting .  To
forestall that, manage the threadpool size in /sbin/zpool, not libzfs.
Use the same size (512), but divided by the number of pools.

This is a backwards-incompatible change to the libzfs abi.

Sponsored by: Axcient
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: George Wilson <gwilson at delphix.com>
Signed-off-by: Alan Somers <asomers at FreeBSD.org>
Closes #16178
DeltaFile
+13-12lib/libzfs/libzfs_mount.c
+15-5cmd/zpool/zpool_main.c
+4-2cmd/zfs/zfs_main.c
+3-2include/libzfs.h
+2-1lib/libzfs/libzfs.abi
+1-1cmd/zed/agents/zfs_mod.c
+38-236 files

OpenZFS/src eced2e2lib/libzfs libzfs_mount.c

libzfs: Fix mounting datasets under thread limit pressure

During parallel zpool import, /sbin/zpool will create a separate thread
pool for each pool, used to mount that pool's datasets.  If the total
thread count exceed's the system's limit on threads per process, then
tpool_dispatch may fail.  If it does, directly execute the mount
operation instead.

Sponsored by: Axcient
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: George Wilson <gwilson at delphix.com>
Signed-off-by: Alan Somers <asomers at FreeBSD.org>
Closes #16178
Fixes #16172
DeltaFile
+4-1lib/libzfs/libzfs_mount.c
+4-11 files

OpenZFS/src f625d03lib/libtpool thread_pool.c

tpool_dispatch: fail if it cannot start at least 1 worker.

Sponsored by: Axcient
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: George Wilson <gwilson at delphix.com>
Signed-off-by: Alan Somers <asomers at FreeBSD.org>
Closes #16178
DeltaFile
+20-8lib/libtpool/thread_pool.c
+20-81 files

OpenZFS/src 89acef9module/zfs spa.c spa_misc.c

Simplified the scope of the namespace lock

If we wait until after we check for no spa references to drop the
namespace lock, then we know that spa consumers will need to call
spa_lookup() and end up waiting on the spa_namespace_cv until we
finish.  This narrows the external checks to spa_lookup and we no
longer need to worry about the spa_vdev_enter case.

Sponsored-By: Klara Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: George Wilson <gwilson at delphix.com>
Signed-off-by: Don Brady <don.brady at klarasystems.com>
Closes #16153
DeltaFile
+20-12module/zfs/spa.c
+2-19module/zfs/spa_misc.c
+22-312 files

OpenZFS/src 975a132cmd/zpool zpool_main.c, module/zfs spa_misc.c spa.c

Add support for parallel pool exports

Changed spa_export_common() such that it no longer holds the
spa_namespace_lock for the entire duration and instead sets
spa_export_thread to indicate an import is in progress on the
spa.  This allows for an export to a diffent pool to proceed
in parallel while an export is still processing potentially
long operations like spa_unload_log_sm_flush_all().

Calls like spa_lookup() and spa_vdev_enter() that rely on
the spa_namespace_lock to serialize them against a concurrent
export, now wait for any in-progress export thread to complete
before proceeding.

The 'zpool import -a' sub-command also provides multi-threaded
support, using a thread pool to submit the exports in parallel.

Sponsored-By: Klara Inc.
Sponsored-by: Wasabi Technology, Inc.

    [4 lines not shown]
DeltaFile
+129-0tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_parallel_pos.ksh
+82-6cmd/zpool/zpool_main.c
+72-0tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_parallel_admin.ksh
+40-10module/zfs/spa_misc.c
+29-7module/zfs/spa.c
+6-3module/zfs/vdev_initialize.c
+358-266 files not shown
+373-3312 files

OpenZFS/src abec7dcmodule/os/linux/spl spl-procfs-list.c, module/zfs dbuf.c

Linux: disable lockdep for a couple of locks

When running a debug kernel with lockdep enabled there
are several locks which report false positives.  Set
MUTEX_NOLOCKDEP/RW_NOLOCKDEP to disable these warnings.

Reviewed-by: Brian Atkinson <batkinson at lanl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Closes #16188 
DeltaFile
+3-3module/zfs/dbuf.c
+1-1module/os/linux/spl/spl-procfs-list.c
+4-42 files

OpenZFS/src 9edf6afcmd ztest.c, lib/libefi rdwr_efi.c

Replace P2ALIGN with P2ALIGN_TYPED and delete P2ALIGN.

In P2ALIGN, the result would be incorrect when align is unsigned
integer and x is larger than max value of the type of align.
In that case, -(align) would be a positive integer, which means
high bits would be zero and finally stay zero after '&' when
align is converted to a larger integer type.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: Youzhong Yang <yyang at mathworks.com>
Signed-off-by: Qiuhao Chen <chenqiuhao1997 at gmail.com>
Closes #15940
DeltaFile
+7-5cmd/ztest.c
+6-5module/zfs/vdev.c
+5-3module/zcommon/zfs_fletcher.c
+3-2module/zfs/dmu.c
+2-2module/zfs/metaslab.c
+2-2lib/libefi/rdwr_efi.c
+25-1910 files not shown
+40-2916 files

OpenZFS/src 136c053module/zfs zap.c

ZAP: Fix leaf references on zap_expand_leaf() errors

Depending on kind of error zap_expand_leaf() may return with or
without valid leaf reference held.  Make sure it returns NULL if
due to error it has no leaf to return.  Make its callers to check
the returned leaf pointer, and release the leaf if it is not NULL.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Alexander Motin <mav at FreeBSD.org>
Sponsored by:   iXsystems, Inc.
Closes #12366 
Closes #16159 
DeltaFile
+14-13module/zfs/zap.c
+14-131 files

OpenZFS/src 41ae864cmd ztest.c, lib/libefi rdwr_efi.c

Replace P2ALIGN with P2ALIGN_TYPED and delete P2ALIGN.

In P2ALIGN, the result would be incorrect when align is unsigned
integer and x is larger than max value of the type of align.
In that case, -(align) would be a positive integer, which means
high bits would be zero and finally stay zero after '&' when
align is converted to a larger integer type.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: Youzhong Yang <yyang at mathworks.com>
Signed-off-by: Qiuhao Chen <chenqiuhao1997 at gmail.com>
Closes #15940 
DeltaFile
+9-6cmd/ztest.c
+6-5module/zfs/vdev.c
+5-3module/zcommon/zfs_fletcher.c
+3-2module/zfs/dmu.c
+2-2module/zfs/metaslab.c
+2-2lib/libefi/rdwr_efi.c
+27-2011 files not shown
+44-3117 files

OpenZFS/src 1ede0c7lib/libspl Makefile.am

libspl_assert: always link -lpthread on FreeBSD

The pthread_* functions are in -lpthread on FreeBSD. Some of them are
implicitly linked through libc, but on FreeBSD 13 at least
pthread_getname_np() is not. Just be explicit, since -lpthread is the
documented interface anyway.

Sponsored-by: https://despairlabs.com/sponsor/
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Rob Norris <robn at despairlabs.com>
Closes #16168 
DeltaFile
+4-0lib/libspl/Makefile.am
+4-01 files

OpenZFS/src 414acbdlib/libspl assert.c

Unbreak FreeBSD cross-build on MacOS broken in 051460b8b

MacOS used FreeBSD-compatible getprogname() and pthread_getname_np().
But pthread_getthreadid_np() does not exist on MacOS. This implements
libspl_gettid() using pthread_threadid_np() to get the thread id
of the current thread.

Tested with FreeBSD GitHub actions
freebsd-src/.github/workflows/cross-bootstrap-tools.yml

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: Rob Norris <rob.norris at klarasystems.com>
Signed-off-by: Martin Matuska <mm at FreeBSD.org>
Closes #16167 
DeltaFile
+20-1lib/libspl/assert.c
+20-11 files

OpenZFS/src 3400127module/zfs zfs_log.c

Fix ZIL clone records for legacy holes

Previous code overengineered cloned range calculation by using
BP_GET_LSIZE(). The problem is that legacy holes don't have the
logical size, so result will be wrong.  But we also don't need
to look on every block size, since they all must be identical.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: Brian Atkinson <batkinson at lanl.gov>
Signed-off-by: Alexander Motin <mav at FreeBSD.org>
Sponsored by:   iXsystems, Inc.
Closes #16165 
DeltaFile
+3-5module/zfs/zfs_log.c
+3-51 files

OpenZFS/src af5dbedinclude/sys dsl_scan.h, module/zfs dsl_scan.c

Fix scn_queue races on very old pools

Code for pools before version 11 uses dmu_objset_find_dp() to scan
for children datasets/clones.  It calls enqueue_clones_cb() and
enqueue_cb() callbacks in parallel from multiple taskq threads.
It ends up bad for scan_ds_queue_insert(), corrupting scn_queue
AVL-tree.  Fix it by introducing a mutex to protect those two
scan_ds_queue_insert() calls.  All other calls are done from the
sync thread and so serialized.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: Brian Atkinson <batkinson at lanl.gov>
Signed-off-by: Alexander Motin <mav at FreeBSD.org>
Sponsored by:   iXsystems, Inc.
Closes #16162
DeltaFile
+6-0module/zfs/dsl_scan.c
+1-0include/sys/dsl_scan.h
+7-02 files

OpenZFS/src a0f3c8acmd/zdb zdb.c

zdb: add missing cleanup for early return

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: Don Brady <don.brady at klarasystems.com>
Reviewed-by: Alexander Motin <mav at FreeBSD.org>
Signed-off-by: Ameer Hamza <ahamza at ixsystems.com>
Closes #16152
DeltaFile
+53-25cmd/zdb/zdb.c
+53-251 files

OpenZFS/src 2dff752module/os/linux/spl spl-taskq.c, module/os/linux/zfs zvol_os.c vdev_disk.c

Replace usage of schedule_timeout with schedule_timeout_interruptible (#16150)

This commit replaces current usages of schedule_timeout() with
schedule_timeout_interruptible() in code paths that expect the running
task to sleep for a short period of time. When schedule_timeout() is
called without previously calling set_current_state(), the running
task never sleeps because the task state remains in TASK_RUNNING.

By calling schedule_timeout_interruptible() to set the task state to
TASK_INTERRUPTIBLE before calling schedule_timeout() we achieve the
intended/desired behavior of putting the task to sleep for the
specified timeout.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Daniel Perry <dtperry at amazon.com>
Closes #16150 
DeltaFile
+2-1module/os/linux/zfs/zvol_os.c
+1-1module/os/linux/spl/spl-taskq.c
+1-1module/os/linux/zfs/vdev_disk.c
+4-33 files