Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp449149ybe; Wed, 4 Sep 2019 02:17:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1+7SwACcpN9Nlx5mNoJwqbJUGIgmyoqre2EvWs1PEjwUljWBJM1mjFio1243qlAaBfCix X-Received: by 2002:a17:90a:ec12:: with SMTP id l18mr3818606pjy.6.1567588640867; Wed, 04 Sep 2019 02:17:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567588640; cv=none; d=google.com; s=arc-20160816; b=sXoQ++C+KlZC9VNTsQJSv90sdq9mfWFtfV7SqeLLLgr2Jzhm8tsQpwO2chIEAaqKeZ 4VlLAMPWEU3u9DGV8iXuQGlTbbznd1YKaXKW3DX/zuwfEsfhbC0ny1z4GJJHgS4h/a3p 21RaPyiecb0XloTXOUxfXcAKXVmxfeizvfI8e8GP0RvJcWpoP2ih9YP6koWUaXGL4ZmW Rw5dzbe7ppdE36qNICYEWKyejcUVvxvbYaTdsnn71hwYZ/JJ2UBSOxgZ3KHbgthBD4NN qKDW+VFArtRQ3ZJPZiLl9yOdMFaoSilggZZtj1gah2K8iINg4dqpm49BrqOVLYyvVQWm J4xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=WulsqcUDqGAlte0XT35jyBuHqWE16gY7+JD//6GJ8LE=; b=u/pgDZ19cBZsB4XcL2GDIfCTog1uPgECjLQ0WHUxD1J8ixkFqrwuEhWLFP+aT4vF1f 4gXfP2N+sYA19j+tCCeVsgcJ5SSq9sDyeJEOmWzhJyXL5bDanZA6l2FRhOt+7coHirM7 CKlXbs1O5OzMERQ0csxJmw/wJV2FQjUPA0WX0sMglcx35fbr0DECJCmFI2qTIUKS3FWA C6X6Ie9N4rtYCmDXOXoaCX5qArRCPyjy7DVtG6iT9RZ1t0r/Vyejyci8ZwoCP5UHLMHM 5RlfaWvVFdCBF7eMRVb8f3V8NiFfsUuaTWjLq1dtE25feCulaY4tCrTRq3e/8Z0uA9So AG4w== ARC-Authentication-Results: i=1; mx.google.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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 18si16616712pgf.457.2019.09.04.02.17.04; Wed, 04 Sep 2019 02:17:20 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729597AbfIDJOo (ORCPT + 99 others); Wed, 4 Sep 2019 05:14:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43272 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727768AbfIDJOo (ORCPT ); Wed, 4 Sep 2019 05:14:44 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0196B91760 for ; Wed, 4 Sep 2019 09:14:44 +0000 (UTC) Received: by mail-wr1-f71.google.com with SMTP id x1so6395567wrn.11 for ; Wed, 04 Sep 2019 02:14:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=WulsqcUDqGAlte0XT35jyBuHqWE16gY7+JD//6GJ8LE=; b=jlCdOjI/kPTyURSfwDK5cuZvl7eBVDTlCYqc6Y1w7z7tdWlsgFmnnKs7bKHVTpf5B1 xRRwTkq69Sq31Z7ByE9NbGA582gUZS3kPbEetvwa16XalwtIKMAC/WPGDBWSsBujE1FS Dy83yHeqcXv+tnc6pU6i1HXRwlQhSwoIGecfmIV1NmNX9Dnvmtn5VQ12ENQH5NgjxNbw eOtdLOxgRGYjPD/5yBgoLOXSq+e9jiasNS8Q0kwRkxhCEHYqWimfV+g8oTzF0XZBlPxr Z3/aEmS7mExZF8aRXHYMUC0bvLKXJ/ap2b6+LbLuDdcsNgpa3eWRo4u00i4H30VsdbHk o54w== X-Gm-Message-State: APjAAAXXzNAorpUQDTFQjbWx6hHY+pJRbaLTUEdXhqUq4LbD8a7zibN5 8Pv00mczRZpiw/lWJbctnzuBuY9366vGKKIKV/8v4mhU8oyCdfFIQ4s6rbYpw4uKb4ytSYCBz3h wRqP7KbDX8wm0gt5urXHaNCwv X-Received: by 2002:a1c:9e03:: with SMTP id h3mr3545579wme.112.1567588482666; Wed, 04 Sep 2019 02:14:42 -0700 (PDT) X-Received: by 2002:a1c:9e03:: with SMTP id h3mr3545568wme.112.1567588482495; Wed, 04 Sep 2019 02:14:42 -0700 (PDT) Received: from redhat.com (bzq-79-176-40-226.red.bezeqint.net. [79.176.40.226]) by smtp.gmail.com with ESMTPSA id b1sm2455532wmj.4.2019.09.04.02.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2019 02:14:41 -0700 (PDT) Date: Wed, 4 Sep 2019 05:14:33 -0400 From: "Michael S. Tsirkin" To: Matt Lupfer Cc: Jason Wang , Paolo Bonzini , Stefan Hajnoczi , "James E . J . Bottomley" , "Martin K . Petersen" , "virtualization@lists.linux-foundation.org" , "linux-scsi@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] scsi: virtio_scsi: unplug LUNs when events missed Message-ID: <20190904051230-mutt-send-email-mst@kernel.org> References: <20190903170408.32286-1-mlupfer@ddn.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190903170408.32286-1-mlupfer@ddn.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 03, 2019 at 05:04:20PM +0000, Matt Lupfer wrote: > 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); > } > > +static void virtscsi_rescan_hotunplug(struct virtio_scsi *vscsi) > +{ > + struct scsi_device *sdev; > + struct Scsi_Host *shost = virtio_scsi_host(vscsi->vdev); > + unsigned char scsi_cmd[MAX_COMMAND_SIZE]; > + int result, inquiry_len, inq_result_len = 256; > + char *inq_result = kmalloc(inq_result_len, GFP_KERNEL); > + > + shost_for_each_device(sdev, shost) { > + inquiry_len = sdev->inquiry_len ? sdev->inquiry_len : 36; > + > + memset(scsi_cmd, 0, sizeof(scsi_cmd)); > + scsi_cmd[0] = INQUIRY; > + scsi_cmd[4] = (unsigned char) inquiry_len; > + > + memset(inq_result, 0, inq_result_len); > + > + result = scsi_execute_req(sdev, scsi_cmd, DMA_FROM_DEVICE, > + inq_result, inquiry_len, NULL, > + 2, 3, NULL); Where do the weird 2 and 3 values come from? Most callers seem to use SD_TIMEOUT, SD_MAX_RETRIES... > + > + if (result == 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 = > @@ -335,6 +365,7 @@ static void virtscsi_handle_event(struct work_struct *work) > cpu_to_virtio32(vscsi->vdev, VIRTIO_SCSI_T_EVENTS_MISSED)) { > event->event &= ~cpu_to_virtio32(vscsi->vdev, > VIRTIO_SCSI_T_EVENTS_MISSED); > + virtscsi_rescan_hotunplug(vscsi); > scsi_scan_host(virtio_scsi_host(vscsi->vdev)); > } > > -- > 2.23.0