diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/examples/blktap | 57 | ||||
-rw-r--r-- | tools/examples/block | 42 | ||||
-rw-r--r-- | tools/examples/block-common.sh | 43 |
3 files changed, 100 insertions, 42 deletions
diff --git a/tools/examples/blktap b/tools/examples/blktap index 5a7ee3236b..e4ac40b331 100644 --- a/tools/examples/blktap +++ b/tools/examples/blktap @@ -8,6 +8,57 @@ dir=$(dirname "$0") findCommand "$@" +## +# check_blktap_sharing file mode +# +# Perform the sharing check for the given blktap and mode. +# +check_blktap_sharing() +{ + local file="$1" + local mode="$2" + + local base_path="$XENBUS_BASE_PATH/$XENBUS_TYPE" + for dom in $(xenstore-list "$base_path") + do + for dev in $(xenstore-list "$base_path/$dom") + do + params=$(xenstore_read "$base_path/$dom/$dev/params" | cut -d: -f2) + if [ "$file" = "$params" ] + then + + if [ "$mode" = 'w' ] + then + if ! same_vm "$dom" + then + echo 'guest' + return + fi + else + local m=$(xenstore_read "$base_path/$dom/$dev/mode") + m=$(canonicalise_mode "$m") + + if [ "$m" = 'w' ] + then + if ! same_vm "$dom" + then + echo 'guest' + return + fi + fi + fi + fi + done + done + + echo 'ok' +} + +FRONTEND_ID=$(xenstore_read "$XENBUS_PATH/frontend-id") +FRONTEND_UUID=$(xenstore_read "/local/domain/$FRONTEND_ID/vm") +mode=$(xenstore_read "$XENBUS_PATH/mode") +mode=$(canonicalise_mode "$mode") + t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING') if [ -n "$t" ] then @@ -20,6 +71,12 @@ then fi file=$(readlink -f "$p") || ebusy "$p does not exist." +if [ "$mode" != '!' ] +then + result=$(check_blktap_sharing "$file" "$mode") + [ "$result" = 'ok' ] || ebusy "$file already in use by other domain" +fi + if [ "$command" = 'add' ] then [ -e "$file" ] || { ebusy $file does not exist; } diff --git a/tools/examples/block b/tools/examples/block index 2b6b991125..1cf6fb8fc8 100644 --- a/tools/examples/block +++ b/tools/examples/block @@ -18,32 +18,6 @@ expand_dev() { ## -# canonicalise_mode mode -# -# Takes the given mode, which may be r, w, ro, rw, w!, or rw!, or variations -# thereof, and canonicalises them to one of -# -# 'r': perform checks for a new read-only mount; -# 'w': perform checks for a read-write mount; or -# '!': perform no checks at all. -# -canonicalise_mode() -{ - local mode="$1" - - if ! expr index "$mode" 'w' >/dev/null - then - echo 'r' - elif ! expr index "$mode" '!' >/dev/null - then - echo 'w' - else - echo '!' - fi -} - - -## # check_sharing device mode # # Check whether the device requested is already in use. To use the device in @@ -126,22 +100,6 @@ check_sharing() } -same_vm() -{ - local otherdom="$1" - # Note that othervm can be MISSING here, because Xend will be racing with - # the hotplug scripts -- the entries in /local/domain can be removed by - # Xend before the hotplug scripts have removed the entry in - # /local/domain/0/backend/. In this case, we want to pretend that the - # VM is the same as FRONTEND_UUID, because that way the 'sharing' will be - # allowed. - local othervm=$(xenstore_read_default "/local/domain/$otherdom/vm" \ - "$FRONTEND_UUID") - - [ "$FRONTEND_UUID" = "$othervm" ] -} - - ## # check_device_sharing dev mode # diff --git a/tools/examples/block-common.sh b/tools/examples/block-common.sh index 000b52724f..a0ebc9b12a 100644 --- a/tools/examples/block-common.sh +++ b/tools/examples/block-common.sh @@ -71,3 +71,46 @@ write_dev() { success } + + +## +# canonicalise_mode mode +# +# Takes the given mode, which may be r, w, ro, rw, w!, or rw!, or variations +# thereof, and canonicalises them to one of +# +# 'r': perform checks for a new read-only mount; +# 'w': perform checks for a read-write mount; or +# '!': perform no checks at all. +# +canonicalise_mode() +{ + local mode="$1" + + if ! expr index "$mode" 'w' >/dev/null + then + echo 'r' + elif ! expr index "$mode" '!' >/dev/null + then + echo 'w' + else + echo '!' + fi +} + + +same_vm() +{ + local otherdom="$1" + # Note that othervm can be MISSING here, because Xend will be racing with + # the hotplug scripts -- the entries in /local/domain can be removed by + # Xend before the hotplug scripts have removed the entry in + # /local/domain/0/backend/. In this case, we want to pretend that the + # VM is the same as FRONTEND_UUID, because that way the 'sharing' will be + # allowed. + local othervm=$(xenstore_read_default "/local/domain/$otherdom/vm" \ + "$FRONTEND_UUID") + + [ "$FRONTEND_UUID" = "$othervm" ] +} + |