Commit Graph

696 Commits

Author SHA1 Message Date
David Disseldorp
96dc6e7ebd socket: check for malloc failure before dereference
Signed-off-by: David Disseldorp <ddiss@suse.de>
2018-10-25 23:38:59 +02:00
David Disseldorp
15021faf19 lib: properly pass through NOP-In data segment
data_pos corresponds to the data_segment_length (+ padding), so should
always be passed to the NOP-In callback if greater than zero.

Fixes: https://github.com/sahlberg/libiscsi/issues/278

Signed-off-by: David Disseldorp <ddiss@suse.de>
2018-10-25 23:38:41 +02:00
Ronnie Sahlberg
04d6c326b8 Add some missing includes
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2018-10-17 05:43:10 +10:00
Ronnie Sahlberg
83dbc4ff84 Merge pull request #275 from franciozzy/isid_2
Call srand() only once
2018-10-17 05:39:44 +10:00
Ronnie Sahlberg
6fa5eaff13 Merge pull request #274 from bonzini/for-gcc-8
Fix warnings from Coverity and GCC 8
2018-10-09 08:11:58 +10:00
Felipe Franciosi
41af44eba1 iscsi_create_context: call srand() only once
iscsi_create_context() calls srand() every time a new context is
generated. That practice is questionable, as the seed does not need to
change before each call to rand(). As a matter of fact, doing so defeats
the purpose of using rand() altogether. Furthermore, the current
implementation is not thread safe.

This improves ISID generation by using /dev/urandom (when available) as
a seed, and calling srand() only once. In case of errors, fallback to
using something similar to the previous implementation (albeit
thread-safe).

Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
2018-10-05 18:10:07 +01:00
Paolo Bonzini
bffafc1c30 avoid truncation when logging message that includes target name 2018-10-04 14:06:39 +02:00
Paolo Bonzini
679d0abe7c avoid fallthrough 2018-10-04 14:06:39 +02:00
Paolo Bonzini
f507c94774 sync: remove unnecessary checks
state is always non-NULL in iscsi_sync_cb and iscsi_discovery_cb.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-10-04 14:06:39 +02:00
Paolo Bonzini
f0fcee72c4 iser: fix posting of receive descriptors
The old code is effectively always posting iser_conn->min_posted_rx
descriptors, since it is

   if (outstanding + iser_conn->min_posted_rx <= iser_conn->qp_max_recv_dtos) {
       if(iser_conn->qp_max_recv_dtos - outstanding > iser_conn->min_posted_rx)
           count = iser_conn->min_posted_rx;
       else
           count = iser_conn->qp_max_recv_dtos - outstanding;

which is equivalent to

    if(iser_conn->qp_max_recv_dtos - outstanding >= iser_conn->min_posted_rx)
        if(iser_conn->qp_max_recv_dtos - outstanding > iser_conn->min_posted_rx)
            count = iser_conn->min_posted_rx;
        else
            count = iser_conn->min_posted_rx;

So the "if" is redundant and the "min_posted_rx" is actually behaving more
like a _maximum_ number of posted descriptors in one iser_post_recvm.
Fix it with the (presumably) intended logic and remove a goto along
the way.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-10-04 14:06:39 +02:00
Ronnie Sahlberg
8f8632f0be Merge pull request #273 from franciozzy/isid_fix
Isid fix
2018-10-02 06:43:59 +10:00
Paolo Bonzini
346fb947cb iser_rcv_completion: unify error handling
Move the iscsi_set_error to iser_post_recv, and avoid leaking the
input buffer "in".

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-10-01 13:22:36 +02:00
Felipe Franciosi
50fb64df91 iscsi_create_context: improve ISID randomness
The current random seed for determining a new context's ISID is
calculated by XOR'ing time(), getpid() and "iscsi". When invoked from
iscsi_reconnect(), all three inputs are likely to be identical,
resulting on identical ISIDs.

That happens because iscsi_reconnect() malloc()s a temporary "iscsi"
which is then free()d at the end of the call. Successive calls to
malloc() (from that function) are therefore likely to reuse the same
address for the context.

When multiple sessions are used for different LUNs of the same target,
and reconnects happen within the same second (the precision given by
time()), then multiple login attempts will happen with identical values,
violating the ISID RULE as described in Section 3.4.3 of RFC3270.

This fixes the issue by introducing a sequence number to the ISID seed
generation.

Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
2018-09-30 19:32:06 +01:00
Felipe Franciosi
1891d502a0 iscsi_reconnect: improve local variable naming
The current iscsi context in iscsi_reconnect() is called "old_iscsi",
whilst the temporary context is called "iscsi". That is rather
confusing, and this fixes that by calling the current context "iscsi"
and the temporary context "tmp_iscsi".

Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
2018-09-30 11:38:38 +01:00
Felipe Franciosi
b377eece90 lib/connect.c: Fix whitespace formatting
This fixes some identation in iscsi_reconnect_cb() where whitespaces
were used instead of hard tabs.

Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
2018-09-30 11:12:30 +01:00
David Disseldorp
c88e9715ab lib/scsi: fix SCSI_PERSISTENT_RESERVE_READ_KEYS handling
When unmarshalling a SCSI_PERSISTENT_RESERVE_READ_KEYS response,
scsi_persistentreservein_datain_unmarshall() assumes that the ADDITIONAL
LENGTH field represents the number of keys packed in the key array.
This is incorrect as key array data buffer may be truncated while
ADDITIONAL LENGTH is left in tact, as per SPC5r17 4.2.5.6:

  If the information being transferred to the Data-In Buffer includes
  fields containing counts ..., then the contents of these fields shall
  not be altered to reflect the truncation, if any, that results from an
  insufficient ALLOCATION LENGTH value, unless the standard that
  describes the Data-In Buffer format states otherwise.

Determine the number of keys returned based on the minimum of the
data-in length and the ADDITIONAL LENGTH value.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2018-05-31 23:10:28 +02:00
Cole Robinson
f1feb218e2 iser: Use local container_of definition
The code was implicitly dependent on container_of from
inifiniband/verbs.h, however that's been removed in rdma-core
latest release:

ce0274acff

Define container_of locally if it's not already defined
2018-04-30 18:11:05 -04:00
Ronnie Sahlberg
7e459df828 Add iscsi_set_no_autoreconnect to the def and syms files
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2018-01-06 07:44:44 +10:00
Felipe Franciosi
25eb87c7ee sync: cancel pending pdus on error
The set of sync connect calls use a stack variable to track the
connection status. This is ok because such calls block on event_poll()
until the connection is established. However, event_poll may return
early in case of errors (or timeout) while PDUs are still queued on the
context (and pointing to a local stack).

This cancels any pending PDUs before returning from sync connect calls.

Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
2017-11-25 17:12:38 +00:00
Felipe Franciosi
3c4925e8da pdu: Introduce iscsi_cancel_pdus()
Introduce a helper exported from lib/pdu.c which cancels all pdus for a
given context. This patch eliminates repeated code from various other
files which have the same purpose. The only functional difference is
that the cancellation done from iscsi-command.c was (incorrectly) not
checking for iscsi->is_loggedin before issuing callbacks.

Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
2017-11-25 17:03:01 +00:00
Felipe Franciosi
5aafc29991 lib/pdu.c: Fix whitespace formatting
iscsi_queue_pdu used whitespaces for identation while the rest of the
file uses hard tabs.
2017-11-25 16:46:57 +00:00
Felipe Franciosi
28d0db9c96 lib/pdu.c: clean up empty lines
Remove some extra empty lines between functions.

Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
2017-11-25 16:44:30 +00:00
Tim Crawford
aba0f7da1a Replace WIN32 with _WIN32
Using WIN32 depends on the build environment defining the variable.
_WIN32 is a predefined MSVC macro and is always available.

Signed-off-by: Tim Crawford <crawfxrd@gmail.com>
2017-11-29 10:07:44 -05:00
Tim Crawford
cdb437c545 Fix compilation with VS2017
The primary issue is that in MSVC 14.00 (VS2015) Microsoft added
snprintf as a function to the standard library and prevents users from
defining it to something else (typically, this was _snprintf). So, only
define it when using _MSC_VER < 1900.

Other changes are:
- Fix macro definition of dup2
- Add macro for getpid
- Add function definition for win32_dup
- Add missing EXTERNs

Signed-off-by: Tim Crawford <crawfxrd@gmail.com>
2017-11-29 10:07:44 -05:00
Ronnie Sahlberg
12222077cc Add project file for iscsi-ls and make it build under visual studio
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-13 12:09:42 -07:00
Ronnie Sahlberg
f750101980 Add initial visual studio project files and fix the win32 build
Win32 has been rotting for a while. This patch adds vs17 build files
as well as fixing up all build errors that have accumulated.
There are still build warnings but those can be addressed in a followup
patch.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-11 21:19:14 -07:00
Ronnie Sahlberg
b1003dc75a Add URL arguments to enable/disable header digest
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-02-17 17:58:19 -08:00
Peter Lieven
b5210a1e31 sync: fix return value for various sync commands
all sync commands that return an integer value are
supposed to return a negative value on error.
However, state.status is positive non-zero on error.
Fix this by returning -1 if the state.status is
not SCSI_STATUS_GOOD.

Reported-by: Sitsofe Wheeler <sitsofe@yahoo.com>
Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-23 15:40:09 +01:00
Ronnie Sahlberg
179f6b33d4 Fix IPV6
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-01-08 12:57:12 -08:00
Ronnie Sahlberg
2eefdbb9e8 Lost patch when resolving conflicts
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-01-07 09:06:59 -08:00
Ronnie Sahlberg
178b3ec5b9 XCOPY: Only set the write flag if we actually have DATA-OUT
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-01-07 08:57:45 -08:00
Ronnie Sahlberg
33d0b63717 Merge branch 'master' into read_batch_pdu2 2017-01-07 08:42:12 -08:00
Peter Lieven
eb7c1d9b0c socket: process PDUs directly after receiving them
this eliminated the need for an inqueue

Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-06 11:48:17 +01:00
Peter Lieven
0225c662d0 socket: restore connected_portal info
this got lost in commit 0d6362f

Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-05 14:47:51 +01:00
Peter Lieven
1cbeec6bdc pdu: verify header digest
we never verified the received header digest. do that now.

Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-05 14:41:21 +01:00
Peter Lieven
443b104833 crc32c: use uint_t types
Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-05 14:39:15 +01:00
Peter Lieven
55eacac425 login: add logging for the negotiation login parameters
Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-05 12:33:47 +01:00
Peter Lieven
23738bf1c3 socket: calculate header checksum at the right place
we mangled the PDU header after calculating the checksum which
effectively broke CRC32C header digests completely.

Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-05 12:28:37 +01:00
Peter Lieven
ed1ed27dde socket: return in->hdr to smalloc pool
commit bc64420 introduced an extra smalloc for the in->hdr,
however it did use iscsi_free instead of iscsi_sfree to free it.

Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-05 12:19:20 +01:00
Peter Lieven
1a552a8afa socket: do not zero header of incoming PDU
we overwrite it anyway

Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-05 12:19:07 +01:00
Peter Lieven
c68d2c0ddb init: introduce iscsi_smalloc
Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-05 12:18:03 +01:00
David Disseldorp
4bc5f962e2 Libiscsi: add support for EXTENDED COPY
Build on existing scsi_cdb_extended_copy() functionality. This operation
can be used to offload inter and intra LU copies to the target.

The API is rather primitive, in that the caller needs to construct the
parameter buffer, including CSCD and segment descriptor lists, etc.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2017-01-04 19:33:00 +01:00
David Disseldorp
f475436c5a Libiscsi: add support for RECEIVE COPY RESULTS
Build on existing scsi_cdb_receive_copy_results() functionality. This
request is most commonly used to determine target-side EXTENDED COPY
operational parameters.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2017-01-04 19:33:00 +01:00
Peter Lieven
e058e825bf socket: break receive loop if there are no more outstanding PDUs
If the length of iscsi->waitpdu and iscsi->inqueue are the same
then except for any target initiated NOPs or async messages
we should have received any and all possible pdus from this
socket and can abort early.

This avoids running the loop one more time just to fail with EAGAIN
at the recs/readv. Just avoiding that recv/readv syscall will shave
at least 10us off this function and thus the latency.

Suggested-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-03 11:13:06 +01:00
Peter Lieven
b81e9a28a6 Batch pdu read in function iscsi_read_from_socket()
iscsi_read_from_socket can currently only read one PDU in each iscsi_service invocation even
if there is more data available on the socket. This patch reads all PDUs until the socket
would block. It enqueues all complete read PDUs and then processes them in order of arrival.

Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-02 15:52:19 +01:00
Ronnie Sahlberg
d7809374e1 Merge pull request #219 from vriera/master
Do not use -I/usr/include. This is unsafe when cross-compiling.
2016-11-14 17:12:36 -08:00
Michal Suchanek
a239423a0f Fix 32bit build.
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2016-11-14 17:28:31 +01:00
Vicente Olivert Riera
f27bdf64f0 Do not use -I/usr/include. This is considered unsafe when cross-compiling
Signed-off-by: Vicente Olivert Riera <Vincent.Riera@imgtec.com>
2016-10-16 10:53:13 +01:00
Ronnie Sahlberg
b8eb923009 New version 1.18.0
- Various updates to the test utility
- Add transport abstraction
- Add support for iSER
- Add iscsi_discovery_sync()

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-10-09 11:54:10 -07:00
Ronnie Sahlberg
d3ef192021 Add synchronous function iscsi_discovery_sync()
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-10-09 11:54:10 -07:00