From mboxrd@z Thu Jan 1 00:00:00 1970 From: Todd Deshane Date: Mon, 24 Jul 2006 14:25:59 +0000 Subject: Re: mapping device name to iscsi target Message-Id: <1153751159.15463.100.camel@localhost> List-Id: References: <1153630174.15463.45.camel@localhost> In-Reply-To: <1153630174.15463.45.camel@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: linux-hotplug@vger.kernel.org Hi All,=20 I have a working rule thanks to a response from Shawn Ferris.=20 here it is:=20 udev rule:=20 BUS=3D"scsi", PROGRAM=3D"/lib/udev/iscsidev.sh %b", SYMLINK+=3D"iscsi/%c/pa= rt% n"=20 iscsidev.sh script:=20 -------------------------------------------------------=20 #!/bin/sh=20 # Sample Path:=20 # /sys/class/scsi_host/host23/device/session19/iscsi_session:session19/targ= etname=20 BUS=3D${1}=20 HOST=3D${BUS%%:*}=20 file=3D"/sys/class/scsi_host/host=20 ${HOST}/device/session*/iscsi_session*/targetname"=20 # This is not an open-scsi drive=20 if [ -z "${file}" ]; then=20 exit 0=20 fi=20 target_name=3D$(cat ${file})=20 echo "${target_name}"=20 ---------------------------------------------------------=20 Notice that you could use the following line of code to dynamically=20 detect the sysfs root (i.e. /sys), but with a read only=20 environment /etc/mtab is disabled so I just hardcoded /sys as the sysfs=20 root=20 ---------------------------------------------------------=20 SYSFS=3D$(mount -t sysfs | awk '{print $3}' 2>/dev/null)=20 ----------------------------------------------------------=20 Maybe this will help someone else in the future. Todd=20 On Sun, 2006-07-23 at 00:49 -0400, Todd Deshane wrote: > Hi, >=20 > I know this topic has came up before on this list, but I still don't > have a reliable solution. >=20 > It was suggested to use the persistent device naming which comes with > udev: > http://www.kernel.org/git/?p=3Dlinux/hotplug/udev.git;a=3Dblob;f=3Detc/ud= ev/60-persistent-storage.rules >=20 > (see: > http://marc.theaimsgroup.com/?l=3Dlinux-hotplug-devel&m=115036155509938&w= =3D2 > for details) >=20 > since it gives the /dev/disk entries such as by-id,by-label and by-uuid, > but i am not sure how to map the uuid back to the iscsi target. > Has anyone done this successful or have any ideas? >=20 > Also, the idea of using the bus id %b seems like a good idea, (see this > thread: > http://marc.theaimsgroup.com/?l=3Dlinux-hotplug-devel&m=106928672620090&w= =3D2 > for details) but doesn't appear to be reliable enough: here is the code > if have for it so far for it: >=20 >=20 > I used the rule: > BUS=3D"scsi", PROGRAM=3D"/lib/udev/iscsidev %b" NAME=3D"%c%n" SYMLINK= =3D"%k" >=20 > with the /lib/udev/iscsidev script as follows: > #!/usr/bin/python > import sys > import os > import re >=20 > arg =3D sys.argv[1] > (targname,bus,targ,lun) =3D arg.split(':') > for targets in os.popen('/sbin/iscsiadm -m session','r').readlines(): > toMatch =3D re.compile('\[0*' + str(targname) + ':') > isMatch =3D toMatch.search(targets) > if(isMatch): > (head,addr,target_name) =3D targets.split(); > sys.stdout.write(target_name) >=20 > script is based off of the perl version in: > http://groups.google.com/group/open-iscsi/browse_thread/thread/bc050f805c= 8f85c/fb0ff969e8da7629?q=3Dudev&lnk=3Dgst&rnum=3D2#fb0ff969e8da7629 >=20 > In most cases this seems to work perfectly... it prints out the target > name and there is a nice mapping (targetname to actual device). However, > the problem seems to be that the bus id %b in the udev rule above can > get out of sync with targname in the script. >=20 > targname refers to the 'xx' in the output of the command iscsiadm -m > session > for example: > # iscsiadm -m session > [xx:] :,1 targetname >=20 > with a quick look at the source code the xx seems to refer to the > session id, which is not necessarily the same as the bus id, hence the > problem of out of sync. >=20 > So, what is the recommended way to get this mapping that > is reliable? >=20 > Any experience with this? ideas/suggestions? >=20 > Thanks in advance, > Todd >=20 >=20 > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share y= our > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=DE= VDEV > _______________________________________________ > Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net > Linux-hotplug-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=DEVD= EV _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel