ZTS: fallocate tests fail with hard coded values
Currently, these two tests pass on disks with 512 byte sectors. In environments where the backing store is different, the number of blocks allocated to write the same file may differ. This change modifies the reported size check to detect an expected change in the reported number of blocks without specifying a particular number. Reviewed-by: Ryan Moeller <ryan@iXsystems.com> Reviewed-by: Tony Nguyen <tony.nguyen@delphix.com> Signed-off-by: John Kennedy <john.kennedy@delphix.com> Closes #13931
This commit is contained in:
parent
505df8d133
commit
ce55d6ae46
|
@ -23,6 +23,7 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2020 by Lawrence Livermore National Security, LLC.
|
# Copyright (c) 2020 by Lawrence Livermore National Security, LLC.
|
||||||
# Copyright (c) 2021 by The FreeBSD Foundation.
|
# Copyright (c) 2021 by The FreeBSD Foundation.
|
||||||
|
# Copyright (c) 2022 by Delphix. All rights reserved.
|
||||||
#
|
#
|
||||||
|
|
||||||
. $STF_SUITE/include/libtest.shlib
|
. $STF_SUITE/include/libtest.shlib
|
||||||
|
@ -35,6 +36,10 @@
|
||||||
# 1. Create a dense file
|
# 1. Create a dense file
|
||||||
# 2. Punch an assortment of holes in the file and verify the result.
|
# 2. Punch an assortment of holes in the file and verify the result.
|
||||||
#
|
#
|
||||||
|
# Note: We can't compare exact block numbers as reported by du, because
|
||||||
|
# different backing stores may allocate different numbers of blocks for
|
||||||
|
# the same amount of data.
|
||||||
|
#
|
||||||
|
|
||||||
verify_runnable "global"
|
verify_runnable "global"
|
||||||
|
|
||||||
|
@ -60,27 +65,24 @@ function cleanup
|
||||||
[[ -e $TESTDIR ]] && log_must rm -f $FILE
|
[[ -e $TESTDIR ]] && log_must rm -f $FILE
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_reported_size
|
function get_reported_size
|
||||||
{
|
{
|
||||||
typeset expected_size=$1
|
if ! [ -e "$FILE" ]; then
|
||||||
|
|
||||||
if ! [ -e "${FILE}" ]; then
|
|
||||||
log_fail "$FILE does not exist"
|
log_fail "$FILE does not exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
reported_size=$(du "${FILE}" | awk '{print $1}')
|
sync_pool $TESTPOOL >/dev/null 2>&1
|
||||||
if [ "$reported_size" != "$expected_size" ]; then
|
du "$FILE" | awk '{print $1}'
|
||||||
log_fail "Incorrect reported size: $reported_size != $expected_size"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_apparent_size
|
function check_apparent_size
|
||||||
{
|
{
|
||||||
typeset expected_size=$1
|
typeset expected_size=$1
|
||||||
|
|
||||||
apparent_size=$(stat_size "${FILE}")
|
apparent_size=$(stat_size "$FILE")
|
||||||
if [ "$apparent_size" != "$expected_size" ]; then
|
if [ "$apparent_size" != "$expected_size" ]; then
|
||||||
log_fail "Incorrect apparent size: $apparent_size != $expected_size"
|
log_fail \
|
||||||
|
"Incorrect apparent size: $apparent_size != $expected_size"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,30 +92,36 @@ log_onexit cleanup
|
||||||
|
|
||||||
# Create a dense file and check it is the correct size.
|
# Create a dense file and check it is the correct size.
|
||||||
log_must file_write -o create -f $FILE -b $BLKSZ -c 8
|
log_must file_write -o create -f $FILE -b $BLKSZ -c 8
|
||||||
sync_pool $TESTPOOL
|
full_size=$(get_reported_size)
|
||||||
log_must check_reported_size 1027
|
|
||||||
|
|
||||||
# Punch a hole for the first full block.
|
# Punch a hole for the first full block. The reported size should decrease.
|
||||||
log_must punch_hole 0 $BLKSZ $FILE
|
log_must punch_hole 0 $BLKSZ $FILE
|
||||||
sync_pool $TESTPOOL
|
one_hole=$(get_reported_size)
|
||||||
log_must check_reported_size 899
|
[[ $full_size -gt $one_hole ]] || log_fail \
|
||||||
|
"One hole failure: $full_size -> $one_hole"
|
||||||
|
|
||||||
# Partially punch a hole in the second block.
|
# Partially punch a hole in the second block. The reported size should
|
||||||
|
# remain constant.
|
||||||
log_must punch_hole $BLKSZ $((BLKSZ / 2)) $FILE
|
log_must punch_hole $BLKSZ $((BLKSZ / 2)) $FILE
|
||||||
sync_pool $TESTPOOL
|
partial_hole=$(get_reported_size)
|
||||||
log_must check_reported_size 899
|
[[ $one_hole -eq $partial_hole ]] || log_fail \
|
||||||
|
"Partial hole failure: $one_hole -> $partial_hole"
|
||||||
|
|
||||||
# Punch a hole which overlaps the third and fourth block.
|
# Punch a hole which overlaps the third and fourth block. The reported size
|
||||||
|
# should remain constant.
|
||||||
log_must punch_hole $(((BLKSZ * 2) + (BLKSZ / 2))) $((BLKSZ)) $FILE
|
log_must punch_hole $(((BLKSZ * 2) + (BLKSZ / 2))) $((BLKSZ)) $FILE
|
||||||
sync_pool $TESTPOOL
|
overlap_hole=$(get_reported_size)
|
||||||
log_must check_reported_size 899
|
[[ $one_hole -eq $overlap_hole ]] || log_fail \
|
||||||
|
"Overlap hole failure: $one_hole -> $overlap_hole"
|
||||||
|
|
||||||
# Punch a hole from the fifth block past the end of file. The apparent
|
# Punch a hole from the fifth block past the end of file. The reported size
|
||||||
# file size should not change since --keep-size is implied.
|
# should decrease, and the apparent file size should not change since
|
||||||
|
# --keep-size is implied.
|
||||||
apparent_size=$(stat_size $FILE)
|
apparent_size=$(stat_size $FILE)
|
||||||
log_must punch_hole $((BLKSZ * 4)) $((BLKSZ * 10)) $FILE
|
log_must punch_hole $((BLKSZ * 4)) $((BLKSZ * 10)) $FILE
|
||||||
sync_pool $TESTPOOL
|
eof_hole=$(get_reported_size)
|
||||||
log_must check_reported_size 387
|
[[ $overlap_hole -gt $eof_hole ]] || log_fail \
|
||||||
|
"EOF hole failure: $overlap_hole -> $eof_hole"
|
||||||
log_must check_apparent_size $apparent_size
|
log_must check_apparent_size $apparent_size
|
||||||
|
|
||||||
log_pass "Ensure holes can be punched in files making them sparse"
|
log_pass "Ensure holes can be punched in files making them sparse"
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2020 by Lawrence Livermore National Security, LLC.
|
# Copyright (c) 2020 by Lawrence Livermore National Security, LLC.
|
||||||
# Copyright (c) 2021 by The FreeBSD Foundation.
|
# Copyright (c) 2021 by The FreeBSD Foundation.
|
||||||
|
# Copyright (c) 2022 by Delphix. All rights reserved.
|
||||||
#
|
#
|
||||||
|
|
||||||
. $STF_SUITE/include/libtest.shlib
|
. $STF_SUITE/include/libtest.shlib
|
||||||
|
@ -35,6 +36,10 @@
|
||||||
# 1. Create a dense file
|
# 1. Create a dense file
|
||||||
# 2. Zero various ranges in the file and verify the result.
|
# 2. Zero various ranges in the file and verify the result.
|
||||||
#
|
#
|
||||||
|
# Note: We can't compare exact block numbers as reported by du, because
|
||||||
|
# different backing stores may allocate different numbers of blocks for
|
||||||
|
# the same amount of data.
|
||||||
|
#
|
||||||
|
|
||||||
verify_runnable "global"
|
verify_runnable "global"
|
||||||
|
|
||||||
|
@ -50,28 +55,24 @@ function cleanup
|
||||||
[[ -e $TESTDIR ]] && log_must rm -f $FILE
|
[[ -e $TESTDIR ]] && log_must rm -f $FILE
|
||||||
}
|
}
|
||||||
|
|
||||||
# Helpfully, this function expects kilobytes, and check_apparent_size expects bytes.
|
function get_reported_size
|
||||||
function check_reported_size
|
|
||||||
{
|
{
|
||||||
typeset expected_size=$1
|
if ! [ -e "$FILE" ]; then
|
||||||
|
|
||||||
if ! [ -e "${FILE}" ]; then
|
|
||||||
log_fail "$FILE does not exist"
|
log_fail "$FILE does not exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
reported_size=$(du "${FILE}" | awk '{print $1}')
|
sync_pool $TESTPOOL >/dev/null 2>&1
|
||||||
if [ "$reported_size" != "$expected_size" ]; then
|
du "$FILE" | awk '{print $1}'
|
||||||
log_fail "Incorrect reported size: $reported_size != $expected_size"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_apparent_size
|
function check_apparent_size
|
||||||
{
|
{
|
||||||
typeset expected_size=$1
|
typeset expected_size=$1
|
||||||
|
|
||||||
apparent_size=$(stat_size "${FILE}")
|
apparent_size=$(stat_size "$FILE")
|
||||||
if [ "$apparent_size" != "$expected_size" ]; then
|
if [ "$apparent_size" != "$expected_size" ]; then
|
||||||
log_fail "Incorrect apparent size: $apparent_size != $expected_size"
|
log_fail \
|
||||||
|
"Incorrect apparent size: $apparent_size != $expected_size"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,38 +83,46 @@ log_onexit cleanup
|
||||||
# Create a dense file and check it is the correct size.
|
# Create a dense file and check it is the correct size.
|
||||||
log_must file_write -o create -f $FILE -b $BLKSZ -c 8
|
log_must file_write -o create -f $FILE -b $BLKSZ -c 8
|
||||||
sync_pool $TESTPOOL
|
sync_pool $TESTPOOL
|
||||||
log_must check_reported_size 1027
|
full_size=$(get_reported_size)
|
||||||
|
|
||||||
# Zero a range covering the first full block.
|
# Zero a range covering the first full block. The reported size should decrease.
|
||||||
log_must zero_range 0 $BLKSZ $FILE
|
log_must zero_range 0 $BLKSZ $FILE
|
||||||
sync_pool $TESTPOOL
|
one_range=$(get_reported_size)
|
||||||
log_must check_reported_size 899
|
[[ $full_size -gt $one_range ]] || log_fail \
|
||||||
|
"One range failure: $full_size -> $one_range"
|
||||||
|
|
||||||
# Partially zero a range in the second block.
|
# Partially zero a range in the second block. The reported size should
|
||||||
|
# remain constant.
|
||||||
log_must zero_range $BLKSZ $((BLKSZ / 2)) $FILE
|
log_must zero_range $BLKSZ $((BLKSZ / 2)) $FILE
|
||||||
sync_pool $TESTPOOL
|
partial_range=$(get_reported_size)
|
||||||
log_must check_reported_size 899
|
[[ $one_range -eq $partial_range ]] || log_fail \
|
||||||
|
"Partial range failure: $one_range -> $partial_range"
|
||||||
|
|
||||||
# Zero range which overlaps the third and fourth block.
|
# Zero range which overlaps the third and fourth block. The reported size
|
||||||
|
# should remain constant.
|
||||||
log_must zero_range $(((BLKSZ * 2) + (BLKSZ / 2))) $((BLKSZ)) $FILE
|
log_must zero_range $(((BLKSZ * 2) + (BLKSZ / 2))) $((BLKSZ)) $FILE
|
||||||
sync_pool $TESTPOOL
|
overlap_range=$(get_reported_size)
|
||||||
log_must check_reported_size 899
|
[[ $one_range -eq $overlap_range ]] || log_fail \
|
||||||
|
"Overlap range failure: $one_range -> $overlap_range"
|
||||||
|
|
||||||
# Zero range from the fifth block past the end of file, with --keep-size.
|
# Zero range from the fifth block past the end of file, with --keep-size.
|
||||||
# The apparent file size must not change, since we did specify --keep-size.
|
# The reported size should decrease, and the apparent file size must not
|
||||||
|
# change, since we did specify --keep-size.
|
||||||
apparent_size=$(stat_size $FILE)
|
apparent_size=$(stat_size $FILE)
|
||||||
log_must fallocate --keep-size --zero-range --offset $((BLKSZ * 4)) --length $((BLKSZ * 10)) "$FILE"
|
log_must fallocate --keep-size --zero-range --offset $((BLKSZ * 4)) --length $((BLKSZ * 10)) "$FILE"
|
||||||
sync_pool $TESTPOOL
|
eof_range=$(get_reported_size)
|
||||||
log_must check_reported_size 387
|
[[ $overlap_range -gt $eof_range ]] || log_fail \
|
||||||
|
"EOF range failure: $overlap_range -> $eof_range"
|
||||||
log_must check_apparent_size $apparent_size
|
log_must check_apparent_size $apparent_size
|
||||||
|
|
||||||
# Zero range from the fifth block past the end of file. The apparent
|
# Zero range from the fifth block past the end of file. The apparent
|
||||||
# file size should change since --keep-size is not implied, unlike
|
# file size should change since --keep-size is not implied, unlike
|
||||||
# with PUNCH_HOLE.
|
# with PUNCH_HOLE. The reported size should remain constant.
|
||||||
apparent_size=$(stat_size $FILE)
|
apparent_size=$(stat_size $FILE)
|
||||||
log_must zero_range $((BLKSZ * 4)) $((BLKSZ * 10)) $FILE
|
log_must zero_range $((BLKSZ * 4)) $((BLKSZ * 10)) $FILE
|
||||||
sync_pool $TESTPOOL
|
eof_range2=$(get_reported_size)
|
||||||
log_must check_reported_size 387
|
[[ $eof_range -eq $eof_range2 ]] || log_fail \
|
||||||
|
"Second EOF range failure: $eof_range -> $eof_range2"
|
||||||
log_must check_apparent_size $((BLKSZ * 14))
|
log_must check_apparent_size $((BLKSZ * 14))
|
||||||
|
|
||||||
log_pass "Ensure ranges can be zeroed in files"
|
log_pass "Ensure ranges can be zeroed in files"
|
||||||
|
|
Loading…
Reference in New Issue