diff mbox series

[1/5] scsi: core: Rework scsi_host_block()

Message ID 20230504235052.4423-2-bvanassche@acm.org
State Superseded
Headers show
Series ufs: Do not requeue while ungating the clock | expand

Commit Message

Bart Van Assche May 4, 2023, 11:50 p.m. UTC
Make scsi_host_block() easier to read by converting it to the widely used
early-return style. This patch reworks code introduced by commit
f983622ae605 ("scsi: core: Avoid calling synchronize_rcu() for each device
in scsi_host_block()").

Cc: Ming Lei <ming.lei@redhat.com>
Cc: Ye Bin <yebin10@huawei.com>
Cc: Hannes Reinecke <hare@suse.de>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/scsi/scsi_lib.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

Comments

Mike Christie May 5, 2023, 3:44 p.m. UTC | #1
On 5/4/23 6:50 PM, Bart Van Assche wrote:
> Make scsi_host_block() easier to read by converting it to the widely used
> early-return style. This patch reworks code introduced by commit
> f983622ae605 ("scsi: core: Avoid calling synchronize_rcu() for each device
> in scsi_host_block()").
> 
> Cc: Ming Lei <ming.lei@redhat.com>
> Cc: Ye Bin <yebin10@huawei.com>
> Cc: Hannes Reinecke <hare@suse.de>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>  drivers/scsi/scsi_lib.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index b7c569a42aa4..758a57616dd3 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -2939,11 +2939,20 @@ scsi_target_unblock(struct device *dev, enum scsi_device_state new_state)
>  }
>  EXPORT_SYMBOL_GPL(scsi_target_unblock);
>  
> +/**
> + * scsi_host_block - Try to transition all logical units to the SDEV_BLOCK state
> + * @shost: device to block
> + *
> + * Pause SCSI command processing for all logical units associated with the SCSI
> + * host and wait until pending scsi_queue_rq() calls have finished.
> + *
> + * Returns zero if successful or a negative error code upon failure.
> + */
>  int
>  scsi_host_block(struct Scsi_Host *shost)
>  {
>  	struct scsi_device *sdev;
> -	int ret = 0;
> +	int ret;
>  
>  	/*
>  	 * Call scsi_internal_device_block_nowait so we can avoid
> @@ -2955,7 +2964,7 @@ scsi_host_block(struct Scsi_Host *shost)
>  		mutex_unlock(&sdev->state_mutex);
>  		if (ret) {
>  			scsi_device_put(sdev);
> -			break;
> +			return ret;
>  		}
>  	}
>  
> @@ -2965,10 +2974,9 @@ scsi_host_block(struct Scsi_Host *shost)
>  	 */
>  	WARN_ON_ONCE(shost->tag_set.flags & BLK_MQ_F_BLOCKING);
>  
> -	if (!ret)
> -		synchronize_rcu();
> +	synchronize_rcu();
>  
> -	return ret;
> +	return 0;
>  }
>  EXPORT_SYMBOL_GPL(scsi_host_block);
>  

Reviewed-by: Mike Christie <michael.christie@oracle.com>
diff mbox series

Patch

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index b7c569a42aa4..758a57616dd3 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2939,11 +2939,20 @@  scsi_target_unblock(struct device *dev, enum scsi_device_state new_state)
 }
 EXPORT_SYMBOL_GPL(scsi_target_unblock);
 
+/**
+ * scsi_host_block - Try to transition all logical units to the SDEV_BLOCK state
+ * @shost: device to block
+ *
+ * Pause SCSI command processing for all logical units associated with the SCSI
+ * host and wait until pending scsi_queue_rq() calls have finished.
+ *
+ * Returns zero if successful or a negative error code upon failure.
+ */
 int
 scsi_host_block(struct Scsi_Host *shost)
 {
 	struct scsi_device *sdev;
-	int ret = 0;
+	int ret;
 
 	/*
 	 * Call scsi_internal_device_block_nowait so we can avoid
@@ -2955,7 +2964,7 @@  scsi_host_block(struct Scsi_Host *shost)
 		mutex_unlock(&sdev->state_mutex);
 		if (ret) {
 			scsi_device_put(sdev);
-			break;
+			return ret;
 		}
 	}
 
@@ -2965,10 +2974,9 @@  scsi_host_block(struct Scsi_Host *shost)
 	 */
 	WARN_ON_ONCE(shost->tag_set.flags & BLK_MQ_F_BLOCKING);
 
-	if (!ret)
-		synchronize_rcu();
+	synchronize_rcu();
 
-	return ret;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(scsi_host_block);