-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Corrected oversight in ZERO_RANGE behavior #13338
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
tests/zfs-tests/tests/functional/fallocate/fallocate_zero-range.ksh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/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 (c) 2020 by Lawrence Livermore National Security, LLC. | ||
# Copyright (c) 2021 by The FreeBSD Foundation. | ||
# | ||
|
||
. $STF_SUITE/include/libtest.shlib | ||
|
||
# | ||
# DESCRIPTION: | ||
# Test FALLOC_FL_ZERO_RANGE functionality | ||
# | ||
# STRATEGY: | ||
# 1. Create a dense file | ||
# 2. Zero various ranges in the file and verify the result. | ||
# | ||
|
||
verify_runnable "global" | ||
|
||
if is_freebsd; then | ||
log_unsupported "FreeBSD does not implement an analogue to ZERO_RANGE." | ||
fi | ||
|
||
FILE=$TESTDIR/$TESTFILE0 | ||
BLKSZ=$(get_prop recordsize $TESTPOOL) | ||
|
||
function cleanup | ||
{ | ||
[[ -e $TESTDIR ]] && log_must rm -f $FILE | ||
} | ||
|
||
# Helpfully, this function expects kilobytes, and check_apparent_size expects bytes. | ||
function check_reported_size | ||
{ | ||
typeset expected_size=$1 | ||
|
||
if ! [ -e "${FILE}" ]; then | ||
log_fail "$FILE does not exist" | ||
fi | ||
|
||
reported_size=$(du "${FILE}" | awk '{print $1}') | ||
if [ "$reported_size" != "$expected_size" ]; then | ||
log_fail "Incorrect reported size: $reported_size != $expected_size" | ||
fi | ||
} | ||
|
||
function check_apparent_size | ||
{ | ||
typeset expected_size=$1 | ||
|
||
apparent_size=$(stat_size "${FILE}") | ||
if [ "$apparent_size" != "$expected_size" ]; then | ||
log_fail "Incorrect apparent size: $apparent_size != $expected_size" | ||
fi | ||
} | ||
|
||
log_assert "Ensure ranges can be zeroed in files" | ||
|
||
log_onexit cleanup | ||
|
||
# Create a dense file and check it is the correct size. | ||
log_must file_write -o create -f $FILE -b $BLKSZ -c 8 | ||
sync_pool $TESTPOOL | ||
log_must check_reported_size 1027 | ||
|
||
# Zero a range covering the first full block. | ||
log_must zero_range 0 $BLKSZ $FILE | ||
sync_pool $TESTPOOL | ||
log_must check_reported_size 899 | ||
|
||
# Partially zero a range in the second block. | ||
log_must zero_range $BLKSZ $((BLKSZ / 2)) $FILE | ||
sync_pool $TESTPOOL | ||
log_must check_reported_size 899 | ||
|
||
# Zero range which overlaps the third and fourth block. | ||
log_must zero_range $(((BLKSZ * 2) + (BLKSZ / 2))) $((BLKSZ)) $FILE | ||
sync_pool $TESTPOOL | ||
log_must check_reported_size 899 | ||
|
||
# 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. | ||
apparent_size=$(stat_size $FILE) | ||
log_must fallocate --keep-size --zero-range --offset $((BLKSZ * 4)) --length $((BLKSZ * 10)) "$FILE" | ||
sync_pool $TESTPOOL | ||
log_must check_reported_size 387 | ||
log_must check_apparent_size $apparent_size | ||
|
||
# Zero range from the fifth block past the end of file. The apparent | ||
# file size should change since --keep-size is not implied, unlike | ||
# with PUNCH_HOLE. | ||
apparent_size=$(stat_size $FILE) | ||
log_must zero_range $((BLKSZ * 4)) $((BLKSZ * 10)) $FILE | ||
sync_pool $TESTPOOL | ||
log_must check_reported_size 387 | ||
log_must check_apparent_size $((BLKSZ * 14)) | ||
|
||
log_pass "Ensure ranges can be zeroed in files" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this actually
is_linux || log_unsupported
, given the case inzero_range
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, yes.
I don't have a particularly strong preference between the two ways of checking (or neither and just including it in the Linux-only runfile), but the punch-hole test had an "If [FreeBSD] && [older than version X], log_unsupported" check at the top, which I just stripped down into this.