From f6d57ef3b0f03d1d85dd4ccaa4e660eb86f7ffc8 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 23 Sep 2014 17:23:27 -0700 Subject: [PATCH] connect.c: remove UA whitelist and just consume up to 10 UAs before failing Lets not use a whitelist of UnitAttentions that we consume during the connect phase. Instead we can just loop and fail after the 10th. If there are more than 10 UAs then we have a problem, otherwise just consume them all, forget them and then pass control back to the caller. Signed-off-by: Ronnie Sahlberg --- lib/connect.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/connect.c b/lib/connect.c index 94835fa..1c681ef 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -34,6 +34,7 @@ struct connect_task { iscsi_command_cb cb; void *private_data; int lun; + int num_uas; }; static void @@ -48,14 +49,24 @@ iscsi_testunitready_cb(struct iscsi_context *iscsi, int status, struct scsi_task *task = command_data; if (status != 0) { - if (task->sense.key == SCSI_SENSE_UNIT_ATTENTION - && (task->sense.ascq == SCSI_SENSE_ASCQ_BUS_RESET || - task->sense.ascq == SCSI_SENSE_ASCQ_POWER_ON_OCCURED || - task->sense.ascq == SCSI_SENSE_ASCQ_NEXUS_LOSS)) { + if (task->sense.key == SCSI_SENSE_UNIT_ATTENTION) { /* This is just the normal unitattention/busreset * you always get just after a fresh login. Try - * again. + * again. Instead of enumerating all of them we + * assume that there will be at most 10 or else + * there is something broken. */ + ct->num_uas++; + if (ct->num_uas > 10) { + iscsi_set_error(iscsi, "iscsi_testunitready " + "Too many UnitAttentions " + "during login."); + ct->cb(iscsi, SCSI_STATUS_ERROR, NULL, + ct->private_data); + iscsi_free(iscsi, ct); + scsi_free_scsi_task(task); + return; + } if (iscsi_testunitready_task(iscsi, ct->lun, iscsi_testunitready_cb, ct) == NULL) { @@ -166,6 +177,7 @@ iscsi_full_connect_async(struct iscsi_context *iscsi, const char *portal, } ct->cb = cb; ct->lun = lun; + ct->num_uas = 0; ct->private_data = private_data; if (iscsi_connect_async(iscsi, portal, iscsi_connect_cb, ct) != 0) { iscsi_free(iscsi, ct);