linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] scsi: virtio_scsi: unplug LUNs when events missed
@ 2019-09-05 18:19 Matt Lupfer
  2019-09-06  8:54 ` Stefan Hajnoczi
  2019-09-11  2:14 ` Martin K. Petersen
  0 siblings, 2 replies; 4+ messages in thread
From: Matt Lupfer @ 2019-09-05 18:19 UTC (permalink / raw)
  To: mst, jasowang, pbonzini, stefanha, jejb, martin.petersen
  Cc: virtualization, linux-scsi, linux-kernel, Matt Lupfer

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 <mlupfer@ddn.com>
---
 drivers/scsi/virtio_scsi.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index 297e1076e571..13a82b94b27b 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -30,6 +30,8 @@
 #include <linux/seqlock.h>
 #include <linux/blk-mq-virtio.h>
 
+#include "sd.h"
+
 #define VIRTIO_SCSI_MEMPOOL_SZ 64
 #define VIRTIO_SCSI_EVENT_LEN 8
 #define VIRTIO_SCSI_VQ_BASE 2
@@ -324,6 +326,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,
+					  SD_TIMEOUT, SD_MAX_RETRIES, NULL);
+
+		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 +367,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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scsi: virtio_scsi: unplug LUNs when events missed
  2019-09-05 18:19 [PATCH v2] scsi: virtio_scsi: unplug LUNs when events missed Matt Lupfer
@ 2019-09-06  8:54 ` Stefan Hajnoczi
  2019-09-09 16:55   ` Paolo Bonzini
  2019-09-11  2:14 ` Martin K. Petersen
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Hajnoczi @ 2019-09-06  8:54 UTC (permalink / raw)
  To: Matt Lupfer
  Cc: mst, jasowang, pbonzini, jejb, martin.petersen, virtualization,
	linux-scsi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 909 bytes --]

On Thu, Sep 05, 2019 at 06:19:28PM +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 <mlupfer@ddn.com>
> ---
>  drivers/scsi/virtio_scsi.c | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)

Please include a changelog in future patch revisions.  For example:

  Signed-off-by: ...
  ---
  v2:
    * Replaced magic constants with sd.h constants [Michael]

Just C and virtio code review, no SCSI specifics:

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scsi: virtio_scsi: unplug LUNs when events missed
  2019-09-06  8:54 ` Stefan Hajnoczi
@ 2019-09-09 16:55   ` Paolo Bonzini
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2019-09-09 16:55 UTC (permalink / raw)
  To: Stefan Hajnoczi, Matt Lupfer
  Cc: mst, jasowang, jejb, martin.petersen, virtualization, linux-scsi,
	linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 1041 bytes --]

On 06/09/19 10:54, Stefan Hajnoczi wrote:
> On Thu, Sep 05, 2019 at 06:19:28PM +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 <mlupfer@ddn.com>
>> ---
>>  drivers/scsi/virtio_scsi.c | 33 +++++++++++++++++++++++++++++++++
>>  1 file changed, 33 insertions(+)
> 
> Please include a changelog in future patch revisions.  For example:
> 
>   Signed-off-by: ...
>   ---
>   v2:
>     * Replaced magic constants with sd.h constants [Michael]
> 
> Just C and virtio code review, no SCSI specifics:
> 
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> 

Acked-by: Paolo Bonzini <pbonzini@redhat.com>


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] scsi: virtio_scsi: unplug LUNs when events missed
  2019-09-05 18:19 [PATCH v2] scsi: virtio_scsi: unplug LUNs when events missed Matt Lupfer
  2019-09-06  8:54 ` Stefan Hajnoczi
@ 2019-09-11  2:14 ` Martin K. Petersen
  1 sibling, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2019-09-11  2:14 UTC (permalink / raw)
  To: Matt Lupfer
  Cc: mst, jasowang, pbonzini, stefanha, jejb, martin.petersen,
	virtualization, linux-scsi, linux-kernel


Matt,

> 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.

Applied to 5.4/scsi-queue, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-09-11  2:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-05 18:19 [PATCH v2] scsi: virtio_scsi: unplug LUNs when events missed Matt Lupfer
2019-09-06  8:54 ` Stefan Hajnoczi
2019-09-09 16:55   ` Paolo Bonzini
2019-09-11  2:14 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).