Monday, April 23, 2012

SCSI-3 Persist Reservation Command on Linux

Note: Linux sg3_utils packages are required.

To query all registrant keys for given device
#sg_persist -i -k -d /dev/sdd

To query all reservations for given device
#sg_persist -i -r -d /dev/sdd

To register
#sg_persist -o -G -S 123abc /dev/sdd

To clear all registrants
#sg_persist -C -K 123abc -o -d /dev/sdd

To reserve
#sg_persist -o -R -K 123abc -T 5 -d /dev/sdd

To release
#sg_persist -o -L -K 123abc -T 5 -d /dev/sdd

Common used reservation Types:
5 - Write Exclusive, registrants only
6 - Exclusive Access, registrants only

Setup iSCSI Target with iscsi-scst 2.0

Environment: Ubuntu 11.04 for i386

1) Install Linux kernel with scst patches(See my post on how to compile scst patched Linux kernel)

$sudo dpkg -i linux-headers-3.0.22-scstcustom_3.0.22-scstcustom-10.00.Custom_i386.deb
$sudo dpkg -i linux-image-3.0.22-scstcustom_3.0.22-scstcustom-10.00.Custom_i386.deb
Edit /boot/grub/grub.cfg to enable new kernel and reboot the host

2) Build scst and iscsi-scst against the new kernel

$cd ~/scst
$sudo make scst scst_install iscsi-scst iscsi_install scstadmin scstadmin_install

See iscsi-scst/README and iscsi-scst/doc for detailed instructions for iscsi-scst compile and configuration introduction.

3) Setup iSCSI target with 2 LUNs (based on iscsi-scst)
$ su
Password:
# modprobe scst
# modprobe scst_vdisk
# echo "add_device disk1 filename=/home/hui/vdisk1; nv_cache=1" >/sys/kernel/scst_tgt/handlers/vdisk_fileio/mgmt
# echo "add_device disk2 filename=/home/hui/vdisk2; nv_cache=1" >/sys/kernel/scst_tgt/handlers/vdisk_fileio/mgmt
# modprobe iscsi_scst
# iscsi-scstd
# echo "add_target iqn.2006-10.net.vlnb:tgt" >/sys/kernel/scst_tgt/targets/iscsi/mgmt
# echo "add disk1 0" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.vlnb:tgt/luns/mgmt
# echo "add disk2 1" >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.vlnb:tgt/luns/mgmt
# echo 1 >/sys/kernel/scst_tgt/targets/iscsi/iqn.2006-10.net.vlnb:tgt/enabled
# echo 1 >/sys/kernel/scst_tgt/targets/iscsi/enabled
4)Alternative way to setup iscsi target is to put the following content to /etc/scst.conf.
HANDLER vdisk_fileio {
        DEVICE disk01 {
                filename /home/hui/vdisk1
                nv_cache 1
        }
        DEVICE disk02 {
                filename /home/hui/vdisk2
                nv_cache 1
        }
}

TARGET_DRIVER iscsi {
        enabled 1

        TARGET iqn.2006-10.net.vlnb:tgt {
                LUN 0 disk01
                LUN 1 disk02

                enabled 1
        }
}
Then start scst service:
$sudo service scst start

5) Setup iSCSI initiator to discover the new devices(assume open-iscsi installed)

$sudo iscsiadm -m discovery -t st -p192.168.1.1
$sudo iscsiadm -m node -T iqn.2006-10.net.vlnb:tgt -p 192.168.1.1 -l

Sunday, April 22, 2012

Session lost after switch from HTTPS to HTTP

I notice an issue that http session Id is not unique from single browser. The following debugging code was added for each Spring controller class:

HttpSession session = request.getSession();
logger.debug("Current session id: " + session.getId());

The session id was always same for https access from the browser. And it was changed for http access even with the same browser.

That looks like a well known issue. I should keep https access for all links to my web application if I would like the session being kept.