9e3f991291d05e43b9ecf1b71ec6674c41c0b660
[xfstests-dev.git] / tests / btrfs / 012
1 #! /bin/bash
2 # FS QA Test No. 012
3 #
4 # Test btrfs-convert
5 #
6 # 1) create ext4 filesystem & populate it
7 # 2) convert it to btrfs, mount it, verify contents
8 # 3) verify archived ext4 image integriy & contents
9 # 4) populate btrfs fs with new data
10 # 5) roll back conversion to original ext4
11 # 6) verify rolled-back fs integrity & contents
12 #
13 #-----------------------------------------------------------------------
14 # Copyright (c) 2013 Red Hat, Inc.  All Rights Reserved.
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29 #
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "== QA output created by $seq"
34
35 here=`pwd`
36 tmp=/tmp/$$
37 status=1        # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
39
40 _cleanup()
41 {
42     cd /
43     rm -f $tmp.*
44 }
45
46 # get standard environment, filters and checks
47 . ./common/rc
48 . ./common/filter.btrfs
49
50 # real QA test starts here
51
52 # Modify as appropriate.
53 _supported_fs btrfs
54 _supported_os Linux
55 _require_scratch_nocheck
56
57 BTRFS_CONVERT_PROG="`set_prog_path btrfs-convert`"
58 E2FSCK_PROG="`set_prog_path e2fsck`"
59
60 _require_command $BTRFS_CONVERT_PROG btrfs-convert
61 _require_command $MKFS_EXT4_PROG mkfs.ext4
62 _require_command $E2FSCK_PROG e2fsck
63
64 rm -f $seqres.full
65
66 # Create & populate an ext4 filesystem
67 $MKFS_EXT4_PROG -F -b 4096 $SCRATCH_DEV > $seqres.full 2>&1 || \
68         _notrun "Could not create ext4 filesystem"
69 # Manual mount so we don't use -t btrfs or selinux context
70 mount -t ext4 $SCRATCH_DEV $SCRATCH_MNT
71
72 cp -aR /lib/modules/`uname -r`/ $SCRATCH_MNT
73 _scratch_unmount
74
75 # Convert it to btrfs, mount it, verify the data
76 $BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \
77         _fail "btrfs-convert failed"
78 _scratch_mount || _fail "Could not mount new btrfs fs"
79 # (Ignore the symlinks which may be broken/nonexistent)
80 diff -r /lib/modules/`uname -r`/ $SCRATCH_MNT/`uname -r`/ 2>&1 | grep -vw "source\|build"
81
82 # Old ext4 image file should exist & be consistent
83 $E2FSCK_PROG -fn $SCRATCH_MNT/ext2_saved/image >> $seqres.full 2>&1 || \
84         _fail "archived ext4 image is corrupt"
85
86 # And the files in that image should match
87 mkdir -p $SCRATCH_MNT/mnt
88 mount -o loop $SCRATCH_MNT/ext2_saved/image $SCRATCH_MNT/mnt || \
89         _fail "could not loop mount saved ext4 image"
90 # Ignore the symlinks which may be broken/nonexistent
91 diff -r /lib/modules/`uname -r`/ $SCRATCH_MNT/mnt/`uname -r`/ 2>&1 | grep -vw "source\|build"
92 umount $SCRATCH_MNT/mnt
93
94 # Now put some fresh data on the btrfs fs
95 mkdir -p $SCRATCH_MNT/new 
96 cp -aR /lib/modules/`uname -r`/ $SCRATCH_MNT/new
97
98 _scratch_unmount
99
100 # Now restore the ext4 device
101 $BTRFS_CONVERT_PROG -r $SCRATCH_DEV >> $seqres.full 2>&1 || \
102         _fail "btrfs-convert rollback failed"
103
104 # Check it again
105 $E2FSCK_PROG -fn $SCRATCH_DEV >> $seqres.full 2>&1 || \
106         _fail "restored ext4 image is corrupt"
107
108 # Mount the un-converted ext4 device & check the contents
109 mount -t ext4 $SCRATCH_DEV $SCRATCH_MNT
110 # (Ignore the symlinks which may be broken/nonexistent)
111 diff -r /lib/modules/`uname -r`/ $SCRATCH_MNT/`uname -r`/ 2>&1 | grep -vw "source\|build"
112
113 _scratch_unmount
114
115 # success, all done
116 status=0
117 exit