OpenZFS/src 546eca1config kernel-writeback.m4, module/os/linux/zfs zfs_vnops_os.c zpl_file.c

zpl: add HAVE_WRITEBACK_ITER and two separate zfs_putpage() implementations

Agent-Logs-Url: https://github.com/openzfs/zfs/sessions/0391b58c-83a1-430e-b0a7-ec34a79f7a31

Co-authored-by: behlendorf <148917+behlendorf at users.noreply.github.com>
DeltaFile
+265-40module/os/linux/zfs/zfs_vnops_os.c
+32-0config/kernel-writeback.m4
+6-8module/os/linux/zfs/zpl_file.c
+303-483 files

OpenZFS/src 0d4da47module/os/linux/zfs zfs_vnops_os.c zpl_file.c

fix(zpl): call folio_end_writeback() on all zfs_putpage() exit paths for Linux 6.12+

Agent-Logs-Url: https://github.com/openzfs/zfs/sessions/5813db17-0820-4c54-80ea-567ebb48146e

Co-authored-by: behlendorf <148917+behlendorf at users.noreply.github.com>
DeltaFile
+24-3module/os/linux/zfs/zfs_vnops_os.c
+19-2module/os/linux/zfs/zpl_file.c
+43-52 files

OpenZFS/src 8da4729module/zfs dsl_crypt.c arc.c

key lookup failure should always return EACCES

spa_do_crypt_abd() already maps a missing key to EACCES. However
spa_do_crypt_mac_abd(), spa_do_crypt_objset_mac_abd(), and
spa_crypt_get_salt() still return the raw
spa_keystore_lookup_key() error (ENOENT). This is inconsistent
As we want to treat all “no key” failures as a permission
failure. Standardize on EACCES for the unloaded-key case.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Alek Pinchuk <alek.pinchuk at connectwise.com>
Closes #18448
DeltaFile
+17-36module/zfs/dsl_crypt.c
+1-1module/zfs/arc.c
+18-372 files

OpenZFS/src 9dd3c65tests/zfs-tests/tests/functional/cli_user/zpool_iostat zpool_iostat_002_pos.ksh

ZTS: zpool_iostat_002_pos increase sleep time

Allow an additional second for the test to complete before checking
the results.  This may explain occasional test failures in the CI.
Additionally, when the test fails dump the tmpfile for inspection.

Reviewed-by: Tony Hutter <hutter2 at llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Closes #18455
DeltaFile
+4-3tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_002_pos.ksh
+4-31 files

OpenZFS/src 91f9b11tests/zfs-tests/tests/functional/redundancy redundancy.kshlib redundancy_draid_spare3.ksh

ZTS: add targeted redundancy_draid_spare exception

When sequentially resilvering a dRAID pool it's possible that a few
correctable checksum errors will be reported.  This is a known issue
which is occasionally observed in the CI.  Until it's resolved we
want the test case to tolerate a few checksum errors in this scenario
to prevent false positives in the CI.

This change also has the additional side effect of standardizing in
one location how the dRAID pool integrity is verified.

Reviewed-by: Tony Hutter <hutter2 at llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Issue #18307
Issue #18319
Closes #18436
DeltaFile
+75-1tests/zfs-tests/tests/functional/redundancy/redundancy.kshlib
+7-21tests/zfs-tests/tests/functional/redundancy/redundancy_draid_spare3.ksh
+2-12tests/zfs-tests/tests/functional/redundancy/redundancy_draid_damaged2.ksh
+4-8tests/zfs-tests/tests/functional/redundancy/redundancy_draid.ksh
+3-9tests/zfs-tests/tests/functional/redundancy/redundancy_draid_spare4.ksh
+2-6tests/zfs-tests/tests/functional/redundancy/redundancy_draid_spare1.ksh
+93-574 files not shown
+99-8010 files

OpenZFS/src fc6aa43module/os/linux/zfs zfs_uio.c

Fix 'kernel BUG at mm/usercopy.c'

Fix a bug where an cgroup-OOM-killed process can cause a panic:

usercopy: Kernel memory exposure attempt detected from vmalloc (offset
1007584, size 217120)!
kernel BUG at mm/usercopy.c:102!

This was caused by zfs_uiomove() not correctly returning EFAULT
for short copies.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Tony Hutter <hutter2 at llnl.gov>
Closes #15918
Closes #18408
DeltaFile
+10-3module/os/linux/zfs/zfs_uio.c
+10-31 files

OpenZFS/src 6758934tests/zfs-tests/tests/functional/snapshot snapshot_018_pos.ksh

ZTS: snapshot_018_pos.ksh add extra margin

The date(1) command and snapshot timestamps use different clock
sources which can result in a small discrepancy.  This can cause
the test the incorrectly fail.  To avoid this, add a brief delay
to the test case to allow for minor skew.

Reviewed-by: Tony Hutter <hutter2 at llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Closes #18450
DeltaFile
+5-0tests/zfs-tests/tests/functional/snapshot/snapshot_018_pos.ksh
+5-01 files

OpenZFS/src 60a7f64tests/zfs-tests/tests/functional/mmp mmp_on_uberblocks.ksh

ZTS: mmp_on_uberblocks.ksh simplify

The last portion of mmp_on_uberblocks.ksh was intended to verify that
the sequence number was incremented.  However, it failed to account for
the case where a txg sync would occur resulting in the sequence number
being correctly reset.

Rather than add additional code to detect this that check has been
removed.  The mmp update frequency is still verified via the kstat
which is a more reliably mechanism to detect the writes.  There are
several other mmp tests which verify the uberblock changes are reflected
on disk so there's no significant loss of test coverage.

Finally, the test case has been simplified to use the within_percent
function for readability.

Reviewed-by: Tony Hutter <hutter2 at llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Closes #18452
DeltaFile
+12-37tests/zfs-tests/tests/functional/mmp/mmp_on_uberblocks.ksh
+12-371 files

OpenZFS/src 207202ctests/zfs-tests/tests/functional/cli_root/zpool_trim zpool_trim_partial.ksh zpool_trim_verify_trimmed.ksh, tests/zfs-tests/tests/functional/trim trim_config.ksh autotrim_config.ksh

ZTS: fix trim test portability for FreeBSD

Replace GNU-specific du flags (--block-size, -B1) and dd conv=nocreat
with POSIX compatible commands. Move -O flag before pool name in
zpool create to align with FreeBSD's strict POSIX getopt(). Relax vdev
size thresholds in trim_config to account for ZFS-on-ZFS overhead.
Add sync_pool before zpool trim -w to ensure freed blocks are committed
before trimming.

Skip zpool_trim_partial, zpool_trim_verify_trimmed, trim_config, and
autotrim_config on FreeBSD where trim does not reclaim space on file
vdevs stored on a ZFS filesystem within the test framework.

Tested on FreeBSD 16.0-CURRENT: 26 PASS, 4 SKIP, 0 FAIL.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Christos Longros <chris.longros at gmail.com>
Closes #18398
DeltaFile
+11-7tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_partial.ksh
+10-4tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_verify_trimmed.ksh
+10-2tests/zfs-tests/tests/functional/trim/trim_config.ksh
+6-0tests/zfs-tests/tests/functional/trim/autotrim_config.ksh
+1-1tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_start_and_cancel_neg.ksh
+1-1tests/zfs-tests/tests/functional/trim/trim.kshlib
+39-151 files not shown
+40-167 files

OpenZFS/src 7f9a480tests/test-runner/bin zts-report.py.in, tests/zfs-tests/tests/functional/cli_root/zpool_trim setup.ksh

ZTS: remove outdated FreeBSD skip from trim tests

FreeBSD has supported hole punching via fspacectl(2) since
FreeBSD 14.0 and the test library already handles this using
truncate -d. Remove the skip that prevented trim tests from
running on FreeBSD.

Tests will still skip if the hardware does not support
TRIM/UNMAP, which is checked separately via diskinfo.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Christos Longros <chris.longros at gmail.com>
Closes #18398
DeltaFile
+0-4tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_trim_basic.ksh
+0-4tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_trim_flag.ksh
+0-4tests/zfs-tests/tests/functional/cli_root/zpool_wait/zpool_wait_trim_cancel.ksh
+0-3tests/test-runner/bin/zts-report.py.in
+0-1tests/zfs-tests/tests/functional/cli_root/zpool_trim/setup.ksh
+0-1tests/zfs-tests/tests/functional/trim/setup.ksh
+0-176 files

OpenZFS/src 3162c63tests/zfs-tests/tests/functional/cli_root/zpool_export zpool_export_parallel_admin.ksh

ZTS: zpool_export_parallel_admin.sh busy export

If the pool is active 'zpool export' will fail resulting in
a test failure.  Swap log_must with log_must_busy so the export
is retried when reported as busy before failing the test.

Reviewed-by: Tony Hutter <hutter2 at llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Closes #18447
DeltaFile
+1-1tests/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_parallel_admin.ksh
+1-11 files

OpenZFS/src 2eee4acinclude zfs_fletcher.h, lib/libzfs libzfs.abi

Fix: draid autopkgtests fail on s390x architecture (Endianness Issue)

The ioctl call to create the pool was returning -1 with errno EINVAL.
Inside the module code, inside vdev_draid.c, verify_perms is calling
fletcher_4_native_varsize. This in turn calls fletcher_4_scalar_native.
So, implemented a fletcher_4_byteswap_varsize which makes use of the
fletcher_4_scalar_byteswap in Big endian machines.

Reviewed-by: Andriy Tkachuk <andriy.tkachuk at gmail.com>
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Pranav P <pranavsdreams at gmail.com>
Closes #16261
Closes #18445
DeltaFile
+137-7lib/libzfs/libzfs.abi
+7-0module/zcommon/zfs_fletcher.c
+4-0module/zfs/vdev_draid.c
+2-0include/zfs_fletcher.h
+150-74 files

OpenZFS/src 513710emodule/os/freebsd/zfs zfs_vnops_os.c

Fix "panic: cache_vop_rename: lingering negative entry"

A FreeBSD ZFS filesystem with properties "utf8only=on" and
"normalization=formD" consistently produces this panic when
building the lang/perl-5.42.0 port.

A ZFS file system with "utf8only=off" and "normalization=none"
works fine.

The cause of the panic seems to be incorrectly using the FreeBSD
namecache when normalisation is present. This commit adds a
predicate to prevent that.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Jan Martin Mikkelsen <janm-github at transactionware.com>
Closes #18430
DeltaFile
+1-1module/os/freebsd/zfs/zfs_vnops_os.c
+1-11 files

OpenZFS/src 6562851cmd/zinject zinject.c, man/man4 zfs.4

Handle raidz errors <= nparity rather than ignoring

This PR adds a check in the mirror and raidz code for the case where 
there are errors <= nparity. In that case, ZFS sets a new flag on 
the zio that will be checked in zio_done. If that flag is set, when 
the write IO completes, we issue a read IO for the same blkptr. 
That will allow ZFS's auto-healing mechanisms and other errors 
recovery tools to detect the effectively-corrupt data, and handle 
it accordingly. Note that because draid raidz's IO done function, 
it also benefits from this functionality.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Paul Dagnelie <paul.dagnelie at klarasystems.com>
Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Closes #18387
DeltaFile
+94-0tests/zfs-tests/tests/functional/raidz/raidz_zinject.ksh
+34-4module/zfs/zio.c
+21-0module/zfs/vdev_raidz.c
+20-0tests/zfs-tests/include/libtest.shlib
+7-0man/man4/zfs.4
+5-2cmd/zinject/zinject.c
+181-65 files not shown
+188-911 files

OpenZFS/src f798b40.github/workflows/scripts qemu-1-setup.sh

CI: Add more debugging to qemu-1-setup.sh

- Remove line where we disable stdout at the end of qemu-1-setup.sh
- Fix comment switching the 2x75GB -> 1x150GB cases
- Add some more debug to the end of the script

Reviewed-by: Tino Reichardt <milky-zfs at mcmilk.de>
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Tony Hutter <hutter2 at llnl.gov>
Closes #18441
DeltaFile
+13-6.github/workflows/scripts/qemu-1-setup.sh
+13-61 files

OpenZFS/src 37e3a26module/zfs dmu_direct.c

dmu_direct: avoid UAF in dmu_write_direct_done()

dmu_write_direct_done() passes dmu_sync_arg_t to
dmu_sync_done(), which updates the override state and
frees the completion context. The Direct I/O error path
then still dereferences dsa->dsa_tx while rolling the
dirty record back with dbuf_undirty(), resulting in a
use-after-free.

Save dsa->dsa_tx in a local variable before calling
dmu_sync_done() and use that saved tx for the error
rollback. This preserves the existing ownership model
for dsa and does not change the Direct I/O write
semantics.

Reviewed-by: Brian Atkinson <batkinson at lanl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Co-authored-by: gality369 <gality369 at example.com>
Signed-off-by: ZhengYuan Huang <gality369 at gmail.com>
Closes #18440
DeltaFile
+7-1module/zfs/dmu_direct.c
+7-11 files

OpenZFS/src ddf19dccontrib/initramfs/scripts zfs

initramfs: fix incorrect variable rename

Fixes regression introduced by 61ab032ae0391bce38aef1e43b5b930724ecdb55.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Co-Authored-By: Claude Sonnet 4.6 <noreply at anthropic.com>
Signed-off-by: Joel Low <joel at joelsplace.sg>
Closes #18442
DeltaFile
+4-4contrib/initramfs/scripts/zfs
+4-41 files

OpenZFS/src c214a3acontrib/initramfs/scripts zfs

initramfs: fix use of renamed variables

Fixes regression introduced by 33dd57e1b4997c0e78e42bf340b2eed5ea954f64.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Co-Authored-By: Claude Sonnet 4.6 <noreply at anthropic.com>
Signed-off-by: Joel Low <joel at joelsplace.sg>
Closes #18442
DeltaFile
+2-2contrib/initramfs/scripts/zfs
+2-21 files

OpenZFS/src 1cebe8alib/libzfs libzfs_dataset.c

libzfs: report invalid permission name in zfs allow

zfs allow with a typo (e.g. "snapshop") produced the misleading
error "operation not applicable to datasets of this type".  Report
"invalid permission" instead.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: Tony Hutter <hutter2 at llnl.gov>
Signed-off-by: Christos Longros <chris.longros at gmail.com>
Closes #18401
Closes #11903
DeltaFile
+1-1lib/libzfs/libzfs_dataset.c
+1-11 files

OpenZFS/src 4339b4eman/man8 zpool-labelclear.8 zpool.8

zpool-labelclear.8: Warn that it's destructive

If I could go back in time, I would beg Sun engineers to pick a
different name. For those of us who have not read the ZFS On-Disk
Specification pdf, it is not at all obvious that clearing a "label" is
such a bad thing.

But changing the name would be a breaking change, so at least for now
we can update the documentation.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: Tony Hutter <hutter2 at llnl.gov>
Signed-off-by: Shelvacu <git at shelvacu.com>
Closes #18347
DeltaFile
+9-0man/man8/zpool-labelclear.8
+3-1man/man8/zpool.8
+12-12 files

OpenZFS/src 7fdd2bflib/libzfs/os/linux libzfs_mount_os.c

libzfs: report permission error from umount helper

Non-root callers got "unmount failed" when ZFS_MOUNT_HELPER was set
because /bin/umount's exit status doesn't preserve errno.  Map a
non-zero helper exit to EPERM when geteuid() != 0 so the user sees
"permission denied".

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Christos Longros <chris.longros at gmail.com>
Closes #11740
Closes #18443
DeltaFile
+5-1lib/libzfs/os/linux/libzfs_mount_os.c
+5-11 files

OpenZFS/src 9be5431.github/workflows/scripts qemu-8-summary.sh qemu-7-prepare.sh

CI: tolerate missing artifacts

When a VM fails to launch or is unreachable the qemu-7-prepare.sh
script will fail to collect the artifacts due to the missing vm*
directories.  We want to collect as much diagnostic information as
possible, when missing create the directory to allow the subsequent
steps to proceed normally.  Additionally, we don't want to fail
if the /tmp/summary.txt file is missing.

Reviewed-by: Tony Hutter <hutter2 at llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Closes #18438
DeltaFile
+5-3.github/workflows/scripts/qemu-8-summary.sh
+5-2.github/workflows/scripts/qemu-7-prepare.sh
+10-52 files

OpenZFS/src b3623d1.github/workflows/scripts qemu-1-setup.sh

CI: Do not set scheduler in qemu-1-setup.sh

We've seen some qemu-1-setup failures while trying to change the
runner's block device scheduler value to 'none':

  We have a single 150GB block device
  Setting up swapspace version 1, size = 16 GiB (17179865088 bytes)
  no label, UUID=7a790bfe-79e5-4e38-b208-9c63fe523294
  tee: '/sys/block/s*/queue/scheduler': No such file or directory

Luckily, we don't need to set the scheduler anymore on modern kernels:
https://github.com/openzfs/zfs/issues/9778#issuecomment-569347505

This commit just removes the code that sets the scheduler.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Tony Hutter <hutter2 at llnl.gov>
Closes #18437
DeltaFile
+0-5.github/workflows/scripts/qemu-1-setup.sh
+0-51 files

OpenZFS/src d88d9c9. META

Linux 7.0 compat: META

Update the META file to reflect compatibility with the 7.0
kernel.

Reviewed-by: Tony Hutter <hutter2 at llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Closes #18435
DeltaFile
+1-1META
+1-11 files

OpenZFS/src b32911btests/zfs-tests/tests/functional/replacement resilver_restart_001.ksh

ZTS: resilver_restart_001 improvements

The resilver_restart_001 test case has not been entirely reliable
when run under the CI.  Address several small issues which may be
responsible.

- Configure the pool as raidz2 instead of raidz1 since the test
  offlines two devices.  This ensures the second device is marked
  as OFFLINE instead of DEGRADED.

- Start the zpool replace after setting SCAN_SUSPEND_PROGRESS to
  close any potential race where the replace finishs to quickly.

- Wait for the offlines/onlined vdevs to fully transition to the
  expected state during the test.

- Add the true flag to sync_pool to force a TXG sync to happen
  even if it might not otherwise be required.


    [5 lines not shown]
DeltaFile
+12-7tests/zfs-tests/tests/functional/replacement/resilver_restart_001.ksh
+12-71 files

OpenZFS/src f37ed04.github/workflows zfs-qemu-packages.yml zfs-qemu.yml, .github/workflows/scripts qemu-7-prepare.sh qemu-9-summary-page.sh

CI: Disable ZIP file artifacts, update versions

The GH artifacts action now lets you disable auto-zipping your
artifacts.  Previously, GH would always automatically put your
artifacts in a ZIP file.  This is annoying when your artifacts
are already in a tarball.

Also update the following action versions

checkout:               v4 -> v6
upload-artifact:        v4 -> v7
download-artifact:      v4 -> v8

Lastly, fix a issue where zfs-qmeu-packages now needs to power
cycle the VM.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: George Melikov <mail at gmelikov.ru>
Signed-off-by: Tony Hutter <hutter2 at llnl.gov>
Closes #18411
DeltaFile
+12-11.github/workflows/zfs-qemu-packages.yml
+20-2.github/workflows/scripts/qemu-7-prepare.sh
+9-7.github/workflows/zfs-qemu.yml
+4-3.github/workflows/checkstyle.yaml
+3-3.github/workflows/zloop.yml
+3-1.github/workflows/scripts/qemu-9-summary-page.sh
+51-272 files not shown
+54-308 files

OpenZFS/src a42a717.github/workflows zfs-qemu-packages.yml zfs-qemu.yml, .github/workflows/scripts qemu-7-prepare.sh

CI: Disable ZIP file artifacts, update versions

The GH artifacts action now lets you disable auto-zipping your
artifacts.  Previously, GH would always automatically put your
artifacts in a ZIP file.  This is annoying when your artifacts
are already in a tarball.

Also update the following action versions

checkout:               v4 -> v6
upload-artifact:        v4 -> v7
download-artifact:      v4 -> v8

Lastly, fix a issue where zfs-qmeu-packages now needs to power
cycle the VM.

Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Reviewed-by: George Melikov <mail at gmelikov.ru>
Signed-off-by: Tony Hutter <hutter2 at llnl.gov>
Closes #18411
DeltaFile
+12-11.github/workflows/zfs-qemu-packages.yml
+20-2.github/workflows/scripts/qemu-7-prepare.sh
+9-7.github/workflows/zfs-qemu.yml
+4-3.github/workflows/checkstyle.yaml
+3-3.github/workflows/zloop.yml
+2-2.github/workflows/smatch.yml
+50-282 files not shown
+54-308 files

OpenZFS/src ba53ba5include/sys metaslab_impl.h metaslab.h, module/zfs metaslab.c spa_misc.c

Fix available space accounting for special/dedup (#18222)

Currently, spa_dspace (base to calculate dataset AVAIL) only includes
the normal allocation class capacity, but dd_used_bytes tracks space
allocated across all classes.  Since we don't want to report free
space of other classes as available (we can't promise new allocations
will be able to use it), report only allocated space, similar to how
we report space saved by dedup and block cloning.

Since we need deflated space here, make allocation classes track
deflated allocated space also.  While here, make mc_deferred also
deflated, matching its use contexts.  Also while there, use
atomic_load() to read the allocation class stats.

Reviewed-by: Rob Norris <robn at despairlabs.com>
Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
Signed-off-by: Alexander Motin <alexander.motin at TrueNAS.com>
Closes #18190
Closes #18222
DeltaFile
+47-23module/zfs/metaslab.c
+5-3include/sys/metaslab_impl.h
+4-1module/zfs/spa_misc.c
+2-3module/zfs/spa_log_spacemap.c
+2-2include/sys/metaslab.h
+1-1module/zfs/spa.c
+61-336 files

OpenZFS/src a78630ainclude/sys metaslab_impl.h metaslab.h, module/zfs metaslab.c spa_log_spacemap.c

Fix available space accounting for special/dedup

Currently, spa_dspace (base to calculate dataset AVAIL) only includes
the normal allocation class capacity, but dd_used_bytes tracks space
allocated across all classes.  Since we don't want to report free
space of other classes as available (we can't promise new allocations
will be able to use it), report only allocated space, similar to how
we report space saved by dedup and block cloning.
    
Since we need deflated space here, make allocation classes track
deflated allocated space also.  While here, make mc_deferred also
deflated, matching its use contexts.  Also while there, use
atomic_load() to read the allocation class stats.

NOTE: This is a backport of this relatively small and self-contained
fix to alleviate the issue.

Sponsored-by: Klara, Inc.
Sponsored-by: OSNexus

    [4 lines not shown]
DeltaFile
+47-23module/zfs/metaslab.c
+5-3include/sys/metaslab_impl.h
+2-3module/zfs/spa_log_spacemap.c
+5-0module/zfs/spa_misc.c
+2-2include/sys/metaslab.h
+1-1module/zfs/spa.c
+62-326 files

OpenZFS/src 1644e2fmodule/zfs dbuf.c, tests/runfiles common.run

Fix read corruption after block clone after truncate

When copy_file_range overwrites a recent truncation, subsequent reads
can incorrectly determine that it is read hole instead of reading the
cloned blocks.

This can happen when the following conditions are met:
- Truncate adds blkid to dn_free_ranges
- A new TXG is created
- copy_file_range calls dmu_brt_clone which override the block pointer
  and set DB_NOFILL
- Subsequent read, given DB_NOFILL, hits dbuf_read_impl and
  dbuf_read_hole
- dbuf_read_hole calls dnode_block_freed, which returns TRUE because the
  truncated blkids are still in dn_free_ranges

This will not happen if the clone and truncate are in the same TXG,
because the block clone would update the current TXG's dn_free_ranges,
which is why this bug only triggers under high IO load (such as

    [16 lines not shown]
DeltaFile
+117-0tests/zfs-tests/cmd/clone_after_trunc.c
+31-0tests/zfs-tests/tests/functional/block_cloning/block_cloning_after_trunc.ksh
+5-1module/zfs/dbuf.c
+2-1tests/runfiles/common.run
+2-0tests/zfs-tests/cmd/Makefile.am
+1-0tests/zfs-tests/tests/Makefile.am
+158-23 files not shown
+161-29 files