Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp2256242ybe; Tue, 3 Sep 2019 10:05:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfO6OH+FNcZRs5lh/6KqFFbkzpt4RV53RELROIo5ClWiaIC+99U+CcAoknooNL3nv2rv2z X-Received: by 2002:a65:5382:: with SMTP id x2mr31310423pgq.422.1567530342082; Tue, 03 Sep 2019 10:05:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1567530342; cv=pass; d=google.com; s=arc-20160816; b=CWbhFGLEG7/eyp1S3163P+c+pbieMONsJSogg8OYCSLFs1CQZDZc7ldVMHrAxV6vwv E7iJmfdCSg+trQ6PO6qfEWCpJHwXV9+kOCAqjcqI7r9aS0sEj5QYy2H8Amo4z5S5Gvss 78KXFYC74B3ZeaYQMdwCCYsJn6HR8qOYPXNnl0N7C2mPKf6YXGyomlQYNYMnQ9SA9VaG TR98U8O0fnPu3k4BrPNZvmZGQGMy1DQpTzLX0OaDsNYQYLpRXMGHEHWkVfauo4N+WbsP kr2ReP+WgnAwLiSAjzqnr6hbZZ9BAAo2vq0gQAv1But5k9fRVflaDU6Dz/57kydc43I8 gjTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=FE1vkhZEcBTm/jJaftv+DejwqE1+7/QXcmbHN3bXq44=; b=HZu5BzM0VEo7XmHtNJ5h/1a9IfXoX4ZzRqeq1ayhbnDrbREnl8mNapsJDKoKW104wP vlzRpIN1/KBccVhdkpUNRnql8jEVkayi5TwUIBD6DC7d2S4TwwoFYuyW7eXZ0vxX4kM5 zb9LnB2adur58yzEvzFr7A0U5nd4j5Lssjq3vHFAWYOfTwM4fch6vnXURrBoeL+pav2c TIrW0AACtiM5xB7J99JVw6m7SkUG6+lSb4+qBvtceZd6tOF9rP9qPAcs/ygr5C2dbGYe X9CtwYkNU0zNeokK1sXNTkUAN70pl8tYADHI2fbW6KojIrAS2sw8D5nzFNH87zdIVLPZ GKlQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ddn.com header.s=selector2 header.b="Fh7/Pj/T"; arc=pass (i=1 spf=pass spfdomain=ddn.com dkim=pass dkdomain=ddn.com dmarc=pass fromdomain=ddn.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ddn.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q12si5876188pfh.87.2019.09.03.10.05.26; Tue, 03 Sep 2019 10:05:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ddn.com header.s=selector2 header.b="Fh7/Pj/T"; arc=pass (i=1 spf=pass spfdomain=ddn.com dkim=pass dkdomain=ddn.com dmarc=pass fromdomain=ddn.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ddn.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730039AbfICREX (ORCPT + 99 others); Tue, 3 Sep 2019 13:04:23 -0400 Received: from mail-eopbgr820047.outbound.protection.outlook.com ([40.107.82.47]:14198 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728571AbfICREW (ORCPT ); Tue, 3 Sep 2019 13:04:22 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SEW3U1DrhnPq/q/gBkOWs/xb9KTcblgjxz1Xth7vc0LAA6vZLSCtvOInon/zzStnTfKQ+MYlhqaEVW9hGiZqX9sKE2SLGW9er/xrKYvcQdsUOOC2M+FDEG6SSew6A2khnGCrTrucSd3nmjDuUl07nWG/Q/O3z7uztSSlh1HT4xpBhEv5HtUcnZko6lw6r3TQNn1WK7xPCDG2HbsNPdPIeqZBRK7TG9f6NxzJ6Ou+y6pBBEOdT3/AF6wgqCXEIfPaaUXI4JPOYjrhuC49OwwXMe7Fx1nsL+Hb0B/4/TI6X+4+mJufNSPoP46EwwXYjTQR0CD7j9Ar/ZzrGusC2f1i5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FE1vkhZEcBTm/jJaftv+DejwqE1+7/QXcmbHN3bXq44=; b=BxBIxDSyWngWgnAnu4zY5SnlMgQO+dp4wYAr3yyX60f16TzBQ1ZVh0Dp2Yoa00eHhDWzVIpyx0GzxN+rAUikxSgcjCEOgUGh45A2+yyT2I47Jxu84JZdQi6FSTr5BGjSE8dXwxywbA8HvAhhqB76UUPXcvRszhH34HB2nTD1oFrnRuWes0kx1veRQvHG8Qie1enNtdow7TUPOg8xUfT6vu/j0C4kM2YktH785IbmP3oYr9VsCE6g5E+HmhF2GNnBKahsMp7d4m2BaD5QCWUbdTtDZF/SF33vdg4tn+5DMS9eGqcVLi6uX87ySKckPBCKenVcK9RPFLei+v3vM0hHQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=ddn.com; dmarc=pass action=none header.from=ddn.com; dkim=pass header.d=ddn.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ddn.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FE1vkhZEcBTm/jJaftv+DejwqE1+7/QXcmbHN3bXq44=; b=Fh7/Pj/Tz6qTg6pwJFWwPoWjdGD4hjMuoFrrhuzUoGPXiWeVUI8YRCLfoNA+gLGOzhV/fZ2ATzYq486DYIL/HpIgdl2fE+6emFst9fUM+rLyRbDMS+qalTxEFacb6Y/GGpdENom0+juoWNAM6GSbUQk8Cma2Ysj4jJLNDvq0jXk= Received: from BY5PR19MB3176.namprd19.prod.outlook.com (10.255.160.21) by BY5PR19MB3221.namprd19.prod.outlook.com (10.255.160.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2241.14; Tue, 3 Sep 2019 17:04:20 +0000 Received: from BY5PR19MB3176.namprd19.prod.outlook.com ([fe80::844f:102f:5181:c074]) by BY5PR19MB3176.namprd19.prod.outlook.com ([fe80::844f:102f:5181:c074%3]) with mapi id 15.20.2220.022; Tue, 3 Sep 2019 17:04:20 +0000 From: Matt Lupfer To: "Michael S . Tsirkin" , Jason Wang , Paolo Bonzini , Stefan Hajnoczi , "James E . J . Bottomley" , "Martin K . Petersen" CC: "virtualization@lists.linux-foundation.org" , "linux-scsi@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Matt Lupfer Subject: [PATCH] scsi: virtio_scsi: unplug LUNs when events missed Thread-Topic: [PATCH] scsi: virtio_scsi: unplug LUNs when events missed Thread-Index: AQHVYnmgUCG1mM4ObEKGSGCIQ1xBzg== Date: Tue, 3 Sep 2019 17:04:20 +0000 Message-ID: <20190903170408.32286-1-mlupfer@ddn.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR03CA0002.namprd03.prod.outlook.com (2603:10b6:404:23::12) To BY5PR19MB3176.namprd19.prod.outlook.com (2603:10b6:a03:184::21) authentication-results: spf=none (sender IP is ) smtp.mailfrom=mlupfer@ddn.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [107.128.241.61] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: cc3df57e-7d38-49e1-eba6-08d73090c2ff x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:BY5PR19MB3221; x-ms-traffictypediagnostic: BY5PR19MB3221: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-forefront-prvs: 01494FA7F7 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(4636009)(39850400004)(376002)(136003)(366004)(346002)(396003)(189003)(199004)(36756003)(71190400001)(71200400001)(14454004)(25786009)(4326008)(256004)(478600001)(5024004)(66556008)(66476007)(66446008)(64756008)(66946007)(476003)(6486002)(2616005)(86362001)(486006)(8676002)(81156014)(102836004)(81166006)(8936002)(50226002)(386003)(7736002)(6506007)(305945005)(6116002)(3846002)(26005)(5660300002)(2906002)(316002)(186003)(110136005)(54906003)(1076003)(52116002)(99286004)(6512007)(66066001)(6436002)(53936002);DIR:OUT;SFP:1101;SCL:1;SRVR:BY5PR19MB3221;H:BY5PR19MB3176.namprd19.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: ddn.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: RUmvvb9EMpVdSOP5wT+r+RINhpPJNUTNk4b/DHOnu/M9IaKFyUuNdjjERa6bKk9Dlx7GAd/jpk+NfTC1NMisgz1/mRYDu88+JzI6xKs0bzTtIDN6z75g4F+4KINMOilhmac2lvQTI9JNkrG/AuJlorJQpAWs/VmufEgi+1MF7gm2PL8nKxRItYFYrAII8cjyZ63KzlJy7NrG7i+bnqZZ7jeyAMAjBQLAYopZwt58iONTQ8gzKDzdjEJz5rMgPePiTLnUErMmRrAQPHgZfOvTPblMYn+Ex9PjJ7pdsQliJTjN1cc7MX8Htfa9fXXFEm1Daa5eiQyLzn3roSXB/Ed9sHjYpOnbftguKWZalCSPcCGKgMuh1nG2vJWhClcL7Ex4iZ5sPeUhnsoe5mDBpc78zl0kfnlxDmUggZ3OQ5BzJR8= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc3df57e-7d38-49e1-eba6-08d73090c2ff X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Sep 2019 17:04:20.2709 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 753b6e26-6fd3-43e6-8248-3f1735d59bb4 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Vt/yFrolFeFtItMqa33m8bCgerKq3VBWspQM6MbtqDFP9VNcOVTyV6OM4vFl5w1v X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR19MB3221 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The event handler calls scsi_scan_host() when events are missed, which will hotplug new LUNs. However, this function won't remove any unplugged LUNs. The result is that hotunplug doesn't work properly when the number of unplugged LUNs exceeds the event queue size (currently 8). Scan existing LUNs when events are missed to check if they are still present. If not, remove them. Signed-off-by: Matt Lupfer --- drivers/scsi/virtio_scsi.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index 297e1076e571..18df77bf371b 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c @@ -324,6 +324,36 @@ static void virtscsi_handle_param_change(struct virtio= _scsi *vscsi, scsi_device_put(sdev); } =20 +static void virtscsi_rescan_hotunplug(struct virtio_scsi *vscsi) +{ + struct scsi_device *sdev; + struct Scsi_Host *shost =3D virtio_scsi_host(vscsi->vdev); + unsigned char scsi_cmd[MAX_COMMAND_SIZE]; + int result, inquiry_len, inq_result_len =3D 256; + char *inq_result =3D kmalloc(inq_result_len, GFP_KERNEL); + + shost_for_each_device(sdev, shost) { + inquiry_len =3D sdev->inquiry_len ? sdev->inquiry_len : 36; + + memset(scsi_cmd, 0, sizeof(scsi_cmd)); + scsi_cmd[0] =3D INQUIRY; + scsi_cmd[4] =3D (unsigned char) inquiry_len; + + memset(inq_result, 0, inq_result_len); + + result =3D scsi_execute_req(sdev, scsi_cmd, DMA_FROM_DEVICE, + inq_result, inquiry_len, NULL, + 2, 3, NULL); + + if (result =3D=3D 0 && inq_result[0] >> 5) { + /* PQ indicates the LUN is not attached */ + scsi_remove_device(sdev); + } + } + + kfree(inq_result); +} + static void virtscsi_handle_event(struct work_struct *work) { struct virtio_scsi_event_node *event_node =3D @@ -335,6 +365,7 @@ static void virtscsi_handle_event(struct work_struct *w= ork) cpu_to_virtio32(vscsi->vdev, VIRTIO_SCSI_T_EVENTS_MISSED)) { event->event &=3D ~cpu_to_virtio32(vscsi->vdev, VIRTIO_SCSI_T_EVENTS_MISSED); + virtscsi_rescan_hotunplug(vscsi); scsi_scan_host(virtio_scsi_host(vscsi->vdev)); } =20 --=20 2.23.0