this patch adds a read of VPD page 0x80 (unit serial number) after successful login.
The serial is then validated on secutive reconnects to avoid the accidental mismatch
of LUN ids if some kind of remapping appears between loss of connection and a later
reconnect.
An additional url parameter force_usn is added to enforce the usn right from the beginning.
If not set via url or the new iscsi_set_unit_serial_number function the usn is learned
at the first successful login.
Signed-off-by: Peter Lieven <pl@dlhnet.de>
When an iSCSI connection enters the reconnection phase, the backoff
time (next_reconnect) increases with reconnection retry_cnt. However,
if the client detects that the target has recovered before reaching
next_reconnect, calling iscsi_reconnect/iscsi_force_reconnect has no
any effect, making fast reconnection impossible.
This patch introduces an interface to reset next_reconnect, so that
the client can reset the backoff time upon detecting target recovery
and achieve faster reconnection.
Resolves: https://github.com/sahlberg/libiscsi/issues/428
Signed-off-by: raywang <honglei.wang@smartx.com>
If a connection attempt is hung, then iscsi_reconnect() won't do anything. This
makes sense if we'd just re-try to connect to the same target, but if (for
example) login redirect might point us to a different, healthy, target, it
should be possible to restart the full connection process on request.
Signed-off-by: John Levon <john.levon@nutanix.com>
Instead of adding __attribute__((unused)) to unused arguments, add the
-Wno-unused-parameter compiler flag.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
This patch is used to fix the following problems in the current connection
method:
1. iscsi_iser_connect() waits until the connection is established or failed,
and may block the caller for a long time.
2. Although there's a cm_thread handles communication events, but in fact it
has no effects after the connection is established.
3. Resources are not released properly after reconnection failed. And once we
try to reconnect again, the resources will leak permanently.
(see iscsi_reconnect()).
This patch eliminate cm_thread and handle communication events in the caller
thread.
Connection procedure:
1. Create a mock fd by eventfd() (or just use old_iscsi->fd while reconnecting),
and assign it to iscsi->fd.
2. Create communication event channel, make it non-blocking and dup the
notifier fd to iscsi->fd.
3. Handle communication events by iscsi_which_events()/iscsi_service() loop
until connection established or falied.
4. If connection is established successfully, dup the notifier fd of completion
queue (CQ) events to iscsi->fd.
5. Handle completion queue (CQ) events by iscsi_which_events()/iscsi_service()
loop.
The entire procedure is non-blocking.
After established, whenever iscsi_service() is called with revents=0 or
queue_pdu() is called with a NOP pdu, communication events will be checked.
When connection failed, iser transport cleanup itself before callbacks.
Signed-off-by: wanghonghao <wanghonghao@bytedance.com>
A new iscsi context is created as TCP transport type, but currently
missing iscsi_init_transport to change transport to iser in
reconnecting logic, then iser could never reconnect successfully.
Use orignal transport to initialize new iscsi context.
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
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>
This fixes some identation in iscsi_reconnect_cb() where whitespaces
were used instead of hard tabs.
Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
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>
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>
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>
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>
we use the flag ISCSI_PDU_NO_CALLBACK and pdu->callback simultaneously, but
check only for one of them in various places. So drop ISCSI_PDU_NO_CALLBACK
and check for pdu->callback != NULL instead.
All PDUs that carried this flag have pdu->callback set to NULL.
Signed-off-by: Peter Lieven <pl@kamp.de>
if we drop a PDU which has a callback we should invoke it otherwise
the caller may wait infinetely for a command completion.
Signed-off-by: Peter Lieven <pl@kamp.de>
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.
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>
During reconnect we normally defer any SCSI commands that are issued
to be queued and sent later, once the re-connect has completed and we have
swapped the contexts.
This is what we want for almost all situations, except when we are
reconnecting very simple applications which request "no ua on reconnect".
For these applications we want to actually send the TURs that are used
during the login phase on the temporary context.
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
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>
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>
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>
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>
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>
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>
iscsi-ls show luns command does not work when the target redirects at login.
to avoid redundant code allow iscsi_full_connect_async to skip the testunit ready
part.
Signed-off-by: Peter Lieven <pl@kamp.de>
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>
The only PDU type that does not have ISCSI_PDU_DROP_ON_RECONNECT is the
SCSI COMMAND PDU. Thsi is the only PDU that we re-queue on reconnect.
All other, including DATA-OUT, NOP, task management, PDUs are simply
dropped.
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
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>
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>
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>
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>