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 43verify_runnable "global" 44 45if is_linux && [[ $(linux_version) -lt $(linux_version "4.5") ]]; then 46 log_unsupported "copy_file_range not available before Linux 4.5" 47fi 48 49export VDIR=$TEST_BASE_DIR/disk-bclone 50export VDEV="$VDIR/a $VDIR/b $VDIR/c" 51export LDEV="$VDIR/e $VDIR/f" 52log_must rm -rf $VDIR 53log_must mkdir -p $VDIR 54log_must truncate -s $MINVDEVSIZE $VDEV $LDEV 55export PASSPHRASE="password" 56 57claim="The slogs are replayed correctly for encrypted cloned files." 58 59log_assert $claim 60 61function cleanup 62{ 63 datasetexists $TESTPOOL && destroy_pool $TESTPOOL 64 rm -rf $TESTDIR $VDIR $VDIR2 65} 66 67log_onexit cleanup 68 69# 70# 1. Create an encrypted file system (TESTFS) 71# 72log_must zpool create -o feature@block_cloning=enabled $TESTPOOL $VDEV \ 73 log mirror $LDEV 74log_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# 80log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/file1 \ 81 oflag=sync bs=128k count=4 82log_must zfs set recordsize=16K $TESTPOOL/$TESTFS 83log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/file2 \ 84 oflag=sync bs=16K count=2048 85sync_pool $TESTPOOL 86 87# 88# 3. Checkpoint for ZIL Replay 89# 90log_must zpool freeze $TESTPOOL 91 92# 93# 4. TX_CLONE_RANGE: Clone the file 94# 95log_must clonefile -f /$TESTPOOL/$TESTFS/file1 /$TESTPOOL/$TESTFS/clone1 96log_must clonefile -f /$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# 104log_must zfs unmount /$TESTPOOL/$TESTFS 105 106log_note "Verify transactions to replay:" 107log_must zdb -iv $TESTPOOL/$TESTFS 108 109log_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# 117log_must eval "echo $PASSPHRASE | zpool import -l -f -d $VDIR $TESTPOOL" 118 119# 120# 7. Compare clone file with the original file 121# 122log_must have_same_content /$TESTPOOL/$TESTFS/file1 /$TESTPOOL/$TESTFS/clone1 123log_must have_same_content /$TESTPOOL/$TESTFS/file2 /$TESTPOOL/$TESTFS/clone2 124 125typeset blocks=$(get_same_blocks $TESTPOOL/$TESTFS file1 \ 126 $TESTPOOL/$TESTFS clone1 $PASSPHRASE) 127log_must [ "$blocks" = "0 1 2 3" ] 128 129typeset blocks=$(get_same_blocks $TESTPOOL/$TESTFS file2 \ 130 $TESTPOOL/$TESTFS clone2 $PASSPHRASE) 131# FreeBSD's seq(1) leaves a trailing space, remove it with sed(1). 132log_must [ "$blocks" = "$(seq -s " " 0 2047 | sed 's/ $//')" ] 133 134log_pass $claim 135