Skip to content

Commit 2ebb9a4

Browse files
ixhamzabehlendorf
authored andcommitted
ZTS: Add test cases for block cloning replay
Reviewed-by: Kay Pedersen <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes #15614
1 parent 5ff4396 commit 2ebb9a4

File tree

5 files changed

+272
-2
lines changed

5 files changed

+272
-2
lines changed

tests/runfiles/linux.run

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ tests = ['block_cloning_copyfilerange', 'block_cloning_copyfilerange_partial',
4343
'block_cloning_disabled_ficlonerange',
4444
'block_cloning_copyfilerange_cross_dataset',
4545
'block_cloning_cross_enc_dataset',
46-
'block_cloning_copyfilerange_fallback_same_txg']
46+
'block_cloning_copyfilerange_fallback_same_txg',
47+
'block_cloning_replay', 'block_cloning_replay_encrypted']
4748
tags = ['functional', 'block_cloning']
4849

4950
[tests/functional/chattr:Linux]

tests/test-runner/bin/zts-report.py.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ elif sys.platform.startswith('linux'):
301301
['SKIP', cfr_reason],
302302
'block_cloning/block_cloning_copyfilerange_fallback':
303303
['SKIP', cfr_reason],
304+
'block_cloning/block_cloning_replay':
305+
['SKIP', cfr_reason],
306+
'block_cloning/block_cloning_replay_encrypted':
307+
['SKIP', cfr_reason],
304308
'block_cloning/block_cloning_copyfilerange_cross_dataset':
305309
['SKIP', cfr_cross_reason],
306310
'block_cloning/block_cloning_copyfilerange_fallback_same_txg':
@@ -309,7 +313,6 @@ elif sys.platform.startswith('linux'):
309313
['SKIP', cfr_cross_reason],
310314
})
311315

312-
313316
# Not all Github actions runners have scsi_debug module, so we may skip
314317
# some tests which use it.
315318
if os.environ.get('CI') == 'true':

tests/zfs-tests/tests/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
452452
functional/block_cloning/block_cloning_ficlonerange.ksh \
453453
functional/block_cloning/block_cloning_ficlonerange_partial.ksh \
454454
functional/block_cloning/block_cloning_cross_enc_dataset.ksh \
455+
functional/block_cloning/block_cloning_replay.ksh \
456+
functional/block_cloning/block_cloning_replay_encrypted.ksh \
455457
functional/bootfs/bootfs_001_pos.ksh \
456458
functional/bootfs/bootfs_002_neg.ksh \
457459
functional/bootfs/bootfs_003_pos.ksh \
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/bin/ksh -p
2+
#
3+
# CDDL HEADER START
4+
#
5+
# The contents of this file are subject to the terms of the
6+
# Common Development and Distribution License (the "License").
7+
# You may not use this file except in compliance with the License.
8+
#
9+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
# or https://opensource.org/licenses/CDDL-1.0.
11+
# See the License for the specific language governing permissions
12+
# and limitations under the License.
13+
#
14+
# When distributing Covered Code, include this CDDL HEADER in each
15+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
# If applicable, add the following below this CDDL HEADER, with the
17+
# fields enclosed by brackets "[]" replaced with your own identifying
18+
# information: Portions Copyright [yyyy] [name of copyright owner]
19+
#
20+
# CDDL HEADER END
21+
#
22+
23+
. $STF_SUITE/include/libtest.shlib
24+
. $STF_SUITE/tests/functional/block_cloning/block_cloning.kshlib
25+
26+
#
27+
# DESCRIPTION:
28+
# Verify slogs are replayed correctly for cloned files. This
29+
# test is ported from slog_replay tests for block cloning.
30+
#
31+
# STRATEGY:
32+
# 1. Create an empty file system (TESTFS)
33+
# 2. Create regular files and sync
34+
# 3. Freeze TESTFS
35+
# 4. Clone the file
36+
# 5. Unmount filesystem
37+
# <At this stage TESTFS is frozen, the intent log contains a
38+
# complete set of deltas to replay it>
39+
# 6. Remount TESTFS <which replays the intent log>
40+
# 7. Compare clone file with the original file
41+
#
42+
43+
verify_runnable "global"
44+
45+
if [[ $(linux_version) -lt $(linux_version "4.5") ]]; then
46+
log_unsupported "copy_file_range not available before Linux 4.5"
47+
fi
48+
49+
export VDIR=$TEST_BASE_DIR/disk-bclone
50+
export VDEV="$VDIR/a $VDIR/b $VDIR/c"
51+
export LDEV="$VDIR/e $VDIR/f"
52+
log_must rm -rf $VDIR
53+
log_must mkdir -p $VDIR
54+
log_must truncate -s $MINVDEVSIZE $VDEV $LDEV
55+
56+
claim="The slogs are replayed correctly for cloned files."
57+
58+
log_assert $claim
59+
60+
function cleanup
61+
{
62+
datasetexists $TESTPOOL && destroy_pool $TESTPOOL
63+
rm -rf $TESTDIR $VDIR $VDIR2
64+
}
65+
66+
log_onexit cleanup
67+
68+
#
69+
# 1. Create an empty file system (TESTFS)
70+
#
71+
log_must zpool create -o feature@block_cloning=enabled $TESTPOOL $VDEV \
72+
log mirror $LDEV
73+
log_must zfs create $TESTPOOL/$TESTFS
74+
75+
#
76+
# 2. TX_WRITE: Create two files and sync txg
77+
#
78+
log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/file1 \
79+
oflag=sync bs=128k count=4
80+
log_must zfs set recordsize=16K $TESTPOOL/$TESTFS
81+
log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/file2 \
82+
oflag=sync bs=16K count=2048
83+
sync_pool $TESTPOOL
84+
85+
#
86+
# 3. Checkpoint for ZIL Replay
87+
#
88+
log_must zpool freeze $TESTPOOL
89+
90+
#
91+
# 4. TX_CLONE_RANGE: Clone the file
92+
#
93+
log_must clonefile -c /$TESTPOOL/$TESTFS/file1 /$TESTPOOL/$TESTFS/clone1
94+
log_must clonefile -c /$TESTPOOL/$TESTFS/file2 /$TESTPOOL/$TESTFS/clone2
95+
96+
#
97+
# 5. Unmount filesystem and export the pool
98+
#
99+
# At this stage TESTFS is frozen, the intent log contains a complete set
100+
# of deltas to replay for clone files.
101+
#
102+
log_must zfs unmount /$TESTPOOL/$TESTFS
103+
104+
log_note "Verify transactions to replay:"
105+
log_must zdb -iv $TESTPOOL/$TESTFS
106+
107+
log_must zpool export $TESTPOOL
108+
109+
#
110+
# 6. Remount TESTFS <which replays the intent log>
111+
#
112+
# Import the pool to unfreeze it and claim log blocks. It has to be
113+
# `zpool import -f` because we can't write a frozen pool's labels!
114+
#
115+
log_must zpool import -f -d $VDIR $TESTPOOL
116+
117+
#
118+
# 7. Compare clone file with the original file
119+
#
120+
log_must have_same_content /$TESTPOOL/$TESTFS/file1 /$TESTPOOL/$TESTFS/clone1
121+
log_must have_same_content /$TESTPOOL/$TESTFS/file2 /$TESTPOOL/$TESTFS/clone2
122+
123+
typeset blocks=$(get_same_blocks $TESTPOOL/$TESTFS file1 \
124+
$TESTPOOL/$TESTFS clone1)
125+
log_must [ "$blocks" = "0 1 2 3" ]
126+
127+
typeset blocks=$(get_same_blocks $TESTPOOL/$TESTFS file2 \
128+
$TESTPOOL/$TESTFS clone2)
129+
log_must [ "$blocks" = "$(seq -s " " 0 2047)" ]
130+
131+
log_pass $claim
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/bin/ksh -p
2+
#
3+
# CDDL HEADER START
4+
#
5+
# The contents of this file are subject to the terms of the
6+
# Common Development and Distribution License (the "License").
7+
# You may not use this file except in compliance with the License.
8+
#
9+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
# or https://opensource.org/licenses/CDDL-1.0.
11+
# See the License for the specific language governing permissions
12+
# and limitations under the License.
13+
#
14+
# When distributing Covered Code, include this CDDL HEADER in each
15+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
# If applicable, add the following below this CDDL HEADER, with the
17+
# fields enclosed by brackets "[]" replaced with your own identifying
18+
# information: Portions Copyright [yyyy] [name of copyright owner]
19+
#
20+
# CDDL HEADER END
21+
#
22+
23+
. $STF_SUITE/include/libtest.shlib
24+
. $STF_SUITE/tests/functional/block_cloning/block_cloning.kshlib
25+
26+
#
27+
# DESCRIPTION:
28+
# Verify slogs are replayed correctly for encrypted cloned files.
29+
# This test is ported from slog_replay tests for block cloning.
30+
#
31+
# STRATEGY:
32+
# 1. Create an encrypted file system (TESTFS)
33+
# 2. Create regular files and sync
34+
# 3. Freeze TESTFS
35+
# 4. Clone the file
36+
# 5. Unmount filesystem
37+
# <At this stage TESTFS is frozen, the intent log contains a
38+
# complete set of deltas to replay it>
39+
# 6. Remount encrypted TESTFS <which replays the intent log>
40+
# 7. Compare clone file with the original file
41+
#
42+
43+
verify_runnable "global"
44+
45+
if [[ $(linux_version) -lt $(linux_version "4.5") ]]; then
46+
log_unsupported "copy_file_range not available before Linux 4.5"
47+
fi
48+
49+
export VDIR=$TEST_BASE_DIR/disk-bclone
50+
export VDEV="$VDIR/a $VDIR/b $VDIR/c"
51+
export LDEV="$VDIR/e $VDIR/f"
52+
log_must rm -rf $VDIR
53+
log_must mkdir -p $VDIR
54+
log_must truncate -s $MINVDEVSIZE $VDEV $LDEV
55+
export PASSPHRASE="password"
56+
57+
claim="The slogs are replayed correctly for encrypted cloned files."
58+
59+
log_assert $claim
60+
61+
function cleanup
62+
{
63+
datasetexists $TESTPOOL && destroy_pool $TESTPOOL
64+
rm -rf $TESTDIR $VDIR $VDIR2
65+
}
66+
67+
log_onexit cleanup
68+
69+
#
70+
# 1. Create an encrypted file system (TESTFS)
71+
#
72+
log_must zpool create -o feature@block_cloning=enabled $TESTPOOL $VDEV \
73+
log mirror $LDEV
74+
log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \
75+
"-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS"
76+
77+
#
78+
# 2. TX_WRITE: Create two files and sync txg
79+
#
80+
log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/file1 \
81+
oflag=sync bs=128k count=4
82+
log_must zfs set recordsize=16K $TESTPOOL/$TESTFS
83+
log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/file2 \
84+
oflag=sync bs=16K count=2048
85+
sync_pool $TESTPOOL
86+
87+
#
88+
# 3. Checkpoint for ZIL Replay
89+
#
90+
log_must zpool freeze $TESTPOOL
91+
92+
#
93+
# 4. TX_CLONE_RANGE: Clone the file
94+
#
95+
log_must clonefile -c /$TESTPOOL/$TESTFS/file1 /$TESTPOOL/$TESTFS/clone1
96+
log_must clonefile -c /$TESTPOOL/$TESTFS/file2 /$TESTPOOL/$TESTFS/clone2
97+
98+
#
99+
# 5. Unmount filesystem and export the pool
100+
#
101+
# At this stage TESTFS is frozen, the intent log contains a complete set
102+
# of deltas to replay for clone files.
103+
#
104+
log_must zfs unmount /$TESTPOOL/$TESTFS
105+
106+
log_note "Verify transactions to replay:"
107+
log_must zdb -iv $TESTPOOL/$TESTFS
108+
109+
log_must zpool export $TESTPOOL
110+
111+
#
112+
# 6. Remount TESTFS <which replays the intent log>
113+
#
114+
# Import the pool to unfreeze it and claim log blocks. It has to be
115+
# `zpool import -f` because we can't write a frozen pool's labels!
116+
#
117+
log_must eval "echo $PASSPHRASE | zpool import -l -f -d $VDIR $TESTPOOL"
118+
119+
#
120+
# 7. Compare clone file with the original file
121+
#
122+
log_must have_same_content /$TESTPOOL/$TESTFS/file1 /$TESTPOOL/$TESTFS/clone1
123+
log_must have_same_content /$TESTPOOL/$TESTFS/file2 /$TESTPOOL/$TESTFS/clone2
124+
125+
typeset blocks=$(get_same_blocks $TESTPOOL/$TESTFS file1 \
126+
$TESTPOOL/$TESTFS clone1 $PASSPHRASE)
127+
log_must [ "$blocks" = "0 1 2 3" ]
128+
129+
typeset blocks=$(get_same_blocks $TESTPOOL/$TESTFS file2 \
130+
$TESTPOOL/$TESTFS clone2 $PASSPHRASE)
131+
log_must [ "$blocks" = "$(seq -s " " 0 2047)" ]
132+
133+
log_pass $claim

0 commit comments

Comments
 (0)