SBC: Fix the LBA out of range check in VERIFY16

This fixes the check for LBA out of range in VERIFY16 where very high LBAs
could wrap back to 0 due to shifting LBA <<9 instead of shifting filesize>>9

Add a check for LBA+TL < LBA wrapping

Add a check for LBA out of range also when transfer length is 0

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
mgmt: fixed -m system -o delete handling

system_active was reset only in case when mgmt response was carrying data.
In case of deleting system, response code was returned in err field of the header
therefore system was not shut down.

Signed-off-by: Alexander Nezhinsky <alexandern@mellanox.com>
Signed-off-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
tgt 1.0.29

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Add support for WRITEVERIFY10/12/16

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
sbc: Add support for COMPAREANDWRITE opcode

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
sbc: Add support for ORWRITE command

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
spc: fix START_STOP

If power condition != 0  then we should ignore LOEJ and START bits
and not do any online/offline operations.

Fix the check for LOEJ and make sure this flag is set to 0 or 1, not 0 or 2.

Check that the removable attribute is set. We should not call
online/offline for non-removable luns

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
sbc: Check for MediaPresent before checking for ThinProvisioning in UNMAP call

This patch does not change any logic, only in which order two error checks
are performed.

Currently the checks are made in the order
1, if not ThinProvision   then error
2, if NoMedia  then error

Since Thin-Provisioning is an attribute of the media itself and not the LUN,
it makes more sense to check these two properties in the reverse order :

1, if NoMedia   then error
2, if not ThinProvisioned  then error

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Add infrastructure for statistics on SCSI device level

To introduce statistics on SCSI device level we need to accumulate them
for each ITL (initiator-target-lun) nexus.

For example in case of iscsi, this is a granularity which is finer than
a session (IT nexus), as it represents access to a specific lun within
the session.

Statistics counters are added to the ITL object, "struct it_nexus_lu_info".
They need to be shown later in various scopes (connection, device, target etc.)
requiring two-way access, both from a device (lun to all its ITLs) and
from an IT nexus (IT nexus to all its ITLs).

Thus linked list heads called "itn_itl_info_list" and "lu_itl_info_list" are
added to struct it_nexus and struct scsi_lu, while struct it_nexus_lu_info
becomes a memeber in these two lists, thru the list entries called:
"itn_itl_info_siblings" and "lu_itl_info_siblings".

Signed-off-by: Alexander Nezhinsky <alexandern@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Show new statistics in various modes; integrate scsi and iscsi stats where relevant

Implemented statistics presentation using --op stat instead of --mode stat,
as --op may be applied to various modes.

Added --op stat to --mode session and --mode conn.

When presenting iscsi connestions/sessions, show integrated scsi and iscsi statistics.
Session stats show the counters for all luns accessible through the session,
along with iscsi counters for all the connections comprising the session
(practically just one). Connection stats only show the iscsi counters.

Signed-off-by: Alexander Nezhinsky <alexandern@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
collect isci conn stats for iser connections

implement iscsi stats update functions iscsi_update_conn_stats_{rx|tx}
common for iscsi and iser. In iser treat rdma-read as data-out pdu, and
rdma-write as data-out pdu for stat collection purposes.

Signed-off-by: Alexander Nezhinsky <alexandern@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
upgrade scripts/checkpatch.pl to version 0.32

Signed-off-by: Alexander Nezhinsky <alexandern@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
scripts/checkpatch.pl modified for stgt, no tree as default

Signed-off-by: Alexander Nezhinsky <alexandern@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
A LUN RESET will clear any PREVENTALLOWs that might be set.

Whena LUN RESET command is received, walk the list of all itl nexuses and
clear the preventallow settings.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
iscsi: deleting portals on iscsi tcp exit

In addition to closing the fds and deleting the tgt events
also cleaning the portals list.

Signed-off-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
tgtd: fork logger before initializing llds

Currently the logger is forked after LLDs are initialized/started, hence
file-descriptors opened during that initialization are duplicated during the
fork and remain open even when closed in the main thread.
The solution is to fork the logger before the LLDs are started.

Signed-off-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
MODE_SENSE: add support for mode subpages

Add support for mode subpages.
Change the modepages from an array of pointers to a linked list
so that we can store an arbitrary number od mode pages with the same
page code (but different subpage codes)

Add a simple modepage with a subpage code 0x0a/0x01 which is the
ControlExtensions subpage.
Have TCMOS set to 1 in this subpage.
This value has the following meaning (SPC):
        A timestamp changeable by methods outside this standard (TCMOS)
        bit set to one specifies that the timestamp may
        be initialized by methods outside the scope of this standard.

Which sounds appropriate since root or ntpd can change the
local time on linux without first asking TGTD and SPC for permission first

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
For each lld save the list of targets using it

Signed-off-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
tgt-admin: add option to restart llds

This patch allows to stop and start lld without restarting tgtd.
Example:
tgtadm --mode lld --lld iser --op start

Signed-off-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Add documentation for starting lld while tgtd is running

Signed-off-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>