Commit Graph

314 Commits

Author SHA1 Message Date
David Disseldorp
f117b6c96d socket: add iscsi_out_queue_length() function
This function allows the caller to determine the number of PDUs queued
for transmission for a given iscsi context.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2016-03-22 21:19:51 +01:00
David Disseldorp
4a3dcf0349 iscsi: add response values for Task Mgmt Func
These values are defined in rfc3720
10.6. Task Management Function Response
-> 10.6.1.  Response

The response field is a single byte value, and is already used within
libiscsi as a command_data parameter for iscsi_task_mgmt_async()
callbacks.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2016-03-22 21:06:39 +01:00
Peter Lieven
97406c5b36 Revert "Fail pending LOGOUT commands on session reconnect"
This seriously breaks qemu NOP timeouts and probably other things.
The reason is that the

define ISCSI_PDU_ERROR_ON_RECONNECT	0x00000016

is masking bits 0x2 and 0x4 as well.

Correctly it should read:
define ISCSI_PDU_ERROR_ON_RECONNECT	0x00000010

However, the better solution for this approach is invoke all callbacks
of PDUs which carry the ISCSI_PDU_DROP_ON_RECONNECT flag. This will
make sure that callbacks of whatever sync tasks are invoked.

This reverts commit 0407cf6aed.
2016-03-17 12:08:20 +01:00
Ronnie Sahlberg
0407cf6aed Fail pending LOGOUT commands on session reconnect
Certain iSCSI commands such as NOP and LOGOUT commands are discarded instead
of re-queued when we have a session failure and reconnect.
Change the LOGOUT command to instead fail with SCSI_STATUS_ERROR when this
happens.

Otherwise, IF we are in iscsi_logout_sync() and we get a session failure
at the same-ish time we may end up automatically re-connecting the
session, but since we have discarded the logout command we will never
get a reply and will hang indefinitely in the event loop for synchronous
commands.
Arguably, we could also just return SCSI_STATUS_GOOD here since
when we perform a logout, we probably don't care too much about how we
disconnected from the server, only that we did disconnect from the server.
That is academic anyway since this only affects the sync API which is only
meant for trivial applications, which will likely not inspect the result
and just do a:
...
iscsi_logout_sync()
iscsi_destroy_context()
...
anyway.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-12-15 21:17:50 -08:00
Ronnie Sahlberg
8e1332d70a Change ISCSI_STATUS_* to SCSI_STATUS_*
We unified ISCSI and SCSI status codes a long long time ago
and got rid of the actual ISCSI_STATUS_* codes.
Update iscsi.h and remove references to these obsolete symbols
and replace with SCSI_STATUS_*
2015-12-15 21:09:42 -08:00
Ronnie Sahlberg
3c44092635 Add a feature to request transparent reconnects without any UA
Normal applications want the current behaviour where we have the library
consume any/all of the UnitAttentions that the target may have queued on the
initial connection, but when we reconnect the session after a failure the
library will pass all the UAs back to the application to process.

Some applications, such as the test suite or really trivial applications
might not want to have to deal with handling of UAs and just "make it work".
Those applications can now request that upon any reconnection of the session
that libiscsi will automatically consume any and all UAs and hide them from
the application.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-12-13 14:29:32 -08:00
David Disseldorp
9aa5b55b41 test/pr: simple PRin REPORT CAPABILITIES test
Check that the Persistent Reserve In REPORT CAPABILITIES response
carries valid LENGTH, ALLOW COMMANDS, and PERSISTENT RESERVATION TYPE
MASK fields.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2015-09-30 11:00:19 +02:00
Ronnie Sahlberg
80b81772e2 Add unmarshalling of VPD BLock Limits settings for atomic writes
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-09-09 06:49:41 -07:00
Ronnie Sahlberg
02fd6217cb Add support for WRITE_ATOMIC_16
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-09-08 10:16:57 -07:00
Ronnie Sahlberg
a6f7c06119 Add support and tests for ExtendedCopy and ReceiveCopyResults
From sushma.gurram@sandisk.com
Add support to libiscsi and tests for these two opcodes.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-08-02 12:57:21 -07:00
Kamalneet Singh
1cef3e62a9 Fix documentation typos and copy-paste errors. 2015-07-18 05:36:19 -07:00
Ronnie Sahlberg
96c00b2178 New version 1.15.0
- Replace some u_int32_t with uint32_t
- Portability fixes to iscsi-perf
- Improved documentation for the tests in README
- Add/fix support for setting task/pdu timeouts and add unit tests for it.
- Add multipath helpers for the test suite and add a simple multipath test
- Skip sending TUR during reconnect, since it can cause the connection to
-   hang.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-06-21 08:50:50 -07:00
Ronnie Sahlberg
0630aa5ef0 Timeouts: Fix bugs in scsi task timeout code
Add a test to verify the pdu timeout handling.
Fix numerous bugs in the timeout handling. It was really broken.

Add test for non-SCSI task PDUs too and verify they works.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-05-24 14:34:06 -07:00
Ronnie Sahlberg
dfeefd6539 New version 1.14.0
- Add support to use /dev/* nodes instead of just iscsi devices.
 - Create a dedicated test for the FUA/DPO flags
 - Allow reusing the context after disconnect
 - Fix non-randomness in rand_key()
 - Add iscsi-perf tool
 - Fix length bug when sending unsolicited data in iscsi_command
 - Reqrite the reconnect logic to begome fully async
 - Fix wrong checks for username in CHAP
 - Support Bidirectional CHAP
 - Improve handling of IMMEDIATE bit
 - Cmdsn, statsn fixes+
 - iscsi_which_events can return 0, which means that there are no events right
   now but try again in a second or so.
 - Ignore any ASYNC EVENTS we receive since we can not yet pass them back to
   the application.
 - Add initial make test support
 - Various minor fixes to libiscsi and the test suite

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-05-10 09:14:11 -07:00
Peter Lieven
b4098c535e init: make LIBISCSI_CACHE_ALLOCATIONS a public environment variable
this variable was introduced for iscsi-test-cu only. This patch
makes it a generic environment variable that can be set per context.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-05-05 14:10:44 +02:00
Peter Lieven
efcf602476 nop: print a warning if the oldest element in iscsi->waitpdu queue is stuck
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-05-05 13:54:15 +02:00
Bart Van Assche
8435f9722e lib: Parse sense specific descriptor
Extend struct scsi_sense with sense specific descriptor information,
introduce the function scsi_parse_sense_data() and let that function
parse the sense specific descriptor.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
2015-04-27 19:17:51 -07:00
Bart Van Assche
cf4076dba9 test-tool: Make it possible to disable memory caching
Disable memory caching in libiscsi if the environment variable
LIBISCSI_CACHE_ALLOCATIONS has been set to zero. This makes
Valgrind reports more meaningful.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
2015-04-20 07:01:17 -07:00
Peter Lieven
b3ad565783 pdu: move update of maxcmdsn, expcmdsn & statsn to iscsi_process_pdu
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-20 14:46:44 +02:00
Ronnie Sahlberg
b6fc366b5c TESTS: Add a test for D_SENSE in the CONTROL mode page
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-04-19 18:20:12 -07:00
Ronnie Sahlberg
f3a3854718 iscsi.h: document when iscsi_which_events return 0
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-04-15 08:25:16 -07:00
Peter Lieven
2858cb5483 NOP: copy the LUN from target NOP-In to NOP-Out
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-13 14:34:23 +02:00
Peter Lieven
913b2ab708 reconnect: avoid deadlock if socker error is received during reconnect
If we are reconnecting and the connection is already established we
end up looping forever if there is a socket error before we finish
the login process. Fix this by invoking the reconnect callback if
there is an error and no new reconnect is scheduled.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-13 12:11:03 +02:00
Peter Lieven
a8b33cefac drop iscsi->is_reconnecting
iscsi->is_reconnecting != 0 is equal to iscsi->old_iscsi != NULL.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-13 10:13:36 +02:00
Peter Lieven
8398059635 sync: add iscsi_reconnect_sync
This function represents the old sync reconnect behaviour.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-31 16:33:36 +02:00
Peter Lieven
b152d26eb9 connect: make the reconnect async
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-31 16:21:00 +02:00
Peter Lieven
cb6667a5dc drop ISCSI_PDU_URGENT_DELIVERY
its not needed anymore

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-26 17:00:20 +01:00
Peter Lieven
ff67986b55 login: drop iscsi_logout_async_internal
now that immediate PDUs are queued at the head of outqueue we do no
longer need the immediate delivery hack.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-26 16:56:50 +01:00
Peter Lieven
a45094b7a7 init: fix segfaul in iscsi_parse_url
We allowed iscsi to be NULL in iscsi_parse_url. Especially
qemu does this and currently segfaults at start. Change the
usage guidelines for target username/password to be the same
as for chap username/password.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-26 10:07:52 +01:00
Ronnie Sahlberg
b1d0ac45f1 Add support for bidirectional CHAP
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-03-14 10:43:03 -07:00
Ronnie Sahlberg
6822baee3f reconnect: we need to reset the in/out iovectors on reconnect
This is a bug that has been there a long time.
When we reconnect and requeue a PDU we must reset the iovectors
for the task. Otherwise, any partially sent/received data when the
command is reconnected would end up containing garbage.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-24 06:54:18 -08:00
Ronnie Sahlberg
76f8296dbb reconnect logic and pdu handling
Rework the reconnect logic so we just call iscsi_scsi_command_async()
for the scsi commands we are re-quining instead of poking into the
private fields of the structures themself.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-23 20:46:57 -08:00
Ronnie Sahlberg
511c2fdbd1 pdu.c: remove iscsi_allocate_pdu_with_itt_flags()
Remove iscsi_allocate_pdu() which is just a wrapper.
Rename iscsi_allocate_pdu_with_itt_flags() to iscsi_allocate_pdu()
and update all callers.

This only removes a wrapper function and contains no logic changes.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-23 20:26:22 -08:00
Peter Lieven
c94fb840bc iscsi-private: add MIN and MAX macros
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-02-23 07:48:29 +01:00
Ronnie Sahlberg
2f5d21b09c iscsi-command.c: Use common function to write unsolicited data-out pdus.
We write unsolicited data-out PDUs from two places;
when we originally write the command in iscsi_scsi_command_async()
but also when we re-queue the PDUs during a session reconnect.

The re-queuing during the session re-connect was recently (almost) fixed
but was still buggy in that it did not correctly clamp the amount of written
data as per first burst length restriction.
This attempts to fix that.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-20 20:51:14 -08:00
Ronnie Sahlberg
b001d980ef reconnect: we must re-queue any missing data-outs during reconnect
If we have writes that do not have the Final bit set during reconnect
we must send out any missing data-out PDU.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-17 06:46:58 -08:00
Ronnie Sahlberg
7865a8a26e Merge branch 'sgio' 2014-12-21 15:07:40 -08:00
Ronnie Sahlberg
8c4a579cda SCSI: scsi_task_get_status add getter function for task status and sense
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-12-19 08:33:21 -08:00
Ronnie Sahlberg
9eabebd78a iscsi.h: remove obsolete scsi_get_data_[in|out]_buffer symbols
These two functions do not exist. Remove them from the header.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-12-18 05:51:23 -08:00
Ronnie Sahlberg
14461757c4 TESTS: Allow Hardware/Software write protect as valid ASCQ
Add 0x2701/0x2702 to the list of valid ASCQ values we accept for devices
that are write protected.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-10-08 06:23:43 -07:00
Bart Van Assche
ded75ae18a Fix WRITE SAME data buffer length handling
From the SPC-4 paragraph about WRITE SAME(10): "The WRITE SAME (10)
command requests that the device server transfer a single logical
block from the Data-Out Buffer [ ... ]". Hence always pass a data
buffer when sending a WRITE SAME(10) command.

Set the NDOB bit in the WRITE SAME(16) command if no data out buffer
is present.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2014-08-21 06:42:49 -07:00
Bart Van Assche
cfce944b35 test_write*_residuals: Fix overflow tests
RFC 3720 is not clear about whether a target should return SUCCESS
or CHECK CONDITION if SPDTL > EDTL. Hence accept both. See also
Fred Knight, Re: [Ips] Data Out residual overflow/underflow handling,
IETF mailing list archive, 21 September 2012
(http://www.ietf.org/mail-archive/web/ips/current/msg02756.html).

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2014-08-04 16:04:21 -07:00
Peter Lieven
59e4a07129 Revert "Rewrite and simplify iscsi_iovector_readv_writev"
Since writing headers and payload in a single iov has never been
implementend and after thinking about it several times seems to
be very hairy I would like to revert this change since
the original implementation is in O(1) while the changed one
is in O(n). This results in a complexity of O(n^2) instead of
O(n) for the whole send operation.

This reverts commit 06eab264f6.
2014-07-14 08:05:32 +02:00
Ronnie Sahlberg
ada1fc2008 Merge pull request #123 from plieven/asyncv3
add support for async messages
2014-07-13 16:46:27 -07:00
Ronnie Sahlberg
d44e9bd94f Merge pull request #116 from plieven/export_uint64
include: add prototypes for scsi_{get,set}_uint64
2014-07-13 16:32:06 -07:00
Ronnie Sahlberg
0693c10b63 bump api version in iscsi.h
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-07-13 16:31:15 -07:00
Peter Lieven
4e129d385c pdu: fix statsn and factor out sn comparision
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:58:38 +02:00
Peter Lieven
81921e3762 pdu: handle async target requests logout events
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:52:27 +02:00
Peter Lieven
98bbeab664 pdu: introduce ISCSI_PDU_URGENT_DELIVERY
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:50:41 +02:00
Peter Lieven
344b21d37d logout: allow additional PDU flags to be passed internally
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:43:54 +02:00