WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Added serialisation facilities. Udev is supposed to seri

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Added serialisation facilities. Udev is supposed to serialise events, but sadly
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Sat, 03 Dec 2005 12:04:09 +0000
Delivery-date: Sat, 03 Dec 2005 12:04:47 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID a57cccdf2d6d5c70bef4f570fe2f906fd18ba406
# Parent  d581e11e247c72ac48ae5be69fd5c08a823dd655
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@xxxxxxxxxxxxx>

diff -r d581e11e247c -r a57cccdf2d6d tools/examples/xen-hotplug-common.sh
--- a/tools/examples/xen-hotplug-common.sh      Fri Dec  2 15:36:39 2005
+++ b/tools/examples/xen-hotplug-common.sh      Fri Dec  2 15:38:22 2005
@@ -18,6 +18,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"
@@ -45,7 +47,7 @@
 }
 
 sigerr() {
-  fatal "$0" "$@" "failed; error detected."
+  fatal "$0 failed; error detected."
 }
 
 trap sigerr ERR
@@ -86,4 +88,88 @@
   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"

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Added serialisation facilities. Udev is supposed to serialise events, but sadly, Xen patchbot -unstable <=