diff --git a/tests/zfs-tests/include/blkdev.shlib b/tests/zfs-tests/include/blkdev.shlib index 3f29d4f594a1..bcba8ee759c9 100644 --- a/tests/zfs-tests/include/blkdev.shlib +++ b/tests/zfs-tests/include/blkdev.shlib @@ -1,654 +1,654 @@ # # 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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # Copyright (c) 2012, 2019 by Delphix. All rights reserved. # Copyright 2016 Nexenta Systems, Inc. # Copyright (c) 2016, 2017 by Intel Corporation. All rights reserved. # Copyright (c) 2017 Lawrence Livermore National Security, LLC. # Copyright (c) 2017 Datto Inc. # Copyright (c) 2017 Open-E, Inc. All Rights Reserved. # Copyright 2019 Richard Elling # # # Returns SCSI host number for the given disk # function get_scsi_host #disk { typeset disk=$1 ls /sys/block/${disk}/device/scsi_device | cut -d : -f 1 } # # Cause a scan of all scsi host adapters by default # # $1 optional host number # function scan_scsi_hosts { typeset hostnum=${1} if is_linux; then if [[ -z $hostnum ]]; then for host in /sys/class/scsi_host/host*; do log_must eval "echo '- - -' > $host/scan" done else log_must eval \ "echo /sys/class/scsi_host/host$hostnum/scan" \ > /dev/null log_must eval \ "echo '- - -' > /sys/class/scsi_host/host$hostnum/scan" fi fi } # # Wait for newly created block devices to have their minors created. # Additional arguments can be passed to udevadm trigger, with the expected # arguments to typically be a block device pathname. This is useful when # checking waiting on a specific device to settle rather than triggering # all devices and waiting for them all to settle. # # The udevadm settle timeout can be 120 or 180 seconds by default for # some distros. If a long delay is experienced, it could be due to some # strangeness in a malfunctioning device that isn't related to the devices # under test. To help debug this condition, a notice is given if settle takes # too long. # # Note: there is no meaningful return code if udevadm fails. Consumers # should not expect a return code (do not call as argument to log_must) # function block_device_wait { if is_linux; then udevadm trigger $* typeset start=$SECONDS udevadm settle typeset elapsed=$((SECONDS - start)) [[ $elapsed > 60 ]] && \ log_note udevadm settle time too long: $elapsed elif is_freebsd; then if [[ ${#@} -eq 0 ]]; then # Do something that has to go through the geom event # queue to complete. sysctl kern.geom.conftxt >/dev/null return fi fi # Poll for the given paths to appear, but give up eventually. typeset -i i for (( i = 0; i < 5; ++i )); do typeset missing=false typeset dev for dev in "${@}"; do - if ! [[ -f $dev ]]; then + if ! [[ -e $dev ]]; then missing=true break fi done if ! $missing; then break fi sleep ${#@} done } # # Check if the given device is physical device # function is_physical_device #device { typeset device=${1#$DEV_DSKDIR/} device=${device#$DEV_RDSKDIR/} if is_linux; then is_disk_device "$DEV_DSKDIR/$device" && \ [[ -f /sys/module/loop/parameters/max_part ]] return $? elif is_freebsd; then is_disk_device "$DEV_DSKDIR/$device" && \ echo $device | egrep -q \ -e '^a?da[0-9]+$' \ -e '^md[0-9]+$' \ -e '^mfid[0-9]+$' \ -e '^nda[0-9]+$' \ -e '^nvd[0-9]+$' \ -e '^vtbd[0-9]+$' return $? else echo $device | egrep "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 return $? fi } # # Check if the given device is a real device (ie SCSI device) # function is_real_device #disk { typeset disk=$1 [[ -z $disk ]] && log_fail "No argument for disk given." if is_linux; then lsblk $DEV_RDSKDIR/$disk -o TYPE 2>/dev/null | \ egrep disk >/dev/null return $? fi } # # Check if the given device is a loop device # function is_loop_device #disk { typeset disk=$1 [[ -z $disk ]] && log_fail "No argument for disk given." if is_linux; then lsblk $DEV_RDSKDIR/$disk -o TYPE 2>/dev/null | \ egrep loop >/dev/null return $? fi } # # Linux: # Check if the given device is a multipath device and if there is a symbolic # link to a device mapper and to a disk # Currently no support for dm devices alone without multipath # # FreeBSD: # Check if the given device is a gmultipath device. # # Others: # No multipath detection. # function is_mpath_device #disk { typeset disk=$1 [[ -z $disk ]] && log_fail "No argument for disk given." if is_linux; then lsblk $DEV_MPATHDIR/$disk -o TYPE 2>/dev/null | \ egrep mpath >/dev/null if (($? == 0)); then readlink $DEV_MPATHDIR/$disk > /dev/null 2>&1 return $? else return $? fi elif is_freebsd; then is_disk_device $DEV_MPATHDIR/$disk else false fi } # # Check if the given path is the appropriate sort of device special node. # function is_disk_device #path { typeset path=$1 if is_freebsd; then # FreeBSD doesn't have block devices, only character devices. test -c $path else test -b $path fi } # Set the slice prefix for disk partitioning depending # on whether the device is a real, multipath, or loop device. # Currently all disks have to be of the same type, so only # checks first disk to determine slice prefix. # function set_slice_prefix { typeset disk typeset -i i=0 if is_linux; then while (( i < $DISK_ARRAY_NUM )); do disk="$(echo $DISKS | nawk '{print $(i + 1)}')" if ( is_mpath_device $disk ) && [[ -z $(echo $disk | awk 'substr($1,18,1)\ ~ /^[[:digit:]]+$/') ]] || ( is_real_device $disk ); then export SLICE_PREFIX="" return 0 elif ( is_mpath_device $disk || is_loop_device \ $disk ); then export SLICE_PREFIX="p" return 0 else log_fail "$disk not supported for partitioning." fi (( i = i + 1)) done fi } # # Set the directory path of the listed devices in $DISK_ARRAY_NUM # Currently all disks have to be of the same type, so only # checks first disk to determine device directory # default = /dev (linux) # real disk = /dev (linux) # multipath device = /dev/mapper (linux) # function set_device_dir { typeset disk typeset -i i=0 if is_linux; then while (( i < $DISK_ARRAY_NUM )); do disk="$(echo $DISKS | nawk '{print $(i + 1)}')" if is_mpath_device $disk; then export DEV_DSKDIR=$DEV_MPATHDIR return 0 else export DEV_DSKDIR=$DEV_RDSKDIR return 0 fi (( i = i + 1)) done else export DEV_DSKDIR=$DEV_RDSKDIR fi } # # Get the directory path of given device # function get_device_dir #device { typeset device=$1 if ! is_freebsd && ! is_physical_device $device; then if [[ $device != "/" ]]; then device=${device%/*} fi if is_disk_device "$DEV_DSKDIR/$device"; then device="$DEV_DSKDIR" fi echo $device else echo "$DEV_DSKDIR" fi } # # Get persistent name for given disk # function get_persistent_disk_name #device { typeset device=$1 typeset dev_id if is_linux; then if is_real_device $device; then dev_id="$(udevadm info -q all -n $DEV_DSKDIR/$device \ | egrep disk/by-id | nawk '{print $2; exit}' \ | nawk -F / '{print $3}')" echo $dev_id elif is_mpath_device $device; then dev_id="$(udevadm info -q all -n $DEV_DSKDIR/$device \ | egrep disk/by-id/dm-uuid \ | nawk '{print $2; exit}' \ | nawk -F / '{print $3}')" echo $dev_id else echo $device fi else echo $device fi } # # Online or offline a disk on the system # # First checks state of disk. Test will fail if disk is not properly onlined # or offlined. Online is a full rescan of SCSI disks by echoing to every # host entry. # function on_off_disk # disk state{online,offline} host { typeset disk=$1 typeset state=$2 typeset host=$3 [[ -z $disk ]] || [[ -z $state ]] && \ log_fail "Arguments invalid or missing" if is_linux; then if [[ $state == "offline" ]] && ( is_mpath_device $disk ); then dm_name="$(readlink $DEV_DSKDIR/$disk \ | nawk -F / '{print $2}')" dep="$(ls /sys/block/${dm_name}/slaves \ | nawk '{print $1}')" while [[ -n $dep ]]; do #check if disk is online lsscsi | egrep $dep > /dev/null if (($? == 0)); then dep_dir="/sys/block/${dm_name}" dep_dir+="/slaves/${dep}/device" ss="${dep_dir}/state" sd="${dep_dir}/delete" log_must eval "echo 'offline' > ${ss}" log_must eval "echo '1' > ${sd}" lsscsi | egrep $dep > /dev/null if (($? == 0)); then log_fail "Offlining" \ "$disk failed" fi fi dep="$(ls /sys/block/$dm_name/slaves \ 2>/dev/null | nawk '{print $1}')" done elif [[ $state == "offline" ]] && ( is_real_device $disk ); then #check if disk is online lsscsi | egrep $disk > /dev/null if (($? == 0)); then dev_state="/sys/block/$disk/device/state" dev_delete="/sys/block/$disk/device/delete" log_must eval "echo 'offline' > ${dev_state}" log_must eval "echo '1' > ${dev_delete}" lsscsi | egrep $disk > /dev/null if (($? == 0)); then log_fail "Offlining $disk" \ "failed" fi else log_note "$disk is already offline" fi elif [[ $state == "online" ]]; then #force a full rescan scan_scsi_hosts $host block_device_wait if is_mpath_device $disk; then dm_name="$(readlink $DEV_DSKDIR/$disk \ | nawk -F / '{print $2}')" dep="$(ls /sys/block/$dm_name/slaves \ | nawk '{print $1}')" lsscsi | egrep $dep > /dev/null if (($? != 0)); then log_fail "Onlining $disk failed" fi elif is_real_device $disk; then block_device_wait typeset -i retries=0 while ! lsscsi | egrep -q $disk; do if (( $retries > 2 )); then log_fail "Onlining $disk failed" break fi (( ++retries )) sleep 1 done else log_fail "$disk is not a real dev" fi else log_fail "$disk failed to $state" fi fi } # # Simulate disk removal # function remove_disk #disk { typeset disk=$1 on_off_disk $disk "offline" block_device_wait } # # Simulate disk insertion for the given SCSI host # function insert_disk #disk scsi_host { typeset disk=$1 typeset scsi_host=$2 on_off_disk $disk "online" $scsi_host block_device_wait } # # Load scsi_debug module with specified parameters # $blksz can be either one of: < 512b | 512e | 4Kn > # function load_scsi_debug # dev_size_mb add_host num_tgts max_luns blksz { typeset devsize=$1 typeset hosts=$2 typeset tgts=$3 typeset luns=$4 typeset blksz=$5 [[ -z $devsize ]] || [[ -z $hosts ]] || [[ -z $tgts ]] || \ [[ -z $luns ]] || [[ -z $blksz ]] && \ log_fail "Arguments invalid or missing" case "$5" in '512b') typeset sector=512 typeset blkexp=0 ;; '512e') typeset sector=512 typeset blkexp=3 ;; '4Kn') typeset sector=4096 typeset blkexp=0 ;; *) log_fail "Unsupported blksz value: $5" ;; esac if is_linux; then modprobe -n scsi_debug if (($? != 0)); then log_unsupported "Platform does not have scsi_debug" "module" fi lsmod | egrep scsi_debug > /dev/null if (($? == 0)); then log_fail "scsi_debug module already installed" else log_must modprobe scsi_debug dev_size_mb=$devsize \ add_host=$hosts num_tgts=$tgts max_luns=$luns \ sector_size=$sector physblk_exp=$blkexp block_device_wait lsscsi | egrep scsi_debug > /dev/null if (($? == 1)); then log_fail "scsi_debug module install failed" fi fi fi } # # Unload scsi_debug module, if needed. # function unload_scsi_debug { log_must_retry "in use" 5 modprobe -r scsi_debug } # # Get scsi_debug device name. # Returns basename of scsi_debug device (for example "sdb"). # function get_debug_device { for i in {1..10} ; do val=$(lsscsi | nawk '/scsi_debug/ {print $6; exit}' | cut -d / -f3) # lsscsi can take time to settle if [ "$val" != "-" ] ; then break fi sleep 1 done echo "$val" } # # Get actual devices used by the pool (i.e. linux sdb1 not sdb). # function get_pool_devices #testpool #devdir { typeset testpool=$1 typeset devdir=$2 typeset out="" if is_linux || is_freebsd; then out=$(zpool status -P $testpool |grep ${devdir} | awk '{print $1}') out=$(echo $out | sed -e "s|${devdir}/||g" | tr '\n' ' ') fi echo $out } # # Write to standard out giving the level, device name, offset and length # of all blocks in an input file. The offset and length are in units of # 512 byte blocks. In the case of mirrored vdevs, only the first # device is listed, as the levels, blocks and offsets will be the same # on other devices. Note that this function only works with mirrored # or non-redundant pools, not raidz. # # The output of this function can be used to introduce corruption at # varying levels of indirection. # function list_file_blocks # input_file { typeset input_file=$1 [[ -f $input_file ]] || log_fail "Couldn't find $input_file" typeset ds="$(zfs list -H -o name $input_file)" typeset pool="${ds%%/*}" typeset objnum="$(get_objnum $input_file)" # # Establish a mapping between vdev ids as shown in a DVA and the # pathnames they correspond to in ${VDEV_MAP[][]}. # # The vdev bits in a DVA refer to the top level vdev id. # ${VDEV_MAP[$id]} is an array of the vdev paths within that vdev. # eval $(zdb -C $pool | awk ' BEGIN { printf "typeset -a VDEV_MAP;" } function subscript(s) { # "[#]" is more convenient than the bare "#" match(s, /\[[0-9]*\]/) return substr(s, RSTART, RLENGTH) } id && !/^ / { # left a top level vdev id = 0 } id && $1 ~ /^path:$/ { # found a vdev path; save it in the map printf "VDEV_MAP%s%s=%s;", id, child, $2 } /^ children/ { # entering a top level vdev id = subscript($0) child = "[0]" # default in case there is no nested vdev printf "typeset -a VDEV_MAP%s;", id } /^ children/ { # entering a nested vdev (e.g. child of a top level mirror) child = subscript($0) } ') # # The awk below parses the output of zdb, printing out the level # of each block along with vdev id, offset and length. The last # two are converted to decimal in the while loop. 4M is added to # the offset to compensate for the first two labels and boot # block. Lastly, the offset and length are printed in units of # 512B blocks for ease of use with dd. # typeset level vdev path offset length if awk -n '' 2>/dev/null; then # gawk needs -n to decode hex AWK='awk -n' else AWK='awk' fi log_must zpool sync -f zdb -dddddd $ds $objnum | $AWK -v pad=$((4<<20)) -v bs=512 ' /^$/ { looking = 0 } looking { level = $2 field = 3 while (split($field, dva, ":") == 3) { # top level vdev id vdev = int(dva[1]) # offset + 4M label/boot pad in 512B blocks offset = (int("0x"dva[2]) + pad) / bs # length in 512B blocks len = int("0x"dva[3]) / bs print level, vdev, offset, len ++field } } /^Indirect blocks:/ { looking = 1 } ' | \ while read level vdev offset length; do for path in ${VDEV_MAP[$vdev][@]}; do echo "$level $path $offset $length" done done 2>/dev/null } function corrupt_blocks_at_level # input_file corrupt_level { typeset input_file=$1 typeset corrupt_level="L${2:-0}" typeset level path offset length [[ -f $input_file ]] || log_fail "Couldn't find $input_file" if is_freebsd; then # Temporarily allow corrupting an inuse device. debugflags=$(sysctl -n kern.geom.debugflags) sysctl kern.geom.debugflags=16 fi list_file_blocks $input_file | \ while read level path offset length; do if [[ $level = $corrupt_level ]]; then log_must dd if=/dev/urandom of=$path bs=512 \ count=$length seek=$offset conv=notrunc fi done if is_freebsd; then sysctl kern.geom.debugflags=$debugflags fi # This is necessary for pools made of loop devices. sync } diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib index e886de432af4..c2ccb24384a8 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib @@ -1,158 +1,158 @@ # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.cfg # # Compare the value of copies property with specified value # $1, the dataset name # $2, the expected copies value # function cmp_prop { typeset ds=$1 typeset val_expect=$2 typeset val_actual val_actual=$(get_prop copies $ds) if [[ $val_actual != $val_expect ]]; then log_fail "Expected value ($val_expect) != actual value " \ "($val_actual)" fi } # # Check the used space is charged correctly # $1, the number of used space # $2, the expected common factor between the used space and the file space # function check_used { typeset charged_spc=$1 typeset -i used typeset -i expected_cfactor=$2 typeset -i cfactor typeset -i fsize=${FILESIZE%[m|M]} ((used = $charged_spc / 1024 / 1024)) ((cfactor = used / fsize)) if ((cfactor != expected_cfactor)); then log_fail "The space is not charged correctly while setting" \ "copies as $expected_cfactor." fi } # # test ncopies on volume # $1 test type zfs|ufs|ext2 # $2 copies # $3 mntp for ufs|ext2 test function do_vol_test { typeset type=$1 typeset copies=$2 typeset mntp=$3 vol=$TESTPOOL/$TESTVOL1 vol_b_path=$ZVOL_DEVDIR/$TESTPOOL/$TESTVOL1 vol_r_path=$ZVOL_RDEVDIR/$TESTPOOL/$TESTVOL1 log_must zfs create -V $VOLSIZE -o copies=$copies $vol log_must zfs set refreservation=none $vol - block_device_wait + block_device_wait $vol_r_path case "$type" in "ext2") if is_freebsd; then log_unsupported "ext2 test not implemented for freebsd" fi log_must eval "new_fs $vol_r_path >/dev/null 2>&1" log_must mount -o rw $vol_b_path $mntp ;; "ufs") if is_linux; then log_unsupported "ufs test not implemented for linux" fi log_must eval "new_fs $vol_r_path >/dev/null 2>&1" log_must mount $vol_b_path $mntp ;; "zfs") if is_freebsd; then # Pool creation on zvols is forbidden by default. # Save and restore the current setting. typeset _saved=$(get_tunable VOL_RECURSIVE) log_must set_tunable64 VOL_RECURSIVE 1 # Allow zpool create $TESTPOOL1 $vol_b_path typeset _zpool_create_result=$? log_must set_tunable64 VOL_RECURSIVE $_saved # Restore log_must test $_zpool_create_result = 0 else log_must zpool create $TESTPOOL1 $vol_b_path fi log_must zfs create $TESTPOOL1/$TESTFS1 ;; *) log_unsupported "$type test not implemented" ;; esac ((nfilesize = copies * ${FILESIZE%m})) pre_used=$(get_prop used $vol) ((target_size = pre_used + nfilesize)) if [[ $type == "zfs" ]]; then log_must mkfile $FILESIZE /$TESTPOOL1/$TESTFS1/$FILE else log_must mkfile $FILESIZE $mntp/$FILE fi post_used=$(get_prop used $vol) ((retries = 0)) while ((post_used < target_size && retries++ < 42)); do sleep 1 post_used=$(get_prop used $vol) done ((used = post_used - pre_used)) if ((used < nfilesize)); then log_fail "The space is not charged correctly while setting" \ "copies as $copies ($used < $nfilesize)" \ "pre=${pre_used} post=${post_used}" fi if [[ $type == "zfs" ]]; then log_must zpool destroy $TESTPOOL1 else log_must umount $mntp fi log_must zfs destroy $vol } diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh index 3623d2bca1c9..0cacb7a98fa2 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh @@ -1,155 +1,155 @@ #!/bin/ksh -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib # # DESCRIPTION: # Rename dataset, verify that the data haven't changed. # # STRATEGY: # 1. Create random data and copy to dataset. # 2. Perform renaming commands. # 3. Verify that the data haven't changed. # verify_runnable "both" function cleanup { if datasetexists $TESTPOOL/$TESTFS ; then log_must zfs destroy -Rf $TESTPOOL/$TESTFS fi log_must zfs create $TESTPOOL/$TESTFS log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS rm -f $SRC_FILE $DST_FILE } function target_obj { typeset dtst=$1 typeset obj typeset type=$(get_prop type $dtst) if [[ $type == "filesystem" ]]; then obj=$(get_prop mountpoint $dtst)/${SRC_FILE##*/} elif [[ $type == "volume" ]]; then obj=$ZVOL_DEVDIR/$dtst fi echo $obj } log_assert "Rename dataset, verify that the data haven't changed." log_onexit cleanup # Generate random data # BS=512 ; CNT=2048 SRC_FILE=$TESTDIR/srcfile.$$ DST_FILE=$TESTDIR/dstfile.$$ log_must dd if=/dev/urandom of=$SRC_FILE bs=$BS count=$CNT fs=$TESTPOOL/$TESTFS/fs.$$ fsclone=$TESTPOOL/$TESTFS/fsclone.$$ log_must zfs create $fs obj=$(target_obj $fs) log_must cp $SRC_FILE $obj snap=${fs}@snap.$$ log_must zfs snapshot $snap log_must zfs clone $snap $fsclone # Rename dataset & clone # log_must zfs rename $fs ${fs}-new log_must zfs rename $fsclone ${fsclone}-new # Compare source file and target file # obj=$(target_obj ${fs}-new) log_must diff $SRC_FILE $obj obj=$(target_obj ${fsclone}-new) log_must diff $SRC_FILE $obj # Rename snapshot and re-clone dataset # log_must zfs rename ${fs}-new $fs log_must zfs rename $snap ${snap}-new log_must zfs clone ${snap}-new $fsclone # Compare source file and target file # obj=$(target_obj $fsclone) log_must diff $SRC_FILE $obj if is_global_zone; then vol=$TESTPOOL/$TESTFS/vol.$$ ; volclone=$TESTPOOL/$TESTFS/volclone.$$ log_must zfs create -V 100M $vol - block_device_wait obj=$(target_obj $vol) + block_device_wait $obj log_must dd if=$SRC_FILE of=$obj bs=$BS count=$CNT snap=${vol}@snap.$$ log_must zfs snapshot $snap log_must zfs clone $snap $volclone - block_device_wait # Rename dataset & clone log_must zfs rename $vol ${vol}-new log_must zfs rename $volclone ${volclone}-new - block_device_wait # Compare source file and target file obj=$(target_obj ${vol}-new) + block_device_wait $obj log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT log_must diff $SRC_FILE $DST_FILE obj=$(target_obj ${volclone}-new) + block_device_wait $obj log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT log_must diff $SRC_FILE $DST_FILE # Rename snapshot and re-clone dataset log_must zfs rename ${vol}-new $vol log_must zfs rename $snap ${snap}-new log_must zfs clone ${snap}-new $volclone - block_device_wait # Compare source file and target file obj=$(target_obj $volclone) + block_device_wait $obj log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT log_must diff $SRC_FILE $DST_FILE fi log_pass "Rename dataset, the data haven't changed passed." diff --git a/tests/zfs-tests/tests/functional/rsend/recv_dedup_encrypted_zvol.ksh b/tests/zfs-tests/tests/functional/rsend/recv_dedup_encrypted_zvol.ksh index 569fcd893e7d..daf559d264d9 100755 --- a/tests/zfs-tests/tests/functional/rsend/recv_dedup_encrypted_zvol.ksh +++ b/tests/zfs-tests/tests/functional/rsend/recv_dedup_encrypted_zvol.ksh @@ -1,60 +1,60 @@ #!/bin/ksh -p # # CDDL HEADER START # # 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. # # CDDL HEADER END # # # Copyright (c) 2020 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/rsend/rsend.kshlib # # DESCRIPTION: # Verifies that we can receive a dedup send stream of a zvol by processing it # with "zstream redup". # verify_runnable "both" function cleanup { destroy_dataset $TESTPOOL/recv "-r" rm $sendfile rm $volfile rm $keyfile } log_onexit cleanup log_assert "Verify zfs can receive raw, recursive, and deduplicated send streams" typeset keyfile=/$TESTPOOL/pkey typeset recvdev=$ZVOL_DEVDIR/$TESTPOOL/recv typeset sendfile_compressed=$STF_SUITE/tests/functional/rsend/dedup_encrypted_zvol.zsend.bz2 typeset sendfile=/$TESTPOOL/dedup_encrypted_zvol.zsend typeset volfile_compressed=$STF_SUITE/tests/functional/rsend/dedup_encrypted_zvol.bz2 typeset volfile=/$TESTPOOL/dedup_encrypted_zvol log_must eval "echo 'password' > $keyfile" log_must eval "bzcat <$sendfile_compressed >$sendfile" log_must eval "zstream redup $sendfile | zfs recv $TESTPOOL/recv" log_must zfs load-key $TESTPOOL/recv -block_device_wait +block_device_wait $volfile log_must eval "bzcat <$volfile_compressed >$volfile" log_must diff $volfile $recvdev log_pass "zfs can receive raw, recursive, and deduplicated send streams" diff --git a/tests/zfs-tests/tests/functional/rsend/send-c_stream_size_estimate.ksh b/tests/zfs-tests/tests/functional/rsend/send-c_stream_size_estimate.ksh index 840b5f085967..b3edb1c45788 100755 --- a/tests/zfs-tests/tests/functional/rsend/send-c_stream_size_estimate.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send-c_stream_size_estimate.ksh @@ -1,97 +1,97 @@ #!/bin/ksh -p # # 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) 2015, Delphix. All rights reserved. # . $STF_SUITE/tests/functional/rsend/rsend.kshlib . $STF_SUITE/include/properties.shlib # # Description: # Verify the stream size estimate given by -P accounts for compressed send. # Verify the stream size given by -P accounts for compressed send." # # Strategy: # 1. For datasets of varied compression types do the following: # 2. Write data, verify stream size estimates with and without -c # verify_runnable "both" typeset send_ds="$POOL2/testfs" typeset send_vol="$POOL2/vol" typeset send_voldev="$ZVOL_DEVDIR/$POOL2/vol" typeset file="$BACKDIR/file.0" typeset megs="16" typeset compress function get_estimated_size { typeset cmd=$1 typeset ds=${cmd##* } if is_freebsd; then mkdir -p $BACKDIR typeset tmpfile=$(TMPDIR=$BACKDIR mktemp) else typeset tmpfile=$(mktemp -p $BACKDIR) fi eval "$cmd >$tmpfile" [[ $? -eq 0 ]] || log_fail "get_estimated_size: $cmd" typeset size=$(eval "awk '\$2 == \"$ds\" {print \$3}' $tmpfile") rm -f $tmpfile echo $size } log_assert "Verify the stream size given by -P accounts for compressed send." log_onexit cleanup_pool $POOL2 write_compressible $BACKDIR ${megs}m for compress in "${compress_prop_vals[@]}"; do datasetexists $send_ds && log_must_busy zfs destroy -r $send_ds datasetexists $send_vol && log_must_busy zfs destroy -r $send_vol log_must zfs create -o compress=$compress $send_ds log_must zfs create -V 1g -o compress=$compress $send_vol - block_device_wait + block_device_wait $send_voldev typeset dir=$(get_prop mountpoint $send_ds) log_must cp $file $dir log_must zfs snapshot $send_ds@snap log_must dd if=$file of=$send_voldev log_must zfs snapshot $send_vol@snap typeset ds_size=$(get_estimated_size "zfs send -nP $send_ds@snap") typeset ds_lrefer=$(get_prop lrefer $send_ds) within_percent $ds_size $ds_lrefer 90 || log_fail \ "$ds_size and $ds_lrefer differed by too much" typeset vol_size=$(get_estimated_size "zfs send -nP $send_vol@snap") typeset vol_lrefer=$(get_prop lrefer $send_vol) within_percent $vol_size $vol_lrefer 90 || log_fail \ "$vol_size and $vol_lrefer differed by too much" typeset ds_csize=$(get_estimated_size "zfs send -nP -c $send_ds@snap") typeset ds_refer=$(get_prop refer $send_ds) within_percent $ds_csize $ds_refer 90 || log_fail \ "$ds_csize and $ds_refer differed by too much" typeset vol_csize=$(get_estimated_size "zfs send -nP -c $send_vol@snap") typeset vol_refer=$(get_prop refer $send_vol) within_percent $vol_csize $vol_refer 90 || log_fail \ "$vol_csize and $vol_refer differed by too much" done log_pass "The stream size given by -P accounts for compressed send." diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_004_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_004_pos.ksh index be72576707d2..cf1e6359bdb6 100755 --- a/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_004_pos.ksh @@ -1,76 +1,76 @@ #!/bin/ksh -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/zvol/zvol_common.shlib # # DESCRIPTION: # When a swap zvol is added its volsize does not change. # # STRATEGY: # 1. Determine what 1/4 arc_c_max is. # 2. Create a zvols in a variety of sizes. # 3. Add them as swap, and verify the volsize is not changed. # verify_runnable "global" function cleanup { is_swap_inuse $swapname && log_must swap_cleanup $swapname datasetexists $vol && log_must zfs destroy $vol } log_assert "For an added swap zvol, (2G <= volsize <= 16G)" log_onexit cleanup for vbs in 8192 16384 32768 65536 131072; do for multiplier in 32 16384 131072; do ((volsize = vbs * multiplier)) vol="$TESTPOOL/vol_$volsize" swapname="${ZVOL_DEVDIR}/$vol" # Create a sparse volume to test larger sizes log_must zfs create -s -b $vbs -V $volsize $vol - block_device_wait + block_device_wait $swapname log_must swap_setup $swapname new_volsize=$(get_prop volsize $vol) [[ $volsize -eq $new_volsize ]] || log_fail "$volsize $new_volsize" log_must swap_cleanup $swapname log_must_busy zfs destroy $vol done done log_pass "For an added swap zvol, (2G <= volsize <= 16G)"