ia64/xen-unstable

view stubdom/stubdom-dm @ 19791:c0d2838fc10f

stubdoms: qemu monitor support

Add support for the qemu monitor in a stubdom, the same way the
emulated serial support was added few days ago. The stubdom exports
the monitor as a pty and minios opens a console frontend; qemu in dom0
provides the correspondent backend for this additional pv console that
happens to be the qemu monitor.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 18 10:20:17 2009 +0100 (2009-06-18)
parents eeb0fce9aeaf
children 415505139333
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 # To fit xterms nicely
9 height=339
11 # Parse arguments
13 domid=
14 domname=
15 vncviewer=0
16 vncpid=
17 extra=
18 sdl=0
19 opengl=1
20 vnc=0
21 vncunused=0
22 while [ "$#" -gt 0 ];
23 do
24 if [ "$#" -ge 2 ];
25 then
26 case "$1" in
27 -d)
28 domid=$2;
29 extra="$extra -d $domid";
30 shift
31 ;;
32 -domain-name)
33 domname=$2;
34 shift
35 ;;
36 -vnc)
37 vnc=1
38 op=${2%,*}
39 ip=${op%:*};
40 vnc_port=${op#*:};
41 shift
42 ;;
43 -vncunused)
44 vncunused=1
45 shift
46 ;;
47 -loadvm)
48 extra="$extra -loadvm $2";
49 shift
50 ;;
51 -k)
52 keymap=$2
53 shift
54 ;;
55 -serial)
56 serial="$2"
57 shift
58 ;;
59 -monitor)
60 monitor="$2"
61 shift
62 ;;
63 esac
64 fi
65 case "$1" in
66 -vncviewer) vncviewer=1 ;;
67 -sdl) sdl=1 ;;
68 -disable-opengl) opengl=0 ;;
69 esac
70 shift
71 done
73 [ -z "$domid" ] && ( echo "couldn't find domain ID" ; exit 1 )
74 [ -z "$domname" ] && ( echo "couldn't find domain name" ; exit 1 )
76 # Termination handler
78 term() {
79 kill %1
80 (
81 [ -n "$vncpid" ] && kill -9 $vncpid
82 xm destroy $domname-dm
83 rm /etc/xen/stubdoms/$domname-dm
84 ) &
85 # We need to exit immediately so as to let xend do the commands above
86 exit 0
87 }
89 trap term SIGHUP
91 ############
92 # stubdomain
93 # Wait for any previous stubdom to terminate
94 while xm list | grep $domname-dm
95 do
96 sleep 1
97 done
99 # Generate stubdom config file
100 mkdir -p /etc/xen/stubdoms &>/dev/null
101 echo "#This file is autogenerated, edit $domname instead!" > /etc/xen/stubdoms/$domname-dm
102 echo "kernel = '/usr/lib/xen/boot/ioemu-stubdom.gz'" >> /etc/xen/stubdoms/$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']" >> /etc/xen/stubdoms/$domname-dm
115 echo -n "disk = [ " >> /etc/xen/stubdoms/$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 "," >> /etc/xen/stubdoms/$domname-dm
130 fi
131 echo -n "'$vbd_type:$vbd_disk,$vbd_dev:$vbd_devtype,$vbd_mode'" >> /etc/xen/stubdoms/$domname-dm
132 j=$(( $j + 1 ))
133 done
134 echo " ] " >> /etc/xen/stubdoms/$domname-dm
135 echo -n "vif = [ " >> /etc/xen/stubdoms/$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 if [ $j -ne 0 ]
143 then
144 echo -n "," >> /etc/xen/stubdoms/$domname-dm
145 fi
146 echo -n "'mac=$vif_mac'" >> /etc/xen/stubdoms/$domname-dm
147 j=$(( $j + 1 ))
148 done
149 echo " ] " >> /etc/xen/stubdoms/$domname-dm
150 creation="xm create -c /etc/xen/stubdoms/$domname-dm target=$domid memory=32 extra=\"$extra\""
152 (while true ; do sleep 60 ; done) | /bin/sh -c "$creation" &
153 #xterm -geometry +0+0 -e /bin/sh -c "$creation ; echo ; echo press ENTER to shut down ; read" &
154 consolepid=$!
157 ###########
158 # vncviewer
159 if [ "$vncviewer" = 1 ]
160 then
161 # Wait for vnc server to appear
162 while ! vnc_port=`xenstore-read /local/domain/$domid/console/vnc-port`
163 do
164 # Check that the stubdom job is still alive
165 kill -0 $consolepid || term
166 sleep 1
167 done
169 vncviewer $ip:$vnc_port &
170 vncpid=$!
171 fi
173 # wait for SIGHUP or stubdom termination
174 wait $consolepid
176 term