From patchwork Fri Apr 28 09:43:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengping Zhou X-Patchwork-Id: 9704329 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 57720602B7 for ; Fri, 28 Apr 2017 09:43:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 466DD28662 for ; Fri, 28 Apr 2017 09:43:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39D1D28667; Fri, 28 Apr 2017 09:43:18 +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 7CE5F28662 for ; Fri, 28 Apr 2017 09:43:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756399AbdD1JnR (ORCPT ); Fri, 28 Apr 2017 05:43:17 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:32846 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756135AbdD1JnP (ORCPT ); Fri, 28 Apr 2017 05:43:15 -0400 Received: by mail-pf0-f196.google.com with SMTP id b23so752497pfc.0 for ; Fri, 28 Apr 2017 02:43:15 -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; bh=HEDGZs/hrbA0J0dB5irFa0E+N/ARZXuhZxnIIfK9YxI=; b=EfTpiFHZv6ZF9rBoL9bquU3SVhuw2XYVm7MutN/U7ZOrCTcqVupGPVAx7IEvHsP5Mi 4U4A/7FWZaHyoY/US9xHvMDsdTMZtcd9YCZcd8MK6oEblKitLxQJwx7+PhN2M4wC7amp +lPWhuK5iZd0867RGIvZueyGMRX2E7kA0FlN1y5Ksm1HufMFaYxkvvU/itp/SIW5FL5S Jtjjcw9eLKouEVPcP1aGXQgjhXrNaKZsD7oUKjtMNdvU+wTLJWAGGuxK+uO5kY/DO4RE vHbrCaCBmdgEBNdegWNBsEGoVRhbyQ4OOOAHTNXx2kQmTWRdBdyecrqzIJ9hjrxmZLDQ bQ/g== 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; bh=HEDGZs/hrbA0J0dB5irFa0E+N/ARZXuhZxnIIfK9YxI=; b=nO0ebA6ldyZYDbNkxt88ev8Kj92KFvnXLboAgAQCg+h5+T9y3W97g5HkTg8yk0zstP QyYr3Fx5uYd5dC+k+L7zGzv4kcCdhdyy+nMcy0gXv0NzmjtMyMo9vKJM/z2yOnWajjOf HVafdMR4yBhUmDd0Hhy0/ovxMwJmoSpPWP3isvprwJuTnKAqyRWo/Pynv2vweLQ53XBS vAVhmymmgA5FPMRuokOWENu+cGSyl+PNG7nY1nG6KGTyP/dGgA1crVDtpbLxpkEpT150 zfXUlu8uk1H1WH/VBkY0MpU2/bfx8/YsTP3KxntyTXWQpBBOigWKzM2iSzhbagcuFMtq 2PTg== X-Gm-Message-State: AN3rC/4IXLDxKVrk9tl7baAHXnsUsdilT8tOiz60rxSVf6j3J3LDxdZq nE7hrpRy26jYTA== X-Received: by 10.84.238.195 with SMTP id l3mr13879620pln.101.1493372595170; Fri, 28 Apr 2017 02:43:15 -0700 (PDT) Received: from 42.localdomain ([47.90.78.247]) by smtp.gmail.com with ESMTPSA id s83sm10280433pfa.128.2017.04.28.02.43.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Apr 2017 02:43:14 -0700 (PDT) From: Zhou Zhengping To: linux-scsi@vger.kernel.org Cc: Zhou Zhengping Subject: [PATCH] MegaRAID SAS: Raidcard hotswap wouldn't work if the device's fd is held in userspace Date: Fri, 28 Apr 2017 17:43:04 +0800 Message-Id: <1493372584-1204-1-git-send-email-johnzzpcrystal@gmail.com> X-Mailer: git-send-email 1.8.3.1 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 61c82a3..b455619 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -1262,6 +1262,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;