debuggers.hg

view stubdom/stubdom-dm @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents 6852e3e7ef58
children
line source
1 #!/bin/bash
2 #
3 # Copyright 2007-2008 Samuel Thibault <samuel.thibault@eu.citrix.net>
4 #
5 # dm script around stubdomains.
6 #
8 DIR=`dirname $0`
9 . "${DIR}/stubdompath.sh"
10 stubdom_configdir="${XEN_CONFIG_DIR}/stubdoms"
12 # To fit xterms nicely
13 height=339
15 # Parse arguments
17 domid=
18 domname=
19 vncviewer=0
20 vncpid=
21 extra=
22 sdl=0
23 opengl=1
24 vnc=0
25 vncunused=0
26 while [ "$#" -gt 0 ];
27 do
28 if [ "$#" -ge 2 ];
29 then
30 case "$1" in
31 -d)
32 domid=$2;
33 extra="$extra -d $domid";
34 shift
35 ;;
36 -domain-name)
37 domname=$2;
38 shift
39 ;;
40 -vnc)
41 vnc=1
42 op=${2%,*}
43 ip=${op%:*};
44 vnc_port=${op#*:};
45 shift
46 ;;
47 -vncunused)
48 vncunused=1
49 shift
50 ;;
51 -loadvm)
52 extra="$extra -loadvm $2";
53 shift
54 ;;
55 -k)
56 keymap=$2
57 shift
58 ;;
59 -serial)
60 serial="$2"
61 shift
62 ;;
63 -monitor)
64 monitor="$2"
65 shift
66 ;;
67 esac
68 fi
69 case "$1" in
70 -vncviewer) vncviewer=1 ;;
71 -sdl) sdl=1 ;;
72 -disable-opengl) opengl=0 ;;
73 esac
74 shift
75 done
77 [ -z "$domid" ] && { echo "couldn't find domain ID" ; exit 1; }
78 [ -z "$domname" ] && { echo "couldn't find domain name" ; exit 1; }
80 # Termination handler
82 term() {
83 [ -n "$vncpid" ] && kill -9 $vncpid
84 rm -f /tmp/domname-dm
85 rm ${stubdom_configdir}/$domname-dm
86 exit 0
87 }
89 trap term SIGHUP
91 ############
92 # stubdomain
93 # Wait for any previous stubdom to terminate
94 while xm list | grep -w $domname-dm
95 do
96 sleep 1
97 done
99 # Generate stubdom config file
100 mkdir -p ${stubdom_configdir} &>/dev/null
101 echo "#This file is autogenerated, edit $domname instead!" > ${stubdom_configdir}/$domname-dm
102 echo "kernel = '${XENFIRMWAREDIR}/ioemu-stubdom.gz'" >> ${stubdom_configdir}/$domname-dm
104 vfb="sdl=$sdl, opengl=$opengl"
105 test "$DISPLAY" && vfb="$vfb, display=$DISPLAY"
106 test "$XAUTHORITY" && vfb="$vfb, xauthority=$XAUTHORITY"
107 test $vnc != 0 && vfb="$vfb, vnc=$vnc, vncdisplay=$vnc_port, vnclisten=$ip, vncunused=$vncunused"
108 vncpasswd=`xenstore-read /local/domain/0/backend/vfb/$domid/0/vncpasswd 2>/dev/null`
109 test "$vncpasswd" && vfb="$vfb, vncpasswd=$vncpasswd"
110 test "$keymap" && vfb="$vfb, keymap=$keymap"
111 test "$monitor" && vfb="$vfb, monitor=$monitor"
112 test "$serial" && vfb="$vfb, serial=$serial"
113 echo "vfb = ['$vfb']" >> ${stubdom_configdir}/$domname-dm
115 echo -n "disk = [ " >> ${stubdom_configdir}/$domname-dm
116 j=0
117 for i in `xenstore-ls /local/domain/$domid/device/vbd | grep 'backend =' | awk '{print $3}'`
118 do
119 i=${i%\"}
120 i=${i#\"}
121 vbd_mode=`xenstore-read $i/mode`
122 vbd_disk=`xenstore-read $i/params`
123 vbd_type=`xenstore-read $i/type`
124 vbd_dev=`xenstore-read $i/dev`
125 vbd_front=`xenstore-read $i/frontend`
126 vbd_devtype=`xenstore-read $vbd_front/device-type`
127 if [ $j -ne 0 ]
128 then
129 echo -n "," >> ${stubdom_configdir}/$domname-dm
130 fi
131 echo -n "'$vbd_type:$vbd_disk,$vbd_dev:$vbd_devtype,$vbd_mode'" >> ${stubdom_configdir}/$domname-dm
132 j=$(( $j + 1 ))
133 done
134 echo " ] " >> ${stubdom_configdir}/$domname-dm
135 echo -n "vif = [ " >> ${stubdom_configdir}/$domname-dm
136 j=0
137 for i in `xenstore-ls /local/domain/$domid/device/vif | grep 'backend =' | awk '{print $3}'`
138 do
139 i=${i%\"}
140 i=${i#\"}
141 vif_mac=`xenstore-read $i/mac`
142 vif_bridge=`xenstore-read $i/bridge`
143 if [ $j -ne 0 ]
144 then
145 echo -n "," >> ${stubdom_configdir}/$domname-dm
146 fi
147 echo -n "'mac=$vif_mac" >> ${stubdom_configdir}/$domname-dm
148 if [ "$vif_bridge" ]
149 then
150 echo -n ",bridge=$vif_bridge'" >> ${stubdom_configdir}/$domname-dm
151 else
152 echo -n "'" >> ${stubdom_configdir}/$domname-dm
153 fi
154 j=$(( $j + 1 ))
155 done
156 echo " ] " >> ${stubdom_configdir}/$domname-dm
158 mkfifo /tmp/$domname-dm
159 xm create -c ${stubdom_configdir}/$domname-dm target=$domid memory=32 extra="$extra" < /tmp/$domname-dm &
160 exec 4>/tmp/$domname-dm
163 ###########
164 # vncviewer
165 if [ "$vncviewer" = 1 ]
166 then
167 # Wait for vnc server to appear
168 while ! vnc_port=`xenstore-read /local/domain/$domid/console/vnc-port`
169 do
170 # Check that the stubdom job is still alive
171 kill -0 $consolepid || term
172 sleep 1
173 done
175 vncviewer $ip:$vnc_port &
176 vncpid=$!
177 fi
179 # wait for SIGHUP or stubdom termination
180 wait
182 term