Commit 098d3227 authored by Ziye Yang's avatar Ziye Yang Committed by Jim Harris
Browse files

lib/iscsi: Add two parameters in spdk_iscsi_conn_write_pdu



This is prepared for the further call back usage.

Change-Id: Iccf304c87e67debfb4e7c330acc9cc233cc3ec48
Signed-off-by: default avatarZiye Yang <ziye.yang@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/481917


Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent d648dde6
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -302,11 +302,22 @@ error_return:
void
spdk_iscsi_conn_free_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
{
	iscsi_conn_xfer_complete_cb cb_fn;
	void *cb_arg;

	cb_fn = pdu->cb_fn;
	cb_arg = pdu->cb_arg;

	assert(cb_fn != NULL);
	pdu->cb_fn = NULL;

	if (pdu->task) {
		spdk_iscsi_task_put(pdu->task);
		spdk_iscsi_conn_handle_queued_datain_tasks(conn);
	}
	spdk_put_pdu(pdu);

	cb_fn(cb_arg);
}

static int
@@ -791,7 +802,7 @@ iscsi_send_logout_request(struct spdk_iscsi_conn *conn)
	to_be32(&rsph->exp_cmd_sn, conn->sess->ExpCmdSN);
	to_be32(&rsph->max_cmd_sn, conn->sess->MaxCmdSN);

	spdk_iscsi_conn_write_pdu(conn, rsp_pdu);
	spdk_iscsi_conn_write_pdu(conn, rsp_pdu, spdk_iscsi_conn_pdu_generic_complete, NULL);
}

static int
@@ -1254,7 +1265,7 @@ iscsi_conn_send_nopin(struct spdk_iscsi_conn *conn)
	to_be32(&rsp->stat_sn, conn->StatSN);
	to_be32(&rsp->exp_cmd_sn, conn->sess->ExpCmdSN);
	to_be32(&rsp->max_cmd_sn, conn->sess->MaxCmdSN);
	spdk_iscsi_conn_write_pdu(conn, rsp_pdu);
	spdk_iscsi_conn_write_pdu(conn, rsp_pdu, spdk_iscsi_conn_pdu_generic_complete, NULL);
	conn->last_nopin = spdk_get_ticks();
	conn->nop_outstanding = true;
}
@@ -1448,7 +1459,9 @@ _iscsi_conn_pdu_write_done(void *cb_arg, int err)
}

void
spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu,
			  iscsi_conn_xfer_complete_cb cb_fn,
			  void *cb_arg)
{
	uint32_t crc32c;
	ssize_t rc;
@@ -1476,6 +1489,8 @@ spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *p
		}
	}

	pdu->cb_fn = cb_fn;
	pdu->cb_arg = cb_arg;
	TAILQ_INSERT_TAIL(&conn->write_pdu_list, pdu, tailq);

	if (spdk_unlikely(conn->state >= ISCSI_CONN_STATE_EXITING)) {
+4 −1
Original line number Diff line number Diff line
@@ -225,9 +225,12 @@ int spdk_iscsi_conn_abort_queued_datain_tasks(struct spdk_iscsi_conn *conn,
int spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int len, void *buf);
int spdk_iscsi_conn_readv_data(struct spdk_iscsi_conn *conn,
			       struct iovec *iov, int iovcnt);
void spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu);
void spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu,
			       iscsi_conn_xfer_complete_cb cb_fn,
			       void *cb_arg);

void spdk_iscsi_conn_free_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu);

void spdk_iscsi_conn_info_json(struct spdk_json_write_ctx *w, struct spdk_iscsi_conn *conn);
void spdk_iscsi_conn_pdu_generic_complete(void *cb_arg);
#endif /* SPDK_ISCSI_CONN_H */
+18 −13
Original line number Diff line number Diff line
@@ -208,6 +208,11 @@ hex2bin(uint8_t *data, size_t data_len, const char *str)
	return total;
}

void
spdk_iscsi_conn_pdu_generic_complete(void *cb_arg)
{
}

static int
iscsi_reject(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu,
	     int reason)
@@ -287,7 +292,7 @@ iscsi_reject(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu,

	SPDK_LOGDUMP(SPDK_LOG_ISCSI, "PDU", (void *)&rsp_pdu->bhs, ISCSI_BHS_LEN);

	spdk_iscsi_conn_write_pdu(conn, rsp_pdu);
	spdk_iscsi_conn_write_pdu(conn, rsp_pdu, spdk_iscsi_conn_pdu_generic_complete, NULL);

	return 0;
}
@@ -1129,7 +1134,7 @@ iscsi_op_login_response(struct spdk_iscsi_conn *conn,
		rsph->flags &= ~ISCSI_LOGIN_CURRENT_STAGE_MASK;
		rsph->flags &= ~ISCSI_LOGIN_NEXT_STAGE_MASK;
	}
	spdk_iscsi_conn_write_pdu(conn, rsp_pdu);
	spdk_iscsi_conn_write_pdu(conn, rsp_pdu, spdk_iscsi_conn_pdu_generic_complete, NULL);

	/* after send PDU digest on/off */
	if (conn->full_feature) {
@@ -2411,7 +2416,7 @@ iscsi_pdu_payload_op_text(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *p
	to_be32(&rsph->exp_cmd_sn, conn->sess->ExpCmdSN);
	to_be32(&rsph->max_cmd_sn, conn->sess->MaxCmdSN);

	spdk_iscsi_conn_write_pdu(conn, rsp_pdu);
	spdk_iscsi_conn_write_pdu(conn, rsp_pdu, spdk_iscsi_conn_pdu_generic_complete, NULL);

	/* update internal variables */
	rc = spdk_iscsi_copy_param2var(conn);
@@ -2523,7 +2528,7 @@ iscsi_pdu_hdr_op_logout(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu
	rsph->time_2_wait = 0;
	rsph->time_2_retain = 0;

	spdk_iscsi_conn_write_pdu(conn, rsp_pdu);
	spdk_iscsi_conn_write_pdu(conn, rsp_pdu, spdk_iscsi_conn_pdu_generic_complete, NULL);

	if (conn->sess == NULL) {
		/*
@@ -2604,7 +2609,7 @@ iscsi_send_r2t(struct spdk_iscsi_conn *conn,
	rsp_pdu->task = task;
	task->scsi.ref++;

	spdk_iscsi_conn_write_pdu(conn, rsp_pdu);
	spdk_iscsi_conn_write_pdu(conn, rsp_pdu, spdk_iscsi_conn_pdu_generic_complete, NULL);

	return 0;
}
@@ -2657,7 +2662,7 @@ iscsi_send_r2t_recovery(struct spdk_iscsi_conn *conn,
	 */
	if (!send_new_r2tsn) {
		to_be32(&pdu->bhs.stat_sn, conn->StatSN);
		spdk_iscsi_conn_write_pdu(conn, pdu);
		spdk_iscsi_conn_write_pdu(conn, pdu, spdk_iscsi_conn_pdu_generic_complete, NULL);
	} else {
		rsph = (struct iscsi_bhs_r2t *)&pdu->bhs;
		transfer_len = from_be32(&rsph->desired_xfer_len);
@@ -2978,7 +2983,7 @@ iscsi_send_datain(struct spdk_iscsi_conn *conn,
		}
	}

	spdk_iscsi_conn_write_pdu(conn, rsp_pdu);
	spdk_iscsi_conn_write_pdu(conn, rsp_pdu, spdk_iscsi_conn_pdu_generic_complete, NULL);

	return DataSN;
}
@@ -3174,7 +3179,7 @@ void spdk_iscsi_task_response(struct spdk_iscsi_conn *conn,
	to_be32(&rsph->bi_read_res_cnt, 0);
	to_be32(&rsph->res_cnt, residual_len);

	spdk_iscsi_conn_write_pdu(conn, rsp_pdu);
	spdk_iscsi_conn_write_pdu(conn, rsp_pdu, spdk_iscsi_conn_pdu_generic_complete, NULL);
}

/*
@@ -3509,7 +3514,7 @@ spdk_iscsi_task_mgmt_response(struct spdk_iscsi_conn *conn,
	to_be32(&rsph->exp_cmd_sn, conn->sess->ExpCmdSN);
	to_be32(&rsph->max_cmd_sn, conn->sess->MaxCmdSN);

	spdk_iscsi_conn_write_pdu(conn, rsp_pdu);
	spdk_iscsi_conn_write_pdu(conn, rsp_pdu, spdk_iscsi_conn_pdu_generic_complete, NULL);
}

static void
@@ -3826,7 +3831,7 @@ iscsi_pdu_payload_op_nopout(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu
	to_be32(&rsph->exp_cmd_sn, conn->sess->ExpCmdSN);
	to_be32(&rsph->max_cmd_sn, conn->sess->MaxCmdSN);

	spdk_iscsi_conn_write_pdu(conn, rsp_pdu);
	spdk_iscsi_conn_write_pdu(conn, rsp_pdu, spdk_iscsi_conn_pdu_generic_complete, NULL);
	conn->last_nopin = spdk_get_ticks();

	return 0;
@@ -3963,7 +3968,7 @@ iscsi_handle_recovery_datain(struct spdk_iscsi_conn *conn,
				if (from_be32(&datain_header->itt) == task_tag &&
				    from_be32(&datain_header->data_sn) == i) {
					TAILQ_REMOVE(&conn->snack_pdu_list, old_pdu, tailq);
					spdk_iscsi_conn_write_pdu(conn, old_pdu);
					spdk_iscsi_conn_write_pdu(conn, old_pdu, old_pdu->cb_fn, old_pdu->cb_arg);
					break;
				}
			}
@@ -4020,7 +4025,7 @@ iscsi_handle_status_snack(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *p
				    beg_run);
		} else {
			TAILQ_REMOVE(&conn->snack_pdu_list, old_pdu, tailq);
			spdk_iscsi_conn_write_pdu(conn, old_pdu);
			spdk_iscsi_conn_write_pdu(conn, old_pdu, old_pdu->cb_fn, old_pdu->cb_arg);
		}
	}

@@ -4475,7 +4480,7 @@ iscsi_pdu_hdr_handle(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
			return SPDK_ISCSI_CONNECTION_FATAL;
		}
		init_login_reject_response(pdu, rsp_pdu);
		spdk_iscsi_conn_write_pdu(conn, rsp_pdu);
		spdk_iscsi_conn_write_pdu(conn, rsp_pdu, spdk_iscsi_conn_pdu_generic_complete, NULL);
		SPDK_ERRLOG("Received opcode %d in login phase\n", opcode);
		return SPDK_ISCSI_LOGIN_ERROR_RESPONSE;
	} else if (conn->state == ISCSI_CONN_STATE_INVALID) {
+5 −0
Original line number Diff line number Diff line
@@ -168,6 +168,8 @@ struct spdk_mobj {
 */
#define SPDK_ISCSI_MAX_SGL_DESCRIPTORS	(5)

typedef void (*iscsi_conn_xfer_complete_cb)(void *cb_arg);

struct spdk_iscsi_pdu {
	struct iscsi_bhs bhs;
	struct spdk_mobj *mobj;
@@ -192,6 +194,9 @@ struct spdk_iscsi_pdu {
	struct spdk_dif_ctx dif_ctx;
	struct spdk_iscsi_conn *conn;

	iscsi_conn_xfer_complete_cb		cb_fn;
	void					*cb_arg;

	/* The sock request ends with a 0 length iovec. Place the actual iovec immediately
	 * after it. There is a static assert below to check if the compiler inserted
	 * any unwanted padding */
+2 −1
Original line number Diff line number Diff line
@@ -190,7 +190,8 @@ DEFINE_STUB(spdk_iscsi_conn_readv_data, int,
	    (struct spdk_iscsi_conn *conn, struct iovec *iov, int iovcnt), 0);

void
spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu,
			  iscsi_conn_xfer_complete_cb cb_fn, void *cb_arg)
{
	TAILQ_INSERT_TAIL(&g_write_pdu_list, pdu, tailq);
}
Loading