#! /bin/bash # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (c) 2022 Oracle. All Rights Reserved. # # FS QA Test No. 721 # # Test non-root atomic file updates when (a) the file contents are cloned into # the staging file; and (b) when the staging file is created empty. . ./common/preamble _begin_fstest auto quick fiexchange swapext # Override the default cleanup function. _cleanup() { cd / rm -r -f $tmp.* $dir } # Import common functions. . ./common/filter . ./common/reflink # real QA test starts here _require_xfs_io_command startupdate _require_test_reflink _require_test _require_user filesnap() { echo "$1" md5sum $2 | _filter_test_dir } mkfile() { rm -f $dir/a _pwrite_byte 0x58 0 $((blksz * nrblks)) $dir/a >> $seqres.full chown $qa_user $dir/a $dir/ sync } dir=$TEST_DIR/test-$seq mkdir -p $dir blksz=65536 nrblks=64 # Use the atomic file update staging prototype in xfs_io to update a file. mkfile filesnap "before commit" $dir/a cmd="$XFS_IO_PROG \ -c 'startupdate' \ -c 'pwrite -S 0x60 44k 55k -b 1m' \ -c 'commitupdate -q' \ \"$dir/a\"" su -s /bin/bash -c "$cmd" $qa_user 2>&1 | _filter_xfs_io | _filter_test_dir filesnap "after commit" $dir/a echo # Use the atomic file updates to replace a file with a shorter file. mkfile filesnap "before shorten commit" $dir/a cmd="$XFS_IO_PROG \ -c 'startupdate' \ -c 'truncate 55k' \ -c 'pwrite -S 0x60 0 55k' \ -c 'commitupdate -q' \ \"$dir/a\"" su -s /bin/bash -c "$cmd" $qa_user 2>&1 | _filter_xfs_io | _filter_test_dir filesnap "after shorten commit" $dir/a echo # Use the atomic file updates to replace a file with a longer file. mkfile filesnap "before lengthen commit" $dir/a cmd="$XFS_IO_PROG \ -c 'startupdate' \ -c \"pwrite -S 0x60 0 $(( (blksz * nrblks) + 37373 ))\" \ -c 'commitupdate -q' \ \"$dir/a\"" su -s /bin/bash -c "$cmd" $qa_user 2>&1 | _filter_xfs_io | _filter_test_dir filesnap "after lengthen commit" $dir/a echo # Use the atomic file update staging prototype in xfs_io to cancel updating a # file. mkfile filesnap "before cancel" $dir/a cmd="$XFS_IO_PROG \ -c 'startupdate' \ -c 'pwrite -S 0x60 44k 55k -b 1m' \ -c 'cancelupdate' \ \"$dir/a\"" su -s /bin/bash -c "$cmd" $qa_user 2>&1 | _filter_xfs_io | _filter_test_dir filesnap "after cancel" $dir/a echo # Now try the update but with the A file open separately so that we clobber # mtime and fail the update. mkfile filesnap "before fail commit" $dir/a cmd="$XFS_IO_PROG \ -c \"open $dir/a\" \ -c 'startupdate' \ -c 'pwrite -S 0x58 44k 55k -b 1m' \ -c 'file 0' \ -c 'close' \ -c 'pwrite -S 0x61 22k 11k -b 1m' \ -c 'commitupdate -q' \ \"$dir/a\"" su -s /bin/bash -c "$cmd" $qa_user 2>&1 | _filter_xfs_io | _filter_test_dir filesnap "after fail commit" $dir/a echo # success, all done status=0 exit