lib/iscsi: Assert if conn->data_in_cnt goes negative or is left positive

During testing, we observed both conn->data_in_cnt went negative or was
left positive unexpectedly.  Hence add assert to detect both cases.

Signed-off-by: Ziye Yang <ziye.yang@intel.com>
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I102d4eb7c8beb0e56b6a46fd0f85b3eb1c447da5
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/474437
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>
This commit is contained in:
Shuhei Matsumoto 2019-11-15 13:22:52 +09:00 committed by Tomasz Zawadzki
parent 39bdb45ed8
commit 3c4dfbd339
2 changed files with 7 additions and 0 deletions

View File

@ -310,9 +310,11 @@ spdk_iscsi_conn_free_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pd
primary = spdk_iscsi_task_get_primary(pdu->task);
if (pdu->bhs.opcode == ISCSI_OP_SCSI_DATAIN) {
if (pdu->task->scsi.offset > 0) {
assert(conn->data_in_cnt > 0);
conn->data_in_cnt--;
if (pdu->bhs.flags & ISCSI_DATAIN_STATUS) {
/* Free the primary task after the last subtask done */
assert(conn->data_in_cnt > 0);
conn->data_in_cnt--;
spdk_iscsi_task_put(primary);
}
@ -324,6 +326,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 */
assert(conn->data_in_cnt > 0);
conn->data_in_cnt--;
spdk_iscsi_task_put(primary);
}
@ -358,6 +361,7 @@ iscsi_conn_free_tasks(struct spdk_iscsi_conn *conn)
if (!iscsi_task->is_queued) {
TAILQ_REMOVE(&conn->queued_datain_tasks, iscsi_task, link);
if (iscsi_task->current_datain_offset > 0) {
assert(conn->data_in_cnt > 0);
conn->data_in_cnt--;
}
spdk_iscsi_task_put(iscsi_task);
@ -517,6 +521,7 @@ _iscsi_conn_remove_lun(void *_ctx)
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) {
assert(conn->data_in_cnt > 0);
conn->data_in_cnt--;
}
spdk_iscsi_task_put(iscsi_task);
@ -587,6 +592,7 @@ iscsi_conn_stop(struct spdk_iscsi_conn *conn)
struct spdk_iscsi_tgt_node *target;
assert(conn->state == ISCSI_CONN_STATE_EXITED);
assert(conn->data_in_cnt == 0);
if (conn->sess != NULL &&
conn->sess->session_type == SESSION_TYPE_NORMAL &&

View File

@ -3025,6 +3025,7 @@ iscsi_transfer_in(struct spdk_iscsi_conn *conn, struct spdk_iscsi_task *task)
if (task->scsi.status != SPDK_SCSI_STATUS_GOOD) {
if (task != primary) {
assert(conn->data_in_cnt > 0);
conn->data_in_cnt--;
}