From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30AF0C4320A for ; Tue, 10 Aug 2021 14:17:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 18F1660FDA for ; Tue, 10 Aug 2021 14:17:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241194AbhHJOST (ORCPT ); Tue, 10 Aug 2021 10:18:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:53856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242557AbhHJOQR (ORCPT ); Tue, 10 Aug 2021 10:16:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4281861058; Tue, 10 Aug 2021 14:15:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628604953; bh=qwQCq/mijMDLUOoivqY7XnQxh5b+WRJ8l/SCOuNzVNM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kVBUf0b/Rp3MWq+M2Ak5C8csUV7B2GDNnpTRVyR2Ag3uR+u7HMh4gQTB8PuhCeF0U e/zPjsdS1RLdIKi5riWpCec1p81NlZMbsezMpkELS8v1tAv6rAy9b17t6EaUcC9+I0 6n5NLqUGslswq+KzfuM3F9yLwVLTE+q4t+jlOtoQtwcJ9x7jcqbyAFe5x9vWMF+qg9 iO+7e1U3C1IfB1BrvogR+3TDgFCnPIB0Vcl0gEZw20iS7ViuP5Qz6n2kt+oaMFP6ly DMMIRuN9DtHdx5Kq2h4Pu8qu/PX5iBcoQ3FuUTZKtXuWB7ZmcJM72HhGFYfAtfmTPo 9xD/+87Ln2c8w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: lijinlin , Bart Van Assche , Wu Bo , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 11/20] scsi: core: Fix capacity set to zero after offlinining device Date: Tue, 10 Aug 2021 10:15:29 -0400 Message-Id: <20210810141538.3117707-11-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210810141538.3117707-1-sashal@kernel.org> References: <20210810141538.3117707-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: lijinlin [ Upstream commit f0f82e2476f6adb9c7a0135cfab8091456990c99 ] 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/20210727034455.1494960-1-lijinlin3@huawei.com Reviewed-by: Bart Van Assche Signed-off-by: lijinlin Signed-off-by: Wu Bo Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- 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 d6e344fa33ad..4dcced95c8b4 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.30.2