generic/778: test snapshot data integrity after punch hole operations
PATCH v2 1/1 generic/778: test snapshot data integrity after punch hole operations
Add test to verify that snapshots preserve original file data when the live file is modified with punch hole operations. The test creates a file, takes a snapshot, punches multiple holes in the original file, then verifies the snapshot data remains unchanged.
---v1->v2: previous version is 'ceph/006: test snapshot data integrity after
punch hole'.
1. move it to generic and add _require_snapshot check.
2. modify punch hole offset/len to be 64K aligned
--- common/rc | 20 +++++++++++ tests/generic/778 | 80 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/778.out | 2 ++ 3 files changed, 102 insertions(+) create mode 100755 tests/generic/778 create mode 100644 tests/generic/778.out
common/rc +20 -0
@@ -5978,6 +5978,26 @@ _require_inplace_writes() fi } +# this test requires filesystem snapshot support +_require_snapshot() +{ + case "$FSTYP" in + ceph) + local check_dir=$1 + [ -z "$check_dir" ] && _fail "_require_snapshot: directory argument required for ceph" + local test_snapdir="$check_dir/.snap/test_snap_$$" + mkdir "$test_snapdir" 2>/dev/null || _notrun "Ceph snapshots not supported (requires fs flag 'allow_snaps' and client auth capability 'snap')" + rmdir "$test_snapdir" + ;; + btrfs) + # btrfs always supports snapshots, no check needed + ;; + *) + _notrun "Snapshots not supported on $FSTYP" + ;; + esac +} + ################################################################################ # make sure this script returns success /bin/true
tests/generic/778 new file +80 -0
80 lines not on this page · raw message
tests/generic/778.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 778 +Silence is golden
Signature · 4 lines
2.43.0 Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.
Quoted 24 lines · ethanwu
Add test to verify that snapshots preserve original file data when the live file is modified with punch hole operations. The test creates a file, takes a snapshot, punches multiple holes in the original file, then verifies the snapshot data remains unchanged.
Signed-off-by ethanwu <[email protected]>---
v1->v2: previous version is 'ceph/006: test snapshot data integrity after
punch hole'.
1. move it to generic and add_require_snapshotcheck.
2. modify punch hole offset/len to be 64K aligned--- common/rc | 20 +++++++++++ tests/generic/778 | 80 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/778.out | 2 ++ 3 files changed, 102 insertions(+) create mode 100755 tests/generic/778 create mode 100644 tests/generic/778.outcommon/rc +0
-0
common/rc _require_inplace_writes() · line 5982
Quoted 5 lines
common/rc +2
-0@@ -5978,6 +5978,26 @@ _require_inplace_writes() fi } +# this test requires filesystem snapshot support +_require_snapshot()
There's snapshot on device mapper layout, so how about change this function name to _require_fs_snapshot() .
Quoted 73 lines
common/rc +18
-0+{ + case "$FSTYP" in + ceph) + local check_dir=$1 + [ -z "$check_dir" ] && _fail "_require_snapshot: directory argument required for ceph" + local test_snapdir="$check_dir/.snap/test_snap_$$" + mkdir "$test_snapdir" 2>/dev/null || _notrun "Ceph snapshots not supported (requires fs flag 'allow_snaps' and client auth capability 'snap')" + rmdir "$test_snapdir" + ;; + btrfs) + # btrfs always supports snapshots, no check needed + ;; + *) + _notrun "Snapshots not supported on $FSTYP" + ;; + esac +} + ################################################################################ # make sure this script returns success /bin/truetests/generic/778 new file +46
-0@@ -0,0 +1,80 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2025 Synology All Rights Reserved. +# +# FS QA Test No. generic/778 +# +# Test that snapshot data remains intact after punch hole operations +# on the original file. +# +. ./common/preamble +_begin_fstest auto quick snapshot + +# Override the default cleanup function +_cleanup() +{ + cd / + rm -rf $tmp.* + if [ -n "$snapdir" ]; then + case "$FSTYP" in + ceph) + rmdir $snapdir 2>/dev/null + ;; + btrfs) + $BTRFS_UTIL_PROG subvolume delete $snapdir > /dev/null + ;; + esac + fi +} + +_require_test +_require_xfs_io_command "pwrite" +_require_xfs_io_command "fpunch" +_require_snapshot $TEST_DIR +_exclude_test_mount_option "test_dummy_encryption" + +# TODO: Update with final commit SHA when merged +[ "$FSTYP" = "ceph" ] && _fixed_by_kernel_commit 1b7b474b3a78 \ + "ceph: fix snapshot context missing in ceph_zero_partial_object" + +workdir=$TEST_DIR/test-$seq +rm -rf $workdir +mkdir $workdir + +$XFS_IO_PROG -f -c "pwrite -S 0xab 0 1048576" $workdir/foo > /dev/null + +# Create snapshot - filesystem specific
tests/generic/778 line 56
Quoted 10 lines
tests/generic/778 new file +10
-0+case "$FSTYP" in +ceph) + snapdir=$TEST_DIR/.snap/snap1 + mkdir $snapdir + ;; +btrfs) + snapdir=$TEST_DIR/snap1 + $BTRFS_UTIL_PROG subvolume snapshot ${TEST_DIR} $snapdir > /dev/null + ;; +esac
Sorry to make this test case to be more complicated, I didn't realize ".snap" is a special directory for ceph. I think you have two choices:
1) Move this case back to be a ceph only test case.
2) Write more common snapshot related helpers, e.g:
_require_fs_snapshot (you've written it) _create_fs_snapshot (to replace above creating snapshot part) _destroy_fs_snapshot (for above cleanup part)
Both are good to me, depends on which one you prefer :)
...
For the ".snap" directory, as you said it can be changed by mount option, so I'm wondering if you can get the "real" snapshot dir name at first, then do other steps, e.g.
snapdir=$(_get_ceph_snapshot_dir) (or whatever name you prefer:) testdir=$TEST_DIR/$snapdir
_require_fs_snapshot $testdir
_create_fs_snapshot $testdir/...
_destroy_fs_snapshot $testdir/...
or
you only test with ceph
Thanks,
Zorro
Quoted 38 lines
tests/generic/778 new file +24
-0+ +original_md5=$(md5sum $snapdir/test-$seq/foo | cut -d' ' -f1) + +# Punch several holes of various sizes at different offsets +$XFS_IO_PROG -c "fpunch 0 65536" $workdir/foo +$XFS_IO_PROG -c "fpunch 131072 65536" $workdir/foo +$XFS_IO_PROG -c "fpunch 262144 65536" $workdir/foo +$XFS_IO_PROG -c "fpunch 393216 65536" $workdir/foo + +# Make sure we don't read from cache +echo 3 > /proc/sys/vm/drop_caches + +snapshot_md5=$(md5sum $snapdir/test-$seq/foo | cut -d' ' -f1) + +if [ "$original_md5" != "$snapshot_md5" ]; then + echo "FAIL: Snapshot data changed after punch hole operations" + echo "Original md5sum: $original_md5" + echo "Snapshot md5sum: $snapshot_md5" +fi + +echo "Silence is golden" + +status=0 +exittests/generic/778.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 778 +Silence is goldenSignature · 4 lines
2.43.0 Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.