2021-07-27 03:21:15

by lijinlin

[permalink] [raw]
Subject: [PATCH v2] scsi: Fix the issue that the disk capacity set to zero

From: lijinlin <[email protected]>

After add physical volumes to a volume group through vgextend, kernel
will rescan partitions, which will read the capacity of the device.
If the device status is set to offline through sysfs at this time,
read capacity command will return a result which the host byte is
DID_NO_CONNECT, the capacity of the device will be set to zero in
read_capacity_error(). However, the capacity of the device can't be
reread after reset the device status to running, is still zero.

Fix this issue by rescan device when the device state changes to
SDEV_RUNNING.

Signed-off-by: lijinlin <[email protected]>
Signed-off-by: Wu Bo <[email protected]>
---
drivers/scsi/scsi_sysfs.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 32489d25158f..ae9bfc658203 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -807,11 +807,14 @@ store_state_field(struct device *dev, struct device_attribute *attr,
mutex_lock(&sdev->state_mutex);
ret = scsi_device_set_state(sdev, state);
/*
- * If the device state changes to SDEV_RUNNING, we need to run
- * the queue to avoid I/O hang.
+ * If the device state changes to SDEV_RUNNING, we need to
+ * rescan the device to revalidate it, and run the queue to
+ * avoid I/O hang.
*/
- if (ret == 0 && state == SDEV_RUNNING)
+ if (ret == 0 && state == SDEV_RUNNING) {
+ scsi_rescan_device(dev);
blk_mq_run_hw_queues(sdev->request_queue, true);
+ }
mutex_unlock(&sdev->state_mutex);

return ret == 0 ? count : -EINVAL;
--
2.27.0


2021-07-27 03:27:46

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: Fix the issue that the disk capacity set to zero


lijinlin,

What changed in v2? Please make sure to include a change log after the
"---" separator when you resubmit a patch.

Thank you!

--
Martin K. Petersen Oracle Linux Engineering

2021-07-27 03:43:21

by Bart Van Assche

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: Fix the issue that the disk capacity set to zero

On 7/26/21 8:44 PM, [email protected] wrote:
> From: lijinlin <[email protected]>
>
> After add physical volumes to a volume group through vgextend, kernel
> will rescan partitions, which will read the capacity of the device.
> If the device status is set to offline through sysfs at this time,
> read capacity command will return a result which the host byte is
> DID_NO_CONNECT, the capacity of the device will be set to zero in
> read_capacity_error(). However, the capacity of the device can't be
> reread after reset the device status to running, is still zero.
>
> Fix this issue by rescan device when the device state changes to
> SDEV_RUNNING.
>
> Signed-off-by: lijinlin <[email protected]>
> Signed-off-by: Wu Bo <[email protected]>
> ---
> drivers/scsi/scsi_sysfs.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
> index 32489d25158f..ae9bfc658203 100644
> --- a/drivers/scsi/scsi_sysfs.c
> +++ b/drivers/scsi/scsi_sysfs.c
> @@ -807,11 +807,14 @@ store_state_field(struct device *dev, struct device_attribute *attr,
> mutex_lock(&sdev->state_mutex);
> ret = scsi_device_set_state(sdev, state);
> /*
> - * If the device state changes to SDEV_RUNNING, we need to run
> - * the queue to avoid I/O hang.
> + * If the device state changes to SDEV_RUNNING, we need to
> + * rescan the device to revalidate it, and run the queue to
> + * avoid I/O hang.
> */
> - if (ret == 0 && state == SDEV_RUNNING)
> + if (ret == 0 && state == SDEV_RUNNING) {
> + scsi_rescan_device(dev);
> blk_mq_run_hw_queues(sdev->request_queue, true);
> + }
> mutex_unlock(&sdev->state_mutex);
>
> return ret == 0 ? count : -EINVAL;

In the future, please mention what has been changed between v1 and v2
under the three dashes ("---"). Anyway:

Reviewed-by: Bart Van Assche <[email protected]>

2021-07-27 06:18:16

by lijinlin

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: Fix the issue that the disk capacity set to zero

Patch v2 only change 'scsi_sysfs:' to 'scsi:' in subject, thanks.

On 2021/7/27 11:25, Martin K. Petersen wrote:>
> lijinlin,
>
> What changed in v2? Please make sure to include a change log after the
> "---" separator when you resubmit a patch.
>
> Thank you!
>