ia64/xen-unstable

view stubdom/stubdom-dm @ 19734:4fb8a6c993e2

VT-d: correct way to submit command to GCMD register

Per VT-d spec, software should submit only one "incremental" command
at a time to Global Command reigster. Current implementation uses a
variable (gcmd) to record the state of Global Status register. It's
error prone.

Signed-off-by: Weidong Han <weidong.han@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 05 09:29:42 2009 +0100 (2009-06-05)
parents 0f752c773497
children eeb0fce9aeaf
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 esac
56 fi
57 case "$1" in
58 -vncviewer) vncviewer=1 ;;
59 -sdl) sdl=1 ;;
60 -disable-opengl) opengl=0 ;;
61 esac
62 shift
63 done
65 [ -z "$domid" ] && ( echo "couldn't find domain ID" ; exit 1 )
66 [ -z "$domname" ] && ( echo "couldn't find domain name" ; exit 1 )
68 # Termination handler
70 term() {
71 kill %1
72 (
73 [ -n "$vncpid" ] && kill -9 $vncpid
74 xm destroy $domname-dm
75 rm /etc/xen/stubdoms/$domname-dm
76 ) &
77 # We need to exit immediately so as to let xend do the commands above
78 exit 0
79 }
81 trap term SIGHUP
83 ############
84 # stubdomain
85 # Wait for any previous stubdom to terminate
86 while xm list | grep $domname-dm
87 do
88 sleep 1
89 done
91 # Generate stubdom config file
92 mkdir -p /etc/xen/stubdoms &>/dev/null
93 echo "#This file is autogenerated, edit $domname instead!" > /etc/xen/stubdoms/$domname-dm
94 echo "kernel = '/usr/lib/xen/boot/ioemu-stubdom.gz'" >> /etc/xen/stubdoms/$domname-dm
96 vfb="sdl=$sdl, opengl=$opengl"
97 test "$DISPLAY" && vfb="$vfb, display=$DISPLAY"
98 test "$XAUTHORITY" && vfb="$vfb, xauthority=$XAUTHORITY"
99 test $vnc != 0 && vfb="$vfb, vnc=$vnc, vncdisplay=$vnc_port, vnclisten=$ip, vncunused=$vncunused"
100 vncpasswd=`xenstore-read /local/domain/0/backend/vfb/$domid/0/vncpasswd 2>/dev/null`
101 test "$vncpasswd" && vfb="$vfb, vncpasswd=$vncpasswd"
102 test "$keymap" && vfb="$vfb, keymap=$keymap"
103 echo "vfb = ['$vfb']" >> /etc/xen/stubdoms/$domname-dm
105 echo -n "disk = [ " >> /etc/xen/stubdoms/$domname-dm
106 j=0
107 for i in `xenstore-ls /local/domain/$domid/device/vbd | grep 'backend =' | awk '{print $3}'`
108 do
109 i=${i%\"}
110 i=${i#\"}
111 vbd_mode=`xenstore-read $i/mode`
112 vbd_disk=`xenstore-read $i/params`
113 vbd_type=`xenstore-read $i/type`
114 vbd_dev=`xenstore-read $i/dev`
115 vbd_front=`xenstore-read $i/frontend`
116 vbd_devtype=`xenstore-read $vbd_front/device-type`
117 if [ $j -ne 0 ]
118 then
119 echo -n "," >> /etc/xen/stubdoms/$domname-dm
120 fi
121 echo -n "'$vbd_type:$vbd_disk,$vbd_dev:$vbd_devtype,$vbd_mode'" >> /etc/xen/stubdoms/$domname-dm
122 j=$(( $j + 1 ))
123 done
124 echo " ] " >> /etc/xen/stubdoms/$domname-dm
125 echo -n "vif = [ " >> /etc/xen/stubdoms/$domname-dm
126 j=0
127 for i in `xenstore-ls /local/domain/$domid/device/vif | grep 'backend =' | awk '{print $3}'`
128 do
129 i=${i%\"}
130 i=${i#\"}
131 vif_mac=`xenstore-read $i/mac`
132 if [ $j -ne 0 ]
133 then
134 echo -n "," >> /etc/xen/stubdoms/$domname-dm
135 fi
136 echo -n "'mac=$vif_mac'" >> /etc/xen/stubdoms/$domname-dm
137 j=$(( $j + 1 ))
138 done
139 echo " ] " >> /etc/xen/stubdoms/$domname-dm
140 creation="xm create -c /etc/xen/stubdoms/$domname-dm target=$domid memory=32 extra=\"$extra\""
142 (while true ; do sleep 60 ; done) | /bin/sh -c "$creation" &
143 #xterm -geometry +0+0 -e /bin/sh -c "$creation ; echo ; echo press ENTER to shut down ; read" &
144 consolepid=$!
147 ###########
148 # vncviewer
149 if [ "$vncviewer" = 1 ]
150 then
151 # Wait for vnc server to appear
152 while ! vnc_port=`xenstore-read /local/domain/$domid/console/vnc-port`
153 do
154 # Check that the stubdom job is still alive
155 kill -0 $consolepid || term
156 sleep 1
157 done
159 vncviewer $ip:$vnc_port &
160 vncpid=$!
161 fi
163 # wait for SIGHUP or stubdom termination
164 wait $consolepid
166 term