5 # This file and its contents are supplied under the terms of the
6 # Common Development and Distribution License ("CDDL"), version 1.0.
7 # You may only use this file in accordance with the terms of version
10 # A full copy of the text of the CDDL should have accompanied this
11 # source. A copy of the CDDL is also available via the Internet at
12 # http://www.illumos.org/license/CDDL.
18 # Copyright (c) 2020 The FreeBSD Foundation [1]
20 # [1] Portions of this software were developed by Allan Jude
21 # under sponsorship from the FreeBSD Foundation.
23 . $STF_SUITE/include/libtest.shlib
27 # ZFS should receive a ZSTD compressed block and be able to determine the level
30 # 1. Create a ZSTD compressed dataset (random level)
31 # 2. Create and checksum a file on the compressed dataset
32 # 3. Snapshot the compressed dataset
33 # 4. Attempt to receive the snapshot into a new dataset
34 # 5. Verify the checksum of the file is the same as the original
35 # 6. Verify the compression level is correctly stored
38 verify_runnable "both"
42 datasetexists $TESTPOOL/$TESTFS1 && \
43 log_must zfs destroy -r $TESTPOOL/$TESTFS1
45 datasetexists $TESTPOOL/$TESTFS2 && \
46 log_must zfs destroy -r $TESTPOOL/$TESTFS2
51 log_assert "ZFS should track compression level when receiving a ZSTD stream"
53 typeset src_data="$STF_SUITE/tests/functional/cli_root/zfs_receive/zstd_test_data.txt"
54 typeset snap="$TESTPOOL/$TESTFS1@snap"
56 random_level=$((RANDOM%19 + 1))
57 log_note "Randomly selected ZSTD level: $random_level"
59 log_must zfs create -o compress=zstd-$random_level $TESTPOOL/$TESTFS1
60 # Make a 5kb compressible file
61 log_must cat $src_data $src_data $src_data $src_data $src_data \
62 > /$TESTPOOL/$TESTFS1/$TESTFILE0
63 typeset checksum=$(md5digest /$TESTPOOL/$TESTFS1/$TESTFILE0)
65 log_must zfs snapshot $snap
67 # get object number of file
68 listing=$(ls -i /$TESTPOOL/$TESTFS1/$TESTFILE0)
71 log_note "file /$TESTPOOL/$TESTFS1/$TESTFILE0 has object number $obj"
73 output=$(zdb -Zddddddbbbbbb $TESTPOOL/$TESTFS1 $obj 2> /dev/null \
74 |grep -m 1 "L0 DVA" |head -n1)
75 dva=$(sed -Ene 's/^.+DVA\[0\]=<([^>]+)>.*$/\1/p' <<< "$output")
76 log_note "block 0 of /$TESTPOOL/$TESTFS1/$TESTFILE0 has a DVA of $dva"
78 zstd_str=$(sed -Ene 's/^.+ ZSTD:size=([^:]+):version=([^:]+):level=([^:]+):.*$/\1:\2:\3/p' <<< "$output")
79 zstd_size1=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[1]}')
80 zstd_version1=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[2]}')
81 zstd_level1=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[3]}')
82 log_note "ZSTD src: size=$zstd_size1 version=$zstd_version1 level=$zstd_level1"
84 log_note "Verify ZFS can receive the ZSTD compressed stream"
85 log_must eval "zfs send -ec $snap | zfs receive $TESTPOOL/$TESTFS2"
87 typeset cksum1=$(md5digest /$TESTPOOL/$TESTFS2/$TESTFILE0)
88 [[ "$cksum1" == "$checksum" ]] || \
89 log_fail "Checksums differ ($cksum1 != $checksum)"
91 # get object number of file
92 listing=$(ls -i /$TESTPOOL/$TESTFS2/$TESTFILE0)
95 log_note "file /$TESTPOOL/$TESTFS2/$TESTFILE0 has object number $obj"
97 output=$(zdb -Zddddddbbbbbb $TESTPOOL/$TESTFS2 $obj 2> /dev/null \
98 |grep -m 1 "L0 DVA" |head -n1)
99 dva=$(sed -Ene 's/^.+DVA\[0\]=<([^>]+)>.*$/\1/p' <<< "$output")
100 log_note "block 0 of /$TESTPOOL/$TESTFS2/$TESTFILE0 has a DVA of $dva"
102 zstd_str=$(sed -Ene 's/^.+ ZSTD:size=([^:]+):version=([^:]+):level=([^:]+):.*$/\1:\2:\3/p' <<< "$output")
103 zstd_size2=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[1]}')
104 (( $zstd_size2 != $zstd_size1 )) && log_fail \
105 "ZFS recv failed: compressed size differs ($zstd_size2 != $zstd_size1)"
106 zstd_version2=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[2]}')
107 zstd_level2=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[3]}')
108 log_note "ZSTD dest: size=$zstd_size2 version=$zstd_version2 level=$zstd_level2"
109 (( $zstd_level2 != $zstd_level1 )) && log_fail \
110 "ZFS recv failed: compression level did not match header level ($zstd_level2 != $zstd_level1)"
112 log_pass "ZFS can receive a ZSTD stream and determine the compression level"