mirror of
https://github.com/xen-project/xen.git
synced 2026-10-30 03:00:05 +01:00
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@xensource.com>
This commit is contained in:
1 parent
902a84f59f
commit
a8a1d48e4c
5 files changed
+64
-38
No files matched your search
@@ -24,8 +24,9 @@ XEN_SCRIPTS = network-bridge vif-bridge
|
||||
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
|
||||
|
||||
+2
-14
@@ -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 @@ expand_dev() {
|
||||
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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -2,25 +2,19 @@
|
||||
|
||||
# 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
|
||||
|
||||
@@ -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
|
||||
|
||||