-
Notifications
You must be signed in to change notification settings - Fork 3
/
khgetmdisk
executable file
·259 lines (222 loc) · 5.31 KB
/
khgetmdisk
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/bin/bash
# just a kludge needs to be re-written
# added support to multi disk requests
set -x
# FIXME:
# there is big sequential loops here probably
# does not matter right now as aoe id's
# only range from {0..9} * {0..15}
export PATH=$PATH:/root/scripts
export BIGPHYS=32
declare -r DISKINFODIR=${KHDISK_INFODIR:-/root/disks}
declare -r MEMCINFODIR=${KHMEMC_INFODIR:-/root/memc}
declare -r AOEIDFILE=$DISKINFODIR/aoenextid
declare -i BUFFERCONFIG=1
if [[ ! -d $DISKINFODIR ]]
then
if [[ -a $DISKINFODIR ]]
then
if ! rm -rf $DISKINFODIR
then
echo "ERROR: $DISKINFODIR exists and is not a directory and cannot be removed" >&2
exit -1
fi
fi
mkdir -p $DISKINFODIR
fi
function resetAOEID {
local id="$1"
if [[ -z "$id" ]]
then
id="0 0"
fi
echo "$id" > $AOEIDFILE
return 0
}
function getAOEID
{
#add locking to this
local shelf
local slot
local nextshelf
local nextslot
local aoeid
if [[ ! -a $AOEIDFILE ]]
then
resetAOEID
fi
aoeid=$(cat $AOEIDFILE)
shelf=${aoeid%% *}
slot=${aoeid##* }
if (( $slot > 15 ))
then
echo "ERROR: exceed max aoe slots $slot" >&2
exit -1
fi
if (( $shelf > 9 ))
then
echo "ERROR: exceed max aoe shelves $shelf" >&2
exit -1
fi
nextslot=$(( $slot + 1 ))
if (( $nextslot > 15 ))
then
nextshelf=$(( $shelf + 1 ))
nextslot=0
else
nextshelf=$shelf
fi
echo "$nextshelf $nextslot" > $AOEIDFILE
echo "$shelf $slot"
return 0
}
function usage
{
echo "$0 [-C] [-c <comma seperated list of IPs>] [-a <comma seperated list of macs>] [-n number]"
echo " -C don't fetch memcached servers from info dir"
echo " -c memcached servers"
echo " -a AOE mac ACL"
echo " -n numer of instances"
echo " -v verbose"
}
origargs="$@"
optcount=0
export FETCHMEMCINFO=1
export VERBOSE=0
while getopts "Cc:a:n:vh" OPT
do
case $OPT in
("C") export FETCHMEMCINFO=0; (( optcount=optcount + 1));;
("c") export memcipaddr="$OPTARG"; (( optcount=optcount + 2));;
("a") export aoeethaddr="$OPTARG"; (( optcount=optcount + 2));;
("n") export num="$OPTARG"; (( optcount=optcount + 2));;
("v") export VERBOSE=1; (( optcount=optcount + 1));;
("h") usage; exit -1;;
esac
done
if [[ -z $num ]]
then
num=1
fi
if [[ $FETCHMEMCINFO = 1 ]]
then
infofiles=$(find $MEMCINFODIR -type f)
for f in $infofiles
do
memcip=$(cat $f | grep nodeinfo)
memcip=${memcip##* }
export memcipaddr=${memcipaddr},$memcip
done
fi
export memcipaddr=${memcipaddr#,}
if [[ -z $aoeeth && -a /proc/device-tree/u-boot-env/aoe_iface ]]
then
aoeeth=$(cat /proc/device-tree/u-boot-env/aoe_iface)
fi
if [[ -z $aoenetid && -a /proc/device-tree/u-boot-env/bg_${aoeeth}_netid ]]
then
aoenetid=$(cat /proc/device-tree/u-boot-env/bg_${aoeeth}_netid)
fi
if [[ -z $ramdisk && -a /root/vblade.cpio.gz.uimg ]]
then
ramdisk=/root/vblade.cpio.gz.uimg
fi
if [[ -z $kernel && -a /root/vblade-uImage ]]
then
kernel=/root/vblade-uImage
fi
if [[ -z $khuser && -a /proc/device-tree/u-boot-env/khctluser ]]
then
khuser=$(cat /proc/device-tree/u-boot-env/khctluser)
fi
if [[ -z $ramdisk || -z $khuser || -z $aoenetid || -z $aoeeth ]]
then
echo "ERROR: Could not determine values" >&2
exit -1
fi
if ! ifconfig $aoeeth up
then
echo "ERROR: failed to config ethernet inteface $aoeeth" >&2
exit -1
else
myethaddr=$(ifconfig $aoeeth | grep HWaddr)
myethaddr=${myethaddr##*HWaddr }
fi
if [[ -z $aoeethaddr ]]
then
aoeethaddr=$myethaddr
fi
# FIXME: HERE IS THE LOOP SEE TOP COMMENT
# all the ids first to ensure that
# we have enough ids
declare -i i=0
declare -a aoeids
while (( $i < $num ))
do
aoeids[$i]=$(getAOEID)
if (( $? != 0 ))
then
if (( $i > 0 ))
then
resetNextAOEid "${aoeids[0]}"
fi
echo "ERROR: need $num aoe disk ids but only got $(( $i + 1 ))" >&2
exit -1
fi
(( i++ ))
done
disks=$(khget -i -n $aoenetid $khuser $num)
echo $disks
if (( $? != 0 ))
then
echo "ERROR: failed to acquire $num nodes for disk" >&2
exit -1
fi
if [[ -n $kernel ]]
then
echo "$disks" | khdo loadkernel $kernel
fi
echo "$disks" | khdo loadramdisk $ramdisk
nodes=$(echo "$disks" | khdo pernodecmd "echo %node%")
i=0
for n in $nodes
do
aoeid="${aoeids[$i]}"
shelf=${aoeid%% *}
slot=${aoeid##* }
configline="itest \$bgp_rank == $n && setenv app_aoe_shelf $shelf && setenv app_aoe_slot $slot && setenv app_aoe_eth eth1"
if (( $BUFFERCONFIG == 1 ))
then
if [[ -z $config ]]
then
config="$configline"
else
config="$config
$configline"
fi
else
echo "$disks" | khdo write "$configline"
fi
echo "$disks" > $DISKINFODIR/e${shelf}.${slot}.info
(( i++ ))
done
if (( $BUFFERCONFIG == 1 ))
then
echo "$disks" | khdo write "$config"
fi
if [[ -n $aoeethaddr ]]
then
echo "$disks" | khdo write "setenv app_aoe_macs $aoeethaddr"
fi
if [[ -n $memcipaddr ]]
then
echo "$disks" | khdo write "setenv app_aoe_memcips $memcipaddr"
fi
if [[ $VERBOSE = 1 ]]
then
echo "$disks" | khdo write "setenv app_aoe_verbose 1"
fi
let BIGPHYS*=256
echo "$disks" | khdo write "setenv bootargs bigphysarea=$BIGPHYS console=bgtty0,\$bgtty_sendid,\$bgtty_rcvid,\$bgtty_dest init=/init ip=\$eth0ip:\$serverip:\$sitegate:\$sitemask::eth0:off"
echo "$disks" | khdo write 'setenv ramfsarg $ramfsaddr'
echo "$disks" | khdo write "run boot"