lib/iscsi: Decrement conn->data_in_cnt of primary correctly for LUN hotplug

We had not decremented conn->data_in_cnt when the primary is removed
from conn->queued_datain_tasks after submitting it.

If we simply add decrement into iscsi_conn_free_tasks() and
_iscsi_conn_remove_lun(), it conflicts with iscsi_transfer_in().

By recent refinements, primary is freed in either spdk_iscsi_conn_free_pdu()
or iscsi_conn_free_tasks()/_iscsi_conn_remove_lun().

Hence let's make decrement of conn->data_in_cnt for primary follow
the management of primary.

In iscsi_conn_free_tasks()/_iscsi_conn_remove_lun(), if
primary->current_datain_offset, conn->data_in_cnt is incremented, and
hence decrement it.

In spdk_iscsi_conn_free_pdu(), if primary and all subtasks are
completed, decrement conn->data_in_cnt.

This patch will fix the issue that conn->data_in_cnt ls still
positive even after all tasks are freed when removing LUN dynamically.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I70cb431ab968387749ff7a5c77cd109904687797
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/474436
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ziye Yang <ziye.yang@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-11-15 13:07:39 +09:00 committed by Tomasz Zawadzki
parent 0110aad718
commit 39bdb45ed8
2 changed files with 7 additions and 10 deletions

View File

@ -324,6 +324,7 @@ spdk_iscsi_conn_free_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pd
if (spdk_iscsi_task_is_read(primary)) {
if (primary->bytes_completed == primary->scsi.transfer_len) {
/* Free the primary task after the last subtask done */
conn->data_in_cnt--;
spdk_iscsi_task_put(primary);
}
}
@ -356,6 +357,9 @@ iscsi_conn_free_tasks(struct spdk_iscsi_conn *conn)
TAILQ_FOREACH_SAFE(iscsi_task, &conn->queued_datain_tasks, link, tmp_iscsi_task) {
if (!iscsi_task->is_queued) {
TAILQ_REMOVE(&conn->queued_datain_tasks, iscsi_task, link);
if (iscsi_task->current_datain_offset > 0) {
conn->data_in_cnt--;
}
spdk_iscsi_task_put(iscsi_task);
}
}
@ -512,6 +516,9 @@ _iscsi_conn_remove_lun(void *_ctx)
TAILQ_FOREACH_SAFE(iscsi_task, &conn->queued_datain_tasks, link, tmp_iscsi_task) {
if ((!iscsi_task->is_queued) && (lun == iscsi_task->scsi.lun)) {
TAILQ_REMOVE(&conn->queued_datain_tasks, iscsi_task, link);
if (iscsi_task->current_datain_offset > 0) {
conn->data_in_cnt--;
}
spdk_iscsi_task_put(iscsi_task);
}
}

View File

@ -3026,16 +3026,6 @@ iscsi_transfer_in(struct spdk_iscsi_conn *conn, struct spdk_iscsi_task *task)
if (task->scsi.status != SPDK_SCSI_STATUS_GOOD) {
if (task != primary) {
conn->data_in_cnt--;
/* Handle the case when primary task return success but the subtask failed */
if (primary->bytes_completed == primary->scsi.transfer_len &&
primary->scsi.status == SPDK_SCSI_STATUS_GOOD) {
conn->data_in_cnt--;
}
} else {
/* handle the case that it is a primary task which has subtasks */
if (primary->scsi.transfer_len != primary->scsi.length) {
conn->data_in_cnt--;
}
}
return 0;