xfstests: more 214 updates
[xfstests-dev.git] / 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 # creator
25 owner=josef@redhat.com
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33
34 _cleanup()
35 {
36     rm -f $tmp.*
37 }
38
39 trap "_cleanup ; exit \$status" 0 1 2 3 15
40
41 # get standard environment, filters and checks
42 . ./common.rc
43 . ./common.filter
44
45 # real QA test starts here
46 _supported_fs btrfs
47 _supported_os Linux
48 _require_scratch
49
50 _scratch_mkfs > /dev/null 2>&1
51 _scratch_mount
52
53 # First test basic snapshotting
54 echo "Creating file foo in root dir"
55 dd if=/dev/zero of=$SCRATCH_MNT/foo bs=1M count=1 &> /dev/null
56 echo "List root dir"
57 ls $SCRATCH_MNT
58 echo "Creating snapshot of root dir"
59 btrfs subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/snap | _filter_scratch
60 echo "List root dir after snapshot"
61 ls $SCRATCH_MNT
62 echo "List snapshot dir"
63 ls $SCRATCH_MNT/snap
64 rm -f $SCRATCH_MNT/foo
65 echo "List root dir after rm of foo"
66 ls $SCRATCH_MNT
67 echo "List snapshot dir"
68 ls $SCRATCH_MNT/snap
69
70 # Test creating a normal subvolme
71 btrfs subvolume create $SCRATCH_MNT/subvol | _filter_scratch
72 echo "Listing root dir"
73 ls $SCRATCH_MNT
74 echo "Listing subvol"
75 ls $SCRATCH_MNT/subvol
76
77 # Test setting a default mount
78 echo "Creating file bar in subvol"
79 dd if=/dev/zero of=$SCRATCH_MNT/subvol/bar bs=1M count=1 &> /dev/null
80 echo "Setting subvol to the default"
81 btrfs subvolume set-default 0 $SCRATCH_MNT/subvol | _filter_scratch
82 _scratch_remount
83 echo "List root dir which is now subvol"
84 ls $SCRATCH_MNT
85 _scratch_unmount
86 echo "Mounting sbuvolid=0 for the root dir"
87 _scratch_mount "-o subvolid=0"
88 echo "List root dir"
89 ls $SCRATCH_MNT
90 echo "Setting the root dir as the default again"
91 btrfs subvolume set-default 0 $SCRATCH_MNT | _filter_scratch
92 _scratch_remount
93 echo "List root dir"
94 ls $SCRATCH_MNT
95
96 # Test listing the subvolumes
97 echo "Listing subvolumes"
98 btrfs subvolume list $SCRATCH_MNT | awk '{ print $NF }'
99
100 # Delete the snapshot
101 btrfs subvolume delete $SCRATCH_MNT/snap | _filter_scratch
102 echo "List root dir"
103 ls $SCRATCH_MNT
104 _scratch_remount
105 echo "List root dir"
106 ls $SCRATCH_MNT
107
108 status=0 ; exit