From: Max Reitz <mreitz@redhat.com>
To: fstests@vger.kernel.org
Cc: Max Reitz <mreitz@redhat.com>
Subject: [PATCH] generic: fallocate two bytes at block boundary
Date: Thu, 26 Sep 2019 17:29:27 +0200 [thread overview]
Message-ID: <20190926152927.2331-1-mreitz@redhat.com> (raw)
Allocating two bytes at a block boundary with fallocate should allocate
both blocks involved. Test this by writing both bytes with dd
afterwards and see whether the on-disk size increases (it should not).
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
tests/generic/568 | 63 +++++++++++++++++++++++++++++++++++++++++++
tests/generic/568.out | 2 ++
tests/generic/group | 1 +
3 files changed, 66 insertions(+)
create mode 100755 tests/generic/568
create mode 100644 tests/generic/568.out
diff --git a/tests/generic/568 b/tests/generic/568
new file mode 100755
index 00000000..8fbdcda0
--- /dev/null
+++ b/tests/generic/568
@@ -0,0 +1,63 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Red Hat, Inc. All Rights Reserved.
+#
+# FS QA Test No. generic/568
+#
+# Test that fallocating an unaligned range allocates all blocks
+# touched by that range
+#
+seq=$(basename $0)
+seqres="$RESULT_DIR/$seq"
+echo "QA output created by $seq"
+
+here=$PWD
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -f "$tmp".*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+
+testfile="$SCRATCH_MNT/testfile"
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+
+# Fallocate 2 bytes across a block boundary
+block_size=$(stat -fc '%S' "$SCRATCH_MNT")
+fallocate -o $((block_size - 1)) -l 2 "$testfile"
+
+# Both the first blocks should be allocated now. Check that by
+# inquiring whether the file grows when we write to the two bytes we
+# have just fallocated.
+
+allocated_size_before=$(($(stat -c '%b * %B' "$testfile")))
+
+dd if=/dev/zero of="$testfile" bs=1 conv=notrunc \
+ seek=$((block_size - 1)) count=2 \
+ 2>&1 | _filter_dd
+
+allocated_size_after=$(($(stat -c '%b * %B' "$testfile")))
+
+if [ $allocated_size_after -gt $allocated_size_before ]; then
+ echo "ERROR: File grew from ${allocated_size_before} B to" \
+ "${allocated_size_after} when writing to the fallocated range."
+else
+ echo "OK: File did not grow."
+fi
+
+status=0
+exit
diff --git a/tests/generic/568.out b/tests/generic/568.out
new file mode 100644
index 00000000..d8210882
--- /dev/null
+++ b/tests/generic/568.out
@@ -0,0 +1,2 @@
+QA output created by 568
+OK: File did not grow.
diff --git a/tests/generic/group b/tests/generic/group
index 7cf4f6c4..24ab29bc 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -570,3 +570,4 @@
565 auto quick copy_range
566 auto quick quota metadata
567 auto quick rw punch
+568 auto quick rw
--
2.21.0
next reply other threads:[~2019-09-26 15:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-26 15:29 Max Reitz [this message]
2019-09-26 15:55 ` [PATCH] generic: fallocate two bytes at block boundary Darrick J. Wong
2019-09-26 16:02 ` Max Reitz
2019-09-26 16:06 ` Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190926152927.2331-1-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=fstests@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).