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>
This commit is contained in:
@@ -56,10 +56,13 @@ iscsi_scsi_response_cb(struct iscsi_context *iscsi, int status,
|
||||
case SCSI_STATUS_TASK_ABORTED:
|
||||
case SCSI_STATUS_ERROR:
|
||||
case SCSI_STATUS_CANCELLED:
|
||||
case SCSI_STATUS_TIMEOUT:
|
||||
scsi_cbdata->task->status = status;
|
||||
scsi_cbdata->callback(iscsi, status, scsi_cbdata->task,
|
||||
scsi_cbdata->private_data);
|
||||
return;
|
||||
default:
|
||||
scsi_cbdata->task->status = SCSI_STATUS_ERROR;
|
||||
iscsi_set_error(iscsi, "Cant handle scsi status %d yet.",
|
||||
status);
|
||||
scsi_cbdata->callback(iscsi, SCSI_STATUS_ERROR, scsi_cbdata->task,
|
||||
@@ -148,44 +151,6 @@ iscsi_send_data_out(struct iscsi_context *iscsi, struct iscsi_pdu *cmd_pdu,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
iscsi_timeout_scan(struct iscsi_context *iscsi)
|
||||
{
|
||||
struct iscsi_pdu *pdu;
|
||||
struct iscsi_pdu *next_pdu;
|
||||
time_t t = time(NULL);
|
||||
|
||||
for (pdu = iscsi->waitpdu; pdu; pdu = next_pdu) {
|
||||
struct iscsi_scsi_cbdata *scsi_cbdata;
|
||||
struct scsi_task *task;
|
||||
|
||||
next_pdu = pdu->next;
|
||||
|
||||
if (pdu->scsi_timeout == 0) {
|
||||
/* no timeout for this pdu */
|
||||
continue;
|
||||
}
|
||||
if (t < pdu->scsi_timeout) {
|
||||
/* not expired yet */
|
||||
continue;
|
||||
}
|
||||
if (pdu->outdata.data[0] != ISCSI_PDU_SCSI_REQUEST) {
|
||||
continue;
|
||||
}
|
||||
|
||||
scsi_cbdata = &pdu->scsi_cbdata;
|
||||
task = scsi_cbdata->task;
|
||||
|
||||
ISCSI_LIST_REMOVE(&iscsi->waitpdu, pdu);
|
||||
pdu->callback(iscsi, SCSI_STATUS_TIMEOUT,
|
||||
task, pdu->private_data);
|
||||
iscsi_set_error(iscsi, "SCSI command timed out");
|
||||
|
||||
/* task is freed by the sync caller */
|
||||
task->status = SCSI_STATUS_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
iscsi_send_unsolicited_data_out(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||
{
|
||||
@@ -1938,4 +1903,3 @@ iscsi_scsi_cancel_all_tasks(struct iscsi_context *iscsi)
|
||||
iscsi_free_pdu(iscsi, pdu);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
39
lib/pdu.c
39
lib/pdu.c
@@ -686,3 +686,42 @@ iscsi_pdu_set_expxferlen(struct iscsi_pdu *pdu, uint32_t expxferlen)
|
||||
pdu->expxferlen = expxferlen;
|
||||
scsi_set_uint32(&pdu->outdata.data[20], expxferlen);
|
||||
}
|
||||
|
||||
void
|
||||
iscsi_timeout_scan(struct iscsi_context *iscsi)
|
||||
{
|
||||
struct iscsi_pdu *pdu;
|
||||
struct iscsi_pdu *next_pdu;
|
||||
time_t t = time(NULL);
|
||||
|
||||
for (pdu = iscsi->outqueue; pdu; pdu = next_pdu) {
|
||||
next_pdu = pdu->next;
|
||||
|
||||
if (pdu->scsi_timeout == 0) {
|
||||
/* no timeout for this pdu */
|
||||
continue;
|
||||
}
|
||||
if (t < pdu->scsi_timeout) {
|
||||
/* not expired yet */
|
||||
continue;
|
||||
}
|
||||
ISCSI_LIST_REMOVE(&iscsi->outqueue, pdu);
|
||||
pdu->callback(iscsi, SCSI_STATUS_TIMEOUT,
|
||||
NULL, pdu->private_data);
|
||||
}
|
||||
for (pdu = iscsi->waitpdu; pdu; pdu = next_pdu) {
|
||||
next_pdu = pdu->next;
|
||||
|
||||
if (pdu->scsi_timeout == 0) {
|
||||
/* no timeout for this pdu */
|
||||
continue;
|
||||
}
|
||||
if (t < pdu->scsi_timeout) {
|
||||
/* not expired yet */
|
||||
continue;
|
||||
}
|
||||
ISCSI_LIST_REMOVE(&iscsi->waitpdu, pdu);
|
||||
pdu->callback(iscsi, SCSI_STATUS_TIMEOUT,
|
||||
NULL, pdu->private_data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -889,6 +889,8 @@ iscsi_service(struct iscsi_context *iscsi, int revents)
|
||||
return iscsi_service_reconnect_if_loggedin(iscsi);
|
||||
}
|
||||
}
|
||||
iscsi_timeout_scan(iscsi);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ event_loop(struct iscsi_context *iscsi, struct iscsi_sync_state *state)
|
||||
int ret;
|
||||
|
||||
while (state->finished == 0) {
|
||||
short revents;
|
||||
|
||||
pfd.fd = iscsi_get_fd(iscsi);
|
||||
pfd.events = iscsi_which_events(iscsi);
|
||||
|
||||
@@ -61,11 +63,8 @@ event_loop(struct iscsi_context *iscsi, struct iscsi_sync_state *state)
|
||||
state->status = -1;
|
||||
return;
|
||||
}
|
||||
if (ret == 0) {
|
||||
iscsi_timeout_scan(iscsi);
|
||||
continue;
|
||||
}
|
||||
if (iscsi_service(iscsi, pfd.revents) < 0) {
|
||||
revents = (ret == 0) ? 0 : pfd.revents;
|
||||
if (iscsi_service(iscsi, revents) < 0) {
|
||||
iscsi_set_error(iscsi,
|
||||
"iscsi_service failed with : %s",
|
||||
iscsi_get_error(iscsi));
|
||||
|
||||
Reference in New Issue
Block a user