ISCSI

From Segfault
Jump to: navigation, search

iSCSI target

Debian

The iSCSI target is the server, i.e. the node that actually serves the disk. We need a kernel with CONFIG_ISCSI_TARGET enabled:

Device Drivers

Generic Target Core Mod (CONFIG_TARGET_CORE)
iSCSI Target Mode Stack (CONFIG_ISCSI_TARGET)

If this is not the case, the distribution should provide the needed kernel module.

apt-get install iscsitarget iscsitarget-dkms linux-headers-`uname -r`   # Debian, Ubuntu
emerge sys-block/iscsitarget                                            # Gentoo

Enable & configure the target:

$ sed 's/false/true/' -i /etc/default/iscsitarget 
$ cat /etc/default/iscsitarget
ISCSITARGET_ENABLE=true
$ cat /etc/iet/ietd.conf
#iSNSServer 192.168.1.16
#iSNSAccessControl No

# IncomingUser: credentials the initiator has to provide
# OutgoingUser: credentials the target will provide
#IncomingUser joe secret
#OutgoingUser jack 12charsecret
 
# iqn.yyyy-mm.<reversed domain name>[:identifier]
Target iqn.2012-01.com.example.int:alice-sdc
      #IncomingUser joe secret
      #OutgoingUser jack 12charsecret
      Lun 0 Path=/dev/sdb,Type=fileio
      Lun 1 Path=/mnt/cdrom/install.iso,Type=fileio,IOMode=ro
$ service iscsitarget restart

$ cat /proc/net/iet/volume 
tid:1 name:iqn.2012-01.com.example.int:alice-sdc
      lun:0 state:0 iotype:fileio iomode:wt blocks:20971520 blocksize:512 path:/dev/sdc

$ cat /proc/net/iet/session 
tid:1 name:iqn.2012-01.com.example.int:alice-sdc

Fedora

Fedora's netbsd-iscsi is configured somehwat differently:

$ yum install netbsd-iscsi

$ cat /etc/iscsi/iscsid.conf
[...]
iscsid.startup = /etc/rc.d/init.d/iscsid force-start        # Comment to disable the target!
node.startup = automatic                                    # automatic, manual 
node.leading_login = No
# node.session.auth.authmethod = CHAP                       # none, CHAP
# node.session.auth.username = username
# node.session.auth.password = password

node.conn[0].iscsi.HeaderDigest = None                      # None, CRC32C
node.session.nr_sessions = 1
node.session.iscsi.FastAbort = Yes
$ cat /etc/iscsi/targets                                    # See targets(5)
# extents       file             start   length
extent0         /tmp/test.img    0       size
extent1         /dev/sdc         0       2GB
extent2         /dev/sdc         0       2GB

# device        resilience       extents
device0         RAID1            extent1,extent2

# target        flags   storage     netmask
target0=foo     rw      extent0     10.0.0.0/16
target1=bar     ro      device0     any

Start the target:

$ systemctl start netbsd-iscsi.service
$ iscsi-target -v all
Reading configuration from `/etc/iscsi/targets'
target0:rw:any
       extent0:/dev/sdb:0:0
pid 3708:util.c:110: iscsi_malloc_atomic(64) = 0x8e21008
DISK: 1 logical unit (0 blocks, 512 bytes/block), type iscsi fs
DISK: LUN 0: 0 MB disk storage for "target0"
TARGET: TargetName is iqn.1994-04.org.netbsd.iscsi-target

$ iscsiadm -m discovery -t st -p `hostname`
127.0.0.1:3260,1 foo
127.0.0.1:3260,2 bar

On Fedora the firewall has to be configured as well:

$ grep -C1 3260 /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3260 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited

$ systemctl restart iptables.service

iSCSI initiator

The iSCSI initiator is the client. We need a kernel with CONFIG_ISCSI_TCP=m set, "=y" might not work:

Device Drivers

SCSI device support
SCSI low-level drivers (SCSI_LOWLEVEL)
iSCSI Initiator over TCP/IP (CONFIG_ISCSI_TCP)
 apt-get install open-iscsi                  # Debian, Ubuntu
 
 emerge sys-block/open-iscsi                 # Gentoo
 rc-update add iscsid default
 $ iscsiadm -m discovery -t st -p alice
 10.0.0.30:3260,1 iqn.2012-01.com.example.int:alice-sdc
 
 $ iscsiadm -m node --targetname "iqn.2012-01.com.example.int:alice-sdc" --portal 10.0.0.30:3260 --login
 Logging in to [iface: default, target: iqn.2012-01.com.example.int:alice-sdc, portal: 10.0.0.30,3260]
 Login to [iface: default, target: iqn.2012-01.com.example.int:alice-sdc, portal: 10.0.0.30,3260]: successful
 $ dmesg
 [  452.304386] scsi3 : iSCSI Initiator over TCP/IP
 [  452.579688] scsi 3:0:0:0: Direct-Access     IET      VIRTUAL-DISK     0    PQ: 0 ANSI: 4
 [  452.592531] sd 3:0:0:0: [sdb] 20971520 512-byte logical blocks: (10.7 GB/10.0 GiB)
 [  452.593550] sd 3:0:0:0: [sdb] Write Protect is off
 [  452.593557] sd 3:0:0:0: [sdb] Mode Sense: 77 00 00 08
 [  452.595679] sd 3:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
 [  452.615505]  sdb: unknown partition table
 [  452.624290] sd 3:0:0:0: [sdb] Attached SCSI disk

Now /dev/sdb should be available on the initiator.

To release the iSCSI target:

 $ iscsiadm -m node --targetname "iqn.2012-01.com.example.int:alice-sdc" --portal 10.0.0.30:3260 --logout

Links