Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1212050pxv; Fri, 23 Jul 2021 02:48:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvVGmy3aKCX8YRblXAF72bhLSwEHe7tijO4oP/01TfNjlzTwSK6STC6tdxKZE4Q+cfAMvL X-Received: by 2002:a92:7c07:: with SMTP id x7mr2903210ilc.198.1627033706431; Fri, 23 Jul 2021 02:48:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627033706; cv=none; d=google.com; s=arc-20160816; b=b3hLgXoJ3FvThXowdlHrIpkIBuFo0K1WoYcJ5dFrtR0CCW6KqWEajJixeniNg4G1am K4PLnwY5Zudt5OX5aCtgaSWw0heI52uEhd6KNLRf4b+SoJxZDxiLLy2SiMvP1P7516fy 3IPlEQVkrYIZl3APGtLuCsv+4nPzLKtYQzJ7eafHwr7CBF3PTNwj+rn6aql5cC12o0so Znj5iGgcxxU99dpmzs/nps/UfiR4jpFoYQE1QJIICVlGsu/wrcr0cFps5k+TMkoZDEK+ Qhw1sa647j/9CREoSN3oyO+ea2QLDO6M4q0d9sGLI2SGbEjm+NNQbZAPc/Vr301cGwN6 gI9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=vrofLe+6gWNCCXY0kKVuhN7S2+UG4kuIJExkpKQqmMQ=; b=RoYpo5UYdE2kcZgLRsruPU+0ZIY2m+gRyU9cdiDFp+Bwgv8ntHQvAGNsqgaOSNd+dc 1FwUuZ6YwhPf4AFG6ZGRtnTwKLFvfPpwa3PqpICDTuYIpqw9RmoTTOO1eAftdgQv+xl0 Xwu/dDkqMKACaZAAowAtRxwQgLLMJ/qOUUwuSzMuig1S/jCIM1nrIgv1sWx9T6aPJWXw oL1lIxWdqLzJDByoipuYwYRstvneCgzbO7qFrEtX1W17i0qdoUgYasLU5tPzdEZobttb esOAx3hQm/KhIaOXf47SbwmHLYzpgOv3nW4vYiCgzYEIgX17XPBENgMAY1hy4UsyKxEL GP3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 187si31984498jau.8.2021.07.23.02.48.15; Fri, 23 Jul 2021 02:48:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231322AbhGWJG5 (ORCPT + 99 others); Fri, 23 Jul 2021 05:06:57 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:15052 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231256AbhGWJG5 (ORCPT ); Fri, 23 Jul 2021 05:06:57 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GWPXh4nfRzZrGy; Fri, 23 Jul 2021 17:44:04 +0800 (CST) Received: from dggema773-chm.china.huawei.com (10.1.198.217) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Fri, 23 Jul 2021 17:47:28 +0800 Received: from localhost.huawei.com (10.175.124.27) by dggema773-chm.china.huawei.com (10.1.198.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Fri, 23 Jul 2021 17:47:28 +0800 From: lijinlin To: , , , CC: , , Subject: [PATCH] scsi_sysfs: Fix the issue that the disk capacity set to zero Date: Fri, 23 Jul 2021 18:13:35 +0800 Message-ID: <20210723101335.1879003-1-lijinlin3@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggema773-chm.china.huawei.com (10.1.198.217) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Wu Bo --- 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