2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Red Hat, Inc. All Rights Reserved.
9 # 1) create ext4 filesystem & populate it
10 # 2) convert it to btrfs, mount it, verify contents
11 # 3) verify archived ext4 image integriy & contents
12 # 4) populate btrfs fs with new data
13 # 5) roll back conversion to original ext4
14 # 6) verify rolled-back fs integrity & contents
17 seqres=$RESULT_DIR/$seq
18 echo "== QA output created by $seq"
22 status=1 # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
31 # get standard environment, filters and checks
33 . ./common/filter.btrfs
35 # real QA test starts here
37 # Modify as appropriate.
39 _require_scratch_nocheck
41 _require_command "$BTRFS_CONVERT_PROG" btrfs-convert
42 _require_command "$MKFS_EXT4_PROG" mkfs.ext4
43 _require_command "$E2FSCK_PROG" e2fsck
45 _require_fs_space $SCRATCH_MNT $(du -s /lib/modules/`uname -r` | ${AWK_PROG} '{print $1}')
49 BLOCK_SIZE=`_get_block_size $TEST_DIR`
51 # Create & populate an ext4 filesystem
52 $MKFS_EXT4_PROG -F -b $BLOCK_SIZE $SCRATCH_DEV > $seqres.full 2>&1 || \
53 _notrun "Could not create ext4 filesystem"
54 # Manual mount so we don't use -t btrfs or selinux context
55 mount -t ext4 $SCRATCH_DEV $SCRATCH_MNT
57 cp -aR /lib/modules/`uname -r`/ $SCRATCH_MNT
60 # Convert it to btrfs, mount it, verify the data
61 $BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \
62 _fail "btrfs-convert failed"
63 _try_scratch_mount || _fail "Could not mount new btrfs fs"
64 # (Ignore the symlinks which may be broken/nonexistent)
65 diff -r /lib/modules/`uname -r`/ $SCRATCH_MNT/`uname -r`/ 2>&1 | grep -vw "source\|build"
67 # Old ext4 image file should exist & be consistent
68 $E2FSCK_PROG -fn $SCRATCH_MNT/ext2_saved/image >> $seqres.full 2>&1 || \
69 _fail "archived ext4 image is corrupt"
71 # And the files in that image should match
72 mkdir -p $SCRATCH_MNT/mnt
73 mount -o loop $SCRATCH_MNT/ext2_saved/image $SCRATCH_MNT/mnt || \
74 _fail "could not loop mount saved ext4 image"
75 # Ignore the symlinks which may be broken/nonexistent
76 diff -r /lib/modules/`uname -r`/ $SCRATCH_MNT/mnt/`uname -r`/ 2>&1 | grep -vw "source\|build"
77 umount $SCRATCH_MNT/mnt
79 # Now put some fresh data on the btrfs fs
80 mkdir -p $SCRATCH_MNT/new
81 cp -aR /lib/modules/`uname -r`/ $SCRATCH_MNT/new
85 # Now restore the ext4 device
86 $BTRFS_CONVERT_PROG -r $SCRATCH_DEV >> $seqres.full 2>&1 || \
87 _fail "btrfs-convert rollback failed"
90 $E2FSCK_PROG -fn $SCRATCH_DEV >> $seqres.full 2>&1 || \
91 _fail "restored ext4 image is corrupt"
93 # Mount the un-converted ext4 device & check the contents
94 mount -t ext4 $SCRATCH_DEV $SCRATCH_MNT
95 # (Ignore the symlinks which may be broken/nonexistent)
96 diff -r /lib/modules/`uname -r`/ $SCRATCH_MNT/`uname -r`/ 2>&1 | grep -vw "source\|build"
100 # Convert it to btrfs, mount it and delete "ext2_saved"
101 $BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \
102 _fail "btrfs-convert failed"
103 _try_scratch_mount || _fail "Could not mount new btrfs fs"
104 $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/ext2_saved >> $seqres.full 2>&1 ||
105 _fail "failed to delete ext2_saved subvolume"
108 # Now restore the ext4 device, expecting a failure
109 $BTRFS_CONVERT_PROG -r $SCRATCH_DEV >> $seqres.full 2>&1
110 [ $? -eq 1 ] || _fail "Failure is expected, but btrfs-convert returns with rollback complete"