generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / generic / 343
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 343
6 #
7 # Test that if we create a hard link for a file F in some directory A, then move
8 # some directory or file B from its parent directory C into directory A, fsync
9 # file F, power fail and mount the filesystem, the directory/file B is located
10 # only at directory A and both links for file F exist.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         _cleanup_flakey
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/dmflakey
30
31 # real QA test starts here
32 _supported_fs generic
33 _require_scratch
34 _require_hardlinks
35 _require_dm_target flakey
36
37 rm -f $seqres.full
38
39 _scratch_mkfs >>$seqres.full 2>&1
40 _require_metadata_journaling $SCRATCH_DEV
41 _init_flakey
42 _mount_flakey
43
44 # Create our test directories and files.
45 mkdir $SCRATCH_MNT/x
46 mkdir $SCRATCH_MNT/y
47 touch $SCRATCH_MNT/x/foo
48 mkdir $SCRATCH_MNT/y/z
49 touch $SCRATCH_MNT/y/foo2
50
51 # Make sure everything is durably persisted.
52 sync
53
54 # Now add a link to foo at directory x, move directory z and file foo2 from
55 # directory y to directory x and fsync foo's inode. We expect that after a
56 # log replay we see the new link for foo's inode and that z and foo2 are only
57 # located at directory x.
58 ln $SCRATCH_MNT/x/foo $SCRATCH_MNT/x/bar
59 mv $SCRATCH_MNT/y/z $SCRATCH_MNT/x/z
60 mv $SCRATCH_MNT/y/foo2 $SCRATCH_MNT/x/foo2
61 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/x/bar
62 _flakey_drop_and_remount
63
64 echo "Filesystem contents after log replay:"
65 ls -R $SCRATCH_MNT/x $SCRATCH_MNT/y | _filter_scratch
66
67 _unmount_flakey
68 status=0
69 exit