Commit Graph

94 Commits

Author SHA1 Message Date
zhenwei pi
384191f57f Improve iSCSI PDU header dump
Dump iSCSI opcode firstly, then dump SCSI opcode for SCSI request.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-12-01 16:42:12 +08:00
zhenwei pi
addb11d64c Drain DATAOUT PDU on timeout
Describe the reason again:
A WRITE16 command[w] handles R2T, and queues DATAOUT PDU m,x,y,z:

          outqueue->DATAOUT[x]->DATAOUT[y]->DATAOUT[z]...
  outqueue_current->DATAOUT[m]
         waitqueue->WRITE16[w]...

1, Once x, y, z gets released in initiator side, the target still expects the remaining
DATAOUT PDUs.
2, Once command w timeout and callback to uplayer, uplayers usually releases memory of
   iscsi task(include memory referenced by iovec.iov_base). DATAOUT[m] would access
   invalid memory iovce.iov_base.

So invoke WRITEx command callback until draining DATAOUT PDUs.

Co-developed-by: Rui Zhang <zhangrui.1203@bytedance.com>
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-11-21 16:59:40 +08:00
zhenwei pi
4c3ac5464a Dump opcode string in iscsi_dump_pdu_header()
Now we have more friendly opcode message once error occurs:
libiscsi:1 command timed out from waitqueue [...]
libiscsi:2 PDU header: 01 c1 ... e9 88[READ16] 00 00 00 ...
                                       ^(human readable opcode string)

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-11-03 12:18:30 +08:00
zhenwei pi
a90520da3c Distinguish command timeout
Distinguish command timeout from outqueue or waitqueue. For example,
A command sequence:  ...NOP,READ,WRITE...

NOP OUT command has no dependence on backend media, it is expected to
response soon. Once NOP timeout in libiscsi:
a, the command is already sent to target, the target side does *not*
   response.
b, the command is still pending in libiscsi.

Separate the two cases for trouble shooting.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-11-03 10:54:11 +08:00
Li kunyu
82846758e1 pdu: Remove temporary variables from functions
Signed-off-by: Li kunyu <kunyu@nfschina.com>
2023-01-07 13:26:54 -08:00
sallyjunjun
1017435ca9 Fix segmentation fault problem.
When execute iscsi_task_mgmt_lun_reset_async function,
pdus are already removed from waitpdu list. In iscsi_service
function, this will call iscsi_process_pdu and release
pdu from waitpdu again, which cause segmentation fault.

Whether waitpud list is NULL should be checked here to avoid
the problem.

Signed-off-by: geruijun <geruijun@huawei.com>
2022-06-14 20:49:09 -07:00
Bart Van Assche
2a5a0b3291 Enable -Wno-unused-parameter
Instead of adding __attribute__((unused)) to unused arguments, add the
-Wno-unused-parameter compiler flag.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2021-05-23 13:23:41 -07:00
David Disseldorp
87272919ad pdu: fix use after free during cancellation
Fixes: 10868c4 ("libiscsi: Avoid discontinuities in cmdsn ordering in some cases")
Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-08-18 15:38:43 +02:00
Xie Yongji
e9c1f10258 pdu: Remove the checking for iscsi->is_loggedin in iscsi_cancel_pdus()
I don't see any problems that calling the callback
during connect/login in iscsi_cancel_pdus(). So let's
remove this check. Otherwise, we have no way to be aware
of a cancellation during login and cause something like
iscsi_login_sync() hangs.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
2020-06-23 19:45:18 +08:00
Xie Yongji
10868c491d libiscsi: Avoid discontinuities in cmdsn ordering in some cases
We should plug the cmdsn gap in order to continue
to use the session when the pdus is cancelled before
sending out.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
2020-06-23 19:45:14 +08:00
David Disseldorp
d42fcd89ce lib: use const for add_data buffers
The buffer is memcopied into the PDU. const makes it a little clearer
that the caller isn't handing over ownership.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2019-09-18 13:30:04 +02:00
Tim Crawford
9347cfebf2 Replace file variables with .dir-locals.el
Signed-off-by: Tim Crawford <tcrawford@datto.com>
2019-02-21 11:54:02 -05:00
David Disseldorp
9d31150e9d socket: improve ISCSI_HEADER_SIZE readability
The ISCSI_HEADER_SIZE macro accesses iscsi->header_size, so pass it in
as a parameter to make it easier to follow callers.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2018-10-25 23:38:59 +02: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
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
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
fa123fc397 abstract transport to static driver functions and opaque driver specific information.
This splits a transport into static driver specific functions for the common
iscsi commands. Optionally, a driver specific opaque memory is introduced
which is currently only used by iSER transport.
Last a lot of functions changed to static.

Signed-off-by: Peter Lieven <pl@kamp.de>
2016-08-05 11:28:43 +02:00
Ronnie Sahlberg
37507c994a Add back iscsi_queue_pdu
We need a public symbol for iscsi_queue_pdu. This is now just a
simple wrapper around iscsi->t->queue_pdu

https://github.com/sahlberg/libiscsi/issues/212

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-07-11 18:37:25 -07:00
Roy Shterman
6c1bdb4808 Libiscsi: Adding free_pdu function to transport abstraction
Signed-off-by: Roy Shterman <roysh@mellanox.com>
2016-06-03 18:47:23 -07:00
Roy Shterman
2671e10565 Libiscsi: Adding new_pdu function to transport abstraction
Signed-off-by: Roy Shterman <roysh@mellanox.com>
2016-06-03 18:45:44 -07:00
Peter Lieven
423b82efa4 pdu: check callback for NULL everywhere
Signed-off-by: Peter Lieven <pl@kamp.de>
2016-05-02 13:55:13 +02:00
Ronnie Sahlberg
99a5f99527 Add some emacs defaults. Tabs are 8 spaces.
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-02-18 21:34:43 -08: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
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
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
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
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
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
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
b152d26eb9 connect: make the reconnect async
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-31 16:21:00 +02:00
Peter Lieven
153e6ba07c pdu: set pdu->cmdsn when the pdu structure is updated
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-30 12:32:03 +02:00
Peter Lieven
7e97763155 nop: add even more SN debugging
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-30 09:02:42 +02:00
Peter Lieven
7fd58eca21 pdu: a target NOP-In may indiciate a changes MaxCmdSN or ExpCmdSN
RFC3720 10.19.  NOP-In
   NOP-In is either sent by a target as a response to a NOP-Out, as a
   "ping" to an initiator, or as a means to carry a changed ExpCmdSN
   and/or MaxCmdSN if another PDU will not be available for a long time
   (as determined by the target).
   ...

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-03-27 13:16:42 +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
Ronnie Sahlberg
aedced3b95 login.c: dont modify pdu->flags directly from iscsi_logout_async_internal
We no longer need to modify pdu->flags directly any more from
iscsi_logout_async_internal. We can just pass these as extra flags to
iscsi_allocate_pdu().

We also always set ISCSI_PDU_DROP_ON_RECONNECT unconditionally so there is
no need to pass this flag in from the callers in pdu.c .

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-23 20:39:37 -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
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
Peter Lieven
ac46262afa pdu: add workaround for DELL Equallogic FW bugs 71409 & 73732
Dell Equallogic storages may redirect connections from one member of a multi member storage
group to another. When the member that has the volume lead changes the storage issues
an async disconnect request message. The correct behaviour would be to either fail all I/O requests
with a check condition (waiting for logout) or fullfil requests until the time specified
in the disconnect request message has elapsed and then drop the connection. In firwamre 7.x
however the storage sometimes cancels requests with SENSE KEY:ILLEGAL_REQUEST(5)
ASCQ:LOGICAL_UNIT_NOT_SUPPORTED(0x2500). This leads to I/O errors propagated to the application.
This patch was reported in May 2014 to Dell and the initial bug 71409 has been fixed in 7.0.7.
However, the first fix did not entirely solve the problem and bug 73732 has been raised.

This patch adds an environment variable LIBISCSI_DROP_CONN_ON_ASYNC_EVENT1 which if set leads
to an immediate drop of the connection when such an async event is received. This is ugly, but
works around the I/O errors.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-10-28 09:20:05 +01:00
Paolo Bonzini
ce0723320c libiscsi: fix dangling pointer for outqueue_current
The outqueue_current PDU might also be in waitpdu if it does not have
ISCSI_PDU_DELETE_WHEN_SENT.  outqueue_current is freed after the
waitpdu list (for reconnect or defer_reconnect), or sometimes not
considered at all (for cancel), and this can cause a dangling pointer.

Keep outqueue_current up to date when a PDU is freed.  A bit hacky,
but it avoids touching code all over the place.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2014-06-17 14:59:50 +02: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
52c6b0d397 pdu: check callback on iscsi_process_reject
if the rejected packet is a NOP-Out it is legal
that it has no callback. In this case we end
up in a segfault.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:57:52 +02:00
Peter Lieven
f14f3ef6fe pdu: handle async events 2,3,4
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:56:43 +02:00
Peter Lieven
21e02c2078 pdu: catch rejected packets while target waits for logout
after a target has send the async target requests logout event it may
reject each request with a waiting for logout reason. Catch these
rejects if an outstanding request and the logout event overlap.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:54:05 +02:00