[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Move block device bind/unbind into hotplug scripts.



# HG changeset patch
# User cl349@xxxxxxxxxxxxxxxxxxxx
# Node ID e9d01c5dc7b4d6b7cda9ade0d137ddb89bb204cc
# Parent  968541972a7c2291001dd65966920d43091ff920
Move block device bind/unbind into hotplug scripts.
Fixes file: devices since unbind now runs after the backend driver
closes the loopback device.
Also moves name -> node translation into the backend domain.
Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>

diff -r 968541972a7c -r e9d01c5dc7b4 tools/examples/Makefile
--- a/tools/examples/Makefile   Mon Sep 12 19:46:30 2005
+++ b/tools/examples/Makefile   Mon Sep 12 19:49:03 2005
@@ -21,6 +21,7 @@
 XEN_SCRIPT_DIR = /etc/xen/scripts
 XEN_SCRIPTS = network-bridge vif-bridge
 XEN_SCRIPTS += network-route vif-route
+XEN_SCRIPTS += block-phy
 XEN_SCRIPTS += block-file
 XEN_SCRIPTS += block-enbd
 
diff -r 968541972a7c -r e9d01c5dc7b4 tools/examples/block-enbd
--- a/tools/examples/block-enbd Mon Sep 12 19:46:30 2005
+++ b/tools/examples/block-enbd Mon Sep 12 19:49:03 2005
@@ -3,31 +3,31 @@
 # Usage: block-enbd [bind server ctl_port |unbind node]
 #
 # The file argument to the bind command is the file we are to bind to a
-# loop device.  We print the path to the loop device node to stdout.
+# loop device.
 #
 # The node argument to unbind is the name of the device node we are to
 # unbind.
 #
 # This assumes you're running a correctly configured server at the other end!
 
+set -e
+
 case $1 in
-       bind)
-               for dev in /dev/nd*; do
-                       if nbd-client $2:$3 $dev; then
-                               echo $dev
-                               exit 0
-                       fi
-               done
-               exit 1
-       ;;
-
-       unbind)
-               nbd-client -d $2
-               exit 0
-       ;;
-
-       *)
-               echo 'Unknown command: ' $1 >&2
-               echo 'Valid commands are: bind, unbind' >&2
-               exit 1
+  bind)
+    for dev in /dev/nd*; do
+      if nbd-client $2:$3 $dev; then
+        major=$(stat -L -c %t "$dev")
+        minor=$(stat -L -c %T "$dev")
+        pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
+        xenstore-write "$XENBUS_PATH"/physical-device $pdev \
+          "$XENBUS_PATH"/node $dev
+        exit 0
+      fi
+    done
+    exit 1
+    ;;
+  unbind)
+    nbd-client -d $2
+    exit 0
+    ;;
 esac
diff -r 968541972a7c -r e9d01c5dc7b4 tools/examples/block-file
--- a/tools/examples/block-file Mon Sep 12 19:46:30 2005
+++ b/tools/examples/block-file Mon Sep 12 19:49:03 2005
@@ -3,29 +3,29 @@
 # Usage: block_loop [bind file|unbind node]
 #
 # The file argument to the bind command is the file we are to bind to a
-# loop device.  We print the path to the loop device node to stdout.
+# loop device.
 #
 # The node argument to unbind is the name of the device node we are to
 # unbind.
 
+set -e
+
 case $1 in
-       bind)
-               for dev in /dev/loop*; do
-                       if losetup $dev $2; then
-                               echo $dev
-                               exit 0
-                       fi
-               done
-               exit 1
-       ;;
-
-       unbind)
-               losetup -d $2
-               exit 0
-       ;;
-
-       *)
-               echo 'Unknown command: ' $1 >&2
-               echo 'Valid commands are: bind, unbind' >&2
-               exit 1
+  bind)
+    for dev in /dev/loop*; do
+      if losetup $dev $2; then
+        major=$(stat -L -c %t "$dev")
+        minor=$(stat -L -c %T "$dev")
+        pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
+        xenstore-write "$XENBUS_PATH"/physical-device $pdev \
+          "$XENBUS_PATH"/node $dev
+        exit 0
+      fi
+    done
+    exit 1
+    ;;
+  unbind)
+    losetup -d $2
+    exit 0
+    ;;
 esac
diff -r 968541972a7c -r e9d01c5dc7b4 tools/examples/xen-backend.agent
--- a/tools/examples/xen-backend.agent  Mon Sep 12 19:46:30 2005
+++ b/tools/examples/xen-backend.agent  Mon Sep 12 19:49:03 2005
@@ -9,8 +9,26 @@
 
 case "$ACTION" in
   add)
+    case "$XENBUS_TYPE" in
+      vbd)
+        t=$(xenstore-read "$XENBUS_PATH"/type)
+        params=$(xenstore-read "$XENBUS_PATH"/params)
+        [ -x /etc/xen/scripts/block-"$t" ] && \
+            /etc/xen/scripts/block-"$t" bind $params
+        ;;
+    esac
     ;;
   remove)
+    case "$XENBUS_TYPE" in
+      vbd)
+        t=$(xenstore-read "$XENBUS_PATH"/type)
+        node=$(xenstore-read "$XENBUS_PATH"/node)
+        [ -x /etc/xen/scripts/block-"$t" ] && \
+            /etc/xen/scripts/block-"$t" unbind $node
+        ;;
+    esac
+    # remove device backend store entries
+    xenstore-rm "$XENBUS_PATH"
     ;;
   online)
     case "$PHYSDEVDRIVER" in
diff -r 968541972a7c -r e9d01c5dc7b4 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Mon Sep 12 19:46:30 2005
+++ b/tools/python/xen/xend/XendDomainInfo.py   Mon Sep 12 19:49:03 2005
@@ -413,17 +413,13 @@
             db['backend'] = backdb.getPath()
             db['backend-id'] = "%i" % backdom.id
 
+            (type, params) = string.split(sxp.child_value(devconfig, 'uname'), 
':', 1)
+            backdb['type'] = type
+            backdb['params'] = params
             backdb['frontend'] = db.getPath()
-            (type, params) = string.split(sxp.child_value(devconfig, 'uname'), 
':', 1)
-            node = Blkctl.block('bind', type, params)
             backdb['frontend-id'] = "%i" % self.id
-            backdb['physical-device'] = "%li" % blkdev_name_to_number(node)
             backdb.saveDB(save=True)
 
-            # Ok, super gross, this really doesn't belong in the frontend db...
-            db['type'] = type
-            db['node'] = node
-            db['params'] = params
             db.saveDB(save=True)
             
             return
@@ -808,9 +804,6 @@
             if type == 'vbd':
                 typedb = ddb.addChild(type)
                 for dev in typedb.keys():
-                    devdb = typedb.addChild(str(dev))
-                    Blkctl.block('unbind', devdb['type'].getData(),
-                                 devdb['node'].getData())
                     typedb[dev].delete()
                 typedb.saveDB(save=True)
             if type == 'vtpm':
diff -r 968541972a7c -r e9d01c5dc7b4 tools/examples/block-phy
--- /dev/null   Mon Sep 12 19:46:30 2005
+++ b/tools/examples/block-phy  Mon Sep 12 19:49:03 2005
@@ -0,0 +1,30 @@
+#! /bin/sh
+
+set -e
+
+expand_dev() {
+  local dev
+  case $1 in
+  /*)
+    dev=$1
+    ;;
+  *)
+    dev=/dev/$1
+    ;;
+  esac
+  echo -n $dev
+}
+
+case $1 in
+  bind)
+    dev=$(expand_dev $2)
+    major=$(stat -L -c %t "$dev")
+    minor=$(stat -L -c %T "$dev")
+    pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
+    xenstore-write "$XENBUS_PATH"/physical-device $pdev \
+        "$XENBUS_PATH"/node $dev
+    exit 0
+    ;;
+  unbind)
+    ;;
+esac

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.