blob: 1cb2905b3a53022f708f8e10e9896fd32ed61ae8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#! /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
|