mirror_zfs/module/os/freebsd/zfs
Matthew Ahrens 7bcb7f0840
File incorrectly zeroed when receiving incremental stream that toggles -L
Background:

By increasing the recordsize property above the default of 128KB, a
filesystem may have "large" blocks.  By default, a send stream of such a
filesystem does not contain large WRITE records, instead it decreases
objects' block sizes to 128KB and splits the large blocks into 128KB
blocks, allowing the large-block filesystem to be received by a system
that does not support the `large_blocks` feature.  A send stream
generated by `zfs send -L` (or `--large-block`) preserves the large
block size on the receiving system, by using large WRITE records.

When receiving an incremental send stream for a filesystem with large
blocks, if the send stream's -L flag was toggled, a bug is encountered
in which the file's contents are incorrectly zeroed out.  The contents
of any blocks that were not modified by this send stream will be lost.
"Toggled" means that the previous send used `-L`, but this incremental
does not use `-L` (-L to no-L); or that the previous send did not use
`-L`, but this incremental does use `-L` (no-L to -L).

Changes:

This commit addresses the problem with several changes to the semantics
of zfs send/receive:

1. "-L to no-L" incrementals are rejected.  If the previous send used
`-L`, but this incremental does not use `-L`, the `zfs receive` will
fail with this error message:

    incremental send stream requires -L (--large-block), to match
    previous receive.

2. "no-L to -L" incrementals are handled correctly, preserving the
smaller (128KB) block size of any already-received files that used large
blocks on the sending system but were split by `zfs send` without the
`-L` flag.

3. A new send stream format flag is added, `SWITCH_TO_LARGE_BLOCKS`.
This feature indicates that we can correctly handle "no-L to -L"
incrementals.  This flag is currently not set on any send streams.  In
the future, we intend for incremental send streams of snapshots that
have large blocks to use `-L` by default, and these streams will also
have the `SWITCH_TO_LARGE_BLOCKS` feature set. This ensures that streams
from the default use of `zfs send` won't encounter the bug mentioned
above, because they can't be received by software with the bug.

Implementation notes:

To facilitate accessing the ZPL's generation number,
`zfs_space_delta_cb()` has been renamed to `zpl_get_file_info()` and
restructured to fill in a struct with ZPL-specific info including owner
and generation.

In the "no-L to -L" case, if this is a compressed send stream (from
`zfs send -cL`), large WRITE records that are being written to small
(128KB) blocksize files need to be decompressed so that they can be
written split up into multiple blocks.  The zio pipeline will recompress
each smaller block individually.

A new test case, `send-L_toggle`, is added, which tests the "no-L to -L"
case and verifies that we get an error for the "-L to no-L" case.

Reviewed-by: Paul Dagnelie <pcd@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes #6224 
Closes #10383
2020-06-09 10:41:01 -07:00
..
abd_os.c Gang ABD Type 2020-05-20 18:06:09 -07:00
arc_os.c Update FreeBSD tunables 2020-04-15 11:14:47 -07:00
crypto_os.c Fix crypto build on FreeBSD HEAD 2020-05-30 12:54:57 -07:00
dmu_os.c Use new FreeBSD API to largely eliminate object locking 2020-04-17 09:30:26 -07:00
hkdf.c Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
kmod_core.c Restore support for in-kernel ZFS ioctls 2020-06-08 13:57:22 -07:00
spa_os.c Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
spa_stats.c Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
sysctl_os.c Update FreeBSD tunables 2020-04-15 11:14:47 -07:00
vdev_file.c Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
vdev_geom.c Avoid the GEOM topology lock recursion when autoexpanding a pool 2020-05-04 15:10:41 -07:00
vdev_label_os.c Add support for boot environment data to be stored in the label 2020-05-07 09:36:33 -07:00
zfs_acl.c Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
zfs_ctldir.c Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
zfs_debug.c Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
zfs_dir.c Connect dataset_kstats for FreeBSD 2020-06-05 17:17:02 -07:00
zfs_file_os.c Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
zfs_fuid_os.c Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
zfs_ioctl_os.c Remove redundant includes 2020-06-08 09:57:36 -07:00
zfs_onexit_os.c Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
zfs_vfsops.c File incorrectly zeroed when receiving incremental stream that toggles -L 2020-06-09 10:41:01 -07:00
zfs_vnops.c Connect dataset_kstats for FreeBSD 2020-06-05 17:17:02 -07:00
zfs_znode.c Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
zio_crypt.c Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
zvol_os.c Connect dataset_kstats for FreeBSD 2020-06-05 17:17:02 -07:00