virtio-scsi: Implement change_queue_depth for virtscsi targets
authorVenkatesh Srinivas <venkateshs@google.com>
Sun, 6 Jul 2014 14:39:27 +0000 (16:39 +0200)
committerChristoph Hellwig <hch@lst.de>
Fri, 25 Jul 2014 21:17:00 +0000 (17:17 -0400)
change_queue_depth allows changing per-target queue depth via sysfs.

It also allows the SCSI midlayer to ramp down the number of concurrent
inflight requests in response to a SCSI BUSY status response and allows
the midlayer to ramp the count back up to the device maximum when the
BUSY condition has resolved.

Signed-off-by: Venkatesh Srinivas <venkateshs@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/scsi/virtio_scsi.c

index cdce502c3c46f0a6613bd3a075146c8a62dcf02f..eee1bc0b506efe64359d7096cbcb0384edb9255b 100644 (file)
@@ -27,6 +27,7 @@
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_tcq.h>
 #include <linux/seqlock.h>
 
 #define VIRTIO_SCSI_MEMPOOL_SZ 64
@@ -654,6 +655,36 @@ static int virtscsi_device_reset(struct scsi_cmnd *sc)
        return virtscsi_tmf(vscsi, cmd);
 }
 
+/**
+ * virtscsi_change_queue_depth() - Change a virtscsi target's queue depth
+ * @sdev:      Virtscsi target whose queue depth to change
+ * @qdepth:    New queue depth
+ * @reason:    Reason for the queue depth change.
+ */
+static int virtscsi_change_queue_depth(struct scsi_device *sdev,
+                                      int qdepth,
+                                      int reason)
+{
+       struct Scsi_Host *shost = sdev->host;
+       int max_depth = shost->cmd_per_lun;
+
+       switch (reason) {
+       case SCSI_QDEPTH_QFULL: /* Drop qdepth in response to BUSY state */
+               scsi_track_queue_full(sdev, qdepth);
+               break;
+       case SCSI_QDEPTH_RAMP_UP: /* Raise qdepth after BUSY state resolved */
+       case SCSI_QDEPTH_DEFAULT: /* Manual change via sysfs */
+               scsi_adjust_queue_depth(sdev,
+                                       scsi_get_tag_type(sdev),
+                                       min(max_depth, qdepth));
+               break;
+       default:
+               return -EOPNOTSUPP;
+       }
+
+       return sdev->queue_depth;
+}
+
 static int virtscsi_abort(struct scsi_cmnd *sc)
 {
        struct virtio_scsi *vscsi = shost_priv(sc->device->host);
@@ -709,6 +740,7 @@ static struct scsi_host_template virtscsi_host_template_single = {
        .this_id = -1,
        .cmd_size = sizeof(struct virtio_scsi_cmd),
        .queuecommand = virtscsi_queuecommand_single,
+       .change_queue_depth = virtscsi_change_queue_depth,
        .eh_abort_handler = virtscsi_abort,
        .eh_device_reset_handler = virtscsi_device_reset,
 
@@ -726,6 +758,7 @@ static struct scsi_host_template virtscsi_host_template_multi = {
        .this_id = -1,
        .cmd_size = sizeof(struct virtio_scsi_cmd),
        .queuecommand = virtscsi_queuecommand_multi,
+       .change_queue_depth = virtscsi_change_queue_depth,
        .eh_abort_handler = virtscsi_abort,
        .eh_device_reset_handler = virtscsi_device_reset,
 
This page took 0.027296 seconds and 5 git commands to generate.