-
Notifications
You must be signed in to change notification settings - Fork 21
/
6000-snapimage_write.sh
executable file
·131 lines (97 loc) · 2.27 KB
/
6000-snapimage_write.sh
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
#!/bin/bash -e
#
# SPDX-License-Identifier: GPL-2.0+
. ./functions.sh
. ./blksnap.sh
echo "---"
echo "Snapshot write test"
# diff_storage_minimum=262144 - set 256 K sectors, it's 125MiB.
modprobe blksnap diff_storage_minimum=262144 chunk_maximum_in_queue=16
sleep 2s
# check module is ready
blksnap_version
if [ -z $1 ]
then
echo "Should use loop device"
#echo "Create original loop device"
LOOPFILE=${HOME}/blksnap-original.img
dd if=/dev/zero of=${LOOPFILE} count=1024 bs=1M
DEVICE=$(loop_device_attach ${LOOPFILE})
mkfs.xfs -f ${DEVICE}
# mkfs.ext4 ${DEVICE}
ORIGINAL=/mnt/blksnap-original
mkdir -p ${ORIGINAL}
mount ${DEVICE} ${ORIGINAL}
else
echo "Should use device [$1]"
DEVICE=$1
MNTDIR=$(findmnt -n -o TARGET ${DEVICE})
echo ${MNTDIR}
ORIGINAL=${MNTDIR}"/blksnap-original"
rm -rf ${ORIGINAL}/*
mkdir -p ${ORIGINAL}
fi
FSTYPE=$(findmnt -n -o FSTYPE ${DEVICE})
if [ "${FSTYPE}" = "xfs" ]
then
MOUNTOPT="-o nouuid"
else
MOUNTOPT=""
fi
if [ -z $2 ]
then
ITERATION_CNT="3"
else
ITERATION_CNT="$2"
fi
IMAGE=/mnt/blksnap-image0
mkdir -p ${IMAGE}
DIFF_STORAGE="/dev/shm"
generate_files_direct ${ORIGINAL} "original-it#0" 5
drop_cache
for ITERATOR in $(seq 1 $ITERATION_CNT)
do
echo "Itearation: ${ITERATOR}"
blksnap_snapshot_create ${DEVICE} "${DIFF_STORAGE}" "256M"
blksnap_snapshot_take
DEVICE_IMAGE=$(blksnap_get_image ${DEVICE})
mount ${MOUNTOPT} ${DEVICE_IMAGE} ${IMAGE}
generate_block_MB ${IMAGE} "image-it#${ITERATOR}" 10 &
IMAGE_PID=$!
generate_block_MB ${ORIGINAL} "original-it#${ITERATOR}" 10
wait ${IMAGE_PID}
drop_cache
check_files ${IMAGE} &
IMAGE_PID=$!
check_files ${ORIGINAL}
wait ${IMAGE_PID}
drop_cache
#echo "pause, press ..."
#read -n 1
echo "Remount image device "${DEVICE_IMAGE}
umount ${DEVICE_IMAGE}
mount ${MOUNTOPT} ${DEVICE_IMAGE} ${IMAGE}
check_files ${IMAGE} &
IMAGE_PID=$!
check_files ${ORIGINAL}
wait ${IMAGE_PID}
#echo "pause, press ..."
#read -n 1
umount ${IMAGE}
blksnap_snapshot_destroy
done
if [ -z $1 ]
then
echo "Destroy original loop device"
umount ${ORIGINAL}
blksnap_detach ${DEVICE}
loop_device_detach ${DEVICE}
imagefile_cleanup ${LOOPFILE}
else
echo "Cleanup directory [${ORIGINAL}]"
rm -rf ${ORIGINAL}/*
fi
echo "Unload module"
modprobe -r blksnap
echo "Snapshot write test finish"
echo "---"