consistent iscsi devices under /dev

79 views
Skip to first unread message

Steve Wray

unread,
Jan 28, 2007, 3:02:02 PM1/28/07
to open-...@googlegroups.com
Hi there,
now that I have finally got my head around how iscsiadm works I may have
some things to contribute back to the group.

1. Consistent naming of iscsi devices under /dev using udev.
I have a file /etc/udev/rules.d/55-openiscsi.rules containing:

<55-openiscsi.rules
KERNEL=="sd*", BUS=="scsi", PROGRAM="/usr/local/sbin/iscsidev.sh
%b",SYMLINK+="iscsi/%c{1}/lun%c{2}/part%n"
</55-openiscsi.rules>


The script /usr/local/sbin/iscsidev.sh looks like this:

<iscsidev.sh>
#!/bin/sh

BUS=${1}
HOST=${BUS%%:*}

# This was the first thing I thought of, I'm sure it can be done better:
LUN=`echo ${BUS} | cut -d":" -f4`

[ -e /sys/class/iscsi_host ] || exit 1

file="/sys/class/iscsi_host/host${HOST}/device/session*/iscsi_session*/targetname"

target_name=$(cat ${file})

# This is not an open-scsi drive
if [ -z "${target_name}" ]; then
exit 1
fi

echo "${target_name} ${LUN}"
</iscsidev.sh>

What this does is create symlinks under:
/dev/iscsi/<targetname>/lun<lunID>/
to the kernel device nodes.

I can't take 100% credit as this was cobbled together from various hints
that I found all over the internet :)


2. Using iscsi with XEN for existing LVM logical volumes.

We have several root filesystems for many XEN hosts on logical volumes.
The format for these logical volumes is generally of the form:

/dev/volumes/hostname
/dev/volumes/hostname-swap

As things stand, these are used by XEN directly and have filesystem/swap
respectively.

I found that I can set up iscsi targets for these at two LUNs in the
same target:

Target iqn.2006-12.fileserver:hostname
Lun 0 Path=/dev/volumes/hostname,Type=fileio
Lun 1 Path=/dev/volumes/hostname-swap,Type=fileio
Alias hostname
IncomingUser hostname hostspassword


On the iscsi initiator end, using my udev config, these come out as:
/dev/iscsi/iqn.2006-12.fileserver:hostname/lun0/part
/dev/iscsi/iqn.2006-12.fileserver:hostname/lun1/part

and you can use these directly in the XEN configuration as:

disk = [
'phy:iscsi/iqn.2006-12.fileserver:hostname/lun0/part,sda1,w',
'phy:iscsi/iqn.2006-12.fileserver:hostname/lun1/part,sda2,w'
]

I was relieved to find that nothing minded having a filesystem directly
on an, eg, /dev/sdb device node with no partition.

XEN live migration works a treat and you don't lose the flexibility of
LVM by making partition tables on logical volumes (as you would if you
ran fdisk on the iscsi targets themselves). Plus you get to use existing
filesystems. So everyone wins.
:)


adrian...@shazamteam.com

unread,
Mar 2, 2007, 10:10:40 AM3/2/07
to open-iscsi
Hi Steve,

Thanks for posting this, it was exactly what i was looking for.

I to am trying to get my head round iscsiadm, took me a while to
realise that the devices were just standard names and could vary
between machines/hardware changes.

This solves the problem very neatly.

I hope someone picks this up and adds it to the open-iscsi install.

On Jan 28, 8:02 pm, Steve Wray <steve.w...@cwa.co.nz> wrote:
> Hi there,
> now that I have finally got my head around how iscsiadm works I may have
> some things to contribute back to the group.
>
> 1. Consistent naming of iscsi devices under /dev using udev.
> I have a file /etc/udev/rules.d/55-openiscsi.rules containing:
>
> <55-openiscsi.rules
> KERNEL=="sd*", BUS=="scsi", PROGRAM="/usr/local/sbin/iscsidev.sh
> %b",SYMLINK+="iscsi/%c{1}/lun%c{2}/part%n"
> </55-openiscsi.rules>
>
> The script /usr/local/sbin/iscsidev.sh looks like this:
>
> <iscsidev.sh>
> #!/bin/sh
>
> BUS=${1}
> HOST=${BUS%%:*}
>
> # This was the first thing I thought of, I'm sure it can be done better:
> LUN=`echo ${BUS} | cut -d":" -f4`
>
> [ -e /sys/class/iscsi_host ] || exit 1
>

> file="/sys/class/iscsi_host/host${HOST}/device/session*/iscsi_session*/targ­etname"

Reply all
Reply to author
Forward
0 new messages