[04/19] target/fileio: Avoid that zero-length READ and WRITE commands hang
diff mbox

Message ID 20170504225102.8931-5-bart.vanassche@sandisk.com
State New, archived
Headers show

Commit Message

Bart Van Assche May 4, 2017, 10:50 p.m. UTC
From __target_execute_cmd() (simplified):

	ret = cmd->execute_cmd(cmd);
	if (ret != 0)
		transport_generic_request_failure(cmd, ret);

From sbc_execute_rw():

	return ops->execute_rw(cmd, cmd->t_data_sg, cmd->t_data_nents,
			       cmd->data_direction);

This means that sbc_ops.execute_rw() must either return a non-zero
value or call target_complete_cmd() and return zero or command
execution stalls. Make sure that fd_execute_rw() calls
target_complete_cmd() even for zero-length commands.

Fixes: commit c66ac9db8d4a ("[SCSI] target: Add LIO target core v4.0.0-rc6")
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Andy Grover <agrover@redhat.com>
Cc: David Disseldorp <ddiss@suse.de>
Cc: <stable@vger.kernel.org>
---
 drivers/target/target_core_file.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Hannes Reinecke May 5, 2017, 6:14 a.m. UTC | #1
On 05/05/2017 12:50 AM, Bart Van Assche wrote:
> From __target_execute_cmd() (simplified):
> 
> 	ret = cmd->execute_cmd(cmd);
> 	if (ret != 0)
> 		transport_generic_request_failure(cmd, ret);
> 
> From sbc_execute_rw():
> 
> 	return ops->execute_rw(cmd, cmd->t_data_sg, cmd->t_data_nents,
> 			       cmd->data_direction);
> 
> This means that sbc_ops.execute_rw() must either return a non-zero
> value or call target_complete_cmd() and return zero or command
> execution stalls. Make sure that fd_execute_rw() calls
> target_complete_cmd() even for zero-length commands.
> 
> Fixes: commit c66ac9db8d4a ("[SCSI] target: Add LIO target core v4.0.0-rc6")
> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Cc: Hannes Reinecke <hare@suse.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Andy Grover <agrover@redhat.com>
> Cc: David Disseldorp <ddiss@suse.de>
> Cc: <stable@vger.kernel.org>
> ---
>  drivers/target/target_core_file.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
Christoph Hellwig May 5, 2017, 8:54 a.m. UTC | #2
Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Nicholas A. Bellinger May 7, 2017, 10:28 p.m. UTC | #3
On Thu, 2017-05-04 at 15:50 -0700, Bart Van Assche wrote:
> From __target_execute_cmd() (simplified):
> 
> 	ret = cmd->execute_cmd(cmd);
> 	if (ret != 0)
> 		transport_generic_request_failure(cmd, ret);
> 
> From sbc_execute_rw():
> 
> 	return ops->execute_rw(cmd, cmd->t_data_sg, cmd->t_data_nents,
> 			       cmd->data_direction);
> 
> This means that sbc_ops.execute_rw() must either return a non-zero
> value or call target_complete_cmd() and return zero or command
> execution stalls. Make sure that fd_execute_rw() calls
> target_complete_cmd() even for zero-length commands.
> 
> Fixes: commit c66ac9db8d4a ("[SCSI] target: Add LIO target core v4.0.0-rc6")
> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Cc: Hannes Reinecke <hare@suse.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Andy Grover <agrover@redhat.com>
> Cc: David Disseldorp <ddiss@suse.de>
> Cc: <stable@vger.kernel.org>
> ---
>  drivers/target/target_core_file.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
> index 1bf6c31e4c21..73b8f93a5fef 100644
> --- a/drivers/target/target_core_file.c
> +++ b/drivers/target/target_core_file.c
> @@ -608,8 +608,7 @@ fd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
>  	if (ret < 0)
>  		return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
>  
> -	if (ret)
> -		target_complete_cmd(cmd, SAM_STAT_GOOD);
> +	target_complete_cmd(cmd, SAM_STAT_GOOD);
>  	return 0;
>  }
>  

Applied, with a commit log to reflect that zero-length commands used to
be handled by target-core, but since commit d81cb447 (v3.7) they are now
submitted to backend drivers.



--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index 1bf6c31e4c21..73b8f93a5fef 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -608,8 +608,7 @@  fd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
 	if (ret < 0)
 		return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 
-	if (ret)
-		target_complete_cmd(cmd, SAM_STAT_GOOD);
+	target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return 0;
 }