# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1187341372 -3600
# Node ID bd8647a7b992c01743e89b7d0d6b258774acee53
# Parent ac7a8c9d620262fd8d193130e3e6f7b2d3be95db
Add sharing-check for blktap
Signed-off-by: Takanori Kasai <kasai.takanori@xxxxxxxxxxxxxx>
Signed-off-by: Hirofumi Tsujimura <tsujimura.hirof@xxxxxxxxxxxxxx>
---
tools/examples/blktap | 57 +++++++++++++++++++++++++++++++++++++++++
tools/examples/block | 42 ------------------------------
tools/examples/block-common.sh | 43 ++++++++++++++++++++++++++++++
3 files changed, 100 insertions(+), 42 deletions(-)
diff -r ac7a8c9d6202 -r bd8647a7b992 tools/examples/blktap
--- a/tools/examples/blktap Fri Aug 17 10:01:40 2007 +0100
+++ b/tools/examples/blktap Fri Aug 17 10:02:52 2007 +0100
@@ -7,6 +7,57 @@ dir=$(dirname "$0")
. "$dir/block-common.sh"
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" ]
@@ -20,6 +71,12 @@ fi
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 -r ac7a8c9d6202 -r bd8647a7b992 tools/examples/block
--- a/tools/examples/block Fri Aug 17 10:01:40 2007 +0100
+++ b/tools/examples/block Fri Aug 17 10:02:52 2007 +0100
@@ -14,32 +14,6 @@ expand_dev() {
;;
esac
echo -n $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
}
@@ -123,22 +97,6 @@ check_sharing()
done
echo 'ok'
-}
-
-
-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" ]
}
diff -r ac7a8c9d6202 -r bd8647a7b992 tools/examples/block-common.sh
--- a/tools/examples/block-common.sh Fri Aug 17 10:01:40 2007 +0100
+++ b/tools/examples/block-common.sh Fri Aug 17 10:02:52 2007 +0100
@@ -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" ]
+}
+
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|