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

scsi: target: pscsi: Remove struct pscsi_plugin_task

Copy directly from the se_cmd CDB to the one in the scsi_request. This
temporarily limits the pscsi backend to supporting only up to 16 byte CDBs,
but this restriction will be lifted later in this series.

Link: https://lore.kernel.org/r/20220224175552.988286-2-hch@lst.de
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Christoph Hellwig and committed by
Martin K. Petersen
c49ff72c a2a59faa

+17 -38
+17 -34
drivers/target/target_core_pscsi.c
··· 593 593 { 594 594 struct pscsi_dev_virt *pdv = PSCSI_DEV(cmd->se_dev); 595 595 struct scsi_device *sd = pdv->pdv_sd; 596 - struct pscsi_plugin_task *pt = cmd->priv; 597 - unsigned char *cdb; 596 + unsigned char *cdb = cmd->priv; 597 + 598 598 /* 599 - * Special case for REPORT_LUNs handling where pscsi_plugin_task has 600 - * not been allocated because TCM is handling the emulation directly. 599 + * Special case for REPORT_LUNs which is emulated and not passed on. 601 600 */ 602 - if (!pt) 601 + if (!cdb) 603 602 return; 604 603 605 - cdb = &pt->pscsi_cdb[0]; 606 604 /* 607 605 * Hack to make sure that Write-Protect modepage is set if R/O mode is 608 606 * forced. ··· 961 963 struct scatterlist *sgl = cmd->t_data_sg; 962 964 u32 sgl_nents = cmd->t_data_nents; 963 965 struct pscsi_dev_virt *pdv = PSCSI_DEV(cmd->se_dev); 964 - struct pscsi_plugin_task *pt; 965 966 struct request *req; 966 967 sense_reason_t ret; 967 - 968 - /* 969 - * Dynamically alloc cdb space, since it may be larger than 970 - * TCM_MAX_COMMAND_SIZE 971 - */ 972 - pt = kzalloc(sizeof(*pt) + scsi_command_size(cmd->t_task_cdb), GFP_KERNEL); 973 - if (!pt) { 974 - return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 975 - } 976 - cmd->priv = pt; 977 - 978 - memcpy(pt->pscsi_cdb, cmd->t_task_cdb, 979 - scsi_command_size(cmd->t_task_cdb)); 980 968 981 969 req = scsi_alloc_request(pdv->pdv_sd->request_queue, 982 970 cmd->data_direction == DMA_TO_DEVICE ? 983 971 REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0); 984 - if (IS_ERR(req)) { 985 - ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 986 - goto fail; 987 - } 972 + if (IS_ERR(req)) 973 + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 988 974 989 975 if (sgl) { 990 976 ret = pscsi_map_sg(cmd, sgl, sgl_nents, req); ··· 978 996 979 997 req->end_io = pscsi_req_done; 980 998 req->end_io_data = cmd; 981 - scsi_req(req)->cmd_len = scsi_command_size(pt->pscsi_cdb); 982 - scsi_req(req)->cmd = &pt->pscsi_cdb[0]; 999 + scsi_req(req)->cmd_len = scsi_command_size(cmd->t_task_cdb); 1000 + if (scsi_req(req)->cmd_len > BLK_MAX_CDB) { 1001 + ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 1002 + goto fail_put_request; 1003 + } 1004 + memcpy(scsi_req(req)->cmd, cmd->t_task_cdb, scsi_req(req)->cmd_len); 983 1005 if (pdv->pdv_sd->type == TYPE_DISK || 984 1006 pdv->pdv_sd->type == TYPE_ZBC) 985 1007 req->timeout = PS_TIMEOUT_DISK; 986 1008 else 987 1009 req->timeout = PS_TIMEOUT_OTHER; 988 1010 scsi_req(req)->retries = PS_RETRY; 1011 + 1012 + cmd->priv = scsi_req(req)->cmd; 989 1013 990 1014 blk_execute_rq_nowait(req, cmd->sam_task_attr == TCM_HEAD_TAG, 991 1015 pscsi_req_done); ··· 1000 1012 1001 1013 fail_put_request: 1002 1014 blk_mq_free_request(req); 1003 - fail: 1004 - kfree(pt); 1005 1015 return ret; 1006 1016 } 1007 1017 ··· 1027 1041 static void pscsi_req_done(struct request *req, blk_status_t status) 1028 1042 { 1029 1043 struct se_cmd *cmd = req->end_io_data; 1030 - struct pscsi_plugin_task *pt = cmd->priv; 1031 1044 int result = scsi_req(req)->result; 1032 1045 enum sam_status scsi_status = result & 0xff; 1046 + u8 *cdb = cmd->priv; 1033 1047 1034 1048 if (scsi_status != SAM_STAT_GOOD) { 1035 1049 pr_debug("PSCSI Status Byte exception at cmd: %p CDB:" 1036 - " 0x%02x Result: 0x%08x\n", cmd, pt->pscsi_cdb[0], 1037 - result); 1050 + " 0x%02x Result: 0x%08x\n", cmd, cdb[0], result); 1038 1051 } 1039 1052 1040 1053 pscsi_complete_cmd(cmd, scsi_status, scsi_req(req)->sense); ··· 1045 1060 break; 1046 1061 default: 1047 1062 pr_debug("PSCSI Host Byte exception at cmd: %p CDB:" 1048 - " 0x%02x Result: 0x%08x\n", cmd, pt->pscsi_cdb[0], 1049 - result); 1063 + " 0x%02x Result: 0x%08x\n", cmd, cdb[0], result); 1050 1064 target_complete_cmd(cmd, SAM_STAT_CHECK_CONDITION); 1051 1065 break; 1052 1066 } 1053 1067 1054 1068 blk_mq_free_request(req); 1055 - kfree(pt); 1056 1069 } 1057 1070 1058 1071 static const struct target_backend_ops pscsi_ops = {
-4
drivers/target/target_core_pscsi.h
··· 23 23 struct scsi_device; 24 24 struct Scsi_Host; 25 25 26 - struct pscsi_plugin_task { 27 - unsigned char pscsi_cdb[0]; 28 - } ____cacheline_aligned; 29 - 30 26 #define PDF_HAS_CHANNEL_ID 0x01 31 27 #define PDF_HAS_TARGET_ID 0x02 32 28 #define PDF_HAS_LUN_ID 0x04