2023-03-25 01:19:12

by Ye Bin

[permalink] [raw]
Subject: [PATCH 3/5] scsi: limit to set the host state

From: Ye Bin <[email protected]>

Now, we can set the host state with any value. Actually, it doesn't
make sense. As previous patch introduce SHOST_BLOCKED state, set this
state, it will blocking IO. So this patch limit to set the host with
running/blocked state.

Signed-off-by: Ye Bin <[email protected]>
---
drivers/scsi/scsi_sysfs.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index b14f95ac594e..42c5936c7711 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -203,6 +203,7 @@ store_shost_state(struct device *dev, struct device_attribute *attr,
int i;
struct Scsi_Host *shost = class_to_shost(dev);
enum scsi_host_state state = 0;
+ enum scsi_host_state old_state;
unsigned long flags;

for (i = 0; i < ARRAY_SIZE(shost_states); i++) {
@@ -216,8 +217,13 @@ store_shost_state(struct device *dev, struct device_attribute *attr,
if (!state)
return -EINVAL;

+ if (state != SHOST_RUNNING && state != SHOST_BLOCKED)
+ return -EINVAL;
+
spin_lock_irqsave(shost->host_lock, flags);
- if (scsi_host_set_state(shost, state)) {
+ old_state = shost->shost_state;
+ if ((old_state != SHOST_RUNNING && old_state != SHOST_BLOCKED) ||
+ scsi_host_set_state(shost, state)) {
spin_unlock_irqrestore(shost->host_lock, flags);
return -EINVAL;
}
--
2.31.1


2023-03-27 21:27:20

by Bart Van Assche

[permalink] [raw]
Subject: Re: [PATCH 3/5] scsi: limit to set the host state

On 3/24/23 18:17, Ye Bin wrote:
> From: Ye Bin <[email protected]>
>
> Now, we can set the host state with any value. Actually, it doesn't
> make sense. As previous patch introduce SHOST_BLOCKED state, set this
> state, it will blocking IO. So this patch limit to set the host with
> running/blocked state.
>
> Signed-off-by: Ye Bin <[email protected]>
> ---
> drivers/scsi/scsi_sysfs.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
> index b14f95ac594e..42c5936c7711 100644
> --- a/drivers/scsi/scsi_sysfs.c
> +++ b/drivers/scsi/scsi_sysfs.c
> @@ -203,6 +203,7 @@ store_shost_state(struct device *dev, struct device_attribute *attr,
> int i;
> struct Scsi_Host *shost = class_to_shost(dev);
> enum scsi_host_state state = 0;
> + enum scsi_host_state old_state;
> unsigned long flags;
>
> for (i = 0; i < ARRAY_SIZE(shost_states); i++) {
> @@ -216,8 +217,13 @@ store_shost_state(struct device *dev, struct device_attribute *attr,
> if (!state)
> return -EINVAL;
>
> + if (state != SHOST_RUNNING && state != SHOST_BLOCKED)
> + return -EINVAL;
> +
> spin_lock_irqsave(shost->host_lock, flags);
> - if (scsi_host_set_state(shost, state)) {
> + old_state = shost->shost_state;
> + if ((old_state != SHOST_RUNNING && old_state != SHOST_BLOCKED) ||
> + scsi_host_set_state(shost, state)) {
> spin_unlock_irqrestore(shost->host_lock, flags);
> return -EINVAL;
> }

Please make sure that the "state != SHOST_RUNNING && state !=
SHOST_BLOCKED" check occurs only once and also that there is one
spin_lock_irqsave() call in this function and only one
spin_unlock_irqrestore() call.

Thanks,

Bart.