Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4342875pxv; Tue, 27 Jul 2021 05:13:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzO2fUkRmAR3S8B+4bz1AdlWKTPKk5dhge5VAktwYpppuorC7awdh6CXSu55LtpfEYhhnR1 X-Received: by 2002:a17:906:6cb:: with SMTP id v11mr12301552ejb.482.1627387993223; Tue, 27 Jul 2021 05:13:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627387993; cv=none; d=google.com; s=arc-20160816; b=UTPAs837l5G217Gcpt5252YCts9xB9F/RYm5O1ksu03Sop5Thw4BvDXS2o/P8KeevZ oTavHTtimT8SwuaMJBfJ2pmgNu5u4duMsTa1TvHJXNUw7RNt2+FcwqKHGaAoQCjZcpNw aMI/+uSQ2jYu4Qe7K9XEdCJ0F9WL42+/3D52vlJOGV18X5jtvI6CabHz0VxDtCcfn61x ulYluYaQvfli50ijJUL0mea+H8MQ2xFhftCa7bG+PVSuyFxoDmcagQ/otEUY4hW1u3jX MpNoez/jzOzkLcfIk7XTHy53qnriVFwOGbnQmBUkr67Bu7WrSFGRaJnMx3k5gEzkpmpL PV6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=mOhm6tbIPspj98iIUU3wpMY6BM34QUaOdq38JboPTRo=; b=nt8WRU+T59rwB28To1HsLYTwQSfbhdAazahzUrZwF1m0+aLzCXzZX78jpPuFyQQM4s 5JCqB6nBJ1S7b8j5CTzKH1wRnZH2FVqbgRQO/wh5JuSt2VOnXpLcLfz3PbP/qQTQWtBz kUAqZsXKdZYakXqXxb5aANRfdg2Wkn9+UQ2iHg4nA8UEIo1TzM3kSulbZZZ1NEB40/MR QAv+LElKMMdUujo0anzK4kRoUUjqVcf61VGf8lXVzrEfoa+Ysg4Mouth2Z98uf+3TtVx y5lXmMvW34ZusL5wX/PaWAAK8mlZevNhaL4KQChQ6T+zywZ0+iwLDMf+mO9JqmWOuP78 cy3g== 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 nb18si2726574ejc.113.2021.07.27.05.12.49; Tue, 27 Jul 2021 05:13:13 -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 S236502AbhG0MIp (ORCPT + 99 others); Tue, 27 Jul 2021 08:08:45 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:7880 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231868AbhG0MIp (ORCPT ); Tue, 27 Jul 2021 08:08:45 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GYwTQ3j1dz80PK; Tue, 27 Jul 2021 20:04:58 +0800 (CST) Received: from dggema773-chm.china.huawei.com (10.1.198.217) by dggemv703-chm.china.huawei.com (10.3.19.46) 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 20:08:42 +0800 Received: from [10.174.179.2] (10.174.179.2) 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 20:08:41 +0800 Subject: Re: [PATCH v2] scsi: Fix the issue that the disk capacity set to zero To: John Garry , , , , CC: , , , References: <20210727034455.1494960-1-lijinlin3@huawei.com> <21370ef0-88c0-e0b7-6099-4e3ee7af502f@huawei.com> From: lijinlin Message-ID: Date: Tue, 27 Jul 2021 20:08:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <21370ef0-88c0-e0b7-6099-4e3ee7af502f@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.2] 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 On 2021/7/27 16:48, John Garry wrote: > On 27/07/2021 04:44, lijinlin3@huawei.com wrote: >> 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); > > I am wondering does any of this need to be done with the device state mutex held? > > Thanks, > John To ensure that the rescan is invoked only in the running state. Thanks. > >> +    } >>       mutex_unlock(&sdev->state_mutex); >>         return ret == 0 ? count : -EINVAL; >> > > .