mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
Fix send/recv lost spill block
When receiving a DRR_OBJECT record the receive_object() function needs to determine how to handle a spill block associated with the object. It may need to be removed or kept depending on how the object was modified at the source. This determination is currently accomplished using a heuristic which takes in to account the DRR_OBJECT record and the existing object properties. This is a problem because there isn't quite enough information available to do the right thing under all circumstances. For example, when only the block size changes the spill block is removed when it should be kept. What's needed to resolve this is an additional flag in the DRR_OBJECT which indicates if the object being received references a spill block. The DRR_OBJECT_SPILL flag was added for this purpose. When set then the object references a spill block and it must be kept. Either it is update to date, or it will be replaced by a subsequent DRR_SPILL record. Conversely, if the object being received doesn't reference a spill block then any existing spill block should always be removed. Since previous versions of ZFS do not understand this new flag additional DRR_SPILL records will be inserted in to the stream. This has the advantage of being fully backward compatible. Existing ZFS systems receiving this stream will recreate the spill block if it was incorrectly removed. Updated ZFS versions will correctly ignore the additional spill blocks which can be identified by checking for the DRR_SPILL_UNMODIFIED flag. The small downside to this approach is that is may increase the size of the stream and of the received snapshot on previous versions of ZFS. Additionally, when receiving streams generated by previous unpatched versions of ZFS spill blocks may still be lost. OpenZFS-issue: https://www.illumos.org/issues/9952 FreeBSD-issue: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=233277 Reviewed-by: Paul Dagnelie <pcd@delphix.com> Reviewed-by: Matt Ahrens <mahrens@delphix.com> Reviewed-by: Tom Caputi <tcaputi@datto.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #8668
This commit is contained in:
@@ -44,6 +44,7 @@ dist_pkgdata_SCRIPTS = \
|
||||
send_realloc_dnode_size.ksh \
|
||||
send_realloc_files.ksh \
|
||||
send_realloc_encrypted_files.ksh \
|
||||
send_spill_block.ksh \
|
||||
send_holds.ksh \
|
||||
send_hole_birth.ksh \
|
||||
send_mixed_raw.ksh \
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
. $STF_SUITE/include/libtest.shlib
|
||||
. $STF_SUITE/include/math.shlib
|
||||
. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
|
||||
. $STF_SUITE/tests/functional/rsend/rsend.cfg
|
||||
|
||||
#
|
||||
@@ -518,9 +519,13 @@ function churn_files
|
||||
value=$((RANDOM % 5))
|
||||
if [ $value -eq 0 -a $xattrs -ne 0 ]; then
|
||||
attrname="testattr$((RANDOM % 3))"
|
||||
attrlen="$(((RANDOM % 1000) + 1))"
|
||||
attrvalue="$(random_string VALID_NAME_CHAR \
|
||||
$attrlen)"
|
||||
attr -qr $attrname $file_name || \
|
||||
log_fail "Failed to remove $attrname"
|
||||
attr -qs $attrname -V TestValue $file_name || \
|
||||
attr -qs $attrname \
|
||||
-V "$attrvalue" $file_name || \
|
||||
log_fail "Failed to set $attrname"
|
||||
elif [ $value -eq 1 ]; then
|
||||
dd if=/dev/urandom of=$file_name \
|
||||
@@ -548,9 +553,12 @@ function churn_files
|
||||
if [ $xattrs -ne 0 ]; then
|
||||
for j in {0..2}; do
|
||||
attrname="testattr$j"
|
||||
attr -qs $attrname -V TestValue \
|
||||
$file_name || log_fail \
|
||||
"Failed to set $attrname"
|
||||
attrlen="$(((RANDOM % 1000) + 1))"
|
||||
attrvalue="$(random_string \
|
||||
VALID_NAME_CHAR $attrlen)"
|
||||
attr -qs $attrname \
|
||||
-V "$attrvalue" $file_name || \
|
||||
log_fail "Failed to set $attrname"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
@@ -791,10 +799,11 @@ function rand_set_prop
|
||||
log_must eval "zfs set $prop='$value' $dtst"
|
||||
}
|
||||
|
||||
# Generate a recursive checksum of a filesystems contents. Only file
|
||||
# data is included in the checksum (no meta data, or xattrs).
|
||||
# Generate a recursive checksum of a filesystem which includes the file
|
||||
# contents and any associated xattrs.
|
||||
function recursive_cksum
|
||||
{
|
||||
find $1 -type f -exec sha256sum {} \; | \
|
||||
find $1 -type f -exec sh -c 'sha256sum {}; getfattr \
|
||||
--absolute-names --only-values -d {} | sha256sum' \; | \
|
||||
sort -k 2 | awk '{ print $1 }' | sha256sum
|
||||
}
|
||||
|
||||
@@ -65,7 +65,16 @@ log_must eval "zfs recv $POOL/newfs < $BACKDIR/fs@snap${last_snap}"
|
||||
# Set atime=off to prevent the recursive_cksum from modifying newfs.
|
||||
log_must zfs set atime=off $POOL/newfs
|
||||
|
||||
for i in {1..5}; do
|
||||
# Due to reduced performance on debug kernels use fewer files by default.
|
||||
if is_kmemleak; then
|
||||
nr_files=100
|
||||
passes=2
|
||||
else
|
||||
nr_files=1000
|
||||
passes=3
|
||||
fi
|
||||
|
||||
for i in {1..$passes}; do
|
||||
# Randomly modify several dataset properties in order to generate
|
||||
# more interesting incremental send streams.
|
||||
rand_set_prop $POOL/fs checksum "off" "fletcher4" "sha256"
|
||||
@@ -76,12 +85,8 @@ for i in {1..5}; do
|
||||
|
||||
# Churn the filesystem in such a way that we're likely to be both
|
||||
# allocating and reallocating objects in the incremental stream.
|
||||
#
|
||||
# Disable xattrs until the following spill block issue is resolved:
|
||||
# https://github.com/openzfs/openzfs/pull/705
|
||||
#
|
||||
log_must churn_files 1000 524288 $POOL/fs 0
|
||||
expected_cksum=$(recursive_cksum /$fs)
|
||||
log_must churn_files $nr_files 524288 $POOL/fs
|
||||
expected_cksum=$(recursive_cksum /$POOL/fs)
|
||||
|
||||
# Create a snapshot and use it to send an incremental stream.
|
||||
this_snap=$((last_snap + 1))
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
# e) Destroy the incremental stream and old snapshot.
|
||||
#
|
||||
|
||||
verify_runnable "both"
|
||||
|
||||
log_assert "Verify incremental receive handles reallocation"
|
||||
|
||||
function cleanup
|
||||
@@ -56,7 +58,16 @@ log_must eval "zfs recv $POOL/newfs < $BACKDIR/fs@snap${last_snap}"
|
||||
# Set atime=off to prevent the recursive_cksum from modifying newfs.
|
||||
log_must zfs set atime=off $POOL/newfs
|
||||
|
||||
for i in {1..5}; do
|
||||
# Due to reduced performance on debug kernels use fewer files by default.
|
||||
if is_kmemleak; then
|
||||
nr_files=100
|
||||
passes=2
|
||||
else
|
||||
nr_files=1000
|
||||
passes=3
|
||||
fi
|
||||
|
||||
for i in {1..$passes}; do
|
||||
# Randomly modify several dataset properties in order to generate
|
||||
# more interesting incremental send streams.
|
||||
rand_set_prop $POOL/fs checksum "off" "fletcher4" "sha256"
|
||||
@@ -67,8 +78,8 @@ for i in {1..5}; do
|
||||
|
||||
# Churn the filesystem in such a way that we're likely to be both
|
||||
# allocating and reallocating objects in the incremental stream.
|
||||
log_must churn_files 1000 524288 $POOL/fs
|
||||
expected_cksum=$(recursive_cksum /$fs)
|
||||
log_must churn_files $nr_files 524288 $POOL/fs
|
||||
expected_cksum=$(recursive_cksum /$POOL/fs)
|
||||
|
||||
# Create a snapshot and use it to send an incremental stream.
|
||||
this_snap=$((last_snap + 1))
|
||||
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
#!/bin/ksh
|
||||
|
||||
#
|
||||
# This file and its contents are supplied under the terms of the
|
||||
# Common Development and Distribution License ("CDDL"), version 1.0.
|
||||
# You may only use this file in accordance with the terms of version
|
||||
# 1.0 of the CDDL.
|
||||
#
|
||||
# A full copy of the text of the CDDL should have accompanied this
|
||||
# source. A copy of the CDDL is also available via the Internet at
|
||||
# http://www.illumos.org/license/CDDL.
|
||||
#
|
||||
|
||||
#
|
||||
# Copyright (c) 2019 by Lawrence Livermore National Security, LLC.
|
||||
#
|
||||
|
||||
. $STF_SUITE/include/libtest.shlib
|
||||
. $STF_SUITE/tests/functional/rsend/rsend.kshlib
|
||||
|
||||
#
|
||||
# Description:
|
||||
# Verify spill blocks are correctly preserved.
|
||||
#
|
||||
# Strategy:
|
||||
# 1) Create a set of files each containing some file data.
|
||||
# 2) Add enough xattrs to the file to require a spill block.
|
||||
# 3) Snapshot and send these files to a new dataset.
|
||||
# 4) Modify the files and spill blocks in a variety of ways.
|
||||
# 5) Send the changes using an incremental send stream.
|
||||
# 6) Verify that all the xattrs (and thus the spill block) were
|
||||
# preserved when receiving the incremental stream.
|
||||
#
|
||||
|
||||
verify_runnable "both"
|
||||
|
||||
log_assert "Verify spill blocks are correctly preserved"
|
||||
|
||||
function cleanup
|
||||
{
|
||||
rm -f $BACKDIR/fs@*
|
||||
destroy_dataset $POOL/fs "-rR"
|
||||
destroy_dataset $POOL/newfs "-rR"
|
||||
}
|
||||
|
||||
attrvalue="abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
log_onexit cleanup
|
||||
|
||||
log_must zfs create $POOL/fs
|
||||
log_must zfs set xattr=sa $POOL/fs
|
||||
log_must zfs set dnodesize=legacy $POOL/fs
|
||||
log_must zfs set recordsize=128k $POOL/fs
|
||||
|
||||
# Create 40 files each with a spill block containing xattrs. Each file
|
||||
# will be modified in a different way to validate the incremental receive.
|
||||
for i in {1..40}; do
|
||||
file="/$POOL/fs/file$i"
|
||||
|
||||
log_must mkfile 16384 $file
|
||||
for j in {1..20}; do
|
||||
log_must attr -qs "testattr$j" -V "$attrvalue" $file
|
||||
done
|
||||
done
|
||||
|
||||
# Snapshot the pool and send it to the new dataset.
|
||||
log_must zfs snapshot $POOL/fs@snap1
|
||||
log_must eval "zfs send -e $POOL/fs@snap1 >$BACKDIR/fs@snap1"
|
||||
log_must eval "zfs recv $POOL/newfs < $BACKDIR/fs@snap1"
|
||||
|
||||
#
|
||||
# Modify file[1-6]'s contents but not the spill blocks.
|
||||
#
|
||||
# file1 - Increase record size; single block
|
||||
# file2 - Increase record size; multiple blocks
|
||||
# file3 - Truncate file to zero size; single block
|
||||
# file4 - Truncate file to smaller size; single block
|
||||
# file5 - Truncate file to much larger size; add holes
|
||||
# file6 - Truncate file to embedded size; embedded data
|
||||
#
|
||||
log_must mkfile 32768 /$POOL/fs/file1
|
||||
log_must mkfile 1048576 /$POOL/fs/file2
|
||||
log_must truncate -s 0 /$POOL/fs/file3
|
||||
log_must truncate -s 8192 /$POOL/fs/file4
|
||||
log_must truncate -s 1073741824 /$POOL/fs/file5
|
||||
log_must truncate -s 50 /$POOL/fs/file6
|
||||
|
||||
#
|
||||
# Modify file[11-16]'s contents and their spill blocks.
|
||||
#
|
||||
# file11 - Increase record size; single block
|
||||
# file12 - Increase record size; multiple blocks
|
||||
# file13 - Truncate file to zero size; single block
|
||||
# file14 - Truncate file to smaller size; single block
|
||||
# file15 - Truncate file to much larger size; add holes
|
||||
# file16 - Truncate file to embedded size; embedded data
|
||||
#
|
||||
log_must mkfile 32768 /$POOL/fs/file11
|
||||
log_must mkfile 1048576 /$POOL/fs/file12
|
||||
log_must truncate -s 0 /$POOL/fs/file13
|
||||
log_must truncate -s 8192 /$POOL/fs/file14
|
||||
log_must truncate -s 1073741824 /$POOL/fs/file15
|
||||
log_must truncate -s 50 /$POOL/fs/file16
|
||||
|
||||
for i in {11..20}; do
|
||||
log_must attr -qr testattr1 /$POOL/fs/file$i
|
||||
done
|
||||
|
||||
#
|
||||
# Modify file[21-26]'s contents and remove their spill blocks.
|
||||
#
|
||||
# file21 - Increase record size; single block
|
||||
# file22 - Increase record size; multiple blocks
|
||||
# file23 - Truncate file to zero size; single block
|
||||
# file24 - Truncate file to smaller size; single block
|
||||
# file25 - Truncate file to much larger size; add holes
|
||||
# file26 - Truncate file to embedded size; embedded data
|
||||
#
|
||||
log_must mkfile 32768 /$POOL/fs/file21
|
||||
log_must mkfile 1048576 /$POOL/fs/file22
|
||||
log_must truncate -s 0 /$POOL/fs/file23
|
||||
log_must truncate -s 8192 /$POOL/fs/file24
|
||||
log_must truncate -s 1073741824 /$POOL/fs/file25
|
||||
log_must truncate -s 50 /$POOL/fs/file26
|
||||
|
||||
for i in {21..30}; do
|
||||
for j in {1..20}; do
|
||||
log_must attr -qr testattr$j /$POOL/fs/file$i
|
||||
done
|
||||
done
|
||||
|
||||
#
|
||||
# Modify file[31-40]'s spill blocks but not the file contents.
|
||||
#
|
||||
for i in {31..40}; do
|
||||
file="/$POOL/fs/file$i"
|
||||
log_must attr -qr testattr$(((RANDOM % 20) + 1)) $file
|
||||
log_must attr -qs testattr$(((RANDOM % 20) + 1)) -V "$attrvalue" $file
|
||||
done
|
||||
|
||||
# Calculate the expected recursive checksum for the source.
|
||||
expected_cksum=$(recursive_cksum /$POOL/fs)
|
||||
|
||||
# Snapshot the pool and send the incremental snapshot.
|
||||
log_must zfs snapshot $POOL/fs@snap2
|
||||
log_must eval "zfs send -e -i $POOL/fs@snap1 $POOL/fs@snap2 >$BACKDIR/fs@snap2"
|
||||
log_must eval "zfs recv -F $POOL/newfs < $BACKDIR/fs@snap2"
|
||||
|
||||
# Validate the received copy using the received recursive checksum.
|
||||
actual_cksum=$(recursive_cksum /$POOL/newfs)
|
||||
if [[ "$expected_cksum" != "$actual_cksum" ]]; then
|
||||
log_fail "Checksums differ ($expected_cksum != $actual_cksum)"
|
||||
fi
|
||||
|
||||
log_pass "Verify spill blocks are correctly preserved"
|
||||
Reference in New Issue
Block a user