btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 118
1 #! /bin/bash
2 # FSQA Test No. 118
3 #
4 # Test that if we fsync a directory that had a snapshot entry in it that was
5 # deleted and crash, the next time we mount the filesystem, the log replay
6 # procedure will not fail and the snapshot is not present anymore.
7 #
8 #-----------------------------------------------------------------------
9 #
10 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
11 # Author: Filipe Manana <fdmanana@suse.com>
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         _cleanup_flakey
38         cd /
39         rm -f $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/dmflakey
46
47 # real QA test starts here
48 _supported_fs btrfs
49 _supported_os Linux
50 _require_scratch
51 _require_dm_target flakey
52
53 rm -f $seqres.full
54
55 _scratch_mkfs >>$seqres.full 2>&1
56 _require_metadata_journaling $SCRATCH_DEV
57 _init_flakey
58 _mount_flakey
59
60 # Create a snapshot at the root of our filesystem (mount point path), delete it,
61 # fsync the mount point path, crash and mount to replay the log. This should
62 # succeed and after the filesystem is mounted the snapshot should not be visible
63 # anymore.
64 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/snap1
65 _run_btrfs_util_prog subvolume delete $SCRATCH_MNT/snap1
66 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT
67 _flakey_drop_and_remount
68 [ -e $SCRATCH_MNT/snap1 ] && echo "Snapshot snap1 still exists after log replay"
69
70 # Similar scenario as above, but this time the snapshot is created inside a
71 # directory and not directly under the root (mount point path).
72 mkdir $SCRATCH_MNT/testdir
73 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/testdir/snap2
74 _run_btrfs_util_prog subvolume delete $SCRATCH_MNT/testdir/snap2
75 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir
76 _flakey_drop_and_remount
77 [ -e $SCRATCH_MNT/testdir/snap2 ] && \
78         echo "Snapshot snap2 still exists after log replay"
79
80 _unmount_flakey
81
82 echo "Silence is golden"
83
84 status=0
85 exit