target: various CDB processing fixes for -rc2
Subsystems (2)
cover target: various CDB processing fixes for -rc2
From: Nicholas Bellinger <[email protected]>
Hi Folks,
The following is a bugfix series for lio-core-2.6.git/master to address various CDB processing breakage that has been introduced with -rc1.
This includes the removal of some duplicate control CDB emulation completion callbacks in transport_emulate_control_cdb, a fix to allow SYNCHRONIZE_CACHE to work again for default IBLOCK/FILEIO cases with zero LBA + range, and the addition of a missing check for DATA_SG_IO traffic to ensure that a receieved LBA + range does not exceed the maximum via ->get_blocks()
This series will also need to goto mainline as well for -rc2, so please have a look and comment.
Thanks!
--nab
Nicholas Bellinger (3):
target: Remove duplicate task completions in
transport_emulate_control_cdb
target: Fix SYNCHRONIZE_CACHE zero LBA + range breakage
target: Add missing DATA_SG_IO transport_cmd_get_valid_sectors check
drivers/target/target_core_cdb.c | 14 ++++++++------ drivers/target/target_core_transport.c | 29 +++++++++++++++-------------- 2 files changed, 23 insertions(+), 20 deletions(-)
Signature · 1 line
1.7.2.5
PATCH 1/3 target: Remove duplicate task completions in transport_emulate_control_cdb
From: Nicholas Bellinger <[email protected]>
This patch removes a duplicate set of transport_complete_task() calls in target_emulate_unmap() and target_emulate_write_same() as the completion call is already done within transport_emulate_control_cdb()
This patch also adds a check in transport_emulate_control_cdb() for the existing SCF_EMULATE_CDB_ASYNC flag currently used by SYNCHRONIZE_CACHE in order to handle IMMEDIATE processing.
--- drivers/target/target_core_cdb.c | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-)
drivers/target/target_core_cdb.c +8 -6
@@ -1076,8 +1076,6 @@ target_emulate_unmap(struct se_task *task) size -=16 ; } - task->task_scsi_status =GOOD ; -transport_complete_task (task,1 ); err:transport_kunmap_first_data_page (cmd);
@@ -1114,8 +1112,6 @@ target_emulate_write_same(struct se_task *task, u32 num_blocks)return ret; } - task->task_scsi_status =GOOD ; -transport_complete_task (task,1 );return 0 ; }
@@ -1227,8 +1223,14 @@ transport_emulate_control_cdb(struct se_task *task)if (ret <0 )return ret; - task->task_scsi_status =GOOD ; -transport_complete_task (task,1 ); +/* +* Handle the successful completion here unless a caller +* has explictly requested an asychronous completion. +*/ +if (!(cmd->se_cmd_flags &SCF_EMULATE_CDB_ASYNC )) { + task->task_scsi_status =GOOD ; +transport_complete_task (task,1 ); + }return PYX_TRANSPORT_SENT_TO_TRANSPORT ; }
Signature · 1 line
1.7.2.5
PATCH 2/3 target: Fix SYNCHRONIZE_CACHE zero LBA + range breakage
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch fixes a SYNCHRONIZE_CACHE CDB handling bug with IBLOCK/FILEIO backends where transport_cmd_get_valid_sectors() was incorrectly rejecting a zero LBA + range CDB from being processed, and returning CHECK_CONDITION.
This includes changing transport_cmd_get_valid_sectors() to return '0' on success and '-EINVAL' on failure (this makes more sense than sectors), and to only check transport_cmd_get_valid_sectors() when a non zero LBA + range SYNCHRONIZE_CACHE operation has been receieved for the non passthrough case.
--- drivers/target/target_core_transport.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
drivers/target/target_core_transport.c +7 -7
@@ -2855,12 +2855,10 @@ static int transport_cmd_get_valid_sectors(struct se_cmd *cmd)" transport_dev_end_lba(): %llu\n" , cmd->t_task_lba, sectors, transport_dev_end_lba(dev)); -pr_err (" We should return CHECK_CONDITION" -" but we don't yet\n" ); -return 0 ; +return -EINVAL ; } -return sectors; +return 0 ; }static int target_check_write_same_discard (unsigned char *flags,struct se_device *dev)
@@ -3352,10 +3350,12 @@ static int transport_generic_cmd_sequencer( cmd->se_cmd_flags |=SCF_EMULATE_CDB_ASYNC ;/* * Check to ensure that LBA + Range does not exceed past end of -* device. +* device for IBLOCK and FILEIO ->do_sync_cache() backend calls */ -if (!transport_cmd_get_valid_sectors (cmd)) - goto out_invalid_cdb_field; +if ((cmd->t_task_lba !=0 ) || (sectors !=0 )) { +if (transport_cmd_get_valid_sectors (cmd) <0 ) + goto out_invalid_cdb_field; + }break ;case UNMAP : size =get_unaligned_be16 (&cdb[7 ]);
Signature · 1 line
1.7.2.5
PATCH 3/3 target: Add missing DATA_SG_IO transport_cmd_get_valid_sectors check
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch adds the missing transport_cmd_get_valid_sectors() check for SCF_SCSI_DATA_SG_IO_CDB type payloads to ensure that a received LBA + range does not exeed past the end of associated backend struct se_device.
This patch also fixes a bug in the failure path of transport_new_cmd_obj() where this check can fail, so change to use a signed 'rc' and return '-EINVAL' to signal proper transport_generic_request_failure() handling.
--- drivers/target/target_core_transport.c | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-)
drivers/target/target_core_transport.c +8 -7
@@ -3893,9 +3893,7 @@ EXPORT_SYMBOL(transport_generic_map_mem_to_cmd);static int transport_new_cmd_obj (struct se_cmd *cmd) {struct se_device *dev = cmd->se_dev; -u32 task_cdbs; -u32 rc; -int set_counts =1 ; +int set_counts =1 , rc, task_cdbs;/* * Setup any BIDI READ tasks and memory from
@@ -3913,7 +3911,7 @@ static int transport_new_cmd_obj(struct se_cmd *cmd) cmd->se_cmd_flags |=SCF_SCSI_CDB_EXCEPTION ; cmd->scsi_sense_reason =TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE ; -return PYX_TRANSPORT_LU_COMM_FAILURE ; +return -EINVAL ; }atomic_inc (&cmd->t_fe_count);atomic_inc (&cmd->t_se_count);
@@ -3932,7 +3930,7 @@ static int transport_new_cmd_obj(struct se_cmd *cmd) cmd->se_cmd_flags |=SCF_SCSI_CDB_EXCEPTION ; cmd->scsi_sense_reason =TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE ; -return PYX_TRANSPORT_LU_COMM_FAILURE ; +return -EINVAL ; }if (set_counts) {
@@ -4250,10 +4248,13 @@ static u32 transport_allocate_tasks( struct scatterlist *sgl, unsigned int sgl_nents) { -if (cmd->se_cmd_flags &SCF_SCSI_DATA_SG_IO_CDB ) +if (cmd->se_cmd_flags &SCF_SCSI_DATA_SG_IO_CDB ) { +if (transport_cmd_get_valid_sectors (cmd) <0 ) +return -EINVAL ; +return transport_allocate_data_tasks (cmd, lba, data_direction, sgl, sgl_nents); -else + }else return transport_allocate_control_task (cmd); }
Signature · 1 line
1.7.2.5