Fix buffer_offset set to 0 in the last Data-IN carrying status

The same function was called both for setting residual counts
in data_in with status and scsi_response pdus. Bi-directional
status, being set to 0 for scsi_response when data_in is actually
passed, resets buffer_offset field inadvertently.

This precluded formatting LUNs exported thru iSCSI to a Windows
initiator.

The fix is to separate these cases and to call a specialized
function for residual count carried in data_in with status.

Signed-off-by: Alexander Nezhinsky <nezhinsky@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Create tx pdu by explicit scsi cmd dir (none, rd,wr,bidir)

Differentiating between various possible cases for tx pdus
(r2t, data-in and scsi_response) has been made using a set of
predicates, some of which are relevant only for a specific
cmd direction types.
Although possibly correct when all counters and flags used
are up-to-date, this may be dangerous and hard to debug.
Explicit check of cmd type allows discriminating only between
the choices feasible for each cmd type.

Alexander Nezhinsky <nezhinsky@gmail.com>
FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
spc: fix corrupted modesense pages

Two argumens were swapped in the header to the function for safe writing to the data-out buffer with
the result that any/all modesense data-in we send back to the initiator are mainly garbage.

Fix this and also add tests for this to libiscsi so that we can catch any future regressions :

    ./bin/iscsi-test-cu iscsi://127.0.0.1/iqn.ronnie.test/1 --test SCSI.ModeSense6.AllPages -V

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
DOCS: Add --bsoflags and sync/direct to the manpage

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

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
iser: Fix bidirectional chap

When bidirectional chap is used, after the authentication phase is completed, the next
message from the target to the initiator should contain only the session parameters.
Currently it is wrongly prefixed with part of the previous message (which contained
authentication data). Fix that by initializing tx_pdu->membuf.size to zero before any
message is created in iser_login_exec.

Signed-off-by: Shlomo Pongratz <shlomop@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
spc: Allow 14bit lun numbers.

Only the topmost 2 bits are reserved, and flat space addressing allows
14bit luns.
Tested by creating a target with 1500 luns.

Signed-off-by: Jan Vesely <jvesely@redhat.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>