iscsi: Refactor a few of loop and branch and remove unnecessary initialization
This is to improve readability and clear logical structure. Change-Id: Ib67e03afb5a40df047f3829baad56656d90e5a54 Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/414927 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
a03934acbd
commit
9e21207a7c
@ -2115,7 +2115,7 @@ spdk_iscsi_op_login_rsp_handle(struct spdk_iscsi_conn *conn,
|
|||||||
struct spdk_iscsi_pdu *rsp_pdu, struct iscsi_param **params,
|
struct spdk_iscsi_pdu *rsp_pdu, struct iscsi_param **params,
|
||||||
int alloc_len)
|
int alloc_len)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc;
|
||||||
struct iscsi_bhs_login_rsp *rsph;
|
struct iscsi_bhs_login_rsp *rsph;
|
||||||
rsph = (struct iscsi_bhs_login_rsp *)&rsp_pdu->bhs;
|
rsph = (struct iscsi_bhs_login_rsp *)&rsp_pdu->bhs;
|
||||||
|
|
||||||
@ -2552,19 +2552,17 @@ spdk_get_scsi_task_from_ttt(struct spdk_iscsi_conn *conn,
|
|||||||
{
|
{
|
||||||
struct spdk_iscsi_pdu *pdu;
|
struct spdk_iscsi_pdu *pdu;
|
||||||
struct iscsi_bhs_data_in *datain_bhs;
|
struct iscsi_bhs_data_in *datain_bhs;
|
||||||
struct spdk_iscsi_task *task = NULL;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(pdu, &conn->snack_pdu_list, tailq) {
|
TAILQ_FOREACH(pdu, &conn->snack_pdu_list, tailq) {
|
||||||
if (pdu->bhs.opcode == ISCSI_OP_SCSI_DATAIN) {
|
if (pdu->bhs.opcode == ISCSI_OP_SCSI_DATAIN) {
|
||||||
datain_bhs = (struct iscsi_bhs_data_in *)&pdu->bhs;
|
datain_bhs = (struct iscsi_bhs_data_in *)&pdu->bhs;
|
||||||
if (from_be32(&datain_bhs->ttt) == transfer_tag) {
|
if (from_be32(&datain_bhs->ttt) == transfer_tag) {
|
||||||
task = pdu->task;
|
return pdu->task;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return task;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function returns the spdk_scsi_task by searching the snack list via
|
/* This function returns the spdk_scsi_task by searching the snack list via
|
||||||
@ -2575,18 +2573,16 @@ spdk_get_scsi_task_from_itt(struct spdk_iscsi_conn *conn,
|
|||||||
uint32_t task_tag, enum iscsi_op opcode)
|
uint32_t task_tag, enum iscsi_op opcode)
|
||||||
{
|
{
|
||||||
struct spdk_iscsi_pdu *pdu;
|
struct spdk_iscsi_pdu *pdu;
|
||||||
struct spdk_iscsi_task *task = NULL;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(pdu, &conn->snack_pdu_list, tailq) {
|
TAILQ_FOREACH(pdu, &conn->snack_pdu_list, tailq) {
|
||||||
if (pdu->bhs.opcode == opcode &&
|
if (pdu->bhs.opcode == opcode &&
|
||||||
pdu->task != NULL &&
|
pdu->task != NULL &&
|
||||||
pdu->task->tag == task_tag) {
|
pdu->task->tag == task_tag) {
|
||||||
task = pdu->task;
|
return pdu->task;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return task;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -2797,11 +2793,7 @@ spdk_iscsi_transfer_in(struct spdk_iscsi_conn *conn,
|
|||||||
}
|
}
|
||||||
primary->datain_datasn = DataSN;
|
primary->datain_datasn = DataSN;
|
||||||
|
|
||||||
if (sent_status) {
|
return sent_status;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2903,7 +2895,7 @@ int spdk_iscsi_conn_handle_queued_datain_tasks(struct spdk_iscsi_conn *conn)
|
|||||||
static int spdk_iscsi_op_scsi_read(struct spdk_iscsi_conn *conn,
|
static int spdk_iscsi_op_scsi_read(struct spdk_iscsi_conn *conn,
|
||||||
struct spdk_iscsi_task *task)
|
struct spdk_iscsi_task *task)
|
||||||
{
|
{
|
||||||
int32_t remaining_size = 0;
|
int32_t remaining_size;
|
||||||
|
|
||||||
TAILQ_INIT(&task->subtask_list);
|
TAILQ_INIT(&task->subtask_list);
|
||||||
task->scsi.dxfer_dir = SPDK_SCSI_DIR_FROM_DEV;
|
task->scsi.dxfer_dir = SPDK_SCSI_DIR_FROM_DEV;
|
||||||
@ -3545,37 +3537,30 @@ spdk_add_transfer_task(struct spdk_iscsi_conn *conn,
|
|||||||
|
|
||||||
void spdk_del_transfer_task(struct spdk_iscsi_conn *conn, uint32_t task_tag)
|
void spdk_del_transfer_task(struct spdk_iscsi_conn *conn, uint32_t task_tag)
|
||||||
{
|
{
|
||||||
struct spdk_iscsi_task *task;
|
struct spdk_iscsi_task *task, *tmp;
|
||||||
int found = 0;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < conn->pending_r2t; i++) {
|
for (i = 0; i < conn->pending_r2t; i++) {
|
||||||
if (conn->outstanding_r2t_tasks[i]->tag == task_tag) {
|
if (conn->outstanding_r2t_tasks[i]->tag == task_tag) {
|
||||||
task = conn->outstanding_r2t_tasks[i];
|
task = conn->outstanding_r2t_tasks[i];
|
||||||
conn->outstanding_r2t_tasks[i] = NULL;
|
|
||||||
conn->data_out_cnt -= task->data_out_cnt;
|
conn->data_out_cnt -= task->data_out_cnt;
|
||||||
found = 1;
|
|
||||||
|
conn->pending_r2t--;
|
||||||
|
for (; i < conn->pending_r2t; i++) {
|
||||||
|
conn->outstanding_r2t_tasks[i] = conn->outstanding_r2t_tasks[i + 1];
|
||||||
|
}
|
||||||
|
conn->outstanding_r2t_tasks[conn->pending_r2t] = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
|
||||||
for (; i < conn->pending_r2t - 1; i++) {
|
|
||||||
conn->outstanding_r2t_tasks[i] = conn->outstanding_r2t_tasks[i + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
conn->pending_r2t--;
|
|
||||||
conn->outstanding_r2t_tasks[conn->pending_r2t] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A large write was just completed, so if there are additional large
|
* A large write was just completed, so if there are additional large
|
||||||
* writes queued for R2Ts, start them now. But first check to make
|
* writes queued for R2Ts, start them now. But first check to make
|
||||||
* sure each of the tasks will fit without the connection's allotment
|
* sure each of the tasks will fit without the connection's allotment
|
||||||
* for total R2T tasks.
|
* for total R2T tasks.
|
||||||
*/
|
*/
|
||||||
while (!TAILQ_EMPTY(&conn->queued_r2t_tasks)) {
|
TAILQ_FOREACH_SAFE(task, &conn->queued_r2t_tasks, link, tmp) {
|
||||||
task = TAILQ_FIRST(&conn->queued_r2t_tasks);
|
|
||||||
if (conn->pending_r2t < DEFAULT_MAXR2T) {
|
if (conn->pending_r2t < DEFAULT_MAXR2T) {
|
||||||
TAILQ_REMOVE(&conn->queued_r2t_tasks, task, link);
|
TAILQ_REMOVE(&conn->queued_r2t_tasks, task, link);
|
||||||
spdk_add_transfer_task(conn, task);
|
spdk_add_transfer_task(conn, task);
|
||||||
@ -3878,28 +3863,21 @@ spdk_iscsi_remove_r2t_pdu_from_snack_list(struct spdk_iscsi_conn *conn,
|
|||||||
struct spdk_iscsi_task *task,
|
struct spdk_iscsi_task *task,
|
||||||
uint32_t r2t_sn)
|
uint32_t r2t_sn)
|
||||||
{
|
{
|
||||||
struct spdk_iscsi_pdu *pdu = NULL;
|
struct spdk_iscsi_pdu *pdu;
|
||||||
struct iscsi_bhs_r2t *r2t_header;
|
struct iscsi_bhs_r2t *r2t_header;
|
||||||
bool found_pdu = false;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(pdu, &conn->snack_pdu_list, tailq) {
|
TAILQ_FOREACH(pdu, &conn->snack_pdu_list, tailq) {
|
||||||
if (pdu->bhs.opcode == ISCSI_OP_R2T) {
|
if (pdu->bhs.opcode == ISCSI_OP_R2T) {
|
||||||
r2t_header = (struct iscsi_bhs_r2t *)&pdu->bhs;
|
r2t_header = (struct iscsi_bhs_r2t *)&pdu->bhs;
|
||||||
if (pdu->task == task &&
|
if (pdu->task == task &&
|
||||||
from_be32(&r2t_header->r2t_sn) == r2t_sn) {
|
from_be32(&r2t_header->r2t_sn) == r2t_sn) {
|
||||||
found_pdu = true;
|
TAILQ_REMOVE(&conn->snack_pdu_list, pdu, tailq);
|
||||||
break;
|
return pdu;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found_pdu) {
|
return NULL;
|
||||||
TAILQ_REMOVE(&conn->snack_pdu_list, pdu, tailq);
|
|
||||||
} else {
|
|
||||||
pdu = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pdu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is used re-send the r2t packet */
|
/* This function is used re-send the r2t packet */
|
||||||
@ -4169,10 +4147,9 @@ static int spdk_iscsi_op_data(struct spdk_iscsi_conn *conn,
|
|||||||
|
|
||||||
send_r2t_recovery_return:
|
send_r2t_recovery_return:
|
||||||
rc = spdk_iscsi_send_r2t_recovery(conn, task, task->acked_r2tsn, true);
|
rc = spdk_iscsi_send_r2t_recovery(conn, task, task->acked_r2tsn, true);
|
||||||
if (rc < 0) {
|
if (rc == 0) {
|
||||||
goto reject_return;
|
return 0;
|
||||||
}
|
}
|
||||||
return rc;
|
|
||||||
|
|
||||||
reject_return:
|
reject_return:
|
||||||
rc = spdk_iscsi_reject(conn, pdu, reject_reason);
|
rc = spdk_iscsi_reject(conn, pdu, reject_reason);
|
||||||
|
Loading…
Reference in New Issue
Block a user