forked from mirage/xen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstubdom-dm
182 lines (164 loc) · 4.3 KB
/
stubdom-dm
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
#!/bin/bash
#
# Copyright 2007-2008 Samuel Thibault <samuel.thibault@eu.citrix.net>
#
# dm script around stubdomains.
#
DIR=`dirname $0`
. "${DIR}/stubdompath.sh"
stubdom_configdir="${XEN_CONFIG_DIR}/stubdoms"
# To fit xterms nicely
height=339
# Parse arguments
domid=
domname=
vncviewer=0
vncpid=
extra=
sdl=0
opengl=1
vnc=0
vncunused=0
while [ "$#" -gt 0 ];
do
if [ "$#" -ge 2 ];
then
case "$1" in
-d)
domid=$2;
extra="$extra -d $domid";
shift
;;
-domain-name)
domname=$2;
shift
;;
-vnc)
vnc=1
op=${2%,*}
ip=${op%:*};
vnc_port=${op#*:};
shift
;;
-vncunused)
vncunused=1
shift
;;
-loadvm)
extra="$extra -loadvm $2";
shift
;;
-k)
keymap=$2
shift
;;
-serial)
serial="$2"
shift
;;
-monitor)
monitor="$2"
shift
;;
esac
fi
case "$1" in
-vncviewer) vncviewer=1 ;;
-sdl) sdl=1 ;;
-disable-opengl) opengl=0 ;;
esac
shift
done
[ -z "$domid" ] && { echo "couldn't find domain ID" ; exit 1; }
[ -z "$domname" ] && { echo "couldn't find domain name" ; exit 1; }
# Termination handler
term() {
[ -n "$vncpid" ] && kill -9 $vncpid
rm -f /tmp/domname-dm
rm ${stubdom_configdir}/$domname-dm
exit 0
}
trap term SIGHUP
############
# stubdomain
# Wait for any previous stubdom to terminate
while xm list | grep -w $domname-dm
do
sleep 1
done
# Generate stubdom config file
mkdir -p ${stubdom_configdir} &>/dev/null
echo "#This file is autogenerated, edit $domname instead!" > ${stubdom_configdir}/$domname-dm
echo "kernel = '${XENFIRMWAREDIR}/ioemu-stubdom.gz'" >> ${stubdom_configdir}/$domname-dm
vfb="sdl=$sdl, opengl=$opengl"
test "$DISPLAY" && vfb="$vfb, display=$DISPLAY"
test "$XAUTHORITY" && vfb="$vfb, xauthority=$XAUTHORITY"
test $vnc != 0 && vfb="$vfb, vnc=$vnc, vncdisplay=$vnc_port, vnclisten=$ip, vncunused=$vncunused"
vncpasswd=`xenstore-read /local/domain/0/backend/vfb/$domid/0/vncpasswd 2>/dev/null`
test "$vncpasswd" && vfb="$vfb, vncpasswd=$vncpasswd"
test "$keymap" && vfb="$vfb, keymap=$keymap"
test "$monitor" && vfb="$vfb, monitor=$monitor"
test "$serial" && vfb="$vfb, serial=$serial"
echo "vfb = ['$vfb']" >> ${stubdom_configdir}/$domname-dm
echo -n "disk = [ " >> ${stubdom_configdir}/$domname-dm
j=0
for i in `xenstore-ls /local/domain/$domid/device/vbd | grep 'backend =' | awk '{print $3}'`
do
i=${i%\"}
i=${i#\"}
vbd_mode=`xenstore-read $i/mode`
vbd_disk=`xenstore-read $i/params`
vbd_type=`xenstore-read $i/type`
vbd_dev=`xenstore-read $i/dev`
vbd_front=`xenstore-read $i/frontend`
vbd_devtype=`xenstore-read $vbd_front/device-type`
if [ $j -ne 0 ]
then
echo -n "," >> ${stubdom_configdir}/$domname-dm
fi
echo -n "'$vbd_type:$vbd_disk,$vbd_dev:$vbd_devtype,$vbd_mode'" >> ${stubdom_configdir}/$domname-dm
j=$(( $j + 1 ))
done
echo " ] " >> ${stubdom_configdir}/$domname-dm
echo -n "vif = [ " >> ${stubdom_configdir}/$domname-dm
j=0
for i in `xenstore-ls /local/domain/$domid/device/vif | grep 'backend =' | awk '{print $3}'`
do
i=${i%\"}
i=${i#\"}
vif_mac=`xenstore-read $i/mac`
vif_bridge=`xenstore-read $i/bridge`
if [ $j -ne 0 ]
then
echo -n "," >> ${stubdom_configdir}/$domname-dm
fi
echo -n "'mac=$vif_mac" >> ${stubdom_configdir}/$domname-dm
if [ "$vif_bridge" ]
then
echo -n ",bridge=$vif_bridge'" >> ${stubdom_configdir}/$domname-dm
else
echo -n "'" >> ${stubdom_configdir}/$domname-dm
fi
j=$(( $j + 1 ))
done
echo " ] " >> ${stubdom_configdir}/$domname-dm
mkfifo /tmp/$domname-dm
xm create -c ${stubdom_configdir}/$domname-dm target=$domid memory=32 extra="$extra" < /tmp/$domname-dm &
exec 4>/tmp/$domname-dm
###########
# vncviewer
if [ "$vncviewer" = 1 ]
then
# Wait for vnc server to appear
while ! vnc_port=`xenstore-read /local/domain/$domid/console/vnc-port`
do
# Check that the stubdom job is still alive
kill -0 $consolepid || term
sleep 1
done
vncviewer $ip:$vnc_port &
vncpid=$!
fi
# wait for SIGHUP or stubdom termination
wait
term