Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <michael.christie@oracle.com>
Signed-off-by: Sudhakar Panneerselvam <sudhakar.panneerselvam@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Sudhakar Panneerselvam and committed by
Martin K. Petersen
a36840d8 f98c2ddf

+31 -31
+5 -6
drivers/target/iscsi/iscsi_target.c
··· 1158 1158 transport_init_se_cmd(&cmd->se_cmd, &iscsi_ops, 1159 1159 conn->sess->se_sess, be32_to_cpu(hdr->data_length), 1160 1160 cmd->data_direction, sam_task_attr, 1161 - cmd->sense_buffer + 2); 1161 + cmd->sense_buffer + 2, scsilun_to_int(&hdr->lun)); 1162 1162 1163 1163 pr_debug("Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x," 1164 1164 " ExpXferLen: %u, Length: %u, CID: %hu\n", hdr->itt, ··· 1167 1167 1168 1168 target_get_sess_cmd(&cmd->se_cmd, true); 1169 1169 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); 1172 1171 if (cmd->sense_reason) 1173 1172 goto attach_cmd; 1174 1173 ··· 1999 2000 2000 2001 transport_init_se_cmd(&cmd->se_cmd, &iscsi_ops, 2001 2002 conn->sess->se_sess, 0, DMA_NONE, 2002 - TCM_SIMPLE_TAG, cmd->sense_buffer + 2); 2003 + TCM_SIMPLE_TAG, cmd->sense_buffer + 2, 2004 + scsilun_to_int(&hdr->lun)); 2003 2005 2004 2006 target_get_sess_cmd(&cmd->se_cmd, true); 2005 2007 ··· 2038 2038 * Locate the struct se_lun for all TMRs not related to ERL=2 TASK_REASSIGN 2039 2039 */ 2040 2040 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); 2043 2042 if (ret < 0) { 2044 2043 se_tmr->response = ISCSI_TMF_RSP_NO_LUN; 2045 2044 goto attach;
+8 -11
drivers/target/target_core_device.c
··· 45 45 struct se_device *g_lun0_dev; 46 46 47 47 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) 49 49 { 50 50 struct se_lun *se_lun = NULL; 51 51 struct se_session *se_sess = se_cmd->se_sess; ··· 54 54 sense_reason_t ret = TCM_NO_SENSE; 55 55 56 56 rcu_read_lock(); 57 - deve = target_nacl_find_deve(nacl, unpacked_lun); 57 + deve = target_nacl_find_deve(nacl, se_cmd->orig_fe_lun); 58 58 if (deve) { 59 59 atomic_long_inc(&deve->total_cmds); 60 60 ··· 74 74 75 75 se_cmd->se_lun = se_lun; 76 76 se_cmd->pr_res_key = deve->pr_res_key; 77 - se_cmd->orig_fe_lun = unpacked_lun; 78 77 se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD; 79 78 se_cmd->lun_ref_active = true; 80 79 ··· 82 83 pr_err("TARGET_CORE[%s]: Detected WRITE_PROTECTED LUN" 83 84 " Access for 0x%08llx\n", 84 85 se_cmd->se_tfo->fabric_name, 85 - unpacked_lun); 86 + se_cmd->orig_fe_lun); 86 87 rcu_read_unlock(); 87 88 ret = TCM_WRITE_PROTECTED; 88 89 goto ref_dev; ··· 97 98 * REPORT_LUNS, et al to be returned when no active 98 99 * MappedLUN=0 exists for this Initiator Port. 99 100 */ 100 - if (unpacked_lun != 0) { 101 + if (se_cmd->orig_fe_lun != 0) { 101 102 pr_err("TARGET_CORE[%s]: Detected NON_EXISTENT_LUN" 102 103 " Access for 0x%08llx from %s\n", 103 104 se_cmd->se_tfo->fabric_name, 104 - unpacked_lun, 105 + se_cmd->orig_fe_lun, 105 106 nacl->initiatorname); 106 107 return TCM_NON_EXISTENT_LUN; 107 108 } 108 109 109 110 se_lun = se_sess->se_tpg->tpg_virt_lun0; 110 111 se_cmd->se_lun = se_sess->se_tpg->tpg_virt_lun0; 111 - se_cmd->orig_fe_lun = 0; 112 112 se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD; 113 113 114 114 percpu_ref_get(&se_lun->lun_ref); ··· 143 145 } 144 146 EXPORT_SYMBOL(transport_lookup_cmd_lun); 145 147 146 - int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u64 unpacked_lun) 148 + int transport_lookup_tmr_lun(struct se_cmd *se_cmd) 147 149 { 148 150 struct se_dev_entry *deve; 149 151 struct se_lun *se_lun = NULL; ··· 153 155 unsigned long flags; 154 156 155 157 rcu_read_lock(); 156 - deve = target_nacl_find_deve(nacl, unpacked_lun); 158 + deve = target_nacl_find_deve(nacl, se_cmd->orig_fe_lun); 157 159 if (deve) { 158 160 se_lun = rcu_dereference(deve->se_lun); 159 161 ··· 164 166 165 167 se_cmd->se_lun = se_lun; 166 168 se_cmd->pr_res_key = deve->pr_res_key; 167 - se_cmd->orig_fe_lun = unpacked_lun; 168 169 se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD; 169 170 se_cmd->lun_ref_active = true; 170 171 } ··· 174 177 pr_debug("TARGET_CORE[%s]: Detected NON_EXISTENT_LUN" 175 178 " Access for 0x%08llx for %s\n", 176 179 se_cmd->se_tfo->fabric_name, 177 - unpacked_lun, 180 + se_cmd->orig_fe_lun, 178 181 nacl->initiatorname); 179 182 return -ENODEV; 180 183 }
+2 -2
drivers/target/target_core_tmr.c
··· 148 148 * code. 149 149 */ 150 150 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); 153 153 154 154 target_put_cmd_and_wait(se_cmd); 155 155
+7 -5
drivers/target/target_core_transport.c
··· 1364 1364 u32 data_length, 1365 1365 int data_direction, 1366 1366 int task_attr, 1367 - unsigned char *sense_buffer) 1367 + unsigned char *sense_buffer, u64 unpacked_lun) 1368 1368 { 1369 1369 INIT_LIST_HEAD(&cmd->se_delayed_node); 1370 1370 INIT_LIST_HEAD(&cmd->se_qf_node); ··· 1383 1383 cmd->data_direction = data_direction; 1384 1384 cmd->sam_task_attr = task_attr; 1385 1385 cmd->sense_buffer = sense_buffer; 1386 + cmd->orig_fe_lun = unpacked_lun; 1386 1387 1387 1388 cmd->state_active = false; 1388 1389 } ··· 1597 1596 * target_core_fabric_ops->queue_status() callback 1598 1597 */ 1599 1598 transport_init_se_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess, 1600 - data_length, data_dir, task_attr, sense); 1599 + data_length, data_dir, task_attr, sense, 1600 + unpacked_lun); 1601 1601 1602 1602 if (flags & TARGET_SCF_USE_CPUID) 1603 1603 se_cmd->se_cmd_flags |= SCF_USE_CPUID; ··· 1624 1622 /* 1625 1623 * Locate se_lun pointer and attach it to struct se_cmd 1626 1624 */ 1627 - rc = transport_lookup_cmd_lun(se_cmd, unpacked_lun); 1625 + rc = transport_lookup_cmd_lun(se_cmd); 1628 1626 if (rc) { 1629 1627 transport_send_check_condition_and_sense(se_cmd, rc, 0); 1630 1628 target_put_sess_cmd(se_cmd); ··· 1792 1790 BUG_ON(!se_tpg); 1793 1791 1794 1792 transport_init_se_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess, 1795 - 0, DMA_NONE, TCM_SIMPLE_TAG, sense); 1793 + 0, DMA_NONE, TCM_SIMPLE_TAG, sense, unpacked_lun); 1796 1794 /* 1797 1795 * FIXME: Currently expect caller to handle se_cmd->se_tmr_req 1798 1796 * allocation failure. ··· 1820 1818 goto failure; 1821 1819 } 1822 1820 1823 - ret = transport_lookup_tmr_lun(se_cmd, unpacked_lun); 1821 + ret = transport_lookup_tmr_lun(se_cmd); 1824 1822 if (ret) 1825 1823 goto failure; 1826 1824
+2 -2
drivers/target/target_core_xcopy.c
··· 585 585 (unsigned long long)src_lba, src_sectors, length); 586 586 587 587 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); 589 589 590 590 rc = target_xcopy_setup_pt_cmd(&xpt_cmd, xop, src_dev, &cdb[0], 591 591 remote_port); ··· 630 630 (unsigned long long)dst_lba, dst_sectors, length); 631 631 632 632 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); 634 634 635 635 rc = target_xcopy_setup_pt_cmd(&xpt_cmd, xop, dst_dev, &cdb[0], 636 636 remote_port);
+4 -2
drivers/usb/gadget/function/f_tcm.c
··· 1049 1049 transport_init_se_cmd(se_cmd, 1050 1050 tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, 1051 1051 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); 1053 1054 goto out; 1054 1055 } 1055 1056 ··· 1180 1179 transport_init_se_cmd(se_cmd, 1181 1180 tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, 1182 1181 tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, 1183 - cmd->prio_attr, cmd->sense_iu.sense); 1182 + cmd->prio_attr, cmd->sense_iu.sense, 1183 + cmd->unpacked_lun); 1184 1184 goto out; 1185 1185 } 1186 1186
+3 -3
include/target/target_core_fabric.h
··· 150 150 151 151 void transport_init_se_cmd(struct se_cmd *, 152 152 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 *); 155 155 sense_reason_t target_cmd_init_cdb(struct se_cmd *, unsigned char *); 156 156 sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *); 157 157 int target_submit_cmd_map_sgls(struct se_cmd *, struct se_session *, ··· 188 188 void core_tmr_release_req(struct se_tmr_req *); 189 189 int transport_generic_handle_tmr(struct se_cmd *); 190 190 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 *); 192 192 void core_allocate_nexus_loss_ua(struct se_node_acl *acl); 193 193 194 194 struct se_node_acl *core_tpg_get_initiator_node_acl(struct se_portal_group *tpg,