direct-io.hg

changeset 7251:1b0dbfedc043

Move the block-phy and block-file handling into a common
block script that gets called by the hotplug agent.

Signed-off-by: Jeremy Katz <katzj@redhat.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Oct 07 13:13:58 2005 +0100 (2005-10-07)
parents e31e64e00ac3
children 99532f6b2ae3
files tools/examples/Makefile tools/examples/block tools/examples/xen-backend.agent
line diff
     1.1 --- a/tools/examples/Makefile	Fri Oct 07 13:11:41 2005 +0100
     1.2 +++ b/tools/examples/Makefile	Fri Oct 07 13:13:58 2005 +0100
     1.3 @@ -22,8 +22,7 @@ XEN_SCRIPT_DIR = /etc/xen/scripts
     1.4  XEN_SCRIPTS = network-bridge vif-bridge
     1.5  XEN_SCRIPTS += network-route vif-route
     1.6  XEN_SCRIPTS += network-nat vif-nat
     1.7 -XEN_SCRIPTS += block-phy
     1.8 -XEN_SCRIPTS += block-file
     1.9 +XEN_SCRIPTS += block
    1.10  XEN_SCRIPTS += block-enbd
    1.11  
    1.12  XEN_HOTPLUG_DIR = /etc/hotplug
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/examples/block	Fri Oct 07 13:13:58 2005 +0100
     2.3 @@ -0,0 +1,82 @@
     2.4 +#!/bin/sh
     2.5 +
     2.6 +set -e
     2.7 +
     2.8 +export PATH=/sbin:/bin:/usr/bin:/usr/sbin:$PATH
     2.9 +
    2.10 +expand_dev() {
    2.11 +  local dev
    2.12 +  case $1 in
    2.13 +  /*)
    2.14 +    dev=$1
    2.15 +    ;;
    2.16 +  *)
    2.17 +    dev=/dev/$1
    2.18 +    ;;
    2.19 +  esac
    2.20 +  echo -n $dev
    2.21 +}
    2.22 +
    2.23 +write_dev() {
    2.24 +  local major
    2.25 +  local minor
    2.26 +  local pdev
    2.27 +	
    2.28 +  major=$(stat -L -c %t "$1")
    2.29 +  minor=$(stat -L -c %T "$1")
    2.30 +  pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
    2.31 +  xenstore-write "$XENBUS_PATH"/physical-device $pdev \
    2.32 +      "$XENBUS_PATH"/node $1
    2.33 +}
    2.34 +
    2.35 +t=$(xenstore-read "$XENBUS_PATH"/type)
    2.36 +
    2.37 +case $1 in 
    2.38 +  bind)
    2.39 +    p=$(xenstore-read "$XENBUS_PATH"/params)
    2.40 +    case $t in 
    2.41 +      phy)
    2.42 +        dev=$(expand_dev $p)
    2.43 +	write_dev "$dev"
    2.44 +	exit 0
    2.45 +	;;
    2.46 +
    2.47 +      file)
    2.48 +	for dev in /dev/loop* ; do
    2.49 +	  echo "dev is $dev, p is $p"
    2.50 +	  if losetup $dev $p; then
    2.51 +	    write_dev "$dev"
    2.52 +            exit 0
    2.53 +	  fi
    2.54 +	done
    2.55 +	exit 1
    2.56 +	;;
    2.57 +
    2.58 +      *)
    2.59 +        [ -x /etc/xen/scripts/block-"$t" ] && \
    2.60 +	    /etc/xen/scripts/block-"$t" bind $p
    2.61 +	;;
    2.62 +    esac
    2.63 +    ;;
    2.64 +
    2.65 +  unbind)
    2.66 +    node=$(xenstore-read "$XENBUS_PATH"/node)
    2.67 +    case $t in 
    2.68 +      phy)
    2.69 +	exit 0
    2.70 +	;;
    2.71 +
    2.72 +      file)
    2.73 +	losetup -d $node
    2.74 +	exit 0
    2.75 +	;;
    2.76 +
    2.77 +      *)
    2.78 +        [ -x /etc/xen/scripts/block-"$t" ] && \
    2.79 +	    /etc/xen/scripts/block-"$t" unbind $node
    2.80 +	;;
    2.81 +
    2.82 +    esac
    2.83 +    ;;
    2.84 +
    2.85 +esac
     3.1 --- a/tools/examples/block-file	Fri Oct 07 13:11:41 2005 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,31 +0,0 @@
     3.4 -#!/bin/sh
     3.5 -
     3.6 -# Usage: block_loop [bind file|unbind node]
     3.7 -#
     3.8 -# The file argument to the bind command is the file we are to bind to a
     3.9 -# loop device.
    3.10 -#
    3.11 -# The node argument to unbind is the name of the device node we are to
    3.12 -# unbind.
    3.13 -
    3.14 -set -e
    3.15 -
    3.16 -case $1 in
    3.17 -  bind)
    3.18 -    for dev in /dev/loop*; do
    3.19 -      if losetup $dev $2; then
    3.20 -        major=$(stat -L -c %t "$dev")
    3.21 -        minor=$(stat -L -c %T "$dev")
    3.22 -        pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
    3.23 -        xenstore-write "$XENBUS_PATH"/physical-device $pdev \
    3.24 -          "$XENBUS_PATH"/node $dev
    3.25 -        exit 0
    3.26 -      fi
    3.27 -    done
    3.28 -    exit 1
    3.29 -    ;;
    3.30 -  unbind)
    3.31 -    losetup -d $2
    3.32 -    exit 0
    3.33 -    ;;
    3.34 -esac
     4.1 --- a/tools/examples/block-phy	Fri Oct 07 13:11:41 2005 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,30 +0,0 @@
     4.4 -#! /bin/sh
     4.5 -
     4.6 -set -e
     4.7 -
     4.8 -expand_dev() {
     4.9 -  local dev
    4.10 -  case $1 in
    4.11 -  /*)
    4.12 -    dev=$1
    4.13 -    ;;
    4.14 -  *)
    4.15 -    dev=/dev/$1
    4.16 -    ;;
    4.17 -  esac
    4.18 -  echo -n $dev
    4.19 -}
    4.20 -
    4.21 -case $1 in
    4.22 -  bind)
    4.23 -    dev=$(expand_dev $2)
    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 -    exit 0
    4.30 -    ;;
    4.31 -  unbind)
    4.32 -    ;;
    4.33 -esac
     5.1 --- a/tools/examples/xen-backend.agent	Fri Oct 07 13:11:41 2005 +0100
     5.2 +++ b/tools/examples/xen-backend.agent	Fri Oct 07 13:13:58 2005 +0100
     5.3 @@ -11,20 +11,14 @@ case "$ACTION" in
     5.4    add)
     5.5      case "$XENBUS_TYPE" in
     5.6        vbd)
     5.7 -        t=$(xenstore-read "$XENBUS_PATH"/type)
     5.8 -        params=$(xenstore-read "$XENBUS_PATH"/params)
     5.9 -        [ -x /etc/xen/scripts/block-"$t" ] && \
    5.10 -            /etc/xen/scripts/block-"$t" bind $params
    5.11 +	/etc/xen/scripts/block bind
    5.12          ;;
    5.13      esac
    5.14      ;;
    5.15    remove)
    5.16      case "$XENBUS_TYPE" in
    5.17        vbd)
    5.18 -        t=$(xenstore-read "$XENBUS_PATH"/type)
    5.19 -        node=$(xenstore-read "$XENBUS_PATH"/node)
    5.20 -        [ -x /etc/xen/scripts/block-"$t" ] && \
    5.21 -            /etc/xen/scripts/block-"$t" unbind $node
    5.22 +	/etc/xen/scripts/block unbind
    5.23          ;;
    5.24      esac
    5.25      # remove device backend store entries