xfstests: cleanup duplicates in all tests
[xfstests-dev.git] / tests / btrfs / 254
1 #! /bin/bash
2 # FS QA Test No. 254
3 #
4 # Test btrfs's subvolume and snapshot support
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2011 Red Hat.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32
33 _cleanup()
34 {
35     rm -f $tmp.*
36 }
37
38 trap "_cleanup ; exit \$status" 0 1 2 3 15
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43
44 # real QA test starts here
45 _supported_fs btrfs
46 _supported_os Linux
47 _require_scratch
48
49 _scratch_mkfs > /dev/null 2>&1
50 _scratch_mount
51
52 # First test basic snapshotting
53 echo "Creating file foo in root dir"
54 dd if=/dev/zero of=$SCRATCH_MNT/foo bs=1M count=1 &> /dev/null
55 echo "List root dir"
56 ls $SCRATCH_MNT
57 echo "Creating snapshot of root dir"
58 $BTRFS_UTIL_PROG subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/snap | _filter_scratch
59 echo "List root dir after snapshot"
60 ls $SCRATCH_MNT
61 echo "List snapshot dir"
62 ls $SCRATCH_MNT/snap
63 rm -f $SCRATCH_MNT/foo
64 echo "List root dir after rm of foo"
65 ls $SCRATCH_MNT
66 echo "List snapshot dir"
67 ls $SCRATCH_MNT/snap
68
69 # Test creating a normal subvolme
70 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol | _filter_scratch
71 echo "Listing root dir"
72 ls $SCRATCH_MNT
73 echo "Listing subvol"
74 ls $SCRATCH_MNT/subvol
75
76 # Test setting a default mount
77 echo "Creating file bar in subvol"
78 dd if=/dev/zero of=$SCRATCH_MNT/subvol/bar bs=1M count=1 &> /dev/null
79 echo "Setting subvol to the default"
80 $BTRFS_UTIL_PROG subvolume set-default 0 $SCRATCH_MNT/subvol | _filter_scratch
81 _scratch_remount
82 echo "List root dir which is now subvol"
83 ls $SCRATCH_MNT
84 _scratch_unmount
85 echo "Mounting sbuvolid=0 for the root dir"
86 _scratch_mount "-o subvolid=0"
87 echo "List root dir"
88 ls $SCRATCH_MNT
89 echo "Setting the root dir as the default again"
90 $BTRFS_UTIL_PROG subvolume set-default 0 $SCRATCH_MNT | _filter_scratch
91 _scratch_remount
92 echo "List root dir"
93 ls $SCRATCH_MNT
94
95 # Test listing the subvolumes
96 echo "Listing subvolumes"
97 $BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{ print $NF }'
98
99 # Delete the snapshot
100 $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/snap | _filter_scratch
101 echo "List root dir"
102 ls $SCRATCH_MNT
103 _scratch_remount
104 echo "List root dir"
105 ls $SCRATCH_MNT
106
107 status=0 ; exit