Skip to content

Commit 80363e1

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: tcm_qla2xxx: Make qlt_alloc_qfull_cmd() set cmd->se_cmd.map_tag
Reduce code duplication by introducing the tcm_qla2xxx_{get,rel}_cmd() functions. Introduce these functions in the tcm_qla2xxx.c source files such that the qla_target.c source file becomes independent of the SCSI target core header files. This patch fixes a bug, namely by ensuring that qlt_alloc_qfull_cmd() sets cmd->se_cmd.map_tag. Cc: Himanshu Madhani <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Himanshu Madhani <[email protected]> Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent bb6d3fb commit 80363e1

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

drivers/scsi/qla2xxx/qla_target.c

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#include <scsi/scsi.h>
2828
#include <scsi/scsi_host.h>
2929
#include <scsi/scsi_tcq.h>
30-
#include <target/target_core_base.h>
31-
#include <target/target_core_fabric.h>
3230

3331
#include "qla_def.h"
3432
#include "qla_target.h"
@@ -3816,7 +3814,7 @@ void qlt_free_cmd(struct qla_tgt_cmd *cmd)
38163814
return;
38173815
}
38183816
cmd->jiffies_at_free = get_jiffies_64();
3819-
target_free_tag(sess->se_sess, &cmd->se_cmd);
3817+
cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd);
38203818
}
38213819
EXPORT_SYMBOL(qlt_free_cmd);
38223820

@@ -4150,7 +4148,7 @@ static void __qlt_do_work(struct qla_tgt_cmd *cmd)
41504148
qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0);
41514149

41524150
qlt_decr_num_pend_cmds(vha);
4153-
target_free_tag(sess->se_sess, &cmd->se_cmd);
4151+
cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd);
41544152
spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
41554153

41564154
ha->tgt.tgt_ops->put_sess(sess);
@@ -4277,24 +4275,18 @@ static struct qla_tgt_cmd *qlt_get_tag(scsi_qla_host_t *vha,
42774275
struct fc_port *sess,
42784276
struct atio_from_isp *atio)
42794277
{
4280-
struct se_session *se_sess = sess->se_sess;
42814278
struct qla_tgt_cmd *cmd;
4282-
int tag, cpu;
42834279

4284-
tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu);
4285-
if (tag < 0)
4280+
cmd = vha->hw->tgt.tgt_ops->get_cmd(sess);
4281+
if (!cmd)
42864282
return NULL;
42874283

4288-
cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag];
4289-
memset(cmd, 0, sizeof(struct qla_tgt_cmd));
42904284
cmd->cmd_type = TYPE_TGT_CMD;
42914285
memcpy(&cmd->atio, atio, sizeof(*atio));
42924286
cmd->state = QLA_TGT_STATE_NEW;
42934287
cmd->tgt = vha->vha_tgt.qla_tgt;
42944288
qlt_incr_num_pend_cmds(vha);
42954289
cmd->vha = vha;
4296-
cmd->se_cmd.map_tag = tag;
4297-
cmd->se_cmd.map_cpu = cpu;
42984290
cmd->sess = sess;
42994291
cmd->loop_id = sess->loop_id;
43004292
cmd->conf_compl_supported = sess->conf_compl_supported;
@@ -5352,9 +5344,7 @@ qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
53525344
struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
53535345
struct qla_hw_data *ha = vha->hw;
53545346
struct fc_port *sess;
5355-
struct se_session *se_sess;
53565347
struct qla_tgt_cmd *cmd;
5357-
int tag, cpu;
53585348
unsigned long flags;
53595349

53605350
if (unlikely(tgt->tgt_stop)) {
@@ -5384,10 +5374,8 @@ qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
53845374
if (!sess)
53855375
return;
53865376

5387-
se_sess = sess->se_sess;
5388-
5389-
tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu);
5390-
if (tag < 0) {
5377+
cmd = ha->tgt.tgt_ops->get_cmd(sess);
5378+
if (!cmd) {
53915379
ql_dbg(ql_dbg_io, vha, 0x3009,
53925380
"qla_target(%d): %s: Allocation of cmd failed\n",
53935381
vha->vp_idx, __func__);
@@ -5402,9 +5390,6 @@ qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
54025390
return;
54035391
}
54045392

5405-
cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag];
5406-
memset(cmd, 0, sizeof(struct qla_tgt_cmd));
5407-
54085393
qlt_incr_num_pend_cmds(vha);
54095394
INIT_LIST_HEAD(&cmd->cmd_list);
54105395
memcpy(&cmd->atio, atio, sizeof(*atio));
@@ -5414,7 +5399,6 @@ qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
54145399
cmd->reset_count = ha->base_qpair->chip_reset;
54155400
cmd->q_full = 1;
54165401
cmd->qpair = ha->base_qpair;
5417-
cmd->se_cmd.map_cpu = cpu;
54185402

54195403
if (qfull) {
54205404
cmd->q_full = 1;

drivers/scsi/qla2xxx/qla_target.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ struct qla_tgt_func_tmpl {
671671
void (*handle_data)(struct qla_tgt_cmd *);
672672
int (*handle_tmr)(struct qla_tgt_mgmt_cmd *, u64, uint16_t,
673673
uint32_t);
674+
struct qla_tgt_cmd *(*get_cmd)(struct fc_port *);
675+
void (*rel_cmd)(struct qla_tgt_cmd *);
674676
void (*free_cmd)(struct qla_tgt_cmd *);
675677
void (*free_mcmd)(struct qla_tgt_mgmt_cmd *);
676678
void (*free_session)(struct fc_port *);

drivers/scsi/qla2xxx/tcm_qla2xxx.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,29 @@ static void tcm_qla2xxx_complete_free(struct work_struct *work)
268268
transport_generic_free_cmd(&cmd->se_cmd, 0);
269269
}
270270

271+
static struct qla_tgt_cmd *tcm_qla2xxx_get_cmd(struct fc_port *sess)
272+
{
273+
struct se_session *se_sess = sess->se_sess;
274+
struct qla_tgt_cmd *cmd;
275+
int tag, cpu;
276+
277+
tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu);
278+
if (tag < 0)
279+
return NULL;
280+
281+
cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag];
282+
memset(cmd, 0, sizeof(struct qla_tgt_cmd));
283+
cmd->se_cmd.map_tag = tag;
284+
cmd->se_cmd.map_cpu = cpu;
285+
286+
return cmd;
287+
}
288+
289+
static void tcm_qla2xxx_rel_cmd(struct qla_tgt_cmd *cmd)
290+
{
291+
target_free_tag(cmd->sess->se_sess, &cmd->se_cmd);
292+
}
293+
271294
/*
272295
* Called from qla_target_template->free_cmd(), and will call
273296
* tcm_qla2xxx_release_cmd via normal struct target_core_fabric_ops
@@ -1549,6 +1572,8 @@ static struct qla_tgt_func_tmpl tcm_qla2xxx_template = {
15491572
.handle_cmd = tcm_qla2xxx_handle_cmd,
15501573
.handle_data = tcm_qla2xxx_handle_data,
15511574
.handle_tmr = tcm_qla2xxx_handle_tmr,
1575+
.get_cmd = tcm_qla2xxx_get_cmd,
1576+
.rel_cmd = tcm_qla2xxx_rel_cmd,
15521577
.free_cmd = tcm_qla2xxx_free_cmd,
15531578
.free_mcmd = tcm_qla2xxx_free_mcmd,
15541579
.free_session = tcm_qla2xxx_free_session,

0 commit comments

Comments
 (0)