-
Notifications
You must be signed in to change notification settings - Fork 2
/
common
executable file
·218 lines (185 loc) · 4.75 KB
/
common
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
#!/bin/bash
#
REPLY=""
function get_project() {
local _PDIR=$1
if [ -e "$_PDIR/scripts/faddr2line" ]; then
REPLY="kernel"
return
fi
if [ -e "$_PDIR/buildlib/cbuild" ]; then
REPLY="rdma-core"
return
fi
if [ -e "$_PDIR/rdma/rdma.h" ]; then
REPLY="iproute"
return
fi
if [ -e "$_PDIR/x" ]; then
REPLY="x-tools"
return
fi
REPLY=""
}
function get_target() {
local _PROJECT=$1
local _TARGET=""
if [ "$_PROJECT" == "rdma-core" ]; then
_TARGET="rdma-core"
fi
if [ "$_PROJECT" == "kernel" ]; then
_TARGET=$(git symbolic-ref --short HEAD)
if [ "$_TARGET" != "rdma-next" ] && [ "$_TARGET" != "rdma-rc" ]; then
# Let's put default for now
_TARGET="rdma-next"
fi
fi
if [ "$_PROJECT" == "iproute" ]; then
_TARGET=$(git symbolic-ref --short HEAD)
if [ "$_TARGET" != "iproute2-next" ] && [ "$_TARGET" != "iproute2-rc" ]; then
# Let's put default for now
_TARGET="iproute2-next"
fi
fi
REPLY=$_TARGET
}
function change_target() {
# Replace rdma-next to be mlx5-next
local _PDIR=$1
local _PROJECT=$2
if [ "$_PROJECT" != "kernel" ]; then
return
fi
local _FOUND=0
echo "------------------ GET_MAINTAINER checks ------------------"
for _file in $_PDIR/*.patch; do
[ -e "$_file" ] || continue
[ "$_file" != "$_PDIR/0000-cover-letter.patch" ] || continue
local _IS_RDMA_NEXT_TARGET=$(grep -c "PATCH rdma-next" $_file)
if [ $_IS_RDMA_NEXT_TARGET -eq 1 ]; then
local _IS_MLX5_NEXT_TARGET=$($GET_MAINTAINER --email --nol --nos --nosubsystem --noroles $_file | grep Saeed -c)
if [ $_IS_MLX5_NEXT_TARGET -eq 1 ]; then
_FOUND=1
echo "REPLACED: $_file"
sed -i -e 's/PATCH rdma-next/PATCH mlx5-next/g' $_file
sed -i -e '/Cc: RDMA mailing list/s/$/, Saeed Mahameed <[email protected]>, linux-netdev <[email protected]>/' $_file
fi
fi
done
if [ $_FOUND -eq 1 ]; then
if [ -f "$_PDIR/0000-cover-letter.patch" ]; then
# It is important for netdev to see it too
sed -i -e '/Cc: RDMA mailing list/s/$/, Saeed Mahameed <[email protected]>, linux-netdev <[email protected]>/' $_PDIR/0000-cover-letter.patch
fi
fi
echo "------------------ GET_MAINTAINER checks ends ------------"
}
function checkpatch() {
local _PDIR=$1
local _PROJECT=$2
sed -i "/^Issue:[ 0-9]*/Id" $_PDIR/*.patch
sed -i "/^Change-id:[ 0-9]*/Id" $_PDIR/*.patch
if [ "$_PROJECT" != "kernel" ]; then
local _IN_TREE="--no-tree --ignore PREFER_KERNEL_TYPES,FILE_PATH_CHANGES,EXECUTE_PERMISSIONS"
else
local _IN_TREE=""
fi
for _file in $_PDIR/*.patch; do
[ -e "$_file" ] || continue
[ "$_file" != "$_PDIR/0000-cover-letter.patch" ] || continue
perl $CHECKPATCH $_IN_TREE -q $_file
done
}
function check_ssh_access() {
local _ADDR=$1
set +e
ssh -q -o ConnectTimeout=2 $_ADDR exit
local _SSH_READY=$?
set -e
REPLY=$_SSH_READY
}
function numb_of_cpus() {
REPLY=$( lscpu | grep "CPU(s): " | head -n 1 | awk '{print $2}' )
}
function get_passthrough_line() {
local _VM_MACHINE=$1
REPLY=$(grep $_VM_MACHINE $DIR/machines.db | awk '{print " -device vfio-pci,host="$2} ' | tr -d '\n' )
}
function get_simx_devices_line() {
local _VM_MACHINE=$1
REPLY=$(grep $_VM_MACHINE $DIR/machines.db | awk '{print " -device "$2} ' | tr -d '\n' )
}
function mass_vfio_bind() {
local _VM_MACHINE=$1
echo "Binding devices, it takes time ...."
REPLY=$(grep $_VM_MACHINE $DIR/machines.db | awk '{print $2} ' | xargs -n1 sudo $DIR/vfio-pci-bind )
}
function qemu_location() {
local _VM_MACHINE=$1
local _IS_QEMU=$(grep $_VM_MACHINE $DIR/machines.db | awk '{print $3} ' | tail -n 1)
if [ "$_IS_QEMU" == "simx" ]; then
REPLY=$X_BI_SIMX
else
REPLY="qemu-system-x86_64"
fi
}
function is_qemu() {
local _VM_MACHINE=$1
REPLY=$(grep $_VM_MACHINE $DIR/machines.db | awk '{print $3} ' | tail -n 1)
if [ "$REPLY" == "simx" ]; then
REPLY=0
else
REPLY=1
fi
}
function get_image_type() {
local _VM_MACHINE=$1
REPLY=$(grep $_VM_MACHINE $DIR/machines.db | awk '{print $3} ' | tail -n 1)
}
# Check if SSH is ready
# 255 means connection is not possible
# 0 means connection is possible
function block_till_ssh_is_ready() {
local _SERVER=$1
echo "Block till $_SERVER SSH is ready"
set +e
ssh -q root@$_SERVER exit
local _SSH_READY=$?
set -e
while [ $_SSH_READY -ne 0 ]; do
set +e
ssh -q root@$_SERVER exit
_SSH_READY=$?
set -e
sleep 5s
done
}
function get_arg_type() {
local _ARG=$1
local _IS_NUMBER=0
case $_ARG in
''|*[!0-9]*) _IS_NUMBER=0 ;;
*) _IS_NUMBER=1 ;;
esac
if [ $_IS_NUMBER -eq 0 ]; then
git show-ref --tags -q $_ARG
if [ $? -eq 0 ]; then
REPLY="TAG"
return
fi
git show-ref --heads -q $_ARG
if [ $? -eq 0 ]; then
REPLY="BRANCH"
return
fi
git rev-parse --verify -q $_ARG > /dev/null
if [ $? -eq 0 ]; then
REPLY="SHA"
return
fi
else
REPLY="VER"
return
fi
REPLY=""
}