#! /bin/bash # SPDX-License-Identifier: GPL-2.0 # Copyright (c) 2013 Red Hat, Inc. All Rights Reserved. # # FS QA Test No. 012 # # Test btrfs-convert # # 1) create ext4 filesystem & populate it # 2) convert it to btrfs, mount it, verify contents # 3) verify archived ext4 image integriy & contents # 4) populate btrfs fs with new data # 5) roll back conversion to original ext4 # 6) verify rolled-back fs integrity & contents # . ./common/preamble _begin_fstest auto convert . ./common/filter.btrfs _supported_fs btrfs _require_scratch_nocheck _require_command "$BTRFS_CONVERT_PROG" btrfs-convert _require_command "$MKFS_EXT4_PROG" mkfs.ext4 _require_command "$E2FSCK_PROG" e2fsck # ext4 does not support zoned block device _require_non_zoned_device "${SCRATCH_DEV}" _require_loop _require_extra_fs ext4 SOURCE_DIR=/etc BASENAME=$(basename $SOURCE_DIR) BLOCK_SIZE=`_get_block_size $TEST_DIR` # Create & populate an ext4 filesystem $MKFS_EXT4_PROG -F -b $BLOCK_SIZE $SCRATCH_DEV > $seqres.full 2>&1 || \ _notrun "Could not create ext4 filesystem" # Manual mount so we don't use -t btrfs or selinux context mount -t ext4 $SCRATCH_DEV $SCRATCH_MNT _require_fs_space $SCRATCH_MNT $(du -s $SOURCE_DIR | ${AWK_PROG} '{print $1}') $TIMEOUT_PROG 10 cp -aRP $SOURCE_DIR $SCRATCH_MNT _scratch_unmount # Convert it to btrfs, mount it, verify the data $BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \ _fail "btrfs-convert failed" _try_scratch_mount || _fail "Could not mount new btrfs fs" # (Ignore the symlinks which may be broken/nonexistent) diff --no-dereference -r $SOURCE_DIR $SCRATCH_MNT/$BASENAME/ 2>&1 # Old ext4 image file should exist & be consistent $E2FSCK_PROG -fn $SCRATCH_MNT/ext2_saved/image >> $seqres.full 2>&1 || \ _fail "archived ext4 image is corrupt" # And the files in that image should match mkdir -p $SCRATCH_MNT/mnt mount -o loop $SCRATCH_MNT/ext2_saved/image $SCRATCH_MNT/mnt || \ _fail "could not loop mount saved ext4 image" # Ignore the symlinks which may be broken/nonexistent diff --no-dereference -r $SOURCE_DIR $SCRATCH_MNT/mnt/$BASENAME/ 2>&1 umount $SCRATCH_MNT/mnt # Now put some fresh data on the btrfs fs mkdir -p $SCRATCH_MNT/new $TIMEOUT_PROG 10 cp -aRP $SOURCE_DIR $SCRATCH_MNT/new _scratch_unmount # Now restore the ext4 device $BTRFS_CONVERT_PROG -r $SCRATCH_DEV >> $seqres.full 2>&1 || \ _fail "btrfs-convert rollback failed" # Check it again $E2FSCK_PROG -fn $SCRATCH_DEV >> $seqres.full 2>&1 || \ _fail "restored ext4 image is corrupt" # Mount the un-converted ext4 device & check the contents mount -t ext4 $SCRATCH_DEV $SCRATCH_MNT # (Ignore the symlinks which may be broken/nonexistent) diff --no-dereference -r $SOURCE_DIR $SCRATCH_MNT/$BASENAME/ 2>&1 _scratch_unmount # Convert it to btrfs, mount it and delete "ext2_saved" $BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \ _fail "btrfs-convert failed" _try_scratch_mount || _fail "Could not mount new btrfs fs" $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/ext2_saved >> $seqres.full 2>&1 || _fail "failed to delete ext2_saved subvolume" _scratch_unmount # Now restore the ext4 device, expecting a failure $BTRFS_CONVERT_PROG -r $SCRATCH_DEV >> $seqres.full 2>&1 [ $? -eq 1 ] || _fail "Failure is expected, but btrfs-convert returns with rollback complete" # success, all done status=0 exit