Skip to content

Commit f0f82e2

Browse files
lijinlinmartinkpetersen
authored andcommitted
scsi: core: Fix capacity set to zero after offlinining device
After adding physical volumes to a volume group through vgextend, the kernel will rescan the partitions. This in turn will cause the device capacity to be queried. 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, and the capacity of the device will be set to zero in read_capacity_error(). After setting device status back to running, the capacity of the device will remain stuck at zero. Fix this issue by rescanning device when the device state changes to SDEV_RUNNING. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: lijinlin <[email protected]> Signed-off-by: Wu Bo <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 5c04243 commit f0f82e2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/scsi/scsi_sysfs.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,11 +807,14 @@ store_state_field(struct device *dev, struct device_attribute *attr,
807807
mutex_lock(&sdev->state_mutex);
808808
ret = scsi_device_set_state(sdev, state);
809809
/*
810-
* If the device state changes to SDEV_RUNNING, we need to run
811-
* the queue to avoid I/O hang.
810+
* If the device state changes to SDEV_RUNNING, we need to
811+
* rescan the device to revalidate it, and run the queue to
812+
* avoid I/O hang.
812813
*/
813-
if (ret == 0 && state == SDEV_RUNNING)
814+
if (ret == 0 && state == SDEV_RUNNING) {
815+
scsi_rescan_device(dev);
814816
blk_mq_run_hw_queues(sdev->request_queue, true);
817+
}
815818
mutex_unlock(&sdev->state_mutex);
816819

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

0 commit comments

Comments
 (0)