-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbcache_func.bash
More file actions
183 lines (169 loc) · 5.73 KB
/
bcache_func.bash
File metadata and controls
183 lines (169 loc) · 5.73 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/bash
function pkg_install() {
log_file=logs/pkg_install.log
zypper --non-interactive in bcache-tools fio python3 | tee $log_file
if [ $? -ne 0 ]; then
echo "package installation FAIL" | tee -a $log_file
exit 1
else
echo "package installation PASS" | tee -a $log_file
exit 0
fi
}
function fio_stress() {
conf_file=${1:-'bcache.fio'}
fio $conf_file
}
function make_cache() {
log_file=logs/make_cache.log
echo -n "input the device names to be used as cache, split by space:"
read cache_dev
echo -n "input the devices name to be used as backend, split by space:"
read backend_dev
make-bcache -B $backend_dev -C $cache_dev -w4k -b1M --writeback | tee $log_file
if [ $? -ne 0 ]; then
echo "cache creating FAIL" | tee -a $log_file
exit 1
else
bcache-status | tee -a $log_file
sleep 3
bcache-status |grep "\[writeback\]"
if [ $? -ne 0 ]; then
echo "cache creating PASS" | tee -a $log_file
exit 0
else
echo "cache mode check FAIL" | tee -a $log_file
exit 1
fi
fi
}
function attach_cache() {
log_file=logs/attach_cache.log
cache_dev=`bcache show |grep \(cache |awk '{print $1}'`
echo -ne "cache dev is \n$cache_dev \nStart to attch it to backend devices\n"
for i in `bcache show |grep \(data |grep 'no cache' |awk '{print $1}'`;do bcache attach $cache_dev $i;done
result=`bcache show |grep \(data |grep 'no cache'`
if [ -z "$result" ]; then
echo "attach cache PASS" | tee $log_file
else
echo "attach cache FAIL" | tee $log_file
exit 1
fi
}
function detach_cache() {
log_file=logs/detach_cache.log
back_dev=`bcache show |grep \(data |awk '{print $1}'`
echo -ne "backend devices are(is) \n$back_dev \nStart to detach them(it)\n"
for i in $back_dev
do
bcache detach $i;
if [ $? -ne 0 ]; then
echo "detach cache FAIL" | tee $log_file
exit 1
fi
sleep 3
bcache-super-show -f $i | grep dev.data.cache_state |grep detached
if [ $? -ne 0 ]; then
echo "check cache status FAIL" | tee $log_file
exit 1
fi
done
echo "detach cache PASS" |tee -a $log_file
}
function chg_cache_mode() {
log_file=logs/chg_cache_mode.log
backend_dev=`bcache show|grep \(data |awk '{print $1}'| awk -F"/dev/" '{print $2}' | sed -n '1p'`
for i in writethrough writeback writearound none
do
bcache set-cachemode /dev/$backend_dev
sleep 3
grep -nr "[$i]" /sys/block/$backend_dev/bcache/cache_mode | tee $log_file
if [ $? -ne 0 ]; then
echo "cache mode change FAIL" | tee -a $log_file
exit 1
fi
done
echo "cache mode change PASS" | tee -a $log_file
}
function writeback_rate_debug() {
backend_dev=`bcache show|grep \(data |awk '{print $1}'| awk -F"/dev/" '{print $2}' | sed -n '1p'`
for i in 1 2 3 4 5;do cat /sys/block/$backend_dev/bcache/writeback_rate_debug;sleep 5;done
}
function writeback_percent() {
log_file=logs/writeback_percent.log
percent="$1"
backend_dev=`bcache show|grep \(data |awk '{print $1}'| awk -F"/dev/" '{print $2}' | sed -n '1p'`
echo "the writeback percent value should be between 0 to 100, the default vaule is 10"
echo $percent > /sys/block/$backend_dev/bcache/writeback_percent
grep $percent /sys/block/$backend_dev/bcache/writeback_percent
if [ $? -ne 0 ]; then
echo "writeback percent change FAIL" | tee -a $log_file
exit 1
else
echo "writeback percent change PASS" | tee -a $log_file
exit 0
fi
}
function cache_replacement_policy() {
log_file=logs/cache_replacement_policy.log
cache_dev=`bcache show |grep \(cache |awk '{print $1}' | awk -F"/dev/" '{print $2}'`
for i in lru fifo random
do
echo $i >/sys/block/$cache_dev/bcache/cache_replacement_policy
sleep 5
bcache-status | grep "\[$i\]"
if [ $? -ne 0 ]; then
echo "cache replacement policy FAIL" | tee -a $log_file
exit 1
fi
done
echo "cache replacement policy PASS" | tee -a $log_file
exit 0
}
function flash_vol_create() {
log_file=logs/flash_vol_create.log
cache_dev=`bcache show |grep \(cache |awk '{print $1}'`
cacheuuid=`bcache-status |grep UUID|awk '{print $2}'`
vol_size=$1
echo $vol_size > /sys/fs/bcache/$cacheuuid/flash_vol_create
if [ $? -ne 0 ]; then
echo "flash volume create FAIL" | tee $log_file
exit 1
else
echo "flash volume create PASS" | tee $log_file
fi
sleep 3
vol_name=`lsblk $cache_dev | sed -n '$p' | awk '{print $1}' | awk -F └─ '{print $2}'`
mkfs -t ext4 /dev/$vol_name
if [ $? -ne 0 ]; then
echo "mkfs on flash volume FAIL" | tee -a $log_file
exit 1
else
echo "mkfs on flash volume PASS" | tee -a $log_file
exit 0
fi
}
function gc() {
log_file=logs/gc.log
cacheuuid=`bcache-status |grep UUID|awk '{print $2}'`
echo 1 > /sys/fs/bcache/$cacheuuid/internal/trigger_gc
if [ $? -ne 0 ]; then
echo "gc FAIL" | tee $log_file
exit 1
else
echo "gc PASS" | tee $log_file
exit 0
fi
}
function clean_up() {
log_file=logs/clean_up.log
for i in `bcache show | grep dev | awk '{print $1}'`;do bcache unregister $i | tee $log_file; wipefs -fa $i |tee -a $log_file;done
a=`bcache show | grep dev`
if [ -z "$a" ]; then
echo "Environment clean up PASS" | tee -a $log_file
exit 0
else
echo "Environment clean up FAIL" | tee -a $log_file
exit 1
fi
}