2014/06/08

iSCSI Configuration

What is iSCSI 

iSCSI ( Internet Small Computer System Interface ) is an Internet Protocol (IP)-based storage networking standard for linking data storage facilities.

By carrying SCSI commands over IP networks, iSCSI is used to facilitate data transfers over intranets and to manage storage over long distances. iSCSI can be used to transmit data over local area networks (LANs), wide area networks (WANs), or the Internet and can enable location-independent data storage and retrieval.

The protocol allows clients (called initiators) to send SCSI commands (CDBs) to SCSI storage devices (targets) on remote servers. It is a storage area network (SAN) protocol, allowing organizations to consolidate storage into data center storage arrays while providing hosts (such as database and web servers) with the illusion of locally attached disks.

Configure Targets

In Ubuntu 14.04, simple setup: set the target device as a image file, no authentication required, can be connected from IP.
[1]Create a new image file for storage area.

# create an image file of size 20G 

root@dlp:~#
mkdir /storage
dd if=/dev/zero of=/storage/lun1.img bs=1024k count=20000

[2]Configure iSCSI Target
root@dlp:~#
aptitude -y install iscsitarget iscsitarget-dkms
root@dlp:~#
vi /etc/default/iscsitarget
# change

ISCSITARGET_ENABLE=true
root@dlp:~#
vi /etc/iet/ietd.conf
# add at the last line

# naming rule : [ iqn.yaer-month.domain:any name ]

Target iqn.2014-04.world.server:target0
 
# provided devicce as a iSCSI target

    Lun 0 Path=/storage/lun1.img,Type=fileio
 
# Alias

    Alias LUN1
 
# authentication info ( set anyone you like for "username", "password" )

    incominguser username password
root@dlp:~#
/etc/init.d/iscsitarget restart 

 * Removing iSCSI enterprise target devices:          [ OK ]
 * Starting iSCSI enterprise target service           [ OK ]
                                                      [ OK ]
root@dlp:~#
ietadm --op show --tid=1 
# show status

Wthreads=8
Type=0
QueuedCommands=32
NOPInterval=0
NOPTimeout=0


Configure Initiator

Simple Setup: No authentication, assume target IP is 192.168.11.4
[1]Configure iSCSI Initiator
root@www:~#
aptitude -y install open-iscsi
root@www:~#
vi /etc/iscsi/iscsid.conf
# discover target

root@www:~#
iscsiadm -m discovery -t sendtargets -p 192.168.11.4

192.168.11.4:3260,1 iqn.2012-07.world.server:target0
# confirm status after discovery

root@www:~#
iscsiadm -m node -o show 

# BEGIN RECORD 2.0-871 node.name = iqn.2012-07.world.server:target0
node.tpgt = 1
node.startup = manual
iface.hwaddress = <empty>
iface.ipaddress = <empty>
iface.iscsi_ifacename = default
iface.net_ifacename = <empty>
iface.transport_name = tcp
iface.initiatorname = <empty>
...
# END RECORD
# login to target

root@www:~#
iscsiadm -m node --login
...
# confirm session
root@www:~# 
iscsiadm -m session -o show 
tcp: [1] 192.168.11.4:3260,1 iqn.2012-07.world.server:target0
# confirm partitions

root@www:~#
cat /proc/partitions 




Reference

http://www.server-world.info/en/note?os=Ubuntu_12.04&p=iscsi
http://www.howtoforge.com/using-iscsi-on-ubuntu-10.04-initiator-and-target
http://en.wikipedia.org/wiki/ISCSI

2014/06/05

Flash Memory Controller

Example code:
http://lxr.linux.no/linux+v2.6.32/drivers/mtd/nand/s3c2410.c

mtd nand driver architecture:
http://kernel.org/doc/htmldocs/mtdnand.html

about ECC of nand:
http://en.wikipedia.org/wiki/Flash_memory
http://en.wikipedia.org/wiki/Error_correcting_code

bad block management
NAND devices also require bad block management by the device driver software, or by a separate controller chip. SD cards, for example, include controller circuitry to perform bad block management and wear leveling. When a logical block is accessed by high-level software, it is mapped to a physical block by the device driver or controller. A number of blocks on the flash chip may be set aside for storing mapping tables to deal with bad blocks, or the system may simply check each block at power-up to create a bad block map in RAM. The overall memory capacity gradually shrinks as more blocks are marked as bad.

nand flash controller diagram

specification of nand interface, including command definition
http://www.micron.com/~/media/Documents/Products/ONFI/onfi_31_spec.pdf

Wear Leveling
JFFS2, YAFFS, and UBIFS include bad block management, wear leveling, error correction and provide reliable filesystems for industrial use on top of NAND Flash.

Some code about Linux file system on Flash
struct nand_chip {
 int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
   uint32_t offset, int data_len, const uint8_t *buf,
   int oob_required, int page, int cached, int raw);
            
               
}

nand_write
  nand_do_write_ops
    chip->write_page ( nand_write_page )
      ecc->write_page ( nand_write_page_hwecc )
        chip->write_buf ( s3c2410_nand_write_buf ) 
      chip->cmdfunc( nand_command ) 
        chip->cmd_ctrl( s3c2410_nand_hwcontrol )
    


    
nand_read
  nand_do_read_ops
    chip->cmdfunc ( nand_command )
      chip->cmd_ctrl( s3c2410_nand_hwcontrol )
    ecc->read_page_raw ( nand_read_page_raw )
      chip->read_buf ( s3c2410_nand_read_buf )
      

mtd_read
  mtd->_read ( nand_read )
mtd_write       
  mtd->_write ( nand_write ) 
    
    
ubi_io_write    
  mtd_write
ubi_io_read
  mtd_read  
  
Wear-Leveling is in the drivers\mtd\ubi\wl.c 


UBIFS to UBI
  ubifs_leb_read
    ubi_read
  ubifs_leb_write
    ubi_leb_write
    

UBIFS and UBI are different
  UBI source code 
    drivers\mtd\ubi
  UBIFS source code
    fs\ubifs
  UBIFS's VFS mount point
    fs\ubifs\file.c
    fs\ubifs\dir.c
    fs\ubifs\super.c

Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...