ia64/xen-unstable

view tools/hotplug/Linux/locking.sh @ 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 #
2 # Copyright (c) 2005 XenSource Ltd.
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of version 2.1 of the GNU Lesser General Public
6 # License as published by the Free Software Foundation.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #
18 #
19 # Serialisation
20 #
22 LOCK_SLEEPTIME=1
23 LOCK_SPINNING_RETRIES=5
24 LOCK_RETRIES=100
25 LOCK_BASEDIR=/var/run/xen-hotplug
28 claim_lock()
29 {
30 local lockdir="$LOCK_BASEDIR/$1"
31 mkdir -p "$LOCK_BASEDIR"
32 _claim_lock "$lockdir"
33 }
36 release_lock()
37 {
38 _release_lock "$LOCK_BASEDIR/$1"
39 }
42 _claim_lock()
43 {
44 local lockdir="$1"
45 local owner=$(_lock_owner "$lockdir")
46 local retries=0
48 while [ $retries -lt $LOCK_RETRIES ]
49 do
50 mkdir "$lockdir" 2>/dev/null && trap "release_lock $1; sigerr" ERR &&
51 _update_lock_info "$lockdir" && return
53 local new_owner=$(_lock_owner "$lockdir")
54 if [ "$new_owner" != "$owner" ]
55 then
56 owner="$new_owner"
57 retries=0
58 fi
60 if [ $retries -gt $LOCK_SPINNING_RETRIES ]
61 then
62 sleep $LOCK_SLEEPTIME
63 else
64 sleep 0
65 fi
66 retries=$(($retries + 1))
67 done
68 _steal_lock "$lockdir"
69 }
72 _release_lock()
73 {
74 trap sigerr ERR
75 rm -rf "$1" 2>/dev/null || true
76 }
79 _steal_lock()
80 {
81 local lockdir="$1"
82 local owner=$(cat "$lockdir/owner" 2>/dev/null || echo "unknown")
83 log err "Forced to steal lock on $lockdir from $owner!"
84 _release_lock "$lockdir"
85 _claim_lock "$lockdir"
86 }
89 _lock_owner()
90 {
91 cat "$1/owner" 2>/dev/null || echo "unknown"
92 }
95 _update_lock_info()
96 {
97 echo "$$: $0" >"$1/owner"
98 }