Skip to content

Commit a36840d

Browse files
ssudhakarpmartinkpetersen
authored andcommitted
scsi: target: Initialize LUN in transport_init_se_cmd()
Initialization of orig_fe_lun is moved to transport_init_se_cmd() from transport_lookup_cmd_lun(). This helps for the cases where the SCSI request fails before the call to transport_lookup_cmd_lun() so that trace_target_cmd_complete() can print the LUN information to the trace buffer. Due to this change, the lun parameter is removed from transport_lookup_cmd_lun() and transport_lookup_tmr_lun(). Link: https://lore.kernel.org/r/1591559913-8388-3-git-send-email-sudhakar.panneerselvam@oracle.com Reviewed-by: Mike Christie <[email protected]> Signed-off-by: Sudhakar Panneerselvam <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent f98c2dd commit a36840d

File tree

7 files changed

+31
-31
lines changed

7 files changed

+31
-31
lines changed

drivers/target/iscsi/iscsi_target.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ int iscsit_setup_scsi_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
11581158
transport_init_se_cmd(&cmd->se_cmd, &iscsi_ops,
11591159
conn->sess->se_sess, be32_to_cpu(hdr->data_length),
11601160
cmd->data_direction, sam_task_attr,
1161-
cmd->sense_buffer + 2);
1161+
cmd->sense_buffer + 2, scsilun_to_int(&hdr->lun));
11621162

11631163
pr_debug("Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x,"
11641164
" ExpXferLen: %u, Length: %u, CID: %hu\n", hdr->itt,
@@ -1167,8 +1167,7 @@ int iscsit_setup_scsi_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
11671167

11681168
target_get_sess_cmd(&cmd->se_cmd, true);
11691169

1170-
cmd->sense_reason = transport_lookup_cmd_lun(&cmd->se_cmd,
1171-
scsilun_to_int(&hdr->lun));
1170+
cmd->sense_reason = transport_lookup_cmd_lun(&cmd->se_cmd);
11721171
if (cmd->sense_reason)
11731172
goto attach_cmd;
11741173

@@ -2000,7 +1999,8 @@ iscsit_handle_task_mgt_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
20001999

20012000
transport_init_se_cmd(&cmd->se_cmd, &iscsi_ops,
20022001
conn->sess->se_sess, 0, DMA_NONE,
2003-
TCM_SIMPLE_TAG, cmd->sense_buffer + 2);
2002+
TCM_SIMPLE_TAG, cmd->sense_buffer + 2,
2003+
scsilun_to_int(&hdr->lun));
20042004

20052005
target_get_sess_cmd(&cmd->se_cmd, true);
20062006

@@ -2038,8 +2038,7 @@ iscsit_handle_task_mgt_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
20382038
* Locate the struct se_lun for all TMRs not related to ERL=2 TASK_REASSIGN
20392039
*/
20402040
if (function != ISCSI_TM_FUNC_TASK_REASSIGN) {
2041-
ret = transport_lookup_tmr_lun(&cmd->se_cmd,
2042-
scsilun_to_int(&hdr->lun));
2041+
ret = transport_lookup_tmr_lun(&cmd->se_cmd);
20432042
if (ret < 0) {
20442043
se_tmr->response = ISCSI_TMF_RSP_NO_LUN;
20452044
goto attach;

drivers/target/target_core_device.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static struct se_hba *lun0_hba;
4545
struct se_device *g_lun0_dev;
4646

4747
sense_reason_t
48-
transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
48+
transport_lookup_cmd_lun(struct se_cmd *se_cmd)
4949
{
5050
struct se_lun *se_lun = NULL;
5151
struct se_session *se_sess = se_cmd->se_sess;
@@ -54,7 +54,7 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
5454
sense_reason_t ret = TCM_NO_SENSE;
5555

5656
rcu_read_lock();
57-
deve = target_nacl_find_deve(nacl, unpacked_lun);
57+
deve = target_nacl_find_deve(nacl, se_cmd->orig_fe_lun);
5858
if (deve) {
5959
atomic_long_inc(&deve->total_cmds);
6060

@@ -74,7 +74,6 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
7474

7575
se_cmd->se_lun = se_lun;
7676
se_cmd->pr_res_key = deve->pr_res_key;
77-
se_cmd->orig_fe_lun = unpacked_lun;
7877
se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD;
7978
se_cmd->lun_ref_active = true;
8079

@@ -83,7 +82,7 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
8382
pr_err("TARGET_CORE[%s]: Detected WRITE_PROTECTED LUN"
8483
" Access for 0x%08llx\n",
8584
se_cmd->se_tfo->fabric_name,
86-
unpacked_lun);
85+
se_cmd->orig_fe_lun);
8786
rcu_read_unlock();
8887
ret = TCM_WRITE_PROTECTED;
8988
goto ref_dev;
@@ -98,18 +97,17 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
9897
* REPORT_LUNS, et al to be returned when no active
9998
* MappedLUN=0 exists for this Initiator Port.
10099
*/
101-
if (unpacked_lun != 0) {
100+
if (se_cmd->orig_fe_lun != 0) {
102101
pr_err("TARGET_CORE[%s]: Detected NON_EXISTENT_LUN"
103102
" Access for 0x%08llx from %s\n",
104103
se_cmd->se_tfo->fabric_name,
105-
unpacked_lun,
104+
se_cmd->orig_fe_lun,
106105
nacl->initiatorname);
107106
return TCM_NON_EXISTENT_LUN;
108107
}
109108

110109
se_lun = se_sess->se_tpg->tpg_virt_lun0;
111110
se_cmd->se_lun = se_sess->se_tpg->tpg_virt_lun0;
112-
se_cmd->orig_fe_lun = 0;
113111
se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD;
114112

115113
percpu_ref_get(&se_lun->lun_ref);
@@ -145,7 +143,7 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
145143
}
146144
EXPORT_SYMBOL(transport_lookup_cmd_lun);
147145

148-
int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
146+
int transport_lookup_tmr_lun(struct se_cmd *se_cmd)
149147
{
150148
struct se_dev_entry *deve;
151149
struct se_lun *se_lun = NULL;
@@ -155,7 +153,7 @@ int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
155153
unsigned long flags;
156154

157155
rcu_read_lock();
158-
deve = target_nacl_find_deve(nacl, unpacked_lun);
156+
deve = target_nacl_find_deve(nacl, se_cmd->orig_fe_lun);
159157
if (deve) {
160158
se_lun = rcu_dereference(deve->se_lun);
161159

@@ -166,7 +164,6 @@ int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
166164

167165
se_cmd->se_lun = se_lun;
168166
se_cmd->pr_res_key = deve->pr_res_key;
169-
se_cmd->orig_fe_lun = unpacked_lun;
170167
se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD;
171168
se_cmd->lun_ref_active = true;
172169
}
@@ -177,7 +174,7 @@ int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
177174
pr_debug("TARGET_CORE[%s]: Detected NON_EXISTENT_LUN"
178175
" Access for 0x%08llx for %s\n",
179176
se_cmd->se_tfo->fabric_name,
180-
unpacked_lun,
177+
se_cmd->orig_fe_lun,
181178
nacl->initiatorname);
182179
return -ENODEV;
183180
}

drivers/target/target_core_tmr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ void core_tmr_abort_task(
148148
* code.
149149
*/
150150
if (!tmr->tmr_dev)
151-
WARN_ON_ONCE(transport_lookup_tmr_lun(tmr->task_cmd,
152-
se_cmd->orig_fe_lun) < 0);
151+
WARN_ON_ONCE(transport_lookup_tmr_lun(tmr->task_cmd) <
152+
0);
153153

154154
target_put_cmd_and_wait(se_cmd);
155155

drivers/target/target_core_transport.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ void transport_init_se_cmd(
13641364
u32 data_length,
13651365
int data_direction,
13661366
int task_attr,
1367-
unsigned char *sense_buffer)
1367+
unsigned char *sense_buffer, u64 unpacked_lun)
13681368
{
13691369
INIT_LIST_HEAD(&cmd->se_delayed_node);
13701370
INIT_LIST_HEAD(&cmd->se_qf_node);
@@ -1383,6 +1383,7 @@ void transport_init_se_cmd(
13831383
cmd->data_direction = data_direction;
13841384
cmd->sam_task_attr = task_attr;
13851385
cmd->sense_buffer = sense_buffer;
1386+
cmd->orig_fe_lun = unpacked_lun;
13861387

13871388
cmd->state_active = false;
13881389
}
@@ -1596,7 +1597,8 @@ int target_submit_cmd_map_sgls(struct se_cmd *se_cmd, struct se_session *se_sess
15961597
* target_core_fabric_ops->queue_status() callback
15971598
*/
15981599
transport_init_se_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess,
1599-
data_length, data_dir, task_attr, sense);
1600+
data_length, data_dir, task_attr, sense,
1601+
unpacked_lun);
16001602

16011603
if (flags & TARGET_SCF_USE_CPUID)
16021604
se_cmd->se_cmd_flags |= SCF_USE_CPUID;
@@ -1622,7 +1624,7 @@ int target_submit_cmd_map_sgls(struct se_cmd *se_cmd, struct se_session *se_sess
16221624
/*
16231625
* Locate se_lun pointer and attach it to struct se_cmd
16241626
*/
1625-
rc = transport_lookup_cmd_lun(se_cmd, unpacked_lun);
1627+
rc = transport_lookup_cmd_lun(se_cmd);
16261628
if (rc) {
16271629
transport_send_check_condition_and_sense(se_cmd, rc, 0);
16281630
target_put_sess_cmd(se_cmd);
@@ -1790,7 +1792,7 @@ int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess,
17901792
BUG_ON(!se_tpg);
17911793

17921794
transport_init_se_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess,
1793-
0, DMA_NONE, TCM_SIMPLE_TAG, sense);
1795+
0, DMA_NONE, TCM_SIMPLE_TAG, sense, unpacked_lun);
17941796
/*
17951797
* FIXME: Currently expect caller to handle se_cmd->se_tmr_req
17961798
* allocation failure.
@@ -1818,7 +1820,7 @@ int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess,
18181820
goto failure;
18191821
}
18201822

1821-
ret = transport_lookup_tmr_lun(se_cmd, unpacked_lun);
1823+
ret = transport_lookup_tmr_lun(se_cmd);
18221824
if (ret)
18231825
goto failure;
18241826

drivers/target/target_core_xcopy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ static int target_xcopy_read_source(
585585
(unsigned long long)src_lba, src_sectors, length);
586586

587587
transport_init_se_cmd(se_cmd, &xcopy_pt_tfo, &xcopy_pt_sess, length,
588-
DMA_FROM_DEVICE, 0, &xpt_cmd.sense_buffer[0]);
588+
DMA_FROM_DEVICE, 0, &xpt_cmd.sense_buffer[0], 0);
589589

590590
rc = target_xcopy_setup_pt_cmd(&xpt_cmd, xop, src_dev, &cdb[0],
591591
remote_port);
@@ -630,7 +630,7 @@ static int target_xcopy_write_destination(
630630
(unsigned long long)dst_lba, dst_sectors, length);
631631

632632
transport_init_se_cmd(se_cmd, &xcopy_pt_tfo, &xcopy_pt_sess, length,
633-
DMA_TO_DEVICE, 0, &xpt_cmd.sense_buffer[0]);
633+
DMA_TO_DEVICE, 0, &xpt_cmd.sense_buffer[0], 0);
634634

635635
rc = target_xcopy_setup_pt_cmd(&xpt_cmd, xop, dst_dev, &cdb[0],
636636
remote_port);

drivers/usb/gadget/function/f_tcm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,8 @@ static void usbg_cmd_work(struct work_struct *work)
10491049
transport_init_se_cmd(se_cmd,
10501050
tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo,
10511051
tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE,
1052-
cmd->prio_attr, cmd->sense_iu.sense);
1052+
cmd->prio_attr, cmd->sense_iu.sense,
1053+
cmd->unpacked_lun);
10531054
goto out;
10541055
}
10551056

@@ -1179,7 +1180,8 @@ static void bot_cmd_work(struct work_struct *work)
11791180
transport_init_se_cmd(se_cmd,
11801181
tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo,
11811182
tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE,
1182-
cmd->prio_attr, cmd->sense_iu.sense);
1183+
cmd->prio_attr, cmd->sense_iu.sense,
1184+
cmd->unpacked_lun);
11831185
goto out;
11841186
}
11851187

include/target/target_core_fabric.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ void transport_deregister_session(struct se_session *);
150150

151151
void transport_init_se_cmd(struct se_cmd *,
152152
const struct target_core_fabric_ops *,
153-
struct se_session *, u32, int, int, unsigned char *);
154-
sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u64);
153+
struct se_session *, u32, int, int, unsigned char *, u64);
154+
sense_reason_t transport_lookup_cmd_lun(struct se_cmd *);
155155
sense_reason_t target_cmd_init_cdb(struct se_cmd *, unsigned char *);
156156
sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *);
157157
int target_submit_cmd_map_sgls(struct se_cmd *, struct se_session *,
@@ -188,7 +188,7 @@ int core_tmr_alloc_req(struct se_cmd *, void *, u8, gfp_t);
188188
void core_tmr_release_req(struct se_tmr_req *);
189189
int transport_generic_handle_tmr(struct se_cmd *);
190190
void transport_generic_request_failure(struct se_cmd *, sense_reason_t);
191-
int transport_lookup_tmr_lun(struct se_cmd *, u64);
191+
int transport_lookup_tmr_lun(struct se_cmd *);
192192
void core_allocate_nexus_loss_ua(struct se_node_acl *acl);
193193

194194
struct se_node_acl *core_tpg_get_initiator_node_acl(struct se_portal_group *tpg,

0 commit comments

Comments
 (0)