ia64/xen-unstable

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