linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 3/3] btrfs-progs: tests/convert: add test case for ext4 unwritten extents
Date: Tue,  7 May 2024 12:52:55 +0930	[thread overview]
Message-ID: <542d0b559a21ae84202d2e7632dfab59019e4982.1715051693.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1715051693.git.wqu@suse.com>

The test case would verify the behaivor of ext4 unwritten extents by:

- Create a unwritten (preallocated) extent on ext4

- Fill the on-disk extent with random garbage
  This is to make sure if btrfs tries to read the on-disk data, it would
  definitely get some garbage.
  As I found sometimes mkfs.ext4 can fill the unused bg with zeros.

- Fill the preallocated file range with some data
  This is to make sure btrfs-convert can handle mixed written and
  unwritten ranges.

- Save the checksum of the file.

- Convert the fs

- verify the checksum
  For older btrfs-convert, there would be only one regular file extent,
  and reading the file would read out some garbage and cause checksum to
  mismatch.

  For the fixed btrfs-convert, we punch holes for unwritten extents,
  thus only the written part would be read out and match the checksum.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 .../025-ext4-uninit-written/test.sh           | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100755 tests/convert-tests/025-ext4-uninit-written/test.sh

diff --git a/tests/convert-tests/025-ext4-uninit-written/test.sh b/tests/convert-tests/025-ext4-uninit-written/test.sh
new file mode 100755
index 000000000000..cca8f69a201e
--- /dev/null
+++ b/tests/convert-tests/025-ext4-uninit-written/test.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+# Make sure btrfs is handling the ext4 uninit (preallocated) extent correctly
+
+source "$TEST_TOP/common" || exit
+source "$TEST_TOP/common.convert" || exit
+
+setup_root_helper
+prepare_test_dev 1G
+
+check_global_prereq mkfs.ext4
+check_global_prereq fallocate
+check_global_prereq filefrag
+check_global_prereq awk
+check_global_prereq md5sum
+check_prereq btrfs-convert
+check_prereq btrfs
+
+convert_test_prep_fs ext4 mke2fs -t ext4 -b 4096
+
+# Create a preallocated extent first.
+run_check $SUDO_HELPER fallocate -l 32K "$TEST_MNT/file"
+sync
+# Get the real on-disk location and write some data into it.
+physical=$(run_check_stdout $SUDO_HELPER filefrag -v "$TEST_MNT/file" | grep unwritten | awk '{print $4}' | grep -o "[[:digit:]]*")
+
+if [ -z "$physical" ]; then
+	_fail "unable to get the physical address of the file"
+fi
+
+# Now fill the underlying range with non-zeros.
+# For properly converted fs, we should not read the contents anyway
+run_check $SUDO_HELPER dd if=/dev/urandom of=$TEST_DEV bs=4096 seek="$physical" conv=notrunc count=8
+
+# Write some thing into the file range.
+run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file" bs=4096 count=1 conv=notrunc
+run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file" bs=4096 count=1 seek=3 conv=notrunc
+sync
+md5_before=$(md5sum "$TEST_MNT/file" | cut -f1 -d' ')
+_log "md5sum before convert: $md5_before"
+run_check_umount_test_dev
+
+# Btrfs-convert should handle the unwritten part correctly, either punching a hole
+# or a proper preallocated extent, so that we won't read the on-disk data.
+convert_test_do_convert
+
+run_check_mount_test_dev
+md5_after=$(md5sum "$TEST_MNT/file" | cut -f1 -d' ')
+_log "md5sum after convert: $md5_after"
+run_check_umount_test_dev
+
+if [ "$md5_before" != "$md5_after" ]; then
+	_fail "contents mismatch"
+fi
-- 
2.45.0


      parent reply	other threads:[~2024-05-07  3:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-07  3:22 [PATCH 0/3] btrfs-progs: convert: proper ext4 unwritten extents handling Qu Wenruo
2024-05-07  3:22 ` [PATCH 1/3] Revert "btrfs-progs: convert: add raid-stripe-tree to allowed features" Qu Wenruo
2024-05-07  3:22 ` [PATCH 2/3] btrfs-progs: convert: rework file extent iteration to handle unwritten extents Qu Wenruo
2024-05-07  7:48   ` Yordan
2024-05-07  3:22 ` Qu Wenruo [this message]

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=542d0b559a21ae84202d2e7632dfab59019e4982.1715051693.git.wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@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).