Patchwork [RFC,7/9] scsi: push qiov to SCSIRequest

login
register
mail settings
Submitter Paolo Bonzini
Date June 6, 2011, 4:26 p.m.
Message ID <1307377620-7538-8-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/98981/
State New
Headers show

Comments

Paolo Bonzini - June 6, 2011, 4:26 p.m.
The simplest place to put an QEMUIOVec for the HBA is the SCSIRequest.
So, push the SCSIDisk's qiov member up and make it visible to the targets.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/scsi-bus.c  |    4 +++-
 hw/scsi-disk.c |   19 +++++++++----------
 hw/scsi.h      |    1 +
 3 files changed, 13 insertions(+), 11 deletions(-)

Patch

diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index ad6a730..3b545ed 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -148,7 +148,9 @@  SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t l
 
 SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun)
 {
-    return d->info->alloc_req(d, tag, lun);
+    SCSIRequest *req = d->info->alloc_req(d, tag, lun);
+    qemu_iovec_reset(&req->qiov);
+    return req;
 }
 
 uint8_t *scsi_req_get_buf(SCSIRequest *req)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index bc6003c..4f5ba1c 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -56,7 +56,6 @@  typedef struct SCSIDiskReq {
     uint32_t sector_count;
     uint32_t buflen;
     struct iovec iov;
-    QEMUIOVector qiov;
     uint32_t status;
 } SCSIDiskReq;
 
@@ -145,8 +144,8 @@  static uint32_t scsi_init_iovec(SCSIDiskReq *r)
         r->iov.iov_base = qemu_blockalign(s->bs, r->buflen);
     }
     r->iov.iov_len = MIN(r->sector_count * 512, r->buflen);
-    qemu_iovec_init_external(&r->qiov, &r->iov, 1);
-    return r->qiov.size / 512;
+    qemu_iovec_init_external(&r->req.qiov, &r->iov, 1);
+    return r->req.qiov.size / 512;
 }
 
 static void scsi_read_complete(void * opaque, int ret)
@@ -164,10 +163,10 @@  static void scsi_read_complete(void * opaque, int ret)
 
     DPRINTF("Data ready tag=0x%x len=%zd\n", r->req.tag, r->iov.iov_len);
 
-    n = r->qiov.size / 512;
+    n = r->req.qiov.size / 512;
     r->sector += n;
     r->sector_count -= n;
-    scsi_req_data(&r->req, r->qiov.size);
+    scsi_req_data(&r->req, r->req.qiov.size);
 }
 
 
@@ -200,7 +199,7 @@  static void scsi_read_data(SCSIRequest *req)
     }
 
     n = scsi_init_iovec(r);
-    r->req.aiocb = bdrv_aio_readv(s->bs, r->sector, &r->qiov, n,
+    r->req.aiocb = bdrv_aio_readv(s->bs, r->sector, &r->req.qiov, n,
                               scsi_read_complete, r);
     if (r->req.aiocb == NULL) {
         scsi_read_complete(r, -EIO);
@@ -263,7 +262,7 @@  static void scsi_write_complete(void * opaque, int ret)
         }
     }
 
-    n = r->qiov.size / 512;
+    n = r->req.qiov.size / 512;
     r->sector += n;
     r->sector_count -= n;
     if (r->sector_count == 0) {
@@ -271,7 +270,7 @@  static void scsi_write_complete(void * opaque, int ret)
     } else {
         len = scsi_init_iovec(r);
         DPRINTF("Write complete tag=0x%x more=%d\n", r->req.tag, len);
-        scsi_req_data(&r->req, r->qiov.size);
+        scsi_req_data(&r->req, r->req.qiov.size);
     }
 }
 
@@ -290,9 +289,9 @@  static void scsi_write_data(SCSIRequest *req)
         return;
     }
 
-    n = r->qiov.size / 512;
+    n = r->req.qiov.size / 512;
     if (n) {
-        r->req.aiocb = bdrv_aio_writev(s->bs, r->sector, &r->qiov, n,
+        r->req.aiocb = bdrv_aio_writev(s->bs, r->sector, &r->req.qiov, n,
                                        scsi_write_complete, r);
         if (r->req.aiocb == NULL) {
             scsi_write_complete(r, -ENOMEM);
diff --git a/hw/scsi.h b/hw/scsi.h
index c1dca35..b551b57 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -30,6 +30,7 @@  typedef struct SCSISense {
 struct SCSIRequest {
     SCSIBus           *bus;
     SCSIDevice        *dev;
+    QEMUIOVector      qiov;
     uint32_t          refcount;
     uint32_t          tag;
     uint32_t          lun;