-
Notifications
You must be signed in to change notification settings - Fork 6
/
provision_all.sh
executable file
·232 lines (205 loc) · 4.46 KB
/
provision_all.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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/bash
# Provisioning a single disk is rather simple, but provisioning all disks
# requires a bit more of work. Demo how to do this by allowing you to
# provision all disks specified for the specified workload criteria
# using one of the supported pre-conditioning methods.
PROVISION_CLEAN="false"
PROVISION_FORCE="false"
PROVISION_DRYRUN="false"
PROVISION_TYPE="nvme"
PROVISION_METHOD="sc"
PROVISION_WORKLOAD="random"
PROVISION_WORKDIR="provisioning"
PROVISION_MASTER="$PROVISION_WORKDIR/master"
DEFCONFIG_SEQ="defconfig-prov_sc_seq"
DEFCONFIG_RANDOM="defconfig-prov_sc_random"
DEFCONFIG="$DEFCONFIG_SEQ"
source scripts/noconfig-lib.sh
usage()
{
echo "Usage: $0 [ options ]"
echo "[ options ]:"
echo "-h | --help Print this help menu"
echo "-c | --clean Leave no trace behind, remove all work we generate"
echo "-f | --force If prior provision results are found, remove them and start fresh"
echo "--dryrun Don't do the actual provisioning, just do a dry run"
echo "-t | --type The type of storage devices to provision"
echo " Supported types:"
echo " nvme"
echo "-m | --method Use this mechanism to provision, valid methods:"
echo " sc: Santa Clara method"
echo "-w | --workload Workload to provision. Valid workloads:"
echo " seq : sequential workloads"
echo " random: random workloads"
echo " mixed: a mix of workloads, use even number"
echo " ending devices for sequential, odd for"
echo " random worloads. For instance,"
echo " /dev/nvme0n1 /dev/nvme2n1 /dev/nvme4n1"
echo " will end up with sequential workloads"
echo " /dev/nvme1n1 /dev/nvme3n1 /dev/nvme5n1"
echo " will end up with random workloads"
}
check_type()
{
TYPE=$1
case $TYPE in
nvme)
return 0
;;
*)
echo -e "Unknown type: $TYPE\n"
usage
exit
;;
esac
}
check_method()
{
METHOD=$1
case $METHOD in
sc)
return 0
;;
*)
echo -e "Unknown method: $METHOD\n"
usage
exit
;;
esac
}
check_workload()
{
WORKLOAD=$1
case $WORKLOAD in
seq)
DEFCONFIG="$DEFCONFIG_SEQ"
return 0
;;
random)
DEFCONFIG="$DEFCONFIG_RANDOM"
return 0
;;
mixed)
DEFCONFIG="$DEFCONFIG_SEQ"
return 0
;;
*)
echo -e "Unknown workload: $WORKLOAD\n"
usage
exit
;;
esac
}
parse_args()
{
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h|--help)
usage
exit
;;
-c|--clean)
PROVISION_CLEAN="true"
shift
;;
-f|--force)
PROVISION_FORCE="true"
shift
;;
--dryrun)
PROVISION_DRYRUN="false"
shift
;;
-t|--type)
PROVISION_TYPE="$2"
shift
shift
;;
-m|--method)
PROVISION_METHOD="$2"
shift
shift
;;
-w|--workload)
PROVISION_WORKLOAD="$2"
shift
shift
;;
*)
echo "Unknown parameter: $key"
usage
exit
;;
esac
done
}
verify_params()
{
check_type $PROVISION_TYPE
check_method $PROVISION_METHOD
check_workload $PROVISION_WORKLOAD
}
provision_finish()
{
if [ "$PROVISION_CLEAN" == "true" ]; then
rm -rf $TMP_WORKDIR
fi
}
trap "provision_finish" EXIT
provision_dev()
{
PROVISION_DEV=$1
PROVISION_CONFIG=$2
export DEV="$PROVISION_DEV"
make $PROVISION_CONFIG
make -j$(nproc --all)
if [ "$PROVISION_DRYRUN" != "true" ]; then
make run
else
make dryrun
fi
}
provision_dev_copy_code()
{
PROVISION_DEV=$1
PROVISION_CONFIG=$2
DEV_PROVISION_DIR="${PROVISION_WORKDIR}/${PROVISION_DEV#/dev/*}"
cp -a $PROVISION_MASTER $DEV_PROVISION_DIR
cd $DEV_PROVISION_DIR
provision_dev $PROVISION_DEV $PROVISION_CONFIG | tee log
}
switch_defconfig()
{
CONF=$1
if [ "$CONF" == "$DEFCONFIG_SEQ" ]; then
echo "$DEFCONFIG_RANDOM"
elif [ "$CONF" == "$DEFCONFIG_RANDOM" ]; then
echo "$DEFCONFIG_SEQ"
fi
}
CHECK_USER="$(id -u)"
if [ "$CHECK_USER" -ne 0 ]; then
echo "$0 must be run as root"
exit 1
fi
parse_args $@
verify_params
if [ -d $PROVISION_WORKDIR ] && [ "$PROVISION_FORCE" != "true" ]; then
echo "$PROVISION_WORKDIR directory not empty, use $0 -f if you want to remove it"
exit 1
fi
list_nvme_devs > /dev/null
if [ $? -ne 0 ]; then
echo "No nvme devices to provision"
exit 1
fi
rm -rf $PROVISION_WORKDIR
mkdir -p $PROVISION_MASTER
git archive master | tar -x -C $PROVISION_MASTER
for i in $(list_nvme_devs); do
nohup $(provision_dev_copy_code $i $DEFCONFIG) >/dev/null 2>&1 &
if [ "$PROVISION_WORKLOAD" == "mixed" ]; then
DEFCONFIG="$(switch_defconfig $DEFCONFIG)"
fi
done