Repository navigation
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·133 lines (106 loc) · 2.21 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·133 lines (106 loc) · 2.21 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bash
#
# If copying using simple dd, after resize2fs using shrinked size,
# fsck report errors, this script for investigating it
#
set -e
a=${1:-"test.img"}
b=${2:-"test_dup.img"}
size=${3:-$((1024 * 1024 * 512))} # 512 MiB
create_delete_iterations=${4:-30}
# system configuration
uname -a
function image_info()
{
dumpe2fs -h $a
}
function create_random()
{
dd if=/dev/urandom bs=1M count=1 >| $1 2>/dev/null
}
function fsck()
{
e2fsck -vvvv -f $1
}
function is_block_device()
{
return $(file $1 2>/dev/null | grep -q "sticky block special")
}
function mnt()
{
img=$1
shift
mnt_opts="$*"
if is_block_device $img; then
if [ ! -z "$mnt_opts" ]; then
mnt_opts="-o $mnt_opts"
fi
mount -t ext4 $img mnt
else
if [ ! -z "$mnt_opts" ]; then
mnt_opts=",$mnt_opts"
fi
mount -o loop$mnt_opts -t ext4 $img mnt
fi
}
function fill_image()
{
if ! is_block_device $1; then
fallocate -l $size $1
fi
}
function calc_md5sum()
{
if ! is_block_device $1; then
md5sum $1
fi
}
# do an acitivity, in parallel, while copying is in progress
function read_activity()
{
img=$1
mnt=$2
for i in $(seq 1 $create_delete_iterations); do
dd if=$img of=/dev/null
dd if=$img of=/dev/null bs=1K
find $mnt -type f | xargs cat > /dev/null
done
}
# create
fill_image $a
mke2fs -F -t ext4 $a
fsck $a
# mount
mkdir -p mnt
mnt $a
# fill it, with holes
for i in $(seq 1 $create_delete_iterations); do
create_random mnt/${i}.test
done
# create holes
for i in $(seq 1 $create_delete_iterations); do
if [ $((i % 2)) -eq 0 ]; then
rm mnt/${i}.test
fi
done
for i in $(seq 1 $create_delete_iterations); do
create_random mnt/${i}.test
done
sync
image_info $a
umount mnt
min_size_4k=$(resize2fs -P $a 2>/dev/null | awk '{print $NF}')
fsck $a
resize2fs $a $min_size_4k
fsck $a
mnt $a ro
read_activity $a mnt &
# copy and check
nc -nlp 2048 | tee >(md5sum >&2) | dd of=$b oflag=direct iflag=fullblock & # receiver
sleep 1
dd if=$a bs=4k count=$min_size_4k | tee >(md5sum >&2) | nc -q1 localhost 2048 # sender
sync
image_info $b
calc_md5sum $a
calc_md5sum $b
fsck $b