hotplug/Linux: add iscsi block hotplug script
PATCH 1/1 hotplug/Linux: add iscsi block hotplug script
This hotplug script has been tested with IET and NetBSD iSCSI targets, without authentication.
This hotplug script will only work with PV guests not using pygrub.
---
Changes due to 4.3 release freeze:
* We can no longer provide a user/password, because they will be stored in xenstore "params" backend node, which can be read by the guest.
* Only works with PV domains because we don't have a hook in libxl to pass the block device created by the script to Qemu.
* Doesn't work with pygrub because we don't call the script until pygrub has already been executed, and even if we called it earlier we still need a hook in order to provide the right block device to pygrub.
Changes since v1:
* Add -e to script shebang, and use 'set +e' if we know hotplug execution might fail.
--- tools/hotplug/Linux/Makefile | 1 + tools/hotplug/Linux/block-iscsi | 198 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+), 0 deletions(-) create mode 100644 tools/hotplug/Linux/block-iscsi
tools/hotplug/Linux/Makefile +1 -0
@@ -21,6 +21,7 @@ XEN_SCRIPTS += blktap XEN_SCRIPTS += xen-hotplug-cleanup XEN_SCRIPTS += external-device-migrate XEN_SCRIPTS += vscsi +XEN_SCRIPTS += block-iscsi XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh XEN_SCRIPT_DATA += block-common.sh
tools/hotplug/Linux/block-iscsi new file +198 -0
198 lines not on this page · raw message
Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 4 lines · Roger Pau Monne
This hotplug script has been tested with IET and NetBSD iSCSI targets, without authentication.
This hotplug script will only work with PV guests not using pygrub.
Thanks. Does this need any docs somewhere, e.g. how to format the target spec?
Is this derived from any of the other block-iscsi scripts floating around on the net?
Quoted 41 lines
Signed-off-by Roger Pau Monné <[email protected]>Cc Ian Campbell <[email protected]>Cc Ian Jackson <[email protected]>---
Changes due to 4.3 release freeze:
* We can no longer provide a user/password, because they will be stored in xenstore "params" backend node, which can be read by the guest.
* Only works with PV domains because we don't have a hook in libxl to pass the block device created by the script to Qemu.
* Doesn't work with pygrub because we don't call the script until pygrub has already been executed, and even if we called it earlier we still need a hook in order to provide the right block device to pygrub.
Changes since v1:
* Add -e to script shebang, and use 'set +e' if we know hotplug execution might fail.--- tools/hotplug/Linux/Makefile | 1 + tools/hotplug/Linux/block-iscsi | 198 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+), 0 deletions(-) create mode 100644 tools/hotplug/Linux/block-iscsitools/hotplug/Linux/Makefile +1
-0@@ -21,6 +21,7 @@ XEN_SCRIPTS += blktap XEN_SCRIPTS += xen-hotplug-cleanup XEN_SCRIPTS += external-device-migrate XEN_SCRIPTS += vscsi +XEN_SCRIPTS += block-iscsi XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh XEN_SCRIPT_DATA += block-common.shtools/hotplug/Linux/block-iscsi new file +0
-0
tools/hotplug/Linux/block-iscsi line 1
Quoted 1 line
tools/hotplug/Linux/block-iscsi new file +1
-0@@ -0,0 +1,198 @@ +#!/bin/sh -e
Does this rely on any bashisms? Most of the other scripts use bash here, and I'd be a bit worried about bashisms in the common code.
Quoted 13 lines
tools/hotplug/Linux/block-iscsi new file +13
-0+# +# Open-iSCSI Xen block device hotplug script +# +# Author Roger Pau Monné <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; version 2.1 only. with the special +# exception on linking described in file LICENSE. +# +# This program 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
tools/hotplug/Linux/block-iscsi line 24
Quoted 10 lines
tools/hotplug/Linux/block-iscsi new file +10
-0+# GNU Lesser General Public License for more details. + +remove_label() +{ + echo $1 | sed "s/^\("$2"\)//" +} + +check_tools() +{ + if ! type iscsiadm > /dev/null 2>&1; then
apparently command -v is more portable?
tools/hotplug/Linux/block-iscsi line 26
Quoted 2 lines
tools/hotplug/Linux/block-iscsi new file +2
-0+ echo "Unable to find iscsiadm tool" + return 1
Error paths should use fatal() from xen-hotplug-common.sh so the error is propagated to xenstore and libxl can print it.
Quoted 33 lines
tools/hotplug/Linux/block-iscsi new file +33
-0+ fi + if [ "$multipath" = "y" ] && ! type multipath > /dev/null 2>&1; then + echo "Unable to find multipath" + return 1 + fi +} + +# Sets the following global variables based on the params field passed in as +# a parameter: iqn, portal, auth_method, user, multipath, password +parse_target() +{ + # set multipath default value + multipath="n" + for param in $(echo "$1" | tr "," "\n") + do + case $param in + iqn=*) + iqn=$(remove_label $param "iqn=") + ;; + portal=*) + portal=$(remove_label $param "portal=") + ;; + multipath=*) + multipath=$(remove_label $param "multipath=") + ;; + esac + done + if [ -z "$iqn" ] || [ -z "$portal" ]; then + echo "iqn= and portal= are required parameters" + return 1 + fi + if [ "$multipath" != "y" ] && [ "$multipath" != "n" ]; then + echo "multipath valid values are y and n, $multipath not a valid value"
tools/hotplug/Linux/block-iscsi line 69
Quoted 10 lines
tools/hotplug/Linux/block-iscsi new file +10
-0+ return 1 + fi + return 0 +} + +# Outputs the block device major:minor +device_major_minor() +{ + stat -L -c %t:%T "$1" +}
Could use block-common.sh provided functionality here.
tools/hotplug/Linux/block-iscsi line 76
Quoted 7 lines
tools/hotplug/Linux/block-iscsi new file +7
-0+ +# Sets $dev to point to the device associated with the value in iqn +find_device() +{ + while [ ! -e /dev/disk/by-path/*"$iqn"-lun-0 ]; do + sleep 0.1 + done
This loop is potentially infinite? (i.e. if something is broken)
tools/hotplug/Linux/block-iscsi line 79
Quoted 3 lines
tools/hotplug/Linux/block-iscsi new file +3
-0+ set +e + sddev=$(readlink -f /dev/disk/by-path/*"$iqn"-lun-0) + set -e
Can't you just to || true instead of frobbing +/-e? Or use do_without_error?
Quoted 13 lines
tools/hotplug/Linux/block-iscsi new file +13
-0+ if [ ! -b "$sddev" ]; then + echo "Unable to find attached device path" + return 1 + fi + if [ "$multipath" = "y" ]; then + mdev=$(multipath -ll "$sddev" | head -1 | awk '{ print $1}') + if [ ! -b /dev/mapper/"$mdev" ]; then + echo "Unable to find attached device multipath" + return 1 + fi + dev="/dev/mapper/$mdev" + else + dev="$sddev"
tools/hotplug/Linux/block-iscsi line 102
Quoted 10 lines
tools/hotplug/Linux/block-iscsi new file +10
-0+ fi + return 0 +} + +# Attaches the target $iqn in $portal and sets $dev to point to the +# multipath device +attach() +{ + set +e + iscsiadm -m node --targetname "$iqn" -p "$portal" --login > /dev/null 2>&1
Might the error message be useful here? if you don't redirect to /dev/null then you can use exec >>/tmp/hotplug.log tricks to debug things...
Quoted 40 lines
tools/hotplug/Linux/block-iscsi new file +40
-0+ rc=$? + set -e + if [ $rc -ne 0 ]; then + echo "Unable to connect to target" + return 1 + fi + find_device + if [ $? -ne 0 ]; then + echo "Unable to find iSCSI device" + return 1 + fi + return 0 +} + +# Discovers targets in $portal and checks that $iqn is one of those targets +# Also sets the auth parameters to attach the device +prepare() +{ + # Check if target is already opened + set +e + iscsiadm -m session 2>&1 | grep -q "$iqn" + rc=$? + set -e + if [ $rc -eq 0 ]; then + echo "Device already opened" + return 1 + fi + # Discover portal targets + set +e + iscsiadm -m discovery -t st -p $portal 2>&1 | grep -q "$iqn" + rc=$? + set -e + if [ $rc -ne 0 ]; then + echo "No matching target iqn found" + return 1 + fi + return 0 +} + +# Attaches the device and writes xenstore backend entries to connect
tools/hotplug/Linux/block-iscsi line 152
Quoted 10 lines
tools/hotplug/Linux/block-iscsi new file +10
-0+# the device +add() +{ + attach + if [ $? -ne 0 ]; then + echo "Failed to attach device" + return 1 + fi + mm=$(device_major_minor "$dev") + xenstore-write "$XENBUS_PATH/physical-device" "$mm"
this == write_dev
Quoted 35 lines
tools/hotplug/Linux/block-iscsi new file +35
-0+ return 0 +} + +# Disconnects the device +remove() +{ + find_device + if [ $? -ne 0 ]; then + echo "Unable to find device" + return 1 + fi + set +e + iscsiadm -m node --targetname "$iqn" -p "$portal" --logout > /dev/null 2>&1 + rc=$? + set -e + if [ $rc -ne 0 ]; then + echo "Unable to disconnect target" + return 1 + fi + return 0 +} + +command=$1 +set +e +target=$(xenstore-read $XENBUS_PATH/params) +set -e +if [ -z "$target" ]; then + echo "No information about the target" + exit 1 +fi + +parse_target "$target" + +check_tools || exit 1 +
tools/hotplug/Linux/block-iscsi line 197
Quoted 10 lines
tools/hotplug/Linux/block-iscsi new file +10
-0+case $command in +add) + prepare + add + exit $? + ;; +remove) + remove + exit $? + ;;
exit 1 for the default case?
tools/hotplug/Linux/block-iscsi line 198
Quoted 1 line
tools/hotplug/Linux/block-iscsi new file +1
-0+esac
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 49 lines · Ian Campbell
Quoted 4 lines · Roger Pau Monne
This hotplug script has been tested with IET and NetBSD iSCSI targets, without authentication.
This hotplug script will only work with PV guests not using pygrub.
Thanks. Does this need any docs somewhere, e.g. how to format the target spec?
Is this derived from any of the other block-iscsi scripts floating around on the net?
Quoted 37 lines
Signed-off-by Roger Pau Monné <[email protected]>Cc Ian Campbell <[email protected]>Cc Ian Jackson <[email protected]>---
Changes due to 4.3 release freeze:
* We can no longer provide a user/password, because they will be stored in xenstore "params" backend node, which can be read by the guest.
* Only works with PV domains because we don't have a hook in libxl to pass the block device created by the script to Qemu.
* Doesn't work with pygrub because we don't call the script until pygrub has already been executed, and even if we called it earlier we still need a hook in order to provide the right block device to pygrub.
Changes since v1:
* Add -e to script shebang, and use 'set +e' if we know hotplug execution might fail.--- tools/hotplug/Linux/Makefile | 1 + tools/hotplug/Linux/block-iscsi | 198 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+), 0 deletions(-) create mode 100644 tools/hotplug/Linux/block-iscsitools/hotplug/Linux/Makefile +1
-0@@ -21,6 +21,7 @@ XEN_SCRIPTS += blktap XEN_SCRIPTS += xen-hotplug-cleanup XEN_SCRIPTS += external-device-migrate XEN_SCRIPTS += vscsi +XEN_SCRIPTS += block-iscsi XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh XEN_SCRIPT_DATA += block-common.shtools/hotplug/Linux/block-iscsi new file +0
-0
Quoted 8 lines
tools/hotplug/Linux/block-iscsi line 1
Quoted 5 lines
index 0000000..3cd6e34
tools/hotplug/Linux/block-iscsi new file +1
-0@@ -0,0 +1,198 @@ +#!/bin/sh -eDoes this rely on any bashisms? Most of the other scripts use bash here, and I'd be a bit worried about bashisms in the common code.
This script originally didn't use any bashisms, but if I include block-common.sh I have to use bash for sure.
Quoted 18 lines
Quoted 18 lines
tools/hotplug/Linux/block-iscsi new file +17
-0+# +# Open-iSCSI Xen block device hotplug script +# +# Author Roger Pau Monné <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; version 2.1 only. with the special +# exception on linking described in file LICENSE. +# +# This program 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. + +remove_label() +{
Quoted 8 lines
tools/hotplug/Linux/block-iscsi line 24
Quoted 6 lines
tools/hotplug/Linux/block-iscsi new file +6
-0+ echo $1 | sed "s/^\("$2"\)//" +} + +check_tools() +{ + if ! type iscsiadm > /dev/null 2>&1; thenapparently command -v is more portable?
OK, I have no preference.
Quoted 6 lines
tools/hotplug/Linux/block-iscsi line 26
Quoted 3 lines
tools/hotplug/Linux/block-iscsi new file +2
-0+ echo "Unable to find iscsiadm tool" + return 1Error paths should use
fatal()fromxen-hotplug-common.shso the error is propagated to xenstore and libxl can print it.
Yes, if we call the script directly from libxl the output form the script will be logged by libxl, but since this script can also be called from udev I have to use fatal.
Quoted 37 lines
Quoted 37 lines
tools/hotplug/Linux/block-iscsi new file +37
-0+ fi + if [ "$multipath" = "y" ] && ! type multipath > /dev/null 2>&1; then + echo "Unable to find multipath" + return 1 + fi +} + +# Sets the following global variables based on the params field passed in as +# a parameter: iqn, portal, auth_method, user, multipath, password +parse_target() +{ + # set multipath default value + multipath="n" + for param in $(echo "$1" | tr "," "\n") + do + case $param in + iqn=*) + iqn=$(remove_label $param "iqn=") + ;; + portal=*) + portal=$(remove_label $param "portal=") + ;; + multipath=*) + multipath=$(remove_label $param "multipath=") + ;; + esac + done + if [ -z "$iqn" ] || [ -z "$portal" ]; then + echo "iqn= and portal= are required parameters" + return 1 + fi + if [ "$multipath" != "y" ] && [ "$multipath" != "n" ]; then + echo "multipath valid values are y and n, $multipath not a valid value" + return 1 + fi + return 0 +}
Quoted 8 lines
tools/hotplug/Linux/block-iscsi line 69
Quoted 6 lines
tools/hotplug/Linux/block-iscsi new file +6
-0+ +# Outputs the block device major:minor +device_major_minor() +{ + stat -L -c %t:%T "$1" +}Could use
block-common.shprovided functionality here.
I've removed this and used write_dev instead.
Quoted 10 lines
tools/hotplug/Linux/block-iscsi line 76
Quoted 8 lines
tools/hotplug/Linux/block-iscsi new file +7
-0+ +# Sets $dev to point to the device associated with the value in iqn +find_device() +{ + while [ ! -e /dev/disk/by-path/*"$iqn"-lun-0 ]; do + sleep 0.1 + doneThis loop is potentially infinite? (i.e. if something is broken)
Yes, I was trusting the timeout in libxl to prevent that, but again since this is not using the new calling convention it should work properly with udev and I have no idea if udev has a timeout, but we shouldn't rely on that.
Quoted 7 lines
tools/hotplug/Linux/block-iscsi line 79
Quoted 4 lines
tools/hotplug/Linux/block-iscsi new file +3
-0+ set +e + sddev=$(readlink -f /dev/disk/by-path/*"$iqn"-lun-0) + set -eCan't you just to || true instead of frobbing +/-e? Or use
do_without_error?
|| true seems appropriate in this case.
Quoted 19 lines
Quoted 19 lines
tools/hotplug/Linux/block-iscsi new file +19
-0+ if [ ! -b "$sddev" ]; then + echo "Unable to find attached device path" + return 1 + fi + if [ "$multipath" = "y" ]; then + mdev=$(multipath -ll "$sddev" | head -1 | awk '{ print $1}') + if [ ! -b /dev/mapper/"$mdev" ]; then + echo "Unable to find attached device multipath" + return 1 + fi + dev="/dev/mapper/$mdev" + else + dev="$sddev" + fi + return 0 +} + +# Attaches the target $iqn in $portal and sets $dev to point to the +# multipath device
Quoted 8 lines
tools/hotplug/Linux/block-iscsi line 102
Quoted 4 lines
tools/hotplug/Linux/block-iscsi new file +4
-0+attach() +{ + set +e + iscsiadm -m node --targetname "$iqn" -p "$portal" --login > /dev/null 2>&1Might the error message be useful here? if you don't redirect to
/dev/nullthen you can use exec >>/tmp/hotplug.log tricks to debug things...
iscsiadm always prints output, even when the target is successfully attached, and I haven't found any option to prevent it, so for now I guess we will have to redirect it to /dev/null
Quoted 45 lines
Quoted 45 lines
tools/hotplug/Linux/block-iscsi new file +44
-0+ rc=$? + set -e + if [ $rc -ne 0 ]; then + echo "Unable to connect to target" + return 1 + fi + find_device + if [ $? -ne 0 ]; then + echo "Unable to find iSCSI device" + return 1 + fi + return 0 +} + +# Discovers targets in $portal and checks that $iqn is one of those targets +# Also sets the auth parameters to attach the device +prepare() +{ + # Check if target is already opened + set +e + iscsiadm -m session 2>&1 | grep -q "$iqn" + rc=$? + set -e + if [ $rc -eq 0 ]; then + echo "Device already opened" + return 1 + fi + # Discover portal targets + set +e + iscsiadm -m discovery -t st -p $portal 2>&1 | grep -q "$iqn" + rc=$? + set -e + if [ $rc -ne 0 ]; then + echo "No matching target iqn found" + return 1 + fi + return 0 +} + +# Attaches the device and writes xenstore backend entries to connect +# the device +add() +{ + attach
Quoted 8 lines
tools/hotplug/Linux/block-iscsi line 152
Quoted 6 lines
tools/hotplug/Linux/block-iscsi new file +6
-0+ if [ $? -ne 0 ]; then + echo "Failed to attach device" + return 1 + fi + mm=$(device_major_minor "$dev") + xenstore-write "$XENBUS_PATH/physical-device" "$mm"this ==
write_dev
Done
Quoted 40 lines
Quoted 40 lines
tools/hotplug/Linux/block-iscsi new file +39
-0+ return 0 +} + +# Disconnects the device +remove() +{ + find_device + if [ $? -ne 0 ]; then + echo "Unable to find device" + return 1 + fi + set +e + iscsiadm -m node --targetname "$iqn" -p "$portal" --logout > /dev/null 2>&1 + rc=$? + set -e + if [ $rc -ne 0 ]; then + echo "Unable to disconnect target" + return 1 + fi + return 0 +} + +command=$1 +set +e +target=$(xenstore-read $XENBUS_PATH/params) +set -e +if [ -z "$target" ]; then + echo "No information about the target" + exit 1 +fi + +parse_target "$target" + +check_tools || exit 1 + +case $command in +add) + prepare + add
Quoted 8 lines
tools/hotplug/Linux/block-iscsi line 197
Quoted 6 lines
tools/hotplug/Linux/block-iscsi new file +6
-0+ exit $? + ;; +remove) + remove + exit $? + ;;exit 1 for the default case?
Yes
Quoted 3 lines
tools/hotplug/Linux/block-iscsi line 198
Quoted 1 line
tools/hotplug/Linux/block-iscsi new file +1
-0+esac
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 9 lines · Roger Pau Monné
Quoted 8 lines · Ian Campbell
Quoted 4 lines · Roger Pau Monne
This hotplug script has been tested with IET and NetBSD iSCSI targets, without authentication.
This hotplug script will only work with PV guests not using pygrub.
Thanks. Does this need any docs somewhere, e.g. how to format the target spec?
Maybe an example in docs/misc/xl-disk-configuration.txt?
I'm not really sure where's the best place to put it, any recommendations?
Quoted 2 lines
Quoted 2 lines
Is this derived from any of the other block-iscsi scripts floating around on the net?
Not really, I've taken a look at other scripts, but decided to start it from scratch.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 6 lines · Roger Pau Monne
Quoted 5 lines · Roger Pau Monné
Quoted 4 lines · Ian Campbell
Quoted 3 lines · Roger Pau Monne
This hotplug script has been tested with IET and NetBSD iSCSI targets, without authentication.
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
This hotplug script will only work with PV guests not using pygrub.
Thanks. Does this need any docs somewhere, e.g. how to format the target spec?
Maybe an example in
docs/misc/xl-disk-configuration.txt?
I think this one is a documentation of the syntax in general and the examples are there to serve as examples of that rather than specific configurations.
Quoted 1 line
I'm not really sure where's the best place to put it, any recommendations?
A new docs/misc/*iscsi*.markdown?
Perhaps a more comprehensive wiki howto too?
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Is this derived from any of the other block-iscsi scripts floating around on the net?
Not really, I've taken a look at other scripts, but decided to start it from scratch.
OK.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 59 lines · Roger Pau Monne
Quoted 49 lines · Ian Campbell
Quoted 4 lines · Roger Pau Monne
This hotplug script has been tested with IET and NetBSD iSCSI targets, without authentication.
This hotplug script will only work with PV guests not using pygrub.
Thanks. Does this need any docs somewhere, e.g. how to format the target spec?
Is this derived from any of the other block-iscsi scripts floating around on the net?
Quoted 37 lines
Signed-off-by Roger Pau Monné <[email protected]>Cc Ian Campbell <[email protected]>Cc Ian Jackson <[email protected]>---
Changes due to 4.3 release freeze:
* We can no longer provide a user/password, because they will be stored in xenstore "params" backend node, which can be read by the guest.
* Only works with PV domains because we don't have a hook in libxl to pass the block device created by the script to Qemu.
* Doesn't work with pygrub because we don't call the script until pygrub has already been executed, and even if we called it earlier we still need a hook in order to provide the right block device to pygrub.
Changes since v1:
* Add -e to script shebang, and use 'set +e' if we know hotplug execution might fail.--- tools/hotplug/Linux/Makefile | 1 + tools/hotplug/Linux/block-iscsi | 198 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+), 0 deletions(-) create mode 100644 tools/hotplug/Linux/block-iscsitools/hotplug/Linux/Makefile +1
-0@@ -21,6 +21,7 @@ XEN_SCRIPTS += blktap XEN_SCRIPTS += xen-hotplug-cleanup XEN_SCRIPTS += external-device-migrate XEN_SCRIPTS += vscsi +XEN_SCRIPTS += block-iscsi XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh XEN_SCRIPT_DATA += block-common.shtools/hotplug/Linux/block-iscsi new file +0
-0Quoted 8 lines
tools/hotplug/Linux/block-iscsi line 1
Quoted 5 lines
index 0000000..3cd6e34
tools/hotplug/Linux/block-iscsi new file +1
-0@@ -0,0 +1,198 @@ +#!/bin/sh -eDoes this rely on any bashisms? Most of the other scripts use bash here, and I'd be a bit worried about bashisms in the common code.
Quoted 2 lines
This script originally didn't use any bashisms, but if I include
block-common.shI have to use bash for sure.
I think I would prefer using the library functions over avoiding bash.
If someone hates bash that much they should port the library over too ;-)
Quoted 9 lines
Quoted 6 lines
tools/hotplug/Linux/block-iscsi line 3
Quoted 3 lines
tools/hotplug/Linux/block-iscsi new file +2
-0+ echo "Unable to find iscsiadm tool" + return 1Error paths should use
fatal()fromxen-hotplug-common.shso the error is propagated to xenstore and libxl can print it.Yes, if we call the script directly from libxl the output form the script will be logged by libxl,
Actually logged or just sent to stdout which libxl hasn't interfered with? or does libxl suck in the stdout of the script? It looks to me like libxl does the former.
Quoted 1 line
but since this script can also be called from udev I have to use fatal.
I think even for libxl, since it writes the error node which libxl does then log.
Quoted 11 lines
Quoted 10 lines
tools/hotplug/Linux/block-iscsi line 76
Quoted 8 lines
tools/hotplug/Linux/block-iscsi new file +7
-0+ +# Sets $dev to point to the device associated with the value in iqn +find_device() +{ + while [ ! -e /dev/disk/by-path/*"$iqn"-lun-0 ]; do + sleep 0.1 + doneThis loop is potentially infinite? (i.e. if something is broken)
Quoted 4 lines
Yes, I was trusting the timeout in libxl to prevent that, but again since this is not using the new calling convention it should work properly with udev and I have no idea if udev has a timeout, but we shouldn't rely on that.
Good.
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
tools/hotplug/Linux/block-iscsi new file +19
-0+ if [ ! -b "$sddev" ]; then + echo "Unable to find attached device path" + return 1 + fi + if [ "$multipath" = "y" ]; then + mdev=$(multipath -ll "$sddev" | head -1 | awk '{ print $1}') + if [ ! -b /dev/mapper/"$mdev" ]; then + echo "Unable to find attached device multipath" + return 1 + fi + dev="/dev/mapper/$mdev" + else + dev="$sddev" + fi + return 0 +} + +# Attaches the target $iqn in $portal and sets $dev to point to the +# multipath deviceQuoted 8 lines
tools/hotplug/Linux/block-iscsi line 102
Quoted 4 lines
tools/hotplug/Linux/block-iscsi new file +4
-0+attach() +{ + set +e + iscsiadm -m node --targetname "$iqn" -p "$portal" --login > /dev/null 2>&1Might the error message be useful here? if you don't redirect to
/dev/nullthen you can use exec >>/tmp/hotplug.log tricks to debug things...
Quoted 3 lines
iscsiadm always prints output, even when the target is successfully attached, and I haven't found any option to prevent it, so for now I guess we will have to redirect it to
/dev/null
Does it produce output on stderr even on success too? i.e. can we just redirect stdout? In a sane world the useful error messages would be on stderr ;-)
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 78 lines · Ian Campbell
Quoted 59 lines · Roger Pau Monne
Quoted 49 lines · Ian Campbell
Quoted 4 lines · Roger Pau Monne
This hotplug script has been tested with IET and NetBSD iSCSI targets, without authentication.
This hotplug script will only work with PV guests not using pygrub.
Thanks. Does this need any docs somewhere, e.g. how to format the target spec?
Is this derived from any of the other block-iscsi scripts floating around on the net?
Quoted 37 lines
Signed-off-by Roger Pau Monné <[email protected]>Cc Ian Campbell <[email protected]>Cc Ian Jackson <[email protected]>---
Changes due to 4.3 release freeze:
* We can no longer provide a user/password, because they will be stored in xenstore "params" backend node, which can be read by the guest.
* Only works with PV domains because we don't have a hook in libxl to pass the block device created by the script to Qemu.
* Doesn't work with pygrub because we don't call the script until pygrub has already been executed, and even if we called it earlier we still need a hook in order to provide the right block device to pygrub.
Changes since v1:
* Add -e to script shebang, and use 'set +e' if we know hotplug execution might fail.--- tools/hotplug/Linux/Makefile | 1 + tools/hotplug/Linux/block-iscsi | 198 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+), 0 deletions(-) create mode 100644 tools/hotplug/Linux/block-iscsitools/hotplug/Linux/Makefile +1
-0@@ -21,6 +21,7 @@ XEN_SCRIPTS += blktap XEN_SCRIPTS += xen-hotplug-cleanup XEN_SCRIPTS += external-device-migrate XEN_SCRIPTS += vscsi +XEN_SCRIPTS += block-iscsi XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh XEN_SCRIPT_DATA += block-common.shtools/hotplug/Linux/block-iscsi new file +0
-0Quoted 8 lines
tools/hotplug/Linux/block-iscsi line 1
Quoted 5 lines
index 0000000..3cd6e34
tools/hotplug/Linux/block-iscsi new file +1
-0@@ -0,0 +1,198 @@ +#!/bin/sh -eDoes this rely on any bashisms? Most of the other scripts use bash here, and I'd be a bit worried about bashisms in the common code.
Quoted 2 lines
This script originally didn't use any bashisms, but if I include
block-common.shI have to use bash for sure.I think I would prefer using the library functions over avoiding bash.
If someone hates bash that much they should port the library over too ;-)
Quoted 9 lines
Quoted 6 lines
tools/hotplug/Linux/block-iscsi line 3
Quoted 3 lines
tools/hotplug/Linux/block-iscsi new file +2
-0+ echo "Unable to find iscsiadm tool" + return 1Error paths should use
fatal()fromxen-hotplug-common.shso the error is propagated to xenstore and libxl can print it.Yes, if we call the script directly from libxl the output form the script will be logged by libxl,
Quoted 8 lines
Actually logged or just sent to stdout which libxl hasn't interfered with? or does libxl suck in the stdout of the script? It looks to me like libxl does the former.
Quoted 1 line
but since this script can also be called from udev I have to use fatal.
I think even for libxl, since it writes the error node which libxl does then log.
Yes, libxl checks the node, so it's better to use fatal/log and all this functions instead of printing to stdout/stderr.
Quoted 47 lines
Quoted 12 lines
Quoted 11 lines
tools/hotplug/Linux/block-iscsi line 76
Quoted 9 lines
tools/hotplug/Linux/block-iscsi new file +7
-0+ +# Sets $dev to point to the device associated with the value in iqn +find_device() +{ + while [ ! -e /dev/disk/by-path/*"$iqn"-lun-0 ]; do + sleep 0.1 + doneThis loop is potentially infinite? (i.e. if something is broken)
Quoted 4 lines
Yes, I was trusting the timeout in libxl to prevent that, but again since this is not using the new calling convention it should work properly with udev and I have no idea if udev has a timeout, but we shouldn't rely on that.
Good.
Quoted 28 lines
Quoted 27 lines
Quoted 13 lines
tools/hotplug/Linux/block-iscsi new file +13
-0+ if [ ! -b "$sddev" ]; then + echo "Unable to find attached device path" + return 1 + fi + if [ "$multipath" = "y" ]; then + mdev=$(multipath -ll "$sddev" | head -1 | awk '{ print $1}') + if [ ! -b /dev/mapper/"$mdev" ]; then + echo "Unable to find attached device multipath" + return 1 + fi + dev="/dev/mapper/$mdev" + else + dev="$sddev"tools/hotplug/Linux/block-iscsi line 102
Quoted 10 lines
tools/hotplug/Linux/block-iscsi new file +10
-0+ fi + return 0 +} + +# Attaches the target $iqn in $portal and sets $dev to point to the +# multipath device +attach() +{ + set +e + iscsiadm -m node --targetname "$iqn" -p "$portal" --login > /dev/null 2>&1Might the error message be useful here? if you don't redirect to
/dev/nullthen you can use exec >>/tmp/hotplug.log tricks to debug things...
Quoted 7 lines
Quoted 3 lines
iscsiadm always prints output, even when the target is successfully attached, and I haven't found any option to prevent it, so for now I guess we will have to redirect it to
/dev/nullDoes it produce output on stderr even on success too? i.e. can we just redirect stdout? In a sane world the useful error messages would be on stderr ;-)
Mmmm, good point, yes, I can redirect stdout only.
Quoted 3 lines
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 15 lines
Quoted 15 lines
Quoted 10 lines
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +2
-0+ echo "Unable to find iscsiadm tool" + return 1Error paths should use
fatal()fromxen-hotplug-common.shso the error is propagated to xenstore and libxl can print it.Yes, if we call the script directly from libxl the output form the script will be logged by libxl,
Actually logged or just sent to stdout which libxl hasn't interfered with? or does libxl suck in the stdout of the script? It looks to me like libxl does the former.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
but since this script can also be called from udev I have to use fatal.
I think even for libxl, since it writes the error node which libxl does then log.
Yes, libxl checks the node, so it's better to use fatal/log and all this functions instead of printing to stdout/stderr.
Agreed.
Slurping hotplug script output into a debug log file might actually be a useful thing for the TODO list though.
Ian.