summaryrefslogtreecommitdiff
path: root/tests/btrfs/136
blob: 3cb7150f9e64a83208aa8956fd64adb905863448 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2017 Lakshmipathi.G  All Rights Reserved.
#
# FS QA Test 136
#
# Test btrfs-convert
#
# 1) create ext3 filesystem & populate it.
# 2) upgrade ext3 filesystem to ext4.
# 3) populate data.
# 4) source has combination of non-extent and extent files.
# 5) convert it to btrfs, mount and verify contents.
. ./common/preamble
_begin_fstest auto convert

. ./common/filter

_supported_fs btrfs
_require_scratch_nocheck
# ext4 does not support zoned block device
_require_non_zoned_device "${SCRATCH_DEV}"

_require_command "$BTRFS_CONVERT_PROG" btrfs-convert
_require_command "$MKFS_EXT4_PROG" mkfs.ext4
_require_command "$E2FSCK_PROG" e2fsck
_require_command "$TUNE2FS_PROG" tune2fs

BLOCK_SIZE=`_get_block_size $TEST_DIR`
EXT_MD5SUM="$tmp.ext43"
BTRFS_MD5SUM="$tmp.btrfs"

populate_data(){
	data_path=$1
	mkdir -p $data_path
	args=`_scale_fsstress_args -p 20 -n 100 $FSSTRESS_AVOID -d $data_path`
	echo "Run fsstress $args" >>$seqres.full
	$FSSTRESS_PROG $args >>$seqres.full &
	fsstress_pid=$!
	wait $fsstress_pid
}

# Create & populate an ext3 filesystem
$MKFS_EXT4_PROG -F -t ext3 -b $BLOCK_SIZE $SCRATCH_DEV > $seqres.full 2>&1 || \
	_notrun "Could not create ext3 filesystem"

# mount and populate non-extent file
mount -t ext3 $SCRATCH_DEV $SCRATCH_MNT
populate_data "$SCRATCH_MNT/ext3_ext4_data/ext3"
_scratch_unmount

# Upgrade it to ext4.
$TUNE2FS_PROG -O extents,uninit_bg,dir_index $SCRATCH_DEV >> $seqres.full 2>&1
# After Conversion, its highly recommended to run e2fsck.
$E2FSCK_PROG -fyD $SCRATCH_DEV >> $seqres.full 2>&1

# mount and populate extent file
mount -t ext4 $SCRATCH_DEV $SCRATCH_MNT
populate_data "$SCRATCH_MNT/ext3_ext4_data/ext4"

# Compute md5 of ext3,ext4 files.
find "$SCRATCH_MNT/ext3_ext4_data" -type f -fprint "$EXT_MD5SUM"
sort "$EXT_MD5SUM" -o "$EXT_MD5SUM"
_scratch_unmount

# Convert non-extent & extent data 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"

# Compute md5 for converted files.
find "$SCRATCH_MNT/ext3_ext4_data" -type f -fprint "$BTRFS_MD5SUM"
sort "$BTRFS_MD5SUM" -o "$BTRFS_MD5SUM"

# Compare two md5sum files.
btrfs_perm=`md5sum "$BTRFS_MD5SUM" | cut -f1 -d' '`
ext_perm=`md5sum "$EXT_MD5SUM" | cut -f1 -d' '`

if [ "$btrfs_perm" != "$ext_perm" ];then
       echo "md5sum mismatch"
fi

# success, all done
echo "Silence is golden"
status=0
exit