ia64/xen-unstable

changeset 9044:911f3ecd975e

The attached patch breaks out

- log() function from xen-hotplug-common.sh -> logging.sh
- locking-related functions from xen-hotplug-common.sh -> locking.sh

- xen-hotplug-common.sh 'sources' both those files now to not loose
these functions (which should make the break-out atomic)

- adapts the Makefile to install locking.sh and logging.sh at the right
place.

I ran the xm-tests over it and no (additional) errors appear due to this
change.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author emellor@leeni.uk.xensource.com
date Mon Feb 27 16:11:01 2006 +0100 (2006-02-27)
parents ee8041b0ab86
children 136aea67b369
files tools/examples/Makefile tools/examples/xen-hotplug-common.sh xen-unstable.hg/tools/examples/locking.sh xen-unstable.hg/tools/examples/logging.sh
line diff
     1.1 --- a/tools/examples/Makefile	Mon Feb 27 15:52:43 2006 +0100
     1.2 +++ b/tools/examples/Makefile	Mon Feb 27 16:11:01 2006 +0100
     1.3 @@ -27,7 +27,7 @@ XEN_SCRIPTS += network-nat vif-nat
     1.4  XEN_SCRIPTS += block
     1.5  XEN_SCRIPTS += block-enbd block-nbd
     1.6  XEN_SCRIPTS += vtpm
     1.7 -XEN_SCRIPT_DATA = xen-script-common.sh
     1.8 +XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
     1.9  XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
    1.10  XEN_SCRIPT_DATA += block-common.sh vtpm-common.sh
    1.11  
     2.1 --- a/tools/examples/xen-hotplug-common.sh	Mon Feb 27 15:52:43 2006 +0100
     2.2 +++ b/tools/examples/xen-hotplug-common.sh	Mon Feb 27 16:11:01 2006 +0100
     2.3 @@ -17,7 +17,9 @@
     2.4  
     2.5  
     2.6  dir=$(dirname "$0")
     2.7 +. "$dir/logging.sh"
     2.8  . "$dir/xen-script-common.sh"
     2.9 +. "$dir/locking.sh"
    2.10  
    2.11  exec 2>>/var/log/xen-hotplug.log
    2.12  
    2.13 @@ -25,12 +27,6 @@ export PATH="/sbin:/bin:/usr/bin:/usr/sb
    2.14  export LANG="POSIX"
    2.15  unset $(set | grep ^LC_ | cut -d= -f1)
    2.16  
    2.17 -log() {
    2.18 -  local level="$1"
    2.19 -  shift
    2.20 -  logger -p "daemon.$level" -- "$0:" "$@" || echo "$0 $@" >&2
    2.21 -}
    2.22 -
    2.23  fatal() {
    2.24    xenstore_write "$XENBUS_PATH"/hotplug-status error
    2.25    log err "$@"
    2.26 @@ -93,87 +89,4 @@ xenstore_write() {
    2.27  }
    2.28  
    2.29  
    2.30 -#
    2.31 -# Serialisation
    2.32 -#
    2.33 -
    2.34 -LOCK_SLEEPTIME=1
    2.35 -LOCK_SPINNING_RETRIES=5
    2.36 -LOCK_RETRIES=10
    2.37 -LOCK_BASEDIR=/var/run/xen-hotplug
    2.38 -
    2.39 -
    2.40 -claim_lock()
    2.41 -{
    2.42 -  local lockdir="$LOCK_BASEDIR/$1"
    2.43 -  mkdir -p "$LOCK_BASEDIR"
    2.44 -  _claim_lock "$lockdir"
    2.45 -}
    2.46 -
    2.47 -
    2.48 -release_lock()
    2.49 -{
    2.50 -  _release_lock "$LOCK_BASEDIR/$1"
    2.51 -}
    2.52 -
    2.53 -
    2.54 -_claim_lock()
    2.55 -{
    2.56 -  local lockdir="$1"
    2.57 -  local owner=$(_lock_owner "$lockdir")
    2.58 -  local retries=0
    2.59 -
    2.60 -  while [ $retries -lt $LOCK_RETRIES ]
    2.61 -  do
    2.62 -    mkdir "$lockdir" 2>/dev/null && trap "release_lock $1; sigerr" ERR &&
    2.63 -      _update_lock_info "$lockdir" && return
    2.64 -
    2.65 -    local new_owner=$(_lock_owner "$lockdir")
    2.66 -    if [ "$new_owner" != "$owner" ]
    2.67 -    then
    2.68 -      owner="$new_owner"
    2.69 -      retries=0
    2.70 -    fi
    2.71 -
    2.72 -    if [ $retries -gt $LOCK_SPINNING_RETRIES ]
    2.73 -    then
    2.74 -      sleep $LOCK_SLEEPTIME
    2.75 -    else
    2.76 -      sleep 0
    2.77 -    fi
    2.78 -    retries=$(($retries + 1))
    2.79 -  done
    2.80 -  _steal_lock "$lockdir"
    2.81 -}
    2.82 -
    2.83 -
    2.84 -_release_lock()
    2.85 -{
    2.86 -  trap sigerr ERR
    2.87 -  rm -rf "$1" 2>/dev/null || true
    2.88 -}
    2.89 -
    2.90 -
    2.91 -_steal_lock()
    2.92 -{
    2.93 -  local lockdir="$1"
    2.94 -  local owner=$(cat "$lockdir/owner" 2>/dev/null || echo "unknown")
    2.95 -  log err "Forced to steal lock on $lockdir from $owner!"
    2.96 -  _release_lock "$lockdir"
    2.97 -  _claim_lock "$lockdir"
    2.98 -}
    2.99 -
   2.100 -
   2.101 -_lock_owner()
   2.102 -{
   2.103 -  cat "$1/owner" 2>/dev/null || echo "unknown"
   2.104 -}
   2.105 -
   2.106 -
   2.107 -_update_lock_info()
   2.108 -{
   2.109 -  echo "$$: $0" >"$1/owner"
   2.110 -}
   2.111 -
   2.112 -
   2.113  log debug "$@" "XENBUS_PATH=$XENBUS_PATH"
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/xen-unstable.hg/tools/examples/locking.sh	Mon Feb 27 16:11:01 2006 +0100
     3.3 @@ -0,0 +1,98 @@
     3.4 +#
     3.5 +# Copyright (c) 2005 XenSource Ltd.
     3.6 +#
     3.7 +# This library is free software; you can redistribute it and/or
     3.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     3.9 +# License as published by the Free Software Foundation.
    3.10 +#
    3.11 +# This library is distributed in the hope that it will be useful,
    3.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.14 +# Lesser General Public License for more details.
    3.15 +#
    3.16 +# You should have received a copy of the GNU Lesser General Public
    3.17 +# License along with this library; if not, write to the Free Software
    3.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.19 +#
    3.20 +
    3.21 +#
    3.22 +# Serialisation
    3.23 +#
    3.24 +
    3.25 +LOCK_SLEEPTIME=1
    3.26 +LOCK_SPINNING_RETRIES=5
    3.27 +LOCK_RETRIES=10
    3.28 +LOCK_BASEDIR=/var/run/xen-hotplug
    3.29 +
    3.30 +
    3.31 +claim_lock()
    3.32 +{
    3.33 +  local lockdir="$LOCK_BASEDIR/$1"
    3.34 +  mkdir -p "$LOCK_BASEDIR"
    3.35 +  _claim_lock "$lockdir"
    3.36 +}
    3.37 +
    3.38 +
    3.39 +release_lock()
    3.40 +{
    3.41 +  _release_lock "$LOCK_BASEDIR/$1"
    3.42 +}
    3.43 +
    3.44 +
    3.45 +_claim_lock()
    3.46 +{
    3.47 +  local lockdir="$1"
    3.48 +  local owner=$(_lock_owner "$lockdir")
    3.49 +  local retries=0
    3.50 +
    3.51 +  while [ $retries -lt $LOCK_RETRIES ]
    3.52 +  do
    3.53 +    mkdir "$lockdir" 2>/dev/null && trap "release_lock $1; sigerr" ERR &&
    3.54 +      _update_lock_info "$lockdir" && return
    3.55 +
    3.56 +    local new_owner=$(_lock_owner "$lockdir")
    3.57 +    if [ "$new_owner" != "$owner" ]
    3.58 +    then
    3.59 +      owner="$new_owner"
    3.60 +      retries=0
    3.61 +    fi
    3.62 +
    3.63 +    if [ $retries -gt $LOCK_SPINNING_RETRIES ]
    3.64 +    then
    3.65 +      sleep $LOCK_SLEEPTIME
    3.66 +    else
    3.67 +      sleep 0
    3.68 +    fi
    3.69 +    retries=$(($retries + 1))
    3.70 +  done
    3.71 +  _steal_lock "$lockdir"
    3.72 +}
    3.73 +
    3.74 +
    3.75 +_release_lock()
    3.76 +{
    3.77 +  trap sigerr ERR
    3.78 +  rm -rf "$1" 2>/dev/null || true
    3.79 +}
    3.80 +
    3.81 +
    3.82 +_steal_lock()
    3.83 +{
    3.84 +  local lockdir="$1"
    3.85 +  local owner=$(cat "$lockdir/owner" 2>/dev/null || echo "unknown")
    3.86 +  log err "Forced to steal lock on $lockdir from $owner!"
    3.87 +  _release_lock "$lockdir"
    3.88 +  _claim_lock "$lockdir"
    3.89 +}
    3.90 +
    3.91 +
    3.92 +_lock_owner()
    3.93 +{
    3.94 +  cat "$1/owner" 2>/dev/null || echo "unknown"
    3.95 +}
    3.96 +
    3.97 +
    3.98 +_update_lock_info()
    3.99 +{
   3.100 +  echo "$$: $0" >"$1/owner"
   3.101 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/xen-unstable.hg/tools/examples/logging.sh	Mon Feb 27 16:11:01 2006 +0100
     4.3 @@ -0,0 +1,22 @@
     4.4 +#
     4.5 +# Copyright (c) 2005 XenSource Ltd.
     4.6 +#
     4.7 +# This library is free software; you can redistribute it and/or
     4.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     4.9 +# License as published by the Free Software Foundation.
    4.10 +#
    4.11 +# This library is distributed in the hope that it will be useful,
    4.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.14 +# Lesser General Public License for more details.
    4.15 +#
    4.16 +# You should have received a copy of the GNU Lesser General Public
    4.17 +# License along with this library; if not, write to the Free Software
    4.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.19 +#
    4.20 +
    4.21 +log() {
    4.22 +  local level="$1"
    4.23 +  shift
    4.24 +  logger -p "daemon.$level" -- "$0:" "$@" || echo "$0 $@" >&2
    4.25 +}