ia64/xen-unstable

changeset 7530:98fd1359eecd

Break the write_dev function out from block into new block-common.sh, where it
can also be used by block-enbd and block-nbd.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Wed Oct 26 14:58:13 2005 +0100 (2005-10-26)
parents 4983606a263e
children 0240a69e1f97
files tools/examples/Makefile tools/examples/block tools/examples/block-common.sh tools/examples/block-enbd tools/examples/block-nbd
line diff
     1.1 --- a/tools/examples/Makefile	Wed Oct 26 14:57:16 2005 +0100
     1.2 +++ b/tools/examples/Makefile	Wed Oct 26 14:58:13 2005 +0100
     1.3 @@ -24,8 +24,9 @@ XEN_SCRIPTS = network-bridge vif-bridge
     1.4  XEN_SCRIPTS += network-route vif-route
     1.5  XEN_SCRIPTS += network-nat vif-nat
     1.6  XEN_SCRIPTS += block
     1.7 -XEN_SCRIPTS += block-enbd
     1.8 +XEN_SCRIPTS += block-enbd block-nbd
     1.9  XEN_SCRIPTS += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
    1.10 +XEN_SCRIPTS += block-common.sh
    1.11  
    1.12  XEN_HOTPLUG_DIR = /etc/hotplug
    1.13  XEN_HOTPLUG_SCRIPTS = xen-backend.agent
     2.1 --- a/tools/examples/block	Wed Oct 26 14:57:16 2005 +0100
     2.2 +++ b/tools/examples/block	Wed Oct 26 14:58:13 2005 +0100
     2.3 @@ -1,7 +1,7 @@
     2.4  #!/bin/sh
     2.5  
     2.6  dir=$(dirname "$0")
     2.7 -. "$dir/xen-hotplug-common.sh"
     2.8 +. "$dir/block-common.sh"
     2.9  
    2.10  expand_dev() {
    2.11    local dev
    2.12 @@ -16,21 +16,9 @@ expand_dev() {
    2.13    echo -n $dev
    2.14  }
    2.15  
    2.16 -write_dev() {
    2.17 -  local major
    2.18 -  local minor
    2.19 -  local pdev
    2.20 -	
    2.21 -  major=$(stat -L -c %t "$1")
    2.22 -  minor=$(stat -L -c %T "$1")
    2.23 -  pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
    2.24 -  xenstore_write "$XENBUS_PATH"/physical-device $pdev \
    2.25 -      "$XENBUS_PATH"/node $1
    2.26 -}
    2.27 -
    2.28  t=$(xenstore_read "$XENBUS_PATH"/type || true)
    2.29  
    2.30 -case $1 in 
    2.31 +case "$command" in 
    2.32    bind)
    2.33      p=$(xenstore_read "$XENBUS_PATH"/params)
    2.34      case $t in 
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/examples/block-common.sh	Wed Oct 26 14:58:13 2005 +0100
     3.3 @@ -0,0 +1,51 @@
     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 +dir=$(dirname "$0")
    3.23 +. "$dir/xen-hotplug-common.sh"
    3.24 +
    3.25 +command="$1"
    3.26 +
    3.27 +if [ "$command" != "bind" ] && [ "$command" != "unbind" ]
    3.28 +then
    3.29 +  log err "Invalid command: $command"
    3.30 +  exit 1
    3.31 +fi
    3.32 +
    3.33 +
    3.34 +XENBUS_PATH="${XENBUS_PATH:?}"
    3.35 +
    3.36 +
    3.37 +##
    3.38 +# Write physical-device = 0xMMmm and node = device to the store, where MM
    3.39 +# and mm are the major and minor numbers of device.
    3.40 +#
    3.41 +# @param device The device from which major and minor numbers are read, which
    3.42 +#               will be written into the store.
    3.43 +#
    3.44 +write_dev() {
    3.45 +  local major
    3.46 +  local minor
    3.47 +  local pdev
    3.48 +	
    3.49 +  major=$(stat -L -c %t "$1")
    3.50 +  minor=$(stat -L -c %T "$1")
    3.51 +  pdev=$(printf "0x%02x%02x" "0x$major" "0x$minor")
    3.52 +  xenstore_write "$XENBUS_PATH"/physical-device "$pdev" \
    3.53 +                 "$XENBUS_PATH"/node "$1"
    3.54 +}
     4.1 --- a/tools/examples/block-enbd	Wed Oct 26 14:57:16 2005 +0100
     4.2 +++ b/tools/examples/block-enbd	Wed Oct 26 14:58:13 2005 +0100
     4.3 @@ -2,25 +2,19 @@
     4.4  
     4.5  # Usage: block-enbd [bind server ctl_port |unbind node]
     4.6  #
     4.7 -# The file argument to the bind command is the file we are to bind to a
     4.8 -# loop device.
     4.9 -#
    4.10  # The node argument to unbind is the name of the device node we are to
    4.11  # unbind.
    4.12  #
    4.13  # This assumes you're running a correctly configured server at the other end!
    4.14  
    4.15 -set -e
    4.16 +dir=$(dirname "$0")
    4.17 +. "$dir/block-common.sh"
    4.18  
    4.19 -case $1 in
    4.20 +case "$command" in
    4.21    bind)
    4.22      for dev in /dev/nd*; do
    4.23        if nbd-client $2:$3 $dev; then
    4.24 -        major=$(stat -L -c %t "$dev")
    4.25 -        minor=$(stat -L -c %T "$dev")
    4.26 -        pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
    4.27 -        xenstore-write "$XENBUS_PATH"/physical-device $pdev \
    4.28 -          "$XENBUS_PATH"/node $dev
    4.29 +        write_dev $dev
    4.30          exit 0
    4.31        fi
    4.32      done
     5.1 --- a/tools/examples/block-nbd	Wed Oct 26 14:57:16 2005 +0100
     5.2 +++ b/tools/examples/block-nbd	Wed Oct 26 14:58:13 2005 +0100
     5.3 @@ -1,28 +1,20 @@
     5.4  #!/bin/sh
     5.5  
     5.6 -# Usage: block-enbd [bind server ctl_port |unbind node]
     5.7 -#
     5.8 -# The file argument to the bind command is the file we are to bind to a
     5.9 -# loop device.
    5.10 +# Usage: block-nbd [bind server ctl_port |unbind node]
    5.11  #
    5.12  # The node argument to unbind is the name of the device node we are to
    5.13  # unbind.
    5.14  #
    5.15  # This assumes you're running a correctly configured server at the other end!
    5.16  
    5.17 -set -e
    5.18 +dir=$(dirname "$0")
    5.19 +. "$dir/block-common.sh"
    5.20  
    5.21 -#echo "block-enbd: $@" | logger -t xen
    5.22 -
    5.23 -case $1 in
    5.24 +case "$command" in
    5.25    bind)
    5.26      for dev in /dev/nbd*; do
    5.27        if nbd-client $2 $3 $dev; then
    5.28 -        major=$(stat -L -c %t "$dev")
    5.29 -        minor=$(stat -L -c %T "$dev")
    5.30 -        pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
    5.31 -        xenstore-write "$XENBUS_PATH"/physical-device $pdev \
    5.32 -          "$XENBUS_PATH"/node $dev
    5.33 +        write_dev $dev
    5.34          exit 0
    5.35        fi
    5.36      done