Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4066383pxv; Mon, 26 Jul 2021 20:21:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyIRqqLLznkq8993RcEziFBT6JnB6eH122uJM1v1zAbAArJ3Qbr5S1U02EQwGHnXo3VEoH X-Received: by 2002:a02:c491:: with SMTP id t17mr19388873jam.56.1627356075015; Mon, 26 Jul 2021 20:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627356075; cv=none; d=google.com; s=arc-20160816; b=Bc1s6Sxuompx8aPaILBWu+hjvho0GIvnZOnFS+c0SmVQ/+ovM5y7Q1+ZMRIEcpycss l9FjCUSMeMQR5bZFCMxXJVnaNGo07ivlVjfMrI/CEJaa4QEPuNe69Ks+FpdhUr5yCeSY DCGBHt6yp27LCwTduRe9vzX4+QkXuex6Lg+Mb7xYfT0EY+mYa9s502yyH32Q5Sw1sAzS eS+5HukIr7WZ49Sx8yXoh8m7QPMpJAv6YmBRfvMYgVAxoyA3GeXhlotFBBVPDCY1zr2b aMcEMT4nYpxLKRrb1zm4tAGloLo35dFnYMpRIdTsYPv8NBei8qP0RfY4MIfkpkV1OTwa n3vA== 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=8b3zYL0sdYTPpA+JgwlAFJRnlfurVGHg1PlZhJFt84k=; b=MRBof4eE8WeJ1bzlIEPoFS1Z5hmdXoHUpRGcqjosPVAo0OBtukbGAzCUhjRaSpEOf3 FeoSxY4A6+GstCASEZeNVEcrc4L46/eFVwaiQNxYKkqJhp/W0Mai0Aok9WSyxHa4yqCD 0tcHJeF69DzbnJdj2m1cdUfE2+8GKodERQsbuXE6LtqxEpd6qQ/ptvmt5MKOJUIJoh8A 8xzZ0SUidFHw2Kc1KlVvMhf9wRaYj5JStfD5D1aVc1hARblCyDj/ezPruo38cK4fuQJS bdXghqPW3mGdouPbljrqUx+Sndp62gjKShkff21WLoI3mTFoGrQ+zOI+OcJbv9bikaNI 7oZg== 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 d13si1935111iod.50.2021.07.26.20.21.03; Mon, 26 Jul 2021 20:21:15 -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 S234749AbhG0Cia (ORCPT + 99 others); Mon, 26 Jul 2021 22:38:30 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:12309 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234513AbhG0Ci3 (ORCPT ); Mon, 26 Jul 2021 22:38:29 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GYhj138VWz7yCY; Tue, 27 Jul 2021 11:14:13 +0800 (CST) Received: from dggema773-chm.china.huawei.com (10.1.198.217) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Tue, 27 Jul 2021 11:18:55 +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; Tue, 27 Jul 2021 11:18:54 +0800 From: To: , , , CC: , , , , , Subject: [PATCH v2] scsi: Fix the issue that the disk capacity set to zero Date: Tue, 27 Jul 2021 11:44:55 +0800 Message-ID: <20210727034455.1494960-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: dggems706-chm.china.huawei.com (10.3.19.183) 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 From: lijinlin 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