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>
This commit is contained in:
Ronnie Sahlberg
2015-12-13 14:29:32 -08:00
parent 74fc637eeb
commit 3c44092635
6 changed files with 29 additions and 1 deletions

View File

@@ -159,6 +159,7 @@ struct iscsi_context {
int scsi_timeout;
struct iscsi_context *old_iscsi;
int retry_cnt;
int no_ua_on_reconnect;
};
#define ISCSI_PDU_IMMEDIATE 0x40

View File

@@ -1305,6 +1305,12 @@ iscsi_set_bind_interfaces(struct iscsi_context *iscsi, char * interfaces);
EXTERN void
iscsi_set_reconnect_max_retries(struct iscsi_context *iscsi, int count);
/* Set to true to have libiscsi use TESTUNITREADY and consume any/all
UnitAttentions that may have triggered in the target.
*/
EXTERN void
iscsi_set_no_ua_on_reconnect(struct iscsi_context *iscsi, int state);
#ifdef __cplusplus
}
#endif

View File

@@ -130,7 +130,11 @@ iscsi_login_cb(struct iscsi_context *iscsi, int status, void *command_data _U_,
return;
}
if (ct->lun != -1 && !iscsi->old_iscsi) {
/* If the application has requested no UA on reconnect OR if this is
the initial connection attempt then we need to consume any/all
UAs that might be present.
*/
if (iscsi->no_ua_on_reconnect || (ct->lun != -1 && !iscsi->old_iscsi)) {
if (iscsi_testunitready_task(iscsi, ct->lun,
iscsi_testunitready_cb, ct) == NULL) {
iscsi_set_error(iscsi, "iscsi_testunitready_async failed.");
@@ -210,6 +214,18 @@ void iscsi_set_noautoreconnect(struct iscsi_context *iscsi, int state)
}
}
/* Set ua reconnect status. The default is that we just reconnect and then
any/all UAs that are generated by the target will be passed back to the
application.
For test applications it can be more convenient to just reconnect
and have any UAs be consumed and ignored by the library.
*/
void iscsi_set_no_ua_on_reconnect(struct iscsi_context *iscsi, int state)
{
iscsi->no_ua_on_reconnect = state;
}
void iscsi_set_reconnect_max_retries(struct iscsi_context *iscsi, int count)
{
iscsi->reconnect_max_retries = count;
@@ -413,6 +429,7 @@ int iscsi_reconnect(struct iscsi_context *old_iscsi)
iscsi->tcp_syncnt = old_iscsi->tcp_syncnt;
iscsi->cache_allocations = old_iscsi->cache_allocations;
iscsi->scsi_timeout = old_iscsi->scsi_timeout;
iscsi->no_ua_on_reconnect = old_iscsi->no_ua_on_reconnect;
iscsi->reconnect_max_retries = old_iscsi->reconnect_max_retries;

View File

@@ -98,6 +98,7 @@ iscsi_set_isid_en
iscsi_set_isid_oui
iscsi_set_isid_random
iscsi_set_isid_reserved
iscsi_set_no_ua_on_reconnect
iscsi_set_session_type
iscsi_set_target_username_pwd
iscsi_set_targetname

View File

@@ -96,6 +96,7 @@ iscsi_set_isid_en
iscsi_set_isid_oui
iscsi_set_isid_random
iscsi_set_isid_reserved
iscsi_set_no_ua_on_reconnect
iscsi_set_session_type
iscsi_set_target_username_pwd
iscsi_set_targetname

View File

@@ -769,6 +769,7 @@ suite_init(void)
"error: Failed to login to target for test set-up\n");
return 1;
}
iscsi_set_no_ua_on_reconnect(mp_sds[i]->iscsi_ctx, 1);
}
#ifndef HAVE_CU_SUITEINFO_PSETUPFUNC
/* libcunit version 1 */
@@ -961,6 +962,7 @@ static int connect_scsi_device(struct scsi_device *sdev, const char *initiatorna
if (sdev->iscsi_ctx == NULL) {
return -1;
}
iscsi_set_no_ua_on_reconnect(sdev->iscsi_ctx, 1);
return 0;
}
#ifdef HAVE_SG_IO