WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] block-iscsi RFC

To: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] block-iscsi RFC
From: Stefan de Konink <skinkie@xxxxxxxxx>
Date: Mon, 28 Jan 2008 22:22:21 +0100
Delivery-date: Mon, 28 Jan 2008 13:22:47 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.9 (X11/20071225)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

This version of block-iscsi is partly based on the work of Kurt Garloff.
But his code wasn't in a working state any more, and my own version was
working but used an stupid syntax based on udev.


I would like to have some feedback, maybe how the bash script can be
prettified.


Stefan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHnkeNYH1+F2Rqwn0RCpuxAKCQ26kxpnuD7bYOZgCzCoxo/riUEQCfdyN5
9+gc0d5tNcLbcDXsxVjJdSc=
=y/ip
-----END PGP SIGNATURE-----
#!/bin/bash

# Usage: block-iscsi

dir=$(dirname "$0")
. "$dir/block-common.sh"

# echo "DBG:xen/scripts/block-iscsi $1 $2 XENBUS_PATH=$XENBUS_PATH $par $node" 
>> /tmp/output.tmp

find_sdev()
{
  unset dev
  for session in /sys/class/iscsi_session/session*; do
    if [ "$1" = "`cat $session/targetname`" ]; then
      dev=`readlink $session/device/target*/*:0:*/block*`
      dev=${dev##*/}
      return
    fi
  done
}

find_sdev_rev()
{
  unset tgt
  for session in /sys/class/iscsi_session/session*; do
    dev=`readlink $session/device/target*/*:0:*/block*`
    dev=${dev##*/}
    if [ "$dev" = "$1" ]; then
      tgt=`cat $session/targetname`
      return
    fi
  done
}

case "$command" in
  add)
    # list of targets on node
    /usr/sbin/iscsiadm -m discovery | sed "s/ .*//g" | while read line; do 
/usr/sbin/iscsiadm -m discovery -t sendtargets -p $line; done >/dev/null
    par=`xenstore-read $XENBUS_PATH/params` || true
    TGTID=`echo $par | sed "s/\/\///g"`
    while read rec uuid; do
      if [ "$uuid" = "$TGTID" ]; then
        find_sdev $TGTID
        if [ -z "$dev" ]; then
          /usr/sbin/iscsiadm -m node -T $uuid -p $rec --login || exit 2
          sleep 4
          find_sdev $TGTID
        fi
        xenstore-write $XENBUS_PATH/node /dev/$dev
        write_dev /dev/$dev
        exit 0
      fi
    done < <(/usr/sbin/iscsiadm -m node)
    exit 1
    ;;

  remove)
    node=`xenstore-read $XENBUS_PATH/node` || true
    dev=$node; dev=${dev#/dev/}
    find_sdev_rev $dev
    if [ -x /sbin/blockdev -a -n "$node"; then blockdev --flushbufs "$node" ]; 
fi
    test -z "$tgt" && exit 2
    /usr/sbin/iscsiadm -m node -T $tgt --logout
    exit 1
    ;;
esac
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] block-iscsi RFC, Stefan de Konink <=