Commit Graph

1840 Commits

Author SHA1 Message Date
David Disseldorp
d7530757df examples: don't assume NOP-In data is zero terminated
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
4728d4eaa6 do not warn for strncpy
strncpy use in iscsi_reconnect is just fine.  Do not warn for it, and
also do not warn if clang does not recognize the flag.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
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
a7a14cc66c Merge pull request #271 from SexyC/master
Fix the 0 blocks writesame failed when target claims supporting maxim…
2018-10-02 06:45:14 +10:00
Ronnie Sahlberg
8f8632f0be Merge pull request #273 from franciozzy/isid_fix
Isid fix
2018-10-02 06:43:59 +10:00
Ronnie Sahlberg
29c0075ce7 Merge pull request #272 from franciozzy/reconnect_fixes
Reconnect fixes
2018-10-02 06:43:21 +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
yayang1
8a3375e459 Fix the 0 blocks writesame failed when target claims supporting maximum writesame length to LUN's total blocks number.
When target claim it support maximum writesame length to the total blocks number, when
we trigger 0blocks writesame opertion, we should expect it to be succeed instread of failure.
2018-09-28 02:31:28 +00:00
Ronnie Sahlberg
36548b4669 Merge pull request #267 from ddiss/prin_readkeys_truncate
fix handling of and test truncated PR-in read-keys responses
2018-06-01 08:04:27 +10:00
David Disseldorp
ab0e40d689 test-tool: add PrinReadKeys.Truncate test
This test registers PR key and then sends a PR-In read-keys request with
an ALLOCATION LENGTH value that forces response truncation. Ensure that
the ADDITIONAL LENGTH is *not* modified as a result of the truncation.

This test currently passes against TGT but fails against LIO (fix
pending).

Signed-off-by: David Disseldorp <ddiss@suse.de>
2018-05-31 23:31:17 +02: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
David Disseldorp
31ab1e1ac9 test-tool: add prin_read_keys() allocation_len parameter
Accepting an Allocation Length parameter allows us to test for
truncation of response data, as per SPC5r17 4.2.5.6:
  The device server shall terminate transfers to the Data-In Buffer when
  the number of bytes or blocks specified by the ALLOCATION LENGTH field
  have been transferred or when all available data have been
  transferred, whichever is less.

With this change, all existing prin_read_keys() callers continue to use
same ALLOCATION LENGTH value as earlier (16K).

Signed-off-by: David Disseldorp <ddiss@suse.de>
2018-05-31 23:08:39 +02:00
David Disseldorp
58642c6d72 tests: drop duplicate PR-unsupported log messages
The helper function -2 return paths already print this message, so the
duplicate in the caller can be dropped.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2018-05-29 16:43:19 +02:00
Ronnie Sahlberg
054528ed2d Merge pull request #265 from crobinso/container_of
iser: Use local container_of definition
2018-05-01 09:23:43 +10: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
8d5d0b241d Merge pull request #263 from bvanassche/master
Various fixes for the libiscsi test tool
2018-03-07 13:19:39 +10:00
Bart Van Assche
4d1918859f test-tool: Avoid crashes due to NULL-pointer dereferences
Avoid that certain test failures cause the test tool to trigger a
segmentation fault.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
2018-03-02 14:02:25 -08:00
Bart Van Assche
8f2abea4de test-tool/test_compareandwrite_simple: Limit the number of blocks used
Make sure that 'maxbl' does not exceed the LUN capacity.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
2018-03-02 14:02:25 -08:00
Bart Van Assche
18de10174b test-tool/test_compareandwrite_simple(): Fix end-of-LUN test
Make sure that the end-of-LUN test happens at the end of the LUN instead
of at the start of the LUN.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
2018-03-02 14:02:22 -08:00
Bart Van Assche
8f468b14fc test-tool/test_compareandwrite_*: Stop at end of medium
Since the argument num_blocks - i is passed as the LBA argument
to COMPAREANDWRITE(), avoid that a negative number is passed.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
2018-03-02 14:02:18 -08:00
Bart Van Assche
fee9eb9423 test-tool/test_async_lu_reset_simple: Continue upon reconnect error
Instead of stopping all tests if a reconnect fails, only stop
test_async_lu_reset_simple.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
2018-03-02 14:02:18 -08:00
Bart Van Assche
ba8cac6b05 test-tool, check_result(): Make failure output more informative
If a SCSI command fails, report the SCSI status code.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
2018-03-02 14:02:18 -08:00
Bart Van Assche
3cd40965a0 libiscsi: Port to gcc 7
Avoid that building with gcc 7 fails as follows:

iscsi-dd.c: In function 'cscd_ident_inq':
iscsi-dd.c:405:8: error: this statement may fall through [-Werror=implicit-fallthrough=]
     if (prev_type <= desig->designator_type) {
        ^
iscsi-dd.c:409:4: note: here
    default:
    ^~~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
2018-03-02 14:02:18 -08: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
Ronnie Sahlberg
0b5842f2c4 Merge pull request #256 from crawfxrd/no-auto-reconnect
Make iscsi_set_noautoreconnect public
2018-01-06 07:43:08 +10:00
Ronnie Sahlberg
fb498c9435 Merge pull request #258 from ddiss/fix_ws_0blk_unmap
test_writesame_unmap_until_end: fix unsupported fallback
2018-01-05 08:57:53 +10:00
Ronnie Sahlberg
fd6957736f Merge pull request #257 from avagin/opt
examples/iscsi-dd: parse the -x option
2018-01-05 08:37:15 +10:00
David Disseldorp
dc0c3c76c0 test_writesame_unmap_until_end: fix unsupported fallback
2e947cc1de added logic to check that
targets missing zero block writesame support return INVALID_FIELD_IN_CDB
to such requests. However, this change incorrectly set the writesame
number_of_logical_blocks field to one.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2017-12-20 17:54:18 +01:00
Andrei Vagin
07d03d5046 examples/iscsi-dd: parse the -x option
Signed-off-by: Andrei Vagin <avagin@openvz.org>
2017-12-15 03:45:00 +03:00
Tim Crawford
32cfd3c2f8 Make iscsi_set_noautoreconnect public
In our use at Datto, we have come across several issues related to the
automatic reconnect logic (mainly its interaction with POLLHUP). This
allows us to disable the functionality, at the expense of writing our
own reconnect logic.

Related: #241
2017-12-13 16:24:20 -05:00
Ronnie Sahlberg
aa617d1e5e Merge pull request #254 from franciozzy/master
PDU cancellation fixes for sync connect calls
2017-12-06 10:49:37 +10:00
Ronnie Sahlberg
b3bc7b022e Merge pull request #253 from crawfxrd/windows-fixes
Fix compilation with VS2017
2017-11-30 09:52:40 +10: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
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
Sushil
0593ac20de 251_SCSI Executing with SCSI device only (no ISCSI URL) ProutRegister test case failed
<iscsi-url> parameter absent handled for SCSI devices.

* Verbose logging segfault fixed.

* For ioctl case, if reservation conflicts hits it is not considered as
test case failure.
2017-11-09 06:15:06 +10:00