Added serialisation facilities. Udev is supposed to serialise events, but sadly

the older hotplug infrastructure does not, so we must be able to serialise the
block-sharing checks (etc) ourselves.

Redirect stderr to /var/log/xen-hotplug.log, for better debugging.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
emellor@leeni.uk.xensource.com committed 2005-12-02 15:38:22 +00:00
1 parent 13b9e071a3
commit d3be5880f8
1 file changed
+87 -1
+87 -1
View File
@@ -19,6 +19,8 @@
dir=$(dirname "$0")
. "$dir/xen-script-common.sh"
exec 2>>/var/log/xen-hotplug.log
export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
export LANG="POSIX"
unset $(set | grep ^LC_ | cut -d= -f1)
@@ -45,7 +47,7 @@ do_or_die() {
}
sigerr() {
fatal "$0" "$@" "failed; error detected."
fatal "$0 failed; error detected."
}
trap sigerr ERR
@@ -86,4 +88,88 @@ xenstore_write() {
xenstore-write "$@" || fatal "Writing $@ to xenstore failed."
}
#
# Serialisation
#
LOCK_SLEEPTIME=1
LOCK_SPINNING_RETRIES=5
LOCK_RETRIES=10
LOCK_BASEDIR=/var/run/xen-hotplug
claim_lock()
{
local lockdir="$LOCK_BASEDIR/$1"
mkdir -p "$LOCK_BASEDIR"
_claim_lock "$lockdir"
}
release_lock()
{
_release_lock "$LOCK_BASEDIR/$1"
}
_claim_lock()
{
local lockdir="$1"
local owner=$(_lock_owner "$lockdir")
local retries=0
while expr $retries '<' $LOCK_RETRIES
do
mkdir "$lockdir" && trap "release_lock $1; sigerr" ERR &&
_update_lock_info "$lockdir" && return
local new_owner=$(_lock_owner "$lockdir")
if [ "$new_owner" != "$owner" ]
then
owner="$new_owner"
retries=0
fi
if expr $retries '>' $LOCK_SPINNING_RETRIES
then
sleep $LOCK_SLEEPTIME
else
sleep 0
fi
retries=$(($retries + 1))
done
_steal_lock "$lockdir"
}
_release_lock()
{
trap sigerr ERR
rm -rf "$1" || true
}
_steal_lock()
{
local lockdir="$1"
local owner=$(cat "$lockdir/owner" 2>/dev/null || echo "unknown")
log err "Forced to steal lock on $lockdir from $owner!"
_release_lock "$lockdir"
_claim_lock "$lockdir"
}
_lock_owner()
{
cat "$1/owner" 2>/dev/null || echo "unknown"
}
_update_lock_info()
{
echo "$$: $0" >"$1/owner"
}
log debug "$@" "XENBUS_PATH=$XENBUS_PATH"
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.