| #! /bin/bash |
| # SPDX-License-Identifier: GPL-2.0 |
| # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved. |
| # |
| # FS QA Test 546 |
| # |
| # Test when a fs is full we can still: |
| # - Do buffered write into a unpopulated preallocated extent |
| # - Clone the untouched part of that preallocated extent |
| # - Fsync |
| # - No data loss even power loss happens after fsync |
| # All operations above should not fail. |
| # |
| 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() |
| { |
| _cleanup_flakey |
| cd / |
| rm -f $tmp.* |
| } |
| |
| # get standard environment, filters and checks |
| . ./common/rc |
| . ./common/filter |
| . ./common/reflink |
| . ./common/dmflakey |
| |
| # remove previous $seqres.full before test |
| rm -f $seqres.full |
| |
| # real QA test starts here |
| |
| # Modify as appropriate. |
| _supported_fs generic |
| _require_xfs_io_command "falloc" |
| _require_scratch_reflink |
| _require_dm_target flakey |
| |
| _scratch_mkfs_sized $((512 * 1024 * 1024)) >> $seqres.full 2>&1 |
| _require_metadata_journaling $SCRATCH_DEV |
| _init_flakey |
| _mount_flakey |
| |
| # Create preallocated extent where we can write into |
| $XFS_IO_PROG -f -c 'falloc 8k 64m' "$SCRATCH_MNT/foobar" >> $seqres.full |
| |
| # Use up all data space, to test later write-into-preallocate behavior |
| _pwrite_byte 0x00 0 512m "$SCRATCH_MNT/padding" >> $seqres.full 2>&1 |
| |
| # Sync to ensure that padding file reach disk so that at log recovery we |
| # still have no data space |
| sync |
| |
| # This should not fail |
| _pwrite_byte 0xcd 1m 16m "$SCRATCH_MNT/foobar" >> $seqres.full |
| |
| # Do reflink here, we shouldn't use extra data space, thus it should not fail |
| $XFS_IO_PROG -c "reflink ${SCRATCH_MNT}/foobar 8k 0 4k" "$SCRATCH_MNT/foobar" \ |
| >> $seqres.full |
| |
| # Checksum before power loss |
| echo md5 before $(_md5_checksum "$SCRATCH_MNT/foobar") |
| |
| # Fsync to check if writeback is ok |
| $XFS_IO_PROG -c 'fsync' "$SCRATCH_MNT/foobar" |
| |
| # Now emulate power loss |
| _flakey_drop_and_remount |
| |
| # Checksum after power loss |
| echo md5 after $(_md5_checksum "$SCRATCH_MNT/foobar") |
| |
| # success, all done |
| status=0 |
| exit |