ia64/xen-unstable

changeset 15774:bd8647a7b992

Add sharing-check for blktap

Signed-off-by: Takanori Kasai <kasai.takanori@jp.fujitsu.com>
Signed-off-by: Hirofumi Tsujimura <tsujimura.hirof@jp.fujitsu.com>
author kfraser@localhost.localdomain
date Fri Aug 17 10:02:52 2007 +0100 (2007-08-17)
parents ac7a8c9d6202
children a1b6555a37bf
files tools/examples/blktap tools/examples/block tools/examples/block-common.sh
line diff
     1.1 --- a/tools/examples/blktap	Fri Aug 17 10:01:40 2007 +0100
     1.2 +++ b/tools/examples/blktap	Fri Aug 17 10:02:52 2007 +0100
     1.3 @@ -8,6 +8,57 @@ dir=$(dirname "$0")
     1.4  
     1.5  findCommand "$@"
     1.6  
     1.7 +##
     1.8 +# check_blktap_sharing file mode
     1.9 +#
    1.10 +# Perform the sharing check for the given blktap and mode.
    1.11 +#
    1.12 +check_blktap_sharing()
    1.13 +{
    1.14 +    local file="$1"
    1.15 +    local mode="$2"
    1.16 +
    1.17 +    local base_path="$XENBUS_BASE_PATH/$XENBUS_TYPE"
    1.18 +    for dom in $(xenstore-list "$base_path")
    1.19 +    do
    1.20 +        for dev in $(xenstore-list "$base_path/$dom")
    1.21 +        do
    1.22 +            params=$(xenstore_read "$base_path/$dom/$dev/params" | cut -d: -f2)
    1.23 +            if [ "$file" = "$params" ]
    1.24 +            then
    1.25 +
    1.26 +                if [ "$mode" = 'w' ]
    1.27 +                then
    1.28 +                    if ! same_vm "$dom" 
    1.29 +                    then
    1.30 +                        echo 'guest'
    1.31 +                        return
    1.32 +                    fi
    1.33 +                else 
    1.34 +                    local m=$(xenstore_read "$base_path/$dom/$dev/mode")
    1.35 +                    m=$(canonicalise_mode "$m")
    1.36 +
    1.37 +                    if [ "$m" = 'w' ] 
    1.38 +                    then
    1.39 +                        if ! same_vm "$dom"
    1.40 +                        then
    1.41 +                            echo 'guest'
    1.42 +                            return
    1.43 +                        fi
    1.44 +                    fi
    1.45 +                fi
    1.46 +            fi
    1.47 +        done
    1.48 +    done
    1.49 +
    1.50 +    echo 'ok'
    1.51 +}
    1.52 +
    1.53 +FRONTEND_ID=$(xenstore_read "$XENBUS_PATH/frontend-id")
    1.54 +FRONTEND_UUID=$(xenstore_read "/local/domain/$FRONTEND_ID/vm")
    1.55 +mode=$(xenstore_read "$XENBUS_PATH/mode")
    1.56 +mode=$(canonicalise_mode "$mode")
    1.57 +
    1.58  t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING')
    1.59  if [ -n "$t" ]
    1.60  then
    1.61 @@ -20,6 +71,12 @@ then
    1.62  fi
    1.63  file=$(readlink -f "$p") || ebusy "$p does not exist."
    1.64  
    1.65 +if [ "$mode" != '!' ] 
    1.66 +then
    1.67 +    result=$(check_blktap_sharing "$file" "$mode")
    1.68 +    [ "$result" = 'ok' ] || ebusy "$file already in use by other domain"
    1.69 +fi
    1.70 +
    1.71  if [ "$command" = 'add' ]
    1.72  then
    1.73      [ -e "$file" ] || { ebusy $file does not exist; }
     2.1 --- a/tools/examples/block	Fri Aug 17 10:01:40 2007 +0100
     2.2 +++ b/tools/examples/block	Fri Aug 17 10:02:52 2007 +0100
     2.3 @@ -18,32 +18,6 @@ expand_dev() {
     2.4  
     2.5  
     2.6  ##
     2.7 -# canonicalise_mode mode
     2.8 -#
     2.9 -# Takes the given mode, which may be r, w, ro, rw, w!, or rw!, or variations
    2.10 -# thereof, and canonicalises them to one of
    2.11 -#
    2.12 -#   'r': perform checks for a new read-only mount;
    2.13 -#   'w': perform checks for a read-write mount; or
    2.14 -#   '!': perform no checks at all.
    2.15 -#
    2.16 -canonicalise_mode()
    2.17 -{
    2.18 -  local mode="$1"
    2.19 -
    2.20 -  if ! expr index "$mode" 'w' >/dev/null
    2.21 -  then
    2.22 -    echo 'r'
    2.23 -  elif ! expr index "$mode" '!' >/dev/null
    2.24 -  then
    2.25 -    echo 'w'
    2.26 -  else
    2.27 -    echo '!'
    2.28 -  fi
    2.29 -}
    2.30 -
    2.31 -
    2.32 -##
    2.33  # check_sharing device mode
    2.34  #
    2.35  # Check whether the device requested is already in use.  To use the device in
    2.36 @@ -126,22 +100,6 @@ check_sharing()
    2.37  }
    2.38  
    2.39  
    2.40 -same_vm()
    2.41 -{
    2.42 -  local otherdom="$1"
    2.43 -  # Note that othervm can be MISSING here, because Xend will be racing with
    2.44 -  # the hotplug scripts -- the entries in /local/domain can be removed by
    2.45 -  # Xend before the hotplug scripts have removed the entry in
    2.46 -  # /local/domain/0/backend/.  In this case, we want to pretend that the
    2.47 -  # VM is the same as FRONTEND_UUID, because that way the 'sharing' will be
    2.48 -  # allowed.
    2.49 -  local othervm=$(xenstore_read_default "/local/domain/$otherdom/vm"         \
    2.50 -                  "$FRONTEND_UUID")
    2.51 -
    2.52 -  [ "$FRONTEND_UUID" = "$othervm" ]
    2.53 -}
    2.54 -
    2.55 -
    2.56  ##
    2.57  # check_device_sharing dev mode
    2.58  #
     3.1 --- a/tools/examples/block-common.sh	Fri Aug 17 10:01:40 2007 +0100
     3.2 +++ b/tools/examples/block-common.sh	Fri Aug 17 10:02:52 2007 +0100
     3.3 @@ -71,3 +71,46 @@ write_dev() {
     3.4  
     3.5    success
     3.6  }
     3.7 +
     3.8 +
     3.9 +##
    3.10 +# canonicalise_mode mode
    3.11 +#
    3.12 +# Takes the given mode, which may be r, w, ro, rw, w!, or rw!, or variations
    3.13 +# thereof, and canonicalises them to one of
    3.14 +#
    3.15 +#   'r': perform checks for a new read-only mount;
    3.16 +#   'w': perform checks for a read-write mount; or
    3.17 +#   '!': perform no checks at all.
    3.18 +#
    3.19 +canonicalise_mode()
    3.20 +{
    3.21 +  local mode="$1"
    3.22 +
    3.23 +  if ! expr index "$mode" 'w' >/dev/null
    3.24 +  then
    3.25 +    echo 'r'
    3.26 +  elif ! expr index "$mode" '!' >/dev/null
    3.27 +  then
    3.28 +    echo 'w'
    3.29 +  else
    3.30 +    echo '!'
    3.31 +  fi
    3.32 +}
    3.33 +
    3.34 +
    3.35 +same_vm()
    3.36 +{
    3.37 +  local otherdom="$1"
    3.38 +  # Note that othervm can be MISSING here, because Xend will be racing with
    3.39 +  # the hotplug scripts -- the entries in /local/domain can be removed by
    3.40 +  # Xend before the hotplug scripts have removed the entry in
    3.41 +  # /local/domain/0/backend/.  In this case, we want to pretend that the
    3.42 +  # VM is the same as FRONTEND_UUID, because that way the 'sharing' will be
    3.43 +  # allowed.
    3.44 +  local othervm=$(xenstore_read_default "/local/domain/$otherdom/vm"         \
    3.45 +                  "$FRONTEND_UUID")
    3.46 +
    3.47 +  [ "$FRONTEND_UUID" = "$othervm" ]
    3.48 +}
    3.49 +