From: Cong Meng <mc@linux.vnet.ibm.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
stefanha@linux.vnet.ibm.com, zwanp@cn.ibm.com,
Rusty Russell <rusty@rustcorp.com.au>,
linuxram@us.ibm.com, qemu-devel@nongnu.org,
virtualization@lists.linux-foundation.org,
Cong Meng <mc@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 2/2 v1] virtio-scsi: set per-LUN queue limits for sg devices
Date: Tue, 21 Aug 2012 16:23:47 +0800 [thread overview]
Message-ID: <1345537427-21601-2-git-send-email-mc@linux.vnet.ibm.com> (raw)
In-Reply-To: <1345537427-21601-1-git-send-email-mc@linux.vnet.ibm.com>
Each virtio scsi HBA has global request queue limits. But the passthrough
LUNs (scsi-generic) come from different host HBAs may have different request
queue limits. If the guest sends commands that exceed the host limits, the
commands will be rejected by host HAB.
To address the issue, this patch responses the newly added virtio control
queue request by returning the per-LUN queue limits.
Signed-off-by: Cong Meng <mc@linux.vnet.ibm.com>
---
hw/virtio-scsi.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index c4a5b22..3c0bd99 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -28,6 +28,7 @@
#define VIRTIO_SCSI_F_INOUT 0
#define VIRTIO_SCSI_F_HOTPLUG 1
#define VIRTIO_SCSI_F_CHANGE 2
+#define VIRTIO_SCSI_F_LUN_QUERY 3
/* Response codes */
#define VIRTIO_SCSI_S_OK 0
@@ -48,6 +49,7 @@
#define VIRTIO_SCSI_T_TMF 0
#define VIRTIO_SCSI_T_AN_QUERY 1
#define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
+#define VIRTIO_SCSI_T_LUN_QUERY 3
/* Valid TMF subtypes. */
#define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
@@ -66,6 +68,11 @@
#define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
#define VIRTIO_SCSI_T_PARAM_CHANGE 3
+/* LUN Query */
+#define VIRTIO_SCSI_T_LQ_MAX_SECTORS 0
+#define VIRTIO_SCSI_T_LQ_MAX_SEGMENTS 1
+#define VIRTIO_SCSI_T_LQ_MAX_SEGMENT_SIZE 2
+
/* Reasons for transport reset event */
#define VIRTIO_SCSI_EVT_RESET_HARD 0
#define VIRTIO_SCSI_EVT_RESET_RESCAN 1
@@ -115,6 +122,18 @@ typedef struct {
uint8_t response;
} QEMU_PACKED VirtIOSCSICtrlANResp;
+/* LUN qeury */
+typedef struct {
+ uint32_t type;
+ uint8_t lun[8];
+ uint32_t subtype;
+} QEMU_PACKED VirtIOSCSICtrlLQReq;
+
+typedef struct {
+ uint32_t response;
+ uint32_t value;
+} QEMU_PACKED VirtIOSCSICtrlLQResp;
+
typedef struct {
uint32_t event;
uint8_t lun[8];
@@ -160,6 +179,7 @@ typedef struct VirtIOSCSIReq {
VirtIOSCSICmdReq *cmd;
VirtIOSCSICtrlTMFReq *tmf;
VirtIOSCSICtrlANReq *an;
+ VirtIOSCSICtrlLQReq *lq;
} req;
union {
char *buf;
@@ -167,6 +187,7 @@ typedef struct VirtIOSCSIReq {
VirtIOSCSICtrlTMFResp *tmf;
VirtIOSCSICtrlANResp *an;
VirtIOSCSIEvent *event;
+ VirtIOSCSICtrlLQResp *lq;
} resp;
} VirtIOSCSIReq;
@@ -285,6 +306,43 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
return req;
}
+static void virtio_scsi_do_lun_query(VirtIOSCSI *s, VirtIOSCSIReq *req)
+{
+ SCSIDevice *d = virtio_scsi_device_find(s, req->req.lq->lun);
+
+ if (!d) {
+ goto fail;
+ }
+
+ switch (req->req.lq->subtype) {
+ case VIRTIO_SCSI_T_LQ_MAX_SECTORS:
+ req->resp.lq->value = get_queue_max_sectors(d->conf.bs);
+ if (!req->resp.lq->value) {
+ goto fail;
+ }
+ break;
+ case VIRTIO_SCSI_T_LQ_MAX_SEGMENTS:
+ req->resp.lq->value = get_queue_max_segments(d->conf.bs);
+ if (!req->resp.lq->value) {
+ goto fail;
+ }
+ break;
+ case VIRTIO_SCSI_T_LQ_MAX_SEGMENT_SIZE:
+ req->resp.lq->value = get_queue_max_segment_size(d->conf.bs);
+ if (!req->resp.lq->value) {
+ goto fail;
+ }
+ break;
+ default:
+ goto fail;
+ }
+
+ req->resp.lq->response = VIRTIO_SCSI_S_OK;
+ return;
+fail:
+ req->resp.lq->response = VIRTIO_SCSI_S_FAILURE;
+}
+
static void virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
{
SCSIDevice *d = virtio_scsi_device_find(s, req->req.tmf->lun);
@@ -414,6 +472,12 @@ static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
}
req->resp.an->event_actual = 0;
req->resp.an->response = VIRTIO_SCSI_S_OK;
+ } else if (req->req.lq->type == VIRTIO_SCSI_T_LUN_QUERY) {
+ if (out_size < sizeof(VirtIOSCSICtrlLQReq) ||
+ in_size < sizeof(VirtIOSCSICtrlLQResp)) {
+ virtio_scsi_bad_req();
+ }
+ virtio_scsi_do_lun_query(s, req);
}
virtio_scsi_complete_req(req);
}
@@ -557,6 +621,7 @@ static uint32_t virtio_scsi_get_features(VirtIODevice *vdev,
{
requested_features |= (1UL << VIRTIO_SCSI_F_HOTPLUG);
requested_features |= (1UL << VIRTIO_SCSI_F_CHANGE);
+ requested_features |= (1UL << VIRTIO_SCSI_F_LUN_QUERY);
return requested_features;
}
--
1.7.7.6
next prev parent reply other threads:[~2012-08-21 8:26 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-21 8:23 [Qemu-devel] [PATCH 1/2 v1] blkdrv: Add queue limits parameters for sg block drive Cong Meng
2012-08-21 8:23 ` Cong Meng [this message]
2012-08-21 9:56 ` [Qemu-devel] [PATCH 2/2 v1] virtio-scsi: set per-LUN queue limits for sg devices Stefan Hajnoczi
2012-08-21 8:48 ` [Qemu-devel] [PATCH 1/2 v1] blkdrv: Add queue limits parameters for sg block drive Paolo Bonzini
2012-08-21 9:41 ` Cong Meng
2012-08-21 9:52 ` Stefan Hajnoczi
2012-08-21 10:14 ` Paolo Bonzini
2012-08-22 11:04 ` Cong Meng
2012-08-22 12:09 ` Paolo Bonzini
2012-08-22 13:13 ` Stefan Hajnoczi
2012-08-22 14:13 ` Paolo Bonzini
2012-08-23 9:31 ` Cong Meng
2012-08-23 10:03 ` Paolo Bonzini
2012-08-23 10:08 ` Stefan Hajnoczi
2012-08-23 10:52 ` Paolo Bonzini
2012-08-23 12:08 ` Stefan Hajnoczi
2012-08-24 0:45 ` Nicholas A. Bellinger
2012-08-24 7:56 ` Paolo Bonzini
2012-08-24 10:43 ` Hannes Reinecke
2012-08-24 9:05 ` Stefan Hajnoczi
2012-08-24 9:14 ` Paolo Bonzini
2012-08-21 9:49 ` Stefan Hajnoczi
2012-08-21 18:31 ` Blue Swirl
2012-08-22 8:25 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1345537427-21601-2-git-send-email-mc@linux.vnet.ibm.com \
--to=mc@linux.vnet.ibm.com \
--cc=kwolf@redhat.com \
--cc=linuxram@us.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rusty@rustcorp.com.au \
--cc=stefanha@linux.vnet.ibm.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=zwanp@cn.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).