Skip to content

Commit bf6a384

Browse files
author
Paul Dagnelie
committed
punch holes in loopbacks
Signed-off-by: Paul Dagnelie <[email protected]>
1 parent dc61419 commit bf6a384

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

tests/zfs-tests/include/libtest.shlib

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,23 @@ function assert
789789
(($@)) || log_fail "$@"
790790
}
791791

792+
function get_file_size
793+
{
794+
typeset filename="$1"
795+
796+
if is_linux; then
797+
if [ -b "$filename" ] ; then
798+
filesize=$(blockdev --getsize64 $filename)
799+
else
800+
filesize=$(stat -c %s $filename)
801+
fi
802+
else
803+
filesize=$(stat -s $filename | awk '{print $8}' | grep -o '[0-9]\+')
804+
fi
805+
806+
echo $filesize
807+
}
808+
792809
#
793810
# Function to format partition size of a disk
794811
# Given a disk cxtxdx reduces all partitions
@@ -1599,6 +1616,14 @@ function create_pool #pool devs_list
15991616

16001617
if is_global_zone ; then
16011618
[[ -d /$pool ]] && rm -rf /$pool
1619+
1620+
for vdev in "$@" ; do
1621+
if [[ "$vdev" =~ "loop" ]] ; then
1622+
# If the device is a loopback, remove previously
1623+
# allocated data.
1624+
punch_hole 0 $(get_file_size /dev/$vdev) /dev/$vdev
1625+
fi
1626+
done
16021627
log_must zpool create -f $pool $@
16031628
fi
16041629

tests/zfs-tests/tests/functional/anyraid/anyraid_common.kshlib

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ function wipe_some_disks_and_verify_content_is_still_okay
4646
done
4747

4848
for disk in $@; do
49-
log_must dd if=/dev/zero of=$disk seek=8 bs=$DD_BLOCK \
50-
count=$(( DD_COUNT - 128 )) conv=notrunc
49+
log_must punch_hole $((DD_BLOCK * 8)) $((DD_BLOCK * (DD_COUNT - 128))) $disk
5150
done
5251

5352
#

tests/zfs-tests/tests/functional/direct/dio.kshlib

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,6 @@ function check_read # pool file bs count skip flags buf_rd dio_rd
261261
fi
262262
}
263263

264-
function get_file_size
265-
{
266-
typeset filename="$1"
267-
268-
if is_linux; then
269-
filesize=$(stat -c %s $filename)
270-
else
271-
filesize=$(stat -s $filename | awk '{print $8}' | grep -o '[0-9]\+')
272-
fi
273-
274-
echo $filesize
275-
}
276-
277264
function do_truncate_reduce
278265
{
279266
typeset filename=$1

0 commit comments

Comments
 (0)