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
13 #-----------------------------------------------------------------------
14 # Copyright (c) 2013 Red Hat, Inc. All Rights Reserved.
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.
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.
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 #-----------------------------------------------------------------------
32 seqres=$RESULT_DIR/$seq
33 echo "== QA output created by $seq"
37 status=1 # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
46 # get standard environment, filters and checks
48 . ./common/filter.btrfs
50 # real QA test starts here
52 # Modify as appropriate.
55 _require_scratch_nocheck
57 BTRFS_CONVERT_PROG="`set_prog_path btrfs-convert`"
58 E2FSCK_PROG="`set_prog_path e2fsck`"
60 _require_command "$BTRFS_CONVERT_PROG" btrfs-convert
61 _require_command "$MKFS_EXT4_PROG" mkfs.ext4
62 _require_command "$E2FSCK_PROG" e2fsck
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
72 cp -aR /lib/modules/`uname -r`/ $SCRATCH_MNT
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"
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"
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
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
100 # Now restore the ext4 device
101 $BTRFS_CONVERT_PROG -r $SCRATCH_DEV >> $seqres.full 2>&1 || \
102 _fail "btrfs-convert rollback failed"
105 $E2FSCK_PROG -fn $SCRATCH_DEV >> $seqres.full 2>&1 || \
106 _fail "restored ext4 image is corrupt"
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"
115 # Convert it to btrfs, mount it and delete "ext2_saved"
116 $BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \
117 _fail "btrfs-convert failed"
118 _scratch_mount || _fail "Could not mount new btrfs fs"
119 $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/ext2_saved >> $seqres.full 2>&1 ||
120 _fail "failed to delete ext2_saved subvolume"
123 # Now restore the ext4 device, expecting a failure
124 $BTRFS_CONVERT_PROG -r $SCRATCH_DEV >> $seqres.full 2>&1
125 [ $? -eq 1 ] || _fail "Failure is expected, but btrfs-convert returns with rollback complete"