Commit Graph

600 Commits

Author SHA1 Message Date
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
Ronnie Sahlberg
74fc637eeb Use MSG_NOSIGNAL with send()
If the server closes the TCP connection before we call send() in
iscsi_write_to_socket() we will get SIGPIPE unless we pass this
argument to send.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-12-06 12:12:49 -08:00
Bart Van Assche
608dbcba12 scsi-lowlevel.c: Use sizeof() instead of a hardcoded constant
This patch does not change any functionality.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
2015-10-07 07:42:30 -07:00
David Disseldorp
ef8e59a24d lib/scsi: fix PRin REPORT CAPS allow_cmds unmarshalling
The Persistent Reserve In REPORT CAPABILITIES response carries the
ALLOW COMMANDS field in bits 4-6 at byte offset 3.
Bit 7 (TMV) should be masked out during ALLOW COMMANDS unmarshalling.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2015-09-30 11:00:13 +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
6c16f9e322 Add tests for WRITE_ATOMIC_16
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-09-08 10:17:15 -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
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
Peter Lieven
1ceb216394 pdu: timed out pdus might have no callback
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-16 12:14:11 +02:00
Peter Lieven
85fc823f59 pdu: do not leak timed out pdus
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-16 12:08:13 +02:00
Peter Lieven
7dd62aca61 pdu: add more debugging info for timed out commands
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-16 12:06:59 +02:00
Peter Lieven
0a3e157844 reconnect: copy scsi_timeout on reconnect
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-16 11:33:57 +02: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
cb4ad5f774 Connect: Don't use the TUR checks on re-connects
Only use TUR to eat any pending unit attentions on the initial connect
but not during reconnect.

From Peter Lieven <pl@kamp.de>

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-05-19 19:21:26 -07:00
Ronnie Sahlberg
45f667739c login.c: use uint32_t instead of u_int32_t
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-05-10 10:55:18 -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
6aa47691ce pdu: add known execptions to target serial processing
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-05-08 12:47:34 +02:00
Peter Lieven
a027931a2c init: simplify the case that the freelist is full in iscsi_sfree
if the freelist gets full we are likely in a low load situation so
we do not need to make all the work copying the pointers.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-05-05 14:14:26 +02: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
724f44c31b socket: change the order of POLLIN and POLLOUT in iscsi_service
the original idea of writing to the socket before reading was to put data
on the wire as early as possible and avoid potential latency increase due
to long taking callbacks invoked in iscsi_read_from_socket.

Benchmarking with libiscsi userland tools have shown that changing the
order increases throughput by about 5%.
The reason is that during POLLIN we might receive an updated MaxCmdSN
which might us allow to send new data out during POLLOUT.

For Qemu the change doesn't matter since POLLIN and POLLOUT are processed
independently.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-05-05 13:57:10 +02:00
Peter Lieven
e9d67540e1 add LIBISCSI_IGNORE_NOP_OUT_ON_STUCK_WAITPDU_QUEUE environment variable
this variable is a helper to tell libiscsi to not reset the nops_in_flight
on receival of a NOP-Out if the oldest element in the waitpdu queue is
not changed since the last NOP-Out.

The idea is that we can detect a command that the target silently dropped
by this mechanism and run into a NOP timeout forcing a reconnect.

This environment variable is not suitable if a command is send that is taking more than
the allowed timeout for a NOP-Out as a reply to a initiator generated NOP-In
(or several NOP-Outs if more than 1 in flight is allowed).

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-05-05 13:54:22 +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
Ronnie Sahlberg
39c4322c99 Merge pull request #161 from czankel/master
Fix '0block' write same and unmap tests and 'out-of-tree' builds
2015-04-26 09:30:18 -07:00
Peter Lieven
cd0f4a30d6 connect: fir off by one error in iscsi->reconnect_max_retries
Before b152d26 it was possible to set iscsi->reconnect_max_retries to 0.
This allowed reconnects, but aborted as soon as the reconnect failed.
The same behaviour is currenltly only possible by setting iscsi->reconnect_max_retries
to 1. iscsi->reconnect_max_retries == 0 forbids reconnecting completly.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-23 14:16:17 +02:00
Peter Lieven
52a6bdb774 Revert "lib: Make iscsi_realloc() update the freed pointer list"
iscsi_realloc MUST NOT be called with a pointer that is in the freelist
of small allocations. First they are free and secondly a realloc
will change the size of the small allocation to an unknown size.

This reverts commit d8de6531f8.
2015-04-23 14:12:57 +02:00
Chris Zankel
e186169064 build: fix 'out-of-tree' build
Prefix include paths with '${srcdir}' to allow 'out-of-tree' builds:

  cd $BUILD
  $LIBISCSI/configure
  make

Signed-off-by: Chris Zankel <chris@zankel.net>
2015-04-22 18:18:14 -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
Bart Van Assche
d8de6531f8 lib: Make iscsi_realloc() update the freed pointer list
This patch improves the stability of libiscsi by avoiding that
stale pointers are passed to free().

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
2015-04-20 06:57:31 -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
Peter Lieven
1f6d901324 socket: fix disconnected message for pending logouts
the check was not quite correct. iscsi->pending_reconnect can be true but
we are still connected (and thus can disconnect). This is the case when
we receive an async logout request.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-20 14:26:11 +02:00
Peter Lieven
fe75c0f10c pdu: remove redundant logout message
the message is redundant since 1bb06b33

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-20 14:16:52 +02:00
Ronnie Sahlberg
ec4eb766c7 reconnect: improve error message is reconnect is disabled
if reconnect is disabled then a failure in iscsi_service_reconnect_if_loggedin
can leak back to the application by iscsi_service returning an error
but the error string is not being updated.
Thus the applucation will print the last prevous error message that was set.

Change iscsi_service_reconnect_if_loggedin to print a less confusing
error message.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-04-16 08:12:49 -07:00
Peter Lieven
e4a448b115 init: don't close fd of iscsi->old_iscsi
its already closed at this point

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-16 11:58:39 +02:00
Peter Lieven
1bb06b337b login: log successful logout
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-16 11:58:33 +02:00
Peter Lieven
812d55d343 socket: do not show misleading disconnect message if we are not actually logged in
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-16 11:58:28 +02:00
Peter Lieven
f455f2f760 pdu: fix Target NOP-In debug output
the lun parameter was missing.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-14 10:05:18 +02: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
e219f1bb97 utils/examples: avoid busy waiting on wait for reconnect
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-13 10:26:28 +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
63fd8679fa reconnect: do not queue TESTUNIT_READY cdbs
those are part of the login process to consume UNIT_ATTENTIONS.

Its questionable if we should consume them at all, but iff we change
that behaviour we should do it for the initial login as well as
for a reconnect.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-13 10:06:32 +02:00
Ronnie Sahlberg
35b8d6a45f Merge pull request #151 from plieven/reconnect_async
Reconnect async
2015-04-10 06:26:59 -07:00
Ronnie Sahlberg
1a0897ae10 pdu.c: silently ignore any SCSI Async Events we receive
Just ignore any iSCSI AsyncMsg / SCSI Async Events we receive instead of
reconnecting. We can't pass the data back to the application anyway
with the current API.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-04-09 19:05:49 -07:00
Peter Lieven
47ea729d08 discovery: set cmdsn in discovery pdu
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-07 21:55:36 +02:00
Peter Lieven
d47b1ecec3 discovery: set cmdsn in discovery pdu
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-07 21:54:44 +02:00
Peter Lieven
a3e5c4d3c5 socket: allow iscsi_which_events to return 0
this is meant as a hint that there can be no event at the moment
and in this special case iscsi_service will return immediately.
We use this at the moment in the case of a wait for a reconnect
in which case we would enter a busy loop waiting for that
reconnect. The 0 means do not poll for the client application.
Do not poll, just wait a little (a few hundred ms) and call iscsi_which_events
again. The wait should be timer driven or at least non busy looping,
of course.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-02 08:34:52 +02:00
Peter Lieven
b7cb8fbf5a iscsi_service: dont return if a reconnect is pending but not yet reconnecting
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-04-02 08:31:53 +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