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 BLOCK_SIZE=`_get_block_size $TEST_DIR`
68 # Create & populate an ext4 filesystem
69 $MKFS_EXT4_PROG -F -b $BLOCK_SIZE $SCRATCH_DEV > $seqres.full 2>&1 || \
70 _notrun "Could not create ext4 filesystem"
71 # Manual mount so we don't use -t btrfs or selinux context
72 mount -t ext4 $SCRATCH_DEV $SCRATCH_MNT
74 cp -aR /lib/modules/`uname -r`/ $SCRATCH_MNT
77 # Convert it to btrfs, mount it, verify the data
78 $BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \
79 _fail "btrfs-convert failed"
80 _scratch_mount || _fail "Could not mount new btrfs fs"
81 # (Ignore the symlinks which may be broken/nonexistent)
82 diff -r /lib/modules/`uname -r`/ $SCRATCH_MNT/`uname -r`/ 2>&1 | grep -vw "source\|build"
84 # Old ext4 image file should exist & be consistent
85 $E2FSCK_PROG -fn $SCRATCH_MNT/ext2_saved/image >> $seqres.full 2>&1 || \
86 _fail "archived ext4 image is corrupt"
88 # And the files in that image should match
89 mkdir -p $SCRATCH_MNT/mnt
90 mount -o loop $SCRATCH_MNT/ext2_saved/image $SCRATCH_MNT/mnt || \
91 _fail "could not loop mount saved ext4 image"
92 # Ignore the symlinks which may be broken/nonexistent
93 diff -r /lib/modules/`uname -r`/ $SCRATCH_MNT/mnt/`uname -r`/ 2>&1 | grep -vw "source\|build"
94 umount $SCRATCH_MNT/mnt
96 # Now put some fresh data on the btrfs fs
97 mkdir -p $SCRATCH_MNT/new
98 cp -aR /lib/modules/`uname -r`/ $SCRATCH_MNT/new
102 # Now restore the ext4 device
103 $BTRFS_CONVERT_PROG -r $SCRATCH_DEV >> $seqres.full 2>&1 || \
104 _fail "btrfs-convert rollback failed"
107 $E2FSCK_PROG -fn $SCRATCH_DEV >> $seqres.full 2>&1 || \
108 _fail "restored ext4 image is corrupt"
110 # Mount the un-converted ext4 device & check the contents
111 mount -t ext4 $SCRATCH_DEV $SCRATCH_MNT
112 # (Ignore the symlinks which may be broken/nonexistent)
113 diff -r /lib/modules/`uname -r`/ $SCRATCH_MNT/`uname -r`/ 2>&1 | grep -vw "source\|build"
117 # Convert it to btrfs, mount it and delete "ext2_saved"
118 $BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \
119 _fail "btrfs-convert failed"
120 _scratch_mount || _fail "Could not mount new btrfs fs"
121 $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/ext2_saved >> $seqres.full 2>&1 ||
122 _fail "failed to delete ext2_saved subvolume"
125 # Now restore the ext4 device, expecting a failure
126 $BTRFS_CONVERT_PROG -r $SCRATCH_DEV >> $seqres.full 2>&1
127 [ $? -eq 1 ] || _fail "Failure is expected, but btrfs-convert returns with rollback complete"