Skip to contentSkip to conversation

Add sharing-check for blktap

PATCH New Kasai Takanori 1 participant 1 message Aug 17, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add sharing-check for blktap

Hi All,

When the same file is specified with blktap in two or more domains, it is not checked regardless of the mode.

The configuration file is defined as follows.

Domain1 :
disk = [ ,"tap:aio:/xen/image/tmp/drive.img-1,xvdd,w" ]

Domain2 :
disk = [ ,"tap:aio:/xen/image/tmp/drive.img-1,xvdd,w" ]

Even if the same file is specified, the domain can be started.

# xm create -f Domain1
Using config file "./Domain1"
Started domain Domain1
# xm create -f Domain2
Using config file "./Domain2"
Started domain Domain2

Whether it is possible to share in the specified mode in file backend and physical device is checked. However, blktap is not checked at all.

Domain1 Domain2 phy: tap:
mode mode file:
--------+---------+----------+------------

  w         w       Error      Started
  w         r       Error      Started
  w         w!      Started    Started
  r         w       Error      Started
  r         r       Started    Started
  r         w!      Started    Started
  w!        w       Error      Started
  w!        r       Started    Started
  w!        w!      Started    Started

There is a possibility of breaking the file because it can unconsciously share the same file by two or more domains. We corrected to do the sharing-check for blktap similarly. It was tested to check it similarly with all cases in this patch.

Best Regards

--
Takanori Kasai

# HG changeset patch
# User [email protected]
# Date 1187334489 -32400
# Node ID f7d985c286f1b670bc470383094bd6238eed122b # Parent 256160ff19b74057f5819af20d68e6e3388c80e3 Add sharing-check for blktap

tools/examples/blktap +57 -0
diff -r 256160ff19b7 -r f7d985c286f1 tools/examples/blktap
@@ -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; }
tools/examples/block +0 -42

54 lines not on this page · raw message

tools/examples/block-common.sh +43 -0

46 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel