ia64/xen-unstable

view tools/hotplug/Linux/vtpm-impl @ 19497:2f6ed9318c03

network-bridge: Fix do_ifup in the case of ${bridge} != ${netdev}

On RHEL5.2, ifup ${bridge} fails if ${bridge} != ${netdev},
because RHEL5.2's ifup ${bridge} runs the following sequence:

1. Search CONFIG that has the same mac address of ${bridge}.=20
ifcfg-${netdev} is found.
2. Run "ip link set dev ${netdev} up".
# ${bridge} is expected.
3. Output "Failed to bring up ${netdev}."
Because ${netdev} does not exist.

Thus, do_ifup() should not use ifup if ${bridge} != ${netdev}.

Signed-off-by: KUWAMURA Shin'ya <kuwa@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Apr 02 11:48:10 2009 +0100 (2009-04-02)
parents 4bfc67b09e9c
children
line source
1 #!/bin/bash
2 # ===================================================================
3 #
4 # Copyright (c) 2005, Intel Corp.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
17 # * Neither the name of Intel Corporation nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32 # OF THE POSSIBILITY OF SUCH DAMAGE.
33 # ===================================================================
35 # | SRC | TAG | CMD SIZE | ORD |mtype|strt
36 TPM_CMD_OPEN=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x11\\x01\\x00\\x00\\x01\\x01\\x01
37 TPM_CMD_RESM=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x11\\x01\\x00\\x00\\x01\\x01\\x02
38 TPM_CMD_CLOS=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x0e\\x01\\x00\\x00\\x02
39 TPM_CMD_DELE=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x0e\\x01\\x00\\x00\\x03
41 TPM_TYPE_PVM=\\x01
42 TPM_TYPE_HVM=\\x02
44 TPM_SUCCESS=00000000
46 TX_VTPM_MANAGER=/var/vtpm/fifos/from_console.fifo
47 RX_VTPM_MANAGER=/var/vtpm/fifos/to_console.fifo
49 VTPM_MIG=/usr/bin/vtpm_migrator
51 # -------------------- Helpers for binary streams -----------
53 function str_to_hex32() {
54 printf "%0.8x" $1
55 }
57 function hex32_to_bin() {
58 local inst=$(str_to_hex32 $1);
60 local n1=`echo $inst | sed 's/\(..\)....../\\\\x\1/'`
61 local n2=`echo $inst | sed 's/..\(..\)..../\\\\x\1/'`
62 local n3=`echo $inst | sed 's/....\(..\)../\\\\x\1/'`
63 local n4=`echo $inst | sed 's/......\(..\)/\\\\x\1/'`
65 echo "$n1$n2$n3$n4"
66 }
68 function vtpm_manager_cmd() {
69 local cmd=$1;
70 local inst=$2;
71 local inst_bin=$(hex32_to_bin $inst);
73 claim_lock vtpm_mgr
75 #send cmd to vtpm_manager
76 printf "$cmd$inst_bin" > $TX_VTPM_MANAGER
78 #recv response
79 set +e
80 local resp_hex=`dd skip=10 bs=1 count=4 if=$RX_VTPM_MANAGER 2> /dev/null | xxd -ps`
81 set -e
83 release_lock vtpm_mgr
85 #return whether the command was successful
86 if [ $resp_hex -ne $TPM_SUCCESS ]; then
87 vtpm_fatal_error=1
88 false
89 else
90 true
91 fi
92 }
94 # Helper to get vm type to pass to vtpm_manager open/resume
95 function vtpm_get_type() {
96 local inst=$(xenstore_read $XENBUS_PATH/frontend-id)
97 local vm=$(xenstore_read /local/domain/$inst/vm)
98 if [ "$vm" != "" ]; then
99 local ostype=$(xenstore-read $vm/image/ostype)
100 if [ "$ostype" == "hvm" ]; then
101 echo $TPM_TYPE_HVM;
102 else
103 echo $TPM_TYPE_PVM;
104 fi
105 fi
106 }
108 # ------------------ Command handlers -----------------
110 # Create new vtpm instance & set it up for use
111 function vtpm_create () {
112 # Creation is handled implicitly by the manager on first setup
113 # so just set it up for use
114 $(vtpm_start $1)
115 }
117 # Setup vtpm instance for use.
118 function vtpm_start() {
119 local vmtype=$(vtpm_get_type);
120 $(vtpm_manager_cmd $TPM_CMD_OPEN$vmtype $1)
121 }
123 function vtpm_resume() {
124 local vmtype=$(vtpm_get_type);
125 $(vtpm_manager_cmd $TPM_CMD_RESM$vmtype $1)
126 }
128 # Reset the vtpm AKA clear PCRs
129 function vtpm_reset() {
130 #not used by current implemenation
131 true
132 }
134 # Shutdown the vtpm while the vm is down
135 # This could be a suspend of shutdown
136 # we cannot distinquish, so save the state
137 # and decide on startup if we should keep is
138 function vtpm_suspend() {
139 $(vtpm_manager_cmd $TPM_CMD_CLOS $1)
140 }
143 function vtpm_delete() {
144 local inst=$1
145 if $(vtpm_manager_cmd $TPM_CMD_DELE $inst); then
146 rm -f /var/vtpm/vtpm_dm_$1.data
147 true
148 else
149 vtpm_fatal_error=1
150 false
151 fi
152 }
154 # Perform a migration step. This function differentiates between migration
155 # to the local host or to a remote machine.
156 # Parameters:
157 # 1st: destination host to migrate to
158 # 2nd: name of the domain to migrate
159 # 3rd: the migration step to perform
160 function vtpm_migrate() {
161 local instance res
163 instance=$(vtpmdb_find_instance $2)
164 if [ "$instance" == "" ]; then
165 log err "VTPM Migratoin failed. Unable to translation of domain name"
166 echo "Error: VTPM Migration failed while looking up instance number"
167 fi
169 case "$3" in
170 0)
171 #Incicate migration supported
172 echo "0"
173 ;;
175 1)
176 # Get Public Key from Destination
177 # Call vtpm_manager's migration part 1
178 claim_lock vtpm_mgr
179 $VTPM_MIG $1 $2 $instance $3
180 release_lock vtpm_mgr
181 ;;
183 2)
184 # Call manager's migration step 2 and send result to destination
185 # If successful remove from db
186 claim_lock vtpm_mgr
187 $VTPM_MIG $1 $2 $instance $3
188 release_lock vtpm_mgr
189 ;;
191 3)
192 if `ps x | grep "$VTPM_MIG $1"`; then
193 log err "VTPM Migration failed to complete."
194 echo "Error: VTPM Migration failed to complete."
195 fi
196 ;;
197 esac
199 }
202 function vtpm_migrate_recover() {
203 echo "Error: Recovery not supported yet"
204 }
206 function vtpm_migrate_local() {
207 echo "Error: local vTPM migration not supported"
208 }