From patchwork Sat Apr 29 18:11:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengping Zhou X-Patchwork-Id: 9705831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C35E60245 for ; Sat, 29 Apr 2017 18:12:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14ACD282E2 for ; Sat, 29 Apr 2017 18:12:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 095DB28304; Sat, 29 Apr 2017 18:12:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, HK_RANDOM_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A809D28338 for ; Sat, 29 Apr 2017 18:12:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969489AbdD2SML (ORCPT ); Sat, 29 Apr 2017 14:12:11 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36857 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967719AbdD2SML (ORCPT ); Sat, 29 Apr 2017 14:12:11 -0400 Received: by mail-pf0-f194.google.com with SMTP id v14so22146757pfd.3 for ; Sat, 29 Apr 2017 11:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rji+svt2cHxjgVbf879IUBhNDEdytldM6esFu9K33r8=; b=to04y8566v0LHmyLJC8iMFAa/yF3ff5y5PeMiDgWKNMyYKjetdVLixclV0WACNGCsh Qi2cfIVEmdloAkJDAqiqkPPFEUcH3Bv+7EfmyfmshpF9up6gZiyCSvh/ZKYrnjD/CACh P5s8LDf/ZhKNjTrJIzr4+Q6Hm39l67bCzMO6s8FkyjwQ/xuT6nQPx3sS85CPZjqT5D7c M0wGzPKBZprnfojzFkl4qk1sv+OQkAL5fux0+mmjVSlWWw01TwRnAhbx9zI5LonLjeHr 0Q+y8FOsuHp+02wfyfhnz/XnydreY6xQWSdj/Zmcdg0Nm3DeftTWQiPeOEepFg5+/Lfl /YSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rji+svt2cHxjgVbf879IUBhNDEdytldM6esFu9K33r8=; b=Z1zx8zAuQytpqBLcZAxpa+tMrdYQy5abWiN2YS5QuXDNh/MRSL5+RvGNliPacLZE+U rXDsnb2g7z0Zo9g4kieONsVEQCyPSwArpiRg8af+XyGwOEibFrtPL19Eo+seTOvNI6C7 e97flWW3Yx1wbI1qVQsHmigSgwTxHR2cD3JP1EbkH79c1nqSeP97R96WtTQLd+YNUULk 4B8ockrjB/cwq/NLFt2un0EzLdcu0YUjNWIRoXVISWB+fMnOsslBjPueIBk5ihgYGLb+ d6ocHwOInPmf24Ee22rz+fHZauJDCGimpn7MvjWGz1SmR9H+ijDDP9PGzTL7cULTLtpZ ZqQg== X-Gm-Message-State: AN3rC/4QICV+4JShg5hA+QZMQfdDFnhjeoQNz1SolDeWKyBwPZX84h3g 3qBR6ho8i0M2Yw== X-Received: by 10.84.229.144 with SMTP id c16mr23231088plk.27.1493489530427; Sat, 29 Apr 2017 11:12:10 -0700 (PDT) Received: from 42.localdomain ([47.90.78.247]) by smtp.gmail.com with ESMTPSA id q64sm21290899pfi.69.2017.04.29.11.12.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Apr 2017 11:12:09 -0700 (PDT) From: Zhou Zhengping To: linux-scsi@vger.kernel.org Cc: hare@suse.de, James.Bottomley@hansenpartnership.com, Zhou Zhengping Subject: [PATCH]scsi: megaraid_sas: fix raid card hotswap failure Date: Sun, 30 Apr 2017 02:11:11 +0800 Message-Id: <1493489471-4848-1-git-send-email-johnzzpcrystal@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1493372584-1204-1-git-send-email-johnzzpcrystal@gmail.com> References: <1493372584-1204-1-git-send-email-johnzzpcrystal@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When a scsi_device is unpluged from scsi controller, if the scsi_device is still be used by application layer,it won't be released until users release it. In this case, scsi_device_remove just set the scsi_device's state to be SDEV_DEL. But if you plug the disk just before the old scsi_device is released, then there will be two scsi_device structures in scsi_host->__devices. when the next unpluging event happens,some low-level drivers will check whether the scsi_device has been added to host (for example, the megaraid sas series controller) by calling scsi_device_lookup(call __scsi_device_lookup) in function megasas_aen_polling.__scsi_device_lookup will return the first scsi_device. Because its state is SDEV_DEL, the scsi_device_lookup will return NULL finally, making the low-level driver assume that the scsi_device has been removed,and won't call scsi_device_remove,which will lead the failure of hot swap. Signed-off-by: Zhou Zhengping Tested-and-reported-by: Zeng Rujia Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=195607 Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 7bfbcfa..61cdd99 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -763,6 +763,8 @@ struct scsi_device *__scsi_device_lookup(struct Scsi_Host *shost, struct scsi_device *sdev; list_for_each_entry(sdev, &shost->__devices, siblings) { + if (sdev->sdev_state == SDEV_DEL) + continue; if (sdev->channel == channel && sdev->id == id && sdev->lun ==lun) return sdev;