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

[Xen-changelog] Break the write_dev function out from block into new block-common.sh, where it



# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID 98fd1359eecdeb58174b52e6339ea35e55022a13
# Parent  4983606a263e2b6cc6a2d253c9469c7073c25e8e
Break the write_dev function out from block into new block-common.sh, where it
can also be used by block-enbd and block-nbd.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r 4983606a263e -r 98fd1359eecd tools/examples/Makefile
--- a/tools/examples/Makefile   Wed Oct 26 13:57:16 2005
+++ b/tools/examples/Makefile   Wed Oct 26 13:58:13 2005
@@ -24,8 +24,9 @@
 XEN_SCRIPTS += network-route vif-route
 XEN_SCRIPTS += network-nat vif-nat
 XEN_SCRIPTS += block
-XEN_SCRIPTS += block-enbd
+XEN_SCRIPTS += block-enbd block-nbd
 XEN_SCRIPTS += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
+XEN_SCRIPTS += block-common.sh
 
 XEN_HOTPLUG_DIR = /etc/hotplug
 XEN_HOTPLUG_SCRIPTS = xen-backend.agent
diff -r 4983606a263e -r 98fd1359eecd tools/examples/block
--- a/tools/examples/block      Wed Oct 26 13:57:16 2005
+++ b/tools/examples/block      Wed Oct 26 13:58:13 2005
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 dir=$(dirname "$0")
-. "$dir/xen-hotplug-common.sh"
+. "$dir/block-common.sh"
 
 expand_dev() {
   local dev
@@ -16,21 +16,9 @@
   echo -n $dev
 }
 
-write_dev() {
-  local major
-  local minor
-  local pdev
-       
-  major=$(stat -L -c %t "$1")
-  minor=$(stat -L -c %T "$1")
-  pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
-  xenstore_write "$XENBUS_PATH"/physical-device $pdev \
-      "$XENBUS_PATH"/node $1
-}
-
 t=$(xenstore_read "$XENBUS_PATH"/type || true)
 
-case $1 in 
+case "$command" in 
   bind)
     p=$(xenstore_read "$XENBUS_PATH"/params)
     case $t in 
diff -r 4983606a263e -r 98fd1359eecd tools/examples/block-enbd
--- a/tools/examples/block-enbd Wed Oct 26 13:57:16 2005
+++ b/tools/examples/block-enbd Wed Oct 26 13:58:13 2005
@@ -1,26 +1,20 @@
 #!/bin/sh
 
 # 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.
 #
 # 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
+dir=$(dirname "$0")
+. "$dir/block-common.sh"
 
-case $1 in
+case "$command" in
   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
+        write_dev $dev
         exit 0
       fi
     done
diff -r 4983606a263e -r 98fd1359eecd tools/examples/block-nbd
--- a/tools/examples/block-nbd  Wed Oct 26 13:57:16 2005
+++ b/tools/examples/block-nbd  Wed Oct 26 13:58:13 2005
@@ -1,28 +1,20 @@
 #!/bin/sh
 
-# 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.
+# Usage: block-nbd [bind server ctl_port |unbind node]
 #
 # 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
+dir=$(dirname "$0")
+. "$dir/block-common.sh"
 
-#echo "block-enbd: $@" | logger -t xen
-
-case $1 in
+case "$command" in
   bind)
     for dev in /dev/nbd*; 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
+        write_dev $dev
         exit 0
       fi
     done
diff -r 4983606a263e -r 98fd1359eecd tools/examples/block-common.sh
--- /dev/null   Wed Oct 26 13:57:16 2005
+++ b/tools/examples/block-common.sh    Wed Oct 26 13:58:13 2005
@@ -0,0 +1,51 @@
+#
+# Copyright (c) 2005 XenSource Ltd.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+
+dir=$(dirname "$0")
+. "$dir/xen-hotplug-common.sh"
+
+command="$1"
+
+if [ "$command" != "bind" ] && [ "$command" != "unbind" ]
+then
+  log err "Invalid command: $command"
+  exit 1
+fi
+
+
+XENBUS_PATH="${XENBUS_PATH:?}"
+
+
+##
+# Write physical-device = 0xMMmm and node = device to the store, where MM
+# and mm are the major and minor numbers of device.
+#
+# @param device The device from which major and minor numbers are read, which
+#               will be written into the store.
+#
+write_dev() {
+  local major
+  local minor
+  local pdev
+       
+  major=$(stat -L -c %t "$1")
+  minor=$(stat -L -c %T "$1")
+  pdev=$(printf "0x%02x%02x" "0x$major" "0x$minor")
+  xenstore_write "$XENBUS_PATH"/physical-device "$pdev" \
+                 "$XENBUS_PATH"/node "$1"
+}

_______________________________________________
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®.