mirror of
https://github.com/SCST-project/scst.git
synced 2026-10-22 06:02:33 +00:00
scst: Narrow transport temporary scopes
Move response headers, residuals, DMA state, FC/SRP target views and the QLA bitmap cursor into their consuming branches or loops. Remove the single-use QLA host alias and the redundant session-completion block; keep its stack completion alive through the existing wait. Preserve allocation and release order, transport ownership and callback signatures. QLogic edits remain within the SCST target subtree. Capture the SRPT management status immediately before response conversion, after request-limit accounting. Preserve its single evaluation while shortening the nested conversion expression. Keep this expression refactoring separate from the remaining LONG_LINE formatting changes. Cppcheck reports variableScope: The scope of the variable 'out_resid' can be reduced.
This commit is contained in:
@@ -824,7 +824,7 @@ static void iscsi_set_resid_no_scst_cmd(struct iscsi_cmnd *rsp)
|
||||
struct iscsi_scsi_cmd_hdr *req_hdr = cmnd_hdr(req);
|
||||
struct iscsi_scsi_rsp_hdr *rsp_hdr =
|
||||
(struct iscsi_scsi_rsp_hdr *)&rsp->pdu.bhs;
|
||||
int resid, out_resid;
|
||||
int resid;
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
@@ -836,7 +836,8 @@ static void iscsi_set_resid_no_scst_cmd(struct iscsi_cmnd *rsp)
|
||||
|
||||
if ((req_hdr->flags & ISCSI_CMD_READ) &&
|
||||
(req_hdr->flags & ISCSI_CMD_WRITE)) {
|
||||
out_resid = req->not_received_data_len;
|
||||
int out_resid = req->not_received_data_len;
|
||||
|
||||
if (out_resid > 0) {
|
||||
rsp_hdr->flags |= ISCSI_FLG_RESIDUAL_UNDERFLOW;
|
||||
rsp_hdr->residual_count = cpu_to_be32(out_resid);
|
||||
@@ -931,7 +932,6 @@ static void send_data_rsp(struct iscsi_cmnd *req, u8 status, int send_status)
|
||||
{
|
||||
struct iscsi_cmnd *rsp;
|
||||
struct iscsi_scsi_cmd_hdr *req_hdr = cmnd_hdr(req);
|
||||
struct iscsi_data_in_hdr *rsp_hdr;
|
||||
u32 pdusize, size, offset, sn;
|
||||
LIST_HEAD(send);
|
||||
|
||||
@@ -943,6 +943,8 @@ static void send_data_rsp(struct iscsi_cmnd *req, u8 status, int send_status)
|
||||
sn = 0;
|
||||
|
||||
while (1) {
|
||||
struct iscsi_data_in_hdr *rsp_hdr;
|
||||
|
||||
rsp = iscsi_alloc_rsp(req);
|
||||
TRACE_DBG("rsp %p", rsp);
|
||||
rsp->sg = req->sg;
|
||||
@@ -1060,10 +1062,10 @@ static void iscsi_tcp_send_data_rsp(struct iscsi_cmnd *req, u8 *sense, int sense
|
||||
(ISCSI_CMD_WRITE | ISCSI_CMD_READ)) {
|
||||
send_data_rsp(req, status, is_send_status);
|
||||
} else {
|
||||
struct iscsi_cmnd *rsp;
|
||||
|
||||
send_data_rsp(req, 0, 0);
|
||||
if (is_send_status) {
|
||||
struct iscsi_cmnd *rsp;
|
||||
|
||||
rsp = create_status_rsp(req, status, sense, sense_len);
|
||||
iscsi_cmnd_init_write(rsp, 0);
|
||||
}
|
||||
@@ -2682,13 +2684,14 @@ static void iscsi_tcp_set_req_data(struct iscsi_cmnd *req,
|
||||
static void nop_out_exec(struct iscsi_cmnd *req)
|
||||
{
|
||||
struct iscsi_cmnd *rsp;
|
||||
struct iscsi_nop_in_hdr *rsp_hdr;
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
TRACE_DBG("%p", req);
|
||||
|
||||
if (req->pdu.bhs.itt != ISCSI_RESERVED_TAG) {
|
||||
struct iscsi_nop_in_hdr *rsp_hdr;
|
||||
|
||||
rsp = iscsi_alloc_main_rsp(req);
|
||||
|
||||
rsp_hdr = (struct iscsi_nop_in_hdr *)&rsp->pdu.bhs;
|
||||
@@ -3350,9 +3353,9 @@ static int iscsi_tcp_send_locally(struct iscsi_cmnd *req,
|
||||
|
||||
static void iscsi_tcp_conn_close(struct iscsi_conn *conn, int flags)
|
||||
{
|
||||
struct sock *sk = conn->sock->sk;
|
||||
|
||||
if (!flags) {
|
||||
struct sock *sk = conn->sock->sk;
|
||||
|
||||
lock_sock(sk);
|
||||
sk->sk_prot->disconnect(sk, 0);
|
||||
release_sock(sk);
|
||||
|
||||
@@ -315,10 +315,10 @@ void isert_wr_release(struct isert_wr *wr)
|
||||
|
||||
if (isert_buf && isert_buf->is_alloced) {
|
||||
struct isert_device *isert_dev = wr->isert_dev;
|
||||
struct ib_device *ib_dev;
|
||||
|
||||
if (isert_buf->sg_cnt) {
|
||||
ib_dev = isert_dev->ib_dev;
|
||||
struct ib_device *ib_dev = isert_dev->ib_dev;
|
||||
|
||||
ib_dma_unmap_sg(ib_dev, isert_buf->sg,
|
||||
isert_buf->sg_cnt, isert_buf->dma_dir);
|
||||
}
|
||||
|
||||
@@ -143,13 +143,14 @@ static inline int isert_pdu_prepare_send(struct isert_conn *isert_conn, struct i
|
||||
{
|
||||
struct isert_device *isert_dev = isert_conn->isert_dev;
|
||||
struct ib_sge *sge = tx_pdu->wr[0].sge_list;
|
||||
size_t to_sync, size;
|
||||
size_t size;
|
||||
int sg_cnt = 0;
|
||||
|
||||
size = ISER_HDRS_SZ + tx_pdu->iscsi.pdu.ahssize +
|
||||
tx_pdu->iscsi.pdu.datasize;
|
||||
while (size) {
|
||||
to_sync = size > PAGE_SIZE ? PAGE_SIZE : size;
|
||||
size_t to_sync = size > PAGE_SIZE ? PAGE_SIZE : size;
|
||||
|
||||
ib_dma_sync_single_for_device(isert_dev->ib_dev, sge->addr,
|
||||
to_sync,
|
||||
DMA_TO_DEVICE);
|
||||
|
||||
@@ -213,10 +213,10 @@ void isert_post_drain(struct isert_conn *isert_conn)
|
||||
|
||||
void isert_conn_disconnect(struct isert_conn *isert_conn)
|
||||
{
|
||||
int err;
|
||||
|
||||
mutex_lock(&isert_conn->state_mutex);
|
||||
if (isert_conn->state != ISER_CONN_CLOSING) {
|
||||
int err;
|
||||
|
||||
isert_conn->state = ISER_CONN_CLOSING;
|
||||
|
||||
err = rdma_disconnect(isert_conn->cm_id);
|
||||
|
||||
@@ -98,7 +98,6 @@ size_t qlt_del_vtarget(u64 port_name)
|
||||
{
|
||||
struct qla_tgt *tgt, *t;
|
||||
scsi_qla_host_t *vha = NULL;
|
||||
struct Scsi_Host *shost;
|
||||
struct fc_host_attrs *fc_host;
|
||||
struct fc_vport *vport;
|
||||
unsigned long flags;
|
||||
@@ -107,6 +106,8 @@ size_t qlt_del_vtarget(u64 port_name)
|
||||
pr_info("%s: %llx", __func__, port_name);
|
||||
mutex_lock(&qla_tgt_mutex);
|
||||
list_for_each_entry_safe(tgt, t, &qla_tgt_glist, tgt_list_entry) {
|
||||
struct Scsi_Host *shost;
|
||||
|
||||
vha = tgt->vha;
|
||||
shost = vha->host;
|
||||
fc_host = shost_to_fc_host(shost);
|
||||
|
||||
@@ -199,10 +199,10 @@ static struct cmd_state_name {
|
||||
static char *cmdstate_to_str(uint8_t state)
|
||||
{
|
||||
int i;
|
||||
struct cmd_state_name *e;
|
||||
|
||||
for (i = 1; i < ARRAY_SIZE(cmd_str); i++) {
|
||||
e = cmd_str + i;
|
||||
const struct cmd_state_name *e = cmd_str + i;
|
||||
|
||||
if (state == e->state)
|
||||
return e->str;
|
||||
}
|
||||
@@ -243,10 +243,9 @@ int sqa_init_tag_bitmap(unsigned long **bitmap, unsigned int tag_num)
|
||||
SCST_KUNIT_VISIBLE
|
||||
int sqa_get_tag_bitmap(unsigned long *bitmap, unsigned int tag_num)
|
||||
{
|
||||
unsigned int tag;
|
||||
|
||||
for (;;) {
|
||||
tag = find_first_zero_bit(bitmap, tag_num);
|
||||
unsigned int tag = find_first_zero_bit(bitmap, tag_num);
|
||||
|
||||
if (tag >= tag_num)
|
||||
return -ENOENT;
|
||||
if (!test_and_set_bit(tag, bitmap))
|
||||
@@ -849,35 +848,32 @@ static void sqa_qla2xxx_free_session(struct fc_port *fcport)
|
||||
struct scsi_qla_host *vha = fcport->vha;
|
||||
struct se_session *se_sess = fcport->se_sess;
|
||||
struct scst_session *scst_sess = se_sess->fabric_sess_ptr;
|
||||
DECLARE_COMPLETION_ONSTACK(c);
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
TRACE_MGMT_DBG("sqatgt(%ld/%d): Deleting session %8phC fcid=%3phC\n",
|
||||
vha->host_no, vha->vp_idx, fcport->port_name, &fcport->d_id);
|
||||
|
||||
{
|
||||
DECLARE_COMPLETION_ONSTACK(c);
|
||||
|
||||
fcport->unreg_done = &c;
|
||||
/*
|
||||
* Use wait=0 (async) to avoid a severe stall under concurrent
|
||||
* session teardown. With wait=1 the workqueue thread blocks
|
||||
* inside scst_unregister_session() until
|
||||
* scst_free_session_callback() fires. That callback cannot be
|
||||
* scheduled until the TM thread processes SCST_UNREG_SESS_TM,
|
||||
* but the TM thread is blocked on scst_mutex which the global
|
||||
* management thread holds during concurrent session teardown
|
||||
* (scst_sess_free_tgt_devs -> synchronize_rcu()). Under load
|
||||
* this stall exceeds the hung-task timeout. With wait=0 the
|
||||
* workqueue thread is released immediately; we wait only on
|
||||
* fcport->unreg_done, signalled by sqa_free_session_done() at
|
||||
* a point where scst_mutex is not held.
|
||||
* See also: iscsi-scst session_free() which carries a similar
|
||||
* warning.
|
||||
*/
|
||||
scst_unregister_session(scst_sess, 0, sqa_free_session_done);
|
||||
wait_for_completion(&c);
|
||||
}
|
||||
fcport->unreg_done = &c;
|
||||
/*
|
||||
* Use wait=0 (async) to avoid a severe stall under concurrent
|
||||
* session teardown. With wait=1 the workqueue thread blocks
|
||||
* inside scst_unregister_session() until
|
||||
* scst_free_session_callback() fires. That callback cannot be
|
||||
* scheduled until the TM thread processes SCST_UNREG_SESS_TM,
|
||||
* but the TM thread is blocked on scst_mutex which the global
|
||||
* management thread holds during concurrent session teardown
|
||||
* (scst_sess_free_tgt_devs -> synchronize_rcu()). Under load
|
||||
* this stall exceeds the hung-task timeout. With wait=0 the
|
||||
* workqueue thread is released immediately; we wait only on
|
||||
* fcport->unreg_done, signalled by sqa_free_session_done() at
|
||||
* a point where scst_mutex is not held.
|
||||
* See also: iscsi-scst session_free() which carries a similar
|
||||
* warning.
|
||||
*/
|
||||
scst_unregister_session(scst_sess, 0, sqa_free_session_done);
|
||||
wait_for_completion(&c);
|
||||
|
||||
TRACE_MGMT_DBG("sqatgt(%ld/%d): Unregister completed %8phC done\n",
|
||||
vha->host_no, vha->vp_idx, fcport->port_name);
|
||||
@@ -1505,13 +1501,10 @@ done:
|
||||
static void sqa_get_target_list(void)
|
||||
{
|
||||
struct qla_tgt *tgt;
|
||||
struct scsi_qla_host *vha;
|
||||
|
||||
mutex_lock(&sqa_mutex);
|
||||
list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) {
|
||||
vha = tgt->vha;
|
||||
sqa_init_scst_tgt(vha);
|
||||
}
|
||||
list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry)
|
||||
sqa_init_scst_tgt(tgt->vha);
|
||||
mutex_unlock(&sqa_mutex);
|
||||
}
|
||||
|
||||
@@ -2232,7 +2225,6 @@ static int sqa_enable_tgt(struct scst_tgt *scst_tgt, bool enable)
|
||||
struct sqa_scst_tgt *sqa_tgt;
|
||||
struct qla_tgt *tgt;
|
||||
struct scsi_qla_host *vha;
|
||||
int rc;
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
@@ -2264,7 +2256,8 @@ static int sqa_enable_tgt(struct scst_tgt *scst_tgt, bool enable)
|
||||
0, 0, sqa_lport_callback);
|
||||
qlt_enable_vha(vha);
|
||||
} else {
|
||||
rc = qlt_stop_phase1(tgt);
|
||||
int rc = qlt_stop_phase1(tgt);
|
||||
|
||||
if (!rc)
|
||||
qlt_stop_phase2(tgt);
|
||||
}
|
||||
|
||||
+16
-11
@@ -751,11 +751,11 @@ static void srpt_unregister_mad_agent(struct srpt_device *sdev)
|
||||
struct ib_port_modify port_modify = {
|
||||
.clr_port_cap_mask = IB_PORT_DEVICE_MGMT_SUP,
|
||||
};
|
||||
struct srpt_port *sport;
|
||||
int i;
|
||||
|
||||
for (i = 1; i <= sdev->device->phys_port_cnt; i++) {
|
||||
sport = &sdev->port[i - 1];
|
||||
struct srpt_port *sport = &sdev->port[i - 1];
|
||||
|
||||
WARN_ON(sport->port != i);
|
||||
if (ib_modify_port(sdev->device, i, 0, &port_modify) < 0)
|
||||
pr_err("disabling MAD processing failed.\n");
|
||||
@@ -1628,7 +1628,7 @@ static int srpt_build_cmd_rsp(struct srpt_rdma_ch *ch,
|
||||
{
|
||||
struct scst_cmd *cmd = &ioctx->cmd;
|
||||
struct srp_rsp *srp_rsp;
|
||||
int resid, max_sense_len;
|
||||
int resid;
|
||||
|
||||
/*
|
||||
* The lowest bit of all SAM-3 status codes is zero (see also
|
||||
@@ -1665,6 +1665,8 @@ static int srpt_build_cmd_rsp(struct srpt_rdma_ch *ch,
|
||||
if (!scst_sense_valid(sense_data)) {
|
||||
sense_data_len = 0;
|
||||
} else {
|
||||
int max_sense_len;
|
||||
|
||||
BUILD_BUG_ON(sizeof(*srp_rsp) >= MIN_MAX_RSP_SIZE);
|
||||
max_sense_len = ch->max_ti_iu_len - sizeof(*srp_rsp);
|
||||
if (sense_data_len > max_sense_len) {
|
||||
@@ -2948,12 +2950,13 @@ static void srpt_cm_rej_recv(struct srpt_rdma_ch *ch,
|
||||
u8 private_data_len)
|
||||
{
|
||||
char *priv = NULL;
|
||||
int i;
|
||||
|
||||
if (private_data_len) {
|
||||
priv = kmalloc(private_data_len * 3 + 1, GFP_KERNEL);
|
||||
|
||||
if (priv) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < private_data_len; i++)
|
||||
sprintf(priv + 3 * i, " %02x", private_data[i]);
|
||||
}
|
||||
@@ -2968,8 +2971,6 @@ static void srpt_check_timeout(struct srpt_rdma_ch *ch)
|
||||
{
|
||||
struct ib_qp_attr attr;
|
||||
struct ib_qp_init_attr iattr;
|
||||
uint64_t T_tr_ns, max_compl_time_ms;
|
||||
uint64_t T_tr_ms;
|
||||
|
||||
if (ib_query_qp(ch->qp, &attr, IB_QP_TIMEOUT, &iattr) < 0) {
|
||||
pr_err("Querying QP attributes failed\n");
|
||||
@@ -2983,6 +2984,9 @@ static void srpt_check_timeout(struct srpt_rdma_ch *ch)
|
||||
*/
|
||||
WARN_ON(attr.timeout >= (1 << 5));
|
||||
if (attr.timeout) {
|
||||
u64 T_tr_ns, max_compl_time_ms;
|
||||
u64 T_tr_ms;
|
||||
|
||||
T_tr_ns = 1ULL << (12 + attr.timeout);
|
||||
max_compl_time_ms = attr.retry_cnt * 4 * T_tr_ns;
|
||||
do_div(max_compl_time_ms, 1000000);
|
||||
@@ -3339,9 +3343,6 @@ free_mem:
|
||||
static void srpt_unmap_sg_to_ib_sge(struct srpt_rdma_ch *ch,
|
||||
struct srpt_send_ioctx *ioctx)
|
||||
{
|
||||
struct scatterlist *sg;
|
||||
scst_data_direction dir;
|
||||
|
||||
EXTRACHECKS_BUG_ON(!ch);
|
||||
EXTRACHECKS_BUG_ON(!ioctx);
|
||||
|
||||
@@ -3356,6 +3357,9 @@ static void srpt_unmap_sg_to_ib_sge(struct srpt_rdma_ch *ch,
|
||||
ioctx->n_rdma = 0;
|
||||
|
||||
if (ioctx->mapped_sg_count) {
|
||||
struct scatterlist *sg;
|
||||
scst_data_direction dir;
|
||||
|
||||
EXTRACHECKS_WARN_ON(ioctx
|
||||
!= scst_cmd_get_tgt_priv(&ioctx->cmd));
|
||||
sg = ioctx->sg;
|
||||
@@ -3739,7 +3743,7 @@ static void srpt_tsk_mgmt_done(struct scst_mgmt_cmd *mcmnd)
|
||||
{
|
||||
struct srpt_rdma_ch *ch;
|
||||
struct srpt_send_ioctx *ioctx;
|
||||
int rsp_len;
|
||||
int rsp_len, status;
|
||||
|
||||
ioctx = scst_mgmt_cmd_get_tgt_priv(mcmnd);
|
||||
BUG_ON(!ioctx);
|
||||
@@ -3756,8 +3760,9 @@ static void srpt_tsk_mgmt_done(struct scst_mgmt_cmd *mcmnd)
|
||||
WARN_ON(ioctx->state == SRPT_STATE_DONE);
|
||||
|
||||
ioctx->req_lim_delta = srpt_inc_req_lim(ch);
|
||||
status = scst_mgmt_cmd_get_status(mcmnd);
|
||||
rsp_len = srpt_build_tskmgmt_rsp(ch, ioctx,
|
||||
scst_to_srp_tsk_mgmt_status(scst_mgmt_cmd_get_status(mcmnd)),
|
||||
scst_to_srp_tsk_mgmt_status(status),
|
||||
ioctx->tsk_mgmt.tag);
|
||||
/*
|
||||
* Note: the srpt_post_send() call below sends the task management
|
||||
|
||||
Reference in New Issue
Block a user