11a787169SDaniel Verkamp# iSCSI Target {#iscsi} 21a787169SDaniel Verkamp 31e1fd9acSwawryk## iSCSI Target Getting Started Guide {#iscsi_getting_started} 41a787169SDaniel Verkamp 523593aa9SBen WalkerThe Storage Performance Development Kit iSCSI target application is named `iscsi_tgt`. 61a787169SDaniel VerkampThis following section describes how to run iscsi from your cloned package. 71a787169SDaniel Verkamp 81a787169SDaniel Verkamp## Prerequisites {#iscsi_prereqs} 91a787169SDaniel Verkamp 101a787169SDaniel VerkampThis guide starts by assuming that you can already build the standard SPDK distribution on your 116129c63aSGangCaoplatform. 121a787169SDaniel Verkamp 136b9b448eSBen WalkerOnce built, the binary will be in `build/bin`. 141a787169SDaniel Verkamp 1539240a9eSCunyin ChangIf you want to kill the application by using signal, make sure use the SIGTERM, then the application 1639240a9eSCunyin Changwill release all the shared memory resource before exit, the SIGKILL will make the shared memory 1739240a9eSCunyin Changresource have no chance to be released by applications, you may need to release the resource manually. 1839240a9eSCunyin Chang 19e87352faSTomasz Kulasek## Introduction 20e87352faSTomasz Kulasek 21e87352faSTomasz KulasekThe following diagram shows relations between different parts of iSCSI structure described in this 22e87352faSTomasz Kulasekdocument. 23e87352faSTomasz Kulasek 24e87352faSTomasz Kulasek 25e87352faSTomasz Kulasek 26e87352faSTomasz Kulasek### Assigning CPU Cores to the iSCSI Target {#iscsi_config_lcore} 276129c63aSGangCao 286129c63aSGangCaoSPDK uses the [DPDK Environment Abstraction Layer](http://dpdk.org/doc/guides/prog_guide/env_abstraction_layer.html) 296129c63aSGangCaoto gain access to hardware resources such as huge memory pages and CPU core(s). DPDK EAL provides 306129c63aSGangCaofunctions to assign threads to specific cores. 316129c63aSGangCaoTo ensure the SPDK iSCSI target has the best performance, place the NICs and the NVMe devices on the 326129c63aSGangCaosame NUMA node and configure the target to run on CPU cores associated with that node. The following 3387d2cd9bSJim Harriscommand line option is used to configure the SPDK iSCSI target: 346129c63aSGangCao 3563ee471bSMaciej Wawryk~~~bash 3687d2cd9bSJim Harris-m 0xF000000 3787d2cd9bSJim Harris~~~ 3887d2cd9bSJim Harris 3987d2cd9bSJim HarrisThis is a hexadecimal bit mask of the CPU cores where the iSCSI target will start polling threads. 4087d2cd9bSJim HarrisIn this example, CPU cores 24, 25, 26 and 27 would be used. 416129c63aSGangCao 426129c63aSGangCao## Configuring iSCSI Target via RPC method {#iscsi_rpc} 436129c63aSGangCao 442903c655STomasz ZawadzkiThe iSCSI target is configured via JSON-RPC calls. See @ref jsonrpc for details. 456129c63aSGangCao 46e87352faSTomasz Kulasek### Portal groups 47e87352faSTomasz Kulasek 480f4b3490SPawel Kaminski- iscsi_create_portal_group -- Add a portal group. 494bb8a88cSPawel Kaminski- iscsi_delete_portal_group -- Delete an existing portal group. 50a1c9546fSPawel Kaminski- iscsi_target_node_add_pg_ig_maps -- Add initiator group to portal group mappings to an existing iSCSI target node. 51655b64daSPawel Kaminski- iscsi_target_node_remove_pg_ig_maps -- Delete initiator group to portal group mappings from an existing iSCSI target node. 521a6c41a9SPawel Kaminski- iscsi_get_portal_groups -- Show information about all available portal groups. 531a787169SDaniel Verkamp 5463ee471bSMaciej Wawryk~~~bash 550f4b3490SPawel Kaminski/path/to/spdk/scripts/rpc.py iscsi_create_portal_group 1 10.0.0.1:3260 566129c63aSGangCao~~~ 576129c63aSGangCao 58e87352faSTomasz Kulasek### Initiator groups 59e87352faSTomasz Kulasek 6094dd4b9aSPawel Kaminski- iscsi_create_initiator_group -- Add an initiator group. 617eedb271SPawel Kaminski- iscsi_delete_initiator_group -- Delete an existing initiator group. 62a7d07920SPawel Kaminski- iscsi_initiator_group_add_initiators -- Add initiators to an existing initiator group. 63e3366470SPawel Kaminski- iscsi_get_initiator_groups -- Show information about all available initiator groups. 646129c63aSGangCao 6563ee471bSMaciej Wawryk~~~bash 6694dd4b9aSPawel Kaminski/path/to/spdk/scripts/rpc.py iscsi_create_initiator_group 2 ANY 10.0.0.2/32 676129c63aSGangCao~~~ 686129c63aSGangCao 69e87352faSTomasz Kulasek### Target nodes 70e87352faSTomasz Kulasek 71ae800252Spaul luse- iscsi_create_target_node -- Add an iSCSI target node. 72ae800252Spaul luse- iscsi_delete_target_node -- Delete an iSCSI target node. 73ae800252Spaul luse- iscsi_target_node_add_lun -- Add a LUN to an existing iSCSI target node. 747d114278SPawel Kaminski- iscsi_get_target_nodes -- Show information about all available iSCSI target nodes. 756129c63aSGangCao 7663ee471bSMaciej Wawryk~~~bash 77758b2f94SPawel Kaminski/path/to/spdk/scripts/rpc.py iscsi_create_target_node Target3 Target3_alias MyBdev:0 1:2 64 -d 781a787169SDaniel Verkamp~~~ 791a787169SDaniel Verkamp 801a787169SDaniel Verkamp## Configuring iSCSI Initiator {#iscsi_initiator} 811a787169SDaniel Verkamp 821a787169SDaniel VerkampThe Linux initiator is open-iscsi. 831a787169SDaniel Verkamp 841a787169SDaniel VerkampInstalling open-iscsi package 851a787169SDaniel VerkampFedora: 8663ee471bSMaciej Wawryk~~~bash 871a787169SDaniel Verkampyum install -y iscsi-initiator-utils 881a787169SDaniel Verkamp~~~ 891a787169SDaniel Verkamp 901a787169SDaniel VerkampUbuntu: 9163ee471bSMaciej Wawryk~~~bash 921a787169SDaniel Verkampapt-get install -y open-iscsi 931a787169SDaniel Verkamp~~~ 941a787169SDaniel Verkamp 951a787169SDaniel Verkamp### Setup 961a787169SDaniel Verkamp 971a787169SDaniel VerkampEdit /etc/iscsi/iscsid.conf 9863ee471bSMaciej Wawryk~~~bash 991a787169SDaniel Verkampnode.session.cmds_max = 4096 1001a787169SDaniel Verkampnode.session.queue_depth = 128 1011a787169SDaniel Verkamp~~~ 1021a787169SDaniel Verkamp 1031a787169SDaniel Verkampiscsid must be restarted or receive SIGHUP for changes to take effect. To send SIGHUP, run: 10463ee471bSMaciej Wawryk~~~bash 1051a787169SDaniel Verkampkillall -HUP iscsid 1061a787169SDaniel Verkamp~~~ 1071a787169SDaniel Verkamp 1081a787169SDaniel VerkampRecommended changes to /etc/sysctl.conf 10963ee471bSMaciej Wawryk~~~bash 1101a787169SDaniel Verkampnet.ipv4.tcp_timestamps = 1 1111a787169SDaniel Verkampnet.ipv4.tcp_sack = 0 1121a787169SDaniel Verkamp 1131a787169SDaniel Verkampnet.ipv4.tcp_rmem = 10000000 10000000 10000000 1141a787169SDaniel Verkampnet.ipv4.tcp_wmem = 10000000 10000000 10000000 1151a787169SDaniel Verkampnet.ipv4.tcp_mem = 10000000 10000000 10000000 1161a787169SDaniel Verkampnet.core.rmem_default = 524287 1171a787169SDaniel Verkampnet.core.wmem_default = 524287 1181a787169SDaniel Verkampnet.core.rmem_max = 524287 1191a787169SDaniel Verkampnet.core.wmem_max = 524287 1201a787169SDaniel Verkampnet.core.optmem_max = 524287 1211a787169SDaniel Verkampnet.core.netdev_max_backlog = 300000 1221a787169SDaniel Verkamp~~~ 1231a787169SDaniel Verkamp 1241a787169SDaniel Verkamp### Discovery 1251a787169SDaniel Verkamp 126e87352faSTomasz KulasekAssume target is at 10.0.0.1 12763ee471bSMaciej Wawryk 12863ee471bSMaciej Wawryk~~~bash 129e87352faSTomasz Kulasekiscsiadm -m discovery -t sendtargets -p 10.0.0.1 1301a787169SDaniel Verkamp~~~ 1311a787169SDaniel Verkamp 1321a787169SDaniel Verkamp### Connect to target 1331a787169SDaniel Verkamp 13463ee471bSMaciej Wawryk~~~bash 1351a787169SDaniel Verkampiscsiadm -m node --login 1361a787169SDaniel Verkamp~~~ 1371a787169SDaniel Verkamp 1381a787169SDaniel VerkampAt this point the iSCSI target should show up as SCSI disks. Check dmesg to see what 1391a787169SDaniel Verkampthey came up as. 1401a787169SDaniel Verkamp 1411a787169SDaniel Verkamp### Disconnect from target 1421a787169SDaniel Verkamp 14363ee471bSMaciej Wawryk~~~bash 1441a787169SDaniel Verkampiscsiadm -m node --logout 1451a787169SDaniel Verkamp~~~ 1461a787169SDaniel Verkamp 1471a787169SDaniel Verkamp### Deleting target node cache 1481a787169SDaniel Verkamp 14963ee471bSMaciej Wawryk~~~bash 1501a787169SDaniel Verkampiscsiadm -m node -o delete 1511a787169SDaniel Verkamp~~~ 1521a787169SDaniel Verkamp 1531a787169SDaniel VerkampThis will cause the initiator to forget all previously discovered iSCSI target nodes. 1541a787169SDaniel Verkamp 1551a787169SDaniel Verkamp### Finding /dev/sdX nodes for iSCSI LUNs 1561a787169SDaniel Verkamp 15763ee471bSMaciej Wawryk~~~bash 1581a787169SDaniel Verkampiscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}' 1591a787169SDaniel Verkamp~~~ 1601a787169SDaniel Verkamp 1611a787169SDaniel VerkampThis will show the /dev node name for each SCSI LUN in all logged in iSCSI sessions. 1621a787169SDaniel Verkamp 1631a787169SDaniel Verkamp### Tuning 1641a787169SDaniel Verkamp 1651a787169SDaniel VerkampAfter the targets are connected, they can be tuned. For example if /dev/sdc is 1661a787169SDaniel Verkampan iSCSI disk then the following can be done: 1671a787169SDaniel VerkampSet noop to scheduler 1681a787169SDaniel Verkamp 16963ee471bSMaciej Wawryk~~~bash 1701a787169SDaniel Verkampecho noop > /sys/block/sdc/queue/scheduler 1711a787169SDaniel Verkamp~~~ 1721a787169SDaniel Verkamp 1731a787169SDaniel VerkampDisable merging/coalescing (can be useful for precise workload measurements) 1741a787169SDaniel Verkamp 17563ee471bSMaciej Wawryk~~~bash 1761a787169SDaniel Verkampecho "2" > /sys/block/sdc/queue/nomerges 1771a787169SDaniel Verkamp~~~ 1781a787169SDaniel Verkamp 1791a787169SDaniel VerkampIncrease requests for block queue 1801a787169SDaniel Verkamp 18163ee471bSMaciej Wawryk~~~bash 1821a787169SDaniel Verkampecho "1024" > /sys/block/sdc/queue/nr_requests 1831a787169SDaniel Verkamp~~~ 1841a787169SDaniel Verkamp 185e87352faSTomasz Kulasek### Example: Configure simple iSCSI Target with one portal and two LUNs 186e87352faSTomasz Kulasek 1875cdab5e2SDayu LiuAssuming we have one iSCSI Target server with portal at 10.0.0.1:3200, two LUNs (Malloc0 and Malloc1), 188e87352faSTomasz Kulasek and accepting initiators on 10.0.0.2/32, like on diagram below: 189e87352faSTomasz Kulasek 190e87352faSTomasz Kulasek 191e87352faSTomasz Kulasek 192e87352faSTomasz Kulasek#### Configure iSCSI Target 193e87352faSTomasz Kulasek 194e87352faSTomasz KulasekStart iscsi_tgt application: 19563ee471bSMaciej Wawryk 19663ee471bSMaciej Wawryk```bash 1976b9b448eSBen Walker./build/bin/iscsi_tgt 198e87352faSTomasz Kulasek``` 199e87352faSTomasz Kulasek 200e87352faSTomasz KulasekConstruct two 64MB Malloc block devices with 512B sector size "Malloc0" and "Malloc1": 201e87352faSTomasz Kulasek 20263ee471bSMaciej Wawryk```bash 2036a9239e8SKarol Latecki./scripts/rpc.py bdev_malloc_create -b Malloc0 64 512 2046a9239e8SKarol Latecki./scripts/rpc.py bdev_malloc_create -b Malloc1 64 512 205e87352faSTomasz Kulasek``` 206e87352faSTomasz Kulasek 207e87352faSTomasz KulasekCreate new portal group with id 1, and address 10.0.0.1:3260: 208e87352faSTomasz Kulasek 20963ee471bSMaciej Wawryk```bash 2106a9239e8SKarol Latecki./scripts/rpc.py iscsi_create_portal_group 1 10.0.0.1:3260 211e87352faSTomasz Kulasek``` 212e87352faSTomasz Kulasek 213e87352faSTomasz KulasekCreate one initiator group with id 2 to accept any connection from 10.0.0.2/32: 214e87352faSTomasz Kulasek 21563ee471bSMaciej Wawryk```bash 2166a9239e8SKarol Latecki./scripts/rpc.py iscsi_create_initiator_group 2 ANY 10.0.0.2/32 217e87352faSTomasz Kulasek``` 218e87352faSTomasz Kulasek 2197592a5feSRami RosenFinally construct one target using previously created bdevs as LUN0 (Malloc0) and LUN1 (Malloc1) 220e87352faSTomasz Kulasekwith a name "disk1" and alias "Data Disk1" using portal group 1 and initiator group 2. 221e87352faSTomasz Kulasek 22263ee471bSMaciej Wawryk```bash 2236a9239e8SKarol Latecki./scripts/rpc.py iscsi_create_target_node disk1 "Data Disk1" "Malloc0:0 Malloc1:1" 1:2 64 -d 224e87352faSTomasz Kulasek``` 225e87352faSTomasz Kulasek 226e87352faSTomasz Kulasek#### Configure initiator 227e87352faSTomasz Kulasek 228e87352faSTomasz KulasekDiscover target 229e87352faSTomasz Kulasek 23063ee471bSMaciej Wawryk~~~bash 231e87352faSTomasz Kulasek$ iscsiadm -m discovery -t sendtargets -p 10.0.0.1 232e87352faSTomasz Kulasek10.0.0.1:3260,1 iqn.2016-06.io.spdk:disk1 233e87352faSTomasz Kulasek~~~ 234e87352faSTomasz Kulasek 235e87352faSTomasz KulasekConnect to the target 236e87352faSTomasz Kulasek 23763ee471bSMaciej Wawryk~~~bash 2386a9239e8SKarol Lateckiiscsiadm -m node --login 239e87352faSTomasz Kulasek~~~ 240e87352faSTomasz Kulasek 241e87352faSTomasz KulasekAt this point the iSCSI target should show up as SCSI disks. 242e87352faSTomasz Kulasek 243e87352faSTomasz KulasekCheck dmesg to see what they came up as. In this example it can look like below: 244e87352faSTomasz Kulasek 24563ee471bSMaciej Wawryk~~~bash 246e87352faSTomasz Kulasek... 247e87352faSTomasz Kulasek[630111.860078] scsi host68: iSCSI Initiator over TCP/IP 248e87352faSTomasz Kulasek[630112.124743] scsi 68:0:0:0: Direct-Access INTEL Malloc disk 0001 PQ: 0 ANSI: 5 249e87352faSTomasz Kulasek[630112.125445] sd 68:0:0:0: [sdd] 131072 512-byte logical blocks: (67.1 MB/64.0 MiB) 250e87352faSTomasz Kulasek[630112.125468] sd 68:0:0:0: Attached scsi generic sg3 type 0 251e87352faSTomasz Kulasek[630112.125926] sd 68:0:0:0: [sdd] Write Protect is off 252e87352faSTomasz Kulasek[630112.125934] sd 68:0:0:0: [sdd] Mode Sense: 83 00 00 08 253e87352faSTomasz Kulasek[630112.126049] sd 68:0:0:0: [sdd] Write cache: enabled, read cache: disabled, doesn't support DPO or FUA 254e87352faSTomasz Kulasek[630112.126483] scsi 68:0:0:1: Direct-Access INTEL Malloc disk 0001 PQ: 0 ANSI: 5 255e87352faSTomasz Kulasek[630112.127096] sd 68:0:0:1: Attached scsi generic sg4 type 0 256e87352faSTomasz Kulasek[630112.127143] sd 68:0:0:1: [sde] 131072 512-byte logical blocks: (67.1 MB/64.0 MiB) 257e87352faSTomasz Kulasek[630112.127566] sd 68:0:0:1: [sde] Write Protect is off 258e87352faSTomasz Kulasek[630112.127573] sd 68:0:0:1: [sde] Mode Sense: 83 00 00 08 259e87352faSTomasz Kulasek[630112.127728] sd 68:0:0:1: [sde] Write cache: enabled, read cache: disabled, doesn't support DPO or FUA 260e87352faSTomasz Kulasek[630112.128246] sd 68:0:0:0: [sdd] Attached SCSI disk 261e87352faSTomasz Kulasek[630112.129789] sd 68:0:0:1: [sde] Attached SCSI disk 262e87352faSTomasz Kulasek... 263e87352faSTomasz Kulasek~~~ 264e87352faSTomasz Kulasek 265e87352faSTomasz KulasekYou may also use simple bash command to find /dev/sdX nodes for each iSCSI LUN 266e87352faSTomasz Kulasekin all logged iSCSI sessions: 267e87352faSTomasz Kulasek 26863ee471bSMaciej Wawryk~~~bash 269e87352faSTomasz Kulasek$ iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}' 270e87352faSTomasz Kulaseksdd 271e87352faSTomasz Kulaseksde 272e87352faSTomasz Kulasek~~~ 2731a787169SDaniel Verkamp 2741e1fd9acSwawryk## iSCSI Hotplug {#iscsi_hotplug} 2751a787169SDaniel Verkamp 2761a787169SDaniel VerkampAt the iSCSI level, we provide the following support for Hotplug: 2771a787169SDaniel Verkamp 2781a787169SDaniel Verkamp1. bdev/nvme: 2791df1583bSwawryk 2801a787169SDaniel VerkampAt the bdev/nvme level, we start one hotplug monitor which will call 2811a787169SDaniel Verkampspdk_nvme_probe() periodically to get the hotplug events. We provide the 2821a787169SDaniel Verkampprivate attach_cb and remove_cb for spdk_nvme_probe(). For the attach_cb, 2831a787169SDaniel Verkampwe will create the block device base on the NVMe device attached, and for the 2841a787169SDaniel Verkampremove_cb, we will unregister the block device, which will also notify the 2851a787169SDaniel Verkampupper level stack (for iSCSI target, the upper level stack is scsi/lun) to 2861a787169SDaniel Verkamphandle the hot-remove event. 2871a787169SDaniel Verkamp 2881a787169SDaniel Verkamp2. scsi/lun: 2891df1583bSwawryk 2901a787169SDaniel VerkampWhen the LUN receive the hot-remove notification from block device layer, 2911a787169SDaniel Verkampthe LUN will be marked as removed, and all the IOs after this point will 2921a787169SDaniel Verkampreturn with check condition status. Then the LUN starts one poller which will 2931a787169SDaniel Verkampwait for all the commands which have already been submitted to block device to 2941a787169SDaniel Verkampreturn back; after all the commands return back, the LUN will be deleted. 2951a787169SDaniel Verkamp 2961a787169SDaniel Verkamp@sa spdk_nvme_probe 29749904470SShuhei Matsumoto 2981e1fd9acSwawryk## iSCSI Login Redirection {#iscsi_login_redirection} 29949904470SShuhei Matsumoto 30049904470SShuhei MatsumotoThe SPDK iSCSI target application supports iSCSI login redirection feature. 30149904470SShuhei Matsumoto 30249904470SShuhei MatsumotoA portal refers to an IP address and TCP port number pair, and a portal group 30349904470SShuhei Matsumotocontains a set of portals. Users for the SPDK iSCSI target application configure 30449904470SShuhei Matsumotoportals through portal groups. 30549904470SShuhei Matsumoto 30649904470SShuhei MatsumotoTo support login redirection feature, we utilize two types of portal groups, 30749904470SShuhei Matsumotopublic portal group and private portal group. 30849904470SShuhei Matsumoto 30949904470SShuhei MatsumotoThe SPDK iSCSI target application usually has a discovery portal. The discovery 31049904470SShuhei Matsumotoportal is connected by an initiator to get a list of targets, as well as the list 31149904470SShuhei Matsumotoof portals on which these target may be accessed, by a discovery session. 31249904470SShuhei Matsumoto 31349904470SShuhei MatsumotoPublic portal groups have their portals returned by a discovery session. Private 31449904470SShuhei Matsumotoportal groups do not have their portals returned by a discovery session. A public 31549904470SShuhei Matsumotoportal group may optionally have a redirect portal for non-discovery logins for 31649904470SShuhei Matsumotoeach associated target. This redirect portal must be from a private portal group. 31749904470SShuhei Matsumoto 31849904470SShuhei MatsumotoInitiators configure portals in public portal groups as target portals. When an 319*a82b365bSJosh Sorefinitiator logs in to a target through a portal in an associated public portal group, 32049904470SShuhei Matsumotothe target sends a temporary redirection response with a redirect portal. Then the 32149904470SShuhei Matsumotoinitiator logs in to the target again through the redirect portal. 32249904470SShuhei Matsumoto 32349904470SShuhei MatsumotoUsers set a portal group to public or private at creation using the 32449904470SShuhei Matsumoto`iscsi_create_portal_group` RPC, associate portal groups with a target using the 3255a92ce53SShuhei Matsumoto`iscsi_create_target_node` RPC or the `iscsi_target_node_add_pg_ig_maps` RPC, 32649904470SShuhei Matsumotospecify a up-to-date redirect portal in a public portal group for a target using 3275a92ce53SShuhei Matsumotothe `iscsi_target_node_set_redirect` RPC, and terminate the corresponding connections 3285a92ce53SShuhei Matsumotoby asynchronous logout request using the `iscsi_target_node_request_logout` RPC. 32949904470SShuhei Matsumoto 33049904470SShuhei MatsumotoTypically users will use the login redirection feature in scale out iSCSI target 33149904470SShuhei Matsumotosystem, which runs multiple SPDK iSCSI target applications. 332